imxfb.c 18 KB

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