blob: 9a1f6d276ee329b38c42b938fcd33344b067b2bb [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>
33
York Sun9b53a9e2008-04-28 02:15:34 -070034#include <sysdev/fsl_soc.h>
Anatolij Gustschin0814a972010-07-23 04:00:36 +000035#include <linux/fsl-diu-fb.h>
Anatolij Gustschin8b856f02010-07-23 04:00:39 +000036#include "edid.h"
York Sun9b53a9e2008-04-28 02:15:34 -070037
38/*
Timur Tabi63cf8df2011-09-15 16:44:51 -050039 * List of supported video modes
40 *
41 * The first entry is the default video mode
York Sun9b53a9e2008-04-28 02:15:34 -070042 */
York Sun9b53a9e2008-04-28 02:15:34 -070043static struct fb_videomode __devinitdata fsl_diu_mode_db[] = {
44 {
45 .name = "1024x768-60",
46 .refresh = 60,
47 .xres = 1024,
48 .yres = 768,
49 .pixclock = 15385,
50 .left_margin = 160,
51 .right_margin = 24,
52 .upper_margin = 29,
53 .lower_margin = 3,
54 .hsync_len = 136,
55 .vsync_len = 6,
56 .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
57 .vmode = FB_VMODE_NONINTERLACED
58 },
59 {
60 .name = "1024x768-70",
61 .refresh = 70,
62 .xres = 1024,
63 .yres = 768,
64 .pixclock = 16886,
65 .left_margin = 3,
66 .right_margin = 3,
67 .upper_margin = 2,
68 .lower_margin = 2,
69 .hsync_len = 40,
70 .vsync_len = 18,
71 .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
72 .vmode = FB_VMODE_NONINTERLACED
73 },
74 {
75 .name = "1024x768-75",
76 .refresh = 75,
77 .xres = 1024,
78 .yres = 768,
79 .pixclock = 15009,
80 .left_margin = 3,
81 .right_margin = 3,
82 .upper_margin = 2,
83 .lower_margin = 2,
84 .hsync_len = 80,
85 .vsync_len = 32,
86 .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
87 .vmode = FB_VMODE_NONINTERLACED
88 },
89 {
90 .name = "1280x1024-60",
91 .refresh = 60,
92 .xres = 1280,
93 .yres = 1024,
94 .pixclock = 9375,
95 .left_margin = 38,
96 .right_margin = 128,
97 .upper_margin = 2,
98 .lower_margin = 7,
99 .hsync_len = 216,
100 .vsync_len = 37,
101 .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
102 .vmode = FB_VMODE_NONINTERLACED
103 },
104 {
105 .name = "1280x1024-70",
106 .refresh = 70,
107 .xres = 1280,
108 .yres = 1024,
109 .pixclock = 9380,
110 .left_margin = 6,
111 .right_margin = 6,
112 .upper_margin = 4,
113 .lower_margin = 4,
114 .hsync_len = 60,
115 .vsync_len = 94,
116 .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
117 .vmode = FB_VMODE_NONINTERLACED
118 },
119 {
120 .name = "1280x1024-75",
121 .refresh = 75,
122 .xres = 1280,
123 .yres = 1024,
124 .pixclock = 9380,
125 .left_margin = 6,
126 .right_margin = 6,
127 .upper_margin = 4,
128 .lower_margin = 4,
129 .hsync_len = 60,
130 .vsync_len = 15,
131 .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
132 .vmode = FB_VMODE_NONINTERLACED
133 },
134 {
135 .name = "320x240", /* for AOI only */
136 .refresh = 60,
137 .xres = 320,
138 .yres = 240,
139 .pixclock = 15385,
140 .left_margin = 0,
141 .right_margin = 0,
142 .upper_margin = 0,
143 .lower_margin = 0,
144 .hsync_len = 0,
145 .vsync_len = 0,
146 .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
147 .vmode = FB_VMODE_NONINTERLACED
148 },
149 {
150 .name = "1280x480-60",
151 .refresh = 60,
152 .xres = 1280,
153 .yres = 480,
154 .pixclock = 18939,
155 .left_margin = 353,
156 .right_margin = 47,
157 .upper_margin = 39,
158 .lower_margin = 4,
159 .hsync_len = 8,
160 .vsync_len = 2,
161 .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
162 .vmode = FB_VMODE_NONINTERLACED
163 },
164};
165
166static char *fb_mode = "1024x768-32@60";
167static unsigned long default_bpp = 32;
Timur Tabi7653aaa2011-07-09 15:38:14 -0500168static enum fsl_diu_monitor_port monitor_port;
169static char *monitor_string;
York Sun9b53a9e2008-04-28 02:15:34 -0700170
171#if defined(CONFIG_NOT_COHERENT_CACHE)
172static u8 *coherence_data;
173static size_t coherence_data_size;
174static unsigned int d_cache_line_size;
175#endif
176
177static DEFINE_SPINLOCK(diu_lock);
178
179struct fsl_diu_data {
180 struct fb_info *fsl_diu_info[FSL_AOI_NUM - 1];
181 /*FSL_AOI_NUM has one dummy AOI */
182 struct device_attribute dev_attr;
183 struct diu_ad *dummy_ad;
184 void *dummy_aoi_virt;
185 unsigned int irq;
186 int fb_enabled;
Timur Tabi7653aaa2011-07-09 15:38:14 -0500187 enum fsl_diu_monitor_port monitor_port;
York Sun9b53a9e2008-04-28 02:15:34 -0700188};
189
190struct mfb_info {
191 int index;
192 int type;
193 char *id;
194 int registered;
195 int blank;
196 unsigned long pseudo_palette[16];
197 struct diu_ad *ad;
198 int cursor_reset;
199 unsigned char g_alpha;
200 unsigned int count;
201 int x_aoi_d; /* aoi display x offset to physical screen */
202 int y_aoi_d; /* aoi display y offset to physical screen */
203 struct fsl_diu_data *parent;
Anatolij Gustschin8b856f02010-07-23 04:00:39 +0000204 u8 *edid_data;
York Sun9b53a9e2008-04-28 02:15:34 -0700205};
206
207
208static struct mfb_info mfb_template[] = {
209 { /* AOI 0 for plane 0 */
Timur Tabi4a85dc8b2011-09-15 16:44:46 -0500210 .index = 0,
211 .type = MFB_TYPE_OUTPUT,
212 .id = "Panel0",
213 .registered = 0,
214 .count = 0,
215 .x_aoi_d = 0,
216 .y_aoi_d = 0,
York Sun9b53a9e2008-04-28 02:15:34 -0700217 },
218 { /* AOI 0 for plane 1 */
Timur Tabi4a85dc8b2011-09-15 16:44:46 -0500219 .index = 1,
220 .type = MFB_TYPE_OUTPUT,
221 .id = "Panel1 AOI0",
222 .registered = 0,
223 .g_alpha = 0xff,
224 .count = 0,
225 .x_aoi_d = 0,
226 .y_aoi_d = 0,
York Sun9b53a9e2008-04-28 02:15:34 -0700227 },
228 { /* AOI 1 for plane 1 */
Timur Tabi4a85dc8b2011-09-15 16:44:46 -0500229 .index = 2,
230 .type = MFB_TYPE_OUTPUT,
231 .id = "Panel1 AOI1",
232 .registered = 0,
233 .g_alpha = 0xff,
234 .count = 0,
235 .x_aoi_d = 0,
236 .y_aoi_d = 480,
York Sun9b53a9e2008-04-28 02:15:34 -0700237 },
238 { /* AOI 0 for plane 2 */
Timur Tabi4a85dc8b2011-09-15 16:44:46 -0500239 .index = 3,
240 .type = MFB_TYPE_OUTPUT,
241 .id = "Panel2 AOI0",
242 .registered = 0,
243 .g_alpha = 0xff,
244 .count = 0,
245 .x_aoi_d = 640,
246 .y_aoi_d = 0,
York Sun9b53a9e2008-04-28 02:15:34 -0700247 },
248 { /* AOI 1 for plane 2 */
Timur Tabi4a85dc8b2011-09-15 16:44:46 -0500249 .index = 4,
250 .type = MFB_TYPE_OUTPUT,
251 .id = "Panel2 AOI1",
252 .registered = 0,
253 .g_alpha = 0xff,
254 .count = 0,
255 .x_aoi_d = 640,
256 .y_aoi_d = 480,
York Sun9b53a9e2008-04-28 02:15:34 -0700257 },
258};
259
260static struct diu_hw dr = {
261 .mode = MFB_MODE1,
262 .reg_lock = __SPIN_LOCK_UNLOCKED(diu_hw.reg_lock),
263};
264
265static struct diu_pool pool;
266
Timur Tabi6b51d512008-07-23 21:31:39 -0700267/**
Timur Tabi7653aaa2011-07-09 15:38:14 -0500268 * fsl_diu_name_to_port - convert a port name to a monitor port enum
269 *
270 * Takes the name of a monitor port ("dvi", "lvds", or "dlvds") and returns
271 * the enum fsl_diu_monitor_port that corresponds to that string.
272 *
273 * For compatibility with older versions, a number ("0", "1", or "2") is also
274 * supported.
275 *
276 * If the string is unknown, DVI is assumed.
277 *
278 * If the particular port is not supported by the platform, another port
279 * (platform-specific) is chosen instead.
280 */
281static enum fsl_diu_monitor_port fsl_diu_name_to_port(const char *s)
282{
283 enum fsl_diu_monitor_port port = FSL_DIU_PORT_DVI;
284 unsigned long val;
285
286 if (s) {
287 if (!strict_strtoul(s, 10, &val) && (val <= 2))
288 port = (enum fsl_diu_monitor_port) val;
289 else if (strncmp(s, "lvds", 4) == 0)
290 port = FSL_DIU_PORT_LVDS;
291 else if (strncmp(s, "dlvds", 5) == 0)
292 port = FSL_DIU_PORT_DLVDS;
293 }
294
295 return diu_ops.valid_monitor_port(port);
296}
297
298/**
Timur Tabi6b51d512008-07-23 21:31:39 -0700299 * fsl_diu_alloc - allocate memory for the DIU
300 * @size: number of bytes to allocate
301 * @param: returned physical address of memory
302 *
303 * This function allocates a physically-contiguous block of memory.
York Sun9b53a9e2008-04-28 02:15:34 -0700304 */
Timur Tabi6b51d512008-07-23 21:31:39 -0700305static void *fsl_diu_alloc(size_t size, phys_addr_t *phys)
York Sun9b53a9e2008-04-28 02:15:34 -0700306{
307 void *virt;
308
Timur Tabi6b51d512008-07-23 21:31:39 -0700309 virt = alloc_pages_exact(size, GFP_DMA | __GFP_ZERO);
Timur Tabi154152a2011-09-15 16:44:47 -0500310 if (virt)
York Sun9b53a9e2008-04-28 02:15:34 -0700311 *phys = virt_to_phys(virt);
York Sun9b53a9e2008-04-28 02:15:34 -0700312
313 return virt;
314}
315
Timur Tabi6b51d512008-07-23 21:31:39 -0700316/**
317 * fsl_diu_free - release DIU memory
318 * @virt: pointer returned by fsl_diu_alloc()
319 * @size: number of bytes allocated by fsl_diu_alloc()
320 *
321 * This function releases memory allocated by fsl_diu_alloc().
322 */
323static void fsl_diu_free(void *virt, size_t size)
York Sun9b53a9e2008-04-28 02:15:34 -0700324{
Timur Tabi6b51d512008-07-23 21:31:39 -0700325 if (virt && size)
326 free_pages_exact(virt, size);
York Sun9b53a9e2008-04-28 02:15:34 -0700327}
328
Anatolij Gustschin0d9dab32010-07-23 04:00:35 +0000329/*
330 * Workaround for failed writing desc register of planes.
331 * Needed with MPC5121 DIU rev 2.0 silicon.
332 */
333void wr_reg_wa(u32 *reg, u32 val)
334{
335 do {
336 out_be32(reg, val);
337 } while (in_be32(reg) != val);
338}
339
York Sun9b53a9e2008-04-28 02:15:34 -0700340static int fsl_diu_enable_panel(struct fb_info *info)
341{
342 struct mfb_info *pmfbi, *cmfbi, *mfbi = info->par;
343 struct diu *hw = dr.diu_reg;
344 struct diu_ad *ad = mfbi->ad;
345 struct fsl_diu_data *machine_data = mfbi->parent;
346 int res = 0;
347
York Sun9b53a9e2008-04-28 02:15:34 -0700348 if (mfbi->type != MFB_TYPE_OFF) {
349 switch (mfbi->index) {
350 case 0: /* plane 0 */
351 if (hw->desc[0] != ad->paddr)
Anatolij Gustschin0d9dab32010-07-23 04:00:35 +0000352 wr_reg_wa(&hw->desc[0], ad->paddr);
York Sun9b53a9e2008-04-28 02:15:34 -0700353 break;
354 case 1: /* plane 1 AOI 0 */
355 cmfbi = machine_data->fsl_diu_info[2]->par;
356 if (hw->desc[1] != ad->paddr) { /* AOI0 closed */
357 if (cmfbi->count > 0) /* AOI1 open */
358 ad->next_ad =
359 cpu_to_le32(cmfbi->ad->paddr);
360 else
361 ad->next_ad = 0;
Anatolij Gustschin0d9dab32010-07-23 04:00:35 +0000362 wr_reg_wa(&hw->desc[1], ad->paddr);
York Sun9b53a9e2008-04-28 02:15:34 -0700363 }
364 break;
365 case 3: /* plane 2 AOI 0 */
366 cmfbi = machine_data->fsl_diu_info[4]->par;
367 if (hw->desc[2] != ad->paddr) { /* AOI0 closed */
368 if (cmfbi->count > 0) /* AOI1 open */
369 ad->next_ad =
370 cpu_to_le32(cmfbi->ad->paddr);
371 else
372 ad->next_ad = 0;
Anatolij Gustschin0d9dab32010-07-23 04:00:35 +0000373 wr_reg_wa(&hw->desc[2], ad->paddr);
York Sun9b53a9e2008-04-28 02:15:34 -0700374 }
375 break;
376 case 2: /* plane 1 AOI 1 */
377 pmfbi = machine_data->fsl_diu_info[1]->par;
378 ad->next_ad = 0;
379 if (hw->desc[1] == machine_data->dummy_ad->paddr)
Anatolij Gustschin0d9dab32010-07-23 04:00:35 +0000380 wr_reg_wa(&hw->desc[1], ad->paddr);
York Sun9b53a9e2008-04-28 02:15:34 -0700381 else /* AOI0 open */
382 pmfbi->ad->next_ad = cpu_to_le32(ad->paddr);
383 break;
384 case 4: /* plane 2 AOI 1 */
385 pmfbi = machine_data->fsl_diu_info[3]->par;
386 ad->next_ad = 0;
387 if (hw->desc[2] == machine_data->dummy_ad->paddr)
Anatolij Gustschin0d9dab32010-07-23 04:00:35 +0000388 wr_reg_wa(&hw->desc[2], ad->paddr);
York Sun9b53a9e2008-04-28 02:15:34 -0700389 else /* AOI0 was open */
390 pmfbi->ad->next_ad = cpu_to_le32(ad->paddr);
391 break;
392 default:
393 res = -EINVAL;
394 break;
395 }
396 } else
397 res = -EINVAL;
398 return res;
399}
400
401static int fsl_diu_disable_panel(struct fb_info *info)
402{
403 struct mfb_info *pmfbi, *cmfbi, *mfbi = info->par;
404 struct diu *hw = dr.diu_reg;
405 struct diu_ad *ad = mfbi->ad;
406 struct fsl_diu_data *machine_data = mfbi->parent;
407 int res = 0;
408
409 switch (mfbi->index) {
410 case 0: /* plane 0 */
411 if (hw->desc[0] != machine_data->dummy_ad->paddr)
Anatolij Gustschin0d9dab32010-07-23 04:00:35 +0000412 wr_reg_wa(&hw->desc[0], machine_data->dummy_ad->paddr);
York Sun9b53a9e2008-04-28 02:15:34 -0700413 break;
414 case 1: /* plane 1 AOI 0 */
415 cmfbi = machine_data->fsl_diu_info[2]->par;
416 if (cmfbi->count > 0) /* AOI1 is open */
Anatolij Gustschin0d9dab32010-07-23 04:00:35 +0000417 wr_reg_wa(&hw->desc[1], cmfbi->ad->paddr);
York Sun9b53a9e2008-04-28 02:15:34 -0700418 /* move AOI1 to the first */
419 else /* AOI1 was closed */
Anatolij Gustschin0d9dab32010-07-23 04:00:35 +0000420 wr_reg_wa(&hw->desc[1], machine_data->dummy_ad->paddr);
York Sun9b53a9e2008-04-28 02:15:34 -0700421 /* close AOI 0 */
422 break;
423 case 3: /* plane 2 AOI 0 */
424 cmfbi = machine_data->fsl_diu_info[4]->par;
425 if (cmfbi->count > 0) /* AOI1 is open */
Anatolij Gustschin0d9dab32010-07-23 04:00:35 +0000426 wr_reg_wa(&hw->desc[2], cmfbi->ad->paddr);
York Sun9b53a9e2008-04-28 02:15:34 -0700427 /* move AOI1 to the first */
428 else /* AOI1 was closed */
Anatolij Gustschin0d9dab32010-07-23 04:00:35 +0000429 wr_reg_wa(&hw->desc[2], machine_data->dummy_ad->paddr);
York Sun9b53a9e2008-04-28 02:15:34 -0700430 /* close AOI 0 */
431 break;
432 case 2: /* plane 1 AOI 1 */
433 pmfbi = machine_data->fsl_diu_info[1]->par;
434 if (hw->desc[1] != ad->paddr) {
435 /* AOI1 is not the first in the chain */
436 if (pmfbi->count > 0)
437 /* AOI0 is open, must be the first */
438 pmfbi->ad->next_ad = 0;
439 } else /* AOI1 is the first in the chain */
Anatolij Gustschin0d9dab32010-07-23 04:00:35 +0000440 wr_reg_wa(&hw->desc[1], machine_data->dummy_ad->paddr);
York Sun9b53a9e2008-04-28 02:15:34 -0700441 /* close AOI 1 */
442 break;
443 case 4: /* plane 2 AOI 1 */
444 pmfbi = machine_data->fsl_diu_info[3]->par;
445 if (hw->desc[2] != ad->paddr) {
446 /* AOI1 is not the first in the chain */
447 if (pmfbi->count > 0)
448 /* AOI0 is open, must be the first */
449 pmfbi->ad->next_ad = 0;
450 } else /* AOI1 is the first in the chain */
Anatolij Gustschin0d9dab32010-07-23 04:00:35 +0000451 wr_reg_wa(&hw->desc[2], machine_data->dummy_ad->paddr);
York Sun9b53a9e2008-04-28 02:15:34 -0700452 /* close AOI 1 */
453 break;
454 default:
455 res = -EINVAL;
456 break;
457 }
458
459 return res;
460}
461
462static void enable_lcdc(struct fb_info *info)
463{
464 struct diu *hw = dr.diu_reg;
465 struct mfb_info *mfbi = info->par;
466 struct fsl_diu_data *machine_data = mfbi->parent;
467
468 if (!machine_data->fb_enabled) {
469 out_be32(&hw->diu_mode, dr.mode);
470 machine_data->fb_enabled++;
471 }
472}
473
474static void disable_lcdc(struct fb_info *info)
475{
476 struct diu *hw = dr.diu_reg;
477 struct mfb_info *mfbi = info->par;
478 struct fsl_diu_data *machine_data = mfbi->parent;
479
480 if (machine_data->fb_enabled) {
481 out_be32(&hw->diu_mode, 0);
482 machine_data->fb_enabled = 0;
483 }
484}
485
486static void adjust_aoi_size_position(struct fb_var_screeninfo *var,
487 struct fb_info *info)
488{
489 struct mfb_info *lower_aoi_mfbi, *upper_aoi_mfbi, *mfbi = info->par;
490 struct fsl_diu_data *machine_data = mfbi->parent;
491 int available_height, upper_aoi_bottom, index = mfbi->index;
492 int lower_aoi_is_open, upper_aoi_is_open;
493 __u32 base_plane_width, base_plane_height, upper_aoi_height;
494
495 base_plane_width = machine_data->fsl_diu_info[0]->var.xres;
496 base_plane_height = machine_data->fsl_diu_info[0]->var.yres;
497
York Sunfdfaa48332008-08-15 00:40:29 -0700498 if (mfbi->x_aoi_d < 0)
499 mfbi->x_aoi_d = 0;
500 if (mfbi->y_aoi_d < 0)
501 mfbi->y_aoi_d = 0;
York Sun9b53a9e2008-04-28 02:15:34 -0700502 switch (index) {
503 case 0:
504 if (mfbi->x_aoi_d != 0)
505 mfbi->x_aoi_d = 0;
506 if (mfbi->y_aoi_d != 0)
507 mfbi->y_aoi_d = 0;
508 break;
509 case 1: /* AOI 0 */
510 case 3:
511 lower_aoi_mfbi = machine_data->fsl_diu_info[index+1]->par;
512 lower_aoi_is_open = lower_aoi_mfbi->count > 0 ? 1 : 0;
513 if (var->xres > base_plane_width)
514 var->xres = base_plane_width;
515 if ((mfbi->x_aoi_d + var->xres) > base_plane_width)
516 mfbi->x_aoi_d = base_plane_width - var->xres;
517
518 if (lower_aoi_is_open)
519 available_height = lower_aoi_mfbi->y_aoi_d;
520 else
521 available_height = base_plane_height;
522 if (var->yres > available_height)
523 var->yres = available_height;
524 if ((mfbi->y_aoi_d + var->yres) > available_height)
525 mfbi->y_aoi_d = available_height - var->yres;
526 break;
527 case 2: /* AOI 1 */
528 case 4:
529 upper_aoi_mfbi = machine_data->fsl_diu_info[index-1]->par;
530 upper_aoi_height =
531 machine_data->fsl_diu_info[index-1]->var.yres;
532 upper_aoi_bottom = upper_aoi_mfbi->y_aoi_d + upper_aoi_height;
533 upper_aoi_is_open = upper_aoi_mfbi->count > 0 ? 1 : 0;
534 if (var->xres > base_plane_width)
535 var->xres = base_plane_width;
536 if ((mfbi->x_aoi_d + var->xres) > base_plane_width)
537 mfbi->x_aoi_d = base_plane_width - var->xres;
538 if (mfbi->y_aoi_d < 0)
539 mfbi->y_aoi_d = 0;
540 if (upper_aoi_is_open) {
541 if (mfbi->y_aoi_d < upper_aoi_bottom)
542 mfbi->y_aoi_d = upper_aoi_bottom;
543 available_height = base_plane_height
544 - upper_aoi_bottom;
545 } else
546 available_height = base_plane_height;
547 if (var->yres > available_height)
548 var->yres = available_height;
549 if ((mfbi->y_aoi_d + var->yres) > base_plane_height)
550 mfbi->y_aoi_d = base_plane_height - var->yres;
551 break;
552 }
553}
554/*
555 * Checks to see if the hardware supports the state requested by var passed
556 * in. This function does not alter the hardware state! If the var passed in
557 * is slightly off by what the hardware can support then we alter the var
558 * PASSED in to what we can do. If the hardware doesn't support mode change
559 * a -EINVAL will be returned by the upper layers.
560 */
561static int fsl_diu_check_var(struct fb_var_screeninfo *var,
562 struct fb_info *info)
563{
York Sun9b53a9e2008-04-28 02:15:34 -0700564 if (var->xres_virtual < var->xres)
565 var->xres_virtual = var->xres;
566 if (var->yres_virtual < var->yres)
567 var->yres_virtual = var->yres;
568
569 if (var->xoffset < 0)
570 var->xoffset = 0;
571
572 if (var->yoffset < 0)
573 var->yoffset = 0;
574
575 if (var->xoffset + info->var.xres > info->var.xres_virtual)
576 var->xoffset = info->var.xres_virtual - info->var.xres;
577
578 if (var->yoffset + info->var.yres > info->var.yres_virtual)
579 var->yoffset = info->var.yres_virtual - info->var.yres;
580
581 if ((var->bits_per_pixel != 32) && (var->bits_per_pixel != 24) &&
582 (var->bits_per_pixel != 16))
583 var->bits_per_pixel = default_bpp;
584
585 switch (var->bits_per_pixel) {
586 case 16:
587 var->red.length = 5;
588 var->red.offset = 11;
589 var->red.msb_right = 0;
590
591 var->green.length = 6;
592 var->green.offset = 5;
593 var->green.msb_right = 0;
594
595 var->blue.length = 5;
596 var->blue.offset = 0;
597 var->blue.msb_right = 0;
598
599 var->transp.length = 0;
600 var->transp.offset = 0;
601 var->transp.msb_right = 0;
602 break;
603 case 24:
604 var->red.length = 8;
605 var->red.offset = 0;
606 var->red.msb_right = 0;
607
608 var->green.length = 8;
609 var->green.offset = 8;
610 var->green.msb_right = 0;
611
612 var->blue.length = 8;
613 var->blue.offset = 16;
614 var->blue.msb_right = 0;
615
616 var->transp.length = 0;
617 var->transp.offset = 0;
618 var->transp.msb_right = 0;
619 break;
620 case 32:
621 var->red.length = 8;
622 var->red.offset = 16;
623 var->red.msb_right = 0;
624
625 var->green.length = 8;
626 var->green.offset = 8;
627 var->green.msb_right = 0;
628
629 var->blue.length = 8;
630 var->blue.offset = 0;
631 var->blue.msb_right = 0;
632
633 var->transp.length = 8;
634 var->transp.offset = 24;
635 var->transp.msb_right = 0;
636
637 break;
638 }
York Sun9b53a9e2008-04-28 02:15:34 -0700639
640 var->height = -1;
641 var->width = -1;
642 var->grayscale = 0;
643
644 /* Copy nonstd field to/from sync for fbset usage */
645 var->sync |= var->nonstd;
646 var->nonstd |= var->sync;
647
648 adjust_aoi_size_position(var, info);
649 return 0;
650}
651
652static void set_fix(struct fb_info *info)
653{
654 struct fb_fix_screeninfo *fix = &info->fix;
655 struct fb_var_screeninfo *var = &info->var;
656 struct mfb_info *mfbi = info->par;
657
Timur Tabiec02dd22011-09-15 16:44:54 -0500658 strncpy(fix->id, mfbi->id, sizeof(fix->id));
York Sun9b53a9e2008-04-28 02:15:34 -0700659 fix->line_length = var->xres_virtual * var->bits_per_pixel / 8;
660 fix->type = FB_TYPE_PACKED_PIXELS;
661 fix->accel = FB_ACCEL_NONE;
662 fix->visual = FB_VISUAL_TRUECOLOR;
663 fix->xpanstep = 1;
664 fix->ypanstep = 1;
665}
666
667static void update_lcdc(struct fb_info *info)
668{
669 struct fb_var_screeninfo *var = &info->var;
670 struct mfb_info *mfbi = info->par;
671 struct fsl_diu_data *machine_data = mfbi->parent;
672 struct diu *hw;
673 int i, j;
674 char __iomem *cursor_base, *gamma_table_base;
675
676 u32 temp;
677
678 hw = dr.diu_reg;
679
680 if (mfbi->type == MFB_TYPE_OFF) {
681 fsl_diu_disable_panel(info);
682 return;
683 }
684
685 diu_ops.set_monitor_port(machine_data->monitor_port);
686 gamma_table_base = pool.gamma.vaddr;
687 cursor_base = pool.cursor.vaddr;
688 /* Prep for DIU init - gamma table, cursor table */
689
690 for (i = 0; i <= 2; i++)
Timur Tabi4a85dc8b2011-09-15 16:44:46 -0500691 for (j = 0; j <= 255; j++)
692 *gamma_table_base++ = j;
York Sun9b53a9e2008-04-28 02:15:34 -0700693
694 diu_ops.set_gamma_table(machine_data->monitor_port, pool.gamma.vaddr);
695
York Sun9b53a9e2008-04-28 02:15:34 -0700696 disable_lcdc(info);
697
698 /* Program DIU registers */
699
700 out_be32(&hw->gamma, pool.gamma.paddr);
701 out_be32(&hw->cursor, pool.cursor.paddr);
702
703 out_be32(&hw->bgnd, 0x007F7F7F); /* BGND */
704 out_be32(&hw->bgnd_wb, 0); /* BGND_WB */
705 out_be32(&hw->disp_size, (var->yres << 16 | var->xres));
706 /* DISP SIZE */
York Sun9b53a9e2008-04-28 02:15:34 -0700707 out_be32(&hw->wb_size, 0); /* WB SIZE */
708 out_be32(&hw->wb_mem_addr, 0); /* WB MEM ADDR */
709
710 /* Horizontal and vertical configuration register */
711 temp = var->left_margin << 22 | /* BP_H */
712 var->hsync_len << 11 | /* PW_H */
713 var->right_margin; /* FP_H */
714
715 out_be32(&hw->hsyn_para, temp);
716
717 temp = var->upper_margin << 22 | /* BP_V */
718 var->vsync_len << 11 | /* PW_V */
719 var->lower_margin; /* FP_V */
720
721 out_be32(&hw->vsyn_para, temp);
722
York Sun9b53a9e2008-04-28 02:15:34 -0700723 diu_ops.set_pixel_clock(var->pixclock);
724
725 out_be32(&hw->syn_pol, 0); /* SYNC SIGNALS POLARITY */
726 out_be32(&hw->thresholds, 0x00037800); /* The Thresholds */
727 out_be32(&hw->int_status, 0); /* INTERRUPT STATUS */
728 out_be32(&hw->plut, 0x01F5F666);
729
730 /* Enable the DIU */
731 enable_lcdc(info);
732}
733
734static int map_video_memory(struct fb_info *info)
735{
736 phys_addr_t phys;
Krzysztof Helt537a1bf2009-06-30 11:41:29 -0700737 u32 smem_len = info->fix.line_length * info->var.yres_virtual;
York Sun9b53a9e2008-04-28 02:15:34 -0700738
Krzysztof Helt537a1bf2009-06-30 11:41:29 -0700739 info->screen_base = fsl_diu_alloc(smem_len, &phys);
Anton Vorontsov05946bc2008-07-04 09:59:38 -0700740 if (info->screen_base == NULL) {
Timur Tabi154152a2011-09-15 16:44:47 -0500741 dev_err(info->dev, "unable to allocate fb memory\n");
York Sun9b53a9e2008-04-28 02:15:34 -0700742 return -ENOMEM;
743 }
Krzysztof Helt537a1bf2009-06-30 11:41:29 -0700744 mutex_lock(&info->mm_lock);
York Sun9b53a9e2008-04-28 02:15:34 -0700745 info->fix.smem_start = (unsigned long) phys;
Krzysztof Helt537a1bf2009-06-30 11:41:29 -0700746 info->fix.smem_len = smem_len;
747 mutex_unlock(&info->mm_lock);
York Sun9b53a9e2008-04-28 02:15:34 -0700748 info->screen_size = info->fix.smem_len;
749
York Sun9b53a9e2008-04-28 02:15:34 -0700750 return 0;
751}
752
753static void unmap_video_memory(struct fb_info *info)
754{
755 fsl_diu_free(info->screen_base, info->fix.smem_len);
Krzysztof Helt537a1bf2009-06-30 11:41:29 -0700756 mutex_lock(&info->mm_lock);
Anton Vorontsov05946bc2008-07-04 09:59:38 -0700757 info->screen_base = NULL;
York Sun9b53a9e2008-04-28 02:15:34 -0700758 info->fix.smem_start = 0;
759 info->fix.smem_len = 0;
Krzysztof Helt537a1bf2009-06-30 11:41:29 -0700760 mutex_unlock(&info->mm_lock);
York Sun9b53a9e2008-04-28 02:15:34 -0700761}
762
763/*
York Sunae5591e2008-08-15 00:40:28 -0700764 * Using the fb_var_screeninfo in fb_info we set the aoi of this
765 * particular framebuffer. It is a light version of fsl_diu_set_par.
766 */
767static int fsl_diu_set_aoi(struct fb_info *info)
768{
769 struct fb_var_screeninfo *var = &info->var;
770 struct mfb_info *mfbi = info->par;
771 struct diu_ad *ad = mfbi->ad;
772
773 /* AOI should not be greater than display size */
774 ad->offset_xyi = cpu_to_le32((var->yoffset << 16) | var->xoffset);
775 ad->offset_xyd = cpu_to_le32((mfbi->y_aoi_d << 16) | mfbi->x_aoi_d);
776 return 0;
777}
778
779/*
York Sun9b53a9e2008-04-28 02:15:34 -0700780 * Using the fb_var_screeninfo in fb_info we set the resolution of this
781 * particular framebuffer. This function alters the fb_fix_screeninfo stored
782 * in fb_info. It does not alter var in fb_info since we are using that
783 * data. This means we depend on the data in var inside fb_info to be
784 * supported by the hardware. fsl_diu_check_var is always called before
785 * fsl_diu_set_par to ensure this.
786 */
787static int fsl_diu_set_par(struct fb_info *info)
788{
789 unsigned long len;
790 struct fb_var_screeninfo *var = &info->var;
791 struct mfb_info *mfbi = info->par;
792 struct fsl_diu_data *machine_data = mfbi->parent;
793 struct diu_ad *ad = mfbi->ad;
794 struct diu *hw;
795
796 hw = dr.diu_reg;
797
798 set_fix(info);
799 mfbi->cursor_reset = 1;
800
801 len = info->var.yres_virtual * info->fix.line_length;
802 /* Alloc & dealloc each time resolution/bpp change */
803 if (len != info->fix.smem_len) {
804 if (info->fix.smem_start)
805 unmap_video_memory(info);
York Sun9b53a9e2008-04-28 02:15:34 -0700806
807 /* Memory allocation for framebuffer */
808 if (map_video_memory(info)) {
Timur Tabi154152a2011-09-15 16:44:47 -0500809 dev_err(info->dev, "unable to allocate fb memory 1\n");
York Sun9b53a9e2008-04-28 02:15:34 -0700810 return -ENOMEM;
811 }
812 }
813
Timur Tabi7653aaa2011-07-09 15:38:14 -0500814 ad->pix_fmt = diu_ops.get_pixel_format(machine_data->monitor_port,
815 var->bits_per_pixel);
York Sun9b53a9e2008-04-28 02:15:34 -0700816 ad->addr = cpu_to_le32(info->fix.smem_start);
York Sunae5591e2008-08-15 00:40:28 -0700817 ad->src_size_g_alpha = cpu_to_le32((var->yres_virtual << 12) |
818 var->xres_virtual) | mfbi->g_alpha;
819 /* AOI should not be greater than display size */
York Sun9b53a9e2008-04-28 02:15:34 -0700820 ad->aoi_size = cpu_to_le32((var->yres << 16) | var->xres);
York Sunae5591e2008-08-15 00:40:28 -0700821 ad->offset_xyi = cpu_to_le32((var->yoffset << 16) | var->xoffset);
York Sun9b53a9e2008-04-28 02:15:34 -0700822 ad->offset_xyd = cpu_to_le32((mfbi->y_aoi_d << 16) | mfbi->x_aoi_d);
823
824 /* Disable chroma keying function */
825 ad->ckmax_r = 0;
826 ad->ckmax_g = 0;
827 ad->ckmax_b = 0;
828
829 ad->ckmin_r = 255;
830 ad->ckmin_g = 255;
831 ad->ckmin_b = 255;
832
833 if (mfbi->index == 0)
834 update_lcdc(info);
835 return 0;
836}
837
838static inline __u32 CNVT_TOHW(__u32 val, __u32 width)
839{
Timur Tabi4a85dc8b2011-09-15 16:44:46 -0500840 return ((val << width) + 0x7FFF - val) >> 16;
York Sun9b53a9e2008-04-28 02:15:34 -0700841}
842
843/*
844 * Set a single color register. The values supplied have a 16 bit magnitude
845 * which needs to be scaled in this function for the hardware. Things to take
846 * into consideration are how many color registers, if any, are supported with
847 * the current color visual. With truecolor mode no color palettes are
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300848 * supported. Here a pseudo palette is created which we store the value in
York Sun9b53a9e2008-04-28 02:15:34 -0700849 * pseudo_palette in struct fb_info. For pseudocolor mode we have a limited
850 * color palette.
851 */
Timur Tabi4a85dc8b2011-09-15 16:44:46 -0500852static int fsl_diu_setcolreg(unsigned int regno, unsigned int red,
853 unsigned int green, unsigned int blue,
854 unsigned int transp, struct fb_info *info)
York Sun9b53a9e2008-04-28 02:15:34 -0700855{
856 int ret = 1;
857
858 /*
859 * If greyscale is true, then we convert the RGB value
860 * to greyscale no matter what visual we are using.
861 */
862 if (info->var.grayscale)
863 red = green = blue = (19595 * red + 38470 * green +
864 7471 * blue) >> 16;
865 switch (info->fix.visual) {
866 case FB_VISUAL_TRUECOLOR:
867 /*
868 * 16-bit True Colour. We encode the RGB value
869 * according to the RGB bitfield information.
870 */
871 if (regno < 16) {
872 u32 *pal = info->pseudo_palette;
873 u32 v;
874
875 red = CNVT_TOHW(red, info->var.red.length);
876 green = CNVT_TOHW(green, info->var.green.length);
877 blue = CNVT_TOHW(blue, info->var.blue.length);
878 transp = CNVT_TOHW(transp, info->var.transp.length);
879
880 v = (red << info->var.red.offset) |
881 (green << info->var.green.offset) |
882 (blue << info->var.blue.offset) |
883 (transp << info->var.transp.offset);
884
885 pal[regno] = v;
886 ret = 0;
887 }
888 break;
York Sun9b53a9e2008-04-28 02:15:34 -0700889 }
890
891 return ret;
892}
893
894/*
895 * Pan (or wrap, depending on the `vmode' field) the display using the
896 * 'xoffset' and 'yoffset' fields of the 'var' structure. If the values
897 * don't fit, return -EINVAL.
898 */
899static int fsl_diu_pan_display(struct fb_var_screeninfo *var,
900 struct fb_info *info)
901{
902 if ((info->var.xoffset == var->xoffset) &&
903 (info->var.yoffset == var->yoffset))
904 return 0; /* No change, do nothing */
905
906 if (var->xoffset < 0 || var->yoffset < 0
907 || var->xoffset + info->var.xres > info->var.xres_virtual
908 || var->yoffset + info->var.yres > info->var.yres_virtual)
909 return -EINVAL;
910
911 info->var.xoffset = var->xoffset;
912 info->var.yoffset = var->yoffset;
913
914 if (var->vmode & FB_VMODE_YWRAP)
915 info->var.vmode |= FB_VMODE_YWRAP;
916 else
917 info->var.vmode &= ~FB_VMODE_YWRAP;
918
York Sunae5591e2008-08-15 00:40:28 -0700919 fsl_diu_set_aoi(info);
920
York Sun9b53a9e2008-04-28 02:15:34 -0700921 return 0;
922}
923
924/*
925 * Blank the screen if blank_mode != 0, else unblank. Return 0 if blanking
926 * succeeded, != 0 if un-/blanking failed.
927 * blank_mode == 2: suspend vsync
928 * blank_mode == 3: suspend hsync
929 * blank_mode == 4: powerdown
930 */
931static int fsl_diu_blank(int blank_mode, struct fb_info *info)
932{
933 struct mfb_info *mfbi = info->par;
934
935 mfbi->blank = blank_mode;
936
937 switch (blank_mode) {
938 case FB_BLANK_VSYNC_SUSPEND:
939 case FB_BLANK_HSYNC_SUSPEND:
940 /* FIXME: fixes to enable_panel and enable lcdc needed */
941 case FB_BLANK_NORMAL:
942 /* fsl_diu_disable_panel(info);*/
943 break;
944 case FB_BLANK_POWERDOWN:
945 /* disable_lcdc(info); */
946 break;
947 case FB_BLANK_UNBLANK:
948 /* fsl_diu_enable_panel(info);*/
949 break;
950 }
951
952 return 0;
953}
954
955static int fsl_diu_ioctl(struct fb_info *info, unsigned int cmd,
956 unsigned long arg)
957{
958 struct mfb_info *mfbi = info->par;
959 struct diu_ad *ad = mfbi->ad;
960 struct mfb_chroma_key ck;
961 unsigned char global_alpha;
962 struct aoi_display_offset aoi_d;
963 __u32 pix_fmt;
964 void __user *buf = (void __user *)arg;
965
966 if (!arg)
967 return -EINVAL;
968 switch (cmd) {
Timur Tabi36b0b1d2011-10-04 19:36:44 -0500969 case MFB_SET_PIXFMT_OLD:
970 dev_warn(info->dev,
971 "MFB_SET_PIXFMT value of 0x%08x is deprecated.\n",
972 MFB_SET_PIXFMT_OLD);
York Sun9b53a9e2008-04-28 02:15:34 -0700973 case MFB_SET_PIXFMT:
974 if (copy_from_user(&pix_fmt, buf, sizeof(pix_fmt)))
975 return -EFAULT;
976 ad->pix_fmt = pix_fmt;
York Sun9b53a9e2008-04-28 02:15:34 -0700977 break;
Timur Tabi36b0b1d2011-10-04 19:36:44 -0500978 case MFB_GET_PIXFMT_OLD:
979 dev_warn(info->dev,
980 "MFB_GET_PIXFMT value of 0x%08x is deprecated.\n",
981 MFB_GET_PIXFMT_OLD);
York Sun9b53a9e2008-04-28 02:15:34 -0700982 case MFB_GET_PIXFMT:
983 pix_fmt = ad->pix_fmt;
984 if (copy_to_user(buf, &pix_fmt, sizeof(pix_fmt)))
985 return -EFAULT;
York Sun9b53a9e2008-04-28 02:15:34 -0700986 break;
987 case MFB_SET_AOID:
988 if (copy_from_user(&aoi_d, buf, sizeof(aoi_d)))
989 return -EFAULT;
990 mfbi->x_aoi_d = aoi_d.x_aoi_d;
991 mfbi->y_aoi_d = aoi_d.y_aoi_d;
York Sun9b53a9e2008-04-28 02:15:34 -0700992 fsl_diu_check_var(&info->var, info);
York Sunae5591e2008-08-15 00:40:28 -0700993 fsl_diu_set_aoi(info);
York Sun9b53a9e2008-04-28 02:15:34 -0700994 break;
995 case MFB_GET_AOID:
996 aoi_d.x_aoi_d = mfbi->x_aoi_d;
997 aoi_d.y_aoi_d = mfbi->y_aoi_d;
998 if (copy_to_user(buf, &aoi_d, sizeof(aoi_d)))
999 return -EFAULT;
York Sun9b53a9e2008-04-28 02:15:34 -07001000 break;
1001 case MFB_GET_ALPHA:
1002 global_alpha = mfbi->g_alpha;
1003 if (copy_to_user(buf, &global_alpha, sizeof(global_alpha)))
1004 return -EFAULT;
York Sun9b53a9e2008-04-28 02:15:34 -07001005 break;
1006 case MFB_SET_ALPHA:
1007 /* set panel information */
1008 if (copy_from_user(&global_alpha, buf, sizeof(global_alpha)))
1009 return -EFAULT;
1010 ad->src_size_g_alpha = (ad->src_size_g_alpha & (~0xff)) |
1011 (global_alpha & 0xff);
1012 mfbi->g_alpha = global_alpha;
York Sun9b53a9e2008-04-28 02:15:34 -07001013 break;
1014 case MFB_SET_CHROMA_KEY:
1015 /* set panel winformation */
1016 if (copy_from_user(&ck, buf, sizeof(ck)))
1017 return -EFAULT;
1018
1019 if (ck.enable &&
1020 (ck.red_max < ck.red_min ||
1021 ck.green_max < ck.green_min ||
1022 ck.blue_max < ck.blue_min))
1023 return -EINVAL;
1024
1025 if (!ck.enable) {
1026 ad->ckmax_r = 0;
1027 ad->ckmax_g = 0;
1028 ad->ckmax_b = 0;
1029 ad->ckmin_r = 255;
1030 ad->ckmin_g = 255;
1031 ad->ckmin_b = 255;
1032 } else {
1033 ad->ckmax_r = ck.red_max;
1034 ad->ckmax_g = ck.green_max;
1035 ad->ckmax_b = ck.blue_max;
1036 ad->ckmin_r = ck.red_min;
1037 ad->ckmin_g = ck.green_min;
1038 ad->ckmin_b = ck.blue_min;
1039 }
York Sun9b53a9e2008-04-28 02:15:34 -07001040 break;
York Sun9b53a9e2008-04-28 02:15:34 -07001041 default:
Timur Tabi154152a2011-09-15 16:44:47 -05001042 dev_err(info->dev, "unknown ioctl command (0x%08X)\n", cmd);
York Sun9b53a9e2008-04-28 02:15:34 -07001043 return -ENOIOCTLCMD;
1044 }
1045
1046 return 0;
1047}
1048
1049/* turn on fb if count == 1
1050 */
1051static int fsl_diu_open(struct fb_info *info, int user)
1052{
1053 struct mfb_info *mfbi = info->par;
1054 int res = 0;
1055
Anatolij Gustschin4b5006e2010-07-23 04:00:37 +00001056 /* free boot splash memory on first /dev/fb0 open */
1057 if (!mfbi->index && diu_ops.release_bootmem)
1058 diu_ops.release_bootmem();
1059
York Sun9b53a9e2008-04-28 02:15:34 -07001060 spin_lock(&diu_lock);
1061 mfbi->count++;
1062 if (mfbi->count == 1) {
York Sun9b53a9e2008-04-28 02:15:34 -07001063 fsl_diu_check_var(&info->var, info);
1064 res = fsl_diu_set_par(info);
1065 if (res < 0)
1066 mfbi->count--;
1067 else {
1068 res = fsl_diu_enable_panel(info);
1069 if (res < 0)
1070 mfbi->count--;
1071 }
1072 }
1073
1074 spin_unlock(&diu_lock);
1075 return res;
1076}
1077
1078/* turn off fb if count == 0
1079 */
1080static int fsl_diu_release(struct fb_info *info, int user)
1081{
1082 struct mfb_info *mfbi = info->par;
1083 int res = 0;
1084
1085 spin_lock(&diu_lock);
1086 mfbi->count--;
1087 if (mfbi->count == 0) {
York Sun9b53a9e2008-04-28 02:15:34 -07001088 res = fsl_diu_disable_panel(info);
1089 if (res < 0)
1090 mfbi->count++;
1091 }
1092 spin_unlock(&diu_lock);
1093 return res;
1094}
1095
1096static struct fb_ops fsl_diu_ops = {
1097 .owner = THIS_MODULE,
1098 .fb_check_var = fsl_diu_check_var,
1099 .fb_set_par = fsl_diu_set_par,
1100 .fb_setcolreg = fsl_diu_setcolreg,
1101 .fb_blank = fsl_diu_blank,
1102 .fb_pan_display = fsl_diu_pan_display,
1103 .fb_fillrect = cfb_fillrect,
1104 .fb_copyarea = cfb_copyarea,
1105 .fb_imageblit = cfb_imageblit,
1106 .fb_ioctl = fsl_diu_ioctl,
1107 .fb_open = fsl_diu_open,
1108 .fb_release = fsl_diu_release,
1109};
1110
1111static int init_fbinfo(struct fb_info *info)
1112{
1113 struct mfb_info *mfbi = info->par;
1114
1115 info->device = NULL;
1116 info->var.activate = FB_ACTIVATE_NOW;
1117 info->fbops = &fsl_diu_ops;
1118 info->flags = FBINFO_FLAG_DEFAULT;
1119 info->pseudo_palette = &mfbi->pseudo_palette;
1120
1121 /* Allocate colormap */
1122 fb_alloc_cmap(&info->cmap, 16, 0);
1123 return 0;
1124}
1125
Anton Vorontsov05946bc2008-07-04 09:59:38 -07001126static int __devinit install_fb(struct fb_info *info)
York Sun9b53a9e2008-04-28 02:15:34 -07001127{
1128 int rc;
1129 struct mfb_info *mfbi = info->par;
1130 const char *aoi_mode, *init_aoi_mode = "320x240";
Anatolij Gustschin8b856f02010-07-23 04:00:39 +00001131 struct fb_videomode *db = fsl_diu_mode_db;
1132 unsigned int dbsize = ARRAY_SIZE(fsl_diu_mode_db);
1133 int has_default_mode = 1;
York Sun9b53a9e2008-04-28 02:15:34 -07001134
1135 if (init_fbinfo(info))
1136 return -EINVAL;
1137
Anatolij Gustschin8b856f02010-07-23 04:00:39 +00001138 if (mfbi->index == 0) { /* plane 0 */
1139 if (mfbi->edid_data) {
1140 /* Now build modedb from EDID */
1141 fb_edid_to_monspecs(mfbi->edid_data, &info->monspecs);
1142 fb_videomode_to_modelist(info->monspecs.modedb,
1143 info->monspecs.modedb_len,
1144 &info->modelist);
1145 db = info->monspecs.modedb;
1146 dbsize = info->monspecs.modedb_len;
1147 }
York Sun9b53a9e2008-04-28 02:15:34 -07001148 aoi_mode = fb_mode;
Anatolij Gustschin8b856f02010-07-23 04:00:39 +00001149 } else {
York Sun9b53a9e2008-04-28 02:15:34 -07001150 aoi_mode = init_aoi_mode;
Anatolij Gustschin8b856f02010-07-23 04:00:39 +00001151 }
Timur Tabi63cf8df2011-09-15 16:44:51 -05001152 rc = fb_find_mode(&info->var, info, aoi_mode, db, dbsize, NULL,
1153 default_bpp);
Timur Tabi154152a2011-09-15 16:44:47 -05001154 if (!rc) {
Anatolij Gustschin8b856f02010-07-23 04:00:39 +00001155 /*
1156 * For plane 0 we continue and look into
1157 * driver's internal modedb.
1158 */
1159 if (mfbi->index == 0 && mfbi->edid_data)
1160 has_default_mode = 0;
1161 else
1162 return -EINVAL;
York Sun9b53a9e2008-04-28 02:15:34 -07001163 }
1164
Anatolij Gustschin8b856f02010-07-23 04:00:39 +00001165 if (!has_default_mode) {
1166 rc = fb_find_mode(&info->var, info, aoi_mode, fsl_diu_mode_db,
Timur Tabi63cf8df2011-09-15 16:44:51 -05001167 ARRAY_SIZE(fsl_diu_mode_db), NULL, default_bpp);
1168 if (rc)
Anatolij Gustschin8b856f02010-07-23 04:00:39 +00001169 has_default_mode = 1;
1170 }
1171
1172 /* Still not found, use preferred mode from database if any */
1173 if (!has_default_mode && info->monspecs.modedb) {
1174 struct fb_monspecs *specs = &info->monspecs;
1175 struct fb_videomode *modedb = &specs->modedb[0];
1176
1177 /*
1178 * Get preferred timing. If not found,
1179 * first mode in database will be used.
1180 */
1181 if (specs->misc & FB_MISC_1ST_DETAIL) {
1182 int i;
1183
1184 for (i = 0; i < specs->modedb_len; i++) {
1185 if (specs->modedb[i].flag & FB_MODE_IS_FIRST) {
1186 modedb = &specs->modedb[i];
1187 break;
1188 }
1189 }
1190 }
1191
1192 info->var.bits_per_pixel = default_bpp;
1193 fb_videomode_to_var(&info->var, modedb);
1194 }
1195
York Sun9b53a9e2008-04-28 02:15:34 -07001196 if (mfbi->type == MFB_TYPE_OFF)
1197 mfbi->blank = FB_BLANK_NORMAL;
1198 else
1199 mfbi->blank = FB_BLANK_UNBLANK;
1200
1201 if (fsl_diu_check_var(&info->var, info)) {
Timur Tabi154152a2011-09-15 16:44:47 -05001202 dev_err(info->dev, "fsl_diu_check_var failed\n");
Timur Tabi589c7972011-09-15 16:44:55 -05001203 unmap_video_memory(info);
York Sun9b53a9e2008-04-28 02:15:34 -07001204 fb_dealloc_cmap(&info->cmap);
1205 return -EINVAL;
1206 }
1207
York Sun9b53a9e2008-04-28 02:15:34 -07001208 if (register_framebuffer(info) < 0) {
Timur Tabi154152a2011-09-15 16:44:47 -05001209 dev_err(info->dev, "register_framebuffer failed\n");
York Sun9b53a9e2008-04-28 02:15:34 -07001210 unmap_video_memory(info);
1211 fb_dealloc_cmap(&info->cmap);
1212 return -EINVAL;
1213 }
1214
1215 mfbi->registered = 1;
Timur Tabi154152a2011-09-15 16:44:47 -05001216 dev_info(info->dev, "%s registered successfully\n", mfbi->id);
York Sun9b53a9e2008-04-28 02:15:34 -07001217
1218 return 0;
1219}
1220
Anton Vorontsov05946bc2008-07-04 09:59:38 -07001221static void uninstall_fb(struct fb_info *info)
York Sun9b53a9e2008-04-28 02:15:34 -07001222{
1223 struct mfb_info *mfbi = info->par;
1224
1225 if (!mfbi->registered)
1226 return;
1227
Anatolij Gustschin8b856f02010-07-23 04:00:39 +00001228 if (mfbi->index == 0)
1229 kfree(mfbi->edid_data);
1230
York Sun9b53a9e2008-04-28 02:15:34 -07001231 unregister_framebuffer(info);
1232 unmap_video_memory(info);
1233 if (&info->cmap)
1234 fb_dealloc_cmap(&info->cmap);
1235
1236 mfbi->registered = 0;
1237}
1238
1239static irqreturn_t fsl_diu_isr(int irq, void *dev_id)
1240{
1241 struct diu *hw = dr.diu_reg;
1242 unsigned int status = in_be32(&hw->int_status);
1243
1244 if (status) {
1245 /* This is the workaround for underrun */
1246 if (status & INT_UNDRUN) {
1247 out_be32(&hw->diu_mode, 0);
York Sun9b53a9e2008-04-28 02:15:34 -07001248 udelay(1);
1249 out_be32(&hw->diu_mode, 1);
1250 }
1251#if defined(CONFIG_NOT_COHERENT_CACHE)
1252 else if (status & INT_VSYNC) {
1253 unsigned int i;
Timur Tabi4a85dc8b2011-09-15 16:44:46 -05001254
York Sun9b53a9e2008-04-28 02:15:34 -07001255 for (i = 0; i < coherence_data_size;
1256 i += d_cache_line_size)
1257 __asm__ __volatile__ (
1258 "dcbz 0, %[input]"
1259 ::[input]"r"(&coherence_data[i]));
1260 }
1261#endif
1262 return IRQ_HANDLED;
1263 }
1264 return IRQ_NONE;
1265}
1266
1267static int request_irq_local(int irq)
1268{
Timur Tabibada04f2011-09-15 16:44:52 -05001269 u32 ints;
York Sun9b53a9e2008-04-28 02:15:34 -07001270 struct diu *hw;
1271 int ret;
1272
1273 hw = dr.diu_reg;
1274
1275 /* Read to clear the status */
Timur Tabibada04f2011-09-15 16:44:52 -05001276 in_be32(&hw->int_status);
York Sun9b53a9e2008-04-28 02:15:34 -07001277
Timur Tabif8c6bf62011-09-15 16:44:53 -05001278 ret = request_irq(irq, fsl_diu_isr, 0, "fsl-diu-fb", NULL);
Timur Tabi154152a2011-09-15 16:44:47 -05001279 if (!ret) {
York Sun9b53a9e2008-04-28 02:15:34 -07001280 ints = INT_PARERR | INT_LS_BF_VS;
1281#if !defined(CONFIG_NOT_COHERENT_CACHE)
1282 ints |= INT_VSYNC;
1283#endif
Timur Tabi4a85dc8b2011-09-15 16:44:46 -05001284
York Sun9b53a9e2008-04-28 02:15:34 -07001285 if (dr.mode == MFB_MODE2 || dr.mode == MFB_MODE3)
1286 ints |= INT_VSYNC_WB;
1287
1288 /* Read to clear the status */
Timur Tabibada04f2011-09-15 16:44:52 -05001289 in_be32(&hw->int_status);
York Sun9b53a9e2008-04-28 02:15:34 -07001290 out_be32(&hw->int_mask, ints);
1291 }
Timur Tabi4a85dc8b2011-09-15 16:44:46 -05001292
York Sun9b53a9e2008-04-28 02:15:34 -07001293 return ret;
1294}
1295
1296static void free_irq_local(int irq)
1297{
1298 struct diu *hw = dr.diu_reg;
1299
1300 /* Disable all LCDC interrupt */
1301 out_be32(&hw->int_mask, 0x1f);
1302
Anton Vorontsov05946bc2008-07-04 09:59:38 -07001303 free_irq(irq, NULL);
York Sun9b53a9e2008-04-28 02:15:34 -07001304}
1305
1306#ifdef CONFIG_PM
1307/*
1308 * Power management hooks. Note that we won't be called from IRQ context,
1309 * unlike the blank functions above, so we may sleep.
1310 */
Grant Likely2dc11582010-08-06 09:25:50 -06001311static int fsl_diu_suspend(struct platform_device *ofdev, pm_message_t state)
York Sun9b53a9e2008-04-28 02:15:34 -07001312{
1313 struct fsl_diu_data *machine_data;
1314
Takashi Iwai48948a32008-07-08 18:41:17 +02001315 machine_data = dev_get_drvdata(&ofdev->dev);
York Sun9b53a9e2008-04-28 02:15:34 -07001316 disable_lcdc(machine_data->fsl_diu_info[0]);
1317
1318 return 0;
1319}
1320
Grant Likely2dc11582010-08-06 09:25:50 -06001321static int fsl_diu_resume(struct platform_device *ofdev)
York Sun9b53a9e2008-04-28 02:15:34 -07001322{
1323 struct fsl_diu_data *machine_data;
1324
Takashi Iwai48948a32008-07-08 18:41:17 +02001325 machine_data = dev_get_drvdata(&ofdev->dev);
York Sun9b53a9e2008-04-28 02:15:34 -07001326 enable_lcdc(machine_data->fsl_diu_info[0]);
1327
1328 return 0;
1329}
1330
1331#else
1332#define fsl_diu_suspend NULL
1333#define fsl_diu_resume NULL
1334#endif /* CONFIG_PM */
1335
1336/* Align to 64-bit(8-byte), 32-byte, etc. */
Anton Vorontsovf3791882009-04-04 22:31:20 +04001337static int allocate_buf(struct device *dev, struct diu_addr *buf, u32 size,
1338 u32 bytes_align)
York Sun9b53a9e2008-04-28 02:15:34 -07001339{
Timur Tabibada04f2011-09-15 16:44:52 -05001340 u32 offset;
1341 dma_addr_t mask;
York Sun9b53a9e2008-04-28 02:15:34 -07001342
Timur Tabibada04f2011-09-15 16:44:52 -05001343 buf->vaddr =
1344 dma_alloc_coherent(dev, size + bytes_align, &buf->paddr,
1345 GFP_DMA | __GFP_ZERO);
York Sun9b53a9e2008-04-28 02:15:34 -07001346 if (!buf->vaddr)
1347 return -ENOMEM;
1348
York Sun9b53a9e2008-04-28 02:15:34 -07001349 mask = bytes_align - 1;
Timur Tabibada04f2011-09-15 16:44:52 -05001350 offset = buf->paddr & mask;
York Sun9b53a9e2008-04-28 02:15:34 -07001351 if (offset) {
1352 buf->offset = bytes_align - offset;
Timur Tabibada04f2011-09-15 16:44:52 -05001353 buf->paddr = buf->paddr + offset;
York Sun9b53a9e2008-04-28 02:15:34 -07001354 } else
1355 buf->offset = 0;
Timur Tabi4a85dc8b2011-09-15 16:44:46 -05001356
York Sun9b53a9e2008-04-28 02:15:34 -07001357 return 0;
1358}
1359
Anton Vorontsovf3791882009-04-04 22:31:20 +04001360static void free_buf(struct device *dev, struct diu_addr *buf, u32 size,
1361 u32 bytes_align)
York Sun9b53a9e2008-04-28 02:15:34 -07001362{
Timur Tabi4a85dc8b2011-09-15 16:44:46 -05001363 dma_free_coherent(dev, size + bytes_align, buf->vaddr,
1364 buf->paddr - buf->offset);
York Sun9b53a9e2008-04-28 02:15:34 -07001365}
1366
1367static ssize_t store_monitor(struct device *device,
1368 struct device_attribute *attr, const char *buf, size_t count)
1369{
Timur Tabi7653aaa2011-07-09 15:38:14 -05001370 enum fsl_diu_monitor_port old_monitor_port;
York Sun9b53a9e2008-04-28 02:15:34 -07001371 struct fsl_diu_data *machine_data =
1372 container_of(attr, struct fsl_diu_data, dev_attr);
1373
York Sun9b53a9e2008-04-28 02:15:34 -07001374 old_monitor_port = machine_data->monitor_port;
Timur Tabi7653aaa2011-07-09 15:38:14 -05001375 machine_data->monitor_port = fsl_diu_name_to_port(buf);
York Sun9b53a9e2008-04-28 02:15:34 -07001376
1377 if (old_monitor_port != machine_data->monitor_port) {
1378 /* All AOIs need adjust pixel format
1379 * fsl_diu_set_par only change the pixsel format here
1380 * unlikely to fail. */
1381 fsl_diu_set_par(machine_data->fsl_diu_info[0]);
1382 fsl_diu_set_par(machine_data->fsl_diu_info[1]);
1383 fsl_diu_set_par(machine_data->fsl_diu_info[2]);
1384 fsl_diu_set_par(machine_data->fsl_diu_info[3]);
1385 fsl_diu_set_par(machine_data->fsl_diu_info[4]);
1386 }
1387 return count;
1388}
1389
1390static ssize_t show_monitor(struct device *device,
1391 struct device_attribute *attr, char *buf)
1392{
1393 struct fsl_diu_data *machine_data =
1394 container_of(attr, struct fsl_diu_data, dev_attr);
Timur Tabi7653aaa2011-07-09 15:38:14 -05001395
1396 switch (machine_data->monitor_port) {
1397 case FSL_DIU_PORT_DVI:
1398 return sprintf(buf, "DVI\n");
1399 case FSL_DIU_PORT_LVDS:
1400 return sprintf(buf, "Single-link LVDS\n");
1401 case FSL_DIU_PORT_DLVDS:
1402 return sprintf(buf, "Dual-link LVDS\n");
1403 }
1404
1405 return 0;
York Sun9b53a9e2008-04-28 02:15:34 -07001406}
1407
Timur Tabi9e52ba62011-09-15 16:44:50 -05001408static int __devinit fsl_diu_probe(struct platform_device *pdev)
York Sun9b53a9e2008-04-28 02:15:34 -07001409{
Timur Tabi9e52ba62011-09-15 16:44:50 -05001410 struct device_node *np = pdev->dev.of_node;
York Sun9b53a9e2008-04-28 02:15:34 -07001411 struct mfb_info *mfbi;
Timur Tabi89f08e32011-09-15 16:44:49 -05001412 phys_addr_t dummy_ad_addr = 0;
York Sun9b53a9e2008-04-28 02:15:34 -07001413 int ret, i, error = 0;
York Sun9b53a9e2008-04-28 02:15:34 -07001414 struct fsl_diu_data *machine_data;
Anatolij Gustschin4b5006e2010-07-23 04:00:37 +00001415 int diu_mode;
York Sun9b53a9e2008-04-28 02:15:34 -07001416
1417 machine_data = kzalloc(sizeof(struct fsl_diu_data), GFP_KERNEL);
1418 if (!machine_data)
1419 return -ENOMEM;
1420
1421 for (i = 0; i < ARRAY_SIZE(machine_data->fsl_diu_info); i++) {
1422 machine_data->fsl_diu_info[i] =
Timur Tabi9e52ba62011-09-15 16:44:50 -05001423 framebuffer_alloc(sizeof(struct mfb_info), &pdev->dev);
York Sun9b53a9e2008-04-28 02:15:34 -07001424 if (!machine_data->fsl_diu_info[i]) {
Timur Tabi9e52ba62011-09-15 16:44:50 -05001425 dev_err(&pdev->dev, "cannot allocate memory\n");
York Sun9b53a9e2008-04-28 02:15:34 -07001426 ret = -ENOMEM;
1427 goto error2;
1428 }
1429 mfbi = machine_data->fsl_diu_info[i]->par;
1430 memcpy(mfbi, &mfb_template[i], sizeof(struct mfb_info));
1431 mfbi->parent = machine_data;
Anatolij Gustschin8b856f02010-07-23 04:00:39 +00001432
1433 if (mfbi->index == 0) {
1434 const u8 *prop;
1435 int len;
1436
1437 /* Get EDID */
1438 prop = of_get_property(np, "edid", &len);
1439 if (prop && len == EDID_LENGTH)
1440 mfbi->edid_data = kmemdup(prop, EDID_LENGTH,
1441 GFP_KERNEL);
1442 }
York Sun9b53a9e2008-04-28 02:15:34 -07001443 }
1444
Timur Tabi9e52ba62011-09-15 16:44:50 -05001445 dr.diu_reg = of_iomap(np, 0);
York Sun9b53a9e2008-04-28 02:15:34 -07001446 if (!dr.diu_reg) {
Timur Tabi9e52ba62011-09-15 16:44:50 -05001447 dev_err(&pdev->dev, "cannot map DIU registers\n");
York Sun9b53a9e2008-04-28 02:15:34 -07001448 ret = -EFAULT;
1449 goto error2;
1450 }
1451
Anatolij Gustschin4b5006e2010-07-23 04:00:37 +00001452 diu_mode = in_be32(&dr.diu_reg->diu_mode);
1453 if (diu_mode != MFB_MODE1)
1454 out_be32(&dr.diu_reg->diu_mode, 0); /* disable DIU */
York Sun9b53a9e2008-04-28 02:15:34 -07001455
1456 /* Get the IRQ of the DIU */
1457 machine_data->irq = irq_of_parse_and_map(np, 0);
1458
1459 if (!machine_data->irq) {
Timur Tabi9e52ba62011-09-15 16:44:50 -05001460 dev_err(&pdev->dev, "could not get DIU IRQ\n");
York Sun9b53a9e2008-04-28 02:15:34 -07001461 ret = -EINVAL;
1462 goto error;
1463 }
1464 machine_data->monitor_port = monitor_port;
1465
1466 /* Area descriptor memory pool aligns to 64-bit boundary */
Timur Tabi9e52ba62011-09-15 16:44:50 -05001467 if (allocate_buf(&pdev->dev, &pool.ad,
Anton Vorontsovf3791882009-04-04 22:31:20 +04001468 sizeof(struct diu_ad) * FSL_AOI_NUM, 8))
York Sun9b53a9e2008-04-28 02:15:34 -07001469 return -ENOMEM;
1470
1471 /* Get memory for Gamma Table - 32-byte aligned memory */
Timur Tabi9e52ba62011-09-15 16:44:50 -05001472 if (allocate_buf(&pdev->dev, &pool.gamma, 768, 32)) {
York Sun9b53a9e2008-04-28 02:15:34 -07001473 ret = -ENOMEM;
1474 goto error;
1475 }
1476
1477 /* For performance, cursor bitmap buffer aligns to 32-byte boundary */
Timur Tabi9e52ba62011-09-15 16:44:50 -05001478 if (allocate_buf(&pdev->dev, &pool.cursor, MAX_CURS * MAX_CURS * 2,
Anton Vorontsovf3791882009-04-04 22:31:20 +04001479 32)) {
York Sun9b53a9e2008-04-28 02:15:34 -07001480 ret = -ENOMEM;
1481 goto error;
1482 }
1483
1484 i = ARRAY_SIZE(machine_data->fsl_diu_info);
1485 machine_data->dummy_ad = (struct diu_ad *)
1486 ((u32)pool.ad.vaddr + pool.ad.offset) + i;
1487 machine_data->dummy_ad->paddr = pool.ad.paddr +
1488 i * sizeof(struct diu_ad);
1489 machine_data->dummy_aoi_virt = fsl_diu_alloc(64, &dummy_ad_addr);
1490 if (!machine_data->dummy_aoi_virt) {
1491 ret = -ENOMEM;
1492 goto error;
1493 }
1494 machine_data->dummy_ad->addr = cpu_to_le32(dummy_ad_addr);
1495 machine_data->dummy_ad->pix_fmt = 0x88882317;
1496 machine_data->dummy_ad->src_size_g_alpha = cpu_to_le32((4 << 12) | 4);
1497 machine_data->dummy_ad->aoi_size = cpu_to_le32((4 << 16) | 2);
1498 machine_data->dummy_ad->offset_xyi = 0;
1499 machine_data->dummy_ad->offset_xyd = 0;
1500 machine_data->dummy_ad->next_ad = 0;
1501
Anatolij Gustschin4b5006e2010-07-23 04:00:37 +00001502 /*
1503 * Let DIU display splash screen if it was pre-initialized
1504 * by the bootloader, set dummy area descriptor otherwise.
1505 */
1506 if (diu_mode != MFB_MODE1)
1507 out_be32(&dr.diu_reg->desc[0], machine_data->dummy_ad->paddr);
1508
York Sun9b53a9e2008-04-28 02:15:34 -07001509 out_be32(&dr.diu_reg->desc[1], machine_data->dummy_ad->paddr);
1510 out_be32(&dr.diu_reg->desc[2], machine_data->dummy_ad->paddr);
1511
1512 for (i = 0; i < ARRAY_SIZE(machine_data->fsl_diu_info); i++) {
1513 machine_data->fsl_diu_info[i]->fix.smem_start = 0;
1514 mfbi = machine_data->fsl_diu_info[i]->par;
1515 mfbi->ad = (struct diu_ad *)((u32)pool.ad.vaddr
1516 + pool.ad.offset) + i;
1517 mfbi->ad->paddr = pool.ad.paddr + i * sizeof(struct diu_ad);
1518 ret = install_fb(machine_data->fsl_diu_info[i]);
1519 if (ret) {
Timur Tabi9e52ba62011-09-15 16:44:50 -05001520 dev_err(&pdev->dev, "could not register fb %d\n", i);
York Sun9b53a9e2008-04-28 02:15:34 -07001521 goto error;
1522 }
1523 }
1524
1525 if (request_irq_local(machine_data->irq)) {
Timur Tabi9e52ba62011-09-15 16:44:50 -05001526 dev_err(&pdev->dev, "could not claim irq\n");
York Sun9b53a9e2008-04-28 02:15:34 -07001527 goto error;
1528 }
1529
Wolfram Sang12765512010-04-06 14:34:52 -07001530 sysfs_attr_init(&machine_data->dev_attr.attr);
York Sun9b53a9e2008-04-28 02:15:34 -07001531 machine_data->dev_attr.attr.name = "monitor";
1532 machine_data->dev_attr.attr.mode = S_IRUGO|S_IWUSR;
1533 machine_data->dev_attr.show = show_monitor;
1534 machine_data->dev_attr.store = store_monitor;
1535 error = device_create_file(machine_data->fsl_diu_info[0]->dev,
1536 &machine_data->dev_attr);
1537 if (error) {
Timur Tabi9e52ba62011-09-15 16:44:50 -05001538 dev_err(&pdev->dev, "could not create sysfs file %s\n",
York Sun9b53a9e2008-04-28 02:15:34 -07001539 machine_data->dev_attr.attr.name);
1540 }
1541
Timur Tabi9e52ba62011-09-15 16:44:50 -05001542 dev_set_drvdata(&pdev->dev, machine_data);
York Sun9b53a9e2008-04-28 02:15:34 -07001543 return 0;
1544
1545error:
Timur Tabi3f78bbd2011-09-15 16:44:56 -05001546 for (i = 0; i < ARRAY_SIZE(machine_data->fsl_diu_info); i++)
1547 uninstall_fb(machine_data->fsl_diu_info[i]);
1548
York Sun9b53a9e2008-04-28 02:15:34 -07001549 if (pool.ad.vaddr)
Timur Tabi9e52ba62011-09-15 16:44:50 -05001550 free_buf(&pdev->dev, &pool.ad,
Anton Vorontsovf3791882009-04-04 22:31:20 +04001551 sizeof(struct diu_ad) * FSL_AOI_NUM, 8);
York Sun9b53a9e2008-04-28 02:15:34 -07001552 if (pool.gamma.vaddr)
Timur Tabi9e52ba62011-09-15 16:44:50 -05001553 free_buf(&pdev->dev, &pool.gamma, 768, 32);
York Sun9b53a9e2008-04-28 02:15:34 -07001554 if (pool.cursor.vaddr)
Timur Tabi9e52ba62011-09-15 16:44:50 -05001555 free_buf(&pdev->dev, &pool.cursor, MAX_CURS * MAX_CURS * 2,
Anton Vorontsovf3791882009-04-04 22:31:20 +04001556 32);
York Sun9b53a9e2008-04-28 02:15:34 -07001557 if (machine_data->dummy_aoi_virt)
1558 fsl_diu_free(machine_data->dummy_aoi_virt, 64);
1559 iounmap(dr.diu_reg);
1560
1561error2:
1562 for (i = 0; i < ARRAY_SIZE(machine_data->fsl_diu_info); i++)
1563 if (machine_data->fsl_diu_info[i])
1564 framebuffer_release(machine_data->fsl_diu_info[i]);
1565 kfree(machine_data);
1566
1567 return ret;
1568}
1569
Timur Tabi9e52ba62011-09-15 16:44:50 -05001570static int fsl_diu_remove(struct platform_device *pdev)
York Sun9b53a9e2008-04-28 02:15:34 -07001571{
1572 struct fsl_diu_data *machine_data;
1573 int i;
1574
Timur Tabi9e52ba62011-09-15 16:44:50 -05001575 machine_data = dev_get_drvdata(&pdev->dev);
York Sun9b53a9e2008-04-28 02:15:34 -07001576 disable_lcdc(machine_data->fsl_diu_info[0]);
1577 free_irq_local(machine_data->irq);
Timur Tabi3f78bbd2011-09-15 16:44:56 -05001578 for (i = 0; i < ARRAY_SIZE(machine_data->fsl_diu_info); i++)
1579 uninstall_fb(machine_data->fsl_diu_info[i]);
York Sun9b53a9e2008-04-28 02:15:34 -07001580 if (pool.ad.vaddr)
Timur Tabi9e52ba62011-09-15 16:44:50 -05001581 free_buf(&pdev->dev, &pool.ad,
Anton Vorontsovf3791882009-04-04 22:31:20 +04001582 sizeof(struct diu_ad) * FSL_AOI_NUM, 8);
York Sun9b53a9e2008-04-28 02:15:34 -07001583 if (pool.gamma.vaddr)
Timur Tabi9e52ba62011-09-15 16:44:50 -05001584 free_buf(&pdev->dev, &pool.gamma, 768, 32);
York Sun9b53a9e2008-04-28 02:15:34 -07001585 if (pool.cursor.vaddr)
Timur Tabi9e52ba62011-09-15 16:44:50 -05001586 free_buf(&pdev->dev, &pool.cursor, MAX_CURS * MAX_CURS * 2, 32);
York Sun9b53a9e2008-04-28 02:15:34 -07001587 if (machine_data->dummy_aoi_virt)
1588 fsl_diu_free(machine_data->dummy_aoi_virt, 64);
1589 iounmap(dr.diu_reg);
1590 for (i = 0; i < ARRAY_SIZE(machine_data->fsl_diu_info); i++)
1591 if (machine_data->fsl_diu_info[i])
1592 framebuffer_release(machine_data->fsl_diu_info[i]);
1593 kfree(machine_data);
1594
1595 return 0;
1596}
1597
1598#ifndef MODULE
1599static int __init fsl_diu_setup(char *options)
1600{
1601 char *opt;
1602 unsigned long val;
1603
1604 if (!options || !*options)
1605 return 0;
1606
1607 while ((opt = strsep(&options, ",")) != NULL) {
1608 if (!*opt)
1609 continue;
1610 if (!strncmp(opt, "monitor=", 8)) {
Timur Tabi7653aaa2011-07-09 15:38:14 -05001611 monitor_port = fsl_diu_name_to_port(opt + 8);
York Sun9b53a9e2008-04-28 02:15:34 -07001612 } else if (!strncmp(opt, "bpp=", 4)) {
1613 if (!strict_strtoul(opt + 4, 10, &val))
1614 default_bpp = val;
1615 } else
1616 fb_mode = opt;
1617 }
1618
1619 return 0;
1620}
1621#endif
1622
1623static struct of_device_id fsl_diu_match[] = {
Anatolij Gustschind24720a2010-02-17 07:33:22 -07001624#ifdef CONFIG_PPC_MPC512x
1625 {
1626 .compatible = "fsl,mpc5121-diu",
1627 },
1628#endif
York Sun9b53a9e2008-04-28 02:15:34 -07001629 {
1630 .compatible = "fsl,diu",
1631 },
1632 {}
1633};
1634MODULE_DEVICE_TABLE(of, fsl_diu_match);
1635
Grant Likely28541d02011-02-22 21:07:43 -07001636static struct platform_driver fsl_diu_driver = {
Grant Likely40182942010-04-13 16:13:02 -07001637 .driver = {
Timur Tabif8c6bf62011-09-15 16:44:53 -05001638 .name = "fsl-diu-fb",
Grant Likely40182942010-04-13 16:13:02 -07001639 .owner = THIS_MODULE,
1640 .of_match_table = fsl_diu_match,
1641 },
York Sun9b53a9e2008-04-28 02:15:34 -07001642 .probe = fsl_diu_probe,
1643 .remove = fsl_diu_remove,
1644 .suspend = fsl_diu_suspend,
1645 .resume = fsl_diu_resume,
1646};
1647
1648static int __init fsl_diu_init(void)
1649{
1650#ifdef CONFIG_NOT_COHERENT_CACHE
1651 struct device_node *np;
1652 const u32 *prop;
1653#endif
1654 int ret;
1655#ifndef MODULE
1656 char *option;
1657
1658 /*
1659 * For kernel boot options (in 'video=xxxfb:<options>' format)
1660 */
1661 if (fb_get_options("fslfb", &option))
1662 return -ENODEV;
1663 fsl_diu_setup(option);
Timur Tabi7653aaa2011-07-09 15:38:14 -05001664#else
1665 monitor_port = fsl_diu_name_to_port(monitor_string);
York Sun9b53a9e2008-04-28 02:15:34 -07001666#endif
Timur Tabi154152a2011-09-15 16:44:47 -05001667 pr_info("Freescale Display Interface Unit (DIU) framebuffer driver\n");
York Sun9b53a9e2008-04-28 02:15:34 -07001668
1669#ifdef CONFIG_NOT_COHERENT_CACHE
1670 np = of_find_node_by_type(NULL, "cpu");
1671 if (!np) {
Timur Tabi154152a2011-09-15 16:44:47 -05001672 pr_err("fsl-diu-fb: can't find 'cpu' device node\n");
York Sun9b53a9e2008-04-28 02:15:34 -07001673 return -ENODEV;
1674 }
1675
1676 prop = of_get_property(np, "d-cache-size", NULL);
Julia Lawall5394ba02008-08-05 13:01:28 -07001677 if (prop == NULL) {
Timur Tabi154152a2011-09-15 16:44:47 -05001678 pr_err("fsl-diu-fb: missing 'd-cache-size' property' "
1679 "in 'cpu' node\n");
Julia Lawall5394ba02008-08-05 13:01:28 -07001680 of_node_put(np);
York Sun9b53a9e2008-04-28 02:15:34 -07001681 return -ENODEV;
Julia Lawall5394ba02008-08-05 13:01:28 -07001682 }
York Sun9b53a9e2008-04-28 02:15:34 -07001683
Timur Tabi4a85dc8b2011-09-15 16:44:46 -05001684 /*
1685 * Freescale PLRU requires 13/8 times the cache size to do a proper
1686 * displacement flush
York Sun9b53a9e2008-04-28 02:15:34 -07001687 */
Timur Tabi9e52ba62011-09-15 16:44:50 -05001688 coherence_data_size = be32_to_cpup(prop) * 13;
York Sun9b53a9e2008-04-28 02:15:34 -07001689 coherence_data_size /= 8;
1690
1691 prop = of_get_property(np, "d-cache-line-size", NULL);
Julia Lawall5394ba02008-08-05 13:01:28 -07001692 if (prop == NULL) {
Timur Tabi154152a2011-09-15 16:44:47 -05001693 pr_err("fsl-diu-fb: missing 'd-cache-line-size' property' "
1694 "in 'cpu' node\n");
Julia Lawall5394ba02008-08-05 13:01:28 -07001695 of_node_put(np);
York Sun9b53a9e2008-04-28 02:15:34 -07001696 return -ENODEV;
Julia Lawall5394ba02008-08-05 13:01:28 -07001697 }
Timur Tabi9e52ba62011-09-15 16:44:50 -05001698 d_cache_line_size = be32_to_cpup(prop);
York Sun9b53a9e2008-04-28 02:15:34 -07001699
1700 of_node_put(np);
1701 coherence_data = vmalloc(coherence_data_size);
1702 if (!coherence_data)
1703 return -ENOMEM;
1704#endif
Timur Tabi4a85dc8b2011-09-15 16:44:46 -05001705
Grant Likely28541d02011-02-22 21:07:43 -07001706 ret = platform_driver_register(&fsl_diu_driver);
York Sun9b53a9e2008-04-28 02:15:34 -07001707 if (ret) {
Timur Tabi154152a2011-09-15 16:44:47 -05001708 pr_err("fsl-diu-fb: failed to register platform driver\n");
York Sun9b53a9e2008-04-28 02:15:34 -07001709#if defined(CONFIG_NOT_COHERENT_CACHE)
1710 vfree(coherence_data);
1711#endif
1712 iounmap(dr.diu_reg);
1713 }
1714 return ret;
1715}
1716
1717static void __exit fsl_diu_exit(void)
1718{
Grant Likely28541d02011-02-22 21:07:43 -07001719 platform_driver_unregister(&fsl_diu_driver);
York Sun9b53a9e2008-04-28 02:15:34 -07001720#if defined(CONFIG_NOT_COHERENT_CACHE)
1721 vfree(coherence_data);
1722#endif
1723}
1724
1725module_init(fsl_diu_init);
1726module_exit(fsl_diu_exit);
1727
1728MODULE_AUTHOR("York Sun <yorksun@freescale.com>");
1729MODULE_DESCRIPTION("Freescale DIU framebuffer driver");
1730MODULE_LICENSE("GPL");
1731
1732module_param_named(mode, fb_mode, charp, 0);
1733MODULE_PARM_DESC(mode,
1734 "Specify resolution as \"<xres>x<yres>[-<bpp>][@<refresh>]\" ");
1735module_param_named(bpp, default_bpp, ulong, 0);
Timur Tabi154152a2011-09-15 16:44:47 -05001736MODULE_PARM_DESC(bpp, "Specify bit-per-pixel if not specified in 'mode'");
Timur Tabi7653aaa2011-07-09 15:38:14 -05001737module_param_named(monitor, monitor_string, charp, 0);
1738MODULE_PARM_DESC(monitor, "Specify the monitor port "
1739 "(\"dvi\", \"lvds\", or \"dlvds\") if supported by the platform");
York Sun9b53a9e2008-04-28 02:15:34 -07001740