mb862xxfbdrv.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203
  1. /*
  2. * drivers/mb862xx/mb862xxfb.c
  3. *
  4. * Fujitsu Carmine/Coral-P(A)/Lime framebuffer driver
  5. *
  6. * (C) 2008 Anatolij Gustschin <agust@denx.de>
  7. * DENX Software Engineering
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. *
  13. */
  14. #undef DEBUG
  15. #include <linux/fb.h>
  16. #include <linux/delay.h>
  17. #include <linux/uaccess.h>
  18. #include <linux/init.h>
  19. #include <linux/interrupt.h>
  20. #include <linux/pci.h>
  21. #if defined(CONFIG_OF)
  22. #include <linux/of_platform.h>
  23. #endif
  24. #include "mb862xxfb.h"
  25. #include "mb862xx_reg.h"
  26. #define NR_PALETTE 256
  27. #define MB862XX_MEM_SIZE 0x1000000
  28. #define CORALP_MEM_SIZE 0x2000000
  29. #define CARMINE_MEM_SIZE 0x8000000
  30. #define DRV_NAME "mb862xxfb"
  31. #if defined(CONFIG_SOCRATES)
  32. static struct mb862xx_gc_mode socrates_gc_mode = {
  33. /* Mode for Prime View PM070WL4 TFT LCD Panel */
  34. { "800x480", 45, 800, 480, 40000, 86, 42, 33, 10, 128, 2, 0, 0, 0 },
  35. /* 16 bits/pixel, 16MB, 133MHz, SDRAM memory mode value */
  36. 16, 0x1000000, GC_CCF_COT_133, 0x4157ba63
  37. };
  38. #endif
  39. /* Helpers */
  40. static inline int h_total(struct fb_var_screeninfo *var)
  41. {
  42. return var->xres + var->left_margin +
  43. var->right_margin + var->hsync_len;
  44. }
  45. static inline int v_total(struct fb_var_screeninfo *var)
  46. {
  47. return var->yres + var->upper_margin +
  48. var->lower_margin + var->vsync_len;
  49. }
  50. static inline int hsp(struct fb_var_screeninfo *var)
  51. {
  52. return var->xres + var->right_margin - 1;
  53. }
  54. static inline int vsp(struct fb_var_screeninfo *var)
  55. {
  56. return var->yres + var->lower_margin - 1;
  57. }
  58. static inline int d_pitch(struct fb_var_screeninfo *var)
  59. {
  60. return var->xres * var->bits_per_pixel / 8;
  61. }
  62. static inline unsigned int chan_to_field(unsigned int chan,
  63. struct fb_bitfield *bf)
  64. {
  65. chan &= 0xffff;
  66. chan >>= 16 - bf->length;
  67. return chan << bf->offset;
  68. }
  69. static int mb862xxfb_setcolreg(unsigned regno,
  70. unsigned red, unsigned green, unsigned blue,
  71. unsigned transp, struct fb_info *info)
  72. {
  73. struct mb862xxfb_par *par = info->par;
  74. unsigned int val;
  75. switch (info->fix.visual) {
  76. case FB_VISUAL_TRUECOLOR:
  77. if (regno < 16) {
  78. val = chan_to_field(red, &info->var.red);
  79. val |= chan_to_field(green, &info->var.green);
  80. val |= chan_to_field(blue, &info->var.blue);
  81. par->pseudo_palette[regno] = val;
  82. }
  83. break;
  84. case FB_VISUAL_PSEUDOCOLOR:
  85. if (regno < 256) {
  86. val = (red >> 8) << 16;
  87. val |= (green >> 8) << 8;
  88. val |= blue >> 8;
  89. outreg(disp, GC_L0PAL0 + (regno * 4), val);
  90. }
  91. break;
  92. default:
  93. return 1; /* unsupported type */
  94. }
  95. return 0;
  96. }
  97. static int mb862xxfb_check_var(struct fb_var_screeninfo *var,
  98. struct fb_info *fbi)
  99. {
  100. unsigned long tmp;
  101. if (fbi->dev)
  102. dev_dbg(fbi->dev, "%s\n", __func__);
  103. /* check if these values fit into the registers */
  104. if (var->hsync_len > 255 || var->vsync_len > 255)
  105. return -EINVAL;
  106. if ((var->xres + var->right_margin) >= 4096)
  107. return -EINVAL;
  108. if ((var->yres + var->lower_margin) > 4096)
  109. return -EINVAL;
  110. if (h_total(var) > 4096 || v_total(var) > 4096)
  111. return -EINVAL;
  112. if (var->xres_virtual > 4096 || var->yres_virtual > 4096)
  113. return -EINVAL;
  114. if (var->bits_per_pixel <= 8)
  115. var->bits_per_pixel = 8;
  116. else if (var->bits_per_pixel <= 16)
  117. var->bits_per_pixel = 16;
  118. else if (var->bits_per_pixel <= 32)
  119. var->bits_per_pixel = 32;
  120. /*
  121. * can cope with 8,16 or 24/32bpp if resulting
  122. * pitch is divisible by 64 without remainder
  123. */
  124. if (d_pitch(&fbi->var) % GC_L0M_L0W_UNIT) {
  125. int r;
  126. var->bits_per_pixel = 0;
  127. do {
  128. var->bits_per_pixel += 8;
  129. r = d_pitch(&fbi->var) % GC_L0M_L0W_UNIT;
  130. } while (r && var->bits_per_pixel <= 32);
  131. if (d_pitch(&fbi->var) % GC_L0M_L0W_UNIT)
  132. return -EINVAL;
  133. }
  134. /* line length is going to be 128 bit aligned */
  135. tmp = (var->xres * var->bits_per_pixel) / 8;
  136. if ((tmp & 15) != 0)
  137. return -EINVAL;
  138. /* set r/g/b positions and validate bpp */
  139. switch (var->bits_per_pixel) {
  140. case 8:
  141. var->red.length = var->bits_per_pixel;
  142. var->green.length = var->bits_per_pixel;
  143. var->blue.length = var->bits_per_pixel;
  144. var->red.offset = 0;
  145. var->green.offset = 0;
  146. var->blue.offset = 0;
  147. var->transp.length = 0;
  148. break;
  149. case 16:
  150. var->red.length = 5;
  151. var->green.length = 5;
  152. var->blue.length = 5;
  153. var->red.offset = 10;
  154. var->green.offset = 5;
  155. var->blue.offset = 0;
  156. var->transp.length = 0;
  157. break;
  158. case 24:
  159. case 32:
  160. var->transp.length = 8;
  161. var->red.length = 8;
  162. var->green.length = 8;
  163. var->blue.length = 8;
  164. var->transp.offset = 24;
  165. var->red.offset = 16;
  166. var->green.offset = 8;
  167. var->blue.offset = 0;
  168. break;
  169. default:
  170. return -EINVAL;
  171. }
  172. return 0;
  173. }
  174. /*
  175. * set display parameters
  176. */
  177. static int mb862xxfb_set_par(struct fb_info *fbi)
  178. {
  179. struct mb862xxfb_par *par = fbi->par;
  180. unsigned long reg, sc;
  181. dev_dbg(par->dev, "%s\n", __func__);
  182. if (par->type == BT_CORALP)
  183. mb862xxfb_init_accel(fbi, fbi->var.xres);
  184. if (par->pre_init)
  185. return 0;
  186. /* disp off */
  187. reg = inreg(disp, GC_DCM1);
  188. reg &= ~GC_DCM01_DEN;
  189. outreg(disp, GC_DCM1, reg);
  190. /* set display reference clock div. */
  191. sc = par->refclk / (1000000 / fbi->var.pixclock) - 1;
  192. reg = inreg(disp, GC_DCM1);
  193. reg &= ~(GC_DCM01_CKS | GC_DCM01_RESV | GC_DCM01_SC);
  194. reg |= sc << 8;
  195. outreg(disp, GC_DCM1, reg);
  196. dev_dbg(par->dev, "SC 0x%lx\n", sc);
  197. /* disp dimension, format */
  198. reg = pack(d_pitch(&fbi->var) / GC_L0M_L0W_UNIT,
  199. (fbi->var.yres - 1));
  200. if (fbi->var.bits_per_pixel == 16)
  201. reg |= GC_L0M_L0C_16;
  202. outreg(disp, GC_L0M, reg);
  203. if (fbi->var.bits_per_pixel == 32) {
  204. reg = inreg(disp, GC_L0EM);
  205. outreg(disp, GC_L0EM, reg | GC_L0EM_L0EC_24);
  206. }
  207. outreg(disp, GC_WY_WX, 0);
  208. reg = pack(fbi->var.yres - 1, fbi->var.xres);
  209. outreg(disp, GC_WH_WW, reg);
  210. outreg(disp, GC_L0OA0, 0);
  211. outreg(disp, GC_L0DA0, 0);
  212. outreg(disp, GC_L0DY_L0DX, 0);
  213. outreg(disp, GC_L0WY_L0WX, 0);
  214. outreg(disp, GC_L0WH_L0WW, reg);
  215. /* both HW-cursors off */
  216. reg = inreg(disp, GC_CPM_CUTC);
  217. reg &= ~(GC_CPM_CEN0 | GC_CPM_CEN1);
  218. outreg(disp, GC_CPM_CUTC, reg);
  219. /* timings */
  220. reg = pack(fbi->var.xres - 1, fbi->var.xres - 1);
  221. outreg(disp, GC_HDB_HDP, reg);
  222. reg = pack((fbi->var.yres - 1), vsp(&fbi->var));
  223. outreg(disp, GC_VDP_VSP, reg);
  224. reg = ((fbi->var.vsync_len - 1) << 24) |
  225. pack((fbi->var.hsync_len - 1), hsp(&fbi->var));
  226. outreg(disp, GC_VSW_HSW_HSP, reg);
  227. outreg(disp, GC_HTP, pack(h_total(&fbi->var) - 1, 0));
  228. outreg(disp, GC_VTR, pack(v_total(&fbi->var) - 1, 0));
  229. /* display on */
  230. reg = inreg(disp, GC_DCM1);
  231. reg |= GC_DCM01_DEN | GC_DCM01_L0E;
  232. reg &= ~GC_DCM01_ESY;
  233. outreg(disp, GC_DCM1, reg);
  234. return 0;
  235. }
  236. static int mb862xxfb_pan(struct fb_var_screeninfo *var,
  237. struct fb_info *info)
  238. {
  239. struct mb862xxfb_par *par = info->par;
  240. unsigned long reg;
  241. reg = pack(var->yoffset, var->xoffset);
  242. outreg(disp, GC_L0WY_L0WX, reg);
  243. reg = pack(var->yres_virtual, var->xres_virtual);
  244. outreg(disp, GC_L0WH_L0WW, reg);
  245. return 0;
  246. }
  247. static int mb862xxfb_blank(int mode, struct fb_info *fbi)
  248. {
  249. struct mb862xxfb_par *par = fbi->par;
  250. unsigned long reg;
  251. dev_dbg(fbi->dev, "blank mode=%d\n", mode);
  252. switch (mode) {
  253. case FB_BLANK_POWERDOWN:
  254. reg = inreg(disp, GC_DCM1);
  255. reg &= ~GC_DCM01_DEN;
  256. outreg(disp, GC_DCM1, reg);
  257. break;
  258. case FB_BLANK_UNBLANK:
  259. reg = inreg(disp, GC_DCM1);
  260. reg |= GC_DCM01_DEN;
  261. outreg(disp, GC_DCM1, reg);
  262. break;
  263. case FB_BLANK_NORMAL:
  264. case FB_BLANK_VSYNC_SUSPEND:
  265. case FB_BLANK_HSYNC_SUSPEND:
  266. default:
  267. return 1;
  268. }
  269. return 0;
  270. }
  271. static int mb862xxfb_ioctl(struct fb_info *fbi, unsigned int cmd,
  272. unsigned long arg)
  273. {
  274. struct mb862xxfb_par *par = fbi->par;
  275. struct mb862xx_l1_cfg *l1_cfg = &par->l1_cfg;
  276. void __user *argp = (void __user *)arg;
  277. int *enable;
  278. u32 l1em = 0;
  279. switch (cmd) {
  280. case MB862XX_L1_GET_CFG:
  281. if (copy_to_user(argp, l1_cfg, sizeof(*l1_cfg)))
  282. return -EFAULT;
  283. break;
  284. case MB862XX_L1_SET_CFG:
  285. if (copy_from_user(l1_cfg, argp, sizeof(*l1_cfg)))
  286. return -EFAULT;
  287. if ((l1_cfg->sw >= l1_cfg->dw) && (l1_cfg->sh >= l1_cfg->dh)) {
  288. /* downscaling */
  289. outreg(cap, GC_CAP_CSC,
  290. pack((l1_cfg->sh << 11) / l1_cfg->dh,
  291. (l1_cfg->sw << 11) / l1_cfg->dw));
  292. l1em = inreg(disp, GC_L1EM);
  293. l1em &= ~GC_L1EM_DM;
  294. } else if ((l1_cfg->sw <= l1_cfg->dw) &&
  295. (l1_cfg->sh <= l1_cfg->dh)) {
  296. /* upscaling */
  297. outreg(cap, GC_CAP_CSC,
  298. pack((l1_cfg->sh << 11) / l1_cfg->dh,
  299. (l1_cfg->sw << 11) / l1_cfg->dw));
  300. outreg(cap, GC_CAP_CMSS,
  301. pack(l1_cfg->sw >> 1, l1_cfg->sh));
  302. outreg(cap, GC_CAP_CMDS,
  303. pack(l1_cfg->dw >> 1, l1_cfg->dh));
  304. l1em = inreg(disp, GC_L1EM);
  305. l1em |= GC_L1EM_DM;
  306. }
  307. if (l1_cfg->mirror) {
  308. outreg(cap, GC_CAP_CBM,
  309. inreg(cap, GC_CAP_CBM) | GC_CBM_HRV);
  310. l1em |= l1_cfg->dw * 2 - 8;
  311. } else {
  312. outreg(cap, GC_CAP_CBM,
  313. inreg(cap, GC_CAP_CBM) & ~GC_CBM_HRV);
  314. l1em &= 0xffff0000;
  315. }
  316. outreg(disp, GC_L1EM, l1em);
  317. break;
  318. case MB862XX_L1_ENABLE:
  319. enable = (int *)arg;
  320. if (*enable) {
  321. outreg(disp, GC_L1DA, par->cap_buf);
  322. outreg(cap, GC_CAP_IMG_START,
  323. pack(l1_cfg->sy >> 1, l1_cfg->sx));
  324. outreg(cap, GC_CAP_IMG_END,
  325. pack(l1_cfg->sh, l1_cfg->sw));
  326. outreg(disp, GC_L1M, GC_L1M_16 | GC_L1M_YC | GC_L1M_CS |
  327. (par->l1_stride << 16));
  328. outreg(disp, GC_L1WY_L1WX,
  329. pack(l1_cfg->dy, l1_cfg->dx));
  330. outreg(disp, GC_L1WH_L1WW,
  331. pack(l1_cfg->dh - 1, l1_cfg->dw));
  332. outreg(disp, GC_DLS, 1);
  333. outreg(cap, GC_CAP_VCM,
  334. GC_VCM_VIE | GC_VCM_CM | GC_VCM_VS_PAL);
  335. outreg(disp, GC_DCM1, inreg(disp, GC_DCM1) |
  336. GC_DCM1_DEN | GC_DCM1_L1E);
  337. } else {
  338. outreg(cap, GC_CAP_VCM,
  339. inreg(cap, GC_CAP_VCM) & ~GC_VCM_VIE);
  340. outreg(disp, GC_DCM1,
  341. inreg(disp, GC_DCM1) & ~GC_DCM1_L1E);
  342. }
  343. break;
  344. case MB862XX_L1_CAP_CTL:
  345. enable = (int *)arg;
  346. if (*enable) {
  347. outreg(cap, GC_CAP_VCM,
  348. inreg(cap, GC_CAP_VCM) | GC_VCM_VIE);
  349. } else {
  350. outreg(cap, GC_CAP_VCM,
  351. inreg(cap, GC_CAP_VCM) & ~GC_VCM_VIE);
  352. }
  353. break;
  354. default:
  355. return -EINVAL;
  356. }
  357. return 0;
  358. }
  359. /* framebuffer ops */
  360. static struct fb_ops mb862xxfb_ops = {
  361. .owner = THIS_MODULE,
  362. .fb_check_var = mb862xxfb_check_var,
  363. .fb_set_par = mb862xxfb_set_par,
  364. .fb_setcolreg = mb862xxfb_setcolreg,
  365. .fb_blank = mb862xxfb_blank,
  366. .fb_pan_display = mb862xxfb_pan,
  367. .fb_fillrect = cfb_fillrect,
  368. .fb_copyarea = cfb_copyarea,
  369. .fb_imageblit = cfb_imageblit,
  370. .fb_ioctl = mb862xxfb_ioctl,
  371. };
  372. /* initialize fb_info data */
  373. static int mb862xxfb_init_fbinfo(struct fb_info *fbi)
  374. {
  375. struct mb862xxfb_par *par = fbi->par;
  376. struct mb862xx_gc_mode *mode = par->gc_mode;
  377. unsigned long reg;
  378. int stride;
  379. fbi->fbops = &mb862xxfb_ops;
  380. fbi->pseudo_palette = par->pseudo_palette;
  381. fbi->screen_base = par->fb_base;
  382. fbi->screen_size = par->mapped_vram;
  383. strcpy(fbi->fix.id, DRV_NAME);
  384. fbi->fix.smem_start = (unsigned long)par->fb_base_phys;
  385. fbi->fix.mmio_start = (unsigned long)par->mmio_base_phys;
  386. fbi->fix.mmio_len = par->mmio_len;
  387. fbi->fix.accel = FB_ACCEL_NONE;
  388. fbi->fix.type = FB_TYPE_PACKED_PIXELS;
  389. fbi->fix.type_aux = 0;
  390. fbi->fix.xpanstep = 1;
  391. fbi->fix.ypanstep = 1;
  392. fbi->fix.ywrapstep = 0;
  393. reg = inreg(disp, GC_DCM1);
  394. if (reg & GC_DCM01_DEN && reg & GC_DCM01_L0E) {
  395. /* get the disp mode from active display cfg */
  396. unsigned long sc = ((reg & GC_DCM01_SC) >> 8) + 1;
  397. unsigned long hsp, vsp, ht, vt;
  398. dev_dbg(par->dev, "using bootloader's disp. mode\n");
  399. fbi->var.pixclock = (sc * 1000000) / par->refclk;
  400. fbi->var.xres = (inreg(disp, GC_HDB_HDP) & 0x0fff) + 1;
  401. reg = inreg(disp, GC_VDP_VSP);
  402. fbi->var.yres = ((reg >> 16) & 0x0fff) + 1;
  403. vsp = (reg & 0x0fff) + 1;
  404. fbi->var.xres_virtual = fbi->var.xres;
  405. fbi->var.yres_virtual = fbi->var.yres;
  406. reg = inreg(disp, GC_L0EM);
  407. if (reg & GC_L0EM_L0EC_24) {
  408. fbi->var.bits_per_pixel = 32;
  409. } else {
  410. reg = inreg(disp, GC_L0M);
  411. if (reg & GC_L0M_L0C_16)
  412. fbi->var.bits_per_pixel = 16;
  413. else
  414. fbi->var.bits_per_pixel = 8;
  415. }
  416. reg = inreg(disp, GC_VSW_HSW_HSP);
  417. fbi->var.hsync_len = ((reg & 0xff0000) >> 16) + 1;
  418. fbi->var.vsync_len = ((reg & 0x3f000000) >> 24) + 1;
  419. hsp = (reg & 0xffff) + 1;
  420. ht = ((inreg(disp, GC_HTP) & 0xfff0000) >> 16) + 1;
  421. fbi->var.right_margin = hsp - fbi->var.xres;
  422. fbi->var.left_margin = ht - hsp - fbi->var.hsync_len;
  423. vt = ((inreg(disp, GC_VTR) & 0xfff0000) >> 16) + 1;
  424. fbi->var.lower_margin = vsp - fbi->var.yres;
  425. fbi->var.upper_margin = vt - vsp - fbi->var.vsync_len;
  426. } else if (mode) {
  427. dev_dbg(par->dev, "using supplied mode\n");
  428. fb_videomode_to_var(&fbi->var, (struct fb_videomode *)mode);
  429. fbi->var.bits_per_pixel = mode->def_bpp ? mode->def_bpp : 8;
  430. } else {
  431. int ret;
  432. ret = fb_find_mode(&fbi->var, fbi, "640x480-16@60",
  433. NULL, 0, NULL, 16);
  434. if (ret == 0 || ret == 4) {
  435. dev_err(par->dev,
  436. "failed to get initial mode\n");
  437. return -EINVAL;
  438. }
  439. }
  440. fbi->var.xoffset = 0;
  441. fbi->var.yoffset = 0;
  442. fbi->var.grayscale = 0;
  443. fbi->var.nonstd = 0;
  444. fbi->var.height = -1;
  445. fbi->var.width = -1;
  446. fbi->var.accel_flags = 0;
  447. fbi->var.vmode = FB_VMODE_NONINTERLACED;
  448. fbi->var.activate = FB_ACTIVATE_NOW;
  449. fbi->flags = FBINFO_DEFAULT |
  450. #ifdef __BIG_ENDIAN
  451. FBINFO_FOREIGN_ENDIAN |
  452. #endif
  453. FBINFO_HWACCEL_XPAN |
  454. FBINFO_HWACCEL_YPAN;
  455. /* check and possibly fix bpp */
  456. if ((fbi->fbops->fb_check_var)(&fbi->var, fbi))
  457. dev_err(par->dev, "check_var() failed on initial setup?\n");
  458. fbi->fix.visual = fbi->var.bits_per_pixel == 8 ?
  459. FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR;
  460. fbi->fix.line_length = (fbi->var.xres_virtual *
  461. fbi->var.bits_per_pixel) / 8;
  462. fbi->fix.smem_len = fbi->fix.line_length * fbi->var.yres_virtual;
  463. /*
  464. * reserve space for capture buffers and two cursors
  465. * at the end of vram: 720x576 * 2 * 2.2 + 64x64 * 16.
  466. */
  467. par->cap_buf = par->mapped_vram - 0x1bd800 - 0x10000;
  468. par->cap_len = 0x1bd800;
  469. par->l1_cfg.sx = 0;
  470. par->l1_cfg.sy = 0;
  471. par->l1_cfg.sw = 720;
  472. par->l1_cfg.sh = 576;
  473. par->l1_cfg.dx = 0;
  474. par->l1_cfg.dy = 0;
  475. par->l1_cfg.dw = 720;
  476. par->l1_cfg.dh = 576;
  477. stride = par->l1_cfg.sw * (fbi->var.bits_per_pixel / 8);
  478. par->l1_stride = stride / 64 + ((stride % 64) ? 1 : 0);
  479. outreg(cap, GC_CAP_CBM, GC_CBM_OO | GC_CBM_CBST |
  480. (par->l1_stride << 16));
  481. outreg(cap, GC_CAP_CBOA, par->cap_buf);
  482. outreg(cap, GC_CAP_CBLA, par->cap_buf + par->cap_len);
  483. return 0;
  484. }
  485. /*
  486. * show some display controller and cursor registers
  487. */
  488. static ssize_t mb862xxfb_show_dispregs(struct device *dev,
  489. struct device_attribute *attr, char *buf)
  490. {
  491. struct fb_info *fbi = dev_get_drvdata(dev);
  492. struct mb862xxfb_par *par = fbi->par;
  493. char *ptr = buf;
  494. unsigned int reg;
  495. for (reg = GC_DCM0; reg <= GC_L0DY_L0DX; reg += 4)
  496. ptr += sprintf(ptr, "%08x = %08x\n",
  497. reg, inreg(disp, reg));
  498. for (reg = GC_CPM_CUTC; reg <= GC_CUY1_CUX1; reg += 4)
  499. ptr += sprintf(ptr, "%08x = %08x\n",
  500. reg, inreg(disp, reg));
  501. for (reg = GC_DCM1; reg <= GC_L0WH_L0WW; reg += 4)
  502. ptr += sprintf(ptr, "%08x = %08x\n",
  503. reg, inreg(disp, reg));
  504. for (reg = 0x400; reg <= 0x410; reg += 4)
  505. ptr += sprintf(ptr, "geo %08x = %08x\n",
  506. reg, inreg(geo, reg));
  507. for (reg = 0x400; reg <= 0x410; reg += 4)
  508. ptr += sprintf(ptr, "draw %08x = %08x\n",
  509. reg, inreg(draw, reg));
  510. for (reg = 0x440; reg <= 0x450; reg += 4)
  511. ptr += sprintf(ptr, "draw %08x = %08x\n",
  512. reg, inreg(draw, reg));
  513. return ptr - buf;
  514. }
  515. static DEVICE_ATTR(dispregs, 0444, mb862xxfb_show_dispregs, NULL);
  516. irqreturn_t mb862xx_intr(int irq, void *dev_id)
  517. {
  518. struct mb862xxfb_par *par = (struct mb862xxfb_par *) dev_id;
  519. unsigned long reg_ist, mask;
  520. if (!par)
  521. return IRQ_NONE;
  522. if (par->type == BT_CARMINE) {
  523. /* Get Interrupt Status */
  524. reg_ist = inreg(ctrl, GC_CTRL_STATUS);
  525. mask = inreg(ctrl, GC_CTRL_INT_MASK);
  526. if (reg_ist == 0)
  527. return IRQ_HANDLED;
  528. reg_ist &= mask;
  529. if (reg_ist == 0)
  530. return IRQ_HANDLED;
  531. /* Clear interrupt status */
  532. outreg(ctrl, 0x0, reg_ist);
  533. } else {
  534. /* Get status */
  535. reg_ist = inreg(host, GC_IST);
  536. mask = inreg(host, GC_IMASK);
  537. reg_ist &= mask;
  538. if (reg_ist == 0)
  539. return IRQ_HANDLED;
  540. /* Clear status */
  541. outreg(host, GC_IST, ~reg_ist);
  542. }
  543. return IRQ_HANDLED;
  544. }
  545. #if defined(CONFIG_FB_MB862XX_LIME)
  546. /*
  547. * GDC (Lime, Coral(B/Q), Mint, ...) on host bus
  548. */
  549. static int mb862xx_gdc_init(struct mb862xxfb_par *par)
  550. {
  551. unsigned long ccf, mmr;
  552. unsigned long ver, rev;
  553. if (!par)
  554. return -ENODEV;
  555. #if defined(CONFIG_FB_PRE_INIT_FB)
  556. par->pre_init = 1;
  557. #endif
  558. par->host = par->mmio_base;
  559. par->i2c = par->mmio_base + MB862XX_I2C_BASE;
  560. par->disp = par->mmio_base + MB862XX_DISP_BASE;
  561. par->cap = par->mmio_base + MB862XX_CAP_BASE;
  562. par->draw = par->mmio_base + MB862XX_DRAW_BASE;
  563. par->geo = par->mmio_base + MB862XX_GEO_BASE;
  564. par->pio = par->mmio_base + MB862XX_PIO_BASE;
  565. par->refclk = GC_DISP_REFCLK_400;
  566. ver = inreg(host, GC_CID);
  567. rev = inreg(pio, GC_REVISION);
  568. if ((ver == 0x303) && (rev & 0xffffff00) == 0x20050100) {
  569. dev_info(par->dev, "Fujitsu Lime v1.%d found\n",
  570. (int)rev & 0xff);
  571. par->type = BT_LIME;
  572. ccf = par->gc_mode ? par->gc_mode->ccf : GC_CCF_COT_100;
  573. mmr = par->gc_mode ? par->gc_mode->mmr : 0x414fb7f2;
  574. } else {
  575. dev_info(par->dev, "? GDC, CID/Rev.: 0x%lx/0x%lx \n", ver, rev);
  576. return -ENODEV;
  577. }
  578. if (!par->pre_init) {
  579. outreg(host, GC_CCF, ccf);
  580. udelay(200);
  581. outreg(host, GC_MMR, mmr);
  582. udelay(10);
  583. }
  584. /* interrupt status */
  585. outreg(host, GC_IST, 0);
  586. outreg(host, GC_IMASK, GC_INT_EN);
  587. return 0;
  588. }
  589. static int __devinit of_platform_mb862xx_probe(struct platform_device *ofdev)
  590. {
  591. struct device_node *np = ofdev->dev.of_node;
  592. struct device *dev = &ofdev->dev;
  593. struct mb862xxfb_par *par;
  594. struct fb_info *info;
  595. struct resource res;
  596. resource_size_t res_size;
  597. unsigned long ret = -ENODEV;
  598. if (of_address_to_resource(np, 0, &res)) {
  599. dev_err(dev, "Invalid address\n");
  600. return -ENXIO;
  601. }
  602. info = framebuffer_alloc(sizeof(struct mb862xxfb_par), dev);
  603. if (info == NULL) {
  604. dev_err(dev, "cannot allocate framebuffer\n");
  605. return -ENOMEM;
  606. }
  607. par = info->par;
  608. par->info = info;
  609. par->dev = dev;
  610. par->irq = irq_of_parse_and_map(np, 0);
  611. if (par->irq == NO_IRQ) {
  612. dev_err(dev, "failed to map irq\n");
  613. ret = -ENODEV;
  614. goto fbrel;
  615. }
  616. res_size = 1 + res.end - res.start;
  617. par->res = request_mem_region(res.start, res_size, DRV_NAME);
  618. if (par->res == NULL) {
  619. dev_err(dev, "Cannot claim framebuffer/mmio\n");
  620. ret = -ENXIO;
  621. goto irqdisp;
  622. }
  623. #if defined(CONFIG_SOCRATES)
  624. par->gc_mode = &socrates_gc_mode;
  625. #endif
  626. par->fb_base_phys = res.start;
  627. par->mmio_base_phys = res.start + MB862XX_MMIO_BASE;
  628. par->mmio_len = MB862XX_MMIO_SIZE;
  629. if (par->gc_mode)
  630. par->mapped_vram = par->gc_mode->max_vram;
  631. else
  632. par->mapped_vram = MB862XX_MEM_SIZE;
  633. par->fb_base = ioremap(par->fb_base_phys, par->mapped_vram);
  634. if (par->fb_base == NULL) {
  635. dev_err(dev, "Cannot map framebuffer\n");
  636. goto rel_reg;
  637. }
  638. par->mmio_base = ioremap(par->mmio_base_phys, par->mmio_len);
  639. if (par->mmio_base == NULL) {
  640. dev_err(dev, "Cannot map registers\n");
  641. goto fb_unmap;
  642. }
  643. dev_dbg(dev, "fb phys 0x%llx 0x%lx\n",
  644. (u64)par->fb_base_phys, (ulong)par->mapped_vram);
  645. dev_dbg(dev, "mmio phys 0x%llx 0x%lx, (irq = %d)\n",
  646. (u64)par->mmio_base_phys, (ulong)par->mmio_len, par->irq);
  647. if (mb862xx_gdc_init(par))
  648. goto io_unmap;
  649. if (request_irq(par->irq, mb862xx_intr, IRQF_DISABLED,
  650. DRV_NAME, (void *)par)) {
  651. dev_err(dev, "Cannot request irq\n");
  652. goto io_unmap;
  653. }
  654. mb862xxfb_init_fbinfo(info);
  655. if (fb_alloc_cmap(&info->cmap, NR_PALETTE, 0) < 0) {
  656. dev_err(dev, "Could not allocate cmap for fb_info.\n");
  657. goto free_irq;
  658. }
  659. if ((info->fbops->fb_set_par)(info))
  660. dev_err(dev, "set_var() failed on initial setup?\n");
  661. if (register_framebuffer(info)) {
  662. dev_err(dev, "failed to register framebuffer\n");
  663. goto rel_cmap;
  664. }
  665. dev_set_drvdata(dev, info);
  666. if (device_create_file(dev, &dev_attr_dispregs))
  667. dev_err(dev, "Can't create sysfs regdump file\n");
  668. return 0;
  669. rel_cmap:
  670. fb_dealloc_cmap(&info->cmap);
  671. free_irq:
  672. outreg(host, GC_IMASK, 0);
  673. free_irq(par->irq, (void *)par);
  674. io_unmap:
  675. iounmap(par->mmio_base);
  676. fb_unmap:
  677. iounmap(par->fb_base);
  678. rel_reg:
  679. release_mem_region(res.start, res_size);
  680. irqdisp:
  681. irq_dispose_mapping(par->irq);
  682. fbrel:
  683. dev_set_drvdata(dev, NULL);
  684. framebuffer_release(info);
  685. return ret;
  686. }
  687. static int __devexit of_platform_mb862xx_remove(struct platform_device *ofdev)
  688. {
  689. struct fb_info *fbi = dev_get_drvdata(&ofdev->dev);
  690. struct mb862xxfb_par *par = fbi->par;
  691. resource_size_t res_size = 1 + par->res->end - par->res->start;
  692. unsigned long reg;
  693. dev_dbg(fbi->dev, "%s release\n", fbi->fix.id);
  694. /* display off */
  695. reg = inreg(disp, GC_DCM1);
  696. reg &= ~(GC_DCM01_DEN | GC_DCM01_L0E);
  697. outreg(disp, GC_DCM1, reg);
  698. /* disable interrupts */
  699. outreg(host, GC_IMASK, 0);
  700. free_irq(par->irq, (void *)par);
  701. irq_dispose_mapping(par->irq);
  702. device_remove_file(&ofdev->dev, &dev_attr_dispregs);
  703. unregister_framebuffer(fbi);
  704. fb_dealloc_cmap(&fbi->cmap);
  705. iounmap(par->mmio_base);
  706. iounmap(par->fb_base);
  707. dev_set_drvdata(&ofdev->dev, NULL);
  708. release_mem_region(par->res->start, res_size);
  709. framebuffer_release(fbi);
  710. return 0;
  711. }
  712. /*
  713. * common types
  714. */
  715. static struct of_device_id __devinitdata of_platform_mb862xx_tbl[] = {
  716. { .compatible = "fujitsu,MB86276", },
  717. { .compatible = "fujitsu,lime", },
  718. { .compatible = "fujitsu,MB86277", },
  719. { .compatible = "fujitsu,mint", },
  720. { .compatible = "fujitsu,MB86293", },
  721. { .compatible = "fujitsu,MB86294", },
  722. { .compatible = "fujitsu,coral", },
  723. { /* end */ }
  724. };
  725. static struct platform_driver of_platform_mb862xxfb_driver = {
  726. .driver = {
  727. .name = DRV_NAME,
  728. .owner = THIS_MODULE,
  729. .of_match_table = of_platform_mb862xx_tbl,
  730. },
  731. .probe = of_platform_mb862xx_probe,
  732. .remove = __devexit_p(of_platform_mb862xx_remove),
  733. };
  734. #endif
  735. #if defined(CONFIG_FB_MB862XX_PCI_GDC)
  736. static int coralp_init(struct mb862xxfb_par *par)
  737. {
  738. int cn, ver;
  739. par->host = par->mmio_base;
  740. par->i2c = par->mmio_base + MB862XX_I2C_BASE;
  741. par->disp = par->mmio_base + MB862XX_DISP_BASE;
  742. par->cap = par->mmio_base + MB862XX_CAP_BASE;
  743. par->draw = par->mmio_base + MB862XX_DRAW_BASE;
  744. par->geo = par->mmio_base + MB862XX_GEO_BASE;
  745. par->pio = par->mmio_base + MB862XX_PIO_BASE;
  746. par->refclk = GC_DISP_REFCLK_400;
  747. if (par->mapped_vram >= 0x2000000) {
  748. /* relocate gdc registers space */
  749. writel(1, par->fb_base + MB862XX_MMIO_BASE + GC_RSW);
  750. udelay(1); /* wait at least 20 bus cycles */
  751. }
  752. ver = inreg(host, GC_CID);
  753. cn = (ver & GC_CID_CNAME_MSK) >> 8;
  754. ver = ver & GC_CID_VERSION_MSK;
  755. if (cn == 3) {
  756. unsigned long reg;
  757. dev_info(par->dev, "Fujitsu Coral-%s GDC Rev.%d found\n",\
  758. (ver == 6) ? "P" : (ver == 8) ? "PA" : "?",
  759. par->pdev->revision);
  760. reg = inreg(disp, GC_DCM1);
  761. if (reg & GC_DCM01_DEN && reg & GC_DCM01_L0E)
  762. par->pre_init = 1;
  763. if (!par->pre_init) {
  764. outreg(host, GC_CCF, GC_CCF_CGE_166 | GC_CCF_COT_133);
  765. udelay(200);
  766. outreg(host, GC_MMR, GC_MMR_CORALP_EVB_VAL);
  767. udelay(10);
  768. }
  769. /* Clear interrupt status */
  770. outreg(host, GC_IST, 0);
  771. } else {
  772. return -ENODEV;
  773. }
  774. mb862xx_i2c_init(par);
  775. return 0;
  776. }
  777. static int init_dram_ctrl(struct mb862xxfb_par *par)
  778. {
  779. unsigned long i = 0;
  780. /*
  781. * Set io mode first! Spec. says IC may be destroyed
  782. * if not set to SSTL2/LVCMOS before init.
  783. */
  784. outreg(dram_ctrl, GC_DCTL_IOCONT1_IOCONT0, GC_EVB_DCTL_IOCONT1_IOCONT0);
  785. /* DRAM init */
  786. outreg(dram_ctrl, GC_DCTL_MODE_ADD, GC_EVB_DCTL_MODE_ADD);
  787. outreg(dram_ctrl, GC_DCTL_SETTIME1_EMODE, GC_EVB_DCTL_SETTIME1_EMODE);
  788. outreg(dram_ctrl, GC_DCTL_REFRESH_SETTIME2,
  789. GC_EVB_DCTL_REFRESH_SETTIME2);
  790. outreg(dram_ctrl, GC_DCTL_RSV2_RSV1, GC_EVB_DCTL_RSV2_RSV1);
  791. outreg(dram_ctrl, GC_DCTL_DDRIF2_DDRIF1, GC_EVB_DCTL_DDRIF2_DDRIF1);
  792. outreg(dram_ctrl, GC_DCTL_RSV0_STATES, GC_EVB_DCTL_RSV0_STATES);
  793. /* DLL reset done? */
  794. while ((inreg(dram_ctrl, GC_DCTL_RSV0_STATES) & GC_DCTL_STATES_MSK)) {
  795. udelay(GC_DCTL_INIT_WAIT_INTERVAL);
  796. if (i++ > GC_DCTL_INIT_WAIT_CNT) {
  797. dev_err(par->dev, "VRAM init failed.\n");
  798. return -EINVAL;
  799. }
  800. }
  801. outreg(dram_ctrl, GC_DCTL_MODE_ADD, GC_EVB_DCTL_MODE_ADD_AFT_RST);
  802. outreg(dram_ctrl, GC_DCTL_RSV0_STATES, GC_EVB_DCTL_RSV0_STATES_AFT_RST);
  803. return 0;
  804. }
  805. static int carmine_init(struct mb862xxfb_par *par)
  806. {
  807. unsigned long reg;
  808. par->ctrl = par->mmio_base + MB86297_CTRL_BASE;
  809. par->i2c = par->mmio_base + MB86297_I2C_BASE;
  810. par->disp = par->mmio_base + MB86297_DISP0_BASE;
  811. par->disp1 = par->mmio_base + MB86297_DISP1_BASE;
  812. par->cap = par->mmio_base + MB86297_CAP0_BASE;
  813. par->cap1 = par->mmio_base + MB86297_CAP1_BASE;
  814. par->draw = par->mmio_base + MB86297_DRAW_BASE;
  815. par->dram_ctrl = par->mmio_base + MB86297_DRAMCTRL_BASE;
  816. par->wrback = par->mmio_base + MB86297_WRBACK_BASE;
  817. par->refclk = GC_DISP_REFCLK_533;
  818. /* warm up */
  819. reg = GC_CTRL_CLK_EN_DRAM | GC_CTRL_CLK_EN_2D3D | GC_CTRL_CLK_EN_DISP0;
  820. outreg(ctrl, GC_CTRL_CLK_ENABLE, reg);
  821. /* check for engine module revision */
  822. if (inreg(draw, GC_2D3D_REV) == GC_RE_REVISION)
  823. dev_info(par->dev, "Fujitsu Carmine GDC Rev.%d found\n",
  824. par->pdev->revision);
  825. else
  826. goto err_init;
  827. reg &= ~GC_CTRL_CLK_EN_2D3D;
  828. outreg(ctrl, GC_CTRL_CLK_ENABLE, reg);
  829. /* set up vram */
  830. if (init_dram_ctrl(par) < 0)
  831. goto err_init;
  832. outreg(ctrl, GC_CTRL_INT_MASK, 0);
  833. return 0;
  834. err_init:
  835. outreg(ctrl, GC_CTRL_CLK_ENABLE, 0);
  836. return -EINVAL;
  837. }
  838. static inline int mb862xx_pci_gdc_init(struct mb862xxfb_par *par)
  839. {
  840. switch (par->type) {
  841. case BT_CORALP:
  842. return coralp_init(par);
  843. case BT_CARMINE:
  844. return carmine_init(par);
  845. default:
  846. return -ENODEV;
  847. }
  848. }
  849. #define CHIP_ID(id) \
  850. { PCI_DEVICE(PCI_VENDOR_ID_FUJITSU_LIMITED, id) }
  851. static struct pci_device_id mb862xx_pci_tbl[] __devinitdata = {
  852. /* MB86295/MB86296 */
  853. CHIP_ID(PCI_DEVICE_ID_FUJITSU_CORALP),
  854. CHIP_ID(PCI_DEVICE_ID_FUJITSU_CORALPA),
  855. /* MB86297 */
  856. CHIP_ID(PCI_DEVICE_ID_FUJITSU_CARMINE),
  857. { 0, }
  858. };
  859. MODULE_DEVICE_TABLE(pci, mb862xx_pci_tbl);
  860. static int __devinit mb862xx_pci_probe(struct pci_dev *pdev,
  861. const struct pci_device_id *ent)
  862. {
  863. struct mb862xxfb_par *par;
  864. struct fb_info *info;
  865. struct device *dev = &pdev->dev;
  866. int ret;
  867. ret = pci_enable_device(pdev);
  868. if (ret < 0) {
  869. dev_err(dev, "Cannot enable PCI device\n");
  870. goto out;
  871. }
  872. info = framebuffer_alloc(sizeof(struct mb862xxfb_par), dev);
  873. if (!info) {
  874. dev_err(dev, "framebuffer alloc failed\n");
  875. ret = -ENOMEM;
  876. goto dis_dev;
  877. }
  878. par = info->par;
  879. par->info = info;
  880. par->dev = dev;
  881. par->pdev = pdev;
  882. par->irq = pdev->irq;
  883. ret = pci_request_regions(pdev, DRV_NAME);
  884. if (ret < 0) {
  885. dev_err(dev, "Cannot reserve region(s) for PCI device\n");
  886. goto rel_fb;
  887. }
  888. switch (pdev->device) {
  889. case PCI_DEVICE_ID_FUJITSU_CORALP:
  890. case PCI_DEVICE_ID_FUJITSU_CORALPA:
  891. par->fb_base_phys = pci_resource_start(par->pdev, 0);
  892. par->mapped_vram = CORALP_MEM_SIZE;
  893. if (par->mapped_vram >= 0x2000000) {
  894. par->mmio_base_phys = par->fb_base_phys +
  895. MB862XX_MMIO_HIGH_BASE;
  896. } else {
  897. par->mmio_base_phys = par->fb_base_phys +
  898. MB862XX_MMIO_BASE;
  899. }
  900. par->mmio_len = MB862XX_MMIO_SIZE;
  901. par->type = BT_CORALP;
  902. break;
  903. case PCI_DEVICE_ID_FUJITSU_CARMINE:
  904. par->fb_base_phys = pci_resource_start(par->pdev, 2);
  905. par->mmio_base_phys = pci_resource_start(par->pdev, 3);
  906. par->mmio_len = pci_resource_len(par->pdev, 3);
  907. par->mapped_vram = CARMINE_MEM_SIZE;
  908. par->type = BT_CARMINE;
  909. break;
  910. default:
  911. /* should never occur */
  912. goto rel_reg;
  913. }
  914. par->fb_base = ioremap(par->fb_base_phys, par->mapped_vram);
  915. if (par->fb_base == NULL) {
  916. dev_err(dev, "Cannot map framebuffer\n");
  917. goto rel_reg;
  918. }
  919. par->mmio_base = ioremap(par->mmio_base_phys, par->mmio_len);
  920. if (par->mmio_base == NULL) {
  921. dev_err(dev, "Cannot map registers\n");
  922. ret = -EIO;
  923. goto fb_unmap;
  924. }
  925. dev_dbg(dev, "fb phys 0x%llx 0x%lx\n",
  926. (unsigned long long)par->fb_base_phys, (ulong)par->mapped_vram);
  927. dev_dbg(dev, "mmio phys 0x%llx 0x%lx\n",
  928. (unsigned long long)par->mmio_base_phys, (ulong)par->mmio_len);
  929. if (mb862xx_pci_gdc_init(par))
  930. goto io_unmap;
  931. if (request_irq(par->irq, mb862xx_intr, IRQF_DISABLED | IRQF_SHARED,
  932. DRV_NAME, (void *)par)) {
  933. dev_err(dev, "Cannot request irq\n");
  934. goto io_unmap;
  935. }
  936. mb862xxfb_init_fbinfo(info);
  937. if (fb_alloc_cmap(&info->cmap, NR_PALETTE, 0) < 0) {
  938. dev_err(dev, "Could not allocate cmap for fb_info.\n");
  939. ret = -ENOMEM;
  940. goto free_irq;
  941. }
  942. if ((info->fbops->fb_set_par)(info))
  943. dev_err(dev, "set_var() failed on initial setup?\n");
  944. ret = register_framebuffer(info);
  945. if (ret < 0) {
  946. dev_err(dev, "failed to register framebuffer\n");
  947. goto rel_cmap;
  948. }
  949. pci_set_drvdata(pdev, info);
  950. if (device_create_file(dev, &dev_attr_dispregs))
  951. dev_err(dev, "Can't create sysfs regdump file\n");
  952. if (par->type == BT_CARMINE)
  953. outreg(ctrl, GC_CTRL_INT_MASK, GC_CARMINE_INT_EN);
  954. else
  955. outreg(host, GC_IMASK, GC_INT_EN);
  956. return 0;
  957. rel_cmap:
  958. fb_dealloc_cmap(&info->cmap);
  959. free_irq:
  960. free_irq(par->irq, (void *)par);
  961. io_unmap:
  962. iounmap(par->mmio_base);
  963. fb_unmap:
  964. iounmap(par->fb_base);
  965. rel_reg:
  966. pci_release_regions(pdev);
  967. rel_fb:
  968. framebuffer_release(info);
  969. dis_dev:
  970. pci_disable_device(pdev);
  971. out:
  972. return ret;
  973. }
  974. static void __devexit mb862xx_pci_remove(struct pci_dev *pdev)
  975. {
  976. struct fb_info *fbi = pci_get_drvdata(pdev);
  977. struct mb862xxfb_par *par = fbi->par;
  978. unsigned long reg;
  979. dev_dbg(fbi->dev, "%s release\n", fbi->fix.id);
  980. /* display off */
  981. reg = inreg(disp, GC_DCM1);
  982. reg &= ~(GC_DCM01_DEN | GC_DCM01_L0E);
  983. outreg(disp, GC_DCM1, reg);
  984. if (par->type == BT_CARMINE) {
  985. outreg(ctrl, GC_CTRL_INT_MASK, 0);
  986. outreg(ctrl, GC_CTRL_CLK_ENABLE, 0);
  987. } else {
  988. outreg(host, GC_IMASK, 0);
  989. }
  990. mb862xx_i2c_exit(par);
  991. device_remove_file(&pdev->dev, &dev_attr_dispregs);
  992. pci_set_drvdata(pdev, NULL);
  993. unregister_framebuffer(fbi);
  994. fb_dealloc_cmap(&fbi->cmap);
  995. free_irq(par->irq, (void *)par);
  996. iounmap(par->mmio_base);
  997. iounmap(par->fb_base);
  998. pci_release_regions(pdev);
  999. framebuffer_release(fbi);
  1000. pci_disable_device(pdev);
  1001. }
  1002. static struct pci_driver mb862xxfb_pci_driver = {
  1003. .name = DRV_NAME,
  1004. .id_table = mb862xx_pci_tbl,
  1005. .probe = mb862xx_pci_probe,
  1006. .remove = __devexit_p(mb862xx_pci_remove),
  1007. };
  1008. #endif
  1009. static int __devinit mb862xxfb_init(void)
  1010. {
  1011. int ret = -ENODEV;
  1012. #if defined(CONFIG_FB_MB862XX_LIME)
  1013. ret = platform_driver_register(&of_platform_mb862xxfb_driver);
  1014. #endif
  1015. #if defined(CONFIG_FB_MB862XX_PCI_GDC)
  1016. ret = pci_register_driver(&mb862xxfb_pci_driver);
  1017. #endif
  1018. return ret;
  1019. }
  1020. static void __exit mb862xxfb_exit(void)
  1021. {
  1022. #if defined(CONFIG_FB_MB862XX_LIME)
  1023. platform_driver_unregister(&of_platform_mb862xxfb_driver);
  1024. #endif
  1025. #if defined(CONFIG_FB_MB862XX_PCI_GDC)
  1026. pci_unregister_driver(&mb862xxfb_pci_driver);
  1027. #endif
  1028. }
  1029. module_init(mb862xxfb_init);
  1030. module_exit(mb862xxfb_exit);
  1031. MODULE_DESCRIPTION("Fujitsu MB862xx Framebuffer driver");
  1032. MODULE_AUTHOR("Anatolij Gustschin <agust@denx.de>");
  1033. MODULE_LICENSE("GPL v2");