Blame view
drivers/bcma/driver_chipcommon.c
10.3 KB
8369ae33b bcma: add Broadco... |
1 2 3 4 5 |
/* * Broadcom specific AMBA * ChipCommon core driver * * Copyright 2005, Broadcom Corporation |
eb032b983 Update my e-mail ... |
6 |
* Copyright 2006, 2007, Michael Buesch <m@bues.ch> |
56fd5f077 bcma: add bcma_ch... |
7 |
* Copyright 2012, Hauke Mehrtens <hauke@hauke-m.de> |
8369ae33b bcma: add Broadco... |
8 9 10 11 12 |
* * Licensed under the GNU/GPL. See COPYING for details. */ #include "bcma_private.h" |
a22a3114a bcma: add methods... |
13 |
#include <linux/bcm47xx_wdt.h> |
44a8e3772 bcma: fix implici... |
14 |
#include <linux/export.h> |
a4855f39d bcma: register wa... |
15 |
#include <linux/platform_device.h> |
8369ae33b bcma: add Broadco... |
16 17 18 19 20 21 22 23 24 25 26 |
#include <linux/bcma/bcma.h> static inline u32 bcma_cc_write32_masked(struct bcma_drv_cc *cc, u16 offset, u32 mask, u32 value) { value &= mask; value |= bcma_cc_read32(cc, offset) & ~mask; bcma_cc_write32(cc, offset, value); return value; } |
6951618b4 bcma: export bcma... |
27 |
u32 bcma_chipco_get_alp_clock(struct bcma_drv_cc *cc) |
56fd5f077 bcma: add bcma_ch... |
28 29 |
{ if (cc->capabilities & BCMA_CC_CAP_PMU) |
5b5ac4144 bcma: unify namin... |
30 |
return bcma_pmu_get_alp_clock(cc); |
56fd5f077 bcma: add bcma_ch... |
31 32 33 |
return 20000000; } |
6951618b4 bcma: export bcma... |
34 |
EXPORT_SYMBOL_GPL(bcma_chipco_get_alp_clock); |
56fd5f077 bcma: add bcma_ch... |
35 |
|
3f37ec79d bcma: support BCM... |
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
static bool bcma_core_cc_has_pmu_watchdog(struct bcma_drv_cc *cc) { struct bcma_bus *bus = cc->core->bus; if (cc->capabilities & BCMA_CC_CAP_PMU) { if (bus->chipinfo.id == BCMA_CHIP_ID_BCM53573) { WARN(bus->chipinfo.rev <= 1, "No watchdog available "); /* 53573B0 and 53573B1 have bugged PMU watchdog. It can * be enabled but timer can't be bumped. Use CC one * instead. */ return false; } return true; } else { return false; } } |
f6354c8cf bcma: set the pmu... |
55 56 57 58 |
static u32 bcma_chipco_watchdog_get_max_timer(struct bcma_drv_cc *cc) { struct bcma_bus *bus = cc->core->bus; u32 nb; |
3f37ec79d bcma: support BCM... |
59 |
if (bcma_core_cc_has_pmu_watchdog(cc)) { |
f6354c8cf bcma: set the pmu... |
60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
if (bus->chipinfo.id == BCMA_CHIP_ID_BCM4706) nb = 32; else if (cc->core->id.rev < 26) nb = 16; else nb = (cc->core->id.rev >= 37) ? 32 : 24; } else { nb = 28; } if (nb == 32) return 0xffffffff; else return (1 << nb) - 1; } |
a22a3114a bcma: add methods... |
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
static u32 bcma_chipco_watchdog_timer_set_wdt(struct bcm47xx_wdt *wdt, u32 ticks) { struct bcma_drv_cc *cc = bcm47xx_wdt_get_drvdata(wdt); return bcma_chipco_watchdog_timer_set(cc, ticks); } static u32 bcma_chipco_watchdog_timer_set_ms_wdt(struct bcm47xx_wdt *wdt, u32 ms) { struct bcma_drv_cc *cc = bcm47xx_wdt_get_drvdata(wdt); u32 ticks; ticks = bcma_chipco_watchdog_timer_set(cc, cc->ticks_per_ms * ms); return ticks / cc->ticks_per_ms; } static int bcma_chipco_watchdog_ticks_per_ms(struct bcma_drv_cc *cc) { struct bcma_bus *bus = cc->core->bus; if (cc->capabilities & BCMA_CC_CAP_PMU) { if (bus->chipinfo.id == BCMA_CHIP_ID_BCM4706) |
d0f66df53 bcma: fix three c... |
98 99 100 |
/* 4706 CC and PMU watchdogs are clocked at 1/4 of ALP * clock */ |
5b5ac4144 bcma: unify namin... |
101 |
return bcma_chipco_get_alp_clock(cc) / 4000; |
a22a3114a bcma: add methods... |
102 103 104 105 |
else /* based on 32KHz ILP clock */ return 32; } else { |
5b5ac4144 bcma: unify namin... |
106 |
return bcma_chipco_get_alp_clock(cc) / 1000; |
a22a3114a bcma: add methods... |
107 108 |
} } |
f6354c8cf bcma: set the pmu... |
109 |
|
a4855f39d bcma: register wa... |
110 111 |
int bcma_chipco_watchdog_register(struct bcma_drv_cc *cc) { |
3f37ec79d bcma: support BCM... |
112 |
struct bcma_bus *bus = cc->core->bus; |
a4855f39d bcma: register wa... |
113 114 |
struct bcm47xx_wdt wdt = {}; struct platform_device *pdev; |
3f37ec79d bcma: support BCM... |
115 116 117 118 119 120 |
if (bus->chipinfo.id == BCMA_CHIP_ID_BCM53573 && bus->chipinfo.rev <= 1) { pr_debug("No watchdog on 53573A0 / 53573A1 "); return 0; } |
a4855f39d bcma: register wa... |
121 122 123 |
wdt.driver_data = cc; wdt.timer_set = bcma_chipco_watchdog_timer_set_wdt; wdt.timer_set_ms = bcma_chipco_watchdog_timer_set_ms_wdt; |
d0f66df53 bcma: fix three c... |
124 125 |
wdt.max_timer_ms = bcma_chipco_watchdog_get_max_timer(cc) / cc->ticks_per_ms; |
a4855f39d bcma: register wa... |
126 127 |
pdev = platform_device_register_data(NULL, "bcm47xx-wdt", |
3f37ec79d bcma: support BCM... |
128 |
bus->num, &wdt, |
a4855f39d bcma: register wa... |
129 130 131 132 133 134 135 136 |
sizeof(wdt)); if (IS_ERR(pdev)) return PTR_ERR(pdev); cc->watchdog = pdev; return 0; } |
0ea6f0c58 bcma: move flash ... |
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
static void bcma_core_chipcommon_flash_detect(struct bcma_drv_cc *cc) { struct bcma_bus *bus = cc->core->bus; switch (cc->capabilities & BCMA_CC_CAP_FLASHT) { case BCMA_CC_FLASHT_STSER: case BCMA_CC_FLASHT_ATSER: bcma_debug(bus, "Found serial flash "); bcma_sflash_init(cc); break; case BCMA_CC_FLASHT_PARA: bcma_debug(bus, "Found parallel flash "); bcma_pflash_init(cc); break; default: bcma_err(bus, "Flash type not supported "); } if (cc->core->id.rev == 38 || bus->chipinfo.id == BCMA_CHIP_ID_BCM4706) { if (cc->capabilities & BCMA_CC_CAP_NFLASH) { bcma_debug(bus, "Found NAND flash "); bcma_nflash_init(cc); } } } |
49655bb8a bcma: just do the... |
167 |
void bcma_core_chipcommon_early_init(struct bcma_drv_cc *cc) |
8369ae33b bcma: add Broadco... |
168 |
{ |
4c81acab3 bcma: init serial... |
169 |
struct bcma_bus *bus = cc->core->bus; |
49655bb8a bcma: just do the... |
170 |
if (cc->early_setup_done) |
517f43e5a bcma: add functio... |
171 |
return; |
ef85fb283 bcma: add locking... |
172 |
spin_lock_init(&cc->gpio_lock); |
8369ae33b bcma: add Broadco... |
173 174 175 176 177 |
if (cc->core->id.rev >= 11) cc->status = bcma_cc_read32(cc, BCMA_CC_CHIPSTAT); cc->capabilities = bcma_cc_read32(cc, BCMA_CC_CAP); if (cc->core->id.rev >= 35) cc->capabilities_ext = bcma_cc_read32(cc, BCMA_CC_CAP_EXT); |
49655bb8a bcma: just do the... |
178 179 |
if (cc->capabilities & BCMA_CC_CAP_PMU) bcma_pmu_early_init(cc); |
0ea6f0c58 bcma: move flash ... |
180 181 |
if (bus->hosttype == BCMA_HOSTTYPE_SOC) bcma_core_chipcommon_flash_detect(cc); |
49655bb8a bcma: just do the... |
182 183 184 185 186 187 188 189 190 191 192 193 |
cc->early_setup_done = true; } void bcma_core_chipcommon_init(struct bcma_drv_cc *cc) { u32 leddc_on = 10; u32 leddc_off = 90; if (cc->setup_done) return; bcma_core_chipcommon_early_init(cc); |
1073e4ee5 bcma: add missing... |
194 |
if (cc->core->id.rev >= 20) { |
88f9b65d4 bcma: add support... |
195 196 197 198 199 200 201 202 203 |
u32 pullup = 0, pulldown = 0; if (cc->core->bus->chipinfo.id == BCMA_CHIP_ID_BCM43142) { pullup = 0x402e0; pulldown = 0x20500; } bcma_cc_write32(cc, BCMA_CC_GPIOPULLUP, pullup); bcma_cc_write32(cc, BCMA_CC_GPIOPULLDOWN, pulldown); |
1073e4ee5 bcma: add missing... |
204 |
} |
8369ae33b bcma: add Broadco... |
205 206 207 208 |
if (cc->capabilities & BCMA_CC_CAP_PMU) bcma_pmu_init(cc); if (cc->capabilities & BCMA_CC_CAP_PCTL) |
3d9d8af33 bcma: use custom ... |
209 210 |
bcma_err(cc->core->bus, "Power control not implemented! "); |
18dfa4952 bcma: cc: set GPI... |
211 212 213 214 215 216 217 218 219 220 221 |
if (cc->core->id.rev >= 16) { if (cc->core->bus->sprom.leddc_on_time && cc->core->bus->sprom.leddc_off_time) { leddc_on = cc->core->bus->sprom.leddc_on_time; leddc_off = cc->core->bus->sprom.leddc_off_time; } bcma_cc_write32(cc, BCMA_CC_GPIOTIMER, ((leddc_on << BCMA_CC_GPIOTIMER_ONTIME_SHIFT) | (leddc_off << BCMA_CC_GPIOTIMER_OFFTIME_SHIFT))); } |
a22a3114a bcma: add methods... |
222 |
cc->ticks_per_ms = bcma_chipco_watchdog_ticks_per_ms(cc); |
517f43e5a bcma: add functio... |
223 224 |
cc->setup_done = true; |
8369ae33b bcma: add Broadco... |
225 226 227 |
} /* Set chip watchdog reset timer to fire in 'ticks' backplane cycles */ |
a22a3114a bcma: add methods... |
228 |
u32 bcma_chipco_watchdog_timer_set(struct bcma_drv_cc *cc, u32 ticks) |
8369ae33b bcma: add Broadco... |
229 |
{ |
f6354c8cf bcma: set the pmu... |
230 |
u32 maxt; |
f6354c8cf bcma: set the pmu... |
231 232 |
maxt = bcma_chipco_watchdog_get_max_timer(cc); |
3f37ec79d bcma: support BCM... |
233 |
if (bcma_core_cc_has_pmu_watchdog(cc)) { |
f6354c8cf bcma: set the pmu... |
234 235 236 237 |
if (ticks == 1) ticks = 2; else if (ticks > maxt) ticks = maxt; |
b3c47afbf bcma: support PMU... |
238 |
bcma_pmu_write32(cc, BCMA_CC_PMU_WATCHDOG, ticks); |
f6354c8cf bcma: set the pmu... |
239 |
} else { |
68fcd2450 bcma: fix watchdo... |
240 241 242 |
struct bcma_bus *bus = cc->core->bus; if (bus->chipinfo.id != BCMA_CHIP_ID_BCM4707 && |
61dba73cd bcma: add support... |
243 |
bus->chipinfo.id != BCMA_CHIP_ID_BCM47094 && |
68fcd2450 bcma: fix watchdo... |
244 245 246 |
bus->chipinfo.id != BCMA_CHIP_ID_BCM53018) bcma_core_set_clockmode(cc->core, ticks ? BCMA_CLKMODE_FAST : BCMA_CLKMODE_DYNAMIC); |
f6354c8cf bcma: set the pmu... |
247 248 249 250 251 |
if (ticks > maxt) ticks = maxt; /* instant NMI */ bcma_cc_write32(cc, BCMA_CC_WATCHDOG, ticks); } |
a22a3114a bcma: add methods... |
252 |
return ticks; |
8369ae33b bcma: add Broadco... |
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 |
} void bcma_chipco_irq_mask(struct bcma_drv_cc *cc, u32 mask, u32 value) { bcma_cc_write32_masked(cc, BCMA_CC_IRQMASK, mask, value); } u32 bcma_chipco_irq_status(struct bcma_drv_cc *cc, u32 mask) { return bcma_cc_read32(cc, BCMA_CC_IRQSTAT) & mask; } u32 bcma_chipco_gpio_in(struct bcma_drv_cc *cc, u32 mask) { return bcma_cc_read32(cc, BCMA_CC_GPIOIN) & mask; } u32 bcma_chipco_gpio_out(struct bcma_drv_cc *cc, u32 mask, u32 value) { |
ef85fb283 bcma: add locking... |
272 273 274 275 276 277 278 279 |
unsigned long flags; u32 res; spin_lock_irqsave(&cc->gpio_lock, flags); res = bcma_cc_write32_masked(cc, BCMA_CC_GPIOOUT, mask, value); spin_unlock_irqrestore(&cc->gpio_lock, flags); return res; |
8369ae33b bcma: add Broadco... |
280 |
} |
ca84a6c5f bcma: export some... |
281 |
EXPORT_SYMBOL_GPL(bcma_chipco_gpio_out); |
8369ae33b bcma: add Broadco... |
282 283 284 |
u32 bcma_chipco_gpio_outen(struct bcma_drv_cc *cc, u32 mask, u32 value) { |
ef85fb283 bcma: add locking... |
285 286 287 288 289 290 291 292 |
unsigned long flags; u32 res; spin_lock_irqsave(&cc->gpio_lock, flags); res = bcma_cc_write32_masked(cc, BCMA_CC_GPIOOUTEN, mask, value); spin_unlock_irqrestore(&cc->gpio_lock, flags); return res; |
8369ae33b bcma: add Broadco... |
293 |
} |
ca84a6c5f bcma: export some... |
294 |
EXPORT_SYMBOL_GPL(bcma_chipco_gpio_outen); |
8369ae33b bcma: add Broadco... |
295 |
|
3e8bb507e bcma: add comment... |
296 297 298 299 |
/* * If the bit is set to 0, chipcommon controlls this GPIO, * if the bit is set to 1, it is used by some part of the chip and not our code. */ |
8369ae33b bcma: add Broadco... |
300 301 |
u32 bcma_chipco_gpio_control(struct bcma_drv_cc *cc, u32 mask, u32 value) { |
ef85fb283 bcma: add locking... |
302 303 304 305 306 307 308 309 |
unsigned long flags; u32 res; spin_lock_irqsave(&cc->gpio_lock, flags); res = bcma_cc_write32_masked(cc, BCMA_CC_GPIOCTL, mask, value); spin_unlock_irqrestore(&cc->gpio_lock, flags); return res; |
8369ae33b bcma: add Broadco... |
310 311 312 313 314 |
} EXPORT_SYMBOL_GPL(bcma_chipco_gpio_control); u32 bcma_chipco_gpio_intmask(struct bcma_drv_cc *cc, u32 mask, u32 value) { |
ef85fb283 bcma: add locking... |
315 316 317 318 319 320 321 322 |
unsigned long flags; u32 res; spin_lock_irqsave(&cc->gpio_lock, flags); res = bcma_cc_write32_masked(cc, BCMA_CC_GPIOIRQ, mask, value); spin_unlock_irqrestore(&cc->gpio_lock, flags); return res; |
8369ae33b bcma: add Broadco... |
323 324 325 326 |
} u32 bcma_chipco_gpio_polarity(struct bcma_drv_cc *cc, u32 mask, u32 value) { |
ef85fb283 bcma: add locking... |
327 328 329 330 331 332 333 334 |
unsigned long flags; u32 res; spin_lock_irqsave(&cc->gpio_lock, flags); res = bcma_cc_write32_masked(cc, BCMA_CC_GPIOPOL, mask, value); spin_unlock_irqrestore(&cc->gpio_lock, flags); return res; |
8369ae33b bcma: add Broadco... |
335 |
} |
e3afe0e5b bcma: add serial ... |
336 |
|
ea3488f46 bcma: add bcma_ch... |
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 |
u32 bcma_chipco_gpio_pullup(struct bcma_drv_cc *cc, u32 mask, u32 value) { unsigned long flags; u32 res; if (cc->core->id.rev < 20) return 0; spin_lock_irqsave(&cc->gpio_lock, flags); res = bcma_cc_write32_masked(cc, BCMA_CC_GPIOPULLUP, mask, value); spin_unlock_irqrestore(&cc->gpio_lock, flags); return res; } u32 bcma_chipco_gpio_pulldown(struct bcma_drv_cc *cc, u32 mask, u32 value) { unsigned long flags; u32 res; if (cc->core->id.rev < 20) return 0; spin_lock_irqsave(&cc->gpio_lock, flags); res = bcma_cc_write32_masked(cc, BCMA_CC_GPIOPULLDOWN, mask, value); spin_unlock_irqrestore(&cc->gpio_lock, flags); return res; |
8369ae33b bcma: add Broadco... |
365 |
} |
e3afe0e5b bcma: add serial ... |
366 |
|
7195439d1 Revert "bcma: ini... |
367 368 |
#ifdef CONFIG_BCMA_DRIVER_MIPS void bcma_chipco_serial_init(struct bcma_drv_cc *cc) |
e3afe0e5b bcma: add serial ... |
369 370 371 372 373 374 375 376 |
{ unsigned int irq; u32 baud_base; u32 i; unsigned int ccrev = cc->core->id.rev; struct bcma_serial_port *ports = cc->serial_ports; if (ccrev >= 11 && ccrev != 15) { |
5b5ac4144 bcma: unify namin... |
377 |
baud_base = bcma_chipco_get_alp_clock(cc); |
e3afe0e5b bcma: add serial ... |
378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 |
if (ccrev >= 21) { /* Turn off UART clock before switching clocksource. */ bcma_cc_write32(cc, BCMA_CC_CORECTL, bcma_cc_read32(cc, BCMA_CC_CORECTL) & ~BCMA_CC_CORECTL_UARTCLKEN); } /* Set the override bit so we don't divide it */ bcma_cc_write32(cc, BCMA_CC_CORECTL, bcma_cc_read32(cc, BCMA_CC_CORECTL) | BCMA_CC_CORECTL_UARTCLK0); if (ccrev >= 21) { /* Re-enable the UART clock. */ bcma_cc_write32(cc, BCMA_CC_CORECTL, bcma_cc_read32(cc, BCMA_CC_CORECTL) | BCMA_CC_CORECTL_UARTCLKEN); } } else { |
d0f66df53 bcma: fix three c... |
395 396 397 |
bcma_err(cc->core->bus, "serial not supported on this device ccrev: 0x%x ", ccrev); |
e3afe0e5b bcma: add serial ... |
398 399 |
return; } |
85eb92e81 bcma: make it pos... |
400 |
irq = bcma_core_irq(cc->core, 0); |
e3afe0e5b bcma: add serial ... |
401 402 403 404 405 406 407 408 409 410 411 |
/* Determine the registers of the UARTs */ cc->nr_serial_ports = (cc->capabilities & BCMA_CC_CAP_NRUART); for (i = 0; i < cc->nr_serial_ports; i++) { ports[i].regs = cc->core->io_addr + BCMA_CC_UART0_DATA + (i * 256); ports[i].irq = irq; ports[i].baud_base = baud_base; ports[i].reg_shift = 0; } } |
7195439d1 Revert "bcma: ini... |
412 |
#endif /* CONFIG_BCMA_DRIVER_MIPS */ |