2 * BRIEF MODULE DESCRIPTION
5 * Copyright 2004-2005 AMD
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>
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>
50 #include <asm/mach-au1x00/au1xxx_pm.h>
53 #ifndef CONFIG_FB_AU1200_DEVS
54 #define CONFIG_FB_AU1200_DEVS 4
57 #define DRIVER_NAME "au1200fb"
58 #define DRIVER_DESC "LCD controller driver for AU1200 processors"
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)
67 #define print_dbg(f, arg...) printk(KERN_DEBUG __FILE__ ": " f "\n", ## arg)
69 #define print_dbg(f, arg...) do {} while (0)
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
{
92 unsigned int backcolor
;
93 unsigned int brightness
;
94 unsigned int colorkey
;
96 unsigned int panel_choice
;
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
{
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
;
129 unsigned int colorkey_mode
;
130 unsigned int double_buffer_mode
;
131 unsigned int ram_array_mode
;
138 struct au1200_lcd_iodata_t
{
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
147 #define LCD_CONTROL_DEFAULT_PO LCD_CONTROL_PO_00
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 */
156 unsigned char* fb_mem
; /* FrameBuffer memory map */
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
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
;
194 uint32 mode_winctrl1
; /* winctrl1[FRM,CCO,PO,PIPE] */
195 uint32 mode_winenable
;
199 #if defined(__BIG_ENDIAN)
200 #define LCD_WINCTRL1_PO_16BPP LCD_WINCTRL1_PO_00
202 #define LCD_WINCTRL1_PO_16BPP LCD_WINCTRL1_PO_01
205 extern int board_au1200fb_panel_init (void);
206 extern int board_au1200fb_panel_shutdown (void);
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
;
215 * Default window configurations
217 static struct window_settings windows
[] = {
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
|
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
|
247 /* mode_winenable*/ 0,
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
|
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
|
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
|
281 /* mode_winenable*/ 0,
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
|
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 */
334 uint32 mode_horztiming
;
335 uint32 mode_verttiming
;
336 uint32 mode_clkcontrol
;
340 uint32 mode_fifoctrl
;
341 uint32 mode_toyclksrc
;
342 uint32 mode_backlight
;
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 /********************************************************************/
356 /* List of panels known to work with the AU1200 LCD controller.
357 * To add a new panel, enter the same specifications as the
358 * Generic_TFT one, and MAKE SURE that it doesn't conflicts
359 * with the controller restrictions. Restrictions are:
361 * STN color panels: max_bpp <= 12
362 * STN mono panels: max_bpp <= 4
363 * TFT panels: max_bpp <= 16
367 static struct panel_settings known_lcd_panels
[] =
369 [0] = { /* QVGA 320x240 H:33.3kHz V:110Hz */
370 .name
= "QVGA_320x240",
380 .input
= FB_DISP_RGB
,
382 .mode_screen
= LCD_SCREEN_SX_N(320) |
383 LCD_SCREEN_SY_N(240),
384 .mode_horztiming
= 0x00c4623b,
385 .mode_verttiming
= 0x00502814,
386 .mode_clkcontrol
= 0x00020002, /* /4=24Mhz */
387 .mode_pwmdiv
= 0x00000000,
388 .mode_pwmhi
= 0x00000000,
389 .mode_outmask
= 0x00FFFFFF,
390 .mode_fifoctrl
= 0x2f2f2f2f,
391 .mode_toyclksrc
= 0x00000004, /* AUXPLL directly */
392 .mode_backlight
= 0x00000000,
393 .mode_auxpll
= 8, /* 96MHz AUXPLL */
395 .device_shutdown
= NULL
,
400 [1] = { /* VGA 640x480 H:30.3kHz V:58Hz */
401 .name
= "VGA_640x480",
411 .input
= FB_DISP_RGB
,
413 .mode_screen
= 0x13f9df80,
414 .mode_horztiming
= 0x003c5859,
415 .mode_verttiming
= 0x00741201,
416 .mode_clkcontrol
= 0x00020001, /* /4=24Mhz */
417 .mode_pwmdiv
= 0x00000000,
418 .mode_pwmhi
= 0x00000000,
419 .mode_outmask
= 0x00FFFFFF,
420 .mode_fifoctrl
= 0x2f2f2f2f,
421 .mode_toyclksrc
= 0x00000004, /* AUXPLL directly */
422 .mode_backlight
= 0x00000000,
423 .mode_auxpll
= 8, /* 96MHz AUXPLL */
425 .device_shutdown
= NULL
,
430 [2] = { /* SVGA 800x600 H:46.1kHz V:69Hz */
431 .name
= "SVGA_800x600",
441 .input
= FB_DISP_RGB
,
443 .mode_screen
= 0x18fa5780,
444 .mode_horztiming
= 0x00dc7e77,
445 .mode_verttiming
= 0x00584805,
446 .mode_clkcontrol
= 0x00020000, /* /2=48Mhz */
447 .mode_pwmdiv
= 0x00000000,
448 .mode_pwmhi
= 0x00000000,
449 .mode_outmask
= 0x00FFFFFF,
450 .mode_fifoctrl
= 0x2f2f2f2f,
451 .mode_toyclksrc
= 0x00000004, /* AUXPLL directly */
452 .mode_backlight
= 0x00000000,
453 .mode_auxpll
= 8, /* 96MHz AUXPLL */
455 .device_shutdown
= NULL
,
460 [3] = { /* XVGA 1024x768 H:56.2kHz V:70Hz */
461 .name
= "XVGA_1024x768",
471 .input
= FB_DISP_RGB
,
473 .mode_screen
= 0x1ffaff80,
474 .mode_horztiming
= 0x007d0e57,
475 .mode_verttiming
= 0x00740a01,
476 .mode_clkcontrol
= 0x000A0000, /* /1 */
477 .mode_pwmdiv
= 0x00000000,
478 .mode_pwmhi
= 0x00000000,
479 .mode_outmask
= 0x00FFFFFF,
480 .mode_fifoctrl
= 0x2f2f2f2f,
481 .mode_toyclksrc
= 0x00000004, /* AUXPLL directly */
482 .mode_backlight
= 0x00000000,
483 .mode_auxpll
= 6, /* 72MHz AUXPLL */
485 .device_shutdown
= NULL
,
490 [4] = { /* XVGA XVGA 1280x1024 H:68.5kHz V:65Hz */
491 .name
= "XVGA_1280x1024",
501 .input
= FB_DISP_RGB
,
503 .mode_screen
= 0x27fbff80,
504 .mode_horztiming
= 0x00cdb2c7,
505 .mode_verttiming
= 0x00600002,
506 .mode_clkcontrol
= 0x000A0000, /* /1 */
507 .mode_pwmdiv
= 0x00000000,
508 .mode_pwmhi
= 0x00000000,
509 .mode_outmask
= 0x00FFFFFF,
510 .mode_fifoctrl
= 0x2f2f2f2f,
511 .mode_toyclksrc
= 0x00000004, /* AUXPLL directly */
512 .mode_backlight
= 0x00000000,
513 .mode_auxpll
= 10, /* 120MHz AUXPLL */
515 .device_shutdown
= NULL
,
520 [5] = { /* Samsung 1024x768 TFT */
521 .name
= "Samsung_1024x768_TFT",
531 .input
= FB_DISP_RGB
,
533 .mode_screen
= 0x1ffaff80,
534 .mode_horztiming
= 0x018cc677,
535 .mode_verttiming
= 0x00241217,
536 .mode_clkcontrol
= 0x00000000, /* SCB 0x1 /4=24Mhz */
537 .mode_pwmdiv
= 0x8000063f, /* SCB 0x0 */
538 .mode_pwmhi
= 0x03400000, /* SCB 0x0 */
539 .mode_outmask
= 0x00FFFFFF,
540 .mode_fifoctrl
= 0x2f2f2f2f,
541 .mode_toyclksrc
= 0x00000004, /* AUXPLL directly */
542 .mode_backlight
= 0x00000000,
543 .mode_auxpll
= 8, /* 96MHz AUXPLL */
544 .device_init
= board_au1200fb_panel_init
,
545 .device_shutdown
= board_au1200fb_panel_shutdown
,
550 [6] = { /* Toshiba 640x480 TFT */
551 .name
= "Toshiba_640x480_TFT",
561 .input
= FB_DISP_RGB
,
563 .mode_screen
= LCD_SCREEN_SX_N(640) |
564 LCD_SCREEN_SY_N(480),
565 .mode_horztiming
= LCD_HORZTIMING_HPW_N(96) |
566 LCD_HORZTIMING_HND1_N(13) | LCD_HORZTIMING_HND2_N(51),
567 .mode_verttiming
= LCD_VERTTIMING_VPW_N(2) |
568 LCD_VERTTIMING_VND1_N(11) | LCD_VERTTIMING_VND2_N(32),
569 .mode_clkcontrol
= 0x00000000, /* /4=24Mhz */
570 .mode_pwmdiv
= 0x8000063f,
571 .mode_pwmhi
= 0x03400000,
572 .mode_outmask
= 0x00fcfcfc,
573 .mode_fifoctrl
= 0x2f2f2f2f,
574 .mode_toyclksrc
= 0x00000004, /* AUXPLL directly */
575 .mode_backlight
= 0x00000000,
576 .mode_auxpll
= 8, /* 96MHz AUXPLL */
577 .device_init
= board_au1200fb_panel_init
,
578 .device_shutdown
= board_au1200fb_panel_shutdown
,
583 [7] = { /* Sharp 320x240 TFT */
584 .name
= "Sharp_320x240_TFT",
594 .input
= FB_DISP_RGB
,
596 .mode_screen
= LCD_SCREEN_SX_N(320) |
597 LCD_SCREEN_SY_N(240),
598 .mode_horztiming
= LCD_HORZTIMING_HPW_N(60) |
599 LCD_HORZTIMING_HND1_N(13) | LCD_HORZTIMING_HND2_N(2),
600 .mode_verttiming
= LCD_VERTTIMING_VPW_N(2) |
601 LCD_VERTTIMING_VND1_N(2) | LCD_VERTTIMING_VND2_N(5),
602 .mode_clkcontrol
= LCD_CLKCONTROL_PCD_N(7), /*16=6Mhz*/
603 .mode_pwmdiv
= 0x8000063f,
604 .mode_pwmhi
= 0x03400000,
605 .mode_outmask
= 0x00fcfcfc,
606 .mode_fifoctrl
= 0x2f2f2f2f,
607 .mode_toyclksrc
= 0x00000004, /* AUXPLL directly */
608 .mode_backlight
= 0x00000000,
609 .mode_auxpll
= 8, /* 96MHz AUXPLL */
610 .device_init
= board_au1200fb_panel_init
,
611 .device_shutdown
= board_au1200fb_panel_shutdown
,
616 [8] = { /* Toppoly TD070WGCB2 7" 856x480 TFT */
617 .name
= "Toppoly_TD070WGCB2",
627 .input
= FB_DISP_RGB
,
629 .mode_screen
= LCD_SCREEN_SX_N(856) |
630 LCD_SCREEN_SY_N(480),
631 .mode_horztiming
= LCD_HORZTIMING_HND2_N(43) |
632 LCD_HORZTIMING_HND1_N(43) | LCD_HORZTIMING_HPW_N(114),
633 .mode_verttiming
= LCD_VERTTIMING_VND2_N(20) |
634 LCD_VERTTIMING_VND1_N(21) | LCD_VERTTIMING_VPW_N(4),
635 .mode_clkcontrol
= 0x00020001, /* /4=24Mhz */
636 .mode_pwmdiv
= 0x8000063f,
637 .mode_pwmhi
= 0x03400000,
638 .mode_outmask
= 0x00fcfcfc,
639 .mode_fifoctrl
= 0x2f2f2f2f,
640 .mode_toyclksrc
= 0x00000004, /* AUXPLL directly */
641 .mode_backlight
= 0x00000000,
642 .mode_auxpll
= 8, /* 96MHz AUXPLL */
643 .device_init
= board_au1200fb_panel_init
,
644 .device_shutdown
= board_au1200fb_panel_shutdown
,
650 #define NUM_PANELS (ARRAY_SIZE(known_lcd_panels))
652 /********************************************************************/
655 static int set_brightness(unsigned int brightness
)
657 unsigned int hi1
, divider
;
659 /* limit brightness pwm duty to >= 30/1600 */
660 if (brightness
< 30) {
663 divider
= (lcd
->pwmdiv
& 0x3FFFF) + 1;
664 hi1
= (lcd
->pwmhi
>> 16) + 1;
665 hi1
= (((brightness
& 0xFF) + 1) * divider
>> 8);
666 lcd
->pwmhi
&= 0xFFFF;
667 lcd
->pwmhi
|= (hi1
<< 16);
671 #endif /* CONFIG_PM */
673 static int winbpp (unsigned int winctrl1
)
677 /* how many bits are needed for each pixel format */
678 switch (winctrl1
& LCD_WINCTRL1_FRM
) {
679 case LCD_WINCTRL1_FRM_1BPP
:
682 case LCD_WINCTRL1_FRM_2BPP
:
685 case LCD_WINCTRL1_FRM_4BPP
:
688 case LCD_WINCTRL1_FRM_8BPP
:
691 case LCD_WINCTRL1_FRM_12BPP
:
692 case LCD_WINCTRL1_FRM_16BPP655
:
693 case LCD_WINCTRL1_FRM_16BPP565
:
694 case LCD_WINCTRL1_FRM_16BPP556
:
695 case LCD_WINCTRL1_FRM_16BPPI1555
:
696 case LCD_WINCTRL1_FRM_16BPPI5551
:
697 case LCD_WINCTRL1_FRM_16BPPA1555
:
698 case LCD_WINCTRL1_FRM_16BPPA5551
:
701 case LCD_WINCTRL1_FRM_24BPP
:
702 case LCD_WINCTRL1_FRM_32BPP
:
710 static int fbinfo2index (struct fb_info
*fb_info
)
714 for (i
= 0; i
< CONFIG_FB_AU1200_DEVS
; ++i
) {
715 if (fb_info
== (struct fb_info
*)(&_au1200fb_devices
[i
].fb_info
))
718 printk("au1200fb: ERROR: fbinfo2index failed!\n");
722 static int au1200_setlocation (struct au1200fb_device
*fbdev
, int plane
,
725 uint32 winctrl0
, winctrl1
, winenable
, fb_offset
= 0;
728 /* FIX!!! NOT CHECKING FOR COMPLETE OFFSCREEN YET */
730 winctrl0
= lcd
->window
[plane
].winctrl0
;
731 winctrl1
= lcd
->window
[plane
].winctrl1
;
732 winctrl0
&= (LCD_WINCTRL0_A
| LCD_WINCTRL0_AEN
);
733 winctrl1
&= ~(LCD_WINCTRL1_SZX
| LCD_WINCTRL1_SZY
);
735 /* Check for off-screen adjustments */
736 xsz
= win
->w
[plane
].xres
;
737 ysz
= win
->w
[plane
].yres
;
738 if ((xpos
+ win
->w
[plane
].xres
) > panel
->Xres
) {
739 /* Off-screen to the right */
740 xsz
= panel
->Xres
- xpos
; /* off by 1 ??? */
741 /*printk("off screen right\n");*/
744 if ((ypos
+ win
->w
[plane
].yres
) > panel
->Yres
) {
745 /* Off-screen to the bottom */
746 ysz
= panel
->Yres
- ypos
; /* off by 1 ??? */
747 /*printk("off screen bottom\n");*/
751 /* Off-screen to the left */
752 xsz
= win
->w
[plane
].xres
+ xpos
;
753 fb_offset
+= (((0 - xpos
) * winbpp(lcd
->window
[plane
].winctrl1
))/8);
755 /*printk("off screen left\n");*/
759 /* Off-screen to the top */
760 ysz
= win
->w
[plane
].yres
+ ypos
;
762 /*printk("off screen top\n");*/
765 /* record settings */
766 win
->w
[plane
].xpos
= xpos
;
767 win
->w
[plane
].ypos
= ypos
;
771 winctrl0
|= (xpos
<< 21);
772 winctrl0
|= (ypos
<< 10);
773 winctrl1
|= (xsz
<< 11);
774 winctrl1
|= (ysz
<< 0);
776 /* Disable the window while making changes, then restore WINEN */
777 winenable
= lcd
->winenable
& (1 << plane
);
779 lcd
->winenable
&= ~(1 << plane
);
780 lcd
->window
[plane
].winctrl0
= winctrl0
;
781 lcd
->window
[plane
].winctrl1
= winctrl1
;
782 lcd
->window
[plane
].winbuf0
=
783 lcd
->window
[plane
].winbuf1
= fbdev
->fb_phys
;
784 lcd
->window
[plane
].winbufctrl
= 0; /* select winbuf0 */
785 lcd
->winenable
|= winenable
;
791 static void au1200_setpanel (struct panel_settings
*newpanel
)
794 * Perform global setup/init of LCD controller
798 /* Make sure all windows disabled */
799 winenable
= lcd
->winenable
;
803 * Ensure everything is disabled before reconfiguring
805 if (lcd
->screen
& LCD_SCREEN_SEN
) {
806 /* Wait for vertical sync period */
807 lcd
->intstatus
= LCD_INT_SS
;
808 while ((lcd
->intstatus
& LCD_INT_SS
) == 0) {
812 lcd
->screen
&= ~LCD_SCREEN_SEN
; /*disable the controller*/
815 lcd
->intstatus
= lcd
->intstatus
; /*clear interrupts*/
817 /*wait for controller to shut down*/
818 } while ((lcd
->intstatus
& LCD_INT_SD
) == 0);
820 /* Call shutdown of current panel (if up) */
821 /* this must occur last, because if an external clock is driving
822 the controller, the clock cannot be turned off before first
823 shutting down the controller.
825 if (panel
->device_shutdown
!= NULL
)
826 panel
->device_shutdown();
829 /* Newpanel == NULL indicates a shutdown operation only */
830 if (newpanel
== NULL
)
835 printk("Panel(%s), %dx%d\n", panel
->name
, panel
->Xres
, panel
->Yres
);
838 * Setup clocking if internal LCD clock source (assumes sys_auxpll valid)
840 if (!(panel
->mode_clkcontrol
& LCD_CLKCONTROL_EXT
))
843 au_writel(panel
->mode_auxpll
, SYS_AUXPLL
);
844 sys_clksrc
= au_readl(SYS_CLKSRC
) & ~0x0000001f;
845 sys_clksrc
|= panel
->mode_toyclksrc
;
846 au_writel(sys_clksrc
, SYS_CLKSRC
);
850 * Configure panel timings
852 lcd
->screen
= panel
->mode_screen
;
853 lcd
->horztiming
= panel
->mode_horztiming
;
854 lcd
->verttiming
= panel
->mode_verttiming
;
855 lcd
->clkcontrol
= panel
->mode_clkcontrol
;
856 lcd
->pwmdiv
= panel
->mode_pwmdiv
;
857 lcd
->pwmhi
= panel
->mode_pwmhi
;
858 lcd
->outmask
= panel
->mode_outmask
;
859 lcd
->fifoctrl
= panel
->mode_fifoctrl
;
862 lcd
->winenable
= winenable
;
865 * Re-enable screen now that it is configured
867 lcd
->screen
|= LCD_SCREEN_SEN
;
870 /* Call init of panel */
871 if (panel
->device_init
!= NULL
) panel
->device_init();
873 /* FIX!!!! not appropriate on panel change!!! Global setup/init */
876 lcd
->backcolor
= win
->mode_backcolor
;
878 /* Setup Color Key - FIX!!! */
879 lcd
->colorkey
= win
->mode_colorkey
;
880 lcd
->colorkeymsk
= win
->mode_colorkeymsk
;
882 /* Setup HWCursor - FIX!!! Need to support this eventually */
883 lcd
->hwc
.cursorctrl
= 0;
884 lcd
->hwc
.cursorpos
= 0;
885 lcd
->hwc
.cursorcolor0
= 0;
886 lcd
->hwc
.cursorcolor1
= 0;
887 lcd
->hwc
.cursorcolor2
= 0;
888 lcd
->hwc
.cursorcolor3
= 0;
893 static void au1200_setmode(struct au1200fb_device
*fbdev
)
895 int plane
= fbdev
->plane
;
896 /* Window/plane setup */
897 lcd
->window
[plane
].winctrl1
= ( 0
898 | LCD_WINCTRL1_PRI_N(plane
)
899 | win
->w
[plane
].mode_winctrl1
/* FRM,CCO,PO,PIPE */
902 au1200_setlocation(fbdev
, plane
, win
->w
[plane
].xpos
, win
->w
[plane
].ypos
);
904 lcd
->window
[plane
].winctrl2
= ( 0
905 | LCD_WINCTRL2_CKMODE_00
907 | LCD_WINCTRL2_BX_N( fbdev
->fb_info
.fix
.line_length
)
911 lcd
->winenable
|= win
->w
[plane
].mode_winenable
;
918 /*#define panel_is_dual(panel) ((panel->mode_screen & LCD_SCREEN_PT) == LCD_SCREEN_PT_010)*/
919 /*#define panel_is_active(panel)((panel->mode_screen & LCD_SCREEN_PT) == LCD_SCREEN_PT_010)*/
921 #define panel_is_color(panel) ((panel->mode_screen & LCD_SCREEN_PT) <= LCD_SCREEN_PT_CDSTN)
923 /* Bitfields format supported by the controller. */
924 static struct fb_bitfield rgb_bitfields
[][4] = {
925 /* Red, Green, Blue, Transp */
926 [LCD_WINCTRL1_FRM_16BPP655
>> 25] =
927 { { 10, 6, 0 }, { 5, 5, 0 }, { 0, 5, 0 }, { 0, 0, 0 } },
929 [LCD_WINCTRL1_FRM_16BPP565
>> 25] =
930 { { 11, 5, 0 }, { 5, 6, 0 }, { 0, 5, 0 }, { 0, 0, 0 } },
932 [LCD_WINCTRL1_FRM_16BPP556
>> 25] =
933 { { 11, 5, 0 }, { 6, 5, 0 }, { 0, 6, 0 }, { 0, 0, 0 } },
935 [LCD_WINCTRL1_FRM_16BPPI1555
>> 25] =
936 { { 10, 5, 0 }, { 5, 5, 0 }, { 0, 5, 0 }, { 0, 0, 0 } },
938 [LCD_WINCTRL1_FRM_16BPPI5551
>> 25] =
939 { { 11, 5, 0 }, { 6, 5, 0 }, { 1, 5, 0 }, { 0, 0, 0 } },
941 [LCD_WINCTRL1_FRM_16BPPA1555
>> 25] =
942 { { 10, 5, 0 }, { 5, 5, 0 }, { 0, 5, 0 }, { 15, 1, 0 } },
944 [LCD_WINCTRL1_FRM_16BPPA5551
>> 25] =
945 { { 11, 5, 0 }, { 6, 5, 0 }, { 1, 5, 0 }, { 0, 1, 0 } },
947 [LCD_WINCTRL1_FRM_24BPP
>> 25] =
948 { { 16, 8, 0 }, { 8, 8, 0 }, { 0, 8, 0 }, { 0, 0, 0 } },
950 [LCD_WINCTRL1_FRM_32BPP
>> 25] =
951 { { 16, 8, 0 }, { 8, 8, 0 }, { 0, 8, 0 }, { 24, 0, 0 } },
954 /*-------------------------------------------------------------------------*/
958 static void au1200fb_update_fbinfo(struct fb_info
*fbi
)
960 /* FIX!!!! This also needs to take the window pixel format into account!!! */
962 /* Update var-dependent FB info */
963 if (panel_is_color(panel
)) {
964 if (fbi
->var
.bits_per_pixel
<= 8) {
966 fbi
->fix
.visual
= FB_VISUAL_PSEUDOCOLOR
;
967 fbi
->fix
.line_length
= fbi
->var
.xres_virtual
/
968 (8/fbi
->var
.bits_per_pixel
);
971 fbi
->fix
.visual
= FB_VISUAL_TRUECOLOR
;
972 fbi
->fix
.line_length
= fbi
->var
.xres_virtual
* (fbi
->var
.bits_per_pixel
/ 8);
975 /* mono FIX!!! mono 8 and 4 bits */
976 fbi
->fix
.visual
= FB_VISUAL_MONO10
;
977 fbi
->fix
.line_length
= fbi
->var
.xres_virtual
/ 8;
980 fbi
->screen_size
= fbi
->fix
.line_length
* fbi
->var
.yres_virtual
;
981 print_dbg("line length: %d\n", fbi
->fix
.line_length
);
982 print_dbg("bits_per_pixel: %d\n", fbi
->var
.bits_per_pixel
);
985 /*-------------------------------------------------------------------------*/
987 /* AU1200 framebuffer driver */
990 * Validate var settings with hardware restrictions and modify it if necessary
992 static int au1200fb_fb_check_var(struct fb_var_screeninfo
*var
,
995 struct au1200fb_device
*fbdev
= (struct au1200fb_device
*)fbi
;
997 int screen_size
, plane
;
999 plane
= fbdev
->plane
;
1001 /* Make sure that the mode respect all LCD controller and
1002 * panel restrictions. */
1003 var
->xres
= win
->w
[plane
].xres
;
1004 var
->yres
= win
->w
[plane
].yres
;
1006 /* No need for virtual resolution support */
1007 var
->xres_virtual
= var
->xres
;
1008 var
->yres_virtual
= var
->yres
;
1010 var
->bits_per_pixel
= winbpp(win
->w
[plane
].mode_winctrl1
);
1012 screen_size
= var
->xres_virtual
* var
->yres_virtual
;
1013 if (var
->bits_per_pixel
> 8) screen_size
*= (var
->bits_per_pixel
/ 8);
1014 else screen_size
/= (8/var
->bits_per_pixel
);
1016 if (fbdev
->fb_len
< screen_size
)
1017 return -EINVAL
; /* Virtual screen is to big, abort */
1019 /* FIX!!!! what are the implicaitons of ignoring this for windows ??? */
1020 /* The max LCD clock is fixed to 48MHz (value of AUX_CLK). The pixel
1021 * clock can only be obtain by dividing this value by an even integer.
1022 * Fallback to a slower pixel clock if necessary. */
1023 pixclock
= max((u32
)(PICOS2KHZ(var
->pixclock
) * 1000), fbi
->monspecs
.dclkmin
);
1024 pixclock
= min(pixclock
, min(fbi
->monspecs
.dclkmax
, (u32
)AU1200_LCD_MAX_CLK
/2));
1026 if (AU1200_LCD_MAX_CLK
% pixclock
) {
1027 int diff
= AU1200_LCD_MAX_CLK
% pixclock
;
1031 var
->pixclock
= KHZ2PICOS(pixclock
/1000);
1032 /* Set bitfield accordingly */
1033 switch (var
->bits_per_pixel
) {
1036 /* 16bpp True color.
1037 * These must be set to MATCH WINCTRL[FORM] */
1039 idx
= (win
->w
[0].mode_winctrl1
& LCD_WINCTRL1_FRM
) >> 25;
1040 var
->red
= rgb_bitfields
[idx
][0];
1041 var
->green
= rgb_bitfields
[idx
][1];
1042 var
->blue
= rgb_bitfields
[idx
][2];
1043 var
->transp
= rgb_bitfields
[idx
][3];
1049 /* 32bpp True color.
1050 * These must be set to MATCH WINCTRL[FORM] */
1052 idx
= (win
->w
[0].mode_winctrl1
& LCD_WINCTRL1_FRM
) >> 25;
1053 var
->red
= rgb_bitfields
[idx
][0];
1054 var
->green
= rgb_bitfields
[idx
][1];
1055 var
->blue
= rgb_bitfields
[idx
][2];
1056 var
->transp
= rgb_bitfields
[idx
][3];
1060 print_dbg("Unsupported depth %dbpp", var
->bits_per_pixel
);
1068 * Set hardware with var settings. This will enable the controller with a
1069 * specific mode, normally validated with the fb_check_var method
1071 static int au1200fb_fb_set_par(struct fb_info
*fbi
)
1073 struct au1200fb_device
*fbdev
= (struct au1200fb_device
*)fbi
;
1075 au1200fb_update_fbinfo(fbi
);
1076 au1200_setmode(fbdev
);
1082 * Set color in LCD palette.
1084 static int au1200fb_fb_setcolreg(unsigned regno
, unsigned red
, unsigned green
,
1085 unsigned blue
, unsigned transp
, struct fb_info
*fbi
)
1087 volatile u32
*palette
= lcd
->palette
;
1090 if (regno
> (AU1200_LCD_NBR_PALETTE_ENTRIES
- 1))
1093 if (fbi
->var
.grayscale
) {
1094 /* Convert color to grayscale */
1095 red
= green
= blue
=
1096 (19595 * red
+ 38470 * green
+ 7471 * blue
) >> 16;
1099 if (fbi
->fix
.visual
== FB_VISUAL_TRUECOLOR
) {
1100 /* Place color in the pseudopalette */
1104 palette
= (u32
*) fbi
->pseudo_palette
;
1106 red
>>= (16 - fbi
->var
.red
.length
);
1107 green
>>= (16 - fbi
->var
.green
.length
);
1108 blue
>>= (16 - fbi
->var
.blue
.length
);
1110 value
= (red
<< fbi
->var
.red
.offset
) |
1111 (green
<< fbi
->var
.green
.offset
)|
1112 (blue
<< fbi
->var
.blue
.offset
);
1115 } else if (1 /*FIX!!! panel_is_active(fbdev->panel)*/) {
1116 /* COLOR TFT PALLETTIZED (use RGB 565) */
1117 value
= (red
& 0xF800)|((green
>> 5) &
1118 0x07E0)|((blue
>> 11) & 0x001F);
1121 } else if (0 /*panel_is_color(fbdev->panel)*/) {
1122 /* COLOR STN MODE */
1126 /* MONOCHROME MODE */
1127 value
= (green
>> 12) & 0x000F;
1131 palette
[regno
] = value
;
1137 * Blank the screen. Depending on the mode, the screen will be
1138 * activated with the backlight color, or desactivated
1140 static int au1200fb_fb_blank(int blank_mode
, struct fb_info
*fbi
)
1142 /* Short-circuit screen blanking */
1146 switch (blank_mode
) {
1148 case FB_BLANK_UNBLANK
:
1149 case FB_BLANK_NORMAL
:
1150 /* printk("turn on panel\n"); */
1151 au1200_setpanel(panel
);
1153 case FB_BLANK_VSYNC_SUSPEND
:
1154 case FB_BLANK_HSYNC_SUSPEND
:
1155 case FB_BLANK_POWERDOWN
:
1156 /* printk("turn off panel\n"); */
1157 au1200_setpanel(NULL
);
1164 /* FB_BLANK_NORMAL is a soft blank */
1165 return (blank_mode
== FB_BLANK_NORMAL
) ? -EINVAL
: 0;
1169 * Map video memory in user space. We don't use the generic fb_mmap
1170 * method mainly to allow the use of the TLB streaming flag (CCA=6)
1172 static int au1200fb_fb_mmap(struct fb_info
*info
, struct vm_area_struct
*vma
)
1176 unsigned long start
=0, off
;
1177 struct au1200fb_device
*fbdev
= (struct au1200fb_device
*) info
;
1180 au1xxx_pm_access(LCD_pm_dev
);
1183 if (vma
->vm_pgoff
> (~0UL >> PAGE_SHIFT
)) {
1187 start
= fbdev
->fb_phys
& PAGE_MASK
;
1188 len
= PAGE_ALIGN((start
& ~PAGE_MASK
) + fbdev
->fb_len
);
1190 off
= vma
->vm_pgoff
<< PAGE_SHIFT
;
1192 if ((vma
->vm_end
- vma
->vm_start
+ off
) > len
) {
1197 vma
->vm_pgoff
= off
>> PAGE_SHIFT
;
1199 vma
->vm_page_prot
= pgprot_noncached(vma
->vm_page_prot
);
1200 pgprot_val(vma
->vm_page_prot
) |= _CACHE_MASK
; /* CCA=7 */
1202 vma
->vm_flags
|= VM_IO
;
1204 return io_remap_pfn_range(vma
, vma
->vm_start
, off
>> PAGE_SHIFT
,
1205 vma
->vm_end
- vma
->vm_start
,
1211 static void set_global(u_int cmd
, struct au1200_lcd_global_regs_t
*pdata
)
1214 unsigned int hi1
, divider
;
1216 /* SCREEN_SIZE: user cannot reset size, must switch panel choice */
1218 if (pdata
->flags
& SCREEN_BACKCOLOR
)
1219 lcd
->backcolor
= pdata
->backcolor
;
1221 if (pdata
->flags
& SCREEN_BRIGHTNESS
) {
1223 // limit brightness pwm duty to >= 30/1600
1224 if (pdata
->brightness
< 30) {
1225 pdata
->brightness
= 30;
1227 divider
= (lcd
->pwmdiv
& 0x3FFFF) + 1;
1228 hi1
= (lcd
->pwmhi
>> 16) + 1;
1229 hi1
= (((pdata
->brightness
& 0xFF)+1) * divider
>> 8);
1230 lcd
->pwmhi
&= 0xFFFF;
1231 lcd
->pwmhi
|= (hi1
<< 16);
1234 if (pdata
->flags
& SCREEN_COLORKEY
)
1235 lcd
->colorkey
= pdata
->colorkey
;
1237 if (pdata
->flags
& SCREEN_MASK
)
1238 lcd
->colorkeymsk
= pdata
->mask
;
1242 static void get_global(u_int cmd
, struct au1200_lcd_global_regs_t
*pdata
)
1244 unsigned int hi1
, divider
;
1246 pdata
->xsize
= ((lcd
->screen
& LCD_SCREEN_SX
) >> 19) + 1;
1247 pdata
->ysize
= ((lcd
->screen
& LCD_SCREEN_SY
) >> 8) + 1;
1249 pdata
->backcolor
= lcd
->backcolor
;
1250 pdata
->colorkey
= lcd
->colorkey
;
1251 pdata
->mask
= lcd
->colorkeymsk
;
1254 hi1
= (lcd
->pwmhi
>> 16) + 1;
1255 divider
= (lcd
->pwmdiv
& 0x3FFFF) + 1;
1256 pdata
->brightness
= ((hi1
<< 8) / divider
) - 1;
1260 static void set_window(unsigned int plane
,
1261 struct au1200_lcd_window_regs_t
*pdata
)
1263 unsigned int val
, bpp
;
1265 /* Window control register 0 */
1266 if (pdata
->flags
& WIN_POSITION
) {
1267 val
= lcd
->window
[plane
].winctrl0
& ~(LCD_WINCTRL0_OX
|
1269 val
|= ((pdata
->xpos
<< 21) & LCD_WINCTRL0_OX
);
1270 val
|= ((pdata
->ypos
<< 10) & LCD_WINCTRL0_OY
);
1271 lcd
->window
[plane
].winctrl0
= val
;
1273 if (pdata
->flags
& WIN_ALPHA_COLOR
) {
1274 val
= lcd
->window
[plane
].winctrl0
& ~(LCD_WINCTRL0_A
);
1275 val
|= ((pdata
->alpha_color
<< 2) & LCD_WINCTRL0_A
);
1276 lcd
->window
[plane
].winctrl0
= val
;
1278 if (pdata
->flags
& WIN_ALPHA_MODE
) {
1279 val
= lcd
->window
[plane
].winctrl0
& ~(LCD_WINCTRL0_AEN
);
1280 val
|= ((pdata
->alpha_mode
<< 1) & LCD_WINCTRL0_AEN
);
1281 lcd
->window
[plane
].winctrl0
= val
;
1284 /* Window control register 1 */
1285 if (pdata
->flags
& WIN_PRIORITY
) {
1286 val
= lcd
->window
[plane
].winctrl1
& ~(LCD_WINCTRL1_PRI
);
1287 val
|= ((pdata
->priority
<< 30) & LCD_WINCTRL1_PRI
);
1288 lcd
->window
[plane
].winctrl1
= val
;
1290 if (pdata
->flags
& WIN_CHANNEL
) {
1291 val
= lcd
->window
[plane
].winctrl1
& ~(LCD_WINCTRL1_PIPE
);
1292 val
|= ((pdata
->channel
<< 29) & LCD_WINCTRL1_PIPE
);
1293 lcd
->window
[plane
].winctrl1
= val
;
1295 if (pdata
->flags
& WIN_BUFFER_FORMAT
) {
1296 val
= lcd
->window
[plane
].winctrl1
& ~(LCD_WINCTRL1_FRM
);
1297 val
|= ((pdata
->buffer_format
<< 25) & LCD_WINCTRL1_FRM
);
1298 lcd
->window
[plane
].winctrl1
= val
;
1300 if (pdata
->flags
& WIN_COLOR_ORDER
) {
1301 val
= lcd
->window
[plane
].winctrl1
& ~(LCD_WINCTRL1_CCO
);
1302 val
|= ((pdata
->color_order
<< 24) & LCD_WINCTRL1_CCO
);
1303 lcd
->window
[plane
].winctrl1
= val
;
1305 if (pdata
->flags
& WIN_PIXEL_ORDER
) {
1306 val
= lcd
->window
[plane
].winctrl1
& ~(LCD_WINCTRL1_PO
);
1307 val
|= ((pdata
->pixel_order
<< 22) & LCD_WINCTRL1_PO
);
1308 lcd
->window
[plane
].winctrl1
= val
;
1310 if (pdata
->flags
& WIN_SIZE
) {
1311 val
= lcd
->window
[plane
].winctrl1
& ~(LCD_WINCTRL1_SZX
|
1313 val
|= (((pdata
->xsize
<< 11) - 1) & LCD_WINCTRL1_SZX
);
1314 val
|= (((pdata
->ysize
) - 1) & LCD_WINCTRL1_SZY
);
1315 lcd
->window
[plane
].winctrl1
= val
;
1316 /* program buffer line width */
1317 bpp
= winbpp(val
) / 8;
1318 val
= lcd
->window
[plane
].winctrl2
& ~(LCD_WINCTRL2_BX
);
1319 val
|= (((pdata
->xsize
* bpp
) << 8) & LCD_WINCTRL2_BX
);
1320 lcd
->window
[plane
].winctrl2
= val
;
1323 /* Window control register 2 */
1324 if (pdata
->flags
& WIN_COLORKEY_MODE
) {
1325 val
= lcd
->window
[plane
].winctrl2
& ~(LCD_WINCTRL2_CKMODE
);
1326 val
|= ((pdata
->colorkey_mode
<< 24) & LCD_WINCTRL2_CKMODE
);
1327 lcd
->window
[plane
].winctrl2
= val
;
1329 if (pdata
->flags
& WIN_DOUBLE_BUFFER_MODE
) {
1330 val
= lcd
->window
[plane
].winctrl2
& ~(LCD_WINCTRL2_DBM
);
1331 val
|= ((pdata
->double_buffer_mode
<< 23) & LCD_WINCTRL2_DBM
);
1332 lcd
->window
[plane
].winctrl2
= val
;
1334 if (pdata
->flags
& WIN_RAM_ARRAY_MODE
) {
1335 val
= lcd
->window
[plane
].winctrl2
& ~(LCD_WINCTRL2_RAM
);
1336 val
|= ((pdata
->ram_array_mode
<< 21) & LCD_WINCTRL2_RAM
);
1337 lcd
->window
[plane
].winctrl2
= val
;
1340 /* Buffer line width programmed with WIN_SIZE */
1342 if (pdata
->flags
& WIN_BUFFER_SCALE
) {
1343 val
= lcd
->window
[plane
].winctrl2
& ~(LCD_WINCTRL2_SCX
|
1345 val
|= ((pdata
->xsize
<< 11) & LCD_WINCTRL2_SCX
);
1346 val
|= ((pdata
->ysize
) & LCD_WINCTRL2_SCY
);
1347 lcd
->window
[plane
].winctrl2
= val
;
1350 if (pdata
->flags
& WIN_ENABLE
) {
1351 val
= lcd
->winenable
;
1353 val
|= (pdata
->enable
& 1) << plane
;
1354 lcd
->winenable
= val
;
1359 static void get_window(unsigned int plane
,
1360 struct au1200_lcd_window_regs_t
*pdata
)
1362 /* Window control register 0 */
1363 pdata
->xpos
= (lcd
->window
[plane
].winctrl0
& LCD_WINCTRL0_OX
) >> 21;
1364 pdata
->ypos
= (lcd
->window
[plane
].winctrl0
& LCD_WINCTRL0_OY
) >> 10;
1365 pdata
->alpha_color
= (lcd
->window
[plane
].winctrl0
& LCD_WINCTRL0_A
) >> 2;
1366 pdata
->alpha_mode
= (lcd
->window
[plane
].winctrl0
& LCD_WINCTRL0_AEN
) >> 1;
1368 /* Window control register 1 */
1369 pdata
->priority
= (lcd
->window
[plane
].winctrl1
& LCD_WINCTRL1_PRI
) >> 30;
1370 pdata
->channel
= (lcd
->window
[plane
].winctrl1
& LCD_WINCTRL1_PIPE
) >> 29;
1371 pdata
->buffer_format
= (lcd
->window
[plane
].winctrl1
& LCD_WINCTRL1_FRM
) >> 25;
1372 pdata
->color_order
= (lcd
->window
[plane
].winctrl1
& LCD_WINCTRL1_CCO
) >> 24;
1373 pdata
->pixel_order
= (lcd
->window
[plane
].winctrl1
& LCD_WINCTRL1_PO
) >> 22;
1374 pdata
->xsize
= ((lcd
->window
[plane
].winctrl1
& LCD_WINCTRL1_SZX
) >> 11) + 1;
1375 pdata
->ysize
= (lcd
->window
[plane
].winctrl1
& LCD_WINCTRL1_SZY
) + 1;
1377 /* Window control register 2 */
1378 pdata
->colorkey_mode
= (lcd
->window
[plane
].winctrl2
& LCD_WINCTRL2_CKMODE
) >> 24;
1379 pdata
->double_buffer_mode
= (lcd
->window
[plane
].winctrl2
& LCD_WINCTRL2_DBM
) >> 23;
1380 pdata
->ram_array_mode
= (lcd
->window
[plane
].winctrl2
& LCD_WINCTRL2_RAM
) >> 21;
1382 pdata
->enable
= (lcd
->winenable
>> plane
) & 1;
1386 static int au1200fb_ioctl(struct fb_info
*info
, unsigned int cmd
,
1393 au1xxx_pm_access(LCD_pm_dev
);
1396 plane
= fbinfo2index(info
);
1397 print_dbg("au1200fb: ioctl %d on plane %d\n", cmd
, plane
);
1399 if (cmd
== AU1200_LCD_FB_IOCTL
) {
1400 struct au1200_lcd_iodata_t iodata
;
1402 if (copy_from_user(&iodata
, (void __user
*) arg
, sizeof(iodata
)))
1405 print_dbg("FB IOCTL called\n");
1407 switch (iodata
.subcmd
) {
1408 case AU1200_LCD_SET_SCREEN
:
1409 print_dbg("AU1200_LCD_SET_SCREEN\n");
1410 set_global(cmd
, &iodata
.global
);
1413 case AU1200_LCD_GET_SCREEN
:
1414 print_dbg("AU1200_LCD_GET_SCREEN\n");
1415 get_global(cmd
, &iodata
.global
);
1418 case AU1200_LCD_SET_WINDOW
:
1419 print_dbg("AU1200_LCD_SET_WINDOW\n");
1420 set_window(plane
, &iodata
.window
);
1423 case AU1200_LCD_GET_WINDOW
:
1424 print_dbg("AU1200_LCD_GET_WINDOW\n");
1425 get_window(plane
, &iodata
.window
);
1428 case AU1200_LCD_SET_PANEL
:
1429 print_dbg("AU1200_LCD_SET_PANEL\n");
1430 if ((iodata
.global
.panel_choice
>= 0) &&
1431 (iodata
.global
.panel_choice
<
1434 struct panel_settings
*newpanel
;
1435 panel_index
= iodata
.global
.panel_choice
;
1436 newpanel
= &known_lcd_panels
[panel_index
];
1437 au1200_setpanel(newpanel
);
1441 case AU1200_LCD_GET_PANEL
:
1442 print_dbg("AU1200_LCD_GET_PANEL\n");
1443 iodata
.global
.panel_choice
= panel_index
;
1450 val
= copy_to_user((void __user
*) arg
, &iodata
, sizeof(iodata
));
1452 print_dbg("error: could not copy %d bytes\n", val
);
1461 static struct fb_ops au1200fb_fb_ops
= {
1462 .owner
= THIS_MODULE
,
1463 .fb_check_var
= au1200fb_fb_check_var
,
1464 .fb_set_par
= au1200fb_fb_set_par
,
1465 .fb_setcolreg
= au1200fb_fb_setcolreg
,
1466 .fb_blank
= au1200fb_fb_blank
,
1467 .fb_fillrect
= cfb_fillrect
,
1468 .fb_copyarea
= cfb_copyarea
,
1469 .fb_imageblit
= cfb_imageblit
,
1471 .fb_ioctl
= au1200fb_ioctl
,
1472 .fb_mmap
= au1200fb_fb_mmap
,
1475 /*-------------------------------------------------------------------------*/
1477 static irqreturn_t
au1200fb_handle_irq(int irq
, void* dev_id
)
1479 /* Nothing to do for now, just clear any pending interrupt */
1480 lcd
->intstatus
= lcd
->intstatus
;
1486 /*-------------------------------------------------------------------------*/
1488 /* AU1200 LCD device probe helpers */
1490 static int au1200fb_init_fbinfo(struct au1200fb_device
*fbdev
)
1492 struct fb_info
*fbi
= &fbdev
->fb_info
;
1495 memset(fbi
, 0, sizeof(struct fb_info
));
1496 fbi
->fbops
= &au1200fb_fb_ops
;
1498 bpp
= winbpp(win
->w
[fbdev
->plane
].mode_winctrl1
);
1500 /* Copy monitor specs from panel data */
1501 memcpy(&fbi
->monspecs
, &panel
->monspecs
, sizeof(struct fb_monspecs
));
1503 /* We first try the user mode passed in argument. If that failed,
1504 * or if no one has been specified, we default to the first mode of the
1505 * panel list. Note that after this call, var data will be set */
1506 if (!fb_find_mode(&fbi
->var
,
1508 NULL
, /* drv_info.opt_mode, */
1509 fbi
->monspecs
.modedb
,
1510 fbi
->monspecs
.modedb_len
,
1511 fbi
->monspecs
.modedb
,
1514 print_err("Cannot find valid mode for panel %s", panel
->name
);
1518 fbi
->pseudo_palette
= kcalloc(16, sizeof(u32
), GFP_KERNEL
);
1519 if (!fbi
->pseudo_palette
) {
1523 if (fb_alloc_cmap(&fbi
->cmap
, AU1200_LCD_NBR_PALETTE_ENTRIES
, 0) < 0) {
1524 print_err("Fail to allocate colormap (%d entries)",
1525 AU1200_LCD_NBR_PALETTE_ENTRIES
);
1526 kfree(fbi
->pseudo_palette
);
1530 strncpy(fbi
->fix
.id
, "AU1200", sizeof(fbi
->fix
.id
));
1531 fbi
->fix
.smem_start
= fbdev
->fb_phys
;
1532 fbi
->fix
.smem_len
= fbdev
->fb_len
;
1533 fbi
->fix
.type
= FB_TYPE_PACKED_PIXELS
;
1534 fbi
->fix
.xpanstep
= 0;
1535 fbi
->fix
.ypanstep
= 0;
1536 fbi
->fix
.mmio_start
= 0;
1537 fbi
->fix
.mmio_len
= 0;
1538 fbi
->fix
.accel
= FB_ACCEL_NONE
;
1540 fbi
->screen_base
= (char __iomem
*) fbdev
->fb_mem
;
1542 au1200fb_update_fbinfo(fbi
);
1547 /*-------------------------------------------------------------------------*/
1549 /* AU1200 LCD controller device driver */
1551 static int au1200fb_drv_probe(struct platform_device
*dev
)
1553 struct au1200fb_device
*fbdev
;
1555 int bpp
, plane
, ret
;
1560 for (plane
= 0; plane
< CONFIG_FB_AU1200_DEVS
; ++plane
) {
1561 bpp
= winbpp(win
->w
[plane
].mode_winctrl1
);
1562 if (win
->w
[plane
].xres
== 0)
1563 win
->w
[plane
].xres
= panel
->Xres
;
1564 if (win
->w
[plane
].yres
== 0)
1565 win
->w
[plane
].yres
= panel
->Yres
;
1567 fbdev
= &_au1200fb_devices
[plane
];
1568 memset(fbdev
, 0, sizeof(struct au1200fb_device
));
1569 fbdev
->plane
= plane
;
1571 /* Allocate the framebuffer to the maximum screen size */
1572 fbdev
->fb_len
= (win
->w
[plane
].xres
* win
->w
[plane
].yres
* bpp
) / 8;
1574 fbdev
->fb_mem
= dma_alloc_noncoherent(&dev
->dev
,
1575 PAGE_ALIGN(fbdev
->fb_len
),
1576 &fbdev
->fb_phys
, GFP_KERNEL
);
1577 if (!fbdev
->fb_mem
) {
1578 print_err("fail to allocate frambuffer (size: %dK))",
1579 fbdev
->fb_len
/ 1024);
1584 * Set page reserved so that mmap will work. This is necessary
1585 * since we'll be remapping normal memory.
1587 for (page
= (unsigned long)fbdev
->fb_phys
;
1588 page
< PAGE_ALIGN((unsigned long)fbdev
->fb_phys
+
1590 page
+= PAGE_SIZE
) {
1591 SetPageReserved(pfn_to_page(page
>> PAGE_SHIFT
)); /* LCD DMA is NOT coherent on Au1200 */
1593 print_dbg("Framebuffer memory map at %p", fbdev
->fb_mem
);
1594 print_dbg("phys=0x%08x, size=%dK", fbdev
->fb_phys
, fbdev
->fb_len
/ 1024);
1597 if ((ret
= au1200fb_init_fbinfo(fbdev
)) < 0)
1600 /* Register new framebuffer */
1601 if ((ret
= register_framebuffer(&fbdev
->fb_info
)) < 0) {
1602 print_err("cannot register new framebuffer");
1606 au1200fb_fb_set_par(&fbdev
->fb_info
);
1608 #if !defined(CONFIG_FRAMEBUFFER_CONSOLE) && defined(CONFIG_LOGO)
1610 if (fb_prepare_logo(&fbdev
->fb_info
, FB_ROTATE_UR
)) {
1611 /* Start display and show logo on boot */
1612 fb_set_cmap(&fbdev
->fb_info
.cmap
,
1615 fb_show_logo(&fbdev
->fb_info
, FB_ROTATE_UR
);
1620 /* Now hook interrupt too */
1621 if ((ret
= request_irq(AU1200_LCD_INT
, au1200fb_handle_irq
,
1622 IRQF_DISABLED
| IRQF_SHARED
, "lcd", (void *)dev
)) < 0) {
1623 print_err("fail to request interrupt line %d (err: %d)",
1624 AU1200_LCD_INT
, ret
);
1631 /* NOTE: This only does the current plane/window that failed; others are still active */
1633 dma_free_noncoherent(dev
, PAGE_ALIGN(fbdev
->fb_len
),
1634 fbdev
->fb_mem
, fbdev
->fb_phys
);
1635 if (fbdev
->fb_info
.cmap
.len
!= 0)
1636 fb_dealloc_cmap(&fbdev
->fb_info
.cmap
);
1637 if (fbdev
->fb_info
.pseudo_palette
)
1638 kfree(fbdev
->fb_info
.pseudo_palette
);
1640 free_irq(AU1200_LCD_INT
, (void*)dev
);
1644 static int au1200fb_drv_remove(struct platform_device
*dev
)
1646 struct au1200fb_device
*fbdev
;
1652 /* Turn off the panel */
1653 au1200_setpanel(NULL
);
1655 for (plane
= 0; plane
< CONFIG_FB_AU1200_DEVS
; ++plane
)
1657 fbdev
= &_au1200fb_devices
[plane
];
1659 /* Clean up all probe data */
1660 unregister_framebuffer(&fbdev
->fb_info
);
1662 dma_free_noncoherent(&dev
->dev
,
1663 PAGE_ALIGN(fbdev
->fb_len
),
1664 fbdev
->fb_mem
, fbdev
->fb_phys
);
1665 if (fbdev
->fb_info
.cmap
.len
!= 0)
1666 fb_dealloc_cmap(&fbdev
->fb_info
.cmap
);
1667 if (fbdev
->fb_info
.pseudo_palette
)
1668 kfree(fbdev
->fb_info
.pseudo_palette
);
1671 free_irq(AU1200_LCD_INT
, (void *)dev
);
1677 static int au1200fb_drv_suspend(struct platform_device
*dev
, u32 state
)
1683 static int au1200fb_drv_resume(struct platform_device
*dev
)
1688 #endif /* CONFIG_PM */
1690 static struct platform_driver au1200fb_driver
= {
1692 .name
= "au1200-lcd",
1693 .owner
= THIS_MODULE
,
1695 .probe
= au1200fb_drv_probe
,
1696 .remove
= au1200fb_drv_remove
,
1698 .suspend
= au1200fb_drv_suspend
,
1699 .resume
= au1200fb_drv_resume
,
1703 /*-------------------------------------------------------------------------*/
1707 static void au1200fb_setup(void)
1709 char* options
= NULL
;
1711 int num_panels
= ARRAY_SIZE(known_lcd_panels
);
1714 fb_get_options(DRIVER_NAME
, &options
);
1717 while ((this_opt
= strsep(&options
,",")) != NULL
) {
1718 /* Panel option - can be panel name,
1719 * "bs" for board-switch, or number/index */
1720 if (!strncmp(this_opt
, "panel:", 6)) {
1725 /* First check for index, which allows
1726 * to short circuit this mess */
1727 li
= simple_strtol(this_opt
, &endptr
, 0);
1728 if (*endptr
== '\0') {
1729 panel_idx
= (int)li
;
1731 else if (strcmp(this_opt
, "bs") == 0) {
1732 extern int board_au1200fb_panel(void);
1733 panel_idx
= board_au1200fb_panel();
1737 for (i
= 0; i
< num_panels
; i
++) {
1738 if (!strcmp(this_opt
, known_lcd_panels
[i
].name
)) {
1744 if ((panel_idx
< 0) || (panel_idx
>= num_panels
)) {
1745 print_warn("Panel %s not supported!", this_opt
);
1748 panel_index
= panel_idx
;
1751 else if (strncmp(this_opt
, "nohwcursor", 10) == 0) {
1755 /* Unsupported option */
1757 print_warn("Unsupported option \"%s\"", this_opt
);
1764 static int au1200fb_pm_callback(au1xxx_power_dev_t
*dev
,
1765 au1xxx_request_t request
, void *data
) {
1768 unsigned int brightness
= 0;
1770 if (request
== AU1XXX_PM_SLEEP
) {
1771 board_au1200fb_panel_shutdown();
1773 else if (request
== AU1XXX_PM_WAKEUP
) {
1774 if(dev
->prev_state
== SLEEP_STATE
)
1777 au1200_setpanel(panel
);
1778 for (plane
= 0; plane
< CONFIG_FB_AU1200_DEVS
; ++plane
) {
1779 struct au1200fb_device
*fbdev
;
1780 fbdev
= &_au1200fb_devices
[plane
];
1781 au1200fb_fb_set_par(&fbdev
->fb_info
);
1785 d
= *((unsigned int*)data
);
1786 if(d
<=10) brightness
= 26;
1787 else if(d
<=20) brightness
= 51;
1788 else if(d
<=30) brightness
= 77;
1789 else if(d
<=40) brightness
= 102;
1790 else if(d
<=50) brightness
= 128;
1791 else if(d
<=60) brightness
= 153;
1792 else if(d
<=70) brightness
= 179;
1793 else if(d
<=80) brightness
= 204;
1794 else if(d
<=90) brightness
= 230;
1795 else brightness
= 255;
1796 set_brightness(brightness
);
1797 } else if (request
== AU1XXX_PM_GETSTATUS
) {
1798 return dev
->cur_state
;
1799 } else if (request
== AU1XXX_PM_ACCESS
) {
1800 if (dev
->cur_state
!= SLEEP_STATE
)
1803 au1200_setpanel(panel
);
1805 } else if (request
== AU1XXX_PM_IDLE
) {
1806 } else if (request
== AU1XXX_PM_CLEANUP
) {
1813 static int __init
au1200fb_init(void)
1815 print_info("" DRIVER_DESC
"");
1817 /* Setup driver with options */
1820 /* Point to the panel selected */
1821 panel
= &known_lcd_panels
[panel_index
];
1822 win
= &windows
[window_index
];
1824 printk(DRIVER_NAME
": Panel %d %s\n", panel_index
, panel
->name
);
1825 printk(DRIVER_NAME
": Win %d %s\n", window_index
, win
->name
);
1827 /* Kickstart the panel, the framebuffers/windows come soon enough */
1828 au1200_setpanel(panel
);
1831 LCD_pm_dev
= new_au1xxx_power_device("LCD", &au1200fb_pm_callback
, NULL
);
1832 if ( LCD_pm_dev
== NULL
)
1833 printk(KERN_INFO
"Unable to create a power management device entry for the au1200fb.\n");
1835 printk(KERN_INFO
"Power management device entry for the au1200fb loaded.\n");
1838 return platform_driver_register(&au1200fb_driver
);
1841 static void __exit
au1200fb_cleanup(void)
1843 platform_driver_unregister(&au1200fb_driver
);
1846 module_init(au1200fb_init
);
1847 module_exit(au1200fb_cleanup
);
1849 MODULE_DESCRIPTION(DRIVER_DESC
);
1850 MODULE_LICENSE("GPL");