imxfb.c 17 KB

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