time.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * linux/arch/m68k/hp300/time.c
  3. *
  4. * Copyright (C) 1998 Philip Blundell <philb@gnu.org>
  5. *
  6. * This file contains the HP300-specific time handling code.
  7. */
  8. #include <asm/ptrace.h>
  9. #include <linux/types.h>
  10. #include <linux/init.h>
  11. #include <linux/sched.h>
  12. #include <linux/kernel_stat.h>
  13. #include <linux/interrupt.h>
  14. #include <asm/machdep.h>
  15. #include <asm/irq.h>
  16. #include <asm/io.h>
  17. #include <asm/traps.h>
  18. #include <asm/blinken.h>
  19. /* Clock hardware definitions */
  20. #define CLOCKBASE 0xf05f8000
  21. #define CLKCR1 0x1
  22. #define CLKCR2 0x3
  23. #define CLKCR3 CLKCR1
  24. #define CLKSR CLKCR2
  25. #define CLKMSB1 0x5
  26. #define CLKMSB2 0x9
  27. #define CLKMSB3 0xD
  28. /* This is for machines which generate the exact clock. */
  29. #define USECS_PER_JIFFY (1000000/HZ)
  30. #define INTVAL ((10000 / 4) - 1)
  31. static irqreturn_t hp300_tick(int irq, void *dev_id)
  32. {
  33. unsigned long tmp;
  34. irq_handler_t vector = dev_id;
  35. in_8(CLOCKBASE + CLKSR);
  36. asm volatile ("movpw %1@(5),%0" : "=d" (tmp) : "a" (CLOCKBASE));
  37. /* Turn off the network and SCSI leds */
  38. blinken_leds(0, 0xe0);
  39. return vector(irq, NULL);
  40. }
  41. u32 hp300_gettimeoffset(void)
  42. {
  43. /* Read current timer 1 value */
  44. unsigned char lsb, msb1, msb2;
  45. unsigned short ticks;
  46. msb1 = in_8(CLOCKBASE + 5);
  47. lsb = in_8(CLOCKBASE + 7);
  48. msb2 = in_8(CLOCKBASE + 5);
  49. if (msb1 != msb2)
  50. /* A carry happened while we were reading. Read it again */
  51. lsb = in_8(CLOCKBASE + 7);
  52. ticks = INTVAL - ((msb2 << 8) | lsb);
  53. return ((USECS_PER_JIFFY * ticks) / INTVAL) * 1000;
  54. }
  55. void __init hp300_sched_init(irq_handler_t vector)
  56. {
  57. out_8(CLOCKBASE + CLKCR2, 0x1); /* select CR1 */
  58. out_8(CLOCKBASE + CLKCR1, 0x1); /* reset */
  59. asm volatile(" movpw %0,%1@(5)" : : "d" (INTVAL), "a" (CLOCKBASE));
  60. if (request_irq(IRQ_AUTO_6, hp300_tick, 0, "timer tick", vector))
  61. pr_err("Couldn't register timer interrupt\n");
  62. out_8(CLOCKBASE + CLKCR2, 0x1); /* select CR1 */
  63. out_8(CLOCKBASE + CLKCR1, 0x40); /* enable irq */
  64. }