via.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737
  1. /*
  2. * 6522 Versatile Interface Adapter (VIA)
  3. *
  4. * There are two of these on the Mac II. Some IRQs are vectored
  5. * via them as are assorted bits and bobs - eg RTC, ADB.
  6. *
  7. * CSA: Motorola seems to have removed documentation on the 6522 from
  8. * their web site; try
  9. * http://nerini.drf.com/vectrex/other/text/chips/6522/
  10. * http://www.zymurgy.net/classic/vic20/vicdet1.htm
  11. * and
  12. * http://193.23.168.87/mikro_laborversuche/via_iobaustein/via6522_1.html
  13. * for info. A full-text web search on 6522 AND VIA will probably also
  14. * net some usefulness. <cananian@alumni.princeton.edu> 20apr1999
  15. *
  16. * Additional data is here (the SY6522 was used in the Mac II etc):
  17. * http://www.6502.org/documents/datasheets/synertek/synertek_sy6522.pdf
  18. * http://www.6502.org/documents/datasheets/synertek/synertek_sy6522_programming_reference.pdf
  19. *
  20. * PRAM/RTC access algorithms are from the NetBSD RTC toolkit version 1.08b
  21. * by Erik Vogan and adapted to Linux by Joshua M. Thompson (funaho@jurai.org)
  22. *
  23. */
  24. #include <linux/types.h>
  25. #include <linux/kernel.h>
  26. #include <linux/mm.h>
  27. #include <linux/delay.h>
  28. #include <linux/init.h>
  29. #include <linux/module.h>
  30. #ifdef CONFIG_GENERIC_HARDIRQS
  31. #include <linux/irq.h>
  32. #endif
  33. #include <asm/bootinfo.h>
  34. #include <asm/macintosh.h>
  35. #include <asm/macints.h>
  36. #include <asm/mac_via.h>
  37. #include <asm/mac_psc.h>
  38. #include <asm/mac_oss.h>
  39. volatile __u8 *via1, *via2;
  40. int rbv_present;
  41. int via_alt_mapping;
  42. EXPORT_SYMBOL(via_alt_mapping);
  43. static __u8 rbv_clear;
  44. /*
  45. * Globals for accessing the VIA chip registers without having to
  46. * check if we're hitting a real VIA or an RBV. Normally you could
  47. * just hit the combined register (ie, vIER|rIER) but that seems to
  48. * break on AV Macs...probably because they actually decode more than
  49. * eight address bits. Why can't Apple engineers at least be
  50. * _consistently_ lazy? - 1999-05-21 (jmt)
  51. */
  52. static int gIER,gIFR,gBufA,gBufB;
  53. /*
  54. * Timer defs.
  55. */
  56. #define TICK_SIZE 10000
  57. #define MAC_CLOCK_TICK (783300/HZ) /* ticks per HZ */
  58. #define MAC_CLOCK_LOW (MAC_CLOCK_TICK&0xFF)
  59. #define MAC_CLOCK_HIGH (MAC_CLOCK_TICK>>8)
  60. /* To disable a NuBus slot on Quadras we make that slot IRQ line an output set
  61. * high. On RBV we just use the slot interrupt enable register. On Macs with
  62. * genuine VIA chips we must use nubus_disabled to keep track of disabled slot
  63. * interrupts. When any slot IRQ is disabled we mask the (edge triggered) CA1
  64. * or "SLOTS" interrupt. When no slot is disabled, we unmask the CA1 interrupt.
  65. * So, on genuine VIAs, having more than one NuBus IRQ can mean trouble,
  66. * because closing one of those drivers can mask all of the NuBus interrupts.
  67. * Also, since we can't mask the unregistered slot IRQs on genuine VIAs, it's
  68. * possible to get interrupts from cards that MacOS or the ROM has configured
  69. * but we have not. FWIW, "Designing Cards and Drivers for Macintosh II and
  70. * Macintosh SE", page 9-8, says, a slot IRQ with no driver would crash MacOS.
  71. */
  72. static u8 nubus_disabled;
  73. void via_debug_dump(void);
  74. void via_irq_enable(int irq);
  75. void via_irq_disable(int irq);
  76. void via_irq_clear(int irq);
  77. /*
  78. * Initialize the VIAs
  79. *
  80. * First we figure out where they actually _are_ as well as what type of
  81. * VIA we have for VIA2 (it could be a real VIA or an RBV or even an OSS.)
  82. * Then we pretty much clear them out and disable all IRQ sources.
  83. *
  84. * Note: the OSS is actually "detected" here and not in oss_init(). It just
  85. * seems more logical to do it here since via_init() needs to know
  86. * these things anyways.
  87. */
  88. void __init via_init(void)
  89. {
  90. switch(macintosh_config->via_type) {
  91. /* IIci, IIsi, IIvx, IIvi (P6xx), LC series */
  92. case MAC_VIA_IIci:
  93. via1 = (void *) VIA1_BASE;
  94. if (macintosh_config->ident == MAC_MODEL_IIFX) {
  95. via2 = NULL;
  96. rbv_present = 0;
  97. oss_present = 1;
  98. } else {
  99. via2 = (void *) RBV_BASE;
  100. rbv_present = 1;
  101. oss_present = 0;
  102. }
  103. if (macintosh_config->ident == MAC_MODEL_LCIII) {
  104. rbv_clear = 0x00;
  105. } else {
  106. /* on most RBVs (& unlike the VIAs), you */
  107. /* need to set bit 7 when you write to IFR */
  108. /* in order for your clear to occur. */
  109. rbv_clear = 0x80;
  110. }
  111. gIER = rIER;
  112. gIFR = rIFR;
  113. gBufA = rSIFR;
  114. gBufB = rBufB;
  115. break;
  116. /* Quadra and early MacIIs agree on the VIA locations */
  117. case MAC_VIA_QUADRA:
  118. case MAC_VIA_II:
  119. via1 = (void *) VIA1_BASE;
  120. via2 = (void *) VIA2_BASE;
  121. rbv_present = 0;
  122. oss_present = 0;
  123. rbv_clear = 0x00;
  124. gIER = vIER;
  125. gIFR = vIFR;
  126. gBufA = vBufA;
  127. gBufB = vBufB;
  128. break;
  129. default:
  130. panic("UNKNOWN VIA TYPE");
  131. }
  132. printk(KERN_INFO "VIA1 at %p is a 6522 or clone\n", via1);
  133. printk(KERN_INFO "VIA2 at %p is ", via2);
  134. if (rbv_present) {
  135. printk("an RBV\n");
  136. } else if (oss_present) {
  137. printk("an OSS\n");
  138. } else {
  139. printk("a 6522 or clone\n");
  140. }
  141. #ifdef DEBUG_VIA
  142. via_debug_dump();
  143. #endif
  144. /*
  145. * Shut down all IRQ sources, reset the timers, and
  146. * kill the timer latch on VIA1.
  147. */
  148. via1[vIER] = 0x7F;
  149. via1[vIFR] = 0x7F;
  150. via1[vT1LL] = 0;
  151. via1[vT1LH] = 0;
  152. via1[vT1CL] = 0;
  153. via1[vT1CH] = 0;
  154. via1[vT2CL] = 0;
  155. via1[vT2CH] = 0;
  156. via1[vACR] &= ~0xC0; /* setup T1 timer with no PB7 output */
  157. via1[vACR] &= ~0x03; /* disable port A & B latches */
  158. /*
  159. * SE/30: disable video IRQ
  160. * XXX: testing for SE/30 VBL
  161. */
  162. if (macintosh_config->ident == MAC_MODEL_SE30) {
  163. via1[vDirB] |= 0x40;
  164. via1[vBufB] |= 0x40;
  165. }
  166. /*
  167. * Set the RTC bits to a known state: all lines to outputs and
  168. * RTC disabled (yes that's 0 to enable and 1 to disable).
  169. */
  170. via1[vDirB] |= (VIA1B_vRTCEnb | VIA1B_vRTCClk | VIA1B_vRTCData);
  171. via1[vBufB] |= (VIA1B_vRTCEnb | VIA1B_vRTCClk);
  172. /* Everything below this point is VIA2/RBV only... */
  173. if (oss_present)
  174. return;
  175. /* Some machines support an alternate IRQ mapping that spreads */
  176. /* Ethernet and Sound out to their own autolevel IRQs and moves */
  177. /* VIA1 to level 6. A/UX uses this mapping and we do too. Note */
  178. /* that the IIfx emulates this alternate mapping using the OSS. */
  179. via_alt_mapping = 0;
  180. if (macintosh_config->via_type == MAC_VIA_QUADRA)
  181. switch (macintosh_config->ident) {
  182. case MAC_MODEL_C660:
  183. case MAC_MODEL_Q840:
  184. /* not applicable */
  185. break;
  186. case MAC_MODEL_P588:
  187. case MAC_MODEL_TV:
  188. case MAC_MODEL_PB140:
  189. case MAC_MODEL_PB145:
  190. case MAC_MODEL_PB160:
  191. case MAC_MODEL_PB165:
  192. case MAC_MODEL_PB165C:
  193. case MAC_MODEL_PB170:
  194. case MAC_MODEL_PB180:
  195. case MAC_MODEL_PB180C:
  196. case MAC_MODEL_PB190:
  197. case MAC_MODEL_PB520:
  198. /* not yet tested */
  199. break;
  200. default:
  201. via_alt_mapping = 1;
  202. via1[vDirB] |= 0x40;
  203. via1[vBufB] &= ~0x40;
  204. break;
  205. }
  206. /*
  207. * Now initialize VIA2. For RBV we just kill all interrupts;
  208. * for a regular VIA we also reset the timers and stuff.
  209. */
  210. via2[gIER] = 0x7F;
  211. via2[gIFR] = 0x7F | rbv_clear;
  212. if (!rbv_present) {
  213. via2[vT1LL] = 0;
  214. via2[vT1LH] = 0;
  215. via2[vT1CL] = 0;
  216. via2[vT1CH] = 0;
  217. via2[vT2CL] = 0;
  218. via2[vT2CH] = 0;
  219. via2[vACR] &= ~0xC0; /* setup T1 timer with no PB7 output */
  220. via2[vACR] &= ~0x03; /* disable port A & B latches */
  221. }
  222. /*
  223. * Set vPCR for control line interrupts (but not on RBV)
  224. */
  225. if (!rbv_present) {
  226. /* For all VIA types, CA1 (SLOTS IRQ) and CB1 (ASC IRQ)
  227. * are made negative edge triggered here.
  228. */
  229. if (macintosh_config->scsi_type == MAC_SCSI_OLD) {
  230. /* CB2 (IRQ) indep. input, positive edge */
  231. /* CA2 (DRQ) indep. input, positive edge */
  232. via2[vPCR] = 0x66;
  233. } else {
  234. /* CB2 (IRQ) indep. input, negative edge */
  235. /* CA2 (DRQ) indep. input, negative edge */
  236. via2[vPCR] = 0x22;
  237. }
  238. }
  239. }
  240. /*
  241. * Start the 100 Hz clock
  242. */
  243. void __init via_init_clock(irq_handler_t func)
  244. {
  245. via1[vACR] |= 0x40;
  246. via1[vT1LL] = MAC_CLOCK_LOW;
  247. via1[vT1LH] = MAC_CLOCK_HIGH;
  248. via1[vT1CL] = MAC_CLOCK_LOW;
  249. via1[vT1CH] = MAC_CLOCK_HIGH;
  250. if (request_irq(IRQ_MAC_TIMER_1, func, 0, "timer", func))
  251. pr_err("Couldn't register %s interrupt\n", "timer");
  252. }
  253. /*
  254. * Debugging dump, used in various places to see what's going on.
  255. */
  256. void via_debug_dump(void)
  257. {
  258. printk(KERN_DEBUG "VIA1: DDRA = 0x%02X DDRB = 0x%02X ACR = 0x%02X\n",
  259. (uint) via1[vDirA], (uint) via1[vDirB], (uint) via1[vACR]);
  260. printk(KERN_DEBUG " PCR = 0x%02X IFR = 0x%02X IER = 0x%02X\n",
  261. (uint) via1[vPCR], (uint) via1[vIFR], (uint) via1[vIER]);
  262. if (oss_present) {
  263. printk(KERN_DEBUG "VIA2: <OSS>\n");
  264. } else if (rbv_present) {
  265. printk(KERN_DEBUG "VIA2: IFR = 0x%02X IER = 0x%02X\n",
  266. (uint) via2[rIFR], (uint) via2[rIER]);
  267. printk(KERN_DEBUG " SIFR = 0x%02X SIER = 0x%02X\n",
  268. (uint) via2[rSIFR], (uint) via2[rSIER]);
  269. } else {
  270. printk(KERN_DEBUG "VIA2: DDRA = 0x%02X DDRB = 0x%02X ACR = 0x%02X\n",
  271. (uint) via2[vDirA], (uint) via2[vDirB],
  272. (uint) via2[vACR]);
  273. printk(KERN_DEBUG " PCR = 0x%02X IFR = 0x%02X IER = 0x%02X\n",
  274. (uint) via2[vPCR],
  275. (uint) via2[vIFR], (uint) via2[vIER]);
  276. }
  277. }
  278. /*
  279. * This is always executed with interrupts disabled.
  280. *
  281. * TBI: get time offset between scheduling timer ticks
  282. */
  283. unsigned long mac_gettimeoffset (void)
  284. {
  285. unsigned long ticks, offset = 0;
  286. /* read VIA1 timer 2 current value */
  287. ticks = via1[vT1CL] | (via1[vT1CH] << 8);
  288. /* The probability of underflow is less than 2% */
  289. if (ticks > MAC_CLOCK_TICK - MAC_CLOCK_TICK / 50)
  290. /* Check for pending timer interrupt in VIA1 IFR */
  291. if (via1[vIFR] & 0x40) offset = TICK_SIZE;
  292. ticks = MAC_CLOCK_TICK - ticks;
  293. ticks = ticks * 10000L / MAC_CLOCK_TICK;
  294. return ticks + offset;
  295. }
  296. /*
  297. * Flush the L2 cache on Macs that have it by flipping
  298. * the system into 24-bit mode for an instant.
  299. */
  300. void via_flush_cache(void)
  301. {
  302. via2[gBufB] &= ~VIA2B_vMode32;
  303. via2[gBufB] |= VIA2B_vMode32;
  304. }
  305. /*
  306. * Return the status of the L2 cache on a IIci
  307. */
  308. int via_get_cache_disable(void)
  309. {
  310. /* Safeguard against being called accidentally */
  311. if (!via2) {
  312. printk(KERN_ERR "via_get_cache_disable called on a non-VIA machine!\n");
  313. return 1;
  314. }
  315. return (int) via2[gBufB] & VIA2B_vCDis;
  316. }
  317. /*
  318. * Initialize VIA2 for Nubus access
  319. */
  320. void __init via_nubus_init(void)
  321. {
  322. /* unlock nubus transactions */
  323. if ((macintosh_config->adb_type != MAC_ADB_PB1) &&
  324. (macintosh_config->adb_type != MAC_ADB_PB2)) {
  325. /* set the line to be an output on non-RBV machines */
  326. if (!rbv_present)
  327. via2[vDirB] |= 0x02;
  328. /* this seems to be an ADB bit on PMU machines */
  329. /* according to MkLinux. -- jmt */
  330. via2[gBufB] |= 0x02;
  331. }
  332. /* Disable all the slot interrupts (where possible). */
  333. switch (macintosh_config->via_type) {
  334. case MAC_VIA_II:
  335. /* Just make the port A lines inputs. */
  336. switch(macintosh_config->ident) {
  337. case MAC_MODEL_II:
  338. case MAC_MODEL_IIX:
  339. case MAC_MODEL_IICX:
  340. case MAC_MODEL_SE30:
  341. /* The top two bits are RAM size outputs. */
  342. via2[vDirA] &= 0xC0;
  343. break;
  344. default:
  345. via2[vDirA] &= 0x80;
  346. }
  347. break;
  348. case MAC_VIA_IIci:
  349. /* RBV. Disable all the slot interrupts. SIER works like IER. */
  350. via2[rSIER] = 0x7F;
  351. break;
  352. case MAC_VIA_QUADRA:
  353. /* Disable the inactive slot interrupts by making those lines outputs. */
  354. if ((macintosh_config->adb_type != MAC_ADB_PB1) &&
  355. (macintosh_config->adb_type != MAC_ADB_PB2)) {
  356. via2[vBufA] |= 0x7F;
  357. via2[vDirA] |= 0x7F;
  358. }
  359. break;
  360. }
  361. }
  362. /*
  363. * The generic VIA interrupt routines (shamelessly stolen from Alan Cox's
  364. * via6522.c :-), disable/pending masks added.
  365. */
  366. #ifdef CONFIG_GENERIC_HARDIRQS
  367. void via1_irq(unsigned int irq, struct irq_desc *desc)
  368. {
  369. int irq_num;
  370. unsigned char irq_bit, events;
  371. events = via1[vIFR] & via1[vIER] & 0x7F;
  372. if (!events)
  373. return;
  374. irq_num = VIA1_SOURCE_BASE;
  375. irq_bit = 1;
  376. do {
  377. if (events & irq_bit) {
  378. via1[vIFR] = irq_bit;
  379. generic_handle_irq(irq_num);
  380. }
  381. ++irq_num;
  382. irq_bit <<= 1;
  383. } while (events >= irq_bit);
  384. }
  385. static void via2_irq(unsigned int irq, struct irq_desc *desc)
  386. {
  387. int irq_num;
  388. unsigned char irq_bit, events;
  389. events = via2[gIFR] & via2[gIER] & 0x7F;
  390. if (!events)
  391. return;
  392. irq_num = VIA2_SOURCE_BASE;
  393. irq_bit = 1;
  394. do {
  395. if (events & irq_bit) {
  396. via2[gIFR] = irq_bit | rbv_clear;
  397. generic_handle_irq(irq_num);
  398. }
  399. ++irq_num;
  400. irq_bit <<= 1;
  401. } while (events >= irq_bit);
  402. }
  403. #else
  404. irqreturn_t via1_irq(int irq, void *dev_id)
  405. {
  406. int irq_num;
  407. unsigned char irq_bit, events;
  408. events = via1[vIFR] & via1[vIER] & 0x7F;
  409. if (!events)
  410. return IRQ_NONE;
  411. irq_num = VIA1_SOURCE_BASE;
  412. irq_bit = 1;
  413. do {
  414. if (events & irq_bit) {
  415. via1[vIFR] = irq_bit;
  416. generic_handle_irq(irq_num);
  417. }
  418. ++irq_num;
  419. irq_bit <<= 1;
  420. } while (events >= irq_bit);
  421. return IRQ_HANDLED;
  422. }
  423. irqreturn_t via2_irq(int irq, void *dev_id)
  424. {
  425. int irq_num;
  426. unsigned char irq_bit, events;
  427. events = via2[gIFR] & via2[gIER] & 0x7F;
  428. if (!events)
  429. return IRQ_NONE;
  430. irq_num = VIA2_SOURCE_BASE;
  431. irq_bit = 1;
  432. do {
  433. if (events & irq_bit) {
  434. via2[gIFR] = irq_bit | rbv_clear;
  435. generic_handle_irq(irq_num);
  436. }
  437. ++irq_num;
  438. irq_bit <<= 1;
  439. } while (events >= irq_bit);
  440. return IRQ_HANDLED;
  441. }
  442. #endif
  443. /*
  444. * Dispatch Nubus interrupts. We are called as a secondary dispatch by the
  445. * VIA2 dispatcher as a fast interrupt handler.
  446. */
  447. #ifdef CONFIG_GENERIC_HARDIRQS
  448. void via_nubus_irq(unsigned int irq, struct irq_desc *desc)
  449. {
  450. int slot_irq;
  451. unsigned char slot_bit, events;
  452. events = ~via2[gBufA] & 0x7F;
  453. if (rbv_present)
  454. events &= via2[rSIER];
  455. else
  456. events &= ~via2[vDirA];
  457. if (!events)
  458. return;
  459. do {
  460. slot_irq = IRQ_NUBUS_F;
  461. slot_bit = 0x40;
  462. do {
  463. if (events & slot_bit) {
  464. events &= ~slot_bit;
  465. generic_handle_irq(slot_irq);
  466. }
  467. --slot_irq;
  468. slot_bit >>= 1;
  469. } while (events);
  470. /* clear the CA1 interrupt and make certain there's no more. */
  471. via2[gIFR] = 0x02 | rbv_clear;
  472. events = ~via2[gBufA] & 0x7F;
  473. if (rbv_present)
  474. events &= via2[rSIER];
  475. else
  476. events &= ~via2[vDirA];
  477. } while (events);
  478. }
  479. #else
  480. irqreturn_t via_nubus_irq(int irq, void *dev_id)
  481. {
  482. int slot_irq;
  483. unsigned char slot_bit, events;
  484. events = ~via2[gBufA] & 0x7F;
  485. if (rbv_present)
  486. events &= via2[rSIER];
  487. else
  488. events &= ~via2[vDirA];
  489. if (!events)
  490. return IRQ_NONE;
  491. do {
  492. slot_irq = IRQ_NUBUS_F;
  493. slot_bit = 0x40;
  494. do {
  495. if (events & slot_bit) {
  496. events &= ~slot_bit;
  497. generic_handle_irq(slot_irq);
  498. }
  499. --slot_irq;
  500. slot_bit >>= 1;
  501. } while (events);
  502. /* clear the CA1 interrupt and make certain there's no more. */
  503. via2[gIFR] = 0x02 | rbv_clear;
  504. events = ~via2[gBufA] & 0x7F;
  505. if (rbv_present)
  506. events &= via2[rSIER];
  507. else
  508. events &= ~via2[vDirA];
  509. } while (events);
  510. return IRQ_HANDLED;
  511. }
  512. #endif
  513. /*
  514. * Register the interrupt dispatchers for VIA or RBV machines only.
  515. */
  516. void __init via_register_interrupts(void)
  517. {
  518. #ifdef CONFIG_GENERIC_HARDIRQS
  519. if (via_alt_mapping) {
  520. /* software interrupt */
  521. irq_set_chained_handler(IRQ_AUTO_1, via1_irq);
  522. /* via1 interrupt */
  523. irq_set_chained_handler(IRQ_AUTO_6, via1_irq);
  524. } else {
  525. irq_set_chained_handler(IRQ_AUTO_1, via1_irq);
  526. }
  527. irq_set_chained_handler(IRQ_AUTO_2, via2_irq);
  528. irq_set_chained_handler(IRQ_MAC_NUBUS, via_nubus_irq);
  529. #else
  530. if (via_alt_mapping) {
  531. if (request_irq(IRQ_AUTO_1, via1_irq, 0, "software",
  532. (void *)via1))
  533. pr_err("Couldn't register %s interrupt\n", "software");
  534. if (request_irq(IRQ_AUTO_6, via1_irq, 0, "via1", (void *)via1))
  535. pr_err("Couldn't register %s interrupt\n", "via1");
  536. } else {
  537. if (request_irq(IRQ_AUTO_1, via1_irq, 0, "via1", (void *)via1))
  538. pr_err("Couldn't register %s interrupt\n", "via1");
  539. }
  540. if (request_irq(IRQ_AUTO_2, via2_irq, 0, "via2", (void *)via2))
  541. pr_err("Couldn't register %s interrupt\n", "via2");
  542. if (request_irq(IRQ_MAC_NUBUS, via_nubus_irq, 0, "nubus",
  543. (void *)via2))
  544. pr_err("Couldn't register %s interrupt\n", "nubus");
  545. #endif
  546. }
  547. void via_irq_enable(int irq) {
  548. int irq_src = IRQ_SRC(irq);
  549. int irq_idx = IRQ_IDX(irq);
  550. #ifdef DEBUG_IRQUSE
  551. printk(KERN_DEBUG "via_irq_enable(%d)\n", irq);
  552. #endif
  553. if (irq_src == 1) {
  554. via1[vIER] = IER_SET_BIT(irq_idx);
  555. } else if (irq_src == 2) {
  556. if (irq != IRQ_MAC_NUBUS || nubus_disabled == 0)
  557. via2[gIER] = IER_SET_BIT(irq_idx);
  558. } else if (irq_src == 7) {
  559. switch (macintosh_config->via_type) {
  560. case MAC_VIA_II:
  561. nubus_disabled &= ~(1 << irq_idx);
  562. /* Enable the CA1 interrupt when no slot is disabled. */
  563. if (!nubus_disabled)
  564. via2[gIER] = IER_SET_BIT(1);
  565. break;
  566. case MAC_VIA_IIci:
  567. /* On RBV, enable the slot interrupt.
  568. * SIER works like IER.
  569. */
  570. via2[rSIER] = IER_SET_BIT(irq_idx);
  571. break;
  572. case MAC_VIA_QUADRA:
  573. /* Make the port A line an input to enable the slot irq.
  574. * But not on PowerBooks, that's ADB.
  575. */
  576. if ((macintosh_config->adb_type != MAC_ADB_PB1) &&
  577. (macintosh_config->adb_type != MAC_ADB_PB2))
  578. via2[vDirA] &= ~(1 << irq_idx);
  579. break;
  580. }
  581. }
  582. }
  583. void via_irq_disable(int irq) {
  584. int irq_src = IRQ_SRC(irq);
  585. int irq_idx = IRQ_IDX(irq);
  586. #ifdef DEBUG_IRQUSE
  587. printk(KERN_DEBUG "via_irq_disable(%d)\n", irq);
  588. #endif
  589. if (irq_src == 1) {
  590. via1[vIER] = IER_CLR_BIT(irq_idx);
  591. } else if (irq_src == 2) {
  592. via2[gIER] = IER_CLR_BIT(irq_idx);
  593. } else if (irq_src == 7) {
  594. switch (macintosh_config->via_type) {
  595. case MAC_VIA_II:
  596. nubus_disabled |= 1 << irq_idx;
  597. if (nubus_disabled)
  598. via2[gIER] = IER_CLR_BIT(1);
  599. break;
  600. case MAC_VIA_IIci:
  601. via2[rSIER] = IER_CLR_BIT(irq_idx);
  602. break;
  603. case MAC_VIA_QUADRA:
  604. if ((macintosh_config->adb_type != MAC_ADB_PB1) &&
  605. (macintosh_config->adb_type != MAC_ADB_PB2))
  606. via2[vDirA] |= 1 << irq_idx;
  607. break;
  608. }
  609. }
  610. }
  611. void via_irq_clear(int irq) {
  612. int irq_src = IRQ_SRC(irq);
  613. int irq_idx = IRQ_IDX(irq);
  614. int irq_bit = 1 << irq_idx;
  615. if (irq_src == 1) {
  616. via1[vIFR] = irq_bit;
  617. } else if (irq_src == 2) {
  618. via2[gIFR] = irq_bit | rbv_clear;
  619. } else if (irq_src == 7) {
  620. /* FIXME: There is no way to clear an individual nubus slot
  621. * IRQ flag, other than getting the device to do it.
  622. */
  623. }
  624. }
  625. /*
  626. * Returns nonzero if an interrupt is pending on the given
  627. * VIA/IRQ combination.
  628. */
  629. int via_irq_pending(int irq)
  630. {
  631. int irq_src = IRQ_SRC(irq);
  632. int irq_idx = IRQ_IDX(irq);
  633. int irq_bit = 1 << irq_idx;
  634. if (irq_src == 1) {
  635. return via1[vIFR] & irq_bit;
  636. } else if (irq_src == 2) {
  637. return via2[gIFR] & irq_bit;
  638. } else if (irq_src == 7) {
  639. /* Always 0 for MAC_VIA_QUADRA if the slot irq is disabled. */
  640. return ~via2[gBufA] & irq_bit;
  641. }
  642. return 0;
  643. }
  644. void via1_set_head(int head)
  645. {
  646. if (head == 0)
  647. via1[vBufA] &= ~VIA1A_vHeadSel;
  648. else
  649. via1[vBufA] |= VIA1A_vHeadSel;
  650. }
  651. EXPORT_SYMBOL(via1_set_head);