2 * Copyright (C) 2013 Boris BREZILLON <b.brezillon@overkiz.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
11 #include <linux/clk-provider.h>
12 #include <linux/clkdev.h>
13 #include <linux/clk/at91_pmc.h>
15 #include <linux/of_address.h>
16 #include <linux/mfd/syscon.h>
17 #include <linux/regmap.h>
19 #include <asm/proc-fns.h>
23 void __iomem *at91_pmc_base;
24 EXPORT_SYMBOL_GPL(at91_pmc_base);
26 void at91rm9200_idle(void)
29 * Disable the processor clock. The processor will be automatically
30 * re-enabled by an interrupt or by a reset.
32 at91_pmc_write(AT91_PMC_SCDR, AT91_PMC_PCK);
35 void at91sam9_idle(void)
37 at91_pmc_write(AT91_PMC_SCDR, AT91_PMC_PCK);
41 int of_at91_get_clk_range(struct device_node *np, const char *propname,
42 struct clk_range *range)
47 ret = of_property_read_u32_index(np, propname, 0, &min);
51 ret = of_property_read_u32_index(np, propname, 1, &max);
62 EXPORT_SYMBOL_GPL(of_at91_get_clk_range);
64 static const struct at91_pmc_caps at91rm9200_caps = {
65 .available_irqs = AT91_PMC_MOSCS | AT91_PMC_LOCKA | AT91_PMC_LOCKB |
66 AT91_PMC_MCKRDY | AT91_PMC_PCK0RDY |
67 AT91_PMC_PCK1RDY | AT91_PMC_PCK2RDY |
71 static const struct at91_pmc_caps at91sam9260_caps = {
72 .available_irqs = AT91_PMC_MOSCS | AT91_PMC_LOCKA | AT91_PMC_LOCKB |
73 AT91_PMC_MCKRDY | AT91_PMC_PCK0RDY |
77 static const struct at91_pmc_caps at91sam9g45_caps = {
78 .available_irqs = AT91_PMC_MOSCS | AT91_PMC_LOCKA | AT91_PMC_MCKRDY |
79 AT91_PMC_LOCKU | AT91_PMC_PCK0RDY |
83 static const struct at91_pmc_caps at91sam9n12_caps = {
84 .available_irqs = AT91_PMC_MOSCS | AT91_PMC_LOCKA | AT91_PMC_LOCKB |
85 AT91_PMC_MCKRDY | AT91_PMC_PCK0RDY |
86 AT91_PMC_PCK1RDY | AT91_PMC_MOSCSELS |
87 AT91_PMC_MOSCRCS | AT91_PMC_CFDEV,
90 static const struct at91_pmc_caps at91sam9x5_caps = {
91 .available_irqs = AT91_PMC_MOSCS | AT91_PMC_LOCKA | AT91_PMC_MCKRDY |
92 AT91_PMC_LOCKU | AT91_PMC_PCK0RDY |
93 AT91_PMC_PCK1RDY | AT91_PMC_MOSCSELS |
94 AT91_PMC_MOSCRCS | AT91_PMC_CFDEV,
97 static const struct at91_pmc_caps sama5d2_caps = {
98 .available_irqs = AT91_PMC_MOSCS | AT91_PMC_LOCKA | AT91_PMC_MCKRDY |
99 AT91_PMC_LOCKU | AT91_PMC_PCK0RDY |
100 AT91_PMC_PCK1RDY | AT91_PMC_PCK2RDY |
101 AT91_PMC_MOSCSELS | AT91_PMC_MOSCRCS |
102 AT91_PMC_CFDEV | AT91_PMC_GCKRDY,
105 static const struct at91_pmc_caps sama5d3_caps = {
106 .available_irqs = AT91_PMC_MOSCS | AT91_PMC_LOCKA | AT91_PMC_MCKRDY |
107 AT91_PMC_LOCKU | AT91_PMC_PCK0RDY |
108 AT91_PMC_PCK1RDY | AT91_PMC_PCK2RDY |
109 AT91_PMC_MOSCSELS | AT91_PMC_MOSCRCS |
113 static struct at91_pmc *__init at91_pmc_init(struct device_node *np,
114 struct regmap *regmap,
115 void __iomem *regbase,
116 const struct at91_pmc_caps *caps)
118 struct at91_pmc *pmc;
120 if (!regbase || !caps)
123 at91_pmc_base = regbase;
125 pmc = kzalloc(sizeof(*pmc), GFP_KERNEL);
129 pmc->regmap = regmap;
132 regmap_write(pmc->regmap, AT91_PMC_IDR, 0xffffffff);
137 static void __init of_at91_pmc_setup(struct device_node *np,
138 const struct at91_pmc_caps *caps)
140 struct at91_pmc *pmc;
141 void __iomem *regbase = of_iomap(np, 0);
142 struct regmap *regmap;
144 regmap = syscon_node_to_regmap(np);
146 panic("Could not retrieve syscon regmap");
148 pmc = at91_pmc_init(np, regmap, regbase, caps);
153 static void __init of_at91rm9200_pmc_setup(struct device_node *np)
155 of_at91_pmc_setup(np, &at91rm9200_caps);
157 CLK_OF_DECLARE(at91rm9200_clk_pmc, "atmel,at91rm9200-pmc",
158 of_at91rm9200_pmc_setup);
160 static void __init of_at91sam9260_pmc_setup(struct device_node *np)
162 of_at91_pmc_setup(np, &at91sam9260_caps);
164 CLK_OF_DECLARE(at91sam9260_clk_pmc, "atmel,at91sam9260-pmc",
165 of_at91sam9260_pmc_setup);
167 static void __init of_at91sam9g45_pmc_setup(struct device_node *np)
169 of_at91_pmc_setup(np, &at91sam9g45_caps);
171 CLK_OF_DECLARE(at91sam9g45_clk_pmc, "atmel,at91sam9g45-pmc",
172 of_at91sam9g45_pmc_setup);
174 static void __init of_at91sam9n12_pmc_setup(struct device_node *np)
176 of_at91_pmc_setup(np, &at91sam9n12_caps);
178 CLK_OF_DECLARE(at91sam9n12_clk_pmc, "atmel,at91sam9n12-pmc",
179 of_at91sam9n12_pmc_setup);
181 static void __init of_at91sam9x5_pmc_setup(struct device_node *np)
183 of_at91_pmc_setup(np, &at91sam9x5_caps);
185 CLK_OF_DECLARE(at91sam9x5_clk_pmc, "atmel,at91sam9x5-pmc",
186 of_at91sam9x5_pmc_setup);
188 static void __init of_sama5d2_pmc_setup(struct device_node *np)
190 of_at91_pmc_setup(np, &sama5d2_caps);
192 CLK_OF_DECLARE(sama5d2_clk_pmc, "atmel,sama5d2-pmc",
193 of_sama5d2_pmc_setup);
195 static void __init of_sama5d3_pmc_setup(struct device_node *np)
197 of_at91_pmc_setup(np, &sama5d3_caps);
199 CLK_OF_DECLARE(sama5d3_clk_pmc, "atmel,sama5d3-pmc",
200 of_sama5d3_pmc_setup);