mbxfb.c 16 KB

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