imxfb.c 17 KB

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