blob: edca73af3cc089fd342573ec0fca20bcc5ddc677 [file] [log] [blame]
Rafał Miłecki8369ae32011-05-09 18:56:46 +02001/*
2 * Broadcom specific AMBA
3 * ChipCommon Power Management Unit driver
4 *
Michael Büscheb032b92011-07-04 20:50:05 +02005 * Copyright 2009, Michael Buesch <m@bues.ch>
Hauke Mehrtensc586e102012-06-30 01:44:44 +02006 * Copyright 2007, 2011, Broadcom Corporation
7 * Copyright 2011, 2012, Hauke Mehrtens <hauke@hauke-m.de>
Rafał Miłecki8369ae32011-05-09 18:56:46 +02008 *
9 * Licensed under the GNU/GPL. See COPYING for details.
10 */
11
12#include "bcma_private.h"
Paul Gortmaker44a8e372011-07-27 21:21:04 -040013#include <linux/export.h>
Rafał Miłecki8369ae32011-05-09 18:56:46 +020014#include <linux/bcma/bcma.h>
15
Rafał Miłecki8d4b9e32012-11-12 13:03:20 +010016u32 bcma_chipco_pll_read(struct bcma_drv_cc *cc, u32 offset)
Hauke Mehrtens908debc2011-07-23 01:20:11 +020017{
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);
21}
Rafał Miłecki8d4b9e32012-11-12 13:03:20 +010022EXPORT_SYMBOL_GPL(bcma_chipco_pll_read);
Hauke Mehrtens908debc2011-07-23 01:20:11 +020023
Rafał Miłecki3861b2c2011-09-16 12:33:58 +020024void bcma_chipco_pll_write(struct bcma_drv_cc *cc, u32 offset, u32 value)
Rafał Miłecki8369ae32011-05-09 18:56:46 +020025{
Rafał Miłecki3861b2c2011-09-16 12:33:58 +020026 bcma_cc_write32(cc, BCMA_CC_PLLCTL_ADDR, offset);
27 bcma_cc_read32(cc, BCMA_CC_PLLCTL_ADDR);
28 bcma_cc_write32(cc, BCMA_CC_PLLCTL_DATA, value);
29}
30EXPORT_SYMBOL_GPL(bcma_chipco_pll_write);
Rafał Miłecki8369ae32011-05-09 18:56:46 +020031
Rafał Miłecki3861b2c2011-09-16 12:33:58 +020032void bcma_chipco_pll_maskset(struct bcma_drv_cc *cc, u32 offset, u32 mask,
33 u32 set)
34{
35 bcma_cc_write32(cc, BCMA_CC_PLLCTL_ADDR, offset);
36 bcma_cc_read32(cc, BCMA_CC_PLLCTL_ADDR);
37 bcma_cc_maskset32(cc, BCMA_CC_PLLCTL_DATA, mask, set);
38}
39EXPORT_SYMBOL_GPL(bcma_chipco_pll_maskset);
40
41void bcma_chipco_chipctl_maskset(struct bcma_drv_cc *cc,
42 u32 offset, u32 mask, u32 set)
43{
Rafał Miłecki8369ae32011-05-09 18:56:46 +020044 bcma_cc_write32(cc, BCMA_CC_CHIPCTL_ADDR, offset);
45 bcma_cc_read32(cc, BCMA_CC_CHIPCTL_ADDR);
Rafał Miłecki3861b2c2011-09-16 12:33:58 +020046 bcma_cc_maskset32(cc, BCMA_CC_CHIPCTL_DATA, mask, set);
Rafał Miłecki8369ae32011-05-09 18:56:46 +020047}
Rafał Miłecki3861b2c2011-09-16 12:33:58 +020048EXPORT_SYMBOL_GPL(bcma_chipco_chipctl_maskset);
49
50void bcma_chipco_regctl_maskset(struct bcma_drv_cc *cc, u32 offset, u32 mask,
51 u32 set)
52{
53 bcma_cc_write32(cc, BCMA_CC_REGCTL_ADDR, offset);
54 bcma_cc_read32(cc, BCMA_CC_REGCTL_ADDR);
55 bcma_cc_maskset32(cc, BCMA_CC_REGCTL_DATA, mask, set);
56}
57EXPORT_SYMBOL_GPL(bcma_chipco_regctl_maskset);
Rafał Miłecki8369ae32011-05-09 18:56:46 +020058
Rafał Miłecki8369ae32011-05-09 18:56:46 +020059static void bcma_pmu_resources_init(struct bcma_drv_cc *cc)
60{
61 struct bcma_bus *bus = cc->core->bus;
62 u32 min_msk = 0, max_msk = 0;
63
64 switch (bus->chipinfo.id) {
Hauke Mehrtens4b4f5be2012-06-30 01:44:38 +020065 case BCMA_CHIP_ID_BCM4313:
Rafał Miłecki8369ae32011-05-09 18:56:46 +020066 min_msk = 0x200D;
67 max_msk = 0xFFFF;
68 break;
Rafał Miłecki8369ae32011-05-09 18:56:46 +020069 default:
Rafał Miłecki3d9d8af2012-07-05 22:07:32 +020070 bcma_debug(bus, "PMU resource config unknown or not needed for device 0x%04X\n",
71 bus->chipinfo.id);
Rafał Miłecki8369ae32011-05-09 18:56:46 +020072 }
73
74 /* Set the resource masks. */
75 if (min_msk)
76 bcma_cc_write32(cc, BCMA_CC_PMU_MINRES_MSK, min_msk);
77 if (max_msk)
78 bcma_cc_write32(cc, BCMA_CC_PMU_MAXRES_MSK, max_msk);
Hauke Mehrtens4795f092012-06-30 01:44:45 +020079
Rafał Miłecki1fd41a62012-09-25 10:17:22 +020080 /*
81 * Add some delay; allow resources to come up and settle.
82 * Delay is required for SoC (early init).
83 */
Hauke Mehrtens4795f092012-06-30 01:44:45 +020084 mdelay(2);
Rafał Miłecki8369ae32011-05-09 18:56:46 +020085}
86
Rafał Miłecki984e5be2011-08-11 23:46:44 +020087/* Disable to allow reading SPROM. Don't know the adventages of enabling it. */
88void bcma_chipco_bcm4331_ext_pa_lines_ctl(struct bcma_drv_cc *cc, bool enable)
89{
90 struct bcma_bus *bus = cc->core->bus;
91 u32 val;
92
93 val = bcma_cc_read32(cc, BCMA_CC_CHIPCTL);
94 if (enable) {
95 val |= BCMA_CHIPCTL_4331_EXTPA_EN;
96 if (bus->chipinfo.pkg == 9 || bus->chipinfo.pkg == 11)
97 val |= BCMA_CHIPCTL_4331_EXTPA_ON_GPIO2_5;
Hauke Mehrtens00eeedc2012-06-30 01:44:37 +020098 else if (bus->chipinfo.rev > 0)
99 val |= BCMA_CHIPCTL_4331_EXTPA_EN2;
Rafał Miłecki984e5be2011-08-11 23:46:44 +0200100 } else {
101 val &= ~BCMA_CHIPCTL_4331_EXTPA_EN;
Hauke Mehrtens00eeedc2012-06-30 01:44:37 +0200102 val &= ~BCMA_CHIPCTL_4331_EXTPA_EN2;
Rafał Miłecki984e5be2011-08-11 23:46:44 +0200103 val &= ~BCMA_CHIPCTL_4331_EXTPA_ON_GPIO2_5;
104 }
105 bcma_cc_write32(cc, BCMA_CC_CHIPCTL, val);
106}
107
Hauke Mehrtens94f34572012-08-05 16:54:41 +0200108static void bcma_pmu_workarounds(struct bcma_drv_cc *cc)
Rafał Miłecki8369ae32011-05-09 18:56:46 +0200109{
110 struct bcma_bus *bus = cc->core->bus;
111
112 switch (bus->chipinfo.id) {
Hauke Mehrtens4b4f5be2012-06-30 01:44:38 +0200113 case BCMA_CHIP_ID_BCM4313:
Hauke Mehrtensb9562542012-06-30 01:44:41 +0200114 /* enable 12 mA drive strenth for 4313 and set chipControl
115 register bit 1 */
116 bcma_chipco_chipctl_maskset(cc, 0,
Hauke Mehrtens1f03bf02012-07-25 23:08:54 +0200117 ~BCMA_CCTRL_4313_12MA_LED_DRIVE,
Hauke Mehrtensb9562542012-06-30 01:44:41 +0200118 BCMA_CCTRL_4313_12MA_LED_DRIVE);
Rafał Miłecki8369ae32011-05-09 18:56:46 +0200119 break;
Hauke Mehrtens4b4f5be2012-06-30 01:44:38 +0200120 case BCMA_CHIP_ID_BCM4331:
121 case BCMA_CHIP_ID_BCM43431:
Seth Forshee69aaedd2012-06-01 09:13:17 -0500122 /* Ext PA lines must be enabled for tx on BCM4331 */
123 bcma_chipco_bcm4331_ext_pa_lines_ctl(cc, true);
Rafał Miłecki8369ae32011-05-09 18:56:46 +0200124 break;
Hauke Mehrtens4b4f5be2012-06-30 01:44:38 +0200125 case BCMA_CHIP_ID_BCM43224:
Hauke Mehrtensb9562542012-06-30 01:44:41 +0200126 case BCMA_CHIP_ID_BCM43421:
127 /* enable 12 mA drive strenth for 43224 and set chipControl
128 register bit 15 */
Rafał Miłecki8369ae32011-05-09 18:56:46 +0200129 if (bus->chipinfo.rev == 0) {
Hauke Mehrtensb9562542012-06-30 01:44:41 +0200130 bcma_cc_maskset32(cc, BCMA_CC_CHIPCTL,
Hauke Mehrtens1f03bf02012-07-25 23:08:54 +0200131 ~BCMA_CCTRL_43224_GPIO_TOGGLE,
Hauke Mehrtensb9562542012-06-30 01:44:41 +0200132 BCMA_CCTRL_43224_GPIO_TOGGLE);
133 bcma_chipco_chipctl_maskset(cc, 0,
Hauke Mehrtens1f03bf02012-07-25 23:08:54 +0200134 ~BCMA_CCTRL_43224A0_12MA_LED_DRIVE,
Hauke Mehrtensb9562542012-06-30 01:44:41 +0200135 BCMA_CCTRL_43224A0_12MA_LED_DRIVE);
Rafał Miłecki8369ae32011-05-09 18:56:46 +0200136 } else {
Hauke Mehrtensb9562542012-06-30 01:44:41 +0200137 bcma_chipco_chipctl_maskset(cc, 0,
Hauke Mehrtens1f03bf02012-07-25 23:08:54 +0200138 ~BCMA_CCTRL_43224B0_12MA_LED_DRIVE,
Hauke Mehrtensb9562542012-06-30 01:44:41 +0200139 BCMA_CCTRL_43224B0_12MA_LED_DRIVE);
Rafał Miłecki8369ae32011-05-09 18:56:46 +0200140 }
141 break;
Rafał Miłecki8369ae32011-05-09 18:56:46 +0200142 default:
Rafał Miłecki3d9d8af2012-07-05 22:07:32 +0200143 bcma_debug(bus, "Workarounds unknown or not needed for device 0x%04X\n",
144 bus->chipinfo.id);
Rafał Miłecki8369ae32011-05-09 18:56:46 +0200145 }
146}
147
Hauke Mehrtens49655bb2012-09-29 20:29:49 +0200148void bcma_pmu_early_init(struct bcma_drv_cc *cc)
Rafał Miłecki8369ae32011-05-09 18:56:46 +0200149{
150 u32 pmucap;
151
152 pmucap = bcma_cc_read32(cc, BCMA_CC_PMU_CAP);
153 cc->pmu.rev = (pmucap & BCMA_CC_PMU_CAP_REVISION);
154
Rafał Miłecki3d9d8af2012-07-05 22:07:32 +0200155 bcma_debug(cc->core->bus, "Found rev %u PMU (capabilities 0x%08X)\n",
156 cc->pmu.rev, pmucap);
Hauke Mehrtens49655bb2012-09-29 20:29:49 +0200157}
Rafał Miłecki8369ae32011-05-09 18:56:46 +0200158
Hauke Mehrtens49655bb2012-09-29 20:29:49 +0200159void bcma_pmu_init(struct bcma_drv_cc *cc)
160{
Rafał Miłecki8369ae32011-05-09 18:56:46 +0200161 if (cc->pmu.rev == 1)
162 bcma_cc_mask32(cc, BCMA_CC_PMU_CTL,
163 ~BCMA_CC_PMU_CTL_NOILPONW);
164 else
165 bcma_cc_set32(cc, BCMA_CC_PMU_CTL,
166 BCMA_CC_PMU_CTL_NOILPONW);
167
Rafał Miłecki8369ae32011-05-09 18:56:46 +0200168 bcma_pmu_resources_init(cc);
Rafał Miłecki8369ae32011-05-09 18:56:46 +0200169 bcma_pmu_workarounds(cc);
170}
Hauke Mehrtense3afe0e2011-07-23 01:20:10 +0200171
Rafał Miłecki5b5ac412012-12-07 12:56:56 +0100172u32 bcma_pmu_get_alp_clock(struct bcma_drv_cc *cc)
Hauke Mehrtense3afe0e2011-07-23 01:20:10 +0200173{
174 struct bcma_bus *bus = cc->core->bus;
175
176 switch (bus->chipinfo.id) {
Hauke Mehrtens4b4f5be2012-06-30 01:44:38 +0200177 case BCMA_CHIP_ID_BCM4313:
Hauke Mehrtensd6b688c2013-03-27 17:23:10 +0100178 case BCMA_CHIP_ID_BCM43224:
179 case BCMA_CHIP_ID_BCM43225:
180 case BCMA_CHIP_ID_BCM43227:
181 case BCMA_CHIP_ID_BCM43228:
182 case BCMA_CHIP_ID_BCM4331:
183 case BCMA_CHIP_ID_BCM43421:
184 case BCMA_CHIP_ID_BCM43428:
185 case BCMA_CHIP_ID_BCM43431:
186 case BCMA_CHIP_ID_BCM4716:
187 case BCMA_CHIP_ID_BCM47162:
188 case BCMA_CHIP_ID_BCM4748:
Hauke Mehrtens4b4f5be2012-06-30 01:44:38 +0200189 case BCMA_CHIP_ID_BCM4749:
Hauke Mehrtensd6b688c2013-03-27 17:23:10 +0100190 case BCMA_CHIP_ID_BCM5357:
Hauke Mehrtens4b4f5be2012-06-30 01:44:38 +0200191 case BCMA_CHIP_ID_BCM53572:
Hauke Mehrtensd6b688c2013-03-27 17:23:10 +0100192 case BCMA_CHIP_ID_BCM6362:
Hauke Mehrtense3afe0e2011-07-23 01:20:10 +0200193 /* always 20Mhz */
194 return 20000 * 1000;
Hauke Mehrtens4b4f5be2012-06-30 01:44:38 +0200195 case BCMA_CHIP_ID_BCM4706:
Hauke Mehrtensd6b688c2013-03-27 17:23:10 +0100196 case BCMA_CHIP_ID_BCM5356:
Hauke Mehrtense3afe0e2011-07-23 01:20:10 +0200197 /* always 25Mhz */
198 return 25000 * 1000;
Hauke Mehrtensd6b688c2013-03-27 17:23:10 +0100199 case BCMA_CHIP_ID_BCM43460:
200 case BCMA_CHIP_ID_BCM4352:
201 case BCMA_CHIP_ID_BCM4360:
202 if (cc->status & BCMA_CC_CHIPST_4360_XTAL_40MZ)
203 return 40000 * 1000;
204 else
205 return 20000 * 1000;
Hauke Mehrtense3afe0e2011-07-23 01:20:10 +0200206 default:
Rafał Miłecki3d9d8af2012-07-05 22:07:32 +0200207 bcma_warn(bus, "No ALP clock specified for %04X device, pmu rev. %d, using default %d Hz\n",
208 bus->chipinfo.id, cc->pmu.rev, BCMA_CC_PMU_ALP_CLOCK);
Hauke Mehrtense3afe0e2011-07-23 01:20:10 +0200209 }
210 return BCMA_CC_PMU_ALP_CLOCK;
211}
Hauke Mehrtens908debc2011-07-23 01:20:11 +0200212
213/* Find the output of the "m" pll divider given pll controls that start with
214 * pllreg "pll0" i.e. 12 for main 6 for phy, 0 for misc.
215 */
Rafał Miłecki5b5ac412012-12-07 12:56:56 +0100216static u32 bcma_pmu_pll_clock(struct bcma_drv_cc *cc, u32 pll0, u32 m)
Hauke Mehrtens908debc2011-07-23 01:20:11 +0200217{
218 u32 tmp, div, ndiv, p1, p2, fc;
219 struct bcma_bus *bus = cc->core->bus;
220
221 BUG_ON((pll0 & 3) || (pll0 > BCMA_CC_PMU4716_MAINPLL_PLL0));
222
223 BUG_ON(!m || m > 4);
224
Hauke Mehrtens4b4f5be2012-06-30 01:44:38 +0200225 if (bus->chipinfo.id == BCMA_CHIP_ID_BCM5357 ||
226 bus->chipinfo.id == BCMA_CHIP_ID_BCM4749) {
Hauke Mehrtens908debc2011-07-23 01:20:11 +0200227 /* Detect failure in clock setting */
228 tmp = bcma_cc_read32(cc, BCMA_CC_CHIPSTAT);
229 if (tmp & 0x40000)
230 return 133 * 1000000;
231 }
232
233 tmp = bcma_chipco_pll_read(cc, pll0 + BCMA_CC_PPL_P1P2_OFF);
234 p1 = (tmp & BCMA_CC_PPL_P1_MASK) >> BCMA_CC_PPL_P1_SHIFT;
235 p2 = (tmp & BCMA_CC_PPL_P2_MASK) >> BCMA_CC_PPL_P2_SHIFT;
236
237 tmp = bcma_chipco_pll_read(cc, pll0 + BCMA_CC_PPL_M14_OFF);
238 div = (tmp >> ((m - 1) * BCMA_CC_PPL_MDIV_WIDTH)) &
239 BCMA_CC_PPL_MDIV_MASK;
240
241 tmp = bcma_chipco_pll_read(cc, pll0 + BCMA_CC_PPL_NM5_OFF);
242 ndiv = (tmp & BCMA_CC_PPL_NDIV_MASK) >> BCMA_CC_PPL_NDIV_SHIFT;
243
244 /* Do calculation in Mhz */
Rafał Miłecki5b5ac412012-12-07 12:56:56 +0100245 fc = bcma_pmu_get_alp_clock(cc) / 1000000;
Hauke Mehrtens908debc2011-07-23 01:20:11 +0200246 fc = (p1 * ndiv * fc) / p2;
247
248 /* Return clock in Hertz */
249 return (fc / div) * 1000000;
250}
251
Rafał Miłecki5b5ac412012-12-07 12:56:56 +0100252static u32 bcma_pmu_pll_clock_bcm4706(struct bcma_drv_cc *cc, u32 pll0, u32 m)
Hauke Mehrtens650cef382012-07-09 22:03:10 +0200253{
254 u32 tmp, ndiv, p1div, p2div;
255 u32 clock;
256
257 BUG_ON(!m || m > 4);
258
259 /* Get N, P1 and P2 dividers to determine CPU clock */
260 tmp = bcma_chipco_pll_read(cc, pll0 + BCMA_CC_PMU6_4706_PROCPLL_OFF);
261 ndiv = (tmp & BCMA_CC_PMU6_4706_PROC_NDIV_INT_MASK)
262 >> BCMA_CC_PMU6_4706_PROC_NDIV_INT_SHIFT;
263 p1div = (tmp & BCMA_CC_PMU6_4706_PROC_P1DIV_MASK)
264 >> BCMA_CC_PMU6_4706_PROC_P1DIV_SHIFT;
265 p2div = (tmp & BCMA_CC_PMU6_4706_PROC_P2DIV_MASK)
266 >> BCMA_CC_PMU6_4706_PROC_P2DIV_SHIFT;
267
268 tmp = bcma_cc_read32(cc, BCMA_CC_CHIPSTAT);
269 if (tmp & BCMA_CC_CHIPST_4706_PKG_OPTION)
270 /* Low cost bonding: Fixed reference clock 25MHz and m = 4 */
271 clock = (25000000 / 4) * ndiv * p2div / p1div;
272 else
273 /* Fixed reference clock 25MHz and m = 2 */
274 clock = (25000000 / 2) * ndiv * p2div / p1div;
275
276 if (m == BCMA_CC_PMU5_MAINPLL_SSB)
277 clock = clock / 4;
278
279 return clock;
280}
281
Hauke Mehrtens908debc2011-07-23 01:20:11 +0200282/* query bus clock frequency for PMU-enabled chipcommon */
Rafał Miłeckidd4544f2013-01-08 20:06:23 +0000283u32 bcma_pmu_get_bus_clock(struct bcma_drv_cc *cc)
Hauke Mehrtens908debc2011-07-23 01:20:11 +0200284{
285 struct bcma_bus *bus = cc->core->bus;
286
287 switch (bus->chipinfo.id) {
Hauke Mehrtens4b4f5be2012-06-30 01:44:38 +0200288 case BCMA_CHIP_ID_BCM4716:
289 case BCMA_CHIP_ID_BCM4748:
290 case BCMA_CHIP_ID_BCM47162:
Rafał Miłecki5b5ac412012-12-07 12:56:56 +0100291 return bcma_pmu_pll_clock(cc, BCMA_CC_PMU4716_MAINPLL_PLL0,
292 BCMA_CC_PMU5_MAINPLL_SSB);
Hauke Mehrtens4b4f5be2012-06-30 01:44:38 +0200293 case BCMA_CHIP_ID_BCM5356:
Rafał Miłecki5b5ac412012-12-07 12:56:56 +0100294 return bcma_pmu_pll_clock(cc, BCMA_CC_PMU5356_MAINPLL_PLL0,
295 BCMA_CC_PMU5_MAINPLL_SSB);
Hauke Mehrtens4b4f5be2012-06-30 01:44:38 +0200296 case BCMA_CHIP_ID_BCM5357:
297 case BCMA_CHIP_ID_BCM4749:
Rafał Miłecki5b5ac412012-12-07 12:56:56 +0100298 return bcma_pmu_pll_clock(cc, BCMA_CC_PMU5357_MAINPLL_PLL0,
299 BCMA_CC_PMU5_MAINPLL_SSB);
Hauke Mehrtens4b4f5be2012-06-30 01:44:38 +0200300 case BCMA_CHIP_ID_BCM4706:
Rafał Miłecki5b5ac412012-12-07 12:56:56 +0100301 return bcma_pmu_pll_clock_bcm4706(cc,
302 BCMA_CC_PMU4706_MAINPLL_PLL0,
303 BCMA_CC_PMU5_MAINPLL_SSB);
Hauke Mehrtens4b4f5be2012-06-30 01:44:38 +0200304 case BCMA_CHIP_ID_BCM53572:
Hauke Mehrtens908debc2011-07-23 01:20:11 +0200305 return 75000000;
306 default:
Rafał Miłecki5b5ac412012-12-07 12:56:56 +0100307 bcma_warn(bus, "No bus clock specified for %04X device, pmu rev. %d, using default %d Hz\n",
Rafał Miłecki3d9d8af2012-07-05 22:07:32 +0200308 bus->chipinfo.id, cc->pmu.rev, BCMA_CC_PMU_HT_CLOCK);
Hauke Mehrtens908debc2011-07-23 01:20:11 +0200309 }
310 return BCMA_CC_PMU_HT_CLOCK;
311}
Rafał Miłeckidd4544f2013-01-08 20:06:23 +0000312EXPORT_SYMBOL_GPL(bcma_pmu_get_bus_clock);
Hauke Mehrtens908debc2011-07-23 01:20:11 +0200313
314/* query cpu clock frequency for PMU-enabled chipcommon */
Rafał Miłecki5b5ac412012-12-07 12:56:56 +0100315u32 bcma_pmu_get_cpu_clock(struct bcma_drv_cc *cc)
Hauke Mehrtens908debc2011-07-23 01:20:11 +0200316{
317 struct bcma_bus *bus = cc->core->bus;
318
Hauke Mehrtens4b4f5be2012-06-30 01:44:38 +0200319 if (bus->chipinfo.id == BCMA_CHIP_ID_BCM53572)
Hauke Mehrtens908debc2011-07-23 01:20:11 +0200320 return 300000000;
321
Rafał Miłecki5b5ac412012-12-07 12:56:56 +0100322 /* New PMUs can have different clock for bus and CPU */
Hauke Mehrtens908debc2011-07-23 01:20:11 +0200323 if (cc->pmu.rev >= 5) {
324 u32 pll;
325 switch (bus->chipinfo.id) {
Hauke Mehrtens650cef382012-07-09 22:03:10 +0200326 case BCMA_CHIP_ID_BCM4706:
Rafał Miłecki5b5ac412012-12-07 12:56:56 +0100327 return bcma_pmu_pll_clock_bcm4706(cc,
Hauke Mehrtens650cef382012-07-09 22:03:10 +0200328 BCMA_CC_PMU4706_MAINPLL_PLL0,
329 BCMA_CC_PMU5_MAINPLL_CPU);
Hauke Mehrtens4b4f5be2012-06-30 01:44:38 +0200330 case BCMA_CHIP_ID_BCM5356:
Hauke Mehrtens908debc2011-07-23 01:20:11 +0200331 pll = BCMA_CC_PMU5356_MAINPLL_PLL0;
332 break;
Hauke Mehrtens4b4f5be2012-06-30 01:44:38 +0200333 case BCMA_CHIP_ID_BCM5357:
334 case BCMA_CHIP_ID_BCM4749:
Hauke Mehrtens908debc2011-07-23 01:20:11 +0200335 pll = BCMA_CC_PMU5357_MAINPLL_PLL0;
336 break;
337 default:
338 pll = BCMA_CC_PMU4716_MAINPLL_PLL0;
339 break;
340 }
341
Rafał Miłecki5b5ac412012-12-07 12:56:56 +0100342 return bcma_pmu_pll_clock(cc, pll, BCMA_CC_PMU5_MAINPLL_CPU);
Hauke Mehrtens908debc2011-07-23 01:20:11 +0200343 }
344
Rafał Miłecki5b5ac412012-12-07 12:56:56 +0100345 /* On old PMUs CPU has the same clock as the bus */
346 return bcma_pmu_get_bus_clock(cc);
Hauke Mehrtens908debc2011-07-23 01:20:11 +0200347}
Hauke Mehrtensc586e102012-06-30 01:44:44 +0200348
349static void bcma_pmu_spuravoid_pll_write(struct bcma_drv_cc *cc, u32 offset,
350 u32 value)
351{
352 bcma_cc_write32(cc, BCMA_CC_PLLCTL_ADDR, offset);
353 bcma_cc_write32(cc, BCMA_CC_PLLCTL_DATA, value);
354}
355
356void bcma_pmu_spuravoid_pllupdate(struct bcma_drv_cc *cc, int spuravoid)
357{
358 u32 tmp = 0;
359 u8 phypll_offset = 0;
360 u8 bcm5357_bcm43236_p1div[] = {0x1, 0x5, 0x5};
361 u8 bcm5357_bcm43236_ndiv[] = {0x30, 0xf6, 0xfc};
362 struct bcma_bus *bus = cc->core->bus;
363
364 switch (bus->chipinfo.id) {
365 case BCMA_CHIP_ID_BCM5357:
366 case BCMA_CHIP_ID_BCM4749:
367 case BCMA_CHIP_ID_BCM53572:
368 /* 5357[ab]0, 43236[ab]0, and 6362b0 */
369
370 /* BCM5357 needs to touch PLL1_PLLCTL[02],
371 so offset PLL0_PLLCTL[02] by 6 */
372 phypll_offset = (bus->chipinfo.id == BCMA_CHIP_ID_BCM5357 ||
373 bus->chipinfo.id == BCMA_CHIP_ID_BCM4749 ||
374 bus->chipinfo.id == BCMA_CHIP_ID_BCM53572) ? 6 : 0;
375
376 /* RMW only the P1 divider */
377 bcma_cc_write32(cc, BCMA_CC_PLLCTL_ADDR,
378 BCMA_CC_PMU_PLL_CTL0 + phypll_offset);
379 tmp = bcma_cc_read32(cc, BCMA_CC_PLLCTL_DATA);
380 tmp &= (~(BCMA_CC_PMU1_PLL0_PC0_P1DIV_MASK));
381 tmp |= (bcm5357_bcm43236_p1div[spuravoid] << BCMA_CC_PMU1_PLL0_PC0_P1DIV_SHIFT);
382 bcma_cc_write32(cc, BCMA_CC_PLLCTL_DATA, tmp);
383
384 /* RMW only the int feedback divider */
385 bcma_cc_write32(cc, BCMA_CC_PLLCTL_ADDR,
386 BCMA_CC_PMU_PLL_CTL2 + phypll_offset);
387 tmp = bcma_cc_read32(cc, BCMA_CC_PLLCTL_DATA);
388 tmp &= ~(BCMA_CC_PMU1_PLL0_PC2_NDIV_INT_MASK);
389 tmp |= (bcm5357_bcm43236_ndiv[spuravoid]) << BCMA_CC_PMU1_PLL0_PC2_NDIV_INT_SHIFT;
390 bcma_cc_write32(cc, BCMA_CC_PLLCTL_DATA, tmp);
391
Hauke Mehrtense3f2ae12013-03-27 17:23:09 +0100392 tmp = BCMA_CC_PMU_CTL_PLL_UPD;
Hauke Mehrtensc586e102012-06-30 01:44:44 +0200393 break;
394
395 case BCMA_CHIP_ID_BCM4331:
396 case BCMA_CHIP_ID_BCM43431:
397 if (spuravoid == 2) {
398 bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL0,
399 0x11500014);
400 bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL2,
401 0x0FC00a08);
402 } else if (spuravoid == 1) {
403 bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL0,
404 0x11500014);
405 bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL2,
406 0x0F600a08);
407 } else {
408 bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL0,
409 0x11100014);
410 bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL2,
411 0x03000a08);
412 }
Hauke Mehrtense3f2ae12013-03-27 17:23:09 +0100413 tmp = BCMA_CC_PMU_CTL_PLL_UPD;
Hauke Mehrtensc586e102012-06-30 01:44:44 +0200414 break;
415
416 case BCMA_CHIP_ID_BCM43224:
417 case BCMA_CHIP_ID_BCM43225:
418 case BCMA_CHIP_ID_BCM43421:
419 if (spuravoid == 1) {
420 bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL0,
421 0x11500010);
422 bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL1,
423 0x000C0C06);
424 bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL2,
425 0x0F600a08);
426 bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL3,
427 0x00000000);
428 bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL4,
429 0x2001E920);
430 bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL5,
431 0x88888815);
432 } else {
433 bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL0,
434 0x11100010);
435 bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL1,
436 0x000c0c06);
437 bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL2,
438 0x03000a08);
439 bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL3,
440 0x00000000);
441 bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL4,
442 0x200005c0);
443 bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL5,
444 0x88888815);
445 }
Hauke Mehrtense3f2ae12013-03-27 17:23:09 +0100446 tmp = BCMA_CC_PMU_CTL_PLL_UPD;
Hauke Mehrtensc586e102012-06-30 01:44:44 +0200447 break;
448
449 case BCMA_CHIP_ID_BCM4716:
450 case BCMA_CHIP_ID_BCM4748:
451 case BCMA_CHIP_ID_BCM47162:
452 if (spuravoid == 1) {
453 bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL0,
454 0x11500060);
455 bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL1,
456 0x080C0C06);
457 bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL2,
458 0x0F600000);
459 bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL3,
460 0x00000000);
461 bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL4,
462 0x2001E924);
463 bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL5,
464 0x88888815);
465 } else {
466 bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL0,
467 0x11100060);
468 bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL1,
469 0x080c0c06);
470 bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL2,
471 0x03000000);
472 bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL3,
473 0x00000000);
474 bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL4,
475 0x200005c0);
476 bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL5,
477 0x88888815);
478 }
479
Hauke Mehrtense3f2ae12013-03-27 17:23:09 +0100480 tmp = BCMA_CC_PMU_CTL_PLL_UPD | BCMA_CC_PMU_CTL_NOILPONW;
Hauke Mehrtensc586e102012-06-30 01:44:44 +0200481 break;
482
483 case BCMA_CHIP_ID_BCM43227:
484 case BCMA_CHIP_ID_BCM43228:
485 case BCMA_CHIP_ID_BCM43428:
486 /* LCNXN */
487 /* PLL Settings for spur avoidance on/off mode,
488 no on2 support for 43228A0 */
489 if (spuravoid == 1) {
490 bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL0,
491 0x01100014);
492 bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL1,
493 0x040C0C06);
494 bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL2,
495 0x03140A08);
496 bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL3,
497 0x00333333);
498 bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL4,
499 0x202C2820);
500 bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL5,
501 0x88888815);
502 } else {
503 bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL0,
504 0x11100014);
505 bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL1,
506 0x040c0c06);
507 bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL2,
508 0x03000a08);
509 bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL3,
510 0x00000000);
511 bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL4,
512 0x200005c0);
513 bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL5,
514 0x88888815);
515 }
Hauke Mehrtense3f2ae12013-03-27 17:23:09 +0100516 tmp = BCMA_CC_PMU_CTL_PLL_UPD;
Hauke Mehrtensc586e102012-06-30 01:44:44 +0200517 break;
518 default:
Rafał Miłecki3d9d8af2012-07-05 22:07:32 +0200519 bcma_err(bus, "Unknown spuravoidance settings for chip 0x%04X, not changing PLL\n",
520 bus->chipinfo.id);
Hauke Mehrtensc586e102012-06-30 01:44:44 +0200521 break;
522 }
523
524 tmp |= bcma_cc_read32(cc, BCMA_CC_PMU_CTL);
525 bcma_cc_write32(cc, BCMA_CC_PMU_CTL, tmp);
526}
527EXPORT_SYMBOL_GPL(bcma_pmu_spuravoid_pllupdate);