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. struct imxfb_info {
  97. struct platform_device *pdev;
  98. void __iomem *regs;
  99. u_int max_bpp;
  100. u_int max_xres;
  101. u_int max_yres;
  102. /*
  103. * These are the addresses we mapped
  104. * the framebuffer memory region to.
  105. */
  106. dma_addr_t map_dma;
  107. u_char *map_cpu;
  108. u_int map_size;
  109. u_char *screen_cpu;
  110. dma_addr_t screen_dma;
  111. u_int palette_size;
  112. dma_addr_t dbar1;
  113. dma_addr_t dbar2;
  114. u_int pcr;
  115. u_int pwmr;
  116. u_int lscr1;
  117. u_int dmacr;
  118. u_int cmap_inverse:1,
  119. cmap_static:1,
  120. unused:30;
  121. void (*lcd_power)(int);
  122. void (*backlight_power)(int);
  123. };
  124. #define IMX_NAME "IMX"
  125. /*
  126. * Minimum X and Y resolutions
  127. */
  128. #define MIN_XRES 64
  129. #define MIN_YRES 64
  130. static struct imxfb_rgb def_rgb_16_tft = {
  131. .red = {.offset = 11, .length = 5,},
  132. .green = {.offset = 5, .length = 6,},
  133. .blue = {.offset = 0, .length = 5,},
  134. .transp = {.offset = 0, .length = 0,},
  135. };
  136. static struct imxfb_rgb def_rgb_16_stn = {
  137. .red = {.offset = 8, .length = 4,},
  138. .green = {.offset = 4, .length = 4,},
  139. .blue = {.offset = 0, .length = 4,},
  140. .transp = {.offset = 0, .length = 0,},
  141. };
  142. static struct imxfb_rgb def_rgb_8 = {
  143. .red = {.offset = 0, .length = 8,},
  144. .green = {.offset = 0, .length = 8,},
  145. .blue = {.offset = 0, .length = 8,},
  146. .transp = {.offset = 0, .length = 0,},
  147. };
  148. static int imxfb_activate_var(struct fb_var_screeninfo *var,
  149. struct fb_info *info);
  150. static inline u_int chan_to_field(u_int chan, struct fb_bitfield *bf)
  151. {
  152. chan &= 0xffff;
  153. chan >>= 16 - bf->length;
  154. return chan << bf->offset;
  155. }
  156. static int imxfb_setpalettereg(u_int regno, u_int red, u_int green, u_int blue,
  157. u_int trans, struct fb_info *info)
  158. {
  159. struct imxfb_info *fbi = info->par;
  160. u_int val, ret = 1;
  161. #define CNVT_TOHW(val,width) ((((val)<<(width))+0x7FFF-(val))>>16)
  162. if (regno < fbi->palette_size) {
  163. val = (CNVT_TOHW(red, 4) << 8) |
  164. (CNVT_TOHW(green,4) << 4) |
  165. CNVT_TOHW(blue, 4);
  166. writel(val, fbi->regs + 0x800 + (regno << 2));
  167. ret = 0;
  168. }
  169. return ret;
  170. }
  171. static int imxfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
  172. u_int trans, struct fb_info *info)
  173. {
  174. struct imxfb_info *fbi = info->par;
  175. unsigned int val;
  176. int ret = 1;
  177. /*
  178. * If inverse mode was selected, invert all the colours
  179. * rather than the register number. The register number
  180. * is what you poke into the framebuffer to produce the
  181. * colour you requested.
  182. */
  183. if (fbi->cmap_inverse) {
  184. red = 0xffff - red;
  185. green = 0xffff - green;
  186. blue = 0xffff - blue;
  187. }
  188. /*
  189. * If greyscale is true, then we convert the RGB value
  190. * to greyscale no mater what visual we are using.
  191. */
  192. if (info->var.grayscale)
  193. red = green = blue = (19595 * red + 38470 * green +
  194. 7471 * blue) >> 16;
  195. switch (info->fix.visual) {
  196. case FB_VISUAL_TRUECOLOR:
  197. /*
  198. * 12 or 16-bit True Colour. We encode the RGB value
  199. * according to the RGB bitfield information.
  200. */
  201. if (regno < 16) {
  202. u32 *pal = info->pseudo_palette;
  203. val = chan_to_field(red, &info->var.red);
  204. val |= chan_to_field(green, &info->var.green);
  205. val |= chan_to_field(blue, &info->var.blue);
  206. pal[regno] = val;
  207. ret = 0;
  208. }
  209. break;
  210. case FB_VISUAL_STATIC_PSEUDOCOLOR:
  211. case FB_VISUAL_PSEUDOCOLOR:
  212. ret = imxfb_setpalettereg(regno, red, green, blue, trans, info);
  213. break;
  214. }
  215. return ret;
  216. }
  217. /*
  218. * imxfb_check_var():
  219. * Round up in the following order: bits_per_pixel, xres,
  220. * yres, xres_virtual, yres_virtual, xoffset, yoffset, grayscale,
  221. * bitfields, horizontal timing, vertical timing.
  222. */
  223. static int imxfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
  224. {
  225. struct imxfb_info *fbi = info->par;
  226. struct imxfb_rgb *rgb;
  227. if (var->xres < MIN_XRES)
  228. var->xres = MIN_XRES;
  229. if (var->yres < MIN_YRES)
  230. var->yres = MIN_YRES;
  231. if (var->xres > fbi->max_xres)
  232. var->xres = fbi->max_xres;
  233. if (var->yres > fbi->max_yres)
  234. var->yres = fbi->max_yres;
  235. var->xres_virtual = max(var->xres_virtual, var->xres);
  236. var->yres_virtual = max(var->yres_virtual, var->yres);
  237. pr_debug("var->bits_per_pixel=%d\n", var->bits_per_pixel);
  238. switch (var->bits_per_pixel) {
  239. case 16:
  240. default:
  241. if (readl(fbi->regs + LCDC_PCR) & PCR_TFT)
  242. rgb = &def_rgb_16_tft;
  243. else
  244. rgb = &def_rgb_16_stn;
  245. break;
  246. case 8:
  247. rgb = &def_rgb_8;
  248. break;
  249. }
  250. /*
  251. * Copy the RGB parameters for this display
  252. * from the machine specific parameters.
  253. */
  254. var->red = rgb->red;
  255. var->green = rgb->green;
  256. var->blue = rgb->blue;
  257. var->transp = rgb->transp;
  258. pr_debug("RGBT length = %d:%d:%d:%d\n",
  259. var->red.length, var->green.length, var->blue.length,
  260. var->transp.length);
  261. pr_debug("RGBT offset = %d:%d:%d:%d\n",
  262. var->red.offset, var->green.offset, var->blue.offset,
  263. var->transp.offset);
  264. return 0;
  265. }
  266. /*
  267. * imxfb_set_par():
  268. * Set the user defined part of the display for the specified console
  269. */
  270. static int imxfb_set_par(struct fb_info *info)
  271. {
  272. struct imxfb_info *fbi = info->par;
  273. struct fb_var_screeninfo *var = &info->var;
  274. pr_debug("set_par\n");
  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. info->fix.line_length = var->xres_virtual * var->bits_per_pixel / 8;
  288. fbi->palette_size = var->bits_per_pixel == 8 ? 256 : 16;
  289. imxfb_activate_var(var, info);
  290. return 0;
  291. }
  292. static void imxfb_enable_controller(struct imxfb_info *fbi)
  293. {
  294. pr_debug("Enabling LCD controller\n");
  295. /* initialize LCDC */
  296. writel(readl(fbi->regs + LCDC_RMCR) & ~RMCR_LCDC_EN,
  297. fbi->regs + LCDC_RMCR); /* just to be safe... */
  298. writel(fbi->screen_dma, fbi->regs + LCDC_SSA);
  299. /* physical screen start address */
  300. writel(VPW_VPW(fbi->max_xres * fbi->max_bpp / 8 / 4),
  301. fbi->regs + LCDC_VPW);
  302. /* panning offset 0 (0 pixel offset) */
  303. writel(0x00000000, fbi->regs + LCDC_POS);
  304. /* disable hardware cursor */
  305. writel(readl(fbi->regs + LCDC_CPOS) & ~(CPOS_CC0 | CPOS_CC1),
  306. fbi->regs + LCDC_CPOS);
  307. writel(RMCR_LCDC_EN, fbi->regs + LCDC_RMCR);
  308. if (fbi->backlight_power)
  309. fbi->backlight_power(1);
  310. if (fbi->lcd_power)
  311. fbi->lcd_power(1);
  312. }
  313. static void imxfb_disable_controller(struct imxfb_info *fbi)
  314. {
  315. pr_debug("Disabling LCD controller\n");
  316. if (fbi->backlight_power)
  317. fbi->backlight_power(0);
  318. if (fbi->lcd_power)
  319. fbi->lcd_power(0);
  320. writel(0, fbi->regs + LCDC_RMCR);
  321. }
  322. static int imxfb_blank(int blank, struct fb_info *info)
  323. {
  324. struct imxfb_info *fbi = info->par;
  325. pr_debug("imxfb_blank: blank=%d\n", blank);
  326. switch (blank) {
  327. case FB_BLANK_POWERDOWN:
  328. case FB_BLANK_VSYNC_SUSPEND:
  329. case FB_BLANK_HSYNC_SUSPEND:
  330. case FB_BLANK_NORMAL:
  331. imxfb_disable_controller(fbi);
  332. break;
  333. case FB_BLANK_UNBLANK:
  334. imxfb_enable_controller(fbi);
  335. break;
  336. }
  337. return 0;
  338. }
  339. static struct fb_ops imxfb_ops = {
  340. .owner = THIS_MODULE,
  341. .fb_check_var = imxfb_check_var,
  342. .fb_set_par = imxfb_set_par,
  343. .fb_setcolreg = imxfb_setcolreg,
  344. .fb_fillrect = cfb_fillrect,
  345. .fb_copyarea = cfb_copyarea,
  346. .fb_imageblit = cfb_imageblit,
  347. .fb_blank = imxfb_blank,
  348. };
  349. /*
  350. * imxfb_activate_var():
  351. * Configures LCD Controller based on entries in var parameter. Settings are
  352. * only written to the controller if changes were made.
  353. */
  354. static int imxfb_activate_var(struct fb_var_screeninfo *var, struct fb_info *info)
  355. {
  356. struct imxfb_info *fbi = info->par;
  357. pr_debug("var: xres=%d hslen=%d lm=%d rm=%d\n",
  358. var->xres, var->hsync_len,
  359. var->left_margin, var->right_margin);
  360. pr_debug("var: yres=%d vslen=%d um=%d bm=%d\n",
  361. var->yres, var->vsync_len,
  362. var->upper_margin, var->lower_margin);
  363. #if DEBUG_VAR
  364. if (var->xres < 16 || var->xres > 1024)
  365. printk(KERN_ERR "%s: invalid xres %d\n",
  366. info->fix.id, var->xres);
  367. if (var->hsync_len < 1 || var->hsync_len > 64)
  368. printk(KERN_ERR "%s: invalid hsync_len %d\n",
  369. info->fix.id, var->hsync_len);
  370. if (var->left_margin > 255)
  371. printk(KERN_ERR "%s: invalid left_margin %d\n",
  372. info->fix.id, var->left_margin);
  373. if (var->right_margin > 255)
  374. printk(KERN_ERR "%s: invalid right_margin %d\n",
  375. info->fix.id, var->right_margin);
  376. if (var->yres < 1 || var->yres > 511)
  377. printk(KERN_ERR "%s: invalid yres %d\n",
  378. info->fix.id, var->yres);
  379. if (var->vsync_len > 100)
  380. printk(KERN_ERR "%s: invalid vsync_len %d\n",
  381. info->fix.id, var->vsync_len);
  382. if (var->upper_margin > 63)
  383. printk(KERN_ERR "%s: invalid upper_margin %d\n",
  384. info->fix.id, var->upper_margin);
  385. if (var->lower_margin > 255)
  386. printk(KERN_ERR "%s: invalid lower_margin %d\n",
  387. info->fix.id, var->lower_margin);
  388. #endif
  389. writel(HCR_H_WIDTH(var->hsync_len) |
  390. HCR_H_WAIT_1(var->right_margin) |
  391. HCR_H_WAIT_2(var->left_margin),
  392. fbi->regs + LCDC_HCR);
  393. writel(VCR_V_WIDTH(var->vsync_len) |
  394. VCR_V_WAIT_1(var->lower_margin) |
  395. VCR_V_WAIT_2(var->upper_margin),
  396. fbi->regs + LCDC_VCR);
  397. writel(SIZE_XMAX(var->xres) | SIZE_YMAX(var->yres),
  398. fbi->regs + LCDC_SIZE);
  399. writel(fbi->pcr, fbi->regs + LCDC_PCR);
  400. writel(fbi->pwmr, fbi->regs + LCDC_PWMR);
  401. writel(fbi->lscr1, fbi->regs + LCDC_LSCR1);
  402. writel(fbi->dmacr, fbi->regs + LCDC_DMACR);
  403. return 0;
  404. }
  405. #ifdef CONFIG_PM
  406. /*
  407. * Power management hooks. Note that we won't be called from IRQ context,
  408. * unlike the blank functions above, so we may sleep.
  409. */
  410. static int imxfb_suspend(struct platform_device *dev, pm_message_t state)
  411. {
  412. struct imxfb_info *fbi = platform_get_drvdata(dev);
  413. pr_debug("%s\n", __func__);
  414. imxfb_disable_controller(fbi);
  415. return 0;
  416. }
  417. static int imxfb_resume(struct platform_device *dev)
  418. {
  419. struct imxfb_info *fbi = platform_get_drvdata(dev);
  420. pr_debug("%s\n", __func__);
  421. imxfb_enable_controller(fbi);
  422. return 0;
  423. }
  424. #else
  425. #define imxfb_suspend NULL
  426. #define imxfb_resume NULL
  427. #endif
  428. static int __init imxfb_init_fbinfo(struct platform_device *pdev)
  429. {
  430. struct imx_fb_platform_data *pdata = pdev->dev.platform_data;
  431. struct fb_info *info = dev_get_drvdata(&pdev->dev);
  432. struct imxfb_info *fbi = info->par;
  433. pr_debug("%s\n",__func__);
  434. info->pseudo_palette = kmalloc(sizeof(u32) * 16, GFP_KERNEL);
  435. if (!info->pseudo_palette)
  436. return -ENOMEM;
  437. memset(fbi, 0, sizeof(struct imxfb_info));
  438. strlcpy(info->fix.id, IMX_NAME, sizeof(info->fix.id));
  439. info->fix.type = FB_TYPE_PACKED_PIXELS;
  440. info->fix.type_aux = 0;
  441. info->fix.xpanstep = 0;
  442. info->fix.ypanstep = 0;
  443. info->fix.ywrapstep = 0;
  444. info->fix.accel = FB_ACCEL_NONE;
  445. info->var.nonstd = 0;
  446. info->var.activate = FB_ACTIVATE_NOW;
  447. info->var.height = -1;
  448. info->var.width = -1;
  449. info->var.accel_flags = 0;
  450. info->var.vmode = FB_VMODE_NONINTERLACED;
  451. info->fbops = &imxfb_ops;
  452. info->flags = FBINFO_FLAG_DEFAULT |
  453. FBINFO_READS_FAST;
  454. fbi->max_xres = pdata->xres;
  455. info->var.xres = pdata->xres;
  456. info->var.xres_virtual = pdata->xres;
  457. fbi->max_yres = pdata->yres;
  458. info->var.yres = pdata->yres;
  459. info->var.yres_virtual = pdata->yres;
  460. fbi->max_bpp = pdata->bpp;
  461. info->var.bits_per_pixel = pdata->bpp;
  462. info->var.nonstd = pdata->nonstd;
  463. info->var.pixclock = pdata->pixclock;
  464. info->var.hsync_len = pdata->hsync_len;
  465. info->var.left_margin = pdata->left_margin;
  466. info->var.right_margin = pdata->right_margin;
  467. info->var.vsync_len = pdata->vsync_len;
  468. info->var.upper_margin = pdata->upper_margin;
  469. info->var.lower_margin = pdata->lower_margin;
  470. info->var.sync = pdata->sync;
  471. info->var.grayscale = pdata->cmap_greyscale;
  472. fbi->cmap_inverse = pdata->cmap_inverse;
  473. fbi->cmap_static = pdata->cmap_static;
  474. fbi->pcr = pdata->pcr;
  475. fbi->lscr1 = pdata->lscr1;
  476. fbi->dmacr = pdata->dmacr;
  477. fbi->pwmr = pdata->pwmr;
  478. fbi->lcd_power = pdata->lcd_power;
  479. fbi->backlight_power = pdata->backlight_power;
  480. info->fix.smem_len = fbi->max_xres * fbi->max_yres *
  481. fbi->max_bpp / 8;
  482. return 0;
  483. }
  484. static int __init imxfb_probe(struct platform_device *pdev)
  485. {
  486. struct imxfb_info *fbi;
  487. struct fb_info *info;
  488. struct imx_fb_platform_data *pdata;
  489. struct resource *res;
  490. int ret;
  491. printk("i.MX Framebuffer driver\n");
  492. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  493. if (!res)
  494. return -ENODEV;
  495. pdata = pdev->dev.platform_data;
  496. if (!pdata) {
  497. dev_err(&pdev->dev,"No platform_data available\n");
  498. return -ENOMEM;
  499. }
  500. info = framebuffer_alloc(sizeof(struct imxfb_info), &pdev->dev);
  501. if (!info)
  502. return -ENOMEM;
  503. fbi = info->par;
  504. platform_set_drvdata(pdev, info);
  505. ret = imxfb_init_fbinfo(pdev);
  506. if (ret < 0)
  507. goto failed_init;
  508. res = request_mem_region(res->start, resource_size(res),
  509. DRIVER_NAME);
  510. if (!res) {
  511. ret = -EBUSY;
  512. goto failed_req;
  513. }
  514. fbi->regs = ioremap(res->start, resource_size(res));
  515. if (fbi->regs == NULL) {
  516. printk(KERN_ERR"Cannot map frame buffer registers\n");
  517. goto failed_ioremap;
  518. }
  519. if (!pdata->fixed_screen_cpu) {
  520. fbi->map_size = PAGE_ALIGN(info->fix.smem_len);
  521. fbi->map_cpu = dma_alloc_writecombine(&pdev->dev,
  522. fbi->map_size, &fbi->map_dma, GFP_KERNEL);
  523. if (!fbi->map_cpu) {
  524. dev_err(&pdev->dev, "Failed to allocate video RAM: %d\n", ret);
  525. ret = -ENOMEM;
  526. goto failed_map;
  527. }
  528. info->screen_base = fbi->map_cpu;
  529. fbi->screen_cpu = fbi->map_cpu;
  530. fbi->screen_dma = fbi->map_dma;
  531. info->fix.smem_start = fbi->screen_dma;
  532. } else {
  533. /* Fixed framebuffer mapping enables location of the screen in eSRAM */
  534. fbi->map_cpu = pdata->fixed_screen_cpu;
  535. fbi->map_dma = pdata->fixed_screen_dma;
  536. info->screen_base = fbi->map_cpu;
  537. fbi->screen_cpu = fbi->map_cpu;
  538. fbi->screen_dma = fbi->map_dma;
  539. info->fix.smem_start = fbi->screen_dma;
  540. }
  541. /*
  542. * This makes sure that our colour bitfield
  543. * descriptors are correctly initialised.
  544. */
  545. imxfb_check_var(&info->var, info);
  546. ret = fb_alloc_cmap(&info->cmap, 1 << info->var.bits_per_pixel, 0);
  547. if (ret < 0)
  548. goto failed_cmap;
  549. imxfb_set_par(info);
  550. ret = register_framebuffer(info);
  551. if (ret < 0) {
  552. dev_err(&pdev->dev, "failed to register framebuffer\n");
  553. goto failed_register;
  554. }
  555. imxfb_enable_controller(fbi);
  556. return 0;
  557. failed_register:
  558. fb_dealloc_cmap(&info->cmap);
  559. failed_cmap:
  560. if (!pdata->fixed_screen_cpu)
  561. dma_free_writecombine(&pdev->dev,fbi->map_size,fbi->map_cpu,
  562. fbi->map_dma);
  563. failed_map:
  564. iounmap(fbi->regs);
  565. failed_ioremap:
  566. release_mem_region(res->start, res->end - res->start);
  567. failed_req:
  568. kfree(info->pseudo_palette);
  569. failed_init:
  570. platform_set_drvdata(pdev, NULL);
  571. framebuffer_release(info);
  572. return ret;
  573. }
  574. static int __devexit imxfb_remove(struct platform_device *pdev)
  575. {
  576. struct fb_info *info = platform_get_drvdata(pdev);
  577. struct imxfb_info *fbi = info->par;
  578. struct resource *res;
  579. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  580. imxfb_disable_controller(fbi);
  581. unregister_framebuffer(info);
  582. fb_dealloc_cmap(&info->cmap);
  583. kfree(info->pseudo_palette);
  584. framebuffer_release(info);
  585. iounmap(fbi->regs);
  586. release_mem_region(res->start, res->end - res->start + 1);
  587. platform_set_drvdata(pdev, NULL);
  588. return 0;
  589. }
  590. void imxfb_shutdown(struct platform_device * dev)
  591. {
  592. struct fb_info *info = platform_get_drvdata(dev);
  593. struct imxfb_info *fbi = info->par;
  594. imxfb_disable_controller(fbi);
  595. }
  596. static struct platform_driver imxfb_driver = {
  597. .suspend = imxfb_suspend,
  598. .resume = imxfb_resume,
  599. .remove = __devexit_p(imxfb_remove),
  600. .shutdown = imxfb_shutdown,
  601. .driver = {
  602. .name = DRIVER_NAME,
  603. },
  604. };
  605. int __init imxfb_init(void)
  606. {
  607. return platform_driver_probe(&imxfb_driver, imxfb_probe);
  608. }
  609. static void __exit imxfb_cleanup(void)
  610. {
  611. platform_driver_unregister(&imxfb_driver);
  612. }
  613. module_init(imxfb_init);
  614. module_exit(imxfb_cleanup);
  615. MODULE_DESCRIPTION("Motorola i.MX framebuffer driver");
  616. MODULE_AUTHOR("Sascha Hauer, Pengutronix");
  617. MODULE_LICENSE("GPL");