Michael Buesch | 61e115a | 2007-09-18 15:12:50 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Sonics Silicon Backplane |
| 3 | * Broadcom ChipCommon core driver |
| 4 | * |
| 5 | * Copyright 2005, Broadcom Corporation |
Michael Büsch | eb032b9 | 2011-07-04 20:50:05 +0200 | [diff] [blame] | 6 | * Copyright 2006, 2007, Michael Buesch <m@bues.ch> |
Michael Buesch | 61e115a | 2007-09-18 15:12:50 -0400 | [diff] [blame] | 7 | * |
| 8 | * Licensed under the GNU/GPL. See COPYING for details. |
| 9 | */ |
| 10 | |
| 11 | #include <linux/ssb/ssb.h> |
| 12 | #include <linux/ssb/ssb_regs.h> |
Paul Gortmaker | 1014c22 | 2011-07-27 22:07:02 -0400 | [diff] [blame] | 13 | #include <linux/export.h> |
Michael Buesch | 61e115a | 2007-09-18 15:12:50 -0400 | [diff] [blame] | 14 | #include <linux/pci.h> |
| 15 | |
| 16 | #include "ssb_private.h" |
| 17 | |
| 18 | |
| 19 | /* Clock sources */ |
| 20 | enum ssb_clksrc { |
| 21 | /* PCI clock */ |
| 22 | SSB_CHIPCO_CLKSRC_PCI, |
| 23 | /* Crystal slow clock oscillator */ |
| 24 | SSB_CHIPCO_CLKSRC_XTALOS, |
| 25 | /* Low power oscillator */ |
| 26 | SSB_CHIPCO_CLKSRC_LOPWROS, |
| 27 | }; |
| 28 | |
| 29 | |
Michael Buesch | c2bcbe6 | 2008-02-19 14:53:35 +0100 | [diff] [blame] | 30 | static inline u32 chipco_write32_masked(struct ssb_chipcommon *cc, u16 offset, |
| 31 | u32 mask, u32 value) |
Michael Buesch | 61e115a | 2007-09-18 15:12:50 -0400 | [diff] [blame] | 32 | { |
| 33 | value &= mask; |
| 34 | value |= chipco_read32(cc, offset) & ~mask; |
| 35 | chipco_write32(cc, offset, value); |
Michael Buesch | c2bcbe6 | 2008-02-19 14:53:35 +0100 | [diff] [blame] | 36 | |
| 37 | return value; |
Michael Buesch | 61e115a | 2007-09-18 15:12:50 -0400 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | void ssb_chipco_set_clockmode(struct ssb_chipcommon *cc, |
| 41 | enum ssb_clkmode mode) |
| 42 | { |
| 43 | struct ssb_device *ccdev = cc->dev; |
| 44 | struct ssb_bus *bus; |
| 45 | u32 tmp; |
| 46 | |
| 47 | if (!ccdev) |
| 48 | return; |
| 49 | bus = ccdev->bus; |
Rafał Miłecki | 0ca6995 | 2011-04-27 17:40:11 +0200 | [diff] [blame] | 50 | |
| 51 | /* We support SLOW only on 6..9 */ |
| 52 | if (ccdev->id.revision >= 10 && mode == SSB_CLKMODE_SLOW) |
| 53 | mode = SSB_CLKMODE_DYNAMIC; |
| 54 | |
| 55 | if (cc->capabilities & SSB_CHIPCO_CAP_PMU) |
| 56 | return; /* PMU controls clockmode, separated function needed */ |
| 57 | SSB_WARN_ON(ccdev->id.revision >= 20); |
| 58 | |
Michael Buesch | 61e115a | 2007-09-18 15:12:50 -0400 | [diff] [blame] | 59 | /* chipcommon cores prior to rev6 don't support dynamic clock control */ |
| 60 | if (ccdev->id.revision < 6) |
| 61 | return; |
Rafał Miłecki | 0ca6995 | 2011-04-27 17:40:11 +0200 | [diff] [blame] | 62 | |
| 63 | /* ChipCommon cores rev10+ need testing */ |
Michael Buesch | 61e115a | 2007-09-18 15:12:50 -0400 | [diff] [blame] | 64 | if (ccdev->id.revision >= 10) |
| 65 | return; |
Rafał Miłecki | 0ca6995 | 2011-04-27 17:40:11 +0200 | [diff] [blame] | 66 | |
Michael Buesch | 61e115a | 2007-09-18 15:12:50 -0400 | [diff] [blame] | 67 | if (!(cc->capabilities & SSB_CHIPCO_CAP_PCTL)) |
| 68 | return; |
| 69 | |
| 70 | switch (mode) { |
Rafał Miłecki | 0ca6995 | 2011-04-27 17:40:11 +0200 | [diff] [blame] | 71 | case SSB_CLKMODE_SLOW: /* For revs 6..9 only */ |
Michael Buesch | 61e115a | 2007-09-18 15:12:50 -0400 | [diff] [blame] | 72 | tmp = chipco_read32(cc, SSB_CHIPCO_SLOWCLKCTL); |
| 73 | tmp |= SSB_CHIPCO_SLOWCLKCTL_FSLOW; |
| 74 | chipco_write32(cc, SSB_CHIPCO_SLOWCLKCTL, tmp); |
| 75 | break; |
| 76 | case SSB_CLKMODE_FAST: |
Rafał Miłecki | 0ca6995 | 2011-04-27 17:40:11 +0200 | [diff] [blame] | 77 | if (ccdev->id.revision < 10) { |
| 78 | ssb_pci_xtal(bus, SSB_GPIO_XTAL, 1); /* Force crystal on */ |
| 79 | tmp = chipco_read32(cc, SSB_CHIPCO_SLOWCLKCTL); |
| 80 | tmp &= ~SSB_CHIPCO_SLOWCLKCTL_FSLOW; |
| 81 | tmp |= SSB_CHIPCO_SLOWCLKCTL_IPLL; |
| 82 | chipco_write32(cc, SSB_CHIPCO_SLOWCLKCTL, tmp); |
| 83 | } else { |
| 84 | chipco_write32(cc, SSB_CHIPCO_SYSCLKCTL, |
| 85 | (chipco_read32(cc, SSB_CHIPCO_SYSCLKCTL) | |
| 86 | SSB_CHIPCO_SYSCLKCTL_FORCEHT)); |
| 87 | /* udelay(150); TODO: not available in early init */ |
| 88 | } |
Michael Buesch | 61e115a | 2007-09-18 15:12:50 -0400 | [diff] [blame] | 89 | break; |
| 90 | case SSB_CLKMODE_DYNAMIC: |
Rafał Miłecki | 0ca6995 | 2011-04-27 17:40:11 +0200 | [diff] [blame] | 91 | if (ccdev->id.revision < 10) { |
| 92 | tmp = chipco_read32(cc, SSB_CHIPCO_SLOWCLKCTL); |
| 93 | tmp &= ~SSB_CHIPCO_SLOWCLKCTL_FSLOW; |
| 94 | tmp &= ~SSB_CHIPCO_SLOWCLKCTL_IPLL; |
| 95 | tmp &= ~SSB_CHIPCO_SLOWCLKCTL_ENXTAL; |
| 96 | if ((tmp & SSB_CHIPCO_SLOWCLKCTL_SRC) != |
| 97 | SSB_CHIPCO_SLOWCLKCTL_SRC_XTAL) |
| 98 | tmp |= SSB_CHIPCO_SLOWCLKCTL_ENXTAL; |
| 99 | chipco_write32(cc, SSB_CHIPCO_SLOWCLKCTL, tmp); |
Michael Buesch | 61e115a | 2007-09-18 15:12:50 -0400 | [diff] [blame] | 100 | |
Rafał Miłecki | 0ca6995 | 2011-04-27 17:40:11 +0200 | [diff] [blame] | 101 | /* For dynamic control, we have to release our xtal_pu |
| 102 | * "force on" */ |
| 103 | if (tmp & SSB_CHIPCO_SLOWCLKCTL_ENXTAL) |
| 104 | ssb_pci_xtal(bus, SSB_GPIO_XTAL, 0); |
| 105 | } else { |
| 106 | chipco_write32(cc, SSB_CHIPCO_SYSCLKCTL, |
| 107 | (chipco_read32(cc, SSB_CHIPCO_SYSCLKCTL) & |
| 108 | ~SSB_CHIPCO_SYSCLKCTL_FORCEHT)); |
| 109 | } |
Michael Buesch | 61e115a | 2007-09-18 15:12:50 -0400 | [diff] [blame] | 110 | break; |
| 111 | default: |
| 112 | SSB_WARN_ON(1); |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | /* Get the Slow Clock Source */ |
| 117 | static enum ssb_clksrc chipco_pctl_get_slowclksrc(struct ssb_chipcommon *cc) |
| 118 | { |
| 119 | struct ssb_bus *bus = cc->dev->bus; |
| 120 | u32 uninitialized_var(tmp); |
| 121 | |
| 122 | if (cc->dev->id.revision < 6) { |
| 123 | if (bus->bustype == SSB_BUSTYPE_SSB || |
| 124 | bus->bustype == SSB_BUSTYPE_PCMCIA) |
| 125 | return SSB_CHIPCO_CLKSRC_XTALOS; |
| 126 | if (bus->bustype == SSB_BUSTYPE_PCI) { |
| 127 | pci_read_config_dword(bus->host_pci, SSB_GPIO_OUT, &tmp); |
| 128 | if (tmp & 0x10) |
| 129 | return SSB_CHIPCO_CLKSRC_PCI; |
| 130 | return SSB_CHIPCO_CLKSRC_XTALOS; |
| 131 | } |
| 132 | } |
| 133 | if (cc->dev->id.revision < 10) { |
| 134 | tmp = chipco_read32(cc, SSB_CHIPCO_SLOWCLKCTL); |
| 135 | tmp &= 0x7; |
| 136 | if (tmp == 0) |
| 137 | return SSB_CHIPCO_CLKSRC_LOPWROS; |
| 138 | if (tmp == 1) |
| 139 | return SSB_CHIPCO_CLKSRC_XTALOS; |
| 140 | if (tmp == 2) |
| 141 | return SSB_CHIPCO_CLKSRC_PCI; |
| 142 | } |
| 143 | |
| 144 | return SSB_CHIPCO_CLKSRC_XTALOS; |
| 145 | } |
| 146 | |
| 147 | /* Get maximum or minimum (depending on get_max flag) slowclock frequency. */ |
| 148 | static int chipco_pctl_clockfreqlimit(struct ssb_chipcommon *cc, int get_max) |
| 149 | { |
| 150 | int uninitialized_var(limit); |
| 151 | enum ssb_clksrc clocksrc; |
| 152 | int divisor = 1; |
| 153 | u32 tmp; |
| 154 | |
| 155 | clocksrc = chipco_pctl_get_slowclksrc(cc); |
| 156 | if (cc->dev->id.revision < 6) { |
| 157 | switch (clocksrc) { |
| 158 | case SSB_CHIPCO_CLKSRC_PCI: |
| 159 | divisor = 64; |
| 160 | break; |
| 161 | case SSB_CHIPCO_CLKSRC_XTALOS: |
| 162 | divisor = 32; |
| 163 | break; |
| 164 | default: |
| 165 | SSB_WARN_ON(1); |
| 166 | } |
| 167 | } else if (cc->dev->id.revision < 10) { |
| 168 | switch (clocksrc) { |
| 169 | case SSB_CHIPCO_CLKSRC_LOPWROS: |
| 170 | break; |
| 171 | case SSB_CHIPCO_CLKSRC_XTALOS: |
| 172 | case SSB_CHIPCO_CLKSRC_PCI: |
| 173 | tmp = chipco_read32(cc, SSB_CHIPCO_SLOWCLKCTL); |
| 174 | divisor = (tmp >> 16) + 1; |
| 175 | divisor *= 4; |
| 176 | break; |
| 177 | } |
| 178 | } else { |
| 179 | tmp = chipco_read32(cc, SSB_CHIPCO_SYSCLKCTL); |
| 180 | divisor = (tmp >> 16) + 1; |
| 181 | divisor *= 4; |
| 182 | } |
| 183 | |
| 184 | switch (clocksrc) { |
| 185 | case SSB_CHIPCO_CLKSRC_LOPWROS: |
| 186 | if (get_max) |
| 187 | limit = 43000; |
| 188 | else |
| 189 | limit = 25000; |
| 190 | break; |
| 191 | case SSB_CHIPCO_CLKSRC_XTALOS: |
| 192 | if (get_max) |
| 193 | limit = 20200000; |
| 194 | else |
| 195 | limit = 19800000; |
| 196 | break; |
| 197 | case SSB_CHIPCO_CLKSRC_PCI: |
| 198 | if (get_max) |
| 199 | limit = 34000000; |
| 200 | else |
| 201 | limit = 25000000; |
| 202 | break; |
| 203 | } |
| 204 | limit /= divisor; |
| 205 | |
| 206 | return limit; |
| 207 | } |
| 208 | |
| 209 | static void chipco_powercontrol_init(struct ssb_chipcommon *cc) |
| 210 | { |
| 211 | struct ssb_bus *bus = cc->dev->bus; |
| 212 | |
| 213 | if (bus->chip_id == 0x4321) { |
| 214 | if (bus->chip_rev == 0) |
| 215 | chipco_write32(cc, SSB_CHIPCO_CHIPCTL, 0x3A4); |
| 216 | else if (bus->chip_rev == 1) |
| 217 | chipco_write32(cc, SSB_CHIPCO_CHIPCTL, 0xA4); |
| 218 | } |
| 219 | |
| 220 | if (!(cc->capabilities & SSB_CHIPCO_CAP_PCTL)) |
| 221 | return; |
| 222 | |
| 223 | if (cc->dev->id.revision >= 10) { |
| 224 | /* Set Idle Power clock rate to 1Mhz */ |
| 225 | chipco_write32(cc, SSB_CHIPCO_SYSCLKCTL, |
| 226 | (chipco_read32(cc, SSB_CHIPCO_SYSCLKCTL) & |
| 227 | 0x0000FFFF) | 0x00040000); |
| 228 | } else { |
| 229 | int maxfreq; |
| 230 | |
| 231 | maxfreq = chipco_pctl_clockfreqlimit(cc, 1); |
| 232 | chipco_write32(cc, SSB_CHIPCO_PLLONDELAY, |
| 233 | (maxfreq * 150 + 999999) / 1000000); |
| 234 | chipco_write32(cc, SSB_CHIPCO_FREFSELDELAY, |
| 235 | (maxfreq * 15 + 999999) / 1000000); |
| 236 | } |
| 237 | } |
| 238 | |
Rafał Miłecki | fd51594 | 2010-05-24 21:50:24 +0200 | [diff] [blame] | 239 | /* http://bcm-v4.sipsolutions.net/802.11/PmuFastPwrupDelay */ |
| 240 | static u16 pmu_fast_powerup_delay(struct ssb_chipcommon *cc) |
| 241 | { |
| 242 | struct ssb_bus *bus = cc->dev->bus; |
| 243 | |
| 244 | switch (bus->chip_id) { |
| 245 | case 0x4312: |
| 246 | case 0x4322: |
| 247 | case 0x4328: |
| 248 | return 7000; |
| 249 | case 0x4325: |
| 250 | /* TODO: */ |
| 251 | default: |
| 252 | return 15000; |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | /* http://bcm-v4.sipsolutions.net/802.11/ClkctlFastPwrupDelay */ |
Michael Buesch | 61e115a | 2007-09-18 15:12:50 -0400 | [diff] [blame] | 257 | static void calc_fast_powerup_delay(struct ssb_chipcommon *cc) |
| 258 | { |
| 259 | struct ssb_bus *bus = cc->dev->bus; |
| 260 | int minfreq; |
| 261 | unsigned int tmp; |
| 262 | u32 pll_on_delay; |
| 263 | |
| 264 | if (bus->bustype != SSB_BUSTYPE_PCI) |
| 265 | return; |
Rafał Miłecki | fd51594 | 2010-05-24 21:50:24 +0200 | [diff] [blame] | 266 | |
| 267 | if (cc->capabilities & SSB_CHIPCO_CAP_PMU) { |
| 268 | cc->fast_pwrup_delay = pmu_fast_powerup_delay(cc); |
| 269 | return; |
| 270 | } |
| 271 | |
Michael Buesch | 61e115a | 2007-09-18 15:12:50 -0400 | [diff] [blame] | 272 | if (!(cc->capabilities & SSB_CHIPCO_CAP_PCTL)) |
| 273 | return; |
| 274 | |
| 275 | minfreq = chipco_pctl_clockfreqlimit(cc, 0); |
| 276 | pll_on_delay = chipco_read32(cc, SSB_CHIPCO_PLLONDELAY); |
| 277 | tmp = (((pll_on_delay + 2) * 1000000) + (minfreq - 1)) / minfreq; |
| 278 | SSB_WARN_ON(tmp & ~0xFFFF); |
| 279 | |
| 280 | cc->fast_pwrup_delay = tmp; |
| 281 | } |
| 282 | |
Hauke Mehrtens | f924e1e | 2012-12-05 18:46:03 +0100 | [diff] [blame^] | 283 | static u32 ssb_chipco_alp_clock(struct ssb_chipcommon *cc) |
| 284 | { |
| 285 | if (cc->capabilities & SSB_CHIPCO_CAP_PMU) |
| 286 | return ssb_pmu_get_alp_clock(cc); |
| 287 | |
| 288 | return 20000000; |
| 289 | } |
| 290 | |
Michael Buesch | 61e115a | 2007-09-18 15:12:50 -0400 | [diff] [blame] | 291 | void ssb_chipcommon_init(struct ssb_chipcommon *cc) |
| 292 | { |
| 293 | if (!cc->dev) |
| 294 | return; /* We don't have a ChipCommon */ |
John W. Linville | d53cdbb | 2010-03-31 21:39:35 +0200 | [diff] [blame] | 295 | if (cc->dev->id.revision >= 11) |
| 296 | cc->status = chipco_read32(cc, SSB_CHIPCO_CHIPSTAT); |
Larry Finger | 9d1ac34 | 2010-05-14 22:08:58 -0500 | [diff] [blame] | 297 | ssb_dprintk(KERN_INFO PFX "chipcommon status is 0x%x\n", cc->status); |
Rafał Miłecki | 9835a30 | 2011-04-24 11:04:19 +0200 | [diff] [blame] | 298 | |
| 299 | if (cc->dev->id.revision >= 20) { |
| 300 | chipco_write32(cc, SSB_CHIPCO_GPIOPULLUP, 0); |
| 301 | chipco_write32(cc, SSB_CHIPCO_GPIOPULLDOWN, 0); |
| 302 | } |
| 303 | |
Michael Buesch | c970314 | 2009-02-03 19:23:18 +0100 | [diff] [blame] | 304 | ssb_pmu_init(cc); |
Michael Buesch | 61e115a | 2007-09-18 15:12:50 -0400 | [diff] [blame] | 305 | chipco_powercontrol_init(cc); |
| 306 | ssb_chipco_set_clockmode(cc, SSB_CLKMODE_FAST); |
| 307 | calc_fast_powerup_delay(cc); |
| 308 | } |
| 309 | |
Michael Buesch | 8fe2b65 | 2008-03-30 00:10:50 +0100 | [diff] [blame] | 310 | void ssb_chipco_suspend(struct ssb_chipcommon *cc) |
Michael Buesch | 61e115a | 2007-09-18 15:12:50 -0400 | [diff] [blame] | 311 | { |
| 312 | if (!cc->dev) |
| 313 | return; |
| 314 | ssb_chipco_set_clockmode(cc, SSB_CLKMODE_SLOW); |
| 315 | } |
| 316 | |
| 317 | void ssb_chipco_resume(struct ssb_chipcommon *cc) |
| 318 | { |
| 319 | if (!cc->dev) |
| 320 | return; |
| 321 | chipco_powercontrol_init(cc); |
| 322 | ssb_chipco_set_clockmode(cc, SSB_CLKMODE_FAST); |
| 323 | } |
| 324 | |
| 325 | /* Get the processor clock */ |
| 326 | void ssb_chipco_get_clockcpu(struct ssb_chipcommon *cc, |
| 327 | u32 *plltype, u32 *n, u32 *m) |
| 328 | { |
| 329 | *n = chipco_read32(cc, SSB_CHIPCO_CLOCK_N); |
| 330 | *plltype = (cc->capabilities & SSB_CHIPCO_CAP_PLLT); |
| 331 | switch (*plltype) { |
| 332 | case SSB_PLLTYPE_2: |
| 333 | case SSB_PLLTYPE_4: |
| 334 | case SSB_PLLTYPE_6: |
| 335 | case SSB_PLLTYPE_7: |
| 336 | *m = chipco_read32(cc, SSB_CHIPCO_CLOCK_MIPS); |
| 337 | break; |
| 338 | case SSB_PLLTYPE_3: |
| 339 | /* 5350 uses m2 to control mips */ |
| 340 | *m = chipco_read32(cc, SSB_CHIPCO_CLOCK_M2); |
| 341 | break; |
| 342 | default: |
| 343 | *m = chipco_read32(cc, SSB_CHIPCO_CLOCK_SB); |
| 344 | break; |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | /* Get the bus clock */ |
| 349 | void ssb_chipco_get_clockcontrol(struct ssb_chipcommon *cc, |
| 350 | u32 *plltype, u32 *n, u32 *m) |
| 351 | { |
| 352 | *n = chipco_read32(cc, SSB_CHIPCO_CLOCK_N); |
| 353 | *plltype = (cc->capabilities & SSB_CHIPCO_CAP_PLLT); |
| 354 | switch (*plltype) { |
| 355 | case SSB_PLLTYPE_6: /* 100/200 or 120/240 only */ |
| 356 | *m = chipco_read32(cc, SSB_CHIPCO_CLOCK_MIPS); |
| 357 | break; |
| 358 | case SSB_PLLTYPE_3: /* 25Mhz, 2 dividers */ |
| 359 | if (cc->dev->bus->chip_id != 0x5365) { |
| 360 | *m = chipco_read32(cc, SSB_CHIPCO_CLOCK_M2); |
| 361 | break; |
| 362 | } |
| 363 | /* Fallthough */ |
| 364 | default: |
| 365 | *m = chipco_read32(cc, SSB_CHIPCO_CLOCK_SB); |
| 366 | } |
| 367 | } |
| 368 | |
| 369 | void ssb_chipco_timing_init(struct ssb_chipcommon *cc, |
| 370 | unsigned long ns) |
| 371 | { |
| 372 | struct ssb_device *dev = cc->dev; |
| 373 | struct ssb_bus *bus = dev->bus; |
| 374 | u32 tmp; |
| 375 | |
| 376 | /* set register for external IO to control LED. */ |
| 377 | chipco_write32(cc, SSB_CHIPCO_PROG_CFG, 0x11); |
| 378 | tmp = DIV_ROUND_UP(10, ns) << SSB_PROG_WCNT_3_SHIFT; /* Waitcount-3 = 10ns */ |
| 379 | tmp |= DIV_ROUND_UP(40, ns) << SSB_PROG_WCNT_1_SHIFT; /* Waitcount-1 = 40ns */ |
| 380 | tmp |= DIV_ROUND_UP(240, ns); /* Waitcount-0 = 240ns */ |
| 381 | chipco_write32(cc, SSB_CHIPCO_PROG_WAITCNT, tmp); /* 0x01020a0c for a 100Mhz clock */ |
| 382 | |
| 383 | /* Set timing for the flash */ |
| 384 | tmp = DIV_ROUND_UP(10, ns) << SSB_FLASH_WCNT_3_SHIFT; /* Waitcount-3 = 10nS */ |
| 385 | tmp |= DIV_ROUND_UP(10, ns) << SSB_FLASH_WCNT_1_SHIFT; /* Waitcount-1 = 10nS */ |
| 386 | tmp |= DIV_ROUND_UP(120, ns); /* Waitcount-0 = 120nS */ |
| 387 | if ((bus->chip_id == 0x5365) || |
| 388 | (dev->id.revision < 9)) |
| 389 | chipco_write32(cc, SSB_CHIPCO_FLASH_WAITCNT, tmp); |
| 390 | if ((bus->chip_id == 0x5365) || |
| 391 | (dev->id.revision < 9) || |
| 392 | ((bus->chip_id == 0x5350) && (bus->chip_rev == 0))) |
| 393 | chipco_write32(cc, SSB_CHIPCO_PCMCIA_MEMWAIT, tmp); |
| 394 | |
| 395 | if (bus->chip_id == 0x5350) { |
| 396 | /* Enable EXTIF */ |
| 397 | tmp = DIV_ROUND_UP(10, ns) << SSB_PROG_WCNT_3_SHIFT; /* Waitcount-3 = 10ns */ |
| 398 | tmp |= DIV_ROUND_UP(20, ns) << SSB_PROG_WCNT_2_SHIFT; /* Waitcount-2 = 20ns */ |
| 399 | tmp |= DIV_ROUND_UP(100, ns) << SSB_PROG_WCNT_1_SHIFT; /* Waitcount-1 = 100ns */ |
| 400 | tmp |= DIV_ROUND_UP(120, ns); /* Waitcount-0 = 120ns */ |
| 401 | chipco_write32(cc, SSB_CHIPCO_PROG_WAITCNT, tmp); /* 0x01020a0c for a 100Mhz clock */ |
| 402 | } |
| 403 | } |
| 404 | |
| 405 | /* Set chip watchdog reset timer to fire in 'ticks' backplane cycles */ |
Michael Buesch | 6b9bafe | 2007-09-19 18:55:12 +0200 | [diff] [blame] | 406 | void ssb_chipco_watchdog_timer_set(struct ssb_chipcommon *cc, u32 ticks) |
Michael Buesch | 61e115a | 2007-09-18 15:12:50 -0400 | [diff] [blame] | 407 | { |
| 408 | /* instant NMI */ |
| 409 | chipco_write32(cc, SSB_CHIPCO_WATCHDOG, ticks); |
| 410 | } |
| 411 | |
Aurelien Jarno | 28de57d | 2008-02-22 16:14:58 +0100 | [diff] [blame] | 412 | void ssb_chipco_irq_mask(struct ssb_chipcommon *cc, u32 mask, u32 value) |
| 413 | { |
| 414 | chipco_write32_masked(cc, SSB_CHIPCO_IRQMASK, mask, value); |
| 415 | } |
| 416 | |
| 417 | u32 ssb_chipco_irq_status(struct ssb_chipcommon *cc, u32 mask) |
| 418 | { |
| 419 | return chipco_read32(cc, SSB_CHIPCO_IRQSTAT) & mask; |
| 420 | } |
| 421 | |
Michael Buesch | 61e115a | 2007-09-18 15:12:50 -0400 | [diff] [blame] | 422 | u32 ssb_chipco_gpio_in(struct ssb_chipcommon *cc, u32 mask) |
| 423 | { |
| 424 | return chipco_read32(cc, SSB_CHIPCO_GPIOIN) & mask; |
| 425 | } |
| 426 | |
Michael Buesch | c2bcbe6 | 2008-02-19 14:53:35 +0100 | [diff] [blame] | 427 | u32 ssb_chipco_gpio_out(struct ssb_chipcommon *cc, u32 mask, u32 value) |
Michael Buesch | 61e115a | 2007-09-18 15:12:50 -0400 | [diff] [blame] | 428 | { |
Michael Buesch | c2bcbe6 | 2008-02-19 14:53:35 +0100 | [diff] [blame] | 429 | return chipco_write32_masked(cc, SSB_CHIPCO_GPIOOUT, mask, value); |
Michael Buesch | 61e115a | 2007-09-18 15:12:50 -0400 | [diff] [blame] | 430 | } |
| 431 | |
Michael Buesch | c2bcbe6 | 2008-02-19 14:53:35 +0100 | [diff] [blame] | 432 | u32 ssb_chipco_gpio_outen(struct ssb_chipcommon *cc, u32 mask, u32 value) |
Michael Buesch | 61e115a | 2007-09-18 15:12:50 -0400 | [diff] [blame] | 433 | { |
Michael Buesch | c2bcbe6 | 2008-02-19 14:53:35 +0100 | [diff] [blame] | 434 | return chipco_write32_masked(cc, SSB_CHIPCO_GPIOOUTEN, mask, value); |
Michael Buesch | 61e115a | 2007-09-18 15:12:50 -0400 | [diff] [blame] | 435 | } |
Michael Buesch | c2bcbe6 | 2008-02-19 14:53:35 +0100 | [diff] [blame] | 436 | |
| 437 | u32 ssb_chipco_gpio_control(struct ssb_chipcommon *cc, u32 mask, u32 value) |
| 438 | { |
| 439 | return chipco_write32_masked(cc, SSB_CHIPCO_GPIOCTL, mask, value); |
| 440 | } |
Larry Finger | 85373ee | 2010-03-10 10:41:32 -0600 | [diff] [blame] | 441 | EXPORT_SYMBOL(ssb_chipco_gpio_control); |
Michael Buesch | c2bcbe6 | 2008-02-19 14:53:35 +0100 | [diff] [blame] | 442 | |
| 443 | u32 ssb_chipco_gpio_intmask(struct ssb_chipcommon *cc, u32 mask, u32 value) |
| 444 | { |
| 445 | return chipco_write32_masked(cc, SSB_CHIPCO_GPIOIRQ, mask, value); |
| 446 | } |
Michael Buesch | c2bcbe6 | 2008-02-19 14:53:35 +0100 | [diff] [blame] | 447 | |
| 448 | u32 ssb_chipco_gpio_polarity(struct ssb_chipcommon *cc, u32 mask, u32 value) |
| 449 | { |
| 450 | return chipco_write32_masked(cc, SSB_CHIPCO_GPIOPOL, mask, value); |
| 451 | } |
Michael Buesch | 61e115a | 2007-09-18 15:12:50 -0400 | [diff] [blame] | 452 | |
| 453 | #ifdef CONFIG_SSB_SERIAL |
| 454 | int ssb_chipco_serial_init(struct ssb_chipcommon *cc, |
| 455 | struct ssb_serial_port *ports) |
| 456 | { |
| 457 | struct ssb_bus *bus = cc->dev->bus; |
| 458 | int nr_ports = 0; |
| 459 | u32 plltype; |
| 460 | unsigned int irq; |
| 461 | u32 baud_base, div; |
| 462 | u32 i, n; |
Michael Buesch | 58ff70d | 2008-02-18 21:44:39 +0100 | [diff] [blame] | 463 | unsigned int ccrev = cc->dev->id.revision; |
Michael Buesch | 61e115a | 2007-09-18 15:12:50 -0400 | [diff] [blame] | 464 | |
| 465 | plltype = (cc->capabilities & SSB_CHIPCO_CAP_PLLT); |
| 466 | irq = ssb_mips_irq(cc->dev); |
| 467 | |
| 468 | if (plltype == SSB_PLLTYPE_1) { |
| 469 | /* PLL clock */ |
| 470 | baud_base = ssb_calc_clock_rate(plltype, |
| 471 | chipco_read32(cc, SSB_CHIPCO_CLOCK_N), |
| 472 | chipco_read32(cc, SSB_CHIPCO_CLOCK_M2)); |
| 473 | div = 1; |
| 474 | } else { |
Michael Buesch | 58ff70d | 2008-02-18 21:44:39 +0100 | [diff] [blame] | 475 | if (ccrev == 20) { |
| 476 | /* BCM5354 uses constant 25MHz clock */ |
| 477 | baud_base = 25000000; |
| 478 | div = 48; |
Michael Buesch | 61e115a | 2007-09-18 15:12:50 -0400 | [diff] [blame] | 479 | /* Set the override bit so we don't divide it */ |
| 480 | chipco_write32(cc, SSB_CHIPCO_CORECTL, |
Michael Buesch | 58ff70d | 2008-02-18 21:44:39 +0100 | [diff] [blame] | 481 | chipco_read32(cc, SSB_CHIPCO_CORECTL) |
| 482 | | SSB_CHIPCO_CORECTL_UARTCLK0); |
| 483 | } else if ((ccrev >= 11) && (ccrev != 15)) { |
Hauke Mehrtens | f924e1e | 2012-12-05 18:46:03 +0100 | [diff] [blame^] | 484 | baud_base = ssb_chipco_alp_clock(cc); |
Michael Buesch | 58ff70d | 2008-02-18 21:44:39 +0100 | [diff] [blame] | 485 | div = 1; |
| 486 | if (ccrev >= 21) { |
| 487 | /* Turn off UART clock before switching clocksource. */ |
| 488 | chipco_write32(cc, SSB_CHIPCO_CORECTL, |
| 489 | chipco_read32(cc, SSB_CHIPCO_CORECTL) |
| 490 | & ~SSB_CHIPCO_CORECTL_UARTCLKEN); |
| 491 | } |
| 492 | /* Set the override bit so we don't divide it */ |
| 493 | chipco_write32(cc, SSB_CHIPCO_CORECTL, |
| 494 | chipco_read32(cc, SSB_CHIPCO_CORECTL) |
| 495 | | SSB_CHIPCO_CORECTL_UARTCLK0); |
| 496 | if (ccrev >= 21) { |
| 497 | /* Re-enable the UART clock. */ |
| 498 | chipco_write32(cc, SSB_CHIPCO_CORECTL, |
| 499 | chipco_read32(cc, SSB_CHIPCO_CORECTL) |
| 500 | | SSB_CHIPCO_CORECTL_UARTCLKEN); |
| 501 | } |
| 502 | } else if (ccrev >= 3) { |
Michael Buesch | 61e115a | 2007-09-18 15:12:50 -0400 | [diff] [blame] | 503 | /* Internal backplane clock */ |
| 504 | baud_base = ssb_clockspeed(bus); |
| 505 | div = chipco_read32(cc, SSB_CHIPCO_CLKDIV) |
| 506 | & SSB_CHIPCO_CLKDIV_UART; |
| 507 | } else { |
| 508 | /* Fixed internal backplane clock */ |
| 509 | baud_base = 88000000; |
| 510 | div = 48; |
| 511 | } |
| 512 | |
| 513 | /* Clock source depends on strapping if UartClkOverride is unset */ |
Michael Buesch | 58ff70d | 2008-02-18 21:44:39 +0100 | [diff] [blame] | 514 | if ((ccrev > 0) && |
Michael Buesch | 61e115a | 2007-09-18 15:12:50 -0400 | [diff] [blame] | 515 | !(chipco_read32(cc, SSB_CHIPCO_CORECTL) & SSB_CHIPCO_CORECTL_UARTCLK0)) { |
| 516 | if ((cc->capabilities & SSB_CHIPCO_CAP_UARTCLK) == |
| 517 | SSB_CHIPCO_CAP_UARTCLK_INT) { |
| 518 | /* Internal divided backplane clock */ |
| 519 | baud_base /= div; |
| 520 | } else { |
| 521 | /* Assume external clock of 1.8432 MHz */ |
| 522 | baud_base = 1843200; |
| 523 | } |
| 524 | } |
| 525 | } |
| 526 | |
| 527 | /* Determine the registers of the UARTs */ |
| 528 | n = (cc->capabilities & SSB_CHIPCO_CAP_NRUART); |
| 529 | for (i = 0; i < n; i++) { |
| 530 | void __iomem *cc_mmio; |
| 531 | void __iomem *uart_regs; |
| 532 | |
| 533 | cc_mmio = cc->dev->bus->mmio + (cc->dev->core_index * SSB_CORE_SIZE); |
| 534 | uart_regs = cc_mmio + SSB_CHIPCO_UART0_DATA; |
| 535 | /* Offset changed at after rev 0 */ |
Michael Buesch | 58ff70d | 2008-02-18 21:44:39 +0100 | [diff] [blame] | 536 | if (ccrev == 0) |
Michael Buesch | 61e115a | 2007-09-18 15:12:50 -0400 | [diff] [blame] | 537 | uart_regs += (i * 8); |
| 538 | else |
| 539 | uart_regs += (i * 256); |
| 540 | |
| 541 | nr_ports++; |
| 542 | ports[i].regs = uart_regs; |
| 543 | ports[i].irq = irq; |
| 544 | ports[i].baud_base = baud_base; |
| 545 | ports[i].reg_shift = 0; |
| 546 | } |
| 547 | |
| 548 | return nr_ports; |
| 549 | } |
| 550 | #endif /* CONFIG_SSB_SERIAL */ |