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 pr_debug("size=%zu\n", size);
327 virt = alloc_pages_exact(size, GFP_DMA | __GFP_ZERO);
329 *phys = virt_to_phys(virt);
330 pr_debug("virt=%p phys=%llx\n", virt,
331 (unsigned long long)*phys);
338 * fsl_diu_free - release DIU memory
339 * @virt: pointer returned by fsl_diu_alloc()
340 * @size: number of bytes allocated by fsl_diu_alloc()
342 * This function releases memory allocated by fsl_diu_alloc().
344 static void fsl_diu_free(void *virt, size_t size)
346 pr_debug("virt=%p size=%zu\n", virt, size);
349 free_pages_exact(virt, size);
353 * Workaround for failed writing desc register of planes.
354 * Needed with MPC5121 DIU rev 2.0 silicon.
356 void wr_reg_wa(u32 *reg, u32 val)
360 } while (in_be32(reg) != val);
363 static int fsl_diu_enable_panel(struct fb_info *info)
365 struct mfb_info *pmfbi, *cmfbi, *mfbi = info->par;
366 struct diu *hw = dr.diu_reg;
367 struct diu_ad *ad = mfbi->ad;
368 struct fsl_diu_data *machine_data = mfbi->parent;
371 pr_debug("enable_panel index %d\n", mfbi->index);
372 if (mfbi->type != MFB_TYPE_OFF) {
373 switch (mfbi->index) {
374 case 0: /* plane 0 */
375 if (hw->desc[0] != ad->paddr)
376 wr_reg_wa(&hw->desc[0], ad->paddr);
378 case 1: /* plane 1 AOI 0 */
379 cmfbi = machine_data->fsl_diu_info[2]->par;
380 if (hw->desc[1] != ad->paddr) { /* AOI0 closed */
381 if (cmfbi->count > 0) /* AOI1 open */
383 cpu_to_le32(cmfbi->ad->paddr);
386 wr_reg_wa(&hw->desc[1], ad->paddr);
389 case 3: /* plane 2 AOI 0 */
390 cmfbi = machine_data->fsl_diu_info[4]->par;
391 if (hw->desc[2] != ad->paddr) { /* AOI0 closed */
392 if (cmfbi->count > 0) /* AOI1 open */
394 cpu_to_le32(cmfbi->ad->paddr);
397 wr_reg_wa(&hw->desc[2], ad->paddr);
400 case 2: /* plane 1 AOI 1 */
401 pmfbi = machine_data->fsl_diu_info[1]->par;
403 if (hw->desc[1] == machine_data->dummy_ad->paddr)
404 wr_reg_wa(&hw->desc[1], ad->paddr);
406 pmfbi->ad->next_ad = cpu_to_le32(ad->paddr);
408 case 4: /* plane 2 AOI 1 */
409 pmfbi = machine_data->fsl_diu_info[3]->par;
411 if (hw->desc[2] == machine_data->dummy_ad->paddr)
412 wr_reg_wa(&hw->desc[2], ad->paddr);
413 else /* AOI0 was open */
414 pmfbi->ad->next_ad = cpu_to_le32(ad->paddr);
425 static int fsl_diu_disable_panel(struct fb_info *info)
427 struct mfb_info *pmfbi, *cmfbi, *mfbi = info->par;
428 struct diu *hw = dr.diu_reg;
429 struct diu_ad *ad = mfbi->ad;
430 struct fsl_diu_data *machine_data = mfbi->parent;
433 switch (mfbi->index) {
434 case 0: /* plane 0 */
435 if (hw->desc[0] != machine_data->dummy_ad->paddr)
436 wr_reg_wa(&hw->desc[0], machine_data->dummy_ad->paddr);
438 case 1: /* plane 1 AOI 0 */
439 cmfbi = machine_data->fsl_diu_info[2]->par;
440 if (cmfbi->count > 0) /* AOI1 is open */
441 wr_reg_wa(&hw->desc[1], cmfbi->ad->paddr);
442 /* move AOI1 to the first */
443 else /* AOI1 was closed */
444 wr_reg_wa(&hw->desc[1], machine_data->dummy_ad->paddr);
447 case 3: /* plane 2 AOI 0 */
448 cmfbi = machine_data->fsl_diu_info[4]->par;
449 if (cmfbi->count > 0) /* AOI1 is open */
450 wr_reg_wa(&hw->desc[2], cmfbi->ad->paddr);
451 /* move AOI1 to the first */
452 else /* AOI1 was closed */
453 wr_reg_wa(&hw->desc[2], machine_data->dummy_ad->paddr);
456 case 2: /* plane 1 AOI 1 */
457 pmfbi = machine_data->fsl_diu_info[1]->par;
458 if (hw->desc[1] != ad->paddr) {
459 /* AOI1 is not the first in the chain */
460 if (pmfbi->count > 0)
461 /* AOI0 is open, must be the first */
462 pmfbi->ad->next_ad = 0;
463 } else /* AOI1 is the first in the chain */
464 wr_reg_wa(&hw->desc[1], machine_data->dummy_ad->paddr);
467 case 4: /* plane 2 AOI 1 */
468 pmfbi = machine_data->fsl_diu_info[3]->par;
469 if (hw->desc[2] != ad->paddr) {
470 /* AOI1 is not the first in the chain */
471 if (pmfbi->count > 0)
472 /* AOI0 is open, must be the first */
473 pmfbi->ad->next_ad = 0;
474 } else /* AOI1 is the first in the chain */
475 wr_reg_wa(&hw->desc[2], machine_data->dummy_ad->paddr);
486 static void enable_lcdc(struct fb_info *info)
488 struct diu *hw = dr.diu_reg;
489 struct mfb_info *mfbi = info->par;
490 struct fsl_diu_data *machine_data = mfbi->parent;
492 if (!machine_data->fb_enabled) {
493 out_be32(&hw->diu_mode, dr.mode);
494 machine_data->fb_enabled++;
498 static void disable_lcdc(struct fb_info *info)
500 struct diu *hw = dr.diu_reg;
501 struct mfb_info *mfbi = info->par;
502 struct fsl_diu_data *machine_data = mfbi->parent;
504 if (machine_data->fb_enabled) {
505 out_be32(&hw->diu_mode, 0);
506 machine_data->fb_enabled = 0;
510 static void adjust_aoi_size_position(struct fb_var_screeninfo *var,
511 struct fb_info *info)
513 struct mfb_info *lower_aoi_mfbi, *upper_aoi_mfbi, *mfbi = info->par;
514 struct fsl_diu_data *machine_data = mfbi->parent;
515 int available_height, upper_aoi_bottom, index = mfbi->index;
516 int lower_aoi_is_open, upper_aoi_is_open;
517 __u32 base_plane_width, base_plane_height, upper_aoi_height;
519 base_plane_width = machine_data->fsl_diu_info[0]->var.xres;
520 base_plane_height = machine_data->fsl_diu_info[0]->var.yres;
522 if (mfbi->x_aoi_d < 0)
524 if (mfbi->y_aoi_d < 0)
528 if (mfbi->x_aoi_d != 0)
530 if (mfbi->y_aoi_d != 0)
535 lower_aoi_mfbi = machine_data->fsl_diu_info[index+1]->par;
536 lower_aoi_is_open = lower_aoi_mfbi->count > 0 ? 1 : 0;
537 if (var->xres > base_plane_width)
538 var->xres = base_plane_width;
539 if ((mfbi->x_aoi_d + var->xres) > base_plane_width)
540 mfbi->x_aoi_d = base_plane_width - var->xres;
542 if (lower_aoi_is_open)
543 available_height = lower_aoi_mfbi->y_aoi_d;
545 available_height = base_plane_height;
546 if (var->yres > available_height)
547 var->yres = available_height;
548 if ((mfbi->y_aoi_d + var->yres) > available_height)
549 mfbi->y_aoi_d = available_height - var->yres;
553 upper_aoi_mfbi = machine_data->fsl_diu_info[index-1]->par;
555 machine_data->fsl_diu_info[index-1]->var.yres;
556 upper_aoi_bottom = upper_aoi_mfbi->y_aoi_d + upper_aoi_height;
557 upper_aoi_is_open = upper_aoi_mfbi->count > 0 ? 1 : 0;
558 if (var->xres > base_plane_width)
559 var->xres = base_plane_width;
560 if ((mfbi->x_aoi_d + var->xres) > base_plane_width)
561 mfbi->x_aoi_d = base_plane_width - var->xres;
562 if (mfbi->y_aoi_d < 0)
564 if (upper_aoi_is_open) {
565 if (mfbi->y_aoi_d < upper_aoi_bottom)
566 mfbi->y_aoi_d = upper_aoi_bottom;
567 available_height = base_plane_height
570 available_height = base_plane_height;
571 if (var->yres > available_height)
572 var->yres = available_height;
573 if ((mfbi->y_aoi_d + var->yres) > base_plane_height)
574 mfbi->y_aoi_d = base_plane_height - var->yres;
579 * Checks to see if the hardware supports the state requested by var passed
580 * in. This function does not alter the hardware state! If the var passed in
581 * is slightly off by what the hardware can support then we alter the var
582 * PASSED in to what we can do. If the hardware doesn't support mode change
583 * a -EINVAL will be returned by the upper layers.
585 static int fsl_diu_check_var(struct fb_var_screeninfo *var,
586 struct fb_info *info)
588 pr_debug("check_var xres: %d\n", var->xres);
589 pr_debug("check_var yres: %d\n", var->yres);
591 if (var->xres_virtual < var->xres)
592 var->xres_virtual = var->xres;
593 if (var->yres_virtual < var->yres)
594 var->yres_virtual = var->yres;
596 if (var->xoffset < 0)
599 if (var->yoffset < 0)
602 if (var->xoffset + info->var.xres > info->var.xres_virtual)
603 var->xoffset = info->var.xres_virtual - info->var.xres;
605 if (var->yoffset + info->var.yres > info->var.yres_virtual)
606 var->yoffset = info->var.yres_virtual - info->var.yres;
608 if ((var->bits_per_pixel != 32) && (var->bits_per_pixel != 24) &&
609 (var->bits_per_pixel != 16))
610 var->bits_per_pixel = default_bpp;
612 switch (var->bits_per_pixel) {
615 var->red.offset = 11;
616 var->red.msb_right = 0;
618 var->green.length = 6;
619 var->green.offset = 5;
620 var->green.msb_right = 0;
622 var->blue.length = 5;
623 var->blue.offset = 0;
624 var->blue.msb_right = 0;
626 var->transp.length = 0;
627 var->transp.offset = 0;
628 var->transp.msb_right = 0;
633 var->red.msb_right = 0;
635 var->green.length = 8;
636 var->green.offset = 8;
637 var->green.msb_right = 0;
639 var->blue.length = 8;
640 var->blue.offset = 16;
641 var->blue.msb_right = 0;
643 var->transp.length = 0;
644 var->transp.offset = 0;
645 var->transp.msb_right = 0;
649 var->red.offset = 16;
650 var->red.msb_right = 0;
652 var->green.length = 8;
653 var->green.offset = 8;
654 var->green.msb_right = 0;
656 var->blue.length = 8;
657 var->blue.offset = 0;
658 var->blue.msb_right = 0;
660 var->transp.length = 8;
661 var->transp.offset = 24;
662 var->transp.msb_right = 0;
671 /* Copy nonstd field to/from sync for fbset usage */
672 var->sync |= var->nonstd;
673 var->nonstd |= var->sync;
675 adjust_aoi_size_position(var, info);
679 static void set_fix(struct fb_info *info)
681 struct fb_fix_screeninfo *fix = &info->fix;
682 struct fb_var_screeninfo *var = &info->var;
683 struct mfb_info *mfbi = info->par;
685 strncpy(fix->id, mfbi->id, strlen(mfbi->id));
686 fix->line_length = var->xres_virtual * var->bits_per_pixel / 8;
687 fix->type = FB_TYPE_PACKED_PIXELS;
688 fix->accel = FB_ACCEL_NONE;
689 fix->visual = FB_VISUAL_TRUECOLOR;
694 static void update_lcdc(struct fb_info *info)
696 struct fb_var_screeninfo *var = &info->var;
697 struct mfb_info *mfbi = info->par;
698 struct fsl_diu_data *machine_data = mfbi->parent;
701 char __iomem *cursor_base, *gamma_table_base;
707 if (mfbi->type == MFB_TYPE_OFF) {
708 fsl_diu_disable_panel(info);
712 diu_ops.set_monitor_port(machine_data->monitor_port);
713 gamma_table_base = pool.gamma.vaddr;
714 cursor_base = pool.cursor.vaddr;
715 /* Prep for DIU init - gamma table, cursor table */
717 for (i = 0; i <= 2; i++)
718 for (j = 0; j <= 255; j++)
719 *gamma_table_base++ = j;
721 diu_ops.set_gamma_table(machine_data->monitor_port, pool.gamma.vaddr);
723 pr_debug("update-lcdc: HW - %p\n Disabling DIU\n", hw);
726 /* Program DIU registers */
728 out_be32(&hw->gamma, pool.gamma.paddr);
729 out_be32(&hw->cursor, pool.cursor.paddr);
731 out_be32(&hw->bgnd, 0x007F7F7F); /* BGND */
732 out_be32(&hw->bgnd_wb, 0); /* BGND_WB */
733 out_be32(&hw->disp_size, (var->yres << 16 | var->xres));
735 pr_debug("DIU xres: %d\n", var->xres);
736 pr_debug("DIU yres: %d\n", var->yres);
738 out_be32(&hw->wb_size, 0); /* WB SIZE */
739 out_be32(&hw->wb_mem_addr, 0); /* WB MEM ADDR */
741 /* Horizontal and vertical configuration register */
742 temp = var->left_margin << 22 | /* BP_H */
743 var->hsync_len << 11 | /* PW_H */
744 var->right_margin; /* FP_H */
746 out_be32(&hw->hsyn_para, temp);
748 temp = var->upper_margin << 22 | /* BP_V */
749 var->vsync_len << 11 | /* PW_V */
750 var->lower_margin; /* FP_V */
752 out_be32(&hw->vsyn_para, temp);
754 pr_debug("DIU right_margin - %d\n", var->right_margin);
755 pr_debug("DIU left_margin - %d\n", var->left_margin);
756 pr_debug("DIU hsync_len - %d\n", var->hsync_len);
757 pr_debug("DIU upper_margin - %d\n", var->upper_margin);
758 pr_debug("DIU lower_margin - %d\n", var->lower_margin);
759 pr_debug("DIU vsync_len - %d\n", var->vsync_len);
760 pr_debug("DIU HSYNC - 0x%08x\n", hw->hsyn_para);
761 pr_debug("DIU VSYNC - 0x%08x\n", hw->vsyn_para);
763 diu_ops.set_pixel_clock(var->pixclock);
765 out_be32(&hw->syn_pol, 0); /* SYNC SIGNALS POLARITY */
766 out_be32(&hw->thresholds, 0x00037800); /* The Thresholds */
767 out_be32(&hw->int_status, 0); /* INTERRUPT STATUS */
768 out_be32(&hw->plut, 0x01F5F666);
774 static int map_video_memory(struct fb_info *info)
777 u32 smem_len = info->fix.line_length * info->var.yres_virtual;
779 pr_debug("info->var.xres_virtual = %d\n", info->var.xres_virtual);
780 pr_debug("info->var.yres_virtual = %d\n", info->var.yres_virtual);
781 pr_debug("info->fix.line_length = %d\n", info->fix.line_length);
782 pr_debug("MAP_VIDEO_MEMORY: smem_len = %u\n", smem_len);
784 info->screen_base = fsl_diu_alloc(smem_len, &phys);
785 if (info->screen_base == NULL) {
786 printk(KERN_ERR "Unable to allocate fb memory\n");
789 mutex_lock(&info->mm_lock);
790 info->fix.smem_start = (unsigned long) phys;
791 info->fix.smem_len = smem_len;
792 mutex_unlock(&info->mm_lock);
793 info->screen_size = info->fix.smem_len;
795 pr_debug("Allocated fb @ paddr=0x%08lx, size=%d.\n",
796 info->fix.smem_start, info->fix.smem_len);
797 pr_debug("screen base %p\n", info->screen_base);
802 static void unmap_video_memory(struct fb_info *info)
804 fsl_diu_free(info->screen_base, info->fix.smem_len);
805 mutex_lock(&info->mm_lock);
806 info->screen_base = NULL;
807 info->fix.smem_start = 0;
808 info->fix.smem_len = 0;
809 mutex_unlock(&info->mm_lock);
813 * Using the fb_var_screeninfo in fb_info we set the aoi of this
814 * particular framebuffer. It is a light version of fsl_diu_set_par.
816 static int fsl_diu_set_aoi(struct fb_info *info)
818 struct fb_var_screeninfo *var = &info->var;
819 struct mfb_info *mfbi = info->par;
820 struct diu_ad *ad = mfbi->ad;
822 /* AOI should not be greater than display size */
823 ad->offset_xyi = cpu_to_le32((var->yoffset << 16) | var->xoffset);
824 ad->offset_xyd = cpu_to_le32((mfbi->y_aoi_d << 16) | mfbi->x_aoi_d);
829 * Using the fb_var_screeninfo in fb_info we set the resolution of this
830 * particular framebuffer. This function alters the fb_fix_screeninfo stored
831 * in fb_info. It does not alter var in fb_info since we are using that
832 * data. This means we depend on the data in var inside fb_info to be
833 * supported by the hardware. fsl_diu_check_var is always called before
834 * fsl_diu_set_par to ensure this.
836 static int fsl_diu_set_par(struct fb_info *info)
839 struct fb_var_screeninfo *var = &info->var;
840 struct mfb_info *mfbi = info->par;
841 struct fsl_diu_data *machine_data = mfbi->parent;
842 struct diu_ad *ad = mfbi->ad;
848 mfbi->cursor_reset = 1;
850 len = info->var.yres_virtual * info->fix.line_length;
851 /* Alloc & dealloc each time resolution/bpp change */
852 if (len != info->fix.smem_len) {
853 if (info->fix.smem_start)
854 unmap_video_memory(info);
855 pr_debug("SET PAR: smem_len = %d\n", info->fix.smem_len);
857 /* Memory allocation for framebuffer */
858 if (map_video_memory(info)) {
859 printk(KERN_ERR "Unable to allocate fb memory 1\n");
864 ad->pix_fmt = diu_ops.get_pixel_format(machine_data->monitor_port,
865 var->bits_per_pixel);
866 ad->addr = cpu_to_le32(info->fix.smem_start);
867 ad->src_size_g_alpha = cpu_to_le32((var->yres_virtual << 12) |
868 var->xres_virtual) | mfbi->g_alpha;
869 /* AOI should not be greater than display size */
870 ad->aoi_size = cpu_to_le32((var->yres << 16) | var->xres);
871 ad->offset_xyi = cpu_to_le32((var->yoffset << 16) | var->xoffset);
872 ad->offset_xyd = cpu_to_le32((mfbi->y_aoi_d << 16) | mfbi->x_aoi_d);
874 /* Disable chroma keying function */
883 if (mfbi->index == 0)
888 static inline __u32 CNVT_TOHW(__u32 val, __u32 width)
890 return ((val << width) + 0x7FFF - val) >> 16;
894 * Set a single color register. The values supplied have a 16 bit magnitude
895 * which needs to be scaled in this function for the hardware. Things to take
896 * into consideration are how many color registers, if any, are supported with
897 * the current color visual. With truecolor mode no color palettes are
898 * supported. Here a pseudo palette is created which we store the value in
899 * pseudo_palette in struct fb_info. For pseudocolor mode we have a limited
902 static int fsl_diu_setcolreg(unsigned int regno, unsigned int red,
903 unsigned int green, unsigned int blue,
904 unsigned int transp, struct fb_info *info)
909 * If greyscale is true, then we convert the RGB value
910 * to greyscale no matter what visual we are using.
912 if (info->var.grayscale)
913 red = green = blue = (19595 * red + 38470 * green +
915 switch (info->fix.visual) {
916 case FB_VISUAL_TRUECOLOR:
918 * 16-bit True Colour. We encode the RGB value
919 * according to the RGB bitfield information.
922 u32 *pal = info->pseudo_palette;
925 red = CNVT_TOHW(red, info->var.red.length);
926 green = CNVT_TOHW(green, info->var.green.length);
927 blue = CNVT_TOHW(blue, info->var.blue.length);
928 transp = CNVT_TOHW(transp, info->var.transp.length);
930 v = (red << info->var.red.offset) |
931 (green << info->var.green.offset) |
932 (blue << info->var.blue.offset) |
933 (transp << info->var.transp.offset);
939 case FB_VISUAL_STATIC_PSEUDOCOLOR:
940 case FB_VISUAL_PSEUDOCOLOR:
948 * Pan (or wrap, depending on the `vmode' field) the display using the
949 * 'xoffset' and 'yoffset' fields of the 'var' structure. If the values
950 * don't fit, return -EINVAL.
952 static int fsl_diu_pan_display(struct fb_var_screeninfo *var,
953 struct fb_info *info)
955 if ((info->var.xoffset == var->xoffset) &&
956 (info->var.yoffset == var->yoffset))
957 return 0; /* No change, do nothing */
959 if (var->xoffset < 0 || var->yoffset < 0
960 || var->xoffset + info->var.xres > info->var.xres_virtual
961 || var->yoffset + info->var.yres > info->var.yres_virtual)
964 info->var.xoffset = var->xoffset;
965 info->var.yoffset = var->yoffset;
967 if (var->vmode & FB_VMODE_YWRAP)
968 info->var.vmode |= FB_VMODE_YWRAP;
970 info->var.vmode &= ~FB_VMODE_YWRAP;
972 fsl_diu_set_aoi(info);
978 * Blank the screen if blank_mode != 0, else unblank. Return 0 if blanking
979 * succeeded, != 0 if un-/blanking failed.
980 * blank_mode == 2: suspend vsync
981 * blank_mode == 3: suspend hsync
982 * blank_mode == 4: powerdown
984 static int fsl_diu_blank(int blank_mode, struct fb_info *info)
986 struct mfb_info *mfbi = info->par;
988 mfbi->blank = blank_mode;
990 switch (blank_mode) {
991 case FB_BLANK_VSYNC_SUSPEND:
992 case FB_BLANK_HSYNC_SUSPEND:
993 /* FIXME: fixes to enable_panel and enable lcdc needed */
994 case FB_BLANK_NORMAL:
995 /* fsl_diu_disable_panel(info);*/
997 case FB_BLANK_POWERDOWN:
998 /* disable_lcdc(info); */
1000 case FB_BLANK_UNBLANK:
1001 /* fsl_diu_enable_panel(info);*/
1008 static int fsl_diu_ioctl(struct fb_info *info, unsigned int cmd,
1011 struct mfb_info *mfbi = info->par;
1012 struct diu_ad *ad = mfbi->ad;
1013 struct mfb_chroma_key ck;
1014 unsigned char global_alpha;
1015 struct aoi_display_offset aoi_d;
1017 void __user *buf = (void __user *)arg;
1022 case MFB_SET_PIXFMT:
1023 if (copy_from_user(&pix_fmt, buf, sizeof(pix_fmt)))
1025 ad->pix_fmt = pix_fmt;
1026 pr_debug("Set pixel format to 0x%08x\n", ad->pix_fmt);
1028 case MFB_GET_PIXFMT:
1029 pix_fmt = ad->pix_fmt;
1030 if (copy_to_user(buf, &pix_fmt, sizeof(pix_fmt)))
1032 pr_debug("get pixel format 0x%08x\n", ad->pix_fmt);
1035 if (copy_from_user(&aoi_d, buf, sizeof(aoi_d)))
1037 mfbi->x_aoi_d = aoi_d.x_aoi_d;
1038 mfbi->y_aoi_d = aoi_d.y_aoi_d;
1039 pr_debug("set AOI display offset of index %d to (%d,%d)\n",
1040 mfbi->index, aoi_d.x_aoi_d, aoi_d.y_aoi_d);
1041 fsl_diu_check_var(&info->var, info);
1042 fsl_diu_set_aoi(info);
1045 aoi_d.x_aoi_d = mfbi->x_aoi_d;
1046 aoi_d.y_aoi_d = mfbi->y_aoi_d;
1047 if (copy_to_user(buf, &aoi_d, sizeof(aoi_d)))
1049 pr_debug("get AOI display offset of index %d (%d,%d)\n",
1050 mfbi->index, aoi_d.x_aoi_d, aoi_d.y_aoi_d);
1053 global_alpha = mfbi->g_alpha;
1054 if (copy_to_user(buf, &global_alpha, sizeof(global_alpha)))
1056 pr_debug("get global alpha of index %d\n", mfbi->index);
1059 /* set panel information */
1060 if (copy_from_user(&global_alpha, buf, sizeof(global_alpha)))
1062 ad->src_size_g_alpha = (ad->src_size_g_alpha & (~0xff)) |
1063 (global_alpha & 0xff);
1064 mfbi->g_alpha = global_alpha;
1065 pr_debug("set global alpha for index %d\n", mfbi->index);
1067 case MFB_SET_CHROMA_KEY:
1068 /* set panel winformation */
1069 if (copy_from_user(&ck, buf, sizeof(ck)))
1073 (ck.red_max < ck.red_min ||
1074 ck.green_max < ck.green_min ||
1075 ck.blue_max < ck.blue_min))
1086 ad->ckmax_r = ck.red_max;
1087 ad->ckmax_g = ck.green_max;
1088 ad->ckmax_b = ck.blue_max;
1089 ad->ckmin_r = ck.red_min;
1090 ad->ckmin_g = ck.green_min;
1091 ad->ckmin_b = ck.blue_min;
1093 pr_debug("set chroma key\n");
1095 case FBIOGET_GWINFO:
1096 if (mfbi->type == MFB_TYPE_OFF)
1098 /* get graphic window information */
1099 if (copy_to_user(buf, ad, sizeof(*ad)))
1102 case FBIOGET_HWCINFO:
1103 pr_debug("FBIOGET_HWCINFO:0x%08x\n", FBIOGET_HWCINFO);
1105 case FBIOPUT_MODEINFO:
1106 pr_debug("FBIOPUT_MODEINFO:0x%08x\n", FBIOPUT_MODEINFO);
1108 case FBIOGET_DISPINFO:
1109 pr_debug("FBIOGET_DISPINFO:0x%08x\n", FBIOGET_DISPINFO);
1113 printk(KERN_ERR "Unknown ioctl command (0x%08X)\n", cmd);
1114 return -ENOIOCTLCMD;
1120 /* turn on fb if count == 1
1122 static int fsl_diu_open(struct fb_info *info, int user)
1124 struct mfb_info *mfbi = info->par;
1127 /* free boot splash memory on first /dev/fb0 open */
1128 if (!mfbi->index && diu_ops.release_bootmem)
1129 diu_ops.release_bootmem();
1131 spin_lock(&diu_lock);
1133 if (mfbi->count == 1) {
1134 pr_debug("open plane index %d\n", mfbi->index);
1135 fsl_diu_check_var(&info->var, info);
1136 res = fsl_diu_set_par(info);
1140 res = fsl_diu_enable_panel(info);
1146 spin_unlock(&diu_lock);
1150 /* turn off fb if count == 0
1152 static int fsl_diu_release(struct fb_info *info, int user)
1154 struct mfb_info *mfbi = info->par;
1157 spin_lock(&diu_lock);
1159 if (mfbi->count == 0) {
1160 pr_debug("release plane index %d\n", mfbi->index);
1161 res = fsl_diu_disable_panel(info);
1165 spin_unlock(&diu_lock);
1169 static struct fb_ops fsl_diu_ops = {
1170 .owner = THIS_MODULE,
1171 .fb_check_var = fsl_diu_check_var,
1172 .fb_set_par = fsl_diu_set_par,
1173 .fb_setcolreg = fsl_diu_setcolreg,
1174 .fb_blank = fsl_diu_blank,
1175 .fb_pan_display = fsl_diu_pan_display,
1176 .fb_fillrect = cfb_fillrect,
1177 .fb_copyarea = cfb_copyarea,
1178 .fb_imageblit = cfb_imageblit,
1179 .fb_ioctl = fsl_diu_ioctl,
1180 .fb_open = fsl_diu_open,
1181 .fb_release = fsl_diu_release,
1184 static int init_fbinfo(struct fb_info *info)
1186 struct mfb_info *mfbi = info->par;
1188 info->device = NULL;
1189 info->var.activate = FB_ACTIVATE_NOW;
1190 info->fbops = &fsl_diu_ops;
1191 info->flags = FBINFO_FLAG_DEFAULT;
1192 info->pseudo_palette = &mfbi->pseudo_palette;
1194 /* Allocate colormap */
1195 fb_alloc_cmap(&info->cmap, 16, 0);
1199 static int __devinit install_fb(struct fb_info *info)
1202 struct mfb_info *mfbi = info->par;
1203 const char *aoi_mode, *init_aoi_mode = "320x240";
1204 struct fb_videomode *db = fsl_diu_mode_db;
1205 unsigned int dbsize = ARRAY_SIZE(fsl_diu_mode_db);
1206 int has_default_mode = 1;
1208 if (init_fbinfo(info))
1211 if (mfbi->index == 0) { /* plane 0 */
1212 if (mfbi->edid_data) {
1213 /* Now build modedb from EDID */
1214 fb_edid_to_monspecs(mfbi->edid_data, &info->monspecs);
1215 fb_videomode_to_modelist(info->monspecs.modedb,
1216 info->monspecs.modedb_len,
1218 db = info->monspecs.modedb;
1219 dbsize = info->monspecs.modedb_len;
1223 aoi_mode = init_aoi_mode;
1225 pr_debug("mode used = %s\n", aoi_mode);
1226 rc = fb_find_mode(&info->var, info, aoi_mode, db, dbsize,
1227 &fsl_diu_default_mode, default_bpp);
1230 pr_debug("using mode specified in @mode\n");
1233 pr_debug("using mode specified in @mode "
1234 "with ignored refresh rate\n");
1237 pr_debug("using mode default mode\n");
1240 pr_debug("using mode from list\n");
1243 pr_debug("rc = %d\n", rc);
1244 pr_debug("failed to find mode\n");
1246 * For plane 0 we continue and look into
1247 * driver's internal modedb.
1249 if (mfbi->index == 0 && mfbi->edid_data)
1250 has_default_mode = 0;
1256 if (!has_default_mode) {
1257 rc = fb_find_mode(&info->var, info, aoi_mode, fsl_diu_mode_db,
1258 ARRAY_SIZE(fsl_diu_mode_db),
1259 &fsl_diu_default_mode,
1261 if (rc > 0 && rc < 5)
1262 has_default_mode = 1;
1265 /* Still not found, use preferred mode from database if any */
1266 if (!has_default_mode && info->monspecs.modedb) {
1267 struct fb_monspecs *specs = &info->monspecs;
1268 struct fb_videomode *modedb = &specs->modedb[0];
1271 * Get preferred timing. If not found,
1272 * first mode in database will be used.
1274 if (specs->misc & FB_MISC_1ST_DETAIL) {
1277 for (i = 0; i < specs->modedb_len; i++) {
1278 if (specs->modedb[i].flag & FB_MODE_IS_FIRST) {
1279 modedb = &specs->modedb[i];
1285 info->var.bits_per_pixel = default_bpp;
1286 fb_videomode_to_var(&info->var, modedb);
1289 pr_debug("xres_virtual %d\n", info->var.xres_virtual);
1290 pr_debug("bits_per_pixel %d\n", info->var.bits_per_pixel);
1292 pr_debug("info->var.yres_virtual = %d\n", info->var.yres_virtual);
1293 pr_debug("info->fix.line_length = %d\n", info->fix.line_length);
1295 if (mfbi->type == MFB_TYPE_OFF)
1296 mfbi->blank = FB_BLANK_NORMAL;
1298 mfbi->blank = FB_BLANK_UNBLANK;
1300 if (fsl_diu_check_var(&info->var, info)) {
1301 printk(KERN_ERR "fb_check_var failed");
1302 fb_dealloc_cmap(&info->cmap);
1306 if (register_framebuffer(info) < 0) {
1307 printk(KERN_ERR "register_framebuffer failed");
1308 unmap_video_memory(info);
1309 fb_dealloc_cmap(&info->cmap);
1313 mfbi->registered = 1;
1314 printk(KERN_INFO "fb%d: %s fb device registered successfully.\n",
1315 info->node, info->fix.id);
1320 static void uninstall_fb(struct fb_info *info)
1322 struct mfb_info *mfbi = info->par;
1324 if (!mfbi->registered)
1327 if (mfbi->index == 0)
1328 kfree(mfbi->edid_data);
1330 unregister_framebuffer(info);
1331 unmap_video_memory(info);
1333 fb_dealloc_cmap(&info->cmap);
1335 mfbi->registered = 0;
1338 static irqreturn_t fsl_diu_isr(int irq, void *dev_id)
1340 struct diu *hw = dr.diu_reg;
1341 unsigned int status = in_be32(&hw->int_status);
1344 /* This is the workaround for underrun */
1345 if (status & INT_UNDRUN) {
1346 out_be32(&hw->diu_mode, 0);
1347 pr_debug("Err: DIU occurs underrun!\n");
1349 out_be32(&hw->diu_mode, 1);
1351 #if defined(CONFIG_NOT_COHERENT_CACHE)
1352 else if (status & INT_VSYNC) {
1355 for (i = 0; i < coherence_data_size;
1356 i += d_cache_line_size)
1357 __asm__ __volatile__ (
1359 ::[input]"r"(&coherence_data[i]));
1367 static int request_irq_local(int irq)
1369 unsigned long status, ints;
1375 /* Read to clear the status */
1376 status = in_be32(&hw->int_status);
1378 ret = request_irq(irq, fsl_diu_isr, 0, "diu", NULL);
1380 pr_info("Request diu IRQ failed.\n");
1382 ints = INT_PARERR | INT_LS_BF_VS;
1383 #if !defined(CONFIG_NOT_COHERENT_CACHE)
1387 if (dr.mode == MFB_MODE2 || dr.mode == MFB_MODE3)
1388 ints |= INT_VSYNC_WB;
1390 /* Read to clear the status */
1391 status = in_be32(&hw->int_status);
1392 out_be32(&hw->int_mask, ints);
1398 static void free_irq_local(int irq)
1400 struct diu *hw = dr.diu_reg;
1402 /* Disable all LCDC interrupt */
1403 out_be32(&hw->int_mask, 0x1f);
1405 free_irq(irq, NULL);
1410 * Power management hooks. Note that we won't be called from IRQ context,
1411 * unlike the blank functions above, so we may sleep.
1413 static int fsl_diu_suspend(struct platform_device *ofdev, pm_message_t state)
1415 struct fsl_diu_data *machine_data;
1417 machine_data = dev_get_drvdata(&ofdev->dev);
1418 disable_lcdc(machine_data->fsl_diu_info[0]);
1423 static int fsl_diu_resume(struct platform_device *ofdev)
1425 struct fsl_diu_data *machine_data;
1427 machine_data = dev_get_drvdata(&ofdev->dev);
1428 enable_lcdc(machine_data->fsl_diu_info[0]);
1434 #define fsl_diu_suspend NULL
1435 #define fsl_diu_resume NULL
1436 #endif /* CONFIG_PM */
1438 /* Align to 64-bit(8-byte), 32-byte, etc. */
1439 static int allocate_buf(struct device *dev, struct diu_addr *buf, u32 size,
1444 dma_addr_t paddr = 0;
1446 ssize = size + bytes_align;
1447 buf->vaddr = dma_alloc_coherent(dev, ssize, &paddr, GFP_DMA |
1452 buf->paddr = (__u32) paddr;
1454 mask = bytes_align - 1;
1455 offset = (u32)buf->paddr & mask;
1457 buf->offset = bytes_align - offset;
1458 buf->paddr = (u32)buf->paddr + offset;
1465 static void free_buf(struct device *dev, struct diu_addr *buf, u32 size,
1468 dma_free_coherent(dev, size + bytes_align, buf->vaddr,
1469 buf->paddr - buf->offset);
1472 static ssize_t store_monitor(struct device *device,
1473 struct device_attribute *attr, const char *buf, size_t count)
1475 enum fsl_diu_monitor_port old_monitor_port;
1476 struct fsl_diu_data *machine_data =
1477 container_of(attr, struct fsl_diu_data, dev_attr);
1479 old_monitor_port = machine_data->monitor_port;
1480 machine_data->monitor_port = fsl_diu_name_to_port(buf);
1482 if (old_monitor_port != machine_data->monitor_port) {
1483 /* All AOIs need adjust pixel format
1484 * fsl_diu_set_par only change the pixsel format here
1485 * unlikely to fail. */
1486 fsl_diu_set_par(machine_data->fsl_diu_info[0]);
1487 fsl_diu_set_par(machine_data->fsl_diu_info[1]);
1488 fsl_diu_set_par(machine_data->fsl_diu_info[2]);
1489 fsl_diu_set_par(machine_data->fsl_diu_info[3]);
1490 fsl_diu_set_par(machine_data->fsl_diu_info[4]);
1495 static ssize_t show_monitor(struct device *device,
1496 struct device_attribute *attr, char *buf)
1498 struct fsl_diu_data *machine_data =
1499 container_of(attr, struct fsl_diu_data, dev_attr);
1501 switch (machine_data->monitor_port) {
1502 case FSL_DIU_PORT_DVI:
1503 return sprintf(buf, "DVI\n");
1504 case FSL_DIU_PORT_LVDS:
1505 return sprintf(buf, "Single-link LVDS\n");
1506 case FSL_DIU_PORT_DLVDS:
1507 return sprintf(buf, "Dual-link LVDS\n");
1513 static int __devinit fsl_diu_probe(struct platform_device *ofdev)
1515 struct device_node *np = ofdev->dev.of_node;
1516 struct mfb_info *mfbi;
1517 phys_addr_t dummy_ad_addr;
1518 int ret, i, error = 0;
1519 struct resource res;
1520 struct fsl_diu_data *machine_data;
1523 machine_data = kzalloc(sizeof(struct fsl_diu_data), GFP_KERNEL);
1527 for (i = 0; i < ARRAY_SIZE(machine_data->fsl_diu_info); i++) {
1528 machine_data->fsl_diu_info[i] =
1529 framebuffer_alloc(sizeof(struct mfb_info), &ofdev->dev);
1530 if (!machine_data->fsl_diu_info[i]) {
1531 dev_err(&ofdev->dev, "cannot allocate memory\n");
1535 mfbi = machine_data->fsl_diu_info[i]->par;
1536 memcpy(mfbi, &mfb_template[i], sizeof(struct mfb_info));
1537 mfbi->parent = machine_data;
1539 if (mfbi->index == 0) {
1544 prop = of_get_property(np, "edid", &len);
1545 if (prop && len == EDID_LENGTH)
1546 mfbi->edid_data = kmemdup(prop, EDID_LENGTH,
1551 ret = of_address_to_resource(np, 0, &res);
1553 dev_err(&ofdev->dev, "could not obtain DIU address\n");
1557 dev_err(&ofdev->dev, "invalid DIU address\n");
1560 dev_dbg(&ofdev->dev, "%s, res.start: 0x%08x\n", __func__, res.start);
1562 dr.diu_reg = ioremap(res.start, sizeof(struct diu));
1564 dev_err(&ofdev->dev, "Err: can't map DIU registers!\n");
1569 diu_mode = in_be32(&dr.diu_reg->diu_mode);
1570 if (diu_mode != MFB_MODE1)
1571 out_be32(&dr.diu_reg->diu_mode, 0); /* disable DIU */
1573 /* Get the IRQ of the DIU */
1574 machine_data->irq = irq_of_parse_and_map(np, 0);
1576 if (!machine_data->irq) {
1577 dev_err(&ofdev->dev, "could not get DIU IRQ\n");
1581 machine_data->monitor_port = monitor_port;
1583 /* Area descriptor memory pool aligns to 64-bit boundary */
1584 if (allocate_buf(&ofdev->dev, &pool.ad,
1585 sizeof(struct diu_ad) * FSL_AOI_NUM, 8))
1588 /* Get memory for Gamma Table - 32-byte aligned memory */
1589 if (allocate_buf(&ofdev->dev, &pool.gamma, 768, 32)) {
1594 /* For performance, cursor bitmap buffer aligns to 32-byte boundary */
1595 if (allocate_buf(&ofdev->dev, &pool.cursor, MAX_CURS * MAX_CURS * 2,
1601 i = ARRAY_SIZE(machine_data->fsl_diu_info);
1602 machine_data->dummy_ad = (struct diu_ad *)
1603 ((u32)pool.ad.vaddr + pool.ad.offset) + i;
1604 machine_data->dummy_ad->paddr = pool.ad.paddr +
1605 i * sizeof(struct diu_ad);
1606 machine_data->dummy_aoi_virt = fsl_diu_alloc(64, &dummy_ad_addr);
1607 if (!machine_data->dummy_aoi_virt) {
1611 machine_data->dummy_ad->addr = cpu_to_le32(dummy_ad_addr);
1612 machine_data->dummy_ad->pix_fmt = 0x88882317;
1613 machine_data->dummy_ad->src_size_g_alpha = cpu_to_le32((4 << 12) | 4);
1614 machine_data->dummy_ad->aoi_size = cpu_to_le32((4 << 16) | 2);
1615 machine_data->dummy_ad->offset_xyi = 0;
1616 machine_data->dummy_ad->offset_xyd = 0;
1617 machine_data->dummy_ad->next_ad = 0;
1620 * Let DIU display splash screen if it was pre-initialized
1621 * by the bootloader, set dummy area descriptor otherwise.
1623 if (diu_mode != MFB_MODE1)
1624 out_be32(&dr.diu_reg->desc[0], machine_data->dummy_ad->paddr);
1626 out_be32(&dr.diu_reg->desc[1], machine_data->dummy_ad->paddr);
1627 out_be32(&dr.diu_reg->desc[2], machine_data->dummy_ad->paddr);
1629 for (i = 0; i < ARRAY_SIZE(machine_data->fsl_diu_info); i++) {
1630 machine_data->fsl_diu_info[i]->fix.smem_start = 0;
1631 mfbi = machine_data->fsl_diu_info[i]->par;
1632 mfbi->ad = (struct diu_ad *)((u32)pool.ad.vaddr
1633 + pool.ad.offset) + i;
1634 mfbi->ad->paddr = pool.ad.paddr + i * sizeof(struct diu_ad);
1635 ret = install_fb(machine_data->fsl_diu_info[i]);
1637 dev_err(&ofdev->dev,
1638 "Failed to register framebuffer %d\n",
1644 if (request_irq_local(machine_data->irq)) {
1645 dev_err(machine_data->fsl_diu_info[0]->dev,
1646 "could not request irq for diu.");
1650 sysfs_attr_init(&machine_data->dev_attr.attr);
1651 machine_data->dev_attr.attr.name = "monitor";
1652 machine_data->dev_attr.attr.mode = S_IRUGO|S_IWUSR;
1653 machine_data->dev_attr.show = show_monitor;
1654 machine_data->dev_attr.store = store_monitor;
1655 error = device_create_file(machine_data->fsl_diu_info[0]->dev,
1656 &machine_data->dev_attr);
1658 dev_err(machine_data->fsl_diu_info[0]->dev,
1659 "could not create sysfs %s file\n",
1660 machine_data->dev_attr.attr.name);
1663 dev_set_drvdata(&ofdev->dev, machine_data);
1667 for (i = ARRAY_SIZE(machine_data->fsl_diu_info);
1669 uninstall_fb(machine_data->fsl_diu_info[i - 1]);
1671 free_buf(&ofdev->dev, &pool.ad,
1672 sizeof(struct diu_ad) * FSL_AOI_NUM, 8);
1673 if (pool.gamma.vaddr)
1674 free_buf(&ofdev->dev, &pool.gamma, 768, 32);
1675 if (pool.cursor.vaddr)
1676 free_buf(&ofdev->dev, &pool.cursor, MAX_CURS * MAX_CURS * 2,
1678 if (machine_data->dummy_aoi_virt)
1679 fsl_diu_free(machine_data->dummy_aoi_virt, 64);
1680 iounmap(dr.diu_reg);
1683 for (i = 0; i < ARRAY_SIZE(machine_data->fsl_diu_info); i++)
1684 if (machine_data->fsl_diu_info[i])
1685 framebuffer_release(machine_data->fsl_diu_info[i]);
1686 kfree(machine_data);
1692 static int fsl_diu_remove(struct platform_device *ofdev)
1694 struct fsl_diu_data *machine_data;
1697 machine_data = dev_get_drvdata(&ofdev->dev);
1698 disable_lcdc(machine_data->fsl_diu_info[0]);
1699 free_irq_local(machine_data->irq);
1700 for (i = ARRAY_SIZE(machine_data->fsl_diu_info); i > 0; i--)
1701 uninstall_fb(machine_data->fsl_diu_info[i - 1]);
1703 free_buf(&ofdev->dev, &pool.ad,
1704 sizeof(struct diu_ad) * FSL_AOI_NUM, 8);
1705 if (pool.gamma.vaddr)
1706 free_buf(&ofdev->dev, &pool.gamma, 768, 32);
1707 if (pool.cursor.vaddr)
1708 free_buf(&ofdev->dev, &pool.cursor, MAX_CURS * MAX_CURS * 2,
1710 if (machine_data->dummy_aoi_virt)
1711 fsl_diu_free(machine_data->dummy_aoi_virt, 64);
1712 iounmap(dr.diu_reg);
1713 for (i = 0; i < ARRAY_SIZE(machine_data->fsl_diu_info); i++)
1714 if (machine_data->fsl_diu_info[i])
1715 framebuffer_release(machine_data->fsl_diu_info[i]);
1716 kfree(machine_data);
1722 static int __init fsl_diu_setup(char *options)
1727 if (!options || !*options)
1730 while ((opt = strsep(&options, ",")) != NULL) {
1733 if (!strncmp(opt, "monitor=", 8)) {
1734 monitor_port = fsl_diu_name_to_port(opt + 8);
1735 } else if (!strncmp(opt, "bpp=", 4)) {
1736 if (!strict_strtoul(opt + 4, 10, &val))
1746 static struct of_device_id fsl_diu_match[] = {
1747 #ifdef CONFIG_PPC_MPC512x
1749 .compatible = "fsl,mpc5121-diu",
1753 .compatible = "fsl,diu",
1757 MODULE_DEVICE_TABLE(of, fsl_diu_match);
1759 static struct platform_driver fsl_diu_driver = {
1762 .owner = THIS_MODULE,
1763 .of_match_table = fsl_diu_match,
1765 .probe = fsl_diu_probe,
1766 .remove = fsl_diu_remove,
1767 .suspend = fsl_diu_suspend,
1768 .resume = fsl_diu_resume,
1771 static int __init fsl_diu_init(void)
1773 #ifdef CONFIG_NOT_COHERENT_CACHE
1774 struct device_node *np;
1782 * For kernel boot options (in 'video=xxxfb:<options>' format)
1784 if (fb_get_options("fslfb", &option))
1786 fsl_diu_setup(option);
1788 monitor_port = fsl_diu_name_to_port(monitor_string);
1790 printk(KERN_INFO "Freescale DIU driver\n");
1792 #ifdef CONFIG_NOT_COHERENT_CACHE
1793 np = of_find_node_by_type(NULL, "cpu");
1795 printk(KERN_ERR "Err: can't find device node 'cpu'\n");
1799 prop = of_get_property(np, "d-cache-size", NULL);
1806 * Freescale PLRU requires 13/8 times the cache size to do a proper
1807 * displacement flush
1809 coherence_data_size = *prop * 13;
1810 coherence_data_size /= 8;
1812 prop = of_get_property(np, "d-cache-line-size", NULL);
1817 d_cache_line_size = *prop;
1820 coherence_data = vmalloc(coherence_data_size);
1821 if (!coherence_data)
1825 ret = platform_driver_register(&fsl_diu_driver);
1828 "fsl-diu: failed to register platform driver\n");
1829 #if defined(CONFIG_NOT_COHERENT_CACHE)
1830 vfree(coherence_data);
1832 iounmap(dr.diu_reg);
1837 static void __exit fsl_diu_exit(void)
1839 platform_driver_unregister(&fsl_diu_driver);
1840 #if defined(CONFIG_NOT_COHERENT_CACHE)
1841 vfree(coherence_data);
1845 module_init(fsl_diu_init);
1846 module_exit(fsl_diu_exit);
1848 MODULE_AUTHOR("York Sun <yorksun@freescale.com>");
1849 MODULE_DESCRIPTION("Freescale DIU framebuffer driver");
1850 MODULE_LICENSE("GPL");
1852 module_param_named(mode, fb_mode, charp, 0);
1853 MODULE_PARM_DESC(mode,
1854 "Specify resolution as \"<xres>x<yres>[-<bpp>][@<refresh>]\" ");
1855 module_param_named(bpp, default_bpp, ulong, 0);
1856 MODULE_PARM_DESC(bpp, "Specify bit-per-pixel if not specified mode");
1857 module_param_named(monitor, monitor_string, charp, 0);
1858 MODULE_PARM_DESC(monitor, "Specify the monitor port "
1859 "(\"dvi\", \"lvds\", or \"dlvds\") if supported by the platform");