mbxfb.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694
  1. /*
  2. * linux/drivers/video/mbx/mbxfb.c
  3. *
  4. * Copyright (C) 2006 Compulab, Ltd.
  5. * Mike Rapoport <mike@compulab.co.il>
  6. *
  7. * Based on pxafb.c
  8. *
  9. * This file is subject to the terms and conditions of the GNU General Public
  10. * License. See the file COPYING in the main directory of this archive for
  11. * more details.
  12. *
  13. * Intel 2700G (Marathon) Graphics Accelerator Frame Buffer Driver
  14. *
  15. */
  16. #include <linux/delay.h>
  17. #include <linux/fb.h>
  18. #include <linux/init.h>
  19. #include <linux/module.h>
  20. #include <linux/platform_device.h>
  21. #include <asm/io.h>
  22. #include <video/mbxfb.h>
  23. #include "regs.h"
  24. #include "reg_bits.h"
  25. static unsigned long virt_base_2700;
  26. #define MIN_XRES 16
  27. #define MIN_YRES 16
  28. #define MAX_XRES 2048
  29. #define MAX_YRES 2048
  30. #define MAX_PALETTES 16
  31. /* FIXME: take care of different chip revisions with different sizes
  32. of ODFB */
  33. #define MEMORY_OFFSET 0x60000
  34. struct mbxfb_info {
  35. struct device *dev;
  36. struct resource *fb_res;
  37. struct resource *fb_req;
  38. struct resource *reg_res;
  39. struct resource *reg_req;
  40. void __iomem *fb_virt_addr;
  41. unsigned long fb_phys_addr;
  42. void __iomem *reg_virt_addr;
  43. unsigned long reg_phys_addr;
  44. int (*platform_probe) (struct fb_info * fb);
  45. int (*platform_remove) (struct fb_info * fb);
  46. u32 pseudo_palette[MAX_PALETTES];
  47. #ifdef CONFIG_FB_MBX_DEBUG
  48. void *debugfs_data;
  49. #endif
  50. };
  51. static struct fb_var_screeninfo mbxfb_default __devinitdata = {
  52. .xres = 640,
  53. .yres = 480,
  54. .xres_virtual = 640,
  55. .yres_virtual = 480,
  56. .bits_per_pixel = 16,
  57. .red = {11, 5, 0},
  58. .green = {5, 6, 0},
  59. .blue = {0, 5, 0},
  60. .activate = FB_ACTIVATE_TEST,
  61. .height = -1,
  62. .width = -1,
  63. .pixclock = 40000,
  64. .left_margin = 48,
  65. .right_margin = 16,
  66. .upper_margin = 33,
  67. .lower_margin = 10,
  68. .hsync_len = 96,
  69. .vsync_len = 2,
  70. .vmode = FB_VMODE_NONINTERLACED,
  71. .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  72. };
  73. static struct fb_fix_screeninfo mbxfb_fix __devinitdata = {
  74. .id = "MBX",
  75. .type = FB_TYPE_PACKED_PIXELS,
  76. .visual = FB_VISUAL_TRUECOLOR,
  77. .xpanstep = 0,
  78. .ypanstep = 0,
  79. .ywrapstep = 0,
  80. .accel = FB_ACCEL_NONE,
  81. };
  82. struct pixclock_div {
  83. u8 m;
  84. u8 n;
  85. u8 p;
  86. };
  87. static unsigned int mbxfb_get_pixclock(unsigned int pixclock_ps,
  88. struct pixclock_div *div)
  89. {
  90. u8 m, n, p;
  91. unsigned int err = 0;
  92. unsigned int min_err = ~0x0;
  93. unsigned int clk;
  94. unsigned int best_clk = 0;
  95. unsigned int ref_clk = 13000; /* FIXME: take from platform data */
  96. unsigned int pixclock;
  97. /* convert pixclock to KHz */
  98. pixclock = PICOS2KHZ(pixclock_ps);
  99. /* PLL output freq = (ref_clk * M) / (N * 2^P)
  100. *
  101. * M: 1 to 63
  102. * N: 1 to 7
  103. * P: 0 to 7
  104. */
  105. /* RAPH: When N==1, the resulting pixel clock appears to
  106. * get divided by 2. Preventing N=1 by starting the following
  107. * loop at 2 prevents this. Is this a bug with my chip
  108. * revision or something I dont understand? */
  109. for (m = 1; m < 64; m++) {
  110. for (n = 2; n < 8; n++) {
  111. for (p = 0; p < 8; p++) {
  112. clk = (ref_clk * m) / (n * (1 << p));
  113. err = (clk > pixclock) ? (clk - pixclock) :
  114. (pixclock - clk);
  115. if (err < min_err) {
  116. min_err = err;
  117. best_clk = clk;
  118. div->m = m;
  119. div->n = n;
  120. div->p = p;
  121. }
  122. }
  123. }
  124. }
  125. return KHZ2PICOS(best_clk);
  126. }
  127. static int mbxfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
  128. u_int trans, struct fb_info *info)
  129. {
  130. u32 val, ret = 1;
  131. if (regno < MAX_PALETTES) {
  132. u32 *pal = info->pseudo_palette;
  133. val = (red & 0xf800) | ((green & 0xfc00) >> 5) |
  134. ((blue & 0xf800) >> 11);
  135. pal[regno] = val;
  136. ret = 0;
  137. }
  138. return ret;
  139. }
  140. static int mbxfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
  141. {
  142. struct pixclock_div div;
  143. var->pixclock = mbxfb_get_pixclock(var->pixclock, &div);
  144. if (var->xres < MIN_XRES)
  145. var->xres = MIN_XRES;
  146. if (var->yres < MIN_YRES)
  147. var->yres = MIN_YRES;
  148. if (var->xres > MAX_XRES)
  149. return -EINVAL;
  150. if (var->yres > MAX_YRES)
  151. return -EINVAL;
  152. var->xres_virtual = max(var->xres_virtual, var->xres);
  153. var->yres_virtual = max(var->yres_virtual, var->yres);
  154. switch (var->bits_per_pixel) {
  155. /* 8 bits-per-pixel is not supported yet */
  156. case 8:
  157. return -EINVAL;
  158. case 16:
  159. var->green.length = (var->green.length == 5) ? 5 : 6;
  160. var->red.length = 5;
  161. var->blue.length = 5;
  162. var->transp.length = 6 - var->green.length;
  163. var->blue.offset = 0;
  164. var->green.offset = 5;
  165. var->red.offset = 5 + var->green.length;
  166. var->transp.offset = (5 + var->red.offset) & 15;
  167. break;
  168. case 24: /* RGB 888 */
  169. case 32: /* RGBA 8888 */
  170. var->red.offset = 16;
  171. var->red.length = 8;
  172. var->green.offset = 8;
  173. var->green.length = 8;
  174. var->blue.offset = 0;
  175. var->blue.length = 8;
  176. var->transp.length = var->bits_per_pixel - 24;
  177. var->transp.offset = (var->transp.length) ? 24 : 0;
  178. break;
  179. }
  180. var->red.msb_right = 0;
  181. var->green.msb_right = 0;
  182. var->blue.msb_right = 0;
  183. var->transp.msb_right = 0;
  184. return 0;
  185. }
  186. static int mbxfb_set_par(struct fb_info *info)
  187. {
  188. struct fb_var_screeninfo *var = &info->var;
  189. struct pixclock_div div;
  190. ushort hbps, ht, hfps, has;
  191. ushort vbps, vt, vfps, vas;
  192. u32 gsctrl = readl(GSCTRL);
  193. u32 gsadr = readl(GSADR);
  194. info->fix.line_length = var->xres_virtual * var->bits_per_pixel / 8;
  195. /* setup color mode */
  196. gsctrl &= ~(FMsk(GSCTRL_GPIXFMT));
  197. /* FIXME: add *WORKING* support for 8-bits per color */
  198. if (info->var.bits_per_pixel == 8) {
  199. return -EINVAL;
  200. } else {
  201. fb_dealloc_cmap(&info->cmap);
  202. gsctrl &= ~GSCTRL_LUT_EN;
  203. info->fix.visual = FB_VISUAL_TRUECOLOR;
  204. switch (info->var.bits_per_pixel) {
  205. case 16:
  206. if (info->var.green.length == 5)
  207. gsctrl |= GSCTRL_GPIXFMT_ARGB1555;
  208. else
  209. gsctrl |= GSCTRL_GPIXFMT_RGB565;
  210. break;
  211. case 24:
  212. gsctrl |= GSCTRL_GPIXFMT_RGB888;
  213. break;
  214. case 32:
  215. gsctrl |= GSCTRL_GPIXFMT_ARGB8888;
  216. break;
  217. }
  218. }
  219. /* setup resolution */
  220. gsctrl &= ~(FMsk(GSCTRL_GSWIDTH) | FMsk(GSCTRL_GSHEIGHT));
  221. gsctrl |= Gsctrl_Width(info->var.xres) |
  222. Gsctrl_Height(info->var.yres);
  223. writel(gsctrl, GSCTRL);
  224. udelay(1000);
  225. gsadr &= ~(FMsk(GSADR_SRCSTRIDE));
  226. gsadr |= Gsadr_Srcstride(info->var.xres * info->var.bits_per_pixel /
  227. (8 * 16) - 1);
  228. writel(gsadr, GSADR);
  229. udelay(1000);
  230. /* setup timings */
  231. var->pixclock = mbxfb_get_pixclock(info->var.pixclock, &div);
  232. writel((Disp_Pll_M(div.m) | Disp_Pll_N(div.n) |
  233. Disp_Pll_P(div.p) | DISP_PLL_EN), DISPPLL);
  234. hbps = var->hsync_len;
  235. has = hbps + var->left_margin;
  236. hfps = has + var->xres;
  237. ht = hfps + var->right_margin;
  238. vbps = var->vsync_len;
  239. vas = vbps + var->upper_margin;
  240. vfps = vas + var->yres;
  241. vt = vfps + var->lower_margin;
  242. writel((Dht01_Hbps(hbps) | Dht01_Ht(ht)), DHT01);
  243. writel((Dht02_Hlbs(has) | Dht02_Has(has)), DHT02);
  244. writel((Dht03_Hfps(hfps) | Dht03_Hrbs(hfps)), DHT03);
  245. writel((Dhdet_Hdes(has) | Dhdet_Hdef(hfps)), DHDET);
  246. writel((Dvt01_Vbps(vbps) | Dvt01_Vt(vt)), DVT01);
  247. writel((Dvt02_Vtbs(vas) | Dvt02_Vas(vas)), DVT02);
  248. writel((Dvt03_Vfps(vfps) | Dvt03_Vbbs(vfps)), DVT03);
  249. writel((Dvdet_Vdes(vas) | Dvdet_Vdef(vfps)), DVDET);
  250. writel((Dvectrl_Vevent(vfps) | Dvectrl_Vfetch(vbps)), DVECTRL);
  251. writel((readl(DSCTRL) | DSCTRL_SYNCGEN_EN), DSCTRL);
  252. return 0;
  253. }
  254. static int mbxfb_blank(int blank, struct fb_info *info)
  255. {
  256. switch (blank) {
  257. case FB_BLANK_POWERDOWN:
  258. case FB_BLANK_VSYNC_SUSPEND:
  259. case FB_BLANK_HSYNC_SUSPEND:
  260. case FB_BLANK_NORMAL:
  261. writel((readl(DSCTRL) & ~DSCTRL_SYNCGEN_EN), DSCTRL);
  262. udelay(1000);
  263. writel((readl(PIXCLK) & ~PIXCLK_EN), PIXCLK);
  264. udelay(1000);
  265. writel((readl(VOVRCLK) & ~VOVRCLK_EN), VOVRCLK);
  266. udelay(1000);
  267. break;
  268. case FB_BLANK_UNBLANK:
  269. writel((readl(DSCTRL) | DSCTRL_SYNCGEN_EN), DSCTRL);
  270. udelay(1000);
  271. writel((readl(PIXCLK) | PIXCLK_EN), PIXCLK);
  272. udelay(1000);
  273. break;
  274. }
  275. return 0;
  276. }
  277. static struct fb_ops mbxfb_ops = {
  278. .owner = THIS_MODULE,
  279. .fb_check_var = mbxfb_check_var,
  280. .fb_set_par = mbxfb_set_par,
  281. .fb_setcolreg = mbxfb_setcolreg,
  282. .fb_fillrect = cfb_fillrect,
  283. .fb_copyarea = cfb_copyarea,
  284. .fb_imageblit = cfb_imageblit,
  285. .fb_blank = mbxfb_blank,
  286. };
  287. /*
  288. Enable external SDRAM controller. Assume that all clocks are active
  289. by now.
  290. */
  291. static void __devinit setup_memc(struct fb_info *fbi)
  292. {
  293. struct mbxfb_info *mfbi = fbi->par;
  294. unsigned long tmp;
  295. int i;
  296. /* FIXME: use platfrom specific parameters */
  297. /* setup SDRAM controller */
  298. writel((LMCFG_LMC_DS | LMCFG_LMC_TS | LMCFG_LMD_TS |
  299. LMCFG_LMA_TS),
  300. LMCFG);
  301. udelay(1000);
  302. writel(LMPWR_MC_PWR_ACT, LMPWR);
  303. udelay(1000);
  304. /* setup SDRAM timings */
  305. writel((Lmtim_Tras(7) | Lmtim_Trp(3) | Lmtim_Trcd(3) |
  306. Lmtim_Trc(9) | Lmtim_Tdpl(2)),
  307. LMTIM);
  308. udelay(1000);
  309. /* setup SDRAM refresh rate */
  310. writel(0xc2b, LMREFRESH);
  311. udelay(1000);
  312. /* setup SDRAM type parameters */
  313. writel((LMTYPE_CASLAT_3 | LMTYPE_BKSZ_2 | LMTYPE_ROWSZ_11 |
  314. LMTYPE_COLSZ_8),
  315. LMTYPE);
  316. udelay(1000);
  317. /* enable memory controller */
  318. writel(LMPWR_MC_PWR_ACT, LMPWR);
  319. udelay(1000);
  320. /* perform dummy reads */
  321. for ( i = 0; i < 16; i++ ) {
  322. tmp = readl(fbi->screen_base);
  323. }
  324. }
  325. static void enable_clocks(struct fb_info *fbi)
  326. {
  327. /* enable clocks */
  328. writel(SYSCLKSRC_PLL_2, SYSCLKSRC);
  329. udelay(1000);
  330. writel(PIXCLKSRC_PLL_1, PIXCLKSRC);
  331. udelay(1000);
  332. writel(0x00000000, CLKSLEEP);
  333. udelay(1000);
  334. writel((Core_Pll_M(0x17) | Core_Pll_N(0x3) | Core_Pll_P(0x0) |
  335. CORE_PLL_EN),
  336. COREPLL);
  337. udelay(1000);
  338. writel((Disp_Pll_M(0x1b) | Disp_Pll_N(0x7) | Disp_Pll_P(0x1) |
  339. DISP_PLL_EN),
  340. DISPPLL);
  341. writel(0x00000000, VOVRCLK);
  342. udelay(1000);
  343. writel(PIXCLK_EN, PIXCLK);
  344. udelay(1000);
  345. writel(MEMCLK_EN, MEMCLK);
  346. udelay(1000);
  347. writel(0x00000006, M24CLK);
  348. udelay(1000);
  349. writel(0x00000006, MBXCLK);
  350. udelay(1000);
  351. writel(SDCLK_EN, SDCLK);
  352. udelay(1000);
  353. writel(0x00000001, PIXCLKDIV);
  354. udelay(1000);
  355. }
  356. static void __devinit setup_graphics(struct fb_info *fbi)
  357. {
  358. unsigned long gsctrl;
  359. gsctrl = GSCTRL_GAMMA_EN | Gsctrl_Width(fbi->var.xres) |
  360. Gsctrl_Height(fbi->var.yres);
  361. switch (fbi->var.bits_per_pixel) {
  362. case 16:
  363. if (fbi->var.green.length == 5)
  364. gsctrl |= GSCTRL_GPIXFMT_ARGB1555;
  365. else
  366. gsctrl |= GSCTRL_GPIXFMT_RGB565;
  367. break;
  368. case 24:
  369. gsctrl |= GSCTRL_GPIXFMT_RGB888;
  370. break;
  371. case 32:
  372. gsctrl |= GSCTRL_GPIXFMT_ARGB8888;
  373. break;
  374. }
  375. writel(gsctrl, GSCTRL);
  376. udelay(1000);
  377. writel(0x00000000, GBBASE);
  378. udelay(1000);
  379. writel(0x00ffffff, GDRCTRL);
  380. udelay(1000);
  381. writel((GSCADR_STR_EN | Gscadr_Gbase_Adr(0x6000)), GSCADR);
  382. udelay(1000);
  383. writel(0x00000000, GPLUT);
  384. udelay(1000);
  385. }
  386. static void __devinit setup_display(struct fb_info *fbi)
  387. {
  388. unsigned long dsctrl = 0;
  389. dsctrl = DSCTRL_BLNK_POL;
  390. if (fbi->var.sync & FB_SYNC_HOR_HIGH_ACT)
  391. dsctrl |= DSCTRL_HS_POL;
  392. if (fbi->var.sync & FB_SYNC_VERT_HIGH_ACT)
  393. dsctrl |= DSCTRL_VS_POL;
  394. writel(dsctrl, DSCTRL);
  395. udelay(1000);
  396. writel(0xd0303010, DMCTRL);
  397. udelay(1000);
  398. writel((readl(DSCTRL) | DSCTRL_SYNCGEN_EN), DSCTRL);
  399. }
  400. static void __devinit enable_controller(struct fb_info *fbi)
  401. {
  402. writel(SYSRST_RST, SYSRST);
  403. udelay(1000);
  404. enable_clocks(fbi);
  405. setup_memc(fbi);
  406. setup_graphics(fbi);
  407. setup_display(fbi);
  408. }
  409. #ifdef CONFIG_PM
  410. /*
  411. * Power management hooks. Note that we won't be called from IRQ context,
  412. * unlike the blank functions above, so we may sleep.
  413. */
  414. static int mbxfb_suspend(struct platform_device *dev, pm_message_t state)
  415. {
  416. /* make frame buffer memory enter self-refresh mode */
  417. writel(LMPWR_MC_PWR_SRM, LMPWR);
  418. while (LMPWRSTAT != LMPWRSTAT_MC_PWR_SRM)
  419. ; /* empty statement */
  420. /* reset the device, since it's initial state is 'mostly sleeping' */
  421. writel(SYSRST_RST, SYSRST);
  422. return 0;
  423. }
  424. static int mbxfb_resume(struct platform_device *dev)
  425. {
  426. struct fb_info *fbi = platform_get_drvdata(dev);
  427. enable_clocks(fbi);
  428. /* setup_graphics(fbi); */
  429. /* setup_display(fbi); */
  430. writel((readl(DSCTRL) | DSCTRL_SYNCGEN_EN), DSCTRL);
  431. return 0;
  432. }
  433. #else
  434. #define mbxfb_suspend NULL
  435. #define mbxfb_resume NULL
  436. #endif
  437. /* debugfs entries */
  438. #ifndef CONFIG_FB_MBX_DEBUG
  439. #define mbxfb_debugfs_init(x) do {} while(0)
  440. #define mbxfb_debugfs_remove(x) do {} while(0)
  441. #endif
  442. #define res_size(_r) (((_r)->end - (_r)->start) + 1)
  443. static int __devinit mbxfb_probe(struct platform_device *dev)
  444. {
  445. int ret;
  446. struct fb_info *fbi;
  447. struct mbxfb_info *mfbi;
  448. struct mbxfb_platform_data *pdata;
  449. dev_dbg(dev, "mbxfb_probe\n");
  450. fbi = framebuffer_alloc(sizeof(struct mbxfb_info), &dev->dev);
  451. if (fbi == NULL) {
  452. dev_err(&dev->dev, "framebuffer_alloc failed\n");
  453. return -ENOMEM;
  454. }
  455. mfbi = fbi->par;
  456. fbi->pseudo_palette = mfbi->pseudo_palette;
  457. pdata = dev->dev.platform_data;
  458. if (pdata->probe)
  459. mfbi->platform_probe = pdata->probe;
  460. if (pdata->remove)
  461. mfbi->platform_remove = pdata->remove;
  462. mfbi->fb_res = platform_get_resource(dev, IORESOURCE_MEM, 0);
  463. mfbi->reg_res = platform_get_resource(dev, IORESOURCE_MEM, 1);
  464. if (!mfbi->fb_res || !mfbi->reg_res) {
  465. dev_err(&dev->dev, "no resources found\n");
  466. ret = -ENODEV;
  467. goto err1;
  468. }
  469. mfbi->fb_req = request_mem_region(mfbi->fb_res->start,
  470. res_size(mfbi->fb_res), dev->name);
  471. if (mfbi->fb_req == NULL) {
  472. dev_err(&dev->dev, "failed to claim framebuffer memory\n");
  473. ret = -EINVAL;
  474. goto err1;
  475. }
  476. mfbi->fb_phys_addr = mfbi->fb_res->start;
  477. mfbi->reg_req = request_mem_region(mfbi->reg_res->start,
  478. res_size(mfbi->reg_res), dev->name);
  479. if (mfbi->reg_req == NULL) {
  480. dev_err(&dev->dev, "failed to claim Marathon registers\n");
  481. ret = -EINVAL;
  482. goto err2;
  483. }
  484. mfbi->reg_phys_addr = mfbi->reg_res->start;
  485. mfbi->reg_virt_addr = ioremap_nocache(mfbi->reg_phys_addr,
  486. res_size(mfbi->reg_req));
  487. if (!mfbi->reg_virt_addr) {
  488. dev_err(&dev->dev, "failed to ioremap Marathon registers\n");
  489. ret = -EINVAL;
  490. goto err3;
  491. }
  492. virt_base_2700 = (unsigned long)mfbi->reg_virt_addr;
  493. mfbi->fb_virt_addr = ioremap_nocache(mfbi->fb_phys_addr,
  494. res_size(mfbi->fb_req));
  495. if (!mfbi->reg_virt_addr) {
  496. dev_err(&dev->dev, "failed to ioremap frame buffer\n");
  497. ret = -EINVAL;
  498. goto err4;
  499. }
  500. /* FIXME: get from platform */
  501. fbi->screen_base = (char __iomem *)(mfbi->fb_virt_addr + 0x60000);
  502. fbi->screen_size = 8 * 1024 * 1024; /* 8 Megs */
  503. fbi->fbops = &mbxfb_ops;
  504. fbi->var = mbxfb_default;
  505. fbi->fix = mbxfb_fix;
  506. fbi->fix.smem_start = mfbi->fb_phys_addr + 0x60000;
  507. fbi->fix.smem_len = 8 * 1024 * 1024;
  508. fbi->fix.line_length = 640 * 2;
  509. ret = fb_alloc_cmap(&fbi->cmap, 256, 0);
  510. if (ret < 0) {
  511. dev_err(&dev->dev, "fb_alloc_cmap failed\n");
  512. ret = -EINVAL;
  513. goto err5;
  514. }
  515. platform_set_drvdata(dev, fbi);
  516. printk(KERN_INFO "fb%d: mbx frame buffer device\n", fbi->node);
  517. if (mfbi->platform_probe)
  518. mfbi->platform_probe(fbi);
  519. enable_controller(fbi);
  520. mbxfb_debugfs_init(fbi);
  521. ret = register_framebuffer(fbi);
  522. if (ret < 0) {
  523. dev_err(&dev->dev, "register_framebuffer failed\n");
  524. ret = -EINVAL;
  525. goto err6;
  526. }
  527. return 0;
  528. err6:
  529. fb_dealloc_cmap(&fbi->cmap);
  530. err5:
  531. iounmap(mfbi->fb_virt_addr);
  532. err4:
  533. iounmap(mfbi->reg_virt_addr);
  534. err3:
  535. release_mem_region(mfbi->reg_res->start, res_size(mfbi->reg_res));
  536. err2:
  537. release_mem_region(mfbi->fb_res->start, res_size(mfbi->fb_res));
  538. err1:
  539. framebuffer_release(fbi);
  540. return ret;
  541. }
  542. static int __devexit mbxfb_remove(struct platform_device *dev)
  543. {
  544. struct fb_info *fbi = platform_get_drvdata(dev);
  545. writel(SYSRST_RST, SYSRST);
  546. udelay(1000);
  547. mbxfb_debugfs_remove(fbi);
  548. if (fbi) {
  549. struct mbxfb_info *mfbi = fbi->par;
  550. unregister_framebuffer(fbi);
  551. if (mfbi) {
  552. if (mfbi->platform_remove)
  553. mfbi->platform_remove(fbi);
  554. if (mfbi->fb_virt_addr)
  555. iounmap(mfbi->fb_virt_addr);
  556. if (mfbi->reg_virt_addr)
  557. iounmap(mfbi->reg_virt_addr);
  558. if (mfbi->reg_req)
  559. release_mem_region(mfbi->reg_req->start,
  560. res_size(mfbi->reg_req));
  561. if (mfbi->fb_req)
  562. release_mem_region(mfbi->fb_req->start,
  563. res_size(mfbi->fb_req));
  564. }
  565. framebuffer_release(fbi);
  566. }
  567. return 0;
  568. }
  569. static struct platform_driver mbxfb_driver = {
  570. .probe = mbxfb_probe,
  571. .remove = mbxfb_remove,
  572. .suspend = mbxfb_suspend,
  573. .resume = mbxfb_resume,
  574. .driver = {
  575. .name = "mbx-fb",
  576. },
  577. };
  578. int __devinit mbxfb_init(void)
  579. {
  580. return platform_driver_register(&mbxfb_driver);
  581. }
  582. static void __devexit mbxfb_exit(void)
  583. {
  584. platform_driver_unregister(&mbxfb_driver);
  585. }
  586. module_init(mbxfb_init);
  587. module_exit(mbxfb_exit);
  588. MODULE_DESCRIPTION("loadable framebuffer driver for Marathon device");
  589. MODULE_AUTHOR("Mike Rapoport, Compulab");
  590. MODULE_LICENSE("GPL");