12 #include <linux/pci.h>
13 #include <linux/export.h>
28 return ssb_read32(pc->dev, offset);
34 ssb_write32(pc->dev, offset, value);
40 return ssb_read16(pc->dev, offset);
46 ssb_write16(pc->dev, offset, value);
53 #ifdef CONFIG_SSB_PCICORE_HOSTMODE
59 #define mips_busprobe32(val, addr) get_dbe((val), ((u32 *)(addr)))
62 #define SSB_PCI_SLOT_MAX 16
71 unsigned int bus,
unsigned int dev,
72 unsigned int func,
unsigned int off)
78 if (pc->cardbusmode && (dev > 1))
83 if (
unlikely(dev >= SSB_PCI_SLOT_MAX))
86 tmp = SSB_PCICORE_SBTOPCI_CFG0;
87 tmp |= ((1 << (dev + 16)) & SSB_PCICORE_SBTOPCI1_MASK);
91 addr |= ((1 << (dev + 16)) & ~SSB_PCICORE_SBTOPCI1_MASK);
97 SSB_PCICORE_SBTOPCI_CFG1);
109 static int ssb_extpci_read_config(
struct ssb_pcicore *pc,
110 unsigned int bus,
unsigned int dev,
111 unsigned int func,
unsigned int off,
119 if (
unlikely(len != 1 && len != 2 && len != 4))
121 addr = get_cfgspace_addr(pc, bus, dev, func, off);
135 val >>= (8 * (off & 3));
139 *((
u8 *)buf) = (
u8)val;
155 static int ssb_extpci_write_config(
struct ssb_pcicore *pc,
156 unsigned int bus,
unsigned int dev,
157 unsigned int func,
unsigned int off,
158 const void *buf,
int len)
165 if (
unlikely(len != 1 && len != 2 && len != 4))
167 addr = get_cfgspace_addr(pc, bus, dev, func, off);
183 val &= ~(0xFF << (8 * (off & 3)));
184 val |= *((
const u8 *)buf) << (8 * (off & 3));
188 val &= ~(0xFFFF << (8 * (off & 3)));
189 val |= *((
const u16 *)buf) << (8 * (off & 3));
192 val = *((
const u32 *)buf);
204 static int ssb_pcicore_read_config(
struct pci_bus *bus,
unsigned int devfn,
211 err = ssb_extpci_read_config(extpci_core, bus->
number,
PCI_SLOT(devfn),
213 spin_unlock_irqrestore(&cfgspace_lock, flags);
218 static int ssb_pcicore_write_config(
struct pci_bus *bus,
unsigned int devfn,
219 int reg,
int size,
u32 val)
225 err = ssb_extpci_write_config(extpci_core, bus->
number,
PCI_SLOT(devfn),
227 spin_unlock_irqrestore(&cfgspace_lock, flags);
232 static struct pci_ops ssb_pcicore_pciops = {
233 .
read = ssb_pcicore_read_config,
234 .write = ssb_pcicore_write_config,
237 static struct resource ssb_pcicore_mem_resource = {
238 .
name =
"SSB PCIcore external memory",
244 static struct resource ssb_pcicore_io_resource = {
245 .
name =
"SSB PCIcore external I/O",
252 .pci_ops = &ssb_pcicore_pciops,
253 .io_resource = &ssb_pcicore_io_resource,
254 .mem_resource = &ssb_pcicore_mem_resource,
259 int ssb_pcicore_plat_dev_init(
struct pci_dev *
d)
261 if (d->
bus->ops != &ssb_pcicore_pciops) {
277 static void ssb_pcicore_fixup_pcibridge(
struct pci_dev *dev)
281 if (dev->
bus->ops != &ssb_pcicore_pciops) {
311 if (dev->
bus->ops != &ssb_pcicore_pciops) {
328 val = SSB_PCICORE_CTL_RST_OE;
329 val |= SSB_PCICORE_CTL_CLK_OE;
331 val |= SSB_PCICORE_CTL_CLK;
334 val |= SSB_PCICORE_CTL_RST;
336 val = SSB_PCICORE_ARBCTL_INTERN;
340 if (pc->dev->bus->has_cardbus_slot) {
353 SSB_PCICORE_SBTOPCI_IO);
356 SSB_PCICORE_SBTOPCI_CFG0);
363 ssb_extpci_write_config(pc, 0, 0, 0,
PCI_COMMAND, &val, 2);
366 ssb_extpci_write_config(pc, 0, 0, 0,
PCI_STATUS, &val, 2);
370 SSB_PCICORE_IMASK_INTA);
376 set_io_port_base(ssb_pcicore_controller.io_map_base);
385 struct ssb_bus *bus = pc->dev->bus;
389 chipid_top = (bus->
chip_id & 0xFF00);
390 if (chipid_top != 0x4700 &&
391 chipid_top != 0x5300)
394 if (bus->
sprom.boardflags_lo & SSB_PCICORE_BFL_NOPCI)
419 if (((tmp & 0xF000) >> 12) != pc->dev->core_index) {
421 tmp |= (pc->dev->core_index << 12);
426 static u8 ssb_pcicore_polarity_workaround(
struct ssb_pcicore *pc)
428 return (ssb_pcie_read(pc, 0x204) & 0x10) ? 0xC0 : 0x80;
431 static void ssb_pcicore_serdes_workaround(
struct ssb_pcicore *pc)
433 const u8 serdes_pll_device = 0x1D;
434 const u8 serdes_rx_device = 0x1F;
437 ssb_pcie_mdio_write(pc, serdes_rx_device, 1 ,
438 ssb_pcicore_polarity_workaround(pc));
439 tmp = ssb_pcie_mdio_read(pc, serdes_pll_device, 1 );
441 ssb_pcie_mdio_write(pc, serdes_pll_device, 1, tmp & ~0x4000);
444 static void ssb_pcicore_pci_setup_workarounds(
struct ssb_pcicore *pc)
451 tmp |= SSB_PCICORE_SBTOPCI_PREF;
452 tmp |= SSB_PCICORE_SBTOPCI_BURST;
455 if (pdev->
id.revision < 5) {
463 }
else if (pdev->
id.revision >= 11) {
465 tmp |= SSB_PCICORE_SBTOPCI_MRM;
470 static void ssb_pcicore_pcie_setup_workarounds(
struct ssb_pcicore *pc)
473 u8 rev = pc->dev->id.revision;
475 if (rev == 0 || rev == 1) {
477 tmp = ssb_pcie_read(pc, 0x4);
479 ssb_pcie_write(pc, 0x4, tmp);
483 tmp = ssb_pcie_read(pc, 0x100);
485 ssb_pcie_write(pc, 0x100, tmp);
489 const u8 serdes_rx_device = 0x1F;
491 ssb_pcie_mdio_write(pc, serdes_rx_device,
493 ssb_pcie_mdio_write(pc, serdes_rx_device,
495 ssb_pcie_mdio_write(pc, serdes_rx_device,
497 }
else if (rev == 3 || rev == 4 || rev == 5) {
499 ssb_pcicore_serdes_workaround(pc);
501 }
else if (rev == 7) {
524 ssb_pcicore_fix_sprom_core_index(pc);
531 ssb_pcicore_serdes_workaround(pc);
546 #ifdef CONFIG_SSB_PCICORE_HOSTMODE
547 pc->hostmode = pcicore_is_in_hostmode(pc);
549 ssb_pcicore_init_hostmode(pc);
552 ssb_pcicore_init_clientmode(pc);
569 const u16 mdio_control = 0x128;
582 for (i = 0; i < 200; i++) {
592 const u16 mdio_control = 0x128;
593 const u16 mdio_data = 0x12C;
594 int max_retries = 10;
603 if (pc->dev->id.revision >= 10) {
605 ssb_pcie_mdio_set_phy(pc, device);
611 if (pc->dev->id.revision < 10)
612 v |= (
u32)device << 22;
613 v |= (
u32)address << 18;
617 for (i = 0; i < max_retries; i++) {
630 static void ssb_pcie_mdio_write(
struct ssb_pcicore *pc,
u8 device,
633 const u16 mdio_control = 0x128;
634 const u16 mdio_data = 0x12C;
635 int max_retries = 10;
643 if (pc->dev->id.revision >= 10) {
645 ssb_pcie_mdio_set_phy(pc, device);
651 if (pc->dev->id.revision < 10)
652 v |= (
u32)device << 22;
653 v |= (
u32)address << 18;
658 for (i = 0; i < max_retries; i++) {
699 tmp |= coremask << 8;
709 intvec |= (1 <<
tmp);
717 ssb_pcicore_pci_setup_workarounds(pc);
720 ssb_pcicore_pcie_setup_workarounds(pc);