summaryrefslogtreecommitdiff
path: root/firmware/target/arm/as3525/sansa-c200v2/lcd-c200v2.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/arm/as3525/sansa-c200v2/lcd-c200v2.c')
-rw-r--r--firmware/target/arm/as3525/sansa-c200v2/lcd-c200v2.c429
1 files changed, 0 insertions, 429 deletions
diff --git a/firmware/target/arm/as3525/sansa-c200v2/lcd-c200v2.c b/firmware/target/arm/as3525/sansa-c200v2/lcd-c200v2.c
deleted file mode 100644
index e16b082ce5..0000000000
--- a/firmware/target/arm/as3525/sansa-c200v2/lcd-c200v2.c
+++ /dev/null
@@ -1,429 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: lcd-e200v2.c 19453 2008-12-16 02:50:39Z saratoga $
9 *
10 * Copyright (C) 2004 by Linus Nielsen Feltzing
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22/* FIXME: Copied from e200v2 lcd driver, unlikely to work, but maybe */
23
24#include "config.h"
25
26#include "cpu.h"
27#include "lcd.h"
28#include "kernel.h"
29#include "thread.h"
30#include <string.h>
31#include <stdlib.h>
32#include "file.h"
33#include "debug.h"
34#include "system.h"
35#include "font.h"
36#include "bidi.h"
37#include "clock-target.h"
38
39static bool display_on = false; /* is the display turned on? */
40static bool display_flipped = false;
41static int y_offset = 0; /* needed for flip */
42
43/* register defines */
44#define R_START_OSC 0x00
45#define R_DRV_OUTPUT_CONTROL 0x01
46#define R_DRV_WAVEFORM_CONTROL 0x02
47#define R_ENTRY_MODE 0x03
48#define R_COMPARE_REG1 0x04
49#define R_COMPARE_REG2 0x05
50
51#define R_DISP_CONTROL1 0x07
52#define R_DISP_CONTROL2 0x08
53#define R_DISP_CONTROL3 0x09
54
55#define R_FRAME_CYCLE_CONTROL 0x0b
56#define R_EXT_DISP_IF_CONTROL 0x0c
57
58#define R_POWER_CONTROL1 0x10
59#define R_POWER_CONTROL2 0x11
60#define R_POWER_CONTROL3 0x12
61#define R_POWER_CONTROL4 0x13
62
63#define R_RAM_ADDR_SET 0x21
64#define R_WRITE_DATA_2_GRAM 0x22
65
66#define R_GAMMA_FINE_ADJ_POS1 0x30
67#define R_GAMMA_FINE_ADJ_POS2 0x31
68#define R_GAMMA_FINE_ADJ_POS3 0x32
69#define R_GAMMA_GRAD_ADJ_POS 0x33
70
71#define R_GAMMA_FINE_ADJ_NEG1 0x34
72#define R_GAMMA_FINE_ADJ_NEG2 0x35
73#define R_GAMMA_FINE_ADJ_NEG3 0x36
74#define R_GAMMA_GRAD_ADJ_NEG 0x37
75
76#define R_GAMMA_AMP_ADJ_RES_POS 0x38
77#define R_GAMMA_AMP_AVG_ADJ_RES_NEG 0x39
78
79#define R_GATE_SCAN_POS 0x40
80#define R_VERT_SCROLL_CONTROL 0x41
81#define R_1ST_SCR_DRV_POS 0x42
82#define R_2ND_SCR_DRV_POS 0x43
83#define R_HORIZ_RAM_ADDR_POS 0x44
84#define R_VERT_RAM_ADDR_POS 0x45
85
86#define R_ENTRY_MODE_HORZ 0x7030
87#define R_ENTRY_MODE_VERT 0x7038
88#define R_ENTRY_MODE_SOLID_VERT 0x1038
89
90/* TODO: Implement this function */
91static void lcd_delay(int x)
92{
93 /* This is just arbitrary - the OF does something more complex */
94 x *= 1024;
95 while (x--);
96}
97
98/* DBOP initialisation, do what OF does */
99static void ams3525_dbop_init(void)
100{
101 CGU_DBOP = (1<<3) | AS3525_DBOP_DIV;
102
103 DBOP_TIMPOL_01 = 0xe167e167;
104 DBOP_TIMPOL_23 = 0xe167006e;
105 DBOP_CTRL = 0x41008;
106
107 GPIOB_AFSEL = 0xfc;
108 GPIOC_AFSEL = 0xff;
109
110 DBOP_TIMPOL_23 = 0x6000e;
111 DBOP_CTRL = 0x51008;
112 DBOP_TIMPOL_01 = 0x6e167;
113 DBOP_TIMPOL_23 = 0xa167e06f;
114
115 /* TODO: The OF calls some other functions here, but maybe not important */
116}
117
118
119static void lcd_write_cmd(int cmd)
120{
121 /* Write register */
122 DBOP_CTRL &= ~(1<<14);
123
124 DBOP_TIMPOL_23 = 0xa167006e;
125
126 DBOP_DOUT = cmd;
127
128 /* Wait for fifo to empty */
129 while ((DBOP_STAT & (1<<10)) == 0);
130
131 DBOP_TIMPOL_23 = 0xa167e06f;
132}
133
134void lcd_write_data(const fb_data* p_bytes, int count)
135{
136 while (count--)
137 {
138 DBOP_DOUT = *p_bytes++;
139
140 /* Wait for fifo to empty */
141 while ((DBOP_STAT & (1<<10)) == 0);
142 }
143}
144
145static void lcd_write_reg(int reg, int value)
146{
147 unsigned short data = value;
148
149 lcd_write_cmd(reg);
150 lcd_write_data(&data, 1);
151}
152
153/*** hardware configuration ***/
154
155void lcd_set_contrast(int val)
156{
157 (void)val;
158}
159
160void lcd_set_invert_display(bool yesno)
161{
162 (void)yesno;
163}
164
165static void flip_lcd(bool yesno)
166{
167 (void)yesno;
168}
169
170
171/* turn the display upside down (call lcd_update() afterwards) */
172void lcd_set_flip(bool yesno)
173{
174 display_flipped = yesno;
175 y_offset = yesno ? 4 : 0; /* FIXME: Is a y_offset needed? */
176
177 if (display_on)
178 flip_lcd(yesno);
179}
180
181static void _display_on(void)
182{
183 /* Initialisation the display the same way as the original firmware */
184
185 lcd_write_reg(R_START_OSC, 0x0001); /* Start Oscilation */
186
187 lcd_write_reg(R_DRV_OUTPUT_CONTROL, 0x011b); /* 220 lines, GS=0, SS=1 */
188
189 /* B/C = 1: n-line inversion form
190 * EOR = 1: polarity inversion occurs by applying an EOR to odd/even
191 * frame select signal and an n-line inversion signal.
192 * FLD = 01b: 1 field interlaced scan, external display iface */
193 lcd_write_reg(R_DRV_WAVEFORM_CONTROL, 0x0700);
194
195 /* Address counter updated in horizontal direction; left to right;
196 * vertical increment horizontal increment.
197 * data format for 8bit transfer or spi = 65k (5,6,5) */
198 lcd_write_reg(R_ENTRY_MODE, 0x0030);
199
200 /* Replace data on writing to GRAM */
201 lcd_write_reg(R_COMPARE_REG1, 0);
202 lcd_write_reg(R_COMPARE_REG2, 0);
203
204 lcd_write_reg(R_DISP_CONTROL1, 0x0000); /* GON = 0, DTE = 0, D1-0 = 00b */
205
206 /* Front porch lines: 2; Back porch lines: 2; */
207 lcd_write_reg(R_DISP_CONTROL2, 0x0203);
208
209 /* Scan cycle = 0 frames */
210 lcd_write_reg(R_DISP_CONTROL3, 0x0000);
211
212 /* 16 clocks */
213 lcd_write_reg(R_FRAME_CYCLE_CONTROL, 0x0000);
214
215 /* 18-bit RGB interface (one transfer/pixel)
216 * internal clock operation;
217 * System interface/VSYNC interface */
218 lcd_write_reg(R_EXT_DISP_IF_CONTROL, 0x0000);
219
220
221 /* zero everything*/
222 lcd_write_reg(R_POWER_CONTROL1, 0x0000); /* STB = 0, SLP = 0 */
223
224 lcd_delay(10);
225
226 /* initialise power supply */
227
228 /* DC12-10 = 000b: Step-up1 = clock/8,
229 * DC02-00 = 000b: Step-up2 = clock/16,
230 * VC2-0 = 010b: VciOUT = 0.87 * VciLVL */
231 lcd_write_reg(R_POWER_CONTROL2, 0x0002);
232
233 /* VRH3-0 = 1000b: Vreg1OUT = REGP * 1.90 */
234 lcd_write_reg(R_POWER_CONTROL3, 0x0008);
235
236 lcd_delay(40);
237
238 lcd_write_reg(R_POWER_CONTROL4, 0x0000); /* VCOMG = 0 */
239
240 /* This register is unknown */
241 lcd_write_reg(0x56, 0x80f);
242
243
244 lcd_write_reg(R_POWER_CONTROL1, 0x4140);
245
246 lcd_delay(10);
247
248 lcd_write_reg(R_POWER_CONTROL2, 0x0000);
249 lcd_write_reg(R_POWER_CONTROL3, 0x0013);
250
251 lcd_delay(20);
252
253 lcd_write_reg(R_POWER_CONTROL4, 0x6d0e);
254
255 lcd_delay(20);
256
257 lcd_write_reg(R_POWER_CONTROL4, 0x6d0e);
258
259 lcd_write_reg(R_GAMMA_FINE_ADJ_POS1, 0x0002);
260 lcd_write_reg(R_GAMMA_FINE_ADJ_POS2, 0x0707);
261 lcd_write_reg(R_GAMMA_FINE_ADJ_POS3, 0x0182);
262 lcd_write_reg(R_GAMMA_GRAD_ADJ_POS, 0x0203);
263 lcd_write_reg(R_GAMMA_FINE_ADJ_NEG1, 0x0706);
264 lcd_write_reg(R_GAMMA_FINE_ADJ_NEG2, 0x0006);
265 lcd_write_reg(R_GAMMA_FINE_ADJ_NEG3, 0x0706);
266 lcd_write_reg(R_GAMMA_GRAD_ADJ_NEG, 0x0000);
267 lcd_write_reg(R_GAMMA_AMP_ADJ_RES_POS, 0x030f);
268 lcd_write_reg(R_GAMMA_AMP_AVG_ADJ_RES_NEG, 0x0f08);
269
270
271 lcd_write_reg(R_RAM_ADDR_SET, 0);
272 lcd_write_reg(R_GATE_SCAN_POS, 0);
273 lcd_write_reg(R_VERT_SCROLL_CONTROL, 0);
274
275 lcd_write_reg(R_1ST_SCR_DRV_POS, (LCD_HEIGHT-1) << 8);
276 lcd_write_reg(R_2ND_SCR_DRV_POS, (LCD_HEIGHT-1) << 8);
277
278 lcd_write_reg(R_HORIZ_RAM_ADDR_POS, (LCD_WIDTH-1) << 8);
279 lcd_write_reg(R_VERT_RAM_ADDR_POS, (LCD_HEIGHT-1) << 8);
280
281
282 lcd_write_reg(R_DISP_CONTROL1, 0x0037);
283
284 display_on=true; /* must be done before calling lcd_update() */
285 lcd_update();
286}
287
288/* LCD init */
289void lcd_init_device(void)
290{
291 ams3525_dbop_init();
292
293 /* Init GPIOs the same as the OF */
294
295 GPIOA_DIR |= (1<<5);
296 GPIOA_PIN(5) = 0;
297
298 GPIOA_PIN(3) = (1<<3);
299
300 GPIOA_DIR |= (3<<3);
301
302 GPIOA_PIN(3) = (1<<3);
303
304 GPIOA_PIN(4) = 0; /*c80b0040 := 0;*/
305
306 GPIOA_DIR |= (1<<7);
307 GPIOA_PIN(7) = 0;
308
309 lcd_delay(1);
310
311 GPIOA_PIN(5) = (1<<5);
312
313 lcd_delay(1);
314
315 _display_on();
316}
317
318void lcd_enable(bool on)
319{
320 if(display_on!=on)
321 {
322 if(on)
323 {
324 _display_on();
325 lcd_activation_call_hook();
326 }
327 else
328 {
329 /* TODO: Implement off sequence */
330 display_on=false;
331 }
332 }
333}
334
335bool lcd_active(void)
336{
337 return display_on;
338}
339
340void lcd_sleep(void)
341{
342 /* TODO */
343}
344
345/*** update functions ***/
346
347/* Performance function to blit a YUV bitmap directly to the LCD
348 * src_x, src_y, width and height should be even
349 * x, y, width and height have to be within LCD bounds
350 */
351void lcd_blit_yuv(unsigned char * const src[3],
352 int src_x, int src_y, int stride,
353 int x, int y, int width, int height)
354{
355 (void)src;
356 (void)src_x;
357 (void)src_y;
358 (void)stride;
359 (void)x;
360 (void)y;
361 (void)width;
362 (void)height;
363}
364
365/* Update the display.
366 This must be called after all other LCD functions that change the display. */
367void lcd_update(void)
368{
369 if (!display_on)
370 return;
371
372 lcd_write_reg(R_ENTRY_MODE, R_ENTRY_MODE_HORZ);
373
374 /* Set start position and window */
375 lcd_write_reg(R_HORIZ_RAM_ADDR_POS, (LCD_WIDTH-1) << 8);
376 lcd_write_reg(R_VERT_RAM_ADDR_POS,
377 ((y_offset + LCD_HEIGHT-1) << 8) | y_offset);
378 lcd_write_reg(R_RAM_ADDR_SET, (y_offset) << 8);
379
380 lcd_write_cmd(R_WRITE_DATA_2_GRAM);
381
382 lcd_write_data((unsigned short *)lcd_framebuffer, LCD_WIDTH*LCD_HEIGHT);
383
384} /* lcd_update */
385
386
387/* Update a fraction of the display. */
388void lcd_update_rect(int x, int y, int width, int height)
389{
390 int ymax;
391 const unsigned short *ptr;
392
393 if (!display_on)
394 return;
395
396 if (x + width > LCD_WIDTH)
397 width = LCD_WIDTH - x; /* Clip right */
398 if (x < 0)
399 width += x, x = 0; /* Clip left */
400 if (width <= 0)
401 return; /* nothing left to do */
402
403 ymax = y + height;
404 if (ymax > LCD_HEIGHT)
405 ymax = LCD_HEIGHT; /* Clip bottom */
406 if (y < 0)
407 y = 0; /* Clip top */
408 if (y >= ymax)
409 return; /* nothing left to do */
410
411 lcd_write_reg(R_ENTRY_MODE, R_ENTRY_MODE_HORZ);
412 /* Set start position and window */
413 lcd_write_reg(R_HORIZ_RAM_ADDR_POS,
414 ((x + width-1) << 8) | x);
415 lcd_write_reg(R_VERT_RAM_ADDR_POS,
416 ((y_offset + y + height - 1) << 8) | (y_offset + y));
417 lcd_write_reg(R_RAM_ADDR_SET, ((y + y_offset) << 8) | x);
418
419 lcd_write_cmd(R_WRITE_DATA_2_GRAM);
420
421 ptr = (unsigned short *)&lcd_framebuffer[y][x];
422
423 do
424 {
425 lcd_write_data(ptr, width);
426 ptr += LCD_WIDTH;
427 }
428 while (++y < ymax);
429} /* lcd_update_rect */