macfb.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931
  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. pr_info("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. pr_info("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. macfb_defined.red.length = macfb_defined.bits_per_pixel;
  527. macfb_defined.green.length = macfb_defined.bits_per_pixel;
  528. macfb_defined.blue.length = macfb_defined.bits_per_pixel;
  529. video_cmap_len = 2;
  530. macfb_fix.visual = FB_VISUAL_MONO01;
  531. break;
  532. case 2:
  533. case 4:
  534. case 8:
  535. macfb_defined.red.length = macfb_defined.bits_per_pixel;
  536. macfb_defined.green.length = macfb_defined.bits_per_pixel;
  537. macfb_defined.blue.length = macfb_defined.bits_per_pixel;
  538. video_cmap_len = 1 << macfb_defined.bits_per_pixel;
  539. macfb_fix.visual = FB_VISUAL_PSEUDOCOLOR;
  540. break;
  541. case 16:
  542. macfb_defined.transp.offset = 15;
  543. macfb_defined.transp.length = 1;
  544. macfb_defined.red.offset = 10;
  545. macfb_defined.red.length = 5;
  546. macfb_defined.green.offset = 5;
  547. macfb_defined.green.length = 5;
  548. macfb_defined.blue.offset = 0;
  549. macfb_defined.blue.length = 5;
  550. video_cmap_len = 16;
  551. /*
  552. * Should actually be FB_VISUAL_DIRECTCOLOR, but this
  553. * works too
  554. */
  555. macfb_fix.visual = FB_VISUAL_TRUECOLOR;
  556. break;
  557. case 24:
  558. case 32:
  559. macfb_defined.red.offset = 16;
  560. macfb_defined.red.length = 8;
  561. macfb_defined.green.offset = 8;
  562. macfb_defined.green.length = 8;
  563. macfb_defined.blue.offset = 0;
  564. macfb_defined.blue.length = 8;
  565. video_cmap_len = 16;
  566. macfb_fix.visual = FB_VISUAL_TRUECOLOR;
  567. break;
  568. default:
  569. pr_err("macfb: unknown or unsupported bit depth: %d\n",
  570. macfb_defined.bits_per_pixel);
  571. err = -EINVAL;
  572. goto fail_unmap;
  573. }
  574. /*
  575. * We take a wild guess that if the video physical address is
  576. * in nubus slot space, that the nubus card is driving video.
  577. * Penguin really ought to tell us whether we are using internal
  578. * video or not.
  579. * Hopefully we only find one of them. Otherwise our NuBus
  580. * code is really broken :-)
  581. */
  582. while ((ndev = nubus_find_type(NUBUS_CAT_DISPLAY,
  583. NUBUS_TYPE_VIDEO, ndev)))
  584. {
  585. unsigned long base = ndev->board->slot_addr;
  586. if (mac_bi_data.videoaddr < base ||
  587. mac_bi_data.videoaddr - base > 0xFFFFFF)
  588. continue;
  589. video_is_nubus = 1;
  590. slot_addr = (unsigned char *)base;
  591. switch(ndev->dr_hw) {
  592. case NUBUS_DRHW_APPLE_MDC:
  593. strcpy(macfb_fix.id, "Mac Disp. Card");
  594. macfb_setpalette = mdc_setpalette;
  595. macfb_defined.activate = FB_ACTIVATE_NOW;
  596. break;
  597. case NUBUS_DRHW_APPLE_TFB:
  598. strcpy(macfb_fix.id, "Toby");
  599. macfb_setpalette = toby_setpalette;
  600. macfb_defined.activate = FB_ACTIVATE_NOW;
  601. break;
  602. case NUBUS_DRHW_APPLE_JET:
  603. strcpy(macfb_fix.id, "Jet");
  604. macfb_setpalette = jet_setpalette;
  605. macfb_defined.activate = FB_ACTIVATE_NOW;
  606. break;
  607. default:
  608. strcpy(macfb_fix.id, "Generic NuBus");
  609. break;
  610. }
  611. }
  612. /* If it's not a NuBus card, it must be internal video */
  613. if (!video_is_nubus)
  614. switch (mac_bi_data.id) {
  615. /*
  616. * DAFB Quadras
  617. * Note: these first four have the v7 DAFB, which is
  618. * known to be rather unlike the ones used in the
  619. * other models
  620. */
  621. case MAC_MODEL_P475:
  622. case MAC_MODEL_P475F:
  623. case MAC_MODEL_P575:
  624. case MAC_MODEL_Q605:
  625. case MAC_MODEL_Q800:
  626. case MAC_MODEL_Q650:
  627. case MAC_MODEL_Q610:
  628. case MAC_MODEL_C650:
  629. case MAC_MODEL_C610:
  630. case MAC_MODEL_Q700:
  631. case MAC_MODEL_Q900:
  632. case MAC_MODEL_Q950:
  633. strcpy(macfb_fix.id, "DAFB");
  634. macfb_setpalette = dafb_setpalette;
  635. dafb_cmap_regs = ioremap(DAFB_BASE, 0x1000);
  636. macfb_defined.activate = FB_ACTIVATE_NOW;
  637. break;
  638. /*
  639. * LC II uses the V8 framebuffer
  640. */
  641. case MAC_MODEL_LCII:
  642. strcpy(macfb_fix.id, "V8");
  643. macfb_setpalette = v8_brazil_setpalette;
  644. v8_brazil_cmap_regs = ioremap(DAC_BASE, 0x1000);
  645. macfb_defined.activate = FB_ACTIVATE_NOW;
  646. break;
  647. /*
  648. * IIvi, IIvx use the "Brazil" framebuffer (which is
  649. * very much like the V8, it seems, and probably uses
  650. * the same DAC)
  651. */
  652. case MAC_MODEL_IIVI:
  653. case MAC_MODEL_IIVX:
  654. case MAC_MODEL_P600:
  655. strcpy(macfb_fix.id, "Brazil");
  656. macfb_setpalette = v8_brazil_setpalette;
  657. v8_brazil_cmap_regs = ioremap(DAC_BASE, 0x1000);
  658. macfb_defined.activate = FB_ACTIVATE_NOW;
  659. break;
  660. /*
  661. * LC III (and friends) use the Sonora framebuffer
  662. * Incidentally this is also used in the non-AV models
  663. * of the x100 PowerMacs
  664. * These do in fact seem to use the same DAC interface
  665. * as the LC II.
  666. */
  667. case MAC_MODEL_LCIII:
  668. case MAC_MODEL_P520:
  669. case MAC_MODEL_P550:
  670. case MAC_MODEL_P460:
  671. strcpy(macfb_fix.id, "Sonora");
  672. macfb_setpalette = v8_brazil_setpalette;
  673. v8_brazil_cmap_regs = ioremap(DAC_BASE, 0x1000);
  674. macfb_defined.activate = FB_ACTIVATE_NOW;
  675. break;
  676. /*
  677. * IIci and IIsi use the infamous RBV chip
  678. * (the IIsi is just a rebadged and crippled
  679. * IIci in a different case, BTW)
  680. */
  681. case MAC_MODEL_IICI:
  682. case MAC_MODEL_IISI:
  683. strcpy(macfb_fix.id, "RBV");
  684. macfb_setpalette = rbv_setpalette;
  685. rbv_cmap_regs = ioremap(DAC_BASE, 0x1000);
  686. macfb_defined.activate = FB_ACTIVATE_NOW;
  687. break;
  688. /*
  689. * AVs use the Civic framebuffer
  690. */
  691. case MAC_MODEL_Q840:
  692. case MAC_MODEL_C660:
  693. strcpy(macfb_fix.id, "Civic");
  694. macfb_setpalette = civic_setpalette;
  695. civic_cmap_regs = ioremap(CIVIC_BASE, 0x1000);
  696. macfb_defined.activate = FB_ACTIVATE_NOW;
  697. break;
  698. /*
  699. * Assorted weirdos
  700. * We think this may be like the LC II
  701. */
  702. case MAC_MODEL_LC:
  703. strcpy(macfb_fix.id, "LC");
  704. if (vidtest) {
  705. macfb_setpalette = v8_brazil_setpalette;
  706. v8_brazil_cmap_regs =
  707. ioremap(DAC_BASE, 0x1000);
  708. macfb_defined.activate = FB_ACTIVATE_NOW;
  709. }
  710. break;
  711. /*
  712. * We think this may be like the LC II
  713. */
  714. case MAC_MODEL_CCL:
  715. strcpy(macfb_fix.id, "Color Classic");
  716. if (vidtest) {
  717. macfb_setpalette = v8_brazil_setpalette;
  718. v8_brazil_cmap_regs =
  719. ioremap(DAC_BASE, 0x1000);
  720. macfb_defined.activate = FB_ACTIVATE_NOW;
  721. }
  722. break;
  723. /*
  724. * And we *do* mean "weirdos"
  725. */
  726. case MAC_MODEL_TV:
  727. strcpy(macfb_fix.id, "Mac TV");
  728. break;
  729. /*
  730. * These don't have colour, so no need to worry
  731. */
  732. case MAC_MODEL_SE30:
  733. case MAC_MODEL_CLII:
  734. strcpy(macfb_fix.id, "Monochrome");
  735. break;
  736. /*
  737. * Powerbooks are particularly difficult. Many of
  738. * them have separate framebuffers for external and
  739. * internal video, which is admittedly pretty cool,
  740. * but will be a bit of a headache to support here.
  741. * Also, many of them are grayscale, and we don't
  742. * really support that.
  743. */
  744. /*
  745. * Slot 0 ROM says TIM. No external video. B&W.
  746. */
  747. case MAC_MODEL_PB140:
  748. case MAC_MODEL_PB145:
  749. case MAC_MODEL_PB170:
  750. strcpy(macfb_fix.id, "DDC");
  751. break;
  752. /*
  753. * Internal is GSC, External (if present) is ViSC
  754. */
  755. case MAC_MODEL_PB150: /* no external video */
  756. case MAC_MODEL_PB160:
  757. case MAC_MODEL_PB165:
  758. case MAC_MODEL_PB180:
  759. case MAC_MODEL_PB210:
  760. case MAC_MODEL_PB230:
  761. strcpy(macfb_fix.id, "GSC");
  762. break;
  763. /*
  764. * Internal is TIM, External is ViSC
  765. */
  766. case MAC_MODEL_PB165C:
  767. case MAC_MODEL_PB180C:
  768. strcpy(macfb_fix.id, "TIM");
  769. break;
  770. /*
  771. * Internal is CSC, External is Keystone+Ariel.
  772. */
  773. case MAC_MODEL_PB190: /* external video is optional */
  774. case MAC_MODEL_PB520:
  775. case MAC_MODEL_PB250:
  776. case MAC_MODEL_PB270C:
  777. case MAC_MODEL_PB280:
  778. case MAC_MODEL_PB280C:
  779. strcpy(macfb_fix.id, "CSC");
  780. macfb_setpalette = csc_setpalette;
  781. csc_cmap_regs = ioremap(CSC_BASE, 0x1000);
  782. macfb_defined.activate = FB_ACTIVATE_NOW;
  783. break;
  784. default:
  785. strcpy(macfb_fix.id, "Unknown");
  786. break;
  787. }
  788. fb_info.fbops = &macfb_ops;
  789. fb_info.var = macfb_defined;
  790. fb_info.fix = macfb_fix;
  791. fb_info.pseudo_palette = pseudo_palette;
  792. fb_info.flags = FBINFO_DEFAULT;
  793. err = fb_alloc_cmap(&fb_info.cmap, video_cmap_len, 0);
  794. if (err)
  795. goto fail_unmap;
  796. err = register_framebuffer(&fb_info);
  797. if (err)
  798. goto fail_dealloc;
  799. pr_info("fb%d: %s frame buffer device\n",
  800. fb_info.node, fb_info.fix.id);
  801. return 0;
  802. fail_dealloc:
  803. fb_dealloc_cmap(&fb_info.cmap);
  804. fail_unmap:
  805. iounmap(fb_info.screen_base);
  806. iounmap_macfb();
  807. return err;
  808. }
  809. module_init(macfb_init);
  810. MODULE_LICENSE("GPL");