2 * Copyright (C) 2010 Juergen Beisert, Pengutronix
4 * This code is based on:
5 * Author: Vitaly Wool <vital@embeddedalley.com>
7 * Copyright 2008-2009 Freescale Semiconductor, Inc. All Rights Reserved.
8 * Copyright 2008 Embedded Alley Solutions, Inc All Rights Reserved.
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
20 #define DRIVER_NAME "mxsfb"
24 * @brief LCDIF driver for i.MX23 and i.MX28
26 * The LCDIF support four modes of operation
27 * - MPU interface (to drive smart displays) -> not supported yet
28 * - VSYNC interface (like MPU interface plus Vsync) -> not supported yet
29 * - Dotclock interface (to drive LC displays with RGB data and sync signals)
30 * - DVI (to drive ITU-R BT656) -> not supported yet
32 * This driver depends on a correct setup of the pins used for this purpose
33 * (platform specific).
35 * For the developer: Don't forget to set the data bus width to the display
36 * in the imx_fb_videomode structure. You will else end up with ugly colours.
37 * If you fight against jitter you can vary the clock delay. This is a feature
38 * of the i.MX28 and you can vary it between 2 ns ... 8 ns in 2 ns steps. Give
39 * the required value in the imx_fb_videomode structure.
42 #include <linux/kernel.h>
43 #include <linux/platform_device.h>
44 #include <linux/clk.h>
45 #include <linux/dma-mapping.h>
47 #include <mach/mxsfb.h>
52 #define LCDC_CTRL 0x00
53 #define LCDC_CTRL1 0x10
54 #define LCDC_V4_CTRL2 0x20
55 #define LCDC_V3_TRANSFER_COUNT 0x20
56 #define LCDC_V4_TRANSFER_COUNT 0x30
57 #define LCDC_V4_CUR_BUF 0x40
58 #define LCDC_V4_NEXT_BUF 0x50
59 #define LCDC_V3_CUR_BUF 0x30
60 #define LCDC_V3_NEXT_BUF 0x40
61 #define LCDC_TIMING 0x60
62 #define LCDC_VDCTRL0 0x70
63 #define LCDC_VDCTRL1 0x80
64 #define LCDC_VDCTRL2 0x90
65 #define LCDC_VDCTRL3 0xa0
66 #define LCDC_VDCTRL4 0xb0
67 #define LCDC_DVICTRL0 0xc0
68 #define LCDC_DVICTRL1 0xd0
69 #define LCDC_DVICTRL2 0xe0
70 #define LCDC_DVICTRL3 0xf0
71 #define LCDC_DVICTRL4 0x100
72 #define LCDC_V4_DATA 0x180
73 #define LCDC_V3_DATA 0x1b0
74 #define LCDC_V4_DEBUG0 0x1d0
75 #define LCDC_V3_DEBUG0 0x1f0
77 #define CTRL_SFTRST (1 << 31)
78 #define CTRL_CLKGATE (1 << 30)
79 #define CTRL_BYPASS_COUNT (1 << 19)
80 #define CTRL_VSYNC_MODE (1 << 18)
81 #define CTRL_DOTCLK_MODE (1 << 17)
82 #define CTRL_DATA_SELECT (1 << 16)
83 #define CTRL_SET_BUS_WIDTH(x) (((x) & 0x3) << 10)
84 #define CTRL_GET_BUS_WIDTH(x) (((x) >> 10) & 0x3)
85 #define CTRL_SET_WORD_LENGTH(x) (((x) & 0x3) << 8)
86 #define CTRL_GET_WORD_LENGTH(x) (((x) >> 8) & 0x3)
87 #define CTRL_MASTER (1 << 5)
88 #define CTRL_DF16 (1 << 3)
89 #define CTRL_DF18 (1 << 2)
90 #define CTRL_DF24 (1 << 1)
91 #define CTRL_RUN (1 << 0)
93 #define CTRL1_FIFO_CLEAR (1 << 21)
94 #define CTRL1_SET_BYTE_PACKAGING(x) (((x) & 0xf) << 16)
95 #define CTRL1_GET_BYTE_PACKAGING(x) (((x) >> 16) & 0xf)
97 #define TRANSFER_COUNT_SET_VCOUNT(x) (((x) & 0xffff) << 16)
98 #define TRANSFER_COUNT_GET_VCOUNT(x) (((x) >> 16) & 0xffff)
99 #define TRANSFER_COUNT_SET_HCOUNT(x) ((x) & 0xffff)
100 #define TRANSFER_COUNT_GET_HCOUNT(x) ((x) & 0xffff)
103 #define VDCTRL0_ENABLE_PRESENT (1 << 28)
104 #define VDCTRL0_VSYNC_ACT_HIGH (1 << 27)
105 #define VDCTRL0_HSYNC_ACT_HIGH (1 << 26)
106 #define VDCTRL0_DOTCLK_ACT_FAILING (1 << 25)
107 #define VDCTRL0_ENABLE_ACT_HIGH (1 << 24)
108 #define VDCTRL0_VSYNC_PERIOD_UNIT (1 << 21)
109 #define VDCTRL0_VSYNC_PULSE_WIDTH_UNIT (1 << 20)
110 #define VDCTRL0_HALF_LINE (1 << 19)
111 #define VDCTRL0_HALF_LINE_MODE (1 << 18)
112 #define VDCTRL0_SET_VSYNC_PULSE_WIDTH(x) ((x) & 0x3ffff)
113 #define VDCTRL0_GET_VSYNC_PULSE_WIDTH(x) ((x) & 0x3ffff)
115 #define VDCTRL2_SET_HSYNC_PERIOD(x) ((x) & 0x3ffff)
116 #define VDCTRL2_GET_HSYNC_PERIOD(x) ((x) & 0x3ffff)
118 #define VDCTRL3_MUX_SYNC_SIGNALS (1 << 29)
119 #define VDCTRL3_VSYNC_ONLY (1 << 28)
120 #define SET_HOR_WAIT_CNT(x) (((x) & 0xfff) << 16)
121 #define GET_HOR_WAIT_CNT(x) (((x) >> 16) & 0xfff)
122 #define SET_VERT_WAIT_CNT(x) ((x) & 0xffff)
123 #define GET_VERT_WAIT_CNT(x) ((x) & 0xffff)
125 #define VDCTRL4_SET_DOTCLK_DLY(x) (((x) & 0x7) << 29) /* v4 only */
126 #define VDCTRL4_GET_DOTCLK_DLY(x) (((x) >> 29) & 0x7) /* v4 only */
127 #define VDCTRL4_SYNC_SIGNALS_ON (1 << 18)
128 #define SET_DOTCLK_H_VALID_DATA_CNT(x) ((x) & 0x3ffff)
130 #define DEBUG0_HSYNC (1 < 26)
131 #define DEBUG0_VSYNC (1 < 25)
146 /* CPU dependent register offsets */
147 struct mxsfb_devdata
{
148 unsigned transfer_count
;
152 unsigned hs_wdth_mask
;
153 unsigned hs_wdth_shift
;
158 struct fb_info fb_info
;
159 struct platform_device
*pdev
;
161 void __iomem
*base
; /* registers */
162 unsigned allocated_size
;
164 unsigned ld_intf_width
;
165 unsigned dotclk_delay
;
166 const struct mxsfb_devdata
*devdata
;
170 #define mxsfb_is_v3(host) (host->devdata->ipversion == 3)
171 #define mxsfb_is_v4(host) (host->devdata->ipversion == 4)
173 static const struct mxsfb_devdata mxsfb_devdata
[] = {
175 .transfer_count
= LCDC_V3_TRANSFER_COUNT
,
176 .cur_buf
= LCDC_V3_CUR_BUF
,
177 .next_buf
= LCDC_V3_NEXT_BUF
,
178 .debug0
= LCDC_V3_DEBUG0
,
179 .hs_wdth_mask
= 0xff,
184 .transfer_count
= LCDC_V4_TRANSFER_COUNT
,
185 .cur_buf
= LCDC_V4_CUR_BUF
,
186 .next_buf
= LCDC_V4_NEXT_BUF
,
187 .debug0
= LCDC_V4_DEBUG0
,
188 .hs_wdth_mask
= 0x3fff,
194 #define to_imxfb_host(x) (container_of(x, struct mxsfb_info, fb_info))
196 /* mask and shift depends on architecture */
197 static inline u32
set_hsync_pulse_width(struct mxsfb_info
*host
, unsigned val
)
199 return (val
& host
->devdata
->hs_wdth_mask
) <<
200 host
->devdata
->hs_wdth_shift
;
203 static inline u32
get_hsync_pulse_width(struct mxsfb_info
*host
, unsigned val
)
205 return (val
>> host
->devdata
->hs_wdth_shift
) &
206 host
->devdata
->hs_wdth_mask
;
209 static const struct fb_bitfield def_rgb565
[] = {
222 [TRANSP
] = { /* no support for transparency */
227 static const struct fb_bitfield def_rgb666
[] = {
240 [TRANSP
] = { /* no support for transparency */
245 static const struct fb_bitfield def_rgb888
[] = {
258 [TRANSP
] = { /* no support for transparency */
263 static inline unsigned chan_to_field(unsigned chan
, struct fb_bitfield
*bf
)
266 chan
>>= 16 - bf
->length
;
267 return chan
<< bf
->offset
;
270 static int mxsfb_check_var(struct fb_var_screeninfo
*var
,
271 struct fb_info
*fb_info
)
273 struct mxsfb_info
*host
= to_imxfb_host(fb_info
);
274 const struct fb_bitfield
*rgb
= NULL
;
276 if (var
->xres
< MIN_XRES
)
277 var
->xres
= MIN_XRES
;
278 if (var
->yres
< MIN_YRES
)
279 var
->yres
= MIN_YRES
;
281 var
->xres_virtual
= var
->xres
;
283 var
->yres_virtual
= var
->yres
;
285 switch (var
->bits_per_pixel
) {
287 /* always expect RGB 565 */
291 switch (host
->ld_intf_width
) {
293 pr_debug("Unsupported LCD bus width mapping\n");
297 /* 24 bit to 18 bit mapping */
307 pr_debug("Unsupported colour depth: %u\n", var
->bits_per_pixel
);
312 * Copy the RGB parameters for this display
313 * from the machine specific parameters.
316 var
->green
= rgb
[GREEN
];
317 var
->blue
= rgb
[BLUE
];
318 var
->transp
= rgb
[TRANSP
];
323 static void mxsfb_enable_controller(struct fb_info
*fb_info
)
325 struct mxsfb_info
*host
= to_imxfb_host(fb_info
);
328 dev_dbg(&host
->pdev
->dev
, "%s\n", __func__
);
330 clk_enable(host
->clk
);
331 clk_set_rate(host
->clk
, PICOS2KHZ(fb_info
->var
.pixclock
) * 1000U);
333 /* if it was disabled, re-enable the mode again */
334 writel(CTRL_DOTCLK_MODE
, host
->base
+ LCDC_CTRL
+ REG_SET
);
336 /* enable the SYNC signals first, then the DMA engine */
337 reg
= readl(host
->base
+ LCDC_VDCTRL4
);
338 reg
|= VDCTRL4_SYNC_SIGNALS_ON
;
339 writel(reg
, host
->base
+ LCDC_VDCTRL4
);
341 writel(CTRL_RUN
, host
->base
+ LCDC_CTRL
+ REG_SET
);
346 static void mxsfb_disable_controller(struct fb_info
*fb_info
)
348 struct mxsfb_info
*host
= to_imxfb_host(fb_info
);
352 dev_dbg(&host
->pdev
->dev
, "%s\n", __func__
);
355 * Even if we disable the controller here, it will still continue
356 * until its FIFOs are running out of data
358 writel(CTRL_DOTCLK_MODE
, host
->base
+ LCDC_CTRL
+ REG_CLR
);
362 reg
= readl(host
->base
+ LCDC_CTRL
);
363 if (!(reg
& CTRL_RUN
))
368 writel(VDCTRL4_SYNC_SIGNALS_ON
, host
->base
+ LCDC_VDCTRL4
+ REG_CLR
);
370 clk_disable(host
->clk
);
375 static int mxsfb_set_par(struct fb_info
*fb_info
)
377 struct mxsfb_info
*host
= to_imxfb_host(fb_info
);
378 u32 ctrl
, vdctrl0
, vdctrl4
;
379 int line_size
, fb_size
;
382 line_size
= fb_info
->var
.xres
* (fb_info
->var
.bits_per_pixel
>> 3);
383 fb_size
= fb_info
->var
.yres_virtual
* line_size
;
385 if (fb_size
> fb_info
->fix
.smem_len
)
388 fb_info
->fix
.line_length
= line_size
;
391 * It seems, you can't re-program the controller if it is still running.
392 * This may lead into shifted pictures (FIFO issue?).
393 * So, first stop the controller and drain its FIFOs
397 mxsfb_disable_controller(fb_info
);
400 /* clear the FIFOs */
401 writel(CTRL1_FIFO_CLEAR
, host
->base
+ LCDC_CTRL1
+ REG_SET
);
403 ctrl
= CTRL_BYPASS_COUNT
| CTRL_MASTER
|
404 CTRL_SET_BUS_WIDTH(host
->ld_intf_width
);
406 switch (fb_info
->var
.bits_per_pixel
) {
408 dev_dbg(&host
->pdev
->dev
, "Setting up RGB565 mode\n");
409 ctrl
|= CTRL_SET_WORD_LENGTH(0);
410 writel(CTRL1_SET_BYTE_PACKAGING(0xf), host
->base
+ LCDC_CTRL1
);
413 dev_dbg(&host
->pdev
->dev
, "Setting up RGB888/666 mode\n");
414 ctrl
|= CTRL_SET_WORD_LENGTH(3);
415 switch (host
->ld_intf_width
) {
417 dev_dbg(&host
->pdev
->dev
,
418 "Unsupported LCD bus width mapping\n");
422 /* 24 bit to 18 bit mapping */
423 ctrl
|= CTRL_DF24
; /* ignore the upper 2 bits in
424 * each colour component
431 /* do not use packed pixels = one pixel per word instead */
432 writel(CTRL1_SET_BYTE_PACKAGING(0x7), host
->base
+ LCDC_CTRL1
);
435 dev_dbg(&host
->pdev
->dev
, "Unhandled color depth of %u\n",
436 fb_info
->var
.bits_per_pixel
);
440 writel(ctrl
, host
->base
+ LCDC_CTRL
);
442 writel(TRANSFER_COUNT_SET_VCOUNT(fb_info
->var
.yres
) |
443 TRANSFER_COUNT_SET_HCOUNT(fb_info
->var
.xres
),
444 host
->base
+ host
->devdata
->transfer_count
);
446 vdctrl0
= VDCTRL0_ENABLE_PRESENT
| /* always in DOTCLOCK mode */
447 VDCTRL0_VSYNC_PERIOD_UNIT
|
448 VDCTRL0_VSYNC_PULSE_WIDTH_UNIT
|
449 VDCTRL0_SET_VSYNC_PULSE_WIDTH(fb_info
->var
.vsync_len
);
450 if (fb_info
->var
.sync
& FB_SYNC_HOR_HIGH_ACT
)
451 vdctrl0
|= VDCTRL0_HSYNC_ACT_HIGH
;
452 if (fb_info
->var
.sync
& FB_SYNC_VERT_HIGH_ACT
)
453 vdctrl0
|= VDCTRL0_VSYNC_ACT_HIGH
;
454 if (fb_info
->var
.sync
& FB_SYNC_DATA_ENABLE_HIGH_ACT
)
455 vdctrl0
|= VDCTRL0_ENABLE_ACT_HIGH
;
456 if (fb_info
->var
.sync
& FB_SYNC_DOTCLK_FAILING_ACT
)
457 vdctrl0
|= VDCTRL0_DOTCLK_ACT_FAILING
;
459 writel(vdctrl0
, host
->base
+ LCDC_VDCTRL0
);
461 /* frame length in lines */
462 writel(fb_info
->var
.upper_margin
+ fb_info
->var
.vsync_len
+
463 fb_info
->var
.lower_margin
+ fb_info
->var
.yres
,
464 host
->base
+ LCDC_VDCTRL1
);
466 /* line length in units of clocks or pixels */
467 writel(set_hsync_pulse_width(host
, fb_info
->var
.hsync_len
) |
468 VDCTRL2_SET_HSYNC_PERIOD(fb_info
->var
.left_margin
+
469 fb_info
->var
.hsync_len
+ fb_info
->var
.right_margin
+
471 host
->base
+ LCDC_VDCTRL2
);
473 writel(SET_HOR_WAIT_CNT(fb_info
->var
.left_margin
+
474 fb_info
->var
.hsync_len
) |
475 SET_VERT_WAIT_CNT(fb_info
->var
.upper_margin
+
476 fb_info
->var
.vsync_len
),
477 host
->base
+ LCDC_VDCTRL3
);
479 vdctrl4
= SET_DOTCLK_H_VALID_DATA_CNT(fb_info
->var
.xres
);
480 if (mxsfb_is_v4(host
))
481 vdctrl4
|= VDCTRL4_SET_DOTCLK_DLY(host
->dotclk_delay
);
482 writel(vdctrl4
, host
->base
+ LCDC_VDCTRL4
);
484 writel(fb_info
->fix
.smem_start
+
485 fb_info
->fix
.line_length
* fb_info
->var
.yoffset
,
486 host
->base
+ host
->devdata
->next_buf
);
489 mxsfb_enable_controller(fb_info
);
494 static int mxsfb_setcolreg(u_int regno
, u_int red
, u_int green
, u_int blue
,
495 u_int transp
, struct fb_info
*fb_info
)
501 * If greyscale is true, then we convert the RGB value
502 * to greyscale no matter what visual we are using.
504 if (fb_info
->var
.grayscale
)
505 red
= green
= blue
= (19595 * red
+ 38470 * green
+
508 switch (fb_info
->fix
.visual
) {
509 case FB_VISUAL_TRUECOLOR
:
511 * 12 or 16-bit True Colour. We encode the RGB value
512 * according to the RGB bitfield information.
515 u32
*pal
= fb_info
->pseudo_palette
;
517 val
= chan_to_field(red
, &fb_info
->var
.red
);
518 val
|= chan_to_field(green
, &fb_info
->var
.green
);
519 val
|= chan_to_field(blue
, &fb_info
->var
.blue
);
526 case FB_VISUAL_STATIC_PSEUDOCOLOR
:
527 case FB_VISUAL_PSEUDOCOLOR
:
534 static int mxsfb_blank(int blank
, struct fb_info
*fb_info
)
536 struct mxsfb_info
*host
= to_imxfb_host(fb_info
);
539 case FB_BLANK_POWERDOWN
:
540 case FB_BLANK_VSYNC_SUSPEND
:
541 case FB_BLANK_HSYNC_SUSPEND
:
542 case FB_BLANK_NORMAL
:
544 mxsfb_disable_controller(fb_info
);
547 case FB_BLANK_UNBLANK
:
549 mxsfb_enable_controller(fb_info
);
555 static int mxsfb_pan_display(struct fb_var_screeninfo
*var
,
556 struct fb_info
*fb_info
)
558 struct mxsfb_info
*host
= to_imxfb_host(fb_info
);
561 if (var
->xoffset
!= 0)
564 offset
= fb_info
->fix
.line_length
* var
->yoffset
;
566 /* update on next VSYNC */
567 writel(fb_info
->fix
.smem_start
+ offset
,
568 host
->base
+ host
->devdata
->next_buf
);
573 static struct fb_ops mxsfb_ops
= {
574 .owner
= THIS_MODULE
,
575 .fb_check_var
= mxsfb_check_var
,
576 .fb_set_par
= mxsfb_set_par
,
577 .fb_setcolreg
= mxsfb_setcolreg
,
578 .fb_blank
= mxsfb_blank
,
579 .fb_pan_display
= mxsfb_pan_display
,
580 .fb_fillrect
= cfb_fillrect
,
581 .fb_copyarea
= cfb_copyarea
,
582 .fb_imageblit
= cfb_imageblit
,
585 static int __devinit
mxsfb_restore_mode(struct mxsfb_info
*host
)
587 struct fb_info
*fb_info
= &host
->fb_info
;
590 unsigned long pa
, fbsize
;
591 int bits_per_pixel
, ofs
;
592 u32 transfer_count
, vdctrl0
, vdctrl2
, vdctrl3
, vdctrl4
, ctrl
;
593 struct fb_videomode vmode
;
595 /* Only restore the mode when the controller is running */
596 ctrl
= readl(host
->base
+ LCDC_CTRL
);
597 if (!(ctrl
& CTRL_RUN
))
600 vdctrl0
= readl(host
->base
+ LCDC_VDCTRL0
);
601 vdctrl2
= readl(host
->base
+ LCDC_VDCTRL2
);
602 vdctrl3
= readl(host
->base
+ LCDC_VDCTRL3
);
603 vdctrl4
= readl(host
->base
+ LCDC_VDCTRL4
);
605 transfer_count
= readl(host
->base
+ host
->devdata
->transfer_count
);
607 vmode
.xres
= TRANSFER_COUNT_GET_HCOUNT(transfer_count
);
608 vmode
.yres
= TRANSFER_COUNT_GET_VCOUNT(transfer_count
);
610 switch (CTRL_GET_WORD_LENGTH(ctrl
)) {
621 fb_info
->var
.bits_per_pixel
= bits_per_pixel
;
623 vmode
.pixclock
= KHZ2PICOS(clk_get_rate(host
->clk
) / 1000U);
624 vmode
.hsync_len
= get_hsync_pulse_width(host
, vdctrl2
);
625 vmode
.left_margin
= GET_HOR_WAIT_CNT(vdctrl3
) - vmode
.hsync_len
;
626 vmode
.right_margin
= VDCTRL2_GET_HSYNC_PERIOD(vdctrl2
) - vmode
.hsync_len
-
627 vmode
.left_margin
- vmode
.xres
;
628 vmode
.vsync_len
= VDCTRL0_GET_VSYNC_PULSE_WIDTH(vdctrl0
);
629 period
= readl(host
->base
+ LCDC_VDCTRL1
);
630 vmode
.upper_margin
= GET_VERT_WAIT_CNT(vdctrl3
) - vmode
.vsync_len
;
631 vmode
.lower_margin
= period
- vmode
.vsync_len
- vmode
.upper_margin
- vmode
.yres
;
633 vmode
.vmode
= FB_VMODE_NONINTERLACED
;
636 if (vdctrl0
& VDCTRL0_HSYNC_ACT_HIGH
)
637 vmode
.sync
|= FB_SYNC_HOR_HIGH_ACT
;
638 if (vdctrl0
& VDCTRL0_VSYNC_ACT_HIGH
)
639 vmode
.sync
|= FB_SYNC_VERT_HIGH_ACT
;
641 pr_debug("Reconstructed video mode:\n");
642 pr_debug("%dx%d, hsync: %u left: %u, right: %u, vsync: %u, upper: %u, lower: %u\n",
643 vmode
.xres
, vmode
.yres
,
644 vmode
.hsync_len
, vmode
.left_margin
, vmode
.right_margin
,
645 vmode
.vsync_len
, vmode
.upper_margin
, vmode
.lower_margin
);
646 pr_debug("pixclk: %ldkHz\n", PICOS2KHZ(vmode
.pixclock
));
648 fb_add_videomode(&vmode
, &fb_info
->modelist
);
650 host
->ld_intf_width
= CTRL_GET_BUS_WIDTH(ctrl
);
651 host
->dotclk_delay
= VDCTRL4_GET_DOTCLK_DLY(vdctrl4
);
653 fb_info
->fix
.line_length
= vmode
.xres
* (bits_per_pixel
>> 3);
655 pa
= readl(host
->base
+ host
->devdata
->cur_buf
);
656 fbsize
= fb_info
->fix
.line_length
* vmode
.yres
;
657 if (pa
< fb_info
->fix
.smem_start
)
659 if (pa
+ fbsize
> fb_info
->fix
.smem_start
+ fb_info
->fix
.smem_len
)
661 ofs
= pa
- fb_info
->fix
.smem_start
;
663 memmove(fb_info
->screen_base
, fb_info
->screen_base
+ ofs
, fbsize
);
664 writel(fb_info
->fix
.smem_start
, host
->base
+ host
->devdata
->next_buf
);
667 line_count
= fb_info
->fix
.smem_len
/ fb_info
->fix
.line_length
;
668 fb_info
->fix
.ypanstep
= 1;
670 clk_enable(host
->clk
);
676 static int __devinit
mxsfb_init_fbinfo(struct mxsfb_info
*host
)
678 struct fb_info
*fb_info
= &host
->fb_info
;
679 struct fb_var_screeninfo
*var
= &fb_info
->var
;
680 struct mxsfb_platform_data
*pdata
= host
->pdev
->dev
.platform_data
;
683 unsigned fb_size
= pdata
->fb_size
;
685 fb_info
->fbops
= &mxsfb_ops
;
686 fb_info
->flags
= FBINFO_FLAG_DEFAULT
| FBINFO_READS_FAST
;
687 strlcpy(fb_info
->fix
.id
, "mxs", sizeof(fb_info
->fix
.id
));
688 fb_info
->fix
.type
= FB_TYPE_PACKED_PIXELS
;
689 fb_info
->fix
.ypanstep
= 1;
690 fb_info
->fix
.visual
= FB_VISUAL_TRUECOLOR
,
691 fb_info
->fix
.accel
= FB_ACCEL_NONE
;
693 var
->bits_per_pixel
= pdata
->default_bpp
? pdata
->default_bpp
: 16;
695 var
->activate
= FB_ACTIVATE_NOW
;
696 var
->accel_flags
= 0;
697 var
->vmode
= FB_VMODE_NONINTERLACED
;
699 host
->dotclk_delay
= pdata
->dotclk_delay
;
700 host
->ld_intf_width
= pdata
->ld_intf_width
;
702 /* Memory allocation for framebuffer */
703 if (pdata
->fb_phys
) {
707 fb_phys
= pdata
->fb_phys
;
709 if (!request_mem_region(fb_phys
, fb_size
, host
->pdev
->name
))
712 fb_virt
= ioremap(fb_phys
, fb_size
);
714 release_mem_region(fb_phys
, fb_size
);
720 fb_size
= SZ_2M
; /* default */
721 fb_virt
= alloc_pages_exact(fb_size
, GFP_DMA
);
725 fb_phys
= virt_to_phys(fb_virt
);
728 fb_info
->fix
.smem_start
= fb_phys
;
729 fb_info
->screen_base
= fb_virt
;
730 fb_info
->screen_size
= fb_info
->fix
.smem_len
= fb_size
;
732 if (mxsfb_restore_mode(host
))
733 memset(fb_virt
, 0, fb_size
);
738 static void __devexit
mxsfb_free_videomem(struct mxsfb_info
*host
)
740 struct fb_info
*fb_info
= &host
->fb_info
;
743 iounmap(fb_info
->screen_base
);
744 release_mem_region(fb_info
->fix
.smem_start
,
745 fb_info
->screen_size
);
747 free_pages_exact(fb_info
->screen_base
, fb_info
->fix
.smem_len
);
751 static int __devinit
mxsfb_probe(struct platform_device
*pdev
)
753 struct mxsfb_platform_data
*pdata
= pdev
->dev
.platform_data
;
754 struct resource
*res
;
755 struct mxsfb_info
*host
;
756 struct fb_info
*fb_info
;
757 struct fb_modelist
*modelist
;
761 dev_err(&pdev
->dev
, "No platformdata. Giving up\n");
765 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
767 dev_err(&pdev
->dev
, "Cannot get memory IO resource\n");
771 if (!request_mem_region(res
->start
, resource_size(res
), pdev
->name
))
774 fb_info
= framebuffer_alloc(sizeof(struct mxsfb_info
), &pdev
->dev
);
776 dev_err(&pdev
->dev
, "Failed to allocate fbdev\n");
778 goto error_alloc_info
;
781 host
= to_imxfb_host(fb_info
);
783 host
->base
= ioremap(res
->start
, resource_size(res
));
785 dev_err(&pdev
->dev
, "ioremap failed\n");
791 platform_set_drvdata(pdev
, host
);
793 host
->devdata
= &mxsfb_devdata
[pdev
->id_entry
->driver_data
];
795 host
->clk
= clk_get(&host
->pdev
->dev
, NULL
);
796 if (IS_ERR(host
->clk
)) {
797 ret
= PTR_ERR(host
->clk
);
801 fb_info
->pseudo_palette
= kmalloc(sizeof(u32
) * 16, GFP_KERNEL
);
802 if (!fb_info
->pseudo_palette
) {
804 goto error_pseudo_pallette
;
807 INIT_LIST_HEAD(&fb_info
->modelist
);
809 ret
= mxsfb_init_fbinfo(host
);
813 for (i
= 0; i
< pdata
->mode_count
; i
++)
814 fb_add_videomode(&pdata
->mode_list
[i
], &fb_info
->modelist
);
816 modelist
= list_first_entry(&fb_info
->modelist
,
817 struct fb_modelist
, list
);
818 fb_videomode_to_var(&fb_info
->var
, &modelist
->mode
);
820 /* init the color fields */
821 mxsfb_check_var(&fb_info
->var
, fb_info
);
823 platform_set_drvdata(pdev
, fb_info
);
825 ret
= register_framebuffer(fb_info
);
827 dev_err(&pdev
->dev
,"Failed to register framebuffer\n");
831 if (!host
->enabled
) {
832 writel(0, host
->base
+ LCDC_CTRL
);
833 mxsfb_set_par(fb_info
);
834 mxsfb_enable_controller(fb_info
);
837 dev_info(&pdev
->dev
, "initialized\n");
843 clk_disable(host
->clk
);
844 fb_destroy_modelist(&fb_info
->modelist
);
846 kfree(fb_info
->pseudo_palette
);
847 error_pseudo_pallette
:
852 framebuffer_release(fb_info
);
854 release_mem_region(res
->start
, resource_size(res
));
859 static int __devexit
mxsfb_remove(struct platform_device
*pdev
)
861 struct fb_info
*fb_info
= platform_get_drvdata(pdev
);
862 struct mxsfb_info
*host
= to_imxfb_host(fb_info
);
863 struct resource
*res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
866 mxsfb_disable_controller(fb_info
);
868 unregister_framebuffer(fb_info
);
869 kfree(fb_info
->pseudo_palette
);
870 mxsfb_free_videomem(host
);
874 framebuffer_release(fb_info
);
875 release_mem_region(res
->start
, resource_size(res
));
877 platform_set_drvdata(pdev
, NULL
);
882 static struct platform_device_id mxsfb_devtype
[] = {
885 .driver_data
= MXSFB_V3
,
888 .driver_data
= MXSFB_V4
,
893 MODULE_DEVICE_TABLE(platform
, mxsfb_devtype
);
895 static struct platform_driver mxsfb_driver
= {
896 .probe
= mxsfb_probe
,
897 .remove
= __devexit_p(mxsfb_remove
),
898 .id_table
= mxsfb_devtype
,
904 static int __init
mxsfb_init(void)
906 return platform_driver_register(&mxsfb_driver
);
909 static void __exit
mxsfb_exit(void)
911 platform_driver_unregister(&mxsfb_driver
);
914 module_init(mxsfb_init
);
915 module_exit(mxsfb_exit
);
917 MODULE_DESCRIPTION("Freescale mxs framebuffer driver");
918 MODULE_AUTHOR("Sascha Hauer, Pengutronix");
919 MODULE_LICENSE("GPL");