time.c 2.0 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/system.h>
  18. #include <asm/traps.h>
  19. #include <asm/blinken.h>
  20. #include "ints.h"
  21. /* Clock hardware definitions */
  22. #define CLOCKBASE 0xf05f8000
  23. #define CLKCR1 0x1
  24. #define CLKCR2 0x3
  25. #define CLKCR3 CLKCR1
  26. #define CLKSR CLKCR2
  27. #define CLKMSB1 0x5
  28. #define CLKMSB2 0x9
  29. #define CLKMSB3 0xD
  30. /* This is for machines which generate the exact clock. */
  31. #define USECS_PER_JIFFY (1000000/HZ)
  32. #define INTVAL ((10000 / 4) - 1)
  33. static irqreturn_t hp300_tick(int irq, void *dev_id, struct pt_regs *regs)
  34. {
  35. unsigned long tmp;
  36. irqreturn_t (*vector)(int, void *, struct pt_regs *) = dev_id;
  37. in_8(CLOCKBASE + CLKSR);
  38. asm volatile ("movpw %1@(5),%0" : "=d" (tmp) : "a" (CLOCKBASE));
  39. /* Turn off the network and SCSI leds */
  40. blinken_leds(0, 0xe0);
  41. return vector(irq, NULL, regs);
  42. }
  43. unsigned long hp300_gettimeoffset(void)
  44. {
  45. /* Read current timer 1 value */
  46. unsigned char lsb, msb1, msb2;
  47. unsigned short ticks;
  48. msb1 = in_8(CLOCKBASE + 5);
  49. lsb = in_8(CLOCKBASE + 7);
  50. msb2 = in_8(CLOCKBASE + 5);
  51. if (msb1 != msb2)
  52. /* A carry happened while we were reading. Read it again */
  53. lsb = in_8(CLOCKBASE + 7);
  54. ticks = INTVAL - ((msb2 << 8) | lsb);
  55. return (USECS_PER_JIFFY * ticks) / INTVAL;
  56. }
  57. void __init hp300_sched_init(irqreturn_t (*vector)(int, void *, struct pt_regs *))
  58. {
  59. out_8(CLOCKBASE + CLKCR2, 0x1); /* select CR1 */
  60. out_8(CLOCKBASE + CLKCR1, 0x1); /* reset */
  61. asm volatile(" movpw %0,%1@(5)" : : "d" (INTVAL), "a" (CLOCKBASE));
  62. cpu_request_irq(6, hp300_tick, IRQ_FLG_STD, "timer tick", vector);
  63. out_8(CLOCKBASE + CLKCR2, 0x1); /* select CR1 */
  64. out_8(CLOCKBASE + CLKCR1, 0x40); /* enable irq */
  65. }