platinumfb.c 20 KB

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