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>
47 #include <asm/mach-au1x00/au1200fb.h> /* platform_data */
50 #define DRIVER_NAME "au1200fb"
51 #define DRIVER_DESC "LCD controller driver for AU1200 processors"
55 #define print_err(f, arg...) printk(KERN_ERR DRIVER_NAME ": " f "\n", ## arg)
56 #define print_warn(f, arg...) printk(KERN_WARNING DRIVER_NAME ": " f "\n", ## arg)
57 #define print_info(f, arg...) printk(KERN_INFO DRIVER_NAME ": " f "\n", ## arg)
60 #define print_dbg(f, arg...) printk(KERN_DEBUG __FILE__ ": " f "\n", ## arg)
62 #define print_dbg(f, arg...) do {} while (0)
66 #define AU1200_LCD_FB_IOCTL 0x46FF
68 #define AU1200_LCD_SET_SCREEN 1
69 #define AU1200_LCD_GET_SCREEN 2
70 #define AU1200_LCD_SET_WINDOW 3
71 #define AU1200_LCD_GET_WINDOW 4
72 #define AU1200_LCD_SET_PANEL 5
73 #define AU1200_LCD_GET_PANEL 6
75 #define SCREEN_SIZE (1<< 1)
76 #define SCREEN_BACKCOLOR (1<< 2)
77 #define SCREEN_BRIGHTNESS (1<< 3)
78 #define SCREEN_COLORKEY (1<< 4)
79 #define SCREEN_MASK (1<< 5)
81 struct au1200_lcd_global_regs_t {
85 unsigned int backcolor;
86 unsigned int brightness;
87 unsigned int colorkey;
89 unsigned int panel_choice;
94 #define WIN_POSITION (1<< 0)
95 #define WIN_ALPHA_COLOR (1<< 1)
96 #define WIN_ALPHA_MODE (1<< 2)
97 #define WIN_PRIORITY (1<< 3)
98 #define WIN_CHANNEL (1<< 4)
99 #define WIN_BUFFER_FORMAT (1<< 5)
100 #define WIN_COLOR_ORDER (1<< 6)
101 #define WIN_PIXEL_ORDER (1<< 7)
102 #define WIN_SIZE (1<< 8)
103 #define WIN_COLORKEY_MODE (1<< 9)
104 #define WIN_DOUBLE_BUFFER_MODE (1<< 10)
105 #define WIN_RAM_ARRAY_MODE (1<< 11)
106 #define WIN_BUFFER_SCALE (1<< 12)
107 #define WIN_ENABLE (1<< 13)
109 struct au1200_lcd_window_regs_t {
113 unsigned int alpha_color;
114 unsigned int alpha_mode;
115 unsigned int priority;
116 unsigned int channel;
117 unsigned int buffer_format;
118 unsigned int color_order;
119 unsigned int pixel_order;
122 unsigned int colorkey_mode;
123 unsigned int double_buffer_mode;
124 unsigned int ram_array_mode;
131 struct au1200_lcd_iodata_t {
133 struct au1200_lcd_global_regs_t global;
134 struct au1200_lcd_window_regs_t window;
137 #if defined(__BIG_ENDIAN)
138 #define LCD_CONTROL_DEFAULT_PO LCD_CONTROL_PO_11
140 #define LCD_CONTROL_DEFAULT_PO LCD_CONTROL_PO_00
142 #define LCD_CONTROL_DEFAULT_SBPPF LCD_CONTROL_SBPPF_565
144 /* Private, per-framebuffer management information (independent of the panel itself) */
145 struct au1200fb_device {
146 struct fb_info *fb_info; /* FB driver info record */
147 struct au1200fb_platdata *pd;
150 unsigned char* fb_mem; /* FrameBuffer memory map */
155 /********************************************************************/
157 /* LCD controller restrictions */
158 #define AU1200_LCD_MAX_XRES 1280
159 #define AU1200_LCD_MAX_YRES 1024
160 #define AU1200_LCD_MAX_BPP 32
161 #define AU1200_LCD_MAX_CLK 96000000 /* fixme: this needs to go away ? */
162 #define AU1200_LCD_NBR_PALETTE_ENTRIES 256
164 /* Default number of visible screen buffer to allocate */
165 #define AU1200FB_NBR_VIDEO_BUFFERS 1
167 /* Default maximum number of fb devices to create */
168 #define MAX_DEVICE_COUNT 4
170 /* Default window configuration entry to use (see windows[]) */
171 #define DEFAULT_WINDOW_INDEX 2
173 /********************************************************************/
175 static struct fb_info *_au1200fb_infos[MAX_DEVICE_COUNT];
176 static struct au1200_lcd *lcd = (struct au1200_lcd *) AU1200_LCD_ADDR;
177 static int device_count = MAX_DEVICE_COUNT;
178 static int window_index = DEFAULT_WINDOW_INDEX; /* default is zero */
179 static int panel_index = 2; /* default is zero */
180 static struct window_settings *win;
181 static struct panel_settings *panel;
182 static int noblanking = 1;
183 static int nohwcursor = 0;
185 struct window_settings {
186 unsigned char name[64];
187 uint32 mode_backcolor;
188 uint32 mode_colorkey;
189 uint32 mode_colorkeymsk;
195 uint32 mode_winctrl1; /* winctrl1[FRM,CCO,PO,PIPE] */
196 uint32 mode_winenable;
200 #if defined(__BIG_ENDIAN)
201 #define LCD_WINCTRL1_PO_16BPP LCD_WINCTRL1_PO_00
203 #define LCD_WINCTRL1_PO_16BPP LCD_WINCTRL1_PO_01
207 * Default window configurations
209 static struct window_settings windows[] = {
211 "0-FS gfx, 1-video, 2-ovly gfx, 3-ovly gfx",
212 /* mode_backcolor */ 0x006600ff,
213 /* mode_colorkey,msk*/ 0, 0,
216 /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
217 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
218 LCD_WINCTRL1_PO_16BPP,
219 /* mode_winenable*/ LCD_WINENABLE_WEN0,
222 /* xres, yres, xpos, ypos */ 100, 100, 100, 100,
223 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
224 LCD_WINCTRL1_PO_16BPP |
226 /* mode_winenable*/ LCD_WINENABLE_WEN1,
229 /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
230 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
231 LCD_WINCTRL1_PO_16BPP,
232 /* mode_winenable*/ 0,
235 /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
236 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
237 LCD_WINCTRL1_PO_16BPP |
239 /* mode_winenable*/ 0,
245 "0-FS gfx, 1-video, 2-ovly gfx, 3-ovly gfx",
246 /* mode_backcolor */ 0x006600ff,
247 /* mode_colorkey,msk*/ 0, 0,
250 /* xres, yres, xpos, ypos */ 320, 240, 5, 5,
251 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_24BPP |
253 /* mode_winenable*/ LCD_WINENABLE_WEN0,
256 /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
257 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565
258 | LCD_WINCTRL1_PO_16BPP,
259 /* mode_winenable*/ 0,
262 /* xres, yres, xpos, ypos */ 100, 100, 0, 0,
263 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
264 LCD_WINCTRL1_PO_16BPP |
266 /* mode_winenable*/ 0/*LCD_WINENABLE_WEN2*/,
269 /* xres, yres, xpos, ypos */ 200, 25, 0, 0,
270 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
271 LCD_WINCTRL1_PO_16BPP |
273 /* mode_winenable*/ 0,
278 "0-FS gfx, 1-video, 2-ovly gfx, 3-ovly gfx",
279 /* mode_backcolor */ 0x006600ff,
280 /* mode_colorkey,msk*/ 0, 0,
283 /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
284 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
285 LCD_WINCTRL1_PO_16BPP,
286 /* mode_winenable*/ LCD_WINENABLE_WEN0,
289 /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
290 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
291 LCD_WINCTRL1_PO_16BPP,
292 /* mode_winenable*/ 0,
295 /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
296 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_32BPP |
297 LCD_WINCTRL1_PO_00|LCD_WINCTRL1_PIPE,
298 /* mode_winenable*/ 0/*LCD_WINENABLE_WEN2*/,
301 /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
302 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
303 LCD_WINCTRL1_PO_16BPP |
305 /* mode_winenable*/ 0,
309 /* Need VGA 640 @ 24bpp, @ 32bpp */
310 /* Need VGA 800 @ 24bpp, @ 32bpp */
311 /* Need VGA 1024 @ 24bpp, @ 32bpp */
315 * Controller configurations for various panels.
318 struct panel_settings
320 const char name[25]; /* Full name <vendor>_<model> */
322 struct fb_monspecs monspecs; /* FB monitor specs */
326 uint32 mode_horztiming;
327 uint32 mode_verttiming;
328 uint32 mode_clkcontrol;
332 uint32 mode_fifoctrl;
333 uint32 mode_toyclksrc;
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_toyclksrc = 0x00000004, /* AUXPLL directly */
383 .mode_backlight = 0x00000000,
384 .mode_auxpll = 8, /* 96MHz AUXPLL */
389 [1] = { /* VGA 640x480 H:30.3kHz V:58Hz */
390 .name = "VGA_640x480",
400 .input = FB_DISP_RGB,
402 .mode_screen = 0x13f9df80,
403 .mode_horztiming = 0x003c5859,
404 .mode_verttiming = 0x00741201,
405 .mode_clkcontrol = 0x00020001, /* /4=24Mhz */
406 .mode_pwmdiv = 0x00000000,
407 .mode_pwmhi = 0x00000000,
408 .mode_outmask = 0x00FFFFFF,
409 .mode_fifoctrl = 0x2f2f2f2f,
410 .mode_toyclksrc = 0x00000004, /* AUXPLL directly */
411 .mode_backlight = 0x00000000,
412 .mode_auxpll = 8, /* 96MHz AUXPLL */
417 [2] = { /* SVGA 800x600 H:46.1kHz V:69Hz */
418 .name = "SVGA_800x600",
428 .input = FB_DISP_RGB,
430 .mode_screen = 0x18fa5780,
431 .mode_horztiming = 0x00dc7e77,
432 .mode_verttiming = 0x00584805,
433 .mode_clkcontrol = 0x00020000, /* /2=48Mhz */
434 .mode_pwmdiv = 0x00000000,
435 .mode_pwmhi = 0x00000000,
436 .mode_outmask = 0x00FFFFFF,
437 .mode_fifoctrl = 0x2f2f2f2f,
438 .mode_toyclksrc = 0x00000004, /* AUXPLL directly */
439 .mode_backlight = 0x00000000,
440 .mode_auxpll = 8, /* 96MHz AUXPLL */
445 [3] = { /* XVGA 1024x768 H:56.2kHz V:70Hz */
446 .name = "XVGA_1024x768",
456 .input = FB_DISP_RGB,
458 .mode_screen = 0x1ffaff80,
459 .mode_horztiming = 0x007d0e57,
460 .mode_verttiming = 0x00740a01,
461 .mode_clkcontrol = 0x000A0000, /* /1 */
462 .mode_pwmdiv = 0x00000000,
463 .mode_pwmhi = 0x00000000,
464 .mode_outmask = 0x00FFFFFF,
465 .mode_fifoctrl = 0x2f2f2f2f,
466 .mode_toyclksrc = 0x00000004, /* AUXPLL directly */
467 .mode_backlight = 0x00000000,
468 .mode_auxpll = 6, /* 72MHz AUXPLL */
473 [4] = { /* XVGA XVGA 1280x1024 H:68.5kHz V:65Hz */
474 .name = "XVGA_1280x1024",
484 .input = FB_DISP_RGB,
486 .mode_screen = 0x27fbff80,
487 .mode_horztiming = 0x00cdb2c7,
488 .mode_verttiming = 0x00600002,
489 .mode_clkcontrol = 0x000A0000, /* /1 */
490 .mode_pwmdiv = 0x00000000,
491 .mode_pwmhi = 0x00000000,
492 .mode_outmask = 0x00FFFFFF,
493 .mode_fifoctrl = 0x2f2f2f2f,
494 .mode_toyclksrc = 0x00000004, /* AUXPLL directly */
495 .mode_backlight = 0x00000000,
496 .mode_auxpll = 10, /* 120MHz AUXPLL */
501 [5] = { /* Samsung 1024x768 TFT */
502 .name = "Samsung_1024x768_TFT",
512 .input = FB_DISP_RGB,
514 .mode_screen = 0x1ffaff80,
515 .mode_horztiming = 0x018cc677,
516 .mode_verttiming = 0x00241217,
517 .mode_clkcontrol = 0x00000000, /* SCB 0x1 /4=24Mhz */
518 .mode_pwmdiv = 0x8000063f, /* SCB 0x0 */
519 .mode_pwmhi = 0x03400000, /* SCB 0x0 */
520 .mode_outmask = 0x00FFFFFF,
521 .mode_fifoctrl = 0x2f2f2f2f,
522 .mode_toyclksrc = 0x00000004, /* AUXPLL directly */
523 .mode_backlight = 0x00000000,
524 .mode_auxpll = 8, /* 96MHz AUXPLL */
529 [6] = { /* Toshiba 640x480 TFT */
530 .name = "Toshiba_640x480_TFT",
540 .input = FB_DISP_RGB,
542 .mode_screen = LCD_SCREEN_SX_N(640) |
543 LCD_SCREEN_SY_N(480),
544 .mode_horztiming = LCD_HORZTIMING_HPW_N(96) |
545 LCD_HORZTIMING_HND1_N(13) | LCD_HORZTIMING_HND2_N(51),
546 .mode_verttiming = LCD_VERTTIMING_VPW_N(2) |
547 LCD_VERTTIMING_VND1_N(11) | LCD_VERTTIMING_VND2_N(32),
548 .mode_clkcontrol = 0x00000000, /* /4=24Mhz */
549 .mode_pwmdiv = 0x8000063f,
550 .mode_pwmhi = 0x03400000,
551 .mode_outmask = 0x00fcfcfc,
552 .mode_fifoctrl = 0x2f2f2f2f,
553 .mode_toyclksrc = 0x00000004, /* AUXPLL directly */
554 .mode_backlight = 0x00000000,
555 .mode_auxpll = 8, /* 96MHz AUXPLL */
560 [7] = { /* Sharp 320x240 TFT */
561 .name = "Sharp_320x240_TFT",
571 .input = FB_DISP_RGB,
573 .mode_screen = LCD_SCREEN_SX_N(320) |
574 LCD_SCREEN_SY_N(240),
575 .mode_horztiming = LCD_HORZTIMING_HPW_N(60) |
576 LCD_HORZTIMING_HND1_N(13) | LCD_HORZTIMING_HND2_N(2),
577 .mode_verttiming = LCD_VERTTIMING_VPW_N(2) |
578 LCD_VERTTIMING_VND1_N(2) | LCD_VERTTIMING_VND2_N(5),
579 .mode_clkcontrol = LCD_CLKCONTROL_PCD_N(7), /*16=6Mhz*/
580 .mode_pwmdiv = 0x8000063f,
581 .mode_pwmhi = 0x03400000,
582 .mode_outmask = 0x00fcfcfc,
583 .mode_fifoctrl = 0x2f2f2f2f,
584 .mode_toyclksrc = 0x00000004, /* AUXPLL directly */
585 .mode_backlight = 0x00000000,
586 .mode_auxpll = 8, /* 96MHz AUXPLL */
591 [8] = { /* Toppoly TD070WGCB2 7" 856x480 TFT */
592 .name = "Toppoly_TD070WGCB2",
602 .input = FB_DISP_RGB,
604 .mode_screen = LCD_SCREEN_SX_N(856) |
605 LCD_SCREEN_SY_N(480),
606 .mode_horztiming = LCD_HORZTIMING_HND2_N(43) |
607 LCD_HORZTIMING_HND1_N(43) | LCD_HORZTIMING_HPW_N(114),
608 .mode_verttiming = LCD_VERTTIMING_VND2_N(20) |
609 LCD_VERTTIMING_VND1_N(21) | LCD_VERTTIMING_VPW_N(4),
610 .mode_clkcontrol = 0x00020001, /* /4=24Mhz */
611 .mode_pwmdiv = 0x8000063f,
612 .mode_pwmhi = 0x03400000,
613 .mode_outmask = 0x00fcfcfc,
614 .mode_fifoctrl = 0x2f2f2f2f,
615 .mode_toyclksrc = 0x00000004, /* AUXPLL directly */
616 .mode_backlight = 0x00000000,
617 .mode_auxpll = 8, /* 96MHz AUXPLL */
622 .name = "DB1300_800x480",
632 .input = FB_DISP_RGB,
634 .mode_screen = LCD_SCREEN_SX_N(800) |
635 LCD_SCREEN_SY_N(480),
636 .mode_horztiming = LCD_HORZTIMING_HPW_N(5) |
637 LCD_HORZTIMING_HND1_N(16) |
638 LCD_HORZTIMING_HND2_N(8),
639 .mode_verttiming = LCD_VERTTIMING_VPW_N(4) |
640 LCD_VERTTIMING_VND1_N(8) |
641 LCD_VERTTIMING_VND2_N(5),
642 .mode_clkcontrol = LCD_CLKCONTROL_PCD_N(1) |
645 .mode_pwmdiv = 0x00000000,
646 .mode_pwmhi = 0x00000000,
647 .mode_outmask = 0x00FFFFFF,
648 .mode_fifoctrl = 0x2f2f2f2f,
649 .mode_toyclksrc = 0x00000004, /* AUXPLL directly */
650 .mode_backlight = 0x00000000,
651 .mode_auxpll = (48/12) * 2,
657 #define NUM_PANELS (ARRAY_SIZE(known_lcd_panels))
659 /********************************************************************/
661 static int winbpp (unsigned int winctrl1)
665 /* how many bits are needed for each pixel format */
666 switch (winctrl1 & LCD_WINCTRL1_FRM) {
667 case LCD_WINCTRL1_FRM_1BPP:
670 case LCD_WINCTRL1_FRM_2BPP:
673 case LCD_WINCTRL1_FRM_4BPP:
676 case LCD_WINCTRL1_FRM_8BPP:
679 case LCD_WINCTRL1_FRM_12BPP:
680 case LCD_WINCTRL1_FRM_16BPP655:
681 case LCD_WINCTRL1_FRM_16BPP565:
682 case LCD_WINCTRL1_FRM_16BPP556:
683 case LCD_WINCTRL1_FRM_16BPPI1555:
684 case LCD_WINCTRL1_FRM_16BPPI5551:
685 case LCD_WINCTRL1_FRM_16BPPA1555:
686 case LCD_WINCTRL1_FRM_16BPPA5551:
689 case LCD_WINCTRL1_FRM_24BPP:
690 case LCD_WINCTRL1_FRM_32BPP:
698 static int fbinfo2index (struct fb_info *fb_info)
702 for (i = 0; i < device_count; ++i) {
703 if (fb_info == _au1200fb_infos[i])
706 printk("au1200fb: ERROR: fbinfo2index failed!\n");
710 static int au1200_setlocation (struct au1200fb_device *fbdev, int plane,
713 uint32 winctrl0, winctrl1, winenable, fb_offset = 0;
716 /* FIX!!! NOT CHECKING FOR COMPLETE OFFSCREEN YET */
718 winctrl0 = lcd->window[plane].winctrl0;
719 winctrl1 = lcd->window[plane].winctrl1;
720 winctrl0 &= (LCD_WINCTRL0_A | LCD_WINCTRL0_AEN);
721 winctrl1 &= ~(LCD_WINCTRL1_SZX | LCD_WINCTRL1_SZY);
723 /* Check for off-screen adjustments */
724 xsz = win->w[plane].xres;
725 ysz = win->w[plane].yres;
726 if ((xpos + win->w[plane].xres) > panel->Xres) {
727 /* Off-screen to the right */
728 xsz = panel->Xres - xpos; /* off by 1 ??? */
729 /*printk("off screen right\n");*/
732 if ((ypos + win->w[plane].yres) > panel->Yres) {
733 /* Off-screen to the bottom */
734 ysz = panel->Yres - ypos; /* off by 1 ??? */
735 /*printk("off screen bottom\n");*/
739 /* Off-screen to the left */
740 xsz = win->w[plane].xres + xpos;
741 fb_offset += (((0 - xpos) * winbpp(lcd->window[plane].winctrl1))/8);
743 /*printk("off screen left\n");*/
747 /* Off-screen to the top */
748 ysz = win->w[plane].yres + ypos;
749 /* fixme: fb_offset += ((0-ypos)*fb_pars[plane].line_length); */
751 /*printk("off screen top\n");*/
754 /* record settings */
755 win->w[plane].xpos = xpos;
756 win->w[plane].ypos = ypos;
760 winctrl0 |= (xpos << 21);
761 winctrl0 |= (ypos << 10);
762 winctrl1 |= (xsz << 11);
763 winctrl1 |= (ysz << 0);
765 /* Disable the window while making changes, then restore WINEN */
766 winenable = lcd->winenable & (1 << plane);
768 lcd->winenable &= ~(1 << plane);
769 lcd->window[plane].winctrl0 = winctrl0;
770 lcd->window[plane].winctrl1 = winctrl1;
771 lcd->window[plane].winbuf0 =
772 lcd->window[plane].winbuf1 = fbdev->fb_phys;
773 lcd->window[plane].winbufctrl = 0; /* select winbuf0 */
774 lcd->winenable |= winenable;
780 static void au1200_setpanel(struct panel_settings *newpanel,
781 struct au1200fb_platdata *pd)
784 * Perform global setup/init of LCD controller
788 /* Make sure all windows disabled */
789 winenable = lcd->winenable;
793 * Ensure everything is disabled before reconfiguring
795 if (lcd->screen & LCD_SCREEN_SEN) {
796 /* Wait for vertical sync period */
797 lcd->intstatus = LCD_INT_SS;
798 while ((lcd->intstatus & LCD_INT_SS) == 0) {
802 lcd->screen &= ~LCD_SCREEN_SEN; /*disable the controller*/
805 lcd->intstatus = lcd->intstatus; /*clear interrupts*/
807 /*wait for controller to shut down*/
808 } while ((lcd->intstatus & LCD_INT_SD) == 0);
810 /* Call shutdown of current panel (if up) */
811 /* this must occur last, because if an external clock is driving
812 the controller, the clock cannot be turned off before first
813 shutting down the controller.
815 if (pd->panel_shutdown)
816 pd->panel_shutdown();
819 /* Newpanel == NULL indicates a shutdown operation only */
820 if (newpanel == NULL)
825 printk("Panel(%s), %dx%d\n", panel->name, panel->Xres, panel->Yres);
828 * Setup clocking if internal LCD clock source (assumes sys_auxpll valid)
830 if (!(panel->mode_clkcontrol & LCD_CLKCONTROL_EXT))
833 au_writel(panel->mode_auxpll, SYS_AUXPLL);
834 sys_clksrc = au_readl(SYS_CLKSRC) & ~0x0000001f;
835 sys_clksrc |= panel->mode_toyclksrc;
836 au_writel(sys_clksrc, SYS_CLKSRC);
840 * Configure panel timings
842 lcd->screen = panel->mode_screen;
843 lcd->horztiming = panel->mode_horztiming;
844 lcd->verttiming = panel->mode_verttiming;
845 lcd->clkcontrol = panel->mode_clkcontrol;
846 lcd->pwmdiv = panel->mode_pwmdiv;
847 lcd->pwmhi = panel->mode_pwmhi;
848 lcd->outmask = panel->mode_outmask;
849 lcd->fifoctrl = panel->mode_fifoctrl;
852 /* fixme: Check window settings to make sure still valid
853 * for new geometry */
855 au1200_setlocation(fbdev, 0, win->w[0].xpos, win->w[0].ypos);
856 au1200_setlocation(fbdev, 1, win->w[1].xpos, win->w[1].ypos);
857 au1200_setlocation(fbdev, 2, win->w[2].xpos, win->w[2].ypos);
858 au1200_setlocation(fbdev, 3, win->w[3].xpos, win->w[3].ypos);
860 lcd->winenable = winenable;
863 * Re-enable screen now that it is configured
865 lcd->screen |= LCD_SCREEN_SEN;
868 /* Call init of panel */
872 /* FIX!!!! not appropriate on panel change!!! Global setup/init */
875 lcd->backcolor = win->mode_backcolor;
877 /* Setup Color Key - FIX!!! */
878 lcd->colorkey = win->mode_colorkey;
879 lcd->colorkeymsk = win->mode_colorkeymsk;
881 /* Setup HWCursor - FIX!!! Need to support this eventually */
882 lcd->hwc.cursorctrl = 0;
883 lcd->hwc.cursorpos = 0;
884 lcd->hwc.cursorcolor0 = 0;
885 lcd->hwc.cursorcolor1 = 0;
886 lcd->hwc.cursorcolor2 = 0;
887 lcd->hwc.cursorcolor3 = 0;
891 #define D(X) printk("%25s: %08X\n", #X, X)
900 D(lcd->window[0].winctrl0);
901 D(lcd->window[0].winctrl1);
902 D(lcd->window[0].winctrl2);
903 D(lcd->window[0].winbuf0);
904 D(lcd->window[0].winbuf1);
905 D(lcd->window[0].winbufctrl);
906 D(lcd->window[1].winctrl0);
907 D(lcd->window[1].winctrl1);
908 D(lcd->window[1].winctrl2);
909 D(lcd->window[1].winbuf0);
910 D(lcd->window[1].winbuf1);
911 D(lcd->window[1].winbufctrl);
912 D(lcd->window[2].winctrl0);
913 D(lcd->window[2].winctrl1);
914 D(lcd->window[2].winctrl2);
915 D(lcd->window[2].winbuf0);
916 D(lcd->window[2].winbuf1);
917 D(lcd->window[2].winbufctrl);
918 D(lcd->window[3].winctrl0);
919 D(lcd->window[3].winctrl1);
920 D(lcd->window[3].winctrl2);
921 D(lcd->window[3].winbuf0);
922 D(lcd->window[3].winbuf1);
923 D(lcd->window[3].winbufctrl);
931 D(lcd->hwc.cursorctrl);
932 D(lcd->hwc.cursorpos);
933 D(lcd->hwc.cursorcolor0);
934 D(lcd->hwc.cursorcolor1);
935 D(lcd->hwc.cursorcolor2);
936 D(lcd->hwc.cursorcolor3);
940 static void au1200_setmode(struct au1200fb_device *fbdev)
942 int plane = fbdev->plane;
943 /* Window/plane setup */
944 lcd->window[plane].winctrl1 = ( 0
945 | LCD_WINCTRL1_PRI_N(plane)
946 | win->w[plane].mode_winctrl1 /* FRM,CCO,PO,PIPE */
949 au1200_setlocation(fbdev, plane, win->w[plane].xpos, win->w[plane].ypos);
951 lcd->window[plane].winctrl2 = ( 0
952 | LCD_WINCTRL2_CKMODE_00
954 | LCD_WINCTRL2_BX_N(fbdev->fb_info->fix.line_length)
958 lcd->winenable |= win->w[plane].mode_winenable;
965 /*#define panel_is_dual(panel) ((panel->mode_screen & LCD_SCREEN_PT) == LCD_SCREEN_PT_010)*/
966 /*#define panel_is_active(panel)((panel->mode_screen & LCD_SCREEN_PT) == LCD_SCREEN_PT_010)*/
968 #define panel_is_color(panel) ((panel->mode_screen & LCD_SCREEN_PT) <= LCD_SCREEN_PT_CDSTN)
970 /* Bitfields format supported by the controller. */
971 static struct fb_bitfield rgb_bitfields[][4] = {
972 /* Red, Green, Blue, Transp */
973 [LCD_WINCTRL1_FRM_16BPP655 >> 25] =
974 { { 10, 6, 0 }, { 5, 5, 0 }, { 0, 5, 0 }, { 0, 0, 0 } },
976 [LCD_WINCTRL1_FRM_16BPP565 >> 25] =
977 { { 11, 5, 0 }, { 5, 6, 0 }, { 0, 5, 0 }, { 0, 0, 0 } },
979 [LCD_WINCTRL1_FRM_16BPP556 >> 25] =
980 { { 11, 5, 0 }, { 6, 5, 0 }, { 0, 6, 0 }, { 0, 0, 0 } },
982 [LCD_WINCTRL1_FRM_16BPPI1555 >> 25] =
983 { { 10, 5, 0 }, { 5, 5, 0 }, { 0, 5, 0 }, { 0, 0, 0 } },
985 [LCD_WINCTRL1_FRM_16BPPI5551 >> 25] =
986 { { 11, 5, 0 }, { 6, 5, 0 }, { 1, 5, 0 }, { 0, 0, 0 } },
988 [LCD_WINCTRL1_FRM_16BPPA1555 >> 25] =
989 { { 10, 5, 0 }, { 5, 5, 0 }, { 0, 5, 0 }, { 15, 1, 0 } },
991 [LCD_WINCTRL1_FRM_16BPPA5551 >> 25] =
992 { { 11, 5, 0 }, { 6, 5, 0 }, { 1, 5, 0 }, { 0, 1, 0 } },
994 [LCD_WINCTRL1_FRM_24BPP >> 25] =
995 { { 16, 8, 0 }, { 8, 8, 0 }, { 0, 8, 0 }, { 0, 0, 0 } },
997 [LCD_WINCTRL1_FRM_32BPP >> 25] =
998 { { 16, 8, 0 }, { 8, 8, 0 }, { 0, 8, 0 }, { 24, 0, 0 } },
1001 /*-------------------------------------------------------------------------*/
1005 static void au1200fb_update_fbinfo(struct fb_info *fbi)
1007 /* FIX!!!! This also needs to take the window pixel format into account!!! */
1009 /* Update var-dependent FB info */
1010 if (panel_is_color(panel)) {
1011 if (fbi->var.bits_per_pixel <= 8) {
1013 fbi->fix.visual = FB_VISUAL_PSEUDOCOLOR;
1014 fbi->fix.line_length = fbi->var.xres_virtual /
1015 (8/fbi->var.bits_per_pixel);
1017 /* non-palettized */
1018 fbi->fix.visual = FB_VISUAL_TRUECOLOR;
1019 fbi->fix.line_length = fbi->var.xres_virtual * (fbi->var.bits_per_pixel / 8);
1022 /* mono FIX!!! mono 8 and 4 bits */
1023 fbi->fix.visual = FB_VISUAL_MONO10;
1024 fbi->fix.line_length = fbi->var.xres_virtual / 8;
1027 fbi->screen_size = fbi->fix.line_length * fbi->var.yres_virtual;
1028 print_dbg("line length: %d\n", fbi->fix.line_length);
1029 print_dbg("bits_per_pixel: %d\n", fbi->var.bits_per_pixel);
1032 /*-------------------------------------------------------------------------*/
1034 /* AU1200 framebuffer driver */
1037 * Validate var settings with hardware restrictions and modify it if necessary
1039 static int au1200fb_fb_check_var(struct fb_var_screeninfo *var,
1040 struct fb_info *fbi)
1042 struct au1200fb_device *fbdev = fbi->par;
1044 int screen_size, plane;
1046 plane = fbdev->plane;
1048 /* Make sure that the mode respect all LCD controller and
1049 * panel restrictions. */
1050 var->xres = win->w[plane].xres;
1051 var->yres = win->w[plane].yres;
1053 /* No need for virtual resolution support */
1054 var->xres_virtual = var->xres;
1055 var->yres_virtual = var->yres;
1057 var->bits_per_pixel = winbpp(win->w[plane].mode_winctrl1);
1059 screen_size = var->xres_virtual * var->yres_virtual;
1060 if (var->bits_per_pixel > 8) screen_size *= (var->bits_per_pixel / 8);
1061 else screen_size /= (8/var->bits_per_pixel);
1063 if (fbdev->fb_len < screen_size)
1064 return -EINVAL; /* Virtual screen is to big, abort */
1066 /* FIX!!!! what are the implicaitons of ignoring this for windows ??? */
1067 /* The max LCD clock is fixed to 48MHz (value of AUX_CLK). The pixel
1068 * clock can only be obtain by dividing this value by an even integer.
1069 * Fallback to a slower pixel clock if necessary. */
1070 pixclock = max((u32)(PICOS2KHZ(var->pixclock) * 1000), fbi->monspecs.dclkmin);
1071 pixclock = min3(pixclock, fbi->monspecs.dclkmax, (u32)AU1200_LCD_MAX_CLK/2);
1073 if (AU1200_LCD_MAX_CLK % pixclock) {
1074 int diff = AU1200_LCD_MAX_CLK % pixclock;
1078 var->pixclock = KHZ2PICOS(pixclock/1000);
1080 if (!panel_is_active(panel)) {
1081 int pcd = AU1200_LCD_MAX_CLK / (pixclock * 2) - 1;
1083 if (!panel_is_color(panel)
1084 && (panel->control_base & LCD_CONTROL_MPI) && (pcd < 3)) {
1085 /* STN 8bit mono panel support is up to 6MHz pixclock */
1086 var->pixclock = KHZ2PICOS(6000);
1088 /* Other STN panel support is up to 12MHz */
1089 var->pixclock = KHZ2PICOS(12000);
1093 /* Set bitfield accordingly */
1094 switch (var->bits_per_pixel) {
1097 /* 16bpp True color.
1098 * These must be set to MATCH WINCTRL[FORM] */
1100 idx = (win->w[0].mode_winctrl1 & LCD_WINCTRL1_FRM) >> 25;
1101 var->red = rgb_bitfields[idx][0];
1102 var->green = rgb_bitfields[idx][1];
1103 var->blue = rgb_bitfields[idx][2];
1104 var->transp = rgb_bitfields[idx][3];
1110 /* 32bpp True color.
1111 * These must be set to MATCH WINCTRL[FORM] */
1113 idx = (win->w[0].mode_winctrl1 & LCD_WINCTRL1_FRM) >> 25;
1114 var->red = rgb_bitfields[idx][0];
1115 var->green = rgb_bitfields[idx][1];
1116 var->blue = rgb_bitfields[idx][2];
1117 var->transp = rgb_bitfields[idx][3];
1121 print_dbg("Unsupported depth %dbpp", var->bits_per_pixel);
1129 * Set hardware with var settings. This will enable the controller with a
1130 * specific mode, normally validated with the fb_check_var method
1132 static int au1200fb_fb_set_par(struct fb_info *fbi)
1134 struct au1200fb_device *fbdev = fbi->par;
1136 au1200fb_update_fbinfo(fbi);
1137 au1200_setmode(fbdev);
1143 * Set color in LCD palette.
1145 static int au1200fb_fb_setcolreg(unsigned regno, unsigned red, unsigned green,
1146 unsigned blue, unsigned transp, struct fb_info *fbi)
1148 volatile u32 *palette = lcd->palette;
1151 if (regno > (AU1200_LCD_NBR_PALETTE_ENTRIES - 1))
1154 if (fbi->var.grayscale) {
1155 /* Convert color to grayscale */
1156 red = green = blue =
1157 (19595 * red + 38470 * green + 7471 * blue) >> 16;
1160 if (fbi->fix.visual == FB_VISUAL_TRUECOLOR) {
1161 /* Place color in the pseudopalette */
1165 palette = (u32*) fbi->pseudo_palette;
1167 red >>= (16 - fbi->var.red.length);
1168 green >>= (16 - fbi->var.green.length);
1169 blue >>= (16 - fbi->var.blue.length);
1171 value = (red << fbi->var.red.offset) |
1172 (green << fbi->var.green.offset)|
1173 (blue << fbi->var.blue.offset);
1176 } else if (1 /*FIX!!! panel_is_active(fbdev->panel)*/) {
1177 /* COLOR TFT PALLETTIZED (use RGB 565) */
1178 value = (red & 0xF800)|((green >> 5) &
1179 0x07E0)|((blue >> 11) & 0x001F);
1182 } else if (0 /*panel_is_color(fbdev->panel)*/) {
1183 /* COLOR STN MODE */
1187 /* MONOCHROME MODE */
1188 value = (green >> 12) & 0x000F;
1192 palette[regno] = value;
1198 * Blank the screen. Depending on the mode, the screen will be
1199 * activated with the backlight color, or desactivated
1201 static int au1200fb_fb_blank(int blank_mode, struct fb_info *fbi)
1203 struct au1200fb_device *fbdev = fbi->par;
1205 /* Short-circuit screen blanking */
1209 switch (blank_mode) {
1211 case FB_BLANK_UNBLANK:
1212 case FB_BLANK_NORMAL:
1213 /* printk("turn on panel\n"); */
1214 au1200_setpanel(panel, fbdev->pd);
1216 case FB_BLANK_VSYNC_SUSPEND:
1217 case FB_BLANK_HSYNC_SUSPEND:
1218 case FB_BLANK_POWERDOWN:
1219 /* printk("turn off panel\n"); */
1220 au1200_setpanel(NULL, fbdev->pd);
1227 /* FB_BLANK_NORMAL is a soft blank */
1228 return (blank_mode == FB_BLANK_NORMAL) ? -EINVAL : 0;
1232 * Map video memory in user space. We don't use the generic fb_mmap
1233 * method mainly to allow the use of the TLB streaming flag (CCA=6)
1235 static int au1200fb_fb_mmap(struct fb_info *info, struct vm_area_struct *vma)
1237 struct au1200fb_device *fbdev = info->par;
1239 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
1240 pgprot_val(vma->vm_page_prot) |= _CACHE_MASK; /* CCA=7 */
1242 return vm_iomap_memory(vma, fbdev->fb_phys, fbdev->fb_len);
1245 static void set_global(u_int cmd, struct au1200_lcd_global_regs_t *pdata)
1248 unsigned int hi1, divider;
1250 /* SCREEN_SIZE: user cannot reset size, must switch panel choice */
1252 if (pdata->flags & SCREEN_BACKCOLOR)
1253 lcd->backcolor = pdata->backcolor;
1255 if (pdata->flags & SCREEN_BRIGHTNESS) {
1257 // limit brightness pwm duty to >= 30/1600
1258 if (pdata->brightness < 30) {
1259 pdata->brightness = 30;
1261 divider = (lcd->pwmdiv & 0x3FFFF) + 1;
1262 hi1 = (lcd->pwmhi >> 16) + 1;
1263 hi1 = (((pdata->brightness & 0xFF)+1) * divider >> 8);
1264 lcd->pwmhi &= 0xFFFF;
1265 lcd->pwmhi |= (hi1 << 16);
1268 if (pdata->flags & SCREEN_COLORKEY)
1269 lcd->colorkey = pdata->colorkey;
1271 if (pdata->flags & SCREEN_MASK)
1272 lcd->colorkeymsk = pdata->mask;
1276 static void get_global(u_int cmd, struct au1200_lcd_global_regs_t *pdata)
1278 unsigned int hi1, divider;
1280 pdata->xsize = ((lcd->screen & LCD_SCREEN_SX) >> 19) + 1;
1281 pdata->ysize = ((lcd->screen & LCD_SCREEN_SY) >> 8) + 1;
1283 pdata->backcolor = lcd->backcolor;
1284 pdata->colorkey = lcd->colorkey;
1285 pdata->mask = lcd->colorkeymsk;
1288 hi1 = (lcd->pwmhi >> 16) + 1;
1289 divider = (lcd->pwmdiv & 0x3FFFF) + 1;
1290 pdata->brightness = ((hi1 << 8) / divider) - 1;
1294 static void set_window(unsigned int plane,
1295 struct au1200_lcd_window_regs_t *pdata)
1297 unsigned int val, bpp;
1299 /* Window control register 0 */
1300 if (pdata->flags & WIN_POSITION) {
1301 val = lcd->window[plane].winctrl0 & ~(LCD_WINCTRL0_OX |
1303 val |= ((pdata->xpos << 21) & LCD_WINCTRL0_OX);
1304 val |= ((pdata->ypos << 10) & LCD_WINCTRL0_OY);
1305 lcd->window[plane].winctrl0 = val;
1307 if (pdata->flags & WIN_ALPHA_COLOR) {
1308 val = lcd->window[plane].winctrl0 & ~(LCD_WINCTRL0_A);
1309 val |= ((pdata->alpha_color << 2) & LCD_WINCTRL0_A);
1310 lcd->window[plane].winctrl0 = val;
1312 if (pdata->flags & WIN_ALPHA_MODE) {
1313 val = lcd->window[plane].winctrl0 & ~(LCD_WINCTRL0_AEN);
1314 val |= ((pdata->alpha_mode << 1) & LCD_WINCTRL0_AEN);
1315 lcd->window[plane].winctrl0 = val;
1318 /* Window control register 1 */
1319 if (pdata->flags & WIN_PRIORITY) {
1320 val = lcd->window[plane].winctrl1 & ~(LCD_WINCTRL1_PRI);
1321 val |= ((pdata->priority << 30) & LCD_WINCTRL1_PRI);
1322 lcd->window[plane].winctrl1 = val;
1324 if (pdata->flags & WIN_CHANNEL) {
1325 val = lcd->window[plane].winctrl1 & ~(LCD_WINCTRL1_PIPE);
1326 val |= ((pdata->channel << 29) & LCD_WINCTRL1_PIPE);
1327 lcd->window[plane].winctrl1 = val;
1329 if (pdata->flags & WIN_BUFFER_FORMAT) {
1330 val = lcd->window[plane].winctrl1 & ~(LCD_WINCTRL1_FRM);
1331 val |= ((pdata->buffer_format << 25) & LCD_WINCTRL1_FRM);
1332 lcd->window[plane].winctrl1 = val;
1334 if (pdata->flags & WIN_COLOR_ORDER) {
1335 val = lcd->window[plane].winctrl1 & ~(LCD_WINCTRL1_CCO);
1336 val |= ((pdata->color_order << 24) & LCD_WINCTRL1_CCO);
1337 lcd->window[plane].winctrl1 = val;
1339 if (pdata->flags & WIN_PIXEL_ORDER) {
1340 val = lcd->window[plane].winctrl1 & ~(LCD_WINCTRL1_PO);
1341 val |= ((pdata->pixel_order << 22) & LCD_WINCTRL1_PO);
1342 lcd->window[plane].winctrl1 = val;
1344 if (pdata->flags & WIN_SIZE) {
1345 val = lcd->window[plane].winctrl1 & ~(LCD_WINCTRL1_SZX |
1347 val |= (((pdata->xsize << 11) - 1) & LCD_WINCTRL1_SZX);
1348 val |= (((pdata->ysize) - 1) & LCD_WINCTRL1_SZY);
1349 lcd->window[plane].winctrl1 = val;
1350 /* program buffer line width */
1351 bpp = winbpp(val) / 8;
1352 val = lcd->window[plane].winctrl2 & ~(LCD_WINCTRL2_BX);
1353 val |= (((pdata->xsize * bpp) << 8) & LCD_WINCTRL2_BX);
1354 lcd->window[plane].winctrl2 = val;
1357 /* Window control register 2 */
1358 if (pdata->flags & WIN_COLORKEY_MODE) {
1359 val = lcd->window[plane].winctrl2 & ~(LCD_WINCTRL2_CKMODE);
1360 val |= ((pdata->colorkey_mode << 24) & LCD_WINCTRL2_CKMODE);
1361 lcd->window[plane].winctrl2 = val;
1363 if (pdata->flags & WIN_DOUBLE_BUFFER_MODE) {
1364 val = lcd->window[plane].winctrl2 & ~(LCD_WINCTRL2_DBM);
1365 val |= ((pdata->double_buffer_mode << 23) & LCD_WINCTRL2_DBM);
1366 lcd->window[plane].winctrl2 = val;
1368 if (pdata->flags & WIN_RAM_ARRAY_MODE) {
1369 val = lcd->window[plane].winctrl2 & ~(LCD_WINCTRL2_RAM);
1370 val |= ((pdata->ram_array_mode << 21) & LCD_WINCTRL2_RAM);
1371 lcd->window[plane].winctrl2 = val;
1374 /* Buffer line width programmed with WIN_SIZE */
1376 if (pdata->flags & WIN_BUFFER_SCALE) {
1377 val = lcd->window[plane].winctrl2 & ~(LCD_WINCTRL2_SCX |
1379 val |= ((pdata->xsize << 11) & LCD_WINCTRL2_SCX);
1380 val |= ((pdata->ysize) & LCD_WINCTRL2_SCY);
1381 lcd->window[plane].winctrl2 = val;
1384 if (pdata->flags & WIN_ENABLE) {
1385 val = lcd->winenable;
1387 val |= (pdata->enable & 1) << plane;
1388 lcd->winenable = val;
1393 static void get_window(unsigned int plane,
1394 struct au1200_lcd_window_regs_t *pdata)
1396 /* Window control register 0 */
1397 pdata->xpos = (lcd->window[plane].winctrl0 & LCD_WINCTRL0_OX) >> 21;
1398 pdata->ypos = (lcd->window[plane].winctrl0 & LCD_WINCTRL0_OY) >> 10;
1399 pdata->alpha_color = (lcd->window[plane].winctrl0 & LCD_WINCTRL0_A) >> 2;
1400 pdata->alpha_mode = (lcd->window[plane].winctrl0 & LCD_WINCTRL0_AEN) >> 1;
1402 /* Window control register 1 */
1403 pdata->priority = (lcd->window[plane].winctrl1& LCD_WINCTRL1_PRI) >> 30;
1404 pdata->channel = (lcd->window[plane].winctrl1 & LCD_WINCTRL1_PIPE) >> 29;
1405 pdata->buffer_format = (lcd->window[plane].winctrl1 & LCD_WINCTRL1_FRM) >> 25;
1406 pdata->color_order = (lcd->window[plane].winctrl1 & LCD_WINCTRL1_CCO) >> 24;
1407 pdata->pixel_order = (lcd->window[plane].winctrl1 & LCD_WINCTRL1_PO) >> 22;
1408 pdata->xsize = ((lcd->window[plane].winctrl1 & LCD_WINCTRL1_SZX) >> 11) + 1;
1409 pdata->ysize = (lcd->window[plane].winctrl1 & LCD_WINCTRL1_SZY) + 1;
1411 /* Window control register 2 */
1412 pdata->colorkey_mode = (lcd->window[plane].winctrl2 & LCD_WINCTRL2_CKMODE) >> 24;
1413 pdata->double_buffer_mode = (lcd->window[plane].winctrl2 & LCD_WINCTRL2_DBM) >> 23;
1414 pdata->ram_array_mode = (lcd->window[plane].winctrl2 & LCD_WINCTRL2_RAM) >> 21;
1416 pdata->enable = (lcd->winenable >> plane) & 1;
1420 static int au1200fb_ioctl(struct fb_info *info, unsigned int cmd,
1423 struct au1200fb_device *fbdev = info->par;
1427 plane = fbinfo2index(info);
1428 print_dbg("au1200fb: ioctl %d on plane %d\n", cmd, plane);
1430 if (cmd == AU1200_LCD_FB_IOCTL) {
1431 struct au1200_lcd_iodata_t iodata;
1433 if (copy_from_user(&iodata, (void __user *) arg, sizeof(iodata)))
1436 print_dbg("FB IOCTL called\n");
1438 switch (iodata.subcmd) {
1439 case AU1200_LCD_SET_SCREEN:
1440 print_dbg("AU1200_LCD_SET_SCREEN\n");
1441 set_global(cmd, &iodata.global);
1444 case AU1200_LCD_GET_SCREEN:
1445 print_dbg("AU1200_LCD_GET_SCREEN\n");
1446 get_global(cmd, &iodata.global);
1449 case AU1200_LCD_SET_WINDOW:
1450 print_dbg("AU1200_LCD_SET_WINDOW\n");
1451 set_window(plane, &iodata.window);
1454 case AU1200_LCD_GET_WINDOW:
1455 print_dbg("AU1200_LCD_GET_WINDOW\n");
1456 get_window(plane, &iodata.window);
1459 case AU1200_LCD_SET_PANEL:
1460 print_dbg("AU1200_LCD_SET_PANEL\n");
1461 if ((iodata.global.panel_choice >= 0) &&
1462 (iodata.global.panel_choice <
1465 struct panel_settings *newpanel;
1466 panel_index = iodata.global.panel_choice;
1467 newpanel = &known_lcd_panels[panel_index];
1468 au1200_setpanel(newpanel, fbdev->pd);
1472 case AU1200_LCD_GET_PANEL:
1473 print_dbg("AU1200_LCD_GET_PANEL\n");
1474 iodata.global.panel_choice = panel_index;
1481 val = copy_to_user((void __user *) arg, &iodata, sizeof(iodata));
1483 print_dbg("error: could not copy %d bytes\n", val);
1492 static struct fb_ops au1200fb_fb_ops = {
1493 .owner = THIS_MODULE,
1494 .fb_check_var = au1200fb_fb_check_var,
1495 .fb_set_par = au1200fb_fb_set_par,
1496 .fb_setcolreg = au1200fb_fb_setcolreg,
1497 .fb_blank = au1200fb_fb_blank,
1498 .fb_fillrect = sys_fillrect,
1499 .fb_copyarea = sys_copyarea,
1500 .fb_imageblit = sys_imageblit,
1501 .fb_read = fb_sys_read,
1502 .fb_write = fb_sys_write,
1504 .fb_ioctl = au1200fb_ioctl,
1505 .fb_mmap = au1200fb_fb_mmap,
1508 /*-------------------------------------------------------------------------*/
1510 static irqreturn_t au1200fb_handle_irq(int irq, void* dev_id)
1512 /* Nothing to do for now, just clear any pending interrupt */
1513 lcd->intstatus = lcd->intstatus;
1519 /*-------------------------------------------------------------------------*/
1521 /* AU1200 LCD device probe helpers */
1523 static int au1200fb_init_fbinfo(struct au1200fb_device *fbdev)
1525 struct fb_info *fbi = fbdev->fb_info;
1528 fbi->fbops = &au1200fb_fb_ops;
1530 bpp = winbpp(win->w[fbdev->plane].mode_winctrl1);
1532 /* Copy monitor specs from panel data */
1533 /* fixme: we're setting up LCD controller windows, so these dont give a
1534 damn as to what the monitor specs are (the panel itself does, but that
1535 isn't done here...so maybe need a generic catchall monitor setting??? */
1536 memcpy(&fbi->monspecs, &panel->monspecs, sizeof(struct fb_monspecs));
1538 /* We first try the user mode passed in argument. If that failed,
1539 * or if no one has been specified, we default to the first mode of the
1540 * panel list. Note that after this call, var data will be set */
1541 if (!fb_find_mode(&fbi->var,
1543 NULL, /* drv_info.opt_mode, */
1544 fbi->monspecs.modedb,
1545 fbi->monspecs.modedb_len,
1546 fbi->monspecs.modedb,
1549 print_err("Cannot find valid mode for panel %s", panel->name);
1553 fbi->pseudo_palette = kcalloc(16, sizeof(u32), GFP_KERNEL);
1554 if (!fbi->pseudo_palette) {
1558 if (fb_alloc_cmap(&fbi->cmap, AU1200_LCD_NBR_PALETTE_ENTRIES, 0) < 0) {
1559 print_err("Fail to allocate colormap (%d entries)",
1560 AU1200_LCD_NBR_PALETTE_ENTRIES);
1561 kfree(fbi->pseudo_palette);
1565 strncpy(fbi->fix.id, "AU1200", sizeof(fbi->fix.id));
1566 fbi->fix.smem_start = fbdev->fb_phys;
1567 fbi->fix.smem_len = fbdev->fb_len;
1568 fbi->fix.type = FB_TYPE_PACKED_PIXELS;
1569 fbi->fix.xpanstep = 0;
1570 fbi->fix.ypanstep = 0;
1571 fbi->fix.mmio_start = 0;
1572 fbi->fix.mmio_len = 0;
1573 fbi->fix.accel = FB_ACCEL_NONE;
1575 fbi->screen_base = (char __iomem *) fbdev->fb_mem;
1577 au1200fb_update_fbinfo(fbi);
1582 /*-------------------------------------------------------------------------*/
1585 static int au1200fb_setup(struct au1200fb_platdata *pd)
1587 char *options = NULL;
1588 char *this_opt, *endptr;
1589 int num_panels = ARRAY_SIZE(known_lcd_panels);
1592 fb_get_options(DRIVER_NAME, &options);
1597 while ((this_opt = strsep(&options, ",")) != NULL) {
1598 /* Panel option - can be panel name,
1599 * "bs" for board-switch, or number/index */
1600 if (!strncmp(this_opt, "panel:", 6)) {
1605 /* First check for index, which allows
1606 * to short circuit this mess */
1607 li = simple_strtol(this_opt, &endptr, 0);
1608 if (*endptr == '\0')
1609 panel_idx = (int)li;
1610 else if (strcmp(this_opt, "bs") == 0)
1611 panel_idx = pd->panel_index();
1613 for (i = 0; i < num_panels; i++) {
1614 if (!strcmp(this_opt,
1615 known_lcd_panels[i].name)) {
1621 if ((panel_idx < 0) || (panel_idx >= num_panels))
1622 print_warn("Panel %s not supported!", this_opt);
1624 panel_index = panel_idx;
1626 } else if (strncmp(this_opt, "nohwcursor", 10) == 0)
1628 else if (strncmp(this_opt, "devices:", 8) == 0) {
1630 device_count = simple_strtol(this_opt, &endptr, 0);
1631 if ((device_count < 0) ||
1632 (device_count > MAX_DEVICE_COUNT))
1633 device_count = MAX_DEVICE_COUNT;
1634 } else if (strncmp(this_opt, "wincfg:", 7) == 0) {
1636 window_index = simple_strtol(this_opt, &endptr, 0);
1637 if ((window_index < 0) ||
1638 (window_index >= ARRAY_SIZE(windows)))
1639 window_index = DEFAULT_WINDOW_INDEX;
1640 } else if (strncmp(this_opt, "off", 3) == 0)
1643 print_warn("Unsupported option \"%s\"", this_opt);
1650 /* AU1200 LCD controller device driver */
1651 static int au1200fb_drv_probe(struct platform_device *dev)
1653 struct au1200fb_device *fbdev;
1654 struct au1200fb_platdata *pd;
1655 struct fb_info *fbi = NULL;
1657 int bpp, plane, ret, irq;
1659 print_info("" DRIVER_DESC "");
1661 pd = dev->dev.platform_data;
1665 /* Setup driver with options */
1666 if (au1200fb_setup(pd))
1669 /* Point to the panel selected */
1670 panel = &known_lcd_panels[panel_index];
1671 win = &windows[window_index];
1673 printk(DRIVER_NAME ": Panel %d %s\n", panel_index, panel->name);
1674 printk(DRIVER_NAME ": Win %d %s\n", window_index, win->name);
1680 for (plane = 0; plane < device_count; ++plane) {
1681 bpp = winbpp(win->w[plane].mode_winctrl1);
1682 if (win->w[plane].xres == 0)
1683 win->w[plane].xres = panel->Xres;
1684 if (win->w[plane].yres == 0)
1685 win->w[plane].yres = panel->Yres;
1687 fbi = framebuffer_alloc(sizeof(struct au1200fb_device),
1692 _au1200fb_infos[plane] = fbi;
1694 fbdev->fb_info = fbi;
1697 fbdev->plane = plane;
1699 /* Allocate the framebuffer to the maximum screen size */
1700 fbdev->fb_len = (win->w[plane].xres * win->w[plane].yres * bpp) / 8;
1702 fbdev->fb_mem = dmam_alloc_noncoherent(&dev->dev,
1703 PAGE_ALIGN(fbdev->fb_len),
1704 &fbdev->fb_phys, GFP_KERNEL);
1705 if (!fbdev->fb_mem) {
1706 print_err("fail to allocate frambuffer (size: %dK))",
1707 fbdev->fb_len / 1024);
1712 * Set page reserved so that mmap will work. This is necessary
1713 * since we'll be remapping normal memory.
1715 for (page = (unsigned long)fbdev->fb_phys;
1716 page < PAGE_ALIGN((unsigned long)fbdev->fb_phys +
1718 page += PAGE_SIZE) {
1719 SetPageReserved(pfn_to_page(page >> PAGE_SHIFT)); /* LCD DMA is NOT coherent on Au1200 */
1721 print_dbg("Framebuffer memory map at %p", fbdev->fb_mem);
1722 print_dbg("phys=0x%08x, size=%dK", fbdev->fb_phys, fbdev->fb_len / 1024);
1725 if ((ret = au1200fb_init_fbinfo(fbdev)) < 0)
1728 /* Register new framebuffer */
1729 ret = register_framebuffer(fbi);
1731 print_err("cannot register new framebuffer");
1735 au1200fb_fb_set_par(fbi);
1737 #if !defined(CONFIG_FRAMEBUFFER_CONSOLE) && defined(CONFIG_LOGO)
1739 if (fb_prepare_logo(fbi, FB_ROTATE_UR)) {
1740 /* Start display and show logo on boot */
1741 fb_set_cmap(&fbi->cmap, fbi);
1742 fb_show_logo(fbi, FB_ROTATE_UR);
1747 /* Now hook interrupt too */
1748 irq = platform_get_irq(dev, 0);
1749 ret = request_irq(irq, au1200fb_handle_irq,
1750 IRQF_SHARED, "lcd", (void *)dev);
1752 print_err("fail to request interrupt line %d (err: %d)",
1757 platform_set_drvdata(dev, pd);
1759 /* Kickstart the panel */
1760 au1200_setpanel(panel, pd);
1765 /* NOTE: This only does the current plane/window that failed; others are still active */
1767 if (fbi->cmap.len != 0)
1768 fb_dealloc_cmap(&fbi->cmap);
1769 kfree(fbi->pseudo_palette);
1772 free_irq(AU1200_LCD_INT, (void*)dev);
1776 static int au1200fb_drv_remove(struct platform_device *dev)
1778 struct au1200fb_platdata *pd = platform_get_drvdata(dev);
1779 struct au1200fb_device *fbdev;
1780 struct fb_info *fbi;
1783 /* Turn off the panel */
1784 au1200_setpanel(NULL, pd);
1786 for (plane = 0; plane < device_count; ++plane) {
1787 fbi = _au1200fb_infos[plane];
1790 /* Clean up all probe data */
1791 unregister_framebuffer(fbi);
1792 if (fbi->cmap.len != 0)
1793 fb_dealloc_cmap(&fbi->cmap);
1794 kfree(fbi->pseudo_palette);
1796 framebuffer_release(fbi);
1797 _au1200fb_infos[plane] = NULL;
1800 free_irq(platform_get_irq(dev, 0), (void *)dev);
1806 static int au1200fb_drv_suspend(struct device *dev)
1808 struct au1200fb_platdata *pd = dev_get_drvdata(dev);
1809 au1200_setpanel(NULL, pd);
1817 static int au1200fb_drv_resume(struct device *dev)
1819 struct au1200fb_platdata *pd = dev_get_drvdata(dev);
1820 struct fb_info *fbi;
1823 /* Kickstart the panel */
1824 au1200_setpanel(panel, pd);
1826 for (i = 0; i < device_count; i++) {
1827 fbi = _au1200fb_infos[i];
1828 au1200fb_fb_set_par(fbi);
1834 static const struct dev_pm_ops au1200fb_pmops = {
1835 .suspend = au1200fb_drv_suspend,
1836 .resume = au1200fb_drv_resume,
1837 .freeze = au1200fb_drv_suspend,
1838 .thaw = au1200fb_drv_resume,
1841 #define AU1200FB_PMOPS (&au1200fb_pmops)
1844 #define AU1200FB_PMOPS NULL
1845 #endif /* CONFIG_PM */
1847 static struct platform_driver au1200fb_driver = {
1849 .name = "au1200-lcd",
1850 .owner = THIS_MODULE,
1851 .pm = AU1200FB_PMOPS,
1853 .probe = au1200fb_drv_probe,
1854 .remove = au1200fb_drv_remove,
1856 module_platform_driver(au1200fb_driver);
1858 MODULE_DESCRIPTION(DRIVER_DESC);
1859 MODULE_LICENSE("GPL");