via.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. /*
  2. * 6522 Versatile Interface Adapter (VIA)
  3. *
  4. * There are two of these on the Mac II. Some IRQ's 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/ide.h>
  30. #include <asm/bootinfo.h>
  31. #include <asm/macintosh.h>
  32. #include <asm/macints.h>
  33. #include <asm/machw.h>
  34. #include <asm/mac_via.h>
  35. #include <asm/mac_psc.h>
  36. volatile __u8 *via1, *via2;
  37. #if 0
  38. /* See note in mac_via.h about how this is possibly not useful */
  39. volatile long *via_memory_bogon=(long *)&via_memory_bogon;
  40. #endif
  41. int rbv_present, via_alt_mapping;
  42. __u8 rbv_clear;
  43. /*
  44. * Globals for accessing the VIA chip registers without having to
  45. * check if we're hitting a real VIA or an RBV. Normally you could
  46. * just hit the combined register (ie, vIER|rIER) but that seems to
  47. * break on AV Macs...probably because they actually decode more than
  48. * eight address bits. Why can't Apple engineers at least be
  49. * _consistently_ lazy? - 1999-05-21 (jmt)
  50. */
  51. static int gIER,gIFR,gBufA,gBufB;
  52. /*
  53. * Timer defs.
  54. */
  55. #define TICK_SIZE 10000
  56. #define MAC_CLOCK_TICK (783300/HZ) /* ticks per HZ */
  57. #define MAC_CLOCK_LOW (MAC_CLOCK_TICK&0xFF)
  58. #define MAC_CLOCK_HIGH (MAC_CLOCK_TICK>>8)
  59. /* To disable a NuBus slot on Quadras we make the slot IRQ lines outputs, set
  60. * high. On RBV we just use the slot interrupt enable register. On Macs with
  61. * genuine VIA chips we must use nubus_disabled to keep track of disabled slot
  62. * interrupts. When any slot IRQ is disabled we mask the (edge triggered) CA1
  63. * or "SLOTS" interrupt. When no slot is disabled, we unmask the CA1 interrupt.
  64. * So, on genuine VIAs, having more than one NuBus IRQ can mean trouble,
  65. * because closing one of those drivers can mask all of the NuBus interrupts.
  66. * Also, since we can't mask the unregistered slot IRQs on genuine VIAs, it's
  67. * possible to get interrupts from cards that MacOS or the ROM has configured
  68. * but we have not. FWIW, "Designing Cards and Drivers for Macintosh II and
  69. * Macintosh SE", page 9-8, says, a slot IRQ with no driver would crash MacOS.
  70. */
  71. static u8 nubus_disabled;
  72. void via_debug_dump(void);
  73. irqreturn_t via1_irq(int, void *);
  74. irqreturn_t via2_irq(int, void *);
  75. irqreturn_t via_nubus_irq(int, void *);
  76. void via_irq_enable(int irq);
  77. void via_irq_disable(int irq);
  78. void via_irq_clear(int irq);
  79. extern irqreturn_t mac_scc_dispatch(int, void *);
  80. extern int oss_present;
  81. /*
  82. * Initialize the VIAs
  83. *
  84. * First we figure out where they actually _are_ as well as what type of
  85. * VIA we have for VIA2 (it could be a real VIA or an RBV or even an OSS.)
  86. * Then we pretty much clear them out and disable all IRQ sources.
  87. *
  88. * Note: the OSS is actually "detected" here and not in oss_init(). It just
  89. * seems more logical to do it here since via_init() needs to know
  90. * these things anyways.
  91. */
  92. void __init via_init(void)
  93. {
  94. switch(macintosh_config->via_type) {
  95. /* IIci, IIsi, IIvx, IIvi (P6xx), LC series */
  96. case MAC_VIA_IIci:
  97. via1 = (void *) VIA1_BASE;
  98. if (macintosh_config->ident == MAC_MODEL_IIFX) {
  99. via2 = NULL;
  100. rbv_present = 0;
  101. oss_present = 1;
  102. } else {
  103. via2 = (void *) RBV_BASE;
  104. rbv_present = 1;
  105. oss_present = 0;
  106. }
  107. if (macintosh_config->ident == MAC_MODEL_LCIII) {
  108. rbv_clear = 0x00;
  109. } else {
  110. /* on most RBVs (& unlike the VIAs), you */
  111. /* need to set bit 7 when you write to IFR */
  112. /* in order for your clear to occur. */
  113. rbv_clear = 0x80;
  114. }
  115. gIER = rIER;
  116. gIFR = rIFR;
  117. gBufA = rSIFR;
  118. gBufB = rBufB;
  119. break;
  120. /* Quadra and early MacIIs agree on the VIA locations */
  121. case MAC_VIA_QUADRA:
  122. case MAC_VIA_II:
  123. via1 = (void *) VIA1_BASE;
  124. via2 = (void *) VIA2_BASE;
  125. rbv_present = 0;
  126. oss_present = 0;
  127. rbv_clear = 0x00;
  128. gIER = vIER;
  129. gIFR = vIFR;
  130. gBufA = vBufA;
  131. gBufB = vBufB;
  132. break;
  133. default:
  134. panic("UNKNOWN VIA TYPE");
  135. }
  136. printk(KERN_INFO "VIA1 at %p is a 6522 or clone\n", via1);
  137. printk(KERN_INFO "VIA2 at %p is ", via2);
  138. if (rbv_present) {
  139. printk("an RBV\n");
  140. } else if (oss_present) {
  141. printk("an OSS\n");
  142. } else {
  143. printk("a 6522 or clone\n");
  144. }
  145. #ifdef DEBUG_VIA
  146. via_debug_dump();
  147. #endif
  148. /*
  149. * Shut down all IRQ sources, reset the timers, and
  150. * kill the timer latch on VIA1.
  151. */
  152. via1[vIER] = 0x7F;
  153. via1[vIFR] = 0x7F;
  154. via1[vT1LL] = 0;
  155. via1[vT1LH] = 0;
  156. via1[vT1CL] = 0;
  157. via1[vT1CH] = 0;
  158. via1[vT2CL] = 0;
  159. via1[vT2CH] = 0;
  160. via1[vACR] &= 0x3F;
  161. via1[vACR] &= ~0x03; /* disable port A & B latches */
  162. /*
  163. * SE/30: disable video IRQ
  164. * XXX: testing for SE/30 VBL
  165. */
  166. if (macintosh_config->ident == MAC_MODEL_SE30) {
  167. via1[vDirB] |= 0x40;
  168. via1[vBufB] |= 0x40;
  169. }
  170. /*
  171. * Set the RTC bits to a known state: all lines to outputs and
  172. * RTC disabled (yes that's 0 to enable and 1 to disable).
  173. */
  174. via1[vDirB] |= (VIA1B_vRTCEnb | VIA1B_vRTCClk | VIA1B_vRTCData);
  175. via1[vBufB] |= (VIA1B_vRTCEnb | VIA1B_vRTCClk);
  176. /* Everything below this point is VIA2/RBV only... */
  177. if (oss_present) return;
  178. #if 1
  179. /* Some machines support an alternate IRQ mapping that spreads */
  180. /* Ethernet and Sound out to their own autolevel IRQs and moves */
  181. /* VIA1 to level 6. A/UX uses this mapping and we do too. Note */
  182. /* that the IIfx emulates this alternate mapping using the OSS. */
  183. switch(macintosh_config->ident) {
  184. case MAC_MODEL_P475:
  185. case MAC_MODEL_P475F:
  186. case MAC_MODEL_P575:
  187. case MAC_MODEL_Q605:
  188. case MAC_MODEL_Q605_ACC:
  189. case MAC_MODEL_C610:
  190. case MAC_MODEL_Q610:
  191. case MAC_MODEL_Q630:
  192. case MAC_MODEL_C650:
  193. case MAC_MODEL_Q650:
  194. case MAC_MODEL_Q700:
  195. case MAC_MODEL_Q800:
  196. case MAC_MODEL_Q900:
  197. case MAC_MODEL_Q950:
  198. via_alt_mapping = 1;
  199. via1[vDirB] |= 0x40;
  200. via1[vBufB] &= ~0x40;
  201. break;
  202. default:
  203. via_alt_mapping = 0;
  204. break;
  205. }
  206. #else
  207. via_alt_mapping = 0;
  208. #endif
  209. /*
  210. * Now initialize VIA2. For RBV we just kill all interrupts;
  211. * for a regular VIA we also reset the timers and stuff.
  212. */
  213. via2[gIER] = 0x7F;
  214. via2[gIFR] = 0x7F | rbv_clear;
  215. if (!rbv_present) {
  216. via2[vT1LL] = 0;
  217. via2[vT1LH] = 0;
  218. via2[vT1CL] = 0;
  219. via2[vT1CH] = 0;
  220. via2[vT2CL] = 0;
  221. via2[vT2CH] = 0;
  222. via2[vACR] &= 0x3F;
  223. via2[vACR] &= ~0x03; /* disable port A & B latches */
  224. }
  225. /*
  226. * Set vPCR for SCSI interrupts (but not on RBV)
  227. */
  228. if (!rbv_present) {
  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. request_irq(IRQ_MAC_TIMER_1, func, IRQ_FLG_LOCK, "timer", func);
  251. }
  252. /*
  253. * Register the interrupt dispatchers for VIA or RBV machines only.
  254. */
  255. void __init via_register_interrupts(void)
  256. {
  257. if (via_alt_mapping) {
  258. request_irq(IRQ_AUTO_1, via1_irq,
  259. IRQ_FLG_LOCK|IRQ_FLG_FAST, "software",
  260. (void *) via1);
  261. request_irq(IRQ_AUTO_6, via1_irq,
  262. IRQ_FLG_LOCK|IRQ_FLG_FAST, "via1",
  263. (void *) via1);
  264. } else {
  265. request_irq(IRQ_AUTO_1, via1_irq,
  266. IRQ_FLG_LOCK|IRQ_FLG_FAST, "via1",
  267. (void *) via1);
  268. }
  269. request_irq(IRQ_AUTO_2, via2_irq, IRQ_FLG_LOCK|IRQ_FLG_FAST,
  270. "via2", (void *) via2);
  271. if (!psc_present) {
  272. request_irq(IRQ_AUTO_4, mac_scc_dispatch, IRQ_FLG_LOCK,
  273. "scc", mac_scc_dispatch);
  274. }
  275. request_irq(IRQ_MAC_NUBUS, via_nubus_irq, IRQ_FLG_LOCK|IRQ_FLG_FAST,
  276. "nubus", (void *) via2);
  277. }
  278. /*
  279. * Debugging dump, used in various places to see what's going on.
  280. */
  281. void via_debug_dump(void)
  282. {
  283. printk(KERN_DEBUG "VIA1: DDRA = 0x%02X DDRB = 0x%02X ACR = 0x%02X\n",
  284. (uint) via1[vDirA], (uint) via1[vDirB], (uint) via1[vACR]);
  285. printk(KERN_DEBUG " PCR = 0x%02X IFR = 0x%02X IER = 0x%02X\n",
  286. (uint) via1[vPCR], (uint) via1[vIFR], (uint) via1[vIER]);
  287. if (oss_present) {
  288. printk(KERN_DEBUG "VIA2: <OSS>\n");
  289. } else if (rbv_present) {
  290. printk(KERN_DEBUG "VIA2: IFR = 0x%02X IER = 0x%02X\n",
  291. (uint) via2[rIFR], (uint) via2[rIER]);
  292. printk(KERN_DEBUG " SIFR = 0x%02X SIER = 0x%02X\n",
  293. (uint) via2[rSIFR], (uint) via2[rSIER]);
  294. } else {
  295. printk(KERN_DEBUG "VIA2: DDRA = 0x%02X DDRB = 0x%02X ACR = 0x%02X\n",
  296. (uint) via2[vDirA], (uint) via2[vDirB],
  297. (uint) via2[vACR]);
  298. printk(KERN_DEBUG " PCR = 0x%02X IFR = 0x%02X IER = 0x%02X\n",
  299. (uint) via2[vPCR],
  300. (uint) via2[vIFR], (uint) via2[vIER]);
  301. }
  302. }
  303. /*
  304. * This is always executed with interrupts disabled.
  305. *
  306. * TBI: get time offset between scheduling timer ticks
  307. */
  308. unsigned long mac_gettimeoffset (void)
  309. {
  310. unsigned long ticks, offset = 0;
  311. /* read VIA1 timer 2 current value */
  312. ticks = via1[vT1CL] | (via1[vT1CH] << 8);
  313. /* The probability of underflow is less than 2% */
  314. if (ticks > MAC_CLOCK_TICK - MAC_CLOCK_TICK / 50)
  315. /* Check for pending timer interrupt in VIA1 IFR */
  316. if (via1[vIFR] & 0x40) offset = TICK_SIZE;
  317. ticks = MAC_CLOCK_TICK - ticks;
  318. ticks = ticks * 10000L / MAC_CLOCK_TICK;
  319. return ticks + offset;
  320. }
  321. /*
  322. * Flush the L2 cache on Macs that have it by flipping
  323. * the system into 24-bit mode for an instant.
  324. */
  325. void via_flush_cache(void)
  326. {
  327. via2[gBufB] &= ~VIA2B_vMode32;
  328. via2[gBufB] |= VIA2B_vMode32;
  329. }
  330. /*
  331. * Return the status of the L2 cache on a IIci
  332. */
  333. int via_get_cache_disable(void)
  334. {
  335. /* Safeguard against being called accidentally */
  336. if (!via2) {
  337. printk(KERN_ERR "via_get_cache_disable called on a non-VIA machine!\n");
  338. return 1;
  339. }
  340. return (int) via2[gBufB] & VIA2B_vCDis;
  341. }
  342. /*
  343. * Initialize VIA2 for Nubus access
  344. */
  345. void __init via_nubus_init(void)
  346. {
  347. /* unlock nubus transactions */
  348. if ((macintosh_config->adb_type != MAC_ADB_PB1) &&
  349. (macintosh_config->adb_type != MAC_ADB_PB2)) {
  350. /* set the line to be an output on non-RBV machines */
  351. if (!rbv_present)
  352. via2[vDirB] |= 0x02;
  353. /* this seems to be an ADB bit on PMU machines */
  354. /* according to MkLinux. -- jmt */
  355. via2[gBufB] |= 0x02;
  356. }
  357. /* Disable all the slot interrupts (where possible). */
  358. switch (macintosh_config->via_type) {
  359. case MAC_VIA_II:
  360. /* Just make the port A lines inputs. */
  361. switch(macintosh_config->ident) {
  362. case MAC_MODEL_II:
  363. case MAC_MODEL_IIX:
  364. case MAC_MODEL_IICX:
  365. case MAC_MODEL_SE30:
  366. /* The top two bits are RAM size outputs. */
  367. via2[vDirA] &= 0xC0;
  368. break;
  369. default:
  370. via2[vDirA] &= 0x80;
  371. }
  372. break;
  373. case MAC_VIA_IIci:
  374. /* RBV. Disable all the slot interrupts. SIER works like IER. */
  375. via2[rSIER] = 0x7F;
  376. break;
  377. case MAC_VIA_QUADRA:
  378. /* Disable the inactive slot interrupts by making those lines outputs. */
  379. if ((macintosh_config->adb_type != MAC_ADB_PB1) &&
  380. (macintosh_config->adb_type != MAC_ADB_PB2)) {
  381. via2[vBufA] |= 0x7F;
  382. via2[vDirA] |= 0x7F;
  383. }
  384. break;
  385. }
  386. }
  387. /*
  388. * The generic VIA interrupt routines (shamelessly stolen from Alan Cox's
  389. * via6522.c :-), disable/pending masks added.
  390. *
  391. * The new interrupt architecture in macints.c takes care of a lot of the
  392. * gruntwork for us, including tallying the interrupts and calling the
  393. * handlers on the linked list. All we need to do here is basically generate
  394. * the machspec interrupt number after clearing the interrupt.
  395. */
  396. irqreturn_t via1_irq(int irq, void *dev_id)
  397. {
  398. int irq_num;
  399. unsigned char irq_bit, events;
  400. events = via1[vIFR] & via1[vIER] & 0x7F;
  401. if (!events)
  402. return IRQ_NONE;
  403. irq_num = VIA1_SOURCE_BASE;
  404. irq_bit = 1;
  405. do {
  406. if (events & irq_bit) {
  407. via1[vIER] = irq_bit;
  408. via1[vIFR] = irq_bit;
  409. m68k_handle_int(irq_num);
  410. via1[vIER] = irq_bit | 0x80;
  411. }
  412. ++irq_num;
  413. irq_bit <<= 1;
  414. } while (events >= irq_bit);
  415. #if 0 /* freakin' pmu is doing weird stuff */
  416. if (!oss_present) {
  417. /* This (still) seems to be necessary to get IDE
  418. working. However, if you enable VBL interrupts,
  419. you're screwed... */
  420. /* FIXME: should we check the SLOTIRQ bit before
  421. pulling this stunt? */
  422. /* No, it won't be set. that's why we're doing this. */
  423. via_irq_disable(IRQ_MAC_NUBUS);
  424. via_irq_clear(IRQ_MAC_NUBUS);
  425. m68k_handle_int(IRQ_MAC_NUBUS);
  426. via_irq_enable(IRQ_MAC_NUBUS);
  427. }
  428. #endif
  429. return IRQ_HANDLED;
  430. }
  431. irqreturn_t via2_irq(int irq, void *dev_id)
  432. {
  433. int irq_num;
  434. unsigned char irq_bit, events;
  435. events = via2[gIFR] & via2[gIER] & 0x7F;
  436. if (!events)
  437. return IRQ_NONE;
  438. irq_num = VIA2_SOURCE_BASE;
  439. irq_bit = 1;
  440. do {
  441. if (events & irq_bit) {
  442. via2[gIER] = irq_bit;
  443. via2[gIFR] = irq_bit | rbv_clear;
  444. m68k_handle_int(irq_num);
  445. if (irq_num != IRQ_MAC_NUBUS || nubus_disabled == 0)
  446. via2[gIER] = irq_bit | 0x80;
  447. }
  448. ++irq_num;
  449. irq_bit <<= 1;
  450. } while (events >= irq_bit);
  451. return IRQ_HANDLED;
  452. }
  453. /*
  454. * Dispatch Nubus interrupts. We are called as a secondary dispatch by the
  455. * VIA2 dispatcher as a fast interrupt handler.
  456. */
  457. irqreturn_t via_nubus_irq(int irq, void *dev_id)
  458. {
  459. int slot_irq;
  460. unsigned char slot_bit, events;
  461. events = ~via2[gBufA] & 0x7F;
  462. if (rbv_present)
  463. events &= via2[rSIER];
  464. else
  465. events &= ~via2[vDirA];
  466. if (!events)
  467. return IRQ_NONE;
  468. do {
  469. slot_irq = IRQ_NUBUS_F;
  470. slot_bit = 0x40;
  471. do {
  472. if (events & slot_bit) {
  473. events &= ~slot_bit;
  474. m68k_handle_int(slot_irq);
  475. }
  476. --slot_irq;
  477. slot_bit >>= 1;
  478. } while (events);
  479. /* clear the CA1 interrupt and make certain there's no more. */
  480. via2[gIFR] = 0x02 | rbv_clear;
  481. events = ~via2[gBufA] & 0x7F;
  482. if (rbv_present)
  483. events &= via2[rSIER];
  484. else
  485. events &= ~via2[vDirA];
  486. } while (events);
  487. return IRQ_HANDLED;
  488. }
  489. void via_irq_enable(int irq) {
  490. int irq_src = IRQ_SRC(irq);
  491. int irq_idx = IRQ_IDX(irq);
  492. #ifdef DEBUG_IRQUSE
  493. printk(KERN_DEBUG "via_irq_enable(%d)\n", irq);
  494. #endif
  495. if (irq_src == 1) {
  496. via1[vIER] = IER_SET_BIT(irq_idx);
  497. } else if (irq_src == 2) {
  498. if (irq != IRQ_MAC_NUBUS || nubus_disabled == 0)
  499. via2[gIER] = IER_SET_BIT(irq_idx);
  500. } else if (irq_src == 7) {
  501. switch (macintosh_config->via_type) {
  502. case MAC_VIA_II:
  503. nubus_disabled &= ~(1 << irq_idx);
  504. /* Enable the CA1 interrupt when no slot is disabled. */
  505. if (!nubus_disabled)
  506. via2[gIER] = IER_SET_BIT(1);
  507. break;
  508. case MAC_VIA_IIci:
  509. /* On RBV, enable the slot interrupt.
  510. * SIER works like IER.
  511. */
  512. via2[rSIER] = IER_SET_BIT(irq_idx);
  513. break;
  514. case MAC_VIA_QUADRA:
  515. /* Make the port A line an input to enable the slot irq.
  516. * But not on PowerBooks, that's ADB.
  517. */
  518. if ((macintosh_config->adb_type != MAC_ADB_PB1) &&
  519. (macintosh_config->adb_type != MAC_ADB_PB2))
  520. via2[vDirA] &= ~(1 << irq_idx);
  521. break;
  522. }
  523. }
  524. }
  525. void via_irq_disable(int irq) {
  526. int irq_src = IRQ_SRC(irq);
  527. int irq_idx = IRQ_IDX(irq);
  528. #ifdef DEBUG_IRQUSE
  529. printk(KERN_DEBUG "via_irq_disable(%d)\n", irq);
  530. #endif
  531. if (irq_src == 1) {
  532. via1[vIER] = IER_CLR_BIT(irq_idx);
  533. } else if (irq_src == 2) {
  534. via2[gIER] = IER_CLR_BIT(irq_idx);
  535. } else if (irq_src == 7) {
  536. switch (macintosh_config->via_type) {
  537. case MAC_VIA_II:
  538. nubus_disabled |= 1 << irq_idx;
  539. if (nubus_disabled)
  540. via2[gIER] = IER_CLR_BIT(1);
  541. break;
  542. case MAC_VIA_IIci:
  543. via2[rSIER] = IER_CLR_BIT(irq_idx);
  544. break;
  545. case MAC_VIA_QUADRA:
  546. if ((macintosh_config->adb_type != MAC_ADB_PB1) &&
  547. (macintosh_config->adb_type != MAC_ADB_PB2))
  548. via2[vDirA] |= 1 << irq_idx;
  549. break;
  550. }
  551. }
  552. }
  553. void via_irq_clear(int irq) {
  554. int irq_src = IRQ_SRC(irq);
  555. int irq_idx = IRQ_IDX(irq);
  556. int irq_bit = 1 << irq_idx;
  557. if (irq_src == 1) {
  558. via1[vIFR] = irq_bit;
  559. } else if (irq_src == 2) {
  560. via2[gIFR] = irq_bit | rbv_clear;
  561. } else if (irq_src == 7) {
  562. /* FIXME: There is no way to clear an individual nubus slot
  563. * IRQ flag, other than getting the device to do it.
  564. */
  565. }
  566. }
  567. /*
  568. * Returns nonzero if an interrupt is pending on the given
  569. * VIA/IRQ combination.
  570. */
  571. int via_irq_pending(int irq)
  572. {
  573. int irq_src = IRQ_SRC(irq);
  574. int irq_idx = IRQ_IDX(irq);
  575. int irq_bit = 1 << irq_idx;
  576. if (irq_src == 1) {
  577. return via1[vIFR] & irq_bit;
  578. } else if (irq_src == 2) {
  579. return via2[gIFR] & irq_bit;
  580. } else if (irq_src == 7) {
  581. /* Always 0 for MAC_VIA_QUADRA if the slot irq is disabled. */
  582. return ~via2[gBufA] & irq_bit;
  583. }
  584. return 0;
  585. }