2 * Copyright 2008 Freescale Semiconductor, Inc. All Rights Reserved.
4 * Freescale DIU Frame Buffer device driver
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>
11 * Based on imxfb.c Copyright (C) 2004 S.Hauer, Pengutronix
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.
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>
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>
34 #include <sysdev/fsl_soc.h>
35 #include <linux/fsl-diu-fb.h>
39 * These parameters give default parameters
40 * for video output 1024x768,
41 * FIXME - change timing to proper amounts
42 * hsync 31.5kHz, vsync 60Hz
44 static struct fb_videomode __devinitdata fsl_diu_default_mode
= {
55 .sync
= FB_SYNC_COMP_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
56 .vmode
= FB_VMODE_NONINTERLACED
59 static struct fb_videomode __devinitdata fsl_diu_mode_db
[] = {
61 .name
= "1024x768-60",
72 .sync
= FB_SYNC_COMP_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
73 .vmode
= FB_VMODE_NONINTERLACED
76 .name
= "1024x768-70",
87 .sync
= FB_SYNC_COMP_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
88 .vmode
= FB_VMODE_NONINTERLACED
91 .name
= "1024x768-75",
102 .sync
= FB_SYNC_COMP_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
103 .vmode
= FB_VMODE_NONINTERLACED
106 .name
= "1280x1024-60",
117 .sync
= FB_SYNC_COMP_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
118 .vmode
= FB_VMODE_NONINTERLACED
121 .name
= "1280x1024-70",
132 .sync
= FB_SYNC_COMP_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
133 .vmode
= FB_VMODE_NONINTERLACED
136 .name
= "1280x1024-75",
147 .sync
= FB_SYNC_COMP_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
148 .vmode
= FB_VMODE_NONINTERLACED
151 .name
= "320x240", /* for AOI only */
162 .sync
= FB_SYNC_COMP_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
163 .vmode
= FB_VMODE_NONINTERLACED
166 .name
= "1280x480-60",
177 .sync
= FB_SYNC_COMP_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
178 .vmode
= FB_VMODE_NONINTERLACED
182 static char *fb_mode
= "1024x768-32@60";
183 static unsigned long default_bpp
= 32;
184 static enum fsl_diu_monitor_port monitor_port
;
185 static char *monitor_string
;
187 #if defined(CONFIG_NOT_COHERENT_CACHE)
188 static u8
*coherence_data
;
189 static size_t coherence_data_size
;
190 static unsigned int d_cache_line_size
;
193 static DEFINE_SPINLOCK(diu_lock
);
195 struct fsl_diu_data
{
196 struct fb_info
*fsl_diu_info
[FSL_AOI_NUM
- 1];
197 /*FSL_AOI_NUM has one dummy AOI */
198 struct device_attribute dev_attr
;
199 struct diu_ad
*dummy_ad
;
200 void *dummy_aoi_virt
;
203 enum fsl_diu_monitor_port monitor_port
;
212 unsigned long pseudo_palette
[16];
215 unsigned char g_alpha
;
217 int x_aoi_d
; /* aoi display x offset to physical screen */
218 int y_aoi_d
; /* aoi display y offset to physical screen */
219 struct fsl_diu_data
*parent
;
224 static struct mfb_info mfb_template
[] = {
225 { /* AOI 0 for plane 0 */
227 .type
= MFB_TYPE_OUTPUT
,
234 { /* AOI 0 for plane 1 */
236 .type
= MFB_TYPE_OUTPUT
,
244 { /* AOI 1 for plane 1 */
246 .type
= MFB_TYPE_OUTPUT
,
254 { /* AOI 0 for plane 2 */
256 .type
= MFB_TYPE_OUTPUT
,
264 { /* AOI 1 for plane 2 */
266 .type
= MFB_TYPE_OUTPUT
,
276 static struct diu_hw dr
= {
278 .reg_lock
= __SPIN_LOCK_UNLOCKED(diu_hw
.reg_lock
),
281 static struct diu_pool pool
;
284 * fsl_diu_name_to_port - convert a port name to a monitor port enum
286 * Takes the name of a monitor port ("dvi", "lvds", or "dlvds") and returns
287 * the enum fsl_diu_monitor_port that corresponds to that string.
289 * For compatibility with older versions, a number ("0", "1", or "2") is also
292 * If the string is unknown, DVI is assumed.
294 * If the particular port is not supported by the platform, another port
295 * (platform-specific) is chosen instead.
297 static enum fsl_diu_monitor_port
fsl_diu_name_to_port(const char *s
)
299 enum fsl_diu_monitor_port port
= FSL_DIU_PORT_DVI
;
303 if (!strict_strtoul(s
, 10, &val
) && (val
<= 2))
304 port
= (enum fsl_diu_monitor_port
) val
;
305 else if (strncmp(s
, "lvds", 4) == 0)
306 port
= FSL_DIU_PORT_LVDS
;
307 else if (strncmp(s
, "dlvds", 5) == 0)
308 port
= FSL_DIU_PORT_DLVDS
;
311 return diu_ops
.valid_monitor_port(port
);
315 * fsl_diu_alloc - allocate memory for the DIU
316 * @size: number of bytes to allocate
317 * @param: returned physical address of memory
319 * This function allocates a physically-contiguous block of memory.
321 static void *fsl_diu_alloc(size_t size
, phys_addr_t
*phys
)
325 virt
= alloc_pages_exact(size
, GFP_DMA
| __GFP_ZERO
);
327 *phys
= virt_to_phys(virt
);
333 * fsl_diu_free - release DIU memory
334 * @virt: pointer returned by fsl_diu_alloc()
335 * @size: number of bytes allocated by fsl_diu_alloc()
337 * This function releases memory allocated by fsl_diu_alloc().
339 static void fsl_diu_free(void *virt
, size_t size
)
342 free_pages_exact(virt
, size
);
346 * Workaround for failed writing desc register of planes.
347 * Needed with MPC5121 DIU rev 2.0 silicon.
349 void wr_reg_wa(u32
*reg
, u32 val
)
353 } while (in_be32(reg
) != val
);
356 static int fsl_diu_enable_panel(struct fb_info
*info
)
358 struct mfb_info
*pmfbi
, *cmfbi
, *mfbi
= info
->par
;
359 struct diu
*hw
= dr
.diu_reg
;
360 struct diu_ad
*ad
= mfbi
->ad
;
361 struct fsl_diu_data
*machine_data
= mfbi
->parent
;
364 if (mfbi
->type
!= MFB_TYPE_OFF
) {
365 switch (mfbi
->index
) {
366 case 0: /* plane 0 */
367 if (hw
->desc
[0] != ad
->paddr
)
368 wr_reg_wa(&hw
->desc
[0], ad
->paddr
);
370 case 1: /* plane 1 AOI 0 */
371 cmfbi
= machine_data
->fsl_diu_info
[2]->par
;
372 if (hw
->desc
[1] != ad
->paddr
) { /* AOI0 closed */
373 if (cmfbi
->count
> 0) /* AOI1 open */
375 cpu_to_le32(cmfbi
->ad
->paddr
);
378 wr_reg_wa(&hw
->desc
[1], ad
->paddr
);
381 case 3: /* plane 2 AOI 0 */
382 cmfbi
= machine_data
->fsl_diu_info
[4]->par
;
383 if (hw
->desc
[2] != ad
->paddr
) { /* AOI0 closed */
384 if (cmfbi
->count
> 0) /* AOI1 open */
386 cpu_to_le32(cmfbi
->ad
->paddr
);
389 wr_reg_wa(&hw
->desc
[2], ad
->paddr
);
392 case 2: /* plane 1 AOI 1 */
393 pmfbi
= machine_data
->fsl_diu_info
[1]->par
;
395 if (hw
->desc
[1] == machine_data
->dummy_ad
->paddr
)
396 wr_reg_wa(&hw
->desc
[1], ad
->paddr
);
398 pmfbi
->ad
->next_ad
= cpu_to_le32(ad
->paddr
);
400 case 4: /* plane 2 AOI 1 */
401 pmfbi
= machine_data
->fsl_diu_info
[3]->par
;
403 if (hw
->desc
[2] == machine_data
->dummy_ad
->paddr
)
404 wr_reg_wa(&hw
->desc
[2], ad
->paddr
);
405 else /* AOI0 was open */
406 pmfbi
->ad
->next_ad
= cpu_to_le32(ad
->paddr
);
417 static int fsl_diu_disable_panel(struct fb_info
*info
)
419 struct mfb_info
*pmfbi
, *cmfbi
, *mfbi
= info
->par
;
420 struct diu
*hw
= dr
.diu_reg
;
421 struct diu_ad
*ad
= mfbi
->ad
;
422 struct fsl_diu_data
*machine_data
= mfbi
->parent
;
425 switch (mfbi
->index
) {
426 case 0: /* plane 0 */
427 if (hw
->desc
[0] != machine_data
->dummy_ad
->paddr
)
428 wr_reg_wa(&hw
->desc
[0], machine_data
->dummy_ad
->paddr
);
430 case 1: /* plane 1 AOI 0 */
431 cmfbi
= machine_data
->fsl_diu_info
[2]->par
;
432 if (cmfbi
->count
> 0) /* AOI1 is open */
433 wr_reg_wa(&hw
->desc
[1], cmfbi
->ad
->paddr
);
434 /* move AOI1 to the first */
435 else /* AOI1 was closed */
436 wr_reg_wa(&hw
->desc
[1], machine_data
->dummy_ad
->paddr
);
439 case 3: /* plane 2 AOI 0 */
440 cmfbi
= machine_data
->fsl_diu_info
[4]->par
;
441 if (cmfbi
->count
> 0) /* AOI1 is open */
442 wr_reg_wa(&hw
->desc
[2], cmfbi
->ad
->paddr
);
443 /* move AOI1 to the first */
444 else /* AOI1 was closed */
445 wr_reg_wa(&hw
->desc
[2], machine_data
->dummy_ad
->paddr
);
448 case 2: /* plane 1 AOI 1 */
449 pmfbi
= machine_data
->fsl_diu_info
[1]->par
;
450 if (hw
->desc
[1] != ad
->paddr
) {
451 /* AOI1 is not the first in the chain */
452 if (pmfbi
->count
> 0)
453 /* AOI0 is open, must be the first */
454 pmfbi
->ad
->next_ad
= 0;
455 } else /* AOI1 is the first in the chain */
456 wr_reg_wa(&hw
->desc
[1], machine_data
->dummy_ad
->paddr
);
459 case 4: /* plane 2 AOI 1 */
460 pmfbi
= machine_data
->fsl_diu_info
[3]->par
;
461 if (hw
->desc
[2] != ad
->paddr
) {
462 /* AOI1 is not the first in the chain */
463 if (pmfbi
->count
> 0)
464 /* AOI0 is open, must be the first */
465 pmfbi
->ad
->next_ad
= 0;
466 } else /* AOI1 is the first in the chain */
467 wr_reg_wa(&hw
->desc
[2], machine_data
->dummy_ad
->paddr
);
478 static void enable_lcdc(struct fb_info
*info
)
480 struct diu
*hw
= dr
.diu_reg
;
481 struct mfb_info
*mfbi
= info
->par
;
482 struct fsl_diu_data
*machine_data
= mfbi
->parent
;
484 if (!machine_data
->fb_enabled
) {
485 out_be32(&hw
->diu_mode
, dr
.mode
);
486 machine_data
->fb_enabled
++;
490 static void disable_lcdc(struct fb_info
*info
)
492 struct diu
*hw
= dr
.diu_reg
;
493 struct mfb_info
*mfbi
= info
->par
;
494 struct fsl_diu_data
*machine_data
= mfbi
->parent
;
496 if (machine_data
->fb_enabled
) {
497 out_be32(&hw
->diu_mode
, 0);
498 machine_data
->fb_enabled
= 0;
502 static void adjust_aoi_size_position(struct fb_var_screeninfo
*var
,
503 struct fb_info
*info
)
505 struct mfb_info
*lower_aoi_mfbi
, *upper_aoi_mfbi
, *mfbi
= info
->par
;
506 struct fsl_diu_data
*machine_data
= mfbi
->parent
;
507 int available_height
, upper_aoi_bottom
, index
= mfbi
->index
;
508 int lower_aoi_is_open
, upper_aoi_is_open
;
509 __u32 base_plane_width
, base_plane_height
, upper_aoi_height
;
511 base_plane_width
= machine_data
->fsl_diu_info
[0]->var
.xres
;
512 base_plane_height
= machine_data
->fsl_diu_info
[0]->var
.yres
;
514 if (mfbi
->x_aoi_d
< 0)
516 if (mfbi
->y_aoi_d
< 0)
520 if (mfbi
->x_aoi_d
!= 0)
522 if (mfbi
->y_aoi_d
!= 0)
527 lower_aoi_mfbi
= machine_data
->fsl_diu_info
[index
+1]->par
;
528 lower_aoi_is_open
= lower_aoi_mfbi
->count
> 0 ? 1 : 0;
529 if (var
->xres
> base_plane_width
)
530 var
->xres
= base_plane_width
;
531 if ((mfbi
->x_aoi_d
+ var
->xres
) > base_plane_width
)
532 mfbi
->x_aoi_d
= base_plane_width
- var
->xres
;
534 if (lower_aoi_is_open
)
535 available_height
= lower_aoi_mfbi
->y_aoi_d
;
537 available_height
= base_plane_height
;
538 if (var
->yres
> available_height
)
539 var
->yres
= available_height
;
540 if ((mfbi
->y_aoi_d
+ var
->yres
) > available_height
)
541 mfbi
->y_aoi_d
= available_height
- var
->yres
;
545 upper_aoi_mfbi
= machine_data
->fsl_diu_info
[index
-1]->par
;
547 machine_data
->fsl_diu_info
[index
-1]->var
.yres
;
548 upper_aoi_bottom
= upper_aoi_mfbi
->y_aoi_d
+ upper_aoi_height
;
549 upper_aoi_is_open
= upper_aoi_mfbi
->count
> 0 ? 1 : 0;
550 if (var
->xres
> base_plane_width
)
551 var
->xres
= base_plane_width
;
552 if ((mfbi
->x_aoi_d
+ var
->xres
) > base_plane_width
)
553 mfbi
->x_aoi_d
= base_plane_width
- var
->xres
;
554 if (mfbi
->y_aoi_d
< 0)
556 if (upper_aoi_is_open
) {
557 if (mfbi
->y_aoi_d
< upper_aoi_bottom
)
558 mfbi
->y_aoi_d
= upper_aoi_bottom
;
559 available_height
= base_plane_height
562 available_height
= base_plane_height
;
563 if (var
->yres
> available_height
)
564 var
->yres
= available_height
;
565 if ((mfbi
->y_aoi_d
+ var
->yres
) > base_plane_height
)
566 mfbi
->y_aoi_d
= base_plane_height
- var
->yres
;
571 * Checks to see if the hardware supports the state requested by var passed
572 * in. This function does not alter the hardware state! If the var passed in
573 * is slightly off by what the hardware can support then we alter the var
574 * PASSED in to what we can do. If the hardware doesn't support mode change
575 * a -EINVAL will be returned by the upper layers.
577 static int fsl_diu_check_var(struct fb_var_screeninfo
*var
,
578 struct fb_info
*info
)
580 if (var
->xres_virtual
< var
->xres
)
581 var
->xres_virtual
= var
->xres
;
582 if (var
->yres_virtual
< var
->yres
)
583 var
->yres_virtual
= var
->yres
;
585 if (var
->xoffset
< 0)
588 if (var
->yoffset
< 0)
591 if (var
->xoffset
+ info
->var
.xres
> info
->var
.xres_virtual
)
592 var
->xoffset
= info
->var
.xres_virtual
- info
->var
.xres
;
594 if (var
->yoffset
+ info
->var
.yres
> info
->var
.yres_virtual
)
595 var
->yoffset
= info
->var
.yres_virtual
- info
->var
.yres
;
597 if ((var
->bits_per_pixel
!= 32) && (var
->bits_per_pixel
!= 24) &&
598 (var
->bits_per_pixel
!= 16))
599 var
->bits_per_pixel
= default_bpp
;
601 switch (var
->bits_per_pixel
) {
604 var
->red
.offset
= 11;
605 var
->red
.msb_right
= 0;
607 var
->green
.length
= 6;
608 var
->green
.offset
= 5;
609 var
->green
.msb_right
= 0;
611 var
->blue
.length
= 5;
612 var
->blue
.offset
= 0;
613 var
->blue
.msb_right
= 0;
615 var
->transp
.length
= 0;
616 var
->transp
.offset
= 0;
617 var
->transp
.msb_right
= 0;
622 var
->red
.msb_right
= 0;
624 var
->green
.length
= 8;
625 var
->green
.offset
= 8;
626 var
->green
.msb_right
= 0;
628 var
->blue
.length
= 8;
629 var
->blue
.offset
= 16;
630 var
->blue
.msb_right
= 0;
632 var
->transp
.length
= 0;
633 var
->transp
.offset
= 0;
634 var
->transp
.msb_right
= 0;
638 var
->red
.offset
= 16;
639 var
->red
.msb_right
= 0;
641 var
->green
.length
= 8;
642 var
->green
.offset
= 8;
643 var
->green
.msb_right
= 0;
645 var
->blue
.length
= 8;
646 var
->blue
.offset
= 0;
647 var
->blue
.msb_right
= 0;
649 var
->transp
.length
= 8;
650 var
->transp
.offset
= 24;
651 var
->transp
.msb_right
= 0;
660 /* Copy nonstd field to/from sync for fbset usage */
661 var
->sync
|= var
->nonstd
;
662 var
->nonstd
|= var
->sync
;
664 adjust_aoi_size_position(var
, info
);
668 static void set_fix(struct fb_info
*info
)
670 struct fb_fix_screeninfo
*fix
= &info
->fix
;
671 struct fb_var_screeninfo
*var
= &info
->var
;
672 struct mfb_info
*mfbi
= info
->par
;
674 strncpy(fix
->id
, mfbi
->id
, strlen(mfbi
->id
));
675 fix
->line_length
= var
->xres_virtual
* var
->bits_per_pixel
/ 8;
676 fix
->type
= FB_TYPE_PACKED_PIXELS
;
677 fix
->accel
= FB_ACCEL_NONE
;
678 fix
->visual
= FB_VISUAL_TRUECOLOR
;
683 static void update_lcdc(struct fb_info
*info
)
685 struct fb_var_screeninfo
*var
= &info
->var
;
686 struct mfb_info
*mfbi
= info
->par
;
687 struct fsl_diu_data
*machine_data
= mfbi
->parent
;
690 char __iomem
*cursor_base
, *gamma_table_base
;
696 if (mfbi
->type
== MFB_TYPE_OFF
) {
697 fsl_diu_disable_panel(info
);
701 diu_ops
.set_monitor_port(machine_data
->monitor_port
);
702 gamma_table_base
= pool
.gamma
.vaddr
;
703 cursor_base
= pool
.cursor
.vaddr
;
704 /* Prep for DIU init - gamma table, cursor table */
706 for (i
= 0; i
<= 2; i
++)
707 for (j
= 0; j
<= 255; j
++)
708 *gamma_table_base
++ = j
;
710 diu_ops
.set_gamma_table(machine_data
->monitor_port
, pool
.gamma
.vaddr
);
714 /* Program DIU registers */
716 out_be32(&hw
->gamma
, pool
.gamma
.paddr
);
717 out_be32(&hw
->cursor
, pool
.cursor
.paddr
);
719 out_be32(&hw
->bgnd
, 0x007F7F7F); /* BGND */
720 out_be32(&hw
->bgnd_wb
, 0); /* BGND_WB */
721 out_be32(&hw
->disp_size
, (var
->yres
<< 16 | var
->xres
));
723 out_be32(&hw
->wb_size
, 0); /* WB SIZE */
724 out_be32(&hw
->wb_mem_addr
, 0); /* WB MEM ADDR */
726 /* Horizontal and vertical configuration register */
727 temp
= var
->left_margin
<< 22 | /* BP_H */
728 var
->hsync_len
<< 11 | /* PW_H */
729 var
->right_margin
; /* FP_H */
731 out_be32(&hw
->hsyn_para
, temp
);
733 temp
= var
->upper_margin
<< 22 | /* BP_V */
734 var
->vsync_len
<< 11 | /* PW_V */
735 var
->lower_margin
; /* FP_V */
737 out_be32(&hw
->vsyn_para
, temp
);
739 diu_ops
.set_pixel_clock(var
->pixclock
);
741 out_be32(&hw
->syn_pol
, 0); /* SYNC SIGNALS POLARITY */
742 out_be32(&hw
->thresholds
, 0x00037800); /* The Thresholds */
743 out_be32(&hw
->int_status
, 0); /* INTERRUPT STATUS */
744 out_be32(&hw
->plut
, 0x01F5F666);
750 static int map_video_memory(struct fb_info
*info
)
753 u32 smem_len
= info
->fix
.line_length
* info
->var
.yres_virtual
;
755 info
->screen_base
= fsl_diu_alloc(smem_len
, &phys
);
756 if (info
->screen_base
== NULL
) {
757 dev_err(info
->dev
, "unable to allocate fb memory\n");
760 mutex_lock(&info
->mm_lock
);
761 info
->fix
.smem_start
= (unsigned long) phys
;
762 info
->fix
.smem_len
= smem_len
;
763 mutex_unlock(&info
->mm_lock
);
764 info
->screen_size
= info
->fix
.smem_len
;
769 static void unmap_video_memory(struct fb_info
*info
)
771 fsl_diu_free(info
->screen_base
, info
->fix
.smem_len
);
772 mutex_lock(&info
->mm_lock
);
773 info
->screen_base
= NULL
;
774 info
->fix
.smem_start
= 0;
775 info
->fix
.smem_len
= 0;
776 mutex_unlock(&info
->mm_lock
);
780 * Using the fb_var_screeninfo in fb_info we set the aoi of this
781 * particular framebuffer. It is a light version of fsl_diu_set_par.
783 static int fsl_diu_set_aoi(struct fb_info
*info
)
785 struct fb_var_screeninfo
*var
= &info
->var
;
786 struct mfb_info
*mfbi
= info
->par
;
787 struct diu_ad
*ad
= mfbi
->ad
;
789 /* AOI should not be greater than display size */
790 ad
->offset_xyi
= cpu_to_le32((var
->yoffset
<< 16) | var
->xoffset
);
791 ad
->offset_xyd
= cpu_to_le32((mfbi
->y_aoi_d
<< 16) | mfbi
->x_aoi_d
);
796 * Using the fb_var_screeninfo in fb_info we set the resolution of this
797 * particular framebuffer. This function alters the fb_fix_screeninfo stored
798 * in fb_info. It does not alter var in fb_info since we are using that
799 * data. This means we depend on the data in var inside fb_info to be
800 * supported by the hardware. fsl_diu_check_var is always called before
801 * fsl_diu_set_par to ensure this.
803 static int fsl_diu_set_par(struct fb_info
*info
)
806 struct fb_var_screeninfo
*var
= &info
->var
;
807 struct mfb_info
*mfbi
= info
->par
;
808 struct fsl_diu_data
*machine_data
= mfbi
->parent
;
809 struct diu_ad
*ad
= mfbi
->ad
;
815 mfbi
->cursor_reset
= 1;
817 len
= info
->var
.yres_virtual
* info
->fix
.line_length
;
818 /* Alloc & dealloc each time resolution/bpp change */
819 if (len
!= info
->fix
.smem_len
) {
820 if (info
->fix
.smem_start
)
821 unmap_video_memory(info
);
823 /* Memory allocation for framebuffer */
824 if (map_video_memory(info
)) {
825 dev_err(info
->dev
, "unable to allocate fb memory 1\n");
830 ad
->pix_fmt
= diu_ops
.get_pixel_format(machine_data
->monitor_port
,
831 var
->bits_per_pixel
);
832 ad
->addr
= cpu_to_le32(info
->fix
.smem_start
);
833 ad
->src_size_g_alpha
= cpu_to_le32((var
->yres_virtual
<< 12) |
834 var
->xres_virtual
) | mfbi
->g_alpha
;
835 /* AOI should not be greater than display size */
836 ad
->aoi_size
= cpu_to_le32((var
->yres
<< 16) | var
->xres
);
837 ad
->offset_xyi
= cpu_to_le32((var
->yoffset
<< 16) | var
->xoffset
);
838 ad
->offset_xyd
= cpu_to_le32((mfbi
->y_aoi_d
<< 16) | mfbi
->x_aoi_d
);
840 /* Disable chroma keying function */
849 if (mfbi
->index
== 0)
854 static inline __u32
CNVT_TOHW(__u32 val
, __u32 width
)
856 return ((val
<< width
) + 0x7FFF - val
) >> 16;
860 * Set a single color register. The values supplied have a 16 bit magnitude
861 * which needs to be scaled in this function for the hardware. Things to take
862 * into consideration are how many color registers, if any, are supported with
863 * the current color visual. With truecolor mode no color palettes are
864 * supported. Here a pseudo palette is created which we store the value in
865 * pseudo_palette in struct fb_info. For pseudocolor mode we have a limited
868 static int fsl_diu_setcolreg(unsigned int regno
, unsigned int red
,
869 unsigned int green
, unsigned int blue
,
870 unsigned int transp
, struct fb_info
*info
)
875 * If greyscale is true, then we convert the RGB value
876 * to greyscale no matter what visual we are using.
878 if (info
->var
.grayscale
)
879 red
= green
= blue
= (19595 * red
+ 38470 * green
+
881 switch (info
->fix
.visual
) {
882 case FB_VISUAL_TRUECOLOR
:
884 * 16-bit True Colour. We encode the RGB value
885 * according to the RGB bitfield information.
888 u32
*pal
= info
->pseudo_palette
;
891 red
= CNVT_TOHW(red
, info
->var
.red
.length
);
892 green
= CNVT_TOHW(green
, info
->var
.green
.length
);
893 blue
= CNVT_TOHW(blue
, info
->var
.blue
.length
);
894 transp
= CNVT_TOHW(transp
, info
->var
.transp
.length
);
896 v
= (red
<< info
->var
.red
.offset
) |
897 (green
<< info
->var
.green
.offset
) |
898 (blue
<< info
->var
.blue
.offset
) |
899 (transp
<< info
->var
.transp
.offset
);
911 * Pan (or wrap, depending on the `vmode' field) the display using the
912 * 'xoffset' and 'yoffset' fields of the 'var' structure. If the values
913 * don't fit, return -EINVAL.
915 static int fsl_diu_pan_display(struct fb_var_screeninfo
*var
,
916 struct fb_info
*info
)
918 if ((info
->var
.xoffset
== var
->xoffset
) &&
919 (info
->var
.yoffset
== var
->yoffset
))
920 return 0; /* No change, do nothing */
922 if (var
->xoffset
< 0 || var
->yoffset
< 0
923 || var
->xoffset
+ info
->var
.xres
> info
->var
.xres_virtual
924 || var
->yoffset
+ info
->var
.yres
> info
->var
.yres_virtual
)
927 info
->var
.xoffset
= var
->xoffset
;
928 info
->var
.yoffset
= var
->yoffset
;
930 if (var
->vmode
& FB_VMODE_YWRAP
)
931 info
->var
.vmode
|= FB_VMODE_YWRAP
;
933 info
->var
.vmode
&= ~FB_VMODE_YWRAP
;
935 fsl_diu_set_aoi(info
);
941 * Blank the screen if blank_mode != 0, else unblank. Return 0 if blanking
942 * succeeded, != 0 if un-/blanking failed.
943 * blank_mode == 2: suspend vsync
944 * blank_mode == 3: suspend hsync
945 * blank_mode == 4: powerdown
947 static int fsl_diu_blank(int blank_mode
, struct fb_info
*info
)
949 struct mfb_info
*mfbi
= info
->par
;
951 mfbi
->blank
= blank_mode
;
953 switch (blank_mode
) {
954 case FB_BLANK_VSYNC_SUSPEND
:
955 case FB_BLANK_HSYNC_SUSPEND
:
956 /* FIXME: fixes to enable_panel and enable lcdc needed */
957 case FB_BLANK_NORMAL
:
958 /* fsl_diu_disable_panel(info);*/
960 case FB_BLANK_POWERDOWN
:
961 /* disable_lcdc(info); */
963 case FB_BLANK_UNBLANK
:
964 /* fsl_diu_enable_panel(info);*/
971 static int fsl_diu_ioctl(struct fb_info
*info
, unsigned int cmd
,
974 struct mfb_info
*mfbi
= info
->par
;
975 struct diu_ad
*ad
= mfbi
->ad
;
976 struct mfb_chroma_key ck
;
977 unsigned char global_alpha
;
978 struct aoi_display_offset aoi_d
;
980 void __user
*buf
= (void __user
*)arg
;
986 if (copy_from_user(&pix_fmt
, buf
, sizeof(pix_fmt
)))
988 ad
->pix_fmt
= pix_fmt
;
991 pix_fmt
= ad
->pix_fmt
;
992 if (copy_to_user(buf
, &pix_fmt
, sizeof(pix_fmt
)))
996 if (copy_from_user(&aoi_d
, buf
, sizeof(aoi_d
)))
998 mfbi
->x_aoi_d
= aoi_d
.x_aoi_d
;
999 mfbi
->y_aoi_d
= aoi_d
.y_aoi_d
;
1000 fsl_diu_check_var(&info
->var
, info
);
1001 fsl_diu_set_aoi(info
);
1004 aoi_d
.x_aoi_d
= mfbi
->x_aoi_d
;
1005 aoi_d
.y_aoi_d
= mfbi
->y_aoi_d
;
1006 if (copy_to_user(buf
, &aoi_d
, sizeof(aoi_d
)))
1010 global_alpha
= mfbi
->g_alpha
;
1011 if (copy_to_user(buf
, &global_alpha
, sizeof(global_alpha
)))
1015 /* set panel information */
1016 if (copy_from_user(&global_alpha
, buf
, sizeof(global_alpha
)))
1018 ad
->src_size_g_alpha
= (ad
->src_size_g_alpha
& (~0xff)) |
1019 (global_alpha
& 0xff);
1020 mfbi
->g_alpha
= global_alpha
;
1022 case MFB_SET_CHROMA_KEY
:
1023 /* set panel winformation */
1024 if (copy_from_user(&ck
, buf
, sizeof(ck
)))
1028 (ck
.red_max
< ck
.red_min
||
1029 ck
.green_max
< ck
.green_min
||
1030 ck
.blue_max
< ck
.blue_min
))
1041 ad
->ckmax_r
= ck
.red_max
;
1042 ad
->ckmax_g
= ck
.green_max
;
1043 ad
->ckmax_b
= ck
.blue_max
;
1044 ad
->ckmin_r
= ck
.red_min
;
1045 ad
->ckmin_g
= ck
.green_min
;
1046 ad
->ckmin_b
= ck
.blue_min
;
1049 case FBIOGET_GWINFO
:
1050 if (mfbi
->type
== MFB_TYPE_OFF
)
1052 /* get graphic window information */
1053 if (copy_to_user(buf
, ad
, sizeof(*ad
)))
1058 dev_err(info
->dev
, "unknown ioctl command (0x%08X)\n", cmd
);
1059 return -ENOIOCTLCMD
;
1065 /* turn on fb if count == 1
1067 static int fsl_diu_open(struct fb_info
*info
, int user
)
1069 struct mfb_info
*mfbi
= info
->par
;
1072 /* free boot splash memory on first /dev/fb0 open */
1073 if (!mfbi
->index
&& diu_ops
.release_bootmem
)
1074 diu_ops
.release_bootmem();
1076 spin_lock(&diu_lock
);
1078 if (mfbi
->count
== 1) {
1079 fsl_diu_check_var(&info
->var
, info
);
1080 res
= fsl_diu_set_par(info
);
1084 res
= fsl_diu_enable_panel(info
);
1090 spin_unlock(&diu_lock
);
1094 /* turn off fb if count == 0
1096 static int fsl_diu_release(struct fb_info
*info
, int user
)
1098 struct mfb_info
*mfbi
= info
->par
;
1101 spin_lock(&diu_lock
);
1103 if (mfbi
->count
== 0) {
1104 res
= fsl_diu_disable_panel(info
);
1108 spin_unlock(&diu_lock
);
1112 static struct fb_ops fsl_diu_ops
= {
1113 .owner
= THIS_MODULE
,
1114 .fb_check_var
= fsl_diu_check_var
,
1115 .fb_set_par
= fsl_diu_set_par
,
1116 .fb_setcolreg
= fsl_diu_setcolreg
,
1117 .fb_blank
= fsl_diu_blank
,
1118 .fb_pan_display
= fsl_diu_pan_display
,
1119 .fb_fillrect
= cfb_fillrect
,
1120 .fb_copyarea
= cfb_copyarea
,
1121 .fb_imageblit
= cfb_imageblit
,
1122 .fb_ioctl
= fsl_diu_ioctl
,
1123 .fb_open
= fsl_diu_open
,
1124 .fb_release
= fsl_diu_release
,
1127 static int init_fbinfo(struct fb_info
*info
)
1129 struct mfb_info
*mfbi
= info
->par
;
1131 info
->device
= NULL
;
1132 info
->var
.activate
= FB_ACTIVATE_NOW
;
1133 info
->fbops
= &fsl_diu_ops
;
1134 info
->flags
= FBINFO_FLAG_DEFAULT
;
1135 info
->pseudo_palette
= &mfbi
->pseudo_palette
;
1137 /* Allocate colormap */
1138 fb_alloc_cmap(&info
->cmap
, 16, 0);
1142 static int __devinit
install_fb(struct fb_info
*info
)
1145 struct mfb_info
*mfbi
= info
->par
;
1146 const char *aoi_mode
, *init_aoi_mode
= "320x240";
1147 struct fb_videomode
*db
= fsl_diu_mode_db
;
1148 unsigned int dbsize
= ARRAY_SIZE(fsl_diu_mode_db
);
1149 int has_default_mode
= 1;
1151 if (init_fbinfo(info
))
1154 if (mfbi
->index
== 0) { /* plane 0 */
1155 if (mfbi
->edid_data
) {
1156 /* Now build modedb from EDID */
1157 fb_edid_to_monspecs(mfbi
->edid_data
, &info
->monspecs
);
1158 fb_videomode_to_modelist(info
->monspecs
.modedb
,
1159 info
->monspecs
.modedb_len
,
1161 db
= info
->monspecs
.modedb
;
1162 dbsize
= info
->monspecs
.modedb_len
;
1166 aoi_mode
= init_aoi_mode
;
1168 rc
= fb_find_mode(&info
->var
, info
, aoi_mode
, db
, dbsize
,
1169 &fsl_diu_default_mode
, default_bpp
);
1172 * For plane 0 we continue and look into
1173 * driver's internal modedb.
1175 if (mfbi
->index
== 0 && mfbi
->edid_data
)
1176 has_default_mode
= 0;
1181 if (!has_default_mode
) {
1182 rc
= fb_find_mode(&info
->var
, info
, aoi_mode
, fsl_diu_mode_db
,
1183 ARRAY_SIZE(fsl_diu_mode_db
),
1184 &fsl_diu_default_mode
,
1186 if (rc
> 0 && rc
< 5)
1187 has_default_mode
= 1;
1190 /* Still not found, use preferred mode from database if any */
1191 if (!has_default_mode
&& info
->monspecs
.modedb
) {
1192 struct fb_monspecs
*specs
= &info
->monspecs
;
1193 struct fb_videomode
*modedb
= &specs
->modedb
[0];
1196 * Get preferred timing. If not found,
1197 * first mode in database will be used.
1199 if (specs
->misc
& FB_MISC_1ST_DETAIL
) {
1202 for (i
= 0; i
< specs
->modedb_len
; i
++) {
1203 if (specs
->modedb
[i
].flag
& FB_MODE_IS_FIRST
) {
1204 modedb
= &specs
->modedb
[i
];
1210 info
->var
.bits_per_pixel
= default_bpp
;
1211 fb_videomode_to_var(&info
->var
, modedb
);
1214 if (mfbi
->type
== MFB_TYPE_OFF
)
1215 mfbi
->blank
= FB_BLANK_NORMAL
;
1217 mfbi
->blank
= FB_BLANK_UNBLANK
;
1219 if (fsl_diu_check_var(&info
->var
, info
)) {
1220 dev_err(info
->dev
, "fsl_diu_check_var failed\n");
1221 fb_dealloc_cmap(&info
->cmap
);
1225 if (register_framebuffer(info
) < 0) {
1226 dev_err(info
->dev
, "register_framebuffer failed\n");
1227 unmap_video_memory(info
);
1228 fb_dealloc_cmap(&info
->cmap
);
1232 mfbi
->registered
= 1;
1233 dev_info(info
->dev
, "%s registered successfully\n", mfbi
->id
);
1238 static void uninstall_fb(struct fb_info
*info
)
1240 struct mfb_info
*mfbi
= info
->par
;
1242 if (!mfbi
->registered
)
1245 if (mfbi
->index
== 0)
1246 kfree(mfbi
->edid_data
);
1248 unregister_framebuffer(info
);
1249 unmap_video_memory(info
);
1251 fb_dealloc_cmap(&info
->cmap
);
1253 mfbi
->registered
= 0;
1256 static irqreturn_t
fsl_diu_isr(int irq
, void *dev_id
)
1258 struct diu
*hw
= dr
.diu_reg
;
1259 unsigned int status
= in_be32(&hw
->int_status
);
1262 /* This is the workaround for underrun */
1263 if (status
& INT_UNDRUN
) {
1264 out_be32(&hw
->diu_mode
, 0);
1266 out_be32(&hw
->diu_mode
, 1);
1268 #if defined(CONFIG_NOT_COHERENT_CACHE)
1269 else if (status
& INT_VSYNC
) {
1272 for (i
= 0; i
< coherence_data_size
;
1273 i
+= d_cache_line_size
)
1274 __asm__
__volatile__ (
1276 ::[input
]"r"(&coherence_data
[i
]));
1284 static int request_irq_local(int irq
)
1286 unsigned long status
, ints
;
1292 /* Read to clear the status */
1293 status
= in_be32(&hw
->int_status
);
1295 ret
= request_irq(irq
, fsl_diu_isr
, 0, "diu", NULL
);
1297 ints
= INT_PARERR
| INT_LS_BF_VS
;
1298 #if !defined(CONFIG_NOT_COHERENT_CACHE)
1302 if (dr
.mode
== MFB_MODE2
|| dr
.mode
== MFB_MODE3
)
1303 ints
|= INT_VSYNC_WB
;
1305 /* Read to clear the status */
1306 status
= in_be32(&hw
->int_status
);
1307 out_be32(&hw
->int_mask
, ints
);
1313 static void free_irq_local(int irq
)
1315 struct diu
*hw
= dr
.diu_reg
;
1317 /* Disable all LCDC interrupt */
1318 out_be32(&hw
->int_mask
, 0x1f);
1320 free_irq(irq
, NULL
);
1325 * Power management hooks. Note that we won't be called from IRQ context,
1326 * unlike the blank functions above, so we may sleep.
1328 static int fsl_diu_suspend(struct platform_device
*ofdev
, pm_message_t state
)
1330 struct fsl_diu_data
*machine_data
;
1332 machine_data
= dev_get_drvdata(&ofdev
->dev
);
1333 disable_lcdc(machine_data
->fsl_diu_info
[0]);
1338 static int fsl_diu_resume(struct platform_device
*ofdev
)
1340 struct fsl_diu_data
*machine_data
;
1342 machine_data
= dev_get_drvdata(&ofdev
->dev
);
1343 enable_lcdc(machine_data
->fsl_diu_info
[0]);
1349 #define fsl_diu_suspend NULL
1350 #define fsl_diu_resume NULL
1351 #endif /* CONFIG_PM */
1353 /* Align to 64-bit(8-byte), 32-byte, etc. */
1354 static int allocate_buf(struct device
*dev
, struct diu_addr
*buf
, u32 size
,
1359 dma_addr_t paddr
= 0;
1361 ssize
= size
+ bytes_align
;
1362 buf
->vaddr
= dma_alloc_coherent(dev
, ssize
, &paddr
, GFP_DMA
|
1367 buf
->paddr
= (__u32
) paddr
;
1369 mask
= bytes_align
- 1;
1370 offset
= (u32
)buf
->paddr
& mask
;
1372 buf
->offset
= bytes_align
- offset
;
1373 buf
->paddr
= (u32
)buf
->paddr
+ offset
;
1380 static void free_buf(struct device
*dev
, struct diu_addr
*buf
, u32 size
,
1383 dma_free_coherent(dev
, size
+ bytes_align
, buf
->vaddr
,
1384 buf
->paddr
- buf
->offset
);
1387 static ssize_t
store_monitor(struct device
*device
,
1388 struct device_attribute
*attr
, const char *buf
, size_t count
)
1390 enum fsl_diu_monitor_port old_monitor_port
;
1391 struct fsl_diu_data
*machine_data
=
1392 container_of(attr
, struct fsl_diu_data
, dev_attr
);
1394 old_monitor_port
= machine_data
->monitor_port
;
1395 machine_data
->monitor_port
= fsl_diu_name_to_port(buf
);
1397 if (old_monitor_port
!= machine_data
->monitor_port
) {
1398 /* All AOIs need adjust pixel format
1399 * fsl_diu_set_par only change the pixsel format here
1400 * unlikely to fail. */
1401 fsl_diu_set_par(machine_data
->fsl_diu_info
[0]);
1402 fsl_diu_set_par(machine_data
->fsl_diu_info
[1]);
1403 fsl_diu_set_par(machine_data
->fsl_diu_info
[2]);
1404 fsl_diu_set_par(machine_data
->fsl_diu_info
[3]);
1405 fsl_diu_set_par(machine_data
->fsl_diu_info
[4]);
1410 static ssize_t
show_monitor(struct device
*device
,
1411 struct device_attribute
*attr
, char *buf
)
1413 struct fsl_diu_data
*machine_data
=
1414 container_of(attr
, struct fsl_diu_data
, dev_attr
);
1416 switch (machine_data
->monitor_port
) {
1417 case FSL_DIU_PORT_DVI
:
1418 return sprintf(buf
, "DVI\n");
1419 case FSL_DIU_PORT_LVDS
:
1420 return sprintf(buf
, "Single-link LVDS\n");
1421 case FSL_DIU_PORT_DLVDS
:
1422 return sprintf(buf
, "Dual-link LVDS\n");
1428 static int __devinit
fsl_diu_probe(struct platform_device
*ofdev
)
1430 struct device_node
*np
= ofdev
->dev
.of_node
;
1431 struct mfb_info
*mfbi
;
1432 phys_addr_t dummy_ad_addr
= 0;
1433 int ret
, i
, error
= 0;
1434 struct resource res
;
1435 struct fsl_diu_data
*machine_data
;
1438 machine_data
= kzalloc(sizeof(struct fsl_diu_data
), GFP_KERNEL
);
1442 for (i
= 0; i
< ARRAY_SIZE(machine_data
->fsl_diu_info
); i
++) {
1443 machine_data
->fsl_diu_info
[i
] =
1444 framebuffer_alloc(sizeof(struct mfb_info
), &ofdev
->dev
);
1445 if (!machine_data
->fsl_diu_info
[i
]) {
1446 dev_err(&ofdev
->dev
, "cannot allocate memory\n");
1450 mfbi
= machine_data
->fsl_diu_info
[i
]->par
;
1451 memcpy(mfbi
, &mfb_template
[i
], sizeof(struct mfb_info
));
1452 mfbi
->parent
= machine_data
;
1454 if (mfbi
->index
== 0) {
1459 prop
= of_get_property(np
, "edid", &len
);
1460 if (prop
&& len
== EDID_LENGTH
)
1461 mfbi
->edid_data
= kmemdup(prop
, EDID_LENGTH
,
1466 ret
= of_address_to_resource(np
, 0, &res
);
1468 dev_err(&ofdev
->dev
, "could not obtain DIU address\n");
1472 dev_err(&ofdev
->dev
, "invalid DIU address\n");
1476 dr
.diu_reg
= ioremap(res
.start
, sizeof(struct diu
));
1478 dev_err(&ofdev
->dev
, "Err: can't map DIU registers!\n");
1483 diu_mode
= in_be32(&dr
.diu_reg
->diu_mode
);
1484 if (diu_mode
!= MFB_MODE1
)
1485 out_be32(&dr
.diu_reg
->diu_mode
, 0); /* disable DIU */
1487 /* Get the IRQ of the DIU */
1488 machine_data
->irq
= irq_of_parse_and_map(np
, 0);
1490 if (!machine_data
->irq
) {
1491 dev_err(&ofdev
->dev
, "could not get DIU IRQ\n");
1495 machine_data
->monitor_port
= monitor_port
;
1497 /* Area descriptor memory pool aligns to 64-bit boundary */
1498 if (allocate_buf(&ofdev
->dev
, &pool
.ad
,
1499 sizeof(struct diu_ad
) * FSL_AOI_NUM
, 8))
1502 /* Get memory for Gamma Table - 32-byte aligned memory */
1503 if (allocate_buf(&ofdev
->dev
, &pool
.gamma
, 768, 32)) {
1508 /* For performance, cursor bitmap buffer aligns to 32-byte boundary */
1509 if (allocate_buf(&ofdev
->dev
, &pool
.cursor
, MAX_CURS
* MAX_CURS
* 2,
1515 i
= ARRAY_SIZE(machine_data
->fsl_diu_info
);
1516 machine_data
->dummy_ad
= (struct diu_ad
*)
1517 ((u32
)pool
.ad
.vaddr
+ pool
.ad
.offset
) + i
;
1518 machine_data
->dummy_ad
->paddr
= pool
.ad
.paddr
+
1519 i
* sizeof(struct diu_ad
);
1520 machine_data
->dummy_aoi_virt
= fsl_diu_alloc(64, &dummy_ad_addr
);
1521 if (!machine_data
->dummy_aoi_virt
) {
1525 machine_data
->dummy_ad
->addr
= cpu_to_le32(dummy_ad_addr
);
1526 machine_data
->dummy_ad
->pix_fmt
= 0x88882317;
1527 machine_data
->dummy_ad
->src_size_g_alpha
= cpu_to_le32((4 << 12) | 4);
1528 machine_data
->dummy_ad
->aoi_size
= cpu_to_le32((4 << 16) | 2);
1529 machine_data
->dummy_ad
->offset_xyi
= 0;
1530 machine_data
->dummy_ad
->offset_xyd
= 0;
1531 machine_data
->dummy_ad
->next_ad
= 0;
1534 * Let DIU display splash screen if it was pre-initialized
1535 * by the bootloader, set dummy area descriptor otherwise.
1537 if (diu_mode
!= MFB_MODE1
)
1538 out_be32(&dr
.diu_reg
->desc
[0], machine_data
->dummy_ad
->paddr
);
1540 out_be32(&dr
.diu_reg
->desc
[1], machine_data
->dummy_ad
->paddr
);
1541 out_be32(&dr
.diu_reg
->desc
[2], machine_data
->dummy_ad
->paddr
);
1543 for (i
= 0; i
< ARRAY_SIZE(machine_data
->fsl_diu_info
); i
++) {
1544 machine_data
->fsl_diu_info
[i
]->fix
.smem_start
= 0;
1545 mfbi
= machine_data
->fsl_diu_info
[i
]->par
;
1546 mfbi
->ad
= (struct diu_ad
*)((u32
)pool
.ad
.vaddr
1547 + pool
.ad
.offset
) + i
;
1548 mfbi
->ad
->paddr
= pool
.ad
.paddr
+ i
* sizeof(struct diu_ad
);
1549 ret
= install_fb(machine_data
->fsl_diu_info
[i
]);
1551 dev_err(&ofdev
->dev
,
1552 "Failed to register framebuffer %d\n",
1558 if (request_irq_local(machine_data
->irq
)) {
1559 dev_err(machine_data
->fsl_diu_info
[0]->dev
,
1560 "could not request irq for diu.");
1564 sysfs_attr_init(&machine_data
->dev_attr
.attr
);
1565 machine_data
->dev_attr
.attr
.name
= "monitor";
1566 machine_data
->dev_attr
.attr
.mode
= S_IRUGO
|S_IWUSR
;
1567 machine_data
->dev_attr
.show
= show_monitor
;
1568 machine_data
->dev_attr
.store
= store_monitor
;
1569 error
= device_create_file(machine_data
->fsl_diu_info
[0]->dev
,
1570 &machine_data
->dev_attr
);
1572 dev_err(machine_data
->fsl_diu_info
[0]->dev
,
1573 "could not create sysfs %s file\n",
1574 machine_data
->dev_attr
.attr
.name
);
1577 dev_set_drvdata(&ofdev
->dev
, machine_data
);
1581 for (i
= ARRAY_SIZE(machine_data
->fsl_diu_info
);
1583 uninstall_fb(machine_data
->fsl_diu_info
[i
- 1]);
1585 free_buf(&ofdev
->dev
, &pool
.ad
,
1586 sizeof(struct diu_ad
) * FSL_AOI_NUM
, 8);
1587 if (pool
.gamma
.vaddr
)
1588 free_buf(&ofdev
->dev
, &pool
.gamma
, 768, 32);
1589 if (pool
.cursor
.vaddr
)
1590 free_buf(&ofdev
->dev
, &pool
.cursor
, MAX_CURS
* MAX_CURS
* 2,
1592 if (machine_data
->dummy_aoi_virt
)
1593 fsl_diu_free(machine_data
->dummy_aoi_virt
, 64);
1594 iounmap(dr
.diu_reg
);
1597 for (i
= 0; i
< ARRAY_SIZE(machine_data
->fsl_diu_info
); i
++)
1598 if (machine_data
->fsl_diu_info
[i
])
1599 framebuffer_release(machine_data
->fsl_diu_info
[i
]);
1600 kfree(machine_data
);
1606 static int fsl_diu_remove(struct platform_device
*ofdev
)
1608 struct fsl_diu_data
*machine_data
;
1611 machine_data
= dev_get_drvdata(&ofdev
->dev
);
1612 disable_lcdc(machine_data
->fsl_diu_info
[0]);
1613 free_irq_local(machine_data
->irq
);
1614 for (i
= ARRAY_SIZE(machine_data
->fsl_diu_info
); i
> 0; i
--)
1615 uninstall_fb(machine_data
->fsl_diu_info
[i
- 1]);
1617 free_buf(&ofdev
->dev
, &pool
.ad
,
1618 sizeof(struct diu_ad
) * FSL_AOI_NUM
, 8);
1619 if (pool
.gamma
.vaddr
)
1620 free_buf(&ofdev
->dev
, &pool
.gamma
, 768, 32);
1621 if (pool
.cursor
.vaddr
)
1622 free_buf(&ofdev
->dev
, &pool
.cursor
, MAX_CURS
* MAX_CURS
* 2,
1624 if (machine_data
->dummy_aoi_virt
)
1625 fsl_diu_free(machine_data
->dummy_aoi_virt
, 64);
1626 iounmap(dr
.diu_reg
);
1627 for (i
= 0; i
< ARRAY_SIZE(machine_data
->fsl_diu_info
); i
++)
1628 if (machine_data
->fsl_diu_info
[i
])
1629 framebuffer_release(machine_data
->fsl_diu_info
[i
]);
1630 kfree(machine_data
);
1636 static int __init
fsl_diu_setup(char *options
)
1641 if (!options
|| !*options
)
1644 while ((opt
= strsep(&options
, ",")) != NULL
) {
1647 if (!strncmp(opt
, "monitor=", 8)) {
1648 monitor_port
= fsl_diu_name_to_port(opt
+ 8);
1649 } else if (!strncmp(opt
, "bpp=", 4)) {
1650 if (!strict_strtoul(opt
+ 4, 10, &val
))
1660 static struct of_device_id fsl_diu_match
[] = {
1661 #ifdef CONFIG_PPC_MPC512x
1663 .compatible
= "fsl,mpc5121-diu",
1667 .compatible
= "fsl,diu",
1671 MODULE_DEVICE_TABLE(of
, fsl_diu_match
);
1673 static struct platform_driver fsl_diu_driver
= {
1676 .owner
= THIS_MODULE
,
1677 .of_match_table
= fsl_diu_match
,
1679 .probe
= fsl_diu_probe
,
1680 .remove
= fsl_diu_remove
,
1681 .suspend
= fsl_diu_suspend
,
1682 .resume
= fsl_diu_resume
,
1685 static int __init
fsl_diu_init(void)
1687 #ifdef CONFIG_NOT_COHERENT_CACHE
1688 struct device_node
*np
;
1696 * For kernel boot options (in 'video=xxxfb:<options>' format)
1698 if (fb_get_options("fslfb", &option
))
1700 fsl_diu_setup(option
);
1702 monitor_port
= fsl_diu_name_to_port(monitor_string
);
1704 pr_info("Freescale Display Interface Unit (DIU) framebuffer driver\n");
1706 #ifdef CONFIG_NOT_COHERENT_CACHE
1707 np
= of_find_node_by_type(NULL
, "cpu");
1709 pr_err("fsl-diu-fb: can't find 'cpu' device node\n");
1713 prop
= of_get_property(np
, "d-cache-size", NULL
);
1715 pr_err("fsl-diu-fb: missing 'd-cache-size' property' "
1722 * Freescale PLRU requires 13/8 times the cache size to do a proper
1723 * displacement flush
1725 coherence_data_size
= *prop
* 13;
1726 coherence_data_size
/= 8;
1728 prop
= of_get_property(np
, "d-cache-line-size", NULL
);
1730 pr_err("fsl-diu-fb: missing 'd-cache-line-size' property' "
1735 d_cache_line_size
= *prop
;
1738 coherence_data
= vmalloc(coherence_data_size
);
1739 if (!coherence_data
)
1743 ret
= platform_driver_register(&fsl_diu_driver
);
1745 pr_err("fsl-diu-fb: failed to register platform driver\n");
1746 #if defined(CONFIG_NOT_COHERENT_CACHE)
1747 vfree(coherence_data
);
1749 iounmap(dr
.diu_reg
);
1754 static void __exit
fsl_diu_exit(void)
1756 platform_driver_unregister(&fsl_diu_driver
);
1757 #if defined(CONFIG_NOT_COHERENT_CACHE)
1758 vfree(coherence_data
);
1762 module_init(fsl_diu_init
);
1763 module_exit(fsl_diu_exit
);
1765 MODULE_AUTHOR("York Sun <yorksun@freescale.com>");
1766 MODULE_DESCRIPTION("Freescale DIU framebuffer driver");
1767 MODULE_LICENSE("GPL");
1769 module_param_named(mode
, fb_mode
, charp
, 0);
1770 MODULE_PARM_DESC(mode
,
1771 "Specify resolution as \"<xres>x<yres>[-<bpp>][@<refresh>]\" ");
1772 module_param_named(bpp
, default_bpp
, ulong
, 0);
1773 MODULE_PARM_DESC(bpp
, "Specify bit-per-pixel if not specified in 'mode'");
1774 module_param_named(monitor
, monitor_string
, charp
, 0);
1775 MODULE_PARM_DESC(monitor
, "Specify the monitor port "
1776 "(\"dvi\", \"lvds\", or \"dlvds\") if supported by the platform");