2007-02-25 13:11:02 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Rockbox driver for iPod LCDs
|
|
|
|
*
|
|
|
|
* Based on code from the ipodlinux project - http://ipodlinux.org/
|
|
|
|
* Adapted for Rockbox in November 2005
|
|
|
|
*
|
|
|
|
* Original file: linux/arch/armnommu/mach-ipod/fb.c
|
|
|
|
*
|
|
|
|
* Copyright (c) 2003-2005 Bernard Leach (leachbj@bouncycastle.org)
|
|
|
|
*
|
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.
|
2007-02-25 13:11:02 +00:00
|
|
|
*
|
|
|
|
* 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"
|
2007-08-10 08:09:53 +00:00
|
|
|
#include "hwcompat.h"
|
2007-02-25 13:11:02 +00:00
|
|
|
|
2007-08-08 07:57:34 +00:00
|
|
|
/* LCD command codes for HD66753 */
|
|
|
|
|
2007-02-25 13:11:02 +00:00
|
|
|
#define R_START_OSC 0x00
|
|
|
|
#define R_DRV_OUTPUT_CONTROL 0x01
|
|
|
|
#define R_DRV_WAVEFORM_CONTROL 0x02
|
|
|
|
#define R_POWER_CONTROL 0x03
|
|
|
|
#define R_CONTRAST_CONTROL 0x04
|
|
|
|
#define R_ENTRY_MODE 0x05
|
|
|
|
#define R_ROTATION 0x06
|
|
|
|
#define R_DISPLAY_CONTROL 0x07
|
|
|
|
#define R_CURSOR_CONTROL 0x08
|
|
|
|
#define R_HORIZONTAL_CURSOR_POS 0x0b
|
|
|
|
#define R_VERTICAL_CURSOR_POS 0x0c
|
|
|
|
#define R_1ST_SCR_DRV_POS 0x0d
|
|
|
|
#define R_2ND_SCR_DRV_POS 0x0e
|
|
|
|
#define R_RAM_WRITE_MASK 0x10
|
|
|
|
#define R_RAM_ADDR_SET 0x11
|
|
|
|
#define R_RAM_DATA 0x12
|
|
|
|
|
2007-07-27 12:05:54 +00:00
|
|
|
#ifdef HAVE_BACKLIGHT_INVERSION
|
|
|
|
/* The backlight makes the LCD appear negative on the 1st/2nd gen */
|
|
|
|
static bool lcd_inverted = false;
|
|
|
|
static bool lcd_backlit = false;
|
2008-04-04 22:13:53 +00:00
|
|
|
#if NUM_CORES > 1
|
|
|
|
/* invert_display() and the lcd_blit_* functions need to be corelocked */
|
|
|
|
static struct corelock cl IBSS_ATTR;
|
|
|
|
#endif
|
2007-07-27 12:40:36 +00:00
|
|
|
static void invert_display(void);
|
2007-07-27 12:05:54 +00:00
|
|
|
#endif
|
|
|
|
|
2007-08-10 08:09:53 +00:00
|
|
|
#if defined(IPOD_1G2G) || defined(IPOD_3G)
|
2008-04-02 19:01:16 +00:00
|
|
|
#define POWER_REG_H 0x1120 /* 1/7 Bias, 5x step-up @ clk/8 */
|
2007-08-10 08:09:53 +00:00
|
|
|
#else
|
2008-04-02 19:01:16 +00:00
|
|
|
#define POWER_REG_H 0x1200 /* 1/7 Bias, 6x step-up @ clk/32 */
|
2007-08-10 08:09:53 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#define CONTRAST_REG_H 0x400
|
|
|
|
|
2008-08-15 19:19:46 +00:00
|
|
|
#if defined(IPOD_1G2G)
|
|
|
|
#define DEFAULT_CONTRAST 45
|
|
|
|
#elif defined(IPOD_3G)
|
|
|
|
#define DEFAULT_CONTRAST 55
|
|
|
|
#elif defined(IPOD_MINI) || defined(IPOD_MINI2G)
|
|
|
|
#define DEFAULT_CONTRAST 42
|
|
|
|
#elif defined(IPOD_4G)
|
|
|
|
#define DEFAULT_CONTRAST 35
|
|
|
|
#endif
|
|
|
|
|
2007-02-25 13:11:02 +00:00
|
|
|
/* needed for flip */
|
|
|
|
static int addr_offset;
|
|
|
|
#if defined(IPOD_MINI) || defined(IPOD_MINI2G)
|
|
|
|
static int pix_offset;
|
2008-01-12 00:59:18 +00:00
|
|
|
void lcd_write_data_shifted(const fb_data* p_bytes, int count);
|
2007-02-25 13:11:02 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* wait for LCD with timeout */
|
|
|
|
static inline void lcd_wait_write(void)
|
|
|
|
{
|
2007-10-12 00:28:57 +00:00
|
|
|
while (LCD1_CONTROL & LCD1_BUSY_MASK);
|
2007-02-25 13:11:02 +00:00
|
|
|
}
|
|
|
|
|
2008-01-12 00:59:18 +00:00
|
|
|
/* send LCD command */
|
|
|
|
static void lcd_prepare_cmd(unsigned cmd)
|
2007-02-25 13:11:02 +00:00
|
|
|
{
|
|
|
|
lcd_wait_write();
|
|
|
|
#ifdef IPOD_MINI2G
|
2008-01-12 00:59:18 +00:00
|
|
|
LCD1_CMD = cmd | 0x740000;
|
2007-02-25 13:11:02 +00:00
|
|
|
#else
|
2008-01-12 00:59:18 +00:00
|
|
|
LCD1_CMD = 0;
|
2007-02-25 13:11:02 +00:00
|
|
|
lcd_wait_write();
|
2008-01-12 00:59:18 +00:00
|
|
|
LCD1_CMD = cmd;
|
2007-02-25 13:11:02 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2008-01-12 00:59:18 +00:00
|
|
|
/* send LCD command and data */
|
|
|
|
static void lcd_cmd_and_data(unsigned cmd, unsigned data)
|
2007-02-25 13:11:02 +00:00
|
|
|
{
|
|
|
|
lcd_wait_write();
|
|
|
|
#ifdef IPOD_MINI2G
|
2007-10-07 16:44:55 +00:00
|
|
|
LCD1_CMD = cmd | 0x740000;
|
2008-01-12 00:59:18 +00:00
|
|
|
lcd_wait_write();
|
|
|
|
LCD1_CMD = data | 0x760000;
|
2007-02-25 13:11:02 +00:00
|
|
|
#else
|
2007-10-07 16:44:55 +00:00
|
|
|
LCD1_CMD = 0;
|
2007-02-25 13:11:02 +00:00
|
|
|
lcd_wait_write();
|
2007-10-07 16:44:55 +00:00
|
|
|
LCD1_CMD = cmd;
|
2008-01-12 00:59:18 +00:00
|
|
|
lcd_wait_write();
|
|
|
|
LCD1_DATA = data >> 8;
|
|
|
|
lcd_wait_write();
|
|
|
|
LCD1_DATA = data & 0xff;
|
2007-02-25 13:11:02 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/* LCD init */
|
|
|
|
void lcd_init_device(void)
|
|
|
|
{
|
2008-04-04 22:13:53 +00:00
|
|
|
#if (NUM_CORES > 1) && defined(HAVE_BACKLIGHT_INVERSION)
|
|
|
|
corelock_init(&cl);
|
|
|
|
#endif
|
2007-11-18 12:49:24 +00:00
|
|
|
#ifdef IPOD_MINI2G /* serial LCD hookup */
|
2007-08-10 08:09:53 +00:00
|
|
|
lcd_wait_write();
|
2007-11-18 12:49:24 +00:00
|
|
|
LCD1_CONTROL = 0x01730084; /* fastest setting */
|
|
|
|
#elif defined(IPOD_1G2G) || defined(IPOD_3G)
|
2008-04-02 19:01:16 +00:00
|
|
|
LCD1_CONTROL = (LCD1_CONTROL & 0x0002) | 0x0084;
|
|
|
|
/* fastest setting, keep backlight bit */
|
2007-11-18 12:49:24 +00:00
|
|
|
#else
|
|
|
|
LCD1_CONTROL = 0x0084; /* fastest setting */
|
2007-08-10 08:09:53 +00:00
|
|
|
#endif
|
|
|
|
|
2008-04-02 19:01:16 +00:00
|
|
|
lcd_cmd_and_data(R_DRV_WAVEFORM_CONTROL, 0x48);
|
|
|
|
/* C waveform, no EOR, 9 lines inversion */
|
2007-08-10 08:09:53 +00:00
|
|
|
lcd_cmd_and_data(R_POWER_CONTROL, POWER_REG_H | 0xc);
|
2008-05-17 09:55:23 +00:00
|
|
|
lcd_cmd_and_data(R_DISPLAY_CONTROL, 0x0019);
|
2008-08-15 19:19:46 +00:00
|
|
|
lcd_set_contrast(DEFAULT_CONTRAST);
|
2007-07-27 12:40:36 +00:00
|
|
|
#ifdef HAVE_BACKLIGHT_INVERSION
|
|
|
|
invert_display();
|
|
|
|
#endif
|
2007-02-25 13:11:02 +00:00
|
|
|
lcd_set_flip(false);
|
|
|
|
lcd_cmd_and_data(R_ENTRY_MODE, 0x0000);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*** hardware configuration ***/
|
|
|
|
|
|
|
|
int lcd_default_contrast(void)
|
|
|
|
{
|
2008-08-15 19:19:46 +00:00
|
|
|
return DEFAULT_CONTRAST;
|
2007-02-25 13:11:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Rockbox stores the contrast as 0..63 - we add 64 to it */
|
|
|
|
void lcd_set_contrast(int val)
|
|
|
|
{
|
|
|
|
if (val < 0) val = 0;
|
|
|
|
else if (val > 63) val = 63;
|
|
|
|
|
2007-08-10 08:09:53 +00:00
|
|
|
lcd_cmd_and_data(R_CONTRAST_CONTROL, CONTRAST_REG_H | (val + 64));
|
2007-02-25 13:11:02 +00:00
|
|
|
}
|
|
|
|
|
2007-07-27 12:05:54 +00:00
|
|
|
#ifdef HAVE_BACKLIGHT_INVERSION
|
|
|
|
static void invert_display(void)
|
|
|
|
{
|
2008-04-04 17:33:39 +00:00
|
|
|
static bool last_invert = false;
|
|
|
|
bool new_invert = lcd_inverted ^ lcd_backlit;
|
|
|
|
|
|
|
|
if (new_invert != last_invert)
|
|
|
|
{
|
|
|
|
int oldlevel = disable_irq_save();
|
2008-04-04 22:13:53 +00:00
|
|
|
#if NUM_CORES > 1
|
|
|
|
corelock_lock(&cl);
|
2008-05-17 09:55:23 +00:00
|
|
|
lcd_cmd_and_data(R_DISPLAY_CONTROL, new_invert? 0x0027 : 0x0019);
|
2008-04-04 22:13:53 +00:00
|
|
|
corelock_unlock(&cl);
|
|
|
|
#else
|
2008-05-17 09:55:23 +00:00
|
|
|
lcd_cmd_and_data(R_DISPLAY_CONTROL, new_invert? 0x0027 : 0x0019);
|
2008-04-04 22:13:53 +00:00
|
|
|
#endif
|
2008-04-04 17:33:39 +00:00
|
|
|
restore_irq(oldlevel);
|
|
|
|
last_invert = new_invert;
|
|
|
|
}
|
2007-07-27 12:05:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void lcd_set_invert_display(bool yesno)
|
|
|
|
{
|
|
|
|
lcd_inverted = yesno;
|
|
|
|
invert_display();
|
|
|
|
}
|
|
|
|
|
|
|
|
void lcd_set_backlight_inversion(bool yesno)
|
|
|
|
{
|
|
|
|
lcd_backlit = yesno;
|
|
|
|
invert_display();
|
|
|
|
}
|
|
|
|
#else
|
2007-02-25 13:11:02 +00:00
|
|
|
void lcd_set_invert_display(bool yesno)
|
|
|
|
{
|
2008-05-17 09:55:23 +00:00
|
|
|
lcd_cmd_and_data(R_DISPLAY_CONTROL, yesno ? 0x0027 : 0x0019);
|
2007-02-25 13:11:02 +00:00
|
|
|
}
|
2007-07-27 12:05:54 +00:00
|
|
|
#endif
|
2007-02-25 13:11:02 +00:00
|
|
|
|
|
|
|
/* turn the display upside down (call lcd_update() afterwards) */
|
|
|
|
void lcd_set_flip(bool yesno)
|
|
|
|
{
|
|
|
|
#if defined(IPOD_MINI) || defined(IPOD_MINI2G)
|
2008-01-12 00:59:18 +00:00
|
|
|
if (yesno)
|
|
|
|
{ /* 168x112, inverse COM order */
|
2007-02-25 13:11:02 +00:00
|
|
|
lcd_cmd_and_data(R_DRV_OUTPUT_CONTROL, 0x020d);
|
|
|
|
lcd_cmd_and_data(R_1ST_SCR_DRV_POS, 0x8316); /* 22..131 */
|
|
|
|
addr_offset = (22 << 5) | (20 - 4);
|
|
|
|
pix_offset = -2;
|
2008-01-12 00:59:18 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{ /* 168x112, inverse SEG order */
|
2007-02-25 13:11:02 +00:00
|
|
|
lcd_cmd_and_data(R_DRV_OUTPUT_CONTROL, 0x010d);
|
|
|
|
lcd_cmd_and_data(R_1ST_SCR_DRV_POS, 0x6d00); /* 0..109 */
|
|
|
|
addr_offset = 20;
|
|
|
|
pix_offset = 0;
|
|
|
|
}
|
|
|
|
#else
|
2008-01-12 00:59:18 +00:00
|
|
|
if (yesno)
|
|
|
|
{ /* 168x128, inverse SEG & COM order */
|
2007-02-25 13:11:02 +00:00
|
|
|
lcd_cmd_and_data(R_DRV_OUTPUT_CONTROL, 0x030f);
|
|
|
|
lcd_cmd_and_data(R_1ST_SCR_DRV_POS, 0x8304); /* 4..131 */
|
|
|
|
addr_offset = (4 << 5) | (20 - 1);
|
2008-01-12 00:59:18 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{ /* 168x128 */
|
2007-02-25 13:11:02 +00:00
|
|
|
lcd_cmd_and_data(R_DRV_OUTPUT_CONTROL, 0x000f);
|
|
|
|
lcd_cmd_and_data(R_1ST_SCR_DRV_POS, 0x7f00); /* 0..127 */
|
|
|
|
addr_offset = 20;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2008-07-16 11:02:14 +00:00
|
|
|
#ifdef HAVE_LCD_ENABLE
|
2007-08-10 08:09:53 +00:00
|
|
|
void lcd_enable(bool on)
|
|
|
|
{
|
|
|
|
if (on)
|
|
|
|
{
|
|
|
|
lcd_cmd_and_data(R_START_OSC, 1); /* start oscillation */
|
|
|
|
sleep(HZ/10); /* wait 10ms */
|
|
|
|
lcd_cmd_and_data(R_POWER_CONTROL, POWER_REG_H); /*clear standby mode */
|
|
|
|
lcd_cmd_and_data(R_POWER_CONTROL, POWER_REG_H | 0xc);
|
|
|
|
/* enable opamp & booster */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
lcd_cmd_and_data(R_POWER_CONTROL, POWER_REG_H);
|
|
|
|
/* switch off opamp & booster */
|
|
|
|
lcd_cmd_and_data(R_POWER_CONTROL, POWER_REG_H | 0x1);
|
|
|
|
/* enter standby mode */
|
|
|
|
}
|
|
|
|
}
|
2008-07-16 11:02:14 +00:00
|
|
|
#endif /* HAVE_LCD_ENABLE */
|
2007-08-10 08:09:53 +00:00
|
|
|
|
2007-02-25 13:11:02 +00:00
|
|
|
/*** update functions ***/
|
|
|
|
|
2008-01-12 00:59:18 +00:00
|
|
|
/* Helper function. */
|
|
|
|
void lcd_mono_data(const unsigned char *data, int count);
|
|
|
|
|
2007-02-25 13:11:02 +00:00
|
|
|
/* Performance function that works with an external buffer
|
|
|
|
note that x, bwidtht and stride are in 8-pixel units! */
|
2008-03-24 00:35:53 +00:00
|
|
|
void lcd_blit_mono(const unsigned char *data, int bx, int y, int bwidth,
|
|
|
|
int height, int stride)
|
2007-02-25 13:11:02 +00:00
|
|
|
{
|
2008-04-04 22:13:53 +00:00
|
|
|
#if (NUM_CORES > 1) && defined(HAVE_BACKLIGHT_INVERSION)
|
|
|
|
corelock_lock(&cl);
|
|
|
|
#endif
|
2008-01-12 00:59:18 +00:00
|
|
|
while (height--)
|
|
|
|
{
|
2007-02-25 13:11:02 +00:00
|
|
|
lcd_cmd_and_data(R_RAM_ADDR_SET, (y++ << 5) + addr_offset - bx);
|
|
|
|
lcd_prepare_cmd(R_RAM_DATA);
|
2008-01-12 00:59:18 +00:00
|
|
|
lcd_mono_data(data, bwidth);
|
2007-02-25 13:11:02 +00:00
|
|
|
data += stride;
|
|
|
|
}
|
2008-04-04 22:13:53 +00:00
|
|
|
#if (NUM_CORES > 1) && defined(HAVE_BACKLIGHT_INVERSION)
|
|
|
|
corelock_unlock(&cl);
|
|
|
|
#endif
|
2007-02-25 13:11:02 +00:00
|
|
|
}
|
|
|
|
|
2008-01-12 00:59:18 +00:00
|
|
|
/* Helper function for lcd_grey_phase_blit(). */
|
|
|
|
void lcd_grey_data(unsigned char *values, unsigned char *phases, int count);
|
|
|
|
|
2008-01-04 23:42:38 +00:00
|
|
|
/* Performance function that works with an external buffer
|
|
|
|
note that bx and bwidth are in 8-pixel units! */
|
2008-03-24 00:35:53 +00:00
|
|
|
void lcd_blit_grey_phase(unsigned char *values, unsigned char *phases,
|
2008-01-09 23:48:26 +00:00
|
|
|
int bx, int y, int bwidth, int height, int stride)
|
2008-01-04 23:42:38 +00:00
|
|
|
{
|
2008-04-04 22:13:53 +00:00
|
|
|
#if (NUM_CORES > 1) && defined(HAVE_BACKLIGHT_INVERSION)
|
|
|
|
corelock_lock(&cl);
|
|
|
|
#endif
|
|
|
|
while (height--)
|
2008-01-12 00:59:18 +00:00
|
|
|
{
|
2008-01-04 23:42:38 +00:00
|
|
|
lcd_cmd_and_data(R_RAM_ADDR_SET, (y++ << 5) + addr_offset - bx);
|
|
|
|
lcd_prepare_cmd(R_RAM_DATA);
|
2008-01-12 00:59:18 +00:00
|
|
|
lcd_grey_data(values, phases, bwidth);
|
2008-01-09 23:48:26 +00:00
|
|
|
values += stride;
|
|
|
|
phases += stride;
|
2008-01-04 23:42:38 +00:00
|
|
|
}
|
2008-04-04 22:13:53 +00:00
|
|
|
#if (NUM_CORES > 1) && defined(HAVE_BACKLIGHT_INVERSION)
|
|
|
|
corelock_unlock(&cl);
|
|
|
|
#endif
|
2008-01-04 23:42:38 +00:00
|
|
|
}
|
|
|
|
|
2007-02-25 13:11:02 +00:00
|
|
|
void lcd_update_rect(int x, int y, int width, int height)
|
|
|
|
{
|
|
|
|
int xmax, ymax;
|
|
|
|
|
|
|
|
if (x + width > LCD_WIDTH)
|
|
|
|
width = LCD_WIDTH - x;
|
|
|
|
if (width <= 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ymax = y + height - 1;
|
|
|
|
if (ymax >= LCD_HEIGHT)
|
|
|
|
ymax = LCD_HEIGHT - 1;
|
|
|
|
|
|
|
|
#if defined(IPOD_MINI) || defined(IPOD_MINI2G)
|
|
|
|
x += pix_offset;
|
|
|
|
#endif
|
|
|
|
/* writing is done in 16-bit units (8 pixels) */
|
|
|
|
xmax = (x + width - 1) >> 3;
|
|
|
|
x >>= 3;
|
|
|
|
width = xmax - x + 1;
|
|
|
|
|
2008-01-12 00:59:18 +00:00
|
|
|
for (; y <= ymax; y++)
|
|
|
|
{
|
2007-02-25 13:11:02 +00:00
|
|
|
lcd_cmd_and_data(R_RAM_ADDR_SET, (y << 5) + addr_offset - x);
|
|
|
|
lcd_prepare_cmd(R_RAM_DATA);
|
|
|
|
|
|
|
|
#if defined(IPOD_MINI) || defined(IPOD_MINI2G)
|
2008-01-12 00:59:18 +00:00
|
|
|
if (pix_offset == -2)
|
|
|
|
lcd_write_data_shifted(&lcd_framebuffer[y][2*x], width);
|
|
|
|
else
|
2007-02-25 13:11:02 +00:00
|
|
|
#endif
|
2008-01-12 00:59:18 +00:00
|
|
|
lcd_write_data(&lcd_framebuffer[y][2*x], width);
|
2007-02-25 13:11:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Update the display. */
|
|
|
|
void lcd_update(void)
|
|
|
|
{
|
|
|
|
lcd_update_rect(0, 0, LCD_WIDTH, LCD_HEIGHT);
|
|
|
|
}
|
2007-09-29 20:56:07 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_LCD_SHUTDOWN
|
|
|
|
/* LCD powerdown */
|
|
|
|
void lcd_shutdown(void)
|
|
|
|
{
|
2008-04-02 19:01:16 +00:00
|
|
|
lcd_cmd_and_data(R_POWER_CONTROL, POWER_REG_H | 0x00); /* Turn off op amp power */
|
|
|
|
lcd_cmd_and_data(R_POWER_CONTROL, POWER_REG_H | 0x02); /* Put LCD driver in standby */
|
2007-09-29 20:56:07 +00:00
|
|
|
}
|
|
|
|
#endif
|