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 regno, unsigned red, unsigned green,
903 unsigned blue, unsigned transp, struct fb_info *info)
908 * If greyscale is true, then we convert the RGB value
909 * to greyscale no matter what visual we are using.
911 if (info->var.grayscale)
912 red = green = blue = (19595 * red + 38470 * green +
914 switch (info->fix.visual) {
915 case FB_VISUAL_TRUECOLOR:
917 * 16-bit True Colour. We encode the RGB value
918 * according to the RGB bitfield information.
921 u32 *pal = info->pseudo_palette;
924 red = CNVT_TOHW(red, info->var.red.length);
925 green = CNVT_TOHW(green, info->var.green.length);
926 blue = CNVT_TOHW(blue, info->var.blue.length);
927 transp = CNVT_TOHW(transp, info->var.transp.length);
929 v = (red << info->var.red.offset) |
930 (green << info->var.green.offset) |
931 (blue << info->var.blue.offset) |
932 (transp << info->var.transp.offset);
938 case FB_VISUAL_STATIC_PSEUDOCOLOR:
939 case FB_VISUAL_PSEUDOCOLOR:
947 * Pan (or wrap, depending on the `vmode' field) the display using the
948 * 'xoffset' and 'yoffset' fields of the 'var' structure. If the values
949 * don't fit, return -EINVAL.
951 static int fsl_diu_pan_display(struct fb_var_screeninfo *var,
952 struct fb_info *info)
954 if ((info->var.xoffset == var->xoffset) &&
955 (info->var.yoffset == var->yoffset))
956 return 0; /* No change, do nothing */
958 if (var->xoffset < 0 || var->yoffset < 0
959 || var->xoffset + info->var.xres > info->var.xres_virtual
960 || var->yoffset + info->var.yres > info->var.yres_virtual)
963 info->var.xoffset = var->xoffset;
964 info->var.yoffset = var->yoffset;
966 if (var->vmode & FB_VMODE_YWRAP)
967 info->var.vmode |= FB_VMODE_YWRAP;
969 info->var.vmode &= ~FB_VMODE_YWRAP;
971 fsl_diu_set_aoi(info);
977 * Blank the screen if blank_mode != 0, else unblank. Return 0 if blanking
978 * succeeded, != 0 if un-/blanking failed.
979 * blank_mode == 2: suspend vsync
980 * blank_mode == 3: suspend hsync
981 * blank_mode == 4: powerdown
983 static int fsl_diu_blank(int blank_mode, struct fb_info *info)
985 struct mfb_info *mfbi = info->par;
987 mfbi->blank = blank_mode;
989 switch (blank_mode) {
990 case FB_BLANK_VSYNC_SUSPEND:
991 case FB_BLANK_HSYNC_SUSPEND:
992 /* FIXME: fixes to enable_panel and enable lcdc needed */
993 case FB_BLANK_NORMAL:
994 /* fsl_diu_disable_panel(info);*/
996 case FB_BLANK_POWERDOWN:
997 /* disable_lcdc(info); */
999 case FB_BLANK_UNBLANK:
1000 /* fsl_diu_enable_panel(info);*/
1007 static int fsl_diu_ioctl(struct fb_info *info, unsigned int cmd,
1010 struct mfb_info *mfbi = info->par;
1011 struct diu_ad *ad = mfbi->ad;
1012 struct mfb_chroma_key ck;
1013 unsigned char global_alpha;
1014 struct aoi_display_offset aoi_d;
1016 void __user *buf = (void __user *)arg;
1021 case MFB_SET_PIXFMT:
1022 if (copy_from_user(&pix_fmt, buf, sizeof(pix_fmt)))
1024 ad->pix_fmt = pix_fmt;
1025 pr_debug("Set pixel format to 0x%08x\n", ad->pix_fmt);
1027 case MFB_GET_PIXFMT:
1028 pix_fmt = ad->pix_fmt;
1029 if (copy_to_user(buf, &pix_fmt, sizeof(pix_fmt)))
1031 pr_debug("get pixel format 0x%08x\n", ad->pix_fmt);
1034 if (copy_from_user(&aoi_d, buf, sizeof(aoi_d)))
1036 mfbi->x_aoi_d = aoi_d.x_aoi_d;
1037 mfbi->y_aoi_d = aoi_d.y_aoi_d;
1038 pr_debug("set AOI display offset of index %d to (%d,%d)\n",
1039 mfbi->index, aoi_d.x_aoi_d, aoi_d.y_aoi_d);
1040 fsl_diu_check_var(&info->var, info);
1041 fsl_diu_set_aoi(info);
1044 aoi_d.x_aoi_d = mfbi->x_aoi_d;
1045 aoi_d.y_aoi_d = mfbi->y_aoi_d;
1046 if (copy_to_user(buf, &aoi_d, sizeof(aoi_d)))
1048 pr_debug("get AOI display offset of index %d (%d,%d)\n",
1049 mfbi->index, aoi_d.x_aoi_d, aoi_d.y_aoi_d);
1052 global_alpha = mfbi->g_alpha;
1053 if (copy_to_user(buf, &global_alpha, sizeof(global_alpha)))
1055 pr_debug("get global alpha of index %d\n", mfbi->index);
1058 /* set panel information */
1059 if (copy_from_user(&global_alpha, buf, sizeof(global_alpha)))
1061 ad->src_size_g_alpha = (ad->src_size_g_alpha & (~0xff)) |
1062 (global_alpha & 0xff);
1063 mfbi->g_alpha = global_alpha;
1064 pr_debug("set global alpha for index %d\n", mfbi->index);
1066 case MFB_SET_CHROMA_KEY:
1067 /* set panel winformation */
1068 if (copy_from_user(&ck, buf, sizeof(ck)))
1072 (ck.red_max < ck.red_min ||
1073 ck.green_max < ck.green_min ||
1074 ck.blue_max < ck.blue_min))
1085 ad->ckmax_r = ck.red_max;
1086 ad->ckmax_g = ck.green_max;
1087 ad->ckmax_b = ck.blue_max;
1088 ad->ckmin_r = ck.red_min;
1089 ad->ckmin_g = ck.green_min;
1090 ad->ckmin_b = ck.blue_min;
1092 pr_debug("set chroma key\n");
1094 case FBIOGET_GWINFO:
1095 if (mfbi->type == MFB_TYPE_OFF)
1097 /* get graphic window information */
1098 if (copy_to_user(buf, ad, sizeof(*ad)))
1101 case FBIOGET_HWCINFO:
1102 pr_debug("FBIOGET_HWCINFO:0x%08x\n", FBIOGET_HWCINFO);
1104 case FBIOPUT_MODEINFO:
1105 pr_debug("FBIOPUT_MODEINFO:0x%08x\n", FBIOPUT_MODEINFO);
1107 case FBIOGET_DISPINFO:
1108 pr_debug("FBIOGET_DISPINFO:0x%08x\n", FBIOGET_DISPINFO);
1112 printk(KERN_ERR "Unknown ioctl command (0x%08X)\n", cmd);
1113 return -ENOIOCTLCMD;
1119 /* turn on fb if count == 1
1121 static int fsl_diu_open(struct fb_info *info, int user)
1123 struct mfb_info *mfbi = info->par;
1126 /* free boot splash memory on first /dev/fb0 open */
1127 if (!mfbi->index && diu_ops.release_bootmem)
1128 diu_ops.release_bootmem();
1130 spin_lock(&diu_lock);
1132 if (mfbi->count == 1) {
1133 pr_debug("open plane index %d\n", mfbi->index);
1134 fsl_diu_check_var(&info->var, info);
1135 res = fsl_diu_set_par(info);
1139 res = fsl_diu_enable_panel(info);
1145 spin_unlock(&diu_lock);
1149 /* turn off fb if count == 0
1151 static int fsl_diu_release(struct fb_info *info, int user)
1153 struct mfb_info *mfbi = info->par;
1156 spin_lock(&diu_lock);
1158 if (mfbi->count == 0) {
1159 pr_debug("release plane index %d\n", mfbi->index);
1160 res = fsl_diu_disable_panel(info);
1164 spin_unlock(&diu_lock);
1168 static struct fb_ops fsl_diu_ops = {
1169 .owner = THIS_MODULE,
1170 .fb_check_var = fsl_diu_check_var,
1171 .fb_set_par = fsl_diu_set_par,
1172 .fb_setcolreg = fsl_diu_setcolreg,
1173 .fb_blank = fsl_diu_blank,
1174 .fb_pan_display = fsl_diu_pan_display,
1175 .fb_fillrect = cfb_fillrect,
1176 .fb_copyarea = cfb_copyarea,
1177 .fb_imageblit = cfb_imageblit,
1178 .fb_ioctl = fsl_diu_ioctl,
1179 .fb_open = fsl_diu_open,
1180 .fb_release = fsl_diu_release,
1183 static int init_fbinfo(struct fb_info *info)
1185 struct mfb_info *mfbi = info->par;
1187 info->device = NULL;
1188 info->var.activate = FB_ACTIVATE_NOW;
1189 info->fbops = &fsl_diu_ops;
1190 info->flags = FBINFO_FLAG_DEFAULT;
1191 info->pseudo_palette = &mfbi->pseudo_palette;
1193 /* Allocate colormap */
1194 fb_alloc_cmap(&info->cmap, 16, 0);
1198 static int __devinit install_fb(struct fb_info *info)
1201 struct mfb_info *mfbi = info->par;
1202 const char *aoi_mode, *init_aoi_mode = "320x240";
1203 struct fb_videomode *db = fsl_diu_mode_db;
1204 unsigned int dbsize = ARRAY_SIZE(fsl_diu_mode_db);
1205 int has_default_mode = 1;
1207 if (init_fbinfo(info))
1210 if (mfbi->index == 0) { /* plane 0 */
1211 if (mfbi->edid_data) {
1212 /* Now build modedb from EDID */
1213 fb_edid_to_monspecs(mfbi->edid_data, &info->monspecs);
1214 fb_videomode_to_modelist(info->monspecs.modedb,
1215 info->monspecs.modedb_len,
1217 db = info->monspecs.modedb;
1218 dbsize = info->monspecs.modedb_len;
1222 aoi_mode = init_aoi_mode;
1224 pr_debug("mode used = %s\n", aoi_mode);
1225 rc = fb_find_mode(&info->var, info, aoi_mode, db, dbsize,
1226 &fsl_diu_default_mode, default_bpp);
1229 pr_debug("using mode specified in @mode\n");
1232 pr_debug("using mode specified in @mode "
1233 "with ignored refresh rate\n");
1236 pr_debug("using mode default mode\n");
1239 pr_debug("using mode from list\n");
1242 pr_debug("rc = %d\n", rc);
1243 pr_debug("failed to find mode\n");
1245 * For plane 0 we continue and look into
1246 * driver's internal modedb.
1248 if (mfbi->index == 0 && mfbi->edid_data)
1249 has_default_mode = 0;
1255 if (!has_default_mode) {
1256 rc = fb_find_mode(&info->var, info, aoi_mode, fsl_diu_mode_db,
1257 ARRAY_SIZE(fsl_diu_mode_db),
1258 &fsl_diu_default_mode,
1260 if (rc > 0 && rc < 5)
1261 has_default_mode = 1;
1264 /* Still not found, use preferred mode from database if any */
1265 if (!has_default_mode && info->monspecs.modedb) {
1266 struct fb_monspecs *specs = &info->monspecs;
1267 struct fb_videomode *modedb = &specs->modedb[0];
1270 * Get preferred timing. If not found,
1271 * first mode in database will be used.
1273 if (specs->misc & FB_MISC_1ST_DETAIL) {
1276 for (i = 0; i < specs->modedb_len; i++) {
1277 if (specs->modedb[i].flag & FB_MODE_IS_FIRST) {
1278 modedb = &specs->modedb[i];
1284 info->var.bits_per_pixel = default_bpp;
1285 fb_videomode_to_var(&info->var, modedb);
1288 pr_debug("xres_virtual %d\n", info->var.xres_virtual);
1289 pr_debug("bits_per_pixel %d\n", info->var.bits_per_pixel);
1291 pr_debug("info->var.yres_virtual = %d\n", info->var.yres_virtual);
1292 pr_debug("info->fix.line_length = %d\n", info->fix.line_length);
1294 if (mfbi->type == MFB_TYPE_OFF)
1295 mfbi->blank = FB_BLANK_NORMAL;
1297 mfbi->blank = FB_BLANK_UNBLANK;
1299 if (fsl_diu_check_var(&info->var, info)) {
1300 printk(KERN_ERR "fb_check_var failed");
1301 fb_dealloc_cmap(&info->cmap);
1305 if (register_framebuffer(info) < 0) {
1306 printk(KERN_ERR "register_framebuffer failed");
1307 unmap_video_memory(info);
1308 fb_dealloc_cmap(&info->cmap);
1312 mfbi->registered = 1;
1313 printk(KERN_INFO "fb%d: %s fb device registered successfully.\n",
1314 info->node, info->fix.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 == 0)
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 *hw = dr.diu_reg;
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);
1346 pr_debug("Err: DIU occurs underrun!\n");
1348 out_be32(&hw->diu_mode, 1);
1350 #if defined(CONFIG_NOT_COHERENT_CACHE)
1351 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(int irq)
1367 unsigned long status, ints;
1373 /* Read to clear the status */
1374 status = in_be32(&hw->int_status);
1376 ret = request_irq(irq, fsl_diu_isr, 0, "diu", NULL);
1378 pr_info("Request diu IRQ failed.\n");
1380 ints = INT_PARERR | INT_LS_BF_VS;
1381 #if !defined(CONFIG_NOT_COHERENT_CACHE)
1384 if (dr.mode == MFB_MODE2 || dr.mode == MFB_MODE3)
1385 ints |= INT_VSYNC_WB;
1387 /* Read to clear the status */
1388 status = in_be32(&hw->int_status);
1389 out_be32(&hw->int_mask, ints);
1394 static void free_irq_local(int irq)
1396 struct diu *hw = dr.diu_reg;
1398 /* Disable all LCDC interrupt */
1399 out_be32(&hw->int_mask, 0x1f);
1401 free_irq(irq, NULL);
1406 * Power management hooks. Note that we won't be called from IRQ context,
1407 * unlike the blank functions above, so we may sleep.
1409 static int fsl_diu_suspend(struct platform_device *ofdev, pm_message_t state)
1411 struct fsl_diu_data *machine_data;
1413 machine_data = dev_get_drvdata(&ofdev->dev);
1414 disable_lcdc(machine_data->fsl_diu_info[0]);
1419 static int fsl_diu_resume(struct platform_device *ofdev)
1421 struct fsl_diu_data *machine_data;
1423 machine_data = dev_get_drvdata(&ofdev->dev);
1424 enable_lcdc(machine_data->fsl_diu_info[0]);
1430 #define fsl_diu_suspend NULL
1431 #define fsl_diu_resume NULL
1432 #endif /* CONFIG_PM */
1434 /* Align to 64-bit(8-byte), 32-byte, etc. */
1435 static int allocate_buf(struct device *dev, struct diu_addr *buf, u32 size,
1440 dma_addr_t paddr = 0;
1442 ssize = size + bytes_align;
1443 buf->vaddr = dma_alloc_coherent(dev, ssize, &paddr, GFP_DMA |
1448 buf->paddr = (__u32) paddr;
1450 mask = bytes_align - 1;
1451 offset = (u32)buf->paddr & mask;
1453 buf->offset = bytes_align - offset;
1454 buf->paddr = (u32)buf->paddr + offset;
1460 static void free_buf(struct device *dev, struct diu_addr *buf, u32 size,
1463 dma_free_coherent(dev, size + bytes_align,
1464 buf->vaddr, (buf->paddr - buf->offset));
1468 static ssize_t store_monitor(struct device *device,
1469 struct device_attribute *attr, const char *buf, size_t count)
1471 enum fsl_diu_monitor_port old_monitor_port;
1472 struct fsl_diu_data *machine_data =
1473 container_of(attr, struct fsl_diu_data, dev_attr);
1475 old_monitor_port = machine_data->monitor_port;
1476 machine_data->monitor_port = fsl_diu_name_to_port(buf);
1478 if (old_monitor_port != machine_data->monitor_port) {
1479 /* All AOIs need adjust pixel format
1480 * fsl_diu_set_par only change the pixsel format here
1481 * unlikely to fail. */
1482 fsl_diu_set_par(machine_data->fsl_diu_info[0]);
1483 fsl_diu_set_par(machine_data->fsl_diu_info[1]);
1484 fsl_diu_set_par(machine_data->fsl_diu_info[2]);
1485 fsl_diu_set_par(machine_data->fsl_diu_info[3]);
1486 fsl_diu_set_par(machine_data->fsl_diu_info[4]);
1491 static ssize_t show_monitor(struct device *device,
1492 struct device_attribute *attr, char *buf)
1494 struct fsl_diu_data *machine_data =
1495 container_of(attr, struct fsl_diu_data, dev_attr);
1497 switch (machine_data->monitor_port) {
1498 case FSL_DIU_PORT_DVI:
1499 return sprintf(buf, "DVI\n");
1500 case FSL_DIU_PORT_LVDS:
1501 return sprintf(buf, "Single-link LVDS\n");
1502 case FSL_DIU_PORT_DLVDS:
1503 return sprintf(buf, "Dual-link LVDS\n");
1509 static int __devinit fsl_diu_probe(struct platform_device *ofdev)
1511 struct device_node *np = ofdev->dev.of_node;
1512 struct mfb_info *mfbi;
1513 phys_addr_t dummy_ad_addr;
1514 int ret, i, error = 0;
1515 struct resource res;
1516 struct fsl_diu_data *machine_data;
1519 machine_data = kzalloc(sizeof(struct fsl_diu_data), GFP_KERNEL);
1523 for (i = 0; i < ARRAY_SIZE(machine_data->fsl_diu_info); i++) {
1524 machine_data->fsl_diu_info[i] =
1525 framebuffer_alloc(sizeof(struct mfb_info), &ofdev->dev);
1526 if (!machine_data->fsl_diu_info[i]) {
1527 dev_err(&ofdev->dev, "cannot allocate memory\n");
1531 mfbi = machine_data->fsl_diu_info[i]->par;
1532 memcpy(mfbi, &mfb_template[i], sizeof(struct mfb_info));
1533 mfbi->parent = machine_data;
1535 if (mfbi->index == 0) {
1540 prop = of_get_property(np, "edid", &len);
1541 if (prop && len == EDID_LENGTH)
1542 mfbi->edid_data = kmemdup(prop, EDID_LENGTH,
1547 ret = of_address_to_resource(np, 0, &res);
1549 dev_err(&ofdev->dev, "could not obtain DIU address\n");
1553 dev_err(&ofdev->dev, "invalid DIU address\n");
1556 dev_dbg(&ofdev->dev, "%s, res.start: 0x%08x\n", __func__, res.start);
1558 dr.diu_reg = ioremap(res.start, sizeof(struct diu));
1560 dev_err(&ofdev->dev, "Err: can't map DIU registers!\n");
1565 diu_mode = in_be32(&dr.diu_reg->diu_mode);
1566 if (diu_mode != MFB_MODE1)
1567 out_be32(&dr.diu_reg->diu_mode, 0); /* disable DIU */
1569 /* Get the IRQ of the DIU */
1570 machine_data->irq = irq_of_parse_and_map(np, 0);
1572 if (!machine_data->irq) {
1573 dev_err(&ofdev->dev, "could not get DIU IRQ\n");
1577 machine_data->monitor_port = monitor_port;
1579 /* Area descriptor memory pool aligns to 64-bit boundary */
1580 if (allocate_buf(&ofdev->dev, &pool.ad,
1581 sizeof(struct diu_ad) * FSL_AOI_NUM, 8))
1584 /* Get memory for Gamma Table - 32-byte aligned memory */
1585 if (allocate_buf(&ofdev->dev, &pool.gamma, 768, 32)) {
1590 /* For performance, cursor bitmap buffer aligns to 32-byte boundary */
1591 if (allocate_buf(&ofdev->dev, &pool.cursor, MAX_CURS * MAX_CURS * 2,
1597 i = ARRAY_SIZE(machine_data->fsl_diu_info);
1598 machine_data->dummy_ad = (struct diu_ad *)
1599 ((u32)pool.ad.vaddr + pool.ad.offset) + i;
1600 machine_data->dummy_ad->paddr = pool.ad.paddr +
1601 i * sizeof(struct diu_ad);
1602 machine_data->dummy_aoi_virt = fsl_diu_alloc(64, &dummy_ad_addr);
1603 if (!machine_data->dummy_aoi_virt) {
1607 machine_data->dummy_ad->addr = cpu_to_le32(dummy_ad_addr);
1608 machine_data->dummy_ad->pix_fmt = 0x88882317;
1609 machine_data->dummy_ad->src_size_g_alpha = cpu_to_le32((4 << 12) | 4);
1610 machine_data->dummy_ad->aoi_size = cpu_to_le32((4 << 16) | 2);
1611 machine_data->dummy_ad->offset_xyi = 0;
1612 machine_data->dummy_ad->offset_xyd = 0;
1613 machine_data->dummy_ad->next_ad = 0;
1616 * Let DIU display splash screen if it was pre-initialized
1617 * by the bootloader, set dummy area descriptor otherwise.
1619 if (diu_mode != MFB_MODE1)
1620 out_be32(&dr.diu_reg->desc[0], machine_data->dummy_ad->paddr);
1622 out_be32(&dr.diu_reg->desc[1], machine_data->dummy_ad->paddr);
1623 out_be32(&dr.diu_reg->desc[2], machine_data->dummy_ad->paddr);
1625 for (i = 0; i < ARRAY_SIZE(machine_data->fsl_diu_info); i++) {
1626 machine_data->fsl_diu_info[i]->fix.smem_start = 0;
1627 mfbi = machine_data->fsl_diu_info[i]->par;
1628 mfbi->ad = (struct diu_ad *)((u32)pool.ad.vaddr
1629 + pool.ad.offset) + i;
1630 mfbi->ad->paddr = pool.ad.paddr + i * sizeof(struct diu_ad);
1631 ret = install_fb(machine_data->fsl_diu_info[i]);
1633 dev_err(&ofdev->dev,
1634 "Failed to register framebuffer %d\n",
1640 if (request_irq_local(machine_data->irq)) {
1641 dev_err(machine_data->fsl_diu_info[0]->dev,
1642 "could not request irq for diu.");
1646 sysfs_attr_init(&machine_data->dev_attr.attr);
1647 machine_data->dev_attr.attr.name = "monitor";
1648 machine_data->dev_attr.attr.mode = S_IRUGO|S_IWUSR;
1649 machine_data->dev_attr.show = show_monitor;
1650 machine_data->dev_attr.store = store_monitor;
1651 error = device_create_file(machine_data->fsl_diu_info[0]->dev,
1652 &machine_data->dev_attr);
1654 dev_err(machine_data->fsl_diu_info[0]->dev,
1655 "could not create sysfs %s file\n",
1656 machine_data->dev_attr.attr.name);
1659 dev_set_drvdata(&ofdev->dev, machine_data);
1663 for (i = ARRAY_SIZE(machine_data->fsl_diu_info);
1665 uninstall_fb(machine_data->fsl_diu_info[i - 1]);
1667 free_buf(&ofdev->dev, &pool.ad,
1668 sizeof(struct diu_ad) * FSL_AOI_NUM, 8);
1669 if (pool.gamma.vaddr)
1670 free_buf(&ofdev->dev, &pool.gamma, 768, 32);
1671 if (pool.cursor.vaddr)
1672 free_buf(&ofdev->dev, &pool.cursor, MAX_CURS * MAX_CURS * 2,
1674 if (machine_data->dummy_aoi_virt)
1675 fsl_diu_free(machine_data->dummy_aoi_virt, 64);
1676 iounmap(dr.diu_reg);
1679 for (i = 0; i < ARRAY_SIZE(machine_data->fsl_diu_info); i++)
1680 if (machine_data->fsl_diu_info[i])
1681 framebuffer_release(machine_data->fsl_diu_info[i]);
1682 kfree(machine_data);
1688 static int fsl_diu_remove(struct platform_device *ofdev)
1690 struct fsl_diu_data *machine_data;
1693 machine_data = dev_get_drvdata(&ofdev->dev);
1694 disable_lcdc(machine_data->fsl_diu_info[0]);
1695 free_irq_local(machine_data->irq);
1696 for (i = ARRAY_SIZE(machine_data->fsl_diu_info); i > 0; i--)
1697 uninstall_fb(machine_data->fsl_diu_info[i - 1]);
1699 free_buf(&ofdev->dev, &pool.ad,
1700 sizeof(struct diu_ad) * FSL_AOI_NUM, 8);
1701 if (pool.gamma.vaddr)
1702 free_buf(&ofdev->dev, &pool.gamma, 768, 32);
1703 if (pool.cursor.vaddr)
1704 free_buf(&ofdev->dev, &pool.cursor, MAX_CURS * MAX_CURS * 2,
1706 if (machine_data->dummy_aoi_virt)
1707 fsl_diu_free(machine_data->dummy_aoi_virt, 64);
1708 iounmap(dr.diu_reg);
1709 for (i = 0; i < ARRAY_SIZE(machine_data->fsl_diu_info); i++)
1710 if (machine_data->fsl_diu_info[i])
1711 framebuffer_release(machine_data->fsl_diu_info[i]);
1712 kfree(machine_data);
1718 static int __init fsl_diu_setup(char *options)
1723 if (!options || !*options)
1726 while ((opt = strsep(&options, ",")) != NULL) {
1729 if (!strncmp(opt, "monitor=", 8)) {
1730 monitor_port = fsl_diu_name_to_port(opt + 8);
1731 } else if (!strncmp(opt, "bpp=", 4)) {
1732 if (!strict_strtoul(opt + 4, 10, &val))
1742 static struct of_device_id fsl_diu_match[] = {
1743 #ifdef CONFIG_PPC_MPC512x
1745 .compatible = "fsl,mpc5121-diu",
1749 .compatible = "fsl,diu",
1753 MODULE_DEVICE_TABLE(of, fsl_diu_match);
1755 static struct platform_driver fsl_diu_driver = {
1758 .owner = THIS_MODULE,
1759 .of_match_table = fsl_diu_match,
1761 .probe = fsl_diu_probe,
1762 .remove = fsl_diu_remove,
1763 .suspend = fsl_diu_suspend,
1764 .resume = fsl_diu_resume,
1767 static int __init fsl_diu_init(void)
1769 #ifdef CONFIG_NOT_COHERENT_CACHE
1770 struct device_node *np;
1778 * For kernel boot options (in 'video=xxxfb:<options>' format)
1780 if (fb_get_options("fslfb", &option))
1782 fsl_diu_setup(option);
1784 monitor_port = fsl_diu_name_to_port(monitor_string);
1786 printk(KERN_INFO "Freescale DIU driver\n");
1788 #ifdef CONFIG_NOT_COHERENT_CACHE
1789 np = of_find_node_by_type(NULL, "cpu");
1791 printk(KERN_ERR "Err: can't find device node 'cpu'\n");
1795 prop = of_get_property(np, "d-cache-size", NULL);
1801 /* Freescale PLRU requires 13/8 times the cache size to do a proper
1804 coherence_data_size = *prop * 13;
1805 coherence_data_size /= 8;
1807 prop = of_get_property(np, "d-cache-line-size", NULL);
1812 d_cache_line_size = *prop;
1815 coherence_data = vmalloc(coherence_data_size);
1816 if (!coherence_data)
1819 ret = platform_driver_register(&fsl_diu_driver);
1822 "fsl-diu: failed to register platform driver\n");
1823 #if defined(CONFIG_NOT_COHERENT_CACHE)
1824 vfree(coherence_data);
1826 iounmap(dr.diu_reg);
1831 static void __exit fsl_diu_exit(void)
1833 platform_driver_unregister(&fsl_diu_driver);
1834 #if defined(CONFIG_NOT_COHERENT_CACHE)
1835 vfree(coherence_data);
1839 module_init(fsl_diu_init);
1840 module_exit(fsl_diu_exit);
1842 MODULE_AUTHOR("York Sun <yorksun@freescale.com>");
1843 MODULE_DESCRIPTION("Freescale DIU framebuffer driver");
1844 MODULE_LICENSE("GPL");
1846 module_param_named(mode, fb_mode, charp, 0);
1847 MODULE_PARM_DESC(mode,
1848 "Specify resolution as \"<xres>x<yres>[-<bpp>][@<refresh>]\" ");
1849 module_param_named(bpp, default_bpp, ulong, 0);
1850 MODULE_PARM_DESC(bpp, "Specify bit-per-pixel if not specified mode");
1851 module_param_named(monitor, monitor_string, charp, 0);
1852 MODULE_PARM_DESC(monitor, "Specify the monitor port "
1853 "(\"dvi\", \"lvds\", or \"dlvds\") if supported by the platform");