Franky Lin | a83369b | 2011-11-04 22:23:28 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2011 Broadcom Corporation |
| 3 | * |
| 4 | * Permission to use, copy, modify, and/or distribute this software for any |
| 5 | * purpose with or without fee is hereby granted, provided that the above |
| 6 | * copyright notice and this permission notice appear in all copies. |
| 7 | * |
| 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
| 11 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION |
| 13 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
| 14 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 15 | */ |
| 16 | /* ***** SDIO interface chip backplane handle functions ***** */ |
| 17 | |
| 18 | #include <linux/types.h> |
| 19 | #include <linux/netdevice.h> |
| 20 | #include <linux/mmc/card.h> |
Franky Lin | fe04015 | 2013-09-25 13:05:41 +0200 | [diff] [blame] | 21 | #include <linux/mmc/sdio_func.h> |
Arend van Spriel | 6e08d75 | 2014-01-06 12:40:50 +0100 | [diff] [blame] | 22 | #include <linux/mmc/sdio_ids.h> |
Franky Lin | 61213be | 2011-11-04 22:23:41 +0100 | [diff] [blame] | 23 | #include <linux/ssb/ssb_regs.h> |
Franky Lin | 99ba15c | 2011-11-04 22:23:42 +0100 | [diff] [blame] | 24 | #include <linux/bcma/bcma.h> |
Franky Lin | 61213be | 2011-11-04 22:23:41 +0100 | [diff] [blame] | 25 | |
Franky Lin | a83369b | 2011-11-04 22:23:28 +0100 | [diff] [blame] | 26 | #include <chipcommon.h> |
| 27 | #include <brcm_hw_ids.h> |
| 28 | #include <brcmu_wifi.h> |
| 29 | #include <brcmu_utils.h> |
Franky Lin | 2d4a9af | 2011-11-04 22:23:31 +0100 | [diff] [blame] | 30 | #include <soc.h> |
Franky Lin | a83369b | 2011-11-04 22:23:28 +0100 | [diff] [blame] | 31 | #include "dhd_dbg.h" |
| 32 | #include "sdio_host.h" |
Arend van Spriel | 20c9c9b | 2014-01-29 15:32:15 +0100 | [diff] [blame^] | 33 | #include "chip.h" |
Franky Lin | a83369b | 2011-11-04 22:23:28 +0100 | [diff] [blame] | 34 | |
| 35 | /* chip core base & ramsize */ |
| 36 | /* bcm4329 */ |
| 37 | /* SDIO device core, ID 0x829 */ |
| 38 | #define BCM4329_CORE_BUS_BASE 0x18011000 |
| 39 | /* internal memory core, ID 0x80e */ |
| 40 | #define BCM4329_CORE_SOCRAM_BASE 0x18003000 |
| 41 | /* ARM Cortex M3 core, ID 0x82a */ |
| 42 | #define BCM4329_CORE_ARM_BASE 0x18002000 |
| 43 | #define BCM4329_RAMSIZE 0x48000 |
| 44 | |
Hante Meuleman | 369508c | 2013-04-11 13:28:54 +0200 | [diff] [blame] | 45 | /* bcm43143 */ |
| 46 | /* SDIO device core */ |
| 47 | #define BCM43143_CORE_BUS_BASE 0x18002000 |
| 48 | /* internal memory core */ |
| 49 | #define BCM43143_CORE_SOCRAM_BASE 0x18004000 |
| 50 | /* ARM Cortex M3 core, ID 0x82a */ |
| 51 | #define BCM43143_CORE_ARM_BASE 0x18003000 |
| 52 | #define BCM43143_RAMSIZE 0x70000 |
| 53 | |
Hante Meuleman | 5303626 | 2014-01-13 22:20:23 +0100 | [diff] [blame] | 54 | /* All D11 cores, ID 0x812 */ |
| 55 | #define BCM43xx_CORE_D11_BASE 0x18001000 |
| 56 | |
Franky Lin | a83369b | 2011-11-04 22:23:28 +0100 | [diff] [blame] | 57 | #define SBCOREREV(sbidh) \ |
Franky Lin | 61213be | 2011-11-04 22:23:41 +0100 | [diff] [blame] | 58 | ((((sbidh) & SSB_IDHIGH_RCHI) >> SSB_IDHIGH_RCHI_SHIFT) | \ |
| 59 | ((sbidh) & SSB_IDHIGH_RCLO)) |
Franky Lin | a83369b | 2011-11-04 22:23:28 +0100 | [diff] [blame] | 60 | |
Franky Lin | 6ca687d | 2011-11-10 20:30:21 +0100 | [diff] [blame] | 61 | /* SOC Interconnect types (aka chip types) */ |
| 62 | #define SOCI_SB 0 |
| 63 | #define SOCI_AI 1 |
| 64 | |
Franky Lin | 523894f | 2011-11-10 20:30:22 +0100 | [diff] [blame] | 65 | /* EROM CompIdentB */ |
| 66 | #define CIB_REV_MASK 0xff000000 |
| 67 | #define CIB_REV_SHIFT 24 |
| 68 | |
Franky Lin | 1640f28 | 2013-04-11 13:28:51 +0200 | [diff] [blame] | 69 | /* ARM CR4 core specific control flag bits */ |
| 70 | #define ARMCR4_BCMA_IOCTL_CPUHALT 0x0020 |
| 71 | |
Hante Meuleman | 5303626 | 2014-01-13 22:20:23 +0100 | [diff] [blame] | 72 | /* D11 core specific control flag bits */ |
| 73 | #define D11_BCMA_IOCTL_PHYCLOCKEN 0x0004 |
| 74 | #define D11_BCMA_IOCTL_PHYRESET 0x0008 |
| 75 | |
Franky Lin | 99ba15c | 2011-11-04 22:23:42 +0100 | [diff] [blame] | 76 | u8 |
Arend van Spriel | 9cf218f | 2014-01-13 22:20:27 +0100 | [diff] [blame] | 77 | brcmf_sdio_chip_getinfidx(struct brcmf_chip *ci, u16 coreid) |
Franky Lin | 99ba15c | 2011-11-04 22:23:42 +0100 | [diff] [blame] | 78 | { |
| 79 | u8 idx; |
| 80 | |
| 81 | for (idx = 0; idx < BRCMF_MAX_CORENUM; idx++) |
| 82 | if (coreid == ci->c_inf[idx].id) |
| 83 | return idx; |
| 84 | |
| 85 | return BRCMF_MAX_CORENUM; |
| 86 | } |
| 87 | |
Franky Lin | 454d2a8 | 2011-11-04 22:23:37 +0100 | [diff] [blame] | 88 | static u32 |
Franky Lin | 523894f | 2011-11-10 20:30:22 +0100 | [diff] [blame] | 89 | brcmf_sdio_sb_corerev(struct brcmf_sdio_dev *sdiodev, |
Arend van Spriel | 9cf218f | 2014-01-13 22:20:27 +0100 | [diff] [blame] | 90 | struct brcmf_chip *ci, u16 coreid) |
Franky Lin | 454d2a8 | 2011-11-04 22:23:37 +0100 | [diff] [blame] | 91 | { |
| 92 | u32 regdata; |
Franky Lin | 523894f | 2011-11-10 20:30:22 +0100 | [diff] [blame] | 93 | u8 idx; |
| 94 | |
| 95 | idx = brcmf_sdio_chip_getinfidx(ci, coreid); |
Franky Lin | 454d2a8 | 2011-11-04 22:23:37 +0100 | [diff] [blame] | 96 | |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 97 | regdata = brcmf_sdiod_regrl(sdiodev, |
| 98 | CORE_SB(ci->c_inf[idx].base, sbidhigh), |
| 99 | NULL); |
Franky Lin | 454d2a8 | 2011-11-04 22:23:37 +0100 | [diff] [blame] | 100 | return SBCOREREV(regdata); |
| 101 | } |
| 102 | |
Franky Lin | 523894f | 2011-11-10 20:30:22 +0100 | [diff] [blame] | 103 | static u32 |
| 104 | brcmf_sdio_ai_corerev(struct brcmf_sdio_dev *sdiodev, |
Arend van Spriel | 9cf218f | 2014-01-13 22:20:27 +0100 | [diff] [blame] | 105 | struct brcmf_chip *ci, u16 coreid) |
Franky Lin | 523894f | 2011-11-10 20:30:22 +0100 | [diff] [blame] | 106 | { |
| 107 | u8 idx; |
| 108 | |
| 109 | idx = brcmf_sdio_chip_getinfidx(ci, coreid); |
| 110 | |
| 111 | return (ci->c_inf[idx].cib & CIB_REV_MASK) >> CIB_REV_SHIFT; |
| 112 | } |
| 113 | |
Franky Lin | 6ca687d | 2011-11-10 20:30:21 +0100 | [diff] [blame] | 114 | static bool |
| 115 | brcmf_sdio_sb_iscoreup(struct brcmf_sdio_dev *sdiodev, |
Arend van Spriel | 9cf218f | 2014-01-13 22:20:27 +0100 | [diff] [blame] | 116 | struct brcmf_chip *ci, u16 coreid) |
Franky Lin | d8f64a4 | 2011-11-04 22:23:36 +0100 | [diff] [blame] | 117 | { |
| 118 | u32 regdata; |
Franky Lin | 6ca687d | 2011-11-10 20:30:21 +0100 | [diff] [blame] | 119 | u8 idx; |
| 120 | |
| 121 | idx = brcmf_sdio_chip_getinfidx(ci, coreid); |
Franky Lin | 7434785 | 2013-09-25 13:05:42 +0200 | [diff] [blame] | 122 | if (idx == BRCMF_MAX_CORENUM) |
| 123 | return false; |
Franky Lin | d8f64a4 | 2011-11-04 22:23:36 +0100 | [diff] [blame] | 124 | |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 125 | regdata = brcmf_sdiod_regrl(sdiodev, |
| 126 | CORE_SB(ci->c_inf[idx].base, sbtmstatelow), |
| 127 | NULL); |
Franky Lin | 61213be | 2011-11-04 22:23:41 +0100 | [diff] [blame] | 128 | regdata &= (SSB_TMSLOW_RESET | SSB_TMSLOW_REJECT | |
| 129 | SSB_IMSTATE_REJECT | SSB_TMSLOW_CLOCK); |
Arend van Spriel | 20c9c9b | 2014-01-29 15:32:15 +0100 | [diff] [blame^] | 130 | return SSB_TMSLOW_CLOCK == regdata; |
Franky Lin | d8f64a4 | 2011-11-04 22:23:36 +0100 | [diff] [blame] | 131 | } |
| 132 | |
Franky Lin | 6ca687d | 2011-11-10 20:30:21 +0100 | [diff] [blame] | 133 | static bool |
| 134 | brcmf_sdio_ai_iscoreup(struct brcmf_sdio_dev *sdiodev, |
Arend van Spriel | 9cf218f | 2014-01-13 22:20:27 +0100 | [diff] [blame] | 135 | struct brcmf_chip *ci, u16 coreid) |
Franky Lin | 6ca687d | 2011-11-10 20:30:21 +0100 | [diff] [blame] | 136 | { |
| 137 | u32 regdata; |
| 138 | u8 idx; |
| 139 | bool ret; |
| 140 | |
| 141 | idx = brcmf_sdio_chip_getinfidx(ci, coreid); |
Franky Lin | 7434785 | 2013-09-25 13:05:42 +0200 | [diff] [blame] | 142 | if (idx == BRCMF_MAX_CORENUM) |
| 143 | return false; |
Franky Lin | 6ca687d | 2011-11-10 20:30:21 +0100 | [diff] [blame] | 144 | |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 145 | regdata = brcmf_sdiod_regrl(sdiodev, ci->c_inf[idx].wrapbase+BCMA_IOCTL, |
| 146 | NULL); |
Franky Lin | 6ca687d | 2011-11-10 20:30:21 +0100 | [diff] [blame] | 147 | ret = (regdata & (BCMA_IOCTL_FGC | BCMA_IOCTL_CLK)) == BCMA_IOCTL_CLK; |
| 148 | |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 149 | regdata = brcmf_sdiod_regrl(sdiodev, |
| 150 | ci->c_inf[idx].wrapbase+BCMA_RESET_CTL, |
| 151 | NULL); |
Franky Lin | 6ca687d | 2011-11-10 20:30:21 +0100 | [diff] [blame] | 152 | ret = ret && ((regdata & BCMA_RESET_CTL_RESET) == 0); |
| 153 | |
| 154 | return ret; |
| 155 | } |
| 156 | |
Franky Lin | 086a2e0 | 2011-11-10 20:30:23 +0100 | [diff] [blame] | 157 | static void |
| 158 | brcmf_sdio_sb_coredisable(struct brcmf_sdio_dev *sdiodev, |
Arend van Spriel | 9cf218f | 2014-01-13 22:20:27 +0100 | [diff] [blame] | 159 | struct brcmf_chip *ci, u16 coreid, u32 pre_resetbits, |
Hante Meuleman | 5303626 | 2014-01-13 22:20:23 +0100 | [diff] [blame] | 160 | u32 in_resetbits) |
Franky Lin | 2d4a9af | 2011-11-04 22:23:31 +0100 | [diff] [blame] | 161 | { |
Franky Lin | 79ae395 | 2012-05-04 18:27:34 -0700 | [diff] [blame] | 162 | u32 regdata, base; |
Franky Lin | 086a2e0 | 2011-11-10 20:30:23 +0100 | [diff] [blame] | 163 | u8 idx; |
| 164 | |
| 165 | idx = brcmf_sdio_chip_getinfidx(ci, coreid); |
Franky Lin | 79ae395 | 2012-05-04 18:27:34 -0700 | [diff] [blame] | 166 | base = ci->c_inf[idx].base; |
Franky Lin | 2d4a9af | 2011-11-04 22:23:31 +0100 | [diff] [blame] | 167 | |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 168 | regdata = brcmf_sdiod_regrl(sdiodev, CORE_SB(base, sbtmstatelow), NULL); |
Franky Lin | 61213be | 2011-11-04 22:23:41 +0100 | [diff] [blame] | 169 | if (regdata & SSB_TMSLOW_RESET) |
Franky Lin | 2d4a9af | 2011-11-04 22:23:31 +0100 | [diff] [blame] | 170 | return; |
| 171 | |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 172 | regdata = brcmf_sdiod_regrl(sdiodev, CORE_SB(base, sbtmstatelow), NULL); |
Franky Lin | 61213be | 2011-11-04 22:23:41 +0100 | [diff] [blame] | 173 | if ((regdata & SSB_TMSLOW_CLOCK) != 0) { |
Franky Lin | 2d4a9af | 2011-11-04 22:23:31 +0100 | [diff] [blame] | 174 | /* |
| 175 | * set target reject and spin until busy is clear |
| 176 | * (preserve core-specific bits) |
| 177 | */ |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 178 | regdata = brcmf_sdiod_regrl(sdiodev, |
| 179 | CORE_SB(base, sbtmstatelow), NULL); |
| 180 | brcmf_sdiod_regwl(sdiodev, CORE_SB(base, sbtmstatelow), |
| 181 | regdata | SSB_TMSLOW_REJECT, NULL); |
Franky Lin | 2d4a9af | 2011-11-04 22:23:31 +0100 | [diff] [blame] | 182 | |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 183 | regdata = brcmf_sdiod_regrl(sdiodev, |
| 184 | CORE_SB(base, sbtmstatelow), NULL); |
Franky Lin | 2d4a9af | 2011-11-04 22:23:31 +0100 | [diff] [blame] | 185 | udelay(1); |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 186 | SPINWAIT((brcmf_sdiod_regrl(sdiodev, |
| 187 | CORE_SB(base, sbtmstatehigh), |
| 188 | NULL) & |
| 189 | SSB_TMSHIGH_BUSY), 100000); |
Franky Lin | 2d4a9af | 2011-11-04 22:23:31 +0100 | [diff] [blame] | 190 | |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 191 | regdata = brcmf_sdiod_regrl(sdiodev, |
| 192 | CORE_SB(base, sbtmstatehigh), |
| 193 | NULL); |
Franky Lin | 61213be | 2011-11-04 22:23:41 +0100 | [diff] [blame] | 194 | if (regdata & SSB_TMSHIGH_BUSY) |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 195 | brcmf_err("core state still busy\n"); |
Franky Lin | 2d4a9af | 2011-11-04 22:23:31 +0100 | [diff] [blame] | 196 | |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 197 | regdata = brcmf_sdiod_regrl(sdiodev, CORE_SB(base, sbidlow), |
| 198 | NULL); |
Franky Lin | 61213be | 2011-11-04 22:23:41 +0100 | [diff] [blame] | 199 | if (regdata & SSB_IDLOW_INITIATOR) { |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 200 | regdata = brcmf_sdiod_regrl(sdiodev, |
| 201 | CORE_SB(base, sbimstate), |
| 202 | NULL); |
Franky Lin | 79ae395 | 2012-05-04 18:27:34 -0700 | [diff] [blame] | 203 | regdata |= SSB_IMSTATE_REJECT; |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 204 | brcmf_sdiod_regwl(sdiodev, CORE_SB(base, sbimstate), |
| 205 | regdata, NULL); |
| 206 | regdata = brcmf_sdiod_regrl(sdiodev, |
| 207 | CORE_SB(base, sbimstate), |
| 208 | NULL); |
Franky Lin | 2d4a9af | 2011-11-04 22:23:31 +0100 | [diff] [blame] | 209 | udelay(1); |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 210 | SPINWAIT((brcmf_sdiod_regrl(sdiodev, |
| 211 | CORE_SB(base, sbimstate), |
| 212 | NULL) & |
| 213 | SSB_IMSTATE_BUSY), 100000); |
Franky Lin | 2d4a9af | 2011-11-04 22:23:31 +0100 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | /* set reset and reject while enabling the clocks */ |
Franky Lin | e13ce26 | 2012-05-04 18:27:35 -0700 | [diff] [blame] | 217 | regdata = SSB_TMSLOW_FGC | SSB_TMSLOW_CLOCK | |
| 218 | SSB_TMSLOW_REJECT | SSB_TMSLOW_RESET; |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 219 | brcmf_sdiod_regwl(sdiodev, CORE_SB(base, sbtmstatelow), |
| 220 | regdata, NULL); |
| 221 | regdata = brcmf_sdiod_regrl(sdiodev, |
| 222 | CORE_SB(base, sbtmstatelow), NULL); |
Franky Lin | 2d4a9af | 2011-11-04 22:23:31 +0100 | [diff] [blame] | 223 | udelay(10); |
| 224 | |
| 225 | /* clear the initiator reject bit */ |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 226 | regdata = brcmf_sdiod_regrl(sdiodev, CORE_SB(base, sbidlow), |
| 227 | NULL); |
Franky Lin | 61213be | 2011-11-04 22:23:41 +0100 | [diff] [blame] | 228 | if (regdata & SSB_IDLOW_INITIATOR) { |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 229 | regdata = brcmf_sdiod_regrl(sdiodev, |
| 230 | CORE_SB(base, sbimstate), |
| 231 | NULL); |
Franky Lin | 79ae395 | 2012-05-04 18:27:34 -0700 | [diff] [blame] | 232 | regdata &= ~SSB_IMSTATE_REJECT; |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 233 | brcmf_sdiod_regwl(sdiodev, CORE_SB(base, sbimstate), |
| 234 | regdata, NULL); |
Franky Lin | 2d4a9af | 2011-11-04 22:23:31 +0100 | [diff] [blame] | 235 | } |
| 236 | } |
| 237 | |
| 238 | /* leave reset and reject asserted */ |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 239 | brcmf_sdiod_regwl(sdiodev, CORE_SB(base, sbtmstatelow), |
| 240 | (SSB_TMSLOW_REJECT | SSB_TMSLOW_RESET), NULL); |
Franky Lin | 2d4a9af | 2011-11-04 22:23:31 +0100 | [diff] [blame] | 241 | udelay(1); |
| 242 | } |
| 243 | |
Franky Lin | 086a2e0 | 2011-11-10 20:30:23 +0100 | [diff] [blame] | 244 | static void |
| 245 | brcmf_sdio_ai_coredisable(struct brcmf_sdio_dev *sdiodev, |
Arend van Spriel | 9cf218f | 2014-01-13 22:20:27 +0100 | [diff] [blame] | 246 | struct brcmf_chip *ci, u16 coreid, u32 pre_resetbits, |
Hante Meuleman | 5303626 | 2014-01-13 22:20:23 +0100 | [diff] [blame] | 247 | u32 in_resetbits) |
Franky Lin | 086a2e0 | 2011-11-10 20:30:23 +0100 | [diff] [blame] | 248 | { |
| 249 | u8 idx; |
| 250 | u32 regdata; |
Hante Meuleman | 5303626 | 2014-01-13 22:20:23 +0100 | [diff] [blame] | 251 | u32 wrapbase; |
Franky Lin | 086a2e0 | 2011-11-10 20:30:23 +0100 | [diff] [blame] | 252 | |
| 253 | idx = brcmf_sdio_chip_getinfidx(ci, coreid); |
Franky Lin | 7434785 | 2013-09-25 13:05:42 +0200 | [diff] [blame] | 254 | if (idx == BRCMF_MAX_CORENUM) |
| 255 | return; |
Franky Lin | 086a2e0 | 2011-11-10 20:30:23 +0100 | [diff] [blame] | 256 | |
Hante Meuleman | 5303626 | 2014-01-13 22:20:23 +0100 | [diff] [blame] | 257 | wrapbase = ci->c_inf[idx].wrapbase; |
| 258 | |
Franky Lin | 086a2e0 | 2011-11-10 20:30:23 +0100 | [diff] [blame] | 259 | /* if core is already in reset, just return */ |
Hante Meuleman | 5303626 | 2014-01-13 22:20:23 +0100 | [diff] [blame] | 260 | regdata = brcmf_sdiod_regrl(sdiodev, wrapbase + BCMA_RESET_CTL, NULL); |
Franky Lin | 086a2e0 | 2011-11-10 20:30:23 +0100 | [diff] [blame] | 261 | if ((regdata & BCMA_RESET_CTL_RESET) != 0) |
| 262 | return; |
| 263 | |
Hante Meuleman | 5303626 | 2014-01-13 22:20:23 +0100 | [diff] [blame] | 264 | /* configure reset */ |
| 265 | brcmf_sdiod_regwl(sdiodev, wrapbase + BCMA_IOCTL, pre_resetbits | |
| 266 | BCMA_IOCTL_FGC | BCMA_IOCTL_CLK, NULL); |
| 267 | regdata = brcmf_sdiod_regrl(sdiodev, wrapbase + BCMA_IOCTL, NULL); |
Franky Lin | 086a2e0 | 2011-11-10 20:30:23 +0100 | [diff] [blame] | 268 | |
Hante Meuleman | 5303626 | 2014-01-13 22:20:23 +0100 | [diff] [blame] | 269 | /* put in reset */ |
| 270 | brcmf_sdiod_regwl(sdiodev, wrapbase + BCMA_RESET_CTL, |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 271 | BCMA_RESET_CTL_RESET, NULL); |
Franky Lin | 1640f28 | 2013-04-11 13:28:51 +0200 | [diff] [blame] | 272 | usleep_range(10, 20); |
| 273 | |
Hante Meuleman | 5303626 | 2014-01-13 22:20:23 +0100 | [diff] [blame] | 274 | /* wait till reset is 1 */ |
| 275 | SPINWAIT(brcmf_sdiod_regrl(sdiodev, wrapbase + BCMA_RESET_CTL, NULL) != |
| 276 | BCMA_RESET_CTL_RESET, 300); |
| 277 | |
| 278 | /* post reset configure */ |
| 279 | brcmf_sdiod_regwl(sdiodev, wrapbase + BCMA_IOCTL, pre_resetbits | |
| 280 | BCMA_IOCTL_FGC | BCMA_IOCTL_CLK, NULL); |
| 281 | regdata = brcmf_sdiod_regrl(sdiodev, wrapbase + BCMA_IOCTL, NULL); |
Franky Lin | 086a2e0 | 2011-11-10 20:30:23 +0100 | [diff] [blame] | 282 | } |
| 283 | |
Franky Lin | d77e70f | 2011-11-10 20:30:24 +0100 | [diff] [blame] | 284 | static void |
| 285 | brcmf_sdio_sb_resetcore(struct brcmf_sdio_dev *sdiodev, |
Arend van Spriel | 9cf218f | 2014-01-13 22:20:27 +0100 | [diff] [blame] | 286 | struct brcmf_chip *ci, u16 coreid, u32 pre_resetbits, |
Hante Meuleman | 5303626 | 2014-01-13 22:20:23 +0100 | [diff] [blame] | 287 | u32 in_resetbits, u32 post_resetbits) |
Franky Lin | 2bc78e1 | 2011-11-04 22:23:38 +0100 | [diff] [blame] | 288 | { |
| 289 | u32 regdata; |
Franky Lin | 086a2e0 | 2011-11-10 20:30:23 +0100 | [diff] [blame] | 290 | u8 idx; |
| 291 | |
| 292 | idx = brcmf_sdio_chip_getinfidx(ci, coreid); |
Franky Lin | 7434785 | 2013-09-25 13:05:42 +0200 | [diff] [blame] | 293 | if (idx == BRCMF_MAX_CORENUM) |
| 294 | return; |
Franky Lin | 2bc78e1 | 2011-11-04 22:23:38 +0100 | [diff] [blame] | 295 | |
| 296 | /* |
| 297 | * Must do the disable sequence first to work for |
| 298 | * arbitrary current core state. |
| 299 | */ |
Hante Meuleman | 5303626 | 2014-01-13 22:20:23 +0100 | [diff] [blame] | 300 | brcmf_sdio_sb_coredisable(sdiodev, ci, coreid, pre_resetbits, |
| 301 | in_resetbits); |
Franky Lin | 2bc78e1 | 2011-11-04 22:23:38 +0100 | [diff] [blame] | 302 | |
| 303 | /* |
| 304 | * Now do the initialization sequence. |
| 305 | * set reset while enabling the clock and |
| 306 | * forcing them on throughout the core |
| 307 | */ |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 308 | brcmf_sdiod_regwl(sdiodev, |
| 309 | CORE_SB(ci->c_inf[idx].base, sbtmstatelow), |
| 310 | SSB_TMSLOW_FGC | SSB_TMSLOW_CLOCK | SSB_TMSLOW_RESET, |
| 311 | NULL); |
| 312 | regdata = brcmf_sdiod_regrl(sdiodev, |
| 313 | CORE_SB(ci->c_inf[idx].base, sbtmstatelow), |
| 314 | NULL); |
Franky Lin | 2bc78e1 | 2011-11-04 22:23:38 +0100 | [diff] [blame] | 315 | udelay(1); |
| 316 | |
Franky Lin | d77e70f | 2011-11-10 20:30:24 +0100 | [diff] [blame] | 317 | /* clear any serror */ |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 318 | regdata = brcmf_sdiod_regrl(sdiodev, |
| 319 | CORE_SB(ci->c_inf[idx].base, sbtmstatehigh), |
| 320 | NULL); |
Franky Lin | 61213be | 2011-11-04 22:23:41 +0100 | [diff] [blame] | 321 | if (regdata & SSB_TMSHIGH_SERR) |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 322 | brcmf_sdiod_regwl(sdiodev, |
| 323 | CORE_SB(ci->c_inf[idx].base, sbtmstatehigh), |
| 324 | 0, NULL); |
Franky Lin | 2bc78e1 | 2011-11-04 22:23:38 +0100 | [diff] [blame] | 325 | |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 326 | regdata = brcmf_sdiod_regrl(sdiodev, |
| 327 | CORE_SB(ci->c_inf[idx].base, sbimstate), |
| 328 | NULL); |
Franky Lin | 61213be | 2011-11-04 22:23:41 +0100 | [diff] [blame] | 329 | if (regdata & (SSB_IMSTATE_IBE | SSB_IMSTATE_TO)) |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 330 | brcmf_sdiod_regwl(sdiodev, |
| 331 | CORE_SB(ci->c_inf[idx].base, sbimstate), |
| 332 | regdata & ~(SSB_IMSTATE_IBE | SSB_IMSTATE_TO), |
| 333 | NULL); |
Franky Lin | 2bc78e1 | 2011-11-04 22:23:38 +0100 | [diff] [blame] | 334 | |
| 335 | /* clear reset and allow it to propagate throughout the core */ |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 336 | brcmf_sdiod_regwl(sdiodev, CORE_SB(ci->c_inf[idx].base, sbtmstatelow), |
| 337 | SSB_TMSLOW_FGC | SSB_TMSLOW_CLOCK, NULL); |
| 338 | regdata = brcmf_sdiod_regrl(sdiodev, |
| 339 | CORE_SB(ci->c_inf[idx].base, sbtmstatelow), |
| 340 | NULL); |
Franky Lin | 2bc78e1 | 2011-11-04 22:23:38 +0100 | [diff] [blame] | 341 | udelay(1); |
| 342 | |
| 343 | /* leave clock enabled */ |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 344 | brcmf_sdiod_regwl(sdiodev, CORE_SB(ci->c_inf[idx].base, sbtmstatelow), |
| 345 | SSB_TMSLOW_CLOCK, NULL); |
| 346 | regdata = brcmf_sdiod_regrl(sdiodev, |
| 347 | CORE_SB(ci->c_inf[idx].base, sbtmstatelow), |
| 348 | NULL); |
Franky Lin | d77e70f | 2011-11-10 20:30:24 +0100 | [diff] [blame] | 349 | udelay(1); |
| 350 | } |
| 351 | |
| 352 | static void |
| 353 | brcmf_sdio_ai_resetcore(struct brcmf_sdio_dev *sdiodev, |
Arend van Spriel | 9cf218f | 2014-01-13 22:20:27 +0100 | [diff] [blame] | 354 | struct brcmf_chip *ci, u16 coreid, u32 pre_resetbits, |
Hante Meuleman | 5303626 | 2014-01-13 22:20:23 +0100 | [diff] [blame] | 355 | u32 in_resetbits, u32 post_resetbits) |
Franky Lin | d77e70f | 2011-11-10 20:30:24 +0100 | [diff] [blame] | 356 | { |
| 357 | u8 idx; |
| 358 | u32 regdata; |
Hante Meuleman | 5303626 | 2014-01-13 22:20:23 +0100 | [diff] [blame] | 359 | u32 wrapbase; |
Franky Lin | d77e70f | 2011-11-10 20:30:24 +0100 | [diff] [blame] | 360 | |
| 361 | idx = brcmf_sdio_chip_getinfidx(ci, coreid); |
Franky Lin | 7434785 | 2013-09-25 13:05:42 +0200 | [diff] [blame] | 362 | if (idx == BRCMF_MAX_CORENUM) |
| 363 | return; |
Franky Lin | d77e70f | 2011-11-10 20:30:24 +0100 | [diff] [blame] | 364 | |
Hante Meuleman | 5303626 | 2014-01-13 22:20:23 +0100 | [diff] [blame] | 365 | wrapbase = ci->c_inf[idx].wrapbase; |
| 366 | |
Franky Lin | d77e70f | 2011-11-10 20:30:24 +0100 | [diff] [blame] | 367 | /* must disable first to work for arbitrary current core state */ |
Hante Meuleman | 5303626 | 2014-01-13 22:20:23 +0100 | [diff] [blame] | 368 | brcmf_sdio_ai_coredisable(sdiodev, ci, coreid, pre_resetbits, |
| 369 | in_resetbits); |
Franky Lin | d77e70f | 2011-11-10 20:30:24 +0100 | [diff] [blame] | 370 | |
Hante Meuleman | 5303626 | 2014-01-13 22:20:23 +0100 | [diff] [blame] | 371 | while (brcmf_sdiod_regrl(sdiodev, wrapbase + BCMA_RESET_CTL, NULL) & |
| 372 | BCMA_RESET_CTL_RESET) { |
| 373 | brcmf_sdiod_regwl(sdiodev, wrapbase + BCMA_RESET_CTL, 0, NULL); |
| 374 | usleep_range(40, 60); |
| 375 | } |
Franky Lin | d77e70f | 2011-11-10 20:30:24 +0100 | [diff] [blame] | 376 | |
Hante Meuleman | 5303626 | 2014-01-13 22:20:23 +0100 | [diff] [blame] | 377 | brcmf_sdiod_regwl(sdiodev, wrapbase + BCMA_IOCTL, post_resetbits | |
| 378 | BCMA_IOCTL_CLK, NULL); |
| 379 | regdata = brcmf_sdiod_regrl(sdiodev, wrapbase + BCMA_IOCTL, NULL); |
Franky Lin | 2bc78e1 | 2011-11-04 22:23:38 +0100 | [diff] [blame] | 380 | } |
| 381 | |
Franky Lin | 1640f28 | 2013-04-11 13:28:51 +0200 | [diff] [blame] | 382 | #ifdef DEBUG |
| 383 | /* safety check for chipinfo */ |
Arend van Spriel | 9cf218f | 2014-01-13 22:20:27 +0100 | [diff] [blame] | 384 | static int brcmf_sdio_chip_cichk(struct brcmf_chip *ci) |
Franky Lin | 1640f28 | 2013-04-11 13:28:51 +0200 | [diff] [blame] | 385 | { |
| 386 | u8 core_idx; |
| 387 | |
| 388 | /* check RAM core presence for ARM CM3 core */ |
| 389 | core_idx = brcmf_sdio_chip_getinfidx(ci, BCMA_CORE_ARM_CM3); |
| 390 | if (BRCMF_MAX_CORENUM != core_idx) { |
| 391 | core_idx = brcmf_sdio_chip_getinfidx(ci, |
| 392 | BCMA_CORE_INTERNAL_MEM); |
| 393 | if (BRCMF_MAX_CORENUM == core_idx) { |
| 394 | brcmf_err("RAM core not provided with ARM CM3 core\n"); |
| 395 | return -ENODEV; |
| 396 | } |
| 397 | } |
| 398 | |
| 399 | /* check RAM base for ARM CR4 core */ |
| 400 | core_idx = brcmf_sdio_chip_getinfidx(ci, BCMA_CORE_ARM_CR4); |
| 401 | if (BRCMF_MAX_CORENUM != core_idx) { |
| 402 | if (ci->rambase == 0) { |
| 403 | brcmf_err("RAM base not provided with ARM CR4 core\n"); |
| 404 | return -ENOMEM; |
| 405 | } |
| 406 | } |
| 407 | |
| 408 | return 0; |
| 409 | } |
| 410 | #else /* DEBUG */ |
Arend van Spriel | 9cf218f | 2014-01-13 22:20:27 +0100 | [diff] [blame] | 411 | static inline int brcmf_sdio_chip_cichk(struct brcmf_chip *ci) |
Franky Lin | 1640f28 | 2013-04-11 13:28:51 +0200 | [diff] [blame] | 412 | { |
| 413 | return 0; |
| 414 | } |
| 415 | #endif |
| 416 | |
Franky Lin | a83369b | 2011-11-04 22:23:28 +0100 | [diff] [blame] | 417 | static int brcmf_sdio_chip_recognition(struct brcmf_sdio_dev *sdiodev, |
Arend van Spriel | 9cf218f | 2014-01-13 22:20:27 +0100 | [diff] [blame] | 418 | struct brcmf_chip *ci) |
Franky Lin | a83369b | 2011-11-04 22:23:28 +0100 | [diff] [blame] | 419 | { |
| 420 | u32 regdata; |
Arend van Spriel | c805eeb | 2014-01-13 22:20:26 +0100 | [diff] [blame] | 421 | u32 socitype; |
Franky Lin | a83369b | 2011-11-04 22:23:28 +0100 | [diff] [blame] | 422 | |
Franky Lin | 069eddd | 2013-04-11 13:28:48 +0200 | [diff] [blame] | 423 | /* Get CC core rev |
Arend van Spriel | c805eeb | 2014-01-13 22:20:26 +0100 | [diff] [blame] | 424 | * Chipid is assume to be at offset 0 from SI_ENUM_BASE |
Franky Lin | a83369b | 2011-11-04 22:23:28 +0100 | [diff] [blame] | 425 | * For different chiptypes or old sdio hosts w/o chipcommon, |
| 426 | * other ways of recognition should be added here. |
| 427 | */ |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 428 | regdata = brcmf_sdiod_regrl(sdiodev, |
Arend van Spriel | c805eeb | 2014-01-13 22:20:26 +0100 | [diff] [blame] | 429 | CORE_CC_REG(SI_ENUM_BASE, chipid), |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 430 | NULL); |
Franky Lin | a83369b | 2011-11-04 22:23:28 +0100 | [diff] [blame] | 431 | ci->chip = regdata & CID_ID_MASK; |
| 432 | ci->chiprev = (regdata & CID_REV_MASK) >> CID_REV_SHIFT; |
Franky Lin | fe04015 | 2013-09-25 13:05:41 +0200 | [diff] [blame] | 433 | if (sdiodev->func[0]->device == SDIO_DEVICE_ID_BROADCOM_4335_4339 && |
| 434 | ci->chiprev >= 2) |
| 435 | ci->chip = BCM4339_CHIP_ID; |
Arend van Spriel | c805eeb | 2014-01-13 22:20:26 +0100 | [diff] [blame] | 436 | socitype = (regdata & CID_TYPE_MASK) >> CID_TYPE_SHIFT; |
Franky Lin | a83369b | 2011-11-04 22:23:28 +0100 | [diff] [blame] | 437 | |
Arend van Spriel | c805eeb | 2014-01-13 22:20:26 +0100 | [diff] [blame] | 438 | brcmf_dbg(INFO, "found %s chip: id=0x%x, rev=%d\n", |
| 439 | socitype == SOCI_SB ? "SB" : "AXI", ci->chip, ci->chiprev); |
Franky Lin | a83369b | 2011-11-04 22:23:28 +0100 | [diff] [blame] | 440 | |
Arend van Spriel | c805eeb | 2014-01-13 22:20:26 +0100 | [diff] [blame] | 441 | if (socitype == SOCI_SB) { |
| 442 | if (ci->chip != BCM4329_CHIP_ID) { |
| 443 | brcmf_err("SB chip is not supported\n"); |
| 444 | return -ENODEV; |
| 445 | } |
| 446 | ci->iscoreup = brcmf_sdio_sb_iscoreup; |
| 447 | ci->corerev = brcmf_sdio_sb_corerev; |
| 448 | ci->coredisable = brcmf_sdio_sb_coredisable; |
| 449 | ci->resetcore = brcmf_sdio_sb_resetcore; |
| 450 | |
| 451 | ci->c_inf[0].id = BCMA_CORE_CHIPCOMMON; |
| 452 | ci->c_inf[0].base = SI_ENUM_BASE; |
Franky Lin | 99ba15c | 2011-11-04 22:23:42 +0100 | [diff] [blame] | 453 | ci->c_inf[1].id = BCMA_CORE_SDIO_DEV; |
| 454 | ci->c_inf[1].base = BCM4329_CORE_BUS_BASE; |
| 455 | ci->c_inf[2].id = BCMA_CORE_INTERNAL_MEM; |
| 456 | ci->c_inf[2].base = BCM4329_CORE_SOCRAM_BASE; |
| 457 | ci->c_inf[3].id = BCMA_CORE_ARM_CM3; |
| 458 | ci->c_inf[3].base = BCM4329_CORE_ARM_BASE; |
Hante Meuleman | 5303626 | 2014-01-13 22:20:23 +0100 | [diff] [blame] | 459 | ci->c_inf[4].id = BCMA_CORE_80211; |
| 460 | ci->c_inf[4].base = BCM43xx_CORE_D11_BASE; |
Franky Lin | a83369b | 2011-11-04 22:23:28 +0100 | [diff] [blame] | 461 | ci->ramsize = BCM4329_RAMSIZE; |
Arend van Spriel | c805eeb | 2014-01-13 22:20:26 +0100 | [diff] [blame] | 462 | } else if (socitype == SOCI_AI) { |
Franky Lin | 6ca687d | 2011-11-10 20:30:21 +0100 | [diff] [blame] | 463 | ci->iscoreup = brcmf_sdio_ai_iscoreup; |
Franky Lin | 523894f | 2011-11-10 20:30:22 +0100 | [diff] [blame] | 464 | ci->corerev = brcmf_sdio_ai_corerev; |
Franky Lin | 086a2e0 | 2011-11-10 20:30:23 +0100 | [diff] [blame] | 465 | ci->coredisable = brcmf_sdio_ai_coredisable; |
Franky Lin | d77e70f | 2011-11-10 20:30:24 +0100 | [diff] [blame] | 466 | ci->resetcore = brcmf_sdio_ai_resetcore; |
Arend van Spriel | c805eeb | 2014-01-13 22:20:26 +0100 | [diff] [blame] | 467 | |
| 468 | ci->c_inf[0].id = BCMA_CORE_CHIPCOMMON; |
| 469 | ci->c_inf[0].base = SI_ENUM_BASE; |
| 470 | |
| 471 | /* Address of cores for new chips should be added here */ |
| 472 | switch (ci->chip) { |
| 473 | case BCM43143_CHIP_ID: |
| 474 | ci->c_inf[0].wrapbase = ci->c_inf[0].base + 0x00100000; |
| 475 | ci->c_inf[0].cib = 0x2b000000; |
| 476 | ci->c_inf[1].id = BCMA_CORE_SDIO_DEV; |
| 477 | ci->c_inf[1].base = BCM43143_CORE_BUS_BASE; |
| 478 | ci->c_inf[1].wrapbase = ci->c_inf[1].base + 0x00100000; |
| 479 | ci->c_inf[1].cib = 0x18000000; |
| 480 | ci->c_inf[2].id = BCMA_CORE_INTERNAL_MEM; |
| 481 | ci->c_inf[2].base = BCM43143_CORE_SOCRAM_BASE; |
| 482 | ci->c_inf[2].wrapbase = ci->c_inf[2].base + 0x00100000; |
| 483 | ci->c_inf[2].cib = 0x14000000; |
| 484 | ci->c_inf[3].id = BCMA_CORE_ARM_CM3; |
| 485 | ci->c_inf[3].base = BCM43143_CORE_ARM_BASE; |
| 486 | ci->c_inf[3].wrapbase = ci->c_inf[3].base + 0x00100000; |
| 487 | ci->c_inf[3].cib = 0x07000000; |
| 488 | ci->c_inf[4].id = BCMA_CORE_80211; |
| 489 | ci->c_inf[4].base = BCM43xx_CORE_D11_BASE; |
| 490 | ci->c_inf[4].wrapbase = ci->c_inf[4].base + 0x00100000; |
| 491 | ci->ramsize = BCM43143_RAMSIZE; |
| 492 | break; |
| 493 | case BCM43241_CHIP_ID: |
| 494 | ci->c_inf[0].wrapbase = 0x18100000; |
| 495 | ci->c_inf[0].cib = 0x2a084411; |
| 496 | ci->c_inf[1].id = BCMA_CORE_SDIO_DEV; |
| 497 | ci->c_inf[1].base = 0x18002000; |
| 498 | ci->c_inf[1].wrapbase = 0x18102000; |
| 499 | ci->c_inf[1].cib = 0x0e004211; |
| 500 | ci->c_inf[2].id = BCMA_CORE_INTERNAL_MEM; |
| 501 | ci->c_inf[2].base = 0x18004000; |
| 502 | ci->c_inf[2].wrapbase = 0x18104000; |
| 503 | ci->c_inf[2].cib = 0x14080401; |
| 504 | ci->c_inf[3].id = BCMA_CORE_ARM_CM3; |
| 505 | ci->c_inf[3].base = 0x18003000; |
| 506 | ci->c_inf[3].wrapbase = 0x18103000; |
| 507 | ci->c_inf[3].cib = 0x07004211; |
| 508 | ci->c_inf[4].id = BCMA_CORE_80211; |
| 509 | ci->c_inf[4].base = BCM43xx_CORE_D11_BASE; |
| 510 | ci->c_inf[4].wrapbase = ci->c_inf[4].base + 0x00100000; |
| 511 | ci->ramsize = 0x90000; |
| 512 | break; |
| 513 | case BCM4330_CHIP_ID: |
| 514 | ci->c_inf[0].wrapbase = 0x18100000; |
| 515 | ci->c_inf[0].cib = 0x27004211; |
| 516 | ci->c_inf[1].id = BCMA_CORE_SDIO_DEV; |
| 517 | ci->c_inf[1].base = 0x18002000; |
| 518 | ci->c_inf[1].wrapbase = 0x18102000; |
| 519 | ci->c_inf[1].cib = 0x07004211; |
| 520 | ci->c_inf[2].id = BCMA_CORE_INTERNAL_MEM; |
| 521 | ci->c_inf[2].base = 0x18004000; |
| 522 | ci->c_inf[2].wrapbase = 0x18104000; |
| 523 | ci->c_inf[2].cib = 0x0d080401; |
| 524 | ci->c_inf[3].id = BCMA_CORE_ARM_CM3; |
| 525 | ci->c_inf[3].base = 0x18003000; |
| 526 | ci->c_inf[3].wrapbase = 0x18103000; |
| 527 | ci->c_inf[3].cib = 0x03004211; |
| 528 | ci->c_inf[4].id = BCMA_CORE_80211; |
| 529 | ci->c_inf[4].base = BCM43xx_CORE_D11_BASE; |
| 530 | ci->c_inf[4].wrapbase = ci->c_inf[4].base + 0x00100000; |
| 531 | ci->ramsize = 0x48000; |
| 532 | break; |
| 533 | case BCM4334_CHIP_ID: |
| 534 | ci->c_inf[0].wrapbase = 0x18100000; |
| 535 | ci->c_inf[0].cib = 0x29004211; |
| 536 | ci->c_inf[1].id = BCMA_CORE_SDIO_DEV; |
| 537 | ci->c_inf[1].base = 0x18002000; |
| 538 | ci->c_inf[1].wrapbase = 0x18102000; |
| 539 | ci->c_inf[1].cib = 0x0d004211; |
| 540 | ci->c_inf[2].id = BCMA_CORE_INTERNAL_MEM; |
| 541 | ci->c_inf[2].base = 0x18004000; |
| 542 | ci->c_inf[2].wrapbase = 0x18104000; |
| 543 | ci->c_inf[2].cib = 0x13080401; |
| 544 | ci->c_inf[3].id = BCMA_CORE_ARM_CM3; |
| 545 | ci->c_inf[3].base = 0x18003000; |
| 546 | ci->c_inf[3].wrapbase = 0x18103000; |
| 547 | ci->c_inf[3].cib = 0x07004211; |
| 548 | ci->c_inf[4].id = BCMA_CORE_80211; |
| 549 | ci->c_inf[4].base = BCM43xx_CORE_D11_BASE; |
| 550 | ci->c_inf[4].wrapbase = ci->c_inf[4].base + 0x00100000; |
| 551 | ci->ramsize = 0x80000; |
| 552 | break; |
| 553 | case BCM4335_CHIP_ID: |
| 554 | ci->c_inf[0].wrapbase = 0x18100000; |
| 555 | ci->c_inf[0].cib = 0x2b084411; |
| 556 | ci->c_inf[1].id = BCMA_CORE_SDIO_DEV; |
| 557 | ci->c_inf[1].base = 0x18005000; |
| 558 | ci->c_inf[1].wrapbase = 0x18105000; |
| 559 | ci->c_inf[1].cib = 0x0f004211; |
| 560 | ci->c_inf[2].id = BCMA_CORE_ARM_CR4; |
| 561 | ci->c_inf[2].base = 0x18002000; |
| 562 | ci->c_inf[2].wrapbase = 0x18102000; |
| 563 | ci->c_inf[2].cib = 0x01084411; |
| 564 | ci->c_inf[3].id = BCMA_CORE_80211; |
| 565 | ci->c_inf[3].base = BCM43xx_CORE_D11_BASE; |
| 566 | ci->c_inf[3].wrapbase = ci->c_inf[3].base + 0x00100000; |
| 567 | ci->ramsize = 0xc0000; |
| 568 | ci->rambase = 0x180000; |
| 569 | break; |
| 570 | case BCM43362_CHIP_ID: |
| 571 | ci->c_inf[0].wrapbase = 0x18100000; |
| 572 | ci->c_inf[0].cib = 0x27004211; |
| 573 | ci->c_inf[1].id = BCMA_CORE_SDIO_DEV; |
| 574 | ci->c_inf[1].base = 0x18002000; |
| 575 | ci->c_inf[1].wrapbase = 0x18102000; |
| 576 | ci->c_inf[1].cib = 0x0a004211; |
| 577 | ci->c_inf[2].id = BCMA_CORE_INTERNAL_MEM; |
| 578 | ci->c_inf[2].base = 0x18004000; |
| 579 | ci->c_inf[2].wrapbase = 0x18104000; |
| 580 | ci->c_inf[2].cib = 0x08080401; |
| 581 | ci->c_inf[3].id = BCMA_CORE_ARM_CM3; |
| 582 | ci->c_inf[3].base = 0x18003000; |
| 583 | ci->c_inf[3].wrapbase = 0x18103000; |
| 584 | ci->c_inf[3].cib = 0x03004211; |
| 585 | ci->c_inf[4].id = BCMA_CORE_80211; |
| 586 | ci->c_inf[4].base = BCM43xx_CORE_D11_BASE; |
| 587 | ci->c_inf[4].wrapbase = ci->c_inf[4].base + 0x00100000; |
| 588 | ci->ramsize = 0x3C000; |
| 589 | break; |
| 590 | case BCM4339_CHIP_ID: |
| 591 | ci->c_inf[0].wrapbase = 0x18100000; |
| 592 | ci->c_inf[0].cib = 0x2e084411; |
| 593 | ci->c_inf[1].id = BCMA_CORE_SDIO_DEV; |
| 594 | ci->c_inf[1].base = 0x18005000; |
| 595 | ci->c_inf[1].wrapbase = 0x18105000; |
| 596 | ci->c_inf[1].cib = 0x15004211; |
| 597 | ci->c_inf[2].id = BCMA_CORE_ARM_CR4; |
| 598 | ci->c_inf[2].base = 0x18002000; |
| 599 | ci->c_inf[2].wrapbase = 0x18102000; |
| 600 | ci->c_inf[2].cib = 0x04084411; |
| 601 | ci->c_inf[3].id = BCMA_CORE_80211; |
| 602 | ci->c_inf[3].base = BCM43xx_CORE_D11_BASE; |
| 603 | ci->c_inf[3].wrapbase = ci->c_inf[3].base + 0x00100000; |
| 604 | ci->ramsize = 0xc0000; |
| 605 | ci->rambase = 0x180000; |
| 606 | break; |
| 607 | default: |
| 608 | brcmf_err("AXI chip is not supported\n"); |
| 609 | return -ENODEV; |
| 610 | } |
| 611 | } else { |
| 612 | brcmf_err("chip backplane type %u is not supported\n", |
| 613 | socitype); |
Franky Lin | 6ca687d | 2011-11-10 20:30:21 +0100 | [diff] [blame] | 614 | return -ENODEV; |
| 615 | } |
| 616 | |
Arend van Spriel | c805eeb | 2014-01-13 22:20:26 +0100 | [diff] [blame] | 617 | return brcmf_sdio_chip_cichk(ci); |
Franky Lin | a83369b | 2011-11-04 22:23:28 +0100 | [diff] [blame] | 618 | } |
| 619 | |
Franky Lin | 5b45e54 | 2011-11-04 22:23:30 +0100 | [diff] [blame] | 620 | static void |
| 621 | brcmf_sdio_chip_buscoresetup(struct brcmf_sdio_dev *sdiodev, |
Arend van Spriel | 9cf218f | 2014-01-13 22:20:27 +0100 | [diff] [blame] | 622 | struct brcmf_chip *ci) |
Franky Lin | 5b45e54 | 2011-11-04 22:23:30 +0100 | [diff] [blame] | 623 | { |
Franky Lin | 79ae395 | 2012-05-04 18:27:34 -0700 | [diff] [blame] | 624 | u32 base = ci->c_inf[0].base; |
| 625 | |
Franky Lin | 5b45e54 | 2011-11-04 22:23:30 +0100 | [diff] [blame] | 626 | /* get chipcommon rev */ |
Franky Lin | 523894f | 2011-11-10 20:30:22 +0100 | [diff] [blame] | 627 | ci->c_inf[0].rev = ci->corerev(sdiodev, ci, ci->c_inf[0].id); |
Franky Lin | 5b45e54 | 2011-11-04 22:23:30 +0100 | [diff] [blame] | 628 | |
| 629 | /* get chipcommon capabilites */ |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 630 | ci->c_inf[0].caps = brcmf_sdiod_regrl(sdiodev, |
| 631 | CORE_CC_REG(base, capabilities), |
| 632 | NULL); |
Franky Lin | 5b45e54 | 2011-11-04 22:23:30 +0100 | [diff] [blame] | 633 | |
| 634 | /* get pmu caps & rev */ |
Franky Lin | 99ba15c | 2011-11-04 22:23:42 +0100 | [diff] [blame] | 635 | if (ci->c_inf[0].caps & CC_CAP_PMU) { |
Franky Lin | 79ae395 | 2012-05-04 18:27:34 -0700 | [diff] [blame] | 636 | ci->pmucaps = |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 637 | brcmf_sdiod_regrl(sdiodev, |
| 638 | CORE_CC_REG(base, pmucapabilities), |
| 639 | NULL); |
Franky Lin | 5b45e54 | 2011-11-04 22:23:30 +0100 | [diff] [blame] | 640 | ci->pmurev = ci->pmucaps & PCAP_REV_MASK; |
| 641 | } |
| 642 | |
Franky Lin | 523894f | 2011-11-10 20:30:22 +0100 | [diff] [blame] | 643 | ci->c_inf[1].rev = ci->corerev(sdiodev, ci, ci->c_inf[1].id); |
Franky Lin | 5b45e54 | 2011-11-04 22:23:30 +0100 | [diff] [blame] | 644 | |
| 645 | brcmf_dbg(INFO, "ccrev=%d, pmurev=%d, buscore rev/type=%d/0x%x\n", |
Franky Lin | 99ba15c | 2011-11-04 22:23:42 +0100 | [diff] [blame] | 646 | ci->c_inf[0].rev, ci->pmurev, |
| 647 | ci->c_inf[1].rev, ci->c_inf[1].id); |
Franky Lin | 966414d | 2011-11-04 22:23:32 +0100 | [diff] [blame] | 648 | |
| 649 | /* |
| 650 | * Make sure any on-chip ARM is off (in case strapping is wrong), |
| 651 | * or downloaded code was already running. |
| 652 | */ |
Hante Meuleman | 5303626 | 2014-01-13 22:20:23 +0100 | [diff] [blame] | 653 | ci->coredisable(sdiodev, ci, BCMA_CORE_ARM_CM3, 0, 0); |
Franky Lin | 5b45e54 | 2011-11-04 22:23:30 +0100 | [diff] [blame] | 654 | } |
| 655 | |
Franky Lin | a83369b | 2011-11-04 22:23:28 +0100 | [diff] [blame] | 656 | int brcmf_sdio_chip_attach(struct brcmf_sdio_dev *sdiodev, |
Arend van Spriel | 9cf218f | 2014-01-13 22:20:27 +0100 | [diff] [blame] | 657 | struct brcmf_chip **ci_ptr) |
Franky Lin | a83369b | 2011-11-04 22:23:28 +0100 | [diff] [blame] | 658 | { |
Franky Lin | a97e4fc | 2011-11-04 22:23:35 +0100 | [diff] [blame] | 659 | int ret; |
Arend van Spriel | 9cf218f | 2014-01-13 22:20:27 +0100 | [diff] [blame] | 660 | struct brcmf_chip *ci; |
Franky Lin | a97e4fc | 2011-11-04 22:23:35 +0100 | [diff] [blame] | 661 | |
| 662 | brcmf_dbg(TRACE, "Enter\n"); |
| 663 | |
Arend van Spriel | 9cf218f | 2014-01-13 22:20:27 +0100 | [diff] [blame] | 664 | ci = kzalloc(sizeof(*ci), GFP_ATOMIC); |
Franky Lin | a97e4fc | 2011-11-04 22:23:35 +0100 | [diff] [blame] | 665 | if (!ci) |
| 666 | return -ENOMEM; |
Franky Lin | a83369b | 2011-11-04 22:23:28 +0100 | [diff] [blame] | 667 | |
Arend van Spriel | 65d80d0 | 2014-01-29 15:32:14 +0100 | [diff] [blame] | 668 | ret = brcmf_sdio_buscoreprep(sdiodev); |
Franky Lin | e63ac6b | 2011-11-04 22:23:29 +0100 | [diff] [blame] | 669 | if (ret != 0) |
Franky Lin | a97e4fc | 2011-11-04 22:23:35 +0100 | [diff] [blame] | 670 | goto err; |
Franky Lin | e63ac6b | 2011-11-04 22:23:29 +0100 | [diff] [blame] | 671 | |
Arend van Spriel | 4744d16 | 2013-12-12 11:58:55 +0100 | [diff] [blame] | 672 | ret = brcmf_sdio_chip_recognition(sdiodev, ci); |
Franky Lin | a83369b | 2011-11-04 22:23:28 +0100 | [diff] [blame] | 673 | if (ret != 0) |
Franky Lin | a97e4fc | 2011-11-04 22:23:35 +0100 | [diff] [blame] | 674 | goto err; |
Franky Lin | a83369b | 2011-11-04 22:23:28 +0100 | [diff] [blame] | 675 | |
Franky Lin | 5b45e54 | 2011-11-04 22:23:30 +0100 | [diff] [blame] | 676 | brcmf_sdio_chip_buscoresetup(sdiodev, ci); |
| 677 | |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 678 | brcmf_sdiod_regwl(sdiodev, CORE_CC_REG(ci->c_inf[0].base, gpiopullup), |
| 679 | 0, NULL); |
| 680 | brcmf_sdiod_regwl(sdiodev, CORE_CC_REG(ci->c_inf[0].base, gpiopulldown), |
| 681 | 0, NULL); |
Franky Lin | 960908d | 2011-11-04 22:23:33 +0100 | [diff] [blame] | 682 | |
Franky Lin | a97e4fc | 2011-11-04 22:23:35 +0100 | [diff] [blame] | 683 | *ci_ptr = ci; |
| 684 | return 0; |
| 685 | |
| 686 | err: |
| 687 | kfree(ci); |
Franky Lin | a83369b | 2011-11-04 22:23:28 +0100 | [diff] [blame] | 688 | return ret; |
| 689 | } |
Franky Lin | a8a6c04 | 2011-11-04 22:23:39 +0100 | [diff] [blame] | 690 | |
| 691 | void |
Arend van Spriel | 9cf218f | 2014-01-13 22:20:27 +0100 | [diff] [blame] | 692 | brcmf_sdio_chip_detach(struct brcmf_chip **ci_ptr) |
Franky Lin | a8a6c04 | 2011-11-04 22:23:39 +0100 | [diff] [blame] | 693 | { |
| 694 | brcmf_dbg(TRACE, "Enter\n"); |
| 695 | |
| 696 | kfree(*ci_ptr); |
| 697 | *ci_ptr = NULL; |
| 698 | } |
Franky Lin | e12afb6 | 2011-11-04 22:23:40 +0100 | [diff] [blame] | 699 | |
Franky Lin | 069eddd | 2013-04-11 13:28:48 +0200 | [diff] [blame] | 700 | static void |
| 701 | brcmf_sdio_chip_cm3_enterdl(struct brcmf_sdio_dev *sdiodev, |
Arend van Spriel | 9cf218f | 2014-01-13 22:20:27 +0100 | [diff] [blame] | 702 | struct brcmf_chip *ci) |
Franky Lin | 069eddd | 2013-04-11 13:28:48 +0200 | [diff] [blame] | 703 | { |
Hante Meuleman | 5303626 | 2014-01-13 22:20:23 +0100 | [diff] [blame] | 704 | ci->coredisable(sdiodev, ci, BCMA_CORE_ARM_CM3, 0, 0); |
| 705 | ci->resetcore(sdiodev, ci, BCMA_CORE_80211, |
| 706 | D11_BCMA_IOCTL_PHYRESET | D11_BCMA_IOCTL_PHYCLOCKEN, |
| 707 | D11_BCMA_IOCTL_PHYCLOCKEN, D11_BCMA_IOCTL_PHYCLOCKEN); |
| 708 | ci->resetcore(sdiodev, ci, BCMA_CORE_INTERNAL_MEM, 0, 0, 0); |
Franky Lin | 069eddd | 2013-04-11 13:28:48 +0200 | [diff] [blame] | 709 | } |
| 710 | |
Arend van Spriel | 9cf218f | 2014-01-13 22:20:27 +0100 | [diff] [blame] | 711 | static bool brcmf_sdio_chip_cm3_exitdl(struct brcmf_sdio_dev *sdiodev, |
| 712 | struct brcmf_chip *ci) |
Franky Lin | 069eddd | 2013-04-11 13:28:48 +0200 | [diff] [blame] | 713 | { |
| 714 | u8 core_idx; |
| 715 | u32 reg_addr; |
| 716 | |
| 717 | if (!ci->iscoreup(sdiodev, ci, BCMA_CORE_INTERNAL_MEM)) { |
| 718 | brcmf_err("SOCRAM core is down after reset?\n"); |
| 719 | return false; |
| 720 | } |
| 721 | |
Franky Lin | 069eddd | 2013-04-11 13:28:48 +0200 | [diff] [blame] | 722 | /* clear all interrupts */ |
| 723 | core_idx = brcmf_sdio_chip_getinfidx(ci, BCMA_CORE_SDIO_DEV); |
| 724 | reg_addr = ci->c_inf[core_idx].base; |
| 725 | reg_addr += offsetof(struct sdpcmd_regs, intstatus); |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 726 | brcmf_sdiod_regwl(sdiodev, reg_addr, 0xFFFFFFFF, NULL); |
Franky Lin | 069eddd | 2013-04-11 13:28:48 +0200 | [diff] [blame] | 727 | |
Hante Meuleman | 5303626 | 2014-01-13 22:20:23 +0100 | [diff] [blame] | 728 | ci->resetcore(sdiodev, ci, BCMA_CORE_ARM_CM3, 0, 0, 0); |
Franky Lin | 1640f28 | 2013-04-11 13:28:51 +0200 | [diff] [blame] | 729 | |
| 730 | return true; |
| 731 | } |
| 732 | |
| 733 | static inline void |
| 734 | brcmf_sdio_chip_cr4_enterdl(struct brcmf_sdio_dev *sdiodev, |
Arend van Spriel | 9cf218f | 2014-01-13 22:20:27 +0100 | [diff] [blame] | 735 | struct brcmf_chip *ci) |
Franky Lin | 1640f28 | 2013-04-11 13:28:51 +0200 | [diff] [blame] | 736 | { |
Hante Meuleman | 5303626 | 2014-01-13 22:20:23 +0100 | [diff] [blame] | 737 | u8 idx; |
| 738 | u32 regdata; |
| 739 | u32 wrapbase; |
| 740 | idx = brcmf_sdio_chip_getinfidx(ci, BCMA_CORE_ARM_CR4); |
| 741 | |
| 742 | if (idx == BRCMF_MAX_CORENUM) |
| 743 | return; |
| 744 | |
| 745 | wrapbase = ci->c_inf[idx].wrapbase; |
| 746 | regdata = brcmf_sdiod_regrl(sdiodev, wrapbase + BCMA_IOCTL, NULL); |
| 747 | regdata &= ARMCR4_BCMA_IOCTL_CPUHALT; |
| 748 | ci->resetcore(sdiodev, ci, BCMA_CORE_ARM_CR4, regdata, |
| 749 | ARMCR4_BCMA_IOCTL_CPUHALT, ARMCR4_BCMA_IOCTL_CPUHALT); |
| 750 | ci->resetcore(sdiodev, ci, BCMA_CORE_80211, |
| 751 | D11_BCMA_IOCTL_PHYRESET | D11_BCMA_IOCTL_PHYCLOCKEN, |
| 752 | D11_BCMA_IOCTL_PHYCLOCKEN, D11_BCMA_IOCTL_PHYCLOCKEN); |
Franky Lin | 1640f28 | 2013-04-11 13:28:51 +0200 | [diff] [blame] | 753 | } |
| 754 | |
Arend van Spriel | 9cf218f | 2014-01-13 22:20:27 +0100 | [diff] [blame] | 755 | static bool brcmf_sdio_chip_cr4_exitdl(struct brcmf_sdio_dev *sdiodev, |
| 756 | struct brcmf_chip *ci, u32 rstvec) |
Franky Lin | 1640f28 | 2013-04-11 13:28:51 +0200 | [diff] [blame] | 757 | { |
| 758 | u8 core_idx; |
| 759 | u32 reg_addr; |
| 760 | |
Franky Lin | 1640f28 | 2013-04-11 13:28:51 +0200 | [diff] [blame] | 761 | /* clear all interrupts */ |
| 762 | core_idx = brcmf_sdio_chip_getinfidx(ci, BCMA_CORE_SDIO_DEV); |
| 763 | reg_addr = ci->c_inf[core_idx].base; |
| 764 | reg_addr += offsetof(struct sdpcmd_regs, intstatus); |
Arend van Spriel | a39be27 | 2013-12-12 11:58:58 +0100 | [diff] [blame] | 765 | brcmf_sdiod_regwl(sdiodev, reg_addr, 0xFFFFFFFF, NULL); |
Franky Lin | 1640f28 | 2013-04-11 13:28:51 +0200 | [diff] [blame] | 766 | |
| 767 | /* Write reset vector to address 0 */ |
Arend van Spriel | 3355650 | 2014-01-13 22:20:25 +0100 | [diff] [blame] | 768 | brcmf_sdiod_ramrw(sdiodev, true, 0, (void *)&rstvec, |
| 769 | sizeof(rstvec)); |
Franky Lin | 1640f28 | 2013-04-11 13:28:51 +0200 | [diff] [blame] | 770 | |
| 771 | /* restore ARM */ |
Hante Meuleman | 5303626 | 2014-01-13 22:20:23 +0100 | [diff] [blame] | 772 | ci->resetcore(sdiodev, ci, BCMA_CORE_ARM_CR4, ARMCR4_BCMA_IOCTL_CPUHALT, |
| 773 | 0, 0); |
Franky Lin | 069eddd | 2013-04-11 13:28:48 +0200 | [diff] [blame] | 774 | |
| 775 | return true; |
| 776 | } |
| 777 | |
| 778 | void brcmf_sdio_chip_enter_download(struct brcmf_sdio_dev *sdiodev, |
Arend van Spriel | 9cf218f | 2014-01-13 22:20:27 +0100 | [diff] [blame] | 779 | struct brcmf_chip *ci) |
Franky Lin | 069eddd | 2013-04-11 13:28:48 +0200 | [diff] [blame] | 780 | { |
Franky Lin | 1640f28 | 2013-04-11 13:28:51 +0200 | [diff] [blame] | 781 | u8 arm_core_idx; |
| 782 | |
| 783 | arm_core_idx = brcmf_sdio_chip_getinfidx(ci, BCMA_CORE_ARM_CM3); |
| 784 | if (BRCMF_MAX_CORENUM != arm_core_idx) { |
| 785 | brcmf_sdio_chip_cm3_enterdl(sdiodev, ci); |
| 786 | return; |
| 787 | } |
| 788 | |
| 789 | brcmf_sdio_chip_cr4_enterdl(sdiodev, ci); |
Franky Lin | 069eddd | 2013-04-11 13:28:48 +0200 | [diff] [blame] | 790 | } |
| 791 | |
| 792 | bool brcmf_sdio_chip_exit_download(struct brcmf_sdio_dev *sdiodev, |
Arend van Spriel | 9cf218f | 2014-01-13 22:20:27 +0100 | [diff] [blame] | 793 | struct brcmf_chip *ci, u32 rstvec) |
Franky Lin | 069eddd | 2013-04-11 13:28:48 +0200 | [diff] [blame] | 794 | { |
Franky Lin | 1640f28 | 2013-04-11 13:28:51 +0200 | [diff] [blame] | 795 | u8 arm_core_idx; |
| 796 | |
| 797 | arm_core_idx = brcmf_sdio_chip_getinfidx(ci, BCMA_CORE_ARM_CM3); |
| 798 | if (BRCMF_MAX_CORENUM != arm_core_idx) |
Hante Meuleman | a74d036 | 2014-01-13 22:20:22 +0100 | [diff] [blame] | 799 | return brcmf_sdio_chip_cm3_exitdl(sdiodev, ci); |
Franky Lin | 1640f28 | 2013-04-11 13:28:51 +0200 | [diff] [blame] | 800 | |
Arend van Spriel | 3355650 | 2014-01-13 22:20:25 +0100 | [diff] [blame] | 801 | return brcmf_sdio_chip_cr4_exitdl(sdiodev, ci, rstvec); |
Franky Lin | 069eddd | 2013-04-11 13:28:48 +0200 | [diff] [blame] | 802 | } |