via.c 17 KB

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