via.c 16 KB

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