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
|
2009-04-13 18:35:11 +00:00
|
|
|
*
|
2005-12-19 14:30:52 +00:00
|
|
|
* 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
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2005-12-18 13:04:00 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2009-08-19 22:15:45 +00:00
|
|
|
|
2010-05-06 21:04:40 +00:00
|
|
|
#include <sys/types.h> /* off_t */
|
2005-12-18 13:04:00 +00:00
|
|
|
#include "config.h"
|
|
|
|
#include "cpu.h"
|
|
|
|
#include "lcd.h"
|
|
|
|
#include "kernel.h"
|
|
|
|
#include "system.h"
|
2009-02-21 11:10:50 +00:00
|
|
|
#ifdef HAVE_LCD_SLEEP
|
|
|
|
/* Included only for lcd_awake() prototype */
|
|
|
|
#include "backlight-target.h"
|
|
|
|
#endif
|
2005-12-18 13:04:00 +00:00
|
|
|
|
2007-10-28 12:09:46 +00:00
|
|
|
/* The BCM bus width is 16 bits. But since the low address bits aren't decoded
|
|
|
|
* by the chip (the 3 BCM address bits are mapped to address bits 16..18 of the
|
|
|
|
* PP5022), writing 32 bits (and even more, using 'stmia') at once works. */
|
|
|
|
#define BCM_DATA (*(volatile unsigned short*)(0x30000000))
|
|
|
|
#define BCM_DATA32 (*(volatile unsigned long *)(0x30000000))
|
|
|
|
#define BCM_WR_ADDR (*(volatile unsigned short*)(0x30010000))
|
|
|
|
#define BCM_WR_ADDR32 (*(volatile unsigned long *)(0x30010000))
|
|
|
|
#define BCM_RD_ADDR (*(volatile unsigned short*)(0x30020000))
|
|
|
|
#define BCM_RD_ADDR32 (*(volatile unsigned long *)(0x30020000))
|
|
|
|
#define BCM_CONTROL (*(volatile unsigned short*)(0x30030000))
|
|
|
|
|
|
|
|
#define BCM_ALT_DATA (*(volatile unsigned short*)(0x30040000))
|
|
|
|
#define BCM_ALT_DATA32 (*(volatile unsigned long *)(0x30040000))
|
|
|
|
#define BCM_ALT_WR_ADDR (*(volatile unsigned short*)(0x30050000))
|
|
|
|
#define BCM_ALT_WR_ADDR32 (*(volatile unsigned long *)(0x30050000))
|
|
|
|
#define BCM_ALT_RD_ADDR (*(volatile unsigned short*)(0x30060000))
|
|
|
|
#define BCM_ALT_RD_ADDR32 (*(volatile unsigned long *)(0x30060000))
|
|
|
|
#define BCM_ALT_CONTROL (*(volatile unsigned short*)(0x30070000))
|
|
|
|
|
2007-11-02 00:07:45 +00:00
|
|
|
/* Time until the BCM is considered stalled and will be re-kicked.
|
|
|
|
* Must be guaranteed to be >~ 20ms. */
|
2009-04-13 18:35:11 +00:00
|
|
|
#define BCM_UPDATE_TIMEOUT (HZ/20)
|
2009-04-12 14:54:12 +00:00
|
|
|
/* An LCD update command done while the LCD is off needs >~ 200ms */
|
|
|
|
#define BCM_LCDINIT_TIMEOUT (HZ/2)
|
2007-11-02 00:07:45 +00:00
|
|
|
|
2009-02-21 11:10:50 +00:00
|
|
|
/* Addresses within BCM */
|
|
|
|
#define BCMA_SRAM_BASE 0
|
|
|
|
#define BCMA_COMMAND 0x1F8
|
|
|
|
#define BCMA_STATUS 0x1FC
|
|
|
|
#define BCMA_CMDPARAM 0xE0000 /* Parameters/data for commands */
|
|
|
|
#define BCMA_SDRAM_BASE 0xC0000000
|
|
|
|
#define BCMA_TV_FB 0xC0000000 /* TV out framebuffer */
|
|
|
|
#define BCMA_TV_BMPDATA 0xC0200000 /* BMP data for TV out functions */
|
|
|
|
|
|
|
|
/* BCM commands. Write them to BCMA_COMMAND. Note BCM_CMD encoding. */
|
|
|
|
#define BCM_CMD(x) ((~((unsigned long)x) << 16) | ((unsigned long)x))
|
|
|
|
#define BCMCMD_LCD_UPDATE BCM_CMD(0)
|
|
|
|
/* Execute "M25 Diagnostics". Status displayed on LCD. Takes <40s */
|
|
|
|
#define BCMCMD_SELFTEST BCM_CMD(1)
|
|
|
|
#define BCMCMD_TV_PALBMP BCM_CMD(2)
|
|
|
|
#define BCMCMD_TV_NTSCBMP BCM_CMD(3)
|
|
|
|
/* BCM_CMD(4) may be another TV-related command */
|
|
|
|
/* The following might do more depending on word at 0xE00000 */
|
|
|
|
#define BCMCMD_LCD_UPDATERECT BCM_CMD(5)
|
|
|
|
#define BCMCMD_LCD_SLEEP BCM_CMD(8)
|
|
|
|
/* BCM_CMD(12) involved in shutdown */
|
2009-04-13 18:35:11 +00:00
|
|
|
/* Macrovision analog copy prevention is on by default on TV output.
|
|
|
|
Execute this command after enabling TV out to turn it off.
|
2009-02-21 11:10:50 +00:00
|
|
|
*/
|
2009-04-13 18:35:11 +00:00
|
|
|
#define BCMCMD_TV_MVOFF BCM_CMD(14)
|
2009-02-21 11:10:50 +00:00
|
|
|
|
2009-04-13 18:35:11 +00:00
|
|
|
enum lcd_status
|
|
|
|
{
|
2007-11-02 00:07:45 +00:00
|
|
|
LCD_IDLE,
|
|
|
|
LCD_INITIAL,
|
|
|
|
LCD_NEED_UPDATE,
|
|
|
|
LCD_UPDATING
|
|
|
|
};
|
|
|
|
|
2009-04-13 18:35:11 +00:00
|
|
|
struct
|
|
|
|
{
|
2009-04-12 14:54:12 +00:00
|
|
|
long update_timeout; /* also used to ensure BCM stays off for >= 50 ms */
|
2007-11-02 00:07:45 +00:00
|
|
|
enum lcd_status state;
|
|
|
|
bool blocked;
|
2007-11-02 00:24:20 +00:00
|
|
|
#if NUM_CORES > 1
|
2007-11-02 00:07:45 +00:00
|
|
|
struct corelock cl; /* inter-core sync */
|
2007-11-02 00:24:20 +00:00
|
|
|
#endif
|
2009-02-21 11:10:50 +00:00
|
|
|
#ifdef HAVE_LCD_SLEEP
|
|
|
|
bool display_on;
|
2009-04-12 14:54:12 +00:00
|
|
|
bool waking;
|
2011-03-02 08:49:38 +00:00
|
|
|
struct semaphore initwakeup;
|
2009-02-21 11:10:50 +00:00
|
|
|
#endif
|
2007-11-02 00:07:45 +00:00
|
|
|
} lcd_state IBSS_ATTR;
|
|
|
|
|
2009-02-21 11:10:50 +00:00
|
|
|
#ifdef HAVE_LCD_SLEEP
|
|
|
|
const fb_data *flash_vmcs_offset;
|
|
|
|
unsigned flash_vmcs_length;
|
|
|
|
|
|
|
|
#define ROM_BASE 0x20000000
|
|
|
|
#define ROM_ID(a,b,c,d) (unsigned int)( ((unsigned int)(d)) | \
|
|
|
|
(((unsigned int)(c)) << 8) | \
|
|
|
|
(((unsigned int)(b)) << 16) | \
|
|
|
|
(((unsigned int)(a)) << 24) )
|
|
|
|
|
|
|
|
/* Get address and length of iPod flash section.
|
|
|
|
Based on part of FS#6721. This may belong elsewhere.
|
|
|
|
(BCM initialization uploads the vmcs section to the BCM.)
|
|
|
|
*/
|
2009-08-06 09:28:25 +00:00
|
|
|
static bool flash_get_section(const unsigned int imageid,
|
|
|
|
void **offset,
|
|
|
|
unsigned int *length)
|
2009-02-21 11:10:50 +00:00
|
|
|
{
|
|
|
|
unsigned long *p = (unsigned long*)(ROM_BASE + 0xffe00);
|
|
|
|
unsigned char *csp, *csend;
|
|
|
|
unsigned long checksum;
|
|
|
|
|
|
|
|
/* Find the image in the directory */
|
2009-04-13 18:35:11 +00:00
|
|
|
while (1)
|
|
|
|
{
|
2009-02-21 11:10:50 +00:00
|
|
|
if (p[0] != ROM_ID('f','l','s','h'))
|
|
|
|
return false;
|
|
|
|
if (p[1] == imageid)
|
|
|
|
break;
|
|
|
|
p += 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
*offset = (void *)(ROM_BASE + p[3]);
|
|
|
|
*length = p[4];
|
|
|
|
|
|
|
|
/* Verify checksum. Probably unnecessary, but it's fast. */
|
|
|
|
checksum = 0;
|
|
|
|
csend = (unsigned char *)(ROM_BASE + p[3] + p[4]);
|
2009-04-13 18:35:11 +00:00
|
|
|
for(csp = (unsigned char *)(ROM_BASE + p[3]); csp < csend; csp++)
|
|
|
|
{
|
2009-02-21 11:10:50 +00:00
|
|
|
checksum += *csp;
|
|
|
|
}
|
|
|
|
|
|
|
|
return checksum == p[7];
|
|
|
|
}
|
|
|
|
#endif /* HAVE_LCD_SLEEP */
|
2007-11-02 00:07:45 +00:00
|
|
|
|
|
|
|
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 */
|
|
|
|
}
|
|
|
|
|
2009-04-12 15:35:57 +00:00
|
|
|
#ifdef HAVE_LCD_SLEEP
|
2009-04-12 14:54:12 +00:00
|
|
|
static void continue_lcd_awake(void)
|
|
|
|
{
|
|
|
|
lcd_state.waking = false;
|
2011-03-02 08:49:38 +00:00
|
|
|
semaphore_release(&(lcd_state.initwakeup));
|
2009-04-12 14:54:12 +00:00
|
|
|
}
|
2009-04-12 15:35:57 +00:00
|
|
|
#endif
|
2009-04-12 14:54:12 +00:00
|
|
|
|
2007-11-02 01:18:14 +00:00
|
|
|
#ifndef BOOTLOADER
|
2007-11-02 00:07:45 +00:00
|
|
|
static void lcd_tick(void)
|
|
|
|
{
|
2008-03-26 01:50:41 +00:00
|
|
|
/* No core level interrupt mask - already in interrupt context */
|
2007-11-02 00:24:20 +00:00
|
|
|
#if NUM_CORES > 1
|
2007-11-02 00:07:45 +00:00
|
|
|
corelock_lock(&lcd_state.cl);
|
2007-11-02 00:24:20 +00:00
|
|
|
#endif
|
2007-11-02 00:07:45 +00:00
|
|
|
|
|
|
|
if (!lcd_state.blocked && lcd_state.state >= LCD_NEED_UPDATE)
|
|
|
|
{
|
2009-02-21 11:10:50 +00:00
|
|
|
unsigned data = bcm_read32(BCMA_COMMAND);
|
|
|
|
bool bcm_is_busy = (data == BCMCMD_LCD_UPDATE || data == 0xFFFF);
|
2009-04-13 18:35:11 +00:00
|
|
|
|
|
|
|
if (((lcd_state.state == LCD_NEED_UPDATE) && !bcm_is_busy)
|
2007-11-02 00:07:45 +00:00
|
|
|
/* 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. */
|
|
|
|
{
|
2009-02-21 11:10:50 +00:00
|
|
|
bcm_write32(BCMA_COMMAND, BCMCMD_LCD_UPDATE); /* Kick off update */
|
2007-11-02 00:07:45 +00:00
|
|
|
BCM_CONTROL = 0x31;
|
|
|
|
lcd_state.update_timeout = current_tick + BCM_UPDATE_TIMEOUT;
|
|
|
|
lcd_state.state = LCD_UPDATING;
|
2009-04-12 15:35:57 +00:00
|
|
|
#ifdef HAVE_LCD_SLEEP
|
2009-04-12 14:54:12 +00:00
|
|
|
if (lcd_state.waking)
|
|
|
|
continue_lcd_awake();
|
2009-04-12 15:35:57 +00:00
|
|
|
#endif
|
2007-11-02 00:07:45 +00:00
|
|
|
}
|
|
|
|
else if ((lcd_state.state == LCD_UPDATING) && !bcm_is_busy)
|
|
|
|
{
|
|
|
|
/* Update finished properly and no new update pending. */
|
|
|
|
lcd_state.state = LCD_IDLE;
|
2009-04-12 15:35:57 +00:00
|
|
|
#ifdef HAVE_LCD_SLEEP
|
2009-04-12 14:54:12 +00:00
|
|
|
if (lcd_state.waking)
|
|
|
|
continue_lcd_awake();
|
2009-04-12 15:35:57 +00:00
|
|
|
#endif
|
2007-11-02 00:07:45 +00:00
|
|
|
}
|
|
|
|
}
|
2007-11-02 00:24:20 +00:00
|
|
|
#if NUM_CORES > 1
|
2007-11-02 00:07:45 +00:00
|
|
|
corelock_unlock(&lcd_state.cl);
|
2007-11-02 00:24:20 +00:00
|
|
|
#endif
|
2007-11-02 00:07:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void lcd_block_tick(void)
|
|
|
|
{
|
2008-03-26 01:50:41 +00:00
|
|
|
int oldlevel = disable_irq_save();
|
2007-11-02 00:07:45 +00:00
|
|
|
|
2007-11-02 00:24:20 +00:00
|
|
|
#if NUM_CORES > 1
|
2007-11-02 00:07:45 +00:00
|
|
|
corelock_lock(&lcd_state.cl);
|
|
|
|
lcd_state.blocked = true;
|
|
|
|
corelock_unlock(&lcd_state.cl);
|
2007-11-02 00:24:20 +00:00
|
|
|
#else
|
|
|
|
lcd_state.blocked = true;
|
|
|
|
#endif
|
2008-03-26 01:50:41 +00:00
|
|
|
restore_irq(oldlevel);
|
2007-11-02 00:07:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void lcd_unblock_and_update(void)
|
|
|
|
{
|
|
|
|
unsigned data;
|
|
|
|
bool bcm_is_busy;
|
2008-03-26 01:50:41 +00:00
|
|
|
int oldlevel = disable_irq_save();
|
2007-11-02 00:07:45 +00:00
|
|
|
|
2007-11-02 00:24:20 +00:00
|
|
|
#if NUM_CORES > 1
|
2007-11-02 00:07:45 +00:00
|
|
|
corelock_lock(&lcd_state.cl);
|
2007-11-02 00:24:20 +00:00
|
|
|
#endif
|
2009-02-21 11:10:50 +00:00
|
|
|
data = bcm_read32(BCMA_COMMAND);
|
|
|
|
bcm_is_busy = (data == BCMCMD_LCD_UPDATE || data == 0xFFFF);
|
2009-04-13 18:35:11 +00:00
|
|
|
|
2007-11-02 00:07:45 +00:00
|
|
|
if (!bcm_is_busy || (lcd_state.state == LCD_INITIAL) ||
|
|
|
|
TIME_AFTER(current_tick, lcd_state.update_timeout))
|
|
|
|
{
|
2009-02-21 11:10:50 +00:00
|
|
|
bcm_write32(BCMA_COMMAND, BCMCMD_LCD_UPDATE); /* Kick off update */
|
2007-11-02 00:07:45 +00:00
|
|
|
BCM_CONTROL = 0x31;
|
|
|
|
lcd_state.update_timeout = current_tick + BCM_UPDATE_TIMEOUT;
|
|
|
|
lcd_state.state = LCD_UPDATING;
|
2009-04-12 15:35:57 +00:00
|
|
|
#ifdef HAVE_LCD_SLEEP
|
2009-04-12 14:54:12 +00:00
|
|
|
if (lcd_state.waking)
|
|
|
|
continue_lcd_awake();
|
2009-04-12 15:35:57 +00:00
|
|
|
#endif
|
2007-11-02 00:07:45 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
lcd_state.state = LCD_NEED_UPDATE; /* Post update request */
|
|
|
|
}
|
|
|
|
lcd_state.blocked = false;
|
2009-04-13 18:35:11 +00:00
|
|
|
|
2007-11-02 00:24:20 +00:00
|
|
|
#if NUM_CORES > 1
|
2007-11-02 00:07:45 +00:00
|
|
|
corelock_unlock(&lcd_state.cl);
|
2007-11-02 00:24:20 +00:00
|
|
|
#endif
|
2008-03-26 01:50:41 +00:00
|
|
|
restore_irq(oldlevel);
|
2007-11-02 00:07:45 +00:00
|
|
|
}
|
|
|
|
|
2007-11-02 01:18:14 +00:00
|
|
|
#else /* BOOTLOADER */
|
|
|
|
|
|
|
|
#define lcd_block_tick()
|
|
|
|
|
|
|
|
static void lcd_unblock_and_update(void)
|
|
|
|
{
|
|
|
|
unsigned data;
|
2009-04-13 18:35:11 +00:00
|
|
|
|
2007-11-02 01:18:14 +00:00
|
|
|
if (lcd_state.state != LCD_INITIAL)
|
|
|
|
{
|
2009-02-21 11:10:50 +00:00
|
|
|
data = bcm_read32(BCMA_COMMAND);
|
|
|
|
while (data == BCMCMD_LCD_UPDATE || data == 0xFFFF)
|
2007-11-02 01:18:14 +00:00
|
|
|
{
|
|
|
|
yield();
|
2009-02-21 11:10:50 +00:00
|
|
|
data = bcm_read32(BCMA_COMMAND);
|
2007-11-02 01:18:14 +00:00
|
|
|
}
|
|
|
|
}
|
2009-02-21 11:10:50 +00:00
|
|
|
bcm_write32(BCMA_COMMAND, BCMCMD_LCD_UPDATE); /* Kick off update */
|
2007-11-02 01:18:14 +00:00
|
|
|
BCM_CONTROL = 0x31;
|
|
|
|
lcd_state.state = LCD_IDLE;
|
|
|
|
}
|
|
|
|
#endif /* BOOTLOADER */
|
|
|
|
|
2005-12-18 13:04:00 +00:00
|
|
|
/*** 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)
|
2007-11-02 00:07:45 +00:00
|
|
|
{
|
2009-02-21 11:10:50 +00:00
|
|
|
/* These port initializations are supposed to be done when initializing
|
|
|
|
the BCM. None of it is changed when shutting down the BCM.
|
|
|
|
*/
|
2009-04-12 14:54:12 +00:00
|
|
|
GPO32_ENABLE |= 0xC000;
|
2009-04-13 18:35:11 +00:00
|
|
|
GPIO_CLEAR_BITWISE(GPIOC_ENABLE, 0x80);
|
2009-02-21 11:10:50 +00:00
|
|
|
/* This pin is used for BCM interrupts */
|
|
|
|
GPIOC_ENABLE |= 0x40;
|
|
|
|
GPIOC_OUTPUT_EN &= ~0x40;
|
|
|
|
GPO32_ENABLE &= ~1;
|
|
|
|
|
2007-11-02 00:07:45 +00:00
|
|
|
lcd_state.blocked = false;
|
|
|
|
lcd_state.state = LCD_INITIAL;
|
2007-11-02 01:18:14 +00:00
|
|
|
#ifndef BOOTLOADER
|
|
|
|
#if NUM_CORES > 1
|
2007-11-02 00:07:45 +00:00
|
|
|
corelock_init(&lcd_state.cl);
|
2009-02-21 11:10:50 +00:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_LCD_SLEEP
|
2009-04-13 18:35:11 +00:00
|
|
|
if (!flash_get_section(ROM_ID('v', 'm', 'c', 's'),
|
2009-02-21 11:10:50 +00:00
|
|
|
(void **)(&flash_vmcs_offset), &flash_vmcs_length))
|
|
|
|
/* BCM cannot be shut down because firmware wasn't found */
|
|
|
|
flash_vmcs_length = 0;
|
2009-04-13 18:35:11 +00:00
|
|
|
else
|
|
|
|
{
|
2009-02-21 11:10:50 +00:00
|
|
|
/* lcd_write_data needs an even number of 16 bit values */
|
|
|
|
flash_vmcs_length = ((flash_vmcs_length + 3) >> 1) & ~1;
|
|
|
|
}
|
2011-03-02 08:49:38 +00:00
|
|
|
semaphore_init(&(lcd_state.initwakeup), 1, 0);
|
2009-04-12 14:54:12 +00:00
|
|
|
lcd_state.waking = false;
|
|
|
|
|
2009-04-13 18:35:11 +00:00
|
|
|
if (GPO32_VAL & 0x4000)
|
2009-04-12 14:54:12 +00:00
|
|
|
{
|
|
|
|
/* BCM is powered. Assume it is initialized. */
|
|
|
|
lcd_state.display_on = true;
|
|
|
|
tick_add_task(&lcd_tick);
|
|
|
|
}
|
2009-04-13 18:35:11 +00:00
|
|
|
else
|
2009-04-12 14:54:12 +00:00
|
|
|
{
|
2009-04-13 18:35:11 +00:00
|
|
|
/* BCM is not powered, so it needs to be initialized.
|
2009-04-12 14:54:12 +00:00
|
|
|
This can only happen when loading Rockbox via ROLO.
|
|
|
|
*/
|
|
|
|
lcd_state.update_timeout = current_tick;
|
|
|
|
lcd_state.display_on = false;
|
|
|
|
lcd_awake();
|
|
|
|
}
|
|
|
|
#else /* !HAVE_LCD_SLEEP */
|
2007-11-02 00:07:45 +00:00
|
|
|
tick_add_task(&lcd_tick);
|
2009-04-13 18:35:11 +00:00
|
|
|
#endif
|
2007-11-02 01:18:14 +00:00
|
|
|
#endif /* !BOOTLOADER */
|
2005-12-18 13:04:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*** update functions ***/
|
|
|
|
|
|
|
|
/* Update a fraction of the display. */
|
|
|
|
void lcd_update_rect(int x, int y, int width, int height)
|
|
|
|
{
|
2007-10-28 12:09:46 +00:00
|
|
|
const fb_data *addr;
|
2007-11-02 00:07:45 +00:00
|
|
|
unsigned bcmaddr;
|
2007-10-28 12:09:46 +00:00
|
|
|
|
2009-02-21 11:10:50 +00:00
|
|
|
#ifdef HAVE_LCD_SLEEP
|
|
|
|
if (!lcd_state.display_on)
|
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
|
2007-10-28 12:09:46 +00:00
|
|
|
if (x + width >= LCD_WIDTH)
|
|
|
|
width = LCD_WIDTH - x;
|
|
|
|
if (y + height >= LCD_HEIGHT)
|
|
|
|
height = LCD_HEIGHT - y;
|
2009-04-13 18:35:11 +00:00
|
|
|
|
2007-10-28 12:09:46 +00:00
|
|
|
if ((width <= 0) || (height <= 0))
|
2007-11-02 00:07:45 +00:00
|
|
|
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;
|
2009-04-13 18:35:11 +00:00
|
|
|
|
2007-11-02 00:07:45 +00:00
|
|
|
/* Prevent the tick from triggering BCM updates while we're writing. */
|
|
|
|
lcd_block_tick();
|
|
|
|
|
2012-02-22 10:18:05 +00:00
|
|
|
addr = FBADDR(x, y);
|
2009-02-21 11:10:50 +00:00
|
|
|
bcmaddr = BCMA_CMDPARAM + (LCD_WIDTH*2) * y + (x << 1);
|
2007-10-28 12:09:46 +00:00
|
|
|
|
2007-11-02 00:07:45 +00:00
|
|
|
if (width == LCD_WIDTH)
|
2007-10-16 19:47:15 +00:00
|
|
|
{
|
2007-11-02 00:07:45 +00:00
|
|
|
bcm_write_addr(bcmaddr);
|
|
|
|
lcd_write_data(addr, width * height);
|
2006-02-16 23:17:49 +00:00
|
|
|
}
|
2007-11-02 00:07:45 +00:00
|
|
|
else
|
2006-03-08 04:14:30 +00:00
|
|
|
{
|
2007-11-02 00:07:45 +00:00
|
|
|
do
|
|
|
|
{
|
|
|
|
bcm_write_addr(bcmaddr);
|
|
|
|
bcmaddr += (LCD_WIDTH*2);
|
|
|
|
lcd_write_data(addr, width);
|
|
|
|
addr += LCD_WIDTH;
|
|
|
|
}
|
|
|
|
while (--height > 0);
|
2005-12-18 13:04:00 +00:00
|
|
|
}
|
2007-11-02 00:07:45 +00:00
|
|
|
lcd_unblock_and_update();
|
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
|
|
|
|
2007-11-26 23:48:23 +00:00
|
|
|
/* 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],
|
|
|
|
unsigned bcmaddr,
|
|
|
|
int width,
|
|
|
|
int stride);
|
2009-04-13 18:35:11 +00:00
|
|
|
|
2006-08-08 21:28:08 +00:00
|
|
|
/* Performance function to blit a YUV bitmap directly to the LCD */
|
2008-03-24 00:35:53 +00:00
|
|
|
void lcd_blit_yuv(unsigned char * const src[3],
|
2006-08-08 21:28:08 +00:00
|
|
|
int src_x, int src_y, int stride,
|
|
|
|
int x, int y, int width, int height)
|
|
|
|
{
|
2007-11-02 00:07:45 +00:00
|
|
|
unsigned bcmaddr;
|
2007-10-22 00:37:50 +00:00
|
|
|
off_t z;
|
2007-11-02 00:07:45 +00:00
|
|
|
unsigned char const * yuv_src[3];
|
2007-10-22 00:37:50 +00:00
|
|
|
|
2009-02-21 11:10:50 +00:00
|
|
|
#ifdef HAVE_LCD_SLEEP
|
|
|
|
if (!lcd_state.display_on)
|
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
|
2007-10-22 00:37:50 +00:00
|
|
|
/* Sorry, but width and height must be >= 2 or else */
|
|
|
|
width &= ~1;
|
|
|
|
|
|
|
|
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]);
|
2006-08-08 21:28:08 +00:00
|
|
|
|
2007-11-02 00:07:45 +00:00
|
|
|
/* Prevent the tick from triggering BCM updates while we're writing. */
|
|
|
|
lcd_block_tick();
|
|
|
|
|
2009-02-21 11:10:50 +00:00
|
|
|
bcmaddr = BCMA_CMDPARAM + (LCD_WIDTH*2) * y + (x << 1);
|
2007-11-02 00:07:45 +00:00
|
|
|
height >>= 1;
|
|
|
|
|
2007-11-26 23:48:23 +00:00
|
|
|
do
|
2006-08-08 21:28:08 +00:00
|
|
|
{
|
2007-11-26 23:48:23 +00:00
|
|
|
lcd_write_yuv420_lines(yuv_src, bcmaddr, width, stride);
|
|
|
|
bcmaddr += (LCD_WIDTH*4); /* Skip up two lines */
|
|
|
|
yuv_src[0] += stride << 1;
|
|
|
|
yuv_src[1] += stride >> 1; /* Skip down one chroma line */
|
|
|
|
yuv_src[2] += stride >> 1;
|
2009-04-13 18:35:11 +00:00
|
|
|
}
|
2007-11-26 23:48:23 +00:00
|
|
|
while (--height > 0);
|
2009-04-13 18:35:11 +00:00
|
|
|
|
2007-11-02 00:07:45 +00:00
|
|
|
lcd_unblock_and_update();
|
2006-08-08 21:28:08 +00:00
|
|
|
}
|
2009-02-21 11:10:50 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_LCD_SLEEP
|
2009-04-13 18:35:11 +00:00
|
|
|
/* Executes a BCM command immediately and waits for it to complete.
|
2009-02-21 11:10:50 +00:00
|
|
|
Other BCM commands (eg. LCD updates or lcd_tick) must not interfere.
|
|
|
|
*/
|
2009-04-13 18:35:11 +00:00
|
|
|
static void bcm_command(unsigned cmd)
|
|
|
|
{
|
2009-02-21 11:10:50 +00:00
|
|
|
unsigned status;
|
2009-04-13 18:35:11 +00:00
|
|
|
|
2009-02-21 11:10:50 +00:00
|
|
|
bcm_write32(BCMA_COMMAND, cmd);
|
|
|
|
|
|
|
|
BCM_CONTROL = 0x31;
|
|
|
|
|
2009-04-13 18:35:11 +00:00
|
|
|
while (1)
|
|
|
|
{
|
2009-02-21 11:10:50 +00:00
|
|
|
status = bcm_read32(BCMA_COMMAND);
|
|
|
|
if (status != cmd && status != 0xFFFF)
|
|
|
|
break;
|
|
|
|
yield();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-06 09:28:25 +00:00
|
|
|
static void bcm_powerdown(void)
|
2009-02-21 11:10:50 +00:00
|
|
|
{
|
2011-01-10 20:56:19 +00:00
|
|
|
/* Immediately switch off the backlight to avoid flashing. */
|
|
|
|
_backlight_hw_enable(false);
|
|
|
|
|
|
|
|
/* Not sure what this does. */
|
2009-02-21 11:10:50 +00:00
|
|
|
bcm_write32(0x10001400, bcm_read32(0x10001400) & ~0xF0);
|
|
|
|
|
2009-04-13 18:35:11 +00:00
|
|
|
/* Blanks the LCD and decreases power consumption
|
2009-02-21 11:10:50 +00:00
|
|
|
below what clearing the LCD would achieve.
|
|
|
|
Executing an LCD update command wakes it.
|
|
|
|
*/
|
|
|
|
bcm_command(BCMCMD_LCD_SLEEP);
|
|
|
|
|
|
|
|
/* Not sure if this does anything */
|
|
|
|
bcm_command(BCM_CMD(0xC));
|
|
|
|
|
|
|
|
/* Further cuts power use, probably by powering down BCM.
|
|
|
|
After this point, BCM needs to be bootstrapped
|
|
|
|
*/
|
|
|
|
GPO32_VAL &= ~0x4000;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Data written to BCM_CONTROL and BCM_ALT_CONTROL */
|
2009-04-13 18:35:11 +00:00
|
|
|
const unsigned char bcm_bootstrapdata[] =
|
|
|
|
{
|
2009-02-21 11:10:50 +00:00
|
|
|
0xA1, 0x81, 0x91, 0x02, 0x12, 0x22, 0x72, 0x62
|
|
|
|
};
|
|
|
|
|
2009-08-06 09:28:25 +00:00
|
|
|
static void bcm_init(void)
|
2009-02-21 11:10:50 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Power up BCM */
|
|
|
|
GPO32_VAL |= 0x4000;
|
2009-04-13 18:35:11 +00:00
|
|
|
sleep(HZ/20);
|
2009-02-21 11:10:50 +00:00
|
|
|
|
|
|
|
/* Bootstrap stage 1 */
|
|
|
|
|
|
|
|
STRAP_OPT_A &= ~0xF00;
|
|
|
|
outl(0x1313, 0x70000040);
|
|
|
|
|
|
|
|
/* Interrupt-related code for future use
|
|
|
|
GPIOC_INT_LEV |= 0x40;
|
|
|
|
GPIOC_INT_EN |= 0x40;
|
2009-04-13 18:35:11 +00:00
|
|
|
CPU_HI_INT_EN |= 0x40000;
|
2009-02-21 11:10:50 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* Bootstrap stage 2 */
|
2009-04-12 14:54:12 +00:00
|
|
|
|
|
|
|
while (BCM_ALT_CONTROL & 0x80);
|
|
|
|
while (!(BCM_ALT_CONTROL & 0x40));
|
|
|
|
|
2009-04-13 18:35:11 +00:00
|
|
|
for (i = 0; i < 8; i++)
|
|
|
|
{
|
2009-02-21 11:10:50 +00:00
|
|
|
BCM_CONTROL = bcm_bootstrapdata[i];
|
|
|
|
}
|
|
|
|
|
2009-04-13 18:35:11 +00:00
|
|
|
for (i = 3; i < 8; i++)
|
|
|
|
{
|
2009-02-21 11:10:50 +00:00
|
|
|
BCM_ALT_CONTROL = bcm_bootstrapdata[i];
|
|
|
|
}
|
2009-04-13 18:35:11 +00:00
|
|
|
|
2009-04-12 14:54:12 +00:00
|
|
|
while ((BCM_RD_ADDR & 1) == 0 || (BCM_ALT_RD_ADDR & 1) == 0);
|
2009-04-13 18:35:11 +00:00
|
|
|
|
2009-02-21 11:10:50 +00:00
|
|
|
(void)BCM_WR_ADDR;
|
|
|
|
(void)BCM_ALT_WR_ADDR;
|
2009-04-13 18:35:11 +00:00
|
|
|
|
2009-02-21 11:10:50 +00:00
|
|
|
/* Bootstrap stage 3: upload firmware */
|
2009-04-13 18:35:11 +00:00
|
|
|
|
2009-04-12 14:54:12 +00:00
|
|
|
while (BCM_ALT_CONTROL & 0x80);
|
|
|
|
while (!(BCM_ALT_CONTROL & 0x40));
|
2009-02-21 11:10:50 +00:00
|
|
|
|
|
|
|
/* Upload firmware to BCM SRAM */
|
|
|
|
bcm_write_addr(BCMA_SRAM_BASE);
|
|
|
|
lcd_write_data(flash_vmcs_offset, flash_vmcs_length);
|
|
|
|
|
|
|
|
bcm_write32(BCMA_COMMAND, 0);
|
|
|
|
bcm_write32(0x10000C00, 0xC0000000);
|
2009-04-13 18:35:11 +00:00
|
|
|
|
2009-04-12 14:54:12 +00:00
|
|
|
while (!(bcm_read32(0x10000C00) & 1));
|
2009-04-13 18:35:11 +00:00
|
|
|
|
2009-02-21 11:10:50 +00:00
|
|
|
bcm_write32(0x10000C00, 0);
|
|
|
|
bcm_write32(0x10000400, 0xA5A50002);
|
2009-04-13 18:35:11 +00:00
|
|
|
|
2009-02-21 11:10:50 +00:00
|
|
|
while (bcm_read32(BCMA_COMMAND) == 0)
|
|
|
|
yield();
|
|
|
|
|
|
|
|
/* sleep(HZ/2) apparently unneeded */
|
|
|
|
}
|
|
|
|
|
|
|
|
void lcd_awake(void)
|
|
|
|
{
|
|
|
|
if (!lcd_state.display_on && flash_vmcs_length != 0)
|
|
|
|
{
|
2009-04-12 14:54:12 +00:00
|
|
|
/* Ensure BCM has been off for >= 50 ms */
|
|
|
|
long sleepwait = lcd_state.update_timeout + HZ/20 - current_tick;
|
|
|
|
if (sleepwait > 0 && sleepwait < HZ/20)
|
|
|
|
sleep(sleepwait);
|
2009-02-21 11:10:50 +00:00
|
|
|
|
|
|
|
bcm_init();
|
|
|
|
|
2009-04-12 14:54:12 +00:00
|
|
|
/* Start the first LCD update, which also initializes the LCD */
|
2009-02-21 11:10:50 +00:00
|
|
|
lcd_state.state = LCD_INITIAL;
|
|
|
|
lcd_state.display_on = true;
|
2009-04-12 14:54:12 +00:00
|
|
|
lcd_update();
|
|
|
|
lcd_state.update_timeout = current_tick + BCM_LCDINIT_TIMEOUT;
|
|
|
|
|
2009-04-13 18:35:11 +00:00
|
|
|
/* Wait for end of first LCD update, so LCD isn't white
|
2009-04-12 14:54:12 +00:00
|
|
|
when the backlight turns on.
|
|
|
|
*/
|
|
|
|
lcd_state.waking = true;
|
|
|
|
tick_add_task(&lcd_tick);
|
2011-03-02 08:49:38 +00:00
|
|
|
semaphore_wait(&(lcd_state.initwakeup), TIMEOUT_BLOCK);
|
2009-04-12 14:54:12 +00:00
|
|
|
|
2009-10-20 21:54:59 +00:00
|
|
|
send_event(LCD_EVENT_ACTIVATION, NULL);
|
2009-02-21 11:10:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-13 18:35:11 +00:00
|
|
|
void lcd_sleep(void)
|
2009-02-21 11:10:50 +00:00
|
|
|
{
|
2009-04-13 18:35:11 +00:00
|
|
|
if (lcd_state.display_on && flash_vmcs_length != 0)
|
|
|
|
{
|
2009-02-21 11:10:50 +00:00
|
|
|
lcd_state.display_on = false;
|
2009-04-13 18:35:11 +00:00
|
|
|
|
2009-02-21 11:10:50 +00:00
|
|
|
/* Wait for BCM to finish work */
|
|
|
|
while (lcd_state.state != LCD_INITIAL && lcd_state.state != LCD_IDLE)
|
|
|
|
yield();
|
2009-04-13 18:35:11 +00:00
|
|
|
|
2009-02-21 11:10:50 +00:00
|
|
|
tick_remove_task(&lcd_tick);
|
|
|
|
bcm_powerdown();
|
2009-04-12 14:54:12 +00:00
|
|
|
|
|
|
|
/* Remember time to ensure BCM stays off for >= 50 ms */
|
|
|
|
lcd_state.update_timeout = current_tick;
|
2009-02-21 11:10:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-17 03:36:36 +00:00
|
|
|
bool lcd_active(void)
|
|
|
|
{
|
2009-03-17 04:01:11 +00:00
|
|
|
return lcd_state.display_on;
|
2009-03-17 03:36:36 +00:00
|
|
|
}
|
|
|
|
|
2009-02-21 11:10:50 +00:00
|
|
|
#ifdef HAVE_LCD_SHUTDOWN
|
2009-04-13 18:35:11 +00:00
|
|
|
void lcd_shutdown(void)
|
2009-02-21 11:10:50 +00:00
|
|
|
{
|
|
|
|
lcd_sleep();
|
|
|
|
}
|
|
|
|
#endif /* HAVE_LCD_SHUTDOWN */
|
|
|
|
#endif /* HAVE_LCD_SLEEP */
|