blob: 5c363d026f64c2856b44e748ecb149d9242be6b6 [file] [log] [blame]
Sascha Hauer7c2f891c2005-05-01 08:59:24 -07001/*
Sascha Hauer7c2f891c2005-05-01 08:59:24 -07002 * Freescale i.MX Frame Buffer device driver
3 *
4 * Copyright (C) 2004 Sascha Hauer, Pengutronix
5 * Based on acornfb.c Copyright (C) Russell King.
6 *
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
9 * more details.
10 *
11 * Please direct your questions and comments on this driver to the following
12 * email address:
13 *
14 * linux-arm-kernel@lists.arm.linux.org.uk
15 */
16
Sascha Hauer7c2f891c2005-05-01 08:59:24 -070017#include <linux/module.h>
18#include <linux/kernel.h>
Sascha Hauer7c2f891c2005-05-01 08:59:24 -070019#include <linux/errno.h>
20#include <linux/string.h>
21#include <linux/interrupt.h>
22#include <linux/slab.h>
Andrea Righi27ac7922008-07-23 21:28:13 -070023#include <linux/mm.h>
Sascha Hauer7c2f891c2005-05-01 08:59:24 -070024#include <linux/fb.h>
25#include <linux/delay.h>
26#include <linux/init.h>
27#include <linux/ioport.h>
28#include <linux/cpufreq.h>
Sascha Hauerf909ef62009-01-15 15:21:00 +010029#include <linux/clk.h>
Russell Kingd052d1b2005-10-29 19:07:23 +010030#include <linux/platform_device.h>
Sascha Hauer7c2f891c2005-05-01 08:59:24 -070031#include <linux/dma-mapping.h>
Juergen Beisert72330b02008-12-16 11:44:07 +010032#include <linux/io.h>
Sascha Hauerf909ef62009-01-15 15:21:00 +010033#include <linux/math64.h>
Sascha Hauer7c2f891c2005-05-01 08:59:24 -070034
Russell Kinga09e64f2008-08-05 16:14:15 +010035#include <mach/imxfb.h>
Sascha Hauerf497d012009-03-18 11:29:31 +010036#include <mach/hardware.h>
Sascha Hauer7c2f891c2005-05-01 08:59:24 -070037
38/*
39 * Complain if VAR is out of range.
40 */
41#define DEBUG_VAR 1
42
Eric Bénard81ef8062010-08-02 08:39:55 +010043#if defined(CONFIG_BACKLIGHT_CLASS_DEVICE) || \
44 (defined(CONFIG_BACKLIGHT_CLASS_DEVICE_MODULE) && \
45 defined(CONFIG_FB_IMX_MODULE))
46#define PWMR_BACKLIGHT_AVAILABLE
47#endif
48
Juergen Beisert72330b02008-12-16 11:44:07 +010049#define DRIVER_NAME "imx-fb"
50
51#define LCDC_SSA 0x00
52
53#define LCDC_SIZE 0x04
54#define SIZE_XMAX(x) ((((x) >> 4) & 0x3f) << 20)
Sascha Hauer1d0f9872009-01-26 17:29:10 +010055
56#ifdef CONFIG_ARCH_MX1
Juergen Beisert72330b02008-12-16 11:44:07 +010057#define SIZE_YMAX(y) ((y) & 0x1ff)
Sascha Hauer1d0f9872009-01-26 17:29:10 +010058#else
59#define SIZE_YMAX(y) ((y) & 0x3ff)
60#endif
Juergen Beisert72330b02008-12-16 11:44:07 +010061
62#define LCDC_VPW 0x08
63#define VPW_VPW(x) ((x) & 0x3ff)
64
65#define LCDC_CPOS 0x0C
66#define CPOS_CC1 (1<<31)
67#define CPOS_CC0 (1<<30)
68#define CPOS_OP (1<<28)
69#define CPOS_CXP(x) (((x) & 3ff) << 16)
Sascha Hauer1d0f9872009-01-26 17:29:10 +010070
71#ifdef CONFIG_ARCH_MX1
Juergen Beisert72330b02008-12-16 11:44:07 +010072#define CPOS_CYP(y) ((y) & 0x1ff)
Sascha Hauer1d0f9872009-01-26 17:29:10 +010073#else
74#define CPOS_CYP(y) ((y) & 0x3ff)
75#endif
Juergen Beisert72330b02008-12-16 11:44:07 +010076
77#define LCDC_LCWHB 0x10
78#define LCWHB_BK_EN (1<<31)
79#define LCWHB_CW(w) (((w) & 0x1f) << 24)
80#define LCWHB_CH(h) (((h) & 0x1f) << 16)
81#define LCWHB_BD(x) ((x) & 0xff)
82
83#define LCDC_LCHCC 0x14
Sascha Hauer1d0f9872009-01-26 17:29:10 +010084
85#ifdef CONFIG_ARCH_MX1
Juergen Beisert72330b02008-12-16 11:44:07 +010086#define LCHCC_CUR_COL_R(r) (((r) & 0x1f) << 11)
87#define LCHCC_CUR_COL_G(g) (((g) & 0x3f) << 5)
88#define LCHCC_CUR_COL_B(b) ((b) & 0x1f)
Sascha Hauer1d0f9872009-01-26 17:29:10 +010089#else
90#define LCHCC_CUR_COL_R(r) (((r) & 0x3f) << 12)
91#define LCHCC_CUR_COL_G(g) (((g) & 0x3f) << 6)
92#define LCHCC_CUR_COL_B(b) ((b) & 0x3f)
93#endif
Juergen Beisert72330b02008-12-16 11:44:07 +010094
95#define LCDC_PCR 0x18
96
97#define LCDC_HCR 0x1C
98#define HCR_H_WIDTH(x) (((x) & 0x3f) << 26)
99#define HCR_H_WAIT_1(x) (((x) & 0xff) << 8)
100#define HCR_H_WAIT_2(x) ((x) & 0xff)
101
102#define LCDC_VCR 0x20
103#define VCR_V_WIDTH(x) (((x) & 0x3f) << 26)
104#define VCR_V_WAIT_1(x) (((x) & 0xff) << 8)
105#define VCR_V_WAIT_2(x) ((x) & 0xff)
106
107#define LCDC_POS 0x24
108#define POS_POS(x) ((x) & 1f)
109
110#define LCDC_LSCR1 0x28
111/* bit fields in imxfb.h */
112
113#define LCDC_PWMR 0x2C
114/* bit fields in imxfb.h */
115
116#define LCDC_DMACR 0x30
117/* bit fields in imxfb.h */
118
119#define LCDC_RMCR 0x34
Sascha Hauer1d0f9872009-01-26 17:29:10 +0100120
121#ifdef CONFIG_ARCH_MX1
Juergen Beisert72330b02008-12-16 11:44:07 +0100122#define RMCR_LCDC_EN (1<<1)
Sascha Hauer1d0f9872009-01-26 17:29:10 +0100123#else
124#define RMCR_LCDC_EN 0
125#endif
126
Juergen Beisert72330b02008-12-16 11:44:07 +0100127#define RMCR_SELF_REF (1<<0)
128
129#define LCDC_LCDICR 0x38
130#define LCDICR_INT_SYN (1<<2)
131#define LCDICR_INT_CON (1)
132
133#define LCDC_LCDISR 0x40
134#define LCDISR_UDR_ERR (1<<3)
135#define LCDISR_ERR_RES (1<<2)
136#define LCDISR_EOF (1<<1)
137#define LCDISR_BOF (1<<0)
138
Sascha Hauer343684f2009-03-19 08:25:41 +0100139/* Used fb-mode. Can be set on kernel command line, therefore file-static. */
140static const char *fb_mode;
141
142
Sascha Hauer24b9baf2008-12-16 11:44:08 +0100143/*
144 * These are the bitfields for each
145 * display depth that we support.
146 */
147struct imxfb_rgb {
148 struct fb_bitfield red;
149 struct fb_bitfield green;
150 struct fb_bitfield blue;
151 struct fb_bitfield transp;
152};
153
Sascha Hauer24b9baf2008-12-16 11:44:08 +0100154struct imxfb_info {
155 struct platform_device *pdev;
156 void __iomem *regs;
Sascha Hauerf909ef62009-01-15 15:21:00 +0100157 struct clk *clk;
Sascha Hauer24b9baf2008-12-16 11:44:08 +0100158
Sascha Hauer24b9baf2008-12-16 11:44:08 +0100159 /*
160 * These are the addresses we mapped
161 * the framebuffer memory region to.
162 */
163 dma_addr_t map_dma;
164 u_char *map_cpu;
165 u_int map_size;
166
167 u_char *screen_cpu;
168 dma_addr_t screen_dma;
169 u_int palette_size;
170
171 dma_addr_t dbar1;
172 dma_addr_t dbar2;
173
174 u_int pcr;
175 u_int pwmr;
176 u_int lscr1;
177 u_int dmacr;
178 u_int cmap_inverse:1,
179 cmap_static:1,
180 unused:30;
181
Sascha Hauer343684f2009-03-19 08:25:41 +0100182 struct imx_fb_videomode *mode;
183 int num_modes;
Eric Bénard81ef8062010-08-02 08:39:55 +0100184#ifdef PWMR_BACKLIGHT_AVAILABLE
Eric Bénard7a2bb232010-07-16 15:09:07 +0200185 struct backlight_device *bl;
Eric Bénard81ef8062010-08-02 08:39:55 +0100186#endif
Sascha Hauer343684f2009-03-19 08:25:41 +0100187
Sascha Hauer24b9baf2008-12-16 11:44:08 +0100188 void (*lcd_power)(int);
189 void (*backlight_power)(int);
190};
191
192#define IMX_NAME "IMX"
193
194/*
195 * Minimum X and Y resolutions
196 */
197#define MIN_XRES 64
198#define MIN_YRES 64
199
Sascha Hauer15122222009-01-26 17:31:02 +0100200/* Actually this really is 18bit support, the lowest 2 bits of each colour
201 * are unused in hardware. We claim to have 24bit support to make software
202 * like X work, which does not support 18bit.
203 */
204static struct imxfb_rgb def_rgb_18 = {
205 .red = {.offset = 16, .length = 8,},
206 .green = {.offset = 8, .length = 8,},
207 .blue = {.offset = 0, .length = 8,},
208 .transp = {.offset = 0, .length = 0,},
209};
210
Sascha Hauer80eee6b2008-12-16 11:44:09 +0100211static struct imxfb_rgb def_rgb_16_tft = {
212 .red = {.offset = 11, .length = 5,},
213 .green = {.offset = 5, .length = 6,},
214 .blue = {.offset = 0, .length = 5,},
215 .transp = {.offset = 0, .length = 0,},
216};
217
218static struct imxfb_rgb def_rgb_16_stn = {
Sascha Hauer66c87192008-12-16 11:44:08 +0100219 .red = {.offset = 8, .length = 4,},
220 .green = {.offset = 4, .length = 4,},
221 .blue = {.offset = 0, .length = 4,},
222 .transp = {.offset = 0, .length = 0,},
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700223};
224
225static struct imxfb_rgb def_rgb_8 = {
Sascha Hauer66c87192008-12-16 11:44:08 +0100226 .red = {.offset = 0, .length = 8,},
227 .green = {.offset = 0, .length = 8,},
228 .blue = {.offset = 0, .length = 8,},
229 .transp = {.offset = 0, .length = 0,},
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700230};
231
Sascha Hauer66c87192008-12-16 11:44:08 +0100232static int imxfb_activate_var(struct fb_var_screeninfo *var,
233 struct fb_info *info);
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700234
235static inline u_int chan_to_field(u_int chan, struct fb_bitfield *bf)
236{
237 chan &= 0xffff;
238 chan >>= 16 - bf->length;
239 return chan << bf->offset;
240}
241
Sascha Hauer66c87192008-12-16 11:44:08 +0100242static int imxfb_setpalettereg(u_int regno, u_int red, u_int green, u_int blue,
243 u_int trans, struct fb_info *info)
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700244{
245 struct imxfb_info *fbi = info->par;
246 u_int val, ret = 1;
247
248#define CNVT_TOHW(val,width) ((((val)<<(width))+0x7FFF-(val))>>16)
249 if (regno < fbi->palette_size) {
250 val = (CNVT_TOHW(red, 4) << 8) |
251 (CNVT_TOHW(green,4) << 4) |
252 CNVT_TOHW(blue, 4);
253
Juergen Beisert72330b02008-12-16 11:44:07 +0100254 writel(val, fbi->regs + 0x800 + (regno << 2));
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700255 ret = 0;
256 }
257 return ret;
258}
259
Sascha Hauer66c87192008-12-16 11:44:08 +0100260static int imxfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700261 u_int trans, struct fb_info *info)
262{
263 struct imxfb_info *fbi = info->par;
264 unsigned int val;
265 int ret = 1;
266
267 /*
268 * If inverse mode was selected, invert all the colours
269 * rather than the register number. The register number
270 * is what you poke into the framebuffer to produce the
271 * colour you requested.
272 */
273 if (fbi->cmap_inverse) {
274 red = 0xffff - red;
275 green = 0xffff - green;
276 blue = 0xffff - blue;
277 }
278
279 /*
280 * If greyscale is true, then we convert the RGB value
281 * to greyscale no mater what visual we are using.
282 */
283 if (info->var.grayscale)
284 red = green = blue = (19595 * red + 38470 * green +
285 7471 * blue) >> 16;
286
287 switch (info->fix.visual) {
288 case FB_VISUAL_TRUECOLOR:
289 /*
290 * 12 or 16-bit True Colour. We encode the RGB value
291 * according to the RGB bitfield information.
292 */
293 if (regno < 16) {
294 u32 *pal = info->pseudo_palette;
295
296 val = chan_to_field(red, &info->var.red);
297 val |= chan_to_field(green, &info->var.green);
298 val |= chan_to_field(blue, &info->var.blue);
299
300 pal[regno] = val;
301 ret = 0;
302 }
303 break;
304
305 case FB_VISUAL_STATIC_PSEUDOCOLOR:
306 case FB_VISUAL_PSEUDOCOLOR:
307 ret = imxfb_setpalettereg(regno, red, green, blue, trans, info);
308 break;
309 }
310
311 return ret;
312}
313
Sascha Hauer343684f2009-03-19 08:25:41 +0100314static const struct imx_fb_videomode *imxfb_find_mode(struct imxfb_info *fbi)
315{
316 struct imx_fb_videomode *m;
317 int i;
318
319 for (i = 0, m = &fbi->mode[0]; i < fbi->num_modes; i++, m++) {
320 if (!strcmp(m->mode.name, fb_mode))
321 return m;
322 }
323 return NULL;
324}
325
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700326/*
327 * imxfb_check_var():
328 * Round up in the following order: bits_per_pixel, xres,
329 * yres, xres_virtual, yres_virtual, xoffset, yoffset, grayscale,
330 * bitfields, horizontal timing, vertical timing.
331 */
Sascha Hauer66c87192008-12-16 11:44:08 +0100332static int imxfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700333{
334 struct imxfb_info *fbi = info->par;
Sascha Hauer80eee6b2008-12-16 11:44:09 +0100335 struct imxfb_rgb *rgb;
Sascha Hauer343684f2009-03-19 08:25:41 +0100336 const struct imx_fb_videomode *imxfb_mode;
337 unsigned long lcd_clk;
338 unsigned long long tmp;
339 u32 pcr = 0;
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700340
341 if (var->xres < MIN_XRES)
342 var->xres = MIN_XRES;
343 if (var->yres < MIN_YRES)
344 var->yres = MIN_YRES;
Sascha Hauer343684f2009-03-19 08:25:41 +0100345
346 imxfb_mode = imxfb_find_mode(fbi);
347 if (!imxfb_mode)
348 return -EINVAL;
349
350 var->xres = imxfb_mode->mode.xres;
351 var->yres = imxfb_mode->mode.yres;
352 var->bits_per_pixel = imxfb_mode->bpp;
353 var->pixclock = imxfb_mode->mode.pixclock;
354 var->hsync_len = imxfb_mode->mode.hsync_len;
355 var->left_margin = imxfb_mode->mode.left_margin;
356 var->right_margin = imxfb_mode->mode.right_margin;
357 var->vsync_len = imxfb_mode->mode.vsync_len;
358 var->upper_margin = imxfb_mode->mode.upper_margin;
359 var->lower_margin = imxfb_mode->mode.lower_margin;
360 var->sync = imxfb_mode->mode.sync;
361 var->xres_virtual = max(var->xres_virtual, var->xres);
362 var->yres_virtual = max(var->yres_virtual, var->yres);
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700363
364 pr_debug("var->bits_per_pixel=%d\n", var->bits_per_pixel);
Sascha Hauer343684f2009-03-19 08:25:41 +0100365
366 lcd_clk = clk_get_rate(fbi->clk);
367
368 tmp = var->pixclock * (unsigned long long)lcd_clk;
369
370 do_div(tmp, 1000000);
371
372 if (do_div(tmp, 1000000) > 500000)
373 tmp++;
374
375 pcr = (unsigned int)tmp;
376
377 if (--pcr > 0x3F) {
378 pcr = 0x3F;
379 printk(KERN_WARNING "Must limit pixel clock to %luHz\n",
380 lcd_clk / pcr);
381 }
382
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700383 switch (var->bits_per_pixel) {
Sascha Hauer15122222009-01-26 17:31:02 +0100384 case 32:
Sascha Hauer343684f2009-03-19 08:25:41 +0100385 pcr |= PCR_BPIX_18;
Sascha Hauer15122222009-01-26 17:31:02 +0100386 rgb = &def_rgb_18;
387 break;
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700388 case 16:
Sascha Hauer80eee6b2008-12-16 11:44:09 +0100389 default:
Sascha Hauer343684f2009-03-19 08:25:41 +0100390 if (cpu_is_mx1())
391 pcr |= PCR_BPIX_12;
392 else
393 pcr |= PCR_BPIX_16;
394
395 if (imxfb_mode->pcr & PCR_TFT)
Sascha Hauer80eee6b2008-12-16 11:44:09 +0100396 rgb = &def_rgb_16_tft;
397 else
398 rgb = &def_rgb_16_stn;
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700399 break;
400 case 8:
Sascha Hauer343684f2009-03-19 08:25:41 +0100401 pcr |= PCR_BPIX_8;
Sascha Hauer80eee6b2008-12-16 11:44:09 +0100402 rgb = &def_rgb_8;
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700403 break;
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700404 }
405
Sascha Hauer343684f2009-03-19 08:25:41 +0100406 /* add sync polarities */
407 pcr |= imxfb_mode->pcr & ~(0x3f | (7 << 25));
408
409 fbi->pcr = pcr;
410
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700411 /*
412 * Copy the RGB parameters for this display
413 * from the machine specific parameters.
414 */
Sascha Hauer80eee6b2008-12-16 11:44:09 +0100415 var->red = rgb->red;
416 var->green = rgb->green;
417 var->blue = rgb->blue;
418 var->transp = rgb->transp;
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700419
420 pr_debug("RGBT length = %d:%d:%d:%d\n",
421 var->red.length, var->green.length, var->blue.length,
422 var->transp.length);
423
424 pr_debug("RGBT offset = %d:%d:%d:%d\n",
425 var->red.offset, var->green.offset, var->blue.offset,
426 var->transp.offset);
427
428 return 0;
429}
430
431/*
432 * imxfb_set_par():
433 * Set the user defined part of the display for the specified console
434 */
435static int imxfb_set_par(struct fb_info *info)
436{
437 struct imxfb_info *fbi = info->par;
438 struct fb_var_screeninfo *var = &info->var;
439
Sascha Hauer15122222009-01-26 17:31:02 +0100440 if (var->bits_per_pixel == 16 || var->bits_per_pixel == 32)
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700441 info->fix.visual = FB_VISUAL_TRUECOLOR;
442 else if (!fbi->cmap_static)
443 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
444 else {
445 /*
446 * Some people have weird ideas about wanting static
447 * pseudocolor maps. I suspect their user space
448 * applications are broken.
449 */
450 info->fix.visual = FB_VISUAL_STATIC_PSEUDOCOLOR;
451 }
452
Sascha Hauer66c87192008-12-16 11:44:08 +0100453 info->fix.line_length = var->xres_virtual * var->bits_per_pixel / 8;
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700454 fbi->palette_size = var->bits_per_pixel == 8 ? 256 : 16;
455
456 imxfb_activate_var(var, info);
457
458 return 0;
459}
460
Eric Bénard81ef8062010-08-02 08:39:55 +0100461#ifdef PWMR_BACKLIGHT_AVAILABLE
Eric Bénard7a2bb232010-07-16 15:09:07 +0200462static int imxfb_bl_get_brightness(struct backlight_device *bl)
463{
464 struct imxfb_info *fbi = bl_get_data(bl);
465
466 return readl(fbi->regs + LCDC_PWMR) & 0xFF;
467}
468
469static int imxfb_bl_update_status(struct backlight_device *bl)
470{
471 struct imxfb_info *fbi = bl_get_data(bl);
472 int brightness = bl->props.brightness;
473
474 if (bl->props.power != FB_BLANK_UNBLANK)
475 brightness = 0;
476 if (bl->props.fb_blank != FB_BLANK_UNBLANK)
477 brightness = 0;
478
479 fbi->pwmr = (fbi->pwmr & ~0xFF) | brightness;
480
481 if (bl->props.fb_blank != FB_BLANK_UNBLANK)
482 clk_enable(fbi->clk);
483 writel(fbi->pwmr, fbi->regs + LCDC_PWMR);
484 if (bl->props.fb_blank != FB_BLANK_UNBLANK)
485 clk_disable(fbi->clk);
486
487 return 0;
488}
489
490static const struct backlight_ops imxfb_lcdc_bl_ops = {
491 .update_status = imxfb_bl_update_status,
492 .get_brightness = imxfb_bl_get_brightness,
493};
494
495static void imxfb_init_backlight(struct imxfb_info *fbi)
496{
497 struct backlight_properties props;
498 struct backlight_device *bl;
499
500 if (fbi->bl)
501 return;
502
503 memset(&props, 0, sizeof(struct backlight_properties));
504 props.max_brightness = 0xff;
505 writel(fbi->pwmr, fbi->regs + LCDC_PWMR);
506
507 bl = backlight_device_register("imxfb-bl", &fbi->pdev->dev, fbi,
508 &imxfb_lcdc_bl_ops, &props);
509 if (IS_ERR(bl)) {
510 dev_err(&fbi->pdev->dev, "error %ld on backlight register\n",
511 PTR_ERR(bl));
512 return;
513 }
514
515 fbi->bl = bl;
516 bl->props.power = FB_BLANK_UNBLANK;
517 bl->props.fb_blank = FB_BLANK_UNBLANK;
518 bl->props.brightness = imxfb_bl_get_brightness(bl);
519}
520
521static void imxfb_exit_backlight(struct imxfb_info *fbi)
522{
523 if (fbi->bl)
524 backlight_device_unregister(fbi->bl);
525}
Eric Bénard81ef8062010-08-02 08:39:55 +0100526#endif
Eric Bénard7a2bb232010-07-16 15:09:07 +0200527
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700528static void imxfb_enable_controller(struct imxfb_info *fbi)
529{
530 pr_debug("Enabling LCD controller\n");
531
Juergen Beisert72330b02008-12-16 11:44:07 +0100532 writel(fbi->screen_dma, fbi->regs + LCDC_SSA);
533
Juergen Beisert72330b02008-12-16 11:44:07 +0100534 /* panning offset 0 (0 pixel offset) */
535 writel(0x00000000, fbi->regs + LCDC_POS);
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700536
537 /* disable hardware cursor */
Juergen Beisert72330b02008-12-16 11:44:07 +0100538 writel(readl(fbi->regs + LCDC_CPOS) & ~(CPOS_CC0 | CPOS_CC1),
539 fbi->regs + LCDC_CPOS);
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700540
Juergen Beisert72330b02008-12-16 11:44:07 +0100541 writel(RMCR_LCDC_EN, fbi->regs + LCDC_RMCR);
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700542
Sascha Hauerf909ef62009-01-15 15:21:00 +0100543 clk_enable(fbi->clk);
544
Sascha Hauer66c87192008-12-16 11:44:08 +0100545 if (fbi->backlight_power)
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700546 fbi->backlight_power(1);
Sascha Hauer66c87192008-12-16 11:44:08 +0100547 if (fbi->lcd_power)
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700548 fbi->lcd_power(1);
549}
550
551static void imxfb_disable_controller(struct imxfb_info *fbi)
552{
553 pr_debug("Disabling LCD controller\n");
554
Sascha Hauer66c87192008-12-16 11:44:08 +0100555 if (fbi->backlight_power)
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700556 fbi->backlight_power(0);
Sascha Hauer66c87192008-12-16 11:44:08 +0100557 if (fbi->lcd_power)
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700558 fbi->lcd_power(0);
559
Sascha Hauerf909ef62009-01-15 15:21:00 +0100560 clk_disable(fbi->clk);
561
Juergen Beisert72330b02008-12-16 11:44:07 +0100562 writel(0, fbi->regs + LCDC_RMCR);
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700563}
564
565static int imxfb_blank(int blank, struct fb_info *info)
566{
567 struct imxfb_info *fbi = info->par;
568
569 pr_debug("imxfb_blank: blank=%d\n", blank);
570
571 switch (blank) {
572 case FB_BLANK_POWERDOWN:
573 case FB_BLANK_VSYNC_SUSPEND:
574 case FB_BLANK_HSYNC_SUSPEND:
575 case FB_BLANK_NORMAL:
576 imxfb_disable_controller(fbi);
577 break;
578
579 case FB_BLANK_UNBLANK:
580 imxfb_enable_controller(fbi);
581 break;
582 }
583 return 0;
584}
585
586static struct fb_ops imxfb_ops = {
587 .owner = THIS_MODULE,
588 .fb_check_var = imxfb_check_var,
589 .fb_set_par = imxfb_set_par,
590 .fb_setcolreg = imxfb_setcolreg,
591 .fb_fillrect = cfb_fillrect,
592 .fb_copyarea = cfb_copyarea,
593 .fb_imageblit = cfb_imageblit,
594 .fb_blank = imxfb_blank,
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700595};
596
597/*
598 * imxfb_activate_var():
599 * Configures LCD Controller based on entries in var parameter. Settings are
600 * only written to the controller if changes were made.
601 */
602static int imxfb_activate_var(struct fb_var_screeninfo *var, struct fb_info *info)
603{
604 struct imxfb_info *fbi = info->par;
Sascha Hauerf909ef62009-01-15 15:21:00 +0100605
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700606 pr_debug("var: xres=%d hslen=%d lm=%d rm=%d\n",
607 var->xres, var->hsync_len,
608 var->left_margin, var->right_margin);
609 pr_debug("var: yres=%d vslen=%d um=%d bm=%d\n",
610 var->yres, var->vsync_len,
611 var->upper_margin, var->lower_margin);
612
613#if DEBUG_VAR
614 if (var->xres < 16 || var->xres > 1024)
615 printk(KERN_ERR "%s: invalid xres %d\n",
616 info->fix.id, var->xres);
617 if (var->hsync_len < 1 || var->hsync_len > 64)
618 printk(KERN_ERR "%s: invalid hsync_len %d\n",
619 info->fix.id, var->hsync_len);
620 if (var->left_margin > 255)
621 printk(KERN_ERR "%s: invalid left_margin %d\n",
622 info->fix.id, var->left_margin);
623 if (var->right_margin > 255)
624 printk(KERN_ERR "%s: invalid right_margin %d\n",
625 info->fix.id, var->right_margin);
626 if (var->yres < 1 || var->yres > 511)
627 printk(KERN_ERR "%s: invalid yres %d\n",
628 info->fix.id, var->yres);
629 if (var->vsync_len > 100)
630 printk(KERN_ERR "%s: invalid vsync_len %d\n",
631 info->fix.id, var->vsync_len);
632 if (var->upper_margin > 63)
633 printk(KERN_ERR "%s: invalid upper_margin %d\n",
634 info->fix.id, var->upper_margin);
635 if (var->lower_margin > 255)
636 printk(KERN_ERR "%s: invalid lower_margin %d\n",
637 info->fix.id, var->lower_margin);
638#endif
639
Sascha Hauer343684f2009-03-19 08:25:41 +0100640 /* physical screen start address */
641 writel(VPW_VPW(var->xres * var->bits_per_pixel / 8 / 4),
642 fbi->regs + LCDC_VPW);
643
Sascha Hauer7e8549b2009-02-14 16:29:38 +0100644 writel(HCR_H_WIDTH(var->hsync_len - 1) |
645 HCR_H_WAIT_1(var->right_margin - 1) |
646 HCR_H_WAIT_2(var->left_margin - 3),
Juergen Beisert72330b02008-12-16 11:44:07 +0100647 fbi->regs + LCDC_HCR);
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700648
Juergen Beisert72330b02008-12-16 11:44:07 +0100649 writel(VCR_V_WIDTH(var->vsync_len) |
Sascha Hauerd6ed5752008-12-16 11:44:08 +0100650 VCR_V_WAIT_1(var->lower_margin) |
651 VCR_V_WAIT_2(var->upper_margin),
Juergen Beisert72330b02008-12-16 11:44:07 +0100652 fbi->regs + LCDC_VCR);
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700653
Juergen Beisert72330b02008-12-16 11:44:07 +0100654 writel(SIZE_XMAX(var->xres) | SIZE_YMAX(var->yres),
655 fbi->regs + LCDC_SIZE);
Sascha Hauerf909ef62009-01-15 15:21:00 +0100656
Sascha Hauer343684f2009-03-19 08:25:41 +0100657 writel(fbi->pcr, fbi->regs + LCDC_PCR);
Eric Bénard81ef8062010-08-02 08:39:55 +0100658#ifndef PWMR_BACKLIGHT_AVAILABLE
659 writel(fbi->pwmr, fbi->regs + LCDC_PWMR);
660#endif
Juergen Beisert72330b02008-12-16 11:44:07 +0100661 writel(fbi->lscr1, fbi->regs + LCDC_LSCR1);
662 writel(fbi->dmacr, fbi->regs + LCDC_DMACR);
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700663
664 return 0;
665}
666
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700667#ifdef CONFIG_PM
668/*
669 * Power management hooks. Note that we won't be called from IRQ context,
670 * unlike the blank functions above, so we may sleep.
671 */
Russell King3ae5eae2005-11-09 22:32:44 +0000672static int imxfb_suspend(struct platform_device *dev, pm_message_t state)
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700673{
Uwe Kleine-König1ec56202010-02-02 13:44:10 -0800674 struct fb_info *info = platform_get_drvdata(dev);
675 struct imxfb_info *fbi = info->par;
Sascha Hauer66c87192008-12-16 11:44:08 +0100676
677 pr_debug("%s\n", __func__);
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700678
Russell King9480e302005-10-28 09:52:56 -0700679 imxfb_disable_controller(fbi);
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700680 return 0;
681}
682
Russell King3ae5eae2005-11-09 22:32:44 +0000683static int imxfb_resume(struct platform_device *dev)
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700684{
Uwe Kleine-König1ec56202010-02-02 13:44:10 -0800685 struct fb_info *info = platform_get_drvdata(dev);
686 struct imxfb_info *fbi = info->par;
Sascha Hauer66c87192008-12-16 11:44:08 +0100687
688 pr_debug("%s\n", __func__);
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700689
Russell King9480e302005-10-28 09:52:56 -0700690 imxfb_enable_controller(fbi);
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700691 return 0;
692}
693#else
694#define imxfb_suspend NULL
695#define imxfb_resume NULL
696#endif
697
Juergen Beisert72330b02008-12-16 11:44:07 +0100698static int __init imxfb_init_fbinfo(struct platform_device *pdev)
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700699{
Sascha Hauer27889272008-12-16 11:44:09 +0100700 struct imx_fb_platform_data *pdata = pdev->dev.platform_data;
Juergen Beisert72330b02008-12-16 11:44:07 +0100701 struct fb_info *info = dev_get_drvdata(&pdev->dev);
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700702 struct imxfb_info *fbi = info->par;
Sascha Hauer343684f2009-03-19 08:25:41 +0100703 struct imx_fb_videomode *m;
704 int i;
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700705
Harvey Harrison5ae12172008-04-28 02:15:47 -0700706 pr_debug("%s\n",__func__);
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700707
Sascha Hauer66c87192008-12-16 11:44:08 +0100708 info->pseudo_palette = kmalloc(sizeof(u32) * 16, GFP_KERNEL);
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700709 if (!info->pseudo_palette)
710 return -ENOMEM;
711
712 memset(fbi, 0, sizeof(struct imxfb_info));
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700713
714 strlcpy(info->fix.id, IMX_NAME, sizeof(info->fix.id));
715
Sascha Hauer66c87192008-12-16 11:44:08 +0100716 info->fix.type = FB_TYPE_PACKED_PIXELS;
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700717 info->fix.type_aux = 0;
718 info->fix.xpanstep = 0;
719 info->fix.ypanstep = 0;
720 info->fix.ywrapstep = 0;
Sascha Hauer66c87192008-12-16 11:44:08 +0100721 info->fix.accel = FB_ACCEL_NONE;
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700722
723 info->var.nonstd = 0;
724 info->var.activate = FB_ACTIVATE_NOW;
725 info->var.height = -1;
726 info->var.width = -1;
727 info->var.accel_flags = 0;
Sascha Hauer66c87192008-12-16 11:44:08 +0100728 info->var.vmode = FB_VMODE_NONINTERLACED;
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700729
730 info->fbops = &imxfb_ops;
Sascha Hauer66c87192008-12-16 11:44:08 +0100731 info->flags = FBINFO_FLAG_DEFAULT |
732 FBINFO_READS_FAST;
Sascha Hauer27889272008-12-16 11:44:09 +0100733 info->var.grayscale = pdata->cmap_greyscale;
734 fbi->cmap_inverse = pdata->cmap_inverse;
735 fbi->cmap_static = pdata->cmap_static;
Sascha Hauer27889272008-12-16 11:44:09 +0100736 fbi->lscr1 = pdata->lscr1;
737 fbi->dmacr = pdata->dmacr;
738 fbi->pwmr = pdata->pwmr;
739 fbi->lcd_power = pdata->lcd_power;
740 fbi->backlight_power = pdata->backlight_power;
Sascha Hauer343684f2009-03-19 08:25:41 +0100741
742 for (i = 0, m = &pdata->mode[0]; i < pdata->num_modes; i++, m++)
743 info->fix.smem_len = max_t(size_t, info->fix.smem_len,
744 m->mode.xres * m->mode.yres * m->bpp / 8);
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700745
746 return 0;
747}
748
Russell King3ae5eae2005-11-09 22:32:44 +0000749static int __init imxfb_probe(struct platform_device *pdev)
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700750{
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700751 struct imxfb_info *fbi;
752 struct fb_info *info;
Sascha Hauer27889272008-12-16 11:44:09 +0100753 struct imx_fb_platform_data *pdata;
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700754 struct resource *res;
Sascha Hauer343684f2009-03-19 08:25:41 +0100755 int ret, i;
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700756
Sascha Hauerd6b51502009-06-29 11:41:09 +0200757 dev_info(&pdev->dev, "i.MX Framebuffer driver\n");
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700758
759 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Sascha Hauer66c87192008-12-16 11:44:08 +0100760 if (!res)
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700761 return -ENODEV;
762
Sascha Hauer27889272008-12-16 11:44:09 +0100763 pdata = pdev->dev.platform_data;
764 if (!pdata) {
Pavel Pisaf99c8922006-01-07 10:44:32 +0000765 dev_err(&pdev->dev,"No platform_data available\n");
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700766 return -ENOMEM;
767 }
768
Russell King3ae5eae2005-11-09 22:32:44 +0000769 info = framebuffer_alloc(sizeof(struct imxfb_info), &pdev->dev);
Sascha Hauer66c87192008-12-16 11:44:08 +0100770 if (!info)
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700771 return -ENOMEM;
772
773 fbi = info->par;
774
Sascha Hauer343684f2009-03-19 08:25:41 +0100775 if (!fb_mode)
776 fb_mode = pdata->mode[0].mode.name;
777
Russell King3ae5eae2005-11-09 22:32:44 +0000778 platform_set_drvdata(pdev, info);
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700779
Juergen Beisert72330b02008-12-16 11:44:07 +0100780 ret = imxfb_init_fbinfo(pdev);
Sascha Hauer66c87192008-12-16 11:44:08 +0100781 if (ret < 0)
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700782 goto failed_init;
783
Juergen Beisert72330b02008-12-16 11:44:07 +0100784 res = request_mem_region(res->start, resource_size(res),
785 DRIVER_NAME);
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700786 if (!res) {
787 ret = -EBUSY;
Juergen Beisert72330b02008-12-16 11:44:07 +0100788 goto failed_req;
789 }
790
Sascha Hauerf909ef62009-01-15 15:21:00 +0100791 fbi->clk = clk_get(&pdev->dev, NULL);
792 if (IS_ERR(fbi->clk)) {
Joe Perchesa419aef2009-08-18 11:18:35 -0700793 ret = PTR_ERR(fbi->clk);
Sascha Hauerf909ef62009-01-15 15:21:00 +0100794 dev_err(&pdev->dev, "unable to get clock: %d\n", ret);
795 goto failed_getclock;
796 }
797
Juergen Beisert72330b02008-12-16 11:44:07 +0100798 fbi->regs = ioremap(res->start, resource_size(res));
799 if (fbi->regs == NULL) {
Sascha Hauerd6b51502009-06-29 11:41:09 +0200800 dev_err(&pdev->dev, "Cannot map frame buffer registers\n");
Juergen Beisert72330b02008-12-16 11:44:07 +0100801 goto failed_ioremap;
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700802 }
803
Sascha Hauer27889272008-12-16 11:44:09 +0100804 if (!pdata->fixed_screen_cpu) {
Juergen Beisert72330b02008-12-16 11:44:07 +0100805 fbi->map_size = PAGE_ALIGN(info->fix.smem_len);
806 fbi->map_cpu = dma_alloc_writecombine(&pdev->dev,
807 fbi->map_size, &fbi->map_dma, GFP_KERNEL);
808
809 if (!fbi->map_cpu) {
Pavel Pisaf99c8922006-01-07 10:44:32 +0000810 dev_err(&pdev->dev, "Failed to allocate video RAM: %d\n", ret);
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700811 ret = -ENOMEM;
812 goto failed_map;
813 }
Juergen Beisert72330b02008-12-16 11:44:07 +0100814
815 info->screen_base = fbi->map_cpu;
816 fbi->screen_cpu = fbi->map_cpu;
817 fbi->screen_dma = fbi->map_dma;
818 info->fix.smem_start = fbi->screen_dma;
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700819 } else {
820 /* Fixed framebuffer mapping enables location of the screen in eSRAM */
Sascha Hauer27889272008-12-16 11:44:09 +0100821 fbi->map_cpu = pdata->fixed_screen_cpu;
822 fbi->map_dma = pdata->fixed_screen_dma;
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700823 info->screen_base = fbi->map_cpu;
824 fbi->screen_cpu = fbi->map_cpu;
825 fbi->screen_dma = fbi->map_dma;
826 info->fix.smem_start = fbi->screen_dma;
827 }
828
Sascha Hauerc0b90a32009-01-15 15:37:22 +0100829 if (pdata->init) {
830 ret = pdata->init(fbi->pdev);
831 if (ret)
832 goto failed_platform_init;
833 }
834
Sascha Hauer343684f2009-03-19 08:25:41 +0100835 fbi->mode = pdata->mode;
836 fbi->num_modes = pdata->num_modes;
837
838 INIT_LIST_HEAD(&info->modelist);
839 for (i = 0; i < pdata->num_modes; i++)
840 fb_add_videomode(&pdata->mode[i].mode, &info->modelist);
841
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700842 /*
843 * This makes sure that our colour bitfield
844 * descriptors are correctly initialised.
845 */
846 imxfb_check_var(&info->var, info);
847
Sascha Hauer66c87192008-12-16 11:44:08 +0100848 ret = fb_alloc_cmap(&info->cmap, 1 << info->var.bits_per_pixel, 0);
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700849 if (ret < 0)
850 goto failed_cmap;
851
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700852 imxfb_set_par(info);
853 ret = register_framebuffer(info);
854 if (ret < 0) {
Pavel Pisaf99c8922006-01-07 10:44:32 +0000855 dev_err(&pdev->dev, "failed to register framebuffer\n");
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700856 goto failed_register;
857 }
858
859 imxfb_enable_controller(fbi);
Eric Bénard7a2bb232010-07-16 15:09:07 +0200860 fbi->pdev = pdev;
Eric Bénard81ef8062010-08-02 08:39:55 +0100861#ifdef PWMR_BACKLIGHT_AVAILABLE
Eric Bénard7a2bb232010-07-16 15:09:07 +0200862 imxfb_init_backlight(fbi);
Eric Bénard81ef8062010-08-02 08:39:55 +0100863#endif
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700864
865 return 0;
866
867failed_register:
868 fb_dealloc_cmap(&info->cmap);
869failed_cmap:
Sascha Hauerc0b90a32009-01-15 15:37:22 +0100870 if (pdata->exit)
871 pdata->exit(fbi->pdev);
872failed_platform_init:
Sascha Hauer27889272008-12-16 11:44:09 +0100873 if (!pdata->fixed_screen_cpu)
Russell King3ae5eae2005-11-09 22:32:44 +0000874 dma_free_writecombine(&pdev->dev,fbi->map_size,fbi->map_cpu,
Juergen Beisert72330b02008-12-16 11:44:07 +0100875 fbi->map_dma);
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700876failed_map:
Sascha Hauerf909ef62009-01-15 15:21:00 +0100877 clk_put(fbi->clk);
878failed_getclock:
Juergen Beisert72330b02008-12-16 11:44:07 +0100879 iounmap(fbi->regs);
880failed_ioremap:
Sascha Hauerd6b51502009-06-29 11:41:09 +0200881 release_mem_region(res->start, resource_size(res));
Juergen Beisert72330b02008-12-16 11:44:07 +0100882failed_req:
883 kfree(info->pseudo_palette);
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700884failed_init:
Russell King3ae5eae2005-11-09 22:32:44 +0000885 platform_set_drvdata(pdev, NULL);
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700886 framebuffer_release(info);
887 return ret;
888}
889
Juergen Beisert72330b02008-12-16 11:44:07 +0100890static int __devexit imxfb_remove(struct platform_device *pdev)
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700891{
Sascha Hauerc0b90a32009-01-15 15:37:22 +0100892 struct imx_fb_platform_data *pdata;
Russell King3ae5eae2005-11-09 22:32:44 +0000893 struct fb_info *info = platform_get_drvdata(pdev);
Sascha Hauer772a9e62005-07-17 20:15:36 +0100894 struct imxfb_info *fbi = info->par;
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700895 struct resource *res;
896
897 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
898
Sascha Hauer772a9e62005-07-17 20:15:36 +0100899 imxfb_disable_controller(fbi);
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700900
Eric Bénard81ef8062010-08-02 08:39:55 +0100901#ifdef PWMR_BACKLIGHT_AVAILABLE
Eric Bénard7a2bb232010-07-16 15:09:07 +0200902 imxfb_exit_backlight(fbi);
Eric Bénard81ef8062010-08-02 08:39:55 +0100903#endif
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700904 unregister_framebuffer(info);
905
Sascha Hauerc0b90a32009-01-15 15:37:22 +0100906 pdata = pdev->dev.platform_data;
907 if (pdata->exit)
908 pdata->exit(fbi->pdev);
909
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700910 fb_dealloc_cmap(&info->cmap);
911 kfree(info->pseudo_palette);
912 framebuffer_release(info);
913
Juergen Beisert72330b02008-12-16 11:44:07 +0100914 iounmap(fbi->regs);
Sascha Hauerd6b51502009-06-29 11:41:09 +0200915 release_mem_region(res->start, resource_size(res));
Sascha Hauerf909ef62009-01-15 15:21:00 +0100916 clk_disable(fbi->clk);
917 clk_put(fbi->clk);
918
Russell King3ae5eae2005-11-09 22:32:44 +0000919 platform_set_drvdata(pdev, NULL);
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700920
921 return 0;
922}
923
Russell King3ae5eae2005-11-09 22:32:44 +0000924void imxfb_shutdown(struct platform_device * dev)
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700925{
Russell King3ae5eae2005-11-09 22:32:44 +0000926 struct fb_info *info = platform_get_drvdata(dev);
Sascha Hauer772a9e62005-07-17 20:15:36 +0100927 struct imxfb_info *fbi = info->par;
928 imxfb_disable_controller(fbi);
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700929}
930
Russell King3ae5eae2005-11-09 22:32:44 +0000931static struct platform_driver imxfb_driver = {
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700932 .suspend = imxfb_suspend,
933 .resume = imxfb_resume,
Juergen Beisert72330b02008-12-16 11:44:07 +0100934 .remove = __devexit_p(imxfb_remove),
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700935 .shutdown = imxfb_shutdown,
Russell King3ae5eae2005-11-09 22:32:44 +0000936 .driver = {
Juergen Beisert72330b02008-12-16 11:44:07 +0100937 .name = DRIVER_NAME,
Russell King3ae5eae2005-11-09 22:32:44 +0000938 },
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700939};
940
Sascha Hauer343684f2009-03-19 08:25:41 +0100941static int imxfb_setup(void)
942{
943#ifndef MODULE
944 char *opt, *options = NULL;
945
946 if (fb_get_options("imxfb", &options))
947 return -ENODEV;
948
949 if (!options || !*options)
950 return 0;
951
952 while ((opt = strsep(&options, ",")) != NULL) {
953 if (!*opt)
954 continue;
955 else
956 fb_mode = opt;
957 }
958#endif
959 return 0;
960}
961
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700962int __init imxfb_init(void)
963{
Sascha Hauer343684f2009-03-19 08:25:41 +0100964 int ret = imxfb_setup();
965
966 if (ret < 0)
967 return ret;
968
Juergen Beisert72330b02008-12-16 11:44:07 +0100969 return platform_driver_probe(&imxfb_driver, imxfb_probe);
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700970}
971
972static void __exit imxfb_cleanup(void)
973{
Russell King3ae5eae2005-11-09 22:32:44 +0000974 platform_driver_unregister(&imxfb_driver);
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700975}
976
977module_init(imxfb_init);
978module_exit(imxfb_cleanup);
979
980MODULE_DESCRIPTION("Motorola i.MX framebuffer driver");
981MODULE_AUTHOR("Sascha Hauer, Pengutronix");
982MODULE_LICENSE("GPL");