leo.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  1. /* leo.c: LEO frame buffer driver
  2. *
  3. * Copyright (C) 2003, 2006 David S. Miller (davem@davemloft.net)
  4. * Copyright (C) 1996-1999 Jakub Jelinek (jj@ultra.linux.cz)
  5. * Copyright (C) 1997 Michal Rehacek (Michal.Rehacek@st.mff.cuni.cz)
  6. *
  7. * Driver layout based loosely on tgafb.c, see that file for credits.
  8. */
  9. #include <linux/module.h>
  10. #include <linux/kernel.h>
  11. #include <linux/errno.h>
  12. #include <linux/string.h>
  13. #include <linux/slab.h>
  14. #include <linux/delay.h>
  15. #include <linux/init.h>
  16. #include <linux/fb.h>
  17. #include <linux/mm.h>
  18. #include <asm/io.h>
  19. #include <asm/prom.h>
  20. #include <asm/of_device.h>
  21. #include <asm/fbio.h>
  22. #include "sbuslib.h"
  23. /*
  24. * Local functions.
  25. */
  26. static int leo_setcolreg(unsigned, unsigned, unsigned, unsigned,
  27. unsigned, struct fb_info *);
  28. static int leo_blank(int, struct fb_info *);
  29. static int leo_mmap(struct fb_info *, struct vm_area_struct *);
  30. static int leo_ioctl(struct fb_info *, unsigned int, unsigned long);
  31. static int leo_pan_display(struct fb_var_screeninfo *, struct fb_info *);
  32. /*
  33. * Frame buffer operations
  34. */
  35. static struct fb_ops leo_ops = {
  36. .owner = THIS_MODULE,
  37. .fb_setcolreg = leo_setcolreg,
  38. .fb_blank = leo_blank,
  39. .fb_pan_display = leo_pan_display,
  40. .fb_fillrect = cfb_fillrect,
  41. .fb_copyarea = cfb_copyarea,
  42. .fb_imageblit = cfb_imageblit,
  43. .fb_mmap = leo_mmap,
  44. .fb_ioctl = leo_ioctl,
  45. #ifdef CONFIG_COMPAT
  46. .fb_compat_ioctl = sbusfb_compat_ioctl,
  47. #endif
  48. };
  49. #define LEO_OFF_LC_SS0_KRN 0x00200000UL
  50. #define LEO_OFF_LC_SS0_USR 0x00201000UL
  51. #define LEO_OFF_LC_SS1_KRN 0x01200000UL
  52. #define LEO_OFF_LC_SS1_USR 0x01201000UL
  53. #define LEO_OFF_LD_SS0 0x00400000UL
  54. #define LEO_OFF_LD_SS1 0x01400000UL
  55. #define LEO_OFF_LD_GBL 0x00401000UL
  56. #define LEO_OFF_LX_KRN 0x00600000UL
  57. #define LEO_OFF_LX_CURSOR 0x00601000UL
  58. #define LEO_OFF_SS0 0x00800000UL
  59. #define LEO_OFF_SS1 0x01800000UL
  60. #define LEO_OFF_UNK 0x00602000UL
  61. #define LEO_OFF_UNK2 0x00000000UL
  62. #define LEO_CUR_ENABLE 0x00000080
  63. #define LEO_CUR_UPDATE 0x00000030
  64. #define LEO_CUR_PROGRESS 0x00000006
  65. #define LEO_CUR_UPDATECMAP 0x00000003
  66. #define LEO_CUR_TYPE_MASK 0x00000000
  67. #define LEO_CUR_TYPE_IMAGE 0x00000020
  68. #define LEO_CUR_TYPE_CMAP 0x00000050
  69. struct leo_cursor {
  70. u8 xxx0[16];
  71. u32 cur_type;
  72. u32 cur_misc;
  73. u32 cur_cursxy;
  74. u32 cur_data;
  75. };
  76. #define LEO_KRN_TYPE_CLUT0 0x00001000
  77. #define LEO_KRN_TYPE_CLUT1 0x00001001
  78. #define LEO_KRN_TYPE_CLUT2 0x00001002
  79. #define LEO_KRN_TYPE_WID 0x00001003
  80. #define LEO_KRN_TYPE_UNK 0x00001006
  81. #define LEO_KRN_TYPE_VIDEO 0x00002003
  82. #define LEO_KRN_TYPE_CLUTDATA 0x00004000
  83. #define LEO_KRN_CSR_ENABLE 0x00000008
  84. #define LEO_KRN_CSR_PROGRESS 0x00000004
  85. #define LEO_KRN_CSR_UNK 0x00000002
  86. #define LEO_KRN_CSR_UNK2 0x00000001
  87. struct leo_lx_krn {
  88. u32 krn_type;
  89. u32 krn_csr;
  90. u32 krn_value;
  91. };
  92. struct leo_lc_ss0_krn {
  93. u32 misc;
  94. u8 xxx0[0x800-4];
  95. u32 rev;
  96. };
  97. struct leo_lc_ss0_usr {
  98. u32 csr;
  99. u32 addrspace;
  100. u32 fontmsk;
  101. u32 fontt;
  102. u32 extent;
  103. u32 src;
  104. u32 dst;
  105. u32 copy;
  106. u32 fill;
  107. };
  108. struct leo_lc_ss1_krn {
  109. u8 unknown;
  110. };
  111. struct leo_lc_ss1_usr {
  112. u8 unknown;
  113. };
  114. struct leo_ld {
  115. u8 xxx0[0xe00];
  116. u32 csr;
  117. u32 wid;
  118. u32 wmask;
  119. u32 widclip;
  120. u32 vclipmin;
  121. u32 vclipmax;
  122. u32 pickmin; /* SS1 only */
  123. u32 pickmax; /* SS1 only */
  124. u32 fg;
  125. u32 bg;
  126. u32 src; /* Copy/Scroll (SS0 only) */
  127. u32 dst; /* Copy/Scroll/Fill (SS0 only) */
  128. u32 extent; /* Copy/Scroll/Fill size (SS0 only) */
  129. u32 xxx1[3];
  130. u32 setsem; /* SS1 only */
  131. u32 clrsem; /* SS1 only */
  132. u32 clrpick; /* SS1 only */
  133. u32 clrdat; /* SS1 only */
  134. u32 alpha; /* SS1 only */
  135. u8 xxx2[0x2c];
  136. u32 winbg;
  137. u32 planemask;
  138. u32 rop;
  139. u32 z;
  140. u32 dczf; /* SS1 only */
  141. u32 dczb; /* SS1 only */
  142. u32 dcs; /* SS1 only */
  143. u32 dczs; /* SS1 only */
  144. u32 pickfb; /* SS1 only */
  145. u32 pickbb; /* SS1 only */
  146. u32 dcfc; /* SS1 only */
  147. u32 forcecol; /* SS1 only */
  148. u32 door[8]; /* SS1 only */
  149. u32 pick[5]; /* SS1 only */
  150. };
  151. #define LEO_SS1_MISC_ENABLE 0x00000001
  152. #define LEO_SS1_MISC_STEREO 0x00000002
  153. struct leo_ld_ss1 {
  154. u8 xxx0[0xef4];
  155. u32 ss1_misc;
  156. };
  157. struct leo_ld_gbl {
  158. u8 unknown;
  159. };
  160. struct leo_par {
  161. spinlock_t lock;
  162. struct leo_lx_krn __iomem *lx_krn;
  163. struct leo_lc_ss0_usr __iomem *lc_ss0_usr;
  164. struct leo_ld_ss0 __iomem *ld_ss0;
  165. struct leo_ld_ss1 __iomem *ld_ss1;
  166. struct leo_cursor __iomem *cursor;
  167. u32 extent;
  168. u32 clut_data[256];
  169. u32 flags;
  170. #define LEO_FLAG_BLANKED 0x00000001
  171. unsigned long physbase;
  172. unsigned long which_io;
  173. unsigned long fbsize;
  174. };
  175. static void leo_wait(struct leo_lx_krn __iomem *lx_krn)
  176. {
  177. int i;
  178. for (i = 0;
  179. (sbus_readl(&lx_krn->krn_csr) & LEO_KRN_CSR_PROGRESS) && i < 300000;
  180. i++)
  181. udelay (1); /* Busy wait at most 0.3 sec */
  182. return;
  183. }
  184. /**
  185. * leo_setcolreg - Optional function. Sets a color register.
  186. * @regno: boolean, 0 copy local, 1 get_user() function
  187. * @red: frame buffer colormap structure
  188. * @green: The green value which can be up to 16 bits wide
  189. * @blue: The blue value which can be up to 16 bits wide.
  190. * @transp: If supported the alpha value which can be up to 16 bits wide.
  191. * @info: frame buffer info structure
  192. */
  193. static int leo_setcolreg(unsigned regno,
  194. unsigned red, unsigned green, unsigned blue,
  195. unsigned transp, struct fb_info *info)
  196. {
  197. struct leo_par *par = (struct leo_par *) info->par;
  198. struct leo_lx_krn __iomem *lx_krn = par->lx_krn;
  199. unsigned long flags;
  200. u32 val;
  201. int i;
  202. if (regno >= 256)
  203. return 1;
  204. red >>= 8;
  205. green >>= 8;
  206. blue >>= 8;
  207. par->clut_data[regno] = red | (green << 8) | (blue << 16);
  208. spin_lock_irqsave(&par->lock, flags);
  209. leo_wait(lx_krn);
  210. sbus_writel(LEO_KRN_TYPE_CLUTDATA, &lx_krn->krn_type);
  211. for (i = 0; i < 256; i++)
  212. sbus_writel(par->clut_data[i], &lx_krn->krn_value);
  213. sbus_writel(LEO_KRN_TYPE_CLUT0, &lx_krn->krn_type);
  214. val = sbus_readl(&lx_krn->krn_csr);
  215. val |= (LEO_KRN_CSR_UNK | LEO_KRN_CSR_UNK2);
  216. sbus_writel(val, &lx_krn->krn_csr);
  217. spin_unlock_irqrestore(&par->lock, flags);
  218. return 0;
  219. }
  220. /**
  221. * leo_blank - Optional function. Blanks the display.
  222. * @blank_mode: the blank mode we want.
  223. * @info: frame buffer structure that represents a single frame buffer
  224. */
  225. static int leo_blank(int blank, struct fb_info *info)
  226. {
  227. struct leo_par *par = (struct leo_par *) info->par;
  228. struct leo_lx_krn __iomem *lx_krn = par->lx_krn;
  229. unsigned long flags;
  230. u32 val;
  231. spin_lock_irqsave(&par->lock, flags);
  232. switch (blank) {
  233. case FB_BLANK_UNBLANK: /* Unblanking */
  234. val = sbus_readl(&lx_krn->krn_csr);
  235. val |= LEO_KRN_CSR_ENABLE;
  236. sbus_writel(val, &lx_krn->krn_csr);
  237. par->flags &= ~LEO_FLAG_BLANKED;
  238. break;
  239. case FB_BLANK_NORMAL: /* Normal blanking */
  240. case FB_BLANK_VSYNC_SUSPEND: /* VESA blank (vsync off) */
  241. case FB_BLANK_HSYNC_SUSPEND: /* VESA blank (hsync off) */
  242. case FB_BLANK_POWERDOWN: /* Poweroff */
  243. val = sbus_readl(&lx_krn->krn_csr);
  244. val &= ~LEO_KRN_CSR_ENABLE;
  245. sbus_writel(val, &lx_krn->krn_csr);
  246. par->flags |= LEO_FLAG_BLANKED;
  247. break;
  248. }
  249. spin_unlock_irqrestore(&par->lock, flags);
  250. return 0;
  251. }
  252. static struct sbus_mmap_map leo_mmap_map[] = {
  253. {
  254. .voff = LEO_SS0_MAP,
  255. .poff = LEO_OFF_SS0,
  256. .size = 0x800000
  257. },
  258. {
  259. .voff = LEO_LC_SS0_USR_MAP,
  260. .poff = LEO_OFF_LC_SS0_USR,
  261. .size = 0x1000
  262. },
  263. {
  264. .voff = LEO_LD_SS0_MAP,
  265. .poff = LEO_OFF_LD_SS0,
  266. .size = 0x1000
  267. },
  268. {
  269. .voff = LEO_LX_CURSOR_MAP,
  270. .poff = LEO_OFF_LX_CURSOR,
  271. .size = 0x1000
  272. },
  273. {
  274. .voff = LEO_SS1_MAP,
  275. .poff = LEO_OFF_SS1,
  276. .size = 0x800000
  277. },
  278. {
  279. .voff = LEO_LC_SS1_USR_MAP,
  280. .poff = LEO_OFF_LC_SS1_USR,
  281. .size = 0x1000
  282. },
  283. {
  284. .voff = LEO_LD_SS1_MAP,
  285. .poff = LEO_OFF_LD_SS1,
  286. .size = 0x1000
  287. },
  288. {
  289. .voff = LEO_UNK_MAP,
  290. .poff = LEO_OFF_UNK,
  291. .size = 0x1000
  292. },
  293. {
  294. .voff = LEO_LX_KRN_MAP,
  295. .poff = LEO_OFF_LX_KRN,
  296. .size = 0x1000
  297. },
  298. {
  299. .voff = LEO_LC_SS0_KRN_MAP,
  300. .poff = LEO_OFF_LC_SS0_KRN,
  301. .size = 0x1000
  302. },
  303. {
  304. .voff = LEO_LC_SS1_KRN_MAP,
  305. .poff = LEO_OFF_LC_SS1_KRN,
  306. .size = 0x1000
  307. },
  308. {
  309. .voff = LEO_LD_GBL_MAP,
  310. .poff = LEO_OFF_LD_GBL,
  311. .size = 0x1000
  312. },
  313. {
  314. .voff = LEO_UNK2_MAP,
  315. .poff = LEO_OFF_UNK2,
  316. .size = 0x100000
  317. },
  318. { .size = 0 }
  319. };
  320. static int leo_mmap(struct fb_info *info, struct vm_area_struct *vma)
  321. {
  322. struct leo_par *par = (struct leo_par *)info->par;
  323. return sbusfb_mmap_helper(leo_mmap_map,
  324. par->physbase, par->fbsize,
  325. par->which_io, vma);
  326. }
  327. static int leo_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
  328. {
  329. struct leo_par *par = (struct leo_par *) info->par;
  330. return sbusfb_ioctl_helper(cmd, arg, info,
  331. FBTYPE_SUNLEO, 32, par->fbsize);
  332. }
  333. /*
  334. * Initialisation
  335. */
  336. static void
  337. leo_init_fix(struct fb_info *info, struct device_node *dp)
  338. {
  339. strlcpy(info->fix.id, dp->name, sizeof(info->fix.id));
  340. info->fix.type = FB_TYPE_PACKED_PIXELS;
  341. info->fix.visual = FB_VISUAL_TRUECOLOR;
  342. info->fix.line_length = 8192;
  343. info->fix.accel = FB_ACCEL_SUN_LEO;
  344. }
  345. static void leo_wid_put(struct fb_info *info, struct fb_wid_list *wl)
  346. {
  347. struct leo_par *par = (struct leo_par *) info->par;
  348. struct leo_lx_krn __iomem *lx_krn = par->lx_krn;
  349. struct fb_wid_item *wi;
  350. unsigned long flags;
  351. u32 val;
  352. int i, j;
  353. spin_lock_irqsave(&par->lock, flags);
  354. leo_wait(lx_krn);
  355. for (i = 0, wi = wl->wl_list; i < wl->wl_count; i++, wi++) {
  356. switch(wi->wi_type) {
  357. case FB_WID_DBL_8:
  358. j = (wi->wi_index & 0xf) + 0x40;
  359. break;
  360. case FB_WID_DBL_24:
  361. j = wi->wi_index & 0x3f;
  362. break;
  363. default:
  364. continue;
  365. };
  366. sbus_writel(0x5800 + j, &lx_krn->krn_type);
  367. sbus_writel(wi->wi_values[0], &lx_krn->krn_value);
  368. }
  369. sbus_writel(LEO_KRN_TYPE_WID, &lx_krn->krn_type);
  370. val = sbus_readl(&lx_krn->krn_csr);
  371. val |= (LEO_KRN_CSR_UNK | LEO_KRN_CSR_UNK2);
  372. sbus_writel(val, &lx_krn->krn_csr);
  373. spin_unlock_irqrestore(&par->lock, flags);
  374. }
  375. static void leo_init_wids(struct fb_info *info)
  376. {
  377. struct fb_wid_item wi;
  378. struct fb_wid_list wl;
  379. wl.wl_count = 1;
  380. wl.wl_list = &wi;
  381. wi.wi_type = FB_WID_DBL_8;
  382. wi.wi_index = 0;
  383. wi.wi_values [0] = 0x2c0;
  384. leo_wid_put(info, &wl);
  385. wi.wi_index = 1;
  386. wi.wi_values [0] = 0x30;
  387. leo_wid_put(info, &wl);
  388. wi.wi_index = 2;
  389. wi.wi_values [0] = 0x20;
  390. leo_wid_put(info, &wl);
  391. wi.wi_type = FB_WID_DBL_24;
  392. wi.wi_index = 1;
  393. wi.wi_values [0] = 0x30;
  394. leo_wid_put(info, &wl);
  395. }
  396. static void leo_switch_from_graph(struct fb_info *info)
  397. {
  398. struct leo_par *par = (struct leo_par *) info->par;
  399. struct leo_ld __iomem *ss = (struct leo_ld __iomem *) par->ld_ss0;
  400. unsigned long flags;
  401. u32 val;
  402. spin_lock_irqsave(&par->lock, flags);
  403. par->extent = ((info->var.xres - 1) |
  404. ((info->var.yres - 1) << 16));
  405. sbus_writel(0xffffffff, &ss->wid);
  406. sbus_writel(0xffff, &ss->wmask);
  407. sbus_writel(0, &ss->vclipmin);
  408. sbus_writel(par->extent, &ss->vclipmax);
  409. sbus_writel(0, &ss->fg);
  410. sbus_writel(0xff000000, &ss->planemask);
  411. sbus_writel(0x310850, &ss->rop);
  412. sbus_writel(0, &ss->widclip);
  413. sbus_writel((info->var.xres-1) | ((info->var.yres-1) << 11),
  414. &par->lc_ss0_usr->extent);
  415. sbus_writel(4, &par->lc_ss0_usr->addrspace);
  416. sbus_writel(0x80000000, &par->lc_ss0_usr->fill);
  417. sbus_writel(0, &par->lc_ss0_usr->fontt);
  418. do {
  419. val = sbus_readl(&par->lc_ss0_usr->csr);
  420. } while (val & 0x20000000);
  421. spin_unlock_irqrestore(&par->lock, flags);
  422. }
  423. static int leo_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
  424. {
  425. /* We just use this to catch switches out of
  426. * graphics mode.
  427. */
  428. leo_switch_from_graph(info);
  429. if (var->xoffset || var->yoffset || var->vmode)
  430. return -EINVAL;
  431. return 0;
  432. }
  433. static void leo_init_hw(struct fb_info *info)
  434. {
  435. struct leo_par *par = (struct leo_par *) info->par;
  436. u32 val;
  437. val = sbus_readl(&par->ld_ss1->ss1_misc);
  438. val |= LEO_SS1_MISC_ENABLE;
  439. sbus_writel(val, &par->ld_ss1->ss1_misc);
  440. leo_switch_from_graph(info);
  441. }
  442. static void leo_fixup_var_rgb(struct fb_var_screeninfo *var)
  443. {
  444. var->red.offset = 0;
  445. var->red.length = 8;
  446. var->green.offset = 8;
  447. var->green.length = 8;
  448. var->blue.offset = 16;
  449. var->blue.length = 8;
  450. var->transp.offset = 0;
  451. var->transp.length = 0;
  452. }
  453. struct all_info {
  454. struct fb_info info;
  455. struct leo_par par;
  456. };
  457. static void leo_unmap_regs(struct of_device *op, struct all_info *all)
  458. {
  459. if (all->par.lc_ss0_usr)
  460. of_iounmap(&op->resource[0], all->par.lc_ss0_usr, 0x1000);
  461. if (all->par.ld_ss0)
  462. of_iounmap(&op->resource[0], all->par.ld_ss0, 0x1000);
  463. if (all->par.ld_ss1)
  464. of_iounmap(&op->resource[0], all->par.ld_ss1, 0x1000);
  465. if (all->par.lx_krn)
  466. of_iounmap(&op->resource[0], all->par.lx_krn, 0x1000);
  467. if (all->par.cursor)
  468. of_iounmap(&op->resource[0],
  469. all->par.cursor, sizeof(struct leo_cursor));
  470. if (all->info.screen_base)
  471. of_iounmap(&op->resource[0], all->info.screen_base, 0x800000);
  472. }
  473. static int __devinit leo_init_one(struct of_device *op)
  474. {
  475. struct device_node *dp = op->node;
  476. struct all_info *all;
  477. int linebytes, err;
  478. all = kzalloc(sizeof(*all), GFP_KERNEL);
  479. if (!all)
  480. return -ENOMEM;
  481. spin_lock_init(&all->par.lock);
  482. all->par.physbase = op->resource[0].start;
  483. all->par.which_io = op->resource[0].flags & IORESOURCE_BITS;
  484. sbusfb_fill_var(&all->info.var, dp->node, 32);
  485. leo_fixup_var_rgb(&all->info.var);
  486. linebytes = of_getintprop_default(dp, "linebytes",
  487. all->info.var.xres);
  488. all->par.fbsize = PAGE_ALIGN(linebytes * all->info.var.yres);
  489. all->par.lc_ss0_usr =
  490. of_ioremap(&op->resource[0], LEO_OFF_LC_SS0_USR,
  491. 0x1000, "leolc ss0usr");
  492. all->par.ld_ss0 =
  493. of_ioremap(&op->resource[0], LEO_OFF_LD_SS0,
  494. 0x1000, "leold ss0");
  495. all->par.ld_ss1 =
  496. of_ioremap(&op->resource[0], LEO_OFF_LD_SS1,
  497. 0x1000, "leold ss1");
  498. all->par.lx_krn =
  499. of_ioremap(&op->resource[0], LEO_OFF_LX_KRN,
  500. 0x1000, "leolx krn");
  501. all->par.cursor =
  502. of_ioremap(&op->resource[0], LEO_OFF_LX_CURSOR,
  503. sizeof(struct leo_cursor), "leolx cursor");
  504. all->info.screen_base =
  505. of_ioremap(&op->resource[0], LEO_OFF_SS0,
  506. 0x800000, "leo ram");
  507. if (!all->par.lc_ss0_usr ||
  508. !all->par.ld_ss0 ||
  509. !all->par.ld_ss1 ||
  510. !all->par.lx_krn ||
  511. !all->par.cursor ||
  512. !all->info.screen_base) {
  513. leo_unmap_regs(op, all);
  514. kfree(all);
  515. return -ENOMEM;
  516. }
  517. all->info.flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN;
  518. all->info.fbops = &leo_ops;
  519. all->info.par = &all->par;
  520. leo_init_wids(&all->info);
  521. leo_init_hw(&all->info);
  522. leo_blank(0, &all->info);
  523. if (fb_alloc_cmap(&all->info.cmap, 256, 0)) {
  524. leo_unmap_regs(op, all);
  525. kfree(all);
  526. return -ENOMEM;;
  527. }
  528. leo_init_fix(&all->info, dp);
  529. err = register_framebuffer(&all->info);
  530. if (err < 0) {
  531. fb_dealloc_cmap(&all->info.cmap);
  532. leo_unmap_regs(op, all);
  533. kfree(all);
  534. return err;
  535. }
  536. dev_set_drvdata(&op->dev, all);
  537. printk("%s: leo at %lx:%lx\n",
  538. dp->full_name,
  539. all->par.which_io, all->par.physbase);
  540. return 0;
  541. }
  542. static int __devinit leo_probe(struct of_device *dev, const struct of_device_id *match)
  543. {
  544. struct of_device *op = to_of_device(&dev->dev);
  545. return leo_init_one(op);
  546. }
  547. static int __devexit leo_remove(struct of_device *op)
  548. {
  549. struct all_info *all = dev_get_drvdata(&op->dev);
  550. unregister_framebuffer(&all->info);
  551. fb_dealloc_cmap(&all->info.cmap);
  552. leo_unmap_regs(op, all);
  553. kfree(all);
  554. dev_set_drvdata(&op->dev, NULL);
  555. return 0;
  556. }
  557. static struct of_device_id leo_match[] = {
  558. {
  559. .name = "leo",
  560. },
  561. {},
  562. };
  563. MODULE_DEVICE_TABLE(of, leo_match);
  564. static struct of_platform_driver leo_driver = {
  565. .name = "leo",
  566. .match_table = leo_match,
  567. .probe = leo_probe,
  568. .remove = __devexit_p(leo_remove),
  569. };
  570. static int __init leo_init(void)
  571. {
  572. if (fb_get_options("leofb", NULL))
  573. return -ENODEV;
  574. return of_register_driver(&leo_driver, &of_bus_type);
  575. }
  576. static void __exit leo_exit(void)
  577. {
  578. of_unregister_driver(&leo_driver);
  579. }
  580. module_init(leo_init);
  581. module_exit(leo_exit);
  582. MODULE_DESCRIPTION("framebuffer driver for LEO chipsets");
  583. MODULE_AUTHOR("David S. Miller <davem@davemloft.net>");
  584. MODULE_VERSION("2.0");
  585. MODULE_LICENSE("GPL");