blob: 62a0a78b6c6446c58cb2ac08bf61157e40c4c6ed [file] [log] [blame]
Joshua Henderson2572f002016-01-13 18:15:39 -07001/*
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 */
Joshua Henderson2572f002016-01-13 18:15:39 -070014#include <linux/clk-provider.h>
15#include <linux/clocksource.h>
16#include <linux/init.h>
Purna Chandra Mandal6e4ad1b2016-05-17 10:35:52 +053017#include <linux/irqdomain.h>
Joshua Henderson2572f002016-01-13 18:15:39 -070018#include <linux/of.h>
19#include <linux/of_irq.h>
Joshua Henderson2572f002016-01-13 18:15:39 -070020
21#include <asm/time.h>
22
23#include "pic32mzda.h"
24
25static const struct of_device_id pic32_infra_match[] = {
26 { .compatible = "microchip,pic32mzda-infra", },
27 { },
28};
29
30#define DEFAULT_CORE_TIMER_INTERRUPT 0
31
32static unsigned int pic32_xlate_core_timer_irq(void)
33{
34 static struct device_node *node;
35 unsigned int irq;
36
37 node = of_find_matching_node(NULL, pic32_infra_match);
38
39 if (WARN_ON(!node))
40 goto default_map;
41
42 irq = irq_of_parse_and_map(node, 0);
43 if (!irq)
44 goto default_map;
45
46 return irq;
47
48default_map:
49
50 return irq_create_mapping(NULL, DEFAULT_CORE_TIMER_INTERRUPT);
51}
52
53unsigned int get_c0_compare_int(void)
54{
55 return pic32_xlate_core_timer_irq();
56}
57
58void __init plat_time_init(void)
59{
Purna Chandra Mandal6e4ad1b2016-05-17 10:35:52 +053060 unsigned long rate = pic32_get_pbclk(7);
Joshua Henderson2572f002016-01-13 18:15:39 -070061
62 of_clk_init(NULL);
Joshua Henderson2572f002016-01-13 18:15:39 -070063
Purna Chandra Mandal6e4ad1b2016-05-17 10:35:52 +053064 pr_info("CPU Clock: %ldMHz\n", rate / 1000000);
65 mips_hpt_frequency = rate / 2;
Joshua Henderson2572f002016-01-13 18:15:39 -070066
67 clocksource_probe();
68}