time_32.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. /* linux/arch/sparc/kernel/time.c
  2. *
  3. * Copyright (C) 1995 David S. Miller (davem@davemloft.net)
  4. * Copyright (C) 1996 Thomas K. Dyas (tdyas@eden.rutgers.edu)
  5. *
  6. * Chris Davis (cdavis@cois.on.ca) 03/27/1998
  7. * Added support for the intersil on the sun4/4200
  8. *
  9. * Gleb Raiko (rajko@mech.math.msu.su) 08/18/1998
  10. * Support for MicroSPARC-IIep, PCI CPU.
  11. *
  12. * This file handles the Sparc specific time handling details.
  13. *
  14. * 1997-09-10 Updated NTP code according to technical memorandum Jan '96
  15. * "A Kernel Model for Precision Timekeeping" by Dave Mills
  16. */
  17. #include <linux/errno.h>
  18. #include <linux/module.h>
  19. #include <linux/sched.h>
  20. #include <linux/kernel.h>
  21. #include <linux/param.h>
  22. #include <linux/string.h>
  23. #include <linux/mm.h>
  24. #include <linux/interrupt.h>
  25. #include <linux/time.h>
  26. #include <linux/rtc.h>
  27. #include <linux/rtc/m48t59.h>
  28. #include <linux/timex.h>
  29. #include <linux/init.h>
  30. #include <linux/pci.h>
  31. #include <linux/ioport.h>
  32. #include <linux/profile.h>
  33. #include <linux/of.h>
  34. #include <linux/of_device.h>
  35. #include <linux/platform_device.h>
  36. #include <asm/oplib.h>
  37. #include <asm/timex.h>
  38. #include <asm/timer.h>
  39. #include <asm/system.h>
  40. #include <asm/irq.h>
  41. #include <asm/io.h>
  42. #include <asm/idprom.h>
  43. #include <asm/machines.h>
  44. #include <asm/page.h>
  45. #include <asm/pcic.h>
  46. #include <asm/irq_regs.h>
  47. #include "irq.h"
  48. DEFINE_SPINLOCK(rtc_lock);
  49. EXPORT_SYMBOL(rtc_lock);
  50. static int set_rtc_mmss(unsigned long);
  51. unsigned long profile_pc(struct pt_regs *regs)
  52. {
  53. extern char __copy_user_begin[], __copy_user_end[];
  54. extern char __atomic_begin[], __atomic_end[];
  55. extern char __bzero_begin[], __bzero_end[];
  56. unsigned long pc = regs->pc;
  57. if (in_lock_functions(pc) ||
  58. (pc >= (unsigned long) __copy_user_begin &&
  59. pc < (unsigned long) __copy_user_end) ||
  60. (pc >= (unsigned long) __atomic_begin &&
  61. pc < (unsigned long) __atomic_end) ||
  62. (pc >= (unsigned long) __bzero_begin &&
  63. pc < (unsigned long) __bzero_end))
  64. pc = regs->u_regs[UREG_RETPC];
  65. return pc;
  66. }
  67. EXPORT_SYMBOL(profile_pc);
  68. __volatile__ unsigned int *master_l10_counter;
  69. u32 (*do_arch_gettimeoffset)(void);
  70. int update_persistent_clock(struct timespec now)
  71. {
  72. return set_rtc_mmss(now.tv_sec);
  73. }
  74. /*
  75. * timer_interrupt() needs to keep up the real-time clock,
  76. * as well as call the "xtime_update()" routine every clocktick
  77. */
  78. #define TICK_SIZE (tick_nsec / 1000)
  79. static irqreturn_t timer_interrupt(int dummy, void *dev_id)
  80. {
  81. #ifndef CONFIG_SMP
  82. profile_tick(CPU_PROFILING);
  83. #endif
  84. clear_clock_irq();
  85. xtime_update(1);
  86. #ifndef CONFIG_SMP
  87. update_process_times(user_mode(get_irq_regs()));
  88. #endif
  89. return IRQ_HANDLED;
  90. }
  91. static unsigned char mostek_read_byte(struct device *dev, u32 ofs)
  92. {
  93. struct platform_device *pdev = to_platform_device(dev);
  94. struct m48t59_plat_data *pdata = pdev->dev.platform_data;
  95. return readb(pdata->ioaddr + ofs);
  96. }
  97. static void mostek_write_byte(struct device *dev, u32 ofs, u8 val)
  98. {
  99. struct platform_device *pdev = to_platform_device(dev);
  100. struct m48t59_plat_data *pdata = pdev->dev.platform_data;
  101. writeb(val, pdata->ioaddr + ofs);
  102. }
  103. static struct m48t59_plat_data m48t59_data = {
  104. .read_byte = mostek_read_byte,
  105. .write_byte = mostek_write_byte,
  106. };
  107. /* resource is set at runtime */
  108. static struct platform_device m48t59_rtc = {
  109. .name = "rtc-m48t59",
  110. .id = 0,
  111. .num_resources = 1,
  112. .dev = {
  113. .platform_data = &m48t59_data,
  114. },
  115. };
  116. static int __devinit clock_probe(struct platform_device *op)
  117. {
  118. struct device_node *dp = op->dev.of_node;
  119. const char *model = of_get_property(dp, "model", NULL);
  120. if (!model)
  121. return -ENODEV;
  122. /* Only the primary RTC has an address property */
  123. if (!of_find_property(dp, "address", NULL))
  124. return -ENODEV;
  125. m48t59_rtc.resource = &op->resource[0];
  126. if (!strcmp(model, "mk48t02")) {
  127. /* Map the clock register io area read-only */
  128. m48t59_data.ioaddr = of_ioremap(&op->resource[0], 0,
  129. 2048, "rtc-m48t59");
  130. m48t59_data.type = M48T59RTC_TYPE_M48T02;
  131. } else if (!strcmp(model, "mk48t08")) {
  132. m48t59_data.ioaddr = of_ioremap(&op->resource[0], 0,
  133. 8192, "rtc-m48t59");
  134. m48t59_data.type = M48T59RTC_TYPE_M48T08;
  135. } else
  136. return -ENODEV;
  137. if (platform_device_register(&m48t59_rtc) < 0)
  138. printk(KERN_ERR "Registering RTC device failed\n");
  139. return 0;
  140. }
  141. static struct of_device_id clock_match[] = {
  142. {
  143. .name = "eeprom",
  144. },
  145. {},
  146. };
  147. static struct platform_driver clock_driver = {
  148. .probe = clock_probe,
  149. .driver = {
  150. .name = "rtc",
  151. .owner = THIS_MODULE,
  152. .of_match_table = clock_match,
  153. },
  154. };
  155. /* Probe for the mostek real time clock chip. */
  156. static int __init clock_init(void)
  157. {
  158. return platform_driver_register(&clock_driver);
  159. }
  160. /* Must be after subsys_initcall() so that busses are probed. Must
  161. * be before device_initcall() because things like the RTC driver
  162. * need to see the clock registers.
  163. */
  164. fs_initcall(clock_init);
  165. u32 sbus_do_gettimeoffset(void)
  166. {
  167. unsigned long val = *master_l10_counter;
  168. unsigned long usec = (val >> 10) & 0x1fffff;
  169. /* Limit hit? */
  170. if (val & 0x80000000)
  171. usec += 1000000 / HZ;
  172. return usec * 1000;
  173. }
  174. u32 arch_gettimeoffset(void)
  175. {
  176. if (unlikely(!do_arch_gettimeoffset))
  177. return 0;
  178. return do_arch_gettimeoffset();
  179. }
  180. static void __init sbus_time_init(void)
  181. {
  182. do_arch_gettimeoffset = sbus_do_gettimeoffset;
  183. btfixup();
  184. sparc_irq_config.init_timers(timer_interrupt);
  185. }
  186. void __init time_init(void)
  187. {
  188. if (pcic_present())
  189. pci_time_init();
  190. else
  191. sbus_time_init();
  192. }
  193. static int set_rtc_mmss(unsigned long secs)
  194. {
  195. struct rtc_device *rtc = rtc_class_open("rtc0");
  196. int err = -1;
  197. if (rtc) {
  198. err = rtc_set_mmss(rtc, secs);
  199. rtc_class_close(rtc);
  200. }
  201. return err;
  202. }