Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Broadcom specific AMBA |
| 3 | * PCI Core |
| 4 | * |
Hauke Mehrtens | 49dc957 | 2012-01-31 00:03:35 +0100 | [diff] [blame] | 5 | * Copyright 2005, 2011, Broadcom Corporation |
Michael Büsch | eb032b9 | 2011-07-04 20:50:05 +0200 | [diff] [blame] | 6 | * Copyright 2006, 2007, Michael Buesch <m@bues.ch> |
Hauke Mehrtens | 2be25ca | 2012-01-31 00:03:32 +0100 | [diff] [blame] | 7 | * Copyright 2011, 2012, Hauke Mehrtens <hauke@hauke-m.de> |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 8 | * |
| 9 | * Licensed under the GNU/GPL. See COPYING for details. |
| 10 | */ |
| 11 | |
| 12 | #include "bcma_private.h" |
Paul Gortmaker | 44a8e37 | 2011-07-27 21:21:04 -0400 | [diff] [blame] | 13 | #include <linux/export.h> |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 14 | #include <linux/bcma/bcma.h> |
| 15 | |
| 16 | /************************************************** |
| 17 | * R/W ops. |
| 18 | **************************************************/ |
| 19 | |
Hauke Mehrtens | 4b259a5 | 2012-01-31 00:03:33 +0100 | [diff] [blame] | 20 | u32 bcma_pcie_read(struct bcma_drv_pci *pc, u32 address) |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 21 | { |
Hauke Mehrtens | 2be25ca | 2012-01-31 00:03:32 +0100 | [diff] [blame] | 22 | pcicore_write32(pc, BCMA_CORE_PCI_PCIEIND_ADDR, address); |
| 23 | pcicore_read32(pc, BCMA_CORE_PCI_PCIEIND_ADDR); |
| 24 | return pcicore_read32(pc, BCMA_CORE_PCI_PCIEIND_DATA); |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 25 | } |
| 26 | |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 27 | static void bcma_pcie_write(struct bcma_drv_pci *pc, u32 address, u32 data) |
| 28 | { |
Hauke Mehrtens | 2be25ca | 2012-01-31 00:03:32 +0100 | [diff] [blame] | 29 | pcicore_write32(pc, BCMA_CORE_PCI_PCIEIND_ADDR, address); |
| 30 | pcicore_read32(pc, BCMA_CORE_PCI_PCIEIND_ADDR); |
| 31 | pcicore_write32(pc, BCMA_CORE_PCI_PCIEIND_DATA, data); |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 32 | } |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 33 | |
Hauke Mehrtens | 521deea | 2013-08-24 00:32:33 +0200 | [diff] [blame] | 34 | static void bcma_pcie_mdio_set_phy(struct bcma_drv_pci *pc, u16 phy) |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 35 | { |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 36 | u32 v; |
| 37 | int i; |
| 38 | |
Hauke Mehrtens | 2be25ca | 2012-01-31 00:03:32 +0100 | [diff] [blame] | 39 | v = BCMA_CORE_PCI_MDIODATA_START; |
| 40 | v |= BCMA_CORE_PCI_MDIODATA_WRITE; |
| 41 | v |= (BCMA_CORE_PCI_MDIODATA_DEV_ADDR << |
| 42 | BCMA_CORE_PCI_MDIODATA_DEVADDR_SHF); |
| 43 | v |= (BCMA_CORE_PCI_MDIODATA_BLK_ADDR << |
| 44 | BCMA_CORE_PCI_MDIODATA_REGADDR_SHF); |
| 45 | v |= BCMA_CORE_PCI_MDIODATA_TA; |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 46 | v |= (phy << 4); |
Hauke Mehrtens | 2be25ca | 2012-01-31 00:03:32 +0100 | [diff] [blame] | 47 | pcicore_write32(pc, BCMA_CORE_PCI_MDIO_DATA, v); |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 48 | |
| 49 | udelay(10); |
| 50 | for (i = 0; i < 200; i++) { |
Hauke Mehrtens | 2be25ca | 2012-01-31 00:03:32 +0100 | [diff] [blame] | 51 | v = pcicore_read32(pc, BCMA_CORE_PCI_MDIO_CONTROL); |
| 52 | if (v & BCMA_CORE_PCI_MDIOCTL_ACCESS_DONE) |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 53 | break; |
Rafał Miłecki | 1fd41a6 | 2012-09-25 10:17:22 +0200 | [diff] [blame] | 54 | usleep_range(1000, 2000); |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 55 | } |
| 56 | } |
| 57 | |
Hauke Mehrtens | 521deea | 2013-08-24 00:32:33 +0200 | [diff] [blame] | 58 | static u16 bcma_pcie_mdio_read(struct bcma_drv_pci *pc, u16 device, u8 address) |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 59 | { |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 60 | int max_retries = 10; |
| 61 | u16 ret = 0; |
| 62 | u32 v; |
| 63 | int i; |
| 64 | |
Hauke Mehrtens | 2be25ca | 2012-01-31 00:03:32 +0100 | [diff] [blame] | 65 | /* enable mdio access to SERDES */ |
| 66 | v = BCMA_CORE_PCI_MDIOCTL_PREAM_EN; |
| 67 | v |= BCMA_CORE_PCI_MDIOCTL_DIVISOR_VAL; |
| 68 | pcicore_write32(pc, BCMA_CORE_PCI_MDIO_CONTROL, v); |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 69 | |
| 70 | if (pc->core->id.rev >= 10) { |
| 71 | max_retries = 200; |
| 72 | bcma_pcie_mdio_set_phy(pc, device); |
Hauke Mehrtens | 2be25ca | 2012-01-31 00:03:32 +0100 | [diff] [blame] | 73 | v = (BCMA_CORE_PCI_MDIODATA_DEV_ADDR << |
| 74 | BCMA_CORE_PCI_MDIODATA_DEVADDR_SHF); |
| 75 | v |= (address << BCMA_CORE_PCI_MDIODATA_REGADDR_SHF); |
| 76 | } else { |
| 77 | v = (device << BCMA_CORE_PCI_MDIODATA_DEVADDR_SHF_OLD); |
| 78 | v |= (address << BCMA_CORE_PCI_MDIODATA_REGADDR_SHF_OLD); |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 79 | } |
| 80 | |
Hauke Mehrtens | 2be25ca | 2012-01-31 00:03:32 +0100 | [diff] [blame] | 81 | v = BCMA_CORE_PCI_MDIODATA_START; |
| 82 | v |= BCMA_CORE_PCI_MDIODATA_READ; |
| 83 | v |= BCMA_CORE_PCI_MDIODATA_TA; |
| 84 | |
| 85 | pcicore_write32(pc, BCMA_CORE_PCI_MDIO_DATA, v); |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 86 | /* Wait for the device to complete the transaction */ |
| 87 | udelay(10); |
Rafał Miłecki | f1a9c1e | 2011-05-12 00:01:47 +0200 | [diff] [blame] | 88 | for (i = 0; i < max_retries; i++) { |
Hauke Mehrtens | 2be25ca | 2012-01-31 00:03:32 +0100 | [diff] [blame] | 89 | v = pcicore_read32(pc, BCMA_CORE_PCI_MDIO_CONTROL); |
| 90 | if (v & BCMA_CORE_PCI_MDIOCTL_ACCESS_DONE) { |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 91 | udelay(10); |
Hauke Mehrtens | 2be25ca | 2012-01-31 00:03:32 +0100 | [diff] [blame] | 92 | ret = pcicore_read32(pc, BCMA_CORE_PCI_MDIO_DATA); |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 93 | break; |
| 94 | } |
Rafał Miłecki | 1fd41a6 | 2012-09-25 10:17:22 +0200 | [diff] [blame] | 95 | usleep_range(1000, 2000); |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 96 | } |
Hauke Mehrtens | 2be25ca | 2012-01-31 00:03:32 +0100 | [diff] [blame] | 97 | pcicore_write32(pc, BCMA_CORE_PCI_MDIO_CONTROL, 0); |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 98 | return ret; |
| 99 | } |
| 100 | |
Hauke Mehrtens | 521deea | 2013-08-24 00:32:33 +0200 | [diff] [blame] | 101 | static void bcma_pcie_mdio_write(struct bcma_drv_pci *pc, u16 device, |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 102 | u8 address, u16 data) |
| 103 | { |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 104 | int max_retries = 10; |
| 105 | u32 v; |
| 106 | int i; |
| 107 | |
Hauke Mehrtens | 2be25ca | 2012-01-31 00:03:32 +0100 | [diff] [blame] | 108 | /* enable mdio access to SERDES */ |
| 109 | v = BCMA_CORE_PCI_MDIOCTL_PREAM_EN; |
| 110 | v |= BCMA_CORE_PCI_MDIOCTL_DIVISOR_VAL; |
| 111 | pcicore_write32(pc, BCMA_CORE_PCI_MDIO_CONTROL, v); |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 112 | |
| 113 | if (pc->core->id.rev >= 10) { |
| 114 | max_retries = 200; |
| 115 | bcma_pcie_mdio_set_phy(pc, device); |
Hauke Mehrtens | 2be25ca | 2012-01-31 00:03:32 +0100 | [diff] [blame] | 116 | v = (BCMA_CORE_PCI_MDIODATA_DEV_ADDR << |
| 117 | BCMA_CORE_PCI_MDIODATA_DEVADDR_SHF); |
| 118 | v |= (address << BCMA_CORE_PCI_MDIODATA_REGADDR_SHF); |
| 119 | } else { |
| 120 | v = (device << BCMA_CORE_PCI_MDIODATA_DEVADDR_SHF_OLD); |
| 121 | v |= (address << BCMA_CORE_PCI_MDIODATA_REGADDR_SHF_OLD); |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 122 | } |
| 123 | |
Hauke Mehrtens | 2be25ca | 2012-01-31 00:03:32 +0100 | [diff] [blame] | 124 | v = BCMA_CORE_PCI_MDIODATA_START; |
| 125 | v |= BCMA_CORE_PCI_MDIODATA_WRITE; |
| 126 | v |= BCMA_CORE_PCI_MDIODATA_TA; |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 127 | v |= data; |
Hauke Mehrtens | 2be25ca | 2012-01-31 00:03:32 +0100 | [diff] [blame] | 128 | pcicore_write32(pc, BCMA_CORE_PCI_MDIO_DATA, v); |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 129 | /* Wait for the device to complete the transaction */ |
| 130 | udelay(10); |
| 131 | for (i = 0; i < max_retries; i++) { |
Hauke Mehrtens | 2be25ca | 2012-01-31 00:03:32 +0100 | [diff] [blame] | 132 | v = pcicore_read32(pc, BCMA_CORE_PCI_MDIO_CONTROL); |
| 133 | if (v & BCMA_CORE_PCI_MDIOCTL_ACCESS_DONE) |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 134 | break; |
Rafał Miłecki | 1fd41a6 | 2012-09-25 10:17:22 +0200 | [diff] [blame] | 135 | usleep_range(1000, 2000); |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 136 | } |
Hauke Mehrtens | 2be25ca | 2012-01-31 00:03:32 +0100 | [diff] [blame] | 137 | pcicore_write32(pc, BCMA_CORE_PCI_MDIO_CONTROL, 0); |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 138 | } |
| 139 | |
Hauke Mehrtens | 521deea | 2013-08-24 00:32:33 +0200 | [diff] [blame] | 140 | static u16 bcma_pcie_mdio_writeread(struct bcma_drv_pci *pc, u16 device, |
| 141 | u8 address, u16 data) |
| 142 | { |
| 143 | bcma_pcie_mdio_write(pc, device, address, data); |
| 144 | return bcma_pcie_mdio_read(pc, device, address); |
| 145 | } |
| 146 | |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 147 | /************************************************** |
| 148 | * Workarounds. |
| 149 | **************************************************/ |
| 150 | |
| 151 | static u8 bcma_pcicore_polarity_workaround(struct bcma_drv_pci *pc) |
| 152 | { |
Hauke Mehrtens | 2be25ca | 2012-01-31 00:03:32 +0100 | [diff] [blame] | 153 | u32 tmp; |
| 154 | |
| 155 | tmp = bcma_pcie_read(pc, BCMA_CORE_PCI_PLP_STATUSREG); |
| 156 | if (tmp & BCMA_CORE_PCI_PLP_POLARITYINV_STAT) |
| 157 | return BCMA_CORE_PCI_SERDES_RX_CTRL_FORCE | |
| 158 | BCMA_CORE_PCI_SERDES_RX_CTRL_POLARITY; |
| 159 | else |
| 160 | return BCMA_CORE_PCI_SERDES_RX_CTRL_FORCE; |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | static void bcma_pcicore_serdes_workaround(struct bcma_drv_pci *pc) |
| 164 | { |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 165 | u16 tmp; |
| 166 | |
Hauke Mehrtens | 2be25ca | 2012-01-31 00:03:32 +0100 | [diff] [blame] | 167 | bcma_pcie_mdio_write(pc, BCMA_CORE_PCI_MDIODATA_DEV_RX, |
| 168 | BCMA_CORE_PCI_SERDES_RX_CTRL, |
| 169 | bcma_pcicore_polarity_workaround(pc)); |
| 170 | tmp = bcma_pcie_mdio_read(pc, BCMA_CORE_PCI_MDIODATA_DEV_PLL, |
| 171 | BCMA_CORE_PCI_SERDES_PLL_CTRL); |
| 172 | if (tmp & BCMA_CORE_PCI_PLL_CTRL_FREQDET_EN) |
| 173 | bcma_pcie_mdio_write(pc, BCMA_CORE_PCI_MDIODATA_DEV_PLL, |
| 174 | BCMA_CORE_PCI_SERDES_PLL_CTRL, |
| 175 | tmp & ~BCMA_CORE_PCI_PLL_CTRL_FREQDET_EN); |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 176 | } |
| 177 | |
Hauke Mehrtens | ec00f37 | 2012-04-29 02:18:51 +0200 | [diff] [blame] | 178 | static void bcma_core_pci_fixcfg(struct bcma_drv_pci *pc) |
| 179 | { |
| 180 | struct bcma_device *core = pc->core; |
| 181 | u16 val16, core_index; |
| 182 | uint regoff; |
| 183 | |
| 184 | regoff = BCMA_CORE_PCI_SPROM(BCMA_CORE_PCI_SPROM_PI_OFFSET); |
| 185 | core_index = (u16)core->core_index; |
| 186 | |
| 187 | val16 = pcicore_read16(pc, regoff); |
| 188 | if (((val16 & BCMA_CORE_PCI_SPROM_PI_MASK) >> BCMA_CORE_PCI_SPROM_PI_SHIFT) |
| 189 | != core_index) { |
| 190 | val16 = (core_index << BCMA_CORE_PCI_SPROM_PI_SHIFT) | |
| 191 | (val16 & ~BCMA_CORE_PCI_SPROM_PI_MASK); |
| 192 | pcicore_write16(pc, regoff, val16); |
| 193 | } |
| 194 | } |
| 195 | |
Hauke Mehrtens | 2b2715b | 2012-04-29 02:18:52 +0200 | [diff] [blame] | 196 | /* Fix MISC config to allow coming out of L2/L3-Ready state w/o PRST */ |
| 197 | /* Needs to happen when coming out of 'standby'/'hibernate' */ |
| 198 | static void bcma_core_pci_config_fixup(struct bcma_drv_pci *pc) |
| 199 | { |
| 200 | u16 val16; |
| 201 | uint regoff; |
| 202 | |
| 203 | regoff = BCMA_CORE_PCI_SPROM(BCMA_CORE_PCI_SPROM_MISC_CONFIG); |
| 204 | |
| 205 | val16 = pcicore_read16(pc, regoff); |
| 206 | |
| 207 | if (!(val16 & BCMA_CORE_PCI_SPROM_L23READY_EXIT_NOPERST)) { |
| 208 | val16 |= BCMA_CORE_PCI_SPROM_L23READY_EXIT_NOPERST; |
| 209 | pcicore_write16(pc, regoff, val16); |
| 210 | } |
| 211 | } |
| 212 | |
Hauke Mehrtens | 521deea | 2013-08-24 00:32:33 +0200 | [diff] [blame] | 213 | static void bcma_core_pci_power_save(struct bcma_drv_pci *pc, bool up) |
| 214 | { |
| 215 | u16 data; |
| 216 | |
| 217 | if (pc->core->id.rev >= 15 && pc->core->id.rev <= 20) { |
| 218 | data = up ? 0x74 : 0x7C; |
| 219 | bcma_pcie_mdio_writeread(pc, BCMA_CORE_PCI_MDIO_BLK1, |
| 220 | BCMA_CORE_PCI_MDIO_BLK1_MGMT1, 0x7F64); |
| 221 | bcma_pcie_mdio_writeread(pc, BCMA_CORE_PCI_MDIO_BLK1, |
| 222 | BCMA_CORE_PCI_MDIO_BLK1_MGMT3, data); |
| 223 | } else if (pc->core->id.rev >= 21 && pc->core->id.rev <= 22) { |
| 224 | data = up ? 0x75 : 0x7D; |
| 225 | bcma_pcie_mdio_writeread(pc, BCMA_CORE_PCI_MDIO_BLK1, |
| 226 | BCMA_CORE_PCI_MDIO_BLK1_MGMT1, 0x7E65); |
| 227 | bcma_pcie_mdio_writeread(pc, BCMA_CORE_PCI_MDIO_BLK1, |
| 228 | BCMA_CORE_PCI_MDIO_BLK1_MGMT3, data); |
| 229 | } |
| 230 | } |
| 231 | |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 232 | /************************************************** |
| 233 | * Init. |
| 234 | **************************************************/ |
| 235 | |
Greg Kroah-Hartman | 0f58a01 | 2012-12-21 15:12:59 -0800 | [diff] [blame] | 236 | static void bcma_core_pci_clientmode_init(struct bcma_drv_pci *pc) |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 237 | { |
Hauke Mehrtens | ec00f37 | 2012-04-29 02:18:51 +0200 | [diff] [blame] | 238 | bcma_core_pci_fixcfg(pc); |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 239 | bcma_pcicore_serdes_workaround(pc); |
Hauke Mehrtens | 2b2715b | 2012-04-29 02:18:52 +0200 | [diff] [blame] | 240 | bcma_core_pci_config_fixup(pc); |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 241 | } |
Rafał Miłecki | 1de520f | 2011-05-19 14:08:22 +0200 | [diff] [blame] | 242 | |
Greg Kroah-Hartman | 0f58a01 | 2012-12-21 15:12:59 -0800 | [diff] [blame] | 243 | void bcma_core_pci_init(struct bcma_drv_pci *pc) |
Rafał Miłecki | 9352f69 | 2011-07-05 19:48:26 +0200 | [diff] [blame] | 244 | { |
Hauke Mehrtens | 517f43e | 2011-07-23 01:20:07 +0200 | [diff] [blame] | 245 | if (pc->setup_done) |
| 246 | return; |
| 247 | |
Rafał Miłecki | 9352f69 | 2011-07-05 19:48:26 +0200 | [diff] [blame] | 248 | #ifdef CONFIG_BCMA_DRIVER_PCI_HOSTMODE |
Hauke Mehrtens | 49dc957 | 2012-01-31 00:03:35 +0100 | [diff] [blame] | 249 | pc->hostmode = bcma_core_pci_is_in_hostmode(pc); |
| 250 | if (pc->hostmode) |
Rafał Miłecki | 9352f69 | 2011-07-05 19:48:26 +0200 | [diff] [blame] | 251 | bcma_core_pci_hostmode_init(pc); |
Rafał Miłecki | 9352f69 | 2011-07-05 19:48:26 +0200 | [diff] [blame] | 252 | #endif /* CONFIG_BCMA_DRIVER_PCI_HOSTMODE */ |
Hauke Mehrtens | 517f43e | 2011-07-23 01:20:07 +0200 | [diff] [blame] | 253 | |
Hauke Mehrtens | 49dc957 | 2012-01-31 00:03:35 +0100 | [diff] [blame] | 254 | if (!pc->hostmode) |
| 255 | bcma_core_pci_clientmode_init(pc); |
Rafał Miłecki | 9352f69 | 2011-07-05 19:48:26 +0200 | [diff] [blame] | 256 | } |
| 257 | |
Rafał Miłecki | 1de520f | 2011-05-19 14:08:22 +0200 | [diff] [blame] | 258 | int bcma_core_pci_irq_ctl(struct bcma_drv_pci *pc, struct bcma_device *core, |
| 259 | bool enable) |
| 260 | { |
Hauke Mehrtens | e702707 | 2012-06-05 20:58:20 +0200 | [diff] [blame] | 261 | struct pci_dev *pdev; |
Rafał Miłecki | 1de520f | 2011-05-19 14:08:22 +0200 | [diff] [blame] | 262 | u32 coremask, tmp; |
Hauke Mehrtens | ecd177c | 2011-07-23 01:20:08 +0200 | [diff] [blame] | 263 | int err = 0; |
| 264 | |
Hauke Mehrtens | e702707 | 2012-06-05 20:58:20 +0200 | [diff] [blame] | 265 | if (!pc || core->bus->hosttype != BCMA_HOSTTYPE_PCI) { |
Hauke Mehrtens | ecd177c | 2011-07-23 01:20:08 +0200 | [diff] [blame] | 266 | /* This bcma device is not on a PCI host-bus. So the IRQs are |
| 267 | * not routed through the PCI core. |
| 268 | * So we must not enable routing through the PCI core. */ |
| 269 | goto out; |
| 270 | } |
Rafał Miłecki | 1de520f | 2011-05-19 14:08:22 +0200 | [diff] [blame] | 271 | |
Hauke Mehrtens | e702707 | 2012-06-05 20:58:20 +0200 | [diff] [blame] | 272 | pdev = pc->core->bus->host_pci; |
| 273 | |
Rafał Miłecki | 1de520f | 2011-05-19 14:08:22 +0200 | [diff] [blame] | 274 | err = pci_read_config_dword(pdev, BCMA_PCI_IRQMASK, &tmp); |
| 275 | if (err) |
| 276 | goto out; |
| 277 | |
| 278 | coremask = BIT(core->core_index) << 8; |
| 279 | if (enable) |
| 280 | tmp |= coremask; |
| 281 | else |
| 282 | tmp &= ~coremask; |
| 283 | |
| 284 | err = pci_write_config_dword(pdev, BCMA_PCI_IRQMASK, tmp); |
| 285 | |
| 286 | out: |
| 287 | return err; |
| 288 | } |
Rafał Miłecki | 440ca98 | 2011-06-18 01:01:59 +0200 | [diff] [blame] | 289 | EXPORT_SYMBOL_GPL(bcma_core_pci_irq_ctl); |
Hauke Mehrtens | 29f6b3d | 2012-04-29 02:18:50 +0200 | [diff] [blame] | 290 | |
Hauke Mehrtens | 780335a | 2013-08-24 00:32:32 +0200 | [diff] [blame] | 291 | static void bcma_core_pci_extend_L1timer(struct bcma_drv_pci *pc, bool extend) |
Hauke Mehrtens | 29f6b3d | 2012-04-29 02:18:50 +0200 | [diff] [blame] | 292 | { |
| 293 | u32 w; |
| 294 | |
| 295 | w = bcma_pcie_read(pc, BCMA_CORE_PCI_DLLP_PMTHRESHREG); |
| 296 | if (extend) |
| 297 | w |= BCMA_CORE_PCI_ASPMTIMER_EXTEND; |
| 298 | else |
| 299 | w &= ~BCMA_CORE_PCI_ASPMTIMER_EXTEND; |
| 300 | bcma_pcie_write(pc, BCMA_CORE_PCI_DLLP_PMTHRESHREG, w); |
| 301 | bcma_pcie_read(pc, BCMA_CORE_PCI_DLLP_PMTHRESHREG); |
| 302 | } |
Hauke Mehrtens | cfe51ec | 2013-08-24 00:32:30 +0200 | [diff] [blame] | 303 | |
| 304 | void bcma_core_pci_up(struct bcma_bus *bus) |
| 305 | { |
| 306 | struct bcma_drv_pci *pc; |
| 307 | |
| 308 | if (bus->hosttype != BCMA_HOSTTYPE_PCI) |
| 309 | return; |
| 310 | |
| 311 | pc = &bus->drv_pci[0]; |
| 312 | |
Hauke Mehrtens | 521deea | 2013-08-24 00:32:33 +0200 | [diff] [blame] | 313 | bcma_core_pci_power_save(pc, true); |
| 314 | |
Hauke Mehrtens | cfe51ec | 2013-08-24 00:32:30 +0200 | [diff] [blame] | 315 | bcma_core_pci_extend_L1timer(pc, true); |
| 316 | } |
| 317 | EXPORT_SYMBOL_GPL(bcma_core_pci_up); |
| 318 | |
| 319 | void bcma_core_pci_down(struct bcma_bus *bus) |
| 320 | { |
| 321 | struct bcma_drv_pci *pc; |
| 322 | |
| 323 | if (bus->hosttype != BCMA_HOSTTYPE_PCI) |
| 324 | return; |
| 325 | |
| 326 | pc = &bus->drv_pci[0]; |
| 327 | |
| 328 | bcma_core_pci_extend_L1timer(pc, false); |
Hauke Mehrtens | 521deea | 2013-08-24 00:32:33 +0200 | [diff] [blame] | 329 | |
| 330 | bcma_core_pci_power_save(pc, false); |
Hauke Mehrtens | cfe51ec | 2013-08-24 00:32:30 +0200 | [diff] [blame] | 331 | } |
| 332 | EXPORT_SYMBOL_GPL(bcma_core_pci_down); |