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>
35 #include <sysdev/fsl_soc.h>
36 #include <linux/fsl-diu-fb.h>
39 #define FSL_AOI_NUM 6 /* 5 AOIs and one dummy AOI */
40 /* 1 for plane 0, 2 for plane 1&2 each */
42 /* HW cursor parameters */
45 /* INT_STATUS/INT_MASK field descriptions */
46 #define INT_VSYNC 0x01 /* Vsync interrupt */
47 #define INT_VSYNC_WB 0x02 /* Vsync interrupt for write back operation */
48 #define INT_UNDRUN 0x04 /* Under run exception interrupt */
49 #define INT_PARERR 0x08 /* Display parameters error interrupt */
50 #define INT_LS_BF_VS 0x10 /* Lines before vsync. interrupt */
53 void *vaddr; /* Virtual address */
54 dma_addr_t paddr; /* Physical address */
59 * List of supported video modes
61 * The first entry is the default video mode. The remain entries are in
62 * order if increasing resolution and frequency. The 320x240-60 mode is
63 * the initial AOI for the second and third planes.
65 static struct fb_videomode __devinitdata fsl_diu_mode_db[] = {
77 .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
78 .vmode = FB_VMODE_NONINTERLACED
91 .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
92 .vmode = FB_VMODE_NONINTERLACED
105 .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
106 .vmode = FB_VMODE_NONINTERLACED
119 .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
120 .vmode = FB_VMODE_NONINTERLACED
133 .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
134 .vmode = FB_VMODE_NONINTERLACED
147 .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
148 .vmode = FB_VMODE_NONINTERLACED
161 .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
162 .vmode = FB_VMODE_NONINTERLACED
175 .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
176 .vmode = FB_VMODE_NONINTERLACED
189 .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
190 .vmode = FB_VMODE_NONINTERLACED
203 .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
204 .vmode = FB_VMODE_NONINTERLACED
217 .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
218 .vmode = FB_VMODE_NONINTERLACED
231 .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
232 .vmode = FB_VMODE_NONINTERLACED
245 .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
246 .vmode = FB_VMODE_NONINTERLACED
259 .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
260 .vmode = FB_VMODE_NONINTERLACED
273 .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
274 .vmode = FB_VMODE_NONINTERLACED
287 .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
288 .vmode = FB_VMODE_NONINTERLACED
301 .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
302 .vmode = FB_VMODE_NONINTERLACED
315 .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
316 .vmode = FB_VMODE_NONINTERLACED
320 static char *fb_mode;
321 static unsigned long default_bpp = 32;
322 static enum fsl_diu_monitor_port monitor_port;
323 static char *monitor_string;
325 #if defined(CONFIG_NOT_COHERENT_CACHE)
326 static u8 *coherence_data;
327 static size_t coherence_data_size;
328 static unsigned int d_cache_line_size;
331 static DEFINE_SPINLOCK(diu_lock);
333 struct fsl_diu_data {
334 struct fb_info *fsl_diu_info[FSL_AOI_NUM - 1];
335 /*FSL_AOI_NUM has one dummy AOI */
336 struct device_attribute dev_attr;
337 struct diu_ad *dummy_ad;
338 void *dummy_aoi_virt;
341 enum fsl_diu_monitor_port monitor_port;
342 struct diu __iomem *diu_reg;
345 struct diu_addr gamma;
346 struct diu_addr pallete;
347 struct diu_addr cursor;
351 PLANE0 = 0, /* Plane 0, only one AOI that fills the screen */
352 PLANE1_AOI0, /* Plane 1, first AOI */
353 PLANE1_AOI1, /* Plane 1, second AOI */
354 PLANE2_AOI0, /* Plane 2, first AOI */
355 PLANE2_AOI1, /* Plane 2, second AOI */
359 enum mfb_index index;
362 unsigned long pseudo_palette[16];
365 unsigned char g_alpha;
367 int x_aoi_d; /* aoi display x offset to physical screen */
368 int y_aoi_d; /* aoi display y offset to physical screen */
369 struct fsl_diu_data *parent;
374 static struct mfb_info mfb_template[] = {
384 .index = PLANE1_AOI0,
393 .index = PLANE1_AOI1,
402 .index = PLANE2_AOI0,
411 .index = PLANE2_AOI1,
422 * fsl_diu_name_to_port - convert a port name to a monitor port enum
424 * Takes the name of a monitor port ("dvi", "lvds", or "dlvds") and returns
425 * the enum fsl_diu_monitor_port that corresponds to that string.
427 * For compatibility with older versions, a number ("0", "1", or "2") is also
430 * If the string is unknown, DVI is assumed.
432 * If the particular port is not supported by the platform, another port
433 * (platform-specific) is chosen instead.
435 static enum fsl_diu_monitor_port fsl_diu_name_to_port(const char *s)
437 enum fsl_diu_monitor_port port = FSL_DIU_PORT_DVI;
441 if (!strict_strtoul(s, 10, &val) && (val <= 2))
442 port = (enum fsl_diu_monitor_port) val;
443 else if (strncmp(s, "lvds", 4) == 0)
444 port = FSL_DIU_PORT_LVDS;
445 else if (strncmp(s, "dlvds", 5) == 0)
446 port = FSL_DIU_PORT_DLVDS;
449 if (diu_ops.valid_monitor_port)
450 port = diu_ops.valid_monitor_port(port);
456 * fsl_diu_alloc - allocate memory for the DIU
457 * @size: number of bytes to allocate
458 * @param: returned physical address of memory
460 * This function allocates a physically-contiguous block of memory.
462 static void *fsl_diu_alloc(size_t size, phys_addr_t *phys)
466 virt = alloc_pages_exact(size, GFP_DMA | __GFP_ZERO);
468 *phys = virt_to_phys(virt);
474 * fsl_diu_free - release DIU memory
475 * @virt: pointer returned by fsl_diu_alloc()
476 * @size: number of bytes allocated by fsl_diu_alloc()
478 * This function releases memory allocated by fsl_diu_alloc().
480 static void fsl_diu_free(void *virt, size_t size)
483 free_pages_exact(virt, size);
487 * Workaround for failed writing desc register of planes.
488 * Needed with MPC5121 DIU rev 2.0 silicon.
490 void wr_reg_wa(u32 *reg, u32 val)
494 } while (in_be32(reg) != val);
497 static void fsl_diu_enable_panel(struct fb_info *info)
499 struct mfb_info *pmfbi, *cmfbi, *mfbi = info->par;
500 struct diu_ad *ad = mfbi->ad;
501 struct fsl_diu_data *machine_data = mfbi->parent;
502 struct diu __iomem *hw = machine_data->diu_reg;
504 switch (mfbi->index) {
506 if (hw->desc[0] != ad->paddr)
507 wr_reg_wa(&hw->desc[0], ad->paddr);
510 cmfbi = machine_data->fsl_diu_info[2]->par;
511 if (hw->desc[1] != ad->paddr) { /* AOI0 closed */
512 if (cmfbi->count > 0) /* AOI1 open */
514 cpu_to_le32(cmfbi->ad->paddr);
517 wr_reg_wa(&hw->desc[1], ad->paddr);
521 cmfbi = machine_data->fsl_diu_info[4]->par;
522 if (hw->desc[2] != ad->paddr) { /* AOI0 closed */
523 if (cmfbi->count > 0) /* AOI1 open */
525 cpu_to_le32(cmfbi->ad->paddr);
528 wr_reg_wa(&hw->desc[2], ad->paddr);
532 pmfbi = machine_data->fsl_diu_info[1]->par;
534 if (hw->desc[1] == machine_data->dummy_ad->paddr)
535 wr_reg_wa(&hw->desc[1], ad->paddr);
537 pmfbi->ad->next_ad = cpu_to_le32(ad->paddr);
540 pmfbi = machine_data->fsl_diu_info[3]->par;
542 if (hw->desc[2] == machine_data->dummy_ad->paddr)
543 wr_reg_wa(&hw->desc[2], ad->paddr);
544 else /* AOI0 was open */
545 pmfbi->ad->next_ad = cpu_to_le32(ad->paddr);
550 static void fsl_diu_disable_panel(struct fb_info *info)
552 struct mfb_info *pmfbi, *cmfbi, *mfbi = info->par;
553 struct diu_ad *ad = mfbi->ad;
554 struct fsl_diu_data *machine_data = mfbi->parent;
555 struct diu __iomem *hw = machine_data->diu_reg;
557 switch (mfbi->index) {
559 if (hw->desc[0] != machine_data->dummy_ad->paddr)
560 wr_reg_wa(&hw->desc[0], machine_data->dummy_ad->paddr);
563 cmfbi = machine_data->fsl_diu_info[2]->par;
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], machine_data->dummy_ad->paddr);
572 cmfbi = machine_data->fsl_diu_info[4]->par;
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], machine_data->dummy_ad->paddr);
581 pmfbi = machine_data->fsl_diu_info[1]->par;
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], machine_data->dummy_ad->paddr);
592 pmfbi = machine_data->fsl_diu_info[3]->par;
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], machine_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 *machine_data = mfbi->parent;
609 struct diu __iomem *hw = machine_data->diu_reg;
611 if (!machine_data->fb_enabled) {
612 out_be32(&hw->diu_mode, MFB_MODE1);
613 machine_data->fb_enabled++;
617 static void disable_lcdc(struct fb_info *info)
619 struct mfb_info *mfbi = info->par;
620 struct fsl_diu_data *machine_data = mfbi->parent;
621 struct diu __iomem *hw = machine_data->diu_reg;
623 if (machine_data->fb_enabled) {
624 out_be32(&hw->diu_mode, 0);
625 machine_data->fb_enabled = 0;
629 static void adjust_aoi_size_position(struct fb_var_screeninfo *var,
630 struct fb_info *info)
632 struct mfb_info *lower_aoi_mfbi, *upper_aoi_mfbi, *mfbi = info->par;
633 struct fsl_diu_data *machine_data = mfbi->parent;
634 int available_height, upper_aoi_bottom;
635 enum mfb_index index = mfbi->index;
636 int lower_aoi_is_open, upper_aoi_is_open;
637 __u32 base_plane_width, base_plane_height, upper_aoi_height;
639 base_plane_width = machine_data->fsl_diu_info[0]->var.xres;
640 base_plane_height = machine_data->fsl_diu_info[0]->var.yres;
642 if (mfbi->x_aoi_d < 0)
644 if (mfbi->y_aoi_d < 0)
648 if (mfbi->x_aoi_d != 0)
650 if (mfbi->y_aoi_d != 0)
655 lower_aoi_mfbi = machine_data->fsl_diu_info[index+1]->par;
656 lower_aoi_is_open = lower_aoi_mfbi->count > 0 ? 1 : 0;
657 if (var->xres > base_plane_width)
658 var->xres = base_plane_width;
659 if ((mfbi->x_aoi_d + var->xres) > base_plane_width)
660 mfbi->x_aoi_d = base_plane_width - var->xres;
662 if (lower_aoi_is_open)
663 available_height = lower_aoi_mfbi->y_aoi_d;
665 available_height = base_plane_height;
666 if (var->yres > available_height)
667 var->yres = available_height;
668 if ((mfbi->y_aoi_d + var->yres) > available_height)
669 mfbi->y_aoi_d = available_height - var->yres;
673 upper_aoi_mfbi = machine_data->fsl_diu_info[index-1]->par;
675 machine_data->fsl_diu_info[index-1]->var.yres;
676 upper_aoi_bottom = upper_aoi_mfbi->y_aoi_d + upper_aoi_height;
677 upper_aoi_is_open = upper_aoi_mfbi->count > 0 ? 1 : 0;
678 if (var->xres > base_plane_width)
679 var->xres = base_plane_width;
680 if ((mfbi->x_aoi_d + var->xres) > base_plane_width)
681 mfbi->x_aoi_d = base_plane_width - var->xres;
682 if (mfbi->y_aoi_d < 0)
684 if (upper_aoi_is_open) {
685 if (mfbi->y_aoi_d < upper_aoi_bottom)
686 mfbi->y_aoi_d = upper_aoi_bottom;
687 available_height = base_plane_height
690 available_height = base_plane_height;
691 if (var->yres > available_height)
692 var->yres = available_height;
693 if ((mfbi->y_aoi_d + var->yres) > base_plane_height)
694 mfbi->y_aoi_d = base_plane_height - var->yres;
699 * Checks to see if the hardware supports the state requested by var passed
700 * in. This function does not alter the hardware state! If the var passed in
701 * is slightly off by what the hardware can support then we alter the var
702 * PASSED in to what we can do. If the hardware doesn't support mode change
703 * a -EINVAL will be returned by the upper layers.
705 static int fsl_diu_check_var(struct fb_var_screeninfo *var,
706 struct fb_info *info)
708 if (var->xres_virtual < var->xres)
709 var->xres_virtual = var->xres;
710 if (var->yres_virtual < var->yres)
711 var->yres_virtual = var->yres;
713 if (var->xoffset < 0)
716 if (var->yoffset < 0)
719 if (var->xoffset + info->var.xres > info->var.xres_virtual)
720 var->xoffset = info->var.xres_virtual - info->var.xres;
722 if (var->yoffset + info->var.yres > info->var.yres_virtual)
723 var->yoffset = info->var.yres_virtual - info->var.yres;
725 if ((var->bits_per_pixel != 32) && (var->bits_per_pixel != 24) &&
726 (var->bits_per_pixel != 16))
727 var->bits_per_pixel = default_bpp;
729 switch (var->bits_per_pixel) {
732 var->red.offset = 11;
733 var->red.msb_right = 0;
735 var->green.length = 6;
736 var->green.offset = 5;
737 var->green.msb_right = 0;
739 var->blue.length = 5;
740 var->blue.offset = 0;
741 var->blue.msb_right = 0;
743 var->transp.length = 0;
744 var->transp.offset = 0;
745 var->transp.msb_right = 0;
750 var->red.msb_right = 0;
752 var->green.length = 8;
753 var->green.offset = 8;
754 var->green.msb_right = 0;
756 var->blue.length = 8;
757 var->blue.offset = 16;
758 var->blue.msb_right = 0;
760 var->transp.length = 0;
761 var->transp.offset = 0;
762 var->transp.msb_right = 0;
766 var->red.offset = 16;
767 var->red.msb_right = 0;
769 var->green.length = 8;
770 var->green.offset = 8;
771 var->green.msb_right = 0;
773 var->blue.length = 8;
774 var->blue.offset = 0;
775 var->blue.msb_right = 0;
777 var->transp.length = 8;
778 var->transp.offset = 24;
779 var->transp.msb_right = 0;
788 /* Copy nonstd field to/from sync for fbset usage */
789 var->sync |= var->nonstd;
790 var->nonstd |= var->sync;
792 adjust_aoi_size_position(var, info);
796 static void set_fix(struct fb_info *info)
798 struct fb_fix_screeninfo *fix = &info->fix;
799 struct fb_var_screeninfo *var = &info->var;
800 struct mfb_info *mfbi = info->par;
802 strncpy(fix->id, mfbi->id, sizeof(fix->id));
803 fix->line_length = var->xres_virtual * var->bits_per_pixel / 8;
804 fix->type = FB_TYPE_PACKED_PIXELS;
805 fix->accel = FB_ACCEL_NONE;
806 fix->visual = FB_VISUAL_TRUECOLOR;
811 static void update_lcdc(struct fb_info *info)
813 struct fb_var_screeninfo *var = &info->var;
814 struct mfb_info *mfbi = info->par;
815 struct fsl_diu_data *machine_data = mfbi->parent;
816 struct diu __iomem *hw;
818 char __iomem *cursor_base, *gamma_table_base;
822 hw = machine_data->diu_reg;
824 diu_ops.set_monitor_port(machine_data->monitor_port);
825 gamma_table_base = machine_data->gamma.vaddr;
826 cursor_base = machine_data->cursor.vaddr;
827 /* Prep for DIU init - gamma table, cursor table */
829 for (i = 0; i <= 2; i++)
830 for (j = 0; j <= 255; j++)
831 *gamma_table_base++ = j;
833 diu_ops.set_gamma_table(machine_data->monitor_port,
834 machine_data->gamma.vaddr);
838 /* Program DIU registers */
840 out_be32(&hw->gamma, machine_data->gamma.paddr);
841 out_be32(&hw->cursor, machine_data->cursor.paddr);
843 out_be32(&hw->bgnd, 0x007F7F7F); /* BGND */
844 out_be32(&hw->bgnd_wb, 0); /* BGND_WB */
845 out_be32(&hw->disp_size, (var->yres << 16 | var->xres));
847 out_be32(&hw->wb_size, 0); /* WB SIZE */
848 out_be32(&hw->wb_mem_addr, 0); /* WB MEM ADDR */
850 /* Horizontal and vertical configuration register */
851 temp = var->left_margin << 22 | /* BP_H */
852 var->hsync_len << 11 | /* PW_H */
853 var->right_margin; /* FP_H */
855 out_be32(&hw->hsyn_para, temp);
857 temp = var->upper_margin << 22 | /* BP_V */
858 var->vsync_len << 11 | /* PW_V */
859 var->lower_margin; /* FP_V */
861 out_be32(&hw->vsyn_para, temp);
863 diu_ops.set_pixel_clock(var->pixclock);
865 out_be32(&hw->syn_pol, 0); /* SYNC SIGNALS POLARITY */
866 out_be32(&hw->thresholds, 0x00037800); /* The Thresholds */
867 out_be32(&hw->int_status, 0); /* INTERRUPT STATUS */
868 out_be32(&hw->plut, 0x01F5F666);
874 static int map_video_memory(struct fb_info *info)
877 u32 smem_len = info->fix.line_length * info->var.yres_virtual;
879 info->screen_base = fsl_diu_alloc(smem_len, &phys);
880 if (info->screen_base == NULL) {
881 dev_err(info->dev, "unable to allocate fb memory\n");
884 mutex_lock(&info->mm_lock);
885 info->fix.smem_start = (unsigned long) phys;
886 info->fix.smem_len = smem_len;
887 mutex_unlock(&info->mm_lock);
888 info->screen_size = info->fix.smem_len;
893 static void unmap_video_memory(struct fb_info *info)
895 fsl_diu_free(info->screen_base, info->fix.smem_len);
896 mutex_lock(&info->mm_lock);
897 info->screen_base = NULL;
898 info->fix.smem_start = 0;
899 info->fix.smem_len = 0;
900 mutex_unlock(&info->mm_lock);
904 * Using the fb_var_screeninfo in fb_info we set the aoi of this
905 * particular framebuffer. It is a light version of fsl_diu_set_par.
907 static int fsl_diu_set_aoi(struct fb_info *info)
909 struct fb_var_screeninfo *var = &info->var;
910 struct mfb_info *mfbi = info->par;
911 struct diu_ad *ad = mfbi->ad;
913 /* AOI should not be greater than display size */
914 ad->offset_xyi = cpu_to_le32((var->yoffset << 16) | var->xoffset);
915 ad->offset_xyd = cpu_to_le32((mfbi->y_aoi_d << 16) | mfbi->x_aoi_d);
920 * Using the fb_var_screeninfo in fb_info we set the resolution of this
921 * particular framebuffer. This function alters the fb_fix_screeninfo stored
922 * in fb_info. It does not alter var in fb_info since we are using that
923 * data. This means we depend on the data in var inside fb_info to be
924 * supported by the hardware. fsl_diu_check_var is always called before
925 * fsl_diu_set_par to ensure this.
927 static int fsl_diu_set_par(struct fb_info *info)
930 struct fb_var_screeninfo *var = &info->var;
931 struct mfb_info *mfbi = info->par;
932 struct fsl_diu_data *machine_data = mfbi->parent;
933 struct diu_ad *ad = mfbi->ad;
934 struct diu __iomem *hw;
936 hw = machine_data->diu_reg;
939 mfbi->cursor_reset = 1;
941 len = info->var.yres_virtual * info->fix.line_length;
942 /* Alloc & dealloc each time resolution/bpp change */
943 if (len != info->fix.smem_len) {
944 if (info->fix.smem_start)
945 unmap_video_memory(info);
947 /* Memory allocation for framebuffer */
948 if (map_video_memory(info)) {
949 dev_err(info->dev, "unable to allocate fb memory 1\n");
954 ad->pix_fmt = diu_ops.get_pixel_format(machine_data->monitor_port,
955 var->bits_per_pixel);
956 ad->addr = cpu_to_le32(info->fix.smem_start);
957 ad->src_size_g_alpha = cpu_to_le32((var->yres_virtual << 12) |
958 var->xres_virtual) | mfbi->g_alpha;
959 /* AOI should not be greater than display size */
960 ad->aoi_size = cpu_to_le32((var->yres << 16) | var->xres);
961 ad->offset_xyi = cpu_to_le32((var->yoffset << 16) | var->xoffset);
962 ad->offset_xyd = cpu_to_le32((mfbi->y_aoi_d << 16) | mfbi->x_aoi_d);
964 /* Disable chroma keying function */
973 if (mfbi->index == PLANE0)
978 static inline __u32 CNVT_TOHW(__u32 val, __u32 width)
980 return ((val << width) + 0x7FFF - val) >> 16;
984 * Set a single color register. The values supplied have a 16 bit magnitude
985 * which needs to be scaled in this function for the hardware. Things to take
986 * into consideration are how many color registers, if any, are supported with
987 * the current color visual. With truecolor mode no color palettes are
988 * supported. Here a pseudo palette is created which we store the value in
989 * pseudo_palette in struct fb_info. For pseudocolor mode we have a limited
992 static int fsl_diu_setcolreg(unsigned int regno, unsigned int red,
993 unsigned int green, unsigned int blue,
994 unsigned int transp, struct fb_info *info)
999 * If greyscale is true, then we convert the RGB value
1000 * to greyscale no matter what visual we are using.
1002 if (info->var.grayscale)
1003 red = green = blue = (19595 * red + 38470 * green +
1005 switch (info->fix.visual) {
1006 case FB_VISUAL_TRUECOLOR:
1008 * 16-bit True Colour. We encode the RGB value
1009 * according to the RGB bitfield information.
1012 u32 *pal = info->pseudo_palette;
1015 red = CNVT_TOHW(red, info->var.red.length);
1016 green = CNVT_TOHW(green, info->var.green.length);
1017 blue = CNVT_TOHW(blue, info->var.blue.length);
1018 transp = CNVT_TOHW(transp, info->var.transp.length);
1020 v = (red << info->var.red.offset) |
1021 (green << info->var.green.offset) |
1022 (blue << info->var.blue.offset) |
1023 (transp << info->var.transp.offset);
1035 * Pan (or wrap, depending on the `vmode' field) the display using the
1036 * 'xoffset' and 'yoffset' fields of the 'var' structure. If the values
1037 * don't fit, return -EINVAL.
1039 static int fsl_diu_pan_display(struct fb_var_screeninfo *var,
1040 struct fb_info *info)
1042 if ((info->var.xoffset == var->xoffset) &&
1043 (info->var.yoffset == var->yoffset))
1044 return 0; /* No change, do nothing */
1046 if (var->xoffset < 0 || var->yoffset < 0
1047 || var->xoffset + info->var.xres > info->var.xres_virtual
1048 || var->yoffset + info->var.yres > info->var.yres_virtual)
1051 info->var.xoffset = var->xoffset;
1052 info->var.yoffset = var->yoffset;
1054 if (var->vmode & FB_VMODE_YWRAP)
1055 info->var.vmode |= FB_VMODE_YWRAP;
1057 info->var.vmode &= ~FB_VMODE_YWRAP;
1059 fsl_diu_set_aoi(info);
1064 static int fsl_diu_ioctl(struct fb_info *info, unsigned int cmd,
1067 struct mfb_info *mfbi = info->par;
1068 struct diu_ad *ad = mfbi->ad;
1069 struct mfb_chroma_key ck;
1070 unsigned char global_alpha;
1071 struct aoi_display_offset aoi_d;
1073 void __user *buf = (void __user *)arg;
1078 case MFB_SET_PIXFMT_OLD:
1080 "MFB_SET_PIXFMT value of 0x%08x is deprecated.\n",
1081 MFB_SET_PIXFMT_OLD);
1082 case MFB_SET_PIXFMT:
1083 if (copy_from_user(&pix_fmt, buf, sizeof(pix_fmt)))
1085 ad->pix_fmt = pix_fmt;
1087 case MFB_GET_PIXFMT_OLD:
1089 "MFB_GET_PIXFMT value of 0x%08x is deprecated.\n",
1090 MFB_GET_PIXFMT_OLD);
1091 case MFB_GET_PIXFMT:
1092 pix_fmt = ad->pix_fmt;
1093 if (copy_to_user(buf, &pix_fmt, sizeof(pix_fmt)))
1097 if (copy_from_user(&aoi_d, buf, sizeof(aoi_d)))
1099 mfbi->x_aoi_d = aoi_d.x_aoi_d;
1100 mfbi->y_aoi_d = aoi_d.y_aoi_d;
1101 fsl_diu_check_var(&info->var, info);
1102 fsl_diu_set_aoi(info);
1105 aoi_d.x_aoi_d = mfbi->x_aoi_d;
1106 aoi_d.y_aoi_d = mfbi->y_aoi_d;
1107 if (copy_to_user(buf, &aoi_d, sizeof(aoi_d)))
1111 global_alpha = mfbi->g_alpha;
1112 if (copy_to_user(buf, &global_alpha, sizeof(global_alpha)))
1116 /* set panel information */
1117 if (copy_from_user(&global_alpha, buf, sizeof(global_alpha)))
1119 ad->src_size_g_alpha = (ad->src_size_g_alpha & (~0xff)) |
1120 (global_alpha & 0xff);
1121 mfbi->g_alpha = global_alpha;
1123 case MFB_SET_CHROMA_KEY:
1124 /* set panel winformation */
1125 if (copy_from_user(&ck, buf, sizeof(ck)))
1129 (ck.red_max < ck.red_min ||
1130 ck.green_max < ck.green_min ||
1131 ck.blue_max < ck.blue_min))
1142 ad->ckmax_r = ck.red_max;
1143 ad->ckmax_g = ck.green_max;
1144 ad->ckmax_b = ck.blue_max;
1145 ad->ckmin_r = ck.red_min;
1146 ad->ckmin_g = ck.green_min;
1147 ad->ckmin_b = ck.blue_min;
1151 dev_err(info->dev, "unknown ioctl command (0x%08X)\n", cmd);
1152 return -ENOIOCTLCMD;
1158 /* turn on fb if count == 1
1160 static int fsl_diu_open(struct fb_info *info, int user)
1162 struct mfb_info *mfbi = info->par;
1165 /* free boot splash memory on first /dev/fb0 open */
1166 if ((mfbi->index == PLANE0) && diu_ops.release_bootmem)
1167 diu_ops.release_bootmem();
1169 spin_lock(&diu_lock);
1171 if (mfbi->count == 1) {
1172 fsl_diu_check_var(&info->var, info);
1173 res = fsl_diu_set_par(info);
1177 fsl_diu_enable_panel(info);
1180 spin_unlock(&diu_lock);
1184 /* turn off fb if count == 0
1186 static int fsl_diu_release(struct fb_info *info, int user)
1188 struct mfb_info *mfbi = info->par;
1191 spin_lock(&diu_lock);
1193 if (mfbi->count == 0)
1194 fsl_diu_disable_panel(info);
1196 spin_unlock(&diu_lock);
1200 static struct fb_ops fsl_diu_ops = {
1201 .owner = THIS_MODULE,
1202 .fb_check_var = fsl_diu_check_var,
1203 .fb_set_par = fsl_diu_set_par,
1204 .fb_setcolreg = fsl_diu_setcolreg,
1205 .fb_pan_display = fsl_diu_pan_display,
1206 .fb_fillrect = cfb_fillrect,
1207 .fb_copyarea = cfb_copyarea,
1208 .fb_imageblit = cfb_imageblit,
1209 .fb_ioctl = fsl_diu_ioctl,
1210 .fb_open = fsl_diu_open,
1211 .fb_release = fsl_diu_release,
1214 static int init_fbinfo(struct fb_info *info)
1216 struct mfb_info *mfbi = info->par;
1218 info->device = NULL;
1219 info->var.activate = FB_ACTIVATE_NOW;
1220 info->fbops = &fsl_diu_ops;
1221 info->flags = FBINFO_FLAG_DEFAULT;
1222 info->pseudo_palette = &mfbi->pseudo_palette;
1224 /* Allocate colormap */
1225 fb_alloc_cmap(&info->cmap, 16, 0);
1229 static int __devinit install_fb(struct fb_info *info)
1232 struct mfb_info *mfbi = info->par;
1233 const char *aoi_mode, *init_aoi_mode = "320x240";
1234 struct fb_videomode *db = fsl_diu_mode_db;
1235 unsigned int dbsize = ARRAY_SIZE(fsl_diu_mode_db);
1236 int has_default_mode = 1;
1238 if (init_fbinfo(info))
1241 if (mfbi->index == PLANE0) {
1242 if (mfbi->edid_data) {
1243 /* Now build modedb from EDID */
1244 fb_edid_to_monspecs(mfbi->edid_data, &info->monspecs);
1245 fb_videomode_to_modelist(info->monspecs.modedb,
1246 info->monspecs.modedb_len,
1248 db = info->monspecs.modedb;
1249 dbsize = info->monspecs.modedb_len;
1253 aoi_mode = init_aoi_mode;
1255 rc = fb_find_mode(&info->var, info, aoi_mode, db, dbsize, NULL,
1259 * For plane 0 we continue and look into
1260 * driver's internal modedb.
1262 if ((mfbi->index == PLANE0) && mfbi->edid_data)
1263 has_default_mode = 0;
1268 if (!has_default_mode) {
1269 rc = fb_find_mode(&info->var, info, aoi_mode, fsl_diu_mode_db,
1270 ARRAY_SIZE(fsl_diu_mode_db), NULL, default_bpp);
1272 has_default_mode = 1;
1275 /* Still not found, use preferred mode from database if any */
1276 if (!has_default_mode && info->monspecs.modedb) {
1277 struct fb_monspecs *specs = &info->monspecs;
1278 struct fb_videomode *modedb = &specs->modedb[0];
1281 * Get preferred timing. If not found,
1282 * first mode in database will be used.
1284 if (specs->misc & FB_MISC_1ST_DETAIL) {
1287 for (i = 0; i < specs->modedb_len; i++) {
1288 if (specs->modedb[i].flag & FB_MODE_IS_FIRST) {
1289 modedb = &specs->modedb[i];
1295 info->var.bits_per_pixel = default_bpp;
1296 fb_videomode_to_var(&info->var, modedb);
1299 if (fsl_diu_check_var(&info->var, info)) {
1300 dev_err(info->dev, "fsl_diu_check_var failed\n");
1301 unmap_video_memory(info);
1302 fb_dealloc_cmap(&info->cmap);
1306 if (register_framebuffer(info) < 0) {
1307 dev_err(info->dev, "register_framebuffer failed\n");
1308 unmap_video_memory(info);
1309 fb_dealloc_cmap(&info->cmap);
1313 mfbi->registered = 1;
1314 dev_info(info->dev, "%s registered successfully\n", mfbi->id);
1319 static void uninstall_fb(struct fb_info *info)
1321 struct mfb_info *mfbi = info->par;
1323 if (!mfbi->registered)
1326 if (mfbi->index == PLANE0)
1327 kfree(mfbi->edid_data);
1329 unregister_framebuffer(info);
1330 unmap_video_memory(info);
1332 fb_dealloc_cmap(&info->cmap);
1334 mfbi->registered = 0;
1337 static irqreturn_t fsl_diu_isr(int irq, void *dev_id)
1339 struct diu __iomem *hw = dev_id;
1340 unsigned int status = in_be32(&hw->int_status);
1343 /* This is the workaround for underrun */
1344 if (status & INT_UNDRUN) {
1345 out_be32(&hw->diu_mode, 0);
1347 out_be32(&hw->diu_mode, 1);
1349 #if defined(CONFIG_NOT_COHERENT_CACHE)
1350 else if (status & INT_VSYNC) {
1353 for (i = 0; i < coherence_data_size;
1354 i += d_cache_line_size)
1355 __asm__ __volatile__ (
1357 ::[input]"r"(&coherence_data[i]));
1365 static int request_irq_local(struct fsl_diu_data *machine_data)
1367 struct diu __iomem *hw = machine_data->diu_reg;
1371 /* Read to clear the status */
1372 in_be32(&hw->int_status);
1374 ret = request_irq(machine_data->irq, fsl_diu_isr, 0, "fsl-diu-fb", hw);
1376 ints = INT_PARERR | INT_LS_BF_VS;
1377 #if !defined(CONFIG_NOT_COHERENT_CACHE)
1381 /* Read to clear the status */
1382 in_be32(&hw->int_status);
1383 out_be32(&hw->int_mask, ints);
1389 static void free_irq_local(struct fsl_diu_data *machine_data)
1391 struct diu __iomem *hw = machine_data->diu_reg;
1393 /* Disable all LCDC interrupt */
1394 out_be32(&hw->int_mask, 0x1f);
1396 free_irq(machine_data->irq, NULL);
1401 * Power management hooks. Note that we won't be called from IRQ context,
1402 * unlike the blank functions above, so we may sleep.
1404 static int fsl_diu_suspend(struct platform_device *ofdev, pm_message_t state)
1406 struct fsl_diu_data *machine_data;
1408 machine_data = dev_get_drvdata(&ofdev->dev);
1409 disable_lcdc(machine_data->fsl_diu_info[0]);
1414 static int fsl_diu_resume(struct platform_device *ofdev)
1416 struct fsl_diu_data *machine_data;
1418 machine_data = dev_get_drvdata(&ofdev->dev);
1419 enable_lcdc(machine_data->fsl_diu_info[0]);
1425 #define fsl_diu_suspend NULL
1426 #define fsl_diu_resume NULL
1427 #endif /* CONFIG_PM */
1429 /* Align to 64-bit(8-byte), 32-byte, etc. */
1430 static int allocate_buf(struct device *dev, struct diu_addr *buf, u32 size,
1437 dma_alloc_coherent(dev, size + bytes_align, &buf->paddr,
1438 GFP_DMA | __GFP_ZERO);
1442 mask = bytes_align - 1;
1443 offset = buf->paddr & mask;
1445 buf->offset = bytes_align - offset;
1446 buf->paddr = buf->paddr + offset;
1453 static void free_buf(struct device *dev, struct diu_addr *buf, u32 size,
1456 dma_free_coherent(dev, size + bytes_align, buf->vaddr,
1457 buf->paddr - buf->offset);
1460 static ssize_t store_monitor(struct device *device,
1461 struct device_attribute *attr, const char *buf, size_t count)
1463 enum fsl_diu_monitor_port old_monitor_port;
1464 struct fsl_diu_data *machine_data =
1465 container_of(attr, struct fsl_diu_data, dev_attr);
1467 old_monitor_port = machine_data->monitor_port;
1468 machine_data->monitor_port = fsl_diu_name_to_port(buf);
1470 if (old_monitor_port != machine_data->monitor_port) {
1471 /* All AOIs need adjust pixel format
1472 * fsl_diu_set_par only change the pixsel format here
1473 * unlikely to fail. */
1474 fsl_diu_set_par(machine_data->fsl_diu_info[0]);
1475 fsl_diu_set_par(machine_data->fsl_diu_info[1]);
1476 fsl_diu_set_par(machine_data->fsl_diu_info[2]);
1477 fsl_diu_set_par(machine_data->fsl_diu_info[3]);
1478 fsl_diu_set_par(machine_data->fsl_diu_info[4]);
1483 static ssize_t show_monitor(struct device *device,
1484 struct device_attribute *attr, char *buf)
1486 struct fsl_diu_data *machine_data =
1487 container_of(attr, struct fsl_diu_data, dev_attr);
1489 switch (machine_data->monitor_port) {
1490 case FSL_DIU_PORT_DVI:
1491 return sprintf(buf, "DVI\n");
1492 case FSL_DIU_PORT_LVDS:
1493 return sprintf(buf, "Single-link LVDS\n");
1494 case FSL_DIU_PORT_DLVDS:
1495 return sprintf(buf, "Dual-link LVDS\n");
1501 static int __devinit fsl_diu_probe(struct platform_device *pdev)
1503 struct device_node *np = pdev->dev.of_node;
1504 struct mfb_info *mfbi;
1505 phys_addr_t dummy_ad_addr = 0;
1506 int ret, i, error = 0;
1507 struct fsl_diu_data *machine_data;
1510 machine_data = kzalloc(sizeof(struct fsl_diu_data), GFP_KERNEL);
1514 spin_lock_init(&machine_data->reg_lock);
1516 for (i = 0; i < ARRAY_SIZE(machine_data->fsl_diu_info); i++) {
1517 machine_data->fsl_diu_info[i] =
1518 framebuffer_alloc(sizeof(struct mfb_info), &pdev->dev);
1519 if (!machine_data->fsl_diu_info[i]) {
1520 dev_err(&pdev->dev, "cannot allocate memory\n");
1524 mfbi = machine_data->fsl_diu_info[i]->par;
1525 memcpy(mfbi, &mfb_template[i], sizeof(struct mfb_info));
1526 mfbi->parent = machine_data;
1528 if (mfbi->index == PLANE0) {
1533 prop = of_get_property(np, "edid", &len);
1534 if (prop && len == EDID_LENGTH)
1535 mfbi->edid_data = kmemdup(prop, EDID_LENGTH,
1540 machine_data->diu_reg = of_iomap(np, 0);
1541 if (!machine_data->diu_reg) {
1542 dev_err(&pdev->dev, "cannot map DIU registers\n");
1547 diu_mode = in_be32(&machine_data->diu_reg->diu_mode);
1548 if (diu_mode == MFB_MODE0)
1549 out_be32(&machine_data->diu_reg->diu_mode, 0); /* disable DIU */
1551 /* Get the IRQ of the DIU */
1552 machine_data->irq = irq_of_parse_and_map(np, 0);
1554 if (!machine_data->irq) {
1555 dev_err(&pdev->dev, "could not get DIU IRQ\n");
1559 machine_data->monitor_port = monitor_port;
1561 /* Area descriptor memory pool aligns to 64-bit boundary */
1562 if (allocate_buf(&pdev->dev, &machine_data->ad,
1563 sizeof(struct diu_ad) * FSL_AOI_NUM, 8))
1566 /* Get memory for Gamma Table - 32-byte aligned memory */
1567 if (allocate_buf(&pdev->dev, &machine_data->gamma, 768, 32)) {
1572 /* For performance, cursor bitmap buffer aligns to 32-byte boundary */
1573 if (allocate_buf(&pdev->dev, &machine_data->cursor,
1574 MAX_CURS * MAX_CURS * 2, 32)) {
1579 i = ARRAY_SIZE(machine_data->fsl_diu_info);
1580 machine_data->dummy_ad = (struct diu_ad *)((u32)machine_data->ad.vaddr +
1581 machine_data->ad.offset) + i;
1582 machine_data->dummy_ad->paddr = machine_data->ad.paddr +
1583 i * sizeof(struct diu_ad);
1584 machine_data->dummy_aoi_virt = fsl_diu_alloc(64, &dummy_ad_addr);
1585 if (!machine_data->dummy_aoi_virt) {
1589 machine_data->dummy_ad->addr = cpu_to_le32(dummy_ad_addr);
1590 machine_data->dummy_ad->pix_fmt = 0x88882317;
1591 machine_data->dummy_ad->src_size_g_alpha = cpu_to_le32((4 << 12) | 4);
1592 machine_data->dummy_ad->aoi_size = cpu_to_le32((4 << 16) | 2);
1593 machine_data->dummy_ad->offset_xyi = 0;
1594 machine_data->dummy_ad->offset_xyd = 0;
1595 machine_data->dummy_ad->next_ad = 0;
1598 * Let DIU display splash screen if it was pre-initialized
1599 * by the bootloader, set dummy area descriptor otherwise.
1601 if (diu_mode == MFB_MODE0)
1602 out_be32(&machine_data->diu_reg->desc[0],
1603 machine_data->dummy_ad->paddr);
1605 out_be32(&machine_data->diu_reg->desc[1], machine_data->dummy_ad->paddr);
1606 out_be32(&machine_data->diu_reg->desc[2], machine_data->dummy_ad->paddr);
1608 for (i = 0; i < ARRAY_SIZE(machine_data->fsl_diu_info); i++) {
1609 machine_data->fsl_diu_info[i]->fix.smem_start = 0;
1610 mfbi = machine_data->fsl_diu_info[i]->par;
1611 mfbi->ad = (struct diu_ad *)((u32)machine_data->ad.vaddr
1612 + machine_data->ad.offset) + i;
1614 machine_data->ad.paddr + i * sizeof(struct diu_ad);
1615 ret = install_fb(machine_data->fsl_diu_info[i]);
1617 dev_err(&pdev->dev, "could not register fb %d\n", i);
1622 if (request_irq_local(machine_data)) {
1623 dev_err(&pdev->dev, "could not claim irq\n");
1627 sysfs_attr_init(&machine_data->dev_attr.attr);
1628 machine_data->dev_attr.attr.name = "monitor";
1629 machine_data->dev_attr.attr.mode = S_IRUGO|S_IWUSR;
1630 machine_data->dev_attr.show = show_monitor;
1631 machine_data->dev_attr.store = store_monitor;
1632 error = device_create_file(machine_data->fsl_diu_info[0]->dev,
1633 &machine_data->dev_attr);
1635 dev_err(&pdev->dev, "could not create sysfs file %s\n",
1636 machine_data->dev_attr.attr.name);
1639 dev_set_drvdata(&pdev->dev, machine_data);
1643 for (i = 0; i < ARRAY_SIZE(machine_data->fsl_diu_info); i++)
1644 uninstall_fb(machine_data->fsl_diu_info[i]);
1646 if (machine_data->ad.vaddr)
1647 free_buf(&pdev->dev, &machine_data->ad,
1648 sizeof(struct diu_ad) * FSL_AOI_NUM, 8);
1649 if (machine_data->gamma.vaddr)
1650 free_buf(&pdev->dev, &machine_data->gamma, 768, 32);
1651 if (machine_data->cursor.vaddr)
1652 free_buf(&pdev->dev, &machine_data->cursor,
1653 MAX_CURS * MAX_CURS * 2, 32);
1654 if (machine_data->dummy_aoi_virt)
1655 fsl_diu_free(machine_data->dummy_aoi_virt, 64);
1656 iounmap(machine_data->diu_reg);
1659 for (i = 0; i < ARRAY_SIZE(machine_data->fsl_diu_info); i++)
1660 if (machine_data->fsl_diu_info[i])
1661 framebuffer_release(machine_data->fsl_diu_info[i]);
1662 kfree(machine_data);
1667 static int fsl_diu_remove(struct platform_device *pdev)
1669 struct fsl_diu_data *machine_data;
1672 machine_data = dev_get_drvdata(&pdev->dev);
1673 disable_lcdc(machine_data->fsl_diu_info[0]);
1674 free_irq_local(machine_data);
1675 for (i = 0; i < ARRAY_SIZE(machine_data->fsl_diu_info); i++)
1676 uninstall_fb(machine_data->fsl_diu_info[i]);
1677 if (machine_data->ad.vaddr)
1678 free_buf(&pdev->dev, &machine_data->ad,
1679 sizeof(struct diu_ad) * FSL_AOI_NUM, 8);
1680 if (machine_data->gamma.vaddr)
1681 free_buf(&pdev->dev, &machine_data->gamma, 768, 32);
1682 if (machine_data->cursor.vaddr)
1683 free_buf(&pdev->dev, &machine_data->cursor,
1684 MAX_CURS * MAX_CURS * 2, 32);
1685 if (machine_data->dummy_aoi_virt)
1686 fsl_diu_free(machine_data->dummy_aoi_virt, 64);
1687 iounmap(machine_data->diu_reg);
1688 for (i = 0; i < ARRAY_SIZE(machine_data->fsl_diu_info); i++)
1689 if (machine_data->fsl_diu_info[i])
1690 framebuffer_release(machine_data->fsl_diu_info[i]);
1691 kfree(machine_data);
1697 static int __init fsl_diu_setup(char *options)
1702 if (!options || !*options)
1705 while ((opt = strsep(&options, ",")) != NULL) {
1708 if (!strncmp(opt, "monitor=", 8)) {
1709 monitor_port = fsl_diu_name_to_port(opt + 8);
1710 } else if (!strncmp(opt, "bpp=", 4)) {
1711 if (!strict_strtoul(opt + 4, 10, &val))
1721 static struct of_device_id fsl_diu_match[] = {
1722 #ifdef CONFIG_PPC_MPC512x
1724 .compatible = "fsl,mpc5121-diu",
1728 .compatible = "fsl,diu",
1732 MODULE_DEVICE_TABLE(of, fsl_diu_match);
1734 static struct platform_driver fsl_diu_driver = {
1736 .name = "fsl-diu-fb",
1737 .owner = THIS_MODULE,
1738 .of_match_table = fsl_diu_match,
1740 .probe = fsl_diu_probe,
1741 .remove = fsl_diu_remove,
1742 .suspend = fsl_diu_suspend,
1743 .resume = fsl_diu_resume,
1746 static int __init fsl_diu_init(void)
1748 #ifdef CONFIG_NOT_COHERENT_CACHE
1749 struct device_node *np;
1757 * For kernel boot options (in 'video=xxxfb:<options>' format)
1759 if (fb_get_options("fslfb", &option))
1761 fsl_diu_setup(option);
1763 monitor_port = fsl_diu_name_to_port(monitor_string);
1767 * Must to verify set_pixel_clock. If not implement on platform,
1768 * then that means that there is no platform support for the DIU.
1770 if (!diu_ops.set_pixel_clock)
1773 pr_info("Freescale Display Interface Unit (DIU) framebuffer driver\n");
1775 #ifdef CONFIG_NOT_COHERENT_CACHE
1776 np = of_find_node_by_type(NULL, "cpu");
1778 pr_err("fsl-diu-fb: can't find 'cpu' device node\n");
1782 prop = of_get_property(np, "d-cache-size", NULL);
1784 pr_err("fsl-diu-fb: missing 'd-cache-size' property' "
1791 * Freescale PLRU requires 13/8 times the cache size to do a proper
1792 * displacement flush
1794 coherence_data_size = be32_to_cpup(prop) * 13;
1795 coherence_data_size /= 8;
1797 prop = of_get_property(np, "d-cache-line-size", NULL);
1799 pr_err("fsl-diu-fb: missing 'd-cache-line-size' property' "
1804 d_cache_line_size = be32_to_cpup(prop);
1807 coherence_data = vmalloc(coherence_data_size);
1808 if (!coherence_data)
1812 ret = platform_driver_register(&fsl_diu_driver);
1814 pr_err("fsl-diu-fb: failed to register platform driver\n");
1815 #if defined(CONFIG_NOT_COHERENT_CACHE)
1816 vfree(coherence_data);
1822 static void __exit fsl_diu_exit(void)
1824 platform_driver_unregister(&fsl_diu_driver);
1825 #if defined(CONFIG_NOT_COHERENT_CACHE)
1826 vfree(coherence_data);
1830 module_init(fsl_diu_init);
1831 module_exit(fsl_diu_exit);
1833 MODULE_AUTHOR("York Sun <yorksun@freescale.com>");
1834 MODULE_DESCRIPTION("Freescale DIU framebuffer driver");
1835 MODULE_LICENSE("GPL");
1837 module_param_named(mode, fb_mode, charp, 0);
1838 MODULE_PARM_DESC(mode,
1839 "Specify resolution as \"<xres>x<yres>[-<bpp>][@<refresh>]\" ");
1840 module_param_named(bpp, default_bpp, ulong, 0);
1841 MODULE_PARM_DESC(bpp, "Specify bit-per-pixel if not specified in 'mode'");
1842 module_param_named(monitor, monitor_string, charp, 0);
1843 MODULE_PARM_DESC(monitor, "Specify the monitor port "
1844 "(\"dvi\", \"lvds\", or \"dlvds\") if supported by the platform");