tango_xtal.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #include <linux/clocksource.h>
  2. #include <linux/sched_clock.h>
  3. #include <linux/of_address.h>
  4. #include <linux/printk.h>
  5. #include <linux/delay.h>
  6. #include <linux/init.h>
  7. #include <linux/clk.h>
  8. static void __iomem *xtal_in_cnt;
  9. static struct delay_timer delay_timer;
  10. static unsigned long notrace read_xtal_counter(void)
  11. {
  12. return readl_relaxed(xtal_in_cnt);
  13. }
  14. static u64 notrace read_sched_clock(void)
  15. {
  16. return read_xtal_counter();
  17. }
  18. static int __init tango_clocksource_init(struct device_node *np)
  19. {
  20. struct clk *clk;
  21. int xtal_freq, ret;
  22. xtal_in_cnt = of_iomap(np, 0);
  23. if (xtal_in_cnt == NULL) {
  24. pr_err("%s: invalid address\n", np->full_name);
  25. return -ENXIO;
  26. }
  27. clk = of_clk_get(np, 0);
  28. if (IS_ERR(clk)) {
  29. pr_err("%s: invalid clock\n", np->full_name);
  30. return PTR_ERR(clk);
  31. }
  32. xtal_freq = clk_get_rate(clk);
  33. delay_timer.freq = xtal_freq;
  34. delay_timer.read_current_timer = read_xtal_counter;
  35. ret = clocksource_mmio_init(xtal_in_cnt, "tango-xtal", xtal_freq, 350,
  36. 32, clocksource_mmio_readl_up);
  37. if (ret) {
  38. pr_err("%s: registration failed\n", np->full_name);
  39. return ret;
  40. }
  41. sched_clock_register(read_sched_clock, 32, xtal_freq);
  42. register_current_timer_delay(&delay_timer);
  43. return 0;
  44. }
  45. CLOCKSOURCE_OF_DECLARE(tango, "sigma,tick-counter", tango_clocksource_init);