via.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * 6522 Versatile Interface Adapter (VIA)
  4. *
  5. * There are two of these on the Mac II. Some IRQs are vectored
  6. * via them as are assorted bits and bobs - eg RTC, ADB.
  7. *
  8. * CSA: Motorola seems to have removed documentation on the 6522 from
  9. * their web site; try
  10. * http://nerini.drf.com/vectrex/other/text/chips/6522/
  11. * http://www.zymurgy.net/classic/vic20/vicdet1.htm
  12. * and
  13. * http://193.23.168.87/mikro_laborversuche/via_iobaustein/via6522_1.html
  14. * for info. A full-text web search on 6522 AND VIA will probably also
  15. * net some usefulness. <cananian@alumni.princeton.edu> 20apr1999
  16. *
  17. * Additional data is here (the SY6522 was used in the Mac II etc):
  18. * http://www.6502.org/documents/datasheets/synertek/synertek_sy6522.pdf
  19. * http://www.6502.org/documents/datasheets/synertek/synertek_sy6522_programming_reference.pdf
  20. *
  21. * PRAM/RTC access algorithms are from the NetBSD RTC toolkit version 1.08b
  22. * by Erik Vogan and adapted to Linux by Joshua M. Thompson (funaho@jurai.org)
  23. *
  24. */
  25. #include <linux/types.h>
  26. #include <linux/kernel.h>
  27. #include <linux/mm.h>
  28. #include <linux/delay.h>
  29. #include <linux/init.h>
  30. #include <linux/module.h>
  31. #include <linux/irq.h>
  32. #include <asm/macintosh.h>
  33. #include <asm/macints.h>
  34. #include <asm/mac_via.h>
  35. #include <asm/mac_psc.h>
  36. #include <asm/mac_oss.h>
  37. volatile __u8 *via1, *via2;
  38. int rbv_present;
  39. int via_alt_mapping;
  40. EXPORT_SYMBOL(via_alt_mapping);
  41. static __u8 rbv_clear;
  42. /*
  43. * Globals for accessing the VIA chip registers without having to
  44. * check if we're hitting a real VIA or an RBV. Normally you could
  45. * just hit the combined register (ie, vIER|rIER) but that seems to
  46. * break on AV Macs...probably because they actually decode more than
  47. * eight address bits. Why can't Apple engineers at least be
  48. * _consistently_ lazy? - 1999-05-21 (jmt)
  49. */
  50. static int gIER,gIFR,gBufA,gBufB;
  51. /*
  52. * On Macs with a genuine VIA chip there is no way to mask an individual slot
  53. * interrupt. This limitation also seems to apply to VIA clone logic cores in
  54. * Quadra-like ASICs. (RBV and OSS machines don't have this limitation.)
  55. *
  56. * We used to fake it by configuring the relevant VIA pin as an output
  57. * (to mask the interrupt) or input (to unmask). That scheme did not work on
  58. * (at least) the Quadra 700. A NuBus card's /NMRQ signal is an open-collector
  59. * circuit (see Designing Cards and Drivers for Macintosh II and Macintosh SE,
  60. * p. 10-11 etc) but VIA outputs are not (see datasheet).
  61. *
  62. * Driving these outputs high must cause the VIA to source current and the
  63. * card to sink current when it asserts /NMRQ. Current will flow but the pin
  64. * voltage is uncertain and so the /NMRQ condition may still cause a transition
  65. * at the VIA2 CA1 input (which explains the lost interrupts). A side effect
  66. * is that a disabled slot IRQ can never be tested as pending or not.
  67. *
  68. * Driving these outputs low doesn't work either. All the slot /NMRQ lines are
  69. * (active low) OR'd together to generate the CA1 (aka "SLOTS") interrupt (see
  70. * The Guide To Macintosh Family Hardware, 2nd edition p. 167). If we drive a
  71. * disabled /NMRQ line low, the falling edge immediately triggers a CA1
  72. * interrupt and all slot interrupts after that will generate no transition
  73. * and therefore no interrupt, even after being re-enabled.
  74. *
  75. * So we make the VIA port A I/O lines inputs and use nubus_disabled to keep
  76. * track of their states. When any slot IRQ becomes disabled we mask the CA1
  77. * umbrella interrupt. Only when all slot IRQs become enabled do we unmask
  78. * the CA1 interrupt. It must remain enabled even when cards have no interrupt
  79. * handler registered. Drivers must therefore disable a slot interrupt at the
  80. * device before they call free_irq (like shared and autovector interrupts).
  81. *
  82. * There is also a related problem when MacOS is used to boot Linux. A network
  83. * card brought up by a MacOS driver may raise an interrupt while Linux boots.
  84. * This can be fatal since it can't be handled until the right driver loads
  85. * (if such a driver exists at all). Apparently related to this hardware
  86. * limitation, "Designing Cards and Drivers", p. 9-8, says that a slot
  87. * interrupt with no driver would crash MacOS (the book was written before
  88. * the appearance of Macs with RBV or OSS).
  89. */
  90. static u8 nubus_disabled;
  91. void via_debug_dump(void);
  92. static void via_nubus_init(void);
  93. /*
  94. * Initialize the VIAs
  95. *
  96. * First we figure out where they actually _are_ as well as what type of
  97. * VIA we have for VIA2 (it could be a real VIA or an RBV or even an OSS.)
  98. * Then we pretty much clear them out and disable all IRQ sources.
  99. */
  100. void __init via_init(void)
  101. {
  102. via1 = (void *)VIA1_BASE;
  103. pr_debug("VIA1 detected at %p\n", via1);
  104. if (oss_present) {
  105. via2 = NULL;
  106. rbv_present = 0;
  107. } else {
  108. switch (macintosh_config->via_type) {
  109. /* IIci, IIsi, IIvx, IIvi (P6xx), LC series */
  110. case MAC_VIA_IICI:
  111. via2 = (void *)RBV_BASE;
  112. pr_debug("VIA2 (RBV) detected at %p\n", via2);
  113. rbv_present = 1;
  114. if (macintosh_config->ident == MAC_MODEL_LCIII) {
  115. rbv_clear = 0x00;
  116. } else {
  117. /* on most RBVs (& unlike the VIAs), you */
  118. /* need to set bit 7 when you write to IFR */
  119. /* in order for your clear to occur. */
  120. rbv_clear = 0x80;
  121. }
  122. gIER = rIER;
  123. gIFR = rIFR;
  124. gBufA = rSIFR;
  125. gBufB = rBufB;
  126. break;
  127. /* Quadra and early MacIIs agree on the VIA locations */
  128. case MAC_VIA_QUADRA:
  129. case MAC_VIA_II:
  130. via2 = (void *) VIA2_BASE;
  131. pr_debug("VIA2 detected at %p\n", via2);
  132. rbv_present = 0;
  133. rbv_clear = 0x00;
  134. gIER = vIER;
  135. gIFR = vIFR;
  136. gBufA = vBufA;
  137. gBufB = vBufB;
  138. break;
  139. default:
  140. panic("UNKNOWN VIA TYPE");
  141. }
  142. }
  143. #ifdef DEBUG_VIA
  144. via_debug_dump();
  145. #endif
  146. /*
  147. * Shut down all IRQ sources, reset the timers, and
  148. * kill the timer latch on VIA1.
  149. */
  150. via1[vIER] = 0x7F;
  151. via1[vIFR] = 0x7F;
  152. via1[vT1LL] = 0;
  153. via1[vT1LH] = 0;
  154. via1[vT1CL] = 0;
  155. via1[vT1CH] = 0;
  156. via1[vT2CL] = 0;
  157. via1[vT2CH] = 0;
  158. via1[vACR] &= ~0xC0; /* setup T1 timer with no PB7 output */
  159. via1[vACR] &= ~0x03; /* disable port A & B latches */
  160. /*
  161. * SE/30: disable video IRQ
  162. * XXX: testing for SE/30 VBL
  163. */
  164. if (macintosh_config->ident == MAC_MODEL_SE30) {
  165. via1[vDirB] |= 0x40;
  166. via1[vBufB] |= 0x40;
  167. }
  168. /*
  169. * Set the RTC bits to a known state: all lines to outputs and
  170. * RTC disabled (yes that's 0 to enable and 1 to disable).
  171. */
  172. via1[vDirB] |= (VIA1B_vRTCEnb | VIA1B_vRTCClk | VIA1B_vRTCData);
  173. via1[vBufB] |= (VIA1B_vRTCEnb | VIA1B_vRTCClk);
  174. /* Everything below this point is VIA2/RBV only... */
  175. if (oss_present)
  176. return;
  177. if ((macintosh_config->via_type == MAC_VIA_QUADRA) &&
  178. (macintosh_config->adb_type != MAC_ADB_PB1) &&
  179. (macintosh_config->adb_type != MAC_ADB_PB2) &&
  180. (macintosh_config->ident != MAC_MODEL_C660) &&
  181. (macintosh_config->ident != MAC_MODEL_Q840)) {
  182. via_alt_mapping = 1;
  183. via1[vDirB] |= 0x40;
  184. via1[vBufB] &= ~0x40;
  185. } else {
  186. via_alt_mapping = 0;
  187. }
  188. /*
  189. * Now initialize VIA2. For RBV we just kill all interrupts;
  190. * for a regular VIA we also reset the timers and stuff.
  191. */
  192. via2[gIER] = 0x7F;
  193. via2[gIFR] = 0x7F | rbv_clear;
  194. if (!rbv_present) {
  195. via2[vT1LL] = 0;
  196. via2[vT1LH] = 0;
  197. via2[vT1CL] = 0;
  198. via2[vT1CH] = 0;
  199. via2[vT2CL] = 0;
  200. via2[vT2CH] = 0;
  201. via2[vACR] &= ~0xC0; /* setup T1 timer with no PB7 output */
  202. via2[vACR] &= ~0x03; /* disable port A & B latches */
  203. }
  204. via_nubus_init();
  205. /* Everything below this point is VIA2 only... */
  206. if (rbv_present)
  207. return;
  208. /*
  209. * Set vPCR for control line interrupts.
  210. *
  211. * CA1 (SLOTS IRQ), CB1 (ASC IRQ): negative edge trigger.
  212. *
  213. * Macs with ESP SCSI have a negative edge triggered SCSI interrupt.
  214. * Testing reveals that PowerBooks do too. However, the SE/30
  215. * schematic diagram shows an active high NCR5380 IRQ line.
  216. */
  217. pr_debug("VIA2 vPCR is 0x%02X\n", via2[vPCR]);
  218. if (macintosh_config->via_type == MAC_VIA_II) {
  219. /* CA2 (SCSI DRQ), CB2 (SCSI IRQ): indep. input, pos. edge */
  220. via2[vPCR] = 0x66;
  221. } else {
  222. /* CA2 (SCSI DRQ), CB2 (SCSI IRQ): indep. input, neg. edge */
  223. via2[vPCR] = 0x22;
  224. }
  225. }
  226. /*
  227. * Debugging dump, used in various places to see what's going on.
  228. */
  229. void via_debug_dump(void)
  230. {
  231. printk(KERN_DEBUG "VIA1: DDRA = 0x%02X DDRB = 0x%02X ACR = 0x%02X\n",
  232. (uint) via1[vDirA], (uint) via1[vDirB], (uint) via1[vACR]);
  233. printk(KERN_DEBUG " PCR = 0x%02X IFR = 0x%02X IER = 0x%02X\n",
  234. (uint) via1[vPCR], (uint) via1[vIFR], (uint) via1[vIER]);
  235. if (!via2)
  236. return;
  237. if (rbv_present) {
  238. printk(KERN_DEBUG "VIA2: IFR = 0x%02X IER = 0x%02X\n",
  239. (uint) via2[rIFR], (uint) via2[rIER]);
  240. printk(KERN_DEBUG " SIFR = 0x%02X SIER = 0x%02X\n",
  241. (uint) via2[rSIFR], (uint) via2[rSIER]);
  242. } else {
  243. printk(KERN_DEBUG "VIA2: DDRA = 0x%02X DDRB = 0x%02X ACR = 0x%02X\n",
  244. (uint) via2[vDirA], (uint) via2[vDirB],
  245. (uint) via2[vACR]);
  246. printk(KERN_DEBUG " PCR = 0x%02X IFR = 0x%02X IER = 0x%02X\n",
  247. (uint) via2[vPCR],
  248. (uint) via2[vIFR], (uint) via2[vIER]);
  249. }
  250. }
  251. /*
  252. * Flush the L2 cache on Macs that have it by flipping
  253. * the system into 24-bit mode for an instant.
  254. */
  255. void via_l2_flush(int writeback)
  256. {
  257. unsigned long flags;
  258. local_irq_save(flags);
  259. via2[gBufB] &= ~VIA2B_vMode32;
  260. via2[gBufB] |= VIA2B_vMode32;
  261. local_irq_restore(flags);
  262. }
  263. /*
  264. * Return the status of the L2 cache on a IIci
  265. */
  266. int via_get_cache_disable(void)
  267. {
  268. /* Safeguard against being called accidentally */
  269. if (!via2) {
  270. printk(KERN_ERR "via_get_cache_disable called on a non-VIA machine!\n");
  271. return 1;
  272. }
  273. return (int) via2[gBufB] & VIA2B_vCDis;
  274. }
  275. /*
  276. * Initialize VIA2 for Nubus access
  277. */
  278. static void __init via_nubus_init(void)
  279. {
  280. /* unlock nubus transactions */
  281. if ((macintosh_config->adb_type != MAC_ADB_PB1) &&
  282. (macintosh_config->adb_type != MAC_ADB_PB2)) {
  283. /* set the line to be an output on non-RBV machines */
  284. if (!rbv_present)
  285. via2[vDirB] |= 0x02;
  286. /* this seems to be an ADB bit on PMU machines */
  287. /* according to MkLinux. -- jmt */
  288. via2[gBufB] |= 0x02;
  289. }
  290. /*
  291. * Disable the slot interrupts. On some hardware that's not possible.
  292. * On some hardware it's unclear what all of these I/O lines do.
  293. */
  294. switch (macintosh_config->via_type) {
  295. case MAC_VIA_II:
  296. case MAC_VIA_QUADRA:
  297. pr_debug("VIA2 vDirA is 0x%02X\n", via2[vDirA]);
  298. break;
  299. case MAC_VIA_IICI:
  300. /* RBV. Disable all the slot interrupts. SIER works like IER. */
  301. via2[rSIER] = 0x7F;
  302. break;
  303. }
  304. }
  305. void via_nubus_irq_startup(int irq)
  306. {
  307. int irq_idx = IRQ_IDX(irq);
  308. switch (macintosh_config->via_type) {
  309. case MAC_VIA_II:
  310. case MAC_VIA_QUADRA:
  311. /* Make the port A line an input. Probably redundant. */
  312. if (macintosh_config->via_type == MAC_VIA_II) {
  313. /* The top two bits are RAM size outputs. */
  314. via2[vDirA] &= 0xC0 | ~(1 << irq_idx);
  315. } else {
  316. /* Allow NuBus slots 9 through F. */
  317. via2[vDirA] &= 0x80 | ~(1 << irq_idx);
  318. }
  319. /* fall through */
  320. case MAC_VIA_IICI:
  321. via_irq_enable(irq);
  322. break;
  323. }
  324. }
  325. void via_nubus_irq_shutdown(int irq)
  326. {
  327. switch (macintosh_config->via_type) {
  328. case MAC_VIA_II:
  329. case MAC_VIA_QUADRA:
  330. /* Ensure that the umbrella CA1 interrupt remains enabled. */
  331. via_irq_enable(irq);
  332. break;
  333. case MAC_VIA_IICI:
  334. via_irq_disable(irq);
  335. break;
  336. }
  337. }
  338. /*
  339. * The generic VIA interrupt routines (shamelessly stolen from Alan Cox's
  340. * via6522.c :-), disable/pending masks added.
  341. */
  342. #define VIA_TIMER_1_INT BIT(6)
  343. void via1_irq(struct irq_desc *desc)
  344. {
  345. int irq_num;
  346. unsigned char irq_bit, events;
  347. events = via1[vIFR] & via1[vIER] & 0x7F;
  348. if (!events)
  349. return;
  350. irq_num = IRQ_MAC_TIMER_1;
  351. irq_bit = VIA_TIMER_1_INT;
  352. if (events & irq_bit) {
  353. unsigned long flags;
  354. local_irq_save(flags);
  355. via1[vIFR] = irq_bit;
  356. generic_handle_irq(irq_num);
  357. local_irq_restore(flags);
  358. events &= ~irq_bit;
  359. if (!events)
  360. return;
  361. }
  362. irq_num = VIA1_SOURCE_BASE;
  363. irq_bit = 1;
  364. do {
  365. if (events & irq_bit) {
  366. via1[vIFR] = irq_bit;
  367. generic_handle_irq(irq_num);
  368. }
  369. ++irq_num;
  370. irq_bit <<= 1;
  371. } while (events >= irq_bit);
  372. }
  373. static void via2_irq(struct irq_desc *desc)
  374. {
  375. int irq_num;
  376. unsigned char irq_bit, events;
  377. events = via2[gIFR] & via2[gIER] & 0x7F;
  378. if (!events)
  379. return;
  380. irq_num = VIA2_SOURCE_BASE;
  381. irq_bit = 1;
  382. do {
  383. if (events & irq_bit) {
  384. via2[gIFR] = irq_bit | rbv_clear;
  385. generic_handle_irq(irq_num);
  386. }
  387. ++irq_num;
  388. irq_bit <<= 1;
  389. } while (events >= irq_bit);
  390. }
  391. /*
  392. * Dispatch Nubus interrupts. We are called as a secondary dispatch by the
  393. * VIA2 dispatcher as a fast interrupt handler.
  394. */
  395. static void via_nubus_irq(struct irq_desc *desc)
  396. {
  397. int slot_irq;
  398. unsigned char slot_bit, events;
  399. events = ~via2[gBufA] & 0x7F;
  400. if (rbv_present)
  401. events &= via2[rSIER];
  402. else
  403. events &= ~via2[vDirA];
  404. if (!events)
  405. return;
  406. do {
  407. slot_irq = IRQ_NUBUS_F;
  408. slot_bit = 0x40;
  409. do {
  410. if (events & slot_bit) {
  411. events &= ~slot_bit;
  412. generic_handle_irq(slot_irq);
  413. }
  414. --slot_irq;
  415. slot_bit >>= 1;
  416. } while (events);
  417. /* clear the CA1 interrupt and make certain there's no more. */
  418. via2[gIFR] = 0x02 | rbv_clear;
  419. events = ~via2[gBufA] & 0x7F;
  420. if (rbv_present)
  421. events &= via2[rSIER];
  422. else
  423. events &= ~via2[vDirA];
  424. } while (events);
  425. }
  426. /*
  427. * Register the interrupt dispatchers for VIA or RBV machines only.
  428. */
  429. void __init via_register_interrupts(void)
  430. {
  431. if (via_alt_mapping) {
  432. /* software interrupt */
  433. irq_set_chained_handler(IRQ_AUTO_1, via1_irq);
  434. /* via1 interrupt */
  435. irq_set_chained_handler(IRQ_AUTO_6, via1_irq);
  436. } else {
  437. irq_set_chained_handler(IRQ_AUTO_1, via1_irq);
  438. }
  439. irq_set_chained_handler(IRQ_AUTO_2, via2_irq);
  440. irq_set_chained_handler(IRQ_MAC_NUBUS, via_nubus_irq);
  441. }
  442. void via_irq_enable(int irq) {
  443. int irq_src = IRQ_SRC(irq);
  444. int irq_idx = IRQ_IDX(irq);
  445. if (irq_src == 1) {
  446. via1[vIER] = IER_SET_BIT(irq_idx);
  447. } else if (irq_src == 2) {
  448. if (irq != IRQ_MAC_NUBUS || nubus_disabled == 0)
  449. via2[gIER] = IER_SET_BIT(irq_idx);
  450. } else if (irq_src == 7) {
  451. switch (macintosh_config->via_type) {
  452. case MAC_VIA_II:
  453. case MAC_VIA_QUADRA:
  454. nubus_disabled &= ~(1 << irq_idx);
  455. /* Enable the CA1 interrupt when no slot is disabled. */
  456. if (!nubus_disabled)
  457. via2[gIER] = IER_SET_BIT(1);
  458. break;
  459. case MAC_VIA_IICI:
  460. /* On RBV, enable the slot interrupt.
  461. * SIER works like IER.
  462. */
  463. via2[rSIER] = IER_SET_BIT(irq_idx);
  464. break;
  465. }
  466. }
  467. }
  468. void via_irq_disable(int irq) {
  469. int irq_src = IRQ_SRC(irq);
  470. int irq_idx = IRQ_IDX(irq);
  471. if (irq_src == 1) {
  472. via1[vIER] = IER_CLR_BIT(irq_idx);
  473. } else if (irq_src == 2) {
  474. via2[gIER] = IER_CLR_BIT(irq_idx);
  475. } else if (irq_src == 7) {
  476. switch (macintosh_config->via_type) {
  477. case MAC_VIA_II:
  478. case MAC_VIA_QUADRA:
  479. nubus_disabled |= 1 << irq_idx;
  480. if (nubus_disabled)
  481. via2[gIER] = IER_CLR_BIT(1);
  482. break;
  483. case MAC_VIA_IICI:
  484. via2[rSIER] = IER_CLR_BIT(irq_idx);
  485. break;
  486. }
  487. }
  488. }
  489. void via1_set_head(int head)
  490. {
  491. if (head == 0)
  492. via1[vBufA] &= ~VIA1A_vHeadSel;
  493. else
  494. via1[vBufA] |= VIA1A_vHeadSel;
  495. }
  496. EXPORT_SYMBOL(via1_set_head);
  497. int via2_scsi_drq_pending(void)
  498. {
  499. return via2[gIFR] & (1 << IRQ_IDX(IRQ_MAC_SCSIDRQ));
  500. }
  501. EXPORT_SYMBOL(via2_scsi_drq_pending);
  502. /* timer and clock source */
  503. #define VIA_CLOCK_FREQ 783360 /* VIA "phase 2" clock in Hz */
  504. #define VIA_TIMER_INTERVAL (1000000 / HZ) /* microseconds per jiffy */
  505. #define VIA_TIMER_CYCLES (VIA_CLOCK_FREQ / HZ) /* clock cycles per jiffy */
  506. #define VIA_TC (VIA_TIMER_CYCLES - 2) /* including 0 and -1 */
  507. #define VIA_TC_LOW (VIA_TC & 0xFF)
  508. #define VIA_TC_HIGH (VIA_TC >> 8)
  509. void __init via_init_clock(irq_handler_t timer_routine)
  510. {
  511. if (request_irq(IRQ_MAC_TIMER_1, timer_routine, 0, "timer", NULL)) {
  512. pr_err("Couldn't register %s interrupt\n", "timer");
  513. return;
  514. }
  515. via1[vT1LL] = VIA_TC_LOW;
  516. via1[vT1LH] = VIA_TC_HIGH;
  517. via1[vT1CL] = VIA_TC_LOW;
  518. via1[vT1CH] = VIA_TC_HIGH;
  519. via1[vACR] |= 0x40;
  520. }
  521. u32 mac_gettimeoffset(void)
  522. {
  523. unsigned long flags;
  524. u8 count_high;
  525. u16 count, offset = 0;
  526. /*
  527. * Timer counter wrap-around is detected with the timer interrupt flag
  528. * but reading the counter low byte (vT1CL) would reset the flag.
  529. * Also, accessing both counter registers is essentially a data race.
  530. * These problems are avoided by ignoring the low byte. Clock accuracy
  531. * is 256 times worse (error can reach 0.327 ms) but CPU overhead is
  532. * reduced by avoiding slow VIA register accesses.
  533. */
  534. local_irq_save(flags);
  535. count_high = via1[vT1CH];
  536. if (count_high == 0xFF)
  537. count_high = 0;
  538. if (count_high > 0 && (via1[vIFR] & VIA_TIMER_1_INT))
  539. offset = VIA_TIMER_CYCLES;
  540. local_irq_restore(flags);
  541. count = count_high << 8;
  542. count = VIA_TIMER_CYCLES - count + offset;
  543. return ((count * VIA_TIMER_INTERVAL) / VIA_TIMER_CYCLES) * 1000;
  544. }