i.MX Framebuffer: Use readl/writel instead of direct pointer deref
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / video / imxfb.c
CommitLineData
7c2f891c
SH
1/*
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
7c2f891c 19
7c2f891c
SH
20#include <linux/module.h>
21#include <linux/kernel.h>
7c2f891c
SH
22#include <linux/errno.h>
23#include <linux/string.h>
24#include <linux/interrupt.h>
25#include <linux/slab.h>
27ac792c 26#include <linux/mm.h>
7c2f891c
SH
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>
d052d1be 32#include <linux/platform_device.h>
7c2f891c 33#include <linux/dma-mapping.h>
72330b0e 34#include <linux/io.h>
7c2f891c 35
a09e64fb 36#include <mach/imxfb.h>
7c2f891c
SH
37
38/*
39 * Complain if VAR is out of range.
40 */
41#define DEBUG_VAR 1
42
43#include "imxfb.h"
44
72330b0e
JB
45#define DRIVER_NAME "imx-fb"
46
47#define LCDC_SSA 0x00
48
49#define LCDC_SIZE 0x04
50#define SIZE_XMAX(x) ((((x) >> 4) & 0x3f) << 20)
51#define SIZE_YMAX(y) ((y) & 0x1ff)
52
53#define LCDC_VPW 0x08
54#define VPW_VPW(x) ((x) & 0x3ff)
55
56#define LCDC_CPOS 0x0C
57#define CPOS_CC1 (1<<31)
58#define CPOS_CC0 (1<<30)
59#define CPOS_OP (1<<28)
60#define CPOS_CXP(x) (((x) & 3ff) << 16)
61#define CPOS_CYP(y) ((y) & 0x1ff)
62
63#define LCDC_LCWHB 0x10
64#define LCWHB_BK_EN (1<<31)
65#define LCWHB_CW(w) (((w) & 0x1f) << 24)
66#define LCWHB_CH(h) (((h) & 0x1f) << 16)
67#define LCWHB_BD(x) ((x) & 0xff)
68
69#define LCDC_LCHCC 0x14
70#define LCHCC_CUR_COL_R(r) (((r) & 0x1f) << 11)
71#define LCHCC_CUR_COL_G(g) (((g) & 0x3f) << 5)
72#define LCHCC_CUR_COL_B(b) ((b) & 0x1f)
73
74#define LCDC_PCR 0x18
75
76#define LCDC_HCR 0x1C
77#define HCR_H_WIDTH(x) (((x) & 0x3f) << 26)
78#define HCR_H_WAIT_1(x) (((x) & 0xff) << 8)
79#define HCR_H_WAIT_2(x) ((x) & 0xff)
80
81#define LCDC_VCR 0x20
82#define VCR_V_WIDTH(x) (((x) & 0x3f) << 26)
83#define VCR_V_WAIT_1(x) (((x) & 0xff) << 8)
84#define VCR_V_WAIT_2(x) ((x) & 0xff)
85
86#define LCDC_POS 0x24
87#define POS_POS(x) ((x) & 1f)
88
89#define LCDC_LSCR1 0x28
90/* bit fields in imxfb.h */
91
92#define LCDC_PWMR 0x2C
93/* bit fields in imxfb.h */
94
95#define LCDC_DMACR 0x30
96/* bit fields in imxfb.h */
97
98#define LCDC_RMCR 0x34
99#define RMCR_LCDC_EN (1<<1)
100#define RMCR_SELF_REF (1<<0)
101
102#define LCDC_LCDICR 0x38
103#define LCDICR_INT_SYN (1<<2)
104#define LCDICR_INT_CON (1)
105
106#define LCDC_LCDISR 0x40
107#define LCDISR_UDR_ERR (1<<3)
108#define LCDISR_ERR_RES (1<<2)
109#define LCDISR_EOF (1<<1)
110#define LCDISR_BOF (1<<0)
111
7c2f891c
SH
112static struct imxfb_rgb def_rgb_16 = {
113 .red = { .offset = 8, .length = 4, },
114 .green = { .offset = 4, .length = 4, },
115 .blue = { .offset = 0, .length = 4, },
116 .transp = { .offset = 0, .length = 0, },
117};
118
119static struct imxfb_rgb def_rgb_8 = {
120 .red = { .offset = 0, .length = 8, },
121 .green = { .offset = 0, .length = 8, },
122 .blue = { .offset = 0, .length = 8, },
123 .transp = { .offset = 0, .length = 0, },
124};
125
126static int imxfb_activate_var(struct fb_var_screeninfo *var, struct fb_info *info);
127
128static inline u_int chan_to_field(u_int chan, struct fb_bitfield *bf)
129{
130 chan &= 0xffff;
131 chan >>= 16 - bf->length;
132 return chan << bf->offset;
133}
134
7c2f891c
SH
135static int
136imxfb_setpalettereg(u_int regno, u_int red, u_int green, u_int blue,
137 u_int trans, struct fb_info *info)
138{
139 struct imxfb_info *fbi = info->par;
140 u_int val, ret = 1;
141
142#define CNVT_TOHW(val,width) ((((val)<<(width))+0x7FFF-(val))>>16)
143 if (regno < fbi->palette_size) {
144 val = (CNVT_TOHW(red, 4) << 8) |
145 (CNVT_TOHW(green,4) << 4) |
146 CNVT_TOHW(blue, 4);
147
72330b0e 148 writel(val, fbi->regs + 0x800 + (regno << 2));
7c2f891c
SH
149 ret = 0;
150 }
151 return ret;
152}
153
154static int
155imxfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
156 u_int trans, struct fb_info *info)
157{
158 struct imxfb_info *fbi = info->par;
159 unsigned int val;
160 int ret = 1;
161
162 /*
163 * If inverse mode was selected, invert all the colours
164 * rather than the register number. The register number
165 * is what you poke into the framebuffer to produce the
166 * colour you requested.
167 */
168 if (fbi->cmap_inverse) {
169 red = 0xffff - red;
170 green = 0xffff - green;
171 blue = 0xffff - blue;
172 }
173
174 /*
175 * If greyscale is true, then we convert the RGB value
176 * to greyscale no mater what visual we are using.
177 */
178 if (info->var.grayscale)
179 red = green = blue = (19595 * red + 38470 * green +
180 7471 * blue) >> 16;
181
182 switch (info->fix.visual) {
183 case FB_VISUAL_TRUECOLOR:
184 /*
185 * 12 or 16-bit True Colour. We encode the RGB value
186 * according to the RGB bitfield information.
187 */
188 if (regno < 16) {
189 u32 *pal = info->pseudo_palette;
190
191 val = chan_to_field(red, &info->var.red);
192 val |= chan_to_field(green, &info->var.green);
193 val |= chan_to_field(blue, &info->var.blue);
194
195 pal[regno] = val;
196 ret = 0;
197 }
198 break;
199
200 case FB_VISUAL_STATIC_PSEUDOCOLOR:
201 case FB_VISUAL_PSEUDOCOLOR:
202 ret = imxfb_setpalettereg(regno, red, green, blue, trans, info);
203 break;
204 }
205
206 return ret;
207}
208
209/*
210 * imxfb_check_var():
211 * Round up in the following order: bits_per_pixel, xres,
212 * yres, xres_virtual, yres_virtual, xoffset, yoffset, grayscale,
213 * bitfields, horizontal timing, vertical timing.
214 */
215static int
216imxfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
217{
218 struct imxfb_info *fbi = info->par;
219 int rgbidx;
220
221 if (var->xres < MIN_XRES)
222 var->xres = MIN_XRES;
223 if (var->yres < MIN_YRES)
224 var->yres = MIN_YRES;
225 if (var->xres > fbi->max_xres)
226 var->xres = fbi->max_xres;
227 if (var->yres > fbi->max_yres)
228 var->yres = fbi->max_yres;
229 var->xres_virtual = max(var->xres_virtual, var->xres);
230 var->yres_virtual = max(var->yres_virtual, var->yres);
231
232 pr_debug("var->bits_per_pixel=%d\n", var->bits_per_pixel);
233 switch (var->bits_per_pixel) {
234 case 16:
235 rgbidx = RGB_16;
236 break;
237 case 8:
238 rgbidx = RGB_8;
239 break;
240 default:
241 rgbidx = RGB_16;
242 }
243
244 /*
245 * Copy the RGB parameters for this display
246 * from the machine specific parameters.
247 */
248 var->red = fbi->rgb[rgbidx]->red;
249 var->green = fbi->rgb[rgbidx]->green;
250 var->blue = fbi->rgb[rgbidx]->blue;
251 var->transp = fbi->rgb[rgbidx]->transp;
252
253 pr_debug("RGBT length = %d:%d:%d:%d\n",
254 var->red.length, var->green.length, var->blue.length,
255 var->transp.length);
256
257 pr_debug("RGBT offset = %d:%d:%d:%d\n",
258 var->red.offset, var->green.offset, var->blue.offset,
259 var->transp.offset);
260
261 return 0;
262}
263
264/*
265 * imxfb_set_par():
266 * Set the user defined part of the display for the specified console
267 */
268static int imxfb_set_par(struct fb_info *info)
269{
270 struct imxfb_info *fbi = info->par;
271 struct fb_var_screeninfo *var = &info->var;
272
273 pr_debug("set_par\n");
274
275 if (var->bits_per_pixel == 16)
276 info->fix.visual = FB_VISUAL_TRUECOLOR;
277 else if (!fbi->cmap_static)
278 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
279 else {
280 /*
281 * Some people have weird ideas about wanting static
282 * pseudocolor maps. I suspect their user space
283 * applications are broken.
284 */
285 info->fix.visual = FB_VISUAL_STATIC_PSEUDOCOLOR;
286 }
287
288 info->fix.line_length = var->xres_virtual *
289 var->bits_per_pixel / 8;
290 fbi->palette_size = var->bits_per_pixel == 8 ? 256 : 16;
291
292 imxfb_activate_var(var, info);
293
294 return 0;
295}
296
297static void imxfb_enable_controller(struct imxfb_info *fbi)
298{
299 pr_debug("Enabling LCD controller\n");
300
301 /* initialize LCDC */
72330b0e
JB
302 writel(readl(fbi->regs + LCDC_RMCR) & ~RMCR_LCDC_EN,
303 fbi->regs + LCDC_RMCR); /* just to be safe... */
304
305 writel(fbi->screen_dma, fbi->regs + LCDC_SSA);
7c2f891c 306
7c2f891c 307 /* physical screen start address */
72330b0e
JB
308 writel(VPW_VPW(fbi->max_xres * fbi->max_bpp / 8 / 4),
309 fbi->regs + LCDC_VPW);
7c2f891c 310
72330b0e
JB
311 /* panning offset 0 (0 pixel offset) */
312 writel(0x00000000, fbi->regs + LCDC_POS);
7c2f891c
SH
313
314 /* disable hardware cursor */
72330b0e
JB
315 writel(readl(fbi->regs + LCDC_CPOS) & ~(CPOS_CC0 | CPOS_CC1),
316 fbi->regs + LCDC_CPOS);
7c2f891c 317
72330b0e 318 writel(RMCR_LCDC_EN, fbi->regs + LCDC_RMCR);
7c2f891c
SH
319
320 if(fbi->backlight_power)
321 fbi->backlight_power(1);
322 if(fbi->lcd_power)
323 fbi->lcd_power(1);
324}
325
326static void imxfb_disable_controller(struct imxfb_info *fbi)
327{
328 pr_debug("Disabling LCD controller\n");
329
330 if(fbi->backlight_power)
331 fbi->backlight_power(0);
332 if(fbi->lcd_power)
333 fbi->lcd_power(0);
334
72330b0e 335 writel(0, fbi->regs + LCDC_RMCR);
7c2f891c
SH
336}
337
338static int imxfb_blank(int blank, struct fb_info *info)
339{
340 struct imxfb_info *fbi = info->par;
341
342 pr_debug("imxfb_blank: blank=%d\n", blank);
343
344 switch (blank) {
345 case FB_BLANK_POWERDOWN:
346 case FB_BLANK_VSYNC_SUSPEND:
347 case FB_BLANK_HSYNC_SUSPEND:
348 case FB_BLANK_NORMAL:
349 imxfb_disable_controller(fbi);
350 break;
351
352 case FB_BLANK_UNBLANK:
353 imxfb_enable_controller(fbi);
354 break;
355 }
356 return 0;
357}
358
359static struct fb_ops imxfb_ops = {
360 .owner = THIS_MODULE,
361 .fb_check_var = imxfb_check_var,
362 .fb_set_par = imxfb_set_par,
363 .fb_setcolreg = imxfb_setcolreg,
364 .fb_fillrect = cfb_fillrect,
365 .fb_copyarea = cfb_copyarea,
366 .fb_imageblit = cfb_imageblit,
367 .fb_blank = imxfb_blank,
7c2f891c
SH
368};
369
370/*
371 * imxfb_activate_var():
372 * Configures LCD Controller based on entries in var parameter. Settings are
373 * only written to the controller if changes were made.
374 */
375static int imxfb_activate_var(struct fb_var_screeninfo *var, struct fb_info *info)
376{
377 struct imxfb_info *fbi = info->par;
378 pr_debug("var: xres=%d hslen=%d lm=%d rm=%d\n",
379 var->xres, var->hsync_len,
380 var->left_margin, var->right_margin);
381 pr_debug("var: yres=%d vslen=%d um=%d bm=%d\n",
382 var->yres, var->vsync_len,
383 var->upper_margin, var->lower_margin);
384
385#if DEBUG_VAR
386 if (var->xres < 16 || var->xres > 1024)
387 printk(KERN_ERR "%s: invalid xres %d\n",
388 info->fix.id, var->xres);
389 if (var->hsync_len < 1 || var->hsync_len > 64)
390 printk(KERN_ERR "%s: invalid hsync_len %d\n",
391 info->fix.id, var->hsync_len);
392 if (var->left_margin > 255)
393 printk(KERN_ERR "%s: invalid left_margin %d\n",
394 info->fix.id, var->left_margin);
395 if (var->right_margin > 255)
396 printk(KERN_ERR "%s: invalid right_margin %d\n",
397 info->fix.id, var->right_margin);
398 if (var->yres < 1 || var->yres > 511)
399 printk(KERN_ERR "%s: invalid yres %d\n",
400 info->fix.id, var->yres);
401 if (var->vsync_len > 100)
402 printk(KERN_ERR "%s: invalid vsync_len %d\n",
403 info->fix.id, var->vsync_len);
404 if (var->upper_margin > 63)
405 printk(KERN_ERR "%s: invalid upper_margin %d\n",
406 info->fix.id, var->upper_margin);
407 if (var->lower_margin > 255)
408 printk(KERN_ERR "%s: invalid lower_margin %d\n",
409 info->fix.id, var->lower_margin);
410#endif
411
72330b0e
JB
412 writel(HCR_H_WIDTH(var->hsync_len) |
413 HCR_H_WAIT_1(var->left_margin) |
414 HCR_H_WAIT_2(var->right_margin),
415 fbi->regs + LCDC_HCR);
7c2f891c 416
72330b0e
JB
417 writel(VCR_V_WIDTH(var->vsync_len) |
418 VCR_V_WAIT_1(var->upper_margin) |
419 VCR_V_WAIT_2(var->lower_margin),
420 fbi->regs + LCDC_VCR);
7c2f891c 421
72330b0e
JB
422 writel(SIZE_XMAX(var->xres) | SIZE_YMAX(var->yres),
423 fbi->regs + LCDC_SIZE);
424 writel(fbi->pcr, fbi->regs + LCDC_PCR);
425 writel(fbi->pwmr, fbi->regs + LCDC_PWMR);
426 writel(fbi->lscr1, fbi->regs + LCDC_LSCR1);
427 writel(fbi->dmacr, fbi->regs + LCDC_DMACR);
7c2f891c
SH
428
429 return 0;
430}
431
7c2f891c
SH
432#ifdef CONFIG_PM
433/*
434 * Power management hooks. Note that we won't be called from IRQ context,
435 * unlike the blank functions above, so we may sleep.
436 */
3ae5eaec 437static int imxfb_suspend(struct platform_device *dev, pm_message_t state)
7c2f891c 438{
3ae5eaec 439 struct imxfb_info *fbi = platform_get_drvdata(dev);
5ae12170 440 pr_debug("%s\n",__func__);
7c2f891c 441
9480e307 442 imxfb_disable_controller(fbi);
7c2f891c
SH
443 return 0;
444}
445
3ae5eaec 446static int imxfb_resume(struct platform_device *dev)
7c2f891c 447{
3ae5eaec 448 struct imxfb_info *fbi = platform_get_drvdata(dev);
5ae12170 449 pr_debug("%s\n",__func__);
7c2f891c 450
9480e307 451 imxfb_enable_controller(fbi);
7c2f891c
SH
452 return 0;
453}
454#else
455#define imxfb_suspend NULL
456#define imxfb_resume NULL
457#endif
458
72330b0e 459static int __init imxfb_init_fbinfo(struct platform_device *pdev)
7c2f891c 460{
72330b0e
JB
461 struct imxfb_mach_info *inf = pdev->dev.platform_data;
462 struct fb_info *info = dev_get_drvdata(&pdev->dev);
7c2f891c
SH
463 struct imxfb_info *fbi = info->par;
464
5ae12170 465 pr_debug("%s\n",__func__);
7c2f891c
SH
466
467 info->pseudo_palette = kmalloc( sizeof(u32) * 16, GFP_KERNEL);
468 if (!info->pseudo_palette)
469 return -ENOMEM;
470
471 memset(fbi, 0, sizeof(struct imxfb_info));
7c2f891c
SH
472
473 strlcpy(info->fix.id, IMX_NAME, sizeof(info->fix.id));
474
475 info->fix.type = FB_TYPE_PACKED_PIXELS;
476 info->fix.type_aux = 0;
477 info->fix.xpanstep = 0;
478 info->fix.ypanstep = 0;
479 info->fix.ywrapstep = 0;
480 info->fix.accel = FB_ACCEL_NONE;
481
482 info->var.nonstd = 0;
483 info->var.activate = FB_ACTIVATE_NOW;
484 info->var.height = -1;
485 info->var.width = -1;
486 info->var.accel_flags = 0;
487 info->var.vmode = FB_VMODE_NONINTERLACED;
488
489 info->fbops = &imxfb_ops;
9da505d1 490 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_READS_FAST;
7c2f891c
SH
491
492 fbi->rgb[RGB_16] = &def_rgb_16;
493 fbi->rgb[RGB_8] = &def_rgb_8;
494
495 fbi->max_xres = inf->xres;
496 info->var.xres = inf->xres;
497 info->var.xres_virtual = inf->xres;
498 fbi->max_yres = inf->yres;
499 info->var.yres = inf->yres;
500 info->var.yres_virtual = inf->yres;
501 fbi->max_bpp = inf->bpp;
502 info->var.bits_per_pixel = inf->bpp;
9da505d1 503 info->var.nonstd = inf->nonstd;
7c2f891c
SH
504 info->var.pixclock = inf->pixclock;
505 info->var.hsync_len = inf->hsync_len;
506 info->var.left_margin = inf->left_margin;
507 info->var.right_margin = inf->right_margin;
508 info->var.vsync_len = inf->vsync_len;
509 info->var.upper_margin = inf->upper_margin;
510 info->var.lower_margin = inf->lower_margin;
511 info->var.sync = inf->sync;
512 info->var.grayscale = inf->cmap_greyscale;
513 fbi->cmap_inverse = inf->cmap_inverse;
90e16ddd 514 fbi->cmap_static = inf->cmap_static;
7c2f891c
SH
515 fbi->pcr = inf->pcr;
516 fbi->lscr1 = inf->lscr1;
772a9e63 517 fbi->dmacr = inf->dmacr;
7c2f891c
SH
518 fbi->pwmr = inf->pwmr;
519 fbi->lcd_power = inf->lcd_power;
520 fbi->backlight_power = inf->backlight_power;
521 info->fix.smem_len = fbi->max_xres * fbi->max_yres *
522 fbi->max_bpp / 8;
523
524 return 0;
525}
526
3ae5eaec 527static int __init imxfb_probe(struct platform_device *pdev)
7c2f891c 528{
7c2f891c
SH
529 struct imxfb_info *fbi;
530 struct fb_info *info;
531 struct imxfb_mach_info *inf;
532 struct resource *res;
533 int ret;
534
535 printk("i.MX Framebuffer driver\n");
536
537 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
538 if(!res)
539 return -ENODEV;
540
3ae5eaec 541 inf = pdev->dev.platform_data;
7c2f891c 542 if(!inf) {
f99c8929 543 dev_err(&pdev->dev,"No platform_data available\n");
7c2f891c
SH
544 return -ENOMEM;
545 }
546
3ae5eaec 547 info = framebuffer_alloc(sizeof(struct imxfb_info), &pdev->dev);
7c2f891c
SH
548 if(!info)
549 return -ENOMEM;
550
551 fbi = info->par;
552
3ae5eaec 553 platform_set_drvdata(pdev, info);
7c2f891c 554
72330b0e 555 ret = imxfb_init_fbinfo(pdev);
7c2f891c
SH
556 if( ret < 0 )
557 goto failed_init;
558
72330b0e
JB
559 res = request_mem_region(res->start, resource_size(res),
560 DRIVER_NAME);
7c2f891c
SH
561 if (!res) {
562 ret = -EBUSY;
72330b0e
JB
563 goto failed_req;
564 }
565
566 fbi->regs = ioremap(res->start, resource_size(res));
567 if (fbi->regs == NULL) {
568 printk(KERN_ERR"Cannot map frame buffer registers\n");
569 goto failed_ioremap;
7c2f891c
SH
570 }
571
572 if (!inf->fixed_screen_cpu) {
72330b0e
JB
573 fbi->map_size = PAGE_ALIGN(info->fix.smem_len);
574 fbi->map_cpu = dma_alloc_writecombine(&pdev->dev,
575 fbi->map_size, &fbi->map_dma, GFP_KERNEL);
576
577 if (!fbi->map_cpu) {
f99c8929 578 dev_err(&pdev->dev, "Failed to allocate video RAM: %d\n", ret);
7c2f891c
SH
579 ret = -ENOMEM;
580 goto failed_map;
581 }
72330b0e
JB
582
583 info->screen_base = fbi->map_cpu;
584 fbi->screen_cpu = fbi->map_cpu;
585 fbi->screen_dma = fbi->map_dma;
586 info->fix.smem_start = fbi->screen_dma;
7c2f891c
SH
587 } else {
588 /* Fixed framebuffer mapping enables location of the screen in eSRAM */
589 fbi->map_cpu = inf->fixed_screen_cpu;
590 fbi->map_dma = inf->fixed_screen_dma;
591 info->screen_base = fbi->map_cpu;
592 fbi->screen_cpu = fbi->map_cpu;
593 fbi->screen_dma = fbi->map_dma;
594 info->fix.smem_start = fbi->screen_dma;
595 }
596
597 /*
598 * This makes sure that our colour bitfield
599 * descriptors are correctly initialised.
600 */
601 imxfb_check_var(&info->var, info);
602
603 ret = fb_alloc_cmap(&info->cmap, 1<<info->var.bits_per_pixel, 0);
604 if (ret < 0)
605 goto failed_cmap;
606
7c2f891c
SH
607 imxfb_set_par(info);
608 ret = register_framebuffer(info);
609 if (ret < 0) {
f99c8929 610 dev_err(&pdev->dev, "failed to register framebuffer\n");
7c2f891c
SH
611 goto failed_register;
612 }
613
614 imxfb_enable_controller(fbi);
615
616 return 0;
617
618failed_register:
619 fb_dealloc_cmap(&info->cmap);
620failed_cmap:
621 if (!inf->fixed_screen_cpu)
3ae5eaec 622 dma_free_writecombine(&pdev->dev,fbi->map_size,fbi->map_cpu,
72330b0e 623 fbi->map_dma);
7c2f891c 624failed_map:
72330b0e
JB
625 iounmap(fbi->regs);
626failed_ioremap:
7c2f891c 627 release_mem_region(res->start, res->end - res->start);
72330b0e
JB
628failed_req:
629 kfree(info->pseudo_palette);
7c2f891c 630failed_init:
3ae5eaec 631 platform_set_drvdata(pdev, NULL);
7c2f891c
SH
632 framebuffer_release(info);
633 return ret;
634}
635
72330b0e 636static int __devexit imxfb_remove(struct platform_device *pdev)
7c2f891c 637{
3ae5eaec 638 struct fb_info *info = platform_get_drvdata(pdev);
772a9e63 639 struct imxfb_info *fbi = info->par;
7c2f891c
SH
640 struct resource *res;
641
642 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
643
772a9e63 644 imxfb_disable_controller(fbi);
7c2f891c
SH
645
646 unregister_framebuffer(info);
647
648 fb_dealloc_cmap(&info->cmap);
649 kfree(info->pseudo_palette);
650 framebuffer_release(info);
651
72330b0e 652 iounmap(fbi->regs);
7c2f891c 653 release_mem_region(res->start, res->end - res->start + 1);
3ae5eaec 654 platform_set_drvdata(pdev, NULL);
7c2f891c
SH
655
656 return 0;
657}
658
3ae5eaec 659void imxfb_shutdown(struct platform_device * dev)
7c2f891c 660{
3ae5eaec 661 struct fb_info *info = platform_get_drvdata(dev);
772a9e63
SH
662 struct imxfb_info *fbi = info->par;
663 imxfb_disable_controller(fbi);
7c2f891c
SH
664}
665
3ae5eaec 666static struct platform_driver imxfb_driver = {
7c2f891c
SH
667 .suspend = imxfb_suspend,
668 .resume = imxfb_resume,
72330b0e 669 .remove = __devexit_p(imxfb_remove),
7c2f891c 670 .shutdown = imxfb_shutdown,
3ae5eaec 671 .driver = {
72330b0e 672 .name = DRIVER_NAME,
3ae5eaec 673 },
7c2f891c
SH
674};
675
676int __init imxfb_init(void)
677{
72330b0e 678 return platform_driver_probe(&imxfb_driver, imxfb_probe);
7c2f891c
SH
679}
680
681static void __exit imxfb_cleanup(void)
682{
3ae5eaec 683 platform_driver_unregister(&imxfb_driver);
7c2f891c
SH
684}
685
686module_init(imxfb_init);
687module_exit(imxfb_cleanup);
688
689MODULE_DESCRIPTION("Motorola i.MX framebuffer driver");
690MODULE_AUTHOR("Sascha Hauer, Pengutronix");
691MODULE_LICENSE("GPL");