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>
45 #include <asm/mach-au1x00/au1000.h>
49 #include <asm/mach-au1x00/au1xxx_pm.h>
52 #ifndef CONFIG_FB_AU1200_DEVS
53 #define CONFIG_FB_AU1200_DEVS 4
56 #define DRIVER_NAME "au1200fb"
57 #define DRIVER_DESC "LCD controller driver for AU1200 processors"
61 #define print_err(f, arg...) printk(KERN_ERR DRIVER_NAME ": " f "\n", ## arg)
62 #define print_warn(f, arg...) printk(KERN_WARNING DRIVER_NAME ": " f "\n", ## arg)
63 #define print_info(f, arg...) printk(KERN_INFO DRIVER_NAME ": " f "\n", ## arg)
66 #define print_dbg(f, arg...) printk(KERN_DEBUG __FILE__ ": " f "\n", ## arg)
68 #define print_dbg(f, arg...) do {} while (0)
72 #define AU1200_LCD_FB_IOCTL 0x46FF
74 #define AU1200_LCD_SET_SCREEN 1
75 #define AU1200_LCD_GET_SCREEN 2
76 #define AU1200_LCD_SET_WINDOW 3
77 #define AU1200_LCD_GET_WINDOW 4
78 #define AU1200_LCD_SET_PANEL 5
79 #define AU1200_LCD_GET_PANEL 6
81 #define SCREEN_SIZE (1<< 1)
82 #define SCREEN_BACKCOLOR (1<< 2)
83 #define SCREEN_BRIGHTNESS (1<< 3)
84 #define SCREEN_COLORKEY (1<< 4)
85 #define SCREEN_MASK (1<< 5)
87 struct au1200_lcd_global_regs_t
{
91 unsigned int backcolor
;
92 unsigned int brightness
;
93 unsigned int colorkey
;
95 unsigned int panel_choice
;
100 #define WIN_POSITION (1<< 0)
101 #define WIN_ALPHA_COLOR (1<< 1)
102 #define WIN_ALPHA_MODE (1<< 2)
103 #define WIN_PRIORITY (1<< 3)
104 #define WIN_CHANNEL (1<< 4)
105 #define WIN_BUFFER_FORMAT (1<< 5)
106 #define WIN_COLOR_ORDER (1<< 6)
107 #define WIN_PIXEL_ORDER (1<< 7)
108 #define WIN_SIZE (1<< 8)
109 #define WIN_COLORKEY_MODE (1<< 9)
110 #define WIN_DOUBLE_BUFFER_MODE (1<< 10)
111 #define WIN_RAM_ARRAY_MODE (1<< 11)
112 #define WIN_BUFFER_SCALE (1<< 12)
113 #define WIN_ENABLE (1<< 13)
115 struct au1200_lcd_window_regs_t
{
119 unsigned int alpha_color
;
120 unsigned int alpha_mode
;
121 unsigned int priority
;
122 unsigned int channel
;
123 unsigned int buffer_format
;
124 unsigned int color_order
;
125 unsigned int pixel_order
;
128 unsigned int colorkey_mode
;
129 unsigned int double_buffer_mode
;
130 unsigned int ram_array_mode
;
137 struct au1200_lcd_iodata_t
{
139 struct au1200_lcd_global_regs_t global
;
140 struct au1200_lcd_window_regs_t window
;
143 #if defined(__BIG_ENDIAN)
144 #define LCD_CONTROL_DEFAULT_PO LCD_CONTROL_PO_11
146 #define LCD_CONTROL_DEFAULT_PO LCD_CONTROL_PO_00
148 #define LCD_CONTROL_DEFAULT_SBPPF LCD_CONTROL_SBPPF_565
150 /* Private, per-framebuffer management information (independent of the panel itself) */
151 struct au1200fb_device
{
152 struct fb_info fb_info
; /* FB driver info record */
155 unsigned char* fb_mem
; /* FrameBuffer memory map */
160 static struct au1200fb_device _au1200fb_devices
[CONFIG_FB_AU1200_DEVS
];
161 /********************************************************************/
163 /* LCD controller restrictions */
164 #define AU1200_LCD_MAX_XRES 1280
165 #define AU1200_LCD_MAX_YRES 1024
166 #define AU1200_LCD_MAX_BPP 32
167 #define AU1200_LCD_MAX_CLK 96000000 /* fixme: this needs to go away ? */
168 #define AU1200_LCD_NBR_PALETTE_ENTRIES 256
170 /* Default number of visible screen buffer to allocate */
171 #define AU1200FB_NBR_VIDEO_BUFFERS 1
173 /********************************************************************/
175 static struct au1200_lcd
*lcd
= (struct au1200_lcd
*) AU1200_LCD_ADDR
;
176 static int window_index
= 2; /* default is zero */
177 static int panel_index
= 2; /* default is zero */
178 static struct window_settings
*win
;
179 static struct panel_settings
*panel
;
180 static int noblanking
= 1;
181 static int nohwcursor
= 0;
183 struct window_settings
{
184 unsigned char name
[64];
185 uint32 mode_backcolor
;
186 uint32 mode_colorkey
;
187 uint32 mode_colorkeymsk
;
193 uint32 mode_winctrl1
; /* winctrl1[FRM,CCO,PO,PIPE] */
194 uint32 mode_winenable
;
198 #if defined(__BIG_ENDIAN)
199 #define LCD_WINCTRL1_PO_16BPP LCD_WINCTRL1_PO_00
201 #define LCD_WINCTRL1_PO_16BPP LCD_WINCTRL1_PO_01
204 extern int board_au1200fb_panel_init (void);
205 extern int board_au1200fb_panel_shutdown (void);
208 int au1200fb_pm_callback(au1xxx_power_dev_t
*dev
,
209 au1xxx_request_t request
, void *data
);
210 au1xxx_power_dev_t
*LCD_pm_dev
;
214 * Default window configurations
216 static struct window_settings windows
[] = {
218 "0-FS gfx, 1-video, 2-ovly gfx, 3-ovly gfx",
219 /* mode_backcolor */ 0x006600ff,
220 /* mode_colorkey,msk*/ 0, 0,
223 /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
224 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565
|
225 LCD_WINCTRL1_PO_16BPP
,
226 /* mode_winenable*/ LCD_WINENABLE_WEN0
,
229 /* xres, yres, xpos, ypos */ 100, 100, 100, 100,
230 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565
|
231 LCD_WINCTRL1_PO_16BPP
|
233 /* mode_winenable*/ LCD_WINENABLE_WEN1
,
236 /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
237 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565
|
238 LCD_WINCTRL1_PO_16BPP
,
239 /* mode_winenable*/ 0,
242 /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
243 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565
|
244 LCD_WINCTRL1_PO_16BPP
|
246 /* mode_winenable*/ 0,
252 "0-FS gfx, 1-video, 2-ovly gfx, 3-ovly gfx",
253 /* mode_backcolor */ 0x006600ff,
254 /* mode_colorkey,msk*/ 0, 0,
257 /* xres, yres, xpos, ypos */ 320, 240, 5, 5,
258 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_24BPP
|
260 /* mode_winenable*/ LCD_WINENABLE_WEN0
,
263 /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
264 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565
265 | LCD_WINCTRL1_PO_16BPP
,
266 /* mode_winenable*/ 0,
269 /* xres, yres, xpos, ypos */ 100, 100, 0, 0,
270 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565
|
271 LCD_WINCTRL1_PO_16BPP
|
273 /* mode_winenable*/ 0/*LCD_WINENABLE_WEN2*/,
276 /* xres, yres, xpos, ypos */ 200, 25, 0, 0,
277 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565
|
278 LCD_WINCTRL1_PO_16BPP
|
280 /* mode_winenable*/ 0,
285 "0-FS gfx, 1-video, 2-ovly gfx, 3-ovly gfx",
286 /* mode_backcolor */ 0x006600ff,
287 /* mode_colorkey,msk*/ 0, 0,
290 /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
291 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565
|
292 LCD_WINCTRL1_PO_16BPP
,
293 /* mode_winenable*/ LCD_WINENABLE_WEN0
,
296 /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
297 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565
|
298 LCD_WINCTRL1_PO_16BPP
,
299 /* mode_winenable*/ 0,
302 /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
303 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_32BPP
|
304 LCD_WINCTRL1_PO_00
|LCD_WINCTRL1_PIPE
,
305 /* mode_winenable*/ 0/*LCD_WINENABLE_WEN2*/,
308 /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
309 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565
|
310 LCD_WINCTRL1_PO_16BPP
|
312 /* mode_winenable*/ 0,
316 /* Need VGA 640 @ 24bpp, @ 32bpp */
317 /* Need VGA 800 @ 24bpp, @ 32bpp */
318 /* Need VGA 1024 @ 24bpp, @ 32bpp */
322 * Controller configurations for various panels.
325 struct panel_settings
327 const char name
[25]; /* Full name <vendor>_<model> */
329 struct fb_monspecs monspecs
; /* FB monitor specs */
333 uint32 mode_horztiming
;
334 uint32 mode_verttiming
;
335 uint32 mode_clkcontrol
;
339 uint32 mode_fifoctrl
;
340 uint32 mode_toyclksrc
;
341 uint32 mode_backlight
;
343 int (*device_init
)(void);
344 int (*device_shutdown
)(void);
345 #define Xres min_xres
346 #define Yres min_yres
347 u32 min_xres
; /* Minimum horizontal resolution */
348 u32 max_xres
; /* Maximum horizontal resolution */
349 u32 min_yres
; /* Minimum vertical resolution */
350 u32 max_yres
; /* Maximum vertical resolution */
353 /********************************************************************/
354 /* fixme: Maybe a modedb for the CRT ? otherwise panels should be as-is */
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
;
761 /* fixme: fb_offset += ((0-ypos)*fb_pars[plane].line_length); */
763 /*printk("off screen top\n");*/
766 /* record settings */
767 win
->w
[plane
].xpos
= xpos
;
768 win
->w
[plane
].ypos
= ypos
;
772 winctrl0
|= (xpos
<< 21);
773 winctrl0
|= (ypos
<< 10);
774 winctrl1
|= (xsz
<< 11);
775 winctrl1
|= (ysz
<< 0);
777 /* Disable the window while making changes, then restore WINEN */
778 winenable
= lcd
->winenable
& (1 << plane
);
780 lcd
->winenable
&= ~(1 << plane
);
781 lcd
->window
[plane
].winctrl0
= winctrl0
;
782 lcd
->window
[plane
].winctrl1
= winctrl1
;
783 lcd
->window
[plane
].winbuf0
=
784 lcd
->window
[plane
].winbuf1
= fbdev
->fb_phys
;
785 lcd
->window
[plane
].winbufctrl
= 0; /* select winbuf0 */
786 lcd
->winenable
|= winenable
;
792 static void au1200_setpanel (struct panel_settings
*newpanel
)
795 * Perform global setup/init of LCD controller
799 /* Make sure all windows disabled */
800 winenable
= lcd
->winenable
;
804 * Ensure everything is disabled before reconfiguring
806 if (lcd
->screen
& LCD_SCREEN_SEN
) {
807 /* Wait for vertical sync period */
808 lcd
->intstatus
= LCD_INT_SS
;
809 while ((lcd
->intstatus
& LCD_INT_SS
) == 0) {
813 lcd
->screen
&= ~LCD_SCREEN_SEN
; /*disable the controller*/
816 lcd
->intstatus
= lcd
->intstatus
; /*clear interrupts*/
818 /*wait for controller to shut down*/
819 } while ((lcd
->intstatus
& LCD_INT_SD
) == 0);
821 /* Call shutdown of current panel (if up) */
822 /* this must occur last, because if an external clock is driving
823 the controller, the clock cannot be turned off before first
824 shutting down the controller.
826 if (panel
->device_shutdown
!= NULL
)
827 panel
->device_shutdown();
830 /* Newpanel == NULL indicates a shutdown operation only */
831 if (newpanel
== NULL
)
836 printk("Panel(%s), %dx%d\n", panel
->name
, panel
->Xres
, panel
->Yres
);
839 * Setup clocking if internal LCD clock source (assumes sys_auxpll valid)
841 if (!(panel
->mode_clkcontrol
& LCD_CLKCONTROL_EXT
))
844 au_writel(panel
->mode_auxpll
, SYS_AUXPLL
);
845 sys_clksrc
= au_readl(SYS_CLKSRC
) & ~0x0000001f;
846 sys_clksrc
|= panel
->mode_toyclksrc
;
847 au_writel(sys_clksrc
, SYS_CLKSRC
);
851 * Configure panel timings
853 lcd
->screen
= panel
->mode_screen
;
854 lcd
->horztiming
= panel
->mode_horztiming
;
855 lcd
->verttiming
= panel
->mode_verttiming
;
856 lcd
->clkcontrol
= panel
->mode_clkcontrol
;
857 lcd
->pwmdiv
= panel
->mode_pwmdiv
;
858 lcd
->pwmhi
= panel
->mode_pwmhi
;
859 lcd
->outmask
= panel
->mode_outmask
;
860 lcd
->fifoctrl
= panel
->mode_fifoctrl
;
863 /* fixme: Check window settings to make sure still valid
864 * for new geometry */
866 au1200_setlocation(fbdev
, 0, win
->w
[0].xpos
, win
->w
[0].ypos
);
867 au1200_setlocation(fbdev
, 1, win
->w
[1].xpos
, win
->w
[1].ypos
);
868 au1200_setlocation(fbdev
, 2, win
->w
[2].xpos
, win
->w
[2].ypos
);
869 au1200_setlocation(fbdev
, 3, win
->w
[3].xpos
, win
->w
[3].ypos
);
871 lcd
->winenable
= winenable
;
874 * Re-enable screen now that it is configured
876 lcd
->screen
|= LCD_SCREEN_SEN
;
879 /* Call init of panel */
880 if (panel
->device_init
!= NULL
) panel
->device_init();
882 /* FIX!!!! not appropriate on panel change!!! Global setup/init */
885 lcd
->backcolor
= win
->mode_backcolor
;
887 /* Setup Color Key - FIX!!! */
888 lcd
->colorkey
= win
->mode_colorkey
;
889 lcd
->colorkeymsk
= win
->mode_colorkeymsk
;
891 /* Setup HWCursor - FIX!!! Need to support this eventually */
892 lcd
->hwc
.cursorctrl
= 0;
893 lcd
->hwc
.cursorpos
= 0;
894 lcd
->hwc
.cursorcolor0
= 0;
895 lcd
->hwc
.cursorcolor1
= 0;
896 lcd
->hwc
.cursorcolor2
= 0;
897 lcd
->hwc
.cursorcolor3
= 0;
901 #define D(X) printk("%25s: %08X\n", #X, X)
910 D(lcd
->window
[0].winctrl0
);
911 D(lcd
->window
[0].winctrl1
);
912 D(lcd
->window
[0].winctrl2
);
913 D(lcd
->window
[0].winbuf0
);
914 D(lcd
->window
[0].winbuf1
);
915 D(lcd
->window
[0].winbufctrl
);
916 D(lcd
->window
[1].winctrl0
);
917 D(lcd
->window
[1].winctrl1
);
918 D(lcd
->window
[1].winctrl2
);
919 D(lcd
->window
[1].winbuf0
);
920 D(lcd
->window
[1].winbuf1
);
921 D(lcd
->window
[1].winbufctrl
);
922 D(lcd
->window
[2].winctrl0
);
923 D(lcd
->window
[2].winctrl1
);
924 D(lcd
->window
[2].winctrl2
);
925 D(lcd
->window
[2].winbuf0
);
926 D(lcd
->window
[2].winbuf1
);
927 D(lcd
->window
[2].winbufctrl
);
928 D(lcd
->window
[3].winctrl0
);
929 D(lcd
->window
[3].winctrl1
);
930 D(lcd
->window
[3].winctrl2
);
931 D(lcd
->window
[3].winbuf0
);
932 D(lcd
->window
[3].winbuf1
);
933 D(lcd
->window
[3].winbufctrl
);
941 D(lcd
->hwc
.cursorctrl
);
942 D(lcd
->hwc
.cursorpos
);
943 D(lcd
->hwc
.cursorcolor0
);
944 D(lcd
->hwc
.cursorcolor1
);
945 D(lcd
->hwc
.cursorcolor2
);
946 D(lcd
->hwc
.cursorcolor3
);
950 static void au1200_setmode(struct au1200fb_device
*fbdev
)
952 int plane
= fbdev
->plane
;
953 /* Window/plane setup */
954 lcd
->window
[plane
].winctrl1
= ( 0
955 | LCD_WINCTRL1_PRI_N(plane
)
956 | win
->w
[plane
].mode_winctrl1
/* FRM,CCO,PO,PIPE */
959 au1200_setlocation(fbdev
, plane
, win
->w
[plane
].xpos
, win
->w
[plane
].ypos
);
961 lcd
->window
[plane
].winctrl2
= ( 0
962 | LCD_WINCTRL2_CKMODE_00
964 | LCD_WINCTRL2_BX_N( fbdev
->fb_info
.fix
.line_length
)
968 lcd
->winenable
|= win
->w
[plane
].mode_winenable
;
975 /*#define panel_is_dual(panel) ((panel->mode_screen & LCD_SCREEN_PT) == LCD_SCREEN_PT_010)*/
976 /*#define panel_is_active(panel)((panel->mode_screen & LCD_SCREEN_PT) == LCD_SCREEN_PT_010)*/
978 #define panel_is_color(panel) ((panel->mode_screen & LCD_SCREEN_PT) <= LCD_SCREEN_PT_CDSTN)
980 /* Bitfields format supported by the controller. */
981 static struct fb_bitfield rgb_bitfields
[][4] = {
982 /* Red, Green, Blue, Transp */
983 [LCD_WINCTRL1_FRM_16BPP655
>> 25] =
984 { { 10, 6, 0 }, { 5, 5, 0 }, { 0, 5, 0 }, { 0, 0, 0 } },
986 [LCD_WINCTRL1_FRM_16BPP565
>> 25] =
987 { { 11, 5, 0 }, { 5, 6, 0 }, { 0, 5, 0 }, { 0, 0, 0 } },
989 [LCD_WINCTRL1_FRM_16BPP556
>> 25] =
990 { { 11, 5, 0 }, { 6, 5, 0 }, { 0, 6, 0 }, { 0, 0, 0 } },
992 [LCD_WINCTRL1_FRM_16BPPI1555
>> 25] =
993 { { 10, 5, 0 }, { 5, 5, 0 }, { 0, 5, 0 }, { 0, 0, 0 } },
995 [LCD_WINCTRL1_FRM_16BPPI5551
>> 25] =
996 { { 11, 5, 0 }, { 6, 5, 0 }, { 1, 5, 0 }, { 0, 0, 0 } },
998 [LCD_WINCTRL1_FRM_16BPPA1555
>> 25] =
999 { { 10, 5, 0 }, { 5, 5, 0 }, { 0, 5, 0 }, { 15, 1, 0 } },
1001 [LCD_WINCTRL1_FRM_16BPPA5551
>> 25] =
1002 { { 11, 5, 0 }, { 6, 5, 0 }, { 1, 5, 0 }, { 0, 1, 0 } },
1004 [LCD_WINCTRL1_FRM_24BPP
>> 25] =
1005 { { 16, 8, 0 }, { 8, 8, 0 }, { 0, 8, 0 }, { 0, 0, 0 } },
1007 [LCD_WINCTRL1_FRM_32BPP
>> 25] =
1008 { { 16, 8, 0 }, { 8, 8, 0 }, { 0, 8, 0 }, { 24, 0, 0 } },
1011 /*-------------------------------------------------------------------------*/
1015 static void au1200fb_update_fbinfo(struct fb_info
*fbi
)
1017 /* FIX!!!! This also needs to take the window pixel format into account!!! */
1019 /* Update var-dependent FB info */
1020 if (panel_is_color(panel
)) {
1021 if (fbi
->var
.bits_per_pixel
<= 8) {
1023 fbi
->fix
.visual
= FB_VISUAL_PSEUDOCOLOR
;
1024 fbi
->fix
.line_length
= fbi
->var
.xres_virtual
/
1025 (8/fbi
->var
.bits_per_pixel
);
1027 /* non-palettized */
1028 fbi
->fix
.visual
= FB_VISUAL_TRUECOLOR
;
1029 fbi
->fix
.line_length
= fbi
->var
.xres_virtual
* (fbi
->var
.bits_per_pixel
/ 8);
1032 /* mono FIX!!! mono 8 and 4 bits */
1033 fbi
->fix
.visual
= FB_VISUAL_MONO10
;
1034 fbi
->fix
.line_length
= fbi
->var
.xres_virtual
/ 8;
1037 fbi
->screen_size
= fbi
->fix
.line_length
* fbi
->var
.yres_virtual
;
1038 print_dbg("line length: %d\n", fbi
->fix
.line_length
);
1039 print_dbg("bits_per_pixel: %d\n", fbi
->var
.bits_per_pixel
);
1042 /*-------------------------------------------------------------------------*/
1044 /* AU1200 framebuffer driver */
1047 * Validate var settings with hardware restrictions and modify it if necessary
1049 static int au1200fb_fb_check_var(struct fb_var_screeninfo
*var
,
1050 struct fb_info
*fbi
)
1052 struct au1200fb_device
*fbdev
= (struct au1200fb_device
*)fbi
;
1054 int screen_size
, plane
;
1056 plane
= fbdev
->plane
;
1058 /* Make sure that the mode respect all LCD controller and
1059 * panel restrictions. */
1060 var
->xres
= win
->w
[plane
].xres
;
1061 var
->yres
= win
->w
[plane
].yres
;
1063 /* No need for virtual resolution support */
1064 var
->xres_virtual
= var
->xres
;
1065 var
->yres_virtual
= var
->yres
;
1067 var
->bits_per_pixel
= winbpp(win
->w
[plane
].mode_winctrl1
);
1069 screen_size
= var
->xres_virtual
* var
->yres_virtual
;
1070 if (var
->bits_per_pixel
> 8) screen_size
*= (var
->bits_per_pixel
/ 8);
1071 else screen_size
/= (8/var
->bits_per_pixel
);
1073 if (fbdev
->fb_len
< screen_size
)
1074 return -EINVAL
; /* Virtual screen is to big, abort */
1076 /* FIX!!!! what are the implicaitons of ignoring this for windows ??? */
1077 /* The max LCD clock is fixed to 48MHz (value of AUX_CLK). The pixel
1078 * clock can only be obtain by dividing this value by an even integer.
1079 * Fallback to a slower pixel clock if necessary. */
1080 pixclock
= max((u32
)(PICOS2KHZ(var
->pixclock
) * 1000), fbi
->monspecs
.dclkmin
);
1081 pixclock
= min(pixclock
, min(fbi
->monspecs
.dclkmax
, (u32
)AU1200_LCD_MAX_CLK
/2));
1083 if (AU1200_LCD_MAX_CLK
% pixclock
) {
1084 int diff
= AU1200_LCD_MAX_CLK
% pixclock
;
1088 var
->pixclock
= KHZ2PICOS(pixclock
/1000);
1090 if (!panel_is_active(panel
)) {
1091 int pcd
= AU1200_LCD_MAX_CLK
/ (pixclock
* 2) - 1;
1093 if (!panel_is_color(panel
)
1094 && (panel
->control_base
& LCD_CONTROL_MPI
) && (pcd
< 3)) {
1095 /* STN 8bit mono panel support is up to 6MHz pixclock */
1096 var
->pixclock
= KHZ2PICOS(6000);
1098 /* Other STN panel support is up to 12MHz */
1099 var
->pixclock
= KHZ2PICOS(12000);
1103 /* Set bitfield accordingly */
1104 switch (var
->bits_per_pixel
) {
1107 /* 16bpp True color.
1108 * These must be set to MATCH WINCTRL[FORM] */
1110 idx
= (win
->w
[0].mode_winctrl1
& LCD_WINCTRL1_FRM
) >> 25;
1111 var
->red
= rgb_bitfields
[idx
][0];
1112 var
->green
= rgb_bitfields
[idx
][1];
1113 var
->blue
= rgb_bitfields
[idx
][2];
1114 var
->transp
= rgb_bitfields
[idx
][3];
1120 /* 32bpp True color.
1121 * These must be set to MATCH WINCTRL[FORM] */
1123 idx
= (win
->w
[0].mode_winctrl1
& LCD_WINCTRL1_FRM
) >> 25;
1124 var
->red
= rgb_bitfields
[idx
][0];
1125 var
->green
= rgb_bitfields
[idx
][1];
1126 var
->blue
= rgb_bitfields
[idx
][2];
1127 var
->transp
= rgb_bitfields
[idx
][3];
1131 print_dbg("Unsupported depth %dbpp", var
->bits_per_pixel
);
1139 * Set hardware with var settings. This will enable the controller with a
1140 * specific mode, normally validated with the fb_check_var method
1142 static int au1200fb_fb_set_par(struct fb_info
*fbi
)
1144 struct au1200fb_device
*fbdev
= (struct au1200fb_device
*)fbi
;
1146 au1200fb_update_fbinfo(fbi
);
1147 au1200_setmode(fbdev
);
1153 * Set color in LCD palette.
1155 static int au1200fb_fb_setcolreg(unsigned regno
, unsigned red
, unsigned green
,
1156 unsigned blue
, unsigned transp
, struct fb_info
*fbi
)
1158 volatile u32
*palette
= lcd
->palette
;
1161 if (regno
> (AU1200_LCD_NBR_PALETTE_ENTRIES
- 1))
1164 if (fbi
->var
.grayscale
) {
1165 /* Convert color to grayscale */
1166 red
= green
= blue
=
1167 (19595 * red
+ 38470 * green
+ 7471 * blue
) >> 16;
1170 if (fbi
->fix
.visual
== FB_VISUAL_TRUECOLOR
) {
1171 /* Place color in the pseudopalette */
1175 palette
= (u32
*) fbi
->pseudo_palette
;
1177 red
>>= (16 - fbi
->var
.red
.length
);
1178 green
>>= (16 - fbi
->var
.green
.length
);
1179 blue
>>= (16 - fbi
->var
.blue
.length
);
1181 value
= (red
<< fbi
->var
.red
.offset
) |
1182 (green
<< fbi
->var
.green
.offset
)|
1183 (blue
<< fbi
->var
.blue
.offset
);
1186 } else if (1 /*FIX!!! panel_is_active(fbdev->panel)*/) {
1187 /* COLOR TFT PALLETTIZED (use RGB 565) */
1188 value
= (red
& 0xF800)|((green
>> 5) &
1189 0x07E0)|((blue
>> 11) & 0x001F);
1192 } else if (0 /*panel_is_color(fbdev->panel)*/) {
1193 /* COLOR STN MODE */
1197 /* MONOCHROME MODE */
1198 value
= (green
>> 12) & 0x000F;
1202 palette
[regno
] = value
;
1208 * Blank the screen. Depending on the mode, the screen will be
1209 * activated with the backlight color, or desactivated
1211 static int au1200fb_fb_blank(int blank_mode
, struct fb_info
*fbi
)
1213 /* Short-circuit screen blanking */
1217 switch (blank_mode
) {
1219 case FB_BLANK_UNBLANK
:
1220 case FB_BLANK_NORMAL
:
1221 /* printk("turn on panel\n"); */
1222 au1200_setpanel(panel
);
1224 case FB_BLANK_VSYNC_SUSPEND
:
1225 case FB_BLANK_HSYNC_SUSPEND
:
1226 case FB_BLANK_POWERDOWN
:
1227 /* printk("turn off panel\n"); */
1228 au1200_setpanel(NULL
);
1235 /* FB_BLANK_NORMAL is a soft blank */
1236 return (blank_mode
== FB_BLANK_NORMAL
) ? -EINVAL
: 0;
1240 * Map video memory in user space. We don't use the generic fb_mmap
1241 * method mainly to allow the use of the TLB streaming flag (CCA=6)
1243 static int au1200fb_fb_mmap(struct fb_info
*info
, struct vm_area_struct
*vma
)
1247 unsigned long start
=0, off
;
1248 struct au1200fb_device
*fbdev
= (struct au1200fb_device
*) info
;
1251 au1xxx_pm_access(LCD_pm_dev
);
1254 if (vma
->vm_pgoff
> (~0UL >> PAGE_SHIFT
)) {
1258 start
= fbdev
->fb_phys
& PAGE_MASK
;
1259 len
= PAGE_ALIGN((start
& ~PAGE_MASK
) + fbdev
->fb_len
);
1261 off
= vma
->vm_pgoff
<< PAGE_SHIFT
;
1263 if ((vma
->vm_end
- vma
->vm_start
+ off
) > len
) {
1268 vma
->vm_pgoff
= off
>> PAGE_SHIFT
;
1270 vma
->vm_page_prot
= pgprot_noncached(vma
->vm_page_prot
);
1271 pgprot_val(vma
->vm_page_prot
) |= _CACHE_MASK
; /* CCA=7 */
1273 vma
->vm_flags
|= VM_IO
;
1275 return io_remap_pfn_range(vma
, vma
->vm_start
, off
>> PAGE_SHIFT
,
1276 vma
->vm_end
- vma
->vm_start
,
1282 static void set_global(u_int cmd
, struct au1200_lcd_global_regs_t
*pdata
)
1285 unsigned int hi1
, divider
;
1287 /* SCREEN_SIZE: user cannot reset size, must switch panel choice */
1289 if (pdata
->flags
& SCREEN_BACKCOLOR
)
1290 lcd
->backcolor
= pdata
->backcolor
;
1292 if (pdata
->flags
& SCREEN_BRIGHTNESS
) {
1294 // limit brightness pwm duty to >= 30/1600
1295 if (pdata
->brightness
< 30) {
1296 pdata
->brightness
= 30;
1298 divider
= (lcd
->pwmdiv
& 0x3FFFF) + 1;
1299 hi1
= (lcd
->pwmhi
>> 16) + 1;
1300 hi1
= (((pdata
->brightness
& 0xFF)+1) * divider
>> 8);
1301 lcd
->pwmhi
&= 0xFFFF;
1302 lcd
->pwmhi
|= (hi1
<< 16);
1305 if (pdata
->flags
& SCREEN_COLORKEY
)
1306 lcd
->colorkey
= pdata
->colorkey
;
1308 if (pdata
->flags
& SCREEN_MASK
)
1309 lcd
->colorkeymsk
= pdata
->mask
;
1313 static void get_global(u_int cmd
, struct au1200_lcd_global_regs_t
*pdata
)
1315 unsigned int hi1
, divider
;
1317 pdata
->xsize
= ((lcd
->screen
& LCD_SCREEN_SX
) >> 19) + 1;
1318 pdata
->ysize
= ((lcd
->screen
& LCD_SCREEN_SY
) >> 8) + 1;
1320 pdata
->backcolor
= lcd
->backcolor
;
1321 pdata
->colorkey
= lcd
->colorkey
;
1322 pdata
->mask
= lcd
->colorkeymsk
;
1325 hi1
= (lcd
->pwmhi
>> 16) + 1;
1326 divider
= (lcd
->pwmdiv
& 0x3FFFF) + 1;
1327 pdata
->brightness
= ((hi1
<< 8) / divider
) - 1;
1331 static void set_window(unsigned int plane
,
1332 struct au1200_lcd_window_regs_t
*pdata
)
1334 unsigned int val
, bpp
;
1336 /* Window control register 0 */
1337 if (pdata
->flags
& WIN_POSITION
) {
1338 val
= lcd
->window
[plane
].winctrl0
& ~(LCD_WINCTRL0_OX
|
1340 val
|= ((pdata
->xpos
<< 21) & LCD_WINCTRL0_OX
);
1341 val
|= ((pdata
->ypos
<< 10) & LCD_WINCTRL0_OY
);
1342 lcd
->window
[plane
].winctrl0
= val
;
1344 if (pdata
->flags
& WIN_ALPHA_COLOR
) {
1345 val
= lcd
->window
[plane
].winctrl0
& ~(LCD_WINCTRL0_A
);
1346 val
|= ((pdata
->alpha_color
<< 2) & LCD_WINCTRL0_A
);
1347 lcd
->window
[plane
].winctrl0
= val
;
1349 if (pdata
->flags
& WIN_ALPHA_MODE
) {
1350 val
= lcd
->window
[plane
].winctrl0
& ~(LCD_WINCTRL0_AEN
);
1351 val
|= ((pdata
->alpha_mode
<< 1) & LCD_WINCTRL0_AEN
);
1352 lcd
->window
[plane
].winctrl0
= val
;
1355 /* Window control register 1 */
1356 if (pdata
->flags
& WIN_PRIORITY
) {
1357 val
= lcd
->window
[plane
].winctrl1
& ~(LCD_WINCTRL1_PRI
);
1358 val
|= ((pdata
->priority
<< 30) & LCD_WINCTRL1_PRI
);
1359 lcd
->window
[plane
].winctrl1
= val
;
1361 if (pdata
->flags
& WIN_CHANNEL
) {
1362 val
= lcd
->window
[plane
].winctrl1
& ~(LCD_WINCTRL1_PIPE
);
1363 val
|= ((pdata
->channel
<< 29) & LCD_WINCTRL1_PIPE
);
1364 lcd
->window
[plane
].winctrl1
= val
;
1366 if (pdata
->flags
& WIN_BUFFER_FORMAT
) {
1367 val
= lcd
->window
[plane
].winctrl1
& ~(LCD_WINCTRL1_FRM
);
1368 val
|= ((pdata
->buffer_format
<< 25) & LCD_WINCTRL1_FRM
);
1369 lcd
->window
[plane
].winctrl1
= val
;
1371 if (pdata
->flags
& WIN_COLOR_ORDER
) {
1372 val
= lcd
->window
[plane
].winctrl1
& ~(LCD_WINCTRL1_CCO
);
1373 val
|= ((pdata
->color_order
<< 24) & LCD_WINCTRL1_CCO
);
1374 lcd
->window
[plane
].winctrl1
= val
;
1376 if (pdata
->flags
& WIN_PIXEL_ORDER
) {
1377 val
= lcd
->window
[plane
].winctrl1
& ~(LCD_WINCTRL1_PO
);
1378 val
|= ((pdata
->pixel_order
<< 22) & LCD_WINCTRL1_PO
);
1379 lcd
->window
[plane
].winctrl1
= val
;
1381 if (pdata
->flags
& WIN_SIZE
) {
1382 val
= lcd
->window
[plane
].winctrl1
& ~(LCD_WINCTRL1_SZX
|
1384 val
|= (((pdata
->xsize
<< 11) - 1) & LCD_WINCTRL1_SZX
);
1385 val
|= (((pdata
->ysize
) - 1) & LCD_WINCTRL1_SZY
);
1386 lcd
->window
[plane
].winctrl1
= val
;
1387 /* program buffer line width */
1388 bpp
= winbpp(val
) / 8;
1389 val
= lcd
->window
[plane
].winctrl2
& ~(LCD_WINCTRL2_BX
);
1390 val
|= (((pdata
->xsize
* bpp
) << 8) & LCD_WINCTRL2_BX
);
1391 lcd
->window
[plane
].winctrl2
= val
;
1394 /* Window control register 2 */
1395 if (pdata
->flags
& WIN_COLORKEY_MODE
) {
1396 val
= lcd
->window
[plane
].winctrl2
& ~(LCD_WINCTRL2_CKMODE
);
1397 val
|= ((pdata
->colorkey_mode
<< 24) & LCD_WINCTRL2_CKMODE
);
1398 lcd
->window
[plane
].winctrl2
= val
;
1400 if (pdata
->flags
& WIN_DOUBLE_BUFFER_MODE
) {
1401 val
= lcd
->window
[plane
].winctrl2
& ~(LCD_WINCTRL2_DBM
);
1402 val
|= ((pdata
->double_buffer_mode
<< 23) & LCD_WINCTRL2_DBM
);
1403 lcd
->window
[plane
].winctrl2
= val
;
1405 if (pdata
->flags
& WIN_RAM_ARRAY_MODE
) {
1406 val
= lcd
->window
[plane
].winctrl2
& ~(LCD_WINCTRL2_RAM
);
1407 val
|= ((pdata
->ram_array_mode
<< 21) & LCD_WINCTRL2_RAM
);
1408 lcd
->window
[plane
].winctrl2
= val
;
1411 /* Buffer line width programmed with WIN_SIZE */
1413 if (pdata
->flags
& WIN_BUFFER_SCALE
) {
1414 val
= lcd
->window
[plane
].winctrl2
& ~(LCD_WINCTRL2_SCX
|
1416 val
|= ((pdata
->xsize
<< 11) & LCD_WINCTRL2_SCX
);
1417 val
|= ((pdata
->ysize
) & LCD_WINCTRL2_SCY
);
1418 lcd
->window
[plane
].winctrl2
= val
;
1421 if (pdata
->flags
& WIN_ENABLE
) {
1422 val
= lcd
->winenable
;
1424 val
|= (pdata
->enable
& 1) << plane
;
1425 lcd
->winenable
= val
;
1430 static void get_window(unsigned int plane
,
1431 struct au1200_lcd_window_regs_t
*pdata
)
1433 /* Window control register 0 */
1434 pdata
->xpos
= (lcd
->window
[plane
].winctrl0
& LCD_WINCTRL0_OX
) >> 21;
1435 pdata
->ypos
= (lcd
->window
[plane
].winctrl0
& LCD_WINCTRL0_OY
) >> 10;
1436 pdata
->alpha_color
= (lcd
->window
[plane
].winctrl0
& LCD_WINCTRL0_A
) >> 2;
1437 pdata
->alpha_mode
= (lcd
->window
[plane
].winctrl0
& LCD_WINCTRL0_AEN
) >> 1;
1439 /* Window control register 1 */
1440 pdata
->priority
= (lcd
->window
[plane
].winctrl1
& LCD_WINCTRL1_PRI
) >> 30;
1441 pdata
->channel
= (lcd
->window
[plane
].winctrl1
& LCD_WINCTRL1_PIPE
) >> 29;
1442 pdata
->buffer_format
= (lcd
->window
[plane
].winctrl1
& LCD_WINCTRL1_FRM
) >> 25;
1443 pdata
->color_order
= (lcd
->window
[plane
].winctrl1
& LCD_WINCTRL1_CCO
) >> 24;
1444 pdata
->pixel_order
= (lcd
->window
[plane
].winctrl1
& LCD_WINCTRL1_PO
) >> 22;
1445 pdata
->xsize
= ((lcd
->window
[plane
].winctrl1
& LCD_WINCTRL1_SZX
) >> 11) + 1;
1446 pdata
->ysize
= (lcd
->window
[plane
].winctrl1
& LCD_WINCTRL1_SZY
) + 1;
1448 /* Window control register 2 */
1449 pdata
->colorkey_mode
= (lcd
->window
[plane
].winctrl2
& LCD_WINCTRL2_CKMODE
) >> 24;
1450 pdata
->double_buffer_mode
= (lcd
->window
[plane
].winctrl2
& LCD_WINCTRL2_DBM
) >> 23;
1451 pdata
->ram_array_mode
= (lcd
->window
[plane
].winctrl2
& LCD_WINCTRL2_RAM
) >> 21;
1453 pdata
->enable
= (lcd
->winenable
>> plane
) & 1;
1457 static int au1200fb_ioctl(struct fb_info
*info
, unsigned int cmd
,
1464 au1xxx_pm_access(LCD_pm_dev
);
1467 plane
= fbinfo2index(info
);
1468 print_dbg("au1200fb: ioctl %d on plane %d\n", cmd
, plane
);
1470 if (cmd
== AU1200_LCD_FB_IOCTL
) {
1471 struct au1200_lcd_iodata_t iodata
;
1473 if (copy_from_user(&iodata
, (void __user
*) arg
, sizeof(iodata
)))
1476 print_dbg("FB IOCTL called\n");
1478 switch (iodata
.subcmd
) {
1479 case AU1200_LCD_SET_SCREEN
:
1480 print_dbg("AU1200_LCD_SET_SCREEN\n");
1481 set_global(cmd
, &iodata
.global
);
1484 case AU1200_LCD_GET_SCREEN
:
1485 print_dbg("AU1200_LCD_GET_SCREEN\n");
1486 get_global(cmd
, &iodata
.global
);
1489 case AU1200_LCD_SET_WINDOW
:
1490 print_dbg("AU1200_LCD_SET_WINDOW\n");
1491 set_window(plane
, &iodata
.window
);
1494 case AU1200_LCD_GET_WINDOW
:
1495 print_dbg("AU1200_LCD_GET_WINDOW\n");
1496 get_window(plane
, &iodata
.window
);
1499 case AU1200_LCD_SET_PANEL
:
1500 print_dbg("AU1200_LCD_SET_PANEL\n");
1501 if ((iodata
.global
.panel_choice
>= 0) &&
1502 (iodata
.global
.panel_choice
<
1505 struct panel_settings
*newpanel
;
1506 panel_index
= iodata
.global
.panel_choice
;
1507 newpanel
= &known_lcd_panels
[panel_index
];
1508 au1200_setpanel(newpanel
);
1512 case AU1200_LCD_GET_PANEL
:
1513 print_dbg("AU1200_LCD_GET_PANEL\n");
1514 iodata
.global
.panel_choice
= panel_index
;
1521 val
= copy_to_user((void __user
*) arg
, &iodata
, sizeof(iodata
));
1523 print_dbg("error: could not copy %d bytes\n", val
);
1532 static struct fb_ops au1200fb_fb_ops
= {
1533 .owner
= THIS_MODULE
,
1534 .fb_check_var
= au1200fb_fb_check_var
,
1535 .fb_set_par
= au1200fb_fb_set_par
,
1536 .fb_setcolreg
= au1200fb_fb_setcolreg
,
1537 .fb_blank
= au1200fb_fb_blank
,
1538 .fb_fillrect
= cfb_fillrect
,
1539 .fb_copyarea
= cfb_copyarea
,
1540 .fb_imageblit
= cfb_imageblit
,
1542 .fb_ioctl
= au1200fb_ioctl
,
1543 .fb_mmap
= au1200fb_fb_mmap
,
1546 /*-------------------------------------------------------------------------*/
1548 static irqreturn_t
au1200fb_handle_irq(int irq
, void* dev_id
)
1550 /* Nothing to do for now, just clear any pending interrupt */
1551 lcd
->intstatus
= lcd
->intstatus
;
1557 /*-------------------------------------------------------------------------*/
1559 /* AU1200 LCD device probe helpers */
1561 static int au1200fb_init_fbinfo(struct au1200fb_device
*fbdev
)
1563 struct fb_info
*fbi
= &fbdev
->fb_info
;
1566 memset(fbi
, 0, sizeof(struct fb_info
));
1567 fbi
->fbops
= &au1200fb_fb_ops
;
1569 bpp
= winbpp(win
->w
[fbdev
->plane
].mode_winctrl1
);
1571 /* Copy monitor specs from panel data */
1572 /* fixme: we're setting up LCD controller windows, so these dont give a
1573 damn as to what the monitor specs are (the panel itself does, but that
1574 isnt done here...so maybe need a generic catchall monitor setting??? */
1575 memcpy(&fbi
->monspecs
, &panel
->monspecs
, sizeof(struct fb_monspecs
));
1577 /* We first try the user mode passed in argument. If that failed,
1578 * or if no one has been specified, we default to the first mode of the
1579 * panel list. Note that after this call, var data will be set */
1580 if (!fb_find_mode(&fbi
->var
,
1582 NULL
, /* drv_info.opt_mode, */
1583 fbi
->monspecs
.modedb
,
1584 fbi
->monspecs
.modedb_len
,
1585 fbi
->monspecs
.modedb
,
1588 print_err("Cannot find valid mode for panel %s", panel
->name
);
1592 fbi
->pseudo_palette
= kcalloc(16, sizeof(u32
), GFP_KERNEL
);
1593 if (!fbi
->pseudo_palette
) {
1597 if (fb_alloc_cmap(&fbi
->cmap
, AU1200_LCD_NBR_PALETTE_ENTRIES
, 0) < 0) {
1598 print_err("Fail to allocate colormap (%d entries)",
1599 AU1200_LCD_NBR_PALETTE_ENTRIES
);
1600 kfree(fbi
->pseudo_palette
);
1604 strncpy(fbi
->fix
.id
, "AU1200", sizeof(fbi
->fix
.id
));
1605 fbi
->fix
.smem_start
= fbdev
->fb_phys
;
1606 fbi
->fix
.smem_len
= fbdev
->fb_len
;
1607 fbi
->fix
.type
= FB_TYPE_PACKED_PIXELS
;
1608 fbi
->fix
.xpanstep
= 0;
1609 fbi
->fix
.ypanstep
= 0;
1610 fbi
->fix
.mmio_start
= 0;
1611 fbi
->fix
.mmio_len
= 0;
1612 fbi
->fix
.accel
= FB_ACCEL_NONE
;
1614 fbi
->screen_base
= (char __iomem
*) fbdev
->fb_mem
;
1616 au1200fb_update_fbinfo(fbi
);
1621 /*-------------------------------------------------------------------------*/
1623 /* AU1200 LCD controller device driver */
1625 static int au1200fb_drv_probe(struct platform_device
*dev
)
1627 struct au1200fb_device
*fbdev
;
1629 int bpp
, plane
, ret
;
1634 for (plane
= 0; plane
< CONFIG_FB_AU1200_DEVS
; ++plane
) {
1635 bpp
= winbpp(win
->w
[plane
].mode_winctrl1
);
1636 if (win
->w
[plane
].xres
== 0)
1637 win
->w
[plane
].xres
= panel
->Xres
;
1638 if (win
->w
[plane
].yres
== 0)
1639 win
->w
[plane
].yres
= panel
->Yres
;
1641 fbdev
= &_au1200fb_devices
[plane
];
1642 memset(fbdev
, 0, sizeof(struct au1200fb_device
));
1643 fbdev
->plane
= plane
;
1645 /* Allocate the framebuffer to the maximum screen size */
1646 fbdev
->fb_len
= (win
->w
[plane
].xres
* win
->w
[plane
].yres
* bpp
) / 8;
1648 fbdev
->fb_mem
= dma_alloc_noncoherent(&dev
->dev
,
1649 PAGE_ALIGN(fbdev
->fb_len
),
1650 &fbdev
->fb_phys
, GFP_KERNEL
);
1651 if (!fbdev
->fb_mem
) {
1652 print_err("fail to allocate frambuffer (size: %dK))",
1653 fbdev
->fb_len
/ 1024);
1658 * Set page reserved so that mmap will work. This is necessary
1659 * since we'll be remapping normal memory.
1661 for (page
= (unsigned long)fbdev
->fb_phys
;
1662 page
< PAGE_ALIGN((unsigned long)fbdev
->fb_phys
+
1664 page
+= PAGE_SIZE
) {
1665 SetPageReserved(pfn_to_page(page
>> PAGE_SHIFT
)); /* LCD DMA is NOT coherent on Au1200 */
1667 print_dbg("Framebuffer memory map at %p", fbdev
->fb_mem
);
1668 print_dbg("phys=0x%08x, size=%dK", fbdev
->fb_phys
, fbdev
->fb_len
/ 1024);
1671 if ((ret
= au1200fb_init_fbinfo(fbdev
)) < 0)
1674 /* Register new framebuffer */
1675 if ((ret
= register_framebuffer(&fbdev
->fb_info
)) < 0) {
1676 print_err("cannot register new framebuffer");
1680 au1200fb_fb_set_par(&fbdev
->fb_info
);
1682 #if !defined(CONFIG_FRAMEBUFFER_CONSOLE) && defined(CONFIG_LOGO)
1684 if (fb_prepare_logo(&fbdev
->fb_info
, FB_ROTATE_UR
)) {
1685 /* Start display and show logo on boot */
1686 fb_set_cmap(&fbdev
->fb_info
.cmap
,
1689 fb_show_logo(&fbdev
->fb_info
, FB_ROTATE_UR
);
1694 /* Now hook interrupt too */
1695 if ((ret
= request_irq(AU1200_LCD_INT
, au1200fb_handle_irq
,
1696 IRQF_DISABLED
| IRQF_SHARED
, "lcd", (void *)dev
)) < 0) {
1697 print_err("fail to request interrupt line %d (err: %d)",
1698 AU1200_LCD_INT
, ret
);
1705 /* NOTE: This only does the current plane/window that failed; others are still active */
1707 dma_free_noncoherent(dev
, PAGE_ALIGN(fbdev
->fb_len
),
1708 fbdev
->fb_mem
, fbdev
->fb_phys
);
1709 if (fbdev
->fb_info
.cmap
.len
!= 0)
1710 fb_dealloc_cmap(&fbdev
->fb_info
.cmap
);
1711 if (fbdev
->fb_info
.pseudo_palette
)
1712 kfree(fbdev
->fb_info
.pseudo_palette
);
1714 free_irq(AU1200_LCD_INT
, (void*)dev
);
1718 static int au1200fb_drv_remove(struct platform_device
*dev
)
1720 struct au1200fb_device
*fbdev
;
1726 /* Turn off the panel */
1727 au1200_setpanel(NULL
);
1729 for (plane
= 0; plane
< CONFIG_FB_AU1200_DEVS
; ++plane
)
1731 fbdev
= &_au1200fb_devices
[plane
];
1733 /* Clean up all probe data */
1734 unregister_framebuffer(&fbdev
->fb_info
);
1736 dma_free_noncoherent(&dev
->dev
,
1737 PAGE_ALIGN(fbdev
->fb_len
),
1738 fbdev
->fb_mem
, fbdev
->fb_phys
);
1739 if (fbdev
->fb_info
.cmap
.len
!= 0)
1740 fb_dealloc_cmap(&fbdev
->fb_info
.cmap
);
1741 if (fbdev
->fb_info
.pseudo_palette
)
1742 kfree(fbdev
->fb_info
.pseudo_palette
);
1745 free_irq(AU1200_LCD_INT
, (void *)dev
);
1751 static int au1200fb_drv_suspend(struct platform_device
*dev
, u32 state
)
1757 static int au1200fb_drv_resume(struct platform_device
*dev
)
1762 #endif /* CONFIG_PM */
1764 static struct platform_driver au1200fb_driver
= {
1766 .name
= "au1200-lcd",
1767 .owner
= THIS_MODULE
,
1769 .probe
= au1200fb_drv_probe
,
1770 .remove
= au1200fb_drv_remove
,
1772 .suspend
= au1200fb_drv_suspend
,
1773 .resume
= au1200fb_drv_resume
,
1777 /*-------------------------------------------------------------------------*/
1781 static void au1200fb_setup(void)
1783 char* options
= NULL
;
1785 int num_panels
= ARRAY_SIZE(known_lcd_panels
);
1788 fb_get_options(DRIVER_NAME
, &options
);
1791 while ((this_opt
= strsep(&options
,",")) != NULL
) {
1792 /* Panel option - can be panel name,
1793 * "bs" for board-switch, or number/index */
1794 if (!strncmp(this_opt
, "panel:", 6)) {
1799 /* First check for index, which allows
1800 * to short circuit this mess */
1801 li
= simple_strtol(this_opt
, &endptr
, 0);
1802 if (*endptr
== '\0') {
1803 panel_idx
= (int)li
;
1805 else if (strcmp(this_opt
, "bs") == 0) {
1806 extern int board_au1200fb_panel(void);
1807 panel_idx
= board_au1200fb_panel();
1811 for (i
= 0; i
< num_panels
; i
++) {
1812 if (!strcmp(this_opt
, known_lcd_panels
[i
].name
)) {
1818 if ((panel_idx
< 0) || (panel_idx
>= num_panels
)) {
1819 print_warn("Panel %s not supported!", this_opt
);
1822 panel_index
= panel_idx
;
1825 else if (strncmp(this_opt
, "nohwcursor", 10) == 0) {
1829 /* Unsupported option */
1831 print_warn("Unsupported option \"%s\"", this_opt
);
1838 static int au1200fb_pm_callback(au1xxx_power_dev_t
*dev
,
1839 au1xxx_request_t request
, void *data
) {
1842 unsigned int brightness
= 0;
1844 if (request
== AU1XXX_PM_SLEEP
) {
1845 board_au1200fb_panel_shutdown();
1847 else if (request
== AU1XXX_PM_WAKEUP
) {
1848 if(dev
->prev_state
== SLEEP_STATE
)
1851 au1200_setpanel(panel
);
1852 for (plane
= 0; plane
< CONFIG_FB_AU1200_DEVS
; ++plane
) {
1853 struct au1200fb_device
*fbdev
;
1854 fbdev
= &_au1200fb_devices
[plane
];
1855 au1200fb_fb_set_par(&fbdev
->fb_info
);
1859 d
= *((unsigned int*)data
);
1860 if(d
<=10) brightness
= 26;
1861 else if(d
<=20) brightness
= 51;
1862 else if(d
<=30) brightness
= 77;
1863 else if(d
<=40) brightness
= 102;
1864 else if(d
<=50) brightness
= 128;
1865 else if(d
<=60) brightness
= 153;
1866 else if(d
<=70) brightness
= 179;
1867 else if(d
<=80) brightness
= 204;
1868 else if(d
<=90) brightness
= 230;
1869 else brightness
= 255;
1870 set_brightness(brightness
);
1871 } else if (request
== AU1XXX_PM_GETSTATUS
) {
1872 return dev
->cur_state
;
1873 } else if (request
== AU1XXX_PM_ACCESS
) {
1874 if (dev
->cur_state
!= SLEEP_STATE
)
1877 au1200_setpanel(panel
);
1879 } else if (request
== AU1XXX_PM_IDLE
) {
1880 } else if (request
== AU1XXX_PM_CLEANUP
) {
1887 static int __init
au1200fb_init(void)
1889 print_info("" DRIVER_DESC
"");
1891 /* Setup driver with options */
1894 /* Point to the panel selected */
1895 panel
= &known_lcd_panels
[panel_index
];
1896 win
= &windows
[window_index
];
1898 printk(DRIVER_NAME
": Panel %d %s\n", panel_index
, panel
->name
);
1899 printk(DRIVER_NAME
": Win %d %s\n", window_index
, win
->name
);
1901 /* Kickstart the panel, the framebuffers/windows come soon enough */
1902 au1200_setpanel(panel
);
1905 LCD_pm_dev
= new_au1xxx_power_device("LCD", &au1200fb_pm_callback
, NULL
);
1906 if ( LCD_pm_dev
== NULL
)
1907 printk(KERN_INFO
"Unable to create a power management device entry for the au1200fb.\n");
1909 printk(KERN_INFO
"Power management device entry for the au1200fb loaded.\n");
1912 return platform_driver_register(&au1200fb_driver
);
1915 static void __exit
au1200fb_cleanup(void)
1917 platform_driver_unregister(&au1200fb_driver
);
1920 module_init(au1200fb_init
);
1921 module_exit(au1200fb_cleanup
);
1923 MODULE_DESCRIPTION(DRIVER_DESC
);
1924 MODULE_LICENSE("GPL");