csrc-gic.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. * Copyright (C) 2012 MIPS Technologies, Inc. All rights reserved.
  7. */
  8. #include <linux/clocksource.h>
  9. #include <linux/init.h>
  10. #include <asm/time.h>
  11. #include <asm/gic.h>
  12. static cycle_t gic_hpt_read(struct clocksource *cs)
  13. {
  14. unsigned int hi, hi2, lo;
  15. do {
  16. GICREAD(GIC_REG(SHARED, GIC_SH_COUNTER_63_32), hi);
  17. GICREAD(GIC_REG(SHARED, GIC_SH_COUNTER_31_00), lo);
  18. GICREAD(GIC_REG(SHARED, GIC_SH_COUNTER_63_32), hi2);
  19. } while (hi2 != hi);
  20. return (((cycle_t) hi) << 32) + lo;
  21. }
  22. static struct clocksource gic_clocksource = {
  23. .name = "GIC",
  24. .read = gic_hpt_read,
  25. .flags = CLOCK_SOURCE_IS_CONTINUOUS,
  26. };
  27. void __init gic_clocksource_init(unsigned int frequency)
  28. {
  29. unsigned int config, bits;
  30. /* Calculate the clocksource mask. */
  31. GICREAD(GIC_REG(SHARED, GIC_SH_CONFIG), config);
  32. bits = 32 + ((config & GIC_SH_CONFIG_COUNTBITS_MSK) >>
  33. (GIC_SH_CONFIG_COUNTBITS_SHF - 2));
  34. /* Set clocksource mask. */
  35. gic_clocksource.mask = CLOCKSOURCE_MASK(bits);
  36. /* Calculate a somewhat reasonable rating value. */
  37. gic_clocksource.rating = 200 + frequency / 10000000;
  38. clocksource_register_hz(&gic_clocksource, frequency);
  39. }