csrc-octeon.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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) 2007 by Ralf Baechle
  7. */
  8. #include <linux/clocksource.h>
  9. #include <linux/init.h>
  10. #include <asm/time.h>
  11. #include <asm/octeon/octeon.h>
  12. #include <asm/octeon/cvmx-ipd-defs.h>
  13. /*
  14. * Set the current core's cvmcount counter to the value of the
  15. * IPD_CLK_COUNT. We do this on all cores as they are brought
  16. * on-line. This allows for a read from a local cpu register to
  17. * access a synchronized counter.
  18. *
  19. */
  20. void octeon_init_cvmcount(void)
  21. {
  22. unsigned long flags;
  23. unsigned loops = 2;
  24. /* Clobber loops so GCC will not unroll the following while loop. */
  25. asm("" : "+r" (loops));
  26. local_irq_save(flags);
  27. /*
  28. * Loop several times so we are executing from the cache,
  29. * which should give more deterministic timing.
  30. */
  31. while (loops--)
  32. write_c0_cvmcount(cvmx_read_csr(CVMX_IPD_CLK_COUNT));
  33. local_irq_restore(flags);
  34. }
  35. static cycle_t octeon_cvmcount_read(struct clocksource *cs)
  36. {
  37. return read_c0_cvmcount();
  38. }
  39. static struct clocksource clocksource_mips = {
  40. .name = "OCTEON_CVMCOUNT",
  41. .read = octeon_cvmcount_read,
  42. .mask = CLOCKSOURCE_MASK(64),
  43. .flags = CLOCK_SOURCE_IS_CONTINUOUS,
  44. };
  45. void __init plat_time_init(void)
  46. {
  47. clocksource_mips.rating = 300;
  48. clocksource_set_clock(&clocksource_mips, mips_hpt_frequency);
  49. clocksource_register(&clocksource_mips);
  50. }