blob: 2181e26e640e9e8aecf910601d7bc0613d13a491 [file] [log] [blame]
Mark Arigob4275d42008-05-21 03:55:17 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2008 by Mark Arigo
11 *
Daniel Stenberg2acc0ac2008-06-28 18:10:04 +000012 * 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.
Mark Arigob4275d42008-05-21 03:55:17 +000016 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#include "config.h"
22#include "cpu.h"
23#include "lcd.h"
24#include "kernel.h"
25#include "system.h"
26
27/* Display status */
28static unsigned lcd_yuv_options SHAREDBSS_ATTR = 0;
29
30/* wait for LCD */
31static inline void lcd_wait_write(void)
32{
33 while (LCD1_CONTROL & LCD1_BUSY_MASK);
34}
35
36/* send LCD data */
37static void lcd_send_data(unsigned data)
38{
39 lcd_wait_write();
40 LCD1_DATA = data >> 8;
41 lcd_wait_write();
42 LCD1_DATA = data & 0xff;
43}
44
45/* send LCD command */
46static void lcd_send_command(unsigned cmd)
47{
48 lcd_wait_write();
49 LCD1_CMD = cmd >> 8;
50 lcd_wait_write();
51 LCD1_CMD = cmd & 0xff;
52}
53
54static void lcd_write_reg(unsigned reg, unsigned data)
55{
56 lcd_send_command(reg);
57 lcd_send_data(data);
58}
59
60void lcd_init_device(void)
61{
62#if 0
63 /* This is the init done by the OF bootloader.
64 Re-initializing the lcd causes it to flash
65 a white screen, so for now disable this. */
66 DEV_INIT1 &= ~0x3000;
67 DEV_INIT1 = DEV_INIT1;
68 DEV_INIT2 &= ~0x400;
69
70 LCD1_CONTROL = 0x4680;
71 udelay(1500);
72 LCD1_CONTROL = 0x4684;
73
74 outl(1, 0x70003018);
75
76 LCD1_CONTROL &= ~0x200;
77 LCD1_CONTROL &= ~0x800;
78 LCD1_CONTROL &= ~0x400;
79 udelay(30000);
80
81 LCD1_CONTROL |= 0x1;
82
83 lcd_write_reg(0x0000, 0x0001);
84 udelay(50000);
85
86 lcd_write_reg(0x0011, 0x171f);
87 lcd_write_reg(0x0012, 0x0001);
88 lcd_write_reg(0x0013, 0x08cd);
89 lcd_write_reg(0x0014, 0x0416);
90 lcd_write_reg(0x0010, 0x1208);
91 udelay(50000);
92
93 lcd_write_reg(0x0013, 0x081C);
94 udelay(200000);
95
96 lcd_write_reg(0x0001, 0x0a0c);
97 lcd_write_reg(0x0002, 0x0200);
98 lcd_write_reg(0x0003, 0x1030);
99 lcd_write_reg(0x0007, 0x0005);
100 lcd_write_reg(0x0008, 0x030a);
101 lcd_write_reg(0x000b, 0x0000);
102 lcd_write_reg(0x000c, 0x0000);
103 lcd_write_reg(0x0030, 0x0000);
104 lcd_write_reg(0x0031, 0x0204);
105 lcd_write_reg(0x0032, 0x0001);
106 lcd_write_reg(0x0033, 0x0600);
107 lcd_write_reg(0x0034, 0x0607);
108 lcd_write_reg(0x0035, 0x0305);
109 lcd_write_reg(0x0036, 0x0707);
110 lcd_write_reg(0x0037, 0x0006);
111 lcd_write_reg(0x0038, 0x0400);
112 lcd_write_reg(0x0040, 0x0000);
113 lcd_write_reg(0x0042, 0x9f00);
114 lcd_write_reg(0x0043, 0x0000);
115 lcd_write_reg(0x0044, 0x7f00);
116 lcd_write_reg(0x0045, 0x9f00);
117 lcd_write_reg(0x00a8, 0x0125);
118 lcd_write_reg(0x00a9, 0x0014);
119 lcd_write_reg(0x00a7, 0x0022);
120
121 lcd_write_reg(0x0007, 0x0021);
122 udelay(40000);
123 lcd_write_reg(0x0007, 0x0023);
124 udelay(40000);
125 lcd_write_reg(0x0007, 0x1037);
126
127 lcd_write_reg(0x0021, 0x0000);
128#endif
129}
130
131/*** hardware configuration ***/
132#if 0
133int lcd_default_contrast(void)
134{
135 return DEFAULT_CONTRAST_SETTING;
136}
137#endif
138
139void lcd_set_contrast(int val)
140{
141 (void)val;
142}
143
144void lcd_set_invert_display(bool yesno)
145{
146 (void)yesno;
147}
148
149/* turn the display upside down (call lcd_update() afterwards) */
150void lcd_set_flip(bool yesno)
151{
152 (void)yesno;
153}
154
155void lcd_yuv_set_options(unsigned options)
156{
157 lcd_yuv_options = options;
158}
159
160/* Performance function to blit a YUV bitmap directly to the LCD */
161void lcd_blit_yuv(unsigned char * const src[3],
162 int src_x, int src_y, int stride,
163 int x, int y, int width, int height)
164{
165 (void)src;
166 (void)src_x;
167 (void)src_y;
168 (void)stride;
169 (void)x;
170 (void)y;
171 (void)width;
172 (void)height;
173}
174
175/* Update the display.
176 This must be called after all other LCD functions that change the display. */
177void lcd_update(void)
178{
179 lcd_update_rect(0, 0, LCD_WIDTH, LCD_HEIGHT);
180}
181
182/* Update a fraction of the display. */
183void lcd_update_rect(int x, int y, int width, int height)
184{
185 const fb_data *addr;
186
187 if (x + width >= LCD_WIDTH)
188 width = LCD_WIDTH - x;
189 if (y + height >= LCD_HEIGHT)
190 height = LCD_HEIGHT - y;
191
192 if ((width <= 0) || (height <= 0))
193 return; /* Nothing left to do. */
194
195 addr = &lcd_framebuffer[y][x];
196
197 do {
198 lcd_write_reg(0x0021, ((y++ & 0xff) << 8) | (x & 0xff));
199 lcd_send_command(0x0022);
200
201 int w = width;
202 do {
203 lcd_send_data(*addr++);
204 } while (--w > 0);
205 addr += LCD_WIDTH - width;
206 } while (--height > 0);
207}