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