lcd drivers: Convert lcd_[remote_]framebuffer to a pointer
[maemo-rb.git] / firmware / target / coldfire / iaudio / m5 / lcd-m5.c
blob8f022adf96b73fc74bb2a67e3153f6127b9b4591
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2007 by Jens Arnold
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_POWER_SAVE 0xa8
40 #define LCD_CNTL_REVERSE 0xa6
41 #define LCD_CNTL_ALL_LIGHTING 0xa4
42 #define LCD_CNTL_COMMON_OUTPUT_STATUS 0xc4
43 #define LCD_CNTL_COLUMN_ADDRESS_DIR 0xa0
44 #define LCD_CNTL_NLINE_ON_OFF 0xe4
45 #define LCD_CNTL_DISPLAY_MODE 0x66
46 #define LCD_CNTL_DUTY_SET 0x6d
47 #define LCD_CNTL_ELECTRONIC_VOLUME 0x81
48 #define LCD_CNTL_DATA_INPUT_DIR 0x84
49 #define LCD_CNTL_DISPLAY_START_LINE 0x8a
50 #define LCD_CNTL_AREA_SCROLL 0x10
52 #define LCD_CNTL_PAGE 0xb1
53 #define LCD_CNTL_COLUMN 0x13
54 #define LCD_CNTL_DATA_WRITE 0x1d
56 /*** shared semi-private declarations ***/
57 extern const unsigned char lcd_dibits[16] ICONST_ATTR;
59 /*** hardware configuration ***/
60 int lcd_default_contrast(void)
62 return DEFAULT_CONTRAST_SETTING;
65 void lcd_set_contrast(int val)
67 /* Keep val in acceptable hw range */
68 if (val < 0)
69 val = 0;
70 else if (val > 127)
71 val = 127;
73 lcd_write_command_ex(LCD_CNTL_ELECTRONIC_VOLUME, val, -1);
76 void lcd_set_invert_display(bool yesno)
78 lcd_write_command(LCD_CNTL_REVERSE | (yesno?1:0));
81 /* turn the display upside down (call lcd_update() afterwards) */
82 void lcd_set_flip(bool yesno)
84 if (yesno)
86 lcd_write_command(LCD_CNTL_COLUMN_ADDRESS_DIR | 0);
87 lcd_write_command(LCD_CNTL_COMMON_OUTPUT_STATUS | 1);
88 lcd_write_command_ex(LCD_CNTL_DUTY_SET, 0x20, 2);
90 else
92 lcd_write_command(LCD_CNTL_COLUMN_ADDRESS_DIR | 1);
93 lcd_write_command(LCD_CNTL_COMMON_OUTPUT_STATUS | 0);
94 lcd_write_command_ex(LCD_CNTL_DUTY_SET, 0x20, 1);
98 void lcd_init_device(void)
100 /* LCD Reset */
101 and_l(~0x00000010, &GPIO1_OUT);
102 or_l(0x00000010, &GPIO1_ENABLE);
103 or_l(0x00000010, &GPIO1_FUNCTION);
104 sleep(1);
105 or_l(0x00000010, &GPIO1_OUT);
106 sleep(1);
108 lcd_write_command(LCD_CNTL_ON_OFF | 1); /* LCD ON */
109 lcd_write_command(LCD_CNTL_OFF_MODE | 1); /* OFF -> VCC on drivers */
110 lcd_write_command(LCD_CNTL_REVERSE | 0); /* Reverse OFF */
111 lcd_write_command(LCD_CNTL_ALL_LIGHTING | 0); /* Normal */
112 lcd_write_command(LCD_CNTL_COMMON_OUTPUT_STATUS | 0); /* Normal dir */
113 lcd_write_command_ex(LCD_CNTL_DISPLAY_START_LINE, 4, -1);
114 lcd_write_command(LCD_CNTL_COLUMN_ADDRESS_DIR | 1); /* Reverse */
115 lcd_write_command_ex(LCD_CNTL_DISPLAY_MODE, 0, -1); /* Greyscale mode */
116 lcd_write_command_ex(LCD_CNTL_GRAY_SCALE_PATTERN, 0x53, -1);
117 lcd_write_command_ex(LCD_CNTL_DUTY_SET, 0x20, 1);
118 lcd_write_command_ex(LCD_CNTL_ELECTRONIC_VOLUME, 40, -1);
120 lcd_write_command(LCD_CNTL_OSC_ON_OFF | 1); /* Oscillator ON */
121 lcd_write_command(LCD_CNTL_POWER_SAVE | 0);
122 lcd_write_command_ex(LCD_CNTL_VOLTAGE_SELECT, 3, -1);
123 lcd_write_command_ex(LCD_CNTL_POWER_CONTROL, 0x17, -1);
124 lcd_write_command_ex(LCD_CNTL_OSC_FREQUENCY, 3, -1);
125 lcd_write_command(LCD_CNTL_NLINE_ON_OFF | 1); /* N-line ON */
126 lcd_write_command_ex(LCD_CNTL_LINE_INVERT_DRIVE, 0x10, -1);
127 lcd_write_command_ex(LCD_CNTL_TEMP_GRADIENT_SELECT, 0, -1);
129 lcd_update();
132 /*** update functions ***/
134 /* Performance function that works with an external buffer
135 note that by and bheight are in 8-pixel units! */
136 void lcd_blit_mono(const unsigned char *data, int x, int by, int width,
137 int bheight, int stride)
139 const unsigned char *src, *src_end;
140 unsigned char *dst_u, *dst_l;
141 static unsigned char upper[LCD_WIDTH] IBSS_ATTR;
142 static unsigned char lower[LCD_WIDTH] IBSS_ATTR;
143 unsigned int byte;
145 by *= 2;
147 while (bheight--)
149 src = data;
150 src_end = data + width;
151 dst_u = upper;
152 dst_l = lower;
155 byte = *src++;
156 *dst_u++ = lcd_dibits[byte & 0x0F];
157 byte >>= 4;
158 *dst_l++ = lcd_dibits[byte & 0x0F];
160 while (src < src_end);
162 lcd_write_command_ex(LCD_CNTL_PAGE, by++, -1);
163 lcd_write_command_ex(LCD_CNTL_COLUMN, x, -1);
164 lcd_write_command(LCD_CNTL_DATA_WRITE);
165 lcd_write_data(upper, width);
167 lcd_write_command_ex(LCD_CNTL_PAGE, by++, -1);
168 lcd_write_command_ex(LCD_CNTL_COLUMN, x, -1);
169 lcd_write_command(LCD_CNTL_DATA_WRITE);
170 lcd_write_data(lower, width);
172 data += stride;
176 /* Helper function for lcd_grey_phase_blit(). */
177 void lcd_grey_data(unsigned char *values, unsigned char *phases, int count);
179 /* Performance function that works with an external buffer
180 note that by and bheight are in 4-pixel units! */
181 void lcd_blit_grey_phase(unsigned char *values, unsigned char *phases,
182 int x, int by, int width, int bheight, int stride)
184 stride <<= 2; /* 4 pixels per block */
185 while (bheight--)
187 lcd_write_command_ex(LCD_CNTL_PAGE, by++, -1);
188 lcd_write_command_ex(LCD_CNTL_COLUMN, x, -1);
189 lcd_write_command(LCD_CNTL_DATA_WRITE);
190 lcd_grey_data(values, phases, width);
191 values += stride;
192 phases += stride;
196 /* Update the display.
197 This must be called after all other LCD functions that change the display. */
198 void lcd_update(void) ICODE_ATTR;
199 void lcd_update(void)
201 int y;
203 /* Copy display bitmap to hardware */
204 for (y = 0; y < LCD_FBHEIGHT; y++)
206 lcd_write_command_ex(LCD_CNTL_PAGE, y, -1);
207 lcd_write_command_ex(LCD_CNTL_COLUMN, 0, -1);
209 lcd_write_command(LCD_CNTL_DATA_WRITE);
210 lcd_write_data (FBADDR(0, y), LCD_WIDTH);
214 /* Update a fraction of the display. */
215 void lcd_update_rect(int, int, int, int) ICODE_ATTR;
216 void lcd_update_rect(int x, int y, int width, int height)
218 int ymax;
220 /* The Y coordinates have to work on even 8 pixel rows */
221 ymax = (y + height-1) >> 2;
222 y >>= 2;
224 if(x + width > LCD_WIDTH)
225 width = LCD_WIDTH - x;
226 if (width <= 0)
227 return; /* nothing left to do, 0 is harmful to lcd_write_data() */
228 if(ymax >= LCD_FBHEIGHT)
229 ymax = LCD_FBHEIGHT-1;
231 /* Copy specified rectange bitmap to hardware */
232 for (; y <= ymax; y++)
234 lcd_write_command_ex(LCD_CNTL_PAGE, y, -1);
235 lcd_write_command_ex(LCD_CNTL_COLUMN, x, -1);
237 lcd_write_command(LCD_CNTL_DATA_WRITE);
238 lcd_write_data (FBADDR(x,y), width);