time.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * Joshua Henderson <joshua.henderson@microchip.com>
  3. * Copyright (C) 2015 Microchip Technology Inc. All rights reserved.
  4. *
  5. * This program is free software; you can distribute it and/or modify it
  6. * under the terms of the GNU General Public License (Version 2) as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12. * for more details.
  13. */
  14. #include <linux/clk-provider.h>
  15. #include <linux/clocksource.h>
  16. #include <linux/init.h>
  17. #include <linux/irqdomain.h>
  18. #include <linux/of.h>
  19. #include <linux/of_irq.h>
  20. #include <asm/time.h>
  21. #include "pic32mzda.h"
  22. static const struct of_device_id pic32_infra_match[] = {
  23. { .compatible = "microchip,pic32mzda-infra", },
  24. { },
  25. };
  26. #define DEFAULT_CORE_TIMER_INTERRUPT 0
  27. static unsigned int pic32_xlate_core_timer_irq(void)
  28. {
  29. static struct device_node *node;
  30. unsigned int irq;
  31. node = of_find_matching_node(NULL, pic32_infra_match);
  32. if (WARN_ON(!node))
  33. goto default_map;
  34. irq = irq_of_parse_and_map(node, 0);
  35. if (!irq)
  36. goto default_map;
  37. return irq;
  38. default_map:
  39. return irq_create_mapping(NULL, DEFAULT_CORE_TIMER_INTERRUPT);
  40. }
  41. unsigned int get_c0_compare_int(void)
  42. {
  43. return pic32_xlate_core_timer_irq();
  44. }
  45. void __init plat_time_init(void)
  46. {
  47. unsigned long rate = pic32_get_pbclk(7);
  48. of_clk_init(NULL);
  49. pr_info("CPU Clock: %ldMHz\n", rate / 1000000);
  50. mips_hpt_frequency = rate / 2;
  51. clocksource_probe();
  52. }