clk: at91: pmc: move pmc structures to C file
[cascardo/linux.git] / drivers / clk / at91 / pmc.c
1 /*
2  *  Copyright (C) 2013 Boris BREZILLON <b.brezillon@overkiz.com>
3  *
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.
8  *
9  */
10
11 #include <linux/clk-provider.h>
12 #include <linux/clkdev.h>
13 #include <linux/clk/at91_pmc.h>
14 #include <linux/of.h>
15 #include <linux/of_address.h>
16 #include <linux/mfd/syscon.h>
17 #include <linux/regmap.h>
18
19 #include <asm/proc-fns.h>
20
21 #include "pmc.h"
22
23 struct at91_pmc_caps {
24         u32 available_irqs;
25 };
26
27 struct at91_pmc {
28         struct regmap *regmap;
29         const struct at91_pmc_caps *caps;
30 };
31
32 void __iomem *at91_pmc_base;
33 EXPORT_SYMBOL_GPL(at91_pmc_base);
34
35 void at91rm9200_idle(void)
36 {
37         /*
38          * Disable the processor clock.  The processor will be automatically
39          * re-enabled by an interrupt or by a reset.
40          */
41         at91_pmc_write(AT91_PMC_SCDR, AT91_PMC_PCK);
42 }
43
44 void at91sam9_idle(void)
45 {
46         at91_pmc_write(AT91_PMC_SCDR, AT91_PMC_PCK);
47         cpu_do_idle();
48 }
49
50 int of_at91_get_clk_range(struct device_node *np, const char *propname,
51                           struct clk_range *range)
52 {
53         u32 min, max;
54         int ret;
55
56         ret = of_property_read_u32_index(np, propname, 0, &min);
57         if (ret)
58                 return ret;
59
60         ret = of_property_read_u32_index(np, propname, 1, &max);
61         if (ret)
62                 return ret;
63
64         if (range) {
65                 range->min = min;
66                 range->max = max;
67         }
68
69         return 0;
70 }
71 EXPORT_SYMBOL_GPL(of_at91_get_clk_range);
72
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 |
77                           AT91_PMC_PCK3RDY,
78 };
79
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 |
83                           AT91_PMC_PCK1RDY,
84 };
85
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 |
89                           AT91_PMC_PCK1RDY,
90 };
91
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,
97 };
98
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,
104 };
105
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,
112 };
113
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 |
119                           AT91_PMC_CFDEV,
120 };
121
122 static void __init of_at91_pmc_setup(struct device_node *np,
123                                      const struct at91_pmc_caps *caps)
124 {
125         struct at91_pmc *pmc;
126         void __iomem *regbase = of_iomap(np, 0);
127         struct regmap *regmap;
128
129         at91_pmc_base = regbase;
130
131         regmap = syscon_node_to_regmap(np);
132         if (IS_ERR(regmap))
133                 panic("Could not retrieve syscon regmap");
134
135         pmc = kzalloc(sizeof(*pmc), GFP_KERNEL);
136         if (!pmc)
137                 return;
138
139         pmc->regmap = regmap;
140         pmc->caps = caps;
141
142         regmap_write(pmc->regmap, AT91_PMC_IDR, 0xffffffff);
143
144 }
145
146 static void __init of_at91rm9200_pmc_setup(struct device_node *np)
147 {
148         of_at91_pmc_setup(np, &at91rm9200_caps);
149 }
150 CLK_OF_DECLARE(at91rm9200_clk_pmc, "atmel,at91rm9200-pmc",
151                of_at91rm9200_pmc_setup);
152
153 static void __init of_at91sam9260_pmc_setup(struct device_node *np)
154 {
155         of_at91_pmc_setup(np, &at91sam9260_caps);
156 }
157 CLK_OF_DECLARE(at91sam9260_clk_pmc, "atmel,at91sam9260-pmc",
158                of_at91sam9260_pmc_setup);
159
160 static void __init of_at91sam9g45_pmc_setup(struct device_node *np)
161 {
162         of_at91_pmc_setup(np, &at91sam9g45_caps);
163 }
164 CLK_OF_DECLARE(at91sam9g45_clk_pmc, "atmel,at91sam9g45-pmc",
165                of_at91sam9g45_pmc_setup);
166
167 static void __init of_at91sam9n12_pmc_setup(struct device_node *np)
168 {
169         of_at91_pmc_setup(np, &at91sam9n12_caps);
170 }
171 CLK_OF_DECLARE(at91sam9n12_clk_pmc, "atmel,at91sam9n12-pmc",
172                of_at91sam9n12_pmc_setup);
173
174 static void __init of_at91sam9x5_pmc_setup(struct device_node *np)
175 {
176         of_at91_pmc_setup(np, &at91sam9x5_caps);
177 }
178 CLK_OF_DECLARE(at91sam9x5_clk_pmc, "atmel,at91sam9x5-pmc",
179                of_at91sam9x5_pmc_setup);
180
181 static void __init of_sama5d2_pmc_setup(struct device_node *np)
182 {
183         of_at91_pmc_setup(np, &sama5d2_caps);
184 }
185 CLK_OF_DECLARE(sama5d2_clk_pmc, "atmel,sama5d2-pmc",
186                of_sama5d2_pmc_setup);
187
188 static void __init of_sama5d3_pmc_setup(struct device_node *np)
189 {
190         of_at91_pmc_setup(np, &sama5d3_caps);
191 }
192 CLK_OF_DECLARE(sama5d3_clk_pmc, "atmel,sama5d3-pmc",
193                of_sama5d3_pmc_setup);