blob: e434e2a5209855a5a38bd71a6e1c1accf9d67b0f [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>
Hante Meulemana8e8ed32014-10-28 14:56:13 +010028#include "debug.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
Arend van Spriel4aa2c472014-01-29 15:32:22 +010035/* PL-368 DMP definitions */
36#define DMP_DESC_TYPE_MSK 0x0000000F
37#define DMP_DESC_EMPTY 0x00000000
38#define DMP_DESC_VALID 0x00000001
39#define DMP_DESC_COMPONENT 0x00000001
40#define DMP_DESC_MASTER_PORT 0x00000003
41#define DMP_DESC_ADDRESS 0x00000005
42#define DMP_DESC_ADDRSIZE_GT32 0x00000008
43#define DMP_DESC_EOT 0x0000000F
44
45#define DMP_COMP_DESIGNER 0xFFF00000
46#define DMP_COMP_DESIGNER_S 20
47#define DMP_COMP_PARTNUM 0x000FFF00
48#define DMP_COMP_PARTNUM_S 8
49#define DMP_COMP_CLASS 0x000000F0
50#define DMP_COMP_CLASS_S 4
51#define DMP_COMP_REVISION 0xFF000000
52#define DMP_COMP_REVISION_S 24
53#define DMP_COMP_NUM_SWRAP 0x00F80000
54#define DMP_COMP_NUM_SWRAP_S 19
55#define DMP_COMP_NUM_MWRAP 0x0007C000
56#define DMP_COMP_NUM_MWRAP_S 14
57#define DMP_COMP_NUM_SPORT 0x00003E00
58#define DMP_COMP_NUM_SPORT_S 9
59#define DMP_COMP_NUM_MPORT 0x000001F0
60#define DMP_COMP_NUM_MPORT_S 4
61
62#define DMP_MASTER_PORT_UID 0x0000FF00
63#define DMP_MASTER_PORT_UID_S 8
64#define DMP_MASTER_PORT_NUM 0x000000F0
65#define DMP_MASTER_PORT_NUM_S 4
66
67#define DMP_SLAVE_ADDR_BASE 0xFFFFF000
68#define DMP_SLAVE_ADDR_BASE_S 12
69#define DMP_SLAVE_PORT_NUM 0x00000F00
70#define DMP_SLAVE_PORT_NUM_S 8
71#define DMP_SLAVE_TYPE 0x000000C0
72#define DMP_SLAVE_TYPE_S 6
73#define DMP_SLAVE_TYPE_SLAVE 0
74#define DMP_SLAVE_TYPE_BRIDGE 1
75#define DMP_SLAVE_TYPE_SWRAP 2
76#define DMP_SLAVE_TYPE_MWRAP 3
77#define DMP_SLAVE_SIZE_TYPE 0x00000030
78#define DMP_SLAVE_SIZE_TYPE_S 4
79#define DMP_SLAVE_SIZE_4K 0
80#define DMP_SLAVE_SIZE_8K 1
81#define DMP_SLAVE_SIZE_16K 2
82#define DMP_SLAVE_SIZE_DESC 3
83
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +010084/* EROM CompIdentB */
85#define CIB_REV_MASK 0xff000000
86#define CIB_REV_SHIFT 24
87
88/* ARM CR4 core specific control flag bits */
89#define ARMCR4_BCMA_IOCTL_CPUHALT 0x0020
90
91/* D11 core specific control flag bits */
92#define D11_BCMA_IOCTL_PHYCLOCKEN 0x0004
93#define D11_BCMA_IOCTL_PHYRESET 0x0008
94
Franky Lina83369b2011-11-04 22:23:28 +010095/* chip core base & ramsize */
96/* bcm4329 */
97/* SDIO device core, ID 0x829 */
98#define BCM4329_CORE_BUS_BASE 0x18011000
99/* internal memory core, ID 0x80e */
100#define BCM4329_CORE_SOCRAM_BASE 0x18003000
101/* ARM Cortex M3 core, ID 0x82a */
102#define BCM4329_CORE_ARM_BASE 0x18002000
Hante Meuleman369508c2013-04-11 13:28:54 +0200103
Hante Meuleman07fe2e32015-08-27 16:14:06 +0200104/* Max possibly supported memory size (limited by IO mapped memory) */
105#define BRCMF_CHIP_MAX_MEMSIZE (4 * 1024 * 1024)
106
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100107#define CORE_SB(base, field) \
108 (base + SBCONFIGOFF + offsetof(struct sbconfig, field))
Franky Lina83369b2011-11-04 22:23:28 +0100109#define SBCOREREV(sbidh) \
Franky Lin61213be2011-11-04 22:23:41 +0100110 ((((sbidh) & SSB_IDHIGH_RCHI) >> SSB_IDHIGH_RCHI_SHIFT) | \
111 ((sbidh) & SSB_IDHIGH_RCLO))
Franky Lina83369b2011-11-04 22:23:28 +0100112
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100113struct sbconfig {
114 u32 PAD[2];
115 u32 sbipsflag; /* initiator port ocp slave flag */
116 u32 PAD[3];
117 u32 sbtpsflag; /* target port ocp slave flag */
118 u32 PAD[11];
119 u32 sbtmerrloga; /* (sonics >= 2.3) */
120 u32 PAD;
121 u32 sbtmerrlog; /* (sonics >= 2.3) */
122 u32 PAD[3];
123 u32 sbadmatch3; /* address match3 */
124 u32 PAD;
125 u32 sbadmatch2; /* address match2 */
126 u32 PAD;
127 u32 sbadmatch1; /* address match1 */
128 u32 PAD[7];
129 u32 sbimstate; /* initiator agent state */
130 u32 sbintvec; /* interrupt mask */
131 u32 sbtmstatelow; /* target state */
132 u32 sbtmstatehigh; /* target state */
133 u32 sbbwa0; /* bandwidth allocation table0 */
134 u32 PAD;
135 u32 sbimconfiglow; /* initiator configuration */
136 u32 sbimconfighigh; /* initiator configuration */
137 u32 sbadmatch0; /* address match0 */
138 u32 PAD;
139 u32 sbtmconfiglow; /* target configuration */
140 u32 sbtmconfighigh; /* target configuration */
141 u32 sbbconfig; /* broadcast configuration */
142 u32 PAD;
143 u32 sbbstate; /* broadcast state */
144 u32 PAD[3];
145 u32 sbactcnfg; /* activate configuration */
146 u32 PAD[3];
147 u32 sbflagst; /* current sbflags */
148 u32 PAD[3];
149 u32 sbidlow; /* identification */
150 u32 sbidhigh; /* identification */
151};
Franky Lin6ca687d2011-11-10 20:30:21 +0100152
Arend van Spriel0da32ba2015-03-11 16:11:31 +0100153/* bankidx and bankinfo reg defines corerev >= 8 */
154#define SOCRAM_BANKINFO_RETNTRAM_MASK 0x00010000
155#define SOCRAM_BANKINFO_SZMASK 0x0000007f
156#define SOCRAM_BANKIDX_ROM_MASK 0x00000100
157
158#define SOCRAM_BANKIDX_MEMTYPE_SHIFT 8
159/* socram bankinfo memtype */
160#define SOCRAM_MEMTYPE_RAM 0
161#define SOCRAM_MEMTYPE_R0M 1
162#define SOCRAM_MEMTYPE_DEVRAM 2
163
164#define SOCRAM_BANKINFO_SZBASE 8192
165#define SRCI_LSS_MASK 0x00f00000
166#define SRCI_LSS_SHIFT 20
167#define SRCI_SRNB_MASK 0xf0
168#define SRCI_SRNB_SHIFT 4
169#define SRCI_SRBSZ_MASK 0xf
170#define SRCI_SRBSZ_SHIFT 0
171#define SR_BSZ_BASE 14
172
173struct sbsocramregs {
174 u32 coreinfo;
175 u32 bwalloc;
176 u32 extracoreinfo;
177 u32 biststat;
178 u32 bankidx;
179 u32 standbyctrl;
180
181 u32 errlogstatus; /* rev 6 */
182 u32 errlogaddr; /* rev 6 */
183 /* used for patching rev 3 & 5 */
184 u32 cambankidx;
185 u32 cambankstandbyctrl;
186 u32 cambankpatchctrl;
187 u32 cambankpatchtblbaseaddr;
188 u32 cambankcmdreg;
189 u32 cambankdatareg;
190 u32 cambankmaskreg;
191 u32 PAD[1];
192 u32 bankinfo; /* corev 8 */
193 u32 bankpda;
194 u32 PAD[14];
195 u32 extmemconfig;
196 u32 extmemparitycsr;
197 u32 extmemparityerrdata;
198 u32 extmemparityerrcnt;
199 u32 extmemwrctrlandsize;
200 u32 PAD[84];
201 u32 workaround;
202 u32 pwrctl; /* corerev >= 2 */
203 u32 PAD[133];
204 u32 sr_control; /* corerev >= 15 */
205 u32 sr_status; /* corerev >= 15 */
206 u32 sr_address; /* corerev >= 15 */
207 u32 sr_data; /* corerev >= 15 */
208};
209
210#define SOCRAMREGOFFS(_f) offsetof(struct sbsocramregs, _f)
Hante Meuleman55acca92015-09-18 22:08:17 +0200211#define SYSMEMREGOFFS(_f) offsetof(struct sbsocramregs, _f)
Arend van Spriel0da32ba2015-03-11 16:11:31 +0100212
213#define ARMCR4_CAP (0x04)
214#define ARMCR4_BANKIDX (0x40)
215#define ARMCR4_BANKINFO (0x44)
216#define ARMCR4_BANKPDA (0x4C)
217
218#define ARMCR4_TCBBNB_MASK 0xf0
219#define ARMCR4_TCBBNB_SHIFT 4
220#define ARMCR4_TCBANB_MASK 0xf
221#define ARMCR4_TCBANB_SHIFT 0
222
223#define ARMCR4_BSZ_MASK 0x3f
224#define ARMCR4_BSZ_MULT 8192
225
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100226struct brcmf_core_priv {
227 struct brcmf_core pub;
228 u32 wrapbase;
229 struct list_head list;
230 struct brcmf_chip_priv *chip;
231};
Franky Lin523894f2011-11-10 20:30:22 +0100232
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100233struct brcmf_chip_priv {
234 struct brcmf_chip pub;
235 const struct brcmf_buscore_ops *ops;
236 void *ctx;
237 /* assured first core is chipcommon, second core is buscore */
238 struct list_head cores;
239 u16 num_cores;
Franky Lin99ba15c2011-11-04 22:23:42 +0100240
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100241 bool (*iscoreup)(struct brcmf_core_priv *core);
242 void (*coredisable)(struct brcmf_core_priv *core, u32 prereset,
243 u32 reset);
244 void (*resetcore)(struct brcmf_core_priv *core, u32 prereset, u32 reset,
245 u32 postreset);
246};
Franky Lin99ba15c2011-11-04 22:23:42 +0100247
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100248static void brcmf_chip_sb_corerev(struct brcmf_chip_priv *ci,
249 struct brcmf_core *core)
Franky Lin454d2a82011-11-04 22:23:37 +0100250{
251 u32 regdata;
Franky Lin523894f2011-11-10 20:30:22 +0100252
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100253 regdata = ci->ops->read32(ci->ctx, CORE_SB(core->base, sbidhigh));
254 core->rev = SBCOREREV(regdata);
Franky Lin454d2a82011-11-04 22:23:37 +0100255}
256
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100257static bool brcmf_chip_sb_iscoreup(struct brcmf_core_priv *core)
Franky Lin523894f2011-11-10 20:30:22 +0100258{
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100259 struct brcmf_chip_priv *ci;
Franky Lind8f64a42011-11-04 22:23:36 +0100260 u32 regdata;
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100261 u32 address;
Franky Lin6ca687d2011-11-10 20:30:21 +0100262
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100263 ci = core->chip;
264 address = CORE_SB(core->pub.base, sbtmstatelow);
265 regdata = ci->ops->read32(ci->ctx, address);
Franky Lin61213be2011-11-04 22:23:41 +0100266 regdata &= (SSB_TMSLOW_RESET | SSB_TMSLOW_REJECT |
267 SSB_IMSTATE_REJECT | SSB_TMSLOW_CLOCK);
Arend van Spriel20c9c9b2014-01-29 15:32:15 +0100268 return SSB_TMSLOW_CLOCK == regdata;
Franky Lind8f64a42011-11-04 22:23:36 +0100269}
270
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100271static bool brcmf_chip_ai_iscoreup(struct brcmf_core_priv *core)
Franky Lin6ca687d2011-11-10 20:30:21 +0100272{
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100273 struct brcmf_chip_priv *ci;
Franky Lin6ca687d2011-11-10 20:30:21 +0100274 u32 regdata;
Franky Lin6ca687d2011-11-10 20:30:21 +0100275 bool ret;
276
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100277 ci = core->chip;
278 regdata = ci->ops->read32(ci->ctx, core->wrapbase + BCMA_IOCTL);
Franky Lin6ca687d2011-11-10 20:30:21 +0100279 ret = (regdata & (BCMA_IOCTL_FGC | BCMA_IOCTL_CLK)) == BCMA_IOCTL_CLK;
280
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100281 regdata = ci->ops->read32(ci->ctx, core->wrapbase + BCMA_RESET_CTL);
Franky Lin6ca687d2011-11-10 20:30:21 +0100282 ret = ret && ((regdata & BCMA_RESET_CTL_RESET) == 0);
283
284 return ret;
285}
286
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100287static void brcmf_chip_sb_coredisable(struct brcmf_core_priv *core,
288 u32 prereset, u32 reset)
Franky Lin2d4a9af2011-11-04 22:23:31 +0100289{
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100290 struct brcmf_chip_priv *ci;
291 u32 val, base;
Franky Lin086a2e02011-11-10 20:30:23 +0100292
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100293 ci = core->chip;
294 base = core->pub.base;
295 val = ci->ops->read32(ci->ctx, CORE_SB(base, sbtmstatelow));
296 if (val & SSB_TMSLOW_RESET)
Franky Lin2d4a9af2011-11-04 22:23:31 +0100297 return;
298
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100299 val = ci->ops->read32(ci->ctx, CORE_SB(base, sbtmstatelow));
300 if ((val & SSB_TMSLOW_CLOCK) != 0) {
Franky Lin2d4a9af2011-11-04 22:23:31 +0100301 /*
302 * set target reject and spin until busy is clear
303 * (preserve core-specific bits)
304 */
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100305 val = ci->ops->read32(ci->ctx, CORE_SB(base, sbtmstatelow));
306 ci->ops->write32(ci->ctx, CORE_SB(base, sbtmstatelow),
307 val | SSB_TMSLOW_REJECT);
Franky Lin2d4a9af2011-11-04 22:23:31 +0100308
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100309 val = ci->ops->read32(ci->ctx, CORE_SB(base, sbtmstatelow));
Franky Lin2d4a9af2011-11-04 22:23:31 +0100310 udelay(1);
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100311 SPINWAIT((ci->ops->read32(ci->ctx, CORE_SB(base, sbtmstatehigh))
312 & SSB_TMSHIGH_BUSY), 100000);
Franky Lin2d4a9af2011-11-04 22:23:31 +0100313
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100314 val = ci->ops->read32(ci->ctx, CORE_SB(base, sbtmstatehigh));
315 if (val & SSB_TMSHIGH_BUSY)
Arend van Spriel5e8149f2012-12-07 10:49:57 +0100316 brcmf_err("core state still busy\n");
Franky Lin2d4a9af2011-11-04 22:23:31 +0100317
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100318 val = ci->ops->read32(ci->ctx, CORE_SB(base, sbidlow));
319 if (val & SSB_IDLOW_INITIATOR) {
320 val = ci->ops->read32(ci->ctx,
321 CORE_SB(base, sbimstate));
322 val |= SSB_IMSTATE_REJECT;
323 ci->ops->write32(ci->ctx,
324 CORE_SB(base, sbimstate), val);
325 val = ci->ops->read32(ci->ctx,
326 CORE_SB(base, sbimstate));
Franky Lin2d4a9af2011-11-04 22:23:31 +0100327 udelay(1);
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100328 SPINWAIT((ci->ops->read32(ci->ctx,
329 CORE_SB(base, sbimstate)) &
Arend van Spriela39be272013-12-12 11:58:58 +0100330 SSB_IMSTATE_BUSY), 100000);
Franky Lin2d4a9af2011-11-04 22:23:31 +0100331 }
332
333 /* set reset and reject while enabling the clocks */
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100334 val = SSB_TMSLOW_FGC | SSB_TMSLOW_CLOCK |
335 SSB_TMSLOW_REJECT | SSB_TMSLOW_RESET;
336 ci->ops->write32(ci->ctx, CORE_SB(base, sbtmstatelow), val);
337 val = ci->ops->read32(ci->ctx, CORE_SB(base, sbtmstatelow));
Franky Lin2d4a9af2011-11-04 22:23:31 +0100338 udelay(10);
339
340 /* clear the initiator reject bit */
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100341 val = ci->ops->read32(ci->ctx, CORE_SB(base, sbidlow));
342 if (val & SSB_IDLOW_INITIATOR) {
343 val = ci->ops->read32(ci->ctx,
344 CORE_SB(base, sbimstate));
345 val &= ~SSB_IMSTATE_REJECT;
346 ci->ops->write32(ci->ctx,
347 CORE_SB(base, sbimstate), val);
Franky Lin2d4a9af2011-11-04 22:23:31 +0100348 }
349 }
350
351 /* leave reset and reject asserted */
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100352 ci->ops->write32(ci->ctx, CORE_SB(base, sbtmstatelow),
353 (SSB_TMSLOW_REJECT | SSB_TMSLOW_RESET));
Franky Lin2d4a9af2011-11-04 22:23:31 +0100354 udelay(1);
355}
356
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100357static void brcmf_chip_ai_coredisable(struct brcmf_core_priv *core,
358 u32 prereset, u32 reset)
Franky Lin086a2e02011-11-10 20:30:23 +0100359{
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100360 struct brcmf_chip_priv *ci;
Franky Lin086a2e02011-11-10 20:30:23 +0100361 u32 regdata;
362
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100363 ci = core->chip;
Hante Meuleman53036262014-01-13 22:20:23 +0100364
Hans de Goedeffa216b2014-04-23 12:20:55 +0200365 /* if core is already in reset, skip reset */
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100366 regdata = ci->ops->read32(ci->ctx, core->wrapbase + BCMA_RESET_CTL);
Franky Lin086a2e02011-11-10 20:30:23 +0100367 if ((regdata & BCMA_RESET_CTL_RESET) != 0)
Hans de Goedeffa216b2014-04-23 12:20:55 +0200368 goto in_reset_configure;
Franky Lin086a2e02011-11-10 20:30:23 +0100369
Hante Meuleman53036262014-01-13 22:20:23 +0100370 /* configure reset */
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100371 ci->ops->write32(ci->ctx, core->wrapbase + BCMA_IOCTL,
372 prereset | BCMA_IOCTL_FGC | BCMA_IOCTL_CLK);
373 ci->ops->read32(ci->ctx, core->wrapbase + BCMA_IOCTL);
Franky Lin086a2e02011-11-10 20:30:23 +0100374
Hante Meuleman53036262014-01-13 22:20:23 +0100375 /* put in reset */
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100376 ci->ops->write32(ci->ctx, core->wrapbase + BCMA_RESET_CTL,
377 BCMA_RESET_CTL_RESET);
Franky Lin1640f282013-04-11 13:28:51 +0200378 usleep_range(10, 20);
379
Hante Meuleman53036262014-01-13 22:20:23 +0100380 /* wait till reset is 1 */
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100381 SPINWAIT(ci->ops->read32(ci->ctx, core->wrapbase + BCMA_RESET_CTL) !=
Hante Meuleman53036262014-01-13 22:20:23 +0100382 BCMA_RESET_CTL_RESET, 300);
383
Hans de Goedeffa216b2014-04-23 12:20:55 +0200384in_reset_configure:
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100385 /* in-reset configure */
386 ci->ops->write32(ci->ctx, core->wrapbase + BCMA_IOCTL,
387 reset | BCMA_IOCTL_FGC | BCMA_IOCTL_CLK);
388 ci->ops->read32(ci->ctx, core->wrapbase + BCMA_IOCTL);
Franky Lin086a2e02011-11-10 20:30:23 +0100389}
390
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100391static void brcmf_chip_sb_resetcore(struct brcmf_core_priv *core, u32 prereset,
392 u32 reset, u32 postreset)
Franky Lin2bc78e12011-11-04 22:23:38 +0100393{
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100394 struct brcmf_chip_priv *ci;
Franky Lin2bc78e12011-11-04 22:23:38 +0100395 u32 regdata;
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100396 u32 base;
Franky Lin086a2e02011-11-10 20:30:23 +0100397
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100398 ci = core->chip;
399 base = core->pub.base;
Franky Lin2bc78e12011-11-04 22:23:38 +0100400 /*
401 * Must do the disable sequence first to work for
402 * arbitrary current core state.
403 */
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100404 brcmf_chip_sb_coredisable(core, 0, 0);
Franky Lin2bc78e12011-11-04 22:23:38 +0100405
406 /*
407 * Now do the initialization sequence.
408 * set reset while enabling the clock and
409 * forcing them on throughout the core
410 */
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100411 ci->ops->write32(ci->ctx, CORE_SB(base, sbtmstatelow),
412 SSB_TMSLOW_FGC | SSB_TMSLOW_CLOCK |
413 SSB_TMSLOW_RESET);
414 regdata = ci->ops->read32(ci->ctx, CORE_SB(base, sbtmstatelow));
Franky Lin2bc78e12011-11-04 22:23:38 +0100415 udelay(1);
416
Franky Lind77e70f2011-11-10 20:30:24 +0100417 /* clear any serror */
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100418 regdata = ci->ops->read32(ci->ctx, CORE_SB(base, sbtmstatehigh));
Franky Lin61213be2011-11-04 22:23:41 +0100419 if (regdata & SSB_TMSHIGH_SERR)
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100420 ci->ops->write32(ci->ctx, CORE_SB(base, sbtmstatehigh), 0);
Franky Lin2bc78e12011-11-04 22:23:38 +0100421
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100422 regdata = ci->ops->read32(ci->ctx, CORE_SB(base, sbimstate));
423 if (regdata & (SSB_IMSTATE_IBE | SSB_IMSTATE_TO)) {
424 regdata &= ~(SSB_IMSTATE_IBE | SSB_IMSTATE_TO);
425 ci->ops->write32(ci->ctx, CORE_SB(base, sbimstate), regdata);
426 }
Franky Lin2bc78e12011-11-04 22:23:38 +0100427
428 /* clear reset and allow it to propagate throughout the core */
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100429 ci->ops->write32(ci->ctx, CORE_SB(base, sbtmstatelow),
430 SSB_TMSLOW_FGC | SSB_TMSLOW_CLOCK);
431 regdata = ci->ops->read32(ci->ctx, CORE_SB(base, sbtmstatelow));
Franky Lin2bc78e12011-11-04 22:23:38 +0100432 udelay(1);
433
434 /* leave clock enabled */
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100435 ci->ops->write32(ci->ctx, CORE_SB(base, sbtmstatelow),
436 SSB_TMSLOW_CLOCK);
437 regdata = ci->ops->read32(ci->ctx, CORE_SB(base, sbtmstatelow));
Franky Lind77e70f2011-11-10 20:30:24 +0100438 udelay(1);
439}
440
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100441static void brcmf_chip_ai_resetcore(struct brcmf_core_priv *core, u32 prereset,
442 u32 reset, u32 postreset)
Franky Lind77e70f2011-11-10 20:30:24 +0100443{
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100444 struct brcmf_chip_priv *ci;
445 int count;
Franky Lind77e70f2011-11-10 20:30:24 +0100446
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100447 ci = core->chip;
Hante Meuleman53036262014-01-13 22:20:23 +0100448
Franky Lind77e70f2011-11-10 20:30:24 +0100449 /* must disable first to work for arbitrary current core state */
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100450 brcmf_chip_ai_coredisable(core, prereset, reset);
Franky Lind77e70f2011-11-10 20:30:24 +0100451
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100452 count = 0;
453 while (ci->ops->read32(ci->ctx, core->wrapbase + BCMA_RESET_CTL) &
Hante Meuleman53036262014-01-13 22:20:23 +0100454 BCMA_RESET_CTL_RESET) {
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100455 ci->ops->write32(ci->ctx, core->wrapbase + BCMA_RESET_CTL, 0);
456 count++;
457 if (count > 50)
458 break;
Hante Meuleman53036262014-01-13 22:20:23 +0100459 usleep_range(40, 60);
460 }
Franky Lind77e70f2011-11-10 20:30:24 +0100461
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100462 ci->ops->write32(ci->ctx, core->wrapbase + BCMA_IOCTL,
463 postreset | BCMA_IOCTL_CLK);
464 ci->ops->read32(ci->ctx, core->wrapbase + BCMA_IOCTL);
465}
466
467static char *brcmf_chip_name(uint chipid, char *buf, uint len)
468{
469 const char *fmt;
470
471 fmt = ((chipid > 0xa000) || (chipid < 0x4000)) ? "%d" : "%x";
472 snprintf(buf, len, fmt, chipid);
473 return buf;
474}
475
476static struct brcmf_core *brcmf_chip_add_core(struct brcmf_chip_priv *ci,
477 u16 coreid, u32 base,
478 u32 wrapbase)
479{
480 struct brcmf_core_priv *core;
481
482 core = kzalloc(sizeof(*core), GFP_KERNEL);
483 if (!core)
484 return ERR_PTR(-ENOMEM);
485
486 core->pub.id = coreid;
487 core->pub.base = base;
488 core->chip = ci;
489 core->wrapbase = wrapbase;
490
491 list_add_tail(&core->list, &ci->cores);
492 return &core->pub;
Franky Lin2bc78e12011-11-04 22:23:38 +0100493}
494
Franky Lin1640f282013-04-11 13:28:51 +0200495/* safety check for chipinfo */
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100496static int brcmf_chip_cores_check(struct brcmf_chip_priv *ci)
Franky Lin1640f282013-04-11 13:28:51 +0200497{
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100498 struct brcmf_core_priv *core;
499 bool need_socram = false;
500 bool has_socram = false;
Arend van Spriel5ded1c22015-03-11 16:11:28 +0100501 bool cpu_found = false;
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100502 int idx = 1;
503
504 list_for_each_entry(core, &ci->cores, list) {
Arend van Spriel4aa2c472014-01-29 15:32:22 +0100505 brcmf_dbg(INFO, " [%-2d] core 0x%x:%-2d base 0x%08x wrap 0x%08x\n",
506 idx++, core->pub.id, core->pub.rev, core->pub.base,
507 core->wrapbase);
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100508
509 switch (core->pub.id) {
510 case BCMA_CORE_ARM_CM3:
Arend van Spriel5ded1c22015-03-11 16:11:28 +0100511 cpu_found = true;
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100512 need_socram = true;
513 break;
514 case BCMA_CORE_INTERNAL_MEM:
515 has_socram = true;
516 break;
517 case BCMA_CORE_ARM_CR4:
Arend van Spriel5ded1c22015-03-11 16:11:28 +0100518 cpu_found = true;
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100519 break;
Hante Meuleman55acca92015-09-18 22:08:17 +0200520 case BCMA_CORE_ARM_CA7:
521 cpu_found = true;
522 break;
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100523 default:
524 break;
525 }
526 }
Franky Lin1640f282013-04-11 13:28:51 +0200527
Arend van Spriel5ded1c22015-03-11 16:11:28 +0100528 if (!cpu_found) {
529 brcmf_err("CPU core not detected\n");
530 return -ENXIO;
531 }
Franky Lin1640f282013-04-11 13:28:51 +0200532 /* check RAM core presence for ARM CM3 core */
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100533 if (need_socram && !has_socram) {
534 brcmf_err("RAM core not provided with ARM CM3 core\n");
535 return -ENODEV;
Franky Lin1640f282013-04-11 13:28:51 +0200536 }
Franky Lin1640f282013-04-11 13:28:51 +0200537 return 0;
538}
Franky Lin1640f282013-04-11 13:28:51 +0200539
Arend van Spriel0da32ba2015-03-11 16:11:31 +0100540static u32 brcmf_chip_core_read32(struct brcmf_core_priv *core, u16 reg)
541{
542 return core->chip->ops->read32(core->chip->ctx, core->pub.base + reg);
543}
544
545static void brcmf_chip_core_write32(struct brcmf_core_priv *core,
546 u16 reg, u32 val)
547{
548 core->chip->ops->write32(core->chip->ctx, core->pub.base + reg, val);
549}
550
551static bool brcmf_chip_socram_banksize(struct brcmf_core_priv *core, u8 idx,
552 u32 *banksize)
553{
554 u32 bankinfo;
555 u32 bankidx = (SOCRAM_MEMTYPE_RAM << SOCRAM_BANKIDX_MEMTYPE_SHIFT);
556
557 bankidx |= idx;
558 brcmf_chip_core_write32(core, SOCRAMREGOFFS(bankidx), bankidx);
559 bankinfo = brcmf_chip_core_read32(core, SOCRAMREGOFFS(bankinfo));
560 *banksize = (bankinfo & SOCRAM_BANKINFO_SZMASK) + 1;
561 *banksize *= SOCRAM_BANKINFO_SZBASE;
562 return !!(bankinfo & SOCRAM_BANKINFO_RETNTRAM_MASK);
563}
564
565static void brcmf_chip_socram_ramsize(struct brcmf_core_priv *sr, u32 *ramsize,
566 u32 *srsize)
567{
568 u32 coreinfo;
569 uint nb, banksize, lss;
570 bool retent;
571 int i;
572
573 *ramsize = 0;
574 *srsize = 0;
575
576 if (WARN_ON(sr->pub.rev < 4))
577 return;
578
579 if (!brcmf_chip_iscoreup(&sr->pub))
580 brcmf_chip_resetcore(&sr->pub, 0, 0, 0);
581
582 /* Get info for determining size */
583 coreinfo = brcmf_chip_core_read32(sr, SOCRAMREGOFFS(coreinfo));
584 nb = (coreinfo & SRCI_SRNB_MASK) >> SRCI_SRNB_SHIFT;
585
586 if ((sr->pub.rev <= 7) || (sr->pub.rev == 12)) {
587 banksize = (coreinfo & SRCI_SRBSZ_MASK);
588 lss = (coreinfo & SRCI_LSS_MASK) >> SRCI_LSS_SHIFT;
589 if (lss != 0)
590 nb--;
591 *ramsize = nb * (1 << (banksize + SR_BSZ_BASE));
592 if (lss != 0)
593 *ramsize += (1 << ((lss - 1) + SR_BSZ_BASE));
594 } else {
595 nb = (coreinfo & SRCI_SRNB_MASK) >> SRCI_SRNB_SHIFT;
596 for (i = 0; i < nb; i++) {
597 retent = brcmf_chip_socram_banksize(sr, i, &banksize);
598 *ramsize += banksize;
599 if (retent)
600 *srsize += banksize;
601 }
602 }
603
604 /* hardcoded save&restore memory sizes */
605 switch (sr->chip->pub.chip) {
606 case BRCM_CC_4334_CHIP_ID:
607 if (sr->chip->pub.chiprev < 2)
608 *srsize = (32 * 1024);
609 break;
Arend van Spriel25911552015-03-18 13:25:26 +0100610 case BRCM_CC_43430_CHIP_ID:
611 /* assume sr for now as we can not check
612 * firmware sr capability at this point.
613 */
614 *srsize = (64 * 1024);
615 break;
Arend van Spriel0da32ba2015-03-11 16:11:31 +0100616 default:
617 break;
618 }
619}
620
Hante Meuleman55acca92015-09-18 22:08:17 +0200621/** Return the SYS MEM size */
622static u32 brcmf_chip_sysmem_ramsize(struct brcmf_core_priv *sysmem)
623{
624 u32 memsize = 0;
625 u32 coreinfo;
626 u32 idx;
627 u32 nb;
628 u32 banksize;
629
630 if (!brcmf_chip_iscoreup(&sysmem->pub))
631 brcmf_chip_resetcore(&sysmem->pub, 0, 0, 0);
632
633 coreinfo = brcmf_chip_core_read32(sysmem, SYSMEMREGOFFS(coreinfo));
634 nb = (coreinfo & SRCI_SRNB_MASK) >> SRCI_SRNB_SHIFT;
635
636 for (idx = 0; idx < nb; idx++) {
637 brcmf_chip_socram_banksize(sysmem, idx, &banksize);
638 memsize += banksize;
639 }
640
641 return memsize;
642}
643
Arend van Spriel0da32ba2015-03-11 16:11:31 +0100644/** Return the TCM-RAM size of the ARMCR4 core. */
645static u32 brcmf_chip_tcm_ramsize(struct brcmf_core_priv *cr4)
646{
647 u32 corecap;
648 u32 memsize = 0;
649 u32 nab;
650 u32 nbb;
651 u32 totb;
652 u32 bxinfo;
653 u32 idx;
654
655 corecap = brcmf_chip_core_read32(cr4, ARMCR4_CAP);
656
657 nab = (corecap & ARMCR4_TCBANB_MASK) >> ARMCR4_TCBANB_SHIFT;
658 nbb = (corecap & ARMCR4_TCBBNB_MASK) >> ARMCR4_TCBBNB_SHIFT;
659 totb = nab + nbb;
660
661 for (idx = 0; idx < totb; idx++) {
662 brcmf_chip_core_write32(cr4, ARMCR4_BANKIDX, idx);
663 bxinfo = brcmf_chip_core_read32(cr4, ARMCR4_BANKINFO);
664 memsize += ((bxinfo & ARMCR4_BSZ_MASK) + 1) * ARMCR4_BSZ_MULT;
665 }
666
667 return memsize;
668}
669
670static u32 brcmf_chip_tcm_rambase(struct brcmf_chip_priv *ci)
Franky Lina83369b2011-11-04 22:23:28 +0100671{
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100672 switch (ci->pub.chip) {
Syed Asifful Dayyan9c510262015-03-06 18:40:42 +0100673 case BRCM_CC_4345_CHIP_ID:
Arend van Spriel0da32ba2015-03-11 16:11:31 +0100674 return 0x198000;
675 case BRCM_CC_4335_CHIP_ID:
Hante Meuleman5779ae62014-07-12 08:49:34 +0200676 case BRCM_CC_4339_CHIP_ID:
Hante Meulemane3c92cb2015-09-18 22:08:05 +0200677 case BRCM_CC_4350_CHIP_ID:
Hante Meuleman5779ae62014-07-12 08:49:34 +0200678 case BRCM_CC_4354_CHIP_ID:
Hante Meuleman9e37f042014-07-30 13:20:04 +0200679 case BRCM_CC_4356_CHIP_ID:
680 case BRCM_CC_43567_CHIP_ID:
681 case BRCM_CC_43569_CHIP_ID:
682 case BRCM_CC_43570_CHIP_ID:
Arend van Spriel67f3b6a2015-04-14 20:10:31 +0200683 case BRCM_CC_4358_CHIP_ID:
Hante Meuleman2aff0302015-10-29 20:33:11 +0100684 case BRCM_CC_4359_CHIP_ID:
Hante Meuleman9e37f042014-07-30 13:20:04 +0200685 case BRCM_CC_43602_CHIP_ID:
Eric Carusof8273ba2015-10-14 12:34:11 -0700686 case BRCM_CC_4371_CHIP_ID:
Arend van Spriel0da32ba2015-03-11 16:11:31 +0100687 return 0x180000;
Hante Meuleman55acca92015-09-18 22:08:17 +0200688 case BRCM_CC_4365_CHIP_ID:
689 case BRCM_CC_4366_CHIP_ID:
690 return 0x200000;
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100691 default:
692 brcmf_err("unknown chip: %s\n", ci->pub.name);
693 break;
694 }
Arend van Spriel0da32ba2015-03-11 16:11:31 +0100695 return 0;
696}
697
698static int brcmf_chip_get_raminfo(struct brcmf_chip_priv *ci)
699{
700 struct brcmf_core_priv *mem_core;
701 struct brcmf_core *mem;
702
703 mem = brcmf_chip_get_core(&ci->pub, BCMA_CORE_ARM_CR4);
704 if (mem) {
705 mem_core = container_of(mem, struct brcmf_core_priv, pub);
706 ci->pub.ramsize = brcmf_chip_tcm_ramsize(mem_core);
707 ci->pub.rambase = brcmf_chip_tcm_rambase(ci);
708 if (!ci->pub.rambase) {
709 brcmf_err("RAM base not provided with ARM CR4 core\n");
710 return -EINVAL;
711 }
712 } else {
Hante Meuleman55acca92015-09-18 22:08:17 +0200713 mem = brcmf_chip_get_core(&ci->pub, BCMA_CORE_SYS_MEM);
714 if (mem) {
715 mem_core = container_of(mem, struct brcmf_core_priv,
716 pub);
717 ci->pub.ramsize = brcmf_chip_sysmem_ramsize(mem_core);
718 ci->pub.rambase = brcmf_chip_tcm_rambase(ci);
719 if (!ci->pub.rambase) {
720 brcmf_err("RAM base not provided with ARM CA7 core\n");
721 return -EINVAL;
722 }
723 } else {
724 mem = brcmf_chip_get_core(&ci->pub,
725 BCMA_CORE_INTERNAL_MEM);
726 if (!mem) {
727 brcmf_err("No memory cores found\n");
728 return -ENOMEM;
729 }
730 mem_core = container_of(mem, struct brcmf_core_priv,
731 pub);
732 brcmf_chip_socram_ramsize(mem_core, &ci->pub.ramsize,
733 &ci->pub.srsize);
734 }
Arend van Spriel0da32ba2015-03-11 16:11:31 +0100735 }
736 brcmf_dbg(INFO, "RAM: base=0x%x size=%d (0x%x) sr=%d (0x%x)\n",
737 ci->pub.rambase, ci->pub.ramsize, ci->pub.ramsize,
738 ci->pub.srsize, ci->pub.srsize);
739
740 if (!ci->pub.ramsize) {
741 brcmf_err("RAM size is undetermined\n");
742 return -ENOMEM;
743 }
Hante Meuleman07fe2e32015-08-27 16:14:06 +0200744
745 if (ci->pub.ramsize > BRCMF_CHIP_MAX_MEMSIZE) {
746 brcmf_err("RAM size is incorrect\n");
747 return -ENOMEM;
748 }
749
Arend van Spriel0da32ba2015-03-11 16:11:31 +0100750 return 0;
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100751}
752
Arend van Spriel4aa2c472014-01-29 15:32:22 +0100753static u32 brcmf_chip_dmp_get_desc(struct brcmf_chip_priv *ci, u32 *eromaddr,
754 u8 *type)
755{
756 u32 val;
757
758 /* read next descriptor */
759 val = ci->ops->read32(ci->ctx, *eromaddr);
760 *eromaddr += 4;
761
762 if (!type)
763 return val;
764
765 /* determine descriptor type */
766 *type = (val & DMP_DESC_TYPE_MSK);
767 if ((*type & ~DMP_DESC_ADDRSIZE_GT32) == DMP_DESC_ADDRESS)
768 *type = DMP_DESC_ADDRESS;
769
770 return val;
771}
772
773static int brcmf_chip_dmp_get_regaddr(struct brcmf_chip_priv *ci, u32 *eromaddr,
774 u32 *regbase, u32 *wrapbase)
775{
776 u8 desc;
777 u32 val;
778 u8 mpnum = 0;
779 u8 stype, sztype, wraptype;
780
781 *regbase = 0;
782 *wrapbase = 0;
783
784 val = brcmf_chip_dmp_get_desc(ci, eromaddr, &desc);
785 if (desc == DMP_DESC_MASTER_PORT) {
786 mpnum = (val & DMP_MASTER_PORT_NUM) >> DMP_MASTER_PORT_NUM_S;
787 wraptype = DMP_SLAVE_TYPE_MWRAP;
788 } else if (desc == DMP_DESC_ADDRESS) {
789 /* revert erom address */
790 *eromaddr -= 4;
791 wraptype = DMP_SLAVE_TYPE_SWRAP;
792 } else {
793 *eromaddr -= 4;
794 return -EILSEQ;
795 }
796
797 do {
798 /* locate address descriptor */
799 do {
800 val = brcmf_chip_dmp_get_desc(ci, eromaddr, &desc);
801 /* unexpected table end */
802 if (desc == DMP_DESC_EOT) {
803 *eromaddr -= 4;
804 return -EFAULT;
805 }
Rafał Miłeckia4f4abd2016-01-26 17:57:01 +0100806 } while (desc != DMP_DESC_ADDRESS &&
807 desc != DMP_DESC_COMPONENT);
808
809 /* stop if we crossed current component border */
810 if (desc == DMP_DESC_COMPONENT) {
811 *eromaddr -= 4;
812 return 0;
813 }
Arend van Spriel4aa2c472014-01-29 15:32:22 +0100814
815 /* skip upper 32-bit address descriptor */
816 if (val & DMP_DESC_ADDRSIZE_GT32)
817 brcmf_chip_dmp_get_desc(ci, eromaddr, NULL);
818
819 sztype = (val & DMP_SLAVE_SIZE_TYPE) >> DMP_SLAVE_SIZE_TYPE_S;
820
821 /* next size descriptor can be skipped */
822 if (sztype == DMP_SLAVE_SIZE_DESC) {
823 val = brcmf_chip_dmp_get_desc(ci, eromaddr, NULL);
824 /* skip upper size descriptor if present */
825 if (val & DMP_DESC_ADDRSIZE_GT32)
826 brcmf_chip_dmp_get_desc(ci, eromaddr, NULL);
827 }
828
829 /* only look for 4K register regions */
830 if (sztype != DMP_SLAVE_SIZE_4K)
831 continue;
832
833 stype = (val & DMP_SLAVE_TYPE) >> DMP_SLAVE_TYPE_S;
834
835 /* only regular slave and wrapper */
836 if (*regbase == 0 && stype == DMP_SLAVE_TYPE_SLAVE)
837 *regbase = val & DMP_SLAVE_ADDR_BASE;
838 if (*wrapbase == 0 && stype == wraptype)
839 *wrapbase = val & DMP_SLAVE_ADDR_BASE;
840 } while (*regbase == 0 || *wrapbase == 0);
841
842 return 0;
843}
844
845static
846int brcmf_chip_dmp_erom_scan(struct brcmf_chip_priv *ci)
847{
848 struct brcmf_core *core;
849 u32 eromaddr;
850 u8 desc_type = 0;
851 u32 val;
852 u16 id;
853 u8 nmp, nsp, nmw, nsw, rev;
854 u32 base, wrap;
855 int err;
856
857 eromaddr = ci->ops->read32(ci->ctx, CORE_CC_REG(SI_ENUM_BASE, eromptr));
858
859 while (desc_type != DMP_DESC_EOT) {
860 val = brcmf_chip_dmp_get_desc(ci, &eromaddr, &desc_type);
861 if (!(val & DMP_DESC_VALID))
862 continue;
863
864 if (desc_type == DMP_DESC_EMPTY)
865 continue;
866
867 /* need a component descriptor */
868 if (desc_type != DMP_DESC_COMPONENT)
869 continue;
870
871 id = (val & DMP_COMP_PARTNUM) >> DMP_COMP_PARTNUM_S;
872
873 /* next descriptor must be component as well */
874 val = brcmf_chip_dmp_get_desc(ci, &eromaddr, &desc_type);
875 if (WARN_ON((val & DMP_DESC_TYPE_MSK) != DMP_DESC_COMPONENT))
876 return -EFAULT;
877
878 /* only look at cores with master port(s) */
879 nmp = (val & DMP_COMP_NUM_MPORT) >> DMP_COMP_NUM_MPORT_S;
880 nsp = (val & DMP_COMP_NUM_SPORT) >> DMP_COMP_NUM_SPORT_S;
881 nmw = (val & DMP_COMP_NUM_MWRAP) >> DMP_COMP_NUM_MWRAP_S;
882 nsw = (val & DMP_COMP_NUM_SWRAP) >> DMP_COMP_NUM_SWRAP_S;
883 rev = (val & DMP_COMP_REVISION) >> DMP_COMP_REVISION_S;
884
885 /* need core with ports */
886 if (nmw + nsw == 0)
887 continue;
888
889 /* try to obtain register address info */
890 err = brcmf_chip_dmp_get_regaddr(ci, &eromaddr, &base, &wrap);
891 if (err)
892 continue;
893
894 /* finally a core to be added */
895 core = brcmf_chip_add_core(ci, id, base, wrap);
896 if (IS_ERR(core))
897 return PTR_ERR(core);
898
899 core->rev = rev;
900 }
901
902 return 0;
903}
904
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100905static int brcmf_chip_recognition(struct brcmf_chip_priv *ci)
906{
907 struct brcmf_core *core;
Franky Lina83369b2011-11-04 22:23:28 +0100908 u32 regdata;
Arend van Sprielc805eeb2014-01-13 22:20:26 +0100909 u32 socitype;
Arend van Spriel0da32ba2015-03-11 16:11:31 +0100910 int ret;
Franky Lina83369b2011-11-04 22:23:28 +0100911
Franky Lin069eddd2013-04-11 13:28:48 +0200912 /* Get CC core rev
Arend van Sprielc805eeb2014-01-13 22:20:26 +0100913 * Chipid is assume to be at offset 0 from SI_ENUM_BASE
Franky Lina83369b2011-11-04 22:23:28 +0100914 * For different chiptypes or old sdio hosts w/o chipcommon,
915 * other ways of recognition should be added here.
916 */
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100917 regdata = ci->ops->read32(ci->ctx, CORE_CC_REG(SI_ENUM_BASE, chipid));
918 ci->pub.chip = regdata & CID_ID_MASK;
919 ci->pub.chiprev = (regdata & CID_REV_MASK) >> CID_REV_SHIFT;
Arend van Sprielc805eeb2014-01-13 22:20:26 +0100920 socitype = (regdata & CID_TYPE_MASK) >> CID_TYPE_SHIFT;
Franky Lina83369b2011-11-04 22:23:28 +0100921
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100922 brcmf_chip_name(ci->pub.chip, ci->pub.name, sizeof(ci->pub.name));
923 brcmf_dbg(INFO, "found %s chip: BCM%s, rev=%d\n",
924 socitype == SOCI_SB ? "SB" : "AXI", ci->pub.name,
925 ci->pub.chiprev);
Franky Lina83369b2011-11-04 22:23:28 +0100926
Arend van Sprielc805eeb2014-01-13 22:20:26 +0100927 if (socitype == SOCI_SB) {
Hante Meuleman5779ae62014-07-12 08:49:34 +0200928 if (ci->pub.chip != BRCM_CC_4329_CHIP_ID) {
Arend van Sprielc805eeb2014-01-13 22:20:26 +0100929 brcmf_err("SB chip is not supported\n");
930 return -ENODEV;
931 }
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100932 ci->iscoreup = brcmf_chip_sb_iscoreup;
933 ci->coredisable = brcmf_chip_sb_coredisable;
934 ci->resetcore = brcmf_chip_sb_resetcore;
Arend van Sprielc805eeb2014-01-13 22:20:26 +0100935
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100936 core = brcmf_chip_add_core(ci, BCMA_CORE_CHIPCOMMON,
937 SI_ENUM_BASE, 0);
938 brcmf_chip_sb_corerev(ci, core);
939 core = brcmf_chip_add_core(ci, BCMA_CORE_SDIO_DEV,
940 BCM4329_CORE_BUS_BASE, 0);
941 brcmf_chip_sb_corerev(ci, core);
942 core = brcmf_chip_add_core(ci, BCMA_CORE_INTERNAL_MEM,
943 BCM4329_CORE_SOCRAM_BASE, 0);
944 brcmf_chip_sb_corerev(ci, core);
945 core = brcmf_chip_add_core(ci, BCMA_CORE_ARM_CM3,
946 BCM4329_CORE_ARM_BASE, 0);
947 brcmf_chip_sb_corerev(ci, core);
Arend van Spriel4aa2c472014-01-29 15:32:22 +0100948
949 core = brcmf_chip_add_core(ci, BCMA_CORE_80211, 0x18001000, 0);
950 brcmf_chip_sb_corerev(ci, core);
Arend van Sprielc805eeb2014-01-13 22:20:26 +0100951 } else if (socitype == SOCI_AI) {
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100952 ci->iscoreup = brcmf_chip_ai_iscoreup;
953 ci->coredisable = brcmf_chip_ai_coredisable;
954 ci->resetcore = brcmf_chip_ai_resetcore;
Arend van Sprielc805eeb2014-01-13 22:20:26 +0100955
Arend van Spriel4aa2c472014-01-29 15:32:22 +0100956 brcmf_chip_dmp_erom_scan(ci);
Arend van Sprielc805eeb2014-01-13 22:20:26 +0100957 } else {
958 brcmf_err("chip backplane type %u is not supported\n",
959 socitype);
Franky Lin6ca687d2011-11-10 20:30:21 +0100960 return -ENODEV;
961 }
962
Arend van Spriel0da32ba2015-03-11 16:11:31 +0100963 ret = brcmf_chip_cores_check(ci);
964 if (ret)
965 return ret;
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100966
Arend van Spriel0da32ba2015-03-11 16:11:31 +0100967 /* assure chip is passive for core access */
968 brcmf_chip_set_passive(&ci->pub);
Hante Meuleman07fe2e32015-08-27 16:14:06 +0200969
970 /* Call bus specific reset function now. Cores have been determined
971 * but further access may require a chip specific reset at this point.
972 */
973 if (ci->ops->reset) {
974 ci->ops->reset(ci->ctx, &ci->pub);
975 brcmf_chip_set_passive(&ci->pub);
976 }
977
Arend van Spriel0da32ba2015-03-11 16:11:31 +0100978 return brcmf_chip_get_raminfo(ci);
Franky Lina83369b2011-11-04 22:23:28 +0100979}
980
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100981static void brcmf_chip_disable_arm(struct brcmf_chip_priv *chip, u16 id)
Franky Lin5b45e542011-11-04 22:23:30 +0100982{
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100983 struct brcmf_core *core;
Hante Meuleman55acca92015-09-18 22:08:17 +0200984 struct brcmf_core_priv *cpu;
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100985 u32 val;
Franky Lin79ae3952012-05-04 18:27:34 -0700986
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100987
988 core = brcmf_chip_get_core(&chip->pub, id);
989 if (!core)
990 return;
991
992 switch (id) {
993 case BCMA_CORE_ARM_CM3:
994 brcmf_chip_coredisable(core, 0, 0);
995 break;
996 case BCMA_CORE_ARM_CR4:
Hante Meuleman55acca92015-09-18 22:08:17 +0200997 case BCMA_CORE_ARM_CA7:
998 cpu = container_of(core, struct brcmf_core_priv, pub);
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +0100999
1000 /* clear all IOCTL bits except HALT bit */
Hante Meuleman55acca92015-09-18 22:08:17 +02001001 val = chip->ops->read32(chip->ctx, cpu->wrapbase + BCMA_IOCTL);
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +01001002 val &= ARMCR4_BCMA_IOCTL_CPUHALT;
1003 brcmf_chip_resetcore(core, val, ARMCR4_BCMA_IOCTL_CPUHALT,
1004 ARMCR4_BCMA_IOCTL_CPUHALT);
1005 break;
1006 default:
1007 brcmf_err("unknown id: %u\n", id);
1008 break;
1009 }
1010}
1011
1012static int brcmf_chip_setup(struct brcmf_chip_priv *chip)
1013{
1014 struct brcmf_chip *pub;
1015 struct brcmf_core_priv *cc;
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +01001016 u32 base;
1017 u32 val;
1018 int ret = 0;
1019
1020 pub = &chip->pub;
1021 cc = list_first_entry(&chip->cores, struct brcmf_core_priv, list);
1022 base = cc->pub.base;
Franky Lin5b45e542011-11-04 22:23:30 +01001023
1024 /* get chipcommon capabilites */
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +01001025 pub->cc_caps = chip->ops->read32(chip->ctx,
1026 CORE_CC_REG(base, capabilities));
Franky Lin5b45e542011-11-04 22:23:30 +01001027
1028 /* get pmu caps & rev */
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +01001029 if (pub->cc_caps & CC_CAP_PMU) {
1030 val = chip->ops->read32(chip->ctx,
1031 CORE_CC_REG(base, pmucapabilities));
1032 pub->pmurev = val & PCAP_REV_MASK;
1033 pub->pmucaps = val;
Franky Lin5b45e542011-11-04 22:23:30 +01001034 }
1035
Arend van Spriel4aa2c472014-01-29 15:32:22 +01001036 brcmf_dbg(INFO, "ccrev=%d, pmurev=%d, pmucaps=0x%x\n",
1037 cc->pub.rev, pub->pmurev, pub->pmucaps);
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +01001038
1039 /* execute bus core specific setup */
1040 if (chip->ops->setup)
1041 ret = chip->ops->setup(chip->ctx, pub);
Franky Lin966414d2011-11-04 22:23:32 +01001042
Franky Lina83369b2011-11-04 22:23:28 +01001043 return ret;
1044}
Franky Lina8a6c042011-11-04 22:23:39 +01001045
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +01001046struct brcmf_chip *brcmf_chip_attach(void *ctx,
1047 const struct brcmf_buscore_ops *ops)
Franky Lina8a6c042011-11-04 22:23:39 +01001048{
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +01001049 struct brcmf_chip_priv *chip;
1050 int err = 0;
Franky Lina8a6c042011-11-04 22:23:39 +01001051
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +01001052 if (WARN_ON(!ops->read32))
1053 err = -EINVAL;
1054 if (WARN_ON(!ops->write32))
1055 err = -EINVAL;
1056 if (WARN_ON(!ops->prepare))
1057 err = -EINVAL;
Arend van Sprield380ebc2015-03-11 16:11:29 +01001058 if (WARN_ON(!ops->activate))
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +01001059 err = -EINVAL;
1060 if (err < 0)
1061 return ERR_PTR(-EINVAL);
1062
1063 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
1064 if (!chip)
1065 return ERR_PTR(-ENOMEM);
1066
1067 INIT_LIST_HEAD(&chip->cores);
1068 chip->num_cores = 0;
1069 chip->ops = ops;
1070 chip->ctx = ctx;
1071
1072 err = ops->prepare(ctx);
1073 if (err < 0)
1074 goto fail;
1075
1076 err = brcmf_chip_recognition(chip);
1077 if (err < 0)
1078 goto fail;
1079
1080 err = brcmf_chip_setup(chip);
1081 if (err < 0)
1082 goto fail;
1083
1084 return &chip->pub;
1085
1086fail:
1087 brcmf_chip_detach(&chip->pub);
1088 return ERR_PTR(err);
1089}
1090
1091void brcmf_chip_detach(struct brcmf_chip *pub)
1092{
1093 struct brcmf_chip_priv *chip;
1094 struct brcmf_core_priv *core;
1095 struct brcmf_core_priv *tmp;
1096
1097 chip = container_of(pub, struct brcmf_chip_priv, pub);
1098 list_for_each_entry_safe(core, tmp, &chip->cores, list) {
1099 list_del(&core->list);
1100 kfree(core);
1101 }
1102 kfree(chip);
1103}
1104
1105struct brcmf_core *brcmf_chip_get_core(struct brcmf_chip *pub, u16 coreid)
1106{
1107 struct brcmf_chip_priv *chip;
1108 struct brcmf_core_priv *core;
1109
1110 chip = container_of(pub, struct brcmf_chip_priv, pub);
1111 list_for_each_entry(core, &chip->cores, list)
1112 if (core->pub.id == coreid)
1113 return &core->pub;
1114
1115 return NULL;
1116}
1117
1118struct brcmf_core *brcmf_chip_get_chipcommon(struct brcmf_chip *pub)
1119{
1120 struct brcmf_chip_priv *chip;
1121 struct brcmf_core_priv *cc;
1122
1123 chip = container_of(pub, struct brcmf_chip_priv, pub);
1124 cc = list_first_entry(&chip->cores, struct brcmf_core_priv, list);
1125 if (WARN_ON(!cc || cc->pub.id != BCMA_CORE_CHIPCOMMON))
1126 return brcmf_chip_get_core(pub, BCMA_CORE_CHIPCOMMON);
1127 return &cc->pub;
1128}
1129
1130bool brcmf_chip_iscoreup(struct brcmf_core *pub)
1131{
1132 struct brcmf_core_priv *core;
1133
1134 core = container_of(pub, struct brcmf_core_priv, pub);
1135 return core->chip->iscoreup(core);
1136}
1137
1138void brcmf_chip_coredisable(struct brcmf_core *pub, u32 prereset, u32 reset)
1139{
1140 struct brcmf_core_priv *core;
1141
1142 core = container_of(pub, struct brcmf_core_priv, pub);
1143 core->chip->coredisable(core, prereset, reset);
1144}
1145
1146void brcmf_chip_resetcore(struct brcmf_core *pub, u32 prereset, u32 reset,
1147 u32 postreset)
1148{
1149 struct brcmf_core_priv *core;
1150
1151 core = container_of(pub, struct brcmf_core_priv, pub);
1152 core->chip->resetcore(core, prereset, reset, postreset);
Franky Lina8a6c042011-11-04 22:23:39 +01001153}
Franky Line12afb62011-11-04 22:23:40 +01001154
Franky Lin069eddd2013-04-11 13:28:48 +02001155static void
Arend van Sprield380ebc2015-03-11 16:11:29 +01001156brcmf_chip_cm3_set_passive(struct brcmf_chip_priv *chip)
Franky Lin069eddd2013-04-11 13:28:48 +02001157{
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +01001158 struct brcmf_core *core;
Arend van Spriel25911552015-03-18 13:25:26 +01001159 struct brcmf_core_priv *sr;
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +01001160
1161 brcmf_chip_disable_arm(chip, BCMA_CORE_ARM_CM3);
1162 core = brcmf_chip_get_core(&chip->pub, BCMA_CORE_80211);
1163 brcmf_chip_resetcore(core, D11_BCMA_IOCTL_PHYRESET |
1164 D11_BCMA_IOCTL_PHYCLOCKEN,
1165 D11_BCMA_IOCTL_PHYCLOCKEN,
1166 D11_BCMA_IOCTL_PHYCLOCKEN);
1167 core = brcmf_chip_get_core(&chip->pub, BCMA_CORE_INTERNAL_MEM);
1168 brcmf_chip_resetcore(core, 0, 0, 0);
Arend van Spriel25911552015-03-18 13:25:26 +01001169
1170 /* disable bank #3 remap for this device */
1171 if (chip->pub.chip == BRCM_CC_43430_CHIP_ID) {
1172 sr = container_of(core, struct brcmf_core_priv, pub);
1173 brcmf_chip_core_write32(sr, SOCRAMREGOFFS(bankidx), 3);
1174 brcmf_chip_core_write32(sr, SOCRAMREGOFFS(bankpda), 0);
1175 }
Franky Lin069eddd2013-04-11 13:28:48 +02001176}
1177
Arend van Sprield380ebc2015-03-11 16:11:29 +01001178static bool brcmf_chip_cm3_set_active(struct brcmf_chip_priv *chip)
Franky Lin069eddd2013-04-11 13:28:48 +02001179{
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +01001180 struct brcmf_core *core;
Franky Lin069eddd2013-04-11 13:28:48 +02001181
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +01001182 core = brcmf_chip_get_core(&chip->pub, BCMA_CORE_INTERNAL_MEM);
1183 if (!brcmf_chip_iscoreup(core)) {
Franky Lin069eddd2013-04-11 13:28:48 +02001184 brcmf_err("SOCRAM core is down after reset?\n");
1185 return false;
1186 }
1187
Arend van Sprield380ebc2015-03-11 16:11:29 +01001188 chip->ops->activate(chip->ctx, &chip->pub, 0);
Franky Lin069eddd2013-04-11 13:28:48 +02001189
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +01001190 core = brcmf_chip_get_core(&chip->pub, BCMA_CORE_ARM_CM3);
1191 brcmf_chip_resetcore(core, 0, 0, 0);
Franky Lin1640f282013-04-11 13:28:51 +02001192
1193 return true;
1194}
1195
1196static inline void
Arend van Sprield380ebc2015-03-11 16:11:29 +01001197brcmf_chip_cr4_set_passive(struct brcmf_chip_priv *chip)
Franky Lin1640f282013-04-11 13:28:51 +02001198{
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +01001199 struct brcmf_core *core;
Hante Meuleman53036262014-01-13 22:20:23 +01001200
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +01001201 brcmf_chip_disable_arm(chip, BCMA_CORE_ARM_CR4);
Hante Meuleman53036262014-01-13 22:20:23 +01001202
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +01001203 core = brcmf_chip_get_core(&chip->pub, BCMA_CORE_80211);
1204 brcmf_chip_resetcore(core, D11_BCMA_IOCTL_PHYRESET |
1205 D11_BCMA_IOCTL_PHYCLOCKEN,
1206 D11_BCMA_IOCTL_PHYCLOCKEN,
1207 D11_BCMA_IOCTL_PHYCLOCKEN);
Franky Lin1640f282013-04-11 13:28:51 +02001208}
1209
Arend van Sprield380ebc2015-03-11 16:11:29 +01001210static bool brcmf_chip_cr4_set_active(struct brcmf_chip_priv *chip, u32 rstvec)
Franky Lin1640f282013-04-11 13:28:51 +02001211{
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +01001212 struct brcmf_core *core;
Franky Lin1640f282013-04-11 13:28:51 +02001213
Arend van Sprield380ebc2015-03-11 16:11:29 +01001214 chip->ops->activate(chip->ctx, &chip->pub, rstvec);
Franky Lin1640f282013-04-11 13:28:51 +02001215
1216 /* restore ARM */
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +01001217 core = brcmf_chip_get_core(&chip->pub, BCMA_CORE_ARM_CR4);
1218 brcmf_chip_resetcore(core, ARMCR4_BCMA_IOCTL_CPUHALT, 0, 0);
Franky Lin069eddd2013-04-11 13:28:48 +02001219
1220 return true;
1221}
1222
Hante Meuleman55acca92015-09-18 22:08:17 +02001223static inline void
1224brcmf_chip_ca7_set_passive(struct brcmf_chip_priv *chip)
1225{
1226 struct brcmf_core *core;
1227
1228 brcmf_chip_disable_arm(chip, BCMA_CORE_ARM_CA7);
1229
1230 core = brcmf_chip_get_core(&chip->pub, BCMA_CORE_80211);
1231 brcmf_chip_resetcore(core, D11_BCMA_IOCTL_PHYRESET |
1232 D11_BCMA_IOCTL_PHYCLOCKEN,
1233 D11_BCMA_IOCTL_PHYCLOCKEN,
1234 D11_BCMA_IOCTL_PHYCLOCKEN);
1235}
1236
1237static bool brcmf_chip_ca7_set_active(struct brcmf_chip_priv *chip, u32 rstvec)
1238{
1239 struct brcmf_core *core;
1240
1241 chip->ops->activate(chip->ctx, &chip->pub, rstvec);
1242
1243 /* restore ARM */
1244 core = brcmf_chip_get_core(&chip->pub, BCMA_CORE_ARM_CA7);
1245 brcmf_chip_resetcore(core, ARMCR4_BCMA_IOCTL_CPUHALT, 0, 0);
1246
1247 return true;
1248}
1249
Arend van Sprield380ebc2015-03-11 16:11:29 +01001250void brcmf_chip_set_passive(struct brcmf_chip *pub)
Franky Lin069eddd2013-04-11 13:28:48 +02001251{
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +01001252 struct brcmf_chip_priv *chip;
1253 struct brcmf_core *arm;
Franky Lin1640f282013-04-11 13:28:51 +02001254
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +01001255 brcmf_dbg(TRACE, "Enter\n");
1256
1257 chip = container_of(pub, struct brcmf_chip_priv, pub);
Arend van Spriel2da5cb292014-01-29 15:32:24 +01001258 arm = brcmf_chip_get_core(pub, BCMA_CORE_ARM_CR4);
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +01001259 if (arm) {
Arend van Sprield380ebc2015-03-11 16:11:29 +01001260 brcmf_chip_cr4_set_passive(chip);
Franky Lin1640f282013-04-11 13:28:51 +02001261 return;
1262 }
Hante Meuleman55acca92015-09-18 22:08:17 +02001263 arm = brcmf_chip_get_core(pub, BCMA_CORE_ARM_CA7);
1264 if (arm) {
1265 brcmf_chip_ca7_set_passive(chip);
1266 return;
1267 }
1268 arm = brcmf_chip_get_core(pub, BCMA_CORE_ARM_CM3);
1269 if (arm) {
1270 brcmf_chip_cm3_set_passive(chip);
1271 return;
1272 }
Franky Lin069eddd2013-04-11 13:28:48 +02001273}
1274
Arend van Sprield380ebc2015-03-11 16:11:29 +01001275bool brcmf_chip_set_active(struct brcmf_chip *pub, u32 rstvec)
Franky Lin069eddd2013-04-11 13:28:48 +02001276{
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +01001277 struct brcmf_chip_priv *chip;
1278 struct brcmf_core *arm;
Franky Lin1640f282013-04-11 13:28:51 +02001279
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +01001280 brcmf_dbg(TRACE, "Enter\n");
Franky Lin1640f282013-04-11 13:28:51 +02001281
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +01001282 chip = container_of(pub, struct brcmf_chip_priv, pub);
Arend van Spriel2da5cb292014-01-29 15:32:24 +01001283 arm = brcmf_chip_get_core(pub, BCMA_CORE_ARM_CR4);
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +01001284 if (arm)
Arend van Sprield380ebc2015-03-11 16:11:29 +01001285 return brcmf_chip_cr4_set_active(chip, rstvec);
Hante Meuleman55acca92015-09-18 22:08:17 +02001286 arm = brcmf_chip_get_core(pub, BCMA_CORE_ARM_CA7);
1287 if (arm)
1288 return brcmf_chip_ca7_set_active(chip, rstvec);
1289 arm = brcmf_chip_get_core(pub, BCMA_CORE_ARM_CM3);
1290 if (arm)
1291 return brcmf_chip_cm3_set_active(chip);
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +01001292
Hante Meuleman55acca92015-09-18 22:08:17 +02001293 return false;
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +01001294}
1295
1296bool brcmf_chip_sr_capable(struct brcmf_chip *pub)
1297{
1298 u32 base, addr, reg, pmu_cc3_mask = ~0;
1299 struct brcmf_chip_priv *chip;
1300
1301 brcmf_dbg(TRACE, "Enter\n");
1302
1303 /* old chips with PMU version less than 17 don't support save restore */
1304 if (pub->pmurev < 17)
1305 return false;
1306
1307 base = brcmf_chip_get_chipcommon(pub)->base;
1308 chip = container_of(pub, struct brcmf_chip_priv, pub);
1309
1310 switch (pub->chip) {
Hante Meuleman5779ae62014-07-12 08:49:34 +02001311 case BRCM_CC_4354_CHIP_ID:
Franky Lina797ca12014-03-15 17:18:17 +01001312 /* explicitly check SR engine enable bit */
1313 pmu_cc3_mask = BIT(2);
1314 /* fall-through */
Hante Meuleman5779ae62014-07-12 08:49:34 +02001315 case BRCM_CC_43241_CHIP_ID:
1316 case BRCM_CC_4335_CHIP_ID:
1317 case BRCM_CC_4339_CHIP_ID:
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +01001318 /* read PMU chipcontrol register 3 */
1319 addr = CORE_CC_REG(base, chipcontrol_addr);
1320 chip->ops->write32(chip->ctx, addr, 3);
1321 addr = CORE_CC_REG(base, chipcontrol_data);
1322 reg = chip->ops->read32(chip->ctx, addr);
1323 return (reg & pmu_cc3_mask) != 0;
Arend van Spriel25911552015-03-18 13:25:26 +01001324 case BRCM_CC_43430_CHIP_ID:
1325 addr = CORE_CC_REG(base, sr_control1);
1326 reg = chip->ops->read32(chip->ctx, addr);
1327 return reg != 0;
Arend van Sprielcb7cf7b2014-01-29 15:32:19 +01001328 default:
1329 addr = CORE_CC_REG(base, pmucapabilities_ext);
1330 reg = chip->ops->read32(chip->ctx, addr);
1331 if ((reg & PCAPEXT_SR_SUPPORTED_MASK) == 0)
1332 return false;
1333
1334 addr = CORE_CC_REG(base, retention_ctl);
1335 reg = chip->ops->read32(chip->ctx, addr);
1336 return (reg & (PMU_RCTL_MACPHY_DISABLE_MASK |
1337 PMU_RCTL_LOGIC_DISABLE_MASK)) == 0;
1338 }
Franky Lin069eddd2013-04-11 13:28:48 +02001339}