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