macfb.c 23 KB

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