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 struct at91_pmc_caps {
28 struct regmap *regmap;
29 const struct at91_pmc_caps *caps;
32 void __iomem *at91_pmc_base;
33 EXPORT_SYMBOL_GPL(at91_pmc_base);
35 void at91rm9200_idle(void)
38 * Disable the processor clock. The processor will be automatically
39 * re-enabled by an interrupt or by a reset.
41 at91_pmc_write(AT91_PMC_SCDR, AT91_PMC_PCK);
44 void at91sam9_idle(void)
46 at91_pmc_write(AT91_PMC_SCDR, AT91_PMC_PCK);
50 int of_at91_get_clk_range(struct device_node *np, const char *propname,
51 struct clk_range *range)
56 ret = of_property_read_u32_index(np, propname, 0, &min);
60 ret = of_property_read_u32_index(np, propname, 1, &max);
71 EXPORT_SYMBOL_GPL(of_at91_get_clk_range);
73 static const struct at91_pmc_caps at91rm9200_caps = {
74 .available_irqs = AT91_PMC_MOSCS | AT91_PMC_LOCKA | AT91_PMC_LOCKB |
75 AT91_PMC_MCKRDY | AT91_PMC_PCK0RDY |
76 AT91_PMC_PCK1RDY | AT91_PMC_PCK2RDY |
80 static const struct at91_pmc_caps at91sam9260_caps = {
81 .available_irqs = AT91_PMC_MOSCS | AT91_PMC_LOCKA | AT91_PMC_LOCKB |
82 AT91_PMC_MCKRDY | AT91_PMC_PCK0RDY |
86 static const struct at91_pmc_caps at91sam9g45_caps = {
87 .available_irqs = AT91_PMC_MOSCS | AT91_PMC_LOCKA | AT91_PMC_MCKRDY |
88 AT91_PMC_LOCKU | AT91_PMC_PCK0RDY |
92 static const struct at91_pmc_caps at91sam9n12_caps = {
93 .available_irqs = AT91_PMC_MOSCS | AT91_PMC_LOCKA | AT91_PMC_LOCKB |
94 AT91_PMC_MCKRDY | AT91_PMC_PCK0RDY |
95 AT91_PMC_PCK1RDY | AT91_PMC_MOSCSELS |
96 AT91_PMC_MOSCRCS | AT91_PMC_CFDEV,
99 static const struct at91_pmc_caps at91sam9x5_caps = {
100 .available_irqs = AT91_PMC_MOSCS | AT91_PMC_LOCKA | AT91_PMC_MCKRDY |
101 AT91_PMC_LOCKU | AT91_PMC_PCK0RDY |
102 AT91_PMC_PCK1RDY | AT91_PMC_MOSCSELS |
103 AT91_PMC_MOSCRCS | AT91_PMC_CFDEV,
106 static const struct at91_pmc_caps sama5d2_caps = {
107 .available_irqs = AT91_PMC_MOSCS | AT91_PMC_LOCKA | AT91_PMC_MCKRDY |
108 AT91_PMC_LOCKU | AT91_PMC_PCK0RDY |
109 AT91_PMC_PCK1RDY | AT91_PMC_PCK2RDY |
110 AT91_PMC_MOSCSELS | AT91_PMC_MOSCRCS |
111 AT91_PMC_CFDEV | AT91_PMC_GCKRDY,
114 static const struct at91_pmc_caps sama5d3_caps = {
115 .available_irqs = AT91_PMC_MOSCS | AT91_PMC_LOCKA | AT91_PMC_MCKRDY |
116 AT91_PMC_LOCKU | AT91_PMC_PCK0RDY |
117 AT91_PMC_PCK1RDY | AT91_PMC_PCK2RDY |
118 AT91_PMC_MOSCSELS | AT91_PMC_MOSCRCS |
122 static void __init of_at91_pmc_setup(struct device_node *np,
123 const struct at91_pmc_caps *caps)
125 struct at91_pmc *pmc;
126 void __iomem *regbase = of_iomap(np, 0);
127 struct regmap *regmap;
129 at91_pmc_base = regbase;
131 regmap = syscon_node_to_regmap(np);
133 panic("Could not retrieve syscon regmap");
135 pmc = kzalloc(sizeof(*pmc), GFP_KERNEL);
139 pmc->regmap = regmap;
142 regmap_write(pmc->regmap, AT91_PMC_IDR, 0xffffffff);
146 static void __init of_at91rm9200_pmc_setup(struct device_node *np)
148 of_at91_pmc_setup(np, &at91rm9200_caps);
150 CLK_OF_DECLARE(at91rm9200_clk_pmc, "atmel,at91rm9200-pmc",
151 of_at91rm9200_pmc_setup);
153 static void __init of_at91sam9260_pmc_setup(struct device_node *np)
155 of_at91_pmc_setup(np, &at91sam9260_caps);
157 CLK_OF_DECLARE(at91sam9260_clk_pmc, "atmel,at91sam9260-pmc",
158 of_at91sam9260_pmc_setup);
160 static void __init of_at91sam9g45_pmc_setup(struct device_node *np)
162 of_at91_pmc_setup(np, &at91sam9g45_caps);
164 CLK_OF_DECLARE(at91sam9g45_clk_pmc, "atmel,at91sam9g45-pmc",
165 of_at91sam9g45_pmc_setup);
167 static void __init of_at91sam9n12_pmc_setup(struct device_node *np)
169 of_at91_pmc_setup(np, &at91sam9n12_caps);
171 CLK_OF_DECLARE(at91sam9n12_clk_pmc, "atmel,at91sam9n12-pmc",
172 of_at91sam9n12_pmc_setup);
174 static void __init of_at91sam9x5_pmc_setup(struct device_node *np)
176 of_at91_pmc_setup(np, &at91sam9x5_caps);
178 CLK_OF_DECLARE(at91sam9x5_clk_pmc, "atmel,at91sam9x5-pmc",
179 of_at91sam9x5_pmc_setup);
181 static void __init of_sama5d2_pmc_setup(struct device_node *np)
183 of_at91_pmc_setup(np, &sama5d2_caps);
185 CLK_OF_DECLARE(sama5d2_clk_pmc, "atmel,sama5d2-pmc",
186 of_sama5d2_pmc_setup);
188 static void __init of_sama5d3_pmc_setup(struct device_node *np)
190 of_at91_pmc_setup(np, &sama5d3_caps);
192 CLK_OF_DECLARE(sama5d3_clk_pmc, "atmel,sama5d3-pmc",
193 of_sama5d3_pmc_setup);