macfb.c 22 KB

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