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>
46 #include <linux/uaccess.h>
48 #include <asm/mach-au1x00/au1000.h>
49 #include <asm/mach-au1x00/au1200fb.h> /* platform_data */
52 #define DRIVER_NAME "au1200fb"
53 #define DRIVER_DESC "LCD controller driver for AU1200 processors"
57 #define print_err(f, arg...) printk(KERN_ERR DRIVER_NAME ": " f "\n", ## arg)
58 #define print_warn(f, arg...) printk(KERN_WARNING DRIVER_NAME ": " f "\n", ## arg)
59 #define print_info(f, arg...) printk(KERN_INFO DRIVER_NAME ": " f "\n", ## arg)
62 #define print_dbg(f, arg...) printk(KERN_DEBUG __FILE__ ": " f "\n", ## arg)
64 #define print_dbg(f, arg...) do {} while (0)
68 #define AU1200_LCD_FB_IOCTL 0x46FF
70 #define AU1200_LCD_SET_SCREEN 1
71 #define AU1200_LCD_GET_SCREEN 2
72 #define AU1200_LCD_SET_WINDOW 3
73 #define AU1200_LCD_GET_WINDOW 4
74 #define AU1200_LCD_SET_PANEL 5
75 #define AU1200_LCD_GET_PANEL 6
77 #define SCREEN_SIZE (1<< 1)
78 #define SCREEN_BACKCOLOR (1<< 2)
79 #define SCREEN_BRIGHTNESS (1<< 3)
80 #define SCREEN_COLORKEY (1<< 4)
81 #define SCREEN_MASK (1<< 5)
83 struct au1200_lcd_global_regs_t {
87 unsigned int backcolor;
88 unsigned int brightness;
89 unsigned int colorkey;
91 unsigned int panel_choice;
96 #define WIN_POSITION (1<< 0)
97 #define WIN_ALPHA_COLOR (1<< 1)
98 #define WIN_ALPHA_MODE (1<< 2)
99 #define WIN_PRIORITY (1<< 3)
100 #define WIN_CHANNEL (1<< 4)
101 #define WIN_BUFFER_FORMAT (1<< 5)
102 #define WIN_COLOR_ORDER (1<< 6)
103 #define WIN_PIXEL_ORDER (1<< 7)
104 #define WIN_SIZE (1<< 8)
105 #define WIN_COLORKEY_MODE (1<< 9)
106 #define WIN_DOUBLE_BUFFER_MODE (1<< 10)
107 #define WIN_RAM_ARRAY_MODE (1<< 11)
108 #define WIN_BUFFER_SCALE (1<< 12)
109 #define WIN_ENABLE (1<< 13)
111 struct au1200_lcd_window_regs_t {
115 unsigned int alpha_color;
116 unsigned int alpha_mode;
117 unsigned int priority;
118 unsigned int channel;
119 unsigned int buffer_format;
120 unsigned int color_order;
121 unsigned int pixel_order;
124 unsigned int colorkey_mode;
125 unsigned int double_buffer_mode;
126 unsigned int ram_array_mode;
133 struct au1200_lcd_iodata_t {
135 struct au1200_lcd_global_regs_t global;
136 struct au1200_lcd_window_regs_t window;
139 #if defined(__BIG_ENDIAN)
140 #define LCD_CONTROL_DEFAULT_PO LCD_CONTROL_PO_11
142 #define LCD_CONTROL_DEFAULT_PO LCD_CONTROL_PO_00
144 #define LCD_CONTROL_DEFAULT_SBPPF LCD_CONTROL_SBPPF_565
146 /* Private, per-framebuffer management information (independent of the panel itself) */
147 struct au1200fb_device {
148 struct fb_info *fb_info; /* FB driver info record */
149 struct au1200fb_platdata *pd;
153 unsigned char* fb_mem; /* FrameBuffer memory map */
158 /********************************************************************/
160 /* LCD controller restrictions */
161 #define AU1200_LCD_MAX_XRES 1280
162 #define AU1200_LCD_MAX_YRES 1024
163 #define AU1200_LCD_MAX_BPP 32
164 #define AU1200_LCD_MAX_CLK 96000000 /* fixme: this needs to go away ? */
165 #define AU1200_LCD_NBR_PALETTE_ENTRIES 256
167 /* Default number of visible screen buffer to allocate */
168 #define AU1200FB_NBR_VIDEO_BUFFERS 1
170 /* Default maximum number of fb devices to create */
171 #define MAX_DEVICE_COUNT 4
173 /* Default window configuration entry to use (see windows[]) */
174 #define DEFAULT_WINDOW_INDEX 2
176 /********************************************************************/
178 static struct fb_info *_au1200fb_infos[MAX_DEVICE_COUNT];
179 static struct au1200_lcd *lcd = (struct au1200_lcd *) AU1200_LCD_ADDR;
180 static int device_count = MAX_DEVICE_COUNT;
181 static int window_index = DEFAULT_WINDOW_INDEX; /* default is zero */
182 static int panel_index = 2; /* default is zero */
183 static struct window_settings *win;
184 static struct panel_settings *panel;
185 static int noblanking = 1;
186 static int nohwcursor = 0;
188 struct window_settings {
189 unsigned char name[64];
190 uint32 mode_backcolor;
191 uint32 mode_colorkey;
192 uint32 mode_colorkeymsk;
198 uint32 mode_winctrl1; /* winctrl1[FRM,CCO,PO,PIPE] */
199 uint32 mode_winenable;
203 #if defined(__BIG_ENDIAN)
204 #define LCD_WINCTRL1_PO_16BPP LCD_WINCTRL1_PO_00
206 #define LCD_WINCTRL1_PO_16BPP LCD_WINCTRL1_PO_01
210 * Default window configurations
212 static struct window_settings windows[] = {
214 "0-FS gfx, 1-video, 2-ovly gfx, 3-ovly gfx",
215 /* mode_backcolor */ 0x006600ff,
216 /* mode_colorkey,msk*/ 0, 0,
219 /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
220 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
221 LCD_WINCTRL1_PO_16BPP,
222 /* mode_winenable*/ LCD_WINENABLE_WEN0,
225 /* xres, yres, xpos, ypos */ 100, 100, 100, 100,
226 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
227 LCD_WINCTRL1_PO_16BPP |
229 /* mode_winenable*/ LCD_WINENABLE_WEN1,
232 /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
233 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
234 LCD_WINCTRL1_PO_16BPP,
235 /* mode_winenable*/ 0,
238 /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
239 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
240 LCD_WINCTRL1_PO_16BPP |
242 /* mode_winenable*/ 0,
248 "0-FS gfx, 1-video, 2-ovly gfx, 3-ovly gfx",
249 /* mode_backcolor */ 0x006600ff,
250 /* mode_colorkey,msk*/ 0, 0,
253 /* xres, yres, xpos, ypos */ 320, 240, 5, 5,
254 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_24BPP |
256 /* mode_winenable*/ LCD_WINENABLE_WEN0,
259 /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
260 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565
261 | LCD_WINCTRL1_PO_16BPP,
262 /* mode_winenable*/ 0,
265 /* xres, yres, xpos, ypos */ 100, 100, 0, 0,
266 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
267 LCD_WINCTRL1_PO_16BPP |
269 /* mode_winenable*/ 0/*LCD_WINENABLE_WEN2*/,
272 /* xres, yres, xpos, ypos */ 200, 25, 0, 0,
273 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
274 LCD_WINCTRL1_PO_16BPP |
276 /* mode_winenable*/ 0,
281 "0-FS gfx, 1-video, 2-ovly gfx, 3-ovly gfx",
282 /* mode_backcolor */ 0x006600ff,
283 /* mode_colorkey,msk*/ 0, 0,
286 /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
287 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
288 LCD_WINCTRL1_PO_16BPP,
289 /* mode_winenable*/ LCD_WINENABLE_WEN0,
292 /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
293 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
294 LCD_WINCTRL1_PO_16BPP,
295 /* mode_winenable*/ 0,
298 /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
299 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_32BPP |
300 LCD_WINCTRL1_PO_00|LCD_WINCTRL1_PIPE,
301 /* mode_winenable*/ 0/*LCD_WINENABLE_WEN2*/,
304 /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
305 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
306 LCD_WINCTRL1_PO_16BPP |
308 /* mode_winenable*/ 0,
312 /* Need VGA 640 @ 24bpp, @ 32bpp */
313 /* Need VGA 800 @ 24bpp, @ 32bpp */
314 /* Need VGA 1024 @ 24bpp, @ 32bpp */
318 * Controller configurations for various panels.
321 struct panel_settings
323 const char name[25]; /* Full name <vendor>_<model> */
325 struct fb_monspecs monspecs; /* FB monitor specs */
329 uint32 mode_horztiming;
330 uint32 mode_verttiming;
331 uint32 mode_clkcontrol;
335 uint32 mode_fifoctrl;
336 uint32 mode_backlight;
338 #define Xres min_xres
339 #define Yres min_yres
340 u32 min_xres; /* Minimum horizontal resolution */
341 u32 max_xres; /* Maximum horizontal resolution */
342 u32 min_yres; /* Minimum vertical resolution */
343 u32 max_yres; /* Maximum vertical resolution */
346 /********************************************************************/
347 /* fixme: Maybe a modedb for the CRT ? otherwise panels should be as-is */
349 /* List of panels known to work with the AU1200 LCD controller.
350 * To add a new panel, enter the same specifications as the
351 * Generic_TFT one, and MAKE SURE that it doesn't conflicts
352 * with the controller restrictions. Restrictions are:
354 * STN color panels: max_bpp <= 12
355 * STN mono panels: max_bpp <= 4
356 * TFT panels: max_bpp <= 16
360 static struct panel_settings known_lcd_panels[] =
362 [0] = { /* QVGA 320x240 H:33.3kHz V:110Hz */
363 .name = "QVGA_320x240",
373 .input = FB_DISP_RGB,
375 .mode_screen = LCD_SCREEN_SX_N(320) |
376 LCD_SCREEN_SY_N(240),
377 .mode_horztiming = 0x00c4623b,
378 .mode_verttiming = 0x00502814,
379 .mode_clkcontrol = 0x00020002, /* /4=24Mhz */
380 .mode_pwmdiv = 0x00000000,
381 .mode_pwmhi = 0x00000000,
382 .mode_outmask = 0x00FFFFFF,
383 .mode_fifoctrl = 0x2f2f2f2f,
384 .mode_backlight = 0x00000000,
390 [1] = { /* VGA 640x480 H:30.3kHz V:58Hz */
391 .name = "VGA_640x480",
401 .input = FB_DISP_RGB,
403 .mode_screen = 0x13f9df80,
404 .mode_horztiming = 0x003c5859,
405 .mode_verttiming = 0x00741201,
406 .mode_clkcontrol = 0x00020001, /* /4=24Mhz */
407 .mode_pwmdiv = 0x00000000,
408 .mode_pwmhi = 0x00000000,
409 .mode_outmask = 0x00FFFFFF,
410 .mode_fifoctrl = 0x2f2f2f2f,
411 .mode_backlight = 0x00000000,
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_backlight = 0x00000000,
444 [3] = { /* XVGA 1024x768 H:56.2kHz V:70Hz */
445 .name = "XVGA_1024x768",
455 .input = FB_DISP_RGB,
457 .mode_screen = 0x1ffaff80,
458 .mode_horztiming = 0x007d0e57,
459 .mode_verttiming = 0x00740a01,
460 .mode_clkcontrol = 0x000A0000, /* /1 */
461 .mode_pwmdiv = 0x00000000,
462 .mode_pwmhi = 0x00000000,
463 .mode_outmask = 0x00FFFFFF,
464 .mode_fifoctrl = 0x2f2f2f2f,
465 .mode_backlight = 0x00000000,
471 [4] = { /* XVGA XVGA 1280x1024 H:68.5kHz V:65Hz */
472 .name = "XVGA_1280x1024",
482 .input = FB_DISP_RGB,
484 .mode_screen = 0x27fbff80,
485 .mode_horztiming = 0x00cdb2c7,
486 .mode_verttiming = 0x00600002,
487 .mode_clkcontrol = 0x000A0000, /* /1 */
488 .mode_pwmdiv = 0x00000000,
489 .mode_pwmhi = 0x00000000,
490 .mode_outmask = 0x00FFFFFF,
491 .mode_fifoctrl = 0x2f2f2f2f,
492 .mode_backlight = 0x00000000,
498 [5] = { /* Samsung 1024x768 TFT */
499 .name = "Samsung_1024x768_TFT",
509 .input = FB_DISP_RGB,
511 .mode_screen = 0x1ffaff80,
512 .mode_horztiming = 0x018cc677,
513 .mode_verttiming = 0x00241217,
514 .mode_clkcontrol = 0x00000000, /* SCB 0x1 /4=24Mhz */
515 .mode_pwmdiv = 0x8000063f, /* SCB 0x0 */
516 .mode_pwmhi = 0x03400000, /* SCB 0x0 */
517 .mode_outmask = 0x00FFFFFF,
518 .mode_fifoctrl = 0x2f2f2f2f,
519 .mode_backlight = 0x00000000,
525 [6] = { /* Toshiba 640x480 TFT */
526 .name = "Toshiba_640x480_TFT",
536 .input = FB_DISP_RGB,
538 .mode_screen = LCD_SCREEN_SX_N(640) |
539 LCD_SCREEN_SY_N(480),
540 .mode_horztiming = LCD_HORZTIMING_HPW_N(96) |
541 LCD_HORZTIMING_HND1_N(13) | LCD_HORZTIMING_HND2_N(51),
542 .mode_verttiming = LCD_VERTTIMING_VPW_N(2) |
543 LCD_VERTTIMING_VND1_N(11) | LCD_VERTTIMING_VND2_N(32),
544 .mode_clkcontrol = 0x00000000, /* /4=24Mhz */
545 .mode_pwmdiv = 0x8000063f,
546 .mode_pwmhi = 0x03400000,
547 .mode_outmask = 0x00fcfcfc,
548 .mode_fifoctrl = 0x2f2f2f2f,
549 .mode_backlight = 0x00000000,
555 [7] = { /* Sharp 320x240 TFT */
556 .name = "Sharp_320x240_TFT",
566 .input = FB_DISP_RGB,
568 .mode_screen = LCD_SCREEN_SX_N(320) |
569 LCD_SCREEN_SY_N(240),
570 .mode_horztiming = LCD_HORZTIMING_HPW_N(60) |
571 LCD_HORZTIMING_HND1_N(13) | LCD_HORZTIMING_HND2_N(2),
572 .mode_verttiming = LCD_VERTTIMING_VPW_N(2) |
573 LCD_VERTTIMING_VND1_N(2) | LCD_VERTTIMING_VND2_N(5),
574 .mode_clkcontrol = LCD_CLKCONTROL_PCD_N(7), /*16=6Mhz*/
575 .mode_pwmdiv = 0x8000063f,
576 .mode_pwmhi = 0x03400000,
577 .mode_outmask = 0x00fcfcfc,
578 .mode_fifoctrl = 0x2f2f2f2f,
579 .mode_backlight = 0x00000000,
580 .lcdclk = 96, /* 96MHz AUXPLL */
585 [8] = { /* Toppoly TD070WGCB2 7" 856x480 TFT */
586 .name = "Toppoly_TD070WGCB2",
596 .input = FB_DISP_RGB,
598 .mode_screen = LCD_SCREEN_SX_N(856) |
599 LCD_SCREEN_SY_N(480),
600 .mode_horztiming = LCD_HORZTIMING_HND2_N(43) |
601 LCD_HORZTIMING_HND1_N(43) | LCD_HORZTIMING_HPW_N(114),
602 .mode_verttiming = LCD_VERTTIMING_VND2_N(20) |
603 LCD_VERTTIMING_VND1_N(21) | LCD_VERTTIMING_VPW_N(4),
604 .mode_clkcontrol = 0x00020001, /* /4=24Mhz */
605 .mode_pwmdiv = 0x8000063f,
606 .mode_pwmhi = 0x03400000,
607 .mode_outmask = 0x00fcfcfc,
608 .mode_fifoctrl = 0x2f2f2f2f,
609 .mode_backlight = 0x00000000,
615 .name = "DB1300_800x480",
625 .input = FB_DISP_RGB,
627 .mode_screen = LCD_SCREEN_SX_N(800) |
628 LCD_SCREEN_SY_N(480),
629 .mode_horztiming = LCD_HORZTIMING_HPW_N(5) |
630 LCD_HORZTIMING_HND1_N(16) |
631 LCD_HORZTIMING_HND2_N(8),
632 .mode_verttiming = LCD_VERTTIMING_VPW_N(4) |
633 LCD_VERTTIMING_VND1_N(8) |
634 LCD_VERTTIMING_VND2_N(5),
635 .mode_clkcontrol = LCD_CLKCONTROL_PCD_N(1) |
638 .mode_pwmdiv = 0x00000000,
639 .mode_pwmhi = 0x00000000,
640 .mode_outmask = 0x00FFFFFF,
641 .mode_fifoctrl = 0x2f2f2f2f,
642 .mode_backlight = 0x00000000,
649 #define NUM_PANELS (ARRAY_SIZE(known_lcd_panels))
651 /********************************************************************/
653 static int winbpp (unsigned int winctrl1)
657 /* how many bits are needed for each pixel format */
658 switch (winctrl1 & LCD_WINCTRL1_FRM) {
659 case LCD_WINCTRL1_FRM_1BPP:
662 case LCD_WINCTRL1_FRM_2BPP:
665 case LCD_WINCTRL1_FRM_4BPP:
668 case LCD_WINCTRL1_FRM_8BPP:
671 case LCD_WINCTRL1_FRM_12BPP:
672 case LCD_WINCTRL1_FRM_16BPP655:
673 case LCD_WINCTRL1_FRM_16BPP565:
674 case LCD_WINCTRL1_FRM_16BPP556:
675 case LCD_WINCTRL1_FRM_16BPPI1555:
676 case LCD_WINCTRL1_FRM_16BPPI5551:
677 case LCD_WINCTRL1_FRM_16BPPA1555:
678 case LCD_WINCTRL1_FRM_16BPPA5551:
681 case LCD_WINCTRL1_FRM_24BPP:
682 case LCD_WINCTRL1_FRM_32BPP:
690 static int fbinfo2index (struct fb_info *fb_info)
694 for (i = 0; i < device_count; ++i) {
695 if (fb_info == _au1200fb_infos[i])
698 printk("au1200fb: ERROR: fbinfo2index failed!\n");
702 static int au1200_setlocation (struct au1200fb_device *fbdev, int plane,
705 uint32 winctrl0, winctrl1, winenable, fb_offset = 0;
708 /* FIX!!! NOT CHECKING FOR COMPLETE OFFSCREEN YET */
710 winctrl0 = lcd->window[plane].winctrl0;
711 winctrl1 = lcd->window[plane].winctrl1;
712 winctrl0 &= (LCD_WINCTRL0_A | LCD_WINCTRL0_AEN);
713 winctrl1 &= ~(LCD_WINCTRL1_SZX | LCD_WINCTRL1_SZY);
715 /* Check for off-screen adjustments */
716 xsz = win->w[plane].xres;
717 ysz = win->w[plane].yres;
718 if ((xpos + win->w[plane].xres) > panel->Xres) {
719 /* Off-screen to the right */
720 xsz = panel->Xres - xpos; /* off by 1 ??? */
721 /*printk("off screen right\n");*/
724 if ((ypos + win->w[plane].yres) > panel->Yres) {
725 /* Off-screen to the bottom */
726 ysz = panel->Yres - ypos; /* off by 1 ??? */
727 /*printk("off screen bottom\n");*/
731 /* Off-screen to the left */
732 xsz = win->w[plane].xres + xpos;
733 fb_offset += (((0 - xpos) * winbpp(lcd->window[plane].winctrl1))/8);
735 /*printk("off screen left\n");*/
739 /* Off-screen to the top */
740 ysz = win->w[plane].yres + ypos;
741 /* fixme: fb_offset += ((0-ypos)*fb_pars[plane].line_length); */
743 /*printk("off screen top\n");*/
746 /* record settings */
747 win->w[plane].xpos = xpos;
748 win->w[plane].ypos = ypos;
752 winctrl0 |= (xpos << 21);
753 winctrl0 |= (ypos << 10);
754 winctrl1 |= (xsz << 11);
755 winctrl1 |= (ysz << 0);
757 /* Disable the window while making changes, then restore WINEN */
758 winenable = lcd->winenable & (1 << plane);
759 wmb(); /* drain writebuffer */
760 lcd->winenable &= ~(1 << plane);
761 lcd->window[plane].winctrl0 = winctrl0;
762 lcd->window[plane].winctrl1 = winctrl1;
763 lcd->window[plane].winbuf0 =
764 lcd->window[plane].winbuf1 = fbdev->fb_phys;
765 lcd->window[plane].winbufctrl = 0; /* select winbuf0 */
766 lcd->winenable |= winenable;
767 wmb(); /* drain writebuffer */
772 static void au1200_setpanel(struct panel_settings *newpanel,
773 struct au1200fb_platdata *pd)
776 * Perform global setup/init of LCD controller
780 /* Make sure all windows disabled */
781 winenable = lcd->winenable;
783 wmb(); /* drain writebuffer */
785 * Ensure everything is disabled before reconfiguring
787 if (lcd->screen & LCD_SCREEN_SEN) {
788 /* Wait for vertical sync period */
789 lcd->intstatus = LCD_INT_SS;
790 while ((lcd->intstatus & LCD_INT_SS) == 0)
793 lcd->screen &= ~LCD_SCREEN_SEN; /*disable the controller*/
796 lcd->intstatus = lcd->intstatus; /*clear interrupts*/
797 wmb(); /* drain writebuffer */
798 /*wait for controller to shut down*/
799 } while ((lcd->intstatus & LCD_INT_SD) == 0);
801 /* Call shutdown of current panel (if up) */
802 /* this must occur last, because if an external clock is driving
803 the controller, the clock cannot be turned off before first
804 shutting down the controller.
806 if (pd->panel_shutdown)
807 pd->panel_shutdown();
810 /* Newpanel == NULL indicates a shutdown operation only */
811 if (newpanel == NULL)
816 printk("Panel(%s), %dx%d\n", panel->name, panel->Xres, panel->Yres);
819 * Setup clocking if internal LCD clock source (assumes sys_auxpll valid)
821 if (!(panel->mode_clkcontrol & LCD_CLKCONTROL_EXT))
823 struct clk *c = clk_get(NULL, "lcd_intclk");
824 long r, pc = panel->lcdclk * 1000000;
827 r = clk_round_rate(c, pc);
828 if ((pc - r) < (pc / 10)) { /* 10% slack */
830 clk_prepare_enable(c);
837 * Configure panel timings
839 lcd->screen = panel->mode_screen;
840 lcd->horztiming = panel->mode_horztiming;
841 lcd->verttiming = panel->mode_verttiming;
842 lcd->clkcontrol = panel->mode_clkcontrol;
843 lcd->pwmdiv = panel->mode_pwmdiv;
844 lcd->pwmhi = panel->mode_pwmhi;
845 lcd->outmask = panel->mode_outmask;
846 lcd->fifoctrl = panel->mode_fifoctrl;
847 wmb(); /* drain writebuffer */
849 /* fixme: Check window settings to make sure still valid
850 * for new geometry */
852 au1200_setlocation(fbdev, 0, win->w[0].xpos, win->w[0].ypos);
853 au1200_setlocation(fbdev, 1, win->w[1].xpos, win->w[1].ypos);
854 au1200_setlocation(fbdev, 2, win->w[2].xpos, win->w[2].ypos);
855 au1200_setlocation(fbdev, 3, win->w[3].xpos, win->w[3].ypos);
857 lcd->winenable = winenable;
860 * Re-enable screen now that it is configured
862 lcd->screen |= LCD_SCREEN_SEN;
863 wmb(); /* drain writebuffer */
865 /* Call init of panel */
869 /* FIX!!!! not appropriate on panel change!!! Global setup/init */
872 lcd->backcolor = win->mode_backcolor;
874 /* Setup Color Key - FIX!!! */
875 lcd->colorkey = win->mode_colorkey;
876 lcd->colorkeymsk = win->mode_colorkeymsk;
878 /* Setup HWCursor - FIX!!! Need to support this eventually */
879 lcd->hwc.cursorctrl = 0;
880 lcd->hwc.cursorpos = 0;
881 lcd->hwc.cursorcolor0 = 0;
882 lcd->hwc.cursorcolor1 = 0;
883 lcd->hwc.cursorcolor2 = 0;
884 lcd->hwc.cursorcolor3 = 0;
888 #define D(X) printk("%25s: %08X\n", #X, X)
897 D(lcd->window[0].winctrl0);
898 D(lcd->window[0].winctrl1);
899 D(lcd->window[0].winctrl2);
900 D(lcd->window[0].winbuf0);
901 D(lcd->window[0].winbuf1);
902 D(lcd->window[0].winbufctrl);
903 D(lcd->window[1].winctrl0);
904 D(lcd->window[1].winctrl1);
905 D(lcd->window[1].winctrl2);
906 D(lcd->window[1].winbuf0);
907 D(lcd->window[1].winbuf1);
908 D(lcd->window[1].winbufctrl);
909 D(lcd->window[2].winctrl0);
910 D(lcd->window[2].winctrl1);
911 D(lcd->window[2].winctrl2);
912 D(lcd->window[2].winbuf0);
913 D(lcd->window[2].winbuf1);
914 D(lcd->window[2].winbufctrl);
915 D(lcd->window[3].winctrl0);
916 D(lcd->window[3].winctrl1);
917 D(lcd->window[3].winctrl2);
918 D(lcd->window[3].winbuf0);
919 D(lcd->window[3].winbuf1);
920 D(lcd->window[3].winbufctrl);
928 D(lcd->hwc.cursorctrl);
929 D(lcd->hwc.cursorpos);
930 D(lcd->hwc.cursorcolor0);
931 D(lcd->hwc.cursorcolor1);
932 D(lcd->hwc.cursorcolor2);
933 D(lcd->hwc.cursorcolor3);
937 static void au1200_setmode(struct au1200fb_device *fbdev)
939 int plane = fbdev->plane;
940 /* Window/plane setup */
941 lcd->window[plane].winctrl1 = ( 0
942 | LCD_WINCTRL1_PRI_N(plane)
943 | win->w[plane].mode_winctrl1 /* FRM,CCO,PO,PIPE */
946 au1200_setlocation(fbdev, plane, win->w[plane].xpos, win->w[plane].ypos);
948 lcd->window[plane].winctrl2 = ( 0
949 | LCD_WINCTRL2_CKMODE_00
951 | LCD_WINCTRL2_BX_N(fbdev->fb_info->fix.line_length)
955 lcd->winenable |= win->w[plane].mode_winenable;
956 wmb(); /* drain writebuffer */
962 /*#define panel_is_dual(panel) ((panel->mode_screen & LCD_SCREEN_PT) == LCD_SCREEN_PT_010)*/
963 /*#define panel_is_active(panel)((panel->mode_screen & LCD_SCREEN_PT) == LCD_SCREEN_PT_010)*/
965 #define panel_is_color(panel) ((panel->mode_screen & LCD_SCREEN_PT) <= LCD_SCREEN_PT_CDSTN)
967 /* Bitfields format supported by the controller. */
968 static struct fb_bitfield rgb_bitfields[][4] = {
969 /* Red, Green, Blue, Transp */
970 [LCD_WINCTRL1_FRM_16BPP655 >> 25] =
971 { { 10, 6, 0 }, { 5, 5, 0 }, { 0, 5, 0 }, { 0, 0, 0 } },
973 [LCD_WINCTRL1_FRM_16BPP565 >> 25] =
974 { { 11, 5, 0 }, { 5, 6, 0 }, { 0, 5, 0 }, { 0, 0, 0 } },
976 [LCD_WINCTRL1_FRM_16BPP556 >> 25] =
977 { { 11, 5, 0 }, { 6, 5, 0 }, { 0, 6, 0 }, { 0, 0, 0 } },
979 [LCD_WINCTRL1_FRM_16BPPI1555 >> 25] =
980 { { 10, 5, 0 }, { 5, 5, 0 }, { 0, 5, 0 }, { 0, 0, 0 } },
982 [LCD_WINCTRL1_FRM_16BPPI5551 >> 25] =
983 { { 11, 5, 0 }, { 6, 5, 0 }, { 1, 5, 0 }, { 0, 0, 0 } },
985 [LCD_WINCTRL1_FRM_16BPPA1555 >> 25] =
986 { { 10, 5, 0 }, { 5, 5, 0 }, { 0, 5, 0 }, { 15, 1, 0 } },
988 [LCD_WINCTRL1_FRM_16BPPA5551 >> 25] =
989 { { 11, 5, 0 }, { 6, 5, 0 }, { 1, 5, 0 }, { 0, 1, 0 } },
991 [LCD_WINCTRL1_FRM_24BPP >> 25] =
992 { { 16, 8, 0 }, { 8, 8, 0 }, { 0, 8, 0 }, { 0, 0, 0 } },
994 [LCD_WINCTRL1_FRM_32BPP >> 25] =
995 { { 16, 8, 0 }, { 8, 8, 0 }, { 0, 8, 0 }, { 24, 0, 0 } },
998 /*-------------------------------------------------------------------------*/
1002 static void au1200fb_update_fbinfo(struct fb_info *fbi)
1004 /* FIX!!!! This also needs to take the window pixel format into account!!! */
1006 /* Update var-dependent FB info */
1007 if (panel_is_color(panel)) {
1008 if (fbi->var.bits_per_pixel <= 8) {
1010 fbi->fix.visual = FB_VISUAL_PSEUDOCOLOR;
1011 fbi->fix.line_length = fbi->var.xres_virtual /
1012 (8/fbi->var.bits_per_pixel);
1014 /* non-palettized */
1015 fbi->fix.visual = FB_VISUAL_TRUECOLOR;
1016 fbi->fix.line_length = fbi->var.xres_virtual * (fbi->var.bits_per_pixel / 8);
1019 /* mono FIX!!! mono 8 and 4 bits */
1020 fbi->fix.visual = FB_VISUAL_MONO10;
1021 fbi->fix.line_length = fbi->var.xres_virtual / 8;
1024 fbi->screen_size = fbi->fix.line_length * fbi->var.yres_virtual;
1025 print_dbg("line length: %d\n", fbi->fix.line_length);
1026 print_dbg("bits_per_pixel: %d\n", fbi->var.bits_per_pixel);
1029 /*-------------------------------------------------------------------------*/
1031 /* AU1200 framebuffer driver */
1034 * Validate var settings with hardware restrictions and modify it if necessary
1036 static int au1200fb_fb_check_var(struct fb_var_screeninfo *var,
1037 struct fb_info *fbi)
1039 struct au1200fb_device *fbdev = fbi->par;
1041 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 return dma_mmap_attrs(fbdev->dev, vma, fbdev->fb_mem, fbdev->fb_phys,
1243 static void set_global(u_int cmd, struct au1200_lcd_global_regs_t *pdata)
1246 unsigned int hi1, divider;
1248 /* SCREEN_SIZE: user cannot reset size, must switch panel choice */
1250 if (pdata->flags & SCREEN_BACKCOLOR)
1251 lcd->backcolor = pdata->backcolor;
1253 if (pdata->flags & SCREEN_BRIGHTNESS) {
1255 // limit brightness pwm duty to >= 30/1600
1256 if (pdata->brightness < 30) {
1257 pdata->brightness = 30;
1259 divider = (lcd->pwmdiv & 0x3FFFF) + 1;
1260 hi1 = (((pdata->brightness & 0xFF)+1) * divider >> 8);
1261 lcd->pwmhi &= 0xFFFF;
1262 lcd->pwmhi |= (hi1 << 16);
1265 if (pdata->flags & SCREEN_COLORKEY)
1266 lcd->colorkey = pdata->colorkey;
1268 if (pdata->flags & SCREEN_MASK)
1269 lcd->colorkeymsk = pdata->mask;
1270 wmb(); /* drain writebuffer */
1273 static void get_global(u_int cmd, struct au1200_lcd_global_regs_t *pdata)
1275 unsigned int hi1, divider;
1277 pdata->xsize = ((lcd->screen & LCD_SCREEN_SX) >> 19) + 1;
1278 pdata->ysize = ((lcd->screen & LCD_SCREEN_SY) >> 8) + 1;
1280 pdata->backcolor = lcd->backcolor;
1281 pdata->colorkey = lcd->colorkey;
1282 pdata->mask = lcd->colorkeymsk;
1285 hi1 = (lcd->pwmhi >> 16) + 1;
1286 divider = (lcd->pwmdiv & 0x3FFFF) + 1;
1287 pdata->brightness = ((hi1 << 8) / divider) - 1;
1288 wmb(); /* drain writebuffer */
1291 static void set_window(unsigned int plane,
1292 struct au1200_lcd_window_regs_t *pdata)
1294 unsigned int val, bpp;
1296 /* Window control register 0 */
1297 if (pdata->flags & WIN_POSITION) {
1298 val = lcd->window[plane].winctrl0 & ~(LCD_WINCTRL0_OX |
1300 val |= ((pdata->xpos << 21) & LCD_WINCTRL0_OX);
1301 val |= ((pdata->ypos << 10) & LCD_WINCTRL0_OY);
1302 lcd->window[plane].winctrl0 = val;
1304 if (pdata->flags & WIN_ALPHA_COLOR) {
1305 val = lcd->window[plane].winctrl0 & ~(LCD_WINCTRL0_A);
1306 val |= ((pdata->alpha_color << 2) & LCD_WINCTRL0_A);
1307 lcd->window[plane].winctrl0 = val;
1309 if (pdata->flags & WIN_ALPHA_MODE) {
1310 val = lcd->window[plane].winctrl0 & ~(LCD_WINCTRL0_AEN);
1311 val |= ((pdata->alpha_mode << 1) & LCD_WINCTRL0_AEN);
1312 lcd->window[plane].winctrl0 = val;
1315 /* Window control register 1 */
1316 if (pdata->flags & WIN_PRIORITY) {
1317 val = lcd->window[plane].winctrl1 & ~(LCD_WINCTRL1_PRI);
1318 val |= ((pdata->priority << 30) & LCD_WINCTRL1_PRI);
1319 lcd->window[plane].winctrl1 = val;
1321 if (pdata->flags & WIN_CHANNEL) {
1322 val = lcd->window[plane].winctrl1 & ~(LCD_WINCTRL1_PIPE);
1323 val |= ((pdata->channel << 29) & LCD_WINCTRL1_PIPE);
1324 lcd->window[plane].winctrl1 = val;
1326 if (pdata->flags & WIN_BUFFER_FORMAT) {
1327 val = lcd->window[plane].winctrl1 & ~(LCD_WINCTRL1_FRM);
1328 val |= ((pdata->buffer_format << 25) & LCD_WINCTRL1_FRM);
1329 lcd->window[plane].winctrl1 = val;
1331 if (pdata->flags & WIN_COLOR_ORDER) {
1332 val = lcd->window[plane].winctrl1 & ~(LCD_WINCTRL1_CCO);
1333 val |= ((pdata->color_order << 24) & LCD_WINCTRL1_CCO);
1334 lcd->window[plane].winctrl1 = val;
1336 if (pdata->flags & WIN_PIXEL_ORDER) {
1337 val = lcd->window[plane].winctrl1 & ~(LCD_WINCTRL1_PO);
1338 val |= ((pdata->pixel_order << 22) & LCD_WINCTRL1_PO);
1339 lcd->window[plane].winctrl1 = val;
1341 if (pdata->flags & WIN_SIZE) {
1342 val = lcd->window[plane].winctrl1 & ~(LCD_WINCTRL1_SZX |
1344 val |= (((pdata->xsize << 11) - 1) & LCD_WINCTRL1_SZX);
1345 val |= (((pdata->ysize) - 1) & LCD_WINCTRL1_SZY);
1346 lcd->window[plane].winctrl1 = val;
1347 /* program buffer line width */
1348 bpp = winbpp(val) / 8;
1349 val = lcd->window[plane].winctrl2 & ~(LCD_WINCTRL2_BX);
1350 val |= (((pdata->xsize * bpp) << 8) & LCD_WINCTRL2_BX);
1351 lcd->window[plane].winctrl2 = val;
1354 /* Window control register 2 */
1355 if (pdata->flags & WIN_COLORKEY_MODE) {
1356 val = lcd->window[plane].winctrl2 & ~(LCD_WINCTRL2_CKMODE);
1357 val |= ((pdata->colorkey_mode << 24) & LCD_WINCTRL2_CKMODE);
1358 lcd->window[plane].winctrl2 = val;
1360 if (pdata->flags & WIN_DOUBLE_BUFFER_MODE) {
1361 val = lcd->window[plane].winctrl2 & ~(LCD_WINCTRL2_DBM);
1362 val |= ((pdata->double_buffer_mode << 23) & LCD_WINCTRL2_DBM);
1363 lcd->window[plane].winctrl2 = val;
1365 if (pdata->flags & WIN_RAM_ARRAY_MODE) {
1366 val = lcd->window[plane].winctrl2 & ~(LCD_WINCTRL2_RAM);
1367 val |= ((pdata->ram_array_mode << 21) & LCD_WINCTRL2_RAM);
1368 lcd->window[plane].winctrl2 = val;
1371 /* Buffer line width programmed with WIN_SIZE */
1373 if (pdata->flags & WIN_BUFFER_SCALE) {
1374 val = lcd->window[plane].winctrl2 & ~(LCD_WINCTRL2_SCX |
1376 val |= ((pdata->xsize << 11) & LCD_WINCTRL2_SCX);
1377 val |= ((pdata->ysize) & LCD_WINCTRL2_SCY);
1378 lcd->window[plane].winctrl2 = val;
1381 if (pdata->flags & WIN_ENABLE) {
1382 val = lcd->winenable;
1384 val |= (pdata->enable & 1) << plane;
1385 lcd->winenable = val;
1387 wmb(); /* drain writebuffer */
1390 static void get_window(unsigned int plane,
1391 struct au1200_lcd_window_regs_t *pdata)
1393 /* Window control register 0 */
1394 pdata->xpos = (lcd->window[plane].winctrl0 & LCD_WINCTRL0_OX) >> 21;
1395 pdata->ypos = (lcd->window[plane].winctrl0 & LCD_WINCTRL0_OY) >> 10;
1396 pdata->alpha_color = (lcd->window[plane].winctrl0 & LCD_WINCTRL0_A) >> 2;
1397 pdata->alpha_mode = (lcd->window[plane].winctrl0 & LCD_WINCTRL0_AEN) >> 1;
1399 /* Window control register 1 */
1400 pdata->priority = (lcd->window[plane].winctrl1& LCD_WINCTRL1_PRI) >> 30;
1401 pdata->channel = (lcd->window[plane].winctrl1 & LCD_WINCTRL1_PIPE) >> 29;
1402 pdata->buffer_format = (lcd->window[plane].winctrl1 & LCD_WINCTRL1_FRM) >> 25;
1403 pdata->color_order = (lcd->window[plane].winctrl1 & LCD_WINCTRL1_CCO) >> 24;
1404 pdata->pixel_order = (lcd->window[plane].winctrl1 & LCD_WINCTRL1_PO) >> 22;
1405 pdata->xsize = ((lcd->window[plane].winctrl1 & LCD_WINCTRL1_SZX) >> 11) + 1;
1406 pdata->ysize = (lcd->window[plane].winctrl1 & LCD_WINCTRL1_SZY) + 1;
1408 /* Window control register 2 */
1409 pdata->colorkey_mode = (lcd->window[plane].winctrl2 & LCD_WINCTRL2_CKMODE) >> 24;
1410 pdata->double_buffer_mode = (lcd->window[plane].winctrl2 & LCD_WINCTRL2_DBM) >> 23;
1411 pdata->ram_array_mode = (lcd->window[plane].winctrl2 & LCD_WINCTRL2_RAM) >> 21;
1413 pdata->enable = (lcd->winenable >> plane) & 1;
1414 wmb(); /* drain writebuffer */
1417 static int au1200fb_ioctl(struct fb_info *info, unsigned int cmd,
1420 struct au1200fb_device *fbdev = info->par;
1424 plane = fbinfo2index(info);
1425 print_dbg("au1200fb: ioctl %d on plane %d\n", cmd, plane);
1427 if (cmd == AU1200_LCD_FB_IOCTL) {
1428 struct au1200_lcd_iodata_t iodata;
1430 if (copy_from_user(&iodata, (void __user *) arg, sizeof(iodata)))
1433 print_dbg("FB IOCTL called\n");
1435 switch (iodata.subcmd) {
1436 case AU1200_LCD_SET_SCREEN:
1437 print_dbg("AU1200_LCD_SET_SCREEN\n");
1438 set_global(cmd, &iodata.global);
1441 case AU1200_LCD_GET_SCREEN:
1442 print_dbg("AU1200_LCD_GET_SCREEN\n");
1443 get_global(cmd, &iodata.global);
1446 case AU1200_LCD_SET_WINDOW:
1447 print_dbg("AU1200_LCD_SET_WINDOW\n");
1448 set_window(plane, &iodata.window);
1451 case AU1200_LCD_GET_WINDOW:
1452 print_dbg("AU1200_LCD_GET_WINDOW\n");
1453 get_window(plane, &iodata.window);
1456 case AU1200_LCD_SET_PANEL:
1457 print_dbg("AU1200_LCD_SET_PANEL\n");
1458 if ((iodata.global.panel_choice >= 0) &&
1459 (iodata.global.panel_choice <
1462 struct panel_settings *newpanel;
1463 panel_index = iodata.global.panel_choice;
1464 newpanel = &known_lcd_panels[panel_index];
1465 au1200_setpanel(newpanel, fbdev->pd);
1469 case AU1200_LCD_GET_PANEL:
1470 print_dbg("AU1200_LCD_GET_PANEL\n");
1471 iodata.global.panel_choice = panel_index;
1478 val = copy_to_user((void __user *) arg, &iodata, sizeof(iodata));
1480 print_dbg("error: could not copy %d bytes\n", val);
1489 static const struct fb_ops au1200fb_fb_ops = {
1490 .owner = THIS_MODULE,
1491 .fb_check_var = au1200fb_fb_check_var,
1492 .fb_set_par = au1200fb_fb_set_par,
1493 .fb_setcolreg = au1200fb_fb_setcolreg,
1494 .fb_blank = au1200fb_fb_blank,
1495 .fb_fillrect = sys_fillrect,
1496 .fb_copyarea = sys_copyarea,
1497 .fb_imageblit = sys_imageblit,
1498 .fb_read = fb_sys_read,
1499 .fb_write = fb_sys_write,
1501 .fb_ioctl = au1200fb_ioctl,
1502 .fb_mmap = au1200fb_fb_mmap,
1505 /*-------------------------------------------------------------------------*/
1507 static irqreturn_t au1200fb_handle_irq(int irq, void* dev_id)
1509 /* Nothing to do for now, just clear any pending interrupt */
1510 lcd->intstatus = lcd->intstatus;
1511 wmb(); /* drain writebuffer */
1516 /*-------------------------------------------------------------------------*/
1518 /* AU1200 LCD device probe helpers */
1520 static int au1200fb_init_fbinfo(struct au1200fb_device *fbdev)
1522 struct fb_info *fbi = fbdev->fb_info;
1525 fbi->fbops = &au1200fb_fb_ops;
1527 bpp = winbpp(win->w[fbdev->plane].mode_winctrl1);
1529 /* Copy monitor specs from panel data */
1530 /* fixme: we're setting up LCD controller windows, so these dont give a
1531 damn as to what the monitor specs are (the panel itself does, but that
1532 isn't done here...so maybe need a generic catchall monitor setting??? */
1533 memcpy(&fbi->monspecs, &panel->monspecs, sizeof(struct fb_monspecs));
1535 /* We first try the user mode passed in argument. If that failed,
1536 * or if no one has been specified, we default to the first mode of the
1537 * panel list. Note that after this call, var data will be set */
1538 if (!fb_find_mode(&fbi->var,
1540 NULL, /* drv_info.opt_mode, */
1541 fbi->monspecs.modedb,
1542 fbi->monspecs.modedb_len,
1543 fbi->monspecs.modedb,
1546 print_err("Cannot find valid mode for panel %s", panel->name);
1550 fbi->pseudo_palette = kcalloc(16, sizeof(u32), GFP_KERNEL);
1551 if (!fbi->pseudo_palette)
1554 ret = fb_alloc_cmap(&fbi->cmap, AU1200_LCD_NBR_PALETTE_ENTRIES, 0);
1556 print_err("Fail to allocate colormap (%d entries)",
1557 AU1200_LCD_NBR_PALETTE_ENTRIES);
1561 strncpy(fbi->fix.id, "AU1200", sizeof(fbi->fix.id));
1562 fbi->fix.smem_start = fbdev->fb_phys;
1563 fbi->fix.smem_len = fbdev->fb_len;
1564 fbi->fix.type = FB_TYPE_PACKED_PIXELS;
1565 fbi->fix.xpanstep = 0;
1566 fbi->fix.ypanstep = 0;
1567 fbi->fix.mmio_start = 0;
1568 fbi->fix.mmio_len = 0;
1569 fbi->fix.accel = FB_ACCEL_NONE;
1571 fbi->screen_base = (char __iomem *) fbdev->fb_mem;
1573 au1200fb_update_fbinfo(fbi);
1578 /*-------------------------------------------------------------------------*/
1581 static int au1200fb_setup(struct au1200fb_platdata *pd)
1583 char *options = NULL;
1584 char *this_opt, *endptr;
1585 int num_panels = ARRAY_SIZE(known_lcd_panels);
1588 fb_get_options(DRIVER_NAME, &options);
1593 while ((this_opt = strsep(&options, ",")) != NULL) {
1594 /* Panel option - can be panel name,
1595 * "bs" for board-switch, or number/index */
1596 if (!strncmp(this_opt, "panel:", 6)) {
1601 /* First check for index, which allows
1602 * to short circuit this mess */
1603 li = simple_strtol(this_opt, &endptr, 0);
1604 if (*endptr == '\0')
1605 panel_idx = (int)li;
1606 else if (strcmp(this_opt, "bs") == 0)
1607 panel_idx = pd->panel_index();
1609 for (i = 0; i < num_panels; i++) {
1610 if (!strcmp(this_opt,
1611 known_lcd_panels[i].name)) {
1617 if ((panel_idx < 0) || (panel_idx >= num_panels))
1618 print_warn("Panel %s not supported!", this_opt);
1620 panel_index = panel_idx;
1622 } else if (strncmp(this_opt, "nohwcursor", 10) == 0)
1624 else if (strncmp(this_opt, "devices:", 8) == 0) {
1626 device_count = simple_strtol(this_opt, &endptr, 0);
1627 if ((device_count < 0) ||
1628 (device_count > MAX_DEVICE_COUNT))
1629 device_count = MAX_DEVICE_COUNT;
1630 } else if (strncmp(this_opt, "wincfg:", 7) == 0) {
1632 window_index = simple_strtol(this_opt, &endptr, 0);
1633 if ((window_index < 0) ||
1634 (window_index >= ARRAY_SIZE(windows)))
1635 window_index = DEFAULT_WINDOW_INDEX;
1636 } else if (strncmp(this_opt, "off", 3) == 0)
1639 print_warn("Unsupported option \"%s\"", this_opt);
1646 /* AU1200 LCD controller device driver */
1647 static int au1200fb_drv_probe(struct platform_device *dev)
1649 struct au1200fb_device *fbdev;
1650 struct au1200fb_platdata *pd;
1651 struct fb_info *fbi = NULL;
1652 int bpp, plane, ret, irq;
1654 print_info("" DRIVER_DESC "");
1656 pd = dev->dev.platform_data;
1660 /* Setup driver with options */
1661 if (au1200fb_setup(pd))
1664 /* Point to the panel selected */
1665 panel = &known_lcd_panels[panel_index];
1666 win = &windows[window_index];
1668 printk(DRIVER_NAME ": Panel %d %s\n", panel_index, panel->name);
1669 printk(DRIVER_NAME ": Win %d %s\n", window_index, win->name);
1671 for (plane = 0; plane < device_count; ++plane) {
1672 bpp = winbpp(win->w[plane].mode_winctrl1);
1673 if (win->w[plane].xres == 0)
1674 win->w[plane].xres = panel->Xres;
1675 if (win->w[plane].yres == 0)
1676 win->w[plane].yres = panel->Yres;
1678 fbi = framebuffer_alloc(sizeof(struct au1200fb_device),
1685 _au1200fb_infos[plane] = fbi;
1687 fbdev->fb_info = fbi;
1689 fbdev->dev = &dev->dev;
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_attrs(&dev->dev,
1697 PAGE_ALIGN(fbdev->fb_len),
1698 &fbdev->fb_phys, GFP_KERNEL, 0);
1699 if (!fbdev->fb_mem) {
1700 print_err("fail to allocate framebuffer (size: %dK))",
1701 fbdev->fb_len / 1024);
1706 print_dbg("Framebuffer memory map at %p", fbdev->fb_mem);
1707 print_dbg("phys=0x%08x, size=%dK", fbdev->fb_phys, fbdev->fb_len / 1024);
1710 ret = au1200fb_init_fbinfo(fbdev);
1714 /* Register new framebuffer */
1715 ret = register_framebuffer(fbi);
1717 print_err("cannot register new framebuffer");
1721 au1200fb_fb_set_par(fbi);
1723 #if !defined(CONFIG_FRAMEBUFFER_CONSOLE) && defined(CONFIG_LOGO)
1725 if (fb_prepare_logo(fbi, FB_ROTATE_UR)) {
1726 /* Start display and show logo on boot */
1727 fb_set_cmap(&fbi->cmap, fbi);
1728 fb_show_logo(fbi, FB_ROTATE_UR);
1733 /* Now hook interrupt too */
1734 irq = platform_get_irq(dev, 0);
1738 ret = request_irq(irq, au1200fb_handle_irq,
1739 IRQF_SHARED, "lcd", (void *)dev);
1741 print_err("fail to request interrupt line %d (err: %d)",
1746 platform_set_drvdata(dev, pd);
1748 /* Kickstart the panel */
1749 au1200_setpanel(panel, pd);
1754 for (plane = 0; plane < device_count; ++plane) {
1755 fbi = _au1200fb_infos[plane];
1759 /* Clean up all probe data */
1760 unregister_framebuffer(fbi);
1761 if (fbi->cmap.len != 0)
1762 fb_dealloc_cmap(&fbi->cmap);
1763 kfree(fbi->pseudo_palette);
1765 framebuffer_release(fbi);
1766 _au1200fb_infos[plane] = NULL;
1771 static int au1200fb_drv_remove(struct platform_device *dev)
1773 struct au1200fb_platdata *pd = platform_get_drvdata(dev);
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];
1783 /* Clean up all probe data */
1784 unregister_framebuffer(fbi);
1785 if (fbi->cmap.len != 0)
1786 fb_dealloc_cmap(&fbi->cmap);
1787 kfree(fbi->pseudo_palette);
1789 framebuffer_release(fbi);
1790 _au1200fb_infos[plane] = NULL;
1793 free_irq(platform_get_irq(dev, 0), (void *)dev);
1799 static int au1200fb_drv_suspend(struct device *dev)
1801 struct au1200fb_platdata *pd = dev_get_drvdata(dev);
1802 au1200_setpanel(NULL, pd);
1805 wmb(); /* drain writebuffer */
1810 static int au1200fb_drv_resume(struct device *dev)
1812 struct au1200fb_platdata *pd = dev_get_drvdata(dev);
1813 struct fb_info *fbi;
1816 /* Kickstart the panel */
1817 au1200_setpanel(panel, pd);
1819 for (i = 0; i < device_count; i++) {
1820 fbi = _au1200fb_infos[i];
1821 au1200fb_fb_set_par(fbi);
1827 static const struct dev_pm_ops au1200fb_pmops = {
1828 .suspend = au1200fb_drv_suspend,
1829 .resume = au1200fb_drv_resume,
1830 .freeze = au1200fb_drv_suspend,
1831 .thaw = au1200fb_drv_resume,
1834 #define AU1200FB_PMOPS (&au1200fb_pmops)
1837 #define AU1200FB_PMOPS NULL
1838 #endif /* CONFIG_PM */
1840 static struct platform_driver au1200fb_driver = {
1842 .name = "au1200-lcd",
1843 .pm = AU1200FB_PMOPS,
1845 .probe = au1200fb_drv_probe,
1846 .remove = au1200fb_drv_remove,
1848 module_platform_driver(au1200fb_driver);
1850 MODULE_DESCRIPTION(DRIVER_DESC);
1851 MODULE_LICENSE("GPL");