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 2961e115a5SMichael Buesch static inline u32 chipco_read32(struct ssb_chipcommon *cc, 3061e115a5SMichael Buesch u16 offset) 3161e115a5SMichael Buesch { 3261e115a5SMichael Buesch return ssb_read32(cc->dev, offset); 3361e115a5SMichael Buesch } 3461e115a5SMichael Buesch 3561e115a5SMichael Buesch static inline void chipco_write32(struct ssb_chipcommon *cc, 3661e115a5SMichael Buesch u16 offset, 3761e115a5SMichael Buesch u32 value) 3861e115a5SMichael Buesch { 3961e115a5SMichael Buesch ssb_write32(cc->dev, offset, value); 4061e115a5SMichael Buesch } 4161e115a5SMichael Buesch 42c2bcbe65SMichael Buesch static inline u32 chipco_write32_masked(struct ssb_chipcommon *cc, u16 offset, 4361e115a5SMichael Buesch u32 mask, u32 value) 4461e115a5SMichael Buesch { 4561e115a5SMichael Buesch value &= mask; 4661e115a5SMichael Buesch value |= chipco_read32(cc, offset) & ~mask; 4761e115a5SMichael Buesch chipco_write32(cc, offset, value); 48c2bcbe65SMichael Buesch 49c2bcbe65SMichael Buesch return value; 5061e115a5SMichael Buesch } 5161e115a5SMichael Buesch 5261e115a5SMichael Buesch void ssb_chipco_set_clockmode(struct ssb_chipcommon *cc, 5361e115a5SMichael Buesch enum ssb_clkmode mode) 5461e115a5SMichael Buesch { 5561e115a5SMichael Buesch struct ssb_device *ccdev = cc->dev; 5661e115a5SMichael Buesch struct ssb_bus *bus; 5761e115a5SMichael Buesch u32 tmp; 5861e115a5SMichael Buesch 5961e115a5SMichael Buesch if (!ccdev) 6061e115a5SMichael Buesch return; 6161e115a5SMichael Buesch bus = ccdev->bus; 6261e115a5SMichael Buesch /* chipcommon cores prior to rev6 don't support dynamic clock control */ 6361e115a5SMichael Buesch if (ccdev->id.revision < 6) 6461e115a5SMichael Buesch return; 6561e115a5SMichael Buesch /* chipcommon cores rev10 are a whole new ball game */ 6661e115a5SMichael Buesch if (ccdev->id.revision >= 10) 6761e115a5SMichael Buesch return; 6861e115a5SMichael Buesch if (!(cc->capabilities & SSB_CHIPCO_CAP_PCTL)) 6961e115a5SMichael Buesch return; 7061e115a5SMichael Buesch 7161e115a5SMichael Buesch switch (mode) { 7261e115a5SMichael Buesch case SSB_CLKMODE_SLOW: 7361e115a5SMichael Buesch tmp = chipco_read32(cc, SSB_CHIPCO_SLOWCLKCTL); 7461e115a5SMichael Buesch tmp |= SSB_CHIPCO_SLOWCLKCTL_FSLOW; 7561e115a5SMichael Buesch chipco_write32(cc, SSB_CHIPCO_SLOWCLKCTL, tmp); 7661e115a5SMichael Buesch break; 7761e115a5SMichael Buesch case SSB_CLKMODE_FAST: 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); 8361e115a5SMichael Buesch break; 8461e115a5SMichael Buesch case SSB_CLKMODE_DYNAMIC: 8561e115a5SMichael Buesch tmp = chipco_read32(cc, SSB_CHIPCO_SLOWCLKCTL); 8661e115a5SMichael Buesch tmp &= ~SSB_CHIPCO_SLOWCLKCTL_FSLOW; 8761e115a5SMichael Buesch tmp &= ~SSB_CHIPCO_SLOWCLKCTL_IPLL; 8861e115a5SMichael Buesch tmp &= ~SSB_CHIPCO_SLOWCLKCTL_ENXTAL; 8961e115a5SMichael Buesch if ((tmp & SSB_CHIPCO_SLOWCLKCTL_SRC) != SSB_CHIPCO_SLOWCLKCTL_SRC_XTAL) 9061e115a5SMichael Buesch tmp |= SSB_CHIPCO_SLOWCLKCTL_ENXTAL; 9161e115a5SMichael Buesch chipco_write32(cc, SSB_CHIPCO_SLOWCLKCTL, tmp); 9261e115a5SMichael Buesch 9361e115a5SMichael Buesch /* for dynamic control, we have to release our xtal_pu "force on" */ 9461e115a5SMichael Buesch if (tmp & SSB_CHIPCO_SLOWCLKCTL_ENXTAL) 9561e115a5SMichael Buesch ssb_pci_xtal(bus, SSB_GPIO_XTAL, 0); 9661e115a5SMichael Buesch break; 9761e115a5SMichael Buesch default: 9861e115a5SMichael Buesch SSB_WARN_ON(1); 9961e115a5SMichael Buesch } 10061e115a5SMichael Buesch } 10161e115a5SMichael Buesch 10261e115a5SMichael Buesch /* Get the Slow Clock Source */ 10361e115a5SMichael Buesch static enum ssb_clksrc chipco_pctl_get_slowclksrc(struct ssb_chipcommon *cc) 10461e115a5SMichael Buesch { 10561e115a5SMichael Buesch struct ssb_bus *bus = cc->dev->bus; 10661e115a5SMichael Buesch u32 uninitialized_var(tmp); 10761e115a5SMichael Buesch 10861e115a5SMichael Buesch if (cc->dev->id.revision < 6) { 10961e115a5SMichael Buesch if (bus->bustype == SSB_BUSTYPE_SSB || 11061e115a5SMichael Buesch bus->bustype == SSB_BUSTYPE_PCMCIA) 11161e115a5SMichael Buesch return SSB_CHIPCO_CLKSRC_XTALOS; 11261e115a5SMichael Buesch if (bus->bustype == SSB_BUSTYPE_PCI) { 11361e115a5SMichael Buesch pci_read_config_dword(bus->host_pci, SSB_GPIO_OUT, &tmp); 11461e115a5SMichael Buesch if (tmp & 0x10) 11561e115a5SMichael Buesch return SSB_CHIPCO_CLKSRC_PCI; 11661e115a5SMichael Buesch return SSB_CHIPCO_CLKSRC_XTALOS; 11761e115a5SMichael Buesch } 11861e115a5SMichael Buesch } 11961e115a5SMichael Buesch if (cc->dev->id.revision < 10) { 12061e115a5SMichael Buesch tmp = chipco_read32(cc, SSB_CHIPCO_SLOWCLKCTL); 12161e115a5SMichael Buesch tmp &= 0x7; 12261e115a5SMichael Buesch if (tmp == 0) 12361e115a5SMichael Buesch return SSB_CHIPCO_CLKSRC_LOPWROS; 12461e115a5SMichael Buesch if (tmp == 1) 12561e115a5SMichael Buesch return SSB_CHIPCO_CLKSRC_XTALOS; 12661e115a5SMichael Buesch if (tmp == 2) 12761e115a5SMichael Buesch return SSB_CHIPCO_CLKSRC_PCI; 12861e115a5SMichael Buesch } 12961e115a5SMichael Buesch 13061e115a5SMichael Buesch return SSB_CHIPCO_CLKSRC_XTALOS; 13161e115a5SMichael Buesch } 13261e115a5SMichael Buesch 13361e115a5SMichael Buesch /* Get maximum or minimum (depending on get_max flag) slowclock frequency. */ 13461e115a5SMichael Buesch static int chipco_pctl_clockfreqlimit(struct ssb_chipcommon *cc, int get_max) 13561e115a5SMichael Buesch { 13661e115a5SMichael Buesch int uninitialized_var(limit); 13761e115a5SMichael Buesch enum ssb_clksrc clocksrc; 13861e115a5SMichael Buesch int divisor = 1; 13961e115a5SMichael Buesch u32 tmp; 14061e115a5SMichael Buesch 14161e115a5SMichael Buesch clocksrc = chipco_pctl_get_slowclksrc(cc); 14261e115a5SMichael Buesch if (cc->dev->id.revision < 6) { 14361e115a5SMichael Buesch switch (clocksrc) { 14461e115a5SMichael Buesch case SSB_CHIPCO_CLKSRC_PCI: 14561e115a5SMichael Buesch divisor = 64; 14661e115a5SMichael Buesch break; 14761e115a5SMichael Buesch case SSB_CHIPCO_CLKSRC_XTALOS: 14861e115a5SMichael Buesch divisor = 32; 14961e115a5SMichael Buesch break; 15061e115a5SMichael Buesch default: 15161e115a5SMichael Buesch SSB_WARN_ON(1); 15261e115a5SMichael Buesch } 15361e115a5SMichael Buesch } else if (cc->dev->id.revision < 10) { 15461e115a5SMichael Buesch switch (clocksrc) { 15561e115a5SMichael Buesch case SSB_CHIPCO_CLKSRC_LOPWROS: 15661e115a5SMichael Buesch break; 15761e115a5SMichael Buesch case SSB_CHIPCO_CLKSRC_XTALOS: 15861e115a5SMichael Buesch case SSB_CHIPCO_CLKSRC_PCI: 15961e115a5SMichael Buesch tmp = chipco_read32(cc, SSB_CHIPCO_SLOWCLKCTL); 16061e115a5SMichael Buesch divisor = (tmp >> 16) + 1; 16161e115a5SMichael Buesch divisor *= 4; 16261e115a5SMichael Buesch break; 16361e115a5SMichael Buesch } 16461e115a5SMichael Buesch } else { 16561e115a5SMichael Buesch tmp = chipco_read32(cc, SSB_CHIPCO_SYSCLKCTL); 16661e115a5SMichael Buesch divisor = (tmp >> 16) + 1; 16761e115a5SMichael Buesch divisor *= 4; 16861e115a5SMichael Buesch } 16961e115a5SMichael Buesch 17061e115a5SMichael Buesch switch (clocksrc) { 17161e115a5SMichael Buesch case SSB_CHIPCO_CLKSRC_LOPWROS: 17261e115a5SMichael Buesch if (get_max) 17361e115a5SMichael Buesch limit = 43000; 17461e115a5SMichael Buesch else 17561e115a5SMichael Buesch limit = 25000; 17661e115a5SMichael Buesch break; 17761e115a5SMichael Buesch case SSB_CHIPCO_CLKSRC_XTALOS: 17861e115a5SMichael Buesch if (get_max) 17961e115a5SMichael Buesch limit = 20200000; 18061e115a5SMichael Buesch else 18161e115a5SMichael Buesch limit = 19800000; 18261e115a5SMichael Buesch break; 18361e115a5SMichael Buesch case SSB_CHIPCO_CLKSRC_PCI: 18461e115a5SMichael Buesch if (get_max) 18561e115a5SMichael Buesch limit = 34000000; 18661e115a5SMichael Buesch else 18761e115a5SMichael Buesch limit = 25000000; 18861e115a5SMichael Buesch break; 18961e115a5SMichael Buesch } 19061e115a5SMichael Buesch limit /= divisor; 19161e115a5SMichael Buesch 19261e115a5SMichael Buesch return limit; 19361e115a5SMichael Buesch } 19461e115a5SMichael Buesch 19561e115a5SMichael Buesch static void chipco_powercontrol_init(struct ssb_chipcommon *cc) 19661e115a5SMichael Buesch { 19761e115a5SMichael Buesch struct ssb_bus *bus = cc->dev->bus; 19861e115a5SMichael Buesch 19961e115a5SMichael Buesch if (bus->chip_id == 0x4321) { 20061e115a5SMichael Buesch if (bus->chip_rev == 0) 20161e115a5SMichael Buesch chipco_write32(cc, SSB_CHIPCO_CHIPCTL, 0x3A4); 20261e115a5SMichael Buesch else if (bus->chip_rev == 1) 20361e115a5SMichael Buesch chipco_write32(cc, SSB_CHIPCO_CHIPCTL, 0xA4); 20461e115a5SMichael Buesch } 20561e115a5SMichael Buesch 20661e115a5SMichael Buesch if (!(cc->capabilities & SSB_CHIPCO_CAP_PCTL)) 20761e115a5SMichael Buesch return; 20861e115a5SMichael Buesch 20961e115a5SMichael Buesch if (cc->dev->id.revision >= 10) { 21061e115a5SMichael Buesch /* Set Idle Power clock rate to 1Mhz */ 21161e115a5SMichael Buesch chipco_write32(cc, SSB_CHIPCO_SYSCLKCTL, 21261e115a5SMichael Buesch (chipco_read32(cc, SSB_CHIPCO_SYSCLKCTL) & 21361e115a5SMichael Buesch 0x0000FFFF) | 0x00040000); 21461e115a5SMichael Buesch } else { 21561e115a5SMichael Buesch int maxfreq; 21661e115a5SMichael Buesch 21761e115a5SMichael Buesch maxfreq = chipco_pctl_clockfreqlimit(cc, 1); 21861e115a5SMichael Buesch chipco_write32(cc, SSB_CHIPCO_PLLONDELAY, 21961e115a5SMichael Buesch (maxfreq * 150 + 999999) / 1000000); 22061e115a5SMichael Buesch chipco_write32(cc, SSB_CHIPCO_FREFSELDELAY, 22161e115a5SMichael Buesch (maxfreq * 15 + 999999) / 1000000); 22261e115a5SMichael Buesch } 22361e115a5SMichael Buesch } 22461e115a5SMichael Buesch 22561e115a5SMichael Buesch static void calc_fast_powerup_delay(struct ssb_chipcommon *cc) 22661e115a5SMichael Buesch { 22761e115a5SMichael Buesch struct ssb_bus *bus = cc->dev->bus; 22861e115a5SMichael Buesch int minfreq; 22961e115a5SMichael Buesch unsigned int tmp; 23061e115a5SMichael Buesch u32 pll_on_delay; 23161e115a5SMichael Buesch 23261e115a5SMichael Buesch if (bus->bustype != SSB_BUSTYPE_PCI) 23361e115a5SMichael Buesch return; 23461e115a5SMichael Buesch if (!(cc->capabilities & SSB_CHIPCO_CAP_PCTL)) 23561e115a5SMichael Buesch return; 23661e115a5SMichael Buesch 23761e115a5SMichael Buesch minfreq = chipco_pctl_clockfreqlimit(cc, 0); 23861e115a5SMichael Buesch pll_on_delay = chipco_read32(cc, SSB_CHIPCO_PLLONDELAY); 23961e115a5SMichael Buesch tmp = (((pll_on_delay + 2) * 1000000) + (minfreq - 1)) / minfreq; 24061e115a5SMichael Buesch SSB_WARN_ON(tmp & ~0xFFFF); 24161e115a5SMichael Buesch 24261e115a5SMichael Buesch cc->fast_pwrup_delay = tmp; 24361e115a5SMichael Buesch } 24461e115a5SMichael Buesch 24561e115a5SMichael Buesch void ssb_chipcommon_init(struct ssb_chipcommon *cc) 24661e115a5SMichael Buesch { 24761e115a5SMichael Buesch if (!cc->dev) 24861e115a5SMichael Buesch return; /* We don't have a ChipCommon */ 24961e115a5SMichael Buesch chipco_powercontrol_init(cc); 25061e115a5SMichael Buesch ssb_chipco_set_clockmode(cc, SSB_CLKMODE_FAST); 25161e115a5SMichael Buesch calc_fast_powerup_delay(cc); 25261e115a5SMichael Buesch } 25361e115a5SMichael Buesch 25461e115a5SMichael Buesch void ssb_chipco_suspend(struct ssb_chipcommon *cc, pm_message_t state) 25561e115a5SMichael Buesch { 25661e115a5SMichael Buesch if (!cc->dev) 25761e115a5SMichael Buesch return; 25861e115a5SMichael Buesch ssb_chipco_set_clockmode(cc, SSB_CLKMODE_SLOW); 25961e115a5SMichael Buesch } 26061e115a5SMichael Buesch 26161e115a5SMichael Buesch void ssb_chipco_resume(struct ssb_chipcommon *cc) 26261e115a5SMichael Buesch { 26361e115a5SMichael Buesch if (!cc->dev) 26461e115a5SMichael Buesch return; 26561e115a5SMichael Buesch chipco_powercontrol_init(cc); 26661e115a5SMichael Buesch ssb_chipco_set_clockmode(cc, SSB_CLKMODE_FAST); 26761e115a5SMichael Buesch } 26861e115a5SMichael Buesch 26961e115a5SMichael Buesch /* Get the processor clock */ 27061e115a5SMichael Buesch void ssb_chipco_get_clockcpu(struct ssb_chipcommon *cc, 27161e115a5SMichael Buesch u32 *plltype, u32 *n, u32 *m) 27261e115a5SMichael Buesch { 27361e115a5SMichael Buesch *n = chipco_read32(cc, SSB_CHIPCO_CLOCK_N); 27461e115a5SMichael Buesch *plltype = (cc->capabilities & SSB_CHIPCO_CAP_PLLT); 27561e115a5SMichael Buesch switch (*plltype) { 27661e115a5SMichael Buesch case SSB_PLLTYPE_2: 27761e115a5SMichael Buesch case SSB_PLLTYPE_4: 27861e115a5SMichael Buesch case SSB_PLLTYPE_6: 27961e115a5SMichael Buesch case SSB_PLLTYPE_7: 28061e115a5SMichael Buesch *m = chipco_read32(cc, SSB_CHIPCO_CLOCK_MIPS); 28161e115a5SMichael Buesch break; 28261e115a5SMichael Buesch case SSB_PLLTYPE_3: 28361e115a5SMichael Buesch /* 5350 uses m2 to control mips */ 28461e115a5SMichael Buesch *m = chipco_read32(cc, SSB_CHIPCO_CLOCK_M2); 28561e115a5SMichael Buesch break; 28661e115a5SMichael Buesch default: 28761e115a5SMichael Buesch *m = chipco_read32(cc, SSB_CHIPCO_CLOCK_SB); 28861e115a5SMichael Buesch break; 28961e115a5SMichael Buesch } 29061e115a5SMichael Buesch } 29161e115a5SMichael Buesch 29261e115a5SMichael Buesch /* Get the bus clock */ 29361e115a5SMichael Buesch void ssb_chipco_get_clockcontrol(struct ssb_chipcommon *cc, 29461e115a5SMichael Buesch u32 *plltype, u32 *n, u32 *m) 29561e115a5SMichael Buesch { 29661e115a5SMichael Buesch *n = chipco_read32(cc, SSB_CHIPCO_CLOCK_N); 29761e115a5SMichael Buesch *plltype = (cc->capabilities & SSB_CHIPCO_CAP_PLLT); 29861e115a5SMichael Buesch switch (*plltype) { 29961e115a5SMichael Buesch case SSB_PLLTYPE_6: /* 100/200 or 120/240 only */ 30061e115a5SMichael Buesch *m = chipco_read32(cc, SSB_CHIPCO_CLOCK_MIPS); 30161e115a5SMichael Buesch break; 30261e115a5SMichael Buesch case SSB_PLLTYPE_3: /* 25Mhz, 2 dividers */ 30361e115a5SMichael Buesch if (cc->dev->bus->chip_id != 0x5365) { 30461e115a5SMichael Buesch *m = chipco_read32(cc, SSB_CHIPCO_CLOCK_M2); 30561e115a5SMichael Buesch break; 30661e115a5SMichael Buesch } 30761e115a5SMichael Buesch /* Fallthough */ 30861e115a5SMichael Buesch default: 30961e115a5SMichael Buesch *m = chipco_read32(cc, SSB_CHIPCO_CLOCK_SB); 31061e115a5SMichael Buesch } 31161e115a5SMichael Buesch } 31261e115a5SMichael Buesch 31361e115a5SMichael Buesch void ssb_chipco_timing_init(struct ssb_chipcommon *cc, 31461e115a5SMichael Buesch unsigned long ns) 31561e115a5SMichael Buesch { 31661e115a5SMichael Buesch struct ssb_device *dev = cc->dev; 31761e115a5SMichael Buesch struct ssb_bus *bus = dev->bus; 31861e115a5SMichael Buesch u32 tmp; 31961e115a5SMichael Buesch 32061e115a5SMichael Buesch /* set register for external IO to control LED. */ 32161e115a5SMichael Buesch chipco_write32(cc, SSB_CHIPCO_PROG_CFG, 0x11); 32261e115a5SMichael Buesch tmp = DIV_ROUND_UP(10, ns) << SSB_PROG_WCNT_3_SHIFT; /* Waitcount-3 = 10ns */ 32361e115a5SMichael Buesch tmp |= DIV_ROUND_UP(40, ns) << SSB_PROG_WCNT_1_SHIFT; /* Waitcount-1 = 40ns */ 32461e115a5SMichael Buesch tmp |= DIV_ROUND_UP(240, ns); /* Waitcount-0 = 240ns */ 32561e115a5SMichael Buesch chipco_write32(cc, SSB_CHIPCO_PROG_WAITCNT, tmp); /* 0x01020a0c for a 100Mhz clock */ 32661e115a5SMichael Buesch 32761e115a5SMichael Buesch /* Set timing for the flash */ 32861e115a5SMichael Buesch tmp = DIV_ROUND_UP(10, ns) << SSB_FLASH_WCNT_3_SHIFT; /* Waitcount-3 = 10nS */ 32961e115a5SMichael Buesch tmp |= DIV_ROUND_UP(10, ns) << SSB_FLASH_WCNT_1_SHIFT; /* Waitcount-1 = 10nS */ 33061e115a5SMichael Buesch tmp |= DIV_ROUND_UP(120, ns); /* Waitcount-0 = 120nS */ 33161e115a5SMichael Buesch if ((bus->chip_id == 0x5365) || 33261e115a5SMichael Buesch (dev->id.revision < 9)) 33361e115a5SMichael Buesch chipco_write32(cc, SSB_CHIPCO_FLASH_WAITCNT, tmp); 33461e115a5SMichael Buesch if ((bus->chip_id == 0x5365) || 33561e115a5SMichael Buesch (dev->id.revision < 9) || 33661e115a5SMichael Buesch ((bus->chip_id == 0x5350) && (bus->chip_rev == 0))) 33761e115a5SMichael Buesch chipco_write32(cc, SSB_CHIPCO_PCMCIA_MEMWAIT, tmp); 33861e115a5SMichael Buesch 33961e115a5SMichael Buesch if (bus->chip_id == 0x5350) { 34061e115a5SMichael Buesch /* Enable EXTIF */ 34161e115a5SMichael Buesch tmp = DIV_ROUND_UP(10, ns) << SSB_PROG_WCNT_3_SHIFT; /* Waitcount-3 = 10ns */ 34261e115a5SMichael Buesch tmp |= DIV_ROUND_UP(20, ns) << SSB_PROG_WCNT_2_SHIFT; /* Waitcount-2 = 20ns */ 34361e115a5SMichael Buesch tmp |= DIV_ROUND_UP(100, ns) << SSB_PROG_WCNT_1_SHIFT; /* Waitcount-1 = 100ns */ 34461e115a5SMichael Buesch tmp |= DIV_ROUND_UP(120, ns); /* Waitcount-0 = 120ns */ 34561e115a5SMichael Buesch chipco_write32(cc, SSB_CHIPCO_PROG_WAITCNT, tmp); /* 0x01020a0c for a 100Mhz clock */ 34661e115a5SMichael Buesch } 34761e115a5SMichael Buesch } 34861e115a5SMichael Buesch 34961e115a5SMichael Buesch /* Set chip watchdog reset timer to fire in 'ticks' backplane cycles */ 3506b9bafecSMichael Buesch void ssb_chipco_watchdog_timer_set(struct ssb_chipcommon *cc, u32 ticks) 35161e115a5SMichael Buesch { 35261e115a5SMichael Buesch /* instant NMI */ 35361e115a5SMichael Buesch chipco_write32(cc, SSB_CHIPCO_WATCHDOG, ticks); 35461e115a5SMichael Buesch } 35561e115a5SMichael Buesch 356*28de57d1SAurelien Jarno void ssb_chipco_irq_mask(struct ssb_chipcommon *cc, u32 mask, u32 value) 357*28de57d1SAurelien Jarno { 358*28de57d1SAurelien Jarno chipco_write32_masked(cc, SSB_CHIPCO_IRQMASK, mask, value); 359*28de57d1SAurelien Jarno } 360*28de57d1SAurelien Jarno 361*28de57d1SAurelien Jarno u32 ssb_chipco_irq_status(struct ssb_chipcommon *cc, u32 mask) 362*28de57d1SAurelien Jarno { 363*28de57d1SAurelien Jarno return chipco_read32(cc, SSB_CHIPCO_IRQSTAT) & mask; 364*28de57d1SAurelien Jarno } 365*28de57d1SAurelien Jarno 36661e115a5SMichael Buesch u32 ssb_chipco_gpio_in(struct ssb_chipcommon *cc, u32 mask) 36761e115a5SMichael Buesch { 36861e115a5SMichael Buesch return chipco_read32(cc, SSB_CHIPCO_GPIOIN) & mask; 36961e115a5SMichael Buesch } 37061e115a5SMichael Buesch 371c2bcbe65SMichael Buesch u32 ssb_chipco_gpio_out(struct ssb_chipcommon *cc, u32 mask, u32 value) 37261e115a5SMichael Buesch { 373c2bcbe65SMichael Buesch return chipco_write32_masked(cc, SSB_CHIPCO_GPIOOUT, mask, value); 37461e115a5SMichael Buesch } 37561e115a5SMichael Buesch 376c2bcbe65SMichael Buesch u32 ssb_chipco_gpio_outen(struct ssb_chipcommon *cc, u32 mask, u32 value) 37761e115a5SMichael Buesch { 378c2bcbe65SMichael Buesch return chipco_write32_masked(cc, SSB_CHIPCO_GPIOOUTEN, mask, value); 37961e115a5SMichael Buesch } 380c2bcbe65SMichael Buesch 381c2bcbe65SMichael Buesch u32 ssb_chipco_gpio_control(struct ssb_chipcommon *cc, u32 mask, u32 value) 382c2bcbe65SMichael Buesch { 383c2bcbe65SMichael Buesch return chipco_write32_masked(cc, SSB_CHIPCO_GPIOCTL, mask, value); 384c2bcbe65SMichael Buesch } 385c2bcbe65SMichael Buesch 386c2bcbe65SMichael Buesch u32 ssb_chipco_gpio_intmask(struct ssb_chipcommon *cc, u32 mask, u32 value) 387c2bcbe65SMichael Buesch { 388c2bcbe65SMichael Buesch return chipco_write32_masked(cc, SSB_CHIPCO_GPIOIRQ, mask, value); 389c2bcbe65SMichael Buesch } 390c2bcbe65SMichael Buesch 391c2bcbe65SMichael Buesch u32 ssb_chipco_gpio_polarity(struct ssb_chipcommon *cc, u32 mask, u32 value) 392c2bcbe65SMichael Buesch { 393c2bcbe65SMichael Buesch return chipco_write32_masked(cc, SSB_CHIPCO_GPIOPOL, mask, value); 394c2bcbe65SMichael Buesch } 39561e115a5SMichael Buesch 39661e115a5SMichael Buesch #ifdef CONFIG_SSB_SERIAL 39761e115a5SMichael Buesch int ssb_chipco_serial_init(struct ssb_chipcommon *cc, 39861e115a5SMichael Buesch struct ssb_serial_port *ports) 39961e115a5SMichael Buesch { 40061e115a5SMichael Buesch struct ssb_bus *bus = cc->dev->bus; 40161e115a5SMichael Buesch int nr_ports = 0; 40261e115a5SMichael Buesch u32 plltype; 40361e115a5SMichael Buesch unsigned int irq; 40461e115a5SMichael Buesch u32 baud_base, div; 40561e115a5SMichael Buesch u32 i, n; 40658ff70d4SMichael Buesch unsigned int ccrev = cc->dev->id.revision; 40761e115a5SMichael Buesch 40861e115a5SMichael Buesch plltype = (cc->capabilities & SSB_CHIPCO_CAP_PLLT); 40961e115a5SMichael Buesch irq = ssb_mips_irq(cc->dev); 41061e115a5SMichael Buesch 41161e115a5SMichael Buesch if (plltype == SSB_PLLTYPE_1) { 41261e115a5SMichael Buesch /* PLL clock */ 41361e115a5SMichael Buesch baud_base = ssb_calc_clock_rate(plltype, 41461e115a5SMichael Buesch chipco_read32(cc, SSB_CHIPCO_CLOCK_N), 41561e115a5SMichael Buesch chipco_read32(cc, SSB_CHIPCO_CLOCK_M2)); 41661e115a5SMichael Buesch div = 1; 41761e115a5SMichael Buesch } else { 41858ff70d4SMichael Buesch if (ccrev == 20) { 41958ff70d4SMichael Buesch /* BCM5354 uses constant 25MHz clock */ 42058ff70d4SMichael Buesch baud_base = 25000000; 42158ff70d4SMichael Buesch div = 48; 42261e115a5SMichael Buesch /* Set the override bit so we don't divide it */ 42361e115a5SMichael Buesch chipco_write32(cc, SSB_CHIPCO_CORECTL, 42458ff70d4SMichael Buesch chipco_read32(cc, SSB_CHIPCO_CORECTL) 42558ff70d4SMichael Buesch | SSB_CHIPCO_CORECTL_UARTCLK0); 42658ff70d4SMichael Buesch } else if ((ccrev >= 11) && (ccrev != 15)) { 42758ff70d4SMichael Buesch /* Fixed ALP clock */ 42858ff70d4SMichael Buesch baud_base = 20000000; 42958ff70d4SMichael Buesch if (cc->capabilities & SSB_CHIPCO_CAP_PMU) { 43058ff70d4SMichael Buesch /* FIXME: baud_base is different for devices with a PMU */ 43158ff70d4SMichael Buesch SSB_WARN_ON(1); 43258ff70d4SMichael Buesch } 43358ff70d4SMichael Buesch div = 1; 43458ff70d4SMichael Buesch if (ccrev >= 21) { 43558ff70d4SMichael Buesch /* Turn off UART clock before switching clocksource. */ 43658ff70d4SMichael Buesch chipco_write32(cc, SSB_CHIPCO_CORECTL, 43758ff70d4SMichael Buesch chipco_read32(cc, SSB_CHIPCO_CORECTL) 43858ff70d4SMichael Buesch & ~SSB_CHIPCO_CORECTL_UARTCLKEN); 43958ff70d4SMichael Buesch } 44058ff70d4SMichael Buesch /* Set the override bit so we don't divide it */ 44158ff70d4SMichael Buesch chipco_write32(cc, SSB_CHIPCO_CORECTL, 44258ff70d4SMichael Buesch chipco_read32(cc, SSB_CHIPCO_CORECTL) 44358ff70d4SMichael Buesch | SSB_CHIPCO_CORECTL_UARTCLK0); 44458ff70d4SMichael Buesch if (ccrev >= 21) { 44558ff70d4SMichael Buesch /* Re-enable the UART clock. */ 44658ff70d4SMichael Buesch chipco_write32(cc, SSB_CHIPCO_CORECTL, 44758ff70d4SMichael Buesch chipco_read32(cc, SSB_CHIPCO_CORECTL) 44858ff70d4SMichael Buesch | SSB_CHIPCO_CORECTL_UARTCLKEN); 44958ff70d4SMichael Buesch } 45058ff70d4SMichael Buesch } else if (ccrev >= 3) { 45161e115a5SMichael Buesch /* Internal backplane clock */ 45261e115a5SMichael Buesch baud_base = ssb_clockspeed(bus); 45361e115a5SMichael Buesch div = chipco_read32(cc, SSB_CHIPCO_CLKDIV) 45461e115a5SMichael Buesch & SSB_CHIPCO_CLKDIV_UART; 45561e115a5SMichael Buesch } else { 45661e115a5SMichael Buesch /* Fixed internal backplane clock */ 45761e115a5SMichael Buesch baud_base = 88000000; 45861e115a5SMichael Buesch div = 48; 45961e115a5SMichael Buesch } 46061e115a5SMichael Buesch 46161e115a5SMichael Buesch /* Clock source depends on strapping if UartClkOverride is unset */ 46258ff70d4SMichael Buesch if ((ccrev > 0) && 46361e115a5SMichael Buesch !(chipco_read32(cc, SSB_CHIPCO_CORECTL) & SSB_CHIPCO_CORECTL_UARTCLK0)) { 46461e115a5SMichael Buesch if ((cc->capabilities & SSB_CHIPCO_CAP_UARTCLK) == 46561e115a5SMichael Buesch SSB_CHIPCO_CAP_UARTCLK_INT) { 46661e115a5SMichael Buesch /* Internal divided backplane clock */ 46761e115a5SMichael Buesch baud_base /= div; 46861e115a5SMichael Buesch } else { 46961e115a5SMichael Buesch /* Assume external clock of 1.8432 MHz */ 47061e115a5SMichael Buesch baud_base = 1843200; 47161e115a5SMichael Buesch } 47261e115a5SMichael Buesch } 47361e115a5SMichael Buesch } 47461e115a5SMichael Buesch 47561e115a5SMichael Buesch /* Determine the registers of the UARTs */ 47661e115a5SMichael Buesch n = (cc->capabilities & SSB_CHIPCO_CAP_NRUART); 47761e115a5SMichael Buesch for (i = 0; i < n; i++) { 47861e115a5SMichael Buesch void __iomem *cc_mmio; 47961e115a5SMichael Buesch void __iomem *uart_regs; 48061e115a5SMichael Buesch 48161e115a5SMichael Buesch cc_mmio = cc->dev->bus->mmio + (cc->dev->core_index * SSB_CORE_SIZE); 48261e115a5SMichael Buesch uart_regs = cc_mmio + SSB_CHIPCO_UART0_DATA; 48361e115a5SMichael Buesch /* Offset changed at after rev 0 */ 48458ff70d4SMichael Buesch if (ccrev == 0) 48561e115a5SMichael Buesch uart_regs += (i * 8); 48661e115a5SMichael Buesch else 48761e115a5SMichael Buesch uart_regs += (i * 256); 48861e115a5SMichael Buesch 48961e115a5SMichael Buesch nr_ports++; 49061e115a5SMichael Buesch ports[i].regs = uart_regs; 49161e115a5SMichael Buesch ports[i].irq = irq; 49261e115a5SMichael Buesch ports[i].baud_base = baud_base; 49361e115a5SMichael Buesch ports[i].reg_shift = 0; 49461e115a5SMichael Buesch } 49561e115a5SMichael Buesch 49661e115a5SMichael Buesch return nr_ports; 49761e115a5SMichael Buesch } 49861e115a5SMichael Buesch #endif /* CONFIG_SSB_SERIAL */ 499