platinumfb.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699
  1. /*
  2. * platinumfb.c -- frame buffer device for the PowerMac 'platinum' display
  3. *
  4. * Copyright (C) 1998 Franz Sirl
  5. *
  6. * Frame buffer structure from:
  7. * drivers/video/controlfb.c -- frame buffer device for
  8. * Apple 'control' display chip.
  9. * Copyright (C) 1998 Dan Jacobowitz
  10. *
  11. * Hardware information from:
  12. * platinum.c: Console support for PowerMac "platinum" display adaptor.
  13. * Copyright (C) 1996 Paul Mackerras and Mark Abene
  14. *
  15. * This file is subject to the terms and conditions of the GNU General Public
  16. * License. See the file COPYING in the main directory of this archive for
  17. * more details.
  18. */
  19. #undef DEBUG
  20. #include <linux/module.h>
  21. #include <linux/kernel.h>
  22. #include <linux/errno.h>
  23. #include <linux/string.h>
  24. #include <linux/mm.h>
  25. #include <linux/vmalloc.h>
  26. #include <linux/delay.h>
  27. #include <linux/interrupt.h>
  28. #include <linux/fb.h>
  29. #include <linux/init.h>
  30. #include <linux/nvram.h>
  31. #include <linux/of.h>
  32. #include <linux/of_address.h>
  33. #include <linux/platform_device.h>
  34. #include "macmodes.h"
  35. #include "platinumfb.h"
  36. static int default_vmode = VMODE_NVRAM;
  37. static int default_cmode = CMODE_NVRAM;
  38. struct fb_info_platinum {
  39. struct fb_info *info;
  40. int vmode, cmode;
  41. int xres, yres;
  42. int vxres, vyres;
  43. int xoffset, yoffset;
  44. struct {
  45. __u8 red, green, blue;
  46. } palette[256];
  47. u32 pseudo_palette[16];
  48. volatile struct cmap_regs __iomem *cmap_regs;
  49. unsigned long cmap_regs_phys;
  50. volatile struct platinum_regs __iomem *platinum_regs;
  51. unsigned long platinum_regs_phys;
  52. __u8 __iomem *frame_buffer;
  53. volatile __u8 __iomem *base_frame_buffer;
  54. unsigned long frame_buffer_phys;
  55. unsigned long total_vram;
  56. int clktype;
  57. int dactype;
  58. struct resource rsrc_fb, rsrc_reg;
  59. };
  60. /*
  61. * Frame buffer device API
  62. */
  63. static int platinumfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
  64. u_int transp, struct fb_info *info);
  65. static int platinumfb_blank(int blank_mode, struct fb_info *info);
  66. static int platinumfb_set_par (struct fb_info *info);
  67. static int platinumfb_check_var (struct fb_var_screeninfo *var, struct fb_info *info);
  68. /*
  69. * internal functions
  70. */
  71. static inline int platinum_vram_reqd(int video_mode, int color_mode);
  72. static int read_platinum_sense(struct fb_info_platinum *pinfo);
  73. static void set_platinum_clock(struct fb_info_platinum *pinfo);
  74. static void platinum_set_hardware(struct fb_info_platinum *pinfo);
  75. static int platinum_var_to_par(struct fb_var_screeninfo *var,
  76. struct fb_info_platinum *pinfo,
  77. int check_only);
  78. /*
  79. * Interface used by the world
  80. */
  81. static const struct fb_ops platinumfb_ops = {
  82. .owner = THIS_MODULE,
  83. FB_DEFAULT_IOMEM_OPS,
  84. .fb_check_var = platinumfb_check_var,
  85. .fb_set_par = platinumfb_set_par,
  86. .fb_setcolreg = platinumfb_setcolreg,
  87. .fb_blank = platinumfb_blank,
  88. };
  89. /*
  90. * Checks a var structure
  91. */
  92. static int platinumfb_check_var (struct fb_var_screeninfo *var, struct fb_info *info)
  93. {
  94. return platinum_var_to_par(var, info->par, 1);
  95. }
  96. /*
  97. * Applies current var to display
  98. */
  99. static int platinumfb_set_par (struct fb_info *info)
  100. {
  101. struct fb_info_platinum *pinfo = info->par;
  102. struct platinum_regvals *init;
  103. int err, offset = 0x20;
  104. if((err = platinum_var_to_par(&info->var, pinfo, 0))) {
  105. printk (KERN_ERR "platinumfb_set_par: error calling"
  106. " platinum_var_to_par: %d.\n", err);
  107. return err;
  108. }
  109. platinum_set_hardware(pinfo);
  110. init = platinum_reg_init[pinfo->vmode-1];
  111. if ((pinfo->vmode == VMODE_832_624_75) && (pinfo->cmode > CMODE_8))
  112. offset = 0x10;
  113. info->screen_base = pinfo->frame_buffer + init->fb_offset + offset;
  114. mutex_lock(&info->mm_lock);
  115. info->fix.smem_start = (pinfo->frame_buffer_phys) + init->fb_offset + offset;
  116. mutex_unlock(&info->mm_lock);
  117. info->fix.visual = (pinfo->cmode == CMODE_8) ?
  118. FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_DIRECTCOLOR;
  119. info->fix.line_length = vmode_attrs[pinfo->vmode-1].hres * (1<<pinfo->cmode)
  120. + offset;
  121. printk("line_length: %x\n", info->fix.line_length);
  122. return 0;
  123. }
  124. static int platinumfb_blank(int blank, struct fb_info *fb)
  125. {
  126. /*
  127. * Blank the screen if blank_mode != 0, else unblank. If blank == NULL
  128. * then the caller blanks by setting the CLUT (Color Look Up Table) to all
  129. * black. Return 0 if blanking succeeded, != 0 if un-/blanking failed due
  130. * to e.g. a video mode which doesn't support it. Implements VESA suspend
  131. * and powerdown modes on hardware that supports disabling hsync/vsync:
  132. * blank_mode == 2: suspend vsync
  133. * blank_mode == 3: suspend hsync
  134. * blank_mode == 4: powerdown
  135. */
  136. /* [danj] I think there's something fishy about those constants... */
  137. /*
  138. struct fb_info_platinum *info = (struct fb_info_platinum *) fb;
  139. int ctrl;
  140. ctrl = le32_to_cpup(&info->platinum_regs->ctrl.r) | 0x33;
  141. if (blank)
  142. --blank_mode;
  143. if (blank & VESA_VSYNC_SUSPEND)
  144. ctrl &= ~3;
  145. if (blank & VESA_HSYNC_SUSPEND)
  146. ctrl &= ~0x30;
  147. out_le32(&info->platinum_regs->ctrl.r, ctrl);
  148. */
  149. /* TODO: Figure out how the heck to powerdown this thing! */
  150. return 0;
  151. }
  152. static int platinumfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
  153. u_int transp, struct fb_info *info)
  154. {
  155. struct fb_info_platinum *pinfo = info->par;
  156. volatile struct cmap_regs __iomem *cmap_regs = pinfo->cmap_regs;
  157. if (regno > 255)
  158. return 1;
  159. red >>= 8;
  160. green >>= 8;
  161. blue >>= 8;
  162. pinfo->palette[regno].red = red;
  163. pinfo->palette[regno].green = green;
  164. pinfo->palette[regno].blue = blue;
  165. out_8(&cmap_regs->addr, regno); /* tell clut what addr to fill */
  166. out_8(&cmap_regs->lut, red); /* send one color channel at */
  167. out_8(&cmap_regs->lut, green); /* a time... */
  168. out_8(&cmap_regs->lut, blue);
  169. if (regno < 16) {
  170. int i;
  171. u32 *pal = info->pseudo_palette;
  172. switch (pinfo->cmode) {
  173. case CMODE_16:
  174. pal[regno] = (regno << 10) | (regno << 5) | regno;
  175. break;
  176. case CMODE_32:
  177. i = (regno << 8) | regno;
  178. pal[regno] = (i << 16) | i;
  179. break;
  180. }
  181. }
  182. return 0;
  183. }
  184. static inline int platinum_vram_reqd(int video_mode, int color_mode)
  185. {
  186. int baseval = vmode_attrs[video_mode-1].hres * (1<<color_mode);
  187. if ((video_mode == VMODE_832_624_75) && (color_mode > CMODE_8))
  188. baseval += 0x10;
  189. else
  190. baseval += 0x20;
  191. return vmode_attrs[video_mode-1].vres * baseval + 0x1000;
  192. }
  193. #define STORE_D2(a, d) { \
  194. out_8(&cmap_regs->addr, (a+32)); \
  195. out_8(&cmap_regs->d2, (d)); \
  196. }
  197. static void set_platinum_clock(struct fb_info_platinum *pinfo)
  198. {
  199. volatile struct cmap_regs __iomem *cmap_regs = pinfo->cmap_regs;
  200. struct platinum_regvals *init;
  201. init = platinum_reg_init[pinfo->vmode-1];
  202. STORE_D2(6, 0xc6);
  203. out_8(&cmap_regs->addr,3+32);
  204. if (in_8(&cmap_regs->d2) == 2) {
  205. STORE_D2(7, init->clock_params[pinfo->clktype][0]);
  206. STORE_D2(8, init->clock_params[pinfo->clktype][1]);
  207. STORE_D2(3, 3);
  208. } else {
  209. STORE_D2(4, init->clock_params[pinfo->clktype][0]);
  210. STORE_D2(5, init->clock_params[pinfo->clktype][1]);
  211. STORE_D2(3, 2);
  212. }
  213. __delay(5000);
  214. STORE_D2(9, 0xa6);
  215. }
  216. /* Now how about actually saying, Make it so! */
  217. /* Some things in here probably don't need to be done each time. */
  218. static void platinum_set_hardware(struct fb_info_platinum *pinfo)
  219. {
  220. volatile struct platinum_regs __iomem *platinum_regs = pinfo->platinum_regs;
  221. volatile struct cmap_regs __iomem *cmap_regs = pinfo->cmap_regs;
  222. struct platinum_regvals *init;
  223. int i;
  224. int vmode, cmode;
  225. vmode = pinfo->vmode;
  226. cmode = pinfo->cmode;
  227. init = platinum_reg_init[vmode - 1];
  228. /* Initialize display timing registers */
  229. out_be32(&platinum_regs->reg[24].r, 7); /* turn display off */
  230. for (i = 0; i < 26; ++i)
  231. out_be32(&platinum_regs->reg[i+32].r, init->regs[i]);
  232. out_be32(&platinum_regs->reg[26+32].r, (pinfo->total_vram == 0x100000 ?
  233. init->offset[cmode] + 4 - cmode :
  234. init->offset[cmode]));
  235. out_be32(&platinum_regs->reg[16].r, (unsigned) pinfo->frame_buffer_phys+init->fb_offset+0x10);
  236. out_be32(&platinum_regs->reg[18].r, init->pitch[cmode]);
  237. out_be32(&platinum_regs->reg[19].r, (pinfo->total_vram == 0x100000 ?
  238. init->mode[cmode+1] :
  239. init->mode[cmode]));
  240. out_be32(&platinum_regs->reg[20].r, (pinfo->total_vram == 0x100000 ? 0x11 : 0x1011));
  241. out_be32(&platinum_regs->reg[21].r, 0x100);
  242. out_be32(&platinum_regs->reg[22].r, 1);
  243. out_be32(&platinum_regs->reg[23].r, 1);
  244. out_be32(&platinum_regs->reg[26].r, 0xc00);
  245. out_be32(&platinum_regs->reg[27].r, 0x235);
  246. /* out_be32(&platinum_regs->reg[27].r, 0x2aa); */
  247. STORE_D2(0, (pinfo->total_vram == 0x100000 ?
  248. init->dacula_ctrl[cmode] & 0xf :
  249. init->dacula_ctrl[cmode]));
  250. STORE_D2(1, 4);
  251. STORE_D2(2, 0);
  252. set_platinum_clock(pinfo);
  253. out_be32(&platinum_regs->reg[24].r, 0); /* turn display on */
  254. }
  255. /*
  256. * Set misc info vars for this driver
  257. */
  258. static void platinum_init_info(struct fb_info *info,
  259. struct fb_info_platinum *pinfo)
  260. {
  261. /* Fill fb_info */
  262. info->fbops = &platinumfb_ops;
  263. info->pseudo_palette = pinfo->pseudo_palette;
  264. info->screen_base = pinfo->frame_buffer + 0x20;
  265. fb_alloc_cmap(&info->cmap, 256, 0);
  266. /* Fill fix common fields */
  267. strcpy(info->fix.id, "platinum");
  268. info->fix.mmio_start = pinfo->platinum_regs_phys;
  269. info->fix.mmio_len = 0x1000;
  270. info->fix.type = FB_TYPE_PACKED_PIXELS;
  271. info->fix.smem_start = pinfo->frame_buffer_phys + 0x20; /* will be updated later */
  272. info->fix.smem_len = pinfo->total_vram - 0x20;
  273. info->fix.ywrapstep = 0;
  274. info->fix.xpanstep = 0;
  275. info->fix.ypanstep = 0;
  276. info->fix.type_aux = 0;
  277. info->fix.accel = FB_ACCEL_NONE;
  278. }
  279. static int platinum_init_fb(struct fb_info *info)
  280. {
  281. struct fb_info_platinum *pinfo = info->par;
  282. struct fb_var_screeninfo var;
  283. int sense, rc;
  284. sense = read_platinum_sense(pinfo);
  285. printk(KERN_INFO "platinumfb: Monitor sense value = 0x%x, ", sense);
  286. if (IS_REACHABLE(CONFIG_NVRAM) && default_vmode == VMODE_NVRAM)
  287. default_vmode = nvram_read_byte(NV_VMODE);
  288. if (default_vmode <= 0 || default_vmode > VMODE_MAX ||
  289. !platinum_reg_init[default_vmode - 1]) {
  290. default_vmode = mac_map_monitor_sense(sense);
  291. if (!platinum_reg_init[default_vmode - 1])
  292. default_vmode = VMODE_640_480_60;
  293. }
  294. if (IS_REACHABLE(CONFIG_NVRAM) && default_cmode == CMODE_NVRAM)
  295. default_cmode = nvram_read_byte(NV_CMODE);
  296. if (default_cmode < CMODE_8 || default_cmode > CMODE_32)
  297. default_cmode = CMODE_8;
  298. /*
  299. * Reduce the pixel size if we don't have enough VRAM.
  300. */
  301. while(default_cmode > CMODE_8 &&
  302. platinum_vram_reqd(default_vmode, default_cmode) > pinfo->total_vram)
  303. default_cmode--;
  304. printk("platinumfb: Using video mode %d and color mode %d.\n", default_vmode, default_cmode);
  305. /* Setup default var */
  306. if (mac_vmode_to_var(default_vmode, default_cmode, &var) < 0) {
  307. /* This shouldn't happen! */
  308. printk("mac_vmode_to_var(%d, %d,) failed\n", default_vmode, default_cmode);
  309. try_again:
  310. default_vmode = VMODE_640_480_60;
  311. default_cmode = CMODE_8;
  312. if (mac_vmode_to_var(default_vmode, default_cmode, &var) < 0) {
  313. printk(KERN_ERR "platinumfb: mac_vmode_to_var() failed\n");
  314. return -ENXIO;
  315. }
  316. }
  317. /* Initialize info structure */
  318. platinum_init_info(info, pinfo);
  319. /* Apply default var */
  320. info->var = var;
  321. var.activate = FB_ACTIVATE_NOW;
  322. rc = fb_set_var(info, &var);
  323. if (rc && (default_vmode != VMODE_640_480_60 || default_cmode != CMODE_8))
  324. goto try_again;
  325. /* Register with fbdev layer */
  326. rc = register_framebuffer(info);
  327. if (rc < 0)
  328. return rc;
  329. fb_info(info, "Apple Platinum frame buffer device\n");
  330. return 0;
  331. }
  332. /*
  333. * Get the monitor sense value.
  334. * Note that this can be called before calibrate_delay,
  335. * so we can't use udelay.
  336. */
  337. static int read_platinum_sense(struct fb_info_platinum *info)
  338. {
  339. volatile struct platinum_regs __iomem *platinum_regs = info->platinum_regs;
  340. int sense;
  341. out_be32(&platinum_regs->reg[23].r, 7); /* turn off drivers */
  342. __delay(2000);
  343. sense = (~in_be32(&platinum_regs->reg[23].r) & 7) << 8;
  344. /* drive each sense line low in turn and collect the other 2 */
  345. out_be32(&platinum_regs->reg[23].r, 3); /* drive A low */
  346. __delay(2000);
  347. sense |= (~in_be32(&platinum_regs->reg[23].r) & 3) << 4;
  348. out_be32(&platinum_regs->reg[23].r, 5); /* drive B low */
  349. __delay(2000);
  350. sense |= (~in_be32(&platinum_regs->reg[23].r) & 4) << 1;
  351. sense |= (~in_be32(&platinum_regs->reg[23].r) & 1) << 2;
  352. out_be32(&platinum_regs->reg[23].r, 6); /* drive C low */
  353. __delay(2000);
  354. sense |= (~in_be32(&platinum_regs->reg[23].r) & 6) >> 1;
  355. out_be32(&platinum_regs->reg[23].r, 7); /* turn off drivers */
  356. return sense;
  357. }
  358. /*
  359. * This routine takes a user-supplied var, and picks the best vmode/cmode from it.
  360. * It also updates the var structure to the actual mode data obtained
  361. */
  362. static int platinum_var_to_par(struct fb_var_screeninfo *var,
  363. struct fb_info_platinum *pinfo,
  364. int check_only)
  365. {
  366. int vmode, cmode;
  367. if (mac_var_to_vmode(var, &vmode, &cmode) != 0) {
  368. printk(KERN_ERR "platinum_var_to_par: mac_var_to_vmode unsuccessful.\n");
  369. printk(KERN_ERR "platinum_var_to_par: var->xres = %d\n", var->xres);
  370. printk(KERN_ERR "platinum_var_to_par: var->yres = %d\n", var->yres);
  371. printk(KERN_ERR "platinum_var_to_par: var->xres_virtual = %d\n", var->xres_virtual);
  372. printk(KERN_ERR "platinum_var_to_par: var->yres_virtual = %d\n", var->yres_virtual);
  373. printk(KERN_ERR "platinum_var_to_par: var->bits_per_pixel = %d\n", var->bits_per_pixel);
  374. printk(KERN_ERR "platinum_var_to_par: var->pixclock = %d\n", var->pixclock);
  375. printk(KERN_ERR "platinum_var_to_par: var->vmode = %d\n", var->vmode);
  376. return -EINVAL;
  377. }
  378. if (!platinum_reg_init[vmode-1]) {
  379. printk(KERN_ERR "platinum_var_to_par, vmode %d not valid.\n", vmode);
  380. return -EINVAL;
  381. }
  382. if (platinum_vram_reqd(vmode, cmode) > pinfo->total_vram) {
  383. printk(KERN_ERR "platinum_var_to_par, not enough ram for vmode %d, cmode %d.\n", vmode, cmode);
  384. return -EINVAL;
  385. }
  386. if (mac_vmode_to_var(vmode, cmode, var))
  387. return -EINVAL;
  388. if (check_only)
  389. return 0;
  390. pinfo->vmode = vmode;
  391. pinfo->cmode = cmode;
  392. pinfo->xres = vmode_attrs[vmode-1].hres;
  393. pinfo->yres = vmode_attrs[vmode-1].vres;
  394. pinfo->xoffset = 0;
  395. pinfo->yoffset = 0;
  396. pinfo->vxres = pinfo->xres;
  397. pinfo->vyres = pinfo->yres;
  398. return 0;
  399. }
  400. /*
  401. * Parse user specified options (`video=platinumfb:')
  402. */
  403. static int __init platinumfb_setup(char *options)
  404. {
  405. char *this_opt;
  406. if (!options || !*options)
  407. return 0;
  408. while ((this_opt = strsep(&options, ",")) != NULL) {
  409. if (!strncmp(this_opt, "vmode:", 6)) {
  410. int vmode = simple_strtoul(this_opt+6, NULL, 0);
  411. if (vmode > 0 && vmode <= VMODE_MAX)
  412. default_vmode = vmode;
  413. } else if (!strncmp(this_opt, "cmode:", 6)) {
  414. int depth = simple_strtoul(this_opt+6, NULL, 0);
  415. switch (depth) {
  416. case 0:
  417. case 8:
  418. default_cmode = CMODE_8;
  419. break;
  420. case 15:
  421. case 16:
  422. default_cmode = CMODE_16;
  423. break;
  424. case 24:
  425. case 32:
  426. default_cmode = CMODE_32;
  427. break;
  428. }
  429. }
  430. }
  431. return 0;
  432. }
  433. #ifdef __powerpc__
  434. #define invalidate_cache(addr) \
  435. asm volatile("eieio; dcbf 0,%1" \
  436. : "=m" (*(addr)) : "r" (addr) : "memory");
  437. #else
  438. #define invalidate_cache(addr)
  439. #endif
  440. static int platinumfb_probe(struct platform_device* odev)
  441. {
  442. struct device_node *dp = odev->dev.of_node;
  443. struct fb_info *info;
  444. struct fb_info_platinum *pinfo;
  445. volatile __u8 *fbuffer;
  446. int bank0, bank1, bank2, bank3, rc;
  447. dev_info(&odev->dev, "Found Apple Platinum video hardware\n");
  448. info = framebuffer_alloc(sizeof(*pinfo), &odev->dev);
  449. if (!info)
  450. return -ENOMEM;
  451. pinfo = info->par;
  452. if (of_address_to_resource(dp, 0, &pinfo->rsrc_reg) ||
  453. of_address_to_resource(dp, 1, &pinfo->rsrc_fb)) {
  454. dev_err(&odev->dev, "Can't get resources\n");
  455. framebuffer_release(info);
  456. return -ENXIO;
  457. }
  458. dev_dbg(&odev->dev, " registers : 0x%llx...0x%llx\n",
  459. (unsigned long long)pinfo->rsrc_reg.start,
  460. (unsigned long long)pinfo->rsrc_reg.end);
  461. dev_dbg(&odev->dev, " framebuffer: 0x%llx...0x%llx\n",
  462. (unsigned long long)pinfo->rsrc_fb.start,
  463. (unsigned long long)pinfo->rsrc_fb.end);
  464. /* Do not try to request register space, they overlap with the
  465. * northbridge and that can fail. Only request framebuffer
  466. */
  467. if (!request_mem_region(pinfo->rsrc_fb.start,
  468. resource_size(&pinfo->rsrc_fb),
  469. "platinumfb framebuffer")) {
  470. printk(KERN_ERR "platinumfb: Can't request framebuffer !\n");
  471. framebuffer_release(info);
  472. return -ENXIO;
  473. }
  474. /* frame buffer - map only 4MB */
  475. pinfo->frame_buffer_phys = pinfo->rsrc_fb.start;
  476. pinfo->frame_buffer = ioremap_wt(pinfo->rsrc_fb.start, 0x400000);
  477. pinfo->base_frame_buffer = pinfo->frame_buffer;
  478. /* registers */
  479. pinfo->platinum_regs_phys = pinfo->rsrc_reg.start;
  480. pinfo->platinum_regs = ioremap(pinfo->rsrc_reg.start, 0x1000);
  481. pinfo->cmap_regs_phys = 0xf301b000; /* XXX not in prom? */
  482. request_mem_region(pinfo->cmap_regs_phys, 0x1000, "platinumfb cmap");
  483. pinfo->cmap_regs = ioremap(pinfo->cmap_regs_phys, 0x1000);
  484. /* Grok total video ram */
  485. out_be32(&pinfo->platinum_regs->reg[16].r, (unsigned)pinfo->frame_buffer_phys);
  486. out_be32(&pinfo->platinum_regs->reg[20].r, 0x1011); /* select max vram */
  487. out_be32(&pinfo->platinum_regs->reg[24].r, 0); /* switch in vram */
  488. fbuffer = pinfo->base_frame_buffer;
  489. fbuffer[0x100000] = 0x34;
  490. fbuffer[0x100008] = 0x0;
  491. invalidate_cache(&fbuffer[0x100000]);
  492. fbuffer[0x200000] = 0x56;
  493. fbuffer[0x200008] = 0x0;
  494. invalidate_cache(&fbuffer[0x200000]);
  495. fbuffer[0x300000] = 0x78;
  496. fbuffer[0x300008] = 0x0;
  497. invalidate_cache(&fbuffer[0x300000]);
  498. bank0 = 1; /* builtin 1MB vram, always there */
  499. bank1 = fbuffer[0x100000] == 0x34;
  500. bank2 = fbuffer[0x200000] == 0x56;
  501. bank3 = fbuffer[0x300000] == 0x78;
  502. pinfo->total_vram = (bank0 + bank1 + bank2 + bank3) * 0x100000;
  503. printk(KERN_INFO "platinumfb: Total VRAM = %dMB (%d%d%d%d)\n",
  504. (unsigned int) (pinfo->total_vram / 1024 / 1024),
  505. bank3, bank2, bank1, bank0);
  506. /*
  507. * Try to determine whether we have an old or a new DACula.
  508. */
  509. out_8(&pinfo->cmap_regs->addr, 0x40);
  510. pinfo->dactype = in_8(&pinfo->cmap_regs->d2);
  511. switch (pinfo->dactype) {
  512. case 0x3c:
  513. pinfo->clktype = 1;
  514. printk(KERN_INFO "platinumfb: DACula type 0x3c\n");
  515. break;
  516. case 0x84:
  517. pinfo->clktype = 0;
  518. printk(KERN_INFO "platinumfb: DACula type 0x84\n");
  519. break;
  520. default:
  521. pinfo->clktype = 0;
  522. printk(KERN_INFO "platinumfb: Unknown DACula type: %x\n", pinfo->dactype);
  523. break;
  524. }
  525. dev_set_drvdata(&odev->dev, info);
  526. rc = platinum_init_fb(info);
  527. if (rc != 0) {
  528. iounmap(pinfo->frame_buffer);
  529. iounmap(pinfo->platinum_regs);
  530. iounmap(pinfo->cmap_regs);
  531. framebuffer_release(info);
  532. }
  533. return rc;
  534. }
  535. static void platinumfb_remove(struct platform_device* odev)
  536. {
  537. struct fb_info *info = dev_get_drvdata(&odev->dev);
  538. struct fb_info_platinum *pinfo = info->par;
  539. unregister_framebuffer (info);
  540. /* Unmap frame buffer and registers */
  541. iounmap(pinfo->frame_buffer);
  542. iounmap(pinfo->platinum_regs);
  543. iounmap(pinfo->cmap_regs);
  544. release_mem_region(pinfo->rsrc_fb.start,
  545. resource_size(&pinfo->rsrc_fb));
  546. release_mem_region(pinfo->cmap_regs_phys, 0x1000);
  547. framebuffer_release(info);
  548. }
  549. static struct of_device_id platinumfb_match[] =
  550. {
  551. {
  552. .name = "platinum",
  553. },
  554. {},
  555. };
  556. static struct platform_driver platinum_driver =
  557. {
  558. .driver = {
  559. .name = "platinumfb",
  560. .of_match_table = platinumfb_match,
  561. },
  562. .probe = platinumfb_probe,
  563. .remove = platinumfb_remove,
  564. };
  565. static int __init platinumfb_init(void)
  566. {
  567. #ifndef MODULE
  568. char *option = NULL;
  569. if (fb_get_options("platinumfb", &option))
  570. return -ENODEV;
  571. platinumfb_setup(option);
  572. #endif
  573. platform_driver_register(&platinum_driver);
  574. return 0;
  575. }
  576. static void __exit platinumfb_exit(void)
  577. {
  578. platform_driver_unregister(&platinum_driver);
  579. }
  580. MODULE_LICENSE("GPL");
  581. MODULE_DESCRIPTION("framebuffer driver for Apple Platinum video");
  582. module_init(platinumfb_init);
  583. #ifdef MODULE
  584. module_exit(platinumfb_exit);
  585. #endif