chip.c 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371
  1. /*
  2. * Copyright (c) 2014 Broadcom Corporation
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  11. * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  13. * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  14. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include <linux/kernel.h>
  17. #include <linux/delay.h>
  18. #include <linux/list.h>
  19. #include <linux/ssb/ssb_regs.h>
  20. #include <linux/bcma/bcma.h>
  21. #include <linux/bcma/bcma_regs.h>
  22. #include <defs.h>
  23. #include <soc.h>
  24. #include <brcm_hw_ids.h>
  25. #include <brcmu_utils.h>
  26. #include <chipcommon.h>
  27. #include "debug.h"
  28. #include "chip.h"
  29. /* SOC Interconnect types (aka chip types) */
  30. #define SOCI_SB 0
  31. #define SOCI_AI 1
  32. /* PL-368 DMP definitions */
  33. #define DMP_DESC_TYPE_MSK 0x0000000F
  34. #define DMP_DESC_EMPTY 0x00000000
  35. #define DMP_DESC_VALID 0x00000001
  36. #define DMP_DESC_COMPONENT 0x00000001
  37. #define DMP_DESC_MASTER_PORT 0x00000003
  38. #define DMP_DESC_ADDRESS 0x00000005
  39. #define DMP_DESC_ADDRSIZE_GT32 0x00000008
  40. #define DMP_DESC_EOT 0x0000000F
  41. #define DMP_COMP_DESIGNER 0xFFF00000
  42. #define DMP_COMP_DESIGNER_S 20
  43. #define DMP_COMP_PARTNUM 0x000FFF00
  44. #define DMP_COMP_PARTNUM_S 8
  45. #define DMP_COMP_CLASS 0x000000F0
  46. #define DMP_COMP_CLASS_S 4
  47. #define DMP_COMP_REVISION 0xFF000000
  48. #define DMP_COMP_REVISION_S 24
  49. #define DMP_COMP_NUM_SWRAP 0x00F80000
  50. #define DMP_COMP_NUM_SWRAP_S 19
  51. #define DMP_COMP_NUM_MWRAP 0x0007C000
  52. #define DMP_COMP_NUM_MWRAP_S 14
  53. #define DMP_COMP_NUM_SPORT 0x00003E00
  54. #define DMP_COMP_NUM_SPORT_S 9
  55. #define DMP_COMP_NUM_MPORT 0x000001F0
  56. #define DMP_COMP_NUM_MPORT_S 4
  57. #define DMP_MASTER_PORT_UID 0x0000FF00
  58. #define DMP_MASTER_PORT_UID_S 8
  59. #define DMP_MASTER_PORT_NUM 0x000000F0
  60. #define DMP_MASTER_PORT_NUM_S 4
  61. #define DMP_SLAVE_ADDR_BASE 0xFFFFF000
  62. #define DMP_SLAVE_ADDR_BASE_S 12
  63. #define DMP_SLAVE_PORT_NUM 0x00000F00
  64. #define DMP_SLAVE_PORT_NUM_S 8
  65. #define DMP_SLAVE_TYPE 0x000000C0
  66. #define DMP_SLAVE_TYPE_S 6
  67. #define DMP_SLAVE_TYPE_SLAVE 0
  68. #define DMP_SLAVE_TYPE_BRIDGE 1
  69. #define DMP_SLAVE_TYPE_SWRAP 2
  70. #define DMP_SLAVE_TYPE_MWRAP 3
  71. #define DMP_SLAVE_SIZE_TYPE 0x00000030
  72. #define DMP_SLAVE_SIZE_TYPE_S 4
  73. #define DMP_SLAVE_SIZE_4K 0
  74. #define DMP_SLAVE_SIZE_8K 1
  75. #define DMP_SLAVE_SIZE_16K 2
  76. #define DMP_SLAVE_SIZE_DESC 3
  77. /* EROM CompIdentB */
  78. #define CIB_REV_MASK 0xff000000
  79. #define CIB_REV_SHIFT 24
  80. /* ARM CR4 core specific control flag bits */
  81. #define ARMCR4_BCMA_IOCTL_CPUHALT 0x0020
  82. /* D11 core specific control flag bits */
  83. #define D11_BCMA_IOCTL_PHYCLOCKEN 0x0004
  84. #define D11_BCMA_IOCTL_PHYRESET 0x0008
  85. /* chip core base & ramsize */
  86. /* bcm4329 */
  87. /* SDIO device core, ID 0x829 */
  88. #define BCM4329_CORE_BUS_BASE 0x18011000
  89. /* internal memory core, ID 0x80e */
  90. #define BCM4329_CORE_SOCRAM_BASE 0x18003000
  91. /* ARM Cortex M3 core, ID 0x82a */
  92. #define BCM4329_CORE_ARM_BASE 0x18002000
  93. /* Max possibly supported memory size (limited by IO mapped memory) */
  94. #define BRCMF_CHIP_MAX_MEMSIZE (4 * 1024 * 1024)
  95. #define CORE_SB(base, field) \
  96. (base + SBCONFIGOFF + offsetof(struct sbconfig, field))
  97. #define SBCOREREV(sbidh) \
  98. ((((sbidh) & SSB_IDHIGH_RCHI) >> SSB_IDHIGH_RCHI_SHIFT) | \
  99. ((sbidh) & SSB_IDHIGH_RCLO))
  100. struct sbconfig {
  101. u32 PAD[2];
  102. u32 sbipsflag; /* initiator port ocp slave flag */
  103. u32 PAD[3];
  104. u32 sbtpsflag; /* target port ocp slave flag */
  105. u32 PAD[11];
  106. u32 sbtmerrloga; /* (sonics >= 2.3) */
  107. u32 PAD;
  108. u32 sbtmerrlog; /* (sonics >= 2.3) */
  109. u32 PAD[3];
  110. u32 sbadmatch3; /* address match3 */
  111. u32 PAD;
  112. u32 sbadmatch2; /* address match2 */
  113. u32 PAD;
  114. u32 sbadmatch1; /* address match1 */
  115. u32 PAD[7];
  116. u32 sbimstate; /* initiator agent state */
  117. u32 sbintvec; /* interrupt mask */
  118. u32 sbtmstatelow; /* target state */
  119. u32 sbtmstatehigh; /* target state */
  120. u32 sbbwa0; /* bandwidth allocation table0 */
  121. u32 PAD;
  122. u32 sbimconfiglow; /* initiator configuration */
  123. u32 sbimconfighigh; /* initiator configuration */
  124. u32 sbadmatch0; /* address match0 */
  125. u32 PAD;
  126. u32 sbtmconfiglow; /* target configuration */
  127. u32 sbtmconfighigh; /* target configuration */
  128. u32 sbbconfig; /* broadcast configuration */
  129. u32 PAD;
  130. u32 sbbstate; /* broadcast state */
  131. u32 PAD[3];
  132. u32 sbactcnfg; /* activate configuration */
  133. u32 PAD[3];
  134. u32 sbflagst; /* current sbflags */
  135. u32 PAD[3];
  136. u32 sbidlow; /* identification */
  137. u32 sbidhigh; /* identification */
  138. };
  139. /* bankidx and bankinfo reg defines corerev >= 8 */
  140. #define SOCRAM_BANKINFO_RETNTRAM_MASK 0x00010000
  141. #define SOCRAM_BANKINFO_SZMASK 0x0000007f
  142. #define SOCRAM_BANKIDX_ROM_MASK 0x00000100
  143. #define SOCRAM_BANKIDX_MEMTYPE_SHIFT 8
  144. /* socram bankinfo memtype */
  145. #define SOCRAM_MEMTYPE_RAM 0
  146. #define SOCRAM_MEMTYPE_R0M 1
  147. #define SOCRAM_MEMTYPE_DEVRAM 2
  148. #define SOCRAM_BANKINFO_SZBASE 8192
  149. #define SRCI_LSS_MASK 0x00f00000
  150. #define SRCI_LSS_SHIFT 20
  151. #define SRCI_SRNB_MASK 0xf0
  152. #define SRCI_SRNB_SHIFT 4
  153. #define SRCI_SRBSZ_MASK 0xf
  154. #define SRCI_SRBSZ_SHIFT 0
  155. #define SR_BSZ_BASE 14
  156. struct sbsocramregs {
  157. u32 coreinfo;
  158. u32 bwalloc;
  159. u32 extracoreinfo;
  160. u32 biststat;
  161. u32 bankidx;
  162. u32 standbyctrl;
  163. u32 errlogstatus; /* rev 6 */
  164. u32 errlogaddr; /* rev 6 */
  165. /* used for patching rev 3 & 5 */
  166. u32 cambankidx;
  167. u32 cambankstandbyctrl;
  168. u32 cambankpatchctrl;
  169. u32 cambankpatchtblbaseaddr;
  170. u32 cambankcmdreg;
  171. u32 cambankdatareg;
  172. u32 cambankmaskreg;
  173. u32 PAD[1];
  174. u32 bankinfo; /* corev 8 */
  175. u32 bankpda;
  176. u32 PAD[14];
  177. u32 extmemconfig;
  178. u32 extmemparitycsr;
  179. u32 extmemparityerrdata;
  180. u32 extmemparityerrcnt;
  181. u32 extmemwrctrlandsize;
  182. u32 PAD[84];
  183. u32 workaround;
  184. u32 pwrctl; /* corerev >= 2 */
  185. u32 PAD[133];
  186. u32 sr_control; /* corerev >= 15 */
  187. u32 sr_status; /* corerev >= 15 */
  188. u32 sr_address; /* corerev >= 15 */
  189. u32 sr_data; /* corerev >= 15 */
  190. };
  191. #define SOCRAMREGOFFS(_f) offsetof(struct sbsocramregs, _f)
  192. #define SYSMEMREGOFFS(_f) offsetof(struct sbsocramregs, _f)
  193. #define ARMCR4_CAP (0x04)
  194. #define ARMCR4_BANKIDX (0x40)
  195. #define ARMCR4_BANKINFO (0x44)
  196. #define ARMCR4_BANKPDA (0x4C)
  197. #define ARMCR4_TCBBNB_MASK 0xf0
  198. #define ARMCR4_TCBBNB_SHIFT 4
  199. #define ARMCR4_TCBANB_MASK 0xf
  200. #define ARMCR4_TCBANB_SHIFT 0
  201. #define ARMCR4_BSZ_MASK 0x3f
  202. #define ARMCR4_BSZ_MULT 8192
  203. struct brcmf_core_priv {
  204. struct brcmf_core pub;
  205. u32 wrapbase;
  206. struct list_head list;
  207. struct brcmf_chip_priv *chip;
  208. };
  209. struct brcmf_chip_priv {
  210. struct brcmf_chip pub;
  211. const struct brcmf_buscore_ops *ops;
  212. void *ctx;
  213. /* assured first core is chipcommon, second core is buscore */
  214. struct list_head cores;
  215. u16 num_cores;
  216. bool (*iscoreup)(struct brcmf_core_priv *core);
  217. void (*coredisable)(struct brcmf_core_priv *core, u32 prereset,
  218. u32 reset);
  219. void (*resetcore)(struct brcmf_core_priv *core, u32 prereset, u32 reset,
  220. u32 postreset);
  221. };
  222. static void brcmf_chip_sb_corerev(struct brcmf_chip_priv *ci,
  223. struct brcmf_core *core)
  224. {
  225. u32 regdata;
  226. regdata = ci->ops->read32(ci->ctx, CORE_SB(core->base, sbidhigh));
  227. core->rev = SBCOREREV(regdata);
  228. }
  229. static bool brcmf_chip_sb_iscoreup(struct brcmf_core_priv *core)
  230. {
  231. struct brcmf_chip_priv *ci;
  232. u32 regdata;
  233. u32 address;
  234. ci = core->chip;
  235. address = CORE_SB(core->pub.base, sbtmstatelow);
  236. regdata = ci->ops->read32(ci->ctx, address);
  237. regdata &= (SSB_TMSLOW_RESET | SSB_TMSLOW_REJECT |
  238. SSB_IMSTATE_REJECT | SSB_TMSLOW_CLOCK);
  239. return SSB_TMSLOW_CLOCK == regdata;
  240. }
  241. static bool brcmf_chip_ai_iscoreup(struct brcmf_core_priv *core)
  242. {
  243. struct brcmf_chip_priv *ci;
  244. u32 regdata;
  245. bool ret;
  246. ci = core->chip;
  247. regdata = ci->ops->read32(ci->ctx, core->wrapbase + BCMA_IOCTL);
  248. ret = (regdata & (BCMA_IOCTL_FGC | BCMA_IOCTL_CLK)) == BCMA_IOCTL_CLK;
  249. regdata = ci->ops->read32(ci->ctx, core->wrapbase + BCMA_RESET_CTL);
  250. ret = ret && ((regdata & BCMA_RESET_CTL_RESET) == 0);
  251. return ret;
  252. }
  253. static void brcmf_chip_sb_coredisable(struct brcmf_core_priv *core,
  254. u32 prereset, u32 reset)
  255. {
  256. struct brcmf_chip_priv *ci;
  257. u32 val, base;
  258. ci = core->chip;
  259. base = core->pub.base;
  260. val = ci->ops->read32(ci->ctx, CORE_SB(base, sbtmstatelow));
  261. if (val & SSB_TMSLOW_RESET)
  262. return;
  263. val = ci->ops->read32(ci->ctx, CORE_SB(base, sbtmstatelow));
  264. if ((val & SSB_TMSLOW_CLOCK) != 0) {
  265. /*
  266. * set target reject and spin until busy is clear
  267. * (preserve core-specific bits)
  268. */
  269. val = ci->ops->read32(ci->ctx, CORE_SB(base, sbtmstatelow));
  270. ci->ops->write32(ci->ctx, CORE_SB(base, sbtmstatelow),
  271. val | SSB_TMSLOW_REJECT);
  272. val = ci->ops->read32(ci->ctx, CORE_SB(base, sbtmstatelow));
  273. udelay(1);
  274. SPINWAIT((ci->ops->read32(ci->ctx, CORE_SB(base, sbtmstatehigh))
  275. & SSB_TMSHIGH_BUSY), 100000);
  276. val = ci->ops->read32(ci->ctx, CORE_SB(base, sbtmstatehigh));
  277. if (val & SSB_TMSHIGH_BUSY)
  278. brcmf_err("core state still busy\n");
  279. val = ci->ops->read32(ci->ctx, CORE_SB(base, sbidlow));
  280. if (val & SSB_IDLOW_INITIATOR) {
  281. val = ci->ops->read32(ci->ctx,
  282. CORE_SB(base, sbimstate));
  283. val |= SSB_IMSTATE_REJECT;
  284. ci->ops->write32(ci->ctx,
  285. CORE_SB(base, sbimstate), val);
  286. val = ci->ops->read32(ci->ctx,
  287. CORE_SB(base, sbimstate));
  288. udelay(1);
  289. SPINWAIT((ci->ops->read32(ci->ctx,
  290. CORE_SB(base, sbimstate)) &
  291. SSB_IMSTATE_BUSY), 100000);
  292. }
  293. /* set reset and reject while enabling the clocks */
  294. val = SSB_TMSLOW_FGC | SSB_TMSLOW_CLOCK |
  295. SSB_TMSLOW_REJECT | SSB_TMSLOW_RESET;
  296. ci->ops->write32(ci->ctx, CORE_SB(base, sbtmstatelow), val);
  297. val = ci->ops->read32(ci->ctx, CORE_SB(base, sbtmstatelow));
  298. udelay(10);
  299. /* clear the initiator reject bit */
  300. val = ci->ops->read32(ci->ctx, CORE_SB(base, sbidlow));
  301. if (val & SSB_IDLOW_INITIATOR) {
  302. val = ci->ops->read32(ci->ctx,
  303. CORE_SB(base, sbimstate));
  304. val &= ~SSB_IMSTATE_REJECT;
  305. ci->ops->write32(ci->ctx,
  306. CORE_SB(base, sbimstate), val);
  307. }
  308. }
  309. /* leave reset and reject asserted */
  310. ci->ops->write32(ci->ctx, CORE_SB(base, sbtmstatelow),
  311. (SSB_TMSLOW_REJECT | SSB_TMSLOW_RESET));
  312. udelay(1);
  313. }
  314. static void brcmf_chip_ai_coredisable(struct brcmf_core_priv *core,
  315. u32 prereset, u32 reset)
  316. {
  317. struct brcmf_chip_priv *ci;
  318. u32 regdata;
  319. ci = core->chip;
  320. /* if core is already in reset, skip reset */
  321. regdata = ci->ops->read32(ci->ctx, core->wrapbase + BCMA_RESET_CTL);
  322. if ((regdata & BCMA_RESET_CTL_RESET) != 0)
  323. goto in_reset_configure;
  324. /* configure reset */
  325. ci->ops->write32(ci->ctx, core->wrapbase + BCMA_IOCTL,
  326. prereset | BCMA_IOCTL_FGC | BCMA_IOCTL_CLK);
  327. ci->ops->read32(ci->ctx, core->wrapbase + BCMA_IOCTL);
  328. /* put in reset */
  329. ci->ops->write32(ci->ctx, core->wrapbase + BCMA_RESET_CTL,
  330. BCMA_RESET_CTL_RESET);
  331. usleep_range(10, 20);
  332. /* wait till reset is 1 */
  333. SPINWAIT(ci->ops->read32(ci->ctx, core->wrapbase + BCMA_RESET_CTL) !=
  334. BCMA_RESET_CTL_RESET, 300);
  335. in_reset_configure:
  336. /* in-reset configure */
  337. ci->ops->write32(ci->ctx, core->wrapbase + BCMA_IOCTL,
  338. reset | BCMA_IOCTL_FGC | BCMA_IOCTL_CLK);
  339. ci->ops->read32(ci->ctx, core->wrapbase + BCMA_IOCTL);
  340. }
  341. static void brcmf_chip_sb_resetcore(struct brcmf_core_priv *core, u32 prereset,
  342. u32 reset, u32 postreset)
  343. {
  344. struct brcmf_chip_priv *ci;
  345. u32 regdata;
  346. u32 base;
  347. ci = core->chip;
  348. base = core->pub.base;
  349. /*
  350. * Must do the disable sequence first to work for
  351. * arbitrary current core state.
  352. */
  353. brcmf_chip_sb_coredisable(core, 0, 0);
  354. /*
  355. * Now do the initialization sequence.
  356. * set reset while enabling the clock and
  357. * forcing them on throughout the core
  358. */
  359. ci->ops->write32(ci->ctx, CORE_SB(base, sbtmstatelow),
  360. SSB_TMSLOW_FGC | SSB_TMSLOW_CLOCK |
  361. SSB_TMSLOW_RESET);
  362. regdata = ci->ops->read32(ci->ctx, CORE_SB(base, sbtmstatelow));
  363. udelay(1);
  364. /* clear any serror */
  365. regdata = ci->ops->read32(ci->ctx, CORE_SB(base, sbtmstatehigh));
  366. if (regdata & SSB_TMSHIGH_SERR)
  367. ci->ops->write32(ci->ctx, CORE_SB(base, sbtmstatehigh), 0);
  368. regdata = ci->ops->read32(ci->ctx, CORE_SB(base, sbimstate));
  369. if (regdata & (SSB_IMSTATE_IBE | SSB_IMSTATE_TO)) {
  370. regdata &= ~(SSB_IMSTATE_IBE | SSB_IMSTATE_TO);
  371. ci->ops->write32(ci->ctx, CORE_SB(base, sbimstate), regdata);
  372. }
  373. /* clear reset and allow it to propagate throughout the core */
  374. ci->ops->write32(ci->ctx, CORE_SB(base, sbtmstatelow),
  375. SSB_TMSLOW_FGC | SSB_TMSLOW_CLOCK);
  376. regdata = ci->ops->read32(ci->ctx, CORE_SB(base, sbtmstatelow));
  377. udelay(1);
  378. /* leave clock enabled */
  379. ci->ops->write32(ci->ctx, CORE_SB(base, sbtmstatelow),
  380. SSB_TMSLOW_CLOCK);
  381. regdata = ci->ops->read32(ci->ctx, CORE_SB(base, sbtmstatelow));
  382. udelay(1);
  383. }
  384. static void brcmf_chip_ai_resetcore(struct brcmf_core_priv *core, u32 prereset,
  385. u32 reset, u32 postreset)
  386. {
  387. struct brcmf_chip_priv *ci;
  388. int count;
  389. ci = core->chip;
  390. /* must disable first to work for arbitrary current core state */
  391. brcmf_chip_ai_coredisable(core, prereset, reset);
  392. count = 0;
  393. while (ci->ops->read32(ci->ctx, core->wrapbase + BCMA_RESET_CTL) &
  394. BCMA_RESET_CTL_RESET) {
  395. ci->ops->write32(ci->ctx, core->wrapbase + BCMA_RESET_CTL, 0);
  396. count++;
  397. if (count > 50)
  398. break;
  399. usleep_range(40, 60);
  400. }
  401. ci->ops->write32(ci->ctx, core->wrapbase + BCMA_IOCTL,
  402. postreset | BCMA_IOCTL_CLK);
  403. ci->ops->read32(ci->ctx, core->wrapbase + BCMA_IOCTL);
  404. }
  405. char *brcmf_chip_name(u32 id, u32 rev, char *buf, uint len)
  406. {
  407. const char *fmt;
  408. fmt = ((id > 0xa000) || (id < 0x4000)) ? "BCM%d/%u" : "BCM%x/%u";
  409. snprintf(buf, len, fmt, id, rev);
  410. return buf;
  411. }
  412. static struct brcmf_core *brcmf_chip_add_core(struct brcmf_chip_priv *ci,
  413. u16 coreid, u32 base,
  414. u32 wrapbase)
  415. {
  416. struct brcmf_core_priv *core;
  417. core = kzalloc(sizeof(*core), GFP_KERNEL);
  418. if (!core)
  419. return ERR_PTR(-ENOMEM);
  420. core->pub.id = coreid;
  421. core->pub.base = base;
  422. core->chip = ci;
  423. core->wrapbase = wrapbase;
  424. list_add_tail(&core->list, &ci->cores);
  425. return &core->pub;
  426. }
  427. /* safety check for chipinfo */
  428. static int brcmf_chip_cores_check(struct brcmf_chip_priv *ci)
  429. {
  430. struct brcmf_core_priv *core;
  431. bool need_socram = false;
  432. bool has_socram = false;
  433. bool cpu_found = false;
  434. int idx = 1;
  435. list_for_each_entry(core, &ci->cores, list) {
  436. brcmf_dbg(INFO, " [%-2d] core 0x%x:%-2d base 0x%08x wrap 0x%08x\n",
  437. idx++, core->pub.id, core->pub.rev, core->pub.base,
  438. core->wrapbase);
  439. switch (core->pub.id) {
  440. case BCMA_CORE_ARM_CM3:
  441. cpu_found = true;
  442. need_socram = true;
  443. break;
  444. case BCMA_CORE_INTERNAL_MEM:
  445. has_socram = true;
  446. break;
  447. case BCMA_CORE_ARM_CR4:
  448. cpu_found = true;
  449. break;
  450. case BCMA_CORE_ARM_CA7:
  451. cpu_found = true;
  452. break;
  453. default:
  454. break;
  455. }
  456. }
  457. if (!cpu_found) {
  458. brcmf_err("CPU core not detected\n");
  459. return -ENXIO;
  460. }
  461. /* check RAM core presence for ARM CM3 core */
  462. if (need_socram && !has_socram) {
  463. brcmf_err("RAM core not provided with ARM CM3 core\n");
  464. return -ENODEV;
  465. }
  466. return 0;
  467. }
  468. static u32 brcmf_chip_core_read32(struct brcmf_core_priv *core, u16 reg)
  469. {
  470. return core->chip->ops->read32(core->chip->ctx, core->pub.base + reg);
  471. }
  472. static void brcmf_chip_core_write32(struct brcmf_core_priv *core,
  473. u16 reg, u32 val)
  474. {
  475. core->chip->ops->write32(core->chip->ctx, core->pub.base + reg, val);
  476. }
  477. static bool brcmf_chip_socram_banksize(struct brcmf_core_priv *core, u8 idx,
  478. u32 *banksize)
  479. {
  480. u32 bankinfo;
  481. u32 bankidx = (SOCRAM_MEMTYPE_RAM << SOCRAM_BANKIDX_MEMTYPE_SHIFT);
  482. bankidx |= idx;
  483. brcmf_chip_core_write32(core, SOCRAMREGOFFS(bankidx), bankidx);
  484. bankinfo = brcmf_chip_core_read32(core, SOCRAMREGOFFS(bankinfo));
  485. *banksize = (bankinfo & SOCRAM_BANKINFO_SZMASK) + 1;
  486. *banksize *= SOCRAM_BANKINFO_SZBASE;
  487. return !!(bankinfo & SOCRAM_BANKINFO_RETNTRAM_MASK);
  488. }
  489. static void brcmf_chip_socram_ramsize(struct brcmf_core_priv *sr, u32 *ramsize,
  490. u32 *srsize)
  491. {
  492. u32 coreinfo;
  493. uint nb, banksize, lss;
  494. bool retent;
  495. int i;
  496. *ramsize = 0;
  497. *srsize = 0;
  498. if (WARN_ON(sr->pub.rev < 4))
  499. return;
  500. if (!brcmf_chip_iscoreup(&sr->pub))
  501. brcmf_chip_resetcore(&sr->pub, 0, 0, 0);
  502. /* Get info for determining size */
  503. coreinfo = brcmf_chip_core_read32(sr, SOCRAMREGOFFS(coreinfo));
  504. nb = (coreinfo & SRCI_SRNB_MASK) >> SRCI_SRNB_SHIFT;
  505. if ((sr->pub.rev <= 7) || (sr->pub.rev == 12)) {
  506. banksize = (coreinfo & SRCI_SRBSZ_MASK);
  507. lss = (coreinfo & SRCI_LSS_MASK) >> SRCI_LSS_SHIFT;
  508. if (lss != 0)
  509. nb--;
  510. *ramsize = nb * (1 << (banksize + SR_BSZ_BASE));
  511. if (lss != 0)
  512. *ramsize += (1 << ((lss - 1) + SR_BSZ_BASE));
  513. } else {
  514. nb = (coreinfo & SRCI_SRNB_MASK) >> SRCI_SRNB_SHIFT;
  515. for (i = 0; i < nb; i++) {
  516. retent = brcmf_chip_socram_banksize(sr, i, &banksize);
  517. *ramsize += banksize;
  518. if (retent)
  519. *srsize += banksize;
  520. }
  521. }
  522. /* hardcoded save&restore memory sizes */
  523. switch (sr->chip->pub.chip) {
  524. case BRCM_CC_4334_CHIP_ID:
  525. if (sr->chip->pub.chiprev < 2)
  526. *srsize = (32 * 1024);
  527. break;
  528. case BRCM_CC_43430_CHIP_ID:
  529. /* assume sr for now as we can not check
  530. * firmware sr capability at this point.
  531. */
  532. *srsize = (64 * 1024);
  533. break;
  534. default:
  535. break;
  536. }
  537. }
  538. /** Return the SYS MEM size */
  539. static u32 brcmf_chip_sysmem_ramsize(struct brcmf_core_priv *sysmem)
  540. {
  541. u32 memsize = 0;
  542. u32 coreinfo;
  543. u32 idx;
  544. u32 nb;
  545. u32 banksize;
  546. if (!brcmf_chip_iscoreup(&sysmem->pub))
  547. brcmf_chip_resetcore(&sysmem->pub, 0, 0, 0);
  548. coreinfo = brcmf_chip_core_read32(sysmem, SYSMEMREGOFFS(coreinfo));
  549. nb = (coreinfo & SRCI_SRNB_MASK) >> SRCI_SRNB_SHIFT;
  550. for (idx = 0; idx < nb; idx++) {
  551. brcmf_chip_socram_banksize(sysmem, idx, &banksize);
  552. memsize += banksize;
  553. }
  554. return memsize;
  555. }
  556. /** Return the TCM-RAM size of the ARMCR4 core. */
  557. static u32 brcmf_chip_tcm_ramsize(struct brcmf_core_priv *cr4)
  558. {
  559. u32 corecap;
  560. u32 memsize = 0;
  561. u32 nab;
  562. u32 nbb;
  563. u32 totb;
  564. u32 bxinfo;
  565. u32 idx;
  566. corecap = brcmf_chip_core_read32(cr4, ARMCR4_CAP);
  567. nab = (corecap & ARMCR4_TCBANB_MASK) >> ARMCR4_TCBANB_SHIFT;
  568. nbb = (corecap & ARMCR4_TCBBNB_MASK) >> ARMCR4_TCBBNB_SHIFT;
  569. totb = nab + nbb;
  570. for (idx = 0; idx < totb; idx++) {
  571. brcmf_chip_core_write32(cr4, ARMCR4_BANKIDX, idx);
  572. bxinfo = brcmf_chip_core_read32(cr4, ARMCR4_BANKINFO);
  573. memsize += ((bxinfo & ARMCR4_BSZ_MASK) + 1) * ARMCR4_BSZ_MULT;
  574. }
  575. return memsize;
  576. }
  577. static u32 brcmf_chip_tcm_rambase(struct brcmf_chip_priv *ci)
  578. {
  579. switch (ci->pub.chip) {
  580. case BRCM_CC_4345_CHIP_ID:
  581. return 0x198000;
  582. case BRCM_CC_4335_CHIP_ID:
  583. case BRCM_CC_4339_CHIP_ID:
  584. case BRCM_CC_4350_CHIP_ID:
  585. case BRCM_CC_4354_CHIP_ID:
  586. case BRCM_CC_4356_CHIP_ID:
  587. case BRCM_CC_43567_CHIP_ID:
  588. case BRCM_CC_43569_CHIP_ID:
  589. case BRCM_CC_43570_CHIP_ID:
  590. case BRCM_CC_4358_CHIP_ID:
  591. case BRCM_CC_4359_CHIP_ID:
  592. case BRCM_CC_43602_CHIP_ID:
  593. case BRCM_CC_4371_CHIP_ID:
  594. return 0x180000;
  595. case BRCM_CC_43465_CHIP_ID:
  596. case BRCM_CC_43525_CHIP_ID:
  597. case BRCM_CC_4365_CHIP_ID:
  598. case BRCM_CC_4366_CHIP_ID:
  599. case BRCM_CC_43664_CHIP_ID:
  600. return 0x200000;
  601. case CY_CC_4373_CHIP_ID:
  602. return 0x160000;
  603. default:
  604. brcmf_err("unknown chip: %s\n", ci->pub.name);
  605. break;
  606. }
  607. return 0;
  608. }
  609. static int brcmf_chip_get_raminfo(struct brcmf_chip_priv *ci)
  610. {
  611. struct brcmf_core_priv *mem_core;
  612. struct brcmf_core *mem;
  613. mem = brcmf_chip_get_core(&ci->pub, BCMA_CORE_ARM_CR4);
  614. if (mem) {
  615. mem_core = container_of(mem, struct brcmf_core_priv, pub);
  616. ci->pub.ramsize = brcmf_chip_tcm_ramsize(mem_core);
  617. ci->pub.rambase = brcmf_chip_tcm_rambase(ci);
  618. if (!ci->pub.rambase) {
  619. brcmf_err("RAM base not provided with ARM CR4 core\n");
  620. return -EINVAL;
  621. }
  622. } else {
  623. mem = brcmf_chip_get_core(&ci->pub, BCMA_CORE_SYS_MEM);
  624. if (mem) {
  625. mem_core = container_of(mem, struct brcmf_core_priv,
  626. pub);
  627. ci->pub.ramsize = brcmf_chip_sysmem_ramsize(mem_core);
  628. ci->pub.rambase = brcmf_chip_tcm_rambase(ci);
  629. if (!ci->pub.rambase) {
  630. brcmf_err("RAM base not provided with ARM CA7 core\n");
  631. return -EINVAL;
  632. }
  633. } else {
  634. mem = brcmf_chip_get_core(&ci->pub,
  635. BCMA_CORE_INTERNAL_MEM);
  636. if (!mem) {
  637. brcmf_err("No memory cores found\n");
  638. return -ENOMEM;
  639. }
  640. mem_core = container_of(mem, struct brcmf_core_priv,
  641. pub);
  642. brcmf_chip_socram_ramsize(mem_core, &ci->pub.ramsize,
  643. &ci->pub.srsize);
  644. }
  645. }
  646. brcmf_dbg(INFO, "RAM: base=0x%x size=%d (0x%x) sr=%d (0x%x)\n",
  647. ci->pub.rambase, ci->pub.ramsize, ci->pub.ramsize,
  648. ci->pub.srsize, ci->pub.srsize);
  649. if (!ci->pub.ramsize) {
  650. brcmf_err("RAM size is undetermined\n");
  651. return -ENOMEM;
  652. }
  653. if (ci->pub.ramsize > BRCMF_CHIP_MAX_MEMSIZE) {
  654. brcmf_err("RAM size is incorrect\n");
  655. return -ENOMEM;
  656. }
  657. return 0;
  658. }
  659. static u32 brcmf_chip_dmp_get_desc(struct brcmf_chip_priv *ci, u32 *eromaddr,
  660. u8 *type)
  661. {
  662. u32 val;
  663. /* read next descriptor */
  664. val = ci->ops->read32(ci->ctx, *eromaddr);
  665. *eromaddr += 4;
  666. if (!type)
  667. return val;
  668. /* determine descriptor type */
  669. *type = (val & DMP_DESC_TYPE_MSK);
  670. if ((*type & ~DMP_DESC_ADDRSIZE_GT32) == DMP_DESC_ADDRESS)
  671. *type = DMP_DESC_ADDRESS;
  672. return val;
  673. }
  674. static int brcmf_chip_dmp_get_regaddr(struct brcmf_chip_priv *ci, u32 *eromaddr,
  675. u32 *regbase, u32 *wrapbase)
  676. {
  677. u8 desc;
  678. u32 val;
  679. u8 mpnum = 0;
  680. u8 stype, sztype, wraptype;
  681. *regbase = 0;
  682. *wrapbase = 0;
  683. val = brcmf_chip_dmp_get_desc(ci, eromaddr, &desc);
  684. if (desc == DMP_DESC_MASTER_PORT) {
  685. mpnum = (val & DMP_MASTER_PORT_NUM) >> DMP_MASTER_PORT_NUM_S;
  686. wraptype = DMP_SLAVE_TYPE_MWRAP;
  687. } else if (desc == DMP_DESC_ADDRESS) {
  688. /* revert erom address */
  689. *eromaddr -= 4;
  690. wraptype = DMP_SLAVE_TYPE_SWRAP;
  691. } else {
  692. *eromaddr -= 4;
  693. return -EILSEQ;
  694. }
  695. do {
  696. /* locate address descriptor */
  697. do {
  698. val = brcmf_chip_dmp_get_desc(ci, eromaddr, &desc);
  699. /* unexpected table end */
  700. if (desc == DMP_DESC_EOT) {
  701. *eromaddr -= 4;
  702. return -EFAULT;
  703. }
  704. } while (desc != DMP_DESC_ADDRESS &&
  705. desc != DMP_DESC_COMPONENT);
  706. /* stop if we crossed current component border */
  707. if (desc == DMP_DESC_COMPONENT) {
  708. *eromaddr -= 4;
  709. return 0;
  710. }
  711. /* skip upper 32-bit address descriptor */
  712. if (val & DMP_DESC_ADDRSIZE_GT32)
  713. brcmf_chip_dmp_get_desc(ci, eromaddr, NULL);
  714. sztype = (val & DMP_SLAVE_SIZE_TYPE) >> DMP_SLAVE_SIZE_TYPE_S;
  715. /* next size descriptor can be skipped */
  716. if (sztype == DMP_SLAVE_SIZE_DESC) {
  717. val = brcmf_chip_dmp_get_desc(ci, eromaddr, NULL);
  718. /* skip upper size descriptor if present */
  719. if (val & DMP_DESC_ADDRSIZE_GT32)
  720. brcmf_chip_dmp_get_desc(ci, eromaddr, NULL);
  721. }
  722. /* only look for 4K register regions */
  723. if (sztype != DMP_SLAVE_SIZE_4K)
  724. continue;
  725. stype = (val & DMP_SLAVE_TYPE) >> DMP_SLAVE_TYPE_S;
  726. /* only regular slave and wrapper */
  727. if (*regbase == 0 && stype == DMP_SLAVE_TYPE_SLAVE)
  728. *regbase = val & DMP_SLAVE_ADDR_BASE;
  729. if (*wrapbase == 0 && stype == wraptype)
  730. *wrapbase = val & DMP_SLAVE_ADDR_BASE;
  731. } while (*regbase == 0 || *wrapbase == 0);
  732. return 0;
  733. }
  734. static
  735. int brcmf_chip_dmp_erom_scan(struct brcmf_chip_priv *ci)
  736. {
  737. struct brcmf_core *core;
  738. u32 eromaddr;
  739. u8 desc_type = 0;
  740. u32 val;
  741. u16 id;
  742. u8 nmp, nsp, nmw, nsw, rev;
  743. u32 base, wrap;
  744. int err;
  745. eromaddr = ci->ops->read32(ci->ctx, CORE_CC_REG(SI_ENUM_BASE, eromptr));
  746. while (desc_type != DMP_DESC_EOT) {
  747. val = brcmf_chip_dmp_get_desc(ci, &eromaddr, &desc_type);
  748. if (!(val & DMP_DESC_VALID))
  749. continue;
  750. if (desc_type == DMP_DESC_EMPTY)
  751. continue;
  752. /* need a component descriptor */
  753. if (desc_type != DMP_DESC_COMPONENT)
  754. continue;
  755. id = (val & DMP_COMP_PARTNUM) >> DMP_COMP_PARTNUM_S;
  756. /* next descriptor must be component as well */
  757. val = brcmf_chip_dmp_get_desc(ci, &eromaddr, &desc_type);
  758. if (WARN_ON((val & DMP_DESC_TYPE_MSK) != DMP_DESC_COMPONENT))
  759. return -EFAULT;
  760. /* only look at cores with master port(s) */
  761. nmp = (val & DMP_COMP_NUM_MPORT) >> DMP_COMP_NUM_MPORT_S;
  762. nsp = (val & DMP_COMP_NUM_SPORT) >> DMP_COMP_NUM_SPORT_S;
  763. nmw = (val & DMP_COMP_NUM_MWRAP) >> DMP_COMP_NUM_MWRAP_S;
  764. nsw = (val & DMP_COMP_NUM_SWRAP) >> DMP_COMP_NUM_SWRAP_S;
  765. rev = (val & DMP_COMP_REVISION) >> DMP_COMP_REVISION_S;
  766. /* need core with ports */
  767. if (nmw + nsw == 0 &&
  768. id != BCMA_CORE_PMU)
  769. continue;
  770. /* try to obtain register address info */
  771. err = brcmf_chip_dmp_get_regaddr(ci, &eromaddr, &base, &wrap);
  772. if (err)
  773. continue;
  774. /* finally a core to be added */
  775. core = brcmf_chip_add_core(ci, id, base, wrap);
  776. if (IS_ERR(core))
  777. return PTR_ERR(core);
  778. core->rev = rev;
  779. }
  780. return 0;
  781. }
  782. static int brcmf_chip_recognition(struct brcmf_chip_priv *ci)
  783. {
  784. struct brcmf_core *core;
  785. u32 regdata;
  786. u32 socitype;
  787. int ret;
  788. /* Get CC core rev
  789. * Chipid is assume to be at offset 0 from SI_ENUM_BASE
  790. * For different chiptypes or old sdio hosts w/o chipcommon,
  791. * other ways of recognition should be added here.
  792. */
  793. regdata = ci->ops->read32(ci->ctx, CORE_CC_REG(SI_ENUM_BASE, chipid));
  794. ci->pub.chip = regdata & CID_ID_MASK;
  795. ci->pub.chiprev = (regdata & CID_REV_MASK) >> CID_REV_SHIFT;
  796. socitype = (regdata & CID_TYPE_MASK) >> CID_TYPE_SHIFT;
  797. brcmf_chip_name(ci->pub.chip, ci->pub.chiprev,
  798. ci->pub.name, sizeof(ci->pub.name));
  799. brcmf_dbg(INFO, "found %s chip: %s\n",
  800. socitype == SOCI_SB ? "SB" : "AXI", ci->pub.name);
  801. if (socitype == SOCI_SB) {
  802. if (ci->pub.chip != BRCM_CC_4329_CHIP_ID) {
  803. brcmf_err("SB chip is not supported\n");
  804. return -ENODEV;
  805. }
  806. ci->iscoreup = brcmf_chip_sb_iscoreup;
  807. ci->coredisable = brcmf_chip_sb_coredisable;
  808. ci->resetcore = brcmf_chip_sb_resetcore;
  809. core = brcmf_chip_add_core(ci, BCMA_CORE_CHIPCOMMON,
  810. SI_ENUM_BASE, 0);
  811. brcmf_chip_sb_corerev(ci, core);
  812. core = brcmf_chip_add_core(ci, BCMA_CORE_SDIO_DEV,
  813. BCM4329_CORE_BUS_BASE, 0);
  814. brcmf_chip_sb_corerev(ci, core);
  815. core = brcmf_chip_add_core(ci, BCMA_CORE_INTERNAL_MEM,
  816. BCM4329_CORE_SOCRAM_BASE, 0);
  817. brcmf_chip_sb_corerev(ci, core);
  818. core = brcmf_chip_add_core(ci, BCMA_CORE_ARM_CM3,
  819. BCM4329_CORE_ARM_BASE, 0);
  820. brcmf_chip_sb_corerev(ci, core);
  821. core = brcmf_chip_add_core(ci, BCMA_CORE_80211, 0x18001000, 0);
  822. brcmf_chip_sb_corerev(ci, core);
  823. } else if (socitype == SOCI_AI) {
  824. ci->iscoreup = brcmf_chip_ai_iscoreup;
  825. ci->coredisable = brcmf_chip_ai_coredisable;
  826. ci->resetcore = brcmf_chip_ai_resetcore;
  827. brcmf_chip_dmp_erom_scan(ci);
  828. } else {
  829. brcmf_err("chip backplane type %u is not supported\n",
  830. socitype);
  831. return -ENODEV;
  832. }
  833. ret = brcmf_chip_cores_check(ci);
  834. if (ret)
  835. return ret;
  836. /* assure chip is passive for core access */
  837. brcmf_chip_set_passive(&ci->pub);
  838. /* Call bus specific reset function now. Cores have been determined
  839. * but further access may require a chip specific reset at this point.
  840. */
  841. if (ci->ops->reset) {
  842. ci->ops->reset(ci->ctx, &ci->pub);
  843. brcmf_chip_set_passive(&ci->pub);
  844. }
  845. return brcmf_chip_get_raminfo(ci);
  846. }
  847. static void brcmf_chip_disable_arm(struct brcmf_chip_priv *chip, u16 id)
  848. {
  849. struct brcmf_core *core;
  850. struct brcmf_core_priv *cpu;
  851. u32 val;
  852. core = brcmf_chip_get_core(&chip->pub, id);
  853. if (!core)
  854. return;
  855. switch (id) {
  856. case BCMA_CORE_ARM_CM3:
  857. brcmf_chip_coredisable(core, 0, 0);
  858. break;
  859. case BCMA_CORE_ARM_CR4:
  860. case BCMA_CORE_ARM_CA7:
  861. cpu = container_of(core, struct brcmf_core_priv, pub);
  862. /* clear all IOCTL bits except HALT bit */
  863. val = chip->ops->read32(chip->ctx, cpu->wrapbase + BCMA_IOCTL);
  864. val &= ARMCR4_BCMA_IOCTL_CPUHALT;
  865. brcmf_chip_resetcore(core, val, ARMCR4_BCMA_IOCTL_CPUHALT,
  866. ARMCR4_BCMA_IOCTL_CPUHALT);
  867. break;
  868. default:
  869. brcmf_err("unknown id: %u\n", id);
  870. break;
  871. }
  872. }
  873. static int brcmf_chip_setup(struct brcmf_chip_priv *chip)
  874. {
  875. struct brcmf_chip *pub;
  876. struct brcmf_core_priv *cc;
  877. struct brcmf_core *pmu;
  878. u32 base;
  879. u32 val;
  880. int ret = 0;
  881. pub = &chip->pub;
  882. cc = list_first_entry(&chip->cores, struct brcmf_core_priv, list);
  883. base = cc->pub.base;
  884. /* get chipcommon capabilites */
  885. pub->cc_caps = chip->ops->read32(chip->ctx,
  886. CORE_CC_REG(base, capabilities));
  887. pub->cc_caps_ext = chip->ops->read32(chip->ctx,
  888. CORE_CC_REG(base,
  889. capabilities_ext));
  890. /* get pmu caps & rev */
  891. pmu = brcmf_chip_get_pmu(pub); /* after reading cc_caps_ext */
  892. if (pub->cc_caps & CC_CAP_PMU) {
  893. val = chip->ops->read32(chip->ctx,
  894. CORE_CC_REG(pmu->base, pmucapabilities));
  895. pub->pmurev = val & PCAP_REV_MASK;
  896. pub->pmucaps = val;
  897. }
  898. brcmf_dbg(INFO, "ccrev=%d, pmurev=%d, pmucaps=0x%x\n",
  899. cc->pub.rev, pub->pmurev, pub->pmucaps);
  900. /* execute bus core specific setup */
  901. if (chip->ops->setup)
  902. ret = chip->ops->setup(chip->ctx, pub);
  903. return ret;
  904. }
  905. struct brcmf_chip *brcmf_chip_attach(void *ctx,
  906. const struct brcmf_buscore_ops *ops)
  907. {
  908. struct brcmf_chip_priv *chip;
  909. int err = 0;
  910. if (WARN_ON(!ops->read32))
  911. err = -EINVAL;
  912. if (WARN_ON(!ops->write32))
  913. err = -EINVAL;
  914. if (WARN_ON(!ops->prepare))
  915. err = -EINVAL;
  916. if (WARN_ON(!ops->activate))
  917. err = -EINVAL;
  918. if (err < 0)
  919. return ERR_PTR(-EINVAL);
  920. chip = kzalloc(sizeof(*chip), GFP_KERNEL);
  921. if (!chip)
  922. return ERR_PTR(-ENOMEM);
  923. INIT_LIST_HEAD(&chip->cores);
  924. chip->num_cores = 0;
  925. chip->ops = ops;
  926. chip->ctx = ctx;
  927. err = ops->prepare(ctx);
  928. if (err < 0)
  929. goto fail;
  930. err = brcmf_chip_recognition(chip);
  931. if (err < 0)
  932. goto fail;
  933. err = brcmf_chip_setup(chip);
  934. if (err < 0)
  935. goto fail;
  936. return &chip->pub;
  937. fail:
  938. brcmf_chip_detach(&chip->pub);
  939. return ERR_PTR(err);
  940. }
  941. void brcmf_chip_detach(struct brcmf_chip *pub)
  942. {
  943. struct brcmf_chip_priv *chip;
  944. struct brcmf_core_priv *core;
  945. struct brcmf_core_priv *tmp;
  946. chip = container_of(pub, struct brcmf_chip_priv, pub);
  947. list_for_each_entry_safe(core, tmp, &chip->cores, list) {
  948. list_del(&core->list);
  949. kfree(core);
  950. }
  951. kfree(chip);
  952. }
  953. struct brcmf_core *brcmf_chip_get_core(struct brcmf_chip *pub, u16 coreid)
  954. {
  955. struct brcmf_chip_priv *chip;
  956. struct brcmf_core_priv *core;
  957. chip = container_of(pub, struct brcmf_chip_priv, pub);
  958. list_for_each_entry(core, &chip->cores, list)
  959. if (core->pub.id == coreid)
  960. return &core->pub;
  961. return NULL;
  962. }
  963. struct brcmf_core *brcmf_chip_get_chipcommon(struct brcmf_chip *pub)
  964. {
  965. struct brcmf_chip_priv *chip;
  966. struct brcmf_core_priv *cc;
  967. chip = container_of(pub, struct brcmf_chip_priv, pub);
  968. cc = list_first_entry(&chip->cores, struct brcmf_core_priv, list);
  969. if (WARN_ON(!cc || cc->pub.id != BCMA_CORE_CHIPCOMMON))
  970. return brcmf_chip_get_core(pub, BCMA_CORE_CHIPCOMMON);
  971. return &cc->pub;
  972. }
  973. struct brcmf_core *brcmf_chip_get_pmu(struct brcmf_chip *pub)
  974. {
  975. struct brcmf_core *cc = brcmf_chip_get_chipcommon(pub);
  976. struct brcmf_core *pmu;
  977. /* See if there is separated PMU core available */
  978. if (cc->rev >= 35 &&
  979. pub->cc_caps_ext & BCMA_CC_CAP_EXT_AOB_PRESENT) {
  980. pmu = brcmf_chip_get_core(pub, BCMA_CORE_PMU);
  981. if (pmu)
  982. return pmu;
  983. }
  984. /* Fallback to ChipCommon core for older hardware */
  985. return cc;
  986. }
  987. bool brcmf_chip_iscoreup(struct brcmf_core *pub)
  988. {
  989. struct brcmf_core_priv *core;
  990. core = container_of(pub, struct brcmf_core_priv, pub);
  991. return core->chip->iscoreup(core);
  992. }
  993. void brcmf_chip_coredisable(struct brcmf_core *pub, u32 prereset, u32 reset)
  994. {
  995. struct brcmf_core_priv *core;
  996. core = container_of(pub, struct brcmf_core_priv, pub);
  997. core->chip->coredisable(core, prereset, reset);
  998. }
  999. void brcmf_chip_resetcore(struct brcmf_core *pub, u32 prereset, u32 reset,
  1000. u32 postreset)
  1001. {
  1002. struct brcmf_core_priv *core;
  1003. core = container_of(pub, struct brcmf_core_priv, pub);
  1004. core->chip->resetcore(core, prereset, reset, postreset);
  1005. }
  1006. static void
  1007. brcmf_chip_cm3_set_passive(struct brcmf_chip_priv *chip)
  1008. {
  1009. struct brcmf_core *core;
  1010. struct brcmf_core_priv *sr;
  1011. brcmf_chip_disable_arm(chip, BCMA_CORE_ARM_CM3);
  1012. core = brcmf_chip_get_core(&chip->pub, BCMA_CORE_80211);
  1013. brcmf_chip_resetcore(core, D11_BCMA_IOCTL_PHYRESET |
  1014. D11_BCMA_IOCTL_PHYCLOCKEN,
  1015. D11_BCMA_IOCTL_PHYCLOCKEN,
  1016. D11_BCMA_IOCTL_PHYCLOCKEN);
  1017. core = brcmf_chip_get_core(&chip->pub, BCMA_CORE_INTERNAL_MEM);
  1018. brcmf_chip_resetcore(core, 0, 0, 0);
  1019. /* disable bank #3 remap for this device */
  1020. if (chip->pub.chip == BRCM_CC_43430_CHIP_ID) {
  1021. sr = container_of(core, struct brcmf_core_priv, pub);
  1022. brcmf_chip_core_write32(sr, SOCRAMREGOFFS(bankidx), 3);
  1023. brcmf_chip_core_write32(sr, SOCRAMREGOFFS(bankpda), 0);
  1024. }
  1025. }
  1026. static bool brcmf_chip_cm3_set_active(struct brcmf_chip_priv *chip)
  1027. {
  1028. struct brcmf_core *core;
  1029. core = brcmf_chip_get_core(&chip->pub, BCMA_CORE_INTERNAL_MEM);
  1030. if (!brcmf_chip_iscoreup(core)) {
  1031. brcmf_err("SOCRAM core is down after reset?\n");
  1032. return false;
  1033. }
  1034. chip->ops->activate(chip->ctx, &chip->pub, 0);
  1035. core = brcmf_chip_get_core(&chip->pub, BCMA_CORE_ARM_CM3);
  1036. brcmf_chip_resetcore(core, 0, 0, 0);
  1037. return true;
  1038. }
  1039. static inline void
  1040. brcmf_chip_cr4_set_passive(struct brcmf_chip_priv *chip)
  1041. {
  1042. struct brcmf_core *core;
  1043. brcmf_chip_disable_arm(chip, BCMA_CORE_ARM_CR4);
  1044. core = brcmf_chip_get_core(&chip->pub, BCMA_CORE_80211);
  1045. brcmf_chip_resetcore(core, D11_BCMA_IOCTL_PHYRESET |
  1046. D11_BCMA_IOCTL_PHYCLOCKEN,
  1047. D11_BCMA_IOCTL_PHYCLOCKEN,
  1048. D11_BCMA_IOCTL_PHYCLOCKEN);
  1049. }
  1050. static bool brcmf_chip_cr4_set_active(struct brcmf_chip_priv *chip, u32 rstvec)
  1051. {
  1052. struct brcmf_core *core;
  1053. chip->ops->activate(chip->ctx, &chip->pub, rstvec);
  1054. /* restore ARM */
  1055. core = brcmf_chip_get_core(&chip->pub, BCMA_CORE_ARM_CR4);
  1056. brcmf_chip_resetcore(core, ARMCR4_BCMA_IOCTL_CPUHALT, 0, 0);
  1057. return true;
  1058. }
  1059. static inline void
  1060. brcmf_chip_ca7_set_passive(struct brcmf_chip_priv *chip)
  1061. {
  1062. struct brcmf_core *core;
  1063. brcmf_chip_disable_arm(chip, BCMA_CORE_ARM_CA7);
  1064. core = brcmf_chip_get_core(&chip->pub, BCMA_CORE_80211);
  1065. brcmf_chip_resetcore(core, D11_BCMA_IOCTL_PHYRESET |
  1066. D11_BCMA_IOCTL_PHYCLOCKEN,
  1067. D11_BCMA_IOCTL_PHYCLOCKEN,
  1068. D11_BCMA_IOCTL_PHYCLOCKEN);
  1069. }
  1070. static bool brcmf_chip_ca7_set_active(struct brcmf_chip_priv *chip, u32 rstvec)
  1071. {
  1072. struct brcmf_core *core;
  1073. chip->ops->activate(chip->ctx, &chip->pub, rstvec);
  1074. /* restore ARM */
  1075. core = brcmf_chip_get_core(&chip->pub, BCMA_CORE_ARM_CA7);
  1076. brcmf_chip_resetcore(core, ARMCR4_BCMA_IOCTL_CPUHALT, 0, 0);
  1077. return true;
  1078. }
  1079. void brcmf_chip_set_passive(struct brcmf_chip *pub)
  1080. {
  1081. struct brcmf_chip_priv *chip;
  1082. struct brcmf_core *arm;
  1083. brcmf_dbg(TRACE, "Enter\n");
  1084. chip = container_of(pub, struct brcmf_chip_priv, pub);
  1085. arm = brcmf_chip_get_core(pub, BCMA_CORE_ARM_CR4);
  1086. if (arm) {
  1087. brcmf_chip_cr4_set_passive(chip);
  1088. return;
  1089. }
  1090. arm = brcmf_chip_get_core(pub, BCMA_CORE_ARM_CA7);
  1091. if (arm) {
  1092. brcmf_chip_ca7_set_passive(chip);
  1093. return;
  1094. }
  1095. arm = brcmf_chip_get_core(pub, BCMA_CORE_ARM_CM3);
  1096. if (arm) {
  1097. brcmf_chip_cm3_set_passive(chip);
  1098. return;
  1099. }
  1100. }
  1101. bool brcmf_chip_set_active(struct brcmf_chip *pub, u32 rstvec)
  1102. {
  1103. struct brcmf_chip_priv *chip;
  1104. struct brcmf_core *arm;
  1105. brcmf_dbg(TRACE, "Enter\n");
  1106. chip = container_of(pub, struct brcmf_chip_priv, pub);
  1107. arm = brcmf_chip_get_core(pub, BCMA_CORE_ARM_CR4);
  1108. if (arm)
  1109. return brcmf_chip_cr4_set_active(chip, rstvec);
  1110. arm = brcmf_chip_get_core(pub, BCMA_CORE_ARM_CA7);
  1111. if (arm)
  1112. return brcmf_chip_ca7_set_active(chip, rstvec);
  1113. arm = brcmf_chip_get_core(pub, BCMA_CORE_ARM_CM3);
  1114. if (arm)
  1115. return brcmf_chip_cm3_set_active(chip);
  1116. return false;
  1117. }
  1118. bool brcmf_chip_sr_capable(struct brcmf_chip *pub)
  1119. {
  1120. u32 base, addr, reg, pmu_cc3_mask = ~0;
  1121. struct brcmf_chip_priv *chip;
  1122. struct brcmf_core *pmu = brcmf_chip_get_pmu(pub);
  1123. brcmf_dbg(TRACE, "Enter\n");
  1124. /* old chips with PMU version less than 17 don't support save restore */
  1125. if (pub->pmurev < 17)
  1126. return false;
  1127. base = brcmf_chip_get_chipcommon(pub)->base;
  1128. chip = container_of(pub, struct brcmf_chip_priv, pub);
  1129. switch (pub->chip) {
  1130. case BRCM_CC_4354_CHIP_ID:
  1131. case BRCM_CC_4356_CHIP_ID:
  1132. case BRCM_CC_4345_CHIP_ID:
  1133. /* explicitly check SR engine enable bit */
  1134. pmu_cc3_mask = BIT(2);
  1135. /* fall-through */
  1136. case BRCM_CC_43241_CHIP_ID:
  1137. case BRCM_CC_4335_CHIP_ID:
  1138. case BRCM_CC_4339_CHIP_ID:
  1139. /* read PMU chipcontrol register 3 */
  1140. addr = CORE_CC_REG(pmu->base, chipcontrol_addr);
  1141. chip->ops->write32(chip->ctx, addr, 3);
  1142. addr = CORE_CC_REG(pmu->base, chipcontrol_data);
  1143. reg = chip->ops->read32(chip->ctx, addr);
  1144. return (reg & pmu_cc3_mask) != 0;
  1145. case BRCM_CC_43430_CHIP_ID:
  1146. addr = CORE_CC_REG(base, sr_control1);
  1147. reg = chip->ops->read32(chip->ctx, addr);
  1148. return reg != 0;
  1149. default:
  1150. addr = CORE_CC_REG(pmu->base, pmucapabilities_ext);
  1151. reg = chip->ops->read32(chip->ctx, addr);
  1152. if ((reg & PCAPEXT_SR_SUPPORTED_MASK) == 0)
  1153. return false;
  1154. addr = CORE_CC_REG(pmu->base, retention_ctl);
  1155. reg = chip->ops->read32(chip->ctx, addr);
  1156. return (reg & (PMU_RCTL_MACPHY_DISABLE_MASK |
  1157. PMU_RCTL_LOGIC_DISABLE_MASK)) == 0;
  1158. }
  1159. }