Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
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
47#include <asm/mach-au1x00/au1000.h>
48#include <asm/mach-au1x00/au1200fb.h> /* platform_data */
49#include "au1200fb.h"
50
51#define DRIVER_NAME "au1200fb"
52#define DRIVER_DESC "LCD controller driver for AU1200 processors"
53
54#define DEBUG 0
55
56#define print_err(f, arg...) printk(KERN_ERR DRIVER_NAME ": " f "\n", ## arg)
57#define print_warn(f, arg...) printk(KERN_WARNING DRIVER_NAME ": " f "\n", ## arg)
58#define print_info(f, arg...) printk(KERN_INFO DRIVER_NAME ": " f "\n", ## arg)
59
60#if DEBUG
61#define print_dbg(f, arg...) printk(KERN_DEBUG __FILE__ ": " f "\n", ## arg)
62#else
63#define print_dbg(f, arg...) do {} while (0)
64#endif
65
66
67#define AU1200_LCD_FB_IOCTL 0x46FF
68
69#define AU1200_LCD_SET_SCREEN 1
70#define AU1200_LCD_GET_SCREEN 2
71#define AU1200_LCD_SET_WINDOW 3
72#define AU1200_LCD_GET_WINDOW 4
73#define AU1200_LCD_SET_PANEL 5
74#define AU1200_LCD_GET_PANEL 6
75
76#define SCREEN_SIZE (1<< 1)
77#define SCREEN_BACKCOLOR (1<< 2)
78#define SCREEN_BRIGHTNESS (1<< 3)
79#define SCREEN_COLORKEY (1<< 4)
80#define SCREEN_MASK (1<< 5)
81
82struct au1200_lcd_global_regs_t {
83 unsigned int flags;
84 unsigned int xsize;
85 unsigned int ysize;
86 unsigned int backcolor;
87 unsigned int brightness;
88 unsigned int colorkey;
89 unsigned int mask;
90 unsigned int panel_choice;
91 char panel_desc[80];
92
93};
94
95#define WIN_POSITION (1<< 0)
96#define WIN_ALPHA_COLOR (1<< 1)
97#define WIN_ALPHA_MODE (1<< 2)
98#define WIN_PRIORITY (1<< 3)
99#define WIN_CHANNEL (1<< 4)
100#define WIN_BUFFER_FORMAT (1<< 5)
101#define WIN_COLOR_ORDER (1<< 6)
102#define WIN_PIXEL_ORDER (1<< 7)
103#define WIN_SIZE (1<< 8)
104#define WIN_COLORKEY_MODE (1<< 9)
105#define WIN_DOUBLE_BUFFER_MODE (1<< 10)
106#define WIN_RAM_ARRAY_MODE (1<< 11)
107#define WIN_BUFFER_SCALE (1<< 12)
108#define WIN_ENABLE (1<< 13)
109
110struct au1200_lcd_window_regs_t {
111 unsigned int flags;
112 unsigned int xpos;
113 unsigned int ypos;
114 unsigned int alpha_color;
115 unsigned int alpha_mode;
116 unsigned int priority;
117 unsigned int channel;
118 unsigned int buffer_format;
119 unsigned int color_order;
120 unsigned int pixel_order;
121 unsigned int xsize;
122 unsigned int ysize;
123 unsigned int colorkey_mode;
124 unsigned int double_buffer_mode;
125 unsigned int ram_array_mode;
126 unsigned int xscale;
127 unsigned int yscale;
128 unsigned int enable;
129};
130
131
132struct au1200_lcd_iodata_t {
133 unsigned int subcmd;
134 struct au1200_lcd_global_regs_t global;
135 struct au1200_lcd_window_regs_t window;
136};
137
138#if defined(__BIG_ENDIAN)
139#define LCD_CONTROL_DEFAULT_PO LCD_CONTROL_PO_11
140#else
141#define LCD_CONTROL_DEFAULT_PO LCD_CONTROL_PO_00
142#endif
143#define LCD_CONTROL_DEFAULT_SBPPF LCD_CONTROL_SBPPF_565
144
145/* Private, per-framebuffer management information (independent of the panel itself) */
146struct au1200fb_device {
147 struct fb_info *fb_info; /* FB driver info record */
148 struct au1200fb_platdata *pd;
149
150 int plane;
151 unsigned char* fb_mem; /* FrameBuffer memory map */
152 unsigned int fb_len;
153 dma_addr_t fb_phys;
154};
155
156/********************************************************************/
157
158/* LCD controller restrictions */
159#define AU1200_LCD_MAX_XRES 1280
160#define AU1200_LCD_MAX_YRES 1024
161#define AU1200_LCD_MAX_BPP 32
162#define AU1200_LCD_MAX_CLK 96000000 /* fixme: this needs to go away ? */
163#define AU1200_LCD_NBR_PALETTE_ENTRIES 256
164
165/* Default number of visible screen buffer to allocate */
166#define AU1200FB_NBR_VIDEO_BUFFERS 1
167
168/* Default maximum number of fb devices to create */
169#define MAX_DEVICE_COUNT 4
170
171/* Default window configuration entry to use (see windows[]) */
172#define DEFAULT_WINDOW_INDEX 2
173
174/********************************************************************/
175
176static struct fb_info *_au1200fb_infos[MAX_DEVICE_COUNT];
177static struct au1200_lcd *lcd = (struct au1200_lcd *) AU1200_LCD_ADDR;
178static int device_count = MAX_DEVICE_COUNT;
179static int window_index = DEFAULT_WINDOW_INDEX; /* default is zero */
180static int panel_index = 2; /* default is zero */
181static struct window_settings *win;
182static struct panel_settings *panel;
183static int noblanking = 1;
184static int nohwcursor = 0;
185
186struct window_settings {
187 unsigned char name[64];
188 uint32 mode_backcolor;
189 uint32 mode_colorkey;
190 uint32 mode_colorkeymsk;
191 struct {
192 int xres;
193 int yres;
194 int xpos;
195 int ypos;
196 uint32 mode_winctrl1; /* winctrl1[FRM,CCO,PO,PIPE] */
197 uint32 mode_winenable;
198 } w[4];
199};
200
201#if defined(__BIG_ENDIAN)
202#define LCD_WINCTRL1_PO_16BPP LCD_WINCTRL1_PO_00
203#else
204#define LCD_WINCTRL1_PO_16BPP LCD_WINCTRL1_PO_01
205#endif
206
207/*
208 * Default window configurations
209 */
210static struct window_settings windows[] = {
211 { /* Index 0 */
212 "0-FS gfx, 1-video, 2-ovly gfx, 3-ovly gfx",
213 /* mode_backcolor */ 0x006600ff,
214 /* mode_colorkey,msk*/ 0, 0,
215 {
216 {
217 /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
218 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
219 LCD_WINCTRL1_PO_16BPP,
220 /* mode_winenable*/ LCD_WINENABLE_WEN0,
221 },
222 {
223 /* xres, yres, xpos, ypos */ 100, 100, 100, 100,
224 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
225 LCD_WINCTRL1_PO_16BPP |
226 LCD_WINCTRL1_PIPE,
227 /* mode_winenable*/ LCD_WINENABLE_WEN1,
228 },
229 {
230 /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
231 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
232 LCD_WINCTRL1_PO_16BPP,
233 /* mode_winenable*/ 0,
234 },
235 {
236 /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
237 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
238 LCD_WINCTRL1_PO_16BPP |
239 LCD_WINCTRL1_PIPE,
240 /* mode_winenable*/ 0,
241 },
242 },
243 },
244
245 { /* Index 1 */
246 "0-FS gfx, 1-video, 2-ovly gfx, 3-ovly gfx",
247 /* mode_backcolor */ 0x006600ff,
248 /* mode_colorkey,msk*/ 0, 0,
249 {
250 {
251 /* xres, yres, xpos, ypos */ 320, 240, 5, 5,
252 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_24BPP |
253 LCD_WINCTRL1_PO_00,
254 /* mode_winenable*/ LCD_WINENABLE_WEN0,
255 },
256 {
257 /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
258 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565
259 | LCD_WINCTRL1_PO_16BPP,
260 /* mode_winenable*/ 0,
261 },
262 {
263 /* xres, yres, xpos, ypos */ 100, 100, 0, 0,
264 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
265 LCD_WINCTRL1_PO_16BPP |
266 LCD_WINCTRL1_PIPE,
267 /* mode_winenable*/ 0/*LCD_WINENABLE_WEN2*/,
268 },
269 {
270 /* xres, yres, xpos, ypos */ 200, 25, 0, 0,
271 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
272 LCD_WINCTRL1_PO_16BPP |
273 LCD_WINCTRL1_PIPE,
274 /* mode_winenable*/ 0,
275 },
276 },
277 },
278 { /* Index 2 */
279 "0-FS gfx, 1-video, 2-ovly gfx, 3-ovly gfx",
280 /* mode_backcolor */ 0x006600ff,
281 /* mode_colorkey,msk*/ 0, 0,
282 {
283 {
284 /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
285 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
286 LCD_WINCTRL1_PO_16BPP,
287 /* mode_winenable*/ LCD_WINENABLE_WEN0,
288 },
289 {
290 /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
291 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
292 LCD_WINCTRL1_PO_16BPP,
293 /* mode_winenable*/ 0,
294 },
295 {
296 /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
297 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_32BPP |
298 LCD_WINCTRL1_PO_00|LCD_WINCTRL1_PIPE,
299 /* mode_winenable*/ 0/*LCD_WINENABLE_WEN2*/,
300 },
301 {
302 /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
303 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
304 LCD_WINCTRL1_PO_16BPP |
305 LCD_WINCTRL1_PIPE,
306 /* mode_winenable*/ 0,
307 },
308 },
309 },
310 /* Need VGA 640 @ 24bpp, @ 32bpp */
311 /* Need VGA 800 @ 24bpp, @ 32bpp */
312 /* Need VGA 1024 @ 24bpp, @ 32bpp */
313};
314
315/*
316 * Controller configurations for various panels.
317 */
318
319struct panel_settings
320{
321 const char name[25]; /* Full name <vendor>_<model> */
322
323 struct fb_monspecs monspecs; /* FB monitor specs */
324
325 /* panel timings */
326 uint32 mode_screen;
327 uint32 mode_horztiming;
328 uint32 mode_verttiming;
329 uint32 mode_clkcontrol;
330 uint32 mode_pwmdiv;
331 uint32 mode_pwmhi;
332 uint32 mode_outmask;
333 uint32 mode_fifoctrl;
334 uint32 mode_backlight;
335 uint32 lcdclk;
336#define Xres min_xres
337#define Yres min_yres
338 u32 min_xres; /* Minimum horizontal resolution */
339 u32 max_xres; /* Maximum horizontal resolution */
340 u32 min_yres; /* Minimum vertical resolution */
341 u32 max_yres; /* Maximum vertical resolution */
342};
343
344/********************************************************************/
345/* fixme: Maybe a modedb for the CRT ? otherwise panels should be as-is */
346
347/* List of panels known to work with the AU1200 LCD controller.
348 * To add a new panel, enter the same specifications as the
349 * Generic_TFT one, and MAKE SURE that it doesn't conflicts
350 * with the controller restrictions. Restrictions are:
351 *
352 * STN color panels: max_bpp <= 12
353 * STN mono panels: max_bpp <= 4
354 * TFT panels: max_bpp <= 16
355 * max_xres <= 800
356 * max_yres <= 600
357 */
358static struct panel_settings known_lcd_panels[] =
359{
360 [0] = { /* QVGA 320x240 H:33.3kHz V:110Hz */
361 .name = "QVGA_320x240",
362 .monspecs = {
363 .modedb = NULL,
364 .modedb_len = 0,
365 .hfmin = 30000,
366 .hfmax = 70000,
367 .vfmin = 60,
368 .vfmax = 60,
369 .dclkmin = 6000000,
370 .dclkmax = 28000000,
371 .input = FB_DISP_RGB,
372 },
373 .mode_screen = LCD_SCREEN_SX_N(320) |
374 LCD_SCREEN_SY_N(240),
375 .mode_horztiming = 0x00c4623b,
376 .mode_verttiming = 0x00502814,
377 .mode_clkcontrol = 0x00020002, /* /4=24Mhz */
378 .mode_pwmdiv = 0x00000000,
379 .mode_pwmhi = 0x00000000,
380 .mode_outmask = 0x00FFFFFF,
381 .mode_fifoctrl = 0x2f2f2f2f,
382 .mode_backlight = 0x00000000,
383 .lcdclk = 96,
384 320, 320,
385 240, 240,
386 },
387
388 [1] = { /* VGA 640x480 H:30.3kHz V:58Hz */
389 .name = "VGA_640x480",
390 .monspecs = {
391 .modedb = NULL,
392 .modedb_len = 0,
393 .hfmin = 30000,
394 .hfmax = 70000,
395 .vfmin = 60,
396 .vfmax = 60,
397 .dclkmin = 6000000,
398 .dclkmax = 28000000,
399 .input = FB_DISP_RGB,
400 },
401 .mode_screen = 0x13f9df80,
402 .mode_horztiming = 0x003c5859,
403 .mode_verttiming = 0x00741201,
404 .mode_clkcontrol = 0x00020001, /* /4=24Mhz */
405 .mode_pwmdiv = 0x00000000,
406 .mode_pwmhi = 0x00000000,
407 .mode_outmask = 0x00FFFFFF,
408 .mode_fifoctrl = 0x2f2f2f2f,
409 .mode_backlight = 0x00000000,
410 .lcdclk = 96,
411 640, 480,
412 640, 480,
413 },
414
415 [2] = { /* SVGA 800x600 H:46.1kHz V:69Hz */
416 .name = "SVGA_800x600",
417 .monspecs = {
418 .modedb = NULL,
419 .modedb_len = 0,
420 .hfmin = 30000,
421 .hfmax = 70000,
422 .vfmin = 60,
423 .vfmax = 60,
424 .dclkmin = 6000000,
425 .dclkmax = 28000000,
426 .input = FB_DISP_RGB,
427 },
428 .mode_screen = 0x18fa5780,
429 .mode_horztiming = 0x00dc7e77,
430 .mode_verttiming = 0x00584805,
431 .mode_clkcontrol = 0x00020000, /* /2=48Mhz */
432 .mode_pwmdiv = 0x00000000,
433 .mode_pwmhi = 0x00000000,
434 .mode_outmask = 0x00FFFFFF,
435 .mode_fifoctrl = 0x2f2f2f2f,
436 .mode_backlight = 0x00000000,
437 .lcdclk = 96,
438 800, 800,
439 600, 600,
440 },
441
442 [3] = { /* XVGA 1024x768 H:56.2kHz V:70Hz */
443 .name = "XVGA_1024x768",
444 .monspecs = {
445 .modedb = NULL,
446 .modedb_len = 0,
447 .hfmin = 30000,
448 .hfmax = 70000,
449 .vfmin = 60,
450 .vfmax = 60,
451 .dclkmin = 6000000,
452 .dclkmax = 28000000,
453 .input = FB_DISP_RGB,
454 },
455 .mode_screen = 0x1ffaff80,
456 .mode_horztiming = 0x007d0e57,
457 .mode_verttiming = 0x00740a01,
458 .mode_clkcontrol = 0x000A0000, /* /1 */
459 .mode_pwmdiv = 0x00000000,
460 .mode_pwmhi = 0x00000000,
461 .mode_outmask = 0x00FFFFFF,
462 .mode_fifoctrl = 0x2f2f2f2f,
463 .mode_backlight = 0x00000000,
464 .lcdclk = 72,
465 1024, 1024,
466 768, 768,
467 },
468
469 [4] = { /* XVGA XVGA 1280x1024 H:68.5kHz V:65Hz */
470 .name = "XVGA_1280x1024",
471 .monspecs = {
472 .modedb = NULL,
473 .modedb_len = 0,
474 .hfmin = 30000,
475 .hfmax = 70000,
476 .vfmin = 60,
477 .vfmax = 60,
478 .dclkmin = 6000000,
479 .dclkmax = 28000000,
480 .input = FB_DISP_RGB,
481 },
482 .mode_screen = 0x27fbff80,
483 .mode_horztiming = 0x00cdb2c7,
484 .mode_verttiming = 0x00600002,
485 .mode_clkcontrol = 0x000A0000, /* /1 */
486 .mode_pwmdiv = 0x00000000,
487 .mode_pwmhi = 0x00000000,
488 .mode_outmask = 0x00FFFFFF,
489 .mode_fifoctrl = 0x2f2f2f2f,
490 .mode_backlight = 0x00000000,
491 .lcdclk = 120,
492 1280, 1280,
493 1024, 1024,
494 },
495
496 [5] = { /* Samsung 1024x768 TFT */
497 .name = "Samsung_1024x768_TFT",
498 .monspecs = {
499 .modedb = NULL,
500 .modedb_len = 0,
501 .hfmin = 30000,
502 .hfmax = 70000,
503 .vfmin = 60,
504 .vfmax = 60,
505 .dclkmin = 6000000,
506 .dclkmax = 28000000,
507 .input = FB_DISP_RGB,
508 },
509 .mode_screen = 0x1ffaff80,
510 .mode_horztiming = 0x018cc677,
511 .mode_verttiming = 0x00241217,
512 .mode_clkcontrol = 0x00000000, /* SCB 0x1 /4=24Mhz */
513 .mode_pwmdiv = 0x8000063f, /* SCB 0x0 */
514 .mode_pwmhi = 0x03400000, /* SCB 0x0 */
515 .mode_outmask = 0x00FFFFFF,
516 .mode_fifoctrl = 0x2f2f2f2f,
517 .mode_backlight = 0x00000000,
518 .lcdclk = 96,
519 1024, 1024,
520 768, 768,
521 },
522
523 [6] = { /* Toshiba 640x480 TFT */
524 .name = "Toshiba_640x480_TFT",
525 .monspecs = {
526 .modedb = NULL,
527 .modedb_len = 0,
528 .hfmin = 30000,
529 .hfmax = 70000,
530 .vfmin = 60,
531 .vfmax = 60,
532 .dclkmin = 6000000,
533 .dclkmax = 28000000,
534 .input = FB_DISP_RGB,
535 },
536 .mode_screen = LCD_SCREEN_SX_N(640) |
537 LCD_SCREEN_SY_N(480),
538 .mode_horztiming = LCD_HORZTIMING_HPW_N(96) |
539 LCD_HORZTIMING_HND1_N(13) | LCD_HORZTIMING_HND2_N(51),
540 .mode_verttiming = LCD_VERTTIMING_VPW_N(2) |
541 LCD_VERTTIMING_VND1_N(11) | LCD_VERTTIMING_VND2_N(32),
542 .mode_clkcontrol = 0x00000000, /* /4=24Mhz */
543 .mode_pwmdiv = 0x8000063f,
544 .mode_pwmhi = 0x03400000,
545 .mode_outmask = 0x00fcfcfc,
546 .mode_fifoctrl = 0x2f2f2f2f,
547 .mode_backlight = 0x00000000,
548 .lcdclk = 96,
549 640, 480,
550 640, 480,
551 },
552
553 [7] = { /* Sharp 320x240 TFT */
554 .name = "Sharp_320x240_TFT",
555 .monspecs = {
556 .modedb = NULL,
557 .modedb_len = 0,
558 .hfmin = 12500,
559 .hfmax = 20000,
560 .vfmin = 38,
561 .vfmax = 81,
562 .dclkmin = 4500000,
563 .dclkmax = 6800000,
564 .input = FB_DISP_RGB,
565 },
566 .mode_screen = LCD_SCREEN_SX_N(320) |
567 LCD_SCREEN_SY_N(240),
568 .mode_horztiming = LCD_HORZTIMING_HPW_N(60) |
569 LCD_HORZTIMING_HND1_N(13) | LCD_HORZTIMING_HND2_N(2),
570 .mode_verttiming = LCD_VERTTIMING_VPW_N(2) |
571 LCD_VERTTIMING_VND1_N(2) | LCD_VERTTIMING_VND2_N(5),
572 .mode_clkcontrol = LCD_CLKCONTROL_PCD_N(7), /*16=6Mhz*/
573 .mode_pwmdiv = 0x8000063f,
574 .mode_pwmhi = 0x03400000,
575 .mode_outmask = 0x00fcfcfc,
576 .mode_fifoctrl = 0x2f2f2f2f,
577 .mode_backlight = 0x00000000,
578 .lcdclk = 96, /* 96MHz AUXPLL */
579 320, 320,
580 240, 240,
581 },
582
583 [8] = { /* Toppoly TD070WGCB2 7" 856x480 TFT */
584 .name = "Toppoly_TD070WGCB2",
585 .monspecs = {
586 .modedb = NULL,
587 .modedb_len = 0,
588 .hfmin = 30000,
589 .hfmax = 70000,
590 .vfmin = 60,
591 .vfmax = 60,
592 .dclkmin = 6000000,
593 .dclkmax = 28000000,
594 .input = FB_DISP_RGB,
595 },
596 .mode_screen = LCD_SCREEN_SX_N(856) |
597 LCD_SCREEN_SY_N(480),
598 .mode_horztiming = LCD_HORZTIMING_HND2_N(43) |
599 LCD_HORZTIMING_HND1_N(43) | LCD_HORZTIMING_HPW_N(114),
600 .mode_verttiming = LCD_VERTTIMING_VND2_N(20) |
601 LCD_VERTTIMING_VND1_N(21) | LCD_VERTTIMING_VPW_N(4),
602 .mode_clkcontrol = 0x00020001, /* /4=24Mhz */
603 .mode_pwmdiv = 0x8000063f,
604 .mode_pwmhi = 0x03400000,
605 .mode_outmask = 0x00fcfcfc,
606 .mode_fifoctrl = 0x2f2f2f2f,
607 .mode_backlight = 0x00000000,
608 .lcdclk = 96,
609 856, 856,
610 480, 480,
611 },
612 [9] = {
613 .name = "DB1300_800x480",
614 .monspecs = {
615 .modedb = NULL,
616 .modedb_len = 0,
617 .hfmin = 30000,
618 .hfmax = 70000,
619 .vfmin = 60,
620 .vfmax = 60,
621 .dclkmin = 6000000,
622 .dclkmax = 28000000,
623 .input = FB_DISP_RGB,
624 },
625 .mode_screen = LCD_SCREEN_SX_N(800) |
626 LCD_SCREEN_SY_N(480),
627 .mode_horztiming = LCD_HORZTIMING_HPW_N(5) |
628 LCD_HORZTIMING_HND1_N(16) |
629 LCD_HORZTIMING_HND2_N(8),
630 .mode_verttiming = LCD_VERTTIMING_VPW_N(4) |
631 LCD_VERTTIMING_VND1_N(8) |
632 LCD_VERTTIMING_VND2_N(5),
633 .mode_clkcontrol = LCD_CLKCONTROL_PCD_N(1) |
634 LCD_CLKCONTROL_IV |
635 LCD_CLKCONTROL_IH,
636 .mode_pwmdiv = 0x00000000,
637 .mode_pwmhi = 0x00000000,
638 .mode_outmask = 0x00FFFFFF,
639 .mode_fifoctrl = 0x2f2f2f2f,
640 .mode_backlight = 0x00000000,
641 .lcdclk = 96,
642 800, 800,
643 480, 480,
644 },
645};
646
647#define NUM_PANELS (ARRAY_SIZE(known_lcd_panels))
648
649/********************************************************************/
650
651static int winbpp (unsigned int winctrl1)
652{
653 int bits = 0;
654
655 /* how many bits are needed for each pixel format */
656 switch (winctrl1 & LCD_WINCTRL1_FRM) {
657 case LCD_WINCTRL1_FRM_1BPP:
658 bits = 1;
659 break;
660 case LCD_WINCTRL1_FRM_2BPP:
661 bits = 2;
662 break;
663 case LCD_WINCTRL1_FRM_4BPP:
664 bits = 4;
665 break;
666 case LCD_WINCTRL1_FRM_8BPP:
667 bits = 8;
668 break;
669 case LCD_WINCTRL1_FRM_12BPP:
670 case LCD_WINCTRL1_FRM_16BPP655:
671 case LCD_WINCTRL1_FRM_16BPP565:
672 case LCD_WINCTRL1_FRM_16BPP556:
673 case LCD_WINCTRL1_FRM_16BPPI1555:
674 case LCD_WINCTRL1_FRM_16BPPI5551:
675 case LCD_WINCTRL1_FRM_16BPPA1555:
676 case LCD_WINCTRL1_FRM_16BPPA5551:
677 bits = 16;
678 break;
679 case LCD_WINCTRL1_FRM_24BPP:
680 case LCD_WINCTRL1_FRM_32BPP:
681 bits = 32;
682 break;
683 }
684
685 return bits;
686}
687
688static int fbinfo2index (struct fb_info *fb_info)
689{
690 int i;
691
692 for (i = 0; i < device_count; ++i) {
693 if (fb_info == _au1200fb_infos[i])
694 return i;
695 }
696 printk("au1200fb: ERROR: fbinfo2index failed!\n");
697 return -1;
698}
699
700static int au1200_setlocation (struct au1200fb_device *fbdev, int plane,
701 int xpos, int ypos)
702{
703 uint32 winctrl0, winctrl1, winenable, fb_offset = 0;
704 int xsz, ysz;
705
706 /* FIX!!! NOT CHECKING FOR COMPLETE OFFSCREEN YET */
707
708 winctrl0 = lcd->window[plane].winctrl0;
709 winctrl1 = lcd->window[plane].winctrl1;
710 winctrl0 &= (LCD_WINCTRL0_A | LCD_WINCTRL0_AEN);
711 winctrl1 &= ~(LCD_WINCTRL1_SZX | LCD_WINCTRL1_SZY);
712
713 /* Check for off-screen adjustments */
714 xsz = win->w[plane].xres;
715 ysz = win->w[plane].yres;
716 if ((xpos + win->w[plane].xres) > panel->Xres) {
717 /* Off-screen to the right */
718 xsz = panel->Xres - xpos; /* off by 1 ??? */
719 /*printk("off screen right\n");*/
720 }
721
722 if ((ypos + win->w[plane].yres) > panel->Yres) {
723 /* Off-screen to the bottom */
724 ysz = panel->Yres - ypos; /* off by 1 ??? */
725 /*printk("off screen bottom\n");*/
726 }
727
728 if (xpos < 0) {
729 /* Off-screen to the left */
730 xsz = win->w[plane].xres + xpos;
731 fb_offset += (((0 - xpos) * winbpp(lcd->window[plane].winctrl1))/8);
732 xpos = 0;
733 /*printk("off screen left\n");*/
734 }
735
736 if (ypos < 0) {
737 /* Off-screen to the top */
738 ysz = win->w[plane].yres + ypos;
739 /* fixme: fb_offset += ((0-ypos)*fb_pars[plane].line_length); */
740 ypos = 0;
741 /*printk("off screen top\n");*/
742 }
743
744 /* record settings */
745 win->w[plane].xpos = xpos;
746 win->w[plane].ypos = ypos;
747
748 xsz -= 1;
749 ysz -= 1;
750 winctrl0 |= (xpos << 21);
751 winctrl0 |= (ypos << 10);
752 winctrl1 |= (xsz << 11);
753 winctrl1 |= (ysz << 0);
754
755 /* Disable the window while making changes, then restore WINEN */
756 winenable = lcd->winenable & (1 << plane);
757 wmb(); /* drain writebuffer */
758 lcd->winenable &= ~(1 << plane);
759 lcd->window[plane].winctrl0 = winctrl0;
760 lcd->window[plane].winctrl1 = winctrl1;
761 lcd->window[plane].winbuf0 =
762 lcd->window[plane].winbuf1 = fbdev->fb_phys;
763 lcd->window[plane].winbufctrl = 0; /* select winbuf0 */
764 lcd->winenable |= winenable;
765 wmb(); /* drain writebuffer */
766
767 return 0;
768}
769
770static void au1200_setpanel(struct panel_settings *newpanel,
771 struct au1200fb_platdata *pd)
772{
773 /*
774 * Perform global setup/init of LCD controller
775 */
776 uint32 winenable;
777
778 /* Make sure all windows disabled */
779 winenable = lcd->winenable;
780 lcd->winenable = 0;
781 wmb(); /* drain writebuffer */
782 /*
783 * Ensure everything is disabled before reconfiguring
784 */
785 if (lcd->screen & LCD_SCREEN_SEN) {
786 /* Wait for vertical sync period */
787 lcd->intstatus = LCD_INT_SS;
788 while ((lcd->intstatus & LCD_INT_SS) == 0)
789 ;
790
791 lcd->screen &= ~LCD_SCREEN_SEN; /*disable the controller*/
792
793 do {
794 lcd->intstatus = lcd->intstatus; /*clear interrupts*/
795 wmb(); /* drain writebuffer */
796 /*wait for controller to shut down*/
797 } while ((lcd->intstatus & LCD_INT_SD) == 0);
798
799 /* Call shutdown of current panel (if up) */
800 /* this must occur last, because if an external clock is driving
801 the controller, the clock cannot be turned off before first
802 shutting down the controller.
803 */
804 if (pd->panel_shutdown)
805 pd->panel_shutdown();
806 }
807
808 /* Newpanel == NULL indicates a shutdown operation only */
809 if (newpanel == NULL)
810 return;
811
812 panel = newpanel;
813
814 printk("Panel(%s), %dx%d\n", panel->name, panel->Xres, panel->Yres);
815
816 /*
817 * Setup clocking if internal LCD clock source (assumes sys_auxpll valid)
818 */
819 if (!(panel->mode_clkcontrol & LCD_CLKCONTROL_EXT))
820 {
821 struct clk *c = clk_get(NULL, "lcd_intclk");
822 long r, pc = panel->lcdclk * 1000000;
823
824 if (!IS_ERR(c)) {
825 r = clk_round_rate(c, pc);
826 if ((pc - r) < (pc / 10)) { /* 10% slack */
827 clk_set_rate(c, r);
828 clk_prepare_enable(c);
829 }
830 clk_put(c);
831 }
832 }
833
834 /*
835 * Configure panel timings
836 */
837 lcd->screen = panel->mode_screen;
838 lcd->horztiming = panel->mode_horztiming;
839 lcd->verttiming = panel->mode_verttiming;
840 lcd->clkcontrol = panel->mode_clkcontrol;
841 lcd->pwmdiv = panel->mode_pwmdiv;
842 lcd->pwmhi = panel->mode_pwmhi;
843 lcd->outmask = panel->mode_outmask;
844 lcd->fifoctrl = panel->mode_fifoctrl;
845 wmb(); /* drain writebuffer */
846
847 /* fixme: Check window settings to make sure still valid
848 * for new geometry */
849#if 0
850 au1200_setlocation(fbdev, 0, win->w[0].xpos, win->w[0].ypos);
851 au1200_setlocation(fbdev, 1, win->w[1].xpos, win->w[1].ypos);
852 au1200_setlocation(fbdev, 2, win->w[2].xpos, win->w[2].ypos);
853 au1200_setlocation(fbdev, 3, win->w[3].xpos, win->w[3].ypos);
854#endif
855 lcd->winenable = winenable;
856
857 /*
858 * Re-enable screen now that it is configured
859 */
860 lcd->screen |= LCD_SCREEN_SEN;
861 wmb(); /* drain writebuffer */
862
863 /* Call init of panel */
864 if (pd->panel_init)
865 pd->panel_init();
866
867 /* FIX!!!! not appropriate on panel change!!! Global setup/init */
868 lcd->intenable = 0;
869 lcd->intstatus = ~0;
870 lcd->backcolor = win->mode_backcolor;
871
872 /* Setup Color Key - FIX!!! */
873 lcd->colorkey = win->mode_colorkey;
874 lcd->colorkeymsk = win->mode_colorkeymsk;
875
876 /* Setup HWCursor - FIX!!! Need to support this eventually */
877 lcd->hwc.cursorctrl = 0;
878 lcd->hwc.cursorpos = 0;
879 lcd->hwc.cursorcolor0 = 0;
880 lcd->hwc.cursorcolor1 = 0;
881 lcd->hwc.cursorcolor2 = 0;
882 lcd->hwc.cursorcolor3 = 0;
883
884
885#if 0
886#define D(X) printk("%25s: %08X\n", #X, X)
887 D(lcd->screen);
888 D(lcd->horztiming);
889 D(lcd->verttiming);
890 D(lcd->clkcontrol);
891 D(lcd->pwmdiv);
892 D(lcd->pwmhi);
893 D(lcd->outmask);
894 D(lcd->fifoctrl);
895 D(lcd->window[0].winctrl0);
896 D(lcd->window[0].winctrl1);
897 D(lcd->window[0].winctrl2);
898 D(lcd->window[0].winbuf0);
899 D(lcd->window[0].winbuf1);
900 D(lcd->window[0].winbufctrl);
901 D(lcd->window[1].winctrl0);
902 D(lcd->window[1].winctrl1);
903 D(lcd->window[1].winctrl2);
904 D(lcd->window[1].winbuf0);
905 D(lcd->window[1].winbuf1);
906 D(lcd->window[1].winbufctrl);
907 D(lcd->window[2].winctrl0);
908 D(lcd->window[2].winctrl1);
909 D(lcd->window[2].winctrl2);
910 D(lcd->window[2].winbuf0);
911 D(lcd->window[2].winbuf1);
912 D(lcd->window[2].winbufctrl);
913 D(lcd->window[3].winctrl0);
914 D(lcd->window[3].winctrl1);
915 D(lcd->window[3].winctrl2);
916 D(lcd->window[3].winbuf0);
917 D(lcd->window[3].winbuf1);
918 D(lcd->window[3].winbufctrl);
919 D(lcd->winenable);
920 D(lcd->intenable);
921 D(lcd->intstatus);
922 D(lcd->backcolor);
923 D(lcd->winenable);
924 D(lcd->colorkey);
925 D(lcd->colorkeymsk);
926 D(lcd->hwc.cursorctrl);
927 D(lcd->hwc.cursorpos);
928 D(lcd->hwc.cursorcolor0);
929 D(lcd->hwc.cursorcolor1);
930 D(lcd->hwc.cursorcolor2);
931 D(lcd->hwc.cursorcolor3);
932#endif
933}
934
935static void au1200_setmode(struct au1200fb_device *fbdev)
936{
937 int plane = fbdev->plane;
938 /* Window/plane setup */
939 lcd->window[plane].winctrl1 = ( 0
940 | LCD_WINCTRL1_PRI_N(plane)
941 | win->w[plane].mode_winctrl1 /* FRM,CCO,PO,PIPE */
942 ) ;
943
944 au1200_setlocation(fbdev, plane, win->w[plane].xpos, win->w[plane].ypos);
945
946 lcd->window[plane].winctrl2 = ( 0
947 | LCD_WINCTRL2_CKMODE_00
948 | LCD_WINCTRL2_DBM
949 | LCD_WINCTRL2_BX_N(fbdev->fb_info->fix.line_length)
950 | LCD_WINCTRL2_SCX_1
951 | LCD_WINCTRL2_SCY_1
952 ) ;
953 lcd->winenable |= win->w[plane].mode_winenable;
954 wmb(); /* drain writebuffer */
955}
956
957
958/* Inline helpers */
959
960/*#define panel_is_dual(panel) ((panel->mode_screen & LCD_SCREEN_PT) == LCD_SCREEN_PT_010)*/
961/*#define panel_is_active(panel)((panel->mode_screen & LCD_SCREEN_PT) == LCD_SCREEN_PT_010)*/
962
963#define panel_is_color(panel) ((panel->mode_screen & LCD_SCREEN_PT) <= LCD_SCREEN_PT_CDSTN)
964
965/* Bitfields format supported by the controller. */
966static struct fb_bitfield rgb_bitfields[][4] = {
967 /* Red, Green, Blue, Transp */
968 [LCD_WINCTRL1_FRM_16BPP655 >> 25] =
969 { { 10, 6, 0 }, { 5, 5, 0 }, { 0, 5, 0 }, { 0, 0, 0 } },
970
971 [LCD_WINCTRL1_FRM_16BPP565 >> 25] =
972 { { 11, 5, 0 }, { 5, 6, 0 }, { 0, 5, 0 }, { 0, 0, 0 } },
973
974 [LCD_WINCTRL1_FRM_16BPP556 >> 25] =
975 { { 11, 5, 0 }, { 6, 5, 0 }, { 0, 6, 0 }, { 0, 0, 0 } },
976
977 [LCD_WINCTRL1_FRM_16BPPI1555 >> 25] =
978 { { 10, 5, 0 }, { 5, 5, 0 }, { 0, 5, 0 }, { 0, 0, 0 } },
979
980 [LCD_WINCTRL1_FRM_16BPPI5551 >> 25] =
981 { { 11, 5, 0 }, { 6, 5, 0 }, { 1, 5, 0 }, { 0, 0, 0 } },
982
983 [LCD_WINCTRL1_FRM_16BPPA1555 >> 25] =
984 { { 10, 5, 0 }, { 5, 5, 0 }, { 0, 5, 0 }, { 15, 1, 0 } },
985
986 [LCD_WINCTRL1_FRM_16BPPA5551 >> 25] =
987 { { 11, 5, 0 }, { 6, 5, 0 }, { 1, 5, 0 }, { 0, 1, 0 } },
988
989 [LCD_WINCTRL1_FRM_24BPP >> 25] =
990 { { 16, 8, 0 }, { 8, 8, 0 }, { 0, 8, 0 }, { 0, 0, 0 } },
991
992 [LCD_WINCTRL1_FRM_32BPP >> 25] =
993 { { 16, 8, 0 }, { 8, 8, 0 }, { 0, 8, 0 }, { 24, 0, 0 } },
994};
995
996/*-------------------------------------------------------------------------*/
997
998/* Helpers */
999
1000static void au1200fb_update_fbinfo(struct fb_info *fbi)
1001{
1002 /* FIX!!!! This also needs to take the window pixel format into account!!! */
1003
1004 /* Update var-dependent FB info */
1005 if (panel_is_color(panel)) {
1006 if (fbi->var.bits_per_pixel <= 8) {
1007 /* palettized */
1008 fbi->fix.visual = FB_VISUAL_PSEUDOCOLOR;
1009 fbi->fix.line_length = fbi->var.xres_virtual /
1010 (8/fbi->var.bits_per_pixel);
1011 } else {
1012 /* non-palettized */
1013 fbi->fix.visual = FB_VISUAL_TRUECOLOR;
1014 fbi->fix.line_length = fbi->var.xres_virtual * (fbi->var.bits_per_pixel / 8);
1015 }
1016 } else {
1017 /* mono FIX!!! mono 8 and 4 bits */
1018 fbi->fix.visual = FB_VISUAL_MONO10;
1019 fbi->fix.line_length = fbi->var.xres_virtual / 8;
1020 }
1021
1022 fbi->screen_size = fbi->fix.line_length * fbi->var.yres_virtual;
1023 print_dbg("line length: %d\n", fbi->fix.line_length);
1024 print_dbg("bits_per_pixel: %d\n", fbi->var.bits_per_pixel);
1025}
1026
1027/*-------------------------------------------------------------------------*/
1028
1029/* AU1200 framebuffer driver */
1030
1031/* fb_check_var
1032 * Validate var settings with hardware restrictions and modify it if necessary
1033 */
1034static int au1200fb_fb_check_var(struct fb_var_screeninfo *var,
1035 struct fb_info *fbi)
1036{
1037 struct au1200fb_device *fbdev = fbi->par;
1038 u32 pixclock;
1039 int screen_size, plane;
1040
1041 plane = fbdev->plane;
1042
1043 /* Make sure that the mode respect all LCD controller and
1044 * panel restrictions. */
1045 var->xres = win->w[plane].xres;
1046 var->yres = win->w[plane].yres;
1047
1048 /* No need for virtual resolution support */
1049 var->xres_virtual = var->xres;
1050 var->yres_virtual = var->yres;
1051
1052 var->bits_per_pixel = winbpp(win->w[plane].mode_winctrl1);
1053
1054 screen_size = var->xres_virtual * var->yres_virtual;
1055 if (var->bits_per_pixel > 8) screen_size *= (var->bits_per_pixel / 8);
1056 else screen_size /= (8/var->bits_per_pixel);
1057
1058 if (fbdev->fb_len < screen_size)
1059 return -EINVAL; /* Virtual screen is to big, abort */
1060
1061 /* FIX!!!! what are the implicaitons of ignoring this for windows ??? */
1062 /* The max LCD clock is fixed to 48MHz (value of AUX_CLK). The pixel
1063 * clock can only be obtain by dividing this value by an even integer.
1064 * Fallback to a slower pixel clock if necessary. */
1065 pixclock = max((u32)(PICOS2KHZ(var->pixclock) * 1000), fbi->monspecs.dclkmin);
1066 pixclock = min3(pixclock, fbi->monspecs.dclkmax, (u32)AU1200_LCD_MAX_CLK/2);
1067
1068 if (AU1200_LCD_MAX_CLK % pixclock) {
1069 int diff = AU1200_LCD_MAX_CLK % pixclock;
1070 pixclock -= diff;
1071 }
1072
1073 var->pixclock = KHZ2PICOS(pixclock/1000);
1074#if 0
1075 if (!panel_is_active(panel)) {
1076 int pcd = AU1200_LCD_MAX_CLK / (pixclock * 2) - 1;
1077
1078 if (!panel_is_color(panel)
1079 && (panel->control_base & LCD_CONTROL_MPI) && (pcd < 3)) {
1080 /* STN 8bit mono panel support is up to 6MHz pixclock */
1081 var->pixclock = KHZ2PICOS(6000);
1082 } else if (!pcd) {
1083 /* Other STN panel support is up to 12MHz */
1084 var->pixclock = KHZ2PICOS(12000);
1085 }
1086 }
1087#endif
1088 /* Set bitfield accordingly */
1089 switch (var->bits_per_pixel) {
1090 case 16:
1091 {
1092 /* 16bpp True color.
1093 * These must be set to MATCH WINCTRL[FORM] */
1094 int idx;
1095 idx = (win->w[0].mode_winctrl1 & LCD_WINCTRL1_FRM) >> 25;
1096 var->red = rgb_bitfields[idx][0];
1097 var->green = rgb_bitfields[idx][1];
1098 var->blue = rgb_bitfields[idx][2];
1099 var->transp = rgb_bitfields[idx][3];
1100 break;
1101 }
1102
1103 case 32:
1104 {
1105 /* 32bpp True color.
1106 * These must be set to MATCH WINCTRL[FORM] */
1107 int idx;
1108 idx = (win->w[0].mode_winctrl1 & LCD_WINCTRL1_FRM) >> 25;
1109 var->red = rgb_bitfields[idx][0];
1110 var->green = rgb_bitfields[idx][1];
1111 var->blue = rgb_bitfields[idx][2];
1112 var->transp = rgb_bitfields[idx][3];
1113 break;
1114 }
1115 default:
1116 print_dbg("Unsupported depth %dbpp", var->bits_per_pixel);
1117 return -EINVAL;
1118 }
1119
1120 return 0;
1121}
1122
1123/* fb_set_par
1124 * Set hardware with var settings. This will enable the controller with a
1125 * specific mode, normally validated with the fb_check_var method
1126 */
1127static int au1200fb_fb_set_par(struct fb_info *fbi)
1128{
1129 struct au1200fb_device *fbdev = fbi->par;
1130
1131 au1200fb_update_fbinfo(fbi);
1132 au1200_setmode(fbdev);
1133
1134 return 0;
1135}
1136
1137/* fb_setcolreg
1138 * Set color in LCD palette.
1139 */
1140static int au1200fb_fb_setcolreg(unsigned regno, unsigned red, unsigned green,
1141 unsigned blue, unsigned transp, struct fb_info *fbi)
1142{
1143 volatile u32 *palette = lcd->palette;
1144 u32 value;
1145
1146 if (regno > (AU1200_LCD_NBR_PALETTE_ENTRIES - 1))
1147 return -EINVAL;
1148
1149 if (fbi->var.grayscale) {
1150 /* Convert color to grayscale */
1151 red = green = blue =
1152 (19595 * red + 38470 * green + 7471 * blue) >> 16;
1153 }
1154
1155 if (fbi->fix.visual == FB_VISUAL_TRUECOLOR) {
1156 /* Place color in the pseudopalette */
1157 if (regno > 16)
1158 return -EINVAL;
1159
1160 palette = (u32*) fbi->pseudo_palette;
1161
1162 red >>= (16 - fbi->var.red.length);
1163 green >>= (16 - fbi->var.green.length);
1164 blue >>= (16 - fbi->var.blue.length);
1165
1166 value = (red << fbi->var.red.offset) |
1167 (green << fbi->var.green.offset)|
1168 (blue << fbi->var.blue.offset);
1169 value &= 0xFFFF;
1170
1171 } else if (1 /*FIX!!! panel_is_active(fbdev->panel)*/) {
1172 /* COLOR TFT PALLETTIZED (use RGB 565) */
1173 value = (red & 0xF800)|((green >> 5) &
1174 0x07E0)|((blue >> 11) & 0x001F);
1175 value &= 0xFFFF;
1176
1177 } else if (0 /*panel_is_color(fbdev->panel)*/) {
1178 /* COLOR STN MODE */
1179 value = 0x1234;
1180 value &= 0xFFF;
1181 } else {
1182 /* MONOCHROME MODE */
1183 value = (green >> 12) & 0x000F;
1184 value &= 0xF;
1185 }
1186
1187 palette[regno] = value;
1188
1189 return 0;
1190}
1191
1192/* fb_blank
1193 * Blank the screen. Depending on the mode, the screen will be
1194 * activated with the backlight color, or desactivated
1195 */
1196static int au1200fb_fb_blank(int blank_mode, struct fb_info *fbi)
1197{
1198 struct au1200fb_device *fbdev = fbi->par;
1199
1200 /* Short-circuit screen blanking */
1201 if (noblanking)
1202 return 0;
1203
1204 switch (blank_mode) {
1205
1206 case FB_BLANK_UNBLANK:
1207 case FB_BLANK_NORMAL:
1208 /* printk("turn on panel\n"); */
1209 au1200_setpanel(panel, fbdev->pd);
1210 break;
1211 case FB_BLANK_VSYNC_SUSPEND:
1212 case FB_BLANK_HSYNC_SUSPEND:
1213 case FB_BLANK_POWERDOWN:
1214 /* printk("turn off panel\n"); */
1215 au1200_setpanel(NULL, fbdev->pd);
1216 break;
1217 default:
1218 break;
1219
1220 }
1221
1222 /* FB_BLANK_NORMAL is a soft blank */
1223 return (blank_mode == FB_BLANK_NORMAL) ? -EINVAL : 0;
1224}
1225
1226/* fb_mmap
1227 * Map video memory in user space. We don't use the generic fb_mmap
1228 * method mainly to allow the use of the TLB streaming flag (CCA=6)
1229 */
1230static int au1200fb_fb_mmap(struct fb_info *info, struct vm_area_struct *vma)
1231{
1232 struct au1200fb_device *fbdev = info->par;
1233
1234 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
1235 pgprot_val(vma->vm_page_prot) |= _CACHE_MASK; /* CCA=7 */
1236
1237 return vm_iomap_memory(vma, fbdev->fb_phys, fbdev->fb_len);
1238}
1239
1240static void set_global(u_int cmd, struct au1200_lcd_global_regs_t *pdata)
1241{
1242
1243 unsigned int hi1, divider;
1244
1245 /* SCREEN_SIZE: user cannot reset size, must switch panel choice */
1246
1247 if (pdata->flags & SCREEN_BACKCOLOR)
1248 lcd->backcolor = pdata->backcolor;
1249
1250 if (pdata->flags & SCREEN_BRIGHTNESS) {
1251
1252 // limit brightness pwm duty to >= 30/1600
1253 if (pdata->brightness < 30) {
1254 pdata->brightness = 30;
1255 }
1256 divider = (lcd->pwmdiv & 0x3FFFF) + 1;
1257 hi1 = (lcd->pwmhi >> 16) + 1;
1258 hi1 = (((pdata->brightness & 0xFF)+1) * divider >> 8);
1259 lcd->pwmhi &= 0xFFFF;
1260 lcd->pwmhi |= (hi1 << 16);
1261 }
1262
1263 if (pdata->flags & SCREEN_COLORKEY)
1264 lcd->colorkey = pdata->colorkey;
1265
1266 if (pdata->flags & SCREEN_MASK)
1267 lcd->colorkeymsk = pdata->mask;
1268 wmb(); /* drain writebuffer */
1269}
1270
1271static void get_global(u_int cmd, struct au1200_lcd_global_regs_t *pdata)
1272{
1273 unsigned int hi1, divider;
1274
1275 pdata->xsize = ((lcd->screen & LCD_SCREEN_SX) >> 19) + 1;
1276 pdata->ysize = ((lcd->screen & LCD_SCREEN_SY) >> 8) + 1;
1277
1278 pdata->backcolor = lcd->backcolor;
1279 pdata->colorkey = lcd->colorkey;
1280 pdata->mask = lcd->colorkeymsk;
1281
1282 // brightness
1283 hi1 = (lcd->pwmhi >> 16) + 1;
1284 divider = (lcd->pwmdiv & 0x3FFFF) + 1;
1285 pdata->brightness = ((hi1 << 8) / divider) - 1;
1286 wmb(); /* drain writebuffer */
1287}
1288
1289static void set_window(unsigned int plane,
1290 struct au1200_lcd_window_regs_t *pdata)
1291{
1292 unsigned int val, bpp;
1293
1294 /* Window control register 0 */
1295 if (pdata->flags & WIN_POSITION) {
1296 val = lcd->window[plane].winctrl0 & ~(LCD_WINCTRL0_OX |
1297 LCD_WINCTRL0_OY);
1298 val |= ((pdata->xpos << 21) & LCD_WINCTRL0_OX);
1299 val |= ((pdata->ypos << 10) & LCD_WINCTRL0_OY);
1300 lcd->window[plane].winctrl0 = val;
1301 }
1302 if (pdata->flags & WIN_ALPHA_COLOR) {
1303 val = lcd->window[plane].winctrl0 & ~(LCD_WINCTRL0_A);
1304 val |= ((pdata->alpha_color << 2) & LCD_WINCTRL0_A);
1305 lcd->window[plane].winctrl0 = val;
1306 }
1307 if (pdata->flags & WIN_ALPHA_MODE) {
1308 val = lcd->window[plane].winctrl0 & ~(LCD_WINCTRL0_AEN);
1309 val |= ((pdata->alpha_mode << 1) & LCD_WINCTRL0_AEN);
1310 lcd->window[plane].winctrl0 = val;
1311 }
1312
1313 /* Window control register 1 */
1314 if (pdata->flags & WIN_PRIORITY) {
1315 val = lcd->window[plane].winctrl1 & ~(LCD_WINCTRL1_PRI);
1316 val |= ((pdata->priority << 30) & LCD_WINCTRL1_PRI);
1317 lcd->window[plane].winctrl1 = val;
1318 }
1319 if (pdata->flags & WIN_CHANNEL) {
1320 val = lcd->window[plane].winctrl1 & ~(LCD_WINCTRL1_PIPE);
1321 val |= ((pdata->channel << 29) & LCD_WINCTRL1_PIPE);
1322 lcd->window[plane].winctrl1 = val;
1323 }
1324 if (pdata->flags & WIN_BUFFER_FORMAT) {
1325 val = lcd->window[plane].winctrl1 & ~(LCD_WINCTRL1_FRM);
1326 val |= ((pdata->buffer_format << 25) & LCD_WINCTRL1_FRM);
1327 lcd->window[plane].winctrl1 = val;
1328 }
1329 if (pdata->flags & WIN_COLOR_ORDER) {
1330 val = lcd->window[plane].winctrl1 & ~(LCD_WINCTRL1_CCO);
1331 val |= ((pdata->color_order << 24) & LCD_WINCTRL1_CCO);
1332 lcd->window[plane].winctrl1 = val;
1333 }
1334 if (pdata->flags & WIN_PIXEL_ORDER) {
1335 val = lcd->window[plane].winctrl1 & ~(LCD_WINCTRL1_PO);
1336 val |= ((pdata->pixel_order << 22) & LCD_WINCTRL1_PO);
1337 lcd->window[plane].winctrl1 = val;
1338 }
1339 if (pdata->flags & WIN_SIZE) {
1340 val = lcd->window[plane].winctrl1 & ~(LCD_WINCTRL1_SZX |
1341 LCD_WINCTRL1_SZY);
1342 val |= (((pdata->xsize << 11) - 1) & LCD_WINCTRL1_SZX);
1343 val |= (((pdata->ysize) - 1) & LCD_WINCTRL1_SZY);
1344 lcd->window[plane].winctrl1 = val;
1345 /* program buffer line width */
1346 bpp = winbpp(val) / 8;
1347 val = lcd->window[plane].winctrl2 & ~(LCD_WINCTRL2_BX);
1348 val |= (((pdata->xsize * bpp) << 8) & LCD_WINCTRL2_BX);
1349 lcd->window[plane].winctrl2 = val;
1350 }
1351
1352 /* Window control register 2 */
1353 if (pdata->flags & WIN_COLORKEY_MODE) {
1354 val = lcd->window[plane].winctrl2 & ~(LCD_WINCTRL2_CKMODE);
1355 val |= ((pdata->colorkey_mode << 24) & LCD_WINCTRL2_CKMODE);
1356 lcd->window[plane].winctrl2 = val;
1357 }
1358 if (pdata->flags & WIN_DOUBLE_BUFFER_MODE) {
1359 val = lcd->window[plane].winctrl2 & ~(LCD_WINCTRL2_DBM);
1360 val |= ((pdata->double_buffer_mode << 23) & LCD_WINCTRL2_DBM);
1361 lcd->window[plane].winctrl2 = val;
1362 }
1363 if (pdata->flags & WIN_RAM_ARRAY_MODE) {
1364 val = lcd->window[plane].winctrl2 & ~(LCD_WINCTRL2_RAM);
1365 val |= ((pdata->ram_array_mode << 21) & LCD_WINCTRL2_RAM);
1366 lcd->window[plane].winctrl2 = val;
1367 }
1368
1369 /* Buffer line width programmed with WIN_SIZE */
1370
1371 if (pdata->flags & WIN_BUFFER_SCALE) {
1372 val = lcd->window[plane].winctrl2 & ~(LCD_WINCTRL2_SCX |
1373 LCD_WINCTRL2_SCY);
1374 val |= ((pdata->xsize << 11) & LCD_WINCTRL2_SCX);
1375 val |= ((pdata->ysize) & LCD_WINCTRL2_SCY);
1376 lcd->window[plane].winctrl2 = val;
1377 }
1378
1379 if (pdata->flags & WIN_ENABLE) {
1380 val = lcd->winenable;
1381 val &= ~(1<<plane);
1382 val |= (pdata->enable & 1) << plane;
1383 lcd->winenable = val;
1384 }
1385 wmb(); /* drain writebuffer */
1386}
1387
1388static void get_window(unsigned int plane,
1389 struct au1200_lcd_window_regs_t *pdata)
1390{
1391 /* Window control register 0 */
1392 pdata->xpos = (lcd->window[plane].winctrl0 & LCD_WINCTRL0_OX) >> 21;
1393 pdata->ypos = (lcd->window[plane].winctrl0 & LCD_WINCTRL0_OY) >> 10;
1394 pdata->alpha_color = (lcd->window[plane].winctrl0 & LCD_WINCTRL0_A) >> 2;
1395 pdata->alpha_mode = (lcd->window[plane].winctrl0 & LCD_WINCTRL0_AEN) >> 1;
1396
1397 /* Window control register 1 */
1398 pdata->priority = (lcd->window[plane].winctrl1& LCD_WINCTRL1_PRI) >> 30;
1399 pdata->channel = (lcd->window[plane].winctrl1 & LCD_WINCTRL1_PIPE) >> 29;
1400 pdata->buffer_format = (lcd->window[plane].winctrl1 & LCD_WINCTRL1_FRM) >> 25;
1401 pdata->color_order = (lcd->window[plane].winctrl1 & LCD_WINCTRL1_CCO) >> 24;
1402 pdata->pixel_order = (lcd->window[plane].winctrl1 & LCD_WINCTRL1_PO) >> 22;
1403 pdata->xsize = ((lcd->window[plane].winctrl1 & LCD_WINCTRL1_SZX) >> 11) + 1;
1404 pdata->ysize = (lcd->window[plane].winctrl1 & LCD_WINCTRL1_SZY) + 1;
1405
1406 /* Window control register 2 */
1407 pdata->colorkey_mode = (lcd->window[plane].winctrl2 & LCD_WINCTRL2_CKMODE) >> 24;
1408 pdata->double_buffer_mode = (lcd->window[plane].winctrl2 & LCD_WINCTRL2_DBM) >> 23;
1409 pdata->ram_array_mode = (lcd->window[plane].winctrl2 & LCD_WINCTRL2_RAM) >> 21;
1410
1411 pdata->enable = (lcd->winenable >> plane) & 1;
1412 wmb(); /* drain writebuffer */
1413}
1414
1415static int au1200fb_ioctl(struct fb_info *info, unsigned int cmd,
1416 unsigned long arg)
1417{
1418 struct au1200fb_device *fbdev = info->par;
1419 int plane;
1420 int val;
1421
1422 plane = fbinfo2index(info);
1423 print_dbg("au1200fb: ioctl %d on plane %d\n", cmd, plane);
1424
1425 if (cmd == AU1200_LCD_FB_IOCTL) {
1426 struct au1200_lcd_iodata_t iodata;
1427
1428 if (copy_from_user(&iodata, (void __user *) arg, sizeof(iodata)))
1429 return -EFAULT;
1430
1431 print_dbg("FB IOCTL called\n");
1432
1433 switch (iodata.subcmd) {
1434 case AU1200_LCD_SET_SCREEN:
1435 print_dbg("AU1200_LCD_SET_SCREEN\n");
1436 set_global(cmd, &iodata.global);
1437 break;
1438
1439 case AU1200_LCD_GET_SCREEN:
1440 print_dbg("AU1200_LCD_GET_SCREEN\n");
1441 get_global(cmd, &iodata.global);
1442 break;
1443
1444 case AU1200_LCD_SET_WINDOW:
1445 print_dbg("AU1200_LCD_SET_WINDOW\n");
1446 set_window(plane, &iodata.window);
1447 break;
1448
1449 case AU1200_LCD_GET_WINDOW:
1450 print_dbg("AU1200_LCD_GET_WINDOW\n");
1451 get_window(plane, &iodata.window);
1452 break;
1453
1454 case AU1200_LCD_SET_PANEL:
1455 print_dbg("AU1200_LCD_SET_PANEL\n");
1456 if ((iodata.global.panel_choice >= 0) &&
1457 (iodata.global.panel_choice <
1458 NUM_PANELS))
1459 {
1460 struct panel_settings *newpanel;
1461 panel_index = iodata.global.panel_choice;
1462 newpanel = &known_lcd_panels[panel_index];
1463 au1200_setpanel(newpanel, fbdev->pd);
1464 }
1465 break;
1466
1467 case AU1200_LCD_GET_PANEL:
1468 print_dbg("AU1200_LCD_GET_PANEL\n");
1469 iodata.global.panel_choice = panel_index;
1470 break;
1471
1472 default:
1473 return -EINVAL;
1474 }
1475
1476 val = copy_to_user((void __user *) arg, &iodata, sizeof(iodata));
1477 if (val) {
1478 print_dbg("error: could not copy %d bytes\n", val);
1479 return -EFAULT;
1480 }
1481 }
1482
1483 return 0;
1484}
1485
1486
1487static struct fb_ops au1200fb_fb_ops = {
1488 .owner = THIS_MODULE,
1489 .fb_check_var = au1200fb_fb_check_var,
1490 .fb_set_par = au1200fb_fb_set_par,
1491 .fb_setcolreg = au1200fb_fb_setcolreg,
1492 .fb_blank = au1200fb_fb_blank,
1493 .fb_fillrect = sys_fillrect,
1494 .fb_copyarea = sys_copyarea,
1495 .fb_imageblit = sys_imageblit,
1496 .fb_read = fb_sys_read,
1497 .fb_write = fb_sys_write,
1498 .fb_sync = NULL,
1499 .fb_ioctl = au1200fb_ioctl,
1500 .fb_mmap = au1200fb_fb_mmap,
1501};
1502
1503/*-------------------------------------------------------------------------*/
1504
1505static irqreturn_t au1200fb_handle_irq(int irq, void* dev_id)
1506{
1507 /* Nothing to do for now, just clear any pending interrupt */
1508 lcd->intstatus = lcd->intstatus;
1509 wmb(); /* drain writebuffer */
1510
1511 return IRQ_HANDLED;
1512}
1513
1514/*-------------------------------------------------------------------------*/
1515
1516/* AU1200 LCD device probe helpers */
1517
1518static int au1200fb_init_fbinfo(struct au1200fb_device *fbdev)
1519{
1520 struct fb_info *fbi = fbdev->fb_info;
1521 int bpp;
1522
1523 fbi->fbops = &au1200fb_fb_ops;
1524
1525 bpp = winbpp(win->w[fbdev->plane].mode_winctrl1);
1526
1527 /* Copy monitor specs from panel data */
1528 /* fixme: we're setting up LCD controller windows, so these dont give a
1529 damn as to what the monitor specs are (the panel itself does, but that
1530 isn't done here...so maybe need a generic catchall monitor setting??? */
1531 memcpy(&fbi->monspecs, &panel->monspecs, sizeof(struct fb_monspecs));
1532
1533 /* We first try the user mode passed in argument. If that failed,
1534 * or if no one has been specified, we default to the first mode of the
1535 * panel list. Note that after this call, var data will be set */
1536 if (!fb_find_mode(&fbi->var,
1537 fbi,
1538 NULL, /* drv_info.opt_mode, */
1539 fbi->monspecs.modedb,
1540 fbi->monspecs.modedb_len,
1541 fbi->monspecs.modedb,
1542 bpp)) {
1543
1544 print_err("Cannot find valid mode for panel %s", panel->name);
1545 return -EFAULT;
1546 }
1547
1548 fbi->pseudo_palette = kcalloc(16, sizeof(u32), GFP_KERNEL);
1549 if (!fbi->pseudo_palette) {
1550 return -ENOMEM;
1551 }
1552
1553 if (fb_alloc_cmap(&fbi->cmap, AU1200_LCD_NBR_PALETTE_ENTRIES, 0) < 0) {
1554 print_err("Fail to allocate colormap (%d entries)",
1555 AU1200_LCD_NBR_PALETTE_ENTRIES);
1556 kfree(fbi->pseudo_palette);
1557 return -EFAULT;
1558 }
1559
1560 strncpy(fbi->fix.id, "AU1200", sizeof(fbi->fix.id));
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->screen_base = (char __iomem *) fbdev->fb_mem;
1571
1572 au1200fb_update_fbinfo(fbi);
1573
1574 return 0;
1575}
1576
1577/*-------------------------------------------------------------------------*/
1578
1579
1580static int au1200fb_setup(struct au1200fb_platdata *pd)
1581{
1582 char *options = NULL;
1583 char *this_opt, *endptr;
1584 int num_panels = ARRAY_SIZE(known_lcd_panels);
1585 int panel_idx = -1;
1586
1587 fb_get_options(DRIVER_NAME, &options);
1588
1589 if (!options)
1590 goto out;
1591
1592 while ((this_opt = strsep(&options, ",")) != NULL) {
1593 /* Panel option - can be panel name,
1594 * "bs" for board-switch, or number/index */
1595 if (!strncmp(this_opt, "panel:", 6)) {
1596 int i;
1597 long int li;
1598 char *endptr;
1599 this_opt += 6;
1600 /* First check for index, which allows
1601 * to short circuit this mess */
1602 li = simple_strtol(this_opt, &endptr, 0);
1603 if (*endptr == '\0')
1604 panel_idx = (int)li;
1605 else if (strcmp(this_opt, "bs") == 0)
1606 panel_idx = pd->panel_index();
1607 else {
1608 for (i = 0; i < num_panels; i++) {
1609 if (!strcmp(this_opt,
1610 known_lcd_panels[i].name)) {
1611 panel_idx = i;
1612 break;
1613 }
1614 }
1615 }
1616 if ((panel_idx < 0) || (panel_idx >= num_panels))
1617 print_warn("Panel %s not supported!", this_opt);
1618 else
1619 panel_index = panel_idx;
1620
1621 } else if (strncmp(this_opt, "nohwcursor", 10) == 0)
1622 nohwcursor = 1;
1623 else if (strncmp(this_opt, "devices:", 8) == 0) {
1624 this_opt += 8;
1625 device_count = simple_strtol(this_opt, &endptr, 0);
1626 if ((device_count < 0) ||
1627 (device_count > MAX_DEVICE_COUNT))
1628 device_count = MAX_DEVICE_COUNT;
1629 } else if (strncmp(this_opt, "wincfg:", 7) == 0) {
1630 this_opt += 7;
1631 window_index = simple_strtol(this_opt, &endptr, 0);
1632 if ((window_index < 0) ||
1633 (window_index >= ARRAY_SIZE(windows)))
1634 window_index = DEFAULT_WINDOW_INDEX;
1635 } else if (strncmp(this_opt, "off", 3) == 0)
1636 return 1;
1637 else
1638 print_warn("Unsupported option \"%s\"", this_opt);
1639 }
1640
1641out:
1642 return 0;
1643}
1644
1645/* AU1200 LCD controller device driver */
1646static int au1200fb_drv_probe(struct platform_device *dev)
1647{
1648 struct au1200fb_device *fbdev;
1649 struct au1200fb_platdata *pd;
1650 struct fb_info *fbi = NULL;
1651 unsigned long page;
1652 int bpp, plane, ret, irq;
1653
1654 print_info("" DRIVER_DESC "");
1655
1656 pd = dev->dev.platform_data;
1657 if (!pd)
1658 return -ENODEV;
1659
1660 /* Setup driver with options */
1661 if (au1200fb_setup(pd))
1662 return -ENODEV;
1663
1664 /* Point to the panel selected */
1665 panel = &known_lcd_panels[panel_index];
1666 win = &windows[window_index];
1667
1668 printk(DRIVER_NAME ": Panel %d %s\n", panel_index, panel->name);
1669 printk(DRIVER_NAME ": Win %d %s\n", window_index, win->name);
1670
1671 /* shut gcc up */
1672 ret = 0;
1673 fbdev = NULL;
1674
1675 for (plane = 0; plane < device_count; ++plane) {
1676 bpp = winbpp(win->w[plane].mode_winctrl1);
1677 if (win->w[plane].xres == 0)
1678 win->w[plane].xres = panel->Xres;
1679 if (win->w[plane].yres == 0)
1680 win->w[plane].yres = panel->Yres;
1681
1682 fbi = framebuffer_alloc(sizeof(struct au1200fb_device),
1683 &dev->dev);
1684 if (!fbi)
1685 goto failed;
1686
1687 _au1200fb_infos[plane] = fbi;
1688 fbdev = fbi->par;
1689 fbdev->fb_info = fbi;
1690 fbdev->pd = pd;
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_noncoherent(&dev->dev,
1698 PAGE_ALIGN(fbdev->fb_len),
1699 &fbdev->fb_phys, GFP_KERNEL);
1700 if (!fbdev->fb_mem) {
1701 print_err("fail to allocate frambuffer (size: %dK))",
1702 fbdev->fb_len / 1024);
1703 return -ENOMEM;
1704 }
1705
1706 /*
1707 * Set page reserved so that mmap will work. This is necessary
1708 * since we'll be remapping normal memory.
1709 */
1710 for (page = (unsigned long)fbdev->fb_phys;
1711 page < PAGE_ALIGN((unsigned long)fbdev->fb_phys +
1712 fbdev->fb_len);
1713 page += PAGE_SIZE) {
1714 SetPageReserved(pfn_to_page(page >> PAGE_SHIFT)); /* LCD DMA is NOT coherent on Au1200 */
1715 }
1716 print_dbg("Framebuffer memory map at %p", fbdev->fb_mem);
1717 print_dbg("phys=0x%08x, size=%dK", fbdev->fb_phys, fbdev->fb_len / 1024);
1718
1719 /* Init FB data */
1720 if ((ret = au1200fb_init_fbinfo(fbdev)) < 0)
1721 goto failed;
1722
1723 /* Register new framebuffer */
1724 ret = register_framebuffer(fbi);
1725 if (ret < 0) {
1726 print_err("cannot register new framebuffer");
1727 goto failed;
1728 }
1729
1730 au1200fb_fb_set_par(fbi);
1731
1732#if !defined(CONFIG_FRAMEBUFFER_CONSOLE) && defined(CONFIG_LOGO)
1733 if (plane == 0)
1734 if (fb_prepare_logo(fbi, FB_ROTATE_UR)) {
1735 /* Start display and show logo on boot */
1736 fb_set_cmap(&fbi->cmap, fbi);
1737 fb_show_logo(fbi, FB_ROTATE_UR);
1738 }
1739#endif
1740 }
1741
1742 /* Now hook interrupt too */
1743 irq = platform_get_irq(dev, 0);
1744 ret = request_irq(irq, au1200fb_handle_irq,
1745 IRQF_SHARED, "lcd", (void *)dev);
1746 if (ret) {
1747 print_err("fail to request interrupt line %d (err: %d)",
1748 irq, ret);
1749 goto failed;
1750 }
1751
1752 platform_set_drvdata(dev, pd);
1753
1754 /* Kickstart the panel */
1755 au1200_setpanel(panel, pd);
1756
1757 return 0;
1758
1759failed:
1760 /* NOTE: This only does the current plane/window that failed; others are still active */
1761 if (fbi) {
1762 if (fbi->cmap.len != 0)
1763 fb_dealloc_cmap(&fbi->cmap);
1764 kfree(fbi->pseudo_palette);
1765 }
1766 if (plane == 0)
1767 free_irq(AU1200_LCD_INT, (void*)dev);
1768 return ret;
1769}
1770
1771static int au1200fb_drv_remove(struct platform_device *dev)
1772{
1773 struct au1200fb_platdata *pd = platform_get_drvdata(dev);
1774 struct au1200fb_device *fbdev;
1775 struct fb_info *fbi;
1776 int plane;
1777
1778 /* Turn off the panel */
1779 au1200_setpanel(NULL, pd);
1780
1781 for (plane = 0; plane < device_count; ++plane) {
1782 fbi = _au1200fb_infos[plane];
1783 fbdev = fbi->par;
1784
1785 /* Clean up all probe data */
1786 unregister_framebuffer(fbi);
1787 if (fbi->cmap.len != 0)
1788 fb_dealloc_cmap(&fbi->cmap);
1789 kfree(fbi->pseudo_palette);
1790
1791 framebuffer_release(fbi);
1792 _au1200fb_infos[plane] = NULL;
1793 }
1794
1795 free_irq(platform_get_irq(dev, 0), (void *)dev);
1796
1797 return 0;
1798}
1799
1800#ifdef CONFIG_PM
1801static int au1200fb_drv_suspend(struct device *dev)
1802{
1803 struct au1200fb_platdata *pd = dev_get_drvdata(dev);
1804 au1200_setpanel(NULL, pd);
1805
1806 lcd->outmask = 0;
1807 wmb(); /* drain writebuffer */
1808
1809 return 0;
1810}
1811
1812static int au1200fb_drv_resume(struct device *dev)
1813{
1814 struct au1200fb_platdata *pd = dev_get_drvdata(dev);
1815 struct fb_info *fbi;
1816 int i;
1817
1818 /* Kickstart the panel */
1819 au1200_setpanel(panel, pd);
1820
1821 for (i = 0; i < device_count; i++) {
1822 fbi = _au1200fb_infos[i];
1823 au1200fb_fb_set_par(fbi);
1824 }
1825
1826 return 0;
1827}
1828
1829static const struct dev_pm_ops au1200fb_pmops = {
1830 .suspend = au1200fb_drv_suspend,
1831 .resume = au1200fb_drv_resume,
1832 .freeze = au1200fb_drv_suspend,
1833 .thaw = au1200fb_drv_resume,
1834};
1835
1836#define AU1200FB_PMOPS (&au1200fb_pmops)
1837
1838#else
1839#define AU1200FB_PMOPS NULL
1840#endif /* CONFIG_PM */
1841
1842static struct platform_driver au1200fb_driver = {
1843 .driver = {
1844 .name = "au1200-lcd",
1845 .owner = THIS_MODULE,
1846 .pm = AU1200FB_PMOPS,
1847 },
1848 .probe = au1200fb_drv_probe,
1849 .remove = au1200fb_drv_remove,
1850};
1851module_platform_driver(au1200fb_driver);
1852
1853MODULE_DESCRIPTION(DRIVER_DESC);
1854MODULE_LICENSE("GPL");