imxfb.c 17 KB

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