aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/clk/Kconfig8
-rw-r--r--drivers/clk/Makefile3
-rw-r--r--drivers/clk/clk-axi-clkgen.c331
-rw-r--r--drivers/clk/clk-composite.c201
-rw-r--r--drivers/clk/clk-mux.c50
-rw-r--r--drivers/clk/clk-prima2.c2
-rw-r--r--drivers/clk/clk-zynq.c1
-rw-r--r--drivers/clk/clk.c193
-rw-r--r--drivers/clk/mxs/clk.c1
-rw-r--r--drivers/clk/spear/spear1340_clock.c18
-rw-r--r--drivers/clk/sunxi/Makefile5
-rw-r--r--drivers/clk/sunxi/clk-factors.c180
-rw-r--r--drivers/clk/sunxi/clk-factors.h27
-rw-r--r--drivers/clk/sunxi/clk-sunxi.c362
-rw-r--r--drivers/clk/tegra/Makefile1
-rw-r--r--drivers/clk/tegra/clk-periph-gate.c11
-rw-r--r--drivers/clk/tegra/clk-periph.c14
-rw-r--r--drivers/clk/tegra/clk-pll.c1144
-rw-r--r--drivers/clk/tegra/clk-tegra114.c2085
-rw-r--r--drivers/clk/tegra/clk-tegra20.c220
-rw-r--r--drivers/clk/tegra/clk-tegra30.c276
-rw-r--r--drivers/clk/tegra/clk.c14
-rw-r--r--drivers/clk/tegra/clk.h121
-rw-r--r--drivers/clk/ux500/clk-prcmu.c136
-rw-r--r--drivers/clocksource/Kconfig9
-rw-r--r--drivers/clocksource/Makefile2
-rw-r--r--drivers/clocksource/arm_arch_timer.c33
-rw-r--r--drivers/clocksource/bcm2835_timer.c12
-rw-r--r--drivers/clocksource/cadence_ttc_timer.c436
-rw-r--r--drivers/clocksource/clksrc-of.c5
-rw-r--r--drivers/clocksource/em_sti.c13
-rw-r--r--drivers/clocksource/exynos_mct.c555
-rw-r--r--drivers/clocksource/sh_cmt.c189
-rw-r--r--drivers/clocksource/sh_mtu2.c2
-rw-r--r--drivers/clocksource/sh_tmu.c2
-rw-r--r--drivers/clocksource/sunxi_timer.c4
-rw-r--r--drivers/clocksource/tegra20_timer.c75
-rw-r--r--drivers/clocksource/vt8500_timer.c16
-rw-r--r--drivers/gpio/Kconfig6
-rw-r--r--drivers/gpio/Makefile1
-rw-r--r--drivers/gpio/gpio-samsung.c9
-rw-r--r--drivers/gpio/gpio-tegra.c21
-rw-r--r--drivers/gpio/gpio-vt8500.c355
-rw-r--r--drivers/irqchip/Kconfig8
-rw-r--r--drivers/irqchip/Makefile3
-rw-r--r--drivers/irqchip/irq-renesas-intc-irqpin.c547
-rw-r--r--drivers/irqchip/irq-renesas-irqc.c307
-rw-r--r--drivers/irqchip/irq-s3c24xx.c1355
-rw-r--r--drivers/mmc/host/s3cmci.c83
-rw-r--r--drivers/of/base.c111
-rw-r--r--drivers/pinctrl/Kconfig1
-rw-r--r--drivers/pinctrl/Makefile1
-rw-r--r--drivers/pinctrl/pinctrl-bcm2835.c19
-rw-r--r--drivers/pinctrl/pinctrl-exynos.c108
-rw-r--r--drivers/pinctrl/pinctrl-samsung.c2
-rw-r--r--drivers/pinctrl/pinctrl-samsung.h1
-rw-r--r--drivers/pinctrl/sh-pfc/pfc-sh73a0.c6
-rw-r--r--drivers/pinctrl/vt8500/Kconfig52
-rw-r--r--drivers/pinctrl/vt8500/Makefile8
-rw-r--r--drivers/pinctrl/vt8500/pinctrl-vt8500.c501
-rw-r--r--drivers/pinctrl/vt8500/pinctrl-wm8505.c532
-rw-r--r--drivers/pinctrl/vt8500/pinctrl-wm8650.c370
-rw-r--r--drivers/pinctrl/vt8500/pinctrl-wm8750.c409
-rw-r--r--drivers/pinctrl/vt8500/pinctrl-wm8850.c388
-rw-r--r--drivers/pinctrl/vt8500/pinctrl-wmt.c632
-rw-r--r--drivers/pinctrl/vt8500/pinctrl-wmt.h79
-rw-r--r--drivers/video/atmel_lcdfb.c120
67 files changed, 11691 insertions, 1101 deletions
diff --git a/drivers/clk/Kconfig b/drivers/clk/Kconfig
index a47e6ee98b8c..a64caefdba12 100644
--- a/drivers/clk/Kconfig
+++ b/drivers/clk/Kconfig
@@ -63,6 +63,14 @@ config CLK_TWL6040
63 McPDM. McPDM module is using the external bit clock on the McPDM bus 63 McPDM. McPDM module is using the external bit clock on the McPDM bus
64 as functional clock. 64 as functional clock.
65 65
66config COMMON_CLK_AXI_CLKGEN
67 tristate "AXI clkgen driver"
68 depends on ARCH_ZYNQ || MICROBLAZE
69 help
70 ---help---
71 Support for the Analog Devices axi-clkgen pcore clock generator for Xilinx
72 FPGAs. It is commonly used in Analog Devices' reference designs.
73
66endmenu 74endmenu
67 75
68source "drivers/clk/mvebu/Kconfig" 76source "drivers/clk/mvebu/Kconfig"
diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile
index 300d4775d926..79e98e416724 100644
--- a/drivers/clk/Makefile
+++ b/drivers/clk/Makefile
@@ -7,6 +7,7 @@ obj-$(CONFIG_COMMON_CLK) += clk-fixed-factor.o
7obj-$(CONFIG_COMMON_CLK) += clk-fixed-rate.o 7obj-$(CONFIG_COMMON_CLK) += clk-fixed-rate.o
8obj-$(CONFIG_COMMON_CLK) += clk-gate.o 8obj-$(CONFIG_COMMON_CLK) += clk-gate.o
9obj-$(CONFIG_COMMON_CLK) += clk-mux.o 9obj-$(CONFIG_COMMON_CLK) += clk-mux.o
10obj-$(CONFIG_COMMON_CLK) += clk-composite.o
10 11
11# SoCs specific 12# SoCs specific
12obj-$(CONFIG_ARCH_BCM2835) += clk-bcm2835.o 13obj-$(CONFIG_ARCH_BCM2835) += clk-bcm2835.o
@@ -23,6 +24,7 @@ ifeq ($(CONFIG_COMMON_CLK), y)
23obj-$(CONFIG_ARCH_MMP) += mmp/ 24obj-$(CONFIG_ARCH_MMP) += mmp/
24endif 25endif
25obj-$(CONFIG_MACH_LOONGSON1) += clk-ls1x.o 26obj-$(CONFIG_MACH_LOONGSON1) += clk-ls1x.o
27obj-$(CONFIG_ARCH_SUNXI) += sunxi/
26obj-$(CONFIG_ARCH_U8500) += ux500/ 28obj-$(CONFIG_ARCH_U8500) += ux500/
27obj-$(CONFIG_ARCH_VT8500) += clk-vt8500.o 29obj-$(CONFIG_ARCH_VT8500) += clk-vt8500.o
28obj-$(CONFIG_ARCH_ZYNQ) += clk-zynq.o 30obj-$(CONFIG_ARCH_ZYNQ) += clk-zynq.o
@@ -31,6 +33,7 @@ obj-$(CONFIG_ARCH_TEGRA) += tegra/
31obj-$(CONFIG_X86) += x86/ 33obj-$(CONFIG_X86) += x86/
32 34
33# Chip specific 35# Chip specific
36obj-$(CONFIG_COMMON_CLK_AXI_CLKGEN) += clk-axi-clkgen.o
34obj-$(CONFIG_COMMON_CLK_WM831X) += clk-wm831x.o 37obj-$(CONFIG_COMMON_CLK_WM831X) += clk-wm831x.o
35obj-$(CONFIG_COMMON_CLK_MAX77686) += clk-max77686.o 38obj-$(CONFIG_COMMON_CLK_MAX77686) += clk-max77686.o
36obj-$(CONFIG_CLK_TWL6040) += clk-twl6040.o 39obj-$(CONFIG_CLK_TWL6040) += clk-twl6040.o
diff --git a/drivers/clk/clk-axi-clkgen.c b/drivers/clk/clk-axi-clkgen.c
new file mode 100644
index 000000000000..8137327847c3
--- /dev/null
+++ b/drivers/clk/clk-axi-clkgen.c
@@ -0,0 +1,331 @@
1/*
2 * AXI clkgen driver
3 *
4 * Copyright 2012-2013 Analog Devices Inc.
5 * Author: Lars-Peter Clausen <lars@metafoo.de>
6 *
7 * Licensed under the GPL-2.
8 *
9 */
10
11#include <linux/platform_device.h>
12#include <linux/clk-provider.h>
13#include <linux/clk.h>
14#include <linux/slab.h>
15#include <linux/io.h>
16#include <linux/of.h>
17#include <linux/module.h>
18#include <linux/err.h>
19
20#define AXI_CLKGEN_REG_UPDATE_ENABLE 0x04
21#define AXI_CLKGEN_REG_CLK_OUT1 0x08
22#define AXI_CLKGEN_REG_CLK_OUT2 0x0c
23#define AXI_CLKGEN_REG_CLK_DIV 0x10
24#define AXI_CLKGEN_REG_CLK_FB1 0x14
25#define AXI_CLKGEN_REG_CLK_FB2 0x18
26#define AXI_CLKGEN_REG_LOCK1 0x1c
27#define AXI_CLKGEN_REG_LOCK2 0x20
28#define AXI_CLKGEN_REG_LOCK3 0x24
29#define AXI_CLKGEN_REG_FILTER1 0x28
30#define AXI_CLKGEN_REG_FILTER2 0x2c
31
32struct axi_clkgen {
33 void __iomem *base;
34 struct clk_hw clk_hw;
35};
36
37static uint32_t axi_clkgen_lookup_filter(unsigned int m)
38{
39 switch (m) {
40 case 0:
41 return 0x01001990;
42 case 1:
43 return 0x01001190;
44 case 2:
45 return 0x01009890;
46 case 3:
47 return 0x01001890;
48 case 4:
49 return 0x01008890;
50 case 5 ... 8:
51 return 0x01009090;
52 case 9 ... 11:
53 return 0x01000890;
54 case 12:
55 return 0x08009090;
56 case 13 ... 22:
57 return 0x01001090;
58 case 23 ... 36:
59 return 0x01008090;
60 case 37 ... 46:
61 return 0x08001090;
62 default:
63 return 0x08008090;
64 }
65}
66
67static const uint32_t axi_clkgen_lock_table[] = {
68 0x060603e8, 0x060603e8, 0x080803e8, 0x0b0b03e8,
69 0x0e0e03e8, 0x111103e8, 0x131303e8, 0x161603e8,
70 0x191903e8, 0x1c1c03e8, 0x1f1f0384, 0x1f1f0339,
71 0x1f1f02ee, 0x1f1f02bc, 0x1f1f028a, 0x1f1f0271,
72 0x1f1f023f, 0x1f1f0226, 0x1f1f020d, 0x1f1f01f4,
73 0x1f1f01db, 0x1f1f01c2, 0x1f1f01a9, 0x1f1f0190,
74 0x1f1f0190, 0x1f1f0177, 0x1f1f015e, 0x1f1f015e,
75 0x1f1f0145, 0x1f1f0145, 0x1f1f012c, 0x1f1f012c,
76 0x1f1f012c, 0x1f1f0113, 0x1f1f0113, 0x1f1f0113,
77};
78
79static uint32_t axi_clkgen_lookup_lock(unsigned int m)
80{
81 if (m < ARRAY_SIZE(axi_clkgen_lock_table))
82 return axi_clkgen_lock_table[m];
83 return 0x1f1f00fa;
84}
85
86static const unsigned int fpfd_min = 10000;
87static const unsigned int fpfd_max = 300000;
88static const unsigned int fvco_min = 600000;
89static const unsigned int fvco_max = 1200000;
90
91static void axi_clkgen_calc_params(unsigned long fin, unsigned long fout,
92 unsigned int *best_d, unsigned int *best_m, unsigned int *best_dout)
93{
94 unsigned long d, d_min, d_max, _d_min, _d_max;
95 unsigned long m, m_min, m_max;
96 unsigned long f, dout, best_f, fvco;
97
98 fin /= 1000;
99 fout /= 1000;
100
101 best_f = ULONG_MAX;
102 *best_d = 0;
103 *best_m = 0;
104 *best_dout = 0;
105
106 d_min = max_t(unsigned long, DIV_ROUND_UP(fin, fpfd_max), 1);
107 d_max = min_t(unsigned long, fin / fpfd_min, 80);
108
109 m_min = max_t(unsigned long, DIV_ROUND_UP(fvco_min, fin) * d_min, 1);
110 m_max = min_t(unsigned long, fvco_max * d_max / fin, 64);
111
112 for (m = m_min; m <= m_max; m++) {
113 _d_min = max(d_min, DIV_ROUND_UP(fin * m, fvco_max));
114 _d_max = min(d_max, fin * m / fvco_min);
115
116 for (d = _d_min; d <= _d_max; d++) {
117 fvco = fin * m / d;
118
119 dout = DIV_ROUND_CLOSEST(fvco, fout);
120 dout = clamp_t(unsigned long, dout, 1, 128);
121 f = fvco / dout;
122 if (abs(f - fout) < abs(best_f - fout)) {
123 best_f = f;
124 *best_d = d;
125 *best_m = m;
126 *best_dout = dout;
127 if (best_f == fout)
128 return;
129 }
130 }
131 }
132}
133
134static void axi_clkgen_calc_clk_params(unsigned int divider, unsigned int *low,
135 unsigned int *high, unsigned int *edge, unsigned int *nocount)
136{
137 if (divider == 1)
138 *nocount = 1;
139 else
140 *nocount = 0;
141
142 *high = divider / 2;
143 *edge = divider % 2;
144 *low = divider - *high;
145}
146
147static void axi_clkgen_write(struct axi_clkgen *axi_clkgen,
148 unsigned int reg, unsigned int val)
149{
150 writel(val, axi_clkgen->base + reg);
151}
152
153static void axi_clkgen_read(struct axi_clkgen *axi_clkgen,
154 unsigned int reg, unsigned int *val)
155{
156 *val = readl(axi_clkgen->base + reg);
157}
158
159static struct axi_clkgen *clk_hw_to_axi_clkgen(struct clk_hw *clk_hw)
160{
161 return container_of(clk_hw, struct axi_clkgen, clk_hw);
162}
163
164static int axi_clkgen_set_rate(struct clk_hw *clk_hw,
165 unsigned long rate, unsigned long parent_rate)
166{
167 struct axi_clkgen *axi_clkgen = clk_hw_to_axi_clkgen(clk_hw);
168 unsigned int d, m, dout;
169 unsigned int nocount;
170 unsigned int high;
171 unsigned int edge;
172 unsigned int low;
173 uint32_t filter;
174 uint32_t lock;
175
176 if (parent_rate == 0 || rate == 0)
177 return -EINVAL;
178
179 axi_clkgen_calc_params(parent_rate, rate, &d, &m, &dout);
180
181 if (d == 0 || dout == 0 || m == 0)
182 return -EINVAL;
183
184 filter = axi_clkgen_lookup_filter(m - 1);
185 lock = axi_clkgen_lookup_lock(m - 1);
186
187 axi_clkgen_write(axi_clkgen, AXI_CLKGEN_REG_UPDATE_ENABLE, 0);
188
189 axi_clkgen_calc_clk_params(dout, &low, &high, &edge, &nocount);
190 axi_clkgen_write(axi_clkgen, AXI_CLKGEN_REG_CLK_OUT1,
191 (high << 6) | low);
192 axi_clkgen_write(axi_clkgen, AXI_CLKGEN_REG_CLK_OUT2,
193 (edge << 7) | (nocount << 6));
194
195 axi_clkgen_calc_clk_params(d, &low, &high, &edge, &nocount);
196 axi_clkgen_write(axi_clkgen, AXI_CLKGEN_REG_CLK_DIV,
197 (edge << 13) | (nocount << 12) | (high << 6) | low);
198
199 axi_clkgen_calc_clk_params(m, &low, &high, &edge, &nocount);
200 axi_clkgen_write(axi_clkgen, AXI_CLKGEN_REG_CLK_FB1,
201 (high << 6) | low);
202 axi_clkgen_write(axi_clkgen, AXI_CLKGEN_REG_CLK_FB2,
203 (edge << 7) | (nocount << 6));
204
205 axi_clkgen_write(axi_clkgen, AXI_CLKGEN_REG_LOCK1, lock & 0x3ff);
206 axi_clkgen_write(axi_clkgen, AXI_CLKGEN_REG_LOCK2,
207 (((lock >> 16) & 0x1f) << 10) | 0x1);
208 axi_clkgen_write(axi_clkgen, AXI_CLKGEN_REG_LOCK3,
209 (((lock >> 24) & 0x1f) << 10) | 0x3e9);
210 axi_clkgen_write(axi_clkgen, AXI_CLKGEN_REG_FILTER1, filter >> 16);
211 axi_clkgen_write(axi_clkgen, AXI_CLKGEN_REG_FILTER2, filter);
212
213 axi_clkgen_write(axi_clkgen, AXI_CLKGEN_REG_UPDATE_ENABLE, 1);
214
215 return 0;
216}
217
218static long axi_clkgen_round_rate(struct clk_hw *hw, unsigned long rate,
219 unsigned long *parent_rate)
220{
221 unsigned int d, m, dout;
222
223 axi_clkgen_calc_params(*parent_rate, rate, &d, &m, &dout);
224
225 if (d == 0 || dout == 0 || m == 0)
226 return -EINVAL;
227
228 return *parent_rate / d * m / dout;
229}
230
231static unsigned long axi_clkgen_recalc_rate(struct clk_hw *clk_hw,
232 unsigned long parent_rate)
233{
234 struct axi_clkgen *axi_clkgen = clk_hw_to_axi_clkgen(clk_hw);
235 unsigned int d, m, dout;
236 unsigned int reg;
237 unsigned long long tmp;
238
239 axi_clkgen_read(axi_clkgen, AXI_CLKGEN_REG_CLK_OUT1, &reg);
240 dout = (reg & 0x3f) + ((reg >> 6) & 0x3f);
241 axi_clkgen_read(axi_clkgen, AXI_CLKGEN_REG_CLK_DIV, &reg);
242 d = (reg & 0x3f) + ((reg >> 6) & 0x3f);
243 axi_clkgen_read(axi_clkgen, AXI_CLKGEN_REG_CLK_FB1, &reg);
244 m = (reg & 0x3f) + ((reg >> 6) & 0x3f);
245
246 if (d == 0 || dout == 0)
247 return 0;
248
249 tmp = (unsigned long long)(parent_rate / d) * m;
250 do_div(tmp, dout);
251
252 if (tmp > ULONG_MAX)
253 return ULONG_MAX;
254
255 return tmp;
256}
257
258static const struct clk_ops axi_clkgen_ops = {
259 .recalc_rate = axi_clkgen_recalc_rate,
260 .round_rate = axi_clkgen_round_rate,
261 .set_rate = axi_clkgen_set_rate,
262};
263
264static int axi_clkgen_probe(struct platform_device *pdev)
265{
266 struct axi_clkgen *axi_clkgen;
267 struct clk_init_data init;
268 const char *parent_name;
269 const char *clk_name;
270 struct resource *mem;
271 struct clk *clk;
272
273 axi_clkgen = devm_kzalloc(&pdev->dev, sizeof(*axi_clkgen), GFP_KERNEL);
274 if (!axi_clkgen)
275 return -ENOMEM;
276
277 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
278 axi_clkgen->base = devm_ioremap_resource(&pdev->dev, mem);
279 if (IS_ERR(axi_clkgen->base))
280 return PTR_ERR(axi_clkgen->base);
281
282 parent_name = of_clk_get_parent_name(pdev->dev.of_node, 0);
283 if (!parent_name)
284 return -EINVAL;
285
286 clk_name = pdev->dev.of_node->name;
287 of_property_read_string(pdev->dev.of_node, "clock-output-names",
288 &clk_name);
289
290 init.name = clk_name;
291 init.ops = &axi_clkgen_ops;
292 init.flags = 0;
293 init.parent_names = &parent_name;
294 init.num_parents = 1;
295
296 axi_clkgen->clk_hw.init = &init;
297 clk = devm_clk_register(&pdev->dev, &axi_clkgen->clk_hw);
298 if (IS_ERR(clk))
299 return PTR_ERR(clk);
300
301 return of_clk_add_provider(pdev->dev.of_node, of_clk_src_simple_get,
302 clk);
303}
304
305static int axi_clkgen_remove(struct platform_device *pdev)
306{
307 of_clk_del_provider(pdev->dev.of_node);
308
309 return 0;
310}
311
312static const struct of_device_id axi_clkgen_ids[] = {
313 { .compatible = "adi,axi-clkgen-1.00.a" },
314 { },
315};
316MODULE_DEVICE_TABLE(of, axi_clkgen_ids);
317
318static struct platform_driver axi_clkgen_driver = {
319 .driver = {
320 .name = "adi-axi-clkgen",
321 .owner = THIS_MODULE,
322 .of_match_table = axi_clkgen_ids,
323 },
324 .probe = axi_clkgen_probe,
325 .remove = axi_clkgen_remove,
326};
327module_platform_driver(axi_clkgen_driver);
328
329MODULE_LICENSE("GPL v2");
330MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
331MODULE_DESCRIPTION("Driver for the Analog Devices' AXI clkgen pcore clock generator");
diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
new file mode 100644
index 000000000000..097dee4fd209
--- /dev/null
+++ b/drivers/clk/clk-composite.c
@@ -0,0 +1,201 @@
1/*
2 * Copyright (c) 2013 NVIDIA CORPORATION. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#include <linux/clk.h>
18#include <linux/clk-provider.h>
19#include <linux/err.h>
20#include <linux/slab.h>
21
22#define to_clk_composite(_hw) container_of(_hw, struct clk_composite, hw)
23
24static u8 clk_composite_get_parent(struct clk_hw *hw)
25{
26 struct clk_composite *composite = to_clk_composite(hw);
27 const struct clk_ops *mux_ops = composite->mux_ops;
28 struct clk_hw *mux_hw = composite->mux_hw;
29
30 mux_hw->clk = hw->clk;
31
32 return mux_ops->get_parent(mux_hw);
33}
34
35static int clk_composite_set_parent(struct clk_hw *hw, u8 index)
36{
37 struct clk_composite *composite = to_clk_composite(hw);
38 const struct clk_ops *mux_ops = composite->mux_ops;
39 struct clk_hw *mux_hw = composite->mux_hw;
40
41 mux_hw->clk = hw->clk;
42
43 return mux_ops->set_parent(mux_hw, index);
44}
45
46static unsigned long clk_composite_recalc_rate(struct clk_hw *hw,
47 unsigned long parent_rate)
48{
49 struct clk_composite *composite = to_clk_composite(hw);
50 const struct clk_ops *div_ops = composite->div_ops;
51 struct clk_hw *div_hw = composite->div_hw;
52
53 div_hw->clk = hw->clk;
54
55 return div_ops->recalc_rate(div_hw, parent_rate);
56}
57
58static long clk_composite_round_rate(struct clk_hw *hw, unsigned long rate,
59 unsigned long *prate)
60{
61 struct clk_composite *composite = to_clk_composite(hw);
62 const struct clk_ops *div_ops = composite->div_ops;
63 struct clk_hw *div_hw = composite->div_hw;
64
65 div_hw->clk = hw->clk;
66
67 return div_ops->round_rate(div_hw, rate, prate);
68}
69
70static int clk_composite_set_rate(struct clk_hw *hw, unsigned long rate,
71 unsigned long parent_rate)
72{
73 struct clk_composite *composite = to_clk_composite(hw);
74 const struct clk_ops *div_ops = composite->div_ops;
75 struct clk_hw *div_hw = composite->div_hw;
76
77 div_hw->clk = hw->clk;
78
79 return div_ops->set_rate(div_hw, rate, parent_rate);
80}
81
82static int clk_composite_is_enabled(struct clk_hw *hw)
83{
84 struct clk_composite *composite = to_clk_composite(hw);
85 const struct clk_ops *gate_ops = composite->gate_ops;
86 struct clk_hw *gate_hw = composite->gate_hw;
87
88 gate_hw->clk = hw->clk;
89
90 return gate_ops->is_enabled(gate_hw);
91}
92
93static int clk_composite_enable(struct clk_hw *hw)
94{
95 struct clk_composite *composite = to_clk_composite(hw);
96 const struct clk_ops *gate_ops = composite->gate_ops;
97 struct clk_hw *gate_hw = composite->gate_hw;
98
99 gate_hw->clk = hw->clk;
100
101 return gate_ops->enable(gate_hw);
102}
103
104static void clk_composite_disable(struct clk_hw *hw)
105{
106 struct clk_composite *composite = to_clk_composite(hw);
107 const struct clk_ops *gate_ops = composite->gate_ops;
108 struct clk_hw *gate_hw = composite->gate_hw;
109
110 gate_hw->clk = hw->clk;
111
112 gate_ops->disable(gate_hw);
113}
114
115struct clk *clk_register_composite(struct device *dev, const char *name,
116 const char **parent_names, int num_parents,
117 struct clk_hw *mux_hw, const struct clk_ops *mux_ops,
118 struct clk_hw *div_hw, const struct clk_ops *div_ops,
119 struct clk_hw *gate_hw, const struct clk_ops *gate_ops,
120 unsigned long flags)
121{
122 struct clk *clk;
123 struct clk_init_data init;
124 struct clk_composite *composite;
125 struct clk_ops *clk_composite_ops;
126
127 composite = kzalloc(sizeof(*composite), GFP_KERNEL);
128 if (!composite) {
129 pr_err("%s: could not allocate composite clk\n", __func__);
130 return ERR_PTR(-ENOMEM);
131 }
132
133 init.name = name;
134 init.flags = flags | CLK_IS_BASIC;
135 init.parent_names = parent_names;
136 init.num_parents = num_parents;
137
138 clk_composite_ops = &composite->ops;
139
140 if (mux_hw && mux_ops) {
141 if (!mux_ops->get_parent || !mux_ops->set_parent) {
142 clk = ERR_PTR(-EINVAL);
143 goto err;
144 }
145
146 composite->mux_hw = mux_hw;
147 composite->mux_ops = mux_ops;
148 clk_composite_ops->get_parent = clk_composite_get_parent;
149 clk_composite_ops->set_parent = clk_composite_set_parent;
150 }
151
152 if (div_hw && div_ops) {
153 if (!div_ops->recalc_rate || !div_ops->round_rate ||
154 !div_ops->set_rate) {
155 clk = ERR_PTR(-EINVAL);
156 goto err;
157 }
158
159 composite->div_hw = div_hw;
160 composite->div_ops = div_ops;
161 clk_composite_ops->recalc_rate = clk_composite_recalc_rate;
162 clk_composite_ops->round_rate = clk_composite_round_rate;
163 clk_composite_ops->set_rate = clk_composite_set_rate;
164 }
165
166 if (gate_hw && gate_ops) {
167 if (!gate_ops->is_enabled || !gate_ops->enable ||
168 !gate_ops->disable) {
169 clk = ERR_PTR(-EINVAL);
170 goto err;
171 }
172
173 composite->gate_hw = gate_hw;
174 composite->gate_ops = gate_ops;
175 clk_composite_ops->is_enabled = clk_composite_is_enabled;
176 clk_composite_ops->enable = clk_composite_enable;
177 clk_composite_ops->disable = clk_composite_disable;
178 }
179
180 init.ops = clk_composite_ops;
181 composite->hw.init = &init;
182
183 clk = clk_register(dev, &composite->hw);
184 if (IS_ERR(clk))
185 goto err;
186
187 if (composite->mux_hw)
188 composite->mux_hw->clk = clk;
189
190 if (composite->div_hw)
191 composite->div_hw->clk = clk;
192
193 if (composite->gate_hw)
194 composite->gate_hw->clk = clk;
195
196 return clk;
197
198err:
199 kfree(composite);
200 return clk;
201}
diff --git a/drivers/clk/clk-mux.c b/drivers/clk/clk-mux.c
index 508c032edce4..25b1734560d0 100644
--- a/drivers/clk/clk-mux.c
+++ b/drivers/clk/clk-mux.c
@@ -32,6 +32,7 @@
32static u8 clk_mux_get_parent(struct clk_hw *hw) 32static u8 clk_mux_get_parent(struct clk_hw *hw)
33{ 33{
34 struct clk_mux *mux = to_clk_mux(hw); 34 struct clk_mux *mux = to_clk_mux(hw);
35 int num_parents = __clk_get_num_parents(hw->clk);
35 u32 val; 36 u32 val;
36 37
37 /* 38 /*
@@ -42,7 +43,16 @@ static u8 clk_mux_get_parent(struct clk_hw *hw)
42 * val = 0x4 really means "bit 2, index starts at bit 0" 43 * val = 0x4 really means "bit 2, index starts at bit 0"
43 */ 44 */
44 val = readl(mux->reg) >> mux->shift; 45 val = readl(mux->reg) >> mux->shift;
45 val &= (1 << mux->width) - 1; 46 val &= mux->mask;
47
48 if (mux->table) {
49 int i;
50
51 for (i = 0; i < num_parents; i++)
52 if (mux->table[i] == val)
53 return i;
54 return -EINVAL;
55 }
46 56
47 if (val && (mux->flags & CLK_MUX_INDEX_BIT)) 57 if (val && (mux->flags & CLK_MUX_INDEX_BIT))
48 val = ffs(val) - 1; 58 val = ffs(val) - 1;
@@ -50,7 +60,7 @@ static u8 clk_mux_get_parent(struct clk_hw *hw)
50 if (val && (mux->flags & CLK_MUX_INDEX_ONE)) 60 if (val && (mux->flags & CLK_MUX_INDEX_ONE))
51 val--; 61 val--;
52 62
53 if (val >= __clk_get_num_parents(hw->clk)) 63 if (val >= num_parents)
54 return -EINVAL; 64 return -EINVAL;
55 65
56 return val; 66 return val;
@@ -62,17 +72,22 @@ static int clk_mux_set_parent(struct clk_hw *hw, u8 index)
62 u32 val; 72 u32 val;
63 unsigned long flags = 0; 73 unsigned long flags = 0;
64 74
65 if (mux->flags & CLK_MUX_INDEX_BIT) 75 if (mux->table)
66 index = (1 << ffs(index)); 76 index = mux->table[index];
67 77
68 if (mux->flags & CLK_MUX_INDEX_ONE) 78 else {
69 index++; 79 if (mux->flags & CLK_MUX_INDEX_BIT)
80 index = (1 << ffs(index));
81
82 if (mux->flags & CLK_MUX_INDEX_ONE)
83 index++;
84 }
70 85
71 if (mux->lock) 86 if (mux->lock)
72 spin_lock_irqsave(mux->lock, flags); 87 spin_lock_irqsave(mux->lock, flags);
73 88
74 val = readl(mux->reg); 89 val = readl(mux->reg);
75 val &= ~(((1 << mux->width) - 1) << mux->shift); 90 val &= ~(mux->mask << mux->shift);
76 val |= index << mux->shift; 91 val |= index << mux->shift;
77 writel(val, mux->reg); 92 writel(val, mux->reg);
78 93
@@ -88,10 +103,10 @@ const struct clk_ops clk_mux_ops = {
88}; 103};
89EXPORT_SYMBOL_GPL(clk_mux_ops); 104EXPORT_SYMBOL_GPL(clk_mux_ops);
90 105
91struct clk *clk_register_mux(struct device *dev, const char *name, 106struct clk *clk_register_mux_table(struct device *dev, const char *name,
92 const char **parent_names, u8 num_parents, unsigned long flags, 107 const char **parent_names, u8 num_parents, unsigned long flags,
93 void __iomem *reg, u8 shift, u8 width, 108 void __iomem *reg, u8 shift, u32 mask,
94 u8 clk_mux_flags, spinlock_t *lock) 109 u8 clk_mux_flags, u32 *table, spinlock_t *lock)
95{ 110{
96 struct clk_mux *mux; 111 struct clk_mux *mux;
97 struct clk *clk; 112 struct clk *clk;
@@ -113,9 +128,10 @@ struct clk *clk_register_mux(struct device *dev, const char *name,
113 /* struct clk_mux assignments */ 128 /* struct clk_mux assignments */
114 mux->reg = reg; 129 mux->reg = reg;
115 mux->shift = shift; 130 mux->shift = shift;
116 mux->width = width; 131 mux->mask = mask;
117 mux->flags = clk_mux_flags; 132 mux->flags = clk_mux_flags;
118 mux->lock = lock; 133 mux->lock = lock;
134 mux->table = table;
119 mux->hw.init = &init; 135 mux->hw.init = &init;
120 136
121 clk = clk_register(dev, &mux->hw); 137 clk = clk_register(dev, &mux->hw);
@@ -125,3 +141,15 @@ struct clk *clk_register_mux(struct device *dev, const char *name,
125 141
126 return clk; 142 return clk;
127} 143}
144
145struct clk *clk_register_mux(struct device *dev, const char *name,
146 const char **parent_names, u8 num_parents, unsigned long flags,
147 void __iomem *reg, u8 shift, u8 width,
148 u8 clk_mux_flags, spinlock_t *lock)
149{
150 u32 mask = BIT(width) - 1;
151
152 return clk_register_mux_table(dev, name, parent_names, num_parents,
153 flags, reg, shift, mask, clk_mux_flags,
154 NULL, lock);
155}
diff --git a/drivers/clk/clk-prima2.c b/drivers/clk/clk-prima2.c
index f8e9d0c27be2..643ca653fef0 100644
--- a/drivers/clk/clk-prima2.c
+++ b/drivers/clk/clk-prima2.c
@@ -1113,7 +1113,7 @@ void __init sirfsoc_of_clk_init(void)
1113 1113
1114 for (i = pll1; i < maxclk; i++) { 1114 for (i = pll1; i < maxclk; i++) {
1115 prima2_clks[i] = clk_register(NULL, prima2_clk_hw_array[i]); 1115 prima2_clks[i] = clk_register(NULL, prima2_clk_hw_array[i]);
1116 BUG_ON(!prima2_clks[i]); 1116 BUG_ON(IS_ERR(prima2_clks[i]));
1117 } 1117 }
1118 clk_register_clkdev(prima2_clks[cpu], NULL, "cpu"); 1118 clk_register_clkdev(prima2_clks[cpu], NULL, "cpu");
1119 clk_register_clkdev(prima2_clks[io], NULL, "io"); 1119 clk_register_clkdev(prima2_clks[io], NULL, "io");
diff --git a/drivers/clk/clk-zynq.c b/drivers/clk/clk-zynq.c
index b14a25f39255..32062977f453 100644
--- a/drivers/clk/clk-zynq.c
+++ b/drivers/clk/clk-zynq.c
@@ -20,6 +20,7 @@
20#include <linux/slab.h> 20#include <linux/slab.h>
21#include <linux/kernel.h> 21#include <linux/kernel.h>
22#include <linux/clk-provider.h> 22#include <linux/clk-provider.h>
23#include <linux/clk/zynq.h>
23 24
24static void __iomem *slcr_base; 25static void __iomem *slcr_base;
25 26
diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index ed87b2405806..0230c9d95975 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -19,14 +19,77 @@
19#include <linux/of.h> 19#include <linux/of.h>
20#include <linux/device.h> 20#include <linux/device.h>
21#include <linux/init.h> 21#include <linux/init.h>
22#include <linux/sched.h>
22 23
23static DEFINE_SPINLOCK(enable_lock); 24static DEFINE_SPINLOCK(enable_lock);
24static DEFINE_MUTEX(prepare_lock); 25static DEFINE_MUTEX(prepare_lock);
25 26
27static struct task_struct *prepare_owner;
28static struct task_struct *enable_owner;
29
30static int prepare_refcnt;
31static int enable_refcnt;
32
26static HLIST_HEAD(clk_root_list); 33static HLIST_HEAD(clk_root_list);
27static HLIST_HEAD(clk_orphan_list); 34static HLIST_HEAD(clk_orphan_list);
28static LIST_HEAD(clk_notifier_list); 35static LIST_HEAD(clk_notifier_list);
29 36
37/*** locking ***/
38static void clk_prepare_lock(void)
39{
40 if (!mutex_trylock(&prepare_lock)) {
41 if (prepare_owner == current) {
42 prepare_refcnt++;
43 return;
44 }
45 mutex_lock(&prepare_lock);
46 }
47 WARN_ON_ONCE(prepare_owner != NULL);
48 WARN_ON_ONCE(prepare_refcnt != 0);
49 prepare_owner = current;
50 prepare_refcnt = 1;
51}
52
53static void clk_prepare_unlock(void)
54{
55 WARN_ON_ONCE(prepare_owner != current);
56 WARN_ON_ONCE(prepare_refcnt == 0);
57
58 if (--prepare_refcnt)
59 return;
60 prepare_owner = NULL;
61 mutex_unlock(&prepare_lock);
62}
63
64static unsigned long clk_enable_lock(void)
65{
66 unsigned long flags;
67
68 if (!spin_trylock_irqsave(&enable_lock, flags)) {
69 if (enable_owner == current) {
70 enable_refcnt++;
71 return flags;
72 }
73 spin_lock_irqsave(&enable_lock, flags);
74 }
75 WARN_ON_ONCE(enable_owner != NULL);
76 WARN_ON_ONCE(enable_refcnt != 0);
77 enable_owner = current;
78 enable_refcnt = 1;
79 return flags;
80}
81
82static void clk_enable_unlock(unsigned long flags)
83{
84 WARN_ON_ONCE(enable_owner != current);
85 WARN_ON_ONCE(enable_refcnt == 0);
86
87 if (--enable_refcnt)
88 return;
89 enable_owner = NULL;
90 spin_unlock_irqrestore(&enable_lock, flags);
91}
92
30/*** debugfs support ***/ 93/*** debugfs support ***/
31 94
32#ifdef CONFIG_COMMON_CLK_DEBUG 95#ifdef CONFIG_COMMON_CLK_DEBUG
@@ -69,7 +132,7 @@ static int clk_summary_show(struct seq_file *s, void *data)
69 seq_printf(s, " clock enable_cnt prepare_cnt rate\n"); 132 seq_printf(s, " clock enable_cnt prepare_cnt rate\n");
70 seq_printf(s, "---------------------------------------------------------------------\n"); 133 seq_printf(s, "---------------------------------------------------------------------\n");
71 134
72 mutex_lock(&prepare_lock); 135 clk_prepare_lock();
73 136
74 hlist_for_each_entry(c, &clk_root_list, child_node) 137 hlist_for_each_entry(c, &clk_root_list, child_node)
75 clk_summary_show_subtree(s, c, 0); 138 clk_summary_show_subtree(s, c, 0);
@@ -77,7 +140,7 @@ static int clk_summary_show(struct seq_file *s, void *data)
77 hlist_for_each_entry(c, &clk_orphan_list, child_node) 140 hlist_for_each_entry(c, &clk_orphan_list, child_node)
78 clk_summary_show_subtree(s, c, 0); 141 clk_summary_show_subtree(s, c, 0);
79 142
80 mutex_unlock(&prepare_lock); 143 clk_prepare_unlock();
81 144
82 return 0; 145 return 0;
83} 146}
@@ -130,7 +193,7 @@ static int clk_dump(struct seq_file *s, void *data)
130 193
131 seq_printf(s, "{"); 194 seq_printf(s, "{");
132 195
133 mutex_lock(&prepare_lock); 196 clk_prepare_lock();
134 197
135 hlist_for_each_entry(c, &clk_root_list, child_node) { 198 hlist_for_each_entry(c, &clk_root_list, child_node) {
136 if (!first_node) 199 if (!first_node)
@@ -144,7 +207,7 @@ static int clk_dump(struct seq_file *s, void *data)
144 clk_dump_subtree(s, c, 0); 207 clk_dump_subtree(s, c, 0);
145 } 208 }
146 209
147 mutex_unlock(&prepare_lock); 210 clk_prepare_unlock();
148 211
149 seq_printf(s, "}"); 212 seq_printf(s, "}");
150 return 0; 213 return 0;
@@ -316,7 +379,7 @@ static int __init clk_debug_init(void)
316 if (!orphandir) 379 if (!orphandir)
317 return -ENOMEM; 380 return -ENOMEM;
318 381
319 mutex_lock(&prepare_lock); 382 clk_prepare_lock();
320 383
321 hlist_for_each_entry(clk, &clk_root_list, child_node) 384 hlist_for_each_entry(clk, &clk_root_list, child_node)
322 clk_debug_create_subtree(clk, rootdir); 385 clk_debug_create_subtree(clk, rootdir);
@@ -326,7 +389,7 @@ static int __init clk_debug_init(void)
326 389
327 inited = 1; 390 inited = 1;
328 391
329 mutex_unlock(&prepare_lock); 392 clk_prepare_unlock();
330 393
331 return 0; 394 return 0;
332} 395}
@@ -336,6 +399,31 @@ static inline int clk_debug_register(struct clk *clk) { return 0; }
336#endif 399#endif
337 400
338/* caller must hold prepare_lock */ 401/* caller must hold prepare_lock */
402static void clk_unprepare_unused_subtree(struct clk *clk)
403{
404 struct clk *child;
405
406 if (!clk)
407 return;
408
409 hlist_for_each_entry(child, &clk->children, child_node)
410 clk_unprepare_unused_subtree(child);
411
412 if (clk->prepare_count)
413 return;
414
415 if (clk->flags & CLK_IGNORE_UNUSED)
416 return;
417
418 if (__clk_is_prepared(clk)) {
419 if (clk->ops->unprepare_unused)
420 clk->ops->unprepare_unused(clk->hw);
421 else if (clk->ops->unprepare)
422 clk->ops->unprepare(clk->hw);
423 }
424}
425
426/* caller must hold prepare_lock */
339static void clk_disable_unused_subtree(struct clk *clk) 427static void clk_disable_unused_subtree(struct clk *clk)
340{ 428{
341 struct clk *child; 429 struct clk *child;
@@ -347,7 +435,7 @@ static void clk_disable_unused_subtree(struct clk *clk)
347 hlist_for_each_entry(child, &clk->children, child_node) 435 hlist_for_each_entry(child, &clk->children, child_node)
348 clk_disable_unused_subtree(child); 436 clk_disable_unused_subtree(child);
349 437
350 spin_lock_irqsave(&enable_lock, flags); 438 flags = clk_enable_lock();
351 439
352 if (clk->enable_count) 440 if (clk->enable_count)
353 goto unlock_out; 441 goto unlock_out;
@@ -368,7 +456,7 @@ static void clk_disable_unused_subtree(struct clk *clk)
368 } 456 }
369 457
370unlock_out: 458unlock_out:
371 spin_unlock_irqrestore(&enable_lock, flags); 459 clk_enable_unlock(flags);
372 460
373out: 461out:
374 return; 462 return;
@@ -378,7 +466,7 @@ static int clk_disable_unused(void)
378{ 466{
379 struct clk *clk; 467 struct clk *clk;
380 468
381 mutex_lock(&prepare_lock); 469 clk_prepare_lock();
382 470
383 hlist_for_each_entry(clk, &clk_root_list, child_node) 471 hlist_for_each_entry(clk, &clk_root_list, child_node)
384 clk_disable_unused_subtree(clk); 472 clk_disable_unused_subtree(clk);
@@ -386,7 +474,13 @@ static int clk_disable_unused(void)
386 hlist_for_each_entry(clk, &clk_orphan_list, child_node) 474 hlist_for_each_entry(clk, &clk_orphan_list, child_node)
387 clk_disable_unused_subtree(clk); 475 clk_disable_unused_subtree(clk);
388 476
389 mutex_unlock(&prepare_lock); 477 hlist_for_each_entry(clk, &clk_root_list, child_node)
478 clk_unprepare_unused_subtree(clk);
479
480 hlist_for_each_entry(clk, &clk_orphan_list, child_node)
481 clk_unprepare_unused_subtree(clk);
482
483 clk_prepare_unlock();
390 484
391 return 0; 485 return 0;
392} 486}
@@ -451,6 +545,27 @@ unsigned long __clk_get_flags(struct clk *clk)
451 return !clk ? 0 : clk->flags; 545 return !clk ? 0 : clk->flags;
452} 546}
453 547
548bool __clk_is_prepared(struct clk *clk)
549{
550 int ret;
551
552 if (!clk)
553 return false;
554
555 /*
556 * .is_prepared is optional for clocks that can prepare
557 * fall back to software usage counter if it is missing
558 */
559 if (!clk->ops->is_prepared) {
560 ret = clk->prepare_count ? 1 : 0;
561 goto out;
562 }
563
564 ret = clk->ops->is_prepared(clk->hw);
565out:
566 return !!ret;
567}
568
454bool __clk_is_enabled(struct clk *clk) 569bool __clk_is_enabled(struct clk *clk)
455{ 570{
456 int ret; 571 int ret;
@@ -548,9 +663,9 @@ void __clk_unprepare(struct clk *clk)
548 */ 663 */
549void clk_unprepare(struct clk *clk) 664void clk_unprepare(struct clk *clk)
550{ 665{
551 mutex_lock(&prepare_lock); 666 clk_prepare_lock();
552 __clk_unprepare(clk); 667 __clk_unprepare(clk);
553 mutex_unlock(&prepare_lock); 668 clk_prepare_unlock();
554} 669}
555EXPORT_SYMBOL_GPL(clk_unprepare); 670EXPORT_SYMBOL_GPL(clk_unprepare);
556 671
@@ -596,9 +711,9 @@ int clk_prepare(struct clk *clk)
596{ 711{
597 int ret; 712 int ret;
598 713
599 mutex_lock(&prepare_lock); 714 clk_prepare_lock();
600 ret = __clk_prepare(clk); 715 ret = __clk_prepare(clk);
601 mutex_unlock(&prepare_lock); 716 clk_prepare_unlock();
602 717
603 return ret; 718 return ret;
604} 719}
@@ -640,9 +755,9 @@ void clk_disable(struct clk *clk)
640{ 755{
641 unsigned long flags; 756 unsigned long flags;
642 757
643 spin_lock_irqsave(&enable_lock, flags); 758 flags = clk_enable_lock();
644 __clk_disable(clk); 759 __clk_disable(clk);
645 spin_unlock_irqrestore(&enable_lock, flags); 760 clk_enable_unlock(flags);
646} 761}
647EXPORT_SYMBOL_GPL(clk_disable); 762EXPORT_SYMBOL_GPL(clk_disable);
648 763
@@ -693,9 +808,9 @@ int clk_enable(struct clk *clk)
693 unsigned long flags; 808 unsigned long flags;
694 int ret; 809 int ret;
695 810
696 spin_lock_irqsave(&enable_lock, flags); 811 flags = clk_enable_lock();
697 ret = __clk_enable(clk); 812 ret = __clk_enable(clk);
698 spin_unlock_irqrestore(&enable_lock, flags); 813 clk_enable_unlock(flags);
699 814
700 return ret; 815 return ret;
701} 816}
@@ -740,9 +855,9 @@ long clk_round_rate(struct clk *clk, unsigned long rate)
740{ 855{
741 unsigned long ret; 856 unsigned long ret;
742 857
743 mutex_lock(&prepare_lock); 858 clk_prepare_lock();
744 ret = __clk_round_rate(clk, rate); 859 ret = __clk_round_rate(clk, rate);
745 mutex_unlock(&prepare_lock); 860 clk_prepare_unlock();
746 861
747 return ret; 862 return ret;
748} 863}
@@ -837,13 +952,13 @@ unsigned long clk_get_rate(struct clk *clk)
837{ 952{
838 unsigned long rate; 953 unsigned long rate;
839 954
840 mutex_lock(&prepare_lock); 955 clk_prepare_lock();
841 956
842 if (clk && (clk->flags & CLK_GET_RATE_NOCACHE)) 957 if (clk && (clk->flags & CLK_GET_RATE_NOCACHE))
843 __clk_recalc_rates(clk, 0); 958 __clk_recalc_rates(clk, 0);
844 959
845 rate = __clk_get_rate(clk); 960 rate = __clk_get_rate(clk);
846 mutex_unlock(&prepare_lock); 961 clk_prepare_unlock();
847 962
848 return rate; 963 return rate;
849} 964}
@@ -974,7 +1089,7 @@ static struct clk *clk_propagate_rate_change(struct clk *clk, unsigned long even
974 int ret = NOTIFY_DONE; 1089 int ret = NOTIFY_DONE;
975 1090
976 if (clk->rate == clk->new_rate) 1091 if (clk->rate == clk->new_rate)
977 return 0; 1092 return NULL;
978 1093
979 if (clk->notifier_count) { 1094 if (clk->notifier_count) {
980 ret = __clk_notify(clk, event, clk->rate, clk->new_rate); 1095 ret = __clk_notify(clk, event, clk->rate, clk->new_rate);
@@ -1048,7 +1163,7 @@ int clk_set_rate(struct clk *clk, unsigned long rate)
1048 int ret = 0; 1163 int ret = 0;
1049 1164
1050 /* prevent racing with updates to the clock topology */ 1165 /* prevent racing with updates to the clock topology */
1051 mutex_lock(&prepare_lock); 1166 clk_prepare_lock();
1052 1167
1053 /* bail early if nothing to do */ 1168 /* bail early if nothing to do */
1054 if (rate == clk->rate) 1169 if (rate == clk->rate)
@@ -1080,7 +1195,7 @@ int clk_set_rate(struct clk *clk, unsigned long rate)
1080 clk_change_rate(top); 1195 clk_change_rate(top);
1081 1196
1082out: 1197out:
1083 mutex_unlock(&prepare_lock); 1198 clk_prepare_unlock();
1084 1199
1085 return ret; 1200 return ret;
1086} 1201}
@@ -1096,9 +1211,9 @@ struct clk *clk_get_parent(struct clk *clk)
1096{ 1211{
1097 struct clk *parent; 1212 struct clk *parent;
1098 1213
1099 mutex_lock(&prepare_lock); 1214 clk_prepare_lock();
1100 parent = __clk_get_parent(clk); 1215 parent = __clk_get_parent(clk);
1101 mutex_unlock(&prepare_lock); 1216 clk_prepare_unlock();
1102 1217
1103 return parent; 1218 return parent;
1104} 1219}
@@ -1242,19 +1357,19 @@ static int __clk_set_parent(struct clk *clk, struct clk *parent)
1242 __clk_prepare(parent); 1357 __clk_prepare(parent);
1243 1358
1244 /* FIXME replace with clk_is_enabled(clk) someday */ 1359 /* FIXME replace with clk_is_enabled(clk) someday */
1245 spin_lock_irqsave(&enable_lock, flags); 1360 flags = clk_enable_lock();
1246 if (clk->enable_count) 1361 if (clk->enable_count)
1247 __clk_enable(parent); 1362 __clk_enable(parent);
1248 spin_unlock_irqrestore(&enable_lock, flags); 1363 clk_enable_unlock(flags);
1249 1364
1250 /* change clock input source */ 1365 /* change clock input source */
1251 ret = clk->ops->set_parent(clk->hw, i); 1366 ret = clk->ops->set_parent(clk->hw, i);
1252 1367
1253 /* clean up old prepare and enable */ 1368 /* clean up old prepare and enable */
1254 spin_lock_irqsave(&enable_lock, flags); 1369 flags = clk_enable_lock();
1255 if (clk->enable_count) 1370 if (clk->enable_count)
1256 __clk_disable(old_parent); 1371 __clk_disable(old_parent);
1257 spin_unlock_irqrestore(&enable_lock, flags); 1372 clk_enable_unlock(flags);
1258 1373
1259 if (clk->prepare_count) 1374 if (clk->prepare_count)
1260 __clk_unprepare(old_parent); 1375 __clk_unprepare(old_parent);
@@ -1286,7 +1401,7 @@ int clk_set_parent(struct clk *clk, struct clk *parent)
1286 return -ENOSYS; 1401 return -ENOSYS;
1287 1402
1288 /* prevent racing with updates to the clock topology */ 1403 /* prevent racing with updates to the clock topology */
1289 mutex_lock(&prepare_lock); 1404 clk_prepare_lock();
1290 1405
1291 if (clk->parent == parent) 1406 if (clk->parent == parent)
1292 goto out; 1407 goto out;
@@ -1315,7 +1430,7 @@ int clk_set_parent(struct clk *clk, struct clk *parent)
1315 __clk_reparent(clk, parent); 1430 __clk_reparent(clk, parent);
1316 1431
1317out: 1432out:
1318 mutex_unlock(&prepare_lock); 1433 clk_prepare_unlock();
1319 1434
1320 return ret; 1435 return ret;
1321} 1436}
@@ -1338,7 +1453,7 @@ int __clk_init(struct device *dev, struct clk *clk)
1338 if (!clk) 1453 if (!clk)
1339 return -EINVAL; 1454 return -EINVAL;
1340 1455
1341 mutex_lock(&prepare_lock); 1456 clk_prepare_lock();
1342 1457
1343 /* check to see if a clock with this name is already registered */ 1458 /* check to see if a clock with this name is already registered */
1344 if (__clk_lookup(clk->name)) { 1459 if (__clk_lookup(clk->name)) {
@@ -1462,7 +1577,7 @@ int __clk_init(struct device *dev, struct clk *clk)
1462 clk_debug_register(clk); 1577 clk_debug_register(clk);
1463 1578
1464out: 1579out:
1465 mutex_unlock(&prepare_lock); 1580 clk_prepare_unlock();
1466 1581
1467 return ret; 1582 return ret;
1468} 1583}
@@ -1696,7 +1811,7 @@ int clk_notifier_register(struct clk *clk, struct notifier_block *nb)
1696 if (!clk || !nb) 1811 if (!clk || !nb)
1697 return -EINVAL; 1812 return -EINVAL;
1698 1813
1699 mutex_lock(&prepare_lock); 1814 clk_prepare_lock();
1700 1815
1701 /* search the list of notifiers for this clk */ 1816 /* search the list of notifiers for this clk */
1702 list_for_each_entry(cn, &clk_notifier_list, node) 1817 list_for_each_entry(cn, &clk_notifier_list, node)
@@ -1720,7 +1835,7 @@ int clk_notifier_register(struct clk *clk, struct notifier_block *nb)
1720 clk->notifier_count++; 1835 clk->notifier_count++;
1721 1836
1722out: 1837out:
1723 mutex_unlock(&prepare_lock); 1838 clk_prepare_unlock();
1724 1839
1725 return ret; 1840 return ret;
1726} 1841}
@@ -1745,7 +1860,7 @@ int clk_notifier_unregister(struct clk *clk, struct notifier_block *nb)
1745 if (!clk || !nb) 1860 if (!clk || !nb)
1746 return -EINVAL; 1861 return -EINVAL;
1747 1862
1748 mutex_lock(&prepare_lock); 1863 clk_prepare_lock();
1749 1864
1750 list_for_each_entry(cn, &clk_notifier_list, node) 1865 list_for_each_entry(cn, &clk_notifier_list, node)
1751 if (cn->clk == clk) 1866 if (cn->clk == clk)
@@ -1766,7 +1881,7 @@ int clk_notifier_unregister(struct clk *clk, struct notifier_block *nb)
1766 ret = -ENOENT; 1881 ret = -ENOENT;
1767 } 1882 }
1768 1883
1769 mutex_unlock(&prepare_lock); 1884 clk_prepare_unlock();
1770 1885
1771 return ret; 1886 return ret;
1772} 1887}
diff --git a/drivers/clk/mxs/clk.c b/drivers/clk/mxs/clk.c
index b24d56067c80..5301bce8957b 100644
--- a/drivers/clk/mxs/clk.c
+++ b/drivers/clk/mxs/clk.c
@@ -13,6 +13,7 @@
13#include <linux/io.h> 13#include <linux/io.h>
14#include <linux/jiffies.h> 14#include <linux/jiffies.h>
15#include <linux/spinlock.h> 15#include <linux/spinlock.h>
16#include "clk.h"
16 17
17DEFINE_SPINLOCK(mxs_lock); 18DEFINE_SPINLOCK(mxs_lock);
18 19
diff --git a/drivers/clk/spear/spear1340_clock.c b/drivers/clk/spear/spear1340_clock.c
index 3ceb4507e95f..9d0b3949db30 100644
--- a/drivers/clk/spear/spear1340_clock.c
+++ b/drivers/clk/spear/spear1340_clock.c
@@ -959,47 +959,47 @@ void __init spear1340_clk_init(void __iomem *misc_base)
959 SPEAR1340_SPDIF_IN_CLK_ENB, 0, &_lock); 959 SPEAR1340_SPDIF_IN_CLK_ENB, 0, &_lock);
960 clk_register_clkdev(clk, NULL, "d0100000.spdif-in"); 960 clk_register_clkdev(clk, NULL, "d0100000.spdif-in");
961 961
962 clk = clk_register_gate(NULL, "acp_clk", "acp_mclk", 0, 962 clk = clk_register_gate(NULL, "acp_clk", "ahb_clk", 0,
963 SPEAR1340_PERIP2_CLK_ENB, SPEAR1340_ACP_CLK_ENB, 0, 963 SPEAR1340_PERIP2_CLK_ENB, SPEAR1340_ACP_CLK_ENB, 0,
964 &_lock); 964 &_lock);
965 clk_register_clkdev(clk, NULL, "acp_clk"); 965 clk_register_clkdev(clk, NULL, "acp_clk");
966 966
967 clk = clk_register_gate(NULL, "plgpio_clk", "plgpio_mclk", 0, 967 clk = clk_register_gate(NULL, "plgpio_clk", "ahb_clk", 0,
968 SPEAR1340_PERIP3_CLK_ENB, SPEAR1340_PLGPIO_CLK_ENB, 0, 968 SPEAR1340_PERIP3_CLK_ENB, SPEAR1340_PLGPIO_CLK_ENB, 0,
969 &_lock); 969 &_lock);
970 clk_register_clkdev(clk, NULL, "e2800000.gpio"); 970 clk_register_clkdev(clk, NULL, "e2800000.gpio");
971 971
972 clk = clk_register_gate(NULL, "video_dec_clk", "video_dec_mclk", 0, 972 clk = clk_register_gate(NULL, "video_dec_clk", "ahb_clk", 0,
973 SPEAR1340_PERIP3_CLK_ENB, SPEAR1340_VIDEO_DEC_CLK_ENB, 973 SPEAR1340_PERIP3_CLK_ENB, SPEAR1340_VIDEO_DEC_CLK_ENB,
974 0, &_lock); 974 0, &_lock);
975 clk_register_clkdev(clk, NULL, "video_dec"); 975 clk_register_clkdev(clk, NULL, "video_dec");
976 976
977 clk = clk_register_gate(NULL, "video_enc_clk", "video_enc_mclk", 0, 977 clk = clk_register_gate(NULL, "video_enc_clk", "ahb_clk", 0,
978 SPEAR1340_PERIP3_CLK_ENB, SPEAR1340_VIDEO_ENC_CLK_ENB, 978 SPEAR1340_PERIP3_CLK_ENB, SPEAR1340_VIDEO_ENC_CLK_ENB,
979 0, &_lock); 979 0, &_lock);
980 clk_register_clkdev(clk, NULL, "video_enc"); 980 clk_register_clkdev(clk, NULL, "video_enc");
981 981
982 clk = clk_register_gate(NULL, "video_in_clk", "video_in_mclk", 0, 982 clk = clk_register_gate(NULL, "video_in_clk", "ahb_clk", 0,
983 SPEAR1340_PERIP3_CLK_ENB, SPEAR1340_VIDEO_IN_CLK_ENB, 0, 983 SPEAR1340_PERIP3_CLK_ENB, SPEAR1340_VIDEO_IN_CLK_ENB, 0,
984 &_lock); 984 &_lock);
985 clk_register_clkdev(clk, NULL, "spear_vip"); 985 clk_register_clkdev(clk, NULL, "spear_vip");
986 986
987 clk = clk_register_gate(NULL, "cam0_clk", "cam0_mclk", 0, 987 clk = clk_register_gate(NULL, "cam0_clk", "ahb_clk", 0,
988 SPEAR1340_PERIP3_CLK_ENB, SPEAR1340_CAM0_CLK_ENB, 0, 988 SPEAR1340_PERIP3_CLK_ENB, SPEAR1340_CAM0_CLK_ENB, 0,
989 &_lock); 989 &_lock);
990 clk_register_clkdev(clk, NULL, "d0200000.cam0"); 990 clk_register_clkdev(clk, NULL, "d0200000.cam0");
991 991
992 clk = clk_register_gate(NULL, "cam1_clk", "cam1_mclk", 0, 992 clk = clk_register_gate(NULL, "cam1_clk", "ahb_clk", 0,
993 SPEAR1340_PERIP3_CLK_ENB, SPEAR1340_CAM1_CLK_ENB, 0, 993 SPEAR1340_PERIP3_CLK_ENB, SPEAR1340_CAM1_CLK_ENB, 0,
994 &_lock); 994 &_lock);
995 clk_register_clkdev(clk, NULL, "d0300000.cam1"); 995 clk_register_clkdev(clk, NULL, "d0300000.cam1");
996 996
997 clk = clk_register_gate(NULL, "cam2_clk", "cam2_mclk", 0, 997 clk = clk_register_gate(NULL, "cam2_clk", "ahb_clk", 0,
998 SPEAR1340_PERIP3_CLK_ENB, SPEAR1340_CAM2_CLK_ENB, 0, 998 SPEAR1340_PERIP3_CLK_ENB, SPEAR1340_CAM2_CLK_ENB, 0,
999 &_lock); 999 &_lock);
1000 clk_register_clkdev(clk, NULL, "d0400000.cam2"); 1000 clk_register_clkdev(clk, NULL, "d0400000.cam2");
1001 1001
1002 clk = clk_register_gate(NULL, "cam3_clk", "cam3_mclk", 0, 1002 clk = clk_register_gate(NULL, "cam3_clk", "ahb_clk", 0,
1003 SPEAR1340_PERIP3_CLK_ENB, SPEAR1340_CAM3_CLK_ENB, 0, 1003 SPEAR1340_PERIP3_CLK_ENB, SPEAR1340_CAM3_CLK_ENB, 0,
1004 &_lock); 1004 &_lock);
1005 clk_register_clkdev(clk, NULL, "d0500000.cam3"); 1005 clk_register_clkdev(clk, NULL, "d0500000.cam3");
diff --git a/drivers/clk/sunxi/Makefile b/drivers/clk/sunxi/Makefile
new file mode 100644
index 000000000000..b5bac917612c
--- /dev/null
+++ b/drivers/clk/sunxi/Makefile
@@ -0,0 +1,5 @@
1#
2# Makefile for sunxi specific clk
3#
4
5obj-y += clk-sunxi.o clk-factors.o
diff --git a/drivers/clk/sunxi/clk-factors.c b/drivers/clk/sunxi/clk-factors.c
new file mode 100644
index 000000000000..88523f91d9b7
--- /dev/null
+++ b/drivers/clk/sunxi/clk-factors.c
@@ -0,0 +1,180 @@
1/*
2 * Copyright (C) 2013 Emilio López <emilio@elopez.com.ar>
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 version 2 as
6 * published by the Free Software Foundation.
7 *
8 * Adjustable factor-based clock implementation
9 */
10
11#include <linux/clk-provider.h>
12#include <linux/module.h>
13#include <linux/slab.h>
14#include <linux/io.h>
15#include <linux/err.h>
16#include <linux/string.h>
17
18#include <linux/delay.h>
19
20#include "clk-factors.h"
21
22/*
23 * DOC: basic adjustable factor-based clock that cannot gate
24 *
25 * Traits of this clock:
26 * prepare - clk_prepare only ensures that parents are prepared
27 * enable - clk_enable only ensures that parents are enabled
28 * rate - rate is adjustable.
29 * clk->rate = (parent->rate * N * (K + 1) >> P) / (M + 1)
30 * parent - fixed parent. No clk_set_parent support
31 */
32
33struct clk_factors {
34 struct clk_hw hw;
35 void __iomem *reg;
36 struct clk_factors_config *config;
37 void (*get_factors) (u32 *rate, u32 parent, u8 *n, u8 *k, u8 *m, u8 *p);
38 spinlock_t *lock;
39};
40
41#define to_clk_factors(_hw) container_of(_hw, struct clk_factors, hw)
42
43#define SETMASK(len, pos) (((-1U) >> (31-len)) << (pos))
44#define CLRMASK(len, pos) (~(SETMASK(len, pos)))
45#define FACTOR_GET(bit, len, reg) (((reg) & SETMASK(len, bit)) >> (bit))
46
47#define FACTOR_SET(bit, len, reg, val) \
48 (((reg) & CLRMASK(len, bit)) | (val << (bit)))
49
50static unsigned long clk_factors_recalc_rate(struct clk_hw *hw,
51 unsigned long parent_rate)
52{
53 u8 n = 1, k = 0, p = 0, m = 0;
54 u32 reg;
55 unsigned long rate;
56 struct clk_factors *factors = to_clk_factors(hw);
57 struct clk_factors_config *config = factors->config;
58
59 /* Fetch the register value */
60 reg = readl(factors->reg);
61
62 /* Get each individual factor if applicable */
63 if (config->nwidth != SUNXI_FACTORS_NOT_APPLICABLE)
64 n = FACTOR_GET(config->nshift, config->nwidth, reg);
65 if (config->kwidth != SUNXI_FACTORS_NOT_APPLICABLE)
66 k = FACTOR_GET(config->kshift, config->kwidth, reg);
67 if (config->mwidth != SUNXI_FACTORS_NOT_APPLICABLE)
68 m = FACTOR_GET(config->mshift, config->mwidth, reg);
69 if (config->pwidth != SUNXI_FACTORS_NOT_APPLICABLE)
70 p = FACTOR_GET(config->pshift, config->pwidth, reg);
71
72 /* Calculate the rate */
73 rate = (parent_rate * n * (k + 1) >> p) / (m + 1);
74
75 return rate;
76}
77
78static long clk_factors_round_rate(struct clk_hw *hw, unsigned long rate,
79 unsigned long *parent_rate)
80{
81 struct clk_factors *factors = to_clk_factors(hw);
82 factors->get_factors((u32 *)&rate, (u32)*parent_rate,
83 NULL, NULL, NULL, NULL);
84
85 return rate;
86}
87
88static int clk_factors_set_rate(struct clk_hw *hw, unsigned long rate,
89 unsigned long parent_rate)
90{
91 u8 n, k, m, p;
92 u32 reg;
93 struct clk_factors *factors = to_clk_factors(hw);
94 struct clk_factors_config *config = factors->config;
95 unsigned long flags = 0;
96
97 factors->get_factors((u32 *)&rate, (u32)parent_rate, &n, &k, &m, &p);
98
99 if (factors->lock)
100 spin_lock_irqsave(factors->lock, flags);
101
102 /* Fetch the register value */
103 reg = readl(factors->reg);
104
105 /* Set up the new factors - macros do not do anything if width is 0 */
106 reg = FACTOR_SET(config->nshift, config->nwidth, reg, n);
107 reg = FACTOR_SET(config->kshift, config->kwidth, reg, k);
108 reg = FACTOR_SET(config->mshift, config->mwidth, reg, m);
109 reg = FACTOR_SET(config->pshift, config->pwidth, reg, p);
110
111 /* Apply them now */
112 writel(reg, factors->reg);
113
114 /* delay 500us so pll stabilizes */
115 __delay((rate >> 20) * 500 / 2);
116
117 if (factors->lock)
118 spin_unlock_irqrestore(factors->lock, flags);
119
120 return 0;
121}
122
123static const struct clk_ops clk_factors_ops = {
124 .recalc_rate = clk_factors_recalc_rate,
125 .round_rate = clk_factors_round_rate,
126 .set_rate = clk_factors_set_rate,
127};
128
129/**
130 * clk_register_factors - register a factors clock with
131 * the clock framework
132 * @dev: device registering this clock
133 * @name: name of this clock
134 * @parent_name: name of clock's parent
135 * @flags: framework-specific flags
136 * @reg: register address to adjust factors
137 * @config: shift and width of factors n, k, m and p
138 * @get_factors: function to calculate the factors for a given frequency
139 * @lock: shared register lock for this clock
140 */
141struct clk *clk_register_factors(struct device *dev, const char *name,
142 const char *parent_name,
143 unsigned long flags, void __iomem *reg,
144 struct clk_factors_config *config,
145 void (*get_factors)(u32 *rate, u32 parent,
146 u8 *n, u8 *k, u8 *m, u8 *p),
147 spinlock_t *lock)
148{
149 struct clk_factors *factors;
150 struct clk *clk;
151 struct clk_init_data init;
152
153 /* allocate the factors */
154 factors = kzalloc(sizeof(struct clk_factors), GFP_KERNEL);
155 if (!factors) {
156 pr_err("%s: could not allocate factors clk\n", __func__);
157 return ERR_PTR(-ENOMEM);
158 }
159
160 init.name = name;
161 init.ops = &clk_factors_ops;
162 init.flags = flags;
163 init.parent_names = (parent_name ? &parent_name : NULL);
164 init.num_parents = (parent_name ? 1 : 0);
165
166 /* struct clk_factors assignments */
167 factors->reg = reg;
168 factors->config = config;
169 factors->lock = lock;
170 factors->hw.init = &init;
171 factors->get_factors = get_factors;
172
173 /* register the clock */
174 clk = clk_register(dev, &factors->hw);
175
176 if (IS_ERR(clk))
177 kfree(factors);
178
179 return clk;
180}
diff --git a/drivers/clk/sunxi/clk-factors.h b/drivers/clk/sunxi/clk-factors.h
new file mode 100644
index 000000000000..f49851cc4380
--- /dev/null
+++ b/drivers/clk/sunxi/clk-factors.h
@@ -0,0 +1,27 @@
1#ifndef __MACH_SUNXI_CLK_FACTORS_H
2#define __MACH_SUNXI_CLK_FACTORS_H
3
4#include <linux/clk-provider.h>
5#include <linux/clkdev.h>
6
7#define SUNXI_FACTORS_NOT_APPLICABLE (0)
8
9struct clk_factors_config {
10 u8 nshift;
11 u8 nwidth;
12 u8 kshift;
13 u8 kwidth;
14 u8 mshift;
15 u8 mwidth;
16 u8 pshift;
17 u8 pwidth;
18};
19
20struct clk *clk_register_factors(struct device *dev, const char *name,
21 const char *parent_name,
22 unsigned long flags, void __iomem *reg,
23 struct clk_factors_config *config,
24 void (*get_factors) (u32 *rate, u32 parent_rate,
25 u8 *n, u8 *k, u8 *m, u8 *p),
26 spinlock_t *lock);
27#endif
diff --git a/drivers/clk/sunxi/clk-sunxi.c b/drivers/clk/sunxi/clk-sunxi.c
new file mode 100644
index 000000000000..d528a2496690
--- /dev/null
+++ b/drivers/clk/sunxi/clk-sunxi.c
@@ -0,0 +1,362 @@
1/*
2 * Copyright 2013 Emilio López
3 *
4 * Emilio López <emilio@elopez.com.ar>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 */
16
17#include <linux/clk-provider.h>
18#include <linux/clkdev.h>
19#include <linux/clk/sunxi.h>
20#include <linux/of.h>
21#include <linux/of_address.h>
22
23#include "clk-factors.h"
24
25static DEFINE_SPINLOCK(clk_lock);
26
27/**
28 * sunxi_osc_clk_setup() - Setup function for gatable oscillator
29 */
30
31#define SUNXI_OSC24M_GATE 0
32
33static void __init sunxi_osc_clk_setup(struct device_node *node)
34{
35 struct clk *clk;
36 const char *clk_name = node->name;
37 const char *parent;
38 void *reg;
39
40 reg = of_iomap(node, 0);
41
42 parent = of_clk_get_parent_name(node, 0);
43
44 clk = clk_register_gate(NULL, clk_name, parent, CLK_IGNORE_UNUSED,
45 reg, SUNXI_OSC24M_GATE, 0, &clk_lock);
46
47 if (clk) {
48 of_clk_add_provider(node, of_clk_src_simple_get, clk);
49 clk_register_clkdev(clk, clk_name, NULL);
50 }
51}
52
53
54
55/**
56 * sunxi_get_pll1_factors() - calculates n, k, m, p factors for PLL1
57 * PLL1 rate is calculated as follows
58 * rate = (parent_rate * n * (k + 1) >> p) / (m + 1);
59 * parent_rate is always 24Mhz
60 */
61
62static void sunxi_get_pll1_factors(u32 *freq, u32 parent_rate,
63 u8 *n, u8 *k, u8 *m, u8 *p)
64{
65 u8 div;
66
67 /* Normalize value to a 6M multiple */
68 div = *freq / 6000000;
69 *freq = 6000000 * div;
70
71 /* we were called to round the frequency, we can now return */
72 if (n == NULL)
73 return;
74
75 /* m is always zero for pll1 */
76 *m = 0;
77
78 /* k is 1 only on these cases */
79 if (*freq >= 768000000 || *freq == 42000000 || *freq == 54000000)
80 *k = 1;
81 else
82 *k = 0;
83
84 /* p will be 3 for divs under 10 */
85 if (div < 10)
86 *p = 3;
87
88 /* p will be 2 for divs between 10 - 20 and odd divs under 32 */
89 else if (div < 20 || (div < 32 && (div & 1)))
90 *p = 2;
91
92 /* p will be 1 for even divs under 32, divs under 40 and odd pairs
93 * of divs between 40-62 */
94 else if (div < 40 || (div < 64 && (div & 2)))
95 *p = 1;
96
97 /* any other entries have p = 0 */
98 else
99 *p = 0;
100
101 /* calculate a suitable n based on k and p */
102 div <<= *p;
103 div /= (*k + 1);
104 *n = div / 4;
105}
106
107
108
109/**
110 * sunxi_get_apb1_factors() - calculates m, p factors for APB1
111 * APB1 rate is calculated as follows
112 * rate = (parent_rate >> p) / (m + 1);
113 */
114
115static void sunxi_get_apb1_factors(u32 *freq, u32 parent_rate,
116 u8 *n, u8 *k, u8 *m, u8 *p)
117{
118 u8 calcm, calcp;
119
120 if (parent_rate < *freq)
121 *freq = parent_rate;
122
123 parent_rate = (parent_rate + (*freq - 1)) / *freq;
124
125 /* Invalid rate! */
126 if (parent_rate > 32)
127 return;
128
129 if (parent_rate <= 4)
130 calcp = 0;
131 else if (parent_rate <= 8)
132 calcp = 1;
133 else if (parent_rate <= 16)
134 calcp = 2;
135 else
136 calcp = 3;
137
138 calcm = (parent_rate >> calcp) - 1;
139
140 *freq = (parent_rate >> calcp) / (calcm + 1);
141
142 /* we were called to round the frequency, we can now return */
143 if (n == NULL)
144 return;
145
146 *m = calcm;
147 *p = calcp;
148}
149
150
151
152/**
153 * sunxi_factors_clk_setup() - Setup function for factor clocks
154 */
155
156struct factors_data {
157 struct clk_factors_config *table;
158 void (*getter) (u32 *rate, u32 parent_rate, u8 *n, u8 *k, u8 *m, u8 *p);
159};
160
161static struct clk_factors_config pll1_config = {
162 .nshift = 8,
163 .nwidth = 5,
164 .kshift = 4,
165 .kwidth = 2,
166 .mshift = 0,
167 .mwidth = 2,
168 .pshift = 16,
169 .pwidth = 2,
170};
171
172static struct clk_factors_config apb1_config = {
173 .mshift = 0,
174 .mwidth = 5,
175 .pshift = 16,
176 .pwidth = 2,
177};
178
179static const __initconst struct factors_data pll1_data = {
180 .table = &pll1_config,
181 .getter = sunxi_get_pll1_factors,
182};
183
184static const __initconst struct factors_data apb1_data = {
185 .table = &apb1_config,
186 .getter = sunxi_get_apb1_factors,
187};
188
189static void __init sunxi_factors_clk_setup(struct device_node *node,
190 struct factors_data *data)
191{
192 struct clk *clk;
193 const char *clk_name = node->name;
194 const char *parent;
195 void *reg;
196
197 reg = of_iomap(node, 0);
198
199 parent = of_clk_get_parent_name(node, 0);
200
201 clk = clk_register_factors(NULL, clk_name, parent, CLK_IGNORE_UNUSED,
202 reg, data->table, data->getter, &clk_lock);
203
204 if (clk) {
205 of_clk_add_provider(node, of_clk_src_simple_get, clk);
206 clk_register_clkdev(clk, clk_name, NULL);
207 }
208}
209
210
211
212/**
213 * sunxi_mux_clk_setup() - Setup function for muxes
214 */
215
216#define SUNXI_MUX_GATE_WIDTH 2
217
218struct mux_data {
219 u8 shift;
220};
221
222static const __initconst struct mux_data cpu_data = {
223 .shift = 16,
224};
225
226static const __initconst struct mux_data apb1_mux_data = {
227 .shift = 24,
228};
229
230static void __init sunxi_mux_clk_setup(struct device_node *node,
231 struct mux_data *data)
232{
233 struct clk *clk;
234 const char *clk_name = node->name;
235 const char **parents = kmalloc(sizeof(char *) * 5, GFP_KERNEL);
236 void *reg;
237 int i = 0;
238
239 reg = of_iomap(node, 0);
240
241 while (i < 5 && (parents[i] = of_clk_get_parent_name(node, i)) != NULL)
242 i++;
243
244 clk = clk_register_mux(NULL, clk_name, parents, i, 0, reg,
245 data->shift, SUNXI_MUX_GATE_WIDTH,
246 0, &clk_lock);
247
248 if (clk) {
249 of_clk_add_provider(node, of_clk_src_simple_get, clk);
250 clk_register_clkdev(clk, clk_name, NULL);
251 }
252}
253
254
255
256/**
257 * sunxi_divider_clk_setup() - Setup function for simple divider clocks
258 */
259
260#define SUNXI_DIVISOR_WIDTH 2
261
262struct div_data {
263 u8 shift;
264 u8 pow;
265};
266
267static const __initconst struct div_data axi_data = {
268 .shift = 0,
269 .pow = 0,
270};
271
272static const __initconst struct div_data ahb_data = {
273 .shift = 4,
274 .pow = 1,
275};
276
277static const __initconst struct div_data apb0_data = {
278 .shift = 8,
279 .pow = 1,
280};
281
282static void __init sunxi_divider_clk_setup(struct device_node *node,
283 struct div_data *data)
284{
285 struct clk *clk;
286 const char *clk_name = node->name;
287 const char *clk_parent;
288 void *reg;
289
290 reg = of_iomap(node, 0);
291
292 clk_parent = of_clk_get_parent_name(node, 0);
293
294 clk = clk_register_divider(NULL, clk_name, clk_parent, 0,
295 reg, data->shift, SUNXI_DIVISOR_WIDTH,
296 data->pow ? CLK_DIVIDER_POWER_OF_TWO : 0,
297 &clk_lock);
298 if (clk) {
299 of_clk_add_provider(node, of_clk_src_simple_get, clk);
300 clk_register_clkdev(clk, clk_name, NULL);
301 }
302}
303
304
305/* Matches for of_clk_init */
306static const __initconst struct of_device_id clk_match[] = {
307 {.compatible = "fixed-clock", .data = of_fixed_clk_setup,},
308 {.compatible = "allwinner,sun4i-osc-clk", .data = sunxi_osc_clk_setup,},
309 {}
310};
311
312/* Matches for factors clocks */
313static const __initconst struct of_device_id clk_factors_match[] = {
314 {.compatible = "allwinner,sun4i-pll1-clk", .data = &pll1_data,},
315 {.compatible = "allwinner,sun4i-apb1-clk", .data = &apb1_data,},
316 {}
317};
318
319/* Matches for divider clocks */
320static const __initconst struct of_device_id clk_div_match[] = {
321 {.compatible = "allwinner,sun4i-axi-clk", .data = &axi_data,},
322 {.compatible = "allwinner,sun4i-ahb-clk", .data = &ahb_data,},
323 {.compatible = "allwinner,sun4i-apb0-clk", .data = &apb0_data,},
324 {}
325};
326
327/* Matches for mux clocks */
328static const __initconst struct of_device_id clk_mux_match[] = {
329 {.compatible = "allwinner,sun4i-cpu-clk", .data = &cpu_data,},
330 {.compatible = "allwinner,sun4i-apb1-mux-clk", .data = &apb1_mux_data,},
331 {}
332};
333
334static void __init of_sunxi_table_clock_setup(const struct of_device_id *clk_match,
335 void *function)
336{
337 struct device_node *np;
338 const struct div_data *data;
339 const struct of_device_id *match;
340 void (*setup_function)(struct device_node *, const void *) = function;
341
342 for_each_matching_node(np, clk_match) {
343 match = of_match_node(clk_match, np);
344 data = match->data;
345 setup_function(np, data);
346 }
347}
348
349void __init sunxi_init_clocks(void)
350{
351 /* Register all the simple sunxi clocks on DT */
352 of_clk_init(clk_match);
353
354 /* Register factor clocks */
355 of_sunxi_table_clock_setup(clk_factors_match, sunxi_factors_clk_setup);
356
357 /* Register divider clocks */
358 of_sunxi_table_clock_setup(clk_div_match, sunxi_divider_clk_setup);
359
360 /* Register mux clocks */
361 of_sunxi_table_clock_setup(clk_mux_match, sunxi_mux_clk_setup);
362}
diff --git a/drivers/clk/tegra/Makefile b/drivers/clk/tegra/Makefile
index 2b41b0f4f731..f49fac2d193a 100644
--- a/drivers/clk/tegra/Makefile
+++ b/drivers/clk/tegra/Makefile
@@ -9,3 +9,4 @@ obj-y += clk-super.o
9 9
10obj-$(CONFIG_ARCH_TEGRA_2x_SOC) += clk-tegra20.o 10obj-$(CONFIG_ARCH_TEGRA_2x_SOC) += clk-tegra20.o
11obj-$(CONFIG_ARCH_TEGRA_3x_SOC) += clk-tegra30.o 11obj-$(CONFIG_ARCH_TEGRA_3x_SOC) += clk-tegra30.o
12obj-$(CONFIG_ARCH_TEGRA_114_SOC) += clk-tegra114.o
diff --git a/drivers/clk/tegra/clk-periph-gate.c b/drivers/clk/tegra/clk-periph-gate.c
index 6dd533251e7b..bafee9895a24 100644
--- a/drivers/clk/tegra/clk-periph-gate.c
+++ b/drivers/clk/tegra/clk-periph-gate.c
@@ -41,7 +41,9 @@ static DEFINE_SPINLOCK(periph_ref_lock);
41#define write_rst_clr(val, gate) \ 41#define write_rst_clr(val, gate) \
42 writel_relaxed(val, gate->clk_base + (gate->regs->rst_clr_reg)) 42 writel_relaxed(val, gate->clk_base + (gate->regs->rst_clr_reg))
43 43
44#define periph_clk_to_bit(periph) (1 << (gate->clk_num % 32)) 44#define periph_clk_to_bit(gate) (1 << (gate->clk_num % 32))
45
46#define LVL2_CLK_GATE_OVRE 0x554
45 47
46/* Peripheral gate clock ops */ 48/* Peripheral gate clock ops */
47static int clk_periph_is_enabled(struct clk_hw *hw) 49static int clk_periph_is_enabled(struct clk_hw *hw)
@@ -83,6 +85,13 @@ static int clk_periph_enable(struct clk_hw *hw)
83 } 85 }
84 } 86 }
85 87
88 if (gate->flags & TEGRA_PERIPH_WAR_1005168) {
89 writel_relaxed(0, gate->clk_base + LVL2_CLK_GATE_OVRE);
90 writel_relaxed(BIT(22), gate->clk_base + LVL2_CLK_GATE_OVRE);
91 udelay(1);
92 writel_relaxed(0, gate->clk_base + LVL2_CLK_GATE_OVRE);
93 }
94
86 spin_unlock_irqrestore(&periph_ref_lock, flags); 95 spin_unlock_irqrestore(&periph_ref_lock, flags);
87 96
88 return 0; 97 return 0;
diff --git a/drivers/clk/tegra/clk-periph.c b/drivers/clk/tegra/clk-periph.c
index 788486e6331a..b2309d37a963 100644
--- a/drivers/clk/tegra/clk-periph.c
+++ b/drivers/clk/tegra/clk-periph.c
@@ -16,6 +16,7 @@
16 16
17#include <linux/clk.h> 17#include <linux/clk.h>
18#include <linux/clk-provider.h> 18#include <linux/clk-provider.h>
19#include <linux/export.h>
19#include <linux/slab.h> 20#include <linux/slab.h>
20#include <linux/err.h> 21#include <linux/err.h>
21 22
@@ -128,6 +129,7 @@ void tegra_periph_reset_deassert(struct clk *c)
128 129
129 tegra_periph_reset(gate, 0); 130 tegra_periph_reset(gate, 0);
130} 131}
132EXPORT_SYMBOL(tegra_periph_reset_deassert);
131 133
132void tegra_periph_reset_assert(struct clk *c) 134void tegra_periph_reset_assert(struct clk *c)
133{ 135{
@@ -147,6 +149,7 @@ void tegra_periph_reset_assert(struct clk *c)
147 149
148 tegra_periph_reset(gate, 1); 150 tegra_periph_reset(gate, 1);
149} 151}
152EXPORT_SYMBOL(tegra_periph_reset_assert);
150 153
151const struct clk_ops tegra_clk_periph_ops = { 154const struct clk_ops tegra_clk_periph_ops = {
152 .get_parent = clk_periph_get_parent, 155 .get_parent = clk_periph_get_parent,
@@ -170,14 +173,15 @@ const struct clk_ops tegra_clk_periph_nodiv_ops = {
170static struct clk *_tegra_clk_register_periph(const char *name, 173static struct clk *_tegra_clk_register_periph(const char *name,
171 const char **parent_names, int num_parents, 174 const char **parent_names, int num_parents,
172 struct tegra_clk_periph *periph, 175 struct tegra_clk_periph *periph,
173 void __iomem *clk_base, u32 offset, bool div) 176 void __iomem *clk_base, u32 offset, bool div,
177 unsigned long flags)
174{ 178{
175 struct clk *clk; 179 struct clk *clk;
176 struct clk_init_data init; 180 struct clk_init_data init;
177 181
178 init.name = name; 182 init.name = name;
179 init.ops = div ? &tegra_clk_periph_ops : &tegra_clk_periph_nodiv_ops; 183 init.ops = div ? &tegra_clk_periph_ops : &tegra_clk_periph_nodiv_ops;
180 init.flags = div ? 0 : CLK_SET_RATE_PARENT; 184 init.flags = flags;
181 init.parent_names = parent_names; 185 init.parent_names = parent_names;
182 init.num_parents = num_parents; 186 init.num_parents = num_parents;
183 187
@@ -202,10 +206,10 @@ static struct clk *_tegra_clk_register_periph(const char *name,
202struct clk *tegra_clk_register_periph(const char *name, 206struct clk *tegra_clk_register_periph(const char *name,
203 const char **parent_names, int num_parents, 207 const char **parent_names, int num_parents,
204 struct tegra_clk_periph *periph, void __iomem *clk_base, 208 struct tegra_clk_periph *periph, void __iomem *clk_base,
205 u32 offset) 209 u32 offset, unsigned long flags)
206{ 210{
207 return _tegra_clk_register_periph(name, parent_names, num_parents, 211 return _tegra_clk_register_periph(name, parent_names, num_parents,
208 periph, clk_base, offset, true); 212 periph, clk_base, offset, true, flags);
209} 213}
210 214
211struct clk *tegra_clk_register_periph_nodiv(const char *name, 215struct clk *tegra_clk_register_periph_nodiv(const char *name,
@@ -214,5 +218,5 @@ struct clk *tegra_clk_register_periph_nodiv(const char *name,
214 u32 offset) 218 u32 offset)
215{ 219{
216 return _tegra_clk_register_periph(name, parent_names, num_parents, 220 return _tegra_clk_register_periph(name, parent_names, num_parents,
217 periph, clk_base, offset, false); 221 periph, clk_base, offset, false, CLK_SET_RATE_PARENT);
218} 222}
diff --git a/drivers/clk/tegra/clk-pll.c b/drivers/clk/tegra/clk-pll.c
index 165f24734c1b..17c2cc086eb4 100644
--- a/drivers/clk/tegra/clk-pll.c
+++ b/drivers/clk/tegra/clk-pll.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved. 2 * Copyright (c) 2012, 2013, NVIDIA CORPORATION. All rights reserved.
3 * 3 *
4 * This program is free software; you can redistribute it and/or modify it 4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License, 5 * under the terms and conditions of the GNU General Public License,
@@ -79,6 +79,48 @@
79#define PLLE_SS_CTRL 0x68 79#define PLLE_SS_CTRL 0x68
80#define PLLE_SS_DISABLE (7 << 10) 80#define PLLE_SS_DISABLE (7 << 10)
81 81
82#define PLLE_AUX_PLLP_SEL BIT(2)
83#define PLLE_AUX_ENABLE_SWCTL BIT(4)
84#define PLLE_AUX_SEQ_ENABLE BIT(24)
85#define PLLE_AUX_PLLRE_SEL BIT(28)
86
87#define PLLE_MISC_PLLE_PTS BIT(8)
88#define PLLE_MISC_IDDQ_SW_VALUE BIT(13)
89#define PLLE_MISC_IDDQ_SW_CTRL BIT(14)
90#define PLLE_MISC_VREG_BG_CTRL_SHIFT 4
91#define PLLE_MISC_VREG_BG_CTRL_MASK (3 << PLLE_MISC_VREG_BG_CTRL_SHIFT)
92#define PLLE_MISC_VREG_CTRL_SHIFT 2
93#define PLLE_MISC_VREG_CTRL_MASK (2 << PLLE_MISC_VREG_CTRL_SHIFT)
94
95#define PLLCX_MISC_STROBE BIT(31)
96#define PLLCX_MISC_RESET BIT(30)
97#define PLLCX_MISC_SDM_DIV_SHIFT 28
98#define PLLCX_MISC_SDM_DIV_MASK (0x3 << PLLCX_MISC_SDM_DIV_SHIFT)
99#define PLLCX_MISC_FILT_DIV_SHIFT 26
100#define PLLCX_MISC_FILT_DIV_MASK (0x3 << PLLCX_MISC_FILT_DIV_SHIFT)
101#define PLLCX_MISC_ALPHA_SHIFT 18
102#define PLLCX_MISC_DIV_LOW_RANGE \
103 ((0x1 << PLLCX_MISC_SDM_DIV_SHIFT) | \
104 (0x1 << PLLCX_MISC_FILT_DIV_SHIFT))
105#define PLLCX_MISC_DIV_HIGH_RANGE \
106 ((0x2 << PLLCX_MISC_SDM_DIV_SHIFT) | \
107 (0x2 << PLLCX_MISC_FILT_DIV_SHIFT))
108#define PLLCX_MISC_COEF_LOW_RANGE \
109 ((0x14 << PLLCX_MISC_KA_SHIFT) | (0x38 << PLLCX_MISC_KB_SHIFT))
110#define PLLCX_MISC_KA_SHIFT 2
111#define PLLCX_MISC_KB_SHIFT 9
112#define PLLCX_MISC_DEFAULT (PLLCX_MISC_COEF_LOW_RANGE | \
113 (0x19 << PLLCX_MISC_ALPHA_SHIFT) | \
114 PLLCX_MISC_DIV_LOW_RANGE | \
115 PLLCX_MISC_RESET)
116#define PLLCX_MISC1_DEFAULT 0x000d2308
117#define PLLCX_MISC2_DEFAULT 0x30211200
118#define PLLCX_MISC3_DEFAULT 0x200
119
120#define PMC_PLLM_WB0_OVERRIDE 0x1dc
121#define PMC_PLLM_WB0_OVERRIDE_2 0x2b0
122#define PMC_PLLM_WB0_OVERRIDE_2_DIVP_MASK BIT(27)
123
82#define PMC_SATA_PWRGT 0x1ac 124#define PMC_SATA_PWRGT 0x1ac
83#define PMC_SATA_PWRGT_PLLE_IDDQ_VALUE BIT(5) 125#define PMC_SATA_PWRGT_PLLE_IDDQ_VALUE BIT(5)
84#define PMC_SATA_PWRGT_PLLE_IDDQ_SWCTL BIT(4) 126#define PMC_SATA_PWRGT_PLLE_IDDQ_SWCTL BIT(4)
@@ -101,6 +143,24 @@
101#define divn_max(p) (divn_mask(p)) 143#define divn_max(p) (divn_mask(p))
102#define divp_max(p) (1 << (divp_mask(p))) 144#define divp_max(p) (1 << (divp_mask(p)))
103 145
146
147#ifdef CONFIG_ARCH_TEGRA_114_SOC
148/* PLLXC has 4-bit PDIV, but entry 15 is not allowed in h/w */
149#define PLLXC_PDIV_MAX 14
150
151/* non-monotonic mapping below is not a typo */
152static u8 pllxc_p[PLLXC_PDIV_MAX + 1] = {
153 /* PDIV: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 */
154 /* p: */ 1, 2, 3, 4, 5, 6, 8, 10, 12, 16, 12, 16, 20, 24, 32
155};
156
157#define PLLCX_PDIV_MAX 7
158static u8 pllcx_p[PLLCX_PDIV_MAX + 1] = {
159 /* PDIV: 0, 1, 2, 3, 4, 5, 6, 7 */
160 /* p: */ 1, 2, 3, 4, 6, 8, 12, 16
161};
162#endif
163
104static void clk_pll_enable_lock(struct tegra_clk_pll *pll) 164static void clk_pll_enable_lock(struct tegra_clk_pll *pll)
105{ 165{
106 u32 val; 166 u32 val;
@@ -108,25 +168,36 @@ static void clk_pll_enable_lock(struct tegra_clk_pll *pll)
108 if (!(pll->flags & TEGRA_PLL_USE_LOCK)) 168 if (!(pll->flags & TEGRA_PLL_USE_LOCK))
109 return; 169 return;
110 170
171 if (!(pll->flags & TEGRA_PLL_HAS_LOCK_ENABLE))
172 return;
173
111 val = pll_readl_misc(pll); 174 val = pll_readl_misc(pll);
112 val |= BIT(pll->params->lock_enable_bit_idx); 175 val |= BIT(pll->params->lock_enable_bit_idx);
113 pll_writel_misc(val, pll); 176 pll_writel_misc(val, pll);
114} 177}
115 178
116static int clk_pll_wait_for_lock(struct tegra_clk_pll *pll, 179static int clk_pll_wait_for_lock(struct tegra_clk_pll *pll)
117 void __iomem *lock_addr, u32 lock_bit_idx)
118{ 180{
119 int i; 181 int i;
120 u32 val; 182 u32 val, lock_mask;
183 void __iomem *lock_addr;
121 184
122 if (!(pll->flags & TEGRA_PLL_USE_LOCK)) { 185 if (!(pll->flags & TEGRA_PLL_USE_LOCK)) {
123 udelay(pll->params->lock_delay); 186 udelay(pll->params->lock_delay);
124 return 0; 187 return 0;
125 } 188 }
126 189
190 lock_addr = pll->clk_base;
191 if (pll->flags & TEGRA_PLL_LOCK_MISC)
192 lock_addr += pll->params->misc_reg;
193 else
194 lock_addr += pll->params->base_reg;
195
196 lock_mask = pll->params->lock_mask;
197
127 for (i = 0; i < pll->params->lock_delay; i++) { 198 for (i = 0; i < pll->params->lock_delay; i++) {
128 val = readl_relaxed(lock_addr); 199 val = readl_relaxed(lock_addr);
129 if (val & BIT(lock_bit_idx)) { 200 if ((val & lock_mask) == lock_mask) {
130 udelay(PLL_POST_LOCK_DELAY); 201 udelay(PLL_POST_LOCK_DELAY);
131 return 0; 202 return 0;
132 } 203 }
@@ -155,7 +226,7 @@ static int clk_pll_is_enabled(struct clk_hw *hw)
155 return val & PLL_BASE_ENABLE ? 1 : 0; 226 return val & PLL_BASE_ENABLE ? 1 : 0;
156} 227}
157 228
158static int _clk_pll_enable(struct clk_hw *hw) 229static void _clk_pll_enable(struct clk_hw *hw)
159{ 230{
160 struct tegra_clk_pll *pll = to_clk_pll(hw); 231 struct tegra_clk_pll *pll = to_clk_pll(hw);
161 u32 val; 232 u32 val;
@@ -163,7 +234,8 @@ static int _clk_pll_enable(struct clk_hw *hw)
163 clk_pll_enable_lock(pll); 234 clk_pll_enable_lock(pll);
164 235
165 val = pll_readl_base(pll); 236 val = pll_readl_base(pll);
166 val &= ~PLL_BASE_BYPASS; 237 if (pll->flags & TEGRA_PLL_BYPASS)
238 val &= ~PLL_BASE_BYPASS;
167 val |= PLL_BASE_ENABLE; 239 val |= PLL_BASE_ENABLE;
168 pll_writel_base(val, pll); 240 pll_writel_base(val, pll);
169 241
@@ -172,11 +244,6 @@ static int _clk_pll_enable(struct clk_hw *hw)
172 val |= PMC_PLLP_WB0_OVERRIDE_PLLM_ENABLE; 244 val |= PMC_PLLP_WB0_OVERRIDE_PLLM_ENABLE;
173 writel_relaxed(val, pll->pmc + PMC_PLLP_WB0_OVERRIDE); 245 writel_relaxed(val, pll->pmc + PMC_PLLP_WB0_OVERRIDE);
174 } 246 }
175
176 clk_pll_wait_for_lock(pll, pll->clk_base + pll->params->base_reg,
177 pll->params->lock_bit_idx);
178
179 return 0;
180} 247}
181 248
182static void _clk_pll_disable(struct clk_hw *hw) 249static void _clk_pll_disable(struct clk_hw *hw)
@@ -185,7 +252,9 @@ static void _clk_pll_disable(struct clk_hw *hw)
185 u32 val; 252 u32 val;
186 253
187 val = pll_readl_base(pll); 254 val = pll_readl_base(pll);
188 val &= ~(PLL_BASE_BYPASS | PLL_BASE_ENABLE); 255 if (pll->flags & TEGRA_PLL_BYPASS)
256 val &= ~PLL_BASE_BYPASS;
257 val &= ~PLL_BASE_ENABLE;
189 pll_writel_base(val, pll); 258 pll_writel_base(val, pll);
190 259
191 if (pll->flags & TEGRA_PLLM) { 260 if (pll->flags & TEGRA_PLLM) {
@@ -204,7 +273,9 @@ static int clk_pll_enable(struct clk_hw *hw)
204 if (pll->lock) 273 if (pll->lock)
205 spin_lock_irqsave(pll->lock, flags); 274 spin_lock_irqsave(pll->lock, flags);
206 275
207 ret = _clk_pll_enable(hw); 276 _clk_pll_enable(hw);
277
278 ret = clk_pll_wait_for_lock(pll);
208 279
209 if (pll->lock) 280 if (pll->lock)
210 spin_unlock_irqrestore(pll->lock, flags); 281 spin_unlock_irqrestore(pll->lock, flags);
@@ -241,8 +312,6 @@ static int _get_table_rate(struct clk_hw *hw,
241 if (sel->input_rate == 0) 312 if (sel->input_rate == 0)
242 return -EINVAL; 313 return -EINVAL;
243 314
244 BUG_ON(sel->p < 1);
245
246 cfg->input_rate = sel->input_rate; 315 cfg->input_rate = sel->input_rate;
247 cfg->output_rate = sel->output_rate; 316 cfg->output_rate = sel->output_rate;
248 cfg->m = sel->m; 317 cfg->m = sel->m;
@@ -257,6 +326,7 @@ static int _calc_rate(struct clk_hw *hw, struct tegra_clk_pll_freq_table *cfg,
257 unsigned long rate, unsigned long parent_rate) 326 unsigned long rate, unsigned long parent_rate)
258{ 327{
259 struct tegra_clk_pll *pll = to_clk_pll(hw); 328 struct tegra_clk_pll *pll = to_clk_pll(hw);
329 struct pdiv_map *p_tohw = pll->params->pdiv_tohw;
260 unsigned long cfreq; 330 unsigned long cfreq;
261 u32 p_div = 0; 331 u32 p_div = 0;
262 332
@@ -290,88 +360,119 @@ static int _calc_rate(struct clk_hw *hw, struct tegra_clk_pll_freq_table *cfg,
290 cfg->output_rate <<= 1) 360 cfg->output_rate <<= 1)
291 p_div++; 361 p_div++;
292 362
293 cfg->p = 1 << p_div;
294 cfg->m = parent_rate / cfreq; 363 cfg->m = parent_rate / cfreq;
295 cfg->n = cfg->output_rate / cfreq; 364 cfg->n = cfg->output_rate / cfreq;
296 cfg->cpcon = OUT_OF_TABLE_CPCON; 365 cfg->cpcon = OUT_OF_TABLE_CPCON;
297 366
298 if (cfg->m > divm_max(pll) || cfg->n > divn_max(pll) || 367 if (cfg->m > divm_max(pll) || cfg->n > divn_max(pll) ||
299 cfg->p > divp_max(pll) || cfg->output_rate > pll->params->vco_max) { 368 (1 << p_div) > divp_max(pll)
369 || cfg->output_rate > pll->params->vco_max) {
300 pr_err("%s: Failed to set %s rate %lu\n", 370 pr_err("%s: Failed to set %s rate %lu\n",
301 __func__, __clk_get_name(hw->clk), rate); 371 __func__, __clk_get_name(hw->clk), rate);
302 return -EINVAL; 372 return -EINVAL;
303 } 373 }
304 374
375 if (p_tohw) {
376 p_div = 1 << p_div;
377 while (p_tohw->pdiv) {
378 if (p_div <= p_tohw->pdiv) {
379 cfg->p = p_tohw->hw_val;
380 break;
381 }
382 p_tohw++;
383 }
384 if (!p_tohw->pdiv)
385 return -EINVAL;
386 } else
387 cfg->p = p_div;
388
305 return 0; 389 return 0;
306} 390}
307 391
308static int _program_pll(struct clk_hw *hw, struct tegra_clk_pll_freq_table *cfg, 392static void _update_pll_mnp(struct tegra_clk_pll *pll,
309 unsigned long rate) 393 struct tegra_clk_pll_freq_table *cfg)
310{ 394{
311 struct tegra_clk_pll *pll = to_clk_pll(hw); 395 u32 val;
312 unsigned long flags = 0;
313 u32 divp, val, old_base;
314 int state;
315
316 divp = __ffs(cfg->p);
317
318 if (pll->flags & TEGRA_PLLU)
319 divp ^= 1;
320 396
321 if (pll->lock) 397 val = pll_readl_base(pll);
322 spin_lock_irqsave(pll->lock, flags);
323 398
324 old_base = val = pll_readl_base(pll);
325 val &= ~((divm_mask(pll) << pll->divm_shift) | 399 val &= ~((divm_mask(pll) << pll->divm_shift) |
326 (divn_mask(pll) << pll->divn_shift) | 400 (divn_mask(pll) << pll->divn_shift) |
327 (divp_mask(pll) << pll->divp_shift)); 401 (divp_mask(pll) << pll->divp_shift));
328 val |= ((cfg->m << pll->divm_shift) | 402 val |= ((cfg->m << pll->divm_shift) |
329 (cfg->n << pll->divn_shift) | 403 (cfg->n << pll->divn_shift) |
330 (divp << pll->divp_shift)); 404 (cfg->p << pll->divp_shift));
331 if (val == old_base) { 405
332 if (pll->lock) 406 pll_writel_base(val, pll);
333 spin_unlock_irqrestore(pll->lock, flags); 407}
334 return 0; 408
409static void _get_pll_mnp(struct tegra_clk_pll *pll,
410 struct tegra_clk_pll_freq_table *cfg)
411{
412 u32 val;
413
414 val = pll_readl_base(pll);
415
416 cfg->m = (val >> pll->divm_shift) & (divm_mask(pll));
417 cfg->n = (val >> pll->divn_shift) & (divn_mask(pll));
418 cfg->p = (val >> pll->divp_shift) & (divp_mask(pll));
419}
420
421static void _update_pll_cpcon(struct tegra_clk_pll *pll,
422 struct tegra_clk_pll_freq_table *cfg,
423 unsigned long rate)
424{
425 u32 val;
426
427 val = pll_readl_misc(pll);
428
429 val &= ~(PLL_MISC_CPCON_MASK << PLL_MISC_CPCON_SHIFT);
430 val |= cfg->cpcon << PLL_MISC_CPCON_SHIFT;
431
432 if (pll->flags & TEGRA_PLL_SET_LFCON) {
433 val &= ~(PLL_MISC_LFCON_MASK << PLL_MISC_LFCON_SHIFT);
434 if (cfg->n >= PLLDU_LFCON_SET_DIVN)
435 val |= 1 << PLL_MISC_LFCON_SHIFT;
436 } else if (pll->flags & TEGRA_PLL_SET_DCCON) {
437 val &= ~(1 << PLL_MISC_DCCON_SHIFT);
438 if (rate >= (pll->params->vco_max >> 1))
439 val |= 1 << PLL_MISC_DCCON_SHIFT;
335 } 440 }
336 441
442 pll_writel_misc(val, pll);
443}
444
445static int _program_pll(struct clk_hw *hw, struct tegra_clk_pll_freq_table *cfg,
446 unsigned long rate)
447{
448 struct tegra_clk_pll *pll = to_clk_pll(hw);
449 int state, ret = 0;
450
337 state = clk_pll_is_enabled(hw); 451 state = clk_pll_is_enabled(hw);
338 452
339 if (state) { 453 if (state)
340 _clk_pll_disable(hw); 454 _clk_pll_disable(hw);
341 val &= ~(PLL_BASE_BYPASS | PLL_BASE_ENABLE);
342 }
343 pll_writel_base(val, pll);
344 455
345 if (pll->flags & TEGRA_PLL_HAS_CPCON) { 456 _update_pll_mnp(pll, cfg);
346 val = pll_readl_misc(pll);
347 val &= ~(PLL_MISC_CPCON_MASK << PLL_MISC_CPCON_SHIFT);
348 val |= cfg->cpcon << PLL_MISC_CPCON_SHIFT;
349 if (pll->flags & TEGRA_PLL_SET_LFCON) {
350 val &= ~(PLL_MISC_LFCON_MASK << PLL_MISC_LFCON_SHIFT);
351 if (cfg->n >= PLLDU_LFCON_SET_DIVN)
352 val |= 0x1 << PLL_MISC_LFCON_SHIFT;
353 } else if (pll->flags & TEGRA_PLL_SET_DCCON) {
354 val &= ~(0x1 << PLL_MISC_DCCON_SHIFT);
355 if (rate >= (pll->params->vco_max >> 1))
356 val |= 0x1 << PLL_MISC_DCCON_SHIFT;
357 }
358 pll_writel_misc(val, pll);
359 }
360 457
361 if (pll->lock) 458 if (pll->flags & TEGRA_PLL_HAS_CPCON)
362 spin_unlock_irqrestore(pll->lock, flags); 459 _update_pll_cpcon(pll, cfg, rate);
363 460
364 if (state) 461 if (state) {
365 clk_pll_enable(hw); 462 _clk_pll_enable(hw);
463 ret = clk_pll_wait_for_lock(pll);
464 }
366 465
367 return 0; 466 return ret;
368} 467}
369 468
370static int clk_pll_set_rate(struct clk_hw *hw, unsigned long rate, 469static int clk_pll_set_rate(struct clk_hw *hw, unsigned long rate,
371 unsigned long parent_rate) 470 unsigned long parent_rate)
372{ 471{
373 struct tegra_clk_pll *pll = to_clk_pll(hw); 472 struct tegra_clk_pll *pll = to_clk_pll(hw);
374 struct tegra_clk_pll_freq_table cfg; 473 struct tegra_clk_pll_freq_table cfg, old_cfg;
474 unsigned long flags = 0;
475 int ret = 0;
375 476
376 if (pll->flags & TEGRA_PLL_FIXED) { 477 if (pll->flags & TEGRA_PLL_FIXED) {
377 if (rate != pll->fixed_rate) { 478 if (rate != pll->fixed_rate) {
@@ -387,7 +488,18 @@ static int clk_pll_set_rate(struct clk_hw *hw, unsigned long rate,
387 _calc_rate(hw, &cfg, rate, parent_rate)) 488 _calc_rate(hw, &cfg, rate, parent_rate))
388 return -EINVAL; 489 return -EINVAL;
389 490
390 return _program_pll(hw, &cfg, rate); 491 if (pll->lock)
492 spin_lock_irqsave(pll->lock, flags);
493
494 _get_pll_mnp(pll, &old_cfg);
495
496 if (old_cfg.m != cfg.m || old_cfg.n != cfg.n || old_cfg.p != cfg.p)
497 ret = _program_pll(hw, &cfg, rate);
498
499 if (pll->lock)
500 spin_unlock_irqrestore(pll->lock, flags);
501
502 return ret;
391} 503}
392 504
393static long clk_pll_round_rate(struct clk_hw *hw, unsigned long rate, 505static long clk_pll_round_rate(struct clk_hw *hw, unsigned long rate,
@@ -409,7 +521,7 @@ static long clk_pll_round_rate(struct clk_hw *hw, unsigned long rate,
409 return -EINVAL; 521 return -EINVAL;
410 522
411 output_rate *= cfg.n; 523 output_rate *= cfg.n;
412 do_div(output_rate, cfg.m * cfg.p); 524 do_div(output_rate, cfg.m * (1 << cfg.p));
413 525
414 return output_rate; 526 return output_rate;
415} 527}
@@ -418,11 +530,15 @@ static unsigned long clk_pll_recalc_rate(struct clk_hw *hw,
418 unsigned long parent_rate) 530 unsigned long parent_rate)
419{ 531{
420 struct tegra_clk_pll *pll = to_clk_pll(hw); 532 struct tegra_clk_pll *pll = to_clk_pll(hw);
421 u32 val = pll_readl_base(pll); 533 struct tegra_clk_pll_freq_table cfg;
422 u32 divn = 0, divm = 0, divp = 0; 534 struct pdiv_map *p_tohw = pll->params->pdiv_tohw;
535 u32 val;
423 u64 rate = parent_rate; 536 u64 rate = parent_rate;
537 int pdiv;
538
539 val = pll_readl_base(pll);
424 540
425 if (val & PLL_BASE_BYPASS) 541 if ((pll->flags & TEGRA_PLL_BYPASS) && (val & PLL_BASE_BYPASS))
426 return parent_rate; 542 return parent_rate;
427 543
428 if ((pll->flags & TEGRA_PLL_FIXED) && !(val & PLL_BASE_OVERRIDE)) { 544 if ((pll->flags & TEGRA_PLL_FIXED) && !(val & PLL_BASE_OVERRIDE)) {
@@ -435,16 +551,29 @@ static unsigned long clk_pll_recalc_rate(struct clk_hw *hw,
435 return pll->fixed_rate; 551 return pll->fixed_rate;
436 } 552 }
437 553
438 divp = (val >> pll->divp_shift) & (divp_mask(pll)); 554 _get_pll_mnp(pll, &cfg);
439 if (pll->flags & TEGRA_PLLU)
440 divp ^= 1;
441 555
442 divn = (val >> pll->divn_shift) & (divn_mask(pll)); 556 if (p_tohw) {
443 divm = (val >> pll->divm_shift) & (divm_mask(pll)); 557 while (p_tohw->pdiv) {
444 divm *= (1 << divp); 558 if (cfg.p == p_tohw->hw_val) {
559 pdiv = p_tohw->pdiv;
560 break;
561 }
562 p_tohw++;
563 }
564
565 if (!p_tohw->pdiv) {
566 WARN_ON(1);
567 pdiv = 1;
568 }
569 } else
570 pdiv = 1 << cfg.p;
571
572 cfg.m *= pdiv;
573
574 rate *= cfg.n;
575 do_div(rate, cfg.m);
445 576
446 rate *= divn;
447 do_div(rate, divm);
448 return rate; 577 return rate;
449} 578}
450 579
@@ -538,8 +667,8 @@ static int clk_plle_enable(struct clk_hw *hw)
538 val |= (PLL_BASE_BYPASS | PLL_BASE_ENABLE); 667 val |= (PLL_BASE_BYPASS | PLL_BASE_ENABLE);
539 pll_writel_base(val, pll); 668 pll_writel_base(val, pll);
540 669
541 clk_pll_wait_for_lock(pll, pll->clk_base + pll->params->misc_reg, 670 clk_pll_wait_for_lock(pll);
542 pll->params->lock_bit_idx); 671
543 return 0; 672 return 0;
544} 673}
545 674
@@ -577,28 +706,531 @@ const struct clk_ops tegra_clk_plle_ops = {
577 .enable = clk_plle_enable, 706 .enable = clk_plle_enable,
578}; 707};
579 708
580static struct clk *_tegra_clk_register_pll(const char *name, 709#ifdef CONFIG_ARCH_TEGRA_114_SOC
581 const char *parent_name, void __iomem *clk_base, 710
582 void __iomem *pmc, unsigned long flags, 711static int _pll_fixed_mdiv(struct tegra_clk_pll_params *pll_params,
583 unsigned long fixed_rate, 712 unsigned long parent_rate)
584 struct tegra_clk_pll_params *pll_params, u8 pll_flags, 713{
585 struct tegra_clk_pll_freq_table *freq_table, spinlock_t *lock, 714 if (parent_rate > pll_params->cf_max)
586 const struct clk_ops *ops) 715 return 2;
716 else
717 return 1;
718}
719
720static int clk_pll_iddq_enable(struct clk_hw *hw)
721{
722 struct tegra_clk_pll *pll = to_clk_pll(hw);
723 unsigned long flags = 0;
724
725 u32 val;
726 int ret;
727
728 if (pll->lock)
729 spin_lock_irqsave(pll->lock, flags);
730
731 val = pll_readl(pll->params->iddq_reg, pll);
732 val &= ~BIT(pll->params->iddq_bit_idx);
733 pll_writel(val, pll->params->iddq_reg, pll);
734 udelay(2);
735
736 _clk_pll_enable(hw);
737
738 ret = clk_pll_wait_for_lock(pll);
739
740 if (pll->lock)
741 spin_unlock_irqrestore(pll->lock, flags);
742
743 return 0;
744}
745
746static void clk_pll_iddq_disable(struct clk_hw *hw)
747{
748 struct tegra_clk_pll *pll = to_clk_pll(hw);
749 unsigned long flags = 0;
750 u32 val;
751
752 if (pll->lock)
753 spin_lock_irqsave(pll->lock, flags);
754
755 _clk_pll_disable(hw);
756
757 val = pll_readl(pll->params->iddq_reg, pll);
758 val |= BIT(pll->params->iddq_bit_idx);
759 pll_writel(val, pll->params->iddq_reg, pll);
760 udelay(2);
761
762 if (pll->lock)
763 spin_unlock_irqrestore(pll->lock, flags);
764}
765
766static int _calc_dynamic_ramp_rate(struct clk_hw *hw,
767 struct tegra_clk_pll_freq_table *cfg,
768 unsigned long rate, unsigned long parent_rate)
769{
770 struct tegra_clk_pll *pll = to_clk_pll(hw);
771 unsigned int p;
772
773 if (!rate)
774 return -EINVAL;
775
776 p = DIV_ROUND_UP(pll->params->vco_min, rate);
777 cfg->m = _pll_fixed_mdiv(pll->params, parent_rate);
778 cfg->p = p;
779 cfg->output_rate = rate * cfg->p;
780 cfg->n = cfg->output_rate * cfg->m / parent_rate;
781
782 if (cfg->n > divn_max(pll) || cfg->output_rate > pll->params->vco_max)
783 return -EINVAL;
784
785 return 0;
786}
787
788static int _pll_ramp_calc_pll(struct clk_hw *hw,
789 struct tegra_clk_pll_freq_table *cfg,
790 unsigned long rate, unsigned long parent_rate)
791{
792 struct tegra_clk_pll *pll = to_clk_pll(hw);
793 int err = 0;
794
795 err = _get_table_rate(hw, cfg, rate, parent_rate);
796 if (err < 0)
797 err = _calc_dynamic_ramp_rate(hw, cfg, rate, parent_rate);
798 else if (cfg->m != _pll_fixed_mdiv(pll->params, parent_rate)) {
799 WARN_ON(1);
800 err = -EINVAL;
801 goto out;
802 }
803
804 if (!cfg->p || (cfg->p > pll->params->max_p))
805 err = -EINVAL;
806
807out:
808 return err;
809}
810
811static int clk_pllxc_set_rate(struct clk_hw *hw, unsigned long rate,
812 unsigned long parent_rate)
813{
814 struct tegra_clk_pll *pll = to_clk_pll(hw);
815 struct tegra_clk_pll_freq_table cfg, old_cfg;
816 unsigned long flags = 0;
817 int ret = 0;
818 u8 old_p;
819
820 ret = _pll_ramp_calc_pll(hw, &cfg, rate, parent_rate);
821 if (ret < 0)
822 return ret;
823
824 if (pll->lock)
825 spin_lock_irqsave(pll->lock, flags);
826
827 _get_pll_mnp(pll, &old_cfg);
828
829 old_p = pllxc_p[old_cfg.p];
830 if (old_cfg.m != cfg.m || old_cfg.n != cfg.n || old_p != cfg.p) {
831 cfg.p -= 1;
832 ret = _program_pll(hw, &cfg, rate);
833 }
834
835 if (pll->lock)
836 spin_unlock_irqrestore(pll->lock, flags);
837
838 return ret;
839}
840
841static long clk_pll_ramp_round_rate(struct clk_hw *hw, unsigned long rate,
842 unsigned long *prate)
843{
844 struct tegra_clk_pll_freq_table cfg;
845 int ret = 0;
846 u64 output_rate = *prate;
847
848 ret = _pll_ramp_calc_pll(hw, &cfg, rate, *prate);
849 if (ret < 0)
850 return ret;
851
852 output_rate *= cfg.n;
853 do_div(output_rate, cfg.m * cfg.p);
854
855 return output_rate;
856}
857
858static int clk_pllm_set_rate(struct clk_hw *hw, unsigned long rate,
859 unsigned long parent_rate)
860{
861 struct tegra_clk_pll_freq_table cfg;
862 struct tegra_clk_pll *pll = to_clk_pll(hw);
863 unsigned long flags = 0;
864 int state, ret = 0;
865 u32 val;
866
867 if (pll->lock)
868 spin_lock_irqsave(pll->lock, flags);
869
870 state = clk_pll_is_enabled(hw);
871 if (state) {
872 if (rate != clk_get_rate(hw->clk)) {
873 pr_err("%s: Cannot change active PLLM\n", __func__);
874 ret = -EINVAL;
875 goto out;
876 }
877 goto out;
878 }
879
880 ret = _pll_ramp_calc_pll(hw, &cfg, rate, parent_rate);
881 if (ret < 0)
882 goto out;
883
884 cfg.p -= 1;
885
886 val = readl_relaxed(pll->pmc + PMC_PLLM_WB0_OVERRIDE);
887 if (val & PMC_PLLP_WB0_OVERRIDE_PLLM_OVERRIDE) {
888 val = readl_relaxed(pll->pmc + PMC_PLLM_WB0_OVERRIDE_2);
889 val = cfg.p ? (val | PMC_PLLM_WB0_OVERRIDE_2_DIVP_MASK) :
890 (val & ~PMC_PLLM_WB0_OVERRIDE_2_DIVP_MASK);
891 writel_relaxed(val, pll->pmc + PMC_PLLM_WB0_OVERRIDE_2);
892
893 val = readl_relaxed(pll->pmc + PMC_PLLM_WB0_OVERRIDE);
894 val &= ~(divn_mask(pll) | divm_mask(pll));
895 val |= (cfg.m << pll->divm_shift) | (cfg.n << pll->divn_shift);
896 writel_relaxed(val, pll->pmc + PMC_PLLM_WB0_OVERRIDE);
897 } else
898 _update_pll_mnp(pll, &cfg);
899
900
901out:
902 if (pll->lock)
903 spin_unlock_irqrestore(pll->lock, flags);
904
905 return ret;
906}
907
908static void _pllcx_strobe(struct tegra_clk_pll *pll)
909{
910 u32 val;
911
912 val = pll_readl_misc(pll);
913 val |= PLLCX_MISC_STROBE;
914 pll_writel_misc(val, pll);
915 udelay(2);
916
917 val &= ~PLLCX_MISC_STROBE;
918 pll_writel_misc(val, pll);
919}
920
921static int clk_pllc_enable(struct clk_hw *hw)
922{
923 struct tegra_clk_pll *pll = to_clk_pll(hw);
924 u32 val;
925 int ret = 0;
926 unsigned long flags = 0;
927
928 if (pll->lock)
929 spin_lock_irqsave(pll->lock, flags);
930
931 _clk_pll_enable(hw);
932 udelay(2);
933
934 val = pll_readl_misc(pll);
935 val &= ~PLLCX_MISC_RESET;
936 pll_writel_misc(val, pll);
937 udelay(2);
938
939 _pllcx_strobe(pll);
940
941 ret = clk_pll_wait_for_lock(pll);
942
943 if (pll->lock)
944 spin_unlock_irqrestore(pll->lock, flags);
945
946 return ret;
947}
948
949static void _clk_pllc_disable(struct clk_hw *hw)
950{
951 struct tegra_clk_pll *pll = to_clk_pll(hw);
952 u32 val;
953
954 _clk_pll_disable(hw);
955
956 val = pll_readl_misc(pll);
957 val |= PLLCX_MISC_RESET;
958 pll_writel_misc(val, pll);
959 udelay(2);
960}
961
962static void clk_pllc_disable(struct clk_hw *hw)
963{
964 struct tegra_clk_pll *pll = to_clk_pll(hw);
965 unsigned long flags = 0;
966
967 if (pll->lock)
968 spin_lock_irqsave(pll->lock, flags);
969
970 _clk_pllc_disable(hw);
971
972 if (pll->lock)
973 spin_unlock_irqrestore(pll->lock, flags);
974}
975
976static int _pllcx_update_dynamic_coef(struct tegra_clk_pll *pll,
977 unsigned long input_rate, u32 n)
978{
979 u32 val, n_threshold;
980
981 switch (input_rate) {
982 case 12000000:
983 n_threshold = 70;
984 break;
985 case 13000000:
986 case 26000000:
987 n_threshold = 71;
988 break;
989 case 16800000:
990 n_threshold = 55;
991 break;
992 case 19200000:
993 n_threshold = 48;
994 break;
995 default:
996 pr_err("%s: Unexpected reference rate %lu\n",
997 __func__, input_rate);
998 return -EINVAL;
999 }
1000
1001 val = pll_readl_misc(pll);
1002 val &= ~(PLLCX_MISC_SDM_DIV_MASK | PLLCX_MISC_FILT_DIV_MASK);
1003 val |= n <= n_threshold ?
1004 PLLCX_MISC_DIV_LOW_RANGE : PLLCX_MISC_DIV_HIGH_RANGE;
1005 pll_writel_misc(val, pll);
1006
1007 return 0;
1008}
1009
1010static int clk_pllc_set_rate(struct clk_hw *hw, unsigned long rate,
1011 unsigned long parent_rate)
1012{
1013 struct tegra_clk_pll_freq_table cfg;
1014 struct tegra_clk_pll *pll = to_clk_pll(hw);
1015 unsigned long flags = 0;
1016 int state, ret = 0;
1017 u32 val;
1018 u16 old_m, old_n;
1019 u8 old_p;
1020
1021 if (pll->lock)
1022 spin_lock_irqsave(pll->lock, flags);
1023
1024 ret = _pll_ramp_calc_pll(hw, &cfg, rate, parent_rate);
1025 if (ret < 0)
1026 goto out;
1027
1028 val = pll_readl_base(pll);
1029 old_m = (val >> pll->divm_shift) & (divm_mask(pll));
1030 old_n = (val >> pll->divn_shift) & (divn_mask(pll));
1031 old_p = pllcx_p[(val >> pll->divp_shift) & (divp_mask(pll))];
1032
1033 if (cfg.m != old_m) {
1034 WARN_ON(1);
1035 goto out;
1036 }
1037
1038 if (old_n == cfg.n && old_p == cfg.p)
1039 goto out;
1040
1041 cfg.p -= 1;
1042
1043 state = clk_pll_is_enabled(hw);
1044 if (state)
1045 _clk_pllc_disable(hw);
1046
1047 ret = _pllcx_update_dynamic_coef(pll, parent_rate, cfg.n);
1048 if (ret < 0)
1049 goto out;
1050
1051 _update_pll_mnp(pll, &cfg);
1052
1053 if (state)
1054 ret = clk_pllc_enable(hw);
1055
1056out:
1057 if (pll->lock)
1058 spin_unlock_irqrestore(pll->lock, flags);
1059
1060 return ret;
1061}
1062
1063static long _pllre_calc_rate(struct tegra_clk_pll *pll,
1064 struct tegra_clk_pll_freq_table *cfg,
1065 unsigned long rate, unsigned long parent_rate)
1066{
1067 u16 m, n;
1068 u64 output_rate = parent_rate;
1069
1070 m = _pll_fixed_mdiv(pll->params, parent_rate);
1071 n = rate * m / parent_rate;
1072
1073 output_rate *= n;
1074 do_div(output_rate, m);
1075
1076 if (cfg) {
1077 cfg->m = m;
1078 cfg->n = n;
1079 }
1080
1081 return output_rate;
1082}
1083static int clk_pllre_set_rate(struct clk_hw *hw, unsigned long rate,
1084 unsigned long parent_rate)
1085{
1086 struct tegra_clk_pll_freq_table cfg, old_cfg;
1087 struct tegra_clk_pll *pll = to_clk_pll(hw);
1088 unsigned long flags = 0;
1089 int state, ret = 0;
1090
1091 if (pll->lock)
1092 spin_lock_irqsave(pll->lock, flags);
1093
1094 _pllre_calc_rate(pll, &cfg, rate, parent_rate);
1095 _get_pll_mnp(pll, &old_cfg);
1096 cfg.p = old_cfg.p;
1097
1098 if (cfg.m != old_cfg.m || cfg.n != old_cfg.n) {
1099 state = clk_pll_is_enabled(hw);
1100 if (state)
1101 _clk_pll_disable(hw);
1102
1103 _update_pll_mnp(pll, &cfg);
1104
1105 if (state) {
1106 _clk_pll_enable(hw);
1107 ret = clk_pll_wait_for_lock(pll);
1108 }
1109 }
1110
1111 if (pll->lock)
1112 spin_unlock_irqrestore(pll->lock, flags);
1113
1114 return ret;
1115}
1116
1117static unsigned long clk_pllre_recalc_rate(struct clk_hw *hw,
1118 unsigned long parent_rate)
1119{
1120 struct tegra_clk_pll_freq_table cfg;
1121 struct tegra_clk_pll *pll = to_clk_pll(hw);
1122 u64 rate = parent_rate;
1123
1124 _get_pll_mnp(pll, &cfg);
1125
1126 rate *= cfg.n;
1127 do_div(rate, cfg.m);
1128
1129 return rate;
1130}
1131
1132static long clk_pllre_round_rate(struct clk_hw *hw, unsigned long rate,
1133 unsigned long *prate)
1134{
1135 struct tegra_clk_pll *pll = to_clk_pll(hw);
1136
1137 return _pllre_calc_rate(pll, NULL, rate, *prate);
1138}
1139
1140static int clk_plle_tegra114_enable(struct clk_hw *hw)
1141{
1142 struct tegra_clk_pll *pll = to_clk_pll(hw);
1143 struct tegra_clk_pll_freq_table sel;
1144 u32 val;
1145 int ret;
1146 unsigned long flags = 0;
1147 unsigned long input_rate = clk_get_rate(clk_get_parent(hw->clk));
1148
1149 if (_get_table_rate(hw, &sel, pll->fixed_rate, input_rate))
1150 return -EINVAL;
1151
1152 if (pll->lock)
1153 spin_lock_irqsave(pll->lock, flags);
1154
1155 val = pll_readl_base(pll);
1156 val &= ~BIT(29); /* Disable lock override */
1157 pll_writel_base(val, pll);
1158
1159 val = pll_readl(pll->params->aux_reg, pll);
1160 val |= PLLE_AUX_ENABLE_SWCTL;
1161 val &= ~PLLE_AUX_SEQ_ENABLE;
1162 pll_writel(val, pll->params->aux_reg, pll);
1163 udelay(1);
1164
1165 val = pll_readl_misc(pll);
1166 val |= PLLE_MISC_LOCK_ENABLE;
1167 val |= PLLE_MISC_IDDQ_SW_CTRL;
1168 val &= ~PLLE_MISC_IDDQ_SW_VALUE;
1169 val |= PLLE_MISC_PLLE_PTS;
1170 val |= PLLE_MISC_VREG_BG_CTRL_MASK | PLLE_MISC_VREG_CTRL_MASK;
1171 pll_writel_misc(val, pll);
1172 udelay(5);
1173
1174 val = pll_readl(PLLE_SS_CTRL, pll);
1175 val |= PLLE_SS_DISABLE;
1176 pll_writel(val, PLLE_SS_CTRL, pll);
1177
1178 val = pll_readl_base(pll);
1179 val &= ~(divm_mask(pll) | divn_mask(pll) | divp_mask(pll));
1180 val &= ~(PLLE_BASE_DIVCML_WIDTH << PLLE_BASE_DIVCML_SHIFT);
1181 val |= sel.m << pll->divm_shift;
1182 val |= sel.n << pll->divn_shift;
1183 val |= sel.cpcon << PLLE_BASE_DIVCML_SHIFT;
1184 pll_writel_base(val, pll);
1185 udelay(1);
1186
1187 _clk_pll_enable(hw);
1188 ret = clk_pll_wait_for_lock(pll);
1189
1190 if (ret < 0)
1191 goto out;
1192
1193 /* TODO: enable hw control of xusb brick pll */
1194
1195out:
1196 if (pll->lock)
1197 spin_unlock_irqrestore(pll->lock, flags);
1198
1199 return ret;
1200}
1201
1202static void clk_plle_tegra114_disable(struct clk_hw *hw)
1203{
1204 struct tegra_clk_pll *pll = to_clk_pll(hw);
1205 unsigned long flags = 0;
1206 u32 val;
1207
1208 if (pll->lock)
1209 spin_lock_irqsave(pll->lock, flags);
1210
1211 _clk_pll_disable(hw);
1212
1213 val = pll_readl_misc(pll);
1214 val |= PLLE_MISC_IDDQ_SW_CTRL | PLLE_MISC_IDDQ_SW_VALUE;
1215 pll_writel_misc(val, pll);
1216 udelay(1);
1217
1218 if (pll->lock)
1219 spin_unlock_irqrestore(pll->lock, flags);
1220}
1221#endif
1222
1223static struct tegra_clk_pll *_tegra_init_pll(void __iomem *clk_base,
1224 void __iomem *pmc, unsigned long fixed_rate,
1225 struct tegra_clk_pll_params *pll_params, u32 pll_flags,
1226 struct tegra_clk_pll_freq_table *freq_table, spinlock_t *lock)
587{ 1227{
588 struct tegra_clk_pll *pll; 1228 struct tegra_clk_pll *pll;
589 struct clk *clk;
590 struct clk_init_data init;
591 1229
592 pll = kzalloc(sizeof(*pll), GFP_KERNEL); 1230 pll = kzalloc(sizeof(*pll), GFP_KERNEL);
593 if (!pll) 1231 if (!pll)
594 return ERR_PTR(-ENOMEM); 1232 return ERR_PTR(-ENOMEM);
595 1233
596 init.name = name;
597 init.ops = ops;
598 init.flags = flags;
599 init.parent_names = (parent_name ? &parent_name : NULL);
600 init.num_parents = (parent_name ? 1 : 0);
601
602 pll->clk_base = clk_base; 1234 pll->clk_base = clk_base;
603 pll->pmc = pmc; 1235 pll->pmc = pmc;
604 1236
@@ -615,34 +1247,336 @@ static struct clk *_tegra_clk_register_pll(const char *name,
615 pll->divm_shift = PLL_BASE_DIVM_SHIFT; 1247 pll->divm_shift = PLL_BASE_DIVM_SHIFT;
616 pll->divm_width = PLL_BASE_DIVM_WIDTH; 1248 pll->divm_width = PLL_BASE_DIVM_WIDTH;
617 1249
1250 return pll;
1251}
1252
1253static struct clk *_tegra_clk_register_pll(struct tegra_clk_pll *pll,
1254 const char *name, const char *parent_name, unsigned long flags,
1255 const struct clk_ops *ops)
1256{
1257 struct clk_init_data init;
1258
1259 init.name = name;
1260 init.ops = ops;
1261 init.flags = flags;
1262 init.parent_names = (parent_name ? &parent_name : NULL);
1263 init.num_parents = (parent_name ? 1 : 0);
1264
618 /* Data in .init is copied by clk_register(), so stack variable OK */ 1265 /* Data in .init is copied by clk_register(), so stack variable OK */
619 pll->hw.init = &init; 1266 pll->hw.init = &init;
620 1267
621 clk = clk_register(NULL, &pll->hw); 1268 return clk_register(NULL, &pll->hw);
622 if (IS_ERR(clk))
623 kfree(pll);
624
625 return clk;
626} 1269}
627 1270
628struct clk *tegra_clk_register_pll(const char *name, const char *parent_name, 1271struct clk *tegra_clk_register_pll(const char *name, const char *parent_name,
629 void __iomem *clk_base, void __iomem *pmc, 1272 void __iomem *clk_base, void __iomem *pmc,
630 unsigned long flags, unsigned long fixed_rate, 1273 unsigned long flags, unsigned long fixed_rate,
631 struct tegra_clk_pll_params *pll_params, u8 pll_flags, 1274 struct tegra_clk_pll_params *pll_params, u32 pll_flags,
632 struct tegra_clk_pll_freq_table *freq_table, spinlock_t *lock) 1275 struct tegra_clk_pll_freq_table *freq_table, spinlock_t *lock)
633{ 1276{
634 return _tegra_clk_register_pll(name, parent_name, clk_base, pmc, 1277 struct tegra_clk_pll *pll;
635 flags, fixed_rate, pll_params, pll_flags, freq_table, 1278 struct clk *clk;
636 lock, &tegra_clk_pll_ops); 1279
1280 pll_flags |= TEGRA_PLL_BYPASS;
1281 pll_flags |= TEGRA_PLL_HAS_LOCK_ENABLE;
1282 pll = _tegra_init_pll(clk_base, pmc, fixed_rate, pll_params, pll_flags,
1283 freq_table, lock);
1284 if (IS_ERR(pll))
1285 return ERR_CAST(pll);
1286
1287 clk = _tegra_clk_register_pll(pll, name, parent_name, flags,
1288 &tegra_clk_pll_ops);
1289 if (IS_ERR(clk))
1290 kfree(pll);
1291
1292 return clk;
637} 1293}
638 1294
639struct clk *tegra_clk_register_plle(const char *name, const char *parent_name, 1295struct clk *tegra_clk_register_plle(const char *name, const char *parent_name,
640 void __iomem *clk_base, void __iomem *pmc, 1296 void __iomem *clk_base, void __iomem *pmc,
641 unsigned long flags, unsigned long fixed_rate, 1297 unsigned long flags, unsigned long fixed_rate,
642 struct tegra_clk_pll_params *pll_params, u8 pll_flags, 1298 struct tegra_clk_pll_params *pll_params, u32 pll_flags,
643 struct tegra_clk_pll_freq_table *freq_table, spinlock_t *lock) 1299 struct tegra_clk_pll_freq_table *freq_table, spinlock_t *lock)
644{ 1300{
645 return _tegra_clk_register_pll(name, parent_name, clk_base, pmc, 1301 struct tegra_clk_pll *pll;
646 flags, fixed_rate, pll_params, pll_flags, freq_table, 1302 struct clk *clk;
647 lock, &tegra_clk_plle_ops); 1303
1304 pll_flags |= TEGRA_PLL_LOCK_MISC | TEGRA_PLL_BYPASS;
1305 pll_flags |= TEGRA_PLL_HAS_LOCK_ENABLE;
1306 pll = _tegra_init_pll(clk_base, pmc, fixed_rate, pll_params, pll_flags,
1307 freq_table, lock);
1308 if (IS_ERR(pll))
1309 return ERR_CAST(pll);
1310
1311 clk = _tegra_clk_register_pll(pll, name, parent_name, flags,
1312 &tegra_clk_plle_ops);
1313 if (IS_ERR(clk))
1314 kfree(pll);
1315
1316 return clk;
1317}
1318
1319#ifdef CONFIG_ARCH_TEGRA_114_SOC
1320const struct clk_ops tegra_clk_pllxc_ops = {
1321 .is_enabled = clk_pll_is_enabled,
1322 .enable = clk_pll_iddq_enable,
1323 .disable = clk_pll_iddq_disable,
1324 .recalc_rate = clk_pll_recalc_rate,
1325 .round_rate = clk_pll_ramp_round_rate,
1326 .set_rate = clk_pllxc_set_rate,
1327};
1328
1329const struct clk_ops tegra_clk_pllm_ops = {
1330 .is_enabled = clk_pll_is_enabled,
1331 .enable = clk_pll_iddq_enable,
1332 .disable = clk_pll_iddq_disable,
1333 .recalc_rate = clk_pll_recalc_rate,
1334 .round_rate = clk_pll_ramp_round_rate,
1335 .set_rate = clk_pllm_set_rate,
1336};
1337
1338const struct clk_ops tegra_clk_pllc_ops = {
1339 .is_enabled = clk_pll_is_enabled,
1340 .enable = clk_pllc_enable,
1341 .disable = clk_pllc_disable,
1342 .recalc_rate = clk_pll_recalc_rate,
1343 .round_rate = clk_pll_ramp_round_rate,
1344 .set_rate = clk_pllc_set_rate,
1345};
1346
1347const struct clk_ops tegra_clk_pllre_ops = {
1348 .is_enabled = clk_pll_is_enabled,
1349 .enable = clk_pll_iddq_enable,
1350 .disable = clk_pll_iddq_disable,
1351 .recalc_rate = clk_pllre_recalc_rate,
1352 .round_rate = clk_pllre_round_rate,
1353 .set_rate = clk_pllre_set_rate,
1354};
1355
1356const struct clk_ops tegra_clk_plle_tegra114_ops = {
1357 .is_enabled = clk_pll_is_enabled,
1358 .enable = clk_plle_tegra114_enable,
1359 .disable = clk_plle_tegra114_disable,
1360 .recalc_rate = clk_pll_recalc_rate,
1361};
1362
1363
1364struct clk *tegra_clk_register_pllxc(const char *name, const char *parent_name,
1365 void __iomem *clk_base, void __iomem *pmc,
1366 unsigned long flags, unsigned long fixed_rate,
1367 struct tegra_clk_pll_params *pll_params,
1368 u32 pll_flags,
1369 struct tegra_clk_pll_freq_table *freq_table,
1370 spinlock_t *lock)
1371{
1372 struct tegra_clk_pll *pll;
1373 struct clk *clk;
1374
1375 if (!pll_params->pdiv_tohw)
1376 return ERR_PTR(-EINVAL);
1377
1378 pll_flags |= TEGRA_PLL_HAS_LOCK_ENABLE;
1379 pll = _tegra_init_pll(clk_base, pmc, fixed_rate, pll_params, pll_flags,
1380 freq_table, lock);
1381 if (IS_ERR(pll))
1382 return ERR_CAST(pll);
1383
1384 clk = _tegra_clk_register_pll(pll, name, parent_name, flags,
1385 &tegra_clk_pllxc_ops);
1386 if (IS_ERR(clk))
1387 kfree(pll);
1388
1389 return clk;
1390}
1391
1392struct clk *tegra_clk_register_pllre(const char *name, const char *parent_name,
1393 void __iomem *clk_base, void __iomem *pmc,
1394 unsigned long flags, unsigned long fixed_rate,
1395 struct tegra_clk_pll_params *pll_params,
1396 u32 pll_flags,
1397 struct tegra_clk_pll_freq_table *freq_table,
1398 spinlock_t *lock, unsigned long parent_rate)
1399{
1400 u32 val;
1401 struct tegra_clk_pll *pll;
1402 struct clk *clk;
1403
1404 pll_flags |= TEGRA_PLL_HAS_LOCK_ENABLE;
1405 pll = _tegra_init_pll(clk_base, pmc, fixed_rate, pll_params, pll_flags,
1406 freq_table, lock);
1407 if (IS_ERR(pll))
1408 return ERR_CAST(pll);
1409
1410 /* program minimum rate by default */
1411
1412 val = pll_readl_base(pll);
1413 if (val & PLL_BASE_ENABLE)
1414 WARN_ON(val & pll_params->iddq_bit_idx);
1415 else {
1416 int m;
1417
1418 m = _pll_fixed_mdiv(pll_params, parent_rate);
1419 val = m << PLL_BASE_DIVM_SHIFT;
1420 val |= (pll_params->vco_min / parent_rate)
1421 << PLL_BASE_DIVN_SHIFT;
1422 pll_writel_base(val, pll);
1423 }
1424
1425 /* disable lock override */
1426
1427 val = pll_readl_misc(pll);
1428 val &= ~BIT(29);
1429 pll_writel_misc(val, pll);
1430
1431 pll_flags |= TEGRA_PLL_LOCK_MISC;
1432 clk = _tegra_clk_register_pll(pll, name, parent_name, flags,
1433 &tegra_clk_pllre_ops);
1434 if (IS_ERR(clk))
1435 kfree(pll);
1436
1437 return clk;
1438}
1439
1440struct clk *tegra_clk_register_pllm(const char *name, const char *parent_name,
1441 void __iomem *clk_base, void __iomem *pmc,
1442 unsigned long flags, unsigned long fixed_rate,
1443 struct tegra_clk_pll_params *pll_params,
1444 u32 pll_flags,
1445 struct tegra_clk_pll_freq_table *freq_table,
1446 spinlock_t *lock)
1447{
1448 struct tegra_clk_pll *pll;
1449 struct clk *clk;
1450
1451 if (!pll_params->pdiv_tohw)
1452 return ERR_PTR(-EINVAL);
1453
1454 pll_flags |= TEGRA_PLL_BYPASS;
1455 pll_flags |= TEGRA_PLL_HAS_LOCK_ENABLE;
1456 pll = _tegra_init_pll(clk_base, pmc, fixed_rate, pll_params, pll_flags,
1457 freq_table, lock);
1458 if (IS_ERR(pll))
1459 return ERR_CAST(pll);
1460
1461 clk = _tegra_clk_register_pll(pll, name, parent_name, flags,
1462 &tegra_clk_pllm_ops);
1463 if (IS_ERR(clk))
1464 kfree(pll);
1465
1466 return clk;
1467}
1468
1469struct clk *tegra_clk_register_pllc(const char *name, const char *parent_name,
1470 void __iomem *clk_base, void __iomem *pmc,
1471 unsigned long flags, unsigned long fixed_rate,
1472 struct tegra_clk_pll_params *pll_params,
1473 u32 pll_flags,
1474 struct tegra_clk_pll_freq_table *freq_table,
1475 spinlock_t *lock)
1476{
1477 struct clk *parent, *clk;
1478 struct pdiv_map *p_tohw = pll_params->pdiv_tohw;
1479 struct tegra_clk_pll *pll;
1480 struct tegra_clk_pll_freq_table cfg;
1481 unsigned long parent_rate;
1482
1483 if (!p_tohw)
1484 return ERR_PTR(-EINVAL);
1485
1486 parent = __clk_lookup(parent_name);
1487 if (IS_ERR(parent)) {
1488 WARN(1, "parent clk %s of %s must be registered first\n",
1489 name, parent_name);
1490 return ERR_PTR(-EINVAL);
1491 }
1492
1493 pll_flags |= TEGRA_PLL_BYPASS;
1494 pll = _tegra_init_pll(clk_base, pmc, fixed_rate, pll_params, pll_flags,
1495 freq_table, lock);
1496 if (IS_ERR(pll))
1497 return ERR_CAST(pll);
1498
1499 parent_rate = __clk_get_rate(parent);
1500
1501 /*
1502 * Most of PLLC register fields are shadowed, and can not be read
1503 * directly from PLL h/w. Hence, actual PLLC boot state is unknown.
1504 * Initialize PLL to default state: disabled, reset; shadow registers
1505 * loaded with default parameters; dividers are preset for half of
1506 * minimum VCO rate (the latter assured that shadowed divider settings
1507 * are within supported range).
1508 */
1509
1510 cfg.m = _pll_fixed_mdiv(pll_params, parent_rate);
1511 cfg.n = cfg.m * pll_params->vco_min / parent_rate;
1512
1513 while (p_tohw->pdiv) {
1514 if (p_tohw->pdiv == 2) {
1515 cfg.p = p_tohw->hw_val;
1516 break;
1517 }
1518 p_tohw++;
1519 }
1520
1521 if (!p_tohw->pdiv) {
1522 WARN_ON(1);
1523 return ERR_PTR(-EINVAL);
1524 }
1525
1526 pll_writel_base(0, pll);
1527 _update_pll_mnp(pll, &cfg);
1528
1529 pll_writel_misc(PLLCX_MISC_DEFAULT, pll);
1530 pll_writel(PLLCX_MISC1_DEFAULT, pll_params->ext_misc_reg[0], pll);
1531 pll_writel(PLLCX_MISC2_DEFAULT, pll_params->ext_misc_reg[1], pll);
1532 pll_writel(PLLCX_MISC3_DEFAULT, pll_params->ext_misc_reg[2], pll);
1533
1534 _pllcx_update_dynamic_coef(pll, parent_rate, cfg.n);
1535
1536 clk = _tegra_clk_register_pll(pll, name, parent_name, flags,
1537 &tegra_clk_pllc_ops);
1538 if (IS_ERR(clk))
1539 kfree(pll);
1540
1541 return clk;
1542}
1543
1544struct clk *tegra_clk_register_plle_tegra114(const char *name,
1545 const char *parent_name,
1546 void __iomem *clk_base, unsigned long flags,
1547 unsigned long fixed_rate,
1548 struct tegra_clk_pll_params *pll_params,
1549 struct tegra_clk_pll_freq_table *freq_table,
1550 spinlock_t *lock)
1551{
1552 struct tegra_clk_pll *pll;
1553 struct clk *clk;
1554 u32 val, val_aux;
1555
1556 pll = _tegra_init_pll(clk_base, NULL, fixed_rate, pll_params,
1557 TEGRA_PLL_HAS_LOCK_ENABLE, freq_table, lock);
1558 if (IS_ERR(pll))
1559 return ERR_CAST(pll);
1560
1561 /* ensure parent is set to pll_re_vco */
1562
1563 val = pll_readl_base(pll);
1564 val_aux = pll_readl(pll_params->aux_reg, pll);
1565
1566 if (val & PLL_BASE_ENABLE) {
1567 if (!(val_aux & PLLE_AUX_PLLRE_SEL))
1568 WARN(1, "pll_e enabled with unsupported parent %s\n",
1569 (val & PLLE_AUX_PLLP_SEL) ? "pllp_out0" : "pll_ref");
1570 } else {
1571 val_aux |= PLLE_AUX_PLLRE_SEL;
1572 pll_writel(val, pll_params->aux_reg, pll);
1573 }
1574
1575 clk = _tegra_clk_register_pll(pll, name, parent_name, flags,
1576 &tegra_clk_plle_tegra114_ops);
1577 if (IS_ERR(clk))
1578 kfree(pll);
1579
1580 return clk;
648} 1581}
1582#endif
diff --git a/drivers/clk/tegra/clk-tegra114.c b/drivers/clk/tegra/clk-tegra114.c
new file mode 100644
index 000000000000..d78e16ee161c
--- /dev/null
+++ b/drivers/clk/tegra/clk-tegra114.c
@@ -0,0 +1,2085 @@
1/*
2 * Copyright (c) 2012, 2013, NVIDIA CORPORATION. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#include <linux/io.h>
18#include <linux/clk.h>
19#include <linux/clk-provider.h>
20#include <linux/clkdev.h>
21#include <linux/of.h>
22#include <linux/of_address.h>
23#include <linux/delay.h>
24#include <linux/clk/tegra.h>
25
26#include "clk.h"
27
28#define RST_DEVICES_L 0x004
29#define RST_DEVICES_H 0x008
30#define RST_DEVICES_U 0x00C
31#define RST_DEVICES_V 0x358
32#define RST_DEVICES_W 0x35C
33#define RST_DEVICES_X 0x28C
34#define RST_DEVICES_SET_L 0x300
35#define RST_DEVICES_CLR_L 0x304
36#define RST_DEVICES_SET_H 0x308
37#define RST_DEVICES_CLR_H 0x30c
38#define RST_DEVICES_SET_U 0x310
39#define RST_DEVICES_CLR_U 0x314
40#define RST_DEVICES_SET_V 0x430
41#define RST_DEVICES_CLR_V 0x434
42#define RST_DEVICES_SET_W 0x438
43#define RST_DEVICES_CLR_W 0x43c
44#define RST_DEVICES_NUM 5
45
46#define CLK_OUT_ENB_L 0x010
47#define CLK_OUT_ENB_H 0x014
48#define CLK_OUT_ENB_U 0x018
49#define CLK_OUT_ENB_V 0x360
50#define CLK_OUT_ENB_W 0x364
51#define CLK_OUT_ENB_X 0x280
52#define CLK_OUT_ENB_SET_L 0x320
53#define CLK_OUT_ENB_CLR_L 0x324
54#define CLK_OUT_ENB_SET_H 0x328
55#define CLK_OUT_ENB_CLR_H 0x32c
56#define CLK_OUT_ENB_SET_U 0x330
57#define CLK_OUT_ENB_CLR_U 0x334
58#define CLK_OUT_ENB_SET_V 0x440
59#define CLK_OUT_ENB_CLR_V 0x444
60#define CLK_OUT_ENB_SET_W 0x448
61#define CLK_OUT_ENB_CLR_W 0x44c
62#define CLK_OUT_ENB_SET_X 0x284
63#define CLK_OUT_ENB_CLR_X 0x288
64#define CLK_OUT_ENB_NUM 6
65
66#define PLLC_BASE 0x80
67#define PLLC_MISC2 0x88
68#define PLLC_MISC 0x8c
69#define PLLC2_BASE 0x4e8
70#define PLLC2_MISC 0x4ec
71#define PLLC3_BASE 0x4fc
72#define PLLC3_MISC 0x500
73#define PLLM_BASE 0x90
74#define PLLM_MISC 0x9c
75#define PLLP_BASE 0xa0
76#define PLLP_MISC 0xac
77#define PLLX_BASE 0xe0
78#define PLLX_MISC 0xe4
79#define PLLX_MISC2 0x514
80#define PLLX_MISC3 0x518
81#define PLLD_BASE 0xd0
82#define PLLD_MISC 0xdc
83#define PLLD2_BASE 0x4b8
84#define PLLD2_MISC 0x4bc
85#define PLLE_BASE 0xe8
86#define PLLE_MISC 0xec
87#define PLLA_BASE 0xb0
88#define PLLA_MISC 0xbc
89#define PLLU_BASE 0xc0
90#define PLLU_MISC 0xcc
91#define PLLRE_BASE 0x4c4
92#define PLLRE_MISC 0x4c8
93
94#define PLL_MISC_LOCK_ENABLE 18
95#define PLLC_MISC_LOCK_ENABLE 24
96#define PLLDU_MISC_LOCK_ENABLE 22
97#define PLLE_MISC_LOCK_ENABLE 9
98#define PLLRE_MISC_LOCK_ENABLE 30
99
100#define PLLC_IDDQ_BIT 26
101#define PLLX_IDDQ_BIT 3
102#define PLLRE_IDDQ_BIT 16
103
104#define PLL_BASE_LOCK BIT(27)
105#define PLLE_MISC_LOCK BIT(11)
106#define PLLRE_MISC_LOCK BIT(24)
107#define PLLCX_BASE_LOCK (BIT(26)|BIT(27))
108
109#define PLLE_AUX 0x48c
110#define PLLC_OUT 0x84
111#define PLLM_OUT 0x94
112#define PLLP_OUTA 0xa4
113#define PLLP_OUTB 0xa8
114#define PLLA_OUT 0xb4
115
116#define AUDIO_SYNC_CLK_I2S0 0x4a0
117#define AUDIO_SYNC_CLK_I2S1 0x4a4
118#define AUDIO_SYNC_CLK_I2S2 0x4a8
119#define AUDIO_SYNC_CLK_I2S3 0x4ac
120#define AUDIO_SYNC_CLK_I2S4 0x4b0
121#define AUDIO_SYNC_CLK_SPDIF 0x4b4
122
123#define AUDIO_SYNC_DOUBLER 0x49c
124
125#define PMC_CLK_OUT_CNTRL 0x1a8
126#define PMC_DPD_PADS_ORIDE 0x1c
127#define PMC_DPD_PADS_ORIDE_BLINK_ENB 20
128#define PMC_CTRL 0
129#define PMC_CTRL_BLINK_ENB 7
130
131#define OSC_CTRL 0x50
132#define OSC_CTRL_OSC_FREQ_SHIFT 28
133#define OSC_CTRL_PLL_REF_DIV_SHIFT 26
134
135#define PLLXC_SW_MAX_P 6
136
137#define CCLKG_BURST_POLICY 0x368
138#define CCLKLP_BURST_POLICY 0x370
139#define SCLK_BURST_POLICY 0x028
140#define SYSTEM_CLK_RATE 0x030
141
142#define UTMIP_PLL_CFG2 0x488
143#define UTMIP_PLL_CFG2_STABLE_COUNT(x) (((x) & 0xffff) << 6)
144#define UTMIP_PLL_CFG2_ACTIVE_DLY_COUNT(x) (((x) & 0x3f) << 18)
145#define UTMIP_PLL_CFG2_FORCE_PD_SAMP_A_POWERDOWN BIT(0)
146#define UTMIP_PLL_CFG2_FORCE_PD_SAMP_B_POWERDOWN BIT(2)
147#define UTMIP_PLL_CFG2_FORCE_PD_SAMP_C_POWERDOWN BIT(4)
148
149#define UTMIP_PLL_CFG1 0x484
150#define UTMIP_PLL_CFG1_ENABLE_DLY_COUNT(x) (((x) & 0x1f) << 6)
151#define UTMIP_PLL_CFG1_XTAL_FREQ_COUNT(x) (((x) & 0xfff) << 0)
152#define UTMIP_PLL_CFG1_FORCE_PLLU_POWERUP BIT(17)
153#define UTMIP_PLL_CFG1_FORCE_PLLU_POWERDOWN BIT(16)
154#define UTMIP_PLL_CFG1_FORCE_PLL_ENABLE_POWERUP BIT(15)
155#define UTMIP_PLL_CFG1_FORCE_PLL_ENABLE_POWERDOWN BIT(14)
156#define UTMIP_PLL_CFG1_FORCE_PLL_ACTIVE_POWERDOWN BIT(12)
157
158#define UTMIPLL_HW_PWRDN_CFG0 0x52c
159#define UTMIPLL_HW_PWRDN_CFG0_SEQ_START_STATE BIT(25)
160#define UTMIPLL_HW_PWRDN_CFG0_SEQ_ENABLE BIT(24)
161#define UTMIPLL_HW_PWRDN_CFG0_USE_LOCKDET BIT(6)
162#define UTMIPLL_HW_PWRDN_CFG0_SEQ_RESET_INPUT_VALUE BIT(5)
163#define UTMIPLL_HW_PWRDN_CFG0_SEQ_IN_SWCTL BIT(4)
164#define UTMIPLL_HW_PWRDN_CFG0_CLK_ENABLE_SWCTL BIT(2)
165#define UTMIPLL_HW_PWRDN_CFG0_IDDQ_OVERRIDE BIT(1)
166#define UTMIPLL_HW_PWRDN_CFG0_IDDQ_SWCTL BIT(0)
167
168#define CLK_SOURCE_I2S0 0x1d8
169#define CLK_SOURCE_I2S1 0x100
170#define CLK_SOURCE_I2S2 0x104
171#define CLK_SOURCE_NDFLASH 0x160
172#define CLK_SOURCE_I2S3 0x3bc
173#define CLK_SOURCE_I2S4 0x3c0
174#define CLK_SOURCE_SPDIF_OUT 0x108
175#define CLK_SOURCE_SPDIF_IN 0x10c
176#define CLK_SOURCE_PWM 0x110
177#define CLK_SOURCE_ADX 0x638
178#define CLK_SOURCE_AMX 0x63c
179#define CLK_SOURCE_HDA 0x428
180#define CLK_SOURCE_HDA2CODEC_2X 0x3e4
181#define CLK_SOURCE_SBC1 0x134
182#define CLK_SOURCE_SBC2 0x118
183#define CLK_SOURCE_SBC3 0x11c
184#define CLK_SOURCE_SBC4 0x1b4
185#define CLK_SOURCE_SBC5 0x3c8
186#define CLK_SOURCE_SBC6 0x3cc
187#define CLK_SOURCE_SATA_OOB 0x420
188#define CLK_SOURCE_SATA 0x424
189#define CLK_SOURCE_NDSPEED 0x3f8
190#define CLK_SOURCE_VFIR 0x168
191#define CLK_SOURCE_SDMMC1 0x150
192#define CLK_SOURCE_SDMMC2 0x154
193#define CLK_SOURCE_SDMMC3 0x1bc
194#define CLK_SOURCE_SDMMC4 0x164
195#define CLK_SOURCE_VDE 0x1c8
196#define CLK_SOURCE_CSITE 0x1d4
197#define CLK_SOURCE_LA 0x1f8
198#define CLK_SOURCE_TRACE 0x634
199#define CLK_SOURCE_OWR 0x1cc
200#define CLK_SOURCE_NOR 0x1d0
201#define CLK_SOURCE_MIPI 0x174
202#define CLK_SOURCE_I2C1 0x124
203#define CLK_SOURCE_I2C2 0x198
204#define CLK_SOURCE_I2C3 0x1b8
205#define CLK_SOURCE_I2C4 0x3c4
206#define CLK_SOURCE_I2C5 0x128
207#define CLK_SOURCE_UARTA 0x178
208#define CLK_SOURCE_UARTB 0x17c
209#define CLK_SOURCE_UARTC 0x1a0
210#define CLK_SOURCE_UARTD 0x1c0
211#define CLK_SOURCE_UARTE 0x1c4
212#define CLK_SOURCE_UARTA_DBG 0x178
213#define CLK_SOURCE_UARTB_DBG 0x17c
214#define CLK_SOURCE_UARTC_DBG 0x1a0
215#define CLK_SOURCE_UARTD_DBG 0x1c0
216#define CLK_SOURCE_UARTE_DBG 0x1c4
217#define CLK_SOURCE_3D 0x158
218#define CLK_SOURCE_2D 0x15c
219#define CLK_SOURCE_VI_SENSOR 0x1a8
220#define CLK_SOURCE_VI 0x148
221#define CLK_SOURCE_EPP 0x16c
222#define CLK_SOURCE_MSENC 0x1f0
223#define CLK_SOURCE_TSEC 0x1f4
224#define CLK_SOURCE_HOST1X 0x180
225#define CLK_SOURCE_HDMI 0x18c
226#define CLK_SOURCE_DISP1 0x138
227#define CLK_SOURCE_DISP2 0x13c
228#define CLK_SOURCE_CILAB 0x614
229#define CLK_SOURCE_CILCD 0x618
230#define CLK_SOURCE_CILE 0x61c
231#define CLK_SOURCE_DSIALP 0x620
232#define CLK_SOURCE_DSIBLP 0x624
233#define CLK_SOURCE_TSENSOR 0x3b8
234#define CLK_SOURCE_D_AUDIO 0x3d0
235#define CLK_SOURCE_DAM0 0x3d8
236#define CLK_SOURCE_DAM1 0x3dc
237#define CLK_SOURCE_DAM2 0x3e0
238#define CLK_SOURCE_ACTMON 0x3e8
239#define CLK_SOURCE_EXTERN1 0x3ec
240#define CLK_SOURCE_EXTERN2 0x3f0
241#define CLK_SOURCE_EXTERN3 0x3f4
242#define CLK_SOURCE_I2CSLOW 0x3fc
243#define CLK_SOURCE_SE 0x42c
244#define CLK_SOURCE_MSELECT 0x3b4
245#define CLK_SOURCE_SOC_THERM 0x644
246#define CLK_SOURCE_XUSB_HOST_SRC 0x600
247#define CLK_SOURCE_XUSB_FALCON_SRC 0x604
248#define CLK_SOURCE_XUSB_FS_SRC 0x608
249#define CLK_SOURCE_XUSB_SS_SRC 0x610
250#define CLK_SOURCE_XUSB_DEV_SRC 0x60c
251#define CLK_SOURCE_EMC 0x19c
252
253static int periph_clk_enb_refcnt[CLK_OUT_ENB_NUM * 32];
254
255static void __iomem *clk_base;
256static void __iomem *pmc_base;
257
258static DEFINE_SPINLOCK(pll_d_lock);
259static DEFINE_SPINLOCK(pll_d2_lock);
260static DEFINE_SPINLOCK(pll_u_lock);
261static DEFINE_SPINLOCK(pll_div_lock);
262static DEFINE_SPINLOCK(pll_re_lock);
263static DEFINE_SPINLOCK(clk_doubler_lock);
264static DEFINE_SPINLOCK(clk_out_lock);
265static DEFINE_SPINLOCK(sysrate_lock);
266
267static struct pdiv_map pllxc_p[] = {
268 { .pdiv = 1, .hw_val = 0 },
269 { .pdiv = 2, .hw_val = 1 },
270 { .pdiv = 3, .hw_val = 2 },
271 { .pdiv = 4, .hw_val = 3 },
272 { .pdiv = 5, .hw_val = 4 },
273 { .pdiv = 6, .hw_val = 5 },
274 { .pdiv = 8, .hw_val = 6 },
275 { .pdiv = 10, .hw_val = 7 },
276 { .pdiv = 12, .hw_val = 8 },
277 { .pdiv = 16, .hw_val = 9 },
278 { .pdiv = 12, .hw_val = 10 },
279 { .pdiv = 16, .hw_val = 11 },
280 { .pdiv = 20, .hw_val = 12 },
281 { .pdiv = 24, .hw_val = 13 },
282 { .pdiv = 32, .hw_val = 14 },
283 { .pdiv = 0, .hw_val = 0 },
284};
285
286static struct tegra_clk_pll_freq_table pll_c_freq_table[] = {
287 { 12000000, 624000000, 104, 0, 2},
288 { 12000000, 600000000, 100, 0, 2},
289 { 13000000, 600000000, 92, 0, 2}, /* actual: 598.0 MHz */
290 { 16800000, 600000000, 71, 0, 2}, /* actual: 596.4 MHz */
291 { 19200000, 600000000, 62, 0, 2}, /* actual: 595.2 MHz */
292 { 26000000, 600000000, 92, 1, 2}, /* actual: 598.0 MHz */
293 { 0, 0, 0, 0, 0, 0 },
294};
295
296static struct tegra_clk_pll_params pll_c_params = {
297 .input_min = 12000000,
298 .input_max = 800000000,
299 .cf_min = 12000000,
300 .cf_max = 19200000, /* s/w policy, h/w capability 50 MHz */
301 .vco_min = 600000000,
302 .vco_max = 1400000000,
303 .base_reg = PLLC_BASE,
304 .misc_reg = PLLC_MISC,
305 .lock_mask = PLL_BASE_LOCK,
306 .lock_enable_bit_idx = PLLC_MISC_LOCK_ENABLE,
307 .lock_delay = 300,
308 .iddq_reg = PLLC_MISC,
309 .iddq_bit_idx = PLLC_IDDQ_BIT,
310 .max_p = PLLXC_SW_MAX_P,
311 .dyn_ramp_reg = PLLC_MISC2,
312 .stepa_shift = 17,
313 .stepb_shift = 9,
314 .pdiv_tohw = pllxc_p,
315};
316
317static struct pdiv_map pllc_p[] = {
318 { .pdiv = 1, .hw_val = 0 },
319 { .pdiv = 2, .hw_val = 1 },
320 { .pdiv = 4, .hw_val = 3 },
321 { .pdiv = 8, .hw_val = 5 },
322 { .pdiv = 16, .hw_val = 7 },
323 { .pdiv = 0, .hw_val = 0 },
324};
325
326static struct tegra_clk_pll_freq_table pll_cx_freq_table[] = {
327 {12000000, 600000000, 100, 0, 2},
328 {13000000, 600000000, 92, 0, 2}, /* actual: 598.0 MHz */
329 {16800000, 600000000, 71, 0, 2}, /* actual: 596.4 MHz */
330 {19200000, 600000000, 62, 0, 2}, /* actual: 595.2 MHz */
331 {26000000, 600000000, 92, 1, 2}, /* actual: 598.0 MHz */
332 {0, 0, 0, 0, 0, 0},
333};
334
335static struct tegra_clk_pll_params pll_c2_params = {
336 .input_min = 12000000,
337 .input_max = 48000000,
338 .cf_min = 12000000,
339 .cf_max = 19200000,
340 .vco_min = 600000000,
341 .vco_max = 1200000000,
342 .base_reg = PLLC2_BASE,
343 .misc_reg = PLLC2_MISC,
344 .lock_mask = PLL_BASE_LOCK,
345 .lock_enable_bit_idx = PLL_MISC_LOCK_ENABLE,
346 .lock_delay = 300,
347 .pdiv_tohw = pllc_p,
348 .ext_misc_reg[0] = 0x4f0,
349 .ext_misc_reg[1] = 0x4f4,
350 .ext_misc_reg[2] = 0x4f8,
351};
352
353static struct tegra_clk_pll_params pll_c3_params = {
354 .input_min = 12000000,
355 .input_max = 48000000,
356 .cf_min = 12000000,
357 .cf_max = 19200000,
358 .vco_min = 600000000,
359 .vco_max = 1200000000,
360 .base_reg = PLLC3_BASE,
361 .misc_reg = PLLC3_MISC,
362 .lock_mask = PLL_BASE_LOCK,
363 .lock_enable_bit_idx = PLL_MISC_LOCK_ENABLE,
364 .lock_delay = 300,
365 .pdiv_tohw = pllc_p,
366 .ext_misc_reg[0] = 0x504,
367 .ext_misc_reg[1] = 0x508,
368 .ext_misc_reg[2] = 0x50c,
369};
370
371static struct pdiv_map pllm_p[] = {
372 { .pdiv = 1, .hw_val = 0 },
373 { .pdiv = 2, .hw_val = 1 },
374 { .pdiv = 0, .hw_val = 0 },
375};
376
377static struct tegra_clk_pll_freq_table pll_m_freq_table[] = {
378 {12000000, 800000000, 66, 0, 1}, /* actual: 792.0 MHz */
379 {13000000, 800000000, 61, 0, 1}, /* actual: 793.0 MHz */
380 {16800000, 800000000, 47, 0, 1}, /* actual: 789.6 MHz */
381 {19200000, 800000000, 41, 0, 1}, /* actual: 787.2 MHz */
382 {26000000, 800000000, 61, 1, 1}, /* actual: 793.0 MHz */
383 {0, 0, 0, 0, 0, 0},
384};
385
386static struct tegra_clk_pll_params pll_m_params = {
387 .input_min = 12000000,
388 .input_max = 500000000,
389 .cf_min = 12000000,
390 .cf_max = 19200000, /* s/w policy, h/w capability 50 MHz */
391 .vco_min = 400000000,
392 .vco_max = 1066000000,
393 .base_reg = PLLM_BASE,
394 .misc_reg = PLLM_MISC,
395 .lock_mask = PLL_BASE_LOCK,
396 .lock_enable_bit_idx = PLL_MISC_LOCK_ENABLE,
397 .lock_delay = 300,
398 .max_p = 2,
399 .pdiv_tohw = pllm_p,
400};
401
402static struct tegra_clk_pll_freq_table pll_p_freq_table[] = {
403 {12000000, 216000000, 432, 12, 1, 8},
404 {13000000, 216000000, 432, 13, 1, 8},
405 {16800000, 216000000, 360, 14, 1, 8},
406 {19200000, 216000000, 360, 16, 1, 8},
407 {26000000, 216000000, 432, 26, 1, 8},
408 {0, 0, 0, 0, 0, 0},
409};
410
411static struct tegra_clk_pll_params pll_p_params = {
412 .input_min = 2000000,
413 .input_max = 31000000,
414 .cf_min = 1000000,
415 .cf_max = 6000000,
416 .vco_min = 200000000,
417 .vco_max = 700000000,
418 .base_reg = PLLP_BASE,
419 .misc_reg = PLLP_MISC,
420 .lock_mask = PLL_BASE_LOCK,
421 .lock_enable_bit_idx = PLL_MISC_LOCK_ENABLE,
422 .lock_delay = 300,
423};
424
425static struct tegra_clk_pll_freq_table pll_a_freq_table[] = {
426 {9600000, 282240000, 147, 5, 0, 4},
427 {9600000, 368640000, 192, 5, 0, 4},
428 {9600000, 240000000, 200, 8, 0, 8},
429
430 {28800000, 282240000, 245, 25, 0, 8},
431 {28800000, 368640000, 320, 25, 0, 8},
432 {28800000, 240000000, 200, 24, 0, 8},
433 {0, 0, 0, 0, 0, 0},
434};
435
436
437static struct tegra_clk_pll_params pll_a_params = {
438 .input_min = 2000000,
439 .input_max = 31000000,
440 .cf_min = 1000000,
441 .cf_max = 6000000,
442 .vco_min = 200000000,
443 .vco_max = 700000000,
444 .base_reg = PLLA_BASE,
445 .misc_reg = PLLA_MISC,
446 .lock_mask = PLL_BASE_LOCK,
447 .lock_enable_bit_idx = PLL_MISC_LOCK_ENABLE,
448 .lock_delay = 300,
449};
450
451static struct tegra_clk_pll_freq_table pll_d_freq_table[] = {
452 {12000000, 216000000, 864, 12, 2, 12},
453 {13000000, 216000000, 864, 13, 2, 12},
454 {16800000, 216000000, 720, 14, 2, 12},
455 {19200000, 216000000, 720, 16, 2, 12},
456 {26000000, 216000000, 864, 26, 2, 12},
457
458 {12000000, 594000000, 594, 12, 0, 12},
459 {13000000, 594000000, 594, 13, 0, 12},
460 {16800000, 594000000, 495, 14, 0, 12},
461 {19200000, 594000000, 495, 16, 0, 12},
462 {26000000, 594000000, 594, 26, 0, 12},
463
464 {12000000, 1000000000, 1000, 12, 0, 12},
465 {13000000, 1000000000, 1000, 13, 0, 12},
466 {19200000, 1000000000, 625, 12, 0, 12},
467 {26000000, 1000000000, 1000, 26, 0, 12},
468
469 {0, 0, 0, 0, 0, 0},
470};
471
472static struct tegra_clk_pll_params pll_d_params = {
473 .input_min = 2000000,
474 .input_max = 40000000,
475 .cf_min = 1000000,
476 .cf_max = 6000000,
477 .vco_min = 500000000,
478 .vco_max = 1000000000,
479 .base_reg = PLLD_BASE,
480 .misc_reg = PLLD_MISC,
481 .lock_mask = PLL_BASE_LOCK,
482 .lock_enable_bit_idx = PLLDU_MISC_LOCK_ENABLE,
483 .lock_delay = 1000,
484};
485
486static struct tegra_clk_pll_params pll_d2_params = {
487 .input_min = 2000000,
488 .input_max = 40000000,
489 .cf_min = 1000000,
490 .cf_max = 6000000,
491 .vco_min = 500000000,
492 .vco_max = 1000000000,
493 .base_reg = PLLD2_BASE,
494 .misc_reg = PLLD2_MISC,
495 .lock_mask = PLL_BASE_LOCK,
496 .lock_enable_bit_idx = PLLDU_MISC_LOCK_ENABLE,
497 .lock_delay = 1000,
498};
499
500static struct pdiv_map pllu_p[] = {
501 { .pdiv = 1, .hw_val = 1 },
502 { .pdiv = 2, .hw_val = 0 },
503 { .pdiv = 0, .hw_val = 0 },
504};
505
506static struct tegra_clk_pll_freq_table pll_u_freq_table[] = {
507 {12000000, 480000000, 960, 12, 0, 12},
508 {13000000, 480000000, 960, 13, 0, 12},
509 {16800000, 480000000, 400, 7, 0, 5},
510 {19200000, 480000000, 200, 4, 0, 3},
511 {26000000, 480000000, 960, 26, 0, 12},
512 {0, 0, 0, 0, 0, 0},
513};
514
515static struct tegra_clk_pll_params pll_u_params = {
516 .input_min = 2000000,
517 .input_max = 40000000,
518 .cf_min = 1000000,
519 .cf_max = 6000000,
520 .vco_min = 480000000,
521 .vco_max = 960000000,
522 .base_reg = PLLU_BASE,
523 .misc_reg = PLLU_MISC,
524 .lock_mask = PLL_BASE_LOCK,
525 .lock_enable_bit_idx = PLLDU_MISC_LOCK_ENABLE,
526 .lock_delay = 1000,
527 .pdiv_tohw = pllu_p,
528};
529
530static struct tegra_clk_pll_freq_table pll_x_freq_table[] = {
531 /* 1 GHz */
532 {12000000, 1000000000, 83, 0, 1}, /* actual: 996.0 MHz */
533 {13000000, 1000000000, 76, 0, 1}, /* actual: 988.0 MHz */
534 {16800000, 1000000000, 59, 0, 1}, /* actual: 991.2 MHz */
535 {19200000, 1000000000, 52, 0, 1}, /* actual: 998.4 MHz */
536 {26000000, 1000000000, 76, 1, 1}, /* actual: 988.0 MHz */
537
538 {0, 0, 0, 0, 0, 0},
539};
540
541static struct tegra_clk_pll_params pll_x_params = {
542 .input_min = 12000000,
543 .input_max = 800000000,
544 .cf_min = 12000000,
545 .cf_max = 19200000, /* s/w policy, h/w capability 50 MHz */
546 .vco_min = 700000000,
547 .vco_max = 2400000000U,
548 .base_reg = PLLX_BASE,
549 .misc_reg = PLLX_MISC,
550 .lock_mask = PLL_BASE_LOCK,
551 .lock_enable_bit_idx = PLL_MISC_LOCK_ENABLE,
552 .lock_delay = 300,
553 .iddq_reg = PLLX_MISC3,
554 .iddq_bit_idx = PLLX_IDDQ_BIT,
555 .max_p = PLLXC_SW_MAX_P,
556 .dyn_ramp_reg = PLLX_MISC2,
557 .stepa_shift = 16,
558 .stepb_shift = 24,
559 .pdiv_tohw = pllxc_p,
560};
561
562static struct tegra_clk_pll_freq_table pll_e_freq_table[] = {
563 /* PLLE special case: use cpcon field to store cml divider value */
564 {336000000, 100000000, 100, 21, 16, 11},
565 {312000000, 100000000, 200, 26, 24, 13},
566 {0, 0, 0, 0, 0, 0},
567};
568
569static struct tegra_clk_pll_params pll_e_params = {
570 .input_min = 12000000,
571 .input_max = 1000000000,
572 .cf_min = 12000000,
573 .cf_max = 75000000,
574 .vco_min = 1600000000,
575 .vco_max = 2400000000U,
576 .base_reg = PLLE_BASE,
577 .misc_reg = PLLE_MISC,
578 .aux_reg = PLLE_AUX,
579 .lock_mask = PLLE_MISC_LOCK,
580 .lock_enable_bit_idx = PLLE_MISC_LOCK_ENABLE,
581 .lock_delay = 300,
582};
583
584static struct tegra_clk_pll_params pll_re_vco_params = {
585 .input_min = 12000000,
586 .input_max = 1000000000,
587 .cf_min = 12000000,
588 .cf_max = 19200000, /* s/w policy, h/w capability 38 MHz */
589 .vco_min = 300000000,
590 .vco_max = 600000000,
591 .base_reg = PLLRE_BASE,
592 .misc_reg = PLLRE_MISC,
593 .lock_mask = PLLRE_MISC_LOCK,
594 .lock_enable_bit_idx = PLLRE_MISC_LOCK_ENABLE,
595 .lock_delay = 300,
596 .iddq_reg = PLLRE_MISC,
597 .iddq_bit_idx = PLLRE_IDDQ_BIT,
598};
599
600/* Peripheral clock registers */
601
602static struct tegra_clk_periph_regs periph_l_regs = {
603 .enb_reg = CLK_OUT_ENB_L,
604 .enb_set_reg = CLK_OUT_ENB_SET_L,
605 .enb_clr_reg = CLK_OUT_ENB_CLR_L,
606 .rst_reg = RST_DEVICES_L,
607 .rst_set_reg = RST_DEVICES_SET_L,
608 .rst_clr_reg = RST_DEVICES_CLR_L,
609};
610
611static struct tegra_clk_periph_regs periph_h_regs = {
612 .enb_reg = CLK_OUT_ENB_H,
613 .enb_set_reg = CLK_OUT_ENB_SET_H,
614 .enb_clr_reg = CLK_OUT_ENB_CLR_H,
615 .rst_reg = RST_DEVICES_H,
616 .rst_set_reg = RST_DEVICES_SET_H,
617 .rst_clr_reg = RST_DEVICES_CLR_H,
618};
619
620static struct tegra_clk_periph_regs periph_u_regs = {
621 .enb_reg = CLK_OUT_ENB_U,
622 .enb_set_reg = CLK_OUT_ENB_SET_U,
623 .enb_clr_reg = CLK_OUT_ENB_CLR_U,
624 .rst_reg = RST_DEVICES_U,
625 .rst_set_reg = RST_DEVICES_SET_U,
626 .rst_clr_reg = RST_DEVICES_CLR_U,
627};
628
629static struct tegra_clk_periph_regs periph_v_regs = {
630 .enb_reg = CLK_OUT_ENB_V,
631 .enb_set_reg = CLK_OUT_ENB_SET_V,
632 .enb_clr_reg = CLK_OUT_ENB_CLR_V,
633 .rst_reg = RST_DEVICES_V,
634 .rst_set_reg = RST_DEVICES_SET_V,
635 .rst_clr_reg = RST_DEVICES_CLR_V,
636};
637
638static struct tegra_clk_periph_regs periph_w_regs = {
639 .enb_reg = CLK_OUT_ENB_W,
640 .enb_set_reg = CLK_OUT_ENB_SET_W,
641 .enb_clr_reg = CLK_OUT_ENB_CLR_W,
642 .rst_reg = RST_DEVICES_W,
643 .rst_set_reg = RST_DEVICES_SET_W,
644 .rst_clr_reg = RST_DEVICES_CLR_W,
645};
646
647/* possible OSC frequencies in Hz */
648static unsigned long tegra114_input_freq[] = {
649 [0] = 13000000,
650 [1] = 16800000,
651 [4] = 19200000,
652 [5] = 38400000,
653 [8] = 12000000,
654 [9] = 48000000,
655 [12] = 260000000,
656};
657
658#define MASK(x) (BIT(x) - 1)
659
660#define TEGRA_INIT_DATA_MUX(_name, _con_id, _dev_id, _parents, _offset, \
661 _clk_num, _regs, _gate_flags, _clk_id) \
662 TEGRA_INIT_DATA_TABLE(_name, _con_id, _dev_id, _parents, _offset,\
663 30, MASK(2), 0, 0, 8, 1, 0, _regs, _clk_num, \
664 periph_clk_enb_refcnt, _gate_flags, _clk_id, \
665 _parents##_idx, 0)
666
667#define TEGRA_INIT_DATA_MUX_FLAGS(_name, _con_id, _dev_id, _parents, _offset,\
668 _clk_num, _regs, _gate_flags, _clk_id, flags)\
669 TEGRA_INIT_DATA_TABLE(_name, _con_id, _dev_id, _parents, _offset,\
670 30, MASK(2), 0, 0, 8, 1, 0, _regs, _clk_num, \
671 periph_clk_enb_refcnt, _gate_flags, _clk_id, \
672 _parents##_idx, flags)
673
674#define TEGRA_INIT_DATA_MUX8(_name, _con_id, _dev_id, _parents, _offset, \
675 _clk_num, _regs, _gate_flags, _clk_id) \
676 TEGRA_INIT_DATA_TABLE(_name, _con_id, _dev_id, _parents, _offset,\
677 29, MASK(3), 0, 0, 8, 1, 0, _regs, _clk_num, \
678 periph_clk_enb_refcnt, _gate_flags, _clk_id, \
679 _parents##_idx, 0)
680
681#define TEGRA_INIT_DATA_INT(_name, _con_id, _dev_id, _parents, _offset, \
682 _clk_num, _regs, _gate_flags, _clk_id) \
683 TEGRA_INIT_DATA_TABLE(_name, _con_id, _dev_id, _parents, _offset,\
684 30, MASK(2), 0, 0, 8, 1, TEGRA_DIVIDER_INT, _regs,\
685 _clk_num, periph_clk_enb_refcnt, _gate_flags, \
686 _clk_id, _parents##_idx, 0)
687
688#define TEGRA_INIT_DATA_INT_FLAGS(_name, _con_id, _dev_id, _parents, _offset,\
689 _clk_num, _regs, _gate_flags, _clk_id, flags)\
690 TEGRA_INIT_DATA_TABLE(_name, _con_id, _dev_id, _parents, _offset,\
691 30, MASK(2), 0, 0, 8, 1, TEGRA_DIVIDER_INT, _regs,\
692 _clk_num, periph_clk_enb_refcnt, _gate_flags, \
693 _clk_id, _parents##_idx, flags)
694
695#define TEGRA_INIT_DATA_INT8(_name, _con_id, _dev_id, _parents, _offset,\
696 _clk_num, _regs, _gate_flags, _clk_id) \
697 TEGRA_INIT_DATA_TABLE(_name, _con_id, _dev_id, _parents, _offset,\
698 29, MASK(3), 0, 0, 8, 1, TEGRA_DIVIDER_INT, _regs,\
699 _clk_num, periph_clk_enb_refcnt, _gate_flags, \
700 _clk_id, _parents##_idx, 0)
701
702#define TEGRA_INIT_DATA_UART(_name, _con_id, _dev_id, _parents, _offset,\
703 _clk_num, _regs, _clk_id) \
704 TEGRA_INIT_DATA_TABLE(_name, _con_id, _dev_id, _parents, _offset,\
705 30, MASK(2), 0, 0, 16, 1, TEGRA_DIVIDER_UART, _regs,\
706 _clk_num, periph_clk_enb_refcnt, 0, _clk_id, \
707 _parents##_idx, 0)
708
709#define TEGRA_INIT_DATA_I2C(_name, _con_id, _dev_id, _parents, _offset,\
710 _clk_num, _regs, _clk_id) \
711 TEGRA_INIT_DATA_TABLE(_name, _con_id, _dev_id, _parents, _offset,\
712 30, MASK(2), 0, 0, 16, 0, 0, _regs, _clk_num, \
713 periph_clk_enb_refcnt, 0, _clk_id, _parents##_idx, 0)
714
715#define TEGRA_INIT_DATA_NODIV(_name, _con_id, _dev_id, _parents, _offset, \
716 _mux_shift, _mux_mask, _clk_num, _regs, \
717 _gate_flags, _clk_id) \
718 TEGRA_INIT_DATA_TABLE(_name, _con_id, _dev_id, _parents, _offset,\
719 _mux_shift, _mux_mask, 0, 0, 0, 0, 0, _regs, \
720 _clk_num, periph_clk_enb_refcnt, _gate_flags, \
721 _clk_id, _parents##_idx, 0)
722
723#define TEGRA_INIT_DATA_XUSB(_name, _con_id, _dev_id, _parents, _offset, \
724 _clk_num, _regs, _gate_flags, _clk_id) \
725 TEGRA_INIT_DATA_TABLE(_name, _con_id, _dev_id, _parents, _offset, \
726 29, MASK(3), 0, 0, 8, 1, TEGRA_DIVIDER_INT, _regs, \
727 _clk_num, periph_clk_enb_refcnt, _gate_flags, \
728 _clk_id, _parents##_idx, 0)
729
730#define TEGRA_INIT_DATA_AUDIO(_name, _con_id, _dev_id, _offset, _clk_num,\
731 _regs, _gate_flags, _clk_id) \
732 TEGRA_INIT_DATA_TABLE(_name, _con_id, _dev_id, mux_d_audio_clk, \
733 _offset, 16, 0xE01F, 0, 0, 8, 1, 0, _regs, _clk_num, \
734 periph_clk_enb_refcnt, _gate_flags , _clk_id, \
735 mux_d_audio_clk_idx, 0)
736
737enum tegra114_clk {
738 rtc = 4, timer = 5, uarta = 6, sdmmc2 = 9, i2s1 = 11, i2c1 = 12,
739 ndflash = 13, sdmmc1 = 14, sdmmc4 = 15, pwm = 17, i2s2 = 18, epp = 19,
740 gr_2d = 21, usbd = 22, isp = 23, gr_3d = 24, disp2 = 26, disp1 = 27,
741 host1x = 28, vcp = 29, i2s0 = 30, apbdma = 34, kbc = 36, kfuse = 40,
742 sbc1 = 41, nor = 42, sbc2 = 44, sbc3 = 46, i2c5 = 47, dsia = 48,
743 mipi = 50, hdmi = 51, csi = 52, i2c2 = 54, uartc = 55, mipi_cal = 56,
744 emc, usb2, usb3, vde = 61, bsea = 62, bsev = 63, uartd = 65,
745 i2c3 = 67, sbc4 = 68, sdmmc3 = 69, owr = 71, csite = 73,
746 la = 76, trace = 77, soc_therm = 78, dtv = 79, ndspeed = 80,
747 i2cslow = 81, dsib = 82, tsec = 83, xusb_host = 89, msenc = 91,
748 csus = 92, mselect = 99, tsensor = 100, i2s3 = 101, i2s4 = 102,
749 i2c4 = 103, sbc5 = 104, sbc6 = 105, d_audio, apbif = 107, dam0, dam1,
750 dam2, hda2codec_2x = 111, audio0_2x = 113, audio1_2x, audio2_2x,
751 audio3_2x, audio4_2x, spdif_2x, actmon = 119, extern1 = 120,
752 extern2 = 121, extern3 = 122, hda = 125, se = 127, hda2hdmi = 128,
753 cilab = 144, cilcd = 145, cile = 146, dsialp = 147, dsiblp = 148,
754 dds = 150, dp2 = 152, amx = 153, adx = 154, xusb_ss = 156, uartb = 192,
755 vfir, spdif_in, spdif_out, vi, vi_sensor, fuse, fuse_burn, clk_32k,
756 clk_m, clk_m_div2, clk_m_div4, pll_ref, pll_c, pll_c_out1, pll_c2,
757 pll_c3, pll_m, pll_m_out1, pll_p, pll_p_out1, pll_p_out2, pll_p_out3,
758 pll_p_out4, pll_a, pll_a_out0, pll_d, pll_d_out0, pll_d2, pll_d2_out0,
759 pll_u, pll_u_480M, pll_u_60M, pll_u_48M, pll_u_12M, pll_x, pll_x_out0,
760 pll_re_vco, pll_re_out, pll_e_out0, spdif_in_sync, i2s0_sync,
761 i2s1_sync, i2s2_sync, i2s3_sync, i2s4_sync, vimclk_sync, audio0,
762 audio1, audio2, audio3, audio4, spdif, clk_out_1, clk_out_2, clk_out_3,
763 blink, xusb_host_src = 252, xusb_falcon_src, xusb_fs_src, xusb_ss_src,
764 xusb_dev_src, xusb_dev, xusb_hs_src, sclk, hclk, pclk, cclk_g, cclk_lp,
765
766 /* Mux clocks */
767
768 audio0_mux = 300, audio1_mux, audio2_mux, audio3_mux, audio4_mux,
769 spdif_mux, clk_out_1_mux, clk_out_2_mux, clk_out_3_mux, dsia_mux,
770 dsib_mux, clk_max,
771};
772
773struct utmi_clk_param {
774 /* Oscillator Frequency in KHz */
775 u32 osc_frequency;
776 /* UTMIP PLL Enable Delay Count */
777 u8 enable_delay_count;
778 /* UTMIP PLL Stable count */
779 u8 stable_count;
780 /* UTMIP PLL Active delay count */
781 u8 active_delay_count;
782 /* UTMIP PLL Xtal frequency count */
783 u8 xtal_freq_count;
784};
785
786static const struct utmi_clk_param utmi_parameters[] = {
787 {.osc_frequency = 13000000, .enable_delay_count = 0x02,
788 .stable_count = 0x33, .active_delay_count = 0x05,
789 .xtal_freq_count = 0x7F},
790 {.osc_frequency = 19200000, .enable_delay_count = 0x03,
791 .stable_count = 0x4B, .active_delay_count = 0x06,
792 .xtal_freq_count = 0xBB},
793 {.osc_frequency = 12000000, .enable_delay_count = 0x02,
794 .stable_count = 0x2F, .active_delay_count = 0x04,
795 .xtal_freq_count = 0x76},
796 {.osc_frequency = 26000000, .enable_delay_count = 0x04,
797 .stable_count = 0x66, .active_delay_count = 0x09,
798 .xtal_freq_count = 0xFE},
799 {.osc_frequency = 16800000, .enable_delay_count = 0x03,
800 .stable_count = 0x41, .active_delay_count = 0x0A,
801 .xtal_freq_count = 0xA4},
802};
803
804/* peripheral mux definitions */
805
806#define MUX_I2S_SPDIF(_id) \
807static const char *mux_pllaout0_##_id##_2x_pllp_clkm[] = { "pll_a_out0", \
808 #_id, "pll_p",\
809 "clk_m"};
810MUX_I2S_SPDIF(audio0)
811MUX_I2S_SPDIF(audio1)
812MUX_I2S_SPDIF(audio2)
813MUX_I2S_SPDIF(audio3)
814MUX_I2S_SPDIF(audio4)
815MUX_I2S_SPDIF(audio)
816
817#define mux_pllaout0_audio0_2x_pllp_clkm_idx NULL
818#define mux_pllaout0_audio1_2x_pllp_clkm_idx NULL
819#define mux_pllaout0_audio2_2x_pllp_clkm_idx NULL
820#define mux_pllaout0_audio3_2x_pllp_clkm_idx NULL
821#define mux_pllaout0_audio4_2x_pllp_clkm_idx NULL
822#define mux_pllaout0_audio_2x_pllp_clkm_idx NULL
823
824static const char *mux_pllp_pllc_pllm_clkm[] = {
825 "pll_p", "pll_c", "pll_m", "clk_m"
826};
827#define mux_pllp_pllc_pllm_clkm_idx NULL
828
829static const char *mux_pllp_pllc_pllm[] = { "pll_p", "pll_c", "pll_m" };
830#define mux_pllp_pllc_pllm_idx NULL
831
832static const char *mux_pllp_pllc_clk32_clkm[] = {
833 "pll_p", "pll_c", "clk_32k", "clk_m"
834};
835#define mux_pllp_pllc_clk32_clkm_idx NULL
836
837static const char *mux_plla_pllc_pllp_clkm[] = {
838 "pll_a_out0", "pll_c", "pll_p", "clk_m"
839};
840#define mux_plla_pllc_pllp_clkm_idx mux_pllp_pllc_pllm_clkm_idx
841
842static const char *mux_pllp_pllc2_c_c3_pllm_clkm[] = {
843 "pll_p", "pll_c2", "pll_c", "pll_c3", "pll_m", "clk_m"
844};
845static u32 mux_pllp_pllc2_c_c3_pllm_clkm_idx[] = {
846 [0] = 0, [1] = 1, [2] = 2, [3] = 3, [4] = 4, [5] = 6,
847};
848
849static const char *mux_pllp_clkm[] = {
850 "pll_p", "clk_m"
851};
852static u32 mux_pllp_clkm_idx[] = {
853 [0] = 0, [1] = 3,
854};
855
856static const char *mux_pllm_pllc2_c_c3_pllp_plla[] = {
857 "pll_m", "pll_c2", "pll_c", "pll_c3", "pll_p", "pll_a_out0"
858};
859#define mux_pllm_pllc2_c_c3_pllp_plla_idx mux_pllp_pllc2_c_c3_pllm_clkm_idx
860
861static const char *mux_pllp_pllm_plld_plla_pllc_plld2_clkm[] = {
862 "pll_p", "pll_m", "pll_d_out0", "pll_a_out0", "pll_c",
863 "pll_d2_out0", "clk_m"
864};
865#define mux_pllp_pllm_plld_plla_pllc_plld2_clkm_idx NULL
866
867static const char *mux_pllm_pllc_pllp_plla[] = {
868 "pll_m", "pll_c", "pll_p", "pll_a_out0"
869};
870#define mux_pllm_pllc_pllp_plla_idx mux_pllp_pllc_pllm_clkm_idx
871
872static const char *mux_pllp_pllc_clkm[] = {
873 "pll_p", "pll_c", "pll_m"
874};
875static u32 mux_pllp_pllc_clkm_idx[] = {
876 [0] = 0, [1] = 1, [2] = 3,
877};
878
879static const char *mux_pllp_pllc_clkm_clk32[] = {
880 "pll_p", "pll_c", "clk_m", "clk_32k"
881};
882#define mux_pllp_pllc_clkm_clk32_idx NULL
883
884static const char *mux_plla_clk32_pllp_clkm_plle[] = {
885 "pll_a_out0", "clk_32k", "pll_p", "clk_m", "pll_e_out0"
886};
887#define mux_plla_clk32_pllp_clkm_plle_idx NULL
888
889static const char *mux_clkm_pllp_pllc_pllre[] = {
890 "clk_m", "pll_p", "pll_c", "pll_re_out"
891};
892static u32 mux_clkm_pllp_pllc_pllre_idx[] = {
893 [0] = 0, [1] = 1, [2] = 3, [3] = 5,
894};
895
896static const char *mux_clkm_48M_pllp_480M[] = {
897 "clk_m", "pll_u_48M", "pll_p", "pll_u_480M"
898};
899#define mux_clkm_48M_pllp_480M_idx NULL
900
901static const char *mux_clkm_pllre_clk32_480M_pllc_ref[] = {
902 "clk_m", "pll_re_out", "clk_32k", "pll_u_480M", "pll_c", "pll_ref"
903};
904static u32 mux_clkm_pllre_clk32_480M_pllc_ref_idx[] = {
905 [0] = 0, [1] = 1, [2] = 3, [3] = 3, [4] = 4, [5] = 7,
906};
907
908static const char *mux_plld_out0_plld2_out0[] = {
909 "pll_d_out0", "pll_d2_out0",
910};
911#define mux_plld_out0_plld2_out0_idx NULL
912
913static const char *mux_d_audio_clk[] = {
914 "pll_a_out0", "pll_p", "clk_m", "spdif_in_sync", "i2s0_sync",
915 "i2s1_sync", "i2s2_sync", "i2s3_sync", "i2s4_sync", "vimclk_sync",
916};
917static u32 mux_d_audio_clk_idx[] = {
918 [0] = 0, [1] = 0x8000, [2] = 0xc000, [3] = 0xE000, [4] = 0xE001,
919 [5] = 0xE002, [6] = 0xE003, [7] = 0xE004, [8] = 0xE005, [9] = 0xE007,
920};
921
922static const char *mux_pllmcp_clkm[] = {
923 "pll_m_out0", "pll_c_out0", "pll_p_out0", "clk_m", "pll_m_ud",
924};
925
926static const struct clk_div_table pll_re_div_table[] = {
927 { .val = 0, .div = 1 },
928 { .val = 1, .div = 2 },
929 { .val = 2, .div = 3 },
930 { .val = 3, .div = 4 },
931 { .val = 4, .div = 5 },
932 { .val = 5, .div = 6 },
933 { .val = 0, .div = 0 },
934};
935
936static struct clk *clks[clk_max];
937static struct clk_onecell_data clk_data;
938
939static unsigned long osc_freq;
940static unsigned long pll_ref_freq;
941
942static int __init tegra114_osc_clk_init(void __iomem *clk_base)
943{
944 struct clk *clk;
945 u32 val, pll_ref_div;
946
947 val = readl_relaxed(clk_base + OSC_CTRL);
948
949 osc_freq = tegra114_input_freq[val >> OSC_CTRL_OSC_FREQ_SHIFT];
950 if (!osc_freq) {
951 WARN_ON(1);
952 return -EINVAL;
953 }
954
955 /* clk_m */
956 clk = clk_register_fixed_rate(NULL, "clk_m", NULL, CLK_IS_ROOT,
957 osc_freq);
958 clk_register_clkdev(clk, "clk_m", NULL);
959 clks[clk_m] = clk;
960
961 /* pll_ref */
962 val = (val >> OSC_CTRL_PLL_REF_DIV_SHIFT) & 3;
963 pll_ref_div = 1 << val;
964 clk = clk_register_fixed_factor(NULL, "pll_ref", "clk_m",
965 CLK_SET_RATE_PARENT, 1, pll_ref_div);
966 clk_register_clkdev(clk, "pll_ref", NULL);
967 clks[pll_ref] = clk;
968
969 pll_ref_freq = osc_freq / pll_ref_div;
970
971 return 0;
972}
973
974static void __init tegra114_fixed_clk_init(void __iomem *clk_base)
975{
976 struct clk *clk;
977
978 /* clk_32k */
979 clk = clk_register_fixed_rate(NULL, "clk_32k", NULL, CLK_IS_ROOT,
980 32768);
981 clk_register_clkdev(clk, "clk_32k", NULL);
982 clks[clk_32k] = clk;
983
984 /* clk_m_div2 */
985 clk = clk_register_fixed_factor(NULL, "clk_m_div2", "clk_m",
986 CLK_SET_RATE_PARENT, 1, 2);
987 clk_register_clkdev(clk, "clk_m_div2", NULL);
988 clks[clk_m_div2] = clk;
989
990 /* clk_m_div4 */
991 clk = clk_register_fixed_factor(NULL, "clk_m_div4", "clk_m",
992 CLK_SET_RATE_PARENT, 1, 4);
993 clk_register_clkdev(clk, "clk_m_div4", NULL);
994 clks[clk_m_div4] = clk;
995
996}
997
998static __init void tegra114_utmi_param_configure(void __iomem *clk_base)
999{
1000 u32 reg;
1001 int i;
1002
1003 for (i = 0; i < ARRAY_SIZE(utmi_parameters); i++) {
1004 if (osc_freq == utmi_parameters[i].osc_frequency)
1005 break;
1006 }
1007
1008 if (i >= ARRAY_SIZE(utmi_parameters)) {
1009 pr_err("%s: Unexpected oscillator freq %lu\n", __func__,
1010 osc_freq);
1011 return;
1012 }
1013
1014 reg = readl_relaxed(clk_base + UTMIP_PLL_CFG2);
1015
1016 /* Program UTMIP PLL stable and active counts */
1017 /* [FIXME] arclk_rst.h says WRONG! This should be 1ms -> 0x50 Check! */
1018 reg &= ~UTMIP_PLL_CFG2_STABLE_COUNT(~0);
1019 reg |= UTMIP_PLL_CFG2_STABLE_COUNT(utmi_parameters[i].stable_count);
1020
1021 reg &= ~UTMIP_PLL_CFG2_ACTIVE_DLY_COUNT(~0);
1022
1023 reg |= UTMIP_PLL_CFG2_ACTIVE_DLY_COUNT(utmi_parameters[i].
1024 active_delay_count);
1025
1026 /* Remove power downs from UTMIP PLL control bits */
1027 reg &= ~UTMIP_PLL_CFG2_FORCE_PD_SAMP_A_POWERDOWN;
1028 reg &= ~UTMIP_PLL_CFG2_FORCE_PD_SAMP_B_POWERDOWN;
1029 reg &= ~UTMIP_PLL_CFG2_FORCE_PD_SAMP_C_POWERDOWN;
1030
1031 writel_relaxed(reg, clk_base + UTMIP_PLL_CFG2);
1032
1033 /* Program UTMIP PLL delay and oscillator frequency counts */
1034 reg = readl_relaxed(clk_base + UTMIP_PLL_CFG1);
1035 reg &= ~UTMIP_PLL_CFG1_ENABLE_DLY_COUNT(~0);
1036
1037 reg |= UTMIP_PLL_CFG1_ENABLE_DLY_COUNT(utmi_parameters[i].
1038 enable_delay_count);
1039
1040 reg &= ~UTMIP_PLL_CFG1_XTAL_FREQ_COUNT(~0);
1041 reg |= UTMIP_PLL_CFG1_XTAL_FREQ_COUNT(utmi_parameters[i].
1042 xtal_freq_count);
1043
1044 /* Remove power downs from UTMIP PLL control bits */
1045 reg &= ~UTMIP_PLL_CFG1_FORCE_PLL_ENABLE_POWERDOWN;
1046 reg &= ~UTMIP_PLL_CFG1_FORCE_PLL_ACTIVE_POWERDOWN;
1047 reg &= ~UTMIP_PLL_CFG1_FORCE_PLLU_POWERUP;
1048 reg &= ~UTMIP_PLL_CFG1_FORCE_PLLU_POWERDOWN;
1049 writel_relaxed(reg, clk_base + UTMIP_PLL_CFG1);
1050
1051 /* Setup HW control of UTMIPLL */
1052 reg = readl_relaxed(clk_base + UTMIPLL_HW_PWRDN_CFG0);
1053 reg |= UTMIPLL_HW_PWRDN_CFG0_USE_LOCKDET;
1054 reg &= ~UTMIPLL_HW_PWRDN_CFG0_CLK_ENABLE_SWCTL;
1055 reg |= UTMIPLL_HW_PWRDN_CFG0_SEQ_START_STATE;
1056 writel_relaxed(reg, clk_base + UTMIPLL_HW_PWRDN_CFG0);
1057
1058 reg = readl_relaxed(clk_base + UTMIP_PLL_CFG1);
1059 reg &= ~UTMIP_PLL_CFG1_FORCE_PLL_ENABLE_POWERUP;
1060 reg &= ~UTMIP_PLL_CFG1_FORCE_PLL_ENABLE_POWERDOWN;
1061 writel_relaxed(reg, clk_base + UTMIP_PLL_CFG1);
1062
1063 udelay(1);
1064
1065 /* Setup SW override of UTMIPLL assuming USB2.0
1066 ports are assigned to USB2 */
1067 reg = readl_relaxed(clk_base + UTMIPLL_HW_PWRDN_CFG0);
1068 reg |= UTMIPLL_HW_PWRDN_CFG0_IDDQ_SWCTL;
1069 reg &= ~UTMIPLL_HW_PWRDN_CFG0_IDDQ_OVERRIDE;
1070 writel_relaxed(reg, clk_base + UTMIPLL_HW_PWRDN_CFG0);
1071
1072 udelay(1);
1073
1074 /* Enable HW control UTMIPLL */
1075 reg = readl_relaxed(clk_base + UTMIPLL_HW_PWRDN_CFG0);
1076 reg |= UTMIPLL_HW_PWRDN_CFG0_SEQ_ENABLE;
1077 writel_relaxed(reg, clk_base + UTMIPLL_HW_PWRDN_CFG0);
1078}
1079
1080static void __init _clip_vco_min(struct tegra_clk_pll_params *pll_params)
1081{
1082 pll_params->vco_min =
1083 DIV_ROUND_UP(pll_params->vco_min, pll_ref_freq) * pll_ref_freq;
1084}
1085
1086static int __init _setup_dynamic_ramp(struct tegra_clk_pll_params *pll_params,
1087 void __iomem *clk_base)
1088{
1089 u32 val;
1090 u32 step_a, step_b;
1091
1092 switch (pll_ref_freq) {
1093 case 12000000:
1094 case 13000000:
1095 case 26000000:
1096 step_a = 0x2B;
1097 step_b = 0x0B;
1098 break;
1099 case 16800000:
1100 step_a = 0x1A;
1101 step_b = 0x09;
1102 break;
1103 case 19200000:
1104 step_a = 0x12;
1105 step_b = 0x08;
1106 break;
1107 default:
1108 pr_err("%s: Unexpected reference rate %lu\n",
1109 __func__, pll_ref_freq);
1110 WARN_ON(1);
1111 return -EINVAL;
1112 }
1113
1114 val = step_a << pll_params->stepa_shift;
1115 val |= step_b << pll_params->stepb_shift;
1116 writel_relaxed(val, clk_base + pll_params->dyn_ramp_reg);
1117
1118 return 0;
1119}
1120
1121static void __init _init_iddq(struct tegra_clk_pll_params *pll_params,
1122 void __iomem *clk_base)
1123{
1124 u32 val, val_iddq;
1125
1126 val = readl_relaxed(clk_base + pll_params->base_reg);
1127 val_iddq = readl_relaxed(clk_base + pll_params->iddq_reg);
1128
1129 if (val & BIT(30))
1130 WARN_ON(val_iddq & BIT(pll_params->iddq_bit_idx));
1131 else {
1132 val_iddq |= BIT(pll_params->iddq_bit_idx);
1133 writel_relaxed(val_iddq, clk_base + pll_params->iddq_reg);
1134 }
1135}
1136
1137static void __init tegra114_pll_init(void __iomem *clk_base,
1138 void __iomem *pmc)
1139{
1140 u32 val;
1141 struct clk *clk;
1142
1143 /* PLLC */
1144 _clip_vco_min(&pll_c_params);
1145 if (_setup_dynamic_ramp(&pll_c_params, clk_base) >= 0) {
1146 _init_iddq(&pll_c_params, clk_base);
1147 clk = tegra_clk_register_pllxc("pll_c", "pll_ref", clk_base,
1148 pmc, 0, 0, &pll_c_params, TEGRA_PLL_USE_LOCK,
1149 pll_c_freq_table, NULL);
1150 clk_register_clkdev(clk, "pll_c", NULL);
1151 clks[pll_c] = clk;
1152
1153 /* PLLC_OUT1 */
1154 clk = tegra_clk_register_divider("pll_c_out1_div", "pll_c",
1155 clk_base + PLLC_OUT, 0, TEGRA_DIVIDER_ROUND_UP,
1156 8, 8, 1, NULL);
1157 clk = tegra_clk_register_pll_out("pll_c_out1", "pll_c_out1_div",
1158 clk_base + PLLC_OUT, 1, 0,
1159 CLK_SET_RATE_PARENT, 0, NULL);
1160 clk_register_clkdev(clk, "pll_c_out1", NULL);
1161 clks[pll_c_out1] = clk;
1162 }
1163
1164 /* PLLC2 */
1165 _clip_vco_min(&pll_c2_params);
1166 clk = tegra_clk_register_pllc("pll_c2", "pll_ref", clk_base, pmc, 0, 0,
1167 &pll_c2_params, TEGRA_PLL_USE_LOCK,
1168 pll_cx_freq_table, NULL);
1169 clk_register_clkdev(clk, "pll_c2", NULL);
1170 clks[pll_c2] = clk;
1171
1172 /* PLLC3 */
1173 _clip_vco_min(&pll_c3_params);
1174 clk = tegra_clk_register_pllc("pll_c3", "pll_ref", clk_base, pmc, 0, 0,
1175 &pll_c3_params, TEGRA_PLL_USE_LOCK,
1176 pll_cx_freq_table, NULL);
1177 clk_register_clkdev(clk, "pll_c3", NULL);
1178 clks[pll_c3] = clk;
1179
1180 /* PLLP */
1181 clk = tegra_clk_register_pll("pll_p", "pll_ref", clk_base, pmc, 0,
1182 408000000, &pll_p_params,
1183 TEGRA_PLL_FIXED | TEGRA_PLL_USE_LOCK,
1184 pll_p_freq_table, NULL);
1185 clk_register_clkdev(clk, "pll_p", NULL);
1186 clks[pll_p] = clk;
1187
1188 /* PLLP_OUT1 */
1189 clk = tegra_clk_register_divider("pll_p_out1_div", "pll_p",
1190 clk_base + PLLP_OUTA, 0, TEGRA_DIVIDER_FIXED |
1191 TEGRA_DIVIDER_ROUND_UP, 8, 8, 1, &pll_div_lock);
1192 clk = tegra_clk_register_pll_out("pll_p_out1", "pll_p_out1_div",
1193 clk_base + PLLP_OUTA, 1, 0,
1194 CLK_IGNORE_UNUSED | CLK_SET_RATE_PARENT, 0,
1195 &pll_div_lock);
1196 clk_register_clkdev(clk, "pll_p_out1", NULL);
1197 clks[pll_p_out1] = clk;
1198
1199 /* PLLP_OUT2 */
1200 clk = tegra_clk_register_divider("pll_p_out2_div", "pll_p",
1201 clk_base + PLLP_OUTA, 0, TEGRA_DIVIDER_FIXED |
1202 TEGRA_DIVIDER_ROUND_UP, 24, 8, 1,
1203 &pll_div_lock);
1204 clk = tegra_clk_register_pll_out("pll_p_out2", "pll_p_out2_div",
1205 clk_base + PLLP_OUTA, 17, 16,
1206 CLK_IGNORE_UNUSED | CLK_SET_RATE_PARENT, 0,
1207 &pll_div_lock);
1208 clk_register_clkdev(clk, "pll_p_out2", NULL);
1209 clks[pll_p_out2] = clk;
1210
1211 /* PLLP_OUT3 */
1212 clk = tegra_clk_register_divider("pll_p_out3_div", "pll_p",
1213 clk_base + PLLP_OUTB, 0, TEGRA_DIVIDER_FIXED |
1214 TEGRA_DIVIDER_ROUND_UP, 8, 8, 1, &pll_div_lock);
1215 clk = tegra_clk_register_pll_out("pll_p_out3", "pll_p_out3_div",
1216 clk_base + PLLP_OUTB, 1, 0,
1217 CLK_IGNORE_UNUSED | CLK_SET_RATE_PARENT, 0,
1218 &pll_div_lock);
1219 clk_register_clkdev(clk, "pll_p_out3", NULL);
1220 clks[pll_p_out3] = clk;
1221
1222 /* PLLP_OUT4 */
1223 clk = tegra_clk_register_divider("pll_p_out4_div", "pll_p",
1224 clk_base + PLLP_OUTB, 0, TEGRA_DIVIDER_FIXED |
1225 TEGRA_DIVIDER_ROUND_UP, 24, 8, 1,
1226 &pll_div_lock);
1227 clk = tegra_clk_register_pll_out("pll_p_out4", "pll_p_out4_div",
1228 clk_base + PLLP_OUTB, 17, 16,
1229 CLK_IGNORE_UNUSED | CLK_SET_RATE_PARENT, 0,
1230 &pll_div_lock);
1231 clk_register_clkdev(clk, "pll_p_out4", NULL);
1232 clks[pll_p_out4] = clk;
1233
1234 /* PLLM */
1235 _clip_vco_min(&pll_m_params);
1236 clk = tegra_clk_register_pllm("pll_m", "pll_ref", clk_base, pmc,
1237 CLK_IGNORE_UNUSED | CLK_SET_RATE_GATE, 0,
1238 &pll_m_params, TEGRA_PLL_USE_LOCK,
1239 pll_m_freq_table, NULL);
1240 clk_register_clkdev(clk, "pll_m", NULL);
1241 clks[pll_m] = clk;
1242
1243 /* PLLM_OUT1 */
1244 clk = tegra_clk_register_divider("pll_m_out1_div", "pll_m",
1245 clk_base + PLLM_OUT, 0, TEGRA_DIVIDER_ROUND_UP,
1246 8, 8, 1, NULL);
1247 clk = tegra_clk_register_pll_out("pll_m_out1", "pll_m_out1_div",
1248 clk_base + PLLM_OUT, 1, 0, CLK_IGNORE_UNUSED |
1249 CLK_SET_RATE_PARENT, 0, NULL);
1250 clk_register_clkdev(clk, "pll_m_out1", NULL);
1251 clks[pll_m_out1] = clk;
1252
1253 /* PLLM_UD */
1254 clk = clk_register_fixed_factor(NULL, "pll_m_ud", "pll_m",
1255 CLK_SET_RATE_PARENT, 1, 1);
1256
1257 /* PLLX */
1258 _clip_vco_min(&pll_x_params);
1259 if (_setup_dynamic_ramp(&pll_x_params, clk_base) >= 0) {
1260 _init_iddq(&pll_x_params, clk_base);
1261 clk = tegra_clk_register_pllxc("pll_x", "pll_ref", clk_base,
1262 pmc, CLK_IGNORE_UNUSED, 0, &pll_x_params,
1263 TEGRA_PLL_USE_LOCK, pll_x_freq_table, NULL);
1264 clk_register_clkdev(clk, "pll_x", NULL);
1265 clks[pll_x] = clk;
1266 }
1267
1268 /* PLLX_OUT0 */
1269 clk = clk_register_fixed_factor(NULL, "pll_x_out0", "pll_x",
1270 CLK_SET_RATE_PARENT, 1, 2);
1271 clk_register_clkdev(clk, "pll_x_out0", NULL);
1272 clks[pll_x_out0] = clk;
1273
1274 /* PLLU */
1275 val = readl(clk_base + pll_u_params.base_reg);
1276 val &= ~BIT(24); /* disable PLLU_OVERRIDE */
1277 writel(val, clk_base + pll_u_params.base_reg);
1278
1279 clk = tegra_clk_register_pll("pll_u", "pll_ref", clk_base, pmc, 0,
1280 0, &pll_u_params, TEGRA_PLLU |
1281 TEGRA_PLL_HAS_CPCON | TEGRA_PLL_SET_LFCON |
1282 TEGRA_PLL_USE_LOCK, pll_u_freq_table, &pll_u_lock);
1283 clk_register_clkdev(clk, "pll_u", NULL);
1284 clks[pll_u] = clk;
1285
1286 tegra114_utmi_param_configure(clk_base);
1287
1288 /* PLLU_480M */
1289 clk = clk_register_gate(NULL, "pll_u_480M", "pll_u",
1290 CLK_SET_RATE_PARENT, clk_base + PLLU_BASE,
1291 22, 0, &pll_u_lock);
1292 clk_register_clkdev(clk, "pll_u_480M", NULL);
1293 clks[pll_u_480M] = clk;
1294
1295 /* PLLU_60M */
1296 clk = clk_register_fixed_factor(NULL, "pll_u_60M", "pll_u",
1297 CLK_SET_RATE_PARENT, 1, 8);
1298 clk_register_clkdev(clk, "pll_u_60M", NULL);
1299 clks[pll_u_60M] = clk;
1300
1301 /* PLLU_48M */
1302 clk = clk_register_fixed_factor(NULL, "pll_u_48M", "pll_u",
1303 CLK_SET_RATE_PARENT, 1, 10);
1304 clk_register_clkdev(clk, "pll_u_48M", NULL);
1305 clks[pll_u_48M] = clk;
1306
1307 /* PLLU_12M */
1308 clk = clk_register_fixed_factor(NULL, "pll_u_12M", "pll_u",
1309 CLK_SET_RATE_PARENT, 1, 40);
1310 clk_register_clkdev(clk, "pll_u_12M", NULL);
1311 clks[pll_u_12M] = clk;
1312
1313 /* PLLD */
1314 clk = tegra_clk_register_pll("pll_d", "pll_ref", clk_base, pmc, 0,
1315 0, &pll_d_params,
1316 TEGRA_PLL_HAS_CPCON | TEGRA_PLL_SET_LFCON |
1317 TEGRA_PLL_USE_LOCK, pll_d_freq_table, &pll_d_lock);
1318 clk_register_clkdev(clk, "pll_d", NULL);
1319 clks[pll_d] = clk;
1320
1321 /* PLLD_OUT0 */
1322 clk = clk_register_fixed_factor(NULL, "pll_d_out0", "pll_d",
1323 CLK_SET_RATE_PARENT, 1, 2);
1324 clk_register_clkdev(clk, "pll_d_out0", NULL);
1325 clks[pll_d_out0] = clk;
1326
1327 /* PLLD2 */
1328 clk = tegra_clk_register_pll("pll_d2", "pll_ref", clk_base, pmc, 0,
1329 0, &pll_d2_params,
1330 TEGRA_PLL_HAS_CPCON | TEGRA_PLL_SET_LFCON |
1331 TEGRA_PLL_USE_LOCK, pll_d_freq_table, &pll_d2_lock);
1332 clk_register_clkdev(clk, "pll_d2", NULL);
1333 clks[pll_d2] = clk;
1334
1335 /* PLLD2_OUT0 */
1336 clk = clk_register_fixed_factor(NULL, "pll_d2_out0", "pll_d2",
1337 CLK_SET_RATE_PARENT, 1, 2);
1338 clk_register_clkdev(clk, "pll_d2_out0", NULL);
1339 clks[pll_d2_out0] = clk;
1340
1341 /* PLLA */
1342 clk = tegra_clk_register_pll("pll_a", "pll_p_out1", clk_base, pmc, 0,
1343 0, &pll_a_params, TEGRA_PLL_HAS_CPCON |
1344 TEGRA_PLL_USE_LOCK, pll_a_freq_table, NULL);
1345 clk_register_clkdev(clk, "pll_a", NULL);
1346 clks[pll_a] = clk;
1347
1348 /* PLLA_OUT0 */
1349 clk = tegra_clk_register_divider("pll_a_out0_div", "pll_a",
1350 clk_base + PLLA_OUT, 0, TEGRA_DIVIDER_ROUND_UP,
1351 8, 8, 1, NULL);
1352 clk = tegra_clk_register_pll_out("pll_a_out0", "pll_a_out0_div",
1353 clk_base + PLLA_OUT, 1, 0, CLK_IGNORE_UNUSED |
1354 CLK_SET_RATE_PARENT, 0, NULL);
1355 clk_register_clkdev(clk, "pll_a_out0", NULL);
1356 clks[pll_a_out0] = clk;
1357
1358 /* PLLRE */
1359 _clip_vco_min(&pll_re_vco_params);
1360 clk = tegra_clk_register_pllre("pll_re_vco", "pll_ref", clk_base, pmc,
1361 0, 0, &pll_re_vco_params, TEGRA_PLL_USE_LOCK,
1362 NULL, &pll_re_lock, pll_ref_freq);
1363 clk_register_clkdev(clk, "pll_re_vco", NULL);
1364 clks[pll_re_vco] = clk;
1365
1366 clk = clk_register_divider_table(NULL, "pll_re_out", "pll_re_vco", 0,
1367 clk_base + PLLRE_BASE, 16, 4, 0,
1368 pll_re_div_table, &pll_re_lock);
1369 clk_register_clkdev(clk, "pll_re_out", NULL);
1370 clks[pll_re_out] = clk;
1371
1372 /* PLLE */
1373 clk = tegra_clk_register_plle_tegra114("pll_e_out0", "pll_re_vco",
1374 clk_base, 0, 100000000, &pll_e_params,
1375 pll_e_freq_table, NULL);
1376 clk_register_clkdev(clk, "pll_e_out0", NULL);
1377 clks[pll_e_out0] = clk;
1378}
1379
1380static const char *mux_audio_sync_clk[] = { "spdif_in_sync", "i2s0_sync",
1381 "i2s1_sync", "i2s2_sync", "i2s3_sync", "i2s4_sync", "vimclk_sync",
1382};
1383
1384static const char *clk_out1_parents[] = { "clk_m", "clk_m_div2",
1385 "clk_m_div4", "extern1",
1386};
1387
1388static const char *clk_out2_parents[] = { "clk_m", "clk_m_div2",
1389 "clk_m_div4", "extern2",
1390};
1391
1392static const char *clk_out3_parents[] = { "clk_m", "clk_m_div2",
1393 "clk_m_div4", "extern3",
1394};
1395
1396static void __init tegra114_audio_clk_init(void __iomem *clk_base)
1397{
1398 struct clk *clk;
1399
1400 /* spdif_in_sync */
1401 clk = tegra_clk_register_sync_source("spdif_in_sync", 24000000,
1402 24000000);
1403 clk_register_clkdev(clk, "spdif_in_sync", NULL);
1404 clks[spdif_in_sync] = clk;
1405
1406 /* i2s0_sync */
1407 clk = tegra_clk_register_sync_source("i2s0_sync", 24000000, 24000000);
1408 clk_register_clkdev(clk, "i2s0_sync", NULL);
1409 clks[i2s0_sync] = clk;
1410
1411 /* i2s1_sync */
1412 clk = tegra_clk_register_sync_source("i2s1_sync", 24000000, 24000000);
1413 clk_register_clkdev(clk, "i2s1_sync", NULL);
1414 clks[i2s1_sync] = clk;
1415
1416 /* i2s2_sync */
1417 clk = tegra_clk_register_sync_source("i2s2_sync", 24000000, 24000000);
1418 clk_register_clkdev(clk, "i2s2_sync", NULL);
1419 clks[i2s2_sync] = clk;
1420
1421 /* i2s3_sync */
1422 clk = tegra_clk_register_sync_source("i2s3_sync", 24000000, 24000000);
1423 clk_register_clkdev(clk, "i2s3_sync", NULL);
1424 clks[i2s3_sync] = clk;
1425
1426 /* i2s4_sync */
1427 clk = tegra_clk_register_sync_source("i2s4_sync", 24000000, 24000000);
1428 clk_register_clkdev(clk, "i2s4_sync", NULL);
1429 clks[i2s4_sync] = clk;
1430
1431 /* vimclk_sync */
1432 clk = tegra_clk_register_sync_source("vimclk_sync", 24000000, 24000000);
1433 clk_register_clkdev(clk, "vimclk_sync", NULL);
1434 clks[vimclk_sync] = clk;
1435
1436 /* audio0 */
1437 clk = clk_register_mux(NULL, "audio0_mux", mux_audio_sync_clk,
1438 ARRAY_SIZE(mux_audio_sync_clk), 0,
1439 clk_base + AUDIO_SYNC_CLK_I2S0, 0, 3, 0,
1440 NULL);
1441 clks[audio0_mux] = clk;
1442 clk = clk_register_gate(NULL, "audio0", "audio0_mux", 0,
1443 clk_base + AUDIO_SYNC_CLK_I2S0, 4,
1444 CLK_GATE_SET_TO_DISABLE, NULL);
1445 clk_register_clkdev(clk, "audio0", NULL);
1446 clks[audio0] = clk;
1447
1448 /* audio1 */
1449 clk = clk_register_mux(NULL, "audio1_mux", mux_audio_sync_clk,
1450 ARRAY_SIZE(mux_audio_sync_clk), 0,
1451 clk_base + AUDIO_SYNC_CLK_I2S1, 0, 3, 0,
1452 NULL);
1453 clks[audio1_mux] = clk;
1454 clk = clk_register_gate(NULL, "audio1", "audio1_mux", 0,
1455 clk_base + AUDIO_SYNC_CLK_I2S1, 4,
1456 CLK_GATE_SET_TO_DISABLE, NULL);
1457 clk_register_clkdev(clk, "audio1", NULL);
1458 clks[audio1] = clk;
1459
1460 /* audio2 */
1461 clk = clk_register_mux(NULL, "audio2_mux", mux_audio_sync_clk,
1462 ARRAY_SIZE(mux_audio_sync_clk), 0,
1463 clk_base + AUDIO_SYNC_CLK_I2S2, 0, 3, 0,
1464 NULL);
1465 clks[audio2_mux] = clk;
1466 clk = clk_register_gate(NULL, "audio2", "audio2_mux", 0,
1467 clk_base + AUDIO_SYNC_CLK_I2S2, 4,
1468 CLK_GATE_SET_TO_DISABLE, NULL);
1469 clk_register_clkdev(clk, "audio2", NULL);
1470 clks[audio2] = clk;
1471
1472 /* audio3 */
1473 clk = clk_register_mux(NULL, "audio3_mux", mux_audio_sync_clk,
1474 ARRAY_SIZE(mux_audio_sync_clk), 0,
1475 clk_base + AUDIO_SYNC_CLK_I2S3, 0, 3, 0,
1476 NULL);
1477 clks[audio3_mux] = clk;
1478 clk = clk_register_gate(NULL, "audio3", "audio3_mux", 0,
1479 clk_base + AUDIO_SYNC_CLK_I2S3, 4,
1480 CLK_GATE_SET_TO_DISABLE, NULL);
1481 clk_register_clkdev(clk, "audio3", NULL);
1482 clks[audio3] = clk;
1483
1484 /* audio4 */
1485 clk = clk_register_mux(NULL, "audio4_mux", mux_audio_sync_clk,
1486 ARRAY_SIZE(mux_audio_sync_clk), 0,
1487 clk_base + AUDIO_SYNC_CLK_I2S4, 0, 3, 0,
1488 NULL);
1489 clks[audio4_mux] = clk;
1490 clk = clk_register_gate(NULL, "audio4", "audio4_mux", 0,
1491 clk_base + AUDIO_SYNC_CLK_I2S4, 4,
1492 CLK_GATE_SET_TO_DISABLE, NULL);
1493 clk_register_clkdev(clk, "audio4", NULL);
1494 clks[audio4] = clk;
1495
1496 /* spdif */
1497 clk = clk_register_mux(NULL, "spdif_mux", mux_audio_sync_clk,
1498 ARRAY_SIZE(mux_audio_sync_clk), 0,
1499 clk_base + AUDIO_SYNC_CLK_SPDIF, 0, 3, 0,
1500 NULL);
1501 clks[spdif_mux] = clk;
1502 clk = clk_register_gate(NULL, "spdif", "spdif_mux", 0,
1503 clk_base + AUDIO_SYNC_CLK_SPDIF, 4,
1504 CLK_GATE_SET_TO_DISABLE, NULL);
1505 clk_register_clkdev(clk, "spdif", NULL);
1506 clks[spdif] = clk;
1507
1508 /* audio0_2x */
1509 clk = clk_register_fixed_factor(NULL, "audio0_doubler", "audio0",
1510 CLK_SET_RATE_PARENT, 2, 1);
1511 clk = tegra_clk_register_divider("audio0_div", "audio0_doubler",
1512 clk_base + AUDIO_SYNC_DOUBLER, 0, 0, 24, 1,
1513 0, &clk_doubler_lock);
1514 clk = tegra_clk_register_periph_gate("audio0_2x", "audio0_div",
1515 TEGRA_PERIPH_NO_RESET, clk_base,
1516 CLK_SET_RATE_PARENT, 113, &periph_v_regs,
1517 periph_clk_enb_refcnt);
1518 clk_register_clkdev(clk, "audio0_2x", NULL);
1519 clks[audio0_2x] = clk;
1520
1521 /* audio1_2x */
1522 clk = clk_register_fixed_factor(NULL, "audio1_doubler", "audio1",
1523 CLK_SET_RATE_PARENT, 2, 1);
1524 clk = tegra_clk_register_divider("audio1_div", "audio1_doubler",
1525 clk_base + AUDIO_SYNC_DOUBLER, 0, 0, 25, 1,
1526 0, &clk_doubler_lock);
1527 clk = tegra_clk_register_periph_gate("audio1_2x", "audio1_div",
1528 TEGRA_PERIPH_NO_RESET, clk_base,
1529 CLK_SET_RATE_PARENT, 114, &periph_v_regs,
1530 periph_clk_enb_refcnt);
1531 clk_register_clkdev(clk, "audio1_2x", NULL);
1532 clks[audio1_2x] = clk;
1533
1534 /* audio2_2x */
1535 clk = clk_register_fixed_factor(NULL, "audio2_doubler", "audio2",
1536 CLK_SET_RATE_PARENT, 2, 1);
1537 clk = tegra_clk_register_divider("audio2_div", "audio2_doubler",
1538 clk_base + AUDIO_SYNC_DOUBLER, 0, 0, 26, 1,
1539 0, &clk_doubler_lock);
1540 clk = tegra_clk_register_periph_gate("audio2_2x", "audio2_div",
1541 TEGRA_PERIPH_NO_RESET, clk_base,
1542 CLK_SET_RATE_PARENT, 115, &periph_v_regs,
1543 periph_clk_enb_refcnt);
1544 clk_register_clkdev(clk, "audio2_2x", NULL);
1545 clks[audio2_2x] = clk;
1546
1547 /* audio3_2x */
1548 clk = clk_register_fixed_factor(NULL, "audio3_doubler", "audio3",
1549 CLK_SET_RATE_PARENT, 2, 1);
1550 clk = tegra_clk_register_divider("audio3_div", "audio3_doubler",
1551 clk_base + AUDIO_SYNC_DOUBLER, 0, 0, 27, 1,
1552 0, &clk_doubler_lock);
1553 clk = tegra_clk_register_periph_gate("audio3_2x", "audio3_div",
1554 TEGRA_PERIPH_NO_RESET, clk_base,
1555 CLK_SET_RATE_PARENT, 116, &periph_v_regs,
1556 periph_clk_enb_refcnt);
1557 clk_register_clkdev(clk, "audio3_2x", NULL);
1558 clks[audio3_2x] = clk;
1559
1560 /* audio4_2x */
1561 clk = clk_register_fixed_factor(NULL, "audio4_doubler", "audio4",
1562 CLK_SET_RATE_PARENT, 2, 1);
1563 clk = tegra_clk_register_divider("audio4_div", "audio4_doubler",
1564 clk_base + AUDIO_SYNC_DOUBLER, 0, 0, 28, 1,
1565 0, &clk_doubler_lock);
1566 clk = tegra_clk_register_periph_gate("audio4_2x", "audio4_div",
1567 TEGRA_PERIPH_NO_RESET, clk_base,
1568 CLK_SET_RATE_PARENT, 117, &periph_v_regs,
1569 periph_clk_enb_refcnt);
1570 clk_register_clkdev(clk, "audio4_2x", NULL);
1571 clks[audio4_2x] = clk;
1572
1573 /* spdif_2x */
1574 clk = clk_register_fixed_factor(NULL, "spdif_doubler", "spdif",
1575 CLK_SET_RATE_PARENT, 2, 1);
1576 clk = tegra_clk_register_divider("spdif_div", "spdif_doubler",
1577 clk_base + AUDIO_SYNC_DOUBLER, 0, 0, 29, 1,
1578 0, &clk_doubler_lock);
1579 clk = tegra_clk_register_periph_gate("spdif_2x", "spdif_div",
1580 TEGRA_PERIPH_NO_RESET, clk_base,
1581 CLK_SET_RATE_PARENT, 118,
1582 &periph_v_regs, periph_clk_enb_refcnt);
1583 clk_register_clkdev(clk, "spdif_2x", NULL);
1584 clks[spdif_2x] = clk;
1585}
1586
1587static void __init tegra114_pmc_clk_init(void __iomem *pmc_base)
1588{
1589 struct clk *clk;
1590
1591 /* clk_out_1 */
1592 clk = clk_register_mux(NULL, "clk_out_1_mux", clk_out1_parents,
1593 ARRAY_SIZE(clk_out1_parents), 0,
1594 pmc_base + PMC_CLK_OUT_CNTRL, 6, 3, 0,
1595 &clk_out_lock);
1596 clks[clk_out_1_mux] = clk;
1597 clk = clk_register_gate(NULL, "clk_out_1", "clk_out_1_mux", 0,
1598 pmc_base + PMC_CLK_OUT_CNTRL, 2, 0,
1599 &clk_out_lock);
1600 clk_register_clkdev(clk, "extern1", "clk_out_1");
1601 clks[clk_out_1] = clk;
1602
1603 /* clk_out_2 */
1604 clk = clk_register_mux(NULL, "clk_out_2_mux", clk_out2_parents,
1605 ARRAY_SIZE(clk_out1_parents), 0,
1606 pmc_base + PMC_CLK_OUT_CNTRL, 14, 3, 0,
1607 &clk_out_lock);
1608 clks[clk_out_2_mux] = clk;
1609 clk = clk_register_gate(NULL, "clk_out_2", "clk_out_2_mux", 0,
1610 pmc_base + PMC_CLK_OUT_CNTRL, 10, 0,
1611 &clk_out_lock);
1612 clk_register_clkdev(clk, "extern2", "clk_out_2");
1613 clks[clk_out_2] = clk;
1614
1615 /* clk_out_3 */
1616 clk = clk_register_mux(NULL, "clk_out_3_mux", clk_out3_parents,
1617 ARRAY_SIZE(clk_out1_parents), 0,
1618 pmc_base + PMC_CLK_OUT_CNTRL, 22, 3, 0,
1619 &clk_out_lock);
1620 clks[clk_out_3_mux] = clk;
1621 clk = clk_register_gate(NULL, "clk_out_3", "clk_out_3_mux", 0,
1622 pmc_base + PMC_CLK_OUT_CNTRL, 18, 0,
1623 &clk_out_lock);
1624 clk_register_clkdev(clk, "extern3", "clk_out_3");
1625 clks[clk_out_3] = clk;
1626
1627 /* blink */
1628 clk = clk_register_gate(NULL, "blink_override", "clk_32k", 0,
1629 pmc_base + PMC_DPD_PADS_ORIDE,
1630 PMC_DPD_PADS_ORIDE_BLINK_ENB, 0, NULL);
1631 clk = clk_register_gate(NULL, "blink", "blink_override", 0,
1632 pmc_base + PMC_CTRL,
1633 PMC_CTRL_BLINK_ENB, 0, NULL);
1634 clk_register_clkdev(clk, "blink", NULL);
1635 clks[blink] = clk;
1636
1637}
1638
1639static const char *sclk_parents[] = { "clk_m", "pll_c_out1", "pll_p_out4",
1640 "pll_p_out3", "pll_p_out2", "unused",
1641 "clk_32k", "pll_m_out1" };
1642
1643static const char *cclk_g_parents[] = { "clk_m", "pll_c", "clk_32k", "pll_m",
1644 "pll_p", "pll_p_out4", "unused",
1645 "unused", "pll_x" };
1646
1647static const char *cclk_lp_parents[] = { "clk_m", "pll_c", "clk_32k", "pll_m",
1648 "pll_p", "pll_p_out4", "unused",
1649 "unused", "pll_x", "pll_x_out0" };
1650
1651static void __init tegra114_super_clk_init(void __iomem *clk_base)
1652{
1653 struct clk *clk;
1654
1655 /* CCLKG */
1656 clk = tegra_clk_register_super_mux("cclk_g", cclk_g_parents,
1657 ARRAY_SIZE(cclk_g_parents),
1658 CLK_SET_RATE_PARENT,
1659 clk_base + CCLKG_BURST_POLICY,
1660 0, 4, 0, 0, NULL);
1661 clk_register_clkdev(clk, "cclk_g", NULL);
1662 clks[cclk_g] = clk;
1663
1664 /* CCLKLP */
1665 clk = tegra_clk_register_super_mux("cclk_lp", cclk_lp_parents,
1666 ARRAY_SIZE(cclk_lp_parents),
1667 CLK_SET_RATE_PARENT,
1668 clk_base + CCLKLP_BURST_POLICY,
1669 0, 4, 8, 9, NULL);
1670 clk_register_clkdev(clk, "cclk_lp", NULL);
1671 clks[cclk_lp] = clk;
1672
1673 /* SCLK */
1674 clk = tegra_clk_register_super_mux("sclk", sclk_parents,
1675 ARRAY_SIZE(sclk_parents),
1676 CLK_SET_RATE_PARENT,
1677 clk_base + SCLK_BURST_POLICY,
1678 0, 4, 0, 0, NULL);
1679 clk_register_clkdev(clk, "sclk", NULL);
1680 clks[sclk] = clk;
1681
1682 /* HCLK */
1683 clk = clk_register_divider(NULL, "hclk_div", "sclk", 0,
1684 clk_base + SYSTEM_CLK_RATE, 4, 2, 0,
1685 &sysrate_lock);
1686 clk = clk_register_gate(NULL, "hclk", "hclk_div", CLK_SET_RATE_PARENT |
1687 CLK_IGNORE_UNUSED, clk_base + SYSTEM_CLK_RATE,
1688 7, CLK_GATE_SET_TO_DISABLE, &sysrate_lock);
1689 clk_register_clkdev(clk, "hclk", NULL);
1690 clks[hclk] = clk;
1691
1692 /* PCLK */
1693 clk = clk_register_divider(NULL, "pclk_div", "hclk", 0,
1694 clk_base + SYSTEM_CLK_RATE, 0, 2, 0,
1695 &sysrate_lock);
1696 clk = clk_register_gate(NULL, "pclk", "pclk_div", CLK_SET_RATE_PARENT |
1697 CLK_IGNORE_UNUSED, clk_base + SYSTEM_CLK_RATE,
1698 3, CLK_GATE_SET_TO_DISABLE, &sysrate_lock);
1699 clk_register_clkdev(clk, "pclk", NULL);
1700 clks[pclk] = clk;
1701}
1702
1703static struct tegra_periph_init_data tegra_periph_clk_list[] = {
1704 TEGRA_INIT_DATA_MUX("i2s0", NULL, "tegra30-i2s.0", mux_pllaout0_audio0_2x_pllp_clkm, CLK_SOURCE_I2S0, 30, &periph_l_regs, TEGRA_PERIPH_ON_APB, i2s0),
1705 TEGRA_INIT_DATA_MUX("i2s1", NULL, "tegra30-i2s.1", mux_pllaout0_audio1_2x_pllp_clkm, CLK_SOURCE_I2S1, 11, &periph_l_regs, TEGRA_PERIPH_ON_APB, i2s1),
1706 TEGRA_INIT_DATA_MUX("i2s2", NULL, "tegra30-i2s.2", mux_pllaout0_audio2_2x_pllp_clkm, CLK_SOURCE_I2S2, 18, &periph_l_regs, TEGRA_PERIPH_ON_APB, i2s2),
1707 TEGRA_INIT_DATA_MUX("i2s3", NULL, "tegra30-i2s.3", mux_pllaout0_audio3_2x_pllp_clkm, CLK_SOURCE_I2S3, 101, &periph_v_regs, TEGRA_PERIPH_ON_APB, i2s3),
1708 TEGRA_INIT_DATA_MUX("i2s4", NULL, "tegra30-i2s.4", mux_pllaout0_audio4_2x_pllp_clkm, CLK_SOURCE_I2S4, 102, &periph_v_regs, TEGRA_PERIPH_ON_APB, i2s4),
1709 TEGRA_INIT_DATA_MUX("spdif_out", "spdif_out", "tegra30-spdif", mux_pllaout0_audio_2x_pllp_clkm, CLK_SOURCE_SPDIF_OUT, 10, &periph_l_regs, TEGRA_PERIPH_ON_APB, spdif_out),
1710 TEGRA_INIT_DATA_MUX("spdif_in", "spdif_in", "tegra30-spdif", mux_pllp_pllc_pllm, CLK_SOURCE_SPDIF_IN, 10, &periph_l_regs, TEGRA_PERIPH_ON_APB, spdif_in),
1711 TEGRA_INIT_DATA_MUX("pwm", NULL, "pwm", mux_pllp_pllc_clk32_clkm, CLK_SOURCE_PWM, 17, &periph_l_regs, TEGRA_PERIPH_ON_APB, pwm),
1712 TEGRA_INIT_DATA_MUX("adx", NULL, "adx", mux_plla_pllc_pllp_clkm, CLK_SOURCE_ADX, 154, &periph_w_regs, TEGRA_PERIPH_ON_APB, adx),
1713 TEGRA_INIT_DATA_MUX("amx", NULL, "amx", mux_plla_pllc_pllp_clkm, CLK_SOURCE_AMX, 153, &periph_w_regs, TEGRA_PERIPH_ON_APB, amx),
1714 TEGRA_INIT_DATA_MUX("hda", "hda", "tegra30-hda", mux_pllp_pllc_pllm_clkm, CLK_SOURCE_HDA, 125, &periph_v_regs, TEGRA_PERIPH_ON_APB, hda),
1715 TEGRA_INIT_DATA_MUX("hda2codec_2x", "hda2codec", "tegra30-hda", mux_pllp_pllc_pllm_clkm, CLK_SOURCE_HDA2CODEC_2X, 111, &periph_v_regs, TEGRA_PERIPH_ON_APB, hda2codec_2x),
1716 TEGRA_INIT_DATA_MUX("sbc1", NULL, "tegra11-spi.0", mux_pllp_pllc_pllm_clkm, CLK_SOURCE_SBC1, 41, &periph_h_regs, TEGRA_PERIPH_ON_APB, sbc1),
1717 TEGRA_INIT_DATA_MUX("sbc2", NULL, "tegra11-spi.1", mux_pllp_pllc_pllm_clkm, CLK_SOURCE_SBC2, 44, &periph_h_regs, TEGRA_PERIPH_ON_APB, sbc2),
1718 TEGRA_INIT_DATA_MUX("sbc3", NULL, "tegra11-spi.2", mux_pllp_pllc_pllm_clkm, CLK_SOURCE_SBC3, 46, &periph_h_regs, TEGRA_PERIPH_ON_APB, sbc3),
1719 TEGRA_INIT_DATA_MUX("sbc4", NULL, "tegra11-spi.3", mux_pllp_pllc_pllm_clkm, CLK_SOURCE_SBC4, 68, &periph_u_regs, TEGRA_PERIPH_ON_APB, sbc4),
1720 TEGRA_INIT_DATA_MUX("sbc5", NULL, "tegra11-spi.4", mux_pllp_pllc_pllm_clkm, CLK_SOURCE_SBC5, 104, &periph_v_regs, TEGRA_PERIPH_ON_APB, sbc5),
1721 TEGRA_INIT_DATA_MUX("sbc6", NULL, "tegra11-spi.5", mux_pllp_pllc_pllm_clkm, CLK_SOURCE_SBC6, 105, &periph_v_regs, TEGRA_PERIPH_ON_APB, sbc6),
1722 TEGRA_INIT_DATA_MUX8("ndflash", NULL, "tegra_nand", mux_pllp_pllc2_c_c3_pllm_clkm, CLK_SOURCE_NDFLASH, 13, &periph_u_regs, TEGRA_PERIPH_ON_APB, ndspeed),
1723 TEGRA_INIT_DATA_MUX8("ndspeed", NULL, "tegra_nand_speed", mux_pllp_pllc2_c_c3_pllm_clkm, CLK_SOURCE_NDSPEED, 80, &periph_u_regs, TEGRA_PERIPH_ON_APB, ndspeed),
1724 TEGRA_INIT_DATA_MUX("vfir", NULL, "vfir", mux_pllp_pllc_pllm_clkm, CLK_SOURCE_VFIR, 7, &periph_l_regs, TEGRA_PERIPH_ON_APB, vfir),
1725 TEGRA_INIT_DATA_MUX("sdmmc1", NULL, "sdhci-tegra.0", mux_pllp_pllc_pllm_clkm, CLK_SOURCE_SDMMC1, 14, &periph_l_regs, 0, sdmmc1),
1726 TEGRA_INIT_DATA_MUX("sdmmc2", NULL, "sdhci-tegra.1", mux_pllp_pllc_pllm_clkm, CLK_SOURCE_SDMMC2, 9, &periph_l_regs, 0, sdmmc2),
1727 TEGRA_INIT_DATA_MUX("sdmmc3", NULL, "sdhci-tegra.2", mux_pllp_pllc_pllm_clkm, CLK_SOURCE_SDMMC3, 69, &periph_u_regs, 0, sdmmc3),
1728 TEGRA_INIT_DATA_MUX("sdmmc4", NULL, "sdhci-tegra.3", mux_pllp_pllc_pllm_clkm, CLK_SOURCE_SDMMC4, 15, &periph_l_regs, 0, sdmmc4),
1729 TEGRA_INIT_DATA_INT("vde", NULL, "vde", mux_pllp_pllc2_c_c3_pllm_clkm, CLK_SOURCE_VDE, 61, &periph_h_regs, 0, vde),
1730 TEGRA_INIT_DATA_MUX_FLAGS("csite", NULL, "csite", mux_pllp_pllc_pllm_clkm, CLK_SOURCE_CSITE, 73, &periph_u_regs, TEGRA_PERIPH_ON_APB, csite, CLK_IGNORE_UNUSED),
1731 TEGRA_INIT_DATA_MUX("la", NULL, "la", mux_pllp_pllc_pllm_clkm, CLK_SOURCE_LA, 76, &periph_u_regs, TEGRA_PERIPH_ON_APB, la),
1732 TEGRA_INIT_DATA_MUX("trace", NULL, "trace", mux_pllp_pllc_pllm_clkm, CLK_SOURCE_TRACE, 77, &periph_u_regs, TEGRA_PERIPH_ON_APB, trace),
1733 TEGRA_INIT_DATA_MUX("owr", NULL, "tegra_w1", mux_pllp_pllc_pllm_clkm, CLK_SOURCE_OWR, 71, &periph_u_regs, TEGRA_PERIPH_ON_APB, owr),
1734 TEGRA_INIT_DATA_MUX("nor", NULL, "tegra-nor", mux_pllp_pllc_pllm_clkm, CLK_SOURCE_NOR, 42, &periph_h_regs, 0, nor),
1735 TEGRA_INIT_DATA_MUX("mipi", NULL, "mipi", mux_pllp_pllc_pllm_clkm, CLK_SOURCE_MIPI, 50, &periph_h_regs, TEGRA_PERIPH_ON_APB, mipi),
1736 TEGRA_INIT_DATA_I2C("i2c1", "div-clk", "tegra11-i2c.0", mux_pllp_clkm, CLK_SOURCE_I2C1, 12, &periph_l_regs, i2c1),
1737 TEGRA_INIT_DATA_I2C("i2c2", "div-clk", "tegra11-i2c.1", mux_pllp_clkm, CLK_SOURCE_I2C2, 54, &periph_h_regs, i2c2),
1738 TEGRA_INIT_DATA_I2C("i2c3", "div-clk", "tegra11-i2c.2", mux_pllp_clkm, CLK_SOURCE_I2C3, 67, &periph_u_regs, i2c3),
1739 TEGRA_INIT_DATA_I2C("i2c4", "div-clk", "tegra11-i2c.3", mux_pllp_clkm, CLK_SOURCE_I2C4, 103, &periph_v_regs, i2c4),
1740 TEGRA_INIT_DATA_I2C("i2c5", "div-clk", "tegra11-i2c.4", mux_pllp_clkm, CLK_SOURCE_I2C5, 47, &periph_h_regs, i2c5),
1741 TEGRA_INIT_DATA_UART("uarta", NULL, "tegra_uart.0", mux_pllp_pllc_pllm_clkm, CLK_SOURCE_UARTA, 6, &periph_l_regs, uarta),
1742 TEGRA_INIT_DATA_UART("uartb", NULL, "tegra_uart.1", mux_pllp_pllc_pllm_clkm, CLK_SOURCE_UARTB, 7, &periph_l_regs, uartb),
1743 TEGRA_INIT_DATA_UART("uartc", NULL, "tegra_uart.2", mux_pllp_pllc_pllm_clkm, CLK_SOURCE_UARTC, 55, &periph_h_regs, uartc),
1744 TEGRA_INIT_DATA_UART("uartd", NULL, "tegra_uart.3", mux_pllp_pllc_pllm_clkm, CLK_SOURCE_UARTD, 65, &periph_u_regs, uartd),
1745 TEGRA_INIT_DATA_INT("3d", NULL, "3d", mux_pllm_pllc2_c_c3_pllp_plla, CLK_SOURCE_3D, 24, &periph_l_regs, 0, gr_3d),
1746 TEGRA_INIT_DATA_INT("2d", NULL, "2d", mux_pllm_pllc2_c_c3_pllp_plla, CLK_SOURCE_2D, 21, &periph_l_regs, 0, gr_2d),
1747 TEGRA_INIT_DATA_MUX("vi_sensor", "vi_sensor", "tegra_camera", mux_pllm_pllc2_c_c3_pllp_plla, CLK_SOURCE_VI_SENSOR, 20, &periph_l_regs, TEGRA_PERIPH_NO_RESET, vi_sensor),
1748 TEGRA_INIT_DATA_INT8("vi", "vi", "tegra_camera", mux_pllm_pllc2_c_c3_pllp_plla, CLK_SOURCE_VI, 20, &periph_l_regs, 0, vi),
1749 TEGRA_INIT_DATA_INT8("epp", NULL, "epp", mux_pllm_pllc2_c_c3_pllp_plla, CLK_SOURCE_EPP, 19, &periph_l_regs, 0, epp),
1750 TEGRA_INIT_DATA_INT8("msenc", NULL, "msenc", mux_pllm_pllc2_c_c3_pllp_plla, CLK_SOURCE_MSENC, 91, &periph_h_regs, TEGRA_PERIPH_WAR_1005168, msenc),
1751 TEGRA_INIT_DATA_INT8("tsec", NULL, "tsec", mux_pllp_pllc2_c_c3_pllm_clkm, CLK_SOURCE_TSEC, 83, &periph_u_regs, 0, tsec),
1752 TEGRA_INIT_DATA_INT8("host1x", NULL, "host1x", mux_pllm_pllc2_c_c3_pllp_plla, CLK_SOURCE_HOST1X, 28, &periph_l_regs, 0, host1x),
1753 TEGRA_INIT_DATA_MUX8("hdmi", NULL, "hdmi", mux_pllp_pllm_plld_plla_pllc_plld2_clkm, CLK_SOURCE_HDMI, 51, &periph_h_regs, 0, hdmi),
1754 TEGRA_INIT_DATA_MUX("cilab", "cilab", "tegra_camera", mux_pllp_pllc_clkm, CLK_SOURCE_CILAB, 144, &periph_w_regs, 0, cilab),
1755 TEGRA_INIT_DATA_MUX("cilcd", "cilcd", "tegra_camera", mux_pllp_pllc_clkm, CLK_SOURCE_CILCD, 145, &periph_w_regs, 0, cilcd),
1756 TEGRA_INIT_DATA_MUX("cile", "cile", "tegra_camera", mux_pllp_pllc_clkm, CLK_SOURCE_CILE, 146, &periph_w_regs, 0, cile),
1757 TEGRA_INIT_DATA_MUX("dsialp", "dsialp", "tegradc.0", mux_pllp_pllc_clkm, CLK_SOURCE_DSIALP, 147, &periph_w_regs, 0, dsialp),
1758 TEGRA_INIT_DATA_MUX("dsiblp", "dsiblp", "tegradc.1", mux_pllp_pllc_clkm, CLK_SOURCE_DSIBLP, 148, &periph_w_regs, 0, dsiblp),
1759 TEGRA_INIT_DATA_MUX("tsensor", NULL, "tegra-tsensor", mux_pllp_pllc_clkm_clk32, CLK_SOURCE_TSENSOR, 100, &periph_v_regs, TEGRA_PERIPH_ON_APB, tsensor),
1760 TEGRA_INIT_DATA_MUX("actmon", NULL, "actmon", mux_pllp_pllc_clk32_clkm, CLK_SOURCE_ACTMON, 119, &periph_v_regs, 0, actmon),
1761 TEGRA_INIT_DATA_MUX8("extern1", NULL, "extern1", mux_plla_clk32_pllp_clkm_plle, CLK_SOURCE_EXTERN1, 120, &periph_v_regs, 0, extern1),
1762 TEGRA_INIT_DATA_MUX8("extern2", NULL, "extern2", mux_plla_clk32_pllp_clkm_plle, CLK_SOURCE_EXTERN2, 121, &periph_v_regs, 0, extern2),
1763 TEGRA_INIT_DATA_MUX8("extern3", NULL, "extern3", mux_plla_clk32_pllp_clkm_plle, CLK_SOURCE_EXTERN3, 122, &periph_v_regs, 0, extern3),
1764 TEGRA_INIT_DATA_MUX("i2cslow", NULL, "i2cslow", mux_pllp_pllc_clk32_clkm, CLK_SOURCE_I2CSLOW, 81, &periph_u_regs, TEGRA_PERIPH_ON_APB, i2cslow),
1765 TEGRA_INIT_DATA_INT8("se", NULL, "se", mux_pllp_pllc2_c_c3_pllm_clkm, CLK_SOURCE_SE, 127, &periph_v_regs, TEGRA_PERIPH_ON_APB, se),
1766 TEGRA_INIT_DATA_INT_FLAGS("mselect", NULL, "mselect", mux_pllp_clkm, CLK_SOURCE_MSELECT, 99, &periph_v_regs, 0, mselect, CLK_IGNORE_UNUSED),
1767 TEGRA_INIT_DATA_MUX8("soc_therm", NULL, "soc_therm", mux_pllm_pllc_pllp_plla, CLK_SOURCE_SOC_THERM, 78, &periph_u_regs, TEGRA_PERIPH_ON_APB, soc_therm),
1768 TEGRA_INIT_DATA_XUSB("xusb_host_src", "host_src", "tegra_xhci", mux_clkm_pllp_pllc_pllre, CLK_SOURCE_XUSB_HOST_SRC, 143, &periph_w_regs, TEGRA_PERIPH_ON_APB | TEGRA_PERIPH_NO_RESET, xusb_host_src),
1769 TEGRA_INIT_DATA_XUSB("xusb_falcon_src", "falcon_src", "tegra_xhci", mux_clkm_pllp_pllc_pllre, CLK_SOURCE_XUSB_FALCON_SRC, 143, &periph_w_regs, TEGRA_PERIPH_NO_RESET, xusb_falcon_src),
1770 TEGRA_INIT_DATA_XUSB("xusb_fs_src", "fs_src", "tegra_xhci", mux_clkm_48M_pllp_480M, CLK_SOURCE_XUSB_FS_SRC, 143, &periph_w_regs, TEGRA_PERIPH_NO_RESET, xusb_fs_src),
1771 TEGRA_INIT_DATA_XUSB("xusb_ss_src", "ss_src", "tegra_xhci", mux_clkm_pllre_clk32_480M_pllc_ref, CLK_SOURCE_XUSB_SS_SRC, 143, &periph_w_regs, TEGRA_PERIPH_NO_RESET, xusb_ss_src),
1772 TEGRA_INIT_DATA_XUSB("xusb_dev_src", "dev_src", "tegra_xhci", mux_clkm_pllp_pllc_pllre, CLK_SOURCE_XUSB_DEV_SRC, 95, &periph_u_regs, TEGRA_PERIPH_ON_APB | TEGRA_PERIPH_NO_RESET, xusb_dev_src),
1773 TEGRA_INIT_DATA_AUDIO("d_audio", "d_audio", "tegra30-ahub", CLK_SOURCE_D_AUDIO, 106, &periph_v_regs, TEGRA_PERIPH_ON_APB, d_audio),
1774 TEGRA_INIT_DATA_AUDIO("dam0", NULL, "tegra30-dam.0", CLK_SOURCE_DAM0, 108, &periph_v_regs, TEGRA_PERIPH_ON_APB, dam0),
1775 TEGRA_INIT_DATA_AUDIO("dam1", NULL, "tegra30-dam.1", CLK_SOURCE_DAM1, 109, &periph_v_regs, TEGRA_PERIPH_ON_APB, dam1),
1776 TEGRA_INIT_DATA_AUDIO("dam2", NULL, "tegra30-dam.2", CLK_SOURCE_DAM2, 110, &periph_v_regs, TEGRA_PERIPH_ON_APB, dam2),
1777};
1778
1779static struct tegra_periph_init_data tegra_periph_nodiv_clk_list[] = {
1780 TEGRA_INIT_DATA_NODIV("disp1", NULL, "tegradc.0", mux_pllp_pllm_plld_plla_pllc_plld2_clkm, CLK_SOURCE_DISP1, 29, 7, 27, &periph_l_regs, 0, disp1),
1781 TEGRA_INIT_DATA_NODIV("disp2", NULL, "tegradc.1", mux_pllp_pllm_plld_plla_pllc_plld2_clkm, CLK_SOURCE_DISP2, 29, 7, 26, &periph_l_regs, 0, disp2),
1782};
1783
1784static __init void tegra114_periph_clk_init(void __iomem *clk_base)
1785{
1786 struct tegra_periph_init_data *data;
1787 struct clk *clk;
1788 int i;
1789 u32 val;
1790
1791 /* apbdma */
1792 clk = tegra_clk_register_periph_gate("apbdma", "clk_m", 0, clk_base,
1793 0, 34, &periph_h_regs,
1794 periph_clk_enb_refcnt);
1795 clks[apbdma] = clk;
1796
1797 /* rtc */
1798 clk = tegra_clk_register_periph_gate("rtc", "clk_32k",
1799 TEGRA_PERIPH_ON_APB |
1800 TEGRA_PERIPH_NO_RESET, clk_base,
1801 0, 4, &periph_l_regs,
1802 periph_clk_enb_refcnt);
1803 clk_register_clkdev(clk, NULL, "rtc-tegra");
1804 clks[rtc] = clk;
1805
1806 /* kbc */
1807 clk = tegra_clk_register_periph_gate("kbc", "clk_32k",
1808 TEGRA_PERIPH_ON_APB |
1809 TEGRA_PERIPH_NO_RESET, clk_base,
1810 0, 36, &periph_h_regs,
1811 periph_clk_enb_refcnt);
1812 clks[kbc] = clk;
1813
1814 /* timer */
1815 clk = tegra_clk_register_periph_gate("timer", "clk_m", 0, clk_base,
1816 0, 5, &periph_l_regs,
1817 periph_clk_enb_refcnt);
1818 clk_register_clkdev(clk, NULL, "timer");
1819 clks[timer] = clk;
1820
1821 /* kfuse */
1822 clk = tegra_clk_register_periph_gate("kfuse", "clk_m",
1823 TEGRA_PERIPH_ON_APB, clk_base, 0, 40,
1824 &periph_h_regs, periph_clk_enb_refcnt);
1825 clks[kfuse] = clk;
1826
1827 /* fuse */
1828 clk = tegra_clk_register_periph_gate("fuse", "clk_m",
1829 TEGRA_PERIPH_ON_APB, clk_base, 0, 39,
1830 &periph_h_regs, periph_clk_enb_refcnt);
1831 clks[fuse] = clk;
1832
1833 /* fuse_burn */
1834 clk = tegra_clk_register_periph_gate("fuse_burn", "clk_m",
1835 TEGRA_PERIPH_ON_APB, clk_base, 0, 39,
1836 &periph_h_regs, periph_clk_enb_refcnt);
1837 clks[fuse_burn] = clk;
1838
1839 /* apbif */
1840 clk = tegra_clk_register_periph_gate("apbif", "clk_m",
1841 TEGRA_PERIPH_ON_APB, clk_base, 0, 107,
1842 &periph_v_regs, periph_clk_enb_refcnt);
1843 clks[apbif] = clk;
1844
1845 /* hda2hdmi */
1846 clk = tegra_clk_register_periph_gate("hda2hdmi", "clk_m",
1847 TEGRA_PERIPH_ON_APB, clk_base, 0, 128,
1848 &periph_w_regs, periph_clk_enb_refcnt);
1849 clks[hda2hdmi] = clk;
1850
1851 /* vcp */
1852 clk = tegra_clk_register_periph_gate("vcp", "clk_m", 0, clk_base, 0,
1853 29, &periph_l_regs,
1854 periph_clk_enb_refcnt);
1855 clks[vcp] = clk;
1856
1857 /* bsea */
1858 clk = tegra_clk_register_periph_gate("bsea", "clk_m", 0, clk_base,
1859 0, 62, &periph_h_regs,
1860 periph_clk_enb_refcnt);
1861 clks[bsea] = clk;
1862
1863 /* bsev */
1864 clk = tegra_clk_register_periph_gate("bsev", "clk_m", 0, clk_base,
1865 0, 63, &periph_h_regs,
1866 periph_clk_enb_refcnt);
1867 clks[bsev] = clk;
1868
1869 /* mipi-cal */
1870 clk = tegra_clk_register_periph_gate("mipi-cal", "clk_m", 0, clk_base,
1871 0, 56, &periph_h_regs,
1872 periph_clk_enb_refcnt);
1873 clks[mipi_cal] = clk;
1874
1875 /* usbd */
1876 clk = tegra_clk_register_periph_gate("usbd", "clk_m", 0, clk_base,
1877 0, 22, &periph_l_regs,
1878 periph_clk_enb_refcnt);
1879 clks[usbd] = clk;
1880
1881 /* usb2 */
1882 clk = tegra_clk_register_periph_gate("usb2", "clk_m", 0, clk_base,
1883 0, 58, &periph_h_regs,
1884 periph_clk_enb_refcnt);
1885 clks[usb2] = clk;
1886
1887 /* usb3 */
1888 clk = tegra_clk_register_periph_gate("usb3", "clk_m", 0, clk_base,
1889 0, 59, &periph_h_regs,
1890 periph_clk_enb_refcnt);
1891 clks[usb3] = clk;
1892
1893 /* csi */
1894 clk = tegra_clk_register_periph_gate("csi", "pll_p_out3", 0, clk_base,
1895 0, 52, &periph_h_regs,
1896 periph_clk_enb_refcnt);
1897 clks[csi] = clk;
1898
1899 /* isp */
1900 clk = tegra_clk_register_periph_gate("isp", "clk_m", 0, clk_base, 0,
1901 23, &periph_l_regs,
1902 periph_clk_enb_refcnt);
1903 clks[isp] = clk;
1904
1905 /* csus */
1906 clk = tegra_clk_register_periph_gate("csus", "clk_m",
1907 TEGRA_PERIPH_NO_RESET, clk_base, 0, 92,
1908 &periph_u_regs, periph_clk_enb_refcnt);
1909 clks[csus] = clk;
1910
1911 /* dds */
1912 clk = tegra_clk_register_periph_gate("dds", "clk_m",
1913 TEGRA_PERIPH_ON_APB, clk_base, 0, 150,
1914 &periph_w_regs, periph_clk_enb_refcnt);
1915 clks[dds] = clk;
1916
1917 /* dp2 */
1918 clk = tegra_clk_register_periph_gate("dp2", "clk_m",
1919 TEGRA_PERIPH_ON_APB, clk_base, 0, 152,
1920 &periph_w_regs, periph_clk_enb_refcnt);
1921 clks[dp2] = clk;
1922
1923 /* dtv */
1924 clk = tegra_clk_register_periph_gate("dtv", "clk_m",
1925 TEGRA_PERIPH_ON_APB, clk_base, 0, 79,
1926 &periph_u_regs, periph_clk_enb_refcnt);
1927 clks[dtv] = clk;
1928
1929 /* dsia */
1930 clk = clk_register_mux(NULL, "dsia_mux", mux_plld_out0_plld2_out0,
1931 ARRAY_SIZE(mux_plld_out0_plld2_out0), 0,
1932 clk_base + PLLD_BASE, 25, 1, 0, &pll_d_lock);
1933 clks[dsia_mux] = clk;
1934 clk = tegra_clk_register_periph_gate("dsia", "dsia_mux", 0, clk_base,
1935 0, 48, &periph_h_regs,
1936 periph_clk_enb_refcnt);
1937 clks[dsia] = clk;
1938
1939 /* dsib */
1940 clk = clk_register_mux(NULL, "dsib_mux", mux_plld_out0_plld2_out0,
1941 ARRAY_SIZE(mux_plld_out0_plld2_out0), 0,
1942 clk_base + PLLD2_BASE, 25, 1, 0, &pll_d2_lock);
1943 clks[dsib_mux] = clk;
1944 clk = tegra_clk_register_periph_gate("dsib", "dsib_mux", 0, clk_base,
1945 0, 82, &periph_u_regs,
1946 periph_clk_enb_refcnt);
1947 clks[dsib] = clk;
1948
1949 /* xusb_hs_src */
1950 val = readl(clk_base + CLK_SOURCE_XUSB_SS_SRC);
1951 val |= BIT(25); /* always select PLLU_60M */
1952 writel(val, clk_base + CLK_SOURCE_XUSB_SS_SRC);
1953
1954 clk = clk_register_fixed_factor(NULL, "xusb_hs_src", "pll_u_60M", 0,
1955 1, 1);
1956 clks[xusb_hs_src] = clk;
1957
1958 /* xusb_host */
1959 clk = tegra_clk_register_periph_gate("xusb_host", "xusb_host_src", 0,
1960 clk_base, 0, 89, &periph_u_regs,
1961 periph_clk_enb_refcnt);
1962 clks[xusb_host] = clk;
1963
1964 /* xusb_ss */
1965 clk = tegra_clk_register_periph_gate("xusb_ss", "xusb_ss_src", 0,
1966 clk_base, 0, 156, &periph_w_regs,
1967 periph_clk_enb_refcnt);
1968 clks[xusb_host] = clk;
1969
1970 /* xusb_dev */
1971 clk = tegra_clk_register_periph_gate("xusb_dev", "xusb_dev_src", 0,
1972 clk_base, 0, 95, &periph_u_regs,
1973 periph_clk_enb_refcnt);
1974 clks[xusb_dev] = clk;
1975
1976 /* emc */
1977 clk = clk_register_mux(NULL, "emc_mux", mux_pllmcp_clkm,
1978 ARRAY_SIZE(mux_pllmcp_clkm), 0,
1979 clk_base + CLK_SOURCE_EMC,
1980 29, 3, 0, NULL);
1981 clk = tegra_clk_register_periph_gate("emc", "emc_mux", 0, clk_base,
1982 CLK_IGNORE_UNUSED, 57, &periph_h_regs,
1983 periph_clk_enb_refcnt);
1984 clks[emc] = clk;
1985
1986 for (i = 0; i < ARRAY_SIZE(tegra_periph_clk_list); i++) {
1987 data = &tegra_periph_clk_list[i];
1988 clk = tegra_clk_register_periph(data->name, data->parent_names,
1989 data->num_parents, &data->periph,
1990 clk_base, data->offset, data->flags);
1991 clks[data->clk_id] = clk;
1992 }
1993
1994 for (i = 0; i < ARRAY_SIZE(tegra_periph_nodiv_clk_list); i++) {
1995 data = &tegra_periph_nodiv_clk_list[i];
1996 clk = tegra_clk_register_periph_nodiv(data->name,
1997 data->parent_names, data->num_parents,
1998 &data->periph, clk_base, data->offset);
1999 clks[data->clk_id] = clk;
2000 }
2001}
2002
2003static struct tegra_cpu_car_ops tegra114_cpu_car_ops;
2004
2005static const struct of_device_id pmc_match[] __initconst = {
2006 { .compatible = "nvidia,tegra114-pmc" },
2007 {},
2008};
2009
2010static __initdata struct tegra_clk_init_table init_table[] = {
2011 {uarta, pll_p, 408000000, 0},
2012 {uartb, pll_p, 408000000, 0},
2013 {uartc, pll_p, 408000000, 0},
2014 {uartd, pll_p, 408000000, 0},
2015 {pll_a, clk_max, 564480000, 1},
2016 {pll_a_out0, clk_max, 11289600, 1},
2017 {extern1, pll_a_out0, 0, 1},
2018 {clk_out_1_mux, extern1, 0, 1},
2019 {clk_out_1, clk_max, 0, 1},
2020 {i2s0, pll_a_out0, 11289600, 0},
2021 {i2s1, pll_a_out0, 11289600, 0},
2022 {i2s2, pll_a_out0, 11289600, 0},
2023 {i2s3, pll_a_out0, 11289600, 0},
2024 {i2s4, pll_a_out0, 11289600, 0},
2025 {clk_max, clk_max, 0, 0}, /* This MUST be the last entry. */
2026};
2027
2028static void __init tegra114_clock_apply_init_table(void)
2029{
2030 tegra_init_from_table(init_table, clks, clk_max);
2031}
2032
2033void __init tegra114_clock_init(struct device_node *np)
2034{
2035 struct device_node *node;
2036 int i;
2037
2038 clk_base = of_iomap(np, 0);
2039 if (!clk_base) {
2040 pr_err("ioremap tegra114 CAR failed\n");
2041 return;
2042 }
2043
2044 node = of_find_matching_node(NULL, pmc_match);
2045 if (!node) {
2046 pr_err("Failed to find pmc node\n");
2047 WARN_ON(1);
2048 return;
2049 }
2050
2051 pmc_base = of_iomap(node, 0);
2052 if (!pmc_base) {
2053 pr_err("Can't map pmc registers\n");
2054 WARN_ON(1);
2055 return;
2056 }
2057
2058 if (tegra114_osc_clk_init(clk_base) < 0)
2059 return;
2060
2061 tegra114_fixed_clk_init(clk_base);
2062 tegra114_pll_init(clk_base, pmc_base);
2063 tegra114_periph_clk_init(clk_base);
2064 tegra114_audio_clk_init(clk_base);
2065 tegra114_pmc_clk_init(pmc_base);
2066 tegra114_super_clk_init(clk_base);
2067
2068 for (i = 0; i < ARRAY_SIZE(clks); i++) {
2069 if (IS_ERR(clks[i])) {
2070 pr_err
2071 ("Tegra114 clk %d: register failed with %ld\n",
2072 i, PTR_ERR(clks[i]));
2073 }
2074 if (!clks[i])
2075 clks[i] = ERR_PTR(-EINVAL);
2076 }
2077
2078 clk_data.clks = clks;
2079 clk_data.clk_num = ARRAY_SIZE(clks);
2080 of_clk_add_provider(np, of_clk_src_onecell_get, &clk_data);
2081
2082 tegra_clk_apply_init_table = tegra114_clock_apply_init_table;
2083
2084 tegra_cpu_car_ops = &tegra114_cpu_car_ops;
2085}
diff --git a/drivers/clk/tegra/clk-tegra20.c b/drivers/clk/tegra/clk-tegra20.c
index f873dcefe0de..8292a00c3de9 100644
--- a/drivers/clk/tegra/clk-tegra20.c
+++ b/drivers/clk/tegra/clk-tegra20.c
@@ -86,8 +86,8 @@
86#define PLLE_BASE 0xe8 86#define PLLE_BASE 0xe8
87#define PLLE_MISC 0xec 87#define PLLE_MISC 0xec
88 88
89#define PLL_BASE_LOCK 27 89#define PLL_BASE_LOCK BIT(27)
90#define PLLE_MISC_LOCK 11 90#define PLLE_MISC_LOCK BIT(11)
91 91
92#define PLL_MISC_LOCK_ENABLE 18 92#define PLL_MISC_LOCK_ENABLE 18
93#define PLLDU_MISC_LOCK_ENABLE 22 93#define PLLDU_MISC_LOCK_ENABLE 22
@@ -236,7 +236,7 @@ enum tegra20_clk {
236 dvc, dsi, mipi = 50, hdmi, csi, tvdac, i2c2, uartc, emc = 57, usb2, 236 dvc, dsi, mipi = 50, hdmi, csi, tvdac, i2c2, uartc, emc = 57, usb2,
237 usb3, mpe, vde, bsea, bsev, speedo, uartd, uarte, i2c3, sbc4, sdmmc3, 237 usb3, mpe, vde, bsea, bsev, speedo, uartd, uarte, i2c3, sbc4, sdmmc3,
238 pex, owr, afi, csite, pcie_xclk, avpucq = 75, la, irama = 84, iramb, 238 pex, owr, afi, csite, pcie_xclk, avpucq = 75, la, irama = 84, iramb,
239 iramc, iramd, cram2, audio_2x, clk_d, csus = 92, cdev1, cdev2, 239 iramc, iramd, cram2, audio_2x, clk_d, csus = 92, cdev2, cdev1,
240 uartb = 96, vfir, spdif_in, spdif_out, vi, vi_sensor, tvo, cve, 240 uartb = 96, vfir, spdif_in, spdif_out, vi, vi_sensor, tvo, cve,
241 osc, clk_32k, clk_m, sclk, cclk, hclk, pclk, blink, pll_a, pll_a_out0, 241 osc, clk_32k, clk_m, sclk, cclk, hclk, pclk, blink, pll_a, pll_a_out0,
242 pll_c, pll_c_out1, pll_d, pll_d_out0, pll_e, pll_m, pll_m_out1, 242 pll_c, pll_c_out1, pll_d, pll_d_out0, pll_e, pll_m, pll_m_out1,
@@ -248,125 +248,125 @@ static struct clk *clks[clk_max];
248static struct clk_onecell_data clk_data; 248static struct clk_onecell_data clk_data;
249 249
250static struct tegra_clk_pll_freq_table pll_c_freq_table[] = { 250static struct tegra_clk_pll_freq_table pll_c_freq_table[] = {
251 { 12000000, 600000000, 600, 12, 1, 8 }, 251 { 12000000, 600000000, 600, 12, 0, 8 },
252 { 13000000, 600000000, 600, 13, 1, 8 }, 252 { 13000000, 600000000, 600, 13, 0, 8 },
253 { 19200000, 600000000, 500, 16, 1, 6 }, 253 { 19200000, 600000000, 500, 16, 0, 6 },
254 { 26000000, 600000000, 600, 26, 1, 8 }, 254 { 26000000, 600000000, 600, 26, 0, 8 },
255 { 0, 0, 0, 0, 0, 0 }, 255 { 0, 0, 0, 0, 0, 0 },
256}; 256};
257 257
258static struct tegra_clk_pll_freq_table pll_m_freq_table[] = { 258static struct tegra_clk_pll_freq_table pll_m_freq_table[] = {
259 { 12000000, 666000000, 666, 12, 1, 8}, 259 { 12000000, 666000000, 666, 12, 0, 8},
260 { 13000000, 666000000, 666, 13, 1, 8}, 260 { 13000000, 666000000, 666, 13, 0, 8},
261 { 19200000, 666000000, 555, 16, 1, 8}, 261 { 19200000, 666000000, 555, 16, 0, 8},
262 { 26000000, 666000000, 666, 26, 1, 8}, 262 { 26000000, 666000000, 666, 26, 0, 8},
263 { 12000000, 600000000, 600, 12, 1, 8}, 263 { 12000000, 600000000, 600, 12, 0, 8},
264 { 13000000, 600000000, 600, 13, 1, 8}, 264 { 13000000, 600000000, 600, 13, 0, 8},
265 { 19200000, 600000000, 375, 12, 1, 6}, 265 { 19200000, 600000000, 375, 12, 0, 6},
266 { 26000000, 600000000, 600, 26, 1, 8}, 266 { 26000000, 600000000, 600, 26, 0, 8},
267 { 0, 0, 0, 0, 0, 0 }, 267 { 0, 0, 0, 0, 0, 0 },
268}; 268};
269 269
270static struct tegra_clk_pll_freq_table pll_p_freq_table[] = { 270static struct tegra_clk_pll_freq_table pll_p_freq_table[] = {
271 { 12000000, 216000000, 432, 12, 2, 8}, 271 { 12000000, 216000000, 432, 12, 1, 8},
272 { 13000000, 216000000, 432, 13, 2, 8}, 272 { 13000000, 216000000, 432, 13, 1, 8},
273 { 19200000, 216000000, 90, 4, 2, 1}, 273 { 19200000, 216000000, 90, 4, 1, 1},
274 { 26000000, 216000000, 432, 26, 2, 8}, 274 { 26000000, 216000000, 432, 26, 1, 8},
275 { 12000000, 432000000, 432, 12, 1, 8}, 275 { 12000000, 432000000, 432, 12, 0, 8},
276 { 13000000, 432000000, 432, 13, 1, 8}, 276 { 13000000, 432000000, 432, 13, 0, 8},
277 { 19200000, 432000000, 90, 4, 1, 1}, 277 { 19200000, 432000000, 90, 4, 0, 1},
278 { 26000000, 432000000, 432, 26, 1, 8}, 278 { 26000000, 432000000, 432, 26, 0, 8},
279 { 0, 0, 0, 0, 0, 0 }, 279 { 0, 0, 0, 0, 0, 0 },
280}; 280};
281 281
282static struct tegra_clk_pll_freq_table pll_a_freq_table[] = { 282static struct tegra_clk_pll_freq_table pll_a_freq_table[] = {
283 { 28800000, 56448000, 49, 25, 1, 1}, 283 { 28800000, 56448000, 49, 25, 0, 1},
284 { 28800000, 73728000, 64, 25, 1, 1}, 284 { 28800000, 73728000, 64, 25, 0, 1},
285 { 28800000, 24000000, 5, 6, 1, 1}, 285 { 28800000, 24000000, 5, 6, 0, 1},
286 { 0, 0, 0, 0, 0, 0 }, 286 { 0, 0, 0, 0, 0, 0 },
287}; 287};
288 288
289static struct tegra_clk_pll_freq_table pll_d_freq_table[] = { 289static struct tegra_clk_pll_freq_table pll_d_freq_table[] = {
290 { 12000000, 216000000, 216, 12, 1, 4}, 290 { 12000000, 216000000, 216, 12, 0, 4},
291 { 13000000, 216000000, 216, 13, 1, 4}, 291 { 13000000, 216000000, 216, 13, 0, 4},
292 { 19200000, 216000000, 135, 12, 1, 3}, 292 { 19200000, 216000000, 135, 12, 0, 3},
293 { 26000000, 216000000, 216, 26, 1, 4}, 293 { 26000000, 216000000, 216, 26, 0, 4},
294 294
295 { 12000000, 594000000, 594, 12, 1, 8}, 295 { 12000000, 594000000, 594, 12, 0, 8},
296 { 13000000, 594000000, 594, 13, 1, 8}, 296 { 13000000, 594000000, 594, 13, 0, 8},
297 { 19200000, 594000000, 495, 16, 1, 8}, 297 { 19200000, 594000000, 495, 16, 0, 8},
298 { 26000000, 594000000, 594, 26, 1, 8}, 298 { 26000000, 594000000, 594, 26, 0, 8},
299 299
300 { 12000000, 1000000000, 1000, 12, 1, 12}, 300 { 12000000, 1000000000, 1000, 12, 0, 12},
301 { 13000000, 1000000000, 1000, 13, 1, 12}, 301 { 13000000, 1000000000, 1000, 13, 0, 12},
302 { 19200000, 1000000000, 625, 12, 1, 8}, 302 { 19200000, 1000000000, 625, 12, 0, 8},
303 { 26000000, 1000000000, 1000, 26, 1, 12}, 303 { 26000000, 1000000000, 1000, 26, 0, 12},
304 304
305 { 0, 0, 0, 0, 0, 0 }, 305 { 0, 0, 0, 0, 0, 0 },
306}; 306};
307 307
308static struct tegra_clk_pll_freq_table pll_u_freq_table[] = { 308static struct tegra_clk_pll_freq_table pll_u_freq_table[] = {
309 { 12000000, 480000000, 960, 12, 2, 0}, 309 { 12000000, 480000000, 960, 12, 0, 0},
310 { 13000000, 480000000, 960, 13, 2, 0}, 310 { 13000000, 480000000, 960, 13, 0, 0},
311 { 19200000, 480000000, 200, 4, 2, 0}, 311 { 19200000, 480000000, 200, 4, 0, 0},
312 { 26000000, 480000000, 960, 26, 2, 0}, 312 { 26000000, 480000000, 960, 26, 0, 0},
313 { 0, 0, 0, 0, 0, 0 }, 313 { 0, 0, 0, 0, 0, 0 },
314}; 314};
315 315
316static struct tegra_clk_pll_freq_table pll_x_freq_table[] = { 316static struct tegra_clk_pll_freq_table pll_x_freq_table[] = {
317 /* 1 GHz */ 317 /* 1 GHz */
318 { 12000000, 1000000000, 1000, 12, 1, 12}, 318 { 12000000, 1000000000, 1000, 12, 0, 12},
319 { 13000000, 1000000000, 1000, 13, 1, 12}, 319 { 13000000, 1000000000, 1000, 13, 0, 12},
320 { 19200000, 1000000000, 625, 12, 1, 8}, 320 { 19200000, 1000000000, 625, 12, 0, 8},
321 { 26000000, 1000000000, 1000, 26, 1, 12}, 321 { 26000000, 1000000000, 1000, 26, 0, 12},
322 322
323 /* 912 MHz */ 323 /* 912 MHz */
324 { 12000000, 912000000, 912, 12, 1, 12}, 324 { 12000000, 912000000, 912, 12, 0, 12},
325 { 13000000, 912000000, 912, 13, 1, 12}, 325 { 13000000, 912000000, 912, 13, 0, 12},
326 { 19200000, 912000000, 760, 16, 1, 8}, 326 { 19200000, 912000000, 760, 16, 0, 8},
327 { 26000000, 912000000, 912, 26, 1, 12}, 327 { 26000000, 912000000, 912, 26, 0, 12},
328 328
329 /* 816 MHz */ 329 /* 816 MHz */
330 { 12000000, 816000000, 816, 12, 1, 12}, 330 { 12000000, 816000000, 816, 12, 0, 12},
331 { 13000000, 816000000, 816, 13, 1, 12}, 331 { 13000000, 816000000, 816, 13, 0, 12},
332 { 19200000, 816000000, 680, 16, 1, 8}, 332 { 19200000, 816000000, 680, 16, 0, 8},
333 { 26000000, 816000000, 816, 26, 1, 12}, 333 { 26000000, 816000000, 816, 26, 0, 12},
334 334
335 /* 760 MHz */ 335 /* 760 MHz */
336 { 12000000, 760000000, 760, 12, 1, 12}, 336 { 12000000, 760000000, 760, 12, 0, 12},
337 { 13000000, 760000000, 760, 13, 1, 12}, 337 { 13000000, 760000000, 760, 13, 0, 12},
338 { 19200000, 760000000, 950, 24, 1, 8}, 338 { 19200000, 760000000, 950, 24, 0, 8},
339 { 26000000, 760000000, 760, 26, 1, 12}, 339 { 26000000, 760000000, 760, 26, 0, 12},
340 340
341 /* 750 MHz */ 341 /* 750 MHz */
342 { 12000000, 750000000, 750, 12, 1, 12}, 342 { 12000000, 750000000, 750, 12, 0, 12},
343 { 13000000, 750000000, 750, 13, 1, 12}, 343 { 13000000, 750000000, 750, 13, 0, 12},
344 { 19200000, 750000000, 625, 16, 1, 8}, 344 { 19200000, 750000000, 625, 16, 0, 8},
345 { 26000000, 750000000, 750, 26, 1, 12}, 345 { 26000000, 750000000, 750, 26, 0, 12},
346 346
347 /* 608 MHz */ 347 /* 608 MHz */
348 { 12000000, 608000000, 608, 12, 1, 12}, 348 { 12000000, 608000000, 608, 12, 0, 12},
349 { 13000000, 608000000, 608, 13, 1, 12}, 349 { 13000000, 608000000, 608, 13, 0, 12},
350 { 19200000, 608000000, 380, 12, 1, 8}, 350 { 19200000, 608000000, 380, 12, 0, 8},
351 { 26000000, 608000000, 608, 26, 1, 12}, 351 { 26000000, 608000000, 608, 26, 0, 12},
352 352
353 /* 456 MHz */ 353 /* 456 MHz */
354 { 12000000, 456000000, 456, 12, 1, 12}, 354 { 12000000, 456000000, 456, 12, 0, 12},
355 { 13000000, 456000000, 456, 13, 1, 12}, 355 { 13000000, 456000000, 456, 13, 0, 12},
356 { 19200000, 456000000, 380, 16, 1, 8}, 356 { 19200000, 456000000, 380, 16, 0, 8},
357 { 26000000, 456000000, 456, 26, 1, 12}, 357 { 26000000, 456000000, 456, 26, 0, 12},
358 358
359 /* 312 MHz */ 359 /* 312 MHz */
360 { 12000000, 312000000, 312, 12, 1, 12}, 360 { 12000000, 312000000, 312, 12, 0, 12},
361 { 13000000, 312000000, 312, 13, 1, 12}, 361 { 13000000, 312000000, 312, 13, 0, 12},
362 { 19200000, 312000000, 260, 16, 1, 8}, 362 { 19200000, 312000000, 260, 16, 0, 8},
363 { 26000000, 312000000, 312, 26, 1, 12}, 363 { 26000000, 312000000, 312, 26, 0, 12},
364 364
365 { 0, 0, 0, 0, 0, 0 }, 365 { 0, 0, 0, 0, 0, 0 },
366}; 366};
367 367
368static struct tegra_clk_pll_freq_table pll_e_freq_table[] = { 368static struct tegra_clk_pll_freq_table pll_e_freq_table[] = {
369 { 12000000, 100000000, 200, 24, 1, 0 }, 369 { 12000000, 100000000, 200, 24, 0, 0 },
370 { 0, 0, 0, 0, 0, 0 }, 370 { 0, 0, 0, 0, 0, 0 },
371}; 371};
372 372
@@ -380,7 +380,7 @@ static struct tegra_clk_pll_params pll_c_params = {
380 .vco_max = 1400000000, 380 .vco_max = 1400000000,
381 .base_reg = PLLC_BASE, 381 .base_reg = PLLC_BASE,
382 .misc_reg = PLLC_MISC, 382 .misc_reg = PLLC_MISC,
383 .lock_bit_idx = PLL_BASE_LOCK, 383 .lock_mask = PLL_BASE_LOCK,
384 .lock_enable_bit_idx = PLL_MISC_LOCK_ENABLE, 384 .lock_enable_bit_idx = PLL_MISC_LOCK_ENABLE,
385 .lock_delay = 300, 385 .lock_delay = 300,
386}; 386};
@@ -394,7 +394,7 @@ static struct tegra_clk_pll_params pll_m_params = {
394 .vco_max = 1200000000, 394 .vco_max = 1200000000,
395 .base_reg = PLLM_BASE, 395 .base_reg = PLLM_BASE,
396 .misc_reg = PLLM_MISC, 396 .misc_reg = PLLM_MISC,
397 .lock_bit_idx = PLL_BASE_LOCK, 397 .lock_mask = PLL_BASE_LOCK,
398 .lock_enable_bit_idx = PLL_MISC_LOCK_ENABLE, 398 .lock_enable_bit_idx = PLL_MISC_LOCK_ENABLE,
399 .lock_delay = 300, 399 .lock_delay = 300,
400}; 400};
@@ -408,7 +408,7 @@ static struct tegra_clk_pll_params pll_p_params = {
408 .vco_max = 1400000000, 408 .vco_max = 1400000000,
409 .base_reg = PLLP_BASE, 409 .base_reg = PLLP_BASE,
410 .misc_reg = PLLP_MISC, 410 .misc_reg = PLLP_MISC,
411 .lock_bit_idx = PLL_BASE_LOCK, 411 .lock_mask = PLL_BASE_LOCK,
412 .lock_enable_bit_idx = PLL_MISC_LOCK_ENABLE, 412 .lock_enable_bit_idx = PLL_MISC_LOCK_ENABLE,
413 .lock_delay = 300, 413 .lock_delay = 300,
414}; 414};
@@ -422,7 +422,7 @@ static struct tegra_clk_pll_params pll_a_params = {
422 .vco_max = 1400000000, 422 .vco_max = 1400000000,
423 .base_reg = PLLA_BASE, 423 .base_reg = PLLA_BASE,
424 .misc_reg = PLLA_MISC, 424 .misc_reg = PLLA_MISC,
425 .lock_bit_idx = PLL_BASE_LOCK, 425 .lock_mask = PLL_BASE_LOCK,
426 .lock_enable_bit_idx = PLL_MISC_LOCK_ENABLE, 426 .lock_enable_bit_idx = PLL_MISC_LOCK_ENABLE,
427 .lock_delay = 300, 427 .lock_delay = 300,
428}; 428};
@@ -436,11 +436,17 @@ static struct tegra_clk_pll_params pll_d_params = {
436 .vco_max = 1000000000, 436 .vco_max = 1000000000,
437 .base_reg = PLLD_BASE, 437 .base_reg = PLLD_BASE,
438 .misc_reg = PLLD_MISC, 438 .misc_reg = PLLD_MISC,
439 .lock_bit_idx = PLL_BASE_LOCK, 439 .lock_mask = PLL_BASE_LOCK,
440 .lock_enable_bit_idx = PLLDU_MISC_LOCK_ENABLE, 440 .lock_enable_bit_idx = PLLDU_MISC_LOCK_ENABLE,
441 .lock_delay = 1000, 441 .lock_delay = 1000,
442}; 442};
443 443
444static struct pdiv_map pllu_p[] = {
445 { .pdiv = 1, .hw_val = 1 },
446 { .pdiv = 2, .hw_val = 0 },
447 { .pdiv = 0, .hw_val = 0 },
448};
449
444static struct tegra_clk_pll_params pll_u_params = { 450static struct tegra_clk_pll_params pll_u_params = {
445 .input_min = 2000000, 451 .input_min = 2000000,
446 .input_max = 40000000, 452 .input_max = 40000000,
@@ -450,9 +456,10 @@ static struct tegra_clk_pll_params pll_u_params = {
450 .vco_max = 960000000, 456 .vco_max = 960000000,
451 .base_reg = PLLU_BASE, 457 .base_reg = PLLU_BASE,
452 .misc_reg = PLLU_MISC, 458 .misc_reg = PLLU_MISC,
453 .lock_bit_idx = PLL_BASE_LOCK, 459 .lock_mask = PLL_BASE_LOCK,
454 .lock_enable_bit_idx = PLLDU_MISC_LOCK_ENABLE, 460 .lock_enable_bit_idx = PLLDU_MISC_LOCK_ENABLE,
455 .lock_delay = 1000, 461 .lock_delay = 1000,
462 .pdiv_tohw = pllu_p,
456}; 463};
457 464
458static struct tegra_clk_pll_params pll_x_params = { 465static struct tegra_clk_pll_params pll_x_params = {
@@ -464,7 +471,7 @@ static struct tegra_clk_pll_params pll_x_params = {
464 .vco_max = 1200000000, 471 .vco_max = 1200000000,
465 .base_reg = PLLX_BASE, 472 .base_reg = PLLX_BASE,
466 .misc_reg = PLLX_MISC, 473 .misc_reg = PLLX_MISC,
467 .lock_bit_idx = PLL_BASE_LOCK, 474 .lock_mask = PLL_BASE_LOCK,
468 .lock_enable_bit_idx = PLL_MISC_LOCK_ENABLE, 475 .lock_enable_bit_idx = PLL_MISC_LOCK_ENABLE,
469 .lock_delay = 300, 476 .lock_delay = 300,
470}; 477};
@@ -478,7 +485,7 @@ static struct tegra_clk_pll_params pll_e_params = {
478 .vco_max = 0, 485 .vco_max = 0,
479 .base_reg = PLLE_BASE, 486 .base_reg = PLLE_BASE,
480 .misc_reg = PLLE_MISC, 487 .misc_reg = PLLE_MISC,
481 .lock_bit_idx = PLLE_MISC_LOCK, 488 .lock_mask = PLLE_MISC_LOCK,
482 .lock_enable_bit_idx = PLLE_MISC_LOCK_ENABLE, 489 .lock_enable_bit_idx = PLLE_MISC_LOCK_ENABLE,
483 .lock_delay = 0, 490 .lock_delay = 0,
484}; 491};
@@ -711,8 +718,8 @@ static void tegra20_pll_init(void)
711} 718}
712 719
713static const char *cclk_parents[] = { "clk_m", "pll_c", "clk_32k", "pll_m", 720static const char *cclk_parents[] = { "clk_m", "pll_c", "clk_32k", "pll_m",
714 "pll_p_cclk", "pll_p_out4_cclk", 721 "pll_p", "pll_p_out4",
715 "pll_p_out3_cclk", "clk_d", "pll_x" }; 722 "pll_p_out3", "clk_d", "pll_x" };
716static const char *sclk_parents[] = { "clk_m", "pll_c_out1", "pll_p_out4", 723static const char *sclk_parents[] = { "clk_m", "pll_c_out1", "pll_p_out4",
717 "pll_p_out3", "pll_p_out2", "clk_d", 724 "pll_p_out3", "pll_p_out2", "clk_d",
718 "clk_32k", "pll_m_out1" }; 725 "clk_32k", "pll_m_out1" };
@@ -721,38 +728,6 @@ static void tegra20_super_clk_init(void)
721{ 728{
722 struct clk *clk; 729 struct clk *clk;
723 730
724 /*
725 * DIV_U71 dividers for CCLK, these dividers are used only
726 * if parent clock is fixed rate.
727 */
728
729 /*
730 * Clock input to cclk divided from pll_p using
731 * U71 divider of cclk.
732 */
733 clk = tegra_clk_register_divider("pll_p_cclk", "pll_p",
734 clk_base + SUPER_CCLK_DIVIDER, 0,
735 TEGRA_DIVIDER_INT, 16, 8, 1, NULL);
736 clk_register_clkdev(clk, "pll_p_cclk", NULL);
737
738 /*
739 * Clock input to cclk divided from pll_p_out3 using
740 * U71 divider of cclk.
741 */
742 clk = tegra_clk_register_divider("pll_p_out3_cclk", "pll_p_out3",
743 clk_base + SUPER_CCLK_DIVIDER, 0,
744 TEGRA_DIVIDER_INT, 16, 8, 1, NULL);
745 clk_register_clkdev(clk, "pll_p_out3_cclk", NULL);
746
747 /*
748 * Clock input to cclk divided from pll_p_out4 using
749 * U71 divider of cclk.
750 */
751 clk = tegra_clk_register_divider("pll_p_out4_cclk", "pll_p_out4",
752 clk_base + SUPER_CCLK_DIVIDER, 0,
753 TEGRA_DIVIDER_INT, 16, 8, 1, NULL);
754 clk_register_clkdev(clk, "pll_p_out4_cclk", NULL);
755
756 /* CCLK */ 731 /* CCLK */
757 clk = tegra_clk_register_super_mux("cclk", cclk_parents, 732 clk = tegra_clk_register_super_mux("cclk", cclk_parents,
758 ARRAY_SIZE(cclk_parents), CLK_SET_RATE_PARENT, 733 ARRAY_SIZE(cclk_parents), CLK_SET_RATE_PARENT,
@@ -1044,7 +1019,7 @@ static void __init tegra20_periph_clk_init(void)
1044 data = &tegra_periph_clk_list[i]; 1019 data = &tegra_periph_clk_list[i];
1045 clk = tegra_clk_register_periph(data->name, data->parent_names, 1020 clk = tegra_clk_register_periph(data->name, data->parent_names,
1046 data->num_parents, &data->periph, 1021 data->num_parents, &data->periph,
1047 clk_base, data->offset); 1022 clk_base, data->offset, data->flags);
1048 clk_register_clkdev(clk, data->con_id, data->dev_id); 1023 clk_register_clkdev(clk, data->con_id, data->dev_id);
1049 clks[data->clk_id] = clk; 1024 clks[data->clk_id] = clk;
1050 } 1025 }
@@ -1279,9 +1254,16 @@ static __initdata struct tegra_clk_init_table init_table[] = {
1279 {host1x, pll_c, 150000000, 0}, 1254 {host1x, pll_c, 150000000, 0},
1280 {disp1, pll_p, 600000000, 0}, 1255 {disp1, pll_p, 600000000, 0},
1281 {disp2, pll_p, 600000000, 0}, 1256 {disp2, pll_p, 600000000, 0},
1257 {gr2d, pll_c, 300000000, 0},
1258 {gr3d, pll_c, 300000000, 0},
1282 {clk_max, clk_max, 0, 0}, /* This MUST be the last entry */ 1259 {clk_max, clk_max, 0, 0}, /* This MUST be the last entry */
1283}; 1260};
1284 1261
1262static void __init tegra20_clock_apply_init_table(void)
1263{
1264 tegra_init_from_table(init_table, clks, clk_max);
1265}
1266
1285/* 1267/*
1286 * Some clocks may be used by different drivers depending on the board 1268 * Some clocks may be used by different drivers depending on the board
1287 * configuration. List those here to register them twice in the clock lookup 1269 * configuration. List those here to register them twice in the clock lookup
@@ -1348,7 +1330,7 @@ void __init tegra20_clock_init(struct device_node *np)
1348 clk_data.clk_num = ARRAY_SIZE(clks); 1330 clk_data.clk_num = ARRAY_SIZE(clks);
1349 of_clk_add_provider(np, of_clk_src_onecell_get, &clk_data); 1331 of_clk_add_provider(np, of_clk_src_onecell_get, &clk_data);
1350 1332
1351 tegra_init_from_table(init_table, clks, clk_max); 1333 tegra_clk_apply_init_table = tegra20_clock_apply_init_table;
1352 1334
1353 tegra_cpu_car_ops = &tegra20_cpu_car_ops; 1335 tegra_cpu_car_ops = &tegra20_cpu_car_ops;
1354} 1336}
diff --git a/drivers/clk/tegra/clk-tegra30.c b/drivers/clk/tegra/clk-tegra30.c
index ba6f51bc9f3b..2dc0c5602613 100644
--- a/drivers/clk/tegra/clk-tegra30.c
+++ b/drivers/clk/tegra/clk-tegra30.c
@@ -116,8 +116,8 @@
116#define PLLDU_MISC_LOCK_ENABLE 22 116#define PLLDU_MISC_LOCK_ENABLE 22
117#define PLLE_MISC_LOCK_ENABLE 9 117#define PLLE_MISC_LOCK_ENABLE 9
118 118
119#define PLL_BASE_LOCK 27 119#define PLL_BASE_LOCK BIT(27)
120#define PLLE_MISC_LOCK 11 120#define PLLE_MISC_LOCK BIT(11)
121 121
122#define PLLE_AUX 0x48c 122#define PLLE_AUX 0x48c
123#define PLLC_OUT 0x84 123#define PLLC_OUT 0x84
@@ -330,7 +330,7 @@ enum tegra30_clk {
330 usb3, mpe, vde, bsea, bsev, speedo, uartd, uarte, i2c3, sbc4, sdmmc3, 330 usb3, mpe, vde, bsea, bsev, speedo, uartd, uarte, i2c3, sbc4, sdmmc3,
331 pcie, owr, afi, csite, pciex, avpucq, la, dtv = 79, ndspeed, i2cslow, 331 pcie, owr, afi, csite, pciex, avpucq, la, dtv = 79, ndspeed, i2cslow,
332 dsib, irama = 84, iramb, iramc, iramd, cram2, audio_2x = 90, csus = 92, 332 dsib, irama = 84, iramb, iramc, iramd, cram2, audio_2x = 90, csus = 92,
333 cdev1, cdev2, cpu_g = 96, cpu_lp, gr3d2, mselect, tsensor, i2s3, i2s4, 333 cdev2, cdev1, cpu_g = 96, cpu_lp, gr3d2, mselect, tsensor, i2s3, i2s4,
334 i2c4, sbc5, sbc6, d_audio, apbif, dam0, dam1, dam2, hda2codec_2x, 334 i2c4, sbc5, sbc6, d_audio, apbif, dam0, dam1, dam2, hda2codec_2x,
335 atomics, audio0_2x, audio1_2x, audio2_2x, audio3_2x, audio4_2x, 335 atomics, audio0_2x, audio1_2x, audio2_2x, audio3_2x, audio4_2x,
336 spdif_2x, actmon, extern1, extern2, extern3, sata_oob, sata, hda, 336 spdif_2x, actmon, extern1, extern2, extern3, sata_oob, sata, hda,
@@ -374,164 +374,170 @@ static const struct utmi_clk_param utmi_parameters[] = {
374}; 374};
375 375
376static struct tegra_clk_pll_freq_table pll_c_freq_table[] = { 376static struct tegra_clk_pll_freq_table pll_c_freq_table[] = {
377 { 12000000, 1040000000, 520, 6, 1, 8}, 377 { 12000000, 1040000000, 520, 6, 0, 8},
378 { 13000000, 1040000000, 480, 6, 1, 8}, 378 { 13000000, 1040000000, 480, 6, 0, 8},
379 { 16800000, 1040000000, 495, 8, 1, 8}, /* actual: 1039.5 MHz */ 379 { 16800000, 1040000000, 495, 8, 0, 8}, /* actual: 1039.5 MHz */
380 { 19200000, 1040000000, 325, 6, 1, 6}, 380 { 19200000, 1040000000, 325, 6, 0, 6},
381 { 26000000, 1040000000, 520, 13, 1, 8}, 381 { 26000000, 1040000000, 520, 13, 0, 8},
382 382
383 { 12000000, 832000000, 416, 6, 1, 8}, 383 { 12000000, 832000000, 416, 6, 0, 8},
384 { 13000000, 832000000, 832, 13, 1, 8}, 384 { 13000000, 832000000, 832, 13, 0, 8},
385 { 16800000, 832000000, 396, 8, 1, 8}, /* actual: 831.6 MHz */ 385 { 16800000, 832000000, 396, 8, 0, 8}, /* actual: 831.6 MHz */
386 { 19200000, 832000000, 260, 6, 1, 8}, 386 { 19200000, 832000000, 260, 6, 0, 8},
387 { 26000000, 832000000, 416, 13, 1, 8}, 387 { 26000000, 832000000, 416, 13, 0, 8},
388 388
389 { 12000000, 624000000, 624, 12, 1, 8}, 389 { 12000000, 624000000, 624, 12, 0, 8},
390 { 13000000, 624000000, 624, 13, 1, 8}, 390 { 13000000, 624000000, 624, 13, 0, 8},
391 { 16800000, 600000000, 520, 14, 1, 8}, 391 { 16800000, 600000000, 520, 14, 0, 8},
392 { 19200000, 624000000, 520, 16, 1, 8}, 392 { 19200000, 624000000, 520, 16, 0, 8},
393 { 26000000, 624000000, 624, 26, 1, 8}, 393 { 26000000, 624000000, 624, 26, 0, 8},
394 394
395 { 12000000, 600000000, 600, 12, 1, 8}, 395 { 12000000, 600000000, 600, 12, 0, 8},
396 { 13000000, 600000000, 600, 13, 1, 8}, 396 { 13000000, 600000000, 600, 13, 0, 8},
397 { 16800000, 600000000, 500, 14, 1, 8}, 397 { 16800000, 600000000, 500, 14, 0, 8},
398 { 19200000, 600000000, 375, 12, 1, 6}, 398 { 19200000, 600000000, 375, 12, 0, 6},
399 { 26000000, 600000000, 600, 26, 1, 8}, 399 { 26000000, 600000000, 600, 26, 0, 8},
400 400
401 { 12000000, 520000000, 520, 12, 1, 8}, 401 { 12000000, 520000000, 520, 12, 0, 8},
402 { 13000000, 520000000, 520, 13, 1, 8}, 402 { 13000000, 520000000, 520, 13, 0, 8},
403 { 16800000, 520000000, 495, 16, 1, 8}, /* actual: 519.75 MHz */ 403 { 16800000, 520000000, 495, 16, 0, 8}, /* actual: 519.75 MHz */
404 { 19200000, 520000000, 325, 12, 1, 6}, 404 { 19200000, 520000000, 325, 12, 0, 6},
405 { 26000000, 520000000, 520, 26, 1, 8}, 405 { 26000000, 520000000, 520, 26, 0, 8},
406 406
407 { 12000000, 416000000, 416, 12, 1, 8}, 407 { 12000000, 416000000, 416, 12, 0, 8},
408 { 13000000, 416000000, 416, 13, 1, 8}, 408 { 13000000, 416000000, 416, 13, 0, 8},
409 { 16800000, 416000000, 396, 16, 1, 8}, /* actual: 415.8 MHz */ 409 { 16800000, 416000000, 396, 16, 0, 8}, /* actual: 415.8 MHz */
410 { 19200000, 416000000, 260, 12, 1, 6}, 410 { 19200000, 416000000, 260, 12, 0, 6},
411 { 26000000, 416000000, 416, 26, 1, 8}, 411 { 26000000, 416000000, 416, 26, 0, 8},
412 { 0, 0, 0, 0, 0, 0 }, 412 { 0, 0, 0, 0, 0, 0 },
413}; 413};
414 414
415static struct tegra_clk_pll_freq_table pll_m_freq_table[] = { 415static struct tegra_clk_pll_freq_table pll_m_freq_table[] = {
416 { 12000000, 666000000, 666, 12, 1, 8}, 416 { 12000000, 666000000, 666, 12, 0, 8},
417 { 13000000, 666000000, 666, 13, 1, 8}, 417 { 13000000, 666000000, 666, 13, 0, 8},
418 { 16800000, 666000000, 555, 14, 1, 8}, 418 { 16800000, 666000000, 555, 14, 0, 8},
419 { 19200000, 666000000, 555, 16, 1, 8}, 419 { 19200000, 666000000, 555, 16, 0, 8},
420 { 26000000, 666000000, 666, 26, 1, 8}, 420 { 26000000, 666000000, 666, 26, 0, 8},
421 { 12000000, 600000000, 600, 12, 1, 8}, 421 { 12000000, 600000000, 600, 12, 0, 8},
422 { 13000000, 600000000, 600, 13, 1, 8}, 422 { 13000000, 600000000, 600, 13, 0, 8},
423 { 16800000, 600000000, 500, 14, 1, 8}, 423 { 16800000, 600000000, 500, 14, 0, 8},
424 { 19200000, 600000000, 375, 12, 1, 6}, 424 { 19200000, 600000000, 375, 12, 0, 6},
425 { 26000000, 600000000, 600, 26, 1, 8}, 425 { 26000000, 600000000, 600, 26, 0, 8},
426 { 0, 0, 0, 0, 0, 0 }, 426 { 0, 0, 0, 0, 0, 0 },
427}; 427};
428 428
429static struct tegra_clk_pll_freq_table pll_p_freq_table[] = { 429static struct tegra_clk_pll_freq_table pll_p_freq_table[] = {
430 { 12000000, 216000000, 432, 12, 2, 8}, 430 { 12000000, 216000000, 432, 12, 1, 8},
431 { 13000000, 216000000, 432, 13, 2, 8}, 431 { 13000000, 216000000, 432, 13, 1, 8},
432 { 16800000, 216000000, 360, 14, 2, 8}, 432 { 16800000, 216000000, 360, 14, 1, 8},
433 { 19200000, 216000000, 360, 16, 2, 8}, 433 { 19200000, 216000000, 360, 16, 1, 8},
434 { 26000000, 216000000, 432, 26, 2, 8}, 434 { 26000000, 216000000, 432, 26, 1, 8},
435 { 0, 0, 0, 0, 0, 0 }, 435 { 0, 0, 0, 0, 0, 0 },
436}; 436};
437 437
438static struct tegra_clk_pll_freq_table pll_a_freq_table[] = { 438static struct tegra_clk_pll_freq_table pll_a_freq_table[] = {
439 { 9600000, 564480000, 294, 5, 1, 4}, 439 { 9600000, 564480000, 294, 5, 0, 4},
440 { 9600000, 552960000, 288, 5, 1, 4}, 440 { 9600000, 552960000, 288, 5, 0, 4},
441 { 9600000, 24000000, 5, 2, 1, 1}, 441 { 9600000, 24000000, 5, 2, 0, 1},
442 442
443 { 28800000, 56448000, 49, 25, 1, 1}, 443 { 28800000, 56448000, 49, 25, 0, 1},
444 { 28800000, 73728000, 64, 25, 1, 1}, 444 { 28800000, 73728000, 64, 25, 0, 1},
445 { 28800000, 24000000, 5, 6, 1, 1}, 445 { 28800000, 24000000, 5, 6, 0, 1},
446 { 0, 0, 0, 0, 0, 0 }, 446 { 0, 0, 0, 0, 0, 0 },
447}; 447};
448 448
449static struct tegra_clk_pll_freq_table pll_d_freq_table[] = { 449static struct tegra_clk_pll_freq_table pll_d_freq_table[] = {
450 { 12000000, 216000000, 216, 12, 1, 4}, 450 { 12000000, 216000000, 216, 12, 0, 4},
451 { 13000000, 216000000, 216, 13, 1, 4}, 451 { 13000000, 216000000, 216, 13, 0, 4},
452 { 16800000, 216000000, 180, 14, 1, 4}, 452 { 16800000, 216000000, 180, 14, 0, 4},
453 { 19200000, 216000000, 180, 16, 1, 4}, 453 { 19200000, 216000000, 180, 16, 0, 4},
454 { 26000000, 216000000, 216, 26, 1, 4}, 454 { 26000000, 216000000, 216, 26, 0, 4},
455 455
456 { 12000000, 594000000, 594, 12, 1, 8}, 456 { 12000000, 594000000, 594, 12, 0, 8},
457 { 13000000, 594000000, 594, 13, 1, 8}, 457 { 13000000, 594000000, 594, 13, 0, 8},
458 { 16800000, 594000000, 495, 14, 1, 8}, 458 { 16800000, 594000000, 495, 14, 0, 8},
459 { 19200000, 594000000, 495, 16, 1, 8}, 459 { 19200000, 594000000, 495, 16, 0, 8},
460 { 26000000, 594000000, 594, 26, 1, 8}, 460 { 26000000, 594000000, 594, 26, 0, 8},
461 461
462 { 12000000, 1000000000, 1000, 12, 1, 12}, 462 { 12000000, 1000000000, 1000, 12, 0, 12},
463 { 13000000, 1000000000, 1000, 13, 1, 12}, 463 { 13000000, 1000000000, 1000, 13, 0, 12},
464 { 19200000, 1000000000, 625, 12, 1, 8}, 464 { 19200000, 1000000000, 625, 12, 0, 8},
465 { 26000000, 1000000000, 1000, 26, 1, 12}, 465 { 26000000, 1000000000, 1000, 26, 0, 12},
466 466
467 { 0, 0, 0, 0, 0, 0 }, 467 { 0, 0, 0, 0, 0, 0 },
468}; 468};
469 469
470static struct pdiv_map pllu_p[] = {
471 { .pdiv = 1, .hw_val = 1 },
472 { .pdiv = 2, .hw_val = 0 },
473 { .pdiv = 0, .hw_val = 0 },
474};
475
470static struct tegra_clk_pll_freq_table pll_u_freq_table[] = { 476static struct tegra_clk_pll_freq_table pll_u_freq_table[] = {
471 { 12000000, 480000000, 960, 12, 2, 12}, 477 { 12000000, 480000000, 960, 12, 0, 12},
472 { 13000000, 480000000, 960, 13, 2, 12}, 478 { 13000000, 480000000, 960, 13, 0, 12},
473 { 16800000, 480000000, 400, 7, 2, 5}, 479 { 16800000, 480000000, 400, 7, 0, 5},
474 { 19200000, 480000000, 200, 4, 2, 3}, 480 { 19200000, 480000000, 200, 4, 0, 3},
475 { 26000000, 480000000, 960, 26, 2, 12}, 481 { 26000000, 480000000, 960, 26, 0, 12},
476 { 0, 0, 0, 0, 0, 0 }, 482 { 0, 0, 0, 0, 0, 0 },
477}; 483};
478 484
479static struct tegra_clk_pll_freq_table pll_x_freq_table[] = { 485static struct tegra_clk_pll_freq_table pll_x_freq_table[] = {
480 /* 1.7 GHz */ 486 /* 1.7 GHz */
481 { 12000000, 1700000000, 850, 6, 1, 8}, 487 { 12000000, 1700000000, 850, 6, 0, 8},
482 { 13000000, 1700000000, 915, 7, 1, 8}, /* actual: 1699.2 MHz */ 488 { 13000000, 1700000000, 915, 7, 0, 8}, /* actual: 1699.2 MHz */
483 { 16800000, 1700000000, 708, 7, 1, 8}, /* actual: 1699.2 MHz */ 489 { 16800000, 1700000000, 708, 7, 0, 8}, /* actual: 1699.2 MHz */
484 { 19200000, 1700000000, 885, 10, 1, 8}, /* actual: 1699.2 MHz */ 490 { 19200000, 1700000000, 885, 10, 0, 8}, /* actual: 1699.2 MHz */
485 { 26000000, 1700000000, 850, 13, 1, 8}, 491 { 26000000, 1700000000, 850, 13, 0, 8},
486 492
487 /* 1.6 GHz */ 493 /* 1.6 GHz */
488 { 12000000, 1600000000, 800, 6, 1, 8}, 494 { 12000000, 1600000000, 800, 6, 0, 8},
489 { 13000000, 1600000000, 738, 6, 1, 8}, /* actual: 1599.0 MHz */ 495 { 13000000, 1600000000, 738, 6, 0, 8}, /* actual: 1599.0 MHz */
490 { 16800000, 1600000000, 857, 9, 1, 8}, /* actual: 1599.7 MHz */ 496 { 16800000, 1600000000, 857, 9, 0, 8}, /* actual: 1599.7 MHz */
491 { 19200000, 1600000000, 500, 6, 1, 8}, 497 { 19200000, 1600000000, 500, 6, 0, 8},
492 { 26000000, 1600000000, 800, 13, 1, 8}, 498 { 26000000, 1600000000, 800, 13, 0, 8},
493 499
494 /* 1.5 GHz */ 500 /* 1.5 GHz */
495 { 12000000, 1500000000, 750, 6, 1, 8}, 501 { 12000000, 1500000000, 750, 6, 0, 8},
496 { 13000000, 1500000000, 923, 8, 1, 8}, /* actual: 1499.8 MHz */ 502 { 13000000, 1500000000, 923, 8, 0, 8}, /* actual: 1499.8 MHz */
497 { 16800000, 1500000000, 625, 7, 1, 8}, 503 { 16800000, 1500000000, 625, 7, 0, 8},
498 { 19200000, 1500000000, 625, 8, 1, 8}, 504 { 19200000, 1500000000, 625, 8, 0, 8},
499 { 26000000, 1500000000, 750, 13, 1, 8}, 505 { 26000000, 1500000000, 750, 13, 0, 8},
500 506
501 /* 1.4 GHz */ 507 /* 1.4 GHz */
502 { 12000000, 1400000000, 700, 6, 1, 8}, 508 { 12000000, 1400000000, 700, 6, 0, 8},
503 { 13000000, 1400000000, 969, 9, 1, 8}, /* actual: 1399.7 MHz */ 509 { 13000000, 1400000000, 969, 9, 0, 8}, /* actual: 1399.7 MHz */
504 { 16800000, 1400000000, 1000, 12, 1, 8}, 510 { 16800000, 1400000000, 1000, 12, 0, 8},
505 { 19200000, 1400000000, 875, 12, 1, 8}, 511 { 19200000, 1400000000, 875, 12, 0, 8},
506 { 26000000, 1400000000, 700, 13, 1, 8}, 512 { 26000000, 1400000000, 700, 13, 0, 8},
507 513
508 /* 1.3 GHz */ 514 /* 1.3 GHz */
509 { 12000000, 1300000000, 975, 9, 1, 8}, 515 { 12000000, 1300000000, 975, 9, 0, 8},
510 { 13000000, 1300000000, 1000, 10, 1, 8}, 516 { 13000000, 1300000000, 1000, 10, 0, 8},
511 { 16800000, 1300000000, 928, 12, 1, 8}, /* actual: 1299.2 MHz */ 517 { 16800000, 1300000000, 928, 12, 0, 8}, /* actual: 1299.2 MHz */
512 { 19200000, 1300000000, 812, 12, 1, 8}, /* actual: 1299.2 MHz */ 518 { 19200000, 1300000000, 812, 12, 0, 8}, /* actual: 1299.2 MHz */
513 { 26000000, 1300000000, 650, 13, 1, 8}, 519 { 26000000, 1300000000, 650, 13, 0, 8},
514 520
515 /* 1.2 GHz */ 521 /* 1.2 GHz */
516 { 12000000, 1200000000, 1000, 10, 1, 8}, 522 { 12000000, 1200000000, 1000, 10, 0, 8},
517 { 13000000, 1200000000, 923, 10, 1, 8}, /* actual: 1199.9 MHz */ 523 { 13000000, 1200000000, 923, 10, 0, 8}, /* actual: 1199.9 MHz */
518 { 16800000, 1200000000, 1000, 14, 1, 8}, 524 { 16800000, 1200000000, 1000, 14, 0, 8},
519 { 19200000, 1200000000, 1000, 16, 1, 8}, 525 { 19200000, 1200000000, 1000, 16, 0, 8},
520 { 26000000, 1200000000, 600, 13, 1, 8}, 526 { 26000000, 1200000000, 600, 13, 0, 8},
521 527
522 /* 1.1 GHz */ 528 /* 1.1 GHz */
523 { 12000000, 1100000000, 825, 9, 1, 8}, 529 { 12000000, 1100000000, 825, 9, 0, 8},
524 { 13000000, 1100000000, 846, 10, 1, 8}, /* actual: 1099.8 MHz */ 530 { 13000000, 1100000000, 846, 10, 0, 8}, /* actual: 1099.8 MHz */
525 { 16800000, 1100000000, 982, 15, 1, 8}, /* actual: 1099.8 MHz */ 531 { 16800000, 1100000000, 982, 15, 0, 8}, /* actual: 1099.8 MHz */
526 { 19200000, 1100000000, 859, 15, 1, 8}, /* actual: 1099.5 MHz */ 532 { 19200000, 1100000000, 859, 15, 0, 8}, /* actual: 1099.5 MHz */
527 { 26000000, 1100000000, 550, 13, 1, 8}, 533 { 26000000, 1100000000, 550, 13, 0, 8},
528 534
529 /* 1 GHz */ 535 /* 1 GHz */
530 { 12000000, 1000000000, 1000, 12, 1, 8}, 536 { 12000000, 1000000000, 1000, 12, 0, 8},
531 { 13000000, 1000000000, 1000, 13, 1, 8}, 537 { 13000000, 1000000000, 1000, 13, 0, 8},
532 { 16800000, 1000000000, 833, 14, 1, 8}, /* actual: 999.6 MHz */ 538 { 16800000, 1000000000, 833, 14, 0, 8}, /* actual: 999.6 MHz */
533 { 19200000, 1000000000, 625, 12, 1, 8}, 539 { 19200000, 1000000000, 625, 12, 0, 8},
534 { 26000000, 1000000000, 1000, 26, 1, 8}, 540 { 26000000, 1000000000, 1000, 26, 0, 8},
535 541
536 { 0, 0, 0, 0, 0, 0 }, 542 { 0, 0, 0, 0, 0, 0 },
537}; 543};
@@ -553,7 +559,7 @@ static struct tegra_clk_pll_params pll_c_params = {
553 .vco_max = 1400000000, 559 .vco_max = 1400000000,
554 .base_reg = PLLC_BASE, 560 .base_reg = PLLC_BASE,
555 .misc_reg = PLLC_MISC, 561 .misc_reg = PLLC_MISC,
556 .lock_bit_idx = PLL_BASE_LOCK, 562 .lock_mask = PLL_BASE_LOCK,
557 .lock_enable_bit_idx = PLL_MISC_LOCK_ENABLE, 563 .lock_enable_bit_idx = PLL_MISC_LOCK_ENABLE,
558 .lock_delay = 300, 564 .lock_delay = 300,
559}; 565};
@@ -567,7 +573,7 @@ static struct tegra_clk_pll_params pll_m_params = {
567 .vco_max = 1200000000, 573 .vco_max = 1200000000,
568 .base_reg = PLLM_BASE, 574 .base_reg = PLLM_BASE,
569 .misc_reg = PLLM_MISC, 575 .misc_reg = PLLM_MISC,
570 .lock_bit_idx = PLL_BASE_LOCK, 576 .lock_mask = PLL_BASE_LOCK,
571 .lock_enable_bit_idx = PLL_MISC_LOCK_ENABLE, 577 .lock_enable_bit_idx = PLL_MISC_LOCK_ENABLE,
572 .lock_delay = 300, 578 .lock_delay = 300,
573}; 579};
@@ -581,7 +587,7 @@ static struct tegra_clk_pll_params pll_p_params = {
581 .vco_max = 1400000000, 587 .vco_max = 1400000000,
582 .base_reg = PLLP_BASE, 588 .base_reg = PLLP_BASE,
583 .misc_reg = PLLP_MISC, 589 .misc_reg = PLLP_MISC,
584 .lock_bit_idx = PLL_BASE_LOCK, 590 .lock_mask = PLL_BASE_LOCK,
585 .lock_enable_bit_idx = PLL_MISC_LOCK_ENABLE, 591 .lock_enable_bit_idx = PLL_MISC_LOCK_ENABLE,
586 .lock_delay = 300, 592 .lock_delay = 300,
587}; 593};
@@ -595,7 +601,7 @@ static struct tegra_clk_pll_params pll_a_params = {
595 .vco_max = 1400000000, 601 .vco_max = 1400000000,
596 .base_reg = PLLA_BASE, 602 .base_reg = PLLA_BASE,
597 .misc_reg = PLLA_MISC, 603 .misc_reg = PLLA_MISC,
598 .lock_bit_idx = PLL_BASE_LOCK, 604 .lock_mask = PLL_BASE_LOCK,
599 .lock_enable_bit_idx = PLL_MISC_LOCK_ENABLE, 605 .lock_enable_bit_idx = PLL_MISC_LOCK_ENABLE,
600 .lock_delay = 300, 606 .lock_delay = 300,
601}; 607};
@@ -609,7 +615,7 @@ static struct tegra_clk_pll_params pll_d_params = {
609 .vco_max = 1000000000, 615 .vco_max = 1000000000,
610 .base_reg = PLLD_BASE, 616 .base_reg = PLLD_BASE,
611 .misc_reg = PLLD_MISC, 617 .misc_reg = PLLD_MISC,
612 .lock_bit_idx = PLL_BASE_LOCK, 618 .lock_mask = PLL_BASE_LOCK,
613 .lock_enable_bit_idx = PLLDU_MISC_LOCK_ENABLE, 619 .lock_enable_bit_idx = PLLDU_MISC_LOCK_ENABLE,
614 .lock_delay = 1000, 620 .lock_delay = 1000,
615}; 621};
@@ -623,7 +629,7 @@ static struct tegra_clk_pll_params pll_d2_params = {
623 .vco_max = 1000000000, 629 .vco_max = 1000000000,
624 .base_reg = PLLD2_BASE, 630 .base_reg = PLLD2_BASE,
625 .misc_reg = PLLD2_MISC, 631 .misc_reg = PLLD2_MISC,
626 .lock_bit_idx = PLL_BASE_LOCK, 632 .lock_mask = PLL_BASE_LOCK,
627 .lock_enable_bit_idx = PLLDU_MISC_LOCK_ENABLE, 633 .lock_enable_bit_idx = PLLDU_MISC_LOCK_ENABLE,
628 .lock_delay = 1000, 634 .lock_delay = 1000,
629}; 635};
@@ -637,9 +643,10 @@ static struct tegra_clk_pll_params pll_u_params = {
637 .vco_max = 960000000, 643 .vco_max = 960000000,
638 .base_reg = PLLU_BASE, 644 .base_reg = PLLU_BASE,
639 .misc_reg = PLLU_MISC, 645 .misc_reg = PLLU_MISC,
640 .lock_bit_idx = PLL_BASE_LOCK, 646 .lock_mask = PLL_BASE_LOCK,
641 .lock_enable_bit_idx = PLLDU_MISC_LOCK_ENABLE, 647 .lock_enable_bit_idx = PLLDU_MISC_LOCK_ENABLE,
642 .lock_delay = 1000, 648 .lock_delay = 1000,
649 .pdiv_tohw = pllu_p,
643}; 650};
644 651
645static struct tegra_clk_pll_params pll_x_params = { 652static struct tegra_clk_pll_params pll_x_params = {
@@ -651,7 +658,7 @@ static struct tegra_clk_pll_params pll_x_params = {
651 .vco_max = 1700000000, 658 .vco_max = 1700000000,
652 .base_reg = PLLX_BASE, 659 .base_reg = PLLX_BASE,
653 .misc_reg = PLLX_MISC, 660 .misc_reg = PLLX_MISC,
654 .lock_bit_idx = PLL_BASE_LOCK, 661 .lock_mask = PLL_BASE_LOCK,
655 .lock_enable_bit_idx = PLL_MISC_LOCK_ENABLE, 662 .lock_enable_bit_idx = PLL_MISC_LOCK_ENABLE,
656 .lock_delay = 300, 663 .lock_delay = 300,
657}; 664};
@@ -665,7 +672,7 @@ static struct tegra_clk_pll_params pll_e_params = {
665 .vco_max = 2400000000U, 672 .vco_max = 2400000000U,
666 .base_reg = PLLE_BASE, 673 .base_reg = PLLE_BASE,
667 .misc_reg = PLLE_MISC, 674 .misc_reg = PLLE_MISC,
668 .lock_bit_idx = PLLE_MISC_LOCK, 675 .lock_mask = PLLE_MISC_LOCK,
669 .lock_enable_bit_idx = PLLE_MISC_LOCK_ENABLE, 676 .lock_enable_bit_idx = PLLE_MISC_LOCK_ENABLE,
670 .lock_delay = 300, 677 .lock_delay = 300,
671}; 678};
@@ -1661,7 +1668,7 @@ static void __init tegra30_periph_clk_init(void)
1661 data = &tegra_periph_clk_list[i]; 1668 data = &tegra_periph_clk_list[i];
1662 clk = tegra_clk_register_periph(data->name, data->parent_names, 1669 clk = tegra_clk_register_periph(data->name, data->parent_names,
1663 data->num_parents, &data->periph, 1670 data->num_parents, &data->periph,
1664 clk_base, data->offset); 1671 clk_base, data->offset, data->flags);
1665 clk_register_clkdev(clk, data->con_id, data->dev_id); 1672 clk_register_clkdev(clk, data->con_id, data->dev_id);
1666 clks[data->clk_id] = clk; 1673 clks[data->clk_id] = clk;
1667 } 1674 }
@@ -1911,9 +1918,16 @@ static __initdata struct tegra_clk_init_table init_table[] = {
1911 {disp1, pll_p, 600000000, 0}, 1918 {disp1, pll_p, 600000000, 0},
1912 {disp2, pll_p, 600000000, 0}, 1919 {disp2, pll_p, 600000000, 0},
1913 {twd, clk_max, 0, 1}, 1920 {twd, clk_max, 0, 1},
1921 {gr2d, pll_c, 300000000, 0},
1922 {gr3d, pll_c, 300000000, 0},
1914 {clk_max, clk_max, 0, 0}, /* This MUST be the last entry. */ 1923 {clk_max, clk_max, 0, 0}, /* This MUST be the last entry. */
1915}; 1924};
1916 1925
1926static void __init tegra30_clock_apply_init_table(void)
1927{
1928 tegra_init_from_table(init_table, clks, clk_max);
1929}
1930
1917/* 1931/*
1918 * Some clocks may be used by different drivers depending on the board 1932 * Some clocks may be used by different drivers depending on the board
1919 * configuration. List those here to register them twice in the clock lookup 1933 * configuration. List those here to register them twice in the clock lookup
@@ -1987,7 +2001,7 @@ void __init tegra30_clock_init(struct device_node *np)
1987 clk_data.clk_num = ARRAY_SIZE(clks); 2001 clk_data.clk_num = ARRAY_SIZE(clks);
1988 of_clk_add_provider(np, of_clk_src_onecell_get, &clk_data); 2002 of_clk_add_provider(np, of_clk_src_onecell_get, &clk_data);
1989 2003
1990 tegra_init_from_table(init_table, clks, clk_max); 2004 tegra_clk_apply_init_table = tegra30_clock_apply_init_table;
1991 2005
1992 tegra_cpu_car_ops = &tegra30_cpu_car_ops; 2006 tegra_cpu_car_ops = &tegra30_cpu_car_ops;
1993} 2007}
diff --git a/drivers/clk/tegra/clk.c b/drivers/clk/tegra/clk.c
index a603b9af0ad3..923ca7ee4694 100644
--- a/drivers/clk/tegra/clk.c
+++ b/drivers/clk/tegra/clk.c
@@ -22,7 +22,8 @@
22#include "clk.h" 22#include "clk.h"
23 23
24/* Global data of Tegra CPU CAR ops */ 24/* Global data of Tegra CPU CAR ops */
25struct tegra_cpu_car_ops *tegra_cpu_car_ops; 25static struct tegra_cpu_car_ops dummy_car_ops;
26struct tegra_cpu_car_ops *tegra_cpu_car_ops = &dummy_car_ops;
26 27
27void __init tegra_init_dup_clks(struct tegra_clk_duplicate *dup_list, 28void __init tegra_init_dup_clks(struct tegra_clk_duplicate *dup_list,
28 struct clk *clks[], int clk_max) 29 struct clk *clks[], int clk_max)
@@ -76,6 +77,7 @@ void __init tegra_init_from_table(struct tegra_clk_init_table *tbl,
76static const struct of_device_id tegra_dt_clk_match[] = { 77static const struct of_device_id tegra_dt_clk_match[] = {
77 { .compatible = "nvidia,tegra20-car", .data = tegra20_clock_init }, 78 { .compatible = "nvidia,tegra20-car", .data = tegra20_clock_init },
78 { .compatible = "nvidia,tegra30-car", .data = tegra30_clock_init }, 79 { .compatible = "nvidia,tegra30-car", .data = tegra30_clock_init },
80 { .compatible = "nvidia,tegra114-car", .data = tegra114_clock_init },
79 { } 81 { }
80}; 82};
81 83
@@ -83,3 +85,13 @@ void __init tegra_clocks_init(void)
83{ 85{
84 of_clk_init(tegra_dt_clk_match); 86 of_clk_init(tegra_dt_clk_match);
85} 87}
88
89tegra_clk_apply_init_table_func tegra_clk_apply_init_table;
90
91void __init tegra_clocks_apply_init_table(void)
92{
93 if (!tegra_clk_apply_init_table)
94 return;
95
96 tegra_clk_apply_init_table();
97}
diff --git a/drivers/clk/tegra/clk.h b/drivers/clk/tegra/clk.h
index 0744731c6229..e0565620d68e 100644
--- a/drivers/clk/tegra/clk.h
+++ b/drivers/clk/tegra/clk.h
@@ -1,4 +1,4 @@
1/* 1 /*
2 * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved. 2 * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved.
3 * 3 *
4 * This program is free software; you can redistribute it and/or modify it 4 * This program is free software; you can redistribute it and/or modify it
@@ -117,6 +117,17 @@ struct tegra_clk_pll_freq_table {
117}; 117};
118 118
119/** 119/**
120 * struct pdiv_map - map post divider to hw value
121 *
122 * @pdiv: post divider
123 * @hw_val: value to be written to the PLL hw
124 */
125struct pdiv_map {
126 u8 pdiv;
127 u8 hw_val;
128};
129
130/**
120 * struct clk_pll_params - PLL parameters 131 * struct clk_pll_params - PLL parameters
121 * 132 *
122 * @input_min: Minimum input frequency 133 * @input_min: Minimum input frequency
@@ -143,9 +154,18 @@ struct tegra_clk_pll_params {
143 u32 base_reg; 154 u32 base_reg;
144 u32 misc_reg; 155 u32 misc_reg;
145 u32 lock_reg; 156 u32 lock_reg;
146 u32 lock_bit_idx; 157 u32 lock_mask;
147 u32 lock_enable_bit_idx; 158 u32 lock_enable_bit_idx;
159 u32 iddq_reg;
160 u32 iddq_bit_idx;
161 u32 aux_reg;
162 u32 dyn_ramp_reg;
163 u32 ext_misc_reg[3];
164 int stepa_shift;
165 int stepb_shift;
148 int lock_delay; 166 int lock_delay;
167 int max_p;
168 struct pdiv_map *pdiv_tohw;
149}; 169};
150 170
151/** 171/**
@@ -182,12 +202,16 @@ struct tegra_clk_pll_params {
182 * TEGRA_PLL_FIXED - We are not supposed to change output frequency 202 * TEGRA_PLL_FIXED - We are not supposed to change output frequency
183 * of some plls. 203 * of some plls.
184 * TEGRA_PLLE_CONFIGURE - Configure PLLE when enabling. 204 * TEGRA_PLLE_CONFIGURE - Configure PLLE when enabling.
205 * TEGRA_PLL_LOCK_MISC - Lock bit is in the misc register instead of the
206 * base register.
207 * TEGRA_PLL_BYPASS - PLL has bypass bit
208 * TEGRA_PLL_HAS_LOCK_ENABLE - PLL has bit to enable lock monitoring
185 */ 209 */
186struct tegra_clk_pll { 210struct tegra_clk_pll {
187 struct clk_hw hw; 211 struct clk_hw hw;
188 void __iomem *clk_base; 212 void __iomem *clk_base;
189 void __iomem *pmc; 213 void __iomem *pmc;
190 u8 flags; 214 u32 flags;
191 unsigned long fixed_rate; 215 unsigned long fixed_rate;
192 spinlock_t *lock; 216 spinlock_t *lock;
193 u8 divn_shift; 217 u8 divn_shift;
@@ -210,20 +234,64 @@ struct tegra_clk_pll {
210#define TEGRA_PLLM BIT(5) 234#define TEGRA_PLLM BIT(5)
211#define TEGRA_PLL_FIXED BIT(6) 235#define TEGRA_PLL_FIXED BIT(6)
212#define TEGRA_PLLE_CONFIGURE BIT(7) 236#define TEGRA_PLLE_CONFIGURE BIT(7)
237#define TEGRA_PLL_LOCK_MISC BIT(8)
238#define TEGRA_PLL_BYPASS BIT(9)
239#define TEGRA_PLL_HAS_LOCK_ENABLE BIT(10)
213 240
214extern const struct clk_ops tegra_clk_pll_ops; 241extern const struct clk_ops tegra_clk_pll_ops;
215extern const struct clk_ops tegra_clk_plle_ops; 242extern const struct clk_ops tegra_clk_plle_ops;
216struct clk *tegra_clk_register_pll(const char *name, const char *parent_name, 243struct clk *tegra_clk_register_pll(const char *name, const char *parent_name,
217 void __iomem *clk_base, void __iomem *pmc, 244 void __iomem *clk_base, void __iomem *pmc,
218 unsigned long flags, unsigned long fixed_rate, 245 unsigned long flags, unsigned long fixed_rate,
219 struct tegra_clk_pll_params *pll_params, u8 pll_flags, 246 struct tegra_clk_pll_params *pll_params, u32 pll_flags,
220 struct tegra_clk_pll_freq_table *freq_table, spinlock_t *lock); 247 struct tegra_clk_pll_freq_table *freq_table, spinlock_t *lock);
248
221struct clk *tegra_clk_register_plle(const char *name, const char *parent_name, 249struct clk *tegra_clk_register_plle(const char *name, const char *parent_name,
222 void __iomem *clk_base, void __iomem *pmc, 250 void __iomem *clk_base, void __iomem *pmc,
223 unsigned long flags, unsigned long fixed_rate, 251 unsigned long flags, unsigned long fixed_rate,
224 struct tegra_clk_pll_params *pll_params, u8 pll_flags, 252 struct tegra_clk_pll_params *pll_params, u32 pll_flags,
225 struct tegra_clk_pll_freq_table *freq_table, spinlock_t *lock); 253 struct tegra_clk_pll_freq_table *freq_table, spinlock_t *lock);
226 254
255struct clk *tegra_clk_register_pllxc(const char *name, const char *parent_name,
256 void __iomem *clk_base, void __iomem *pmc,
257 unsigned long flags, unsigned long fixed_rate,
258 struct tegra_clk_pll_params *pll_params,
259 u32 pll_flags,
260 struct tegra_clk_pll_freq_table *freq_table,
261 spinlock_t *lock);
262
263struct clk *tegra_clk_register_pllm(const char *name, const char *parent_name,
264 void __iomem *clk_base, void __iomem *pmc,
265 unsigned long flags, unsigned long fixed_rate,
266 struct tegra_clk_pll_params *pll_params,
267 u32 pll_flags,
268 struct tegra_clk_pll_freq_table *freq_table,
269 spinlock_t *lock);
270
271struct clk *tegra_clk_register_pllc(const char *name, const char *parent_name,
272 void __iomem *clk_base, void __iomem *pmc,
273 unsigned long flags, unsigned long fixed_rate,
274 struct tegra_clk_pll_params *pll_params,
275 u32 pll_flags,
276 struct tegra_clk_pll_freq_table *freq_table,
277 spinlock_t *lock);
278
279struct clk *tegra_clk_register_pllre(const char *name, const char *parent_name,
280 void __iomem *clk_base, void __iomem *pmc,
281 unsigned long flags, unsigned long fixed_rate,
282 struct tegra_clk_pll_params *pll_params,
283 u32 pll_flags,
284 struct tegra_clk_pll_freq_table *freq_table,
285 spinlock_t *lock, unsigned long parent_rate);
286
287struct clk *tegra_clk_register_plle_tegra114(const char *name,
288 const char *parent_name,
289 void __iomem *clk_base, unsigned long flags,
290 unsigned long fixed_rate,
291 struct tegra_clk_pll_params *pll_params,
292 struct tegra_clk_pll_freq_table *freq_table,
293 spinlock_t *lock);
294
227/** 295/**
228 * struct tegra_clk_pll_out - PLL divider down clock 296 * struct tegra_clk_pll_out - PLL divider down clock
229 * 297 *
@@ -290,6 +358,7 @@ struct tegra_clk_periph_regs {
290 * TEGRA_PERIPH_ON_APB - If peripheral is in the APB bus then read the 358 * TEGRA_PERIPH_ON_APB - If peripheral is in the APB bus then read the
291 * bus to flush the write operation in apb bus. This flag indicates 359 * bus to flush the write operation in apb bus. This flag indicates
292 * that this peripheral is in apb bus. 360 * that this peripheral is in apb bus.
361 * TEGRA_PERIPH_WAR_1005168 - Apply workaround for Tegra114 MSENC bug
293 */ 362 */
294struct tegra_clk_periph_gate { 363struct tegra_clk_periph_gate {
295 u32 magic; 364 u32 magic;
@@ -309,6 +378,7 @@ struct tegra_clk_periph_gate {
309#define TEGRA_PERIPH_NO_RESET BIT(0) 378#define TEGRA_PERIPH_NO_RESET BIT(0)
310#define TEGRA_PERIPH_MANUAL_RESET BIT(1) 379#define TEGRA_PERIPH_MANUAL_RESET BIT(1)
311#define TEGRA_PERIPH_ON_APB BIT(2) 380#define TEGRA_PERIPH_ON_APB BIT(2)
381#define TEGRA_PERIPH_WAR_1005168 BIT(3)
312 382
313void tegra_periph_reset(struct tegra_clk_periph_gate *gate, bool assert); 383void tegra_periph_reset(struct tegra_clk_periph_gate *gate, bool assert);
314extern const struct clk_ops tegra_clk_periph_gate_ops; 384extern const struct clk_ops tegra_clk_periph_gate_ops;
@@ -349,21 +419,22 @@ extern const struct clk_ops tegra_clk_periph_ops;
349struct clk *tegra_clk_register_periph(const char *name, 419struct clk *tegra_clk_register_periph(const char *name,
350 const char **parent_names, int num_parents, 420 const char **parent_names, int num_parents,
351 struct tegra_clk_periph *periph, void __iomem *clk_base, 421 struct tegra_clk_periph *periph, void __iomem *clk_base,
352 u32 offset); 422 u32 offset, unsigned long flags);
353struct clk *tegra_clk_register_periph_nodiv(const char *name, 423struct clk *tegra_clk_register_periph_nodiv(const char *name,
354 const char **parent_names, int num_parents, 424 const char **parent_names, int num_parents,
355 struct tegra_clk_periph *periph, void __iomem *clk_base, 425 struct tegra_clk_periph *periph, void __iomem *clk_base,
356 u32 offset); 426 u32 offset);
357 427
358#define TEGRA_CLK_PERIPH(_mux_shift, _mux_width, _mux_flags, \ 428#define TEGRA_CLK_PERIPH(_mux_shift, _mux_mask, _mux_flags, \
359 _div_shift, _div_width, _div_frac_width, \ 429 _div_shift, _div_width, _div_frac_width, \
360 _div_flags, _clk_num, _enb_refcnt, _regs, \ 430 _div_flags, _clk_num, _enb_refcnt, _regs, \
361 _gate_flags) \ 431 _gate_flags, _table) \
362 { \ 432 { \
363 .mux = { \ 433 .mux = { \
364 .flags = _mux_flags, \ 434 .flags = _mux_flags, \
365 .shift = _mux_shift, \ 435 .shift = _mux_shift, \
366 .width = _mux_width, \ 436 .mask = _mux_mask, \
437 .table = _table, \
367 }, \ 438 }, \
368 .divider = { \ 439 .divider = { \
369 .flags = _div_flags, \ 440 .flags = _div_flags, \
@@ -391,28 +462,41 @@ struct tegra_periph_init_data {
391 u32 offset; 462 u32 offset;
392 const char *con_id; 463 const char *con_id;
393 const char *dev_id; 464 const char *dev_id;
465 unsigned long flags;
394}; 466};
395 467
396#define TEGRA_INIT_DATA(_name, _con_id, _dev_id, _parent_names, _offset, \ 468#define TEGRA_INIT_DATA_TABLE(_name, _con_id, _dev_id, _parent_names, _offset,\
397 _mux_shift, _mux_width, _mux_flags, _div_shift, \ 469 _mux_shift, _mux_mask, _mux_flags, _div_shift, \
398 _div_width, _div_frac_width, _div_flags, _regs, \ 470 _div_width, _div_frac_width, _div_flags, _regs, \
399 _clk_num, _enb_refcnt, _gate_flags, _clk_id) \ 471 _clk_num, _enb_refcnt, _gate_flags, _clk_id, _table,\
472 _flags) \
400 { \ 473 { \
401 .name = _name, \ 474 .name = _name, \
402 .clk_id = _clk_id, \ 475 .clk_id = _clk_id, \
403 .parent_names = _parent_names, \ 476 .parent_names = _parent_names, \
404 .num_parents = ARRAY_SIZE(_parent_names), \ 477 .num_parents = ARRAY_SIZE(_parent_names), \
405 .periph = TEGRA_CLK_PERIPH(_mux_shift, _mux_width, \ 478 .periph = TEGRA_CLK_PERIPH(_mux_shift, _mux_mask, \
406 _mux_flags, _div_shift, \ 479 _mux_flags, _div_shift, \
407 _div_width, _div_frac_width, \ 480 _div_width, _div_frac_width, \
408 _div_flags, _clk_num, \ 481 _div_flags, _clk_num, \
409 _enb_refcnt, _regs, \ 482 _enb_refcnt, _regs, \
410 _gate_flags), \ 483 _gate_flags, _table), \
411 .offset = _offset, \ 484 .offset = _offset, \
412 .con_id = _con_id, \ 485 .con_id = _con_id, \
413 .dev_id = _dev_id, \ 486 .dev_id = _dev_id, \
487 .flags = _flags \
414 } 488 }
415 489
490#define TEGRA_INIT_DATA(_name, _con_id, _dev_id, _parent_names, _offset,\
491 _mux_shift, _mux_width, _mux_flags, _div_shift, \
492 _div_width, _div_frac_width, _div_flags, _regs, \
493 _clk_num, _enb_refcnt, _gate_flags, _clk_id) \
494 TEGRA_INIT_DATA_TABLE(_name, _con_id, _dev_id, _parent_names, _offset,\
495 _mux_shift, BIT(_mux_width) - 1, _mux_flags, \
496 _div_shift, _div_width, _div_frac_width, _div_flags, \
497 _regs, _clk_num, _enb_refcnt, _gate_flags, _clk_id,\
498 NULL, 0)
499
416/** 500/**
417 * struct clk_super_mux - super clock 501 * struct clk_super_mux - super clock
418 * 502 *
@@ -499,4 +583,13 @@ void tegra30_clock_init(struct device_node *np);
499static inline void tegra30_clock_init(struct device_node *np) {} 583static inline void tegra30_clock_init(struct device_node *np) {}
500#endif /* CONFIG_ARCH_TEGRA_3x_SOC */ 584#endif /* CONFIG_ARCH_TEGRA_3x_SOC */
501 585
586#ifdef CONFIG_ARCH_TEGRA_114_SOC
587void tegra114_clock_init(struct device_node *np);
588#else
589static inline void tegra114_clock_init(struct device_node *np) {}
590#endif /* CONFIG_ARCH_TEGRA114_SOC */
591
592typedef void (*tegra_clk_apply_init_table_func)(void);
593extern tegra_clk_apply_init_table_func tegra_clk_apply_init_table;
594
502#endif /* TEGRA_CLK_H */ 595#endif /* TEGRA_CLK_H */
diff --git a/drivers/clk/ux500/clk-prcmu.c b/drivers/clk/ux500/clk-prcmu.c
index 74faa7e3cf59..293a28854417 100644
--- a/drivers/clk/ux500/clk-prcmu.c
+++ b/drivers/clk/ux500/clk-prcmu.c
@@ -20,15 +20,23 @@
20struct clk_prcmu { 20struct clk_prcmu {
21 struct clk_hw hw; 21 struct clk_hw hw;
22 u8 cg_sel; 22 u8 cg_sel;
23 int is_prepared;
23 int is_enabled; 24 int is_enabled;
25 int opp_requested;
24}; 26};
25 27
26/* PRCMU clock operations. */ 28/* PRCMU clock operations. */
27 29
28static int clk_prcmu_prepare(struct clk_hw *hw) 30static int clk_prcmu_prepare(struct clk_hw *hw)
29{ 31{
32 int ret;
30 struct clk_prcmu *clk = to_clk_prcmu(hw); 33 struct clk_prcmu *clk = to_clk_prcmu(hw);
31 return prcmu_request_clock(clk->cg_sel, true); 34
35 ret = prcmu_request_clock(clk->cg_sel, true);
36 if (!ret)
37 clk->is_prepared = 1;
38
39 return ret;;
32} 40}
33 41
34static void clk_prcmu_unprepare(struct clk_hw *hw) 42static void clk_prcmu_unprepare(struct clk_hw *hw)
@@ -36,7 +44,15 @@ static void clk_prcmu_unprepare(struct clk_hw *hw)
36 struct clk_prcmu *clk = to_clk_prcmu(hw); 44 struct clk_prcmu *clk = to_clk_prcmu(hw);
37 if (prcmu_request_clock(clk->cg_sel, false)) 45 if (prcmu_request_clock(clk->cg_sel, false))
38 pr_err("clk_prcmu: %s failed to disable %s.\n", __func__, 46 pr_err("clk_prcmu: %s failed to disable %s.\n", __func__,
39 hw->init->name); 47 __clk_get_name(hw->clk));
48 else
49 clk->is_prepared = 0;
50}
51
52static int clk_prcmu_is_prepared(struct clk_hw *hw)
53{
54 struct clk_prcmu *clk = to_clk_prcmu(hw);
55 return clk->is_prepared;
40} 56}
41 57
42static int clk_prcmu_enable(struct clk_hw *hw) 58static int clk_prcmu_enable(struct clk_hw *hw)
@@ -79,58 +95,52 @@ static int clk_prcmu_set_rate(struct clk_hw *hw, unsigned long rate,
79 return prcmu_set_clock_rate(clk->cg_sel, rate); 95 return prcmu_set_clock_rate(clk->cg_sel, rate);
80} 96}
81 97
82static int request_ape_opp100(bool enable)
83{
84 static int reqs;
85 int err = 0;
86
87 if (enable) {
88 if (!reqs)
89 err = prcmu_qos_add_requirement(PRCMU_QOS_APE_OPP,
90 "clock", 100);
91 if (!err)
92 reqs++;
93 } else {
94 reqs--;
95 if (!reqs)
96 prcmu_qos_remove_requirement(PRCMU_QOS_APE_OPP,
97 "clock");
98 }
99 return err;
100}
101
102static int clk_prcmu_opp_prepare(struct clk_hw *hw) 98static int clk_prcmu_opp_prepare(struct clk_hw *hw)
103{ 99{
104 int err; 100 int err;
105 struct clk_prcmu *clk = to_clk_prcmu(hw); 101 struct clk_prcmu *clk = to_clk_prcmu(hw);
106 102
107 err = request_ape_opp100(true); 103 if (!clk->opp_requested) {
108 if (err) { 104 err = prcmu_qos_add_requirement(PRCMU_QOS_APE_OPP,
109 pr_err("clk_prcmu: %s failed to request APE OPP100 for %s.\n", 105 (char *)__clk_get_name(hw->clk),
110 __func__, hw->init->name); 106 100);
111 return err; 107 if (err) {
108 pr_err("clk_prcmu: %s fail req APE OPP for %s.\n",
109 __func__, __clk_get_name(hw->clk));
110 return err;
111 }
112 clk->opp_requested = 1;
112 } 113 }
113 114
114 err = prcmu_request_clock(clk->cg_sel, true); 115 err = prcmu_request_clock(clk->cg_sel, true);
115 if (err) 116 if (err) {
116 request_ape_opp100(false); 117 prcmu_qos_remove_requirement(PRCMU_QOS_APE_OPP,
118 (char *)__clk_get_name(hw->clk));
119 clk->opp_requested = 0;
120 return err;
121 }
117 122
118 return err; 123 clk->is_prepared = 1;
124 return 0;
119} 125}
120 126
121static void clk_prcmu_opp_unprepare(struct clk_hw *hw) 127static void clk_prcmu_opp_unprepare(struct clk_hw *hw)
122{ 128{
123 struct clk_prcmu *clk = to_clk_prcmu(hw); 129 struct clk_prcmu *clk = to_clk_prcmu(hw);
124 130
125 if (prcmu_request_clock(clk->cg_sel, false)) 131 if (prcmu_request_clock(clk->cg_sel, false)) {
126 goto out_error; 132 pr_err("clk_prcmu: %s failed to disable %s.\n", __func__,
127 if (request_ape_opp100(false)) 133 __clk_get_name(hw->clk));
128 goto out_error; 134 return;
129 return; 135 }
130 136
131out_error: 137 if (clk->opp_requested) {
132 pr_err("clk_prcmu: %s failed to disable %s.\n", __func__, 138 prcmu_qos_remove_requirement(PRCMU_QOS_APE_OPP,
133 hw->init->name); 139 (char *)__clk_get_name(hw->clk));
140 clk->opp_requested = 0;
141 }
142
143 clk->is_prepared = 0;
134} 144}
135 145
136static int clk_prcmu_opp_volt_prepare(struct clk_hw *hw) 146static int clk_prcmu_opp_volt_prepare(struct clk_hw *hw)
@@ -138,38 +148,49 @@ static int clk_prcmu_opp_volt_prepare(struct clk_hw *hw)
138 int err; 148 int err;
139 struct clk_prcmu *clk = to_clk_prcmu(hw); 149 struct clk_prcmu *clk = to_clk_prcmu(hw);
140 150
141 err = prcmu_request_ape_opp_100_voltage(true); 151 if (!clk->opp_requested) {
142 if (err) { 152 err = prcmu_request_ape_opp_100_voltage(true);
143 pr_err("clk_prcmu: %s failed to request APE OPP VOLT for %s.\n", 153 if (err) {
144 __func__, hw->init->name); 154 pr_err("clk_prcmu: %s fail req APE OPP VOLT for %s.\n",
145 return err; 155 __func__, __clk_get_name(hw->clk));
156 return err;
157 }
158 clk->opp_requested = 1;
146 } 159 }
147 160
148 err = prcmu_request_clock(clk->cg_sel, true); 161 err = prcmu_request_clock(clk->cg_sel, true);
149 if (err) 162 if (err) {
150 prcmu_request_ape_opp_100_voltage(false); 163 prcmu_request_ape_opp_100_voltage(false);
164 clk->opp_requested = 0;
165 return err;
166 }
151 167
152 return err; 168 clk->is_prepared = 1;
169 return 0;
153} 170}
154 171
155static void clk_prcmu_opp_volt_unprepare(struct clk_hw *hw) 172static void clk_prcmu_opp_volt_unprepare(struct clk_hw *hw)
156{ 173{
157 struct clk_prcmu *clk = to_clk_prcmu(hw); 174 struct clk_prcmu *clk = to_clk_prcmu(hw);
158 175
159 if (prcmu_request_clock(clk->cg_sel, false)) 176 if (prcmu_request_clock(clk->cg_sel, false)) {
160 goto out_error; 177 pr_err("clk_prcmu: %s failed to disable %s.\n", __func__,
161 if (prcmu_request_ape_opp_100_voltage(false)) 178 __clk_get_name(hw->clk));
162 goto out_error; 179 return;
163 return; 180 }
164 181
165out_error: 182 if (clk->opp_requested) {
166 pr_err("clk_prcmu: %s failed to disable %s.\n", __func__, 183 prcmu_request_ape_opp_100_voltage(false);
167 hw->init->name); 184 clk->opp_requested = 0;
185 }
186
187 clk->is_prepared = 0;
168} 188}
169 189
170static struct clk_ops clk_prcmu_scalable_ops = { 190static struct clk_ops clk_prcmu_scalable_ops = {
171 .prepare = clk_prcmu_prepare, 191 .prepare = clk_prcmu_prepare,
172 .unprepare = clk_prcmu_unprepare, 192 .unprepare = clk_prcmu_unprepare,
193 .is_prepared = clk_prcmu_is_prepared,
173 .enable = clk_prcmu_enable, 194 .enable = clk_prcmu_enable,
174 .disable = clk_prcmu_disable, 195 .disable = clk_prcmu_disable,
175 .is_enabled = clk_prcmu_is_enabled, 196 .is_enabled = clk_prcmu_is_enabled,
@@ -181,6 +202,7 @@ static struct clk_ops clk_prcmu_scalable_ops = {
181static struct clk_ops clk_prcmu_gate_ops = { 202static struct clk_ops clk_prcmu_gate_ops = {
182 .prepare = clk_prcmu_prepare, 203 .prepare = clk_prcmu_prepare,
183 .unprepare = clk_prcmu_unprepare, 204 .unprepare = clk_prcmu_unprepare,
205 .is_prepared = clk_prcmu_is_prepared,
184 .enable = clk_prcmu_enable, 206 .enable = clk_prcmu_enable,
185 .disable = clk_prcmu_disable, 207 .disable = clk_prcmu_disable,
186 .is_enabled = clk_prcmu_is_enabled, 208 .is_enabled = clk_prcmu_is_enabled,
@@ -202,6 +224,7 @@ static struct clk_ops clk_prcmu_rate_ops = {
202static struct clk_ops clk_prcmu_opp_gate_ops = { 224static struct clk_ops clk_prcmu_opp_gate_ops = {
203 .prepare = clk_prcmu_opp_prepare, 225 .prepare = clk_prcmu_opp_prepare,
204 .unprepare = clk_prcmu_opp_unprepare, 226 .unprepare = clk_prcmu_opp_unprepare,
227 .is_prepared = clk_prcmu_is_prepared,
205 .enable = clk_prcmu_enable, 228 .enable = clk_prcmu_enable,
206 .disable = clk_prcmu_disable, 229 .disable = clk_prcmu_disable,
207 .is_enabled = clk_prcmu_is_enabled, 230 .is_enabled = clk_prcmu_is_enabled,
@@ -211,6 +234,7 @@ static struct clk_ops clk_prcmu_opp_gate_ops = {
211static struct clk_ops clk_prcmu_opp_volt_scalable_ops = { 234static struct clk_ops clk_prcmu_opp_volt_scalable_ops = {
212 .prepare = clk_prcmu_opp_volt_prepare, 235 .prepare = clk_prcmu_opp_volt_prepare,
213 .unprepare = clk_prcmu_opp_volt_unprepare, 236 .unprepare = clk_prcmu_opp_volt_unprepare,
237 .is_prepared = clk_prcmu_is_prepared,
214 .enable = clk_prcmu_enable, 238 .enable = clk_prcmu_enable,
215 .disable = clk_prcmu_disable, 239 .disable = clk_prcmu_disable,
216 .is_enabled = clk_prcmu_is_enabled, 240 .is_enabled = clk_prcmu_is_enabled,
@@ -242,7 +266,9 @@ static struct clk *clk_reg_prcmu(const char *name,
242 } 266 }
243 267
244 clk->cg_sel = cg_sel; 268 clk->cg_sel = cg_sel;
269 clk->is_prepared = 1;
245 clk->is_enabled = 1; 270 clk->is_enabled = 1;
271 clk->opp_requested = 0;
246 /* "rate" can be used for changing the initial frequency */ 272 /* "rate" can be used for changing the initial frequency */
247 if (rate) 273 if (rate)
248 prcmu_set_clock_rate(cg_sel, rate); 274 prcmu_set_clock_rate(cg_sel, rate);
diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig
index e507ab7df60b..29ba35e6a143 100644
--- a/drivers/clocksource/Kconfig
+++ b/drivers/clocksource/Kconfig
@@ -31,6 +31,9 @@ config SUNXI_TIMER
31config VT8500_TIMER 31config VT8500_TIMER
32 bool 32 bool
33 33
34config CADENCE_TTC_TIMER
35 bool
36
34config CLKSRC_NOMADIK_MTU 37config CLKSRC_NOMADIK_MTU
35 bool 38 bool
36 depends on (ARCH_NOMADIK || ARCH_U8500) 39 depends on (ARCH_NOMADIK || ARCH_U8500)
@@ -62,8 +65,14 @@ config CLKSRC_DBX500_PRCMU_SCHED_CLOCK
62 65
63config ARM_ARCH_TIMER 66config ARM_ARCH_TIMER
64 bool 67 bool
68 select CLKSRC_OF if OF
65 69
66config CLKSRC_METAG_GENERIC 70config CLKSRC_METAG_GENERIC
67 def_bool y if METAG 71 def_bool y if METAG
68 help 72 help
69 This option enables support for the Meta per-thread timers. 73 This option enables support for the Meta per-thread timers.
74
75config CLKSRC_EXYNOS_MCT
76 def_bool y if ARCH_EXYNOS
77 help
78 Support for Multi Core Timer controller on Exynos SoCs.
diff --git a/drivers/clocksource/Makefile b/drivers/clocksource/Makefile
index 4d8283aec5b5..cd1f09cbd61a 100644
--- a/drivers/clocksource/Makefile
+++ b/drivers/clocksource/Makefile
@@ -19,6 +19,8 @@ obj-$(CONFIG_ARCH_BCM2835) += bcm2835_timer.o
19obj-$(CONFIG_SUNXI_TIMER) += sunxi_timer.o 19obj-$(CONFIG_SUNXI_TIMER) += sunxi_timer.o
20obj-$(CONFIG_ARCH_TEGRA) += tegra20_timer.o 20obj-$(CONFIG_ARCH_TEGRA) += tegra20_timer.o
21obj-$(CONFIG_VT8500_TIMER) += vt8500_timer.o 21obj-$(CONFIG_VT8500_TIMER) += vt8500_timer.o
22obj-$(CONFIG_CADENCE_TTC_TIMER) += cadence_ttc_timer.o
23obj-$(CONFIG_CLKSRC_EXYNOS_MCT) += exynos_mct.o
22 24
23obj-$(CONFIG_ARM_ARCH_TIMER) += arm_arch_timer.o 25obj-$(CONFIG_ARM_ARCH_TIMER) += arm_arch_timer.o
24obj-$(CONFIG_CLKSRC_METAG_GENERIC) += metag_generic.o 26obj-$(CONFIG_CLKSRC_METAG_GENERIC) += metag_generic.o
diff --git a/drivers/clocksource/arm_arch_timer.c b/drivers/clocksource/arm_arch_timer.c
index d7ad425ab9b3..a2b254189782 100644
--- a/drivers/clocksource/arm_arch_timer.c
+++ b/drivers/clocksource/arm_arch_timer.c
@@ -248,14 +248,16 @@ static void __cpuinit arch_timer_stop(struct clock_event_device *clk)
248static int __cpuinit arch_timer_cpu_notify(struct notifier_block *self, 248static int __cpuinit arch_timer_cpu_notify(struct notifier_block *self,
249 unsigned long action, void *hcpu) 249 unsigned long action, void *hcpu)
250{ 250{
251 struct clock_event_device *evt = this_cpu_ptr(arch_timer_evt); 251 /*
252 252 * Grab cpu pointer in each case to avoid spurious
253 * preemptible warnings
254 */
253 switch (action & ~CPU_TASKS_FROZEN) { 255 switch (action & ~CPU_TASKS_FROZEN) {
254 case CPU_STARTING: 256 case CPU_STARTING:
255 arch_timer_setup(evt); 257 arch_timer_setup(this_cpu_ptr(arch_timer_evt));
256 break; 258 break;
257 case CPU_DYING: 259 case CPU_DYING:
258 arch_timer_stop(evt); 260 arch_timer_stop(this_cpu_ptr(arch_timer_evt));
259 break; 261 break;
260 } 262 }
261 263
@@ -337,22 +339,14 @@ out:
337 return err; 339 return err;
338} 340}
339 341
340static const struct of_device_id arch_timer_of_match[] __initconst = { 342static void __init arch_timer_init(struct device_node *np)
341 { .compatible = "arm,armv7-timer", },
342 { .compatible = "arm,armv8-timer", },
343 {},
344};
345
346int __init arch_timer_init(void)
347{ 343{
348 struct device_node *np;
349 u32 freq; 344 u32 freq;
350 int i; 345 int i;
351 346
352 np = of_find_matching_node(NULL, arch_timer_of_match); 347 if (arch_timer_get_rate()) {
353 if (!np) { 348 pr_warn("arch_timer: multiple nodes in dt, skipping\n");
354 pr_err("arch_timer: can't find DT node\n"); 349 return;
355 return -ENODEV;
356 } 350 }
357 351
358 /* Try to determine the frequency from the device tree or CNTFRQ */ 352 /* Try to determine the frequency from the device tree or CNTFRQ */
@@ -378,7 +372,7 @@ int __init arch_timer_init(void)
378 if (!arch_timer_ppi[PHYS_SECURE_PPI] || 372 if (!arch_timer_ppi[PHYS_SECURE_PPI] ||
379 !arch_timer_ppi[PHYS_NONSECURE_PPI]) { 373 !arch_timer_ppi[PHYS_NONSECURE_PPI]) {
380 pr_warn("arch_timer: No interrupt available, giving up\n"); 374 pr_warn("arch_timer: No interrupt available, giving up\n");
381 return -EINVAL; 375 return;
382 } 376 }
383 } 377 }
384 378
@@ -387,5 +381,8 @@ int __init arch_timer_init(void)
387 else 381 else
388 arch_timer_read_counter = arch_counter_get_cntpct; 382 arch_timer_read_counter = arch_counter_get_cntpct;
389 383
390 return arch_timer_register(); 384 arch_timer_register();
385 arch_timer_arch_init();
391} 386}
387CLOCKSOURCE_OF_DECLARE(armv7_arch_timer, "arm,armv7-timer", arch_timer_init);
388CLOCKSOURCE_OF_DECLARE(armv8_arch_timer, "arm,armv8-timer", arch_timer_init);
diff --git a/drivers/clocksource/bcm2835_timer.c b/drivers/clocksource/bcm2835_timer.c
index 50c68fef944b..766611d29945 100644
--- a/drivers/clocksource/bcm2835_timer.c
+++ b/drivers/clocksource/bcm2835_timer.c
@@ -95,23 +95,13 @@ static irqreturn_t bcm2835_time_interrupt(int irq, void *dev_id)
95 } 95 }
96} 96}
97 97
98static struct of_device_id bcm2835_time_match[] __initconst = { 98static void __init bcm2835_timer_init(struct device_node *node)
99 { .compatible = "brcm,bcm2835-system-timer" },
100 {}
101};
102
103static void __init bcm2835_timer_init(void)
104{ 99{
105 struct device_node *node;
106 void __iomem *base; 100 void __iomem *base;
107 u32 freq; 101 u32 freq;
108 int irq; 102 int irq;
109 struct bcm2835_timer *timer; 103 struct bcm2835_timer *timer;
110 104
111 node = of_find_matching_node(NULL, bcm2835_time_match);
112 if (!node)
113 panic("No bcm2835 timer node");
114
115 base = of_iomap(node, 0); 105 base = of_iomap(node, 0);
116 if (!base) 106 if (!base)
117 panic("Can't remap registers"); 107 panic("Can't remap registers");
diff --git a/drivers/clocksource/cadence_ttc_timer.c b/drivers/clocksource/cadence_ttc_timer.c
new file mode 100644
index 000000000000..685bc60e210a
--- /dev/null
+++ b/drivers/clocksource/cadence_ttc_timer.c
@@ -0,0 +1,436 @@
1/*
2 * This file contains driver for the Cadence Triple Timer Counter Rev 06
3 *
4 * Copyright (C) 2011-2013 Xilinx
5 *
6 * based on arch/mips/kernel/time.c timer driver
7 *
8 * This software is licensed under the terms of the GNU General Public
9 * License version 2, as published by the Free Software Foundation, and
10 * may be copied, distributed, and modified under those terms.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 */
17
18#include <linux/clk.h>
19#include <linux/interrupt.h>
20#include <linux/clockchips.h>
21#include <linux/of_address.h>
22#include <linux/of_irq.h>
23#include <linux/slab.h>
24#include <linux/clk-provider.h>
25
26/*
27 * This driver configures the 2 16-bit count-up timers as follows:
28 *
29 * T1: Timer 1, clocksource for generic timekeeping
30 * T2: Timer 2, clockevent source for hrtimers
31 * T3: Timer 3, <unused>
32 *
33 * The input frequency to the timer module for emulation is 2.5MHz which is
34 * common to all the timer channels (T1, T2, and T3). With a pre-scaler of 32,
35 * the timers are clocked at 78.125KHz (12.8 us resolution).
36
37 * The input frequency to the timer module in silicon is configurable and
38 * obtained from device tree. The pre-scaler of 32 is used.
39 */
40
41/*
42 * Timer Register Offset Definitions of Timer 1, Increment base address by 4
43 * and use same offsets for Timer 2
44 */
45#define TTC_CLK_CNTRL_OFFSET 0x00 /* Clock Control Reg, RW */
46#define TTC_CNT_CNTRL_OFFSET 0x0C /* Counter Control Reg, RW */
47#define TTC_COUNT_VAL_OFFSET 0x18 /* Counter Value Reg, RO */
48#define TTC_INTR_VAL_OFFSET 0x24 /* Interval Count Reg, RW */
49#define TTC_ISR_OFFSET 0x54 /* Interrupt Status Reg, RO */
50#define TTC_IER_OFFSET 0x60 /* Interrupt Enable Reg, RW */
51
52#define TTC_CNT_CNTRL_DISABLE_MASK 0x1
53
54/*
55 * Setup the timers to use pre-scaling, using a fixed value for now that will
56 * work across most input frequency, but it may need to be more dynamic
57 */
58#define PRESCALE_EXPONENT 11 /* 2 ^ PRESCALE_EXPONENT = PRESCALE */
59#define PRESCALE 2048 /* The exponent must match this */
60#define CLK_CNTRL_PRESCALE ((PRESCALE_EXPONENT - 1) << 1)
61#define CLK_CNTRL_PRESCALE_EN 1
62#define CNT_CNTRL_RESET (1 << 4)
63
64/**
65 * struct ttc_timer - This definition defines local timer structure
66 *
67 * @base_addr: Base address of timer
68 * @clk: Associated clock source
69 * @clk_rate_change_nb Notifier block for clock rate changes
70 */
71struct ttc_timer {
72 void __iomem *base_addr;
73 struct clk *clk;
74 struct notifier_block clk_rate_change_nb;
75};
76
77#define to_ttc_timer(x) \
78 container_of(x, struct ttc_timer, clk_rate_change_nb)
79
80struct ttc_timer_clocksource {
81 struct ttc_timer ttc;
82 struct clocksource cs;
83};
84
85#define to_ttc_timer_clksrc(x) \
86 container_of(x, struct ttc_timer_clocksource, cs)
87
88struct ttc_timer_clockevent {
89 struct ttc_timer ttc;
90 struct clock_event_device ce;
91};
92
93#define to_ttc_timer_clkevent(x) \
94 container_of(x, struct ttc_timer_clockevent, ce)
95
96/**
97 * ttc_set_interval - Set the timer interval value
98 *
99 * @timer: Pointer to the timer instance
100 * @cycles: Timer interval ticks
101 **/
102static void ttc_set_interval(struct ttc_timer *timer,
103 unsigned long cycles)
104{
105 u32 ctrl_reg;
106
107 /* Disable the counter, set the counter value and re-enable counter */
108 ctrl_reg = __raw_readl(timer->base_addr + TTC_CNT_CNTRL_OFFSET);
109 ctrl_reg |= TTC_CNT_CNTRL_DISABLE_MASK;
110 __raw_writel(ctrl_reg, timer->base_addr + TTC_CNT_CNTRL_OFFSET);
111
112 __raw_writel(cycles, timer->base_addr + TTC_INTR_VAL_OFFSET);
113
114 /*
115 * Reset the counter (0x10) so that it starts from 0, one-shot
116 * mode makes this needed for timing to be right.
117 */
118 ctrl_reg |= CNT_CNTRL_RESET;
119 ctrl_reg &= ~TTC_CNT_CNTRL_DISABLE_MASK;
120 __raw_writel(ctrl_reg, timer->base_addr + TTC_CNT_CNTRL_OFFSET);
121}
122
123/**
124 * ttc_clock_event_interrupt - Clock event timer interrupt handler
125 *
126 * @irq: IRQ number of the Timer
127 * @dev_id: void pointer to the ttc_timer instance
128 *
129 * returns: Always IRQ_HANDLED - success
130 **/
131static irqreturn_t ttc_clock_event_interrupt(int irq, void *dev_id)
132{
133 struct ttc_timer_clockevent *ttce = dev_id;
134 struct ttc_timer *timer = &ttce->ttc;
135
136 /* Acknowledge the interrupt and call event handler */
137 __raw_readl(timer->base_addr + TTC_ISR_OFFSET);
138
139 ttce->ce.event_handler(&ttce->ce);
140
141 return IRQ_HANDLED;
142}
143
144/**
145 * __ttc_clocksource_read - Reads the timer counter register
146 *
147 * returns: Current timer counter register value
148 **/
149static cycle_t __ttc_clocksource_read(struct clocksource *cs)
150{
151 struct ttc_timer *timer = &to_ttc_timer_clksrc(cs)->ttc;
152
153 return (cycle_t)__raw_readl(timer->base_addr +
154 TTC_COUNT_VAL_OFFSET);
155}
156
157/**
158 * ttc_set_next_event - Sets the time interval for next event
159 *
160 * @cycles: Timer interval ticks
161 * @evt: Address of clock event instance
162 *
163 * returns: Always 0 - success
164 **/
165static int ttc_set_next_event(unsigned long cycles,
166 struct clock_event_device *evt)
167{
168 struct ttc_timer_clockevent *ttce = to_ttc_timer_clkevent(evt);
169 struct ttc_timer *timer = &ttce->ttc;
170
171 ttc_set_interval(timer, cycles);
172 return 0;
173}
174
175/**
176 * ttc_set_mode - Sets the mode of timer
177 *
178 * @mode: Mode to be set
179 * @evt: Address of clock event instance
180 **/
181static void ttc_set_mode(enum clock_event_mode mode,
182 struct clock_event_device *evt)
183{
184 struct ttc_timer_clockevent *ttce = to_ttc_timer_clkevent(evt);
185 struct ttc_timer *timer = &ttce->ttc;
186 u32 ctrl_reg;
187
188 switch (mode) {
189 case CLOCK_EVT_MODE_PERIODIC:
190 ttc_set_interval(timer,
191 DIV_ROUND_CLOSEST(clk_get_rate(ttce->ttc.clk),
192 PRESCALE * HZ));
193 break;
194 case CLOCK_EVT_MODE_ONESHOT:
195 case CLOCK_EVT_MODE_UNUSED:
196 case CLOCK_EVT_MODE_SHUTDOWN:
197 ctrl_reg = __raw_readl(timer->base_addr +
198 TTC_CNT_CNTRL_OFFSET);
199 ctrl_reg |= TTC_CNT_CNTRL_DISABLE_MASK;
200 __raw_writel(ctrl_reg,
201 timer->base_addr + TTC_CNT_CNTRL_OFFSET);
202 break;
203 case CLOCK_EVT_MODE_RESUME:
204 ctrl_reg = __raw_readl(timer->base_addr +
205 TTC_CNT_CNTRL_OFFSET);
206 ctrl_reg &= ~TTC_CNT_CNTRL_DISABLE_MASK;
207 __raw_writel(ctrl_reg,
208 timer->base_addr + TTC_CNT_CNTRL_OFFSET);
209 break;
210 }
211}
212
213static int ttc_rate_change_clocksource_cb(struct notifier_block *nb,
214 unsigned long event, void *data)
215{
216 struct clk_notifier_data *ndata = data;
217 struct ttc_timer *ttc = to_ttc_timer(nb);
218 struct ttc_timer_clocksource *ttccs = container_of(ttc,
219 struct ttc_timer_clocksource, ttc);
220
221 switch (event) {
222 case POST_RATE_CHANGE:
223 /*
224 * Do whatever is necessary to maintain a proper time base
225 *
226 * I cannot find a way to adjust the currently used clocksource
227 * to the new frequency. __clocksource_updatefreq_hz() sounds
228 * good, but does not work. Not sure what's that missing.
229 *
230 * This approach works, but triggers two clocksource switches.
231 * The first after unregister to clocksource jiffies. And
232 * another one after the register to the newly registered timer.
233 *
234 * Alternatively we could 'waste' another HW timer to ping pong
235 * between clock sources. That would also use one register and
236 * one unregister call, but only trigger one clocksource switch
237 * for the cost of another HW timer used by the OS.
238 */
239 clocksource_unregister(&ttccs->cs);
240 clocksource_register_hz(&ttccs->cs,
241 ndata->new_rate / PRESCALE);
242 /* fall through */
243 case PRE_RATE_CHANGE:
244 case ABORT_RATE_CHANGE:
245 default:
246 return NOTIFY_DONE;
247 }
248}
249
250static void __init ttc_setup_clocksource(struct clk *clk, void __iomem *base)
251{
252 struct ttc_timer_clocksource *ttccs;
253 int err;
254
255 ttccs = kzalloc(sizeof(*ttccs), GFP_KERNEL);
256 if (WARN_ON(!ttccs))
257 return;
258
259 ttccs->ttc.clk = clk;
260
261 err = clk_prepare_enable(ttccs->ttc.clk);
262 if (WARN_ON(err)) {
263 kfree(ttccs);
264 return;
265 }
266
267 ttccs->ttc.clk_rate_change_nb.notifier_call =
268 ttc_rate_change_clocksource_cb;
269 ttccs->ttc.clk_rate_change_nb.next = NULL;
270 if (clk_notifier_register(ttccs->ttc.clk,
271 &ttccs->ttc.clk_rate_change_nb))
272 pr_warn("Unable to register clock notifier.\n");
273
274 ttccs->ttc.base_addr = base;
275 ttccs->cs.name = "ttc_clocksource";
276 ttccs->cs.rating = 200;
277 ttccs->cs.read = __ttc_clocksource_read;
278 ttccs->cs.mask = CLOCKSOURCE_MASK(16);
279 ttccs->cs.flags = CLOCK_SOURCE_IS_CONTINUOUS;
280
281 /*
282 * Setup the clock source counter to be an incrementing counter
283 * with no interrupt and it rolls over at 0xFFFF. Pre-scale
284 * it by 32 also. Let it start running now.
285 */
286 __raw_writel(0x0, ttccs->ttc.base_addr + TTC_IER_OFFSET);
287 __raw_writel(CLK_CNTRL_PRESCALE | CLK_CNTRL_PRESCALE_EN,
288 ttccs->ttc.base_addr + TTC_CLK_CNTRL_OFFSET);
289 __raw_writel(CNT_CNTRL_RESET,
290 ttccs->ttc.base_addr + TTC_CNT_CNTRL_OFFSET);
291
292 err = clocksource_register_hz(&ttccs->cs,
293 clk_get_rate(ttccs->ttc.clk) / PRESCALE);
294 if (WARN_ON(err)) {
295 kfree(ttccs);
296 return;
297 }
298}
299
300static int ttc_rate_change_clockevent_cb(struct notifier_block *nb,
301 unsigned long event, void *data)
302{
303 struct clk_notifier_data *ndata = data;
304 struct ttc_timer *ttc = to_ttc_timer(nb);
305 struct ttc_timer_clockevent *ttcce = container_of(ttc,
306 struct ttc_timer_clockevent, ttc);
307
308 switch (event) {
309 case POST_RATE_CHANGE:
310 {
311 unsigned long flags;
312
313 /*
314 * clockevents_update_freq should be called with IRQ disabled on
315 * the CPU the timer provides events for. The timer we use is
316 * common to both CPUs, not sure if we need to run on both
317 * cores.
318 */
319 local_irq_save(flags);
320 clockevents_update_freq(&ttcce->ce,
321 ndata->new_rate / PRESCALE);
322 local_irq_restore(flags);
323
324 /* fall through */
325 }
326 case PRE_RATE_CHANGE:
327 case ABORT_RATE_CHANGE:
328 default:
329 return NOTIFY_DONE;
330 }
331}
332
333static void __init ttc_setup_clockevent(struct clk *clk,
334 void __iomem *base, u32 irq)
335{
336 struct ttc_timer_clockevent *ttcce;
337 int err;
338
339 ttcce = kzalloc(sizeof(*ttcce), GFP_KERNEL);
340 if (WARN_ON(!ttcce))
341 return;
342
343 ttcce->ttc.clk = clk;
344
345 err = clk_prepare_enable(ttcce->ttc.clk);
346 if (WARN_ON(err)) {
347 kfree(ttcce);
348 return;
349 }
350
351 ttcce->ttc.clk_rate_change_nb.notifier_call =
352 ttc_rate_change_clockevent_cb;
353 ttcce->ttc.clk_rate_change_nb.next = NULL;
354 if (clk_notifier_register(ttcce->ttc.clk,
355 &ttcce->ttc.clk_rate_change_nb))
356 pr_warn("Unable to register clock notifier.\n");
357
358 ttcce->ttc.base_addr = base;
359 ttcce->ce.name = "ttc_clockevent";
360 ttcce->ce.features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT;
361 ttcce->ce.set_next_event = ttc_set_next_event;
362 ttcce->ce.set_mode = ttc_set_mode;
363 ttcce->ce.rating = 200;
364 ttcce->ce.irq = irq;
365 ttcce->ce.cpumask = cpu_possible_mask;
366
367 /*
368 * Setup the clock event timer to be an interval timer which
369 * is prescaled by 32 using the interval interrupt. Leave it
370 * disabled for now.
371 */
372 __raw_writel(0x23, ttcce->ttc.base_addr + TTC_CNT_CNTRL_OFFSET);
373 __raw_writel(CLK_CNTRL_PRESCALE | CLK_CNTRL_PRESCALE_EN,
374 ttcce->ttc.base_addr + TTC_CLK_CNTRL_OFFSET);
375 __raw_writel(0x1, ttcce->ttc.base_addr + TTC_IER_OFFSET);
376
377 err = request_irq(irq, ttc_clock_event_interrupt,
378 IRQF_DISABLED | IRQF_TIMER,
379 ttcce->ce.name, ttcce);
380 if (WARN_ON(err)) {
381 kfree(ttcce);
382 return;
383 }
384
385 clockevents_config_and_register(&ttcce->ce,
386 clk_get_rate(ttcce->ttc.clk) / PRESCALE, 1, 0xfffe);
387}
388
389/**
390 * ttc_timer_init - Initialize the timer
391 *
392 * Initializes the timer hardware and register the clock source and clock event
393 * timers with Linux kernal timer framework
394 */
395static void __init ttc_timer_init(struct device_node *timer)
396{
397 unsigned int irq;
398 void __iomem *timer_baseaddr;
399 struct clk *clk;
400 static int initialized;
401
402 if (initialized)
403 return;
404
405 initialized = 1;
406
407 /*
408 * Get the 1st Triple Timer Counter (TTC) block from the device tree
409 * and use it. Note that the event timer uses the interrupt and it's the
410 * 2nd TTC hence the irq_of_parse_and_map(,1)
411 */
412 timer_baseaddr = of_iomap(timer, 0);
413 if (!timer_baseaddr) {
414 pr_err("ERROR: invalid timer base address\n");
415 BUG();
416 }
417
418 irq = irq_of_parse_and_map(timer, 1);
419 if (irq <= 0) {
420 pr_err("ERROR: invalid interrupt number\n");
421 BUG();
422 }
423
424 clk = of_clk_get_by_name(timer, "cpu_1x");
425 if (IS_ERR(clk)) {
426 pr_err("ERROR: timer input clock not found\n");
427 BUG();
428 }
429
430 ttc_setup_clocksource(clk, timer_baseaddr);
431 ttc_setup_clockevent(clk, timer_baseaddr + 4, irq);
432
433 pr_info("%s #0 at %p, irq=%d\n", timer->name, timer_baseaddr, irq);
434}
435
436CLOCKSOURCE_OF_DECLARE(ttc, "cdns,ttc", ttc_timer_init);
diff --git a/drivers/clocksource/clksrc-of.c b/drivers/clocksource/clksrc-of.c
index bdabdaa8d00f..37f5325bec95 100644
--- a/drivers/clocksource/clksrc-of.c
+++ b/drivers/clocksource/clksrc-of.c
@@ -16,6 +16,7 @@
16 16
17#include <linux/init.h> 17#include <linux/init.h>
18#include <linux/of.h> 18#include <linux/of.h>
19#include <linux/clocksource.h>
19 20
20extern struct of_device_id __clksrc_of_table[]; 21extern struct of_device_id __clksrc_of_table[];
21 22
@@ -26,10 +27,10 @@ void __init clocksource_of_init(void)
26{ 27{
27 struct device_node *np; 28 struct device_node *np;
28 const struct of_device_id *match; 29 const struct of_device_id *match;
29 void (*init_func)(void); 30 clocksource_of_init_fn init_func;
30 31
31 for_each_matching_node_and_match(np, __clksrc_of_table, &match) { 32 for_each_matching_node_and_match(np, __clksrc_of_table, &match) {
32 init_func = match->data; 33 init_func = match->data;
33 init_func(); 34 init_func(np);
34 } 35 }
35} 36}
diff --git a/drivers/clocksource/em_sti.c b/drivers/clocksource/em_sti.c
index e6a553cb73e8..4329a29a5310 100644
--- a/drivers/clocksource/em_sti.c
+++ b/drivers/clocksource/em_sti.c
@@ -399,7 +399,18 @@ static struct platform_driver em_sti_device_driver = {
399 } 399 }
400}; 400};
401 401
402module_platform_driver(em_sti_device_driver); 402static int __init em_sti_init(void)
403{
404 return platform_driver_register(&em_sti_device_driver);
405}
406
407static void __exit em_sti_exit(void)
408{
409 platform_driver_unregister(&em_sti_device_driver);
410}
411
412subsys_initcall(em_sti_init);
413module_exit(em_sti_exit);
403 414
404MODULE_AUTHOR("Magnus Damm"); 415MODULE_AUTHOR("Magnus Damm");
405MODULE_DESCRIPTION("Renesas Emma Mobile STI Timer Driver"); 416MODULE_DESCRIPTION("Renesas Emma Mobile STI Timer Driver");
diff --git a/drivers/clocksource/exynos_mct.c b/drivers/clocksource/exynos_mct.c
new file mode 100644
index 000000000000..b078d7cbc930
--- /dev/null
+++ b/drivers/clocksource/exynos_mct.c
@@ -0,0 +1,555 @@
1/* linux/arch/arm/mach-exynos4/mct.c
2 *
3 * Copyright (c) 2011 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com
5 *
6 * EXYNOS4 MCT(Multi-Core Timer) support
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11*/
12
13#include <linux/sched.h>
14#include <linux/interrupt.h>
15#include <linux/irq.h>
16#include <linux/err.h>
17#include <linux/clk.h>
18#include <linux/clockchips.h>
19#include <linux/platform_device.h>
20#include <linux/delay.h>
21#include <linux/percpu.h>
22#include <linux/of.h>
23#include <linux/of_irq.h>
24#include <linux/of_address.h>
25#include <linux/clocksource.h>
26
27#include <asm/localtimer.h>
28
29#include <plat/cpu.h>
30
31#include <mach/map.h>
32#include <mach/irqs.h>
33#include <asm/mach/time.h>
34
35#define EXYNOS4_MCTREG(x) (x)
36#define EXYNOS4_MCT_G_CNT_L EXYNOS4_MCTREG(0x100)
37#define EXYNOS4_MCT_G_CNT_U EXYNOS4_MCTREG(0x104)
38#define EXYNOS4_MCT_G_CNT_WSTAT EXYNOS4_MCTREG(0x110)
39#define EXYNOS4_MCT_G_COMP0_L EXYNOS4_MCTREG(0x200)
40#define EXYNOS4_MCT_G_COMP0_U EXYNOS4_MCTREG(0x204)
41#define EXYNOS4_MCT_G_COMP0_ADD_INCR EXYNOS4_MCTREG(0x208)
42#define EXYNOS4_MCT_G_TCON EXYNOS4_MCTREG(0x240)
43#define EXYNOS4_MCT_G_INT_CSTAT EXYNOS4_MCTREG(0x244)
44#define EXYNOS4_MCT_G_INT_ENB EXYNOS4_MCTREG(0x248)
45#define EXYNOS4_MCT_G_WSTAT EXYNOS4_MCTREG(0x24C)
46#define _EXYNOS4_MCT_L_BASE EXYNOS4_MCTREG(0x300)
47#define EXYNOS4_MCT_L_BASE(x) (_EXYNOS4_MCT_L_BASE + (0x100 * x))
48#define EXYNOS4_MCT_L_MASK (0xffffff00)
49
50#define MCT_L_TCNTB_OFFSET (0x00)
51#define MCT_L_ICNTB_OFFSET (0x08)
52#define MCT_L_TCON_OFFSET (0x20)
53#define MCT_L_INT_CSTAT_OFFSET (0x30)
54#define MCT_L_INT_ENB_OFFSET (0x34)
55#define MCT_L_WSTAT_OFFSET (0x40)
56#define MCT_G_TCON_START (1 << 8)
57#define MCT_G_TCON_COMP0_AUTO_INC (1 << 1)
58#define MCT_G_TCON_COMP0_ENABLE (1 << 0)
59#define MCT_L_TCON_INTERVAL_MODE (1 << 2)
60#define MCT_L_TCON_INT_START (1 << 1)
61#define MCT_L_TCON_TIMER_START (1 << 0)
62
63#define TICK_BASE_CNT 1
64
65enum {
66 MCT_INT_SPI,
67 MCT_INT_PPI
68};
69
70enum {
71 MCT_G0_IRQ,
72 MCT_G1_IRQ,
73 MCT_G2_IRQ,
74 MCT_G3_IRQ,
75 MCT_L0_IRQ,
76 MCT_L1_IRQ,
77 MCT_L2_IRQ,
78 MCT_L3_IRQ,
79 MCT_NR_IRQS,
80};
81
82static void __iomem *reg_base;
83static unsigned long clk_rate;
84static unsigned int mct_int_type;
85static int mct_irqs[MCT_NR_IRQS];
86
87struct mct_clock_event_device {
88 struct clock_event_device *evt;
89 unsigned long base;
90 char name[10];
91};
92
93static void exynos4_mct_write(unsigned int value, unsigned long offset)
94{
95 unsigned long stat_addr;
96 u32 mask;
97 u32 i;
98
99 __raw_writel(value, reg_base + offset);
100
101 if (likely(offset >= EXYNOS4_MCT_L_BASE(0))) {
102 stat_addr = (offset & ~EXYNOS4_MCT_L_MASK) + MCT_L_WSTAT_OFFSET;
103 switch (offset & EXYNOS4_MCT_L_MASK) {
104 case MCT_L_TCON_OFFSET:
105 mask = 1 << 3; /* L_TCON write status */
106 break;
107 case MCT_L_ICNTB_OFFSET:
108 mask = 1 << 1; /* L_ICNTB write status */
109 break;
110 case MCT_L_TCNTB_OFFSET:
111 mask = 1 << 0; /* L_TCNTB write status */
112 break;
113 default:
114 return;
115 }
116 } else {
117 switch (offset) {
118 case EXYNOS4_MCT_G_TCON:
119 stat_addr = EXYNOS4_MCT_G_WSTAT;
120 mask = 1 << 16; /* G_TCON write status */
121 break;
122 case EXYNOS4_MCT_G_COMP0_L:
123 stat_addr = EXYNOS4_MCT_G_WSTAT;
124 mask = 1 << 0; /* G_COMP0_L write status */
125 break;
126 case EXYNOS4_MCT_G_COMP0_U:
127 stat_addr = EXYNOS4_MCT_G_WSTAT;
128 mask = 1 << 1; /* G_COMP0_U write status */
129 break;
130 case EXYNOS4_MCT_G_COMP0_ADD_INCR:
131 stat_addr = EXYNOS4_MCT_G_WSTAT;
132 mask = 1 << 2; /* G_COMP0_ADD_INCR w status */
133 break;
134 case EXYNOS4_MCT_G_CNT_L:
135 stat_addr = EXYNOS4_MCT_G_CNT_WSTAT;
136 mask = 1 << 0; /* G_CNT_L write status */
137 break;
138 case EXYNOS4_MCT_G_CNT_U:
139 stat_addr = EXYNOS4_MCT_G_CNT_WSTAT;
140 mask = 1 << 1; /* G_CNT_U write status */
141 break;
142 default:
143 return;
144 }
145 }
146
147 /* Wait maximum 1 ms until written values are applied */
148 for (i = 0; i < loops_per_jiffy / 1000 * HZ; i++)
149 if (__raw_readl(reg_base + stat_addr) & mask) {
150 __raw_writel(mask, reg_base + stat_addr);
151 return;
152 }
153
154 panic("MCT hangs after writing %d (offset:0x%lx)\n", value, offset);
155}
156
157/* Clocksource handling */
158static void exynos4_mct_frc_start(u32 hi, u32 lo)
159{
160 u32 reg;
161
162 exynos4_mct_write(lo, EXYNOS4_MCT_G_CNT_L);
163 exynos4_mct_write(hi, EXYNOS4_MCT_G_CNT_U);
164
165 reg = __raw_readl(reg_base + EXYNOS4_MCT_G_TCON);
166 reg |= MCT_G_TCON_START;
167 exynos4_mct_write(reg, EXYNOS4_MCT_G_TCON);
168}
169
170static cycle_t exynos4_frc_read(struct clocksource *cs)
171{
172 unsigned int lo, hi;
173 u32 hi2 = __raw_readl(reg_base + EXYNOS4_MCT_G_CNT_U);
174
175 do {
176 hi = hi2;
177 lo = __raw_readl(reg_base + EXYNOS4_MCT_G_CNT_L);
178 hi2 = __raw_readl(reg_base + EXYNOS4_MCT_G_CNT_U);
179 } while (hi != hi2);
180
181 return ((cycle_t)hi << 32) | lo;
182}
183
184static void exynos4_frc_resume(struct clocksource *cs)
185{
186 exynos4_mct_frc_start(0, 0);
187}
188
189struct clocksource mct_frc = {
190 .name = "mct-frc",
191 .rating = 400,
192 .read = exynos4_frc_read,
193 .mask = CLOCKSOURCE_MASK(64),
194 .flags = CLOCK_SOURCE_IS_CONTINUOUS,
195 .resume = exynos4_frc_resume,
196};
197
198static void __init exynos4_clocksource_init(void)
199{
200 exynos4_mct_frc_start(0, 0);
201
202 if (clocksource_register_hz(&mct_frc, clk_rate))
203 panic("%s: can't register clocksource\n", mct_frc.name);
204}
205
206static void exynos4_mct_comp0_stop(void)
207{
208 unsigned int tcon;
209
210 tcon = __raw_readl(reg_base + EXYNOS4_MCT_G_TCON);
211 tcon &= ~(MCT_G_TCON_COMP0_ENABLE | MCT_G_TCON_COMP0_AUTO_INC);
212
213 exynos4_mct_write(tcon, EXYNOS4_MCT_G_TCON);
214 exynos4_mct_write(0, EXYNOS4_MCT_G_INT_ENB);
215}
216
217static void exynos4_mct_comp0_start(enum clock_event_mode mode,
218 unsigned long cycles)
219{
220 unsigned int tcon;
221 cycle_t comp_cycle;
222
223 tcon = __raw_readl(reg_base + EXYNOS4_MCT_G_TCON);
224
225 if (mode == CLOCK_EVT_MODE_PERIODIC) {
226 tcon |= MCT_G_TCON_COMP0_AUTO_INC;
227 exynos4_mct_write(cycles, EXYNOS4_MCT_G_COMP0_ADD_INCR);
228 }
229
230 comp_cycle = exynos4_frc_read(&mct_frc) + cycles;
231 exynos4_mct_write((u32)comp_cycle, EXYNOS4_MCT_G_COMP0_L);
232 exynos4_mct_write((u32)(comp_cycle >> 32), EXYNOS4_MCT_G_COMP0_U);
233
234 exynos4_mct_write(0x1, EXYNOS4_MCT_G_INT_ENB);
235
236 tcon |= MCT_G_TCON_COMP0_ENABLE;
237 exynos4_mct_write(tcon , EXYNOS4_MCT_G_TCON);
238}
239
240static int exynos4_comp_set_next_event(unsigned long cycles,
241 struct clock_event_device *evt)
242{
243 exynos4_mct_comp0_start(evt->mode, cycles);
244
245 return 0;
246}
247
248static void exynos4_comp_set_mode(enum clock_event_mode mode,
249 struct clock_event_device *evt)
250{
251 unsigned long cycles_per_jiffy;
252 exynos4_mct_comp0_stop();
253
254 switch (mode) {
255 case CLOCK_EVT_MODE_PERIODIC:
256 cycles_per_jiffy =
257 (((unsigned long long) NSEC_PER_SEC / HZ * evt->mult) >> evt->shift);
258 exynos4_mct_comp0_start(mode, cycles_per_jiffy);
259 break;
260
261 case CLOCK_EVT_MODE_ONESHOT:
262 case CLOCK_EVT_MODE_UNUSED:
263 case CLOCK_EVT_MODE_SHUTDOWN:
264 case CLOCK_EVT_MODE_RESUME:
265 break;
266 }
267}
268
269static struct clock_event_device mct_comp_device = {
270 .name = "mct-comp",
271 .features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT,
272 .rating = 250,
273 .set_next_event = exynos4_comp_set_next_event,
274 .set_mode = exynos4_comp_set_mode,
275};
276
277static irqreturn_t exynos4_mct_comp_isr(int irq, void *dev_id)
278{
279 struct clock_event_device *evt = dev_id;
280
281 exynos4_mct_write(0x1, EXYNOS4_MCT_G_INT_CSTAT);
282
283 evt->event_handler(evt);
284
285 return IRQ_HANDLED;
286}
287
288static struct irqaction mct_comp_event_irq = {
289 .name = "mct_comp_irq",
290 .flags = IRQF_TIMER | IRQF_IRQPOLL,
291 .handler = exynos4_mct_comp_isr,
292 .dev_id = &mct_comp_device,
293};
294
295static void exynos4_clockevent_init(void)
296{
297 mct_comp_device.cpumask = cpumask_of(0);
298 clockevents_config_and_register(&mct_comp_device, clk_rate,
299 0xf, 0xffffffff);
300 setup_irq(mct_irqs[MCT_G0_IRQ], &mct_comp_event_irq);
301}
302
303#ifdef CONFIG_LOCAL_TIMERS
304
305static DEFINE_PER_CPU(struct mct_clock_event_device, percpu_mct_tick);
306
307/* Clock event handling */
308static void exynos4_mct_tick_stop(struct mct_clock_event_device *mevt)
309{
310 unsigned long tmp;
311 unsigned long mask = MCT_L_TCON_INT_START | MCT_L_TCON_TIMER_START;
312 unsigned long offset = mevt->base + MCT_L_TCON_OFFSET;
313
314 tmp = __raw_readl(reg_base + offset);
315 if (tmp & mask) {
316 tmp &= ~mask;
317 exynos4_mct_write(tmp, offset);
318 }
319}
320
321static void exynos4_mct_tick_start(unsigned long cycles,
322 struct mct_clock_event_device *mevt)
323{
324 unsigned long tmp;
325
326 exynos4_mct_tick_stop(mevt);
327
328 tmp = (1 << 31) | cycles; /* MCT_L_UPDATE_ICNTB */
329
330 /* update interrupt count buffer */
331 exynos4_mct_write(tmp, mevt->base + MCT_L_ICNTB_OFFSET);
332
333 /* enable MCT tick interrupt */
334 exynos4_mct_write(0x1, mevt->base + MCT_L_INT_ENB_OFFSET);
335
336 tmp = __raw_readl(reg_base + mevt->base + MCT_L_TCON_OFFSET);
337 tmp |= MCT_L_TCON_INT_START | MCT_L_TCON_TIMER_START |
338 MCT_L_TCON_INTERVAL_MODE;
339 exynos4_mct_write(tmp, mevt->base + MCT_L_TCON_OFFSET);
340}
341
342static int exynos4_tick_set_next_event(unsigned long cycles,
343 struct clock_event_device *evt)
344{
345 struct mct_clock_event_device *mevt = this_cpu_ptr(&percpu_mct_tick);
346
347 exynos4_mct_tick_start(cycles, mevt);
348
349 return 0;
350}
351
352static inline void exynos4_tick_set_mode(enum clock_event_mode mode,
353 struct clock_event_device *evt)
354{
355 struct mct_clock_event_device *mevt = this_cpu_ptr(&percpu_mct_tick);
356 unsigned long cycles_per_jiffy;
357
358 exynos4_mct_tick_stop(mevt);
359
360 switch (mode) {
361 case CLOCK_EVT_MODE_PERIODIC:
362 cycles_per_jiffy =
363 (((unsigned long long) NSEC_PER_SEC / HZ * evt->mult) >> evt->shift);
364 exynos4_mct_tick_start(cycles_per_jiffy, mevt);
365 break;
366
367 case CLOCK_EVT_MODE_ONESHOT:
368 case CLOCK_EVT_MODE_UNUSED:
369 case CLOCK_EVT_MODE_SHUTDOWN:
370 case CLOCK_EVT_MODE_RESUME:
371 break;
372 }
373}
374
375static int exynos4_mct_tick_clear(struct mct_clock_event_device *mevt)
376{
377 struct clock_event_device *evt = mevt->evt;
378
379 /*
380 * This is for supporting oneshot mode.
381 * Mct would generate interrupt periodically
382 * without explicit stopping.
383 */
384 if (evt->mode != CLOCK_EVT_MODE_PERIODIC)
385 exynos4_mct_tick_stop(mevt);
386
387 /* Clear the MCT tick interrupt */
388 if (__raw_readl(reg_base + mevt->base + MCT_L_INT_CSTAT_OFFSET) & 1) {
389 exynos4_mct_write(0x1, mevt->base + MCT_L_INT_CSTAT_OFFSET);
390 return 1;
391 } else {
392 return 0;
393 }
394}
395
396static irqreturn_t exynos4_mct_tick_isr(int irq, void *dev_id)
397{
398 struct mct_clock_event_device *mevt = dev_id;
399 struct clock_event_device *evt = mevt->evt;
400
401 exynos4_mct_tick_clear(mevt);
402
403 evt->event_handler(evt);
404
405 return IRQ_HANDLED;
406}
407
408static struct irqaction mct_tick0_event_irq = {
409 .name = "mct_tick0_irq",
410 .flags = IRQF_TIMER | IRQF_NOBALANCING,
411 .handler = exynos4_mct_tick_isr,
412};
413
414static struct irqaction mct_tick1_event_irq = {
415 .name = "mct_tick1_irq",
416 .flags = IRQF_TIMER | IRQF_NOBALANCING,
417 .handler = exynos4_mct_tick_isr,
418};
419
420static int __cpuinit exynos4_local_timer_setup(struct clock_event_device *evt)
421{
422 struct mct_clock_event_device *mevt;
423 unsigned int cpu = smp_processor_id();
424
425 mevt = this_cpu_ptr(&percpu_mct_tick);
426 mevt->evt = evt;
427
428 mevt->base = EXYNOS4_MCT_L_BASE(cpu);
429 sprintf(mevt->name, "mct_tick%d", cpu);
430
431 evt->name = mevt->name;
432 evt->cpumask = cpumask_of(cpu);
433 evt->set_next_event = exynos4_tick_set_next_event;
434 evt->set_mode = exynos4_tick_set_mode;
435 evt->features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT;
436 evt->rating = 450;
437 clockevents_config_and_register(evt, clk_rate / (TICK_BASE_CNT + 1),
438 0xf, 0x7fffffff);
439
440 exynos4_mct_write(TICK_BASE_CNT, mevt->base + MCT_L_TCNTB_OFFSET);
441
442 if (mct_int_type == MCT_INT_SPI) {
443 if (cpu == 0) {
444 mct_tick0_event_irq.dev_id = mevt;
445 evt->irq = mct_irqs[MCT_L0_IRQ];
446 setup_irq(evt->irq, &mct_tick0_event_irq);
447 } else {
448 mct_tick1_event_irq.dev_id = mevt;
449 evt->irq = mct_irqs[MCT_L1_IRQ];
450 setup_irq(evt->irq, &mct_tick1_event_irq);
451 irq_set_affinity(evt->irq, cpumask_of(1));
452 }
453 } else {
454 enable_percpu_irq(mct_irqs[MCT_L0_IRQ], 0);
455 }
456
457 return 0;
458}
459
460static void exynos4_local_timer_stop(struct clock_event_device *evt)
461{
462 unsigned int cpu = smp_processor_id();
463 evt->set_mode(CLOCK_EVT_MODE_UNUSED, evt);
464 if (mct_int_type == MCT_INT_SPI)
465 if (cpu == 0)
466 remove_irq(evt->irq, &mct_tick0_event_irq);
467 else
468 remove_irq(evt->irq, &mct_tick1_event_irq);
469 else
470 disable_percpu_irq(mct_irqs[MCT_L0_IRQ]);
471}
472
473static struct local_timer_ops exynos4_mct_tick_ops __cpuinitdata = {
474 .setup = exynos4_local_timer_setup,
475 .stop = exynos4_local_timer_stop,
476};
477#endif /* CONFIG_LOCAL_TIMERS */
478
479static void __init exynos4_timer_resources(void __iomem *base)
480{
481 struct clk *mct_clk;
482 mct_clk = clk_get(NULL, "xtal");
483
484 clk_rate = clk_get_rate(mct_clk);
485
486 reg_base = base;
487 if (!reg_base)
488 panic("%s: unable to ioremap mct address space\n", __func__);
489
490#ifdef CONFIG_LOCAL_TIMERS
491 if (mct_int_type == MCT_INT_PPI) {
492 int err;
493
494 err = request_percpu_irq(mct_irqs[MCT_L0_IRQ],
495 exynos4_mct_tick_isr, "MCT",
496 &percpu_mct_tick);
497 WARN(err, "MCT: can't request IRQ %d (%d)\n",
498 mct_irqs[MCT_L0_IRQ], err);
499 }
500
501 local_timer_register(&exynos4_mct_tick_ops);
502#endif /* CONFIG_LOCAL_TIMERS */
503}
504
505void __init mct_init(void)
506{
507 if (soc_is_exynos4210()) {
508 mct_irqs[MCT_G0_IRQ] = EXYNOS4_IRQ_MCT_G0;
509 mct_irqs[MCT_L0_IRQ] = EXYNOS4_IRQ_MCT_L0;
510 mct_irqs[MCT_L1_IRQ] = EXYNOS4_IRQ_MCT_L1;
511 mct_int_type = MCT_INT_SPI;
512 } else {
513 panic("unable to determine mct controller type\n");
514 }
515
516 exynos4_timer_resources(S5P_VA_SYSTIMER);
517 exynos4_clocksource_init();
518 exynos4_clockevent_init();
519}
520
521static void __init mct_init_dt(struct device_node *np, unsigned int int_type)
522{
523 u32 nr_irqs, i;
524
525 mct_int_type = int_type;
526
527 /* This driver uses only one global timer interrupt */
528 mct_irqs[MCT_G0_IRQ] = irq_of_parse_and_map(np, MCT_G0_IRQ);
529
530 /*
531 * Find out the number of local irqs specified. The local
532 * timer irqs are specified after the four global timer
533 * irqs are specified.
534 */
535 nr_irqs = of_irq_count(np);
536 for (i = MCT_L0_IRQ; i < nr_irqs; i++)
537 mct_irqs[i] = irq_of_parse_and_map(np, i);
538
539 exynos4_timer_resources(of_iomap(np, 0));
540 exynos4_clocksource_init();
541 exynos4_clockevent_init();
542}
543
544
545static void __init mct_init_spi(struct device_node *np)
546{
547 return mct_init_dt(np, MCT_INT_SPI);
548}
549
550static void __init mct_init_ppi(struct device_node *np)
551{
552 return mct_init_dt(np, MCT_INT_PPI);
553}
554CLOCKSOURCE_OF_DECLARE(exynos4210, "samsung,exynos4210-mct", mct_init_spi);
555CLOCKSOURCE_OF_DECLARE(exynos4412, "samsung,exynos4412-mct", mct_init_ppi);
diff --git a/drivers/clocksource/sh_cmt.c b/drivers/clocksource/sh_cmt.c
index 488c14cc8dbf..08d0c418c94a 100644
--- a/drivers/clocksource/sh_cmt.c
+++ b/drivers/clocksource/sh_cmt.c
@@ -54,62 +54,100 @@ struct sh_cmt_priv {
54 struct clocksource cs; 54 struct clocksource cs;
55 unsigned long total_cycles; 55 unsigned long total_cycles;
56 bool cs_enabled; 56 bool cs_enabled;
57
58 /* callbacks for CMSTR and CMCSR access */
59 unsigned long (*read_control)(void __iomem *base, unsigned long offs);
60 void (*write_control)(void __iomem *base, unsigned long offs,
61 unsigned long value);
62
63 /* callbacks for CMCNT and CMCOR access */
64 unsigned long (*read_count)(void __iomem *base, unsigned long offs);
65 void (*write_count)(void __iomem *base, unsigned long offs,
66 unsigned long value);
57}; 67};
58 68
59static DEFINE_RAW_SPINLOCK(sh_cmt_lock); 69/* Examples of supported CMT timer register layouts and I/O access widths:
70 *
71 * "16-bit counter and 16-bit control" as found on sh7263:
72 * CMSTR 0xfffec000 16-bit
73 * CMCSR 0xfffec002 16-bit
74 * CMCNT 0xfffec004 16-bit
75 * CMCOR 0xfffec006 16-bit
76 *
77 * "32-bit counter and 16-bit control" as found on sh7372, sh73a0, r8a7740:
78 * CMSTR 0xffca0000 16-bit
79 * CMCSR 0xffca0060 16-bit
80 * CMCNT 0xffca0064 32-bit
81 * CMCOR 0xffca0068 32-bit
82 */
83
84static unsigned long sh_cmt_read16(void __iomem *base, unsigned long offs)
85{
86 return ioread16(base + (offs << 1));
87}
88
89static unsigned long sh_cmt_read32(void __iomem *base, unsigned long offs)
90{
91 return ioread32(base + (offs << 2));
92}
93
94static void sh_cmt_write16(void __iomem *base, unsigned long offs,
95 unsigned long value)
96{
97 iowrite16(value, base + (offs << 1));
98}
99
100static void sh_cmt_write32(void __iomem *base, unsigned long offs,
101 unsigned long value)
102{
103 iowrite32(value, base + (offs << 2));
104}
60 105
61#define CMSTR -1 /* shared register */
62#define CMCSR 0 /* channel register */ 106#define CMCSR 0 /* channel register */
63#define CMCNT 1 /* channel register */ 107#define CMCNT 1 /* channel register */
64#define CMCOR 2 /* channel register */ 108#define CMCOR 2 /* channel register */
65 109
66static inline unsigned long sh_cmt_read(struct sh_cmt_priv *p, int reg_nr) 110static inline unsigned long sh_cmt_read_cmstr(struct sh_cmt_priv *p)
67{ 111{
68 struct sh_timer_config *cfg = p->pdev->dev.platform_data; 112 struct sh_timer_config *cfg = p->pdev->dev.platform_data;
69 void __iomem *base = p->mapbase;
70 unsigned long offs;
71
72 if (reg_nr == CMSTR) {
73 offs = 0;
74 base -= cfg->channel_offset;
75 } else
76 offs = reg_nr;
77
78 if (p->width == 16)
79 offs <<= 1;
80 else {
81 offs <<= 2;
82 if ((reg_nr == CMCNT) || (reg_nr == CMCOR))
83 return ioread32(base + offs);
84 }
85 113
86 return ioread16(base + offs); 114 return p->read_control(p->mapbase - cfg->channel_offset, 0);
87} 115}
88 116
89static inline void sh_cmt_write(struct sh_cmt_priv *p, int reg_nr, 117static inline unsigned long sh_cmt_read_cmcsr(struct sh_cmt_priv *p)
90 unsigned long value) 118{
119 return p->read_control(p->mapbase, CMCSR);
120}
121
122static inline unsigned long sh_cmt_read_cmcnt(struct sh_cmt_priv *p)
123{
124 return p->read_count(p->mapbase, CMCNT);
125}
126
127static inline void sh_cmt_write_cmstr(struct sh_cmt_priv *p,
128 unsigned long value)
91{ 129{
92 struct sh_timer_config *cfg = p->pdev->dev.platform_data; 130 struct sh_timer_config *cfg = p->pdev->dev.platform_data;
93 void __iomem *base = p->mapbase;
94 unsigned long offs;
95
96 if (reg_nr == CMSTR) {
97 offs = 0;
98 base -= cfg->channel_offset;
99 } else
100 offs = reg_nr;
101
102 if (p->width == 16)
103 offs <<= 1;
104 else {
105 offs <<= 2;
106 if ((reg_nr == CMCNT) || (reg_nr == CMCOR)) {
107 iowrite32(value, base + offs);
108 return;
109 }
110 }
111 131
112 iowrite16(value, base + offs); 132 p->write_control(p->mapbase - cfg->channel_offset, 0, value);
133}
134
135static inline void sh_cmt_write_cmcsr(struct sh_cmt_priv *p,
136 unsigned long value)
137{
138 p->write_control(p->mapbase, CMCSR, value);
139}
140
141static inline void sh_cmt_write_cmcnt(struct sh_cmt_priv *p,
142 unsigned long value)
143{
144 p->write_count(p->mapbase, CMCNT, value);
145}
146
147static inline void sh_cmt_write_cmcor(struct sh_cmt_priv *p,
148 unsigned long value)
149{
150 p->write_count(p->mapbase, CMCOR, value);
113} 151}
114 152
115static unsigned long sh_cmt_get_counter(struct sh_cmt_priv *p, 153static unsigned long sh_cmt_get_counter(struct sh_cmt_priv *p,
@@ -118,15 +156,15 @@ static unsigned long sh_cmt_get_counter(struct sh_cmt_priv *p,
118 unsigned long v1, v2, v3; 156 unsigned long v1, v2, v3;
119 int o1, o2; 157 int o1, o2;
120 158
121 o1 = sh_cmt_read(p, CMCSR) & p->overflow_bit; 159 o1 = sh_cmt_read_cmcsr(p) & p->overflow_bit;
122 160
123 /* Make sure the timer value is stable. Stolen from acpi_pm.c */ 161 /* Make sure the timer value is stable. Stolen from acpi_pm.c */
124 do { 162 do {
125 o2 = o1; 163 o2 = o1;
126 v1 = sh_cmt_read(p, CMCNT); 164 v1 = sh_cmt_read_cmcnt(p);
127 v2 = sh_cmt_read(p, CMCNT); 165 v2 = sh_cmt_read_cmcnt(p);
128 v3 = sh_cmt_read(p, CMCNT); 166 v3 = sh_cmt_read_cmcnt(p);
129 o1 = sh_cmt_read(p, CMCSR) & p->overflow_bit; 167 o1 = sh_cmt_read_cmcsr(p) & p->overflow_bit;
130 } while (unlikely((o1 != o2) || (v1 > v2 && v1 < v3) 168 } while (unlikely((o1 != o2) || (v1 > v2 && v1 < v3)
131 || (v2 > v3 && v2 < v1) || (v3 > v1 && v3 < v2))); 169 || (v2 > v3 && v2 < v1) || (v3 > v1 && v3 < v2)));
132 170
@@ -134,6 +172,7 @@ static unsigned long sh_cmt_get_counter(struct sh_cmt_priv *p,
134 return v2; 172 return v2;
135} 173}
136 174
175static DEFINE_RAW_SPINLOCK(sh_cmt_lock);
137 176
138static void sh_cmt_start_stop_ch(struct sh_cmt_priv *p, int start) 177static void sh_cmt_start_stop_ch(struct sh_cmt_priv *p, int start)
139{ 178{
@@ -142,14 +181,14 @@ static void sh_cmt_start_stop_ch(struct sh_cmt_priv *p, int start)
142 181
143 /* start stop register shared by multiple timer channels */ 182 /* start stop register shared by multiple timer channels */
144 raw_spin_lock_irqsave(&sh_cmt_lock, flags); 183 raw_spin_lock_irqsave(&sh_cmt_lock, flags);
145 value = sh_cmt_read(p, CMSTR); 184 value = sh_cmt_read_cmstr(p);
146 185
147 if (start) 186 if (start)
148 value |= 1 << cfg->timer_bit; 187 value |= 1 << cfg->timer_bit;
149 else 188 else
150 value &= ~(1 << cfg->timer_bit); 189 value &= ~(1 << cfg->timer_bit);
151 190
152 sh_cmt_write(p, CMSTR, value); 191 sh_cmt_write_cmstr(p, value);
153 raw_spin_unlock_irqrestore(&sh_cmt_lock, flags); 192 raw_spin_unlock_irqrestore(&sh_cmt_lock, flags);
154} 193}
155 194
@@ -173,14 +212,14 @@ static int sh_cmt_enable(struct sh_cmt_priv *p, unsigned long *rate)
173 /* configure channel, periodic mode and maximum timeout */ 212 /* configure channel, periodic mode and maximum timeout */
174 if (p->width == 16) { 213 if (p->width == 16) {
175 *rate = clk_get_rate(p->clk) / 512; 214 *rate = clk_get_rate(p->clk) / 512;
176 sh_cmt_write(p, CMCSR, 0x43); 215 sh_cmt_write_cmcsr(p, 0x43);
177 } else { 216 } else {
178 *rate = clk_get_rate(p->clk) / 8; 217 *rate = clk_get_rate(p->clk) / 8;
179 sh_cmt_write(p, CMCSR, 0x01a4); 218 sh_cmt_write_cmcsr(p, 0x01a4);
180 } 219 }
181 220
182 sh_cmt_write(p, CMCOR, 0xffffffff); 221 sh_cmt_write_cmcor(p, 0xffffffff);
183 sh_cmt_write(p, CMCNT, 0); 222 sh_cmt_write_cmcnt(p, 0);
184 223
185 /* 224 /*
186 * According to the sh73a0 user's manual, as CMCNT can be operated 225 * According to the sh73a0 user's manual, as CMCNT can be operated
@@ -194,12 +233,12 @@ static int sh_cmt_enable(struct sh_cmt_priv *p, unsigned long *rate)
194 * take RCLKx2 at maximum. 233 * take RCLKx2 at maximum.
195 */ 234 */
196 for (k = 0; k < 100; k++) { 235 for (k = 0; k < 100; k++) {
197 if (!sh_cmt_read(p, CMCNT)) 236 if (!sh_cmt_read_cmcnt(p))
198 break; 237 break;
199 udelay(1); 238 udelay(1);
200 } 239 }
201 240
202 if (sh_cmt_read(p, CMCNT)) { 241 if (sh_cmt_read_cmcnt(p)) {
203 dev_err(&p->pdev->dev, "cannot clear CMCNT\n"); 242 dev_err(&p->pdev->dev, "cannot clear CMCNT\n");
204 ret = -ETIMEDOUT; 243 ret = -ETIMEDOUT;
205 goto err1; 244 goto err1;
@@ -222,7 +261,7 @@ static void sh_cmt_disable(struct sh_cmt_priv *p)
222 sh_cmt_start_stop_ch(p, 0); 261 sh_cmt_start_stop_ch(p, 0);
223 262
224 /* disable interrupts in CMT block */ 263 /* disable interrupts in CMT block */
225 sh_cmt_write(p, CMCSR, 0); 264 sh_cmt_write_cmcsr(p, 0);
226 265
227 /* stop clock */ 266 /* stop clock */
228 clk_disable(p->clk); 267 clk_disable(p->clk);
@@ -270,7 +309,7 @@ static void sh_cmt_clock_event_program_verify(struct sh_cmt_priv *p,
270 if (new_match > p->max_match_value) 309 if (new_match > p->max_match_value)
271 new_match = p->max_match_value; 310 new_match = p->max_match_value;
272 311
273 sh_cmt_write(p, CMCOR, new_match); 312 sh_cmt_write_cmcor(p, new_match);
274 313
275 now = sh_cmt_get_counter(p, &has_wrapped); 314 now = sh_cmt_get_counter(p, &has_wrapped);
276 if (has_wrapped && (new_match > p->match_value)) { 315 if (has_wrapped && (new_match > p->match_value)) {
@@ -346,7 +385,7 @@ static irqreturn_t sh_cmt_interrupt(int irq, void *dev_id)
346 struct sh_cmt_priv *p = dev_id; 385 struct sh_cmt_priv *p = dev_id;
347 386
348 /* clear flags */ 387 /* clear flags */
349 sh_cmt_write(p, CMCSR, sh_cmt_read(p, CMCSR) & p->clear_bits); 388 sh_cmt_write_cmcsr(p, sh_cmt_read_cmcsr(p) & p->clear_bits);
350 389
351 /* update clock source counter to begin with if enabled 390 /* update clock source counter to begin with if enabled
352 * the wrap flag should be cleared by the timer specific 391 * the wrap flag should be cleared by the timer specific
@@ -625,14 +664,6 @@ static int sh_cmt_register(struct sh_cmt_priv *p, char *name,
625 unsigned long clockevent_rating, 664 unsigned long clockevent_rating,
626 unsigned long clocksource_rating) 665 unsigned long clocksource_rating)
627{ 666{
628 if (p->width == (sizeof(p->max_match_value) * 8))
629 p->max_match_value = ~0;
630 else
631 p->max_match_value = (1 << p->width) - 1;
632
633 p->match_value = p->max_match_value;
634 raw_spin_lock_init(&p->lock);
635
636 if (clockevent_rating) 667 if (clockevent_rating)
637 sh_cmt_register_clockevent(p, name, clockevent_rating); 668 sh_cmt_register_clockevent(p, name, clockevent_rating);
638 669
@@ -657,8 +688,6 @@ static int sh_cmt_setup(struct sh_cmt_priv *p, struct platform_device *pdev)
657 goto err0; 688 goto err0;
658 } 689 }
659 690
660 platform_set_drvdata(pdev, p);
661
662 res = platform_get_resource(p->pdev, IORESOURCE_MEM, 0); 691 res = platform_get_resource(p->pdev, IORESOURCE_MEM, 0);
663 if (!res) { 692 if (!res) {
664 dev_err(&p->pdev->dev, "failed to get I/O memory\n"); 693 dev_err(&p->pdev->dev, "failed to get I/O memory\n");
@@ -693,32 +722,51 @@ static int sh_cmt_setup(struct sh_cmt_priv *p, struct platform_device *pdev)
693 goto err1; 722 goto err1;
694 } 723 }
695 724
725 p->read_control = sh_cmt_read16;
726 p->write_control = sh_cmt_write16;
727
696 if (resource_size(res) == 6) { 728 if (resource_size(res) == 6) {
697 p->width = 16; 729 p->width = 16;
730 p->read_count = sh_cmt_read16;
731 p->write_count = sh_cmt_write16;
698 p->overflow_bit = 0x80; 732 p->overflow_bit = 0x80;
699 p->clear_bits = ~0x80; 733 p->clear_bits = ~0x80;
700 } else { 734 } else {
701 p->width = 32; 735 p->width = 32;
736 p->read_count = sh_cmt_read32;
737 p->write_count = sh_cmt_write32;
702 p->overflow_bit = 0x8000; 738 p->overflow_bit = 0x8000;
703 p->clear_bits = ~0xc000; 739 p->clear_bits = ~0xc000;
704 } 740 }
705 741
742 if (p->width == (sizeof(p->max_match_value) * 8))
743 p->max_match_value = ~0;
744 else
745 p->max_match_value = (1 << p->width) - 1;
746
747 p->match_value = p->max_match_value;
748 raw_spin_lock_init(&p->lock);
749
706 ret = sh_cmt_register(p, (char *)dev_name(&p->pdev->dev), 750 ret = sh_cmt_register(p, (char *)dev_name(&p->pdev->dev),
707 cfg->clockevent_rating, 751 cfg->clockevent_rating,
708 cfg->clocksource_rating); 752 cfg->clocksource_rating);
709 if (ret) { 753 if (ret) {
710 dev_err(&p->pdev->dev, "registration failed\n"); 754 dev_err(&p->pdev->dev, "registration failed\n");
711 goto err1; 755 goto err2;
712 } 756 }
713 p->cs_enabled = false; 757 p->cs_enabled = false;
714 758
715 ret = setup_irq(irq, &p->irqaction); 759 ret = setup_irq(irq, &p->irqaction);
716 if (ret) { 760 if (ret) {
717 dev_err(&p->pdev->dev, "failed to request irq %d\n", irq); 761 dev_err(&p->pdev->dev, "failed to request irq %d\n", irq);
718 goto err1; 762 goto err2;
719 } 763 }
720 764
765 platform_set_drvdata(pdev, p);
766
721 return 0; 767 return 0;
768err2:
769 clk_put(p->clk);
722 770
723err1: 771err1:
724 iounmap(p->mapbase); 772 iounmap(p->mapbase);
@@ -751,7 +799,6 @@ static int sh_cmt_probe(struct platform_device *pdev)
751 ret = sh_cmt_setup(p, pdev); 799 ret = sh_cmt_setup(p, pdev);
752 if (ret) { 800 if (ret) {
753 kfree(p); 801 kfree(p);
754 platform_set_drvdata(pdev, NULL);
755 pm_runtime_idle(&pdev->dev); 802 pm_runtime_idle(&pdev->dev);
756 return ret; 803 return ret;
757 } 804 }
@@ -791,7 +838,7 @@ static void __exit sh_cmt_exit(void)
791} 838}
792 839
793early_platform_init("earlytimer", &sh_cmt_device_driver); 840early_platform_init("earlytimer", &sh_cmt_device_driver);
794module_init(sh_cmt_init); 841subsys_initcall(sh_cmt_init);
795module_exit(sh_cmt_exit); 842module_exit(sh_cmt_exit);
796 843
797MODULE_AUTHOR("Magnus Damm"); 844MODULE_AUTHOR("Magnus Damm");
diff --git a/drivers/clocksource/sh_mtu2.c b/drivers/clocksource/sh_mtu2.c
index 83943e27cfac..4aac9ee0d0c0 100644
--- a/drivers/clocksource/sh_mtu2.c
+++ b/drivers/clocksource/sh_mtu2.c
@@ -386,7 +386,7 @@ static void __exit sh_mtu2_exit(void)
386} 386}
387 387
388early_platform_init("earlytimer", &sh_mtu2_device_driver); 388early_platform_init("earlytimer", &sh_mtu2_device_driver);
389module_init(sh_mtu2_init); 389subsys_initcall(sh_mtu2_init);
390module_exit(sh_mtu2_exit); 390module_exit(sh_mtu2_exit);
391 391
392MODULE_AUTHOR("Magnus Damm"); 392MODULE_AUTHOR("Magnus Damm");
diff --git a/drivers/clocksource/sh_tmu.c b/drivers/clocksource/sh_tmu.c
index b4502edce2a1..78b8dae49628 100644
--- a/drivers/clocksource/sh_tmu.c
+++ b/drivers/clocksource/sh_tmu.c
@@ -549,7 +549,7 @@ static void __exit sh_tmu_exit(void)
549} 549}
550 550
551early_platform_init("earlytimer", &sh_tmu_device_driver); 551early_platform_init("earlytimer", &sh_tmu_device_driver);
552module_init(sh_tmu_init); 552subsys_initcall(sh_tmu_init);
553module_exit(sh_tmu_exit); 553module_exit(sh_tmu_exit);
554 554
555MODULE_AUTHOR("Magnus Damm"); 555MODULE_AUTHOR("Magnus Damm");
diff --git a/drivers/clocksource/sunxi_timer.c b/drivers/clocksource/sunxi_timer.c
index 4086b9167159..0ce85e29769b 100644
--- a/drivers/clocksource/sunxi_timer.c
+++ b/drivers/clocksource/sunxi_timer.c
@@ -23,7 +23,7 @@
23#include <linux/of_address.h> 23#include <linux/of_address.h>
24#include <linux/of_irq.h> 24#include <linux/of_irq.h>
25#include <linux/sunxi_timer.h> 25#include <linux/sunxi_timer.h>
26#include <linux/clk-provider.h> 26#include <linux/clk/sunxi.h>
27 27
28#define TIMER_CTL_REG 0x00 28#define TIMER_CTL_REG 0x00
29#define TIMER_CTL_ENABLE (1 << 0) 29#define TIMER_CTL_ENABLE (1 << 0)
@@ -123,7 +123,7 @@ void __init sunxi_timer_init(void)
123 if (irq <= 0) 123 if (irq <= 0)
124 panic("Can't parse IRQ"); 124 panic("Can't parse IRQ");
125 125
126 of_clk_init(NULL); 126 sunxi_init_clocks();
127 127
128 clk = of_clk_get(node, 0); 128 clk = of_clk_get(node, 0);
129 if (IS_ERR(clk)) 129 if (IS_ERR(clk))
diff --git a/drivers/clocksource/tegra20_timer.c b/drivers/clocksource/tegra20_timer.c
index 0bde03feb095..ae877b021b54 100644
--- a/drivers/clocksource/tegra20_timer.c
+++ b/drivers/clocksource/tegra20_timer.c
@@ -154,29 +154,12 @@ static struct irqaction tegra_timer_irq = {
154 .dev_id = &tegra_clockevent, 154 .dev_id = &tegra_clockevent,
155}; 155};
156 156
157static const struct of_device_id timer_match[] __initconst = { 157static void __init tegra20_init_timer(struct device_node *np)
158 { .compatible = "nvidia,tegra20-timer" },
159 {}
160};
161
162static const struct of_device_id rtc_match[] __initconst = {
163 { .compatible = "nvidia,tegra20-rtc" },
164 {}
165};
166
167static void __init tegra20_init_timer(void)
168{ 158{
169 struct device_node *np;
170 struct clk *clk; 159 struct clk *clk;
171 unsigned long rate; 160 unsigned long rate;
172 int ret; 161 int ret;
173 162
174 np = of_find_matching_node(NULL, timer_match);
175 if (!np) {
176 pr_err("Failed to find timer DT node\n");
177 BUG();
178 }
179
180 timer_reg_base = of_iomap(np, 0); 163 timer_reg_base = of_iomap(np, 0);
181 if (!timer_reg_base) { 164 if (!timer_reg_base) {
182 pr_err("Can't map timer registers\n"); 165 pr_err("Can't map timer registers\n");
@@ -189,7 +172,7 @@ static void __init tegra20_init_timer(void)
189 BUG(); 172 BUG();
190 } 173 }
191 174
192 clk = clk_get_sys("timer", NULL); 175 clk = of_clk_get(np, 0);
193 if (IS_ERR(clk)) { 176 if (IS_ERR(clk)) {
194 pr_warn("Unable to get timer clock. Assuming 12Mhz input clock.\n"); 177 pr_warn("Unable to get timer clock. Assuming 12Mhz input clock.\n");
195 rate = 12000000; 178 rate = 12000000;
@@ -200,30 +183,6 @@ static void __init tegra20_init_timer(void)
200 183
201 of_node_put(np); 184 of_node_put(np);
202 185
203 np = of_find_matching_node(NULL, rtc_match);
204 if (!np) {
205 pr_err("Failed to find RTC DT node\n");
206 BUG();
207 }
208
209 rtc_base = of_iomap(np, 0);
210 if (!rtc_base) {
211 pr_err("Can't map RTC registers");
212 BUG();
213 }
214
215 /*
216 * rtc registers are used by read_persistent_clock, keep the rtc clock
217 * enabled
218 */
219 clk = clk_get_sys("rtc-tegra", NULL);
220 if (IS_ERR(clk))
221 pr_warn("Unable to get rtc-tegra clock\n");
222 else
223 clk_prepare_enable(clk);
224
225 of_node_put(np);
226
227 switch (rate) { 186 switch (rate) {
228 case 12000000: 187 case 12000000:
229 timer_writel(0x000b, TIMERUS_USEC_CFG); 188 timer_writel(0x000b, TIMERUS_USEC_CFG);
@@ -259,12 +218,34 @@ static void __init tegra20_init_timer(void)
259 tegra_clockevent.irq = tegra_timer_irq.irq; 218 tegra_clockevent.irq = tegra_timer_irq.irq;
260 clockevents_config_and_register(&tegra_clockevent, 1000000, 219 clockevents_config_and_register(&tegra_clockevent, 1000000,
261 0x1, 0x1fffffff); 220 0x1, 0x1fffffff);
262#ifdef CONFIG_HAVE_ARM_TWD 221}
263 twd_local_timer_of_register(); 222CLOCKSOURCE_OF_DECLARE(tegra20_timer, "nvidia,tegra20-timer", tegra20_init_timer);
264#endif 223
224static void __init tegra20_init_rtc(struct device_node *np)
225{
226 struct clk *clk;
227
228 rtc_base = of_iomap(np, 0);
229 if (!rtc_base) {
230 pr_err("Can't map RTC registers");
231 BUG();
232 }
233
234 /*
235 * rtc registers are used by read_persistent_clock, keep the rtc clock
236 * enabled
237 */
238 clk = of_clk_get(np, 0);
239 if (IS_ERR(clk))
240 pr_warn("Unable to get rtc-tegra clock\n");
241 else
242 clk_prepare_enable(clk);
243
244 of_node_put(np);
245
265 register_persistent_clock(NULL, tegra_read_persistent_clock); 246 register_persistent_clock(NULL, tegra_read_persistent_clock);
266} 247}
267CLOCKSOURCE_OF_DECLARE(tegra20, "nvidia,tegra20-timer", tegra20_init_timer); 248CLOCKSOURCE_OF_DECLARE(tegra20_rtc, "nvidia,tegra20-rtc", tegra20_init_rtc);
268 249
269#ifdef CONFIG_PM 250#ifdef CONFIG_PM
270static u32 usec_config; 251static u32 usec_config;
diff --git a/drivers/clocksource/vt8500_timer.c b/drivers/clocksource/vt8500_timer.c
index 8efc86b5b5dd..64f553f04fa4 100644
--- a/drivers/clocksource/vt8500_timer.c
+++ b/drivers/clocksource/vt8500_timer.c
@@ -129,22 +129,10 @@ static struct irqaction irq = {
129 .dev_id = &clockevent, 129 .dev_id = &clockevent,
130}; 130};
131 131
132static struct of_device_id vt8500_timer_ids[] = { 132static void __init vt8500_timer_init(struct device_node *np)
133 { .compatible = "via,vt8500-timer" },
134 { }
135};
136
137static void __init vt8500_timer_init(void)
138{ 133{
139 struct device_node *np;
140 int timer_irq; 134 int timer_irq;
141 135
142 np = of_find_matching_node(NULL, vt8500_timer_ids);
143 if (!np) {
144 pr_err("%s: Timer description missing from Device Tree\n",
145 __func__);
146 return;
147 }
148 regbase = of_iomap(np, 0); 136 regbase = of_iomap(np, 0);
149 if (!regbase) { 137 if (!regbase) {
150 pr_err("%s: Missing iobase description in Device Tree\n", 138 pr_err("%s: Missing iobase description in Device Tree\n",
@@ -177,4 +165,4 @@ static void __init vt8500_timer_init(void)
177 4, 0xf0000000); 165 4, 0xf0000000);
178} 166}
179 167
180CLOCKSOURCE_OF_DECLARE(vt8500, "via,vt8500-timer", vt8500_timer_init) 168CLOCKSOURCE_OF_DECLARE(vt8500, "via,vt8500-timer", vt8500_timer_init);
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index 93aaadf99f28..b166e30b3bc4 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -227,12 +227,6 @@ config GPIO_TS5500
227 blocks of the TS-5500: DIO1, DIO2 and the LCD port, and the TS-5600 227 blocks of the TS-5500: DIO1, DIO2 and the LCD port, and the TS-5600
228 LCD port. 228 LCD port.
229 229
230config GPIO_VT8500
231 bool "VIA/Wondermedia SoC GPIO Support"
232 depends on ARCH_VT8500
233 help
234 Say yes here to support the VT8500/WM8505/WM8650 GPIO controller.
235
236config GPIO_XILINX 230config GPIO_XILINX
237 bool "Xilinx GPIO support" 231 bool "Xilinx GPIO support"
238 depends on PPC_OF || MICROBLAZE 232 depends on PPC_OF || MICROBLAZE
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index 22e07bc9fcb5..a274d7df3c8c 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -80,7 +80,6 @@ obj-$(CONFIG_GPIO_TWL6040) += gpio-twl6040.o
80obj-$(CONFIG_GPIO_UCB1400) += gpio-ucb1400.o 80obj-$(CONFIG_GPIO_UCB1400) += gpio-ucb1400.o
81obj-$(CONFIG_GPIO_VIPERBOARD) += gpio-viperboard.o 81obj-$(CONFIG_GPIO_VIPERBOARD) += gpio-viperboard.o
82obj-$(CONFIG_GPIO_VR41XX) += gpio-vr41xx.o 82obj-$(CONFIG_GPIO_VR41XX) += gpio-vr41xx.o
83obj-$(CONFIG_GPIO_VT8500) += gpio-vt8500.o
84obj-$(CONFIG_GPIO_VX855) += gpio-vx855.o 83obj-$(CONFIG_GPIO_VX855) += gpio-vx855.o
85obj-$(CONFIG_GPIO_WM831X) += gpio-wm831x.o 84obj-$(CONFIG_GPIO_WM831X) += gpio-wm831x.o
86obj-$(CONFIG_GPIO_WM8350) += gpio-wm8350.o 85obj-$(CONFIG_GPIO_WM8350) += gpio-wm8350.o
diff --git a/drivers/gpio/gpio-samsung.c b/drivers/gpio/gpio-samsung.c
index b3643ff007e4..99e0fa49fcbd 100644
--- a/drivers/gpio/gpio-samsung.c
+++ b/drivers/gpio/gpio-samsung.c
@@ -1122,8 +1122,12 @@ int samsung_gpiolib_to_irq(struct gpio_chip *chip, unsigned int offset)
1122#ifdef CONFIG_PLAT_S3C24XX 1122#ifdef CONFIG_PLAT_S3C24XX
1123static int s3c24xx_gpiolib_fbank_to_irq(struct gpio_chip *chip, unsigned offset) 1123static int s3c24xx_gpiolib_fbank_to_irq(struct gpio_chip *chip, unsigned offset)
1124{ 1124{
1125 if (offset < 4) 1125 if (offset < 4) {
1126 return IRQ_EINT0 + offset; 1126 if (soc_is_s3c2412())
1127 return IRQ_EINT0_2412 + offset;
1128 else
1129 return IRQ_EINT0 + offset;
1130 }
1127 1131
1128 if (offset < 8) 1132 if (offset < 8)
1129 return IRQ_EINT4 + offset - 4; 1133 return IRQ_EINT4 + offset - 4;
@@ -3024,6 +3028,7 @@ static __init int samsung_gpiolib_init(void)
3024 static const struct of_device_id exynos_pinctrl_ids[] = { 3028 static const struct of_device_id exynos_pinctrl_ids[] = {
3025 { .compatible = "samsung,exynos4210-pinctrl", }, 3029 { .compatible = "samsung,exynos4210-pinctrl", },
3026 { .compatible = "samsung,exynos4x12-pinctrl", }, 3030 { .compatible = "samsung,exynos4x12-pinctrl", },
3031 { .compatible = "samsung,exynos5250-pinctrl", },
3027 { .compatible = "samsung,exynos5440-pinctrl", }, 3032 { .compatible = "samsung,exynos5440-pinctrl", },
3028 }; 3033 };
3029 for_each_matching_node(pctrl_np, exynos_pinctrl_ids) 3034 for_each_matching_node(pctrl_np, exynos_pinctrl_ids)
diff --git a/drivers/gpio/gpio-tegra.c b/drivers/gpio/gpio-tegra.c
index 414ad912232f..e3956359202c 100644
--- a/drivers/gpio/gpio-tegra.c
+++ b/drivers/gpio/gpio-tegra.c
@@ -72,6 +72,7 @@ struct tegra_gpio_bank {
72 u32 oe[4]; 72 u32 oe[4];
73 u32 int_enb[4]; 73 u32 int_enb[4];
74 u32 int_lvl[4]; 74 u32 int_lvl[4];
75 u32 wake_enb[4];
75#endif 76#endif
76}; 77};
77 78
@@ -333,15 +334,31 @@ static int tegra_gpio_suspend(struct device *dev)
333 bank->oe[p] = tegra_gpio_readl(GPIO_OE(gpio)); 334 bank->oe[p] = tegra_gpio_readl(GPIO_OE(gpio));
334 bank->int_enb[p] = tegra_gpio_readl(GPIO_INT_ENB(gpio)); 335 bank->int_enb[p] = tegra_gpio_readl(GPIO_INT_ENB(gpio));
335 bank->int_lvl[p] = tegra_gpio_readl(GPIO_INT_LVL(gpio)); 336 bank->int_lvl[p] = tegra_gpio_readl(GPIO_INT_LVL(gpio));
337
338 /* Enable gpio irq for wake up source */
339 tegra_gpio_writel(bank->wake_enb[p],
340 GPIO_INT_ENB(gpio));
336 } 341 }
337 } 342 }
338 local_irq_restore(flags); 343 local_irq_restore(flags);
339 return 0; 344 return 0;
340} 345}
341 346
342static int tegra_gpio_wake_enable(struct irq_data *d, unsigned int enable) 347static int tegra_gpio_irq_set_wake(struct irq_data *d, unsigned int enable)
343{ 348{
344 struct tegra_gpio_bank *bank = irq_data_get_irq_chip_data(d); 349 struct tegra_gpio_bank *bank = irq_data_get_irq_chip_data(d);
350 int gpio = d->hwirq;
351 u32 port, bit, mask;
352
353 port = GPIO_PORT(gpio);
354 bit = GPIO_BIT(gpio);
355 mask = BIT(bit);
356
357 if (enable)
358 bank->wake_enb[port] |= mask;
359 else
360 bank->wake_enb[port] &= ~mask;
361
345 return irq_set_irq_wake(bank->irq, enable); 362 return irq_set_irq_wake(bank->irq, enable);
346} 363}
347#endif 364#endif
@@ -353,7 +370,7 @@ static struct irq_chip tegra_gpio_irq_chip = {
353 .irq_unmask = tegra_gpio_irq_unmask, 370 .irq_unmask = tegra_gpio_irq_unmask,
354 .irq_set_type = tegra_gpio_irq_set_type, 371 .irq_set_type = tegra_gpio_irq_set_type,
355#ifdef CONFIG_PM_SLEEP 372#ifdef CONFIG_PM_SLEEP
356 .irq_set_wake = tegra_gpio_wake_enable, 373 .irq_set_wake = tegra_gpio_irq_set_wake,
357#endif 374#endif
358}; 375};
359 376
diff --git a/drivers/gpio/gpio-vt8500.c b/drivers/gpio/gpio-vt8500.c
deleted file mode 100644
index 81683ca35ac1..000000000000
--- a/drivers/gpio/gpio-vt8500.c
+++ /dev/null
@@ -1,355 +0,0 @@
1/* drivers/gpio/gpio-vt8500.c
2 *
3 * Copyright (C) 2012 Tony Prisk <linux@prisktech.co.nz>
4 * Based on arch/arm/mach-vt8500/gpio.c:
5 * - Copyright (C) 2010 Alexey Charkov <alchark@gmail.com>
6 *
7 * This software is licensed under the terms of the GNU General Public
8 * License version 2, as published by the Free Software Foundation, and
9 * may be copied, distributed, and modified under those terms.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 */
17
18#include <linux/module.h>
19#include <linux/err.h>
20#include <linux/io.h>
21#include <linux/gpio.h>
22#include <linux/platform_device.h>
23#include <linux/bitops.h>
24#include <linux/of.h>
25#include <linux/of_address.h>
26#include <linux/of_irq.h>
27#include <linux/of_device.h>
28
29/*
30 We handle GPIOs by bank, each bank containing up to 32 GPIOs covered
31 by one set of registers (although not all may be valid).
32
33 Because different SoC's have different register offsets, we pass the
34 register offsets as data in vt8500_gpio_dt_ids[].
35
36 A value of NO_REG is used to indicate that this register is not
37 supported. Only used for ->en at the moment.
38*/
39
40#define NO_REG 0xFFFF
41
42/*
43 * struct vt8500_gpio_bank_regoffsets
44 * @en: offset to enable register of the bank
45 * @dir: offset to direction register of the bank
46 * @data_out: offset to the data out register of the bank
47 * @data_in: offset to the data in register of the bank
48 * @ngpio: highest valid pin in this bank
49 */
50
51struct vt8500_gpio_bank_regoffsets {
52 unsigned int en;
53 unsigned int dir;
54 unsigned int data_out;
55 unsigned int data_in;
56 unsigned char ngpio;
57};
58
59struct vt8500_gpio_data {
60 unsigned int num_banks;
61 struct vt8500_gpio_bank_regoffsets banks[];
62};
63
64#define VT8500_BANK(__en, __dir, __out, __in, __ngpio) \
65{ \
66 .en = __en, \
67 .dir = __dir, \
68 .data_out = __out, \
69 .data_in = __in, \
70 .ngpio = __ngpio, \
71}
72
73static struct vt8500_gpio_data vt8500_data = {
74 .num_banks = 7,
75 .banks = {
76 VT8500_BANK(NO_REG, 0x3C, 0x5C, 0x7C, 9),
77 VT8500_BANK(0x00, 0x20, 0x40, 0x60, 26),
78 VT8500_BANK(0x04, 0x24, 0x44, 0x64, 28),
79 VT8500_BANK(0x08, 0x28, 0x48, 0x68, 31),
80 VT8500_BANK(0x0C, 0x2C, 0x4C, 0x6C, 19),
81 VT8500_BANK(0x10, 0x30, 0x50, 0x70, 19),
82 VT8500_BANK(0x14, 0x34, 0x54, 0x74, 23),
83 },
84};
85
86static struct vt8500_gpio_data wm8505_data = {
87 .num_banks = 10,
88 .banks = {
89 VT8500_BANK(0x64, 0x8C, 0xB4, 0xDC, 22),
90 VT8500_BANK(0x40, 0x68, 0x90, 0xB8, 8),
91 VT8500_BANK(0x44, 0x6C, 0x94, 0xBC, 32),
92 VT8500_BANK(0x48, 0x70, 0x98, 0xC0, 6),
93 VT8500_BANK(0x4C, 0x74, 0x9C, 0xC4, 16),
94 VT8500_BANK(0x50, 0x78, 0xA0, 0xC8, 25),
95 VT8500_BANK(0x54, 0x7C, 0xA4, 0xCC, 5),
96 VT8500_BANK(0x58, 0x80, 0xA8, 0xD0, 5),
97 VT8500_BANK(0x5C, 0x84, 0xAC, 0xD4, 12),
98 VT8500_BANK(0x60, 0x88, 0xB0, 0xD8, 16),
99 VT8500_BANK(0x500, 0x504, 0x508, 0x50C, 6),
100 },
101};
102
103/*
104 * No information about which bits are valid so we just make
105 * them all available until its figured out.
106 */
107static struct vt8500_gpio_data wm8650_data = {
108 .num_banks = 9,
109 .banks = {
110 VT8500_BANK(0x40, 0x80, 0xC0, 0x00, 32),
111 VT8500_BANK(0x44, 0x84, 0xC4, 0x04, 32),
112 VT8500_BANK(0x48, 0x88, 0xC8, 0x08, 32),
113 VT8500_BANK(0x4C, 0x8C, 0xCC, 0x0C, 32),
114 VT8500_BANK(0x50, 0x90, 0xD0, 0x10, 32),
115 VT8500_BANK(0x54, 0x94, 0xD4, 0x14, 32),
116 VT8500_BANK(0x58, 0x98, 0xD8, 0x18, 32),
117 VT8500_BANK(0x5C, 0x9C, 0xDC, 0x1C, 32),
118 VT8500_BANK(0x7C, 0xBC, 0xFC, 0x3C, 32),
119 VT8500_BANK(0x500, 0x504, 0x508, 0x50C, 6),
120 },
121};
122
123struct vt8500_gpio_chip {
124 struct gpio_chip chip;
125
126 const struct vt8500_gpio_bank_regoffsets *regs;
127 void __iomem *base;
128};
129
130struct vt8500_data {
131 struct vt8500_gpio_chip *chip;
132 void __iomem *iobase;
133 int num_banks;
134};
135
136
137#define to_vt8500(__chip) container_of(__chip, struct vt8500_gpio_chip, chip)
138
139static int vt8500_gpio_request(struct gpio_chip *chip, unsigned offset)
140{
141 u32 val;
142 struct vt8500_gpio_chip *vt8500_chip = to_vt8500(chip);
143
144 if (vt8500_chip->regs->en == NO_REG)
145 return 0;
146
147 val = readl_relaxed(vt8500_chip->base + vt8500_chip->regs->en);
148 val |= BIT(offset);
149 writel_relaxed(val, vt8500_chip->base + vt8500_chip->regs->en);
150
151 return 0;
152}
153
154static void vt8500_gpio_free(struct gpio_chip *chip, unsigned offset)
155{
156 struct vt8500_gpio_chip *vt8500_chip = to_vt8500(chip);
157 u32 val;
158
159 if (vt8500_chip->regs->en == NO_REG)
160 return;
161
162 val = readl_relaxed(vt8500_chip->base + vt8500_chip->regs->en);
163 val &= ~BIT(offset);
164 writel_relaxed(val, vt8500_chip->base + vt8500_chip->regs->en);
165}
166
167static int vt8500_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
168{
169 struct vt8500_gpio_chip *vt8500_chip = to_vt8500(chip);
170
171 u32 val = readl_relaxed(vt8500_chip->base + vt8500_chip->regs->dir);
172 val &= ~BIT(offset);
173 writel_relaxed(val, vt8500_chip->base + vt8500_chip->regs->dir);
174
175 return 0;
176}
177
178static int vt8500_gpio_direction_output(struct gpio_chip *chip, unsigned offset,
179 int value)
180{
181 struct vt8500_gpio_chip *vt8500_chip = to_vt8500(chip);
182
183 u32 val = readl_relaxed(vt8500_chip->base + vt8500_chip->regs->dir);
184 val |= BIT(offset);
185 writel_relaxed(val, vt8500_chip->base + vt8500_chip->regs->dir);
186
187 if (value) {
188 val = readl_relaxed(vt8500_chip->base +
189 vt8500_chip->regs->data_out);
190 val |= BIT(offset);
191 writel_relaxed(val, vt8500_chip->base +
192 vt8500_chip->regs->data_out);
193 }
194 return 0;
195}
196
197static int vt8500_gpio_get_value(struct gpio_chip *chip, unsigned offset)
198{
199 struct vt8500_gpio_chip *vt8500_chip = to_vt8500(chip);
200
201 return (readl_relaxed(vt8500_chip->base + vt8500_chip->regs->data_in) >>
202 offset) & 1;
203}
204
205static void vt8500_gpio_set_value(struct gpio_chip *chip, unsigned offset,
206 int value)
207{
208 struct vt8500_gpio_chip *vt8500_chip = to_vt8500(chip);
209
210 u32 val = readl_relaxed(vt8500_chip->base +
211 vt8500_chip->regs->data_out);
212 if (value)
213 val |= BIT(offset);
214 else
215 val &= ~BIT(offset);
216
217 writel_relaxed(val, vt8500_chip->base + vt8500_chip->regs->data_out);
218}
219
220static int vt8500_of_xlate(struct gpio_chip *gc,
221 const struct of_phandle_args *gpiospec, u32 *flags)
222{
223 /* bank if specificed in gpiospec->args[0] */
224 if (flags)
225 *flags = gpiospec->args[2];
226
227 return gpiospec->args[1];
228}
229
230static int vt8500_add_chips(struct platform_device *pdev, void __iomem *base,
231 const struct vt8500_gpio_data *data)
232{
233 struct vt8500_data *priv;
234 struct vt8500_gpio_chip *vtchip;
235 struct gpio_chip *chip;
236 int i;
237 int pin_cnt = 0;
238
239 priv = devm_kzalloc(&pdev->dev, sizeof(struct vt8500_data), GFP_KERNEL);
240 if (!priv) {
241 dev_err(&pdev->dev, "failed to allocate memory\n");
242 return -ENOMEM;
243 }
244
245 priv->chip = devm_kzalloc(&pdev->dev,
246 sizeof(struct vt8500_gpio_chip) * data->num_banks,
247 GFP_KERNEL);
248 if (!priv->chip) {
249 dev_err(&pdev->dev, "failed to allocate chip memory\n");
250 return -ENOMEM;
251 }
252
253 priv->iobase = base;
254 priv->num_banks = data->num_banks;
255 platform_set_drvdata(pdev, priv);
256
257 vtchip = priv->chip;
258
259 for (i = 0; i < data->num_banks; i++) {
260 vtchip[i].base = base;
261 vtchip[i].regs = &data->banks[i];
262
263 chip = &vtchip[i].chip;
264
265 chip->of_xlate = vt8500_of_xlate;
266 chip->of_gpio_n_cells = 3;
267 chip->of_node = pdev->dev.of_node;
268
269 chip->request = vt8500_gpio_request;
270 chip->free = vt8500_gpio_free;
271 chip->direction_input = vt8500_gpio_direction_input;
272 chip->direction_output = vt8500_gpio_direction_output;
273 chip->get = vt8500_gpio_get_value;
274 chip->set = vt8500_gpio_set_value;
275 chip->can_sleep = 0;
276 chip->base = pin_cnt;
277 chip->ngpio = data->banks[i].ngpio;
278
279 pin_cnt += data->banks[i].ngpio;
280
281 gpiochip_add(chip);
282 }
283 return 0;
284}
285
286static struct of_device_id vt8500_gpio_dt_ids[] = {
287 { .compatible = "via,vt8500-gpio", .data = &vt8500_data, },
288 { .compatible = "wm,wm8505-gpio", .data = &wm8505_data, },
289 { .compatible = "wm,wm8650-gpio", .data = &wm8650_data, },
290 { /* Sentinel */ },
291};
292
293static int vt8500_gpio_probe(struct platform_device *pdev)
294{
295 int ret;
296 void __iomem *gpio_base;
297 struct resource *res;
298 const struct of_device_id *of_id =
299 of_match_device(vt8500_gpio_dt_ids, &pdev->dev);
300
301 if (!of_id) {
302 dev_err(&pdev->dev, "No matching driver data\n");
303 return -ENODEV;
304 }
305
306 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
307 if (!res) {
308 dev_err(&pdev->dev, "Unable to get IO resource\n");
309 return -ENODEV;
310 }
311
312 gpio_base = devm_request_and_ioremap(&pdev->dev, res);
313 if (!gpio_base) {
314 dev_err(&pdev->dev, "Unable to map GPIO registers\n");
315 return -ENOMEM;
316 }
317
318 ret = vt8500_add_chips(pdev, gpio_base, of_id->data);
319
320 return ret;
321}
322
323static int vt8500_gpio_remove(struct platform_device *pdev)
324{
325 int i;
326 int ret;
327 struct vt8500_data *priv = platform_get_drvdata(pdev);
328 struct vt8500_gpio_chip *vtchip = priv->chip;
329
330 for (i = 0; i < priv->num_banks; i++) {
331 ret = gpiochip_remove(&vtchip[i].chip);
332 if (ret)
333 dev_warn(&pdev->dev, "gpiochip_remove returned %d\n",
334 ret);
335 }
336
337 return 0;
338}
339
340static struct platform_driver vt8500_gpio_driver = {
341 .probe = vt8500_gpio_probe,
342 .remove = vt8500_gpio_remove,
343 .driver = {
344 .name = "vt8500-gpio",
345 .owner = THIS_MODULE,
346 .of_match_table = vt8500_gpio_dt_ids,
347 },
348};
349
350module_platform_driver(vt8500_gpio_driver);
351
352MODULE_DESCRIPTION("VT8500 GPIO Driver");
353MODULE_AUTHOR("Tony Prisk <linux@prisktech.co.nz>");
354MODULE_LICENSE("GPL v2");
355MODULE_DEVICE_TABLE(of, vt8500_gpio_dt_ids);
diff --git a/drivers/irqchip/Kconfig b/drivers/irqchip/Kconfig
index a350969e5efe..4a33351c25dc 100644
--- a/drivers/irqchip/Kconfig
+++ b/drivers/irqchip/Kconfig
@@ -25,6 +25,14 @@ config ARM_VIC_NR
25 The maximum number of VICs available in the system, for 25 The maximum number of VICs available in the system, for
26 power management. 26 power management.
27 27
28config RENESAS_INTC_IRQPIN
29 bool
30 select IRQ_DOMAIN
31
32config RENESAS_IRQC
33 bool
34 select IRQ_DOMAIN
35
28config VERSATILE_FPGA_IRQ 36config VERSATILE_FPGA_IRQ
29 bool 37 bool
30 select IRQ_DOMAIN 38 select IRQ_DOMAIN
diff --git a/drivers/irqchip/Makefile b/drivers/irqchip/Makefile
index dae27a77c1e1..154722aa26cb 100644
--- a/drivers/irqchip/Makefile
+++ b/drivers/irqchip/Makefile
@@ -3,10 +3,13 @@ obj-$(CONFIG_IRQCHIP) += irqchip.o
3obj-$(CONFIG_ARCH_BCM2835) += irq-bcm2835.o 3obj-$(CONFIG_ARCH_BCM2835) += irq-bcm2835.o
4obj-$(CONFIG_ARCH_EXYNOS) += exynos-combiner.o 4obj-$(CONFIG_ARCH_EXYNOS) += exynos-combiner.o
5obj-$(CONFIG_ARCH_MVEBU) += irq-armada-370-xp.o 5obj-$(CONFIG_ARCH_MVEBU) += irq-armada-370-xp.o
6obj-$(CONFIG_ARCH_S3C24XX) += irq-s3c24xx.o
6obj-$(CONFIG_METAG) += irq-metag-ext.o 7obj-$(CONFIG_METAG) += irq-metag-ext.o
7obj-$(CONFIG_METAG_PERFCOUNTER_IRQS) += irq-metag.o 8obj-$(CONFIG_METAG_PERFCOUNTER_IRQS) += irq-metag.o
8obj-$(CONFIG_ARCH_SUNXI) += irq-sunxi.o 9obj-$(CONFIG_ARCH_SUNXI) += irq-sunxi.o
9obj-$(CONFIG_ARCH_SPEAR3XX) += spear-shirq.o 10obj-$(CONFIG_ARCH_SPEAR3XX) += spear-shirq.o
10obj-$(CONFIG_ARM_GIC) += irq-gic.o 11obj-$(CONFIG_ARM_GIC) += irq-gic.o
11obj-$(CONFIG_ARM_VIC) += irq-vic.o 12obj-$(CONFIG_ARM_VIC) += irq-vic.o
13obj-$(CONFIG_RENESAS_INTC_IRQPIN) += irq-renesas-intc-irqpin.o
14obj-$(CONFIG_RENESAS_IRQC) += irq-renesas-irqc.o
12obj-$(CONFIG_VERSATILE_FPGA_IRQ) += irq-versatile-fpga.o 15obj-$(CONFIG_VERSATILE_FPGA_IRQ) += irq-versatile-fpga.o
diff --git a/drivers/irqchip/irq-renesas-intc-irqpin.c b/drivers/irqchip/irq-renesas-intc-irqpin.c
new file mode 100644
index 000000000000..5a68e5accec1
--- /dev/null
+++ b/drivers/irqchip/irq-renesas-intc-irqpin.c
@@ -0,0 +1,547 @@
1/*
2 * Renesas INTC External IRQ Pin Driver
3 *
4 * Copyright (C) 2013 Magnus Damm
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20#include <linux/init.h>
21#include <linux/platform_device.h>
22#include <linux/spinlock.h>
23#include <linux/interrupt.h>
24#include <linux/ioport.h>
25#include <linux/io.h>
26#include <linux/irq.h>
27#include <linux/irqdomain.h>
28#include <linux/err.h>
29#include <linux/slab.h>
30#include <linux/module.h>
31#include <linux/platform_data/irq-renesas-intc-irqpin.h>
32
33#define INTC_IRQPIN_MAX 8 /* maximum 8 interrupts per driver instance */
34
35#define INTC_IRQPIN_REG_SENSE 0 /* ICRn */
36#define INTC_IRQPIN_REG_PRIO 1 /* INTPRInn */
37#define INTC_IRQPIN_REG_SOURCE 2 /* INTREQnn */
38#define INTC_IRQPIN_REG_MASK 3 /* INTMSKnn */
39#define INTC_IRQPIN_REG_CLEAR 4 /* INTMSKCLRnn */
40#define INTC_IRQPIN_REG_NR 5
41
42/* INTC external IRQ PIN hardware register access:
43 *
44 * SENSE is read-write 32-bit with 2-bits or 4-bits per IRQ (*)
45 * PRIO is read-write 32-bit with 4-bits per IRQ (**)
46 * SOURCE is read-only 32-bit or 8-bit with 1-bit per IRQ (***)
47 * MASK is write-only 32-bit or 8-bit with 1-bit per IRQ (***)
48 * CLEAR is write-only 32-bit or 8-bit with 1-bit per IRQ (***)
49 *
50 * (*) May be accessed by more than one driver instance - lock needed
51 * (**) Read-modify-write access by one driver instance - lock needed
52 * (***) Accessed by one driver instance only - no locking needed
53 */
54
55struct intc_irqpin_iomem {
56 void __iomem *iomem;
57 unsigned long (*read)(void __iomem *iomem);
58 void (*write)(void __iomem *iomem, unsigned long data);
59 int width;
60};
61
62struct intc_irqpin_irq {
63 int hw_irq;
64 int requested_irq;
65 int domain_irq;
66 struct intc_irqpin_priv *p;
67};
68
69struct intc_irqpin_priv {
70 struct intc_irqpin_iomem iomem[INTC_IRQPIN_REG_NR];
71 struct intc_irqpin_irq irq[INTC_IRQPIN_MAX];
72 struct renesas_intc_irqpin_config config;
73 unsigned int number_of_irqs;
74 struct platform_device *pdev;
75 struct irq_chip irq_chip;
76 struct irq_domain *irq_domain;
77 bool shared_irqs;
78 u8 shared_irq_mask;
79};
80
81static unsigned long intc_irqpin_read32(void __iomem *iomem)
82{
83 return ioread32(iomem);
84}
85
86static unsigned long intc_irqpin_read8(void __iomem *iomem)
87{
88 return ioread8(iomem);
89}
90
91static void intc_irqpin_write32(void __iomem *iomem, unsigned long data)
92{
93 iowrite32(data, iomem);
94}
95
96static void intc_irqpin_write8(void __iomem *iomem, unsigned long data)
97{
98 iowrite8(data, iomem);
99}
100
101static inline unsigned long intc_irqpin_read(struct intc_irqpin_priv *p,
102 int reg)
103{
104 struct intc_irqpin_iomem *i = &p->iomem[reg];
105
106 return i->read(i->iomem);
107}
108
109static inline void intc_irqpin_write(struct intc_irqpin_priv *p,
110 int reg, unsigned long data)
111{
112 struct intc_irqpin_iomem *i = &p->iomem[reg];
113
114 i->write(i->iomem, data);
115}
116
117static inline unsigned long intc_irqpin_hwirq_mask(struct intc_irqpin_priv *p,
118 int reg, int hw_irq)
119{
120 return BIT((p->iomem[reg].width - 1) - hw_irq);
121}
122
123static inline void intc_irqpin_irq_write_hwirq(struct intc_irqpin_priv *p,
124 int reg, int hw_irq)
125{
126 intc_irqpin_write(p, reg, intc_irqpin_hwirq_mask(p, reg, hw_irq));
127}
128
129static DEFINE_RAW_SPINLOCK(intc_irqpin_lock); /* only used by slow path */
130
131static void intc_irqpin_read_modify_write(struct intc_irqpin_priv *p,
132 int reg, int shift,
133 int width, int value)
134{
135 unsigned long flags;
136 unsigned long tmp;
137
138 raw_spin_lock_irqsave(&intc_irqpin_lock, flags);
139
140 tmp = intc_irqpin_read(p, reg);
141 tmp &= ~(((1 << width) - 1) << shift);
142 tmp |= value << shift;
143 intc_irqpin_write(p, reg, tmp);
144
145 raw_spin_unlock_irqrestore(&intc_irqpin_lock, flags);
146}
147
148static void intc_irqpin_mask_unmask_prio(struct intc_irqpin_priv *p,
149 int irq, int do_mask)
150{
151 int bitfield_width = 4; /* PRIO assumed to have fixed bitfield width */
152 int shift = (7 - irq) * bitfield_width; /* PRIO assumed to be 32-bit */
153
154 intc_irqpin_read_modify_write(p, INTC_IRQPIN_REG_PRIO,
155 shift, bitfield_width,
156 do_mask ? 0 : (1 << bitfield_width) - 1);
157}
158
159static int intc_irqpin_set_sense(struct intc_irqpin_priv *p, int irq, int value)
160{
161 int bitfield_width = p->config.sense_bitfield_width;
162 int shift = (7 - irq) * bitfield_width; /* SENSE assumed to be 32-bit */
163
164 dev_dbg(&p->pdev->dev, "sense irq = %d, mode = %d\n", irq, value);
165
166 if (value >= (1 << bitfield_width))
167 return -EINVAL;
168
169 intc_irqpin_read_modify_write(p, INTC_IRQPIN_REG_SENSE, shift,
170 bitfield_width, value);
171 return 0;
172}
173
174static void intc_irqpin_dbg(struct intc_irqpin_irq *i, char *str)
175{
176 dev_dbg(&i->p->pdev->dev, "%s (%d:%d:%d)\n",
177 str, i->requested_irq, i->hw_irq, i->domain_irq);
178}
179
180static void intc_irqpin_irq_enable(struct irq_data *d)
181{
182 struct intc_irqpin_priv *p = irq_data_get_irq_chip_data(d);
183 int hw_irq = irqd_to_hwirq(d);
184
185 intc_irqpin_dbg(&p->irq[hw_irq], "enable");
186 intc_irqpin_irq_write_hwirq(p, INTC_IRQPIN_REG_CLEAR, hw_irq);
187}
188
189static void intc_irqpin_irq_disable(struct irq_data *d)
190{
191 struct intc_irqpin_priv *p = irq_data_get_irq_chip_data(d);
192 int hw_irq = irqd_to_hwirq(d);
193
194 intc_irqpin_dbg(&p->irq[hw_irq], "disable");
195 intc_irqpin_irq_write_hwirq(p, INTC_IRQPIN_REG_MASK, hw_irq);
196}
197
198static void intc_irqpin_shared_irq_enable(struct irq_data *d)
199{
200 struct intc_irqpin_priv *p = irq_data_get_irq_chip_data(d);
201 int hw_irq = irqd_to_hwirq(d);
202
203 intc_irqpin_dbg(&p->irq[hw_irq], "shared enable");
204 intc_irqpin_irq_write_hwirq(p, INTC_IRQPIN_REG_CLEAR, hw_irq);
205
206 p->shared_irq_mask &= ~BIT(hw_irq);
207}
208
209static void intc_irqpin_shared_irq_disable(struct irq_data *d)
210{
211 struct intc_irqpin_priv *p = irq_data_get_irq_chip_data(d);
212 int hw_irq = irqd_to_hwirq(d);
213
214 intc_irqpin_dbg(&p->irq[hw_irq], "shared disable");
215 intc_irqpin_irq_write_hwirq(p, INTC_IRQPIN_REG_MASK, hw_irq);
216
217 p->shared_irq_mask |= BIT(hw_irq);
218}
219
220static void intc_irqpin_irq_enable_force(struct irq_data *d)
221{
222 struct intc_irqpin_priv *p = irq_data_get_irq_chip_data(d);
223 int irq = p->irq[irqd_to_hwirq(d)].requested_irq;
224
225 intc_irqpin_irq_enable(d);
226
227 /* enable interrupt through parent interrupt controller,
228 * assumes non-shared interrupt with 1:1 mapping
229 * needed for busted IRQs on some SoCs like sh73a0
230 */
231 irq_get_chip(irq)->irq_unmask(irq_get_irq_data(irq));
232}
233
234static void intc_irqpin_irq_disable_force(struct irq_data *d)
235{
236 struct intc_irqpin_priv *p = irq_data_get_irq_chip_data(d);
237 int irq = p->irq[irqd_to_hwirq(d)].requested_irq;
238
239 /* disable interrupt through parent interrupt controller,
240 * assumes non-shared interrupt with 1:1 mapping
241 * needed for busted IRQs on some SoCs like sh73a0
242 */
243 irq_get_chip(irq)->irq_mask(irq_get_irq_data(irq));
244 intc_irqpin_irq_disable(d);
245}
246
247#define INTC_IRQ_SENSE_VALID 0x10
248#define INTC_IRQ_SENSE(x) (x + INTC_IRQ_SENSE_VALID)
249
250static unsigned char intc_irqpin_sense[IRQ_TYPE_SENSE_MASK + 1] = {
251 [IRQ_TYPE_EDGE_FALLING] = INTC_IRQ_SENSE(0x00),
252 [IRQ_TYPE_EDGE_RISING] = INTC_IRQ_SENSE(0x01),
253 [IRQ_TYPE_LEVEL_LOW] = INTC_IRQ_SENSE(0x02),
254 [IRQ_TYPE_LEVEL_HIGH] = INTC_IRQ_SENSE(0x03),
255 [IRQ_TYPE_EDGE_BOTH] = INTC_IRQ_SENSE(0x04),
256};
257
258static int intc_irqpin_irq_set_type(struct irq_data *d, unsigned int type)
259{
260 unsigned char value = intc_irqpin_sense[type & IRQ_TYPE_SENSE_MASK];
261 struct intc_irqpin_priv *p = irq_data_get_irq_chip_data(d);
262
263 if (!(value & INTC_IRQ_SENSE_VALID))
264 return -EINVAL;
265
266 return intc_irqpin_set_sense(p, irqd_to_hwirq(d),
267 value ^ INTC_IRQ_SENSE_VALID);
268}
269
270static irqreturn_t intc_irqpin_irq_handler(int irq, void *dev_id)
271{
272 struct intc_irqpin_irq *i = dev_id;
273 struct intc_irqpin_priv *p = i->p;
274 unsigned long bit;
275
276 intc_irqpin_dbg(i, "demux1");
277 bit = intc_irqpin_hwirq_mask(p, INTC_IRQPIN_REG_SOURCE, i->hw_irq);
278
279 if (intc_irqpin_read(p, INTC_IRQPIN_REG_SOURCE) & bit) {
280 intc_irqpin_write(p, INTC_IRQPIN_REG_SOURCE, ~bit);
281 intc_irqpin_dbg(i, "demux2");
282 generic_handle_irq(i->domain_irq);
283 return IRQ_HANDLED;
284 }
285 return IRQ_NONE;
286}
287
288static irqreturn_t intc_irqpin_shared_irq_handler(int irq, void *dev_id)
289{
290 struct intc_irqpin_priv *p = dev_id;
291 unsigned int reg_source = intc_irqpin_read(p, INTC_IRQPIN_REG_SOURCE);
292 irqreturn_t status = IRQ_NONE;
293 int k;
294
295 for (k = 0; k < 8; k++) {
296 if (reg_source & BIT(7 - k)) {
297 if (BIT(k) & p->shared_irq_mask)
298 continue;
299
300 status |= intc_irqpin_irq_handler(irq, &p->irq[k]);
301 }
302 }
303
304 return status;
305}
306
307static int intc_irqpin_irq_domain_map(struct irq_domain *h, unsigned int virq,
308 irq_hw_number_t hw)
309{
310 struct intc_irqpin_priv *p = h->host_data;
311
312 p->irq[hw].domain_irq = virq;
313 p->irq[hw].hw_irq = hw;
314
315 intc_irqpin_dbg(&p->irq[hw], "map");
316 irq_set_chip_data(virq, h->host_data);
317 irq_set_chip_and_handler(virq, &p->irq_chip, handle_level_irq);
318 set_irq_flags(virq, IRQF_VALID); /* kill me now */
319 return 0;
320}
321
322static struct irq_domain_ops intc_irqpin_irq_domain_ops = {
323 .map = intc_irqpin_irq_domain_map,
324 .xlate = irq_domain_xlate_twocell,
325};
326
327static int intc_irqpin_probe(struct platform_device *pdev)
328{
329 struct renesas_intc_irqpin_config *pdata = pdev->dev.platform_data;
330 struct intc_irqpin_priv *p;
331 struct intc_irqpin_iomem *i;
332 struct resource *io[INTC_IRQPIN_REG_NR];
333 struct resource *irq;
334 struct irq_chip *irq_chip;
335 void (*enable_fn)(struct irq_data *d);
336 void (*disable_fn)(struct irq_data *d);
337 const char *name = dev_name(&pdev->dev);
338 int ref_irq;
339 int ret;
340 int k;
341
342 p = devm_kzalloc(&pdev->dev, sizeof(*p), GFP_KERNEL);
343 if (!p) {
344 dev_err(&pdev->dev, "failed to allocate driver data\n");
345 ret = -ENOMEM;
346 goto err0;
347 }
348
349 /* deal with driver instance configuration */
350 if (pdata)
351 memcpy(&p->config, pdata, sizeof(*pdata));
352 if (!p->config.sense_bitfield_width)
353 p->config.sense_bitfield_width = 4; /* default to 4 bits */
354
355 p->pdev = pdev;
356 platform_set_drvdata(pdev, p);
357
358 /* get hold of manadatory IOMEM */
359 for (k = 0; k < INTC_IRQPIN_REG_NR; k++) {
360 io[k] = platform_get_resource(pdev, IORESOURCE_MEM, k);
361 if (!io[k]) {
362 dev_err(&pdev->dev, "not enough IOMEM resources\n");
363 ret = -EINVAL;
364 goto err0;
365 }
366 }
367
368 /* allow any number of IRQs between 1 and INTC_IRQPIN_MAX */
369 for (k = 0; k < INTC_IRQPIN_MAX; k++) {
370 irq = platform_get_resource(pdev, IORESOURCE_IRQ, k);
371 if (!irq)
372 break;
373
374 p->irq[k].p = p;
375 p->irq[k].requested_irq = irq->start;
376 }
377
378 p->number_of_irqs = k;
379 if (p->number_of_irqs < 1) {
380 dev_err(&pdev->dev, "not enough IRQ resources\n");
381 ret = -EINVAL;
382 goto err0;
383 }
384
385 /* ioremap IOMEM and setup read/write callbacks */
386 for (k = 0; k < INTC_IRQPIN_REG_NR; k++) {
387 i = &p->iomem[k];
388
389 switch (resource_size(io[k])) {
390 case 1:
391 i->width = 8;
392 i->read = intc_irqpin_read8;
393 i->write = intc_irqpin_write8;
394 break;
395 case 4:
396 i->width = 32;
397 i->read = intc_irqpin_read32;
398 i->write = intc_irqpin_write32;
399 break;
400 default:
401 dev_err(&pdev->dev, "IOMEM size mismatch\n");
402 ret = -EINVAL;
403 goto err0;
404 }
405
406 i->iomem = devm_ioremap_nocache(&pdev->dev, io[k]->start,
407 resource_size(io[k]));
408 if (!i->iomem) {
409 dev_err(&pdev->dev, "failed to remap IOMEM\n");
410 ret = -ENXIO;
411 goto err0;
412 }
413 }
414
415 /* mask all interrupts using priority */
416 for (k = 0; k < p->number_of_irqs; k++)
417 intc_irqpin_mask_unmask_prio(p, k, 1);
418
419 /* clear all pending interrupts */
420 intc_irqpin_write(p, INTC_IRQPIN_REG_SOURCE, 0x0);
421
422 /* scan for shared interrupt lines */
423 ref_irq = p->irq[0].requested_irq;
424 p->shared_irqs = true;
425 for (k = 1; k < p->number_of_irqs; k++) {
426 if (ref_irq != p->irq[k].requested_irq) {
427 p->shared_irqs = false;
428 break;
429 }
430 }
431
432 /* use more severe masking method if requested */
433 if (p->config.control_parent) {
434 enable_fn = intc_irqpin_irq_enable_force;
435 disable_fn = intc_irqpin_irq_disable_force;
436 } else if (!p->shared_irqs) {
437 enable_fn = intc_irqpin_irq_enable;
438 disable_fn = intc_irqpin_irq_disable;
439 } else {
440 enable_fn = intc_irqpin_shared_irq_enable;
441 disable_fn = intc_irqpin_shared_irq_disable;
442 }
443
444 irq_chip = &p->irq_chip;
445 irq_chip->name = name;
446 irq_chip->irq_mask = disable_fn;
447 irq_chip->irq_unmask = enable_fn;
448 irq_chip->irq_enable = enable_fn;
449 irq_chip->irq_disable = disable_fn;
450 irq_chip->irq_set_type = intc_irqpin_irq_set_type;
451 irq_chip->flags = IRQCHIP_SKIP_SET_WAKE;
452
453 p->irq_domain = irq_domain_add_simple(pdev->dev.of_node,
454 p->number_of_irqs,
455 p->config.irq_base,
456 &intc_irqpin_irq_domain_ops, p);
457 if (!p->irq_domain) {
458 ret = -ENXIO;
459 dev_err(&pdev->dev, "cannot initialize irq domain\n");
460 goto err0;
461 }
462
463 if (p->shared_irqs) {
464 /* request one shared interrupt */
465 if (devm_request_irq(&pdev->dev, p->irq[0].requested_irq,
466 intc_irqpin_shared_irq_handler,
467 IRQF_SHARED, name, p)) {
468 dev_err(&pdev->dev, "failed to request low IRQ\n");
469 ret = -ENOENT;
470 goto err1;
471 }
472 } else {
473 /* request interrupts one by one */
474 for (k = 0; k < p->number_of_irqs; k++) {
475 if (devm_request_irq(&pdev->dev,
476 p->irq[k].requested_irq,
477 intc_irqpin_irq_handler,
478 0, name, &p->irq[k])) {
479 dev_err(&pdev->dev,
480 "failed to request low IRQ\n");
481 ret = -ENOENT;
482 goto err1;
483 }
484 }
485 }
486
487 /* unmask all interrupts on prio level */
488 for (k = 0; k < p->number_of_irqs; k++)
489 intc_irqpin_mask_unmask_prio(p, k, 0);
490
491 dev_info(&pdev->dev, "driving %d irqs\n", p->number_of_irqs);
492
493 /* warn in case of mismatch if irq base is specified */
494 if (p->config.irq_base) {
495 if (p->config.irq_base != p->irq[0].domain_irq)
496 dev_warn(&pdev->dev, "irq base mismatch (%d/%d)\n",
497 p->config.irq_base, p->irq[0].domain_irq);
498 }
499
500 return 0;
501
502err1:
503 irq_domain_remove(p->irq_domain);
504err0:
505 return ret;
506}
507
508static int intc_irqpin_remove(struct platform_device *pdev)
509{
510 struct intc_irqpin_priv *p = platform_get_drvdata(pdev);
511
512 irq_domain_remove(p->irq_domain);
513
514 return 0;
515}
516
517static const struct of_device_id intc_irqpin_dt_ids[] = {
518 { .compatible = "renesas,intc-irqpin", },
519 {},
520};
521MODULE_DEVICE_TABLE(of, intc_irqpin_dt_ids);
522
523static struct platform_driver intc_irqpin_device_driver = {
524 .probe = intc_irqpin_probe,
525 .remove = intc_irqpin_remove,
526 .driver = {
527 .name = "renesas_intc_irqpin",
528 .of_match_table = intc_irqpin_dt_ids,
529 .owner = THIS_MODULE,
530 }
531};
532
533static int __init intc_irqpin_init(void)
534{
535 return platform_driver_register(&intc_irqpin_device_driver);
536}
537postcore_initcall(intc_irqpin_init);
538
539static void __exit intc_irqpin_exit(void)
540{
541 platform_driver_unregister(&intc_irqpin_device_driver);
542}
543module_exit(intc_irqpin_exit);
544
545MODULE_AUTHOR("Magnus Damm");
546MODULE_DESCRIPTION("Renesas INTC External IRQ Pin Driver");
547MODULE_LICENSE("GPL v2");
diff --git a/drivers/irqchip/irq-renesas-irqc.c b/drivers/irqchip/irq-renesas-irqc.c
new file mode 100644
index 000000000000..927bff373aac
--- /dev/null
+++ b/drivers/irqchip/irq-renesas-irqc.c
@@ -0,0 +1,307 @@
1/*
2 * Renesas IRQC Driver
3 *
4 * Copyright (C) 2013 Magnus Damm
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20#include <linux/init.h>
21#include <linux/platform_device.h>
22#include <linux/spinlock.h>
23#include <linux/interrupt.h>
24#include <linux/ioport.h>
25#include <linux/io.h>
26#include <linux/irq.h>
27#include <linux/irqdomain.h>
28#include <linux/err.h>
29#include <linux/slab.h>
30#include <linux/module.h>
31#include <linux/platform_data/irq-renesas-irqc.h>
32
33#define IRQC_IRQ_MAX 32 /* maximum 32 interrupts per driver instance */
34
35#define IRQC_REQ_STS 0x00
36#define IRQC_EN_STS 0x04
37#define IRQC_EN_SET 0x08
38#define IRQC_INT_CPU_BASE(n) (0x000 + ((n) * 0x10))
39#define DETECT_STATUS 0x100
40#define IRQC_CONFIG(n) (0x180 + ((n) * 0x04))
41
42struct irqc_irq {
43 int hw_irq;
44 int requested_irq;
45 int domain_irq;
46 struct irqc_priv *p;
47};
48
49struct irqc_priv {
50 void __iomem *iomem;
51 void __iomem *cpu_int_base;
52 struct irqc_irq irq[IRQC_IRQ_MAX];
53 struct renesas_irqc_config config;
54 unsigned int number_of_irqs;
55 struct platform_device *pdev;
56 struct irq_chip irq_chip;
57 struct irq_domain *irq_domain;
58};
59
60static void irqc_dbg(struct irqc_irq *i, char *str)
61{
62 dev_dbg(&i->p->pdev->dev, "%s (%d:%d:%d)\n",
63 str, i->requested_irq, i->hw_irq, i->domain_irq);
64}
65
66static void irqc_irq_enable(struct irq_data *d)
67{
68 struct irqc_priv *p = irq_data_get_irq_chip_data(d);
69 int hw_irq = irqd_to_hwirq(d);
70
71 irqc_dbg(&p->irq[hw_irq], "enable");
72 iowrite32(BIT(hw_irq), p->cpu_int_base + IRQC_EN_SET);
73}
74
75static void irqc_irq_disable(struct irq_data *d)
76{
77 struct irqc_priv *p = irq_data_get_irq_chip_data(d);
78 int hw_irq = irqd_to_hwirq(d);
79
80 irqc_dbg(&p->irq[hw_irq], "disable");
81 iowrite32(BIT(hw_irq), p->cpu_int_base + IRQC_EN_STS);
82}
83
84#define INTC_IRQ_SENSE_VALID 0x10
85#define INTC_IRQ_SENSE(x) (x + INTC_IRQ_SENSE_VALID)
86
87static unsigned char irqc_sense[IRQ_TYPE_SENSE_MASK + 1] = {
88 [IRQ_TYPE_LEVEL_LOW] = INTC_IRQ_SENSE(0x01),
89 [IRQ_TYPE_LEVEL_HIGH] = INTC_IRQ_SENSE(0x02),
90 [IRQ_TYPE_EDGE_FALLING] = INTC_IRQ_SENSE(0x04), /* Synchronous */
91 [IRQ_TYPE_EDGE_RISING] = INTC_IRQ_SENSE(0x08), /* Synchronous */
92 [IRQ_TYPE_EDGE_BOTH] = INTC_IRQ_SENSE(0x0c), /* Synchronous */
93};
94
95static int irqc_irq_set_type(struct irq_data *d, unsigned int type)
96{
97 struct irqc_priv *p = irq_data_get_irq_chip_data(d);
98 int hw_irq = irqd_to_hwirq(d);
99 unsigned char value = irqc_sense[type & IRQ_TYPE_SENSE_MASK];
100 unsigned long tmp;
101
102 irqc_dbg(&p->irq[hw_irq], "sense");
103
104 if (!(value & INTC_IRQ_SENSE_VALID))
105 return -EINVAL;
106
107 tmp = ioread32(p->iomem + IRQC_CONFIG(hw_irq));
108 tmp &= ~0x3f;
109 tmp |= value ^ INTC_IRQ_SENSE_VALID;
110 iowrite32(tmp, p->iomem + IRQC_CONFIG(hw_irq));
111 return 0;
112}
113
114static irqreturn_t irqc_irq_handler(int irq, void *dev_id)
115{
116 struct irqc_irq *i = dev_id;
117 struct irqc_priv *p = i->p;
118 unsigned long bit = BIT(i->hw_irq);
119
120 irqc_dbg(i, "demux1");
121
122 if (ioread32(p->iomem + DETECT_STATUS) & bit) {
123 iowrite32(bit, p->iomem + DETECT_STATUS);
124 irqc_dbg(i, "demux2");
125 generic_handle_irq(i->domain_irq);
126 return IRQ_HANDLED;
127 }
128 return IRQ_NONE;
129}
130
131static int irqc_irq_domain_map(struct irq_domain *h, unsigned int virq,
132 irq_hw_number_t hw)
133{
134 struct irqc_priv *p = h->host_data;
135
136 p->irq[hw].domain_irq = virq;
137 p->irq[hw].hw_irq = hw;
138
139 irqc_dbg(&p->irq[hw], "map");
140 irq_set_chip_data(virq, h->host_data);
141 irq_set_chip_and_handler(virq, &p->irq_chip, handle_level_irq);
142 set_irq_flags(virq, IRQF_VALID); /* kill me now */
143 return 0;
144}
145
146static struct irq_domain_ops irqc_irq_domain_ops = {
147 .map = irqc_irq_domain_map,
148 .xlate = irq_domain_xlate_twocell,
149};
150
151static int irqc_probe(struct platform_device *pdev)
152{
153 struct renesas_irqc_config *pdata = pdev->dev.platform_data;
154 struct irqc_priv *p;
155 struct resource *io;
156 struct resource *irq;
157 struct irq_chip *irq_chip;
158 const char *name = dev_name(&pdev->dev);
159 int ret;
160 int k;
161
162 p = kzalloc(sizeof(*p), GFP_KERNEL);
163 if (!p) {
164 dev_err(&pdev->dev, "failed to allocate driver data\n");
165 ret = -ENOMEM;
166 goto err0;
167 }
168
169 /* deal with driver instance configuration */
170 if (pdata)
171 memcpy(&p->config, pdata, sizeof(*pdata));
172
173 p->pdev = pdev;
174 platform_set_drvdata(pdev, p);
175
176 /* get hold of manadatory IOMEM */
177 io = platform_get_resource(pdev, IORESOURCE_MEM, 0);
178 if (!io) {
179 dev_err(&pdev->dev, "not enough IOMEM resources\n");
180 ret = -EINVAL;
181 goto err1;
182 }
183
184 /* allow any number of IRQs between 1 and IRQC_IRQ_MAX */
185 for (k = 0; k < IRQC_IRQ_MAX; k++) {
186 irq = platform_get_resource(pdev, IORESOURCE_IRQ, k);
187 if (!irq)
188 break;
189
190 p->irq[k].p = p;
191 p->irq[k].requested_irq = irq->start;
192 }
193
194 p->number_of_irqs = k;
195 if (p->number_of_irqs < 1) {
196 dev_err(&pdev->dev, "not enough IRQ resources\n");
197 ret = -EINVAL;
198 goto err1;
199 }
200
201 /* ioremap IOMEM and setup read/write callbacks */
202 p->iomem = ioremap_nocache(io->start, resource_size(io));
203 if (!p->iomem) {
204 dev_err(&pdev->dev, "failed to remap IOMEM\n");
205 ret = -ENXIO;
206 goto err2;
207 }
208
209 p->cpu_int_base = p->iomem + IRQC_INT_CPU_BASE(0); /* SYS-SPI */
210
211 irq_chip = &p->irq_chip;
212 irq_chip->name = name;
213 irq_chip->irq_mask = irqc_irq_disable;
214 irq_chip->irq_unmask = irqc_irq_enable;
215 irq_chip->irq_enable = irqc_irq_enable;
216 irq_chip->irq_disable = irqc_irq_disable;
217 irq_chip->irq_set_type = irqc_irq_set_type;
218 irq_chip->flags = IRQCHIP_SKIP_SET_WAKE;
219
220 p->irq_domain = irq_domain_add_simple(pdev->dev.of_node,
221 p->number_of_irqs,
222 p->config.irq_base,
223 &irqc_irq_domain_ops, p);
224 if (!p->irq_domain) {
225 ret = -ENXIO;
226 dev_err(&pdev->dev, "cannot initialize irq domain\n");
227 goto err2;
228 }
229
230 /* request interrupts one by one */
231 for (k = 0; k < p->number_of_irqs; k++) {
232 if (request_irq(p->irq[k].requested_irq, irqc_irq_handler,
233 0, name, &p->irq[k])) {
234 dev_err(&pdev->dev, "failed to request IRQ\n");
235 ret = -ENOENT;
236 goto err3;
237 }
238 }
239
240 dev_info(&pdev->dev, "driving %d irqs\n", p->number_of_irqs);
241
242 /* warn in case of mismatch if irq base is specified */
243 if (p->config.irq_base) {
244 if (p->config.irq_base != p->irq[0].domain_irq)
245 dev_warn(&pdev->dev, "irq base mismatch (%d/%d)\n",
246 p->config.irq_base, p->irq[0].domain_irq);
247 }
248
249 return 0;
250err3:
251 for (; k >= 0; k--)
252 free_irq(p->irq[k - 1].requested_irq, &p->irq[k - 1]);
253
254 irq_domain_remove(p->irq_domain);
255err2:
256 iounmap(p->iomem);
257err1:
258 kfree(p);
259err0:
260 return ret;
261}
262
263static int irqc_remove(struct platform_device *pdev)
264{
265 struct irqc_priv *p = platform_get_drvdata(pdev);
266 int k;
267
268 for (k = 0; k < p->number_of_irqs; k++)
269 free_irq(p->irq[k].requested_irq, &p->irq[k]);
270
271 irq_domain_remove(p->irq_domain);
272 iounmap(p->iomem);
273 kfree(p);
274 return 0;
275}
276
277static const struct of_device_id irqc_dt_ids[] = {
278 { .compatible = "renesas,irqc", },
279 {},
280};
281MODULE_DEVICE_TABLE(of, irqc_dt_ids);
282
283static struct platform_driver irqc_device_driver = {
284 .probe = irqc_probe,
285 .remove = irqc_remove,
286 .driver = {
287 .name = "renesas_irqc",
288 .of_match_table = irqc_dt_ids,
289 .owner = THIS_MODULE,
290 }
291};
292
293static int __init irqc_init(void)
294{
295 return platform_driver_register(&irqc_device_driver);
296}
297postcore_initcall(irqc_init);
298
299static void __exit irqc_exit(void)
300{
301 platform_driver_unregister(&irqc_device_driver);
302}
303module_exit(irqc_exit);
304
305MODULE_AUTHOR("Magnus Damm");
306MODULE_DESCRIPTION("Renesas IRQC Driver");
307MODULE_LICENSE("GPL v2");
diff --git a/drivers/irqchip/irq-s3c24xx.c b/drivers/irqchip/irq-s3c24xx.c
new file mode 100644
index 000000000000..5e40b3424df8
--- /dev/null
+++ b/drivers/irqchip/irq-s3c24xx.c
@@ -0,0 +1,1355 @@
1/*
2 * S3C24XX IRQ handling
3 *
4 * Copyright (c) 2003-2004 Simtec Electronics
5 * Ben Dooks <ben@simtec.co.uk>
6 * Copyright (c) 2012 Heiko Stuebner <heiko@sntech.de>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17*/
18
19#include <linux/init.h>
20#include <linux/slab.h>
21#include <linux/module.h>
22#include <linux/io.h>
23#include <linux/err.h>
24#include <linux/interrupt.h>
25#include <linux/ioport.h>
26#include <linux/device.h>
27#include <linux/irqdomain.h>
28#include <linux/of.h>
29#include <linux/of_irq.h>
30#include <linux/of_address.h>
31
32#include <asm/exception.h>
33#include <asm/mach/irq.h>
34
35#include <mach/regs-irq.h>
36#include <mach/regs-gpio.h>
37
38#include <plat/cpu.h>
39#include <plat/regs-irqtype.h>
40#include <plat/pm.h>
41
42#include "irqchip.h"
43
44#define S3C_IRQTYPE_NONE 0
45#define S3C_IRQTYPE_EINT 1
46#define S3C_IRQTYPE_EDGE 2
47#define S3C_IRQTYPE_LEVEL 3
48
49struct s3c_irq_data {
50 unsigned int type;
51 unsigned long offset;
52 unsigned long parent_irq;
53
54 /* data gets filled during init */
55 struct s3c_irq_intc *intc;
56 unsigned long sub_bits;
57 struct s3c_irq_intc *sub_intc;
58};
59
60/*
61 * Sructure holding the controller data
62 * @reg_pending register holding pending irqs
63 * @reg_intpnd special register intpnd in main intc
64 * @reg_mask mask register
65 * @domain irq_domain of the controller
66 * @parent parent controller for ext and sub irqs
67 * @irqs irq-data, always s3c_irq_data[32]
68 */
69struct s3c_irq_intc {
70 void __iomem *reg_pending;
71 void __iomem *reg_intpnd;
72 void __iomem *reg_mask;
73 struct irq_domain *domain;
74 struct s3c_irq_intc *parent;
75 struct s3c_irq_data *irqs;
76};
77
78/*
79 * Array holding pointers to the global controller structs
80 * [0] ... main_intc
81 * [1] ... sub_intc
82 * [2] ... main_intc2 on s3c2416
83 */
84static struct s3c_irq_intc *s3c_intc[3];
85
86static void s3c_irq_mask(struct irq_data *data)
87{
88 struct s3c_irq_data *irq_data = irq_data_get_irq_chip_data(data);
89 struct s3c_irq_intc *intc = irq_data->intc;
90 struct s3c_irq_intc *parent_intc = intc->parent;
91 struct s3c_irq_data *parent_data;
92 unsigned long mask;
93 unsigned int irqno;
94
95 mask = __raw_readl(intc->reg_mask);
96 mask |= (1UL << irq_data->offset);
97 __raw_writel(mask, intc->reg_mask);
98
99 if (parent_intc) {
100 parent_data = &parent_intc->irqs[irq_data->parent_irq];
101
102 /* check to see if we need to mask the parent IRQ
103 * The parent_irq is always in main_intc, so the hwirq
104 * for find_mapping does not need an offset in any case.
105 */
106 if ((mask & parent_data->sub_bits) == parent_data->sub_bits) {
107 irqno = irq_find_mapping(parent_intc->domain,
108 irq_data->parent_irq);
109 s3c_irq_mask(irq_get_irq_data(irqno));
110 }
111 }
112}
113
114static void s3c_irq_unmask(struct irq_data *data)
115{
116 struct s3c_irq_data *irq_data = irq_data_get_irq_chip_data(data);
117 struct s3c_irq_intc *intc = irq_data->intc;
118 struct s3c_irq_intc *parent_intc = intc->parent;
119 unsigned long mask;
120 unsigned int irqno;
121
122 mask = __raw_readl(intc->reg_mask);
123 mask &= ~(1UL << irq_data->offset);
124 __raw_writel(mask, intc->reg_mask);
125
126 if (parent_intc) {
127 irqno = irq_find_mapping(parent_intc->domain,
128 irq_data->parent_irq);
129 s3c_irq_unmask(irq_get_irq_data(irqno));
130 }
131}
132
133static inline void s3c_irq_ack(struct irq_data *data)
134{
135 struct s3c_irq_data *irq_data = irq_data_get_irq_chip_data(data);
136 struct s3c_irq_intc *intc = irq_data->intc;
137 unsigned long bitval = 1UL << irq_data->offset;
138
139 __raw_writel(bitval, intc->reg_pending);
140 if (intc->reg_intpnd)
141 __raw_writel(bitval, intc->reg_intpnd);
142}
143
144static int s3c_irq_type(struct irq_data *data, unsigned int type)
145{
146 switch (type) {
147 case IRQ_TYPE_NONE:
148 break;
149 case IRQ_TYPE_EDGE_RISING:
150 case IRQ_TYPE_EDGE_FALLING:
151 case IRQ_TYPE_EDGE_BOTH:
152 irq_set_handler(data->irq, handle_edge_irq);
153 break;
154 case IRQ_TYPE_LEVEL_LOW:
155 case IRQ_TYPE_LEVEL_HIGH:
156 irq_set_handler(data->irq, handle_level_irq);
157 break;
158 default:
159 pr_err("No such irq type %d", type);
160 return -EINVAL;
161 }
162
163 return 0;
164}
165
166static int s3c_irqext_type_set(void __iomem *gpcon_reg,
167 void __iomem *extint_reg,
168 unsigned long gpcon_offset,
169 unsigned long extint_offset,
170 unsigned int type)
171{
172 unsigned long newvalue = 0, value;
173
174 /* Set the GPIO to external interrupt mode */
175 value = __raw_readl(gpcon_reg);
176 value = (value & ~(3 << gpcon_offset)) | (0x02 << gpcon_offset);
177 __raw_writel(value, gpcon_reg);
178
179 /* Set the external interrupt to pointed trigger type */
180 switch (type)
181 {
182 case IRQ_TYPE_NONE:
183 pr_warn("No edge setting!\n");
184 break;
185
186 case IRQ_TYPE_EDGE_RISING:
187 newvalue = S3C2410_EXTINT_RISEEDGE;
188 break;
189
190 case IRQ_TYPE_EDGE_FALLING:
191 newvalue = S3C2410_EXTINT_FALLEDGE;
192 break;
193
194 case IRQ_TYPE_EDGE_BOTH:
195 newvalue = S3C2410_EXTINT_BOTHEDGE;
196 break;
197
198 case IRQ_TYPE_LEVEL_LOW:
199 newvalue = S3C2410_EXTINT_LOWLEV;
200 break;
201
202 case IRQ_TYPE_LEVEL_HIGH:
203 newvalue = S3C2410_EXTINT_HILEV;
204 break;
205
206 default:
207 pr_err("No such irq type %d", type);
208 return -EINVAL;
209 }
210
211 value = __raw_readl(extint_reg);
212 value = (value & ~(7 << extint_offset)) | (newvalue << extint_offset);
213 __raw_writel(value, extint_reg);
214
215 return 0;
216}
217
218static int s3c_irqext_type(struct irq_data *data, unsigned int type)
219{
220 void __iomem *extint_reg;
221 void __iomem *gpcon_reg;
222 unsigned long gpcon_offset, extint_offset;
223
224 if ((data->hwirq >= 4) && (data->hwirq <= 7)) {
225 gpcon_reg = S3C2410_GPFCON;
226 extint_reg = S3C24XX_EXTINT0;
227 gpcon_offset = (data->hwirq) * 2;
228 extint_offset = (data->hwirq) * 4;
229 } else if ((data->hwirq >= 8) && (data->hwirq <= 15)) {
230 gpcon_reg = S3C2410_GPGCON;
231 extint_reg = S3C24XX_EXTINT1;
232 gpcon_offset = (data->hwirq - 8) * 2;
233 extint_offset = (data->hwirq - 8) * 4;
234 } else if ((data->hwirq >= 16) && (data->hwirq <= 23)) {
235 gpcon_reg = S3C2410_GPGCON;
236 extint_reg = S3C24XX_EXTINT2;
237 gpcon_offset = (data->hwirq - 8) * 2;
238 extint_offset = (data->hwirq - 16) * 4;
239 } else {
240 return -EINVAL;
241 }
242
243 return s3c_irqext_type_set(gpcon_reg, extint_reg, gpcon_offset,
244 extint_offset, type);
245}
246
247static int s3c_irqext0_type(struct irq_data *data, unsigned int type)
248{
249 void __iomem *extint_reg;
250 void __iomem *gpcon_reg;
251 unsigned long gpcon_offset, extint_offset;
252
253 if ((data->hwirq >= 0) && (data->hwirq <= 3)) {
254 gpcon_reg = S3C2410_GPFCON;
255 extint_reg = S3C24XX_EXTINT0;
256 gpcon_offset = (data->hwirq) * 2;
257 extint_offset = (data->hwirq) * 4;
258 } else {
259 return -EINVAL;
260 }
261
262 return s3c_irqext_type_set(gpcon_reg, extint_reg, gpcon_offset,
263 extint_offset, type);
264}
265
266static struct irq_chip s3c_irq_chip = {
267 .name = "s3c",
268 .irq_ack = s3c_irq_ack,
269 .irq_mask = s3c_irq_mask,
270 .irq_unmask = s3c_irq_unmask,
271 .irq_set_type = s3c_irq_type,
272 .irq_set_wake = s3c_irq_wake
273};
274
275static struct irq_chip s3c_irq_level_chip = {
276 .name = "s3c-level",
277 .irq_mask = s3c_irq_mask,
278 .irq_unmask = s3c_irq_unmask,
279 .irq_ack = s3c_irq_ack,
280 .irq_set_type = s3c_irq_type,
281};
282
283static struct irq_chip s3c_irqext_chip = {
284 .name = "s3c-ext",
285 .irq_mask = s3c_irq_mask,
286 .irq_unmask = s3c_irq_unmask,
287 .irq_ack = s3c_irq_ack,
288 .irq_set_type = s3c_irqext_type,
289 .irq_set_wake = s3c_irqext_wake
290};
291
292static struct irq_chip s3c_irq_eint0t4 = {
293 .name = "s3c-ext0",
294 .irq_ack = s3c_irq_ack,
295 .irq_mask = s3c_irq_mask,
296 .irq_unmask = s3c_irq_unmask,
297 .irq_set_wake = s3c_irq_wake,
298 .irq_set_type = s3c_irqext0_type,
299};
300
301static void s3c_irq_demux(unsigned int irq, struct irq_desc *desc)
302{
303 struct irq_chip *chip = irq_desc_get_chip(desc);
304 struct s3c_irq_data *irq_data = irq_desc_get_chip_data(desc);
305 struct s3c_irq_intc *intc = irq_data->intc;
306 struct s3c_irq_intc *sub_intc = irq_data->sub_intc;
307 unsigned long src;
308 unsigned long msk;
309 unsigned int n;
310 unsigned int offset;
311
312 /* we're using individual domains for the non-dt case
313 * and one big domain for the dt case where the subintc
314 * starts at hwirq number 32.
315 */
316 offset = (intc->domain->of_node) ? 32 : 0;
317
318 chained_irq_enter(chip, desc);
319
320 src = __raw_readl(sub_intc->reg_pending);
321 msk = __raw_readl(sub_intc->reg_mask);
322
323 src &= ~msk;
324 src &= irq_data->sub_bits;
325
326 while (src) {
327 n = __ffs(src);
328 src &= ~(1 << n);
329 irq = irq_find_mapping(sub_intc->domain, offset + n);
330 generic_handle_irq(irq);
331 }
332
333 chained_irq_exit(chip, desc);
334}
335
336static inline int s3c24xx_handle_intc(struct s3c_irq_intc *intc,
337 struct pt_regs *regs, int intc_offset)
338{
339 int pnd;
340 int offset;
341 int irq;
342
343 pnd = __raw_readl(intc->reg_intpnd);
344 if (!pnd)
345 return false;
346
347 /* non-dt machines use individual domains */
348 if (!intc->domain->of_node)
349 intc_offset = 0;
350
351 /* We have a problem that the INTOFFSET register does not always
352 * show one interrupt. Occasionally we get two interrupts through
353 * the prioritiser, and this causes the INTOFFSET register to show
354 * what looks like the logical-or of the two interrupt numbers.
355 *
356 * Thanks to Klaus, Shannon, et al for helping to debug this problem
357 */
358 offset = __raw_readl(intc->reg_intpnd + 4);
359
360 /* Find the bit manually, when the offset is wrong.
361 * The pending register only ever contains the one bit of the next
362 * interrupt to handle.
363 */
364 if (!(pnd & (1 << offset)))
365 offset = __ffs(pnd);
366
367 irq = irq_find_mapping(intc->domain, intc_offset + offset);
368 handle_IRQ(irq, regs);
369 return true;
370}
371
372asmlinkage void __exception_irq_entry s3c24xx_handle_irq(struct pt_regs *regs)
373{
374 do {
375 if (likely(s3c_intc[0]))
376 if (s3c24xx_handle_intc(s3c_intc[0], regs, 0))
377 continue;
378
379 if (s3c_intc[2])
380 if (s3c24xx_handle_intc(s3c_intc[2], regs, 64))
381 continue;
382
383 break;
384 } while (1);
385}
386
387#ifdef CONFIG_FIQ
388/**
389 * s3c24xx_set_fiq - set the FIQ routing
390 * @irq: IRQ number to route to FIQ on processor.
391 * @on: Whether to route @irq to the FIQ, or to remove the FIQ routing.
392 *
393 * Change the state of the IRQ to FIQ routing depending on @irq and @on. If
394 * @on is true, the @irq is checked to see if it can be routed and the
395 * interrupt controller updated to route the IRQ. If @on is false, the FIQ
396 * routing is cleared, regardless of which @irq is specified.
397 */
398int s3c24xx_set_fiq(unsigned int irq, bool on)
399{
400 u32 intmod;
401 unsigned offs;
402
403 if (on) {
404 offs = irq - FIQ_START;
405 if (offs > 31)
406 return -EINVAL;
407
408 intmod = 1 << offs;
409 } else {
410 intmod = 0;
411 }
412
413 __raw_writel(intmod, S3C2410_INTMOD);
414 return 0;
415}
416
417EXPORT_SYMBOL_GPL(s3c24xx_set_fiq);
418#endif
419
420static int s3c24xx_irq_map(struct irq_domain *h, unsigned int virq,
421 irq_hw_number_t hw)
422{
423 struct s3c_irq_intc *intc = h->host_data;
424 struct s3c_irq_data *irq_data = &intc->irqs[hw];
425 struct s3c_irq_intc *parent_intc;
426 struct s3c_irq_data *parent_irq_data;
427 unsigned int irqno;
428
429 /* attach controller pointer to irq_data */
430 irq_data->intc = intc;
431 irq_data->offset = hw;
432
433 parent_intc = intc->parent;
434
435 /* set handler and flags */
436 switch (irq_data->type) {
437 case S3C_IRQTYPE_NONE:
438 return 0;
439 case S3C_IRQTYPE_EINT:
440 /* On the S3C2412, the EINT0to3 have a parent irq
441 * but need the s3c_irq_eint0t4 chip
442 */
443 if (parent_intc && (!soc_is_s3c2412() || hw >= 4))
444 irq_set_chip_and_handler(virq, &s3c_irqext_chip,
445 handle_edge_irq);
446 else
447 irq_set_chip_and_handler(virq, &s3c_irq_eint0t4,
448 handle_edge_irq);
449 break;
450 case S3C_IRQTYPE_EDGE:
451 if (parent_intc || intc->reg_pending == S3C2416_SRCPND2)
452 irq_set_chip_and_handler(virq, &s3c_irq_level_chip,
453 handle_edge_irq);
454 else
455 irq_set_chip_and_handler(virq, &s3c_irq_chip,
456 handle_edge_irq);
457 break;
458 case S3C_IRQTYPE_LEVEL:
459 if (parent_intc)
460 irq_set_chip_and_handler(virq, &s3c_irq_level_chip,
461 handle_level_irq);
462 else
463 irq_set_chip_and_handler(virq, &s3c_irq_chip,
464 handle_level_irq);
465 break;
466 default:
467 pr_err("irq-s3c24xx: unsupported irqtype %d\n", irq_data->type);
468 return -EINVAL;
469 }
470
471 irq_set_chip_data(virq, irq_data);
472
473 set_irq_flags(virq, IRQF_VALID);
474
475 if (parent_intc && irq_data->type != S3C_IRQTYPE_NONE) {
476 if (irq_data->parent_irq > 31) {
477 pr_err("irq-s3c24xx: parent irq %lu is out of range\n",
478 irq_data->parent_irq);
479 goto err;
480 }
481
482 parent_irq_data = &parent_intc->irqs[irq_data->parent_irq];
483 parent_irq_data->sub_intc = intc;
484 parent_irq_data->sub_bits |= (1UL << hw);
485
486 /* attach the demuxer to the parent irq */
487 irqno = irq_find_mapping(parent_intc->domain,
488 irq_data->parent_irq);
489 if (!irqno) {
490 pr_err("irq-s3c24xx: could not find mapping for parent irq %lu\n",
491 irq_data->parent_irq);
492 goto err;
493 }
494 irq_set_chained_handler(irqno, s3c_irq_demux);
495 }
496
497 return 0;
498
499err:
500 set_irq_flags(virq, 0);
501
502 /* the only error can result from bad mapping data*/
503 return -EINVAL;
504}
505
506static struct irq_domain_ops s3c24xx_irq_ops = {
507 .map = s3c24xx_irq_map,
508 .xlate = irq_domain_xlate_twocell,
509};
510
511static void s3c24xx_clear_intc(struct s3c_irq_intc *intc)
512{
513 void __iomem *reg_source;
514 unsigned long pend;
515 unsigned long last;
516 int i;
517
518 /* if intpnd is set, read the next pending irq from there */
519 reg_source = intc->reg_intpnd ? intc->reg_intpnd : intc->reg_pending;
520
521 last = 0;
522 for (i = 0; i < 4; i++) {
523 pend = __raw_readl(reg_source);
524
525 if (pend == 0 || pend == last)
526 break;
527
528 __raw_writel(pend, intc->reg_pending);
529 if (intc->reg_intpnd)
530 __raw_writel(pend, intc->reg_intpnd);
531
532 pr_info("irq: clearing pending status %08x\n", (int)pend);
533 last = pend;
534 }
535}
536
537static struct s3c_irq_intc *s3c24xx_init_intc(struct device_node *np,
538 struct s3c_irq_data *irq_data,
539 struct s3c_irq_intc *parent,
540 unsigned long address)
541{
542 struct s3c_irq_intc *intc;
543 void __iomem *base = (void *)0xf6000000; /* static mapping */
544 int irq_num;
545 int irq_start;
546 int ret;
547
548 intc = kzalloc(sizeof(struct s3c_irq_intc), GFP_KERNEL);
549 if (!intc)
550 return ERR_PTR(-ENOMEM);
551
552 intc->irqs = irq_data;
553
554 if (parent)
555 intc->parent = parent;
556
557 /* select the correct data for the controller.
558 * Need to hard code the irq num start and offset
559 * to preserve the static mapping for now
560 */
561 switch (address) {
562 case 0x4a000000:
563 pr_debug("irq: found main intc\n");
564 intc->reg_pending = base;
565 intc->reg_mask = base + 0x08;
566 intc->reg_intpnd = base + 0x10;
567 irq_num = 32;
568 irq_start = S3C2410_IRQ(0);
569 break;
570 case 0x4a000018:
571 pr_debug("irq: found subintc\n");
572 intc->reg_pending = base + 0x18;
573 intc->reg_mask = base + 0x1c;
574 irq_num = 29;
575 irq_start = S3C2410_IRQSUB(0);
576 break;
577 case 0x4a000040:
578 pr_debug("irq: found intc2\n");
579 intc->reg_pending = base + 0x40;
580 intc->reg_mask = base + 0x48;
581 intc->reg_intpnd = base + 0x50;
582 irq_num = 8;
583 irq_start = S3C2416_IRQ(0);
584 break;
585 case 0x560000a4:
586 pr_debug("irq: found eintc\n");
587 base = (void *)0xfd000000;
588
589 intc->reg_mask = base + 0xa4;
590 intc->reg_pending = base + 0x08;
591 irq_num = 24;
592 irq_start = S3C2410_IRQ(32);
593 break;
594 default:
595 pr_err("irq: unsupported controller address\n");
596 ret = -EINVAL;
597 goto err;
598 }
599
600 /* now that all the data is complete, init the irq-domain */
601 s3c24xx_clear_intc(intc);
602 intc->domain = irq_domain_add_legacy(np, irq_num, irq_start,
603 0, &s3c24xx_irq_ops,
604 intc);
605 if (!intc->domain) {
606 pr_err("irq: could not create irq-domain\n");
607 ret = -EINVAL;
608 goto err;
609 }
610
611 set_handle_irq(s3c24xx_handle_irq);
612
613 return intc;
614
615err:
616 kfree(intc);
617 return ERR_PTR(ret);
618}
619
620static struct s3c_irq_data init_eint[32] = {
621 { .type = S3C_IRQTYPE_NONE, }, /* reserved */
622 { .type = S3C_IRQTYPE_NONE, }, /* reserved */
623 { .type = S3C_IRQTYPE_NONE, }, /* reserved */
624 { .type = S3C_IRQTYPE_NONE, }, /* reserved */
625 { .type = S3C_IRQTYPE_EINT, .parent_irq = 4 }, /* EINT4 */
626 { .type = S3C_IRQTYPE_EINT, .parent_irq = 4 }, /* EINT5 */
627 { .type = S3C_IRQTYPE_EINT, .parent_irq = 4 }, /* EINT6 */
628 { .type = S3C_IRQTYPE_EINT, .parent_irq = 4 }, /* EINT7 */
629 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT8 */
630 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT9 */
631 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT10 */
632 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT11 */
633 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT12 */
634 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT13 */
635 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT14 */
636 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT15 */
637 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT16 */
638 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT17 */
639 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT18 */
640 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT19 */
641 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT20 */
642 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT21 */
643 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT22 */
644 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT23 */
645};
646
647#ifdef CONFIG_CPU_S3C2410
648static struct s3c_irq_data init_s3c2410base[32] = {
649 { .type = S3C_IRQTYPE_EINT, }, /* EINT0 */
650 { .type = S3C_IRQTYPE_EINT, }, /* EINT1 */
651 { .type = S3C_IRQTYPE_EINT, }, /* EINT2 */
652 { .type = S3C_IRQTYPE_EINT, }, /* EINT3 */
653 { .type = S3C_IRQTYPE_LEVEL, }, /* EINT4to7 */
654 { .type = S3C_IRQTYPE_LEVEL, }, /* EINT8to23 */
655 { .type = S3C_IRQTYPE_NONE, }, /* reserved */
656 { .type = S3C_IRQTYPE_EDGE, }, /* nBATT_FLT */
657 { .type = S3C_IRQTYPE_EDGE, }, /* TICK */
658 { .type = S3C_IRQTYPE_EDGE, }, /* WDT */
659 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER0 */
660 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER1 */
661 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER2 */
662 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER3 */
663 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER4 */
664 { .type = S3C_IRQTYPE_LEVEL, }, /* UART2 */
665 { .type = S3C_IRQTYPE_EDGE, }, /* LCD */
666 { .type = S3C_IRQTYPE_EDGE, }, /* DMA0 */
667 { .type = S3C_IRQTYPE_EDGE, }, /* DMA1 */
668 { .type = S3C_IRQTYPE_EDGE, }, /* DMA2 */
669 { .type = S3C_IRQTYPE_EDGE, }, /* DMA3 */
670 { .type = S3C_IRQTYPE_EDGE, }, /* SDI */
671 { .type = S3C_IRQTYPE_EDGE, }, /* SPI0 */
672 { .type = S3C_IRQTYPE_LEVEL, }, /* UART1 */
673 { .type = S3C_IRQTYPE_NONE, }, /* reserved */
674 { .type = S3C_IRQTYPE_EDGE, }, /* USBD */
675 { .type = S3C_IRQTYPE_EDGE, }, /* USBH */
676 { .type = S3C_IRQTYPE_EDGE, }, /* IIC */
677 { .type = S3C_IRQTYPE_LEVEL, }, /* UART0 */
678 { .type = S3C_IRQTYPE_EDGE, }, /* SPI1 */
679 { .type = S3C_IRQTYPE_EDGE, }, /* RTC */
680 { .type = S3C_IRQTYPE_LEVEL, }, /* ADCPARENT */
681};
682
683static struct s3c_irq_data init_s3c2410subint[32] = {
684 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 28 }, /* UART0-RX */
685 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 28 }, /* UART0-TX */
686 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 28 }, /* UART0-ERR */
687 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 23 }, /* UART1-RX */
688 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 23 }, /* UART1-TX */
689 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 23 }, /* UART1-ERR */
690 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 15 }, /* UART2-RX */
691 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 15 }, /* UART2-TX */
692 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 15 }, /* UART2-ERR */
693 { .type = S3C_IRQTYPE_EDGE, .parent_irq = 31 }, /* TC */
694 { .type = S3C_IRQTYPE_EDGE, .parent_irq = 31 }, /* ADC */
695};
696
697void __init s3c2410_init_irq(void)
698{
699#ifdef CONFIG_FIQ
700 init_FIQ(FIQ_START);
701#endif
702
703 s3c_intc[0] = s3c24xx_init_intc(NULL, &init_s3c2410base[0], NULL,
704 0x4a000000);
705 if (IS_ERR(s3c_intc[0])) {
706 pr_err("irq: could not create main interrupt controller\n");
707 return;
708 }
709
710 s3c_intc[1] = s3c24xx_init_intc(NULL, &init_s3c2410subint[0],
711 s3c_intc[0], 0x4a000018);
712 s3c24xx_init_intc(NULL, &init_eint[0], s3c_intc[0], 0x560000a4);
713}
714#endif
715
716#ifdef CONFIG_CPU_S3C2412
717static struct s3c_irq_data init_s3c2412base[32] = {
718 { .type = S3C_IRQTYPE_LEVEL, }, /* EINT0 */
719 { .type = S3C_IRQTYPE_LEVEL, }, /* EINT1 */
720 { .type = S3C_IRQTYPE_LEVEL, }, /* EINT2 */
721 { .type = S3C_IRQTYPE_LEVEL, }, /* EINT3 */
722 { .type = S3C_IRQTYPE_LEVEL, }, /* EINT4to7 */
723 { .type = S3C_IRQTYPE_LEVEL, }, /* EINT8to23 */
724 { .type = S3C_IRQTYPE_NONE, }, /* reserved */
725 { .type = S3C_IRQTYPE_EDGE, }, /* nBATT_FLT */
726 { .type = S3C_IRQTYPE_EDGE, }, /* TICK */
727 { .type = S3C_IRQTYPE_EDGE, }, /* WDT */
728 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER0 */
729 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER1 */
730 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER2 */
731 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER3 */
732 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER4 */
733 { .type = S3C_IRQTYPE_LEVEL, }, /* UART2 */
734 { .type = S3C_IRQTYPE_EDGE, }, /* LCD */
735 { .type = S3C_IRQTYPE_EDGE, }, /* DMA0 */
736 { .type = S3C_IRQTYPE_EDGE, }, /* DMA1 */
737 { .type = S3C_IRQTYPE_EDGE, }, /* DMA2 */
738 { .type = S3C_IRQTYPE_EDGE, }, /* DMA3 */
739 { .type = S3C_IRQTYPE_LEVEL, }, /* SDI/CF */
740 { .type = S3C_IRQTYPE_EDGE, }, /* SPI0 */
741 { .type = S3C_IRQTYPE_LEVEL, }, /* UART1 */
742 { .type = S3C_IRQTYPE_NONE, }, /* reserved */
743 { .type = S3C_IRQTYPE_EDGE, }, /* USBD */
744 { .type = S3C_IRQTYPE_EDGE, }, /* USBH */
745 { .type = S3C_IRQTYPE_EDGE, }, /* IIC */
746 { .type = S3C_IRQTYPE_LEVEL, }, /* UART0 */
747 { .type = S3C_IRQTYPE_EDGE, }, /* SPI1 */
748 { .type = S3C_IRQTYPE_EDGE, }, /* RTC */
749 { .type = S3C_IRQTYPE_LEVEL, }, /* ADCPARENT */
750};
751
752static struct s3c_irq_data init_s3c2412eint[32] = {
753 { .type = S3C_IRQTYPE_EINT, .parent_irq = 0 }, /* EINT0 */
754 { .type = S3C_IRQTYPE_EINT, .parent_irq = 1 }, /* EINT1 */
755 { .type = S3C_IRQTYPE_EINT, .parent_irq = 2 }, /* EINT2 */
756 { .type = S3C_IRQTYPE_EINT, .parent_irq = 3 }, /* EINT3 */
757 { .type = S3C_IRQTYPE_EINT, .parent_irq = 4 }, /* EINT4 */
758 { .type = S3C_IRQTYPE_EINT, .parent_irq = 4 }, /* EINT5 */
759 { .type = S3C_IRQTYPE_EINT, .parent_irq = 4 }, /* EINT6 */
760 { .type = S3C_IRQTYPE_EINT, .parent_irq = 4 }, /* EINT7 */
761 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT8 */
762 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT9 */
763 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT10 */
764 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT11 */
765 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT12 */
766 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT13 */
767 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT14 */
768 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT15 */
769 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT16 */
770 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT17 */
771 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT18 */
772 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT19 */
773 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT20 */
774 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT21 */
775 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT22 */
776 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT23 */
777};
778
779static struct s3c_irq_data init_s3c2412subint[32] = {
780 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 28 }, /* UART0-RX */
781 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 28 }, /* UART0-TX */
782 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 28 }, /* UART0-ERR */
783 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 23 }, /* UART1-RX */
784 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 23 }, /* UART1-TX */
785 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 23 }, /* UART1-ERR */
786 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 15 }, /* UART2-RX */
787 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 15 }, /* UART2-TX */
788 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 15 }, /* UART2-ERR */
789 { .type = S3C_IRQTYPE_EDGE, .parent_irq = 31 }, /* TC */
790 { .type = S3C_IRQTYPE_EDGE, .parent_irq = 31 }, /* ADC */
791 { .type = S3C_IRQTYPE_NONE, },
792 { .type = S3C_IRQTYPE_NONE, },
793 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 21 }, /* SDI */
794 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 21 }, /* CF */
795};
796
797void s3c2412_init_irq(void)
798{
799 pr_info("S3C2412: IRQ Support\n");
800
801#ifdef CONFIG_FIQ
802 init_FIQ(FIQ_START);
803#endif
804
805 s3c_intc[0] = s3c24xx_init_intc(NULL, &init_s3c2412base[0], NULL,
806 0x4a000000);
807 if (IS_ERR(s3c_intc[0])) {
808 pr_err("irq: could not create main interrupt controller\n");
809 return;
810 }
811
812 s3c24xx_init_intc(NULL, &init_s3c2412eint[0], s3c_intc[0], 0x560000a4);
813 s3c_intc[1] = s3c24xx_init_intc(NULL, &init_s3c2412subint[0],
814 s3c_intc[0], 0x4a000018);
815}
816#endif
817
818#ifdef CONFIG_CPU_S3C2416
819static struct s3c_irq_data init_s3c2416base[32] = {
820 { .type = S3C_IRQTYPE_EINT, }, /* EINT0 */
821 { .type = S3C_IRQTYPE_EINT, }, /* EINT1 */
822 { .type = S3C_IRQTYPE_EINT, }, /* EINT2 */
823 { .type = S3C_IRQTYPE_EINT, }, /* EINT3 */
824 { .type = S3C_IRQTYPE_LEVEL, }, /* EINT4to7 */
825 { .type = S3C_IRQTYPE_LEVEL, }, /* EINT8to23 */
826 { .type = S3C_IRQTYPE_NONE, }, /* reserved */
827 { .type = S3C_IRQTYPE_EDGE, }, /* nBATT_FLT */
828 { .type = S3C_IRQTYPE_EDGE, }, /* TICK */
829 { .type = S3C_IRQTYPE_LEVEL, }, /* WDT/AC97 */
830 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER0 */
831 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER1 */
832 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER2 */
833 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER3 */
834 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER4 */
835 { .type = S3C_IRQTYPE_LEVEL, }, /* UART2 */
836 { .type = S3C_IRQTYPE_LEVEL, }, /* LCD */
837 { .type = S3C_IRQTYPE_LEVEL, }, /* DMA */
838 { .type = S3C_IRQTYPE_LEVEL, }, /* UART3 */
839 { .type = S3C_IRQTYPE_NONE, }, /* reserved */
840 { .type = S3C_IRQTYPE_EDGE, }, /* SDI1 */
841 { .type = S3C_IRQTYPE_EDGE, }, /* SDI0 */
842 { .type = S3C_IRQTYPE_EDGE, }, /* SPI0 */
843 { .type = S3C_IRQTYPE_LEVEL, }, /* UART1 */
844 { .type = S3C_IRQTYPE_EDGE, }, /* NAND */
845 { .type = S3C_IRQTYPE_EDGE, }, /* USBD */
846 { .type = S3C_IRQTYPE_EDGE, }, /* USBH */
847 { .type = S3C_IRQTYPE_EDGE, }, /* IIC */
848 { .type = S3C_IRQTYPE_LEVEL, }, /* UART0 */
849 { .type = S3C_IRQTYPE_NONE, },
850 { .type = S3C_IRQTYPE_EDGE, }, /* RTC */
851 { .type = S3C_IRQTYPE_LEVEL, }, /* ADCPARENT */
852};
853
854static struct s3c_irq_data init_s3c2416subint[32] = {
855 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 28 }, /* UART0-RX */
856 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 28 }, /* UART0-TX */
857 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 28 }, /* UART0-ERR */
858 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 23 }, /* UART1-RX */
859 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 23 }, /* UART1-TX */
860 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 23 }, /* UART1-ERR */
861 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 15 }, /* UART2-RX */
862 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 15 }, /* UART2-TX */
863 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 15 }, /* UART2-ERR */
864 { .type = S3C_IRQTYPE_EDGE, .parent_irq = 31 }, /* TC */
865 { .type = S3C_IRQTYPE_EDGE, .parent_irq = 31 }, /* ADC */
866 { .type = S3C_IRQTYPE_NONE }, /* reserved */
867 { .type = S3C_IRQTYPE_NONE }, /* reserved */
868 { .type = S3C_IRQTYPE_NONE }, /* reserved */
869 { .type = S3C_IRQTYPE_NONE }, /* reserved */
870 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 16 }, /* LCD2 */
871 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 16 }, /* LCD3 */
872 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 16 }, /* LCD4 */
873 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 17 }, /* DMA0 */
874 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 17 }, /* DMA1 */
875 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 17 }, /* DMA2 */
876 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 17 }, /* DMA3 */
877 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 17 }, /* DMA4 */
878 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 17 }, /* DMA5 */
879 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 18 }, /* UART3-RX */
880 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 18 }, /* UART3-TX */
881 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 18 }, /* UART3-ERR */
882 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 9 }, /* WDT */
883 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 9 }, /* AC97 */
884};
885
886static struct s3c_irq_data init_s3c2416_second[32] = {
887 { .type = S3C_IRQTYPE_EDGE }, /* 2D */
888 { .type = S3C_IRQTYPE_NONE }, /* reserved */
889 { .type = S3C_IRQTYPE_NONE }, /* reserved */
890 { .type = S3C_IRQTYPE_NONE }, /* reserved */
891 { .type = S3C_IRQTYPE_EDGE }, /* PCM0 */
892 { .type = S3C_IRQTYPE_NONE }, /* reserved */
893 { .type = S3C_IRQTYPE_EDGE }, /* I2S0 */
894};
895
896void __init s3c2416_init_irq(void)
897{
898 pr_info("S3C2416: IRQ Support\n");
899
900#ifdef CONFIG_FIQ
901 init_FIQ(FIQ_START);
902#endif
903
904 s3c_intc[0] = s3c24xx_init_intc(NULL, &init_s3c2416base[0], NULL,
905 0x4a000000);
906 if (IS_ERR(s3c_intc[0])) {
907 pr_err("irq: could not create main interrupt controller\n");
908 return;
909 }
910
911 s3c24xx_init_intc(NULL, &init_eint[0], s3c_intc[0], 0x560000a4);
912 s3c_intc[1] = s3c24xx_init_intc(NULL, &init_s3c2416subint[0],
913 s3c_intc[0], 0x4a000018);
914
915 s3c_intc[2] = s3c24xx_init_intc(NULL, &init_s3c2416_second[0],
916 NULL, 0x4a000040);
917}
918
919#endif
920
921#ifdef CONFIG_CPU_S3C2440
922static struct s3c_irq_data init_s3c2440base[32] = {
923 { .type = S3C_IRQTYPE_EINT, }, /* EINT0 */
924 { .type = S3C_IRQTYPE_EINT, }, /* EINT1 */
925 { .type = S3C_IRQTYPE_EINT, }, /* EINT2 */
926 { .type = S3C_IRQTYPE_EINT, }, /* EINT3 */
927 { .type = S3C_IRQTYPE_LEVEL, }, /* EINT4to7 */
928 { .type = S3C_IRQTYPE_LEVEL, }, /* EINT8to23 */
929 { .type = S3C_IRQTYPE_LEVEL, }, /* CAM */
930 { .type = S3C_IRQTYPE_EDGE, }, /* nBATT_FLT */
931 { .type = S3C_IRQTYPE_EDGE, }, /* TICK */
932 { .type = S3C_IRQTYPE_LEVEL, }, /* WDT/AC97 */
933 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER0 */
934 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER1 */
935 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER2 */
936 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER3 */
937 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER4 */
938 { .type = S3C_IRQTYPE_LEVEL, }, /* UART2 */
939 { .type = S3C_IRQTYPE_EDGE, }, /* LCD */
940 { .type = S3C_IRQTYPE_EDGE, }, /* DMA0 */
941 { .type = S3C_IRQTYPE_EDGE, }, /* DMA1 */
942 { .type = S3C_IRQTYPE_EDGE, }, /* DMA2 */
943 { .type = S3C_IRQTYPE_EDGE, }, /* DMA3 */
944 { .type = S3C_IRQTYPE_EDGE, }, /* SDI */
945 { .type = S3C_IRQTYPE_EDGE, }, /* SPI0 */
946 { .type = S3C_IRQTYPE_LEVEL, }, /* UART1 */
947 { .type = S3C_IRQTYPE_LEVEL, }, /* NFCON */
948 { .type = S3C_IRQTYPE_EDGE, }, /* USBD */
949 { .type = S3C_IRQTYPE_EDGE, }, /* USBH */
950 { .type = S3C_IRQTYPE_EDGE, }, /* IIC */
951 { .type = S3C_IRQTYPE_LEVEL, }, /* UART0 */
952 { .type = S3C_IRQTYPE_EDGE, }, /* SPI1 */
953 { .type = S3C_IRQTYPE_EDGE, }, /* RTC */
954 { .type = S3C_IRQTYPE_LEVEL, }, /* ADCPARENT */
955};
956
957static struct s3c_irq_data init_s3c2440subint[32] = {
958 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 28 }, /* UART0-RX */
959 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 28 }, /* UART0-TX */
960 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 28 }, /* UART0-ERR */
961 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 23 }, /* UART1-RX */
962 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 23 }, /* UART1-TX */
963 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 23 }, /* UART1-ERR */
964 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 15 }, /* UART2-RX */
965 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 15 }, /* UART2-TX */
966 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 15 }, /* UART2-ERR */
967 { .type = S3C_IRQTYPE_EDGE, .parent_irq = 31 }, /* TC */
968 { .type = S3C_IRQTYPE_EDGE, .parent_irq = 31 }, /* ADC */
969 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 6 }, /* CAM_C */
970 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 6 }, /* CAM_P */
971 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 9 }, /* WDT */
972 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 9 }, /* AC97 */
973};
974
975void __init s3c2440_init_irq(void)
976{
977 pr_info("S3C2440: IRQ Support\n");
978
979#ifdef CONFIG_FIQ
980 init_FIQ(FIQ_START);
981#endif
982
983 s3c_intc[0] = s3c24xx_init_intc(NULL, &init_s3c2440base[0], NULL,
984 0x4a000000);
985 if (IS_ERR(s3c_intc[0])) {
986 pr_err("irq: could not create main interrupt controller\n");
987 return;
988 }
989
990 s3c24xx_init_intc(NULL, &init_eint[0], s3c_intc[0], 0x560000a4);
991 s3c_intc[1] = s3c24xx_init_intc(NULL, &init_s3c2440subint[0],
992 s3c_intc[0], 0x4a000018);
993}
994#endif
995
996#ifdef CONFIG_CPU_S3C2442
997static struct s3c_irq_data init_s3c2442base[32] = {
998 { .type = S3C_IRQTYPE_EINT, }, /* EINT0 */
999 { .type = S3C_IRQTYPE_EINT, }, /* EINT1 */
1000 { .type = S3C_IRQTYPE_EINT, }, /* EINT2 */
1001 { .type = S3C_IRQTYPE_EINT, }, /* EINT3 */
1002 { .type = S3C_IRQTYPE_LEVEL, }, /* EINT4to7 */
1003 { .type = S3C_IRQTYPE_LEVEL, }, /* EINT8to23 */
1004 { .type = S3C_IRQTYPE_LEVEL, }, /* CAM */
1005 { .type = S3C_IRQTYPE_EDGE, }, /* nBATT_FLT */
1006 { .type = S3C_IRQTYPE_EDGE, }, /* TICK */
1007 { .type = S3C_IRQTYPE_EDGE, }, /* WDT */
1008 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER0 */
1009 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER1 */
1010 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER2 */
1011 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER3 */
1012 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER4 */
1013 { .type = S3C_IRQTYPE_LEVEL, }, /* UART2 */
1014 { .type = S3C_IRQTYPE_EDGE, }, /* LCD */
1015 { .type = S3C_IRQTYPE_EDGE, }, /* DMA0 */
1016 { .type = S3C_IRQTYPE_EDGE, }, /* DMA1 */
1017 { .type = S3C_IRQTYPE_EDGE, }, /* DMA2 */
1018 { .type = S3C_IRQTYPE_EDGE, }, /* DMA3 */
1019 { .type = S3C_IRQTYPE_EDGE, }, /* SDI */
1020 { .type = S3C_IRQTYPE_EDGE, }, /* SPI0 */
1021 { .type = S3C_IRQTYPE_LEVEL, }, /* UART1 */
1022 { .type = S3C_IRQTYPE_LEVEL, }, /* NFCON */
1023 { .type = S3C_IRQTYPE_EDGE, }, /* USBD */
1024 { .type = S3C_IRQTYPE_EDGE, }, /* USBH */
1025 { .type = S3C_IRQTYPE_EDGE, }, /* IIC */
1026 { .type = S3C_IRQTYPE_LEVEL, }, /* UART0 */
1027 { .type = S3C_IRQTYPE_EDGE, }, /* SPI1 */
1028 { .type = S3C_IRQTYPE_EDGE, }, /* RTC */
1029 { .type = S3C_IRQTYPE_LEVEL, }, /* ADCPARENT */
1030};
1031
1032static struct s3c_irq_data init_s3c2442subint[32] = {
1033 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 28 }, /* UART0-RX */
1034 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 28 }, /* UART0-TX */
1035 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 28 }, /* UART0-ERR */
1036 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 23 }, /* UART1-RX */
1037 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 23 }, /* UART1-TX */
1038 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 23 }, /* UART1-ERR */
1039 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 15 }, /* UART2-RX */
1040 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 15 }, /* UART2-TX */
1041 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 15 }, /* UART2-ERR */
1042 { .type = S3C_IRQTYPE_EDGE, .parent_irq = 31 }, /* TC */
1043 { .type = S3C_IRQTYPE_EDGE, .parent_irq = 31 }, /* ADC */
1044 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 6 }, /* CAM_C */
1045 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 6 }, /* CAM_P */
1046};
1047
1048void __init s3c2442_init_irq(void)
1049{
1050 pr_info("S3C2442: IRQ Support\n");
1051
1052#ifdef CONFIG_FIQ
1053 init_FIQ(FIQ_START);
1054#endif
1055
1056 s3c_intc[0] = s3c24xx_init_intc(NULL, &init_s3c2442base[0], NULL,
1057 0x4a000000);
1058 if (IS_ERR(s3c_intc[0])) {
1059 pr_err("irq: could not create main interrupt controller\n");
1060 return;
1061 }
1062
1063 s3c24xx_init_intc(NULL, &init_eint[0], s3c_intc[0], 0x560000a4);
1064 s3c_intc[1] = s3c24xx_init_intc(NULL, &init_s3c2442subint[0],
1065 s3c_intc[0], 0x4a000018);
1066}
1067#endif
1068
1069#ifdef CONFIG_CPU_S3C2443
1070static struct s3c_irq_data init_s3c2443base[32] = {
1071 { .type = S3C_IRQTYPE_EINT, }, /* EINT0 */
1072 { .type = S3C_IRQTYPE_EINT, }, /* EINT1 */
1073 { .type = S3C_IRQTYPE_EINT, }, /* EINT2 */
1074 { .type = S3C_IRQTYPE_EINT, }, /* EINT3 */
1075 { .type = S3C_IRQTYPE_LEVEL, }, /* EINT4to7 */
1076 { .type = S3C_IRQTYPE_LEVEL, }, /* EINT8to23 */
1077 { .type = S3C_IRQTYPE_LEVEL, }, /* CAM */
1078 { .type = S3C_IRQTYPE_EDGE, }, /* nBATT_FLT */
1079 { .type = S3C_IRQTYPE_EDGE, }, /* TICK */
1080 { .type = S3C_IRQTYPE_LEVEL, }, /* WDT/AC97 */
1081 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER0 */
1082 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER1 */
1083 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER2 */
1084 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER3 */
1085 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER4 */
1086 { .type = S3C_IRQTYPE_LEVEL, }, /* UART2 */
1087 { .type = S3C_IRQTYPE_LEVEL, }, /* LCD */
1088 { .type = S3C_IRQTYPE_LEVEL, }, /* DMA */
1089 { .type = S3C_IRQTYPE_LEVEL, }, /* UART3 */
1090 { .type = S3C_IRQTYPE_EDGE, }, /* CFON */
1091 { .type = S3C_IRQTYPE_EDGE, }, /* SDI1 */
1092 { .type = S3C_IRQTYPE_EDGE, }, /* SDI0 */
1093 { .type = S3C_IRQTYPE_EDGE, }, /* SPI0 */
1094 { .type = S3C_IRQTYPE_LEVEL, }, /* UART1 */
1095 { .type = S3C_IRQTYPE_EDGE, }, /* NAND */
1096 { .type = S3C_IRQTYPE_EDGE, }, /* USBD */
1097 { .type = S3C_IRQTYPE_EDGE, }, /* USBH */
1098 { .type = S3C_IRQTYPE_EDGE, }, /* IIC */
1099 { .type = S3C_IRQTYPE_LEVEL, }, /* UART0 */
1100 { .type = S3C_IRQTYPE_EDGE, }, /* SPI1 */
1101 { .type = S3C_IRQTYPE_EDGE, }, /* RTC */
1102 { .type = S3C_IRQTYPE_LEVEL, }, /* ADCPARENT */
1103};
1104
1105
1106static struct s3c_irq_data init_s3c2443subint[32] = {
1107 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 28 }, /* UART0-RX */
1108 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 28 }, /* UART0-TX */
1109 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 28 }, /* UART0-ERR */
1110 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 23 }, /* UART1-RX */
1111 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 23 }, /* UART1-TX */
1112 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 23 }, /* UART1-ERR */
1113 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 15 }, /* UART2-RX */
1114 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 15 }, /* UART2-TX */
1115 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 15 }, /* UART2-ERR */
1116 { .type = S3C_IRQTYPE_EDGE, .parent_irq = 31 }, /* TC */
1117 { .type = S3C_IRQTYPE_EDGE, .parent_irq = 31 }, /* ADC */
1118 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 6 }, /* CAM_C */
1119 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 6 }, /* CAM_P */
1120 { .type = S3C_IRQTYPE_NONE }, /* reserved */
1121 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 16 }, /* LCD1 */
1122 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 16 }, /* LCD2 */
1123 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 16 }, /* LCD3 */
1124 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 16 }, /* LCD4 */
1125 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 17 }, /* DMA0 */
1126 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 17 }, /* DMA1 */
1127 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 17 }, /* DMA2 */
1128 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 17 }, /* DMA3 */
1129 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 17 }, /* DMA4 */
1130 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 17 }, /* DMA5 */
1131 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 18 }, /* UART3-RX */
1132 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 18 }, /* UART3-TX */
1133 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 18 }, /* UART3-ERR */
1134 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 9 }, /* WDT */
1135 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 9 }, /* AC97 */
1136};
1137
1138void __init s3c2443_init_irq(void)
1139{
1140 pr_info("S3C2443: IRQ Support\n");
1141
1142#ifdef CONFIG_FIQ
1143 init_FIQ(FIQ_START);
1144#endif
1145
1146 s3c_intc[0] = s3c24xx_init_intc(NULL, &init_s3c2443base[0], NULL,
1147 0x4a000000);
1148 if (IS_ERR(s3c_intc[0])) {
1149 pr_err("irq: could not create main interrupt controller\n");
1150 return;
1151 }
1152
1153 s3c24xx_init_intc(NULL, &init_eint[0], s3c_intc[0], 0x560000a4);
1154 s3c_intc[1] = s3c24xx_init_intc(NULL, &init_s3c2443subint[0],
1155 s3c_intc[0], 0x4a000018);
1156}
1157#endif
1158
1159#ifdef CONFIG_OF
1160static int s3c24xx_irq_map_of(struct irq_domain *h, unsigned int virq,
1161 irq_hw_number_t hw)
1162{
1163 unsigned int ctrl_num = hw / 32;
1164 unsigned int intc_hw = hw % 32;
1165 struct s3c_irq_intc *intc = s3c_intc[ctrl_num];
1166 struct s3c_irq_intc *parent_intc = intc->parent;
1167 struct s3c_irq_data *irq_data = &intc->irqs[intc_hw];
1168
1169 /* attach controller pointer to irq_data */
1170 irq_data->intc = intc;
1171 irq_data->offset = intc_hw;
1172
1173 if (!parent_intc)
1174 irq_set_chip_and_handler(virq, &s3c_irq_chip, handle_edge_irq);
1175 else
1176 irq_set_chip_and_handler(virq, &s3c_irq_level_chip,
1177 handle_edge_irq);
1178
1179 irq_set_chip_data(virq, irq_data);
1180
1181 set_irq_flags(virq, IRQF_VALID);
1182
1183 return 0;
1184}
1185
1186/* Translate our of irq notation
1187 * format: <ctrl_num ctrl_irq parent_irq type>
1188 */
1189static int s3c24xx_irq_xlate_of(struct irq_domain *d, struct device_node *n,
1190 const u32 *intspec, unsigned int intsize,
1191 irq_hw_number_t *out_hwirq, unsigned int *out_type)
1192{
1193 struct s3c_irq_intc *intc;
1194 struct s3c_irq_intc *parent_intc;
1195 struct s3c_irq_data *irq_data;
1196 struct s3c_irq_data *parent_irq_data;
1197 int irqno;
1198
1199 if (WARN_ON(intsize < 4))
1200 return -EINVAL;
1201
1202 if (intspec[0] > 2 || !s3c_intc[intspec[0]]) {
1203 pr_err("controller number %d invalid\n", intspec[0]);
1204 return -EINVAL;
1205 }
1206 intc = s3c_intc[intspec[0]];
1207
1208 *out_hwirq = intspec[0] * 32 + intspec[2];
1209 *out_type = intspec[3] & IRQ_TYPE_SENSE_MASK;
1210
1211 parent_intc = intc->parent;
1212 if (parent_intc) {
1213 irq_data = &intc->irqs[intspec[2]];
1214 irq_data->parent_irq = intspec[1];
1215 parent_irq_data = &parent_intc->irqs[irq_data->parent_irq];
1216 parent_irq_data->sub_intc = intc;
1217 parent_irq_data->sub_bits |= (1UL << intspec[2]);
1218
1219 /* parent_intc is always s3c_intc[0], so no offset */
1220 irqno = irq_create_mapping(parent_intc->domain, intspec[1]);
1221 if (irqno < 0) {
1222 pr_err("irq: could not map parent interrupt\n");
1223 return irqno;
1224 }
1225
1226 irq_set_chained_handler(irqno, s3c_irq_demux);
1227 }
1228
1229 return 0;
1230}
1231
1232static struct irq_domain_ops s3c24xx_irq_ops_of = {
1233 .map = s3c24xx_irq_map_of,
1234 .xlate = s3c24xx_irq_xlate_of,
1235};
1236
1237struct s3c24xx_irq_of_ctrl {
1238 char *name;
1239 unsigned long offset;
1240 struct s3c_irq_intc **handle;
1241 struct s3c_irq_intc **parent;
1242 struct irq_domain_ops *ops;
1243};
1244
1245static int __init s3c_init_intc_of(struct device_node *np,
1246 struct device_node *interrupt_parent,
1247 struct s3c24xx_irq_of_ctrl *s3c_ctrl, int num_ctrl)
1248{
1249 struct s3c_irq_intc *intc;
1250 struct s3c24xx_irq_of_ctrl *ctrl;
1251 struct irq_domain *domain;
1252 void __iomem *reg_base;
1253 int i;
1254
1255 reg_base = of_iomap(np, 0);
1256 if (!reg_base) {
1257 pr_err("irq-s3c24xx: could not map irq registers\n");
1258 return -EINVAL;
1259 }
1260
1261 domain = irq_domain_add_linear(np, num_ctrl * 32,
1262 &s3c24xx_irq_ops_of, NULL);
1263 if (!domain) {
1264 pr_err("irq: could not create irq-domain\n");
1265 return -EINVAL;
1266 }
1267
1268 for (i = 0; i < num_ctrl; i++) {
1269 ctrl = &s3c_ctrl[i];
1270
1271 pr_debug("irq: found controller %s\n", ctrl->name);
1272
1273 intc = kzalloc(sizeof(struct s3c_irq_intc), GFP_KERNEL);
1274 if (!intc)
1275 return -ENOMEM;
1276
1277 intc->domain = domain;
1278 intc->irqs = kzalloc(sizeof(struct s3c_irq_data) * 32,
1279 GFP_KERNEL);
1280 if (!intc->irqs) {
1281 kfree(intc);
1282 return -ENOMEM;
1283 }
1284
1285 if (ctrl->parent) {
1286 intc->reg_pending = reg_base + ctrl->offset;
1287 intc->reg_mask = reg_base + ctrl->offset + 0x4;
1288
1289 if (*(ctrl->parent)) {
1290 intc->parent = *(ctrl->parent);
1291 } else {
1292 pr_warn("irq: parent of %s missing\n",
1293 ctrl->name);
1294 kfree(intc->irqs);
1295 kfree(intc);
1296 continue;
1297 }
1298 } else {
1299 intc->reg_pending = reg_base + ctrl->offset;
1300 intc->reg_mask = reg_base + ctrl->offset + 0x08;
1301 intc->reg_intpnd = reg_base + ctrl->offset + 0x10;
1302 }
1303
1304 s3c24xx_clear_intc(intc);
1305 s3c_intc[i] = intc;
1306 }
1307
1308 set_handle_irq(s3c24xx_handle_irq);
1309
1310 return 0;
1311}
1312
1313static struct s3c24xx_irq_of_ctrl s3c2410_ctrl[] = {
1314 {
1315 .name = "intc",
1316 .offset = 0,
1317 }, {
1318 .name = "subintc",
1319 .offset = 0x18,
1320 .parent = &s3c_intc[0],
1321 }
1322};
1323
1324int __init s3c2410_init_intc_of(struct device_node *np,
1325 struct device_node *interrupt_parent,
1326 struct s3c24xx_irq_of_ctrl *ctrl, int num_ctrl)
1327{
1328 return s3c_init_intc_of(np, interrupt_parent,
1329 s3c2410_ctrl, ARRAY_SIZE(s3c2410_ctrl));
1330}
1331IRQCHIP_DECLARE(s3c2410_irq, "samsung,s3c2410-irq", s3c2410_init_intc_of);
1332
1333static struct s3c24xx_irq_of_ctrl s3c2416_ctrl[] = {
1334 {
1335 .name = "intc",
1336 .offset = 0,
1337 }, {
1338 .name = "subintc",
1339 .offset = 0x18,
1340 .parent = &s3c_intc[0],
1341 }, {
1342 .name = "intc2",
1343 .offset = 0x40,
1344 }
1345};
1346
1347int __init s3c2416_init_intc_of(struct device_node *np,
1348 struct device_node *interrupt_parent,
1349 struct s3c24xx_irq_of_ctrl *ctrl, int num_ctrl)
1350{
1351 return s3c_init_intc_of(np, interrupt_parent,
1352 s3c2416_ctrl, ARRAY_SIZE(s3c2416_ctrl));
1353}
1354IRQCHIP_DECLARE(s3c2416_irq, "samsung,s3c2416-irq", s3c2416_init_intc_of);
1355#endif
diff --git a/drivers/mmc/host/s3cmci.c b/drivers/mmc/host/s3cmci.c
index 63fb265e0da6..8d6794cdf899 100644
--- a/drivers/mmc/host/s3cmci.c
+++ b/drivers/mmc/host/s3cmci.c
@@ -25,14 +25,93 @@
25 25
26#include <mach/dma.h> 26#include <mach/dma.h>
27 27
28#include <mach/regs-sdi.h>
29
30#include <linux/platform_data/mmc-s3cmci.h> 28#include <linux/platform_data/mmc-s3cmci.h>
31 29
32#include "s3cmci.h" 30#include "s3cmci.h"
33 31
34#define DRIVER_NAME "s3c-mci" 32#define DRIVER_NAME "s3c-mci"
35 33
34#define S3C2410_SDICON (0x00)
35#define S3C2410_SDIPRE (0x04)
36#define S3C2410_SDICMDARG (0x08)
37#define S3C2410_SDICMDCON (0x0C)
38#define S3C2410_SDICMDSTAT (0x10)
39#define S3C2410_SDIRSP0 (0x14)
40#define S3C2410_SDIRSP1 (0x18)
41#define S3C2410_SDIRSP2 (0x1C)
42#define S3C2410_SDIRSP3 (0x20)
43#define S3C2410_SDITIMER (0x24)
44#define S3C2410_SDIBSIZE (0x28)
45#define S3C2410_SDIDCON (0x2C)
46#define S3C2410_SDIDCNT (0x30)
47#define S3C2410_SDIDSTA (0x34)
48#define S3C2410_SDIFSTA (0x38)
49
50#define S3C2410_SDIDATA (0x3C)
51#define S3C2410_SDIIMSK (0x40)
52
53#define S3C2440_SDIDATA (0x40)
54#define S3C2440_SDIIMSK (0x3C)
55
56#define S3C2440_SDICON_SDRESET (1 << 8)
57#define S3C2410_SDICON_SDIOIRQ (1 << 3)
58#define S3C2410_SDICON_FIFORESET (1 << 1)
59#define S3C2410_SDICON_CLOCKTYPE (1 << 0)
60
61#define S3C2410_SDICMDCON_LONGRSP (1 << 10)
62#define S3C2410_SDICMDCON_WAITRSP (1 << 9)
63#define S3C2410_SDICMDCON_CMDSTART (1 << 8)
64#define S3C2410_SDICMDCON_SENDERHOST (1 << 6)
65#define S3C2410_SDICMDCON_INDEX (0x3f)
66
67#define S3C2410_SDICMDSTAT_CRCFAIL (1 << 12)
68#define S3C2410_SDICMDSTAT_CMDSENT (1 << 11)
69#define S3C2410_SDICMDSTAT_CMDTIMEOUT (1 << 10)
70#define S3C2410_SDICMDSTAT_RSPFIN (1 << 9)
71
72#define S3C2440_SDIDCON_DS_WORD (2 << 22)
73#define S3C2410_SDIDCON_TXAFTERRESP (1 << 20)
74#define S3C2410_SDIDCON_RXAFTERCMD (1 << 19)
75#define S3C2410_SDIDCON_BLOCKMODE (1 << 17)
76#define S3C2410_SDIDCON_WIDEBUS (1 << 16)
77#define S3C2410_SDIDCON_DMAEN (1 << 15)
78#define S3C2410_SDIDCON_STOP (1 << 14)
79#define S3C2440_SDIDCON_DATSTART (1 << 14)
80
81#define S3C2410_SDIDCON_XFER_RXSTART (2 << 12)
82#define S3C2410_SDIDCON_XFER_TXSTART (3 << 12)
83
84#define S3C2410_SDIDCON_BLKNUM_MASK (0xFFF)
85
86#define S3C2410_SDIDSTA_SDIOIRQDETECT (1 << 9)
87#define S3C2410_SDIDSTA_FIFOFAIL (1 << 8)
88#define S3C2410_SDIDSTA_CRCFAIL (1 << 7)
89#define S3C2410_SDIDSTA_RXCRCFAIL (1 << 6)
90#define S3C2410_SDIDSTA_DATATIMEOUT (1 << 5)
91#define S3C2410_SDIDSTA_XFERFINISH (1 << 4)
92#define S3C2410_SDIDSTA_TXDATAON (1 << 1)
93#define S3C2410_SDIDSTA_RXDATAON (1 << 0)
94
95#define S3C2440_SDIFSTA_FIFORESET (1 << 16)
96#define S3C2440_SDIFSTA_FIFOFAIL (3 << 14)
97#define S3C2410_SDIFSTA_TFDET (1 << 13)
98#define S3C2410_SDIFSTA_RFDET (1 << 12)
99#define S3C2410_SDIFSTA_COUNTMASK (0x7f)
100
101#define S3C2410_SDIIMSK_RESPONSECRC (1 << 17)
102#define S3C2410_SDIIMSK_CMDSENT (1 << 16)
103#define S3C2410_SDIIMSK_CMDTIMEOUT (1 << 15)
104#define S3C2410_SDIIMSK_RESPONSEND (1 << 14)
105#define S3C2410_SDIIMSK_SDIOIRQ (1 << 12)
106#define S3C2410_SDIIMSK_FIFOFAIL (1 << 11)
107#define S3C2410_SDIIMSK_CRCSTATUS (1 << 10)
108#define S3C2410_SDIIMSK_DATACRC (1 << 9)
109#define S3C2410_SDIIMSK_DATATIMEOUT (1 << 8)
110#define S3C2410_SDIIMSK_DATAFINISH (1 << 7)
111#define S3C2410_SDIIMSK_TXFIFOHALF (1 << 4)
112#define S3C2410_SDIIMSK_RXFIFOLAST (1 << 2)
113#define S3C2410_SDIIMSK_RXFIFOHALF (1 << 0)
114
36enum dbg_channels { 115enum dbg_channels {
37 dbg_err = (1 << 0), 116 dbg_err = (1 << 0),
38 dbg_debug = (1 << 1), 117 dbg_debug = (1 << 1),
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 321d3ef05006..c6443de58fb0 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -746,6 +746,64 @@ struct device_node *of_find_node_by_phandle(phandle handle)
746EXPORT_SYMBOL(of_find_node_by_phandle); 746EXPORT_SYMBOL(of_find_node_by_phandle);
747 747
748/** 748/**
749 * of_find_property_value_of_size
750 *
751 * @np: device node from which the property value is to be read.
752 * @propname: name of the property to be searched.
753 * @len: requested length of property value
754 *
755 * Search for a property in a device node and valid the requested size.
756 * Returns the property value on success, -EINVAL if the property does not
757 * exist, -ENODATA if property does not have a value, and -EOVERFLOW if the
758 * property data isn't large enough.
759 *
760 */
761static void *of_find_property_value_of_size(const struct device_node *np,
762 const char *propname, u32 len)
763{
764 struct property *prop = of_find_property(np, propname, NULL);
765
766 if (!prop)
767 return ERR_PTR(-EINVAL);
768 if (!prop->value)
769 return ERR_PTR(-ENODATA);
770 if (len > prop->length)
771 return ERR_PTR(-EOVERFLOW);
772
773 return prop->value;
774}
775
776/**
777 * of_property_read_u32_index - Find and read a u32 from a multi-value property.
778 *
779 * @np: device node from which the property value is to be read.
780 * @propname: name of the property to be searched.
781 * @index: index of the u32 in the list of values
782 * @out_value: pointer to return value, modified only if no error.
783 *
784 * Search for a property in a device node and read nth 32-bit value from
785 * it. Returns 0 on success, -EINVAL if the property does not exist,
786 * -ENODATA if property does not have a value, and -EOVERFLOW if the
787 * property data isn't large enough.
788 *
789 * The out_value is modified only if a valid u32 value can be decoded.
790 */
791int of_property_read_u32_index(const struct device_node *np,
792 const char *propname,
793 u32 index, u32 *out_value)
794{
795 const u32 *val = of_find_property_value_of_size(np, propname,
796 ((index + 1) * sizeof(*out_value)));
797
798 if (IS_ERR(val))
799 return PTR_ERR(val);
800
801 *out_value = be32_to_cpup(((__be32 *)val) + index);
802 return 0;
803}
804EXPORT_SYMBOL_GPL(of_property_read_u32_index);
805
806/**
749 * of_property_read_u8_array - Find and read an array of u8 from a property. 807 * of_property_read_u8_array - Find and read an array of u8 from a property.
750 * 808 *
751 * @np: device node from which the property value is to be read. 809 * @np: device node from which the property value is to be read.
@@ -766,17 +824,12 @@ EXPORT_SYMBOL(of_find_node_by_phandle);
766int of_property_read_u8_array(const struct device_node *np, 824int of_property_read_u8_array(const struct device_node *np,
767 const char *propname, u8 *out_values, size_t sz) 825 const char *propname, u8 *out_values, size_t sz)
768{ 826{
769 struct property *prop = of_find_property(np, propname, NULL); 827 const u8 *val = of_find_property_value_of_size(np, propname,
770 const u8 *val; 828 (sz * sizeof(*out_values)));
771 829
772 if (!prop) 830 if (IS_ERR(val))
773 return -EINVAL; 831 return PTR_ERR(val);
774 if (!prop->value)
775 return -ENODATA;
776 if ((sz * sizeof(*out_values)) > prop->length)
777 return -EOVERFLOW;
778 832
779 val = prop->value;
780 while (sz--) 833 while (sz--)
781 *out_values++ = *val++; 834 *out_values++ = *val++;
782 return 0; 835 return 0;
@@ -804,17 +857,12 @@ EXPORT_SYMBOL_GPL(of_property_read_u8_array);
804int of_property_read_u16_array(const struct device_node *np, 857int of_property_read_u16_array(const struct device_node *np,
805 const char *propname, u16 *out_values, size_t sz) 858 const char *propname, u16 *out_values, size_t sz)
806{ 859{
807 struct property *prop = of_find_property(np, propname, NULL); 860 const __be16 *val = of_find_property_value_of_size(np, propname,
808 const __be16 *val; 861 (sz * sizeof(*out_values)));
809 862
810 if (!prop) 863 if (IS_ERR(val))
811 return -EINVAL; 864 return PTR_ERR(val);
812 if (!prop->value)
813 return -ENODATA;
814 if ((sz * sizeof(*out_values)) > prop->length)
815 return -EOVERFLOW;
816 865
817 val = prop->value;
818 while (sz--) 866 while (sz--)
819 *out_values++ = be16_to_cpup(val++); 867 *out_values++ = be16_to_cpup(val++);
820 return 0; 868 return 0;
@@ -841,17 +889,12 @@ int of_property_read_u32_array(const struct device_node *np,
841 const char *propname, u32 *out_values, 889 const char *propname, u32 *out_values,
842 size_t sz) 890 size_t sz)
843{ 891{
844 struct property *prop = of_find_property(np, propname, NULL); 892 const __be32 *val = of_find_property_value_of_size(np, propname,
845 const __be32 *val; 893 (sz * sizeof(*out_values)));
846 894
847 if (!prop) 895 if (IS_ERR(val))
848 return -EINVAL; 896 return PTR_ERR(val);
849 if (!prop->value)
850 return -ENODATA;
851 if ((sz * sizeof(*out_values)) > prop->length)
852 return -EOVERFLOW;
853 897
854 val = prop->value;
855 while (sz--) 898 while (sz--)
856 *out_values++ = be32_to_cpup(val++); 899 *out_values++ = be32_to_cpup(val++);
857 return 0; 900 return 0;
@@ -874,15 +917,13 @@ EXPORT_SYMBOL_GPL(of_property_read_u32_array);
874int of_property_read_u64(const struct device_node *np, const char *propname, 917int of_property_read_u64(const struct device_node *np, const char *propname,
875 u64 *out_value) 918 u64 *out_value)
876{ 919{
877 struct property *prop = of_find_property(np, propname, NULL); 920 const __be32 *val = of_find_property_value_of_size(np, propname,
921 sizeof(*out_value));
878 922
879 if (!prop) 923 if (IS_ERR(val))
880 return -EINVAL; 924 return PTR_ERR(val);
881 if (!prop->value) 925
882 return -ENODATA; 926 *out_value = of_read_number(val, 2);
883 if (sizeof(*out_value) > prop->length)
884 return -EOVERFLOW;
885 *out_value = of_read_number(prop->value, 2);
886 return 0; 927 return 0;
887} 928}
888EXPORT_SYMBOL_GPL(of_property_read_u64); 929EXPORT_SYMBOL_GPL(of_property_read_u64);
diff --git a/drivers/pinctrl/Kconfig b/drivers/pinctrl/Kconfig
index 34f51d2d90d2..35e94009829b 100644
--- a/drivers/pinctrl/Kconfig
+++ b/drivers/pinctrl/Kconfig
@@ -229,6 +229,7 @@ config PINCTRL_EXYNOS5440
229source "drivers/pinctrl/mvebu/Kconfig" 229source "drivers/pinctrl/mvebu/Kconfig"
230source "drivers/pinctrl/sh-pfc/Kconfig" 230source "drivers/pinctrl/sh-pfc/Kconfig"
231source "drivers/pinctrl/spear/Kconfig" 231source "drivers/pinctrl/spear/Kconfig"
232source "drivers/pinctrl/vt8500/Kconfig"
232 233
233config PINCTRL_XWAY 234config PINCTRL_XWAY
234 bool 235 bool
diff --git a/drivers/pinctrl/Makefile b/drivers/pinctrl/Makefile
index f82cc5baf767..a5a52c83c13a 100644
--- a/drivers/pinctrl/Makefile
+++ b/drivers/pinctrl/Makefile
@@ -52,3 +52,4 @@ obj-$(CONFIG_PLAT_ORION) += mvebu/
52obj-$(CONFIG_ARCH_SHMOBILE) += sh-pfc/ 52obj-$(CONFIG_ARCH_SHMOBILE) += sh-pfc/
53obj-$(CONFIG_SUPERH) += sh-pfc/ 53obj-$(CONFIG_SUPERH) += sh-pfc/
54obj-$(CONFIG_PLAT_SPEAR) += spear/ 54obj-$(CONFIG_PLAT_SPEAR) += spear/
55obj-$(CONFIG_ARCH_VT8500) += vt8500/
diff --git a/drivers/pinctrl/pinctrl-bcm2835.c b/drivers/pinctrl/pinctrl-bcm2835.c
index 4eb6d2c4e4df..2a2e427d765e 100644
--- a/drivers/pinctrl/pinctrl-bcm2835.c
+++ b/drivers/pinctrl/pinctrl-bcm2835.c
@@ -699,11 +699,6 @@ static int bcm2835_pctl_dt_node_to_map_pull(struct bcm2835_pinctrl *pc,
699 return 0; 699 return 0;
700} 700}
701 701
702static inline u32 prop_u32(struct property *p, int i)
703{
704 return be32_to_cpup(((__be32 *)p->value) + i);
705}
706
707static int bcm2835_pctl_dt_node_to_map(struct pinctrl_dev *pctldev, 702static int bcm2835_pctl_dt_node_to_map(struct pinctrl_dev *pctldev,
708 struct device_node *np, 703 struct device_node *np,
709 struct pinctrl_map **map, unsigned *num_maps) 704 struct pinctrl_map **map, unsigned *num_maps)
@@ -761,7 +756,9 @@ static int bcm2835_pctl_dt_node_to_map(struct pinctrl_dev *pctldev,
761 return -ENOMEM; 756 return -ENOMEM;
762 757
763 for (i = 0; i < num_pins; i++) { 758 for (i = 0; i < num_pins; i++) {
764 pin = prop_u32(pins, i); 759 err = of_property_read_u32_index(np, "brcm,pins", i, &pin);
760 if (err)
761 goto out;
765 if (pin >= ARRAY_SIZE(bcm2835_gpio_pins)) { 762 if (pin >= ARRAY_SIZE(bcm2835_gpio_pins)) {
766 dev_err(pc->dev, "%s: invalid brcm,pins value %d\n", 763 dev_err(pc->dev, "%s: invalid brcm,pins value %d\n",
767 of_node_full_name(np), pin); 764 of_node_full_name(np), pin);
@@ -770,14 +767,20 @@ static int bcm2835_pctl_dt_node_to_map(struct pinctrl_dev *pctldev,
770 } 767 }
771 768
772 if (num_funcs) { 769 if (num_funcs) {
773 func = prop_u32(funcs, (num_funcs > 1) ? i : 0); 770 err = of_property_read_u32_index(np, "brcm,function",
771 (num_funcs > 1) ? i : 0, &func);
772 if (err)
773 goto out;
774 err = bcm2835_pctl_dt_node_to_map_func(pc, np, pin, 774 err = bcm2835_pctl_dt_node_to_map_func(pc, np, pin,
775 func, &cur_map); 775 func, &cur_map);
776 if (err) 776 if (err)
777 goto out; 777 goto out;
778 } 778 }
779 if (num_pulls) { 779 if (num_pulls) {
780 pull = prop_u32(pulls, (num_pulls > 1) ? i : 0); 780 err = of_property_read_u32_index(np, "brcm,pull",
781 (num_funcs > 1) ? i : 0, &pull);
782 if (err)
783 goto out;
781 err = bcm2835_pctl_dt_node_to_map_pull(pc, np, pin, 784 err = bcm2835_pctl_dt_node_to_map_pull(pc, np, pin,
782 pull, &cur_map); 785 pull, &cur_map);
783 if (err) 786 if (err)
diff --git a/drivers/pinctrl/pinctrl-exynos.c b/drivers/pinctrl/pinctrl-exynos.c
index 538b9ddaadf7..8738933a57d7 100644
--- a/drivers/pinctrl/pinctrl-exynos.c
+++ b/drivers/pinctrl/pinctrl-exynos.c
@@ -677,3 +677,111 @@ struct samsung_pin_ctrl exynos4x12_pin_ctrl[] = {
677 .label = "exynos4x12-gpio-ctrl3", 677 .label = "exynos4x12-gpio-ctrl3",
678 }, 678 },
679}; 679};
680
681/* pin banks of exynos5250 pin-controller 0 */
682static struct samsung_pin_bank exynos5250_pin_banks0[] = {
683 EXYNOS_PIN_BANK_EINTG(8, 0x000, "gpa0", 0x00),
684 EXYNOS_PIN_BANK_EINTG(6, 0x020, "gpa1", 0x04),
685 EXYNOS_PIN_BANK_EINTG(8, 0x040, "gpa2", 0x08),
686 EXYNOS_PIN_BANK_EINTG(5, 0x060, "gpb0", 0x0c),
687 EXYNOS_PIN_BANK_EINTG(5, 0x080, "gpb1", 0x10),
688 EXYNOS_PIN_BANK_EINTG(4, 0x0A0, "gpb2", 0x14),
689 EXYNOS_PIN_BANK_EINTG(4, 0x0C0, "gpb3", 0x18),
690 EXYNOS_PIN_BANK_EINTG(7, 0x0E0, "gpc0", 0x1c),
691 EXYNOS_PIN_BANK_EINTG(4, 0x100, "gpc1", 0x20),
692 EXYNOS_PIN_BANK_EINTG(7, 0x120, "gpc2", 0x24),
693 EXYNOS_PIN_BANK_EINTG(7, 0x140, "gpc3", 0x28),
694 EXYNOS_PIN_BANK_EINTG(4, 0x160, "gpd0", 0x2c),
695 EXYNOS_PIN_BANK_EINTG(8, 0x180, "gpd1", 0x30),
696 EXYNOS_PIN_BANK_EINTG(7, 0x2E0, "gpc4", 0x34),
697 EXYNOS_PIN_BANK_EINTN(6, 0x1A0, "gpy0"),
698 EXYNOS_PIN_BANK_EINTN(4, 0x1C0, "gpy1"),
699 EXYNOS_PIN_BANK_EINTN(6, 0x1E0, "gpy2"),
700 EXYNOS_PIN_BANK_EINTN(8, 0x200, "gpy3"),
701 EXYNOS_PIN_BANK_EINTN(8, 0x220, "gpy4"),
702 EXYNOS_PIN_BANK_EINTN(8, 0x240, "gpy5"),
703 EXYNOS_PIN_BANK_EINTN(8, 0x260, "gpy6"),
704 EXYNOS_PIN_BANK_EINTW(8, 0xC00, "gpx0", 0x00),
705 EXYNOS_PIN_BANK_EINTW(8, 0xC20, "gpx1", 0x04),
706 EXYNOS_PIN_BANK_EINTW(8, 0xC40, "gpx2", 0x08),
707 EXYNOS_PIN_BANK_EINTW(8, 0xC60, "gpx3", 0x0c),
708};
709
710/* pin banks of exynos5250 pin-controller 1 */
711static struct samsung_pin_bank exynos5250_pin_banks1[] = {
712 EXYNOS_PIN_BANK_EINTG(8, 0x000, "gpe0", 0x00),
713 EXYNOS_PIN_BANK_EINTG(2, 0x020, "gpe1", 0x04),
714 EXYNOS_PIN_BANK_EINTG(4, 0x040, "gpf0", 0x08),
715 EXYNOS_PIN_BANK_EINTG(4, 0x060, "gpf1", 0x0c),
716 EXYNOS_PIN_BANK_EINTG(8, 0x080, "gpg0", 0x10),
717 EXYNOS_PIN_BANK_EINTG(8, 0x0A0, "gpg1", 0x14),
718 EXYNOS_PIN_BANK_EINTG(2, 0x0C0, "gpg2", 0x18),
719 EXYNOS_PIN_BANK_EINTG(4, 0x0E0, "gph0", 0x1c),
720 EXYNOS_PIN_BANK_EINTG(8, 0x100, "gph1", 0x20),
721};
722
723/* pin banks of exynos5250 pin-controller 2 */
724static struct samsung_pin_bank exynos5250_pin_banks2[] = {
725 EXYNOS_PIN_BANK_EINTG(8, 0x000, "gpv0", 0x00),
726 EXYNOS_PIN_BANK_EINTG(8, 0x020, "gpv1", 0x04),
727 EXYNOS_PIN_BANK_EINTG(8, 0x060, "gpv2", 0x08),
728 EXYNOS_PIN_BANK_EINTG(8, 0x080, "gpv3", 0x0c),
729 EXYNOS_PIN_BANK_EINTG(2, 0x0C0, "gpv4", 0x10),
730};
731
732/* pin banks of exynos5250 pin-controller 3 */
733static struct samsung_pin_bank exynos5250_pin_banks3[] = {
734 EXYNOS_PIN_BANK_EINTG(7, 0x000, "gpz", 0x00),
735};
736
737/*
738 * Samsung pinctrl driver data for Exynos5250 SoC. Exynos5250 SoC includes
739 * four gpio/pin-mux/pinconfig controllers.
740 */
741struct samsung_pin_ctrl exynos5250_pin_ctrl[] = {
742 {
743 /* pin-controller instance 0 data */
744 .pin_banks = exynos5250_pin_banks0,
745 .nr_banks = ARRAY_SIZE(exynos5250_pin_banks0),
746 .geint_con = EXYNOS_GPIO_ECON_OFFSET,
747 .geint_mask = EXYNOS_GPIO_EMASK_OFFSET,
748 .geint_pend = EXYNOS_GPIO_EPEND_OFFSET,
749 .weint_con = EXYNOS_WKUP_ECON_OFFSET,
750 .weint_mask = EXYNOS_WKUP_EMASK_OFFSET,
751 .weint_pend = EXYNOS_WKUP_EPEND_OFFSET,
752 .svc = EXYNOS_SVC_OFFSET,
753 .eint_gpio_init = exynos_eint_gpio_init,
754 .eint_wkup_init = exynos_eint_wkup_init,
755 .label = "exynos5250-gpio-ctrl0",
756 }, {
757 /* pin-controller instance 1 data */
758 .pin_banks = exynos5250_pin_banks1,
759 .nr_banks = ARRAY_SIZE(exynos5250_pin_banks1),
760 .geint_con = EXYNOS_GPIO_ECON_OFFSET,
761 .geint_mask = EXYNOS_GPIO_EMASK_OFFSET,
762 .geint_pend = EXYNOS_GPIO_EPEND_OFFSET,
763 .svc = EXYNOS_SVC_OFFSET,
764 .eint_gpio_init = exynos_eint_gpio_init,
765 .label = "exynos5250-gpio-ctrl1",
766 }, {
767 /* pin-controller instance 2 data */
768 .pin_banks = exynos5250_pin_banks2,
769 .nr_banks = ARRAY_SIZE(exynos5250_pin_banks2),
770 .geint_con = EXYNOS_GPIO_ECON_OFFSET,
771 .geint_mask = EXYNOS_GPIO_EMASK_OFFSET,
772 .geint_pend = EXYNOS_GPIO_EPEND_OFFSET,
773 .svc = EXYNOS_SVC_OFFSET,
774 .eint_gpio_init = exynos_eint_gpio_init,
775 .label = "exynos5250-gpio-ctrl2",
776 }, {
777 /* pin-controller instance 3 data */
778 .pin_banks = exynos5250_pin_banks3,
779 .nr_banks = ARRAY_SIZE(exynos5250_pin_banks3),
780 .geint_con = EXYNOS_GPIO_ECON_OFFSET,
781 .geint_mask = EXYNOS_GPIO_EMASK_OFFSET,
782 .geint_pend = EXYNOS_GPIO_EPEND_OFFSET,
783 .svc = EXYNOS_SVC_OFFSET,
784 .eint_gpio_init = exynos_eint_gpio_init,
785 .label = "exynos5250-gpio-ctrl3",
786 },
787};
diff --git a/drivers/pinctrl/pinctrl-samsung.c b/drivers/pinctrl/pinctrl-samsung.c
index f206df175656..3d5cf639aa46 100644
--- a/drivers/pinctrl/pinctrl-samsung.c
+++ b/drivers/pinctrl/pinctrl-samsung.c
@@ -948,6 +948,8 @@ static const struct of_device_id samsung_pinctrl_dt_match[] = {
948 .data = (void *)exynos4210_pin_ctrl }, 948 .data = (void *)exynos4210_pin_ctrl },
949 { .compatible = "samsung,exynos4x12-pinctrl", 949 { .compatible = "samsung,exynos4x12-pinctrl",
950 .data = (void *)exynos4x12_pin_ctrl }, 950 .data = (void *)exynos4x12_pin_ctrl },
951 { .compatible = "samsung,exynos5250-pinctrl",
952 .data = (void *)exynos5250_pin_ctrl },
951 {}, 953 {},
952}; 954};
953MODULE_DEVICE_TABLE(of, samsung_pinctrl_dt_match); 955MODULE_DEVICE_TABLE(of, samsung_pinctrl_dt_match);
diff --git a/drivers/pinctrl/pinctrl-samsung.h b/drivers/pinctrl/pinctrl-samsung.h
index e2d4e67f7e88..ee964aadce0c 100644
--- a/drivers/pinctrl/pinctrl-samsung.h
+++ b/drivers/pinctrl/pinctrl-samsung.h
@@ -237,5 +237,6 @@ struct samsung_pmx_func {
237/* list of all exported SoC specific data */ 237/* list of all exported SoC specific data */
238extern struct samsung_pin_ctrl exynos4210_pin_ctrl[]; 238extern struct samsung_pin_ctrl exynos4210_pin_ctrl[];
239extern struct samsung_pin_ctrl exynos4x12_pin_ctrl[]; 239extern struct samsung_pin_ctrl exynos4x12_pin_ctrl[];
240extern struct samsung_pin_ctrl exynos5250_pin_ctrl[];
240 241
241#endif /* __PINCTRL_SAMSUNG_H */ 242#endif /* __PINCTRL_SAMSUNG_H */
diff --git a/drivers/pinctrl/sh-pfc/pfc-sh73a0.c b/drivers/pinctrl/sh-pfc/pfc-sh73a0.c
index 709008e94124..6f15c03077a0 100644
--- a/drivers/pinctrl/sh-pfc/pfc-sh73a0.c
+++ b/drivers/pinctrl/sh-pfc/pfc-sh73a0.c
@@ -2733,9 +2733,9 @@ static struct pinmux_data_reg pinmux_data_regs[] = {
2733 { }, 2733 { },
2734}; 2734};
2735 2735
2736/* IRQ pins through INTCS with IRQ0->15 from 0x200 and IRQ16-31 from 0x3200 */ 2736/* External IRQ pins mapped at IRQPIN_BASE */
2737#define EXT_IRQ16L(n) intcs_evt2irq(0x200 + ((n) << 5)) 2737#define EXT_IRQ16L(n) irq_pin(n)
2738#define EXT_IRQ16H(n) intcs_evt2irq(0x3200 + ((n - 16) << 5)) 2738#define EXT_IRQ16H(n) irq_pin(n)
2739 2739
2740static struct pinmux_irq pinmux_irqs[] = { 2740static struct pinmux_irq pinmux_irqs[] = {
2741 PINMUX_IRQ(EXT_IRQ16H(19), PORT9_FN0), 2741 PINMUX_IRQ(EXT_IRQ16H(19), PORT9_FN0),
diff --git a/drivers/pinctrl/vt8500/Kconfig b/drivers/pinctrl/vt8500/Kconfig
new file mode 100644
index 000000000000..55724a73d94a
--- /dev/null
+++ b/drivers/pinctrl/vt8500/Kconfig
@@ -0,0 +1,52 @@
1#
2# VIA/Wondermedia PINCTRL drivers
3#
4
5if ARCH_VT8500
6
7config PINCTRL_WMT
8 bool
9 select PINMUX
10 select GENERIC_PINCONF
11
12config PINCTRL_VT8500
13 bool "VIA VT8500 pin controller driver"
14 depends on ARCH_WM8505
15 select PINCTRL_WMT
16 help
17 Say yes here to support the gpio/pin control module on
18 VIA VT8500 SoCs.
19
20config PINCTRL_WM8505
21 bool "Wondermedia WM8505 pin controller driver"
22 depends on ARCH_WM8505
23 select PINCTRL_WMT
24 help
25 Say yes here to support the gpio/pin control module on
26 Wondermedia WM8505 SoCs.
27
28config PINCTRL_WM8650
29 bool "Wondermedia WM8650 pin controller driver"
30 depends on ARCH_WM8505
31 select PINCTRL_WMT
32 help
33 Say yes here to support the gpio/pin control module on
34 Wondermedia WM8650 SoCs.
35
36config PINCTRL_WM8750
37 bool "Wondermedia WM8750 pin controller driver"
38 depends on ARCH_WM8750
39 select PINCTRL_WMT
40 help
41 Say yes here to support the gpio/pin control module on
42 Wondermedia WM8750 SoCs.
43
44config PINCTRL_WM8850
45 bool "Wondermedia WM8850 pin controller driver"
46 depends on ARCH_WM8850
47 select PINCTRL_WMT
48 help
49 Say yes here to support the gpio/pin control module on
50 Wondermedia WM8850 SoCs.
51
52endif
diff --git a/drivers/pinctrl/vt8500/Makefile b/drivers/pinctrl/vt8500/Makefile
new file mode 100644
index 000000000000..24ec45dd0d80
--- /dev/null
+++ b/drivers/pinctrl/vt8500/Makefile
@@ -0,0 +1,8 @@
1# VIA/Wondermedia pinctrl support
2
3obj-$(CONFIG_PINCTRL_WMT) += pinctrl-wmt.o
4obj-$(CONFIG_PINCTRL_VT8500) += pinctrl-vt8500.o
5obj-$(CONFIG_PINCTRL_WM8505) += pinctrl-wm8505.o
6obj-$(CONFIG_PINCTRL_WM8650) += pinctrl-wm8650.o
7obj-$(CONFIG_PINCTRL_WM8750) += pinctrl-wm8750.o
8obj-$(CONFIG_PINCTRL_WM8850) += pinctrl-wm8850.o
diff --git a/drivers/pinctrl/vt8500/pinctrl-vt8500.c b/drivers/pinctrl/vt8500/pinctrl-vt8500.c
new file mode 100644
index 000000000000..f2fe9f85cfa6
--- /dev/null
+++ b/drivers/pinctrl/vt8500/pinctrl-vt8500.c
@@ -0,0 +1,501 @@
1/*
2 * Pinctrl data for VIA VT8500 SoC
3 *
4 * Copyright (c) 2013 Tony Prisk <linux@prisktech.co.nz>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 */
15
16#include <linux/io.h>
17#include <linux/module.h>
18#include <linux/pinctrl/pinctrl.h>
19#include <linux/platform_device.h>
20#include <linux/slab.h>
21
22#include "pinctrl-wmt.h"
23
24/*
25 * Describe the register offsets within the GPIO memory space
26 * The dedicated external GPIO's should always be listed in bank 0
27 * so they are exported in the 0..31 range which is what users
28 * expect.
29 *
30 * Do not reorder these banks as it will change the pin numbering
31 */
32static const struct wmt_pinctrl_bank_registers vt8500_banks[] = {
33 WMT_PINCTRL_BANK(NO_REG, 0x3C, 0x5C, 0x7C, NO_REG, NO_REG), /* 0 */
34 WMT_PINCTRL_BANK(0x00, 0x20, 0x40, 0x60, NO_REG, NO_REG), /* 1 */
35 WMT_PINCTRL_BANK(0x04, 0x24, 0x44, 0x64, NO_REG, NO_REG), /* 2 */
36 WMT_PINCTRL_BANK(0x08, 0x28, 0x48, 0x68, NO_REG, NO_REG), /* 3 */
37 WMT_PINCTRL_BANK(0x0C, 0x2C, 0x4C, 0x6C, NO_REG, NO_REG), /* 4 */
38 WMT_PINCTRL_BANK(0x10, 0x30, 0x50, 0x70, NO_REG, NO_REG), /* 5 */
39 WMT_PINCTRL_BANK(0x14, 0x34, 0x54, 0x74, NO_REG, NO_REG), /* 6 */
40};
41
42/* Please keep sorted by bank/bit */
43#define WMT_PIN_EXTGPIO0 WMT_PIN(0, 0)
44#define WMT_PIN_EXTGPIO1 WMT_PIN(0, 1)
45#define WMT_PIN_EXTGPIO2 WMT_PIN(0, 2)
46#define WMT_PIN_EXTGPIO3 WMT_PIN(0, 3)
47#define WMT_PIN_EXTGPIO4 WMT_PIN(0, 4)
48#define WMT_PIN_EXTGPIO5 WMT_PIN(0, 5)
49#define WMT_PIN_EXTGPIO6 WMT_PIN(0, 6)
50#define WMT_PIN_EXTGPIO7 WMT_PIN(0, 7)
51#define WMT_PIN_EXTGPIO8 WMT_PIN(0, 8)
52#define WMT_PIN_UART0RTS WMT_PIN(1, 0)
53#define WMT_PIN_UART0TXD WMT_PIN(1, 1)
54#define WMT_PIN_UART0CTS WMT_PIN(1, 2)
55#define WMT_PIN_UART0RXD WMT_PIN(1, 3)
56#define WMT_PIN_UART1RTS WMT_PIN(1, 4)
57#define WMT_PIN_UART1TXD WMT_PIN(1, 5)
58#define WMT_PIN_UART1CTS WMT_PIN(1, 6)
59#define WMT_PIN_UART1RXD WMT_PIN(1, 7)
60#define WMT_PIN_SPI0CLK WMT_PIN(1, 8)
61#define WMT_PIN_SPI0SS WMT_PIN(1, 9)
62#define WMT_PIN_SPI0MISO WMT_PIN(1, 10)
63#define WMT_PIN_SPI0MOSI WMT_PIN(1, 11)
64#define WMT_PIN_SPI1CLK WMT_PIN(1, 12)
65#define WMT_PIN_SPI1SS WMT_PIN(1, 13)
66#define WMT_PIN_SPI1MISO WMT_PIN(1, 14)
67#define WMT_PIN_SPI1MOSI WMT_PIN(1, 15)
68#define WMT_PIN_SPI2CLK WMT_PIN(1, 16)
69#define WMT_PIN_SPI2SS WMT_PIN(1, 17)
70#define WMT_PIN_SPI2MISO WMT_PIN(1, 18)
71#define WMT_PIN_SPI2MOSI WMT_PIN(1, 19)
72#define WMT_PIN_SDDATA0 WMT_PIN(2, 0)
73#define WMT_PIN_SDDATA1 WMT_PIN(2, 1)
74#define WMT_PIN_SDDATA2 WMT_PIN(2, 2)
75#define WMT_PIN_SDDATA3 WMT_PIN(2, 3)
76#define WMT_PIN_MMCDATA0 WMT_PIN(2, 4)
77#define WMT_PIN_MMCDATA1 WMT_PIN(2, 5)
78#define WMT_PIN_MMCDATA2 WMT_PIN(2, 6)
79#define WMT_PIN_MMCDATA3 WMT_PIN(2, 7)
80#define WMT_PIN_SDCLK WMT_PIN(2, 8)
81#define WMT_PIN_SDWP WMT_PIN(2, 9)
82#define WMT_PIN_SDCMD WMT_PIN(2, 10)
83#define WMT_PIN_MSDATA0 WMT_PIN(2, 16)
84#define WMT_PIN_MSDATA1 WMT_PIN(2, 17)
85#define WMT_PIN_MSDATA2 WMT_PIN(2, 18)
86#define WMT_PIN_MSDATA3 WMT_PIN(2, 19)
87#define WMT_PIN_MSCLK WMT_PIN(2, 20)
88#define WMT_PIN_MSBS WMT_PIN(2, 21)
89#define WMT_PIN_MSINS WMT_PIN(2, 22)
90#define WMT_PIN_I2C0SCL WMT_PIN(2, 24)
91#define WMT_PIN_I2C0SDA WMT_PIN(2, 25)
92#define WMT_PIN_I2C1SCL WMT_PIN(2, 26)
93#define WMT_PIN_I2C1SDA WMT_PIN(2, 27)
94#define WMT_PIN_MII0RXD0 WMT_PIN(3, 0)
95#define WMT_PIN_MII0RXD1 WMT_PIN(3, 1)
96#define WMT_PIN_MII0RXD2 WMT_PIN(3, 2)
97#define WMT_PIN_MII0RXD3 WMT_PIN(3, 3)
98#define WMT_PIN_MII0RXCLK WMT_PIN(3, 4)
99#define WMT_PIN_MII0RXDV WMT_PIN(3, 5)
100#define WMT_PIN_MII0RXERR WMT_PIN(3, 6)
101#define WMT_PIN_MII0PHYRST WMT_PIN(3, 7)
102#define WMT_PIN_MII0TXD0 WMT_PIN(3, 8)
103#define WMT_PIN_MII0TXD1 WMT_PIN(3, 9)
104#define WMT_PIN_MII0TXD2 WMT_PIN(3, 10)
105#define WMT_PIN_MII0TXD3 WMT_PIN(3, 11)
106#define WMT_PIN_MII0TXCLK WMT_PIN(3, 12)
107#define WMT_PIN_MII0TXEN WMT_PIN(3, 13)
108#define WMT_PIN_MII0TXERR WMT_PIN(3, 14)
109#define WMT_PIN_MII0PHYPD WMT_PIN(3, 15)
110#define WMT_PIN_MII0COL WMT_PIN(3, 16)
111#define WMT_PIN_MII0CRS WMT_PIN(3, 17)
112#define WMT_PIN_MII0MDIO WMT_PIN(3, 18)
113#define WMT_PIN_MII0MDC WMT_PIN(3, 19)
114#define WMT_PIN_SEECS WMT_PIN(3, 20)
115#define WMT_PIN_SEECK WMT_PIN(3, 21)
116#define WMT_PIN_SEEDI WMT_PIN(3, 22)
117#define WMT_PIN_SEEDO WMT_PIN(3, 23)
118#define WMT_PIN_IDEDREQ0 WMT_PIN(3, 24)
119#define WMT_PIN_IDEDREQ1 WMT_PIN(3, 25)
120#define WMT_PIN_IDEIOW WMT_PIN(3, 26)
121#define WMT_PIN_IDEIOR WMT_PIN(3, 27)
122#define WMT_PIN_IDEDACK WMT_PIN(3, 28)
123#define WMT_PIN_IDEIORDY WMT_PIN(3, 29)
124#define WMT_PIN_IDEINTRQ WMT_PIN(3, 30)
125#define WMT_PIN_VDIN0 WMT_PIN(4, 0)
126#define WMT_PIN_VDIN1 WMT_PIN(4, 1)
127#define WMT_PIN_VDIN2 WMT_PIN(4, 2)
128#define WMT_PIN_VDIN3 WMT_PIN(4, 3)
129#define WMT_PIN_VDIN4 WMT_PIN(4, 4)
130#define WMT_PIN_VDIN5 WMT_PIN(4, 5)
131#define WMT_PIN_VDIN6 WMT_PIN(4, 6)
132#define WMT_PIN_VDIN7 WMT_PIN(4, 7)
133#define WMT_PIN_VDOUT0 WMT_PIN(4, 8)
134#define WMT_PIN_VDOUT1 WMT_PIN(4, 9)
135#define WMT_PIN_VDOUT2 WMT_PIN(4, 10)
136#define WMT_PIN_VDOUT3 WMT_PIN(4, 11)
137#define WMT_PIN_VDOUT4 WMT_PIN(4, 12)
138#define WMT_PIN_VDOUT5 WMT_PIN(4, 13)
139#define WMT_PIN_NANDCLE0 WMT_PIN(4, 14)
140#define WMT_PIN_NANDCLE1 WMT_PIN(4, 15)
141#define WMT_PIN_VDOUT6_7 WMT_PIN(4, 16)
142#define WMT_PIN_VHSYNC WMT_PIN(4, 17)
143#define WMT_PIN_VVSYNC WMT_PIN(4, 18)
144#define WMT_PIN_TSDIN0 WMT_PIN(5, 8)
145#define WMT_PIN_TSDIN1 WMT_PIN(5, 9)
146#define WMT_PIN_TSDIN2 WMT_PIN(5, 10)
147#define WMT_PIN_TSDIN3 WMT_PIN(5, 11)
148#define WMT_PIN_TSDIN4 WMT_PIN(5, 12)
149#define WMT_PIN_TSDIN5 WMT_PIN(5, 13)
150#define WMT_PIN_TSDIN6 WMT_PIN(5, 14)
151#define WMT_PIN_TSDIN7 WMT_PIN(5, 15)
152#define WMT_PIN_TSSYNC WMT_PIN(5, 16)
153#define WMT_PIN_TSVALID WMT_PIN(5, 17)
154#define WMT_PIN_TSCLK WMT_PIN(5, 18)
155#define WMT_PIN_LCDD0 WMT_PIN(6, 0)
156#define WMT_PIN_LCDD1 WMT_PIN(6, 1)
157#define WMT_PIN_LCDD2 WMT_PIN(6, 2)
158#define WMT_PIN_LCDD3 WMT_PIN(6, 3)
159#define WMT_PIN_LCDD4 WMT_PIN(6, 4)
160#define WMT_PIN_LCDD5 WMT_PIN(6, 5)
161#define WMT_PIN_LCDD6 WMT_PIN(6, 6)
162#define WMT_PIN_LCDD7 WMT_PIN(6, 7)
163#define WMT_PIN_LCDD8 WMT_PIN(6, 8)
164#define WMT_PIN_LCDD9 WMT_PIN(6, 9)
165#define WMT_PIN_LCDD10 WMT_PIN(6, 10)
166#define WMT_PIN_LCDD11 WMT_PIN(6, 11)
167#define WMT_PIN_LCDD12 WMT_PIN(6, 12)
168#define WMT_PIN_LCDD13 WMT_PIN(6, 13)
169#define WMT_PIN_LCDD14 WMT_PIN(6, 14)
170#define WMT_PIN_LCDD15 WMT_PIN(6, 15)
171#define WMT_PIN_LCDD16 WMT_PIN(6, 16)
172#define WMT_PIN_LCDD17 WMT_PIN(6, 17)
173#define WMT_PIN_LCDCLK WMT_PIN(6, 18)
174#define WMT_PIN_LCDDEN WMT_PIN(6, 19)
175#define WMT_PIN_LCDLINE WMT_PIN(6, 20)
176#define WMT_PIN_LCDFRM WMT_PIN(6, 21)
177#define WMT_PIN_LCDBIAS WMT_PIN(6, 22)
178
179static const struct pinctrl_pin_desc vt8500_pins[] = {
180 PINCTRL_PIN(WMT_PIN_EXTGPIO0, "extgpio0"),
181 PINCTRL_PIN(WMT_PIN_EXTGPIO1, "extgpio1"),
182 PINCTRL_PIN(WMT_PIN_EXTGPIO2, "extgpio2"),
183 PINCTRL_PIN(WMT_PIN_EXTGPIO3, "extgpio3"),
184 PINCTRL_PIN(WMT_PIN_EXTGPIO4, "extgpio4"),
185 PINCTRL_PIN(WMT_PIN_EXTGPIO5, "extgpio5"),
186 PINCTRL_PIN(WMT_PIN_EXTGPIO6, "extgpio6"),
187 PINCTRL_PIN(WMT_PIN_EXTGPIO7, "extgpio7"),
188 PINCTRL_PIN(WMT_PIN_EXTGPIO8, "extgpio8"),
189 PINCTRL_PIN(WMT_PIN_UART0RTS, "uart0_rts"),
190 PINCTRL_PIN(WMT_PIN_UART0TXD, "uart0_txd"),
191 PINCTRL_PIN(WMT_PIN_UART0CTS, "uart0_cts"),
192 PINCTRL_PIN(WMT_PIN_UART0RXD, "uart0_rxd"),
193 PINCTRL_PIN(WMT_PIN_UART1RTS, "uart1_rts"),
194 PINCTRL_PIN(WMT_PIN_UART1TXD, "uart1_txd"),
195 PINCTRL_PIN(WMT_PIN_UART1CTS, "uart1_cts"),
196 PINCTRL_PIN(WMT_PIN_UART1RXD, "uart1_rxd"),
197 PINCTRL_PIN(WMT_PIN_SPI0CLK, "spi0_clk"),
198 PINCTRL_PIN(WMT_PIN_SPI0SS, "spi0_ss"),
199 PINCTRL_PIN(WMT_PIN_SPI0MISO, "spi0_miso"),
200 PINCTRL_PIN(WMT_PIN_SPI0MOSI, "spi0_mosi"),
201 PINCTRL_PIN(WMT_PIN_SPI1CLK, "spi1_clk"),
202 PINCTRL_PIN(WMT_PIN_SPI1SS, "spi1_ss"),
203 PINCTRL_PIN(WMT_PIN_SPI1MISO, "spi1_miso"),
204 PINCTRL_PIN(WMT_PIN_SPI1MOSI, "spi1_mosi"),
205 PINCTRL_PIN(WMT_PIN_SPI2CLK, "spi2_clk"),
206 PINCTRL_PIN(WMT_PIN_SPI2SS, "spi2_ss"),
207 PINCTRL_PIN(WMT_PIN_SPI2MISO, "spi2_miso"),
208 PINCTRL_PIN(WMT_PIN_SPI2MOSI, "spi2_mosi"),
209 PINCTRL_PIN(WMT_PIN_SDDATA0, "sd_data0"),
210 PINCTRL_PIN(WMT_PIN_SDDATA1, "sd_data1"),
211 PINCTRL_PIN(WMT_PIN_SDDATA2, "sd_data2"),
212 PINCTRL_PIN(WMT_PIN_SDDATA3, "sd_data3"),
213 PINCTRL_PIN(WMT_PIN_MMCDATA0, "mmc_data0"),
214 PINCTRL_PIN(WMT_PIN_MMCDATA1, "mmc_data1"),
215 PINCTRL_PIN(WMT_PIN_MMCDATA2, "mmc_data2"),
216 PINCTRL_PIN(WMT_PIN_MMCDATA3, "mmc_data3"),
217 PINCTRL_PIN(WMT_PIN_SDCLK, "sd_clk"),
218 PINCTRL_PIN(WMT_PIN_SDWP, "sd_wp"),
219 PINCTRL_PIN(WMT_PIN_SDCMD, "sd_cmd"),
220 PINCTRL_PIN(WMT_PIN_MSDATA0, "ms_data0"),
221 PINCTRL_PIN(WMT_PIN_MSDATA1, "ms_data1"),
222 PINCTRL_PIN(WMT_PIN_MSDATA2, "ms_data2"),
223 PINCTRL_PIN(WMT_PIN_MSDATA3, "ms_data3"),
224 PINCTRL_PIN(WMT_PIN_MSCLK, "ms_clk"),
225 PINCTRL_PIN(WMT_PIN_MSBS, "ms_bs"),
226 PINCTRL_PIN(WMT_PIN_MSINS, "ms_ins"),
227 PINCTRL_PIN(WMT_PIN_I2C0SCL, "i2c0_scl"),
228 PINCTRL_PIN(WMT_PIN_I2C0SDA, "i2c0_sda"),
229 PINCTRL_PIN(WMT_PIN_I2C1SCL, "i2c1_scl"),
230 PINCTRL_PIN(WMT_PIN_I2C1SDA, "i2c1_sda"),
231 PINCTRL_PIN(WMT_PIN_MII0RXD0, "mii0_rxd0"),
232 PINCTRL_PIN(WMT_PIN_MII0RXD1, "mii0_rxd1"),
233 PINCTRL_PIN(WMT_PIN_MII0RXD2, "mii0_rxd2"),
234 PINCTRL_PIN(WMT_PIN_MII0RXD3, "mii0_rxd3"),
235 PINCTRL_PIN(WMT_PIN_MII0RXCLK, "mii0_rxclk"),
236 PINCTRL_PIN(WMT_PIN_MII0RXDV, "mii0_rxdv"),
237 PINCTRL_PIN(WMT_PIN_MII0RXERR, "mii0_rxerr"),
238 PINCTRL_PIN(WMT_PIN_MII0PHYRST, "mii0_phyrst"),
239 PINCTRL_PIN(WMT_PIN_MII0TXD0, "mii0_txd0"),
240 PINCTRL_PIN(WMT_PIN_MII0TXD1, "mii0_txd1"),
241 PINCTRL_PIN(WMT_PIN_MII0TXD2, "mii0_txd2"),
242 PINCTRL_PIN(WMT_PIN_MII0TXD3, "mii0_txd3"),
243 PINCTRL_PIN(WMT_PIN_MII0TXCLK, "mii0_txclk"),
244 PINCTRL_PIN(WMT_PIN_MII0TXEN, "mii0_txen"),
245 PINCTRL_PIN(WMT_PIN_MII0TXERR, "mii0_txerr"),
246 PINCTRL_PIN(WMT_PIN_MII0PHYPD, "mii0_phypd"),
247 PINCTRL_PIN(WMT_PIN_MII0COL, "mii0_col"),
248 PINCTRL_PIN(WMT_PIN_MII0CRS, "mii0_crs"),
249 PINCTRL_PIN(WMT_PIN_MII0MDIO, "mii0_mdio"),
250 PINCTRL_PIN(WMT_PIN_MII0MDC, "mii0_mdc"),
251 PINCTRL_PIN(WMT_PIN_SEECS, "see_cs"),
252 PINCTRL_PIN(WMT_PIN_SEECK, "see_ck"),
253 PINCTRL_PIN(WMT_PIN_SEEDI, "see_di"),
254 PINCTRL_PIN(WMT_PIN_SEEDO, "see_do"),
255 PINCTRL_PIN(WMT_PIN_IDEDREQ0, "ide_dreq0"),
256 PINCTRL_PIN(WMT_PIN_IDEDREQ1, "ide_dreq1"),
257 PINCTRL_PIN(WMT_PIN_IDEIOW, "ide_iow"),
258 PINCTRL_PIN(WMT_PIN_IDEIOR, "ide_ior"),
259 PINCTRL_PIN(WMT_PIN_IDEDACK, "ide_dack"),
260 PINCTRL_PIN(WMT_PIN_IDEIORDY, "ide_iordy"),
261 PINCTRL_PIN(WMT_PIN_IDEINTRQ, "ide_intrq"),
262 PINCTRL_PIN(WMT_PIN_VDIN0, "vdin0"),
263 PINCTRL_PIN(WMT_PIN_VDIN1, "vdin1"),
264 PINCTRL_PIN(WMT_PIN_VDIN2, "vdin2"),
265 PINCTRL_PIN(WMT_PIN_VDIN3, "vdin3"),
266 PINCTRL_PIN(WMT_PIN_VDIN4, "vdin4"),
267 PINCTRL_PIN(WMT_PIN_VDIN5, "vdin5"),
268 PINCTRL_PIN(WMT_PIN_VDIN6, "vdin6"),
269 PINCTRL_PIN(WMT_PIN_VDIN7, "vdin7"),
270 PINCTRL_PIN(WMT_PIN_VDOUT0, "vdout0"),
271 PINCTRL_PIN(WMT_PIN_VDOUT1, "vdout1"),
272 PINCTRL_PIN(WMT_PIN_VDOUT2, "vdout2"),
273 PINCTRL_PIN(WMT_PIN_VDOUT3, "vdout3"),
274 PINCTRL_PIN(WMT_PIN_VDOUT4, "vdout4"),
275 PINCTRL_PIN(WMT_PIN_VDOUT5, "vdout5"),
276 PINCTRL_PIN(WMT_PIN_NANDCLE0, "nand_cle0"),
277 PINCTRL_PIN(WMT_PIN_NANDCLE1, "nand_cle1"),
278 PINCTRL_PIN(WMT_PIN_VDOUT6_7, "vdout6_7"),
279 PINCTRL_PIN(WMT_PIN_VHSYNC, "vhsync"),
280 PINCTRL_PIN(WMT_PIN_VVSYNC, "vvsync"),
281 PINCTRL_PIN(WMT_PIN_TSDIN0, "tsdin0"),
282 PINCTRL_PIN(WMT_PIN_TSDIN1, "tsdin1"),
283 PINCTRL_PIN(WMT_PIN_TSDIN2, "tsdin2"),
284 PINCTRL_PIN(WMT_PIN_TSDIN3, "tsdin3"),
285 PINCTRL_PIN(WMT_PIN_TSDIN4, "tsdin4"),
286 PINCTRL_PIN(WMT_PIN_TSDIN5, "tsdin5"),
287 PINCTRL_PIN(WMT_PIN_TSDIN6, "tsdin6"),
288 PINCTRL_PIN(WMT_PIN_TSDIN7, "tsdin7"),
289 PINCTRL_PIN(WMT_PIN_TSSYNC, "tssync"),
290 PINCTRL_PIN(WMT_PIN_TSVALID, "tsvalid"),
291 PINCTRL_PIN(WMT_PIN_TSCLK, "tsclk"),
292 PINCTRL_PIN(WMT_PIN_LCDD0, "lcd_d0"),
293 PINCTRL_PIN(WMT_PIN_LCDD1, "lcd_d1"),
294 PINCTRL_PIN(WMT_PIN_LCDD2, "lcd_d2"),
295 PINCTRL_PIN(WMT_PIN_LCDD3, "lcd_d3"),
296 PINCTRL_PIN(WMT_PIN_LCDD4, "lcd_d4"),
297 PINCTRL_PIN(WMT_PIN_LCDD5, "lcd_d5"),
298 PINCTRL_PIN(WMT_PIN_LCDD6, "lcd_d6"),
299 PINCTRL_PIN(WMT_PIN_LCDD7, "lcd_d7"),
300 PINCTRL_PIN(WMT_PIN_LCDD8, "lcd_d8"),
301 PINCTRL_PIN(WMT_PIN_LCDD9, "lcd_d9"),
302 PINCTRL_PIN(WMT_PIN_LCDD10, "lcd_d10"),
303 PINCTRL_PIN(WMT_PIN_LCDD11, "lcd_d11"),
304 PINCTRL_PIN(WMT_PIN_LCDD12, "lcd_d12"),
305 PINCTRL_PIN(WMT_PIN_LCDD13, "lcd_d13"),
306 PINCTRL_PIN(WMT_PIN_LCDD14, "lcd_d14"),
307 PINCTRL_PIN(WMT_PIN_LCDD15, "lcd_d15"),
308 PINCTRL_PIN(WMT_PIN_LCDD16, "lcd_d16"),
309 PINCTRL_PIN(WMT_PIN_LCDD17, "lcd_d17"),
310 PINCTRL_PIN(WMT_PIN_LCDCLK, "lcd_clk"),
311 PINCTRL_PIN(WMT_PIN_LCDDEN, "lcd_den"),
312 PINCTRL_PIN(WMT_PIN_LCDLINE, "lcd_line"),
313 PINCTRL_PIN(WMT_PIN_LCDFRM, "lcd_frm"),
314 PINCTRL_PIN(WMT_PIN_LCDBIAS, "lcd_bias"),
315};
316
317/* Order of these names must match the above list */
318static const char * const vt8500_groups[] = {
319 "extgpio0",
320 "extgpio1",
321 "extgpio2",
322 "extgpio3",
323 "extgpio4",
324 "extgpio5",
325 "extgpio6",
326 "extgpio7",
327 "extgpio8",
328 "uart0_rts",
329 "uart0_txd",
330 "uart0_cts",
331 "uart0_rxd",
332 "uart1_rts",
333 "uart1_txd",
334 "uart1_cts",
335 "uart1_rxd",
336 "spi0_clk",
337 "spi0_ss",
338 "spi0_miso",
339 "spi0_mosi",
340 "spi1_clk",
341 "spi1_ss",
342 "spi1_miso",
343 "spi1_mosi",
344 "spi2_clk",
345 "spi2_ss",
346 "spi2_miso",
347 "spi2_mosi",
348 "sd_data0",
349 "sd_data1",
350 "sd_data2",
351 "sd_data3",
352 "mmc_data0",
353 "mmc_data1",
354 "mmc_data2",
355 "mmc_data3",
356 "sd_clk",
357 "sd_wp",
358 "sd_cmd",
359 "ms_data0",
360 "ms_data1",
361 "ms_data2",
362 "ms_data3",
363 "ms_clk",
364 "ms_bs",
365 "ms_ins",
366 "i2c0_scl",
367 "i2c0_sda",
368 "i2c1_scl",
369 "i2c1_sda",
370 "mii0_rxd0",
371 "mii0_rxd1",
372 "mii0_rxd2",
373 "mii0_rxd3",
374 "mii0_rxclk",
375 "mii0_rxdv",
376 "mii0_rxerr",
377 "mii0_phyrst",
378 "mii0_txd0",
379 "mii0_txd1",
380 "mii0_txd2",
381 "mii0_txd3",
382 "mii0_txclk",
383 "mii0_txen",
384 "mii0_txerr",
385 "mii0_phypd",
386 "mii0_col",
387 "mii0_crs",
388 "mii0_mdio",
389 "mii0_mdc",
390 "see_cs",
391 "see_ck",
392 "see_di",
393 "see_do",
394 "ide_dreq0",
395 "ide_dreq1",
396 "ide_iow",
397 "ide_ior",
398 "ide_dack",
399 "ide_iordy",
400 "ide_intrq",
401 "vdin0",
402 "vdin1",
403 "vdin2",
404 "vdin3",
405 "vdin4",
406 "vdin5",
407 "vdin6",
408 "vdin7",
409 "vdout0",
410 "vdout1",
411 "vdout2",
412 "vdout3",
413 "vdout4",
414 "vdout5",
415 "nand_cle0",
416 "nand_cle1",
417 "vdout6_7",
418 "vhsync",
419 "vvsync",
420 "tsdin0",
421 "tsdin1",
422 "tsdin2",
423 "tsdin3",
424 "tsdin4",
425 "tsdin5",
426 "tsdin6",
427 "tsdin7",
428 "tssync",
429 "tsvalid",
430 "tsclk",
431 "lcd_d0",
432 "lcd_d1",
433 "lcd_d2",
434 "lcd_d3",
435 "lcd_d4",
436 "lcd_d5",
437 "lcd_d6",
438 "lcd_d7",
439 "lcd_d8",
440 "lcd_d9",
441 "lcd_d10",
442 "lcd_d11",
443 "lcd_d12",
444 "lcd_d13",
445 "lcd_d14",
446 "lcd_d15",
447 "lcd_d16",
448 "lcd_d17",
449 "lcd_clk",
450 "lcd_den",
451 "lcd_line",
452 "lcd_frm",
453 "lcd_bias",
454};
455
456static int vt8500_pinctrl_probe(struct platform_device *pdev)
457{
458 struct wmt_pinctrl_data *data;
459
460 data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
461 if (!data) {
462 dev_err(&pdev->dev, "failed to allocate data\n");
463 return -ENOMEM;
464 }
465
466 data->banks = vt8500_banks;
467 data->nbanks = ARRAY_SIZE(vt8500_banks);
468 data->pins = vt8500_pins;
469 data->npins = ARRAY_SIZE(vt8500_pins);
470 data->groups = vt8500_groups;
471 data->ngroups = ARRAY_SIZE(vt8500_groups);
472
473 return wmt_pinctrl_probe(pdev, data);
474}
475
476static int vt8500_pinctrl_remove(struct platform_device *pdev)
477{
478 return wmt_pinctrl_remove(pdev);
479}
480
481static struct of_device_id wmt_pinctrl_of_match[] = {
482 { .compatible = "via,vt8500-pinctrl" },
483 { /* sentinel */ },
484};
485
486static struct platform_driver wmt_pinctrl_driver = {
487 .probe = vt8500_pinctrl_probe,
488 .remove = vt8500_pinctrl_remove,
489 .driver = {
490 .name = "pinctrl-vt8500",
491 .owner = THIS_MODULE,
492 .of_match_table = wmt_pinctrl_of_match,
493 },
494};
495
496module_platform_driver(wmt_pinctrl_driver);
497
498MODULE_AUTHOR("Tony Prisk <linux@prisktech.co.nz>");
499MODULE_DESCRIPTION("VIA VT8500 Pincontrol driver");
500MODULE_LICENSE("GPL v2");
501MODULE_DEVICE_TABLE(of, wmt_pinctrl_of_match);
diff --git a/drivers/pinctrl/vt8500/pinctrl-wm8505.c b/drivers/pinctrl/vt8500/pinctrl-wm8505.c
new file mode 100644
index 000000000000..483ba732694e
--- /dev/null
+++ b/drivers/pinctrl/vt8500/pinctrl-wm8505.c
@@ -0,0 +1,532 @@
1/*
2 * Pinctrl data for Wondermedia WM8505 SoC
3 *
4 * Copyright (c) 2013 Tony Prisk <linux@prisktech.co.nz>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 */
15
16#include <linux/io.h>
17#include <linux/module.h>
18#include <linux/pinctrl/pinctrl.h>
19#include <linux/platform_device.h>
20#include <linux/slab.h>
21
22#include "pinctrl-wmt.h"
23
24/*
25 * Describe the register offsets within the GPIO memory space
26 * The dedicated external GPIO's should always be listed in bank 0
27 * so they are exported in the 0..31 range which is what users
28 * expect.
29 *
30 * Do not reorder these banks as it will change the pin numbering
31 */
32static const struct wmt_pinctrl_bank_registers wm8505_banks[] = {
33 WMT_PINCTRL_BANK(0x64, 0x8C, 0xB4, 0xDC, NO_REG, NO_REG), /* 0 */
34 WMT_PINCTRL_BANK(0x40, 0x68, 0x90, 0xB8, NO_REG, NO_REG), /* 1 */
35 WMT_PINCTRL_BANK(0x44, 0x6C, 0x94, 0xBC, NO_REG, NO_REG), /* 2 */
36 WMT_PINCTRL_BANK(0x48, 0x70, 0x98, 0xC0, NO_REG, NO_REG), /* 3 */
37 WMT_PINCTRL_BANK(0x4C, 0x74, 0x9C, 0xC4, NO_REG, NO_REG), /* 4 */
38 WMT_PINCTRL_BANK(0x50, 0x78, 0xA0, 0xC8, NO_REG, NO_REG), /* 5 */
39 WMT_PINCTRL_BANK(0x54, 0x7C, 0xA4, 0xD0, NO_REG, NO_REG), /* 6 */
40 WMT_PINCTRL_BANK(0x58, 0x80, 0xA8, 0xD4, NO_REG, NO_REG), /* 7 */
41 WMT_PINCTRL_BANK(0x5C, 0x84, 0xAC, 0xD8, NO_REG, NO_REG), /* 8 */
42 WMT_PINCTRL_BANK(0x60, 0x88, 0xB0, 0xDC, NO_REG, NO_REG), /* 9 */
43 WMT_PINCTRL_BANK(0x500, 0x504, 0x508, 0x50C, NO_REG, NO_REG), /* 10 */
44};
45
46/* Please keep sorted by bank/bit */
47#define WMT_PIN_EXTGPIO0 WMT_PIN(0, 0)
48#define WMT_PIN_EXTGPIO1 WMT_PIN(0, 1)
49#define WMT_PIN_EXTGPIO2 WMT_PIN(0, 2)
50#define WMT_PIN_EXTGPIO3 WMT_PIN(0, 3)
51#define WMT_PIN_EXTGPIO4 WMT_PIN(0, 4)
52#define WMT_PIN_EXTGPIO5 WMT_PIN(0, 5)
53#define WMT_PIN_EXTGPIO6 WMT_PIN(0, 6)
54#define WMT_PIN_EXTGPIO7 WMT_PIN(0, 7)
55#define WMT_PIN_WAKEUP0 WMT_PIN(0, 16)
56#define WMT_PIN_WAKEUP1 WMT_PIN(0, 17)
57#define WMT_PIN_WAKEUP2 WMT_PIN(0, 18)
58#define WMT_PIN_WAKEUP3 WMT_PIN(0, 19)
59#define WMT_PIN_SUSGPIO0 WMT_PIN(0, 21)
60#define WMT_PIN_SDDATA0 WMT_PIN(1, 0)
61#define WMT_PIN_SDDATA1 WMT_PIN(1, 1)
62#define WMT_PIN_SDDATA2 WMT_PIN(1, 2)
63#define WMT_PIN_SDDATA3 WMT_PIN(1, 3)
64#define WMT_PIN_MMCDATA0 WMT_PIN(1, 4)
65#define WMT_PIN_MMCDATA1 WMT_PIN(1, 5)
66#define WMT_PIN_MMCDATA2 WMT_PIN(1, 6)
67#define WMT_PIN_MMCDATA3 WMT_PIN(1, 7)
68#define WMT_PIN_VDIN0 WMT_PIN(2, 0)
69#define WMT_PIN_VDIN1 WMT_PIN(2, 1)
70#define WMT_PIN_VDIN2 WMT_PIN(2, 2)
71#define WMT_PIN_VDIN3 WMT_PIN(2, 3)
72#define WMT_PIN_VDIN4 WMT_PIN(2, 4)
73#define WMT_PIN_VDIN5 WMT_PIN(2, 5)
74#define WMT_PIN_VDIN6 WMT_PIN(2, 6)
75#define WMT_PIN_VDIN7 WMT_PIN(2, 7)
76#define WMT_PIN_VDOUT0 WMT_PIN(2, 8)
77#define WMT_PIN_VDOUT1 WMT_PIN(2, 9)
78#define WMT_PIN_VDOUT2 WMT_PIN(2, 10)
79#define WMT_PIN_VDOUT3 WMT_PIN(2, 11)
80#define WMT_PIN_VDOUT4 WMT_PIN(2, 12)
81#define WMT_PIN_VDOUT5 WMT_PIN(2, 13)
82#define WMT_PIN_VDOUT6 WMT_PIN(2, 14)
83#define WMT_PIN_VDOUT7 WMT_PIN(2, 15)
84#define WMT_PIN_VDOUT8 WMT_PIN(2, 16)
85#define WMT_PIN_VDOUT9 WMT_PIN(2, 17)
86#define WMT_PIN_VDOUT10 WMT_PIN(2, 18)
87#define WMT_PIN_VDOUT11 WMT_PIN(2, 19)
88#define WMT_PIN_VDOUT12 WMT_PIN(2, 20)
89#define WMT_PIN_VDOUT13 WMT_PIN(2, 21)
90#define WMT_PIN_VDOUT14 WMT_PIN(2, 22)
91#define WMT_PIN_VDOUT15 WMT_PIN(2, 23)
92#define WMT_PIN_VDOUT16 WMT_PIN(2, 24)
93#define WMT_PIN_VDOUT17 WMT_PIN(2, 25)
94#define WMT_PIN_VDOUT18 WMT_PIN(2, 26)
95#define WMT_PIN_VDOUT19 WMT_PIN(2, 27)
96#define WMT_PIN_VDOUT20 WMT_PIN(2, 28)
97#define WMT_PIN_VDOUT21 WMT_PIN(2, 29)
98#define WMT_PIN_VDOUT22 WMT_PIN(2, 30)
99#define WMT_PIN_VDOUT23 WMT_PIN(2, 31)
100#define WMT_PIN_VHSYNC WMT_PIN(3, 0)
101#define WMT_PIN_VVSYNC WMT_PIN(3, 1)
102#define WMT_PIN_VGAHSYNC WMT_PIN(3, 2)
103#define WMT_PIN_VGAVSYNC WMT_PIN(3, 3)
104#define WMT_PIN_VDHSYNC WMT_PIN(3, 4)
105#define WMT_PIN_VDVSYNC WMT_PIN(3, 5)
106#define WMT_PIN_NORD0 WMT_PIN(4, 0)
107#define WMT_PIN_NORD1 WMT_PIN(4, 1)
108#define WMT_PIN_NORD2 WMT_PIN(4, 2)
109#define WMT_PIN_NORD3 WMT_PIN(4, 3)
110#define WMT_PIN_NORD4 WMT_PIN(4, 4)
111#define WMT_PIN_NORD5 WMT_PIN(4, 5)
112#define WMT_PIN_NORD6 WMT_PIN(4, 6)
113#define WMT_PIN_NORD7 WMT_PIN(4, 7)
114#define WMT_PIN_NORD8 WMT_PIN(4, 8)
115#define WMT_PIN_NORD9 WMT_PIN(4, 9)
116#define WMT_PIN_NORD10 WMT_PIN(4, 10)
117#define WMT_PIN_NORD11 WMT_PIN(4, 11)
118#define WMT_PIN_NORD12 WMT_PIN(4, 12)
119#define WMT_PIN_NORD13 WMT_PIN(4, 13)
120#define WMT_PIN_NORD14 WMT_PIN(4, 14)
121#define WMT_PIN_NORD15 WMT_PIN(4, 15)
122#define WMT_PIN_NORA0 WMT_PIN(5, 0)
123#define WMT_PIN_NORA1 WMT_PIN(5, 1)
124#define WMT_PIN_NORA2 WMT_PIN(5, 2)
125#define WMT_PIN_NORA3 WMT_PIN(5, 3)
126#define WMT_PIN_NORA4 WMT_PIN(5, 4)
127#define WMT_PIN_NORA5 WMT_PIN(5, 5)
128#define WMT_PIN_NORA6 WMT_PIN(5, 6)
129#define WMT_PIN_NORA7 WMT_PIN(5, 7)
130#define WMT_PIN_NORA8 WMT_PIN(5, 8)
131#define WMT_PIN_NORA9 WMT_PIN(5, 9)
132#define WMT_PIN_NORA10 WMT_PIN(5, 10)
133#define WMT_PIN_NORA11 WMT_PIN(5, 11)
134#define WMT_PIN_NORA12 WMT_PIN(5, 12)
135#define WMT_PIN_NORA13 WMT_PIN(5, 13)
136#define WMT_PIN_NORA14 WMT_PIN(5, 14)
137#define WMT_PIN_NORA15 WMT_PIN(5, 15)
138#define WMT_PIN_NORA16 WMT_PIN(5, 16)
139#define WMT_PIN_NORA17 WMT_PIN(5, 17)
140#define WMT_PIN_NORA18 WMT_PIN(5, 18)
141#define WMT_PIN_NORA19 WMT_PIN(5, 19)
142#define WMT_PIN_NORA20 WMT_PIN(5, 20)
143#define WMT_PIN_NORA21 WMT_PIN(5, 21)
144#define WMT_PIN_NORA22 WMT_PIN(5, 22)
145#define WMT_PIN_NORA23 WMT_PIN(5, 23)
146#define WMT_PIN_NORA24 WMT_PIN(5, 24)
147#define WMT_PIN_AC97SDI WMT_PIN(6, 0)
148#define WMT_PIN_AC97SYNC WMT_PIN(6, 1)
149#define WMT_PIN_AC97SDO WMT_PIN(6, 2)
150#define WMT_PIN_AC97BCLK WMT_PIN(6, 3)
151#define WMT_PIN_AC97RST WMT_PIN(6, 4)
152#define WMT_PIN_SFDO WMT_PIN(7, 0)
153#define WMT_PIN_SFCS0 WMT_PIN(7, 1)
154#define WMT_PIN_SFCS1 WMT_PIN(7, 2)
155#define WMT_PIN_SFCLK WMT_PIN(7, 3)
156#define WMT_PIN_SFDI WMT_PIN(7, 4)
157#define WMT_PIN_SPI0CLK WMT_PIN(8, 0)
158#define WMT_PIN_SPI0MISO WMT_PIN(8, 1)
159#define WMT_PIN_SPI0MOSI WMT_PIN(8, 2)
160#define WMT_PIN_SPI0SS WMT_PIN(8, 3)
161#define WMT_PIN_SPI1CLK WMT_PIN(8, 4)
162#define WMT_PIN_SPI1MISO WMT_PIN(8, 5)
163#define WMT_PIN_SPI1MOSI WMT_PIN(8, 6)
164#define WMT_PIN_SPI1SS WMT_PIN(8, 7)
165#define WMT_PIN_SPI2CLK WMT_PIN(8, 8)
166#define WMT_PIN_SPI2MISO WMT_PIN(8, 9)
167#define WMT_PIN_SPI2MOSI WMT_PIN(8, 10)
168#define WMT_PIN_SPI2SS WMT_PIN(8, 11)
169#define WMT_PIN_UART0_RTS WMT_PIN(9, 0)
170#define WMT_PIN_UART0_TXD WMT_PIN(9, 1)
171#define WMT_PIN_UART0_CTS WMT_PIN(9, 2)
172#define WMT_PIN_UART0_RXD WMT_PIN(9, 3)
173#define WMT_PIN_UART1_RTS WMT_PIN(9, 4)
174#define WMT_PIN_UART1_TXD WMT_PIN(9, 5)
175#define WMT_PIN_UART1_CTS WMT_PIN(9, 6)
176#define WMT_PIN_UART1_RXD WMT_PIN(9, 7)
177#define WMT_PIN_UART2_RTS WMT_PIN(9, 8)
178#define WMT_PIN_UART2_TXD WMT_PIN(9, 9)
179#define WMT_PIN_UART2_CTS WMT_PIN(9, 10)
180#define WMT_PIN_UART2_RXD WMT_PIN(9, 11)
181#define WMT_PIN_UART3_RTS WMT_PIN(9, 12)
182#define WMT_PIN_UART3_TXD WMT_PIN(9, 13)
183#define WMT_PIN_UART3_CTS WMT_PIN(9, 14)
184#define WMT_PIN_UART3_RXD WMT_PIN(9, 15)
185#define WMT_PIN_I2C0SCL WMT_PIN(10, 0)
186#define WMT_PIN_I2C0SDA WMT_PIN(10, 1)
187#define WMT_PIN_I2C1SCL WMT_PIN(10, 2)
188#define WMT_PIN_I2C1SDA WMT_PIN(10, 3)
189#define WMT_PIN_I2C2SCL WMT_PIN(10, 4)
190#define WMT_PIN_I2C2SDA WMT_PIN(10, 5)
191
192static const struct pinctrl_pin_desc wm8505_pins[] = {
193 PINCTRL_PIN(WMT_PIN_EXTGPIO0, "extgpio0"),
194 PINCTRL_PIN(WMT_PIN_EXTGPIO1, "extgpio1"),
195 PINCTRL_PIN(WMT_PIN_EXTGPIO2, "extgpio2"),
196 PINCTRL_PIN(WMT_PIN_EXTGPIO3, "extgpio3"),
197 PINCTRL_PIN(WMT_PIN_EXTGPIO4, "extgpio4"),
198 PINCTRL_PIN(WMT_PIN_EXTGPIO5, "extgpio5"),
199 PINCTRL_PIN(WMT_PIN_EXTGPIO6, "extgpio6"),
200 PINCTRL_PIN(WMT_PIN_EXTGPIO7, "extgpio7"),
201 PINCTRL_PIN(WMT_PIN_WAKEUP0, "wakeup0"),
202 PINCTRL_PIN(WMT_PIN_WAKEUP1, "wakeup1"),
203 PINCTRL_PIN(WMT_PIN_WAKEUP2, "wakeup2"),
204 PINCTRL_PIN(WMT_PIN_WAKEUP3, "wakeup3"),
205 PINCTRL_PIN(WMT_PIN_SUSGPIO0, "susgpio0"),
206 PINCTRL_PIN(WMT_PIN_SDDATA0, "sd_data0"),
207 PINCTRL_PIN(WMT_PIN_SDDATA1, "sd_data1"),
208 PINCTRL_PIN(WMT_PIN_SDDATA2, "sd_data2"),
209 PINCTRL_PIN(WMT_PIN_SDDATA3, "sd_data3"),
210 PINCTRL_PIN(WMT_PIN_MMCDATA0, "mmc_data0"),
211 PINCTRL_PIN(WMT_PIN_MMCDATA1, "mmc_data1"),
212 PINCTRL_PIN(WMT_PIN_MMCDATA2, "mmc_data2"),
213 PINCTRL_PIN(WMT_PIN_MMCDATA3, "mmc_data3"),
214 PINCTRL_PIN(WMT_PIN_VDIN0, "vdin0"),
215 PINCTRL_PIN(WMT_PIN_VDIN1, "vdin1"),
216 PINCTRL_PIN(WMT_PIN_VDIN2, "vdin2"),
217 PINCTRL_PIN(WMT_PIN_VDIN3, "vdin3"),
218 PINCTRL_PIN(WMT_PIN_VDIN4, "vdin4"),
219 PINCTRL_PIN(WMT_PIN_VDIN5, "vdin5"),
220 PINCTRL_PIN(WMT_PIN_VDIN6, "vdin6"),
221 PINCTRL_PIN(WMT_PIN_VDIN7, "vdin7"),
222 PINCTRL_PIN(WMT_PIN_VDOUT0, "vdout0"),
223 PINCTRL_PIN(WMT_PIN_VDOUT1, "vdout1"),
224 PINCTRL_PIN(WMT_PIN_VDOUT2, "vdout2"),
225 PINCTRL_PIN(WMT_PIN_VDOUT3, "vdout3"),
226 PINCTRL_PIN(WMT_PIN_VDOUT4, "vdout4"),
227 PINCTRL_PIN(WMT_PIN_VDOUT5, "vdout5"),
228 PINCTRL_PIN(WMT_PIN_VDOUT6, "vdout6"),
229 PINCTRL_PIN(WMT_PIN_VDOUT7, "vdout7"),
230 PINCTRL_PIN(WMT_PIN_VDOUT8, "vdout8"),
231 PINCTRL_PIN(WMT_PIN_VDOUT9, "vdout9"),
232 PINCTRL_PIN(WMT_PIN_VDOUT10, "vdout10"),
233 PINCTRL_PIN(WMT_PIN_VDOUT11, "vdout11"),
234 PINCTRL_PIN(WMT_PIN_VDOUT12, "vdout12"),
235 PINCTRL_PIN(WMT_PIN_VDOUT13, "vdout13"),
236 PINCTRL_PIN(WMT_PIN_VDOUT14, "vdout14"),
237 PINCTRL_PIN(WMT_PIN_VDOUT15, "vdout15"),
238 PINCTRL_PIN(WMT_PIN_VDOUT16, "vdout16"),
239 PINCTRL_PIN(WMT_PIN_VDOUT17, "vdout17"),
240 PINCTRL_PIN(WMT_PIN_VDOUT18, "vdout18"),
241 PINCTRL_PIN(WMT_PIN_VDOUT19, "vdout19"),
242 PINCTRL_PIN(WMT_PIN_VDOUT20, "vdout20"),
243 PINCTRL_PIN(WMT_PIN_VDOUT21, "vdout21"),
244 PINCTRL_PIN(WMT_PIN_VDOUT22, "vdout22"),
245 PINCTRL_PIN(WMT_PIN_VDOUT23, "vdout23"),
246 PINCTRL_PIN(WMT_PIN_VHSYNC, "v_hsync"),
247 PINCTRL_PIN(WMT_PIN_VVSYNC, "v_vsync"),
248 PINCTRL_PIN(WMT_PIN_VGAHSYNC, "vga_hsync"),
249 PINCTRL_PIN(WMT_PIN_VGAVSYNC, "vga_vsync"),
250 PINCTRL_PIN(WMT_PIN_VDHSYNC, "vd_hsync"),
251 PINCTRL_PIN(WMT_PIN_VDVSYNC, "vd_vsync"),
252 PINCTRL_PIN(WMT_PIN_NORD0, "nor_d0"),
253 PINCTRL_PIN(WMT_PIN_NORD1, "nor_d1"),
254 PINCTRL_PIN(WMT_PIN_NORD2, "nor_d2"),
255 PINCTRL_PIN(WMT_PIN_NORD3, "nor_d3"),
256 PINCTRL_PIN(WMT_PIN_NORD4, "nor_d4"),
257 PINCTRL_PIN(WMT_PIN_NORD5, "nor_d5"),
258 PINCTRL_PIN(WMT_PIN_NORD6, "nor_d6"),
259 PINCTRL_PIN(WMT_PIN_NORD7, "nor_d7"),
260 PINCTRL_PIN(WMT_PIN_NORD8, "nor_d8"),
261 PINCTRL_PIN(WMT_PIN_NORD9, "nor_d9"),
262 PINCTRL_PIN(WMT_PIN_NORD10, "nor_d10"),
263 PINCTRL_PIN(WMT_PIN_NORD11, "nor_d11"),
264 PINCTRL_PIN(WMT_PIN_NORD12, "nor_d12"),
265 PINCTRL_PIN(WMT_PIN_NORD13, "nor_d13"),
266 PINCTRL_PIN(WMT_PIN_NORD14, "nor_d14"),
267 PINCTRL_PIN(WMT_PIN_NORD15, "nor_d15"),
268 PINCTRL_PIN(WMT_PIN_NORA0, "nor_a0"),
269 PINCTRL_PIN(WMT_PIN_NORA1, "nor_a1"),
270 PINCTRL_PIN(WMT_PIN_NORA2, "nor_a2"),
271 PINCTRL_PIN(WMT_PIN_NORA3, "nor_a3"),
272 PINCTRL_PIN(WMT_PIN_NORA4, "nor_a4"),
273 PINCTRL_PIN(WMT_PIN_NORA5, "nor_a5"),
274 PINCTRL_PIN(WMT_PIN_NORA6, "nor_a6"),
275 PINCTRL_PIN(WMT_PIN_NORA7, "nor_a7"),
276 PINCTRL_PIN(WMT_PIN_NORA8, "nor_a8"),
277 PINCTRL_PIN(WMT_PIN_NORA9, "nor_a9"),
278 PINCTRL_PIN(WMT_PIN_NORA10, "nor_a10"),
279 PINCTRL_PIN(WMT_PIN_NORA11, "nor_a11"),
280 PINCTRL_PIN(WMT_PIN_NORA12, "nor_a12"),
281 PINCTRL_PIN(WMT_PIN_NORA13, "nor_a13"),
282 PINCTRL_PIN(WMT_PIN_NORA14, "nor_a14"),
283 PINCTRL_PIN(WMT_PIN_NORA15, "nor_a15"),
284 PINCTRL_PIN(WMT_PIN_NORA16, "nor_a16"),
285 PINCTRL_PIN(WMT_PIN_NORA17, "nor_a17"),
286 PINCTRL_PIN(WMT_PIN_NORA18, "nor_a18"),
287 PINCTRL_PIN(WMT_PIN_NORA19, "nor_a19"),
288 PINCTRL_PIN(WMT_PIN_NORA20, "nor_a20"),
289 PINCTRL_PIN(WMT_PIN_NORA21, "nor_a21"),
290 PINCTRL_PIN(WMT_PIN_NORA22, "nor_a22"),
291 PINCTRL_PIN(WMT_PIN_NORA23, "nor_a23"),
292 PINCTRL_PIN(WMT_PIN_NORA24, "nor_a24"),
293 PINCTRL_PIN(WMT_PIN_AC97SDI, "ac97_sdi"),
294 PINCTRL_PIN(WMT_PIN_AC97SYNC, "ac97_sync"),
295 PINCTRL_PIN(WMT_PIN_AC97SDO, "ac97_sdo"),
296 PINCTRL_PIN(WMT_PIN_AC97BCLK, "ac97_bclk"),
297 PINCTRL_PIN(WMT_PIN_AC97RST, "ac97_rst"),
298 PINCTRL_PIN(WMT_PIN_SFDO, "sf_do"),
299 PINCTRL_PIN(WMT_PIN_SFCS0, "sf_cs0"),
300 PINCTRL_PIN(WMT_PIN_SFCS1, "sf_cs1"),
301 PINCTRL_PIN(WMT_PIN_SFCLK, "sf_clk"),
302 PINCTRL_PIN(WMT_PIN_SFDI, "sf_di"),
303 PINCTRL_PIN(WMT_PIN_SPI0CLK, "spi0_clk"),
304 PINCTRL_PIN(WMT_PIN_SPI0MISO, "spi0_miso"),
305 PINCTRL_PIN(WMT_PIN_SPI0MOSI, "spi0_mosi"),
306 PINCTRL_PIN(WMT_PIN_SPI0SS, "spi0_ss"),
307 PINCTRL_PIN(WMT_PIN_SPI1CLK, "spi1_clk"),
308 PINCTRL_PIN(WMT_PIN_SPI1MISO, "spi1_miso"),
309 PINCTRL_PIN(WMT_PIN_SPI1MOSI, "spi1_mosi"),
310 PINCTRL_PIN(WMT_PIN_SPI1SS, "spi1_ss"),
311 PINCTRL_PIN(WMT_PIN_SPI2CLK, "spi2_clk"),
312 PINCTRL_PIN(WMT_PIN_SPI2MISO, "spi2_miso"),
313 PINCTRL_PIN(WMT_PIN_SPI2MOSI, "spi2_mosi"),
314 PINCTRL_PIN(WMT_PIN_SPI2SS, "spi2_ss"),
315 PINCTRL_PIN(WMT_PIN_UART0_RTS, "uart0_rts"),
316 PINCTRL_PIN(WMT_PIN_UART0_TXD, "uart0_txd"),
317 PINCTRL_PIN(WMT_PIN_UART0_CTS, "uart0_cts"),
318 PINCTRL_PIN(WMT_PIN_UART0_RXD, "uart0_rxd"),
319 PINCTRL_PIN(WMT_PIN_UART1_RTS, "uart1_rts"),
320 PINCTRL_PIN(WMT_PIN_UART1_TXD, "uart1_txd"),
321 PINCTRL_PIN(WMT_PIN_UART1_CTS, "uart1_cts"),
322 PINCTRL_PIN(WMT_PIN_UART1_RXD, "uart1_rxd"),
323 PINCTRL_PIN(WMT_PIN_UART2_RTS, "uart2_rts"),
324 PINCTRL_PIN(WMT_PIN_UART2_TXD, "uart2_txd"),
325 PINCTRL_PIN(WMT_PIN_UART2_CTS, "uart2_cts"),
326 PINCTRL_PIN(WMT_PIN_UART2_RXD, "uart2_rxd"),
327 PINCTRL_PIN(WMT_PIN_UART3_RTS, "uart3_rts"),
328 PINCTRL_PIN(WMT_PIN_UART3_TXD, "uart3_txd"),
329 PINCTRL_PIN(WMT_PIN_UART3_CTS, "uart3_cts"),
330 PINCTRL_PIN(WMT_PIN_UART3_RXD, "uart3_rxd"),
331 PINCTRL_PIN(WMT_PIN_I2C0SCL, "i2c0_scl"),
332 PINCTRL_PIN(WMT_PIN_I2C0SDA, "i2c0_sda"),
333 PINCTRL_PIN(WMT_PIN_I2C1SCL, "i2c1_scl"),
334 PINCTRL_PIN(WMT_PIN_I2C1SDA, "i2c1_sda"),
335 PINCTRL_PIN(WMT_PIN_I2C2SCL, "i2c2_scl"),
336 PINCTRL_PIN(WMT_PIN_I2C2SDA, "i2c2_sda"),
337};
338
339/* Order of these names must match the above list */
340static const char * const wm8505_groups[] = {
341 "extgpio0",
342 "extgpio1",
343 "extgpio2",
344 "extgpio3",
345 "extgpio4",
346 "extgpio5",
347 "extgpio6",
348 "extgpio7",
349 "wakeup0",
350 "wakeup1",
351 "wakeup2",
352 "wakeup3",
353 "susgpio0",
354 "sd_data0",
355 "sd_data1",
356 "sd_data2",
357 "sd_data3",
358 "mmc_data0",
359 "mmc_data1",
360 "mmc_data2",
361 "mmc_data3",
362 "vdin0",
363 "vdin1",
364 "vdin2",
365 "vdin3",
366 "vdin4",
367 "vdin5",
368 "vdin6",
369 "vdin7",
370 "vdout0",
371 "vdout1",
372 "vdout2",
373 "vdout3",
374 "vdout4",
375 "vdout5",
376 "vdout6",
377 "vdout7",
378 "vdout8",
379 "vdout9",
380 "vdout10",
381 "vdout11",
382 "vdout12",
383 "vdout13",
384 "vdout14",
385 "vdout15",
386 "vdout16",
387 "vdout17",
388 "vdout18",
389 "vdout19",
390 "vdout20",
391 "vdout21",
392 "vdout22",
393 "vdout23",
394 "v_hsync",
395 "v_vsync",
396 "vga_hsync",
397 "vga_vsync",
398 "vd_hsync",
399 "vd_vsync",
400 "nor_d0",
401 "nor_d1",
402 "nor_d2",
403 "nor_d3",
404 "nor_d4",
405 "nor_d5",
406 "nor_d6",
407 "nor_d7",
408 "nor_d8",
409 "nor_d9",
410 "nor_d10",
411 "nor_d11",
412 "nor_d12",
413 "nor_d13",
414 "nor_d14",
415 "nor_d15",
416 "nor_a0",
417 "nor_a1",
418 "nor_a2",
419 "nor_a3",
420 "nor_a4",
421 "nor_a5",
422 "nor_a6",
423 "nor_a7",
424 "nor_a8",
425 "nor_a9",
426 "nor_a10",
427 "nor_a11",
428 "nor_a12",
429 "nor_a13",
430 "nor_a14",
431 "nor_a15",
432 "nor_a16",
433 "nor_a17",
434 "nor_a18",
435 "nor_a19",
436 "nor_a20",
437 "nor_a21",
438 "nor_a22",
439 "nor_a23",
440 "nor_a24",
441 "ac97_sdi",
442 "ac97_sync",
443 "ac97_sdo",
444 "ac97_bclk",
445 "ac97_rst",
446 "sf_do",
447 "sf_cs0",
448 "sf_cs1",
449 "sf_clk",
450 "sf_di",
451 "spi0_clk",
452 "spi0_miso",
453 "spi0_mosi",
454 "spi0_ss",
455 "spi1_clk",
456 "spi1_miso",
457 "spi1_mosi",
458 "spi1_ss",
459 "spi2_clk",
460 "spi2_miso",
461 "spi2_mosi",
462 "spi2_ss",
463 "uart0_rts",
464 "uart0_txd",
465 "uart0_cts",
466 "uart0_rxd",
467 "uart1_rts",
468 "uart1_txd",
469 "uart1_cts",
470 "uart1_rxd",
471 "uart2_rts",
472 "uart2_txd",
473 "uart2_cts",
474 "uart2_rxd",
475 "uart3_rts",
476 "uart3_txd",
477 "uart3_cts",
478 "uart3_rxd",
479 "i2c0_scl",
480 "i2c0_sda",
481 "i2c1_scl",
482 "i2c1_sda",
483 "i2c2_scl",
484 "i2c2_sda",
485};
486
487static int wm8505_pinctrl_probe(struct platform_device *pdev)
488{
489 struct wmt_pinctrl_data *data;
490
491 data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
492 if (!data) {
493 dev_err(&pdev->dev, "failed to allocate data\n");
494 return -ENOMEM;
495 }
496
497 data->banks = wm8505_banks;
498 data->nbanks = ARRAY_SIZE(wm8505_banks);
499 data->pins = wm8505_pins;
500 data->npins = ARRAY_SIZE(wm8505_pins);
501 data->groups = wm8505_groups;
502 data->ngroups = ARRAY_SIZE(wm8505_groups);
503
504 return wmt_pinctrl_probe(pdev, data);
505}
506
507static int wm8505_pinctrl_remove(struct platform_device *pdev)
508{
509 return wmt_pinctrl_remove(pdev);
510}
511
512static struct of_device_id wmt_pinctrl_of_match[] = {
513 { .compatible = "wm,wm8505-pinctrl" },
514 { /* sentinel */ },
515};
516
517static struct platform_driver wmt_pinctrl_driver = {
518 .probe = wm8505_pinctrl_probe,
519 .remove = wm8505_pinctrl_remove,
520 .driver = {
521 .name = "pinctrl-wm8505",
522 .owner = THIS_MODULE,
523 .of_match_table = wmt_pinctrl_of_match,
524 },
525};
526
527module_platform_driver(wmt_pinctrl_driver);
528
529MODULE_AUTHOR("Tony Prisk <linux@prisktech.co.nz>");
530MODULE_DESCRIPTION("Wondermedia WM8505 Pincontrol driver");
531MODULE_LICENSE("GPL v2");
532MODULE_DEVICE_TABLE(of, wmt_pinctrl_of_match);
diff --git a/drivers/pinctrl/vt8500/pinctrl-wm8650.c b/drivers/pinctrl/vt8500/pinctrl-wm8650.c
new file mode 100644
index 000000000000..7de57f063153
--- /dev/null
+++ b/drivers/pinctrl/vt8500/pinctrl-wm8650.c
@@ -0,0 +1,370 @@
1/*
2 * Pinctrl data for Wondermedia WM8650 SoC
3 *
4 * Copyright (c) 2013 Tony Prisk <linux@prisktech.co.nz>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 */
15
16#include <linux/io.h>
17#include <linux/module.h>
18#include <linux/pinctrl/pinctrl.h>
19#include <linux/platform_device.h>
20#include <linux/slab.h>
21
22#include "pinctrl-wmt.h"
23
24/*
25 * Describe the register offsets within the GPIO memory space
26 * The dedicated external GPIO's should always be listed in bank 0
27 * so they are exported in the 0..31 range which is what users
28 * expect.
29 *
30 * Do not reorder these banks as it will change the pin numbering
31 */
32static const struct wmt_pinctrl_bank_registers wm8650_banks[] = {
33 WMT_PINCTRL_BANK(0x40, 0x80, 0xC0, 0x00, 0x480, 0x4C0), /* 0 */
34 WMT_PINCTRL_BANK(0x44, 0x84, 0xC4, 0x04, 0x484, 0x4C4), /* 1 */
35 WMT_PINCTRL_BANK(0x48, 0x88, 0xC8, 0x08, 0x488, 0x4C8), /* 2 */
36 WMT_PINCTRL_BANK(0x4C, 0x8C, 0xCC, 0x0C, 0x48C, 0x4CC), /* 3 */
37 WMT_PINCTRL_BANK(0x50, 0x90, 0xD0, 0x10, 0x490, 0x4D0), /* 4 */
38 WMT_PINCTRL_BANK(0x54, 0x94, 0xD4, 0x14, 0x494, 0x4D4), /* 5 */
39 WMT_PINCTRL_BANK(0x58, 0x98, 0xD8, 0x18, 0x498, 0x4D8), /* 6 */
40 WMT_PINCTRL_BANK(0x5C, 0x9C, 0xDC, 0x1C, 0x49C, 0x4DC), /* 7 */
41};
42
43/* Please keep sorted by bank/bit */
44#define WMT_PIN_EXTGPIO0 WMT_PIN(0, 0)
45#define WMT_PIN_EXTGPIO1 WMT_PIN(0, 1)
46#define WMT_PIN_EXTGPIO2 WMT_PIN(0, 2)
47#define WMT_PIN_EXTGPIO3 WMT_PIN(0, 3)
48#define WMT_PIN_EXTGPIO4 WMT_PIN(0, 4)
49#define WMT_PIN_EXTGPIO5 WMT_PIN(0, 5)
50#define WMT_PIN_EXTGPIO6 WMT_PIN(0, 6)
51#define WMT_PIN_EXTGPIO7 WMT_PIN(0, 7)
52#define WMT_PIN_WAKEUP0 WMT_PIN(0, 16)
53#define WMT_PIN_WAKEUP1 WMT_PIN(0, 17)
54#define WMT_PIN_SUSGPIO0 WMT_PIN(0, 21)
55#define WMT_PIN_SD0CD WMT_PIN(0, 28)
56#define WMT_PIN_SD1CD WMT_PIN(0, 29)
57#define WMT_PIN_VDOUT0 WMT_PIN(1, 0)
58#define WMT_PIN_VDOUT1 WMT_PIN(1, 1)
59#define WMT_PIN_VDOUT2 WMT_PIN(1, 2)
60#define WMT_PIN_VDOUT3 WMT_PIN(1, 3)
61#define WMT_PIN_VDOUT4 WMT_PIN(1, 4)
62#define WMT_PIN_VDOUT5 WMT_PIN(1, 5)
63#define WMT_PIN_VDOUT6 WMT_PIN(1, 6)
64#define WMT_PIN_VDOUT7 WMT_PIN(1, 7)
65#define WMT_PIN_VDOUT8 WMT_PIN(1, 8)
66#define WMT_PIN_VDOUT9 WMT_PIN(1, 9)
67#define WMT_PIN_VDOUT10 WMT_PIN(1, 10)
68#define WMT_PIN_VDOUT11 WMT_PIN(1, 11)
69#define WMT_PIN_VDOUT12 WMT_PIN(1, 12)
70#define WMT_PIN_VDOUT13 WMT_PIN(1, 13)
71#define WMT_PIN_VDOUT14 WMT_PIN(1, 14)
72#define WMT_PIN_VDOUT15 WMT_PIN(1, 15)
73#define WMT_PIN_VDOUT16 WMT_PIN(1, 16)
74#define WMT_PIN_VDOUT17 WMT_PIN(1, 17)
75#define WMT_PIN_VDOUT18 WMT_PIN(1, 18)
76#define WMT_PIN_VDOUT19 WMT_PIN(1, 19)
77#define WMT_PIN_VDOUT20 WMT_PIN(1, 20)
78#define WMT_PIN_VDOUT21 WMT_PIN(1, 21)
79#define WMT_PIN_VDOUT22 WMT_PIN(1, 22)
80#define WMT_PIN_VDOUT23 WMT_PIN(1, 23)
81#define WMT_PIN_VDIN0 WMT_PIN(2, 0)
82#define WMT_PIN_VDIN1 WMT_PIN(2, 1)
83#define WMT_PIN_VDIN2 WMT_PIN(2, 2)
84#define WMT_PIN_VDIN3 WMT_PIN(2, 3)
85#define WMT_PIN_VDIN4 WMT_PIN(2, 4)
86#define WMT_PIN_VDIN5 WMT_PIN(2, 5)
87#define WMT_PIN_VDIN6 WMT_PIN(2, 6)
88#define WMT_PIN_VDIN7 WMT_PIN(2, 7)
89#define WMT_PIN_I2C1SCL WMT_PIN(2, 12)
90#define WMT_PIN_I2C1SDA WMT_PIN(2, 13)
91#define WMT_PIN_SPI0MOSI WMT_PIN(2, 24)
92#define WMT_PIN_SPI0MISO WMT_PIN(2, 25)
93#define WMT_PIN_SPI0SS0 WMT_PIN(2, 26)
94#define WMT_PIN_SPI0CLK WMT_PIN(2, 27)
95#define WMT_PIN_SD0DATA0 WMT_PIN(3, 8)
96#define WMT_PIN_SD0DATA1 WMT_PIN(3, 9)
97#define WMT_PIN_SD0DATA2 WMT_PIN(3, 10)
98#define WMT_PIN_SD0DATA3 WMT_PIN(3, 11)
99#define WMT_PIN_SD0CLK WMT_PIN(3, 12)
100#define WMT_PIN_SD0WP WMT_PIN(3, 13)
101#define WMT_PIN_SD0CMD WMT_PIN(3, 14)
102#define WMT_PIN_SD1DATA0 WMT_PIN(3, 24)
103#define WMT_PIN_SD1DATA1 WMT_PIN(3, 25)
104#define WMT_PIN_SD1DATA2 WMT_PIN(3, 26)
105#define WMT_PIN_SD1DATA3 WMT_PIN(3, 27)
106#define WMT_PIN_SD1DATA4 WMT_PIN(3, 28)
107#define WMT_PIN_SD1DATA5 WMT_PIN(3, 29)
108#define WMT_PIN_SD1DATA6 WMT_PIN(3, 30)
109#define WMT_PIN_SD1DATA7 WMT_PIN(3, 31)
110#define WMT_PIN_I2C0SCL WMT_PIN(5, 8)
111#define WMT_PIN_I2C0SDA WMT_PIN(5, 9)
112#define WMT_PIN_UART0RTS WMT_PIN(5, 16)
113#define WMT_PIN_UART0TXD WMT_PIN(5, 17)
114#define WMT_PIN_UART0CTS WMT_PIN(5, 18)
115#define WMT_PIN_UART0RXD WMT_PIN(5, 19)
116#define WMT_PIN_UART1RTS WMT_PIN(5, 20)
117#define WMT_PIN_UART1TXD WMT_PIN(5, 21)
118#define WMT_PIN_UART1CTS WMT_PIN(5, 22)
119#define WMT_PIN_UART1RXD WMT_PIN(5, 23)
120#define WMT_PIN_UART2RTS WMT_PIN(5, 24)
121#define WMT_PIN_UART2TXD WMT_PIN(5, 25)
122#define WMT_PIN_UART2CTS WMT_PIN(5, 26)
123#define WMT_PIN_UART2RXD WMT_PIN(5, 27)
124#define WMT_PIN_UART3RTS WMT_PIN(5, 28)
125#define WMT_PIN_UART3TXD WMT_PIN(5, 29)
126#define WMT_PIN_UART3CTS WMT_PIN(5, 30)
127#define WMT_PIN_UART3RXD WMT_PIN(5, 31)
128#define WMT_PIN_KPADROW0 WMT_PIN(6, 16)
129#define WMT_PIN_KPADROW1 WMT_PIN(6, 17)
130#define WMT_PIN_KPADCOL0 WMT_PIN(6, 18)
131#define WMT_PIN_KPADCOL1 WMT_PIN(6, 19)
132#define WMT_PIN_SD1CLK WMT_PIN(7, 0)
133#define WMT_PIN_SD1CMD WMT_PIN(7, 1)
134#define WMT_PIN_SD1WP WMT_PIN(7, 13)
135
136static const struct pinctrl_pin_desc wm8650_pins[] = {
137 PINCTRL_PIN(WMT_PIN_EXTGPIO0, "extgpio0"),
138 PINCTRL_PIN(WMT_PIN_EXTGPIO1, "extgpio1"),
139 PINCTRL_PIN(WMT_PIN_EXTGPIO2, "extgpio2"),
140 PINCTRL_PIN(WMT_PIN_EXTGPIO3, "extgpio3"),
141 PINCTRL_PIN(WMT_PIN_EXTGPIO4, "extgpio4"),
142 PINCTRL_PIN(WMT_PIN_EXTGPIO5, "extgpio5"),
143 PINCTRL_PIN(WMT_PIN_EXTGPIO6, "extgpio6"),
144 PINCTRL_PIN(WMT_PIN_EXTGPIO7, "extgpio7"),
145 PINCTRL_PIN(WMT_PIN_WAKEUP0, "wakeup0"),
146 PINCTRL_PIN(WMT_PIN_WAKEUP1, "wakeup1"),
147 PINCTRL_PIN(WMT_PIN_SUSGPIO0, "susgpio0"),
148 PINCTRL_PIN(WMT_PIN_SD0CD, "sd0_cd"),
149 PINCTRL_PIN(WMT_PIN_SD1CD, "sd1_cd"),
150 PINCTRL_PIN(WMT_PIN_VDOUT0, "vdout0"),
151 PINCTRL_PIN(WMT_PIN_VDOUT1, "vdout1"),
152 PINCTRL_PIN(WMT_PIN_VDOUT2, "vdout2"),
153 PINCTRL_PIN(WMT_PIN_VDOUT3, "vdout3"),
154 PINCTRL_PIN(WMT_PIN_VDOUT4, "vdout4"),
155 PINCTRL_PIN(WMT_PIN_VDOUT5, "vdout5"),
156 PINCTRL_PIN(WMT_PIN_VDOUT6, "vdout6"),
157 PINCTRL_PIN(WMT_PIN_VDOUT7, "vdout7"),
158 PINCTRL_PIN(WMT_PIN_VDOUT8, "vdout8"),
159 PINCTRL_PIN(WMT_PIN_VDOUT9, "vdout9"),
160 PINCTRL_PIN(WMT_PIN_VDOUT10, "vdout10"),
161 PINCTRL_PIN(WMT_PIN_VDOUT11, "vdout11"),
162 PINCTRL_PIN(WMT_PIN_VDOUT12, "vdout12"),
163 PINCTRL_PIN(WMT_PIN_VDOUT13, "vdout13"),
164 PINCTRL_PIN(WMT_PIN_VDOUT14, "vdout14"),
165 PINCTRL_PIN(WMT_PIN_VDOUT15, "vdout15"),
166 PINCTRL_PIN(WMT_PIN_VDOUT16, "vdout16"),
167 PINCTRL_PIN(WMT_PIN_VDOUT17, "vdout17"),
168 PINCTRL_PIN(WMT_PIN_VDOUT18, "vdout18"),
169 PINCTRL_PIN(WMT_PIN_VDOUT19, "vdout19"),
170 PINCTRL_PIN(WMT_PIN_VDOUT20, "vdout20"),
171 PINCTRL_PIN(WMT_PIN_VDOUT21, "vdout21"),
172 PINCTRL_PIN(WMT_PIN_VDOUT22, "vdout22"),
173 PINCTRL_PIN(WMT_PIN_VDOUT23, "vdout23"),
174 PINCTRL_PIN(WMT_PIN_VDIN0, "vdin0"),
175 PINCTRL_PIN(WMT_PIN_VDIN1, "vdin1"),
176 PINCTRL_PIN(WMT_PIN_VDIN2, "vdin2"),
177 PINCTRL_PIN(WMT_PIN_VDIN3, "vdin3"),
178 PINCTRL_PIN(WMT_PIN_VDIN4, "vdin4"),
179 PINCTRL_PIN(WMT_PIN_VDIN5, "vdin5"),
180 PINCTRL_PIN(WMT_PIN_VDIN6, "vdin6"),
181 PINCTRL_PIN(WMT_PIN_VDIN7, "vdin7"),
182 PINCTRL_PIN(WMT_PIN_I2C1SCL, "i2c1_scl"),
183 PINCTRL_PIN(WMT_PIN_I2C1SDA, "i2c1_sda"),
184 PINCTRL_PIN(WMT_PIN_SPI0MOSI, "spi0_mosi"),
185 PINCTRL_PIN(WMT_PIN_SPI0MISO, "spi0_miso"),
186 PINCTRL_PIN(WMT_PIN_SPI0SS0, "spi0_ss0"),
187 PINCTRL_PIN(WMT_PIN_SPI0CLK, "spi0_clk"),
188 PINCTRL_PIN(WMT_PIN_SD0DATA0, "sd0_data0"),
189 PINCTRL_PIN(WMT_PIN_SD0DATA1, "sd0_data1"),
190 PINCTRL_PIN(WMT_PIN_SD0DATA2, "sd0_data2"),
191 PINCTRL_PIN(WMT_PIN_SD0DATA3, "sd0_data3"),
192 PINCTRL_PIN(WMT_PIN_SD0CLK, "sd0_clk"),
193 PINCTRL_PIN(WMT_PIN_SD0WP, "sd0_wp"),
194 PINCTRL_PIN(WMT_PIN_SD0CMD, "sd0_cmd"),
195 PINCTRL_PIN(WMT_PIN_SD1DATA0, "sd1_data0"),
196 PINCTRL_PIN(WMT_PIN_SD1DATA1, "sd1_data1"),
197 PINCTRL_PIN(WMT_PIN_SD1DATA2, "sd1_data2"),
198 PINCTRL_PIN(WMT_PIN_SD1DATA3, "sd1_data3"),
199 PINCTRL_PIN(WMT_PIN_SD1DATA4, "sd1_data4"),
200 PINCTRL_PIN(WMT_PIN_SD1DATA5, "sd1_data5"),
201 PINCTRL_PIN(WMT_PIN_SD1DATA6, "sd1_data6"),
202 PINCTRL_PIN(WMT_PIN_SD1DATA7, "sd1_data7"),
203 PINCTRL_PIN(WMT_PIN_I2C0SCL, "i2c0_scl"),
204 PINCTRL_PIN(WMT_PIN_I2C0SDA, "i2c0_sda"),
205 PINCTRL_PIN(WMT_PIN_UART0RTS, "uart0_rts"),
206 PINCTRL_PIN(WMT_PIN_UART0TXD, "uart0_txd"),
207 PINCTRL_PIN(WMT_PIN_UART0CTS, "uart0_cts"),
208 PINCTRL_PIN(WMT_PIN_UART0RXD, "uart0_rxd"),
209 PINCTRL_PIN(WMT_PIN_UART1RTS, "uart1_rts"),
210 PINCTRL_PIN(WMT_PIN_UART1TXD, "uart1_txd"),
211 PINCTRL_PIN(WMT_PIN_UART1CTS, "uart1_cts"),
212 PINCTRL_PIN(WMT_PIN_UART1RXD, "uart1_rxd"),
213 PINCTRL_PIN(WMT_PIN_UART2RTS, "uart2_rts"),
214 PINCTRL_PIN(WMT_PIN_UART2TXD, "uart2_txd"),
215 PINCTRL_PIN(WMT_PIN_UART2CTS, "uart2_cts"),
216 PINCTRL_PIN(WMT_PIN_UART2RXD, "uart2_rxd"),
217 PINCTRL_PIN(WMT_PIN_UART3RTS, "uart3_rts"),
218 PINCTRL_PIN(WMT_PIN_UART3TXD, "uart3_txd"),
219 PINCTRL_PIN(WMT_PIN_UART3CTS, "uart3_cts"),
220 PINCTRL_PIN(WMT_PIN_UART3RXD, "uart3_rxd"),
221 PINCTRL_PIN(WMT_PIN_KPADROW0, "kpadrow0"),
222 PINCTRL_PIN(WMT_PIN_KPADROW1, "kpadrow1"),
223 PINCTRL_PIN(WMT_PIN_KPADCOL0, "kpadcol0"),
224 PINCTRL_PIN(WMT_PIN_KPADCOL1, "kpadcol1"),
225 PINCTRL_PIN(WMT_PIN_SD1CLK, "sd1_clk"),
226 PINCTRL_PIN(WMT_PIN_SD1CMD, "sd1_cmd"),
227 PINCTRL_PIN(WMT_PIN_SD1WP, "sd1_wp"),
228};
229
230/* Order of these names must match the above list */
231static const char * const wm8650_groups[] = {
232 "extgpio0",
233 "extgpio1",
234 "extgpio2",
235 "extgpio3",
236 "extgpio4",
237 "extgpio5",
238 "extgpio6",
239 "extgpio7",
240 "wakeup0",
241 "wakeup1",
242 "susgpio0",
243 "sd0_cd",
244 "sd1_cd",
245 "vdout0",
246 "vdout1",
247 "vdout2",
248 "vdout3",
249 "vdout4",
250 "vdout5",
251 "vdout6",
252 "vdout7",
253 "vdout8",
254 "vdout9",
255 "vdout10",
256 "vdout11",
257 "vdout12",
258 "vdout13",
259 "vdout14",
260 "vdout15",
261 "vdout16",
262 "vdout17",
263 "vdout18",
264 "vdout19",
265 "vdout20",
266 "vdout21",
267 "vdout22",
268 "vdout23",
269 "vdin0",
270 "vdin1",
271 "vdin2",
272 "vdin3",
273 "vdin4",
274 "vdin5",
275 "vdin6",
276 "vdin7",
277 "i2c1_scl",
278 "i2c1_sda",
279 "spi0_mosi",
280 "spi0_miso",
281 "spi0_ss0",
282 "spi0_clk",
283 "sd0_data0",
284 "sd0_data1",
285 "sd0_data2",
286 "sd0_data3",
287 "sd0_clk",
288 "sd0_wp",
289 "sd0_cmd",
290 "sd1_data0",
291 "sd1_data1",
292 "sd1_data2",
293 "sd1_data3",
294 "sd1_data4",
295 "sd1_data5",
296 "sd1_data6",
297 "sd1_data7",
298 "i2c0_scl",
299 "i2c0_sda",
300 "uart0_rts",
301 "uart0_txd",
302 "uart0_cts",
303 "uart0_rxd",
304 "uart1_rts",
305 "uart1_txd",
306 "uart1_cts",
307 "uart1_rxd",
308 "uart2_rts",
309 "uart2_txd",
310 "uart2_cts",
311 "uart2_rxd",
312 "uart3_rts",
313 "uart3_txd",
314 "uart3_cts",
315 "uart3_rxd",
316 "kpadrow0",
317 "kpadrow1",
318 "kpadcol0",
319 "kpadcol1",
320 "sd1_clk",
321 "sd1_cmd",
322 "sd1_wp",
323};
324
325static int wm8650_pinctrl_probe(struct platform_device *pdev)
326{
327 struct wmt_pinctrl_data *data;
328
329 data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
330 if (!data) {
331 dev_err(&pdev->dev, "failed to allocate data\n");
332 return -ENOMEM;
333 }
334
335 data->banks = wm8650_banks;
336 data->nbanks = ARRAY_SIZE(wm8650_banks);
337 data->pins = wm8650_pins;
338 data->npins = ARRAY_SIZE(wm8650_pins);
339 data->groups = wm8650_groups;
340 data->ngroups = ARRAY_SIZE(wm8650_groups);
341
342 return wmt_pinctrl_probe(pdev, data);
343}
344
345static int wm8650_pinctrl_remove(struct platform_device *pdev)
346{
347 return wmt_pinctrl_remove(pdev);
348}
349
350static struct of_device_id wmt_pinctrl_of_match[] = {
351 { .compatible = "wm,wm8650-pinctrl" },
352 { /* sentinel */ },
353};
354
355static struct platform_driver wmt_pinctrl_driver = {
356 .probe = wm8650_pinctrl_probe,
357 .remove = wm8650_pinctrl_remove,
358 .driver = {
359 .name = "pinctrl-wm8650",
360 .owner = THIS_MODULE,
361 .of_match_table = wmt_pinctrl_of_match,
362 },
363};
364
365module_platform_driver(wmt_pinctrl_driver);
366
367MODULE_AUTHOR("Tony Prisk <linux@prisktech.co.nz>");
368MODULE_DESCRIPTION("Wondermedia WM8650 Pincontrol driver");
369MODULE_LICENSE("GPL v2");
370MODULE_DEVICE_TABLE(of, wmt_pinctrl_of_match);
diff --git a/drivers/pinctrl/vt8500/pinctrl-wm8750.c b/drivers/pinctrl/vt8500/pinctrl-wm8750.c
new file mode 100644
index 000000000000..b964cc550568
--- /dev/null
+++ b/drivers/pinctrl/vt8500/pinctrl-wm8750.c
@@ -0,0 +1,409 @@
1/*
2 * Pinctrl data for Wondermedia WM8750 SoC
3 *
4 * Copyright (c) 2013 Tony Prisk <linux@prisktech.co.nz>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 */
15
16#include <linux/io.h>
17#include <linux/module.h>
18#include <linux/pinctrl/pinctrl.h>
19#include <linux/platform_device.h>
20#include <linux/slab.h>
21
22#include "pinctrl-wmt.h"
23
24/*
25 * Describe the register offsets within the GPIO memory space
26 * The dedicated external GPIO's should always be listed in bank 0
27 * so they are exported in the 0..31 range which is what users
28 * expect.
29 *
30 * Do not reorder these banks as it will change the pin numbering
31 */
32static const struct wmt_pinctrl_bank_registers wm8750_banks[] = {
33 WMT_PINCTRL_BANK(0x40, 0x80, 0xC0, 0x00, 0x480, 0x4C0), /* 0 */
34 WMT_PINCTRL_BANK(0x44, 0x84, 0xC4, 0x04, 0x484, 0x4C4), /* 1 */
35 WMT_PINCTRL_BANK(0x48, 0x88, 0xC8, 0x08, 0x488, 0x4C8), /* 2 */
36 WMT_PINCTRL_BANK(0x4C, 0x8C, 0xCC, 0x0C, 0x48C, 0x4CC), /* 3 */
37 WMT_PINCTRL_BANK(0x50, 0x90, 0xD0, 0x10, 0x490, 0x4D0), /* 4 */
38 WMT_PINCTRL_BANK(0x54, 0x94, 0xD4, 0x14, 0x494, 0x4D4), /* 5 */
39 WMT_PINCTRL_BANK(0x58, 0x98, 0xD8, 0x18, 0x498, 0x4D8), /* 6 */
40 WMT_PINCTRL_BANK(0x5C, 0x9C, 0xDC, 0x1C, 0x49C, 0x4DC), /* 7 */
41 WMT_PINCTRL_BANK(0x60, 0xA0, 0xE0, 0x20, 0x4A0, 0x4E0), /* 8 */
42 WMT_PINCTRL_BANK(0x70, 0xB0, 0xF0, 0x30, 0x4B0, 0x4F0), /* 9 */
43 WMT_PINCTRL_BANK(0x7C, 0xBC, 0xDC, 0x3C, 0x4BC, 0x4FC), /* 10 */
44};
45
46/* Please keep sorted by bank/bit */
47#define WMT_PIN_EXTGPIO0 WMT_PIN(0, 0)
48#define WMT_PIN_EXTGPIO1 WMT_PIN(0, 1)
49#define WMT_PIN_EXTGPIO2 WMT_PIN(0, 2)
50#define WMT_PIN_EXTGPIO3 WMT_PIN(0, 3)
51#define WMT_PIN_EXTGPIO4 WMT_PIN(0, 4)
52#define WMT_PIN_EXTGPIO5 WMT_PIN(0, 5)
53#define WMT_PIN_EXTGPIO6 WMT_PIN(0, 6)
54#define WMT_PIN_EXTGPIO7 WMT_PIN(0, 7)
55#define WMT_PIN_WAKEUP0 WMT_PIN(0, 16)
56#define WMT_PIN_WAKEUP1 WMT_PIN(0, 16)
57#define WMT_PIN_SD0CD WMT_PIN(0, 28)
58#define WMT_PIN_VDOUT0 WMT_PIN(1, 0)
59#define WMT_PIN_VDOUT1 WMT_PIN(1, 1)
60#define WMT_PIN_VDOUT2 WMT_PIN(1, 2)
61#define WMT_PIN_VDOUT3 WMT_PIN(1, 3)
62#define WMT_PIN_VDOUT4 WMT_PIN(1, 4)
63#define WMT_PIN_VDOUT5 WMT_PIN(1, 5)
64#define WMT_PIN_VDOUT6 WMT_PIN(1, 6)
65#define WMT_PIN_VDOUT7 WMT_PIN(1, 7)
66#define WMT_PIN_VDOUT8 WMT_PIN(1, 8)
67#define WMT_PIN_VDOUT9 WMT_PIN(1, 9)
68#define WMT_PIN_VDOUT10 WMT_PIN(1, 10)
69#define WMT_PIN_VDOUT11 WMT_PIN(1, 11)
70#define WMT_PIN_VDOUT12 WMT_PIN(1, 12)
71#define WMT_PIN_VDOUT13 WMT_PIN(1, 13)
72#define WMT_PIN_VDOUT14 WMT_PIN(1, 14)
73#define WMT_PIN_VDOUT15 WMT_PIN(1, 15)
74#define WMT_PIN_VDOUT16 WMT_PIN(1, 16)
75#define WMT_PIN_VDOUT17 WMT_PIN(1, 17)
76#define WMT_PIN_VDOUT18 WMT_PIN(1, 18)
77#define WMT_PIN_VDOUT19 WMT_PIN(1, 19)
78#define WMT_PIN_VDOUT20 WMT_PIN(1, 20)
79#define WMT_PIN_VDOUT21 WMT_PIN(1, 21)
80#define WMT_PIN_VDOUT22 WMT_PIN(1, 22)
81#define WMT_PIN_VDOUT23 WMT_PIN(1, 23)
82#define WMT_PIN_VDIN0 WMT_PIN(2, 0)
83#define WMT_PIN_VDIN1 WMT_PIN(2, 1)
84#define WMT_PIN_VDIN2 WMT_PIN(2, 2)
85#define WMT_PIN_VDIN3 WMT_PIN(2, 3)
86#define WMT_PIN_VDIN4 WMT_PIN(2, 4)
87#define WMT_PIN_VDIN5 WMT_PIN(2, 5)
88#define WMT_PIN_VDIN6 WMT_PIN(2, 6)
89#define WMT_PIN_VDIN7 WMT_PIN(2, 7)
90#define WMT_PIN_SPI0_MOSI WMT_PIN(2, 24)
91#define WMT_PIN_SPI0_MISO WMT_PIN(2, 25)
92#define WMT_PIN_SPI0_SS WMT_PIN(2, 26)
93#define WMT_PIN_SPI0_CLK WMT_PIN(2, 27)
94#define WMT_PIN_SPI0_SSB WMT_PIN(2, 28)
95#define WMT_PIN_SD0CLK WMT_PIN(3, 17)
96#define WMT_PIN_SD0CMD WMT_PIN(3, 18)
97#define WMT_PIN_SD0WP WMT_PIN(3, 19)
98#define WMT_PIN_SD0DATA0 WMT_PIN(3, 20)
99#define WMT_PIN_SD0DATA1 WMT_PIN(3, 21)
100#define WMT_PIN_SD0DATA2 WMT_PIN(3, 22)
101#define WMT_PIN_SD0DATA3 WMT_PIN(3, 23)
102#define WMT_PIN_SD1DATA0 WMT_PIN(3, 24)
103#define WMT_PIN_SD1DATA1 WMT_PIN(3, 25)
104#define WMT_PIN_SD1DATA2 WMT_PIN(3, 26)
105#define WMT_PIN_SD1DATA3 WMT_PIN(3, 27)
106#define WMT_PIN_SD1DATA4 WMT_PIN(3, 28)
107#define WMT_PIN_SD1DATA5 WMT_PIN(3, 29)
108#define WMT_PIN_SD1DATA6 WMT_PIN(3, 30)
109#define WMT_PIN_SD1DATA7 WMT_PIN(3, 31)
110#define WMT_PIN_I2C0_SCL WMT_PIN(5, 8)
111#define WMT_PIN_I2C0_SDA WMT_PIN(5, 9)
112#define WMT_PIN_I2C1_SCL WMT_PIN(5, 10)
113#define WMT_PIN_I2C1_SDA WMT_PIN(5, 11)
114#define WMT_PIN_I2C2_SCL WMT_PIN(5, 12)
115#define WMT_PIN_I2C2_SDA WMT_PIN(5, 13)
116#define WMT_PIN_UART0_RTS WMT_PIN(5, 16)
117#define WMT_PIN_UART0_TXD WMT_PIN(5, 17)
118#define WMT_PIN_UART0_CTS WMT_PIN(5, 18)
119#define WMT_PIN_UART0_RXD WMT_PIN(5, 19)
120#define WMT_PIN_UART1_RTS WMT_PIN(5, 20)
121#define WMT_PIN_UART1_TXD WMT_PIN(5, 21)
122#define WMT_PIN_UART1_CTS WMT_PIN(5, 22)
123#define WMT_PIN_UART1_RXD WMT_PIN(5, 23)
124#define WMT_PIN_UART2_RTS WMT_PIN(5, 24)
125#define WMT_PIN_UART2_TXD WMT_PIN(5, 25)
126#define WMT_PIN_UART2_CTS WMT_PIN(5, 26)
127#define WMT_PIN_UART2_RXD WMT_PIN(5, 27)
128#define WMT_PIN_UART3_RTS WMT_PIN(5, 28)
129#define WMT_PIN_UART3_TXD WMT_PIN(5, 29)
130#define WMT_PIN_UART3_CTS WMT_PIN(5, 30)
131#define WMT_PIN_UART3_RXD WMT_PIN(5, 31)
132#define WMT_PIN_SD2CD WMT_PIN(6, 0)
133#define WMT_PIN_SD2DATA3 WMT_PIN(6, 1)
134#define WMT_PIN_SD2DATA0 WMT_PIN(6, 2)
135#define WMT_PIN_SD2WP WMT_PIN(6, 3)
136#define WMT_PIN_SD2DATA1 WMT_PIN(6, 4)
137#define WMT_PIN_SD2DATA2 WMT_PIN(6, 5)
138#define WMT_PIN_SD2CMD WMT_PIN(6, 6)
139#define WMT_PIN_SD2CLK WMT_PIN(6, 7)
140#define WMT_PIN_SD2PWR WMT_PIN(6, 9)
141#define WMT_PIN_SD1CLK WMT_PIN(7, 0)
142#define WMT_PIN_SD1CMD WMT_PIN(7, 1)
143#define WMT_PIN_SD1PWR WMT_PIN(7, 10)
144#define WMT_PIN_SD1WP WMT_PIN(7, 11)
145#define WMT_PIN_SD1CD WMT_PIN(7, 12)
146#define WMT_PIN_SPI0SS3 WMT_PIN(7, 24)
147#define WMT_PIN_SPI0SS2 WMT_PIN(7, 25)
148#define WMT_PIN_PWMOUT1 WMT_PIN(7, 26)
149#define WMT_PIN_PWMOUT0 WMT_PIN(7, 27)
150
151static const struct pinctrl_pin_desc wm8750_pins[] = {
152 PINCTRL_PIN(WMT_PIN_EXTGPIO0, "extgpio0"),
153 PINCTRL_PIN(WMT_PIN_EXTGPIO1, "extgpio1"),
154 PINCTRL_PIN(WMT_PIN_EXTGPIO2, "extgpio2"),
155 PINCTRL_PIN(WMT_PIN_EXTGPIO3, "extgpio3"),
156 PINCTRL_PIN(WMT_PIN_EXTGPIO4, "extgpio4"),
157 PINCTRL_PIN(WMT_PIN_EXTGPIO5, "extgpio5"),
158 PINCTRL_PIN(WMT_PIN_EXTGPIO6, "extgpio6"),
159 PINCTRL_PIN(WMT_PIN_EXTGPIO7, "extgpio7"),
160 PINCTRL_PIN(WMT_PIN_WAKEUP0, "wakeup0"),
161 PINCTRL_PIN(WMT_PIN_WAKEUP1, "wakeup1"),
162 PINCTRL_PIN(WMT_PIN_SD0CD, "sd0_cd"),
163 PINCTRL_PIN(WMT_PIN_VDOUT0, "vdout0"),
164 PINCTRL_PIN(WMT_PIN_VDOUT1, "vdout1"),
165 PINCTRL_PIN(WMT_PIN_VDOUT2, "vdout2"),
166 PINCTRL_PIN(WMT_PIN_VDOUT3, "vdout3"),
167 PINCTRL_PIN(WMT_PIN_VDOUT4, "vdout4"),
168 PINCTRL_PIN(WMT_PIN_VDOUT5, "vdout5"),
169 PINCTRL_PIN(WMT_PIN_VDOUT6, "vdout6"),
170 PINCTRL_PIN(WMT_PIN_VDOUT7, "vdout7"),
171 PINCTRL_PIN(WMT_PIN_VDOUT8, "vdout8"),
172 PINCTRL_PIN(WMT_PIN_VDOUT9, "vdout9"),
173 PINCTRL_PIN(WMT_PIN_VDOUT10, "vdout10"),
174 PINCTRL_PIN(WMT_PIN_VDOUT11, "vdout11"),
175 PINCTRL_PIN(WMT_PIN_VDOUT12, "vdout12"),
176 PINCTRL_PIN(WMT_PIN_VDOUT13, "vdout13"),
177 PINCTRL_PIN(WMT_PIN_VDOUT14, "vdout14"),
178 PINCTRL_PIN(WMT_PIN_VDOUT15, "vdout15"),
179 PINCTRL_PIN(WMT_PIN_VDOUT16, "vdout16"),
180 PINCTRL_PIN(WMT_PIN_VDOUT17, "vdout17"),
181 PINCTRL_PIN(WMT_PIN_VDOUT18, "vdout18"),
182 PINCTRL_PIN(WMT_PIN_VDOUT19, "vdout19"),
183 PINCTRL_PIN(WMT_PIN_VDOUT20, "vdout20"),
184 PINCTRL_PIN(WMT_PIN_VDOUT21, "vdout21"),
185 PINCTRL_PIN(WMT_PIN_VDOUT22, "vdout22"),
186 PINCTRL_PIN(WMT_PIN_VDOUT23, "vdout23"),
187 PINCTRL_PIN(WMT_PIN_VDIN0, "vdin0"),
188 PINCTRL_PIN(WMT_PIN_VDIN1, "vdin1"),
189 PINCTRL_PIN(WMT_PIN_VDIN2, "vdin2"),
190 PINCTRL_PIN(WMT_PIN_VDIN3, "vdin3"),
191 PINCTRL_PIN(WMT_PIN_VDIN4, "vdin4"),
192 PINCTRL_PIN(WMT_PIN_VDIN5, "vdin5"),
193 PINCTRL_PIN(WMT_PIN_VDIN6, "vdin6"),
194 PINCTRL_PIN(WMT_PIN_VDIN7, "vdin7"),
195 PINCTRL_PIN(WMT_PIN_SPI0_MOSI, "spi0_mosi"),
196 PINCTRL_PIN(WMT_PIN_SPI0_MISO, "spi0_miso"),
197 PINCTRL_PIN(WMT_PIN_SPI0_SS, "spi0_ss"),
198 PINCTRL_PIN(WMT_PIN_SPI0_CLK, "spi0_clk"),
199 PINCTRL_PIN(WMT_PIN_SPI0_SSB, "spi0_ssb"),
200 PINCTRL_PIN(WMT_PIN_SD0CLK, "sd0_clk"),
201 PINCTRL_PIN(WMT_PIN_SD0CMD, "sd0_cmd"),
202 PINCTRL_PIN(WMT_PIN_SD0WP, "sd0_wp"),
203 PINCTRL_PIN(WMT_PIN_SD0DATA0, "sd0_data0"),
204 PINCTRL_PIN(WMT_PIN_SD0DATA1, "sd0_data1"),
205 PINCTRL_PIN(WMT_PIN_SD0DATA2, "sd0_data2"),
206 PINCTRL_PIN(WMT_PIN_SD0DATA3, "sd0_data3"),
207 PINCTRL_PIN(WMT_PIN_SD1DATA0, "sd1_data0"),
208 PINCTRL_PIN(WMT_PIN_SD1DATA1, "sd1_data1"),
209 PINCTRL_PIN(WMT_PIN_SD1DATA2, "sd1_data2"),
210 PINCTRL_PIN(WMT_PIN_SD1DATA3, "sd1_data3"),
211 PINCTRL_PIN(WMT_PIN_SD1DATA4, "sd1_data4"),
212 PINCTRL_PIN(WMT_PIN_SD1DATA5, "sd1_data5"),
213 PINCTRL_PIN(WMT_PIN_SD1DATA6, "sd1_data6"),
214 PINCTRL_PIN(WMT_PIN_SD1DATA7, "sd1_data7"),
215 PINCTRL_PIN(WMT_PIN_I2C0_SCL, "i2c0_scl"),
216 PINCTRL_PIN(WMT_PIN_I2C0_SDA, "i2c0_sda"),
217 PINCTRL_PIN(WMT_PIN_I2C1_SCL, "i2c1_scl"),
218 PINCTRL_PIN(WMT_PIN_I2C1_SDA, "i2c1_sda"),
219 PINCTRL_PIN(WMT_PIN_I2C2_SCL, "i2c2_scl"),
220 PINCTRL_PIN(WMT_PIN_I2C2_SDA, "i2c2_sda"),
221 PINCTRL_PIN(WMT_PIN_UART0_RTS, "uart0_rts"),
222 PINCTRL_PIN(WMT_PIN_UART0_TXD, "uart0_txd"),
223 PINCTRL_PIN(WMT_PIN_UART0_CTS, "uart0_cts"),
224 PINCTRL_PIN(WMT_PIN_UART0_RXD, "uart0_rxd"),
225 PINCTRL_PIN(WMT_PIN_UART1_RTS, "uart1_rts"),
226 PINCTRL_PIN(WMT_PIN_UART1_TXD, "uart1_txd"),
227 PINCTRL_PIN(WMT_PIN_UART1_CTS, "uart1_cts"),
228 PINCTRL_PIN(WMT_PIN_UART1_RXD, "uart1_rxd"),
229 PINCTRL_PIN(WMT_PIN_UART2_RTS, "uart2_rts"),
230 PINCTRL_PIN(WMT_PIN_UART2_TXD, "uart2_txd"),
231 PINCTRL_PIN(WMT_PIN_UART2_CTS, "uart2_cts"),
232 PINCTRL_PIN(WMT_PIN_UART2_RXD, "uart2_rxd"),
233 PINCTRL_PIN(WMT_PIN_UART3_RTS, "uart3_rts"),
234 PINCTRL_PIN(WMT_PIN_UART3_TXD, "uart3_txd"),
235 PINCTRL_PIN(WMT_PIN_UART3_CTS, "uart3_cts"),
236 PINCTRL_PIN(WMT_PIN_UART3_RXD, "uart3_rxd"),
237 PINCTRL_PIN(WMT_PIN_SD2CD, "sd2_cd"),
238 PINCTRL_PIN(WMT_PIN_SD2DATA3, "sd2_data3"),
239 PINCTRL_PIN(WMT_PIN_SD2DATA0, "sd2_data0"),
240 PINCTRL_PIN(WMT_PIN_SD2WP, "sd2_wp"),
241 PINCTRL_PIN(WMT_PIN_SD2DATA1, "sd2_data1"),
242 PINCTRL_PIN(WMT_PIN_SD2DATA2, "sd2_data2"),
243 PINCTRL_PIN(WMT_PIN_SD2CMD, "sd2_cmd"),
244 PINCTRL_PIN(WMT_PIN_SD2CLK, "sd2_clk"),
245 PINCTRL_PIN(WMT_PIN_SD2PWR, "sd2_pwr"),
246 PINCTRL_PIN(WMT_PIN_SD1CLK, "sd1_clk"),
247 PINCTRL_PIN(WMT_PIN_SD1CMD, "sd1_cmd"),
248 PINCTRL_PIN(WMT_PIN_SD1PWR, "sd1_pwr"),
249 PINCTRL_PIN(WMT_PIN_SD1WP, "sd1_wp"),
250 PINCTRL_PIN(WMT_PIN_SD1CD, "sd1_cd"),
251 PINCTRL_PIN(WMT_PIN_SPI0SS3, "spi0_ss3"),
252 PINCTRL_PIN(WMT_PIN_SPI0SS2, "spi0_ss2"),
253 PINCTRL_PIN(WMT_PIN_PWMOUT1, "pwmout1"),
254 PINCTRL_PIN(WMT_PIN_PWMOUT0, "pwmout0"),
255};
256
257/* Order of these names must match the above list */
258static const char * const wm8750_groups[] = {
259 "extgpio0",
260 "extgpio1",
261 "extgpio2",
262 "extgpio3",
263 "extgpio4",
264 "extgpio5",
265 "extgpio6",
266 "extgpio7",
267 "wakeup0",
268 "wakeup1",
269 "sd0_cd",
270 "vdout0",
271 "vdout1",
272 "vdout2",
273 "vdout3",
274 "vdout4",
275 "vdout5",
276 "vdout6",
277 "vdout7",
278 "vdout8",
279 "vdout9",
280 "vdout10",
281 "vdout11",
282 "vdout12",
283 "vdout13",
284 "vdout14",
285 "vdout15",
286 "vdout16",
287 "vdout17",
288 "vdout18",
289 "vdout19",
290 "vdout20",
291 "vdout21",
292 "vdout22",
293 "vdout23",
294 "vdin0",
295 "vdin1",
296 "vdin2",
297 "vdin3",
298 "vdin4",
299 "vdin5",
300 "vdin6",
301 "vdin7",
302 "spi0_mosi",
303 "spi0_miso",
304 "spi0_ss",
305 "spi0_clk",
306 "spi0_ssb",
307 "sd0_clk",
308 "sd0_cmd",
309 "sd0_wp",
310 "sd0_data0",
311 "sd0_data1",
312 "sd0_data2",
313 "sd0_data3",
314 "sd1_data0",
315 "sd1_data1",
316 "sd1_data2",
317 "sd1_data3",
318 "sd1_data4",
319 "sd1_data5",
320 "sd1_data6",
321 "sd1_data7",
322 "i2c0_scl",
323 "i2c0_sda",
324 "i2c1_scl",
325 "i2c1_sda",
326 "i2c2_scl",
327 "i2c2_sda",
328 "uart0_rts",
329 "uart0_txd",
330 "uart0_cts",
331 "uart0_rxd",
332 "uart1_rts",
333 "uart1_txd",
334 "uart1_cts",
335 "uart1_rxd",
336 "uart2_rts",
337 "uart2_txd",
338 "uart2_cts",
339 "uart2_rxd",
340 "uart3_rts",
341 "uart3_txd",
342 "uart3_cts",
343 "uart3_rxd",
344 "sd2_cd",
345 "sd2_data3",
346 "sd2_data0",
347 "sd2_wp",
348 "sd2_data1",
349 "sd2_data2",
350 "sd2_cmd",
351 "sd2_clk",
352 "sd2_pwr",
353 "sd1_clk",
354 "sd1_cmd",
355 "sd1_pwr",
356 "sd1_wp",
357 "sd1_cd",
358 "spi0_ss3",
359 "spi0_ss2",
360 "pwmout1",
361 "pwmout0",
362};
363
364static int wm8750_pinctrl_probe(struct platform_device *pdev)
365{
366 struct wmt_pinctrl_data *data;
367
368 data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
369 if (!data) {
370 dev_err(&pdev->dev, "failed to allocate data\n");
371 return -ENOMEM;
372 }
373
374 data->banks = wm8750_banks;
375 data->nbanks = ARRAY_SIZE(wm8750_banks);
376 data->pins = wm8750_pins;
377 data->npins = ARRAY_SIZE(wm8750_pins);
378 data->groups = wm8750_groups;
379 data->ngroups = ARRAY_SIZE(wm8750_groups);
380
381 return wmt_pinctrl_probe(pdev, data);
382}
383
384static int wm8750_pinctrl_remove(struct platform_device *pdev)
385{
386 return wmt_pinctrl_remove(pdev);
387}
388
389static struct of_device_id wmt_pinctrl_of_match[] = {
390 { .compatible = "wm,wm8750-pinctrl" },
391 { /* sentinel */ },
392};
393
394static struct platform_driver wmt_pinctrl_driver = {
395 .probe = wm8750_pinctrl_probe,
396 .remove = wm8750_pinctrl_remove,
397 .driver = {
398 .name = "pinctrl-wm8750",
399 .owner = THIS_MODULE,
400 .of_match_table = wmt_pinctrl_of_match,
401 },
402};
403
404module_platform_driver(wmt_pinctrl_driver);
405
406MODULE_AUTHOR("Tony Prisk <linux@prisktech.co.nz>");
407MODULE_DESCRIPTION("Wondermedia WM8750 Pincontrol driver");
408MODULE_LICENSE("GPL v2");
409MODULE_DEVICE_TABLE(of, wmt_pinctrl_of_match);
diff --git a/drivers/pinctrl/vt8500/pinctrl-wm8850.c b/drivers/pinctrl/vt8500/pinctrl-wm8850.c
new file mode 100644
index 000000000000..ecadce9c91d5
--- /dev/null
+++ b/drivers/pinctrl/vt8500/pinctrl-wm8850.c
@@ -0,0 +1,388 @@
1/*
2 * Pinctrl data for Wondermedia WM8850 SoC
3 *
4 * Copyright (c) 2013 Tony Prisk <linux@prisktech.co.nz>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 */
15
16#include <linux/io.h>
17#include <linux/module.h>
18#include <linux/pinctrl/pinctrl.h>
19#include <linux/platform_device.h>
20#include <linux/slab.h>
21
22#include "pinctrl-wmt.h"
23
24/*
25 * Describe the register offsets within the GPIO memory space
26 * The dedicated external GPIO's should always be listed in bank 0
27 * so they are exported in the 0..31 range which is what users
28 * expect.
29 *
30 * Do not reorder these banks as it will change the pin numbering
31 */
32static const struct wmt_pinctrl_bank_registers wm8850_banks[] = {
33 WMT_PINCTRL_BANK(0x40, 0x80, 0xC0, 0x00, 0x480, 0x4C0), /* 0 */
34 WMT_PINCTRL_BANK(0x44, 0x84, 0xC4, 0x04, 0x484, 0x4C4), /* 1 */
35 WMT_PINCTRL_BANK(0x48, 0x88, 0xC8, 0x08, 0x488, 0x4C8), /* 2 */
36 WMT_PINCTRL_BANK(0x4C, 0x8C, 0xCC, 0x0C, 0x48C, 0x4CC), /* 3 */
37 WMT_PINCTRL_BANK(0x50, 0x90, 0xD0, 0x10, 0x490, 0x4D0), /* 4 */
38 WMT_PINCTRL_BANK(0x54, 0x94, 0xD4, 0x14, 0x494, 0x4D4), /* 5 */
39 WMT_PINCTRL_BANK(0x58, 0x98, 0xD8, 0x18, 0x498, 0x4D8), /* 6 */
40 WMT_PINCTRL_BANK(0x5C, 0x9C, 0xDC, 0x1C, 0x49C, 0x4DC), /* 7 */
41 WMT_PINCTRL_BANK(0x60, 0xA0, 0xE0, 0x20, 0x4A0, 0x4E0), /* 8 */
42 WMT_PINCTRL_BANK(0x70, 0xB0, 0xF0, 0x30, 0x4B0, 0x4F0), /* 9 */
43 WMT_PINCTRL_BANK(0x7C, 0xBC, 0xDC, 0x3C, 0x4BC, 0x4FC), /* 10 */
44};
45
46/* Please keep sorted by bank/bit */
47#define WMT_PIN_EXTGPIO0 WMT_PIN(0, 0)
48#define WMT_PIN_EXTGPIO1 WMT_PIN(0, 1)
49#define WMT_PIN_EXTGPIO2 WMT_PIN(0, 2)
50#define WMT_PIN_EXTGPIO3 WMT_PIN(0, 3)
51#define WMT_PIN_EXTGPIO4 WMT_PIN(0, 4)
52#define WMT_PIN_EXTGPIO5 WMT_PIN(0, 5)
53#define WMT_PIN_EXTGPIO6 WMT_PIN(0, 6)
54#define WMT_PIN_EXTGPIO7 WMT_PIN(0, 7)
55#define WMT_PIN_WAKEUP0 WMT_PIN(0, 16)
56#define WMT_PIN_WAKEUP1 WMT_PIN(0, 17)
57#define WMT_PIN_WAKEUP2 WMT_PIN(0, 18)
58#define WMT_PIN_WAKEUP3 WMT_PIN(0, 19)
59#define WMT_PIN_SUSGPIO0 WMT_PIN(0, 21)
60#define WMT_PIN_SUSGPIO1 WMT_PIN(0, 22)
61#define WMT_PIN_SD0CD WMT_PIN(0, 28)
62#define WMT_PIN_VDOUT0 WMT_PIN(1, 0)
63#define WMT_PIN_VDOUT1 WMT_PIN(1, 1)
64#define WMT_PIN_VDOUT2 WMT_PIN(1, 2)
65#define WMT_PIN_VDOUT3 WMT_PIN(1, 3)
66#define WMT_PIN_VDOUT4 WMT_PIN(1, 4)
67#define WMT_PIN_VDOUT5 WMT_PIN(1, 5)
68#define WMT_PIN_VDOUT6 WMT_PIN(1, 6)
69#define WMT_PIN_VDOUT7 WMT_PIN(1, 7)
70#define WMT_PIN_VDOUT8 WMT_PIN(1, 8)
71#define WMT_PIN_VDOUT9 WMT_PIN(1, 9)
72#define WMT_PIN_VDOUT10 WMT_PIN(1, 10)
73#define WMT_PIN_VDOUT11 WMT_PIN(1, 11)
74#define WMT_PIN_VDOUT12 WMT_PIN(1, 12)
75#define WMT_PIN_VDOUT13 WMT_PIN(1, 13)
76#define WMT_PIN_VDOUT14 WMT_PIN(1, 14)
77#define WMT_PIN_VDOUT15 WMT_PIN(1, 15)
78#define WMT_PIN_VDOUT16 WMT_PIN(1, 16)
79#define WMT_PIN_VDOUT17 WMT_PIN(1, 17)
80#define WMT_PIN_VDOUT18 WMT_PIN(1, 18)
81#define WMT_PIN_VDOUT19 WMT_PIN(1, 19)
82#define WMT_PIN_VDOUT20 WMT_PIN(1, 20)
83#define WMT_PIN_VDOUT21 WMT_PIN(1, 21)
84#define WMT_PIN_VDOUT22 WMT_PIN(1, 22)
85#define WMT_PIN_VDOUT23 WMT_PIN(1, 23)
86#define WMT_PIN_VDIN0 WMT_PIN(2, 0)
87#define WMT_PIN_VDIN1 WMT_PIN(2, 1)
88#define WMT_PIN_VDIN2 WMT_PIN(2, 2)
89#define WMT_PIN_VDIN3 WMT_PIN(2, 3)
90#define WMT_PIN_VDIN4 WMT_PIN(2, 4)
91#define WMT_PIN_VDIN5 WMT_PIN(2, 5)
92#define WMT_PIN_VDIN6 WMT_PIN(2, 6)
93#define WMT_PIN_VDIN7 WMT_PIN(2, 7)
94#define WMT_PIN_SPI0_MOSI WMT_PIN(2, 24)
95#define WMT_PIN_SPI0_MISO WMT_PIN(2, 25)
96#define WMT_PIN_SPI0_SS WMT_PIN(2, 26)
97#define WMT_PIN_SPI0_CLK WMT_PIN(2, 27)
98#define WMT_PIN_SPI0_SSB WMT_PIN(2, 28)
99#define WMT_PIN_SD0CLK WMT_PIN(3, 17)
100#define WMT_PIN_SD0CMD WMT_PIN(3, 18)
101#define WMT_PIN_SD0WP WMT_PIN(3, 19)
102#define WMT_PIN_SD0DATA0 WMT_PIN(3, 20)
103#define WMT_PIN_SD0DATA1 WMT_PIN(3, 21)
104#define WMT_PIN_SD0DATA2 WMT_PIN(3, 22)
105#define WMT_PIN_SD0DATA3 WMT_PIN(3, 23)
106#define WMT_PIN_SD1DATA0 WMT_PIN(3, 24)
107#define WMT_PIN_SD1DATA1 WMT_PIN(3, 25)
108#define WMT_PIN_SD1DATA2 WMT_PIN(3, 26)
109#define WMT_PIN_SD1DATA3 WMT_PIN(3, 27)
110#define WMT_PIN_SD1DATA4 WMT_PIN(3, 28)
111#define WMT_PIN_SD1DATA5 WMT_PIN(3, 29)
112#define WMT_PIN_SD1DATA6 WMT_PIN(3, 30)
113#define WMT_PIN_SD1DATA7 WMT_PIN(3, 31)
114#define WMT_PIN_I2C0_SCL WMT_PIN(5, 8)
115#define WMT_PIN_I2C0_SDA WMT_PIN(5, 9)
116#define WMT_PIN_I2C1_SCL WMT_PIN(5, 10)
117#define WMT_PIN_I2C1_SDA WMT_PIN(5, 11)
118#define WMT_PIN_I2C2_SCL WMT_PIN(5, 12)
119#define WMT_PIN_I2C2_SDA WMT_PIN(5, 13)
120#define WMT_PIN_UART0_RTS WMT_PIN(5, 16)
121#define WMT_PIN_UART0_TXD WMT_PIN(5, 17)
122#define WMT_PIN_UART0_CTS WMT_PIN(5, 18)
123#define WMT_PIN_UART0_RXD WMT_PIN(5, 19)
124#define WMT_PIN_UART1_RTS WMT_PIN(5, 20)
125#define WMT_PIN_UART1_TXD WMT_PIN(5, 21)
126#define WMT_PIN_UART1_CTS WMT_PIN(5, 22)
127#define WMT_PIN_UART1_RXD WMT_PIN(5, 23)
128#define WMT_PIN_UART2_RTS WMT_PIN(5, 24)
129#define WMT_PIN_UART2_TXD WMT_PIN(5, 25)
130#define WMT_PIN_UART2_CTS WMT_PIN(5, 26)
131#define WMT_PIN_UART2_RXD WMT_PIN(5, 27)
132#define WMT_PIN_SD2WP WMT_PIN(6, 3)
133#define WMT_PIN_SD2CMD WMT_PIN(6, 6)
134#define WMT_PIN_SD2CLK WMT_PIN(6, 7)
135#define WMT_PIN_SD2PWR WMT_PIN(6, 9)
136#define WMT_PIN_SD1CLK WMT_PIN(7, 0)
137#define WMT_PIN_SD1CMD WMT_PIN(7, 1)
138#define WMT_PIN_SD1PWR WMT_PIN(7, 10)
139#define WMT_PIN_SD1WP WMT_PIN(7, 11)
140#define WMT_PIN_SD1CD WMT_PIN(7, 12)
141#define WMT_PIN_PWMOUT1 WMT_PIN(7, 26)
142#define WMT_PIN_PWMOUT0 WMT_PIN(7, 27)
143
144static const struct pinctrl_pin_desc wm8850_pins[] = {
145 PINCTRL_PIN(WMT_PIN_EXTGPIO0, "extgpio0"),
146 PINCTRL_PIN(WMT_PIN_EXTGPIO1, "extgpio1"),
147 PINCTRL_PIN(WMT_PIN_EXTGPIO2, "extgpio2"),
148 PINCTRL_PIN(WMT_PIN_EXTGPIO3, "extgpio3"),
149 PINCTRL_PIN(WMT_PIN_EXTGPIO4, "extgpio4"),
150 PINCTRL_PIN(WMT_PIN_EXTGPIO5, "extgpio5"),
151 PINCTRL_PIN(WMT_PIN_EXTGPIO6, "extgpio6"),
152 PINCTRL_PIN(WMT_PIN_EXTGPIO7, "extgpio7"),
153 PINCTRL_PIN(WMT_PIN_WAKEUP0, "wakeup0"),
154 PINCTRL_PIN(WMT_PIN_WAKEUP1, "wakeup1"),
155 PINCTRL_PIN(WMT_PIN_WAKEUP2, "wakeup2"),
156 PINCTRL_PIN(WMT_PIN_WAKEUP3, "wakeup3"),
157 PINCTRL_PIN(WMT_PIN_SUSGPIO0, "susgpio0"),
158 PINCTRL_PIN(WMT_PIN_SUSGPIO1, "susgpio1"),
159 PINCTRL_PIN(WMT_PIN_SD0CD, "sd0_cd"),
160 PINCTRL_PIN(WMT_PIN_VDOUT0, "vdout0"),
161 PINCTRL_PIN(WMT_PIN_VDOUT1, "vdout1"),
162 PINCTRL_PIN(WMT_PIN_VDOUT2, "vdout2"),
163 PINCTRL_PIN(WMT_PIN_VDOUT3, "vdout3"),
164 PINCTRL_PIN(WMT_PIN_VDOUT4, "vdout4"),
165 PINCTRL_PIN(WMT_PIN_VDOUT5, "vdout5"),
166 PINCTRL_PIN(WMT_PIN_VDOUT6, "vdout6"),
167 PINCTRL_PIN(WMT_PIN_VDOUT7, "vdout7"),
168 PINCTRL_PIN(WMT_PIN_VDOUT8, "vdout8"),
169 PINCTRL_PIN(WMT_PIN_VDOUT9, "vdout9"),
170 PINCTRL_PIN(WMT_PIN_VDOUT10, "vdout10"),
171 PINCTRL_PIN(WMT_PIN_VDOUT11, "vdout11"),
172 PINCTRL_PIN(WMT_PIN_VDOUT12, "vdout12"),
173 PINCTRL_PIN(WMT_PIN_VDOUT13, "vdout13"),
174 PINCTRL_PIN(WMT_PIN_VDOUT14, "vdout14"),
175 PINCTRL_PIN(WMT_PIN_VDOUT15, "vdout15"),
176 PINCTRL_PIN(WMT_PIN_VDOUT16, "vdout16"),
177 PINCTRL_PIN(WMT_PIN_VDOUT17, "vdout17"),
178 PINCTRL_PIN(WMT_PIN_VDOUT18, "vdout18"),
179 PINCTRL_PIN(WMT_PIN_VDOUT19, "vdout19"),
180 PINCTRL_PIN(WMT_PIN_VDOUT20, "vdout20"),
181 PINCTRL_PIN(WMT_PIN_VDOUT21, "vdout21"),
182 PINCTRL_PIN(WMT_PIN_VDOUT22, "vdout22"),
183 PINCTRL_PIN(WMT_PIN_VDOUT23, "vdout23"),
184 PINCTRL_PIN(WMT_PIN_VDIN0, "vdin0"),
185 PINCTRL_PIN(WMT_PIN_VDIN1, "vdin1"),
186 PINCTRL_PIN(WMT_PIN_VDIN2, "vdin2"),
187 PINCTRL_PIN(WMT_PIN_VDIN3, "vdin3"),
188 PINCTRL_PIN(WMT_PIN_VDIN4, "vdin4"),
189 PINCTRL_PIN(WMT_PIN_VDIN5, "vdin5"),
190 PINCTRL_PIN(WMT_PIN_VDIN6, "vdin6"),
191 PINCTRL_PIN(WMT_PIN_VDIN7, "vdin7"),
192 PINCTRL_PIN(WMT_PIN_SPI0_MOSI, "spi0_mosi"),
193 PINCTRL_PIN(WMT_PIN_SPI0_MISO, "spi0_miso"),
194 PINCTRL_PIN(WMT_PIN_SPI0_SS, "spi0_ss"),
195 PINCTRL_PIN(WMT_PIN_SPI0_CLK, "spi0_clk"),
196 PINCTRL_PIN(WMT_PIN_SPI0_SSB, "spi0_ssb"),
197 PINCTRL_PIN(WMT_PIN_SD0CLK, "sd0_clk"),
198 PINCTRL_PIN(WMT_PIN_SD0CMD, "sd0_cmd"),
199 PINCTRL_PIN(WMT_PIN_SD0WP, "sd0_wp"),
200 PINCTRL_PIN(WMT_PIN_SD0DATA0, "sd0_data0"),
201 PINCTRL_PIN(WMT_PIN_SD0DATA1, "sd0_data1"),
202 PINCTRL_PIN(WMT_PIN_SD0DATA2, "sd0_data2"),
203 PINCTRL_PIN(WMT_PIN_SD0DATA3, "sd0_data3"),
204 PINCTRL_PIN(WMT_PIN_SD1DATA0, "sd1_data0"),
205 PINCTRL_PIN(WMT_PIN_SD1DATA1, "sd1_data1"),
206 PINCTRL_PIN(WMT_PIN_SD1DATA2, "sd1_data2"),
207 PINCTRL_PIN(WMT_PIN_SD1DATA3, "sd1_data3"),
208 PINCTRL_PIN(WMT_PIN_SD1DATA4, "sd1_data4"),
209 PINCTRL_PIN(WMT_PIN_SD1DATA5, "sd1_data5"),
210 PINCTRL_PIN(WMT_PIN_SD1DATA6, "sd1_data6"),
211 PINCTRL_PIN(WMT_PIN_SD1DATA7, "sd1_data7"),
212 PINCTRL_PIN(WMT_PIN_I2C0_SCL, "i2c0_scl"),
213 PINCTRL_PIN(WMT_PIN_I2C0_SDA, "i2c0_sda"),
214 PINCTRL_PIN(WMT_PIN_I2C1_SCL, "i2c1_scl"),
215 PINCTRL_PIN(WMT_PIN_I2C1_SDA, "i2c1_sda"),
216 PINCTRL_PIN(WMT_PIN_I2C2_SCL, "i2c2_scl"),
217 PINCTRL_PIN(WMT_PIN_I2C2_SDA, "i2c2_sda"),
218 PINCTRL_PIN(WMT_PIN_UART0_RTS, "uart0_rts"),
219 PINCTRL_PIN(WMT_PIN_UART0_TXD, "uart0_txd"),
220 PINCTRL_PIN(WMT_PIN_UART0_CTS, "uart0_cts"),
221 PINCTRL_PIN(WMT_PIN_UART0_RXD, "uart0_rxd"),
222 PINCTRL_PIN(WMT_PIN_UART1_RTS, "uart1_rts"),
223 PINCTRL_PIN(WMT_PIN_UART1_TXD, "uart1_txd"),
224 PINCTRL_PIN(WMT_PIN_UART1_CTS, "uart1_cts"),
225 PINCTRL_PIN(WMT_PIN_UART1_RXD, "uart1_rxd"),
226 PINCTRL_PIN(WMT_PIN_UART2_RTS, "uart2_rts"),
227 PINCTRL_PIN(WMT_PIN_UART2_TXD, "uart2_txd"),
228 PINCTRL_PIN(WMT_PIN_UART2_CTS, "uart2_cts"),
229 PINCTRL_PIN(WMT_PIN_UART2_RXD, "uart2_rxd"),
230 PINCTRL_PIN(WMT_PIN_SD2WP, "sd2_wp"),
231 PINCTRL_PIN(WMT_PIN_SD2CMD, "sd2_cmd"),
232 PINCTRL_PIN(WMT_PIN_SD2CLK, "sd2_clk"),
233 PINCTRL_PIN(WMT_PIN_SD2PWR, "sd2_pwr"),
234 PINCTRL_PIN(WMT_PIN_SD1CLK, "sd1_clk"),
235 PINCTRL_PIN(WMT_PIN_SD1CMD, "sd1_cmd"),
236 PINCTRL_PIN(WMT_PIN_SD1PWR, "sd1_pwr"),
237 PINCTRL_PIN(WMT_PIN_SD1WP, "sd1_wp"),
238 PINCTRL_PIN(WMT_PIN_SD1CD, "sd1_cd"),
239 PINCTRL_PIN(WMT_PIN_PWMOUT1, "pwmout1"),
240 PINCTRL_PIN(WMT_PIN_PWMOUT0, "pwmout0"),
241};
242
243/* Order of these names must match the above list */
244static const char * const wm8850_groups[] = {
245 "extgpio0",
246 "extgpio1",
247 "extgpio2",
248 "extgpio3",
249 "extgpio4",
250 "extgpio5",
251 "extgpio6",
252 "extgpio7",
253 "wakeup0",
254 "wakeup1",
255 "wakeup2",
256 "wakeup3",
257 "susgpio0",
258 "susgpio1",
259 "sd0_cd",
260 "vdout0",
261 "vdout1",
262 "vdout2",
263 "vdout3",
264 "vdout4",
265 "vdout5",
266 "vdout6",
267 "vdout7",
268 "vdout8",
269 "vdout9",
270 "vdout10",
271 "vdout11",
272 "vdout12",
273 "vdout13",
274 "vdout14",
275 "vdout15",
276 "vdout16",
277 "vdout17",
278 "vdout18",
279 "vdout19",
280 "vdout20",
281 "vdout21",
282 "vdout22",
283 "vdout23",
284 "vdin0",
285 "vdin1",
286 "vdin2",
287 "vdin3",
288 "vdin4",
289 "vdin5",
290 "vdin6",
291 "vdin7",
292 "spi0_mosi",
293 "spi0_miso",
294 "spi0_ss",
295 "spi0_clk",
296 "spi0_ssb",
297 "sd0_clk",
298 "sd0_cmd",
299 "sd0_wp",
300 "sd0_data0",
301 "sd0_data1",
302 "sd0_data2",
303 "sd0_data3",
304 "sd1_data0",
305 "sd1_data1",
306 "sd1_data2",
307 "sd1_data3",
308 "sd1_data4",
309 "sd1_data5",
310 "sd1_data6",
311 "sd1_data7",
312 "i2c0_scl",
313 "i2c0_sda",
314 "i2c1_scl",
315 "i2c1_sda",
316 "i2c2_scl",
317 "i2c2_sda",
318 "uart0_rts",
319 "uart0_txd",
320 "uart0_cts",
321 "uart0_rxd",
322 "uart1_rts",
323 "uart1_txd",
324 "uart1_cts",
325 "uart1_rxd",
326 "uart2_rts",
327 "uart2_txd",
328 "uart2_cts",
329 "uart2_rxd",
330 "sd2_wp",
331 "sd2_cmd",
332 "sd2_clk",
333 "sd2_pwr",
334 "sd1_clk",
335 "sd1_cmd",
336 "sd1_pwr",
337 "sd1_wp",
338 "sd1_cd",
339 "pwmout1",
340 "pwmout0",
341};
342
343static int wm8850_pinctrl_probe(struct platform_device *pdev)
344{
345 struct wmt_pinctrl_data *data;
346
347 data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
348 if (!data) {
349 dev_err(&pdev->dev, "failed to allocate data\n");
350 return -ENOMEM;
351 }
352
353 data->banks = wm8850_banks;
354 data->nbanks = ARRAY_SIZE(wm8850_banks);
355 data->pins = wm8850_pins;
356 data->npins = ARRAY_SIZE(wm8850_pins);
357 data->groups = wm8850_groups;
358 data->ngroups = ARRAY_SIZE(wm8850_groups);
359
360 return wmt_pinctrl_probe(pdev, data);
361}
362
363static int wm8850_pinctrl_remove(struct platform_device *pdev)
364{
365 return wmt_pinctrl_remove(pdev);
366}
367
368static struct of_device_id wmt_pinctrl_of_match[] = {
369 { .compatible = "wm,wm8850-pinctrl" },
370 { /* sentinel */ },
371};
372
373static struct platform_driver wmt_pinctrl_driver = {
374 .probe = wm8850_pinctrl_probe,
375 .remove = wm8850_pinctrl_remove,
376 .driver = {
377 .name = "pinctrl-wm8850",
378 .owner = THIS_MODULE,
379 .of_match_table = wmt_pinctrl_of_match,
380 },
381};
382
383module_platform_driver(wmt_pinctrl_driver);
384
385MODULE_AUTHOR("Tony Prisk <linux@prisktech.co.nz>");
386MODULE_DESCRIPTION("Wondermedia WM8850 Pincontrol driver");
387MODULE_LICENSE("GPL v2");
388MODULE_DEVICE_TABLE(of, wmt_pinctrl_of_match);
diff --git a/drivers/pinctrl/vt8500/pinctrl-wmt.c b/drivers/pinctrl/vt8500/pinctrl-wmt.c
new file mode 100644
index 000000000000..14400a7974bd
--- /dev/null
+++ b/drivers/pinctrl/vt8500/pinctrl-wmt.c
@@ -0,0 +1,632 @@
1/*
2 * Pinctrl driver for the Wondermedia SoC's
3 *
4 * Copyright (c) 2013 Tony Prisk <linux@prisktech.co.nz>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 */
15
16#include <linux/err.h>
17#include <linux/gpio.h>
18#include <linux/interrupt.h>
19#include <linux/io.h>
20#include <linux/irq.h>
21#include <linux/module.h>
22#include <linux/of.h>
23#include <linux/of_irq.h>
24#include <linux/pinctrl/consumer.h>
25#include <linux/pinctrl/machine.h>
26#include <linux/pinctrl/pinconf.h>
27#include <linux/pinctrl/pinconf-generic.h>
28#include <linux/pinctrl/pinctrl.h>
29#include <linux/pinctrl/pinmux.h>
30#include <linux/platform_device.h>
31#include <linux/slab.h>
32
33#include "pinctrl-wmt.h"
34
35static inline void wmt_setbits(struct wmt_pinctrl_data *data, u32 reg,
36 u32 mask)
37{
38 u32 val;
39
40 val = readl_relaxed(data->base + reg);
41 val |= mask;
42 writel_relaxed(val, data->base + reg);
43}
44
45static inline void wmt_clearbits(struct wmt_pinctrl_data *data, u32 reg,
46 u32 mask)
47{
48 u32 val;
49
50 val = readl_relaxed(data->base + reg);
51 val &= ~mask;
52 writel_relaxed(val, data->base + reg);
53}
54
55enum wmt_func_sel {
56 WMT_FSEL_GPIO_IN = 0,
57 WMT_FSEL_GPIO_OUT = 1,
58 WMT_FSEL_ALT = 2,
59 WMT_FSEL_COUNT = 3,
60};
61
62static const char * const wmt_functions[WMT_FSEL_COUNT] = {
63 [WMT_FSEL_GPIO_IN] = "gpio_in",
64 [WMT_FSEL_GPIO_OUT] = "gpio_out",
65 [WMT_FSEL_ALT] = "alt",
66};
67
68static int wmt_pmx_get_functions_count(struct pinctrl_dev *pctldev)
69{
70 return WMT_FSEL_COUNT;
71}
72
73static const char *wmt_pmx_get_function_name(struct pinctrl_dev *pctldev,
74 unsigned selector)
75{
76 return wmt_functions[selector];
77}
78
79static int wmt_pmx_get_function_groups(struct pinctrl_dev *pctldev,
80 unsigned selector,
81 const char * const **groups,
82 unsigned * const num_groups)
83{
84 struct wmt_pinctrl_data *data = pinctrl_dev_get_drvdata(pctldev);
85
86 /* every pin does every function */
87 *groups = data->groups;
88 *num_groups = data->ngroups;
89
90 return 0;
91}
92
93static int wmt_set_pinmux(struct wmt_pinctrl_data *data, unsigned func,
94 unsigned pin)
95{
96 u32 bank = WMT_BANK_FROM_PIN(pin);
97 u32 bit = WMT_BIT_FROM_PIN(pin);
98 u32 reg_en = data->banks[bank].reg_en;
99 u32 reg_dir = data->banks[bank].reg_dir;
100
101 if (reg_dir == NO_REG) {
102 dev_err(data->dev, "pin:%d no direction register defined\n",
103 pin);
104 return -EINVAL;
105 }
106
107 /*
108 * If reg_en == NO_REG, we assume it is a dedicated GPIO and cannot be
109 * disabled (as on VT8500) and that no alternate function is available.
110 */
111 switch (func) {
112 case WMT_FSEL_GPIO_IN:
113 if (reg_en != NO_REG)
114 wmt_setbits(data, reg_en, BIT(bit));
115 wmt_clearbits(data, reg_dir, BIT(bit));
116 break;
117 case WMT_FSEL_GPIO_OUT:
118 if (reg_en != NO_REG)
119 wmt_setbits(data, reg_en, BIT(bit));
120 wmt_setbits(data, reg_dir, BIT(bit));
121 break;
122 case WMT_FSEL_ALT:
123 if (reg_en == NO_REG) {
124 dev_err(data->dev, "pin:%d no alt function available\n",
125 pin);
126 return -EINVAL;
127 }
128 wmt_clearbits(data, reg_en, BIT(bit));
129 }
130
131 return 0;
132}
133
134static int wmt_pmx_enable(struct pinctrl_dev *pctldev,
135 unsigned func_selector,
136 unsigned group_selector)
137{
138 struct wmt_pinctrl_data *data = pinctrl_dev_get_drvdata(pctldev);
139 u32 pinnum = data->pins[group_selector].number;
140
141 return wmt_set_pinmux(data, func_selector, pinnum);
142}
143
144static void wmt_pmx_disable(struct pinctrl_dev *pctldev,
145 unsigned func_selector,
146 unsigned group_selector)
147{
148 struct wmt_pinctrl_data *data = pinctrl_dev_get_drvdata(pctldev);
149 u32 pinnum = data->pins[group_selector].number;
150
151 /* disable by setting GPIO_IN */
152 wmt_set_pinmux(data, WMT_FSEL_GPIO_IN, pinnum);
153}
154
155static void wmt_pmx_gpio_disable_free(struct pinctrl_dev *pctldev,
156 struct pinctrl_gpio_range *range,
157 unsigned offset)
158{
159 struct wmt_pinctrl_data *data = pinctrl_dev_get_drvdata(pctldev);
160
161 /* disable by setting GPIO_IN */
162 wmt_set_pinmux(data, WMT_FSEL_GPIO_IN, offset);
163}
164
165static int wmt_pmx_gpio_set_direction(struct pinctrl_dev *pctldev,
166 struct pinctrl_gpio_range *range,
167 unsigned offset,
168 bool input)
169{
170 struct wmt_pinctrl_data *data = pinctrl_dev_get_drvdata(pctldev);
171
172 wmt_set_pinmux(data, (input ? WMT_FSEL_GPIO_IN : WMT_FSEL_GPIO_OUT),
173 offset);
174
175 return 0;
176}
177
178static struct pinmux_ops wmt_pinmux_ops = {
179 .get_functions_count = wmt_pmx_get_functions_count,
180 .get_function_name = wmt_pmx_get_function_name,
181 .get_function_groups = wmt_pmx_get_function_groups,
182 .enable = wmt_pmx_enable,
183 .disable = wmt_pmx_disable,
184 .gpio_disable_free = wmt_pmx_gpio_disable_free,
185 .gpio_set_direction = wmt_pmx_gpio_set_direction,
186};
187
188static int wmt_get_groups_count(struct pinctrl_dev *pctldev)
189{
190 struct wmt_pinctrl_data *data = pinctrl_dev_get_drvdata(pctldev);
191
192 return data->ngroups;
193}
194
195static const char *wmt_get_group_name(struct pinctrl_dev *pctldev,
196 unsigned selector)
197{
198 struct wmt_pinctrl_data *data = pinctrl_dev_get_drvdata(pctldev);
199
200 return data->groups[selector];
201}
202
203static int wmt_get_group_pins(struct pinctrl_dev *pctldev,
204 unsigned selector,
205 const unsigned **pins,
206 unsigned *num_pins)
207{
208 struct wmt_pinctrl_data *data = pinctrl_dev_get_drvdata(pctldev);
209
210 *pins = &data->pins[selector].number;
211 *num_pins = 1;
212
213 return 0;
214}
215
216static int wmt_pctl_find_group_by_pin(struct wmt_pinctrl_data *data, u32 pin)
217{
218 int i;
219
220 for (i = 0; i < data->npins; i++) {
221 if (data->pins[i].number == pin)
222 return i;
223 }
224
225 return -EINVAL;
226}
227
228static int wmt_pctl_dt_node_to_map_func(struct wmt_pinctrl_data *data,
229 struct device_node *np,
230 u32 pin, u32 fnum,
231 struct pinctrl_map **maps)
232{
233 int group;
234 struct pinctrl_map *map = *maps;
235
236 if (fnum >= ARRAY_SIZE(wmt_functions)) {
237 dev_err(data->dev, "invalid wm,function %d\n", fnum);
238 return -EINVAL;
239 }
240
241 group = wmt_pctl_find_group_by_pin(data, pin);
242 if (group < 0) {
243 dev_err(data->dev, "unable to match pin %d to group\n", pin);
244 return group;
245 }
246
247 map->type = PIN_MAP_TYPE_MUX_GROUP;
248 map->data.mux.group = data->groups[group];
249 map->data.mux.function = wmt_functions[fnum];
250 (*maps)++;
251
252 return 0;
253}
254
255static int wmt_pctl_dt_node_to_map_pull(struct wmt_pinctrl_data *data,
256 struct device_node *np,
257 u32 pin, u32 pull,
258 struct pinctrl_map **maps)
259{
260 int group;
261 unsigned long *configs;
262 struct pinctrl_map *map = *maps;
263
264 if (pull > 2) {
265 dev_err(data->dev, "invalid wm,pull %d\n", pull);
266 return -EINVAL;
267 }
268
269 group = wmt_pctl_find_group_by_pin(data, pin);
270 if (group < 0) {
271 dev_err(data->dev, "unable to match pin %d to group\n", pin);
272 return group;
273 }
274
275 configs = kzalloc(sizeof(*configs), GFP_KERNEL);
276 if (!configs)
277 return -ENOMEM;
278
279 configs[0] = pull;
280
281 map->type = PIN_MAP_TYPE_CONFIGS_PIN;
282 map->data.configs.group_or_pin = data->groups[group];
283 map->data.configs.configs = configs;
284 map->data.configs.num_configs = 1;
285 (*maps)++;
286
287 return 0;
288}
289
290static void wmt_pctl_dt_free_map(struct pinctrl_dev *pctldev,
291 struct pinctrl_map *maps,
292 unsigned num_maps)
293{
294 int i;
295
296 for (i = 0; i < num_maps; i++)
297 if (maps[i].type == PIN_MAP_TYPE_CONFIGS_PIN)
298 kfree(maps[i].data.configs.configs);
299
300 kfree(maps);
301}
302
303static int wmt_pctl_dt_node_to_map(struct pinctrl_dev *pctldev,
304 struct device_node *np,
305 struct pinctrl_map **map,
306 unsigned *num_maps)
307{
308 struct pinctrl_map *maps, *cur_map;
309 struct property *pins, *funcs, *pulls;
310 u32 pin, func, pull;
311 int num_pins, num_funcs, num_pulls, maps_per_pin;
312 int i, err;
313 struct wmt_pinctrl_data *data = pinctrl_dev_get_drvdata(pctldev);
314
315 pins = of_find_property(np, "wm,pins", NULL);
316 if (!pins) {
317 dev_err(data->dev, "missing wmt,pins property\n");
318 return -EINVAL;
319 }
320
321 funcs = of_find_property(np, "wm,function", NULL);
322 pulls = of_find_property(np, "wm,pull", NULL);
323
324 if (!funcs && !pulls) {
325 dev_err(data->dev, "neither wm,function nor wm,pull specified\n");
326 return -EINVAL;
327 }
328
329 /*
330 * The following lines calculate how many values are defined for each
331 * of the properties.
332 */
333 num_pins = pins->length / sizeof(u32);
334 num_funcs = funcs ? (funcs->length / sizeof(u32)) : 0;
335 num_pulls = pulls ? (pulls->length / sizeof(u32)) : 0;
336
337 if (num_funcs > 1 && num_funcs != num_pins) {
338 dev_err(data->dev, "wm,function must have 1 or %d entries\n",
339 num_pins);
340 return -EINVAL;
341 }
342
343 if (num_pulls > 1 && num_pulls != num_pins) {
344 dev_err(data->dev, "wm,pull must have 1 or %d entries\n",
345 num_pins);
346 return -EINVAL;
347 }
348
349 maps_per_pin = 0;
350 if (num_funcs)
351 maps_per_pin++;
352 if (num_pulls)
353 maps_per_pin++;
354
355 cur_map = maps = kzalloc(num_pins * maps_per_pin * sizeof(*maps),
356 GFP_KERNEL);
357 if (!maps)
358 return -ENOMEM;
359
360 for (i = 0; i < num_pins; i++) {
361 err = of_property_read_u32_index(np, "wm,pins", i, &pin);
362 if (err)
363 goto fail;
364
365 if (pin >= (data->nbanks * 32)) {
366 dev_err(data->dev, "invalid wm,pins value\n");
367 err = -EINVAL;
368 goto fail;
369 }
370
371 if (num_funcs) {
372 err = of_property_read_u32_index(np, "wm,function",
373 (num_funcs > 1 ? i : 0), &func);
374 if (err)
375 goto fail;
376
377 err = wmt_pctl_dt_node_to_map_func(data, np, pin, func,
378 &cur_map);
379 if (err)
380 goto fail;
381 }
382
383 if (num_pulls) {
384 err = of_property_read_u32_index(np, "wm,pull",
385 (num_pulls > 1 ? i : 0), &pull);
386 if (err)
387 goto fail;
388
389 err = wmt_pctl_dt_node_to_map_pull(data, np, pin, pull,
390 &cur_map);
391 if (err)
392 goto fail;
393 }
394 }
395 *map = maps;
396 *num_maps = num_pins * maps_per_pin;
397 return 0;
398
399/*
400 * The fail path removes any maps that have been allocated. The fail path is
401 * only called from code after maps has been kzalloc'd. It is also safe to
402 * pass 'num_pins * maps_per_pin' as the map count even though we probably
403 * failed before all the mappings were read as all maps are allocated at once,
404 * and configs are only allocated for .type = PIN_MAP_TYPE_CONFIGS_PIN - there
405 * is no failpath where a config can be allocated without .type being set.
406 */
407fail:
408 wmt_pctl_dt_free_map(pctldev, maps, num_pins * maps_per_pin);
409 return err;
410}
411
412static struct pinctrl_ops wmt_pctl_ops = {
413 .get_groups_count = wmt_get_groups_count,
414 .get_group_name = wmt_get_group_name,
415 .get_group_pins = wmt_get_group_pins,
416 .dt_node_to_map = wmt_pctl_dt_node_to_map,
417 .dt_free_map = wmt_pctl_dt_free_map,
418};
419
420static int wmt_pinconf_get(struct pinctrl_dev *pctldev, unsigned pin,
421 unsigned long *config)
422{
423 return -ENOTSUPP;
424}
425
426static int wmt_pinconf_set(struct pinctrl_dev *pctldev, unsigned pin,
427 unsigned long config)
428{
429 struct wmt_pinctrl_data *data = pinctrl_dev_get_drvdata(pctldev);
430 enum pin_config_param param = pinconf_to_config_param(config);
431 u16 arg = pinconf_to_config_argument(config);
432 u32 bank = WMT_BANK_FROM_PIN(pin);
433 u32 bit = WMT_BIT_FROM_PIN(pin);
434 u32 reg_pull_en = data->banks[bank].reg_pull_en;
435 u32 reg_pull_cfg = data->banks[bank].reg_pull_cfg;
436
437 if ((reg_pull_en == NO_REG) || (reg_pull_cfg == NO_REG)) {
438 dev_err(data->dev, "bias functions not supported on pin %d\n",
439 pin);
440 return -EINVAL;
441 }
442
443 if ((param == PIN_CONFIG_BIAS_PULL_DOWN) ||
444 (param == PIN_CONFIG_BIAS_PULL_UP)) {
445 if (arg == 0)
446 param = PIN_CONFIG_BIAS_DISABLE;
447 }
448
449 switch (param) {
450 case PIN_CONFIG_BIAS_DISABLE:
451 wmt_clearbits(data, reg_pull_en, BIT(bit));
452 break;
453 case PIN_CONFIG_BIAS_PULL_DOWN:
454 wmt_clearbits(data, reg_pull_cfg, BIT(bit));
455 wmt_setbits(data, reg_pull_en, BIT(bit));
456 break;
457 case PIN_CONFIG_BIAS_PULL_UP:
458 wmt_setbits(data, reg_pull_cfg, BIT(bit));
459 wmt_setbits(data, reg_pull_en, BIT(bit));
460 break;
461 default:
462 dev_err(data->dev, "unknown pinconf param\n");
463 return -EINVAL;
464 }
465
466 return 0;
467}
468
469static struct pinconf_ops wmt_pinconf_ops = {
470 .pin_config_get = wmt_pinconf_get,
471 .pin_config_set = wmt_pinconf_set,
472};
473
474static struct pinctrl_desc wmt_desc = {
475 .owner = THIS_MODULE,
476 .name = "pinctrl-wmt",
477 .pctlops = &wmt_pctl_ops,
478 .pmxops = &wmt_pinmux_ops,
479 .confops = &wmt_pinconf_ops,
480};
481
482static int wmt_gpio_request(struct gpio_chip *chip, unsigned offset)
483{
484 return pinctrl_request_gpio(chip->base + offset);
485}
486
487static void wmt_gpio_free(struct gpio_chip *chip, unsigned offset)
488{
489 pinctrl_free_gpio(chip->base + offset);
490}
491
492static int wmt_gpio_get_direction(struct gpio_chip *chip, unsigned offset)
493{
494 struct wmt_pinctrl_data *data = dev_get_drvdata(chip->dev);
495 u32 bank = WMT_BANK_FROM_PIN(offset);
496 u32 bit = WMT_BIT_FROM_PIN(offset);
497 u32 reg_dir = data->banks[bank].reg_dir;
498 u32 val;
499
500 val = readl_relaxed(data->base + reg_dir);
501 if (val & BIT(bit))
502 return GPIOF_DIR_OUT;
503 else
504 return GPIOF_DIR_IN;
505}
506
507static int wmt_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
508{
509 return pinctrl_gpio_direction_input(chip->base + offset);
510}
511
512static int wmt_gpio_direction_output(struct gpio_chip *chip, unsigned offset,
513 int value)
514{
515 return pinctrl_gpio_direction_output(chip->base + offset);
516}
517
518static int wmt_gpio_get_value(struct gpio_chip *chip, unsigned offset)
519{
520 struct wmt_pinctrl_data *data = dev_get_drvdata(chip->dev);
521 u32 bank = WMT_BANK_FROM_PIN(offset);
522 u32 bit = WMT_BIT_FROM_PIN(offset);
523 u32 reg_data_in = data->banks[bank].reg_data_in;
524
525 if (reg_data_in == NO_REG) {
526 dev_err(data->dev, "no data in register defined\n");
527 return -EINVAL;
528 }
529
530 return !!(readl_relaxed(data->base + reg_data_in) & BIT(bit));
531}
532
533static void wmt_gpio_set_value(struct gpio_chip *chip, unsigned offset,
534 int val)
535{
536 struct wmt_pinctrl_data *data = dev_get_drvdata(chip->dev);
537 u32 bank = WMT_BANK_FROM_PIN(offset);
538 u32 bit = WMT_BIT_FROM_PIN(offset);
539 u32 reg_data_out = data->banks[bank].reg_data_out;
540
541 if (reg_data_out == NO_REG) {
542 dev_err(data->dev, "no data out register defined\n");
543 return;
544 }
545
546 if (val)
547 wmt_setbits(data, reg_data_out, BIT(bit));
548 else
549 wmt_clearbits(data, reg_data_out, BIT(bit));
550}
551
552static struct gpio_chip wmt_gpio_chip = {
553 .label = "gpio-wmt",
554 .owner = THIS_MODULE,
555 .request = wmt_gpio_request,
556 .free = wmt_gpio_free,
557 .get_direction = wmt_gpio_get_direction,
558 .direction_input = wmt_gpio_direction_input,
559 .direction_output = wmt_gpio_direction_output,
560 .get = wmt_gpio_get_value,
561 .set = wmt_gpio_set_value,
562 .can_sleep = 0,
563};
564
565int wmt_pinctrl_probe(struct platform_device *pdev,
566 struct wmt_pinctrl_data *data)
567{
568 int err;
569 struct resource *res;
570
571 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
572 data->base = devm_request_and_ioremap(&pdev->dev, res);
573 if (!data->base) {
574 dev_err(&pdev->dev, "failed to map memory resource\n");
575 return -EBUSY;
576 }
577
578 wmt_desc.pins = data->pins;
579 wmt_desc.npins = data->npins;
580
581 data->gpio_chip = wmt_gpio_chip;
582 data->gpio_chip.dev = &pdev->dev;
583 data->gpio_chip.of_node = pdev->dev.of_node;
584 data->gpio_chip.ngpio = data->nbanks * 32;
585
586 platform_set_drvdata(pdev, data);
587
588 data->dev = &pdev->dev;
589
590 data->pctl_dev = pinctrl_register(&wmt_desc, &pdev->dev, data);
591 if (IS_ERR(data->pctl_dev)) {
592 dev_err(&pdev->dev, "Failed to register pinctrl\n");
593 return -EINVAL;
594 }
595
596 err = gpiochip_add(&data->gpio_chip);
597 if (err) {
598 dev_err(&pdev->dev, "could not add GPIO chip\n");
599 goto fail_gpio;
600 }
601
602 err = gpiochip_add_pin_range(&data->gpio_chip, dev_name(data->dev),
603 0, 0, data->nbanks * 32);
604 if (err)
605 goto fail_range;
606
607 dev_info(&pdev->dev, "Pin controller initialized\n");
608
609 return 0;
610
611fail_range:
612 err = gpiochip_remove(&data->gpio_chip);
613 if (err)
614 dev_err(&pdev->dev, "failed to remove gpio chip\n");
615fail_gpio:
616 pinctrl_unregister(data->pctl_dev);
617 return err;
618}
619
620int wmt_pinctrl_remove(struct platform_device *pdev)
621{
622 struct wmt_pinctrl_data *data = platform_get_drvdata(pdev);
623 int err;
624
625 err = gpiochip_remove(&data->gpio_chip);
626 if (err)
627 dev_err(&pdev->dev, "failed to remove gpio chip\n");
628
629 pinctrl_unregister(data->pctl_dev);
630
631 return 0;
632}
diff --git a/drivers/pinctrl/vt8500/pinctrl-wmt.h b/drivers/pinctrl/vt8500/pinctrl-wmt.h
new file mode 100644
index 000000000000..41f5f2deb5d6
--- /dev/null
+++ b/drivers/pinctrl/vt8500/pinctrl-wmt.h
@@ -0,0 +1,79 @@
1/*
2 * Pinctrl driver for the Wondermedia SoC's
3 *
4 * Copyright (c) 2013 Tony Prisk <linux@prisktech.co.nz>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 */
15
16#include <linux/gpio.h>
17
18/* VT8500 has no enable register in the extgpio bank. */
19#define NO_REG 0xFFFF
20
21#define WMT_PINCTRL_BANK(__en, __dir, __dout, __din, __pen, __pcfg) \
22{ \
23 .reg_en = __en, \
24 .reg_dir = __dir, \
25 .reg_data_out = __dout, \
26 .reg_data_in = __din, \
27 .reg_pull_en = __pen, \
28 .reg_pull_cfg = __pcfg, \
29}
30
31/* Encode/decode the bank/bit pairs into a pin value */
32#define WMT_PIN(__bank, __offset) ((__bank << 5) | __offset)
33#define WMT_BANK_FROM_PIN(__pin) (__pin >> 5)
34#define WMT_BIT_FROM_PIN(__pin) (__pin & 0x1f)
35
36#define WMT_GROUP(__name, __data) \
37{ \
38 .name = __name, \
39 .pins = __data, \
40 .npins = ARRAY_SIZE(__data), \
41}
42
43struct wmt_pinctrl_bank_registers {
44 u32 reg_en;
45 u32 reg_dir;
46 u32 reg_data_out;
47 u32 reg_data_in;
48
49 u32 reg_pull_en;
50 u32 reg_pull_cfg;
51};
52
53struct wmt_pinctrl_group {
54 const char *name;
55 const unsigned int *pins;
56 const unsigned npins;
57};
58
59struct wmt_pinctrl_data {
60 struct device *dev;
61 struct pinctrl_dev *pctl_dev;
62
63 /* must be initialized before calling wmt_pinctrl_probe */
64 void __iomem *base;
65 const struct wmt_pinctrl_bank_registers *banks;
66 const struct pinctrl_pin_desc *pins;
67 const char * const *groups;
68
69 u32 nbanks;
70 u32 npins;
71 u32 ngroups;
72
73 struct gpio_chip gpio_chip;
74 struct pinctrl_gpio_range gpio_range;
75};
76
77int wmt_pinctrl_probe(struct platform_device *pdev,
78 struct wmt_pinctrl_data *data);
79int wmt_pinctrl_remove(struct platform_device *pdev);
diff --git a/drivers/video/atmel_lcdfb.c b/drivers/video/atmel_lcdfb.c
index 025428e04c33..c1a2914447e1 100644
--- a/drivers/video/atmel_lcdfb.c
+++ b/drivers/video/atmel_lcdfb.c
@@ -34,6 +34,77 @@
34#define ATMEL_LCDC_DMA_BURST_LEN 8 /* words */ 34#define ATMEL_LCDC_DMA_BURST_LEN 8 /* words */
35#define ATMEL_LCDC_FIFO_SIZE 512 /* words */ 35#define ATMEL_LCDC_FIFO_SIZE 512 /* words */
36 36
37struct atmel_lcdfb_config {
38 bool have_alt_pixclock;
39 bool have_hozval;
40 bool have_intensity_bit;
41};
42
43static struct atmel_lcdfb_config at91sam9261_config = {
44 .have_hozval = true,
45 .have_intensity_bit = true,
46};
47
48static struct atmel_lcdfb_config at91sam9263_config = {
49 .have_intensity_bit = true,
50};
51
52static struct atmel_lcdfb_config at91sam9g10_config = {
53 .have_hozval = true,
54};
55
56static struct atmel_lcdfb_config at91sam9g45_config = {
57 .have_alt_pixclock = true,
58};
59
60static struct atmel_lcdfb_config at91sam9g45es_config = {
61};
62
63static struct atmel_lcdfb_config at91sam9rl_config = {
64 .have_intensity_bit = true,
65};
66
67static struct atmel_lcdfb_config at32ap_config = {
68 .have_hozval = true,
69};
70
71static const struct platform_device_id atmel_lcdfb_devtypes[] = {
72 {
73 .name = "at91sam9261-lcdfb",
74 .driver_data = (unsigned long)&at91sam9261_config,
75 }, {
76 .name = "at91sam9263-lcdfb",
77 .driver_data = (unsigned long)&at91sam9263_config,
78 }, {
79 .name = "at91sam9g10-lcdfb",
80 .driver_data = (unsigned long)&at91sam9g10_config,
81 }, {
82 .name = "at91sam9g45-lcdfb",
83 .driver_data = (unsigned long)&at91sam9g45_config,
84 }, {
85 .name = "at91sam9g45es-lcdfb",
86 .driver_data = (unsigned long)&at91sam9g45es_config,
87 }, {
88 .name = "at91sam9rl-lcdfb",
89 .driver_data = (unsigned long)&at91sam9rl_config,
90 }, {
91 .name = "at32ap-lcdfb",
92 .driver_data = (unsigned long)&at32ap_config,
93 }, {
94 /* terminator */
95 }
96};
97
98static struct atmel_lcdfb_config *
99atmel_lcdfb_get_config(struct platform_device *pdev)
100{
101 unsigned long data;
102
103 data = platform_get_device_id(pdev)->driver_data;
104
105 return (struct atmel_lcdfb_config *)data;
106}
107
37#if defined(CONFIG_ARCH_AT91) 108#if defined(CONFIG_ARCH_AT91)
38#define ATMEL_LCDFB_FBINFO_DEFAULT (FBINFO_DEFAULT \ 109#define ATMEL_LCDFB_FBINFO_DEFAULT (FBINFO_DEFAULT \
39 | FBINFO_PARTIAL_PAN_OK \ 110 | FBINFO_PARTIAL_PAN_OK \
@@ -193,14 +264,16 @@ static struct fb_fix_screeninfo atmel_lcdfb_fix __initdata = {
193 .accel = FB_ACCEL_NONE, 264 .accel = FB_ACCEL_NONE,
194}; 265};
195 266
196static unsigned long compute_hozval(unsigned long xres, unsigned long lcdcon2) 267static unsigned long compute_hozval(struct atmel_lcdfb_info *sinfo,
268 unsigned long xres)
197{ 269{
270 unsigned long lcdcon2;
198 unsigned long value; 271 unsigned long value;
199 272
200 if (!(cpu_is_at91sam9261() || cpu_is_at91sam9g10() 273 if (!sinfo->config->have_hozval)
201 || cpu_is_at32ap7000()))
202 return xres; 274 return xres;
203 275
276 lcdcon2 = lcdc_readl(sinfo, ATMEL_LCDC_LCDCON2);
204 value = xres; 277 value = xres;
205 if ((lcdcon2 & ATMEL_LCDC_DISTYPE) != ATMEL_LCDC_DISTYPE_TFT) { 278 if ((lcdcon2 & ATMEL_LCDC_DISTYPE) != ATMEL_LCDC_DISTYPE_TFT) {
206 /* STN display */ 279 /* STN display */
@@ -423,7 +496,7 @@ static int atmel_lcdfb_check_var(struct fb_var_screeninfo *var,
423 break; 496 break;
424 case 16: 497 case 16:
425 /* Older SOCs use IBGR:555 rather than BGR:565. */ 498 /* Older SOCs use IBGR:555 rather than BGR:565. */
426 if (sinfo->have_intensity_bit) 499 if (sinfo->config->have_intensity_bit)
427 var->green.length = 5; 500 var->green.length = 5;
428 else 501 else
429 var->green.length = 6; 502 var->green.length = 6;
@@ -531,7 +604,7 @@ static int atmel_lcdfb_set_par(struct fb_info *info)
531 /* Now, the LCDC core... */ 604 /* Now, the LCDC core... */
532 605
533 /* Set pixel clock */ 606 /* Set pixel clock */
534 if (cpu_is_at91sam9g45() && !cpu_is_at91sam9g45es()) 607 if (sinfo->config->have_alt_pixclock)
535 pix_factor = 1; 608 pix_factor = 1;
536 609
537 clk_value_khz = clk_get_rate(sinfo->lcdc_clk) / 1000; 610 clk_value_khz = clk_get_rate(sinfo->lcdc_clk) / 1000;
@@ -591,8 +664,7 @@ static int atmel_lcdfb_set_par(struct fb_info *info)
591 lcdc_writel(sinfo, ATMEL_LCDC_TIM2, value); 664 lcdc_writel(sinfo, ATMEL_LCDC_TIM2, value);
592 665
593 /* Horizontal value (aka line size) */ 666 /* Horizontal value (aka line size) */
594 hozval_linesz = compute_hozval(info->var.xres, 667 hozval_linesz = compute_hozval(sinfo, info->var.xres);
595 lcdc_readl(sinfo, ATMEL_LCDC_LCDCON2));
596 668
597 /* Display size */ 669 /* Display size */
598 value = (hozval_linesz - 1) << ATMEL_LCDC_HOZVAL_OFFSET; 670 value = (hozval_linesz - 1) << ATMEL_LCDC_HOZVAL_OFFSET;
@@ -684,7 +756,7 @@ static int atmel_lcdfb_setcolreg(unsigned int regno, unsigned int red,
684 756
685 case FB_VISUAL_PSEUDOCOLOR: 757 case FB_VISUAL_PSEUDOCOLOR:
686 if (regno < 256) { 758 if (regno < 256) {
687 if (sinfo->have_intensity_bit) { 759 if (sinfo->config->have_intensity_bit) {
688 /* old style I+BGR:555 */ 760 /* old style I+BGR:555 */
689 val = ((red >> 11) & 0x001f); 761 val = ((red >> 11) & 0x001f);
690 val |= ((green >> 6) & 0x03e0); 762 val |= ((green >> 6) & 0x03e0);
@@ -821,15 +893,13 @@ static int __init atmel_lcdfb_init_fbinfo(struct atmel_lcdfb_info *sinfo)
821 893
822static void atmel_lcdfb_start_clock(struct atmel_lcdfb_info *sinfo) 894static void atmel_lcdfb_start_clock(struct atmel_lcdfb_info *sinfo)
823{ 895{
824 if (sinfo->bus_clk) 896 clk_enable(sinfo->bus_clk);
825 clk_enable(sinfo->bus_clk);
826 clk_enable(sinfo->lcdc_clk); 897 clk_enable(sinfo->lcdc_clk);
827} 898}
828 899
829static void atmel_lcdfb_stop_clock(struct atmel_lcdfb_info *sinfo) 900static void atmel_lcdfb_stop_clock(struct atmel_lcdfb_info *sinfo)
830{ 901{
831 if (sinfo->bus_clk) 902 clk_disable(sinfo->bus_clk);
832 clk_disable(sinfo->bus_clk);
833 clk_disable(sinfo->lcdc_clk); 903 clk_disable(sinfo->lcdc_clk);
834} 904}
835 905
@@ -874,10 +944,9 @@ static int __init atmel_lcdfb_probe(struct platform_device *pdev)
874 } 944 }
875 sinfo->info = info; 945 sinfo->info = info;
876 sinfo->pdev = pdev; 946 sinfo->pdev = pdev;
877 if (cpu_is_at91sam9261() || cpu_is_at91sam9263() || 947 sinfo->config = atmel_lcdfb_get_config(pdev);
878 cpu_is_at91sam9rl()) { 948 if (!sinfo->config)
879 sinfo->have_intensity_bit = true; 949 goto free_info;
880 }
881 950
882 strcpy(info->fix.id, sinfo->pdev->name); 951 strcpy(info->fix.id, sinfo->pdev->name);
883 info->flags = ATMEL_LCDFB_FBINFO_DEFAULT; 952 info->flags = ATMEL_LCDFB_FBINFO_DEFAULT;
@@ -888,13 +957,10 @@ static int __init atmel_lcdfb_probe(struct platform_device *pdev)
888 info->fix = atmel_lcdfb_fix; 957 info->fix = atmel_lcdfb_fix;
889 958
890 /* Enable LCDC Clocks */ 959 /* Enable LCDC Clocks */
891 if (cpu_is_at91sam9261() || cpu_is_at91sam9g10() 960 sinfo->bus_clk = clk_get(dev, "hclk");
892 || cpu_is_at32ap7000()) { 961 if (IS_ERR(sinfo->bus_clk)) {
893 sinfo->bus_clk = clk_get(dev, "hck1"); 962 ret = PTR_ERR(sinfo->bus_clk);
894 if (IS_ERR(sinfo->bus_clk)) { 963 goto free_info;
895 ret = PTR_ERR(sinfo->bus_clk);
896 goto free_info;
897 }
898 } 964 }
899 sinfo->lcdc_clk = clk_get(dev, "lcdc_clk"); 965 sinfo->lcdc_clk = clk_get(dev, "lcdc_clk");
900 if (IS_ERR(sinfo->lcdc_clk)) { 966 if (IS_ERR(sinfo->lcdc_clk)) {
@@ -1055,8 +1121,7 @@ stop_clk:
1055 atmel_lcdfb_stop_clock(sinfo); 1121 atmel_lcdfb_stop_clock(sinfo);
1056 clk_put(sinfo->lcdc_clk); 1122 clk_put(sinfo->lcdc_clk);
1057put_bus_clk: 1123put_bus_clk:
1058 if (sinfo->bus_clk) 1124 clk_put(sinfo->bus_clk);
1059 clk_put(sinfo->bus_clk);
1060free_info: 1125free_info:
1061 framebuffer_release(info); 1126 framebuffer_release(info);
1062out: 1127out:
@@ -1081,8 +1146,7 @@ static int __exit atmel_lcdfb_remove(struct platform_device *pdev)
1081 unregister_framebuffer(info); 1146 unregister_framebuffer(info);
1082 atmel_lcdfb_stop_clock(sinfo); 1147 atmel_lcdfb_stop_clock(sinfo);
1083 clk_put(sinfo->lcdc_clk); 1148 clk_put(sinfo->lcdc_clk);
1084 if (sinfo->bus_clk) 1149 clk_put(sinfo->bus_clk);
1085 clk_put(sinfo->bus_clk);
1086 fb_dealloc_cmap(&info->cmap); 1150 fb_dealloc_cmap(&info->cmap);
1087 free_irq(sinfo->irq_base, info); 1151 free_irq(sinfo->irq_base, info);
1088 iounmap(sinfo->mmio); 1152 iounmap(sinfo->mmio);
@@ -1151,7 +1215,7 @@ static struct platform_driver atmel_lcdfb_driver = {
1151 .remove = __exit_p(atmel_lcdfb_remove), 1215 .remove = __exit_p(atmel_lcdfb_remove),
1152 .suspend = atmel_lcdfb_suspend, 1216 .suspend = atmel_lcdfb_suspend,
1153 .resume = atmel_lcdfb_resume, 1217 .resume = atmel_lcdfb_resume,
1154 1218 .id_table = atmel_lcdfb_devtypes,
1155 .driver = { 1219 .driver = {
1156 .name = "atmel_lcdfb", 1220 .name = "atmel_lcdfb",
1157 .owner = THIS_MODULE, 1221 .owner = THIS_MODULE,