aiutils.c 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863
  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 "srom.h"
  30. #include "nicpci.h"
  31. #include "aiutils.h"
  32. /* slow_clk_ctl */
  33. /* slow clock source mask */
  34. #define SCC_SS_MASK 0x00000007
  35. /* source of slow clock is LPO */
  36. #define SCC_SS_LPO 0x00000000
  37. /* source of slow clock is crystal */
  38. #define SCC_SS_XTAL 0x00000001
  39. /* source of slow clock is PCI */
  40. #define SCC_SS_PCI 0x00000002
  41. /* LPOFreqSel, 1: 160Khz, 0: 32KHz */
  42. #define SCC_LF 0x00000200
  43. /* LPOPowerDown, 1: LPO is disabled, 0: LPO is enabled */
  44. #define SCC_LP 0x00000400
  45. /* ForceSlowClk, 1: sb/cores running on slow clock, 0: power logic control */
  46. #define SCC_FS 0x00000800
  47. /* IgnorePllOffReq, 1/0:
  48. * power logic ignores/honors PLL clock disable requests from core
  49. */
  50. #define SCC_IP 0x00001000
  51. /* XtalControlEn, 1/0:
  52. * power logic does/doesn't disable crystal when appropriate
  53. */
  54. #define SCC_XC 0x00002000
  55. /* XtalPU (RO), 1/0: crystal running/disabled */
  56. #define SCC_XP 0x00004000
  57. /* ClockDivider (SlowClk = 1/(4+divisor)) */
  58. #define SCC_CD_MASK 0xffff0000
  59. #define SCC_CD_SHIFT 16
  60. /* system_clk_ctl */
  61. /* ILPen: Enable Idle Low Power */
  62. #define SYCC_IE 0x00000001
  63. /* ALPen: Enable Active Low Power */
  64. #define SYCC_AE 0x00000002
  65. /* ForcePLLOn */
  66. #define SYCC_FP 0x00000004
  67. /* Force ALP (or HT if ALPen is not set */
  68. #define SYCC_AR 0x00000008
  69. /* Force HT */
  70. #define SYCC_HR 0x00000010
  71. /* ClkDiv (ILP = 1/(4 * (divisor + 1)) */
  72. #define SYCC_CD_MASK 0xffff0000
  73. #define SYCC_CD_SHIFT 16
  74. #define CST4329_SPROM_OTP_SEL_MASK 0x00000003
  75. /* OTP is powered up, use def. CIS, no SPROM */
  76. #define CST4329_DEFCIS_SEL 0
  77. /* OTP is powered up, SPROM is present */
  78. #define CST4329_SPROM_SEL 1
  79. /* OTP is powered up, no SPROM */
  80. #define CST4329_OTP_SEL 2
  81. /* OTP is powered down, SPROM is present */
  82. #define CST4329_OTP_PWRDN 3
  83. #define CST4329_SPI_SDIO_MODE_MASK 0x00000004
  84. #define CST4329_SPI_SDIO_MODE_SHIFT 2
  85. /* 43224 chip-specific ChipControl register bits */
  86. #define CCTRL43224_GPIO_TOGGLE 0x8000
  87. /* 12 mA drive strength */
  88. #define CCTRL_43224A0_12MA_LED_DRIVE 0x00F000F0
  89. /* 12 mA drive strength for later 43224s */
  90. #define CCTRL_43224B0_12MA_LED_DRIVE 0xF0
  91. /* 43236 Chip specific ChipStatus register bits */
  92. #define CST43236_SFLASH_MASK 0x00000040
  93. #define CST43236_OTP_MASK 0x00000080
  94. #define CST43236_HSIC_MASK 0x00000100 /* USB/HSIC */
  95. #define CST43236_BP_CLK 0x00000200 /* 120/96Mbps */
  96. #define CST43236_BOOT_MASK 0x00001800
  97. #define CST43236_BOOT_SHIFT 11
  98. #define CST43236_BOOT_FROM_SRAM 0 /* boot from SRAM, ARM in reset */
  99. #define CST43236_BOOT_FROM_ROM 1 /* boot from ROM */
  100. #define CST43236_BOOT_FROM_FLASH 2 /* boot from FLASH */
  101. #define CST43236_BOOT_FROM_INVALID 3
  102. /* 4331 chip-specific ChipControl register bits */
  103. /* 0 disable */
  104. #define CCTRL4331_BT_COEXIST (1<<0)
  105. /* 0 SECI is disabled (JTAG functional) */
  106. #define CCTRL4331_SECI (1<<1)
  107. /* 0 disable */
  108. #define CCTRL4331_EXT_LNA (1<<2)
  109. /* sprom/gpio13-15 mux */
  110. #define CCTRL4331_SPROM_GPIO13_15 (1<<3)
  111. /* 0 ext pa disable, 1 ext pa enabled */
  112. #define CCTRL4331_EXTPA_EN (1<<4)
  113. /* set drive out GPIO_CLK on sprom_cs pin */
  114. #define CCTRL4331_GPIOCLK_ON_SPROMCS (1<<5)
  115. /* use sprom_cs pin as PCIE mdio interface */
  116. #define CCTRL4331_PCIE_MDIO_ON_SPROMCS (1<<6)
  117. /* aband extpa will be at gpio2/5 and sprom_dout */
  118. #define CCTRL4331_EXTPA_ON_GPIO2_5 (1<<7)
  119. /* override core control on pipe_AuxClkEnable */
  120. #define CCTRL4331_OVR_PIPEAUXCLKEN (1<<8)
  121. /* override core control on pipe_AuxPowerDown */
  122. #define CCTRL4331_OVR_PIPEAUXPWRDOWN (1<<9)
  123. /* pcie_auxclkenable */
  124. #define CCTRL4331_PCIE_AUXCLKEN (1<<10)
  125. /* pcie_pipe_pllpowerdown */
  126. #define CCTRL4331_PCIE_PIPE_PLLDOWN (1<<11)
  127. /* enable bt_shd0 at gpio4 */
  128. #define CCTRL4331_BT_SHD0_ON_GPIO4 (1<<16)
  129. /* enable bt_shd1 at gpio5 */
  130. #define CCTRL4331_BT_SHD1_ON_GPIO5 (1<<17)
  131. /* 4331 Chip specific ChipStatus register bits */
  132. /* crystal frequency 20/40Mhz */
  133. #define CST4331_XTAL_FREQ 0x00000001
  134. #define CST4331_SPROM_PRESENT 0x00000002
  135. #define CST4331_OTP_PRESENT 0x00000004
  136. #define CST4331_LDO_RF 0x00000008
  137. #define CST4331_LDO_PAR 0x00000010
  138. /* 4319 chip-specific ChipStatus register bits */
  139. #define CST4319_SPI_CPULESSUSB 0x00000001
  140. #define CST4319_SPI_CLK_POL 0x00000002
  141. #define CST4319_SPI_CLK_PH 0x00000008
  142. /* gpio [7:6], SDIO CIS selection */
  143. #define CST4319_SPROM_OTP_SEL_MASK 0x000000c0
  144. #define CST4319_SPROM_OTP_SEL_SHIFT 6
  145. /* use default CIS, OTP is powered up */
  146. #define CST4319_DEFCIS_SEL 0x00000000
  147. /* use SPROM, OTP is powered up */
  148. #define CST4319_SPROM_SEL 0x00000040
  149. /* use OTP, OTP is powered up */
  150. #define CST4319_OTP_SEL 0x00000080
  151. /* use SPROM, OTP is powered down */
  152. #define CST4319_OTP_PWRDN 0x000000c0
  153. /* gpio [8], sdio/usb mode */
  154. #define CST4319_SDIO_USB_MODE 0x00000100
  155. #define CST4319_REMAP_SEL_MASK 0x00000600
  156. #define CST4319_ILPDIV_EN 0x00000800
  157. #define CST4319_XTAL_PD_POL 0x00001000
  158. #define CST4319_LPO_SEL 0x00002000
  159. #define CST4319_RES_INIT_MODE 0x0000c000
  160. /* PALDO is configured with external PNP */
  161. #define CST4319_PALDO_EXTPNP 0x00010000
  162. #define CST4319_CBUCK_MODE_MASK 0x00060000
  163. #define CST4319_CBUCK_MODE_BURST 0x00020000
  164. #define CST4319_CBUCK_MODE_LPBURST 0x00060000
  165. #define CST4319_RCAL_VALID 0x01000000
  166. #define CST4319_RCAL_VALUE_MASK 0x3e000000
  167. #define CST4319_RCAL_VALUE_SHIFT 25
  168. /* 4336 chip-specific ChipStatus register bits */
  169. #define CST4336_SPI_MODE_MASK 0x00000001
  170. #define CST4336_SPROM_PRESENT 0x00000002
  171. #define CST4336_OTP_PRESENT 0x00000004
  172. #define CST4336_ARMREMAP_0 0x00000008
  173. #define CST4336_ILPDIV_EN_MASK 0x00000010
  174. #define CST4336_ILPDIV_EN_SHIFT 4
  175. #define CST4336_XTAL_PD_POL_MASK 0x00000020
  176. #define CST4336_XTAL_PD_POL_SHIFT 5
  177. #define CST4336_LPO_SEL_MASK 0x00000040
  178. #define CST4336_LPO_SEL_SHIFT 6
  179. #define CST4336_RES_INIT_MODE_MASK 0x00000180
  180. #define CST4336_RES_INIT_MODE_SHIFT 7
  181. #define CST4336_CBUCK_MODE_MASK 0x00000600
  182. #define CST4336_CBUCK_MODE_SHIFT 9
  183. /* 4313 chip-specific ChipStatus register bits */
  184. #define CST4313_SPROM_PRESENT 1
  185. #define CST4313_OTP_PRESENT 2
  186. #define CST4313_SPROM_OTP_SEL_MASK 0x00000002
  187. #define CST4313_SPROM_OTP_SEL_SHIFT 0
  188. /* 4313 Chip specific ChipControl register bits */
  189. /* 12 mA drive strengh for later 4313 */
  190. #define CCTRL_4313_12MA_LED_DRIVE 0x00000007
  191. /* Manufacturer Ids */
  192. #define MFGID_ARM 0x43b
  193. #define MFGID_BRCM 0x4bf
  194. #define MFGID_MIPS 0x4a7
  195. /* Enumeration ROM registers */
  196. #define ER_EROMENTRY 0x000
  197. #define ER_REMAPCONTROL 0xe00
  198. #define ER_REMAPSELECT 0xe04
  199. #define ER_MASTERSELECT 0xe10
  200. #define ER_ITCR 0xf00
  201. #define ER_ITIP 0xf04
  202. /* Erom entries */
  203. #define ER_TAG 0xe
  204. #define ER_TAG1 0x6
  205. #define ER_VALID 1
  206. #define ER_CI 0
  207. #define ER_MP 2
  208. #define ER_ADD 4
  209. #define ER_END 0xe
  210. #define ER_BAD 0xffffffff
  211. /* EROM CompIdentA */
  212. #define CIA_MFG_MASK 0xfff00000
  213. #define CIA_MFG_SHIFT 20
  214. #define CIA_CID_MASK 0x000fff00
  215. #define CIA_CID_SHIFT 8
  216. #define CIA_CCL_MASK 0x000000f0
  217. #define CIA_CCL_SHIFT 4
  218. /* EROM CompIdentB */
  219. #define CIB_REV_MASK 0xff000000
  220. #define CIB_REV_SHIFT 24
  221. #define CIB_NSW_MASK 0x00f80000
  222. #define CIB_NSW_SHIFT 19
  223. #define CIB_NMW_MASK 0x0007c000
  224. #define CIB_NMW_SHIFT 14
  225. #define CIB_NSP_MASK 0x00003e00
  226. #define CIB_NSP_SHIFT 9
  227. #define CIB_NMP_MASK 0x000001f0
  228. #define CIB_NMP_SHIFT 4
  229. /* EROM AddrDesc */
  230. #define AD_ADDR_MASK 0xfffff000
  231. #define AD_SP_MASK 0x00000f00
  232. #define AD_SP_SHIFT 8
  233. #define AD_ST_MASK 0x000000c0
  234. #define AD_ST_SHIFT 6
  235. #define AD_ST_SLAVE 0x00000000
  236. #define AD_ST_BRIDGE 0x00000040
  237. #define AD_ST_SWRAP 0x00000080
  238. #define AD_ST_MWRAP 0x000000c0
  239. #define AD_SZ_MASK 0x00000030
  240. #define AD_SZ_SHIFT 4
  241. #define AD_SZ_4K 0x00000000
  242. #define AD_SZ_8K 0x00000010
  243. #define AD_SZ_16K 0x00000020
  244. #define AD_SZ_SZD 0x00000030
  245. #define AD_AG32 0x00000008
  246. #define AD_ADDR_ALIGN 0x00000fff
  247. #define AD_SZ_BASE 0x00001000 /* 4KB */
  248. /* EROM SizeDesc */
  249. #define SD_SZ_MASK 0xfffff000
  250. #define SD_SG32 0x00000008
  251. #define SD_SZ_ALIGN 0x00000fff
  252. /* PCI config space bit 4 for 4306c0 slow clock source */
  253. #define PCI_CFG_GPIO_SCS 0x10
  254. /* PCI config space GPIO 14 for Xtal power-up */
  255. #define PCI_CFG_GPIO_XTAL 0x40
  256. /* PCI config space GPIO 15 for PLL power-down */
  257. #define PCI_CFG_GPIO_PLL 0x80
  258. /* power control defines */
  259. #define PLL_DELAY 150 /* us pll on delay */
  260. #define FREF_DELAY 200 /* us fref change delay */
  261. #define XTAL_ON_DELAY 1000 /* us crystal power-on delay */
  262. /* resetctrl */
  263. #define AIRC_RESET 1
  264. #define NOREV -1 /* Invalid rev */
  265. /* GPIO Based LED powersave defines */
  266. #define DEFAULT_GPIO_ONTIME 10 /* Default: 10% on */
  267. #define DEFAULT_GPIO_OFFTIME 90 /* Default: 10% on */
  268. /* When Srom support present, fields in sromcontrol */
  269. #define SRC_START 0x80000000
  270. #define SRC_BUSY 0x80000000
  271. #define SRC_OPCODE 0x60000000
  272. #define SRC_OP_READ 0x00000000
  273. #define SRC_OP_WRITE 0x20000000
  274. #define SRC_OP_WRDIS 0x40000000
  275. #define SRC_OP_WREN 0x60000000
  276. #define SRC_OTPSEL 0x00000010
  277. #define SRC_LOCK 0x00000008
  278. #define SRC_SIZE_MASK 0x00000006
  279. #define SRC_SIZE_1K 0x00000000
  280. #define SRC_SIZE_4K 0x00000002
  281. #define SRC_SIZE_16K 0x00000004
  282. #define SRC_SIZE_SHIFT 1
  283. #define SRC_PRESENT 0x00000001
  284. /* External PA enable mask */
  285. #define GPIO_CTRL_EPA_EN_MASK 0x40
  286. #define DEFAULT_GPIOTIMERVAL \
  287. ((DEFAULT_GPIO_ONTIME << GPIO_ONTIME_SHIFT) | DEFAULT_GPIO_OFFTIME)
  288. #define BADIDX (SI_MAXCORES + 1)
  289. /* Newer chips can access PCI/PCIE and CC core without requiring to change
  290. * PCI BAR0 WIN
  291. */
  292. #define SI_FAST(sih) ((ai_get_buscoretype(sih) == PCIE_CORE_ID) || \
  293. ((ai_get_buscoretype(sih) == PCI_CORE_ID) && \
  294. ai_get_buscorerev(sih) >= 13))
  295. #define CCREGS_FAST(si) (((char __iomem *)((si)->curmap) + \
  296. PCI_16KB0_CCREGS_OFFSET))
  297. #define IS_SIM(chippkg) \
  298. ((chippkg == HDLSIM_PKG_ID) || (chippkg == HWSIM_PKG_ID))
  299. /*
  300. * Macros to disable/restore function core(D11, ENET, ILINE20, etc) interrupts
  301. * before after core switching to avoid invalid register accesss inside ISR.
  302. */
  303. #define INTR_OFF(si, intr_val) \
  304. if ((si)->intrsoff_fn && \
  305. (si)->coreid[(si)->curidx] == (si)->dev_coreid) \
  306. intr_val = (*(si)->intrsoff_fn)((si)->intr_arg)
  307. #define INTR_RESTORE(si, intr_val) \
  308. if ((si)->intrsrestore_fn && \
  309. (si)->coreid[(si)->curidx] == (si)->dev_coreid) \
  310. (*(si)->intrsrestore_fn)((si)->intr_arg, intr_val)
  311. #define PCI(sih) (ai_get_buscoretype(sih) == PCI_CORE_ID)
  312. #define PCIE(sih) (ai_get_buscoretype(sih) == PCIE_CORE_ID)
  313. #define PCI_FORCEHT(sih) (PCIE(sih) && (ai_get_chip_id(sih) == BCM4716_CHIP_ID))
  314. #ifdef BCMDBG
  315. #define SI_MSG(fmt, ...) pr_debug(fmt, ##__VA_ARGS__)
  316. #else
  317. #define SI_MSG(fmt, ...) no_printk(fmt, ##__VA_ARGS__)
  318. #endif /* BCMDBG */
  319. #define GOODCOREADDR(x, b) \
  320. (((x) >= (b)) && ((x) < ((b) + SI_MAXCORES * SI_CORE_SIZE)) && \
  321. IS_ALIGNED((x), SI_CORE_SIZE))
  322. #define PCIEREGS(si) ((__iomem char *)((si)->curmap) + \
  323. PCI_16KB0_PCIREGS_OFFSET)
  324. struct aidmp {
  325. u32 oobselina30; /* 0x000 */
  326. u32 oobselina74; /* 0x004 */
  327. u32 PAD[6];
  328. u32 oobselinb30; /* 0x020 */
  329. u32 oobselinb74; /* 0x024 */
  330. u32 PAD[6];
  331. u32 oobselinc30; /* 0x040 */
  332. u32 oobselinc74; /* 0x044 */
  333. u32 PAD[6];
  334. u32 oobselind30; /* 0x060 */
  335. u32 oobselind74; /* 0x064 */
  336. u32 PAD[38];
  337. u32 oobselouta30; /* 0x100 */
  338. u32 oobselouta74; /* 0x104 */
  339. u32 PAD[6];
  340. u32 oobseloutb30; /* 0x120 */
  341. u32 oobseloutb74; /* 0x124 */
  342. u32 PAD[6];
  343. u32 oobseloutc30; /* 0x140 */
  344. u32 oobseloutc74; /* 0x144 */
  345. u32 PAD[6];
  346. u32 oobseloutd30; /* 0x160 */
  347. u32 oobseloutd74; /* 0x164 */
  348. u32 PAD[38];
  349. u32 oobsynca; /* 0x200 */
  350. u32 oobseloutaen; /* 0x204 */
  351. u32 PAD[6];
  352. u32 oobsyncb; /* 0x220 */
  353. u32 oobseloutben; /* 0x224 */
  354. u32 PAD[6];
  355. u32 oobsyncc; /* 0x240 */
  356. u32 oobseloutcen; /* 0x244 */
  357. u32 PAD[6];
  358. u32 oobsyncd; /* 0x260 */
  359. u32 oobseloutden; /* 0x264 */
  360. u32 PAD[38];
  361. u32 oobaextwidth; /* 0x300 */
  362. u32 oobainwidth; /* 0x304 */
  363. u32 oobaoutwidth; /* 0x308 */
  364. u32 PAD[5];
  365. u32 oobbextwidth; /* 0x320 */
  366. u32 oobbinwidth; /* 0x324 */
  367. u32 oobboutwidth; /* 0x328 */
  368. u32 PAD[5];
  369. u32 oobcextwidth; /* 0x340 */
  370. u32 oobcinwidth; /* 0x344 */
  371. u32 oobcoutwidth; /* 0x348 */
  372. u32 PAD[5];
  373. u32 oobdextwidth; /* 0x360 */
  374. u32 oobdinwidth; /* 0x364 */
  375. u32 oobdoutwidth; /* 0x368 */
  376. u32 PAD[37];
  377. u32 ioctrlset; /* 0x400 */
  378. u32 ioctrlclear; /* 0x404 */
  379. u32 ioctrl; /* 0x408 */
  380. u32 PAD[61];
  381. u32 iostatus; /* 0x500 */
  382. u32 PAD[127];
  383. u32 ioctrlwidth; /* 0x700 */
  384. u32 iostatuswidth; /* 0x704 */
  385. u32 PAD[62];
  386. u32 resetctrl; /* 0x800 */
  387. u32 resetstatus; /* 0x804 */
  388. u32 resetreadid; /* 0x808 */
  389. u32 resetwriteid; /* 0x80c */
  390. u32 PAD[60];
  391. u32 errlogctrl; /* 0x900 */
  392. u32 errlogdone; /* 0x904 */
  393. u32 errlogstatus; /* 0x908 */
  394. u32 errlogaddrlo; /* 0x90c */
  395. u32 errlogaddrhi; /* 0x910 */
  396. u32 errlogid; /* 0x914 */
  397. u32 errloguser; /* 0x918 */
  398. u32 errlogflags; /* 0x91c */
  399. u32 PAD[56];
  400. u32 intstatus; /* 0xa00 */
  401. u32 PAD[127];
  402. u32 config; /* 0xe00 */
  403. u32 PAD[63];
  404. u32 itcr; /* 0xf00 */
  405. u32 PAD[3];
  406. u32 itipooba; /* 0xf10 */
  407. u32 itipoobb; /* 0xf14 */
  408. u32 itipoobc; /* 0xf18 */
  409. u32 itipoobd; /* 0xf1c */
  410. u32 PAD[4];
  411. u32 itipoobaout; /* 0xf30 */
  412. u32 itipoobbout; /* 0xf34 */
  413. u32 itipoobcout; /* 0xf38 */
  414. u32 itipoobdout; /* 0xf3c */
  415. u32 PAD[4];
  416. u32 itopooba; /* 0xf50 */
  417. u32 itopoobb; /* 0xf54 */
  418. u32 itopoobc; /* 0xf58 */
  419. u32 itopoobd; /* 0xf5c */
  420. u32 PAD[4];
  421. u32 itopoobain; /* 0xf70 */
  422. u32 itopoobbin; /* 0xf74 */
  423. u32 itopoobcin; /* 0xf78 */
  424. u32 itopoobdin; /* 0xf7c */
  425. u32 PAD[4];
  426. u32 itopreset; /* 0xf90 */
  427. u32 PAD[15];
  428. u32 peripherialid4; /* 0xfd0 */
  429. u32 peripherialid5; /* 0xfd4 */
  430. u32 peripherialid6; /* 0xfd8 */
  431. u32 peripherialid7; /* 0xfdc */
  432. u32 peripherialid0; /* 0xfe0 */
  433. u32 peripherialid1; /* 0xfe4 */
  434. u32 peripherialid2; /* 0xfe8 */
  435. u32 peripherialid3; /* 0xfec */
  436. u32 componentid0; /* 0xff0 */
  437. u32 componentid1; /* 0xff4 */
  438. u32 componentid2; /* 0xff8 */
  439. u32 componentid3; /* 0xffc */
  440. };
  441. /* parse the enumeration rom to identify all cores */
  442. static void ai_scan(struct si_pub *sih, struct bcma_bus *bus)
  443. {
  444. struct si_info *sii = (struct si_info *)sih;
  445. struct bcma_device *core;
  446. uint idx;
  447. list_for_each_entry(core, &bus->cores, list) {
  448. idx = core->core_index;
  449. sii->cia[idx] = core->id.manuf << CIA_MFG_SHIFT;
  450. sii->cia[idx] |= core->id.id << CIA_CID_SHIFT;
  451. sii->cia[idx] |= core->id.class << CIA_CCL_SHIFT;
  452. sii->cib[idx] = core->id.rev << CIB_REV_SHIFT;
  453. sii->coreid[idx] = core->id.id;
  454. sii->coresba[idx] = core->addr;
  455. sii->coresba_size[idx] = 0x1000;
  456. sii->coresba2[idx] = 0;
  457. sii->coresba2_size[idx] = 0;
  458. sii->wrapba[idx] = core->wrap;
  459. sii->numcores++;
  460. }
  461. }
  462. static struct bcma_device *ai_find_bcma_core(struct si_pub *sih, uint coreidx)
  463. {
  464. struct si_info *sii = (struct si_info *)sih;
  465. struct bcma_device *core;
  466. list_for_each_entry(core, &sii->icbus->cores, list) {
  467. if (core->core_index == coreidx)
  468. return core;
  469. }
  470. return NULL;
  471. }
  472. /*
  473. * This function changes the logical "focus" to the indicated core.
  474. * Return the current core's virtual address. Since each core starts with the
  475. * same set of registers (BIST, clock control, etc), the returned address
  476. * contains the first register of this 'common' register block (not to be
  477. * confused with 'common core').
  478. */
  479. void __iomem *ai_setcoreidx(struct si_pub *sih, uint coreidx)
  480. {
  481. struct si_info *sii = (struct si_info *)sih;
  482. struct bcma_device *core;
  483. if (sii->curidx != coreidx) {
  484. core = ai_find_bcma_core(sih, coreidx);
  485. if (core == NULL)
  486. return NULL;
  487. (void)bcma_aread32(core, BCMA_IOST);
  488. sii->curidx = coreidx;
  489. }
  490. return sii->curmap;
  491. }
  492. /* Return the number of address spaces in current core */
  493. int ai_numaddrspaces(struct si_pub *sih)
  494. {
  495. return 2;
  496. }
  497. /* Return the address of the nth address space in the current core */
  498. u32 ai_addrspace(struct si_pub *sih, uint asidx)
  499. {
  500. struct si_info *sii;
  501. uint cidx;
  502. sii = (struct si_info *)sih;
  503. cidx = sii->curidx;
  504. if (asidx == 0)
  505. return sii->coresba[cidx];
  506. else if (asidx == 1)
  507. return sii->coresba2[cidx];
  508. else {
  509. /* Need to parse the erom again to find addr space */
  510. return 0;
  511. }
  512. }
  513. /* Return the size of the nth address space in the current core */
  514. u32 ai_addrspacesize(struct si_pub *sih, uint asidx)
  515. {
  516. struct si_info *sii;
  517. uint cidx;
  518. sii = (struct si_info *)sih;
  519. cidx = sii->curidx;
  520. if (asidx == 0)
  521. return sii->coresba_size[cidx];
  522. else if (asidx == 1)
  523. return sii->coresba2_size[cidx];
  524. else {
  525. /* Need to parse the erom again to find addr */
  526. return 0;
  527. }
  528. }
  529. uint ai_flag(struct si_pub *sih)
  530. {
  531. struct si_info *sii;
  532. struct aidmp *ai;
  533. sii = (struct si_info *)sih;
  534. ai = sii->curwrap;
  535. return R_REG(&ai->oobselouta30) & 0x1f;
  536. }
  537. void ai_setint(struct si_pub *sih, int siflag)
  538. {
  539. }
  540. uint ai_corevendor(struct si_pub *sih)
  541. {
  542. struct si_info *sii;
  543. u32 cia;
  544. sii = (struct si_info *)sih;
  545. cia = sii->cia[sii->curidx];
  546. return (cia & CIA_MFG_MASK) >> CIA_MFG_SHIFT;
  547. }
  548. uint ai_corerev(struct si_pub *sih)
  549. {
  550. struct si_info *sii;
  551. u32 cib;
  552. sii = (struct si_info *)sih;
  553. cib = sii->cib[sii->curidx];
  554. return (cib & CIB_REV_MASK) >> CIB_REV_SHIFT;
  555. }
  556. bool ai_iscoreup(struct si_pub *sih)
  557. {
  558. struct si_info *sii;
  559. struct aidmp *ai;
  560. sii = (struct si_info *)sih;
  561. ai = sii->curwrap;
  562. return (((R_REG(&ai->ioctrl) & (SICF_FGC | SICF_CLOCK_EN)) ==
  563. SICF_CLOCK_EN)
  564. && ((R_REG(&ai->resetctrl) & AIRC_RESET) == 0));
  565. }
  566. void ai_core_cflags_wo(struct si_pub *sih, u32 mask, u32 val)
  567. {
  568. struct si_info *sii;
  569. struct aidmp *ai;
  570. u32 w;
  571. sii = (struct si_info *)sih;
  572. ai = sii->curwrap;
  573. if (mask || val) {
  574. w = ((R_REG(&ai->ioctrl) & ~mask) | val);
  575. W_REG(&ai->ioctrl, w);
  576. }
  577. }
  578. u32 ai_core_cflags(struct si_pub *sih, u32 mask, u32 val)
  579. {
  580. struct si_info *sii;
  581. struct aidmp *ai;
  582. u32 w;
  583. sii = (struct si_info *)sih;
  584. ai = sii->curwrap;
  585. if (mask || val) {
  586. w = ((R_REG(&ai->ioctrl) & ~mask) | val);
  587. W_REG(&ai->ioctrl, w);
  588. }
  589. return R_REG(&ai->ioctrl);
  590. }
  591. /* return true if PCIE capability exists in the pci config space */
  592. static bool ai_ispcie(struct si_info *sii)
  593. {
  594. u8 cap_ptr;
  595. cap_ptr =
  596. pcicore_find_pci_capability(sii->pcibus, PCI_CAP_ID_EXP, NULL,
  597. NULL);
  598. if (!cap_ptr)
  599. return false;
  600. return true;
  601. }
  602. static bool ai_buscore_prep(struct si_info *sii)
  603. {
  604. /* kludge to enable the clock on the 4306 which lacks a slowclock */
  605. if (!ai_ispcie(sii))
  606. ai_clkctl_xtal(&sii->pub, XTAL | PLL, ON);
  607. return true;
  608. }
  609. u32 ai_core_sflags(struct si_pub *sih, u32 mask, u32 val)
  610. {
  611. struct si_info *sii;
  612. struct aidmp *ai;
  613. u32 w;
  614. sii = (struct si_info *)sih;
  615. ai = sii->curwrap;
  616. if (mask || val) {
  617. w = ((R_REG(&ai->iostatus) & ~mask) | val);
  618. W_REG(&ai->iostatus, w);
  619. }
  620. return R_REG(&ai->iostatus);
  621. }
  622. static bool
  623. ai_buscore_setup(struct si_info *sii, u32 savewin, uint *origidx)
  624. {
  625. bool pci, pcie;
  626. uint i;
  627. uint pciidx, pcieidx, pcirev, pcierev;
  628. struct chipcregs __iomem *cc;
  629. cc = ai_setcoreidx(&sii->pub, SI_CC_IDX);
  630. /* get chipcommon rev */
  631. sii->pub.ccrev = (int)ai_corerev(&sii->pub);
  632. /* get chipcommon chipstatus */
  633. if (ai_get_ccrev(&sii->pub) >= 11)
  634. sii->chipst = R_REG(&cc->chipstatus);
  635. /* get chipcommon capabilites */
  636. sii->pub.cccaps = R_REG(&cc->capabilities);
  637. /* get pmu rev and caps */
  638. if (ai_get_cccaps(&sii->pub) & CC_CAP_PMU) {
  639. sii->pub.pmucaps = R_REG(&cc->pmucapabilities);
  640. sii->pub.pmurev = sii->pub.pmucaps & PCAP_REV_MASK;
  641. }
  642. /* figure out bus/orignal core idx */
  643. sii->pub.buscoretype = NODEV_CORE_ID;
  644. sii->pub.buscorerev = NOREV;
  645. sii->buscoreidx = BADIDX;
  646. pci = pcie = false;
  647. pcirev = pcierev = NOREV;
  648. pciidx = pcieidx = BADIDX;
  649. for (i = 0; i < sii->numcores; i++) {
  650. uint cid, crev;
  651. ai_setcoreidx(&sii->pub, i);
  652. cid = ai_coreid(&sii->pub);
  653. crev = ai_corerev(&sii->pub);
  654. if (cid == PCI_CORE_ID) {
  655. pciidx = i;
  656. pcirev = crev;
  657. pci = true;
  658. } else if (cid == PCIE_CORE_ID) {
  659. pcieidx = i;
  660. pcierev = crev;
  661. pcie = true;
  662. }
  663. /* find the core idx before entering this func. */
  664. if ((savewin && (savewin == sii->coresba[i])) ||
  665. (cc == sii->regs[i]))
  666. *origidx = i;
  667. }
  668. if (pci && pcie) {
  669. if (ai_ispcie(sii))
  670. pci = false;
  671. else
  672. pcie = false;
  673. }
  674. if (pci) {
  675. sii->pub.buscoretype = PCI_CORE_ID;
  676. sii->pub.buscorerev = pcirev;
  677. sii->buscoreidx = pciidx;
  678. } else if (pcie) {
  679. sii->pub.buscoretype = PCIE_CORE_ID;
  680. sii->pub.buscorerev = pcierev;
  681. sii->buscoreidx = pcieidx;
  682. }
  683. /* fixup necessary chip/core configurations */
  684. if (SI_FAST(&sii->pub)) {
  685. if (!sii->pch) {
  686. sii->pch = pcicore_init(&sii->pub, sii->pcibus,
  687. (__iomem void *)PCIEREGS(sii));
  688. if (sii->pch == NULL)
  689. return false;
  690. }
  691. }
  692. if (ai_pci_fixcfg(&sii->pub)) {
  693. /* si_doattach: si_pci_fixcfg failed */
  694. return false;
  695. }
  696. /* return to the original core */
  697. ai_setcoreidx(&sii->pub, *origidx);
  698. return true;
  699. }
  700. /*
  701. * get boardtype and boardrev
  702. */
  703. static __used void ai_nvram_process(struct si_info *sii)
  704. {
  705. uint w = 0;
  706. /* do a pci config read to get subsystem id and subvendor id */
  707. pci_read_config_dword(sii->pcibus, PCI_SUBSYSTEM_VENDOR_ID, &w);
  708. sii->pub.boardvendor = w & 0xffff;
  709. sii->pub.boardtype = (w >> 16) & 0xffff;
  710. }
  711. static struct si_info *ai_doattach(struct si_info *sii,
  712. struct bcma_bus *pbus)
  713. {
  714. void __iomem *regs = pbus->mmio;
  715. struct si_pub *sih = &sii->pub;
  716. u32 w, savewin;
  717. struct chipcregs __iomem *cc;
  718. uint socitype;
  719. uint origidx;
  720. memset((unsigned char *) sii, 0, sizeof(struct si_info));
  721. savewin = 0;
  722. sii->icbus = pbus;
  723. sii->buscoreidx = BADIDX;
  724. sii->pcibus = pbus->host_pci;
  725. sii->curmap = regs;
  726. sii->curwrap = sii->curmap + SI_CORE_SIZE;
  727. /* switch to Chipcommon core */
  728. bcma_read32(pbus->drv_cc.core, 0);
  729. savewin = SI_ENUM_BASE;
  730. cc = (struct chipcregs __iomem *) regs;
  731. /* bus/core/clk setup for register access */
  732. if (!ai_buscore_prep(sii))
  733. return NULL;
  734. /*
  735. * ChipID recognition.
  736. * We assume we can read chipid at offset 0 from the regs arg.
  737. * If we add other chiptypes (or if we need to support old sdio
  738. * hosts w/o chipcommon), some way of recognizing them needs to
  739. * be added here.
  740. */
  741. w = R_REG(&cc->chipid);
  742. socitype = (w & CID_TYPE_MASK) >> CID_TYPE_SHIFT;
  743. /* Might as wll fill in chip id rev & pkg */
  744. sih->chip = w & CID_ID_MASK;
  745. sih->chiprev = (w & CID_REV_MASK) >> CID_REV_SHIFT;
  746. sih->chippkg = (w & CID_PKG_MASK) >> CID_PKG_SHIFT;
  747. /* scan for cores */
  748. if (socitype == SOCI_AI) {
  749. SI_MSG("Found chip type AI (0x%08x)\n", w);
  750. /* pass chipc address instead of original core base */
  751. ai_scan(&sii->pub, pbus);
  752. } else {
  753. /* Found chip of unknown type */
  754. return NULL;
  755. }
  756. /* no cores found, bail out */
  757. if (sii->numcores == 0)
  758. return NULL;
  759. /* bus/core/clk setup */
  760. origidx = SI_CC_IDX;
  761. if (!ai_buscore_setup(sii, savewin, &origidx))
  762. goto exit;
  763. /* Init nvram from sprom/otp if they exist */
  764. if (srom_var_init(&sii->pub, cc))
  765. goto exit;
  766. ai_nvram_process(sii);
  767. /* === NVRAM, clock is ready === */
  768. cc = (struct chipcregs __iomem *) ai_setcore(sih, CC_CORE_ID, 0);
  769. W_REG(&cc->gpiopullup, 0);
  770. W_REG(&cc->gpiopulldown, 0);
  771. ai_setcoreidx(sih, origidx);
  772. /* PMU specific initializations */
  773. if (ai_get_cccaps(sih) & CC_CAP_PMU) {
  774. u32 xtalfreq;
  775. si_pmu_init(sih);
  776. si_pmu_chip_init(sih);
  777. xtalfreq = si_pmu_measure_alpclk(sih);
  778. si_pmu_pll_init(sih, xtalfreq);
  779. si_pmu_res_init(sih);
  780. si_pmu_swreg_init(sih);
  781. }
  782. /* setup the GPIO based LED powersave register */
  783. w = getintvar(sih, BRCMS_SROM_LEDDC);
  784. if (w == 0)
  785. w = DEFAULT_GPIOTIMERVAL;
  786. ai_corereg(sih, SI_CC_IDX, offsetof(struct chipcregs, gpiotimerval),
  787. ~0, w);
  788. if (PCIE(sih))
  789. pcicore_attach(sii->pch, SI_DOATTACH);
  790. if (ai_get_chip_id(sih) == BCM43224_CHIP_ID) {
  791. /*
  792. * enable 12 mA drive strenth for 43224 and
  793. * set chipControl register bit 15
  794. */
  795. if (ai_get_chiprev(sih) == 0) {
  796. SI_MSG("Applying 43224A0 WARs\n");
  797. ai_corereg(sih, SI_CC_IDX,
  798. offsetof(struct chipcregs, chipcontrol),
  799. CCTRL43224_GPIO_TOGGLE,
  800. CCTRL43224_GPIO_TOGGLE);
  801. si_pmu_chipcontrol(sih, 0, CCTRL_43224A0_12MA_LED_DRIVE,
  802. CCTRL_43224A0_12MA_LED_DRIVE);
  803. }
  804. if (ai_get_chiprev(sih) >= 1) {
  805. SI_MSG("Applying 43224B0+ WARs\n");
  806. si_pmu_chipcontrol(sih, 0, CCTRL_43224B0_12MA_LED_DRIVE,
  807. CCTRL_43224B0_12MA_LED_DRIVE);
  808. }
  809. }
  810. if (ai_get_chip_id(sih) == BCM4313_CHIP_ID) {
  811. /*
  812. * enable 12 mA drive strenth for 4313 and
  813. * set chipControl register bit 1
  814. */
  815. SI_MSG("Applying 4313 WARs\n");
  816. si_pmu_chipcontrol(sih, 0, CCTRL_4313_12MA_LED_DRIVE,
  817. CCTRL_4313_12MA_LED_DRIVE);
  818. }
  819. return sii;
  820. exit:
  821. if (sii->pch)
  822. pcicore_deinit(sii->pch);
  823. sii->pch = NULL;
  824. return NULL;
  825. }
  826. /*
  827. * Allocate a si handle and do the attach.
  828. */
  829. struct si_pub *
  830. ai_attach(struct bcma_bus *pbus)
  831. {
  832. struct si_info *sii;
  833. /* alloc struct si_info */
  834. sii = kmalloc(sizeof(struct si_info), GFP_ATOMIC);
  835. if (sii == NULL)
  836. return NULL;
  837. if (ai_doattach(sii, pbus) == NULL) {
  838. kfree(sii);
  839. return NULL;
  840. }
  841. return (struct si_pub *) sii;
  842. }
  843. /* may be called with core in reset */
  844. void ai_detach(struct si_pub *sih)
  845. {
  846. struct si_info *sii;
  847. struct si_pub *si_local = NULL;
  848. memcpy(&si_local, &sih, sizeof(struct si_pub **));
  849. sii = (struct si_info *)sih;
  850. if (sii == NULL)
  851. return;
  852. if (sii->pch)
  853. pcicore_deinit(sii->pch);
  854. sii->pch = NULL;
  855. srom_free_vars(sih);
  856. kfree(sii);
  857. }
  858. /* register driver interrupt disabling and restoring callback functions */
  859. void
  860. ai_register_intr_callback(struct si_pub *sih, void *intrsoff_fn,
  861. void *intrsrestore_fn,
  862. void *intrsenabled_fn, void *intr_arg)
  863. {
  864. struct si_info *sii;
  865. sii = (struct si_info *)sih;
  866. sii->intr_arg = intr_arg;
  867. sii->intrsoff_fn = (u32 (*)(void *)) intrsoff_fn;
  868. sii->intrsrestore_fn = (void (*) (void *, u32)) intrsrestore_fn;
  869. sii->intrsenabled_fn = (bool (*)(void *)) intrsenabled_fn;
  870. /* save current core id. when this function called, the current core
  871. * must be the core which provides driver functions(il, et, wl, etc.)
  872. */
  873. sii->dev_coreid = sii->coreid[sii->curidx];
  874. }
  875. void ai_deregister_intr_callback(struct si_pub *sih)
  876. {
  877. struct si_info *sii;
  878. sii = (struct si_info *)sih;
  879. sii->intrsoff_fn = NULL;
  880. }
  881. uint ai_coreid(struct si_pub *sih)
  882. {
  883. struct si_info *sii;
  884. sii = (struct si_info *)sih;
  885. return sii->coreid[sii->curidx];
  886. }
  887. uint ai_coreidx(struct si_pub *sih)
  888. {
  889. struct si_info *sii;
  890. sii = (struct si_info *)sih;
  891. return sii->curidx;
  892. }
  893. bool ai_backplane64(struct si_pub *sih)
  894. {
  895. return (ai_get_cccaps(sih) & CC_CAP_BKPLN64) != 0;
  896. }
  897. /* return index of coreid or BADIDX if not found */
  898. uint ai_findcoreidx(struct si_pub *sih, uint coreid, uint coreunit)
  899. {
  900. struct bcma_device *core;
  901. struct si_info *sii;
  902. uint found;
  903. sii = (struct si_info *)sih;
  904. found = 0;
  905. list_for_each_entry(core, &sii->icbus->cores, list)
  906. if (core->id.id == coreid) {
  907. if (found == coreunit)
  908. return core->core_index;
  909. found++;
  910. }
  911. return BADIDX;
  912. }
  913. /*
  914. * This function changes logical "focus" to the indicated core;
  915. * must be called with interrupts off.
  916. * Moreover, callers should keep interrupts off during switching
  917. * out of and back to d11 core.
  918. */
  919. void __iomem *ai_setcore(struct si_pub *sih, uint coreid, uint coreunit)
  920. {
  921. uint idx;
  922. idx = ai_findcoreidx(sih, coreid, coreunit);
  923. if (idx >= SI_MAXCORES)
  924. return NULL;
  925. return ai_setcoreidx(sih, idx);
  926. }
  927. /* Turn off interrupt as required by ai_setcore, before switch core */
  928. void __iomem *ai_switch_core(struct si_pub *sih, uint coreid, uint *origidx,
  929. uint *intr_val)
  930. {
  931. void __iomem *cc;
  932. struct si_info *sii;
  933. sii = (struct si_info *)sih;
  934. if (SI_FAST(sih)) {
  935. /* Overloading the origidx variable to remember the coreid,
  936. * this works because the core ids cannot be confused with
  937. * core indices.
  938. */
  939. *origidx = coreid;
  940. if (coreid == CC_CORE_ID)
  941. return CCREGS_FAST(sii);
  942. else if (coreid == ai_get_buscoretype(sih))
  943. return PCIEREGS(sii);
  944. }
  945. INTR_OFF(sii, *intr_val);
  946. *origidx = sii->curidx;
  947. cc = ai_setcore(sih, coreid, 0);
  948. return cc;
  949. }
  950. /* restore coreidx and restore interrupt */
  951. void ai_restore_core(struct si_pub *sih, uint coreid, uint intr_val)
  952. {
  953. struct si_info *sii;
  954. sii = (struct si_info *)sih;
  955. if (SI_FAST(sih)
  956. && ((coreid == CC_CORE_ID) || (coreid == ai_get_buscoretype(sih))))
  957. return;
  958. ai_setcoreidx(sih, coreid);
  959. INTR_RESTORE(sii, intr_val);
  960. }
  961. void ai_write_wrapperreg(struct si_pub *sih, u32 offset, u32 val)
  962. {
  963. struct si_info *sii = (struct si_info *)sih;
  964. u32 *w = (u32 *) sii->curwrap;
  965. W_REG(w + (offset / 4), val);
  966. return;
  967. }
  968. /*
  969. * Switch to 'coreidx', issue a single arbitrary 32bit register mask&set
  970. * operation, switch back to the original core, and return the new value.
  971. *
  972. * When using the silicon backplane, no fiddling with interrupts or core
  973. * switches is needed.
  974. *
  975. * Also, when using pci/pcie, we can optimize away the core switching for pci
  976. * registers and (on newer pci cores) chipcommon registers.
  977. */
  978. uint ai_corereg(struct si_pub *sih, uint coreidx, uint regoff, uint mask,
  979. uint val)
  980. {
  981. uint origidx = 0;
  982. u32 __iomem *r = NULL;
  983. uint w;
  984. uint intr_val = 0;
  985. bool fast = false;
  986. struct si_info *sii;
  987. sii = (struct si_info *)sih;
  988. if (coreidx >= SI_MAXCORES)
  989. return 0;
  990. /*
  991. * If pci/pcie, we can get at pci/pcie regs
  992. * and on newer cores to chipc
  993. */
  994. if ((sii->coreid[coreidx] == CC_CORE_ID) && SI_FAST(sih)) {
  995. /* Chipc registers are mapped at 12KB */
  996. fast = true;
  997. r = (u32 __iomem *)((__iomem char *)sii->curmap +
  998. PCI_16KB0_CCREGS_OFFSET + regoff);
  999. } else if (sii->buscoreidx == coreidx) {
  1000. /*
  1001. * pci registers are at either in the last 2KB of
  1002. * an 8KB window or, in pcie and pci rev 13 at 8KB
  1003. */
  1004. fast = true;
  1005. if (SI_FAST(sih))
  1006. r = (u32 __iomem *)((__iomem char *)sii->curmap +
  1007. PCI_16KB0_PCIREGS_OFFSET + regoff);
  1008. else
  1009. r = (u32 __iomem *)((__iomem char *)sii->curmap +
  1010. ((regoff >= SBCONFIGOFF) ?
  1011. PCI_BAR0_PCISBR_OFFSET :
  1012. PCI_BAR0_PCIREGS_OFFSET) + regoff);
  1013. }
  1014. if (!fast) {
  1015. INTR_OFF(sii, intr_val);
  1016. /* save current core index */
  1017. origidx = ai_coreidx(&sii->pub);
  1018. /* switch core */
  1019. r = (u32 __iomem *) ((unsigned char __iomem *)
  1020. ai_setcoreidx(&sii->pub, coreidx) + regoff);
  1021. }
  1022. /* mask and set */
  1023. if (mask || val) {
  1024. w = (R_REG(r) & ~mask) | val;
  1025. W_REG(r, w);
  1026. }
  1027. /* readback */
  1028. w = R_REG(r);
  1029. if (!fast) {
  1030. /* restore core index */
  1031. if (origidx != coreidx)
  1032. ai_setcoreidx(&sii->pub, origidx);
  1033. INTR_RESTORE(sii, intr_val);
  1034. }
  1035. return w;
  1036. }
  1037. void ai_core_disable(struct si_pub *sih, u32 bits)
  1038. {
  1039. struct si_info *sii;
  1040. u32 dummy;
  1041. struct aidmp *ai;
  1042. sii = (struct si_info *)sih;
  1043. ai = sii->curwrap;
  1044. /* if core is already in reset, just return */
  1045. if (R_REG(&ai->resetctrl) & AIRC_RESET)
  1046. return;
  1047. W_REG(&ai->ioctrl, bits);
  1048. dummy = R_REG(&ai->ioctrl);
  1049. udelay(10);
  1050. W_REG(&ai->resetctrl, AIRC_RESET);
  1051. udelay(1);
  1052. }
  1053. /* reset and re-enable a core
  1054. * inputs:
  1055. * bits - core specific bits that are set during and after reset sequence
  1056. * resetbits - core specific bits that are set only during reset sequence
  1057. */
  1058. void ai_core_reset(struct si_pub *sih, u32 bits, u32 resetbits)
  1059. {
  1060. struct si_info *sii;
  1061. struct aidmp *ai;
  1062. u32 dummy;
  1063. sii = (struct si_info *)sih;
  1064. ai = sii->curwrap;
  1065. /*
  1066. * Must do the disable sequence first to work
  1067. * for arbitrary current core state.
  1068. */
  1069. ai_core_disable(sih, (bits | resetbits));
  1070. /*
  1071. * Now do the initialization sequence.
  1072. */
  1073. W_REG(&ai->ioctrl, (bits | SICF_FGC | SICF_CLOCK_EN));
  1074. dummy = R_REG(&ai->ioctrl);
  1075. W_REG(&ai->resetctrl, 0);
  1076. udelay(1);
  1077. W_REG(&ai->ioctrl, (bits | SICF_CLOCK_EN));
  1078. dummy = R_REG(&ai->ioctrl);
  1079. udelay(1);
  1080. }
  1081. /* return the slow clock source - LPO, XTAL, or PCI */
  1082. static uint ai_slowclk_src(struct si_info *sii)
  1083. {
  1084. struct chipcregs __iomem *cc;
  1085. u32 val;
  1086. if (ai_get_ccrev(&sii->pub) < 6) {
  1087. pci_read_config_dword(sii->pcibus, PCI_GPIO_OUT,
  1088. &val);
  1089. if (val & PCI_CFG_GPIO_SCS)
  1090. return SCC_SS_PCI;
  1091. return SCC_SS_XTAL;
  1092. } else if (ai_get_ccrev(&sii->pub) < 10) {
  1093. cc = (struct chipcregs __iomem *)
  1094. ai_setcoreidx(&sii->pub, sii->curidx);
  1095. return R_REG(&cc->slow_clk_ctl) & SCC_SS_MASK;
  1096. } else /* Insta-clock */
  1097. return SCC_SS_XTAL;
  1098. }
  1099. /*
  1100. * return the ILP (slowclock) min or max frequency
  1101. * precondition: we've established the chip has dynamic clk control
  1102. */
  1103. static uint ai_slowclk_freq(struct si_info *sii, bool max_freq,
  1104. struct chipcregs __iomem *cc)
  1105. {
  1106. u32 slowclk;
  1107. uint div;
  1108. slowclk = ai_slowclk_src(sii);
  1109. if (ai_get_ccrev(&sii->pub) < 6) {
  1110. if (slowclk == SCC_SS_PCI)
  1111. return max_freq ? (PCIMAXFREQ / 64)
  1112. : (PCIMINFREQ / 64);
  1113. else
  1114. return max_freq ? (XTALMAXFREQ / 32)
  1115. : (XTALMINFREQ / 32);
  1116. } else if (ai_get_ccrev(&sii->pub) < 10) {
  1117. div = 4 *
  1118. (((R_REG(&cc->slow_clk_ctl) & SCC_CD_MASK) >>
  1119. SCC_CD_SHIFT) + 1);
  1120. if (slowclk == SCC_SS_LPO)
  1121. return max_freq ? LPOMAXFREQ : LPOMINFREQ;
  1122. else if (slowclk == SCC_SS_XTAL)
  1123. return max_freq ? (XTALMAXFREQ / div)
  1124. : (XTALMINFREQ / div);
  1125. else if (slowclk == SCC_SS_PCI)
  1126. return max_freq ? (PCIMAXFREQ / div)
  1127. : (PCIMINFREQ / div);
  1128. } else {
  1129. /* Chipc rev 10 is InstaClock */
  1130. div = R_REG(&cc->system_clk_ctl) >> SYCC_CD_SHIFT;
  1131. div = 4 * (div + 1);
  1132. return max_freq ? XTALMAXFREQ : (XTALMINFREQ / div);
  1133. }
  1134. return 0;
  1135. }
  1136. static void
  1137. ai_clkctl_setdelay(struct si_info *sii, struct chipcregs __iomem *cc)
  1138. {
  1139. uint slowmaxfreq, pll_delay, slowclk;
  1140. uint pll_on_delay, fref_sel_delay;
  1141. pll_delay = PLL_DELAY;
  1142. /*
  1143. * If the slow clock is not sourced by the xtal then
  1144. * add the xtal_on_delay since the xtal will also be
  1145. * powered down by dynamic clk control logic.
  1146. */
  1147. slowclk = ai_slowclk_src(sii);
  1148. if (slowclk != SCC_SS_XTAL)
  1149. pll_delay += XTAL_ON_DELAY;
  1150. /* Starting with 4318 it is ILP that is used for the delays */
  1151. slowmaxfreq =
  1152. ai_slowclk_freq(sii,
  1153. (ai_get_ccrev(&sii->pub) >= 10) ? false : true, cc);
  1154. pll_on_delay = ((slowmaxfreq * pll_delay) + 999999) / 1000000;
  1155. fref_sel_delay = ((slowmaxfreq * FREF_DELAY) + 999999) / 1000000;
  1156. W_REG(&cc->pll_on_delay, pll_on_delay);
  1157. W_REG(&cc->fref_sel_delay, fref_sel_delay);
  1158. }
  1159. /* initialize power control delay registers */
  1160. void ai_clkctl_init(struct si_pub *sih)
  1161. {
  1162. struct si_info *sii;
  1163. uint origidx = 0;
  1164. struct chipcregs __iomem *cc;
  1165. bool fast;
  1166. if (!(ai_get_cccaps(sih) & CC_CAP_PWR_CTL))
  1167. return;
  1168. sii = (struct si_info *)sih;
  1169. fast = SI_FAST(sih);
  1170. if (!fast) {
  1171. origidx = sii->curidx;
  1172. cc = (struct chipcregs __iomem *)
  1173. ai_setcore(sih, CC_CORE_ID, 0);
  1174. if (cc == NULL)
  1175. return;
  1176. } else {
  1177. cc = (struct chipcregs __iomem *) CCREGS_FAST(sii);
  1178. if (cc == NULL)
  1179. return;
  1180. }
  1181. /* set all Instaclk chip ILP to 1 MHz */
  1182. if (ai_get_ccrev(sih) >= 10)
  1183. SET_REG(&cc->system_clk_ctl, SYCC_CD_MASK,
  1184. (ILP_DIV_1MHZ << SYCC_CD_SHIFT));
  1185. ai_clkctl_setdelay(sii, cc);
  1186. if (!fast)
  1187. ai_setcoreidx(sih, origidx);
  1188. }
  1189. /*
  1190. * return the value suitable for writing to the
  1191. * dot11 core FAST_PWRUP_DELAY register
  1192. */
  1193. u16 ai_clkctl_fast_pwrup_delay(struct si_pub *sih)
  1194. {
  1195. struct si_info *sii;
  1196. uint origidx = 0;
  1197. struct chipcregs __iomem *cc;
  1198. uint slowminfreq;
  1199. u16 fpdelay;
  1200. uint intr_val = 0;
  1201. bool fast;
  1202. sii = (struct si_info *)sih;
  1203. if (ai_get_cccaps(sih) & CC_CAP_PMU) {
  1204. INTR_OFF(sii, intr_val);
  1205. fpdelay = si_pmu_fast_pwrup_delay(sih);
  1206. INTR_RESTORE(sii, intr_val);
  1207. return fpdelay;
  1208. }
  1209. if (!(ai_get_cccaps(sih) & CC_CAP_PWR_CTL))
  1210. return 0;
  1211. fast = SI_FAST(sih);
  1212. fpdelay = 0;
  1213. if (!fast) {
  1214. origidx = sii->curidx;
  1215. INTR_OFF(sii, intr_val);
  1216. cc = (struct chipcregs __iomem *)
  1217. ai_setcore(sih, CC_CORE_ID, 0);
  1218. if (cc == NULL)
  1219. goto done;
  1220. } else {
  1221. cc = (struct chipcregs __iomem *) CCREGS_FAST(sii);
  1222. if (cc == NULL)
  1223. goto done;
  1224. }
  1225. slowminfreq = ai_slowclk_freq(sii, false, cc);
  1226. fpdelay = (((R_REG(&cc->pll_on_delay) + 2) * 1000000) +
  1227. (slowminfreq - 1)) / slowminfreq;
  1228. done:
  1229. if (!fast) {
  1230. ai_setcoreidx(sih, origidx);
  1231. INTR_RESTORE(sii, intr_val);
  1232. }
  1233. return fpdelay;
  1234. }
  1235. /* turn primary xtal and/or pll off/on */
  1236. int ai_clkctl_xtal(struct si_pub *sih, uint what, bool on)
  1237. {
  1238. struct si_info *sii;
  1239. u32 in, out, outen;
  1240. sii = (struct si_info *)sih;
  1241. /* pcie core doesn't have any mapping to control the xtal pu */
  1242. if (PCIE(sih))
  1243. return -1;
  1244. pci_read_config_dword(sii->pcibus, PCI_GPIO_IN, &in);
  1245. pci_read_config_dword(sii->pcibus, PCI_GPIO_OUT, &out);
  1246. pci_read_config_dword(sii->pcibus, PCI_GPIO_OUTEN, &outen);
  1247. /*
  1248. * Avoid glitching the clock if GPRS is already using it.
  1249. * We can't actually read the state of the PLLPD so we infer it
  1250. * by the value of XTAL_PU which *is* readable via gpioin.
  1251. */
  1252. if (on && (in & PCI_CFG_GPIO_XTAL))
  1253. return 0;
  1254. if (what & XTAL)
  1255. outen |= PCI_CFG_GPIO_XTAL;
  1256. if (what & PLL)
  1257. outen |= PCI_CFG_GPIO_PLL;
  1258. if (on) {
  1259. /* turn primary xtal on */
  1260. if (what & XTAL) {
  1261. out |= PCI_CFG_GPIO_XTAL;
  1262. if (what & PLL)
  1263. out |= PCI_CFG_GPIO_PLL;
  1264. pci_write_config_dword(sii->pcibus,
  1265. PCI_GPIO_OUT, out);
  1266. pci_write_config_dword(sii->pcibus,
  1267. PCI_GPIO_OUTEN, outen);
  1268. udelay(XTAL_ON_DELAY);
  1269. }
  1270. /* turn pll on */
  1271. if (what & PLL) {
  1272. out &= ~PCI_CFG_GPIO_PLL;
  1273. pci_write_config_dword(sii->pcibus,
  1274. PCI_GPIO_OUT, out);
  1275. mdelay(2);
  1276. }
  1277. } else {
  1278. if (what & XTAL)
  1279. out &= ~PCI_CFG_GPIO_XTAL;
  1280. if (what & PLL)
  1281. out |= PCI_CFG_GPIO_PLL;
  1282. pci_write_config_dword(sii->pcibus,
  1283. PCI_GPIO_OUT, out);
  1284. pci_write_config_dword(sii->pcibus,
  1285. PCI_GPIO_OUTEN, outen);
  1286. }
  1287. return 0;
  1288. }
  1289. /* clk control mechanism through chipcommon, no policy checking */
  1290. static bool _ai_clkctl_cc(struct si_info *sii, uint mode)
  1291. {
  1292. uint origidx = 0;
  1293. struct chipcregs __iomem *cc;
  1294. u32 scc;
  1295. uint intr_val = 0;
  1296. bool fast = SI_FAST(&sii->pub);
  1297. /* chipcommon cores prior to rev6 don't support dynamic clock control */
  1298. if (ai_get_ccrev(&sii->pub) < 6)
  1299. return false;
  1300. if (!fast) {
  1301. INTR_OFF(sii, intr_val);
  1302. origidx = sii->curidx;
  1303. cc = (struct chipcregs __iomem *)
  1304. ai_setcore(&sii->pub, CC_CORE_ID, 0);
  1305. } else {
  1306. cc = (struct chipcregs __iomem *) CCREGS_FAST(sii);
  1307. if (cc == NULL)
  1308. goto done;
  1309. }
  1310. if (!(ai_get_cccaps(&sii->pub) & CC_CAP_PWR_CTL) &&
  1311. (ai_get_ccrev(&sii->pub) < 20))
  1312. goto done;
  1313. switch (mode) {
  1314. case CLK_FAST: /* FORCEHT, fast (pll) clock */
  1315. if (ai_get_ccrev(&sii->pub) < 10) {
  1316. /*
  1317. * don't forget to force xtal back
  1318. * on before we clear SCC_DYN_XTAL..
  1319. */
  1320. ai_clkctl_xtal(&sii->pub, XTAL, ON);
  1321. SET_REG(&cc->slow_clk_ctl,
  1322. (SCC_XC | SCC_FS | SCC_IP), SCC_IP);
  1323. } else if (ai_get_ccrev(&sii->pub) < 20) {
  1324. OR_REG(&cc->system_clk_ctl, SYCC_HR);
  1325. } else {
  1326. OR_REG(&cc->clk_ctl_st, CCS_FORCEHT);
  1327. }
  1328. /* wait for the PLL */
  1329. if (ai_get_cccaps(&sii->pub) & CC_CAP_PMU) {
  1330. u32 htavail = CCS_HTAVAIL;
  1331. SPINWAIT(((R_REG(&cc->clk_ctl_st) & htavail)
  1332. == 0), PMU_MAX_TRANSITION_DLY);
  1333. } else {
  1334. udelay(PLL_DELAY);
  1335. }
  1336. break;
  1337. case CLK_DYNAMIC: /* enable dynamic clock control */
  1338. if (ai_get_ccrev(&sii->pub) < 10) {
  1339. scc = R_REG(&cc->slow_clk_ctl);
  1340. scc &= ~(SCC_FS | SCC_IP | SCC_XC);
  1341. if ((scc & SCC_SS_MASK) != SCC_SS_XTAL)
  1342. scc |= SCC_XC;
  1343. W_REG(&cc->slow_clk_ctl, scc);
  1344. /*
  1345. * for dynamic control, we have to
  1346. * release our xtal_pu "force on"
  1347. */
  1348. if (scc & SCC_XC)
  1349. ai_clkctl_xtal(&sii->pub, XTAL, OFF);
  1350. } else if (ai_get_ccrev(&sii->pub) < 20) {
  1351. /* Instaclock */
  1352. AND_REG(&cc->system_clk_ctl, ~SYCC_HR);
  1353. } else {
  1354. AND_REG(&cc->clk_ctl_st, ~CCS_FORCEHT);
  1355. }
  1356. break;
  1357. default:
  1358. break;
  1359. }
  1360. done:
  1361. if (!fast) {
  1362. ai_setcoreidx(&sii->pub, origidx);
  1363. INTR_RESTORE(sii, intr_val);
  1364. }
  1365. return mode == CLK_FAST;
  1366. }
  1367. /*
  1368. * clock control policy function throught chipcommon
  1369. *
  1370. * set dynamic clk control mode (forceslow, forcefast, dynamic)
  1371. * returns true if we are forcing fast clock
  1372. * this is a wrapper over the next internal function
  1373. * to allow flexible policy settings for outside caller
  1374. */
  1375. bool ai_clkctl_cc(struct si_pub *sih, uint mode)
  1376. {
  1377. struct si_info *sii;
  1378. sii = (struct si_info *)sih;
  1379. /* chipcommon cores prior to rev6 don't support dynamic clock control */
  1380. if (ai_get_ccrev(sih) < 6)
  1381. return false;
  1382. if (PCI_FORCEHT(sih))
  1383. return mode == CLK_FAST;
  1384. return _ai_clkctl_cc(sii, mode);
  1385. }
  1386. /* Build device path */
  1387. int ai_devpath(struct si_pub *sih, char *path, int size)
  1388. {
  1389. int slen;
  1390. if (!path || size <= 0)
  1391. return -1;
  1392. slen = snprintf(path, (size_t) size, "pci/%u/%u/",
  1393. ((struct si_info *)sih)->pcibus->bus->number,
  1394. PCI_SLOT(((struct pci_dev *)
  1395. (((struct si_info *)(sih))->pcibus))->devfn));
  1396. if (slen < 0 || slen >= size) {
  1397. path[0] = '\0';
  1398. return -1;
  1399. }
  1400. return 0;
  1401. }
  1402. void ai_pci_up(struct si_pub *sih)
  1403. {
  1404. struct si_info *sii;
  1405. sii = (struct si_info *)sih;
  1406. if (PCI_FORCEHT(sih))
  1407. _ai_clkctl_cc(sii, CLK_FAST);
  1408. if (PCIE(sih))
  1409. pcicore_up(sii->pch, SI_PCIUP);
  1410. }
  1411. /* Unconfigure and/or apply various WARs when system is going to sleep mode */
  1412. void ai_pci_sleep(struct si_pub *sih)
  1413. {
  1414. struct si_info *sii;
  1415. sii = (struct si_info *)sih;
  1416. pcicore_sleep(sii->pch);
  1417. }
  1418. /* Unconfigure and/or apply various WARs when going down */
  1419. void ai_pci_down(struct si_pub *sih)
  1420. {
  1421. struct si_info *sii;
  1422. sii = (struct si_info *)sih;
  1423. /* release FORCEHT since chip is going to "down" state */
  1424. if (PCI_FORCEHT(sih))
  1425. _ai_clkctl_cc(sii, CLK_DYNAMIC);
  1426. pcicore_down(sii->pch, SI_PCIDOWN);
  1427. }
  1428. /*
  1429. * Configure the pci core for pci client (NIC) action
  1430. * coremask is the bitvec of cores by index to be enabled.
  1431. */
  1432. void ai_pci_setup(struct si_pub *sih, uint coremask)
  1433. {
  1434. struct si_info *sii;
  1435. struct sbpciregs __iomem *regs = NULL;
  1436. u32 siflag = 0, w;
  1437. uint idx = 0;
  1438. sii = (struct si_info *)sih;
  1439. if (PCI(sih)) {
  1440. /* get current core index */
  1441. idx = sii->curidx;
  1442. /* we interrupt on this backplane flag number */
  1443. siflag = ai_flag(sih);
  1444. /* switch over to pci core */
  1445. regs = ai_setcoreidx(sih, sii->buscoreidx);
  1446. }
  1447. /*
  1448. * Enable sb->pci interrupts. Assume
  1449. * PCI rev 2.3 support was added in pci core rev 6 and things changed..
  1450. */
  1451. if (PCIE(sih) || (PCI(sih) && (ai_get_buscorerev(sih) >= 6))) {
  1452. /* pci config write to set this core bit in PCIIntMask */
  1453. pci_read_config_dword(sii->pcibus, PCI_INT_MASK, &w);
  1454. w |= (coremask << PCI_SBIM_SHIFT);
  1455. pci_write_config_dword(sii->pcibus, PCI_INT_MASK, w);
  1456. } else {
  1457. /* set sbintvec bit for our flag number */
  1458. ai_setint(sih, siflag);
  1459. }
  1460. if (PCI(sih)) {
  1461. pcicore_pci_setup(sii->pch, regs);
  1462. /* switch back to previous core */
  1463. ai_setcoreidx(sih, idx);
  1464. }
  1465. }
  1466. /*
  1467. * Fixup SROMless PCI device's configuration.
  1468. * The current core may be changed upon return.
  1469. */
  1470. int ai_pci_fixcfg(struct si_pub *sih)
  1471. {
  1472. uint origidx;
  1473. void __iomem *regs = NULL;
  1474. struct si_info *sii = (struct si_info *)sih;
  1475. /* Fixup PI in SROM shadow area to enable the correct PCI core access */
  1476. /* save the current index */
  1477. origidx = ai_coreidx(&sii->pub);
  1478. /* check 'pi' is correct and fix it if not */
  1479. regs = ai_setcore(&sii->pub, ai_get_buscoretype(sih), 0);
  1480. if (ai_get_buscoretype(sih) == PCIE_CORE_ID)
  1481. pcicore_fixcfg_pcie(sii->pch,
  1482. (struct sbpcieregs __iomem *)regs);
  1483. else if (ai_get_buscoretype(sih) == PCI_CORE_ID)
  1484. pcicore_fixcfg_pci(sii->pch, (struct sbpciregs __iomem *)regs);
  1485. /* restore the original index */
  1486. ai_setcoreidx(&sii->pub, origidx);
  1487. pcicore_hwup(sii->pch);
  1488. return 0;
  1489. }
  1490. /* mask&set gpiocontrol bits */
  1491. u32 ai_gpiocontrol(struct si_pub *sih, u32 mask, u32 val, u8 priority)
  1492. {
  1493. uint regoff;
  1494. regoff = offsetof(struct chipcregs, gpiocontrol);
  1495. return ai_corereg(sih, SI_CC_IDX, regoff, mask, val);
  1496. }
  1497. void ai_chipcontrl_epa4331(struct si_pub *sih, bool on)
  1498. {
  1499. struct si_info *sii;
  1500. struct chipcregs __iomem *cc;
  1501. uint origidx;
  1502. u32 val;
  1503. sii = (struct si_info *)sih;
  1504. origidx = ai_coreidx(sih);
  1505. cc = (struct chipcregs __iomem *) ai_setcore(sih, CC_CORE_ID, 0);
  1506. val = R_REG(&cc->chipcontrol);
  1507. if (on) {
  1508. if (ai_get_chippkg(sih) == 9 || ai_get_chippkg(sih) == 0xb)
  1509. /* Ext PA Controls for 4331 12x9 Package */
  1510. W_REG(&cc->chipcontrol, val |
  1511. CCTRL4331_EXTPA_EN |
  1512. CCTRL4331_EXTPA_ON_GPIO2_5);
  1513. else
  1514. /* Ext PA Controls for 4331 12x12 Package */
  1515. W_REG(&cc->chipcontrol,
  1516. val | CCTRL4331_EXTPA_EN);
  1517. } else {
  1518. val &= ~(CCTRL4331_EXTPA_EN | CCTRL4331_EXTPA_ON_GPIO2_5);
  1519. W_REG(&cc->chipcontrol, val);
  1520. }
  1521. ai_setcoreidx(sih, origidx);
  1522. }
  1523. /* Enable BT-COEX & Ex-PA for 4313 */
  1524. void ai_epa_4313war(struct si_pub *sih)
  1525. {
  1526. struct si_info *sii;
  1527. struct chipcregs __iomem *cc;
  1528. uint origidx;
  1529. sii = (struct si_info *)sih;
  1530. origidx = ai_coreidx(sih);
  1531. cc = ai_setcore(sih, CC_CORE_ID, 0);
  1532. /* EPA Fix */
  1533. W_REG(&cc->gpiocontrol,
  1534. R_REG(&cc->gpiocontrol) | GPIO_CTRL_EPA_EN_MASK);
  1535. ai_setcoreidx(sih, origidx);
  1536. }
  1537. /* check if the device is removed */
  1538. bool ai_deviceremoved(struct si_pub *sih)
  1539. {
  1540. u32 w;
  1541. struct si_info *sii;
  1542. sii = (struct si_info *)sih;
  1543. pci_read_config_dword(sii->pcibus, PCI_VENDOR_ID, &w);
  1544. if ((w & 0xFFFF) != PCI_VENDOR_ID_BROADCOM)
  1545. return true;
  1546. return false;
  1547. }
  1548. bool ai_is_sprom_available(struct si_pub *sih)
  1549. {
  1550. struct si_info *sii = (struct si_info *)sih;
  1551. if (ai_get_ccrev(sih) >= 31) {
  1552. uint origidx;
  1553. struct chipcregs __iomem *cc;
  1554. u32 sromctrl;
  1555. if ((ai_get_cccaps(sih) & CC_CAP_SROM) == 0)
  1556. return false;
  1557. origidx = sii->curidx;
  1558. cc = ai_setcoreidx(sih, SI_CC_IDX);
  1559. sromctrl = R_REG(&cc->sromcontrol);
  1560. ai_setcoreidx(sih, origidx);
  1561. return sromctrl & SRC_PRESENT;
  1562. }
  1563. switch (ai_get_chip_id(sih)) {
  1564. case BCM4313_CHIP_ID:
  1565. return (sii->chipst & CST4313_SPROM_PRESENT) != 0;
  1566. default:
  1567. return true;
  1568. }
  1569. }
  1570. bool ai_is_otp_disabled(struct si_pub *sih)
  1571. {
  1572. struct si_info *sii = (struct si_info *)sih;
  1573. switch (ai_get_chip_id(sih)) {
  1574. case BCM4313_CHIP_ID:
  1575. return (sii->chipst & CST4313_OTP_PRESENT) == 0;
  1576. /* These chips always have their OTP on */
  1577. case BCM43224_CHIP_ID:
  1578. case BCM43225_CHIP_ID:
  1579. default:
  1580. return false;
  1581. }
  1582. }