macfb.c 24 KB

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