imxfb.c 20 KB

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