time.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * arch/sh64/kernel/time.c
  7. *
  8. * Copyright (C) 2000, 2001 Paolo Alberelli
  9. * Copyright (C) 2003, 2004 Paul Mundt
  10. * Copyright (C) 2003 Richard Curnow
  11. *
  12. * Original TMU/RTC code taken from sh version.
  13. * Copyright (C) 1999 Tetsuya Okada & Niibe Yutaka
  14. * Some code taken from i386 version.
  15. * Copyright (C) 1991, 1992, 1995 Linus Torvalds
  16. */
  17. #include <linux/config.h>
  18. #include <linux/errno.h>
  19. #include <linux/rwsem.h>
  20. #include <linux/sched.h>
  21. #include <linux/kernel.h>
  22. #include <linux/param.h>
  23. #include <linux/string.h>
  24. #include <linux/mm.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/time.h>
  27. #include <linux/delay.h>
  28. #include <linux/init.h>
  29. #include <linux/profile.h>
  30. #include <linux/smp.h>
  31. #include <asm/registers.h> /* required by inline __asm__ stmt. */
  32. #include <asm/processor.h>
  33. #include <asm/uaccess.h>
  34. #include <asm/io.h>
  35. #include <asm/irq.h>
  36. #include <asm/delay.h>
  37. #include <linux/timex.h>
  38. #include <linux/irq.h>
  39. #include <asm/hardware.h>
  40. #define TMU_TOCR_INIT 0x00
  41. #define TMU0_TCR_INIT 0x0020
  42. #define TMU_TSTR_INIT 1
  43. #define TMU_TSTR_OFF 0
  44. /* RCR1 Bits */
  45. #define RCR1_CF 0x80 /* Carry Flag */
  46. #define RCR1_CIE 0x10 /* Carry Interrupt Enable */
  47. #define RCR1_AIE 0x08 /* Alarm Interrupt Enable */
  48. #define RCR1_AF 0x01 /* Alarm Flag */
  49. /* RCR2 Bits */
  50. #define RCR2_PEF 0x80 /* PEriodic interrupt Flag */
  51. #define RCR2_PESMASK 0x70 /* Periodic interrupt Set */
  52. #define RCR2_RTCEN 0x08 /* ENable RTC */
  53. #define RCR2_ADJ 0x04 /* ADJustment (30-second) */
  54. #define RCR2_RESET 0x02 /* Reset bit */
  55. #define RCR2_START 0x01 /* Start bit */
  56. /* Clock, Power and Reset Controller */
  57. #define CPRC_BLOCK_OFF 0x01010000
  58. #define CPRC_BASE PHYS_PERIPHERAL_BLOCK + CPRC_BLOCK_OFF
  59. #define FRQCR (cprc_base+0x0)
  60. #define WTCSR (cprc_base+0x0018)
  61. #define STBCR (cprc_base+0x0030)
  62. /* Time Management Unit */
  63. #define TMU_BLOCK_OFF 0x01020000
  64. #define TMU_BASE PHYS_PERIPHERAL_BLOCK + TMU_BLOCK_OFF
  65. #define TMU0_BASE tmu_base + 0x8 + (0xc * 0x0)
  66. #define TMU1_BASE tmu_base + 0x8 + (0xc * 0x1)
  67. #define TMU2_BASE tmu_base + 0x8 + (0xc * 0x2)
  68. #define TMU_TOCR tmu_base+0x0 /* Byte access */
  69. #define TMU_TSTR tmu_base+0x4 /* Byte access */
  70. #define TMU0_TCOR TMU0_BASE+0x0 /* Long access */
  71. #define TMU0_TCNT TMU0_BASE+0x4 /* Long access */
  72. #define TMU0_TCR TMU0_BASE+0x8 /* Word access */
  73. /* Real Time Clock */
  74. #define RTC_BLOCK_OFF 0x01040000
  75. #define RTC_BASE PHYS_PERIPHERAL_BLOCK + RTC_BLOCK_OFF
  76. #define R64CNT rtc_base+0x00
  77. #define RSECCNT rtc_base+0x04
  78. #define RMINCNT rtc_base+0x08
  79. #define RHRCNT rtc_base+0x0c
  80. #define RWKCNT rtc_base+0x10
  81. #define RDAYCNT rtc_base+0x14
  82. #define RMONCNT rtc_base+0x18
  83. #define RYRCNT rtc_base+0x1c /* 16bit */
  84. #define RSECAR rtc_base+0x20
  85. #define RMINAR rtc_base+0x24
  86. #define RHRAR rtc_base+0x28
  87. #define RWKAR rtc_base+0x2c
  88. #define RDAYAR rtc_base+0x30
  89. #define RMONAR rtc_base+0x34
  90. #define RCR1 rtc_base+0x38
  91. #define RCR2 rtc_base+0x3c
  92. #ifndef BCD_TO_BIN
  93. #define BCD_TO_BIN(val) ((val)=((val)&15) + ((val)>>4)*10)
  94. #endif
  95. #ifndef BIN_TO_BCD
  96. #define BIN_TO_BCD(val) ((val)=(((val)/10)<<4) + (val)%10)
  97. #endif
  98. #define TICK_SIZE (tick_nsec / 1000)
  99. extern unsigned long wall_jiffies;
  100. u64 jiffies_64 = INITIAL_JIFFIES;
  101. static unsigned long tmu_base, rtc_base;
  102. unsigned long cprc_base;
  103. /* Variables to allow interpolation of time of day to resolution better than a
  104. * jiffy. */
  105. /* This is effectively protected by xtime_lock */
  106. static unsigned long ctc_last_interrupt;
  107. static unsigned long long usecs_per_jiffy = 1000000/HZ; /* Approximation */
  108. #define CTC_JIFFY_SCALE_SHIFT 40
  109. /* 2**CTC_JIFFY_SCALE_SHIFT / ctc_ticks_per_jiffy */
  110. static unsigned long long scaled_recip_ctc_ticks_per_jiffy;
  111. /* Estimate number of microseconds that have elapsed since the last timer tick,
  112. by scaling the delta that has occured in the CTC register.
  113. WARNING WARNING WARNING : This algorithm relies on the CTC decrementing at
  114. the CPU clock rate. If the CPU sleeps, the CTC stops counting. Bear this
  115. in mind if enabling SLEEP_WORKS in process.c. In that case, this algorithm
  116. probably needs to use TMU.TCNT0 instead. This will work even if the CPU is
  117. sleeping, though will be coarser.
  118. FIXME : What if usecs_per_tick is moving around too much, e.g. if an adjtime
  119. is running or if the freq or tick arguments of adjtimex are modified after
  120. we have calibrated the scaling factor? This will result in either a jump at
  121. the end of a tick period, or a wrap backwards at the start of the next one,
  122. if the application is reading the time of day often enough. I think we
  123. ought to do better than this. For this reason, usecs_per_jiffy is left
  124. separated out in the calculation below. This allows some future hook into
  125. the adjtime-related stuff in kernel/timer.c to remove this hazard.
  126. */
  127. static unsigned long usecs_since_tick(void)
  128. {
  129. unsigned long long current_ctc;
  130. long ctc_ticks_since_interrupt;
  131. unsigned long long ull_ctc_ticks_since_interrupt;
  132. unsigned long result;
  133. unsigned long long mul1_out;
  134. unsigned long long mul1_out_high;
  135. unsigned long long mul2_out_low, mul2_out_high;
  136. /* Read CTC register */
  137. asm ("getcon cr62, %0" : "=r" (current_ctc));
  138. /* Note, the CTC counts down on each CPU clock, not up.
  139. Note(2), use long type to get correct wraparound arithmetic when
  140. the counter crosses zero. */
  141. ctc_ticks_since_interrupt = (long) ctc_last_interrupt - (long) current_ctc;
  142. ull_ctc_ticks_since_interrupt = (unsigned long long) ctc_ticks_since_interrupt;
  143. /* Inline assembly to do 32x32x32->64 multiplier */
  144. asm volatile ("mulu.l %1, %2, %0" :
  145. "=r" (mul1_out) :
  146. "r" (ull_ctc_ticks_since_interrupt), "r" (usecs_per_jiffy));
  147. mul1_out_high = mul1_out >> 32;
  148. asm volatile ("mulu.l %1, %2, %0" :
  149. "=r" (mul2_out_low) :
  150. "r" (mul1_out), "r" (scaled_recip_ctc_ticks_per_jiffy));
  151. #if 1
  152. asm volatile ("mulu.l %1, %2, %0" :
  153. "=r" (mul2_out_high) :
  154. "r" (mul1_out_high), "r" (scaled_recip_ctc_ticks_per_jiffy));
  155. #endif
  156. result = (unsigned long) (((mul2_out_high << 32) + mul2_out_low) >> CTC_JIFFY_SCALE_SHIFT);
  157. return result;
  158. }
  159. void do_gettimeofday(struct timeval *tv)
  160. {
  161. unsigned long flags;
  162. unsigned long seq;
  163. unsigned long usec, sec;
  164. do {
  165. seq = read_seqbegin_irqsave(&xtime_lock, flags);
  166. usec = usecs_since_tick();
  167. {
  168. unsigned long lost = jiffies - wall_jiffies;
  169. if (lost)
  170. usec += lost * (1000000 / HZ);
  171. }
  172. sec = xtime.tv_sec;
  173. usec += xtime.tv_nsec / 1000;
  174. } while (read_seqretry_irqrestore(&xtime_lock, seq, flags));
  175. while (usec >= 1000000) {
  176. usec -= 1000000;
  177. sec++;
  178. }
  179. tv->tv_sec = sec;
  180. tv->tv_usec = usec;
  181. }
  182. int do_settimeofday(struct timespec *tv)
  183. {
  184. time_t wtm_sec, sec = tv->tv_sec;
  185. long wtm_nsec, nsec = tv->tv_nsec;
  186. if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
  187. return -EINVAL;
  188. write_seqlock_irq(&xtime_lock);
  189. /*
  190. * This is revolting. We need to set "xtime" correctly. However, the
  191. * value in this location is the value at the most recent update of
  192. * wall time. Discover what correction gettimeofday() would have
  193. * made, and then undo it!
  194. */
  195. nsec -= 1000 * (usecs_since_tick() +
  196. (jiffies - wall_jiffies) * (1000000 / HZ));
  197. wtm_sec = wall_to_monotonic.tv_sec + (xtime.tv_sec - sec);
  198. wtm_nsec = wall_to_monotonic.tv_nsec + (xtime.tv_nsec - nsec);
  199. set_normalized_timespec(&xtime, sec, nsec);
  200. set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec);
  201. ntp_clear();
  202. write_sequnlock_irq(&xtime_lock);
  203. clock_was_set();
  204. return 0;
  205. }
  206. static int set_rtc_time(unsigned long nowtime)
  207. {
  208. int retval = 0;
  209. int real_seconds, real_minutes, cmos_minutes;
  210. ctrl_outb(RCR2_RESET, RCR2); /* Reset pre-scaler & stop RTC */
  211. cmos_minutes = ctrl_inb(RMINCNT);
  212. BCD_TO_BIN(cmos_minutes);
  213. /*
  214. * since we're only adjusting minutes and seconds,
  215. * don't interfere with hour overflow. This avoids
  216. * messing with unknown time zones but requires your
  217. * RTC not to be off by more than 15 minutes
  218. */
  219. real_seconds = nowtime % 60;
  220. real_minutes = nowtime / 60;
  221. if (((abs(real_minutes - cmos_minutes) + 15)/30) & 1)
  222. real_minutes += 30; /* correct for half hour time zone */
  223. real_minutes %= 60;
  224. if (abs(real_minutes - cmos_minutes) < 30) {
  225. BIN_TO_BCD(real_seconds);
  226. BIN_TO_BCD(real_minutes);
  227. ctrl_outb(real_seconds, RSECCNT);
  228. ctrl_outb(real_minutes, RMINCNT);
  229. } else {
  230. printk(KERN_WARNING
  231. "set_rtc_time: can't update from %d to %d\n",
  232. cmos_minutes, real_minutes);
  233. retval = -1;
  234. }
  235. ctrl_outb(RCR2_RTCEN|RCR2_START, RCR2); /* Start RTC */
  236. return retval;
  237. }
  238. /* last time the RTC clock got updated */
  239. static long last_rtc_update = 0;
  240. /*
  241. * timer_interrupt() needs to keep up the real-time clock,
  242. * as well as call the "do_timer()" routine every clocktick
  243. */
  244. static inline void do_timer_interrupt(int irq, struct pt_regs *regs)
  245. {
  246. unsigned long long current_ctc;
  247. asm ("getcon cr62, %0" : "=r" (current_ctc));
  248. ctc_last_interrupt = (unsigned long) current_ctc;
  249. do_timer(regs);
  250. #ifndef CONFIG_SMP
  251. update_process_times(user_mode(regs));
  252. #endif
  253. profile_tick(CPU_PROFILING, regs);
  254. #ifdef CONFIG_HEARTBEAT
  255. {
  256. extern void heartbeat(void);
  257. heartbeat();
  258. }
  259. #endif
  260. /*
  261. * If we have an externally synchronized Linux clock, then update
  262. * RTC clock accordingly every ~11 minutes. Set_rtc_mmss() has to be
  263. * called as close as possible to 500 ms before the new second starts.
  264. */
  265. if (ntp_synced() &&
  266. xtime.tv_sec > last_rtc_update + 660 &&
  267. (xtime.tv_nsec / 1000) >= 500000 - ((unsigned) TICK_SIZE) / 2 &&
  268. (xtime.tv_nsec / 1000) <= 500000 + ((unsigned) TICK_SIZE) / 2) {
  269. if (set_rtc_time(xtime.tv_sec) == 0)
  270. last_rtc_update = xtime.tv_sec;
  271. else
  272. last_rtc_update = xtime.tv_sec - 600; /* do it again in 60 s */
  273. }
  274. }
  275. /*
  276. * This is the same as the above, except we _also_ save the current
  277. * Time Stamp Counter value at the time of the timer interrupt, so that
  278. * we later on can estimate the time of day more exactly.
  279. */
  280. static irqreturn_t timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  281. {
  282. unsigned long timer_status;
  283. /* Clear UNF bit */
  284. timer_status = ctrl_inw(TMU0_TCR);
  285. timer_status &= ~0x100;
  286. ctrl_outw(timer_status, TMU0_TCR);
  287. /*
  288. * Here we are in the timer irq handler. We just have irqs locally
  289. * disabled but we don't know if the timer_bh is running on the other
  290. * CPU. We need to avoid to SMP race with it. NOTE: we don' t need
  291. * the irq version of write_lock because as just said we have irq
  292. * locally disabled. -arca
  293. */
  294. write_lock(&xtime_lock);
  295. do_timer_interrupt(irq, regs);
  296. write_unlock(&xtime_lock);
  297. return IRQ_HANDLED;
  298. }
  299. static unsigned long get_rtc_time(void)
  300. {
  301. unsigned int sec, min, hr, wk, day, mon, yr, yr100;
  302. again:
  303. do {
  304. ctrl_outb(0, RCR1); /* Clear CF-bit */
  305. sec = ctrl_inb(RSECCNT);
  306. min = ctrl_inb(RMINCNT);
  307. hr = ctrl_inb(RHRCNT);
  308. wk = ctrl_inb(RWKCNT);
  309. day = ctrl_inb(RDAYCNT);
  310. mon = ctrl_inb(RMONCNT);
  311. yr = ctrl_inw(RYRCNT);
  312. yr100 = (yr >> 8);
  313. yr &= 0xff;
  314. } while ((ctrl_inb(RCR1) & RCR1_CF) != 0);
  315. BCD_TO_BIN(yr100);
  316. BCD_TO_BIN(yr);
  317. BCD_TO_BIN(mon);
  318. BCD_TO_BIN(day);
  319. BCD_TO_BIN(hr);
  320. BCD_TO_BIN(min);
  321. BCD_TO_BIN(sec);
  322. if (yr > 99 || mon < 1 || mon > 12 || day > 31 || day < 1 ||
  323. hr > 23 || min > 59 || sec > 59) {
  324. printk(KERN_ERR
  325. "SH RTC: invalid value, resetting to 1 Jan 2000\n");
  326. ctrl_outb(RCR2_RESET, RCR2); /* Reset & Stop */
  327. ctrl_outb(0, RSECCNT);
  328. ctrl_outb(0, RMINCNT);
  329. ctrl_outb(0, RHRCNT);
  330. ctrl_outb(6, RWKCNT);
  331. ctrl_outb(1, RDAYCNT);
  332. ctrl_outb(1, RMONCNT);
  333. ctrl_outw(0x2000, RYRCNT);
  334. ctrl_outb(RCR2_RTCEN|RCR2_START, RCR2); /* Start */
  335. goto again;
  336. }
  337. return mktime(yr100 * 100 + yr, mon, day, hr, min, sec);
  338. }
  339. static __init unsigned int get_cpu_hz(void)
  340. {
  341. unsigned int count;
  342. unsigned long __dummy;
  343. unsigned long ctc_val_init, ctc_val;
  344. /*
  345. ** Regardless the toolchain, force the compiler to use the
  346. ** arbitrary register r3 as a clock tick counter.
  347. ** NOTE: r3 must be in accordance with rtc_interrupt()
  348. */
  349. register unsigned long long __rtc_irq_flag __asm__ ("r3");
  350. local_irq_enable();
  351. do {} while (ctrl_inb(R64CNT) != 0);
  352. ctrl_outb(RCR1_CIE, RCR1); /* Enable carry interrupt */
  353. /*
  354. * r3 is arbitrary. CDC does not support "=z".
  355. */
  356. ctc_val_init = 0xffffffff;
  357. ctc_val = ctc_val_init;
  358. asm volatile("gettr tr0, %1\n\t"
  359. "putcon %0, " __CTC "\n\t"
  360. "and %2, r63, %2\n\t"
  361. "pta $+4, tr0\n\t"
  362. "beq/l %2, r63, tr0\n\t"
  363. "ptabs %1, tr0\n\t"
  364. "getcon " __CTC ", %0\n\t"
  365. : "=r"(ctc_val), "=r" (__dummy), "=r" (__rtc_irq_flag)
  366. : "0" (0));
  367. local_irq_disable();
  368. /*
  369. * SH-3:
  370. * CPU clock = 4 stages * loop
  371. * tst rm,rm if id ex
  372. * bt/s 1b if id ex
  373. * add #1,rd if id ex
  374. * (if) pipe line stole
  375. * tst rm,rm if id ex
  376. * ....
  377. *
  378. *
  379. * SH-4:
  380. * CPU clock = 6 stages * loop
  381. * I don't know why.
  382. * ....
  383. *
  384. * SH-5:
  385. * Use CTC register to count. This approach returns the right value
  386. * even if the I-cache is disabled (e.g. whilst debugging.)
  387. *
  388. */
  389. count = ctc_val_init - ctc_val; /* CTC counts down */
  390. #if defined (CONFIG_SH_SIMULATOR)
  391. /*
  392. * Let's pretend we are a 5MHz SH-5 to avoid a too
  393. * little timer interval. Also to keep delay
  394. * calibration within a reasonable time.
  395. */
  396. return 5000000;
  397. #else
  398. /*
  399. * This really is count by the number of clock cycles
  400. * by the ratio between a complete R64CNT
  401. * wrap-around (128) and CUI interrupt being raised (64).
  402. */
  403. return count*2;
  404. #endif
  405. }
  406. static irqreturn_t rtc_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  407. {
  408. ctrl_outb(0, RCR1); /* Disable Carry Interrupts */
  409. regs->regs[3] = 1; /* Using r3 */
  410. return IRQ_HANDLED;
  411. }
  412. static struct irqaction irq0 = { timer_interrupt, SA_INTERRUPT, CPU_MASK_NONE, "timer", NULL, NULL};
  413. static struct irqaction irq1 = { rtc_interrupt, SA_INTERRUPT, CPU_MASK_NONE, "rtc", NULL, NULL};
  414. void __init time_init(void)
  415. {
  416. unsigned int cpu_clock, master_clock, bus_clock, module_clock;
  417. unsigned long interval;
  418. unsigned long frqcr, ifc, pfc;
  419. static int ifc_table[] = { 2, 4, 6, 8, 10, 12, 16, 24 };
  420. #define bfc_table ifc_table /* Same */
  421. #define pfc_table ifc_table /* Same */
  422. tmu_base = onchip_remap(TMU_BASE, 1024, "TMU");
  423. if (!tmu_base) {
  424. panic("Unable to remap TMU\n");
  425. }
  426. rtc_base = onchip_remap(RTC_BASE, 1024, "RTC");
  427. if (!rtc_base) {
  428. panic("Unable to remap RTC\n");
  429. }
  430. cprc_base = onchip_remap(CPRC_BASE, 1024, "CPRC");
  431. if (!cprc_base) {
  432. panic("Unable to remap CPRC\n");
  433. }
  434. xtime.tv_sec = get_rtc_time();
  435. xtime.tv_nsec = 0;
  436. setup_irq(TIMER_IRQ, &irq0);
  437. setup_irq(RTC_IRQ, &irq1);
  438. /* Check how fast it is.. */
  439. cpu_clock = get_cpu_hz();
  440. /* Note careful order of operations to maintain reasonable precision and avoid overflow. */
  441. scaled_recip_ctc_ticks_per_jiffy = ((1ULL << CTC_JIFFY_SCALE_SHIFT) / (unsigned long long)(cpu_clock / HZ));
  442. disable_irq(RTC_IRQ);
  443. printk("CPU clock: %d.%02dMHz\n",
  444. (cpu_clock / 1000000), (cpu_clock % 1000000)/10000);
  445. {
  446. unsigned short bfc;
  447. frqcr = ctrl_inl(FRQCR);
  448. ifc = ifc_table[(frqcr>> 6) & 0x0007];
  449. bfc = bfc_table[(frqcr>> 3) & 0x0007];
  450. pfc = pfc_table[(frqcr>> 12) & 0x0007];
  451. master_clock = cpu_clock * ifc;
  452. bus_clock = master_clock/bfc;
  453. }
  454. printk("Bus clock: %d.%02dMHz\n",
  455. (bus_clock/1000000), (bus_clock % 1000000)/10000);
  456. module_clock = master_clock/pfc;
  457. printk("Module clock: %d.%02dMHz\n",
  458. (module_clock/1000000), (module_clock % 1000000)/10000);
  459. interval = (module_clock/(HZ*4));
  460. printk("Interval = %ld\n", interval);
  461. current_cpu_data.cpu_clock = cpu_clock;
  462. current_cpu_data.master_clock = master_clock;
  463. current_cpu_data.bus_clock = bus_clock;
  464. current_cpu_data.module_clock = module_clock;
  465. /* Start TMU0 */
  466. ctrl_outb(TMU_TSTR_OFF, TMU_TSTR);
  467. ctrl_outb(TMU_TOCR_INIT, TMU_TOCR);
  468. ctrl_outw(TMU0_TCR_INIT, TMU0_TCR);
  469. ctrl_outl(interval, TMU0_TCOR);
  470. ctrl_outl(interval, TMU0_TCNT);
  471. ctrl_outb(TMU_TSTR_INIT, TMU_TSTR);
  472. }
  473. void enter_deep_standby(void)
  474. {
  475. /* Disable watchdog timer */
  476. ctrl_outl(0xa5000000, WTCSR);
  477. /* Configure deep standby on sleep */
  478. ctrl_outl(0x03, STBCR);
  479. #ifdef CONFIG_SH_ALPHANUMERIC
  480. {
  481. extern void mach_alphanum(int position, unsigned char value);
  482. extern void mach_alphanum_brightness(int setting);
  483. char halted[] = "Halted. ";
  484. int i;
  485. mach_alphanum_brightness(6); /* dimmest setting above off */
  486. for (i=0; i<8; i++) {
  487. mach_alphanum(i, halted[i]);
  488. }
  489. asm __volatile__ ("synco");
  490. }
  491. #endif
  492. asm __volatile__ ("sleep");
  493. asm __volatile__ ("synci");
  494. asm __volatile__ ("nop");
  495. asm __volatile__ ("nop");
  496. asm __volatile__ ("nop");
  497. asm __volatile__ ("nop");
  498. panic("Unexpected wakeup!\n");
  499. }
  500. /*
  501. * Scheduler clock - returns current time in nanosec units.
  502. */
  503. unsigned long long sched_clock(void)
  504. {
  505. return (unsigned long long)jiffies * (1000000000 / HZ);
  506. }