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/clk.h>
34 #include <linux/module.h>
35 #include <linux/platform_device.h>
36 #include <linux/kernel.h>
37 #include <linux/errno.h>
38 #include <linux/string.h>
41 #include <linux/init.h>
42 #include <linux/interrupt.h>
43 #include <linux/ctype.h>
44 #include <linux/dma-mapping.h>
45 #include <linux/slab.h>
47 #include <asm/mach-au1x00/au1000.h>
48 #include <asm/mach-au1x00/au1200fb.h> /* platform_data */
51 #define DRIVER_NAME "au1200fb"
52 #define DRIVER_DESC "LCD controller driver for AU1200 processors"
56 #define print_err(f, arg...) printk(KERN_ERR DRIVER_NAME ": " f "\n", ## arg)
57 #define print_warn(f, arg...) printk(KERN_WARNING DRIVER_NAME ": " f "\n", ## arg)
58 #define print_info(f, arg...) printk(KERN_INFO DRIVER_NAME ": " f "\n", ## arg)
61 #define print_dbg(f, arg...) printk(KERN_DEBUG __FILE__ ": " f "\n", ## arg)
63 #define print_dbg(f, arg...) do {} while (0)
67 #define AU1200_LCD_FB_IOCTL 0x46FF
69 #define AU1200_LCD_SET_SCREEN 1
70 #define AU1200_LCD_GET_SCREEN 2
71 #define AU1200_LCD_SET_WINDOW 3
72 #define AU1200_LCD_GET_WINDOW 4
73 #define AU1200_LCD_SET_PANEL 5
74 #define AU1200_LCD_GET_PANEL 6
76 #define SCREEN_SIZE (1<< 1)
77 #define SCREEN_BACKCOLOR (1<< 2)
78 #define SCREEN_BRIGHTNESS (1<< 3)
79 #define SCREEN_COLORKEY (1<< 4)
80 #define SCREEN_MASK (1<< 5)
82 struct au1200_lcd_global_regs_t
{
86 unsigned int backcolor
;
87 unsigned int brightness
;
88 unsigned int colorkey
;
90 unsigned int panel_choice
;
95 #define WIN_POSITION (1<< 0)
96 #define WIN_ALPHA_COLOR (1<< 1)
97 #define WIN_ALPHA_MODE (1<< 2)
98 #define WIN_PRIORITY (1<< 3)
99 #define WIN_CHANNEL (1<< 4)
100 #define WIN_BUFFER_FORMAT (1<< 5)
101 #define WIN_COLOR_ORDER (1<< 6)
102 #define WIN_PIXEL_ORDER (1<< 7)
103 #define WIN_SIZE (1<< 8)
104 #define WIN_COLORKEY_MODE (1<< 9)
105 #define WIN_DOUBLE_BUFFER_MODE (1<< 10)
106 #define WIN_RAM_ARRAY_MODE (1<< 11)
107 #define WIN_BUFFER_SCALE (1<< 12)
108 #define WIN_ENABLE (1<< 13)
110 struct au1200_lcd_window_regs_t
{
114 unsigned int alpha_color
;
115 unsigned int alpha_mode
;
116 unsigned int priority
;
117 unsigned int channel
;
118 unsigned int buffer_format
;
119 unsigned int color_order
;
120 unsigned int pixel_order
;
123 unsigned int colorkey_mode
;
124 unsigned int double_buffer_mode
;
125 unsigned int ram_array_mode
;
132 struct au1200_lcd_iodata_t
{
134 struct au1200_lcd_global_regs_t global
;
135 struct au1200_lcd_window_regs_t window
;
138 #if defined(__BIG_ENDIAN)
139 #define LCD_CONTROL_DEFAULT_PO LCD_CONTROL_PO_11
141 #define LCD_CONTROL_DEFAULT_PO LCD_CONTROL_PO_00
143 #define LCD_CONTROL_DEFAULT_SBPPF LCD_CONTROL_SBPPF_565
145 /* Private, per-framebuffer management information (independent of the panel itself) */
146 struct au1200fb_device
{
147 struct fb_info
*fb_info
; /* FB driver info record */
148 struct au1200fb_platdata
*pd
;
151 unsigned char* fb_mem
; /* FrameBuffer memory map */
156 /********************************************************************/
158 /* LCD controller restrictions */
159 #define AU1200_LCD_MAX_XRES 1280
160 #define AU1200_LCD_MAX_YRES 1024
161 #define AU1200_LCD_MAX_BPP 32
162 #define AU1200_LCD_MAX_CLK 96000000 /* fixme: this needs to go away ? */
163 #define AU1200_LCD_NBR_PALETTE_ENTRIES 256
165 /* Default number of visible screen buffer to allocate */
166 #define AU1200FB_NBR_VIDEO_BUFFERS 1
168 /* Default maximum number of fb devices to create */
169 #define MAX_DEVICE_COUNT 4
171 /* Default window configuration entry to use (see windows[]) */
172 #define DEFAULT_WINDOW_INDEX 2
174 /********************************************************************/
176 static struct fb_info
*_au1200fb_infos
[MAX_DEVICE_COUNT
];
177 static struct au1200_lcd
*lcd
= (struct au1200_lcd
*) AU1200_LCD_ADDR
;
178 static int device_count
= MAX_DEVICE_COUNT
;
179 static int window_index
= DEFAULT_WINDOW_INDEX
; /* default is zero */
180 static int panel_index
= 2; /* default is zero */
181 static struct window_settings
*win
;
182 static struct panel_settings
*panel
;
183 static int noblanking
= 1;
184 static int nohwcursor
= 0;
186 struct window_settings
{
187 unsigned char name
[64];
188 uint32 mode_backcolor
;
189 uint32 mode_colorkey
;
190 uint32 mode_colorkeymsk
;
196 uint32 mode_winctrl1
; /* winctrl1[FRM,CCO,PO,PIPE] */
197 uint32 mode_winenable
;
201 #if defined(__BIG_ENDIAN)
202 #define LCD_WINCTRL1_PO_16BPP LCD_WINCTRL1_PO_00
204 #define LCD_WINCTRL1_PO_16BPP LCD_WINCTRL1_PO_01
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_backlight
;
336 #define Xres min_xres
337 #define Yres min_yres
338 u32 min_xres
; /* Minimum horizontal resolution */
339 u32 max_xres
; /* Maximum horizontal resolution */
340 u32 min_yres
; /* Minimum vertical resolution */
341 u32 max_yres
; /* Maximum vertical resolution */
344 /********************************************************************/
345 /* fixme: Maybe a modedb for the CRT ? otherwise panels should be as-is */
347 /* List of panels known to work with the AU1200 LCD controller.
348 * To add a new panel, enter the same specifications as the
349 * Generic_TFT one, and MAKE SURE that it doesn't conflicts
350 * with the controller restrictions. Restrictions are:
352 * STN color panels: max_bpp <= 12
353 * STN mono panels: max_bpp <= 4
354 * TFT panels: max_bpp <= 16
358 static struct panel_settings known_lcd_panels
[] =
360 [0] = { /* QVGA 320x240 H:33.3kHz V:110Hz */
361 .name
= "QVGA_320x240",
371 .input
= FB_DISP_RGB
,
373 .mode_screen
= LCD_SCREEN_SX_N(320) |
374 LCD_SCREEN_SY_N(240),
375 .mode_horztiming
= 0x00c4623b,
376 .mode_verttiming
= 0x00502814,
377 .mode_clkcontrol
= 0x00020002, /* /4=24Mhz */
378 .mode_pwmdiv
= 0x00000000,
379 .mode_pwmhi
= 0x00000000,
380 .mode_outmask
= 0x00FFFFFF,
381 .mode_fifoctrl
= 0x2f2f2f2f,
382 .mode_backlight
= 0x00000000,
388 [1] = { /* VGA 640x480 H:30.3kHz V:58Hz */
389 .name
= "VGA_640x480",
399 .input
= FB_DISP_RGB
,
401 .mode_screen
= 0x13f9df80,
402 .mode_horztiming
= 0x003c5859,
403 .mode_verttiming
= 0x00741201,
404 .mode_clkcontrol
= 0x00020001, /* /4=24Mhz */
405 .mode_pwmdiv
= 0x00000000,
406 .mode_pwmhi
= 0x00000000,
407 .mode_outmask
= 0x00FFFFFF,
408 .mode_fifoctrl
= 0x2f2f2f2f,
409 .mode_backlight
= 0x00000000,
415 [2] = { /* SVGA 800x600 H:46.1kHz V:69Hz */
416 .name
= "SVGA_800x600",
426 .input
= FB_DISP_RGB
,
428 .mode_screen
= 0x18fa5780,
429 .mode_horztiming
= 0x00dc7e77,
430 .mode_verttiming
= 0x00584805,
431 .mode_clkcontrol
= 0x00020000, /* /2=48Mhz */
432 .mode_pwmdiv
= 0x00000000,
433 .mode_pwmhi
= 0x00000000,
434 .mode_outmask
= 0x00FFFFFF,
435 .mode_fifoctrl
= 0x2f2f2f2f,
436 .mode_backlight
= 0x00000000,
442 [3] = { /* XVGA 1024x768 H:56.2kHz V:70Hz */
443 .name
= "XVGA_1024x768",
453 .input
= FB_DISP_RGB
,
455 .mode_screen
= 0x1ffaff80,
456 .mode_horztiming
= 0x007d0e57,
457 .mode_verttiming
= 0x00740a01,
458 .mode_clkcontrol
= 0x000A0000, /* /1 */
459 .mode_pwmdiv
= 0x00000000,
460 .mode_pwmhi
= 0x00000000,
461 .mode_outmask
= 0x00FFFFFF,
462 .mode_fifoctrl
= 0x2f2f2f2f,
463 .mode_backlight
= 0x00000000,
469 [4] = { /* XVGA XVGA 1280x1024 H:68.5kHz V:65Hz */
470 .name
= "XVGA_1280x1024",
480 .input
= FB_DISP_RGB
,
482 .mode_screen
= 0x27fbff80,
483 .mode_horztiming
= 0x00cdb2c7,
484 .mode_verttiming
= 0x00600002,
485 .mode_clkcontrol
= 0x000A0000, /* /1 */
486 .mode_pwmdiv
= 0x00000000,
487 .mode_pwmhi
= 0x00000000,
488 .mode_outmask
= 0x00FFFFFF,
489 .mode_fifoctrl
= 0x2f2f2f2f,
490 .mode_backlight
= 0x00000000,
496 [5] = { /* Samsung 1024x768 TFT */
497 .name
= "Samsung_1024x768_TFT",
507 .input
= FB_DISP_RGB
,
509 .mode_screen
= 0x1ffaff80,
510 .mode_horztiming
= 0x018cc677,
511 .mode_verttiming
= 0x00241217,
512 .mode_clkcontrol
= 0x00000000, /* SCB 0x1 /4=24Mhz */
513 .mode_pwmdiv
= 0x8000063f, /* SCB 0x0 */
514 .mode_pwmhi
= 0x03400000, /* SCB 0x0 */
515 .mode_outmask
= 0x00FFFFFF,
516 .mode_fifoctrl
= 0x2f2f2f2f,
517 .mode_backlight
= 0x00000000,
523 [6] = { /* Toshiba 640x480 TFT */
524 .name
= "Toshiba_640x480_TFT",
534 .input
= FB_DISP_RGB
,
536 .mode_screen
= LCD_SCREEN_SX_N(640) |
537 LCD_SCREEN_SY_N(480),
538 .mode_horztiming
= LCD_HORZTIMING_HPW_N(96) |
539 LCD_HORZTIMING_HND1_N(13) | LCD_HORZTIMING_HND2_N(51),
540 .mode_verttiming
= LCD_VERTTIMING_VPW_N(2) |
541 LCD_VERTTIMING_VND1_N(11) | LCD_VERTTIMING_VND2_N(32),
542 .mode_clkcontrol
= 0x00000000, /* /4=24Mhz */
543 .mode_pwmdiv
= 0x8000063f,
544 .mode_pwmhi
= 0x03400000,
545 .mode_outmask
= 0x00fcfcfc,
546 .mode_fifoctrl
= 0x2f2f2f2f,
547 .mode_backlight
= 0x00000000,
553 [7] = { /* Sharp 320x240 TFT */
554 .name
= "Sharp_320x240_TFT",
564 .input
= FB_DISP_RGB
,
566 .mode_screen
= LCD_SCREEN_SX_N(320) |
567 LCD_SCREEN_SY_N(240),
568 .mode_horztiming
= LCD_HORZTIMING_HPW_N(60) |
569 LCD_HORZTIMING_HND1_N(13) | LCD_HORZTIMING_HND2_N(2),
570 .mode_verttiming
= LCD_VERTTIMING_VPW_N(2) |
571 LCD_VERTTIMING_VND1_N(2) | LCD_VERTTIMING_VND2_N(5),
572 .mode_clkcontrol
= LCD_CLKCONTROL_PCD_N(7), /*16=6Mhz*/
573 .mode_pwmdiv
= 0x8000063f,
574 .mode_pwmhi
= 0x03400000,
575 .mode_outmask
= 0x00fcfcfc,
576 .mode_fifoctrl
= 0x2f2f2f2f,
577 .mode_backlight
= 0x00000000,
578 .lcdclk
= 96, /* 96MHz AUXPLL */
583 [8] = { /* Toppoly TD070WGCB2 7" 856x480 TFT */
584 .name
= "Toppoly_TD070WGCB2",
594 .input
= FB_DISP_RGB
,
596 .mode_screen
= LCD_SCREEN_SX_N(856) |
597 LCD_SCREEN_SY_N(480),
598 .mode_horztiming
= LCD_HORZTIMING_HND2_N(43) |
599 LCD_HORZTIMING_HND1_N(43) | LCD_HORZTIMING_HPW_N(114),
600 .mode_verttiming
= LCD_VERTTIMING_VND2_N(20) |
601 LCD_VERTTIMING_VND1_N(21) | LCD_VERTTIMING_VPW_N(4),
602 .mode_clkcontrol
= 0x00020001, /* /4=24Mhz */
603 .mode_pwmdiv
= 0x8000063f,
604 .mode_pwmhi
= 0x03400000,
605 .mode_outmask
= 0x00fcfcfc,
606 .mode_fifoctrl
= 0x2f2f2f2f,
607 .mode_backlight
= 0x00000000,
613 .name
= "DB1300_800x480",
623 .input
= FB_DISP_RGB
,
625 .mode_screen
= LCD_SCREEN_SX_N(800) |
626 LCD_SCREEN_SY_N(480),
627 .mode_horztiming
= LCD_HORZTIMING_HPW_N(5) |
628 LCD_HORZTIMING_HND1_N(16) |
629 LCD_HORZTIMING_HND2_N(8),
630 .mode_verttiming
= LCD_VERTTIMING_VPW_N(4) |
631 LCD_VERTTIMING_VND1_N(8) |
632 LCD_VERTTIMING_VND2_N(5),
633 .mode_clkcontrol
= LCD_CLKCONTROL_PCD_N(1) |
636 .mode_pwmdiv
= 0x00000000,
637 .mode_pwmhi
= 0x00000000,
638 .mode_outmask
= 0x00FFFFFF,
639 .mode_fifoctrl
= 0x2f2f2f2f,
640 .mode_backlight
= 0x00000000,
647 #define NUM_PANELS (ARRAY_SIZE(known_lcd_panels))
649 /********************************************************************/
651 static int winbpp (unsigned int winctrl1
)
655 /* how many bits are needed for each pixel format */
656 switch (winctrl1
& LCD_WINCTRL1_FRM
) {
657 case LCD_WINCTRL1_FRM_1BPP
:
660 case LCD_WINCTRL1_FRM_2BPP
:
663 case LCD_WINCTRL1_FRM_4BPP
:
666 case LCD_WINCTRL1_FRM_8BPP
:
669 case LCD_WINCTRL1_FRM_12BPP
:
670 case LCD_WINCTRL1_FRM_16BPP655
:
671 case LCD_WINCTRL1_FRM_16BPP565
:
672 case LCD_WINCTRL1_FRM_16BPP556
:
673 case LCD_WINCTRL1_FRM_16BPPI1555
:
674 case LCD_WINCTRL1_FRM_16BPPI5551
:
675 case LCD_WINCTRL1_FRM_16BPPA1555
:
676 case LCD_WINCTRL1_FRM_16BPPA5551
:
679 case LCD_WINCTRL1_FRM_24BPP
:
680 case LCD_WINCTRL1_FRM_32BPP
:
688 static int fbinfo2index (struct fb_info
*fb_info
)
692 for (i
= 0; i
< device_count
; ++i
) {
693 if (fb_info
== _au1200fb_infos
[i
])
696 printk("au1200fb: ERROR: fbinfo2index failed!\n");
700 static int au1200_setlocation (struct au1200fb_device
*fbdev
, int plane
,
703 uint32 winctrl0
, winctrl1
, winenable
, fb_offset
= 0;
706 /* FIX!!! NOT CHECKING FOR COMPLETE OFFSCREEN YET */
708 winctrl0
= lcd
->window
[plane
].winctrl0
;
709 winctrl1
= lcd
->window
[plane
].winctrl1
;
710 winctrl0
&= (LCD_WINCTRL0_A
| LCD_WINCTRL0_AEN
);
711 winctrl1
&= ~(LCD_WINCTRL1_SZX
| LCD_WINCTRL1_SZY
);
713 /* Check for off-screen adjustments */
714 xsz
= win
->w
[plane
].xres
;
715 ysz
= win
->w
[plane
].yres
;
716 if ((xpos
+ win
->w
[plane
].xres
) > panel
->Xres
) {
717 /* Off-screen to the right */
718 xsz
= panel
->Xres
- xpos
; /* off by 1 ??? */
719 /*printk("off screen right\n");*/
722 if ((ypos
+ win
->w
[plane
].yres
) > panel
->Yres
) {
723 /* Off-screen to the bottom */
724 ysz
= panel
->Yres
- ypos
; /* off by 1 ??? */
725 /*printk("off screen bottom\n");*/
729 /* Off-screen to the left */
730 xsz
= win
->w
[plane
].xres
+ xpos
;
731 fb_offset
+= (((0 - xpos
) * winbpp(lcd
->window
[plane
].winctrl1
))/8);
733 /*printk("off screen left\n");*/
737 /* Off-screen to the top */
738 ysz
= win
->w
[plane
].yres
+ ypos
;
739 /* fixme: fb_offset += ((0-ypos)*fb_pars[plane].line_length); */
741 /*printk("off screen top\n");*/
744 /* record settings */
745 win
->w
[plane
].xpos
= xpos
;
746 win
->w
[plane
].ypos
= ypos
;
750 winctrl0
|= (xpos
<< 21);
751 winctrl0
|= (ypos
<< 10);
752 winctrl1
|= (xsz
<< 11);
753 winctrl1
|= (ysz
<< 0);
755 /* Disable the window while making changes, then restore WINEN */
756 winenable
= lcd
->winenable
& (1 << plane
);
757 wmb(); /* drain writebuffer */
758 lcd
->winenable
&= ~(1 << plane
);
759 lcd
->window
[plane
].winctrl0
= winctrl0
;
760 lcd
->window
[plane
].winctrl1
= winctrl1
;
761 lcd
->window
[plane
].winbuf0
=
762 lcd
->window
[plane
].winbuf1
= fbdev
->fb_phys
;
763 lcd
->window
[plane
].winbufctrl
= 0; /* select winbuf0 */
764 lcd
->winenable
|= winenable
;
765 wmb(); /* drain writebuffer */
770 static void au1200_setpanel(struct panel_settings
*newpanel
,
771 struct au1200fb_platdata
*pd
)
774 * Perform global setup/init of LCD controller
778 /* Make sure all windows disabled */
779 winenable
= lcd
->winenable
;
781 wmb(); /* drain writebuffer */
783 * Ensure everything is disabled before reconfiguring
785 if (lcd
->screen
& LCD_SCREEN_SEN
) {
786 /* Wait for vertical sync period */
787 lcd
->intstatus
= LCD_INT_SS
;
788 while ((lcd
->intstatus
& LCD_INT_SS
) == 0)
791 lcd
->screen
&= ~LCD_SCREEN_SEN
; /*disable the controller*/
794 lcd
->intstatus
= lcd
->intstatus
; /*clear interrupts*/
795 wmb(); /* drain writebuffer */
796 /*wait for controller to shut down*/
797 } while ((lcd
->intstatus
& LCD_INT_SD
) == 0);
799 /* Call shutdown of current panel (if up) */
800 /* this must occur last, because if an external clock is driving
801 the controller, the clock cannot be turned off before first
802 shutting down the controller.
804 if (pd
->panel_shutdown
)
805 pd
->panel_shutdown();
808 /* Newpanel == NULL indicates a shutdown operation only */
809 if (newpanel
== NULL
)
814 printk("Panel(%s), %dx%d\n", panel
->name
, panel
->Xres
, panel
->Yres
);
817 * Setup clocking if internal LCD clock source (assumes sys_auxpll valid)
819 if (!(panel
->mode_clkcontrol
& LCD_CLKCONTROL_EXT
))
821 struct clk
*c
= clk_get(NULL
, "lcd_intclk");
822 long r
, pc
= panel
->lcdclk
* 1000000;
825 r
= clk_round_rate(c
, pc
);
826 if ((pc
- r
) < (pc
/ 10)) { /* 10% slack */
828 clk_prepare_enable(c
);
835 * Configure panel timings
837 lcd
->screen
= panel
->mode_screen
;
838 lcd
->horztiming
= panel
->mode_horztiming
;
839 lcd
->verttiming
= panel
->mode_verttiming
;
840 lcd
->clkcontrol
= panel
->mode_clkcontrol
;
841 lcd
->pwmdiv
= panel
->mode_pwmdiv
;
842 lcd
->pwmhi
= panel
->mode_pwmhi
;
843 lcd
->outmask
= panel
->mode_outmask
;
844 lcd
->fifoctrl
= panel
->mode_fifoctrl
;
845 wmb(); /* drain writebuffer */
847 /* fixme: Check window settings to make sure still valid
848 * for new geometry */
850 au1200_setlocation(fbdev
, 0, win
->w
[0].xpos
, win
->w
[0].ypos
);
851 au1200_setlocation(fbdev
, 1, win
->w
[1].xpos
, win
->w
[1].ypos
);
852 au1200_setlocation(fbdev
, 2, win
->w
[2].xpos
, win
->w
[2].ypos
);
853 au1200_setlocation(fbdev
, 3, win
->w
[3].xpos
, win
->w
[3].ypos
);
855 lcd
->winenable
= winenable
;
858 * Re-enable screen now that it is configured
860 lcd
->screen
|= LCD_SCREEN_SEN
;
861 wmb(); /* drain writebuffer */
863 /* Call init of panel */
867 /* FIX!!!! not appropriate on panel change!!! Global setup/init */
870 lcd
->backcolor
= win
->mode_backcolor
;
872 /* Setup Color Key - FIX!!! */
873 lcd
->colorkey
= win
->mode_colorkey
;
874 lcd
->colorkeymsk
= win
->mode_colorkeymsk
;
876 /* Setup HWCursor - FIX!!! Need to support this eventually */
877 lcd
->hwc
.cursorctrl
= 0;
878 lcd
->hwc
.cursorpos
= 0;
879 lcd
->hwc
.cursorcolor0
= 0;
880 lcd
->hwc
.cursorcolor1
= 0;
881 lcd
->hwc
.cursorcolor2
= 0;
882 lcd
->hwc
.cursorcolor3
= 0;
886 #define D(X) printk("%25s: %08X\n", #X, X)
895 D(lcd
->window
[0].winctrl0
);
896 D(lcd
->window
[0].winctrl1
);
897 D(lcd
->window
[0].winctrl2
);
898 D(lcd
->window
[0].winbuf0
);
899 D(lcd
->window
[0].winbuf1
);
900 D(lcd
->window
[0].winbufctrl
);
901 D(lcd
->window
[1].winctrl0
);
902 D(lcd
->window
[1].winctrl1
);
903 D(lcd
->window
[1].winctrl2
);
904 D(lcd
->window
[1].winbuf0
);
905 D(lcd
->window
[1].winbuf1
);
906 D(lcd
->window
[1].winbufctrl
);
907 D(lcd
->window
[2].winctrl0
);
908 D(lcd
->window
[2].winctrl1
);
909 D(lcd
->window
[2].winctrl2
);
910 D(lcd
->window
[2].winbuf0
);
911 D(lcd
->window
[2].winbuf1
);
912 D(lcd
->window
[2].winbufctrl
);
913 D(lcd
->window
[3].winctrl0
);
914 D(lcd
->window
[3].winctrl1
);
915 D(lcd
->window
[3].winctrl2
);
916 D(lcd
->window
[3].winbuf0
);
917 D(lcd
->window
[3].winbuf1
);
918 D(lcd
->window
[3].winbufctrl
);
926 D(lcd
->hwc
.cursorctrl
);
927 D(lcd
->hwc
.cursorpos
);
928 D(lcd
->hwc
.cursorcolor0
);
929 D(lcd
->hwc
.cursorcolor1
);
930 D(lcd
->hwc
.cursorcolor2
);
931 D(lcd
->hwc
.cursorcolor3
);
935 static void au1200_setmode(struct au1200fb_device
*fbdev
)
937 int plane
= fbdev
->plane
;
938 /* Window/plane setup */
939 lcd
->window
[plane
].winctrl1
= ( 0
940 | LCD_WINCTRL1_PRI_N(plane
)
941 | win
->w
[plane
].mode_winctrl1
/* FRM,CCO,PO,PIPE */
944 au1200_setlocation(fbdev
, plane
, win
->w
[plane
].xpos
, win
->w
[plane
].ypos
);
946 lcd
->window
[plane
].winctrl2
= ( 0
947 | LCD_WINCTRL2_CKMODE_00
949 | LCD_WINCTRL2_BX_N(fbdev
->fb_info
->fix
.line_length
)
953 lcd
->winenable
|= win
->w
[plane
].mode_winenable
;
954 wmb(); /* drain writebuffer */
960 /*#define panel_is_dual(panel) ((panel->mode_screen & LCD_SCREEN_PT) == LCD_SCREEN_PT_010)*/
961 /*#define panel_is_active(panel)((panel->mode_screen & LCD_SCREEN_PT) == LCD_SCREEN_PT_010)*/
963 #define panel_is_color(panel) ((panel->mode_screen & LCD_SCREEN_PT) <= LCD_SCREEN_PT_CDSTN)
965 /* Bitfields format supported by the controller. */
966 static struct fb_bitfield rgb_bitfields
[][4] = {
967 /* Red, Green, Blue, Transp */
968 [LCD_WINCTRL1_FRM_16BPP655
>> 25] =
969 { { 10, 6, 0 }, { 5, 5, 0 }, { 0, 5, 0 }, { 0, 0, 0 } },
971 [LCD_WINCTRL1_FRM_16BPP565
>> 25] =
972 { { 11, 5, 0 }, { 5, 6, 0 }, { 0, 5, 0 }, { 0, 0, 0 } },
974 [LCD_WINCTRL1_FRM_16BPP556
>> 25] =
975 { { 11, 5, 0 }, { 6, 5, 0 }, { 0, 6, 0 }, { 0, 0, 0 } },
977 [LCD_WINCTRL1_FRM_16BPPI1555
>> 25] =
978 { { 10, 5, 0 }, { 5, 5, 0 }, { 0, 5, 0 }, { 0, 0, 0 } },
980 [LCD_WINCTRL1_FRM_16BPPI5551
>> 25] =
981 { { 11, 5, 0 }, { 6, 5, 0 }, { 1, 5, 0 }, { 0, 0, 0 } },
983 [LCD_WINCTRL1_FRM_16BPPA1555
>> 25] =
984 { { 10, 5, 0 }, { 5, 5, 0 }, { 0, 5, 0 }, { 15, 1, 0 } },
986 [LCD_WINCTRL1_FRM_16BPPA5551
>> 25] =
987 { { 11, 5, 0 }, { 6, 5, 0 }, { 1, 5, 0 }, { 0, 1, 0 } },
989 [LCD_WINCTRL1_FRM_24BPP
>> 25] =
990 { { 16, 8, 0 }, { 8, 8, 0 }, { 0, 8, 0 }, { 0, 0, 0 } },
992 [LCD_WINCTRL1_FRM_32BPP
>> 25] =
993 { { 16, 8, 0 }, { 8, 8, 0 }, { 0, 8, 0 }, { 24, 0, 0 } },
996 /*-------------------------------------------------------------------------*/
1000 static void au1200fb_update_fbinfo(struct fb_info
*fbi
)
1002 /* FIX!!!! This also needs to take the window pixel format into account!!! */
1004 /* Update var-dependent FB info */
1005 if (panel_is_color(panel
)) {
1006 if (fbi
->var
.bits_per_pixel
<= 8) {
1008 fbi
->fix
.visual
= FB_VISUAL_PSEUDOCOLOR
;
1009 fbi
->fix
.line_length
= fbi
->var
.xres_virtual
/
1010 (8/fbi
->var
.bits_per_pixel
);
1012 /* non-palettized */
1013 fbi
->fix
.visual
= FB_VISUAL_TRUECOLOR
;
1014 fbi
->fix
.line_length
= fbi
->var
.xres_virtual
* (fbi
->var
.bits_per_pixel
/ 8);
1017 /* mono FIX!!! mono 8 and 4 bits */
1018 fbi
->fix
.visual
= FB_VISUAL_MONO10
;
1019 fbi
->fix
.line_length
= fbi
->var
.xres_virtual
/ 8;
1022 fbi
->screen_size
= fbi
->fix
.line_length
* fbi
->var
.yres_virtual
;
1023 print_dbg("line length: %d\n", fbi
->fix
.line_length
);
1024 print_dbg("bits_per_pixel: %d\n", fbi
->var
.bits_per_pixel
);
1027 /*-------------------------------------------------------------------------*/
1029 /* AU1200 framebuffer driver */
1032 * Validate var settings with hardware restrictions and modify it if necessary
1034 static int au1200fb_fb_check_var(struct fb_var_screeninfo
*var
,
1035 struct fb_info
*fbi
)
1037 struct au1200fb_device
*fbdev
= fbi
->par
;
1039 int screen_size
, plane
;
1041 plane
= fbdev
->plane
;
1043 /* Make sure that the mode respect all LCD controller and
1044 * panel restrictions. */
1045 var
->xres
= win
->w
[plane
].xres
;
1046 var
->yres
= win
->w
[plane
].yres
;
1048 /* No need for virtual resolution support */
1049 var
->xres_virtual
= var
->xres
;
1050 var
->yres_virtual
= var
->yres
;
1052 var
->bits_per_pixel
= winbpp(win
->w
[plane
].mode_winctrl1
);
1054 screen_size
= var
->xres_virtual
* var
->yres_virtual
;
1055 if (var
->bits_per_pixel
> 8) screen_size
*= (var
->bits_per_pixel
/ 8);
1056 else screen_size
/= (8/var
->bits_per_pixel
);
1058 if (fbdev
->fb_len
< screen_size
)
1059 return -EINVAL
; /* Virtual screen is to big, abort */
1061 /* FIX!!!! what are the implicaitons of ignoring this for windows ??? */
1062 /* The max LCD clock is fixed to 48MHz (value of AUX_CLK). The pixel
1063 * clock can only be obtain by dividing this value by an even integer.
1064 * Fallback to a slower pixel clock if necessary. */
1065 pixclock
= max((u32
)(PICOS2KHZ(var
->pixclock
) * 1000), fbi
->monspecs
.dclkmin
);
1066 pixclock
= min3(pixclock
, fbi
->monspecs
.dclkmax
, (u32
)AU1200_LCD_MAX_CLK
/2);
1068 if (AU1200_LCD_MAX_CLK
% pixclock
) {
1069 int diff
= AU1200_LCD_MAX_CLK
% pixclock
;
1073 var
->pixclock
= KHZ2PICOS(pixclock
/1000);
1075 if (!panel_is_active(panel
)) {
1076 int pcd
= AU1200_LCD_MAX_CLK
/ (pixclock
* 2) - 1;
1078 if (!panel_is_color(panel
)
1079 && (panel
->control_base
& LCD_CONTROL_MPI
) && (pcd
< 3)) {
1080 /* STN 8bit mono panel support is up to 6MHz pixclock */
1081 var
->pixclock
= KHZ2PICOS(6000);
1083 /* Other STN panel support is up to 12MHz */
1084 var
->pixclock
= KHZ2PICOS(12000);
1088 /* Set bitfield accordingly */
1089 switch (var
->bits_per_pixel
) {
1092 /* 16bpp True color.
1093 * These must be set to MATCH WINCTRL[FORM] */
1095 idx
= (win
->w
[0].mode_winctrl1
& LCD_WINCTRL1_FRM
) >> 25;
1096 var
->red
= rgb_bitfields
[idx
][0];
1097 var
->green
= rgb_bitfields
[idx
][1];
1098 var
->blue
= rgb_bitfields
[idx
][2];
1099 var
->transp
= rgb_bitfields
[idx
][3];
1105 /* 32bpp True color.
1106 * These must be set to MATCH WINCTRL[FORM] */
1108 idx
= (win
->w
[0].mode_winctrl1
& LCD_WINCTRL1_FRM
) >> 25;
1109 var
->red
= rgb_bitfields
[idx
][0];
1110 var
->green
= rgb_bitfields
[idx
][1];
1111 var
->blue
= rgb_bitfields
[idx
][2];
1112 var
->transp
= rgb_bitfields
[idx
][3];
1116 print_dbg("Unsupported depth %dbpp", var
->bits_per_pixel
);
1124 * Set hardware with var settings. This will enable the controller with a
1125 * specific mode, normally validated with the fb_check_var method
1127 static int au1200fb_fb_set_par(struct fb_info
*fbi
)
1129 struct au1200fb_device
*fbdev
= fbi
->par
;
1131 au1200fb_update_fbinfo(fbi
);
1132 au1200_setmode(fbdev
);
1138 * Set color in LCD palette.
1140 static int au1200fb_fb_setcolreg(unsigned regno
, unsigned red
, unsigned green
,
1141 unsigned blue
, unsigned transp
, struct fb_info
*fbi
)
1143 volatile u32
*palette
= lcd
->palette
;
1146 if (regno
> (AU1200_LCD_NBR_PALETTE_ENTRIES
- 1))
1149 if (fbi
->var
.grayscale
) {
1150 /* Convert color to grayscale */
1151 red
= green
= blue
=
1152 (19595 * red
+ 38470 * green
+ 7471 * blue
) >> 16;
1155 if (fbi
->fix
.visual
== FB_VISUAL_TRUECOLOR
) {
1156 /* Place color in the pseudopalette */
1160 palette
= (u32
*) fbi
->pseudo_palette
;
1162 red
>>= (16 - fbi
->var
.red
.length
);
1163 green
>>= (16 - fbi
->var
.green
.length
);
1164 blue
>>= (16 - fbi
->var
.blue
.length
);
1166 value
= (red
<< fbi
->var
.red
.offset
) |
1167 (green
<< fbi
->var
.green
.offset
)|
1168 (blue
<< fbi
->var
.blue
.offset
);
1171 } else if (1 /*FIX!!! panel_is_active(fbdev->panel)*/) {
1172 /* COLOR TFT PALLETTIZED (use RGB 565) */
1173 value
= (red
& 0xF800)|((green
>> 5) &
1174 0x07E0)|((blue
>> 11) & 0x001F);
1177 } else if (0 /*panel_is_color(fbdev->panel)*/) {
1178 /* COLOR STN MODE */
1182 /* MONOCHROME MODE */
1183 value
= (green
>> 12) & 0x000F;
1187 palette
[regno
] = value
;
1193 * Blank the screen. Depending on the mode, the screen will be
1194 * activated with the backlight color, or desactivated
1196 static int au1200fb_fb_blank(int blank_mode
, struct fb_info
*fbi
)
1198 struct au1200fb_device
*fbdev
= fbi
->par
;
1200 /* Short-circuit screen blanking */
1204 switch (blank_mode
) {
1206 case FB_BLANK_UNBLANK
:
1207 case FB_BLANK_NORMAL
:
1208 /* printk("turn on panel\n"); */
1209 au1200_setpanel(panel
, fbdev
->pd
);
1211 case FB_BLANK_VSYNC_SUSPEND
:
1212 case FB_BLANK_HSYNC_SUSPEND
:
1213 case FB_BLANK_POWERDOWN
:
1214 /* printk("turn off panel\n"); */
1215 au1200_setpanel(NULL
, fbdev
->pd
);
1222 /* FB_BLANK_NORMAL is a soft blank */
1223 return (blank_mode
== FB_BLANK_NORMAL
) ? -EINVAL
: 0;
1227 * Map video memory in user space. We don't use the generic fb_mmap
1228 * method mainly to allow the use of the TLB streaming flag (CCA=6)
1230 static int au1200fb_fb_mmap(struct fb_info
*info
, struct vm_area_struct
*vma
)
1232 struct au1200fb_device
*fbdev
= info
->par
;
1234 vma
->vm_page_prot
= pgprot_noncached(vma
->vm_page_prot
);
1235 pgprot_val(vma
->vm_page_prot
) |= _CACHE_MASK
; /* CCA=7 */
1237 return vm_iomap_memory(vma
, fbdev
->fb_phys
, fbdev
->fb_len
);
1240 static void set_global(u_int cmd
, struct au1200_lcd_global_regs_t
*pdata
)
1243 unsigned int hi1
, divider
;
1245 /* SCREEN_SIZE: user cannot reset size, must switch panel choice */
1247 if (pdata
->flags
& SCREEN_BACKCOLOR
)
1248 lcd
->backcolor
= pdata
->backcolor
;
1250 if (pdata
->flags
& SCREEN_BRIGHTNESS
) {
1252 // limit brightness pwm duty to >= 30/1600
1253 if (pdata
->brightness
< 30) {
1254 pdata
->brightness
= 30;
1256 divider
= (lcd
->pwmdiv
& 0x3FFFF) + 1;
1257 hi1
= (((pdata
->brightness
& 0xFF)+1) * divider
>> 8);
1258 lcd
->pwmhi
&= 0xFFFF;
1259 lcd
->pwmhi
|= (hi1
<< 16);
1262 if (pdata
->flags
& SCREEN_COLORKEY
)
1263 lcd
->colorkey
= pdata
->colorkey
;
1265 if (pdata
->flags
& SCREEN_MASK
)
1266 lcd
->colorkeymsk
= pdata
->mask
;
1267 wmb(); /* drain writebuffer */
1270 static void get_global(u_int cmd
, struct au1200_lcd_global_regs_t
*pdata
)
1272 unsigned int hi1
, divider
;
1274 pdata
->xsize
= ((lcd
->screen
& LCD_SCREEN_SX
) >> 19) + 1;
1275 pdata
->ysize
= ((lcd
->screen
& LCD_SCREEN_SY
) >> 8) + 1;
1277 pdata
->backcolor
= lcd
->backcolor
;
1278 pdata
->colorkey
= lcd
->colorkey
;
1279 pdata
->mask
= lcd
->colorkeymsk
;
1282 hi1
= (lcd
->pwmhi
>> 16) + 1;
1283 divider
= (lcd
->pwmdiv
& 0x3FFFF) + 1;
1284 pdata
->brightness
= ((hi1
<< 8) / divider
) - 1;
1285 wmb(); /* drain writebuffer */
1288 static void set_window(unsigned int plane
,
1289 struct au1200_lcd_window_regs_t
*pdata
)
1291 unsigned int val
, bpp
;
1293 /* Window control register 0 */
1294 if (pdata
->flags
& WIN_POSITION
) {
1295 val
= lcd
->window
[plane
].winctrl0
& ~(LCD_WINCTRL0_OX
|
1297 val
|= ((pdata
->xpos
<< 21) & LCD_WINCTRL0_OX
);
1298 val
|= ((pdata
->ypos
<< 10) & LCD_WINCTRL0_OY
);
1299 lcd
->window
[plane
].winctrl0
= val
;
1301 if (pdata
->flags
& WIN_ALPHA_COLOR
) {
1302 val
= lcd
->window
[plane
].winctrl0
& ~(LCD_WINCTRL0_A
);
1303 val
|= ((pdata
->alpha_color
<< 2) & LCD_WINCTRL0_A
);
1304 lcd
->window
[plane
].winctrl0
= val
;
1306 if (pdata
->flags
& WIN_ALPHA_MODE
) {
1307 val
= lcd
->window
[plane
].winctrl0
& ~(LCD_WINCTRL0_AEN
);
1308 val
|= ((pdata
->alpha_mode
<< 1) & LCD_WINCTRL0_AEN
);
1309 lcd
->window
[plane
].winctrl0
= val
;
1312 /* Window control register 1 */
1313 if (pdata
->flags
& WIN_PRIORITY
) {
1314 val
= lcd
->window
[plane
].winctrl1
& ~(LCD_WINCTRL1_PRI
);
1315 val
|= ((pdata
->priority
<< 30) & LCD_WINCTRL1_PRI
);
1316 lcd
->window
[plane
].winctrl1
= val
;
1318 if (pdata
->flags
& WIN_CHANNEL
) {
1319 val
= lcd
->window
[plane
].winctrl1
& ~(LCD_WINCTRL1_PIPE
);
1320 val
|= ((pdata
->channel
<< 29) & LCD_WINCTRL1_PIPE
);
1321 lcd
->window
[plane
].winctrl1
= val
;
1323 if (pdata
->flags
& WIN_BUFFER_FORMAT
) {
1324 val
= lcd
->window
[plane
].winctrl1
& ~(LCD_WINCTRL1_FRM
);
1325 val
|= ((pdata
->buffer_format
<< 25) & LCD_WINCTRL1_FRM
);
1326 lcd
->window
[plane
].winctrl1
= val
;
1328 if (pdata
->flags
& WIN_COLOR_ORDER
) {
1329 val
= lcd
->window
[plane
].winctrl1
& ~(LCD_WINCTRL1_CCO
);
1330 val
|= ((pdata
->color_order
<< 24) & LCD_WINCTRL1_CCO
);
1331 lcd
->window
[plane
].winctrl1
= val
;
1333 if (pdata
->flags
& WIN_PIXEL_ORDER
) {
1334 val
= lcd
->window
[plane
].winctrl1
& ~(LCD_WINCTRL1_PO
);
1335 val
|= ((pdata
->pixel_order
<< 22) & LCD_WINCTRL1_PO
);
1336 lcd
->window
[plane
].winctrl1
= val
;
1338 if (pdata
->flags
& WIN_SIZE
) {
1339 val
= lcd
->window
[plane
].winctrl1
& ~(LCD_WINCTRL1_SZX
|
1341 val
|= (((pdata
->xsize
<< 11) - 1) & LCD_WINCTRL1_SZX
);
1342 val
|= (((pdata
->ysize
) - 1) & LCD_WINCTRL1_SZY
);
1343 lcd
->window
[plane
].winctrl1
= val
;
1344 /* program buffer line width */
1345 bpp
= winbpp(val
) / 8;
1346 val
= lcd
->window
[plane
].winctrl2
& ~(LCD_WINCTRL2_BX
);
1347 val
|= (((pdata
->xsize
* bpp
) << 8) & LCD_WINCTRL2_BX
);
1348 lcd
->window
[plane
].winctrl2
= val
;
1351 /* Window control register 2 */
1352 if (pdata
->flags
& WIN_COLORKEY_MODE
) {
1353 val
= lcd
->window
[plane
].winctrl2
& ~(LCD_WINCTRL2_CKMODE
);
1354 val
|= ((pdata
->colorkey_mode
<< 24) & LCD_WINCTRL2_CKMODE
);
1355 lcd
->window
[plane
].winctrl2
= val
;
1357 if (pdata
->flags
& WIN_DOUBLE_BUFFER_MODE
) {
1358 val
= lcd
->window
[plane
].winctrl2
& ~(LCD_WINCTRL2_DBM
);
1359 val
|= ((pdata
->double_buffer_mode
<< 23) & LCD_WINCTRL2_DBM
);
1360 lcd
->window
[plane
].winctrl2
= val
;
1362 if (pdata
->flags
& WIN_RAM_ARRAY_MODE
) {
1363 val
= lcd
->window
[plane
].winctrl2
& ~(LCD_WINCTRL2_RAM
);
1364 val
|= ((pdata
->ram_array_mode
<< 21) & LCD_WINCTRL2_RAM
);
1365 lcd
->window
[plane
].winctrl2
= val
;
1368 /* Buffer line width programmed with WIN_SIZE */
1370 if (pdata
->flags
& WIN_BUFFER_SCALE
) {
1371 val
= lcd
->window
[plane
].winctrl2
& ~(LCD_WINCTRL2_SCX
|
1373 val
|= ((pdata
->xsize
<< 11) & LCD_WINCTRL2_SCX
);
1374 val
|= ((pdata
->ysize
) & LCD_WINCTRL2_SCY
);
1375 lcd
->window
[plane
].winctrl2
= val
;
1378 if (pdata
->flags
& WIN_ENABLE
) {
1379 val
= lcd
->winenable
;
1381 val
|= (pdata
->enable
& 1) << plane
;
1382 lcd
->winenable
= val
;
1384 wmb(); /* drain writebuffer */
1387 static void get_window(unsigned int plane
,
1388 struct au1200_lcd_window_regs_t
*pdata
)
1390 /* Window control register 0 */
1391 pdata
->xpos
= (lcd
->window
[plane
].winctrl0
& LCD_WINCTRL0_OX
) >> 21;
1392 pdata
->ypos
= (lcd
->window
[plane
].winctrl0
& LCD_WINCTRL0_OY
) >> 10;
1393 pdata
->alpha_color
= (lcd
->window
[plane
].winctrl0
& LCD_WINCTRL0_A
) >> 2;
1394 pdata
->alpha_mode
= (lcd
->window
[plane
].winctrl0
& LCD_WINCTRL0_AEN
) >> 1;
1396 /* Window control register 1 */
1397 pdata
->priority
= (lcd
->window
[plane
].winctrl1
& LCD_WINCTRL1_PRI
) >> 30;
1398 pdata
->channel
= (lcd
->window
[plane
].winctrl1
& LCD_WINCTRL1_PIPE
) >> 29;
1399 pdata
->buffer_format
= (lcd
->window
[plane
].winctrl1
& LCD_WINCTRL1_FRM
) >> 25;
1400 pdata
->color_order
= (lcd
->window
[plane
].winctrl1
& LCD_WINCTRL1_CCO
) >> 24;
1401 pdata
->pixel_order
= (lcd
->window
[plane
].winctrl1
& LCD_WINCTRL1_PO
) >> 22;
1402 pdata
->xsize
= ((lcd
->window
[plane
].winctrl1
& LCD_WINCTRL1_SZX
) >> 11) + 1;
1403 pdata
->ysize
= (lcd
->window
[plane
].winctrl1
& LCD_WINCTRL1_SZY
) + 1;
1405 /* Window control register 2 */
1406 pdata
->colorkey_mode
= (lcd
->window
[plane
].winctrl2
& LCD_WINCTRL2_CKMODE
) >> 24;
1407 pdata
->double_buffer_mode
= (lcd
->window
[plane
].winctrl2
& LCD_WINCTRL2_DBM
) >> 23;
1408 pdata
->ram_array_mode
= (lcd
->window
[plane
].winctrl2
& LCD_WINCTRL2_RAM
) >> 21;
1410 pdata
->enable
= (lcd
->winenable
>> plane
) & 1;
1411 wmb(); /* drain writebuffer */
1414 static int au1200fb_ioctl(struct fb_info
*info
, unsigned int cmd
,
1417 struct au1200fb_device
*fbdev
= info
->par
;
1421 plane
= fbinfo2index(info
);
1422 print_dbg("au1200fb: ioctl %d on plane %d\n", cmd
, plane
);
1424 if (cmd
== AU1200_LCD_FB_IOCTL
) {
1425 struct au1200_lcd_iodata_t iodata
;
1427 if (copy_from_user(&iodata
, (void __user
*) arg
, sizeof(iodata
)))
1430 print_dbg("FB IOCTL called\n");
1432 switch (iodata
.subcmd
) {
1433 case AU1200_LCD_SET_SCREEN
:
1434 print_dbg("AU1200_LCD_SET_SCREEN\n");
1435 set_global(cmd
, &iodata
.global
);
1438 case AU1200_LCD_GET_SCREEN
:
1439 print_dbg("AU1200_LCD_GET_SCREEN\n");
1440 get_global(cmd
, &iodata
.global
);
1443 case AU1200_LCD_SET_WINDOW
:
1444 print_dbg("AU1200_LCD_SET_WINDOW\n");
1445 set_window(plane
, &iodata
.window
);
1448 case AU1200_LCD_GET_WINDOW
:
1449 print_dbg("AU1200_LCD_GET_WINDOW\n");
1450 get_window(plane
, &iodata
.window
);
1453 case AU1200_LCD_SET_PANEL
:
1454 print_dbg("AU1200_LCD_SET_PANEL\n");
1455 if ((iodata
.global
.panel_choice
>= 0) &&
1456 (iodata
.global
.panel_choice
<
1459 struct panel_settings
*newpanel
;
1460 panel_index
= iodata
.global
.panel_choice
;
1461 newpanel
= &known_lcd_panels
[panel_index
];
1462 au1200_setpanel(newpanel
, fbdev
->pd
);
1466 case AU1200_LCD_GET_PANEL
:
1467 print_dbg("AU1200_LCD_GET_PANEL\n");
1468 iodata
.global
.panel_choice
= panel_index
;
1475 val
= copy_to_user((void __user
*) arg
, &iodata
, sizeof(iodata
));
1477 print_dbg("error: could not copy %d bytes\n", val
);
1486 static struct fb_ops au1200fb_fb_ops
= {
1487 .owner
= THIS_MODULE
,
1488 .fb_check_var
= au1200fb_fb_check_var
,
1489 .fb_set_par
= au1200fb_fb_set_par
,
1490 .fb_setcolreg
= au1200fb_fb_setcolreg
,
1491 .fb_blank
= au1200fb_fb_blank
,
1492 .fb_fillrect
= sys_fillrect
,
1493 .fb_copyarea
= sys_copyarea
,
1494 .fb_imageblit
= sys_imageblit
,
1495 .fb_read
= fb_sys_read
,
1496 .fb_write
= fb_sys_write
,
1498 .fb_ioctl
= au1200fb_ioctl
,
1499 .fb_mmap
= au1200fb_fb_mmap
,
1502 /*-------------------------------------------------------------------------*/
1504 static irqreturn_t
au1200fb_handle_irq(int irq
, void* dev_id
)
1506 /* Nothing to do for now, just clear any pending interrupt */
1507 lcd
->intstatus
= lcd
->intstatus
;
1508 wmb(); /* drain writebuffer */
1513 /*-------------------------------------------------------------------------*/
1515 /* AU1200 LCD device probe helpers */
1517 static int au1200fb_init_fbinfo(struct au1200fb_device
*fbdev
)
1519 struct fb_info
*fbi
= fbdev
->fb_info
;
1522 fbi
->fbops
= &au1200fb_fb_ops
;
1524 bpp
= winbpp(win
->w
[fbdev
->plane
].mode_winctrl1
);
1526 /* Copy monitor specs from panel data */
1527 /* fixme: we're setting up LCD controller windows, so these dont give a
1528 damn as to what the monitor specs are (the panel itself does, but that
1529 isn't done here...so maybe need a generic catchall monitor setting??? */
1530 memcpy(&fbi
->monspecs
, &panel
->monspecs
, sizeof(struct fb_monspecs
));
1532 /* We first try the user mode passed in argument. If that failed,
1533 * or if no one has been specified, we default to the first mode of the
1534 * panel list. Note that after this call, var data will be set */
1535 if (!fb_find_mode(&fbi
->var
,
1537 NULL
, /* drv_info.opt_mode, */
1538 fbi
->monspecs
.modedb
,
1539 fbi
->monspecs
.modedb_len
,
1540 fbi
->monspecs
.modedb
,
1543 print_err("Cannot find valid mode for panel %s", panel
->name
);
1547 fbi
->pseudo_palette
= kcalloc(16, sizeof(u32
), GFP_KERNEL
);
1548 if (!fbi
->pseudo_palette
) {
1552 if (fb_alloc_cmap(&fbi
->cmap
, AU1200_LCD_NBR_PALETTE_ENTRIES
, 0) < 0) {
1553 print_err("Fail to allocate colormap (%d entries)",
1554 AU1200_LCD_NBR_PALETTE_ENTRIES
);
1555 kfree(fbi
->pseudo_palette
);
1559 strncpy(fbi
->fix
.id
, "AU1200", sizeof(fbi
->fix
.id
));
1560 fbi
->fix
.smem_start
= fbdev
->fb_phys
;
1561 fbi
->fix
.smem_len
= fbdev
->fb_len
;
1562 fbi
->fix
.type
= FB_TYPE_PACKED_PIXELS
;
1563 fbi
->fix
.xpanstep
= 0;
1564 fbi
->fix
.ypanstep
= 0;
1565 fbi
->fix
.mmio_start
= 0;
1566 fbi
->fix
.mmio_len
= 0;
1567 fbi
->fix
.accel
= FB_ACCEL_NONE
;
1569 fbi
->screen_base
= (char __iomem
*) fbdev
->fb_mem
;
1571 au1200fb_update_fbinfo(fbi
);
1576 /*-------------------------------------------------------------------------*/
1579 static int au1200fb_setup(struct au1200fb_platdata
*pd
)
1581 char *options
= NULL
;
1582 char *this_opt
, *endptr
;
1583 int num_panels
= ARRAY_SIZE(known_lcd_panels
);
1586 fb_get_options(DRIVER_NAME
, &options
);
1591 while ((this_opt
= strsep(&options
, ",")) != NULL
) {
1592 /* Panel option - can be panel name,
1593 * "bs" for board-switch, or number/index */
1594 if (!strncmp(this_opt
, "panel:", 6)) {
1599 /* First check for index, which allows
1600 * to short circuit this mess */
1601 li
= simple_strtol(this_opt
, &endptr
, 0);
1602 if (*endptr
== '\0')
1603 panel_idx
= (int)li
;
1604 else if (strcmp(this_opt
, "bs") == 0)
1605 panel_idx
= pd
->panel_index();
1607 for (i
= 0; i
< num_panels
; i
++) {
1608 if (!strcmp(this_opt
,
1609 known_lcd_panels
[i
].name
)) {
1615 if ((panel_idx
< 0) || (panel_idx
>= num_panels
))
1616 print_warn("Panel %s not supported!", this_opt
);
1618 panel_index
= panel_idx
;
1620 } else if (strncmp(this_opt
, "nohwcursor", 10) == 0)
1622 else if (strncmp(this_opt
, "devices:", 8) == 0) {
1624 device_count
= simple_strtol(this_opt
, &endptr
, 0);
1625 if ((device_count
< 0) ||
1626 (device_count
> MAX_DEVICE_COUNT
))
1627 device_count
= MAX_DEVICE_COUNT
;
1628 } else if (strncmp(this_opt
, "wincfg:", 7) == 0) {
1630 window_index
= simple_strtol(this_opt
, &endptr
, 0);
1631 if ((window_index
< 0) ||
1632 (window_index
>= ARRAY_SIZE(windows
)))
1633 window_index
= DEFAULT_WINDOW_INDEX
;
1634 } else if (strncmp(this_opt
, "off", 3) == 0)
1637 print_warn("Unsupported option \"%s\"", this_opt
);
1644 /* AU1200 LCD controller device driver */
1645 static int au1200fb_drv_probe(struct platform_device
*dev
)
1647 struct au1200fb_device
*fbdev
;
1648 struct au1200fb_platdata
*pd
;
1649 struct fb_info
*fbi
= NULL
;
1651 int bpp
, plane
, ret
, irq
;
1653 print_info("" DRIVER_DESC
"");
1655 pd
= dev
->dev
.platform_data
;
1659 /* Setup driver with options */
1660 if (au1200fb_setup(pd
))
1663 /* Point to the panel selected */
1664 panel
= &known_lcd_panels
[panel_index
];
1665 win
= &windows
[window_index
];
1667 printk(DRIVER_NAME
": Panel %d %s\n", panel_index
, panel
->name
);
1668 printk(DRIVER_NAME
": Win %d %s\n", window_index
, win
->name
);
1674 for (plane
= 0; plane
< device_count
; ++plane
) {
1675 bpp
= winbpp(win
->w
[plane
].mode_winctrl1
);
1676 if (win
->w
[plane
].xres
== 0)
1677 win
->w
[plane
].xres
= panel
->Xres
;
1678 if (win
->w
[plane
].yres
== 0)
1679 win
->w
[plane
].yres
= panel
->Yres
;
1681 fbi
= framebuffer_alloc(sizeof(struct au1200fb_device
),
1686 _au1200fb_infos
[plane
] = fbi
;
1688 fbdev
->fb_info
= fbi
;
1691 fbdev
->plane
= plane
;
1693 /* Allocate the framebuffer to the maximum screen size */
1694 fbdev
->fb_len
= (win
->w
[plane
].xres
* win
->w
[plane
].yres
* bpp
) / 8;
1696 fbdev
->fb_mem
= dmam_alloc_noncoherent(&dev
->dev
,
1697 PAGE_ALIGN(fbdev
->fb_len
),
1698 &fbdev
->fb_phys
, GFP_KERNEL
);
1699 if (!fbdev
->fb_mem
) {
1700 print_err("fail to allocate frambuffer (size: %dK))",
1701 fbdev
->fb_len
/ 1024);
1706 * Set page reserved so that mmap will work. This is necessary
1707 * since we'll be remapping normal memory.
1709 for (page
= (unsigned long)fbdev
->fb_phys
;
1710 page
< PAGE_ALIGN((unsigned long)fbdev
->fb_phys
+
1712 page
+= PAGE_SIZE
) {
1713 SetPageReserved(pfn_to_page(page
>> PAGE_SHIFT
)); /* LCD DMA is NOT coherent on Au1200 */
1715 print_dbg("Framebuffer memory map at %p", fbdev
->fb_mem
);
1716 print_dbg("phys=0x%08x, size=%dK", fbdev
->fb_phys
, fbdev
->fb_len
/ 1024);
1719 if ((ret
= au1200fb_init_fbinfo(fbdev
)) < 0)
1722 /* Register new framebuffer */
1723 ret
= register_framebuffer(fbi
);
1725 print_err("cannot register new framebuffer");
1729 au1200fb_fb_set_par(fbi
);
1731 #if !defined(CONFIG_FRAMEBUFFER_CONSOLE) && defined(CONFIG_LOGO)
1733 if (fb_prepare_logo(fbi
, FB_ROTATE_UR
)) {
1734 /* Start display and show logo on boot */
1735 fb_set_cmap(&fbi
->cmap
, fbi
);
1736 fb_show_logo(fbi
, FB_ROTATE_UR
);
1741 /* Now hook interrupt too */
1742 irq
= platform_get_irq(dev
, 0);
1743 ret
= request_irq(irq
, au1200fb_handle_irq
,
1744 IRQF_SHARED
, "lcd", (void *)dev
);
1746 print_err("fail to request interrupt line %d (err: %d)",
1751 platform_set_drvdata(dev
, pd
);
1753 /* Kickstart the panel */
1754 au1200_setpanel(panel
, pd
);
1759 /* NOTE: This only does the current plane/window that failed; others are still active */
1761 if (fbi
->cmap
.len
!= 0)
1762 fb_dealloc_cmap(&fbi
->cmap
);
1763 kfree(fbi
->pseudo_palette
);
1766 free_irq(AU1200_LCD_INT
, (void*)dev
);
1770 static int au1200fb_drv_remove(struct platform_device
*dev
)
1772 struct au1200fb_platdata
*pd
= platform_get_drvdata(dev
);
1773 struct au1200fb_device
*fbdev
;
1774 struct fb_info
*fbi
;
1777 /* Turn off the panel */
1778 au1200_setpanel(NULL
, pd
);
1780 for (plane
= 0; plane
< device_count
; ++plane
) {
1781 fbi
= _au1200fb_infos
[plane
];
1784 /* Clean up all probe data */
1785 unregister_framebuffer(fbi
);
1786 if (fbi
->cmap
.len
!= 0)
1787 fb_dealloc_cmap(&fbi
->cmap
);
1788 kfree(fbi
->pseudo_palette
);
1790 framebuffer_release(fbi
);
1791 _au1200fb_infos
[plane
] = NULL
;
1794 free_irq(platform_get_irq(dev
, 0), (void *)dev
);
1800 static int au1200fb_drv_suspend(struct device
*dev
)
1802 struct au1200fb_platdata
*pd
= dev_get_drvdata(dev
);
1803 au1200_setpanel(NULL
, pd
);
1806 wmb(); /* drain writebuffer */
1811 static int au1200fb_drv_resume(struct device
*dev
)
1813 struct au1200fb_platdata
*pd
= dev_get_drvdata(dev
);
1814 struct fb_info
*fbi
;
1817 /* Kickstart the panel */
1818 au1200_setpanel(panel
, pd
);
1820 for (i
= 0; i
< device_count
; i
++) {
1821 fbi
= _au1200fb_infos
[i
];
1822 au1200fb_fb_set_par(fbi
);
1828 static const struct dev_pm_ops au1200fb_pmops
= {
1829 .suspend
= au1200fb_drv_suspend
,
1830 .resume
= au1200fb_drv_resume
,
1831 .freeze
= au1200fb_drv_suspend
,
1832 .thaw
= au1200fb_drv_resume
,
1835 #define AU1200FB_PMOPS (&au1200fb_pmops)
1838 #define AU1200FB_PMOPS NULL
1839 #endif /* CONFIG_PM */
1841 static struct platform_driver au1200fb_driver
= {
1843 .name
= "au1200-lcd",
1844 .pm
= AU1200FB_PMOPS
,
1846 .probe
= au1200fb_drv_probe
,
1847 .remove
= au1200fb_drv_remove
,
1849 module_platform_driver(au1200fb_driver
);
1851 MODULE_DESCRIPTION(DRIVER_DESC
);
1852 MODULE_LICENSE("GPL");