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 | |
Joe Perches | 02f7719 | 2012-01-15 00:38:44 -0800 | [diff] [blame] | 18 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 19 | |
Franky Lin | a83369b | 2011-11-04 22:23:28 +0100 | [diff] [blame] | 20 | #include <linux/types.h> |
| 21 | #include <linux/netdevice.h> |
| 22 | #include <linux/mmc/card.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" |
| 33 | #include "sdio_chip.h" |
| 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 | |
Franky Lin | a83369b | 2011-11-04 22:23:28 +0100 | [diff] [blame] | 45 | #define SBCOREREV(sbidh) \ |
Franky Lin | 61213be | 2011-11-04 22:23:41 +0100 | [diff] [blame] | 46 | ((((sbidh) & SSB_IDHIGH_RCHI) >> SSB_IDHIGH_RCHI_SHIFT) | \ |
| 47 | ((sbidh) & SSB_IDHIGH_RCLO)) |
Franky Lin | a83369b | 2011-11-04 22:23:28 +0100 | [diff] [blame] | 48 | |
Franky Lin | 6ca687d | 2011-11-10 20:30:21 +0100 | [diff] [blame] | 49 | /* SOC Interconnect types (aka chip types) */ |
| 50 | #define SOCI_SB 0 |
| 51 | #define SOCI_AI 1 |
| 52 | |
Franky Lin | 523894f | 2011-11-10 20:30:22 +0100 | [diff] [blame] | 53 | /* EROM CompIdentB */ |
| 54 | #define CIB_REV_MASK 0xff000000 |
| 55 | #define CIB_REV_SHIFT 24 |
| 56 | |
Franky Lin | e12afb6 | 2011-11-04 22:23:40 +0100 | [diff] [blame] | 57 | #define SDIOD_DRVSTR_KEY(chip, pmu) (((chip) << 16) | (pmu)) |
| 58 | /* SDIO Pad drive strength to select value mappings */ |
| 59 | struct sdiod_drive_str { |
| 60 | u8 strength; /* Pad Drive Strength in mA */ |
| 61 | u8 sel; /* Chip-specific select value */ |
| 62 | }; |
Franky Lin | ce2d7d7 | 2011-12-08 15:06:39 -0800 | [diff] [blame] | 63 | /* SDIO Drive Strength to sel value table for PMU Rev 11 (1.8V) */ |
Franky Lin | ffb2756 | 2011-12-08 15:06:40 -0800 | [diff] [blame] | 64 | static const struct sdiod_drive_str sdiod_drvstr_tab1_1v8[] = { |
Franky Lin | ce2d7d7 | 2011-12-08 15:06:39 -0800 | [diff] [blame] | 65 | {32, 0x6}, |
| 66 | {26, 0x7}, |
| 67 | {22, 0x4}, |
| 68 | {16, 0x5}, |
| 69 | {12, 0x2}, |
| 70 | {8, 0x3}, |
| 71 | {4, 0x0}, |
| 72 | {0, 0x1} |
| 73 | }; |
| 74 | |
Franky Lin | 99ba15c | 2011-11-04 22:23:42 +0100 | [diff] [blame] | 75 | u8 |
| 76 | brcmf_sdio_chip_getinfidx(struct chip_info *ci, u16 coreid) |
| 77 | { |
| 78 | u8 idx; |
| 79 | |
| 80 | for (idx = 0; idx < BRCMF_MAX_CORENUM; idx++) |
| 81 | if (coreid == ci->c_inf[idx].id) |
| 82 | return idx; |
| 83 | |
| 84 | return BRCMF_MAX_CORENUM; |
| 85 | } |
| 86 | |
Franky Lin | 454d2a8 | 2011-11-04 22:23:37 +0100 | [diff] [blame] | 87 | static u32 |
Franky Lin | 523894f | 2011-11-10 20:30:22 +0100 | [diff] [blame] | 88 | brcmf_sdio_sb_corerev(struct brcmf_sdio_dev *sdiodev, |
| 89 | struct chip_info *ci, u16 coreid) |
Franky Lin | 454d2a8 | 2011-11-04 22:23:37 +0100 | [diff] [blame] | 90 | { |
| 91 | u32 regdata; |
Franky Lin | 523894f | 2011-11-10 20:30:22 +0100 | [diff] [blame] | 92 | u8 idx; |
| 93 | |
| 94 | idx = brcmf_sdio_chip_getinfidx(ci, coreid); |
Franky Lin | 454d2a8 | 2011-11-04 22:23:37 +0100 | [diff] [blame] | 95 | |
Franky Lin | 79ae395 | 2012-05-04 18:27:34 -0700 | [diff] [blame] | 96 | regdata = brcmf_sdio_regrl(sdiodev, |
| 97 | CORE_SB(ci->c_inf[idx].base, sbidhigh), |
| 98 | NULL); |
Franky Lin | 454d2a8 | 2011-11-04 22:23:37 +0100 | [diff] [blame] | 99 | return SBCOREREV(regdata); |
| 100 | } |
| 101 | |
Franky Lin | 523894f | 2011-11-10 20:30:22 +0100 | [diff] [blame] | 102 | static u32 |
| 103 | brcmf_sdio_ai_corerev(struct brcmf_sdio_dev *sdiodev, |
| 104 | struct chip_info *ci, u16 coreid) |
| 105 | { |
| 106 | u8 idx; |
| 107 | |
| 108 | idx = brcmf_sdio_chip_getinfidx(ci, coreid); |
| 109 | |
| 110 | return (ci->c_inf[idx].cib & CIB_REV_MASK) >> CIB_REV_SHIFT; |
| 111 | } |
| 112 | |
Franky Lin | 6ca687d | 2011-11-10 20:30:21 +0100 | [diff] [blame] | 113 | static bool |
| 114 | brcmf_sdio_sb_iscoreup(struct brcmf_sdio_dev *sdiodev, |
| 115 | struct chip_info *ci, u16 coreid) |
Franky Lin | d8f64a4 | 2011-11-04 22:23:36 +0100 | [diff] [blame] | 116 | { |
| 117 | u32 regdata; |
Franky Lin | 6ca687d | 2011-11-10 20:30:21 +0100 | [diff] [blame] | 118 | u8 idx; |
| 119 | |
| 120 | idx = brcmf_sdio_chip_getinfidx(ci, coreid); |
Franky Lin | d8f64a4 | 2011-11-04 22:23:36 +0100 | [diff] [blame] | 121 | |
Franky Lin | 79ae395 | 2012-05-04 18:27:34 -0700 | [diff] [blame] | 122 | regdata = brcmf_sdio_regrl(sdiodev, |
| 123 | CORE_SB(ci->c_inf[idx].base, sbtmstatelow), |
| 124 | NULL); |
Franky Lin | 61213be | 2011-11-04 22:23:41 +0100 | [diff] [blame] | 125 | regdata &= (SSB_TMSLOW_RESET | SSB_TMSLOW_REJECT | |
| 126 | SSB_IMSTATE_REJECT | SSB_TMSLOW_CLOCK); |
| 127 | return (SSB_TMSLOW_CLOCK == regdata); |
Franky Lin | d8f64a4 | 2011-11-04 22:23:36 +0100 | [diff] [blame] | 128 | } |
| 129 | |
Franky Lin | 6ca687d | 2011-11-10 20:30:21 +0100 | [diff] [blame] | 130 | static bool |
| 131 | brcmf_sdio_ai_iscoreup(struct brcmf_sdio_dev *sdiodev, |
| 132 | struct chip_info *ci, u16 coreid) |
| 133 | { |
| 134 | u32 regdata; |
| 135 | u8 idx; |
| 136 | bool ret; |
| 137 | |
| 138 | idx = brcmf_sdio_chip_getinfidx(ci, coreid); |
| 139 | |
Franky Lin | 79ae395 | 2012-05-04 18:27:34 -0700 | [diff] [blame] | 140 | regdata = brcmf_sdio_regrl(sdiodev, ci->c_inf[idx].wrapbase+BCMA_IOCTL, |
| 141 | NULL); |
Franky Lin | 6ca687d | 2011-11-10 20:30:21 +0100 | [diff] [blame] | 142 | ret = (regdata & (BCMA_IOCTL_FGC | BCMA_IOCTL_CLK)) == BCMA_IOCTL_CLK; |
| 143 | |
Franky Lin | 79ae395 | 2012-05-04 18:27:34 -0700 | [diff] [blame] | 144 | regdata = brcmf_sdio_regrl(sdiodev, |
| 145 | ci->c_inf[idx].wrapbase+BCMA_RESET_CTL, |
| 146 | NULL); |
Franky Lin | 6ca687d | 2011-11-10 20:30:21 +0100 | [diff] [blame] | 147 | ret = ret && ((regdata & BCMA_RESET_CTL_RESET) == 0); |
| 148 | |
| 149 | return ret; |
| 150 | } |
| 151 | |
Franky Lin | 086a2e0 | 2011-11-10 20:30:23 +0100 | [diff] [blame] | 152 | static void |
| 153 | brcmf_sdio_sb_coredisable(struct brcmf_sdio_dev *sdiodev, |
| 154 | struct chip_info *ci, u16 coreid) |
Franky Lin | 2d4a9af | 2011-11-04 22:23:31 +0100 | [diff] [blame] | 155 | { |
Franky Lin | 79ae395 | 2012-05-04 18:27:34 -0700 | [diff] [blame] | 156 | u32 regdata, base; |
Franky Lin | 086a2e0 | 2011-11-10 20:30:23 +0100 | [diff] [blame] | 157 | u8 idx; |
| 158 | |
| 159 | idx = brcmf_sdio_chip_getinfidx(ci, coreid); |
Franky Lin | 79ae395 | 2012-05-04 18:27:34 -0700 | [diff] [blame] | 160 | base = ci->c_inf[idx].base; |
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 | regdata = brcmf_sdio_regrl(sdiodev, CORE_SB(base, sbtmstatelow), NULL); |
Franky Lin | 61213be | 2011-11-04 22:23:41 +0100 | [diff] [blame] | 163 | if (regdata & SSB_TMSLOW_RESET) |
Franky Lin | 2d4a9af | 2011-11-04 22:23:31 +0100 | [diff] [blame] | 164 | return; |
| 165 | |
Franky Lin | 79ae395 | 2012-05-04 18:27:34 -0700 | [diff] [blame] | 166 | regdata = brcmf_sdio_regrl(sdiodev, CORE_SB(base, sbtmstatelow), NULL); |
Franky Lin | 61213be | 2011-11-04 22:23:41 +0100 | [diff] [blame] | 167 | if ((regdata & SSB_TMSLOW_CLOCK) != 0) { |
Franky Lin | 2d4a9af | 2011-11-04 22:23:31 +0100 | [diff] [blame] | 168 | /* |
| 169 | * set target reject and spin until busy is clear |
| 170 | * (preserve core-specific bits) |
| 171 | */ |
Franky Lin | 79ae395 | 2012-05-04 18:27:34 -0700 | [diff] [blame] | 172 | regdata = brcmf_sdio_regrl(sdiodev, CORE_SB(base, sbtmstatelow), |
| 173 | NULL); |
Franky Lin | e13ce26 | 2012-05-04 18:27:35 -0700 | [diff] [blame^] | 174 | brcmf_sdio_regwl(sdiodev, CORE_SB(base, sbtmstatelow), |
| 175 | regdata | SSB_TMSLOW_REJECT, NULL); |
Franky Lin | 2d4a9af | 2011-11-04 22:23:31 +0100 | [diff] [blame] | 176 | |
Franky Lin | 79ae395 | 2012-05-04 18:27:34 -0700 | [diff] [blame] | 177 | regdata = brcmf_sdio_regrl(sdiodev, CORE_SB(base, sbtmstatelow), |
| 178 | NULL); |
Franky Lin | 2d4a9af | 2011-11-04 22:23:31 +0100 | [diff] [blame] | 179 | udelay(1); |
Franky Lin | 79ae395 | 2012-05-04 18:27:34 -0700 | [diff] [blame] | 180 | SPINWAIT((brcmf_sdio_regrl(sdiodev, |
| 181 | CORE_SB(base, sbtmstatehigh), |
| 182 | NULL) & |
Franky Lin | 61213be | 2011-11-04 22:23:41 +0100 | [diff] [blame] | 183 | SSB_TMSHIGH_BUSY), 100000); |
Franky Lin | 2d4a9af | 2011-11-04 22:23:31 +0100 | [diff] [blame] | 184 | |
Franky Lin | 79ae395 | 2012-05-04 18:27:34 -0700 | [diff] [blame] | 185 | regdata = brcmf_sdio_regrl(sdiodev, |
| 186 | CORE_SB(base, sbtmstatehigh), |
| 187 | NULL); |
Franky Lin | 61213be | 2011-11-04 22:23:41 +0100 | [diff] [blame] | 188 | if (regdata & SSB_TMSHIGH_BUSY) |
Franky Lin | 2d4a9af | 2011-11-04 22:23:31 +0100 | [diff] [blame] | 189 | brcmf_dbg(ERROR, "core state still busy\n"); |
| 190 | |
Franky Lin | 79ae395 | 2012-05-04 18:27:34 -0700 | [diff] [blame] | 191 | regdata = brcmf_sdio_regrl(sdiodev, CORE_SB(base, sbidlow), |
| 192 | NULL); |
Franky Lin | 61213be | 2011-11-04 22:23:41 +0100 | [diff] [blame] | 193 | if (regdata & SSB_IDLOW_INITIATOR) { |
Franky Lin | 79ae395 | 2012-05-04 18:27:34 -0700 | [diff] [blame] | 194 | regdata = brcmf_sdio_regrl(sdiodev, |
| 195 | CORE_SB(base, sbimstate), |
| 196 | NULL); |
| 197 | regdata |= SSB_IMSTATE_REJECT; |
Franky Lin | e13ce26 | 2012-05-04 18:27:35 -0700 | [diff] [blame^] | 198 | brcmf_sdio_regwl(sdiodev, CORE_SB(base, sbimstate), |
| 199 | regdata, NULL); |
Franky Lin | 79ae395 | 2012-05-04 18:27:34 -0700 | [diff] [blame] | 200 | regdata = brcmf_sdio_regrl(sdiodev, |
| 201 | CORE_SB(base, sbimstate), |
| 202 | NULL); |
Franky Lin | 2d4a9af | 2011-11-04 22:23:31 +0100 | [diff] [blame] | 203 | udelay(1); |
Franky Lin | 79ae395 | 2012-05-04 18:27:34 -0700 | [diff] [blame] | 204 | SPINWAIT((brcmf_sdio_regrl(sdiodev, |
| 205 | CORE_SB(base, sbimstate), |
| 206 | NULL) & |
Franky Lin | 61213be | 2011-11-04 22:23:41 +0100 | [diff] [blame] | 207 | SSB_IMSTATE_BUSY), 100000); |
Franky Lin | 2d4a9af | 2011-11-04 22:23:31 +0100 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | /* set reset and reject while enabling the clocks */ |
Franky Lin | e13ce26 | 2012-05-04 18:27:35 -0700 | [diff] [blame^] | 211 | regdata = SSB_TMSLOW_FGC | SSB_TMSLOW_CLOCK | |
| 212 | SSB_TMSLOW_REJECT | SSB_TMSLOW_RESET; |
| 213 | brcmf_sdio_regwl(sdiodev, CORE_SB(base, sbtmstatelow), |
| 214 | regdata, NULL); |
Franky Lin | 79ae395 | 2012-05-04 18:27:34 -0700 | [diff] [blame] | 215 | regdata = brcmf_sdio_regrl(sdiodev, CORE_SB(base, sbtmstatelow), |
| 216 | NULL); |
Franky Lin | 2d4a9af | 2011-11-04 22:23:31 +0100 | [diff] [blame] | 217 | udelay(10); |
| 218 | |
| 219 | /* clear the initiator reject bit */ |
Franky Lin | 79ae395 | 2012-05-04 18:27:34 -0700 | [diff] [blame] | 220 | regdata = brcmf_sdio_regrl(sdiodev, CORE_SB(base, sbidlow), |
| 221 | NULL); |
Franky Lin | 61213be | 2011-11-04 22:23:41 +0100 | [diff] [blame] | 222 | if (regdata & SSB_IDLOW_INITIATOR) { |
Franky Lin | 79ae395 | 2012-05-04 18:27:34 -0700 | [diff] [blame] | 223 | regdata = brcmf_sdio_regrl(sdiodev, |
| 224 | CORE_SB(base, sbimstate), |
| 225 | NULL); |
| 226 | regdata &= ~SSB_IMSTATE_REJECT; |
Franky Lin | e13ce26 | 2012-05-04 18:27:35 -0700 | [diff] [blame^] | 227 | brcmf_sdio_regwl(sdiodev, CORE_SB(base, sbimstate), |
| 228 | regdata, NULL); |
Franky Lin | 2d4a9af | 2011-11-04 22:23:31 +0100 | [diff] [blame] | 229 | } |
| 230 | } |
| 231 | |
| 232 | /* leave reset and reject asserted */ |
Franky Lin | e13ce26 | 2012-05-04 18:27:35 -0700 | [diff] [blame^] | 233 | brcmf_sdio_regwl(sdiodev, CORE_SB(base, sbtmstatelow), |
| 234 | (SSB_TMSLOW_REJECT | SSB_TMSLOW_RESET), NULL); |
Franky Lin | 2d4a9af | 2011-11-04 22:23:31 +0100 | [diff] [blame] | 235 | udelay(1); |
| 236 | } |
| 237 | |
Franky Lin | 086a2e0 | 2011-11-10 20:30:23 +0100 | [diff] [blame] | 238 | static void |
| 239 | brcmf_sdio_ai_coredisable(struct brcmf_sdio_dev *sdiodev, |
| 240 | struct chip_info *ci, u16 coreid) |
| 241 | { |
| 242 | u8 idx; |
| 243 | u32 regdata; |
| 244 | |
| 245 | idx = brcmf_sdio_chip_getinfidx(ci, coreid); |
| 246 | |
| 247 | /* if core is already in reset, just return */ |
Franky Lin | 79ae395 | 2012-05-04 18:27:34 -0700 | [diff] [blame] | 248 | regdata = brcmf_sdio_regrl(sdiodev, |
| 249 | ci->c_inf[idx].wrapbase+BCMA_RESET_CTL, |
| 250 | NULL); |
Franky Lin | 086a2e0 | 2011-11-10 20:30:23 +0100 | [diff] [blame] | 251 | if ((regdata & BCMA_RESET_CTL_RESET) != 0) |
| 252 | return; |
| 253 | |
Franky Lin | e13ce26 | 2012-05-04 18:27:35 -0700 | [diff] [blame^] | 254 | brcmf_sdio_regwl(sdiodev, ci->c_inf[idx].wrapbase+BCMA_IOCTL, 0, NULL); |
Franky Lin | 79ae395 | 2012-05-04 18:27:34 -0700 | [diff] [blame] | 255 | regdata = brcmf_sdio_regrl(sdiodev, ci->c_inf[idx].wrapbase+BCMA_IOCTL, |
| 256 | NULL); |
Franky Lin | 086a2e0 | 2011-11-10 20:30:23 +0100 | [diff] [blame] | 257 | udelay(10); |
| 258 | |
Franky Lin | e13ce26 | 2012-05-04 18:27:35 -0700 | [diff] [blame^] | 259 | brcmf_sdio_regwl(sdiodev, ci->c_inf[idx].wrapbase+BCMA_RESET_CTL, |
| 260 | BCMA_RESET_CTL_RESET, NULL); |
Franky Lin | 086a2e0 | 2011-11-10 20:30:23 +0100 | [diff] [blame] | 261 | udelay(1); |
| 262 | } |
| 263 | |
Franky Lin | d77e70f | 2011-11-10 20:30:24 +0100 | [diff] [blame] | 264 | static void |
| 265 | brcmf_sdio_sb_resetcore(struct brcmf_sdio_dev *sdiodev, |
| 266 | struct chip_info *ci, u16 coreid) |
Franky Lin | 2bc78e1 | 2011-11-04 22:23:38 +0100 | [diff] [blame] | 267 | { |
| 268 | u32 regdata; |
Franky Lin | 086a2e0 | 2011-11-10 20:30:23 +0100 | [diff] [blame] | 269 | u8 idx; |
| 270 | |
| 271 | idx = brcmf_sdio_chip_getinfidx(ci, coreid); |
Franky Lin | 2bc78e1 | 2011-11-04 22:23:38 +0100 | [diff] [blame] | 272 | |
| 273 | /* |
| 274 | * Must do the disable sequence first to work for |
| 275 | * arbitrary current core state. |
| 276 | */ |
Franky Lin | d77e70f | 2011-11-10 20:30:24 +0100 | [diff] [blame] | 277 | brcmf_sdio_sb_coredisable(sdiodev, ci, coreid); |
Franky Lin | 2bc78e1 | 2011-11-04 22:23:38 +0100 | [diff] [blame] | 278 | |
| 279 | /* |
| 280 | * Now do the initialization sequence. |
| 281 | * set reset while enabling the clock and |
| 282 | * forcing them on throughout the core |
| 283 | */ |
Franky Lin | e13ce26 | 2012-05-04 18:27:35 -0700 | [diff] [blame^] | 284 | brcmf_sdio_regwl(sdiodev, |
| 285 | CORE_SB(ci->c_inf[idx].base, sbtmstatelow), |
| 286 | SSB_TMSLOW_FGC | SSB_TMSLOW_CLOCK | SSB_TMSLOW_RESET, |
| 287 | NULL); |
Franky Lin | 79ae395 | 2012-05-04 18:27:34 -0700 | [diff] [blame] | 288 | regdata = brcmf_sdio_regrl(sdiodev, |
| 289 | CORE_SB(ci->c_inf[idx].base, sbtmstatelow), |
| 290 | NULL); |
Franky Lin | 2bc78e1 | 2011-11-04 22:23:38 +0100 | [diff] [blame] | 291 | udelay(1); |
| 292 | |
Franky Lin | d77e70f | 2011-11-10 20:30:24 +0100 | [diff] [blame] | 293 | /* clear any serror */ |
Franky Lin | 79ae395 | 2012-05-04 18:27:34 -0700 | [diff] [blame] | 294 | regdata = brcmf_sdio_regrl(sdiodev, |
| 295 | CORE_SB(ci->c_inf[idx].base, sbtmstatehigh), |
| 296 | NULL); |
Franky Lin | 61213be | 2011-11-04 22:23:41 +0100 | [diff] [blame] | 297 | if (regdata & SSB_TMSHIGH_SERR) |
Franky Lin | e13ce26 | 2012-05-04 18:27:35 -0700 | [diff] [blame^] | 298 | brcmf_sdio_regwl(sdiodev, |
| 299 | CORE_SB(ci->c_inf[idx].base, sbtmstatehigh), |
| 300 | 0, NULL); |
Franky Lin | 2bc78e1 | 2011-11-04 22:23:38 +0100 | [diff] [blame] | 301 | |
Franky Lin | 79ae395 | 2012-05-04 18:27:34 -0700 | [diff] [blame] | 302 | regdata = brcmf_sdio_regrl(sdiodev, |
| 303 | CORE_SB(ci->c_inf[idx].base, sbimstate), |
| 304 | NULL); |
Franky Lin | 61213be | 2011-11-04 22:23:41 +0100 | [diff] [blame] | 305 | if (regdata & (SSB_IMSTATE_IBE | SSB_IMSTATE_TO)) |
Franky Lin | e13ce26 | 2012-05-04 18:27:35 -0700 | [diff] [blame^] | 306 | brcmf_sdio_regwl(sdiodev, |
| 307 | CORE_SB(ci->c_inf[idx].base, sbimstate), |
| 308 | regdata & ~(SSB_IMSTATE_IBE | SSB_IMSTATE_TO), |
| 309 | NULL); |
Franky Lin | 2bc78e1 | 2011-11-04 22:23:38 +0100 | [diff] [blame] | 310 | |
| 311 | /* clear reset and allow it to propagate throughout the core */ |
Franky Lin | e13ce26 | 2012-05-04 18:27:35 -0700 | [diff] [blame^] | 312 | brcmf_sdio_regwl(sdiodev, CORE_SB(ci->c_inf[idx].base, sbtmstatelow), |
| 313 | SSB_TMSLOW_FGC | SSB_TMSLOW_CLOCK, NULL); |
Franky Lin | 79ae395 | 2012-05-04 18:27:34 -0700 | [diff] [blame] | 314 | regdata = brcmf_sdio_regrl(sdiodev, |
| 315 | CORE_SB(ci->c_inf[idx].base, sbtmstatelow), |
| 316 | NULL); |
Franky Lin | 2bc78e1 | 2011-11-04 22:23:38 +0100 | [diff] [blame] | 317 | udelay(1); |
| 318 | |
| 319 | /* leave clock enabled */ |
Franky Lin | e13ce26 | 2012-05-04 18:27:35 -0700 | [diff] [blame^] | 320 | brcmf_sdio_regwl(sdiodev, CORE_SB(ci->c_inf[idx].base, sbtmstatelow), |
| 321 | SSB_TMSLOW_CLOCK, NULL); |
Franky Lin | 79ae395 | 2012-05-04 18:27:34 -0700 | [diff] [blame] | 322 | regdata = brcmf_sdio_regrl(sdiodev, |
| 323 | CORE_SB(ci->c_inf[idx].base, sbtmstatelow), |
| 324 | NULL); |
Franky Lin | d77e70f | 2011-11-10 20:30:24 +0100 | [diff] [blame] | 325 | udelay(1); |
| 326 | } |
| 327 | |
| 328 | static void |
| 329 | brcmf_sdio_ai_resetcore(struct brcmf_sdio_dev *sdiodev, |
| 330 | struct chip_info *ci, u16 coreid) |
| 331 | { |
| 332 | u8 idx; |
| 333 | u32 regdata; |
| 334 | |
| 335 | idx = brcmf_sdio_chip_getinfidx(ci, coreid); |
| 336 | |
| 337 | /* must disable first to work for arbitrary current core state */ |
| 338 | brcmf_sdio_ai_coredisable(sdiodev, ci, coreid); |
| 339 | |
| 340 | /* now do initialization sequence */ |
Franky Lin | e13ce26 | 2012-05-04 18:27:35 -0700 | [diff] [blame^] | 341 | brcmf_sdio_regwl(sdiodev, ci->c_inf[idx].wrapbase+BCMA_IOCTL, |
| 342 | BCMA_IOCTL_FGC | BCMA_IOCTL_CLK, NULL); |
Franky Lin | 79ae395 | 2012-05-04 18:27:34 -0700 | [diff] [blame] | 343 | regdata = brcmf_sdio_regrl(sdiodev, ci->c_inf[idx].wrapbase+BCMA_IOCTL, |
| 344 | NULL); |
Franky Lin | e13ce26 | 2012-05-04 18:27:35 -0700 | [diff] [blame^] | 345 | brcmf_sdio_regwl(sdiodev, ci->c_inf[idx].wrapbase+BCMA_RESET_CTL, |
| 346 | 0, NULL); |
Franky Lin | d77e70f | 2011-11-10 20:30:24 +0100 | [diff] [blame] | 347 | udelay(1); |
| 348 | |
Franky Lin | e13ce26 | 2012-05-04 18:27:35 -0700 | [diff] [blame^] | 349 | brcmf_sdio_regwl(sdiodev, ci->c_inf[idx].wrapbase+BCMA_IOCTL, |
| 350 | BCMA_IOCTL_CLK, NULL); |
Franky Lin | 79ae395 | 2012-05-04 18:27:34 -0700 | [diff] [blame] | 351 | regdata = brcmf_sdio_regrl(sdiodev, ci->c_inf[idx].wrapbase+BCMA_IOCTL, |
| 352 | NULL); |
Franky Lin | 2bc78e1 | 2011-11-04 22:23:38 +0100 | [diff] [blame] | 353 | udelay(1); |
| 354 | } |
| 355 | |
Franky Lin | a83369b | 2011-11-04 22:23:28 +0100 | [diff] [blame] | 356 | static int brcmf_sdio_chip_recognition(struct brcmf_sdio_dev *sdiodev, |
| 357 | struct chip_info *ci, u32 regs) |
| 358 | { |
| 359 | u32 regdata; |
| 360 | |
| 361 | /* |
| 362 | * Get CC core rev |
| 363 | * Chipid is assume to be at offset 0 from regs arg |
| 364 | * For different chiptypes or old sdio hosts w/o chipcommon, |
| 365 | * other ways of recognition should be added here. |
| 366 | */ |
Franky Lin | 99ba15c | 2011-11-04 22:23:42 +0100 | [diff] [blame] | 367 | ci->c_inf[0].id = BCMA_CORE_CHIPCOMMON; |
| 368 | ci->c_inf[0].base = regs; |
Franky Lin | 79ae395 | 2012-05-04 18:27:34 -0700 | [diff] [blame] | 369 | regdata = brcmf_sdio_regrl(sdiodev, |
| 370 | CORE_CC_REG(ci->c_inf[0].base, chipid), |
| 371 | NULL); |
Franky Lin | a83369b | 2011-11-04 22:23:28 +0100 | [diff] [blame] | 372 | ci->chip = regdata & CID_ID_MASK; |
| 373 | ci->chiprev = (regdata & CID_REV_MASK) >> CID_REV_SHIFT; |
Franky Lin | 6ca687d | 2011-11-10 20:30:21 +0100 | [diff] [blame] | 374 | ci->socitype = (regdata & CID_TYPE_MASK) >> CID_TYPE_SHIFT; |
Franky Lin | a83369b | 2011-11-04 22:23:28 +0100 | [diff] [blame] | 375 | |
| 376 | brcmf_dbg(INFO, "chipid=0x%x chiprev=%d\n", ci->chip, ci->chiprev); |
| 377 | |
| 378 | /* Address of cores for new chips should be added here */ |
| 379 | switch (ci->chip) { |
| 380 | case BCM4329_CHIP_ID: |
Franky Lin | 99ba15c | 2011-11-04 22:23:42 +0100 | [diff] [blame] | 381 | ci->c_inf[1].id = BCMA_CORE_SDIO_DEV; |
| 382 | ci->c_inf[1].base = BCM4329_CORE_BUS_BASE; |
| 383 | ci->c_inf[2].id = BCMA_CORE_INTERNAL_MEM; |
| 384 | ci->c_inf[2].base = BCM4329_CORE_SOCRAM_BASE; |
| 385 | ci->c_inf[3].id = BCMA_CORE_ARM_CM3; |
| 386 | ci->c_inf[3].base = BCM4329_CORE_ARM_BASE; |
Franky Lin | a83369b | 2011-11-04 22:23:28 +0100 | [diff] [blame] | 387 | ci->ramsize = BCM4329_RAMSIZE; |
| 388 | break; |
Franky Lin | ce2d7d7 | 2011-12-08 15:06:39 -0800 | [diff] [blame] | 389 | case BCM4330_CHIP_ID: |
| 390 | ci->c_inf[0].wrapbase = 0x18100000; |
| 391 | ci->c_inf[0].cib = 0x27004211; |
| 392 | ci->c_inf[1].id = BCMA_CORE_SDIO_DEV; |
| 393 | ci->c_inf[1].base = 0x18002000; |
| 394 | ci->c_inf[1].wrapbase = 0x18102000; |
| 395 | ci->c_inf[1].cib = 0x07004211; |
| 396 | ci->c_inf[2].id = BCMA_CORE_INTERNAL_MEM; |
| 397 | ci->c_inf[2].base = 0x18004000; |
| 398 | ci->c_inf[2].wrapbase = 0x18104000; |
| 399 | ci->c_inf[2].cib = 0x0d080401; |
| 400 | ci->c_inf[3].id = BCMA_CORE_ARM_CM3; |
| 401 | ci->c_inf[3].base = 0x18003000; |
| 402 | ci->c_inf[3].wrapbase = 0x18103000; |
| 403 | ci->c_inf[3].cib = 0x03004211; |
| 404 | ci->ramsize = 0x48000; |
| 405 | break; |
Franky Lin | a83369b | 2011-11-04 22:23:28 +0100 | [diff] [blame] | 406 | default: |
| 407 | brcmf_dbg(ERROR, "chipid 0x%x is not supported\n", ci->chip); |
| 408 | return -ENODEV; |
| 409 | } |
| 410 | |
Franky Lin | 6ca687d | 2011-11-10 20:30:21 +0100 | [diff] [blame] | 411 | switch (ci->socitype) { |
| 412 | case SOCI_SB: |
| 413 | ci->iscoreup = brcmf_sdio_sb_iscoreup; |
Franky Lin | 523894f | 2011-11-10 20:30:22 +0100 | [diff] [blame] | 414 | ci->corerev = brcmf_sdio_sb_corerev; |
Franky Lin | 086a2e0 | 2011-11-10 20:30:23 +0100 | [diff] [blame] | 415 | ci->coredisable = brcmf_sdio_sb_coredisable; |
Franky Lin | d77e70f | 2011-11-10 20:30:24 +0100 | [diff] [blame] | 416 | ci->resetcore = brcmf_sdio_sb_resetcore; |
Franky Lin | 6ca687d | 2011-11-10 20:30:21 +0100 | [diff] [blame] | 417 | break; |
| 418 | case SOCI_AI: |
| 419 | ci->iscoreup = brcmf_sdio_ai_iscoreup; |
Franky Lin | 523894f | 2011-11-10 20:30:22 +0100 | [diff] [blame] | 420 | ci->corerev = brcmf_sdio_ai_corerev; |
Franky Lin | 086a2e0 | 2011-11-10 20:30:23 +0100 | [diff] [blame] | 421 | ci->coredisable = brcmf_sdio_ai_coredisable; |
Franky Lin | d77e70f | 2011-11-10 20:30:24 +0100 | [diff] [blame] | 422 | ci->resetcore = brcmf_sdio_ai_resetcore; |
Franky Lin | 6ca687d | 2011-11-10 20:30:21 +0100 | [diff] [blame] | 423 | break; |
| 424 | default: |
| 425 | brcmf_dbg(ERROR, "socitype %u not supported\n", ci->socitype); |
| 426 | return -ENODEV; |
| 427 | } |
| 428 | |
Franky Lin | a83369b | 2011-11-04 22:23:28 +0100 | [diff] [blame] | 429 | return 0; |
| 430 | } |
| 431 | |
Franky Lin | e63ac6b | 2011-11-04 22:23:29 +0100 | [diff] [blame] | 432 | static int |
| 433 | brcmf_sdio_chip_buscoreprep(struct brcmf_sdio_dev *sdiodev) |
| 434 | { |
| 435 | int err = 0; |
| 436 | u8 clkval, clkset; |
| 437 | |
| 438 | /* Try forcing SDIO core to do ALPAvail request only */ |
| 439 | clkset = SBSDIO_FORCE_HW_CLKREQ_OFF | SBSDIO_ALP_AVAIL_REQ; |
Franky Lin | 3bba829 | 2012-05-04 18:27:33 -0700 | [diff] [blame] | 440 | brcmf_sdio_regwb(sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, clkset, &err); |
Franky Lin | e63ac6b | 2011-11-04 22:23:29 +0100 | [diff] [blame] | 441 | if (err) { |
| 442 | brcmf_dbg(ERROR, "error writing for HT off\n"); |
| 443 | return err; |
| 444 | } |
| 445 | |
| 446 | /* If register supported, wait for ALPAvail and then force ALP */ |
| 447 | /* This may take up to 15 milliseconds */ |
Franky Lin | 45db339 | 2012-05-04 18:27:32 -0700 | [diff] [blame] | 448 | clkval = brcmf_sdio_regrb(sdiodev, |
| 449 | SBSDIO_FUNC1_CHIPCLKCSR, NULL); |
Franky Lin | e63ac6b | 2011-11-04 22:23:29 +0100 | [diff] [blame] | 450 | |
| 451 | if ((clkval & ~SBSDIO_AVBITS) != clkset) { |
| 452 | brcmf_dbg(ERROR, "ChipClkCSR access: wrote 0x%02x read 0x%02x\n", |
| 453 | clkset, clkval); |
| 454 | return -EACCES; |
| 455 | } |
| 456 | |
Franky Lin | 45db339 | 2012-05-04 18:27:32 -0700 | [diff] [blame] | 457 | SPINWAIT(((clkval = brcmf_sdio_regrb(sdiodev, |
| 458 | SBSDIO_FUNC1_CHIPCLKCSR, NULL)), |
Franky Lin | e63ac6b | 2011-11-04 22:23:29 +0100 | [diff] [blame] | 459 | !SBSDIO_ALPAV(clkval)), |
| 460 | PMU_MAX_TRANSITION_DLY); |
| 461 | if (!SBSDIO_ALPAV(clkval)) { |
| 462 | brcmf_dbg(ERROR, "timeout on ALPAV wait, clkval 0x%02x\n", |
| 463 | clkval); |
| 464 | return -EBUSY; |
| 465 | } |
| 466 | |
| 467 | clkset = SBSDIO_FORCE_HW_CLKREQ_OFF | SBSDIO_FORCE_ALP; |
Franky Lin | 3bba829 | 2012-05-04 18:27:33 -0700 | [diff] [blame] | 468 | brcmf_sdio_regwb(sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, clkset, &err); |
Franky Lin | e63ac6b | 2011-11-04 22:23:29 +0100 | [diff] [blame] | 469 | udelay(65); |
| 470 | |
| 471 | /* Also, disable the extra SDIO pull-ups */ |
Franky Lin | 3bba829 | 2012-05-04 18:27:33 -0700 | [diff] [blame] | 472 | brcmf_sdio_regwb(sdiodev, SBSDIO_FUNC1_SDIOPULLUP, 0, NULL); |
Franky Lin | e63ac6b | 2011-11-04 22:23:29 +0100 | [diff] [blame] | 473 | |
| 474 | return 0; |
| 475 | } |
| 476 | |
Franky Lin | 5b45e54 | 2011-11-04 22:23:30 +0100 | [diff] [blame] | 477 | static void |
| 478 | brcmf_sdio_chip_buscoresetup(struct brcmf_sdio_dev *sdiodev, |
| 479 | struct chip_info *ci) |
| 480 | { |
Franky Lin | 79ae395 | 2012-05-04 18:27:34 -0700 | [diff] [blame] | 481 | u32 base = ci->c_inf[0].base; |
| 482 | |
Franky Lin | 5b45e54 | 2011-11-04 22:23:30 +0100 | [diff] [blame] | 483 | /* get chipcommon rev */ |
Franky Lin | 523894f | 2011-11-10 20:30:22 +0100 | [diff] [blame] | 484 | 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] | 485 | |
| 486 | /* get chipcommon capabilites */ |
Franky Lin | 79ae395 | 2012-05-04 18:27:34 -0700 | [diff] [blame] | 487 | ci->c_inf[0].caps = brcmf_sdio_regrl(sdiodev, |
| 488 | CORE_CC_REG(base, capabilities), |
| 489 | NULL); |
Franky Lin | 5b45e54 | 2011-11-04 22:23:30 +0100 | [diff] [blame] | 490 | |
| 491 | /* get pmu caps & rev */ |
Franky Lin | 99ba15c | 2011-11-04 22:23:42 +0100 | [diff] [blame] | 492 | if (ci->c_inf[0].caps & CC_CAP_PMU) { |
Franky Lin | 79ae395 | 2012-05-04 18:27:34 -0700 | [diff] [blame] | 493 | ci->pmucaps = |
| 494 | brcmf_sdio_regrl(sdiodev, |
| 495 | CORE_CC_REG(base, pmucapabilities), |
| 496 | NULL); |
Franky Lin | 5b45e54 | 2011-11-04 22:23:30 +0100 | [diff] [blame] | 497 | ci->pmurev = ci->pmucaps & PCAP_REV_MASK; |
| 498 | } |
| 499 | |
Franky Lin | 523894f | 2011-11-10 20:30:22 +0100 | [diff] [blame] | 500 | 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] | 501 | |
| 502 | 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] | 503 | ci->c_inf[0].rev, ci->pmurev, |
| 504 | ci->c_inf[1].rev, ci->c_inf[1].id); |
Franky Lin | 966414d | 2011-11-04 22:23:32 +0100 | [diff] [blame] | 505 | |
| 506 | /* |
| 507 | * Make sure any on-chip ARM is off (in case strapping is wrong), |
| 508 | * or downloaded code was already running. |
| 509 | */ |
Franky Lin | 086a2e0 | 2011-11-10 20:30:23 +0100 | [diff] [blame] | 510 | ci->coredisable(sdiodev, ci, BCMA_CORE_ARM_CM3); |
Franky Lin | 5b45e54 | 2011-11-04 22:23:30 +0100 | [diff] [blame] | 511 | } |
| 512 | |
Franky Lin | a83369b | 2011-11-04 22:23:28 +0100 | [diff] [blame] | 513 | int brcmf_sdio_chip_attach(struct brcmf_sdio_dev *sdiodev, |
Franky Lin | a97e4fc | 2011-11-04 22:23:35 +0100 | [diff] [blame] | 514 | struct chip_info **ci_ptr, u32 regs) |
Franky Lin | a83369b | 2011-11-04 22:23:28 +0100 | [diff] [blame] | 515 | { |
Franky Lin | a97e4fc | 2011-11-04 22:23:35 +0100 | [diff] [blame] | 516 | int ret; |
| 517 | struct chip_info *ci; |
| 518 | |
| 519 | brcmf_dbg(TRACE, "Enter\n"); |
| 520 | |
| 521 | /* alloc chip_info_t */ |
| 522 | ci = kzalloc(sizeof(struct chip_info), GFP_ATOMIC); |
| 523 | if (!ci) |
| 524 | return -ENOMEM; |
Franky Lin | a83369b | 2011-11-04 22:23:28 +0100 | [diff] [blame] | 525 | |
Franky Lin | e63ac6b | 2011-11-04 22:23:29 +0100 | [diff] [blame] | 526 | ret = brcmf_sdio_chip_buscoreprep(sdiodev); |
| 527 | if (ret != 0) |
Franky Lin | a97e4fc | 2011-11-04 22:23:35 +0100 | [diff] [blame] | 528 | goto err; |
Franky Lin | e63ac6b | 2011-11-04 22:23:29 +0100 | [diff] [blame] | 529 | |
Franky Lin | a83369b | 2011-11-04 22:23:28 +0100 | [diff] [blame] | 530 | ret = brcmf_sdio_chip_recognition(sdiodev, ci, regs); |
| 531 | if (ret != 0) |
Franky Lin | a97e4fc | 2011-11-04 22:23:35 +0100 | [diff] [blame] | 532 | goto err; |
Franky Lin | a83369b | 2011-11-04 22:23:28 +0100 | [diff] [blame] | 533 | |
Franky Lin | 5b45e54 | 2011-11-04 22:23:30 +0100 | [diff] [blame] | 534 | brcmf_sdio_chip_buscoresetup(sdiodev, ci); |
| 535 | |
Franky Lin | e13ce26 | 2012-05-04 18:27:35 -0700 | [diff] [blame^] | 536 | brcmf_sdio_regwl(sdiodev, CORE_CC_REG(ci->c_inf[0].base, gpiopullup), |
| 537 | 0, NULL); |
| 538 | brcmf_sdio_regwl(sdiodev, CORE_CC_REG(ci->c_inf[0].base, gpiopulldown), |
| 539 | 0, NULL); |
Franky Lin | 960908d | 2011-11-04 22:23:33 +0100 | [diff] [blame] | 540 | |
Franky Lin | a97e4fc | 2011-11-04 22:23:35 +0100 | [diff] [blame] | 541 | *ci_ptr = ci; |
| 542 | return 0; |
| 543 | |
| 544 | err: |
| 545 | kfree(ci); |
Franky Lin | a83369b | 2011-11-04 22:23:28 +0100 | [diff] [blame] | 546 | return ret; |
| 547 | } |
Franky Lin | a8a6c04 | 2011-11-04 22:23:39 +0100 | [diff] [blame] | 548 | |
| 549 | void |
| 550 | brcmf_sdio_chip_detach(struct chip_info **ci_ptr) |
| 551 | { |
| 552 | brcmf_dbg(TRACE, "Enter\n"); |
| 553 | |
| 554 | kfree(*ci_ptr); |
| 555 | *ci_ptr = NULL; |
| 556 | } |
Franky Lin | e12afb6 | 2011-11-04 22:23:40 +0100 | [diff] [blame] | 557 | |
| 558 | static char *brcmf_sdio_chip_name(uint chipid, char *buf, uint len) |
| 559 | { |
| 560 | const char *fmt; |
| 561 | |
| 562 | fmt = ((chipid > 0xa000) || (chipid < 0x4000)) ? "%d" : "%x"; |
| 563 | snprintf(buf, len, fmt, chipid); |
| 564 | return buf; |
| 565 | } |
| 566 | |
| 567 | void |
| 568 | brcmf_sdio_chip_drivestrengthinit(struct brcmf_sdio_dev *sdiodev, |
| 569 | struct chip_info *ci, u32 drivestrength) |
| 570 | { |
| 571 | struct sdiod_drive_str *str_tab = NULL; |
| 572 | u32 str_mask = 0; |
| 573 | u32 str_shift = 0; |
| 574 | char chn[8]; |
Franky Lin | 79ae395 | 2012-05-04 18:27:34 -0700 | [diff] [blame] | 575 | u32 base = ci->c_inf[0].base; |
Franky Lin | e12afb6 | 2011-11-04 22:23:40 +0100 | [diff] [blame] | 576 | |
Franky Lin | 99ba15c | 2011-11-04 22:23:42 +0100 | [diff] [blame] | 577 | if (!(ci->c_inf[0].caps & CC_CAP_PMU)) |
Franky Lin | e12afb6 | 2011-11-04 22:23:40 +0100 | [diff] [blame] | 578 | return; |
| 579 | |
| 580 | switch (SDIOD_DRVSTR_KEY(ci->chip, ci->pmurev)) { |
Franky Lin | ce2d7d7 | 2011-12-08 15:06:39 -0800 | [diff] [blame] | 581 | case SDIOD_DRVSTR_KEY(BCM4330_CHIP_ID, 12): |
Franky Lin | ffb2756 | 2011-12-08 15:06:40 -0800 | [diff] [blame] | 582 | str_tab = (struct sdiod_drive_str *)&sdiod_drvstr_tab1_1v8; |
Franky Lin | ce2d7d7 | 2011-12-08 15:06:39 -0800 | [diff] [blame] | 583 | str_mask = 0x00003800; |
| 584 | str_shift = 11; |
| 585 | break; |
Franky Lin | e12afb6 | 2011-11-04 22:23:40 +0100 | [diff] [blame] | 586 | default: |
| 587 | brcmf_dbg(ERROR, "No SDIO Drive strength init done for chip %s rev %d pmurev %d\n", |
| 588 | brcmf_sdio_chip_name(ci->chip, chn, 8), |
| 589 | ci->chiprev, ci->pmurev); |
| 590 | break; |
| 591 | } |
| 592 | |
| 593 | if (str_tab != NULL) { |
| 594 | u32 drivestrength_sel = 0; |
| 595 | u32 cc_data_temp; |
| 596 | int i; |
| 597 | |
| 598 | for (i = 0; str_tab[i].strength != 0; i++) { |
| 599 | if (drivestrength >= str_tab[i].strength) { |
| 600 | drivestrength_sel = str_tab[i].sel; |
| 601 | break; |
| 602 | } |
| 603 | } |
| 604 | |
Franky Lin | e13ce26 | 2012-05-04 18:27:35 -0700 | [diff] [blame^] | 605 | brcmf_sdio_regwl(sdiodev, CORE_CC_REG(base, chipcontrol_addr), |
| 606 | 1, NULL); |
Franky Lin | 79ae395 | 2012-05-04 18:27:34 -0700 | [diff] [blame] | 607 | cc_data_temp = |
| 608 | brcmf_sdio_regrl(sdiodev, |
| 609 | CORE_CC_REG(base, chipcontrol_addr), |
| 610 | NULL); |
Franky Lin | e12afb6 | 2011-11-04 22:23:40 +0100 | [diff] [blame] | 611 | cc_data_temp &= ~str_mask; |
| 612 | drivestrength_sel <<= str_shift; |
| 613 | cc_data_temp |= drivestrength_sel; |
Franky Lin | e13ce26 | 2012-05-04 18:27:35 -0700 | [diff] [blame^] | 614 | brcmf_sdio_regwl(sdiodev, CORE_CC_REG(base, chipcontrol_addr), |
| 615 | cc_data_temp, NULL); |
Franky Lin | e12afb6 | 2011-11-04 22:23:40 +0100 | [diff] [blame] | 616 | |
| 617 | brcmf_dbg(INFO, "SDIO: %dmA drive strength selected, set to 0x%08x\n", |
| 618 | drivestrength, cc_data_temp); |
| 619 | } |
| 620 | } |