blob: 29652ab15ee035d7955214de03d8749b63a36f99 [file] [log] [blame]
York Sun9b53a9e2008-04-28 02:15:34 -07001/*
2 * Copyright 2008 Freescale Semiconductor, Inc. All Rights Reserved.
3 *
4 * Freescale DIU Frame Buffer device driver
5 *
6 * Authors: Hongjun Chen <hong-jun.chen@freescale.com>
7 * Paul Widmer <paul.widmer@freescale.com>
8 * Srikanth Srinivasan <srikanth.srinivasan@freescale.com>
9 * York Sun <yorksun@freescale.com>
10 *
11 * Based on imxfb.c Copyright (C) 2004 S.Hauer, Pengutronix
12 *
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2 of the License, or (at your
16 * option) any later version.
17 *
18 */
19
20#include <linux/module.h>
21#include <linux/kernel.h>
22#include <linux/errno.h>
23#include <linux/string.h>
24#include <linux/slab.h>
25#include <linux/fb.h>
26#include <linux/init.h>
27#include <linux/dma-mapping.h>
28#include <linux/platform_device.h>
29#include <linux/interrupt.h>
30#include <linux/clk.h>
31#include <linux/uaccess.h>
32#include <linux/vmalloc.h>
Timur Tabib715f9f2011-09-28 16:19:48 -050033#include <linux/spinlock.h>
York Sun9b53a9e2008-04-28 02:15:34 -070034
York Sun9b53a9e2008-04-28 02:15:34 -070035#include <sysdev/fsl_soc.h>
Anatolij Gustschin0814a972010-07-23 04:00:36 +000036#include <linux/fsl-diu-fb.h>
Anatolij Gustschin8b856f02010-07-23 04:00:39 +000037#include "edid.h"
York Sun9b53a9e2008-04-28 02:15:34 -070038
Timur Tabib715f9f2011-09-28 16:19:48 -050039#define FSL_AOI_NUM 6 /* 5 AOIs and one dummy AOI */
40 /* 1 for plane 0, 2 for plane 1&2 each */
41
42/* HW cursor parameters */
43#define MAX_CURS 32
44
45/* INT_STATUS/INT_MASK field descriptions */
46#define INT_VSYNC 0x01 /* Vsync interrupt */
47#define INT_VSYNC_WB 0x02 /* Vsync interrupt for write back operation */
48#define INT_UNDRUN 0x04 /* Under run exception interrupt */
49#define INT_PARERR 0x08 /* Display parameters error interrupt */
50#define INT_LS_BF_VS 0x10 /* Lines before vsync. interrupt */
51
52/* Panels'operation modes */
53#define MFB_TYPE_OUTPUT 0 /* Panel output to display */
54#define MFB_TYPE_OFF 1 /* Panel off */
55#define MFB_TYPE_WB 2 /* Panel written back to memory */
56#define MFB_TYPE_TEST 3 /* Panel generate color bar */
57
58struct diu_hw {
59 struct diu __iomem *diu_reg;
60 spinlock_t reg_lock;
61 unsigned int mode; /* DIU operation mode */
62};
63
64struct diu_addr {
65 void *vaddr; /* Virtual address */
66 dma_addr_t paddr; /* Physical address */
67 __u32 offset;
68};
69
70struct diu_pool {
71 struct diu_addr ad;
72 struct diu_addr gamma;
73 struct diu_addr pallete;
74 struct diu_addr cursor;
75};
76
York Sun9b53a9e2008-04-28 02:15:34 -070077/*
Timur Tabi63cf8df2011-09-15 16:44:51 -050078 * List of supported video modes
79 *
Timur Tabi760af8f2011-09-28 16:19:50 -050080 * The first entry is the default video mode. The remain entries are in
81 * order if increasing resolution and frequency. The 320x240-60 mode is
82 * the initial AOI for the second and third planes.
York Sun9b53a9e2008-04-28 02:15:34 -070083 */
York Sun9b53a9e2008-04-28 02:15:34 -070084static struct fb_videomode __devinitdata fsl_diu_mode_db[] = {
85 {
York Sun9b53a9e2008-04-28 02:15:34 -070086 .refresh = 60,
87 .xres = 1024,
88 .yres = 768,
89 .pixclock = 15385,
90 .left_margin = 160,
91 .right_margin = 24,
92 .upper_margin = 29,
93 .lower_margin = 3,
94 .hsync_len = 136,
95 .vsync_len = 6,
96 .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
97 .vmode = FB_VMODE_NONINTERLACED
98 },
99 {
Timur Tabi760af8f2011-09-28 16:19:50 -0500100 .refresh = 60,
101 .xres = 320,
102 .yres = 240,
103 .pixclock = 79440,
104 .left_margin = 16,
105 .right_margin = 16,
106 .upper_margin = 16,
107 .lower_margin = 5,
108 .hsync_len = 48,
109 .vsync_len = 1,
110 .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
111 .vmode = FB_VMODE_NONINTERLACED
112 },
113 {
114 .refresh = 60,
115 .xres = 640,
116 .yres = 480,
117 .pixclock = 39722,
118 .left_margin = 48,
119 .right_margin = 16,
120 .upper_margin = 33,
121 .lower_margin = 10,
122 .hsync_len = 96,
123 .vsync_len = 2,
124 .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
125 .vmode = FB_VMODE_NONINTERLACED
126 },
127 {
128 .refresh = 72,
129 .xres = 640,
130 .yres = 480,
131 .pixclock = 32052,
132 .left_margin = 128,
133 .right_margin = 24,
134 .upper_margin = 28,
135 .lower_margin = 9,
136 .hsync_len = 40,
137 .vsync_len = 3,
138 .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
139 .vmode = FB_VMODE_NONINTERLACED
140 },
141 {
142 .refresh = 75,
143 .xres = 640,
144 .yres = 480,
145 .pixclock = 31747,
146 .left_margin = 120,
147 .right_margin = 16,
148 .upper_margin = 16,
149 .lower_margin = 1,
150 .hsync_len = 64,
151 .vsync_len = 3,
152 .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
153 .vmode = FB_VMODE_NONINTERLACED
154 },
155 {
156 .refresh = 90,
157 .xres = 640,
158 .yres = 480,
159 .pixclock = 25057,
160 .left_margin = 120,
161 .right_margin = 32,
162 .upper_margin = 14,
163 .lower_margin = 25,
164 .hsync_len = 40,
165 .vsync_len = 14,
166 .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
167 .vmode = FB_VMODE_NONINTERLACED
168 },
169 {
170 .refresh = 100,
171 .xres = 640,
172 .yres = 480,
173 .pixclock = 22272,
174 .left_margin = 48,
175 .right_margin = 32,
176 .upper_margin = 17,
177 .lower_margin = 22,
178 .hsync_len = 128,
179 .vsync_len = 12,
180 .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
181 .vmode = FB_VMODE_NONINTERLACED
182 },
183 {
184 .refresh = 60,
185 .xres = 800,
186 .yres = 480,
187 .pixclock = 33805,
188 .left_margin = 96,
189 .right_margin = 24,
190 .upper_margin = 10,
191 .lower_margin = 3,
192 .hsync_len = 72,
193 .vsync_len = 7,
194 .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
195 .vmode = FB_VMODE_NONINTERLACED
196 },
197 {
198 .refresh = 60,
199 .xres = 800,
200 .yres = 600,
201 .pixclock = 25000,
202 .left_margin = 88,
203 .right_margin = 40,
204 .upper_margin = 23,
205 .lower_margin = 1,
206 .hsync_len = 128,
207 .vsync_len = 4,
208 .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
209 .vmode = FB_VMODE_NONINTERLACED
210 },
211 {
212 .refresh = 60,
213 .xres = 854,
214 .yres = 480,
215 .pixclock = 31518,
216 .left_margin = 104,
217 .right_margin = 16,
218 .upper_margin = 13,
219 .lower_margin = 1,
220 .hsync_len = 88,
221 .vsync_len = 3,
222 .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
223 .vmode = FB_VMODE_NONINTERLACED
224 },
225 {
York Sun9b53a9e2008-04-28 02:15:34 -0700226 .refresh = 70,
227 .xres = 1024,
228 .yres = 768,
229 .pixclock = 16886,
230 .left_margin = 3,
231 .right_margin = 3,
232 .upper_margin = 2,
233 .lower_margin = 2,
234 .hsync_len = 40,
235 .vsync_len = 18,
236 .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
237 .vmode = FB_VMODE_NONINTERLACED
238 },
239 {
York Sun9b53a9e2008-04-28 02:15:34 -0700240 .refresh = 75,
241 .xres = 1024,
242 .yres = 768,
243 .pixclock = 15009,
244 .left_margin = 3,
245 .right_margin = 3,
246 .upper_margin = 2,
247 .lower_margin = 2,
248 .hsync_len = 80,
249 .vsync_len = 32,
250 .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
251 .vmode = FB_VMODE_NONINTERLACED
252 },
253 {
Timur Tabi760af8f2011-09-28 16:19:50 -0500254 .refresh = 60,
255 .xres = 1280,
256 .yres = 480,
257 .pixclock = 18939,
258 .left_margin = 353,
259 .right_margin = 47,
260 .upper_margin = 39,
261 .lower_margin = 4,
262 .hsync_len = 8,
263 .vsync_len = 2,
264 .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
265 .vmode = FB_VMODE_NONINTERLACED
266 },
267 {
268 .refresh = 60,
269 .xres = 1280,
270 .yres = 720,
271 .pixclock = 13426,
272 .left_margin = 192,
273 .right_margin = 64,
274 .upper_margin = 22,
275 .lower_margin = 1,
276 .hsync_len = 136,
277 .vsync_len = 3,
278 .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
279 .vmode = FB_VMODE_NONINTERLACED
280 },
281 {
York Sun9b53a9e2008-04-28 02:15:34 -0700282 .refresh = 60,
283 .xres = 1280,
284 .yres = 1024,
285 .pixclock = 9375,
286 .left_margin = 38,
287 .right_margin = 128,
288 .upper_margin = 2,
289 .lower_margin = 7,
290 .hsync_len = 216,
291 .vsync_len = 37,
292 .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
293 .vmode = FB_VMODE_NONINTERLACED
294 },
295 {
York Sun9b53a9e2008-04-28 02:15:34 -0700296 .refresh = 70,
297 .xres = 1280,
298 .yres = 1024,
299 .pixclock = 9380,
300 .left_margin = 6,
301 .right_margin = 6,
302 .upper_margin = 4,
303 .lower_margin = 4,
304 .hsync_len = 60,
305 .vsync_len = 94,
306 .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
307 .vmode = FB_VMODE_NONINTERLACED
308 },
309 {
York Sun9b53a9e2008-04-28 02:15:34 -0700310 .refresh = 75,
311 .xres = 1280,
312 .yres = 1024,
313 .pixclock = 9380,
314 .left_margin = 6,
315 .right_margin = 6,
316 .upper_margin = 4,
317 .lower_margin = 4,
318 .hsync_len = 60,
319 .vsync_len = 15,
320 .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
321 .vmode = FB_VMODE_NONINTERLACED
322 },
323 {
York Sun9b53a9e2008-04-28 02:15:34 -0700324 .refresh = 60,
Timur Tabi760af8f2011-09-28 16:19:50 -0500325 .xres = 1920,
326 .yres = 1080,
327 .pixclock = 5787,
328 .left_margin = 328,
329 .right_margin = 120,
330 .upper_margin = 34,
331 .lower_margin = 1,
332 .hsync_len = 208,
333 .vsync_len = 3,
York Sun9b53a9e2008-04-28 02:15:34 -0700334 .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
335 .vmode = FB_VMODE_NONINTERLACED
336 },
337};
338
Timur Tabi760af8f2011-09-28 16:19:50 -0500339static char *fb_mode;
York Sun9b53a9e2008-04-28 02:15:34 -0700340static unsigned long default_bpp = 32;
Timur Tabi7653aaa2011-07-09 15:38:14 -0500341static enum fsl_diu_monitor_port monitor_port;
342static char *monitor_string;
York Sun9b53a9e2008-04-28 02:15:34 -0700343
344#if defined(CONFIG_NOT_COHERENT_CACHE)
345static u8 *coherence_data;
346static size_t coherence_data_size;
347static unsigned int d_cache_line_size;
348#endif
349
350static DEFINE_SPINLOCK(diu_lock);
351
352struct fsl_diu_data {
353 struct fb_info *fsl_diu_info[FSL_AOI_NUM - 1];
354 /*FSL_AOI_NUM has one dummy AOI */
355 struct device_attribute dev_attr;
356 struct diu_ad *dummy_ad;
357 void *dummy_aoi_virt;
358 unsigned int irq;
359 int fb_enabled;
Timur Tabi7653aaa2011-07-09 15:38:14 -0500360 enum fsl_diu_monitor_port monitor_port;
York Sun9b53a9e2008-04-28 02:15:34 -0700361};
362
363struct mfb_info {
364 int index;
365 int type;
366 char *id;
367 int registered;
York Sun9b53a9e2008-04-28 02:15:34 -0700368 unsigned long pseudo_palette[16];
369 struct diu_ad *ad;
370 int cursor_reset;
371 unsigned char g_alpha;
372 unsigned int count;
373 int x_aoi_d; /* aoi display x offset to physical screen */
374 int y_aoi_d; /* aoi display y offset to physical screen */
375 struct fsl_diu_data *parent;
Anatolij Gustschin8b856f02010-07-23 04:00:39 +0000376 u8 *edid_data;
York Sun9b53a9e2008-04-28 02:15:34 -0700377};
378
379
380static struct mfb_info mfb_template[] = {
381 { /* AOI 0 for plane 0 */
Timur Tabi4a85dc8b2011-09-15 16:44:46 -0500382 .index = 0,
383 .type = MFB_TYPE_OUTPUT,
384 .id = "Panel0",
385 .registered = 0,
386 .count = 0,
387 .x_aoi_d = 0,
388 .y_aoi_d = 0,
York Sun9b53a9e2008-04-28 02:15:34 -0700389 },
390 { /* AOI 0 for plane 1 */
Timur Tabi4a85dc8b2011-09-15 16:44:46 -0500391 .index = 1,
392 .type = MFB_TYPE_OUTPUT,
393 .id = "Panel1 AOI0",
394 .registered = 0,
395 .g_alpha = 0xff,
396 .count = 0,
397 .x_aoi_d = 0,
398 .y_aoi_d = 0,
York Sun9b53a9e2008-04-28 02:15:34 -0700399 },
400 { /* AOI 1 for plane 1 */
Timur Tabi4a85dc8b2011-09-15 16:44:46 -0500401 .index = 2,
402 .type = MFB_TYPE_OUTPUT,
403 .id = "Panel1 AOI1",
404 .registered = 0,
405 .g_alpha = 0xff,
406 .count = 0,
407 .x_aoi_d = 0,
408 .y_aoi_d = 480,
York Sun9b53a9e2008-04-28 02:15:34 -0700409 },
410 { /* AOI 0 for plane 2 */
Timur Tabi4a85dc8b2011-09-15 16:44:46 -0500411 .index = 3,
412 .type = MFB_TYPE_OUTPUT,
413 .id = "Panel2 AOI0",
414 .registered = 0,
415 .g_alpha = 0xff,
416 .count = 0,
417 .x_aoi_d = 640,
418 .y_aoi_d = 0,
York Sun9b53a9e2008-04-28 02:15:34 -0700419 },
420 { /* AOI 1 for plane 2 */
Timur Tabi4a85dc8b2011-09-15 16:44:46 -0500421 .index = 4,
422 .type = MFB_TYPE_OUTPUT,
423 .id = "Panel2 AOI1",
424 .registered = 0,
425 .g_alpha = 0xff,
426 .count = 0,
427 .x_aoi_d = 640,
428 .y_aoi_d = 480,
York Sun9b53a9e2008-04-28 02:15:34 -0700429 },
430};
431
432static struct diu_hw dr = {
433 .mode = MFB_MODE1,
434 .reg_lock = __SPIN_LOCK_UNLOCKED(diu_hw.reg_lock),
435};
436
437static struct diu_pool pool;
438
Timur Tabi6b51d512008-07-23 21:31:39 -0700439/**
Timur Tabi7653aaa2011-07-09 15:38:14 -0500440 * fsl_diu_name_to_port - convert a port name to a monitor port enum
441 *
442 * Takes the name of a monitor port ("dvi", "lvds", or "dlvds") and returns
443 * the enum fsl_diu_monitor_port that corresponds to that string.
444 *
445 * For compatibility with older versions, a number ("0", "1", or "2") is also
446 * supported.
447 *
448 * If the string is unknown, DVI is assumed.
449 *
450 * If the particular port is not supported by the platform, another port
451 * (platform-specific) is chosen instead.
452 */
453static enum fsl_diu_monitor_port fsl_diu_name_to_port(const char *s)
454{
455 enum fsl_diu_monitor_port port = FSL_DIU_PORT_DVI;
456 unsigned long val;
457
458 if (s) {
459 if (!strict_strtoul(s, 10, &val) && (val <= 2))
460 port = (enum fsl_diu_monitor_port) val;
461 else if (strncmp(s, "lvds", 4) == 0)
462 port = FSL_DIU_PORT_LVDS;
463 else if (strncmp(s, "dlvds", 5) == 0)
464 port = FSL_DIU_PORT_DLVDS;
465 }
466
467 return diu_ops.valid_monitor_port(port);
468}
469
470/**
Timur Tabi6b51d512008-07-23 21:31:39 -0700471 * fsl_diu_alloc - allocate memory for the DIU
472 * @size: number of bytes to allocate
473 * @param: returned physical address of memory
474 *
475 * This function allocates a physically-contiguous block of memory.
York Sun9b53a9e2008-04-28 02:15:34 -0700476 */
Timur Tabi6b51d512008-07-23 21:31:39 -0700477static void *fsl_diu_alloc(size_t size, phys_addr_t *phys)
York Sun9b53a9e2008-04-28 02:15:34 -0700478{
479 void *virt;
480
Timur Tabi6b51d512008-07-23 21:31:39 -0700481 virt = alloc_pages_exact(size, GFP_DMA | __GFP_ZERO);
Timur Tabi154152a2011-09-15 16:44:47 -0500482 if (virt)
York Sun9b53a9e2008-04-28 02:15:34 -0700483 *phys = virt_to_phys(virt);
York Sun9b53a9e2008-04-28 02:15:34 -0700484
485 return virt;
486}
487
Timur Tabi6b51d512008-07-23 21:31:39 -0700488/**
489 * fsl_diu_free - release DIU memory
490 * @virt: pointer returned by fsl_diu_alloc()
491 * @size: number of bytes allocated by fsl_diu_alloc()
492 *
493 * This function releases memory allocated by fsl_diu_alloc().
494 */
495static void fsl_diu_free(void *virt, size_t size)
York Sun9b53a9e2008-04-28 02:15:34 -0700496{
Timur Tabi6b51d512008-07-23 21:31:39 -0700497 if (virt && size)
498 free_pages_exact(virt, size);
York Sun9b53a9e2008-04-28 02:15:34 -0700499}
500
Anatolij Gustschin0d9dab32010-07-23 04:00:35 +0000501/*
502 * Workaround for failed writing desc register of planes.
503 * Needed with MPC5121 DIU rev 2.0 silicon.
504 */
505void wr_reg_wa(u32 *reg, u32 val)
506{
507 do {
508 out_be32(reg, val);
509 } while (in_be32(reg) != val);
510}
511
York Sun9b53a9e2008-04-28 02:15:34 -0700512static int fsl_diu_enable_panel(struct fb_info *info)
513{
514 struct mfb_info *pmfbi, *cmfbi, *mfbi = info->par;
515 struct diu *hw = dr.diu_reg;
516 struct diu_ad *ad = mfbi->ad;
517 struct fsl_diu_data *machine_data = mfbi->parent;
518 int res = 0;
519
York Sun9b53a9e2008-04-28 02:15:34 -0700520 if (mfbi->type != MFB_TYPE_OFF) {
521 switch (mfbi->index) {
522 case 0: /* plane 0 */
523 if (hw->desc[0] != ad->paddr)
Anatolij Gustschin0d9dab32010-07-23 04:00:35 +0000524 wr_reg_wa(&hw->desc[0], ad->paddr);
York Sun9b53a9e2008-04-28 02:15:34 -0700525 break;
526 case 1: /* plane 1 AOI 0 */
527 cmfbi = machine_data->fsl_diu_info[2]->par;
528 if (hw->desc[1] != ad->paddr) { /* AOI0 closed */
529 if (cmfbi->count > 0) /* AOI1 open */
530 ad->next_ad =
531 cpu_to_le32(cmfbi->ad->paddr);
532 else
533 ad->next_ad = 0;
Anatolij Gustschin0d9dab32010-07-23 04:00:35 +0000534 wr_reg_wa(&hw->desc[1], ad->paddr);
York Sun9b53a9e2008-04-28 02:15:34 -0700535 }
536 break;
537 case 3: /* plane 2 AOI 0 */
538 cmfbi = machine_data->fsl_diu_info[4]->par;
539 if (hw->desc[2] != ad->paddr) { /* AOI0 closed */
540 if (cmfbi->count > 0) /* AOI1 open */
541 ad->next_ad =
542 cpu_to_le32(cmfbi->ad->paddr);
543 else
544 ad->next_ad = 0;
Anatolij Gustschin0d9dab32010-07-23 04:00:35 +0000545 wr_reg_wa(&hw->desc[2], ad->paddr);
York Sun9b53a9e2008-04-28 02:15:34 -0700546 }
547 break;
548 case 2: /* plane 1 AOI 1 */
549 pmfbi = machine_data->fsl_diu_info[1]->par;
550 ad->next_ad = 0;
551 if (hw->desc[1] == machine_data->dummy_ad->paddr)
Anatolij Gustschin0d9dab32010-07-23 04:00:35 +0000552 wr_reg_wa(&hw->desc[1], ad->paddr);
York Sun9b53a9e2008-04-28 02:15:34 -0700553 else /* AOI0 open */
554 pmfbi->ad->next_ad = cpu_to_le32(ad->paddr);
555 break;
556 case 4: /* plane 2 AOI 1 */
557 pmfbi = machine_data->fsl_diu_info[3]->par;
558 ad->next_ad = 0;
559 if (hw->desc[2] == machine_data->dummy_ad->paddr)
Anatolij Gustschin0d9dab32010-07-23 04:00:35 +0000560 wr_reg_wa(&hw->desc[2], ad->paddr);
York Sun9b53a9e2008-04-28 02:15:34 -0700561 else /* AOI0 was open */
562 pmfbi->ad->next_ad = cpu_to_le32(ad->paddr);
563 break;
564 default:
565 res = -EINVAL;
566 break;
567 }
568 } else
569 res = -EINVAL;
570 return res;
571}
572
573static int fsl_diu_disable_panel(struct fb_info *info)
574{
575 struct mfb_info *pmfbi, *cmfbi, *mfbi = info->par;
576 struct diu *hw = dr.diu_reg;
577 struct diu_ad *ad = mfbi->ad;
578 struct fsl_diu_data *machine_data = mfbi->parent;
579 int res = 0;
580
581 switch (mfbi->index) {
582 case 0: /* plane 0 */
583 if (hw->desc[0] != machine_data->dummy_ad->paddr)
Anatolij Gustschin0d9dab32010-07-23 04:00:35 +0000584 wr_reg_wa(&hw->desc[0], machine_data->dummy_ad->paddr);
York Sun9b53a9e2008-04-28 02:15:34 -0700585 break;
586 case 1: /* plane 1 AOI 0 */
587 cmfbi = machine_data->fsl_diu_info[2]->par;
588 if (cmfbi->count > 0) /* AOI1 is open */
Anatolij Gustschin0d9dab32010-07-23 04:00:35 +0000589 wr_reg_wa(&hw->desc[1], cmfbi->ad->paddr);
York Sun9b53a9e2008-04-28 02:15:34 -0700590 /* move AOI1 to the first */
591 else /* AOI1 was closed */
Anatolij Gustschin0d9dab32010-07-23 04:00:35 +0000592 wr_reg_wa(&hw->desc[1], machine_data->dummy_ad->paddr);
York Sun9b53a9e2008-04-28 02:15:34 -0700593 /* close AOI 0 */
594 break;
595 case 3: /* plane 2 AOI 0 */
596 cmfbi = machine_data->fsl_diu_info[4]->par;
597 if (cmfbi->count > 0) /* AOI1 is open */
Anatolij Gustschin0d9dab32010-07-23 04:00:35 +0000598 wr_reg_wa(&hw->desc[2], cmfbi->ad->paddr);
York Sun9b53a9e2008-04-28 02:15:34 -0700599 /* move AOI1 to the first */
600 else /* AOI1 was closed */
Anatolij Gustschin0d9dab32010-07-23 04:00:35 +0000601 wr_reg_wa(&hw->desc[2], machine_data->dummy_ad->paddr);
York Sun9b53a9e2008-04-28 02:15:34 -0700602 /* close AOI 0 */
603 break;
604 case 2: /* plane 1 AOI 1 */
605 pmfbi = machine_data->fsl_diu_info[1]->par;
606 if (hw->desc[1] != ad->paddr) {
607 /* AOI1 is not the first in the chain */
608 if (pmfbi->count > 0)
609 /* AOI0 is open, must be the first */
610 pmfbi->ad->next_ad = 0;
611 } else /* AOI1 is the first in the chain */
Anatolij Gustschin0d9dab32010-07-23 04:00:35 +0000612 wr_reg_wa(&hw->desc[1], machine_data->dummy_ad->paddr);
York Sun9b53a9e2008-04-28 02:15:34 -0700613 /* close AOI 1 */
614 break;
615 case 4: /* plane 2 AOI 1 */
616 pmfbi = machine_data->fsl_diu_info[3]->par;
617 if (hw->desc[2] != ad->paddr) {
618 /* AOI1 is not the first in the chain */
619 if (pmfbi->count > 0)
620 /* AOI0 is open, must be the first */
621 pmfbi->ad->next_ad = 0;
622 } else /* AOI1 is the first in the chain */
Anatolij Gustschin0d9dab32010-07-23 04:00:35 +0000623 wr_reg_wa(&hw->desc[2], machine_data->dummy_ad->paddr);
York Sun9b53a9e2008-04-28 02:15:34 -0700624 /* close AOI 1 */
625 break;
626 default:
627 res = -EINVAL;
628 break;
629 }
630
631 return res;
632}
633
634static void enable_lcdc(struct fb_info *info)
635{
636 struct diu *hw = dr.diu_reg;
637 struct mfb_info *mfbi = info->par;
638 struct fsl_diu_data *machine_data = mfbi->parent;
639
640 if (!machine_data->fb_enabled) {
641 out_be32(&hw->diu_mode, dr.mode);
642 machine_data->fb_enabled++;
643 }
644}
645
646static void disable_lcdc(struct fb_info *info)
647{
648 struct diu *hw = dr.diu_reg;
649 struct mfb_info *mfbi = info->par;
650 struct fsl_diu_data *machine_data = mfbi->parent;
651
652 if (machine_data->fb_enabled) {
653 out_be32(&hw->diu_mode, 0);
654 machine_data->fb_enabled = 0;
655 }
656}
657
658static void adjust_aoi_size_position(struct fb_var_screeninfo *var,
659 struct fb_info *info)
660{
661 struct mfb_info *lower_aoi_mfbi, *upper_aoi_mfbi, *mfbi = info->par;
662 struct fsl_diu_data *machine_data = mfbi->parent;
663 int available_height, upper_aoi_bottom, index = mfbi->index;
664 int lower_aoi_is_open, upper_aoi_is_open;
665 __u32 base_plane_width, base_plane_height, upper_aoi_height;
666
667 base_plane_width = machine_data->fsl_diu_info[0]->var.xres;
668 base_plane_height = machine_data->fsl_diu_info[0]->var.yres;
669
York Sunfdfaa48332008-08-15 00:40:29 -0700670 if (mfbi->x_aoi_d < 0)
671 mfbi->x_aoi_d = 0;
672 if (mfbi->y_aoi_d < 0)
673 mfbi->y_aoi_d = 0;
York Sun9b53a9e2008-04-28 02:15:34 -0700674 switch (index) {
675 case 0:
676 if (mfbi->x_aoi_d != 0)
677 mfbi->x_aoi_d = 0;
678 if (mfbi->y_aoi_d != 0)
679 mfbi->y_aoi_d = 0;
680 break;
681 case 1: /* AOI 0 */
682 case 3:
683 lower_aoi_mfbi = machine_data->fsl_diu_info[index+1]->par;
684 lower_aoi_is_open = lower_aoi_mfbi->count > 0 ? 1 : 0;
685 if (var->xres > base_plane_width)
686 var->xres = base_plane_width;
687 if ((mfbi->x_aoi_d + var->xres) > base_plane_width)
688 mfbi->x_aoi_d = base_plane_width - var->xres;
689
690 if (lower_aoi_is_open)
691 available_height = lower_aoi_mfbi->y_aoi_d;
692 else
693 available_height = base_plane_height;
694 if (var->yres > available_height)
695 var->yres = available_height;
696 if ((mfbi->y_aoi_d + var->yres) > available_height)
697 mfbi->y_aoi_d = available_height - var->yres;
698 break;
699 case 2: /* AOI 1 */
700 case 4:
701 upper_aoi_mfbi = machine_data->fsl_diu_info[index-1]->par;
702 upper_aoi_height =
703 machine_data->fsl_diu_info[index-1]->var.yres;
704 upper_aoi_bottom = upper_aoi_mfbi->y_aoi_d + upper_aoi_height;
705 upper_aoi_is_open = upper_aoi_mfbi->count > 0 ? 1 : 0;
706 if (var->xres > base_plane_width)
707 var->xres = base_plane_width;
708 if ((mfbi->x_aoi_d + var->xres) > base_plane_width)
709 mfbi->x_aoi_d = base_plane_width - var->xres;
710 if (mfbi->y_aoi_d < 0)
711 mfbi->y_aoi_d = 0;
712 if (upper_aoi_is_open) {
713 if (mfbi->y_aoi_d < upper_aoi_bottom)
714 mfbi->y_aoi_d = upper_aoi_bottom;
715 available_height = base_plane_height
716 - upper_aoi_bottom;
717 } else
718 available_height = base_plane_height;
719 if (var->yres > available_height)
720 var->yres = available_height;
721 if ((mfbi->y_aoi_d + var->yres) > base_plane_height)
722 mfbi->y_aoi_d = base_plane_height - var->yres;
723 break;
724 }
725}
726/*
727 * Checks to see if the hardware supports the state requested by var passed
728 * in. This function does not alter the hardware state! If the var passed in
729 * is slightly off by what the hardware can support then we alter the var
730 * PASSED in to what we can do. If the hardware doesn't support mode change
731 * a -EINVAL will be returned by the upper layers.
732 */
733static int fsl_diu_check_var(struct fb_var_screeninfo *var,
734 struct fb_info *info)
735{
York Sun9b53a9e2008-04-28 02:15:34 -0700736 if (var->xres_virtual < var->xres)
737 var->xres_virtual = var->xres;
738 if (var->yres_virtual < var->yres)
739 var->yres_virtual = var->yres;
740
741 if (var->xoffset < 0)
742 var->xoffset = 0;
743
744 if (var->yoffset < 0)
745 var->yoffset = 0;
746
747 if (var->xoffset + info->var.xres > info->var.xres_virtual)
748 var->xoffset = info->var.xres_virtual - info->var.xres;
749
750 if (var->yoffset + info->var.yres > info->var.yres_virtual)
751 var->yoffset = info->var.yres_virtual - info->var.yres;
752
753 if ((var->bits_per_pixel != 32) && (var->bits_per_pixel != 24) &&
754 (var->bits_per_pixel != 16))
755 var->bits_per_pixel = default_bpp;
756
757 switch (var->bits_per_pixel) {
758 case 16:
759 var->red.length = 5;
760 var->red.offset = 11;
761 var->red.msb_right = 0;
762
763 var->green.length = 6;
764 var->green.offset = 5;
765 var->green.msb_right = 0;
766
767 var->blue.length = 5;
768 var->blue.offset = 0;
769 var->blue.msb_right = 0;
770
771 var->transp.length = 0;
772 var->transp.offset = 0;
773 var->transp.msb_right = 0;
774 break;
775 case 24:
776 var->red.length = 8;
777 var->red.offset = 0;
778 var->red.msb_right = 0;
779
780 var->green.length = 8;
781 var->green.offset = 8;
782 var->green.msb_right = 0;
783
784 var->blue.length = 8;
785 var->blue.offset = 16;
786 var->blue.msb_right = 0;
787
788 var->transp.length = 0;
789 var->transp.offset = 0;
790 var->transp.msb_right = 0;
791 break;
792 case 32:
793 var->red.length = 8;
794 var->red.offset = 16;
795 var->red.msb_right = 0;
796
797 var->green.length = 8;
798 var->green.offset = 8;
799 var->green.msb_right = 0;
800
801 var->blue.length = 8;
802 var->blue.offset = 0;
803 var->blue.msb_right = 0;
804
805 var->transp.length = 8;
806 var->transp.offset = 24;
807 var->transp.msb_right = 0;
808
809 break;
810 }
York Sun9b53a9e2008-04-28 02:15:34 -0700811
812 var->height = -1;
813 var->width = -1;
814 var->grayscale = 0;
815
816 /* Copy nonstd field to/from sync for fbset usage */
817 var->sync |= var->nonstd;
818 var->nonstd |= var->sync;
819
820 adjust_aoi_size_position(var, info);
821 return 0;
822}
823
824static void set_fix(struct fb_info *info)
825{
826 struct fb_fix_screeninfo *fix = &info->fix;
827 struct fb_var_screeninfo *var = &info->var;
828 struct mfb_info *mfbi = info->par;
829
Timur Tabiec02dd22011-09-15 16:44:54 -0500830 strncpy(fix->id, mfbi->id, sizeof(fix->id));
York Sun9b53a9e2008-04-28 02:15:34 -0700831 fix->line_length = var->xres_virtual * var->bits_per_pixel / 8;
832 fix->type = FB_TYPE_PACKED_PIXELS;
833 fix->accel = FB_ACCEL_NONE;
834 fix->visual = FB_VISUAL_TRUECOLOR;
835 fix->xpanstep = 1;
836 fix->ypanstep = 1;
837}
838
839static void update_lcdc(struct fb_info *info)
840{
841 struct fb_var_screeninfo *var = &info->var;
842 struct mfb_info *mfbi = info->par;
843 struct fsl_diu_data *machine_data = mfbi->parent;
844 struct diu *hw;
845 int i, j;
846 char __iomem *cursor_base, *gamma_table_base;
847
848 u32 temp;
849
850 hw = dr.diu_reg;
851
852 if (mfbi->type == MFB_TYPE_OFF) {
853 fsl_diu_disable_panel(info);
854 return;
855 }
856
857 diu_ops.set_monitor_port(machine_data->monitor_port);
858 gamma_table_base = pool.gamma.vaddr;
859 cursor_base = pool.cursor.vaddr;
860 /* Prep for DIU init - gamma table, cursor table */
861
862 for (i = 0; i <= 2; i++)
Timur Tabi4a85dc8b2011-09-15 16:44:46 -0500863 for (j = 0; j <= 255; j++)
864 *gamma_table_base++ = j;
York Sun9b53a9e2008-04-28 02:15:34 -0700865
866 diu_ops.set_gamma_table(machine_data->monitor_port, pool.gamma.vaddr);
867
York Sun9b53a9e2008-04-28 02:15:34 -0700868 disable_lcdc(info);
869
870 /* Program DIU registers */
871
872 out_be32(&hw->gamma, pool.gamma.paddr);
873 out_be32(&hw->cursor, pool.cursor.paddr);
874
875 out_be32(&hw->bgnd, 0x007F7F7F); /* BGND */
876 out_be32(&hw->bgnd_wb, 0); /* BGND_WB */
877 out_be32(&hw->disp_size, (var->yres << 16 | var->xres));
878 /* DISP SIZE */
York Sun9b53a9e2008-04-28 02:15:34 -0700879 out_be32(&hw->wb_size, 0); /* WB SIZE */
880 out_be32(&hw->wb_mem_addr, 0); /* WB MEM ADDR */
881
882 /* Horizontal and vertical configuration register */
883 temp = var->left_margin << 22 | /* BP_H */
884 var->hsync_len << 11 | /* PW_H */
885 var->right_margin; /* FP_H */
886
887 out_be32(&hw->hsyn_para, temp);
888
889 temp = var->upper_margin << 22 | /* BP_V */
890 var->vsync_len << 11 | /* PW_V */
891 var->lower_margin; /* FP_V */
892
893 out_be32(&hw->vsyn_para, temp);
894
York Sun9b53a9e2008-04-28 02:15:34 -0700895 diu_ops.set_pixel_clock(var->pixclock);
896
897 out_be32(&hw->syn_pol, 0); /* SYNC SIGNALS POLARITY */
898 out_be32(&hw->thresholds, 0x00037800); /* The Thresholds */
899 out_be32(&hw->int_status, 0); /* INTERRUPT STATUS */
900 out_be32(&hw->plut, 0x01F5F666);
901
902 /* Enable the DIU */
903 enable_lcdc(info);
904}
905
906static int map_video_memory(struct fb_info *info)
907{
908 phys_addr_t phys;
Krzysztof Helt537a1bf2009-06-30 11:41:29 -0700909 u32 smem_len = info->fix.line_length * info->var.yres_virtual;
York Sun9b53a9e2008-04-28 02:15:34 -0700910
Krzysztof Helt537a1bf2009-06-30 11:41:29 -0700911 info->screen_base = fsl_diu_alloc(smem_len, &phys);
Anton Vorontsov05946bc2008-07-04 09:59:38 -0700912 if (info->screen_base == NULL) {
Timur Tabi154152a2011-09-15 16:44:47 -0500913 dev_err(info->dev, "unable to allocate fb memory\n");
York Sun9b53a9e2008-04-28 02:15:34 -0700914 return -ENOMEM;
915 }
Krzysztof Helt537a1bf2009-06-30 11:41:29 -0700916 mutex_lock(&info->mm_lock);
York Sun9b53a9e2008-04-28 02:15:34 -0700917 info->fix.smem_start = (unsigned long) phys;
Krzysztof Helt537a1bf2009-06-30 11:41:29 -0700918 info->fix.smem_len = smem_len;
919 mutex_unlock(&info->mm_lock);
York Sun9b53a9e2008-04-28 02:15:34 -0700920 info->screen_size = info->fix.smem_len;
921
York Sun9b53a9e2008-04-28 02:15:34 -0700922 return 0;
923}
924
925static void unmap_video_memory(struct fb_info *info)
926{
927 fsl_diu_free(info->screen_base, info->fix.smem_len);
Krzysztof Helt537a1bf2009-06-30 11:41:29 -0700928 mutex_lock(&info->mm_lock);
Anton Vorontsov05946bc2008-07-04 09:59:38 -0700929 info->screen_base = NULL;
York Sun9b53a9e2008-04-28 02:15:34 -0700930 info->fix.smem_start = 0;
931 info->fix.smem_len = 0;
Krzysztof Helt537a1bf2009-06-30 11:41:29 -0700932 mutex_unlock(&info->mm_lock);
York Sun9b53a9e2008-04-28 02:15:34 -0700933}
934
935/*
York Sunae5591e2008-08-15 00:40:28 -0700936 * Using the fb_var_screeninfo in fb_info we set the aoi of this
937 * particular framebuffer. It is a light version of fsl_diu_set_par.
938 */
939static int fsl_diu_set_aoi(struct fb_info *info)
940{
941 struct fb_var_screeninfo *var = &info->var;
942 struct mfb_info *mfbi = info->par;
943 struct diu_ad *ad = mfbi->ad;
944
945 /* AOI should not be greater than display size */
946 ad->offset_xyi = cpu_to_le32((var->yoffset << 16) | var->xoffset);
947 ad->offset_xyd = cpu_to_le32((mfbi->y_aoi_d << 16) | mfbi->x_aoi_d);
948 return 0;
949}
950
951/*
York Sun9b53a9e2008-04-28 02:15:34 -0700952 * Using the fb_var_screeninfo in fb_info we set the resolution of this
953 * particular framebuffer. This function alters the fb_fix_screeninfo stored
954 * in fb_info. It does not alter var in fb_info since we are using that
955 * data. This means we depend on the data in var inside fb_info to be
956 * supported by the hardware. fsl_diu_check_var is always called before
957 * fsl_diu_set_par to ensure this.
958 */
959static int fsl_diu_set_par(struct fb_info *info)
960{
961 unsigned long len;
962 struct fb_var_screeninfo *var = &info->var;
963 struct mfb_info *mfbi = info->par;
964 struct fsl_diu_data *machine_data = mfbi->parent;
965 struct diu_ad *ad = mfbi->ad;
966 struct diu *hw;
967
968 hw = dr.diu_reg;
969
970 set_fix(info);
971 mfbi->cursor_reset = 1;
972
973 len = info->var.yres_virtual * info->fix.line_length;
974 /* Alloc & dealloc each time resolution/bpp change */
975 if (len != info->fix.smem_len) {
976 if (info->fix.smem_start)
977 unmap_video_memory(info);
York Sun9b53a9e2008-04-28 02:15:34 -0700978
979 /* Memory allocation for framebuffer */
980 if (map_video_memory(info)) {
Timur Tabi154152a2011-09-15 16:44:47 -0500981 dev_err(info->dev, "unable to allocate fb memory 1\n");
York Sun9b53a9e2008-04-28 02:15:34 -0700982 return -ENOMEM;
983 }
984 }
985
Timur Tabi7653aaa2011-07-09 15:38:14 -0500986 ad->pix_fmt = diu_ops.get_pixel_format(machine_data->monitor_port,
987 var->bits_per_pixel);
York Sun9b53a9e2008-04-28 02:15:34 -0700988 ad->addr = cpu_to_le32(info->fix.smem_start);
York Sunae5591e2008-08-15 00:40:28 -0700989 ad->src_size_g_alpha = cpu_to_le32((var->yres_virtual << 12) |
990 var->xres_virtual) | mfbi->g_alpha;
991 /* AOI should not be greater than display size */
York Sun9b53a9e2008-04-28 02:15:34 -0700992 ad->aoi_size = cpu_to_le32((var->yres << 16) | var->xres);
York Sunae5591e2008-08-15 00:40:28 -0700993 ad->offset_xyi = cpu_to_le32((var->yoffset << 16) | var->xoffset);
York Sun9b53a9e2008-04-28 02:15:34 -0700994 ad->offset_xyd = cpu_to_le32((mfbi->y_aoi_d << 16) | mfbi->x_aoi_d);
995
996 /* Disable chroma keying function */
997 ad->ckmax_r = 0;
998 ad->ckmax_g = 0;
999 ad->ckmax_b = 0;
1000
1001 ad->ckmin_r = 255;
1002 ad->ckmin_g = 255;
1003 ad->ckmin_b = 255;
1004
1005 if (mfbi->index == 0)
1006 update_lcdc(info);
1007 return 0;
1008}
1009
1010static inline __u32 CNVT_TOHW(__u32 val, __u32 width)
1011{
Timur Tabi4a85dc8b2011-09-15 16:44:46 -05001012 return ((val << width) + 0x7FFF - val) >> 16;
York Sun9b53a9e2008-04-28 02:15:34 -07001013}
1014
1015/*
1016 * Set a single color register. The values supplied have a 16 bit magnitude
1017 * which needs to be scaled in this function for the hardware. Things to take
1018 * into consideration are how many color registers, if any, are supported with
1019 * the current color visual. With truecolor mode no color palettes are
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001020 * supported. Here a pseudo palette is created which we store the value in
York Sun9b53a9e2008-04-28 02:15:34 -07001021 * pseudo_palette in struct fb_info. For pseudocolor mode we have a limited
1022 * color palette.
1023 */
Timur Tabi4a85dc8b2011-09-15 16:44:46 -05001024static int fsl_diu_setcolreg(unsigned int regno, unsigned int red,
1025 unsigned int green, unsigned int blue,
1026 unsigned int transp, struct fb_info *info)
York Sun9b53a9e2008-04-28 02:15:34 -07001027{
1028 int ret = 1;
1029
1030 /*
1031 * If greyscale is true, then we convert the RGB value
1032 * to greyscale no matter what visual we are using.
1033 */
1034 if (info->var.grayscale)
1035 red = green = blue = (19595 * red + 38470 * green +
1036 7471 * blue) >> 16;
1037 switch (info->fix.visual) {
1038 case FB_VISUAL_TRUECOLOR:
1039 /*
1040 * 16-bit True Colour. We encode the RGB value
1041 * according to the RGB bitfield information.
1042 */
1043 if (regno < 16) {
1044 u32 *pal = info->pseudo_palette;
1045 u32 v;
1046
1047 red = CNVT_TOHW(red, info->var.red.length);
1048 green = CNVT_TOHW(green, info->var.green.length);
1049 blue = CNVT_TOHW(blue, info->var.blue.length);
1050 transp = CNVT_TOHW(transp, info->var.transp.length);
1051
1052 v = (red << info->var.red.offset) |
1053 (green << info->var.green.offset) |
1054 (blue << info->var.blue.offset) |
1055 (transp << info->var.transp.offset);
1056
1057 pal[regno] = v;
1058 ret = 0;
1059 }
1060 break;
York Sun9b53a9e2008-04-28 02:15:34 -07001061 }
1062
1063 return ret;
1064}
1065
1066/*
1067 * Pan (or wrap, depending on the `vmode' field) the display using the
1068 * 'xoffset' and 'yoffset' fields of the 'var' structure. If the values
1069 * don't fit, return -EINVAL.
1070 */
1071static int fsl_diu_pan_display(struct fb_var_screeninfo *var,
1072 struct fb_info *info)
1073{
1074 if ((info->var.xoffset == var->xoffset) &&
1075 (info->var.yoffset == var->yoffset))
1076 return 0; /* No change, do nothing */
1077
1078 if (var->xoffset < 0 || var->yoffset < 0
1079 || var->xoffset + info->var.xres > info->var.xres_virtual
1080 || var->yoffset + info->var.yres > info->var.yres_virtual)
1081 return -EINVAL;
1082
1083 info->var.xoffset = var->xoffset;
1084 info->var.yoffset = var->yoffset;
1085
1086 if (var->vmode & FB_VMODE_YWRAP)
1087 info->var.vmode |= FB_VMODE_YWRAP;
1088 else
1089 info->var.vmode &= ~FB_VMODE_YWRAP;
1090
York Sunae5591e2008-08-15 00:40:28 -07001091 fsl_diu_set_aoi(info);
1092
York Sun9b53a9e2008-04-28 02:15:34 -07001093 return 0;
1094}
1095
York Sun9b53a9e2008-04-28 02:15:34 -07001096static int fsl_diu_ioctl(struct fb_info *info, unsigned int cmd,
1097 unsigned long arg)
1098{
1099 struct mfb_info *mfbi = info->par;
1100 struct diu_ad *ad = mfbi->ad;
1101 struct mfb_chroma_key ck;
1102 unsigned char global_alpha;
1103 struct aoi_display_offset aoi_d;
1104 __u32 pix_fmt;
1105 void __user *buf = (void __user *)arg;
1106
1107 if (!arg)
1108 return -EINVAL;
1109 switch (cmd) {
Timur Tabi36b0b1d2011-10-04 19:36:44 -05001110 case MFB_SET_PIXFMT_OLD:
1111 dev_warn(info->dev,
1112 "MFB_SET_PIXFMT value of 0x%08x is deprecated.\n",
1113 MFB_SET_PIXFMT_OLD);
York Sun9b53a9e2008-04-28 02:15:34 -07001114 case MFB_SET_PIXFMT:
1115 if (copy_from_user(&pix_fmt, buf, sizeof(pix_fmt)))
1116 return -EFAULT;
1117 ad->pix_fmt = pix_fmt;
York Sun9b53a9e2008-04-28 02:15:34 -07001118 break;
Timur Tabi36b0b1d2011-10-04 19:36:44 -05001119 case MFB_GET_PIXFMT_OLD:
1120 dev_warn(info->dev,
1121 "MFB_GET_PIXFMT value of 0x%08x is deprecated.\n",
1122 MFB_GET_PIXFMT_OLD);
York Sun9b53a9e2008-04-28 02:15:34 -07001123 case MFB_GET_PIXFMT:
1124 pix_fmt = ad->pix_fmt;
1125 if (copy_to_user(buf, &pix_fmt, sizeof(pix_fmt)))
1126 return -EFAULT;
York Sun9b53a9e2008-04-28 02:15:34 -07001127 break;
1128 case MFB_SET_AOID:
1129 if (copy_from_user(&aoi_d, buf, sizeof(aoi_d)))
1130 return -EFAULT;
1131 mfbi->x_aoi_d = aoi_d.x_aoi_d;
1132 mfbi->y_aoi_d = aoi_d.y_aoi_d;
York Sun9b53a9e2008-04-28 02:15:34 -07001133 fsl_diu_check_var(&info->var, info);
York Sunae5591e2008-08-15 00:40:28 -07001134 fsl_diu_set_aoi(info);
York Sun9b53a9e2008-04-28 02:15:34 -07001135 break;
1136 case MFB_GET_AOID:
1137 aoi_d.x_aoi_d = mfbi->x_aoi_d;
1138 aoi_d.y_aoi_d = mfbi->y_aoi_d;
1139 if (copy_to_user(buf, &aoi_d, sizeof(aoi_d)))
1140 return -EFAULT;
York Sun9b53a9e2008-04-28 02:15:34 -07001141 break;
1142 case MFB_GET_ALPHA:
1143 global_alpha = mfbi->g_alpha;
1144 if (copy_to_user(buf, &global_alpha, sizeof(global_alpha)))
1145 return -EFAULT;
York Sun9b53a9e2008-04-28 02:15:34 -07001146 break;
1147 case MFB_SET_ALPHA:
1148 /* set panel information */
1149 if (copy_from_user(&global_alpha, buf, sizeof(global_alpha)))
1150 return -EFAULT;
1151 ad->src_size_g_alpha = (ad->src_size_g_alpha & (~0xff)) |
1152 (global_alpha & 0xff);
1153 mfbi->g_alpha = global_alpha;
York Sun9b53a9e2008-04-28 02:15:34 -07001154 break;
1155 case MFB_SET_CHROMA_KEY:
1156 /* set panel winformation */
1157 if (copy_from_user(&ck, buf, sizeof(ck)))
1158 return -EFAULT;
1159
1160 if (ck.enable &&
1161 (ck.red_max < ck.red_min ||
1162 ck.green_max < ck.green_min ||
1163 ck.blue_max < ck.blue_min))
1164 return -EINVAL;
1165
1166 if (!ck.enable) {
1167 ad->ckmax_r = 0;
1168 ad->ckmax_g = 0;
1169 ad->ckmax_b = 0;
1170 ad->ckmin_r = 255;
1171 ad->ckmin_g = 255;
1172 ad->ckmin_b = 255;
1173 } else {
1174 ad->ckmax_r = ck.red_max;
1175 ad->ckmax_g = ck.green_max;
1176 ad->ckmax_b = ck.blue_max;
1177 ad->ckmin_r = ck.red_min;
1178 ad->ckmin_g = ck.green_min;
1179 ad->ckmin_b = ck.blue_min;
1180 }
York Sun9b53a9e2008-04-28 02:15:34 -07001181 break;
York Sun9b53a9e2008-04-28 02:15:34 -07001182 default:
Timur Tabi154152a2011-09-15 16:44:47 -05001183 dev_err(info->dev, "unknown ioctl command (0x%08X)\n", cmd);
York Sun9b53a9e2008-04-28 02:15:34 -07001184 return -ENOIOCTLCMD;
1185 }
1186
1187 return 0;
1188}
1189
1190/* turn on fb if count == 1
1191 */
1192static int fsl_diu_open(struct fb_info *info, int user)
1193{
1194 struct mfb_info *mfbi = info->par;
1195 int res = 0;
1196
Anatolij Gustschin4b5006e2010-07-23 04:00:37 +00001197 /* free boot splash memory on first /dev/fb0 open */
1198 if (!mfbi->index && diu_ops.release_bootmem)
1199 diu_ops.release_bootmem();
1200
York Sun9b53a9e2008-04-28 02:15:34 -07001201 spin_lock(&diu_lock);
1202 mfbi->count++;
1203 if (mfbi->count == 1) {
York Sun9b53a9e2008-04-28 02:15:34 -07001204 fsl_diu_check_var(&info->var, info);
1205 res = fsl_diu_set_par(info);
1206 if (res < 0)
1207 mfbi->count--;
1208 else {
1209 res = fsl_diu_enable_panel(info);
1210 if (res < 0)
1211 mfbi->count--;
1212 }
1213 }
1214
1215 spin_unlock(&diu_lock);
1216 return res;
1217}
1218
1219/* turn off fb if count == 0
1220 */
1221static int fsl_diu_release(struct fb_info *info, int user)
1222{
1223 struct mfb_info *mfbi = info->par;
1224 int res = 0;
1225
1226 spin_lock(&diu_lock);
1227 mfbi->count--;
1228 if (mfbi->count == 0) {
York Sun9b53a9e2008-04-28 02:15:34 -07001229 res = fsl_diu_disable_panel(info);
1230 if (res < 0)
1231 mfbi->count++;
1232 }
1233 spin_unlock(&diu_lock);
1234 return res;
1235}
1236
1237static struct fb_ops fsl_diu_ops = {
1238 .owner = THIS_MODULE,
1239 .fb_check_var = fsl_diu_check_var,
1240 .fb_set_par = fsl_diu_set_par,
1241 .fb_setcolreg = fsl_diu_setcolreg,
York Sun9b53a9e2008-04-28 02:15:34 -07001242 .fb_pan_display = fsl_diu_pan_display,
1243 .fb_fillrect = cfb_fillrect,
1244 .fb_copyarea = cfb_copyarea,
1245 .fb_imageblit = cfb_imageblit,
1246 .fb_ioctl = fsl_diu_ioctl,
1247 .fb_open = fsl_diu_open,
1248 .fb_release = fsl_diu_release,
1249};
1250
1251static int init_fbinfo(struct fb_info *info)
1252{
1253 struct mfb_info *mfbi = info->par;
1254
1255 info->device = NULL;
1256 info->var.activate = FB_ACTIVATE_NOW;
1257 info->fbops = &fsl_diu_ops;
1258 info->flags = FBINFO_FLAG_DEFAULT;
1259 info->pseudo_palette = &mfbi->pseudo_palette;
1260
1261 /* Allocate colormap */
1262 fb_alloc_cmap(&info->cmap, 16, 0);
1263 return 0;
1264}
1265
Anton Vorontsov05946bc2008-07-04 09:59:38 -07001266static int __devinit install_fb(struct fb_info *info)
York Sun9b53a9e2008-04-28 02:15:34 -07001267{
1268 int rc;
1269 struct mfb_info *mfbi = info->par;
1270 const char *aoi_mode, *init_aoi_mode = "320x240";
Anatolij Gustschin8b856f02010-07-23 04:00:39 +00001271 struct fb_videomode *db = fsl_diu_mode_db;
1272 unsigned int dbsize = ARRAY_SIZE(fsl_diu_mode_db);
1273 int has_default_mode = 1;
York Sun9b53a9e2008-04-28 02:15:34 -07001274
1275 if (init_fbinfo(info))
1276 return -EINVAL;
1277
Anatolij Gustschin8b856f02010-07-23 04:00:39 +00001278 if (mfbi->index == 0) { /* plane 0 */
1279 if (mfbi->edid_data) {
1280 /* Now build modedb from EDID */
1281 fb_edid_to_monspecs(mfbi->edid_data, &info->monspecs);
1282 fb_videomode_to_modelist(info->monspecs.modedb,
1283 info->monspecs.modedb_len,
1284 &info->modelist);
1285 db = info->monspecs.modedb;
1286 dbsize = info->monspecs.modedb_len;
1287 }
York Sun9b53a9e2008-04-28 02:15:34 -07001288 aoi_mode = fb_mode;
Anatolij Gustschin8b856f02010-07-23 04:00:39 +00001289 } else {
York Sun9b53a9e2008-04-28 02:15:34 -07001290 aoi_mode = init_aoi_mode;
Anatolij Gustschin8b856f02010-07-23 04:00:39 +00001291 }
Timur Tabi63cf8df2011-09-15 16:44:51 -05001292 rc = fb_find_mode(&info->var, info, aoi_mode, db, dbsize, NULL,
1293 default_bpp);
Timur Tabi154152a2011-09-15 16:44:47 -05001294 if (!rc) {
Anatolij Gustschin8b856f02010-07-23 04:00:39 +00001295 /*
1296 * For plane 0 we continue and look into
1297 * driver's internal modedb.
1298 */
1299 if (mfbi->index == 0 && mfbi->edid_data)
1300 has_default_mode = 0;
1301 else
1302 return -EINVAL;
York Sun9b53a9e2008-04-28 02:15:34 -07001303 }
1304
Anatolij Gustschin8b856f02010-07-23 04:00:39 +00001305 if (!has_default_mode) {
1306 rc = fb_find_mode(&info->var, info, aoi_mode, fsl_diu_mode_db,
Timur Tabi63cf8df2011-09-15 16:44:51 -05001307 ARRAY_SIZE(fsl_diu_mode_db), NULL, default_bpp);
1308 if (rc)
Anatolij Gustschin8b856f02010-07-23 04:00:39 +00001309 has_default_mode = 1;
1310 }
1311
1312 /* Still not found, use preferred mode from database if any */
1313 if (!has_default_mode && info->monspecs.modedb) {
1314 struct fb_monspecs *specs = &info->monspecs;
1315 struct fb_videomode *modedb = &specs->modedb[0];
1316
1317 /*
1318 * Get preferred timing. If not found,
1319 * first mode in database will be used.
1320 */
1321 if (specs->misc & FB_MISC_1ST_DETAIL) {
1322 int i;
1323
1324 for (i = 0; i < specs->modedb_len; i++) {
1325 if (specs->modedb[i].flag & FB_MODE_IS_FIRST) {
1326 modedb = &specs->modedb[i];
1327 break;
1328 }
1329 }
1330 }
1331
1332 info->var.bits_per_pixel = default_bpp;
1333 fb_videomode_to_var(&info->var, modedb);
1334 }
1335
York Sun9b53a9e2008-04-28 02:15:34 -07001336 if (fsl_diu_check_var(&info->var, info)) {
Timur Tabi154152a2011-09-15 16:44:47 -05001337 dev_err(info->dev, "fsl_diu_check_var failed\n");
Timur Tabi589c7972011-09-15 16:44:55 -05001338 unmap_video_memory(info);
York Sun9b53a9e2008-04-28 02:15:34 -07001339 fb_dealloc_cmap(&info->cmap);
1340 return -EINVAL;
1341 }
1342
York Sun9b53a9e2008-04-28 02:15:34 -07001343 if (register_framebuffer(info) < 0) {
Timur Tabi154152a2011-09-15 16:44:47 -05001344 dev_err(info->dev, "register_framebuffer failed\n");
York Sun9b53a9e2008-04-28 02:15:34 -07001345 unmap_video_memory(info);
1346 fb_dealloc_cmap(&info->cmap);
1347 return -EINVAL;
1348 }
1349
1350 mfbi->registered = 1;
Timur Tabi154152a2011-09-15 16:44:47 -05001351 dev_info(info->dev, "%s registered successfully\n", mfbi->id);
York Sun9b53a9e2008-04-28 02:15:34 -07001352
1353 return 0;
1354}
1355
Anton Vorontsov05946bc2008-07-04 09:59:38 -07001356static void uninstall_fb(struct fb_info *info)
York Sun9b53a9e2008-04-28 02:15:34 -07001357{
1358 struct mfb_info *mfbi = info->par;
1359
1360 if (!mfbi->registered)
1361 return;
1362
Anatolij Gustschin8b856f02010-07-23 04:00:39 +00001363 if (mfbi->index == 0)
1364 kfree(mfbi->edid_data);
1365
York Sun9b53a9e2008-04-28 02:15:34 -07001366 unregister_framebuffer(info);
1367 unmap_video_memory(info);
1368 if (&info->cmap)
1369 fb_dealloc_cmap(&info->cmap);
1370
1371 mfbi->registered = 0;
1372}
1373
1374static irqreturn_t fsl_diu_isr(int irq, void *dev_id)
1375{
1376 struct diu *hw = dr.diu_reg;
1377 unsigned int status = in_be32(&hw->int_status);
1378
1379 if (status) {
1380 /* This is the workaround for underrun */
1381 if (status & INT_UNDRUN) {
1382 out_be32(&hw->diu_mode, 0);
York Sun9b53a9e2008-04-28 02:15:34 -07001383 udelay(1);
1384 out_be32(&hw->diu_mode, 1);
1385 }
1386#if defined(CONFIG_NOT_COHERENT_CACHE)
1387 else if (status & INT_VSYNC) {
1388 unsigned int i;
Timur Tabi4a85dc8b2011-09-15 16:44:46 -05001389
York Sun9b53a9e2008-04-28 02:15:34 -07001390 for (i = 0; i < coherence_data_size;
1391 i += d_cache_line_size)
1392 __asm__ __volatile__ (
1393 "dcbz 0, %[input]"
1394 ::[input]"r"(&coherence_data[i]));
1395 }
1396#endif
1397 return IRQ_HANDLED;
1398 }
1399 return IRQ_NONE;
1400}
1401
1402static int request_irq_local(int irq)
1403{
Timur Tabibada04f2011-09-15 16:44:52 -05001404 u32 ints;
York Sun9b53a9e2008-04-28 02:15:34 -07001405 struct diu *hw;
1406 int ret;
1407
1408 hw = dr.diu_reg;
1409
1410 /* Read to clear the status */
Timur Tabibada04f2011-09-15 16:44:52 -05001411 in_be32(&hw->int_status);
York Sun9b53a9e2008-04-28 02:15:34 -07001412
Timur Tabif8c6bf62011-09-15 16:44:53 -05001413 ret = request_irq(irq, fsl_diu_isr, 0, "fsl-diu-fb", NULL);
Timur Tabi154152a2011-09-15 16:44:47 -05001414 if (!ret) {
York Sun9b53a9e2008-04-28 02:15:34 -07001415 ints = INT_PARERR | INT_LS_BF_VS;
1416#if !defined(CONFIG_NOT_COHERENT_CACHE)
1417 ints |= INT_VSYNC;
1418#endif
Timur Tabi4a85dc8b2011-09-15 16:44:46 -05001419
York Sun9b53a9e2008-04-28 02:15:34 -07001420 if (dr.mode == MFB_MODE2 || dr.mode == MFB_MODE3)
1421 ints |= INT_VSYNC_WB;
1422
1423 /* Read to clear the status */
Timur Tabibada04f2011-09-15 16:44:52 -05001424 in_be32(&hw->int_status);
York Sun9b53a9e2008-04-28 02:15:34 -07001425 out_be32(&hw->int_mask, ints);
1426 }
Timur Tabi4a85dc8b2011-09-15 16:44:46 -05001427
York Sun9b53a9e2008-04-28 02:15:34 -07001428 return ret;
1429}
1430
1431static void free_irq_local(int irq)
1432{
1433 struct diu *hw = dr.diu_reg;
1434
1435 /* Disable all LCDC interrupt */
1436 out_be32(&hw->int_mask, 0x1f);
1437
Anton Vorontsov05946bc2008-07-04 09:59:38 -07001438 free_irq(irq, NULL);
York Sun9b53a9e2008-04-28 02:15:34 -07001439}
1440
1441#ifdef CONFIG_PM
1442/*
1443 * Power management hooks. Note that we won't be called from IRQ context,
1444 * unlike the blank functions above, so we may sleep.
1445 */
Grant Likely2dc11582010-08-06 09:25:50 -06001446static int fsl_diu_suspend(struct platform_device *ofdev, pm_message_t state)
York Sun9b53a9e2008-04-28 02:15:34 -07001447{
1448 struct fsl_diu_data *machine_data;
1449
Takashi Iwai48948a32008-07-08 18:41:17 +02001450 machine_data = dev_get_drvdata(&ofdev->dev);
York Sun9b53a9e2008-04-28 02:15:34 -07001451 disable_lcdc(machine_data->fsl_diu_info[0]);
1452
1453 return 0;
1454}
1455
Grant Likely2dc11582010-08-06 09:25:50 -06001456static int fsl_diu_resume(struct platform_device *ofdev)
York Sun9b53a9e2008-04-28 02:15:34 -07001457{
1458 struct fsl_diu_data *machine_data;
1459
Takashi Iwai48948a32008-07-08 18:41:17 +02001460 machine_data = dev_get_drvdata(&ofdev->dev);
York Sun9b53a9e2008-04-28 02:15:34 -07001461 enable_lcdc(machine_data->fsl_diu_info[0]);
1462
1463 return 0;
1464}
1465
1466#else
1467#define fsl_diu_suspend NULL
1468#define fsl_diu_resume NULL
1469#endif /* CONFIG_PM */
1470
1471/* Align to 64-bit(8-byte), 32-byte, etc. */
Anton Vorontsovf3791882009-04-04 22:31:20 +04001472static int allocate_buf(struct device *dev, struct diu_addr *buf, u32 size,
1473 u32 bytes_align)
York Sun9b53a9e2008-04-28 02:15:34 -07001474{
Timur Tabibada04f2011-09-15 16:44:52 -05001475 u32 offset;
1476 dma_addr_t mask;
York Sun9b53a9e2008-04-28 02:15:34 -07001477
Timur Tabibada04f2011-09-15 16:44:52 -05001478 buf->vaddr =
1479 dma_alloc_coherent(dev, size + bytes_align, &buf->paddr,
1480 GFP_DMA | __GFP_ZERO);
York Sun9b53a9e2008-04-28 02:15:34 -07001481 if (!buf->vaddr)
1482 return -ENOMEM;
1483
York Sun9b53a9e2008-04-28 02:15:34 -07001484 mask = bytes_align - 1;
Timur Tabibada04f2011-09-15 16:44:52 -05001485 offset = buf->paddr & mask;
York Sun9b53a9e2008-04-28 02:15:34 -07001486 if (offset) {
1487 buf->offset = bytes_align - offset;
Timur Tabibada04f2011-09-15 16:44:52 -05001488 buf->paddr = buf->paddr + offset;
York Sun9b53a9e2008-04-28 02:15:34 -07001489 } else
1490 buf->offset = 0;
Timur Tabi4a85dc8b2011-09-15 16:44:46 -05001491
York Sun9b53a9e2008-04-28 02:15:34 -07001492 return 0;
1493}
1494
Anton Vorontsovf3791882009-04-04 22:31:20 +04001495static void free_buf(struct device *dev, struct diu_addr *buf, u32 size,
1496 u32 bytes_align)
York Sun9b53a9e2008-04-28 02:15:34 -07001497{
Timur Tabi4a85dc8b2011-09-15 16:44:46 -05001498 dma_free_coherent(dev, size + bytes_align, buf->vaddr,
1499 buf->paddr - buf->offset);
York Sun9b53a9e2008-04-28 02:15:34 -07001500}
1501
1502static ssize_t store_monitor(struct device *device,
1503 struct device_attribute *attr, const char *buf, size_t count)
1504{
Timur Tabi7653aaa2011-07-09 15:38:14 -05001505 enum fsl_diu_monitor_port old_monitor_port;
York Sun9b53a9e2008-04-28 02:15:34 -07001506 struct fsl_diu_data *machine_data =
1507 container_of(attr, struct fsl_diu_data, dev_attr);
1508
York Sun9b53a9e2008-04-28 02:15:34 -07001509 old_monitor_port = machine_data->monitor_port;
Timur Tabi7653aaa2011-07-09 15:38:14 -05001510 machine_data->monitor_port = fsl_diu_name_to_port(buf);
York Sun9b53a9e2008-04-28 02:15:34 -07001511
1512 if (old_monitor_port != machine_data->monitor_port) {
1513 /* All AOIs need adjust pixel format
1514 * fsl_diu_set_par only change the pixsel format here
1515 * unlikely to fail. */
1516 fsl_diu_set_par(machine_data->fsl_diu_info[0]);
1517 fsl_diu_set_par(machine_data->fsl_diu_info[1]);
1518 fsl_diu_set_par(machine_data->fsl_diu_info[2]);
1519 fsl_diu_set_par(machine_data->fsl_diu_info[3]);
1520 fsl_diu_set_par(machine_data->fsl_diu_info[4]);
1521 }
1522 return count;
1523}
1524
1525static ssize_t show_monitor(struct device *device,
1526 struct device_attribute *attr, char *buf)
1527{
1528 struct fsl_diu_data *machine_data =
1529 container_of(attr, struct fsl_diu_data, dev_attr);
Timur Tabi7653aaa2011-07-09 15:38:14 -05001530
1531 switch (machine_data->monitor_port) {
1532 case FSL_DIU_PORT_DVI:
1533 return sprintf(buf, "DVI\n");
1534 case FSL_DIU_PORT_LVDS:
1535 return sprintf(buf, "Single-link LVDS\n");
1536 case FSL_DIU_PORT_DLVDS:
1537 return sprintf(buf, "Dual-link LVDS\n");
1538 }
1539
1540 return 0;
York Sun9b53a9e2008-04-28 02:15:34 -07001541}
1542
Timur Tabi9e52ba62011-09-15 16:44:50 -05001543static int __devinit fsl_diu_probe(struct platform_device *pdev)
York Sun9b53a9e2008-04-28 02:15:34 -07001544{
Timur Tabi9e52ba62011-09-15 16:44:50 -05001545 struct device_node *np = pdev->dev.of_node;
York Sun9b53a9e2008-04-28 02:15:34 -07001546 struct mfb_info *mfbi;
Timur Tabi89f08e32011-09-15 16:44:49 -05001547 phys_addr_t dummy_ad_addr = 0;
York Sun9b53a9e2008-04-28 02:15:34 -07001548 int ret, i, error = 0;
York Sun9b53a9e2008-04-28 02:15:34 -07001549 struct fsl_diu_data *machine_data;
Anatolij Gustschin4b5006e2010-07-23 04:00:37 +00001550 int diu_mode;
York Sun9b53a9e2008-04-28 02:15:34 -07001551
1552 machine_data = kzalloc(sizeof(struct fsl_diu_data), GFP_KERNEL);
1553 if (!machine_data)
1554 return -ENOMEM;
1555
1556 for (i = 0; i < ARRAY_SIZE(machine_data->fsl_diu_info); i++) {
1557 machine_data->fsl_diu_info[i] =
Timur Tabi9e52ba62011-09-15 16:44:50 -05001558 framebuffer_alloc(sizeof(struct mfb_info), &pdev->dev);
York Sun9b53a9e2008-04-28 02:15:34 -07001559 if (!machine_data->fsl_diu_info[i]) {
Timur Tabi9e52ba62011-09-15 16:44:50 -05001560 dev_err(&pdev->dev, "cannot allocate memory\n");
York Sun9b53a9e2008-04-28 02:15:34 -07001561 ret = -ENOMEM;
1562 goto error2;
1563 }
1564 mfbi = machine_data->fsl_diu_info[i]->par;
1565 memcpy(mfbi, &mfb_template[i], sizeof(struct mfb_info));
1566 mfbi->parent = machine_data;
Anatolij Gustschin8b856f02010-07-23 04:00:39 +00001567
1568 if (mfbi->index == 0) {
1569 const u8 *prop;
1570 int len;
1571
1572 /* Get EDID */
1573 prop = of_get_property(np, "edid", &len);
1574 if (prop && len == EDID_LENGTH)
1575 mfbi->edid_data = kmemdup(prop, EDID_LENGTH,
1576 GFP_KERNEL);
1577 }
York Sun9b53a9e2008-04-28 02:15:34 -07001578 }
1579
Timur Tabi9e52ba62011-09-15 16:44:50 -05001580 dr.diu_reg = of_iomap(np, 0);
York Sun9b53a9e2008-04-28 02:15:34 -07001581 if (!dr.diu_reg) {
Timur Tabi9e52ba62011-09-15 16:44:50 -05001582 dev_err(&pdev->dev, "cannot map DIU registers\n");
York Sun9b53a9e2008-04-28 02:15:34 -07001583 ret = -EFAULT;
1584 goto error2;
1585 }
1586
Anatolij Gustschin4b5006e2010-07-23 04:00:37 +00001587 diu_mode = in_be32(&dr.diu_reg->diu_mode);
1588 if (diu_mode != MFB_MODE1)
1589 out_be32(&dr.diu_reg->diu_mode, 0); /* disable DIU */
York Sun9b53a9e2008-04-28 02:15:34 -07001590
1591 /* Get the IRQ of the DIU */
1592 machine_data->irq = irq_of_parse_and_map(np, 0);
1593
1594 if (!machine_data->irq) {
Timur Tabi9e52ba62011-09-15 16:44:50 -05001595 dev_err(&pdev->dev, "could not get DIU IRQ\n");
York Sun9b53a9e2008-04-28 02:15:34 -07001596 ret = -EINVAL;
1597 goto error;
1598 }
1599 machine_data->monitor_port = monitor_port;
1600
1601 /* Area descriptor memory pool aligns to 64-bit boundary */
Timur Tabi9e52ba62011-09-15 16:44:50 -05001602 if (allocate_buf(&pdev->dev, &pool.ad,
Anton Vorontsovf3791882009-04-04 22:31:20 +04001603 sizeof(struct diu_ad) * FSL_AOI_NUM, 8))
York Sun9b53a9e2008-04-28 02:15:34 -07001604 return -ENOMEM;
1605
1606 /* Get memory for Gamma Table - 32-byte aligned memory */
Timur Tabi9e52ba62011-09-15 16:44:50 -05001607 if (allocate_buf(&pdev->dev, &pool.gamma, 768, 32)) {
York Sun9b53a9e2008-04-28 02:15:34 -07001608 ret = -ENOMEM;
1609 goto error;
1610 }
1611
1612 /* For performance, cursor bitmap buffer aligns to 32-byte boundary */
Timur Tabi9e52ba62011-09-15 16:44:50 -05001613 if (allocate_buf(&pdev->dev, &pool.cursor, MAX_CURS * MAX_CURS * 2,
Anton Vorontsovf3791882009-04-04 22:31:20 +04001614 32)) {
York Sun9b53a9e2008-04-28 02:15:34 -07001615 ret = -ENOMEM;
1616 goto error;
1617 }
1618
1619 i = ARRAY_SIZE(machine_data->fsl_diu_info);
1620 machine_data->dummy_ad = (struct diu_ad *)
1621 ((u32)pool.ad.vaddr + pool.ad.offset) + i;
1622 machine_data->dummy_ad->paddr = pool.ad.paddr +
1623 i * sizeof(struct diu_ad);
1624 machine_data->dummy_aoi_virt = fsl_diu_alloc(64, &dummy_ad_addr);
1625 if (!machine_data->dummy_aoi_virt) {
1626 ret = -ENOMEM;
1627 goto error;
1628 }
1629 machine_data->dummy_ad->addr = cpu_to_le32(dummy_ad_addr);
1630 machine_data->dummy_ad->pix_fmt = 0x88882317;
1631 machine_data->dummy_ad->src_size_g_alpha = cpu_to_le32((4 << 12) | 4);
1632 machine_data->dummy_ad->aoi_size = cpu_to_le32((4 << 16) | 2);
1633 machine_data->dummy_ad->offset_xyi = 0;
1634 machine_data->dummy_ad->offset_xyd = 0;
1635 machine_data->dummy_ad->next_ad = 0;
1636
Anatolij Gustschin4b5006e2010-07-23 04:00:37 +00001637 /*
1638 * Let DIU display splash screen if it was pre-initialized
1639 * by the bootloader, set dummy area descriptor otherwise.
1640 */
1641 if (diu_mode != MFB_MODE1)
1642 out_be32(&dr.diu_reg->desc[0], machine_data->dummy_ad->paddr);
1643
York Sun9b53a9e2008-04-28 02:15:34 -07001644 out_be32(&dr.diu_reg->desc[1], machine_data->dummy_ad->paddr);
1645 out_be32(&dr.diu_reg->desc[2], machine_data->dummy_ad->paddr);
1646
1647 for (i = 0; i < ARRAY_SIZE(machine_data->fsl_diu_info); i++) {
1648 machine_data->fsl_diu_info[i]->fix.smem_start = 0;
1649 mfbi = machine_data->fsl_diu_info[i]->par;
1650 mfbi->ad = (struct diu_ad *)((u32)pool.ad.vaddr
1651 + pool.ad.offset) + i;
1652 mfbi->ad->paddr = pool.ad.paddr + i * sizeof(struct diu_ad);
1653 ret = install_fb(machine_data->fsl_diu_info[i]);
1654 if (ret) {
Timur Tabi9e52ba62011-09-15 16:44:50 -05001655 dev_err(&pdev->dev, "could not register fb %d\n", i);
York Sun9b53a9e2008-04-28 02:15:34 -07001656 goto error;
1657 }
1658 }
1659
1660 if (request_irq_local(machine_data->irq)) {
Timur Tabi9e52ba62011-09-15 16:44:50 -05001661 dev_err(&pdev->dev, "could not claim irq\n");
York Sun9b53a9e2008-04-28 02:15:34 -07001662 goto error;
1663 }
1664
Wolfram Sang12765512010-04-06 14:34:52 -07001665 sysfs_attr_init(&machine_data->dev_attr.attr);
York Sun9b53a9e2008-04-28 02:15:34 -07001666 machine_data->dev_attr.attr.name = "monitor";
1667 machine_data->dev_attr.attr.mode = S_IRUGO|S_IWUSR;
1668 machine_data->dev_attr.show = show_monitor;
1669 machine_data->dev_attr.store = store_monitor;
1670 error = device_create_file(machine_data->fsl_diu_info[0]->dev,
1671 &machine_data->dev_attr);
1672 if (error) {
Timur Tabi9e52ba62011-09-15 16:44:50 -05001673 dev_err(&pdev->dev, "could not create sysfs file %s\n",
York Sun9b53a9e2008-04-28 02:15:34 -07001674 machine_data->dev_attr.attr.name);
1675 }
1676
Timur Tabi9e52ba62011-09-15 16:44:50 -05001677 dev_set_drvdata(&pdev->dev, machine_data);
York Sun9b53a9e2008-04-28 02:15:34 -07001678 return 0;
1679
1680error:
Timur Tabi3f78bbd2011-09-15 16:44:56 -05001681 for (i = 0; i < ARRAY_SIZE(machine_data->fsl_diu_info); i++)
1682 uninstall_fb(machine_data->fsl_diu_info[i]);
1683
York Sun9b53a9e2008-04-28 02:15:34 -07001684 if (pool.ad.vaddr)
Timur Tabi9e52ba62011-09-15 16:44:50 -05001685 free_buf(&pdev->dev, &pool.ad,
Anton Vorontsovf3791882009-04-04 22:31:20 +04001686 sizeof(struct diu_ad) * FSL_AOI_NUM, 8);
York Sun9b53a9e2008-04-28 02:15:34 -07001687 if (pool.gamma.vaddr)
Timur Tabi9e52ba62011-09-15 16:44:50 -05001688 free_buf(&pdev->dev, &pool.gamma, 768, 32);
York Sun9b53a9e2008-04-28 02:15:34 -07001689 if (pool.cursor.vaddr)
Timur Tabi9e52ba62011-09-15 16:44:50 -05001690 free_buf(&pdev->dev, &pool.cursor, MAX_CURS * MAX_CURS * 2,
Anton Vorontsovf3791882009-04-04 22:31:20 +04001691 32);
York Sun9b53a9e2008-04-28 02:15:34 -07001692 if (machine_data->dummy_aoi_virt)
1693 fsl_diu_free(machine_data->dummy_aoi_virt, 64);
1694 iounmap(dr.diu_reg);
1695
1696error2:
1697 for (i = 0; i < ARRAY_SIZE(machine_data->fsl_diu_info); i++)
1698 if (machine_data->fsl_diu_info[i])
1699 framebuffer_release(machine_data->fsl_diu_info[i]);
1700 kfree(machine_data);
1701
1702 return ret;
1703}
1704
Timur Tabi9e52ba62011-09-15 16:44:50 -05001705static int fsl_diu_remove(struct platform_device *pdev)
York Sun9b53a9e2008-04-28 02:15:34 -07001706{
1707 struct fsl_diu_data *machine_data;
1708 int i;
1709
Timur Tabi9e52ba62011-09-15 16:44:50 -05001710 machine_data = dev_get_drvdata(&pdev->dev);
York Sun9b53a9e2008-04-28 02:15:34 -07001711 disable_lcdc(machine_data->fsl_diu_info[0]);
1712 free_irq_local(machine_data->irq);
Timur Tabi3f78bbd2011-09-15 16:44:56 -05001713 for (i = 0; i < ARRAY_SIZE(machine_data->fsl_diu_info); i++)
1714 uninstall_fb(machine_data->fsl_diu_info[i]);
York Sun9b53a9e2008-04-28 02:15:34 -07001715 if (pool.ad.vaddr)
Timur Tabi9e52ba62011-09-15 16:44:50 -05001716 free_buf(&pdev->dev, &pool.ad,
Anton Vorontsovf3791882009-04-04 22:31:20 +04001717 sizeof(struct diu_ad) * FSL_AOI_NUM, 8);
York Sun9b53a9e2008-04-28 02:15:34 -07001718 if (pool.gamma.vaddr)
Timur Tabi9e52ba62011-09-15 16:44:50 -05001719 free_buf(&pdev->dev, &pool.gamma, 768, 32);
York Sun9b53a9e2008-04-28 02:15:34 -07001720 if (pool.cursor.vaddr)
Timur Tabi9e52ba62011-09-15 16:44:50 -05001721 free_buf(&pdev->dev, &pool.cursor, MAX_CURS * MAX_CURS * 2, 32);
York Sun9b53a9e2008-04-28 02:15:34 -07001722 if (machine_data->dummy_aoi_virt)
1723 fsl_diu_free(machine_data->dummy_aoi_virt, 64);
1724 iounmap(dr.diu_reg);
1725 for (i = 0; i < ARRAY_SIZE(machine_data->fsl_diu_info); i++)
1726 if (machine_data->fsl_diu_info[i])
1727 framebuffer_release(machine_data->fsl_diu_info[i]);
1728 kfree(machine_data);
1729
1730 return 0;
1731}
1732
1733#ifndef MODULE
1734static int __init fsl_diu_setup(char *options)
1735{
1736 char *opt;
1737 unsigned long val;
1738
1739 if (!options || !*options)
1740 return 0;
1741
1742 while ((opt = strsep(&options, ",")) != NULL) {
1743 if (!*opt)
1744 continue;
1745 if (!strncmp(opt, "monitor=", 8)) {
Timur Tabi7653aaa2011-07-09 15:38:14 -05001746 monitor_port = fsl_diu_name_to_port(opt + 8);
York Sun9b53a9e2008-04-28 02:15:34 -07001747 } else if (!strncmp(opt, "bpp=", 4)) {
1748 if (!strict_strtoul(opt + 4, 10, &val))
1749 default_bpp = val;
1750 } else
1751 fb_mode = opt;
1752 }
1753
1754 return 0;
1755}
1756#endif
1757
1758static struct of_device_id fsl_diu_match[] = {
Anatolij Gustschind24720a2010-02-17 07:33:22 -07001759#ifdef CONFIG_PPC_MPC512x
1760 {
1761 .compatible = "fsl,mpc5121-diu",
1762 },
1763#endif
York Sun9b53a9e2008-04-28 02:15:34 -07001764 {
1765 .compatible = "fsl,diu",
1766 },
1767 {}
1768};
1769MODULE_DEVICE_TABLE(of, fsl_diu_match);
1770
Grant Likely28541d02011-02-22 21:07:43 -07001771static struct platform_driver fsl_diu_driver = {
Grant Likely40182942010-04-13 16:13:02 -07001772 .driver = {
Timur Tabif8c6bf62011-09-15 16:44:53 -05001773 .name = "fsl-diu-fb",
Grant Likely40182942010-04-13 16:13:02 -07001774 .owner = THIS_MODULE,
1775 .of_match_table = fsl_diu_match,
1776 },
York Sun9b53a9e2008-04-28 02:15:34 -07001777 .probe = fsl_diu_probe,
1778 .remove = fsl_diu_remove,
1779 .suspend = fsl_diu_suspend,
1780 .resume = fsl_diu_resume,
1781};
1782
1783static int __init fsl_diu_init(void)
1784{
1785#ifdef CONFIG_NOT_COHERENT_CACHE
1786 struct device_node *np;
1787 const u32 *prop;
1788#endif
1789 int ret;
1790#ifndef MODULE
1791 char *option;
1792
1793 /*
1794 * For kernel boot options (in 'video=xxxfb:<options>' format)
1795 */
1796 if (fb_get_options("fslfb", &option))
1797 return -ENODEV;
1798 fsl_diu_setup(option);
Timur Tabi7653aaa2011-07-09 15:38:14 -05001799#else
1800 monitor_port = fsl_diu_name_to_port(monitor_string);
York Sun9b53a9e2008-04-28 02:15:34 -07001801#endif
Timur Tabi154152a2011-09-15 16:44:47 -05001802 pr_info("Freescale Display Interface Unit (DIU) framebuffer driver\n");
York Sun9b53a9e2008-04-28 02:15:34 -07001803
1804#ifdef CONFIG_NOT_COHERENT_CACHE
1805 np = of_find_node_by_type(NULL, "cpu");
1806 if (!np) {
Timur Tabi154152a2011-09-15 16:44:47 -05001807 pr_err("fsl-diu-fb: can't find 'cpu' device node\n");
York Sun9b53a9e2008-04-28 02:15:34 -07001808 return -ENODEV;
1809 }
1810
1811 prop = of_get_property(np, "d-cache-size", NULL);
Julia Lawall5394ba02008-08-05 13:01:28 -07001812 if (prop == NULL) {
Timur Tabi154152a2011-09-15 16:44:47 -05001813 pr_err("fsl-diu-fb: missing 'd-cache-size' property' "
1814 "in 'cpu' node\n");
Julia Lawall5394ba02008-08-05 13:01:28 -07001815 of_node_put(np);
York Sun9b53a9e2008-04-28 02:15:34 -07001816 return -ENODEV;
Julia Lawall5394ba02008-08-05 13:01:28 -07001817 }
York Sun9b53a9e2008-04-28 02:15:34 -07001818
Timur Tabi4a85dc8b2011-09-15 16:44:46 -05001819 /*
1820 * Freescale PLRU requires 13/8 times the cache size to do a proper
1821 * displacement flush
York Sun9b53a9e2008-04-28 02:15:34 -07001822 */
Timur Tabi9e52ba62011-09-15 16:44:50 -05001823 coherence_data_size = be32_to_cpup(prop) * 13;
York Sun9b53a9e2008-04-28 02:15:34 -07001824 coherence_data_size /= 8;
1825
1826 prop = of_get_property(np, "d-cache-line-size", NULL);
Julia Lawall5394ba02008-08-05 13:01:28 -07001827 if (prop == NULL) {
Timur Tabi154152a2011-09-15 16:44:47 -05001828 pr_err("fsl-diu-fb: missing 'd-cache-line-size' property' "
1829 "in 'cpu' node\n");
Julia Lawall5394ba02008-08-05 13:01:28 -07001830 of_node_put(np);
York Sun9b53a9e2008-04-28 02:15:34 -07001831 return -ENODEV;
Julia Lawall5394ba02008-08-05 13:01:28 -07001832 }
Timur Tabi9e52ba62011-09-15 16:44:50 -05001833 d_cache_line_size = be32_to_cpup(prop);
York Sun9b53a9e2008-04-28 02:15:34 -07001834
1835 of_node_put(np);
1836 coherence_data = vmalloc(coherence_data_size);
1837 if (!coherence_data)
1838 return -ENOMEM;
1839#endif
Timur Tabi4a85dc8b2011-09-15 16:44:46 -05001840
Grant Likely28541d02011-02-22 21:07:43 -07001841 ret = platform_driver_register(&fsl_diu_driver);
York Sun9b53a9e2008-04-28 02:15:34 -07001842 if (ret) {
Timur Tabi154152a2011-09-15 16:44:47 -05001843 pr_err("fsl-diu-fb: failed to register platform driver\n");
York Sun9b53a9e2008-04-28 02:15:34 -07001844#if defined(CONFIG_NOT_COHERENT_CACHE)
1845 vfree(coherence_data);
1846#endif
1847 iounmap(dr.diu_reg);
1848 }
1849 return ret;
1850}
1851
1852static void __exit fsl_diu_exit(void)
1853{
Grant Likely28541d02011-02-22 21:07:43 -07001854 platform_driver_unregister(&fsl_diu_driver);
York Sun9b53a9e2008-04-28 02:15:34 -07001855#if defined(CONFIG_NOT_COHERENT_CACHE)
1856 vfree(coherence_data);
1857#endif
1858}
1859
1860module_init(fsl_diu_init);
1861module_exit(fsl_diu_exit);
1862
1863MODULE_AUTHOR("York Sun <yorksun@freescale.com>");
1864MODULE_DESCRIPTION("Freescale DIU framebuffer driver");
1865MODULE_LICENSE("GPL");
1866
1867module_param_named(mode, fb_mode, charp, 0);
1868MODULE_PARM_DESC(mode,
1869 "Specify resolution as \"<xres>x<yres>[-<bpp>][@<refresh>]\" ");
1870module_param_named(bpp, default_bpp, ulong, 0);
Timur Tabi154152a2011-09-15 16:44:47 -05001871MODULE_PARM_DESC(bpp, "Specify bit-per-pixel if not specified in 'mode'");
Timur Tabi7653aaa2011-07-09 15:38:14 -05001872module_param_named(monitor, monitor_string, charp, 0);
1873MODULE_PARM_DESC(monitor, "Specify the monitor port "
1874 "(\"dvi\", \"lvds\", or \"dlvds\") if supported by the platform");
York Sun9b53a9e2008-04-28 02:15:34 -07001875