csrc-sb1250.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Copyright (C) 2000, 2001 Broadcom Corporation
  4. */
  5. #include <linux/clocksource.h>
  6. #include <linux/sched_clock.h>
  7. #include <asm/addrspace.h>
  8. #include <asm/io.h>
  9. #include <asm/time.h>
  10. #include <asm/sibyte/sb1250.h>
  11. #include <asm/sibyte/sb1250_regs.h>
  12. #include <asm/sibyte/sb1250_int.h>
  13. #include <asm/sibyte/sb1250_scd.h>
  14. #define SB1250_HPT_NUM 3
  15. #define SB1250_HPT_VALUE M_SCD_TIMER_CNT /* max value */
  16. /*
  17. * The HPT is free running from SB1250_HPT_VALUE down to 0 then starts over
  18. * again.
  19. */
  20. static inline u64 sb1250_hpt_get_cycles(void)
  21. {
  22. unsigned int count;
  23. void __iomem *addr;
  24. addr = IOADDR(A_SCD_TIMER_REGISTER(SB1250_HPT_NUM, R_SCD_TIMER_CNT));
  25. count = G_SCD_TIMER_CNT(__raw_readq(addr));
  26. return SB1250_HPT_VALUE - count;
  27. }
  28. static u64 sb1250_hpt_read(struct clocksource *cs)
  29. {
  30. return sb1250_hpt_get_cycles();
  31. }
  32. struct clocksource bcm1250_clocksource = {
  33. .name = "bcm1250-counter-3",
  34. .rating = 200,
  35. .read = sb1250_hpt_read,
  36. .mask = CLOCKSOURCE_MASK(23),
  37. .flags = CLOCK_SOURCE_IS_CONTINUOUS,
  38. };
  39. static u64 notrace sb1250_read_sched_clock(void)
  40. {
  41. return sb1250_hpt_get_cycles();
  42. }
  43. void __init sb1250_clocksource_init(void)
  44. {
  45. struct clocksource *cs = &bcm1250_clocksource;
  46. /* Setup hpt using timer #3 but do not enable irq for it */
  47. __raw_writeq(0,
  48. IOADDR(A_SCD_TIMER_REGISTER(SB1250_HPT_NUM,
  49. R_SCD_TIMER_CFG)));
  50. __raw_writeq(SB1250_HPT_VALUE,
  51. IOADDR(A_SCD_TIMER_REGISTER(SB1250_HPT_NUM,
  52. R_SCD_TIMER_INIT)));
  53. __raw_writeq(M_SCD_TIMER_ENABLE | M_SCD_TIMER_MODE_CONTINUOUS,
  54. IOADDR(A_SCD_TIMER_REGISTER(SB1250_HPT_NUM,
  55. R_SCD_TIMER_CFG)));
  56. clocksource_register_hz(cs, V_SCD_TIMER_FREQ);
  57. sched_clock_register(sb1250_read_sched_clock, 23, V_SCD_TIMER_FREQ);
  58. }