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>
33 #include <linux/spinlock.h>
34 #include <linux/of_address.h>
35 #include <linux/of_irq.h>
37 #include <sysdev/fsl_soc.h>
38 #include <linux/fsl-diu-fb.h>
41 #define NUM_AOIS 5 /* 1 for plane 0, 2 for planes 1 & 2 each */
43 /* HW cursor parameters */
46 /* INT_STATUS/INT_MASK field descriptions */
47 #define INT_VSYNC 0x01 /* Vsync interrupt */
48 #define INT_VSYNC_WB 0x02 /* Vsync interrupt for write back operation */
49 #define INT_UNDRUN 0x04 /* Under run exception interrupt */
50 #define INT_PARERR 0x08 /* Display parameters error interrupt */
51 #define INT_LS_BF_VS 0x10 /* Lines before vsync. interrupt */
54 * List of supported video modes
56 * The first entry is the default video mode. The remain entries are in
57 * order if increasing resolution and frequency. The 320x240-60 mode is
58 * the initial AOI for the second and third planes.
60 static struct fb_videomode fsl_diu_mode_db
[] = {
72 .sync
= FB_SYNC_COMP_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
73 .vmode
= FB_VMODE_NONINTERLACED
86 .sync
= FB_SYNC_COMP_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
87 .vmode
= FB_VMODE_NONINTERLACED
100 .sync
= FB_SYNC_COMP_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
101 .vmode
= FB_VMODE_NONINTERLACED
114 .sync
= FB_SYNC_COMP_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
115 .vmode
= FB_VMODE_NONINTERLACED
128 .sync
= FB_SYNC_COMP_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
129 .vmode
= FB_VMODE_NONINTERLACED
142 .sync
= FB_SYNC_COMP_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
143 .vmode
= FB_VMODE_NONINTERLACED
156 .sync
= FB_SYNC_COMP_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
157 .vmode
= FB_VMODE_NONINTERLACED
170 .sync
= FB_SYNC_COMP_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
171 .vmode
= FB_VMODE_NONINTERLACED
184 .sync
= FB_SYNC_COMP_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
185 .vmode
= FB_VMODE_NONINTERLACED
198 .sync
= FB_SYNC_COMP_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
199 .vmode
= FB_VMODE_NONINTERLACED
212 .sync
= FB_SYNC_COMP_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
213 .vmode
= FB_VMODE_NONINTERLACED
226 .sync
= FB_SYNC_COMP_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
227 .vmode
= FB_VMODE_NONINTERLACED
240 .sync
= FB_SYNC_COMP_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
241 .vmode
= FB_VMODE_NONINTERLACED
254 .sync
= FB_SYNC_COMP_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
255 .vmode
= FB_VMODE_NONINTERLACED
268 .sync
= FB_SYNC_COMP_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
269 .vmode
= FB_VMODE_NONINTERLACED
282 .sync
= FB_SYNC_COMP_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
283 .vmode
= FB_VMODE_NONINTERLACED
296 .sync
= FB_SYNC_COMP_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
297 .vmode
= FB_VMODE_NONINTERLACED
310 .sync
= FB_SYNC_COMP_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
311 .vmode
= FB_VMODE_NONINTERLACED
315 static char *fb_mode
;
316 static unsigned long default_bpp
= 32;
317 static enum fsl_diu_monitor_port monitor_port
;
318 static char *monitor_string
;
320 #if defined(CONFIG_NOT_COHERENT_CACHE)
321 static u8
*coherence_data
;
322 static size_t coherence_data_size
;
323 static unsigned int d_cache_line_size
;
326 static DEFINE_SPINLOCK(diu_lock
);
329 PLANE0
= 0, /* Plane 0, only one AOI that fills the screen */
330 PLANE1_AOI0
, /* Plane 1, first AOI */
331 PLANE1_AOI1
, /* Plane 1, second AOI */
332 PLANE2_AOI0
, /* Plane 2, first AOI */
333 PLANE2_AOI1
, /* Plane 2, second AOI */
337 enum mfb_index index
;
340 unsigned long pseudo_palette
[16];
342 unsigned char g_alpha
;
344 int x_aoi_d
; /* aoi display x offset to physical screen */
345 int y_aoi_d
; /* aoi display y offset to physical screen */
346 struct fsl_diu_data
*parent
;
350 * struct fsl_diu_data - per-DIU data structure
351 * @dma_addr: DMA address of this structure
352 * @fsl_diu_info: fb_info objects, one per AOI
353 * @dev_attr: sysfs structure
355 * @monitor_port: the monitor port this DIU is connected to
356 * @diu_reg: pointer to the DIU hardware registers
357 * @reg_lock: spinlock for register access
358 * @dummy_aoi: video buffer for the 4x4 32-bit dummy AOI
359 * dummy_ad: DIU Area Descriptor for the dummy AOI
360 * @ad[]: Area Descriptors for each real AOI
361 * @gamma: gamma color table
362 * @cursor: hardware cursor data
364 * This data structure must be allocated with 32-byte alignment, so that the
365 * internal fields can be aligned properly.
367 struct fsl_diu_data
{
369 struct fb_info fsl_diu_info
[NUM_AOIS
];
370 struct mfb_info mfb
[NUM_AOIS
];
371 struct device_attribute dev_attr
;
373 enum fsl_diu_monitor_port monitor_port
;
374 struct diu __iomem
*diu_reg
;
376 u8 dummy_aoi
[4 * 4 * 4];
377 struct diu_ad dummy_ad
__aligned(8);
378 struct diu_ad ad
[NUM_AOIS
] __aligned(8);
379 u8 gamma
[256 * 3] __aligned(32);
380 /* It's easier to parse the cursor data as little-endian */
381 __le16 cursor
[MAX_CURS
* MAX_CURS
] __aligned(32);
382 /* Blank cursor data -- used to hide the cursor */
383 __le16 blank_cursor
[MAX_CURS
* MAX_CURS
] __aligned(32);
384 uint8_t edid_data
[EDID_LENGTH
];
388 /* Determine the DMA address of a member of the fsl_diu_data structure */
389 #define DMA_ADDR(p, f) ((p)->dma_addr + offsetof(struct fsl_diu_data, f))
391 static const struct mfb_info mfb_template
[] = {
401 .index
= PLANE1_AOI0
,
410 .index
= PLANE1_AOI1
,
419 .index
= PLANE2_AOI0
,
428 .index
= PLANE2_AOI1
,
439 static void __attribute__ ((unused
)) fsl_diu_dump(struct diu __iomem
*hw
)
442 pr_debug("DIU: desc=%08x,%08x,%08x, gamma=%08x palette=%08x "
443 "cursor=%08x curs_pos=%08x diu_mode=%08x bgnd=%08x "
444 "disp_size=%08x hsyn_para=%08x vsyn_para=%08x syn_pol=%08x "
445 "thresholds=%08x int_mask=%08x plut=%08x\n",
446 hw
->desc
[0], hw
->desc
[1], hw
->desc
[2], hw
->gamma
,
447 hw
->palette
, hw
->cursor
, hw
->curs_pos
, hw
->diu_mode
,
448 hw
->bgnd
, hw
->disp_size
, hw
->hsyn_para
, hw
->vsyn_para
,
449 hw
->syn_pol
, hw
->thresholds
, hw
->int_mask
, hw
->plut
);
455 * fsl_diu_name_to_port - convert a port name to a monitor port enum
457 * Takes the name of a monitor port ("dvi", "lvds", or "dlvds") and returns
458 * the enum fsl_diu_monitor_port that corresponds to that string.
460 * For compatibility with older versions, a number ("0", "1", or "2") is also
463 * If the string is unknown, DVI is assumed.
465 * If the particular port is not supported by the platform, another port
466 * (platform-specific) is chosen instead.
468 static enum fsl_diu_monitor_port
fsl_diu_name_to_port(const char *s
)
470 enum fsl_diu_monitor_port port
= FSL_DIU_PORT_DVI
;
474 if (!kstrtoul(s
, 10, &val
) && (val
<= 2))
475 port
= (enum fsl_diu_monitor_port
) val
;
476 else if (strncmp(s
, "lvds", 4) == 0)
477 port
= FSL_DIU_PORT_LVDS
;
478 else if (strncmp(s
, "dlvds", 5) == 0)
479 port
= FSL_DIU_PORT_DLVDS
;
482 if (diu_ops
.valid_monitor_port
)
483 port
= diu_ops
.valid_monitor_port(port
);
489 * Workaround for failed writing desc register of planes.
490 * Needed with MPC5121 DIU rev 2.0 silicon.
492 void wr_reg_wa(u32
*reg
, u32 val
)
496 } while (in_be32(reg
) != val
);
499 static void fsl_diu_enable_panel(struct fb_info
*info
)
501 struct mfb_info
*pmfbi
, *cmfbi
, *mfbi
= info
->par
;
502 struct diu_ad
*ad
= mfbi
->ad
;
503 struct fsl_diu_data
*data
= mfbi
->parent
;
504 struct diu __iomem
*hw
= data
->diu_reg
;
506 switch (mfbi
->index
) {
508 wr_reg_wa(&hw
->desc
[0], ad
->paddr
);
511 cmfbi
= &data
->mfb
[2];
512 if (hw
->desc
[1] != ad
->paddr
) { /* AOI0 closed */
513 if (cmfbi
->count
> 0) /* AOI1 open */
515 cpu_to_le32(cmfbi
->ad
->paddr
);
518 wr_reg_wa(&hw
->desc
[1], ad
->paddr
);
522 cmfbi
= &data
->mfb
[4];
523 if (hw
->desc
[2] != ad
->paddr
) { /* AOI0 closed */
524 if (cmfbi
->count
> 0) /* AOI1 open */
526 cpu_to_le32(cmfbi
->ad
->paddr
);
529 wr_reg_wa(&hw
->desc
[2], ad
->paddr
);
533 pmfbi
= &data
->mfb
[1];
535 if (hw
->desc
[1] == data
->dummy_ad
.paddr
)
536 wr_reg_wa(&hw
->desc
[1], ad
->paddr
);
538 pmfbi
->ad
->next_ad
= cpu_to_le32(ad
->paddr
);
541 pmfbi
= &data
->mfb
[3];
543 if (hw
->desc
[2] == data
->dummy_ad
.paddr
)
544 wr_reg_wa(&hw
->desc
[2], ad
->paddr
);
545 else /* AOI0 was open */
546 pmfbi
->ad
->next_ad
= cpu_to_le32(ad
->paddr
);
551 static void fsl_diu_disable_panel(struct fb_info
*info
)
553 struct mfb_info
*pmfbi
, *cmfbi
, *mfbi
= info
->par
;
554 struct diu_ad
*ad
= mfbi
->ad
;
555 struct fsl_diu_data
*data
= mfbi
->parent
;
556 struct diu __iomem
*hw
= data
->diu_reg
;
558 switch (mfbi
->index
) {
560 wr_reg_wa(&hw
->desc
[0], 0);
563 cmfbi
= &data
->mfb
[2];
564 if (cmfbi
->count
> 0) /* AOI1 is open */
565 wr_reg_wa(&hw
->desc
[1], cmfbi
->ad
->paddr
);
566 /* move AOI1 to the first */
567 else /* AOI1 was closed */
568 wr_reg_wa(&hw
->desc
[1], data
->dummy_ad
.paddr
);
572 cmfbi
= &data
->mfb
[4];
573 if (cmfbi
->count
> 0) /* AOI1 is open */
574 wr_reg_wa(&hw
->desc
[2], cmfbi
->ad
->paddr
);
575 /* move AOI1 to the first */
576 else /* AOI1 was closed */
577 wr_reg_wa(&hw
->desc
[2], data
->dummy_ad
.paddr
);
581 pmfbi
= &data
->mfb
[1];
582 if (hw
->desc
[1] != ad
->paddr
) {
583 /* AOI1 is not the first in the chain */
584 if (pmfbi
->count
> 0)
585 /* AOI0 is open, must be the first */
586 pmfbi
->ad
->next_ad
= 0;
587 } else /* AOI1 is the first in the chain */
588 wr_reg_wa(&hw
->desc
[1], data
->dummy_ad
.paddr
);
592 pmfbi
= &data
->mfb
[3];
593 if (hw
->desc
[2] != ad
->paddr
) {
594 /* AOI1 is not the first in the chain */
595 if (pmfbi
->count
> 0)
596 /* AOI0 is open, must be the first */
597 pmfbi
->ad
->next_ad
= 0;
598 } else /* AOI1 is the first in the chain */
599 wr_reg_wa(&hw
->desc
[2], data
->dummy_ad
.paddr
);
605 static void enable_lcdc(struct fb_info
*info
)
607 struct mfb_info
*mfbi
= info
->par
;
608 struct fsl_diu_data
*data
= mfbi
->parent
;
609 struct diu __iomem
*hw
= data
->diu_reg
;
611 out_be32(&hw
->diu_mode
, MFB_MODE1
);
614 static void disable_lcdc(struct fb_info
*info
)
616 struct mfb_info
*mfbi
= info
->par
;
617 struct fsl_diu_data
*data
= mfbi
->parent
;
618 struct diu __iomem
*hw
= data
->diu_reg
;
620 out_be32(&hw
->diu_mode
, 0);
623 static void adjust_aoi_size_position(struct fb_var_screeninfo
*var
,
624 struct fb_info
*info
)
626 struct mfb_info
*lower_aoi_mfbi
, *upper_aoi_mfbi
, *mfbi
= info
->par
;
627 struct fsl_diu_data
*data
= mfbi
->parent
;
628 int available_height
, upper_aoi_bottom
;
629 enum mfb_index index
= mfbi
->index
;
630 int lower_aoi_is_open
, upper_aoi_is_open
;
631 __u32 base_plane_width
, base_plane_height
, upper_aoi_height
;
633 base_plane_width
= data
->fsl_diu_info
[0].var
.xres
;
634 base_plane_height
= data
->fsl_diu_info
[0].var
.yres
;
636 if (mfbi
->x_aoi_d
< 0)
638 if (mfbi
->y_aoi_d
< 0)
642 if (mfbi
->x_aoi_d
!= 0)
644 if (mfbi
->y_aoi_d
!= 0)
649 lower_aoi_mfbi
= data
->fsl_diu_info
[index
+1].par
;
650 lower_aoi_is_open
= lower_aoi_mfbi
->count
> 0 ? 1 : 0;
651 if (var
->xres
> base_plane_width
)
652 var
->xres
= base_plane_width
;
653 if ((mfbi
->x_aoi_d
+ var
->xres
) > base_plane_width
)
654 mfbi
->x_aoi_d
= base_plane_width
- var
->xres
;
656 if (lower_aoi_is_open
)
657 available_height
= lower_aoi_mfbi
->y_aoi_d
;
659 available_height
= base_plane_height
;
660 if (var
->yres
> available_height
)
661 var
->yres
= available_height
;
662 if ((mfbi
->y_aoi_d
+ var
->yres
) > available_height
)
663 mfbi
->y_aoi_d
= available_height
- var
->yres
;
667 upper_aoi_mfbi
= data
->fsl_diu_info
[index
-1].par
;
668 upper_aoi_height
= data
->fsl_diu_info
[index
-1].var
.yres
;
669 upper_aoi_bottom
= upper_aoi_mfbi
->y_aoi_d
+ upper_aoi_height
;
670 upper_aoi_is_open
= upper_aoi_mfbi
->count
> 0 ? 1 : 0;
671 if (var
->xres
> base_plane_width
)
672 var
->xres
= base_plane_width
;
673 if ((mfbi
->x_aoi_d
+ var
->xres
) > base_plane_width
)
674 mfbi
->x_aoi_d
= base_plane_width
- var
->xres
;
675 if (mfbi
->y_aoi_d
< 0)
677 if (upper_aoi_is_open
) {
678 if (mfbi
->y_aoi_d
< upper_aoi_bottom
)
679 mfbi
->y_aoi_d
= upper_aoi_bottom
;
680 available_height
= base_plane_height
683 available_height
= base_plane_height
;
684 if (var
->yres
> available_height
)
685 var
->yres
= available_height
;
686 if ((mfbi
->y_aoi_d
+ var
->yres
) > base_plane_height
)
687 mfbi
->y_aoi_d
= base_plane_height
- var
->yres
;
692 * Checks to see if the hardware supports the state requested by var passed
693 * in. This function does not alter the hardware state! If the var passed in
694 * is slightly off by what the hardware can support then we alter the var
695 * PASSED in to what we can do. If the hardware doesn't support mode change
696 * a -EINVAL will be returned by the upper layers.
698 static int fsl_diu_check_var(struct fb_var_screeninfo
*var
,
699 struct fb_info
*info
)
701 if (var
->xres_virtual
< var
->xres
)
702 var
->xres_virtual
= var
->xres
;
703 if (var
->yres_virtual
< var
->yres
)
704 var
->yres_virtual
= var
->yres
;
706 if (var
->xoffset
+ info
->var
.xres
> info
->var
.xres_virtual
)
707 var
->xoffset
= info
->var
.xres_virtual
- info
->var
.xres
;
709 if (var
->yoffset
+ info
->var
.yres
> info
->var
.yres_virtual
)
710 var
->yoffset
= info
->var
.yres_virtual
- info
->var
.yres
;
712 if ((var
->bits_per_pixel
!= 32) && (var
->bits_per_pixel
!= 24) &&
713 (var
->bits_per_pixel
!= 16))
714 var
->bits_per_pixel
= default_bpp
;
716 switch (var
->bits_per_pixel
) {
719 var
->red
.offset
= 11;
720 var
->red
.msb_right
= 0;
722 var
->green
.length
= 6;
723 var
->green
.offset
= 5;
724 var
->green
.msb_right
= 0;
726 var
->blue
.length
= 5;
727 var
->blue
.offset
= 0;
728 var
->blue
.msb_right
= 0;
730 var
->transp
.length
= 0;
731 var
->transp
.offset
= 0;
732 var
->transp
.msb_right
= 0;
737 var
->red
.msb_right
= 0;
739 var
->green
.length
= 8;
740 var
->green
.offset
= 8;
741 var
->green
.msb_right
= 0;
743 var
->blue
.length
= 8;
744 var
->blue
.offset
= 16;
745 var
->blue
.msb_right
= 0;
747 var
->transp
.length
= 0;
748 var
->transp
.offset
= 0;
749 var
->transp
.msb_right
= 0;
753 var
->red
.offset
= 16;
754 var
->red
.msb_right
= 0;
756 var
->green
.length
= 8;
757 var
->green
.offset
= 8;
758 var
->green
.msb_right
= 0;
760 var
->blue
.length
= 8;
761 var
->blue
.offset
= 0;
762 var
->blue
.msb_right
= 0;
764 var
->transp
.length
= 8;
765 var
->transp
.offset
= 24;
766 var
->transp
.msb_right
= 0;
775 /* Copy nonstd field to/from sync for fbset usage */
776 var
->sync
|= var
->nonstd
;
777 var
->nonstd
|= var
->sync
;
779 adjust_aoi_size_position(var
, info
);
783 static void set_fix(struct fb_info
*info
)
785 struct fb_fix_screeninfo
*fix
= &info
->fix
;
786 struct fb_var_screeninfo
*var
= &info
->var
;
787 struct mfb_info
*mfbi
= info
->par
;
789 strncpy(fix
->id
, mfbi
->id
, sizeof(fix
->id
));
790 fix
->line_length
= var
->xres_virtual
* var
->bits_per_pixel
/ 8;
791 fix
->type
= FB_TYPE_PACKED_PIXELS
;
792 fix
->accel
= FB_ACCEL_NONE
;
793 fix
->visual
= FB_VISUAL_TRUECOLOR
;
798 static void update_lcdc(struct fb_info
*info
)
800 struct fb_var_screeninfo
*var
= &info
->var
;
801 struct mfb_info
*mfbi
= info
->par
;
802 struct fsl_diu_data
*data
= mfbi
->parent
;
803 struct diu __iomem
*hw
;
805 u8
*gamma_table_base
;
811 if (diu_ops
.set_monitor_port
)
812 diu_ops
.set_monitor_port(data
->monitor_port
);
813 gamma_table_base
= data
->gamma
;
815 /* Prep for DIU init - gamma table, cursor table */
817 for (i
= 0; i
<= 2; i
++)
818 for (j
= 0; j
<= 255; j
++)
819 *gamma_table_base
++ = j
;
821 if (diu_ops
.set_gamma_table
)
822 diu_ops
.set_gamma_table(data
->monitor_port
, data
->gamma
);
826 /* Program DIU registers */
828 out_be32(&hw
->gamma
, DMA_ADDR(data
, gamma
));
830 out_be32(&hw
->bgnd
, 0x007F7F7F); /* Set background to grey */
831 out_be32(&hw
->disp_size
, (var
->yres
<< 16) | var
->xres
);
833 /* Horizontal and vertical configuration register */
834 temp
= var
->left_margin
<< 22 | /* BP_H */
835 var
->hsync_len
<< 11 | /* PW_H */
836 var
->right_margin
; /* FP_H */
838 out_be32(&hw
->hsyn_para
, temp
);
840 temp
= var
->upper_margin
<< 22 | /* BP_V */
841 var
->vsync_len
<< 11 | /* PW_V */
842 var
->lower_margin
; /* FP_V */
844 out_be32(&hw
->vsyn_para
, temp
);
846 diu_ops
.set_pixel_clock(var
->pixclock
);
848 #ifndef CONFIG_PPC_MPC512x
850 * The PLUT register is defined differently on the MPC5121 than it
851 * is on other SOCs. Unfortunately, there's no documentation that
852 * explains how it's supposed to be programmed, so for now, we leave
853 * it at the default value on the MPC5121.
855 * For other SOCs, program it for the highest priority, which will
856 * reduce the chance of underrun. Technically, we should scale the
857 * priority to match the screen resolution, but doing that properly
858 * requires delicate fine-tuning for each use-case.
860 out_be32(&hw
->plut
, 0x01F5F666);
867 static int map_video_memory(struct fb_info
*info
)
869 u32 smem_len
= info
->fix
.line_length
* info
->var
.yres_virtual
;
872 p
= alloc_pages_exact(smem_len
, GFP_DMA
| __GFP_ZERO
);
874 dev_err(info
->dev
, "unable to allocate fb memory\n");
877 mutex_lock(&info
->mm_lock
);
878 info
->screen_base
= p
;
879 info
->fix
.smem_start
= virt_to_phys(info
->screen_base
);
880 info
->fix
.smem_len
= smem_len
;
881 mutex_unlock(&info
->mm_lock
);
882 info
->screen_size
= info
->fix
.smem_len
;
887 static void unmap_video_memory(struct fb_info
*info
)
889 void *p
= info
->screen_base
;
890 size_t l
= info
->fix
.smem_len
;
892 mutex_lock(&info
->mm_lock
);
893 info
->screen_base
= NULL
;
894 info
->fix
.smem_start
= 0;
895 info
->fix
.smem_len
= 0;
896 mutex_unlock(&info
->mm_lock
);
899 free_pages_exact(p
, l
);
903 * Using the fb_var_screeninfo in fb_info we set the aoi of this
904 * particular framebuffer. It is a light version of fsl_diu_set_par.
906 static int fsl_diu_set_aoi(struct fb_info
*info
)
908 struct fb_var_screeninfo
*var
= &info
->var
;
909 struct mfb_info
*mfbi
= info
->par
;
910 struct diu_ad
*ad
= mfbi
->ad
;
912 /* AOI should not be greater than display size */
913 ad
->offset_xyi
= cpu_to_le32((var
->yoffset
<< 16) | var
->xoffset
);
914 ad
->offset_xyd
= cpu_to_le32((mfbi
->y_aoi_d
<< 16) | mfbi
->x_aoi_d
);
919 * fsl_diu_get_pixel_format: return the pixel format for a given color depth
921 * The pixel format is a 32-bit value that determine which bits in each
922 * pixel are to be used for each color. This is the default function used
923 * if the platform does not define its own version.
925 static u32
fsl_diu_get_pixel_format(unsigned int bits_per_pixel
)
927 #define PF_BYTE_F 0x10000000
928 #define PF_ALPHA_C_MASK 0x0E000000
929 #define PF_ALPHA_C_SHIFT 25
930 #define PF_BLUE_C_MASK 0x01800000
931 #define PF_BLUE_C_SHIFT 23
932 #define PF_GREEN_C_MASK 0x00600000
933 #define PF_GREEN_C_SHIFT 21
934 #define PF_RED_C_MASK 0x00180000
935 #define PF_RED_C_SHIFT 19
936 #define PF_PALETTE 0x00040000
937 #define PF_PIXEL_S_MASK 0x00030000
938 #define PF_PIXEL_S_SHIFT 16
939 #define PF_COMP_3_MASK 0x0000F000
940 #define PF_COMP_3_SHIFT 12
941 #define PF_COMP_2_MASK 0x00000F00
942 #define PF_COMP_2_SHIFT 8
943 #define PF_COMP_1_MASK 0x000000F0
944 #define PF_COMP_1_SHIFT 4
945 #define PF_COMP_0_MASK 0x0000000F
946 #define PF_COMP_0_SHIFT 0
948 #define MAKE_PF(alpha, red, green, blue, size, c0, c1, c2, c3) \
949 cpu_to_le32(PF_BYTE_F | (alpha << PF_ALPHA_C_SHIFT) | \
950 (blue << PF_BLUE_C_SHIFT) | (green << PF_GREEN_C_SHIFT) | \
951 (red << PF_RED_C_SHIFT) | (c3 << PF_COMP_3_SHIFT) | \
952 (c2 << PF_COMP_2_SHIFT) | (c1 << PF_COMP_1_SHIFT) | \
953 (c0 << PF_COMP_0_SHIFT) | (size << PF_PIXEL_S_SHIFT))
955 switch (bits_per_pixel
) {
958 return MAKE_PF(3, 2, 1, 0, 3, 8, 8, 8, 8);
961 return MAKE_PF(4, 0, 1, 2, 2, 8, 8, 8, 0);
964 return MAKE_PF(4, 2, 1, 0, 1, 5, 6, 5, 0);
966 pr_err("fsl-diu: unsupported color depth %u\n", bits_per_pixel
);
972 * Copies a cursor image from user space to the proper place in driver
973 * memory so that the hardware can display the cursor image.
975 * Cursor data is represented as a sequence of 'width' bits packed into bytes.
976 * That is, the first 8 bits are in the first byte, the second 8 bits in the
977 * second byte, and so on. Therefore, the each row of the cursor is (width +
978 * 7) / 8 bytes of 'data'
980 * The DIU only supports cursors up to 32x32 (MAX_CURS). We reject cursors
981 * larger than this, so we already know that 'width' <= 32. Therefore, we can
982 * simplify our code by using a 32-bit big-endian integer ("line") to read in
983 * a single line of pixels, and only look at the top 'width' bits of that
986 * This could result in an unaligned 32-bit read. For example, if the cursor
987 * is 24x24, then the first three bytes of 'image' contain the pixel data for
988 * the top line of the cursor. We do a 32-bit read of 'image', but we look
989 * only at the top 24 bits. Then we increment 'image' by 3 bytes. The next
990 * read is unaligned. The only problem is that we might read past the end of
991 * 'image' by 1-3 bytes, but that should not cause any problems.
993 static void fsl_diu_load_cursor_image(struct fb_info
*info
,
994 const void *image
, uint16_t bg
, uint16_t fg
,
995 unsigned int width
, unsigned int height
)
997 struct mfb_info
*mfbi
= info
->par
;
998 struct fsl_diu_data
*data
= mfbi
->parent
;
999 __le16
*cursor
= data
->cursor
;
1000 __le16 _fg
= cpu_to_le16(fg
);
1001 __le16 _bg
= cpu_to_le16(bg
);
1004 for (h
= 0; h
< height
; h
++) {
1005 uint32_t mask
= 1 << 31;
1006 uint32_t line
= be32_to_cpup(image
);
1008 for (w
= 0; w
< width
; w
++) {
1009 cursor
[w
] = (line
& mask
) ? _fg
: _bg
;
1014 image
+= DIV_ROUND_UP(width
, 8);
1019 * Set a hardware cursor. The image data for the cursor is passed via the
1022 static int fsl_diu_cursor(struct fb_info
*info
, struct fb_cursor
*cursor
)
1024 struct mfb_info
*mfbi
= info
->par
;
1025 struct fsl_diu_data
*data
= mfbi
->parent
;
1026 struct diu __iomem
*hw
= data
->diu_reg
;
1028 if (cursor
->image
.width
> MAX_CURS
|| cursor
->image
.height
> MAX_CURS
)
1031 /* The cursor size has changed */
1032 if (cursor
->set
& FB_CUR_SETSIZE
) {
1034 * The DIU cursor is a fixed size, so when we get this
1035 * message, instead of resizing the cursor, we just clear
1036 * all the image data, in expectation of new data. However,
1037 * in tests this control does not appear to be normally
1040 memset(data
->cursor
, 0, sizeof(data
->cursor
));
1043 /* The cursor position has changed (cursor->image.dx|dy) */
1044 if (cursor
->set
& FB_CUR_SETPOS
) {
1047 yy
= (cursor
->image
.dy
- info
->var
.yoffset
) & 0x7ff;
1048 xx
= (cursor
->image
.dx
- info
->var
.xoffset
) & 0x7ff;
1050 out_be32(&hw
->curs_pos
, yy
<< 16 | xx
);
1054 * FB_CUR_SETIMAGE - the cursor image has changed
1055 * FB_CUR_SETCMAP - the cursor colors has changed
1056 * FB_CUR_SETSHAPE - the cursor bitmask has changed
1058 if (cursor
->set
& (FB_CUR_SETSHAPE
| FB_CUR_SETCMAP
| FB_CUR_SETIMAGE
)) {
1059 unsigned int image_size
=
1060 DIV_ROUND_UP(cursor
->image
.width
, 8) * cursor
->image
.height
;
1061 unsigned int image_words
=
1062 DIV_ROUND_UP(image_size
, sizeof(uint32_t));
1063 unsigned int bg_idx
= cursor
->image
.bg_color
;
1064 unsigned int fg_idx
= cursor
->image
.fg_color
;
1065 uint8_t buffer
[image_size
];
1066 uint32_t *image
, *source
, *mask
;
1070 if (info
->state
!= FBINFO_STATE_RUNNING
)
1074 * Determine the size of the cursor image data. Normally,
1077 image_size
= DIV_ROUND_UP(cursor
->image
.width
, 8) *
1078 cursor
->image
.height
;
1080 bg
= ((info
->cmap
.red
[bg_idx
] & 0xf8) << 7) |
1081 ((info
->cmap
.green
[bg_idx
] & 0xf8) << 2) |
1082 ((info
->cmap
.blue
[bg_idx
] & 0xf8) >> 3) |
1085 fg
= ((info
->cmap
.red
[fg_idx
] & 0xf8) << 7) |
1086 ((info
->cmap
.green
[fg_idx
] & 0xf8) << 2) |
1087 ((info
->cmap
.blue
[fg_idx
] & 0xf8) >> 3) |
1090 /* Use 32-bit operations on the data to improve performance */
1091 image
= (uint32_t *)buffer
;
1092 source
= (uint32_t *)cursor
->image
.data
;
1093 mask
= (uint32_t *)cursor
->mask
;
1095 if (cursor
->rop
== ROP_XOR
)
1096 for (i
= 0; i
< image_words
; i
++)
1097 image
[i
] = source
[i
] ^ mask
[i
];
1099 for (i
= 0; i
< image_words
; i
++)
1100 image
[i
] = source
[i
] & mask
[i
];
1102 fsl_diu_load_cursor_image(info
, image
, bg
, fg
,
1103 cursor
->image
.width
, cursor
->image
.height
);
1107 * Show or hide the cursor. The cursor data is always stored in the
1108 * 'cursor' memory block, and the actual cursor position is always in
1109 * the DIU's CURS_POS register. To hide the cursor, we redirect the
1110 * CURSOR register to a blank cursor. The show the cursor, we
1111 * redirect the CURSOR register to the real cursor data.
1114 out_be32(&hw
->cursor
, DMA_ADDR(data
, cursor
));
1116 out_be32(&hw
->cursor
, DMA_ADDR(data
, blank_cursor
));
1122 * Using the fb_var_screeninfo in fb_info we set the resolution of this
1123 * particular framebuffer. This function alters the fb_fix_screeninfo stored
1124 * in fb_info. It does not alter var in fb_info since we are using that
1125 * data. This means we depend on the data in var inside fb_info to be
1126 * supported by the hardware. fsl_diu_check_var is always called before
1127 * fsl_diu_set_par to ensure this.
1129 static int fsl_diu_set_par(struct fb_info
*info
)
1132 struct fb_var_screeninfo
*var
= &info
->var
;
1133 struct mfb_info
*mfbi
= info
->par
;
1134 struct fsl_diu_data
*data
= mfbi
->parent
;
1135 struct diu_ad
*ad
= mfbi
->ad
;
1136 struct diu __iomem
*hw
;
1142 len
= info
->var
.yres_virtual
* info
->fix
.line_length
;
1143 /* Alloc & dealloc each time resolution/bpp change */
1144 if (len
!= info
->fix
.smem_len
) {
1145 if (info
->fix
.smem_start
)
1146 unmap_video_memory(info
);
1148 /* Memory allocation for framebuffer */
1149 if (map_video_memory(info
)) {
1150 dev_err(info
->dev
, "unable to allocate fb memory 1\n");
1155 if (diu_ops
.get_pixel_format
)
1156 ad
->pix_fmt
= diu_ops
.get_pixel_format(data
->monitor_port
,
1157 var
->bits_per_pixel
);
1159 ad
->pix_fmt
= fsl_diu_get_pixel_format(var
->bits_per_pixel
);
1161 ad
->addr
= cpu_to_le32(info
->fix
.smem_start
);
1162 ad
->src_size_g_alpha
= cpu_to_le32((var
->yres_virtual
<< 12) |
1163 var
->xres_virtual
) | mfbi
->g_alpha
;
1164 /* AOI should not be greater than display size */
1165 ad
->aoi_size
= cpu_to_le32((var
->yres
<< 16) | var
->xres
);
1166 ad
->offset_xyi
= cpu_to_le32((var
->yoffset
<< 16) | var
->xoffset
);
1167 ad
->offset_xyd
= cpu_to_le32((mfbi
->y_aoi_d
<< 16) | mfbi
->x_aoi_d
);
1169 /* Disable chroma keying function */
1178 if (mfbi
->index
== PLANE0
)
1183 static inline __u32
CNVT_TOHW(__u32 val
, __u32 width
)
1185 return ((val
<< width
) + 0x7FFF - val
) >> 16;
1189 * Set a single color register. The values supplied have a 16 bit magnitude
1190 * which needs to be scaled in this function for the hardware. Things to take
1191 * into consideration are how many color registers, if any, are supported with
1192 * the current color visual. With truecolor mode no color palettes are
1193 * supported. Here a pseudo palette is created which we store the value in
1194 * pseudo_palette in struct fb_info. For pseudocolor mode we have a limited
1197 static int fsl_diu_setcolreg(unsigned int regno
, unsigned int red
,
1198 unsigned int green
, unsigned int blue
,
1199 unsigned int transp
, struct fb_info
*info
)
1204 * If greyscale is true, then we convert the RGB value
1205 * to greyscale no matter what visual we are using.
1207 if (info
->var
.grayscale
)
1208 red
= green
= blue
= (19595 * red
+ 38470 * green
+
1210 switch (info
->fix
.visual
) {
1211 case FB_VISUAL_TRUECOLOR
:
1213 * 16-bit True Colour. We encode the RGB value
1214 * according to the RGB bitfield information.
1217 u32
*pal
= info
->pseudo_palette
;
1220 red
= CNVT_TOHW(red
, info
->var
.red
.length
);
1221 green
= CNVT_TOHW(green
, info
->var
.green
.length
);
1222 blue
= CNVT_TOHW(blue
, info
->var
.blue
.length
);
1223 transp
= CNVT_TOHW(transp
, info
->var
.transp
.length
);
1225 v
= (red
<< info
->var
.red
.offset
) |
1226 (green
<< info
->var
.green
.offset
) |
1227 (blue
<< info
->var
.blue
.offset
) |
1228 (transp
<< info
->var
.transp
.offset
);
1240 * Pan (or wrap, depending on the `vmode' field) the display using the
1241 * 'xoffset' and 'yoffset' fields of the 'var' structure. If the values
1242 * don't fit, return -EINVAL.
1244 static int fsl_diu_pan_display(struct fb_var_screeninfo
*var
,
1245 struct fb_info
*info
)
1247 if ((info
->var
.xoffset
== var
->xoffset
) &&
1248 (info
->var
.yoffset
== var
->yoffset
))
1249 return 0; /* No change, do nothing */
1251 if (var
->xoffset
+ info
->var
.xres
> info
->var
.xres_virtual
1252 || var
->yoffset
+ info
->var
.yres
> info
->var
.yres_virtual
)
1255 info
->var
.xoffset
= var
->xoffset
;
1256 info
->var
.yoffset
= var
->yoffset
;
1258 if (var
->vmode
& FB_VMODE_YWRAP
)
1259 info
->var
.vmode
|= FB_VMODE_YWRAP
;
1261 info
->var
.vmode
&= ~FB_VMODE_YWRAP
;
1263 fsl_diu_set_aoi(info
);
1268 static int fsl_diu_ioctl(struct fb_info
*info
, unsigned int cmd
,
1271 struct mfb_info
*mfbi
= info
->par
;
1272 struct diu_ad
*ad
= mfbi
->ad
;
1273 struct mfb_chroma_key ck
;
1274 unsigned char global_alpha
;
1275 struct aoi_display_offset aoi_d
;
1277 void __user
*buf
= (void __user
*)arg
;
1282 dev_dbg(info
->dev
, "ioctl %08x (dir=%s%s type=%u nr=%u size=%u)\n", cmd
,
1283 _IOC_DIR(cmd
) & _IOC_READ
? "R" : "",
1284 _IOC_DIR(cmd
) & _IOC_WRITE
? "W" : "",
1285 _IOC_TYPE(cmd
), _IOC_NR(cmd
), _IOC_SIZE(cmd
));
1288 case MFB_SET_PIXFMT_OLD
:
1290 "MFB_SET_PIXFMT value of 0x%08x is deprecated.\n",
1291 MFB_SET_PIXFMT_OLD
);
1292 case MFB_SET_PIXFMT
:
1293 if (copy_from_user(&pix_fmt
, buf
, sizeof(pix_fmt
)))
1295 ad
->pix_fmt
= pix_fmt
;
1297 case MFB_GET_PIXFMT_OLD
:
1299 "MFB_GET_PIXFMT value of 0x%08x is deprecated.\n",
1300 MFB_GET_PIXFMT_OLD
);
1301 case MFB_GET_PIXFMT
:
1302 pix_fmt
= ad
->pix_fmt
;
1303 if (copy_to_user(buf
, &pix_fmt
, sizeof(pix_fmt
)))
1307 if (copy_from_user(&aoi_d
, buf
, sizeof(aoi_d
)))
1309 mfbi
->x_aoi_d
= aoi_d
.x_aoi_d
;
1310 mfbi
->y_aoi_d
= aoi_d
.y_aoi_d
;
1311 fsl_diu_check_var(&info
->var
, info
);
1312 fsl_diu_set_aoi(info
);
1315 aoi_d
.x_aoi_d
= mfbi
->x_aoi_d
;
1316 aoi_d
.y_aoi_d
= mfbi
->y_aoi_d
;
1317 if (copy_to_user(buf
, &aoi_d
, sizeof(aoi_d
)))
1321 global_alpha
= mfbi
->g_alpha
;
1322 if (copy_to_user(buf
, &global_alpha
, sizeof(global_alpha
)))
1326 /* set panel information */
1327 if (copy_from_user(&global_alpha
, buf
, sizeof(global_alpha
)))
1329 ad
->src_size_g_alpha
= (ad
->src_size_g_alpha
& (~0xff)) |
1330 (global_alpha
& 0xff);
1331 mfbi
->g_alpha
= global_alpha
;
1333 case MFB_SET_CHROMA_KEY
:
1334 /* set panel winformation */
1335 if (copy_from_user(&ck
, buf
, sizeof(ck
)))
1339 (ck
.red_max
< ck
.red_min
||
1340 ck
.green_max
< ck
.green_min
||
1341 ck
.blue_max
< ck
.blue_min
))
1352 ad
->ckmax_r
= ck
.red_max
;
1353 ad
->ckmax_g
= ck
.green_max
;
1354 ad
->ckmax_b
= ck
.blue_max
;
1355 ad
->ckmin_r
= ck
.red_min
;
1356 ad
->ckmin_g
= ck
.green_min
;
1357 ad
->ckmin_b
= ck
.blue_min
;
1360 #ifdef CONFIG_PPC_MPC512x
1361 case MFB_SET_GAMMA
: {
1362 struct fsl_diu_data
*data
= mfbi
->parent
;
1364 if (copy_from_user(data
->gamma
, buf
, sizeof(data
->gamma
)))
1366 setbits32(&data
->diu_reg
->gamma
, 0); /* Force table reload */
1369 case MFB_GET_GAMMA
: {
1370 struct fsl_diu_data
*data
= mfbi
->parent
;
1372 if (copy_to_user(buf
, data
->gamma
, sizeof(data
->gamma
)))
1378 dev_err(info
->dev
, "unknown ioctl command (0x%08X)\n", cmd
);
1379 return -ENOIOCTLCMD
;
1385 static inline void fsl_diu_enable_interrupts(struct fsl_diu_data
*data
)
1387 u32 int_mask
= INT_UNDRUN
; /* enable underrun detection */
1389 if (IS_ENABLED(CONFIG_NOT_COHERENT_CACHE
))
1390 int_mask
|= INT_VSYNC
; /* enable vertical sync */
1392 clrbits32(&data
->diu_reg
->int_mask
, int_mask
);
1395 /* turn on fb if count == 1
1397 static int fsl_diu_open(struct fb_info
*info
, int user
)
1399 struct mfb_info
*mfbi
= info
->par
;
1402 /* free boot splash memory on first /dev/fb0 open */
1403 if ((mfbi
->index
== PLANE0
) && diu_ops
.release_bootmem
)
1404 diu_ops
.release_bootmem();
1406 spin_lock(&diu_lock
);
1408 if (mfbi
->count
== 1) {
1409 fsl_diu_check_var(&info
->var
, info
);
1410 res
= fsl_diu_set_par(info
);
1414 fsl_diu_enable_interrupts(mfbi
->parent
);
1415 fsl_diu_enable_panel(info
);
1419 spin_unlock(&diu_lock
);
1423 /* turn off fb if count == 0
1425 static int fsl_diu_release(struct fb_info
*info
, int user
)
1427 struct mfb_info
*mfbi
= info
->par
;
1430 spin_lock(&diu_lock
);
1432 if (mfbi
->count
== 0) {
1433 struct fsl_diu_data
*data
= mfbi
->parent
;
1434 bool disable
= true;
1437 /* Disable interrupts only if all AOIs are closed */
1438 for (i
= 0; i
< NUM_AOIS
; i
++) {
1439 struct mfb_info
*mi
= data
->fsl_diu_info
[i
].par
;
1445 out_be32(&data
->diu_reg
->int_mask
, 0xffffffff);
1446 fsl_diu_disable_panel(info
);
1449 spin_unlock(&diu_lock
);
1453 static struct fb_ops fsl_diu_ops
= {
1454 .owner
= THIS_MODULE
,
1455 .fb_check_var
= fsl_diu_check_var
,
1456 .fb_set_par
= fsl_diu_set_par
,
1457 .fb_setcolreg
= fsl_diu_setcolreg
,
1458 .fb_pan_display
= fsl_diu_pan_display
,
1459 .fb_fillrect
= cfb_fillrect
,
1460 .fb_copyarea
= cfb_copyarea
,
1461 .fb_imageblit
= cfb_imageblit
,
1462 .fb_ioctl
= fsl_diu_ioctl
,
1463 .fb_open
= fsl_diu_open
,
1464 .fb_release
= fsl_diu_release
,
1465 .fb_cursor
= fsl_diu_cursor
,
1468 static int install_fb(struct fb_info
*info
)
1471 struct mfb_info
*mfbi
= info
->par
;
1472 struct fsl_diu_data
*data
= mfbi
->parent
;
1473 const char *aoi_mode
, *init_aoi_mode
= "320x240";
1474 struct fb_videomode
*db
= fsl_diu_mode_db
;
1475 unsigned int dbsize
= ARRAY_SIZE(fsl_diu_mode_db
);
1476 int has_default_mode
= 1;
1478 info
->var
.activate
= FB_ACTIVATE_NOW
;
1479 info
->fbops
= &fsl_diu_ops
;
1480 info
->flags
= FBINFO_DEFAULT
| FBINFO_VIRTFB
| FBINFO_PARTIAL_PAN_OK
|
1482 info
->pseudo_palette
= mfbi
->pseudo_palette
;
1484 rc
= fb_alloc_cmap(&info
->cmap
, 16, 0);
1488 if (mfbi
->index
== PLANE0
) {
1489 if (data
->has_edid
) {
1490 /* Now build modedb from EDID */
1491 fb_edid_to_monspecs(data
->edid_data
, &info
->monspecs
);
1492 fb_videomode_to_modelist(info
->monspecs
.modedb
,
1493 info
->monspecs
.modedb_len
,
1495 db
= info
->monspecs
.modedb
;
1496 dbsize
= info
->monspecs
.modedb_len
;
1500 aoi_mode
= init_aoi_mode
;
1502 rc
= fb_find_mode(&info
->var
, info
, aoi_mode
, db
, dbsize
, NULL
,
1506 * For plane 0 we continue and look into
1507 * driver's internal modedb.
1509 if ((mfbi
->index
== PLANE0
) && data
->has_edid
)
1510 has_default_mode
= 0;
1515 if (!has_default_mode
) {
1516 rc
= fb_find_mode(&info
->var
, info
, aoi_mode
, fsl_diu_mode_db
,
1517 ARRAY_SIZE(fsl_diu_mode_db
), NULL
, default_bpp
);
1519 has_default_mode
= 1;
1522 /* Still not found, use preferred mode from database if any */
1523 if (!has_default_mode
&& info
->monspecs
.modedb
) {
1524 struct fb_monspecs
*specs
= &info
->monspecs
;
1525 struct fb_videomode
*modedb
= &specs
->modedb
[0];
1528 * Get preferred timing. If not found,
1529 * first mode in database will be used.
1531 if (specs
->misc
& FB_MISC_1ST_DETAIL
) {
1534 for (i
= 0; i
< specs
->modedb_len
; i
++) {
1535 if (specs
->modedb
[i
].flag
& FB_MODE_IS_FIRST
) {
1536 modedb
= &specs
->modedb
[i
];
1542 info
->var
.bits_per_pixel
= default_bpp
;
1543 fb_videomode_to_var(&info
->var
, modedb
);
1546 if (fsl_diu_check_var(&info
->var
, info
)) {
1547 dev_err(info
->dev
, "fsl_diu_check_var failed\n");
1548 unmap_video_memory(info
);
1549 fb_dealloc_cmap(&info
->cmap
);
1553 if (register_framebuffer(info
) < 0) {
1554 dev_err(info
->dev
, "register_framebuffer failed\n");
1555 unmap_video_memory(info
);
1556 fb_dealloc_cmap(&info
->cmap
);
1560 mfbi
->registered
= 1;
1561 dev_info(info
->dev
, "%s registered successfully\n", mfbi
->id
);
1566 static void uninstall_fb(struct fb_info
*info
)
1568 struct mfb_info
*mfbi
= info
->par
;
1570 if (!mfbi
->registered
)
1573 unregister_framebuffer(info
);
1574 unmap_video_memory(info
);
1576 fb_dealloc_cmap(&info
->cmap
);
1578 mfbi
->registered
= 0;
1581 static irqreturn_t
fsl_diu_isr(int irq
, void *dev_id
)
1583 struct diu __iomem
*hw
= dev_id
;
1584 uint32_t status
= in_be32(&hw
->int_status
);
1587 /* This is the workaround for underrun */
1588 if (status
& INT_UNDRUN
) {
1589 out_be32(&hw
->diu_mode
, 0);
1591 out_be32(&hw
->diu_mode
, 1);
1593 #if defined(CONFIG_NOT_COHERENT_CACHE)
1594 else if (status
& INT_VSYNC
) {
1597 for (i
= 0; i
< coherence_data_size
;
1598 i
+= d_cache_line_size
)
1599 __asm__
__volatile__ (
1601 ::[input
]"r"(&coherence_data
[i
]));
1611 * Power management hooks. Note that we won't be called from IRQ context,
1612 * unlike the blank functions above, so we may sleep.
1614 static int fsl_diu_suspend(struct platform_device
*ofdev
, pm_message_t state
)
1616 struct fsl_diu_data
*data
;
1618 data
= dev_get_drvdata(&ofdev
->dev
);
1619 disable_lcdc(data
->fsl_diu_info
);
1624 static int fsl_diu_resume(struct platform_device
*ofdev
)
1626 struct fsl_diu_data
*data
;
1629 data
= dev_get_drvdata(&ofdev
->dev
);
1631 fsl_diu_enable_interrupts(data
);
1632 update_lcdc(data
->fsl_diu_info
);
1633 for (i
= 0; i
< NUM_AOIS
; i
++) {
1634 if (data
->mfb
[i
].count
)
1635 fsl_diu_enable_panel(&data
->fsl_diu_info
[i
]);
1642 #define fsl_diu_suspend NULL
1643 #define fsl_diu_resume NULL
1644 #endif /* CONFIG_PM */
1646 static ssize_t
store_monitor(struct device
*device
,
1647 struct device_attribute
*attr
, const char *buf
, size_t count
)
1649 enum fsl_diu_monitor_port old_monitor_port
;
1650 struct fsl_diu_data
*data
=
1651 container_of(attr
, struct fsl_diu_data
, dev_attr
);
1653 old_monitor_port
= data
->monitor_port
;
1654 data
->monitor_port
= fsl_diu_name_to_port(buf
);
1656 if (old_monitor_port
!= data
->monitor_port
) {
1657 /* All AOIs need adjust pixel format
1658 * fsl_diu_set_par only change the pixsel format here
1659 * unlikely to fail. */
1662 for (i
=0; i
< NUM_AOIS
; i
++)
1663 fsl_diu_set_par(&data
->fsl_diu_info
[i
]);
1668 static ssize_t
show_monitor(struct device
*device
,
1669 struct device_attribute
*attr
, char *buf
)
1671 struct fsl_diu_data
*data
=
1672 container_of(attr
, struct fsl_diu_data
, dev_attr
);
1674 switch (data
->monitor_port
) {
1675 case FSL_DIU_PORT_DVI
:
1676 return sprintf(buf
, "DVI\n");
1677 case FSL_DIU_PORT_LVDS
:
1678 return sprintf(buf
, "Single-link LVDS\n");
1679 case FSL_DIU_PORT_DLVDS
:
1680 return sprintf(buf
, "Dual-link LVDS\n");
1686 static int fsl_diu_probe(struct platform_device
*pdev
)
1688 struct device_node
*np
= pdev
->dev
.of_node
;
1689 struct mfb_info
*mfbi
;
1690 struct fsl_diu_data
*data
;
1691 dma_addr_t dma_addr
; /* DMA addr of fsl_diu_data struct */
1696 data
= dmam_alloc_coherent(&pdev
->dev
, sizeof(struct fsl_diu_data
),
1697 &dma_addr
, GFP_DMA
| __GFP_ZERO
);
1700 data
->dma_addr
= dma_addr
;
1703 * dma_alloc_coherent() uses a page allocator, so the address is
1704 * always page-aligned. We need the memory to be 32-byte aligned,
1705 * so that's good. However, if one day the allocator changes, we
1706 * need to catch that. It's not worth the effort to handle unaligned
1707 * alloctions now because it's highly unlikely to ever be a problem.
1709 if ((unsigned long)data
& 31) {
1710 dev_err(&pdev
->dev
, "misaligned allocation");
1715 spin_lock_init(&data
->reg_lock
);
1717 for (i
= 0; i
< NUM_AOIS
; i
++) {
1718 struct fb_info
*info
= &data
->fsl_diu_info
[i
];
1720 info
->device
= &pdev
->dev
;
1721 info
->par
= &data
->mfb
[i
];
1724 * We store the physical address of the AD in the reserved
1725 * 'paddr' field of the AD itself.
1727 data
->ad
[i
].paddr
= DMA_ADDR(data
, ad
[i
]);
1729 info
->fix
.smem_start
= 0;
1731 /* Initialize the AOI data structure */
1733 memcpy(mfbi
, &mfb_template
[i
], sizeof(struct mfb_info
));
1734 mfbi
->parent
= data
;
1735 mfbi
->ad
= &data
->ad
[i
];
1738 /* Get the EDID data from the device tree, if present */
1739 prop
= of_get_property(np
, "edid", &ret
);
1740 if (prop
&& ret
== EDID_LENGTH
) {
1741 memcpy(data
->edid_data
, prop
, EDID_LENGTH
);
1742 data
->has_edid
= true;
1745 data
->diu_reg
= of_iomap(np
, 0);
1746 if (!data
->diu_reg
) {
1747 dev_err(&pdev
->dev
, "cannot map DIU registers\n");
1752 /* Get the IRQ of the DIU */
1753 data
->irq
= irq_of_parse_and_map(np
, 0);
1756 dev_err(&pdev
->dev
, "could not get DIU IRQ\n");
1760 data
->monitor_port
= monitor_port
;
1762 /* Initialize the dummy Area Descriptor */
1763 data
->dummy_ad
.addr
= cpu_to_le32(DMA_ADDR(data
, dummy_aoi
));
1764 data
->dummy_ad
.pix_fmt
= 0x88882317;
1765 data
->dummy_ad
.src_size_g_alpha
= cpu_to_le32((4 << 12) | 4);
1766 data
->dummy_ad
.aoi_size
= cpu_to_le32((4 << 16) | 2);
1767 data
->dummy_ad
.offset_xyi
= 0;
1768 data
->dummy_ad
.offset_xyd
= 0;
1769 data
->dummy_ad
.next_ad
= 0;
1770 data
->dummy_ad
.paddr
= DMA_ADDR(data
, dummy_ad
);
1773 * Let DIU continue to display splash screen if it was pre-initialized
1774 * by the bootloader; otherwise, clear the display.
1776 if (in_be32(&data
->diu_reg
->diu_mode
) == MFB_MODE0
)
1777 out_be32(&data
->diu_reg
->desc
[0], 0);
1779 out_be32(&data
->diu_reg
->desc
[1], data
->dummy_ad
.paddr
);
1780 out_be32(&data
->diu_reg
->desc
[2], data
->dummy_ad
.paddr
);
1783 * Older versions of U-Boot leave interrupts enabled, so disable
1784 * all of them and clear the status register.
1786 out_be32(&data
->diu_reg
->int_mask
, 0xffffffff);
1787 in_be32(&data
->diu_reg
->int_status
);
1789 ret
= request_irq(data
->irq
, fsl_diu_isr
, 0, "fsl-diu-fb",
1792 dev_err(&pdev
->dev
, "could not claim irq\n");
1796 for (i
= 0; i
< NUM_AOIS
; i
++) {
1797 ret
= install_fb(&data
->fsl_diu_info
[i
]);
1799 dev_err(&pdev
->dev
, "could not register fb %d\n", i
);
1800 free_irq(data
->irq
, data
->diu_reg
);
1805 sysfs_attr_init(&data
->dev_attr
.attr
);
1806 data
->dev_attr
.attr
.name
= "monitor";
1807 data
->dev_attr
.attr
.mode
= S_IRUGO
|S_IWUSR
;
1808 data
->dev_attr
.show
= show_monitor
;
1809 data
->dev_attr
.store
= store_monitor
;
1810 ret
= device_create_file(&pdev
->dev
, &data
->dev_attr
);
1812 dev_err(&pdev
->dev
, "could not create sysfs file %s\n",
1813 data
->dev_attr
.attr
.name
);
1816 dev_set_drvdata(&pdev
->dev
, data
);
1820 for (i
= 0; i
< NUM_AOIS
; i
++)
1821 uninstall_fb(&data
->fsl_diu_info
[i
]);
1823 iounmap(data
->diu_reg
);
1828 static int fsl_diu_remove(struct platform_device
*pdev
)
1830 struct fsl_diu_data
*data
;
1833 data
= dev_get_drvdata(&pdev
->dev
);
1834 disable_lcdc(&data
->fsl_diu_info
[0]);
1836 free_irq(data
->irq
, data
->diu_reg
);
1838 for (i
= 0; i
< NUM_AOIS
; i
++)
1839 uninstall_fb(&data
->fsl_diu_info
[i
]);
1841 iounmap(data
->diu_reg
);
1847 static int __init
fsl_diu_setup(char *options
)
1852 if (!options
|| !*options
)
1855 while ((opt
= strsep(&options
, ",")) != NULL
) {
1858 if (!strncmp(opt
, "monitor=", 8)) {
1859 monitor_port
= fsl_diu_name_to_port(opt
+ 8);
1860 } else if (!strncmp(opt
, "bpp=", 4)) {
1861 if (!kstrtoul(opt
+ 4, 10, &val
))
1871 static const struct of_device_id fsl_diu_match
[] = {
1872 #ifdef CONFIG_PPC_MPC512x
1874 .compatible
= "fsl,mpc5121-diu",
1878 .compatible
= "fsl,diu",
1882 MODULE_DEVICE_TABLE(of
, fsl_diu_match
);
1884 static struct platform_driver fsl_diu_driver
= {
1886 .name
= "fsl-diu-fb",
1887 .of_match_table
= fsl_diu_match
,
1889 .probe
= fsl_diu_probe
,
1890 .remove
= fsl_diu_remove
,
1891 .suspend
= fsl_diu_suspend
,
1892 .resume
= fsl_diu_resume
,
1895 static int __init
fsl_diu_init(void)
1897 #ifdef CONFIG_NOT_COHERENT_CACHE
1898 struct device_node
*np
;
1906 * For kernel boot options (in 'video=xxxfb:<options>' format)
1908 if (fb_get_options("fslfb", &option
))
1910 fsl_diu_setup(option
);
1912 monitor_port
= fsl_diu_name_to_port(monitor_string
);
1916 * Must to verify set_pixel_clock. If not implement on platform,
1917 * then that means that there is no platform support for the DIU.
1919 if (!diu_ops
.set_pixel_clock
)
1922 pr_info("Freescale Display Interface Unit (DIU) framebuffer driver\n");
1924 #ifdef CONFIG_NOT_COHERENT_CACHE
1925 np
= of_find_node_by_type(NULL
, "cpu");
1927 pr_err("fsl-diu-fb: can't find 'cpu' device node\n");
1931 prop
= of_get_property(np
, "d-cache-size", NULL
);
1933 pr_err("fsl-diu-fb: missing 'd-cache-size' property' "
1940 * Freescale PLRU requires 13/8 times the cache size to do a proper
1941 * displacement flush
1943 coherence_data_size
= be32_to_cpup(prop
) * 13;
1944 coherence_data_size
/= 8;
1946 pr_debug("fsl-diu-fb: coherence data size is %zu bytes\n",
1947 coherence_data_size
);
1949 prop
= of_get_property(np
, "d-cache-line-size", NULL
);
1951 pr_err("fsl-diu-fb: missing 'd-cache-line-size' property' "
1956 d_cache_line_size
= be32_to_cpup(prop
);
1958 pr_debug("fsl-diu-fb: cache lines size is %u bytes\n",
1962 coherence_data
= vmalloc(coherence_data_size
);
1963 if (!coherence_data
) {
1964 pr_err("fsl-diu-fb: could not allocate coherence data "
1965 "(size=%zu)\n", coherence_data_size
);
1971 ret
= platform_driver_register(&fsl_diu_driver
);
1973 pr_err("fsl-diu-fb: failed to register platform driver\n");
1974 #if defined(CONFIG_NOT_COHERENT_CACHE)
1975 vfree(coherence_data
);
1981 static void __exit
fsl_diu_exit(void)
1983 platform_driver_unregister(&fsl_diu_driver
);
1984 #if defined(CONFIG_NOT_COHERENT_CACHE)
1985 vfree(coherence_data
);
1989 module_init(fsl_diu_init
);
1990 module_exit(fsl_diu_exit
);
1992 MODULE_AUTHOR("York Sun <yorksun@freescale.com>");
1993 MODULE_DESCRIPTION("Freescale DIU framebuffer driver");
1994 MODULE_LICENSE("GPL");
1996 module_param_named(mode
, fb_mode
, charp
, 0);
1997 MODULE_PARM_DESC(mode
,
1998 "Specify resolution as \"<xres>x<yres>[-<bpp>][@<refresh>]\" ");
1999 module_param_named(bpp
, default_bpp
, ulong
, 0);
2000 MODULE_PARM_DESC(bpp
, "Specify bit-per-pixel if not specified in 'mode'");
2001 module_param_named(monitor
, monitor_string
, charp
, 0);
2002 MODULE_PARM_DESC(monitor
, "Specify the monitor port "
2003 "(\"dvi\", \"lvds\", or \"dlvds\") if supported by the platform");