libata: fix oops when LPM is used with PMP
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / video / au1200fb.c
blob4ea187d937681ae154eeaef876675dbf9fd5622c
1 /*
2 * BRIEF MODULE DESCRIPTION
3 * Au1200 LCD Driver.
5 * Copyright 2004-2005 AMD
6 * Author: AMD
8 * Based on:
9 * linux/drivers/video/skeletonfb.c -- Skeleton for a frame buffer device
10 * Created 28 Dec 1997 by Geert Uytterhoeven
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version.
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
20 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
24 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 * You should have received a copy of the GNU General Public License along
29 * with this program; if not, write to the Free Software Foundation, Inc.,
30 * 675 Mass Ave, Cambridge, MA 02139, USA.
33 #include <linux/module.h>
34 #include <linux/platform_device.h>
35 #include <linux/kernel.h>
36 #include <linux/errno.h>
37 #include <linux/string.h>
38 #include <linux/mm.h>
39 #include <linux/fb.h>
40 #include <linux/init.h>
41 #include <linux/interrupt.h>
42 #include <linux/ctype.h>
43 #include <linux/dma-mapping.h>
44 #include <linux/slab.h>
46 #include <asm/mach-au1x00/au1000.h>
47 #include "au1200fb.h"
49 #ifdef CONFIG_PM
50 #include <asm/mach-au1x00/au1xxx_pm.h>
51 #endif
53 #ifndef CONFIG_FB_AU1200_DEVS
54 #define CONFIG_FB_AU1200_DEVS 4
55 #endif
57 #define DRIVER_NAME "au1200fb"
58 #define DRIVER_DESC "LCD controller driver for AU1200 processors"
60 #define DEBUG 1
62 #define print_err(f, arg...) printk(KERN_ERR DRIVER_NAME ": " f "\n", ## arg)
63 #define print_warn(f, arg...) printk(KERN_WARNING DRIVER_NAME ": " f "\n", ## arg)
64 #define print_info(f, arg...) printk(KERN_INFO DRIVER_NAME ": " f "\n", ## arg)
66 #if DEBUG
67 #define print_dbg(f, arg...) printk(KERN_DEBUG __FILE__ ": " f "\n", ## arg)
68 #else
69 #define print_dbg(f, arg...) do {} while (0)
70 #endif
73 #define AU1200_LCD_FB_IOCTL 0x46FF
75 #define AU1200_LCD_SET_SCREEN 1
76 #define AU1200_LCD_GET_SCREEN 2
77 #define AU1200_LCD_SET_WINDOW 3
78 #define AU1200_LCD_GET_WINDOW 4
79 #define AU1200_LCD_SET_PANEL 5
80 #define AU1200_LCD_GET_PANEL 6
82 #define SCREEN_SIZE (1<< 1)
83 #define SCREEN_BACKCOLOR (1<< 2)
84 #define SCREEN_BRIGHTNESS (1<< 3)
85 #define SCREEN_COLORKEY (1<< 4)
86 #define SCREEN_MASK (1<< 5)
88 struct au1200_lcd_global_regs_t {
89 unsigned int flags;
90 unsigned int xsize;
91 unsigned int ysize;
92 unsigned int backcolor;
93 unsigned int brightness;
94 unsigned int colorkey;
95 unsigned int mask;
96 unsigned int panel_choice;
97 char panel_desc[80];
101 #define WIN_POSITION (1<< 0)
102 #define WIN_ALPHA_COLOR (1<< 1)
103 #define WIN_ALPHA_MODE (1<< 2)
104 #define WIN_PRIORITY (1<< 3)
105 #define WIN_CHANNEL (1<< 4)
106 #define WIN_BUFFER_FORMAT (1<< 5)
107 #define WIN_COLOR_ORDER (1<< 6)
108 #define WIN_PIXEL_ORDER (1<< 7)
109 #define WIN_SIZE (1<< 8)
110 #define WIN_COLORKEY_MODE (1<< 9)
111 #define WIN_DOUBLE_BUFFER_MODE (1<< 10)
112 #define WIN_RAM_ARRAY_MODE (1<< 11)
113 #define WIN_BUFFER_SCALE (1<< 12)
114 #define WIN_ENABLE (1<< 13)
116 struct au1200_lcd_window_regs_t {
117 unsigned int flags;
118 unsigned int xpos;
119 unsigned int ypos;
120 unsigned int alpha_color;
121 unsigned int alpha_mode;
122 unsigned int priority;
123 unsigned int channel;
124 unsigned int buffer_format;
125 unsigned int color_order;
126 unsigned int pixel_order;
127 unsigned int xsize;
128 unsigned int ysize;
129 unsigned int colorkey_mode;
130 unsigned int double_buffer_mode;
131 unsigned int ram_array_mode;
132 unsigned int xscale;
133 unsigned int yscale;
134 unsigned int enable;
138 struct au1200_lcd_iodata_t {
139 unsigned int subcmd;
140 struct au1200_lcd_global_regs_t global;
141 struct au1200_lcd_window_regs_t window;
144 #if defined(__BIG_ENDIAN)
145 #define LCD_CONTROL_DEFAULT_PO LCD_CONTROL_PO_11
146 #else
147 #define LCD_CONTROL_DEFAULT_PO LCD_CONTROL_PO_00
148 #endif
149 #define LCD_CONTROL_DEFAULT_SBPPF LCD_CONTROL_SBPPF_565
151 /* Private, per-framebuffer management information (independent of the panel itself) */
152 struct au1200fb_device {
153 struct fb_info fb_info; /* FB driver info record */
155 int plane;
156 unsigned char* fb_mem; /* FrameBuffer memory map */
157 unsigned int fb_len;
158 dma_addr_t fb_phys;
161 static struct au1200fb_device _au1200fb_devices[CONFIG_FB_AU1200_DEVS];
162 /********************************************************************/
164 /* LCD controller restrictions */
165 #define AU1200_LCD_MAX_XRES 1280
166 #define AU1200_LCD_MAX_YRES 1024
167 #define AU1200_LCD_MAX_BPP 32
168 #define AU1200_LCD_MAX_CLK 96000000 /* fixme: this needs to go away ? */
169 #define AU1200_LCD_NBR_PALETTE_ENTRIES 256
171 /* Default number of visible screen buffer to allocate */
172 #define AU1200FB_NBR_VIDEO_BUFFERS 1
174 /********************************************************************/
176 static struct au1200_lcd *lcd = (struct au1200_lcd *) AU1200_LCD_ADDR;
177 static int window_index = 2; /* default is zero */
178 static int panel_index = 2; /* default is zero */
179 static struct window_settings *win;
180 static struct panel_settings *panel;
181 static int noblanking = 1;
182 static int nohwcursor = 0;
184 struct window_settings {
185 unsigned char name[64];
186 uint32 mode_backcolor;
187 uint32 mode_colorkey;
188 uint32 mode_colorkeymsk;
189 struct {
190 int xres;
191 int yres;
192 int xpos;
193 int ypos;
194 uint32 mode_winctrl1; /* winctrl1[FRM,CCO,PO,PIPE] */
195 uint32 mode_winenable;
196 } w[4];
199 #if defined(__BIG_ENDIAN)
200 #define LCD_WINCTRL1_PO_16BPP LCD_WINCTRL1_PO_00
201 #else
202 #define LCD_WINCTRL1_PO_16BPP LCD_WINCTRL1_PO_01
203 #endif
205 extern int board_au1200fb_panel_init (void);
206 extern int board_au1200fb_panel_shutdown (void);
208 #ifdef CONFIG_PM
209 int au1200fb_pm_callback(au1xxx_power_dev_t *dev,
210 au1xxx_request_t request, void *data);
211 au1xxx_power_dev_t *LCD_pm_dev;
212 #endif
215 * Default window configurations
217 static struct window_settings windows[] = {
218 { /* Index 0 */
219 "0-FS gfx, 1-video, 2-ovly gfx, 3-ovly gfx",
220 /* mode_backcolor */ 0x006600ff,
221 /* mode_colorkey,msk*/ 0, 0,
224 /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
225 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
226 LCD_WINCTRL1_PO_16BPP,
227 /* mode_winenable*/ LCD_WINENABLE_WEN0,
230 /* xres, yres, xpos, ypos */ 100, 100, 100, 100,
231 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
232 LCD_WINCTRL1_PO_16BPP |
233 LCD_WINCTRL1_PIPE,
234 /* mode_winenable*/ LCD_WINENABLE_WEN1,
237 /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
238 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
239 LCD_WINCTRL1_PO_16BPP,
240 /* mode_winenable*/ 0,
243 /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
244 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
245 LCD_WINCTRL1_PO_16BPP |
246 LCD_WINCTRL1_PIPE,
247 /* mode_winenable*/ 0,
252 { /* Index 1 */
253 "0-FS gfx, 1-video, 2-ovly gfx, 3-ovly gfx",
254 /* mode_backcolor */ 0x006600ff,
255 /* mode_colorkey,msk*/ 0, 0,
258 /* xres, yres, xpos, ypos */ 320, 240, 5, 5,
259 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_24BPP |
260 LCD_WINCTRL1_PO_00,
261 /* mode_winenable*/ LCD_WINENABLE_WEN0,
264 /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
265 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565
266 | LCD_WINCTRL1_PO_16BPP,
267 /* mode_winenable*/ 0,
270 /* xres, yres, xpos, ypos */ 100, 100, 0, 0,
271 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
272 LCD_WINCTRL1_PO_16BPP |
273 LCD_WINCTRL1_PIPE,
274 /* mode_winenable*/ 0/*LCD_WINENABLE_WEN2*/,
277 /* xres, yres, xpos, ypos */ 200, 25, 0, 0,
278 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
279 LCD_WINCTRL1_PO_16BPP |
280 LCD_WINCTRL1_PIPE,
281 /* mode_winenable*/ 0,
285 { /* Index 2 */
286 "0-FS gfx, 1-video, 2-ovly gfx, 3-ovly gfx",
287 /* mode_backcolor */ 0x006600ff,
288 /* mode_colorkey,msk*/ 0, 0,
291 /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
292 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
293 LCD_WINCTRL1_PO_16BPP,
294 /* mode_winenable*/ LCD_WINENABLE_WEN0,
297 /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
298 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
299 LCD_WINCTRL1_PO_16BPP,
300 /* mode_winenable*/ 0,
303 /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
304 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_32BPP |
305 LCD_WINCTRL1_PO_00|LCD_WINCTRL1_PIPE,
306 /* mode_winenable*/ 0/*LCD_WINENABLE_WEN2*/,
309 /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
310 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
311 LCD_WINCTRL1_PO_16BPP |
312 LCD_WINCTRL1_PIPE,
313 /* mode_winenable*/ 0,
317 /* Need VGA 640 @ 24bpp, @ 32bpp */
318 /* Need VGA 800 @ 24bpp, @ 32bpp */
319 /* Need VGA 1024 @ 24bpp, @ 32bpp */
323 * Controller configurations for various panels.
326 struct panel_settings
328 const char name[25]; /* Full name <vendor>_<model> */
330 struct fb_monspecs monspecs; /* FB monitor specs */
332 /* panel timings */
333 uint32 mode_screen;
334 uint32 mode_horztiming;
335 uint32 mode_verttiming;
336 uint32 mode_clkcontrol;
337 uint32 mode_pwmdiv;
338 uint32 mode_pwmhi;
339 uint32 mode_outmask;
340 uint32 mode_fifoctrl;
341 uint32 mode_toyclksrc;
342 uint32 mode_backlight;
343 uint32 mode_auxpll;
344 int (*device_init)(void);
345 int (*device_shutdown)(void);
346 #define Xres min_xres
347 #define Yres min_yres
348 u32 min_xres; /* Minimum horizontal resolution */
349 u32 max_xres; /* Maximum horizontal resolution */
350 u32 min_yres; /* Minimum vertical resolution */
351 u32 max_yres; /* Maximum vertical resolution */
354 /********************************************************************/
355 /* fixme: Maybe a modedb for the CRT ? otherwise panels should be as-is */
357 /* List of panels known to work with the AU1200 LCD controller.
358 * To add a new panel, enter the same specifications as the
359 * Generic_TFT one, and MAKE SURE that it doesn't conflicts
360 * with the controller restrictions. Restrictions are:
362 * STN color panels: max_bpp <= 12
363 * STN mono panels: max_bpp <= 4
364 * TFT panels: max_bpp <= 16
365 * max_xres <= 800
366 * max_yres <= 600
368 static struct panel_settings known_lcd_panels[] =
370 [0] = { /* QVGA 320x240 H:33.3kHz V:110Hz */
371 .name = "QVGA_320x240",
372 .monspecs = {
373 .modedb = NULL,
374 .modedb_len = 0,
375 .hfmin = 30000,
376 .hfmax = 70000,
377 .vfmin = 60,
378 .vfmax = 60,
379 .dclkmin = 6000000,
380 .dclkmax = 28000000,
381 .input = FB_DISP_RGB,
383 .mode_screen = LCD_SCREEN_SX_N(320) |
384 LCD_SCREEN_SY_N(240),
385 .mode_horztiming = 0x00c4623b,
386 .mode_verttiming = 0x00502814,
387 .mode_clkcontrol = 0x00020002, /* /4=24Mhz */
388 .mode_pwmdiv = 0x00000000,
389 .mode_pwmhi = 0x00000000,
390 .mode_outmask = 0x00FFFFFF,
391 .mode_fifoctrl = 0x2f2f2f2f,
392 .mode_toyclksrc = 0x00000004, /* AUXPLL directly */
393 .mode_backlight = 0x00000000,
394 .mode_auxpll = 8, /* 96MHz AUXPLL */
395 .device_init = NULL,
396 .device_shutdown = NULL,
397 320, 320,
398 240, 240,
401 [1] = { /* VGA 640x480 H:30.3kHz V:58Hz */
402 .name = "VGA_640x480",
403 .monspecs = {
404 .modedb = NULL,
405 .modedb_len = 0,
406 .hfmin = 30000,
407 .hfmax = 70000,
408 .vfmin = 60,
409 .vfmax = 60,
410 .dclkmin = 6000000,
411 .dclkmax = 28000000,
412 .input = FB_DISP_RGB,
414 .mode_screen = 0x13f9df80,
415 .mode_horztiming = 0x003c5859,
416 .mode_verttiming = 0x00741201,
417 .mode_clkcontrol = 0x00020001, /* /4=24Mhz */
418 .mode_pwmdiv = 0x00000000,
419 .mode_pwmhi = 0x00000000,
420 .mode_outmask = 0x00FFFFFF,
421 .mode_fifoctrl = 0x2f2f2f2f,
422 .mode_toyclksrc = 0x00000004, /* AUXPLL directly */
423 .mode_backlight = 0x00000000,
424 .mode_auxpll = 8, /* 96MHz AUXPLL */
425 .device_init = NULL,
426 .device_shutdown = NULL,
427 640, 480,
428 640, 480,
431 [2] = { /* SVGA 800x600 H:46.1kHz V:69Hz */
432 .name = "SVGA_800x600",
433 .monspecs = {
434 .modedb = NULL,
435 .modedb_len = 0,
436 .hfmin = 30000,
437 .hfmax = 70000,
438 .vfmin = 60,
439 .vfmax = 60,
440 .dclkmin = 6000000,
441 .dclkmax = 28000000,
442 .input = FB_DISP_RGB,
444 .mode_screen = 0x18fa5780,
445 .mode_horztiming = 0x00dc7e77,
446 .mode_verttiming = 0x00584805,
447 .mode_clkcontrol = 0x00020000, /* /2=48Mhz */
448 .mode_pwmdiv = 0x00000000,
449 .mode_pwmhi = 0x00000000,
450 .mode_outmask = 0x00FFFFFF,
451 .mode_fifoctrl = 0x2f2f2f2f,
452 .mode_toyclksrc = 0x00000004, /* AUXPLL directly */
453 .mode_backlight = 0x00000000,
454 .mode_auxpll = 8, /* 96MHz AUXPLL */
455 .device_init = NULL,
456 .device_shutdown = NULL,
457 800, 800,
458 600, 600,
461 [3] = { /* XVGA 1024x768 H:56.2kHz V:70Hz */
462 .name = "XVGA_1024x768",
463 .monspecs = {
464 .modedb = NULL,
465 .modedb_len = 0,
466 .hfmin = 30000,
467 .hfmax = 70000,
468 .vfmin = 60,
469 .vfmax = 60,
470 .dclkmin = 6000000,
471 .dclkmax = 28000000,
472 .input = FB_DISP_RGB,
474 .mode_screen = 0x1ffaff80,
475 .mode_horztiming = 0x007d0e57,
476 .mode_verttiming = 0x00740a01,
477 .mode_clkcontrol = 0x000A0000, /* /1 */
478 .mode_pwmdiv = 0x00000000,
479 .mode_pwmhi = 0x00000000,
480 .mode_outmask = 0x00FFFFFF,
481 .mode_fifoctrl = 0x2f2f2f2f,
482 .mode_toyclksrc = 0x00000004, /* AUXPLL directly */
483 .mode_backlight = 0x00000000,
484 .mode_auxpll = 6, /* 72MHz AUXPLL */
485 .device_init = NULL,
486 .device_shutdown = NULL,
487 1024, 1024,
488 768, 768,
491 [4] = { /* XVGA XVGA 1280x1024 H:68.5kHz V:65Hz */
492 .name = "XVGA_1280x1024",
493 .monspecs = {
494 .modedb = NULL,
495 .modedb_len = 0,
496 .hfmin = 30000,
497 .hfmax = 70000,
498 .vfmin = 60,
499 .vfmax = 60,
500 .dclkmin = 6000000,
501 .dclkmax = 28000000,
502 .input = FB_DISP_RGB,
504 .mode_screen = 0x27fbff80,
505 .mode_horztiming = 0x00cdb2c7,
506 .mode_verttiming = 0x00600002,
507 .mode_clkcontrol = 0x000A0000, /* /1 */
508 .mode_pwmdiv = 0x00000000,
509 .mode_pwmhi = 0x00000000,
510 .mode_outmask = 0x00FFFFFF,
511 .mode_fifoctrl = 0x2f2f2f2f,
512 .mode_toyclksrc = 0x00000004, /* AUXPLL directly */
513 .mode_backlight = 0x00000000,
514 .mode_auxpll = 10, /* 120MHz AUXPLL */
515 .device_init = NULL,
516 .device_shutdown = NULL,
517 1280, 1280,
518 1024, 1024,
521 [5] = { /* Samsung 1024x768 TFT */
522 .name = "Samsung_1024x768_TFT",
523 .monspecs = {
524 .modedb = NULL,
525 .modedb_len = 0,
526 .hfmin = 30000,
527 .hfmax = 70000,
528 .vfmin = 60,
529 .vfmax = 60,
530 .dclkmin = 6000000,
531 .dclkmax = 28000000,
532 .input = FB_DISP_RGB,
534 .mode_screen = 0x1ffaff80,
535 .mode_horztiming = 0x018cc677,
536 .mode_verttiming = 0x00241217,
537 .mode_clkcontrol = 0x00000000, /* SCB 0x1 /4=24Mhz */
538 .mode_pwmdiv = 0x8000063f, /* SCB 0x0 */
539 .mode_pwmhi = 0x03400000, /* SCB 0x0 */
540 .mode_outmask = 0x00FFFFFF,
541 .mode_fifoctrl = 0x2f2f2f2f,
542 .mode_toyclksrc = 0x00000004, /* AUXPLL directly */
543 .mode_backlight = 0x00000000,
544 .mode_auxpll = 8, /* 96MHz AUXPLL */
545 .device_init = board_au1200fb_panel_init,
546 .device_shutdown = board_au1200fb_panel_shutdown,
547 1024, 1024,
548 768, 768,
551 [6] = { /* Toshiba 640x480 TFT */
552 .name = "Toshiba_640x480_TFT",
553 .monspecs = {
554 .modedb = NULL,
555 .modedb_len = 0,
556 .hfmin = 30000,
557 .hfmax = 70000,
558 .vfmin = 60,
559 .vfmax = 60,
560 .dclkmin = 6000000,
561 .dclkmax = 28000000,
562 .input = FB_DISP_RGB,
564 .mode_screen = LCD_SCREEN_SX_N(640) |
565 LCD_SCREEN_SY_N(480),
566 .mode_horztiming = LCD_HORZTIMING_HPW_N(96) |
567 LCD_HORZTIMING_HND1_N(13) | LCD_HORZTIMING_HND2_N(51),
568 .mode_verttiming = LCD_VERTTIMING_VPW_N(2) |
569 LCD_VERTTIMING_VND1_N(11) | LCD_VERTTIMING_VND2_N(32),
570 .mode_clkcontrol = 0x00000000, /* /4=24Mhz */
571 .mode_pwmdiv = 0x8000063f,
572 .mode_pwmhi = 0x03400000,
573 .mode_outmask = 0x00fcfcfc,
574 .mode_fifoctrl = 0x2f2f2f2f,
575 .mode_toyclksrc = 0x00000004, /* AUXPLL directly */
576 .mode_backlight = 0x00000000,
577 .mode_auxpll = 8, /* 96MHz AUXPLL */
578 .device_init = board_au1200fb_panel_init,
579 .device_shutdown = board_au1200fb_panel_shutdown,
580 640, 480,
581 640, 480,
584 [7] = { /* Sharp 320x240 TFT */
585 .name = "Sharp_320x240_TFT",
586 .monspecs = {
587 .modedb = NULL,
588 .modedb_len = 0,
589 .hfmin = 12500,
590 .hfmax = 20000,
591 .vfmin = 38,
592 .vfmax = 81,
593 .dclkmin = 4500000,
594 .dclkmax = 6800000,
595 .input = FB_DISP_RGB,
597 .mode_screen = LCD_SCREEN_SX_N(320) |
598 LCD_SCREEN_SY_N(240),
599 .mode_horztiming = LCD_HORZTIMING_HPW_N(60) |
600 LCD_HORZTIMING_HND1_N(13) | LCD_HORZTIMING_HND2_N(2),
601 .mode_verttiming = LCD_VERTTIMING_VPW_N(2) |
602 LCD_VERTTIMING_VND1_N(2) | LCD_VERTTIMING_VND2_N(5),
603 .mode_clkcontrol = LCD_CLKCONTROL_PCD_N(7), /*16=6Mhz*/
604 .mode_pwmdiv = 0x8000063f,
605 .mode_pwmhi = 0x03400000,
606 .mode_outmask = 0x00fcfcfc,
607 .mode_fifoctrl = 0x2f2f2f2f,
608 .mode_toyclksrc = 0x00000004, /* AUXPLL directly */
609 .mode_backlight = 0x00000000,
610 .mode_auxpll = 8, /* 96MHz AUXPLL */
611 .device_init = board_au1200fb_panel_init,
612 .device_shutdown = board_au1200fb_panel_shutdown,
613 320, 320,
614 240, 240,
617 [8] = { /* Toppoly TD070WGCB2 7" 856x480 TFT */
618 .name = "Toppoly_TD070WGCB2",
619 .monspecs = {
620 .modedb = NULL,
621 .modedb_len = 0,
622 .hfmin = 30000,
623 .hfmax = 70000,
624 .vfmin = 60,
625 .vfmax = 60,
626 .dclkmin = 6000000,
627 .dclkmax = 28000000,
628 .input = FB_DISP_RGB,
630 .mode_screen = LCD_SCREEN_SX_N(856) |
631 LCD_SCREEN_SY_N(480),
632 .mode_horztiming = LCD_HORZTIMING_HND2_N(43) |
633 LCD_HORZTIMING_HND1_N(43) | LCD_HORZTIMING_HPW_N(114),
634 .mode_verttiming = LCD_VERTTIMING_VND2_N(20) |
635 LCD_VERTTIMING_VND1_N(21) | LCD_VERTTIMING_VPW_N(4),
636 .mode_clkcontrol = 0x00020001, /* /4=24Mhz */
637 .mode_pwmdiv = 0x8000063f,
638 .mode_pwmhi = 0x03400000,
639 .mode_outmask = 0x00fcfcfc,
640 .mode_fifoctrl = 0x2f2f2f2f,
641 .mode_toyclksrc = 0x00000004, /* AUXPLL directly */
642 .mode_backlight = 0x00000000,
643 .mode_auxpll = 8, /* 96MHz AUXPLL */
644 .device_init = board_au1200fb_panel_init,
645 .device_shutdown = board_au1200fb_panel_shutdown,
646 856, 856,
647 480, 480,
651 #define NUM_PANELS (ARRAY_SIZE(known_lcd_panels))
653 /********************************************************************/
655 #ifdef CONFIG_PM
656 static int set_brightness(unsigned int brightness)
658 unsigned int hi1, divider;
660 /* limit brightness pwm duty to >= 30/1600 */
661 if (brightness < 30) {
662 brightness = 30;
664 divider = (lcd->pwmdiv & 0x3FFFF) + 1;
665 hi1 = (lcd->pwmhi >> 16) + 1;
666 hi1 = (((brightness & 0xFF) + 1) * divider >> 8);
667 lcd->pwmhi &= 0xFFFF;
668 lcd->pwmhi |= (hi1 << 16);
670 return brightness;
672 #endif /* CONFIG_PM */
674 static int winbpp (unsigned int winctrl1)
676 int bits = 0;
678 /* how many bits are needed for each pixel format */
679 switch (winctrl1 & LCD_WINCTRL1_FRM) {
680 case LCD_WINCTRL1_FRM_1BPP:
681 bits = 1;
682 break;
683 case LCD_WINCTRL1_FRM_2BPP:
684 bits = 2;
685 break;
686 case LCD_WINCTRL1_FRM_4BPP:
687 bits = 4;
688 break;
689 case LCD_WINCTRL1_FRM_8BPP:
690 bits = 8;
691 break;
692 case LCD_WINCTRL1_FRM_12BPP:
693 case LCD_WINCTRL1_FRM_16BPP655:
694 case LCD_WINCTRL1_FRM_16BPP565:
695 case LCD_WINCTRL1_FRM_16BPP556:
696 case LCD_WINCTRL1_FRM_16BPPI1555:
697 case LCD_WINCTRL1_FRM_16BPPI5551:
698 case LCD_WINCTRL1_FRM_16BPPA1555:
699 case LCD_WINCTRL1_FRM_16BPPA5551:
700 bits = 16;
701 break;
702 case LCD_WINCTRL1_FRM_24BPP:
703 case LCD_WINCTRL1_FRM_32BPP:
704 bits = 32;
705 break;
708 return bits;
711 static int fbinfo2index (struct fb_info *fb_info)
713 int i;
715 for (i = 0; i < CONFIG_FB_AU1200_DEVS; ++i) {
716 if (fb_info == (struct fb_info *)(&_au1200fb_devices[i].fb_info))
717 return i;
719 printk("au1200fb: ERROR: fbinfo2index failed!\n");
720 return -1;
723 static int au1200_setlocation (struct au1200fb_device *fbdev, int plane,
724 int xpos, int ypos)
726 uint32 winctrl0, winctrl1, winenable, fb_offset = 0;
727 int xsz, ysz;
729 /* FIX!!! NOT CHECKING FOR COMPLETE OFFSCREEN YET */
731 winctrl0 = lcd->window[plane].winctrl0;
732 winctrl1 = lcd->window[plane].winctrl1;
733 winctrl0 &= (LCD_WINCTRL0_A | LCD_WINCTRL0_AEN);
734 winctrl1 &= ~(LCD_WINCTRL1_SZX | LCD_WINCTRL1_SZY);
736 /* Check for off-screen adjustments */
737 xsz = win->w[plane].xres;
738 ysz = win->w[plane].yres;
739 if ((xpos + win->w[plane].xres) > panel->Xres) {
740 /* Off-screen to the right */
741 xsz = panel->Xres - xpos; /* off by 1 ??? */
742 /*printk("off screen right\n");*/
745 if ((ypos + win->w[plane].yres) > panel->Yres) {
746 /* Off-screen to the bottom */
747 ysz = panel->Yres - ypos; /* off by 1 ??? */
748 /*printk("off screen bottom\n");*/
751 if (xpos < 0) {
752 /* Off-screen to the left */
753 xsz = win->w[plane].xres + xpos;
754 fb_offset += (((0 - xpos) * winbpp(lcd->window[plane].winctrl1))/8);
755 xpos = 0;
756 /*printk("off screen left\n");*/
759 if (ypos < 0) {
760 /* Off-screen to the top */
761 ysz = win->w[plane].yres + ypos;
762 /* fixme: fb_offset += ((0-ypos)*fb_pars[plane].line_length); */
763 ypos = 0;
764 /*printk("off screen top\n");*/
767 /* record settings */
768 win->w[plane].xpos = xpos;
769 win->w[plane].ypos = ypos;
771 xsz -= 1;
772 ysz -= 1;
773 winctrl0 |= (xpos << 21);
774 winctrl0 |= (ypos << 10);
775 winctrl1 |= (xsz << 11);
776 winctrl1 |= (ysz << 0);
778 /* Disable the window while making changes, then restore WINEN */
779 winenable = lcd->winenable & (1 << plane);
780 au_sync();
781 lcd->winenable &= ~(1 << plane);
782 lcd->window[plane].winctrl0 = winctrl0;
783 lcd->window[plane].winctrl1 = winctrl1;
784 lcd->window[plane].winbuf0 =
785 lcd->window[plane].winbuf1 = fbdev->fb_phys;
786 lcd->window[plane].winbufctrl = 0; /* select winbuf0 */
787 lcd->winenable |= winenable;
788 au_sync();
790 return 0;
793 static void au1200_setpanel (struct panel_settings *newpanel)
796 * Perform global setup/init of LCD controller
798 uint32 winenable;
800 /* Make sure all windows disabled */
801 winenable = lcd->winenable;
802 lcd->winenable = 0;
803 au_sync();
805 * Ensure everything is disabled before reconfiguring
807 if (lcd->screen & LCD_SCREEN_SEN) {
808 /* Wait for vertical sync period */
809 lcd->intstatus = LCD_INT_SS;
810 while ((lcd->intstatus & LCD_INT_SS) == 0) {
811 au_sync();
814 lcd->screen &= ~LCD_SCREEN_SEN; /*disable the controller*/
816 do {
817 lcd->intstatus = lcd->intstatus; /*clear interrupts*/
818 au_sync();
819 /*wait for controller to shut down*/
820 } while ((lcd->intstatus & LCD_INT_SD) == 0);
822 /* Call shutdown of current panel (if up) */
823 /* this must occur last, because if an external clock is driving
824 the controller, the clock cannot be turned off before first
825 shutting down the controller.
827 if (panel->device_shutdown != NULL)
828 panel->device_shutdown();
831 /* Newpanel == NULL indicates a shutdown operation only */
832 if (newpanel == NULL)
833 return;
835 panel = newpanel;
837 printk("Panel(%s), %dx%d\n", panel->name, panel->Xres, panel->Yres);
840 * Setup clocking if internal LCD clock source (assumes sys_auxpll valid)
842 if (!(panel->mode_clkcontrol & LCD_CLKCONTROL_EXT))
844 uint32 sys_clksrc;
845 au_writel(panel->mode_auxpll, SYS_AUXPLL);
846 sys_clksrc = au_readl(SYS_CLKSRC) & ~0x0000001f;
847 sys_clksrc |= panel->mode_toyclksrc;
848 au_writel(sys_clksrc, SYS_CLKSRC);
852 * Configure panel timings
854 lcd->screen = panel->mode_screen;
855 lcd->horztiming = panel->mode_horztiming;
856 lcd->verttiming = panel->mode_verttiming;
857 lcd->clkcontrol = panel->mode_clkcontrol;
858 lcd->pwmdiv = panel->mode_pwmdiv;
859 lcd->pwmhi = panel->mode_pwmhi;
860 lcd->outmask = panel->mode_outmask;
861 lcd->fifoctrl = panel->mode_fifoctrl;
862 au_sync();
864 /* fixme: Check window settings to make sure still valid
865 * for new geometry */
866 #if 0
867 au1200_setlocation(fbdev, 0, win->w[0].xpos, win->w[0].ypos);
868 au1200_setlocation(fbdev, 1, win->w[1].xpos, win->w[1].ypos);
869 au1200_setlocation(fbdev, 2, win->w[2].xpos, win->w[2].ypos);
870 au1200_setlocation(fbdev, 3, win->w[3].xpos, win->w[3].ypos);
871 #endif
872 lcd->winenable = winenable;
875 * Re-enable screen now that it is configured
877 lcd->screen |= LCD_SCREEN_SEN;
878 au_sync();
880 /* Call init of panel */
881 if (panel->device_init != NULL) panel->device_init();
883 /* FIX!!!! not appropriate on panel change!!! Global setup/init */
884 lcd->intenable = 0;
885 lcd->intstatus = ~0;
886 lcd->backcolor = win->mode_backcolor;
888 /* Setup Color Key - FIX!!! */
889 lcd->colorkey = win->mode_colorkey;
890 lcd->colorkeymsk = win->mode_colorkeymsk;
892 /* Setup HWCursor - FIX!!! Need to support this eventually */
893 lcd->hwc.cursorctrl = 0;
894 lcd->hwc.cursorpos = 0;
895 lcd->hwc.cursorcolor0 = 0;
896 lcd->hwc.cursorcolor1 = 0;
897 lcd->hwc.cursorcolor2 = 0;
898 lcd->hwc.cursorcolor3 = 0;
901 #if 0
902 #define D(X) printk("%25s: %08X\n", #X, X)
903 D(lcd->screen);
904 D(lcd->horztiming);
905 D(lcd->verttiming);
906 D(lcd->clkcontrol);
907 D(lcd->pwmdiv);
908 D(lcd->pwmhi);
909 D(lcd->outmask);
910 D(lcd->fifoctrl);
911 D(lcd->window[0].winctrl0);
912 D(lcd->window[0].winctrl1);
913 D(lcd->window[0].winctrl2);
914 D(lcd->window[0].winbuf0);
915 D(lcd->window[0].winbuf1);
916 D(lcd->window[0].winbufctrl);
917 D(lcd->window[1].winctrl0);
918 D(lcd->window[1].winctrl1);
919 D(lcd->window[1].winctrl2);
920 D(lcd->window[1].winbuf0);
921 D(lcd->window[1].winbuf1);
922 D(lcd->window[1].winbufctrl);
923 D(lcd->window[2].winctrl0);
924 D(lcd->window[2].winctrl1);
925 D(lcd->window[2].winctrl2);
926 D(lcd->window[2].winbuf0);
927 D(lcd->window[2].winbuf1);
928 D(lcd->window[2].winbufctrl);
929 D(lcd->window[3].winctrl0);
930 D(lcd->window[3].winctrl1);
931 D(lcd->window[3].winctrl2);
932 D(lcd->window[3].winbuf0);
933 D(lcd->window[3].winbuf1);
934 D(lcd->window[3].winbufctrl);
935 D(lcd->winenable);
936 D(lcd->intenable);
937 D(lcd->intstatus);
938 D(lcd->backcolor);
939 D(lcd->winenable);
940 D(lcd->colorkey);
941 D(lcd->colorkeymsk);
942 D(lcd->hwc.cursorctrl);
943 D(lcd->hwc.cursorpos);
944 D(lcd->hwc.cursorcolor0);
945 D(lcd->hwc.cursorcolor1);
946 D(lcd->hwc.cursorcolor2);
947 D(lcd->hwc.cursorcolor3);
948 #endif
951 static void au1200_setmode(struct au1200fb_device *fbdev)
953 int plane = fbdev->plane;
954 /* Window/plane setup */
955 lcd->window[plane].winctrl1 = ( 0
956 | LCD_WINCTRL1_PRI_N(plane)
957 | win->w[plane].mode_winctrl1 /* FRM,CCO,PO,PIPE */
960 au1200_setlocation(fbdev, plane, win->w[plane].xpos, win->w[plane].ypos);
962 lcd->window[plane].winctrl2 = ( 0
963 | LCD_WINCTRL2_CKMODE_00
964 | LCD_WINCTRL2_DBM
965 | LCD_WINCTRL2_BX_N( fbdev->fb_info.fix.line_length)
966 | LCD_WINCTRL2_SCX_1
967 | LCD_WINCTRL2_SCY_1
969 lcd->winenable |= win->w[plane].mode_winenable;
970 au_sync();
974 /* Inline helpers */
976 /*#define panel_is_dual(panel) ((panel->mode_screen & LCD_SCREEN_PT) == LCD_SCREEN_PT_010)*/
977 /*#define panel_is_active(panel)((panel->mode_screen & LCD_SCREEN_PT) == LCD_SCREEN_PT_010)*/
979 #define panel_is_color(panel) ((panel->mode_screen & LCD_SCREEN_PT) <= LCD_SCREEN_PT_CDSTN)
981 /* Bitfields format supported by the controller. */
982 static struct fb_bitfield rgb_bitfields[][4] = {
983 /* Red, Green, Blue, Transp */
984 [LCD_WINCTRL1_FRM_16BPP655 >> 25] =
985 { { 10, 6, 0 }, { 5, 5, 0 }, { 0, 5, 0 }, { 0, 0, 0 } },
987 [LCD_WINCTRL1_FRM_16BPP565 >> 25] =
988 { { 11, 5, 0 }, { 5, 6, 0 }, { 0, 5, 0 }, { 0, 0, 0 } },
990 [LCD_WINCTRL1_FRM_16BPP556 >> 25] =
991 { { 11, 5, 0 }, { 6, 5, 0 }, { 0, 6, 0 }, { 0, 0, 0 } },
993 [LCD_WINCTRL1_FRM_16BPPI1555 >> 25] =
994 { { 10, 5, 0 }, { 5, 5, 0 }, { 0, 5, 0 }, { 0, 0, 0 } },
996 [LCD_WINCTRL1_FRM_16BPPI5551 >> 25] =
997 { { 11, 5, 0 }, { 6, 5, 0 }, { 1, 5, 0 }, { 0, 0, 0 } },
999 [LCD_WINCTRL1_FRM_16BPPA1555 >> 25] =
1000 { { 10, 5, 0 }, { 5, 5, 0 }, { 0, 5, 0 }, { 15, 1, 0 } },
1002 [LCD_WINCTRL1_FRM_16BPPA5551 >> 25] =
1003 { { 11, 5, 0 }, { 6, 5, 0 }, { 1, 5, 0 }, { 0, 1, 0 } },
1005 [LCD_WINCTRL1_FRM_24BPP >> 25] =
1006 { { 16, 8, 0 }, { 8, 8, 0 }, { 0, 8, 0 }, { 0, 0, 0 } },
1008 [LCD_WINCTRL1_FRM_32BPP >> 25] =
1009 { { 16, 8, 0 }, { 8, 8, 0 }, { 0, 8, 0 }, { 24, 0, 0 } },
1012 /*-------------------------------------------------------------------------*/
1014 /* Helpers */
1016 static void au1200fb_update_fbinfo(struct fb_info *fbi)
1018 /* FIX!!!! This also needs to take the window pixel format into account!!! */
1020 /* Update var-dependent FB info */
1021 if (panel_is_color(panel)) {
1022 if (fbi->var.bits_per_pixel <= 8) {
1023 /* palettized */
1024 fbi->fix.visual = FB_VISUAL_PSEUDOCOLOR;
1025 fbi->fix.line_length = fbi->var.xres_virtual /
1026 (8/fbi->var.bits_per_pixel);
1027 } else {
1028 /* non-palettized */
1029 fbi->fix.visual = FB_VISUAL_TRUECOLOR;
1030 fbi->fix.line_length = fbi->var.xres_virtual * (fbi->var.bits_per_pixel / 8);
1032 } else {
1033 /* mono FIX!!! mono 8 and 4 bits */
1034 fbi->fix.visual = FB_VISUAL_MONO10;
1035 fbi->fix.line_length = fbi->var.xres_virtual / 8;
1038 fbi->screen_size = fbi->fix.line_length * fbi->var.yres_virtual;
1039 print_dbg("line length: %d\n", fbi->fix.line_length);
1040 print_dbg("bits_per_pixel: %d\n", fbi->var.bits_per_pixel);
1043 /*-------------------------------------------------------------------------*/
1045 /* AU1200 framebuffer driver */
1047 /* fb_check_var
1048 * Validate var settings with hardware restrictions and modify it if necessary
1050 static int au1200fb_fb_check_var(struct fb_var_screeninfo *var,
1051 struct fb_info *fbi)
1053 struct au1200fb_device *fbdev = (struct au1200fb_device *)fbi;
1054 u32 pixclock;
1055 int screen_size, plane;
1057 plane = fbdev->plane;
1059 /* Make sure that the mode respect all LCD controller and
1060 * panel restrictions. */
1061 var->xres = win->w[plane].xres;
1062 var->yres = win->w[plane].yres;
1064 /* No need for virtual resolution support */
1065 var->xres_virtual = var->xres;
1066 var->yres_virtual = var->yres;
1068 var->bits_per_pixel = winbpp(win->w[plane].mode_winctrl1);
1070 screen_size = var->xres_virtual * var->yres_virtual;
1071 if (var->bits_per_pixel > 8) screen_size *= (var->bits_per_pixel / 8);
1072 else screen_size /= (8/var->bits_per_pixel);
1074 if (fbdev->fb_len < screen_size)
1075 return -EINVAL; /* Virtual screen is to big, abort */
1077 /* FIX!!!! what are the implicaitons of ignoring this for windows ??? */
1078 /* The max LCD clock is fixed to 48MHz (value of AUX_CLK). The pixel
1079 * clock can only be obtain by dividing this value by an even integer.
1080 * Fallback to a slower pixel clock if necessary. */
1081 pixclock = max((u32)(PICOS2KHZ(var->pixclock) * 1000), fbi->monspecs.dclkmin);
1082 pixclock = min3(pixclock, fbi->monspecs.dclkmax, (u32)AU1200_LCD_MAX_CLK/2);
1084 if (AU1200_LCD_MAX_CLK % pixclock) {
1085 int diff = AU1200_LCD_MAX_CLK % pixclock;
1086 pixclock -= diff;
1089 var->pixclock = KHZ2PICOS(pixclock/1000);
1090 #if 0
1091 if (!panel_is_active(panel)) {
1092 int pcd = AU1200_LCD_MAX_CLK / (pixclock * 2) - 1;
1094 if (!panel_is_color(panel)
1095 && (panel->control_base & LCD_CONTROL_MPI) && (pcd < 3)) {
1096 /* STN 8bit mono panel support is up to 6MHz pixclock */
1097 var->pixclock = KHZ2PICOS(6000);
1098 } else if (!pcd) {
1099 /* Other STN panel support is up to 12MHz */
1100 var->pixclock = KHZ2PICOS(12000);
1103 #endif
1104 /* Set bitfield accordingly */
1105 switch (var->bits_per_pixel) {
1106 case 16:
1108 /* 16bpp True color.
1109 * These must be set to MATCH WINCTRL[FORM] */
1110 int idx;
1111 idx = (win->w[0].mode_winctrl1 & LCD_WINCTRL1_FRM) >> 25;
1112 var->red = rgb_bitfields[idx][0];
1113 var->green = rgb_bitfields[idx][1];
1114 var->blue = rgb_bitfields[idx][2];
1115 var->transp = rgb_bitfields[idx][3];
1116 break;
1119 case 32:
1121 /* 32bpp True color.
1122 * These must be set to MATCH WINCTRL[FORM] */
1123 int idx;
1124 idx = (win->w[0].mode_winctrl1 & LCD_WINCTRL1_FRM) >> 25;
1125 var->red = rgb_bitfields[idx][0];
1126 var->green = rgb_bitfields[idx][1];
1127 var->blue = rgb_bitfields[idx][2];
1128 var->transp = rgb_bitfields[idx][3];
1129 break;
1131 default:
1132 print_dbg("Unsupported depth %dbpp", var->bits_per_pixel);
1133 return -EINVAL;
1136 return 0;
1139 /* fb_set_par
1140 * Set hardware with var settings. This will enable the controller with a
1141 * specific mode, normally validated with the fb_check_var method
1143 static int au1200fb_fb_set_par(struct fb_info *fbi)
1145 struct au1200fb_device *fbdev = (struct au1200fb_device *)fbi;
1147 au1200fb_update_fbinfo(fbi);
1148 au1200_setmode(fbdev);
1150 return 0;
1153 /* fb_setcolreg
1154 * Set color in LCD palette.
1156 static int au1200fb_fb_setcolreg(unsigned regno, unsigned red, unsigned green,
1157 unsigned blue, unsigned transp, struct fb_info *fbi)
1159 volatile u32 *palette = lcd->palette;
1160 u32 value;
1162 if (regno > (AU1200_LCD_NBR_PALETTE_ENTRIES - 1))
1163 return -EINVAL;
1165 if (fbi->var.grayscale) {
1166 /* Convert color to grayscale */
1167 red = green = blue =
1168 (19595 * red + 38470 * green + 7471 * blue) >> 16;
1171 if (fbi->fix.visual == FB_VISUAL_TRUECOLOR) {
1172 /* Place color in the pseudopalette */
1173 if (regno > 16)
1174 return -EINVAL;
1176 palette = (u32*) fbi->pseudo_palette;
1178 red >>= (16 - fbi->var.red.length);
1179 green >>= (16 - fbi->var.green.length);
1180 blue >>= (16 - fbi->var.blue.length);
1182 value = (red << fbi->var.red.offset) |
1183 (green << fbi->var.green.offset)|
1184 (blue << fbi->var.blue.offset);
1185 value &= 0xFFFF;
1187 } else if (1 /*FIX!!! panel_is_active(fbdev->panel)*/) {
1188 /* COLOR TFT PALLETTIZED (use RGB 565) */
1189 value = (red & 0xF800)|((green >> 5) &
1190 0x07E0)|((blue >> 11) & 0x001F);
1191 value &= 0xFFFF;
1193 } else if (0 /*panel_is_color(fbdev->panel)*/) {
1194 /* COLOR STN MODE */
1195 value = 0x1234;
1196 value &= 0xFFF;
1197 } else {
1198 /* MONOCHROME MODE */
1199 value = (green >> 12) & 0x000F;
1200 value &= 0xF;
1203 palette[regno] = value;
1205 return 0;
1208 /* fb_blank
1209 * Blank the screen. Depending on the mode, the screen will be
1210 * activated with the backlight color, or desactivated
1212 static int au1200fb_fb_blank(int blank_mode, struct fb_info *fbi)
1214 /* Short-circuit screen blanking */
1215 if (noblanking)
1216 return 0;
1218 switch (blank_mode) {
1220 case FB_BLANK_UNBLANK:
1221 case FB_BLANK_NORMAL:
1222 /* printk("turn on panel\n"); */
1223 au1200_setpanel(panel);
1224 break;
1225 case FB_BLANK_VSYNC_SUSPEND:
1226 case FB_BLANK_HSYNC_SUSPEND:
1227 case FB_BLANK_POWERDOWN:
1228 /* printk("turn off panel\n"); */
1229 au1200_setpanel(NULL);
1230 break;
1231 default:
1232 break;
1236 /* FB_BLANK_NORMAL is a soft blank */
1237 return (blank_mode == FB_BLANK_NORMAL) ? -EINVAL : 0;
1240 /* fb_mmap
1241 * Map video memory in user space. We don't use the generic fb_mmap
1242 * method mainly to allow the use of the TLB streaming flag (CCA=6)
1244 static int au1200fb_fb_mmap(struct fb_info *info, struct vm_area_struct *vma)
1247 unsigned int len;
1248 unsigned long start=0, off;
1249 struct au1200fb_device *fbdev = (struct au1200fb_device *) info;
1251 #ifdef CONFIG_PM
1252 au1xxx_pm_access(LCD_pm_dev);
1253 #endif
1255 if (vma->vm_pgoff > (~0UL >> PAGE_SHIFT)) {
1256 return -EINVAL;
1259 start = fbdev->fb_phys & PAGE_MASK;
1260 len = PAGE_ALIGN((start & ~PAGE_MASK) + fbdev->fb_len);
1262 off = vma->vm_pgoff << PAGE_SHIFT;
1264 if ((vma->vm_end - vma->vm_start + off) > len) {
1265 return -EINVAL;
1268 off += start;
1269 vma->vm_pgoff = off >> PAGE_SHIFT;
1271 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
1272 pgprot_val(vma->vm_page_prot) |= _CACHE_MASK; /* CCA=7 */
1274 vma->vm_flags |= VM_IO;
1276 return io_remap_pfn_range(vma, vma->vm_start, off >> PAGE_SHIFT,
1277 vma->vm_end - vma->vm_start,
1278 vma->vm_page_prot);
1280 return 0;
1283 static void set_global(u_int cmd, struct au1200_lcd_global_regs_t *pdata)
1286 unsigned int hi1, divider;
1288 /* SCREEN_SIZE: user cannot reset size, must switch panel choice */
1290 if (pdata->flags & SCREEN_BACKCOLOR)
1291 lcd->backcolor = pdata->backcolor;
1293 if (pdata->flags & SCREEN_BRIGHTNESS) {
1295 // limit brightness pwm duty to >= 30/1600
1296 if (pdata->brightness < 30) {
1297 pdata->brightness = 30;
1299 divider = (lcd->pwmdiv & 0x3FFFF) + 1;
1300 hi1 = (lcd->pwmhi >> 16) + 1;
1301 hi1 = (((pdata->brightness & 0xFF)+1) * divider >> 8);
1302 lcd->pwmhi &= 0xFFFF;
1303 lcd->pwmhi |= (hi1 << 16);
1306 if (pdata->flags & SCREEN_COLORKEY)
1307 lcd->colorkey = pdata->colorkey;
1309 if (pdata->flags & SCREEN_MASK)
1310 lcd->colorkeymsk = pdata->mask;
1311 au_sync();
1314 static void get_global(u_int cmd, struct au1200_lcd_global_regs_t *pdata)
1316 unsigned int hi1, divider;
1318 pdata->xsize = ((lcd->screen & LCD_SCREEN_SX) >> 19) + 1;
1319 pdata->ysize = ((lcd->screen & LCD_SCREEN_SY) >> 8) + 1;
1321 pdata->backcolor = lcd->backcolor;
1322 pdata->colorkey = lcd->colorkey;
1323 pdata->mask = lcd->colorkeymsk;
1325 // brightness
1326 hi1 = (lcd->pwmhi >> 16) + 1;
1327 divider = (lcd->pwmdiv & 0x3FFFF) + 1;
1328 pdata->brightness = ((hi1 << 8) / divider) - 1;
1329 au_sync();
1332 static void set_window(unsigned int plane,
1333 struct au1200_lcd_window_regs_t *pdata)
1335 unsigned int val, bpp;
1337 /* Window control register 0 */
1338 if (pdata->flags & WIN_POSITION) {
1339 val = lcd->window[plane].winctrl0 & ~(LCD_WINCTRL0_OX |
1340 LCD_WINCTRL0_OY);
1341 val |= ((pdata->xpos << 21) & LCD_WINCTRL0_OX);
1342 val |= ((pdata->ypos << 10) & LCD_WINCTRL0_OY);
1343 lcd->window[plane].winctrl0 = val;
1345 if (pdata->flags & WIN_ALPHA_COLOR) {
1346 val = lcd->window[plane].winctrl0 & ~(LCD_WINCTRL0_A);
1347 val |= ((pdata->alpha_color << 2) & LCD_WINCTRL0_A);
1348 lcd->window[plane].winctrl0 = val;
1350 if (pdata->flags & WIN_ALPHA_MODE) {
1351 val = lcd->window[plane].winctrl0 & ~(LCD_WINCTRL0_AEN);
1352 val |= ((pdata->alpha_mode << 1) & LCD_WINCTRL0_AEN);
1353 lcd->window[plane].winctrl0 = val;
1356 /* Window control register 1 */
1357 if (pdata->flags & WIN_PRIORITY) {
1358 val = lcd->window[plane].winctrl1 & ~(LCD_WINCTRL1_PRI);
1359 val |= ((pdata->priority << 30) & LCD_WINCTRL1_PRI);
1360 lcd->window[plane].winctrl1 = val;
1362 if (pdata->flags & WIN_CHANNEL) {
1363 val = lcd->window[plane].winctrl1 & ~(LCD_WINCTRL1_PIPE);
1364 val |= ((pdata->channel << 29) & LCD_WINCTRL1_PIPE);
1365 lcd->window[plane].winctrl1 = val;
1367 if (pdata->flags & WIN_BUFFER_FORMAT) {
1368 val = lcd->window[plane].winctrl1 & ~(LCD_WINCTRL1_FRM);
1369 val |= ((pdata->buffer_format << 25) & LCD_WINCTRL1_FRM);
1370 lcd->window[plane].winctrl1 = val;
1372 if (pdata->flags & WIN_COLOR_ORDER) {
1373 val = lcd->window[plane].winctrl1 & ~(LCD_WINCTRL1_CCO);
1374 val |= ((pdata->color_order << 24) & LCD_WINCTRL1_CCO);
1375 lcd->window[plane].winctrl1 = val;
1377 if (pdata->flags & WIN_PIXEL_ORDER) {
1378 val = lcd->window[plane].winctrl1 & ~(LCD_WINCTRL1_PO);
1379 val |= ((pdata->pixel_order << 22) & LCD_WINCTRL1_PO);
1380 lcd->window[plane].winctrl1 = val;
1382 if (pdata->flags & WIN_SIZE) {
1383 val = lcd->window[plane].winctrl1 & ~(LCD_WINCTRL1_SZX |
1384 LCD_WINCTRL1_SZY);
1385 val |= (((pdata->xsize << 11) - 1) & LCD_WINCTRL1_SZX);
1386 val |= (((pdata->ysize) - 1) & LCD_WINCTRL1_SZY);
1387 lcd->window[plane].winctrl1 = val;
1388 /* program buffer line width */
1389 bpp = winbpp(val) / 8;
1390 val = lcd->window[plane].winctrl2 & ~(LCD_WINCTRL2_BX);
1391 val |= (((pdata->xsize * bpp) << 8) & LCD_WINCTRL2_BX);
1392 lcd->window[plane].winctrl2 = val;
1395 /* Window control register 2 */
1396 if (pdata->flags & WIN_COLORKEY_MODE) {
1397 val = lcd->window[plane].winctrl2 & ~(LCD_WINCTRL2_CKMODE);
1398 val |= ((pdata->colorkey_mode << 24) & LCD_WINCTRL2_CKMODE);
1399 lcd->window[plane].winctrl2 = val;
1401 if (pdata->flags & WIN_DOUBLE_BUFFER_MODE) {
1402 val = lcd->window[plane].winctrl2 & ~(LCD_WINCTRL2_DBM);
1403 val |= ((pdata->double_buffer_mode << 23) & LCD_WINCTRL2_DBM);
1404 lcd->window[plane].winctrl2 = val;
1406 if (pdata->flags & WIN_RAM_ARRAY_MODE) {
1407 val = lcd->window[plane].winctrl2 & ~(LCD_WINCTRL2_RAM);
1408 val |= ((pdata->ram_array_mode << 21) & LCD_WINCTRL2_RAM);
1409 lcd->window[plane].winctrl2 = val;
1412 /* Buffer line width programmed with WIN_SIZE */
1414 if (pdata->flags & WIN_BUFFER_SCALE) {
1415 val = lcd->window[plane].winctrl2 & ~(LCD_WINCTRL2_SCX |
1416 LCD_WINCTRL2_SCY);
1417 val |= ((pdata->xsize << 11) & LCD_WINCTRL2_SCX);
1418 val |= ((pdata->ysize) & LCD_WINCTRL2_SCY);
1419 lcd->window[plane].winctrl2 = val;
1422 if (pdata->flags & WIN_ENABLE) {
1423 val = lcd->winenable;
1424 val &= ~(1<<plane);
1425 val |= (pdata->enable & 1) << plane;
1426 lcd->winenable = val;
1428 au_sync();
1431 static void get_window(unsigned int plane,
1432 struct au1200_lcd_window_regs_t *pdata)
1434 /* Window control register 0 */
1435 pdata->xpos = (lcd->window[plane].winctrl0 & LCD_WINCTRL0_OX) >> 21;
1436 pdata->ypos = (lcd->window[plane].winctrl0 & LCD_WINCTRL0_OY) >> 10;
1437 pdata->alpha_color = (lcd->window[plane].winctrl0 & LCD_WINCTRL0_A) >> 2;
1438 pdata->alpha_mode = (lcd->window[plane].winctrl0 & LCD_WINCTRL0_AEN) >> 1;
1440 /* Window control register 1 */
1441 pdata->priority = (lcd->window[plane].winctrl1& LCD_WINCTRL1_PRI) >> 30;
1442 pdata->channel = (lcd->window[plane].winctrl1 & LCD_WINCTRL1_PIPE) >> 29;
1443 pdata->buffer_format = (lcd->window[plane].winctrl1 & LCD_WINCTRL1_FRM) >> 25;
1444 pdata->color_order = (lcd->window[plane].winctrl1 & LCD_WINCTRL1_CCO) >> 24;
1445 pdata->pixel_order = (lcd->window[plane].winctrl1 & LCD_WINCTRL1_PO) >> 22;
1446 pdata->xsize = ((lcd->window[plane].winctrl1 & LCD_WINCTRL1_SZX) >> 11) + 1;
1447 pdata->ysize = (lcd->window[plane].winctrl1 & LCD_WINCTRL1_SZY) + 1;
1449 /* Window control register 2 */
1450 pdata->colorkey_mode = (lcd->window[plane].winctrl2 & LCD_WINCTRL2_CKMODE) >> 24;
1451 pdata->double_buffer_mode = (lcd->window[plane].winctrl2 & LCD_WINCTRL2_DBM) >> 23;
1452 pdata->ram_array_mode = (lcd->window[plane].winctrl2 & LCD_WINCTRL2_RAM) >> 21;
1454 pdata->enable = (lcd->winenable >> plane) & 1;
1455 au_sync();
1458 static int au1200fb_ioctl(struct fb_info *info, unsigned int cmd,
1459 unsigned long arg)
1461 int plane;
1462 int val;
1464 #ifdef CONFIG_PM
1465 au1xxx_pm_access(LCD_pm_dev);
1466 #endif
1468 plane = fbinfo2index(info);
1469 print_dbg("au1200fb: ioctl %d on plane %d\n", cmd, plane);
1471 if (cmd == AU1200_LCD_FB_IOCTL) {
1472 struct au1200_lcd_iodata_t iodata;
1474 if (copy_from_user(&iodata, (void __user *) arg, sizeof(iodata)))
1475 return -EFAULT;
1477 print_dbg("FB IOCTL called\n");
1479 switch (iodata.subcmd) {
1480 case AU1200_LCD_SET_SCREEN:
1481 print_dbg("AU1200_LCD_SET_SCREEN\n");
1482 set_global(cmd, &iodata.global);
1483 break;
1485 case AU1200_LCD_GET_SCREEN:
1486 print_dbg("AU1200_LCD_GET_SCREEN\n");
1487 get_global(cmd, &iodata.global);
1488 break;
1490 case AU1200_LCD_SET_WINDOW:
1491 print_dbg("AU1200_LCD_SET_WINDOW\n");
1492 set_window(plane, &iodata.window);
1493 break;
1495 case AU1200_LCD_GET_WINDOW:
1496 print_dbg("AU1200_LCD_GET_WINDOW\n");
1497 get_window(plane, &iodata.window);
1498 break;
1500 case AU1200_LCD_SET_PANEL:
1501 print_dbg("AU1200_LCD_SET_PANEL\n");
1502 if ((iodata.global.panel_choice >= 0) &&
1503 (iodata.global.panel_choice <
1504 NUM_PANELS))
1506 struct panel_settings *newpanel;
1507 panel_index = iodata.global.panel_choice;
1508 newpanel = &known_lcd_panels[panel_index];
1509 au1200_setpanel(newpanel);
1511 break;
1513 case AU1200_LCD_GET_PANEL:
1514 print_dbg("AU1200_LCD_GET_PANEL\n");
1515 iodata.global.panel_choice = panel_index;
1516 break;
1518 default:
1519 return -EINVAL;
1522 val = copy_to_user((void __user *) arg, &iodata, sizeof(iodata));
1523 if (val) {
1524 print_dbg("error: could not copy %d bytes\n", val);
1525 return -EFAULT;
1529 return 0;
1533 static struct fb_ops au1200fb_fb_ops = {
1534 .owner = THIS_MODULE,
1535 .fb_check_var = au1200fb_fb_check_var,
1536 .fb_set_par = au1200fb_fb_set_par,
1537 .fb_setcolreg = au1200fb_fb_setcolreg,
1538 .fb_blank = au1200fb_fb_blank,
1539 .fb_fillrect = cfb_fillrect,
1540 .fb_copyarea = cfb_copyarea,
1541 .fb_imageblit = cfb_imageblit,
1542 .fb_sync = NULL,
1543 .fb_ioctl = au1200fb_ioctl,
1544 .fb_mmap = au1200fb_fb_mmap,
1547 /*-------------------------------------------------------------------------*/
1549 static irqreturn_t au1200fb_handle_irq(int irq, void* dev_id)
1551 /* Nothing to do for now, just clear any pending interrupt */
1552 lcd->intstatus = lcd->intstatus;
1553 au_sync();
1555 return IRQ_HANDLED;
1558 /*-------------------------------------------------------------------------*/
1560 /* AU1200 LCD device probe helpers */
1562 static int au1200fb_init_fbinfo(struct au1200fb_device *fbdev)
1564 struct fb_info *fbi = &fbdev->fb_info;
1565 int bpp;
1567 memset(fbi, 0, sizeof(struct fb_info));
1568 fbi->fbops = &au1200fb_fb_ops;
1570 bpp = winbpp(win->w[fbdev->plane].mode_winctrl1);
1572 /* Copy monitor specs from panel data */
1573 /* fixme: we're setting up LCD controller windows, so these dont give a
1574 damn as to what the monitor specs are (the panel itself does, but that
1575 isnt done here...so maybe need a generic catchall monitor setting??? */
1576 memcpy(&fbi->monspecs, &panel->monspecs, sizeof(struct fb_monspecs));
1578 /* We first try the user mode passed in argument. If that failed,
1579 * or if no one has been specified, we default to the first mode of the
1580 * panel list. Note that after this call, var data will be set */
1581 if (!fb_find_mode(&fbi->var,
1582 fbi,
1583 NULL, /* drv_info.opt_mode, */
1584 fbi->monspecs.modedb,
1585 fbi->monspecs.modedb_len,
1586 fbi->monspecs.modedb,
1587 bpp)) {
1589 print_err("Cannot find valid mode for panel %s", panel->name);
1590 return -EFAULT;
1593 fbi->pseudo_palette = kcalloc(16, sizeof(u32), GFP_KERNEL);
1594 if (!fbi->pseudo_palette) {
1595 return -ENOMEM;
1598 if (fb_alloc_cmap(&fbi->cmap, AU1200_LCD_NBR_PALETTE_ENTRIES, 0) < 0) {
1599 print_err("Fail to allocate colormap (%d entries)",
1600 AU1200_LCD_NBR_PALETTE_ENTRIES);
1601 kfree(fbi->pseudo_palette);
1602 return -EFAULT;
1605 strncpy(fbi->fix.id, "AU1200", sizeof(fbi->fix.id));
1606 fbi->fix.smem_start = fbdev->fb_phys;
1607 fbi->fix.smem_len = fbdev->fb_len;
1608 fbi->fix.type = FB_TYPE_PACKED_PIXELS;
1609 fbi->fix.xpanstep = 0;
1610 fbi->fix.ypanstep = 0;
1611 fbi->fix.mmio_start = 0;
1612 fbi->fix.mmio_len = 0;
1613 fbi->fix.accel = FB_ACCEL_NONE;
1615 fbi->screen_base = (char __iomem *) fbdev->fb_mem;
1617 au1200fb_update_fbinfo(fbi);
1619 return 0;
1622 /*-------------------------------------------------------------------------*/
1624 /* AU1200 LCD controller device driver */
1626 static int au1200fb_drv_probe(struct platform_device *dev)
1628 struct au1200fb_device *fbdev;
1629 unsigned long page;
1630 int bpp, plane, ret;
1632 if (!dev)
1633 return -EINVAL;
1635 for (plane = 0; plane < CONFIG_FB_AU1200_DEVS; ++plane) {
1636 bpp = winbpp(win->w[plane].mode_winctrl1);
1637 if (win->w[plane].xres == 0)
1638 win->w[plane].xres = panel->Xres;
1639 if (win->w[plane].yres == 0)
1640 win->w[plane].yres = panel->Yres;
1642 fbdev = &_au1200fb_devices[plane];
1643 memset(fbdev, 0, sizeof(struct au1200fb_device));
1644 fbdev->plane = plane;
1646 /* Allocate the framebuffer to the maximum screen size */
1647 fbdev->fb_len = (win->w[plane].xres * win->w[plane].yres * bpp) / 8;
1649 fbdev->fb_mem = dma_alloc_noncoherent(&dev->dev,
1650 PAGE_ALIGN(fbdev->fb_len),
1651 &fbdev->fb_phys, GFP_KERNEL);
1652 if (!fbdev->fb_mem) {
1653 print_err("fail to allocate frambuffer (size: %dK))",
1654 fbdev->fb_len / 1024);
1655 return -ENOMEM;
1659 * Set page reserved so that mmap will work. This is necessary
1660 * since we'll be remapping normal memory.
1662 for (page = (unsigned long)fbdev->fb_phys;
1663 page < PAGE_ALIGN((unsigned long)fbdev->fb_phys +
1664 fbdev->fb_len);
1665 page += PAGE_SIZE) {
1666 SetPageReserved(pfn_to_page(page >> PAGE_SHIFT)); /* LCD DMA is NOT coherent on Au1200 */
1668 print_dbg("Framebuffer memory map at %p", fbdev->fb_mem);
1669 print_dbg("phys=0x%08x, size=%dK", fbdev->fb_phys, fbdev->fb_len / 1024);
1671 /* Init FB data */
1672 if ((ret = au1200fb_init_fbinfo(fbdev)) < 0)
1673 goto failed;
1675 /* Register new framebuffer */
1676 if ((ret = register_framebuffer(&fbdev->fb_info)) < 0) {
1677 print_err("cannot register new framebuffer");
1678 goto failed;
1681 au1200fb_fb_set_par(&fbdev->fb_info);
1683 #if !defined(CONFIG_FRAMEBUFFER_CONSOLE) && defined(CONFIG_LOGO)
1684 if (plane == 0)
1685 if (fb_prepare_logo(&fbdev->fb_info, FB_ROTATE_UR)) {
1686 /* Start display and show logo on boot */
1687 fb_set_cmap(&fbdev->fb_info.cmap,
1688 &fbdev->fb_info);
1690 fb_show_logo(&fbdev->fb_info, FB_ROTATE_UR);
1692 #endif
1695 /* Now hook interrupt too */
1696 if ((ret = request_irq(AU1200_LCD_INT, au1200fb_handle_irq,
1697 IRQF_DISABLED | IRQF_SHARED, "lcd", (void *)dev)) < 0) {
1698 print_err("fail to request interrupt line %d (err: %d)",
1699 AU1200_LCD_INT, ret);
1700 goto failed;
1703 return 0;
1705 failed:
1706 /* NOTE: This only does the current plane/window that failed; others are still active */
1707 if (fbdev->fb_mem)
1708 dma_free_noncoherent(dev, PAGE_ALIGN(fbdev->fb_len),
1709 fbdev->fb_mem, fbdev->fb_phys);
1710 if (fbdev->fb_info.cmap.len != 0)
1711 fb_dealloc_cmap(&fbdev->fb_info.cmap);
1712 if (fbdev->fb_info.pseudo_palette)
1713 kfree(fbdev->fb_info.pseudo_palette);
1714 if (plane == 0)
1715 free_irq(AU1200_LCD_INT, (void*)dev);
1716 return ret;
1719 static int au1200fb_drv_remove(struct platform_device *dev)
1721 struct au1200fb_device *fbdev;
1722 int plane;
1724 if (!dev)
1725 return -ENODEV;
1727 /* Turn off the panel */
1728 au1200_setpanel(NULL);
1730 for (plane = 0; plane < CONFIG_FB_AU1200_DEVS; ++plane)
1732 fbdev = &_au1200fb_devices[plane];
1734 /* Clean up all probe data */
1735 unregister_framebuffer(&fbdev->fb_info);
1736 if (fbdev->fb_mem)
1737 dma_free_noncoherent(&dev->dev,
1738 PAGE_ALIGN(fbdev->fb_len),
1739 fbdev->fb_mem, fbdev->fb_phys);
1740 if (fbdev->fb_info.cmap.len != 0)
1741 fb_dealloc_cmap(&fbdev->fb_info.cmap);
1742 if (fbdev->fb_info.pseudo_palette)
1743 kfree(fbdev->fb_info.pseudo_palette);
1746 free_irq(AU1200_LCD_INT, (void *)dev);
1748 return 0;
1751 #ifdef CONFIG_PM
1752 static int au1200fb_drv_suspend(struct platform_device *dev, u32 state)
1754 /* TODO */
1755 return 0;
1758 static int au1200fb_drv_resume(struct platform_device *dev)
1760 /* TODO */
1761 return 0;
1763 #endif /* CONFIG_PM */
1765 static struct platform_driver au1200fb_driver = {
1766 .driver = {
1767 .name = "au1200-lcd",
1768 .owner = THIS_MODULE,
1770 .probe = au1200fb_drv_probe,
1771 .remove = au1200fb_drv_remove,
1772 #ifdef CONFIG_PM
1773 .suspend = au1200fb_drv_suspend,
1774 .resume = au1200fb_drv_resume,
1775 #endif
1778 /*-------------------------------------------------------------------------*/
1780 /* Kernel driver */
1782 static void au1200fb_setup(void)
1784 char* options = NULL;
1785 char* this_opt;
1786 int num_panels = ARRAY_SIZE(known_lcd_panels);
1787 int panel_idx = -1;
1789 fb_get_options(DRIVER_NAME, &options);
1791 if (options) {
1792 while ((this_opt = strsep(&options,",")) != NULL) {
1793 /* Panel option - can be panel name,
1794 * "bs" for board-switch, or number/index */
1795 if (!strncmp(this_opt, "panel:", 6)) {
1796 int i;
1797 long int li;
1798 char *endptr;
1799 this_opt += 6;
1800 /* First check for index, which allows
1801 * to short circuit this mess */
1802 li = simple_strtol(this_opt, &endptr, 0);
1803 if (*endptr == '\0') {
1804 panel_idx = (int)li;
1806 else if (strcmp(this_opt, "bs") == 0) {
1807 extern int board_au1200fb_panel(void);
1808 panel_idx = board_au1200fb_panel();
1811 else
1812 for (i = 0; i < num_panels; i++) {
1813 if (!strcmp(this_opt, known_lcd_panels[i].name)) {
1814 panel_idx = i;
1815 break;
1819 if ((panel_idx < 0) || (panel_idx >= num_panels)) {
1820 print_warn("Panel %s not supported!", this_opt);
1822 else
1823 panel_index = panel_idx;
1826 else if (strncmp(this_opt, "nohwcursor", 10) == 0) {
1827 nohwcursor = 1;
1830 /* Unsupported option */
1831 else {
1832 print_warn("Unsupported option \"%s\"", this_opt);
1838 #ifdef CONFIG_PM
1839 static int au1200fb_pm_callback(au1xxx_power_dev_t *dev,
1840 au1xxx_request_t request, void *data) {
1841 int retval = -1;
1842 unsigned int d = 0;
1843 unsigned int brightness = 0;
1845 if (request == AU1XXX_PM_SLEEP) {
1846 board_au1200fb_panel_shutdown();
1848 else if (request == AU1XXX_PM_WAKEUP) {
1849 if(dev->prev_state == SLEEP_STATE)
1851 int plane;
1852 au1200_setpanel(panel);
1853 for (plane = 0; plane < CONFIG_FB_AU1200_DEVS; ++plane) {
1854 struct au1200fb_device *fbdev;
1855 fbdev = &_au1200fb_devices[plane];
1856 au1200fb_fb_set_par(&fbdev->fb_info);
1860 d = *((unsigned int*)data);
1861 if(d <=10) brightness = 26;
1862 else if(d<=20) brightness = 51;
1863 else if(d<=30) brightness = 77;
1864 else if(d<=40) brightness = 102;
1865 else if(d<=50) brightness = 128;
1866 else if(d<=60) brightness = 153;
1867 else if(d<=70) brightness = 179;
1868 else if(d<=80) brightness = 204;
1869 else if(d<=90) brightness = 230;
1870 else brightness = 255;
1871 set_brightness(brightness);
1872 } else if (request == AU1XXX_PM_GETSTATUS) {
1873 return dev->cur_state;
1874 } else if (request == AU1XXX_PM_ACCESS) {
1875 if (dev->cur_state != SLEEP_STATE)
1876 return retval;
1877 else {
1878 au1200_setpanel(panel);
1880 } else if (request == AU1XXX_PM_IDLE) {
1881 } else if (request == AU1XXX_PM_CLEANUP) {
1884 return retval;
1886 #endif
1888 static int __init au1200fb_init(void)
1890 print_info("" DRIVER_DESC "");
1892 /* Setup driver with options */
1893 au1200fb_setup();
1895 /* Point to the panel selected */
1896 panel = &known_lcd_panels[panel_index];
1897 win = &windows[window_index];
1899 printk(DRIVER_NAME ": Panel %d %s\n", panel_index, panel->name);
1900 printk(DRIVER_NAME ": Win %d %s\n", window_index, win->name);
1902 /* Kickstart the panel, the framebuffers/windows come soon enough */
1903 au1200_setpanel(panel);
1905 #ifdef CONFIG_PM
1906 LCD_pm_dev = new_au1xxx_power_device("LCD", &au1200fb_pm_callback, NULL);
1907 if ( LCD_pm_dev == NULL)
1908 printk(KERN_INFO "Unable to create a power management device entry for the au1200fb.\n");
1909 else
1910 printk(KERN_INFO "Power management device entry for the au1200fb loaded.\n");
1911 #endif
1913 return platform_driver_register(&au1200fb_driver);
1916 static void __exit au1200fb_cleanup(void)
1918 platform_driver_unregister(&au1200fb_driver);
1921 module_init(au1200fb_init);
1922 module_exit(au1200fb_cleanup);
1924 MODULE_DESCRIPTION(DRIVER_DESC);
1925 MODULE_LICENSE("GPL");