blob: 267c1ff9ebd9b8b841bc448cbf8b0005c9df1710 [file] [log] [blame]
Sascha Hauer7c2f891c2005-05-01 08:59:24 -07001/*
2 * linux/drivers/video/imxfb.c
3 *
4 * Freescale i.MX Frame Buffer device driver
5 *
6 * Copyright (C) 2004 Sascha Hauer, Pengutronix
7 * Based on acornfb.c Copyright (C) Russell King.
8 *
9 * This file is subject to the terms and conditions of the GNU General Public
10 * License. See the file COPYING in the main directory of this archive for
11 * more details.
12 *
13 * Please direct your questions and comments on this driver to the following
14 * email address:
15 *
16 * linux-arm-kernel@lists.arm.linux.org.uk
17 */
18
19//#define DEBUG 1
20
Sascha Hauer7c2f891c2005-05-01 08:59:24 -070021#include <linux/module.h>
22#include <linux/kernel.h>
Sascha Hauer7c2f891c2005-05-01 08:59:24 -070023#include <linux/errno.h>
24#include <linux/string.h>
25#include <linux/interrupt.h>
26#include <linux/slab.h>
27#include <linux/fb.h>
28#include <linux/delay.h>
29#include <linux/init.h>
30#include <linux/ioport.h>
31#include <linux/cpufreq.h>
Russell Kingd052d1b2005-10-29 19:07:23 +010032#include <linux/platform_device.h>
Sascha Hauer7c2f891c2005-05-01 08:59:24 -070033#include <linux/dma-mapping.h>
34
35#include <asm/hardware.h>
36#include <asm/io.h>
Sascha Hauer7c2f891c2005-05-01 08:59:24 -070037#include <asm/uaccess.h>
38#include <asm/arch/imxfb.h>
39
40/*
41 * Complain if VAR is out of range.
42 */
43#define DEBUG_VAR 1
44
45#include "imxfb.h"
46
47static struct imxfb_rgb def_rgb_16 = {
48 .red = { .offset = 8, .length = 4, },
49 .green = { .offset = 4, .length = 4, },
50 .blue = { .offset = 0, .length = 4, },
51 .transp = { .offset = 0, .length = 0, },
52};
53
54static struct imxfb_rgb def_rgb_8 = {
55 .red = { .offset = 0, .length = 8, },
56 .green = { .offset = 0, .length = 8, },
57 .blue = { .offset = 0, .length = 8, },
58 .transp = { .offset = 0, .length = 0, },
59};
60
61static int imxfb_activate_var(struct fb_var_screeninfo *var, struct fb_info *info);
62
63static inline u_int chan_to_field(u_int chan, struct fb_bitfield *bf)
64{
65 chan &= 0xffff;
66 chan >>= 16 - bf->length;
67 return chan << bf->offset;
68}
69
70#define LCDC_PALETTE(x) __REG2(IMX_LCDC_BASE+0x800, (x)<<2)
71static int
72imxfb_setpalettereg(u_int regno, u_int red, u_int green, u_int blue,
73 u_int trans, struct fb_info *info)
74{
75 struct imxfb_info *fbi = info->par;
76 u_int val, ret = 1;
77
78#define CNVT_TOHW(val,width) ((((val)<<(width))+0x7FFF-(val))>>16)
79 if (regno < fbi->palette_size) {
80 val = (CNVT_TOHW(red, 4) << 8) |
81 (CNVT_TOHW(green,4) << 4) |
82 CNVT_TOHW(blue, 4);
83
84 LCDC_PALETTE(regno) = val;
85 ret = 0;
86 }
87 return ret;
88}
89
90static int
91imxfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
92 u_int trans, struct fb_info *info)
93{
94 struct imxfb_info *fbi = info->par;
95 unsigned int val;
96 int ret = 1;
97
98 /*
99 * If inverse mode was selected, invert all the colours
100 * rather than the register number. The register number
101 * is what you poke into the framebuffer to produce the
102 * colour you requested.
103 */
104 if (fbi->cmap_inverse) {
105 red = 0xffff - red;
106 green = 0xffff - green;
107 blue = 0xffff - blue;
108 }
109
110 /*
111 * If greyscale is true, then we convert the RGB value
112 * to greyscale no mater what visual we are using.
113 */
114 if (info->var.grayscale)
115 red = green = blue = (19595 * red + 38470 * green +
116 7471 * blue) >> 16;
117
118 switch (info->fix.visual) {
119 case FB_VISUAL_TRUECOLOR:
120 /*
121 * 12 or 16-bit True Colour. We encode the RGB value
122 * according to the RGB bitfield information.
123 */
124 if (regno < 16) {
125 u32 *pal = info->pseudo_palette;
126
127 val = chan_to_field(red, &info->var.red);
128 val |= chan_to_field(green, &info->var.green);
129 val |= chan_to_field(blue, &info->var.blue);
130
131 pal[regno] = val;
132 ret = 0;
133 }
134 break;
135
136 case FB_VISUAL_STATIC_PSEUDOCOLOR:
137 case FB_VISUAL_PSEUDOCOLOR:
138 ret = imxfb_setpalettereg(regno, red, green, blue, trans, info);
139 break;
140 }
141
142 return ret;
143}
144
145/*
146 * imxfb_check_var():
147 * Round up in the following order: bits_per_pixel, xres,
148 * yres, xres_virtual, yres_virtual, xoffset, yoffset, grayscale,
149 * bitfields, horizontal timing, vertical timing.
150 */
151static int
152imxfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
153{
154 struct imxfb_info *fbi = info->par;
155 int rgbidx;
156
157 if (var->xres < MIN_XRES)
158 var->xres = MIN_XRES;
159 if (var->yres < MIN_YRES)
160 var->yres = MIN_YRES;
161 if (var->xres > fbi->max_xres)
162 var->xres = fbi->max_xres;
163 if (var->yres > fbi->max_yres)
164 var->yres = fbi->max_yres;
165 var->xres_virtual = max(var->xres_virtual, var->xres);
166 var->yres_virtual = max(var->yres_virtual, var->yres);
167
168 pr_debug("var->bits_per_pixel=%d\n", var->bits_per_pixel);
169 switch (var->bits_per_pixel) {
170 case 16:
171 rgbidx = RGB_16;
172 break;
173 case 8:
174 rgbidx = RGB_8;
175 break;
176 default:
177 rgbidx = RGB_16;
178 }
179
180 /*
181 * Copy the RGB parameters for this display
182 * from the machine specific parameters.
183 */
184 var->red = fbi->rgb[rgbidx]->red;
185 var->green = fbi->rgb[rgbidx]->green;
186 var->blue = fbi->rgb[rgbidx]->blue;
187 var->transp = fbi->rgb[rgbidx]->transp;
188
189 pr_debug("RGBT length = %d:%d:%d:%d\n",
190 var->red.length, var->green.length, var->blue.length,
191 var->transp.length);
192
193 pr_debug("RGBT offset = %d:%d:%d:%d\n",
194 var->red.offset, var->green.offset, var->blue.offset,
195 var->transp.offset);
196
197 return 0;
198}
199
200/*
201 * imxfb_set_par():
202 * Set the user defined part of the display for the specified console
203 */
204static int imxfb_set_par(struct fb_info *info)
205{
206 struct imxfb_info *fbi = info->par;
207 struct fb_var_screeninfo *var = &info->var;
208
209 pr_debug("set_par\n");
210
211 if (var->bits_per_pixel == 16)
212 info->fix.visual = FB_VISUAL_TRUECOLOR;
213 else if (!fbi->cmap_static)
214 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
215 else {
216 /*
217 * Some people have weird ideas about wanting static
218 * pseudocolor maps. I suspect their user space
219 * applications are broken.
220 */
221 info->fix.visual = FB_VISUAL_STATIC_PSEUDOCOLOR;
222 }
223
224 info->fix.line_length = var->xres_virtual *
225 var->bits_per_pixel / 8;
226 fbi->palette_size = var->bits_per_pixel == 8 ? 256 : 16;
227
228 imxfb_activate_var(var, info);
229
230 return 0;
231}
232
233static void imxfb_enable_controller(struct imxfb_info *fbi)
234{
235 pr_debug("Enabling LCD controller\n");
236
237 /* initialize LCDC */
238 LCDC_RMCR &= ~RMCR_LCDC_EN; /* just to be safe... */
239
240 LCDC_SSA = fbi->screen_dma;
241 /* physical screen start address */
242 LCDC_VPW = VPW_VPW(fbi->max_xres * fbi->max_bpp / 8 / 4);
243
244 LCDC_POS = 0x00000000; /* panning offset 0 (0 pixel offset) */
245
246 /* disable hardware cursor */
247 LCDC_CPOS &= ~(CPOS_CC0 | CPOS_CC1);
248
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700249 LCDC_RMCR = RMCR_LCDC_EN;
250
251 if(fbi->backlight_power)
252 fbi->backlight_power(1);
253 if(fbi->lcd_power)
254 fbi->lcd_power(1);
255}
256
257static void imxfb_disable_controller(struct imxfb_info *fbi)
258{
259 pr_debug("Disabling LCD controller\n");
260
261 if(fbi->backlight_power)
262 fbi->backlight_power(0);
263 if(fbi->lcd_power)
264 fbi->lcd_power(0);
265
266 LCDC_RMCR = 0;
267}
268
269static int imxfb_blank(int blank, struct fb_info *info)
270{
271 struct imxfb_info *fbi = info->par;
272
273 pr_debug("imxfb_blank: blank=%d\n", blank);
274
275 switch (blank) {
276 case FB_BLANK_POWERDOWN:
277 case FB_BLANK_VSYNC_SUSPEND:
278 case FB_BLANK_HSYNC_SUSPEND:
279 case FB_BLANK_NORMAL:
280 imxfb_disable_controller(fbi);
281 break;
282
283 case FB_BLANK_UNBLANK:
284 imxfb_enable_controller(fbi);
285 break;
286 }
287 return 0;
288}
289
290static struct fb_ops imxfb_ops = {
291 .owner = THIS_MODULE,
292 .fb_check_var = imxfb_check_var,
293 .fb_set_par = imxfb_set_par,
294 .fb_setcolreg = imxfb_setcolreg,
295 .fb_fillrect = cfb_fillrect,
296 .fb_copyarea = cfb_copyarea,
297 .fb_imageblit = cfb_imageblit,
298 .fb_blank = imxfb_blank,
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700299};
300
301/*
302 * imxfb_activate_var():
303 * Configures LCD Controller based on entries in var parameter. Settings are
304 * only written to the controller if changes were made.
305 */
306static int imxfb_activate_var(struct fb_var_screeninfo *var, struct fb_info *info)
307{
308 struct imxfb_info *fbi = info->par;
309 pr_debug("var: xres=%d hslen=%d lm=%d rm=%d\n",
310 var->xres, var->hsync_len,
311 var->left_margin, var->right_margin);
312 pr_debug("var: yres=%d vslen=%d um=%d bm=%d\n",
313 var->yres, var->vsync_len,
314 var->upper_margin, var->lower_margin);
315
316#if DEBUG_VAR
317 if (var->xres < 16 || var->xres > 1024)
318 printk(KERN_ERR "%s: invalid xres %d\n",
319 info->fix.id, var->xres);
320 if (var->hsync_len < 1 || var->hsync_len > 64)
321 printk(KERN_ERR "%s: invalid hsync_len %d\n",
322 info->fix.id, var->hsync_len);
323 if (var->left_margin > 255)
324 printk(KERN_ERR "%s: invalid left_margin %d\n",
325 info->fix.id, var->left_margin);
326 if (var->right_margin > 255)
327 printk(KERN_ERR "%s: invalid right_margin %d\n",
328 info->fix.id, var->right_margin);
329 if (var->yres < 1 || var->yres > 511)
330 printk(KERN_ERR "%s: invalid yres %d\n",
331 info->fix.id, var->yres);
332 if (var->vsync_len > 100)
333 printk(KERN_ERR "%s: invalid vsync_len %d\n",
334 info->fix.id, var->vsync_len);
335 if (var->upper_margin > 63)
336 printk(KERN_ERR "%s: invalid upper_margin %d\n",
337 info->fix.id, var->upper_margin);
338 if (var->lower_margin > 255)
339 printk(KERN_ERR "%s: invalid lower_margin %d\n",
340 info->fix.id, var->lower_margin);
341#endif
342
343 LCDC_HCR = HCR_H_WIDTH(var->hsync_len) |
344 HCR_H_WAIT_1(var->left_margin) |
345 HCR_H_WAIT_2(var->right_margin);
346
347 LCDC_VCR = VCR_V_WIDTH(var->vsync_len) |
348 VCR_V_WAIT_1(var->upper_margin) |
349 VCR_V_WAIT_2(var->lower_margin);
350
351 LCDC_SIZE = SIZE_XMAX(var->xres) | SIZE_YMAX(var->yres);
352 LCDC_PCR = fbi->pcr;
353 LCDC_PWMR = fbi->pwmr;
354 LCDC_LSCR1 = fbi->lscr1;
Sascha Hauer772a9e62005-07-17 20:15:36 +0100355 LCDC_DMACR = fbi->dmacr;
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700356
357 return 0;
358}
359
360static void imxfb_setup_gpio(struct imxfb_info *fbi)
361{
362 int width;
363
364 LCDC_RMCR &= ~(RMCR_LCDC_EN | RMCR_SELF_REF);
365
366 if( fbi->pcr & PCR_TFT )
367 width = 16;
368 else
369 width = 1 << ((fbi->pcr >> 28) & 0x3);
370
371 switch(width) {
372 case 16:
373 imx_gpio_mode(PD30_PF_LD15);
374 imx_gpio_mode(PD29_PF_LD14);
375 imx_gpio_mode(PD28_PF_LD13);
376 imx_gpio_mode(PD27_PF_LD12);
377 imx_gpio_mode(PD26_PF_LD11);
378 imx_gpio_mode(PD25_PF_LD10);
379 imx_gpio_mode(PD24_PF_LD9);
380 imx_gpio_mode(PD23_PF_LD8);
381 case 8:
382 imx_gpio_mode(PD22_PF_LD7);
383 imx_gpio_mode(PD21_PF_LD6);
384 imx_gpio_mode(PD20_PF_LD5);
385 imx_gpio_mode(PD19_PF_LD4);
386 case 4:
387 imx_gpio_mode(PD18_PF_LD3);
388 imx_gpio_mode(PD17_PF_LD2);
389 case 2:
390 imx_gpio_mode(PD16_PF_LD1);
391 case 1:
392 imx_gpio_mode(PD15_PF_LD0);
393 }
394
395 /* initialize GPIOs */
396 imx_gpio_mode(PD6_PF_LSCLK);
397 imx_gpio_mode(PD10_PF_SPL_SPR);
398 imx_gpio_mode(PD11_PF_CONTRAST);
399 imx_gpio_mode(PD14_PF_FLM_VSYNC);
400 imx_gpio_mode(PD13_PF_LP_HSYNC);
401 imx_gpio_mode(PD7_PF_REV);
402 imx_gpio_mode(PD8_PF_CLS);
403
404#ifndef CONFIG_MACH_PIMX1
405 /* on PiMX1 used as buffers enable signal
406 */
407 imx_gpio_mode(PD9_PF_PS);
408#endif
409
410#ifndef CONFIG_MACH_MX1FS2
411 /* on mx1fs2 this pin is used to (de)activate the display, so we need
412 * it as a normal gpio
413 */
414 imx_gpio_mode(PD12_PF_ACD_OE);
415#endif
416
417}
418
419#ifdef CONFIG_PM
420/*
421 * Power management hooks. Note that we won't be called from IRQ context,
422 * unlike the blank functions above, so we may sleep.
423 */
Russell King3ae5eae2005-11-09 22:32:44 +0000424static int imxfb_suspend(struct platform_device *dev, pm_message_t state)
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700425{
Russell King3ae5eae2005-11-09 22:32:44 +0000426 struct imxfb_info *fbi = platform_get_drvdata(dev);
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700427 pr_debug("%s\n",__FUNCTION__);
428
Russell King9480e302005-10-28 09:52:56 -0700429 imxfb_disable_controller(fbi);
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700430 return 0;
431}
432
Russell King3ae5eae2005-11-09 22:32:44 +0000433static int imxfb_resume(struct platform_device *dev)
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700434{
Russell King3ae5eae2005-11-09 22:32:44 +0000435 struct imxfb_info *fbi = platform_get_drvdata(dev);
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700436 pr_debug("%s\n",__FUNCTION__);
437
Russell King9480e302005-10-28 09:52:56 -0700438 imxfb_enable_controller(fbi);
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700439 return 0;
440}
441#else
442#define imxfb_suspend NULL
443#define imxfb_resume NULL
444#endif
445
446static int __init imxfb_init_fbinfo(struct device *dev)
447{
448 struct imxfb_mach_info *inf = dev->platform_data;
449 struct fb_info *info = dev_get_drvdata(dev);
450 struct imxfb_info *fbi = info->par;
451
452 pr_debug("%s\n",__FUNCTION__);
453
454 info->pseudo_palette = kmalloc( sizeof(u32) * 16, GFP_KERNEL);
455 if (!info->pseudo_palette)
456 return -ENOMEM;
457
458 memset(fbi, 0, sizeof(struct imxfb_info));
459 fbi->dev = dev;
460
461 strlcpy(info->fix.id, IMX_NAME, sizeof(info->fix.id));
462
463 info->fix.type = FB_TYPE_PACKED_PIXELS;
464 info->fix.type_aux = 0;
465 info->fix.xpanstep = 0;
466 info->fix.ypanstep = 0;
467 info->fix.ywrapstep = 0;
468 info->fix.accel = FB_ACCEL_NONE;
469
470 info->var.nonstd = 0;
471 info->var.activate = FB_ACTIVATE_NOW;
472 info->var.height = -1;
473 info->var.width = -1;
474 info->var.accel_flags = 0;
475 info->var.vmode = FB_VMODE_NONINTERLACED;
476
477 info->fbops = &imxfb_ops;
478 info->flags = FBINFO_FLAG_DEFAULT;
479 info->pseudo_palette = (fbi + 1);
480
481 fbi->rgb[RGB_16] = &def_rgb_16;
482 fbi->rgb[RGB_8] = &def_rgb_8;
483
484 fbi->max_xres = inf->xres;
485 info->var.xres = inf->xres;
486 info->var.xres_virtual = inf->xres;
487 fbi->max_yres = inf->yres;
488 info->var.yres = inf->yres;
489 info->var.yres_virtual = inf->yres;
490 fbi->max_bpp = inf->bpp;
491 info->var.bits_per_pixel = inf->bpp;
492 info->var.pixclock = inf->pixclock;
493 info->var.hsync_len = inf->hsync_len;
494 info->var.left_margin = inf->left_margin;
495 info->var.right_margin = inf->right_margin;
496 info->var.vsync_len = inf->vsync_len;
497 info->var.upper_margin = inf->upper_margin;
498 info->var.lower_margin = inf->lower_margin;
499 info->var.sync = inf->sync;
500 info->var.grayscale = inf->cmap_greyscale;
501 fbi->cmap_inverse = inf->cmap_inverse;
502 fbi->pcr = inf->pcr;
503 fbi->lscr1 = inf->lscr1;
Sascha Hauer772a9e62005-07-17 20:15:36 +0100504 fbi->dmacr = inf->dmacr;
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700505 fbi->pwmr = inf->pwmr;
506 fbi->lcd_power = inf->lcd_power;
507 fbi->backlight_power = inf->backlight_power;
508 info->fix.smem_len = fbi->max_xres * fbi->max_yres *
509 fbi->max_bpp / 8;
510
511 return 0;
512}
513
514/*
515 * Allocates the DRAM memory for the frame buffer. This buffer is
516 * remapped into a non-cached, non-buffered, memory region to
517 * allow pixel writes to occur without flushing the cache.
518 * Once this area is remapped, all virtual memory access to the
519 * video memory should occur at the new region.
520 */
521static int __init imxfb_map_video_memory(struct fb_info *info)
522{
523 struct imxfb_info *fbi = info->par;
524
525 fbi->map_size = PAGE_ALIGN(info->fix.smem_len);
526 fbi->map_cpu = dma_alloc_writecombine(fbi->dev, fbi->map_size,
527 &fbi->map_dma,GFP_KERNEL);
528
529 if (fbi->map_cpu) {
530 info->screen_base = fbi->map_cpu;
531 fbi->screen_cpu = fbi->map_cpu;
532 fbi->screen_dma = fbi->map_dma;
533 info->fix.smem_start = fbi->screen_dma;
534 }
535
536 return fbi->map_cpu ? 0 : -ENOMEM;
537}
538
Russell King3ae5eae2005-11-09 22:32:44 +0000539static int __init imxfb_probe(struct platform_device *pdev)
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700540{
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700541 struct imxfb_info *fbi;
542 struct fb_info *info;
543 struct imxfb_mach_info *inf;
544 struct resource *res;
545 int ret;
546
547 printk("i.MX Framebuffer driver\n");
548
549 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
550 if(!res)
551 return -ENODEV;
552
Russell King3ae5eae2005-11-09 22:32:44 +0000553 inf = pdev->dev.platform_data;
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700554 if(!inf) {
Pavel Pisaf99c8922006-01-07 10:44:32 +0000555 dev_err(&pdev->dev,"No platform_data available\n");
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700556 return -ENOMEM;
557 }
558
Russell King3ae5eae2005-11-09 22:32:44 +0000559 info = framebuffer_alloc(sizeof(struct imxfb_info), &pdev->dev);
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700560 if(!info)
561 return -ENOMEM;
562
563 fbi = info->par;
564
Russell King3ae5eae2005-11-09 22:32:44 +0000565 platform_set_drvdata(pdev, info);
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700566
Russell King3ae5eae2005-11-09 22:32:44 +0000567 ret = imxfb_init_fbinfo(&pdev->dev);
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700568 if( ret < 0 )
569 goto failed_init;
570
571 res = request_mem_region(res->start, res->end - res->start + 1, "IMXFB");
572 if (!res) {
573 ret = -EBUSY;
574 goto failed_regs;
575 }
576
577 if (!inf->fixed_screen_cpu) {
578 ret = imxfb_map_video_memory(info);
579 if (ret) {
Pavel Pisaf99c8922006-01-07 10:44:32 +0000580 dev_err(&pdev->dev, "Failed to allocate video RAM: %d\n", ret);
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700581 ret = -ENOMEM;
582 goto failed_map;
583 }
584 } else {
585 /* Fixed framebuffer mapping enables location of the screen in eSRAM */
586 fbi->map_cpu = inf->fixed_screen_cpu;
587 fbi->map_dma = inf->fixed_screen_dma;
588 info->screen_base = fbi->map_cpu;
589 fbi->screen_cpu = fbi->map_cpu;
590 fbi->screen_dma = fbi->map_dma;
591 info->fix.smem_start = fbi->screen_dma;
592 }
593
594 /*
595 * This makes sure that our colour bitfield
596 * descriptors are correctly initialised.
597 */
598 imxfb_check_var(&info->var, info);
599
600 ret = fb_alloc_cmap(&info->cmap, 1<<info->var.bits_per_pixel, 0);
601 if (ret < 0)
602 goto failed_cmap;
603
604 imxfb_setup_gpio(fbi);
605
606 imxfb_set_par(info);
607 ret = register_framebuffer(info);
608 if (ret < 0) {
Pavel Pisaf99c8922006-01-07 10:44:32 +0000609 dev_err(&pdev->dev, "failed to register framebuffer\n");
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700610 goto failed_register;
611 }
612
613 imxfb_enable_controller(fbi);
614
615 return 0;
616
617failed_register:
618 fb_dealloc_cmap(&info->cmap);
619failed_cmap:
620 if (!inf->fixed_screen_cpu)
Russell King3ae5eae2005-11-09 22:32:44 +0000621 dma_free_writecombine(&pdev->dev,fbi->map_size,fbi->map_cpu,
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700622 fbi->map_dma);
623failed_map:
624 kfree(info->pseudo_palette);
625failed_regs:
626 release_mem_region(res->start, res->end - res->start);
627failed_init:
Russell King3ae5eae2005-11-09 22:32:44 +0000628 platform_set_drvdata(pdev, NULL);
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700629 framebuffer_release(info);
630 return ret;
631}
632
Russell King3ae5eae2005-11-09 22:32:44 +0000633static int imxfb_remove(struct platform_device *pdev)
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700634{
Russell King3ae5eae2005-11-09 22:32:44 +0000635 struct fb_info *info = platform_get_drvdata(pdev);
Sascha Hauer772a9e62005-07-17 20:15:36 +0100636 struct imxfb_info *fbi = info->par;
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700637 struct resource *res;
638
639 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
640
Sascha Hauer772a9e62005-07-17 20:15:36 +0100641 imxfb_disable_controller(fbi);
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700642
643 unregister_framebuffer(info);
644
645 fb_dealloc_cmap(&info->cmap);
646 kfree(info->pseudo_palette);
647 framebuffer_release(info);
648
649 release_mem_region(res->start, res->end - res->start + 1);
Russell King3ae5eae2005-11-09 22:32:44 +0000650 platform_set_drvdata(pdev, NULL);
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700651
652 return 0;
653}
654
Russell King3ae5eae2005-11-09 22:32:44 +0000655void imxfb_shutdown(struct platform_device * dev)
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700656{
Russell King3ae5eae2005-11-09 22:32:44 +0000657 struct fb_info *info = platform_get_drvdata(dev);
Sascha Hauer772a9e62005-07-17 20:15:36 +0100658 struct imxfb_info *fbi = info->par;
659 imxfb_disable_controller(fbi);
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700660}
661
Russell King3ae5eae2005-11-09 22:32:44 +0000662static struct platform_driver imxfb_driver = {
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700663 .probe = imxfb_probe,
664 .suspend = imxfb_suspend,
665 .resume = imxfb_resume,
666 .remove = imxfb_remove,
667 .shutdown = imxfb_shutdown,
Russell King3ae5eae2005-11-09 22:32:44 +0000668 .driver = {
669 .name = "imx-fb",
670 },
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700671};
672
673int __init imxfb_init(void)
674{
Russell King3ae5eae2005-11-09 22:32:44 +0000675 return platform_driver_register(&imxfb_driver);
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700676}
677
678static void __exit imxfb_cleanup(void)
679{
Russell King3ae5eae2005-11-09 22:32:44 +0000680 platform_driver_unregister(&imxfb_driver);
Sascha Hauer7c2f891c2005-05-01 08:59:24 -0700681}
682
683module_init(imxfb_init);
684module_exit(imxfb_cleanup);
685
686MODULE_DESCRIPTION("Motorola i.MX framebuffer driver");
687MODULE_AUTHOR("Sascha Hauer, Pengutronix");
688MODULE_LICENSE("GPL");