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