imxfb.c 19 KB

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