platinumfb.c 20 KB

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