summaryrefslogtreecommitdiff
path: root/firmware/target/arm/samsung/yh920/lcd-yh920.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/arm/samsung/yh920/lcd-yh920.c')
-rw-r--r--firmware/target/arm/samsung/yh920/lcd-yh920.c294
1 files changed, 294 insertions, 0 deletions
diff --git a/firmware/target/arm/samsung/yh920/lcd-yh920.c b/firmware/target/arm/samsung/yh920/lcd-yh920.c
new file mode 100644
index 0000000000..6c1528b630
--- /dev/null
+++ b/firmware/target/arm/samsung/yh920/lcd-yh920.c
@@ -0,0 +1,294 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
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#include "config.h"
22
23#include "system.h"
24#include "kernel.h"
25#include "lcd.h"
26
27/*** definitions ***/
28
29/* LCD command codes */
30#define LCD_CNTL_POWER_CONTROL 0x25
31#define LCD_CNTL_VOLTAGE_SELECT 0x2b
32#define LCD_CNTL_LINE_INVERT_DRIVE 0x36
33#define LCD_CNTL_GRAY_SCALE_PATTERN 0x39
34#define LCD_CNTL_TEMP_GRADIENT_SELECT 0x4e
35#define LCD_CNTL_OSC_FREQUENCY 0x5f
36#define LCD_CNTL_ON_OFF 0xae
37#define LCD_CNTL_OSC_ON_OFF 0xaa
38#define LCD_CNTL_OFF_MODE 0xbe
39#define LCD_CNTL_REVERSE 0xa6
40#define LCD_CNTL_ALL_LIGHTING 0xa4
41#define LCD_CNTL_COMMON_OUTPUT_STATUS 0xc4
42#define LCD_CNTL_COLUMN_ADDRESS_DIR 0xa0
43#define LCD_CNTL_NLINE_ON_OFF 0xe4
44#define LCD_CNTL_DISPLAY_MODE 0x66
45#define LCD_CNTL_DUTY_SET 0x6d
46#define LCD_CNTL_ELECTRONIC_VOLUME 0x81
47#define LCD_CNTL_DATA_INPUT_DIR 0x84
48#define LCD_CNTL_DISPLAY_START_LINE 0x8a
49#define LCD_CNTL_AREA_SCROLL 0x10
50
51#define LCD_CNTL_PAGE 0xb1
52#define LCD_CNTL_COLUMN 0x13
53#define LCD_CNTL_DATA_WRITE 0x1d
54
55/* lcd commands */
56static void lcd_send_data(unsigned byte)
57{
58 while (LCD1_CONTROL & LCD1_BUSY_MASK); /* wait for LCD */
59 LCD1_DATA = byte;
60}
61
62static void lcd_send_cmd(unsigned byte)
63{
64 while (LCD1_CONTROL & LCD1_BUSY_MASK); /* wait for LCD */
65 LCD1_CMD = byte;
66}
67
68static void lcd_write_reg(unsigned cmd, unsigned data)
69{
70 lcd_send_cmd(cmd);
71 lcd_send_data(data);
72}
73
74static void lcd_write_reg_ex(unsigned cmd, unsigned data0, unsigned data1)
75{
76 lcd_send_cmd(cmd);
77 lcd_send_data(data0);
78 lcd_send_data(data1);
79}
80
81/*** hardware configuration ***/
82int lcd_default_contrast(void)
83{
84 return DEFAULT_CONTRAST_SETTING;
85}
86
87void lcd_set_contrast(int val)
88{
89 /* Keep val in acceptable hw range */
90 if (val < 0)
91 val = 0;
92 else if (val > 127)
93 val = 127;
94
95 lcd_write_reg_ex(LCD_CNTL_ELECTRONIC_VOLUME, val, -1);
96}
97
98void lcd_set_invert_display(bool yesno)
99{
100 lcd_send_cmd(LCD_CNTL_REVERSE | (yesno?1:0));
101}
102
103/* turn the display upside down (call lcd_update() afterwards) */
104void lcd_set_flip(bool yesno)
105{
106 if (yesno)
107 {
108 lcd_send_cmd(LCD_CNTL_COLUMN_ADDRESS_DIR | 1);
109 lcd_send_cmd(LCD_CNTL_COMMON_OUTPUT_STATUS | 0);
110 lcd_write_reg_ex(LCD_CNTL_DUTY_SET, 0x20, 0);
111 }
112 else
113 {
114 lcd_send_cmd(LCD_CNTL_COLUMN_ADDRESS_DIR | 0);
115 lcd_send_cmd(LCD_CNTL_COMMON_OUTPUT_STATUS | 1);
116 lcd_write_reg_ex(LCD_CNTL_DUTY_SET, 0x20, 1);
117 }
118}
119
120void lcd_init_device(void)
121{
122#if 0
123 /* This is the init sequence from the yh820 OF bootloader */
124 unsigned long tmp;
125
126 DEV_INIT2 |= 0x400;
127
128 DEV_INIT1 &= ~0x3000;
129 tmp = DEV_INIT1;
130 DEV_INIT1 = tmp;
131 DEV_INIT2 &= ~0x400;
132
133 LCD1_CONTROL &= ~0x4;
134 udelay(15);
135 LCD1_CONTROL |= 0x4;
136
137 LCD1_CONTROL = 0x680;
138 LCD1_CONTROL = 0x684;
139
140 LCD1_CONTROL |= 0x1;
141
142 lcd_send_cmd(LCD_CNTL_RESET);
143 lcd_send_cmd(LCD_CNTL_DISCHARGE_ON_OFF | 0);
144 lcd_send_cmd(LCD_CNTL_ON_OFF | 0); /* LCD OFF */
145 lcd_send_cmd(LCD_CNTL_COLUMN_ADDRESS_DIR | 0); /* Normal */
146 lcd_send_cmd(LCD_CNTL_COMMON_OUTPUT_STATUS | 0); /* Normal */
147 lcd_send_cmd(LCD_CNTL_REVERSE | 0); /* Reverse OFF */
148 lcd_send_cmd(LCD_CNTL_ALL_LIGHTING | 0); /* Normal */
149 lcd_write_reg_ex(LCD_CNTL_DUTY_SET, 0x1f, 0x00);
150 lcd_send_cmd(LCD_CNTL_OFF_MODE | 1); /* OFF -> VCC on drivers */
151 lcd_write_reg(LCD_CNTL_VOLTAGE_SELECT, 0x03);
152 lcd_write_reg(LCD_CNTL_ELECTRONIC_VOLUME, 0x40);
153 lcd_write_reg(LCD_CNTL_TEMP_GRADIENT_SELECT, 0x00);
154 lcd_write_reg(LCD_CNTL_LINE_INVERT_DRIVE, 0x1f);
155 lcd_send_cmd(LCD_CNTL_NLINE_ON_OFF | 1); /* N-line ON */
156 lcd_write_reg(LCD_CNTL_OSC_FREQUENCY, 0x00);
157 lcd_send_cmd(LCD_CNTL_OSC_ON_OFF | 1); /* Oscillator ON */
158 lcd_write_reg(LCD_CNTL_STEPUP_CK_FREQ, 0x03);
159 lcd_write_reg(LCD_CNTL_POWER_CONTROL, 0x1c);
160 lcd_write_reg(LCD_CNTL_POWER_CONTROL, 0x1e);
161 lcd_write_reg(LCD_CNTL_DISPLAY_START_LINE, 0x00);
162 lcd_send_cmd(LCD_CNTL_DATA_INPUT_DIR | 0); /* Column mode */
163 lcd_send_cmd(LCD_CNTL_DISPLAY_MODE, 0); /* Greyscale mode */
164 lcd_write_reg(LCD_CNTL_GRAY_SCALE_PATTERN, 0x52);
165 lcd_send_cmd(LCD_CNTL_PARTIAL_DISPLAY_ON_OFF | 0);
166 lcd_write_reg(LCD_CNTL_POWER_CONTROL, 0x1f);
167 lcd_send_cmd(LCD_CNTL_ON_OFF | 1); /* LCD ON */
168#endif
169}
170
171/*** update functions ***/
172
173/* Performance function that works with an external buffer
174 note that by and bheight are in 8-pixel units! */
175void lcd_blit_mono(const unsigned char *data, int x, int by, int width,
176 int bheight, int stride)
177{
178 (void)data;
179 (void)x;
180 (void)by;
181 (void)width;
182 (void)bheight;
183 (void)stride;
184
185#if 0
186 /* This is from the h100 lcd code, perhaps we can adapt */
187 const unsigned char *src, *src_end;
188 unsigned char *dst_u, *dst_l;
189 static unsigned char upper[LCD_WIDTH] IBSS_ATTR;
190 static unsigned char lower[LCD_WIDTH] IBSS_ATTR;
191 unsigned int byte;
192
193 by *= 2;
194
195 while (bheight--)
196 {
197 src = data;
198 src_end = data + width;
199 dst_u = upper;
200 dst_l = lower;
201 do
202 {
203 byte = *src++;
204 *dst_u++ = lcd_dibits[byte & 0x0F];
205 byte >>= 4;
206 *dst_l++ = lcd_dibits[byte & 0x0F];
207 }
208 while (src < src_end);
209
210 lcd_write_reg_ex(LCD_CNTL_PAGE, by++, -1);
211 lcd_write_reg_ex(LCD_CNTL_COLUMN, x, -1);
212 lcd_send_cmd(LCD_CNTL_DATA_WRITE);
213 lcd_write_data(upper, width);
214
215 lcd_write_reg_ex(LCD_CNTL_PAGE, by++, -1);
216 lcd_write_reg_ex(LCD_CNTL_COLUMN, x, -1);
217 lcd_send_cmd(LCD_CNTL_DATA_WRITE);
218 lcd_write_data(lower, width);
219
220 data += stride;
221 }
222#endif
223}
224
225/* Helper function for lcd_grey_phase_blit(). */
226/* void lcd_grey_data(unsigned char *values, unsigned char *phases, int count); */
227
228/* Performance function that works with an external buffer
229 note that by and bheight are in 4-pixel units! */
230void lcd_blit_grey_phase(unsigned char *values, unsigned char *phases,
231 int x, int by, int width, int bheight, int stride)
232{
233 (void)values;
234 (void)phases;
235 (void)x;
236 (void)by;
237 (void)width;
238 (void)bheight;
239 (void)stride;
240
241#if 0
242 /* This is from the h100 lcd code, perhaps we can adapt */
243 stride <<= 2; /* 4 pixels per block */
244 while (bheight--)
245 {
246 lcd_write_reg_ex(LCD_CNTL_PAGE, by++, -1);
247 lcd_write_reg_ex(LCD_CNTL_COLUMN, x, -1);
248 lcd_send_cmd(LCD_CNTL_DATA_WRITE);
249 lcd_grey_data(values, phases, width);
250 values += stride;
251 phases += stride;
252 }
253#endif
254}
255
256/* Update a fraction of the display. */
257/* void lcd_update_rect(int, int, int, int) ICODE_ATTR; */
258void lcd_update_rect(int x0, int y, int width, int height)
259{
260 const fb_data *addr;
261 int ymax;
262 int x = x0;
263
264 /* The Y coordinates have to work on even 8 pixel rows */
265 ymax = (y + height-1) >> 2;
266 y >>= 2;
267
268 if(x + width > LCD_WIDTH)
269 width = LCD_WIDTH - x;
270 if (width <= 0)
271 return; /* nothing left to do, 0 is harmful to lcd_write_data() */
272 if(ymax >= LCD_FBHEIGHT)
273 ymax = LCD_FBHEIGHT-1;
274
275 /* Copy specified rectange bitmap to hardware */
276 for (; y <= ymax; y++)
277 {
278 lcd_write_reg(LCD_CNTL_PAGE, y);
279 lcd_write_reg(LCD_CNTL_COLUMN, x0);
280
281 addr = &lcd_framebuffer[y][x0];
282
283 lcd_send_cmd(LCD_CNTL_DATA_WRITE);
284 for (x = x0; x < width; x++)
285 lcd_send_data(*addr++);
286 }
287}
288
289/* Update the display.
290 This must be called after all other LCD functions that change the display. */
291void lcd_update(void)
292{
293 lcd_update_rect(0, 0, LCD_WIDTH, LCD_HEIGHT);
294}