hpet.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716
  1. #include <linux/clocksource.h>
  2. #include <linux/clockchips.h>
  3. #include <linux/delay.h>
  4. #include <linux/errno.h>
  5. #include <linux/hpet.h>
  6. #include <linux/init.h>
  7. #include <linux/sysdev.h>
  8. #include <linux/pm.h>
  9. #include <asm/fixmap.h>
  10. #include <asm/hpet.h>
  11. #include <asm/i8253.h>
  12. #include <asm/io.h>
  13. #define HPET_MASK CLOCKSOURCE_MASK(32)
  14. #define HPET_SHIFT 22
  15. /* FSEC = 10^-15
  16. NSEC = 10^-9 */
  17. #define FSEC_PER_NSEC 1000000
  18. /*
  19. * HPET address is set in acpi/boot.c, when an ACPI entry exists
  20. */
  21. unsigned long hpet_address;
  22. static void __iomem *hpet_virt_address;
  23. unsigned long hpet_readl(unsigned long a)
  24. {
  25. return readl(hpet_virt_address + a);
  26. }
  27. static inline void hpet_writel(unsigned long d, unsigned long a)
  28. {
  29. writel(d, hpet_virt_address + a);
  30. }
  31. #ifdef CONFIG_X86_64
  32. #include <asm/pgtable.h>
  33. static inline void hpet_set_mapping(void)
  34. {
  35. set_fixmap_nocache(FIX_HPET_BASE, hpet_address);
  36. __set_fixmap(VSYSCALL_HPET, hpet_address, PAGE_KERNEL_VSYSCALL_NOCACHE);
  37. hpet_virt_address = (void __iomem *)fix_to_virt(FIX_HPET_BASE);
  38. }
  39. static inline void hpet_clear_mapping(void)
  40. {
  41. hpet_virt_address = NULL;
  42. }
  43. #else
  44. static inline void hpet_set_mapping(void)
  45. {
  46. hpet_virt_address = ioremap_nocache(hpet_address, HPET_MMAP_SIZE);
  47. }
  48. static inline void hpet_clear_mapping(void)
  49. {
  50. iounmap(hpet_virt_address);
  51. hpet_virt_address = NULL;
  52. }
  53. #endif
  54. /*
  55. * HPET command line enable / disable
  56. */
  57. static int boot_hpet_disable;
  58. int hpet_force_user;
  59. static int __init hpet_setup(char* str)
  60. {
  61. if (str) {
  62. if (!strncmp("disable", str, 7))
  63. boot_hpet_disable = 1;
  64. if (!strncmp("force", str, 5))
  65. hpet_force_user = 1;
  66. }
  67. return 1;
  68. }
  69. __setup("hpet=", hpet_setup);
  70. static int __init disable_hpet(char *str)
  71. {
  72. boot_hpet_disable = 1;
  73. return 1;
  74. }
  75. __setup("nohpet", disable_hpet);
  76. static inline int is_hpet_capable(void)
  77. {
  78. return (!boot_hpet_disable && hpet_address);
  79. }
  80. /*
  81. * HPET timer interrupt enable / disable
  82. */
  83. static int hpet_legacy_int_enabled;
  84. /**
  85. * is_hpet_enabled - check whether the hpet timer interrupt is enabled
  86. */
  87. int is_hpet_enabled(void)
  88. {
  89. return is_hpet_capable() && hpet_legacy_int_enabled;
  90. }
  91. EXPORT_SYMBOL_GPL(is_hpet_enabled);
  92. /*
  93. * When the hpet driver (/dev/hpet) is enabled, we need to reserve
  94. * timer 0 and timer 1 in case of RTC emulation.
  95. */
  96. #ifdef CONFIG_HPET
  97. static void hpet_reserve_platform_timers(unsigned long id)
  98. {
  99. struct hpet __iomem *hpet = hpet_virt_address;
  100. struct hpet_timer __iomem *timer = &hpet->hpet_timers[2];
  101. unsigned int nrtimers, i;
  102. struct hpet_data hd;
  103. nrtimers = ((id & HPET_ID_NUMBER) >> HPET_ID_NUMBER_SHIFT) + 1;
  104. memset(&hd, 0, sizeof (hd));
  105. hd.hd_phys_address = hpet_address;
  106. hd.hd_address = hpet;
  107. hd.hd_nirqs = nrtimers;
  108. hd.hd_flags = HPET_DATA_PLATFORM;
  109. hpet_reserve_timer(&hd, 0);
  110. #ifdef CONFIG_HPET_EMULATE_RTC
  111. hpet_reserve_timer(&hd, 1);
  112. #endif
  113. hd.hd_irq[0] = HPET_LEGACY_8254;
  114. hd.hd_irq[1] = HPET_LEGACY_RTC;
  115. for (i = 2; i < nrtimers; timer++, i++) {
  116. hd.hd_irq[i] = (readl(&timer->hpet_config) & Tn_INT_ROUTE_CNF_MASK) >>
  117. Tn_INT_ROUTE_CNF_SHIFT;
  118. }
  119. hpet_alloc(&hd);
  120. }
  121. #else
  122. static void hpet_reserve_platform_timers(unsigned long id) { }
  123. #endif
  124. /*
  125. * Common hpet info
  126. */
  127. static unsigned long hpet_period;
  128. static void hpet_legacy_set_mode(enum clock_event_mode mode,
  129. struct clock_event_device *evt);
  130. static int hpet_legacy_next_event(unsigned long delta,
  131. struct clock_event_device *evt);
  132. /*
  133. * The hpet clock event device
  134. */
  135. static struct clock_event_device hpet_clockevent = {
  136. .name = "hpet",
  137. .features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT,
  138. .set_mode = hpet_legacy_set_mode,
  139. .set_next_event = hpet_legacy_next_event,
  140. .shift = 32,
  141. .irq = 0,
  142. .rating = 50,
  143. };
  144. static void hpet_start_counter(void)
  145. {
  146. unsigned long cfg = hpet_readl(HPET_CFG);
  147. cfg &= ~HPET_CFG_ENABLE;
  148. hpet_writel(cfg, HPET_CFG);
  149. hpet_writel(0, HPET_COUNTER);
  150. hpet_writel(0, HPET_COUNTER + 4);
  151. cfg |= HPET_CFG_ENABLE;
  152. hpet_writel(cfg, HPET_CFG);
  153. }
  154. static void hpet_resume_device(void)
  155. {
  156. force_hpet_resume();
  157. }
  158. static void hpet_restart_counter(void)
  159. {
  160. hpet_resume_device();
  161. hpet_start_counter();
  162. }
  163. static void hpet_enable_legacy_int(void)
  164. {
  165. unsigned long cfg = hpet_readl(HPET_CFG);
  166. cfg |= HPET_CFG_LEGACY;
  167. hpet_writel(cfg, HPET_CFG);
  168. hpet_legacy_int_enabled = 1;
  169. }
  170. static void hpet_legacy_clockevent_register(void)
  171. {
  172. uint64_t hpet_freq;
  173. /* Start HPET legacy interrupts */
  174. hpet_enable_legacy_int();
  175. /*
  176. * The period is a femto seconds value. We need to calculate the
  177. * scaled math multiplication factor for nanosecond to hpet tick
  178. * conversion.
  179. */
  180. hpet_freq = 1000000000000000ULL;
  181. do_div(hpet_freq, hpet_period);
  182. hpet_clockevent.mult = div_sc((unsigned long) hpet_freq,
  183. NSEC_PER_SEC, hpet_clockevent.shift);
  184. /* Calculate the min / max delta */
  185. hpet_clockevent.max_delta_ns = clockevent_delta2ns(0x7FFFFFFF,
  186. &hpet_clockevent);
  187. hpet_clockevent.min_delta_ns = clockevent_delta2ns(0x30,
  188. &hpet_clockevent);
  189. /*
  190. * Start hpet with the boot cpu mask and make it
  191. * global after the IO_APIC has been initialized.
  192. */
  193. hpet_clockevent.cpumask = cpumask_of_cpu(smp_processor_id());
  194. clockevents_register_device(&hpet_clockevent);
  195. global_clock_event = &hpet_clockevent;
  196. printk(KERN_DEBUG "hpet clockevent registered\n");
  197. }
  198. static void hpet_legacy_set_mode(enum clock_event_mode mode,
  199. struct clock_event_device *evt)
  200. {
  201. unsigned long cfg, cmp, now;
  202. uint64_t delta;
  203. switch(mode) {
  204. case CLOCK_EVT_MODE_PERIODIC:
  205. delta = ((uint64_t)(NSEC_PER_SEC/HZ)) * hpet_clockevent.mult;
  206. delta >>= hpet_clockevent.shift;
  207. now = hpet_readl(HPET_COUNTER);
  208. cmp = now + (unsigned long) delta;
  209. cfg = hpet_readl(HPET_T0_CFG);
  210. cfg |= HPET_TN_ENABLE | HPET_TN_PERIODIC |
  211. HPET_TN_SETVAL | HPET_TN_32BIT;
  212. hpet_writel(cfg, HPET_T0_CFG);
  213. /*
  214. * The first write after writing TN_SETVAL to the
  215. * config register sets the counter value, the second
  216. * write sets the period.
  217. */
  218. hpet_writel(cmp, HPET_T0_CMP);
  219. udelay(1);
  220. hpet_writel((unsigned long) delta, HPET_T0_CMP);
  221. break;
  222. case CLOCK_EVT_MODE_ONESHOT:
  223. cfg = hpet_readl(HPET_T0_CFG);
  224. cfg &= ~HPET_TN_PERIODIC;
  225. cfg |= HPET_TN_ENABLE | HPET_TN_32BIT;
  226. hpet_writel(cfg, HPET_T0_CFG);
  227. break;
  228. case CLOCK_EVT_MODE_UNUSED:
  229. case CLOCK_EVT_MODE_SHUTDOWN:
  230. cfg = hpet_readl(HPET_T0_CFG);
  231. cfg &= ~HPET_TN_ENABLE;
  232. hpet_writel(cfg, HPET_T0_CFG);
  233. break;
  234. case CLOCK_EVT_MODE_RESUME:
  235. hpet_enable_legacy_int();
  236. break;
  237. }
  238. }
  239. static int hpet_legacy_next_event(unsigned long delta,
  240. struct clock_event_device *evt)
  241. {
  242. unsigned long cnt;
  243. cnt = hpet_readl(HPET_COUNTER);
  244. cnt += delta;
  245. hpet_writel(cnt, HPET_T0_CMP);
  246. return ((long)(hpet_readl(HPET_COUNTER) - cnt ) > 0) ? -ETIME : 0;
  247. }
  248. /*
  249. * Clock source related code
  250. */
  251. static cycle_t read_hpet(void)
  252. {
  253. return (cycle_t)hpet_readl(HPET_COUNTER);
  254. }
  255. #ifdef CONFIG_X86_64
  256. static cycle_t __vsyscall_fn vread_hpet(void)
  257. {
  258. return readl((const void __iomem *)fix_to_virt(VSYSCALL_HPET) + 0xf0);
  259. }
  260. #endif
  261. static struct clocksource clocksource_hpet = {
  262. .name = "hpet",
  263. .rating = 250,
  264. .read = read_hpet,
  265. .mask = HPET_MASK,
  266. .shift = HPET_SHIFT,
  267. .flags = CLOCK_SOURCE_IS_CONTINUOUS,
  268. .resume = hpet_restart_counter,
  269. #ifdef CONFIG_X86_64
  270. .vread = vread_hpet,
  271. #endif
  272. };
  273. static int hpet_clocksource_register(void)
  274. {
  275. u64 tmp, start, now;
  276. cycle_t t1;
  277. /* Start the counter */
  278. hpet_start_counter();
  279. /* Verify whether hpet counter works */
  280. t1 = read_hpet();
  281. rdtscll(start);
  282. /*
  283. * We don't know the TSC frequency yet, but waiting for
  284. * 200000 TSC cycles is safe:
  285. * 4 GHz == 50us
  286. * 1 GHz == 200us
  287. */
  288. do {
  289. rep_nop();
  290. rdtscll(now);
  291. } while ((now - start) < 200000UL);
  292. if (t1 == read_hpet()) {
  293. printk(KERN_WARNING
  294. "HPET counter not counting. HPET disabled\n");
  295. return -ENODEV;
  296. }
  297. /* Initialize and register HPET clocksource
  298. *
  299. * hpet period is in femto seconds per cycle
  300. * so we need to convert this to ns/cyc units
  301. * approximated by mult/2^shift
  302. *
  303. * fsec/cyc * 1nsec/1000000fsec = nsec/cyc = mult/2^shift
  304. * fsec/cyc * 1ns/1000000fsec * 2^shift = mult
  305. * fsec/cyc * 2^shift * 1nsec/1000000fsec = mult
  306. * (fsec/cyc << shift)/1000000 = mult
  307. * (hpet_period << shift)/FSEC_PER_NSEC = mult
  308. */
  309. tmp = (u64)hpet_period << HPET_SHIFT;
  310. do_div(tmp, FSEC_PER_NSEC);
  311. clocksource_hpet.mult = (u32)tmp;
  312. clocksource_register(&clocksource_hpet);
  313. return 0;
  314. }
  315. /**
  316. * hpet_enable - Try to setup the HPET timer. Returns 1 on success.
  317. */
  318. int __init hpet_enable(void)
  319. {
  320. unsigned long id;
  321. if (!is_hpet_capable())
  322. return 0;
  323. hpet_set_mapping();
  324. /*
  325. * Read the period and check for a sane value:
  326. */
  327. hpet_period = hpet_readl(HPET_PERIOD);
  328. if (hpet_period < HPET_MIN_PERIOD || hpet_period > HPET_MAX_PERIOD)
  329. goto out_nohpet;
  330. /*
  331. * Read the HPET ID register to retrieve the IRQ routing
  332. * information and the number of channels
  333. */
  334. id = hpet_readl(HPET_ID);
  335. #ifdef CONFIG_HPET_EMULATE_RTC
  336. /*
  337. * The legacy routing mode needs at least two channels, tick timer
  338. * and the rtc emulation channel.
  339. */
  340. if (!(id & HPET_ID_NUMBER))
  341. goto out_nohpet;
  342. #endif
  343. if (hpet_clocksource_register())
  344. goto out_nohpet;
  345. if (id & HPET_ID_LEGSUP) {
  346. hpet_legacy_clockevent_register();
  347. return 1;
  348. }
  349. return 0;
  350. out_nohpet:
  351. hpet_clear_mapping();
  352. boot_hpet_disable = 1;
  353. return 0;
  354. }
  355. /*
  356. * Needs to be late, as the reserve_timer code calls kalloc !
  357. *
  358. * Not a problem on i386 as hpet_enable is called from late_time_init,
  359. * but on x86_64 it is necessary !
  360. */
  361. static __init int hpet_late_init(void)
  362. {
  363. if (boot_hpet_disable)
  364. return -ENODEV;
  365. if (!hpet_address) {
  366. if (!force_hpet_address)
  367. return -ENODEV;
  368. hpet_address = force_hpet_address;
  369. hpet_enable();
  370. if (!hpet_virt_address)
  371. return -ENODEV;
  372. }
  373. hpet_reserve_platform_timers(hpet_readl(HPET_ID));
  374. return 0;
  375. }
  376. fs_initcall(hpet_late_init);
  377. void hpet_disable(void)
  378. {
  379. if (is_hpet_capable()) {
  380. unsigned long cfg = hpet_readl(HPET_CFG);
  381. if (hpet_legacy_int_enabled) {
  382. cfg &= ~HPET_CFG_LEGACY;
  383. hpet_legacy_int_enabled = 0;
  384. }
  385. cfg &= ~HPET_CFG_ENABLE;
  386. hpet_writel(cfg, HPET_CFG);
  387. }
  388. }
  389. #ifdef CONFIG_HPET_EMULATE_RTC
  390. /* HPET in LegacyReplacement Mode eats up RTC interrupt line. When, HPET
  391. * is enabled, we support RTC interrupt functionality in software.
  392. * RTC has 3 kinds of interrupts:
  393. * 1) Update Interrupt - generate an interrupt, every sec, when RTC clock
  394. * is updated
  395. * 2) Alarm Interrupt - generate an interrupt at a specific time of day
  396. * 3) Periodic Interrupt - generate periodic interrupt, with frequencies
  397. * 2Hz-8192Hz (2Hz-64Hz for non-root user) (all freqs in powers of 2)
  398. * (1) and (2) above are implemented using polling at a frequency of
  399. * 64 Hz. The exact frequency is a tradeoff between accuracy and interrupt
  400. * overhead. (DEFAULT_RTC_INT_FREQ)
  401. * For (3), we use interrupts at 64Hz or user specified periodic
  402. * frequency, whichever is higher.
  403. */
  404. #include <linux/mc146818rtc.h>
  405. #include <linux/rtc.h>
  406. #include <asm/rtc.h>
  407. #define DEFAULT_RTC_INT_FREQ 64
  408. #define DEFAULT_RTC_SHIFT 6
  409. #define RTC_NUM_INTS 1
  410. static unsigned long hpet_rtc_flags;
  411. static unsigned long hpet_prev_update_sec;
  412. static struct rtc_time hpet_alarm_time;
  413. static unsigned long hpet_pie_count;
  414. static unsigned long hpet_t1_cmp;
  415. static unsigned long hpet_default_delta;
  416. static unsigned long hpet_pie_delta;
  417. static unsigned long hpet_pie_limit;
  418. static rtc_irq_handler irq_handler;
  419. /*
  420. * Registers a IRQ handler.
  421. */
  422. int hpet_register_irq_handler(rtc_irq_handler handler)
  423. {
  424. if (!is_hpet_enabled())
  425. return -ENODEV;
  426. if (irq_handler)
  427. return -EBUSY;
  428. irq_handler = handler;
  429. return 0;
  430. }
  431. EXPORT_SYMBOL_GPL(hpet_register_irq_handler);
  432. /*
  433. * Deregisters the IRQ handler registered with hpet_register_irq_handler()
  434. * and does cleanup.
  435. */
  436. void hpet_unregister_irq_handler(rtc_irq_handler handler)
  437. {
  438. if (!is_hpet_enabled())
  439. return;
  440. irq_handler = NULL;
  441. hpet_rtc_flags = 0;
  442. }
  443. EXPORT_SYMBOL_GPL(hpet_unregister_irq_handler);
  444. /*
  445. * Timer 1 for RTC emulation. We use one shot mode, as periodic mode
  446. * is not supported by all HPET implementations for timer 1.
  447. *
  448. * hpet_rtc_timer_init() is called when the rtc is initialized.
  449. */
  450. int hpet_rtc_timer_init(void)
  451. {
  452. unsigned long cfg, cnt, delta, flags;
  453. if (!is_hpet_enabled())
  454. return 0;
  455. if (!hpet_default_delta) {
  456. uint64_t clc;
  457. clc = (uint64_t) hpet_clockevent.mult * NSEC_PER_SEC;
  458. clc >>= hpet_clockevent.shift + DEFAULT_RTC_SHIFT;
  459. hpet_default_delta = (unsigned long) clc;
  460. }
  461. if (!(hpet_rtc_flags & RTC_PIE) || hpet_pie_limit)
  462. delta = hpet_default_delta;
  463. else
  464. delta = hpet_pie_delta;
  465. local_irq_save(flags);
  466. cnt = delta + hpet_readl(HPET_COUNTER);
  467. hpet_writel(cnt, HPET_T1_CMP);
  468. hpet_t1_cmp = cnt;
  469. cfg = hpet_readl(HPET_T1_CFG);
  470. cfg &= ~HPET_TN_PERIODIC;
  471. cfg |= HPET_TN_ENABLE | HPET_TN_32BIT;
  472. hpet_writel(cfg, HPET_T1_CFG);
  473. local_irq_restore(flags);
  474. return 1;
  475. }
  476. EXPORT_SYMBOL_GPL(hpet_rtc_timer_init);
  477. /*
  478. * The functions below are called from rtc driver.
  479. * Return 0 if HPET is not being used.
  480. * Otherwise do the necessary changes and return 1.
  481. */
  482. int hpet_mask_rtc_irq_bit(unsigned long bit_mask)
  483. {
  484. if (!is_hpet_enabled())
  485. return 0;
  486. hpet_rtc_flags &= ~bit_mask;
  487. return 1;
  488. }
  489. EXPORT_SYMBOL_GPL(hpet_mask_rtc_irq_bit);
  490. int hpet_set_rtc_irq_bit(unsigned long bit_mask)
  491. {
  492. unsigned long oldbits = hpet_rtc_flags;
  493. if (!is_hpet_enabled())
  494. return 0;
  495. hpet_rtc_flags |= bit_mask;
  496. if (!oldbits)
  497. hpet_rtc_timer_init();
  498. return 1;
  499. }
  500. EXPORT_SYMBOL_GPL(hpet_set_rtc_irq_bit);
  501. int hpet_set_alarm_time(unsigned char hrs, unsigned char min,
  502. unsigned char sec)
  503. {
  504. if (!is_hpet_enabled())
  505. return 0;
  506. hpet_alarm_time.tm_hour = hrs;
  507. hpet_alarm_time.tm_min = min;
  508. hpet_alarm_time.tm_sec = sec;
  509. return 1;
  510. }
  511. EXPORT_SYMBOL_GPL(hpet_set_alarm_time);
  512. int hpet_set_periodic_freq(unsigned long freq)
  513. {
  514. uint64_t clc;
  515. if (!is_hpet_enabled())
  516. return 0;
  517. if (freq <= DEFAULT_RTC_INT_FREQ)
  518. hpet_pie_limit = DEFAULT_RTC_INT_FREQ / freq;
  519. else {
  520. clc = (uint64_t) hpet_clockevent.mult * NSEC_PER_SEC;
  521. do_div(clc, freq);
  522. clc >>= hpet_clockevent.shift;
  523. hpet_pie_delta = (unsigned long) clc;
  524. }
  525. return 1;
  526. }
  527. EXPORT_SYMBOL_GPL(hpet_set_periodic_freq);
  528. int hpet_rtc_dropped_irq(void)
  529. {
  530. return is_hpet_enabled();
  531. }
  532. EXPORT_SYMBOL_GPL(hpet_rtc_dropped_irq);
  533. static void hpet_rtc_timer_reinit(void)
  534. {
  535. unsigned long cfg, delta;
  536. int lost_ints = -1;
  537. if (unlikely(!hpet_rtc_flags)) {
  538. cfg = hpet_readl(HPET_T1_CFG);
  539. cfg &= ~HPET_TN_ENABLE;
  540. hpet_writel(cfg, HPET_T1_CFG);
  541. return;
  542. }
  543. if (!(hpet_rtc_flags & RTC_PIE) || hpet_pie_limit)
  544. delta = hpet_default_delta;
  545. else
  546. delta = hpet_pie_delta;
  547. /*
  548. * Increment the comparator value until we are ahead of the
  549. * current count.
  550. */
  551. do {
  552. hpet_t1_cmp += delta;
  553. hpet_writel(hpet_t1_cmp, HPET_T1_CMP);
  554. lost_ints++;
  555. } while ((long)(hpet_readl(HPET_COUNTER) - hpet_t1_cmp) > 0);
  556. if (lost_ints) {
  557. if (hpet_rtc_flags & RTC_PIE)
  558. hpet_pie_count += lost_ints;
  559. if (printk_ratelimit())
  560. printk(KERN_WARNING "rtc: lost %d interrupts\n",
  561. lost_ints);
  562. }
  563. }
  564. irqreturn_t hpet_rtc_interrupt(int irq, void *dev_id)
  565. {
  566. struct rtc_time curr_time;
  567. unsigned long rtc_int_flag = 0;
  568. hpet_rtc_timer_reinit();
  569. memset(&curr_time, 0, sizeof(struct rtc_time));
  570. if (hpet_rtc_flags & (RTC_UIE | RTC_AIE))
  571. get_rtc_time(&curr_time);
  572. if (hpet_rtc_flags & RTC_UIE &&
  573. curr_time.tm_sec != hpet_prev_update_sec) {
  574. rtc_int_flag = RTC_UF;
  575. hpet_prev_update_sec = curr_time.tm_sec;
  576. }
  577. if (hpet_rtc_flags & RTC_PIE &&
  578. ++hpet_pie_count >= hpet_pie_limit) {
  579. rtc_int_flag |= RTC_PF;
  580. hpet_pie_count = 0;
  581. }
  582. if (hpet_rtc_flags & RTC_AIE &&
  583. (curr_time.tm_sec == hpet_alarm_time.tm_sec) &&
  584. (curr_time.tm_min == hpet_alarm_time.tm_min) &&
  585. (curr_time.tm_hour == hpet_alarm_time.tm_hour))
  586. rtc_int_flag |= RTC_AF;
  587. if (rtc_int_flag) {
  588. rtc_int_flag |= (RTC_IRQF | (RTC_NUM_INTS << 8));
  589. if (irq_handler)
  590. irq_handler(rtc_int_flag, dev_id);
  591. }
  592. return IRQ_HANDLED;
  593. }
  594. EXPORT_SYMBOL_GPL(hpet_rtc_interrupt);
  595. #endif