bcma: add PCI ID for BCM43224
[deliverable/linux.git] / drivers / bcma / driver_chipcommon_pmu.c
CommitLineData
8369ae33
RM
1/*
2 * Broadcom specific AMBA
3 * ChipCommon Power Management Unit driver
4 *
eb032b98 5 * Copyright 2009, Michael Buesch <m@bues.ch>
8369ae33
RM
6 * Copyright 2007, Broadcom Corporation
7 *
8 * Licensed under the GNU/GPL. See COPYING for details.
9 */
10
11#include "bcma_private.h"
44a8e377 12#include <linux/export.h>
8369ae33
RM
13#include <linux/bcma/bcma.h>
14
908debc8
HM
15static u32 bcma_chipco_pll_read(struct bcma_drv_cc *cc, u32 offset)
16{
17 bcma_cc_write32(cc, BCMA_CC_PLLCTL_ADDR, offset);
18 bcma_cc_read32(cc, BCMA_CC_PLLCTL_ADDR);
19 return bcma_cc_read32(cc, BCMA_CC_PLLCTL_DATA);
20}
21
3861b2c5 22void bcma_chipco_pll_write(struct bcma_drv_cc *cc, u32 offset, u32 value)
8369ae33 23{
3861b2c5
RM
24 bcma_cc_write32(cc, BCMA_CC_PLLCTL_ADDR, offset);
25 bcma_cc_read32(cc, BCMA_CC_PLLCTL_ADDR);
26 bcma_cc_write32(cc, BCMA_CC_PLLCTL_DATA, value);
27}
28EXPORT_SYMBOL_GPL(bcma_chipco_pll_write);
8369ae33 29
3861b2c5
RM
30void bcma_chipco_pll_maskset(struct bcma_drv_cc *cc, u32 offset, u32 mask,
31 u32 set)
32{
33 bcma_cc_write32(cc, BCMA_CC_PLLCTL_ADDR, offset);
34 bcma_cc_read32(cc, BCMA_CC_PLLCTL_ADDR);
35 bcma_cc_maskset32(cc, BCMA_CC_PLLCTL_DATA, mask, set);
36}
37EXPORT_SYMBOL_GPL(bcma_chipco_pll_maskset);
38
39void bcma_chipco_chipctl_maskset(struct bcma_drv_cc *cc,
40 u32 offset, u32 mask, u32 set)
41{
8369ae33
RM
42 bcma_cc_write32(cc, BCMA_CC_CHIPCTL_ADDR, offset);
43 bcma_cc_read32(cc, BCMA_CC_CHIPCTL_ADDR);
3861b2c5
RM
44 bcma_cc_maskset32(cc, BCMA_CC_CHIPCTL_DATA, mask, set);
45}
46EXPORT_SYMBOL_GPL(bcma_chipco_chipctl_maskset);
47
48void bcma_chipco_regctl_maskset(struct bcma_drv_cc *cc, u32 offset, u32 mask,
49 u32 set)
50{
51 bcma_cc_write32(cc, BCMA_CC_REGCTL_ADDR, offset);
52 bcma_cc_read32(cc, BCMA_CC_REGCTL_ADDR);
53 bcma_cc_maskset32(cc, BCMA_CC_REGCTL_DATA, mask, set);
8369ae33 54}
3861b2c5 55EXPORT_SYMBOL_GPL(bcma_chipco_regctl_maskset);
8369ae33
RM
56
57static void bcma_pmu_pll_init(struct bcma_drv_cc *cc)
58{
59 struct bcma_bus *bus = cc->core->bus;
60
61 switch (bus->chipinfo.id) {
4b4f5be2
HM
62 case BCMA_CHIP_ID_BCM4313:
63 case BCMA_CHIP_ID_BCM4331:
64 case BCMA_CHIP_ID_BCM43224:
65 case BCMA_CHIP_ID_BCM43225:
8369ae33
RM
66 break;
67 default:
68 pr_err("PLL init unknown for device 0x%04X\n",
69 bus->chipinfo.id);
70 }
71}
72
73static void bcma_pmu_resources_init(struct bcma_drv_cc *cc)
74{
75 struct bcma_bus *bus = cc->core->bus;
76 u32 min_msk = 0, max_msk = 0;
77
78 switch (bus->chipinfo.id) {
4b4f5be2 79 case BCMA_CHIP_ID_BCM4313:
8369ae33
RM
80 min_msk = 0x200D;
81 max_msk = 0xFFFF;
82 break;
4b4f5be2
HM
83 case BCMA_CHIP_ID_BCM4331:
84 case BCMA_CHIP_ID_BCM43224:
85 case BCMA_CHIP_ID_BCM43225:
8369ae33
RM
86 break;
87 default:
88 pr_err("PMU resource config unknown for device 0x%04X\n",
89 bus->chipinfo.id);
90 }
91
92 /* Set the resource masks. */
93 if (min_msk)
94 bcma_cc_write32(cc, BCMA_CC_PMU_MINRES_MSK, min_msk);
95 if (max_msk)
96 bcma_cc_write32(cc, BCMA_CC_PMU_MAXRES_MSK, max_msk);
97}
98
99void bcma_pmu_swreg_init(struct bcma_drv_cc *cc)
100{
101 struct bcma_bus *bus = cc->core->bus;
102
103 switch (bus->chipinfo.id) {
4b4f5be2
HM
104 case BCMA_CHIP_ID_BCM4313:
105 case BCMA_CHIP_ID_BCM4331:
106 case BCMA_CHIP_ID_BCM43224:
107 case BCMA_CHIP_ID_BCM43225:
8369ae33
RM
108 break;
109 default:
110 pr_err("PMU switch/regulators init unknown for device "
111 "0x%04X\n", bus->chipinfo.id);
112 }
113}
114
984e5bef
RM
115/* Disable to allow reading SPROM. Don't know the adventages of enabling it. */
116void bcma_chipco_bcm4331_ext_pa_lines_ctl(struct bcma_drv_cc *cc, bool enable)
117{
118 struct bcma_bus *bus = cc->core->bus;
119 u32 val;
120
121 val = bcma_cc_read32(cc, BCMA_CC_CHIPCTL);
122 if (enable) {
123 val |= BCMA_CHIPCTL_4331_EXTPA_EN;
124 if (bus->chipinfo.pkg == 9 || bus->chipinfo.pkg == 11)
125 val |= BCMA_CHIPCTL_4331_EXTPA_ON_GPIO2_5;
00eeedcf
HM
126 else if (bus->chipinfo.rev > 0)
127 val |= BCMA_CHIPCTL_4331_EXTPA_EN2;
984e5bef
RM
128 } else {
129 val &= ~BCMA_CHIPCTL_4331_EXTPA_EN;
00eeedcf 130 val &= ~BCMA_CHIPCTL_4331_EXTPA_EN2;
984e5bef
RM
131 val &= ~BCMA_CHIPCTL_4331_EXTPA_ON_GPIO2_5;
132 }
133 bcma_cc_write32(cc, BCMA_CC_CHIPCTL, val);
134}
135
8369ae33
RM
136void bcma_pmu_workarounds(struct bcma_drv_cc *cc)
137{
138 struct bcma_bus *bus = cc->core->bus;
139
140 switch (bus->chipinfo.id) {
4b4f5be2 141 case BCMA_CHIP_ID_BCM4313:
8369ae33
RM
142 bcma_chipco_chipctl_maskset(cc, 0, ~0, 0x7);
143 break;
4b4f5be2
HM
144 case BCMA_CHIP_ID_BCM4331:
145 case BCMA_CHIP_ID_BCM43431:
69aaedd3
SF
146 /* Ext PA lines must be enabled for tx on BCM4331 */
147 bcma_chipco_bcm4331_ext_pa_lines_ctl(cc, true);
8369ae33 148 break;
4b4f5be2 149 case BCMA_CHIP_ID_BCM43224:
8369ae33
RM
150 if (bus->chipinfo.rev == 0) {
151 pr_err("Workarounds for 43224 rev 0 not fully "
152 "implemented\n");
898f699e 153 bcma_chipco_chipctl_maskset(cc, 0, ~0, 0x00F000F0);
8369ae33
RM
154 } else {
155 bcma_chipco_chipctl_maskset(cc, 0, ~0, 0xF0);
156 }
157 break;
4b4f5be2 158 case BCMA_CHIP_ID_BCM43225:
91fa4b0a 159 break;
8369ae33
RM
160 default:
161 pr_err("Workarounds unknown for device 0x%04X\n",
162 bus->chipinfo.id);
163 }
164}
165
166void bcma_pmu_init(struct bcma_drv_cc *cc)
167{
168 u32 pmucap;
169
170 pmucap = bcma_cc_read32(cc, BCMA_CC_PMU_CAP);
171 cc->pmu.rev = (pmucap & BCMA_CC_PMU_CAP_REVISION);
172
173 pr_debug("Found rev %u PMU (capabilities 0x%08X)\n", cc->pmu.rev,
174 pmucap);
175
176 if (cc->pmu.rev == 1)
177 bcma_cc_mask32(cc, BCMA_CC_PMU_CTL,
178 ~BCMA_CC_PMU_CTL_NOILPONW);
179 else
180 bcma_cc_set32(cc, BCMA_CC_PMU_CTL,
181 BCMA_CC_PMU_CTL_NOILPONW);
182
8369ae33
RM
183 bcma_pmu_pll_init(cc);
184 bcma_pmu_resources_init(cc);
185 bcma_pmu_swreg_init(cc);
186 bcma_pmu_workarounds(cc);
187}
e3afe0e5
HM
188
189u32 bcma_pmu_alp_clock(struct bcma_drv_cc *cc)
190{
191 struct bcma_bus *bus = cc->core->bus;
192
193 switch (bus->chipinfo.id) {
4b4f5be2
HM
194 case BCMA_CHIP_ID_BCM4716:
195 case BCMA_CHIP_ID_BCM4748:
196 case BCMA_CHIP_ID_BCM47162:
197 case BCMA_CHIP_ID_BCM4313:
198 case BCMA_CHIP_ID_BCM5357:
199 case BCMA_CHIP_ID_BCM4749:
200 case BCMA_CHIP_ID_BCM53572:
e3afe0e5
HM
201 /* always 20Mhz */
202 return 20000 * 1000;
4b4f5be2
HM
203 case BCMA_CHIP_ID_BCM5356:
204 case BCMA_CHIP_ID_BCM4706:
e3afe0e5
HM
205 /* always 25Mhz */
206 return 25000 * 1000;
207 default:
208 pr_warn("No ALP clock specified for %04X device, "
209 "pmu rev. %d, using default %d Hz\n",
210 bus->chipinfo.id, cc->pmu.rev, BCMA_CC_PMU_ALP_CLOCK);
211 }
212 return BCMA_CC_PMU_ALP_CLOCK;
213}
908debc8
HM
214
215/* Find the output of the "m" pll divider given pll controls that start with
216 * pllreg "pll0" i.e. 12 for main 6 for phy, 0 for misc.
217 */
218static u32 bcma_pmu_clock(struct bcma_drv_cc *cc, u32 pll0, u32 m)
219{
220 u32 tmp, div, ndiv, p1, p2, fc;
221 struct bcma_bus *bus = cc->core->bus;
222
223 BUG_ON((pll0 & 3) || (pll0 > BCMA_CC_PMU4716_MAINPLL_PLL0));
224
225 BUG_ON(!m || m > 4);
226
4b4f5be2
HM
227 if (bus->chipinfo.id == BCMA_CHIP_ID_BCM5357 ||
228 bus->chipinfo.id == BCMA_CHIP_ID_BCM4749) {
908debc8
HM
229 /* Detect failure in clock setting */
230 tmp = bcma_cc_read32(cc, BCMA_CC_CHIPSTAT);
231 if (tmp & 0x40000)
232 return 133 * 1000000;
233 }
234
235 tmp = bcma_chipco_pll_read(cc, pll0 + BCMA_CC_PPL_P1P2_OFF);
236 p1 = (tmp & BCMA_CC_PPL_P1_MASK) >> BCMA_CC_PPL_P1_SHIFT;
237 p2 = (tmp & BCMA_CC_PPL_P2_MASK) >> BCMA_CC_PPL_P2_SHIFT;
238
239 tmp = bcma_chipco_pll_read(cc, pll0 + BCMA_CC_PPL_M14_OFF);
240 div = (tmp >> ((m - 1) * BCMA_CC_PPL_MDIV_WIDTH)) &
241 BCMA_CC_PPL_MDIV_MASK;
242
243 tmp = bcma_chipco_pll_read(cc, pll0 + BCMA_CC_PPL_NM5_OFF);
244 ndiv = (tmp & BCMA_CC_PPL_NDIV_MASK) >> BCMA_CC_PPL_NDIV_SHIFT;
245
246 /* Do calculation in Mhz */
247 fc = bcma_pmu_alp_clock(cc) / 1000000;
248 fc = (p1 * ndiv * fc) / p2;
249
250 /* Return clock in Hertz */
251 return (fc / div) * 1000000;
252}
253
254/* query bus clock frequency for PMU-enabled chipcommon */
255u32 bcma_pmu_get_clockcontrol(struct bcma_drv_cc *cc)
256{
257 struct bcma_bus *bus = cc->core->bus;
258
259 switch (bus->chipinfo.id) {
4b4f5be2
HM
260 case BCMA_CHIP_ID_BCM4716:
261 case BCMA_CHIP_ID_BCM4748:
262 case BCMA_CHIP_ID_BCM47162:
908debc8
HM
263 return bcma_pmu_clock(cc, BCMA_CC_PMU4716_MAINPLL_PLL0,
264 BCMA_CC_PMU5_MAINPLL_SSB);
4b4f5be2 265 case BCMA_CHIP_ID_BCM5356:
908debc8
HM
266 return bcma_pmu_clock(cc, BCMA_CC_PMU5356_MAINPLL_PLL0,
267 BCMA_CC_PMU5_MAINPLL_SSB);
4b4f5be2
HM
268 case BCMA_CHIP_ID_BCM5357:
269 case BCMA_CHIP_ID_BCM4749:
908debc8
HM
270 return bcma_pmu_clock(cc, BCMA_CC_PMU5357_MAINPLL_PLL0,
271 BCMA_CC_PMU5_MAINPLL_SSB);
4b4f5be2 272 case BCMA_CHIP_ID_BCM4706:
908debc8
HM
273 return bcma_pmu_clock(cc, BCMA_CC_PMU4706_MAINPLL_PLL0,
274 BCMA_CC_PMU5_MAINPLL_SSB);
4b4f5be2 275 case BCMA_CHIP_ID_BCM53572:
908debc8
HM
276 return 75000000;
277 default:
278 pr_warn("No backplane clock specified for %04X device, "
279 "pmu rev. %d, using default %d Hz\n",
280 bus->chipinfo.id, cc->pmu.rev, BCMA_CC_PMU_HT_CLOCK);
281 }
282 return BCMA_CC_PMU_HT_CLOCK;
283}
284
285/* query cpu clock frequency for PMU-enabled chipcommon */
286u32 bcma_pmu_get_clockcpu(struct bcma_drv_cc *cc)
287{
288 struct bcma_bus *bus = cc->core->bus;
289
4b4f5be2 290 if (bus->chipinfo.id == BCMA_CHIP_ID_BCM53572)
908debc8
HM
291 return 300000000;
292
293 if (cc->pmu.rev >= 5) {
294 u32 pll;
295 switch (bus->chipinfo.id) {
4b4f5be2 296 case BCMA_CHIP_ID_BCM5356:
908debc8
HM
297 pll = BCMA_CC_PMU5356_MAINPLL_PLL0;
298 break;
4b4f5be2
HM
299 case BCMA_CHIP_ID_BCM5357:
300 case BCMA_CHIP_ID_BCM4749:
908debc8
HM
301 pll = BCMA_CC_PMU5357_MAINPLL_PLL0;
302 break;
303 default:
304 pll = BCMA_CC_PMU4716_MAINPLL_PLL0;
305 break;
306 }
307
4b4f5be2 308 /* TODO: if (bus->chipinfo.id == BCMA_CHIP_ID_BCM4706)
908debc8
HM
309 return si_4706_pmu_clock(sih, osh, cc, PMU4706_MAINPLL_PLL0, PMU5_MAINPLL_CPU); */
310 return bcma_pmu_clock(cc, pll, BCMA_CC_PMU5_MAINPLL_CPU);
311 }
312
313 return bcma_pmu_get_clockcontrol(cc);
314}
This page took 0.103765 seconds and 5 git commands to generate.