blob: 151a67110ecfc5fa345dfd2d97bd2fbe917e6e3b [file] [log] [blame]
Franky Lina83369b2011-11-04 22:23:28 +01001/*
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +01002 * Copyright (c) 2014 Broadcom Corporation
Franky Lina83369b2011-11-04 22:23:28 +01003 *
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 */
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +010016#include <linux/kernel.h>
17#include <linux/delay.h>
18#include <linux/list.h>
Franky Lin61213be2011-11-04 22:23:41 +010019#include <linux/ssb/ssb_regs.h>
Franky Lin99ba15c2011-11-04 22:23:42 +010020#include <linux/bcma/bcma.h>
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +010021#include <linux/bcma/bcma_regs.h>
Franky Lin61213be2011-11-04 22:23:41 +010022
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +010023#include <defs.h>
Franky Lin2d4a9af2011-11-04 22:23:31 +010024#include <soc.h>
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +010025#include <brcm_hw_ids.h>
26#include <brcmu_utils.h>
27#include <chipcommon.h>
Franky Lina83369b2011-11-04 22:23:28 +010028#include "dhd_dbg.h"
Arend van Spriel20c9c9b2014-01-29 15:32:15 +010029#include "chip.h"
Franky Lina83369b2011-11-04 22:23:28 +010030
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +010031/* SOC Interconnect types (aka chip types) */
32#define SOCI_SB 0
33#define SOCI_AI 1
34
35/* EROM CompIdentB */
36#define CIB_REV_MASK 0xff000000
37#define CIB_REV_SHIFT 24
38
39/* ARM CR4 core specific control flag bits */
40#define ARMCR4_BCMA_IOCTL_CPUHALT 0x0020
41
42/* D11 core specific control flag bits */
43#define D11_BCMA_IOCTL_PHYCLOCKEN 0x0004
44#define D11_BCMA_IOCTL_PHYRESET 0x0008
45
Franky Lina83369b2011-11-04 22:23:28 +010046/* chip core base & ramsize */
47/* bcm4329 */
48/* SDIO device core, ID 0x829 */
49#define BCM4329_CORE_BUS_BASE 0x18011000
50/* internal memory core, ID 0x80e */
51#define BCM4329_CORE_SOCRAM_BASE 0x18003000
52/* ARM Cortex M3 core, ID 0x82a */
53#define BCM4329_CORE_ARM_BASE 0x18002000
54#define BCM4329_RAMSIZE 0x48000
55
Hante Meuleman369508c2013-04-11 13:28:54 +020056/* bcm43143 */
57/* SDIO device core */
58#define BCM43143_CORE_BUS_BASE 0x18002000
59/* internal memory core */
60#define BCM43143_CORE_SOCRAM_BASE 0x18004000
61/* ARM Cortex M3 core, ID 0x82a */
62#define BCM43143_CORE_ARM_BASE 0x18003000
63#define BCM43143_RAMSIZE 0x70000
64
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +010065#define CORE_SB(base, field) \
66 (base + SBCONFIGOFF + offsetof(struct sbconfig, field))
Franky Lina83369b2011-11-04 22:23:28 +010067#define SBCOREREV(sbidh) \
Franky Lin61213be2011-11-04 22:23:41 +010068 ((((sbidh) & SSB_IDHIGH_RCHI) >> SSB_IDHIGH_RCHI_SHIFT) | \
69 ((sbidh) & SSB_IDHIGH_RCLO))
Franky Lina83369b2011-11-04 22:23:28 +010070
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +010071struct sbconfig {
72 u32 PAD[2];
73 u32 sbipsflag; /* initiator port ocp slave flag */
74 u32 PAD[3];
75 u32 sbtpsflag; /* target port ocp slave flag */
76 u32 PAD[11];
77 u32 sbtmerrloga; /* (sonics >= 2.3) */
78 u32 PAD;
79 u32 sbtmerrlog; /* (sonics >= 2.3) */
80 u32 PAD[3];
81 u32 sbadmatch3; /* address match3 */
82 u32 PAD;
83 u32 sbadmatch2; /* address match2 */
84 u32 PAD;
85 u32 sbadmatch1; /* address match1 */
86 u32 PAD[7];
87 u32 sbimstate; /* initiator agent state */
88 u32 sbintvec; /* interrupt mask */
89 u32 sbtmstatelow; /* target state */
90 u32 sbtmstatehigh; /* target state */
91 u32 sbbwa0; /* bandwidth allocation table0 */
92 u32 PAD;
93 u32 sbimconfiglow; /* initiator configuration */
94 u32 sbimconfighigh; /* initiator configuration */
95 u32 sbadmatch0; /* address match0 */
96 u32 PAD;
97 u32 sbtmconfiglow; /* target configuration */
98 u32 sbtmconfighigh; /* target configuration */
99 u32 sbbconfig; /* broadcast configuration */
100 u32 PAD;
101 u32 sbbstate; /* broadcast state */
102 u32 PAD[3];
103 u32 sbactcnfg; /* activate configuration */
104 u32 PAD[3];
105 u32 sbflagst; /* current sbflags */
106 u32 PAD[3];
107 u32 sbidlow; /* identification */
108 u32 sbidhigh; /* identification */
109};
Franky Lin6ca687d2011-11-10 20:30:21 +0100110
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100111struct brcmf_core_priv {
112 struct brcmf_core pub;
113 u32 wrapbase;
114 struct list_head list;
115 struct brcmf_chip_priv *chip;
116};
Franky Lin523894f2011-11-10 20:30:22 +0100117
Franky Lin1640f282013-04-11 13:28:51 +0200118/* ARM CR4 core specific control flag bits */
119#define ARMCR4_BCMA_IOCTL_CPUHALT 0x0020
120
Hante Meuleman53036262014-01-13 22:20:23 +0100121/* D11 core specific control flag bits */
122#define D11_BCMA_IOCTL_PHYCLOCKEN 0x0004
123#define D11_BCMA_IOCTL_PHYRESET 0x0008
124
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100125struct brcmf_chip_priv {
126 struct brcmf_chip pub;
127 const struct brcmf_buscore_ops *ops;
128 void *ctx;
129 /* assured first core is chipcommon, second core is buscore */
130 struct list_head cores;
131 u16 num_cores;
Franky Lin99ba15c2011-11-04 22:23:42 +0100132
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100133 bool (*iscoreup)(struct brcmf_core_priv *core);
134 void (*coredisable)(struct brcmf_core_priv *core, u32 prereset,
135 u32 reset);
136 void (*resetcore)(struct brcmf_core_priv *core, u32 prereset, u32 reset,
137 u32 postreset);
138};
Franky Lin99ba15c2011-11-04 22:23:42 +0100139
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100140static void brcmf_chip_sb_corerev(struct brcmf_chip_priv *ci,
141 struct brcmf_core *core)
Franky Lin454d2a82011-11-04 22:23:37 +0100142{
143 u32 regdata;
Franky Lin523894f2011-11-10 20:30:22 +0100144
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100145 regdata = ci->ops->read32(ci->ctx, CORE_SB(core->base, sbidhigh));
146 core->rev = SBCOREREV(regdata);
Franky Lin454d2a82011-11-04 22:23:37 +0100147}
148
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100149static bool brcmf_chip_sb_iscoreup(struct brcmf_core_priv *core)
Franky Lin523894f2011-11-10 20:30:22 +0100150{
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100151 struct brcmf_chip_priv *ci;
Franky Lind8f64a42011-11-04 22:23:36 +0100152 u32 regdata;
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100153 u32 address;
Franky Lin6ca687d2011-11-10 20:30:21 +0100154
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100155 ci = core->chip;
156 address = CORE_SB(core->pub.base, sbtmstatelow);
157 regdata = ci->ops->read32(ci->ctx, address);
Franky Lin61213be2011-11-04 22:23:41 +0100158 regdata &= (SSB_TMSLOW_RESET | SSB_TMSLOW_REJECT |
159 SSB_IMSTATE_REJECT | SSB_TMSLOW_CLOCK);
Arend van Spriel20c9c9b2014-01-29 15:32:15 +0100160 return SSB_TMSLOW_CLOCK == regdata;
Franky Lind8f64a42011-11-04 22:23:36 +0100161}
162
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100163static bool brcmf_chip_ai_iscoreup(struct brcmf_core_priv *core)
Franky Lin6ca687d2011-11-10 20:30:21 +0100164{
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100165 struct brcmf_chip_priv *ci;
Franky Lin6ca687d2011-11-10 20:30:21 +0100166 u32 regdata;
Franky Lin6ca687d2011-11-10 20:30:21 +0100167 bool ret;
168
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100169 ci = core->chip;
170 regdata = ci->ops->read32(ci->ctx, core->wrapbase + BCMA_IOCTL);
Franky Lin6ca687d2011-11-10 20:30:21 +0100171 ret = (regdata & (BCMA_IOCTL_FGC | BCMA_IOCTL_CLK)) == BCMA_IOCTL_CLK;
172
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100173 regdata = ci->ops->read32(ci->ctx, core->wrapbase + BCMA_RESET_CTL);
Franky Lin6ca687d2011-11-10 20:30:21 +0100174 ret = ret && ((regdata & BCMA_RESET_CTL_RESET) == 0);
175
176 return ret;
177}
178
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100179static void brcmf_chip_sb_coredisable(struct brcmf_core_priv *core,
180 u32 prereset, u32 reset)
Franky Lin2d4a9af2011-11-04 22:23:31 +0100181{
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100182 struct brcmf_chip_priv *ci;
183 u32 val, base;
Franky Lin086a2e02011-11-10 20:30:23 +0100184
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100185 ci = core->chip;
186 base = core->pub.base;
187 val = ci->ops->read32(ci->ctx, CORE_SB(base, sbtmstatelow));
188 if (val & SSB_TMSLOW_RESET)
Franky Lin2d4a9af2011-11-04 22:23:31 +0100189 return;
190
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100191 val = ci->ops->read32(ci->ctx, CORE_SB(base, sbtmstatelow));
192 if ((val & SSB_TMSLOW_CLOCK) != 0) {
Franky Lin2d4a9af2011-11-04 22:23:31 +0100193 /*
194 * set target reject and spin until busy is clear
195 * (preserve core-specific bits)
196 */
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100197 val = ci->ops->read32(ci->ctx, CORE_SB(base, sbtmstatelow));
198 ci->ops->write32(ci->ctx, CORE_SB(base, sbtmstatelow),
199 val | SSB_TMSLOW_REJECT);
Franky Lin2d4a9af2011-11-04 22:23:31 +0100200
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100201 val = ci->ops->read32(ci->ctx, CORE_SB(base, sbtmstatelow));
Franky Lin2d4a9af2011-11-04 22:23:31 +0100202 udelay(1);
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100203 SPINWAIT((ci->ops->read32(ci->ctx, CORE_SB(base, sbtmstatehigh))
204 & SSB_TMSHIGH_BUSY), 100000);
Franky Lin2d4a9af2011-11-04 22:23:31 +0100205
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100206 val = ci->ops->read32(ci->ctx, CORE_SB(base, sbtmstatehigh));
207 if (val & SSB_TMSHIGH_BUSY)
Arend van Spriel5e8149f2012-12-07 10:49:57 +0100208 brcmf_err("core state still busy\n");
Franky Lin2d4a9af2011-11-04 22:23:31 +0100209
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100210 val = ci->ops->read32(ci->ctx, CORE_SB(base, sbidlow));
211 if (val & SSB_IDLOW_INITIATOR) {
212 val = ci->ops->read32(ci->ctx,
213 CORE_SB(base, sbimstate));
214 val |= SSB_IMSTATE_REJECT;
215 ci->ops->write32(ci->ctx,
216 CORE_SB(base, sbimstate), val);
217 val = ci->ops->read32(ci->ctx,
218 CORE_SB(base, sbimstate));
Franky Lin2d4a9af2011-11-04 22:23:31 +0100219 udelay(1);
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100220 SPINWAIT((ci->ops->read32(ci->ctx,
221 CORE_SB(base, sbimstate)) &
Arend van Spriela39be272013-12-12 11:58:58 +0100222 SSB_IMSTATE_BUSY), 100000);
Franky Lin2d4a9af2011-11-04 22:23:31 +0100223 }
224
225 /* set reset and reject while enabling the clocks */
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100226 val = SSB_TMSLOW_FGC | SSB_TMSLOW_CLOCK |
227 SSB_TMSLOW_REJECT | SSB_TMSLOW_RESET;
228 ci->ops->write32(ci->ctx, CORE_SB(base, sbtmstatelow), val);
229 val = ci->ops->read32(ci->ctx, CORE_SB(base, sbtmstatelow));
Franky Lin2d4a9af2011-11-04 22:23:31 +0100230 udelay(10);
231
232 /* clear the initiator reject bit */
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100233 val = ci->ops->read32(ci->ctx, CORE_SB(base, sbidlow));
234 if (val & SSB_IDLOW_INITIATOR) {
235 val = ci->ops->read32(ci->ctx,
236 CORE_SB(base, sbimstate));
237 val &= ~SSB_IMSTATE_REJECT;
238 ci->ops->write32(ci->ctx,
239 CORE_SB(base, sbimstate), val);
Franky Lin2d4a9af2011-11-04 22:23:31 +0100240 }
241 }
242
243 /* leave reset and reject asserted */
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100244 ci->ops->write32(ci->ctx, CORE_SB(base, sbtmstatelow),
245 (SSB_TMSLOW_REJECT | SSB_TMSLOW_RESET));
Franky Lin2d4a9af2011-11-04 22:23:31 +0100246 udelay(1);
247}
248
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100249static void brcmf_chip_ai_coredisable(struct brcmf_core_priv *core,
250 u32 prereset, u32 reset)
Franky Lin086a2e02011-11-10 20:30:23 +0100251{
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100252 struct brcmf_chip_priv *ci;
Franky Lin086a2e02011-11-10 20:30:23 +0100253 u32 regdata;
254
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100255 ci = core->chip;
Hante Meuleman53036262014-01-13 22:20:23 +0100256
Franky Lin086a2e02011-11-10 20:30:23 +0100257 /* if core is already in reset, just return */
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100258 regdata = ci->ops->read32(ci->ctx, core->wrapbase + BCMA_RESET_CTL);
Franky Lin086a2e02011-11-10 20:30:23 +0100259 if ((regdata & BCMA_RESET_CTL_RESET) != 0)
260 return;
261
Hante Meuleman53036262014-01-13 22:20:23 +0100262 /* configure reset */
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100263 ci->ops->write32(ci->ctx, core->wrapbase + BCMA_IOCTL,
264 prereset | BCMA_IOCTL_FGC | BCMA_IOCTL_CLK);
265 ci->ops->read32(ci->ctx, core->wrapbase + BCMA_IOCTL);
Franky Lin086a2e02011-11-10 20:30:23 +0100266
Hante Meuleman53036262014-01-13 22:20:23 +0100267 /* put in reset */
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100268 ci->ops->write32(ci->ctx, core->wrapbase + BCMA_RESET_CTL,
269 BCMA_RESET_CTL_RESET);
Franky Lin1640f282013-04-11 13:28:51 +0200270 usleep_range(10, 20);
271
Hante Meuleman53036262014-01-13 22:20:23 +0100272 /* wait till reset is 1 */
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100273 SPINWAIT(ci->ops->read32(ci->ctx, core->wrapbase + BCMA_RESET_CTL) !=
Hante Meuleman53036262014-01-13 22:20:23 +0100274 BCMA_RESET_CTL_RESET, 300);
275
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100276 /* in-reset configure */
277 ci->ops->write32(ci->ctx, core->wrapbase + BCMA_IOCTL,
278 reset | BCMA_IOCTL_FGC | BCMA_IOCTL_CLK);
279 ci->ops->read32(ci->ctx, core->wrapbase + BCMA_IOCTL);
Franky Lin086a2e02011-11-10 20:30:23 +0100280}
281
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100282static void brcmf_chip_sb_resetcore(struct brcmf_core_priv *core, u32 prereset,
283 u32 reset, u32 postreset)
Franky Lin2bc78e12011-11-04 22:23:38 +0100284{
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100285 struct brcmf_chip_priv *ci;
Franky Lin2bc78e12011-11-04 22:23:38 +0100286 u32 regdata;
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100287 u32 base;
Franky Lin086a2e02011-11-10 20:30:23 +0100288
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100289 ci = core->chip;
290 base = core->pub.base;
Franky Lin2bc78e12011-11-04 22:23:38 +0100291 /*
292 * Must do the disable sequence first to work for
293 * arbitrary current core state.
294 */
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100295 brcmf_chip_sb_coredisable(core, 0, 0);
Franky Lin2bc78e12011-11-04 22:23:38 +0100296
297 /*
298 * Now do the initialization sequence.
299 * set reset while enabling the clock and
300 * forcing them on throughout the core
301 */
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100302 ci->ops->write32(ci->ctx, CORE_SB(base, sbtmstatelow),
303 SSB_TMSLOW_FGC | SSB_TMSLOW_CLOCK |
304 SSB_TMSLOW_RESET);
305 regdata = ci->ops->read32(ci->ctx, CORE_SB(base, sbtmstatelow));
Franky Lin2bc78e12011-11-04 22:23:38 +0100306 udelay(1);
307
Franky Lind77e70f2011-11-10 20:30:24 +0100308 /* clear any serror */
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100309 regdata = ci->ops->read32(ci->ctx, CORE_SB(base, sbtmstatehigh));
Franky Lin61213be2011-11-04 22:23:41 +0100310 if (regdata & SSB_TMSHIGH_SERR)
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100311 ci->ops->write32(ci->ctx, CORE_SB(base, sbtmstatehigh), 0);
Franky Lin2bc78e12011-11-04 22:23:38 +0100312
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100313 regdata = ci->ops->read32(ci->ctx, CORE_SB(base, sbimstate));
314 if (regdata & (SSB_IMSTATE_IBE | SSB_IMSTATE_TO)) {
315 regdata &= ~(SSB_IMSTATE_IBE | SSB_IMSTATE_TO);
316 ci->ops->write32(ci->ctx, CORE_SB(base, sbimstate), regdata);
317 }
Franky Lin2bc78e12011-11-04 22:23:38 +0100318
319 /* clear reset and allow it to propagate throughout the core */
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100320 ci->ops->write32(ci->ctx, CORE_SB(base, sbtmstatelow),
321 SSB_TMSLOW_FGC | SSB_TMSLOW_CLOCK);
322 regdata = ci->ops->read32(ci->ctx, CORE_SB(base, sbtmstatelow));
Franky Lin2bc78e12011-11-04 22:23:38 +0100323 udelay(1);
324
325 /* leave clock enabled */
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100326 ci->ops->write32(ci->ctx, CORE_SB(base, sbtmstatelow),
327 SSB_TMSLOW_CLOCK);
328 regdata = ci->ops->read32(ci->ctx, CORE_SB(base, sbtmstatelow));
Franky Lind77e70f2011-11-10 20:30:24 +0100329 udelay(1);
330}
331
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100332static void brcmf_chip_ai_resetcore(struct brcmf_core_priv *core, u32 prereset,
333 u32 reset, u32 postreset)
Franky Lind77e70f2011-11-10 20:30:24 +0100334{
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100335 struct brcmf_chip_priv *ci;
336 int count;
Franky Lind77e70f2011-11-10 20:30:24 +0100337
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100338 ci = core->chip;
Hante Meuleman53036262014-01-13 22:20:23 +0100339
Franky Lind77e70f2011-11-10 20:30:24 +0100340 /* must disable first to work for arbitrary current core state */
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100341 brcmf_chip_ai_coredisable(core, prereset, reset);
Franky Lind77e70f2011-11-10 20:30:24 +0100342
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100343 count = 0;
344 while (ci->ops->read32(ci->ctx, core->wrapbase + BCMA_RESET_CTL) &
Hante Meuleman53036262014-01-13 22:20:23 +0100345 BCMA_RESET_CTL_RESET) {
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100346 ci->ops->write32(ci->ctx, core->wrapbase + BCMA_RESET_CTL, 0);
347 count++;
348 if (count > 50)
349 break;
Hante Meuleman53036262014-01-13 22:20:23 +0100350 usleep_range(40, 60);
351 }
Franky Lind77e70f2011-11-10 20:30:24 +0100352
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100353 ci->ops->write32(ci->ctx, core->wrapbase + BCMA_IOCTL,
354 postreset | BCMA_IOCTL_CLK);
355 ci->ops->read32(ci->ctx, core->wrapbase + BCMA_IOCTL);
356}
357
358static char *brcmf_chip_name(uint chipid, char *buf, uint len)
359{
360 const char *fmt;
361
362 fmt = ((chipid > 0xa000) || (chipid < 0x4000)) ? "%d" : "%x";
363 snprintf(buf, len, fmt, chipid);
364 return buf;
365}
366
367static struct brcmf_core *brcmf_chip_add_core(struct brcmf_chip_priv *ci,
368 u16 coreid, u32 base,
369 u32 wrapbase)
370{
371 struct brcmf_core_priv *core;
372
373 core = kzalloc(sizeof(*core), GFP_KERNEL);
374 if (!core)
375 return ERR_PTR(-ENOMEM);
376
377 core->pub.id = coreid;
378 core->pub.base = base;
379 core->chip = ci;
380 core->wrapbase = wrapbase;
381
382 list_add_tail(&core->list, &ci->cores);
383 return &core->pub;
Franky Lin2bc78e12011-11-04 22:23:38 +0100384}
385
Franky Lin1640f282013-04-11 13:28:51 +0200386#ifdef DEBUG
387/* safety check for chipinfo */
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100388static int brcmf_chip_cores_check(struct brcmf_chip_priv *ci)
Franky Lin1640f282013-04-11 13:28:51 +0200389{
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100390 struct brcmf_core_priv *core;
391 bool need_socram = false;
392 bool has_socram = false;
393 int idx = 1;
394
395 list_for_each_entry(core, &ci->cores, list) {
396 brcmf_dbg(INFO, " [%-2d] core 0x%x rev %-2d base 0x%08x\n",
397 idx++, core->pub.id, core->pub.rev, core->pub.base);
398
399 switch (core->pub.id) {
400 case BCMA_CORE_ARM_CM3:
401 need_socram = true;
402 break;
403 case BCMA_CORE_INTERNAL_MEM:
404 has_socram = true;
405 break;
406 case BCMA_CORE_ARM_CR4:
407 if (ci->pub.rambase == 0) {
408 brcmf_err("RAM base not provided with ARM CR4 core\n");
409 return -ENOMEM;
410 }
411 break;
412 default:
413 break;
414 }
415 }
Franky Lin1640f282013-04-11 13:28:51 +0200416
417 /* check RAM core presence for ARM CM3 core */
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100418 if (need_socram && !has_socram) {
419 brcmf_err("RAM core not provided with ARM CM3 core\n");
420 return -ENODEV;
Franky Lin1640f282013-04-11 13:28:51 +0200421 }
Franky Lin1640f282013-04-11 13:28:51 +0200422 return 0;
423}
424#else /* DEBUG */
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100425static inline int brcmf_chip_cores_check(struct brcmf_chip_priv *ci)
Franky Lin1640f282013-04-11 13:28:51 +0200426{
427 return 0;
428}
429#endif
430
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100431static void brcmf_chip_get_raminfo(struct brcmf_chip_priv *ci)
Franky Lina83369b2011-11-04 22:23:28 +0100432{
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100433 switch (ci->pub.chip) {
434 case BCM4329_CHIP_ID:
435 ci->pub.ramsize = BCM4329_RAMSIZE;
436 break;
437 case BCM43143_CHIP_ID:
438 ci->pub.ramsize = BCM43143_RAMSIZE;
439 break;
440 case BCM43241_CHIP_ID:
441 ci->pub.ramsize = 0x90000;
442 break;
443 case BCM4330_CHIP_ID:
444 ci->pub.ramsize = 0x48000;
445 break;
446 case BCM4334_CHIP_ID:
447 ci->pub.ramsize = 0x80000;
448 break;
449 case BCM4335_CHIP_ID:
450 ci->pub.ramsize = 0xc0000;
451 ci->pub.rambase = 0x180000;
452 break;
453 case BCM43362_CHIP_ID:
454 ci->pub.ramsize = 0x3c000;
455 break;
456 case BCM4339_CHIP_ID:
457 ci->pub.ramsize = 0xc0000;
458 ci->pub.rambase = 0x180000;
459 break;
460 default:
461 brcmf_err("unknown chip: %s\n", ci->pub.name);
462 break;
463 }
464}
465
466static int brcmf_chip_recognition(struct brcmf_chip_priv *ci)
467{
468 struct brcmf_core *core;
Franky Lina83369b2011-11-04 22:23:28 +0100469 u32 regdata;
Arend van Sprielc805eeb2014-01-13 22:20:26 +0100470 u32 socitype;
Franky Lina83369b2011-11-04 22:23:28 +0100471
Franky Lin069eddd2013-04-11 13:28:48 +0200472 /* Get CC core rev
Arend van Sprielc805eeb2014-01-13 22:20:26 +0100473 * Chipid is assume to be at offset 0 from SI_ENUM_BASE
Franky Lina83369b2011-11-04 22:23:28 +0100474 * For different chiptypes or old sdio hosts w/o chipcommon,
475 * other ways of recognition should be added here.
476 */
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100477 regdata = ci->ops->read32(ci->ctx, CORE_CC_REG(SI_ENUM_BASE, chipid));
478 ci->pub.chip = regdata & CID_ID_MASK;
479 ci->pub.chiprev = (regdata & CID_REV_MASK) >> CID_REV_SHIFT;
Arend van Sprielc805eeb2014-01-13 22:20:26 +0100480 socitype = (regdata & CID_TYPE_MASK) >> CID_TYPE_SHIFT;
Franky Lina83369b2011-11-04 22:23:28 +0100481
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100482 brcmf_chip_name(ci->pub.chip, ci->pub.name, sizeof(ci->pub.name));
483 brcmf_dbg(INFO, "found %s chip: BCM%s, rev=%d\n",
484 socitype == SOCI_SB ? "SB" : "AXI", ci->pub.name,
485 ci->pub.chiprev);
Franky Lina83369b2011-11-04 22:23:28 +0100486
Arend van Sprielc805eeb2014-01-13 22:20:26 +0100487 if (socitype == SOCI_SB) {
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100488 if (ci->pub.chip != BCM4329_CHIP_ID) {
Arend van Sprielc805eeb2014-01-13 22:20:26 +0100489 brcmf_err("SB chip is not supported\n");
490 return -ENODEV;
491 }
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100492 ci->iscoreup = brcmf_chip_sb_iscoreup;
493 ci->coredisable = brcmf_chip_sb_coredisable;
494 ci->resetcore = brcmf_chip_sb_resetcore;
Arend van Sprielc805eeb2014-01-13 22:20:26 +0100495
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100496 core = brcmf_chip_add_core(ci, BCMA_CORE_CHIPCOMMON,
497 SI_ENUM_BASE, 0);
498 brcmf_chip_sb_corerev(ci, core);
499 core = brcmf_chip_add_core(ci, BCMA_CORE_SDIO_DEV,
500 BCM4329_CORE_BUS_BASE, 0);
501 brcmf_chip_sb_corerev(ci, core);
502 core = brcmf_chip_add_core(ci, BCMA_CORE_INTERNAL_MEM,
503 BCM4329_CORE_SOCRAM_BASE, 0);
504 brcmf_chip_sb_corerev(ci, core);
505 core = brcmf_chip_add_core(ci, BCMA_CORE_ARM_CM3,
506 BCM4329_CORE_ARM_BASE, 0);
507 brcmf_chip_sb_corerev(ci, core);
Arend van Sprielc805eeb2014-01-13 22:20:26 +0100508 } else if (socitype == SOCI_AI) {
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100509 ci->iscoreup = brcmf_chip_ai_iscoreup;
510 ci->coredisable = brcmf_chip_ai_coredisable;
511 ci->resetcore = brcmf_chip_ai_resetcore;
Arend van Sprielc805eeb2014-01-13 22:20:26 +0100512
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100513 core = brcmf_chip_add_core(ci, BCMA_CORE_CHIPCOMMON,
514 SI_ENUM_BASE,
515 SI_ENUM_BASE + 0x100000);
Arend van Sprielc805eeb2014-01-13 22:20:26 +0100516
517 /* Address of cores for new chips should be added here */
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100518 switch (ci->pub.chip) {
Arend van Sprielc805eeb2014-01-13 22:20:26 +0100519 case BCM43143_CHIP_ID:
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100520 core->rev = 43;
521 core = brcmf_chip_add_core(ci, BCMA_CORE_SDIO_DEV,
522 BCM43143_CORE_BUS_BASE,
523 BCM43143_CORE_BUS_BASE +
524 0x100000);
525 core->rev = 24;
526 core = brcmf_chip_add_core(ci, BCMA_CORE_INTERNAL_MEM,
527 BCM43143_CORE_SOCRAM_BASE,
528 BCM43143_CORE_SOCRAM_BASE +
529 0x100000);
530 core->rev = 20;
531 core = brcmf_chip_add_core(ci, BCMA_CORE_ARM_CM3,
532 BCM43143_CORE_ARM_BASE,
533 BCM43143_CORE_ARM_BASE +
534 0x100000);
535 core->rev = 7;
Arend van Sprielc805eeb2014-01-13 22:20:26 +0100536 break;
537 case BCM43241_CHIP_ID:
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100538 core->rev = 42;
539 core = brcmf_chip_add_core(ci, BCMA_CORE_SDIO_DEV,
540 0x18002000, 0x18102000);
541 core->rev = 14;
542 core = brcmf_chip_add_core(ci, BCMA_CORE_INTERNAL_MEM,
543 0x18004000, 0x18104000);
544 core->rev = 20;
545 core = brcmf_chip_add_core(ci, BCMA_CORE_ARM_CM3,
546 0x18003000, 0x18103000);
547 core->rev = 7;
Arend van Sprielc805eeb2014-01-13 22:20:26 +0100548 break;
549 case BCM4330_CHIP_ID:
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100550 core->rev = 39;
551 core = brcmf_chip_add_core(ci, BCMA_CORE_SDIO_DEV,
552 0x18002000, 0x18102000);
553 core->rev = 7;
554 core = brcmf_chip_add_core(ci, BCMA_CORE_INTERNAL_MEM,
555 0x18004000, 0x18104000);
556 core->rev = 13;
557 core = brcmf_chip_add_core(ci, BCMA_CORE_ARM_CM3,
558 0x18003000, 0x18103000);
559 core->rev = 3;
Arend van Sprielc805eeb2014-01-13 22:20:26 +0100560 break;
561 case BCM4334_CHIP_ID:
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100562 core->rev = 41;
563 core = brcmf_chip_add_core(ci, BCMA_CORE_SDIO_DEV,
564 0x18002000, 0x18102000);
565 core->rev = 13;
566 core = brcmf_chip_add_core(ci, BCMA_CORE_INTERNAL_MEM,
567 0x18004000, 0x18104000);
568 core->rev = 19;
569 core = brcmf_chip_add_core(ci, BCMA_CORE_ARM_CM3,
570 0x18003000, 0x18103000);
571 core->rev = 7;
Arend van Sprielc805eeb2014-01-13 22:20:26 +0100572 break;
573 case BCM4335_CHIP_ID:
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100574 core->rev = 43;
575 core = brcmf_chip_add_core(ci, BCMA_CORE_SDIO_DEV,
576 0x18005000, 0x18105000);
577 core->rev = 15;
578 core = brcmf_chip_add_core(ci, BCMA_CORE_ARM_CR4,
579 0x18002000, 0x18102000);
580 core->rev = 1;
Arend van Sprielc805eeb2014-01-13 22:20:26 +0100581 break;
582 case BCM43362_CHIP_ID:
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100583 core->rev = 39;
584 core = brcmf_chip_add_core(ci, BCMA_CORE_SDIO_DEV,
585 0x18002000, 0x18102000);
586 core->rev = 10;
587 core = brcmf_chip_add_core(ci, BCMA_CORE_INTERNAL_MEM,
588 0x18004000, 0x18104000);
589 core->rev = 8;
590 core = brcmf_chip_add_core(ci, BCMA_CORE_ARM_CM3,
591 0x18003000, 0x18103000);
592 core->rev = 3;
Arend van Sprielc805eeb2014-01-13 22:20:26 +0100593 break;
594 case BCM4339_CHIP_ID:
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100595 core->rev = 46;
596 core = brcmf_chip_add_core(ci, BCMA_CORE_SDIO_DEV,
597 0x18005000, 0x18105000);
598 core->rev = 21;
599 core = brcmf_chip_add_core(ci, BCMA_CORE_ARM_CR4,
600 0x18002000, 0x18102000);
601 core->rev = 4;
Arend van Sprielc805eeb2014-01-13 22:20:26 +0100602 break;
603 default:
604 brcmf_err("AXI chip is not supported\n");
605 return -ENODEV;
606 }
607 } else {
608 brcmf_err("chip backplane type %u is not supported\n",
609 socitype);
Franky Lin6ca687d2011-11-10 20:30:21 +0100610 return -ENODEV;
611 }
612
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100613 /* add 802.11 core for all chips on same backplane address */
614 core = brcmf_chip_add_core(ci, BCMA_CORE_80211, 0x18001000, 0x18101000);
615
616 brcmf_chip_get_raminfo(ci);
617
618 return brcmf_chip_cores_check(ci);
Franky Lina83369b2011-11-04 22:23:28 +0100619}
620
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100621static void brcmf_chip_disable_arm(struct brcmf_chip_priv *chip, u16 id)
Franky Lin5b45e542011-11-04 22:23:30 +0100622{
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100623 struct brcmf_core *core;
624 struct brcmf_core_priv *cr4;
625 u32 val;
Franky Lin79ae3952012-05-04 18:27:34 -0700626
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100627
628 core = brcmf_chip_get_core(&chip->pub, id);
629 if (!core)
630 return;
631
632 switch (id) {
633 case BCMA_CORE_ARM_CM3:
634 brcmf_chip_coredisable(core, 0, 0);
635 break;
636 case BCMA_CORE_ARM_CR4:
637 cr4 = container_of(core, struct brcmf_core_priv, pub);
638
639 /* clear all IOCTL bits except HALT bit */
640 val = chip->ops->read32(chip->ctx, cr4->wrapbase + BCMA_IOCTL);
641 val &= ARMCR4_BCMA_IOCTL_CPUHALT;
642 brcmf_chip_resetcore(core, val, ARMCR4_BCMA_IOCTL_CPUHALT,
643 ARMCR4_BCMA_IOCTL_CPUHALT);
644 break;
645 default:
646 brcmf_err("unknown id: %u\n", id);
647 break;
648 }
649}
650
651static int brcmf_chip_setup(struct brcmf_chip_priv *chip)
652{
653 struct brcmf_chip *pub;
654 struct brcmf_core_priv *cc;
655 struct brcmf_core_priv *bus;
656 u32 base;
657 u32 val;
658 int ret = 0;
659
660 pub = &chip->pub;
661 cc = list_first_entry(&chip->cores, struct brcmf_core_priv, list);
662 base = cc->pub.base;
Franky Lin5b45e542011-11-04 22:23:30 +0100663
664 /* get chipcommon capabilites */
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100665 pub->cc_caps = chip->ops->read32(chip->ctx,
666 CORE_CC_REG(base, capabilities));
Franky Lin5b45e542011-11-04 22:23:30 +0100667
668 /* get pmu caps & rev */
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100669 if (pub->cc_caps & CC_CAP_PMU) {
670 val = chip->ops->read32(chip->ctx,
671 CORE_CC_REG(base, pmucapabilities));
672 pub->pmurev = val & PCAP_REV_MASK;
673 pub->pmucaps = val;
Franky Lin5b45e542011-11-04 22:23:30 +0100674 }
675
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100676 bus = list_next_entry(cc, list);
Franky Lin5b45e542011-11-04 22:23:30 +0100677
678 brcmf_dbg(INFO, "ccrev=%d, pmurev=%d, buscore rev/type=%d/0x%x\n",
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100679 cc->pub.rev, pub->pmurev, bus->pub.rev, bus->pub.id);
680
681 /* execute bus core specific setup */
682 if (chip->ops->setup)
683 ret = chip->ops->setup(chip->ctx, pub);
Franky Lin966414d2011-11-04 22:23:32 +0100684
685 /*
686 * Make sure any on-chip ARM is off (in case strapping is wrong),
687 * or downloaded code was already running.
688 */
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100689 brcmf_chip_disable_arm(chip, BCMA_CORE_ARM_CM3);
690 brcmf_chip_disable_arm(chip, BCMA_CORE_ARM_CR4);
Franky Lina83369b2011-11-04 22:23:28 +0100691 return ret;
692}
Franky Lina8a6c042011-11-04 22:23:39 +0100693
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100694struct brcmf_chip *brcmf_chip_attach(void *ctx,
695 const struct brcmf_buscore_ops *ops)
Franky Lina8a6c042011-11-04 22:23:39 +0100696{
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100697 struct brcmf_chip_priv *chip;
698 int err = 0;
Franky Lina8a6c042011-11-04 22:23:39 +0100699
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100700 if (WARN_ON(!ops->read32))
701 err = -EINVAL;
702 if (WARN_ON(!ops->write32))
703 err = -EINVAL;
704 if (WARN_ON(!ops->prepare))
705 err = -EINVAL;
706 if (WARN_ON(!ops->exit_dl))
707 err = -EINVAL;
708 if (err < 0)
709 return ERR_PTR(-EINVAL);
710
711 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
712 if (!chip)
713 return ERR_PTR(-ENOMEM);
714
715 INIT_LIST_HEAD(&chip->cores);
716 chip->num_cores = 0;
717 chip->ops = ops;
718 chip->ctx = ctx;
719
720 err = ops->prepare(ctx);
721 if (err < 0)
722 goto fail;
723
724 err = brcmf_chip_recognition(chip);
725 if (err < 0)
726 goto fail;
727
728 err = brcmf_chip_setup(chip);
729 if (err < 0)
730 goto fail;
731
732 return &chip->pub;
733
734fail:
735 brcmf_chip_detach(&chip->pub);
736 return ERR_PTR(err);
737}
738
739void brcmf_chip_detach(struct brcmf_chip *pub)
740{
741 struct brcmf_chip_priv *chip;
742 struct brcmf_core_priv *core;
743 struct brcmf_core_priv *tmp;
744
745 chip = container_of(pub, struct brcmf_chip_priv, pub);
746 list_for_each_entry_safe(core, tmp, &chip->cores, list) {
747 list_del(&core->list);
748 kfree(core);
749 }
750 kfree(chip);
751}
752
753struct brcmf_core *brcmf_chip_get_core(struct brcmf_chip *pub, u16 coreid)
754{
755 struct brcmf_chip_priv *chip;
756 struct brcmf_core_priv *core;
757
758 chip = container_of(pub, struct brcmf_chip_priv, pub);
759 list_for_each_entry(core, &chip->cores, list)
760 if (core->pub.id == coreid)
761 return &core->pub;
762
763 return NULL;
764}
765
766struct brcmf_core *brcmf_chip_get_chipcommon(struct brcmf_chip *pub)
767{
768 struct brcmf_chip_priv *chip;
769 struct brcmf_core_priv *cc;
770
771 chip = container_of(pub, struct brcmf_chip_priv, pub);
772 cc = list_first_entry(&chip->cores, struct brcmf_core_priv, list);
773 if (WARN_ON(!cc || cc->pub.id != BCMA_CORE_CHIPCOMMON))
774 return brcmf_chip_get_core(pub, BCMA_CORE_CHIPCOMMON);
775 return &cc->pub;
776}
777
778bool brcmf_chip_iscoreup(struct brcmf_core *pub)
779{
780 struct brcmf_core_priv *core;
781
782 core = container_of(pub, struct brcmf_core_priv, pub);
783 return core->chip->iscoreup(core);
784}
785
786void brcmf_chip_coredisable(struct brcmf_core *pub, u32 prereset, u32 reset)
787{
788 struct brcmf_core_priv *core;
789
790 core = container_of(pub, struct brcmf_core_priv, pub);
791 core->chip->coredisable(core, prereset, reset);
792}
793
794void brcmf_chip_resetcore(struct brcmf_core *pub, u32 prereset, u32 reset,
795 u32 postreset)
796{
797 struct brcmf_core_priv *core;
798
799 core = container_of(pub, struct brcmf_core_priv, pub);
800 core->chip->resetcore(core, prereset, reset, postreset);
Franky Lina8a6c042011-11-04 22:23:39 +0100801}
Franky Line12afb62011-11-04 22:23:40 +0100802
Franky Lin069eddd2013-04-11 13:28:48 +0200803static void
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100804brcmf_chip_cm3_enterdl(struct brcmf_chip_priv *chip)
Franky Lin069eddd2013-04-11 13:28:48 +0200805{
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100806 struct brcmf_core *core;
807
808 brcmf_chip_disable_arm(chip, BCMA_CORE_ARM_CM3);
809 core = brcmf_chip_get_core(&chip->pub, BCMA_CORE_80211);
810 brcmf_chip_resetcore(core, D11_BCMA_IOCTL_PHYRESET |
811 D11_BCMA_IOCTL_PHYCLOCKEN,
812 D11_BCMA_IOCTL_PHYCLOCKEN,
813 D11_BCMA_IOCTL_PHYCLOCKEN);
814 core = brcmf_chip_get_core(&chip->pub, BCMA_CORE_INTERNAL_MEM);
815 brcmf_chip_resetcore(core, 0, 0, 0);
Franky Lin069eddd2013-04-11 13:28:48 +0200816}
817
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100818static bool brcmf_chip_cm3_exitdl(struct brcmf_chip_priv *chip)
Franky Lin069eddd2013-04-11 13:28:48 +0200819{
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100820 struct brcmf_core *core;
Franky Lin069eddd2013-04-11 13:28:48 +0200821
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100822 core = brcmf_chip_get_core(&chip->pub, BCMA_CORE_INTERNAL_MEM);
823 if (!brcmf_chip_iscoreup(core)) {
Franky Lin069eddd2013-04-11 13:28:48 +0200824 brcmf_err("SOCRAM core is down after reset?\n");
825 return false;
826 }
827
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100828 chip->ops->exit_dl(chip->ctx, &chip->pub, 0);
Franky Lin069eddd2013-04-11 13:28:48 +0200829
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100830 core = brcmf_chip_get_core(&chip->pub, BCMA_CORE_ARM_CM3);
831 brcmf_chip_resetcore(core, 0, 0, 0);
Franky Lin1640f282013-04-11 13:28:51 +0200832
833 return true;
834}
835
836static inline void
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100837brcmf_chip_cr4_enterdl(struct brcmf_chip_priv *chip)
Franky Lin1640f282013-04-11 13:28:51 +0200838{
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100839 struct brcmf_core *core;
Hante Meuleman53036262014-01-13 22:20:23 +0100840
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100841 brcmf_chip_disable_arm(chip, BCMA_CORE_ARM_CR4);
Hante Meuleman53036262014-01-13 22:20:23 +0100842
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100843 core = brcmf_chip_get_core(&chip->pub, BCMA_CORE_80211);
844 brcmf_chip_resetcore(core, D11_BCMA_IOCTL_PHYRESET |
845 D11_BCMA_IOCTL_PHYCLOCKEN,
846 D11_BCMA_IOCTL_PHYCLOCKEN,
847 D11_BCMA_IOCTL_PHYCLOCKEN);
Franky Lin1640f282013-04-11 13:28:51 +0200848}
849
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100850static bool brcmf_chip_cr4_exitdl(struct brcmf_chip_priv *chip, u32 rstvec)
Franky Lin1640f282013-04-11 13:28:51 +0200851{
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100852 struct brcmf_core *core;
Franky Lin1640f282013-04-11 13:28:51 +0200853
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100854 chip->ops->exit_dl(chip->ctx, &chip->pub, rstvec);
Franky Lin1640f282013-04-11 13:28:51 +0200855
856 /* restore ARM */
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100857 core = brcmf_chip_get_core(&chip->pub, BCMA_CORE_ARM_CR4);
858 brcmf_chip_resetcore(core, ARMCR4_BCMA_IOCTL_CPUHALT, 0, 0);
Franky Lin069eddd2013-04-11 13:28:48 +0200859
860 return true;
861}
862
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100863void brcmf_chip_enter_download(struct brcmf_chip *pub)
Franky Lin069eddd2013-04-11 13:28:48 +0200864{
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100865 struct brcmf_chip_priv *chip;
866 struct brcmf_core *arm;
Franky Lin1640f282013-04-11 13:28:51 +0200867
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100868 brcmf_dbg(TRACE, "Enter\n");
869
870 chip = container_of(pub, struct brcmf_chip_priv, pub);
871 arm = brcmf_chip_get_core(pub, BCMA_CORE_ARM_CM3);
872 if (arm) {
873 brcmf_chip_cm3_enterdl(chip);
Franky Lin1640f282013-04-11 13:28:51 +0200874 return;
875 }
876
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100877 brcmf_chip_cr4_enterdl(chip);
Franky Lin069eddd2013-04-11 13:28:48 +0200878}
879
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100880bool brcmf_chip_exit_download(struct brcmf_chip *pub, u32 rstvec)
Franky Lin069eddd2013-04-11 13:28:48 +0200881{
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100882 struct brcmf_chip_priv *chip;
883 struct brcmf_core *arm;
Franky Lin1640f282013-04-11 13:28:51 +0200884
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100885 brcmf_dbg(TRACE, "Enter\n");
Franky Lin1640f282013-04-11 13:28:51 +0200886
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100887 chip = container_of(pub, struct brcmf_chip_priv, pub);
888 arm = brcmf_chip_get_core(pub, BCMA_CORE_ARM_CM3);
889 if (arm)
890 return brcmf_chip_cm3_exitdl(chip);
891
892 return brcmf_chip_cr4_exitdl(chip, rstvec);
893}
894
895bool brcmf_chip_sr_capable(struct brcmf_chip *pub)
896{
897 u32 base, addr, reg, pmu_cc3_mask = ~0;
898 struct brcmf_chip_priv *chip;
899
900 brcmf_dbg(TRACE, "Enter\n");
901
902 /* old chips with PMU version less than 17 don't support save restore */
903 if (pub->pmurev < 17)
904 return false;
905
906 base = brcmf_chip_get_chipcommon(pub)->base;
907 chip = container_of(pub, struct brcmf_chip_priv, pub);
908
909 switch (pub->chip) {
910 case BCM43241_CHIP_ID:
911 case BCM4335_CHIP_ID:
912 case BCM4339_CHIP_ID:
913 /* read PMU chipcontrol register 3 */
914 addr = CORE_CC_REG(base, chipcontrol_addr);
915 chip->ops->write32(chip->ctx, addr, 3);
916 addr = CORE_CC_REG(base, chipcontrol_data);
917 reg = chip->ops->read32(chip->ctx, addr);
918 return (reg & pmu_cc3_mask) != 0;
919 default:
920 addr = CORE_CC_REG(base, pmucapabilities_ext);
921 reg = chip->ops->read32(chip->ctx, addr);
922 if ((reg & PCAPEXT_SR_SUPPORTED_MASK) == 0)
923 return false;
924
925 addr = CORE_CC_REG(base, retention_ctl);
926 reg = chip->ops->read32(chip->ctx, addr);
927 return (reg & (PMU_RCTL_MACPHY_DISABLE_MASK |
928 PMU_RCTL_LOGIC_DISABLE_MASK)) == 0;
929 }
Franky Lin069eddd2013-04-11 13:28:48 +0200930}