2 * Broadcom specific AMBA
5 * Licensed under the GNU/GPL. See COPYING for details.
8 #include "bcma_private.h"
9 #include <linux/bcma/bcma.h>
10 #include <linux/pci.h>
12 static void bcma_host_pci_switch_core(struct bcma_device
*core
)
14 pci_write_config_dword(core
->bus
->host_pci
, BCMA_PCI_BAR0_WIN
,
16 pci_write_config_dword(core
->bus
->host_pci
, BCMA_PCI_BAR0_WIN2
,
18 core
->bus
->mapped_core
= core
;
19 pr_debug("Switched to core: 0x%X\n", core
->id
.id
);
22 static u8
bcma_host_pci_read8(struct bcma_device
*core
, u16 offset
)
24 if (core
->bus
->mapped_core
!= core
)
25 bcma_host_pci_switch_core(core
);
26 return ioread8(core
->bus
->mmio
+ offset
);
29 static u16
bcma_host_pci_read16(struct bcma_device
*core
, u16 offset
)
31 if (core
->bus
->mapped_core
!= core
)
32 bcma_host_pci_switch_core(core
);
33 return ioread16(core
->bus
->mmio
+ offset
);
36 static u32
bcma_host_pci_read32(struct bcma_device
*core
, u16 offset
)
38 if (core
->bus
->mapped_core
!= core
)
39 bcma_host_pci_switch_core(core
);
40 return ioread32(core
->bus
->mmio
+ offset
);
43 static void bcma_host_pci_write8(struct bcma_device
*core
, u16 offset
,
46 if (core
->bus
->mapped_core
!= core
)
47 bcma_host_pci_switch_core(core
);
48 iowrite8(value
, core
->bus
->mmio
+ offset
);
51 static void bcma_host_pci_write16(struct bcma_device
*core
, u16 offset
,
54 if (core
->bus
->mapped_core
!= core
)
55 bcma_host_pci_switch_core(core
);
56 iowrite16(value
, core
->bus
->mmio
+ offset
);
59 static void bcma_host_pci_write32(struct bcma_device
*core
, u16 offset
,
62 if (core
->bus
->mapped_core
!= core
)
63 bcma_host_pci_switch_core(core
);
64 iowrite32(value
, core
->bus
->mmio
+ offset
);
67 static u32
bcma_host_pci_aread32(struct bcma_device
*core
, u16 offset
)
69 if (core
->bus
->mapped_core
!= core
)
70 bcma_host_pci_switch_core(core
);
71 return ioread32(core
->bus
->mmio
+ (1 * BCMA_CORE_SIZE
) + offset
);
74 static void bcma_host_pci_awrite32(struct bcma_device
*core
, u16 offset
,
77 if (core
->bus
->mapped_core
!= core
)
78 bcma_host_pci_switch_core(core
);
79 iowrite32(value
, core
->bus
->mmio
+ (1 * BCMA_CORE_SIZE
) + offset
);
82 const struct bcma_host_ops bcma_host_pci_ops
= {
83 .read8
= bcma_host_pci_read8
,
84 .read16
= bcma_host_pci_read16
,
85 .read32
= bcma_host_pci_read32
,
86 .write8
= bcma_host_pci_write8
,
87 .write16
= bcma_host_pci_write16
,
88 .write32
= bcma_host_pci_write32
,
89 .aread32
= bcma_host_pci_aread32
,
90 .awrite32
= bcma_host_pci_awrite32
,
93 static int bcma_host_pci_probe(struct pci_dev
*dev
,
94 const struct pci_device_id
*id
)
102 bus
= kzalloc(sizeof(*bus
), GFP_KERNEL
);
106 /* Basic PCI configuration */
107 err
= pci_enable_device(dev
);
111 name
= dev_name(&dev
->dev
);
112 if (dev
->driver
&& dev
->driver
->name
)
113 name
= dev
->driver
->name
;
114 err
= pci_request_regions(dev
, name
);
116 goto err_pci_disable
;
119 /* Disable the RETRY_TIMEOUT register (0x41) to keep
120 * PCI Tx retries from interfering with C3 CPU state */
121 pci_read_config_dword(dev
, 0x40, &val
);
122 if ((val
& 0x0000ff00) != 0)
123 pci_write_config_dword(dev
, 0x40, val
& 0xffff00ff);
125 /* SSB needed additional powering up, do we have any AMBA PCI cards? */
126 if (!pci_is_pcie(dev
))
127 pr_err("PCI card detected, report problems.\n");
131 bus
->mmio
= pci_iomap(dev
, 0, ~0UL);
133 goto err_pci_release_regions
;
137 bus
->hosttype
= BCMA_HOSTTYPE_PCI
;
138 bus
->ops
= &bcma_host_pci_ops
;
141 err
= bcma_bus_register(bus
);
143 goto err_pci_unmap_mmio
;
145 pci_set_drvdata(dev
, bus
);
151 pci_iounmap(dev
, bus
->mmio
);
152 err_pci_release_regions
:
153 pci_release_regions(dev
);
155 pci_disable_device(dev
);
161 static void bcma_host_pci_remove(struct pci_dev
*dev
)
163 struct bcma_bus
*bus
= pci_get_drvdata(dev
);
165 bcma_bus_unregister(bus
);
166 pci_iounmap(dev
, bus
->mmio
);
167 pci_release_regions(dev
);
168 pci_disable_device(dev
);
170 pci_set_drvdata(dev
, NULL
);
173 static DEFINE_PCI_DEVICE_TABLE(bcma_pci_bridge_tbl
) = {
174 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, 0x0576) },
175 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, 0x4331) },
176 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, 0x4353) },
177 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, 0x4727) },
180 MODULE_DEVICE_TABLE(pci
, bcma_pci_bridge_tbl
);
182 static struct pci_driver bcma_pci_bridge_driver
= {
183 .name
= "bcma-pci-bridge",
184 .id_table
= bcma_pci_bridge_tbl
,
185 .probe
= bcma_host_pci_probe
,
186 .remove
= bcma_host_pci_remove
,
189 int __init
bcma_host_pci_init(void)
191 return pci_register_driver(&bcma_pci_bridge_driver
);
194 void __exit
bcma_host_pci_exit(void)
196 pci_unregister_driver(&bcma_pci_bridge_driver
);