68c988ab60c57ffdbfe9393f7ea59332819ab20f
[openwrt/openwrt.git] / target / linux / brcm2708 / patches-3.18 / 0048-BCM2708-Migrate-to-the-Common-Clock-Framework.patch
1 From 466743ec93a99240c1a5a04d65f490fd8370fbc3 Mon Sep 17 00:00:00 2001
2 From: notro <notro@tronnes.org>
3 Date: Sun, 6 Jul 2014 12:09:30 +0200
4 Subject: [PATCH 048/114] BCM2708: Migrate to the Common Clock Framework
5
6 As part of moving towards using Device Tree, the Common Clock Framework
7 has to be used instead of the BCM2708 clock implementation.
8
9 Selecting COMMON_CLK removes the need to set CLKDEV_LOOKUP and HAVE_CLK explicitly.
10
11 CONFIG_ARCH_BCM2708_CHIPIT #ifdef's are removed. They are no longer in use.
12
13 Signed-off-by: Noralf Tronnes <notro@tronnes.org>
14 ---
15 arch/arm/Kconfig | 3 +-
16 arch/arm/mach-bcm2708/Makefile | 2 +-
17 arch/arm/mach-bcm2708/bcm2708.c | 79 +++++++++++++++++------------------------
18 arch/arm/mach-bcm2708/clock.c | 61 -------------------------------
19 arch/arm/mach-bcm2708/clock.h | 24 -------------
20 5 files changed, 34 insertions(+), 135 deletions(-)
21 delete mode 100644 arch/arm/mach-bcm2708/clock.c
22 delete mode 100644 arch/arm/mach-bcm2708/clock.h
23
24 diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
25 index ba9c18e..0f2287f 100644
26 --- a/arch/arm/Kconfig
27 +++ b/arch/arm/Kconfig
28 @@ -385,11 +385,10 @@ config ARCH_BCM2708
29 bool "Broadcom BCM2708 family"
30 select CPU_V6
31 select ARM_AMBA
32 - select HAVE_CLK
33 select HAVE_SCHED_CLOCK
34 select NEED_MACH_GPIO_H
35 select NEED_MACH_MEMORY_H
36 - select CLKDEV_LOOKUP
37 + select COMMON_CLK
38 select ARCH_HAS_CPUFREQ
39 select GENERIC_CLOCKEVENTS
40 select ARM_ERRATA_411920
41 diff --git a/arch/arm/mach-bcm2708/Makefile b/arch/arm/mach-bcm2708/Makefile
42 index a722f3f..21e3521 100644
43 --- a/arch/arm/mach-bcm2708/Makefile
44 +++ b/arch/arm/mach-bcm2708/Makefile
45 @@ -2,6 +2,6 @@
46 # Makefile for the linux kernel.
47 #
48
49 -obj-$(CONFIG_MACH_BCM2708) += clock.o bcm2708.o armctrl.o vcio.o power.o dma.o
50 +obj-$(CONFIG_MACH_BCM2708) += bcm2708.o armctrl.o vcio.o power.o dma.o
51 obj-$(CONFIG_BCM2708_GPIO) += bcm2708_gpio.o
52 obj-$(CONFIG_BCM2708_VCMEM) += vc_mem.o
53 diff --git a/arch/arm/mach-bcm2708/bcm2708.c b/arch/arm/mach-bcm2708/bcm2708.c
54 index 633be19..ef12cb8 100644
55 --- a/arch/arm/mach-bcm2708/bcm2708.c
56 +++ b/arch/arm/mach-bcm2708/bcm2708.c
57 @@ -27,6 +27,8 @@
58 #include <linux/interrupt.h>
59 #include <linux/amba/bus.h>
60 #include <linux/amba/clcd.h>
61 +#include <linux/clk-provider.h>
62 +#include <linux/clkdev.h>
63 #include <linux/clockchips.h>
64 #include <linux/cnt32_to_63.h>
65 #include <linux/io.h>
66 @@ -58,7 +60,6 @@
67
68 #include "bcm2708.h"
69 #include "armctrl.h"
70 -#include "clock.h"
71
72 #ifdef CONFIG_BCM_VC_CMA
73 #include <linux/broadcom/vc_cma.h>
74 @@ -84,7 +85,7 @@
75
76 /* command line parameters */
77 static unsigned boardrev, serial;
78 -static unsigned uart_clock;
79 +static unsigned uart_clock = UART0_CLOCK;
80 static unsigned disk_led_gpio = 16;
81 static unsigned disk_led_active_low = 1;
82 static unsigned reboot_part = 0;
83 @@ -196,51 +197,39 @@ static void __init bcm2708_clocksource_init(void)
84 }
85 }
86
87 +struct clk __init *bcm2708_clk_register(const char *name, unsigned long fixed_rate)
88 +{
89 + struct clk *clk;
90
91 -/*
92 - * These are fixed clocks.
93 - */
94 -static struct clk ref24_clk = {
95 - .rate = UART0_CLOCK, /* The UART is clocked at 3MHz via APB_CLK */
96 -};
97 + clk = clk_register_fixed_rate(NULL, name, NULL, CLK_IS_ROOT,
98 + fixed_rate);
99 + if (IS_ERR(clk))
100 + pr_err("%s not registered\n", name);
101
102 -static struct clk osc_clk = {
103 -#ifdef CONFIG_ARCH_BCM2708_CHIPIT
104 - .rate = 27000000,
105 -#else
106 - .rate = 500000000, /* ARM clock is set from the VideoCore booter */
107 -#endif
108 -};
109 + return clk;
110 +}
111
112 -/* warning - the USB needs a clock > 34MHz */
113 +void __init bcm2708_register_clkdev(struct clk *clk, const char *name)
114 +{
115 + int ret;
116
117 -static struct clk sdhost_clk = {
118 -#ifdef CONFIG_ARCH_BCM2708_CHIPIT
119 - .rate = 4000000, /* 4MHz */
120 -#else
121 - .rate = 250000000, /* 250MHz */
122 -#endif
123 -};
124 + ret = clk_register_clkdev(clk, NULL, name);
125 + if (ret)
126 + pr_err("%s alias not registered\n", name);
127 +}
128
129 -static struct clk_lookup lookups[] = {
130 - { /* UART0 */
131 - .dev_id = "dev:f1",
132 - .clk = &ref24_clk,
133 - },
134 - { /* USB */
135 - .dev_id = "bcm2708_usb",
136 - .clk = &osc_clk,
137 - }, { /* SPI */
138 - .dev_id = "bcm2708_spi.0",
139 - .clk = &sdhost_clk,
140 - }, { /* BSC0 */
141 - .dev_id = "bcm2708_i2c.0",
142 - .clk = &sdhost_clk,
143 - }, { /* BSC1 */
144 - .dev_id = "bcm2708_i2c.1",
145 - .clk = &sdhost_clk,
146 - }
147 -};
148 +void __init bcm2708_init_clocks(void)
149 +{
150 + struct clk *clk;
151 +
152 + clk = bcm2708_clk_register("uart0_clk", uart_clock);
153 + bcm2708_register_clkdev(clk, "dev:f1");
154 +
155 + clk = bcm2708_clk_register("sdhost_clk", 250000000);
156 + bcm2708_register_clkdev(clk, "bcm2708_spi.0");
157 + bcm2708_register_clkdev(clk, "bcm2708_i2c.0");
158 + bcm2708_register_clkdev(clk, "bcm2708_i2c.1");
159 +}
160
161 #define UART0_IRQ { IRQ_UART, 0 /*NO_IRQ*/ }
162 #define UART0_DMA { 15, 14 }
163 @@ -755,11 +744,7 @@ void __init bcm2708_init(void)
164 printk("bcm2708.uart_clock = %d\n", uart_clock);
165 pm_power_off = bcm2708_power_off;
166
167 - if (uart_clock)
168 - lookups[0].clk->rate = uart_clock;
169 -
170 - for (i = 0; i < ARRAY_SIZE(lookups); i++)
171 - clkdev_add(&lookups[i]);
172 + bcm2708_init_clocks();
173
174 bcm_register_device(&bcm2708_dmaman_device);
175 bcm_register_device(&bcm2708_vcio_device);
176 diff --git a/arch/arm/mach-bcm2708/clock.c b/arch/arm/mach-bcm2708/clock.c
177 deleted file mode 100644
178 index 4fc556e..0000000
179 --- a/arch/arm/mach-bcm2708/clock.c
180 +++ /dev/null
181 @@ -1,61 +0,0 @@
182 -/*
183 - * linux/arch/arm/mach-bcm2708/clock.c
184 - *
185 - * Copyright (C) 2010 Broadcom
186 - *
187 - * This program is free software; you can redistribute it and/or modify
188 - * it under the terms of the GNU General Public License as published by
189 - * the Free Software Foundation; either version 2 of the License, or
190 - * (at your option) any later version.
191 - *
192 - * This program is distributed in the hope that it will be useful,
193 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
194 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
195 - * GNU General Public License for more details.
196 - *
197 - * You should have received a copy of the GNU General Public License
198 - * along with this program; if not, write to the Free Software
199 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
200 - */
201 -#include <linux/module.h>
202 -#include <linux/kernel.h>
203 -#include <linux/device.h>
204 -#include <linux/list.h>
205 -#include <linux/errno.h>
206 -#include <linux/err.h>
207 -#include <linux/string.h>
208 -#include <linux/clk.h>
209 -#include <linux/mutex.h>
210 -
211 -#include <asm/clkdev.h>
212 -
213 -#include "clock.h"
214 -
215 -int clk_enable(struct clk *clk)
216 -{
217 - return 0;
218 -}
219 -EXPORT_SYMBOL(clk_enable);
220 -
221 -void clk_disable(struct clk *clk)
222 -{
223 -}
224 -EXPORT_SYMBOL(clk_disable);
225 -
226 -unsigned long clk_get_rate(struct clk *clk)
227 -{
228 - return clk->rate;
229 -}
230 -EXPORT_SYMBOL(clk_get_rate);
231 -
232 -long clk_round_rate(struct clk *clk, unsigned long rate)
233 -{
234 - return clk->rate;
235 -}
236 -EXPORT_SYMBOL(clk_round_rate);
237 -
238 -int clk_set_rate(struct clk *clk, unsigned long rate)
239 -{
240 - return -EIO;
241 -}
242 -EXPORT_SYMBOL(clk_set_rate);
243 diff --git a/arch/arm/mach-bcm2708/clock.h b/arch/arm/mach-bcm2708/clock.h
244 deleted file mode 100644
245 index 5f9d725..0000000
246 --- a/arch/arm/mach-bcm2708/clock.h
247 +++ /dev/null
248 @@ -1,24 +0,0 @@
249 -/*
250 - * linux/arch/arm/mach-bcm2708/clock.h
251 - *
252 - * Copyright (C) 2010 Broadcom
253 - *
254 - * This program is free software; you can redistribute it and/or modify
255 - * it under the terms of the GNU General Public License as published by
256 - * the Free Software Foundation; either version 2 of the License, or
257 - * (at your option) any later version.
258 - *
259 - * This program is distributed in the hope that it will be useful,
260 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
261 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
262 - * GNU General Public License for more details.
263 - *
264 - * You should have received a copy of the GNU General Public License
265 - * along with this program; if not, write to the Free Software
266 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
267 - */
268 -struct module;
269 -
270 -struct clk {
271 - unsigned long rate;
272 -};
273 --
274 1.8.3.2
275