PageRenderTime 51ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/drivers/video/macfb.c

https://github.com/mstsirkin/linux
C | 934 lines | 633 code | 119 blank | 182 comment | 50 complexity | f38415924917471df320ef950221d542 MD5 | raw file
  1. /*
  2. * macfb.c: Generic framebuffer for Macs whose colourmaps/modes we
  3. * don't know how to set.
  4. *
  5. * (c) 1999 David Huggins-Daines <dhd@debian.org>
  6. *
  7. * Primarily based on vesafb.c, by Gerd Knorr
  8. * (c) 1998 Gerd Knorr <kraxel@cs.tu-berlin.de>
  9. *
  10. * Also uses information and code from:
  11. *
  12. * The original macfb.c from Linux/mac68k 2.0, by Alan Cox, Juergen
  13. * Mellinger, Mikael Forselius, Michael Schmitz, and others.
  14. *
  15. * valkyriefb.c, by Martin Costabel, Kevin Schoedel, Barry Nathan, Dan
  16. * Jacobowitz, Paul Mackerras, Fabio Riccardi, and Geert Uytterhoeven.
  17. *
  18. * The VideoToolbox "Bugs" web page at
  19. * http://rajsky.psych.nyu.edu/Tips/VideoBugs.html
  20. *
  21. * This code is free software. You may copy, modify, and distribute
  22. * it subject to the terms and conditions of the GNU General Public
  23. * License, version 2, or any later version, at your convenience.
  24. */
  25. #include <linux/module.h>
  26. #include <linux/kernel.h>
  27. #include <linux/errno.h>
  28. #include <linux/string.h>
  29. #include <linux/mm.h>
  30. #include <linux/delay.h>
  31. #include <linux/nubus.h>
  32. #include <linux/init.h>
  33. #include <linux/fb.h>
  34. #include <asm/setup.h>
  35. #include <asm/bootinfo.h>
  36. #include <asm/macintosh.h>
  37. #include <asm/io.h>
  38. /* Common DAC base address for the LC, RBV, Valkyrie, and IIvx */
  39. #define DAC_BASE 0x50f24000
  40. /* Some addresses for the DAFB */
  41. #define DAFB_BASE 0xf9800200
  42. /* Address for the built-in Civic framebuffer in Quadra AVs */
  43. #define CIVIC_BASE 0x50f30800
  44. /* GSC (Gray Scale Controller) base address */
  45. #define GSC_BASE 0x50F20000
  46. /* CSC (Color Screen Controller) base address */
  47. #define CSC_BASE 0x50F20000
  48. static int (*macfb_setpalette)(unsigned int regno, unsigned int red,
  49. unsigned int green, unsigned int blue,
  50. struct fb_info *info);
  51. static struct {
  52. unsigned char addr;
  53. unsigned char lut;
  54. } __iomem *v8_brazil_cmap_regs;
  55. static struct {
  56. unsigned char addr;
  57. char pad1[3]; /* word aligned */
  58. unsigned char lut;
  59. char pad2[3]; /* word aligned */
  60. unsigned char cntl; /* a guess as to purpose */
  61. } __iomem *rbv_cmap_regs;
  62. static struct {
  63. unsigned long reset;
  64. unsigned long pad1[3];
  65. unsigned char pad2[3];
  66. unsigned char lut;
  67. } __iomem *dafb_cmap_regs;
  68. static struct {
  69. unsigned char addr; /* OFFSET: 0x00 */
  70. unsigned char pad1[15];
  71. unsigned char lut; /* OFFSET: 0x10 */
  72. unsigned char pad2[15];
  73. unsigned char status; /* OFFSET: 0x20 */
  74. unsigned char pad3[7];
  75. unsigned long vbl_addr; /* OFFSET: 0x28 */
  76. unsigned int status2; /* OFFSET: 0x2C */
  77. } __iomem *civic_cmap_regs;
  78. static struct {
  79. char pad1[0x40];
  80. unsigned char clut_waddr; /* 0x40 */
  81. char pad2;
  82. unsigned char clut_data; /* 0x42 */
  83. char pad3[0x3];
  84. unsigned char clut_raddr; /* 0x46 */
  85. } __iomem *csc_cmap_regs;
  86. /* The registers in these structs are in NuBus slot space */
  87. struct mdc_cmap_regs {
  88. char pad1[0x200200];
  89. unsigned char addr;
  90. char pad2[6];
  91. unsigned char lut;
  92. };
  93. struct toby_cmap_regs {
  94. char pad1[0x90018];
  95. unsigned char lut; /* TFBClutWDataReg, offset 0x90018 */
  96. char pad2[3];
  97. unsigned char addr; /* TFBClutAddrReg, offset 0x9001C */
  98. };
  99. struct jet_cmap_regs {
  100. char pad1[0xe0e000];
  101. unsigned char addr;
  102. unsigned char lut;
  103. };
  104. #define PIXEL_TO_MM(a) (((a)*10)/28) /* width in mm at 72 dpi */
  105. static struct fb_var_screeninfo macfb_defined = {
  106. .bits_per_pixel = 8,
  107. .activate = FB_ACTIVATE_NOW,
  108. .width = -1,
  109. .height = -1,
  110. .right_margin = 32,
  111. .upper_margin = 16,
  112. .lower_margin = 4,
  113. .vsync_len = 4,
  114. .vmode = FB_VMODE_NONINTERLACED,
  115. };
  116. static struct fb_fix_screeninfo macfb_fix = {
  117. .type = FB_TYPE_PACKED_PIXELS,
  118. .accel = FB_ACCEL_NONE,
  119. };
  120. static void *slot_addr;
  121. static struct fb_info fb_info;
  122. static u32 pseudo_palette[16];
  123. static int inverse;
  124. static int vidtest;
  125. /*
  126. * Unlike the Valkyrie, the DAFB cannot set individual colormap
  127. * registers. Therefore, we do what the MacOS driver does (no
  128. * kidding!) and simply set them one by one until we hit the one we
  129. * want.
  130. */
  131. static int dafb_setpalette(unsigned int regno, unsigned int red,
  132. unsigned int green, unsigned int blue,
  133. struct fb_info *info)
  134. {
  135. static int lastreg = -1;
  136. unsigned long flags;
  137. local_irq_save(flags);
  138. /*
  139. * fbdev will set an entire colourmap, but X won't. Hopefully
  140. * this should accommodate both of them
  141. */
  142. if (regno != lastreg + 1) {
  143. int i;
  144. /* Stab in the dark trying to reset the CLUT pointer */
  145. nubus_writel(0, &dafb_cmap_regs->reset);
  146. nop();
  147. /* Loop until we get to the register we want */
  148. for (i = 0; i < regno; i++) {
  149. nubus_writeb(info->cmap.red[i] >> 8,
  150. &dafb_cmap_regs->lut);
  151. nop();
  152. nubus_writeb(info->cmap.green[i] >> 8,
  153. &dafb_cmap_regs->lut);
  154. nop();
  155. nubus_writeb(info->cmap.blue[i] >> 8,
  156. &dafb_cmap_regs->lut);
  157. nop();
  158. }
  159. }
  160. nubus_writeb(red, &dafb_cmap_regs->lut);
  161. nop();
  162. nubus_writeb(green, &dafb_cmap_regs->lut);
  163. nop();
  164. nubus_writeb(blue, &dafb_cmap_regs->lut);
  165. local_irq_restore(flags);
  166. lastreg = regno;
  167. return 0;
  168. }
  169. /* V8 and Brazil seem to use the same DAC. Sonora does as well. */
  170. static int v8_brazil_setpalette(unsigned int regno, unsigned int red,
  171. unsigned int green, unsigned int blue,
  172. struct fb_info *info)
  173. {
  174. unsigned int bpp = info->var.bits_per_pixel;
  175. unsigned long flags;
  176. if (bpp > 8)
  177. return 1; /* failsafe */
  178. local_irq_save(flags);
  179. /* On these chips, the CLUT register numbers are spread out
  180. * across the register space. Thus:
  181. * In 8bpp, all regnos are valid.
  182. * In 4bpp, the regnos are 0x0f, 0x1f, 0x2f, etc, etc
  183. * In 2bpp, the regnos are 0x3f, 0x7f, 0xbf, 0xff
  184. */
  185. regno = (regno << (8 - bpp)) | (0xFF >> bpp);
  186. nubus_writeb(regno, &v8_brazil_cmap_regs->addr);
  187. nop();
  188. /* send one color channel at a time */
  189. nubus_writeb(red, &v8_brazil_cmap_regs->lut);
  190. nop();
  191. nubus_writeb(green, &v8_brazil_cmap_regs->lut);
  192. nop();
  193. nubus_writeb(blue, &v8_brazil_cmap_regs->lut);
  194. local_irq_restore(flags);
  195. return 0;
  196. }
  197. /* RAM-Based Video */
  198. static int rbv_setpalette(unsigned int regno, unsigned int red,
  199. unsigned int green, unsigned int blue,
  200. struct fb_info *info)
  201. {
  202. unsigned long flags;
  203. if (info->var.bits_per_pixel > 8)
  204. return 1; /* failsafe */
  205. local_irq_save(flags);
  206. /* From the VideoToolbox driver. Seems to be saying that
  207. * regno #254 and #255 are the important ones for 1-bit color,
  208. * regno #252-255 are the important ones for 2-bit color, etc.
  209. */
  210. regno += 256 - (1 << info->var.bits_per_pixel);
  211. /* reset clut? (VideoToolbox sez "not necessary") */
  212. nubus_writeb(0xFF, &rbv_cmap_regs->cntl);
  213. nop();
  214. /* tell clut which address to use. */
  215. nubus_writeb(regno, &rbv_cmap_regs->addr);
  216. nop();
  217. /* send one color channel at a time. */
  218. nubus_writeb(red, &rbv_cmap_regs->lut);
  219. nop();
  220. nubus_writeb(green, &rbv_cmap_regs->lut);
  221. nop();
  222. nubus_writeb(blue, &rbv_cmap_regs->lut);
  223. local_irq_restore(flags);
  224. return 0;
  225. }
  226. /* Macintosh Display Card (8*24) */
  227. static int mdc_setpalette(unsigned int regno, unsigned int red,
  228. unsigned int green, unsigned int blue,
  229. struct fb_info *info)
  230. {
  231. struct mdc_cmap_regs *cmap_regs = slot_addr;
  232. unsigned long flags;
  233. local_irq_save(flags);
  234. /* the nop's are there to order writes. */
  235. nubus_writeb(regno, &cmap_regs->addr);
  236. nop();
  237. nubus_writeb(red, &cmap_regs->lut);
  238. nop();
  239. nubus_writeb(green, &cmap_regs->lut);
  240. nop();
  241. nubus_writeb(blue, &cmap_regs->lut);
  242. local_irq_restore(flags);
  243. return 0;
  244. }
  245. /* Toby frame buffer */
  246. static int toby_setpalette(unsigned int regno, unsigned int red,
  247. unsigned int green, unsigned int blue,
  248. struct fb_info *info)
  249. {
  250. struct toby_cmap_regs *cmap_regs = slot_addr;
  251. unsigned int bpp = info->var.bits_per_pixel;
  252. unsigned long flags;
  253. red = ~red;
  254. green = ~green;
  255. blue = ~blue;
  256. regno = (regno << (8 - bpp)) | (0xFF >> bpp);
  257. local_irq_save(flags);
  258. nubus_writeb(regno, &cmap_regs->addr);
  259. nop();
  260. nubus_writeb(red, &cmap_regs->lut);
  261. nop();
  262. nubus_writeb(green, &cmap_regs->lut);
  263. nop();
  264. nubus_writeb(blue, &cmap_regs->lut);
  265. local_irq_restore(flags);
  266. return 0;
  267. }
  268. /* Jet frame buffer */
  269. static int jet_setpalette(unsigned int regno, unsigned int red,
  270. unsigned int green, unsigned int blue,
  271. struct fb_info *info)
  272. {
  273. struct jet_cmap_regs *cmap_regs = slot_addr;
  274. unsigned long flags;
  275. local_irq_save(flags);
  276. nubus_writeb(regno, &cmap_regs->addr);
  277. nop();
  278. nubus_writeb(red, &cmap_regs->lut);
  279. nop();
  280. nubus_writeb(green, &cmap_regs->lut);
  281. nop();
  282. nubus_writeb(blue, &cmap_regs->lut);
  283. local_irq_restore(flags);
  284. return 0;
  285. }
  286. /*
  287. * Civic framebuffer -- Quadra AV built-in video. A chip
  288. * called Sebastian holds the actual color palettes, and
  289. * apparently, there are two different banks of 512K RAM
  290. * which can act as separate framebuffers for doing video
  291. * input and viewing the screen at the same time! The 840AV
  292. * Can add another 1MB RAM to give the two framebuffers
  293. * 1MB RAM apiece.
  294. */
  295. static int civic_setpalette(unsigned int regno, unsigned int red,
  296. unsigned int green, unsigned int blue,
  297. struct fb_info *info)
  298. {
  299. unsigned long flags;
  300. int clut_status;
  301. if (info->var.bits_per_pixel > 8)
  302. return 1; /* failsafe */
  303. local_irq_save(flags);
  304. /* Set the register address */
  305. nubus_writeb(regno, &civic_cmap_regs->addr);
  306. nop();
  307. /*
  308. * Grab a status word and do some checking;
  309. * Then finally write the clut!
  310. */
  311. clut_status = nubus_readb(&civic_cmap_regs->status2);
  312. if ((clut_status & 0x0008) == 0)
  313. {
  314. #if 0
  315. if ((clut_status & 0x000D) != 0)
  316. {
  317. nubus_writeb(0x00, &civic_cmap_regs->lut);
  318. nop();
  319. nubus_writeb(0x00, &civic_cmap_regs->lut);
  320. nop();
  321. }
  322. #endif
  323. nubus_writeb(red, &civic_cmap_regs->lut);
  324. nop();
  325. nubus_writeb(green, &civic_cmap_regs->lut);
  326. nop();
  327. nubus_writeb(blue, &civic_cmap_regs->lut);
  328. nop();
  329. nubus_writeb(0x00, &civic_cmap_regs->lut);
  330. }
  331. else
  332. {
  333. unsigned char junk;
  334. junk = nubus_readb(&civic_cmap_regs->lut);
  335. nop();
  336. junk = nubus_readb(&civic_cmap_regs->lut);
  337. nop();
  338. junk = nubus_readb(&civic_cmap_regs->lut);
  339. nop();
  340. junk = nubus_readb(&civic_cmap_regs->lut);
  341. nop();
  342. if ((clut_status & 0x000D) != 0)
  343. {
  344. nubus_writeb(0x00, &civic_cmap_regs->lut);
  345. nop();
  346. nubus_writeb(0x00, &civic_cmap_regs->lut);
  347. nop();
  348. }
  349. nubus_writeb(red, &civic_cmap_regs->lut);
  350. nop();
  351. nubus_writeb(green, &civic_cmap_regs->lut);
  352. nop();
  353. nubus_writeb(blue, &civic_cmap_regs->lut);
  354. nop();
  355. nubus_writeb(junk, &civic_cmap_regs->lut);
  356. }
  357. local_irq_restore(flags);
  358. return 0;
  359. }
  360. /*
  361. * The CSC is the framebuffer on the PowerBook 190 series
  362. * (and the 5300 too, but that's a PowerMac). This function
  363. * brought to you in part by the ECSC driver for MkLinux.
  364. */
  365. static int csc_setpalette(unsigned int regno, unsigned int red,
  366. unsigned int green, unsigned int blue,
  367. struct fb_info *info)
  368. {
  369. unsigned long flags;
  370. local_irq_save(flags);
  371. udelay(1); /* mklinux on PB 5300 waits for 260 ns */
  372. nubus_writeb(regno, &csc_cmap_regs->clut_waddr);
  373. nubus_writeb(red, &csc_cmap_regs->clut_data);
  374. nubus_writeb(green, &csc_cmap_regs->clut_data);
  375. nubus_writeb(blue, &csc_cmap_regs->clut_data);
  376. local_irq_restore(flags);
  377. return 0;
  378. }
  379. static int macfb_setcolreg(unsigned regno, unsigned red, unsigned green,
  380. unsigned blue, unsigned transp,
  381. struct fb_info *fb_info)
  382. {
  383. /*
  384. * Set a single color register. The values supplied are
  385. * already rounded down to the hardware's capabilities
  386. * (according to the entries in the `var' structure).
  387. * Return non-zero for invalid regno.
  388. */
  389. if (regno >= fb_info->cmap.len)
  390. return 1;
  391. if (fb_info->var.bits_per_pixel <= 8) {
  392. switch (fb_info->var.bits_per_pixel) {
  393. case 1:
  394. /* We shouldn't get here */
  395. break;
  396. case 2:
  397. case 4:
  398. case 8:
  399. if (macfb_setpalette)
  400. macfb_setpalette(regno, red >> 8, green >> 8,
  401. blue >> 8, fb_info);
  402. else
  403. return 1;
  404. break;
  405. }
  406. } else if (regno < 16) {
  407. switch (fb_info->var.bits_per_pixel) {
  408. case 16:
  409. if (fb_info->var.red.offset == 10) {
  410. /* 1:5:5:5 */
  411. ((u32*) (fb_info->pseudo_palette))[regno] =
  412. ((red & 0xf800) >> 1) |
  413. ((green & 0xf800) >> 6) |
  414. ((blue & 0xf800) >> 11) |
  415. ((transp != 0) << 15);
  416. } else {
  417. /* 0:5:6:5 */
  418. ((u32*) (fb_info->pseudo_palette))[regno] =
  419. ((red & 0xf800) >> 0) |
  420. ((green & 0xfc00) >> 5) |
  421. ((blue & 0xf800) >> 11);
  422. }
  423. break;
  424. /*
  425. * 24-bit colour almost doesn't exist on 68k Macs --
  426. * http://support.apple.com/kb/TA28634 (Old Article: 10992)
  427. */
  428. case 24:
  429. case 32:
  430. red >>= 8;
  431. green >>= 8;
  432. blue >>= 8;
  433. ((u32 *)(fb_info->pseudo_palette))[regno] =
  434. (red << fb_info->var.red.offset) |
  435. (green << fb_info->var.green.offset) |
  436. (blue << fb_info->var.blue.offset);
  437. break;
  438. }
  439. }
  440. return 0;
  441. }
  442. static struct fb_ops macfb_ops = {
  443. .owner = THIS_MODULE,
  444. .fb_setcolreg = macfb_setcolreg,
  445. .fb_fillrect = cfb_fillrect,
  446. .fb_copyarea = cfb_copyarea,
  447. .fb_imageblit = cfb_imageblit,
  448. };
  449. static void __init macfb_setup(char *options)
  450. {
  451. char *this_opt;
  452. if (!options || !*options)
  453. return;
  454. while ((this_opt = strsep(&options, ",")) != NULL) {
  455. if (!*this_opt)
  456. continue;
  457. if (!strcmp(this_opt, "inverse"))
  458. inverse = 1;
  459. else
  460. if (!strcmp(this_opt, "vidtest"))
  461. vidtest = 1; /* enable experimental CLUT code */
  462. }
  463. }
  464. static void __init iounmap_macfb(void)
  465. {
  466. if (dafb_cmap_regs)
  467. iounmap(dafb_cmap_regs);
  468. if (v8_brazil_cmap_regs)
  469. iounmap(v8_brazil_cmap_regs);
  470. if (rbv_cmap_regs)
  471. iounmap(rbv_cmap_regs);
  472. if (civic_cmap_regs)
  473. iounmap(civic_cmap_regs);
  474. if (csc_cmap_regs)
  475. iounmap(csc_cmap_regs);
  476. }
  477. static int __init macfb_init(void)
  478. {
  479. int video_cmap_len, video_is_nubus = 0;
  480. struct nubus_dev* ndev = NULL;
  481. char *option = NULL;
  482. int err;
  483. if (fb_get_options("macfb", &option))
  484. return -ENODEV;
  485. macfb_setup(option);
  486. if (!MACH_IS_MAC)
  487. return -ENODEV;
  488. if (mac_bi_data.id == MAC_MODEL_Q630 ||
  489. mac_bi_data.id == MAC_MODEL_P588)
  490. return -ENODEV; /* See valkyriefb.c */
  491. macfb_defined.xres = mac_bi_data.dimensions & 0xFFFF;
  492. macfb_defined.yres = mac_bi_data.dimensions >> 16;
  493. macfb_defined.bits_per_pixel = mac_bi_data.videodepth;
  494. macfb_fix.line_length = mac_bi_data.videorow;
  495. macfb_fix.smem_len = macfb_fix.line_length * macfb_defined.yres;
  496. /* Note: physical address (since 2.1.127) */
  497. macfb_fix.smem_start = mac_bi_data.videoaddr;
  498. /*
  499. * This is actually redundant with the initial mappings.
  500. * However, there are some non-obvious aspects to the way
  501. * those mappings are set up, so this is in fact the safest
  502. * way to ensure that this driver will work on every possible Mac
  503. */
  504. fb_info.screen_base = ioremap(mac_bi_data.videoaddr,
  505. macfb_fix.smem_len);
  506. if (!fb_info.screen_base)
  507. return -ENODEV;
  508. printk("macfb: framebuffer at 0x%08lx, mapped to 0x%p, size %dk\n",
  509. macfb_fix.smem_start, fb_info.screen_base,
  510. macfb_fix.smem_len / 1024);
  511. printk("macfb: mode is %dx%dx%d, linelength=%d\n",
  512. macfb_defined.xres, macfb_defined.yres,
  513. macfb_defined.bits_per_pixel, macfb_fix.line_length);
  514. /* Fill in the available video resolution */
  515. macfb_defined.xres_virtual = macfb_defined.xres;
  516. macfb_defined.yres_virtual = macfb_defined.yres;
  517. macfb_defined.height = PIXEL_TO_MM(macfb_defined.yres);
  518. macfb_defined.width = PIXEL_TO_MM(macfb_defined.xres);
  519. /* Some dummy values for timing to make fbset happy */
  520. macfb_defined.pixclock = 10000000 / macfb_defined.xres *
  521. 1000 / macfb_defined.yres;
  522. macfb_defined.left_margin = (macfb_defined.xres / 8) & 0xf8;
  523. macfb_defined.hsync_len = (macfb_defined.xres / 8) & 0xf8;
  524. switch (macfb_defined.bits_per_pixel) {
  525. case 1:
  526. /*
  527. * XXX: I think this will catch any program that tries
  528. * to do FBIO_PUTCMAP when the visual is monochrome.
  529. */
  530. macfb_defined.red.length = macfb_defined.bits_per_pixel;
  531. macfb_defined.green.length = macfb_defined.bits_per_pixel;
  532. macfb_defined.blue.length = macfb_defined.bits_per_pixel;
  533. video_cmap_len = 0;
  534. macfb_fix.visual = FB_VISUAL_MONO01;
  535. break;
  536. case 2:
  537. case 4:
  538. case 8:
  539. macfb_defined.red.length = macfb_defined.bits_per_pixel;
  540. macfb_defined.green.length = macfb_defined.bits_per_pixel;
  541. macfb_defined.blue.length = macfb_defined.bits_per_pixel;
  542. video_cmap_len = 1 << macfb_defined.bits_per_pixel;
  543. macfb_fix.visual = FB_VISUAL_PSEUDOCOLOR;
  544. break;
  545. case 16:
  546. macfb_defined.transp.offset = 15;
  547. macfb_defined.transp.length = 1;
  548. macfb_defined.red.offset = 10;
  549. macfb_defined.red.length = 5;
  550. macfb_defined.green.offset = 5;
  551. macfb_defined.green.length = 5;
  552. macfb_defined.blue.offset = 0;
  553. macfb_defined.blue.length = 5;
  554. video_cmap_len = 16;
  555. /*
  556. * Should actually be FB_VISUAL_DIRECTCOLOR, but this
  557. * works too
  558. */
  559. macfb_fix.visual = FB_VISUAL_TRUECOLOR;
  560. break;
  561. case 24:
  562. case 32:
  563. macfb_defined.red.offset = 16;
  564. macfb_defined.red.length = 8;
  565. macfb_defined.green.offset = 8;
  566. macfb_defined.green.length = 8;
  567. macfb_defined.blue.offset = 0;
  568. macfb_defined.blue.length = 8;
  569. video_cmap_len = 16;
  570. macfb_fix.visual = FB_VISUAL_TRUECOLOR;
  571. break;
  572. default:
  573. video_cmap_len = 0;
  574. macfb_fix.visual = FB_VISUAL_MONO01;
  575. printk("macfb: unknown or unsupported bit depth: %d\n",
  576. macfb_defined.bits_per_pixel);
  577. break;
  578. }
  579. /*
  580. * We take a wild guess that if the video physical address is
  581. * in nubus slot space, that the nubus card is driving video.
  582. * Penguin really ought to tell us whether we are using internal
  583. * video or not.
  584. * Hopefully we only find one of them. Otherwise our NuBus
  585. * code is really broken :-)
  586. */
  587. while ((ndev = nubus_find_type(NUBUS_CAT_DISPLAY,
  588. NUBUS_TYPE_VIDEO, ndev)))
  589. {
  590. unsigned long base = ndev->board->slot_addr;
  591. if (mac_bi_data.videoaddr < base ||
  592. mac_bi_data.videoaddr - base > 0xFFFFFF)
  593. continue;
  594. video_is_nubus = 1;
  595. slot_addr = (unsigned char *)base;
  596. switch(ndev->dr_hw) {
  597. case NUBUS_DRHW_APPLE_MDC:
  598. strcpy(macfb_fix.id, "Mac Disp. Card");
  599. macfb_setpalette = mdc_setpalette;
  600. macfb_defined.activate = FB_ACTIVATE_NOW;
  601. break;
  602. case NUBUS_DRHW_APPLE_TFB:
  603. strcpy(macfb_fix.id, "Toby");
  604. macfb_setpalette = toby_setpalette;
  605. macfb_defined.activate = FB_ACTIVATE_NOW;
  606. break;
  607. case NUBUS_DRHW_APPLE_JET:
  608. strcpy(macfb_fix.id, "Jet");
  609. macfb_setpalette = jet_setpalette;
  610. macfb_defined.activate = FB_ACTIVATE_NOW;
  611. break;
  612. default:
  613. strcpy(macfb_fix.id, "Generic NuBus");
  614. break;
  615. }
  616. }
  617. /* If it's not a NuBus card, it must be internal video */
  618. if (!video_is_nubus)
  619. switch (mac_bi_data.id) {
  620. /*
  621. * DAFB Quadras
  622. * Note: these first four have the v7 DAFB, which is
  623. * known to be rather unlike the ones used in the
  624. * other models
  625. */
  626. case MAC_MODEL_P475:
  627. case MAC_MODEL_P475F:
  628. case MAC_MODEL_P575:
  629. case MAC_MODEL_Q605:
  630. case MAC_MODEL_Q800:
  631. case MAC_MODEL_Q650:
  632. case MAC_MODEL_Q610:
  633. case MAC_MODEL_C650:
  634. case MAC_MODEL_C610:
  635. case MAC_MODEL_Q700:
  636. case MAC_MODEL_Q900:
  637. case MAC_MODEL_Q950:
  638. strcpy(macfb_fix.id, "DAFB");
  639. macfb_setpalette = dafb_setpalette;
  640. macfb_defined.activate = FB_ACTIVATE_NOW;
  641. dafb_cmap_regs = ioremap(DAFB_BASE, 0x1000);
  642. break;
  643. /*
  644. * LC II uses the V8 framebuffer
  645. */
  646. case MAC_MODEL_LCII:
  647. strcpy(macfb_fix.id, "V8");
  648. macfb_setpalette = v8_brazil_setpalette;
  649. macfb_defined.activate = FB_ACTIVATE_NOW;
  650. v8_brazil_cmap_regs = ioremap(DAC_BASE, 0x1000);
  651. break;
  652. /*
  653. * IIvi, IIvx use the "Brazil" framebuffer (which is
  654. * very much like the V8, it seems, and probably uses
  655. * the same DAC)
  656. */
  657. case MAC_MODEL_IIVI:
  658. case MAC_MODEL_IIVX:
  659. case MAC_MODEL_P600:
  660. strcpy(macfb_fix.id, "Brazil");
  661. macfb_setpalette = v8_brazil_setpalette;
  662. macfb_defined.activate = FB_ACTIVATE_NOW;
  663. v8_brazil_cmap_regs = ioremap(DAC_BASE, 0x1000);
  664. break;
  665. /*
  666. * LC III (and friends) use the Sonora framebuffer
  667. * Incidentally this is also used in the non-AV models
  668. * of the x100 PowerMacs
  669. * These do in fact seem to use the same DAC interface
  670. * as the LC II.
  671. */
  672. case MAC_MODEL_LCIII:
  673. case MAC_MODEL_P520:
  674. case MAC_MODEL_P550:
  675. case MAC_MODEL_P460:
  676. macfb_setpalette = v8_brazil_setpalette;
  677. macfb_defined.activate = FB_ACTIVATE_NOW;
  678. strcpy(macfb_fix.id, "Sonora");
  679. v8_brazil_cmap_regs = ioremap(DAC_BASE, 0x1000);
  680. break;
  681. /*
  682. * IIci and IIsi use the infamous RBV chip
  683. * (the IIsi is just a rebadged and crippled
  684. * IIci in a different case, BTW)
  685. */
  686. case MAC_MODEL_IICI:
  687. case MAC_MODEL_IISI:
  688. macfb_setpalette = rbv_setpalette;
  689. macfb_defined.activate = FB_ACTIVATE_NOW;
  690. strcpy(macfb_fix.id, "RBV");
  691. rbv_cmap_regs = ioremap(DAC_BASE, 0x1000);
  692. break;
  693. /*
  694. * AVs use the Civic framebuffer
  695. */
  696. case MAC_MODEL_Q840:
  697. case MAC_MODEL_C660:
  698. macfb_setpalette = civic_setpalette;
  699. macfb_defined.activate = FB_ACTIVATE_NOW;
  700. strcpy(macfb_fix.id, "Civic");
  701. civic_cmap_regs = ioremap(CIVIC_BASE, 0x1000);
  702. break;
  703. /*
  704. * Assorted weirdos
  705. * We think this may be like the LC II
  706. */
  707. case MAC_MODEL_LC:
  708. if (vidtest) {
  709. macfb_setpalette = v8_brazil_setpalette;
  710. macfb_defined.activate = FB_ACTIVATE_NOW;
  711. v8_brazil_cmap_regs =
  712. ioremap(DAC_BASE, 0x1000);
  713. }
  714. strcpy(macfb_fix.id, "LC");
  715. break;
  716. /*
  717. * We think this may be like the LC II
  718. */
  719. case MAC_MODEL_CCL:
  720. if (vidtest) {
  721. macfb_setpalette = v8_brazil_setpalette;
  722. macfb_defined.activate = FB_ACTIVATE_NOW;
  723. v8_brazil_cmap_regs =
  724. ioremap(DAC_BASE, 0x1000);
  725. }
  726. strcpy(macfb_fix.id, "Color Classic");
  727. break;
  728. /*
  729. * And we *do* mean "weirdos"
  730. */
  731. case MAC_MODEL_TV:
  732. strcpy(macfb_fix.id, "Mac TV");
  733. break;
  734. /*
  735. * These don't have colour, so no need to worry
  736. */
  737. case MAC_MODEL_SE30:
  738. case MAC_MODEL_CLII:
  739. strcpy(macfb_fix.id, "Monochrome");
  740. break;
  741. /*
  742. * Powerbooks are particularly difficult. Many of
  743. * them have separate framebuffers for external and
  744. * internal video, which is admittedly pretty cool,
  745. * but will be a bit of a headache to support here.
  746. * Also, many of them are grayscale, and we don't
  747. * really support that.
  748. */
  749. /*
  750. * Slot 0 ROM says TIM. No external video. B&W.
  751. */
  752. case MAC_MODEL_PB140:
  753. case MAC_MODEL_PB145:
  754. case MAC_MODEL_PB170:
  755. strcpy(macfb_fix.id, "DDC");
  756. break;
  757. /*
  758. * Internal is GSC, External (if present) is ViSC
  759. */
  760. case MAC_MODEL_PB150: /* no external video */
  761. case MAC_MODEL_PB160:
  762. case MAC_MODEL_PB165:
  763. case MAC_MODEL_PB180:
  764. case MAC_MODEL_PB210:
  765. case MAC_MODEL_PB230:
  766. strcpy(macfb_fix.id, "GSC");
  767. break;
  768. /*
  769. * Internal is TIM, External is ViSC
  770. */
  771. case MAC_MODEL_PB165C:
  772. case MAC_MODEL_PB180C:
  773. strcpy(macfb_fix.id, "TIM");
  774. break;
  775. /*
  776. * Internal is CSC, External is Keystone+Ariel.
  777. */
  778. case MAC_MODEL_PB190: /* external video is optional */
  779. case MAC_MODEL_PB520:
  780. case MAC_MODEL_PB250:
  781. case MAC_MODEL_PB270C:
  782. case MAC_MODEL_PB280:
  783. case MAC_MODEL_PB280C:
  784. macfb_setpalette = csc_setpalette;
  785. macfb_defined.activate = FB_ACTIVATE_NOW;
  786. strcpy(macfb_fix.id, "CSC");
  787. csc_cmap_regs = ioremap(CSC_BASE, 0x1000);
  788. break;
  789. default:
  790. strcpy(macfb_fix.id, "Unknown");
  791. break;
  792. }
  793. fb_info.fbops = &macfb_ops;
  794. fb_info.var = macfb_defined;
  795. fb_info.fix = macfb_fix;
  796. fb_info.pseudo_palette = pseudo_palette;
  797. fb_info.flags = FBINFO_DEFAULT;
  798. err = fb_alloc_cmap(&fb_info.cmap, video_cmap_len, 0);
  799. if (err)
  800. goto fail_unmap;
  801. err = register_framebuffer(&fb_info);
  802. if (err)
  803. goto fail_dealloc;
  804. printk("fb%d: %s frame buffer device\n",
  805. fb_info.node, fb_info.fix.id);
  806. return 0;
  807. fail_dealloc:
  808. fb_dealloc_cmap(&fb_info.cmap);
  809. fail_unmap:
  810. iounmap(fb_info.screen_base);
  811. iounmap_macfb();
  812. return err;
  813. }
  814. module_init(macfb_init);
  815. MODULE_LICENSE("GPL");