1 /*
2 * BRIEF MODULE DESCRIPTION
3 * Au1200 LCD Driver.
4 *
5 * Copyright 2004-2005 AMD
6 * Author: AMD
7 *
8 * Based on:
9 * linux/drivers/video/skeletonfb.c -- Skeleton for a frame buffer device
10 * Created 28 Dec 1997 by Geert Uytterhoeven
11 *
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.
16 *
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.
27 *
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.
31 */
32
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>
39 #include <linux/mm.h>
40 #include <linux/fb.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>
47
48 #include <asm/mach-au1x00/au1000.h>
49 #include <asm/mach-au1x00/au1200fb.h> /* platform_data */
50 #include "au1200fb.h"
51
52 #define DRIVER_NAME "au1200fb"
53 #define DRIVER_DESC "LCD controller driver for AU1200 processors"
54
55 #define DEBUG 0
56
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)
60
61 #if DEBUG
62 #define print_dbg(f, arg...) printk(KERN_DEBUG __FILE__ ": " f "\n", ## arg)
63 #else
64 #define print_dbg(f, arg...) do {} while (0)
65 #endif
66
67
68 #define AU1200_LCD_FB_IOCTL 0x46FF
69
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
76
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)
82
83 struct au1200_lcd_global_regs_t {
84 unsigned int flags;
85 unsigned int xsize;
86 unsigned int ysize;
87 unsigned int backcolor;
88 unsigned int brightness;
89 unsigned int colorkey;
90 unsigned int mask;
91 unsigned int panel_choice;
92 char panel_desc[80];
93
94 };
95
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)
110
111 struct au1200_lcd_window_regs_t {
112 unsigned int flags;
113 unsigned int xpos;
114 unsigned int ypos;
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;
122 unsigned int xsize;
123 unsigned int ysize;
124 unsigned int colorkey_mode;
125 unsigned int double_buffer_mode;
126 unsigned int ram_array_mode;
127 unsigned int xscale;
128 unsigned int yscale;
129 unsigned int enable;
130 };
131
132
133 struct au1200_lcd_iodata_t {
134 unsigned int subcmd;
135 struct au1200_lcd_global_regs_t global;
136 struct au1200_lcd_window_regs_t window;
137 };
138
139 #if defined(__BIG_ENDIAN)
140 #define LCD_CONTROL_DEFAULT_PO LCD_CONTROL_PO_11
141 #else
142 #define LCD_CONTROL_DEFAULT_PO LCD_CONTROL_PO_00
143 #endif
144 #define LCD_CONTROL_DEFAULT_SBPPF LCD_CONTROL_SBPPF_565
145
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;
150 struct device *dev;
151
152 int plane;
153 unsigned char* fb_mem; /* FrameBuffer memory map */
154 unsigned int fb_len;
155 dma_addr_t fb_phys;
156 };
157
158 /********************************************************************/
159
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
166
167 /* Default number of visible screen buffer to allocate */
168 #define AU1200FB_NBR_VIDEO_BUFFERS 1
169
170 /* Default maximum number of fb devices to create */
171 #define MAX_DEVICE_COUNT 4
172
173 /* Default window configuration entry to use (see windows[]) */
174 #define DEFAULT_WINDOW_INDEX 2
175
176 /********************************************************************/
177
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;
187
188 struct window_settings {
189 unsigned char name[64];
190 uint32 mode_backcolor;
191 uint32 mode_colorkey;
192 uint32 mode_colorkeymsk;
193 struct {
194 int xres;
195 int yres;
196 int xpos;
197 int ypos;
198 uint32 mode_winctrl1; /* winctrl1[FRM,CCO,PO,PIPE] */
199 uint32 mode_winenable;
200 } w[4];
201 };
202
203 #if defined(__BIG_ENDIAN)
204 #define LCD_WINCTRL1_PO_16BPP LCD_WINCTRL1_PO_00
205 #else
206 #define LCD_WINCTRL1_PO_16BPP LCD_WINCTRL1_PO_01
207 #endif
208
209 /*
210 * Default window configurations
211 */
212 static struct window_settings windows[] = {
213 { /* Index 0 */
214 "0-FS gfx, 1-video, 2-ovly gfx, 3-ovly gfx",
215 /* mode_backcolor */ 0x006600ff,
216 /* mode_colorkey,msk*/ 0, 0,
217 {
218 {
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,
223 },
224 {
225 /* xres, yres, xpos, ypos */ 100, 100, 100, 100,
226 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
227 LCD_WINCTRL1_PO_16BPP |
228 LCD_WINCTRL1_PIPE,
229 /* mode_winenable*/ LCD_WINENABLE_WEN1,
230 },
231 {
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,
236 },
237 {
238 /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
239 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
240 LCD_WINCTRL1_PO_16BPP |
241 LCD_WINCTRL1_PIPE,
242 /* mode_winenable*/ 0,
243 },
244 },
245 },
246
247 { /* Index 1 */
248 "0-FS gfx, 1-video, 2-ovly gfx, 3-ovly gfx",
249 /* mode_backcolor */ 0x006600ff,
250 /* mode_colorkey,msk*/ 0, 0,
251 {
252 {
253 /* xres, yres, xpos, ypos */ 320, 240, 5, 5,
254 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_24BPP |
255 LCD_WINCTRL1_PO_00,
256 /* mode_winenable*/ LCD_WINENABLE_WEN0,
257 },
258 {
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,
263 },
264 {
265 /* xres, yres, xpos, ypos */ 100, 100, 0, 0,
266 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
267 LCD_WINCTRL1_PO_16BPP |
268 LCD_WINCTRL1_PIPE,
269 /* mode_winenable*/ 0/*LCD_WINENABLE_WEN2*/,
270 },
271 {
272 /* xres, yres, xpos, ypos */ 200, 25, 0, 0,
273 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
274 LCD_WINCTRL1_PO_16BPP |
275 LCD_WINCTRL1_PIPE,
276 /* mode_winenable*/ 0,
277 },
278 },
279 },
280 { /* Index 2 */
281 "0-FS gfx, 1-video, 2-ovly gfx, 3-ovly gfx",
282 /* mode_backcolor */ 0x006600ff,
283 /* mode_colorkey,msk*/ 0, 0,
284 {
285 {
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,
290 },
291 {
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,
296 },
297 {
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*/,
302 },
303 {
304 /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
305 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
306 LCD_WINCTRL1_PO_16BPP |
307 LCD_WINCTRL1_PIPE,
308 /* mode_winenable*/ 0,
309 },
310 },
311 },
312 /* Need VGA 640 @ 24bpp, @ 32bpp */
313 /* Need VGA 800 @ 24bpp, @ 32bpp */
314 /* Need VGA 1024 @ 24bpp, @ 32bpp */
315 };
316
317 /*
318 * Controller configurations for various panels.
319 */
320
321 struct panel_settings
322 {
323 const char name[25]; /* Full name <vendor>_<model> */
324
325 struct fb_monspecs monspecs; /* FB monitor specs */
326
327 /* panel timings */
328 uint32 mode_screen;
329 uint32 mode_horztiming;
330 uint32 mode_verttiming;
331 uint32 mode_clkcontrol;
332 uint32 mode_pwmdiv;
333 uint32 mode_pwmhi;
334 uint32 mode_outmask;
335 uint32 mode_fifoctrl;
336 uint32 mode_backlight;
337 uint32 lcdclk;
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 */
344 };
345
346 /********************************************************************/
347 /* fixme: Maybe a modedb for the CRT ? otherwise panels should be as-is */
348
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:
353 *
354 * STN color panels: max_bpp <= 12
355 * STN mono panels: max_bpp <= 4
356 * TFT panels: max_bpp <= 16
357 * max_xres <= 800
358 * max_yres <= 600
359 */
360 static struct panel_settings known_lcd_panels[] =
361 {
362 [0] = { /* QVGA 320x240 H:33.3kHz V:110Hz */
363 .name = "QVGA_320x240",
364 .monspecs = {
365 .modedb = NULL,
366 .modedb_len = 0,
367 .hfmin = 30000,
368 .hfmax = 70000,
369 .vfmin = 60,
370 .vfmax = 60,
371 .dclkmin = 6000000,
372 .dclkmax = 28000000,
373 .input = FB_DISP_RGB,
374 },
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,
385 .lcdclk = 96,
386 320, 320,
387 240, 240,
388 },
389
390 [1] = { /* VGA 640x480 H:30.3kHz V:58Hz */
391 .name = "VGA_640x480",
392 .monspecs = {
393 .modedb = NULL,
394 .modedb_len = 0,
395 .hfmin = 30000,
396 .hfmax = 70000,
397 .vfmin = 60,
398 .vfmax = 60,
399 .dclkmin = 6000000,
400 .dclkmax = 28000000,
401 .input = FB_DISP_RGB,
402 },
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,
412 .lcdclk = 96,
413 640, 480,
414 640, 480,
415 },
416
417 [2] = { /* SVGA 800x600 H:46.1kHz V:69Hz */
418 .name = "SVGA_800x600",
419 .monspecs = {
420 .modedb = NULL,
421 .modedb_len = 0,
422 .hfmin = 30000,
423 .hfmax = 70000,
424 .vfmin = 60,
425 .vfmax = 60,
426 .dclkmin = 6000000,
427 .dclkmax = 28000000,
428 .input = FB_DISP_RGB,
429 },
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,
439 .lcdclk = 96,
440 800, 800,
441 600, 600,
442 },
443
444 [3] = { /* XVGA 1024x768 H:56.2kHz V:70Hz */
445 .name = "XVGA_1024x768",
446 .monspecs = {
447 .modedb = NULL,
448 .modedb_len = 0,
449 .hfmin = 30000,
450 .hfmax = 70000,
451 .vfmin = 60,
452 .vfmax = 60,
453 .dclkmin = 6000000,
454 .dclkmax = 28000000,
455 .input = FB_DISP_RGB,
456 },
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,
466 .lcdclk = 72,
467 1024, 1024,
468 768, 768,
469 },
470
471 [4] = { /* XVGA XVGA 1280x1024 H:68.5kHz V:65Hz */
472 .name = "XVGA_1280x1024",
473 .monspecs = {
474 .modedb = NULL,
475 .modedb_len = 0,
476 .hfmin = 30000,
477 .hfmax = 70000,
478 .vfmin = 60,
479 .vfmax = 60,
480 .dclkmin = 6000000,
481 .dclkmax = 28000000,
482 .input = FB_DISP_RGB,
483 },
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,
493 .lcdclk = 120,
494 1280, 1280,
495 1024, 1024,
496 },
497
498 [5] = { /* Samsung 1024x768 TFT */
499 .name = "Samsung_1024x768_TFT",
500 .monspecs = {
501 .modedb = NULL,
502 .modedb_len = 0,
503 .hfmin = 30000,
504 .hfmax = 70000,
505 .vfmin = 60,
506 .vfmax = 60,
507 .dclkmin = 6000000,
508 .dclkmax = 28000000,
509 .input = FB_DISP_RGB,
510 },
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,
520 .lcdclk = 96,
521 1024, 1024,
522 768, 768,
523 },
524
525 [6] = { /* Toshiba 640x480 TFT */
526 .name = "Toshiba_640x480_TFT",
527 .monspecs = {
528 .modedb = NULL,
529 .modedb_len = 0,
530 .hfmin = 30000,
531 .hfmax = 70000,
532 .vfmin = 60,
533 .vfmax = 60,
534 .dclkmin = 6000000,
535 .dclkmax = 28000000,
536 .input = FB_DISP_RGB,
537 },
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,
550 .lcdclk = 96,
551 640, 480,
552 640, 480,
553 },
554
555 [7] = { /* Sharp 320x240 TFT */
556 .name = "Sharp_320x240_TFT",
557 .monspecs = {
558 .modedb = NULL,
559 .modedb_len = 0,
560 .hfmin = 12500,
561 .hfmax = 20000,
562 .vfmin = 38,
563 .vfmax = 81,
564 .dclkmin = 4500000,
565 .dclkmax = 6800000,
566 .input = FB_DISP_RGB,
567 },
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 */
581 320, 320,
582 240, 240,
583 },
584
585 [8] = { /* Toppoly TD070WGCB2 7" 856x480 TFT */
586 .name = "Toppoly_TD070WGCB2",
587 .monspecs = {
588 .modedb = NULL,
589 .modedb_len = 0,
590 .hfmin = 30000,
591 .hfmax = 70000,
592 .vfmin = 60,
593 .vfmax = 60,
594 .dclkmin = 6000000,
595 .dclkmax = 28000000,
596 .input = FB_DISP_RGB,
597 },
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,
610 .lcdclk = 96,
611 856, 856,
612 480, 480,
613 },
614 [9] = {
615 .name = "DB1300_800x480",
616 .monspecs = {
617 .modedb = NULL,
618 .modedb_len = 0,
619 .hfmin = 30000,
620 .hfmax = 70000,
621 .vfmin = 60,
622 .vfmax = 60,
623 .dclkmin = 6000000,
624 .dclkmax = 28000000,
625 .input = FB_DISP_RGB,
626 },
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) |
636 LCD_CLKCONTROL_IV |
637 LCD_CLKCONTROL_IH,
638 .mode_pwmdiv = 0x00000000,
639 .mode_pwmhi = 0x00000000,
640 .mode_outmask = 0x00FFFFFF,
641 .mode_fifoctrl = 0x2f2f2f2f,
642 .mode_backlight = 0x00000000,
643 .lcdclk = 96,
644 800, 800,
645 480, 480,
646 },
647 };
648
649 #define NUM_PANELS (ARRAY_SIZE(known_lcd_panels))
650
651 /********************************************************************/
652
winbpp(unsigned int winctrl1)653 static int winbpp (unsigned int winctrl1)
654 {
655 int bits = 0;
656
657 /* how many bits are needed for each pixel format */
658 switch (winctrl1 & LCD_WINCTRL1_FRM) {
659 case LCD_WINCTRL1_FRM_1BPP:
660 bits = 1;
661 break;
662 case LCD_WINCTRL1_FRM_2BPP:
663 bits = 2;
664 break;
665 case LCD_WINCTRL1_FRM_4BPP:
666 bits = 4;
667 break;
668 case LCD_WINCTRL1_FRM_8BPP:
669 bits = 8;
670 break;
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:
679 bits = 16;
680 break;
681 case LCD_WINCTRL1_FRM_24BPP:
682 case LCD_WINCTRL1_FRM_32BPP:
683 bits = 32;
684 break;
685 }
686
687 return bits;
688 }
689
fbinfo2index(struct fb_info * fb_info)690 static int fbinfo2index (struct fb_info *fb_info)
691 {
692 int i;
693
694 for (i = 0; i < device_count; ++i) {
695 if (fb_info == _au1200fb_infos[i])
696 return i;
697 }
698 printk("au1200fb: ERROR: fbinfo2index failed!\n");
699 return -1;
700 }
701
au1200_setlocation(struct au1200fb_device * fbdev,int plane,int xpos,int ypos)702 static int au1200_setlocation (struct au1200fb_device *fbdev, int plane,
703 int xpos, int ypos)
704 {
705 uint32 winctrl0, winctrl1, winenable, fb_offset = 0;
706 int xsz, ysz;
707
708 /* FIX!!! NOT CHECKING FOR COMPLETE OFFSCREEN YET */
709
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);
714
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");*/
722 }
723
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");*/
728 }
729
730 if (xpos < 0) {
731 /* Off-screen to the left */
732 xsz = win->w[plane].xres + xpos;
733 fb_offset += (((0 - xpos) * winbpp(lcd->window[plane].winctrl1))/8);
734 xpos = 0;
735 /*printk("off screen left\n");*/
736 }
737
738 if (ypos < 0) {
739 /* Off-screen to the top */
740 ysz = win->w[plane].yres + ypos;
741 /* fixme: fb_offset += ((0-ypos)*fb_pars[plane].line_length); */
742 ypos = 0;
743 /*printk("off screen top\n");*/
744 }
745
746 /* record settings */
747 win->w[plane].xpos = xpos;
748 win->w[plane].ypos = ypos;
749
750 xsz -= 1;
751 ysz -= 1;
752 winctrl0 |= (xpos << 21);
753 winctrl0 |= (ypos << 10);
754 winctrl1 |= (xsz << 11);
755 winctrl1 |= (ysz << 0);
756
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 */
768
769 return 0;
770 }
771
au1200_setpanel(struct panel_settings * newpanel,struct au1200fb_platdata * pd)772 static void au1200_setpanel(struct panel_settings *newpanel,
773 struct au1200fb_platdata *pd)
774 {
775 /*
776 * Perform global setup/init of LCD controller
777 */
778 uint32 winenable;
779
780 /* Make sure all windows disabled */
781 winenable = lcd->winenable;
782 lcd->winenable = 0;
783 wmb(); /* drain writebuffer */
784 /*
785 * Ensure everything is disabled before reconfiguring
786 */
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)
791 ;
792
793 lcd->screen &= ~LCD_SCREEN_SEN; /*disable the controller*/
794
795 do {
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);
800
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.
805 */
806 if (pd->panel_shutdown)
807 pd->panel_shutdown();
808 }
809
810 /* Newpanel == NULL indicates a shutdown operation only */
811 if (newpanel == NULL)
812 return;
813
814 panel = newpanel;
815
816 printk("Panel(%s), %dx%d\n", panel->name, panel->Xres, panel->Yres);
817
818 /*
819 * Setup clocking if internal LCD clock source (assumes sys_auxpll valid)
820 */
821 if (!(panel->mode_clkcontrol & LCD_CLKCONTROL_EXT))
822 {
823 struct clk *c = clk_get(NULL, "lcd_intclk");
824 long r, pc = panel->lcdclk * 1000000;
825
826 if (!IS_ERR(c)) {
827 r = clk_round_rate(c, pc);
828 if ((pc - r) < (pc / 10)) { /* 10% slack */
829 clk_set_rate(c, r);
830 clk_prepare_enable(c);
831 }
832 clk_put(c);
833 }
834 }
835
836 /*
837 * Configure panel timings
838 */
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 */
848
849 /* fixme: Check window settings to make sure still valid
850 * for new geometry */
851 #if 0
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);
856 #endif
857 lcd->winenable = winenable;
858
859 /*
860 * Re-enable screen now that it is configured
861 */
862 lcd->screen |= LCD_SCREEN_SEN;
863 wmb(); /* drain writebuffer */
864
865 /* Call init of panel */
866 if (pd->panel_init)
867 pd->panel_init();
868
869 /* FIX!!!! not appropriate on panel change!!! Global setup/init */
870 lcd->intenable = 0;
871 lcd->intstatus = ~0;
872 lcd->backcolor = win->mode_backcolor;
873
874 /* Setup Color Key - FIX!!! */
875 lcd->colorkey = win->mode_colorkey;
876 lcd->colorkeymsk = win->mode_colorkeymsk;
877
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;
885
886
887 #if 0
888 #define D(X) printk("%25s: %08X\n", #X, X)
889 D(lcd->screen);
890 D(lcd->horztiming);
891 D(lcd->verttiming);
892 D(lcd->clkcontrol);
893 D(lcd->pwmdiv);
894 D(lcd->pwmhi);
895 D(lcd->outmask);
896 D(lcd->fifoctrl);
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);
921 D(lcd->winenable);
922 D(lcd->intenable);
923 D(lcd->intstatus);
924 D(lcd->backcolor);
925 D(lcd->winenable);
926 D(lcd->colorkey);
927 D(lcd->colorkeymsk);
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);
934 #endif
935 }
936
au1200_setmode(struct au1200fb_device * fbdev)937 static void au1200_setmode(struct au1200fb_device *fbdev)
938 {
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 */
944 ) ;
945
946 au1200_setlocation(fbdev, plane, win->w[plane].xpos, win->w[plane].ypos);
947
948 lcd->window[plane].winctrl2 = ( 0
949 | LCD_WINCTRL2_CKMODE_00
950 | LCD_WINCTRL2_DBM
951 | LCD_WINCTRL2_BX_N(fbdev->fb_info->fix.line_length)
952 | LCD_WINCTRL2_SCX_1
953 | LCD_WINCTRL2_SCY_1
954 ) ;
955 lcd->winenable |= win->w[plane].mode_winenable;
956 wmb(); /* drain writebuffer */
957 }
958
959
960 /* Inline helpers */
961
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)*/
964
965 #define panel_is_color(panel) ((panel->mode_screen & LCD_SCREEN_PT) <= LCD_SCREEN_PT_CDSTN)
966
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 } },
972
973 [LCD_WINCTRL1_FRM_16BPP565 >> 25] =
974 { { 11, 5, 0 }, { 5, 6, 0 }, { 0, 5, 0 }, { 0, 0, 0 } },
975
976 [LCD_WINCTRL1_FRM_16BPP556 >> 25] =
977 { { 11, 5, 0 }, { 6, 5, 0 }, { 0, 6, 0 }, { 0, 0, 0 } },
978
979 [LCD_WINCTRL1_FRM_16BPPI1555 >> 25] =
980 { { 10, 5, 0 }, { 5, 5, 0 }, { 0, 5, 0 }, { 0, 0, 0 } },
981
982 [LCD_WINCTRL1_FRM_16BPPI5551 >> 25] =
983 { { 11, 5, 0 }, { 6, 5, 0 }, { 1, 5, 0 }, { 0, 0, 0 } },
984
985 [LCD_WINCTRL1_FRM_16BPPA1555 >> 25] =
986 { { 10, 5, 0 }, { 5, 5, 0 }, { 0, 5, 0 }, { 15, 1, 0 } },
987
988 [LCD_WINCTRL1_FRM_16BPPA5551 >> 25] =
989 { { 11, 5, 0 }, { 6, 5, 0 }, { 1, 5, 0 }, { 0, 1, 0 } },
990
991 [LCD_WINCTRL1_FRM_24BPP >> 25] =
992 { { 16, 8, 0 }, { 8, 8, 0 }, { 0, 8, 0 }, { 0, 0, 0 } },
993
994 [LCD_WINCTRL1_FRM_32BPP >> 25] =
995 { { 16, 8, 0 }, { 8, 8, 0 }, { 0, 8, 0 }, { 24, 0, 0 } },
996 };
997
998 /*-------------------------------------------------------------------------*/
999
1000 /* Helpers */
1001
au1200fb_update_fbinfo(struct fb_info * fbi)1002 static void au1200fb_update_fbinfo(struct fb_info *fbi)
1003 {
1004 /* FIX!!!! This also needs to take the window pixel format into account!!! */
1005
1006 /* Update var-dependent FB info */
1007 if (panel_is_color(panel)) {
1008 if (fbi->var.bits_per_pixel <= 8) {
1009 /* palettized */
1010 fbi->fix.visual = FB_VISUAL_PSEUDOCOLOR;
1011 fbi->fix.line_length = fbi->var.xres_virtual /
1012 (8/fbi->var.bits_per_pixel);
1013 } else {
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);
1017 }
1018 } else {
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;
1022 }
1023
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);
1027 }
1028
1029 /*-------------------------------------------------------------------------*/
1030
1031 /* AU1200 framebuffer driver */
1032
1033 /* fb_check_var
1034 * Validate var settings with hardware restrictions and modify it if necessary
1035 */
au1200fb_fb_check_var(struct fb_var_screeninfo * var,struct fb_info * fbi)1036 static int au1200fb_fb_check_var(struct fb_var_screeninfo *var,
1037 struct fb_info *fbi)
1038 {
1039 struct au1200fb_device *fbdev = fbi->par;
1040 u32 pixclock;
1041 int screen_size, plane;
1042
1043 if (!var->pixclock)
1044 return -EINVAL;
1045
1046 plane = fbdev->plane;
1047
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;
1052
1053 /* No need for virtual resolution support */
1054 var->xres_virtual = var->xres;
1055 var->yres_virtual = var->yres;
1056
1057 var->bits_per_pixel = winbpp(win->w[plane].mode_winctrl1);
1058
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);
1062
1063 if (fbdev->fb_len < screen_size)
1064 return -EINVAL; /* Virtual screen is to big, abort */
1065
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);
1072
1073 if (AU1200_LCD_MAX_CLK % pixclock) {
1074 int diff = AU1200_LCD_MAX_CLK % pixclock;
1075 pixclock -= diff;
1076 }
1077
1078 var->pixclock = KHZ2PICOS(pixclock/1000);
1079 #if 0
1080 if (!panel_is_active(panel)) {
1081 int pcd = AU1200_LCD_MAX_CLK / (pixclock * 2) - 1;
1082
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);
1087 } else if (!pcd) {
1088 /* Other STN panel support is up to 12MHz */
1089 var->pixclock = KHZ2PICOS(12000);
1090 }
1091 }
1092 #endif
1093 /* Set bitfield accordingly */
1094 switch (var->bits_per_pixel) {
1095 case 16:
1096 {
1097 /* 16bpp True color.
1098 * These must be set to MATCH WINCTRL[FORM] */
1099 int idx;
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];
1105 break;
1106 }
1107
1108 case 32:
1109 {
1110 /* 32bpp True color.
1111 * These must be set to MATCH WINCTRL[FORM] */
1112 int idx;
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];
1118 break;
1119 }
1120 default:
1121 print_dbg("Unsupported depth %dbpp", var->bits_per_pixel);
1122 return -EINVAL;
1123 }
1124
1125 return 0;
1126 }
1127
1128 /* fb_set_par
1129 * Set hardware with var settings. This will enable the controller with a
1130 * specific mode, normally validated with the fb_check_var method
1131 */
au1200fb_fb_set_par(struct fb_info * fbi)1132 static int au1200fb_fb_set_par(struct fb_info *fbi)
1133 {
1134 struct au1200fb_device *fbdev = fbi->par;
1135
1136 au1200fb_update_fbinfo(fbi);
1137 au1200_setmode(fbdev);
1138
1139 return 0;
1140 }
1141
1142 /* fb_setcolreg
1143 * Set color in LCD palette.
1144 */
au1200fb_fb_setcolreg(unsigned regno,unsigned red,unsigned green,unsigned blue,unsigned transp,struct fb_info * fbi)1145 static int au1200fb_fb_setcolreg(unsigned regno, unsigned red, unsigned green,
1146 unsigned blue, unsigned transp, struct fb_info *fbi)
1147 {
1148 volatile u32 *palette = lcd->palette;
1149 u32 value;
1150
1151 if (regno > (AU1200_LCD_NBR_PALETTE_ENTRIES - 1))
1152 return -EINVAL;
1153
1154 if (fbi->var.grayscale) {
1155 /* Convert color to grayscale */
1156 red = green = blue =
1157 (19595 * red + 38470 * green + 7471 * blue) >> 16;
1158 }
1159
1160 if (fbi->fix.visual == FB_VISUAL_TRUECOLOR) {
1161 /* Place color in the pseudopalette */
1162 if (regno > 16)
1163 return -EINVAL;
1164
1165 palette = (u32*) fbi->pseudo_palette;
1166
1167 red >>= (16 - fbi->var.red.length);
1168 green >>= (16 - fbi->var.green.length);
1169 blue >>= (16 - fbi->var.blue.length);
1170
1171 value = (red << fbi->var.red.offset) |
1172 (green << fbi->var.green.offset)|
1173 (blue << fbi->var.blue.offset);
1174 value &= 0xFFFF;
1175
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);
1180 value &= 0xFFFF;
1181
1182 } else if (0 /*panel_is_color(fbdev->panel)*/) {
1183 /* COLOR STN MODE */
1184 value = 0x1234;
1185 value &= 0xFFF;
1186 } else {
1187 /* MONOCHROME MODE */
1188 value = (green >> 12) & 0x000F;
1189 value &= 0xF;
1190 }
1191
1192 palette[regno] = value;
1193
1194 return 0;
1195 }
1196
1197 /* fb_blank
1198 * Blank the screen. Depending on the mode, the screen will be
1199 * activated with the backlight color, or desactivated
1200 */
au1200fb_fb_blank(int blank_mode,struct fb_info * fbi)1201 static int au1200fb_fb_blank(int blank_mode, struct fb_info *fbi)
1202 {
1203 struct au1200fb_device *fbdev = fbi->par;
1204
1205 /* Short-circuit screen blanking */
1206 if (noblanking)
1207 return 0;
1208
1209 switch (blank_mode) {
1210
1211 case FB_BLANK_UNBLANK:
1212 case FB_BLANK_NORMAL:
1213 /* printk("turn on panel\n"); */
1214 au1200_setpanel(panel, fbdev->pd);
1215 break;
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);
1221 break;
1222 default:
1223 break;
1224
1225 }
1226
1227 /* FB_BLANK_NORMAL is a soft blank */
1228 return (blank_mode == FB_BLANK_NORMAL) ? -EINVAL : 0;
1229 }
1230
1231 /* fb_mmap
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)
1234 */
au1200fb_fb_mmap(struct fb_info * info,struct vm_area_struct * vma)1235 static int au1200fb_fb_mmap(struct fb_info *info, struct vm_area_struct *vma)
1236 {
1237 struct au1200fb_device *fbdev = info->par;
1238
1239 vma->vm_page_prot = pgprot_decrypted(vma->vm_page_prot);
1240
1241 return dma_mmap_coherent(fbdev->dev, vma,
1242 fbdev->fb_mem, fbdev->fb_phys, fbdev->fb_len);
1243 }
1244
set_global(u_int cmd,struct au1200_lcd_global_regs_t * pdata)1245 static void set_global(u_int cmd, struct au1200_lcd_global_regs_t *pdata)
1246 {
1247
1248 unsigned int hi1, divider;
1249
1250 /* SCREEN_SIZE: user cannot reset size, must switch panel choice */
1251
1252 if (pdata->flags & SCREEN_BACKCOLOR)
1253 lcd->backcolor = pdata->backcolor;
1254
1255 if (pdata->flags & SCREEN_BRIGHTNESS) {
1256
1257 // limit brightness pwm duty to >= 30/1600
1258 if (pdata->brightness < 30) {
1259 pdata->brightness = 30;
1260 }
1261 divider = (lcd->pwmdiv & 0x3FFFF) + 1;
1262 hi1 = (((pdata->brightness & 0xFF)+1) * divider >> 8);
1263 lcd->pwmhi &= 0xFFFF;
1264 lcd->pwmhi |= (hi1 << 16);
1265 }
1266
1267 if (pdata->flags & SCREEN_COLORKEY)
1268 lcd->colorkey = pdata->colorkey;
1269
1270 if (pdata->flags & SCREEN_MASK)
1271 lcd->colorkeymsk = pdata->mask;
1272 wmb(); /* drain writebuffer */
1273 }
1274
get_global(u_int cmd,struct au1200_lcd_global_regs_t * pdata)1275 static void get_global(u_int cmd, struct au1200_lcd_global_regs_t *pdata)
1276 {
1277 unsigned int hi1, divider;
1278
1279 pdata->xsize = ((lcd->screen & LCD_SCREEN_SX) >> 19) + 1;
1280 pdata->ysize = ((lcd->screen & LCD_SCREEN_SY) >> 8) + 1;
1281
1282 pdata->backcolor = lcd->backcolor;
1283 pdata->colorkey = lcd->colorkey;
1284 pdata->mask = lcd->colorkeymsk;
1285
1286 // brightness
1287 hi1 = (lcd->pwmhi >> 16) + 1;
1288 divider = (lcd->pwmdiv & 0x3FFFF) + 1;
1289 pdata->brightness = ((hi1 << 8) / divider) - 1;
1290 wmb(); /* drain writebuffer */
1291 }
1292
set_window(unsigned int plane,struct au1200_lcd_window_regs_t * pdata)1293 static void set_window(unsigned int plane,
1294 struct au1200_lcd_window_regs_t *pdata)
1295 {
1296 unsigned int val, bpp;
1297
1298 /* Window control register 0 */
1299 if (pdata->flags & WIN_POSITION) {
1300 val = lcd->window[plane].winctrl0 & ~(LCD_WINCTRL0_OX |
1301 LCD_WINCTRL0_OY);
1302 val |= ((pdata->xpos << 21) & LCD_WINCTRL0_OX);
1303 val |= ((pdata->ypos << 10) & LCD_WINCTRL0_OY);
1304 lcd->window[plane].winctrl0 = val;
1305 }
1306 if (pdata->flags & WIN_ALPHA_COLOR) {
1307 val = lcd->window[plane].winctrl0 & ~(LCD_WINCTRL0_A);
1308 val |= ((pdata->alpha_color << 2) & LCD_WINCTRL0_A);
1309 lcd->window[plane].winctrl0 = val;
1310 }
1311 if (pdata->flags & WIN_ALPHA_MODE) {
1312 val = lcd->window[plane].winctrl0 & ~(LCD_WINCTRL0_AEN);
1313 val |= ((pdata->alpha_mode << 1) & LCD_WINCTRL0_AEN);
1314 lcd->window[plane].winctrl0 = val;
1315 }
1316
1317 /* Window control register 1 */
1318 if (pdata->flags & WIN_PRIORITY) {
1319 val = lcd->window[plane].winctrl1 & ~(LCD_WINCTRL1_PRI);
1320 val |= ((pdata->priority << 30) & LCD_WINCTRL1_PRI);
1321 lcd->window[plane].winctrl1 = val;
1322 }
1323 if (pdata->flags & WIN_CHANNEL) {
1324 val = lcd->window[plane].winctrl1 & ~(LCD_WINCTRL1_PIPE);
1325 val |= ((pdata->channel << 29) & LCD_WINCTRL1_PIPE);
1326 lcd->window[plane].winctrl1 = val;
1327 }
1328 if (pdata->flags & WIN_BUFFER_FORMAT) {
1329 val = lcd->window[plane].winctrl1 & ~(LCD_WINCTRL1_FRM);
1330 val |= ((pdata->buffer_format << 25) & LCD_WINCTRL1_FRM);
1331 lcd->window[plane].winctrl1 = val;
1332 }
1333 if (pdata->flags & WIN_COLOR_ORDER) {
1334 val = lcd->window[plane].winctrl1 & ~(LCD_WINCTRL1_CCO);
1335 val |= ((pdata->color_order << 24) & LCD_WINCTRL1_CCO);
1336 lcd->window[plane].winctrl1 = val;
1337 }
1338 if (pdata->flags & WIN_PIXEL_ORDER) {
1339 val = lcd->window[plane].winctrl1 & ~(LCD_WINCTRL1_PO);
1340 val |= ((pdata->pixel_order << 22) & LCD_WINCTRL1_PO);
1341 lcd->window[plane].winctrl1 = val;
1342 }
1343 if (pdata->flags & WIN_SIZE) {
1344 val = lcd->window[plane].winctrl1 & ~(LCD_WINCTRL1_SZX |
1345 LCD_WINCTRL1_SZY);
1346 val |= (((pdata->xsize << 11) - 1) & LCD_WINCTRL1_SZX);
1347 val |= (((pdata->ysize) - 1) & LCD_WINCTRL1_SZY);
1348 lcd->window[plane].winctrl1 = val;
1349 /* program buffer line width */
1350 bpp = winbpp(val) / 8;
1351 val = lcd->window[plane].winctrl2 & ~(LCD_WINCTRL2_BX);
1352 val |= (((pdata->xsize * bpp) << 8) & LCD_WINCTRL2_BX);
1353 lcd->window[plane].winctrl2 = val;
1354 }
1355
1356 /* Window control register 2 */
1357 if (pdata->flags & WIN_COLORKEY_MODE) {
1358 val = lcd->window[plane].winctrl2 & ~(LCD_WINCTRL2_CKMODE);
1359 val |= ((pdata->colorkey_mode << 24) & LCD_WINCTRL2_CKMODE);
1360 lcd->window[plane].winctrl2 = val;
1361 }
1362 if (pdata->flags & WIN_DOUBLE_BUFFER_MODE) {
1363 val = lcd->window[plane].winctrl2 & ~(LCD_WINCTRL2_DBM);
1364 val |= ((pdata->double_buffer_mode << 23) & LCD_WINCTRL2_DBM);
1365 lcd->window[plane].winctrl2 = val;
1366 }
1367 if (pdata->flags & WIN_RAM_ARRAY_MODE) {
1368 val = lcd->window[plane].winctrl2 & ~(LCD_WINCTRL2_RAM);
1369 val |= ((pdata->ram_array_mode << 21) & LCD_WINCTRL2_RAM);
1370 lcd->window[plane].winctrl2 = val;
1371 }
1372
1373 /* Buffer line width programmed with WIN_SIZE */
1374
1375 if (pdata->flags & WIN_BUFFER_SCALE) {
1376 val = lcd->window[plane].winctrl2 & ~(LCD_WINCTRL2_SCX |
1377 LCD_WINCTRL2_SCY);
1378 val |= ((pdata->xsize << 11) & LCD_WINCTRL2_SCX);
1379 val |= ((pdata->ysize) & LCD_WINCTRL2_SCY);
1380 lcd->window[plane].winctrl2 = val;
1381 }
1382
1383 if (pdata->flags & WIN_ENABLE) {
1384 val = lcd->winenable;
1385 val &= ~(1<<plane);
1386 val |= (pdata->enable & 1) << plane;
1387 lcd->winenable = val;
1388 }
1389 wmb(); /* drain writebuffer */
1390 }
1391
get_window(unsigned int plane,struct au1200_lcd_window_regs_t * pdata)1392 static void get_window(unsigned int plane,
1393 struct au1200_lcd_window_regs_t *pdata)
1394 {
1395 /* Window control register 0 */
1396 pdata->xpos = (lcd->window[plane].winctrl0 & LCD_WINCTRL0_OX) >> 21;
1397 pdata->ypos = (lcd->window[plane].winctrl0 & LCD_WINCTRL0_OY) >> 10;
1398 pdata->alpha_color = (lcd->window[plane].winctrl0 & LCD_WINCTRL0_A) >> 2;
1399 pdata->alpha_mode = (lcd->window[plane].winctrl0 & LCD_WINCTRL0_AEN) >> 1;
1400
1401 /* Window control register 1 */
1402 pdata->priority = (lcd->window[plane].winctrl1& LCD_WINCTRL1_PRI) >> 30;
1403 pdata->channel = (lcd->window[plane].winctrl1 & LCD_WINCTRL1_PIPE) >> 29;
1404 pdata->buffer_format = (lcd->window[plane].winctrl1 & LCD_WINCTRL1_FRM) >> 25;
1405 pdata->color_order = (lcd->window[plane].winctrl1 & LCD_WINCTRL1_CCO) >> 24;
1406 pdata->pixel_order = (lcd->window[plane].winctrl1 & LCD_WINCTRL1_PO) >> 22;
1407 pdata->xsize = ((lcd->window[plane].winctrl1 & LCD_WINCTRL1_SZX) >> 11) + 1;
1408 pdata->ysize = (lcd->window[plane].winctrl1 & LCD_WINCTRL1_SZY) + 1;
1409
1410 /* Window control register 2 */
1411 pdata->colorkey_mode = (lcd->window[plane].winctrl2 & LCD_WINCTRL2_CKMODE) >> 24;
1412 pdata->double_buffer_mode = (lcd->window[plane].winctrl2 & LCD_WINCTRL2_DBM) >> 23;
1413 pdata->ram_array_mode = (lcd->window[plane].winctrl2 & LCD_WINCTRL2_RAM) >> 21;
1414
1415 pdata->enable = (lcd->winenable >> plane) & 1;
1416 wmb(); /* drain writebuffer */
1417 }
1418
au1200fb_ioctl(struct fb_info * info,unsigned int cmd,unsigned long arg)1419 static int au1200fb_ioctl(struct fb_info *info, unsigned int cmd,
1420 unsigned long arg)
1421 {
1422 struct au1200fb_device *fbdev = info->par;
1423 int plane;
1424 int val;
1425
1426 plane = fbinfo2index(info);
1427 print_dbg("au1200fb: ioctl %d on plane %d\n", cmd, plane);
1428
1429 if (cmd == AU1200_LCD_FB_IOCTL) {
1430 struct au1200_lcd_iodata_t iodata;
1431
1432 if (copy_from_user(&iodata, (void __user *) arg, sizeof(iodata)))
1433 return -EFAULT;
1434
1435 print_dbg("FB IOCTL called\n");
1436
1437 switch (iodata.subcmd) {
1438 case AU1200_LCD_SET_SCREEN:
1439 print_dbg("AU1200_LCD_SET_SCREEN\n");
1440 set_global(cmd, &iodata.global);
1441 break;
1442
1443 case AU1200_LCD_GET_SCREEN:
1444 print_dbg("AU1200_LCD_GET_SCREEN\n");
1445 get_global(cmd, &iodata.global);
1446 break;
1447
1448 case AU1200_LCD_SET_WINDOW:
1449 print_dbg("AU1200_LCD_SET_WINDOW\n");
1450 set_window(plane, &iodata.window);
1451 break;
1452
1453 case AU1200_LCD_GET_WINDOW:
1454 print_dbg("AU1200_LCD_GET_WINDOW\n");
1455 get_window(plane, &iodata.window);
1456 break;
1457
1458 case AU1200_LCD_SET_PANEL:
1459 print_dbg("AU1200_LCD_SET_PANEL\n");
1460 if ((iodata.global.panel_choice >= 0) &&
1461 (iodata.global.panel_choice <
1462 NUM_PANELS))
1463 {
1464 struct panel_settings *newpanel;
1465 panel_index = iodata.global.panel_choice;
1466 newpanel = &known_lcd_panels[panel_index];
1467 au1200_setpanel(newpanel, fbdev->pd);
1468 }
1469 break;
1470
1471 case AU1200_LCD_GET_PANEL:
1472 print_dbg("AU1200_LCD_GET_PANEL\n");
1473 iodata.global.panel_choice = panel_index;
1474 break;
1475
1476 default:
1477 return -EINVAL;
1478 }
1479
1480 val = copy_to_user((void __user *) arg, &iodata, sizeof(iodata));
1481 if (val) {
1482 print_dbg("error: could not copy %d bytes\n", val);
1483 return -EFAULT;
1484 }
1485 }
1486
1487 return 0;
1488 }
1489
1490
1491 static const struct fb_ops au1200fb_fb_ops = {
1492 .owner = THIS_MODULE,
1493 __FB_DEFAULT_DMAMEM_OPS_RDWR,
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_DEFAULT_DMAMEM_OPS_DRAW,
1499 .fb_sync = NULL,
1500 .fb_ioctl = au1200fb_ioctl,
1501 .fb_mmap = au1200fb_fb_mmap,
1502 };
1503
1504 /*-------------------------------------------------------------------------*/
1505
au1200fb_handle_irq(int irq,void * dev_id)1506 static irqreturn_t au1200fb_handle_irq(int irq, void* dev_id)
1507 {
1508 /* Nothing to do for now, just clear any pending interrupt */
1509 lcd->intstatus = lcd->intstatus;
1510 wmb(); /* drain writebuffer */
1511
1512 return IRQ_HANDLED;
1513 }
1514
1515 /*-------------------------------------------------------------------------*/
1516
1517 /* AU1200 LCD device probe helpers */
1518
au1200fb_init_fbinfo(struct au1200fb_device * fbdev)1519 static int au1200fb_init_fbinfo(struct au1200fb_device *fbdev)
1520 {
1521 struct fb_info *fbi = fbdev->fb_info;
1522 int bpp, ret;
1523
1524 fbi->fbops = &au1200fb_fb_ops;
1525
1526 bpp = winbpp(win->w[fbdev->plane].mode_winctrl1);
1527
1528 /* Copy monitor specs from panel data */
1529 /* fixme: we're setting up LCD controller windows, so these dont give a
1530 damn as to what the monitor specs are (the panel itself does, but that
1531 isn't done here...so maybe need a generic catchall monitor setting??? */
1532 memcpy(&fbi->monspecs, &panel->monspecs, sizeof(struct fb_monspecs));
1533
1534 /* We first try the user mode passed in argument. If that failed,
1535 * or if no one has been specified, we default to the first mode of the
1536 * panel list. Note that after this call, var data will be set */
1537 if (!fb_find_mode(&fbi->var,
1538 fbi,
1539 NULL, /* drv_info.opt_mode, */
1540 fbi->monspecs.modedb,
1541 fbi->monspecs.modedb_len,
1542 fbi->monspecs.modedb,
1543 bpp)) {
1544
1545 print_err("Cannot find valid mode for panel %s", panel->name);
1546 return -EFAULT;
1547 }
1548
1549 fbi->pseudo_palette = kcalloc(16, sizeof(u32), GFP_KERNEL);
1550 if (!fbi->pseudo_palette)
1551 return -ENOMEM;
1552
1553 ret = fb_alloc_cmap(&fbi->cmap, AU1200_LCD_NBR_PALETTE_ENTRIES, 0);
1554 if (ret < 0) {
1555 print_err("Fail to allocate colormap (%d entries)",
1556 AU1200_LCD_NBR_PALETTE_ENTRIES);
1557 return ret;
1558 }
1559
1560 strscpy(fbi->fix.id, "AU1200");
1561 fbi->fix.smem_start = fbdev->fb_phys;
1562 fbi->fix.smem_len = fbdev->fb_len;
1563 fbi->fix.type = FB_TYPE_PACKED_PIXELS;
1564 fbi->fix.xpanstep = 0;
1565 fbi->fix.ypanstep = 0;
1566 fbi->fix.mmio_start = 0;
1567 fbi->fix.mmio_len = 0;
1568 fbi->fix.accel = FB_ACCEL_NONE;
1569
1570 fbi->flags |= FBINFO_VIRTFB;
1571
1572 fbi->screen_buffer = fbdev->fb_mem;
1573
1574 au1200fb_update_fbinfo(fbi);
1575
1576 return 0;
1577 }
1578
1579 /*-------------------------------------------------------------------------*/
1580
1581
au1200fb_setup(struct au1200fb_platdata * pd)1582 static int au1200fb_setup(struct au1200fb_platdata *pd)
1583 {
1584 char *options = NULL;
1585 char *this_opt, *endptr;
1586 int num_panels = ARRAY_SIZE(known_lcd_panels);
1587 int panel_idx = -1;
1588
1589 fb_get_options(DRIVER_NAME, &options);
1590
1591 if (!options)
1592 goto out;
1593
1594 while ((this_opt = strsep(&options, ",")) != NULL) {
1595 /* Panel option - can be panel name,
1596 * "bs" for board-switch, or number/index */
1597 if (!strncmp(this_opt, "panel:", 6)) {
1598 int i;
1599 long int li;
1600 char *endptr;
1601 this_opt += 6;
1602 /* First check for index, which allows
1603 * to short circuit this mess */
1604 li = simple_strtol(this_opt, &endptr, 0);
1605 if (*endptr == '\0')
1606 panel_idx = (int)li;
1607 else if (strcmp(this_opt, "bs") == 0)
1608 panel_idx = pd->panel_index();
1609 else {
1610 for (i = 0; i < num_panels; i++) {
1611 if (!strcmp(this_opt,
1612 known_lcd_panels[i].name)) {
1613 panel_idx = i;
1614 break;
1615 }
1616 }
1617 }
1618 if ((panel_idx < 0) || (panel_idx >= num_panels))
1619 print_warn("Panel %s not supported!", this_opt);
1620 else
1621 panel_index = panel_idx;
1622
1623 } else if (strncmp(this_opt, "nohwcursor", 10) == 0)
1624 nohwcursor = 1;
1625 else if (strncmp(this_opt, "devices:", 8) == 0) {
1626 this_opt += 8;
1627 device_count = simple_strtol(this_opt, &endptr, 0);
1628 if ((device_count < 0) ||
1629 (device_count > MAX_DEVICE_COUNT))
1630 device_count = MAX_DEVICE_COUNT;
1631 } else if (strncmp(this_opt, "wincfg:", 7) == 0) {
1632 this_opt += 7;
1633 window_index = simple_strtol(this_opt, &endptr, 0);
1634 if ((window_index < 0) ||
1635 (window_index >= ARRAY_SIZE(windows)))
1636 window_index = DEFAULT_WINDOW_INDEX;
1637 } else if (strncmp(this_opt, "off", 3) == 0)
1638 return 1;
1639 else
1640 print_warn("Unsupported option \"%s\"", this_opt);
1641 }
1642
1643 out:
1644 return 0;
1645 }
1646
1647 /* AU1200 LCD controller device driver */
au1200fb_drv_probe(struct platform_device * dev)1648 static int au1200fb_drv_probe(struct platform_device *dev)
1649 {
1650 struct au1200fb_device *fbdev;
1651 struct au1200fb_platdata *pd;
1652 struct fb_info *fbi = NULL;
1653 int bpp, plane, ret, irq;
1654
1655 print_info("" DRIVER_DESC "");
1656
1657 pd = dev->dev.platform_data;
1658 if (!pd)
1659 return -ENODEV;
1660
1661 /* Setup driver with options */
1662 if (au1200fb_setup(pd))
1663 return -ENODEV;
1664
1665 /* Point to the panel selected */
1666 panel = &known_lcd_panels[panel_index];
1667 win = &windows[window_index];
1668
1669 printk(DRIVER_NAME ": Panel %d %s\n", panel_index, panel->name);
1670 printk(DRIVER_NAME ": Win %d %s\n", window_index, win->name);
1671
1672 for (plane = 0; plane < device_count; ++plane) {
1673 bpp = winbpp(win->w[plane].mode_winctrl1);
1674 if (win->w[plane].xres == 0)
1675 win->w[plane].xres = panel->Xres;
1676 if (win->w[plane].yres == 0)
1677 win->w[plane].yres = panel->Yres;
1678
1679 fbi = framebuffer_alloc(sizeof(struct au1200fb_device),
1680 &dev->dev);
1681 if (!fbi) {
1682 ret = -ENOMEM;
1683 goto failed;
1684 }
1685
1686 _au1200fb_infos[plane] = fbi;
1687 fbdev = fbi->par;
1688 fbdev->fb_info = fbi;
1689 fbdev->pd = pd;
1690 fbdev->dev = &dev->dev;
1691
1692 fbdev->plane = plane;
1693
1694 /* Allocate the framebuffer to the maximum screen size */
1695 fbdev->fb_len = (win->w[plane].xres * win->w[plane].yres * bpp) / 8;
1696
1697 fbdev->fb_mem = dmam_alloc_attrs(&dev->dev,
1698 PAGE_ALIGN(fbdev->fb_len),
1699 &fbdev->fb_phys, GFP_KERNEL, 0);
1700 if (!fbdev->fb_mem) {
1701 print_err("fail to allocate framebuffer (size: %dK))",
1702 fbdev->fb_len / 1024);
1703 ret = -ENOMEM;
1704 goto failed;
1705 }
1706
1707 print_dbg("Framebuffer memory map at %p", fbdev->fb_mem);
1708 print_dbg("phys=0x%08x, size=%dK", fbdev->fb_phys, fbdev->fb_len / 1024);
1709
1710 /* Init FB data */
1711 ret = au1200fb_init_fbinfo(fbdev);
1712 if (ret < 0)
1713 goto failed;
1714
1715 /* Register new framebuffer */
1716 ret = register_framebuffer(fbi);
1717 if (ret < 0) {
1718 print_err("cannot register new framebuffer");
1719 goto failed;
1720 }
1721
1722 au1200fb_fb_set_par(fbi);
1723 }
1724
1725 /* Now hook interrupt too */
1726 irq = platform_get_irq(dev, 0);
1727 if (irq < 0)
1728 return irq;
1729
1730 ret = request_irq(irq, au1200fb_handle_irq,
1731 IRQF_SHARED, "lcd", (void *)dev);
1732 if (ret) {
1733 print_err("fail to request interrupt line %d (err: %d)",
1734 irq, ret);
1735 goto failed;
1736 }
1737
1738 platform_set_drvdata(dev, pd);
1739
1740 /* Kickstart the panel */
1741 au1200_setpanel(panel, pd);
1742
1743 return 0;
1744
1745 failed:
1746 for (plane = 0; plane < device_count; ++plane) {
1747 fbi = _au1200fb_infos[plane];
1748 if (!fbi)
1749 break;
1750
1751 /* Clean up all probe data */
1752 unregister_framebuffer(fbi);
1753 if (fbi->cmap.len != 0)
1754 fb_dealloc_cmap(&fbi->cmap);
1755 kfree(fbi->pseudo_palette);
1756
1757 framebuffer_release(fbi);
1758 _au1200fb_infos[plane] = NULL;
1759 }
1760 return ret;
1761 }
1762
au1200fb_drv_remove(struct platform_device * dev)1763 static void au1200fb_drv_remove(struct platform_device *dev)
1764 {
1765 struct au1200fb_platdata *pd = platform_get_drvdata(dev);
1766 struct fb_info *fbi;
1767 int plane;
1768
1769 /* Turn off the panel */
1770 au1200_setpanel(NULL, pd);
1771
1772 for (plane = 0; plane < device_count; ++plane) {
1773 fbi = _au1200fb_infos[plane];
1774
1775 /* Clean up all probe data */
1776 unregister_framebuffer(fbi);
1777 if (fbi->cmap.len != 0)
1778 fb_dealloc_cmap(&fbi->cmap);
1779 kfree(fbi->pseudo_palette);
1780
1781 framebuffer_release(fbi);
1782 _au1200fb_infos[plane] = NULL;
1783 }
1784
1785 free_irq(platform_get_irq(dev, 0), (void *)dev);
1786 }
1787
1788 #ifdef CONFIG_PM
au1200fb_drv_suspend(struct device * dev)1789 static int au1200fb_drv_suspend(struct device *dev)
1790 {
1791 struct au1200fb_platdata *pd = dev_get_drvdata(dev);
1792 au1200_setpanel(NULL, pd);
1793
1794 lcd->outmask = 0;
1795 wmb(); /* drain writebuffer */
1796
1797 return 0;
1798 }
1799
au1200fb_drv_resume(struct device * dev)1800 static int au1200fb_drv_resume(struct device *dev)
1801 {
1802 struct au1200fb_platdata *pd = dev_get_drvdata(dev);
1803 struct fb_info *fbi;
1804 int i;
1805
1806 /* Kickstart the panel */
1807 au1200_setpanel(panel, pd);
1808
1809 for (i = 0; i < device_count; i++) {
1810 fbi = _au1200fb_infos[i];
1811 au1200fb_fb_set_par(fbi);
1812 }
1813
1814 return 0;
1815 }
1816
1817 static const struct dev_pm_ops au1200fb_pmops = {
1818 .suspend = au1200fb_drv_suspend,
1819 .resume = au1200fb_drv_resume,
1820 .freeze = au1200fb_drv_suspend,
1821 .thaw = au1200fb_drv_resume,
1822 };
1823
1824 #define AU1200FB_PMOPS (&au1200fb_pmops)
1825
1826 #else
1827 #define AU1200FB_PMOPS NULL
1828 #endif /* CONFIG_PM */
1829
1830 static struct platform_driver au1200fb_driver = {
1831 .driver = {
1832 .name = "au1200-lcd",
1833 .pm = AU1200FB_PMOPS,
1834 },
1835 .probe = au1200fb_drv_probe,
1836 .remove = au1200fb_drv_remove,
1837 };
1838 module_platform_driver(au1200fb_driver);
1839
1840 MODULE_DESCRIPTION(DRIVER_DESC);
1841 MODULE_LICENSE("GPL");
1842