time.c 2.0 KB

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