lcd drivers: Convert lcd_[remote_]framebuffer to a pointer
[maemo-rb.git] / firmware / target / arm / pnx0101 / iriver-ifp7xx / lcd-ifp7xx.c
blob1ad604d50c6708a34f84d87289977b5928adf341
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 by Alan Korr
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 "kernel.h"
24 #include "lcd.h"
25 #include "system.h"
27 /*** definitions ***/
29 #define LCD_SET_LOWER_COLUMN_ADDRESS ((char)0x00)
30 #define LCD_SET_HIGHER_COLUMN_ADDRESS ((char)0x10)
31 #define LCD_SET_INTERNAL_REGULATOR_RESISTOR_RATIO ((char)0x20)
32 #define LCD_SET_POWER_CONTROL_REGISTER ((char)0x28)
33 #define LCD_SET_DISPLAY_START_LINE ((char)0x40)
34 #define LCD_SET_CONTRAST_CONTROL_REGISTER ((char)0x81)
35 #define LCD_SET_SEGMENT_REMAP ((char)0xA0)
36 #define LCD_SET_LCD_BIAS ((char)0xA2)
37 #define LCD_SET_ENTIRE_DISPLAY_OFF ((char)0xA4)
38 #define LCD_SET_ENTIRE_DISPLAY_ON ((char)0xA5)
39 #define LCD_SET_NORMAL_DISPLAY ((char)0xA6)
40 #define LCD_SET_REVERSE_DISPLAY ((char)0xA7)
41 #define LCD_SET_MULTIPLEX_RATIO ((char)0xA8)
42 #define LCD_SET_BIAS_TC_OSC ((char)0xA9)
43 #define LCD_SET_1OVER4_BIAS_RATIO ((char)0xAA)
44 #define LCD_SET_INDICATOR_OFF ((char)0xAC)
45 #define LCD_SET_INDICATOR_ON ((char)0xAD)
46 #define LCD_SET_DISPLAY_OFF ((char)0xAE)
47 #define LCD_SET_DISPLAY_ON ((char)0xAF)
48 #define LCD_SET_PAGE_ADDRESS ((char)0xB0)
49 #define LCD_SET_COM_OUTPUT_SCAN_DIRECTION ((char)0xC0)
50 #define LCD_SET_TOTAL_FRAME_PHASES ((char)0xD2)
51 #define LCD_SET_DISPLAY_OFFSET ((char)0xD3)
52 #define LCD_SET_READ_MODIFY_WRITE_MODE ((char)0xE0)
53 #define LCD_SOFTWARE_RESET ((char)0xE2)
54 #define LCD_NOP ((char)0xE3)
55 #define LCD_SET_END_OF_READ_MODIFY_WRITE_MODE ((char)0xEE)
57 /* LCD command codes */
58 #define LCD_CNTL_RESET 0xe2 /* Software reset */
59 #define LCD_CNTL_POWER 0x2f /* Power control */
60 #define LCD_CNTL_CONTRAST 0x81 /* Contrast */
61 #define LCD_CNTL_OUTSCAN 0xc8 /* Output scan direction */
62 #define LCD_CNTL_SEGREMAP 0xa1 /* Segment remap */
63 #define LCD_CNTL_DISPON 0xaf /* Display on */
65 #define LCD_CNTL_PAGE 0xb0 /* Page address */
66 #define LCD_CNTL_HIGHCOL 0x10 /* Upper column address */
67 #define LCD_CNTL_LOWCOL 0x00 /* Lower column address */
69 /*** driver routines ***/
71 void lcd_write_command(int cmd)
73 while ((LCDSTAT & 3) != 3);
74 LCDCMD = cmd;
77 void lcd_write_data( const unsigned char* data, int count )
79 int i;
80 for (i=0; i < count; i++) {
81 while ((LCDSTAT & 3) != 3);
82 LCDDATA = data[i];
86 /*** hardware configuration ***/
88 int lcd_default_contrast(void)
90 return 45;
93 void lcd_set_contrast(int val)
95 lcd_write_command(LCD_CNTL_CONTRAST);
96 lcd_write_command(val);
99 void lcd_set_invert_display(bool yesno)
101 if (yesno)
102 lcd_write_command(LCD_SET_REVERSE_DISPLAY);
103 else
104 lcd_write_command(LCD_SET_NORMAL_DISPLAY);
107 /* turn the display upside down (call lcd_update() afterwards) */
108 void lcd_set_flip(bool yesno)
110 if (yesno)
112 lcd_write_command(LCD_SET_SEGMENT_REMAP);
113 lcd_write_command(LCD_SET_COM_OUTPUT_SCAN_DIRECTION);
115 else
117 lcd_write_command(LCD_SET_SEGMENT_REMAP | 0x01);
118 lcd_write_command(LCD_SET_COM_OUTPUT_SCAN_DIRECTION | 0x08);
122 void lcd_init_device(void)
124 LCDREG10 = 0xf;
125 LCDREG04 = 0x4084;
127 /* inits like the original firmware */
128 lcd_write_command(LCD_SOFTWARE_RESET);
129 lcd_write_command(LCD_SET_INTERNAL_REGULATOR_RESISTOR_RATIO + 4);
130 lcd_write_command(LCD_SET_LCD_BIAS);
131 lcd_write_command(LCD_SET_POWER_CONTROL_REGISTER + 7);
132 /* power control register: op-amp=1, regulator=1, booster=1 */
133 lcd_write_command(LCD_SET_DISPLAY_ON);
134 lcd_write_command(LCD_SET_NORMAL_DISPLAY);
135 lcd_set_flip(false);
136 lcd_write_command(LCD_SET_DISPLAY_START_LINE + 0);
137 lcd_set_contrast(lcd_default_contrast());
138 lcd_write_command(LCD_SET_PAGE_ADDRESS);
139 lcd_write_command(LCD_SET_LOWER_COLUMN_ADDRESS + 0);
140 lcd_write_command(LCD_SET_HIGHER_COLUMN_ADDRESS + 0);
142 lcd_clear_display();
143 lcd_update();
146 /*** Update functions ***/
148 /* Performance function that works with an external buffer
149 note that by and bheight are in 8-pixel units! */
150 void lcd_blit_mono(const unsigned char *data, int x, int by, int width,
151 int bheight, int stride)
153 /* Copy display bitmap to hardware */
154 while (bheight--)
156 lcd_write_command (LCD_CNTL_PAGE | (by++ & 0xf));
157 lcd_write_command (LCD_CNTL_HIGHCOL | (((x+4)>>4) & 0xf));
158 lcd_write_command (LCD_CNTL_LOWCOL | ((x+4) & 0xf));
160 lcd_write_data(data, width);
161 data += stride;
166 /* Performance function that works with an external buffer
167 note that by and bheight are in 8-pixel units! */
168 void lcd_blit_grey_phase(unsigned char *values, unsigned char *phases,
169 int x, int by, int width, int bheight, int stride)
171 (void)values;
172 (void)phases;
173 (void)x;
174 (void)by;
175 (void)width;
176 (void)bheight;
177 (void)stride;
180 /* Update the display.
181 This must be called after all other LCD functions that change the display. */
182 void lcd_update(void) ICODE_ATTR;
183 void lcd_update(void)
185 int y;
187 /* Copy display bitmap to hardware */
188 for (y = 0; y < LCD_FBHEIGHT; y++)
190 lcd_write_command (LCD_CNTL_PAGE | (y & 0xf));
191 lcd_write_command (LCD_CNTL_HIGHCOL);
192 lcd_write_command (LCD_CNTL_LOWCOL | 4);
194 lcd_write_data (FBADDR(0, y), LCD_WIDTH);
198 /* Update a fraction of the display. */
199 void lcd_update_rect(int, int, int, int) ICODE_ATTR;
200 void lcd_update_rect(int x, int y, int width, int height)
202 int ymax;
204 /* The Y coordinates have to work on even 8 pixel rows */
205 ymax = (y + height-1) >> 3;
206 y >>= 3;
208 if(x + width > LCD_WIDTH)
209 width = LCD_WIDTH - x;
210 if (width <= 0)
211 return; /* nothing left to do, 0 is harmful to lcd_write_data() */
212 if(ymax >= LCD_FBHEIGHT)
213 ymax = LCD_FBHEIGHT-1;
215 /* Copy specified rectange bitmap to hardware */
216 for (; y <= ymax; y++)
218 lcd_write_command (LCD_CNTL_PAGE | (y & 0xf));
219 lcd_write_command (LCD_CNTL_HIGHCOL | (((x+4) >> 4) & 0xf));
220 lcd_write_command (LCD_CNTL_LOWCOL | ((x+4) & 0xf));
222 lcd_write_data (FBADDR(x,y), width);