aiutils.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740
  1. /*
  2. * Copyright (c) 2010 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. * File contents: support functions for PCI/PCIe
  17. */
  18. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  19. #include <linux/delay.h>
  20. #include <defs.h>
  21. #include <chipcommon.h>
  22. #include <brcmu_utils.h>
  23. #include <brcm_hw_ids.h>
  24. #include <soc.h>
  25. #include "types.h"
  26. #include "pub.h"
  27. #include "pmu.h"
  28. #include "aiutils.h"
  29. /* slow_clk_ctl */
  30. /* slow clock source mask */
  31. #define SCC_SS_MASK 0x00000007
  32. /* source of slow clock is LPO */
  33. #define SCC_SS_LPO 0x00000000
  34. /* source of slow clock is crystal */
  35. #define SCC_SS_XTAL 0x00000001
  36. /* source of slow clock is PCI */
  37. #define SCC_SS_PCI 0x00000002
  38. /* LPOFreqSel, 1: 160Khz, 0: 32KHz */
  39. #define SCC_LF 0x00000200
  40. /* LPOPowerDown, 1: LPO is disabled, 0: LPO is enabled */
  41. #define SCC_LP 0x00000400
  42. /* ForceSlowClk, 1: sb/cores running on slow clock, 0: power logic control */
  43. #define SCC_FS 0x00000800
  44. /* IgnorePllOffReq, 1/0:
  45. * power logic ignores/honors PLL clock disable requests from core
  46. */
  47. #define SCC_IP 0x00001000
  48. /* XtalControlEn, 1/0:
  49. * power logic does/doesn't disable crystal when appropriate
  50. */
  51. #define SCC_XC 0x00002000
  52. /* XtalPU (RO), 1/0: crystal running/disabled */
  53. #define SCC_XP 0x00004000
  54. /* ClockDivider (SlowClk = 1/(4+divisor)) */
  55. #define SCC_CD_MASK 0xffff0000
  56. #define SCC_CD_SHIFT 16
  57. /* system_clk_ctl */
  58. /* ILPen: Enable Idle Low Power */
  59. #define SYCC_IE 0x00000001
  60. /* ALPen: Enable Active Low Power */
  61. #define SYCC_AE 0x00000002
  62. /* ForcePLLOn */
  63. #define SYCC_FP 0x00000004
  64. /* Force ALP (or HT if ALPen is not set */
  65. #define SYCC_AR 0x00000008
  66. /* Force HT */
  67. #define SYCC_HR 0x00000010
  68. /* ClkDiv (ILP = 1/(4 * (divisor + 1)) */
  69. #define SYCC_CD_MASK 0xffff0000
  70. #define SYCC_CD_SHIFT 16
  71. #define CST4329_SPROM_OTP_SEL_MASK 0x00000003
  72. /* OTP is powered up, use def. CIS, no SPROM */
  73. #define CST4329_DEFCIS_SEL 0
  74. /* OTP is powered up, SPROM is present */
  75. #define CST4329_SPROM_SEL 1
  76. /* OTP is powered up, no SPROM */
  77. #define CST4329_OTP_SEL 2
  78. /* OTP is powered down, SPROM is present */
  79. #define CST4329_OTP_PWRDN 3
  80. #define CST4329_SPI_SDIO_MODE_MASK 0x00000004
  81. #define CST4329_SPI_SDIO_MODE_SHIFT 2
  82. /* 43224 chip-specific ChipControl register bits */
  83. #define CCTRL43224_GPIO_TOGGLE 0x8000
  84. /* 12 mA drive strength */
  85. #define CCTRL_43224A0_12MA_LED_DRIVE 0x00F000F0
  86. /* 12 mA drive strength for later 43224s */
  87. #define CCTRL_43224B0_12MA_LED_DRIVE 0xF0
  88. /* 43236 Chip specific ChipStatus register bits */
  89. #define CST43236_SFLASH_MASK 0x00000040
  90. #define CST43236_OTP_MASK 0x00000080
  91. #define CST43236_HSIC_MASK 0x00000100 /* USB/HSIC */
  92. #define CST43236_BP_CLK 0x00000200 /* 120/96Mbps */
  93. #define CST43236_BOOT_MASK 0x00001800
  94. #define CST43236_BOOT_SHIFT 11
  95. #define CST43236_BOOT_FROM_SRAM 0 /* boot from SRAM, ARM in reset */
  96. #define CST43236_BOOT_FROM_ROM 1 /* boot from ROM */
  97. #define CST43236_BOOT_FROM_FLASH 2 /* boot from FLASH */
  98. #define CST43236_BOOT_FROM_INVALID 3
  99. /* 4331 chip-specific ChipControl register bits */
  100. /* 0 disable */
  101. #define CCTRL4331_BT_COEXIST (1<<0)
  102. /* 0 SECI is disabled (JTAG functional) */
  103. #define CCTRL4331_SECI (1<<1)
  104. /* 0 disable */
  105. #define CCTRL4331_EXT_LNA (1<<2)
  106. /* sprom/gpio13-15 mux */
  107. #define CCTRL4331_SPROM_GPIO13_15 (1<<3)
  108. /* 0 ext pa disable, 1 ext pa enabled */
  109. #define CCTRL4331_EXTPA_EN (1<<4)
  110. /* set drive out GPIO_CLK on sprom_cs pin */
  111. #define CCTRL4331_GPIOCLK_ON_SPROMCS (1<<5)
  112. /* use sprom_cs pin as PCIE mdio interface */
  113. #define CCTRL4331_PCIE_MDIO_ON_SPROMCS (1<<6)
  114. /* aband extpa will be at gpio2/5 and sprom_dout */
  115. #define CCTRL4331_EXTPA_ON_GPIO2_5 (1<<7)
  116. /* override core control on pipe_AuxClkEnable */
  117. #define CCTRL4331_OVR_PIPEAUXCLKEN (1<<8)
  118. /* override core control on pipe_AuxPowerDown */
  119. #define CCTRL4331_OVR_PIPEAUXPWRDOWN (1<<9)
  120. /* pcie_auxclkenable */
  121. #define CCTRL4331_PCIE_AUXCLKEN (1<<10)
  122. /* pcie_pipe_pllpowerdown */
  123. #define CCTRL4331_PCIE_PIPE_PLLDOWN (1<<11)
  124. /* enable bt_shd0 at gpio4 */
  125. #define CCTRL4331_BT_SHD0_ON_GPIO4 (1<<16)
  126. /* enable bt_shd1 at gpio5 */
  127. #define CCTRL4331_BT_SHD1_ON_GPIO5 (1<<17)
  128. /* 4331 Chip specific ChipStatus register bits */
  129. /* crystal frequency 20/40Mhz */
  130. #define CST4331_XTAL_FREQ 0x00000001
  131. #define CST4331_SPROM_PRESENT 0x00000002
  132. #define CST4331_OTP_PRESENT 0x00000004
  133. #define CST4331_LDO_RF 0x00000008
  134. #define CST4331_LDO_PAR 0x00000010
  135. /* 4319 chip-specific ChipStatus register bits */
  136. #define CST4319_SPI_CPULESSUSB 0x00000001
  137. #define CST4319_SPI_CLK_POL 0x00000002
  138. #define CST4319_SPI_CLK_PH 0x00000008
  139. /* gpio [7:6], SDIO CIS selection */
  140. #define CST4319_SPROM_OTP_SEL_MASK 0x000000c0
  141. #define CST4319_SPROM_OTP_SEL_SHIFT 6
  142. /* use default CIS, OTP is powered up */
  143. #define CST4319_DEFCIS_SEL 0x00000000
  144. /* use SPROM, OTP is powered up */
  145. #define CST4319_SPROM_SEL 0x00000040
  146. /* use OTP, OTP is powered up */
  147. #define CST4319_OTP_SEL 0x00000080
  148. /* use SPROM, OTP is powered down */
  149. #define CST4319_OTP_PWRDN 0x000000c0
  150. /* gpio [8], sdio/usb mode */
  151. #define CST4319_SDIO_USB_MODE 0x00000100
  152. #define CST4319_REMAP_SEL_MASK 0x00000600
  153. #define CST4319_ILPDIV_EN 0x00000800
  154. #define CST4319_XTAL_PD_POL 0x00001000
  155. #define CST4319_LPO_SEL 0x00002000
  156. #define CST4319_RES_INIT_MODE 0x0000c000
  157. /* PALDO is configured with external PNP */
  158. #define CST4319_PALDO_EXTPNP 0x00010000
  159. #define CST4319_CBUCK_MODE_MASK 0x00060000
  160. #define CST4319_CBUCK_MODE_BURST 0x00020000
  161. #define CST4319_CBUCK_MODE_LPBURST 0x00060000
  162. #define CST4319_RCAL_VALID 0x01000000
  163. #define CST4319_RCAL_VALUE_MASK 0x3e000000
  164. #define CST4319_RCAL_VALUE_SHIFT 25
  165. /* 4336 chip-specific ChipStatus register bits */
  166. #define CST4336_SPI_MODE_MASK 0x00000001
  167. #define CST4336_SPROM_PRESENT 0x00000002
  168. #define CST4336_OTP_PRESENT 0x00000004
  169. #define CST4336_ARMREMAP_0 0x00000008
  170. #define CST4336_ILPDIV_EN_MASK 0x00000010
  171. #define CST4336_ILPDIV_EN_SHIFT 4
  172. #define CST4336_XTAL_PD_POL_MASK 0x00000020
  173. #define CST4336_XTAL_PD_POL_SHIFT 5
  174. #define CST4336_LPO_SEL_MASK 0x00000040
  175. #define CST4336_LPO_SEL_SHIFT 6
  176. #define CST4336_RES_INIT_MODE_MASK 0x00000180
  177. #define CST4336_RES_INIT_MODE_SHIFT 7
  178. #define CST4336_CBUCK_MODE_MASK 0x00000600
  179. #define CST4336_CBUCK_MODE_SHIFT 9
  180. /* 4313 chip-specific ChipStatus register bits */
  181. #define CST4313_SPROM_PRESENT 1
  182. #define CST4313_OTP_PRESENT 2
  183. #define CST4313_SPROM_OTP_SEL_MASK 0x00000002
  184. #define CST4313_SPROM_OTP_SEL_SHIFT 0
  185. /* 4313 Chip specific ChipControl register bits */
  186. /* 12 mA drive strengh for later 4313 */
  187. #define CCTRL_4313_12MA_LED_DRIVE 0x00000007
  188. /* Manufacturer Ids */
  189. #define MFGID_ARM 0x43b
  190. #define MFGID_BRCM 0x4bf
  191. #define MFGID_MIPS 0x4a7
  192. /* Enumeration ROM registers */
  193. #define ER_EROMENTRY 0x000
  194. #define ER_REMAPCONTROL 0xe00
  195. #define ER_REMAPSELECT 0xe04
  196. #define ER_MASTERSELECT 0xe10
  197. #define ER_ITCR 0xf00
  198. #define ER_ITIP 0xf04
  199. /* Erom entries */
  200. #define ER_TAG 0xe
  201. #define ER_TAG1 0x6
  202. #define ER_VALID 1
  203. #define ER_CI 0
  204. #define ER_MP 2
  205. #define ER_ADD 4
  206. #define ER_END 0xe
  207. #define ER_BAD 0xffffffff
  208. /* EROM CompIdentA */
  209. #define CIA_MFG_MASK 0xfff00000
  210. #define CIA_MFG_SHIFT 20
  211. #define CIA_CID_MASK 0x000fff00
  212. #define CIA_CID_SHIFT 8
  213. #define CIA_CCL_MASK 0x000000f0
  214. #define CIA_CCL_SHIFT 4
  215. /* EROM CompIdentB */
  216. #define CIB_REV_MASK 0xff000000
  217. #define CIB_REV_SHIFT 24
  218. #define CIB_NSW_MASK 0x00f80000
  219. #define CIB_NSW_SHIFT 19
  220. #define CIB_NMW_MASK 0x0007c000
  221. #define CIB_NMW_SHIFT 14
  222. #define CIB_NSP_MASK 0x00003e00
  223. #define CIB_NSP_SHIFT 9
  224. #define CIB_NMP_MASK 0x000001f0
  225. #define CIB_NMP_SHIFT 4
  226. /* EROM AddrDesc */
  227. #define AD_ADDR_MASK 0xfffff000
  228. #define AD_SP_MASK 0x00000f00
  229. #define AD_SP_SHIFT 8
  230. #define AD_ST_MASK 0x000000c0
  231. #define AD_ST_SHIFT 6
  232. #define AD_ST_SLAVE 0x00000000
  233. #define AD_ST_BRIDGE 0x00000040
  234. #define AD_ST_SWRAP 0x00000080
  235. #define AD_ST_MWRAP 0x000000c0
  236. #define AD_SZ_MASK 0x00000030
  237. #define AD_SZ_SHIFT 4
  238. #define AD_SZ_4K 0x00000000
  239. #define AD_SZ_8K 0x00000010
  240. #define AD_SZ_16K 0x00000020
  241. #define AD_SZ_SZD 0x00000030
  242. #define AD_AG32 0x00000008
  243. #define AD_ADDR_ALIGN 0x00000fff
  244. #define AD_SZ_BASE 0x00001000 /* 4KB */
  245. /* EROM SizeDesc */
  246. #define SD_SZ_MASK 0xfffff000
  247. #define SD_SG32 0x00000008
  248. #define SD_SZ_ALIGN 0x00000fff
  249. /* PCI config space bit 4 for 4306c0 slow clock source */
  250. #define PCI_CFG_GPIO_SCS 0x10
  251. /* PCI config space GPIO 14 for Xtal power-up */
  252. #define PCI_CFG_GPIO_XTAL 0x40
  253. /* PCI config space GPIO 15 for PLL power-down */
  254. #define PCI_CFG_GPIO_PLL 0x80
  255. /* power control defines */
  256. #define PLL_DELAY 150 /* us pll on delay */
  257. #define FREF_DELAY 200 /* us fref change delay */
  258. #define XTAL_ON_DELAY 1000 /* us crystal power-on delay */
  259. /* resetctrl */
  260. #define AIRC_RESET 1
  261. #define NOREV -1 /* Invalid rev */
  262. /* GPIO Based LED powersave defines */
  263. #define DEFAULT_GPIO_ONTIME 10 /* Default: 10% on */
  264. #define DEFAULT_GPIO_OFFTIME 90 /* Default: 10% on */
  265. /* When Srom support present, fields in sromcontrol */
  266. #define SRC_START 0x80000000
  267. #define SRC_BUSY 0x80000000
  268. #define SRC_OPCODE 0x60000000
  269. #define SRC_OP_READ 0x00000000
  270. #define SRC_OP_WRITE 0x20000000
  271. #define SRC_OP_WRDIS 0x40000000
  272. #define SRC_OP_WREN 0x60000000
  273. #define SRC_OTPSEL 0x00000010
  274. #define SRC_LOCK 0x00000008
  275. #define SRC_SIZE_MASK 0x00000006
  276. #define SRC_SIZE_1K 0x00000000
  277. #define SRC_SIZE_4K 0x00000002
  278. #define SRC_SIZE_16K 0x00000004
  279. #define SRC_SIZE_SHIFT 1
  280. #define SRC_PRESENT 0x00000001
  281. /* External PA enable mask */
  282. #define GPIO_CTRL_EPA_EN_MASK 0x40
  283. #define DEFAULT_GPIOTIMERVAL \
  284. ((DEFAULT_GPIO_ONTIME << GPIO_ONTIME_SHIFT) | DEFAULT_GPIO_OFFTIME)
  285. #define BADIDX (SI_MAXCORES + 1)
  286. #define IS_SIM(chippkg) \
  287. ((chippkg == HDLSIM_PKG_ID) || (chippkg == HWSIM_PKG_ID))
  288. #ifdef DEBUG
  289. #define SI_MSG(fmt, ...) pr_debug(fmt, ##__VA_ARGS__)
  290. #else
  291. #define SI_MSG(fmt, ...) no_printk(fmt, ##__VA_ARGS__)
  292. #endif /* DEBUG */
  293. #define GOODCOREADDR(x, b) \
  294. (((x) >= (b)) && ((x) < ((b) + SI_MAXCORES * SI_CORE_SIZE)) && \
  295. IS_ALIGNED((x), SI_CORE_SIZE))
  296. struct aidmp {
  297. u32 oobselina30; /* 0x000 */
  298. u32 oobselina74; /* 0x004 */
  299. u32 PAD[6];
  300. u32 oobselinb30; /* 0x020 */
  301. u32 oobselinb74; /* 0x024 */
  302. u32 PAD[6];
  303. u32 oobselinc30; /* 0x040 */
  304. u32 oobselinc74; /* 0x044 */
  305. u32 PAD[6];
  306. u32 oobselind30; /* 0x060 */
  307. u32 oobselind74; /* 0x064 */
  308. u32 PAD[38];
  309. u32 oobselouta30; /* 0x100 */
  310. u32 oobselouta74; /* 0x104 */
  311. u32 PAD[6];
  312. u32 oobseloutb30; /* 0x120 */
  313. u32 oobseloutb74; /* 0x124 */
  314. u32 PAD[6];
  315. u32 oobseloutc30; /* 0x140 */
  316. u32 oobseloutc74; /* 0x144 */
  317. u32 PAD[6];
  318. u32 oobseloutd30; /* 0x160 */
  319. u32 oobseloutd74; /* 0x164 */
  320. u32 PAD[38];
  321. u32 oobsynca; /* 0x200 */
  322. u32 oobseloutaen; /* 0x204 */
  323. u32 PAD[6];
  324. u32 oobsyncb; /* 0x220 */
  325. u32 oobseloutben; /* 0x224 */
  326. u32 PAD[6];
  327. u32 oobsyncc; /* 0x240 */
  328. u32 oobseloutcen; /* 0x244 */
  329. u32 PAD[6];
  330. u32 oobsyncd; /* 0x260 */
  331. u32 oobseloutden; /* 0x264 */
  332. u32 PAD[38];
  333. u32 oobaextwidth; /* 0x300 */
  334. u32 oobainwidth; /* 0x304 */
  335. u32 oobaoutwidth; /* 0x308 */
  336. u32 PAD[5];
  337. u32 oobbextwidth; /* 0x320 */
  338. u32 oobbinwidth; /* 0x324 */
  339. u32 oobboutwidth; /* 0x328 */
  340. u32 PAD[5];
  341. u32 oobcextwidth; /* 0x340 */
  342. u32 oobcinwidth; /* 0x344 */
  343. u32 oobcoutwidth; /* 0x348 */
  344. u32 PAD[5];
  345. u32 oobdextwidth; /* 0x360 */
  346. u32 oobdinwidth; /* 0x364 */
  347. u32 oobdoutwidth; /* 0x368 */
  348. u32 PAD[37];
  349. u32 ioctrlset; /* 0x400 */
  350. u32 ioctrlclear; /* 0x404 */
  351. u32 ioctrl; /* 0x408 */
  352. u32 PAD[61];
  353. u32 iostatus; /* 0x500 */
  354. u32 PAD[127];
  355. u32 ioctrlwidth; /* 0x700 */
  356. u32 iostatuswidth; /* 0x704 */
  357. u32 PAD[62];
  358. u32 resetctrl; /* 0x800 */
  359. u32 resetstatus; /* 0x804 */
  360. u32 resetreadid; /* 0x808 */
  361. u32 resetwriteid; /* 0x80c */
  362. u32 PAD[60];
  363. u32 errlogctrl; /* 0x900 */
  364. u32 errlogdone; /* 0x904 */
  365. u32 errlogstatus; /* 0x908 */
  366. u32 errlogaddrlo; /* 0x90c */
  367. u32 errlogaddrhi; /* 0x910 */
  368. u32 errlogid; /* 0x914 */
  369. u32 errloguser; /* 0x918 */
  370. u32 errlogflags; /* 0x91c */
  371. u32 PAD[56];
  372. u32 intstatus; /* 0xa00 */
  373. u32 PAD[127];
  374. u32 config; /* 0xe00 */
  375. u32 PAD[63];
  376. u32 itcr; /* 0xf00 */
  377. u32 PAD[3];
  378. u32 itipooba; /* 0xf10 */
  379. u32 itipoobb; /* 0xf14 */
  380. u32 itipoobc; /* 0xf18 */
  381. u32 itipoobd; /* 0xf1c */
  382. u32 PAD[4];
  383. u32 itipoobaout; /* 0xf30 */
  384. u32 itipoobbout; /* 0xf34 */
  385. u32 itipoobcout; /* 0xf38 */
  386. u32 itipoobdout; /* 0xf3c */
  387. u32 PAD[4];
  388. u32 itopooba; /* 0xf50 */
  389. u32 itopoobb; /* 0xf54 */
  390. u32 itopoobc; /* 0xf58 */
  391. u32 itopoobd; /* 0xf5c */
  392. u32 PAD[4];
  393. u32 itopoobain; /* 0xf70 */
  394. u32 itopoobbin; /* 0xf74 */
  395. u32 itopoobcin; /* 0xf78 */
  396. u32 itopoobdin; /* 0xf7c */
  397. u32 PAD[4];
  398. u32 itopreset; /* 0xf90 */
  399. u32 PAD[15];
  400. u32 peripherialid4; /* 0xfd0 */
  401. u32 peripherialid5; /* 0xfd4 */
  402. u32 peripherialid6; /* 0xfd8 */
  403. u32 peripherialid7; /* 0xfdc */
  404. u32 peripherialid0; /* 0xfe0 */
  405. u32 peripherialid1; /* 0xfe4 */
  406. u32 peripherialid2; /* 0xfe8 */
  407. u32 peripherialid3; /* 0xfec */
  408. u32 componentid0; /* 0xff0 */
  409. u32 componentid1; /* 0xff4 */
  410. u32 componentid2; /* 0xff8 */
  411. u32 componentid3; /* 0xffc */
  412. };
  413. static bool
  414. ai_buscore_setup(struct si_info *sii, struct bcma_device *cc)
  415. {
  416. /* no cores found, bail out */
  417. if (cc->bus->nr_cores == 0)
  418. return false;
  419. /* get chipcommon rev */
  420. sii->pub.ccrev = cc->id.rev;
  421. /* get chipcommon chipstatus */
  422. sii->chipst = bcma_read32(cc, CHIPCREGOFFS(chipstatus));
  423. /* get chipcommon capabilites */
  424. sii->pub.cccaps = bcma_read32(cc, CHIPCREGOFFS(capabilities));
  425. /* get pmu rev and caps */
  426. if (ai_get_cccaps(&sii->pub) & CC_CAP_PMU) {
  427. sii->pub.pmucaps = bcma_read32(cc,
  428. CHIPCREGOFFS(pmucapabilities));
  429. sii->pub.pmurev = sii->pub.pmucaps & PCAP_REV_MASK;
  430. }
  431. return true;
  432. }
  433. static struct si_info *ai_doattach(struct si_info *sii,
  434. struct bcma_bus *pbus)
  435. {
  436. struct si_pub *sih = &sii->pub;
  437. struct bcma_device *cc;
  438. sii->icbus = pbus;
  439. sii->pcibus = pbus->host_pci;
  440. /* switch to Chipcommon core */
  441. cc = pbus->drv_cc.core;
  442. sih->chip = pbus->chipinfo.id;
  443. sih->chiprev = pbus->chipinfo.rev;
  444. sih->chippkg = pbus->chipinfo.pkg;
  445. sih->boardvendor = pbus->boardinfo.vendor;
  446. sih->boardtype = pbus->boardinfo.type;
  447. if (!ai_buscore_setup(sii, cc))
  448. goto exit;
  449. /* === NVRAM, clock is ready === */
  450. bcma_write32(cc, CHIPCREGOFFS(gpiopullup), 0);
  451. bcma_write32(cc, CHIPCREGOFFS(gpiopulldown), 0);
  452. /* PMU specific initializations */
  453. if (ai_get_cccaps(sih) & CC_CAP_PMU) {
  454. (void)si_pmu_measure_alpclk(sih);
  455. }
  456. return sii;
  457. exit:
  458. return NULL;
  459. }
  460. /*
  461. * Allocate a si handle and do the attach.
  462. */
  463. struct si_pub *
  464. ai_attach(struct bcma_bus *pbus)
  465. {
  466. struct si_info *sii;
  467. /* alloc struct si_info */
  468. sii = kzalloc(sizeof(struct si_info), GFP_ATOMIC);
  469. if (sii == NULL)
  470. return NULL;
  471. if (ai_doattach(sii, pbus) == NULL) {
  472. kfree(sii);
  473. return NULL;
  474. }
  475. return (struct si_pub *) sii;
  476. }
  477. /* may be called with core in reset */
  478. void ai_detach(struct si_pub *sih)
  479. {
  480. struct si_info *sii;
  481. struct si_pub *si_local = NULL;
  482. memcpy(&si_local, &sih, sizeof(struct si_pub **));
  483. sii = container_of(sih, struct si_info, pub);
  484. if (sii == NULL)
  485. return;
  486. kfree(sii);
  487. }
  488. /*
  489. * read/modify chipcommon core register.
  490. */
  491. uint ai_cc_reg(struct si_pub *sih, uint regoff, u32 mask, u32 val)
  492. {
  493. struct bcma_device *cc;
  494. u32 w;
  495. struct si_info *sii;
  496. sii = container_of(sih, struct si_info, pub);
  497. cc = sii->icbus->drv_cc.core;
  498. /* mask and set */
  499. if (mask || val)
  500. bcma_maskset32(cc, regoff, ~mask, val);
  501. /* readback */
  502. w = bcma_read32(cc, regoff);
  503. return w;
  504. }
  505. /* return the slow clock source - LPO, XTAL, or PCI */
  506. static uint ai_slowclk_src(struct si_pub *sih, struct bcma_device *cc)
  507. {
  508. return SCC_SS_XTAL;
  509. }
  510. /*
  511. * return the ILP (slowclock) min or max frequency
  512. * precondition: we've established the chip has dynamic clk control
  513. */
  514. static uint ai_slowclk_freq(struct si_pub *sih, bool max_freq,
  515. struct bcma_device *cc)
  516. {
  517. uint div;
  518. /* Chipc rev 10 is InstaClock */
  519. div = bcma_read32(cc, CHIPCREGOFFS(system_clk_ctl));
  520. div = 4 * ((div >> SYCC_CD_SHIFT) + 1);
  521. return max_freq ? XTALMAXFREQ : (XTALMINFREQ / div);
  522. }
  523. static void
  524. ai_clkctl_setdelay(struct si_pub *sih, struct bcma_device *cc)
  525. {
  526. uint slowmaxfreq, pll_delay, slowclk;
  527. uint pll_on_delay, fref_sel_delay;
  528. pll_delay = PLL_DELAY;
  529. /*
  530. * If the slow clock is not sourced by the xtal then
  531. * add the xtal_on_delay since the xtal will also be
  532. * powered down by dynamic clk control logic.
  533. */
  534. slowclk = ai_slowclk_src(sih, cc);
  535. if (slowclk != SCC_SS_XTAL)
  536. pll_delay += XTAL_ON_DELAY;
  537. /* Starting with 4318 it is ILP that is used for the delays */
  538. slowmaxfreq =
  539. ai_slowclk_freq(sih, false, cc);
  540. pll_on_delay = ((slowmaxfreq * pll_delay) + 999999) / 1000000;
  541. fref_sel_delay = ((slowmaxfreq * FREF_DELAY) + 999999) / 1000000;
  542. bcma_write32(cc, CHIPCREGOFFS(pll_on_delay), pll_on_delay);
  543. bcma_write32(cc, CHIPCREGOFFS(fref_sel_delay), fref_sel_delay);
  544. }
  545. /* initialize power control delay registers */
  546. void ai_clkctl_init(struct si_pub *sih)
  547. {
  548. struct si_info *sii = container_of(sih, struct si_info, pub);
  549. struct bcma_device *cc;
  550. if (!(ai_get_cccaps(sih) & CC_CAP_PWR_CTL))
  551. return;
  552. cc = sii->icbus->drv_cc.core;
  553. if (cc == NULL)
  554. return;
  555. /* set all Instaclk chip ILP to 1 MHz */
  556. bcma_maskset32(cc, CHIPCREGOFFS(system_clk_ctl), SYCC_CD_MASK,
  557. (ILP_DIV_1MHZ << SYCC_CD_SHIFT));
  558. ai_clkctl_setdelay(sih, cc);
  559. }
  560. /*
  561. * return the value suitable for writing to the
  562. * dot11 core FAST_PWRUP_DELAY register
  563. */
  564. u16 ai_clkctl_fast_pwrup_delay(struct si_pub *sih)
  565. {
  566. struct si_info *sii;
  567. struct bcma_device *cc;
  568. uint slowminfreq;
  569. u16 fpdelay;
  570. sii = container_of(sih, struct si_info, pub);
  571. if (ai_get_cccaps(sih) & CC_CAP_PMU) {
  572. fpdelay = si_pmu_fast_pwrup_delay(sih);
  573. return fpdelay;
  574. }
  575. if (!(ai_get_cccaps(sih) & CC_CAP_PWR_CTL))
  576. return 0;
  577. fpdelay = 0;
  578. cc = sii->icbus->drv_cc.core;
  579. if (cc) {
  580. slowminfreq = ai_slowclk_freq(sih, false, cc);
  581. fpdelay = (((bcma_read32(cc, CHIPCREGOFFS(pll_on_delay)) + 2)
  582. * 1000000) + (slowminfreq - 1)) / slowminfreq;
  583. }
  584. return fpdelay;
  585. }
  586. /*
  587. * clock control policy function throught chipcommon
  588. *
  589. * set dynamic clk control mode (forceslow, forcefast, dynamic)
  590. * returns true if we are forcing fast clock
  591. * this is a wrapper over the next internal function
  592. * to allow flexible policy settings for outside caller
  593. */
  594. bool ai_clkctl_cc(struct si_pub *sih, enum bcma_clkmode mode)
  595. {
  596. struct si_info *sii;
  597. struct bcma_device *cc;
  598. sii = container_of(sih, struct si_info, pub);
  599. cc = sii->icbus->drv_cc.core;
  600. bcma_core_set_clockmode(cc, mode);
  601. return mode == BCMA_CLKMODE_FAST;
  602. }
  603. void ai_pci_up(struct si_pub *sih)
  604. {
  605. struct si_info *sii;
  606. sii = container_of(sih, struct si_info, pub);
  607. if (sii->icbus->hosttype == BCMA_HOSTTYPE_PCI)
  608. bcma_core_pci_extend_L1timer(&sii->icbus->drv_pci, true);
  609. }
  610. /* Unconfigure and/or apply various WARs when going down */
  611. void ai_pci_down(struct si_pub *sih)
  612. {
  613. struct si_info *sii;
  614. sii = container_of(sih, struct si_info, pub);
  615. if (sii->icbus->hosttype == BCMA_HOSTTYPE_PCI)
  616. bcma_core_pci_extend_L1timer(&sii->icbus->drv_pci, false);
  617. }
  618. /* Enable BT-COEX & Ex-PA for 4313 */
  619. void ai_epa_4313war(struct si_pub *sih)
  620. {
  621. struct si_info *sii = container_of(sih, struct si_info, pub);
  622. struct bcma_device *cc;
  623. cc = sii->icbus->drv_cc.core;
  624. /* EPA Fix */
  625. bcma_set32(cc, CHIPCREGOFFS(gpiocontrol), GPIO_CTRL_EPA_EN_MASK);
  626. }
  627. /* check if the device is removed */
  628. bool ai_deviceremoved(struct si_pub *sih)
  629. {
  630. u32 w;
  631. struct si_info *sii;
  632. sii = container_of(sih, struct si_info, pub);
  633. if (sii->icbus->hosttype != BCMA_HOSTTYPE_PCI)
  634. return false;
  635. pci_read_config_dword(sii->pcibus, PCI_VENDOR_ID, &w);
  636. if ((w & 0xFFFF) != PCI_VENDOR_ID_BROADCOM)
  637. return true;
  638. return false;
  639. }