summaryrefslogtreecommitdiff
path: root/firmware/target/arm/sandisk/sansa-view/lcd-view.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/arm/sandisk/sansa-view/lcd-view.c')
-rw-r--r--firmware/target/arm/sandisk/sansa-view/lcd-view.c428
1 files changed, 428 insertions, 0 deletions
diff --git a/firmware/target/arm/sandisk/sansa-view/lcd-view.c b/firmware/target/arm/sandisk/sansa-view/lcd-view.c
new file mode 100644
index 0000000000..39b0d574eb
--- /dev/null
+++ b/firmware/target/arm/sandisk/sansa-view/lcd-view.c
@@ -0,0 +1,428 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Rockbox driver for Sansa View LCDs
11 *
12 * Copyright (c) 2009 Robert Keevil
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
18 *
19 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 * KIND, either express or implied.
21 *
22 ****************************************************************************/
23#include <string.h>
24#include "cpu.h"
25#include "system.h"
26#include "backlight-target.h"
27#include "lcd.h"
28
29#include "bitmaps/rockboxlogo.h"
30
31/* Power and display status */
32static bool power_on = false; /* Is the power turned on? */
33static bool display_on SHAREDBSS_ATTR = false; /* Is the display turned on? */
34static unsigned lcd_yuv_options SHAREDBSS_ATTR = 0;
35
36#define LCD_DATA_OUT_GPIO GPIOH_OUTPUT_VAL
37#define LCD_DATA_OUT_PIN 4
38
39#define LCD_CLOCK_GPIO GPIOH_OUTPUT_VAL
40#define LCD_CLOCK_PIN 6
41
42#define LCD_CS_GPIO GPIOH_OUTPUT_VAL
43#define LCD_CS_PIN 7
44
45#ifdef BOOTLOADER
46static void lcd_init_gpio(void)
47{
48 // OF: 0x5CC8
49
50 outl(inl(0x70000010) | 0xFC000000, 0x70000010);
51 outl(inl(0x70000014) | 0xC300000, 0x70000014);
52
53 GPIOE_ENABLE = 0;
54/* TODO: check GPIOM exists and isn't just atomic access */
55/* GPIOM_ENABLE &= ~0x3; */
56 GPIOJ_ENABLE &= ~0x1a;
57 GPIOB_ENABLE &= ~0x8;
58 GPIOH_OUTPUT_VAL |= 0x80;
59 GPIOH_OUTPUT_EN |= 0x80;
60 GPIOH_ENABLE |= 0x80;
61 GPIOH_OUTPUT_VAL |= 0x40;
62 GPIOH_OUTPUT_EN |= 0x40;
63 GPIOH_ENABLE |= 0x40;
64 GPIOH_OUTPUT_VAL |= 0x20;
65 GPIOH_OUTPUT_EN |= 0x20;
66 GPIOH_ENABLE |= 0x20;
67 GPIOH_OUTPUT_VAL |= 0x10;
68 GPIOH_OUTPUT_EN |= 0x10;
69 GPIOH_ENABLE |= 0x10;
70// GPIOD_OUTOUT_VAL &= ~0x1; //backlight on
71// GPIOD_ENABLE |= 0x1;
72 GPIOB_OUTPUT_VAL |= 0x4;
73 GPIOB_ENABLE |= 0x4;
74 GPIOB_OUTPUT_EN |= 0x4;
75 GPIOG_ENABLE |= 0x8;
76 GPIOG_OUTPUT_EN &= ~0x8;
77
78// more to add here...
79}
80#endif
81
82static void lcd_send_msg(unsigned char count, unsigned int data)
83{
84 // OF: 0x645C
85 int i;
86
87 LCD_CLOCK_GPIO |= (1 << LCD_CLOCK_PIN);
88 LCD_CS_GPIO &= ~(1 << LCD_CS_PIN);
89
90 for (i = count - 1; i >= 0; i--)
91 {
92 if (data & (1 << count))
93 {
94// LCD_DATA_OUT_GPIO &= ~(1 << LCD_DATA_OUT_PIN);
95 LCD_DATA_OUT_GPIO |= (1 << LCD_DATA_OUT_PIN);
96 } else {
97// LCD_DATA_OUT_GPIO |= (1 << LCD_DATA_OUT_PIN);
98 LCD_DATA_OUT_GPIO &= ~(1 << LCD_DATA_OUT_PIN);
99 }
100 LCD_CLOCK_GPIO &= ~(1 << LCD_CLOCK_PIN);
101 udelay(1);
102 LCD_CLOCK_GPIO |= (1 << LCD_CLOCK_PIN);
103 udelay(2);
104 }
105
106 LCD_CS_GPIO |= (1 << LCD_CS_PIN);
107 LCD_CLOCK_GPIO |= (1 << LCD_CLOCK_PIN);
108 udelay(1);
109}
110
111/*
112static void lcd_write_reg(unsigned int reg, unsigned int data)
113{
114// OF: 0x6278 - referenced from 0x62840
115
116// So far this function is always called with shift = 0x0 ?
117// If so can remove and simplify
118
119 unsigned int cmd;
120 unsigned int shift = 0;
121
122 cmd = shift << 0x2;
123 cmd |= 0x70;
124 cmd = cmd << 0x10;
125 cmd |= reg;
126 lcd_send_msg(0x18, cmd);
127
128 cmd = shift << 0x2;
129 cmd |= 0x72;
130 cmd = cmd << 0x10;
131 cmd |= data;
132 lcd_send_msg(0x18, cmd);
133
134// lcd_send_msg(0x70, reg);
135// lcd_send_msg(0x72, data);
136}
137*/
138
139static void lcd_write_cmd(unsigned int cmd)
140{
141 lcd_send_msg(0x18, (0x700000 | cmd));
142}
143
144static void lcd_write_info(unsigned int data)
145{
146 lcd_send_msg(0x18, (0x720000 | data));
147}
148
149static void lcd_write_reg(unsigned int cmd, unsigned int data)
150{
151 lcd_write_cmd(cmd);
152 lcd_write_info(data);
153}
154
155/* Run the powerup sequence for the driver IC */
156static void lcd_power_on(void)
157{
158 /* OF: 0x5DC0 *
159 * r2: cmd *
160 * r3: data */
161 lcd_write_reg(0xE5, 0x8000);
162 lcd_write_reg(0x0, 0x1);
163 lcd_write_reg(0x1, 0x100);
164 lcd_write_reg(0x2, 0x700);
165 lcd_write_reg(0x3, 0x1230);
166 lcd_write_reg(0x4, 0x0);
167 lcd_write_reg(0x8, 0x408);
168 lcd_write_reg(0x9, 0x0);
169 lcd_write_reg(0xa, 0x0);
170 lcd_write_reg(0xd, 0x0);
171 lcd_write_reg(0xf, 0x2);
172 lcd_write_reg(0x10, 0x0);
173 lcd_write_reg(0x11, 0x0);
174 lcd_write_reg(0x12, 0x0);
175 lcd_write_reg(0x13, 0x0);
176 sleep(HZ/5);
177 lcd_write_reg(0x10, 0x17B0);
178 lcd_write_reg(0x11, 0x7);
179 sleep(HZ/20);
180 lcd_write_reg(0x12, 0x13c);
181 sleep(HZ/20);
182
183 // OF: BNE 0x5fb2
184
185 // two different models in use?!?
186 if (1)
187 {
188 lcd_write_reg(0x13, 0x1800);
189 lcd_write_reg(0x29, 0x13);
190 sleep(HZ/10);
191 lcd_write_reg(0x20, 0x0);
192 lcd_write_reg(0x21, 0x0);
193
194 lcd_write_reg(0x30, 0x2);
195 lcd_write_reg(0x31, 0xF07); // 0x37 option in other controller
196 lcd_write_reg(0x32, 0x403); // 0x31 option in other controller
197 lcd_write_reg(0x35, 0x206);
198 lcd_write_reg(0x36, 0x504);
199 lcd_write_reg(0x37, 0x707);
200 lcd_write_reg(0x38, 0x403);
201 }
202 else
203 {
204 // OF: last func continues, 0x5EFC
205 lcd_write_reg(0x13, 0x1700);
206 lcd_write_reg(0x29, 0x10);
207 sleep(HZ/10);
208 lcd_write_reg(0x20, 0x0);
209 lcd_write_reg(0x21, 0x0);
210
211 lcd_write_reg(0x30, 0x7);
212 lcd_write_reg(0x31, 0x403);
213 lcd_write_reg(0x32, 0x400);
214 lcd_write_reg(0x35, 0x3);
215 lcd_write_reg(0x36, 0xF07);
216 lcd_write_reg(0x37, 0x403);
217 lcd_write_reg(0x37, 0x106);
218 }
219
220 // OF: b 0x6066
221 lcd_write_reg(0x39, 0x7);
222 lcd_write_reg(0x3c, 0x700);
223 lcd_write_reg(0x3d, 0x700);
224
225 lcd_write_reg(0x50, 0x0);
226 lcd_write_reg(0x51, 0xef); // 239 - LCD_WIDTH
227 lcd_write_reg(0x52, 0x0);
228 lcd_write_reg(0x53, 0x13f); // 319 - LCD_HEIGHT
229
230 // OF: b 0x6114
231 lcd_write_reg(0x60, 0x2700);
232 lcd_write_reg(0x61, 0x1);
233 lcd_write_reg(0x6a, 0x0);
234
235 lcd_write_reg(0x80, 0x0);
236 lcd_write_reg(0x81, 0x0);
237 lcd_write_reg(0x82, 0x0);
238 lcd_write_reg(0x83, 0x0);
239 lcd_write_reg(0x84, 0x0);
240 lcd_write_reg(0x85, 0x0);
241
242 // OF: 0x61A8
243 lcd_write_reg(0x90, 0x10);
244 lcd_write_reg(0x92, 0x0);
245 lcd_write_reg(0x93, 0x3);
246 lcd_write_reg(0x95, 0x110);
247 lcd_write_reg(0x97, 0x0);
248 lcd_write_reg(0x98, 0x0);
249
250 lcd_write_reg(0xc, 0x110);
251 lcd_write_reg(0x7, 0x173);
252 sleep(HZ/10);
253 lcd_write_cmd(0x22);
254
255 power_on = true;
256}
257
258void unknown01(void)
259{
260 // OF: 0x62C4
261
262 lcd_write_reg(0x10, 0x17B0);
263 udelay(100);
264 lcd_write_reg(0x7, 0x173);
265}
266
267void unknown02(void)
268{
269 // OF: 0x6308
270
271 lcd_write_reg(0x7, 0x160);
272 lcd_write_reg(0x10, 0x17B1);
273}
274
275void unknown03(void)
276{
277 // OF: 0x6410
278 GPIOJ_ENABLE |= 0x2;
279 GPIOJ_OUTPUT_EN |= 0x2;
280 GPIOJ_OUTPUT_VAL &= ~0x02;
281}
282
283void unknown04(void)
284{
285 // OF: 0x623C
286
287 GPIOB_OUTPUT_VAL |= 0x4;
288 udelay(1000);
289 GPIOB_OUTPUT_VAL &= ~0x4;
290 sleep(HZ/10);
291 GPIOB_OUTPUT_VAL |= 0x4;
292 udelay(1000);
293}
294
295/* Run the display on sequence for the driver IC */
296static void lcd_display_on(void)
297{
298 display_on = true;
299}
300
301
302#if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
303bool lcd_active(void)
304{
305 return display_on;
306}
307
308/* Turn off visible display operations */
309static void lcd_display_off(void)
310{
311 display_on = false;
312}
313#endif
314
315void lcd_init_device(void)
316{
317
318#ifdef BOOTLOADER /* Bother at all to do this again? */
319//#if 0
320/* Init GPIO ports */
321 lcd_init_gpio();
322 lcd_power_on();
323 lcd_display_on();
324#else
325
326 power_on = true;
327 display_on = true;
328
329 lcd_set_invert_display(false);
330 lcd_set_flip(false);
331#endif
332}
333
334#if defined(HAVE_LCD_ENABLE)
335void lcd_enable(bool on)
336{
337 (void)on;
338}
339#endif
340
341#if defined(HAVE_LCD_SLEEP)
342void lcd_sleep(void)
343{
344
345}
346#endif
347
348void lcd_update(void)
349{
350 const fb_data *addr;
351
352 addr = &lcd_framebuffer[LCD_HEIGHT][LCD_WIDTH];
353
354 lcd_write_reg(0x20, 0x0);
355 lcd_write_reg(0x21, 0x0);
356
357 int i,j;
358 for(i=0; i < LCD_HEIGHT; i++)
359 {
360 for(j=0; j < LCD_WIDTH; j++)
361 {
362 lcd_write_reg(0x22, *addr);
363 addr++;
364 }
365 }
366}
367
368/* Update a fraction of the display. */
369void lcd_update_rect(int x, int y, int width, int height)
370{
371 (void)x;
372 (void)y;
373 (void)width;
374 (void)height;
375 lcd_update();
376}
377
378
379/*** hardware configuration ***/
380
381void lcd_set_contrast(int val)
382{
383 (void)val;
384}
385
386void lcd_set_invert_display(bool yesno)
387{
388 (void)yesno;
389}
390
391/* turn the display upside down (call lcd_update() afterwards) */
392void lcd_set_flip(bool yesno)
393{
394 (void)yesno;
395}
396
397/* Blitting functions */
398
399void lcd_yuv_set_options(unsigned options)
400{
401 lcd_yuv_options = options;
402}
403
404/* Line write helper function for lcd_yuv_blit. Write two lines of yuv420. */
405extern void lcd_write_yuv420_lines(fb_data *dst,
406 unsigned char const * const src[3],
407 int width,
408 int stride);
409extern void lcd_write_yuv420_lines_odither(fb_data *dst,
410 unsigned char const * const src[3],
411 int width,
412 int stride,
413 int x_screen, /* To align dither pattern */
414 int y_screen);
415
416void lcd_blit_yuv(unsigned char * const src[3],
417 int src_x, int src_y, int stride,
418 int x, int y, int width, int height)
419{
420 (void)src;
421 (void)src_x;
422 (void)src_y;
423 (void)stride;
424 (void)x;
425 (void)y;
426 (void)width;
427 (void)height;
428}