2 * Broadcom specific AMBA
3 * ChipCommon Power Management Unit driver
5 * Copyright 2009, Michael Buesch <m@bues.ch>
6 * Copyright 2007, Broadcom Corporation
8 * Licensed under the GNU/GPL. See COPYING for details.
11 #include "bcma_private.h"
12 #include <linux/bcma/bcma.h>
14 static u32
bcma_chipco_pll_read(struct bcma_drv_cc
*cc
, u32 offset
)
16 bcma_cc_write32(cc
, BCMA_CC_PLLCTL_ADDR
, offset
);
17 bcma_cc_read32(cc
, BCMA_CC_PLLCTL_ADDR
);
18 return bcma_cc_read32(cc
, BCMA_CC_PLLCTL_DATA
);
21 static void bcma_chipco_chipctl_maskset(struct bcma_drv_cc
*cc
,
22 u32 offset
, u32 mask
, u32 set
)
26 bcma_cc_read32(cc
, BCMA_CC_CHIPCTL_ADDR
);
27 bcma_cc_write32(cc
, BCMA_CC_CHIPCTL_ADDR
, offset
);
28 bcma_cc_read32(cc
, BCMA_CC_CHIPCTL_ADDR
);
29 value
= bcma_cc_read32(cc
, BCMA_CC_CHIPCTL_DATA
);
32 bcma_cc_write32(cc
, BCMA_CC_CHIPCTL_DATA
, value
);
33 bcma_cc_read32(cc
, BCMA_CC_CHIPCTL_DATA
);
36 static void bcma_pmu_pll_init(struct bcma_drv_cc
*cc
)
38 struct bcma_bus
*bus
= cc
->core
->bus
;
40 switch (bus
->chipinfo
.id
) {
47 pr_err("PLL init unknown for device 0x%04X\n",
52 static void bcma_pmu_resources_init(struct bcma_drv_cc
*cc
)
54 struct bcma_bus
*bus
= cc
->core
->bus
;
55 u32 min_msk
= 0, max_msk
= 0;
57 switch (bus
->chipinfo
.id
) {
66 pr_err("PMU resource config unknown for device 0x%04X\n",
70 /* Set the resource masks. */
72 bcma_cc_write32(cc
, BCMA_CC_PMU_MINRES_MSK
, min_msk
);
74 bcma_cc_write32(cc
, BCMA_CC_PMU_MAXRES_MSK
, max_msk
);
77 void bcma_pmu_swreg_init(struct bcma_drv_cc
*cc
)
79 struct bcma_bus
*bus
= cc
->core
->bus
;
81 switch (bus
->chipinfo
.id
) {
88 pr_err("PMU switch/regulators init unknown for device "
89 "0x%04X\n", bus
->chipinfo
.id
);
93 /* Disable to allow reading SPROM. Don't know the adventages of enabling it. */
94 void bcma_chipco_bcm4331_ext_pa_lines_ctl(struct bcma_drv_cc
*cc
, bool enable
)
96 struct bcma_bus
*bus
= cc
->core
->bus
;
99 val
= bcma_cc_read32(cc
, BCMA_CC_CHIPCTL
);
101 val
|= BCMA_CHIPCTL_4331_EXTPA_EN
;
102 if (bus
->chipinfo
.pkg
== 9 || bus
->chipinfo
.pkg
== 11)
103 val
|= BCMA_CHIPCTL_4331_EXTPA_ON_GPIO2_5
;
105 val
&= ~BCMA_CHIPCTL_4331_EXTPA_EN
;
106 val
&= ~BCMA_CHIPCTL_4331_EXTPA_ON_GPIO2_5
;
108 bcma_cc_write32(cc
, BCMA_CC_CHIPCTL
, val
);
111 void bcma_pmu_workarounds(struct bcma_drv_cc
*cc
)
113 struct bcma_bus
*bus
= cc
->core
->bus
;
115 switch (bus
->chipinfo
.id
) {
117 bcma_chipco_chipctl_maskset(cc
, 0, ~0, 0x7);
120 /* BCM4331 workaround is SPROM-related, we put it in sprom.c */
123 if (bus
->chipinfo
.rev
== 0) {
124 pr_err("Workarounds for 43224 rev 0 not fully "
126 bcma_chipco_chipctl_maskset(cc
, 0, ~0, 0x00F000F0);
128 bcma_chipco_chipctl_maskset(cc
, 0, ~0, 0xF0);
134 pr_err("Workarounds unknown for device 0x%04X\n",
139 void bcma_pmu_init(struct bcma_drv_cc
*cc
)
143 pmucap
= bcma_cc_read32(cc
, BCMA_CC_PMU_CAP
);
144 cc
->pmu
.rev
= (pmucap
& BCMA_CC_PMU_CAP_REVISION
);
146 pr_debug("Found rev %u PMU (capabilities 0x%08X)\n", cc
->pmu
.rev
,
149 if (cc
->pmu
.rev
== 1)
150 bcma_cc_mask32(cc
, BCMA_CC_PMU_CTL
,
151 ~BCMA_CC_PMU_CTL_NOILPONW
);
153 bcma_cc_set32(cc
, BCMA_CC_PMU_CTL
,
154 BCMA_CC_PMU_CTL_NOILPONW
);
156 if (cc
->core
->id
.id
== 0x4329 && cc
->core
->id
.rev
== 2)
157 pr_err("Fix for 4329b0 bad LPOM state not implemented!\n");
159 bcma_pmu_pll_init(cc
);
160 bcma_pmu_resources_init(cc
);
161 bcma_pmu_swreg_init(cc
);
162 bcma_pmu_workarounds(cc
);
165 u32
bcma_pmu_alp_clock(struct bcma_drv_cc
*cc
)
167 struct bcma_bus
*bus
= cc
->core
->bus
;
169 switch (bus
->chipinfo
.id
) {
184 pr_warn("No ALP clock specified for %04X device, "
185 "pmu rev. %d, using default %d Hz\n",
186 bus
->chipinfo
.id
, cc
->pmu
.rev
, BCMA_CC_PMU_ALP_CLOCK
);
188 return BCMA_CC_PMU_ALP_CLOCK
;
191 /* Find the output of the "m" pll divider given pll controls that start with
192 * pllreg "pll0" i.e. 12 for main 6 for phy, 0 for misc.
194 static u32
bcma_pmu_clock(struct bcma_drv_cc
*cc
, u32 pll0
, u32 m
)
196 u32 tmp
, div
, ndiv
, p1
, p2
, fc
;
197 struct bcma_bus
*bus
= cc
->core
->bus
;
199 BUG_ON((pll0
& 3) || (pll0
> BCMA_CC_PMU4716_MAINPLL_PLL0
));
203 if (bus
->chipinfo
.id
== 0x5357 || bus
->chipinfo
.id
== 0x4749) {
204 /* Detect failure in clock setting */
205 tmp
= bcma_cc_read32(cc
, BCMA_CC_CHIPSTAT
);
207 return 133 * 1000000;
210 tmp
= bcma_chipco_pll_read(cc
, pll0
+ BCMA_CC_PPL_P1P2_OFF
);
211 p1
= (tmp
& BCMA_CC_PPL_P1_MASK
) >> BCMA_CC_PPL_P1_SHIFT
;
212 p2
= (tmp
& BCMA_CC_PPL_P2_MASK
) >> BCMA_CC_PPL_P2_SHIFT
;
214 tmp
= bcma_chipco_pll_read(cc
, pll0
+ BCMA_CC_PPL_M14_OFF
);
215 div
= (tmp
>> ((m
- 1) * BCMA_CC_PPL_MDIV_WIDTH
)) &
216 BCMA_CC_PPL_MDIV_MASK
;
218 tmp
= bcma_chipco_pll_read(cc
, pll0
+ BCMA_CC_PPL_NM5_OFF
);
219 ndiv
= (tmp
& BCMA_CC_PPL_NDIV_MASK
) >> BCMA_CC_PPL_NDIV_SHIFT
;
221 /* Do calculation in Mhz */
222 fc
= bcma_pmu_alp_clock(cc
) / 1000000;
223 fc
= (p1
* ndiv
* fc
) / p2
;
225 /* Return clock in Hertz */
226 return (fc
/ div
) * 1000000;
229 /* query bus clock frequency for PMU-enabled chipcommon */
230 u32
bcma_pmu_get_clockcontrol(struct bcma_drv_cc
*cc
)
232 struct bcma_bus
*bus
= cc
->core
->bus
;
234 switch (bus
->chipinfo
.id
) {
238 return bcma_pmu_clock(cc
, BCMA_CC_PMU4716_MAINPLL_PLL0
,
239 BCMA_CC_PMU5_MAINPLL_SSB
);
241 return bcma_pmu_clock(cc
, BCMA_CC_PMU5356_MAINPLL_PLL0
,
242 BCMA_CC_PMU5_MAINPLL_SSB
);
245 return bcma_pmu_clock(cc
, BCMA_CC_PMU5357_MAINPLL_PLL0
,
246 BCMA_CC_PMU5_MAINPLL_SSB
);
248 return bcma_pmu_clock(cc
, BCMA_CC_PMU4706_MAINPLL_PLL0
,
249 BCMA_CC_PMU5_MAINPLL_SSB
);
253 pr_warn("No backplane clock specified for %04X device, "
254 "pmu rev. %d, using default %d Hz\n",
255 bus
->chipinfo
.id
, cc
->pmu
.rev
, BCMA_CC_PMU_HT_CLOCK
);
257 return BCMA_CC_PMU_HT_CLOCK
;
260 /* query cpu clock frequency for PMU-enabled chipcommon */
261 u32
bcma_pmu_get_clockcpu(struct bcma_drv_cc
*cc
)
263 struct bcma_bus
*bus
= cc
->core
->bus
;
265 if (bus
->chipinfo
.id
== 53572)
268 if (cc
->pmu
.rev
>= 5) {
270 switch (bus
->chipinfo
.id
) {
272 pll
= BCMA_CC_PMU5356_MAINPLL_PLL0
;
276 pll
= BCMA_CC_PMU5357_MAINPLL_PLL0
;
279 pll
= BCMA_CC_PMU4716_MAINPLL_PLL0
;
283 /* TODO: if (bus->chipinfo.id == 0x5300)
284 return si_4706_pmu_clock(sih, osh, cc, PMU4706_MAINPLL_PLL0, PMU5_MAINPLL_CPU); */
285 return bcma_pmu_clock(cc
, pll
, BCMA_CC_PMU5_MAINPLL_CPU
);
288 return bcma_pmu_get_clockcontrol(cc
);