1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Rockbox driver for iPod LCDs
12 * Based on code from the ipodlinux project - http://ipodlinux.org/
13 * Adapted for Rockbox in November 2005
15 * Original file: linux/arch/armnommu/mach-ipod/fb.c
17 * Copyright (c) 2003-2005 Bernard Leach (leachbj@bouncycastle.org)
19 * This program is free software; you can redistribute it and/or
20 * modify it under the terms of the GNU General Public License
21 * as published by the Free Software Foundation; either version 2
22 * of the License, or (at your option) any later version.
24 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
25 * KIND, either express or implied.
27 ****************************************************************************/
35 /* LCD command codes for HD66753 */
37 #define R_START_OSC 0x00
38 #define R_DRV_OUTPUT_CONTROL 0x01
39 #define R_DRV_WAVEFORM_CONTROL 0x02
40 #define R_POWER_CONTROL 0x03
41 #define R_CONTRAST_CONTROL 0x04
42 #define R_ENTRY_MODE 0x05
43 #define R_ROTATION 0x06
44 #define R_DISPLAY_CONTROL 0x07
45 #define R_CURSOR_CONTROL 0x08
46 #define R_HORIZONTAL_CURSOR_POS 0x0b
47 #define R_VERTICAL_CURSOR_POS 0x0c
48 #define R_1ST_SCR_DRV_POS 0x0d
49 #define R_2ND_SCR_DRV_POS 0x0e
50 #define R_RAM_WRITE_MASK 0x10
51 #define R_RAM_ADDR_SET 0x11
52 #define R_RAM_DATA 0x12
54 #ifdef HAVE_BACKLIGHT_INVERSION
55 /* The backlight makes the LCD appear negative on the 1st/2nd gen */
56 static bool lcd_inverted
= false;
57 static bool lcd_backlit
= false;
59 /* invert_display() and the lcd_blit_* functions need to be corelocked */
60 static struct corelock cl IBSS_ATTR
;
62 static void invert_display(void);
65 #if defined(IPOD_1G2G) || defined(IPOD_3G)
66 #define POWER_REG_H 0x1120 /* 1/7 Bias, 5x step-up @ clk/8 */
68 #define POWER_REG_H 0x1200 /* 1/7 Bias, 6x step-up @ clk/32 */
71 #define CONTRAST_REG_H 0x400
73 #if defined(IPOD_1G2G)
74 #define DEFAULT_CONTRAST 45
75 #elif defined(IPOD_3G)
76 #define DEFAULT_CONTRAST 50
77 #elif defined(IPOD_MINI) || defined(IPOD_MINI2G)
78 #define DEFAULT_CONTRAST 42
79 #elif defined(IPOD_4G)
80 #define DEFAULT_CONTRAST 35
84 static int addr_offset
;
85 #if defined(IPOD_MINI) || defined(IPOD_MINI2G)
86 static int pix_offset
;
87 void lcd_write_data_shifted(const fb_data
* p_bytes
, int count
);
90 /* wait for LCD with timeout */
91 static inline void lcd_wait_write(void)
93 while (LCD1_CONTROL
& LCD1_BUSY_MASK
);
96 /* send LCD command */
97 static void lcd_prepare_cmd(unsigned cmd
)
101 LCD1_CMD
= cmd
| 0x740000;
109 /* send LCD command and data */
110 static void lcd_cmd_and_data(unsigned cmd
, unsigned data
)
114 LCD1_CMD
= cmd
| 0x740000;
116 LCD1_CMD
= data
| 0x760000;
122 LCD1_DATA
= data
>> 8;
124 LCD1_DATA
= data
& 0xff;
129 void lcd_init_device(void)
131 #if (NUM_CORES > 1) && defined(HAVE_BACKLIGHT_INVERSION)
134 #ifdef IPOD_MINI2G /* serial LCD hookup */
136 LCD1_CONTROL
= 0x01730084; /* fastest setting */
137 #elif defined(IPOD_1G2G) || defined(IPOD_3G)
138 LCD1_CONTROL
= (LCD1_CONTROL
& 0x0002) | 0x0084;
139 /* fastest setting, keep backlight bit */
141 LCD1_CONTROL
= 0x0084; /* fastest setting */
144 lcd_cmd_and_data(R_DRV_WAVEFORM_CONTROL
, 0x48);
145 /* C waveform, no EOR, 9 lines inversion */
146 lcd_cmd_and_data(R_POWER_CONTROL
, POWER_REG_H
| 0xc);
147 lcd_cmd_and_data(R_DISPLAY_CONTROL
, 0x0019);
148 lcd_set_contrast(DEFAULT_CONTRAST
);
149 #ifdef HAVE_BACKLIGHT_INVERSION
153 lcd_cmd_and_data(R_ENTRY_MODE
, 0x0000);
156 /*** hardware configuration ***/
158 int lcd_default_contrast(void)
160 return DEFAULT_CONTRAST
;
163 /* Rockbox stores the contrast as 0..63 - we add 64 to it */
164 void lcd_set_contrast(int val
)
166 if (val
< 0) val
= 0;
167 else if (val
> 63) val
= 63;
169 lcd_cmd_and_data(R_CONTRAST_CONTROL
, CONTRAST_REG_H
| (val
+ 64));
172 #ifdef HAVE_BACKLIGHT_INVERSION
173 static void invert_display(void)
175 static bool last_invert
= false;
176 bool new_invert
= lcd_inverted
^ lcd_backlit
;
178 if (new_invert
!= last_invert
)
180 int oldlevel
= disable_irq_save();
183 lcd_cmd_and_data(R_DISPLAY_CONTROL
, new_invert
? 0x0027 : 0x0019);
184 corelock_unlock(&cl
);
186 lcd_cmd_and_data(R_DISPLAY_CONTROL
, new_invert
? 0x0027 : 0x0019);
188 restore_irq(oldlevel
);
189 last_invert
= new_invert
;
193 void lcd_set_invert_display(bool yesno
)
195 lcd_inverted
= yesno
;
199 void lcd_set_backlight_inversion(bool yesno
)
205 void lcd_set_invert_display(bool yesno
)
207 lcd_cmd_and_data(R_DISPLAY_CONTROL
, yesno
? 0x0027 : 0x0019);
211 /* turn the display upside down (call lcd_update() afterwards) */
212 void lcd_set_flip(bool yesno
)
214 #if defined(IPOD_MINI) || defined(IPOD_MINI2G)
216 { /* 168x112, inverse COM order */
217 lcd_cmd_and_data(R_DRV_OUTPUT_CONTROL
, 0x020d);
218 lcd_cmd_and_data(R_1ST_SCR_DRV_POS
, 0x8316); /* 22..131 */
219 addr_offset
= (22 << 5) | (20 - 4);
223 { /* 168x112, inverse SEG order */
224 lcd_cmd_and_data(R_DRV_OUTPUT_CONTROL
, 0x010d);
225 lcd_cmd_and_data(R_1ST_SCR_DRV_POS
, 0x6d00); /* 0..109 */
231 { /* 168x128, inverse SEG & COM order */
232 lcd_cmd_and_data(R_DRV_OUTPUT_CONTROL
, 0x030f);
233 lcd_cmd_and_data(R_1ST_SCR_DRV_POS
, 0x8304); /* 4..131 */
234 addr_offset
= (4 << 5) | (20 - 1);
238 lcd_cmd_and_data(R_DRV_OUTPUT_CONTROL
, 0x000f);
239 lcd_cmd_and_data(R_1ST_SCR_DRV_POS
, 0x7f00); /* 0..127 */
245 #ifdef HAVE_LCD_ENABLE
246 void lcd_enable(bool on
)
250 lcd_cmd_and_data(R_START_OSC
, 1); /* start oscillation */
251 sleep(HZ
/10); /* wait 10ms */
252 lcd_cmd_and_data(R_POWER_CONTROL
, POWER_REG_H
); /*clear standby mode */
253 lcd_cmd_and_data(R_POWER_CONTROL
, POWER_REG_H
| 0xc);
254 /* enable opamp & booster */
258 lcd_cmd_and_data(R_POWER_CONTROL
, POWER_REG_H
);
259 /* switch off opamp & booster */
260 lcd_cmd_and_data(R_POWER_CONTROL
, POWER_REG_H
| 0x1);
261 /* enter standby mode */
264 #endif /* HAVE_LCD_ENABLE */
266 /*** update functions ***/
268 /* Helper function. */
269 void lcd_mono_data(const unsigned char *data
, int count
);
271 /* Performance function that works with an external buffer
272 note that x, bwidtht and stride are in 8-pixel units! */
273 void lcd_blit_mono(const unsigned char *data
, int bx
, int y
, int bwidth
,
274 int height
, int stride
)
276 #if (NUM_CORES > 1) && defined(HAVE_BACKLIGHT_INVERSION)
281 lcd_cmd_and_data(R_RAM_ADDR_SET
, (y
++ << 5) + addr_offset
- bx
);
282 lcd_prepare_cmd(R_RAM_DATA
);
283 lcd_mono_data(data
, bwidth
);
286 #if (NUM_CORES > 1) && defined(HAVE_BACKLIGHT_INVERSION)
287 corelock_unlock(&cl
);
291 /* Helper function for lcd_grey_phase_blit(). */
292 void lcd_grey_data(unsigned char *values
, unsigned char *phases
, int count
);
294 /* Performance function that works with an external buffer
295 note that bx and bwidth are in 8-pixel units! */
296 void lcd_blit_grey_phase(unsigned char *values
, unsigned char *phases
,
297 int bx
, int y
, int bwidth
, int height
, int stride
)
299 #if (NUM_CORES > 1) && defined(HAVE_BACKLIGHT_INVERSION)
304 lcd_cmd_and_data(R_RAM_ADDR_SET
, (y
++ << 5) + addr_offset
- bx
);
305 lcd_prepare_cmd(R_RAM_DATA
);
306 lcd_grey_data(values
, phases
, bwidth
);
310 #if (NUM_CORES > 1) && defined(HAVE_BACKLIGHT_INVERSION)
311 corelock_unlock(&cl
);
315 void lcd_update_rect(int x
, int y
, int width
, int height
)
319 if (x
+ width
> LCD_WIDTH
)
320 width
= LCD_WIDTH
- x
;
324 ymax
= y
+ height
- 1;
325 if (ymax
>= LCD_HEIGHT
)
326 ymax
= LCD_HEIGHT
- 1;
328 #if defined(IPOD_MINI) || defined(IPOD_MINI2G)
331 /* writing is done in 16-bit units (8 pixels) */
332 xmax
= (x
+ width
- 1) >> 3;
334 width
= xmax
- x
+ 1;
336 for (; y
<= ymax
; y
++)
338 lcd_cmd_and_data(R_RAM_ADDR_SET
, (y
<< 5) + addr_offset
- x
);
339 lcd_prepare_cmd(R_RAM_DATA
);
341 #if defined(IPOD_MINI) || defined(IPOD_MINI2G)
342 if (pix_offset
== -2)
343 lcd_write_data_shifted(&lcd_framebuffer
[y
][2*x
], width
);
346 lcd_write_data(&lcd_framebuffer
[y
][2*x
], width
);
350 /* Update the display. */
351 void lcd_update(void)
353 lcd_update_rect(0, 0, LCD_WIDTH
, LCD_HEIGHT
);
356 #ifdef HAVE_LCD_SHUTDOWN
358 void lcd_shutdown(void)
360 lcd_cmd_and_data(R_POWER_CONTROL
, POWER_REG_H
| 0x00); /* Turn off op amp power */
361 lcd_cmd_and_data(R_POWER_CONTROL
, POWER_REG_H
| 0x02); /* Put LCD driver in standby */