blob: 6c4342f1d9b4e0f5a38f9ae69b0d638f37db8416 [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 },
Manuel Lauss64cd04d2011-11-10 12:03:26 +0000642 [9] = {
643 .name = "DB1300_800x480",
644 .monspecs = {
645 .modedb = NULL,
646 .modedb_len = 0,
647 .hfmin = 30000,
648 .hfmax = 70000,
649 .vfmin = 60,
650 .vfmax = 60,
651 .dclkmin = 6000000,
652 .dclkmax = 28000000,
653 .input = FB_DISP_RGB,
654 },
655 .mode_screen = LCD_SCREEN_SX_N(800) |
656 LCD_SCREEN_SY_N(480),
657 .mode_horztiming = LCD_HORZTIMING_HPW_N(5) |
658 LCD_HORZTIMING_HND1_N(16) |
659 LCD_HORZTIMING_HND2_N(8),
660 .mode_verttiming = LCD_VERTTIMING_VPW_N(4) |
661 LCD_VERTTIMING_VND1_N(8) |
662 LCD_VERTTIMING_VND2_N(5),
663 .mode_clkcontrol = LCD_CLKCONTROL_PCD_N(1) |
664 LCD_CLKCONTROL_IV |
665 LCD_CLKCONTROL_IH,
666 .mode_pwmdiv = 0x00000000,
667 .mode_pwmhi = 0x00000000,
668 .mode_outmask = 0x00FFFFFF,
669 .mode_fifoctrl = 0x2f2f2f2f,
670 .mode_toyclksrc = 0x00000004, /* AUXPLL directly */
671 .mode_backlight = 0x00000000,
672 .mode_auxpll = (48/12) * 2,
673 .device_init = board_au1200fb_panel_init,
674 .device_shutdown = board_au1200fb_panel_shutdown,
675 800, 800,
676 480, 480,
677 },
Ralf Baechlef95ec3c2006-03-27 01:17:27 -0800678};
679
680#define NUM_PANELS (ARRAY_SIZE(known_lcd_panels))
681
682/********************************************************************/
683
Ralf Baechlef95ec3c2006-03-27 01:17:27 -0800684static int winbpp (unsigned int winctrl1)
685{
686 int bits = 0;
687
688 /* how many bits are needed for each pixel format */
689 switch (winctrl1 & LCD_WINCTRL1_FRM) {
690 case LCD_WINCTRL1_FRM_1BPP:
691 bits = 1;
692 break;
693 case LCD_WINCTRL1_FRM_2BPP:
694 bits = 2;
695 break;
696 case LCD_WINCTRL1_FRM_4BPP:
697 bits = 4;
698 break;
699 case LCD_WINCTRL1_FRM_8BPP:
700 bits = 8;
701 break;
702 case LCD_WINCTRL1_FRM_12BPP:
703 case LCD_WINCTRL1_FRM_16BPP655:
704 case LCD_WINCTRL1_FRM_16BPP565:
705 case LCD_WINCTRL1_FRM_16BPP556:
706 case LCD_WINCTRL1_FRM_16BPPI1555:
707 case LCD_WINCTRL1_FRM_16BPPI5551:
708 case LCD_WINCTRL1_FRM_16BPPA1555:
709 case LCD_WINCTRL1_FRM_16BPPA5551:
710 bits = 16;
711 break;
712 case LCD_WINCTRL1_FRM_24BPP:
713 case LCD_WINCTRL1_FRM_32BPP:
714 bits = 32;
715 break;
716 }
717
718 return bits;
719}
720
721static int fbinfo2index (struct fb_info *fb_info)
722{
723 int i;
724
Manuel Lauss8be90b02011-06-10 15:23:03 +0000725 for (i = 0; i < device_count; ++i) {
Manuel Laussc329f602011-06-10 15:23:01 +0000726 if (fb_info == _au1200fb_infos[i])
Ralf Baechlef95ec3c2006-03-27 01:17:27 -0800727 return i;
728 }
729 printk("au1200fb: ERROR: fbinfo2index failed!\n");
730 return -1;
731}
732
733static int au1200_setlocation (struct au1200fb_device *fbdev, int plane,
734 int xpos, int ypos)
735{
736 uint32 winctrl0, winctrl1, winenable, fb_offset = 0;
737 int xsz, ysz;
738
739 /* FIX!!! NOT CHECKING FOR COMPLETE OFFSCREEN YET */
740
741 winctrl0 = lcd->window[plane].winctrl0;
742 winctrl1 = lcd->window[plane].winctrl1;
743 winctrl0 &= (LCD_WINCTRL0_A | LCD_WINCTRL0_AEN);
744 winctrl1 &= ~(LCD_WINCTRL1_SZX | LCD_WINCTRL1_SZY);
745
746 /* Check for off-screen adjustments */
747 xsz = win->w[plane].xres;
748 ysz = win->w[plane].yres;
749 if ((xpos + win->w[plane].xres) > panel->Xres) {
750 /* Off-screen to the right */
751 xsz = panel->Xres - xpos; /* off by 1 ??? */
752 /*printk("off screen right\n");*/
753 }
754
755 if ((ypos + win->w[plane].yres) > panel->Yres) {
756 /* Off-screen to the bottom */
757 ysz = panel->Yres - ypos; /* off by 1 ??? */
758 /*printk("off screen bottom\n");*/
759 }
760
761 if (xpos < 0) {
762 /* Off-screen to the left */
763 xsz = win->w[plane].xres + xpos;
764 fb_offset += (((0 - xpos) * winbpp(lcd->window[plane].winctrl1))/8);
765 xpos = 0;
766 /*printk("off screen left\n");*/
767 }
768
769 if (ypos < 0) {
770 /* Off-screen to the top */
771 ysz = win->w[plane].yres + ypos;
772 /* fixme: fb_offset += ((0-ypos)*fb_pars[plane].line_length); */
773 ypos = 0;
774 /*printk("off screen top\n");*/
775 }
776
777 /* record settings */
778 win->w[plane].xpos = xpos;
779 win->w[plane].ypos = ypos;
780
781 xsz -= 1;
782 ysz -= 1;
783 winctrl0 |= (xpos << 21);
784 winctrl0 |= (ypos << 10);
785 winctrl1 |= (xsz << 11);
786 winctrl1 |= (ysz << 0);
787
788 /* Disable the window while making changes, then restore WINEN */
789 winenable = lcd->winenable & (1 << plane);
790 au_sync();
791 lcd->winenable &= ~(1 << plane);
792 lcd->window[plane].winctrl0 = winctrl0;
793 lcd->window[plane].winctrl1 = winctrl1;
794 lcd->window[plane].winbuf0 =
795 lcd->window[plane].winbuf1 = fbdev->fb_phys;
796 lcd->window[plane].winbufctrl = 0; /* select winbuf0 */
797 lcd->winenable |= winenable;
798 au_sync();
799
800 return 0;
801}
802
803static void au1200_setpanel (struct panel_settings *newpanel)
804{
805 /*
806 * Perform global setup/init of LCD controller
807 */
808 uint32 winenable;
809
810 /* Make sure all windows disabled */
811 winenable = lcd->winenable;
812 lcd->winenable = 0;
813 au_sync();
814 /*
815 * Ensure everything is disabled before reconfiguring
816 */
817 if (lcd->screen & LCD_SCREEN_SEN) {
818 /* Wait for vertical sync period */
819 lcd->intstatus = LCD_INT_SS;
820 while ((lcd->intstatus & LCD_INT_SS) == 0) {
821 au_sync();
822 }
823
824 lcd->screen &= ~LCD_SCREEN_SEN; /*disable the controller*/
825
826 do {
827 lcd->intstatus = lcd->intstatus; /*clear interrupts*/
828 au_sync();
829 /*wait for controller to shut down*/
830 } while ((lcd->intstatus & LCD_INT_SD) == 0);
831
832 /* Call shutdown of current panel (if up) */
833 /* this must occur last, because if an external clock is driving
834 the controller, the clock cannot be turned off before first
835 shutting down the controller.
836 */
837 if (panel->device_shutdown != NULL)
838 panel->device_shutdown();
839 }
840
841 /* Newpanel == NULL indicates a shutdown operation only */
842 if (newpanel == NULL)
843 return;
844
845 panel = newpanel;
846
847 printk("Panel(%s), %dx%d\n", panel->name, panel->Xres, panel->Yres);
848
849 /*
850 * Setup clocking if internal LCD clock source (assumes sys_auxpll valid)
851 */
852 if (!(panel->mode_clkcontrol & LCD_CLKCONTROL_EXT))
853 {
854 uint32 sys_clksrc;
855 au_writel(panel->mode_auxpll, SYS_AUXPLL);
856 sys_clksrc = au_readl(SYS_CLKSRC) & ~0x0000001f;
857 sys_clksrc |= panel->mode_toyclksrc;
858 au_writel(sys_clksrc, SYS_CLKSRC);
859 }
860
861 /*
862 * Configure panel timings
863 */
864 lcd->screen = panel->mode_screen;
865 lcd->horztiming = panel->mode_horztiming;
866 lcd->verttiming = panel->mode_verttiming;
867 lcd->clkcontrol = panel->mode_clkcontrol;
868 lcd->pwmdiv = panel->mode_pwmdiv;
869 lcd->pwmhi = panel->mode_pwmhi;
870 lcd->outmask = panel->mode_outmask;
871 lcd->fifoctrl = panel->mode_fifoctrl;
872 au_sync();
873
874 /* fixme: Check window settings to make sure still valid
875 * for new geometry */
876#if 0
877 au1200_setlocation(fbdev, 0, win->w[0].xpos, win->w[0].ypos);
878 au1200_setlocation(fbdev, 1, win->w[1].xpos, win->w[1].ypos);
879 au1200_setlocation(fbdev, 2, win->w[2].xpos, win->w[2].ypos);
880 au1200_setlocation(fbdev, 3, win->w[3].xpos, win->w[3].ypos);
881#endif
882 lcd->winenable = winenable;
883
884 /*
885 * Re-enable screen now that it is configured
886 */
887 lcd->screen |= LCD_SCREEN_SEN;
888 au_sync();
889
890 /* Call init of panel */
891 if (panel->device_init != NULL) panel->device_init();
892
893 /* FIX!!!! not appropriate on panel change!!! Global setup/init */
894 lcd->intenable = 0;
895 lcd->intstatus = ~0;
896 lcd->backcolor = win->mode_backcolor;
897
898 /* Setup Color Key - FIX!!! */
899 lcd->colorkey = win->mode_colorkey;
900 lcd->colorkeymsk = win->mode_colorkeymsk;
901
902 /* Setup HWCursor - FIX!!! Need to support this eventually */
903 lcd->hwc.cursorctrl = 0;
904 lcd->hwc.cursorpos = 0;
905 lcd->hwc.cursorcolor0 = 0;
906 lcd->hwc.cursorcolor1 = 0;
907 lcd->hwc.cursorcolor2 = 0;
908 lcd->hwc.cursorcolor3 = 0;
909
910
911#if 0
912#define D(X) printk("%25s: %08X\n", #X, X)
913 D(lcd->screen);
914 D(lcd->horztiming);
915 D(lcd->verttiming);
916 D(lcd->clkcontrol);
917 D(lcd->pwmdiv);
918 D(lcd->pwmhi);
919 D(lcd->outmask);
920 D(lcd->fifoctrl);
921 D(lcd->window[0].winctrl0);
922 D(lcd->window[0].winctrl1);
923 D(lcd->window[0].winctrl2);
924 D(lcd->window[0].winbuf0);
925 D(lcd->window[0].winbuf1);
926 D(lcd->window[0].winbufctrl);
927 D(lcd->window[1].winctrl0);
928 D(lcd->window[1].winctrl1);
929 D(lcd->window[1].winctrl2);
930 D(lcd->window[1].winbuf0);
931 D(lcd->window[1].winbuf1);
932 D(lcd->window[1].winbufctrl);
933 D(lcd->window[2].winctrl0);
934 D(lcd->window[2].winctrl1);
935 D(lcd->window[2].winctrl2);
936 D(lcd->window[2].winbuf0);
937 D(lcd->window[2].winbuf1);
938 D(lcd->window[2].winbufctrl);
939 D(lcd->window[3].winctrl0);
940 D(lcd->window[3].winctrl1);
941 D(lcd->window[3].winctrl2);
942 D(lcd->window[3].winbuf0);
943 D(lcd->window[3].winbuf1);
944 D(lcd->window[3].winbufctrl);
945 D(lcd->winenable);
946 D(lcd->intenable);
947 D(lcd->intstatus);
948 D(lcd->backcolor);
949 D(lcd->winenable);
950 D(lcd->colorkey);
951 D(lcd->colorkeymsk);
952 D(lcd->hwc.cursorctrl);
953 D(lcd->hwc.cursorpos);
954 D(lcd->hwc.cursorcolor0);
955 D(lcd->hwc.cursorcolor1);
956 D(lcd->hwc.cursorcolor2);
957 D(lcd->hwc.cursorcolor3);
958#endif
959}
960
961static void au1200_setmode(struct au1200fb_device *fbdev)
962{
963 int plane = fbdev->plane;
964 /* Window/plane setup */
965 lcd->window[plane].winctrl1 = ( 0
966 | LCD_WINCTRL1_PRI_N(plane)
967 | win->w[plane].mode_winctrl1 /* FRM,CCO,PO,PIPE */
968 ) ;
969
970 au1200_setlocation(fbdev, plane, win->w[plane].xpos, win->w[plane].ypos);
971
972 lcd->window[plane].winctrl2 = ( 0
973 | LCD_WINCTRL2_CKMODE_00
974 | LCD_WINCTRL2_DBM
Manuel Laussc329f602011-06-10 15:23:01 +0000975 | LCD_WINCTRL2_BX_N(fbdev->fb_info->fix.line_length)
Ralf Baechlef95ec3c2006-03-27 01:17:27 -0800976 | LCD_WINCTRL2_SCX_1
977 | LCD_WINCTRL2_SCY_1
978 ) ;
979 lcd->winenable |= win->w[plane].mode_winenable;
980 au_sync();
981}
982
983
984/* Inline helpers */
985
986/*#define panel_is_dual(panel) ((panel->mode_screen & LCD_SCREEN_PT) == LCD_SCREEN_PT_010)*/
987/*#define panel_is_active(panel)((panel->mode_screen & LCD_SCREEN_PT) == LCD_SCREEN_PT_010)*/
988
989#define panel_is_color(panel) ((panel->mode_screen & LCD_SCREEN_PT) <= LCD_SCREEN_PT_CDSTN)
990
991/* Bitfields format supported by the controller. */
992static struct fb_bitfield rgb_bitfields[][4] = {
993 /* Red, Green, Blue, Transp */
994 [LCD_WINCTRL1_FRM_16BPP655 >> 25] =
995 { { 10, 6, 0 }, { 5, 5, 0 }, { 0, 5, 0 }, { 0, 0, 0 } },
996
997 [LCD_WINCTRL1_FRM_16BPP565 >> 25] =
998 { { 11, 5, 0 }, { 5, 6, 0 }, { 0, 5, 0 }, { 0, 0, 0 } },
999
1000 [LCD_WINCTRL1_FRM_16BPP556 >> 25] =
1001 { { 11, 5, 0 }, { 6, 5, 0 }, { 0, 6, 0 }, { 0, 0, 0 } },
1002
1003 [LCD_WINCTRL1_FRM_16BPPI1555 >> 25] =
1004 { { 10, 5, 0 }, { 5, 5, 0 }, { 0, 5, 0 }, { 0, 0, 0 } },
1005
1006 [LCD_WINCTRL1_FRM_16BPPI5551 >> 25] =
1007 { { 11, 5, 0 }, { 6, 5, 0 }, { 1, 5, 0 }, { 0, 0, 0 } },
1008
1009 [LCD_WINCTRL1_FRM_16BPPA1555 >> 25] =
1010 { { 10, 5, 0 }, { 5, 5, 0 }, { 0, 5, 0 }, { 15, 1, 0 } },
1011
1012 [LCD_WINCTRL1_FRM_16BPPA5551 >> 25] =
1013 { { 11, 5, 0 }, { 6, 5, 0 }, { 1, 5, 0 }, { 0, 1, 0 } },
1014
1015 [LCD_WINCTRL1_FRM_24BPP >> 25] =
1016 { { 16, 8, 0 }, { 8, 8, 0 }, { 0, 8, 0 }, { 0, 0, 0 } },
1017
1018 [LCD_WINCTRL1_FRM_32BPP >> 25] =
1019 { { 16, 8, 0 }, { 8, 8, 0 }, { 0, 8, 0 }, { 24, 0, 0 } },
1020};
1021
1022/*-------------------------------------------------------------------------*/
1023
1024/* Helpers */
1025
1026static void au1200fb_update_fbinfo(struct fb_info *fbi)
1027{
1028 /* FIX!!!! This also needs to take the window pixel format into account!!! */
1029
1030 /* Update var-dependent FB info */
1031 if (panel_is_color(panel)) {
1032 if (fbi->var.bits_per_pixel <= 8) {
1033 /* palettized */
1034 fbi->fix.visual = FB_VISUAL_PSEUDOCOLOR;
1035 fbi->fix.line_length = fbi->var.xres_virtual /
1036 (8/fbi->var.bits_per_pixel);
1037 } else {
1038 /* non-palettized */
1039 fbi->fix.visual = FB_VISUAL_TRUECOLOR;
1040 fbi->fix.line_length = fbi->var.xres_virtual * (fbi->var.bits_per_pixel / 8);
1041 }
1042 } else {
1043 /* mono FIX!!! mono 8 and 4 bits */
1044 fbi->fix.visual = FB_VISUAL_MONO10;
1045 fbi->fix.line_length = fbi->var.xres_virtual / 8;
1046 }
1047
1048 fbi->screen_size = fbi->fix.line_length * fbi->var.yres_virtual;
1049 print_dbg("line length: %d\n", fbi->fix.line_length);
1050 print_dbg("bits_per_pixel: %d\n", fbi->var.bits_per_pixel);
1051}
1052
1053/*-------------------------------------------------------------------------*/
1054
1055/* AU1200 framebuffer driver */
1056
1057/* fb_check_var
1058 * Validate var settings with hardware restrictions and modify it if necessary
1059 */
1060static int au1200fb_fb_check_var(struct fb_var_screeninfo *var,
1061 struct fb_info *fbi)
1062{
Manuel Laussc329f602011-06-10 15:23:01 +00001063 struct au1200fb_device *fbdev = fbi->par;
Ralf Baechlef95ec3c2006-03-27 01:17:27 -08001064 u32 pixclock;
1065 int screen_size, plane;
1066
1067 plane = fbdev->plane;
1068
1069 /* Make sure that the mode respect all LCD controller and
1070 * panel restrictions. */
1071 var->xres = win->w[plane].xres;
1072 var->yres = win->w[plane].yres;
1073
1074 /* No need for virtual resolution support */
1075 var->xres_virtual = var->xres;
1076 var->yres_virtual = var->yres;
1077
1078 var->bits_per_pixel = winbpp(win->w[plane].mode_winctrl1);
1079
1080 screen_size = var->xres_virtual * var->yres_virtual;
1081 if (var->bits_per_pixel > 8) screen_size *= (var->bits_per_pixel / 8);
1082 else screen_size /= (8/var->bits_per_pixel);
1083
1084 if (fbdev->fb_len < screen_size)
1085 return -EINVAL; /* Virtual screen is to big, abort */
1086
1087 /* FIX!!!! what are the implicaitons of ignoring this for windows ??? */
1088 /* The max LCD clock is fixed to 48MHz (value of AUX_CLK). The pixel
1089 * clock can only be obtain by dividing this value by an even integer.
1090 * Fallback to a slower pixel clock if necessary. */
1091 pixclock = max((u32)(PICOS2KHZ(var->pixclock) * 1000), fbi->monspecs.dclkmin);
Hagen Paul Pfeifer732eacc2010-10-26 14:22:23 -07001092 pixclock = min3(pixclock, fbi->monspecs.dclkmax, (u32)AU1200_LCD_MAX_CLK/2);
Ralf Baechlef95ec3c2006-03-27 01:17:27 -08001093
1094 if (AU1200_LCD_MAX_CLK % pixclock) {
1095 int diff = AU1200_LCD_MAX_CLK % pixclock;
1096 pixclock -= diff;
1097 }
1098
1099 var->pixclock = KHZ2PICOS(pixclock/1000);
1100#if 0
1101 if (!panel_is_active(panel)) {
1102 int pcd = AU1200_LCD_MAX_CLK / (pixclock * 2) - 1;
1103
1104 if (!panel_is_color(panel)
1105 && (panel->control_base & LCD_CONTROL_MPI) && (pcd < 3)) {
1106 /* STN 8bit mono panel support is up to 6MHz pixclock */
1107 var->pixclock = KHZ2PICOS(6000);
1108 } else if (!pcd) {
1109 /* Other STN panel support is up to 12MHz */
1110 var->pixclock = KHZ2PICOS(12000);
1111 }
1112 }
1113#endif
1114 /* Set bitfield accordingly */
1115 switch (var->bits_per_pixel) {
1116 case 16:
1117 {
1118 /* 16bpp True color.
1119 * These must be set to MATCH WINCTRL[FORM] */
1120 int idx;
1121 idx = (win->w[0].mode_winctrl1 & LCD_WINCTRL1_FRM) >> 25;
1122 var->red = rgb_bitfields[idx][0];
1123 var->green = rgb_bitfields[idx][1];
1124 var->blue = rgb_bitfields[idx][2];
1125 var->transp = rgb_bitfields[idx][3];
1126 break;
1127 }
1128
1129 case 32:
1130 {
1131 /* 32bpp True color.
1132 * These must be set to MATCH WINCTRL[FORM] */
1133 int idx;
1134 idx = (win->w[0].mode_winctrl1 & LCD_WINCTRL1_FRM) >> 25;
1135 var->red = rgb_bitfields[idx][0];
1136 var->green = rgb_bitfields[idx][1];
1137 var->blue = rgb_bitfields[idx][2];
1138 var->transp = rgb_bitfields[idx][3];
1139 break;
1140 }
1141 default:
1142 print_dbg("Unsupported depth %dbpp", var->bits_per_pixel);
1143 return -EINVAL;
1144 }
1145
1146 return 0;
1147}
1148
1149/* fb_set_par
1150 * Set hardware with var settings. This will enable the controller with a
1151 * specific mode, normally validated with the fb_check_var method
1152 */
1153static int au1200fb_fb_set_par(struct fb_info *fbi)
1154{
Manuel Laussc329f602011-06-10 15:23:01 +00001155 struct au1200fb_device *fbdev = fbi->par;
Ralf Baechlef95ec3c2006-03-27 01:17:27 -08001156
1157 au1200fb_update_fbinfo(fbi);
1158 au1200_setmode(fbdev);
1159
1160 return 0;
1161}
1162
1163/* fb_setcolreg
1164 * Set color in LCD palette.
1165 */
1166static int au1200fb_fb_setcolreg(unsigned regno, unsigned red, unsigned green,
1167 unsigned blue, unsigned transp, struct fb_info *fbi)
1168{
1169 volatile u32 *palette = lcd->palette;
1170 u32 value;
1171
1172 if (regno > (AU1200_LCD_NBR_PALETTE_ENTRIES - 1))
1173 return -EINVAL;
1174
1175 if (fbi->var.grayscale) {
1176 /* Convert color to grayscale */
1177 red = green = blue =
1178 (19595 * red + 38470 * green + 7471 * blue) >> 16;
1179 }
1180
1181 if (fbi->fix.visual == FB_VISUAL_TRUECOLOR) {
1182 /* Place color in the pseudopalette */
1183 if (regno > 16)
1184 return -EINVAL;
1185
1186 palette = (u32*) fbi->pseudo_palette;
1187
1188 red >>= (16 - fbi->var.red.length);
1189 green >>= (16 - fbi->var.green.length);
1190 blue >>= (16 - fbi->var.blue.length);
1191
1192 value = (red << fbi->var.red.offset) |
1193 (green << fbi->var.green.offset)|
1194 (blue << fbi->var.blue.offset);
1195 value &= 0xFFFF;
1196
1197 } else if (1 /*FIX!!! panel_is_active(fbdev->panel)*/) {
1198 /* COLOR TFT PALLETTIZED (use RGB 565) */
1199 value = (red & 0xF800)|((green >> 5) &
1200 0x07E0)|((blue >> 11) & 0x001F);
1201 value &= 0xFFFF;
1202
1203 } else if (0 /*panel_is_color(fbdev->panel)*/) {
1204 /* COLOR STN MODE */
1205 value = 0x1234;
1206 value &= 0xFFF;
1207 } else {
1208 /* MONOCHROME MODE */
1209 value = (green >> 12) & 0x000F;
1210 value &= 0xF;
1211 }
1212
1213 palette[regno] = value;
1214
1215 return 0;
1216}
1217
1218/* fb_blank
1219 * Blank the screen. Depending on the mode, the screen will be
1220 * activated with the backlight color, or desactivated
1221 */
1222static int au1200fb_fb_blank(int blank_mode, struct fb_info *fbi)
1223{
1224 /* Short-circuit screen blanking */
1225 if (noblanking)
1226 return 0;
1227
1228 switch (blank_mode) {
1229
1230 case FB_BLANK_UNBLANK:
1231 case FB_BLANK_NORMAL:
1232 /* printk("turn on panel\n"); */
1233 au1200_setpanel(panel);
1234 break;
1235 case FB_BLANK_VSYNC_SUSPEND:
1236 case FB_BLANK_HSYNC_SUSPEND:
1237 case FB_BLANK_POWERDOWN:
1238 /* printk("turn off panel\n"); */
1239 au1200_setpanel(NULL);
1240 break;
1241 default:
1242 break;
1243
1244 }
1245
1246 /* FB_BLANK_NORMAL is a soft blank */
1247 return (blank_mode == FB_BLANK_NORMAL) ? -EINVAL : 0;
1248}
1249
1250/* fb_mmap
1251 * Map video memory in user space. We don't use the generic fb_mmap
1252 * method mainly to allow the use of the TLB streaming flag (CCA=6)
1253 */
1254static int au1200fb_fb_mmap(struct fb_info *info, struct vm_area_struct *vma)
1255
1256{
1257 unsigned int len;
1258 unsigned long start=0, off;
Manuel Laussc329f602011-06-10 15:23:01 +00001259 struct au1200fb_device *fbdev = info->par;
Ralf Baechlef95ec3c2006-03-27 01:17:27 -08001260
Ralf Baechlef95ec3c2006-03-27 01:17:27 -08001261 if (vma->vm_pgoff > (~0UL >> PAGE_SHIFT)) {
1262 return -EINVAL;
1263 }
1264
1265 start = fbdev->fb_phys & PAGE_MASK;
1266 len = PAGE_ALIGN((start & ~PAGE_MASK) + fbdev->fb_len);
1267
1268 off = vma->vm_pgoff << PAGE_SHIFT;
1269
1270 if ((vma->vm_end - vma->vm_start + off) > len) {
1271 return -EINVAL;
1272 }
1273
1274 off += start;
1275 vma->vm_pgoff = off >> PAGE_SHIFT;
1276
1277 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
1278 pgprot_val(vma->vm_page_prot) |= _CACHE_MASK; /* CCA=7 */
1279
1280 vma->vm_flags |= VM_IO;
1281
1282 return io_remap_pfn_range(vma, vma->vm_start, off >> PAGE_SHIFT,
1283 vma->vm_end - vma->vm_start,
1284 vma->vm_page_prot);
1285
1286 return 0;
1287}
1288
1289static void set_global(u_int cmd, struct au1200_lcd_global_regs_t *pdata)
1290{
1291
1292 unsigned int hi1, divider;
1293
1294 /* SCREEN_SIZE: user cannot reset size, must switch panel choice */
1295
1296 if (pdata->flags & SCREEN_BACKCOLOR)
1297 lcd->backcolor = pdata->backcolor;
1298
1299 if (pdata->flags & SCREEN_BRIGHTNESS) {
1300
1301 // limit brightness pwm duty to >= 30/1600
1302 if (pdata->brightness < 30) {
1303 pdata->brightness = 30;
1304 }
1305 divider = (lcd->pwmdiv & 0x3FFFF) + 1;
1306 hi1 = (lcd->pwmhi >> 16) + 1;
1307 hi1 = (((pdata->brightness & 0xFF)+1) * divider >> 8);
1308 lcd->pwmhi &= 0xFFFF;
1309 lcd->pwmhi |= (hi1 << 16);
1310 }
1311
1312 if (pdata->flags & SCREEN_COLORKEY)
1313 lcd->colorkey = pdata->colorkey;
1314
1315 if (pdata->flags & SCREEN_MASK)
1316 lcd->colorkeymsk = pdata->mask;
1317 au_sync();
1318}
1319
1320static void get_global(u_int cmd, struct au1200_lcd_global_regs_t *pdata)
1321{
1322 unsigned int hi1, divider;
1323
1324 pdata->xsize = ((lcd->screen & LCD_SCREEN_SX) >> 19) + 1;
1325 pdata->ysize = ((lcd->screen & LCD_SCREEN_SY) >> 8) + 1;
1326
1327 pdata->backcolor = lcd->backcolor;
1328 pdata->colorkey = lcd->colorkey;
1329 pdata->mask = lcd->colorkeymsk;
1330
1331 // brightness
1332 hi1 = (lcd->pwmhi >> 16) + 1;
1333 divider = (lcd->pwmdiv & 0x3FFFF) + 1;
1334 pdata->brightness = ((hi1 << 8) / divider) - 1;
1335 au_sync();
1336}
1337
1338static void set_window(unsigned int plane,
1339 struct au1200_lcd_window_regs_t *pdata)
1340{
1341 unsigned int val, bpp;
1342
1343 /* Window control register 0 */
1344 if (pdata->flags & WIN_POSITION) {
1345 val = lcd->window[plane].winctrl0 & ~(LCD_WINCTRL0_OX |
1346 LCD_WINCTRL0_OY);
1347 val |= ((pdata->xpos << 21) & LCD_WINCTRL0_OX);
1348 val |= ((pdata->ypos << 10) & LCD_WINCTRL0_OY);
1349 lcd->window[plane].winctrl0 = val;
1350 }
1351 if (pdata->flags & WIN_ALPHA_COLOR) {
1352 val = lcd->window[plane].winctrl0 & ~(LCD_WINCTRL0_A);
1353 val |= ((pdata->alpha_color << 2) & LCD_WINCTRL0_A);
1354 lcd->window[plane].winctrl0 = val;
1355 }
1356 if (pdata->flags & WIN_ALPHA_MODE) {
1357 val = lcd->window[plane].winctrl0 & ~(LCD_WINCTRL0_AEN);
1358 val |= ((pdata->alpha_mode << 1) & LCD_WINCTRL0_AEN);
1359 lcd->window[plane].winctrl0 = val;
1360 }
1361
1362 /* Window control register 1 */
1363 if (pdata->flags & WIN_PRIORITY) {
1364 val = lcd->window[plane].winctrl1 & ~(LCD_WINCTRL1_PRI);
1365 val |= ((pdata->priority << 30) & LCD_WINCTRL1_PRI);
1366 lcd->window[plane].winctrl1 = val;
1367 }
1368 if (pdata->flags & WIN_CHANNEL) {
1369 val = lcd->window[plane].winctrl1 & ~(LCD_WINCTRL1_PIPE);
1370 val |= ((pdata->channel << 29) & LCD_WINCTRL1_PIPE);
1371 lcd->window[plane].winctrl1 = val;
1372 }
1373 if (pdata->flags & WIN_BUFFER_FORMAT) {
1374 val = lcd->window[plane].winctrl1 & ~(LCD_WINCTRL1_FRM);
1375 val |= ((pdata->buffer_format << 25) & LCD_WINCTRL1_FRM);
1376 lcd->window[plane].winctrl1 = val;
1377 }
1378 if (pdata->flags & WIN_COLOR_ORDER) {
1379 val = lcd->window[plane].winctrl1 & ~(LCD_WINCTRL1_CCO);
1380 val |= ((pdata->color_order << 24) & LCD_WINCTRL1_CCO);
1381 lcd->window[plane].winctrl1 = val;
1382 }
1383 if (pdata->flags & WIN_PIXEL_ORDER) {
1384 val = lcd->window[plane].winctrl1 & ~(LCD_WINCTRL1_PO);
1385 val |= ((pdata->pixel_order << 22) & LCD_WINCTRL1_PO);
1386 lcd->window[plane].winctrl1 = val;
1387 }
1388 if (pdata->flags & WIN_SIZE) {
1389 val = lcd->window[plane].winctrl1 & ~(LCD_WINCTRL1_SZX |
1390 LCD_WINCTRL1_SZY);
1391 val |= (((pdata->xsize << 11) - 1) & LCD_WINCTRL1_SZX);
1392 val |= (((pdata->ysize) - 1) & LCD_WINCTRL1_SZY);
1393 lcd->window[plane].winctrl1 = val;
1394 /* program buffer line width */
1395 bpp = winbpp(val) / 8;
1396 val = lcd->window[plane].winctrl2 & ~(LCD_WINCTRL2_BX);
1397 val |= (((pdata->xsize * bpp) << 8) & LCD_WINCTRL2_BX);
1398 lcd->window[plane].winctrl2 = val;
1399 }
1400
1401 /* Window control register 2 */
1402 if (pdata->flags & WIN_COLORKEY_MODE) {
1403 val = lcd->window[plane].winctrl2 & ~(LCD_WINCTRL2_CKMODE);
1404 val |= ((pdata->colorkey_mode << 24) & LCD_WINCTRL2_CKMODE);
1405 lcd->window[plane].winctrl2 = val;
1406 }
1407 if (pdata->flags & WIN_DOUBLE_BUFFER_MODE) {
1408 val = lcd->window[plane].winctrl2 & ~(LCD_WINCTRL2_DBM);
1409 val |= ((pdata->double_buffer_mode << 23) & LCD_WINCTRL2_DBM);
1410 lcd->window[plane].winctrl2 = val;
1411 }
1412 if (pdata->flags & WIN_RAM_ARRAY_MODE) {
1413 val = lcd->window[plane].winctrl2 & ~(LCD_WINCTRL2_RAM);
1414 val |= ((pdata->ram_array_mode << 21) & LCD_WINCTRL2_RAM);
1415 lcd->window[plane].winctrl2 = val;
1416 }
1417
1418 /* Buffer line width programmed with WIN_SIZE */
1419
1420 if (pdata->flags & WIN_BUFFER_SCALE) {
1421 val = lcd->window[plane].winctrl2 & ~(LCD_WINCTRL2_SCX |
1422 LCD_WINCTRL2_SCY);
1423 val |= ((pdata->xsize << 11) & LCD_WINCTRL2_SCX);
1424 val |= ((pdata->ysize) & LCD_WINCTRL2_SCY);
1425 lcd->window[plane].winctrl2 = val;
1426 }
1427
1428 if (pdata->flags & WIN_ENABLE) {
1429 val = lcd->winenable;
1430 val &= ~(1<<plane);
1431 val |= (pdata->enable & 1) << plane;
1432 lcd->winenable = val;
1433 }
1434 au_sync();
1435}
1436
1437static void get_window(unsigned int plane,
1438 struct au1200_lcd_window_regs_t *pdata)
1439{
1440 /* Window control register 0 */
1441 pdata->xpos = (lcd->window[plane].winctrl0 & LCD_WINCTRL0_OX) >> 21;
1442 pdata->ypos = (lcd->window[plane].winctrl0 & LCD_WINCTRL0_OY) >> 10;
1443 pdata->alpha_color = (lcd->window[plane].winctrl0 & LCD_WINCTRL0_A) >> 2;
1444 pdata->alpha_mode = (lcd->window[plane].winctrl0 & LCD_WINCTRL0_AEN) >> 1;
1445
1446 /* Window control register 1 */
1447 pdata->priority = (lcd->window[plane].winctrl1& LCD_WINCTRL1_PRI) >> 30;
1448 pdata->channel = (lcd->window[plane].winctrl1 & LCD_WINCTRL1_PIPE) >> 29;
1449 pdata->buffer_format = (lcd->window[plane].winctrl1 & LCD_WINCTRL1_FRM) >> 25;
1450 pdata->color_order = (lcd->window[plane].winctrl1 & LCD_WINCTRL1_CCO) >> 24;
1451 pdata->pixel_order = (lcd->window[plane].winctrl1 & LCD_WINCTRL1_PO) >> 22;
1452 pdata->xsize = ((lcd->window[plane].winctrl1 & LCD_WINCTRL1_SZX) >> 11) + 1;
1453 pdata->ysize = (lcd->window[plane].winctrl1 & LCD_WINCTRL1_SZY) + 1;
1454
1455 /* Window control register 2 */
1456 pdata->colorkey_mode = (lcd->window[plane].winctrl2 & LCD_WINCTRL2_CKMODE) >> 24;
1457 pdata->double_buffer_mode = (lcd->window[plane].winctrl2 & LCD_WINCTRL2_DBM) >> 23;
1458 pdata->ram_array_mode = (lcd->window[plane].winctrl2 & LCD_WINCTRL2_RAM) >> 21;
1459
1460 pdata->enable = (lcd->winenable >> plane) & 1;
1461 au_sync();
1462}
1463
1464static int au1200fb_ioctl(struct fb_info *info, unsigned int cmd,
1465 unsigned long arg)
1466{
1467 int plane;
1468 int val;
1469
Ralf Baechlef95ec3c2006-03-27 01:17:27 -08001470 plane = fbinfo2index(info);
1471 print_dbg("au1200fb: ioctl %d on plane %d\n", cmd, plane);
1472
1473 if (cmd == AU1200_LCD_FB_IOCTL) {
1474 struct au1200_lcd_iodata_t iodata;
1475
1476 if (copy_from_user(&iodata, (void __user *) arg, sizeof(iodata)))
1477 return -EFAULT;
1478
1479 print_dbg("FB IOCTL called\n");
1480
1481 switch (iodata.subcmd) {
1482 case AU1200_LCD_SET_SCREEN:
1483 print_dbg("AU1200_LCD_SET_SCREEN\n");
1484 set_global(cmd, &iodata.global);
1485 break;
1486
1487 case AU1200_LCD_GET_SCREEN:
1488 print_dbg("AU1200_LCD_GET_SCREEN\n");
1489 get_global(cmd, &iodata.global);
1490 break;
1491
1492 case AU1200_LCD_SET_WINDOW:
1493 print_dbg("AU1200_LCD_SET_WINDOW\n");
1494 set_window(plane, &iodata.window);
1495 break;
1496
1497 case AU1200_LCD_GET_WINDOW:
1498 print_dbg("AU1200_LCD_GET_WINDOW\n");
1499 get_window(plane, &iodata.window);
1500 break;
1501
1502 case AU1200_LCD_SET_PANEL:
1503 print_dbg("AU1200_LCD_SET_PANEL\n");
1504 if ((iodata.global.panel_choice >= 0) &&
1505 (iodata.global.panel_choice <
1506 NUM_PANELS))
1507 {
1508 struct panel_settings *newpanel;
1509 panel_index = iodata.global.panel_choice;
1510 newpanel = &known_lcd_panels[panel_index];
1511 au1200_setpanel(newpanel);
1512 }
1513 break;
1514
1515 case AU1200_LCD_GET_PANEL:
1516 print_dbg("AU1200_LCD_GET_PANEL\n");
1517 iodata.global.panel_choice = panel_index;
1518 break;
1519
1520 default:
1521 return -EINVAL;
1522 }
1523
1524 val = copy_to_user((void __user *) arg, &iodata, sizeof(iodata));
1525 if (val) {
1526 print_dbg("error: could not copy %d bytes\n", val);
1527 return -EFAULT;
1528 }
1529 }
1530
1531 return 0;
1532}
1533
1534
1535static struct fb_ops au1200fb_fb_ops = {
1536 .owner = THIS_MODULE,
1537 .fb_check_var = au1200fb_fb_check_var,
1538 .fb_set_par = au1200fb_fb_set_par,
1539 .fb_setcolreg = au1200fb_fb_setcolreg,
1540 .fb_blank = au1200fb_fb_blank,
Manuel Lauss4ee58462011-06-10 15:23:04 +00001541 .fb_fillrect = sys_fillrect,
1542 .fb_copyarea = sys_copyarea,
1543 .fb_imageblit = sys_imageblit,
1544 .fb_read = fb_sys_read,
1545 .fb_write = fb_sys_write,
Ralf Baechlef95ec3c2006-03-27 01:17:27 -08001546 .fb_sync = NULL,
1547 .fb_ioctl = au1200fb_ioctl,
1548 .fb_mmap = au1200fb_fb_mmap,
1549};
1550
1551/*-------------------------------------------------------------------------*/
1552
David Howells7d12e782006-10-05 14:55:46 +01001553static irqreturn_t au1200fb_handle_irq(int irq, void* dev_id)
Ralf Baechlef95ec3c2006-03-27 01:17:27 -08001554{
1555 /* Nothing to do for now, just clear any pending interrupt */
1556 lcd->intstatus = lcd->intstatus;
1557 au_sync();
1558
1559 return IRQ_HANDLED;
1560}
1561
1562/*-------------------------------------------------------------------------*/
1563
1564/* AU1200 LCD device probe helpers */
1565
1566static int au1200fb_init_fbinfo(struct au1200fb_device *fbdev)
1567{
Manuel Laussc329f602011-06-10 15:23:01 +00001568 struct fb_info *fbi = fbdev->fb_info;
Ralf Baechlef95ec3c2006-03-27 01:17:27 -08001569 int bpp;
1570
Ralf Baechlef95ec3c2006-03-27 01:17:27 -08001571 fbi->fbops = &au1200fb_fb_ops;
1572
1573 bpp = winbpp(win->w[fbdev->plane].mode_winctrl1);
1574
1575 /* Copy monitor specs from panel data */
1576 /* fixme: we're setting up LCD controller windows, so these dont give a
1577 damn as to what the monitor specs are (the panel itself does, but that
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001578 isn't done here...so maybe need a generic catchall monitor setting??? */
Ralf Baechlef95ec3c2006-03-27 01:17:27 -08001579 memcpy(&fbi->monspecs, &panel->monspecs, sizeof(struct fb_monspecs));
1580
1581 /* We first try the user mode passed in argument. If that failed,
1582 * or if no one has been specified, we default to the first mode of the
1583 * panel list. Note that after this call, var data will be set */
1584 if (!fb_find_mode(&fbi->var,
1585 fbi,
1586 NULL, /* drv_info.opt_mode, */
1587 fbi->monspecs.modedb,
1588 fbi->monspecs.modedb_len,
1589 fbi->monspecs.modedb,
1590 bpp)) {
1591
1592 print_err("Cannot find valid mode for panel %s", panel->name);
1593 return -EFAULT;
1594 }
1595
Yoann Padioleaudd00cc42007-07-19 01:49:03 -07001596 fbi->pseudo_palette = kcalloc(16, sizeof(u32), GFP_KERNEL);
Ralf Baechlef95ec3c2006-03-27 01:17:27 -08001597 if (!fbi->pseudo_palette) {
1598 return -ENOMEM;
1599 }
Ralf Baechlef95ec3c2006-03-27 01:17:27 -08001600
1601 if (fb_alloc_cmap(&fbi->cmap, AU1200_LCD_NBR_PALETTE_ENTRIES, 0) < 0) {
1602 print_err("Fail to allocate colormap (%d entries)",
1603 AU1200_LCD_NBR_PALETTE_ENTRIES);
1604 kfree(fbi->pseudo_palette);
1605 return -EFAULT;
1606 }
1607
1608 strncpy(fbi->fix.id, "AU1200", sizeof(fbi->fix.id));
1609 fbi->fix.smem_start = fbdev->fb_phys;
1610 fbi->fix.smem_len = fbdev->fb_len;
1611 fbi->fix.type = FB_TYPE_PACKED_PIXELS;
1612 fbi->fix.xpanstep = 0;
1613 fbi->fix.ypanstep = 0;
1614 fbi->fix.mmio_start = 0;
1615 fbi->fix.mmio_len = 0;
1616 fbi->fix.accel = FB_ACCEL_NONE;
1617
1618 fbi->screen_base = (char __iomem *) fbdev->fb_mem;
1619
1620 au1200fb_update_fbinfo(fbi);
1621
1622 return 0;
1623}
1624
1625/*-------------------------------------------------------------------------*/
1626
1627/* AU1200 LCD controller device driver */
1628
Manuel Lauss98707fc2011-06-10 15:23:02 +00001629static int __devinit au1200fb_drv_probe(struct platform_device *dev)
Ralf Baechlef95ec3c2006-03-27 01:17:27 -08001630{
1631 struct au1200fb_device *fbdev;
Manuel Laussc329f602011-06-10 15:23:01 +00001632 struct fb_info *fbi = NULL;
Ralf Baechlef95ec3c2006-03-27 01:17:27 -08001633 unsigned long page;
Manuel Lauss1630d852011-06-12 17:15:29 +00001634 int bpp, plane, ret, irq;
Ralf Baechlef95ec3c2006-03-27 01:17:27 -08001635
Manuel Laussc329f602011-06-10 15:23:01 +00001636 /* shut gcc up */
1637 ret = 0;
1638 fbdev = NULL;
Ralf Baechlef95ec3c2006-03-27 01:17:27 -08001639
Manuel Lauss98707fc2011-06-10 15:23:02 +00001640 /* Kickstart the panel */
1641 au1200_setpanel(panel);
1642
Manuel Lauss8be90b02011-06-10 15:23:03 +00001643 for (plane = 0; plane < device_count; ++plane) {
Ralf Baechlef95ec3c2006-03-27 01:17:27 -08001644 bpp = winbpp(win->w[plane].mode_winctrl1);
1645 if (win->w[plane].xres == 0)
1646 win->w[plane].xres = panel->Xres;
1647 if (win->w[plane].yres == 0)
1648 win->w[plane].yres = panel->Yres;
1649
Manuel Laussc329f602011-06-10 15:23:01 +00001650 fbi = framebuffer_alloc(sizeof(struct au1200fb_device),
1651 &dev->dev);
1652 if (!fbi)
1653 goto failed;
1654
1655 _au1200fb_infos[plane] = fbi;
1656 fbdev = fbi->par;
1657 fbdev->fb_info = fbi;
1658
Ralf Baechlef95ec3c2006-03-27 01:17:27 -08001659 fbdev->plane = plane;
1660
1661 /* Allocate the framebuffer to the maximum screen size */
1662 fbdev->fb_len = (win->w[plane].xres * win->w[plane].yres * bpp) / 8;
1663
Ming Lei7a192ec2009-02-06 23:40:12 +08001664 fbdev->fb_mem = dma_alloc_noncoherent(&dev->dev,
Ralf Baechlef95ec3c2006-03-27 01:17:27 -08001665 PAGE_ALIGN(fbdev->fb_len),
1666 &fbdev->fb_phys, GFP_KERNEL);
1667 if (!fbdev->fb_mem) {
1668 print_err("fail to allocate frambuffer (size: %dK))",
1669 fbdev->fb_len / 1024);
1670 return -ENOMEM;
1671 }
1672
1673 /*
1674 * Set page reserved so that mmap will work. This is necessary
1675 * since we'll be remapping normal memory.
1676 */
1677 for (page = (unsigned long)fbdev->fb_phys;
1678 page < PAGE_ALIGN((unsigned long)fbdev->fb_phys +
1679 fbdev->fb_len);
1680 page += PAGE_SIZE) {
1681 SetPageReserved(pfn_to_page(page >> PAGE_SHIFT)); /* LCD DMA is NOT coherent on Au1200 */
1682 }
1683 print_dbg("Framebuffer memory map at %p", fbdev->fb_mem);
1684 print_dbg("phys=0x%08x, size=%dK", fbdev->fb_phys, fbdev->fb_len / 1024);
1685
1686 /* Init FB data */
1687 if ((ret = au1200fb_init_fbinfo(fbdev)) < 0)
1688 goto failed;
1689
1690 /* Register new framebuffer */
Manuel Laussc329f602011-06-10 15:23:01 +00001691 ret = register_framebuffer(fbi);
1692 if (ret < 0) {
Ralf Baechlef95ec3c2006-03-27 01:17:27 -08001693 print_err("cannot register new framebuffer");
1694 goto failed;
1695 }
1696
Manuel Laussc329f602011-06-10 15:23:01 +00001697 au1200fb_fb_set_par(fbi);
Ralf Baechlef95ec3c2006-03-27 01:17:27 -08001698
1699#if !defined(CONFIG_FRAMEBUFFER_CONSOLE) && defined(CONFIG_LOGO)
1700 if (plane == 0)
Manuel Laussc329f602011-06-10 15:23:01 +00001701 if (fb_prepare_logo(fbi, FB_ROTATE_UR)) {
Ralf Baechlef95ec3c2006-03-27 01:17:27 -08001702 /* Start display and show logo on boot */
Manuel Laussc329f602011-06-10 15:23:01 +00001703 fb_set_cmap(&fbi->cmap, fbi);
1704 fb_show_logo(fbi, FB_ROTATE_UR);
Ralf Baechlef95ec3c2006-03-27 01:17:27 -08001705 }
1706#endif
1707 }
1708
1709 /* Now hook interrupt too */
Manuel Lauss1630d852011-06-12 17:15:29 +00001710 irq = platform_get_irq(dev, 0);
1711 ret = request_irq(irq, au1200fb_handle_irq,
Yong Zhangf8798cc2011-09-22 16:59:16 +08001712 IRQF_SHARED, "lcd", (void *)dev);
Manuel Lauss1630d852011-06-12 17:15:29 +00001713 if (ret) {
Ralf Baechlef95ec3c2006-03-27 01:17:27 -08001714 print_err("fail to request interrupt line %d (err: %d)",
Manuel Lauss1630d852011-06-12 17:15:29 +00001715 irq, ret);
Ralf Baechlef95ec3c2006-03-27 01:17:27 -08001716 goto failed;
1717 }
1718
1719 return 0;
1720
1721failed:
1722 /* NOTE: This only does the current plane/window that failed; others are still active */
1723 if (fbdev->fb_mem)
Manuel Laussc329f602011-06-10 15:23:01 +00001724 dma_free_noncoherent(&dev->dev, PAGE_ALIGN(fbdev->fb_len),
Ralf Baechlef95ec3c2006-03-27 01:17:27 -08001725 fbdev->fb_mem, fbdev->fb_phys);
Manuel Laussc329f602011-06-10 15:23:01 +00001726 if (fbi) {
1727 if (fbi->cmap.len != 0)
1728 fb_dealloc_cmap(&fbi->cmap);
1729 kfree(fbi->pseudo_palette);
1730 }
Ralf Baechlef95ec3c2006-03-27 01:17:27 -08001731 if (plane == 0)
1732 free_irq(AU1200_LCD_INT, (void*)dev);
1733 return ret;
1734}
1735
Manuel Lauss98707fc2011-06-10 15:23:02 +00001736static int __devexit au1200fb_drv_remove(struct platform_device *dev)
Ralf Baechlef95ec3c2006-03-27 01:17:27 -08001737{
1738 struct au1200fb_device *fbdev;
Manuel Laussc329f602011-06-10 15:23:01 +00001739 struct fb_info *fbi;
Ralf Baechlef95ec3c2006-03-27 01:17:27 -08001740 int plane;
1741
Ralf Baechlef95ec3c2006-03-27 01:17:27 -08001742 /* Turn off the panel */
1743 au1200_setpanel(NULL);
1744
Manuel Lauss8be90b02011-06-10 15:23:03 +00001745 for (plane = 0; plane < device_count; ++plane) {
Manuel Laussc329f602011-06-10 15:23:01 +00001746 fbi = _au1200fb_infos[plane];
1747 fbdev = fbi->par;
Ralf Baechlef95ec3c2006-03-27 01:17:27 -08001748
1749 /* Clean up all probe data */
Manuel Laussc329f602011-06-10 15:23:01 +00001750 unregister_framebuffer(fbi);
Ralf Baechlef95ec3c2006-03-27 01:17:27 -08001751 if (fbdev->fb_mem)
Ming Lei7a192ec2009-02-06 23:40:12 +08001752 dma_free_noncoherent(&dev->dev,
1753 PAGE_ALIGN(fbdev->fb_len),
Ralf Baechlef95ec3c2006-03-27 01:17:27 -08001754 fbdev->fb_mem, fbdev->fb_phys);
Manuel Laussc329f602011-06-10 15:23:01 +00001755 if (fbi->cmap.len != 0)
1756 fb_dealloc_cmap(&fbi->cmap);
1757 kfree(fbi->pseudo_palette);
1758
1759 framebuffer_release(fbi);
1760 _au1200fb_infos[plane] = NULL;
Ralf Baechlef95ec3c2006-03-27 01:17:27 -08001761 }
1762
Manuel Lauss1630d852011-06-12 17:15:29 +00001763 free_irq(platform_get_irq(dev, 0), (void *)dev);
Ralf Baechlef95ec3c2006-03-27 01:17:27 -08001764
1765 return 0;
1766}
1767
1768#ifdef CONFIG_PM
Manuel Lauss98707fc2011-06-10 15:23:02 +00001769static int au1200fb_drv_suspend(struct device *dev)
Ralf Baechlef95ec3c2006-03-27 01:17:27 -08001770{
Manuel Lauss98707fc2011-06-10 15:23:02 +00001771 au1200_setpanel(NULL);
1772
1773 lcd->outmask = 0;
1774 au_sync();
1775
Ralf Baechlef95ec3c2006-03-27 01:17:27 -08001776 return 0;
1777}
1778
Manuel Lauss98707fc2011-06-10 15:23:02 +00001779static int au1200fb_drv_resume(struct device *dev)
Ralf Baechlef95ec3c2006-03-27 01:17:27 -08001780{
Manuel Lauss98707fc2011-06-10 15:23:02 +00001781 struct fb_info *fbi;
1782 int i;
1783
1784 /* Kickstart the panel */
1785 au1200_setpanel(panel);
1786
Manuel Lauss8be90b02011-06-10 15:23:03 +00001787 for (i = 0; i < device_count; i++) {
Manuel Lauss98707fc2011-06-10 15:23:02 +00001788 fbi = _au1200fb_infos[i];
1789 au1200fb_fb_set_par(fbi);
1790 }
1791
Ralf Baechlef95ec3c2006-03-27 01:17:27 -08001792 return 0;
1793}
Manuel Lauss98707fc2011-06-10 15:23:02 +00001794
1795static const struct dev_pm_ops au1200fb_pmops = {
1796 .suspend = au1200fb_drv_suspend,
1797 .resume = au1200fb_drv_resume,
1798 .freeze = au1200fb_drv_suspend,
1799 .thaw = au1200fb_drv_resume,
1800};
1801
1802#define AU1200FB_PMOPS (&au1200fb_pmops)
1803
1804#else
1805#define AU1200FB_PMOPS NULL
Ralf Baechlef95ec3c2006-03-27 01:17:27 -08001806#endif /* CONFIG_PM */
1807
Ming Lei7a192ec2009-02-06 23:40:12 +08001808static struct platform_driver au1200fb_driver = {
1809 .driver = {
Manuel Lauss98707fc2011-06-10 15:23:02 +00001810 .name = "au1200-lcd",
1811 .owner = THIS_MODULE,
1812 .pm = AU1200FB_PMOPS,
Ming Lei7a192ec2009-02-06 23:40:12 +08001813 },
Ralf Baechlef95ec3c2006-03-27 01:17:27 -08001814 .probe = au1200fb_drv_probe,
Manuel Lauss98707fc2011-06-10 15:23:02 +00001815 .remove = __devexit_p(au1200fb_drv_remove),
Ralf Baechlef95ec3c2006-03-27 01:17:27 -08001816};
1817
1818/*-------------------------------------------------------------------------*/
1819
1820/* Kernel driver */
1821
Manuel Lauss8be90b02011-06-10 15:23:03 +00001822static int au1200fb_setup(void)
Ralf Baechlef95ec3c2006-03-27 01:17:27 -08001823{
Manuel Lauss8be90b02011-06-10 15:23:03 +00001824 char *options = NULL;
1825 char *this_opt, *endptr;
Ralf Baechlef95ec3c2006-03-27 01:17:27 -08001826 int num_panels = ARRAY_SIZE(known_lcd_panels);
1827 int panel_idx = -1;
1828
1829 fb_get_options(DRIVER_NAME, &options);
1830
1831 if (options) {
1832 while ((this_opt = strsep(&options,",")) != NULL) {
1833 /* Panel option - can be panel name,
1834 * "bs" for board-switch, or number/index */
1835 if (!strncmp(this_opt, "panel:", 6)) {
1836 int i;
1837 long int li;
1838 char *endptr;
1839 this_opt += 6;
1840 /* First check for index, which allows
1841 * to short circuit this mess */
1842 li = simple_strtol(this_opt, &endptr, 0);
1843 if (*endptr == '\0') {
1844 panel_idx = (int)li;
1845 }
1846 else if (strcmp(this_opt, "bs") == 0) {
1847 extern int board_au1200fb_panel(void);
1848 panel_idx = board_au1200fb_panel();
1849 }
1850
1851 else
1852 for (i = 0; i < num_panels; i++) {
1853 if (!strcmp(this_opt, known_lcd_panels[i].name)) {
1854 panel_idx = i;
1855 break;
1856 }
1857 }
1858
1859 if ((panel_idx < 0) || (panel_idx >= num_panels)) {
1860 print_warn("Panel %s not supported!", this_opt);
1861 }
1862 else
1863 panel_index = panel_idx;
1864 }
1865
1866 else if (strncmp(this_opt, "nohwcursor", 10) == 0) {
1867 nohwcursor = 1;
1868 }
1869
Manuel Lauss8be90b02011-06-10 15:23:03 +00001870 else if (strncmp(this_opt, "devices:", 8) == 0) {
1871 this_opt += 8;
1872 device_count = simple_strtol(this_opt,
1873 &endptr, 0);
1874 if ((device_count < 0) ||
1875 (device_count > MAX_DEVICE_COUNT))
1876 device_count = MAX_DEVICE_COUNT;
1877 }
1878
1879 else if (strncmp(this_opt, "wincfg:", 7) == 0) {
1880 this_opt += 7;
1881 window_index = simple_strtol(this_opt,
1882 &endptr, 0);
1883 if ((window_index < 0) ||
1884 (window_index >= ARRAY_SIZE(windows)))
1885 window_index = DEFAULT_WINDOW_INDEX;
1886 }
1887
1888 else if (strncmp(this_opt, "off", 3) == 0)
1889 return 1;
Ralf Baechlef95ec3c2006-03-27 01:17:27 -08001890 /* Unsupported option */
1891 else {
1892 print_warn("Unsupported option \"%s\"", this_opt);
1893 }
1894 }
1895 }
Manuel Lauss8be90b02011-06-10 15:23:03 +00001896 return 0;
Ralf Baechlef95ec3c2006-03-27 01:17:27 -08001897}
1898
Ralf Baechlef95ec3c2006-03-27 01:17:27 -08001899static int __init au1200fb_init(void)
1900{
1901 print_info("" DRIVER_DESC "");
1902
1903 /* Setup driver with options */
Manuel Lauss8be90b02011-06-10 15:23:03 +00001904 if (au1200fb_setup())
1905 return -ENODEV;
Ralf Baechlef95ec3c2006-03-27 01:17:27 -08001906
1907 /* Point to the panel selected */
1908 panel = &known_lcd_panels[panel_index];
1909 win = &windows[window_index];
1910
1911 printk(DRIVER_NAME ": Panel %d %s\n", panel_index, panel->name);
1912 printk(DRIVER_NAME ": Win %d %s\n", window_index, win->name);
1913
Ming Lei7a192ec2009-02-06 23:40:12 +08001914 return platform_driver_register(&au1200fb_driver);
Ralf Baechlef95ec3c2006-03-27 01:17:27 -08001915}
1916
1917static void __exit au1200fb_cleanup(void)
1918{
Ming Lei7a192ec2009-02-06 23:40:12 +08001919 platform_driver_unregister(&au1200fb_driver);
Ralf Baechlef95ec3c2006-03-27 01:17:27 -08001920}
1921
1922module_init(au1200fb_init);
1923module_exit(au1200fb_cleanup);
1924
1925MODULE_DESCRIPTION(DRIVER_DESC);
1926MODULE_LICENSE("GPL");