161e115a5SMichael Buesch /*
261e115a5SMichael Buesch * Sonics Silicon Backplane
361e115a5SMichael Buesch * Broadcom ChipCommon core driver
461e115a5SMichael Buesch *
561e115a5SMichael Buesch * Copyright 2005, Broadcom Corporation
6eb032b98SMichael Büsch * Copyright 2006, 2007, Michael Buesch <m@bues.ch>
77ffbffe3SHauke Mehrtens * Copyright 2012, Hauke Mehrtens <hauke@hauke-m.de>
861e115a5SMichael Buesch *
961e115a5SMichael Buesch * Licensed under the GNU/GPL. See COPYING for details.
1061e115a5SMichael Buesch */
1161e115a5SMichael Buesch
12b8b6069cSMichael Büsch #include "ssb_private.h"
13b8b6069cSMichael Büsch
1461e115a5SMichael Buesch #include <linux/ssb/ssb.h>
1561e115a5SMichael Buesch #include <linux/ssb/ssb_regs.h>
161014c22eSPaul Gortmaker #include <linux/export.h>
1761e115a5SMichael Buesch #include <linux/pci.h>
187ffbffe3SHauke Mehrtens #include <linux/bcm47xx_wdt.h>
1961e115a5SMichael Buesch
2061e115a5SMichael Buesch
2161e115a5SMichael Buesch /* Clock sources */
2261e115a5SMichael Buesch enum ssb_clksrc {
2361e115a5SMichael Buesch /* PCI clock */
2461e115a5SMichael Buesch SSB_CHIPCO_CLKSRC_PCI,
2561e115a5SMichael Buesch /* Crystal slow clock oscillator */
2661e115a5SMichael Buesch SSB_CHIPCO_CLKSRC_XTALOS,
2761e115a5SMichael Buesch /* Low power oscillator */
2861e115a5SMichael Buesch SSB_CHIPCO_CLKSRC_LOPWROS,
2961e115a5SMichael Buesch };
3061e115a5SMichael Buesch
3161e115a5SMichael Buesch
chipco_write32_masked(struct ssb_chipcommon * cc,u16 offset,u32 mask,u32 value)32c2bcbe65SMichael Buesch static inline u32 chipco_write32_masked(struct ssb_chipcommon *cc, u16 offset,
3361e115a5SMichael Buesch u32 mask, u32 value)
3461e115a5SMichael Buesch {
3561e115a5SMichael Buesch value &= mask;
3661e115a5SMichael Buesch value |= chipco_read32(cc, offset) & ~mask;
3761e115a5SMichael Buesch chipco_write32(cc, offset, value);
38c2bcbe65SMichael Buesch
39c2bcbe65SMichael Buesch return value;
4061e115a5SMichael Buesch }
4161e115a5SMichael Buesch
ssb_chipco_set_clockmode(struct ssb_chipcommon * cc,enum ssb_clkmode mode)4261e115a5SMichael Buesch void ssb_chipco_set_clockmode(struct ssb_chipcommon *cc,
4361e115a5SMichael Buesch enum ssb_clkmode mode)
4461e115a5SMichael Buesch {
4561e115a5SMichael Buesch struct ssb_device *ccdev = cc->dev;
4661e115a5SMichael Buesch struct ssb_bus *bus;
4761e115a5SMichael Buesch u32 tmp;
4861e115a5SMichael Buesch
4961e115a5SMichael Buesch if (!ccdev)
5061e115a5SMichael Buesch return;
5161e115a5SMichael Buesch bus = ccdev->bus;
520ca69955SRafał Miłecki
530ca69955SRafał Miłecki /* We support SLOW only on 6..9 */
540ca69955SRafał Miłecki if (ccdev->id.revision >= 10 && mode == SSB_CLKMODE_SLOW)
550ca69955SRafał Miłecki mode = SSB_CLKMODE_DYNAMIC;
560ca69955SRafał Miłecki
570ca69955SRafał Miłecki if (cc->capabilities & SSB_CHIPCO_CAP_PMU)
580ca69955SRafał Miłecki return; /* PMU controls clockmode, separated function needed */
59209b4375SMichael Büsch WARN_ON(ccdev->id.revision >= 20);
600ca69955SRafał Miłecki
6161e115a5SMichael Buesch /* chipcommon cores prior to rev6 don't support dynamic clock control */
6261e115a5SMichael Buesch if (ccdev->id.revision < 6)
6361e115a5SMichael Buesch return;
640ca69955SRafał Miłecki
650ca69955SRafał Miłecki /* ChipCommon cores rev10+ need testing */
6661e115a5SMichael Buesch if (ccdev->id.revision >= 10)
6761e115a5SMichael Buesch return;
680ca69955SRafał Miłecki
6961e115a5SMichael Buesch if (!(cc->capabilities & SSB_CHIPCO_CAP_PCTL))
7061e115a5SMichael Buesch return;
7161e115a5SMichael Buesch
7261e115a5SMichael Buesch switch (mode) {
730ca69955SRafał Miłecki case SSB_CLKMODE_SLOW: /* For revs 6..9 only */
7461e115a5SMichael Buesch tmp = chipco_read32(cc, SSB_CHIPCO_SLOWCLKCTL);
7561e115a5SMichael Buesch tmp |= SSB_CHIPCO_SLOWCLKCTL_FSLOW;
7661e115a5SMichael Buesch chipco_write32(cc, SSB_CHIPCO_SLOWCLKCTL, tmp);
7761e115a5SMichael Buesch break;
7861e115a5SMichael Buesch case SSB_CLKMODE_FAST:
790ca69955SRafał Miłecki if (ccdev->id.revision < 10) {
8061e115a5SMichael Buesch ssb_pci_xtal(bus, SSB_GPIO_XTAL, 1); /* Force crystal on */
8161e115a5SMichael Buesch tmp = chipco_read32(cc, SSB_CHIPCO_SLOWCLKCTL);
8261e115a5SMichael Buesch tmp &= ~SSB_CHIPCO_SLOWCLKCTL_FSLOW;
8361e115a5SMichael Buesch tmp |= SSB_CHIPCO_SLOWCLKCTL_IPLL;
8461e115a5SMichael Buesch chipco_write32(cc, SSB_CHIPCO_SLOWCLKCTL, tmp);
850ca69955SRafał Miłecki } else {
860ca69955SRafał Miłecki chipco_write32(cc, SSB_CHIPCO_SYSCLKCTL,
870ca69955SRafał Miłecki (chipco_read32(cc, SSB_CHIPCO_SYSCLKCTL) |
880ca69955SRafał Miłecki SSB_CHIPCO_SYSCLKCTL_FORCEHT));
890ca69955SRafał Miłecki /* udelay(150); TODO: not available in early init */
900ca69955SRafał Miłecki }
9161e115a5SMichael Buesch break;
9261e115a5SMichael Buesch case SSB_CLKMODE_DYNAMIC:
930ca69955SRafał Miłecki if (ccdev->id.revision < 10) {
9461e115a5SMichael Buesch tmp = chipco_read32(cc, SSB_CHIPCO_SLOWCLKCTL);
9561e115a5SMichael Buesch tmp &= ~SSB_CHIPCO_SLOWCLKCTL_FSLOW;
9661e115a5SMichael Buesch tmp &= ~SSB_CHIPCO_SLOWCLKCTL_IPLL;
9761e115a5SMichael Buesch tmp &= ~SSB_CHIPCO_SLOWCLKCTL_ENXTAL;
980ca69955SRafał Miłecki if ((tmp & SSB_CHIPCO_SLOWCLKCTL_SRC) !=
990ca69955SRafał Miłecki SSB_CHIPCO_SLOWCLKCTL_SRC_XTAL)
10061e115a5SMichael Buesch tmp |= SSB_CHIPCO_SLOWCLKCTL_ENXTAL;
10161e115a5SMichael Buesch chipco_write32(cc, SSB_CHIPCO_SLOWCLKCTL, tmp);
10261e115a5SMichael Buesch
1030ca69955SRafał Miłecki /* For dynamic control, we have to release our xtal_pu
1040ca69955SRafał Miłecki * "force on" */
10561e115a5SMichael Buesch if (tmp & SSB_CHIPCO_SLOWCLKCTL_ENXTAL)
10661e115a5SMichael Buesch ssb_pci_xtal(bus, SSB_GPIO_XTAL, 0);
1070ca69955SRafał Miłecki } else {
1080ca69955SRafał Miłecki chipco_write32(cc, SSB_CHIPCO_SYSCLKCTL,
1090ca69955SRafał Miłecki (chipco_read32(cc, SSB_CHIPCO_SYSCLKCTL) &
1100ca69955SRafał Miłecki ~SSB_CHIPCO_SYSCLKCTL_FORCEHT));
1110ca69955SRafał Miłecki }
11261e115a5SMichael Buesch break;
11361e115a5SMichael Buesch default:
114209b4375SMichael Büsch WARN_ON(1);
11561e115a5SMichael Buesch }
11661e115a5SMichael Buesch }
11761e115a5SMichael Buesch
11861e115a5SMichael Buesch /* Get the Slow Clock Source */
chipco_pctl_get_slowclksrc(struct ssb_chipcommon * cc)11961e115a5SMichael Buesch static enum ssb_clksrc chipco_pctl_get_slowclksrc(struct ssb_chipcommon *cc)
12061e115a5SMichael Buesch {
12161e115a5SMichael Buesch struct ssb_bus *bus = cc->dev->bus;
1223f649ab7SKees Cook u32 tmp;
12361e115a5SMichael Buesch
12461e115a5SMichael Buesch if (cc->dev->id.revision < 6) {
12561e115a5SMichael Buesch if (bus->bustype == SSB_BUSTYPE_SSB ||
12661e115a5SMichael Buesch bus->bustype == SSB_BUSTYPE_PCMCIA)
12761e115a5SMichael Buesch return SSB_CHIPCO_CLKSRC_XTALOS;
12861e115a5SMichael Buesch if (bus->bustype == SSB_BUSTYPE_PCI) {
12961e115a5SMichael Buesch pci_read_config_dword(bus->host_pci, SSB_GPIO_OUT, &tmp);
13061e115a5SMichael Buesch if (tmp & 0x10)
13161e115a5SMichael Buesch return SSB_CHIPCO_CLKSRC_PCI;
13261e115a5SMichael Buesch return SSB_CHIPCO_CLKSRC_XTALOS;
13361e115a5SMichael Buesch }
13461e115a5SMichael Buesch }
13561e115a5SMichael Buesch if (cc->dev->id.revision < 10) {
13661e115a5SMichael Buesch tmp = chipco_read32(cc, SSB_CHIPCO_SLOWCLKCTL);
13761e115a5SMichael Buesch tmp &= 0x7;
13861e115a5SMichael Buesch if (tmp == 0)
13961e115a5SMichael Buesch return SSB_CHIPCO_CLKSRC_LOPWROS;
14061e115a5SMichael Buesch if (tmp == 1)
14161e115a5SMichael Buesch return SSB_CHIPCO_CLKSRC_XTALOS;
14261e115a5SMichael Buesch if (tmp == 2)
14361e115a5SMichael Buesch return SSB_CHIPCO_CLKSRC_PCI;
14461e115a5SMichael Buesch }
14561e115a5SMichael Buesch
14661e115a5SMichael Buesch return SSB_CHIPCO_CLKSRC_XTALOS;
14761e115a5SMichael Buesch }
14861e115a5SMichael Buesch
14961e115a5SMichael Buesch /* Get maximum or minimum (depending on get_max flag) slowclock frequency. */
chipco_pctl_clockfreqlimit(struct ssb_chipcommon * cc,int get_max)15061e115a5SMichael Buesch static int chipco_pctl_clockfreqlimit(struct ssb_chipcommon *cc, int get_max)
15161e115a5SMichael Buesch {
1523f649ab7SKees Cook int limit;
15361e115a5SMichael Buesch enum ssb_clksrc clocksrc;
15461e115a5SMichael Buesch int divisor = 1;
15561e115a5SMichael Buesch u32 tmp;
15661e115a5SMichael Buesch
15761e115a5SMichael Buesch clocksrc = chipco_pctl_get_slowclksrc(cc);
15861e115a5SMichael Buesch if (cc->dev->id.revision < 6) {
15961e115a5SMichael Buesch switch (clocksrc) {
16061e115a5SMichael Buesch case SSB_CHIPCO_CLKSRC_PCI:
16161e115a5SMichael Buesch divisor = 64;
16261e115a5SMichael Buesch break;
16361e115a5SMichael Buesch case SSB_CHIPCO_CLKSRC_XTALOS:
16461e115a5SMichael Buesch divisor = 32;
16561e115a5SMichael Buesch break;
16661e115a5SMichael Buesch default:
167209b4375SMichael Büsch WARN_ON(1);
16861e115a5SMichael Buesch }
16961e115a5SMichael Buesch } else if (cc->dev->id.revision < 10) {
17061e115a5SMichael Buesch switch (clocksrc) {
17161e115a5SMichael Buesch case SSB_CHIPCO_CLKSRC_LOPWROS:
17261e115a5SMichael Buesch break;
17361e115a5SMichael Buesch case SSB_CHIPCO_CLKSRC_XTALOS:
17461e115a5SMichael Buesch case SSB_CHIPCO_CLKSRC_PCI:
17561e115a5SMichael Buesch tmp = chipco_read32(cc, SSB_CHIPCO_SLOWCLKCTL);
17661e115a5SMichael Buesch divisor = (tmp >> 16) + 1;
17761e115a5SMichael Buesch divisor *= 4;
17861e115a5SMichael Buesch break;
17961e115a5SMichael Buesch }
18061e115a5SMichael Buesch } else {
18161e115a5SMichael Buesch tmp = chipco_read32(cc, SSB_CHIPCO_SYSCLKCTL);
18261e115a5SMichael Buesch divisor = (tmp >> 16) + 1;
18361e115a5SMichael Buesch divisor *= 4;
18461e115a5SMichael Buesch }
18561e115a5SMichael Buesch
18661e115a5SMichael Buesch switch (clocksrc) {
18761e115a5SMichael Buesch case SSB_CHIPCO_CLKSRC_LOPWROS:
18861e115a5SMichael Buesch if (get_max)
18961e115a5SMichael Buesch limit = 43000;
19061e115a5SMichael Buesch else
19161e115a5SMichael Buesch limit = 25000;
19261e115a5SMichael Buesch break;
19361e115a5SMichael Buesch case SSB_CHIPCO_CLKSRC_XTALOS:
19461e115a5SMichael Buesch if (get_max)
19561e115a5SMichael Buesch limit = 20200000;
19661e115a5SMichael Buesch else
19761e115a5SMichael Buesch limit = 19800000;
19861e115a5SMichael Buesch break;
19961e115a5SMichael Buesch case SSB_CHIPCO_CLKSRC_PCI:
20061e115a5SMichael Buesch if (get_max)
20161e115a5SMichael Buesch limit = 34000000;
20261e115a5SMichael Buesch else
20361e115a5SMichael Buesch limit = 25000000;
20461e115a5SMichael Buesch break;
20561e115a5SMichael Buesch }
20661e115a5SMichael Buesch limit /= divisor;
20761e115a5SMichael Buesch
20861e115a5SMichael Buesch return limit;
20961e115a5SMichael Buesch }
21061e115a5SMichael Buesch
chipco_powercontrol_init(struct ssb_chipcommon * cc)21161e115a5SMichael Buesch static void chipco_powercontrol_init(struct ssb_chipcommon *cc)
21261e115a5SMichael Buesch {
21361e115a5SMichael Buesch struct ssb_bus *bus = cc->dev->bus;
21461e115a5SMichael Buesch
21561e115a5SMichael Buesch if (bus->chip_id == 0x4321) {
21661e115a5SMichael Buesch if (bus->chip_rev == 0)
21761e115a5SMichael Buesch chipco_write32(cc, SSB_CHIPCO_CHIPCTL, 0x3A4);
21861e115a5SMichael Buesch else if (bus->chip_rev == 1)
21961e115a5SMichael Buesch chipco_write32(cc, SSB_CHIPCO_CHIPCTL, 0xA4);
22061e115a5SMichael Buesch }
22161e115a5SMichael Buesch
22261e115a5SMichael Buesch if (!(cc->capabilities & SSB_CHIPCO_CAP_PCTL))
22361e115a5SMichael Buesch return;
22461e115a5SMichael Buesch
22561e115a5SMichael Buesch if (cc->dev->id.revision >= 10) {
22661e115a5SMichael Buesch /* Set Idle Power clock rate to 1Mhz */
22761e115a5SMichael Buesch chipco_write32(cc, SSB_CHIPCO_SYSCLKCTL,
22861e115a5SMichael Buesch (chipco_read32(cc, SSB_CHIPCO_SYSCLKCTL) &
22961e115a5SMichael Buesch 0x0000FFFF) | 0x00040000);
23061e115a5SMichael Buesch } else {
23161e115a5SMichael Buesch int maxfreq;
23261e115a5SMichael Buesch
23361e115a5SMichael Buesch maxfreq = chipco_pctl_clockfreqlimit(cc, 1);
23461e115a5SMichael Buesch chipco_write32(cc, SSB_CHIPCO_PLLONDELAY,
23561e115a5SMichael Buesch (maxfreq * 150 + 999999) / 1000000);
23661e115a5SMichael Buesch chipco_write32(cc, SSB_CHIPCO_FREFSELDELAY,
23761e115a5SMichael Buesch (maxfreq * 15 + 999999) / 1000000);
23861e115a5SMichael Buesch }
23961e115a5SMichael Buesch }
24061e115a5SMichael Buesch
2410db5bc7bSAlexander A. Klimov /* https://bcm-v4.sipsolutions.net/802.11/PmuFastPwrupDelay */
pmu_fast_powerup_delay(struct ssb_chipcommon * cc)242fd515941SRafał Miłecki static u16 pmu_fast_powerup_delay(struct ssb_chipcommon *cc)
243fd515941SRafał Miłecki {
244fd515941SRafał Miłecki struct ssb_bus *bus = cc->dev->bus;
245fd515941SRafał Miłecki
246fd515941SRafał Miłecki switch (bus->chip_id) {
247fd515941SRafał Miłecki case 0x4312:
248fd515941SRafał Miłecki case 0x4322:
249fd515941SRafał Miłecki case 0x4328:
250fd515941SRafał Miłecki return 7000;
251fd515941SRafał Miłecki case 0x4325:
252fd515941SRafał Miłecki /* TODO: */
253fd515941SRafał Miłecki default:
254fd515941SRafał Miłecki return 15000;
255fd515941SRafał Miłecki }
256fd515941SRafał Miłecki }
257fd515941SRafał Miłecki
2580db5bc7bSAlexander A. Klimov /* https://bcm-v4.sipsolutions.net/802.11/ClkctlFastPwrupDelay */
calc_fast_powerup_delay(struct ssb_chipcommon * cc)25961e115a5SMichael Buesch static void calc_fast_powerup_delay(struct ssb_chipcommon *cc)
26061e115a5SMichael Buesch {
26161e115a5SMichael Buesch struct ssb_bus *bus = cc->dev->bus;
26261e115a5SMichael Buesch int minfreq;
26361e115a5SMichael Buesch unsigned int tmp;
26461e115a5SMichael Buesch u32 pll_on_delay;
26561e115a5SMichael Buesch
26661e115a5SMichael Buesch if (bus->bustype != SSB_BUSTYPE_PCI)
26761e115a5SMichael Buesch return;
268fd515941SRafał Miłecki
269fd515941SRafał Miłecki if (cc->capabilities & SSB_CHIPCO_CAP_PMU) {
270fd515941SRafał Miłecki cc->fast_pwrup_delay = pmu_fast_powerup_delay(cc);
271fd515941SRafał Miłecki return;
272fd515941SRafał Miłecki }
273fd515941SRafał Miłecki
27461e115a5SMichael Buesch if (!(cc->capabilities & SSB_CHIPCO_CAP_PCTL))
27561e115a5SMichael Buesch return;
27661e115a5SMichael Buesch
27761e115a5SMichael Buesch minfreq = chipco_pctl_clockfreqlimit(cc, 0);
27861e115a5SMichael Buesch pll_on_delay = chipco_read32(cc, SSB_CHIPCO_PLLONDELAY);
27961e115a5SMichael Buesch tmp = (((pll_on_delay + 2) * 1000000) + (minfreq - 1)) / minfreq;
280209b4375SMichael Büsch WARN_ON(tmp & ~0xFFFF);
28161e115a5SMichael Buesch
28261e115a5SMichael Buesch cc->fast_pwrup_delay = tmp;
28361e115a5SMichael Buesch }
28461e115a5SMichael Buesch
ssb_chipco_alp_clock(struct ssb_chipcommon * cc)285f924e1e9SHauke Mehrtens static u32 ssb_chipco_alp_clock(struct ssb_chipcommon *cc)
286f924e1e9SHauke Mehrtens {
287f924e1e9SHauke Mehrtens if (cc->capabilities & SSB_CHIPCO_CAP_PMU)
288f924e1e9SHauke Mehrtens return ssb_pmu_get_alp_clock(cc);
289f924e1e9SHauke Mehrtens
290f924e1e9SHauke Mehrtens return 20000000;
291f924e1e9SHauke Mehrtens }
292f924e1e9SHauke Mehrtens
ssb_chipco_watchdog_get_max_timer(struct ssb_chipcommon * cc)29326107309SHauke Mehrtens static u32 ssb_chipco_watchdog_get_max_timer(struct ssb_chipcommon *cc)
29426107309SHauke Mehrtens {
29526107309SHauke Mehrtens u32 nb;
29626107309SHauke Mehrtens
29726107309SHauke Mehrtens if (cc->capabilities & SSB_CHIPCO_CAP_PMU) {
29826107309SHauke Mehrtens if (cc->dev->id.revision < 26)
29926107309SHauke Mehrtens nb = 16;
30026107309SHauke Mehrtens else
30126107309SHauke Mehrtens nb = (cc->dev->id.revision >= 37) ? 32 : 24;
30226107309SHauke Mehrtens } else {
30326107309SHauke Mehrtens nb = 28;
30426107309SHauke Mehrtens }
30526107309SHauke Mehrtens if (nb == 32)
30626107309SHauke Mehrtens return 0xffffffff;
30726107309SHauke Mehrtens else
30826107309SHauke Mehrtens return (1 << nb) - 1;
30926107309SHauke Mehrtens }
31026107309SHauke Mehrtens
ssb_chipco_watchdog_timer_set_wdt(struct bcm47xx_wdt * wdt,u32 ticks)3117ffbffe3SHauke Mehrtens u32 ssb_chipco_watchdog_timer_set_wdt(struct bcm47xx_wdt *wdt, u32 ticks)
3127ffbffe3SHauke Mehrtens {
3137ffbffe3SHauke Mehrtens struct ssb_chipcommon *cc = bcm47xx_wdt_get_drvdata(wdt);
3147ffbffe3SHauke Mehrtens
3157ffbffe3SHauke Mehrtens if (cc->dev->bus->bustype != SSB_BUSTYPE_SSB)
3167ffbffe3SHauke Mehrtens return 0;
3177ffbffe3SHauke Mehrtens
3187ffbffe3SHauke Mehrtens return ssb_chipco_watchdog_timer_set(cc, ticks);
3197ffbffe3SHauke Mehrtens }
3207ffbffe3SHauke Mehrtens
ssb_chipco_watchdog_timer_set_ms(struct bcm47xx_wdt * wdt,u32 ms)3217ffbffe3SHauke Mehrtens u32 ssb_chipco_watchdog_timer_set_ms(struct bcm47xx_wdt *wdt, u32 ms)
3227ffbffe3SHauke Mehrtens {
3237ffbffe3SHauke Mehrtens struct ssb_chipcommon *cc = bcm47xx_wdt_get_drvdata(wdt);
3247ffbffe3SHauke Mehrtens u32 ticks;
3257ffbffe3SHauke Mehrtens
3267ffbffe3SHauke Mehrtens if (cc->dev->bus->bustype != SSB_BUSTYPE_SSB)
3277ffbffe3SHauke Mehrtens return 0;
3287ffbffe3SHauke Mehrtens
3297ffbffe3SHauke Mehrtens ticks = ssb_chipco_watchdog_timer_set(cc, cc->ticks_per_ms * ms);
3307ffbffe3SHauke Mehrtens return ticks / cc->ticks_per_ms;
3317ffbffe3SHauke Mehrtens }
3327ffbffe3SHauke Mehrtens
ssb_chipco_watchdog_ticks_per_ms(struct ssb_chipcommon * cc)3337ffbffe3SHauke Mehrtens static int ssb_chipco_watchdog_ticks_per_ms(struct ssb_chipcommon *cc)
3347ffbffe3SHauke Mehrtens {
3357ffbffe3SHauke Mehrtens struct ssb_bus *bus = cc->dev->bus;
3367ffbffe3SHauke Mehrtens
3377ffbffe3SHauke Mehrtens if (cc->capabilities & SSB_CHIPCO_CAP_PMU) {
3387ffbffe3SHauke Mehrtens /* based on 32KHz ILP clock */
3397ffbffe3SHauke Mehrtens return 32;
3407ffbffe3SHauke Mehrtens } else {
3417ffbffe3SHauke Mehrtens if (cc->dev->id.revision < 18)
3427ffbffe3SHauke Mehrtens return ssb_clockspeed(bus) / 1000;
3437ffbffe3SHauke Mehrtens else
3447ffbffe3SHauke Mehrtens return ssb_chipco_alp_clock(cc) / 1000;
3457ffbffe3SHauke Mehrtens }
3467ffbffe3SHauke Mehrtens }
3477ffbffe3SHauke Mehrtens
ssb_chipcommon_init(struct ssb_chipcommon * cc)34861e115a5SMichael Buesch void ssb_chipcommon_init(struct ssb_chipcommon *cc)
34961e115a5SMichael Buesch {
35061e115a5SMichael Buesch if (!cc->dev)
35161e115a5SMichael Buesch return; /* We don't have a ChipCommon */
352394bc7e3SHauke Mehrtens
353394bc7e3SHauke Mehrtens spin_lock_init(&cc->gpio_lock);
354394bc7e3SHauke Mehrtens
355d53cdbb9SJohn W. Linville if (cc->dev->id.revision >= 11)
356d53cdbb9SJohn W. Linville cc->status = chipco_read32(cc, SSB_CHIPCO_CHIPSTAT);
357b8b6069cSMichael Büsch dev_dbg(cc->dev->dev, "chipcommon status is 0x%x\n", cc->status);
3589835a30eSRafał Miłecki
3599835a30eSRafał Miłecki if (cc->dev->id.revision >= 20) {
3609835a30eSRafał Miłecki chipco_write32(cc, SSB_CHIPCO_GPIOPULLUP, 0);
3619835a30eSRafał Miłecki chipco_write32(cc, SSB_CHIPCO_GPIOPULLDOWN, 0);
3629835a30eSRafał Miłecki }
3639835a30eSRafał Miłecki
364c9703146SMichael Buesch ssb_pmu_init(cc);
36561e115a5SMichael Buesch chipco_powercontrol_init(cc);
36661e115a5SMichael Buesch ssb_chipco_set_clockmode(cc, SSB_CLKMODE_FAST);
36761e115a5SMichael Buesch calc_fast_powerup_delay(cc);
3687ffbffe3SHauke Mehrtens
3697ffbffe3SHauke Mehrtens if (cc->dev->bus->bustype == SSB_BUSTYPE_SSB) {
3707ffbffe3SHauke Mehrtens cc->ticks_per_ms = ssb_chipco_watchdog_ticks_per_ms(cc);
3717ffbffe3SHauke Mehrtens cc->max_timer_ms = ssb_chipco_watchdog_get_max_timer(cc) / cc->ticks_per_ms;
3727ffbffe3SHauke Mehrtens }
37361e115a5SMichael Buesch }
37461e115a5SMichael Buesch
ssb_chipco_suspend(struct ssb_chipcommon * cc)3758fe2b65aSMichael Buesch void ssb_chipco_suspend(struct ssb_chipcommon *cc)
37661e115a5SMichael Buesch {
37761e115a5SMichael Buesch if (!cc->dev)
37861e115a5SMichael Buesch return;
37961e115a5SMichael Buesch ssb_chipco_set_clockmode(cc, SSB_CLKMODE_SLOW);
38061e115a5SMichael Buesch }
38161e115a5SMichael Buesch
ssb_chipco_resume(struct ssb_chipcommon * cc)38261e115a5SMichael Buesch void ssb_chipco_resume(struct ssb_chipcommon *cc)
38361e115a5SMichael Buesch {
38461e115a5SMichael Buesch if (!cc->dev)
38561e115a5SMichael Buesch return;
38661e115a5SMichael Buesch chipco_powercontrol_init(cc);
38761e115a5SMichael Buesch ssb_chipco_set_clockmode(cc, SSB_CLKMODE_FAST);
38861e115a5SMichael Buesch }
38961e115a5SMichael Buesch
39061e115a5SMichael Buesch /* Get the processor clock */
ssb_chipco_get_clockcpu(struct ssb_chipcommon * cc,u32 * plltype,u32 * n,u32 * m)39161e115a5SMichael Buesch void ssb_chipco_get_clockcpu(struct ssb_chipcommon *cc,
39261e115a5SMichael Buesch u32 *plltype, u32 *n, u32 *m)
39361e115a5SMichael Buesch {
39461e115a5SMichael Buesch *n = chipco_read32(cc, SSB_CHIPCO_CLOCK_N);
39561e115a5SMichael Buesch *plltype = (cc->capabilities & SSB_CHIPCO_CAP_PLLT);
39661e115a5SMichael Buesch switch (*plltype) {
39761e115a5SMichael Buesch case SSB_PLLTYPE_2:
39861e115a5SMichael Buesch case SSB_PLLTYPE_4:
39961e115a5SMichael Buesch case SSB_PLLTYPE_6:
40061e115a5SMichael Buesch case SSB_PLLTYPE_7:
40161e115a5SMichael Buesch *m = chipco_read32(cc, SSB_CHIPCO_CLOCK_MIPS);
40261e115a5SMichael Buesch break;
40361e115a5SMichael Buesch case SSB_PLLTYPE_3:
40461e115a5SMichael Buesch /* 5350 uses m2 to control mips */
40561e115a5SMichael Buesch *m = chipco_read32(cc, SSB_CHIPCO_CLOCK_M2);
40661e115a5SMichael Buesch break;
40761e115a5SMichael Buesch default:
40861e115a5SMichael Buesch *m = chipco_read32(cc, SSB_CHIPCO_CLOCK_SB);
40961e115a5SMichael Buesch break;
41061e115a5SMichael Buesch }
41161e115a5SMichael Buesch }
41261e115a5SMichael Buesch
41361e115a5SMichael Buesch /* Get the bus clock */
ssb_chipco_get_clockcontrol(struct ssb_chipcommon * cc,u32 * plltype,u32 * n,u32 * m)41461e115a5SMichael Buesch void ssb_chipco_get_clockcontrol(struct ssb_chipcommon *cc,
41561e115a5SMichael Buesch u32 *plltype, u32 *n, u32 *m)
41661e115a5SMichael Buesch {
41761e115a5SMichael Buesch *n = chipco_read32(cc, SSB_CHIPCO_CLOCK_N);
41861e115a5SMichael Buesch *plltype = (cc->capabilities & SSB_CHIPCO_CAP_PLLT);
41961e115a5SMichael Buesch switch (*plltype) {
42061e115a5SMichael Buesch case SSB_PLLTYPE_6: /* 100/200 or 120/240 only */
42161e115a5SMichael Buesch *m = chipco_read32(cc, SSB_CHIPCO_CLOCK_MIPS);
42261e115a5SMichael Buesch break;
42361e115a5SMichael Buesch case SSB_PLLTYPE_3: /* 25Mhz, 2 dividers */
42461e115a5SMichael Buesch if (cc->dev->bus->chip_id != 0x5365) {
42561e115a5SMichael Buesch *m = chipco_read32(cc, SSB_CHIPCO_CLOCK_M2);
42661e115a5SMichael Buesch break;
42761e115a5SMichael Buesch }
428*df561f66SGustavo A. R. Silva fallthrough;
42961e115a5SMichael Buesch default:
43061e115a5SMichael Buesch *m = chipco_read32(cc, SSB_CHIPCO_CLOCK_SB);
43161e115a5SMichael Buesch }
43261e115a5SMichael Buesch }
43361e115a5SMichael Buesch
ssb_chipco_timing_init(struct ssb_chipcommon * cc,unsigned long ns)43461e115a5SMichael Buesch void ssb_chipco_timing_init(struct ssb_chipcommon *cc,
43561e115a5SMichael Buesch unsigned long ns)
43661e115a5SMichael Buesch {
43761e115a5SMichael Buesch struct ssb_device *dev = cc->dev;
43861e115a5SMichael Buesch struct ssb_bus *bus = dev->bus;
43961e115a5SMichael Buesch u32 tmp;
44061e115a5SMichael Buesch
44161e115a5SMichael Buesch /* set register for external IO to control LED. */
44261e115a5SMichael Buesch chipco_write32(cc, SSB_CHIPCO_PROG_CFG, 0x11);
44361e115a5SMichael Buesch tmp = DIV_ROUND_UP(10, ns) << SSB_PROG_WCNT_3_SHIFT; /* Waitcount-3 = 10ns */
44461e115a5SMichael Buesch tmp |= DIV_ROUND_UP(40, ns) << SSB_PROG_WCNT_1_SHIFT; /* Waitcount-1 = 40ns */
44561e115a5SMichael Buesch tmp |= DIV_ROUND_UP(240, ns); /* Waitcount-0 = 240ns */
44661e115a5SMichael Buesch chipco_write32(cc, SSB_CHIPCO_PROG_WAITCNT, tmp); /* 0x01020a0c for a 100Mhz clock */
44761e115a5SMichael Buesch
44861e115a5SMichael Buesch /* Set timing for the flash */
44961e115a5SMichael Buesch tmp = DIV_ROUND_UP(10, ns) << SSB_FLASH_WCNT_3_SHIFT; /* Waitcount-3 = 10nS */
45061e115a5SMichael Buesch tmp |= DIV_ROUND_UP(10, ns) << SSB_FLASH_WCNT_1_SHIFT; /* Waitcount-1 = 10nS */
45161e115a5SMichael Buesch tmp |= DIV_ROUND_UP(120, ns); /* Waitcount-0 = 120nS */
45261e115a5SMichael Buesch if ((bus->chip_id == 0x5365) ||
45361e115a5SMichael Buesch (dev->id.revision < 9))
45461e115a5SMichael Buesch chipco_write32(cc, SSB_CHIPCO_FLASH_WAITCNT, tmp);
45561e115a5SMichael Buesch if ((bus->chip_id == 0x5365) ||
45661e115a5SMichael Buesch (dev->id.revision < 9) ||
45761e115a5SMichael Buesch ((bus->chip_id == 0x5350) && (bus->chip_rev == 0)))
45861e115a5SMichael Buesch chipco_write32(cc, SSB_CHIPCO_PCMCIA_MEMWAIT, tmp);
45961e115a5SMichael Buesch
46061e115a5SMichael Buesch if (bus->chip_id == 0x5350) {
46161e115a5SMichael Buesch /* Enable EXTIF */
46261e115a5SMichael Buesch tmp = DIV_ROUND_UP(10, ns) << SSB_PROG_WCNT_3_SHIFT; /* Waitcount-3 = 10ns */
46361e115a5SMichael Buesch tmp |= DIV_ROUND_UP(20, ns) << SSB_PROG_WCNT_2_SHIFT; /* Waitcount-2 = 20ns */
46461e115a5SMichael Buesch tmp |= DIV_ROUND_UP(100, ns) << SSB_PROG_WCNT_1_SHIFT; /* Waitcount-1 = 100ns */
46561e115a5SMichael Buesch tmp |= DIV_ROUND_UP(120, ns); /* Waitcount-0 = 120ns */
46661e115a5SMichael Buesch chipco_write32(cc, SSB_CHIPCO_PROG_WAITCNT, tmp); /* 0x01020a0c for a 100Mhz clock */
46761e115a5SMichael Buesch }
46861e115a5SMichael Buesch }
46961e115a5SMichael Buesch
47061e115a5SMichael Buesch /* Set chip watchdog reset timer to fire in 'ticks' backplane cycles */
ssb_chipco_watchdog_timer_set(struct ssb_chipcommon * cc,u32 ticks)4717ffbffe3SHauke Mehrtens u32 ssb_chipco_watchdog_timer_set(struct ssb_chipcommon *cc, u32 ticks)
47261e115a5SMichael Buesch {
47326107309SHauke Mehrtens u32 maxt;
47426107309SHauke Mehrtens enum ssb_clkmode clkmode;
47526107309SHauke Mehrtens
47626107309SHauke Mehrtens maxt = ssb_chipco_watchdog_get_max_timer(cc);
47726107309SHauke Mehrtens if (cc->capabilities & SSB_CHIPCO_CAP_PMU) {
47826107309SHauke Mehrtens if (ticks == 1)
47926107309SHauke Mehrtens ticks = 2;
48026107309SHauke Mehrtens else if (ticks > maxt)
48126107309SHauke Mehrtens ticks = maxt;
48226107309SHauke Mehrtens chipco_write32(cc, SSB_CHIPCO_PMU_WATCHDOG, ticks);
48326107309SHauke Mehrtens } else {
48426107309SHauke Mehrtens clkmode = ticks ? SSB_CLKMODE_FAST : SSB_CLKMODE_DYNAMIC;
48526107309SHauke Mehrtens ssb_chipco_set_clockmode(cc, clkmode);
48626107309SHauke Mehrtens if (ticks > maxt)
48726107309SHauke Mehrtens ticks = maxt;
48861e115a5SMichael Buesch /* instant NMI */
48961e115a5SMichael Buesch chipco_write32(cc, SSB_CHIPCO_WATCHDOG, ticks);
49061e115a5SMichael Buesch }
4917ffbffe3SHauke Mehrtens return ticks;
49226107309SHauke Mehrtens }
49361e115a5SMichael Buesch
ssb_chipco_irq_mask(struct ssb_chipcommon * cc,u32 mask,u32 value)49428de57d1SAurelien Jarno void ssb_chipco_irq_mask(struct ssb_chipcommon *cc, u32 mask, u32 value)
49528de57d1SAurelien Jarno {
49628de57d1SAurelien Jarno chipco_write32_masked(cc, SSB_CHIPCO_IRQMASK, mask, value);
49728de57d1SAurelien Jarno }
49828de57d1SAurelien Jarno
ssb_chipco_irq_status(struct ssb_chipcommon * cc,u32 mask)49928de57d1SAurelien Jarno u32 ssb_chipco_irq_status(struct ssb_chipcommon *cc, u32 mask)
50028de57d1SAurelien Jarno {
50128de57d1SAurelien Jarno return chipco_read32(cc, SSB_CHIPCO_IRQSTAT) & mask;
50228de57d1SAurelien Jarno }
50328de57d1SAurelien Jarno
ssb_chipco_gpio_in(struct ssb_chipcommon * cc,u32 mask)50461e115a5SMichael Buesch u32 ssb_chipco_gpio_in(struct ssb_chipcommon *cc, u32 mask)
50561e115a5SMichael Buesch {
50661e115a5SMichael Buesch return chipco_read32(cc, SSB_CHIPCO_GPIOIN) & mask;
50761e115a5SMichael Buesch }
50861e115a5SMichael Buesch
ssb_chipco_gpio_out(struct ssb_chipcommon * cc,u32 mask,u32 value)509c2bcbe65SMichael Buesch u32 ssb_chipco_gpio_out(struct ssb_chipcommon *cc, u32 mask, u32 value)
51061e115a5SMichael Buesch {
511394bc7e3SHauke Mehrtens unsigned long flags;
512394bc7e3SHauke Mehrtens u32 res = 0;
513394bc7e3SHauke Mehrtens
514394bc7e3SHauke Mehrtens spin_lock_irqsave(&cc->gpio_lock, flags);
515394bc7e3SHauke Mehrtens res = chipco_write32_masked(cc, SSB_CHIPCO_GPIOOUT, mask, value);
516394bc7e3SHauke Mehrtens spin_unlock_irqrestore(&cc->gpio_lock, flags);
517394bc7e3SHauke Mehrtens
518394bc7e3SHauke Mehrtens return res;
51961e115a5SMichael Buesch }
52061e115a5SMichael Buesch
ssb_chipco_gpio_outen(struct ssb_chipcommon * cc,u32 mask,u32 value)521c2bcbe65SMichael Buesch u32 ssb_chipco_gpio_outen(struct ssb_chipcommon *cc, u32 mask, u32 value)
52261e115a5SMichael Buesch {
523394bc7e3SHauke Mehrtens unsigned long flags;
524394bc7e3SHauke Mehrtens u32 res = 0;
525394bc7e3SHauke Mehrtens
526394bc7e3SHauke Mehrtens spin_lock_irqsave(&cc->gpio_lock, flags);
527394bc7e3SHauke Mehrtens res = chipco_write32_masked(cc, SSB_CHIPCO_GPIOOUTEN, mask, value);
528394bc7e3SHauke Mehrtens spin_unlock_irqrestore(&cc->gpio_lock, flags);
529394bc7e3SHauke Mehrtens
530394bc7e3SHauke Mehrtens return res;
53161e115a5SMichael Buesch }
532c2bcbe65SMichael Buesch
ssb_chipco_gpio_control(struct ssb_chipcommon * cc,u32 mask,u32 value)533c2bcbe65SMichael Buesch u32 ssb_chipco_gpio_control(struct ssb_chipcommon *cc, u32 mask, u32 value)
534c2bcbe65SMichael Buesch {
535394bc7e3SHauke Mehrtens unsigned long flags;
536394bc7e3SHauke Mehrtens u32 res = 0;
537394bc7e3SHauke Mehrtens
538394bc7e3SHauke Mehrtens spin_lock_irqsave(&cc->gpio_lock, flags);
539394bc7e3SHauke Mehrtens res = chipco_write32_masked(cc, SSB_CHIPCO_GPIOCTL, mask, value);
540394bc7e3SHauke Mehrtens spin_unlock_irqrestore(&cc->gpio_lock, flags);
541394bc7e3SHauke Mehrtens
542394bc7e3SHauke Mehrtens return res;
543c2bcbe65SMichael Buesch }
54485373ee8SLarry Finger EXPORT_SYMBOL(ssb_chipco_gpio_control);
545c2bcbe65SMichael Buesch
ssb_chipco_gpio_intmask(struct ssb_chipcommon * cc,u32 mask,u32 value)546c2bcbe65SMichael Buesch u32 ssb_chipco_gpio_intmask(struct ssb_chipcommon *cc, u32 mask, u32 value)
547c2bcbe65SMichael Buesch {
548394bc7e3SHauke Mehrtens unsigned long flags;
549394bc7e3SHauke Mehrtens u32 res = 0;
550394bc7e3SHauke Mehrtens
551394bc7e3SHauke Mehrtens spin_lock_irqsave(&cc->gpio_lock, flags);
552394bc7e3SHauke Mehrtens res = chipco_write32_masked(cc, SSB_CHIPCO_GPIOIRQ, mask, value);
553394bc7e3SHauke Mehrtens spin_unlock_irqrestore(&cc->gpio_lock, flags);
554394bc7e3SHauke Mehrtens
555394bc7e3SHauke Mehrtens return res;
556c2bcbe65SMichael Buesch }
557c2bcbe65SMichael Buesch
ssb_chipco_gpio_polarity(struct ssb_chipcommon * cc,u32 mask,u32 value)558c2bcbe65SMichael Buesch u32 ssb_chipco_gpio_polarity(struct ssb_chipcommon *cc, u32 mask, u32 value)
559c2bcbe65SMichael Buesch {
560394bc7e3SHauke Mehrtens unsigned long flags;
561394bc7e3SHauke Mehrtens u32 res = 0;
562394bc7e3SHauke Mehrtens
563394bc7e3SHauke Mehrtens spin_lock_irqsave(&cc->gpio_lock, flags);
564394bc7e3SHauke Mehrtens res = chipco_write32_masked(cc, SSB_CHIPCO_GPIOPOL, mask, value);
565394bc7e3SHauke Mehrtens spin_unlock_irqrestore(&cc->gpio_lock, flags);
566394bc7e3SHauke Mehrtens
567394bc7e3SHauke Mehrtens return res;
568c2bcbe65SMichael Buesch }
56961e115a5SMichael Buesch
ssb_chipco_gpio_pullup(struct ssb_chipcommon * cc,u32 mask,u32 value)570da22f22eSHauke Mehrtens u32 ssb_chipco_gpio_pullup(struct ssb_chipcommon *cc, u32 mask, u32 value)
571da22f22eSHauke Mehrtens {
572394bc7e3SHauke Mehrtens unsigned long flags;
573394bc7e3SHauke Mehrtens u32 res = 0;
574394bc7e3SHauke Mehrtens
575da22f22eSHauke Mehrtens if (cc->dev->id.revision < 20)
576da22f22eSHauke Mehrtens return 0xffffffff;
577da22f22eSHauke Mehrtens
578394bc7e3SHauke Mehrtens spin_lock_irqsave(&cc->gpio_lock, flags);
579394bc7e3SHauke Mehrtens res = chipco_write32_masked(cc, SSB_CHIPCO_GPIOPULLUP, mask, value);
580394bc7e3SHauke Mehrtens spin_unlock_irqrestore(&cc->gpio_lock, flags);
581394bc7e3SHauke Mehrtens
582394bc7e3SHauke Mehrtens return res;
583da22f22eSHauke Mehrtens }
584da22f22eSHauke Mehrtens
ssb_chipco_gpio_pulldown(struct ssb_chipcommon * cc,u32 mask,u32 value)585da22f22eSHauke Mehrtens u32 ssb_chipco_gpio_pulldown(struct ssb_chipcommon *cc, u32 mask, u32 value)
586da22f22eSHauke Mehrtens {
587394bc7e3SHauke Mehrtens unsigned long flags;
588394bc7e3SHauke Mehrtens u32 res = 0;
589394bc7e3SHauke Mehrtens
590da22f22eSHauke Mehrtens if (cc->dev->id.revision < 20)
591da22f22eSHauke Mehrtens return 0xffffffff;
592da22f22eSHauke Mehrtens
593394bc7e3SHauke Mehrtens spin_lock_irqsave(&cc->gpio_lock, flags);
594394bc7e3SHauke Mehrtens res = chipco_write32_masked(cc, SSB_CHIPCO_GPIOPULLDOWN, mask, value);
595394bc7e3SHauke Mehrtens spin_unlock_irqrestore(&cc->gpio_lock, flags);
596394bc7e3SHauke Mehrtens
597394bc7e3SHauke Mehrtens return res;
59861e115a5SMichael Buesch }
59961e115a5SMichael Buesch
60061e115a5SMichael Buesch #ifdef CONFIG_SSB_SERIAL
ssb_chipco_serial_init(struct ssb_chipcommon * cc,struct ssb_serial_port * ports)60161e115a5SMichael Buesch int ssb_chipco_serial_init(struct ssb_chipcommon *cc,
60261e115a5SMichael Buesch struct ssb_serial_port *ports)
60361e115a5SMichael Buesch {
60461e115a5SMichael Buesch struct ssb_bus *bus = cc->dev->bus;
60558ff70d4SMichael Buesch int nr_ports = 0;
60658ff70d4SMichael Buesch u32 plltype;
60758ff70d4SMichael Buesch unsigned int irq;
60858ff70d4SMichael Buesch u32 baud_base, div;
60961e115a5SMichael Buesch u32 i, n;
61061e115a5SMichael Buesch unsigned int ccrev = cc->dev->id.revision;
61158ff70d4SMichael Buesch
61258ff70d4SMichael Buesch plltype = (cc->capabilities & SSB_CHIPCO_CAP_PLLT);
61358ff70d4SMichael Buesch irq = ssb_mips_irq(cc->dev);
61458ff70d4SMichael Buesch
61558ff70d4SMichael Buesch if (plltype == SSB_PLLTYPE_1) {
61658ff70d4SMichael Buesch /* PLL clock */
61758ff70d4SMichael Buesch baud_base = ssb_calc_clock_rate(plltype,
61858ff70d4SMichael Buesch chipco_read32(cc, SSB_CHIPCO_CLOCK_N),
61958ff70d4SMichael Buesch chipco_read32(cc, SSB_CHIPCO_CLOCK_M2));
62058ff70d4SMichael Buesch div = 1;
62158ff70d4SMichael Buesch } else {
62258ff70d4SMichael Buesch if (ccrev == 20) {
62358ff70d4SMichael Buesch /* BCM5354 uses constant 25MHz clock */
62458ff70d4SMichael Buesch baud_base = 25000000;
62558ff70d4SMichael Buesch div = 48;
62658ff70d4SMichael Buesch /* Set the override bit so we don't divide it */
62758ff70d4SMichael Buesch chipco_write32(cc, SSB_CHIPCO_CORECTL,
62858ff70d4SMichael Buesch chipco_read32(cc, SSB_CHIPCO_CORECTL)
62958ff70d4SMichael Buesch | SSB_CHIPCO_CORECTL_UARTCLK0);
63058ff70d4SMichael Buesch } else if ((ccrev >= 11) && (ccrev != 15)) {
631f924e1e9SHauke Mehrtens baud_base = ssb_chipco_alp_clock(cc);
63258ff70d4SMichael Buesch div = 1;
63358ff70d4SMichael Buesch if (ccrev >= 21) {
63458ff70d4SMichael Buesch /* Turn off UART clock before switching clocksource. */
63558ff70d4SMichael Buesch chipco_write32(cc, SSB_CHIPCO_CORECTL,
63658ff70d4SMichael Buesch chipco_read32(cc, SSB_CHIPCO_CORECTL)
63758ff70d4SMichael Buesch & ~SSB_CHIPCO_CORECTL_UARTCLKEN);
63858ff70d4SMichael Buesch }
63958ff70d4SMichael Buesch /* Set the override bit so we don't divide it */
64058ff70d4SMichael Buesch chipco_write32(cc, SSB_CHIPCO_CORECTL,
64158ff70d4SMichael Buesch chipco_read32(cc, SSB_CHIPCO_CORECTL)
64258ff70d4SMichael Buesch | SSB_CHIPCO_CORECTL_UARTCLK0);
64358ff70d4SMichael Buesch if (ccrev >= 21) {
64458ff70d4SMichael Buesch /* Re-enable the UART clock. */
64558ff70d4SMichael Buesch chipco_write32(cc, SSB_CHIPCO_CORECTL,
64658ff70d4SMichael Buesch chipco_read32(cc, SSB_CHIPCO_CORECTL)
64758ff70d4SMichael Buesch | SSB_CHIPCO_CORECTL_UARTCLKEN);
64858ff70d4SMichael Buesch }
64958ff70d4SMichael Buesch } else if (ccrev >= 3) {
65061e115a5SMichael Buesch /* Internal backplane clock */
65161e115a5SMichael Buesch baud_base = ssb_clockspeed(bus);
65261e115a5SMichael Buesch div = chipco_read32(cc, SSB_CHIPCO_CLKDIV)
65361e115a5SMichael Buesch & SSB_CHIPCO_CLKDIV_UART;
65461e115a5SMichael Buesch } else {
65561e115a5SMichael Buesch /* Fixed internal backplane clock */
65661e115a5SMichael Buesch baud_base = 88000000;
65761e115a5SMichael Buesch div = 48;
65861e115a5SMichael Buesch }
65961e115a5SMichael Buesch
66061e115a5SMichael Buesch /* Clock source depends on strapping if UartClkOverride is unset */
66158ff70d4SMichael Buesch if ((ccrev > 0) &&
66261e115a5SMichael Buesch !(chipco_read32(cc, SSB_CHIPCO_CORECTL) & SSB_CHIPCO_CORECTL_UARTCLK0)) {
66361e115a5SMichael Buesch if ((cc->capabilities & SSB_CHIPCO_CAP_UARTCLK) ==
66461e115a5SMichael Buesch SSB_CHIPCO_CAP_UARTCLK_INT) {
66561e115a5SMichael Buesch /* Internal divided backplane clock */
66661e115a5SMichael Buesch baud_base /= div;
66761e115a5SMichael Buesch } else {
66861e115a5SMichael Buesch /* Assume external clock of 1.8432 MHz */
66961e115a5SMichael Buesch baud_base = 1843200;
67061e115a5SMichael Buesch }
67161e115a5SMichael Buesch }
67261e115a5SMichael Buesch }
67361e115a5SMichael Buesch
67461e115a5SMichael Buesch /* Determine the registers of the UARTs */
67561e115a5SMichael Buesch n = (cc->capabilities & SSB_CHIPCO_CAP_NRUART);
67661e115a5SMichael Buesch for (i = 0; i < n; i++) {
67761e115a5SMichael Buesch void __iomem *cc_mmio;
67861e115a5SMichael Buesch void __iomem *uart_regs;
67961e115a5SMichael Buesch
68061e115a5SMichael Buesch cc_mmio = cc->dev->bus->mmio + (cc->dev->core_index * SSB_CORE_SIZE);
68161e115a5SMichael Buesch uart_regs = cc_mmio + SSB_CHIPCO_UART0_DATA;
68261e115a5SMichael Buesch /* Offset changed at after rev 0 */
68358ff70d4SMichael Buesch if (ccrev == 0)
68461e115a5SMichael Buesch uart_regs += (i * 8);
68561e115a5SMichael Buesch else
68661e115a5SMichael Buesch uart_regs += (i * 256);
68761e115a5SMichael Buesch
68861e115a5SMichael Buesch nr_ports++;
68961e115a5SMichael Buesch ports[i].regs = uart_regs;
69061e115a5SMichael Buesch ports[i].irq = irq;
69161e115a5SMichael Buesch ports[i].baud_base = baud_base;
69261e115a5SMichael Buesch ports[i].reg_shift = 0;
69361e115a5SMichael Buesch }
69461e115a5SMichael Buesch
69561e115a5SMichael Buesch return nr_ports;
69661e115a5SMichael Buesch }
69761e115a5SMichael Buesch #endif /* CONFIG_SSB_SERIAL */
698