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 <linux/platform_data/video-imxfb.h>
38 * Complain if VAR is out of range.
42 #if defined(CONFIG_BACKLIGHT_CLASS_DEVICE) || \
43 (defined(CONFIG_BACKLIGHT_CLASS_DEVICE_MODULE) && \
44 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 #define YMAX_MASK_IMX1 0x1ff
56 #define YMAX_MASK_IMX21 0x3ff
59 #define VPW_VPW(x) ((x) & 0x3ff)
61 #define LCDC_CPOS 0x0C
62 #define CPOS_CC1 (1<<31)
63 #define CPOS_CC0 (1<<30)
64 #define CPOS_OP (1<<28)
65 #define CPOS_CXP(x) (((x) & 3ff) << 16)
67 #define LCDC_LCWHB 0x10
68 #define LCWHB_BK_EN (1<<31)
69 #define LCWHB_CW(w) (((w) & 0x1f) << 24)
70 #define LCWHB_CH(h) (((h) & 0x1f) << 16)
71 #define LCWHB_BD(x) ((x) & 0xff)
73 #define LCDC_LCHCC 0x14
78 #define HCR_H_WIDTH(x) (((x) & 0x3f) << 26)
79 #define HCR_H_WAIT_1(x) (((x) & 0xff) << 8)
80 #define HCR_H_WAIT_2(x) ((x) & 0xff)
83 #define VCR_V_WIDTH(x) (((x) & 0x3f) << 26)
84 #define VCR_V_WAIT_1(x) (((x) & 0xff) << 8)
85 #define VCR_V_WAIT_2(x) ((x) & 0xff)
88 #define POS_POS(x) ((x) & 1f)
90 #define LCDC_LSCR1 0x28
91 /* bit fields in imxfb.h */
93 #define LCDC_PWMR 0x2C
94 /* bit fields in imxfb.h */
96 #define LCDC_DMACR 0x30
97 /* bit fields in imxfb.h */
99 #define LCDC_RMCR 0x34
101 #define RMCR_LCDC_EN_MX1 (1<<1)
103 #define RMCR_SELF_REF (1<<0)
105 #define LCDC_LCDICR 0x38
106 #define LCDICR_INT_SYN (1<<2)
107 #define LCDICR_INT_CON (1)
109 #define LCDC_LCDISR 0x40
110 #define LCDISR_UDR_ERR (1<<3)
111 #define LCDISR_ERR_RES (1<<2)
112 #define LCDISR_EOF (1<<1)
113 #define LCDISR_BOF (1<<0)
115 /* Used fb-mode. Can be set on kernel command line, therefore file-static. */
116 static const char *fb_mode
;
120 * These are the bitfields for each
121 * display depth that we support.
124 struct fb_bitfield red
;
125 struct fb_bitfield green
;
126 struct fb_bitfield blue
;
127 struct fb_bitfield transp
;
136 struct platform_device
*pdev
;
141 enum imxfb_type devtype
;
144 * These are the addresses we mapped
145 * the framebuffer memory region to.
152 dma_addr_t screen_dma
;
162 u_int cmap_inverse
:1,
166 struct imx_fb_videomode
*mode
;
168 #ifdef PWMR_BACKLIGHT_AVAILABLE
169 struct backlight_device
*bl
;
172 void (*lcd_power
)(int);
173 void (*backlight_power
)(int);
176 static struct platform_device_id imxfb_devtype
[] = {
179 .driver_data
= IMX1_FB
,
182 .driver_data
= IMX21_FB
,
187 MODULE_DEVICE_TABLE(platform
, imxfb_devtype
);
189 static inline int is_imx1_fb(struct imxfb_info
*fbi
)
191 return fbi
->devtype
== IMX1_FB
;
194 #define IMX_NAME "IMX"
197 * Minimum X and Y resolutions
202 /* Actually this really is 18bit support, the lowest 2 bits of each colour
203 * are unused in hardware. We claim to have 24bit support to make software
204 * like X work, which does not support 18bit.
206 static struct imxfb_rgb def_rgb_18
= {
207 .red
= {.offset
= 16, .length
= 8,},
208 .green
= {.offset
= 8, .length
= 8,},
209 .blue
= {.offset
= 0, .length
= 8,},
210 .transp
= {.offset
= 0, .length
= 0,},
213 static struct imxfb_rgb def_rgb_16_tft
= {
214 .red
= {.offset
= 11, .length
= 5,},
215 .green
= {.offset
= 5, .length
= 6,},
216 .blue
= {.offset
= 0, .length
= 5,},
217 .transp
= {.offset
= 0, .length
= 0,},
220 static struct imxfb_rgb def_rgb_16_stn
= {
221 .red
= {.offset
= 8, .length
= 4,},
222 .green
= {.offset
= 4, .length
= 4,},
223 .blue
= {.offset
= 0, .length
= 4,},
224 .transp
= {.offset
= 0, .length
= 0,},
227 static struct imxfb_rgb def_rgb_8
= {
228 .red
= {.offset
= 0, .length
= 8,},
229 .green
= {.offset
= 0, .length
= 8,},
230 .blue
= {.offset
= 0, .length
= 8,},
231 .transp
= {.offset
= 0, .length
= 0,},
234 static int imxfb_activate_var(struct fb_var_screeninfo
*var
,
235 struct fb_info
*info
);
237 static inline u_int
chan_to_field(u_int chan
, struct fb_bitfield
*bf
)
240 chan
>>= 16 - bf
->length
;
241 return chan
<< bf
->offset
;
244 static int imxfb_setpalettereg(u_int regno
, u_int red
, u_int green
, u_int blue
,
245 u_int trans
, struct fb_info
*info
)
247 struct imxfb_info
*fbi
= info
->par
;
250 #define CNVT_TOHW(val,width) ((((val)<<(width))+0x7FFF-(val))>>16)
251 if (regno
< fbi
->palette_size
) {
252 val
= (CNVT_TOHW(red
, 4) << 8) |
253 (CNVT_TOHW(green
,4) << 4) |
256 writel(val
, fbi
->regs
+ 0x800 + (regno
<< 2));
262 static int imxfb_setcolreg(u_int regno
, u_int red
, u_int green
, u_int blue
,
263 u_int trans
, struct fb_info
*info
)
265 struct imxfb_info
*fbi
= info
->par
;
270 * If inverse mode was selected, invert all the colours
271 * rather than the register number. The register number
272 * is what you poke into the framebuffer to produce the
273 * colour you requested.
275 if (fbi
->cmap_inverse
) {
277 green
= 0xffff - green
;
278 blue
= 0xffff - blue
;
282 * If greyscale is true, then we convert the RGB value
283 * to greyscale no mater what visual we are using.
285 if (info
->var
.grayscale
)
286 red
= green
= blue
= (19595 * red
+ 38470 * green
+
289 switch (info
->fix
.visual
) {
290 case FB_VISUAL_TRUECOLOR
:
292 * 12 or 16-bit True Colour. We encode the RGB value
293 * according to the RGB bitfield information.
296 u32
*pal
= info
->pseudo_palette
;
298 val
= chan_to_field(red
, &info
->var
.red
);
299 val
|= chan_to_field(green
, &info
->var
.green
);
300 val
|= chan_to_field(blue
, &info
->var
.blue
);
307 case FB_VISUAL_STATIC_PSEUDOCOLOR
:
308 case FB_VISUAL_PSEUDOCOLOR
:
309 ret
= imxfb_setpalettereg(regno
, red
, green
, blue
, trans
, info
);
316 static const struct imx_fb_videomode
*imxfb_find_mode(struct imxfb_info
*fbi
)
318 struct imx_fb_videomode
*m
;
321 for (i
= 0, m
= &fbi
->mode
[0]; i
< fbi
->num_modes
; i
++, m
++) {
322 if (!strcmp(m
->mode
.name
, fb_mode
))
330 * Round up in the following order: bits_per_pixel, xres,
331 * yres, xres_virtual, yres_virtual, xoffset, yoffset, grayscale,
332 * bitfields, horizontal timing, vertical timing.
334 static int imxfb_check_var(struct fb_var_screeninfo
*var
, struct fb_info
*info
)
336 struct imxfb_info
*fbi
= info
->par
;
337 struct imxfb_rgb
*rgb
;
338 const struct imx_fb_videomode
*imxfb_mode
;
339 unsigned long lcd_clk
;
340 unsigned long long tmp
;
343 if (var
->xres
< MIN_XRES
)
344 var
->xres
= MIN_XRES
;
345 if (var
->yres
< MIN_YRES
)
346 var
->yres
= MIN_YRES
;
348 imxfb_mode
= imxfb_find_mode(fbi
);
352 var
->xres
= imxfb_mode
->mode
.xres
;
353 var
->yres
= imxfb_mode
->mode
.yres
;
354 var
->bits_per_pixel
= imxfb_mode
->bpp
;
355 var
->pixclock
= imxfb_mode
->mode
.pixclock
;
356 var
->hsync_len
= imxfb_mode
->mode
.hsync_len
;
357 var
->left_margin
= imxfb_mode
->mode
.left_margin
;
358 var
->right_margin
= imxfb_mode
->mode
.right_margin
;
359 var
->vsync_len
= imxfb_mode
->mode
.vsync_len
;
360 var
->upper_margin
= imxfb_mode
->mode
.upper_margin
;
361 var
->lower_margin
= imxfb_mode
->mode
.lower_margin
;
362 var
->sync
= imxfb_mode
->mode
.sync
;
363 var
->xres_virtual
= max(var
->xres_virtual
, var
->xres
);
364 var
->yres_virtual
= max(var
->yres_virtual
, var
->yres
);
366 pr_debug("var->bits_per_pixel=%d\n", var
->bits_per_pixel
);
368 lcd_clk
= clk_get_rate(fbi
->clk_per
);
370 tmp
= var
->pixclock
* (unsigned long long)lcd_clk
;
372 do_div(tmp
, 1000000);
374 if (do_div(tmp
, 1000000) > 500000)
377 pcr
= (unsigned int)tmp
;
381 printk(KERN_WARNING
"Must limit pixel clock to %luHz\n",
385 switch (var
->bits_per_pixel
) {
397 if (imxfb_mode
->pcr
& PCR_TFT
)
398 rgb
= &def_rgb_16_tft
;
400 rgb
= &def_rgb_16_stn
;
408 /* add sync polarities */
409 pcr
|= imxfb_mode
->pcr
& ~(0x3f | (7 << 25));
414 * Copy the RGB parameters for this display
415 * from the machine specific parameters.
418 var
->green
= rgb
->green
;
419 var
->blue
= rgb
->blue
;
420 var
->transp
= rgb
->transp
;
422 pr_debug("RGBT length = %d:%d:%d:%d\n",
423 var
->red
.length
, var
->green
.length
, var
->blue
.length
,
426 pr_debug("RGBT offset = %d:%d:%d:%d\n",
427 var
->red
.offset
, var
->green
.offset
, var
->blue
.offset
,
435 * Set the user defined part of the display for the specified console
437 static int imxfb_set_par(struct fb_info
*info
)
439 struct imxfb_info
*fbi
= info
->par
;
440 struct fb_var_screeninfo
*var
= &info
->var
;
442 if (var
->bits_per_pixel
== 16 || var
->bits_per_pixel
== 32)
443 info
->fix
.visual
= FB_VISUAL_TRUECOLOR
;
444 else if (!fbi
->cmap_static
)
445 info
->fix
.visual
= FB_VISUAL_PSEUDOCOLOR
;
448 * Some people have weird ideas about wanting static
449 * pseudocolor maps. I suspect their user space
450 * applications are broken.
452 info
->fix
.visual
= FB_VISUAL_STATIC_PSEUDOCOLOR
;
455 info
->fix
.line_length
= var
->xres_virtual
* var
->bits_per_pixel
/ 8;
456 fbi
->palette_size
= var
->bits_per_pixel
== 8 ? 256 : 16;
458 imxfb_activate_var(var
, info
);
463 #ifdef PWMR_BACKLIGHT_AVAILABLE
464 static int imxfb_bl_get_brightness(struct backlight_device
*bl
)
466 struct imxfb_info
*fbi
= bl_get_data(bl
);
468 return readl(fbi
->regs
+ LCDC_PWMR
) & 0xFF;
471 static int imxfb_bl_update_status(struct backlight_device
*bl
)
473 struct imxfb_info
*fbi
= bl_get_data(bl
);
474 int brightness
= bl
->props
.brightness
;
476 if (bl
->props
.power
!= FB_BLANK_UNBLANK
)
478 if (bl
->props
.fb_blank
!= FB_BLANK_UNBLANK
)
481 fbi
->pwmr
= (fbi
->pwmr
& ~0xFF) | brightness
;
483 if (bl
->props
.fb_blank
!= FB_BLANK_UNBLANK
) {
484 clk_prepare_enable(fbi
->clk_ipg
);
485 clk_prepare_enable(fbi
->clk_ahb
);
486 clk_prepare_enable(fbi
->clk_per
);
488 writel(fbi
->pwmr
, fbi
->regs
+ LCDC_PWMR
);
489 if (bl
->props
.fb_blank
!= FB_BLANK_UNBLANK
) {
490 clk_disable_unprepare(fbi
->clk_per
);
491 clk_disable_unprepare(fbi
->clk_ahb
);
492 clk_disable_unprepare(fbi
->clk_ipg
);
498 static const struct backlight_ops imxfb_lcdc_bl_ops
= {
499 .update_status
= imxfb_bl_update_status
,
500 .get_brightness
= imxfb_bl_get_brightness
,
503 static void imxfb_init_backlight(struct imxfb_info
*fbi
)
505 struct backlight_properties props
;
506 struct backlight_device
*bl
;
511 memset(&props
, 0, sizeof(struct backlight_properties
));
512 props
.max_brightness
= 0xff;
513 props
.type
= BACKLIGHT_RAW
;
514 writel(fbi
->pwmr
, fbi
->regs
+ LCDC_PWMR
);
516 bl
= backlight_device_register("imxfb-bl", &fbi
->pdev
->dev
, fbi
,
517 &imxfb_lcdc_bl_ops
, &props
);
519 dev_err(&fbi
->pdev
->dev
, "error %ld on backlight register\n",
525 bl
->props
.power
= FB_BLANK_UNBLANK
;
526 bl
->props
.fb_blank
= FB_BLANK_UNBLANK
;
527 bl
->props
.brightness
= imxfb_bl_get_brightness(bl
);
530 static void imxfb_exit_backlight(struct imxfb_info
*fbi
)
533 backlight_device_unregister(fbi
->bl
);
537 static void imxfb_enable_controller(struct imxfb_info
*fbi
)
539 pr_debug("Enabling LCD controller\n");
541 writel(fbi
->screen_dma
, fbi
->regs
+ LCDC_SSA
);
543 /* panning offset 0 (0 pixel offset) */
544 writel(0x00000000, fbi
->regs
+ LCDC_POS
);
546 /* disable hardware cursor */
547 writel(readl(fbi
->regs
+ LCDC_CPOS
) & ~(CPOS_CC0
| CPOS_CC1
),
548 fbi
->regs
+ LCDC_CPOS
);
551 * RMCR_LCDC_EN_MX1 is present on i.MX1 only, but doesn't hurt
554 writel(RMCR_LCDC_EN_MX1
, fbi
->regs
+ LCDC_RMCR
);
556 clk_prepare_enable(fbi
->clk_ipg
);
557 clk_prepare_enable(fbi
->clk_ahb
);
558 clk_prepare_enable(fbi
->clk_per
);
560 if (fbi
->backlight_power
)
561 fbi
->backlight_power(1);
566 static void imxfb_disable_controller(struct imxfb_info
*fbi
)
568 pr_debug("Disabling LCD controller\n");
570 if (fbi
->backlight_power
)
571 fbi
->backlight_power(0);
575 clk_disable_unprepare(fbi
->clk_per
);
576 clk_disable_unprepare(fbi
->clk_ipg
);
577 clk_disable_unprepare(fbi
->clk_ahb
);
579 writel(0, fbi
->regs
+ LCDC_RMCR
);
582 static int imxfb_blank(int blank
, struct fb_info
*info
)
584 struct imxfb_info
*fbi
= info
->par
;
586 pr_debug("imxfb_blank: blank=%d\n", blank
);
589 case FB_BLANK_POWERDOWN
:
590 case FB_BLANK_VSYNC_SUSPEND
:
591 case FB_BLANK_HSYNC_SUSPEND
:
592 case FB_BLANK_NORMAL
:
593 imxfb_disable_controller(fbi
);
596 case FB_BLANK_UNBLANK
:
597 imxfb_enable_controller(fbi
);
603 static struct fb_ops imxfb_ops
= {
604 .owner
= THIS_MODULE
,
605 .fb_check_var
= imxfb_check_var
,
606 .fb_set_par
= imxfb_set_par
,
607 .fb_setcolreg
= imxfb_setcolreg
,
608 .fb_fillrect
= cfb_fillrect
,
609 .fb_copyarea
= cfb_copyarea
,
610 .fb_imageblit
= cfb_imageblit
,
611 .fb_blank
= imxfb_blank
,
615 * imxfb_activate_var():
616 * Configures LCD Controller based on entries in var parameter. Settings are
617 * only written to the controller if changes were made.
619 static int imxfb_activate_var(struct fb_var_screeninfo
*var
, struct fb_info
*info
)
621 struct imxfb_info
*fbi
= info
->par
;
622 u32 ymax_mask
= is_imx1_fb(fbi
) ? YMAX_MASK_IMX1
: YMAX_MASK_IMX21
;
624 pr_debug("var: xres=%d hslen=%d lm=%d rm=%d\n",
625 var
->xres
, var
->hsync_len
,
626 var
->left_margin
, var
->right_margin
);
627 pr_debug("var: yres=%d vslen=%d um=%d bm=%d\n",
628 var
->yres
, var
->vsync_len
,
629 var
->upper_margin
, var
->lower_margin
);
632 if (var
->xres
< 16 || var
->xres
> 1024)
633 printk(KERN_ERR
"%s: invalid xres %d\n",
634 info
->fix
.id
, var
->xres
);
635 if (var
->hsync_len
< 1 || var
->hsync_len
> 64)
636 printk(KERN_ERR
"%s: invalid hsync_len %d\n",
637 info
->fix
.id
, var
->hsync_len
);
638 if (var
->left_margin
> 255)
639 printk(KERN_ERR
"%s: invalid left_margin %d\n",
640 info
->fix
.id
, var
->left_margin
);
641 if (var
->right_margin
> 255)
642 printk(KERN_ERR
"%s: invalid right_margin %d\n",
643 info
->fix
.id
, var
->right_margin
);
644 if (var
->yres
< 1 || var
->yres
> ymax_mask
)
645 printk(KERN_ERR
"%s: invalid yres %d\n",
646 info
->fix
.id
, var
->yres
);
647 if (var
->vsync_len
> 100)
648 printk(KERN_ERR
"%s: invalid vsync_len %d\n",
649 info
->fix
.id
, var
->vsync_len
);
650 if (var
->upper_margin
> 63)
651 printk(KERN_ERR
"%s: invalid upper_margin %d\n",
652 info
->fix
.id
, var
->upper_margin
);
653 if (var
->lower_margin
> 255)
654 printk(KERN_ERR
"%s: invalid lower_margin %d\n",
655 info
->fix
.id
, var
->lower_margin
);
658 /* physical screen start address */
659 writel(VPW_VPW(var
->xres
* var
->bits_per_pixel
/ 8 / 4),
660 fbi
->regs
+ LCDC_VPW
);
662 writel(HCR_H_WIDTH(var
->hsync_len
- 1) |
663 HCR_H_WAIT_1(var
->right_margin
- 1) |
664 HCR_H_WAIT_2(var
->left_margin
- 3),
665 fbi
->regs
+ LCDC_HCR
);
667 writel(VCR_V_WIDTH(var
->vsync_len
) |
668 VCR_V_WAIT_1(var
->lower_margin
) |
669 VCR_V_WAIT_2(var
->upper_margin
),
670 fbi
->regs
+ LCDC_VCR
);
672 writel(SIZE_XMAX(var
->xres
) | (var
->yres
& ymax_mask
),
673 fbi
->regs
+ LCDC_SIZE
);
675 writel(fbi
->pcr
, fbi
->regs
+ LCDC_PCR
);
676 #ifndef PWMR_BACKLIGHT_AVAILABLE
677 writel(fbi
->pwmr
, fbi
->regs
+ LCDC_PWMR
);
679 writel(fbi
->lscr1
, fbi
->regs
+ LCDC_LSCR1
);
680 writel(fbi
->dmacr
, fbi
->regs
+ LCDC_DMACR
);
687 * Power management hooks. Note that we won't be called from IRQ context,
688 * unlike the blank functions above, so we may sleep.
690 static int imxfb_suspend(struct platform_device
*dev
, pm_message_t state
)
692 struct fb_info
*info
= platform_get_drvdata(dev
);
693 struct imxfb_info
*fbi
= info
->par
;
695 pr_debug("%s\n", __func__
);
697 imxfb_disable_controller(fbi
);
701 static int imxfb_resume(struct platform_device
*dev
)
703 struct fb_info
*info
= platform_get_drvdata(dev
);
704 struct imxfb_info
*fbi
= info
->par
;
706 pr_debug("%s\n", __func__
);
708 imxfb_enable_controller(fbi
);
712 #define imxfb_suspend NULL
713 #define imxfb_resume NULL
716 static int __init
imxfb_init_fbinfo(struct platform_device
*pdev
)
718 struct imx_fb_platform_data
*pdata
= pdev
->dev
.platform_data
;
719 struct fb_info
*info
= dev_get_drvdata(&pdev
->dev
);
720 struct imxfb_info
*fbi
= info
->par
;
721 struct imx_fb_videomode
*m
;
724 pr_debug("%s\n",__func__
);
726 info
->pseudo_palette
= kmalloc(sizeof(u32
) * 16, GFP_KERNEL
);
727 if (!info
->pseudo_palette
)
730 memset(fbi
, 0, sizeof(struct imxfb_info
));
732 strlcpy(info
->fix
.id
, IMX_NAME
, sizeof(info
->fix
.id
));
734 info
->fix
.type
= FB_TYPE_PACKED_PIXELS
;
735 info
->fix
.type_aux
= 0;
736 info
->fix
.xpanstep
= 0;
737 info
->fix
.ypanstep
= 0;
738 info
->fix
.ywrapstep
= 0;
739 info
->fix
.accel
= FB_ACCEL_NONE
;
741 info
->var
.nonstd
= 0;
742 info
->var
.activate
= FB_ACTIVATE_NOW
;
743 info
->var
.height
= -1;
744 info
->var
.width
= -1;
745 info
->var
.accel_flags
= 0;
746 info
->var
.vmode
= FB_VMODE_NONINTERLACED
;
748 info
->fbops
= &imxfb_ops
;
749 info
->flags
= FBINFO_FLAG_DEFAULT
|
751 info
->var
.grayscale
= pdata
->cmap_greyscale
;
752 fbi
->cmap_inverse
= pdata
->cmap_inverse
;
753 fbi
->cmap_static
= pdata
->cmap_static
;
754 fbi
->lscr1
= pdata
->lscr1
;
755 fbi
->dmacr
= pdata
->dmacr
;
756 fbi
->pwmr
= pdata
->pwmr
;
757 fbi
->lcd_power
= pdata
->lcd_power
;
758 fbi
->backlight_power
= pdata
->backlight_power
;
760 for (i
= 0, m
= &pdata
->mode
[0]; i
< pdata
->num_modes
; i
++, m
++)
761 info
->fix
.smem_len
= max_t(size_t, info
->fix
.smem_len
,
762 m
->mode
.xres
* m
->mode
.yres
* m
->bpp
/ 8);
767 static int __init
imxfb_probe(struct platform_device
*pdev
)
769 struct imxfb_info
*fbi
;
770 struct fb_info
*info
;
771 struct imx_fb_platform_data
*pdata
;
772 struct resource
*res
;
775 dev_info(&pdev
->dev
, "i.MX Framebuffer driver\n");
777 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
781 pdata
= pdev
->dev
.platform_data
;
783 dev_err(&pdev
->dev
,"No platform_data available\n");
787 info
= framebuffer_alloc(sizeof(struct imxfb_info
), &pdev
->dev
);
792 fbi
->devtype
= pdev
->id_entry
->driver_data
;
795 fb_mode
= pdata
->mode
[0].mode
.name
;
797 platform_set_drvdata(pdev
, info
);
799 ret
= imxfb_init_fbinfo(pdev
);
803 res
= request_mem_region(res
->start
, resource_size(res
),
810 fbi
->clk_ipg
= devm_clk_get(&pdev
->dev
, "ipg");
811 if (IS_ERR(fbi
->clk_ipg
)) {
812 ret
= PTR_ERR(fbi
->clk_ipg
);
813 goto failed_getclock
;
816 fbi
->clk_ahb
= devm_clk_get(&pdev
->dev
, "ahb");
817 if (IS_ERR(fbi
->clk_ahb
)) {
818 ret
= PTR_ERR(fbi
->clk_ahb
);
819 goto failed_getclock
;
822 fbi
->clk_per
= devm_clk_get(&pdev
->dev
, "per");
823 if (IS_ERR(fbi
->clk_per
)) {
824 ret
= PTR_ERR(fbi
->clk_per
);
825 goto failed_getclock
;
828 fbi
->regs
= ioremap(res
->start
, resource_size(res
));
829 if (fbi
->regs
== NULL
) {
830 dev_err(&pdev
->dev
, "Cannot map frame buffer registers\n");
835 if (!pdata
->fixed_screen_cpu
) {
836 fbi
->map_size
= PAGE_ALIGN(info
->fix
.smem_len
);
837 fbi
->map_cpu
= dma_alloc_writecombine(&pdev
->dev
,
838 fbi
->map_size
, &fbi
->map_dma
, GFP_KERNEL
);
841 dev_err(&pdev
->dev
, "Failed to allocate video RAM: %d\n", ret
);
846 info
->screen_base
= fbi
->map_cpu
;
847 fbi
->screen_cpu
= fbi
->map_cpu
;
848 fbi
->screen_dma
= fbi
->map_dma
;
849 info
->fix
.smem_start
= fbi
->screen_dma
;
851 /* Fixed framebuffer mapping enables location of the screen in eSRAM */
852 fbi
->map_cpu
= pdata
->fixed_screen_cpu
;
853 fbi
->map_dma
= pdata
->fixed_screen_dma
;
854 info
->screen_base
= fbi
->map_cpu
;
855 fbi
->screen_cpu
= fbi
->map_cpu
;
856 fbi
->screen_dma
= fbi
->map_dma
;
857 info
->fix
.smem_start
= fbi
->screen_dma
;
861 ret
= pdata
->init(fbi
->pdev
);
863 goto failed_platform_init
;
866 fbi
->mode
= pdata
->mode
;
867 fbi
->num_modes
= pdata
->num_modes
;
869 INIT_LIST_HEAD(&info
->modelist
);
870 for (i
= 0; i
< pdata
->num_modes
; i
++)
871 fb_add_videomode(&pdata
->mode
[i
].mode
, &info
->modelist
);
874 * This makes sure that our colour bitfield
875 * descriptors are correctly initialised.
877 imxfb_check_var(&info
->var
, info
);
879 ret
= fb_alloc_cmap(&info
->cmap
, 1 << info
->var
.bits_per_pixel
, 0);
884 ret
= register_framebuffer(info
);
886 dev_err(&pdev
->dev
, "failed to register framebuffer\n");
887 goto failed_register
;
890 imxfb_enable_controller(fbi
);
892 #ifdef PWMR_BACKLIGHT_AVAILABLE
893 imxfb_init_backlight(fbi
);
899 fb_dealloc_cmap(&info
->cmap
);
902 pdata
->exit(fbi
->pdev
);
903 failed_platform_init
:
904 if (!pdata
->fixed_screen_cpu
)
905 dma_free_writecombine(&pdev
->dev
,fbi
->map_size
,fbi
->map_cpu
,
911 release_mem_region(res
->start
, resource_size(res
));
913 kfree(info
->pseudo_palette
);
915 platform_set_drvdata(pdev
, NULL
);
916 framebuffer_release(info
);
920 static int imxfb_remove(struct platform_device
*pdev
)
922 struct imx_fb_platform_data
*pdata
;
923 struct fb_info
*info
= platform_get_drvdata(pdev
);
924 struct imxfb_info
*fbi
= info
->par
;
925 struct resource
*res
;
927 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
929 imxfb_disable_controller(fbi
);
931 #ifdef PWMR_BACKLIGHT_AVAILABLE
932 imxfb_exit_backlight(fbi
);
934 unregister_framebuffer(info
);
936 pdata
= pdev
->dev
.platform_data
;
938 pdata
->exit(fbi
->pdev
);
940 fb_dealloc_cmap(&info
->cmap
);
941 kfree(info
->pseudo_palette
);
942 framebuffer_release(info
);
945 release_mem_region(res
->start
, resource_size(res
));
947 platform_set_drvdata(pdev
, NULL
);
952 void imxfb_shutdown(struct platform_device
* dev
)
954 struct fb_info
*info
= platform_get_drvdata(dev
);
955 struct imxfb_info
*fbi
= info
->par
;
956 imxfb_disable_controller(fbi
);
959 static struct platform_driver imxfb_driver
= {
960 .suspend
= imxfb_suspend
,
961 .resume
= imxfb_resume
,
962 .remove
= imxfb_remove
,
963 .shutdown
= imxfb_shutdown
,
967 .id_table
= imxfb_devtype
,
970 static int imxfb_setup(void)
973 char *opt
, *options
= NULL
;
975 if (fb_get_options("imxfb", &options
))
978 if (!options
|| !*options
)
981 while ((opt
= strsep(&options
, ",")) != NULL
) {
991 int __init
imxfb_init(void)
993 int ret
= imxfb_setup();
998 return platform_driver_probe(&imxfb_driver
, imxfb_probe
);
1001 static void __exit
imxfb_cleanup(void)
1003 platform_driver_unregister(&imxfb_driver
);
1006 module_init(imxfb_init
);
1007 module_exit(imxfb_cleanup
);
1009 MODULE_DESCRIPTION("Freescale i.MX framebuffer driver");
1010 MODULE_AUTHOR("Sascha Hauer, Pengutronix");
1011 MODULE_LICENSE("GPL");