2 * Freescale i.MX Frame Buffer device driver
4 * Copyright (C) 2004 Sascha Hauer, Pengutronix
5 * Based on acornfb.c Copyright (C) Russell King.
7 * This file is subject to the terms and conditions of the GNU General Public
8 * License. See the file COPYING in the main directory of this archive for
11 * Please direct your questions and comments on this driver to the following
14 * linux-arm-kernel@lists.arm.linux.org.uk
17 #include <linux/module.h>
18 #include <linux/kernel.h>
19 #include <linux/errno.h>
20 #include <linux/string.h>
21 #include <linux/interrupt.h>
22 #include <linux/slab.h>
25 #include <linux/delay.h>
26 #include <linux/init.h>
27 #include <linux/ioport.h>
28 #include <linux/cpufreq.h>
29 #include <linux/clk.h>
30 #include <linux/platform_device.h>
31 #include <linux/dma-mapping.h>
33 #include <linux/math64.h>
35 #include <mach/imxfb.h>
36 #include <mach/hardware.h>
39 * Complain if VAR is out of range.
43 #if defined(CONFIG_BACKLIGHT_CLASS_DEVICE) || \
44 (defined(CONFIG_BACKLIGHT_CLASS_DEVICE_MODULE) && defined(CONFIG_FB_IMX_MODULE))
45 #define PWMR_BACKLIGHT_AVAILABLE
48 #define DRIVER_NAME "imx-fb"
52 #define LCDC_SIZE 0x04
53 #define SIZE_XMAX(x) ((((x) >> 4) & 0x3f) << 20)
55 #ifdef CONFIG_ARCH_MX1
56 #define SIZE_YMAX(y) ((y) & 0x1ff)
58 #define SIZE_YMAX(y) ((y) & 0x3ff)
62 #define VPW_VPW(x) ((x) & 0x3ff)
64 #define LCDC_CPOS 0x0C
65 #define CPOS_CC1 (1<<31)
66 #define CPOS_CC0 (1<<30)
67 #define CPOS_OP (1<<28)
68 #define CPOS_CXP(x) (((x) & 3ff) << 16)
70 #ifdef CONFIG_ARCH_MX1
71 #define CPOS_CYP(y) ((y) & 0x1ff)
73 #define CPOS_CYP(y) ((y) & 0x3ff)
76 #define LCDC_LCWHB 0x10
77 #define LCWHB_BK_EN (1<<31)
78 #define LCWHB_CW(w) (((w) & 0x1f) << 24)
79 #define LCWHB_CH(h) (((h) & 0x1f) << 16)
80 #define LCWHB_BD(x) ((x) & 0xff)
82 #define LCDC_LCHCC 0x14
84 #ifdef CONFIG_ARCH_MX1
85 #define LCHCC_CUR_COL_R(r) (((r) & 0x1f) << 11)
86 #define LCHCC_CUR_COL_G(g) (((g) & 0x3f) << 5)
87 #define LCHCC_CUR_COL_B(b) ((b) & 0x1f)
89 #define LCHCC_CUR_COL_R(r) (((r) & 0x3f) << 12)
90 #define LCHCC_CUR_COL_G(g) (((g) & 0x3f) << 6)
91 #define LCHCC_CUR_COL_B(b) ((b) & 0x3f)
97 #define HCR_H_WIDTH(x) (((x) & 0x3f) << 26)
98 #define HCR_H_WAIT_1(x) (((x) & 0xff) << 8)
99 #define HCR_H_WAIT_2(x) ((x) & 0xff)
101 #define LCDC_VCR 0x20
102 #define VCR_V_WIDTH(x) (((x) & 0x3f) << 26)
103 #define VCR_V_WAIT_1(x) (((x) & 0xff) << 8)
104 #define VCR_V_WAIT_2(x) ((x) & 0xff)
106 #define LCDC_POS 0x24
107 #define POS_POS(x) ((x) & 1f)
109 #define LCDC_LSCR1 0x28
110 /* bit fields in imxfb.h */
112 #define LCDC_PWMR 0x2C
113 /* bit fields in imxfb.h */
115 #define LCDC_DMACR 0x30
116 /* bit fields in imxfb.h */
118 #define LCDC_RMCR 0x34
120 #ifdef CONFIG_ARCH_MX1
121 #define RMCR_LCDC_EN (1<<1)
123 #define RMCR_LCDC_EN 0
126 #define RMCR_SELF_REF (1<<0)
128 #define LCDC_LCDICR 0x38
129 #define LCDICR_INT_SYN (1<<2)
130 #define LCDICR_INT_CON (1)
132 #define LCDC_LCDISR 0x40
133 #define LCDISR_UDR_ERR (1<<3)
134 #define LCDISR_ERR_RES (1<<2)
135 #define LCDISR_EOF (1<<1)
136 #define LCDISR_BOF (1<<0)
138 /* Used fb-mode. Can be set on kernel command line, therefore file-static. */
139 static const char *fb_mode
;
143 * These are the bitfields for each
144 * display depth that we support.
147 struct fb_bitfield red
;
148 struct fb_bitfield green
;
149 struct fb_bitfield blue
;
150 struct fb_bitfield transp
;
154 struct platform_device
*pdev
;
159 * These are the addresses we mapped
160 * the framebuffer memory region to.
167 dma_addr_t screen_dma
;
177 u_int cmap_inverse
:1,
181 struct imx_fb_videomode
*mode
;
183 #ifdef PWMR_BACKLIGHT_AVAILABLE
184 struct backlight_device
*bl
;
187 void (*lcd_power
)(int);
188 void (*backlight_power
)(int);
191 #define IMX_NAME "IMX"
194 * Minimum X and Y resolutions
199 /* Actually this really is 18bit support, the lowest 2 bits of each colour
200 * are unused in hardware. We claim to have 24bit support to make software
201 * like X work, which does not support 18bit.
203 static struct imxfb_rgb def_rgb_18
= {
204 .red
= {.offset
= 16, .length
= 8,},
205 .green
= {.offset
= 8, .length
= 8,},
206 .blue
= {.offset
= 0, .length
= 8,},
207 .transp
= {.offset
= 0, .length
= 0,},
210 static struct imxfb_rgb def_rgb_16_tft
= {
211 .red
= {.offset
= 11, .length
= 5,},
212 .green
= {.offset
= 5, .length
= 6,},
213 .blue
= {.offset
= 0, .length
= 5,},
214 .transp
= {.offset
= 0, .length
= 0,},
217 static struct imxfb_rgb def_rgb_16_stn
= {
218 .red
= {.offset
= 8, .length
= 4,},
219 .green
= {.offset
= 4, .length
= 4,},
220 .blue
= {.offset
= 0, .length
= 4,},
221 .transp
= {.offset
= 0, .length
= 0,},
224 static struct imxfb_rgb def_rgb_8
= {
225 .red
= {.offset
= 0, .length
= 8,},
226 .green
= {.offset
= 0, .length
= 8,},
227 .blue
= {.offset
= 0, .length
= 8,},
228 .transp
= {.offset
= 0, .length
= 0,},
231 static int imxfb_activate_var(struct fb_var_screeninfo
*var
,
232 struct fb_info
*info
);
234 static inline u_int
chan_to_field(u_int chan
, struct fb_bitfield
*bf
)
237 chan
>>= 16 - bf
->length
;
238 return chan
<< bf
->offset
;
241 static int imxfb_setpalettereg(u_int regno
, u_int red
, u_int green
, u_int blue
,
242 u_int trans
, struct fb_info
*info
)
244 struct imxfb_info
*fbi
= info
->par
;
247 #define CNVT_TOHW(val,width) ((((val)<<(width))+0x7FFF-(val))>>16)
248 if (regno
< fbi
->palette_size
) {
249 val
= (CNVT_TOHW(red
, 4) << 8) |
250 (CNVT_TOHW(green
,4) << 4) |
253 writel(val
, fbi
->regs
+ 0x800 + (regno
<< 2));
259 static int imxfb_setcolreg(u_int regno
, u_int red
, u_int green
, u_int blue
,
260 u_int trans
, struct fb_info
*info
)
262 struct imxfb_info
*fbi
= info
->par
;
267 * If inverse mode was selected, invert all the colours
268 * rather than the register number. The register number
269 * is what you poke into the framebuffer to produce the
270 * colour you requested.
272 if (fbi
->cmap_inverse
) {
274 green
= 0xffff - green
;
275 blue
= 0xffff - blue
;
279 * If greyscale is true, then we convert the RGB value
280 * to greyscale no mater what visual we are using.
282 if (info
->var
.grayscale
)
283 red
= green
= blue
= (19595 * red
+ 38470 * green
+
286 switch (info
->fix
.visual
) {
287 case FB_VISUAL_TRUECOLOR
:
289 * 12 or 16-bit True Colour. We encode the RGB value
290 * according to the RGB bitfield information.
293 u32
*pal
= info
->pseudo_palette
;
295 val
= chan_to_field(red
, &info
->var
.red
);
296 val
|= chan_to_field(green
, &info
->var
.green
);
297 val
|= chan_to_field(blue
, &info
->var
.blue
);
304 case FB_VISUAL_STATIC_PSEUDOCOLOR
:
305 case FB_VISUAL_PSEUDOCOLOR
:
306 ret
= imxfb_setpalettereg(regno
, red
, green
, blue
, trans
, info
);
313 static const struct imx_fb_videomode
*imxfb_find_mode(struct imxfb_info
*fbi
)
315 struct imx_fb_videomode
*m
;
318 for (i
= 0, m
= &fbi
->mode
[0]; i
< fbi
->num_modes
; i
++, m
++) {
319 if (!strcmp(m
->mode
.name
, fb_mode
))
327 * Round up in the following order: bits_per_pixel, xres,
328 * yres, xres_virtual, yres_virtual, xoffset, yoffset, grayscale,
329 * bitfields, horizontal timing, vertical timing.
331 static int imxfb_check_var(struct fb_var_screeninfo
*var
, struct fb_info
*info
)
333 struct imxfb_info
*fbi
= info
->par
;
334 struct imxfb_rgb
*rgb
;
335 const struct imx_fb_videomode
*imxfb_mode
;
336 unsigned long lcd_clk
;
337 unsigned long long tmp
;
340 if (var
->xres
< MIN_XRES
)
341 var
->xres
= MIN_XRES
;
342 if (var
->yres
< MIN_YRES
)
343 var
->yres
= MIN_YRES
;
345 imxfb_mode
= imxfb_find_mode(fbi
);
349 var
->xres
= imxfb_mode
->mode
.xres
;
350 var
->yres
= imxfb_mode
->mode
.yres
;
351 var
->bits_per_pixel
= imxfb_mode
->bpp
;
352 var
->pixclock
= imxfb_mode
->mode
.pixclock
;
353 var
->hsync_len
= imxfb_mode
->mode
.hsync_len
;
354 var
->left_margin
= imxfb_mode
->mode
.left_margin
;
355 var
->right_margin
= imxfb_mode
->mode
.right_margin
;
356 var
->vsync_len
= imxfb_mode
->mode
.vsync_len
;
357 var
->upper_margin
= imxfb_mode
->mode
.upper_margin
;
358 var
->lower_margin
= imxfb_mode
->mode
.lower_margin
;
359 var
->sync
= imxfb_mode
->mode
.sync
;
360 var
->xres_virtual
= max(var
->xres_virtual
, var
->xres
);
361 var
->yres_virtual
= max(var
->yres_virtual
, var
->yres
);
363 pr_debug("var->bits_per_pixel=%d\n", var
->bits_per_pixel
);
365 lcd_clk
= clk_get_rate(fbi
->clk
);
367 tmp
= var
->pixclock
* (unsigned long long)lcd_clk
;
369 do_div(tmp
, 1000000);
371 if (do_div(tmp
, 1000000) > 500000)
374 pcr
= (unsigned int)tmp
;
378 printk(KERN_WARNING
"Must limit pixel clock to %luHz\n",
382 switch (var
->bits_per_pixel
) {
394 if (imxfb_mode
->pcr
& PCR_TFT
)
395 rgb
= &def_rgb_16_tft
;
397 rgb
= &def_rgb_16_stn
;
405 /* add sync polarities */
406 pcr
|= imxfb_mode
->pcr
& ~(0x3f | (7 << 25));
411 * Copy the RGB parameters for this display
412 * from the machine specific parameters.
415 var
->green
= rgb
->green
;
416 var
->blue
= rgb
->blue
;
417 var
->transp
= rgb
->transp
;
419 pr_debug("RGBT length = %d:%d:%d:%d\n",
420 var
->red
.length
, var
->green
.length
, var
->blue
.length
,
423 pr_debug("RGBT offset = %d:%d:%d:%d\n",
424 var
->red
.offset
, var
->green
.offset
, var
->blue
.offset
,
432 * Set the user defined part of the display for the specified console
434 static int imxfb_set_par(struct fb_info
*info
)
436 struct imxfb_info
*fbi
= info
->par
;
437 struct fb_var_screeninfo
*var
= &info
->var
;
439 if (var
->bits_per_pixel
== 16 || var
->bits_per_pixel
== 32)
440 info
->fix
.visual
= FB_VISUAL_TRUECOLOR
;
441 else if (!fbi
->cmap_static
)
442 info
->fix
.visual
= FB_VISUAL_PSEUDOCOLOR
;
445 * Some people have weird ideas about wanting static
446 * pseudocolor maps. I suspect their user space
447 * applications are broken.
449 info
->fix
.visual
= FB_VISUAL_STATIC_PSEUDOCOLOR
;
452 info
->fix
.line_length
= var
->xres_virtual
* var
->bits_per_pixel
/ 8;
453 fbi
->palette_size
= var
->bits_per_pixel
== 8 ? 256 : 16;
455 imxfb_activate_var(var
, info
);
460 #ifdef PWMR_BACKLIGHT_AVAILABLE
461 static int imxfb_bl_get_brightness(struct backlight_device
*bl
)
463 struct imxfb_info
*fbi
= bl_get_data(bl
);
465 return readl(fbi
->regs
+ LCDC_PWMR
) & 0xFF;
468 static int imxfb_bl_update_status(struct backlight_device
*bl
)
470 struct imxfb_info
*fbi
= bl_get_data(bl
);
471 int brightness
= bl
->props
.brightness
;
473 if (bl
->props
.power
!= FB_BLANK_UNBLANK
)
475 if (bl
->props
.fb_blank
!= FB_BLANK_UNBLANK
)
478 fbi
->pwmr
= (fbi
->pwmr
& ~0xFF) | brightness
;
480 if (bl
->props
.fb_blank
!= FB_BLANK_UNBLANK
)
481 clk_enable(fbi
->clk
);
482 writel(fbi
->pwmr
, fbi
->regs
+ LCDC_PWMR
);
483 if (bl
->props
.fb_blank
!= FB_BLANK_UNBLANK
)
484 clk_disable(fbi
->clk
);
489 static const struct backlight_ops imxfb_lcdc_bl_ops
= {
490 .update_status
= imxfb_bl_update_status
,
491 .get_brightness
= imxfb_bl_get_brightness
,
494 static void imxfb_init_backlight(struct imxfb_info
*fbi
)
496 struct backlight_properties props
;
497 struct backlight_device
*bl
;
502 memset(&props
, 0, sizeof(struct backlight_properties
));
503 props
.max_brightness
= 0xff;
504 writel(fbi
->pwmr
, fbi
->regs
+ LCDC_PWMR
);
506 bl
= backlight_device_register("imxfb-bl", &fbi
->pdev
->dev
, fbi
,
507 &imxfb_lcdc_bl_ops
, &props
);
509 dev_err(&fbi
->pdev
->dev
, "error %ld on backlight register\n",
515 bl
->props
.power
= FB_BLANK_UNBLANK
;
516 bl
->props
.fb_blank
= FB_BLANK_UNBLANK
;
517 bl
->props
.brightness
= imxfb_bl_get_brightness(bl
);
520 static void imxfb_exit_backlight(struct imxfb_info
*fbi
)
523 backlight_device_unregister(fbi
->bl
);
527 static void imxfb_enable_controller(struct imxfb_info
*fbi
)
529 pr_debug("Enabling LCD controller\n");
531 writel(fbi
->screen_dma
, fbi
->regs
+ LCDC_SSA
);
533 /* panning offset 0 (0 pixel offset) */
534 writel(0x00000000, fbi
->regs
+ LCDC_POS
);
536 /* disable hardware cursor */
537 writel(readl(fbi
->regs
+ LCDC_CPOS
) & ~(CPOS_CC0
| CPOS_CC1
),
538 fbi
->regs
+ LCDC_CPOS
);
540 writel(RMCR_LCDC_EN
, fbi
->regs
+ LCDC_RMCR
);
542 clk_enable(fbi
->clk
);
544 if (fbi
->backlight_power
)
545 fbi
->backlight_power(1);
550 static void imxfb_disable_controller(struct imxfb_info
*fbi
)
552 pr_debug("Disabling LCD controller\n");
554 if (fbi
->backlight_power
)
555 fbi
->backlight_power(0);
559 clk_disable(fbi
->clk
);
561 writel(0, fbi
->regs
+ LCDC_RMCR
);
564 static int imxfb_blank(int blank
, struct fb_info
*info
)
566 struct imxfb_info
*fbi
= info
->par
;
568 pr_debug("imxfb_blank: blank=%d\n", blank
);
571 case FB_BLANK_POWERDOWN
:
572 case FB_BLANK_VSYNC_SUSPEND
:
573 case FB_BLANK_HSYNC_SUSPEND
:
574 case FB_BLANK_NORMAL
:
575 imxfb_disable_controller(fbi
);
578 case FB_BLANK_UNBLANK
:
579 imxfb_enable_controller(fbi
);
585 static struct fb_ops imxfb_ops
= {
586 .owner
= THIS_MODULE
,
587 .fb_check_var
= imxfb_check_var
,
588 .fb_set_par
= imxfb_set_par
,
589 .fb_setcolreg
= imxfb_setcolreg
,
590 .fb_fillrect
= cfb_fillrect
,
591 .fb_copyarea
= cfb_copyarea
,
592 .fb_imageblit
= cfb_imageblit
,
593 .fb_blank
= imxfb_blank
,
597 * imxfb_activate_var():
598 * Configures LCD Controller based on entries in var parameter. Settings are
599 * only written to the controller if changes were made.
601 static int imxfb_activate_var(struct fb_var_screeninfo
*var
, struct fb_info
*info
)
603 struct imxfb_info
*fbi
= info
->par
;
605 pr_debug("var: xres=%d hslen=%d lm=%d rm=%d\n",
606 var
->xres
, var
->hsync_len
,
607 var
->left_margin
, var
->right_margin
);
608 pr_debug("var: yres=%d vslen=%d um=%d bm=%d\n",
609 var
->yres
, var
->vsync_len
,
610 var
->upper_margin
, var
->lower_margin
);
613 if (var
->xres
< 16 || var
->xres
> 1024)
614 printk(KERN_ERR
"%s: invalid xres %d\n",
615 info
->fix
.id
, var
->xres
);
616 if (var
->hsync_len
< 1 || var
->hsync_len
> 64)
617 printk(KERN_ERR
"%s: invalid hsync_len %d\n",
618 info
->fix
.id
, var
->hsync_len
);
619 if (var
->left_margin
> 255)
620 printk(KERN_ERR
"%s: invalid left_margin %d\n",
621 info
->fix
.id
, var
->left_margin
);
622 if (var
->right_margin
> 255)
623 printk(KERN_ERR
"%s: invalid right_margin %d\n",
624 info
->fix
.id
, var
->right_margin
);
625 if (var
->yres
< 1 || var
->yres
> 511)
626 printk(KERN_ERR
"%s: invalid yres %d\n",
627 info
->fix
.id
, var
->yres
);
628 if (var
->vsync_len
> 100)
629 printk(KERN_ERR
"%s: invalid vsync_len %d\n",
630 info
->fix
.id
, var
->vsync_len
);
631 if (var
->upper_margin
> 63)
632 printk(KERN_ERR
"%s: invalid upper_margin %d\n",
633 info
->fix
.id
, var
->upper_margin
);
634 if (var
->lower_margin
> 255)
635 printk(KERN_ERR
"%s: invalid lower_margin %d\n",
636 info
->fix
.id
, var
->lower_margin
);
639 /* physical screen start address */
640 writel(VPW_VPW(var
->xres
* var
->bits_per_pixel
/ 8 / 4),
641 fbi
->regs
+ LCDC_VPW
);
643 writel(HCR_H_WIDTH(var
->hsync_len
- 1) |
644 HCR_H_WAIT_1(var
->right_margin
- 1) |
645 HCR_H_WAIT_2(var
->left_margin
- 3),
646 fbi
->regs
+ LCDC_HCR
);
648 writel(VCR_V_WIDTH(var
->vsync_len
) |
649 VCR_V_WAIT_1(var
->lower_margin
) |
650 VCR_V_WAIT_2(var
->upper_margin
),
651 fbi
->regs
+ LCDC_VCR
);
653 writel(SIZE_XMAX(var
->xres
) | SIZE_YMAX(var
->yres
),
654 fbi
->regs
+ LCDC_SIZE
);
656 writel(fbi
->pcr
, fbi
->regs
+ LCDC_PCR
);
657 #ifndef PWMR_BACKLIGHT_AVAILABLE
658 writel(fbi
->pwmr
, fbi
->regs
+ LCDC_PWMR
);
660 writel(fbi
->lscr1
, fbi
->regs
+ LCDC_LSCR1
);
661 writel(fbi
->dmacr
, fbi
->regs
+ LCDC_DMACR
);
668 * Power management hooks. Note that we won't be called from IRQ context,
669 * unlike the blank functions above, so we may sleep.
671 static int imxfb_suspend(struct platform_device
*dev
, pm_message_t state
)
673 struct fb_info
*info
= platform_get_drvdata(dev
);
674 struct imxfb_info
*fbi
= info
->par
;
676 pr_debug("%s\n", __func__
);
678 imxfb_disable_controller(fbi
);
682 static int imxfb_resume(struct platform_device
*dev
)
684 struct fb_info
*info
= platform_get_drvdata(dev
);
685 struct imxfb_info
*fbi
= info
->par
;
687 pr_debug("%s\n", __func__
);
689 imxfb_enable_controller(fbi
);
693 #define imxfb_suspend NULL
694 #define imxfb_resume NULL
697 static int __init
imxfb_init_fbinfo(struct platform_device
*pdev
)
699 struct imx_fb_platform_data
*pdata
= pdev
->dev
.platform_data
;
700 struct fb_info
*info
= dev_get_drvdata(&pdev
->dev
);
701 struct imxfb_info
*fbi
= info
->par
;
702 struct imx_fb_videomode
*m
;
705 pr_debug("%s\n",__func__
);
707 info
->pseudo_palette
= kmalloc(sizeof(u32
) * 16, GFP_KERNEL
);
708 if (!info
->pseudo_palette
)
711 memset(fbi
, 0, sizeof(struct imxfb_info
));
713 strlcpy(info
->fix
.id
, IMX_NAME
, sizeof(info
->fix
.id
));
715 info
->fix
.type
= FB_TYPE_PACKED_PIXELS
;
716 info
->fix
.type_aux
= 0;
717 info
->fix
.xpanstep
= 0;
718 info
->fix
.ypanstep
= 0;
719 info
->fix
.ywrapstep
= 0;
720 info
->fix
.accel
= FB_ACCEL_NONE
;
722 info
->var
.nonstd
= 0;
723 info
->var
.activate
= FB_ACTIVATE_NOW
;
724 info
->var
.height
= -1;
725 info
->var
.width
= -1;
726 info
->var
.accel_flags
= 0;
727 info
->var
.vmode
= FB_VMODE_NONINTERLACED
;
729 info
->fbops
= &imxfb_ops
;
730 info
->flags
= FBINFO_FLAG_DEFAULT
|
732 info
->var
.grayscale
= pdata
->cmap_greyscale
;
733 fbi
->cmap_inverse
= pdata
->cmap_inverse
;
734 fbi
->cmap_static
= pdata
->cmap_static
;
735 fbi
->lscr1
= pdata
->lscr1
;
736 fbi
->dmacr
= pdata
->dmacr
;
737 fbi
->pwmr
= pdata
->pwmr
;
738 fbi
->lcd_power
= pdata
->lcd_power
;
739 fbi
->backlight_power
= pdata
->backlight_power
;
741 for (i
= 0, m
= &pdata
->mode
[0]; i
< pdata
->num_modes
; i
++, m
++)
742 info
->fix
.smem_len
= max_t(size_t, info
->fix
.smem_len
,
743 m
->mode
.xres
* m
->mode
.yres
* m
->bpp
/ 8);
748 static int __init
imxfb_probe(struct platform_device
*pdev
)
750 struct imxfb_info
*fbi
;
751 struct fb_info
*info
;
752 struct imx_fb_platform_data
*pdata
;
753 struct resource
*res
;
756 dev_info(&pdev
->dev
, "i.MX Framebuffer driver\n");
758 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
762 pdata
= pdev
->dev
.platform_data
;
764 dev_err(&pdev
->dev
,"No platform_data available\n");
768 info
= framebuffer_alloc(sizeof(struct imxfb_info
), &pdev
->dev
);
775 fb_mode
= pdata
->mode
[0].mode
.name
;
777 platform_set_drvdata(pdev
, info
);
779 ret
= imxfb_init_fbinfo(pdev
);
783 res
= request_mem_region(res
->start
, resource_size(res
),
790 fbi
->clk
= clk_get(&pdev
->dev
, NULL
);
791 if (IS_ERR(fbi
->clk
)) {
792 ret
= PTR_ERR(fbi
->clk
);
793 dev_err(&pdev
->dev
, "unable to get clock: %d\n", ret
);
794 goto failed_getclock
;
797 fbi
->regs
= ioremap(res
->start
, resource_size(res
));
798 if (fbi
->regs
== NULL
) {
799 dev_err(&pdev
->dev
, "Cannot map frame buffer registers\n");
803 if (!pdata
->fixed_screen_cpu
) {
804 fbi
->map_size
= PAGE_ALIGN(info
->fix
.smem_len
);
805 fbi
->map_cpu
= dma_alloc_writecombine(&pdev
->dev
,
806 fbi
->map_size
, &fbi
->map_dma
, GFP_KERNEL
);
809 dev_err(&pdev
->dev
, "Failed to allocate video RAM: %d\n", ret
);
814 info
->screen_base
= fbi
->map_cpu
;
815 fbi
->screen_cpu
= fbi
->map_cpu
;
816 fbi
->screen_dma
= fbi
->map_dma
;
817 info
->fix
.smem_start
= fbi
->screen_dma
;
819 /* Fixed framebuffer mapping enables location of the screen in eSRAM */
820 fbi
->map_cpu
= pdata
->fixed_screen_cpu
;
821 fbi
->map_dma
= pdata
->fixed_screen_dma
;
822 info
->screen_base
= fbi
->map_cpu
;
823 fbi
->screen_cpu
= fbi
->map_cpu
;
824 fbi
->screen_dma
= fbi
->map_dma
;
825 info
->fix
.smem_start
= fbi
->screen_dma
;
829 ret
= pdata
->init(fbi
->pdev
);
831 goto failed_platform_init
;
834 fbi
->mode
= pdata
->mode
;
835 fbi
->num_modes
= pdata
->num_modes
;
837 INIT_LIST_HEAD(&info
->modelist
);
838 for (i
= 0; i
< pdata
->num_modes
; i
++)
839 fb_add_videomode(&pdata
->mode
[i
].mode
, &info
->modelist
);
842 * This makes sure that our colour bitfield
843 * descriptors are correctly initialised.
845 imxfb_check_var(&info
->var
, info
);
847 ret
= fb_alloc_cmap(&info
->cmap
, 1 << info
->var
.bits_per_pixel
, 0);
852 ret
= register_framebuffer(info
);
854 dev_err(&pdev
->dev
, "failed to register framebuffer\n");
855 goto failed_register
;
858 imxfb_enable_controller(fbi
);
860 #ifdef PWMR_BACKLIGHT_AVAILABLE
861 imxfb_init_backlight(fbi
);
867 fb_dealloc_cmap(&info
->cmap
);
870 pdata
->exit(fbi
->pdev
);
871 failed_platform_init
:
872 if (!pdata
->fixed_screen_cpu
)
873 dma_free_writecombine(&pdev
->dev
,fbi
->map_size
,fbi
->map_cpu
,
880 release_mem_region(res
->start
, resource_size(res
));
882 kfree(info
->pseudo_palette
);
884 platform_set_drvdata(pdev
, NULL
);
885 framebuffer_release(info
);
889 static int __devexit
imxfb_remove(struct platform_device
*pdev
)
891 struct imx_fb_platform_data
*pdata
;
892 struct fb_info
*info
= platform_get_drvdata(pdev
);
893 struct imxfb_info
*fbi
= info
->par
;
894 struct resource
*res
;
896 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
898 imxfb_disable_controller(fbi
);
900 #ifdef PWMR_BACKLIGHT_AVAILABLE
901 imxfb_exit_backlight(fbi
);
903 unregister_framebuffer(info
);
905 pdata
= pdev
->dev
.platform_data
;
907 pdata
->exit(fbi
->pdev
);
909 fb_dealloc_cmap(&info
->cmap
);
910 kfree(info
->pseudo_palette
);
911 framebuffer_release(info
);
914 release_mem_region(res
->start
, resource_size(res
));
915 clk_disable(fbi
->clk
);
918 platform_set_drvdata(pdev
, NULL
);
923 void imxfb_shutdown(struct platform_device
* dev
)
925 struct fb_info
*info
= platform_get_drvdata(dev
);
926 struct imxfb_info
*fbi
= info
->par
;
927 imxfb_disable_controller(fbi
);
930 static struct platform_driver imxfb_driver
= {
931 .suspend
= imxfb_suspend
,
932 .resume
= imxfb_resume
,
933 .remove
= __devexit_p(imxfb_remove
),
934 .shutdown
= imxfb_shutdown
,
940 static int imxfb_setup(void)
943 char *opt
, *options
= NULL
;
945 if (fb_get_options("imxfb", &options
))
948 if (!options
|| !*options
)
951 while ((opt
= strsep(&options
, ",")) != NULL
) {
961 int __init
imxfb_init(void)
963 int ret
= imxfb_setup();
968 return platform_driver_probe(&imxfb_driver
, imxfb_probe
);
971 static void __exit
imxfb_cleanup(void)
973 platform_driver_unregister(&imxfb_driver
);
976 module_init(imxfb_init
);
977 module_exit(imxfb_cleanup
);
979 MODULE_DESCRIPTION("Motorola i.MX framebuffer driver");
980 MODULE_AUTHOR("Sascha Hauer, Pengutronix");
981 MODULE_LICENSE("GPL");