2011-05-09 16:56:46 +00:00
|
|
|
/*
|
|
|
|
* Broadcom specific AMBA
|
|
|
|
* PCI Core
|
|
|
|
*
|
2012-01-30 23:03:35 +00:00
|
|
|
* Copyright 2005, 2011, Broadcom Corporation
|
2011-07-04 18:50:05 +00:00
|
|
|
* Copyright 2006, 2007, Michael Buesch <m@bues.ch>
|
2012-01-30 23:03:32 +00:00
|
|
|
* Copyright 2011, 2012, Hauke Mehrtens <hauke@hauke-m.de>
|
2011-05-09 16:56:46 +00:00
|
|
|
*
|
|
|
|
* Licensed under the GNU/GPL. See COPYING for details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "bcma_private.h"
|
2011-07-28 01:21:04 +00:00
|
|
|
#include <linux/export.h>
|
2011-05-09 16:56:46 +00:00
|
|
|
#include <linux/bcma/bcma.h>
|
|
|
|
|
|
|
|
/**************************************************
|
|
|
|
* R/W ops.
|
|
|
|
**************************************************/
|
|
|
|
|
2012-01-30 23:03:33 +00:00
|
|
|
u32 bcma_pcie_read(struct bcma_drv_pci *pc, u32 address)
|
2011-05-09 16:56:46 +00:00
|
|
|
{
|
2012-01-30 23:03:32 +00:00
|
|
|
pcicore_write32(pc, BCMA_CORE_PCI_PCIEIND_ADDR, address);
|
|
|
|
pcicore_read32(pc, BCMA_CORE_PCI_PCIEIND_ADDR);
|
|
|
|
return pcicore_read32(pc, BCMA_CORE_PCI_PCIEIND_DATA);
|
2011-05-09 16:56:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void bcma_pcie_write(struct bcma_drv_pci *pc, u32 address, u32 data)
|
|
|
|
{
|
2012-01-30 23:03:32 +00:00
|
|
|
pcicore_write32(pc, BCMA_CORE_PCI_PCIEIND_ADDR, address);
|
|
|
|
pcicore_read32(pc, BCMA_CORE_PCI_PCIEIND_ADDR);
|
|
|
|
pcicore_write32(pc, BCMA_CORE_PCI_PCIEIND_DATA, data);
|
2011-05-09 16:56:46 +00:00
|
|
|
}
|
|
|
|
|
2013-08-23 22:32:33 +00:00
|
|
|
static void bcma_pcie_mdio_set_phy(struct bcma_drv_pci *pc, u16 phy)
|
2011-05-09 16:56:46 +00:00
|
|
|
{
|
|
|
|
u32 v;
|
|
|
|
int i;
|
|
|
|
|
2012-01-30 23:03:32 +00:00
|
|
|
v = BCMA_CORE_PCI_MDIODATA_START;
|
|
|
|
v |= BCMA_CORE_PCI_MDIODATA_WRITE;
|
|
|
|
v |= (BCMA_CORE_PCI_MDIODATA_DEV_ADDR <<
|
|
|
|
BCMA_CORE_PCI_MDIODATA_DEVADDR_SHF);
|
|
|
|
v |= (BCMA_CORE_PCI_MDIODATA_BLK_ADDR <<
|
|
|
|
BCMA_CORE_PCI_MDIODATA_REGADDR_SHF);
|
|
|
|
v |= BCMA_CORE_PCI_MDIODATA_TA;
|
2011-05-09 16:56:46 +00:00
|
|
|
v |= (phy << 4);
|
2012-01-30 23:03:32 +00:00
|
|
|
pcicore_write32(pc, BCMA_CORE_PCI_MDIO_DATA, v);
|
2011-05-09 16:56:46 +00:00
|
|
|
|
|
|
|
udelay(10);
|
|
|
|
for (i = 0; i < 200; i++) {
|
2012-01-30 23:03:32 +00:00
|
|
|
v = pcicore_read32(pc, BCMA_CORE_PCI_MDIO_CONTROL);
|
|
|
|
if (v & BCMA_CORE_PCI_MDIOCTL_ACCESS_DONE)
|
2011-05-09 16:56:46 +00:00
|
|
|
break;
|
2012-09-25 08:17:22 +00:00
|
|
|
usleep_range(1000, 2000);
|
2011-05-09 16:56:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-23 22:32:33 +00:00
|
|
|
static u16 bcma_pcie_mdio_read(struct bcma_drv_pci *pc, u16 device, u8 address)
|
2011-05-09 16:56:46 +00:00
|
|
|
{
|
|
|
|
int max_retries = 10;
|
|
|
|
u16 ret = 0;
|
|
|
|
u32 v;
|
|
|
|
int i;
|
|
|
|
|
2012-01-30 23:03:32 +00:00
|
|
|
/* enable mdio access to SERDES */
|
|
|
|
v = BCMA_CORE_PCI_MDIOCTL_PREAM_EN;
|
|
|
|
v |= BCMA_CORE_PCI_MDIOCTL_DIVISOR_VAL;
|
|
|
|
pcicore_write32(pc, BCMA_CORE_PCI_MDIO_CONTROL, v);
|
2011-05-09 16:56:46 +00:00
|
|
|
|
|
|
|
if (pc->core->id.rev >= 10) {
|
|
|
|
max_retries = 200;
|
|
|
|
bcma_pcie_mdio_set_phy(pc, device);
|
2012-01-30 23:03:32 +00:00
|
|
|
v = (BCMA_CORE_PCI_MDIODATA_DEV_ADDR <<
|
|
|
|
BCMA_CORE_PCI_MDIODATA_DEVADDR_SHF);
|
|
|
|
v |= (address << BCMA_CORE_PCI_MDIODATA_REGADDR_SHF);
|
|
|
|
} else {
|
|
|
|
v = (device << BCMA_CORE_PCI_MDIODATA_DEVADDR_SHF_OLD);
|
|
|
|
v |= (address << BCMA_CORE_PCI_MDIODATA_REGADDR_SHF_OLD);
|
2011-05-09 16:56:46 +00:00
|
|
|
}
|
|
|
|
|
2012-01-30 23:03:32 +00:00
|
|
|
v = BCMA_CORE_PCI_MDIODATA_START;
|
|
|
|
v |= BCMA_CORE_PCI_MDIODATA_READ;
|
|
|
|
v |= BCMA_CORE_PCI_MDIODATA_TA;
|
|
|
|
|
|
|
|
pcicore_write32(pc, BCMA_CORE_PCI_MDIO_DATA, v);
|
2011-05-09 16:56:46 +00:00
|
|
|
/* Wait for the device to complete the transaction */
|
|
|
|
udelay(10);
|
2011-05-11 22:01:47 +00:00
|
|
|
for (i = 0; i < max_retries; i++) {
|
2012-01-30 23:03:32 +00:00
|
|
|
v = pcicore_read32(pc, BCMA_CORE_PCI_MDIO_CONTROL);
|
|
|
|
if (v & BCMA_CORE_PCI_MDIOCTL_ACCESS_DONE) {
|
2011-05-09 16:56:46 +00:00
|
|
|
udelay(10);
|
2012-01-30 23:03:32 +00:00
|
|
|
ret = pcicore_read32(pc, BCMA_CORE_PCI_MDIO_DATA);
|
2011-05-09 16:56:46 +00:00
|
|
|
break;
|
|
|
|
}
|
2012-09-25 08:17:22 +00:00
|
|
|
usleep_range(1000, 2000);
|
2011-05-09 16:56:46 +00:00
|
|
|
}
|
2012-01-30 23:03:32 +00:00
|
|
|
pcicore_write32(pc, BCMA_CORE_PCI_MDIO_CONTROL, 0);
|
2011-05-09 16:56:46 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-08-23 22:32:33 +00:00
|
|
|
static void bcma_pcie_mdio_write(struct bcma_drv_pci *pc, u16 device,
|
2011-05-09 16:56:46 +00:00
|
|
|
u8 address, u16 data)
|
|
|
|
{
|
|
|
|
int max_retries = 10;
|
|
|
|
u32 v;
|
|
|
|
int i;
|
|
|
|
|
2012-01-30 23:03:32 +00:00
|
|
|
/* enable mdio access to SERDES */
|
|
|
|
v = BCMA_CORE_PCI_MDIOCTL_PREAM_EN;
|
|
|
|
v |= BCMA_CORE_PCI_MDIOCTL_DIVISOR_VAL;
|
|
|
|
pcicore_write32(pc, BCMA_CORE_PCI_MDIO_CONTROL, v);
|
2011-05-09 16:56:46 +00:00
|
|
|
|
|
|
|
if (pc->core->id.rev >= 10) {
|
|
|
|
max_retries = 200;
|
|
|
|
bcma_pcie_mdio_set_phy(pc, device);
|
2012-01-30 23:03:32 +00:00
|
|
|
v = (BCMA_CORE_PCI_MDIODATA_DEV_ADDR <<
|
|
|
|
BCMA_CORE_PCI_MDIODATA_DEVADDR_SHF);
|
|
|
|
v |= (address << BCMA_CORE_PCI_MDIODATA_REGADDR_SHF);
|
|
|
|
} else {
|
|
|
|
v = (device << BCMA_CORE_PCI_MDIODATA_DEVADDR_SHF_OLD);
|
|
|
|
v |= (address << BCMA_CORE_PCI_MDIODATA_REGADDR_SHF_OLD);
|
2011-05-09 16:56:46 +00:00
|
|
|
}
|
|
|
|
|
2012-01-30 23:03:32 +00:00
|
|
|
v = BCMA_CORE_PCI_MDIODATA_START;
|
|
|
|
v |= BCMA_CORE_PCI_MDIODATA_WRITE;
|
|
|
|
v |= BCMA_CORE_PCI_MDIODATA_TA;
|
2011-05-09 16:56:46 +00:00
|
|
|
v |= data;
|
2012-01-30 23:03:32 +00:00
|
|
|
pcicore_write32(pc, BCMA_CORE_PCI_MDIO_DATA, v);
|
2011-05-09 16:56:46 +00:00
|
|
|
/* Wait for the device to complete the transaction */
|
|
|
|
udelay(10);
|
|
|
|
for (i = 0; i < max_retries; i++) {
|
2012-01-30 23:03:32 +00:00
|
|
|
v = pcicore_read32(pc, BCMA_CORE_PCI_MDIO_CONTROL);
|
|
|
|
if (v & BCMA_CORE_PCI_MDIOCTL_ACCESS_DONE)
|
2011-05-09 16:56:46 +00:00
|
|
|
break;
|
2012-09-25 08:17:22 +00:00
|
|
|
usleep_range(1000, 2000);
|
2011-05-09 16:56:46 +00:00
|
|
|
}
|
2012-01-30 23:03:32 +00:00
|
|
|
pcicore_write32(pc, BCMA_CORE_PCI_MDIO_CONTROL, 0);
|
2011-05-09 16:56:46 +00:00
|
|
|
}
|
|
|
|
|
2013-08-23 22:32:33 +00:00
|
|
|
static u16 bcma_pcie_mdio_writeread(struct bcma_drv_pci *pc, u16 device,
|
|
|
|
u8 address, u16 data)
|
|
|
|
{
|
|
|
|
bcma_pcie_mdio_write(pc, device, address, data);
|
|
|
|
return bcma_pcie_mdio_read(pc, device, address);
|
|
|
|
}
|
|
|
|
|
2011-05-09 16:56:46 +00:00
|
|
|
/**************************************************
|
|
|
|
* Workarounds.
|
|
|
|
**************************************************/
|
|
|
|
|
|
|
|
static u8 bcma_pcicore_polarity_workaround(struct bcma_drv_pci *pc)
|
|
|
|
{
|
2012-01-30 23:03:32 +00:00
|
|
|
u32 tmp;
|
|
|
|
|
|
|
|
tmp = bcma_pcie_read(pc, BCMA_CORE_PCI_PLP_STATUSREG);
|
|
|
|
if (tmp & BCMA_CORE_PCI_PLP_POLARITYINV_STAT)
|
|
|
|
return BCMA_CORE_PCI_SERDES_RX_CTRL_FORCE |
|
|
|
|
BCMA_CORE_PCI_SERDES_RX_CTRL_POLARITY;
|
|
|
|
else
|
|
|
|
return BCMA_CORE_PCI_SERDES_RX_CTRL_FORCE;
|
2011-05-09 16:56:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void bcma_pcicore_serdes_workaround(struct bcma_drv_pci *pc)
|
|
|
|
{
|
|
|
|
u16 tmp;
|
|
|
|
|
2012-01-30 23:03:32 +00:00
|
|
|
bcma_pcie_mdio_write(pc, BCMA_CORE_PCI_MDIODATA_DEV_RX,
|
|
|
|
BCMA_CORE_PCI_SERDES_RX_CTRL,
|
|
|
|
bcma_pcicore_polarity_workaround(pc));
|
|
|
|
tmp = bcma_pcie_mdio_read(pc, BCMA_CORE_PCI_MDIODATA_DEV_PLL,
|
|
|
|
BCMA_CORE_PCI_SERDES_PLL_CTRL);
|
|
|
|
if (tmp & BCMA_CORE_PCI_PLL_CTRL_FREQDET_EN)
|
|
|
|
bcma_pcie_mdio_write(pc, BCMA_CORE_PCI_MDIODATA_DEV_PLL,
|
|
|
|
BCMA_CORE_PCI_SERDES_PLL_CTRL,
|
|
|
|
tmp & ~BCMA_CORE_PCI_PLL_CTRL_FREQDET_EN);
|
2011-05-09 16:56:46 +00:00
|
|
|
}
|
|
|
|
|
2012-04-29 00:18:51 +00:00
|
|
|
static void bcma_core_pci_fixcfg(struct bcma_drv_pci *pc)
|
|
|
|
{
|
|
|
|
struct bcma_device *core = pc->core;
|
|
|
|
u16 val16, core_index;
|
|
|
|
uint regoff;
|
|
|
|
|
|
|
|
regoff = BCMA_CORE_PCI_SPROM(BCMA_CORE_PCI_SPROM_PI_OFFSET);
|
|
|
|
core_index = (u16)core->core_index;
|
|
|
|
|
|
|
|
val16 = pcicore_read16(pc, regoff);
|
|
|
|
if (((val16 & BCMA_CORE_PCI_SPROM_PI_MASK) >> BCMA_CORE_PCI_SPROM_PI_SHIFT)
|
|
|
|
!= core_index) {
|
|
|
|
val16 = (core_index << BCMA_CORE_PCI_SPROM_PI_SHIFT) |
|
|
|
|
(val16 & ~BCMA_CORE_PCI_SPROM_PI_MASK);
|
|
|
|
pcicore_write16(pc, regoff, val16);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-29 00:18:52 +00:00
|
|
|
/* Fix MISC config to allow coming out of L2/L3-Ready state w/o PRST */
|
|
|
|
/* Needs to happen when coming out of 'standby'/'hibernate' */
|
|
|
|
static void bcma_core_pci_config_fixup(struct bcma_drv_pci *pc)
|
|
|
|
{
|
|
|
|
u16 val16;
|
|
|
|
uint regoff;
|
|
|
|
|
|
|
|
regoff = BCMA_CORE_PCI_SPROM(BCMA_CORE_PCI_SPROM_MISC_CONFIG);
|
|
|
|
|
|
|
|
val16 = pcicore_read16(pc, regoff);
|
|
|
|
|
|
|
|
if (!(val16 & BCMA_CORE_PCI_SPROM_L23READY_EXIT_NOPERST)) {
|
|
|
|
val16 |= BCMA_CORE_PCI_SPROM_L23READY_EXIT_NOPERST;
|
|
|
|
pcicore_write16(pc, regoff, val16);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-09 16:56:46 +00:00
|
|
|
/**************************************************
|
|
|
|
* Init.
|
|
|
|
**************************************************/
|
|
|
|
|
2012-12-21 23:12:59 +00:00
|
|
|
static void bcma_core_pci_clientmode_init(struct bcma_drv_pci *pc)
|
2011-05-09 16:56:46 +00:00
|
|
|
{
|
2012-04-29 00:18:51 +00:00
|
|
|
bcma_core_pci_fixcfg(pc);
|
2011-05-09 16:56:46 +00:00
|
|
|
bcma_pcicore_serdes_workaround(pc);
|
2012-04-29 00:18:52 +00:00
|
|
|
bcma_core_pci_config_fixup(pc);
|
2011-05-09 16:56:46 +00:00
|
|
|
}
|
2011-05-19 12:08:22 +00:00
|
|
|
|
2012-12-21 23:12:59 +00:00
|
|
|
void bcma_core_pci_init(struct bcma_drv_pci *pc)
|
2011-07-05 17:48:26 +00:00
|
|
|
{
|
2011-07-22 23:20:07 +00:00
|
|
|
if (pc->setup_done)
|
|
|
|
return;
|
|
|
|
|
2012-01-30 23:03:35 +00:00
|
|
|
pc->hostmode = bcma_core_pci_is_in_hostmode(pc);
|
|
|
|
if (pc->hostmode)
|
2011-07-05 17:48:26 +00:00
|
|
|
bcma_core_pci_hostmode_init(pc);
|
2011-07-22 23:20:07 +00:00
|
|
|
|
2012-01-30 23:03:35 +00:00
|
|
|
if (!pc->hostmode)
|
|
|
|
bcma_core_pci_clientmode_init(pc);
|
2011-07-05 17:48:26 +00:00
|
|
|
}
|
|
|
|
|
2013-09-25 10:11:02 +00:00
|
|
|
void bcma_core_pci_power_save(struct bcma_bus *bus, bool up)
|
|
|
|
{
|
|
|
|
struct bcma_drv_pci *pc;
|
|
|
|
u16 data;
|
|
|
|
|
|
|
|
if (bus->hosttype != BCMA_HOSTTYPE_PCI)
|
|
|
|
return;
|
|
|
|
|
|
|
|
pc = &bus->drv_pci[0];
|
|
|
|
|
|
|
|
if (pc->core->id.rev >= 15 && pc->core->id.rev <= 20) {
|
|
|
|
data = up ? 0x74 : 0x7C;
|
|
|
|
bcma_pcie_mdio_writeread(pc, BCMA_CORE_PCI_MDIO_BLK1,
|
|
|
|
BCMA_CORE_PCI_MDIO_BLK1_MGMT1, 0x7F64);
|
|
|
|
bcma_pcie_mdio_writeread(pc, BCMA_CORE_PCI_MDIO_BLK1,
|
|
|
|
BCMA_CORE_PCI_MDIO_BLK1_MGMT3, data);
|
|
|
|
} else if (pc->core->id.rev >= 21 && pc->core->id.rev <= 22) {
|
|
|
|
data = up ? 0x75 : 0x7D;
|
|
|
|
bcma_pcie_mdio_writeread(pc, BCMA_CORE_PCI_MDIO_BLK1,
|
|
|
|
BCMA_CORE_PCI_MDIO_BLK1_MGMT1, 0x7E65);
|
|
|
|
bcma_pcie_mdio_writeread(pc, BCMA_CORE_PCI_MDIO_BLK1,
|
|
|
|
BCMA_CORE_PCI_MDIO_BLK1_MGMT3, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(bcma_core_pci_power_save);
|
|
|
|
|
2011-05-19 12:08:22 +00:00
|
|
|
int bcma_core_pci_irq_ctl(struct bcma_drv_pci *pc, struct bcma_device *core,
|
|
|
|
bool enable)
|
|
|
|
{
|
2012-06-05 18:58:20 +00:00
|
|
|
struct pci_dev *pdev;
|
2011-05-19 12:08:22 +00:00
|
|
|
u32 coremask, tmp;
|
2011-07-22 23:20:08 +00:00
|
|
|
int err = 0;
|
|
|
|
|
2012-06-05 18:58:20 +00:00
|
|
|
if (!pc || core->bus->hosttype != BCMA_HOSTTYPE_PCI) {
|
2011-07-22 23:20:08 +00:00
|
|
|
/* This bcma device is not on a PCI host-bus. So the IRQs are
|
|
|
|
* not routed through the PCI core.
|
|
|
|
* So we must not enable routing through the PCI core. */
|
|
|
|
goto out;
|
|
|
|
}
|
2011-05-19 12:08:22 +00:00
|
|
|
|
2012-06-05 18:58:20 +00:00
|
|
|
pdev = pc->core->bus->host_pci;
|
|
|
|
|
2011-05-19 12:08:22 +00:00
|
|
|
err = pci_read_config_dword(pdev, BCMA_PCI_IRQMASK, &tmp);
|
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
coremask = BIT(core->core_index) << 8;
|
|
|
|
if (enable)
|
|
|
|
tmp |= coremask;
|
|
|
|
else
|
|
|
|
tmp &= ~coremask;
|
|
|
|
|
|
|
|
err = pci_write_config_dword(pdev, BCMA_PCI_IRQMASK, tmp);
|
|
|
|
|
|
|
|
out:
|
|
|
|
return err;
|
|
|
|
}
|
2011-06-17 23:01:59 +00:00
|
|
|
EXPORT_SYMBOL_GPL(bcma_core_pci_irq_ctl);
|
2012-04-29 00:18:50 +00:00
|
|
|
|
2013-08-23 22:32:32 +00:00
|
|
|
static void bcma_core_pci_extend_L1timer(struct bcma_drv_pci *pc, bool extend)
|
2012-04-29 00:18:50 +00:00
|
|
|
{
|
|
|
|
u32 w;
|
|
|
|
|
|
|
|
w = bcma_pcie_read(pc, BCMA_CORE_PCI_DLLP_PMTHRESHREG);
|
|
|
|
if (extend)
|
|
|
|
w |= BCMA_CORE_PCI_ASPMTIMER_EXTEND;
|
|
|
|
else
|
|
|
|
w &= ~BCMA_CORE_PCI_ASPMTIMER_EXTEND;
|
|
|
|
bcma_pcie_write(pc, BCMA_CORE_PCI_DLLP_PMTHRESHREG, w);
|
|
|
|
bcma_pcie_read(pc, BCMA_CORE_PCI_DLLP_PMTHRESHREG);
|
|
|
|
}
|
2013-08-23 22:32:30 +00:00
|
|
|
|
|
|
|
void bcma_core_pci_up(struct bcma_bus *bus)
|
|
|
|
{
|
|
|
|
struct bcma_drv_pci *pc;
|
|
|
|
|
|
|
|
if (bus->hosttype != BCMA_HOSTTYPE_PCI)
|
|
|
|
return;
|
|
|
|
|
|
|
|
pc = &bus->drv_pci[0];
|
|
|
|
|
|
|
|
bcma_core_pci_extend_L1timer(pc, true);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(bcma_core_pci_up);
|
|
|
|
|
|
|
|
void bcma_core_pci_down(struct bcma_bus *bus)
|
|
|
|
{
|
|
|
|
struct bcma_drv_pci *pc;
|
|
|
|
|
|
|
|
if (bus->hosttype != BCMA_HOSTTYPE_PCI)
|
|
|
|
return;
|
|
|
|
|
|
|
|
pc = &bus->drv_pci[0];
|
|
|
|
|
|
|
|
bcma_core_pci_extend_L1timer(pc, false);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(bcma_core_pci_down);
|