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> 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> 131014c22eSPaul Gortmaker #include <linux/export.h> 1461e115a5SMichael Buesch #include <linux/pci.h> 1561e115a5SMichael Buesch 1661e115a5SMichael Buesch #include "ssb_private.h" 1761e115a5SMichael Buesch 1861e115a5SMichael Buesch 1961e115a5SMichael Buesch /* Clock sources */ 2061e115a5SMichael Buesch enum ssb_clksrc { 2161e115a5SMichael Buesch /* PCI clock */ 2261e115a5SMichael Buesch SSB_CHIPCO_CLKSRC_PCI, 2361e115a5SMichael Buesch /* Crystal slow clock oscillator */ 2461e115a5SMichael Buesch SSB_CHIPCO_CLKSRC_XTALOS, 2561e115a5SMichael Buesch /* Low power oscillator */ 2661e115a5SMichael Buesch SSB_CHIPCO_CLKSRC_LOPWROS, 2761e115a5SMichael Buesch }; 2861e115a5SMichael Buesch 2961e115a5SMichael Buesch 30c2bcbe65SMichael Buesch static inline u32 chipco_write32_masked(struct ssb_chipcommon *cc, u16 offset, 3161e115a5SMichael Buesch u32 mask, u32 value) 3261e115a5SMichael Buesch { 3361e115a5SMichael Buesch value &= mask; 3461e115a5SMichael Buesch value |= chipco_read32(cc, offset) & ~mask; 3561e115a5SMichael Buesch chipco_write32(cc, offset, value); 36c2bcbe65SMichael Buesch 37c2bcbe65SMichael Buesch return value; 3861e115a5SMichael Buesch } 3961e115a5SMichael Buesch 4061e115a5SMichael Buesch void ssb_chipco_set_clockmode(struct ssb_chipcommon *cc, 4161e115a5SMichael Buesch enum ssb_clkmode mode) 4261e115a5SMichael Buesch { 4361e115a5SMichael Buesch struct ssb_device *ccdev = cc->dev; 4461e115a5SMichael Buesch struct ssb_bus *bus; 4561e115a5SMichael Buesch u32 tmp; 4661e115a5SMichael Buesch 4761e115a5SMichael Buesch if (!ccdev) 4861e115a5SMichael Buesch return; 4961e115a5SMichael Buesch bus = ccdev->bus; 500ca69955SRafał Miłecki 510ca69955SRafał Miłecki /* We support SLOW only on 6..9 */ 520ca69955SRafał Miłecki if (ccdev->id.revision >= 10 && mode == SSB_CLKMODE_SLOW) 530ca69955SRafał Miłecki mode = SSB_CLKMODE_DYNAMIC; 540ca69955SRafał Miłecki 550ca69955SRafał Miłecki if (cc->capabilities & SSB_CHIPCO_CAP_PMU) 560ca69955SRafał Miłecki return; /* PMU controls clockmode, separated function needed */ 570ca69955SRafał Miłecki SSB_WARN_ON(ccdev->id.revision >= 20); 580ca69955SRafał Miłecki 5961e115a5SMichael Buesch /* chipcommon cores prior to rev6 don't support dynamic clock control */ 6061e115a5SMichael Buesch if (ccdev->id.revision < 6) 6161e115a5SMichael Buesch return; 620ca69955SRafał Miłecki 630ca69955SRafał Miłecki /* ChipCommon cores rev10+ need testing */ 6461e115a5SMichael Buesch if (ccdev->id.revision >= 10) 6561e115a5SMichael Buesch return; 660ca69955SRafał Miłecki 6761e115a5SMichael Buesch if (!(cc->capabilities & SSB_CHIPCO_CAP_PCTL)) 6861e115a5SMichael Buesch return; 6961e115a5SMichael Buesch 7061e115a5SMichael Buesch switch (mode) { 710ca69955SRafał Miłecki case SSB_CLKMODE_SLOW: /* For revs 6..9 only */ 7261e115a5SMichael Buesch tmp = chipco_read32(cc, SSB_CHIPCO_SLOWCLKCTL); 7361e115a5SMichael Buesch tmp |= SSB_CHIPCO_SLOWCLKCTL_FSLOW; 7461e115a5SMichael Buesch chipco_write32(cc, SSB_CHIPCO_SLOWCLKCTL, tmp); 7561e115a5SMichael Buesch break; 7661e115a5SMichael Buesch case SSB_CLKMODE_FAST: 770ca69955SRafał Miłecki if (ccdev->id.revision < 10) { 7861e115a5SMichael Buesch ssb_pci_xtal(bus, SSB_GPIO_XTAL, 1); /* Force crystal on */ 7961e115a5SMichael Buesch tmp = chipco_read32(cc, SSB_CHIPCO_SLOWCLKCTL); 8061e115a5SMichael Buesch tmp &= ~SSB_CHIPCO_SLOWCLKCTL_FSLOW; 8161e115a5SMichael Buesch tmp |= SSB_CHIPCO_SLOWCLKCTL_IPLL; 8261e115a5SMichael Buesch chipco_write32(cc, SSB_CHIPCO_SLOWCLKCTL, tmp); 830ca69955SRafał Miłecki } else { 840ca69955SRafał Miłecki chipco_write32(cc, SSB_CHIPCO_SYSCLKCTL, 850ca69955SRafał Miłecki (chipco_read32(cc, SSB_CHIPCO_SYSCLKCTL) | 860ca69955SRafał Miłecki SSB_CHIPCO_SYSCLKCTL_FORCEHT)); 870ca69955SRafał Miłecki /* udelay(150); TODO: not available in early init */ 880ca69955SRafał Miłecki } 8961e115a5SMichael Buesch break; 9061e115a5SMichael Buesch case SSB_CLKMODE_DYNAMIC: 910ca69955SRafał Miłecki if (ccdev->id.revision < 10) { 9261e115a5SMichael Buesch tmp = chipco_read32(cc, SSB_CHIPCO_SLOWCLKCTL); 9361e115a5SMichael Buesch tmp &= ~SSB_CHIPCO_SLOWCLKCTL_FSLOW; 9461e115a5SMichael Buesch tmp &= ~SSB_CHIPCO_SLOWCLKCTL_IPLL; 9561e115a5SMichael Buesch tmp &= ~SSB_CHIPCO_SLOWCLKCTL_ENXTAL; 960ca69955SRafał Miłecki if ((tmp & SSB_CHIPCO_SLOWCLKCTL_SRC) != 970ca69955SRafał Miłecki SSB_CHIPCO_SLOWCLKCTL_SRC_XTAL) 9861e115a5SMichael Buesch tmp |= SSB_CHIPCO_SLOWCLKCTL_ENXTAL; 9961e115a5SMichael Buesch chipco_write32(cc, SSB_CHIPCO_SLOWCLKCTL, tmp); 10061e115a5SMichael Buesch 1010ca69955SRafał Miłecki /* For dynamic control, we have to release our xtal_pu 1020ca69955SRafał Miłecki * "force on" */ 10361e115a5SMichael Buesch if (tmp & SSB_CHIPCO_SLOWCLKCTL_ENXTAL) 10461e115a5SMichael Buesch ssb_pci_xtal(bus, SSB_GPIO_XTAL, 0); 1050ca69955SRafał Miłecki } else { 1060ca69955SRafał Miłecki chipco_write32(cc, SSB_CHIPCO_SYSCLKCTL, 1070ca69955SRafał Miłecki (chipco_read32(cc, SSB_CHIPCO_SYSCLKCTL) & 1080ca69955SRafał Miłecki ~SSB_CHIPCO_SYSCLKCTL_FORCEHT)); 1090ca69955SRafał Miłecki } 11061e115a5SMichael Buesch break; 11161e115a5SMichael Buesch default: 11261e115a5SMichael Buesch SSB_WARN_ON(1); 11361e115a5SMichael Buesch } 11461e115a5SMichael Buesch } 11561e115a5SMichael Buesch 11661e115a5SMichael Buesch /* Get the Slow Clock Source */ 11761e115a5SMichael Buesch static enum ssb_clksrc chipco_pctl_get_slowclksrc(struct ssb_chipcommon *cc) 11861e115a5SMichael Buesch { 11961e115a5SMichael Buesch struct ssb_bus *bus = cc->dev->bus; 12061e115a5SMichael Buesch u32 uninitialized_var(tmp); 12161e115a5SMichael Buesch 12261e115a5SMichael Buesch if (cc->dev->id.revision < 6) { 12361e115a5SMichael Buesch if (bus->bustype == SSB_BUSTYPE_SSB || 12461e115a5SMichael Buesch bus->bustype == SSB_BUSTYPE_PCMCIA) 12561e115a5SMichael Buesch return SSB_CHIPCO_CLKSRC_XTALOS; 12661e115a5SMichael Buesch if (bus->bustype == SSB_BUSTYPE_PCI) { 12761e115a5SMichael Buesch pci_read_config_dword(bus->host_pci, SSB_GPIO_OUT, &tmp); 12861e115a5SMichael Buesch if (tmp & 0x10) 12961e115a5SMichael Buesch return SSB_CHIPCO_CLKSRC_PCI; 13061e115a5SMichael Buesch return SSB_CHIPCO_CLKSRC_XTALOS; 13161e115a5SMichael Buesch } 13261e115a5SMichael Buesch } 13361e115a5SMichael Buesch if (cc->dev->id.revision < 10) { 13461e115a5SMichael Buesch tmp = chipco_read32(cc, SSB_CHIPCO_SLOWCLKCTL); 13561e115a5SMichael Buesch tmp &= 0x7; 13661e115a5SMichael Buesch if (tmp == 0) 13761e115a5SMichael Buesch return SSB_CHIPCO_CLKSRC_LOPWROS; 13861e115a5SMichael Buesch if (tmp == 1) 13961e115a5SMichael Buesch return SSB_CHIPCO_CLKSRC_XTALOS; 14061e115a5SMichael Buesch if (tmp == 2) 14161e115a5SMichael Buesch return SSB_CHIPCO_CLKSRC_PCI; 14261e115a5SMichael Buesch } 14361e115a5SMichael Buesch 14461e115a5SMichael Buesch return SSB_CHIPCO_CLKSRC_XTALOS; 14561e115a5SMichael Buesch } 14661e115a5SMichael Buesch 14761e115a5SMichael Buesch /* Get maximum or minimum (depending on get_max flag) slowclock frequency. */ 14861e115a5SMichael Buesch static int chipco_pctl_clockfreqlimit(struct ssb_chipcommon *cc, int get_max) 14961e115a5SMichael Buesch { 15061e115a5SMichael Buesch int uninitialized_var(limit); 15161e115a5SMichael Buesch enum ssb_clksrc clocksrc; 15261e115a5SMichael Buesch int divisor = 1; 15361e115a5SMichael Buesch u32 tmp; 15461e115a5SMichael Buesch 15561e115a5SMichael Buesch clocksrc = chipco_pctl_get_slowclksrc(cc); 15661e115a5SMichael Buesch if (cc->dev->id.revision < 6) { 15761e115a5SMichael Buesch switch (clocksrc) { 15861e115a5SMichael Buesch case SSB_CHIPCO_CLKSRC_PCI: 15961e115a5SMichael Buesch divisor = 64; 16061e115a5SMichael Buesch break; 16161e115a5SMichael Buesch case SSB_CHIPCO_CLKSRC_XTALOS: 16261e115a5SMichael Buesch divisor = 32; 16361e115a5SMichael Buesch break; 16461e115a5SMichael Buesch default: 16561e115a5SMichael Buesch SSB_WARN_ON(1); 16661e115a5SMichael Buesch } 16761e115a5SMichael Buesch } else if (cc->dev->id.revision < 10) { 16861e115a5SMichael Buesch switch (clocksrc) { 16961e115a5SMichael Buesch case SSB_CHIPCO_CLKSRC_LOPWROS: 17061e115a5SMichael Buesch break; 17161e115a5SMichael Buesch case SSB_CHIPCO_CLKSRC_XTALOS: 17261e115a5SMichael Buesch case SSB_CHIPCO_CLKSRC_PCI: 17361e115a5SMichael Buesch tmp = chipco_read32(cc, SSB_CHIPCO_SLOWCLKCTL); 17461e115a5SMichael Buesch divisor = (tmp >> 16) + 1; 17561e115a5SMichael Buesch divisor *= 4; 17661e115a5SMichael Buesch break; 17761e115a5SMichael Buesch } 17861e115a5SMichael Buesch } else { 17961e115a5SMichael Buesch tmp = chipco_read32(cc, SSB_CHIPCO_SYSCLKCTL); 18061e115a5SMichael Buesch divisor = (tmp >> 16) + 1; 18161e115a5SMichael Buesch divisor *= 4; 18261e115a5SMichael Buesch } 18361e115a5SMichael Buesch 18461e115a5SMichael Buesch switch (clocksrc) { 18561e115a5SMichael Buesch case SSB_CHIPCO_CLKSRC_LOPWROS: 18661e115a5SMichael Buesch if (get_max) 18761e115a5SMichael Buesch limit = 43000; 18861e115a5SMichael Buesch else 18961e115a5SMichael Buesch limit = 25000; 19061e115a5SMichael Buesch break; 19161e115a5SMichael Buesch case SSB_CHIPCO_CLKSRC_XTALOS: 19261e115a5SMichael Buesch if (get_max) 19361e115a5SMichael Buesch limit = 20200000; 19461e115a5SMichael Buesch else 19561e115a5SMichael Buesch limit = 19800000; 19661e115a5SMichael Buesch break; 19761e115a5SMichael Buesch case SSB_CHIPCO_CLKSRC_PCI: 19861e115a5SMichael Buesch if (get_max) 19961e115a5SMichael Buesch limit = 34000000; 20061e115a5SMichael Buesch else 20161e115a5SMichael Buesch limit = 25000000; 20261e115a5SMichael Buesch break; 20361e115a5SMichael Buesch } 20461e115a5SMichael Buesch limit /= divisor; 20561e115a5SMichael Buesch 20661e115a5SMichael Buesch return limit; 20761e115a5SMichael Buesch } 20861e115a5SMichael Buesch 20961e115a5SMichael Buesch static void chipco_powercontrol_init(struct ssb_chipcommon *cc) 21061e115a5SMichael Buesch { 21161e115a5SMichael Buesch struct ssb_bus *bus = cc->dev->bus; 21261e115a5SMichael Buesch 21361e115a5SMichael Buesch if (bus->chip_id == 0x4321) { 21461e115a5SMichael Buesch if (bus->chip_rev == 0) 21561e115a5SMichael Buesch chipco_write32(cc, SSB_CHIPCO_CHIPCTL, 0x3A4); 21661e115a5SMichael Buesch else if (bus->chip_rev == 1) 21761e115a5SMichael Buesch chipco_write32(cc, SSB_CHIPCO_CHIPCTL, 0xA4); 21861e115a5SMichael Buesch } 21961e115a5SMichael Buesch 22061e115a5SMichael Buesch if (!(cc->capabilities & SSB_CHIPCO_CAP_PCTL)) 22161e115a5SMichael Buesch return; 22261e115a5SMichael Buesch 22361e115a5SMichael Buesch if (cc->dev->id.revision >= 10) { 22461e115a5SMichael Buesch /* Set Idle Power clock rate to 1Mhz */ 22561e115a5SMichael Buesch chipco_write32(cc, SSB_CHIPCO_SYSCLKCTL, 22661e115a5SMichael Buesch (chipco_read32(cc, SSB_CHIPCO_SYSCLKCTL) & 22761e115a5SMichael Buesch 0x0000FFFF) | 0x00040000); 22861e115a5SMichael Buesch } else { 22961e115a5SMichael Buesch int maxfreq; 23061e115a5SMichael Buesch 23161e115a5SMichael Buesch maxfreq = chipco_pctl_clockfreqlimit(cc, 1); 23261e115a5SMichael Buesch chipco_write32(cc, SSB_CHIPCO_PLLONDELAY, 23361e115a5SMichael Buesch (maxfreq * 150 + 999999) / 1000000); 23461e115a5SMichael Buesch chipco_write32(cc, SSB_CHIPCO_FREFSELDELAY, 23561e115a5SMichael Buesch (maxfreq * 15 + 999999) / 1000000); 23661e115a5SMichael Buesch } 23761e115a5SMichael Buesch } 23861e115a5SMichael Buesch 239fd515941SRafał Miłecki /* http://bcm-v4.sipsolutions.net/802.11/PmuFastPwrupDelay */ 240fd515941SRafał Miłecki static u16 pmu_fast_powerup_delay(struct ssb_chipcommon *cc) 241fd515941SRafał Miłecki { 242fd515941SRafał Miłecki struct ssb_bus *bus = cc->dev->bus; 243fd515941SRafał Miłecki 244fd515941SRafał Miłecki switch (bus->chip_id) { 245fd515941SRafał Miłecki case 0x4312: 246fd515941SRafał Miłecki case 0x4322: 247fd515941SRafał Miłecki case 0x4328: 248fd515941SRafał Miłecki return 7000; 249fd515941SRafał Miłecki case 0x4325: 250fd515941SRafał Miłecki /* TODO: */ 251fd515941SRafał Miłecki default: 252fd515941SRafał Miłecki return 15000; 253fd515941SRafał Miłecki } 254fd515941SRafał Miłecki } 255fd515941SRafał Miłecki 256fd515941SRafał Miłecki /* http://bcm-v4.sipsolutions.net/802.11/ClkctlFastPwrupDelay */ 25761e115a5SMichael Buesch static void calc_fast_powerup_delay(struct ssb_chipcommon *cc) 25861e115a5SMichael Buesch { 25961e115a5SMichael Buesch struct ssb_bus *bus = cc->dev->bus; 26061e115a5SMichael Buesch int minfreq; 26161e115a5SMichael Buesch unsigned int tmp; 26261e115a5SMichael Buesch u32 pll_on_delay; 26361e115a5SMichael Buesch 26461e115a5SMichael Buesch if (bus->bustype != SSB_BUSTYPE_PCI) 26561e115a5SMichael Buesch return; 266fd515941SRafał Miłecki 267fd515941SRafał Miłecki if (cc->capabilities & SSB_CHIPCO_CAP_PMU) { 268fd515941SRafał Miłecki cc->fast_pwrup_delay = pmu_fast_powerup_delay(cc); 269fd515941SRafał Miłecki return; 270fd515941SRafał Miłecki } 271fd515941SRafał Miłecki 27261e115a5SMichael Buesch if (!(cc->capabilities & SSB_CHIPCO_CAP_PCTL)) 27361e115a5SMichael Buesch return; 27461e115a5SMichael Buesch 27561e115a5SMichael Buesch minfreq = chipco_pctl_clockfreqlimit(cc, 0); 27661e115a5SMichael Buesch pll_on_delay = chipco_read32(cc, SSB_CHIPCO_PLLONDELAY); 27761e115a5SMichael Buesch tmp = (((pll_on_delay + 2) * 1000000) + (minfreq - 1)) / minfreq; 27861e115a5SMichael Buesch SSB_WARN_ON(tmp & ~0xFFFF); 27961e115a5SMichael Buesch 28061e115a5SMichael Buesch cc->fast_pwrup_delay = tmp; 28161e115a5SMichael Buesch } 28261e115a5SMichael Buesch 28361e115a5SMichael Buesch void ssb_chipcommon_init(struct ssb_chipcommon *cc) 28461e115a5SMichael Buesch { 28561e115a5SMichael Buesch if (!cc->dev) 28661e115a5SMichael Buesch return; /* We don't have a ChipCommon */ 287d53cdbb9SJohn W. Linville if (cc->dev->id.revision >= 11) 288d53cdbb9SJohn W. Linville cc->status = chipco_read32(cc, SSB_CHIPCO_CHIPSTAT); 2899d1ac34eSLarry Finger ssb_dprintk(KERN_INFO PFX "chipcommon status is 0x%x\n", cc->status); 2909835a30eSRafał Miłecki 2919835a30eSRafał Miłecki if (cc->dev->id.revision >= 20) { 2929835a30eSRafał Miłecki chipco_write32(cc, SSB_CHIPCO_GPIOPULLUP, 0); 2939835a30eSRafał Miłecki chipco_write32(cc, SSB_CHIPCO_GPIOPULLDOWN, 0); 2949835a30eSRafał Miłecki } 2959835a30eSRafał Miłecki 296c9703146SMichael Buesch ssb_pmu_init(cc); 29761e115a5SMichael Buesch chipco_powercontrol_init(cc); 29861e115a5SMichael Buesch ssb_chipco_set_clockmode(cc, SSB_CLKMODE_FAST); 29961e115a5SMichael Buesch calc_fast_powerup_delay(cc); 30061e115a5SMichael Buesch } 30161e115a5SMichael Buesch 3028fe2b65aSMichael Buesch void ssb_chipco_suspend(struct ssb_chipcommon *cc) 30361e115a5SMichael Buesch { 30461e115a5SMichael Buesch if (!cc->dev) 30561e115a5SMichael Buesch return; 30661e115a5SMichael Buesch ssb_chipco_set_clockmode(cc, SSB_CLKMODE_SLOW); 30761e115a5SMichael Buesch } 30861e115a5SMichael Buesch 30961e115a5SMichael Buesch void ssb_chipco_resume(struct ssb_chipcommon *cc) 31061e115a5SMichael Buesch { 31161e115a5SMichael Buesch if (!cc->dev) 31261e115a5SMichael Buesch return; 31361e115a5SMichael Buesch chipco_powercontrol_init(cc); 31461e115a5SMichael Buesch ssb_chipco_set_clockmode(cc, SSB_CLKMODE_FAST); 31561e115a5SMichael Buesch } 31661e115a5SMichael Buesch 31761e115a5SMichael Buesch /* Get the processor clock */ 31861e115a5SMichael Buesch void ssb_chipco_get_clockcpu(struct ssb_chipcommon *cc, 31961e115a5SMichael Buesch u32 *plltype, u32 *n, u32 *m) 32061e115a5SMichael Buesch { 32161e115a5SMichael Buesch *n = chipco_read32(cc, SSB_CHIPCO_CLOCK_N); 32261e115a5SMichael Buesch *plltype = (cc->capabilities & SSB_CHIPCO_CAP_PLLT); 32361e115a5SMichael Buesch switch (*plltype) { 32461e115a5SMichael Buesch case SSB_PLLTYPE_2: 32561e115a5SMichael Buesch case SSB_PLLTYPE_4: 32661e115a5SMichael Buesch case SSB_PLLTYPE_6: 32761e115a5SMichael Buesch case SSB_PLLTYPE_7: 32861e115a5SMichael Buesch *m = chipco_read32(cc, SSB_CHIPCO_CLOCK_MIPS); 32961e115a5SMichael Buesch break; 33061e115a5SMichael Buesch case SSB_PLLTYPE_3: 33161e115a5SMichael Buesch /* 5350 uses m2 to control mips */ 33261e115a5SMichael Buesch *m = chipco_read32(cc, SSB_CHIPCO_CLOCK_M2); 33361e115a5SMichael Buesch break; 33461e115a5SMichael Buesch default: 33561e115a5SMichael Buesch *m = chipco_read32(cc, SSB_CHIPCO_CLOCK_SB); 33661e115a5SMichael Buesch break; 33761e115a5SMichael Buesch } 33861e115a5SMichael Buesch } 33961e115a5SMichael Buesch 34061e115a5SMichael Buesch /* Get the bus clock */ 34161e115a5SMichael Buesch void ssb_chipco_get_clockcontrol(struct ssb_chipcommon *cc, 34261e115a5SMichael Buesch u32 *plltype, u32 *n, u32 *m) 34361e115a5SMichael Buesch { 34461e115a5SMichael Buesch *n = chipco_read32(cc, SSB_CHIPCO_CLOCK_N); 34561e115a5SMichael Buesch *plltype = (cc->capabilities & SSB_CHIPCO_CAP_PLLT); 34661e115a5SMichael Buesch switch (*plltype) { 34761e115a5SMichael Buesch case SSB_PLLTYPE_6: /* 100/200 or 120/240 only */ 34861e115a5SMichael Buesch *m = chipco_read32(cc, SSB_CHIPCO_CLOCK_MIPS); 34961e115a5SMichael Buesch break; 35061e115a5SMichael Buesch case SSB_PLLTYPE_3: /* 25Mhz, 2 dividers */ 35161e115a5SMichael Buesch if (cc->dev->bus->chip_id != 0x5365) { 35261e115a5SMichael Buesch *m = chipco_read32(cc, SSB_CHIPCO_CLOCK_M2); 35361e115a5SMichael Buesch break; 35461e115a5SMichael Buesch } 35561e115a5SMichael Buesch /* Fallthough */ 35661e115a5SMichael Buesch default: 35761e115a5SMichael Buesch *m = chipco_read32(cc, SSB_CHIPCO_CLOCK_SB); 35861e115a5SMichael Buesch } 35961e115a5SMichael Buesch } 36061e115a5SMichael Buesch 36161e115a5SMichael Buesch void ssb_chipco_timing_init(struct ssb_chipcommon *cc, 36261e115a5SMichael Buesch unsigned long ns) 36361e115a5SMichael Buesch { 36461e115a5SMichael Buesch struct ssb_device *dev = cc->dev; 36561e115a5SMichael Buesch struct ssb_bus *bus = dev->bus; 36661e115a5SMichael Buesch u32 tmp; 36761e115a5SMichael Buesch 36861e115a5SMichael Buesch /* set register for external IO to control LED. */ 36961e115a5SMichael Buesch chipco_write32(cc, SSB_CHIPCO_PROG_CFG, 0x11); 37061e115a5SMichael Buesch tmp = DIV_ROUND_UP(10, ns) << SSB_PROG_WCNT_3_SHIFT; /* Waitcount-3 = 10ns */ 37161e115a5SMichael Buesch tmp |= DIV_ROUND_UP(40, ns) << SSB_PROG_WCNT_1_SHIFT; /* Waitcount-1 = 40ns */ 37261e115a5SMichael Buesch tmp |= DIV_ROUND_UP(240, ns); /* Waitcount-0 = 240ns */ 37361e115a5SMichael Buesch chipco_write32(cc, SSB_CHIPCO_PROG_WAITCNT, tmp); /* 0x01020a0c for a 100Mhz clock */ 37461e115a5SMichael Buesch 37561e115a5SMichael Buesch /* Set timing for the flash */ 37661e115a5SMichael Buesch tmp = DIV_ROUND_UP(10, ns) << SSB_FLASH_WCNT_3_SHIFT; /* Waitcount-3 = 10nS */ 37761e115a5SMichael Buesch tmp |= DIV_ROUND_UP(10, ns) << SSB_FLASH_WCNT_1_SHIFT; /* Waitcount-1 = 10nS */ 37861e115a5SMichael Buesch tmp |= DIV_ROUND_UP(120, ns); /* Waitcount-0 = 120nS */ 37961e115a5SMichael Buesch if ((bus->chip_id == 0x5365) || 38061e115a5SMichael Buesch (dev->id.revision < 9)) 38161e115a5SMichael Buesch chipco_write32(cc, SSB_CHIPCO_FLASH_WAITCNT, tmp); 38261e115a5SMichael Buesch if ((bus->chip_id == 0x5365) || 38361e115a5SMichael Buesch (dev->id.revision < 9) || 38461e115a5SMichael Buesch ((bus->chip_id == 0x5350) && (bus->chip_rev == 0))) 38561e115a5SMichael Buesch chipco_write32(cc, SSB_CHIPCO_PCMCIA_MEMWAIT, tmp); 38661e115a5SMichael Buesch 38761e115a5SMichael Buesch if (bus->chip_id == 0x5350) { 38861e115a5SMichael Buesch /* Enable EXTIF */ 38961e115a5SMichael Buesch tmp = DIV_ROUND_UP(10, ns) << SSB_PROG_WCNT_3_SHIFT; /* Waitcount-3 = 10ns */ 39061e115a5SMichael Buesch tmp |= DIV_ROUND_UP(20, ns) << SSB_PROG_WCNT_2_SHIFT; /* Waitcount-2 = 20ns */ 39161e115a5SMichael Buesch tmp |= DIV_ROUND_UP(100, ns) << SSB_PROG_WCNT_1_SHIFT; /* Waitcount-1 = 100ns */ 39261e115a5SMichael Buesch tmp |= DIV_ROUND_UP(120, ns); /* Waitcount-0 = 120ns */ 39361e115a5SMichael Buesch chipco_write32(cc, SSB_CHIPCO_PROG_WAITCNT, tmp); /* 0x01020a0c for a 100Mhz clock */ 39461e115a5SMichael Buesch } 39561e115a5SMichael Buesch } 39661e115a5SMichael Buesch 39761e115a5SMichael Buesch /* Set chip watchdog reset timer to fire in 'ticks' backplane cycles */ 3986b9bafecSMichael Buesch void ssb_chipco_watchdog_timer_set(struct ssb_chipcommon *cc, u32 ticks) 39961e115a5SMichael Buesch { 40061e115a5SMichael Buesch /* instant NMI */ 40161e115a5SMichael Buesch chipco_write32(cc, SSB_CHIPCO_WATCHDOG, ticks); 40261e115a5SMichael Buesch } 40361e115a5SMichael Buesch 40428de57d1SAurelien Jarno void ssb_chipco_irq_mask(struct ssb_chipcommon *cc, u32 mask, u32 value) 40528de57d1SAurelien Jarno { 40628de57d1SAurelien Jarno chipco_write32_masked(cc, SSB_CHIPCO_IRQMASK, mask, value); 40728de57d1SAurelien Jarno } 40828de57d1SAurelien Jarno 40928de57d1SAurelien Jarno u32 ssb_chipco_irq_status(struct ssb_chipcommon *cc, u32 mask) 41028de57d1SAurelien Jarno { 41128de57d1SAurelien Jarno return chipco_read32(cc, SSB_CHIPCO_IRQSTAT) & mask; 41228de57d1SAurelien Jarno } 41328de57d1SAurelien Jarno 41461e115a5SMichael Buesch u32 ssb_chipco_gpio_in(struct ssb_chipcommon *cc, u32 mask) 41561e115a5SMichael Buesch { 41661e115a5SMichael Buesch return chipco_read32(cc, SSB_CHIPCO_GPIOIN) & mask; 41761e115a5SMichael Buesch } 41861e115a5SMichael Buesch 419c2bcbe65SMichael Buesch u32 ssb_chipco_gpio_out(struct ssb_chipcommon *cc, u32 mask, u32 value) 42061e115a5SMichael Buesch { 421c2bcbe65SMichael Buesch return chipco_write32_masked(cc, SSB_CHIPCO_GPIOOUT, mask, value); 42261e115a5SMichael Buesch } 42361e115a5SMichael Buesch 424c2bcbe65SMichael Buesch u32 ssb_chipco_gpio_outen(struct ssb_chipcommon *cc, u32 mask, u32 value) 42561e115a5SMichael Buesch { 426c2bcbe65SMichael Buesch return chipco_write32_masked(cc, SSB_CHIPCO_GPIOOUTEN, mask, value); 42761e115a5SMichael Buesch } 428c2bcbe65SMichael Buesch 429c2bcbe65SMichael Buesch u32 ssb_chipco_gpio_control(struct ssb_chipcommon *cc, u32 mask, u32 value) 430c2bcbe65SMichael Buesch { 431c2bcbe65SMichael Buesch return chipco_write32_masked(cc, SSB_CHIPCO_GPIOCTL, mask, value); 432c2bcbe65SMichael Buesch } 43385373ee8SLarry Finger EXPORT_SYMBOL(ssb_chipco_gpio_control); 434c2bcbe65SMichael Buesch 435c2bcbe65SMichael Buesch u32 ssb_chipco_gpio_intmask(struct ssb_chipcommon *cc, u32 mask, u32 value) 436c2bcbe65SMichael Buesch { 437c2bcbe65SMichael Buesch return chipco_write32_masked(cc, SSB_CHIPCO_GPIOIRQ, mask, value); 438c2bcbe65SMichael Buesch } 439c2bcbe65SMichael Buesch 440c2bcbe65SMichael Buesch u32 ssb_chipco_gpio_polarity(struct ssb_chipcommon *cc, u32 mask, u32 value) 441c2bcbe65SMichael Buesch { 442c2bcbe65SMichael Buesch return chipco_write32_masked(cc, SSB_CHIPCO_GPIOPOL, mask, value); 443c2bcbe65SMichael Buesch } 44461e115a5SMichael Buesch 445*da22f22eSHauke Mehrtens u32 ssb_chipco_gpio_pullup(struct ssb_chipcommon *cc, u32 mask, u32 value) 446*da22f22eSHauke Mehrtens { 447*da22f22eSHauke Mehrtens if (cc->dev->id.revision < 20) 448*da22f22eSHauke Mehrtens return 0xffffffff; 449*da22f22eSHauke Mehrtens 450*da22f22eSHauke Mehrtens return chipco_write32_masked(cc, SSB_CHIPCO_GPIOPULLUP, mask, value); 451*da22f22eSHauke Mehrtens } 452*da22f22eSHauke Mehrtens 453*da22f22eSHauke Mehrtens u32 ssb_chipco_gpio_pulldown(struct ssb_chipcommon *cc, u32 mask, u32 value) 454*da22f22eSHauke Mehrtens { 455*da22f22eSHauke Mehrtens if (cc->dev->id.revision < 20) 456*da22f22eSHauke Mehrtens return 0xffffffff; 457*da22f22eSHauke Mehrtens 458*da22f22eSHauke Mehrtens return chipco_write32_masked(cc, SSB_CHIPCO_GPIOPULLDOWN, mask, value); 459*da22f22eSHauke Mehrtens } 460*da22f22eSHauke Mehrtens 46161e115a5SMichael Buesch #ifdef CONFIG_SSB_SERIAL 46261e115a5SMichael Buesch int ssb_chipco_serial_init(struct ssb_chipcommon *cc, 46361e115a5SMichael Buesch struct ssb_serial_port *ports) 46461e115a5SMichael Buesch { 46561e115a5SMichael Buesch struct ssb_bus *bus = cc->dev->bus; 46661e115a5SMichael Buesch int nr_ports = 0; 46761e115a5SMichael Buesch u32 plltype; 46861e115a5SMichael Buesch unsigned int irq; 46961e115a5SMichael Buesch u32 baud_base, div; 47061e115a5SMichael Buesch u32 i, n; 47158ff70d4SMichael Buesch unsigned int ccrev = cc->dev->id.revision; 47261e115a5SMichael Buesch 47361e115a5SMichael Buesch plltype = (cc->capabilities & SSB_CHIPCO_CAP_PLLT); 47461e115a5SMichael Buesch irq = ssb_mips_irq(cc->dev); 47561e115a5SMichael Buesch 47661e115a5SMichael Buesch if (plltype == SSB_PLLTYPE_1) { 47761e115a5SMichael Buesch /* PLL clock */ 47861e115a5SMichael Buesch baud_base = ssb_calc_clock_rate(plltype, 47961e115a5SMichael Buesch chipco_read32(cc, SSB_CHIPCO_CLOCK_N), 48061e115a5SMichael Buesch chipco_read32(cc, SSB_CHIPCO_CLOCK_M2)); 48161e115a5SMichael Buesch div = 1; 48261e115a5SMichael Buesch } else { 48358ff70d4SMichael Buesch if (ccrev == 20) { 48458ff70d4SMichael Buesch /* BCM5354 uses constant 25MHz clock */ 48558ff70d4SMichael Buesch baud_base = 25000000; 48658ff70d4SMichael Buesch div = 48; 48761e115a5SMichael Buesch /* Set the override bit so we don't divide it */ 48861e115a5SMichael Buesch chipco_write32(cc, SSB_CHIPCO_CORECTL, 48958ff70d4SMichael Buesch chipco_read32(cc, SSB_CHIPCO_CORECTL) 49058ff70d4SMichael Buesch | SSB_CHIPCO_CORECTL_UARTCLK0); 49158ff70d4SMichael Buesch } else if ((ccrev >= 11) && (ccrev != 15)) { 49258ff70d4SMichael Buesch /* Fixed ALP clock */ 49358ff70d4SMichael Buesch baud_base = 20000000; 49458ff70d4SMichael Buesch if (cc->capabilities & SSB_CHIPCO_CAP_PMU) { 49558ff70d4SMichael Buesch /* FIXME: baud_base is different for devices with a PMU */ 49658ff70d4SMichael Buesch SSB_WARN_ON(1); 49758ff70d4SMichael Buesch } 49858ff70d4SMichael Buesch div = 1; 49958ff70d4SMichael Buesch if (ccrev >= 21) { 50058ff70d4SMichael Buesch /* Turn off UART clock before switching clocksource. */ 50158ff70d4SMichael Buesch chipco_write32(cc, SSB_CHIPCO_CORECTL, 50258ff70d4SMichael Buesch chipco_read32(cc, SSB_CHIPCO_CORECTL) 50358ff70d4SMichael Buesch & ~SSB_CHIPCO_CORECTL_UARTCLKEN); 50458ff70d4SMichael Buesch } 50558ff70d4SMichael Buesch /* Set the override bit so we don't divide it */ 50658ff70d4SMichael Buesch chipco_write32(cc, SSB_CHIPCO_CORECTL, 50758ff70d4SMichael Buesch chipco_read32(cc, SSB_CHIPCO_CORECTL) 50858ff70d4SMichael Buesch | SSB_CHIPCO_CORECTL_UARTCLK0); 50958ff70d4SMichael Buesch if (ccrev >= 21) { 51058ff70d4SMichael Buesch /* Re-enable the UART clock. */ 51158ff70d4SMichael Buesch chipco_write32(cc, SSB_CHIPCO_CORECTL, 51258ff70d4SMichael Buesch chipco_read32(cc, SSB_CHIPCO_CORECTL) 51358ff70d4SMichael Buesch | SSB_CHIPCO_CORECTL_UARTCLKEN); 51458ff70d4SMichael Buesch } 51558ff70d4SMichael Buesch } else if (ccrev >= 3) { 51661e115a5SMichael Buesch /* Internal backplane clock */ 51761e115a5SMichael Buesch baud_base = ssb_clockspeed(bus); 51861e115a5SMichael Buesch div = chipco_read32(cc, SSB_CHIPCO_CLKDIV) 51961e115a5SMichael Buesch & SSB_CHIPCO_CLKDIV_UART; 52061e115a5SMichael Buesch } else { 52161e115a5SMichael Buesch /* Fixed internal backplane clock */ 52261e115a5SMichael Buesch baud_base = 88000000; 52361e115a5SMichael Buesch div = 48; 52461e115a5SMichael Buesch } 52561e115a5SMichael Buesch 52661e115a5SMichael Buesch /* Clock source depends on strapping if UartClkOverride is unset */ 52758ff70d4SMichael Buesch if ((ccrev > 0) && 52861e115a5SMichael Buesch !(chipco_read32(cc, SSB_CHIPCO_CORECTL) & SSB_CHIPCO_CORECTL_UARTCLK0)) { 52961e115a5SMichael Buesch if ((cc->capabilities & SSB_CHIPCO_CAP_UARTCLK) == 53061e115a5SMichael Buesch SSB_CHIPCO_CAP_UARTCLK_INT) { 53161e115a5SMichael Buesch /* Internal divided backplane clock */ 53261e115a5SMichael Buesch baud_base /= div; 53361e115a5SMichael Buesch } else { 53461e115a5SMichael Buesch /* Assume external clock of 1.8432 MHz */ 53561e115a5SMichael Buesch baud_base = 1843200; 53661e115a5SMichael Buesch } 53761e115a5SMichael Buesch } 53861e115a5SMichael Buesch } 53961e115a5SMichael Buesch 54061e115a5SMichael Buesch /* Determine the registers of the UARTs */ 54161e115a5SMichael Buesch n = (cc->capabilities & SSB_CHIPCO_CAP_NRUART); 54261e115a5SMichael Buesch for (i = 0; i < n; i++) { 54361e115a5SMichael Buesch void __iomem *cc_mmio; 54461e115a5SMichael Buesch void __iomem *uart_regs; 54561e115a5SMichael Buesch 54661e115a5SMichael Buesch cc_mmio = cc->dev->bus->mmio + (cc->dev->core_index * SSB_CORE_SIZE); 54761e115a5SMichael Buesch uart_regs = cc_mmio + SSB_CHIPCO_UART0_DATA; 54861e115a5SMichael Buesch /* Offset changed at after rev 0 */ 54958ff70d4SMichael Buesch if (ccrev == 0) 55061e115a5SMichael Buesch uart_regs += (i * 8); 55161e115a5SMichael Buesch else 55261e115a5SMichael Buesch uart_regs += (i * 256); 55361e115a5SMichael Buesch 55461e115a5SMichael Buesch nr_ports++; 55561e115a5SMichael Buesch ports[i].regs = uart_regs; 55661e115a5SMichael Buesch ports[i].irq = irq; 55761e115a5SMichael Buesch ports[i].baud_base = baud_base; 55861e115a5SMichael Buesch ports[i].reg_shift = 0; 55961e115a5SMichael Buesch } 56061e115a5SMichael Buesch 56161e115a5SMichael Buesch return nr_ports; 56261e115a5SMichael Buesch } 56361e115a5SMichael Buesch #endif /* CONFIG_SSB_SERIAL */ 564