161e115a5SMichael Buesch /* 261e115a5SMichael Buesch * Sonics Silicon Backplane 361e115a5SMichael Buesch * Broadcom ChipCommon core driver 461e115a5SMichael Buesch * 561e115a5SMichael Buesch * Copyright 2005, Broadcom Corporation 661e115a5SMichael Buesch * Copyright 2006, 2007, Michael Buesch <mb@bu3sch.de> 761e115a5SMichael Buesch * 861e115a5SMichael Buesch * Licensed under the GNU/GPL. See COPYING for details. 961e115a5SMichael Buesch */ 1061e115a5SMichael Buesch 1161e115a5SMichael Buesch #include <linux/ssb/ssb.h> 1261e115a5SMichael Buesch #include <linux/ssb/ssb_regs.h> 1361e115a5SMichael Buesch #include <linux/pci.h> 1461e115a5SMichael Buesch 1561e115a5SMichael Buesch #include "ssb_private.h" 1661e115a5SMichael Buesch 1761e115a5SMichael Buesch 1861e115a5SMichael Buesch /* Clock sources */ 1961e115a5SMichael Buesch enum ssb_clksrc { 2061e115a5SMichael Buesch /* PCI clock */ 2161e115a5SMichael Buesch SSB_CHIPCO_CLKSRC_PCI, 2261e115a5SMichael Buesch /* Crystal slow clock oscillator */ 2361e115a5SMichael Buesch SSB_CHIPCO_CLKSRC_XTALOS, 2461e115a5SMichael Buesch /* Low power oscillator */ 2561e115a5SMichael Buesch SSB_CHIPCO_CLKSRC_LOPWROS, 2661e115a5SMichael Buesch }; 2761e115a5SMichael Buesch 2861e115a5SMichael Buesch 29c2bcbe65SMichael Buesch static inline u32 chipco_write32_masked(struct ssb_chipcommon *cc, u16 offset, 3061e115a5SMichael Buesch u32 mask, u32 value) 3161e115a5SMichael Buesch { 3261e115a5SMichael Buesch value &= mask; 3361e115a5SMichael Buesch value |= chipco_read32(cc, offset) & ~mask; 3461e115a5SMichael Buesch chipco_write32(cc, offset, value); 35c2bcbe65SMichael Buesch 36c2bcbe65SMichael Buesch return value; 3761e115a5SMichael Buesch } 3861e115a5SMichael Buesch 3961e115a5SMichael Buesch void ssb_chipco_set_clockmode(struct ssb_chipcommon *cc, 4061e115a5SMichael Buesch enum ssb_clkmode mode) 4161e115a5SMichael Buesch { 4261e115a5SMichael Buesch struct ssb_device *ccdev = cc->dev; 4361e115a5SMichael Buesch struct ssb_bus *bus; 4461e115a5SMichael Buesch u32 tmp; 4561e115a5SMichael Buesch 4661e115a5SMichael Buesch if (!ccdev) 4761e115a5SMichael Buesch return; 4861e115a5SMichael Buesch bus = ccdev->bus; 49*0ca69955SRafał Miłecki 50*0ca69955SRafał Miłecki /* We support SLOW only on 6..9 */ 51*0ca69955SRafał Miłecki if (ccdev->id.revision >= 10 && mode == SSB_CLKMODE_SLOW) 52*0ca69955SRafał Miłecki mode = SSB_CLKMODE_DYNAMIC; 53*0ca69955SRafał Miłecki 54*0ca69955SRafał Miłecki if (cc->capabilities & SSB_CHIPCO_CAP_PMU) 55*0ca69955SRafał Miłecki return; /* PMU controls clockmode, separated function needed */ 56*0ca69955SRafał Miłecki SSB_WARN_ON(ccdev->id.revision >= 20); 57*0ca69955SRafał Miłecki 5861e115a5SMichael Buesch /* chipcommon cores prior to rev6 don't support dynamic clock control */ 5961e115a5SMichael Buesch if (ccdev->id.revision < 6) 6061e115a5SMichael Buesch return; 61*0ca69955SRafał Miłecki 62*0ca69955SRafał Miłecki /* ChipCommon cores rev10+ need testing */ 6361e115a5SMichael Buesch if (ccdev->id.revision >= 10) 6461e115a5SMichael Buesch return; 65*0ca69955SRafał Miłecki 6661e115a5SMichael Buesch if (!(cc->capabilities & SSB_CHIPCO_CAP_PCTL)) 6761e115a5SMichael Buesch return; 6861e115a5SMichael Buesch 6961e115a5SMichael Buesch switch (mode) { 70*0ca69955SRafał Miłecki case SSB_CLKMODE_SLOW: /* For revs 6..9 only */ 7161e115a5SMichael Buesch tmp = chipco_read32(cc, SSB_CHIPCO_SLOWCLKCTL); 7261e115a5SMichael Buesch tmp |= SSB_CHIPCO_SLOWCLKCTL_FSLOW; 7361e115a5SMichael Buesch chipco_write32(cc, SSB_CHIPCO_SLOWCLKCTL, tmp); 7461e115a5SMichael Buesch break; 7561e115a5SMichael Buesch case SSB_CLKMODE_FAST: 76*0ca69955SRafał Miłecki if (ccdev->id.revision < 10) { 7761e115a5SMichael Buesch ssb_pci_xtal(bus, SSB_GPIO_XTAL, 1); /* Force crystal on */ 7861e115a5SMichael Buesch tmp = chipco_read32(cc, SSB_CHIPCO_SLOWCLKCTL); 7961e115a5SMichael Buesch tmp &= ~SSB_CHIPCO_SLOWCLKCTL_FSLOW; 8061e115a5SMichael Buesch tmp |= SSB_CHIPCO_SLOWCLKCTL_IPLL; 8161e115a5SMichael Buesch chipco_write32(cc, SSB_CHIPCO_SLOWCLKCTL, tmp); 82*0ca69955SRafał Miłecki } else { 83*0ca69955SRafał Miłecki chipco_write32(cc, SSB_CHIPCO_SYSCLKCTL, 84*0ca69955SRafał Miłecki (chipco_read32(cc, SSB_CHIPCO_SYSCLKCTL) | 85*0ca69955SRafał Miłecki SSB_CHIPCO_SYSCLKCTL_FORCEHT)); 86*0ca69955SRafał Miłecki /* udelay(150); TODO: not available in early init */ 87*0ca69955SRafał Miłecki } 8861e115a5SMichael Buesch break; 8961e115a5SMichael Buesch case SSB_CLKMODE_DYNAMIC: 90*0ca69955SRafał Miłecki if (ccdev->id.revision < 10) { 9161e115a5SMichael Buesch tmp = chipco_read32(cc, SSB_CHIPCO_SLOWCLKCTL); 9261e115a5SMichael Buesch tmp &= ~SSB_CHIPCO_SLOWCLKCTL_FSLOW; 9361e115a5SMichael Buesch tmp &= ~SSB_CHIPCO_SLOWCLKCTL_IPLL; 9461e115a5SMichael Buesch tmp &= ~SSB_CHIPCO_SLOWCLKCTL_ENXTAL; 95*0ca69955SRafał Miłecki if ((tmp & SSB_CHIPCO_SLOWCLKCTL_SRC) != 96*0ca69955SRafał Miłecki SSB_CHIPCO_SLOWCLKCTL_SRC_XTAL) 9761e115a5SMichael Buesch tmp |= SSB_CHIPCO_SLOWCLKCTL_ENXTAL; 9861e115a5SMichael Buesch chipco_write32(cc, SSB_CHIPCO_SLOWCLKCTL, tmp); 9961e115a5SMichael Buesch 100*0ca69955SRafał Miłecki /* For dynamic control, we have to release our xtal_pu 101*0ca69955SRafał Miłecki * "force on" */ 10261e115a5SMichael Buesch if (tmp & SSB_CHIPCO_SLOWCLKCTL_ENXTAL) 10361e115a5SMichael Buesch ssb_pci_xtal(bus, SSB_GPIO_XTAL, 0); 104*0ca69955SRafał Miłecki } else { 105*0ca69955SRafał Miłecki chipco_write32(cc, SSB_CHIPCO_SYSCLKCTL, 106*0ca69955SRafał Miłecki (chipco_read32(cc, SSB_CHIPCO_SYSCLKCTL) & 107*0ca69955SRafał Miłecki ~SSB_CHIPCO_SYSCLKCTL_FORCEHT)); 108*0ca69955SRafał Miłecki } 10961e115a5SMichael Buesch break; 11061e115a5SMichael Buesch default: 11161e115a5SMichael Buesch SSB_WARN_ON(1); 11261e115a5SMichael Buesch } 11361e115a5SMichael Buesch } 11461e115a5SMichael Buesch 11561e115a5SMichael Buesch /* Get the Slow Clock Source */ 11661e115a5SMichael Buesch static enum ssb_clksrc chipco_pctl_get_slowclksrc(struct ssb_chipcommon *cc) 11761e115a5SMichael Buesch { 11861e115a5SMichael Buesch struct ssb_bus *bus = cc->dev->bus; 11961e115a5SMichael Buesch u32 uninitialized_var(tmp); 12061e115a5SMichael Buesch 12161e115a5SMichael Buesch if (cc->dev->id.revision < 6) { 12261e115a5SMichael Buesch if (bus->bustype == SSB_BUSTYPE_SSB || 12361e115a5SMichael Buesch bus->bustype == SSB_BUSTYPE_PCMCIA) 12461e115a5SMichael Buesch return SSB_CHIPCO_CLKSRC_XTALOS; 12561e115a5SMichael Buesch if (bus->bustype == SSB_BUSTYPE_PCI) { 12661e115a5SMichael Buesch pci_read_config_dword(bus->host_pci, SSB_GPIO_OUT, &tmp); 12761e115a5SMichael Buesch if (tmp & 0x10) 12861e115a5SMichael Buesch return SSB_CHIPCO_CLKSRC_PCI; 12961e115a5SMichael Buesch return SSB_CHIPCO_CLKSRC_XTALOS; 13061e115a5SMichael Buesch } 13161e115a5SMichael Buesch } 13261e115a5SMichael Buesch if (cc->dev->id.revision < 10) { 13361e115a5SMichael Buesch tmp = chipco_read32(cc, SSB_CHIPCO_SLOWCLKCTL); 13461e115a5SMichael Buesch tmp &= 0x7; 13561e115a5SMichael Buesch if (tmp == 0) 13661e115a5SMichael Buesch return SSB_CHIPCO_CLKSRC_LOPWROS; 13761e115a5SMichael Buesch if (tmp == 1) 13861e115a5SMichael Buesch return SSB_CHIPCO_CLKSRC_XTALOS; 13961e115a5SMichael Buesch if (tmp == 2) 14061e115a5SMichael Buesch return SSB_CHIPCO_CLKSRC_PCI; 14161e115a5SMichael Buesch } 14261e115a5SMichael Buesch 14361e115a5SMichael Buesch return SSB_CHIPCO_CLKSRC_XTALOS; 14461e115a5SMichael Buesch } 14561e115a5SMichael Buesch 14661e115a5SMichael Buesch /* Get maximum or minimum (depending on get_max flag) slowclock frequency. */ 14761e115a5SMichael Buesch static int chipco_pctl_clockfreqlimit(struct ssb_chipcommon *cc, int get_max) 14861e115a5SMichael Buesch { 14961e115a5SMichael Buesch int uninitialized_var(limit); 15061e115a5SMichael Buesch enum ssb_clksrc clocksrc; 15161e115a5SMichael Buesch int divisor = 1; 15261e115a5SMichael Buesch u32 tmp; 15361e115a5SMichael Buesch 15461e115a5SMichael Buesch clocksrc = chipco_pctl_get_slowclksrc(cc); 15561e115a5SMichael Buesch if (cc->dev->id.revision < 6) { 15661e115a5SMichael Buesch switch (clocksrc) { 15761e115a5SMichael Buesch case SSB_CHIPCO_CLKSRC_PCI: 15861e115a5SMichael Buesch divisor = 64; 15961e115a5SMichael Buesch break; 16061e115a5SMichael Buesch case SSB_CHIPCO_CLKSRC_XTALOS: 16161e115a5SMichael Buesch divisor = 32; 16261e115a5SMichael Buesch break; 16361e115a5SMichael Buesch default: 16461e115a5SMichael Buesch SSB_WARN_ON(1); 16561e115a5SMichael Buesch } 16661e115a5SMichael Buesch } else if (cc->dev->id.revision < 10) { 16761e115a5SMichael Buesch switch (clocksrc) { 16861e115a5SMichael Buesch case SSB_CHIPCO_CLKSRC_LOPWROS: 16961e115a5SMichael Buesch break; 17061e115a5SMichael Buesch case SSB_CHIPCO_CLKSRC_XTALOS: 17161e115a5SMichael Buesch case SSB_CHIPCO_CLKSRC_PCI: 17261e115a5SMichael Buesch tmp = chipco_read32(cc, SSB_CHIPCO_SLOWCLKCTL); 17361e115a5SMichael Buesch divisor = (tmp >> 16) + 1; 17461e115a5SMichael Buesch divisor *= 4; 17561e115a5SMichael Buesch break; 17661e115a5SMichael Buesch } 17761e115a5SMichael Buesch } else { 17861e115a5SMichael Buesch tmp = chipco_read32(cc, SSB_CHIPCO_SYSCLKCTL); 17961e115a5SMichael Buesch divisor = (tmp >> 16) + 1; 18061e115a5SMichael Buesch divisor *= 4; 18161e115a5SMichael Buesch } 18261e115a5SMichael Buesch 18361e115a5SMichael Buesch switch (clocksrc) { 18461e115a5SMichael Buesch case SSB_CHIPCO_CLKSRC_LOPWROS: 18561e115a5SMichael Buesch if (get_max) 18661e115a5SMichael Buesch limit = 43000; 18761e115a5SMichael Buesch else 18861e115a5SMichael Buesch limit = 25000; 18961e115a5SMichael Buesch break; 19061e115a5SMichael Buesch case SSB_CHIPCO_CLKSRC_XTALOS: 19161e115a5SMichael Buesch if (get_max) 19261e115a5SMichael Buesch limit = 20200000; 19361e115a5SMichael Buesch else 19461e115a5SMichael Buesch limit = 19800000; 19561e115a5SMichael Buesch break; 19661e115a5SMichael Buesch case SSB_CHIPCO_CLKSRC_PCI: 19761e115a5SMichael Buesch if (get_max) 19861e115a5SMichael Buesch limit = 34000000; 19961e115a5SMichael Buesch else 20061e115a5SMichael Buesch limit = 25000000; 20161e115a5SMichael Buesch break; 20261e115a5SMichael Buesch } 20361e115a5SMichael Buesch limit /= divisor; 20461e115a5SMichael Buesch 20561e115a5SMichael Buesch return limit; 20661e115a5SMichael Buesch } 20761e115a5SMichael Buesch 20861e115a5SMichael Buesch static void chipco_powercontrol_init(struct ssb_chipcommon *cc) 20961e115a5SMichael Buesch { 21061e115a5SMichael Buesch struct ssb_bus *bus = cc->dev->bus; 21161e115a5SMichael Buesch 21261e115a5SMichael Buesch if (bus->chip_id == 0x4321) { 21361e115a5SMichael Buesch if (bus->chip_rev == 0) 21461e115a5SMichael Buesch chipco_write32(cc, SSB_CHIPCO_CHIPCTL, 0x3A4); 21561e115a5SMichael Buesch else if (bus->chip_rev == 1) 21661e115a5SMichael Buesch chipco_write32(cc, SSB_CHIPCO_CHIPCTL, 0xA4); 21761e115a5SMichael Buesch } 21861e115a5SMichael Buesch 21961e115a5SMichael Buesch if (!(cc->capabilities & SSB_CHIPCO_CAP_PCTL)) 22061e115a5SMichael Buesch return; 22161e115a5SMichael Buesch 22261e115a5SMichael Buesch if (cc->dev->id.revision >= 10) { 22361e115a5SMichael Buesch /* Set Idle Power clock rate to 1Mhz */ 22461e115a5SMichael Buesch chipco_write32(cc, SSB_CHIPCO_SYSCLKCTL, 22561e115a5SMichael Buesch (chipco_read32(cc, SSB_CHIPCO_SYSCLKCTL) & 22661e115a5SMichael Buesch 0x0000FFFF) | 0x00040000); 22761e115a5SMichael Buesch } else { 22861e115a5SMichael Buesch int maxfreq; 22961e115a5SMichael Buesch 23061e115a5SMichael Buesch maxfreq = chipco_pctl_clockfreqlimit(cc, 1); 23161e115a5SMichael Buesch chipco_write32(cc, SSB_CHIPCO_PLLONDELAY, 23261e115a5SMichael Buesch (maxfreq * 150 + 999999) / 1000000); 23361e115a5SMichael Buesch chipco_write32(cc, SSB_CHIPCO_FREFSELDELAY, 23461e115a5SMichael Buesch (maxfreq * 15 + 999999) / 1000000); 23561e115a5SMichael Buesch } 23661e115a5SMichael Buesch } 23761e115a5SMichael Buesch 238fd515941SRafał Miłecki /* http://bcm-v4.sipsolutions.net/802.11/PmuFastPwrupDelay */ 239fd515941SRafał Miłecki static u16 pmu_fast_powerup_delay(struct ssb_chipcommon *cc) 240fd515941SRafał Miłecki { 241fd515941SRafał Miłecki struct ssb_bus *bus = cc->dev->bus; 242fd515941SRafał Miłecki 243fd515941SRafał Miłecki switch (bus->chip_id) { 244fd515941SRafał Miłecki case 0x4312: 245fd515941SRafał Miłecki case 0x4322: 246fd515941SRafał Miłecki case 0x4328: 247fd515941SRafał Miłecki return 7000; 248fd515941SRafał Miłecki case 0x4325: 249fd515941SRafał Miłecki /* TODO: */ 250fd515941SRafał Miłecki default: 251fd515941SRafał Miłecki return 15000; 252fd515941SRafał Miłecki } 253fd515941SRafał Miłecki } 254fd515941SRafał Miłecki 255fd515941SRafał Miłecki /* http://bcm-v4.sipsolutions.net/802.11/ClkctlFastPwrupDelay */ 25661e115a5SMichael Buesch static void calc_fast_powerup_delay(struct ssb_chipcommon *cc) 25761e115a5SMichael Buesch { 25861e115a5SMichael Buesch struct ssb_bus *bus = cc->dev->bus; 25961e115a5SMichael Buesch int minfreq; 26061e115a5SMichael Buesch unsigned int tmp; 26161e115a5SMichael Buesch u32 pll_on_delay; 26261e115a5SMichael Buesch 26361e115a5SMichael Buesch if (bus->bustype != SSB_BUSTYPE_PCI) 26461e115a5SMichael Buesch return; 265fd515941SRafał Miłecki 266fd515941SRafał Miłecki if (cc->capabilities & SSB_CHIPCO_CAP_PMU) { 267fd515941SRafał Miłecki cc->fast_pwrup_delay = pmu_fast_powerup_delay(cc); 268fd515941SRafał Miłecki return; 269fd515941SRafał Miłecki } 270fd515941SRafał Miłecki 27161e115a5SMichael Buesch if (!(cc->capabilities & SSB_CHIPCO_CAP_PCTL)) 27261e115a5SMichael Buesch return; 27361e115a5SMichael Buesch 27461e115a5SMichael Buesch minfreq = chipco_pctl_clockfreqlimit(cc, 0); 27561e115a5SMichael Buesch pll_on_delay = chipco_read32(cc, SSB_CHIPCO_PLLONDELAY); 27661e115a5SMichael Buesch tmp = (((pll_on_delay + 2) * 1000000) + (minfreq - 1)) / minfreq; 27761e115a5SMichael Buesch SSB_WARN_ON(tmp & ~0xFFFF); 27861e115a5SMichael Buesch 27961e115a5SMichael Buesch cc->fast_pwrup_delay = tmp; 28061e115a5SMichael Buesch } 28161e115a5SMichael Buesch 28261e115a5SMichael Buesch void ssb_chipcommon_init(struct ssb_chipcommon *cc) 28361e115a5SMichael Buesch { 28461e115a5SMichael Buesch if (!cc->dev) 28561e115a5SMichael Buesch return; /* We don't have a ChipCommon */ 286d53cdbb9SJohn W. Linville if (cc->dev->id.revision >= 11) 287d53cdbb9SJohn W. Linville cc->status = chipco_read32(cc, SSB_CHIPCO_CHIPSTAT); 2889d1ac34eSLarry Finger ssb_dprintk(KERN_INFO PFX "chipcommon status is 0x%x\n", cc->status); 2899835a30eSRafał Miłecki 2909835a30eSRafał Miłecki if (cc->dev->id.revision >= 20) { 2919835a30eSRafał Miłecki chipco_write32(cc, SSB_CHIPCO_GPIOPULLUP, 0); 2929835a30eSRafał Miłecki chipco_write32(cc, SSB_CHIPCO_GPIOPULLDOWN, 0); 2939835a30eSRafał Miłecki } 2949835a30eSRafał Miłecki 295c9703146SMichael Buesch ssb_pmu_init(cc); 29661e115a5SMichael Buesch chipco_powercontrol_init(cc); 29761e115a5SMichael Buesch ssb_chipco_set_clockmode(cc, SSB_CLKMODE_FAST); 29861e115a5SMichael Buesch calc_fast_powerup_delay(cc); 29961e115a5SMichael Buesch } 30061e115a5SMichael Buesch 3018fe2b65aSMichael Buesch void ssb_chipco_suspend(struct ssb_chipcommon *cc) 30261e115a5SMichael Buesch { 30361e115a5SMichael Buesch if (!cc->dev) 30461e115a5SMichael Buesch return; 30561e115a5SMichael Buesch ssb_chipco_set_clockmode(cc, SSB_CLKMODE_SLOW); 30661e115a5SMichael Buesch } 30761e115a5SMichael Buesch 30861e115a5SMichael Buesch void ssb_chipco_resume(struct ssb_chipcommon *cc) 30961e115a5SMichael Buesch { 31061e115a5SMichael Buesch if (!cc->dev) 31161e115a5SMichael Buesch return; 31261e115a5SMichael Buesch chipco_powercontrol_init(cc); 31361e115a5SMichael Buesch ssb_chipco_set_clockmode(cc, SSB_CLKMODE_FAST); 31461e115a5SMichael Buesch } 31561e115a5SMichael Buesch 31661e115a5SMichael Buesch /* Get the processor clock */ 31761e115a5SMichael Buesch void ssb_chipco_get_clockcpu(struct ssb_chipcommon *cc, 31861e115a5SMichael Buesch u32 *plltype, u32 *n, u32 *m) 31961e115a5SMichael Buesch { 32061e115a5SMichael Buesch *n = chipco_read32(cc, SSB_CHIPCO_CLOCK_N); 32161e115a5SMichael Buesch *plltype = (cc->capabilities & SSB_CHIPCO_CAP_PLLT); 32261e115a5SMichael Buesch switch (*plltype) { 32361e115a5SMichael Buesch case SSB_PLLTYPE_2: 32461e115a5SMichael Buesch case SSB_PLLTYPE_4: 32561e115a5SMichael Buesch case SSB_PLLTYPE_6: 32661e115a5SMichael Buesch case SSB_PLLTYPE_7: 32761e115a5SMichael Buesch *m = chipco_read32(cc, SSB_CHIPCO_CLOCK_MIPS); 32861e115a5SMichael Buesch break; 32961e115a5SMichael Buesch case SSB_PLLTYPE_3: 33061e115a5SMichael Buesch /* 5350 uses m2 to control mips */ 33161e115a5SMichael Buesch *m = chipco_read32(cc, SSB_CHIPCO_CLOCK_M2); 33261e115a5SMichael Buesch break; 33361e115a5SMichael Buesch default: 33461e115a5SMichael Buesch *m = chipco_read32(cc, SSB_CHIPCO_CLOCK_SB); 33561e115a5SMichael Buesch break; 33661e115a5SMichael Buesch } 33761e115a5SMichael Buesch } 33861e115a5SMichael Buesch 33961e115a5SMichael Buesch /* Get the bus clock */ 34061e115a5SMichael Buesch void ssb_chipco_get_clockcontrol(struct ssb_chipcommon *cc, 34161e115a5SMichael Buesch u32 *plltype, u32 *n, u32 *m) 34261e115a5SMichael Buesch { 34361e115a5SMichael Buesch *n = chipco_read32(cc, SSB_CHIPCO_CLOCK_N); 34461e115a5SMichael Buesch *plltype = (cc->capabilities & SSB_CHIPCO_CAP_PLLT); 34561e115a5SMichael Buesch switch (*plltype) { 34661e115a5SMichael Buesch case SSB_PLLTYPE_6: /* 100/200 or 120/240 only */ 34761e115a5SMichael Buesch *m = chipco_read32(cc, SSB_CHIPCO_CLOCK_MIPS); 34861e115a5SMichael Buesch break; 34961e115a5SMichael Buesch case SSB_PLLTYPE_3: /* 25Mhz, 2 dividers */ 35061e115a5SMichael Buesch if (cc->dev->bus->chip_id != 0x5365) { 35161e115a5SMichael Buesch *m = chipco_read32(cc, SSB_CHIPCO_CLOCK_M2); 35261e115a5SMichael Buesch break; 35361e115a5SMichael Buesch } 35461e115a5SMichael Buesch /* Fallthough */ 35561e115a5SMichael Buesch default: 35661e115a5SMichael Buesch *m = chipco_read32(cc, SSB_CHIPCO_CLOCK_SB); 35761e115a5SMichael Buesch } 35861e115a5SMichael Buesch } 35961e115a5SMichael Buesch 36061e115a5SMichael Buesch void ssb_chipco_timing_init(struct ssb_chipcommon *cc, 36161e115a5SMichael Buesch unsigned long ns) 36261e115a5SMichael Buesch { 36361e115a5SMichael Buesch struct ssb_device *dev = cc->dev; 36461e115a5SMichael Buesch struct ssb_bus *bus = dev->bus; 36561e115a5SMichael Buesch u32 tmp; 36661e115a5SMichael Buesch 36761e115a5SMichael Buesch /* set register for external IO to control LED. */ 36861e115a5SMichael Buesch chipco_write32(cc, SSB_CHIPCO_PROG_CFG, 0x11); 36961e115a5SMichael Buesch tmp = DIV_ROUND_UP(10, ns) << SSB_PROG_WCNT_3_SHIFT; /* Waitcount-3 = 10ns */ 37061e115a5SMichael Buesch tmp |= DIV_ROUND_UP(40, ns) << SSB_PROG_WCNT_1_SHIFT; /* Waitcount-1 = 40ns */ 37161e115a5SMichael Buesch tmp |= DIV_ROUND_UP(240, ns); /* Waitcount-0 = 240ns */ 37261e115a5SMichael Buesch chipco_write32(cc, SSB_CHIPCO_PROG_WAITCNT, tmp); /* 0x01020a0c for a 100Mhz clock */ 37361e115a5SMichael Buesch 37461e115a5SMichael Buesch /* Set timing for the flash */ 37561e115a5SMichael Buesch tmp = DIV_ROUND_UP(10, ns) << SSB_FLASH_WCNT_3_SHIFT; /* Waitcount-3 = 10nS */ 37661e115a5SMichael Buesch tmp |= DIV_ROUND_UP(10, ns) << SSB_FLASH_WCNT_1_SHIFT; /* Waitcount-1 = 10nS */ 37761e115a5SMichael Buesch tmp |= DIV_ROUND_UP(120, ns); /* Waitcount-0 = 120nS */ 37861e115a5SMichael Buesch if ((bus->chip_id == 0x5365) || 37961e115a5SMichael Buesch (dev->id.revision < 9)) 38061e115a5SMichael Buesch chipco_write32(cc, SSB_CHIPCO_FLASH_WAITCNT, tmp); 38161e115a5SMichael Buesch if ((bus->chip_id == 0x5365) || 38261e115a5SMichael Buesch (dev->id.revision < 9) || 38361e115a5SMichael Buesch ((bus->chip_id == 0x5350) && (bus->chip_rev == 0))) 38461e115a5SMichael Buesch chipco_write32(cc, SSB_CHIPCO_PCMCIA_MEMWAIT, tmp); 38561e115a5SMichael Buesch 38661e115a5SMichael Buesch if (bus->chip_id == 0x5350) { 38761e115a5SMichael Buesch /* Enable EXTIF */ 38861e115a5SMichael Buesch tmp = DIV_ROUND_UP(10, ns) << SSB_PROG_WCNT_3_SHIFT; /* Waitcount-3 = 10ns */ 38961e115a5SMichael Buesch tmp |= DIV_ROUND_UP(20, ns) << SSB_PROG_WCNT_2_SHIFT; /* Waitcount-2 = 20ns */ 39061e115a5SMichael Buesch tmp |= DIV_ROUND_UP(100, ns) << SSB_PROG_WCNT_1_SHIFT; /* Waitcount-1 = 100ns */ 39161e115a5SMichael Buesch tmp |= DIV_ROUND_UP(120, ns); /* Waitcount-0 = 120ns */ 39261e115a5SMichael Buesch chipco_write32(cc, SSB_CHIPCO_PROG_WAITCNT, tmp); /* 0x01020a0c for a 100Mhz clock */ 39361e115a5SMichael Buesch } 39461e115a5SMichael Buesch } 39561e115a5SMichael Buesch 39661e115a5SMichael Buesch /* Set chip watchdog reset timer to fire in 'ticks' backplane cycles */ 3976b9bafecSMichael Buesch void ssb_chipco_watchdog_timer_set(struct ssb_chipcommon *cc, u32 ticks) 39861e115a5SMichael Buesch { 39961e115a5SMichael Buesch /* instant NMI */ 40061e115a5SMichael Buesch chipco_write32(cc, SSB_CHIPCO_WATCHDOG, ticks); 40161e115a5SMichael Buesch } 40261e115a5SMichael Buesch 40328de57d1SAurelien Jarno void ssb_chipco_irq_mask(struct ssb_chipcommon *cc, u32 mask, u32 value) 40428de57d1SAurelien Jarno { 40528de57d1SAurelien Jarno chipco_write32_masked(cc, SSB_CHIPCO_IRQMASK, mask, value); 40628de57d1SAurelien Jarno } 40728de57d1SAurelien Jarno 40828de57d1SAurelien Jarno u32 ssb_chipco_irq_status(struct ssb_chipcommon *cc, u32 mask) 40928de57d1SAurelien Jarno { 41028de57d1SAurelien Jarno return chipco_read32(cc, SSB_CHIPCO_IRQSTAT) & mask; 41128de57d1SAurelien Jarno } 41228de57d1SAurelien Jarno 41361e115a5SMichael Buesch u32 ssb_chipco_gpio_in(struct ssb_chipcommon *cc, u32 mask) 41461e115a5SMichael Buesch { 41561e115a5SMichael Buesch return chipco_read32(cc, SSB_CHIPCO_GPIOIN) & mask; 41661e115a5SMichael Buesch } 41761e115a5SMichael Buesch 418c2bcbe65SMichael Buesch u32 ssb_chipco_gpio_out(struct ssb_chipcommon *cc, u32 mask, u32 value) 41961e115a5SMichael Buesch { 420c2bcbe65SMichael Buesch return chipco_write32_masked(cc, SSB_CHIPCO_GPIOOUT, mask, value); 42161e115a5SMichael Buesch } 42261e115a5SMichael Buesch 423c2bcbe65SMichael Buesch u32 ssb_chipco_gpio_outen(struct ssb_chipcommon *cc, u32 mask, u32 value) 42461e115a5SMichael Buesch { 425c2bcbe65SMichael Buesch return chipco_write32_masked(cc, SSB_CHIPCO_GPIOOUTEN, mask, value); 42661e115a5SMichael Buesch } 427c2bcbe65SMichael Buesch 428c2bcbe65SMichael Buesch u32 ssb_chipco_gpio_control(struct ssb_chipcommon *cc, u32 mask, u32 value) 429c2bcbe65SMichael Buesch { 430c2bcbe65SMichael Buesch return chipco_write32_masked(cc, SSB_CHIPCO_GPIOCTL, mask, value); 431c2bcbe65SMichael Buesch } 43285373ee8SLarry Finger EXPORT_SYMBOL(ssb_chipco_gpio_control); 433c2bcbe65SMichael Buesch 434c2bcbe65SMichael Buesch u32 ssb_chipco_gpio_intmask(struct ssb_chipcommon *cc, u32 mask, u32 value) 435c2bcbe65SMichael Buesch { 436c2bcbe65SMichael Buesch return chipco_write32_masked(cc, SSB_CHIPCO_GPIOIRQ, mask, value); 437c2bcbe65SMichael Buesch } 438c2bcbe65SMichael Buesch 439c2bcbe65SMichael Buesch u32 ssb_chipco_gpio_polarity(struct ssb_chipcommon *cc, u32 mask, u32 value) 440c2bcbe65SMichael Buesch { 441c2bcbe65SMichael Buesch return chipco_write32_masked(cc, SSB_CHIPCO_GPIOPOL, mask, value); 442c2bcbe65SMichael Buesch } 44361e115a5SMichael Buesch 44461e115a5SMichael Buesch #ifdef CONFIG_SSB_SERIAL 44561e115a5SMichael Buesch int ssb_chipco_serial_init(struct ssb_chipcommon *cc, 44661e115a5SMichael Buesch struct ssb_serial_port *ports) 44761e115a5SMichael Buesch { 44861e115a5SMichael Buesch struct ssb_bus *bus = cc->dev->bus; 44961e115a5SMichael Buesch int nr_ports = 0; 45061e115a5SMichael Buesch u32 plltype; 45161e115a5SMichael Buesch unsigned int irq; 45261e115a5SMichael Buesch u32 baud_base, div; 45361e115a5SMichael Buesch u32 i, n; 45458ff70d4SMichael Buesch unsigned int ccrev = cc->dev->id.revision; 45561e115a5SMichael Buesch 45661e115a5SMichael Buesch plltype = (cc->capabilities & SSB_CHIPCO_CAP_PLLT); 45761e115a5SMichael Buesch irq = ssb_mips_irq(cc->dev); 45861e115a5SMichael Buesch 45961e115a5SMichael Buesch if (plltype == SSB_PLLTYPE_1) { 46061e115a5SMichael Buesch /* PLL clock */ 46161e115a5SMichael Buesch baud_base = ssb_calc_clock_rate(plltype, 46261e115a5SMichael Buesch chipco_read32(cc, SSB_CHIPCO_CLOCK_N), 46361e115a5SMichael Buesch chipco_read32(cc, SSB_CHIPCO_CLOCK_M2)); 46461e115a5SMichael Buesch div = 1; 46561e115a5SMichael Buesch } else { 46658ff70d4SMichael Buesch if (ccrev == 20) { 46758ff70d4SMichael Buesch /* BCM5354 uses constant 25MHz clock */ 46858ff70d4SMichael Buesch baud_base = 25000000; 46958ff70d4SMichael Buesch div = 48; 47061e115a5SMichael Buesch /* Set the override bit so we don't divide it */ 47161e115a5SMichael Buesch chipco_write32(cc, SSB_CHIPCO_CORECTL, 47258ff70d4SMichael Buesch chipco_read32(cc, SSB_CHIPCO_CORECTL) 47358ff70d4SMichael Buesch | SSB_CHIPCO_CORECTL_UARTCLK0); 47458ff70d4SMichael Buesch } else if ((ccrev >= 11) && (ccrev != 15)) { 47558ff70d4SMichael Buesch /* Fixed ALP clock */ 47658ff70d4SMichael Buesch baud_base = 20000000; 47758ff70d4SMichael Buesch if (cc->capabilities & SSB_CHIPCO_CAP_PMU) { 47858ff70d4SMichael Buesch /* FIXME: baud_base is different for devices with a PMU */ 47958ff70d4SMichael Buesch SSB_WARN_ON(1); 48058ff70d4SMichael Buesch } 48158ff70d4SMichael Buesch div = 1; 48258ff70d4SMichael Buesch if (ccrev >= 21) { 48358ff70d4SMichael Buesch /* Turn off UART clock before switching clocksource. */ 48458ff70d4SMichael Buesch chipco_write32(cc, SSB_CHIPCO_CORECTL, 48558ff70d4SMichael Buesch chipco_read32(cc, SSB_CHIPCO_CORECTL) 48658ff70d4SMichael Buesch & ~SSB_CHIPCO_CORECTL_UARTCLKEN); 48758ff70d4SMichael Buesch } 48858ff70d4SMichael Buesch /* Set the override bit so we don't divide it */ 48958ff70d4SMichael Buesch chipco_write32(cc, SSB_CHIPCO_CORECTL, 49058ff70d4SMichael Buesch chipco_read32(cc, SSB_CHIPCO_CORECTL) 49158ff70d4SMichael Buesch | SSB_CHIPCO_CORECTL_UARTCLK0); 49258ff70d4SMichael Buesch if (ccrev >= 21) { 49358ff70d4SMichael Buesch /* Re-enable the UART clock. */ 49458ff70d4SMichael Buesch chipco_write32(cc, SSB_CHIPCO_CORECTL, 49558ff70d4SMichael Buesch chipco_read32(cc, SSB_CHIPCO_CORECTL) 49658ff70d4SMichael Buesch | SSB_CHIPCO_CORECTL_UARTCLKEN); 49758ff70d4SMichael Buesch } 49858ff70d4SMichael Buesch } else if (ccrev >= 3) { 49961e115a5SMichael Buesch /* Internal backplane clock */ 50061e115a5SMichael Buesch baud_base = ssb_clockspeed(bus); 50161e115a5SMichael Buesch div = chipco_read32(cc, SSB_CHIPCO_CLKDIV) 50261e115a5SMichael Buesch & SSB_CHIPCO_CLKDIV_UART; 50361e115a5SMichael Buesch } else { 50461e115a5SMichael Buesch /* Fixed internal backplane clock */ 50561e115a5SMichael Buesch baud_base = 88000000; 50661e115a5SMichael Buesch div = 48; 50761e115a5SMichael Buesch } 50861e115a5SMichael Buesch 50961e115a5SMichael Buesch /* Clock source depends on strapping if UartClkOverride is unset */ 51058ff70d4SMichael Buesch if ((ccrev > 0) && 51161e115a5SMichael Buesch !(chipco_read32(cc, SSB_CHIPCO_CORECTL) & SSB_CHIPCO_CORECTL_UARTCLK0)) { 51261e115a5SMichael Buesch if ((cc->capabilities & SSB_CHIPCO_CAP_UARTCLK) == 51361e115a5SMichael Buesch SSB_CHIPCO_CAP_UARTCLK_INT) { 51461e115a5SMichael Buesch /* Internal divided backplane clock */ 51561e115a5SMichael Buesch baud_base /= div; 51661e115a5SMichael Buesch } else { 51761e115a5SMichael Buesch /* Assume external clock of 1.8432 MHz */ 51861e115a5SMichael Buesch baud_base = 1843200; 51961e115a5SMichael Buesch } 52061e115a5SMichael Buesch } 52161e115a5SMichael Buesch } 52261e115a5SMichael Buesch 52361e115a5SMichael Buesch /* Determine the registers of the UARTs */ 52461e115a5SMichael Buesch n = (cc->capabilities & SSB_CHIPCO_CAP_NRUART); 52561e115a5SMichael Buesch for (i = 0; i < n; i++) { 52661e115a5SMichael Buesch void __iomem *cc_mmio; 52761e115a5SMichael Buesch void __iomem *uart_regs; 52861e115a5SMichael Buesch 52961e115a5SMichael Buesch cc_mmio = cc->dev->bus->mmio + (cc->dev->core_index * SSB_CORE_SIZE); 53061e115a5SMichael Buesch uart_regs = cc_mmio + SSB_CHIPCO_UART0_DATA; 53161e115a5SMichael Buesch /* Offset changed at after rev 0 */ 53258ff70d4SMichael Buesch if (ccrev == 0) 53361e115a5SMichael Buesch uart_regs += (i * 8); 53461e115a5SMichael Buesch else 53561e115a5SMichael Buesch uart_regs += (i * 256); 53661e115a5SMichael Buesch 53761e115a5SMichael Buesch nr_ports++; 53861e115a5SMichael Buesch ports[i].regs = uart_regs; 53961e115a5SMichael Buesch ports[i].irq = irq; 54061e115a5SMichael Buesch ports[i].baud_base = baud_base; 54161e115a5SMichael Buesch ports[i].reg_shift = 0; 54261e115a5SMichael Buesch } 54361e115a5SMichael Buesch 54461e115a5SMichael Buesch return nr_ports; 54561e115a5SMichael Buesch } 54661e115a5SMichael Buesch #endif /* CONFIG_SSB_SERIAL */ 547