lcd drivers: Convert lcd_[remote_]framebuffer to a pointer
[maemo-rb.git] / firmware / target / arm / olympus / mrobe-100 / lcd-mr100.c
blobd336ad7419b69bec1068ea1c73e2012910fe85f5
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2008 by Mark Arigo
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"
22 #include "cpu.h"
23 #include "lcd.h"
24 #include "kernel.h"
25 #include "system.h"
27 /* The m:robe 100 display has a register set that is very similar to the
28 Solomon SSD1815 */
30 /*** definitions ***/
32 #define LCD_SET_LOWER_COLUMN_ADDRESS ((char)0x00)
33 #define LCD_SET_HIGHER_COLUMN_ADDRESS ((char)0x10)
34 #define LCD_SET_INTERNAL_REGULATOR_RESISTOR_RATIO ((char)0x20)
35 #define LCD_SET_POWER_CONTROL_REGISTER ((char)0x28)
36 #define LCD_SET_DISPLAY_START_LINE ((char)0x40)
37 #define LCD_SET_CONTRAST_CONTROL_REGISTER ((char)0x81)
38 #define LCD_SET_SEGMENT_REMAP ((char)0xA0)
39 #define LCD_SET_LCD_BIAS ((char)0xA2)
40 #define LCD_SET_ENTIRE_DISPLAY_OFF ((char)0xA4)
41 #define LCD_SET_ENTIRE_DISPLAY_ON ((char)0xA5)
42 #define LCD_SET_NORMAL_DISPLAY ((char)0xA6)
43 #define LCD_SET_REVERSE_DISPLAY ((char)0xA7)
44 #define LCD_SET_MULTIPLEX_RATIO ((char)0xA8)
45 #define LCD_SET_BIAS_TC_OSC ((char)0xA9)
46 #define LCD_SET_1OVER4_BIAS_RATIO ((char)0xAA)
47 #define LCD_SET_INDICATOR_OFF ((char)0xAC)
48 #define LCD_SET_INDICATOR_ON ((char)0xAD)
49 #define LCD_SET_DISPLAY_OFF ((char)0xAE)
50 #define LCD_SET_DISPLAY_ON ((char)0xAF)
51 #define LCD_SET_PAGE_ADDRESS ((char)0xB0)
52 #define LCD_SET_COM_OUTPUT_SCAN_DIRECTION ((char)0xC0)
53 #define LCD_SET_TOTAL_FRAME_PHASES ((char)0xD2)
54 #define LCD_SET_DISPLAY_OFFSET ((char)0xD3)
55 #define LCD_SET_READ_MODIFY_WRITE_MODE ((char)0xE0)
56 #define LCD_SOFTWARE_RESET ((char)0xE2)
57 #define LCD_NOP ((char)0xE3)
58 #define LCD_SET_END_OF_READ_MODIFY_WRITE_MODE ((char)0xEE)
60 /* LCD command codes */
62 #define LCD_CNTL_RESET 0xe2 /* Software reset */
63 #define LCD_CNTL_POWER 0x2f /* Power control */
64 #define LCD_CNTL_CONTRAST 0x81 /* Contrast */
65 #define LCD_CNTL_OUTSCAN 0xc8 /* Output scan direction */
66 #define LCD_CNTL_SEGREMAP 0xa1 /* Segment remap */
67 #define LCD_CNTL_DISPON 0xaf /* Display on */
69 #define LCD_CNTL_PAGE 0xb0 /* Page address */
70 #define LCD_CNTL_HIGHCOL 0x10 /* Upper column address */
71 #define LCD_CNTL_LOWCOL 0x00 /* Lower column address */
73 /* send LCD command */
75 void lcd_write_command(int byte)
77 while (LCD1_CONTROL & LCD1_BUSY_MASK); /* wait for LCD */
78 LCD1_CMD = byte;
81 static int xoffset; /* needed for flip */
83 /*** hardware configuration ***/
85 int lcd_default_contrast(void)
87 return DEFAULT_CONTRAST_SETTING;
90 void lcd_set_contrast(int val)
92 lcd_write_command(LCD_CNTL_CONTRAST);
93 lcd_write_command(val);
96 void lcd_set_invert_display(bool yesno)
98 if (yesno)
99 lcd_write_command(LCD_SET_REVERSE_DISPLAY);
100 else
101 lcd_write_command(LCD_SET_NORMAL_DISPLAY);
104 /* turn the display upside down (call lcd_update() afterwards) */
105 void lcd_set_flip(bool yesno)
107 if (!yesno)
109 /* normal */
110 lcd_write_command(LCD_SET_COM_OUTPUT_SCAN_DIRECTION | 0xc);
111 xoffset = 240 - LCD_WIDTH; /* 240 colums minus the 160 we have */
113 else
115 /* upside-down */
116 lcd_write_command(LCD_SET_COM_OUTPUT_SCAN_DIRECTION);
117 xoffset = 0;
121 /* LCD init */
122 void lcd_init_device(void)
124 int i;
126 DEV_INIT1 &= ~0xfc000000;
128 i = DEV_INIT1;
129 DEV_INIT1 = i;
131 DEV_INIT2 &= ~0x400;
132 udelay(10000);
134 LCD1_CONTROL &= ~0x4;
135 udelay(15);
137 LCD1_CONTROL |= 0x4;
138 udelay(10);
140 LCD1_CONTROL = 0x0094;
142 /* OF just reads these */
143 LCD1_CONTROL;
144 inl(0x70003004);
145 LCD1_CMD;
146 inl(0x7000300c);
148 LCD1_CONTROL |= 0x1;
149 udelay(15000);
151 lcd_write_command(LCD_SOFTWARE_RESET); /* 0xE2 */
152 lcd_write_command(LCD_SET_POWER_CONTROL_REGISTER + 7); /* 0x2F */
153 /* power control register: op-amp=1, regulator=1, booster=1 */
154 lcd_write_command(LCD_SET_INTERNAL_REGULATOR_RESISTOR_RATIO + 6); /* 0x26 */
156 lcd_set_flip(false); /* 0xCC */
158 lcd_write_command(0xe8);
160 lcd_set_contrast(lcd_default_contrast()); /* 0x80, 0x00 */
162 lcd_write_command(LCD_SET_DISPLAY_START_LINE + 0); /* 0x40 */
163 lcd_write_command(LCD_SET_NORMAL_DISPLAY); /* 0xA6 */
165 lcd_write_command(0x88);
167 lcd_write_command(LCD_SET_PAGE_ADDRESS); /* 0xB0 */
168 lcd_write_command(LCD_SET_HIGHER_COLUMN_ADDRESS + 0); /* 0x10 */
169 lcd_write_command(LCD_SET_LOWER_COLUMN_ADDRESS + 0); /* 0x00 */
171 lcd_write_command(LCD_SET_DISPLAY_ON); /* 0xAF */
174 /*** update functions ***/
176 /* Performance function that works with an external buffer
177 note that by and bheight are in 8-pixel units! */
178 void lcd_blit_mono(const unsigned char* data, int x, int by, int width,
179 int bheight, int stride)
181 int cmd1, cmd2;
183 cmd1 = LCD_CNTL_HIGHCOL | (((x + xoffset) >> 4) & 0xf);
184 cmd2 = LCD_CNTL_LOWCOL | ((x + xoffset) & 0xf);
186 /* Copy display bitmap to hardware */
187 while (bheight--)
189 lcd_write_command(LCD_CNTL_PAGE | (by++ & 0xff));
190 lcd_write_command(cmd1);
191 lcd_write_command(cmd2);
193 lcd_write_data(data, width);
195 data += stride;
199 /* Helper function for lcd_grey_phase_blit(). */
200 void lcd_grey_data(unsigned char *values, unsigned char *phases, int count);
202 /* Performance function that works with an external buffer
203 note that by and bheight are in 8-pixel units! */
204 void lcd_blit_grey_phase(unsigned char *values, unsigned char *phases,
205 int x, int by, int width, int bheight, int stride)
207 int cmd1, cmd2;
209 stride <<= 3; /* 8 pixels per block */
210 cmd1 = LCD_CNTL_HIGHCOL | (((x + xoffset) >> 4) & 0xf);
211 cmd2 = LCD_CNTL_LOWCOL | ((x + xoffset) & 0xf);
213 while (bheight--)
215 lcd_write_command(LCD_CNTL_PAGE | (by++ & 0xff));
216 lcd_write_command(cmd1);
217 lcd_write_command(cmd2);
219 lcd_grey_data(values, phases, width);
220 values += stride;
221 phases += stride;
225 /* Update the display.
226 This must be called after all other LCD functions that change the display. */
227 void lcd_update(void) ICODE_ATTR;
228 void lcd_update(void)
230 int y, cmd1, cmd2;
232 cmd1 = LCD_CNTL_HIGHCOL | (((xoffset) >> 4) & 0xf);
233 cmd2 = LCD_CNTL_LOWCOL | ((xoffset) & 0xf);
235 /* Copy display bitmap to hardware */
236 for (y = 0; y < LCD_FBHEIGHT; y++)
238 lcd_write_command (LCD_CNTL_PAGE | (y & 0xf));
239 lcd_write_command(cmd1);
240 lcd_write_command(cmd2);
242 lcd_write_data (FBADDR(0, y), LCD_WIDTH);
246 /* Update a fraction of the display. */
247 void lcd_update_rect(int, int, int, int) ICODE_ATTR;
248 void lcd_update_rect(int x, int y, int width, int height)
250 int ymax, cmd1, cmd2;
252 /* The Y coordinates have to work on even 8 pixel rows */
253 ymax = (y + height - 1) >> 3;
254 y >>= 3;
256 if(x + width > LCD_WIDTH)
257 width = LCD_WIDTH - x;
258 if (width <= 0)
259 return; /* nothing left to do, 0 is harmful to lcd_write_data() */
260 if(ymax >= LCD_FBHEIGHT)
261 ymax = LCD_FBHEIGHT-1;
264 cmd1 = LCD_CNTL_HIGHCOL | (((x + xoffset) >> 4) & 0xf);
265 cmd2 = LCD_CNTL_LOWCOL | ((x + xoffset) & 0xf);
267 /* Copy specified rectange bitmap to hardware */
268 for (; y <= ymax; y++)
270 lcd_write_command(LCD_CNTL_PAGE | (y & 0xf));
271 lcd_write_command(cmd1);
272 lcd_write_command(cmd2);
274 lcd_write_data (FBADDR(x,y), width);