summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--firmware/target/arm/ipod/video/lcd-as-video.S73
-rw-r--r--firmware/target/arm/ipod/video/lcd-video.c314
2 files changed, 234 insertions, 153 deletions
diff --git a/firmware/target/arm/ipod/video/lcd-as-video.S b/firmware/target/arm/ipod/video/lcd-as-video.S
index ffd2e0cf10..5a7daa7681 100644
--- a/firmware/target/arm/ipod/video/lcd-as-video.S
+++ b/firmware/target/arm/ipod/video/lcd-as-video.S
@@ -22,16 +22,11 @@
.align 2
.global lcd_write_data
.type lcd_write_data, %function
- /* r0 = addr */
-lcd_write_data: /* r1 = pixel count */
+ /* r0 = addr, must be aligned */
+lcd_write_data: /* r1 = pixel count, must be even */
stmfd sp!, {r4-r6}
mov r2, #0x30000000 /* LCD data port */
- tst r0, #2 /* first pixel unaligned? */
- ldrneh r3, [r0], #2
- strneh r3, [r2]
- subne r1, r1, #1
-
subs r1, r1, #16
.loop16:
ldmgeia r0!, {r3-r6}
@@ -51,17 +46,16 @@ lcd_write_data: /* r1 = pixel count */
tst r1, #2
ldrne r3, [r0], #4
strne r3, [r2]
- tst r1, #1
- ldrneh r3, [r0]
- strneh r3, [r2]
ldmfd sp!, {r4-r6}
bx lr
/****************************************************************************
- * void lcd_write_yuv_420_lines(unsigned char const * const src[3],
- * int width,
- * int stride);
+ * void lcd_write_yuv_420_upper(unsigned char const * const src[3],
+ * unsigned char *croma_buf, int width);
+ *
+ * void lcd_write_yuv_420_lower(unsigned char *y_src,
+ * unsigned char *croma_buf, int width);
*
* |R| |1.000000 -0.000001 1.402000| |Y'|
* |G| = |1.000000 -0.334136 -0.714136| |Pb|
@@ -72,25 +66,18 @@ lcd_write_data: /* r1 = pixel count */
* |B| |74 128 0| |Cr - 128| >> 9
*/
.align 2
- .global lcd_write_yuv420_lines
- .type lcd_write_yuv420_lines, %function
-lcd_write_yuv420_lines:
+ .global lcd_write_yuv420_upper
+ .type lcd_write_yuv420_upper, %function
+lcd_write_yuv420_upper:
/* r0 = yuv_src */
- /* r1 = width */
- /* r2 = stride */
+ /* r1 = chroma buffer */
+ /* r2 = width */
stmfd sp!, { r4-r12 } /* save non-scratch */
ldmia r0, { r10, r11, r12 } /* r10 = yuv_src[0] = Y'_p */
/* r11 = yuv_src[1] = Cb_p */
/* r12 = yuv_src[2] = Cr_p */
- add r2, r10, r2 /* r2 = &ysrc[stride] */
- add r3, r1, r1, asl #1 /* number of bytes for chroma buffer */
- add r3, r3, #15 /* plus room for 3 additional words, */
- bic r3, r3, #3 /* rounded up to multiples of 4 byte */
- sub sp, sp, r3 /* and allocate on stack */
- stmia sp, {r1, r2, r3} /* width, &ysrc[stride], stack_alloc */
-
- mov r7, r1 /* r7 = loop count */
- add r8, sp, #12 /* chroma buffer */
+ mov r7, r2 /* r7 = loop count */
+ mov r8, r1 /* chroma buffer */
mov r9, #0x30000000 /* LCD data port */
/* 1st loop start */
@@ -181,13 +168,27 @@ lcd_write_yuv420_lines:
subs r7, r7, #2 /* check for loop end */
bgt 10b /* back to beginning */
- /* 1st loop end */
-
- add r8, sp, #12 /* chroma buffer */
- ldmia sp, { r7, r10 } /* r7 = loop count */
- /* r10 = &ysrc[stride] */
- /* 2nd loop start */
+ ldmfd sp!, { r4-r12 } /* restore registers */
+ bx lr
+
+ .ltorg
+ .size lcd_write_yuv420_upper, .-lcd_write_yuv420_upper
+
+
+ .align 2
+ .global lcd_write_yuv420_lower
+ .type lcd_write_yuv420_lower, %function
+lcd_write_yuv420_lower:
+ /* r0 = y_src */
+ /* r1 = croma buf */
+ /* r2 = width */
+ stmfd sp!, { r4-r10 } /* save non-scratch */
+ mov r10, r0 /* r10 = y_src */
+ mov r7, r2 /* r7 = loop count */
+ mov r8, r1 /* chroma buffer */
+ mov r9, #0x30000000 /* LCD data port */
+
20: /* loop start */
/* restore r1, r3 and r0 from chroma buffer */
@@ -257,10 +258,8 @@ lcd_write_yuv420_lines:
bgt 20b /* back to beginning */
/* 2nd loop end */
- ldr r3, [sp, #8]
- add sp, sp, r3 /* deallocate buffer */
- ldmfd sp!, { r4-r12 } /* restore registers */
+ ldmfd sp!, { r4-r10 } /* restore registers */
bx lr
.ltorg
- .size lcd_write_yuv420_lines, .-lcd_write_yuv420_lines
+ .size lcd_write_yuv420_lower, .-lcd_write_yuv420_lower
diff --git a/firmware/target/arm/ipod/video/lcd-video.c b/firmware/target/arm/ipod/video/lcd-video.c
index 04a4344125..232458e230 100644
--- a/firmware/target/arm/ipod/video/lcd-video.c
+++ b/firmware/target/arm/ipod/video/lcd-video.c
@@ -48,6 +48,132 @@
#define BCM_ALT_RD_ADDR32 (*(volatile unsigned long *)(0x30060000))
#define BCM_ALT_CONTROL (*(volatile unsigned short*)(0x30070000))
+#define BCM_FB_BASE 0xE0020 /* Address of internal BCM framebuffer */
+
+/* Time until the BCM is considered stalled and will be re-kicked.
+ * Must be guaranteed to be >~ 20ms. */
+#define BCM_UPDATE_TIMEOUT (HZ/20)
+
+enum lcd_status {
+ LCD_IDLE,
+ LCD_INITIAL,
+ LCD_NEED_UPDATE,
+ LCD_UPDATING
+};
+
+struct {
+ long update_timeout;
+ enum lcd_status state;
+ bool blocked;
+ struct corelock cl; /* inter-core sync */
+} lcd_state IBSS_ATTR;
+
+
+static inline void bcm_write_addr(unsigned address)
+{
+ BCM_WR_ADDR32 = address; /* write destination address */
+
+ while (!(BCM_CONTROL & 0x2)); /* wait for it to be write ready */
+}
+
+static inline void bcm_write32(unsigned address, unsigned value)
+{
+
+ bcm_write_addr(address); /* set destination address */
+
+ BCM_DATA32 = value; /* write value */
+}
+
+static inline unsigned bcm_read32(unsigned address)
+{
+ while (!(BCM_RD_ADDR & 1));
+
+ BCM_RD_ADDR32 = address; /* write source address */
+
+ while (!(BCM_CONTROL & 0x10)); /* wait for it to be read ready */
+
+ return BCM_DATA32; /* read value */
+}
+
+static void bcm_setup_rect(unsigned x, unsigned y,
+ unsigned width, unsigned height)
+{
+ bcm_write_addr(0xE0004);
+ BCM_DATA32 = x;
+ BCM_DATA32 = y;
+ BCM_DATA32 = x + width - 1;
+ BCM_DATA32 = y + height - 1;
+}
+
+static void lcd_tick(void)
+{
+ /* No set_irq_level - already in interrupt context */
+ corelock_lock(&lcd_state.cl);
+
+ if (!lcd_state.blocked && lcd_state.state >= LCD_NEED_UPDATE)
+ {
+ unsigned data = bcm_read32(0x1F8);
+ bool bcm_is_busy = (data == 0xFFFA0005 || data == 0xFFFF);
+
+ if (((lcd_state.state == LCD_NEED_UPDATE) && !bcm_is_busy)
+ /* Update requested and BCM is no longer busy. */
+ || (TIME_AFTER(current_tick, lcd_state.update_timeout) && bcm_is_busy))
+ /* BCM still busy after timeout, i.e. stalled. */
+ {
+ bcm_write32(0x1F8, 0xFFFA0005); /* Kick off update */
+ BCM_CONTROL = 0x31;
+ lcd_state.update_timeout = current_tick + BCM_UPDATE_TIMEOUT;
+ lcd_state.state = LCD_UPDATING;
+ }
+ else if ((lcd_state.state == LCD_UPDATING) && !bcm_is_busy)
+ {
+ /* Update finished properly and no new update pending. */
+ lcd_state.state = LCD_IDLE;
+ }
+ }
+ corelock_unlock(&lcd_state.cl);
+}
+
+static inline void lcd_block_tick(void)
+{
+ int oldlevel = set_irq_level(HIGHEST_IRQ_LEVEL);
+
+ corelock_lock(&lcd_state.cl);
+ lcd_state.blocked = true;
+ corelock_unlock(&lcd_state.cl);
+
+ set_irq_level(oldlevel);
+}
+
+static void lcd_unblock_and_update(void)
+{
+ unsigned data;
+ bool bcm_is_busy;
+ int oldlevel = set_irq_level(HIGHEST_IRQ_LEVEL);
+
+ corelock_lock(&lcd_state.cl);
+
+ data = bcm_read32(0x1F8);
+ bcm_is_busy = (data == 0xFFFA0005 || data == 0xFFFF);
+
+ if (!bcm_is_busy || (lcd_state.state == LCD_INITIAL) ||
+ TIME_AFTER(current_tick, lcd_state.update_timeout))
+ {
+ bcm_write32(0x1F8, 0xFFFA0005); /* Kick off update */
+ BCM_CONTROL = 0x31;
+ lcd_state.update_timeout = current_tick + BCM_UPDATE_TIMEOUT;
+ lcd_state.state = LCD_UPDATING;
+ }
+ else
+ {
+ lcd_state.state = LCD_NEED_UPDATE; /* Post update request */
+ }
+ lcd_state.blocked = false;
+ corelock_unlock(&lcd_state.cl);
+
+ set_irq_level(oldlevel);
+}
+
/*** hardware configuration ***/
void lcd_set_contrast(int val)
@@ -71,8 +197,12 @@ void lcd_set_flip(bool yesno)
/* LCD init */
void lcd_init_device(void)
-{
- /* iPodLinux doesn't appear have any LCD init code for the Video */
+{
+ lcd_state.blocked = false;
+ lcd_state.state = LCD_INITIAL;
+ corelock_init(&lcd_state.cl);
+ bcm_setup_rect(0, 0, LCD_WIDTH, LCD_HEIGHT);
+ tick_add_task(&lcd_tick);
}
/*** update functions ***/
@@ -91,55 +221,11 @@ void lcd_blit(const fb_data* data, int x, int by, int width,
(void)stride;
}
-static inline void lcd_bcm_write32(unsigned address, unsigned value)
-{
- /* write out destination address */
- BCM_WR_ADDR32 = address;
-
- /* wait for it to be write ready */
- while (!(BCM_CONTROL & 0x2));
-
- /* write out the value */
- BCM_DATA32 = value;
-}
-
-static void lcd_bcm_setup_rect(unsigned cmd,
- unsigned x,
- unsigned y,
- unsigned width,
- unsigned height)
-{
- lcd_bcm_write32(0x1F8, 0xFFFA0005);
- lcd_bcm_write32(0xE0000, cmd);
- lcd_bcm_write32(0xE0004, x);
- lcd_bcm_write32(0xE0008, y);
- lcd_bcm_write32(0xE000C, x + width - 1);
- lcd_bcm_write32(0xE0010, y + height - 1);
- lcd_bcm_write32(0xE0014, (width * height) << 1);
- lcd_bcm_write32(0xE0018, (width * height) << 1);
- lcd_bcm_write32(0xE001C, 0);
-}
-
-static inline unsigned lcd_bcm_read32(unsigned address)
-{
- while (!(BCM_RD_ADDR & 1));
-
- /* write out destination address */
- BCM_RD_ADDR32 = address;
-
- /* wait for it to be read ready */
- while (!(BCM_CONTROL & 0x10));
-
- /* read the value */
- return BCM_DATA32;
-}
-
-static bool finishup_needed = false;
-
/* Update a fraction of the display. */
void lcd_update_rect(int x, int y, int width, int height)
{
const fb_data *addr;
+ unsigned bcmaddr;
if (x + width >= LCD_WIDTH)
width = LCD_WIDTH - x;
@@ -147,43 +233,36 @@ void lcd_update_rect(int x, int y, int width, int height)
height = LCD_HEIGHT - y;
if ((width <= 0) || (height <= 0))
- return; /* Nothing left to do - 0 is harmful to lcd_write_data(). */
-
+ return; /* Nothing left to do. */
+
+ /* Ensure x and width are both even. The BCM doesn't like small unaligned
+ * writes and would just ignore them. */
+ width = (width + (x & 1) + 1) & ~1;
+ x &= ~1;
+
+ /* Prevent the tick from triggering BCM updates while we're writing. */
+ lcd_block_tick();
+
addr = &lcd_framebuffer[y][x];
+ bcmaddr = BCM_FB_BASE + (LCD_WIDTH*2) * y + (x << 1);
- if (finishup_needed)
+ if (width == LCD_WIDTH)
{
- /* Bottom-half of original lcd_bcm_finishup() function */
- unsigned int data = lcd_bcm_read32(0x1F8);
- while (data == 0xFFFA0005 || data == 0xFFFF)
- {
- /* This loop can wait for up to 14ms - so we yield() */
- yield();
- data = lcd_bcm_read32(0x1F8);
- }
+ bcm_write_addr(bcmaddr);
+ lcd_write_data(addr, width * height);
}
- lcd_bcm_read32(0x1FC);
-
- lcd_bcm_setup_rect(0x34, x, y, width, height);
-
- /* write out destination address */
- BCM_WR_ADDR32 = 0xE0020;
-
- while (!(BCM_CONTROL & 0x2)); /* wait for it to be write ready */
-
- do
+ else
{
- lcd_write_data(addr, width);
- addr += LCD_WIDTH;
+ do
+ {
+ bcm_write_addr(bcmaddr);
+ bcmaddr += (LCD_WIDTH*2);
+ lcd_write_data(addr, width);
+ addr += LCD_WIDTH;
+ }
+ while (--height > 0);
}
- while (--height > 0);
-
- /* Top-half of original lcd_bcm_finishup() function */
- BCM_CONTROL = 0x31;
-
- lcd_bcm_read32(0x1FC);
-
- finishup_needed = true;
+ lcd_unblock_and_update();
}
/* Update the display.
@@ -193,18 +272,21 @@ void lcd_update(void)
lcd_update_rect(0, 0, LCD_WIDTH, LCD_HEIGHT);
}
-/* Line write helper function for lcd_yuv_blit. Write two lines of yuv420. */
-extern void lcd_write_yuv420_lines(unsigned char const * const src[3],
- int width,
- int stride);
+/* Line write helper functions for lcd_yuv_blit. Write two lines of yuv420. */
+extern void lcd_write_yuv420_upper(unsigned char const * const src[3],
+ unsigned char *chroma_buf, int width);
+extern void lcd_write_yuv420_lower(unsigned const char *y_src,
+ unsigned char *chroma_buf, int width);
/* Performance function to blit a YUV bitmap directly to the LCD */
void lcd_yuv_blit(unsigned char * const src[3],
int src_x, int src_y, int stride,
int x, int y, int width, int height)
{
- unsigned char const * yuv_src[3];
+ unsigned bcmaddr;
off_t z;
+ unsigned char const * yuv_src[3];
+ unsigned char chroma_buf[3*width]; /* dynamic */
/* Sorry, but width and height must be >= 2 or else */
width &= ~1;
@@ -214,42 +296,42 @@ void lcd_yuv_blit(unsigned char * const src[3],
yuv_src[1] = src[1] + (z >> 2) + (src_x >> 1);
yuv_src[2] = src[2] + (yuv_src[1] - src[1]);
- if (finishup_needed)
+ /* Prevent the tick from triggering BCM updates while we're writing. */
+ lcd_block_tick();
+
+ bcmaddr = BCM_FB_BASE + (LCD_WIDTH*2) * y + (x << 1);
+ height >>= 1;
+
+ if (width == LCD_WIDTH)
{
- /* Bottom-half of original lcd_bcm_finishup() function */
- unsigned int data = lcd_bcm_read32(0x1F8);
- while (data == 0xFFFA0005 || data == 0xFFFF)
+ bcm_write_addr(bcmaddr);
+ do
{
- /* This loop can wait for up to 14ms - so we yield() */
- yield();
- data = lcd_bcm_read32(0x1F8);
- }
+ lcd_write_yuv420_upper(yuv_src, chroma_buf, width);
+ yuv_src[0] += stride;
+ lcd_write_yuv420_lower(yuv_src[0], chroma_buf, width);
+ yuv_src[0] += stride;
+ yuv_src[1] += stride >> 1; /* Skip down one chroma line */
+ yuv_src[2] += stride >> 1;
+ }
+ while (--height > 0);
}
-
- lcd_bcm_read32(0x1FC);
-
- lcd_bcm_setup_rect(0x34, x, y, width, height);
-
- /* write out destination address */
- BCM_WR_ADDR32 = 0xE0020;
-
- while (!(BCM_CONTROL & 0x2)); /* wait for it to be write ready */
-
- height >>= 1;
- do
+ else
{
- lcd_write_yuv420_lines(yuv_src, width, stride);
-
- yuv_src[0] += stride << 1; /* Skip down two luma lines */
- yuv_src[1] += stride >> 1; /* Skip down one chroma line */
- yuv_src[2] += stride >> 1;
+ do
+ {
+ bcm_write_addr(bcmaddr);
+ bcmaddr += (LCD_WIDTH*2);
+ lcd_write_yuv420_upper(yuv_src, chroma_buf, width);
+ yuv_src[0] += stride;
+ bcm_write_addr(bcmaddr);
+ bcmaddr += (LCD_WIDTH*2);
+ lcd_write_yuv420_lower(yuv_src[0], chroma_buf, width);
+ yuv_src[0] += stride;
+ yuv_src[1] += stride >> 1; /* Skip down one chroma line */
+ yuv_src[2] += stride >> 1;
+ }
+ while (--height > 0);
}
- while (--height > 0);
-
- /* Top-half of original lcd_bcm_finishup() function */
- BCM_CONTROL = 0x31;
-
- lcd_bcm_read32(0x1FC);
-
- finishup_needed = true;
+ lcd_unblock_and_update();
}