macfb.c 27 KB

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