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>
49 #define DRIVER_NAME "au1200fb"
50 #define DRIVER_DESC "LCD controller driver for AU1200 processors"
54 #define print_err(f, arg...) printk(KERN_ERR DRIVER_NAME ": " f "\n", ## arg)
55 #define print_warn(f, arg...) printk(KERN_WARNING DRIVER_NAME ": " f "\n", ## arg)
56 #define print_info(f, arg...) printk(KERN_INFO DRIVER_NAME ": " f "\n", ## arg)
59 #define print_dbg(f, arg...) printk(KERN_DEBUG __FILE__ ": " f "\n", ## arg)
61 #define print_dbg(f, arg...) do {} while (0)
65 #define AU1200_LCD_FB_IOCTL 0x46FF
67 #define AU1200_LCD_SET_SCREEN 1
68 #define AU1200_LCD_GET_SCREEN 2
69 #define AU1200_LCD_SET_WINDOW 3
70 #define AU1200_LCD_GET_WINDOW 4
71 #define AU1200_LCD_SET_PANEL 5
72 #define AU1200_LCD_GET_PANEL 6
74 #define SCREEN_SIZE (1<< 1)
75 #define SCREEN_BACKCOLOR (1<< 2)
76 #define SCREEN_BRIGHTNESS (1<< 3)
77 #define SCREEN_COLORKEY (1<< 4)
78 #define SCREEN_MASK (1<< 5)
80 struct au1200_lcd_global_regs_t
{
84 unsigned int backcolor
;
85 unsigned int brightness
;
86 unsigned int colorkey
;
88 unsigned int panel_choice
;
93 #define WIN_POSITION (1<< 0)
94 #define WIN_ALPHA_COLOR (1<< 1)
95 #define WIN_ALPHA_MODE (1<< 2)
96 #define WIN_PRIORITY (1<< 3)
97 #define WIN_CHANNEL (1<< 4)
98 #define WIN_BUFFER_FORMAT (1<< 5)
99 #define WIN_COLOR_ORDER (1<< 6)
100 #define WIN_PIXEL_ORDER (1<< 7)
101 #define WIN_SIZE (1<< 8)
102 #define WIN_COLORKEY_MODE (1<< 9)
103 #define WIN_DOUBLE_BUFFER_MODE (1<< 10)
104 #define WIN_RAM_ARRAY_MODE (1<< 11)
105 #define WIN_BUFFER_SCALE (1<< 12)
106 #define WIN_ENABLE (1<< 13)
108 struct au1200_lcd_window_regs_t
{
112 unsigned int alpha_color
;
113 unsigned int alpha_mode
;
114 unsigned int priority
;
115 unsigned int channel
;
116 unsigned int buffer_format
;
117 unsigned int color_order
;
118 unsigned int pixel_order
;
121 unsigned int colorkey_mode
;
122 unsigned int double_buffer_mode
;
123 unsigned int ram_array_mode
;
130 struct au1200_lcd_iodata_t
{
132 struct au1200_lcd_global_regs_t global
;
133 struct au1200_lcd_window_regs_t window
;
136 #if defined(__BIG_ENDIAN)
137 #define LCD_CONTROL_DEFAULT_PO LCD_CONTROL_PO_11
139 #define LCD_CONTROL_DEFAULT_PO LCD_CONTROL_PO_00
141 #define LCD_CONTROL_DEFAULT_SBPPF LCD_CONTROL_SBPPF_565
143 /* Private, per-framebuffer management information (independent of the panel itself) */
144 struct au1200fb_device
{
145 struct fb_info
*fb_info
; /* FB driver info record */
148 unsigned char* fb_mem
; /* FrameBuffer memory map */
153 /********************************************************************/
155 /* LCD controller restrictions */
156 #define AU1200_LCD_MAX_XRES 1280
157 #define AU1200_LCD_MAX_YRES 1024
158 #define AU1200_LCD_MAX_BPP 32
159 #define AU1200_LCD_MAX_CLK 96000000 /* fixme: this needs to go away ? */
160 #define AU1200_LCD_NBR_PALETTE_ENTRIES 256
162 /* Default number of visible screen buffer to allocate */
163 #define AU1200FB_NBR_VIDEO_BUFFERS 1
165 /* Default maximum number of fb devices to create */
166 #define MAX_DEVICE_COUNT 4
168 /* Default window configuration entry to use (see windows[]) */
169 #define DEFAULT_WINDOW_INDEX 2
171 /********************************************************************/
173 static struct fb_info
*_au1200fb_infos
[MAX_DEVICE_COUNT
];
174 static struct au1200_lcd
*lcd
= (struct au1200_lcd
*) AU1200_LCD_ADDR
;
175 static int device_count
= MAX_DEVICE_COUNT
;
176 static int window_index
= DEFAULT_WINDOW_INDEX
; /* 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 * Default window configurations
210 static struct window_settings windows
[] = {
212 "0-FS gfx, 1-video, 2-ovly gfx, 3-ovly gfx",
213 /* mode_backcolor */ 0x006600ff,
214 /* mode_colorkey,msk*/ 0, 0,
217 /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
218 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565
|
219 LCD_WINCTRL1_PO_16BPP
,
220 /* mode_winenable*/ LCD_WINENABLE_WEN0
,
223 /* xres, yres, xpos, ypos */ 100, 100, 100, 100,
224 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565
|
225 LCD_WINCTRL1_PO_16BPP
|
227 /* mode_winenable*/ LCD_WINENABLE_WEN1
,
230 /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
231 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565
|
232 LCD_WINCTRL1_PO_16BPP
,
233 /* mode_winenable*/ 0,
236 /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
237 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565
|
238 LCD_WINCTRL1_PO_16BPP
|
240 /* mode_winenable*/ 0,
246 "0-FS gfx, 1-video, 2-ovly gfx, 3-ovly gfx",
247 /* mode_backcolor */ 0x006600ff,
248 /* mode_colorkey,msk*/ 0, 0,
251 /* xres, yres, xpos, ypos */ 320, 240, 5, 5,
252 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_24BPP
|
254 /* mode_winenable*/ LCD_WINENABLE_WEN0
,
257 /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
258 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565
259 | LCD_WINCTRL1_PO_16BPP
,
260 /* mode_winenable*/ 0,
263 /* xres, yres, xpos, ypos */ 100, 100, 0, 0,
264 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565
|
265 LCD_WINCTRL1_PO_16BPP
|
267 /* mode_winenable*/ 0/*LCD_WINENABLE_WEN2*/,
270 /* xres, yres, xpos, ypos */ 200, 25, 0, 0,
271 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565
|
272 LCD_WINCTRL1_PO_16BPP
|
274 /* mode_winenable*/ 0,
279 "0-FS gfx, 1-video, 2-ovly gfx, 3-ovly gfx",
280 /* mode_backcolor */ 0x006600ff,
281 /* mode_colorkey,msk*/ 0, 0,
284 /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
285 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565
|
286 LCD_WINCTRL1_PO_16BPP
,
287 /* mode_winenable*/ LCD_WINENABLE_WEN0
,
290 /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
291 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565
|
292 LCD_WINCTRL1_PO_16BPP
,
293 /* mode_winenable*/ 0,
296 /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
297 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_32BPP
|
298 LCD_WINCTRL1_PO_00
|LCD_WINCTRL1_PIPE
,
299 /* mode_winenable*/ 0/*LCD_WINENABLE_WEN2*/,
302 /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
303 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565
|
304 LCD_WINCTRL1_PO_16BPP
|
306 /* mode_winenable*/ 0,
310 /* Need VGA 640 @ 24bpp, @ 32bpp */
311 /* Need VGA 800 @ 24bpp, @ 32bpp */
312 /* Need VGA 1024 @ 24bpp, @ 32bpp */
316 * Controller configurations for various panels.
319 struct panel_settings
321 const char name
[25]; /* Full name <vendor>_<model> */
323 struct fb_monspecs monspecs
; /* FB monitor specs */
327 uint32 mode_horztiming
;
328 uint32 mode_verttiming
;
329 uint32 mode_clkcontrol
;
333 uint32 mode_fifoctrl
;
334 uint32 mode_toyclksrc
;
335 uint32 mode_backlight
;
337 int (*device_init
)(void);
338 int (*device_shutdown
)(void);
339 #define Xres min_xres
340 #define Yres min_yres
341 u32 min_xres
; /* Minimum horizontal resolution */
342 u32 max_xres
; /* Maximum horizontal resolution */
343 u32 min_yres
; /* Minimum vertical resolution */
344 u32 max_yres
; /* Maximum vertical resolution */
347 /********************************************************************/
348 /* fixme: Maybe a modedb for the CRT ? otherwise panels should be as-is */
350 /* List of panels known to work with the AU1200 LCD controller.
351 * To add a new panel, enter the same specifications as the
352 * Generic_TFT one, and MAKE SURE that it doesn't conflicts
353 * with the controller restrictions. Restrictions are:
355 * STN color panels: max_bpp <= 12
356 * STN mono panels: max_bpp <= 4
357 * TFT panels: max_bpp <= 16
361 static struct panel_settings known_lcd_panels
[] =
363 [0] = { /* QVGA 320x240 H:33.3kHz V:110Hz */
364 .name
= "QVGA_320x240",
374 .input
= FB_DISP_RGB
,
376 .mode_screen
= LCD_SCREEN_SX_N(320) |
377 LCD_SCREEN_SY_N(240),
378 .mode_horztiming
= 0x00c4623b,
379 .mode_verttiming
= 0x00502814,
380 .mode_clkcontrol
= 0x00020002, /* /4=24Mhz */
381 .mode_pwmdiv
= 0x00000000,
382 .mode_pwmhi
= 0x00000000,
383 .mode_outmask
= 0x00FFFFFF,
384 .mode_fifoctrl
= 0x2f2f2f2f,
385 .mode_toyclksrc
= 0x00000004, /* AUXPLL directly */
386 .mode_backlight
= 0x00000000,
387 .mode_auxpll
= 8, /* 96MHz AUXPLL */
389 .device_shutdown
= NULL
,
394 [1] = { /* VGA 640x480 H:30.3kHz V:58Hz */
395 .name
= "VGA_640x480",
405 .input
= FB_DISP_RGB
,
407 .mode_screen
= 0x13f9df80,
408 .mode_horztiming
= 0x003c5859,
409 .mode_verttiming
= 0x00741201,
410 .mode_clkcontrol
= 0x00020001, /* /4=24Mhz */
411 .mode_pwmdiv
= 0x00000000,
412 .mode_pwmhi
= 0x00000000,
413 .mode_outmask
= 0x00FFFFFF,
414 .mode_fifoctrl
= 0x2f2f2f2f,
415 .mode_toyclksrc
= 0x00000004, /* AUXPLL directly */
416 .mode_backlight
= 0x00000000,
417 .mode_auxpll
= 8, /* 96MHz AUXPLL */
419 .device_shutdown
= NULL
,
424 [2] = { /* SVGA 800x600 H:46.1kHz V:69Hz */
425 .name
= "SVGA_800x600",
435 .input
= FB_DISP_RGB
,
437 .mode_screen
= 0x18fa5780,
438 .mode_horztiming
= 0x00dc7e77,
439 .mode_verttiming
= 0x00584805,
440 .mode_clkcontrol
= 0x00020000, /* /2=48Mhz */
441 .mode_pwmdiv
= 0x00000000,
442 .mode_pwmhi
= 0x00000000,
443 .mode_outmask
= 0x00FFFFFF,
444 .mode_fifoctrl
= 0x2f2f2f2f,
445 .mode_toyclksrc
= 0x00000004, /* AUXPLL directly */
446 .mode_backlight
= 0x00000000,
447 .mode_auxpll
= 8, /* 96MHz AUXPLL */
449 .device_shutdown
= NULL
,
454 [3] = { /* XVGA 1024x768 H:56.2kHz V:70Hz */
455 .name
= "XVGA_1024x768",
465 .input
= FB_DISP_RGB
,
467 .mode_screen
= 0x1ffaff80,
468 .mode_horztiming
= 0x007d0e57,
469 .mode_verttiming
= 0x00740a01,
470 .mode_clkcontrol
= 0x000A0000, /* /1 */
471 .mode_pwmdiv
= 0x00000000,
472 .mode_pwmhi
= 0x00000000,
473 .mode_outmask
= 0x00FFFFFF,
474 .mode_fifoctrl
= 0x2f2f2f2f,
475 .mode_toyclksrc
= 0x00000004, /* AUXPLL directly */
476 .mode_backlight
= 0x00000000,
477 .mode_auxpll
= 6, /* 72MHz AUXPLL */
479 .device_shutdown
= NULL
,
484 [4] = { /* XVGA XVGA 1280x1024 H:68.5kHz V:65Hz */
485 .name
= "XVGA_1280x1024",
495 .input
= FB_DISP_RGB
,
497 .mode_screen
= 0x27fbff80,
498 .mode_horztiming
= 0x00cdb2c7,
499 .mode_verttiming
= 0x00600002,
500 .mode_clkcontrol
= 0x000A0000, /* /1 */
501 .mode_pwmdiv
= 0x00000000,
502 .mode_pwmhi
= 0x00000000,
503 .mode_outmask
= 0x00FFFFFF,
504 .mode_fifoctrl
= 0x2f2f2f2f,
505 .mode_toyclksrc
= 0x00000004, /* AUXPLL directly */
506 .mode_backlight
= 0x00000000,
507 .mode_auxpll
= 10, /* 120MHz AUXPLL */
509 .device_shutdown
= NULL
,
514 [5] = { /* Samsung 1024x768 TFT */
515 .name
= "Samsung_1024x768_TFT",
525 .input
= FB_DISP_RGB
,
527 .mode_screen
= 0x1ffaff80,
528 .mode_horztiming
= 0x018cc677,
529 .mode_verttiming
= 0x00241217,
530 .mode_clkcontrol
= 0x00000000, /* SCB 0x1 /4=24Mhz */
531 .mode_pwmdiv
= 0x8000063f, /* SCB 0x0 */
532 .mode_pwmhi
= 0x03400000, /* SCB 0x0 */
533 .mode_outmask
= 0x00FFFFFF,
534 .mode_fifoctrl
= 0x2f2f2f2f,
535 .mode_toyclksrc
= 0x00000004, /* AUXPLL directly */
536 .mode_backlight
= 0x00000000,
537 .mode_auxpll
= 8, /* 96MHz AUXPLL */
538 .device_init
= board_au1200fb_panel_init
,
539 .device_shutdown
= board_au1200fb_panel_shutdown
,
544 [6] = { /* Toshiba 640x480 TFT */
545 .name
= "Toshiba_640x480_TFT",
555 .input
= FB_DISP_RGB
,
557 .mode_screen
= LCD_SCREEN_SX_N(640) |
558 LCD_SCREEN_SY_N(480),
559 .mode_horztiming
= LCD_HORZTIMING_HPW_N(96) |
560 LCD_HORZTIMING_HND1_N(13) | LCD_HORZTIMING_HND2_N(51),
561 .mode_verttiming
= LCD_VERTTIMING_VPW_N(2) |
562 LCD_VERTTIMING_VND1_N(11) | LCD_VERTTIMING_VND2_N(32),
563 .mode_clkcontrol
= 0x00000000, /* /4=24Mhz */
564 .mode_pwmdiv
= 0x8000063f,
565 .mode_pwmhi
= 0x03400000,
566 .mode_outmask
= 0x00fcfcfc,
567 .mode_fifoctrl
= 0x2f2f2f2f,
568 .mode_toyclksrc
= 0x00000004, /* AUXPLL directly */
569 .mode_backlight
= 0x00000000,
570 .mode_auxpll
= 8, /* 96MHz AUXPLL */
571 .device_init
= board_au1200fb_panel_init
,
572 .device_shutdown
= board_au1200fb_panel_shutdown
,
577 [7] = { /* Sharp 320x240 TFT */
578 .name
= "Sharp_320x240_TFT",
588 .input
= FB_DISP_RGB
,
590 .mode_screen
= LCD_SCREEN_SX_N(320) |
591 LCD_SCREEN_SY_N(240),
592 .mode_horztiming
= LCD_HORZTIMING_HPW_N(60) |
593 LCD_HORZTIMING_HND1_N(13) | LCD_HORZTIMING_HND2_N(2),
594 .mode_verttiming
= LCD_VERTTIMING_VPW_N(2) |
595 LCD_VERTTIMING_VND1_N(2) | LCD_VERTTIMING_VND2_N(5),
596 .mode_clkcontrol
= LCD_CLKCONTROL_PCD_N(7), /*16=6Mhz*/
597 .mode_pwmdiv
= 0x8000063f,
598 .mode_pwmhi
= 0x03400000,
599 .mode_outmask
= 0x00fcfcfc,
600 .mode_fifoctrl
= 0x2f2f2f2f,
601 .mode_toyclksrc
= 0x00000004, /* AUXPLL directly */
602 .mode_backlight
= 0x00000000,
603 .mode_auxpll
= 8, /* 96MHz AUXPLL */
604 .device_init
= board_au1200fb_panel_init
,
605 .device_shutdown
= board_au1200fb_panel_shutdown
,
610 [8] = { /* Toppoly TD070WGCB2 7" 856x480 TFT */
611 .name
= "Toppoly_TD070WGCB2",
621 .input
= FB_DISP_RGB
,
623 .mode_screen
= LCD_SCREEN_SX_N(856) |
624 LCD_SCREEN_SY_N(480),
625 .mode_horztiming
= LCD_HORZTIMING_HND2_N(43) |
626 LCD_HORZTIMING_HND1_N(43) | LCD_HORZTIMING_HPW_N(114),
627 .mode_verttiming
= LCD_VERTTIMING_VND2_N(20) |
628 LCD_VERTTIMING_VND1_N(21) | LCD_VERTTIMING_VPW_N(4),
629 .mode_clkcontrol
= 0x00020001, /* /4=24Mhz */
630 .mode_pwmdiv
= 0x8000063f,
631 .mode_pwmhi
= 0x03400000,
632 .mode_outmask
= 0x00fcfcfc,
633 .mode_fifoctrl
= 0x2f2f2f2f,
634 .mode_toyclksrc
= 0x00000004, /* AUXPLL directly */
635 .mode_backlight
= 0x00000000,
636 .mode_auxpll
= 8, /* 96MHz AUXPLL */
637 .device_init
= board_au1200fb_panel_init
,
638 .device_shutdown
= board_au1200fb_panel_shutdown
,
644 #define NUM_PANELS (ARRAY_SIZE(known_lcd_panels))
646 /********************************************************************/
648 static int winbpp (unsigned int winctrl1
)
652 /* how many bits are needed for each pixel format */
653 switch (winctrl1
& LCD_WINCTRL1_FRM
) {
654 case LCD_WINCTRL1_FRM_1BPP
:
657 case LCD_WINCTRL1_FRM_2BPP
:
660 case LCD_WINCTRL1_FRM_4BPP
:
663 case LCD_WINCTRL1_FRM_8BPP
:
666 case LCD_WINCTRL1_FRM_12BPP
:
667 case LCD_WINCTRL1_FRM_16BPP655
:
668 case LCD_WINCTRL1_FRM_16BPP565
:
669 case LCD_WINCTRL1_FRM_16BPP556
:
670 case LCD_WINCTRL1_FRM_16BPPI1555
:
671 case LCD_WINCTRL1_FRM_16BPPI5551
:
672 case LCD_WINCTRL1_FRM_16BPPA1555
:
673 case LCD_WINCTRL1_FRM_16BPPA5551
:
676 case LCD_WINCTRL1_FRM_24BPP
:
677 case LCD_WINCTRL1_FRM_32BPP
:
685 static int fbinfo2index (struct fb_info
*fb_info
)
689 for (i
= 0; i
< device_count
; ++i
) {
690 if (fb_info
== _au1200fb_infos
[i
])
693 printk("au1200fb: ERROR: fbinfo2index failed!\n");
697 static int au1200_setlocation (struct au1200fb_device
*fbdev
, int plane
,
700 uint32 winctrl0
, winctrl1
, winenable
, fb_offset
= 0;
703 /* FIX!!! NOT CHECKING FOR COMPLETE OFFSCREEN YET */
705 winctrl0
= lcd
->window
[plane
].winctrl0
;
706 winctrl1
= lcd
->window
[plane
].winctrl1
;
707 winctrl0
&= (LCD_WINCTRL0_A
| LCD_WINCTRL0_AEN
);
708 winctrl1
&= ~(LCD_WINCTRL1_SZX
| LCD_WINCTRL1_SZY
);
710 /* Check for off-screen adjustments */
711 xsz
= win
->w
[plane
].xres
;
712 ysz
= win
->w
[plane
].yres
;
713 if ((xpos
+ win
->w
[plane
].xres
) > panel
->Xres
) {
714 /* Off-screen to the right */
715 xsz
= panel
->Xres
- xpos
; /* off by 1 ??? */
716 /*printk("off screen right\n");*/
719 if ((ypos
+ win
->w
[plane
].yres
) > panel
->Yres
) {
720 /* Off-screen to the bottom */
721 ysz
= panel
->Yres
- ypos
; /* off by 1 ??? */
722 /*printk("off screen bottom\n");*/
726 /* Off-screen to the left */
727 xsz
= win
->w
[plane
].xres
+ xpos
;
728 fb_offset
+= (((0 - xpos
) * winbpp(lcd
->window
[plane
].winctrl1
))/8);
730 /*printk("off screen left\n");*/
734 /* Off-screen to the top */
735 ysz
= win
->w
[plane
].yres
+ ypos
;
736 /* fixme: fb_offset += ((0-ypos)*fb_pars[plane].line_length); */
738 /*printk("off screen top\n");*/
741 /* record settings */
742 win
->w
[plane
].xpos
= xpos
;
743 win
->w
[plane
].ypos
= ypos
;
747 winctrl0
|= (xpos
<< 21);
748 winctrl0
|= (ypos
<< 10);
749 winctrl1
|= (xsz
<< 11);
750 winctrl1
|= (ysz
<< 0);
752 /* Disable the window while making changes, then restore WINEN */
753 winenable
= lcd
->winenable
& (1 << plane
);
755 lcd
->winenable
&= ~(1 << plane
);
756 lcd
->window
[plane
].winctrl0
= winctrl0
;
757 lcd
->window
[plane
].winctrl1
= winctrl1
;
758 lcd
->window
[plane
].winbuf0
=
759 lcd
->window
[plane
].winbuf1
= fbdev
->fb_phys
;
760 lcd
->window
[plane
].winbufctrl
= 0; /* select winbuf0 */
761 lcd
->winenable
|= winenable
;
767 static void au1200_setpanel (struct panel_settings
*newpanel
)
770 * Perform global setup/init of LCD controller
774 /* Make sure all windows disabled */
775 winenable
= lcd
->winenable
;
779 * Ensure everything is disabled before reconfiguring
781 if (lcd
->screen
& LCD_SCREEN_SEN
) {
782 /* Wait for vertical sync period */
783 lcd
->intstatus
= LCD_INT_SS
;
784 while ((lcd
->intstatus
& LCD_INT_SS
) == 0) {
788 lcd
->screen
&= ~LCD_SCREEN_SEN
; /*disable the controller*/
791 lcd
->intstatus
= lcd
->intstatus
; /*clear interrupts*/
793 /*wait for controller to shut down*/
794 } while ((lcd
->intstatus
& LCD_INT_SD
) == 0);
796 /* Call shutdown of current panel (if up) */
797 /* this must occur last, because if an external clock is driving
798 the controller, the clock cannot be turned off before first
799 shutting down the controller.
801 if (panel
->device_shutdown
!= NULL
)
802 panel
->device_shutdown();
805 /* Newpanel == NULL indicates a shutdown operation only */
806 if (newpanel
== NULL
)
811 printk("Panel(%s), %dx%d\n", panel
->name
, panel
->Xres
, panel
->Yres
);
814 * Setup clocking if internal LCD clock source (assumes sys_auxpll valid)
816 if (!(panel
->mode_clkcontrol
& LCD_CLKCONTROL_EXT
))
819 au_writel(panel
->mode_auxpll
, SYS_AUXPLL
);
820 sys_clksrc
= au_readl(SYS_CLKSRC
) & ~0x0000001f;
821 sys_clksrc
|= panel
->mode_toyclksrc
;
822 au_writel(sys_clksrc
, SYS_CLKSRC
);
826 * Configure panel timings
828 lcd
->screen
= panel
->mode_screen
;
829 lcd
->horztiming
= panel
->mode_horztiming
;
830 lcd
->verttiming
= panel
->mode_verttiming
;
831 lcd
->clkcontrol
= panel
->mode_clkcontrol
;
832 lcd
->pwmdiv
= panel
->mode_pwmdiv
;
833 lcd
->pwmhi
= panel
->mode_pwmhi
;
834 lcd
->outmask
= panel
->mode_outmask
;
835 lcd
->fifoctrl
= panel
->mode_fifoctrl
;
838 /* fixme: Check window settings to make sure still valid
839 * for new geometry */
841 au1200_setlocation(fbdev
, 0, win
->w
[0].xpos
, win
->w
[0].ypos
);
842 au1200_setlocation(fbdev
, 1, win
->w
[1].xpos
, win
->w
[1].ypos
);
843 au1200_setlocation(fbdev
, 2, win
->w
[2].xpos
, win
->w
[2].ypos
);
844 au1200_setlocation(fbdev
, 3, win
->w
[3].xpos
, win
->w
[3].ypos
);
846 lcd
->winenable
= winenable
;
849 * Re-enable screen now that it is configured
851 lcd
->screen
|= LCD_SCREEN_SEN
;
854 /* Call init of panel */
855 if (panel
->device_init
!= NULL
) panel
->device_init();
857 /* FIX!!!! not appropriate on panel change!!! Global setup/init */
860 lcd
->backcolor
= win
->mode_backcolor
;
862 /* Setup Color Key - FIX!!! */
863 lcd
->colorkey
= win
->mode_colorkey
;
864 lcd
->colorkeymsk
= win
->mode_colorkeymsk
;
866 /* Setup HWCursor - FIX!!! Need to support this eventually */
867 lcd
->hwc
.cursorctrl
= 0;
868 lcd
->hwc
.cursorpos
= 0;
869 lcd
->hwc
.cursorcolor0
= 0;
870 lcd
->hwc
.cursorcolor1
= 0;
871 lcd
->hwc
.cursorcolor2
= 0;
872 lcd
->hwc
.cursorcolor3
= 0;
876 #define D(X) printk("%25s: %08X\n", #X, X)
885 D(lcd
->window
[0].winctrl0
);
886 D(lcd
->window
[0].winctrl1
);
887 D(lcd
->window
[0].winctrl2
);
888 D(lcd
->window
[0].winbuf0
);
889 D(lcd
->window
[0].winbuf1
);
890 D(lcd
->window
[0].winbufctrl
);
891 D(lcd
->window
[1].winctrl0
);
892 D(lcd
->window
[1].winctrl1
);
893 D(lcd
->window
[1].winctrl2
);
894 D(lcd
->window
[1].winbuf0
);
895 D(lcd
->window
[1].winbuf1
);
896 D(lcd
->window
[1].winbufctrl
);
897 D(lcd
->window
[2].winctrl0
);
898 D(lcd
->window
[2].winctrl1
);
899 D(lcd
->window
[2].winctrl2
);
900 D(lcd
->window
[2].winbuf0
);
901 D(lcd
->window
[2].winbuf1
);
902 D(lcd
->window
[2].winbufctrl
);
903 D(lcd
->window
[3].winctrl0
);
904 D(lcd
->window
[3].winctrl1
);
905 D(lcd
->window
[3].winctrl2
);
906 D(lcd
->window
[3].winbuf0
);
907 D(lcd
->window
[3].winbuf1
);
908 D(lcd
->window
[3].winbufctrl
);
916 D(lcd
->hwc
.cursorctrl
);
917 D(lcd
->hwc
.cursorpos
);
918 D(lcd
->hwc
.cursorcolor0
);
919 D(lcd
->hwc
.cursorcolor1
);
920 D(lcd
->hwc
.cursorcolor2
);
921 D(lcd
->hwc
.cursorcolor3
);
925 static void au1200_setmode(struct au1200fb_device
*fbdev
)
927 int plane
= fbdev
->plane
;
928 /* Window/plane setup */
929 lcd
->window
[plane
].winctrl1
= ( 0
930 | LCD_WINCTRL1_PRI_N(plane
)
931 | win
->w
[plane
].mode_winctrl1
/* FRM,CCO,PO,PIPE */
934 au1200_setlocation(fbdev
, plane
, win
->w
[plane
].xpos
, win
->w
[plane
].ypos
);
936 lcd
->window
[plane
].winctrl2
= ( 0
937 | LCD_WINCTRL2_CKMODE_00
939 | LCD_WINCTRL2_BX_N(fbdev
->fb_info
->fix
.line_length
)
943 lcd
->winenable
|= win
->w
[plane
].mode_winenable
;
950 /*#define panel_is_dual(panel) ((panel->mode_screen & LCD_SCREEN_PT) == LCD_SCREEN_PT_010)*/
951 /*#define panel_is_active(panel)((panel->mode_screen & LCD_SCREEN_PT) == LCD_SCREEN_PT_010)*/
953 #define panel_is_color(panel) ((panel->mode_screen & LCD_SCREEN_PT) <= LCD_SCREEN_PT_CDSTN)
955 /* Bitfields format supported by the controller. */
956 static struct fb_bitfield rgb_bitfields
[][4] = {
957 /* Red, Green, Blue, Transp */
958 [LCD_WINCTRL1_FRM_16BPP655
>> 25] =
959 { { 10, 6, 0 }, { 5, 5, 0 }, { 0, 5, 0 }, { 0, 0, 0 } },
961 [LCD_WINCTRL1_FRM_16BPP565
>> 25] =
962 { { 11, 5, 0 }, { 5, 6, 0 }, { 0, 5, 0 }, { 0, 0, 0 } },
964 [LCD_WINCTRL1_FRM_16BPP556
>> 25] =
965 { { 11, 5, 0 }, { 6, 5, 0 }, { 0, 6, 0 }, { 0, 0, 0 } },
967 [LCD_WINCTRL1_FRM_16BPPI1555
>> 25] =
968 { { 10, 5, 0 }, { 5, 5, 0 }, { 0, 5, 0 }, { 0, 0, 0 } },
970 [LCD_WINCTRL1_FRM_16BPPI5551
>> 25] =
971 { { 11, 5, 0 }, { 6, 5, 0 }, { 1, 5, 0 }, { 0, 0, 0 } },
973 [LCD_WINCTRL1_FRM_16BPPA1555
>> 25] =
974 { { 10, 5, 0 }, { 5, 5, 0 }, { 0, 5, 0 }, { 15, 1, 0 } },
976 [LCD_WINCTRL1_FRM_16BPPA5551
>> 25] =
977 { { 11, 5, 0 }, { 6, 5, 0 }, { 1, 5, 0 }, { 0, 1, 0 } },
979 [LCD_WINCTRL1_FRM_24BPP
>> 25] =
980 { { 16, 8, 0 }, { 8, 8, 0 }, { 0, 8, 0 }, { 0, 0, 0 } },
982 [LCD_WINCTRL1_FRM_32BPP
>> 25] =
983 { { 16, 8, 0 }, { 8, 8, 0 }, { 0, 8, 0 }, { 24, 0, 0 } },
986 /*-------------------------------------------------------------------------*/
990 static void au1200fb_update_fbinfo(struct fb_info
*fbi
)
992 /* FIX!!!! This also needs to take the window pixel format into account!!! */
994 /* Update var-dependent FB info */
995 if (panel_is_color(panel
)) {
996 if (fbi
->var
.bits_per_pixel
<= 8) {
998 fbi
->fix
.visual
= FB_VISUAL_PSEUDOCOLOR
;
999 fbi
->fix
.line_length
= fbi
->var
.xres_virtual
/
1000 (8/fbi
->var
.bits_per_pixel
);
1002 /* non-palettized */
1003 fbi
->fix
.visual
= FB_VISUAL_TRUECOLOR
;
1004 fbi
->fix
.line_length
= fbi
->var
.xres_virtual
* (fbi
->var
.bits_per_pixel
/ 8);
1007 /* mono FIX!!! mono 8 and 4 bits */
1008 fbi
->fix
.visual
= FB_VISUAL_MONO10
;
1009 fbi
->fix
.line_length
= fbi
->var
.xres_virtual
/ 8;
1012 fbi
->screen_size
= fbi
->fix
.line_length
* fbi
->var
.yres_virtual
;
1013 print_dbg("line length: %d\n", fbi
->fix
.line_length
);
1014 print_dbg("bits_per_pixel: %d\n", fbi
->var
.bits_per_pixel
);
1017 /*-------------------------------------------------------------------------*/
1019 /* AU1200 framebuffer driver */
1022 * Validate var settings with hardware restrictions and modify it if necessary
1024 static int au1200fb_fb_check_var(struct fb_var_screeninfo
*var
,
1025 struct fb_info
*fbi
)
1027 struct au1200fb_device
*fbdev
= fbi
->par
;
1029 int screen_size
, plane
;
1031 plane
= fbdev
->plane
;
1033 /* Make sure that the mode respect all LCD controller and
1034 * panel restrictions. */
1035 var
->xres
= win
->w
[plane
].xres
;
1036 var
->yres
= win
->w
[plane
].yres
;
1038 /* No need for virtual resolution support */
1039 var
->xres_virtual
= var
->xres
;
1040 var
->yres_virtual
= var
->yres
;
1042 var
->bits_per_pixel
= winbpp(win
->w
[plane
].mode_winctrl1
);
1044 screen_size
= var
->xres_virtual
* var
->yres_virtual
;
1045 if (var
->bits_per_pixel
> 8) screen_size
*= (var
->bits_per_pixel
/ 8);
1046 else screen_size
/= (8/var
->bits_per_pixel
);
1048 if (fbdev
->fb_len
< screen_size
)
1049 return -EINVAL
; /* Virtual screen is to big, abort */
1051 /* FIX!!!! what are the implicaitons of ignoring this for windows ??? */
1052 /* The max LCD clock is fixed to 48MHz (value of AUX_CLK). The pixel
1053 * clock can only be obtain by dividing this value by an even integer.
1054 * Fallback to a slower pixel clock if necessary. */
1055 pixclock
= max((u32
)(PICOS2KHZ(var
->pixclock
) * 1000), fbi
->monspecs
.dclkmin
);
1056 pixclock
= min3(pixclock
, fbi
->monspecs
.dclkmax
, (u32
)AU1200_LCD_MAX_CLK
/2);
1058 if (AU1200_LCD_MAX_CLK
% pixclock
) {
1059 int diff
= AU1200_LCD_MAX_CLK
% pixclock
;
1063 var
->pixclock
= KHZ2PICOS(pixclock
/1000);
1065 if (!panel_is_active(panel
)) {
1066 int pcd
= AU1200_LCD_MAX_CLK
/ (pixclock
* 2) - 1;
1068 if (!panel_is_color(panel
)
1069 && (panel
->control_base
& LCD_CONTROL_MPI
) && (pcd
< 3)) {
1070 /* STN 8bit mono panel support is up to 6MHz pixclock */
1071 var
->pixclock
= KHZ2PICOS(6000);
1073 /* Other STN panel support is up to 12MHz */
1074 var
->pixclock
= KHZ2PICOS(12000);
1078 /* Set bitfield accordingly */
1079 switch (var
->bits_per_pixel
) {
1082 /* 16bpp True color.
1083 * These must be set to MATCH WINCTRL[FORM] */
1085 idx
= (win
->w
[0].mode_winctrl1
& LCD_WINCTRL1_FRM
) >> 25;
1086 var
->red
= rgb_bitfields
[idx
][0];
1087 var
->green
= rgb_bitfields
[idx
][1];
1088 var
->blue
= rgb_bitfields
[idx
][2];
1089 var
->transp
= rgb_bitfields
[idx
][3];
1095 /* 32bpp True color.
1096 * These must be set to MATCH WINCTRL[FORM] */
1098 idx
= (win
->w
[0].mode_winctrl1
& LCD_WINCTRL1_FRM
) >> 25;
1099 var
->red
= rgb_bitfields
[idx
][0];
1100 var
->green
= rgb_bitfields
[idx
][1];
1101 var
->blue
= rgb_bitfields
[idx
][2];
1102 var
->transp
= rgb_bitfields
[idx
][3];
1106 print_dbg("Unsupported depth %dbpp", var
->bits_per_pixel
);
1114 * Set hardware with var settings. This will enable the controller with a
1115 * specific mode, normally validated with the fb_check_var method
1117 static int au1200fb_fb_set_par(struct fb_info
*fbi
)
1119 struct au1200fb_device
*fbdev
= fbi
->par
;
1121 au1200fb_update_fbinfo(fbi
);
1122 au1200_setmode(fbdev
);
1128 * Set color in LCD palette.
1130 static int au1200fb_fb_setcolreg(unsigned regno
, unsigned red
, unsigned green
,
1131 unsigned blue
, unsigned transp
, struct fb_info
*fbi
)
1133 volatile u32
*palette
= lcd
->palette
;
1136 if (regno
> (AU1200_LCD_NBR_PALETTE_ENTRIES
- 1))
1139 if (fbi
->var
.grayscale
) {
1140 /* Convert color to grayscale */
1141 red
= green
= blue
=
1142 (19595 * red
+ 38470 * green
+ 7471 * blue
) >> 16;
1145 if (fbi
->fix
.visual
== FB_VISUAL_TRUECOLOR
) {
1146 /* Place color in the pseudopalette */
1150 palette
= (u32
*) fbi
->pseudo_palette
;
1152 red
>>= (16 - fbi
->var
.red
.length
);
1153 green
>>= (16 - fbi
->var
.green
.length
);
1154 blue
>>= (16 - fbi
->var
.blue
.length
);
1156 value
= (red
<< fbi
->var
.red
.offset
) |
1157 (green
<< fbi
->var
.green
.offset
)|
1158 (blue
<< fbi
->var
.blue
.offset
);
1161 } else if (1 /*FIX!!! panel_is_active(fbdev->panel)*/) {
1162 /* COLOR TFT PALLETTIZED (use RGB 565) */
1163 value
= (red
& 0xF800)|((green
>> 5) &
1164 0x07E0)|((blue
>> 11) & 0x001F);
1167 } else if (0 /*panel_is_color(fbdev->panel)*/) {
1168 /* COLOR STN MODE */
1172 /* MONOCHROME MODE */
1173 value
= (green
>> 12) & 0x000F;
1177 palette
[regno
] = value
;
1183 * Blank the screen. Depending on the mode, the screen will be
1184 * activated with the backlight color, or desactivated
1186 static int au1200fb_fb_blank(int blank_mode
, struct fb_info
*fbi
)
1188 /* Short-circuit screen blanking */
1192 switch (blank_mode
) {
1194 case FB_BLANK_UNBLANK
:
1195 case FB_BLANK_NORMAL
:
1196 /* printk("turn on panel\n"); */
1197 au1200_setpanel(panel
);
1199 case FB_BLANK_VSYNC_SUSPEND
:
1200 case FB_BLANK_HSYNC_SUSPEND
:
1201 case FB_BLANK_POWERDOWN
:
1202 /* printk("turn off panel\n"); */
1203 au1200_setpanel(NULL
);
1210 /* FB_BLANK_NORMAL is a soft blank */
1211 return (blank_mode
== FB_BLANK_NORMAL
) ? -EINVAL
: 0;
1215 * Map video memory in user space. We don't use the generic fb_mmap
1216 * method mainly to allow the use of the TLB streaming flag (CCA=6)
1218 static int au1200fb_fb_mmap(struct fb_info
*info
, struct vm_area_struct
*vma
)
1222 unsigned long start
=0, off
;
1223 struct au1200fb_device
*fbdev
= info
->par
;
1225 if (vma
->vm_pgoff
> (~0UL >> PAGE_SHIFT
)) {
1229 start
= fbdev
->fb_phys
& PAGE_MASK
;
1230 len
= PAGE_ALIGN((start
& ~PAGE_MASK
) + fbdev
->fb_len
);
1232 off
= vma
->vm_pgoff
<< PAGE_SHIFT
;
1234 if ((vma
->vm_end
- vma
->vm_start
+ off
) > len
) {
1239 vma
->vm_pgoff
= off
>> PAGE_SHIFT
;
1241 vma
->vm_page_prot
= pgprot_noncached(vma
->vm_page_prot
);
1242 pgprot_val(vma
->vm_page_prot
) |= _CACHE_MASK
; /* CCA=7 */
1244 vma
->vm_flags
|= VM_IO
;
1246 return io_remap_pfn_range(vma
, vma
->vm_start
, off
>> PAGE_SHIFT
,
1247 vma
->vm_end
- vma
->vm_start
,
1253 static void set_global(u_int cmd
, struct au1200_lcd_global_regs_t
*pdata
)
1256 unsigned int hi1
, divider
;
1258 /* SCREEN_SIZE: user cannot reset size, must switch panel choice */
1260 if (pdata
->flags
& SCREEN_BACKCOLOR
)
1261 lcd
->backcolor
= pdata
->backcolor
;
1263 if (pdata
->flags
& SCREEN_BRIGHTNESS
) {
1265 // limit brightness pwm duty to >= 30/1600
1266 if (pdata
->brightness
< 30) {
1267 pdata
->brightness
= 30;
1269 divider
= (lcd
->pwmdiv
& 0x3FFFF) + 1;
1270 hi1
= (lcd
->pwmhi
>> 16) + 1;
1271 hi1
= (((pdata
->brightness
& 0xFF)+1) * divider
>> 8);
1272 lcd
->pwmhi
&= 0xFFFF;
1273 lcd
->pwmhi
|= (hi1
<< 16);
1276 if (pdata
->flags
& SCREEN_COLORKEY
)
1277 lcd
->colorkey
= pdata
->colorkey
;
1279 if (pdata
->flags
& SCREEN_MASK
)
1280 lcd
->colorkeymsk
= pdata
->mask
;
1284 static void get_global(u_int cmd
, struct au1200_lcd_global_regs_t
*pdata
)
1286 unsigned int hi1
, divider
;
1288 pdata
->xsize
= ((lcd
->screen
& LCD_SCREEN_SX
) >> 19) + 1;
1289 pdata
->ysize
= ((lcd
->screen
& LCD_SCREEN_SY
) >> 8) + 1;
1291 pdata
->backcolor
= lcd
->backcolor
;
1292 pdata
->colorkey
= lcd
->colorkey
;
1293 pdata
->mask
= lcd
->colorkeymsk
;
1296 hi1
= (lcd
->pwmhi
>> 16) + 1;
1297 divider
= (lcd
->pwmdiv
& 0x3FFFF) + 1;
1298 pdata
->brightness
= ((hi1
<< 8) / divider
) - 1;
1302 static void set_window(unsigned int plane
,
1303 struct au1200_lcd_window_regs_t
*pdata
)
1305 unsigned int val
, bpp
;
1307 /* Window control register 0 */
1308 if (pdata
->flags
& WIN_POSITION
) {
1309 val
= lcd
->window
[plane
].winctrl0
& ~(LCD_WINCTRL0_OX
|
1311 val
|= ((pdata
->xpos
<< 21) & LCD_WINCTRL0_OX
);
1312 val
|= ((pdata
->ypos
<< 10) & LCD_WINCTRL0_OY
);
1313 lcd
->window
[plane
].winctrl0
= val
;
1315 if (pdata
->flags
& WIN_ALPHA_COLOR
) {
1316 val
= lcd
->window
[plane
].winctrl0
& ~(LCD_WINCTRL0_A
);
1317 val
|= ((pdata
->alpha_color
<< 2) & LCD_WINCTRL0_A
);
1318 lcd
->window
[plane
].winctrl0
= val
;
1320 if (pdata
->flags
& WIN_ALPHA_MODE
) {
1321 val
= lcd
->window
[plane
].winctrl0
& ~(LCD_WINCTRL0_AEN
);
1322 val
|= ((pdata
->alpha_mode
<< 1) & LCD_WINCTRL0_AEN
);
1323 lcd
->window
[plane
].winctrl0
= val
;
1326 /* Window control register 1 */
1327 if (pdata
->flags
& WIN_PRIORITY
) {
1328 val
= lcd
->window
[plane
].winctrl1
& ~(LCD_WINCTRL1_PRI
);
1329 val
|= ((pdata
->priority
<< 30) & LCD_WINCTRL1_PRI
);
1330 lcd
->window
[plane
].winctrl1
= val
;
1332 if (pdata
->flags
& WIN_CHANNEL
) {
1333 val
= lcd
->window
[plane
].winctrl1
& ~(LCD_WINCTRL1_PIPE
);
1334 val
|= ((pdata
->channel
<< 29) & LCD_WINCTRL1_PIPE
);
1335 lcd
->window
[plane
].winctrl1
= val
;
1337 if (pdata
->flags
& WIN_BUFFER_FORMAT
) {
1338 val
= lcd
->window
[plane
].winctrl1
& ~(LCD_WINCTRL1_FRM
);
1339 val
|= ((pdata
->buffer_format
<< 25) & LCD_WINCTRL1_FRM
);
1340 lcd
->window
[plane
].winctrl1
= val
;
1342 if (pdata
->flags
& WIN_COLOR_ORDER
) {
1343 val
= lcd
->window
[plane
].winctrl1
& ~(LCD_WINCTRL1_CCO
);
1344 val
|= ((pdata
->color_order
<< 24) & LCD_WINCTRL1_CCO
);
1345 lcd
->window
[plane
].winctrl1
= val
;
1347 if (pdata
->flags
& WIN_PIXEL_ORDER
) {
1348 val
= lcd
->window
[plane
].winctrl1
& ~(LCD_WINCTRL1_PO
);
1349 val
|= ((pdata
->pixel_order
<< 22) & LCD_WINCTRL1_PO
);
1350 lcd
->window
[plane
].winctrl1
= val
;
1352 if (pdata
->flags
& WIN_SIZE
) {
1353 val
= lcd
->window
[plane
].winctrl1
& ~(LCD_WINCTRL1_SZX
|
1355 val
|= (((pdata
->xsize
<< 11) - 1) & LCD_WINCTRL1_SZX
);
1356 val
|= (((pdata
->ysize
) - 1) & LCD_WINCTRL1_SZY
);
1357 lcd
->window
[plane
].winctrl1
= val
;
1358 /* program buffer line width */
1359 bpp
= winbpp(val
) / 8;
1360 val
= lcd
->window
[plane
].winctrl2
& ~(LCD_WINCTRL2_BX
);
1361 val
|= (((pdata
->xsize
* bpp
) << 8) & LCD_WINCTRL2_BX
);
1362 lcd
->window
[plane
].winctrl2
= val
;
1365 /* Window control register 2 */
1366 if (pdata
->flags
& WIN_COLORKEY_MODE
) {
1367 val
= lcd
->window
[plane
].winctrl2
& ~(LCD_WINCTRL2_CKMODE
);
1368 val
|= ((pdata
->colorkey_mode
<< 24) & LCD_WINCTRL2_CKMODE
);
1369 lcd
->window
[plane
].winctrl2
= val
;
1371 if (pdata
->flags
& WIN_DOUBLE_BUFFER_MODE
) {
1372 val
= lcd
->window
[plane
].winctrl2
& ~(LCD_WINCTRL2_DBM
);
1373 val
|= ((pdata
->double_buffer_mode
<< 23) & LCD_WINCTRL2_DBM
);
1374 lcd
->window
[plane
].winctrl2
= val
;
1376 if (pdata
->flags
& WIN_RAM_ARRAY_MODE
) {
1377 val
= lcd
->window
[plane
].winctrl2
& ~(LCD_WINCTRL2_RAM
);
1378 val
|= ((pdata
->ram_array_mode
<< 21) & LCD_WINCTRL2_RAM
);
1379 lcd
->window
[plane
].winctrl2
= val
;
1382 /* Buffer line width programmed with WIN_SIZE */
1384 if (pdata
->flags
& WIN_BUFFER_SCALE
) {
1385 val
= lcd
->window
[plane
].winctrl2
& ~(LCD_WINCTRL2_SCX
|
1387 val
|= ((pdata
->xsize
<< 11) & LCD_WINCTRL2_SCX
);
1388 val
|= ((pdata
->ysize
) & LCD_WINCTRL2_SCY
);
1389 lcd
->window
[plane
].winctrl2
= val
;
1392 if (pdata
->flags
& WIN_ENABLE
) {
1393 val
= lcd
->winenable
;
1395 val
|= (pdata
->enable
& 1) << plane
;
1396 lcd
->winenable
= val
;
1401 static void get_window(unsigned int plane
,
1402 struct au1200_lcd_window_regs_t
*pdata
)
1404 /* Window control register 0 */
1405 pdata
->xpos
= (lcd
->window
[plane
].winctrl0
& LCD_WINCTRL0_OX
) >> 21;
1406 pdata
->ypos
= (lcd
->window
[plane
].winctrl0
& LCD_WINCTRL0_OY
) >> 10;
1407 pdata
->alpha_color
= (lcd
->window
[plane
].winctrl0
& LCD_WINCTRL0_A
) >> 2;
1408 pdata
->alpha_mode
= (lcd
->window
[plane
].winctrl0
& LCD_WINCTRL0_AEN
) >> 1;
1410 /* Window control register 1 */
1411 pdata
->priority
= (lcd
->window
[plane
].winctrl1
& LCD_WINCTRL1_PRI
) >> 30;
1412 pdata
->channel
= (lcd
->window
[plane
].winctrl1
& LCD_WINCTRL1_PIPE
) >> 29;
1413 pdata
->buffer_format
= (lcd
->window
[plane
].winctrl1
& LCD_WINCTRL1_FRM
) >> 25;
1414 pdata
->color_order
= (lcd
->window
[plane
].winctrl1
& LCD_WINCTRL1_CCO
) >> 24;
1415 pdata
->pixel_order
= (lcd
->window
[plane
].winctrl1
& LCD_WINCTRL1_PO
) >> 22;
1416 pdata
->xsize
= ((lcd
->window
[plane
].winctrl1
& LCD_WINCTRL1_SZX
) >> 11) + 1;
1417 pdata
->ysize
= (lcd
->window
[plane
].winctrl1
& LCD_WINCTRL1_SZY
) + 1;
1419 /* Window control register 2 */
1420 pdata
->colorkey_mode
= (lcd
->window
[plane
].winctrl2
& LCD_WINCTRL2_CKMODE
) >> 24;
1421 pdata
->double_buffer_mode
= (lcd
->window
[plane
].winctrl2
& LCD_WINCTRL2_DBM
) >> 23;
1422 pdata
->ram_array_mode
= (lcd
->window
[plane
].winctrl2
& LCD_WINCTRL2_RAM
) >> 21;
1424 pdata
->enable
= (lcd
->winenable
>> plane
) & 1;
1428 static int au1200fb_ioctl(struct fb_info
*info
, unsigned int cmd
,
1434 plane
= fbinfo2index(info
);
1435 print_dbg("au1200fb: ioctl %d on plane %d\n", cmd
, plane
);
1437 if (cmd
== AU1200_LCD_FB_IOCTL
) {
1438 struct au1200_lcd_iodata_t iodata
;
1440 if (copy_from_user(&iodata
, (void __user
*) arg
, sizeof(iodata
)))
1443 print_dbg("FB IOCTL called\n");
1445 switch (iodata
.subcmd
) {
1446 case AU1200_LCD_SET_SCREEN
:
1447 print_dbg("AU1200_LCD_SET_SCREEN\n");
1448 set_global(cmd
, &iodata
.global
);
1451 case AU1200_LCD_GET_SCREEN
:
1452 print_dbg("AU1200_LCD_GET_SCREEN\n");
1453 get_global(cmd
, &iodata
.global
);
1456 case AU1200_LCD_SET_WINDOW
:
1457 print_dbg("AU1200_LCD_SET_WINDOW\n");
1458 set_window(plane
, &iodata
.window
);
1461 case AU1200_LCD_GET_WINDOW
:
1462 print_dbg("AU1200_LCD_GET_WINDOW\n");
1463 get_window(plane
, &iodata
.window
);
1466 case AU1200_LCD_SET_PANEL
:
1467 print_dbg("AU1200_LCD_SET_PANEL\n");
1468 if ((iodata
.global
.panel_choice
>= 0) &&
1469 (iodata
.global
.panel_choice
<
1472 struct panel_settings
*newpanel
;
1473 panel_index
= iodata
.global
.panel_choice
;
1474 newpanel
= &known_lcd_panels
[panel_index
];
1475 au1200_setpanel(newpanel
);
1479 case AU1200_LCD_GET_PANEL
:
1480 print_dbg("AU1200_LCD_GET_PANEL\n");
1481 iodata
.global
.panel_choice
= panel_index
;
1488 val
= copy_to_user((void __user
*) arg
, &iodata
, sizeof(iodata
));
1490 print_dbg("error: could not copy %d bytes\n", val
);
1499 static struct fb_ops au1200fb_fb_ops
= {
1500 .owner
= THIS_MODULE
,
1501 .fb_check_var
= au1200fb_fb_check_var
,
1502 .fb_set_par
= au1200fb_fb_set_par
,
1503 .fb_setcolreg
= au1200fb_fb_setcolreg
,
1504 .fb_blank
= au1200fb_fb_blank
,
1505 .fb_fillrect
= sys_fillrect
,
1506 .fb_copyarea
= sys_copyarea
,
1507 .fb_imageblit
= sys_imageblit
,
1508 .fb_read
= fb_sys_read
,
1509 .fb_write
= fb_sys_write
,
1511 .fb_ioctl
= au1200fb_ioctl
,
1512 .fb_mmap
= au1200fb_fb_mmap
,
1515 /*-------------------------------------------------------------------------*/
1517 static irqreturn_t
au1200fb_handle_irq(int irq
, void* dev_id
)
1519 /* Nothing to do for now, just clear any pending interrupt */
1520 lcd
->intstatus
= lcd
->intstatus
;
1526 /*-------------------------------------------------------------------------*/
1528 /* AU1200 LCD device probe helpers */
1530 static int au1200fb_init_fbinfo(struct au1200fb_device
*fbdev
)
1532 struct fb_info
*fbi
= fbdev
->fb_info
;
1535 fbi
->fbops
= &au1200fb_fb_ops
;
1537 bpp
= winbpp(win
->w
[fbdev
->plane
].mode_winctrl1
);
1539 /* Copy monitor specs from panel data */
1540 /* fixme: we're setting up LCD controller windows, so these dont give a
1541 damn as to what the monitor specs are (the panel itself does, but that
1542 isn't done here...so maybe need a generic catchall monitor setting??? */
1543 memcpy(&fbi
->monspecs
, &panel
->monspecs
, sizeof(struct fb_monspecs
));
1545 /* We first try the user mode passed in argument. If that failed,
1546 * or if no one has been specified, we default to the first mode of the
1547 * panel list. Note that after this call, var data will be set */
1548 if (!fb_find_mode(&fbi
->var
,
1550 NULL
, /* drv_info.opt_mode, */
1551 fbi
->monspecs
.modedb
,
1552 fbi
->monspecs
.modedb_len
,
1553 fbi
->monspecs
.modedb
,
1556 print_err("Cannot find valid mode for panel %s", panel
->name
);
1560 fbi
->pseudo_palette
= kcalloc(16, sizeof(u32
), GFP_KERNEL
);
1561 if (!fbi
->pseudo_palette
) {
1565 if (fb_alloc_cmap(&fbi
->cmap
, AU1200_LCD_NBR_PALETTE_ENTRIES
, 0) < 0) {
1566 print_err("Fail to allocate colormap (%d entries)",
1567 AU1200_LCD_NBR_PALETTE_ENTRIES
);
1568 kfree(fbi
->pseudo_palette
);
1572 strncpy(fbi
->fix
.id
, "AU1200", sizeof(fbi
->fix
.id
));
1573 fbi
->fix
.smem_start
= fbdev
->fb_phys
;
1574 fbi
->fix
.smem_len
= fbdev
->fb_len
;
1575 fbi
->fix
.type
= FB_TYPE_PACKED_PIXELS
;
1576 fbi
->fix
.xpanstep
= 0;
1577 fbi
->fix
.ypanstep
= 0;
1578 fbi
->fix
.mmio_start
= 0;
1579 fbi
->fix
.mmio_len
= 0;
1580 fbi
->fix
.accel
= FB_ACCEL_NONE
;
1582 fbi
->screen_base
= (char __iomem
*) fbdev
->fb_mem
;
1584 au1200fb_update_fbinfo(fbi
);
1589 /*-------------------------------------------------------------------------*/
1591 /* AU1200 LCD controller device driver */
1593 static int __devinit
au1200fb_drv_probe(struct platform_device
*dev
)
1595 struct au1200fb_device
*fbdev
;
1596 struct fb_info
*fbi
= NULL
;
1598 int bpp
, plane
, ret
, irq
;
1604 /* Kickstart the panel */
1605 au1200_setpanel(panel
);
1607 for (plane
= 0; plane
< device_count
; ++plane
) {
1608 bpp
= winbpp(win
->w
[plane
].mode_winctrl1
);
1609 if (win
->w
[plane
].xres
== 0)
1610 win
->w
[plane
].xres
= panel
->Xres
;
1611 if (win
->w
[plane
].yres
== 0)
1612 win
->w
[plane
].yres
= panel
->Yres
;
1614 fbi
= framebuffer_alloc(sizeof(struct au1200fb_device
),
1619 _au1200fb_infos
[plane
] = fbi
;
1621 fbdev
->fb_info
= fbi
;
1623 fbdev
->plane
= plane
;
1625 /* Allocate the framebuffer to the maximum screen size */
1626 fbdev
->fb_len
= (win
->w
[plane
].xres
* win
->w
[plane
].yres
* bpp
) / 8;
1628 fbdev
->fb_mem
= dma_alloc_noncoherent(&dev
->dev
,
1629 PAGE_ALIGN(fbdev
->fb_len
),
1630 &fbdev
->fb_phys
, GFP_KERNEL
);
1631 if (!fbdev
->fb_mem
) {
1632 print_err("fail to allocate frambuffer (size: %dK))",
1633 fbdev
->fb_len
/ 1024);
1638 * Set page reserved so that mmap will work. This is necessary
1639 * since we'll be remapping normal memory.
1641 for (page
= (unsigned long)fbdev
->fb_phys
;
1642 page
< PAGE_ALIGN((unsigned long)fbdev
->fb_phys
+
1644 page
+= PAGE_SIZE
) {
1645 SetPageReserved(pfn_to_page(page
>> PAGE_SHIFT
)); /* LCD DMA is NOT coherent on Au1200 */
1647 print_dbg("Framebuffer memory map at %p", fbdev
->fb_mem
);
1648 print_dbg("phys=0x%08x, size=%dK", fbdev
->fb_phys
, fbdev
->fb_len
/ 1024);
1651 if ((ret
= au1200fb_init_fbinfo(fbdev
)) < 0)
1654 /* Register new framebuffer */
1655 ret
= register_framebuffer(fbi
);
1657 print_err("cannot register new framebuffer");
1661 au1200fb_fb_set_par(fbi
);
1663 #if !defined(CONFIG_FRAMEBUFFER_CONSOLE) && defined(CONFIG_LOGO)
1665 if (fb_prepare_logo(fbi
, FB_ROTATE_UR
)) {
1666 /* Start display and show logo on boot */
1667 fb_set_cmap(&fbi
->cmap
, fbi
);
1668 fb_show_logo(fbi
, FB_ROTATE_UR
);
1673 /* Now hook interrupt too */
1674 irq
= platform_get_irq(dev
, 0);
1675 ret
= request_irq(irq
, au1200fb_handle_irq
,
1676 IRQF_DISABLED
| IRQF_SHARED
, "lcd", (void *)dev
);
1678 print_err("fail to request interrupt line %d (err: %d)",
1686 /* NOTE: This only does the current plane/window that failed; others are still active */
1688 dma_free_noncoherent(&dev
->dev
, PAGE_ALIGN(fbdev
->fb_len
),
1689 fbdev
->fb_mem
, fbdev
->fb_phys
);
1691 if (fbi
->cmap
.len
!= 0)
1692 fb_dealloc_cmap(&fbi
->cmap
);
1693 kfree(fbi
->pseudo_palette
);
1696 free_irq(AU1200_LCD_INT
, (void*)dev
);
1700 static int __devexit
au1200fb_drv_remove(struct platform_device
*dev
)
1702 struct au1200fb_device
*fbdev
;
1703 struct fb_info
*fbi
;
1706 /* Turn off the panel */
1707 au1200_setpanel(NULL
);
1709 for (plane
= 0; plane
< device_count
; ++plane
) {
1710 fbi
= _au1200fb_infos
[plane
];
1713 /* Clean up all probe data */
1714 unregister_framebuffer(fbi
);
1716 dma_free_noncoherent(&dev
->dev
,
1717 PAGE_ALIGN(fbdev
->fb_len
),
1718 fbdev
->fb_mem
, fbdev
->fb_phys
);
1719 if (fbi
->cmap
.len
!= 0)
1720 fb_dealloc_cmap(&fbi
->cmap
);
1721 kfree(fbi
->pseudo_palette
);
1723 framebuffer_release(fbi
);
1724 _au1200fb_infos
[plane
] = NULL
;
1727 free_irq(platform_get_irq(dev
, 0), (void *)dev
);
1733 static int au1200fb_drv_suspend(struct device
*dev
)
1735 au1200_setpanel(NULL
);
1743 static int au1200fb_drv_resume(struct device
*dev
)
1745 struct fb_info
*fbi
;
1748 /* Kickstart the panel */
1749 au1200_setpanel(panel
);
1751 for (i
= 0; i
< device_count
; i
++) {
1752 fbi
= _au1200fb_infos
[i
];
1753 au1200fb_fb_set_par(fbi
);
1759 static const struct dev_pm_ops au1200fb_pmops
= {
1760 .suspend
= au1200fb_drv_suspend
,
1761 .resume
= au1200fb_drv_resume
,
1762 .freeze
= au1200fb_drv_suspend
,
1763 .thaw
= au1200fb_drv_resume
,
1766 #define AU1200FB_PMOPS (&au1200fb_pmops)
1769 #define AU1200FB_PMOPS NULL
1770 #endif /* CONFIG_PM */
1772 static struct platform_driver au1200fb_driver
= {
1774 .name
= "au1200-lcd",
1775 .owner
= THIS_MODULE
,
1776 .pm
= AU1200FB_PMOPS
,
1778 .probe
= au1200fb_drv_probe
,
1779 .remove
= __devexit_p(au1200fb_drv_remove
),
1782 /*-------------------------------------------------------------------------*/
1786 static int au1200fb_setup(void)
1788 char *options
= NULL
;
1789 char *this_opt
, *endptr
;
1790 int num_panels
= ARRAY_SIZE(known_lcd_panels
);
1793 fb_get_options(DRIVER_NAME
, &options
);
1796 while ((this_opt
= strsep(&options
,",")) != NULL
) {
1797 /* Panel option - can be panel name,
1798 * "bs" for board-switch, or number/index */
1799 if (!strncmp(this_opt
, "panel:", 6)) {
1804 /* First check for index, which allows
1805 * to short circuit this mess */
1806 li
= simple_strtol(this_opt
, &endptr
, 0);
1807 if (*endptr
== '\0') {
1808 panel_idx
= (int)li
;
1810 else if (strcmp(this_opt
, "bs") == 0) {
1811 extern int board_au1200fb_panel(void);
1812 panel_idx
= board_au1200fb_panel();
1816 for (i
= 0; i
< num_panels
; i
++) {
1817 if (!strcmp(this_opt
, known_lcd_panels
[i
].name
)) {
1823 if ((panel_idx
< 0) || (panel_idx
>= num_panels
)) {
1824 print_warn("Panel %s not supported!", this_opt
);
1827 panel_index
= panel_idx
;
1830 else if (strncmp(this_opt
, "nohwcursor", 10) == 0) {
1834 else if (strncmp(this_opt
, "devices:", 8) == 0) {
1836 device_count
= simple_strtol(this_opt
,
1838 if ((device_count
< 0) ||
1839 (device_count
> MAX_DEVICE_COUNT
))
1840 device_count
= MAX_DEVICE_COUNT
;
1843 else if (strncmp(this_opt
, "wincfg:", 7) == 0) {
1845 window_index
= simple_strtol(this_opt
,
1847 if ((window_index
< 0) ||
1848 (window_index
>= ARRAY_SIZE(windows
)))
1849 window_index
= DEFAULT_WINDOW_INDEX
;
1852 else if (strncmp(this_opt
, "off", 3) == 0)
1854 /* Unsupported option */
1856 print_warn("Unsupported option \"%s\"", this_opt
);
1863 static int __init
au1200fb_init(void)
1865 print_info("" DRIVER_DESC
"");
1867 /* Setup driver with options */
1868 if (au1200fb_setup())
1871 /* Point to the panel selected */
1872 panel
= &known_lcd_panels
[panel_index
];
1873 win
= &windows
[window_index
];
1875 printk(DRIVER_NAME
": Panel %d %s\n", panel_index
, panel
->name
);
1876 printk(DRIVER_NAME
": Win %d %s\n", window_index
, win
->name
);
1878 return platform_driver_register(&au1200fb_driver
);
1881 static void __exit
au1200fb_cleanup(void)
1883 platform_driver_unregister(&au1200fb_driver
);
1886 module_init(au1200fb_init
);
1887 module_exit(au1200fb_cleanup
);
1889 MODULE_DESCRIPTION(DRIVER_DESC
);
1890 MODULE_LICENSE("GPL");