2 * Broadcom specific AMBA
5 * Copyright 2005, Broadcom Corporation
6 * Copyright 2006, 2007, Michael Buesch <m@bues.ch>
8 * Licensed under the GNU/GPL. See COPYING for details.
11 #include "bcma_private.h"
12 #include <linux/export.h>
13 #include <linux/bcma/bcma.h>
15 /**************************************************
17 **************************************************/
19 static u32
bcma_pcie_read(struct bcma_drv_pci
*pc
, u32 address
)
21 pcicore_write32(pc
, 0x130, address
);
22 pcicore_read32(pc
, 0x130);
23 return pcicore_read32(pc
, 0x134);
27 static void bcma_pcie_write(struct bcma_drv_pci
*pc
, u32 address
, u32 data
)
29 pcicore_write32(pc
, 0x130, address
);
30 pcicore_read32(pc
, 0x130);
31 pcicore_write32(pc
, 0x134, data
);
35 static void bcma_pcie_mdio_set_phy(struct bcma_drv_pci
*pc
, u8 phy
)
37 const u16 mdio_control
= 0x128;
38 const u16 mdio_data
= 0x12C;
42 v
= (1 << 30); /* Start of Transaction */
43 v
|= (1 << 28); /* Write Transaction */
44 v
|= (1 << 17); /* Turnaround */
47 pcicore_write32(pc
, mdio_data
, v
);
50 for (i
= 0; i
< 200; i
++) {
51 v
= pcicore_read32(pc
, mdio_control
);
52 if (v
& 0x100 /* Trans complete */)
58 static u16
bcma_pcie_mdio_read(struct bcma_drv_pci
*pc
, u8 device
, u8 address
)
60 const u16 mdio_control
= 0x128;
61 const u16 mdio_data
= 0x12C;
67 v
= 0x80; /* Enable Preamble Sequence */
68 v
|= 0x2; /* MDIO Clock Divisor */
69 pcicore_write32(pc
, mdio_control
, v
);
71 if (pc
->core
->id
.rev
>= 10) {
73 bcma_pcie_mdio_set_phy(pc
, device
);
76 v
= (1 << 30); /* Start of Transaction */
77 v
|= (1 << 29); /* Read Transaction */
78 v
|= (1 << 17); /* Turnaround */
79 if (pc
->core
->id
.rev
< 10)
80 v
|= (u32
)device
<< 22;
81 v
|= (u32
)address
<< 18;
82 pcicore_write32(pc
, mdio_data
, v
);
83 /* Wait for the device to complete the transaction */
85 for (i
= 0; i
< max_retries
; i
++) {
86 v
= pcicore_read32(pc
, mdio_control
);
87 if (v
& 0x100 /* Trans complete */) {
89 ret
= pcicore_read32(pc
, mdio_data
);
94 pcicore_write32(pc
, mdio_control
, 0);
98 static void bcma_pcie_mdio_write(struct bcma_drv_pci
*pc
, u8 device
,
101 const u16 mdio_control
= 0x128;
102 const u16 mdio_data
= 0x12C;
103 int max_retries
= 10;
107 v
= 0x80; /* Enable Preamble Sequence */
108 v
|= 0x2; /* MDIO Clock Divisor */
109 pcicore_write32(pc
, mdio_control
, v
);
111 if (pc
->core
->id
.rev
>= 10) {
113 bcma_pcie_mdio_set_phy(pc
, device
);
116 v
= (1 << 30); /* Start of Transaction */
117 v
|= (1 << 28); /* Write Transaction */
118 v
|= (1 << 17); /* Turnaround */
119 if (pc
->core
->id
.rev
< 10)
120 v
|= (u32
)device
<< 22;
121 v
|= (u32
)address
<< 18;
123 pcicore_write32(pc
, mdio_data
, v
);
124 /* Wait for the device to complete the transaction */
126 for (i
= 0; i
< max_retries
; i
++) {
127 v
= pcicore_read32(pc
, mdio_control
);
128 if (v
& 0x100 /* Trans complete */)
132 pcicore_write32(pc
, mdio_control
, 0);
135 /**************************************************
137 **************************************************/
139 static u8
bcma_pcicore_polarity_workaround(struct bcma_drv_pci
*pc
)
141 return (bcma_pcie_read(pc
, 0x204) & 0x10) ? 0xC0 : 0x80;
144 static void bcma_pcicore_serdes_workaround(struct bcma_drv_pci
*pc
)
146 const u8 serdes_pll_device
= 0x1D;
147 const u8 serdes_rx_device
= 0x1F;
150 bcma_pcie_mdio_write(pc
, serdes_rx_device
, 1 /* Control */,
151 bcma_pcicore_polarity_workaround(pc
));
152 tmp
= bcma_pcie_mdio_read(pc
, serdes_pll_device
, 1 /* Control */);
154 bcma_pcie_mdio_write(pc
, serdes_pll_device
, 1, tmp
& ~0x4000);
157 /**************************************************
159 **************************************************/
161 static void bcma_core_pci_clientmode_init(struct bcma_drv_pci
*pc
)
163 bcma_pcicore_serdes_workaround(pc
);
166 static bool bcma_core_pci_is_in_hostmode(struct bcma_drv_pci
*pc
)
168 struct bcma_bus
*bus
= pc
->core
->bus
;
171 chipid_top
= (bus
->chipinfo
.id
& 0xFF00);
172 if (chipid_top
!= 0x4700 &&
173 chipid_top
!= 0x5300)
176 #ifdef CONFIG_SSB_DRIVER_PCICORE
177 if (bus
->sprom
.boardflags_lo
& SSB_BFL_NOPCI
)
179 #endif /* CONFIG_SSB_DRIVER_PCICORE */
182 /* TODO: on BCMA we use address from EROM instead of magic formula */
184 return !mips_busprobe32(tmp
, (bus
->mmio
+
185 (pc
->core
->core_index
* BCMA_CORE_SIZE
)));
191 void bcma_core_pci_init(struct bcma_drv_pci
*pc
)
196 if (bcma_core_pci_is_in_hostmode(pc
)) {
197 #ifdef CONFIG_BCMA_DRIVER_PCI_HOSTMODE
198 bcma_core_pci_hostmode_init(pc
);
200 pr_err("Driver compiled without support for hostmode PCI\n");
201 #endif /* CONFIG_BCMA_DRIVER_PCI_HOSTMODE */
203 bcma_core_pci_clientmode_init(pc
);
206 pc
->setup_done
= true;
209 int bcma_core_pci_irq_ctl(struct bcma_drv_pci
*pc
, struct bcma_device
*core
,
212 struct pci_dev
*pdev
= pc
->core
->bus
->host_pci
;
216 if (core
->bus
->hosttype
!= BCMA_HOSTTYPE_PCI
) {
217 /* This bcma device is not on a PCI host-bus. So the IRQs are
218 * not routed through the PCI core.
219 * So we must not enable routing through the PCI core. */
223 err
= pci_read_config_dword(pdev
, BCMA_PCI_IRQMASK
, &tmp
);
227 coremask
= BIT(core
->core_index
) << 8;
233 err
= pci_write_config_dword(pdev
, BCMA_PCI_IRQMASK
, tmp
);
238 EXPORT_SYMBOL_GPL(bcma_core_pci_irq_ctl
);