1 From bd2bb5fbf1982b18f44b6fd78e45717e0757cdc0 Mon Sep 17 00:00:00 2001
2 From: Hauke Mehrtens <hauke@hauke-m.de>
3 Date: Sat, 16 Jul 2011 15:19:38 +0200
4 Subject: [PATCH 07/26] bcma: get CPU clock
6 Add method to return the clock of the CPU. This is needed by the arch
7 code to calculate the mips_hpt_frequency.
9 Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
11 drivers/bcma/bcma_private.h | 1 +
12 drivers/bcma/driver_chipcommon_pmu.c | 107 +++++++++++++++++++++++++++
13 drivers/bcma/driver_mips.c | 12 +++
14 include/linux/bcma/bcma_driver_chipcommon.h | 39 ++++++++++
15 include/linux/bcma/bcma_driver_mips.h | 2 +
16 5 files changed, 161 insertions(+), 0 deletions(-)
18 --- a/drivers/bcma/bcma_private.h
19 +++ b/drivers/bcma/bcma_private.h
20 @@ -36,6 +36,7 @@ void bcma_chipco_serial_init(struct bcma
22 /* driver_chipcommon_pmu.c */
23 u32 bcma_pmu_alp_clock(struct bcma_drv_cc *cc);
24 +u32 bcma_pmu_get_clockcpu(struct bcma_drv_cc *cc);
26 #ifdef CONFIG_BCMA_HOST_PCI
28 --- a/drivers/bcma/driver_chipcommon_pmu.c
29 +++ b/drivers/bcma/driver_chipcommon_pmu.c
31 #include "bcma_private.h"
32 #include <linux/bcma/bcma.h>
34 +static u32 bcma_chipco_pll_read(struct bcma_drv_cc *cc, u32 offset)
36 + bcma_cc_write32(cc, BCMA_CC_PLLCTL_ADDR, offset);
37 + bcma_cc_read32(cc, BCMA_CC_PLLCTL_ADDR);
38 + return bcma_cc_read32(cc, BCMA_CC_PLLCTL_DATA);
41 static void bcma_chipco_chipctl_maskset(struct bcma_drv_cc *cc,
42 u32 offset, u32 mask, u32 set)
44 @@ -162,3 +169,103 @@ u32 bcma_pmu_alp_clock(struct bcma_drv_c
46 return BCMA_CC_PMU_ALP_CLOCK;
49 +/* Find the output of the "m" pll divider given pll controls that start with
50 + * pllreg "pll0" i.e. 12 for main 6 for phy, 0 for misc.
52 +static u32 bcma_pmu_clock(struct bcma_drv_cc *cc, u32 pll0, u32 m)
54 + u32 tmp, div, ndiv, p1, p2, fc;
55 + struct bcma_bus *bus = cc->core->bus;
57 + BUG_ON((pll0 & 3) || (pll0 > BCMA_CC_PMU4716_MAINPLL_PLL0));
59 + BUG_ON(!m || m > 4);
61 + if (bus->chipinfo.id == 0x5357 || bus->chipinfo.id == 0x4749) {
62 + /* Detect failure in clock setting */
63 + tmp = bcma_cc_read32(cc, BCMA_CC_CHIPSTAT);
65 + return 133 * 1000000;
68 + tmp = bcma_chipco_pll_read(cc, pll0 + BCMA_CC_PPL_P1P2_OFF);
69 + p1 = (tmp & BCMA_CC_PPL_P1_MASK) >> BCMA_CC_PPL_P1_SHIFT;
70 + p2 = (tmp & BCMA_CC_PPL_P2_MASK) >> BCMA_CC_PPL_P2_SHIFT;
72 + tmp = bcma_chipco_pll_read(cc, pll0 + BCMA_CC_PPL_M14_OFF);
73 + div = (tmp >> ((m - 1) * BCMA_CC_PPL_MDIV_WIDTH)) &
74 + BCMA_CC_PPL_MDIV_MASK;
76 + tmp = bcma_chipco_pll_read(cc, pll0 + BCMA_CC_PPL_NM5_OFF);
77 + ndiv = (tmp & BCMA_CC_PPL_NDIV_MASK) >> BCMA_CC_PPL_NDIV_SHIFT;
79 + /* Do calculation in Mhz */
80 + fc = bcma_pmu_alp_clock(cc) / 1000000;
81 + fc = (p1 * ndiv * fc) / p2;
83 + /* Return clock in Hertz */
84 + return (fc / div) * 1000000;
87 +/* query bus clock frequency for PMU-enabled chipcommon */
88 +u32 bcma_pmu_get_clockcontrol(struct bcma_drv_cc *cc)
90 + struct bcma_bus *bus = cc->core->bus;
92 + switch (bus->chipinfo.id) {
96 + return bcma_pmu_clock(cc, BCMA_CC_PMU4716_MAINPLL_PLL0,
97 + BCMA_CC_PMU5_MAINPLL_SSB);
99 + return bcma_pmu_clock(cc, BCMA_CC_PMU5356_MAINPLL_PLL0,
100 + BCMA_CC_PMU5_MAINPLL_SSB);
103 + return bcma_pmu_clock(cc, BCMA_CC_PMU5357_MAINPLL_PLL0,
104 + BCMA_CC_PMU5_MAINPLL_SSB);
106 + return bcma_pmu_clock(cc, BCMA_CC_PMU4706_MAINPLL_PLL0,
107 + BCMA_CC_PMU5_MAINPLL_SSB);
111 + pr_warn("No backplane clock specified for %04X device, "
112 + "pmu rev. %d, using default %d Hz\n",
113 + bus->chipinfo.id, cc->pmu.rev, BCMA_CC_PMU_HT_CLOCK);
115 + return BCMA_CC_PMU_HT_CLOCK;
118 +/* query cpu clock frequency for PMU-enabled chipcommon */
119 +u32 bcma_pmu_get_clockcpu(struct bcma_drv_cc *cc)
121 + struct bcma_bus *bus = cc->core->bus;
123 + if (bus->chipinfo.id == 53572)
126 + if (cc->pmu.rev >= 5) {
128 + switch (bus->chipinfo.id) {
130 + pll = BCMA_CC_PMU5356_MAINPLL_PLL0;
134 + pll = BCMA_CC_PMU5357_MAINPLL_PLL0;
137 + pll = BCMA_CC_PMU4716_MAINPLL_PLL0;
141 + /* TODO: if (bus->chipinfo.id == 0x5300)
142 + return si_4706_pmu_clock(sih, osh, cc, PMU4706_MAINPLL_PLL0, PMU5_MAINPLL_CPU); */
143 + return bcma_pmu_clock(cc, pll, BCMA_CC_PMU5_MAINPLL_CPU);
146 + return bcma_pmu_get_clockcontrol(cc);
148 --- a/drivers/bcma/driver_mips.c
149 +++ b/drivers/bcma/driver_mips.c
150 @@ -166,6 +166,18 @@ static void bcma_core_mips_dump_irq(stru
154 +u32 bcma_cpu_clock(struct bcma_drv_mips *mcore)
156 + struct bcma_bus *bus = mcore->core->bus;
158 + if (bus->drv_cc.capabilities & BCMA_CC_CAP_PMU)
159 + return bcma_pmu_get_clockcpu(&bus->drv_cc);
161 + pr_err("No PMU available, need this to get the cpu clock\n");
164 +EXPORT_SYMBOL(bcma_cpu_clock);
166 static void bcma_core_mips_flash_detect(struct bcma_drv_mips *mcore)
168 struct bcma_bus *bus = mcore->core->bus;
169 --- a/include/linux/bcma/bcma_driver_chipcommon.h
170 +++ b/include/linux/bcma/bcma_driver_chipcommon.h
172 #define BCMA_CC_SPROM 0x0800 /* SPROM beginning */
173 #define BCMA_CC_SPROM_PCIE6 0x0830 /* SPROM beginning on PCIe rev >= 6 */
175 +/* Divider allocation in 4716/47162/5356 */
176 +#define BCMA_CC_PMU5_MAINPLL_CPU 1
177 +#define BCMA_CC_PMU5_MAINPLL_MEM 2
178 +#define BCMA_CC_PMU5_MAINPLL_SSB 3
180 +/* PLL usage in 4716/47162 */
181 +#define BCMA_CC_PMU4716_MAINPLL_PLL0 12
183 +/* PLL usage in 5356/5357 */
184 +#define BCMA_CC_PMU5356_MAINPLL_PLL0 0
185 +#define BCMA_CC_PMU5357_MAINPLL_PLL0 0
188 +#define BCMA_CC_PMU4706_MAINPLL_PLL0 0
190 /* ALP clock on pre-PMU chips */
191 #define BCMA_CC_PMU_ALP_CLOCK 20000000
192 +/* HT clock for systems with PMU-enabled chipcommon */
193 +#define BCMA_CC_PMU_HT_CLOCK 80000000
195 +/* PMU rev 5 (& 6) */
196 +#define BCMA_CC_PPL_P1P2_OFF 0
197 +#define BCMA_CC_PPL_P1_MASK 0x0f000000
198 +#define BCMA_CC_PPL_P1_SHIFT 24
199 +#define BCMA_CC_PPL_P2_MASK 0x00f00000
200 +#define BCMA_CC_PPL_P2_SHIFT 20
201 +#define BCMA_CC_PPL_M14_OFF 1
202 +#define BCMA_CC_PPL_MDIV_MASK 0x000000ff
203 +#define BCMA_CC_PPL_MDIV_WIDTH 8
204 +#define BCMA_CC_PPL_NM5_OFF 2
205 +#define BCMA_CC_PPL_NDIV_MASK 0xfff00000
206 +#define BCMA_CC_PPL_NDIV_SHIFT 20
207 +#define BCMA_CC_PPL_FMAB_OFF 3
208 +#define BCMA_CC_PPL_MRAT_MASK 0xf0000000
209 +#define BCMA_CC_PPL_MRAT_SHIFT 28
210 +#define BCMA_CC_PPL_ABRAT_MASK 0x08000000
211 +#define BCMA_CC_PPL_ABRAT_SHIFT 27
212 +#define BCMA_CC_PPL_FDIV_MASK 0x07ffffff
213 +#define BCMA_CC_PPL_PLLCTL_OFF 4
214 +#define BCMA_CC_PPL_PCHI_OFF 5
215 +#define BCMA_CC_PPL_PCHI_MASK 0x0000003f
217 /* Data for the PMU, if available.
218 * Check availability with ((struct bcma_chipcommon)->capabilities & BCMA_CC_CAP_PMU)
219 --- a/include/linux/bcma/bcma_driver_mips.h
220 +++ b/include/linux/bcma/bcma_driver_mips.h
221 @@ -44,6 +44,8 @@ extern void bcma_core_mips_init(struct b
222 static inline void bcma_core_mips_init(struct bcma_drv_mips *mcore) { }
225 +extern u32 bcma_cpu_clock(struct bcma_drv_mips *mcore);
227 extern unsigned int bcma_core_mips_irq(struct bcma_device *dev);
229 #endif /* LINUX_BCMA_DRIVER_MIPS_H_ */