diff options
author | Michael Sparmann <theseven@rockbox.org> | 2011-03-01 01:52:12 +0000 |
---|---|---|
committer | Michael Sparmann <theseven@rockbox.org> | 2011-03-01 01:52:12 +0000 |
commit | 7a7c8f071dd37ad74a299c4b18706d99a67bd128 (patch) | |
tree | cdbfa66ee4bf88b0f9dc046d01380207da812754 /firmware | |
parent | 24a6f93aa88cd5dd6b3feef9509e0b32894ebe0b (diff) |
iPod Classic: Use DMA (and double buffering) for LCD updates
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29474 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/target/arm/s5l8702/ipod6g/lcd-asm-ipod6g.S | 81 | ||||
-rw-r--r-- | firmware/target/arm/s5l8702/ipod6g/lcd-ipod6g.c | 156 |
2 files changed, 103 insertions, 134 deletions
diff --git a/firmware/target/arm/s5l8702/ipod6g/lcd-asm-ipod6g.S b/firmware/target/arm/s5l8702/ipod6g/lcd-asm-ipod6g.S index 7d9e8274d5..ec8a24c4e5 100644 --- a/firmware/target/arm/s5l8702/ipod6g/lcd-asm-ipod6g.S +++ b/firmware/target/arm/s5l8702/ipod6g/lcd-asm-ipod6g.S @@ -19,57 +19,15 @@ * ****************************************************************************/ -#define FORCE_FIFO_WAIT -/**************************************************************************** - * #define FORCE_FIFO_WAIT - * - * This is not needed in YUV blitting when the LCD IF is fast enough. In this - * case YUV-to-RGB conversion per pixel needs longer than the transfer of a - * pixel via the LCD IF. For iPod nano 2G this is true if the LCD IF is - * configured to use LCD_PHTIME = 0x00 (see lcd-nano2g.c). - ****************************************************************************/ #include "config.h" .section .icode, "ax", %progbits -/**************************************************************************** - * void lcd_write_line(const fb_data *addr, - * int pixelcount, - * const unsigned int lcd_base_addr); - * - * Writes pixelcount pixels from src-pointer (lcd_framebuffer) to LCD dataport. - */ - .align 2 - .global lcd_write_line - .type lcd_write_line, %function - /* r0 = addr, must be aligned */ - /* r1 = pixel count, must be even */ -lcd_write_line: /* r2 = LCD_BASE */ - stmfd sp!, {r4-r6, lr} /* save non-scratch registers */ - add r12, r2, #0x40 /* LCD_WDATA = LCD data port */ - -.loop: - ldmia r0!, {r3, r5} /* read 2 pixel (=8 byte) */ - - /* wait for FIFO half full */ -.fifo_wait: - ldr lr, [r2, #0x1C] /* while (LCD_STATUS & 0x08); */ - tst lr, #0x8 - bgt .fifo_wait - - mov r4, r3, asr #16 /* r3 = 1st pixel, r4 = 2nd pixel */ - mov r6, r5, asr #16 /* r5 = 3rd pixel, r6 = 4th pixel */ - stmia r12, {r3-r6} /* write pixels (lowest 16 bit used) */ - - subs r1, r1, #4 - bgt .loop - - ldmpc regs=r4-r6 /**************************************************************************** * extern void lcd_write_yuv420_lines(unsigned char const * const src[3], - * const unsigned LCD_BASE, + * uint16_t* out, * int width, * int stride); * @@ -93,7 +51,7 @@ lcd_write_line: /* r2 = LCD_BASE */ .type lcd_write_yuv420_lines, %function lcd_write_yuv420_lines: /* r0 = src = yuv_src */ - /* r1 = dst = LCD_BASE */ + /* r1 = dst = out */ /* r2 = width */ /* r3 = stride */ stmfd sp!, { r4-r10, lr } /* save non-scratch */ @@ -103,14 +61,14 @@ lcd_write_yuv420_lines: add r3, r9, r3 /* r3 = &ysrc[stride] */ add r4, r2, r2, asr #1 /* chroma buffer lenght = width/2 *3 */ mov r4, r4, asl #2 /* use words for str/ldm possibility */ - add r4, r4, #19 /* plus room for 4 additional words, */ + add r4, r4, #15 /* plus room for 3 additional words, */ bic r4, r4, #3 /* rounded up to multiples of 4 byte */ sub sp, sp, r4 /* and allocate on stack */ - stmia sp, {r1-r4} /* LCD_BASE, width, &ysrc[stride], stack_alloc */ + stmia sp, {r2-r4} /* width, &ysrc[stride], stack_alloc */ mov r7, r2 /* r7 = loop count */ - add r8, sp, #16 /* chroma buffer */ - add lr, r1, #0x40 /* LCD data port = LCD_BASE + 0x40 */ + add r8, sp, #12 /* chroma buffer */ + mov lr, r1 /* RGB565 data destination buffer */ /* 1st loop start */ 10: /* loop start */ @@ -195,23 +153,16 @@ lcd_write_yuv420_lines: /* calculate pixel_2 and pack with pixel_1 before writing */ orr r5, r5, r3, lsl #5 /* pixel_2 = r<<11 | g<<5 | b */ orr r5, r5, r6, lsl #11 /* r5 = pixel_2 */ -#ifdef FORCE_FIFO_WAIT - /* wait for FIFO half full */ -.fifo_wait1: - ldr r3, [lr, #-0x24] /* while (LCD_STATUS & 0x08); */ - tst r3, #0x8 - bgt .fifo_wait1 -#endif - stmia lr, {r4,r5} /* write pixel_1 and pixel_2 */ + orr r4, r4, r5, lsl #16 + str r4, [lr], #4 /* write pixel_1 and pixel_2 */ subs r7, r7, #2 /* check for loop end */ bgt 10b /* back to beginning */ /* 1st loop end */ /* Reload several registers for pointer rewinding for next loop */ - add r8, sp, #16 /* chroma buffer */ - ldmia sp, { r1, r7, r9} /* r1 = LCD_BASE */ - /* r7 = loop count */ + add r8, sp, #12 /* chroma buffer */ + ldmia sp, {r7, r9} /* r7 = loop count */ /* r9 = &ysrc[stride] */ /* 2nd loop start */ @@ -275,20 +226,14 @@ lcd_write_yuv420_lines: /* calculate pixel_2 and pack with pixel_1 before writing */ orr r5, r5, r3, lsl #5 /* pixel_2 = r<<11 | g<<5 | b */ orr r5, r5, r6, lsl #11 /* r5 = pixel_2 */ -#ifdef FORCE_FIFO_WAIT - /* wait for FIFO half full */ -.fifo_wait2: - ldr r3, [lr, #-0x24] /* while (LCD_STATUS & 0x08); */ - tst r3, #0x8 - bgt .fifo_wait2 -#endif - stmia lr, {r4,r5} /* write pixel_1 and pixel_2 */ + orr r4, r4, r5, lsl #16 + str r4, [lr], #4 /* write pixel_1 and pixel_2 */ subs r7, r7, #2 /* check for loop end */ bgt 20b /* back to beginning */ /* 2nd loop end */ - ldr r3, [sp, #12] + ldr r3, [sp, #8] add sp, sp, r3 /* deallocate buffer */ ldmpc regs=r4-r10 /* restore registers */ diff --git a/firmware/target/arm/s5l8702/ipod6g/lcd-ipod6g.c b/firmware/target/arm/s5l8702/ipod6g/lcd-ipod6g.c index 7b3e9319d7..de731a91b8 100644 --- a/firmware/target/arm/s5l8702/ipod6g/lcd-ipod6g.c +++ b/firmware/target/arm/s5l8702/ipod6g/lcd-ipod6g.c @@ -27,6 +27,7 @@ #include "cpu.h" #include "pmu-target.h" #include "power.h" +#include "string.h" #define R_HORIZ_GRAM_ADDR_SET 0x200 @@ -48,6 +49,10 @@ /** globals **/ int lcd_type; /* also needed in debug-s5l8702.c */ +static struct dma_lli lcd_lli[(LCD_WIDTH * LCD_HEIGHT - 1) / 0xfff] CACHEALIGN_ATTR; +static struct wakeup lcd_wakeup; +static struct mutex lcd_mutex; +static uint16_t lcd_dblbuf[LCD_HEIGHT][LCD_WIDTH]; static inline void s5l_lcd_write_cmd_data(int cmd, int data) @@ -100,6 +105,7 @@ bool lcd_active(void) void lcd_shutdown(void) { + mutex_lock(&lcd_mutex); pmu_write(0x2b, 0); /* Kill the backlight, instantly. */ pmu_write(0x29, 0); @@ -131,6 +137,7 @@ void lcd_shutdown(void) s5l_lcd_write_cmd(0x10); sleep(HZ / 20); } + mutex_unlock(&lcd_mutex); } void lcd_sleep(void) @@ -142,6 +149,8 @@ void lcd_sleep(void) void lcd_init_device(void) { /* Detect lcd type */ + wakeup_init(&lcd_wakeup); + mutex_init(&lcd_mutex); lcd_type = (PDAT6 & 0x30) >> 4; } @@ -149,7 +158,9 @@ void lcd_init_device(void) static inline void lcd_write_pixel(fb_data pixel) { + mutex_lock(&lcd_mutex); LCD_WDATA = pixel; + mutex_unlock(&lcd_mutex); } /* Update the display. @@ -165,121 +176,134 @@ extern void lcd_write_line(const fb_data *addr, int pixelcount, const unsigned int lcd_base_addr); -/* Update a fraction of the display. */ -void lcd_update_rect(int, int, int, int) ICODE_ATTR; -void lcd_update_rect(int x, int y, int width, int height) +static void displaylcd_setup(int x, int y, int width, int height) ICODE_ATTR; +static void displaylcd_setup(int x, int y, int width, int height) { - int y0, x0, y1, x1; - fb_data* p; - - /* Both x and width need to be preprocessed due to asm optimizations */ - x = x & ~1; /* ensure x is even */ - width = (width + 3) & ~3; /* ensure width is a multiple of 4 */ + mutex_lock(&lcd_mutex); + while (DMAC0C4CONFIG & 1) wakeup_wait(&lcd_wakeup, HZ / 10); - x0 = x; /* start horiz */ - y0 = y; /* start vert */ - x1 = (x + width) - 1; /* max horiz */ - y1 = (y + height) - 1; /* max vert */ + int xe = (x + width) - 1; /* max horiz */ + int ye = (y + height) - 1; /* max vert */ if (lcd_type & 2) { - s5l_lcd_write_cmd_data(R_HORIZ_ADDR_START_POS, x0); - s5l_lcd_write_cmd_data(R_HORIZ_ADDR_END_POS, x1); - s5l_lcd_write_cmd_data(R_VERT_ADDR_START_POS, y0); - s5l_lcd_write_cmd_data(R_VERT_ADDR_END_POS, y1); + s5l_lcd_write_cmd_data(R_HORIZ_ADDR_START_POS, x); + s5l_lcd_write_cmd_data(R_HORIZ_ADDR_END_POS, xe); + s5l_lcd_write_cmd_data(R_VERT_ADDR_START_POS, y); + s5l_lcd_write_cmd_data(R_VERT_ADDR_END_POS, ye); - s5l_lcd_write_cmd_data(R_HORIZ_GRAM_ADDR_SET, x0); - s5l_lcd_write_cmd_data(R_VERT_GRAM_ADDR_SET, y0); + s5l_lcd_write_cmd_data(R_HORIZ_GRAM_ADDR_SET, x); + s5l_lcd_write_cmd_data(R_VERT_GRAM_ADDR_SET, y); s5l_lcd_write_cmd(R_WRITE_DATA_TO_GRAM); } else { s5l_lcd_write_cmd(R_COLUMN_ADDR_SET); - s5l_lcd_write_data(x0 >> 8); - s5l_lcd_write_data(x0 & 0xff); - s5l_lcd_write_data(x1 >> 8); - s5l_lcd_write_data(x1 & 0xff); + s5l_lcd_write_data(x >> 8); + s5l_lcd_write_data(x & 0xff); + s5l_lcd_write_data(xe >> 8); + s5l_lcd_write_data(xe & 0xff); s5l_lcd_write_cmd(R_ROW_ADDR_SET); - s5l_lcd_write_data(y0 >> 8); - s5l_lcd_write_data(y0 & 0xff); - s5l_lcd_write_data(y1 >> 8); - s5l_lcd_write_data(y1 & 0xff); + s5l_lcd_write_data(y >> 8); + s5l_lcd_write_data(y & 0xff); + s5l_lcd_write_data(ye >> 8); + s5l_lcd_write_data(ye & 0xff); s5l_lcd_write_cmd(R_MEMORY_WRITE); } +} + +static void displaylcd_dma(int pixels) ICODE_ATTR; +static void displaylcd_dma(int pixels) +{ + int i; + void* data = lcd_dblbuf; + for (i = -1; i < (int)ARRAYLEN(lcd_lli) && pixels > 0; i++, pixels -= 0xfff) + { + bool last = i + 1 >= (int)ARRAYLEN(lcd_lli) || pixels <= 0xfff; + struct dma_lli* lli = i < 0 ? (struct dma_lli*)((int)&DMAC0C4LLI) : &lcd_lli[i]; + lli->srcaddr = data; + lli->dstaddr = (void*)((int)&LCD_WDATA); + lli->nextlli = last ? NULL : &lcd_lli[i + 1]; + lli->control = 0x70240000 | (last ? pixels : 0xfff) + | (last ? 0x80000000 : 0) | 0x4000000; + data += 0x1ffe; + } + clean_dcache(); + DMAC0C4CONFIG = 0x88c1; + mutex_unlock(&lcd_mutex); +} + +void INT_DMAC0C4(void) ICODE_ATTR; +void INT_DMAC0C4(void) +{ + DMAC0INTTCCLR = 0x10; + wakeup_signal(&lcd_wakeup); +} + +/* Update a fraction of the display. */ +void lcd_update_rect(int, int, int, int) ICODE_ATTR; +void lcd_update_rect(int x, int y, int width, int height) +{ + int pixels = width * height; + fb_data* p = &lcd_framebuffer[y][x]; + uint16_t* out = lcd_dblbuf[0]; + + displaylcd_setup(x, y, width, height); /* Copy display bitmap to hardware */ - p = &lcd_framebuffer[y0][x0]; if (LCD_WIDTH == width) { /* Write all lines at once */ - lcd_write_line(p, height*LCD_WIDTH, LCD_BASE); + memcpy(out, p, pixels * 2); } else { - y1 = height; do { /* Write a single line */ - lcd_write_line(p, width, LCD_BASE); + memcpy(out, p, width * 2); p += LCD_WIDTH; - } while (--y1 > 0 ); + out += width; + } while (--height); } + + displaylcd_dma(pixels); } /* Line write helper function for lcd_yuv_blit. Writes two lines of yuv420. */ extern void lcd_write_yuv420_lines(unsigned char const * const src[3], - const unsigned int lcd_baseadress, + uint16_t* outbuf, int width, int stride); /* Blit a YUV bitmap directly to the LCD */ void lcd_blit_yuv(unsigned char * const src[3], int src_x, int src_y, int stride, + int x, int y, int width, int height) ICODE_ATTR; +void lcd_blit_yuv(unsigned char * const src[3], + int src_x, int src_y, int stride, int x, int y, int width, int height) { - unsigned int z, y0, x0, y1, x1;; + unsigned int z; unsigned char const * yuv_src[3]; width = (width + 1) & ~1; /* ensure width is even */ - x0 = x; /* start horiz */ - y0 = y; /* start vert */ - x1 = (x + width) - 1; /* max horiz */ - y1 = (y + height) - 1; /* max vert */ - - if (lcd_type & 2) { - s5l_lcd_write_cmd_data(R_HORIZ_ADDR_START_POS, x0); - s5l_lcd_write_cmd_data(R_HORIZ_ADDR_END_POS, x1); - s5l_lcd_write_cmd_data(R_VERT_ADDR_START_POS, y0); - s5l_lcd_write_cmd_data(R_VERT_ADDR_END_POS, y1); - - s5l_lcd_write_cmd_data(R_HORIZ_GRAM_ADDR_SET, x0); - s5l_lcd_write_cmd_data(R_VERT_GRAM_ADDR_SET, y0); - - s5l_lcd_write_cmd(R_WRITE_DATA_TO_GRAM); - } else { - s5l_lcd_write_cmd(R_COLUMN_ADDR_SET); - s5l_lcd_write_data(x0 >> 8); - s5l_lcd_write_data(x0 & 0xff); - s5l_lcd_write_data(x1 >> 8); - s5l_lcd_write_data(x1 & 0xff); - - s5l_lcd_write_cmd(R_ROW_ADDR_SET); - s5l_lcd_write_data(y0 >> 8); - s5l_lcd_write_data(y0 & 0xff); - s5l_lcd_write_data(y1 >> 8); - s5l_lcd_write_data(y1 & 0xff); - - s5l_lcd_write_cmd(R_MEMORY_WRITE); - } + int pixels = width * height; + uint16_t* out = lcd_dblbuf[0]; z = stride * src_y; yuv_src[0] = src[0] + z + src_x; yuv_src[1] = src[1] + (z >> 2) + (src_x >> 1); yuv_src[2] = src[2] + (yuv_src[1] - src[1]); + displaylcd_setup(x, y, width, height); + height >>= 1; do { - lcd_write_yuv420_lines(yuv_src, LCD_BASE, width, stride); + lcd_write_yuv420_lines(yuv_src, out, width, stride); yuv_src[0] += stride << 1; yuv_src[1] += stride >> 1; /* Skip down one chroma line */ yuv_src[2] += stride >> 1; - } while (--height > 0); + out += width << 1; + } while (--height); + + displaylcd_dma(pixels); } |