lcd drivers: Convert lcd_[remote_]framebuffer to a pointer
[maemo-rb.git] / firmware / target / coldfire / iriver / h100 / lcd-h100.c
blobb13751b9eb6e51187133fc1e84112c728f9a21ea
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2004 by Linus Nielsen Feltzing
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.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
21 #include "config.h"
23 #include "system.h"
24 #include "kernel.h"
25 #include "lcd.h"
27 /*** definitions ***/
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
51 #define LCD_CNTL_PAGE 0xb1
52 #define LCD_CNTL_COLUMN 0x13
53 #define LCD_CNTL_DATA_WRITE 0x1d
55 /*** shared semi-private declarations ***/
56 extern const unsigned char lcd_dibits[16] ICONST_ATTR;
58 /*** hardware configuration ***/
59 int lcd_default_contrast(void)
61 return DEFAULT_CONTRAST_SETTING;
64 void lcd_set_contrast(int val)
66 /* Keep val in acceptable hw range */
67 if (val < 0)
68 val = 0;
69 else if (val > 127)
70 val = 127;
72 lcd_write_command_ex(LCD_CNTL_ELECTRONIC_VOLUME, val, -1);
75 void lcd_set_invert_display(bool yesno)
77 lcd_write_command(LCD_CNTL_REVERSE | (yesno?1:0));
80 /* turn the display upside down (call lcd_update() afterwards) */
81 void lcd_set_flip(bool yesno)
83 if (yesno)
85 lcd_write_command(LCD_CNTL_COLUMN_ADDRESS_DIR | 1);
86 lcd_write_command(LCD_CNTL_COMMON_OUTPUT_STATUS | 0);
87 lcd_write_command_ex(LCD_CNTL_DUTY_SET, 0x20, 0);
89 else
91 lcd_write_command(LCD_CNTL_COLUMN_ADDRESS_DIR | 0);
92 lcd_write_command(LCD_CNTL_COMMON_OUTPUT_STATUS | 1);
93 lcd_write_command_ex(LCD_CNTL_DUTY_SET, 0x20, 1);
97 void lcd_init_device(void)
99 /* GPO35 is the LCD A0 pin
100 GPO46 is LCD RESET */
101 or_l(0x00004008, &GPIO1_OUT);
102 or_l(0x00004008, &GPIO1_ENABLE);
103 or_l(0x00004008, &GPIO1_FUNCTION);
105 /* Reset LCD */
106 sleep(1);
107 and_l(~0x00004000, &GPIO1_OUT);
108 sleep(1);
109 or_l(0x00004000, &GPIO1_OUT);
110 sleep(1);
112 lcd_write_command(LCD_CNTL_COLUMN_ADDRESS_DIR | 0); /* Normal */
113 lcd_write_command(LCD_CNTL_COMMON_OUTPUT_STATUS | 1); /* Reverse dir */
114 lcd_write_command(LCD_CNTL_REVERSE | 0); /* Reverse OFF */
115 lcd_write_command(LCD_CNTL_ALL_LIGHTING | 0); /* Normal */
116 lcd_write_command_ex(LCD_CNTL_DUTY_SET, 0x20, 1);
117 lcd_write_command(LCD_CNTL_OFF_MODE | 1); /* OFF -> VCC on drivers */
118 lcd_write_command_ex(LCD_CNTL_VOLTAGE_SELECT, 3, -1);
119 lcd_write_command_ex(LCD_CNTL_ELECTRONIC_VOLUME, 0x1c, -1);
120 lcd_write_command_ex(LCD_CNTL_TEMP_GRADIENT_SELECT, 0, -1);
122 lcd_write_command_ex(LCD_CNTL_LINE_INVERT_DRIVE, 0x10, -1);
123 lcd_write_command(LCD_CNTL_NLINE_ON_OFF | 1); /* N-line ON */
125 lcd_write_command_ex(LCD_CNTL_OSC_FREQUENCY, 3, -1);
126 lcd_write_command(LCD_CNTL_OSC_ON_OFF | 1); /* Oscillator ON */
128 lcd_write_command_ex(LCD_CNTL_POWER_CONTROL, 0x16, -1);
129 sleep(HZ/10); /* 100 ms pause */
130 lcd_write_command_ex(LCD_CNTL_POWER_CONTROL, 0x17, -1);
132 lcd_write_command_ex(LCD_CNTL_DISPLAY_START_LINE, 0, -1);
133 lcd_write_command_ex(LCD_CNTL_GRAY_SCALE_PATTERN, 0x43, -1);
134 lcd_write_command_ex(LCD_CNTL_DISPLAY_MODE, 0, -1); /* Greyscale mode */
135 lcd_write_command(LCD_CNTL_DATA_INPUT_DIR | 0); /* Column mode */
137 lcd_update();
138 lcd_write_command(LCD_CNTL_ON_OFF | 1); /* LCD ON */
141 /*** update functions ***/
143 /* Performance function that works with an external buffer
144 note that by and bheight are in 8-pixel units! */
145 void lcd_blit_mono(const unsigned char *data, int x, int by, int width,
146 int bheight, int stride)
148 const unsigned char *src, *src_end;
149 unsigned char *dst_u, *dst_l;
150 static unsigned char upper[LCD_WIDTH] IBSS_ATTR;
151 static unsigned char lower[LCD_WIDTH] IBSS_ATTR;
152 unsigned int byte;
154 by *= 2;
156 while (bheight--)
158 src = data;
159 src_end = data + width;
160 dst_u = upper;
161 dst_l = lower;
164 byte = *src++;
165 *dst_u++ = lcd_dibits[byte & 0x0F];
166 byte >>= 4;
167 *dst_l++ = lcd_dibits[byte & 0x0F];
169 while (src < src_end);
171 lcd_write_command_ex(LCD_CNTL_PAGE, by++, -1);
172 lcd_write_command_ex(LCD_CNTL_COLUMN, x, -1);
173 lcd_write_command(LCD_CNTL_DATA_WRITE);
174 lcd_write_data(upper, width);
176 lcd_write_command_ex(LCD_CNTL_PAGE, by++, -1);
177 lcd_write_command_ex(LCD_CNTL_COLUMN, x, -1);
178 lcd_write_command(LCD_CNTL_DATA_WRITE);
179 lcd_write_data(lower, width);
181 data += stride;
185 /* Helper function for lcd_grey_phase_blit(). */
186 void lcd_grey_data(unsigned char *values, unsigned char *phases, int count);
188 /* Performance function that works with an external buffer
189 note that by and bheight are in 4-pixel units! */
190 void lcd_blit_grey_phase(unsigned char *values, unsigned char *phases,
191 int x, int by, int width, int bheight, int stride)
193 stride <<= 2; /* 4 pixels per block */
194 while (bheight--)
196 lcd_write_command_ex(LCD_CNTL_PAGE, by++, -1);
197 lcd_write_command_ex(LCD_CNTL_COLUMN, x, -1);
198 lcd_write_command(LCD_CNTL_DATA_WRITE);
199 lcd_grey_data(values, phases, width);
200 values += stride;
201 phases += stride;
205 /* Update the display.
206 This must be called after all other LCD functions that change the display. */
207 void lcd_update(void) ICODE_ATTR;
208 void lcd_update(void)
210 int y;
212 /* Copy display bitmap to hardware */
213 for (y = 0; y < LCD_FBHEIGHT; y++)
215 lcd_write_command_ex(LCD_CNTL_PAGE, y, -1);
216 lcd_write_command_ex(LCD_CNTL_COLUMN, 0, -1);
218 lcd_write_command(LCD_CNTL_DATA_WRITE);
219 lcd_write_data (FBADDR(0, y), LCD_WIDTH);
223 /* Update a fraction of the display. */
224 void lcd_update_rect(int, int, int, int) ICODE_ATTR;
225 void lcd_update_rect(int x, int y, int width, int height)
227 int ymax;
229 /* The Y coordinates have to work on even 8 pixel rows */
230 ymax = (y + height-1) >> 2;
231 y >>= 2;
233 if(x + width > LCD_WIDTH)
234 width = LCD_WIDTH - x;
235 if (width <= 0)
236 return; /* nothing left to do, 0 is harmful to lcd_write_data() */
237 if(ymax >= LCD_FBHEIGHT)
238 ymax = LCD_FBHEIGHT-1;
240 /* Copy specified rectange bitmap to hardware */
241 for (; y <= ymax; y++)
243 lcd_write_command_ex(LCD_CNTL_PAGE, y, -1);
244 lcd_write_command_ex(LCD_CNTL_COLUMN, x, -1);
246 lcd_write_command(LCD_CNTL_DATA_WRITE);
247 lcd_write_data (FBADDR(x,y), width);