2 * Broadcom specific AMBA
3 * ChipCommon Power Management Unit driver
5 * Copyright 2009, Michael Buesch <m@bues.ch>
6 * Copyright 2007, 2011, Broadcom Corporation
7 * Copyright 2011, 2012, Hauke Mehrtens <hauke@hauke-m.de>
9 * Licensed under the GNU/GPL. See COPYING for details.
12 #include "bcma_private.h"
13 #include <linux/export.h>
14 #include <linux/bcma/bcma.h>
16 static u32
bcma_chipco_pll_read(struct bcma_drv_cc
*cc
, u32 offset
)
18 bcma_cc_write32(cc
, BCMA_CC_PLLCTL_ADDR
, offset
);
19 bcma_cc_read32(cc
, BCMA_CC_PLLCTL_ADDR
);
20 return bcma_cc_read32(cc
, BCMA_CC_PLLCTL_DATA
);
23 void bcma_chipco_pll_write(struct bcma_drv_cc
*cc
, u32 offset
, u32 value
)
25 bcma_cc_write32(cc
, BCMA_CC_PLLCTL_ADDR
, offset
);
26 bcma_cc_read32(cc
, BCMA_CC_PLLCTL_ADDR
);
27 bcma_cc_write32(cc
, BCMA_CC_PLLCTL_DATA
, value
);
29 EXPORT_SYMBOL_GPL(bcma_chipco_pll_write
);
31 void bcma_chipco_pll_maskset(struct bcma_drv_cc
*cc
, u32 offset
, u32 mask
,
34 bcma_cc_write32(cc
, BCMA_CC_PLLCTL_ADDR
, offset
);
35 bcma_cc_read32(cc
, BCMA_CC_PLLCTL_ADDR
);
36 bcma_cc_maskset32(cc
, BCMA_CC_PLLCTL_DATA
, mask
, set
);
38 EXPORT_SYMBOL_GPL(bcma_chipco_pll_maskset
);
40 void bcma_chipco_chipctl_maskset(struct bcma_drv_cc
*cc
,
41 u32 offset
, u32 mask
, u32 set
)
43 bcma_cc_write32(cc
, BCMA_CC_CHIPCTL_ADDR
, offset
);
44 bcma_cc_read32(cc
, BCMA_CC_CHIPCTL_ADDR
);
45 bcma_cc_maskset32(cc
, BCMA_CC_CHIPCTL_DATA
, mask
, set
);
47 EXPORT_SYMBOL_GPL(bcma_chipco_chipctl_maskset
);
49 void bcma_chipco_regctl_maskset(struct bcma_drv_cc
*cc
, u32 offset
, u32 mask
,
52 bcma_cc_write32(cc
, BCMA_CC_REGCTL_ADDR
, offset
);
53 bcma_cc_read32(cc
, BCMA_CC_REGCTL_ADDR
);
54 bcma_cc_maskset32(cc
, BCMA_CC_REGCTL_DATA
, mask
, set
);
56 EXPORT_SYMBOL_GPL(bcma_chipco_regctl_maskset
);
58 static void bcma_pmu_resources_init(struct bcma_drv_cc
*cc
)
60 struct bcma_bus
*bus
= cc
->core
->bus
;
61 u32 min_msk
= 0, max_msk
= 0;
63 switch (bus
->chipinfo
.id
) {
64 case BCMA_CHIP_ID_BCM4313
:
69 bcma_debug(bus
, "PMU resource config unknown or not needed for device 0x%04X\n",
73 /* Set the resource masks. */
75 bcma_cc_write32(cc
, BCMA_CC_PMU_MINRES_MSK
, min_msk
);
77 bcma_cc_write32(cc
, BCMA_CC_PMU_MAXRES_MSK
, max_msk
);
80 * Add some delay; allow resources to come up and settle.
81 * Delay is required for SoC (early init).
86 /* Disable to allow reading SPROM. Don't know the adventages of enabling it. */
87 void bcma_chipco_bcm4331_ext_pa_lines_ctl(struct bcma_drv_cc
*cc
, bool enable
)
89 struct bcma_bus
*bus
= cc
->core
->bus
;
92 val
= bcma_cc_read32(cc
, BCMA_CC_CHIPCTL
);
94 val
|= BCMA_CHIPCTL_4331_EXTPA_EN
;
95 if (bus
->chipinfo
.pkg
== 9 || bus
->chipinfo
.pkg
== 11)
96 val
|= BCMA_CHIPCTL_4331_EXTPA_ON_GPIO2_5
;
97 else if (bus
->chipinfo
.rev
> 0)
98 val
|= BCMA_CHIPCTL_4331_EXTPA_EN2
;
100 val
&= ~BCMA_CHIPCTL_4331_EXTPA_EN
;
101 val
&= ~BCMA_CHIPCTL_4331_EXTPA_EN2
;
102 val
&= ~BCMA_CHIPCTL_4331_EXTPA_ON_GPIO2_5
;
104 bcma_cc_write32(cc
, BCMA_CC_CHIPCTL
, val
);
107 static void bcma_pmu_workarounds(struct bcma_drv_cc
*cc
)
109 struct bcma_bus
*bus
= cc
->core
->bus
;
111 switch (bus
->chipinfo
.id
) {
112 case BCMA_CHIP_ID_BCM4313
:
113 /* enable 12 mA drive strenth for 4313 and set chipControl
115 bcma_chipco_chipctl_maskset(cc
, 0,
116 ~BCMA_CCTRL_4313_12MA_LED_DRIVE
,
117 BCMA_CCTRL_4313_12MA_LED_DRIVE
);
119 case BCMA_CHIP_ID_BCM4331
:
120 case BCMA_CHIP_ID_BCM43431
:
121 /* Ext PA lines must be enabled for tx on BCM4331 */
122 bcma_chipco_bcm4331_ext_pa_lines_ctl(cc
, true);
124 case BCMA_CHIP_ID_BCM43224
:
125 case BCMA_CHIP_ID_BCM43421
:
126 /* enable 12 mA drive strenth for 43224 and set chipControl
128 if (bus
->chipinfo
.rev
== 0) {
129 bcma_cc_maskset32(cc
, BCMA_CC_CHIPCTL
,
130 ~BCMA_CCTRL_43224_GPIO_TOGGLE
,
131 BCMA_CCTRL_43224_GPIO_TOGGLE
);
132 bcma_chipco_chipctl_maskset(cc
, 0,
133 ~BCMA_CCTRL_43224A0_12MA_LED_DRIVE
,
134 BCMA_CCTRL_43224A0_12MA_LED_DRIVE
);
136 bcma_chipco_chipctl_maskset(cc
, 0,
137 ~BCMA_CCTRL_43224B0_12MA_LED_DRIVE
,
138 BCMA_CCTRL_43224B0_12MA_LED_DRIVE
);
142 bcma_debug(bus
, "Workarounds unknown or not needed for device 0x%04X\n",
147 void bcma_pmu_init(struct bcma_drv_cc
*cc
)
151 pmucap
= bcma_cc_read32(cc
, BCMA_CC_PMU_CAP
);
152 cc
->pmu
.rev
= (pmucap
& BCMA_CC_PMU_CAP_REVISION
);
154 bcma_debug(cc
->core
->bus
, "Found rev %u PMU (capabilities 0x%08X)\n",
155 cc
->pmu
.rev
, pmucap
);
157 if (cc
->pmu
.rev
== 1)
158 bcma_cc_mask32(cc
, BCMA_CC_PMU_CTL
,
159 ~BCMA_CC_PMU_CTL_NOILPONW
);
161 bcma_cc_set32(cc
, BCMA_CC_PMU_CTL
,
162 BCMA_CC_PMU_CTL_NOILPONW
);
164 bcma_pmu_resources_init(cc
);
165 bcma_pmu_workarounds(cc
);
168 u32
bcma_pmu_alp_clock(struct bcma_drv_cc
*cc
)
170 struct bcma_bus
*bus
= cc
->core
->bus
;
172 switch (bus
->chipinfo
.id
) {
173 case BCMA_CHIP_ID_BCM4716
:
174 case BCMA_CHIP_ID_BCM4748
:
175 case BCMA_CHIP_ID_BCM47162
:
176 case BCMA_CHIP_ID_BCM4313
:
177 case BCMA_CHIP_ID_BCM5357
:
178 case BCMA_CHIP_ID_BCM4749
:
179 case BCMA_CHIP_ID_BCM53572
:
182 case BCMA_CHIP_ID_BCM5356
:
183 case BCMA_CHIP_ID_BCM4706
:
187 bcma_warn(bus
, "No ALP clock specified for %04X device, pmu rev. %d, using default %d Hz\n",
188 bus
->chipinfo
.id
, cc
->pmu
.rev
, BCMA_CC_PMU_ALP_CLOCK
);
190 return BCMA_CC_PMU_ALP_CLOCK
;
193 /* Find the output of the "m" pll divider given pll controls that start with
194 * pllreg "pll0" i.e. 12 for main 6 for phy, 0 for misc.
196 static u32
bcma_pmu_clock(struct bcma_drv_cc
*cc
, u32 pll0
, u32 m
)
198 u32 tmp
, div
, ndiv
, p1
, p2
, fc
;
199 struct bcma_bus
*bus
= cc
->core
->bus
;
201 BUG_ON((pll0
& 3) || (pll0
> BCMA_CC_PMU4716_MAINPLL_PLL0
));
205 if (bus
->chipinfo
.id
== BCMA_CHIP_ID_BCM5357
||
206 bus
->chipinfo
.id
== BCMA_CHIP_ID_BCM4749
) {
207 /* Detect failure in clock setting */
208 tmp
= bcma_cc_read32(cc
, BCMA_CC_CHIPSTAT
);
210 return 133 * 1000000;
213 tmp
= bcma_chipco_pll_read(cc
, pll0
+ BCMA_CC_PPL_P1P2_OFF
);
214 p1
= (tmp
& BCMA_CC_PPL_P1_MASK
) >> BCMA_CC_PPL_P1_SHIFT
;
215 p2
= (tmp
& BCMA_CC_PPL_P2_MASK
) >> BCMA_CC_PPL_P2_SHIFT
;
217 tmp
= bcma_chipco_pll_read(cc
, pll0
+ BCMA_CC_PPL_M14_OFF
);
218 div
= (tmp
>> ((m
- 1) * BCMA_CC_PPL_MDIV_WIDTH
)) &
219 BCMA_CC_PPL_MDIV_MASK
;
221 tmp
= bcma_chipco_pll_read(cc
, pll0
+ BCMA_CC_PPL_NM5_OFF
);
222 ndiv
= (tmp
& BCMA_CC_PPL_NDIV_MASK
) >> BCMA_CC_PPL_NDIV_SHIFT
;
224 /* Do calculation in Mhz */
225 fc
= bcma_pmu_alp_clock(cc
) / 1000000;
226 fc
= (p1
* ndiv
* fc
) / p2
;
228 /* Return clock in Hertz */
229 return (fc
/ div
) * 1000000;
232 static u32
bcma_pmu_clock_bcm4706(struct bcma_drv_cc
*cc
, u32 pll0
, u32 m
)
234 u32 tmp
, ndiv
, p1div
, p2div
;
239 /* Get N, P1 and P2 dividers to determine CPU clock */
240 tmp
= bcma_chipco_pll_read(cc
, pll0
+ BCMA_CC_PMU6_4706_PROCPLL_OFF
);
241 ndiv
= (tmp
& BCMA_CC_PMU6_4706_PROC_NDIV_INT_MASK
)
242 >> BCMA_CC_PMU6_4706_PROC_NDIV_INT_SHIFT
;
243 p1div
= (tmp
& BCMA_CC_PMU6_4706_PROC_P1DIV_MASK
)
244 >> BCMA_CC_PMU6_4706_PROC_P1DIV_SHIFT
;
245 p2div
= (tmp
& BCMA_CC_PMU6_4706_PROC_P2DIV_MASK
)
246 >> BCMA_CC_PMU6_4706_PROC_P2DIV_SHIFT
;
248 tmp
= bcma_cc_read32(cc
, BCMA_CC_CHIPSTAT
);
249 if (tmp
& BCMA_CC_CHIPST_4706_PKG_OPTION
)
250 /* Low cost bonding: Fixed reference clock 25MHz and m = 4 */
251 clock
= (25000000 / 4) * ndiv
* p2div
/ p1div
;
253 /* Fixed reference clock 25MHz and m = 2 */
254 clock
= (25000000 / 2) * ndiv
* p2div
/ p1div
;
256 if (m
== BCMA_CC_PMU5_MAINPLL_SSB
)
262 /* query bus clock frequency for PMU-enabled chipcommon */
263 static u32
bcma_pmu_get_clockcontrol(struct bcma_drv_cc
*cc
)
265 struct bcma_bus
*bus
= cc
->core
->bus
;
267 switch (bus
->chipinfo
.id
) {
268 case BCMA_CHIP_ID_BCM4716
:
269 case BCMA_CHIP_ID_BCM4748
:
270 case BCMA_CHIP_ID_BCM47162
:
271 return bcma_pmu_clock(cc
, BCMA_CC_PMU4716_MAINPLL_PLL0
,
272 BCMA_CC_PMU5_MAINPLL_SSB
);
273 case BCMA_CHIP_ID_BCM5356
:
274 return bcma_pmu_clock(cc
, BCMA_CC_PMU5356_MAINPLL_PLL0
,
275 BCMA_CC_PMU5_MAINPLL_SSB
);
276 case BCMA_CHIP_ID_BCM5357
:
277 case BCMA_CHIP_ID_BCM4749
:
278 return bcma_pmu_clock(cc
, BCMA_CC_PMU5357_MAINPLL_PLL0
,
279 BCMA_CC_PMU5_MAINPLL_SSB
);
280 case BCMA_CHIP_ID_BCM4706
:
281 return bcma_pmu_clock_bcm4706(cc
, BCMA_CC_PMU4706_MAINPLL_PLL0
,
282 BCMA_CC_PMU5_MAINPLL_SSB
);
283 case BCMA_CHIP_ID_BCM53572
:
286 bcma_warn(bus
, "No backplane clock specified for %04X device, pmu rev. %d, using default %d Hz\n",
287 bus
->chipinfo
.id
, cc
->pmu
.rev
, BCMA_CC_PMU_HT_CLOCK
);
289 return BCMA_CC_PMU_HT_CLOCK
;
292 /* query cpu clock frequency for PMU-enabled chipcommon */
293 u32
bcma_pmu_get_clockcpu(struct bcma_drv_cc
*cc
)
295 struct bcma_bus
*bus
= cc
->core
->bus
;
297 if (bus
->chipinfo
.id
== BCMA_CHIP_ID_BCM53572
)
300 if (cc
->pmu
.rev
>= 5) {
302 switch (bus
->chipinfo
.id
) {
303 case BCMA_CHIP_ID_BCM4706
:
304 return bcma_pmu_clock_bcm4706(cc
,
305 BCMA_CC_PMU4706_MAINPLL_PLL0
,
306 BCMA_CC_PMU5_MAINPLL_CPU
);
307 case BCMA_CHIP_ID_BCM5356
:
308 pll
= BCMA_CC_PMU5356_MAINPLL_PLL0
;
310 case BCMA_CHIP_ID_BCM5357
:
311 case BCMA_CHIP_ID_BCM4749
:
312 pll
= BCMA_CC_PMU5357_MAINPLL_PLL0
;
315 pll
= BCMA_CC_PMU4716_MAINPLL_PLL0
;
319 return bcma_pmu_clock(cc
, pll
, BCMA_CC_PMU5_MAINPLL_CPU
);
322 return bcma_pmu_get_clockcontrol(cc
);
325 static void bcma_pmu_spuravoid_pll_write(struct bcma_drv_cc
*cc
, u32 offset
,
328 bcma_cc_write32(cc
, BCMA_CC_PLLCTL_ADDR
, offset
);
329 bcma_cc_write32(cc
, BCMA_CC_PLLCTL_DATA
, value
);
332 void bcma_pmu_spuravoid_pllupdate(struct bcma_drv_cc
*cc
, int spuravoid
)
335 u8 phypll_offset
= 0;
336 u8 bcm5357_bcm43236_p1div
[] = {0x1, 0x5, 0x5};
337 u8 bcm5357_bcm43236_ndiv
[] = {0x30, 0xf6, 0xfc};
338 struct bcma_bus
*bus
= cc
->core
->bus
;
340 switch (bus
->chipinfo
.id
) {
341 case BCMA_CHIP_ID_BCM5357
:
342 case BCMA_CHIP_ID_BCM4749
:
343 case BCMA_CHIP_ID_BCM53572
:
344 /* 5357[ab]0, 43236[ab]0, and 6362b0 */
346 /* BCM5357 needs to touch PLL1_PLLCTL[02],
347 so offset PLL0_PLLCTL[02] by 6 */
348 phypll_offset
= (bus
->chipinfo
.id
== BCMA_CHIP_ID_BCM5357
||
349 bus
->chipinfo
.id
== BCMA_CHIP_ID_BCM4749
||
350 bus
->chipinfo
.id
== BCMA_CHIP_ID_BCM53572
) ? 6 : 0;
352 /* RMW only the P1 divider */
353 bcma_cc_write32(cc
, BCMA_CC_PLLCTL_ADDR
,
354 BCMA_CC_PMU_PLL_CTL0
+ phypll_offset
);
355 tmp
= bcma_cc_read32(cc
, BCMA_CC_PLLCTL_DATA
);
356 tmp
&= (~(BCMA_CC_PMU1_PLL0_PC0_P1DIV_MASK
));
357 tmp
|= (bcm5357_bcm43236_p1div
[spuravoid
] << BCMA_CC_PMU1_PLL0_PC0_P1DIV_SHIFT
);
358 bcma_cc_write32(cc
, BCMA_CC_PLLCTL_DATA
, tmp
);
360 /* RMW only the int feedback divider */
361 bcma_cc_write32(cc
, BCMA_CC_PLLCTL_ADDR
,
362 BCMA_CC_PMU_PLL_CTL2
+ phypll_offset
);
363 tmp
= bcma_cc_read32(cc
, BCMA_CC_PLLCTL_DATA
);
364 tmp
&= ~(BCMA_CC_PMU1_PLL0_PC2_NDIV_INT_MASK
);
365 tmp
|= (bcm5357_bcm43236_ndiv
[spuravoid
]) << BCMA_CC_PMU1_PLL0_PC2_NDIV_INT_SHIFT
;
366 bcma_cc_write32(cc
, BCMA_CC_PLLCTL_DATA
, tmp
);
371 case BCMA_CHIP_ID_BCM4331
:
372 case BCMA_CHIP_ID_BCM43431
:
373 if (spuravoid
== 2) {
374 bcma_pmu_spuravoid_pll_write(cc
, BCMA_CC_PMU_PLL_CTL0
,
376 bcma_pmu_spuravoid_pll_write(cc
, BCMA_CC_PMU_PLL_CTL2
,
378 } else if (spuravoid
== 1) {
379 bcma_pmu_spuravoid_pll_write(cc
, BCMA_CC_PMU_PLL_CTL0
,
381 bcma_pmu_spuravoid_pll_write(cc
, BCMA_CC_PMU_PLL_CTL2
,
384 bcma_pmu_spuravoid_pll_write(cc
, BCMA_CC_PMU_PLL_CTL0
,
386 bcma_pmu_spuravoid_pll_write(cc
, BCMA_CC_PMU_PLL_CTL2
,
392 case BCMA_CHIP_ID_BCM43224
:
393 case BCMA_CHIP_ID_BCM43225
:
394 case BCMA_CHIP_ID_BCM43421
:
395 if (spuravoid
== 1) {
396 bcma_pmu_spuravoid_pll_write(cc
, BCMA_CC_PMU_PLL_CTL0
,
398 bcma_pmu_spuravoid_pll_write(cc
, BCMA_CC_PMU_PLL_CTL1
,
400 bcma_pmu_spuravoid_pll_write(cc
, BCMA_CC_PMU_PLL_CTL2
,
402 bcma_pmu_spuravoid_pll_write(cc
, BCMA_CC_PMU_PLL_CTL3
,
404 bcma_pmu_spuravoid_pll_write(cc
, BCMA_CC_PMU_PLL_CTL4
,
406 bcma_pmu_spuravoid_pll_write(cc
, BCMA_CC_PMU_PLL_CTL5
,
409 bcma_pmu_spuravoid_pll_write(cc
, BCMA_CC_PMU_PLL_CTL0
,
411 bcma_pmu_spuravoid_pll_write(cc
, BCMA_CC_PMU_PLL_CTL1
,
413 bcma_pmu_spuravoid_pll_write(cc
, BCMA_CC_PMU_PLL_CTL2
,
415 bcma_pmu_spuravoid_pll_write(cc
, BCMA_CC_PMU_PLL_CTL3
,
417 bcma_pmu_spuravoid_pll_write(cc
, BCMA_CC_PMU_PLL_CTL4
,
419 bcma_pmu_spuravoid_pll_write(cc
, BCMA_CC_PMU_PLL_CTL5
,
425 case BCMA_CHIP_ID_BCM4716
:
426 case BCMA_CHIP_ID_BCM4748
:
427 case BCMA_CHIP_ID_BCM47162
:
428 if (spuravoid
== 1) {
429 bcma_pmu_spuravoid_pll_write(cc
, BCMA_CC_PMU_PLL_CTL0
,
431 bcma_pmu_spuravoid_pll_write(cc
, BCMA_CC_PMU_PLL_CTL1
,
433 bcma_pmu_spuravoid_pll_write(cc
, BCMA_CC_PMU_PLL_CTL2
,
435 bcma_pmu_spuravoid_pll_write(cc
, BCMA_CC_PMU_PLL_CTL3
,
437 bcma_pmu_spuravoid_pll_write(cc
, BCMA_CC_PMU_PLL_CTL4
,
439 bcma_pmu_spuravoid_pll_write(cc
, BCMA_CC_PMU_PLL_CTL5
,
442 bcma_pmu_spuravoid_pll_write(cc
, BCMA_CC_PMU_PLL_CTL0
,
444 bcma_pmu_spuravoid_pll_write(cc
, BCMA_CC_PMU_PLL_CTL1
,
446 bcma_pmu_spuravoid_pll_write(cc
, BCMA_CC_PMU_PLL_CTL2
,
448 bcma_pmu_spuravoid_pll_write(cc
, BCMA_CC_PMU_PLL_CTL3
,
450 bcma_pmu_spuravoid_pll_write(cc
, BCMA_CC_PMU_PLL_CTL4
,
452 bcma_pmu_spuravoid_pll_write(cc
, BCMA_CC_PMU_PLL_CTL5
,
459 case BCMA_CHIP_ID_BCM43227
:
460 case BCMA_CHIP_ID_BCM43228
:
461 case BCMA_CHIP_ID_BCM43428
:
463 /* PLL Settings for spur avoidance on/off mode,
464 no on2 support for 43228A0 */
465 if (spuravoid
== 1) {
466 bcma_pmu_spuravoid_pll_write(cc
, BCMA_CC_PMU_PLL_CTL0
,
468 bcma_pmu_spuravoid_pll_write(cc
, BCMA_CC_PMU_PLL_CTL1
,
470 bcma_pmu_spuravoid_pll_write(cc
, BCMA_CC_PMU_PLL_CTL2
,
472 bcma_pmu_spuravoid_pll_write(cc
, BCMA_CC_PMU_PLL_CTL3
,
474 bcma_pmu_spuravoid_pll_write(cc
, BCMA_CC_PMU_PLL_CTL4
,
476 bcma_pmu_spuravoid_pll_write(cc
, BCMA_CC_PMU_PLL_CTL5
,
479 bcma_pmu_spuravoid_pll_write(cc
, BCMA_CC_PMU_PLL_CTL0
,
481 bcma_pmu_spuravoid_pll_write(cc
, BCMA_CC_PMU_PLL_CTL1
,
483 bcma_pmu_spuravoid_pll_write(cc
, BCMA_CC_PMU_PLL_CTL2
,
485 bcma_pmu_spuravoid_pll_write(cc
, BCMA_CC_PMU_PLL_CTL3
,
487 bcma_pmu_spuravoid_pll_write(cc
, BCMA_CC_PMU_PLL_CTL4
,
489 bcma_pmu_spuravoid_pll_write(cc
, BCMA_CC_PMU_PLL_CTL5
,
495 bcma_err(bus
, "Unknown spuravoidance settings for chip 0x%04X, not changing PLL\n",
500 tmp
|= bcma_cc_read32(cc
, BCMA_CC_PMU_CTL
);
501 bcma_cc_write32(cc
, BCMA_CC_PMU_CTL
, tmp
);
503 EXPORT_SYMBOL_GPL(bcma_pmu_spuravoid_pllupdate
);