aiutils.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197
  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 <linux/pci.h>
  21. #include <defs.h>
  22. #include <chipcommon.h>
  23. #include <brcmu_utils.h>
  24. #include <brcm_hw_ids.h>
  25. #include <soc.h>
  26. #include "types.h"
  27. #include "pub.h"
  28. #include "pmu.h"
  29. #include "nicpci.h"
  30. #include "aiutils.h"
  31. /* slow_clk_ctl */
  32. /* slow clock source mask */
  33. #define SCC_SS_MASK 0x00000007
  34. /* source of slow clock is LPO */
  35. #define SCC_SS_LPO 0x00000000
  36. /* source of slow clock is crystal */
  37. #define SCC_SS_XTAL 0x00000001
  38. /* source of slow clock is PCI */
  39. #define SCC_SS_PCI 0x00000002
  40. /* LPOFreqSel, 1: 160Khz, 0: 32KHz */
  41. #define SCC_LF 0x00000200
  42. /* LPOPowerDown, 1: LPO is disabled, 0: LPO is enabled */
  43. #define SCC_LP 0x00000400
  44. /* ForceSlowClk, 1: sb/cores running on slow clock, 0: power logic control */
  45. #define SCC_FS 0x00000800
  46. /* IgnorePllOffReq, 1/0:
  47. * power logic ignores/honors PLL clock disable requests from core
  48. */
  49. #define SCC_IP 0x00001000
  50. /* XtalControlEn, 1/0:
  51. * power logic does/doesn't disable crystal when appropriate
  52. */
  53. #define SCC_XC 0x00002000
  54. /* XtalPU (RO), 1/0: crystal running/disabled */
  55. #define SCC_XP 0x00004000
  56. /* ClockDivider (SlowClk = 1/(4+divisor)) */
  57. #define SCC_CD_MASK 0xffff0000
  58. #define SCC_CD_SHIFT 16
  59. /* system_clk_ctl */
  60. /* ILPen: Enable Idle Low Power */
  61. #define SYCC_IE 0x00000001
  62. /* ALPen: Enable Active Low Power */
  63. #define SYCC_AE 0x00000002
  64. /* ForcePLLOn */
  65. #define SYCC_FP 0x00000004
  66. /* Force ALP (or HT if ALPen is not set */
  67. #define SYCC_AR 0x00000008
  68. /* Force HT */
  69. #define SYCC_HR 0x00000010
  70. /* ClkDiv (ILP = 1/(4 * (divisor + 1)) */
  71. #define SYCC_CD_MASK 0xffff0000
  72. #define SYCC_CD_SHIFT 16
  73. #define CST4329_SPROM_OTP_SEL_MASK 0x00000003
  74. /* OTP is powered up, use def. CIS, no SPROM */
  75. #define CST4329_DEFCIS_SEL 0
  76. /* OTP is powered up, SPROM is present */
  77. #define CST4329_SPROM_SEL 1
  78. /* OTP is powered up, no SPROM */
  79. #define CST4329_OTP_SEL 2
  80. /* OTP is powered down, SPROM is present */
  81. #define CST4329_OTP_PWRDN 3
  82. #define CST4329_SPI_SDIO_MODE_MASK 0x00000004
  83. #define CST4329_SPI_SDIO_MODE_SHIFT 2
  84. /* 43224 chip-specific ChipControl register bits */
  85. #define CCTRL43224_GPIO_TOGGLE 0x8000
  86. /* 12 mA drive strength */
  87. #define CCTRL_43224A0_12MA_LED_DRIVE 0x00F000F0
  88. /* 12 mA drive strength for later 43224s */
  89. #define CCTRL_43224B0_12MA_LED_DRIVE 0xF0
  90. /* 43236 Chip specific ChipStatus register bits */
  91. #define CST43236_SFLASH_MASK 0x00000040
  92. #define CST43236_OTP_MASK 0x00000080
  93. #define CST43236_HSIC_MASK 0x00000100 /* USB/HSIC */
  94. #define CST43236_BP_CLK 0x00000200 /* 120/96Mbps */
  95. #define CST43236_BOOT_MASK 0x00001800
  96. #define CST43236_BOOT_SHIFT 11
  97. #define CST43236_BOOT_FROM_SRAM 0 /* boot from SRAM, ARM in reset */
  98. #define CST43236_BOOT_FROM_ROM 1 /* boot from ROM */
  99. #define CST43236_BOOT_FROM_FLASH 2 /* boot from FLASH */
  100. #define CST43236_BOOT_FROM_INVALID 3
  101. /* 4331 chip-specific ChipControl register bits */
  102. /* 0 disable */
  103. #define CCTRL4331_BT_COEXIST (1<<0)
  104. /* 0 SECI is disabled (JTAG functional) */
  105. #define CCTRL4331_SECI (1<<1)
  106. /* 0 disable */
  107. #define CCTRL4331_EXT_LNA (1<<2)
  108. /* sprom/gpio13-15 mux */
  109. #define CCTRL4331_SPROM_GPIO13_15 (1<<3)
  110. /* 0 ext pa disable, 1 ext pa enabled */
  111. #define CCTRL4331_EXTPA_EN (1<<4)
  112. /* set drive out GPIO_CLK on sprom_cs pin */
  113. #define CCTRL4331_GPIOCLK_ON_SPROMCS (1<<5)
  114. /* use sprom_cs pin as PCIE mdio interface */
  115. #define CCTRL4331_PCIE_MDIO_ON_SPROMCS (1<<6)
  116. /* aband extpa will be at gpio2/5 and sprom_dout */
  117. #define CCTRL4331_EXTPA_ON_GPIO2_5 (1<<7)
  118. /* override core control on pipe_AuxClkEnable */
  119. #define CCTRL4331_OVR_PIPEAUXCLKEN (1<<8)
  120. /* override core control on pipe_AuxPowerDown */
  121. #define CCTRL4331_OVR_PIPEAUXPWRDOWN (1<<9)
  122. /* pcie_auxclkenable */
  123. #define CCTRL4331_PCIE_AUXCLKEN (1<<10)
  124. /* pcie_pipe_pllpowerdown */
  125. #define CCTRL4331_PCIE_PIPE_PLLDOWN (1<<11)
  126. /* enable bt_shd0 at gpio4 */
  127. #define CCTRL4331_BT_SHD0_ON_GPIO4 (1<<16)
  128. /* enable bt_shd1 at gpio5 */
  129. #define CCTRL4331_BT_SHD1_ON_GPIO5 (1<<17)
  130. /* 4331 Chip specific ChipStatus register bits */
  131. /* crystal frequency 20/40Mhz */
  132. #define CST4331_XTAL_FREQ 0x00000001
  133. #define CST4331_SPROM_PRESENT 0x00000002
  134. #define CST4331_OTP_PRESENT 0x00000004
  135. #define CST4331_LDO_RF 0x00000008
  136. #define CST4331_LDO_PAR 0x00000010
  137. /* 4319 chip-specific ChipStatus register bits */
  138. #define CST4319_SPI_CPULESSUSB 0x00000001
  139. #define CST4319_SPI_CLK_POL 0x00000002
  140. #define CST4319_SPI_CLK_PH 0x00000008
  141. /* gpio [7:6], SDIO CIS selection */
  142. #define CST4319_SPROM_OTP_SEL_MASK 0x000000c0
  143. #define CST4319_SPROM_OTP_SEL_SHIFT 6
  144. /* use default CIS, OTP is powered up */
  145. #define CST4319_DEFCIS_SEL 0x00000000
  146. /* use SPROM, OTP is powered up */
  147. #define CST4319_SPROM_SEL 0x00000040
  148. /* use OTP, OTP is powered up */
  149. #define CST4319_OTP_SEL 0x00000080
  150. /* use SPROM, OTP is powered down */
  151. #define CST4319_OTP_PWRDN 0x000000c0
  152. /* gpio [8], sdio/usb mode */
  153. #define CST4319_SDIO_USB_MODE 0x00000100
  154. #define CST4319_REMAP_SEL_MASK 0x00000600
  155. #define CST4319_ILPDIV_EN 0x00000800
  156. #define CST4319_XTAL_PD_POL 0x00001000
  157. #define CST4319_LPO_SEL 0x00002000
  158. #define CST4319_RES_INIT_MODE 0x0000c000
  159. /* PALDO is configured with external PNP */
  160. #define CST4319_PALDO_EXTPNP 0x00010000
  161. #define CST4319_CBUCK_MODE_MASK 0x00060000
  162. #define CST4319_CBUCK_MODE_BURST 0x00020000
  163. #define CST4319_CBUCK_MODE_LPBURST 0x00060000
  164. #define CST4319_RCAL_VALID 0x01000000
  165. #define CST4319_RCAL_VALUE_MASK 0x3e000000
  166. #define CST4319_RCAL_VALUE_SHIFT 25
  167. /* 4336 chip-specific ChipStatus register bits */
  168. #define CST4336_SPI_MODE_MASK 0x00000001
  169. #define CST4336_SPROM_PRESENT 0x00000002
  170. #define CST4336_OTP_PRESENT 0x00000004
  171. #define CST4336_ARMREMAP_0 0x00000008
  172. #define CST4336_ILPDIV_EN_MASK 0x00000010
  173. #define CST4336_ILPDIV_EN_SHIFT 4
  174. #define CST4336_XTAL_PD_POL_MASK 0x00000020
  175. #define CST4336_XTAL_PD_POL_SHIFT 5
  176. #define CST4336_LPO_SEL_MASK 0x00000040
  177. #define CST4336_LPO_SEL_SHIFT 6
  178. #define CST4336_RES_INIT_MODE_MASK 0x00000180
  179. #define CST4336_RES_INIT_MODE_SHIFT 7
  180. #define CST4336_CBUCK_MODE_MASK 0x00000600
  181. #define CST4336_CBUCK_MODE_SHIFT 9
  182. /* 4313 chip-specific ChipStatus register bits */
  183. #define CST4313_SPROM_PRESENT 1
  184. #define CST4313_OTP_PRESENT 2
  185. #define CST4313_SPROM_OTP_SEL_MASK 0x00000002
  186. #define CST4313_SPROM_OTP_SEL_SHIFT 0
  187. /* 4313 Chip specific ChipControl register bits */
  188. /* 12 mA drive strengh for later 4313 */
  189. #define CCTRL_4313_12MA_LED_DRIVE 0x00000007
  190. /* Manufacturer Ids */
  191. #define MFGID_ARM 0x43b
  192. #define MFGID_BRCM 0x4bf
  193. #define MFGID_MIPS 0x4a7
  194. /* Enumeration ROM registers */
  195. #define ER_EROMENTRY 0x000
  196. #define ER_REMAPCONTROL 0xe00
  197. #define ER_REMAPSELECT 0xe04
  198. #define ER_MASTERSELECT 0xe10
  199. #define ER_ITCR 0xf00
  200. #define ER_ITIP 0xf04
  201. /* Erom entries */
  202. #define ER_TAG 0xe
  203. #define ER_TAG1 0x6
  204. #define ER_VALID 1
  205. #define ER_CI 0
  206. #define ER_MP 2
  207. #define ER_ADD 4
  208. #define ER_END 0xe
  209. #define ER_BAD 0xffffffff
  210. /* EROM CompIdentA */
  211. #define CIA_MFG_MASK 0xfff00000
  212. #define CIA_MFG_SHIFT 20
  213. #define CIA_CID_MASK 0x000fff00
  214. #define CIA_CID_SHIFT 8
  215. #define CIA_CCL_MASK 0x000000f0
  216. #define CIA_CCL_SHIFT 4
  217. /* EROM CompIdentB */
  218. #define CIB_REV_MASK 0xff000000
  219. #define CIB_REV_SHIFT 24
  220. #define CIB_NSW_MASK 0x00f80000
  221. #define CIB_NSW_SHIFT 19
  222. #define CIB_NMW_MASK 0x0007c000
  223. #define CIB_NMW_SHIFT 14
  224. #define CIB_NSP_MASK 0x00003e00
  225. #define CIB_NSP_SHIFT 9
  226. #define CIB_NMP_MASK 0x000001f0
  227. #define CIB_NMP_SHIFT 4
  228. /* EROM AddrDesc */
  229. #define AD_ADDR_MASK 0xfffff000
  230. #define AD_SP_MASK 0x00000f00
  231. #define AD_SP_SHIFT 8
  232. #define AD_ST_MASK 0x000000c0
  233. #define AD_ST_SHIFT 6
  234. #define AD_ST_SLAVE 0x00000000
  235. #define AD_ST_BRIDGE 0x00000040
  236. #define AD_ST_SWRAP 0x00000080
  237. #define AD_ST_MWRAP 0x000000c0
  238. #define AD_SZ_MASK 0x00000030
  239. #define AD_SZ_SHIFT 4
  240. #define AD_SZ_4K 0x00000000
  241. #define AD_SZ_8K 0x00000010
  242. #define AD_SZ_16K 0x00000020
  243. #define AD_SZ_SZD 0x00000030
  244. #define AD_AG32 0x00000008
  245. #define AD_ADDR_ALIGN 0x00000fff
  246. #define AD_SZ_BASE 0x00001000 /* 4KB */
  247. /* EROM SizeDesc */
  248. #define SD_SZ_MASK 0xfffff000
  249. #define SD_SG32 0x00000008
  250. #define SD_SZ_ALIGN 0x00000fff
  251. /* PCI config space bit 4 for 4306c0 slow clock source */
  252. #define PCI_CFG_GPIO_SCS 0x10
  253. /* PCI config space GPIO 14 for Xtal power-up */
  254. #define PCI_CFG_GPIO_XTAL 0x40
  255. /* PCI config space GPIO 15 for PLL power-down */
  256. #define PCI_CFG_GPIO_PLL 0x80
  257. /* power control defines */
  258. #define PLL_DELAY 150 /* us pll on delay */
  259. #define FREF_DELAY 200 /* us fref change delay */
  260. #define XTAL_ON_DELAY 1000 /* us crystal power-on delay */
  261. /* resetctrl */
  262. #define AIRC_RESET 1
  263. #define NOREV -1 /* Invalid rev */
  264. /* GPIO Based LED powersave defines */
  265. #define DEFAULT_GPIO_ONTIME 10 /* Default: 10% on */
  266. #define DEFAULT_GPIO_OFFTIME 90 /* Default: 10% on */
  267. /* When Srom support present, fields in sromcontrol */
  268. #define SRC_START 0x80000000
  269. #define SRC_BUSY 0x80000000
  270. #define SRC_OPCODE 0x60000000
  271. #define SRC_OP_READ 0x00000000
  272. #define SRC_OP_WRITE 0x20000000
  273. #define SRC_OP_WRDIS 0x40000000
  274. #define SRC_OP_WREN 0x60000000
  275. #define SRC_OTPSEL 0x00000010
  276. #define SRC_LOCK 0x00000008
  277. #define SRC_SIZE_MASK 0x00000006
  278. #define SRC_SIZE_1K 0x00000000
  279. #define SRC_SIZE_4K 0x00000002
  280. #define SRC_SIZE_16K 0x00000004
  281. #define SRC_SIZE_SHIFT 1
  282. #define SRC_PRESENT 0x00000001
  283. /* External PA enable mask */
  284. #define GPIO_CTRL_EPA_EN_MASK 0x40
  285. #define DEFAULT_GPIOTIMERVAL \
  286. ((DEFAULT_GPIO_ONTIME << GPIO_ONTIME_SHIFT) | DEFAULT_GPIO_OFFTIME)
  287. #define BADIDX (SI_MAXCORES + 1)
  288. #define IS_SIM(chippkg) \
  289. ((chippkg == HDLSIM_PKG_ID) || (chippkg == HWSIM_PKG_ID))
  290. #define PCI(sih) (ai_get_buscoretype(sih) == PCI_CORE_ID)
  291. #define PCIE(sih) (ai_get_buscoretype(sih) == PCIE_CORE_ID)
  292. #define PCI_FORCEHT(sih) (PCIE(sih) && (ai_get_chip_id(sih) == BCM4716_CHIP_ID))
  293. #ifdef DEBUG
  294. #define SI_MSG(fmt, ...) pr_debug(fmt, ##__VA_ARGS__)
  295. #else
  296. #define SI_MSG(fmt, ...) no_printk(fmt, ##__VA_ARGS__)
  297. #endif /* DEBUG */
  298. #define GOODCOREADDR(x, b) \
  299. (((x) >= (b)) && ((x) < ((b) + SI_MAXCORES * SI_CORE_SIZE)) && \
  300. IS_ALIGNED((x), SI_CORE_SIZE))
  301. struct aidmp {
  302. u32 oobselina30; /* 0x000 */
  303. u32 oobselina74; /* 0x004 */
  304. u32 PAD[6];
  305. u32 oobselinb30; /* 0x020 */
  306. u32 oobselinb74; /* 0x024 */
  307. u32 PAD[6];
  308. u32 oobselinc30; /* 0x040 */
  309. u32 oobselinc74; /* 0x044 */
  310. u32 PAD[6];
  311. u32 oobselind30; /* 0x060 */
  312. u32 oobselind74; /* 0x064 */
  313. u32 PAD[38];
  314. u32 oobselouta30; /* 0x100 */
  315. u32 oobselouta74; /* 0x104 */
  316. u32 PAD[6];
  317. u32 oobseloutb30; /* 0x120 */
  318. u32 oobseloutb74; /* 0x124 */
  319. u32 PAD[6];
  320. u32 oobseloutc30; /* 0x140 */
  321. u32 oobseloutc74; /* 0x144 */
  322. u32 PAD[6];
  323. u32 oobseloutd30; /* 0x160 */
  324. u32 oobseloutd74; /* 0x164 */
  325. u32 PAD[38];
  326. u32 oobsynca; /* 0x200 */
  327. u32 oobseloutaen; /* 0x204 */
  328. u32 PAD[6];
  329. u32 oobsyncb; /* 0x220 */
  330. u32 oobseloutben; /* 0x224 */
  331. u32 PAD[6];
  332. u32 oobsyncc; /* 0x240 */
  333. u32 oobseloutcen; /* 0x244 */
  334. u32 PAD[6];
  335. u32 oobsyncd; /* 0x260 */
  336. u32 oobseloutden; /* 0x264 */
  337. u32 PAD[38];
  338. u32 oobaextwidth; /* 0x300 */
  339. u32 oobainwidth; /* 0x304 */
  340. u32 oobaoutwidth; /* 0x308 */
  341. u32 PAD[5];
  342. u32 oobbextwidth; /* 0x320 */
  343. u32 oobbinwidth; /* 0x324 */
  344. u32 oobboutwidth; /* 0x328 */
  345. u32 PAD[5];
  346. u32 oobcextwidth; /* 0x340 */
  347. u32 oobcinwidth; /* 0x344 */
  348. u32 oobcoutwidth; /* 0x348 */
  349. u32 PAD[5];
  350. u32 oobdextwidth; /* 0x360 */
  351. u32 oobdinwidth; /* 0x364 */
  352. u32 oobdoutwidth; /* 0x368 */
  353. u32 PAD[37];
  354. u32 ioctrlset; /* 0x400 */
  355. u32 ioctrlclear; /* 0x404 */
  356. u32 ioctrl; /* 0x408 */
  357. u32 PAD[61];
  358. u32 iostatus; /* 0x500 */
  359. u32 PAD[127];
  360. u32 ioctrlwidth; /* 0x700 */
  361. u32 iostatuswidth; /* 0x704 */
  362. u32 PAD[62];
  363. u32 resetctrl; /* 0x800 */
  364. u32 resetstatus; /* 0x804 */
  365. u32 resetreadid; /* 0x808 */
  366. u32 resetwriteid; /* 0x80c */
  367. u32 PAD[60];
  368. u32 errlogctrl; /* 0x900 */
  369. u32 errlogdone; /* 0x904 */
  370. u32 errlogstatus; /* 0x908 */
  371. u32 errlogaddrlo; /* 0x90c */
  372. u32 errlogaddrhi; /* 0x910 */
  373. u32 errlogid; /* 0x914 */
  374. u32 errloguser; /* 0x918 */
  375. u32 errlogflags; /* 0x91c */
  376. u32 PAD[56];
  377. u32 intstatus; /* 0xa00 */
  378. u32 PAD[127];
  379. u32 config; /* 0xe00 */
  380. u32 PAD[63];
  381. u32 itcr; /* 0xf00 */
  382. u32 PAD[3];
  383. u32 itipooba; /* 0xf10 */
  384. u32 itipoobb; /* 0xf14 */
  385. u32 itipoobc; /* 0xf18 */
  386. u32 itipoobd; /* 0xf1c */
  387. u32 PAD[4];
  388. u32 itipoobaout; /* 0xf30 */
  389. u32 itipoobbout; /* 0xf34 */
  390. u32 itipoobcout; /* 0xf38 */
  391. u32 itipoobdout; /* 0xf3c */
  392. u32 PAD[4];
  393. u32 itopooba; /* 0xf50 */
  394. u32 itopoobb; /* 0xf54 */
  395. u32 itopoobc; /* 0xf58 */
  396. u32 itopoobd; /* 0xf5c */
  397. u32 PAD[4];
  398. u32 itopoobain; /* 0xf70 */
  399. u32 itopoobbin; /* 0xf74 */
  400. u32 itopoobcin; /* 0xf78 */
  401. u32 itopoobdin; /* 0xf7c */
  402. u32 PAD[4];
  403. u32 itopreset; /* 0xf90 */
  404. u32 PAD[15];
  405. u32 peripherialid4; /* 0xfd0 */
  406. u32 peripherialid5; /* 0xfd4 */
  407. u32 peripherialid6; /* 0xfd8 */
  408. u32 peripherialid7; /* 0xfdc */
  409. u32 peripherialid0; /* 0xfe0 */
  410. u32 peripherialid1; /* 0xfe4 */
  411. u32 peripherialid2; /* 0xfe8 */
  412. u32 peripherialid3; /* 0xfec */
  413. u32 componentid0; /* 0xff0 */
  414. u32 componentid1; /* 0xff4 */
  415. u32 componentid2; /* 0xff8 */
  416. u32 componentid3; /* 0xffc */
  417. };
  418. /* return true if PCIE capability exists in the pci config space */
  419. static bool ai_ispcie(struct si_info *sii)
  420. {
  421. u8 cap_ptr;
  422. cap_ptr =
  423. pcicore_find_pci_capability(sii->pcibus, PCI_CAP_ID_EXP, NULL,
  424. NULL);
  425. if (!cap_ptr)
  426. return false;
  427. return true;
  428. }
  429. static bool ai_buscore_prep(struct si_info *sii)
  430. {
  431. /* kludge to enable the clock on the 4306 which lacks a slowclock */
  432. if (!ai_ispcie(sii))
  433. ai_clkctl_xtal(&sii->pub, XTAL | PLL, ON);
  434. return true;
  435. }
  436. static bool
  437. ai_buscore_setup(struct si_info *sii, struct bcma_device *cc)
  438. {
  439. struct bcma_device *pci = NULL;
  440. struct bcma_device *pcie = NULL;
  441. struct bcma_device *core;
  442. /* no cores found, bail out */
  443. if (cc->bus->nr_cores == 0)
  444. return false;
  445. /* get chipcommon rev */
  446. sii->pub.ccrev = cc->id.rev;
  447. /* get chipcommon chipstatus */
  448. if (ai_get_ccrev(&sii->pub) >= 11)
  449. sii->chipst = bcma_read32(cc, CHIPCREGOFFS(chipstatus));
  450. /* get chipcommon capabilites */
  451. sii->pub.cccaps = bcma_read32(cc, CHIPCREGOFFS(capabilities));
  452. /* get pmu rev and caps */
  453. if (ai_get_cccaps(&sii->pub) & CC_CAP_PMU) {
  454. sii->pub.pmucaps = bcma_read32(cc,
  455. CHIPCREGOFFS(pmucapabilities));
  456. sii->pub.pmurev = sii->pub.pmucaps & PCAP_REV_MASK;
  457. }
  458. /* figure out buscore */
  459. list_for_each_entry(core, &cc->bus->cores, list) {
  460. uint cid, crev;
  461. cid = core->id.id;
  462. crev = core->id.rev;
  463. if (cid == PCI_CORE_ID) {
  464. pci = core;
  465. } else if (cid == PCIE_CORE_ID) {
  466. pcie = core;
  467. }
  468. }
  469. if (pci && pcie) {
  470. if (ai_ispcie(sii))
  471. pci = NULL;
  472. else
  473. pcie = NULL;
  474. }
  475. if (pci) {
  476. sii->buscore = pci;
  477. } else if (pcie) {
  478. sii->buscore = pcie;
  479. }
  480. /* fixup necessary chip/core configurations */
  481. if (!sii->pch) {
  482. sii->pch = pcicore_init(&sii->pub, sii->icbus->drv_pci.core);
  483. if (sii->pch == NULL)
  484. return false;
  485. }
  486. if (ai_pci_fixcfg(&sii->pub))
  487. return false;
  488. return true;
  489. }
  490. /*
  491. * get boardtype and boardrev
  492. */
  493. static __used void ai_nvram_process(struct si_info *sii)
  494. {
  495. uint w = 0;
  496. /* do a pci config read to get subsystem id and subvendor id */
  497. pci_read_config_dword(sii->pcibus, PCI_SUBSYSTEM_VENDOR_ID, &w);
  498. sii->pub.boardvendor = w & 0xffff;
  499. sii->pub.boardtype = (w >> 16) & 0xffff;
  500. }
  501. static struct si_info *ai_doattach(struct si_info *sii,
  502. struct bcma_bus *pbus)
  503. {
  504. struct si_pub *sih = &sii->pub;
  505. u32 w, savewin;
  506. struct bcma_device *cc;
  507. uint socitype;
  508. struct ssb_sprom *sprom = &pbus->sprom;
  509. savewin = 0;
  510. sii->icbus = pbus;
  511. sii->pcibus = pbus->host_pci;
  512. /* switch to Chipcommon core */
  513. cc = pbus->drv_cc.core;
  514. /* bus/core/clk setup for register access */
  515. if (!ai_buscore_prep(sii))
  516. return NULL;
  517. /*
  518. * ChipID recognition.
  519. * We assume we can read chipid at offset 0 from the regs arg.
  520. * If we add other chiptypes (or if we need to support old sdio
  521. * hosts w/o chipcommon), some way of recognizing them needs to
  522. * be added here.
  523. */
  524. w = bcma_read32(cc, CHIPCREGOFFS(chipid));
  525. socitype = (w & CID_TYPE_MASK) >> CID_TYPE_SHIFT;
  526. /* Might as wll fill in chip id rev & pkg */
  527. sih->chip = w & CID_ID_MASK;
  528. sih->chiprev = (w & CID_REV_MASK) >> CID_REV_SHIFT;
  529. sih->chippkg = (w & CID_PKG_MASK) >> CID_PKG_SHIFT;
  530. /* scan for cores */
  531. if (socitype != SOCI_AI)
  532. return NULL;
  533. SI_MSG("Found chip type AI (0x%08x)\n", w);
  534. if (!ai_buscore_setup(sii, cc))
  535. goto exit;
  536. ai_nvram_process(sii);
  537. /* === NVRAM, clock is ready === */
  538. bcma_write32(cc, CHIPCREGOFFS(gpiopullup), 0);
  539. bcma_write32(cc, CHIPCREGOFFS(gpiopulldown), 0);
  540. /* PMU specific initializations */
  541. if (ai_get_cccaps(sih) & CC_CAP_PMU) {
  542. si_pmu_init(sih);
  543. (void)si_pmu_measure_alpclk(sih);
  544. si_pmu_res_init(sih);
  545. }
  546. /* setup the GPIO based LED powersave register */
  547. w = (sprom->leddc_on_time << BCMA_CC_GPIOTIMER_ONTIME_SHIFT) |
  548. (sprom->leddc_off_time << BCMA_CC_GPIOTIMER_OFFTIME_SHIFT);
  549. if (w == 0)
  550. w = DEFAULT_GPIOTIMERVAL;
  551. ai_cc_reg(sih, offsetof(struct chipcregs, gpiotimerval),
  552. ~0, w);
  553. if (PCIE(sih))
  554. pcicore_attach(sii->pch, SI_DOATTACH);
  555. if (ai_get_chip_id(sih) == BCM43224_CHIP_ID) {
  556. /*
  557. * enable 12 mA drive strenth for 43224 and
  558. * set chipControl register bit 15
  559. */
  560. if (ai_get_chiprev(sih) == 0) {
  561. SI_MSG("Applying 43224A0 WARs\n");
  562. ai_cc_reg(sih, offsetof(struct chipcregs, chipcontrol),
  563. CCTRL43224_GPIO_TOGGLE,
  564. CCTRL43224_GPIO_TOGGLE);
  565. si_pmu_chipcontrol(sih, 0, CCTRL_43224A0_12MA_LED_DRIVE,
  566. CCTRL_43224A0_12MA_LED_DRIVE);
  567. }
  568. if (ai_get_chiprev(sih) >= 1) {
  569. SI_MSG("Applying 43224B0+ WARs\n");
  570. si_pmu_chipcontrol(sih, 0, CCTRL_43224B0_12MA_LED_DRIVE,
  571. CCTRL_43224B0_12MA_LED_DRIVE);
  572. }
  573. }
  574. if (ai_get_chip_id(sih) == BCM4313_CHIP_ID) {
  575. /*
  576. * enable 12 mA drive strenth for 4313 and
  577. * set chipControl register bit 1
  578. */
  579. SI_MSG("Applying 4313 WARs\n");
  580. si_pmu_chipcontrol(sih, 0, CCTRL_4313_12MA_LED_DRIVE,
  581. CCTRL_4313_12MA_LED_DRIVE);
  582. }
  583. return sii;
  584. exit:
  585. if (sii->pch)
  586. pcicore_deinit(sii->pch);
  587. sii->pch = NULL;
  588. return NULL;
  589. }
  590. /*
  591. * Allocate a si handle and do the attach.
  592. */
  593. struct si_pub *
  594. ai_attach(struct bcma_bus *pbus)
  595. {
  596. struct si_info *sii;
  597. /* alloc struct si_info */
  598. sii = kzalloc(sizeof(struct si_info), GFP_ATOMIC);
  599. if (sii == NULL)
  600. return NULL;
  601. if (ai_doattach(sii, pbus) == NULL) {
  602. kfree(sii);
  603. return NULL;
  604. }
  605. return (struct si_pub *) sii;
  606. }
  607. /* may be called with core in reset */
  608. void ai_detach(struct si_pub *sih)
  609. {
  610. struct si_info *sii;
  611. struct si_pub *si_local = NULL;
  612. memcpy(&si_local, &sih, sizeof(struct si_pub **));
  613. sii = (struct si_info *)sih;
  614. if (sii == NULL)
  615. return;
  616. if (sii->pch)
  617. pcicore_deinit(sii->pch);
  618. sii->pch = NULL;
  619. kfree(sii);
  620. }
  621. /* return index of coreid or BADIDX if not found */
  622. struct bcma_device *ai_findcore(struct si_pub *sih, u16 coreid, u16 coreunit)
  623. {
  624. struct bcma_device *core;
  625. struct si_info *sii;
  626. uint found;
  627. sii = (struct si_info *)sih;
  628. found = 0;
  629. list_for_each_entry(core, &sii->icbus->cores, list)
  630. if (core->id.id == coreid) {
  631. if (found == coreunit)
  632. return core;
  633. found++;
  634. }
  635. return NULL;
  636. }
  637. /*
  638. * read/modify chipcommon core register.
  639. */
  640. uint ai_cc_reg(struct si_pub *sih, uint regoff, u32 mask, u32 val)
  641. {
  642. struct bcma_device *cc;
  643. u32 w;
  644. struct si_info *sii;
  645. sii = (struct si_info *)sih;
  646. cc = sii->icbus->drv_cc.core;
  647. /* mask and set */
  648. if (mask || val) {
  649. bcma_maskset32(cc, regoff, ~mask, val);
  650. }
  651. /* readback */
  652. w = bcma_read32(cc, regoff);
  653. return w;
  654. }
  655. /* return the slow clock source - LPO, XTAL, or PCI */
  656. static uint ai_slowclk_src(struct si_pub *sih, struct bcma_device *cc)
  657. {
  658. struct si_info *sii;
  659. u32 val;
  660. sii = (struct si_info *)sih;
  661. if (ai_get_ccrev(&sii->pub) < 6) {
  662. pci_read_config_dword(sii->pcibus, PCI_GPIO_OUT,
  663. &val);
  664. if (val & PCI_CFG_GPIO_SCS)
  665. return SCC_SS_PCI;
  666. return SCC_SS_XTAL;
  667. } else if (ai_get_ccrev(&sii->pub) < 10) {
  668. return bcma_read32(cc, CHIPCREGOFFS(slow_clk_ctl)) &
  669. SCC_SS_MASK;
  670. } else /* Insta-clock */
  671. return SCC_SS_XTAL;
  672. }
  673. /*
  674. * return the ILP (slowclock) min or max frequency
  675. * precondition: we've established the chip has dynamic clk control
  676. */
  677. static uint ai_slowclk_freq(struct si_pub *sih, bool max_freq,
  678. struct bcma_device *cc)
  679. {
  680. u32 slowclk;
  681. uint div;
  682. slowclk = ai_slowclk_src(sih, cc);
  683. if (ai_get_ccrev(sih) < 6) {
  684. if (slowclk == SCC_SS_PCI)
  685. return max_freq ? (PCIMAXFREQ / 64)
  686. : (PCIMINFREQ / 64);
  687. else
  688. return max_freq ? (XTALMAXFREQ / 32)
  689. : (XTALMINFREQ / 32);
  690. } else if (ai_get_ccrev(sih) < 10) {
  691. div = 4 *
  692. (((bcma_read32(cc, CHIPCREGOFFS(slow_clk_ctl)) &
  693. SCC_CD_MASK) >> SCC_CD_SHIFT) + 1);
  694. if (slowclk == SCC_SS_LPO)
  695. return max_freq ? LPOMAXFREQ : LPOMINFREQ;
  696. else if (slowclk == SCC_SS_XTAL)
  697. return max_freq ? (XTALMAXFREQ / div)
  698. : (XTALMINFREQ / div);
  699. else if (slowclk == SCC_SS_PCI)
  700. return max_freq ? (PCIMAXFREQ / div)
  701. : (PCIMINFREQ / div);
  702. } else {
  703. /* Chipc rev 10 is InstaClock */
  704. div = bcma_read32(cc, CHIPCREGOFFS(system_clk_ctl));
  705. div = 4 * ((div >> SYCC_CD_SHIFT) + 1);
  706. return max_freq ? XTALMAXFREQ : (XTALMINFREQ / div);
  707. }
  708. return 0;
  709. }
  710. static void
  711. ai_clkctl_setdelay(struct si_pub *sih, struct bcma_device *cc)
  712. {
  713. uint slowmaxfreq, pll_delay, slowclk;
  714. uint pll_on_delay, fref_sel_delay;
  715. pll_delay = PLL_DELAY;
  716. /*
  717. * If the slow clock is not sourced by the xtal then
  718. * add the xtal_on_delay since the xtal will also be
  719. * powered down by dynamic clk control logic.
  720. */
  721. slowclk = ai_slowclk_src(sih, cc);
  722. if (slowclk != SCC_SS_XTAL)
  723. pll_delay += XTAL_ON_DELAY;
  724. /* Starting with 4318 it is ILP that is used for the delays */
  725. slowmaxfreq =
  726. ai_slowclk_freq(sih,
  727. (ai_get_ccrev(sih) >= 10) ? false : true, cc);
  728. pll_on_delay = ((slowmaxfreq * pll_delay) + 999999) / 1000000;
  729. fref_sel_delay = ((slowmaxfreq * FREF_DELAY) + 999999) / 1000000;
  730. bcma_write32(cc, CHIPCREGOFFS(pll_on_delay), pll_on_delay);
  731. bcma_write32(cc, CHIPCREGOFFS(fref_sel_delay), fref_sel_delay);
  732. }
  733. /* initialize power control delay registers */
  734. void ai_clkctl_init(struct si_pub *sih)
  735. {
  736. struct bcma_device *cc;
  737. if (!(ai_get_cccaps(sih) & CC_CAP_PWR_CTL))
  738. return;
  739. cc = ai_findcore(sih, BCMA_CORE_CHIPCOMMON, 0);
  740. if (cc == NULL)
  741. return;
  742. /* set all Instaclk chip ILP to 1 MHz */
  743. if (ai_get_ccrev(sih) >= 10)
  744. bcma_maskset32(cc, CHIPCREGOFFS(system_clk_ctl), SYCC_CD_MASK,
  745. (ILP_DIV_1MHZ << SYCC_CD_SHIFT));
  746. ai_clkctl_setdelay(sih, cc);
  747. }
  748. /*
  749. * return the value suitable for writing to the
  750. * dot11 core FAST_PWRUP_DELAY register
  751. */
  752. u16 ai_clkctl_fast_pwrup_delay(struct si_pub *sih)
  753. {
  754. struct si_info *sii;
  755. struct bcma_device *cc;
  756. uint slowminfreq;
  757. u16 fpdelay;
  758. sii = (struct si_info *)sih;
  759. if (ai_get_cccaps(sih) & CC_CAP_PMU) {
  760. fpdelay = si_pmu_fast_pwrup_delay(sih);
  761. return fpdelay;
  762. }
  763. if (!(ai_get_cccaps(sih) & CC_CAP_PWR_CTL))
  764. return 0;
  765. fpdelay = 0;
  766. cc = ai_findcore(sih, CC_CORE_ID, 0);
  767. if (cc) {
  768. slowminfreq = ai_slowclk_freq(sih, false, cc);
  769. fpdelay = (((bcma_read32(cc, CHIPCREGOFFS(pll_on_delay)) + 2)
  770. * 1000000) + (slowminfreq - 1)) / slowminfreq;
  771. }
  772. return fpdelay;
  773. }
  774. /* turn primary xtal and/or pll off/on */
  775. int ai_clkctl_xtal(struct si_pub *sih, uint what, bool on)
  776. {
  777. struct si_info *sii;
  778. u32 in, out, outen;
  779. sii = (struct si_info *)sih;
  780. /* pcie core doesn't have any mapping to control the xtal pu */
  781. if (PCIE(sih))
  782. return -1;
  783. pci_read_config_dword(sii->pcibus, PCI_GPIO_IN, &in);
  784. pci_read_config_dword(sii->pcibus, PCI_GPIO_OUT, &out);
  785. pci_read_config_dword(sii->pcibus, PCI_GPIO_OUTEN, &outen);
  786. /*
  787. * Avoid glitching the clock if GPRS is already using it.
  788. * We can't actually read the state of the PLLPD so we infer it
  789. * by the value of XTAL_PU which *is* readable via gpioin.
  790. */
  791. if (on && (in & PCI_CFG_GPIO_XTAL))
  792. return 0;
  793. if (what & XTAL)
  794. outen |= PCI_CFG_GPIO_XTAL;
  795. if (what & PLL)
  796. outen |= PCI_CFG_GPIO_PLL;
  797. if (on) {
  798. /* turn primary xtal on */
  799. if (what & XTAL) {
  800. out |= PCI_CFG_GPIO_XTAL;
  801. if (what & PLL)
  802. out |= PCI_CFG_GPIO_PLL;
  803. pci_write_config_dword(sii->pcibus,
  804. PCI_GPIO_OUT, out);
  805. pci_write_config_dword(sii->pcibus,
  806. PCI_GPIO_OUTEN, outen);
  807. udelay(XTAL_ON_DELAY);
  808. }
  809. /* turn pll on */
  810. if (what & PLL) {
  811. out &= ~PCI_CFG_GPIO_PLL;
  812. pci_write_config_dword(sii->pcibus,
  813. PCI_GPIO_OUT, out);
  814. mdelay(2);
  815. }
  816. } else {
  817. if (what & XTAL)
  818. out &= ~PCI_CFG_GPIO_XTAL;
  819. if (what & PLL)
  820. out |= PCI_CFG_GPIO_PLL;
  821. pci_write_config_dword(sii->pcibus,
  822. PCI_GPIO_OUT, out);
  823. pci_write_config_dword(sii->pcibus,
  824. PCI_GPIO_OUTEN, outen);
  825. }
  826. return 0;
  827. }
  828. /* clk control mechanism through chipcommon, no policy checking */
  829. static bool _ai_clkctl_cc(struct si_info *sii, uint mode)
  830. {
  831. struct bcma_device *cc;
  832. u32 scc;
  833. /* chipcommon cores prior to rev6 don't support dynamic clock control */
  834. if (ai_get_ccrev(&sii->pub) < 6)
  835. return false;
  836. cc = ai_findcore(&sii->pub, BCMA_CORE_CHIPCOMMON, 0);
  837. if (!(ai_get_cccaps(&sii->pub) & CC_CAP_PWR_CTL) &&
  838. (ai_get_ccrev(&sii->pub) < 20))
  839. return mode == CLK_FAST;
  840. switch (mode) {
  841. case CLK_FAST: /* FORCEHT, fast (pll) clock */
  842. if (ai_get_ccrev(&sii->pub) < 10) {
  843. /*
  844. * don't forget to force xtal back
  845. * on before we clear SCC_DYN_XTAL..
  846. */
  847. ai_clkctl_xtal(&sii->pub, XTAL, ON);
  848. bcma_maskset32(cc, CHIPCREGOFFS(slow_clk_ctl),
  849. (SCC_XC | SCC_FS | SCC_IP), SCC_IP);
  850. } else if (ai_get_ccrev(&sii->pub) < 20) {
  851. bcma_set32(cc, CHIPCREGOFFS(system_clk_ctl), SYCC_HR);
  852. } else {
  853. bcma_set32(cc, CHIPCREGOFFS(clk_ctl_st), CCS_FORCEHT);
  854. }
  855. /* wait for the PLL */
  856. if (ai_get_cccaps(&sii->pub) & CC_CAP_PMU) {
  857. u32 htavail = CCS_HTAVAIL;
  858. SPINWAIT(((bcma_read32(cc, CHIPCREGOFFS(clk_ctl_st)) &
  859. htavail) == 0), PMU_MAX_TRANSITION_DLY);
  860. } else {
  861. udelay(PLL_DELAY);
  862. }
  863. break;
  864. case CLK_DYNAMIC: /* enable dynamic clock control */
  865. if (ai_get_ccrev(&sii->pub) < 10) {
  866. scc = bcma_read32(cc, CHIPCREGOFFS(slow_clk_ctl));
  867. scc &= ~(SCC_FS | SCC_IP | SCC_XC);
  868. if ((scc & SCC_SS_MASK) != SCC_SS_XTAL)
  869. scc |= SCC_XC;
  870. bcma_write32(cc, CHIPCREGOFFS(slow_clk_ctl), scc);
  871. /*
  872. * for dynamic control, we have to
  873. * release our xtal_pu "force on"
  874. */
  875. if (scc & SCC_XC)
  876. ai_clkctl_xtal(&sii->pub, XTAL, OFF);
  877. } else if (ai_get_ccrev(&sii->pub) < 20) {
  878. /* Instaclock */
  879. bcma_mask32(cc, CHIPCREGOFFS(system_clk_ctl), ~SYCC_HR);
  880. } else {
  881. bcma_mask32(cc, CHIPCREGOFFS(clk_ctl_st), ~CCS_FORCEHT);
  882. }
  883. break;
  884. default:
  885. break;
  886. }
  887. return mode == CLK_FAST;
  888. }
  889. /*
  890. * clock control policy function throught chipcommon
  891. *
  892. * set dynamic clk control mode (forceslow, forcefast, dynamic)
  893. * returns true if we are forcing fast clock
  894. * this is a wrapper over the next internal function
  895. * to allow flexible policy settings for outside caller
  896. */
  897. bool ai_clkctl_cc(struct si_pub *sih, uint mode)
  898. {
  899. struct si_info *sii;
  900. sii = (struct si_info *)sih;
  901. /* chipcommon cores prior to rev6 don't support dynamic clock control */
  902. if (ai_get_ccrev(sih) < 6)
  903. return false;
  904. if (PCI_FORCEHT(sih))
  905. return mode == CLK_FAST;
  906. return _ai_clkctl_cc(sii, mode);
  907. }
  908. void ai_pci_up(struct si_pub *sih)
  909. {
  910. struct si_info *sii;
  911. sii = (struct si_info *)sih;
  912. if (PCI_FORCEHT(sih))
  913. _ai_clkctl_cc(sii, CLK_FAST);
  914. if (PCIE(sih))
  915. pcicore_up(sii->pch, SI_PCIUP);
  916. }
  917. /* Unconfigure and/or apply various WARs when system is going to sleep mode */
  918. void ai_pci_sleep(struct si_pub *sih)
  919. {
  920. struct si_info *sii;
  921. sii = (struct si_info *)sih;
  922. pcicore_sleep(sii->pch);
  923. }
  924. /* Unconfigure and/or apply various WARs when going down */
  925. void ai_pci_down(struct si_pub *sih)
  926. {
  927. struct si_info *sii;
  928. sii = (struct si_info *)sih;
  929. /* release FORCEHT since chip is going to "down" state */
  930. if (PCI_FORCEHT(sih))
  931. _ai_clkctl_cc(sii, CLK_DYNAMIC);
  932. pcicore_down(sii->pch, SI_PCIDOWN);
  933. }
  934. /*
  935. * Configure the pci core for pci client (NIC) action
  936. * coremask is the bitvec of cores by index to be enabled.
  937. */
  938. void ai_pci_setup(struct si_pub *sih, uint coremask)
  939. {
  940. struct si_info *sii;
  941. u32 w;
  942. sii = (struct si_info *)sih;
  943. /*
  944. * Enable sb->pci interrupts. Assume
  945. * PCI rev 2.3 support was added in pci core rev 6 and things changed..
  946. */
  947. if (PCIE(sih) || (PCI(sih) && (ai_get_buscorerev(sih) >= 6))) {
  948. /* pci config write to set this core bit in PCIIntMask */
  949. pci_read_config_dword(sii->pcibus, PCI_INT_MASK, &w);
  950. w |= (coremask << PCI_SBIM_SHIFT);
  951. pci_write_config_dword(sii->pcibus, PCI_INT_MASK, w);
  952. }
  953. if (PCI(sih)) {
  954. pcicore_pci_setup(sii->pch);
  955. }
  956. }
  957. /*
  958. * Fixup SROMless PCI device's configuration.
  959. * The current core may be changed upon return.
  960. */
  961. int ai_pci_fixcfg(struct si_pub *sih)
  962. {
  963. struct si_info *sii = (struct si_info *)sih;
  964. /* Fixup PI in SROM shadow area to enable the correct PCI core access */
  965. /* check 'pi' is correct and fix it if not */
  966. pcicore_fixcfg(sii->pch);
  967. pcicore_hwup(sii->pch);
  968. return 0;
  969. }
  970. /* mask&set gpiocontrol bits */
  971. u32 ai_gpiocontrol(struct si_pub *sih, u32 mask, u32 val, u8 priority)
  972. {
  973. uint regoff;
  974. regoff = offsetof(struct chipcregs, gpiocontrol);
  975. return ai_cc_reg(sih, regoff, mask, val);
  976. }
  977. void ai_chipcontrl_epa4331(struct si_pub *sih, bool on)
  978. {
  979. struct bcma_device *cc;
  980. u32 val;
  981. cc = ai_findcore(sih, CC_CORE_ID, 0);
  982. if (on) {
  983. if (ai_get_chippkg(sih) == 9 || ai_get_chippkg(sih) == 0xb)
  984. /* Ext PA Controls for 4331 12x9 Package */
  985. bcma_set32(cc, CHIPCREGOFFS(chipcontrol),
  986. CCTRL4331_EXTPA_EN |
  987. CCTRL4331_EXTPA_ON_GPIO2_5);
  988. else
  989. /* Ext PA Controls for 4331 12x12 Package */
  990. bcma_set32(cc, CHIPCREGOFFS(chipcontrol),
  991. CCTRL4331_EXTPA_EN);
  992. } else {
  993. val &= ~(CCTRL4331_EXTPA_EN | CCTRL4331_EXTPA_ON_GPIO2_5);
  994. bcma_mask32(cc, CHIPCREGOFFS(chipcontrol),
  995. ~(CCTRL4331_EXTPA_EN | CCTRL4331_EXTPA_ON_GPIO2_5));
  996. }
  997. }
  998. /* Enable BT-COEX & Ex-PA for 4313 */
  999. void ai_epa_4313war(struct si_pub *sih)
  1000. {
  1001. struct bcma_device *cc;
  1002. cc = ai_findcore(sih, CC_CORE_ID, 0);
  1003. /* EPA Fix */
  1004. bcma_set32(cc, CHIPCREGOFFS(gpiocontrol), GPIO_CTRL_EPA_EN_MASK);
  1005. }
  1006. /* check if the device is removed */
  1007. bool ai_deviceremoved(struct si_pub *sih)
  1008. {
  1009. u32 w;
  1010. struct si_info *sii;
  1011. sii = (struct si_info *)sih;
  1012. pci_read_config_dword(sii->pcibus, PCI_VENDOR_ID, &w);
  1013. if ((w & 0xFFFF) != PCI_VENDOR_ID_BROADCOM)
  1014. return true;
  1015. return false;
  1016. }
  1017. uint ai_get_buscoretype(struct si_pub *sih)
  1018. {
  1019. struct si_info *sii = (struct si_info *)sih;
  1020. return sii->buscore->id.id;
  1021. }
  1022. uint ai_get_buscorerev(struct si_pub *sih)
  1023. {
  1024. struct si_info *sii = (struct si_info *)sih;
  1025. return sii->buscore->id.rev;
  1026. }