time.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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.h>
  15. #include <linux/clk-provider.h>
  16. #include <linux/clocksource.h>
  17. #include <linux/init.h>
  18. #include <linux/of.h>
  19. #include <linux/of_irq.h>
  20. #include <linux/irqdomain.h>
  21. #include <asm/time.h>
  22. #include "pic32mzda.h"
  23. static const struct of_device_id pic32_infra_match[] = {
  24. { .compatible = "microchip,pic32mzda-infra", },
  25. { },
  26. };
  27. #define DEFAULT_CORE_TIMER_INTERRUPT 0
  28. static unsigned int pic32_xlate_core_timer_irq(void)
  29. {
  30. static struct device_node *node;
  31. unsigned int irq;
  32. node = of_find_matching_node(NULL, pic32_infra_match);
  33. if (WARN_ON(!node))
  34. goto default_map;
  35. irq = irq_of_parse_and_map(node, 0);
  36. if (!irq)
  37. goto default_map;
  38. return irq;
  39. default_map:
  40. return irq_create_mapping(NULL, DEFAULT_CORE_TIMER_INTERRUPT);
  41. }
  42. unsigned int get_c0_compare_int(void)
  43. {
  44. return pic32_xlate_core_timer_irq();
  45. }
  46. void __init plat_time_init(void)
  47. {
  48. struct clk *clk;
  49. of_clk_init(NULL);
  50. clk = clk_get_sys("cpu_clk", NULL);
  51. if (IS_ERR(clk))
  52. panic("unable to get CPU clock, err=%ld", PTR_ERR(clk));
  53. clk_prepare_enable(clk);
  54. pr_info("CPU Clock: %ldMHz\n", clk_get_rate(clk) / 1000000);
  55. mips_hpt_frequency = clk_get_rate(clk) / 2;
  56. clocksource_probe();
  57. }