Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Broadcom specific AMBA |
| 3 | * ChipCommon Power Management Unit driver |
| 4 | * |
Michael Büsch | eb032b9 | 2011-07-04 20:50:05 +0200 | [diff] [blame] | 5 | * Copyright 2009, Michael Buesch <m@bues.ch> |
Hauke Mehrtens | c586e10 | 2012-06-30 01:44:44 +0200 | [diff] [blame^] | 6 | * Copyright 2007, 2011, Broadcom Corporation |
| 7 | * Copyright 2011, 2012, Hauke Mehrtens <hauke@hauke-m.de> |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 8 | * |
| 9 | * Licensed under the GNU/GPL. See COPYING for details. |
| 10 | */ |
| 11 | |
| 12 | #include "bcma_private.h" |
Paul Gortmaker | 44a8e37 | 2011-07-27 21:21:04 -0400 | [diff] [blame] | 13 | #include <linux/export.h> |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 14 | #include <linux/bcma/bcma.h> |
| 15 | |
Hauke Mehrtens | 908debc | 2011-07-23 01:20:11 +0200 | [diff] [blame] | 16 | static u32 bcma_chipco_pll_read(struct bcma_drv_cc *cc, u32 offset) |
| 17 | { |
| 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 | } |
| 22 | |
Rafał Miłecki | 3861b2c | 2011-09-16 12:33:58 +0200 | [diff] [blame] | 23 | void bcma_chipco_pll_write(struct bcma_drv_cc *cc, u32 offset, u32 value) |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 24 | { |
Rafał Miłecki | 3861b2c | 2011-09-16 12:33:58 +0200 | [diff] [blame] | 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); |
| 28 | } |
| 29 | EXPORT_SYMBOL_GPL(bcma_chipco_pll_write); |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 30 | |
Rafał Miłecki | 3861b2c | 2011-09-16 12:33:58 +0200 | [diff] [blame] | 31 | void bcma_chipco_pll_maskset(struct bcma_drv_cc *cc, u32 offset, u32 mask, |
| 32 | u32 set) |
| 33 | { |
| 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); |
| 37 | } |
| 38 | EXPORT_SYMBOL_GPL(bcma_chipco_pll_maskset); |
| 39 | |
| 40 | void bcma_chipco_chipctl_maskset(struct bcma_drv_cc *cc, |
| 41 | u32 offset, u32 mask, u32 set) |
| 42 | { |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 43 | bcma_cc_write32(cc, BCMA_CC_CHIPCTL_ADDR, offset); |
| 44 | bcma_cc_read32(cc, BCMA_CC_CHIPCTL_ADDR); |
Rafał Miłecki | 3861b2c | 2011-09-16 12:33:58 +0200 | [diff] [blame] | 45 | bcma_cc_maskset32(cc, BCMA_CC_CHIPCTL_DATA, mask, set); |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 46 | } |
Rafał Miłecki | 3861b2c | 2011-09-16 12:33:58 +0200 | [diff] [blame] | 47 | EXPORT_SYMBOL_GPL(bcma_chipco_chipctl_maskset); |
| 48 | |
| 49 | void bcma_chipco_regctl_maskset(struct bcma_drv_cc *cc, u32 offset, u32 mask, |
| 50 | u32 set) |
| 51 | { |
| 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); |
| 55 | } |
| 56 | EXPORT_SYMBOL_GPL(bcma_chipco_regctl_maskset); |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 57 | |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 58 | static void bcma_pmu_resources_init(struct bcma_drv_cc *cc) |
| 59 | { |
| 60 | struct bcma_bus *bus = cc->core->bus; |
| 61 | u32 min_msk = 0, max_msk = 0; |
| 62 | |
| 63 | switch (bus->chipinfo.id) { |
Hauke Mehrtens | 4b4f5be | 2012-06-30 01:44:38 +0200 | [diff] [blame] | 64 | case BCMA_CHIP_ID_BCM4313: |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 65 | min_msk = 0x200D; |
| 66 | max_msk = 0xFFFF; |
| 67 | break; |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 68 | default: |
Hauke Mehrtens | 6270d1c | 2012-06-30 01:44:43 +0200 | [diff] [blame] | 69 | pr_debug("PMU resource config unknown or not needed for device 0x%04X\n", |
| 70 | bus->chipinfo.id); |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | /* Set the resource masks. */ |
| 74 | if (min_msk) |
| 75 | bcma_cc_write32(cc, BCMA_CC_PMU_MINRES_MSK, min_msk); |
| 76 | if (max_msk) |
| 77 | bcma_cc_write32(cc, BCMA_CC_PMU_MAXRES_MSK, max_msk); |
| 78 | } |
| 79 | |
Rafał Miłecki | 984e5be | 2011-08-11 23:46:44 +0200 | [diff] [blame] | 80 | /* Disable to allow reading SPROM. Don't know the adventages of enabling it. */ |
| 81 | void bcma_chipco_bcm4331_ext_pa_lines_ctl(struct bcma_drv_cc *cc, bool enable) |
| 82 | { |
| 83 | struct bcma_bus *bus = cc->core->bus; |
| 84 | u32 val; |
| 85 | |
| 86 | val = bcma_cc_read32(cc, BCMA_CC_CHIPCTL); |
| 87 | if (enable) { |
| 88 | val |= BCMA_CHIPCTL_4331_EXTPA_EN; |
| 89 | if (bus->chipinfo.pkg == 9 || bus->chipinfo.pkg == 11) |
| 90 | val |= BCMA_CHIPCTL_4331_EXTPA_ON_GPIO2_5; |
Hauke Mehrtens | 00eeedc | 2012-06-30 01:44:37 +0200 | [diff] [blame] | 91 | else if (bus->chipinfo.rev > 0) |
| 92 | val |= BCMA_CHIPCTL_4331_EXTPA_EN2; |
Rafał Miłecki | 984e5be | 2011-08-11 23:46:44 +0200 | [diff] [blame] | 93 | } else { |
| 94 | val &= ~BCMA_CHIPCTL_4331_EXTPA_EN; |
Hauke Mehrtens | 00eeedc | 2012-06-30 01:44:37 +0200 | [diff] [blame] | 95 | val &= ~BCMA_CHIPCTL_4331_EXTPA_EN2; |
Rafał Miłecki | 984e5be | 2011-08-11 23:46:44 +0200 | [diff] [blame] | 96 | val &= ~BCMA_CHIPCTL_4331_EXTPA_ON_GPIO2_5; |
| 97 | } |
| 98 | bcma_cc_write32(cc, BCMA_CC_CHIPCTL, val); |
| 99 | } |
| 100 | |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 101 | void bcma_pmu_workarounds(struct bcma_drv_cc *cc) |
| 102 | { |
| 103 | struct bcma_bus *bus = cc->core->bus; |
| 104 | |
| 105 | switch (bus->chipinfo.id) { |
Hauke Mehrtens | 4b4f5be | 2012-06-30 01:44:38 +0200 | [diff] [blame] | 106 | case BCMA_CHIP_ID_BCM4313: |
Hauke Mehrtens | b956254 | 2012-06-30 01:44:41 +0200 | [diff] [blame] | 107 | /* enable 12 mA drive strenth for 4313 and set chipControl |
| 108 | register bit 1 */ |
| 109 | bcma_chipco_chipctl_maskset(cc, 0, |
| 110 | BCMA_CCTRL_4313_12MA_LED_DRIVE, |
| 111 | BCMA_CCTRL_4313_12MA_LED_DRIVE); |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 112 | break; |
Hauke Mehrtens | 4b4f5be | 2012-06-30 01:44:38 +0200 | [diff] [blame] | 113 | case BCMA_CHIP_ID_BCM4331: |
| 114 | case BCMA_CHIP_ID_BCM43431: |
Seth Forshee | 69aaedd | 2012-06-01 09:13:17 -0500 | [diff] [blame] | 115 | /* Ext PA lines must be enabled for tx on BCM4331 */ |
| 116 | bcma_chipco_bcm4331_ext_pa_lines_ctl(cc, true); |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 117 | break; |
Hauke Mehrtens | 4b4f5be | 2012-06-30 01:44:38 +0200 | [diff] [blame] | 118 | case BCMA_CHIP_ID_BCM43224: |
Hauke Mehrtens | b956254 | 2012-06-30 01:44:41 +0200 | [diff] [blame] | 119 | case BCMA_CHIP_ID_BCM43421: |
| 120 | /* enable 12 mA drive strenth for 43224 and set chipControl |
| 121 | register bit 15 */ |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 122 | if (bus->chipinfo.rev == 0) { |
Hauke Mehrtens | b956254 | 2012-06-30 01:44:41 +0200 | [diff] [blame] | 123 | bcma_cc_maskset32(cc, BCMA_CC_CHIPCTL, |
| 124 | BCMA_CCTRL_43224_GPIO_TOGGLE, |
| 125 | BCMA_CCTRL_43224_GPIO_TOGGLE); |
| 126 | bcma_chipco_chipctl_maskset(cc, 0, |
| 127 | BCMA_CCTRL_43224A0_12MA_LED_DRIVE, |
| 128 | BCMA_CCTRL_43224A0_12MA_LED_DRIVE); |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 129 | } else { |
Hauke Mehrtens | b956254 | 2012-06-30 01:44:41 +0200 | [diff] [blame] | 130 | bcma_chipco_chipctl_maskset(cc, 0, |
| 131 | BCMA_CCTRL_43224B0_12MA_LED_DRIVE, |
| 132 | BCMA_CCTRL_43224B0_12MA_LED_DRIVE); |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 133 | } |
| 134 | break; |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 135 | default: |
Hauke Mehrtens | 6270d1c | 2012-06-30 01:44:43 +0200 | [diff] [blame] | 136 | pr_debug("Workarounds unknown or not needed for device 0x%04X\n", |
| 137 | bus->chipinfo.id); |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 138 | } |
| 139 | } |
| 140 | |
| 141 | void bcma_pmu_init(struct bcma_drv_cc *cc) |
| 142 | { |
| 143 | u32 pmucap; |
| 144 | |
| 145 | pmucap = bcma_cc_read32(cc, BCMA_CC_PMU_CAP); |
| 146 | cc->pmu.rev = (pmucap & BCMA_CC_PMU_CAP_REVISION); |
| 147 | |
| 148 | pr_debug("Found rev %u PMU (capabilities 0x%08X)\n", cc->pmu.rev, |
| 149 | pmucap); |
| 150 | |
| 151 | if (cc->pmu.rev == 1) |
| 152 | bcma_cc_mask32(cc, BCMA_CC_PMU_CTL, |
| 153 | ~BCMA_CC_PMU_CTL_NOILPONW); |
| 154 | else |
| 155 | bcma_cc_set32(cc, BCMA_CC_PMU_CTL, |
| 156 | BCMA_CC_PMU_CTL_NOILPONW); |
| 157 | |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 158 | bcma_pmu_resources_init(cc); |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 159 | bcma_pmu_workarounds(cc); |
| 160 | } |
Hauke Mehrtens | e3afe0e | 2011-07-23 01:20:10 +0200 | [diff] [blame] | 161 | |
| 162 | u32 bcma_pmu_alp_clock(struct bcma_drv_cc *cc) |
| 163 | { |
| 164 | struct bcma_bus *bus = cc->core->bus; |
| 165 | |
| 166 | switch (bus->chipinfo.id) { |
Hauke Mehrtens | 4b4f5be | 2012-06-30 01:44:38 +0200 | [diff] [blame] | 167 | case BCMA_CHIP_ID_BCM4716: |
| 168 | case BCMA_CHIP_ID_BCM4748: |
| 169 | case BCMA_CHIP_ID_BCM47162: |
| 170 | case BCMA_CHIP_ID_BCM4313: |
| 171 | case BCMA_CHIP_ID_BCM5357: |
| 172 | case BCMA_CHIP_ID_BCM4749: |
| 173 | case BCMA_CHIP_ID_BCM53572: |
Hauke Mehrtens | e3afe0e | 2011-07-23 01:20:10 +0200 | [diff] [blame] | 174 | /* always 20Mhz */ |
| 175 | return 20000 * 1000; |
Hauke Mehrtens | 4b4f5be | 2012-06-30 01:44:38 +0200 | [diff] [blame] | 176 | case BCMA_CHIP_ID_BCM5356: |
| 177 | case BCMA_CHIP_ID_BCM4706: |
Hauke Mehrtens | e3afe0e | 2011-07-23 01:20:10 +0200 | [diff] [blame] | 178 | /* always 25Mhz */ |
| 179 | return 25000 * 1000; |
| 180 | default: |
| 181 | pr_warn("No ALP clock specified for %04X device, " |
| 182 | "pmu rev. %d, using default %d Hz\n", |
| 183 | bus->chipinfo.id, cc->pmu.rev, BCMA_CC_PMU_ALP_CLOCK); |
| 184 | } |
| 185 | return BCMA_CC_PMU_ALP_CLOCK; |
| 186 | } |
Hauke Mehrtens | 908debc | 2011-07-23 01:20:11 +0200 | [diff] [blame] | 187 | |
| 188 | /* Find the output of the "m" pll divider given pll controls that start with |
| 189 | * pllreg "pll0" i.e. 12 for main 6 for phy, 0 for misc. |
| 190 | */ |
| 191 | static u32 bcma_pmu_clock(struct bcma_drv_cc *cc, u32 pll0, u32 m) |
| 192 | { |
| 193 | u32 tmp, div, ndiv, p1, p2, fc; |
| 194 | struct bcma_bus *bus = cc->core->bus; |
| 195 | |
| 196 | BUG_ON((pll0 & 3) || (pll0 > BCMA_CC_PMU4716_MAINPLL_PLL0)); |
| 197 | |
| 198 | BUG_ON(!m || m > 4); |
| 199 | |
Hauke Mehrtens | 4b4f5be | 2012-06-30 01:44:38 +0200 | [diff] [blame] | 200 | if (bus->chipinfo.id == BCMA_CHIP_ID_BCM5357 || |
| 201 | bus->chipinfo.id == BCMA_CHIP_ID_BCM4749) { |
Hauke Mehrtens | 908debc | 2011-07-23 01:20:11 +0200 | [diff] [blame] | 202 | /* Detect failure in clock setting */ |
| 203 | tmp = bcma_cc_read32(cc, BCMA_CC_CHIPSTAT); |
| 204 | if (tmp & 0x40000) |
| 205 | return 133 * 1000000; |
| 206 | } |
| 207 | |
| 208 | tmp = bcma_chipco_pll_read(cc, pll0 + BCMA_CC_PPL_P1P2_OFF); |
| 209 | p1 = (tmp & BCMA_CC_PPL_P1_MASK) >> BCMA_CC_PPL_P1_SHIFT; |
| 210 | p2 = (tmp & BCMA_CC_PPL_P2_MASK) >> BCMA_CC_PPL_P2_SHIFT; |
| 211 | |
| 212 | tmp = bcma_chipco_pll_read(cc, pll0 + BCMA_CC_PPL_M14_OFF); |
| 213 | div = (tmp >> ((m - 1) * BCMA_CC_PPL_MDIV_WIDTH)) & |
| 214 | BCMA_CC_PPL_MDIV_MASK; |
| 215 | |
| 216 | tmp = bcma_chipco_pll_read(cc, pll0 + BCMA_CC_PPL_NM5_OFF); |
| 217 | ndiv = (tmp & BCMA_CC_PPL_NDIV_MASK) >> BCMA_CC_PPL_NDIV_SHIFT; |
| 218 | |
| 219 | /* Do calculation in Mhz */ |
| 220 | fc = bcma_pmu_alp_clock(cc) / 1000000; |
| 221 | fc = (p1 * ndiv * fc) / p2; |
| 222 | |
| 223 | /* Return clock in Hertz */ |
| 224 | return (fc / div) * 1000000; |
| 225 | } |
| 226 | |
| 227 | /* query bus clock frequency for PMU-enabled chipcommon */ |
| 228 | u32 bcma_pmu_get_clockcontrol(struct bcma_drv_cc *cc) |
| 229 | { |
| 230 | struct bcma_bus *bus = cc->core->bus; |
| 231 | |
| 232 | switch (bus->chipinfo.id) { |
Hauke Mehrtens | 4b4f5be | 2012-06-30 01:44:38 +0200 | [diff] [blame] | 233 | case BCMA_CHIP_ID_BCM4716: |
| 234 | case BCMA_CHIP_ID_BCM4748: |
| 235 | case BCMA_CHIP_ID_BCM47162: |
Hauke Mehrtens | 908debc | 2011-07-23 01:20:11 +0200 | [diff] [blame] | 236 | return bcma_pmu_clock(cc, BCMA_CC_PMU4716_MAINPLL_PLL0, |
| 237 | BCMA_CC_PMU5_MAINPLL_SSB); |
Hauke Mehrtens | 4b4f5be | 2012-06-30 01:44:38 +0200 | [diff] [blame] | 238 | case BCMA_CHIP_ID_BCM5356: |
Hauke Mehrtens | 908debc | 2011-07-23 01:20:11 +0200 | [diff] [blame] | 239 | return bcma_pmu_clock(cc, BCMA_CC_PMU5356_MAINPLL_PLL0, |
| 240 | BCMA_CC_PMU5_MAINPLL_SSB); |
Hauke Mehrtens | 4b4f5be | 2012-06-30 01:44:38 +0200 | [diff] [blame] | 241 | case BCMA_CHIP_ID_BCM5357: |
| 242 | case BCMA_CHIP_ID_BCM4749: |
Hauke Mehrtens | 908debc | 2011-07-23 01:20:11 +0200 | [diff] [blame] | 243 | return bcma_pmu_clock(cc, BCMA_CC_PMU5357_MAINPLL_PLL0, |
| 244 | BCMA_CC_PMU5_MAINPLL_SSB); |
Hauke Mehrtens | 4b4f5be | 2012-06-30 01:44:38 +0200 | [diff] [blame] | 245 | case BCMA_CHIP_ID_BCM4706: |
Hauke Mehrtens | 908debc | 2011-07-23 01:20:11 +0200 | [diff] [blame] | 246 | return bcma_pmu_clock(cc, BCMA_CC_PMU4706_MAINPLL_PLL0, |
| 247 | BCMA_CC_PMU5_MAINPLL_SSB); |
Hauke Mehrtens | 4b4f5be | 2012-06-30 01:44:38 +0200 | [diff] [blame] | 248 | case BCMA_CHIP_ID_BCM53572: |
Hauke Mehrtens | 908debc | 2011-07-23 01:20:11 +0200 | [diff] [blame] | 249 | return 75000000; |
| 250 | default: |
| 251 | pr_warn("No backplane clock specified for %04X device, " |
| 252 | "pmu rev. %d, using default %d Hz\n", |
| 253 | bus->chipinfo.id, cc->pmu.rev, BCMA_CC_PMU_HT_CLOCK); |
| 254 | } |
| 255 | return BCMA_CC_PMU_HT_CLOCK; |
| 256 | } |
| 257 | |
| 258 | /* query cpu clock frequency for PMU-enabled chipcommon */ |
| 259 | u32 bcma_pmu_get_clockcpu(struct bcma_drv_cc *cc) |
| 260 | { |
| 261 | struct bcma_bus *bus = cc->core->bus; |
| 262 | |
Hauke Mehrtens | 4b4f5be | 2012-06-30 01:44:38 +0200 | [diff] [blame] | 263 | if (bus->chipinfo.id == BCMA_CHIP_ID_BCM53572) |
Hauke Mehrtens | 908debc | 2011-07-23 01:20:11 +0200 | [diff] [blame] | 264 | return 300000000; |
| 265 | |
| 266 | if (cc->pmu.rev >= 5) { |
| 267 | u32 pll; |
| 268 | switch (bus->chipinfo.id) { |
Hauke Mehrtens | 4b4f5be | 2012-06-30 01:44:38 +0200 | [diff] [blame] | 269 | case BCMA_CHIP_ID_BCM5356: |
Hauke Mehrtens | 908debc | 2011-07-23 01:20:11 +0200 | [diff] [blame] | 270 | pll = BCMA_CC_PMU5356_MAINPLL_PLL0; |
| 271 | break; |
Hauke Mehrtens | 4b4f5be | 2012-06-30 01:44:38 +0200 | [diff] [blame] | 272 | case BCMA_CHIP_ID_BCM5357: |
| 273 | case BCMA_CHIP_ID_BCM4749: |
Hauke Mehrtens | 908debc | 2011-07-23 01:20:11 +0200 | [diff] [blame] | 274 | pll = BCMA_CC_PMU5357_MAINPLL_PLL0; |
| 275 | break; |
| 276 | default: |
| 277 | pll = BCMA_CC_PMU4716_MAINPLL_PLL0; |
| 278 | break; |
| 279 | } |
| 280 | |
Hauke Mehrtens | 4b4f5be | 2012-06-30 01:44:38 +0200 | [diff] [blame] | 281 | /* TODO: if (bus->chipinfo.id == BCMA_CHIP_ID_BCM4706) |
Hauke Mehrtens | 908debc | 2011-07-23 01:20:11 +0200 | [diff] [blame] | 282 | return si_4706_pmu_clock(sih, osh, cc, PMU4706_MAINPLL_PLL0, PMU5_MAINPLL_CPU); */ |
| 283 | return bcma_pmu_clock(cc, pll, BCMA_CC_PMU5_MAINPLL_CPU); |
| 284 | } |
| 285 | |
| 286 | return bcma_pmu_get_clockcontrol(cc); |
| 287 | } |
Hauke Mehrtens | c586e10 | 2012-06-30 01:44:44 +0200 | [diff] [blame^] | 288 | |
| 289 | static void bcma_pmu_spuravoid_pll_write(struct bcma_drv_cc *cc, u32 offset, |
| 290 | u32 value) |
| 291 | { |
| 292 | bcma_cc_write32(cc, BCMA_CC_PLLCTL_ADDR, offset); |
| 293 | bcma_cc_write32(cc, BCMA_CC_PLLCTL_DATA, value); |
| 294 | } |
| 295 | |
| 296 | void bcma_pmu_spuravoid_pllupdate(struct bcma_drv_cc *cc, int spuravoid) |
| 297 | { |
| 298 | u32 tmp = 0; |
| 299 | u8 phypll_offset = 0; |
| 300 | u8 bcm5357_bcm43236_p1div[] = {0x1, 0x5, 0x5}; |
| 301 | u8 bcm5357_bcm43236_ndiv[] = {0x30, 0xf6, 0xfc}; |
| 302 | struct bcma_bus *bus = cc->core->bus; |
| 303 | |
| 304 | switch (bus->chipinfo.id) { |
| 305 | case BCMA_CHIP_ID_BCM5357: |
| 306 | case BCMA_CHIP_ID_BCM4749: |
| 307 | case BCMA_CHIP_ID_BCM53572: |
| 308 | /* 5357[ab]0, 43236[ab]0, and 6362b0 */ |
| 309 | |
| 310 | /* BCM5357 needs to touch PLL1_PLLCTL[02], |
| 311 | so offset PLL0_PLLCTL[02] by 6 */ |
| 312 | phypll_offset = (bus->chipinfo.id == BCMA_CHIP_ID_BCM5357 || |
| 313 | bus->chipinfo.id == BCMA_CHIP_ID_BCM4749 || |
| 314 | bus->chipinfo.id == BCMA_CHIP_ID_BCM53572) ? 6 : 0; |
| 315 | |
| 316 | /* RMW only the P1 divider */ |
| 317 | bcma_cc_write32(cc, BCMA_CC_PLLCTL_ADDR, |
| 318 | BCMA_CC_PMU_PLL_CTL0 + phypll_offset); |
| 319 | tmp = bcma_cc_read32(cc, BCMA_CC_PLLCTL_DATA); |
| 320 | tmp &= (~(BCMA_CC_PMU1_PLL0_PC0_P1DIV_MASK)); |
| 321 | tmp |= (bcm5357_bcm43236_p1div[spuravoid] << BCMA_CC_PMU1_PLL0_PC0_P1DIV_SHIFT); |
| 322 | bcma_cc_write32(cc, BCMA_CC_PLLCTL_DATA, tmp); |
| 323 | |
| 324 | /* RMW only the int feedback divider */ |
| 325 | bcma_cc_write32(cc, BCMA_CC_PLLCTL_ADDR, |
| 326 | BCMA_CC_PMU_PLL_CTL2 + phypll_offset); |
| 327 | tmp = bcma_cc_read32(cc, BCMA_CC_PLLCTL_DATA); |
| 328 | tmp &= ~(BCMA_CC_PMU1_PLL0_PC2_NDIV_INT_MASK); |
| 329 | tmp |= (bcm5357_bcm43236_ndiv[spuravoid]) << BCMA_CC_PMU1_PLL0_PC2_NDIV_INT_SHIFT; |
| 330 | bcma_cc_write32(cc, BCMA_CC_PLLCTL_DATA, tmp); |
| 331 | |
| 332 | tmp = 1 << 10; |
| 333 | break; |
| 334 | |
| 335 | case BCMA_CHIP_ID_BCM4331: |
| 336 | case BCMA_CHIP_ID_BCM43431: |
| 337 | if (spuravoid == 2) { |
| 338 | bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL0, |
| 339 | 0x11500014); |
| 340 | bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL2, |
| 341 | 0x0FC00a08); |
| 342 | } else if (spuravoid == 1) { |
| 343 | bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL0, |
| 344 | 0x11500014); |
| 345 | bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL2, |
| 346 | 0x0F600a08); |
| 347 | } else { |
| 348 | bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL0, |
| 349 | 0x11100014); |
| 350 | bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL2, |
| 351 | 0x03000a08); |
| 352 | } |
| 353 | tmp = 1 << 10; |
| 354 | break; |
| 355 | |
| 356 | case BCMA_CHIP_ID_BCM43224: |
| 357 | case BCMA_CHIP_ID_BCM43225: |
| 358 | case BCMA_CHIP_ID_BCM43421: |
| 359 | if (spuravoid == 1) { |
| 360 | bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL0, |
| 361 | 0x11500010); |
| 362 | bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL1, |
| 363 | 0x000C0C06); |
| 364 | bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL2, |
| 365 | 0x0F600a08); |
| 366 | bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL3, |
| 367 | 0x00000000); |
| 368 | bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL4, |
| 369 | 0x2001E920); |
| 370 | bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL5, |
| 371 | 0x88888815); |
| 372 | } else { |
| 373 | bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL0, |
| 374 | 0x11100010); |
| 375 | bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL1, |
| 376 | 0x000c0c06); |
| 377 | bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL2, |
| 378 | 0x03000a08); |
| 379 | bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL3, |
| 380 | 0x00000000); |
| 381 | bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL4, |
| 382 | 0x200005c0); |
| 383 | bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL5, |
| 384 | 0x88888815); |
| 385 | } |
| 386 | tmp = 1 << 10; |
| 387 | break; |
| 388 | |
| 389 | case BCMA_CHIP_ID_BCM4716: |
| 390 | case BCMA_CHIP_ID_BCM4748: |
| 391 | case BCMA_CHIP_ID_BCM47162: |
| 392 | if (spuravoid == 1) { |
| 393 | bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL0, |
| 394 | 0x11500060); |
| 395 | bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL1, |
| 396 | 0x080C0C06); |
| 397 | bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL2, |
| 398 | 0x0F600000); |
| 399 | bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL3, |
| 400 | 0x00000000); |
| 401 | bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL4, |
| 402 | 0x2001E924); |
| 403 | bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL5, |
| 404 | 0x88888815); |
| 405 | } else { |
| 406 | bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL0, |
| 407 | 0x11100060); |
| 408 | bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL1, |
| 409 | 0x080c0c06); |
| 410 | bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL2, |
| 411 | 0x03000000); |
| 412 | bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL3, |
| 413 | 0x00000000); |
| 414 | bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL4, |
| 415 | 0x200005c0); |
| 416 | bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL5, |
| 417 | 0x88888815); |
| 418 | } |
| 419 | |
| 420 | tmp = 3 << 9; |
| 421 | break; |
| 422 | |
| 423 | case BCMA_CHIP_ID_BCM43227: |
| 424 | case BCMA_CHIP_ID_BCM43228: |
| 425 | case BCMA_CHIP_ID_BCM43428: |
| 426 | /* LCNXN */ |
| 427 | /* PLL Settings for spur avoidance on/off mode, |
| 428 | no on2 support for 43228A0 */ |
| 429 | if (spuravoid == 1) { |
| 430 | bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL0, |
| 431 | 0x01100014); |
| 432 | bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL1, |
| 433 | 0x040C0C06); |
| 434 | bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL2, |
| 435 | 0x03140A08); |
| 436 | bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL3, |
| 437 | 0x00333333); |
| 438 | bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL4, |
| 439 | 0x202C2820); |
| 440 | bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL5, |
| 441 | 0x88888815); |
| 442 | } else { |
| 443 | bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL0, |
| 444 | 0x11100014); |
| 445 | bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL1, |
| 446 | 0x040c0c06); |
| 447 | bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL2, |
| 448 | 0x03000a08); |
| 449 | bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL3, |
| 450 | 0x00000000); |
| 451 | bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL4, |
| 452 | 0x200005c0); |
| 453 | bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL5, |
| 454 | 0x88888815); |
| 455 | } |
| 456 | tmp = 1 << 10; |
| 457 | break; |
| 458 | default: |
| 459 | pr_err("unknown spuravoidance settings for chip 0x%04X, not changing PLL\n", |
| 460 | bus->chipinfo.id); |
| 461 | break; |
| 462 | } |
| 463 | |
| 464 | tmp |= bcma_cc_read32(cc, BCMA_CC_PMU_CTL); |
| 465 | bcma_cc_write32(cc, BCMA_CC_PMU_CTL, tmp); |
| 466 | } |
| 467 | EXPORT_SYMBOL_GPL(bcma_pmu_spuravoid_pllupdate); |