1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 by Alan Korr
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
29 #define LCD_SET_LOWER_COLUMN_ADDRESS ((char)0x00)
30 #define LCD_SET_HIGHER_COLUMN_ADDRESS ((char)0x10)
31 #define LCD_SET_INTERNAL_REGULATOR_RESISTOR_RATIO ((char)0x20)
32 #define LCD_SET_POWER_CONTROL_REGISTER ((char)0x28)
33 #define LCD_SET_DISPLAY_START_LINE ((char)0x40)
34 #define LCD_SET_CONTRAST_CONTROL_REGISTER ((char)0x81)
35 #define LCD_SET_SEGMENT_REMAP ((char)0xA0)
36 #define LCD_SET_LCD_BIAS ((char)0xA2)
37 #define LCD_SET_ENTIRE_DISPLAY_OFF ((char)0xA4)
38 #define LCD_SET_ENTIRE_DISPLAY_ON ((char)0xA5)
39 #define LCD_SET_NORMAL_DISPLAY ((char)0xA6)
40 #define LCD_SET_REVERSE_DISPLAY ((char)0xA7)
41 #define LCD_SET_MULTIPLEX_RATIO ((char)0xA8)
42 #define LCD_SET_BIAS_TC_OSC ((char)0xA9)
43 #define LCD_SET_1OVER4_BIAS_RATIO ((char)0xAA)
44 #define LCD_SET_INDICATOR_OFF ((char)0xAC)
45 #define LCD_SET_INDICATOR_ON ((char)0xAD)
46 #define LCD_SET_DISPLAY_OFF ((char)0xAE)
47 #define LCD_SET_DISPLAY_ON ((char)0xAF)
48 #define LCD_SET_PAGE_ADDRESS ((char)0xB0)
49 #define LCD_SET_COM_OUTPUT_SCAN_DIRECTION ((char)0xC0)
50 #define LCD_SET_TOTAL_FRAME_PHASES ((char)0xD2)
51 #define LCD_SET_DISPLAY_OFFSET ((char)0xD3)
52 #define LCD_SET_READ_MODIFY_WRITE_MODE ((char)0xE0)
53 #define LCD_SOFTWARE_RESET ((char)0xE2)
54 #define LCD_NOP ((char)0xE3)
55 #define LCD_SET_END_OF_READ_MODIFY_WRITE_MODE ((char)0xEE)
57 /* LCD command codes */
58 #define LCD_CNTL_RESET 0xe2 /* Software reset */
59 #define LCD_CNTL_POWER 0x2f /* Power control */
60 #define LCD_CNTL_CONTRAST 0x81 /* Contrast */
61 #define LCD_CNTL_OUTSCAN 0xc8 /* Output scan direction */
62 #define LCD_CNTL_SEGREMAP 0xa1 /* Segment remap */
63 #define LCD_CNTL_DISPON 0xaf /* Display on */
65 #define LCD_CNTL_PAGE 0xb0 /* Page address */
66 #define LCD_CNTL_HIGHCOL 0x10 /* Upper column address */
67 #define LCD_CNTL_LOWCOL 0x00 /* Lower column address */
69 /* TCC77x specific defines */
70 #define LCD_BASE 0x50000000
71 #define LCD_CMD *(volatile unsigned char*)(LCD_BASE)
72 #define LCD_DATA *(volatile unsigned char*)(LCD_BASE+1)
74 void lcd_write_command(int byte
)
85 void lcd_write_data(const fb_data
* p_bytes
, int count
)
89 LCD_DATA
= *(p_bytes
++);
99 /* End of TCC77x specific defines */
104 static int xoffset
; /* needed for flip */
106 /*** hardware configuration ***/
108 int lcd_default_contrast(void)
113 void lcd_set_contrast(int val
)
115 lcd_write_command(LCD_CNTL_CONTRAST
);
116 lcd_write_command(val
);
119 void lcd_set_invert_display(bool yesno
)
122 lcd_write_command(LCD_SET_REVERSE_DISPLAY
);
124 lcd_write_command(LCD_SET_NORMAL_DISPLAY
);
127 /* turn the display upside down (call lcd_update() afterwards) */
128 void lcd_set_flip(bool yesno
)
130 /* TODO: flip mode isn't working. The commands in the else part of
131 this function are how the original firmware inits the LCD */
135 lcd_write_command(LCD_SET_SEGMENT_REMAP
| 0x01);
136 lcd_write_command(LCD_SET_COM_OUTPUT_SCAN_DIRECTION
);
137 xoffset
= 132 - LCD_WIDTH
; /* 132 colums minus the 128 we have */
141 lcd_write_command(LCD_SET_SEGMENT_REMAP
);
142 lcd_write_command(LCD_SET_COM_OUTPUT_SCAN_DIRECTION
| 0x08);
149 void lcd_init_device(void)
153 /* Telechips init the same as the original firmware */
154 CSCFG1
&= 0xc3ffc000;
155 CSCFG1
|= 0x3400101a;
157 CSCFG1
&= ~(1 << 21);
159 bus_width
= ((MCFG
>> 11) & 0x3) ^ 3;
161 CSCFG1
= (bus_width
<< 28) |
162 (3 << 26) | /* MTYPE = 3 */
163 ((LCD_BASE
>> 28) << 22) | /* CSBASE = 0x5 */
164 (1 << 20) | /* Unknown */
165 (3 << 11) | /* Setup time = 3 cycles */
166 (3 << 3) | /* Pulse width = 3+1 cycles */
167 (1 << 0); /* Hold time = 1 cycle */
169 /* SSD1815 inits like the original firmware */
170 lcd_write_command(LCD_SET_DISPLAY_OFF
);
172 lcd_write_command(LCD_SET_INTERNAL_REGULATOR_RESISTOR_RATIO
| 5);
173 lcd_set_contrast(lcd_default_contrast());
174 lcd_write_command(LCD_SET_POWER_CONTROL_REGISTER
| 7);
175 /* power control register: op-amp=1, regulator=1, booster=1 */
176 lcd_write_command(LCD_SET_BIAS_TC_OSC
);
178 /* 0xc2 = 110 000 10: Osc. Freq 110 - ???
179 TC value 000 - "-0.01%/C (TC0, POR)"
180 Bias ratio 10 - "1/9, 1/7 (POR)"
182 lcd_write_command(0xc2);
183 lcd_write_command(LCD_SET_DISPLAY_ON
);
189 /*** Update functions ***/
191 /* Performance function that works with an external buffer
192 note that by and bheight are in 8-pixel units! */
193 void lcd_blit(const unsigned char* data
, int x
, int by
, int width
,
194 int bheight
, int stride
)
196 /* Copy display bitmap to hardware */
199 lcd_write_command (LCD_CNTL_PAGE
| (by
++ & 0xf));
200 lcd_write_command (LCD_CNTL_HIGHCOL
| (((x
+xoffset
)>>4) & 0xf));
201 lcd_write_command (LCD_CNTL_LOWCOL
| ((x
+xoffset
) & 0xf));
203 lcd_write_data(data
, width
);
209 /* Update the display.
210 This must be called after all other LCD functions that change the display. */
211 void lcd_update(void) ICODE_ATTR
;
212 void lcd_update(void)
216 /* Copy display bitmap to hardware */
217 for (y
= 0; y
< LCD_FBHEIGHT
; y
++)
219 lcd_write_command (LCD_CNTL_PAGE
| (y
& 0xf));
220 lcd_write_command (LCD_CNTL_HIGHCOL
| ((xoffset
>> 4) & 0xf));
221 lcd_write_command (LCD_CNTL_LOWCOL
| (xoffset
& 0xf));
223 lcd_write_data (lcd_framebuffer
[y
], LCD_WIDTH
);
227 /* Update a fraction of the display. */
228 void lcd_update_rect(int, int, int, int) ICODE_ATTR
;
229 void lcd_update_rect(int x
, int y
, int width
, int height
)
233 /* The Y coordinates have to work on even 8 pixel rows */
234 ymax
= (y
+ height
-1) >> 3;
237 if(x
+ width
> LCD_WIDTH
)
238 width
= LCD_WIDTH
- x
;
240 return; /* nothing left to do, 0 is harmful to lcd_write_data() */
241 if(ymax
>= LCD_FBHEIGHT
)
242 ymax
= LCD_FBHEIGHT
-1;
244 /* Copy specified rectange bitmap to hardware */
245 for (; y
<= ymax
; y
++)
247 lcd_write_command (LCD_CNTL_PAGE
| (y
& 0xf));
248 lcd_write_command (LCD_CNTL_HIGHCOL
| (((x
+xoffset
) >> 4) & 0xf));
249 lcd_write_command (LCD_CNTL_LOWCOL
| ((x
+xoffset
) & 0xf));
251 lcd_write_data (&lcd_framebuffer
[y
][x
], width
);