2005-12-18 13:04:00 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
2005-12-19 14:30:52 +00:00
|
|
|
* LCD driver for iPod Video
|
|
|
|
*
|
|
|
|
* Based on code from the ipodlinux project - http://ipodlinux.org/
|
|
|
|
* Adapted for Rockbox in December 2005
|
2005-12-18 13:04:00 +00:00
|
|
|
*
|
2005-12-19 14:30:52 +00:00
|
|
|
* Original file: linux/arch/armnommu/mach-ipod/fb.c
|
2005-12-18 13:04:00 +00:00
|
|
|
*
|
2005-12-19 14:30:52 +00:00
|
|
|
* Copyright (c) 2003-2005 Bernard Leach (leachbj@bouncycastle.org)
|
2005-12-18 13:04:00 +00:00
|
|
|
*
|
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
#include "config.h"
|
|
|
|
#include "cpu.h"
|
|
|
|
#include "lcd.h"
|
|
|
|
#include "kernel.h"
|
|
|
|
#include "system.h"
|
|
|
|
|
|
|
|
/*** hardware configuration ***/
|
|
|
|
|
|
|
|
void lcd_set_contrast(int val)
|
|
|
|
{
|
|
|
|
/* TODO: Implement lcd_set_contrast() */
|
|
|
|
(void)val;
|
|
|
|
}
|
|
|
|
|
|
|
|
void lcd_set_invert_display(bool yesno)
|
|
|
|
{
|
|
|
|
/* TODO: Implement lcd_set_invert_display() */
|
|
|
|
(void)yesno;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* turn the display upside down (call lcd_update() afterwards) */
|
|
|
|
void lcd_set_flip(bool yesno)
|
|
|
|
{
|
|
|
|
/* TODO: Implement lcd_set_flip() */
|
|
|
|
(void)yesno;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* LCD init */
|
|
|
|
void lcd_init_device(void)
|
|
|
|
{
|
|
|
|
/* iPodLinux doesn't appear have any LCD init code for the Video */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*** update functions ***/
|
|
|
|
|
|
|
|
/* Performance function that works with an external buffer
|
|
|
|
note that by and bheight are in 4-pixel units! */
|
|
|
|
void lcd_blit(const fb_data* data, int x, int by, int width,
|
|
|
|
int bheight, int stride)
|
|
|
|
{
|
|
|
|
/* TODO: Implement lcd_blit() */
|
|
|
|
(void)data;
|
|
|
|
(void)x;
|
|
|
|
(void)by;
|
|
|
|
(void)width;
|
|
|
|
(void)bheight;
|
|
|
|
(void)stride;
|
|
|
|
}
|
|
|
|
|
2006-02-15 14:13:51 +00:00
|
|
|
static inline void lcd_bcm_write32(unsigned address, unsigned value)
|
2005-12-18 13:04:00 +00:00
|
|
|
{
|
|
|
|
/* write out destination address as two 16bit values */
|
|
|
|
outw(address, 0x30010000);
|
|
|
|
outw((address >> 16), 0x30010000);
|
|
|
|
|
|
|
|
/* wait for it to be write ready */
|
|
|
|
while ((inw(0x30030000) & 0x2) == 0);
|
|
|
|
|
|
|
|
/* write out the value low 16, high 16 */
|
|
|
|
outw(value, 0x30000000);
|
|
|
|
outw((value >> 16), 0x30000000);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void lcd_bcm_setup_rect(unsigned cmd,
|
|
|
|
unsigned start_horiz,
|
|
|
|
unsigned start_vert,
|
|
|
|
unsigned max_horiz,
|
|
|
|
unsigned max_vert,
|
|
|
|
unsigned count)
|
|
|
|
{
|
|
|
|
lcd_bcm_write32(0x1F8, 0xFFFA0005);
|
|
|
|
lcd_bcm_write32(0xE0000, cmd);
|
|
|
|
lcd_bcm_write32(0xE0004, start_horiz);
|
|
|
|
lcd_bcm_write32(0xE0008, start_vert);
|
|
|
|
lcd_bcm_write32(0xE000C, max_horiz);
|
|
|
|
lcd_bcm_write32(0xE0010, max_vert);
|
|
|
|
lcd_bcm_write32(0xE0014, count);
|
|
|
|
lcd_bcm_write32(0xE0018, count);
|
|
|
|
lcd_bcm_write32(0xE001C, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned lcd_bcm_read32(unsigned address) {
|
|
|
|
while ((inw(0x30020000) & 1) == 0);
|
|
|
|
|
|
|
|
/* write out destination address as two 16bit values */
|
|
|
|
outw(address, 0x30020000);
|
|
|
|
outw((address >> 16), 0x30020000);
|
|
|
|
|
|
|
|
/* wait for it to be read ready */
|
|
|
|
while ((inw(0x30030000) & 0x10) == 0);
|
|
|
|
|
|
|
|
/* read the value */
|
|
|
|
return inw(0x30000000) | inw(0x30000000) << 16;
|
|
|
|
}
|
|
|
|
|
2006-08-08 21:28:08 +00:00
|
|
|
static int finishup_needed = 0;
|
|
|
|
|
2005-12-18 13:04:00 +00:00
|
|
|
/* Update a fraction of the display. */
|
2006-02-16 21:15:05 +00:00
|
|
|
void lcd_update_rect(int x, int y, int width, int height) ICODE_ATTR;
|
2005-12-18 13:04:00 +00:00
|
|
|
void lcd_update_rect(int x, int y, int width, int height)
|
|
|
|
{
|
2006-03-08 04:14:30 +00:00
|
|
|
{
|
|
|
|
int endy = x + width;
|
|
|
|
/* Ensure x and width are both even - so we can read 32-bit aligned
|
|
|
|
data from lcd_framebuffer */
|
|
|
|
x &= ~1;
|
|
|
|
width &= ~1;
|
|
|
|
if (x + width < endy) {
|
|
|
|
width += 2;
|
|
|
|
}
|
|
|
|
}
|
2005-12-18 13:04:00 +00:00
|
|
|
|
2006-02-16 23:17:49 +00:00
|
|
|
if (finishup_needed) {
|
2006-03-08 04:14:30 +00:00
|
|
|
unsigned int data;
|
2006-02-16 23:17:49 +00:00
|
|
|
/* Bottom-half of original lcd_bcm_finishup() function */
|
|
|
|
do {
|
|
|
|
/* This function takes about 14ms to execute - so we yield() */
|
|
|
|
yield();
|
|
|
|
data = lcd_bcm_read32(0x1F8);
|
|
|
|
} while (data == 0xFFFA0005 || data == 0xFFFF);
|
|
|
|
}
|
|
|
|
|
|
|
|
lcd_bcm_read32(0x1FC);
|
|
|
|
|
2006-03-08 04:14:30 +00:00
|
|
|
{
|
|
|
|
int rect1, rect2, rect3, rect4;
|
|
|
|
int count = (width * height) << 1;
|
|
|
|
/* calculate the drawing region */
|
|
|
|
rect1 = x; /* start horiz */
|
|
|
|
rect2 = y; /* start vert */
|
|
|
|
rect3 = (x + width) - 1; /* max horiz */
|
|
|
|
rect4 = (y + height) - 1; /* max vert */
|
|
|
|
|
|
|
|
/* setup the drawing region */
|
|
|
|
lcd_bcm_setup_rect(0x34, rect1, rect2, rect3, rect4, count);
|
|
|
|
}
|
2006-02-15 21:07:37 +00:00
|
|
|
|
|
|
|
/* write out destination address as two 16bit values */
|
|
|
|
outw((0xE0020 & 0xffff), 0x30010000);
|
|
|
|
outw((0xE0020 >> 16), 0x30010000);
|
2005-12-18 13:04:00 +00:00
|
|
|
|
2006-02-16 00:52:47 +00:00
|
|
|
/* wait for it to be write ready */
|
|
|
|
while ((inw(0x30030000) & 0x2) == 0);
|
|
|
|
|
2006-03-08 04:14:30 +00:00
|
|
|
{
|
|
|
|
unsigned short *src = (unsigned short*)&lcd_framebuffer[y][x];
|
2006-03-09 01:32:34 +00:00
|
|
|
unsigned short *end = &src[LCD_WIDTH * height];
|
|
|
|
int line_rem = (LCD_WIDTH - width);
|
|
|
|
while (src < end) {
|
2006-07-19 17:47:06 +00:00
|
|
|
/* Duff's Device to unroll loop */
|
|
|
|
register int count = width ;
|
|
|
|
register int n=( count + 7 ) / 8;
|
|
|
|
switch( count % 8 ) {
|
|
|
|
case 0: do{ outw(*(src++), 0x30000000);
|
|
|
|
case 7: outw(*(src++), 0x30000000);
|
|
|
|
case 6: outw(*(src++), 0x30000000);
|
|
|
|
case 5: outw(*(src++), 0x30000000);
|
|
|
|
case 4: outw(*(src++), 0x30000000);
|
|
|
|
case 3: outw(*(src++), 0x30000000);
|
|
|
|
case 2: outw(*(src++), 0x30000000);
|
|
|
|
case 1: outw(*(src++), 0x30000000);
|
|
|
|
} while(--n>0);
|
2006-03-08 04:14:30 +00:00
|
|
|
}
|
2006-03-09 01:32:34 +00:00
|
|
|
src += line_rem;
|
2006-02-15 21:07:37 +00:00
|
|
|
}
|
2005-12-18 13:04:00 +00:00
|
|
|
}
|
|
|
|
|
2006-02-16 23:17:49 +00:00
|
|
|
/* Top-half of original lcd_bcm_finishup() function */
|
|
|
|
outw(0x31, 0x30030000);
|
|
|
|
|
|
|
|
lcd_bcm_read32(0x1FC);
|
|
|
|
|
|
|
|
finishup_needed = 1;
|
2005-12-18 13:04:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Update the display.
|
|
|
|
This must be called after all other LCD functions that change the display. */
|
|
|
|
void lcd_update(void)
|
|
|
|
{
|
|
|
|
lcd_update_rect(0, 0, LCD_WIDTH, LCD_HEIGHT);
|
|
|
|
}
|
2006-08-08 21:28:08 +00:00
|
|
|
|
|
|
|
#define CSUB_X 2
|
|
|
|
#define CSUB_Y 2
|
|
|
|
|
|
|
|
#define RYFAC (31*257)
|
2006-08-17 08:37:35 +00:00
|
|
|
#define GYFAC (31*257)
|
2006-08-08 21:28:08 +00:00
|
|
|
#define BYFAC (31*257)
|
|
|
|
#define RVFAC 11170 /* 31 * 257 * 1.402 */
|
2006-08-17 08:37:35 +00:00
|
|
|
#define GVFAC (-5690) /* 31 * 257 * -0.714136 */
|
|
|
|
#define GUFAC (-2742) /* 31 * 257 * -0.344136 */
|
2006-08-08 21:28:08 +00:00
|
|
|
#define BUFAC 14118 /* 31 * 257 * 1.772 */
|
|
|
|
|
|
|
|
#define ROUNDOFFS (127*257)
|
2006-08-17 08:37:35 +00:00
|
|
|
#define ROUNDOFFSG (63*257)
|
2006-08-08 21:28:08 +00:00
|
|
|
|
|
|
|
/* 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)
|
|
|
|
{
|
|
|
|
int ymax;
|
|
|
|
|
|
|
|
width = (width + 1) & ~1;
|
|
|
|
|
|
|
|
if (finishup_needed) {
|
|
|
|
unsigned int data;
|
|
|
|
/* Bottom-half of original lcd_bcm_finishup() function */
|
2006-08-17 08:37:35 +00:00
|
|
|
data = lcd_bcm_read32(0x1F8);
|
|
|
|
while (data == 0xFFFA0005 || data == 0xFFFF) {
|
|
|
|
/* This loop can wait for up to 14ms - so we yield() */
|
2006-08-08 21:28:08 +00:00
|
|
|
yield();
|
|
|
|
data = lcd_bcm_read32(0x1F8);
|
2006-08-17 08:37:35 +00:00
|
|
|
}
|
2006-08-08 21:28:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
lcd_bcm_read32(0x1FC);
|
|
|
|
|
|
|
|
{
|
|
|
|
int rect1, rect2, rect3, rect4;
|
|
|
|
int count = (width * height) << 1;
|
|
|
|
/* calculate the drawing region */
|
|
|
|
rect1 = x; /* start horiz */
|
|
|
|
rect2 = y; /* start vert */
|
|
|
|
rect3 = (x + width) - 1; /* max horiz */
|
|
|
|
rect4 = (y + height) - 1; /* max vert */
|
|
|
|
|
|
|
|
/* setup the drawing region */
|
|
|
|
lcd_bcm_setup_rect(0x34, rect1, rect2, rect3, rect4, count);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* write out destination address as two 16bit values */
|
|
|
|
outw((0xE0020 & 0xffff), 0x30010000);
|
|
|
|
outw((0xE0020 >> 16), 0x30010000);
|
|
|
|
|
|
|
|
/* wait for it to be write ready */
|
|
|
|
while ((inw(0x30030000) & 0x2) == 0);
|
|
|
|
|
|
|
|
ymax = y + height - 1 ;
|
|
|
|
|
2006-08-17 08:37:35 +00:00
|
|
|
const int stride_div_csub_x = stride/CSUB_X;
|
|
|
|
|
2006-08-08 21:28:08 +00:00
|
|
|
for (; y <= ymax ; y++)
|
|
|
|
{
|
|
|
|
/* upsampling, YUV->RGB conversion and reduction to RGB565 in one go */
|
|
|
|
const unsigned char *ysrc = src[0] + stride * src_y + src_x;
|
2006-08-17 08:37:35 +00:00
|
|
|
|
|
|
|
const int uvoffset = stride_div_csub_x * (src_y/CSUB_Y) +
|
|
|
|
(src_x/CSUB_X);
|
|
|
|
|
|
|
|
const unsigned char *usrc = src[1] + uvoffset;
|
|
|
|
const unsigned char *vsrc = src[2] + uvoffset;
|
2006-08-08 21:28:08 +00:00
|
|
|
const unsigned char *row_end = ysrc + width;
|
|
|
|
|
|
|
|
int y, u, v;
|
2006-08-17 08:37:35 +00:00
|
|
|
int red1, green1, blue1;
|
|
|
|
int red2, green2, blue2;
|
2006-08-08 21:28:08 +00:00
|
|
|
unsigned rbits, gbits, bbits;
|
|
|
|
|
|
|
|
int rc, gc, bc;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
u = *usrc++ - 128;
|
|
|
|
v = *vsrc++ - 128;
|
|
|
|
rc = RVFAC * v + ROUNDOFFS;
|
2006-08-17 08:37:35 +00:00
|
|
|
gc = GVFAC * v + GUFAC * u + ROUNDOFFSG;
|
2006-08-08 21:28:08 +00:00
|
|
|
bc = BUFAC * u + ROUNDOFFS;
|
|
|
|
|
|
|
|
/* Pixel 1 */
|
|
|
|
y = *ysrc++;
|
|
|
|
|
2006-08-17 08:37:35 +00:00
|
|
|
red1 = RYFAC * y + rc;
|
|
|
|
green1 = GYFAC * y + gc;
|
|
|
|
blue1 = BYFAC * y + bc;
|
2006-08-08 21:28:08 +00:00
|
|
|
|
|
|
|
/* Pixel 2 */
|
|
|
|
y = *ysrc++;
|
2006-08-17 08:37:35 +00:00
|
|
|
red2 = RYFAC * y + rc;
|
|
|
|
green2 = GYFAC * y + gc;
|
|
|
|
blue2 = BYFAC * y + bc;
|
|
|
|
|
|
|
|
/* Since out of bounds errors are relatively rare, we check two
|
|
|
|
pixels at once to see if any components are out of bounds, and
|
|
|
|
then fix whichever is broken. This works due to high values and
|
|
|
|
negative values both becoming larger than the cutoff when
|
|
|
|
casted to unsigned. And ORing them together checks all of them
|
|
|
|
simultaneously. */
|
|
|
|
if (((unsigned)(red1 | green1 | blue1 |
|
|
|
|
red2 | green2 | blue2)) > (RYFAC*255+ROUNDOFFS)) {
|
|
|
|
if (((unsigned)(red1 | green1 | blue1)) >
|
|
|
|
(RYFAC*255+ROUNDOFFS)) {
|
|
|
|
if ((unsigned)red1 > (RYFAC*255+ROUNDOFFS))
|
|
|
|
{
|
|
|
|
if (red1 < 0)
|
|
|
|
red1 = 0;
|
|
|
|
else
|
|
|
|
red1 = (RYFAC*255+ROUNDOFFS);
|
|
|
|
}
|
|
|
|
if ((unsigned)green1 > (GYFAC*255+ROUNDOFFSG))
|
|
|
|
{
|
|
|
|
if (green1 < 0)
|
|
|
|
green1 = 0;
|
|
|
|
else
|
|
|
|
green1 = (GYFAC*255+ROUNDOFFSG);
|
|
|
|
}
|
|
|
|
if ((unsigned)blue1 > (BYFAC*255+ROUNDOFFS))
|
|
|
|
{
|
|
|
|
if (blue1 < 0)
|
|
|
|
blue1 = 0;
|
|
|
|
else
|
|
|
|
blue1 = (BYFAC*255+ROUNDOFFS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (((unsigned)(red2 | green2 | blue2)) >
|
|
|
|
(RYFAC*255+ROUNDOFFS)) {
|
|
|
|
if ((unsigned)red2 > (RYFAC*255+ROUNDOFFS))
|
|
|
|
{
|
|
|
|
if (red2 < 0)
|
|
|
|
red2 = 0;
|
|
|
|
else
|
|
|
|
red2 = (RYFAC*255+ROUNDOFFS);
|
|
|
|
}
|
|
|
|
if ((unsigned)green2 > (GYFAC*255+ROUNDOFFSG))
|
|
|
|
{
|
|
|
|
if (green2 < 0)
|
|
|
|
green2 = 0;
|
|
|
|
else
|
|
|
|
green2 = (GYFAC*255+ROUNDOFFSG);
|
|
|
|
}
|
|
|
|
if ((unsigned)blue2 > (BYFAC*255+ROUNDOFFS))
|
|
|
|
{
|
|
|
|
if (blue2 < 0)
|
|
|
|
blue2 = 0;
|
|
|
|
else
|
|
|
|
blue2 = (BYFAC*255+ROUNDOFFS);
|
|
|
|
}
|
|
|
|
}
|
2006-08-08 21:28:08 +00:00
|
|
|
}
|
2006-08-17 08:37:35 +00:00
|
|
|
|
|
|
|
rbits = red1 >> 16 ;
|
|
|
|
gbits = green1 >> 15 ;
|
|
|
|
bbits = blue1 >> 16 ;
|
|
|
|
|
|
|
|
outw((rbits << 11) | (gbits << 5) | bbits, 0x30000000);
|
2006-08-08 21:28:08 +00:00
|
|
|
|
2006-08-17 08:37:35 +00:00
|
|
|
rbits = red2 >> 16 ;
|
|
|
|
gbits = green2 >> 15 ;
|
|
|
|
bbits = blue2 >> 16 ;
|
2006-08-08 21:28:08 +00:00
|
|
|
outw((rbits << 11) | (gbits << 5) | bbits, 0x30000000);
|
|
|
|
}
|
|
|
|
while (ysrc < row_end);
|
|
|
|
|
|
|
|
src_y++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Top-half of original lcd_bcm_finishup() function */
|
|
|
|
outw(0x31, 0x30030000);
|
|
|
|
|
|
|
|
lcd_bcm_read32(0x1FC);
|
|
|
|
|
|
|
|
finishup_needed = 1;
|
|
|
|
}
|