aiutils.c 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079
  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. #include <linux/delay.h>
  19. #include <linux/pci.h>
  20. #include <defs.h>
  21. #include <chipcommon.h>
  22. #include <brcmu_utils.h>
  23. #include <brcm_hw_ids.h>
  24. #include <soc.h>
  25. #include "types.h"
  26. #include "pub.h"
  27. #include "pmu.h"
  28. #include "srom.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. /* Newer chips can access PCI/PCIE and CC core without requiring to change
  289. * PCI BAR0 WIN
  290. */
  291. #define SI_FAST(si) (((si)->pub.buscoretype == PCIE_CORE_ID) || \
  292. (((si)->pub.buscoretype == PCI_CORE_ID) && \
  293. (si)->pub.buscorerev >= 13))
  294. #define CCREGS_FAST(si) (((char __iomem *)((si)->curmap) + \
  295. PCI_16KB0_CCREGS_OFFSET))
  296. #define IS_SIM(chippkg) \
  297. ((chippkg == HDLSIM_PKG_ID) || (chippkg == HWSIM_PKG_ID))
  298. /*
  299. * Macros to disable/restore function core(D11, ENET, ILINE20, etc) interrupts
  300. * before after core switching to avoid invalid register accesss inside ISR.
  301. */
  302. #define INTR_OFF(si, intr_val) \
  303. if ((si)->intrsoff_fn && \
  304. (si)->coreid[(si)->curidx] == (si)->dev_coreid) \
  305. intr_val = (*(si)->intrsoff_fn)((si)->intr_arg)
  306. #define INTR_RESTORE(si, intr_val) \
  307. if ((si)->intrsrestore_fn && \
  308. (si)->coreid[(si)->curidx] == (si)->dev_coreid) \
  309. (*(si)->intrsrestore_fn)((si)->intr_arg, intr_val)
  310. #define PCI(si) ((si)->pub.buscoretype == PCI_CORE_ID)
  311. #define PCIE(si) ((si)->pub.buscoretype == PCIE_CORE_ID)
  312. #define PCI_FORCEHT(si) (PCIE(si) && (si->pub.chip == BCM4716_CHIP_ID))
  313. #ifdef BCMDBG
  314. #define SI_MSG(args) printk args
  315. #else
  316. #define SI_MSG(args)
  317. #endif /* BCMDBG */
  318. #define GOODCOREADDR(x, b) \
  319. (((x) >= (b)) && ((x) < ((b) + SI_MAXCORES * SI_CORE_SIZE)) && \
  320. IS_ALIGNED((x), SI_CORE_SIZE))
  321. #define PCIEREGS(si) ((__iomem char *)((si)->curmap) + \
  322. PCI_16KB0_PCIREGS_OFFSET)
  323. struct aidmp {
  324. u32 oobselina30; /* 0x000 */
  325. u32 oobselina74; /* 0x004 */
  326. u32 PAD[6];
  327. u32 oobselinb30; /* 0x020 */
  328. u32 oobselinb74; /* 0x024 */
  329. u32 PAD[6];
  330. u32 oobselinc30; /* 0x040 */
  331. u32 oobselinc74; /* 0x044 */
  332. u32 PAD[6];
  333. u32 oobselind30; /* 0x060 */
  334. u32 oobselind74; /* 0x064 */
  335. u32 PAD[38];
  336. u32 oobselouta30; /* 0x100 */
  337. u32 oobselouta74; /* 0x104 */
  338. u32 PAD[6];
  339. u32 oobseloutb30; /* 0x120 */
  340. u32 oobseloutb74; /* 0x124 */
  341. u32 PAD[6];
  342. u32 oobseloutc30; /* 0x140 */
  343. u32 oobseloutc74; /* 0x144 */
  344. u32 PAD[6];
  345. u32 oobseloutd30; /* 0x160 */
  346. u32 oobseloutd74; /* 0x164 */
  347. u32 PAD[38];
  348. u32 oobsynca; /* 0x200 */
  349. u32 oobseloutaen; /* 0x204 */
  350. u32 PAD[6];
  351. u32 oobsyncb; /* 0x220 */
  352. u32 oobseloutben; /* 0x224 */
  353. u32 PAD[6];
  354. u32 oobsyncc; /* 0x240 */
  355. u32 oobseloutcen; /* 0x244 */
  356. u32 PAD[6];
  357. u32 oobsyncd; /* 0x260 */
  358. u32 oobseloutden; /* 0x264 */
  359. u32 PAD[38];
  360. u32 oobaextwidth; /* 0x300 */
  361. u32 oobainwidth; /* 0x304 */
  362. u32 oobaoutwidth; /* 0x308 */
  363. u32 PAD[5];
  364. u32 oobbextwidth; /* 0x320 */
  365. u32 oobbinwidth; /* 0x324 */
  366. u32 oobboutwidth; /* 0x328 */
  367. u32 PAD[5];
  368. u32 oobcextwidth; /* 0x340 */
  369. u32 oobcinwidth; /* 0x344 */
  370. u32 oobcoutwidth; /* 0x348 */
  371. u32 PAD[5];
  372. u32 oobdextwidth; /* 0x360 */
  373. u32 oobdinwidth; /* 0x364 */
  374. u32 oobdoutwidth; /* 0x368 */
  375. u32 PAD[37];
  376. u32 ioctrlset; /* 0x400 */
  377. u32 ioctrlclear; /* 0x404 */
  378. u32 ioctrl; /* 0x408 */
  379. u32 PAD[61];
  380. u32 iostatus; /* 0x500 */
  381. u32 PAD[127];
  382. u32 ioctrlwidth; /* 0x700 */
  383. u32 iostatuswidth; /* 0x704 */
  384. u32 PAD[62];
  385. u32 resetctrl; /* 0x800 */
  386. u32 resetstatus; /* 0x804 */
  387. u32 resetreadid; /* 0x808 */
  388. u32 resetwriteid; /* 0x80c */
  389. u32 PAD[60];
  390. u32 errlogctrl; /* 0x900 */
  391. u32 errlogdone; /* 0x904 */
  392. u32 errlogstatus; /* 0x908 */
  393. u32 errlogaddrlo; /* 0x90c */
  394. u32 errlogaddrhi; /* 0x910 */
  395. u32 errlogid; /* 0x914 */
  396. u32 errloguser; /* 0x918 */
  397. u32 errlogflags; /* 0x91c */
  398. u32 PAD[56];
  399. u32 intstatus; /* 0xa00 */
  400. u32 PAD[127];
  401. u32 config; /* 0xe00 */
  402. u32 PAD[63];
  403. u32 itcr; /* 0xf00 */
  404. u32 PAD[3];
  405. u32 itipooba; /* 0xf10 */
  406. u32 itipoobb; /* 0xf14 */
  407. u32 itipoobc; /* 0xf18 */
  408. u32 itipoobd; /* 0xf1c */
  409. u32 PAD[4];
  410. u32 itipoobaout; /* 0xf30 */
  411. u32 itipoobbout; /* 0xf34 */
  412. u32 itipoobcout; /* 0xf38 */
  413. u32 itipoobdout; /* 0xf3c */
  414. u32 PAD[4];
  415. u32 itopooba; /* 0xf50 */
  416. u32 itopoobb; /* 0xf54 */
  417. u32 itopoobc; /* 0xf58 */
  418. u32 itopoobd; /* 0xf5c */
  419. u32 PAD[4];
  420. u32 itopoobain; /* 0xf70 */
  421. u32 itopoobbin; /* 0xf74 */
  422. u32 itopoobcin; /* 0xf78 */
  423. u32 itopoobdin; /* 0xf7c */
  424. u32 PAD[4];
  425. u32 itopreset; /* 0xf90 */
  426. u32 PAD[15];
  427. u32 peripherialid4; /* 0xfd0 */
  428. u32 peripherialid5; /* 0xfd4 */
  429. u32 peripherialid6; /* 0xfd8 */
  430. u32 peripherialid7; /* 0xfdc */
  431. u32 peripherialid0; /* 0xfe0 */
  432. u32 peripherialid1; /* 0xfe4 */
  433. u32 peripherialid2; /* 0xfe8 */
  434. u32 peripherialid3; /* 0xfec */
  435. u32 componentid0; /* 0xff0 */
  436. u32 componentid1; /* 0xff4 */
  437. u32 componentid2; /* 0xff8 */
  438. u32 componentid3; /* 0xffc */
  439. };
  440. /* EROM parsing */
  441. static u32
  442. get_erom_ent(struct si_pub *sih, u32 __iomem **eromptr, u32 mask, u32 match)
  443. {
  444. u32 ent;
  445. uint inv = 0, nom = 0;
  446. while (true) {
  447. ent = R_REG(*eromptr);
  448. (*eromptr)++;
  449. if (mask == 0)
  450. break;
  451. if ((ent & ER_VALID) == 0) {
  452. inv++;
  453. continue;
  454. }
  455. if (ent == (ER_END | ER_VALID))
  456. break;
  457. if ((ent & mask) == match)
  458. break;
  459. nom++;
  460. }
  461. return ent;
  462. }
  463. static u32
  464. get_asd(struct si_pub *sih, u32 __iomem **eromptr, uint sp, uint ad, uint st,
  465. u32 *addrl, u32 *addrh, u32 *sizel, u32 *sizeh)
  466. {
  467. u32 asd, sz, szd;
  468. asd = get_erom_ent(sih, eromptr, ER_VALID, ER_VALID);
  469. if (((asd & ER_TAG1) != ER_ADD) ||
  470. (((asd & AD_SP_MASK) >> AD_SP_SHIFT) != sp) ||
  471. ((asd & AD_ST_MASK) != st)) {
  472. /* This is not what we want, "push" it back */
  473. (*eromptr)--;
  474. return 0;
  475. }
  476. *addrl = asd & AD_ADDR_MASK;
  477. if (asd & AD_AG32)
  478. *addrh = get_erom_ent(sih, eromptr, 0, 0);
  479. else
  480. *addrh = 0;
  481. *sizeh = 0;
  482. sz = asd & AD_SZ_MASK;
  483. if (sz == AD_SZ_SZD) {
  484. szd = get_erom_ent(sih, eromptr, 0, 0);
  485. *sizel = szd & SD_SZ_MASK;
  486. if (szd & SD_SG32)
  487. *sizeh = get_erom_ent(sih, eromptr, 0, 0);
  488. } else
  489. *sizel = AD_SZ_BASE << (sz >> AD_SZ_SHIFT);
  490. return asd;
  491. }
  492. static void ai_hwfixup(struct si_info *sii)
  493. {
  494. }
  495. /* parse the enumeration rom to identify all cores */
  496. static void ai_scan(struct si_pub *sih, struct chipcregs __iomem *cc)
  497. {
  498. struct si_info *sii = (struct si_info *)sih;
  499. u32 erombase;
  500. u32 __iomem *eromptr, *eromlim;
  501. void __iomem *regs = cc;
  502. erombase = R_REG(&cc->eromptr);
  503. /* Set wrappers address */
  504. sii->curwrap = (void *)((unsigned long)cc + SI_CORE_SIZE);
  505. /* Now point the window at the erom */
  506. pci_write_config_dword(sii->pbus, PCI_BAR0_WIN, erombase);
  507. eromptr = regs;
  508. eromlim = eromptr + (ER_REMAPCONTROL / sizeof(u32));
  509. while (eromptr < eromlim) {
  510. u32 cia, cib, cid, mfg, crev, nmw, nsw, nmp, nsp;
  511. u32 mpd, asd, addrl, addrh, sizel, sizeh;
  512. u32 __iomem *base;
  513. uint i, j, idx;
  514. bool br;
  515. br = false;
  516. /* Grok a component */
  517. cia = get_erom_ent(sih, &eromptr, ER_TAG, ER_CI);
  518. if (cia == (ER_END | ER_VALID)) {
  519. /* Found END of erom */
  520. ai_hwfixup(sii);
  521. return;
  522. }
  523. base = eromptr - 1;
  524. cib = get_erom_ent(sih, &eromptr, 0, 0);
  525. if ((cib & ER_TAG) != ER_CI) {
  526. /* CIA not followed by CIB */
  527. goto error;
  528. }
  529. cid = (cia & CIA_CID_MASK) >> CIA_CID_SHIFT;
  530. mfg = (cia & CIA_MFG_MASK) >> CIA_MFG_SHIFT;
  531. crev = (cib & CIB_REV_MASK) >> CIB_REV_SHIFT;
  532. nmw = (cib & CIB_NMW_MASK) >> CIB_NMW_SHIFT;
  533. nsw = (cib & CIB_NSW_MASK) >> CIB_NSW_SHIFT;
  534. nmp = (cib & CIB_NMP_MASK) >> CIB_NMP_SHIFT;
  535. nsp = (cib & CIB_NSP_MASK) >> CIB_NSP_SHIFT;
  536. if (((mfg == MFGID_ARM) && (cid == DEF_AI_COMP)) || (nsp == 0))
  537. continue;
  538. if ((nmw + nsw == 0)) {
  539. /* A component which is not a core */
  540. if (cid == OOB_ROUTER_CORE_ID) {
  541. asd = get_asd(sih, &eromptr, 0, 0, AD_ST_SLAVE,
  542. &addrl, &addrh, &sizel, &sizeh);
  543. if (asd != 0)
  544. sii->oob_router = addrl;
  545. }
  546. continue;
  547. }
  548. idx = sii->numcores;
  549. /* sii->eromptr[idx] = base; */
  550. sii->cia[idx] = cia;
  551. sii->cib[idx] = cib;
  552. sii->coreid[idx] = cid;
  553. for (i = 0; i < nmp; i++) {
  554. mpd = get_erom_ent(sih, &eromptr, ER_VALID, ER_VALID);
  555. if ((mpd & ER_TAG) != ER_MP) {
  556. /* Not enough MP entries for component */
  557. goto error;
  558. }
  559. }
  560. /* First Slave Address Descriptor should be port 0:
  561. * the main register space for the core
  562. */
  563. asd =
  564. get_asd(sih, &eromptr, 0, 0, AD_ST_SLAVE, &addrl, &addrh,
  565. &sizel, &sizeh);
  566. if (asd == 0) {
  567. /* Try again to see if it is a bridge */
  568. asd =
  569. get_asd(sih, &eromptr, 0, 0, AD_ST_BRIDGE, &addrl,
  570. &addrh, &sizel, &sizeh);
  571. if (asd != 0)
  572. br = true;
  573. else if ((addrh != 0) || (sizeh != 0)
  574. || (sizel != SI_CORE_SIZE)) {
  575. /* First Slave ASD for core malformed */
  576. goto error;
  577. }
  578. }
  579. sii->coresba[idx] = addrl;
  580. sii->coresba_size[idx] = sizel;
  581. /* Get any more ASDs in port 0 */
  582. j = 1;
  583. do {
  584. asd =
  585. get_asd(sih, &eromptr, 0, j, AD_ST_SLAVE, &addrl,
  586. &addrh, &sizel, &sizeh);
  587. if ((asd != 0) && (j == 1) && (sizel == SI_CORE_SIZE)) {
  588. sii->coresba2[idx] = addrl;
  589. sii->coresba2_size[idx] = sizel;
  590. }
  591. j++;
  592. } while (asd != 0);
  593. /* Go through the ASDs for other slave ports */
  594. for (i = 1; i < nsp; i++) {
  595. j = 0;
  596. do {
  597. asd =
  598. get_asd(sih, &eromptr, i, j++, AD_ST_SLAVE,
  599. &addrl, &addrh, &sizel, &sizeh);
  600. } while (asd != 0);
  601. if (j == 0) {
  602. /* SP has no address descriptors */
  603. goto error;
  604. }
  605. }
  606. /* Now get master wrappers */
  607. for (i = 0; i < nmw; i++) {
  608. asd =
  609. get_asd(sih, &eromptr, i, 0, AD_ST_MWRAP, &addrl,
  610. &addrh, &sizel, &sizeh);
  611. if (asd == 0) {
  612. /* Missing descriptor for MW */
  613. goto error;
  614. }
  615. if ((sizeh != 0) || (sizel != SI_CORE_SIZE)) {
  616. /* Master wrapper %d is not 4KB */
  617. goto error;
  618. }
  619. if (i == 0)
  620. sii->wrapba[idx] = addrl;
  621. }
  622. /* And finally slave wrappers */
  623. for (i = 0; i < nsw; i++) {
  624. uint fwp = (nsp == 1) ? 0 : 1;
  625. asd =
  626. get_asd(sih, &eromptr, fwp + i, 0, AD_ST_SWRAP,
  627. &addrl, &addrh, &sizel, &sizeh);
  628. if (asd == 0) {
  629. /* Missing descriptor for SW */
  630. goto error;
  631. }
  632. if ((sizeh != 0) || (sizel != SI_CORE_SIZE)) {
  633. /* Slave wrapper is not 4KB */
  634. goto error;
  635. }
  636. if ((nmw == 0) && (i == 0))
  637. sii->wrapba[idx] = addrl;
  638. }
  639. /* Don't record bridges */
  640. if (br)
  641. continue;
  642. /* Done with core */
  643. sii->numcores++;
  644. }
  645. error:
  646. /* Reached end of erom without finding END */
  647. sii->numcores = 0;
  648. return;
  649. }
  650. /*
  651. * This function changes the logical "focus" to the indicated core.
  652. * Return the current core's virtual address. Since each core starts with the
  653. * same set of registers (BIST, clock control, etc), the returned address
  654. * contains the first register of this 'common' register block (not to be
  655. * confused with 'common core').
  656. */
  657. void __iomem *ai_setcoreidx(struct si_pub *sih, uint coreidx)
  658. {
  659. struct si_info *sii = (struct si_info *)sih;
  660. u32 addr = sii->coresba[coreidx];
  661. u32 wrap = sii->wrapba[coreidx];
  662. if (coreidx >= sii->numcores)
  663. return NULL;
  664. /* point bar0 window */
  665. pci_write_config_dword(sii->pbus, PCI_BAR0_WIN, addr);
  666. /* point bar0 2nd 4KB window */
  667. pci_write_config_dword(sii->pbus, PCI_BAR0_WIN2, wrap);
  668. sii->curidx = coreidx;
  669. return sii->curmap;
  670. }
  671. /* Return the number of address spaces in current core */
  672. int ai_numaddrspaces(struct si_pub *sih)
  673. {
  674. return 2;
  675. }
  676. /* Return the address of the nth address space in the current core */
  677. u32 ai_addrspace(struct si_pub *sih, uint asidx)
  678. {
  679. struct si_info *sii;
  680. uint cidx;
  681. sii = (struct si_info *)sih;
  682. cidx = sii->curidx;
  683. if (asidx == 0)
  684. return sii->coresba[cidx];
  685. else if (asidx == 1)
  686. return sii->coresba2[cidx];
  687. else {
  688. /* Need to parse the erom again to find addr space */
  689. return 0;
  690. }
  691. }
  692. /* Return the size of the nth address space in the current core */
  693. u32 ai_addrspacesize(struct si_pub *sih, uint asidx)
  694. {
  695. struct si_info *sii;
  696. uint cidx;
  697. sii = (struct si_info *)sih;
  698. cidx = sii->curidx;
  699. if (asidx == 0)
  700. return sii->coresba_size[cidx];
  701. else if (asidx == 1)
  702. return sii->coresba2_size[cidx];
  703. else {
  704. /* Need to parse the erom again to find addr */
  705. return 0;
  706. }
  707. }
  708. uint ai_flag(struct si_pub *sih)
  709. {
  710. struct si_info *sii;
  711. struct aidmp *ai;
  712. sii = (struct si_info *)sih;
  713. ai = sii->curwrap;
  714. return R_REG(&ai->oobselouta30) & 0x1f;
  715. }
  716. void ai_setint(struct si_pub *sih, int siflag)
  717. {
  718. }
  719. uint ai_corevendor(struct si_pub *sih)
  720. {
  721. struct si_info *sii;
  722. u32 cia;
  723. sii = (struct si_info *)sih;
  724. cia = sii->cia[sii->curidx];
  725. return (cia & CIA_MFG_MASK) >> CIA_MFG_SHIFT;
  726. }
  727. uint ai_corerev(struct si_pub *sih)
  728. {
  729. struct si_info *sii;
  730. u32 cib;
  731. sii = (struct si_info *)sih;
  732. cib = sii->cib[sii->curidx];
  733. return (cib & CIB_REV_MASK) >> CIB_REV_SHIFT;
  734. }
  735. bool ai_iscoreup(struct si_pub *sih)
  736. {
  737. struct si_info *sii;
  738. struct aidmp *ai;
  739. sii = (struct si_info *)sih;
  740. ai = sii->curwrap;
  741. return (((R_REG(&ai->ioctrl) & (SICF_FGC | SICF_CLOCK_EN)) ==
  742. SICF_CLOCK_EN)
  743. && ((R_REG(&ai->resetctrl) & AIRC_RESET) == 0));
  744. }
  745. void ai_core_cflags_wo(struct si_pub *sih, u32 mask, u32 val)
  746. {
  747. struct si_info *sii;
  748. struct aidmp *ai;
  749. u32 w;
  750. sii = (struct si_info *)sih;
  751. ai = sii->curwrap;
  752. if (mask || val) {
  753. w = ((R_REG(&ai->ioctrl) & ~mask) | val);
  754. W_REG(&ai->ioctrl, w);
  755. }
  756. }
  757. u32 ai_core_cflags(struct si_pub *sih, u32 mask, u32 val)
  758. {
  759. struct si_info *sii;
  760. struct aidmp *ai;
  761. u32 w;
  762. sii = (struct si_info *)sih;
  763. ai = sii->curwrap;
  764. if (mask || val) {
  765. w = ((R_REG(&ai->ioctrl) & ~mask) | val);
  766. W_REG(&ai->ioctrl, w);
  767. }
  768. return R_REG(&ai->ioctrl);
  769. }
  770. /* return true if PCIE capability exists in the pci config space */
  771. static bool ai_ispcie(struct si_info *sii)
  772. {
  773. u8 cap_ptr;
  774. cap_ptr =
  775. pcicore_find_pci_capability(sii->pbus, PCI_CAP_ID_EXP, NULL,
  776. NULL);
  777. if (!cap_ptr)
  778. return false;
  779. return true;
  780. }
  781. static bool ai_buscore_prep(struct si_info *sii)
  782. {
  783. /* kludge to enable the clock on the 4306 which lacks a slowclock */
  784. if (!ai_ispcie(sii))
  785. ai_clkctl_xtal(&sii->pub, XTAL | PLL, ON);
  786. return true;
  787. }
  788. u32 ai_core_sflags(struct si_pub *sih, u32 mask, u32 val)
  789. {
  790. struct si_info *sii;
  791. struct aidmp *ai;
  792. u32 w;
  793. sii = (struct si_info *)sih;
  794. ai = sii->curwrap;
  795. if (mask || val) {
  796. w = ((R_REG(&ai->iostatus) & ~mask) | val);
  797. W_REG(&ai->iostatus, w);
  798. }
  799. return R_REG(&ai->iostatus);
  800. }
  801. static bool
  802. ai_buscore_setup(struct si_info *sii, u32 savewin, uint *origidx)
  803. {
  804. bool pci, pcie;
  805. uint i;
  806. uint pciidx, pcieidx, pcirev, pcierev;
  807. struct chipcregs __iomem *cc;
  808. cc = ai_setcoreidx(&sii->pub, SI_CC_IDX);
  809. /* get chipcommon rev */
  810. sii->pub.ccrev = (int)ai_corerev(&sii->pub);
  811. /* get chipcommon chipstatus */
  812. if (sii->pub.ccrev >= 11)
  813. sii->pub.chipst = R_REG(&cc->chipstatus);
  814. /* get chipcommon capabilites */
  815. sii->pub.cccaps = R_REG(&cc->capabilities);
  816. /* get chipcommon extended capabilities */
  817. if (sii->pub.ccrev >= 35)
  818. sii->pub.cccaps_ext = R_REG(&cc->capabilities_ext);
  819. /* get pmu rev and caps */
  820. if (sii->pub.cccaps & CC_CAP_PMU) {
  821. sii->pub.pmucaps = R_REG(&cc->pmucapabilities);
  822. sii->pub.pmurev = sii->pub.pmucaps & PCAP_REV_MASK;
  823. }
  824. /* figure out bus/orignal core idx */
  825. sii->pub.buscoretype = NODEV_CORE_ID;
  826. sii->pub.buscorerev = NOREV;
  827. sii->pub.buscoreidx = BADIDX;
  828. pci = pcie = false;
  829. pcirev = pcierev = NOREV;
  830. pciidx = pcieidx = BADIDX;
  831. for (i = 0; i < sii->numcores; i++) {
  832. uint cid, crev;
  833. ai_setcoreidx(&sii->pub, i);
  834. cid = ai_coreid(&sii->pub);
  835. crev = ai_corerev(&sii->pub);
  836. if (cid == PCI_CORE_ID) {
  837. pciidx = i;
  838. pcirev = crev;
  839. pci = true;
  840. } else if (cid == PCIE_CORE_ID) {
  841. pcieidx = i;
  842. pcierev = crev;
  843. pcie = true;
  844. }
  845. /* find the core idx before entering this func. */
  846. if ((savewin && (savewin == sii->coresba[i])) ||
  847. (cc == sii->regs[i]))
  848. *origidx = i;
  849. }
  850. if (pci && pcie) {
  851. if (ai_ispcie(sii))
  852. pci = false;
  853. else
  854. pcie = false;
  855. }
  856. if (pci) {
  857. sii->pub.buscoretype = PCI_CORE_ID;
  858. sii->pub.buscorerev = pcirev;
  859. sii->pub.buscoreidx = pciidx;
  860. } else if (pcie) {
  861. sii->pub.buscoretype = PCIE_CORE_ID;
  862. sii->pub.buscorerev = pcierev;
  863. sii->pub.buscoreidx = pcieidx;
  864. }
  865. /* fixup necessary chip/core configurations */
  866. if (SI_FAST(sii)) {
  867. if (!sii->pch) {
  868. sii->pch = pcicore_init(&sii->pub, sii->pbus,
  869. (__iomem void *)PCIEREGS(sii));
  870. if (sii->pch == NULL)
  871. return false;
  872. }
  873. }
  874. if (ai_pci_fixcfg(&sii->pub)) {
  875. /* si_doattach: si_pci_fixcfg failed */
  876. return false;
  877. }
  878. /* return to the original core */
  879. ai_setcoreidx(&sii->pub, *origidx);
  880. return true;
  881. }
  882. /*
  883. * get boardtype and boardrev
  884. */
  885. static __used void ai_nvram_process(struct si_info *sii)
  886. {
  887. uint w = 0;
  888. /* do a pci config read to get subsystem id and subvendor id */
  889. pci_read_config_dword(sii->pbus, PCI_SUBSYSTEM_VENDOR_ID, &w);
  890. sii->pub.boardvendor = w & 0xffff;
  891. sii->pub.boardtype = (w >> 16) & 0xffff;
  892. sii->pub.boardflags = getintvar(&sii->pub, BRCMS_SROM_BOARDFLAGS);
  893. }
  894. static struct si_info *ai_doattach(struct si_info *sii,
  895. void __iomem *regs, struct pci_dev *pbus)
  896. {
  897. struct si_pub *sih = &sii->pub;
  898. u32 w, savewin;
  899. struct chipcregs __iomem *cc;
  900. uint socitype;
  901. uint origidx;
  902. memset((unsigned char *) sii, 0, sizeof(struct si_info));
  903. savewin = 0;
  904. sih->buscoreidx = BADIDX;
  905. sii->curmap = regs;
  906. sii->pbus = pbus;
  907. /* find Chipcommon address */
  908. pci_read_config_dword(sii->pbus, PCI_BAR0_WIN, &savewin);
  909. if (!GOODCOREADDR(savewin, SI_ENUM_BASE))
  910. savewin = SI_ENUM_BASE;
  911. pci_write_config_dword(sii->pbus, PCI_BAR0_WIN,
  912. SI_ENUM_BASE);
  913. cc = (struct chipcregs __iomem *) regs;
  914. /* bus/core/clk setup for register access */
  915. if (!ai_buscore_prep(sii))
  916. return NULL;
  917. /*
  918. * ChipID recognition.
  919. * We assume we can read chipid at offset 0 from the regs arg.
  920. * If we add other chiptypes (or if we need to support old sdio
  921. * hosts w/o chipcommon), some way of recognizing them needs to
  922. * be added here.
  923. */
  924. w = R_REG(&cc->chipid);
  925. socitype = (w & CID_TYPE_MASK) >> CID_TYPE_SHIFT;
  926. /* Might as wll fill in chip id rev & pkg */
  927. sih->chip = w & CID_ID_MASK;
  928. sih->chiprev = (w & CID_REV_MASK) >> CID_REV_SHIFT;
  929. sih->chippkg = (w & CID_PKG_MASK) >> CID_PKG_SHIFT;
  930. sih->issim = false;
  931. /* scan for cores */
  932. if (socitype == SOCI_AI) {
  933. SI_MSG(("Found chip type AI (0x%08x)\n", w));
  934. /* pass chipc address instead of original core base */
  935. ai_scan(&sii->pub, cc);
  936. } else {
  937. /* Found chip of unknown type */
  938. return NULL;
  939. }
  940. /* no cores found, bail out */
  941. if (sii->numcores == 0)
  942. return NULL;
  943. /* bus/core/clk setup */
  944. origidx = SI_CC_IDX;
  945. if (!ai_buscore_setup(sii, savewin, &origidx))
  946. goto exit;
  947. /* Init nvram from sprom/otp if they exist */
  948. if (srom_var_init(&sii->pub, cc))
  949. goto exit;
  950. ai_nvram_process(sii);
  951. /* === NVRAM, clock is ready === */
  952. cc = (struct chipcregs __iomem *) ai_setcore(sih, CC_CORE_ID, 0);
  953. W_REG(&cc->gpiopullup, 0);
  954. W_REG(&cc->gpiopulldown, 0);
  955. ai_setcoreidx(sih, origidx);
  956. /* PMU specific initializations */
  957. if (sih->cccaps & CC_CAP_PMU) {
  958. u32 xtalfreq;
  959. si_pmu_init(sih);
  960. si_pmu_chip_init(sih);
  961. xtalfreq = si_pmu_measure_alpclk(sih);
  962. si_pmu_pll_init(sih, xtalfreq);
  963. si_pmu_res_init(sih);
  964. si_pmu_swreg_init(sih);
  965. }
  966. /* setup the GPIO based LED powersave register */
  967. w = getintvar(sih, BRCMS_SROM_LEDDC);
  968. if (w == 0)
  969. w = DEFAULT_GPIOTIMERVAL;
  970. ai_corereg(sih, SI_CC_IDX, offsetof(struct chipcregs, gpiotimerval),
  971. ~0, w);
  972. if (PCIE(sii))
  973. pcicore_attach(sii->pch, SI_DOATTACH);
  974. if (sih->chip == BCM43224_CHIP_ID) {
  975. /*
  976. * enable 12 mA drive strenth for 43224 and
  977. * set chipControl register bit 15
  978. */
  979. if (sih->chiprev == 0) {
  980. SI_MSG(("Applying 43224A0 WARs\n"));
  981. ai_corereg(sih, SI_CC_IDX,
  982. offsetof(struct chipcregs, chipcontrol),
  983. CCTRL43224_GPIO_TOGGLE,
  984. CCTRL43224_GPIO_TOGGLE);
  985. si_pmu_chipcontrol(sih, 0, CCTRL_43224A0_12MA_LED_DRIVE,
  986. CCTRL_43224A0_12MA_LED_DRIVE);
  987. }
  988. if (sih->chiprev >= 1) {
  989. SI_MSG(("Applying 43224B0+ WARs\n"));
  990. si_pmu_chipcontrol(sih, 0, CCTRL_43224B0_12MA_LED_DRIVE,
  991. CCTRL_43224B0_12MA_LED_DRIVE);
  992. }
  993. }
  994. if (sih->chip == BCM4313_CHIP_ID) {
  995. /*
  996. * enable 12 mA drive strenth for 4313 and
  997. * set chipControl register bit 1
  998. */
  999. SI_MSG(("Applying 4313 WARs\n"));
  1000. si_pmu_chipcontrol(sih, 0, CCTRL_4313_12MA_LED_DRIVE,
  1001. CCTRL_4313_12MA_LED_DRIVE);
  1002. }
  1003. return sii;
  1004. exit:
  1005. if (sii->pch)
  1006. pcicore_deinit(sii->pch);
  1007. sii->pch = NULL;
  1008. return NULL;
  1009. }
  1010. /*
  1011. * Allocate a si handle.
  1012. * devid - pci device id (used to determine chip#)
  1013. * osh - opaque OS handle
  1014. * regs - virtual address of initial core registers
  1015. */
  1016. struct si_pub *
  1017. ai_attach(void __iomem *regs, struct pci_dev *sdh)
  1018. {
  1019. struct si_info *sii;
  1020. /* alloc struct si_info */
  1021. sii = kmalloc(sizeof(struct si_info), GFP_ATOMIC);
  1022. if (sii == NULL)
  1023. return NULL;
  1024. if (ai_doattach(sii, regs, sdh) == NULL) {
  1025. kfree(sii);
  1026. return NULL;
  1027. }
  1028. return (struct si_pub *) sii;
  1029. }
  1030. /* may be called with core in reset */
  1031. void ai_detach(struct si_pub *sih)
  1032. {
  1033. struct si_info *sii;
  1034. struct si_pub *si_local = NULL;
  1035. memcpy(&si_local, &sih, sizeof(struct si_pub **));
  1036. sii = (struct si_info *)sih;
  1037. if (sii == NULL)
  1038. return;
  1039. if (sii->pch)
  1040. pcicore_deinit(sii->pch);
  1041. sii->pch = NULL;
  1042. srom_free_vars(sih);
  1043. kfree(sii);
  1044. }
  1045. /* register driver interrupt disabling and restoring callback functions */
  1046. void
  1047. ai_register_intr_callback(struct si_pub *sih, void *intrsoff_fn,
  1048. void *intrsrestore_fn,
  1049. void *intrsenabled_fn, void *intr_arg)
  1050. {
  1051. struct si_info *sii;
  1052. sii = (struct si_info *)sih;
  1053. sii->intr_arg = intr_arg;
  1054. sii->intrsoff_fn = (u32 (*)(void *)) intrsoff_fn;
  1055. sii->intrsrestore_fn = (void (*) (void *, u32)) intrsrestore_fn;
  1056. sii->intrsenabled_fn = (bool (*)(void *)) intrsenabled_fn;
  1057. /* save current core id. when this function called, the current core
  1058. * must be the core which provides driver functions(il, et, wl, etc.)
  1059. */
  1060. sii->dev_coreid = sii->coreid[sii->curidx];
  1061. }
  1062. void ai_deregister_intr_callback(struct si_pub *sih)
  1063. {
  1064. struct si_info *sii;
  1065. sii = (struct si_info *)sih;
  1066. sii->intrsoff_fn = NULL;
  1067. }
  1068. uint ai_coreid(struct si_pub *sih)
  1069. {
  1070. struct si_info *sii;
  1071. sii = (struct si_info *)sih;
  1072. return sii->coreid[sii->curidx];
  1073. }
  1074. uint ai_coreidx(struct si_pub *sih)
  1075. {
  1076. struct si_info *sii;
  1077. sii = (struct si_info *)sih;
  1078. return sii->curidx;
  1079. }
  1080. bool ai_backplane64(struct si_pub *sih)
  1081. {
  1082. return (sih->cccaps & CC_CAP_BKPLN64) != 0;
  1083. }
  1084. /* return index of coreid or BADIDX if not found */
  1085. uint ai_findcoreidx(struct si_pub *sih, uint coreid, uint coreunit)
  1086. {
  1087. struct si_info *sii;
  1088. uint found;
  1089. uint i;
  1090. sii = (struct si_info *)sih;
  1091. found = 0;
  1092. for (i = 0; i < sii->numcores; i++)
  1093. if (sii->coreid[i] == coreid) {
  1094. if (found == coreunit)
  1095. return i;
  1096. found++;
  1097. }
  1098. return BADIDX;
  1099. }
  1100. /*
  1101. * This function changes logical "focus" to the indicated core;
  1102. * must be called with interrupts off.
  1103. * Moreover, callers should keep interrupts off during switching
  1104. * out of and back to d11 core.
  1105. */
  1106. void __iomem *ai_setcore(struct si_pub *sih, uint coreid, uint coreunit)
  1107. {
  1108. uint idx;
  1109. idx = ai_findcoreidx(sih, coreid, coreunit);
  1110. if (idx >= SI_MAXCORES)
  1111. return NULL;
  1112. return ai_setcoreidx(sih, idx);
  1113. }
  1114. /* Turn off interrupt as required by ai_setcore, before switch core */
  1115. void __iomem *ai_switch_core(struct si_pub *sih, uint coreid, uint *origidx,
  1116. uint *intr_val)
  1117. {
  1118. void __iomem *cc;
  1119. struct si_info *sii;
  1120. sii = (struct si_info *)sih;
  1121. if (SI_FAST(sii)) {
  1122. /* Overloading the origidx variable to remember the coreid,
  1123. * this works because the core ids cannot be confused with
  1124. * core indices.
  1125. */
  1126. *origidx = coreid;
  1127. if (coreid == CC_CORE_ID)
  1128. return CCREGS_FAST(sii);
  1129. else if (coreid == sih->buscoretype)
  1130. return PCIEREGS(sii);
  1131. }
  1132. INTR_OFF(sii, *intr_val);
  1133. *origidx = sii->curidx;
  1134. cc = ai_setcore(sih, coreid, 0);
  1135. return cc;
  1136. }
  1137. /* restore coreidx and restore interrupt */
  1138. void ai_restore_core(struct si_pub *sih, uint coreid, uint intr_val)
  1139. {
  1140. struct si_info *sii;
  1141. sii = (struct si_info *)sih;
  1142. if (SI_FAST(sii)
  1143. && ((coreid == CC_CORE_ID) || (coreid == sih->buscoretype)))
  1144. return;
  1145. ai_setcoreidx(sih, coreid);
  1146. INTR_RESTORE(sii, intr_val);
  1147. }
  1148. void ai_write_wrapperreg(struct si_pub *sih, u32 offset, u32 val)
  1149. {
  1150. struct si_info *sii = (struct si_info *)sih;
  1151. u32 *w = (u32 *) sii->curwrap;
  1152. W_REG(w + (offset / 4), val);
  1153. return;
  1154. }
  1155. /*
  1156. * Switch to 'coreidx', issue a single arbitrary 32bit register mask&set
  1157. * operation, switch back to the original core, and return the new value.
  1158. *
  1159. * When using the silicon backplane, no fiddling with interrupts or core
  1160. * switches is needed.
  1161. *
  1162. * Also, when using pci/pcie, we can optimize away the core switching for pci
  1163. * registers and (on newer pci cores) chipcommon registers.
  1164. */
  1165. uint ai_corereg(struct si_pub *sih, uint coreidx, uint regoff, uint mask,
  1166. uint val)
  1167. {
  1168. uint origidx = 0;
  1169. u32 __iomem *r = NULL;
  1170. uint w;
  1171. uint intr_val = 0;
  1172. bool fast = false;
  1173. struct si_info *sii;
  1174. sii = (struct si_info *)sih;
  1175. if (coreidx >= SI_MAXCORES)
  1176. return 0;
  1177. /*
  1178. * If pci/pcie, we can get at pci/pcie regs
  1179. * and on newer cores to chipc
  1180. */
  1181. if ((sii->coreid[coreidx] == CC_CORE_ID) && SI_FAST(sii)) {
  1182. /* Chipc registers are mapped at 12KB */
  1183. fast = true;
  1184. r = (u32 __iomem *)((__iomem char *)sii->curmap +
  1185. PCI_16KB0_CCREGS_OFFSET + regoff);
  1186. } else if (sii->pub.buscoreidx == coreidx) {
  1187. /*
  1188. * pci registers are at either in the last 2KB of
  1189. * an 8KB window or, in pcie and pci rev 13 at 8KB
  1190. */
  1191. fast = true;
  1192. if (SI_FAST(sii))
  1193. r = (u32 __iomem *)((__iomem char *)sii->curmap +
  1194. PCI_16KB0_PCIREGS_OFFSET + regoff);
  1195. else
  1196. r = (u32 __iomem *)((__iomem char *)sii->curmap +
  1197. ((regoff >= SBCONFIGOFF) ?
  1198. PCI_BAR0_PCISBR_OFFSET :
  1199. PCI_BAR0_PCIREGS_OFFSET) + regoff);
  1200. }
  1201. if (!fast) {
  1202. INTR_OFF(sii, intr_val);
  1203. /* save current core index */
  1204. origidx = ai_coreidx(&sii->pub);
  1205. /* switch core */
  1206. r = (u32 __iomem *) ((unsigned char __iomem *)
  1207. ai_setcoreidx(&sii->pub, coreidx) + regoff);
  1208. }
  1209. /* mask and set */
  1210. if (mask || val) {
  1211. w = (R_REG(r) & ~mask) | val;
  1212. W_REG(r, w);
  1213. }
  1214. /* readback */
  1215. w = R_REG(r);
  1216. if (!fast) {
  1217. /* restore core index */
  1218. if (origidx != coreidx)
  1219. ai_setcoreidx(&sii->pub, origidx);
  1220. INTR_RESTORE(sii, intr_val);
  1221. }
  1222. return w;
  1223. }
  1224. void ai_core_disable(struct si_pub *sih, u32 bits)
  1225. {
  1226. struct si_info *sii;
  1227. u32 dummy;
  1228. struct aidmp *ai;
  1229. sii = (struct si_info *)sih;
  1230. ai = sii->curwrap;
  1231. /* if core is already in reset, just return */
  1232. if (R_REG(&ai->resetctrl) & AIRC_RESET)
  1233. return;
  1234. W_REG(&ai->ioctrl, bits);
  1235. dummy = R_REG(&ai->ioctrl);
  1236. udelay(10);
  1237. W_REG(&ai->resetctrl, AIRC_RESET);
  1238. udelay(1);
  1239. }
  1240. /* reset and re-enable a core
  1241. * inputs:
  1242. * bits - core specific bits that are set during and after reset sequence
  1243. * resetbits - core specific bits that are set only during reset sequence
  1244. */
  1245. void ai_core_reset(struct si_pub *sih, u32 bits, u32 resetbits)
  1246. {
  1247. struct si_info *sii;
  1248. struct aidmp *ai;
  1249. u32 dummy;
  1250. sii = (struct si_info *)sih;
  1251. ai = sii->curwrap;
  1252. /*
  1253. * Must do the disable sequence first to work
  1254. * for arbitrary current core state.
  1255. */
  1256. ai_core_disable(sih, (bits | resetbits));
  1257. /*
  1258. * Now do the initialization sequence.
  1259. */
  1260. W_REG(&ai->ioctrl, (bits | SICF_FGC | SICF_CLOCK_EN));
  1261. dummy = R_REG(&ai->ioctrl);
  1262. W_REG(&ai->resetctrl, 0);
  1263. udelay(1);
  1264. W_REG(&ai->ioctrl, (bits | SICF_CLOCK_EN));
  1265. dummy = R_REG(&ai->ioctrl);
  1266. udelay(1);
  1267. }
  1268. /* return the slow clock source - LPO, XTAL, or PCI */
  1269. static uint ai_slowclk_src(struct si_info *sii)
  1270. {
  1271. struct chipcregs __iomem *cc;
  1272. u32 val;
  1273. if (sii->pub.ccrev < 6) {
  1274. pci_read_config_dword(sii->pbus, PCI_GPIO_OUT,
  1275. &val);
  1276. if (val & PCI_CFG_GPIO_SCS)
  1277. return SCC_SS_PCI;
  1278. return SCC_SS_XTAL;
  1279. } else if (sii->pub.ccrev < 10) {
  1280. cc = (struct chipcregs __iomem *)
  1281. ai_setcoreidx(&sii->pub, sii->curidx);
  1282. return R_REG(&cc->slow_clk_ctl) & SCC_SS_MASK;
  1283. } else /* Insta-clock */
  1284. return SCC_SS_XTAL;
  1285. }
  1286. /*
  1287. * return the ILP (slowclock) min or max frequency
  1288. * precondition: we've established the chip has dynamic clk control
  1289. */
  1290. static uint ai_slowclk_freq(struct si_info *sii, bool max_freq,
  1291. struct chipcregs __iomem *cc)
  1292. {
  1293. u32 slowclk;
  1294. uint div;
  1295. slowclk = ai_slowclk_src(sii);
  1296. if (sii->pub.ccrev < 6) {
  1297. if (slowclk == SCC_SS_PCI)
  1298. return max_freq ? (PCIMAXFREQ / 64)
  1299. : (PCIMINFREQ / 64);
  1300. else
  1301. return max_freq ? (XTALMAXFREQ / 32)
  1302. : (XTALMINFREQ / 32);
  1303. } else if (sii->pub.ccrev < 10) {
  1304. div = 4 *
  1305. (((R_REG(&cc->slow_clk_ctl) & SCC_CD_MASK) >>
  1306. SCC_CD_SHIFT) + 1);
  1307. if (slowclk == SCC_SS_LPO)
  1308. return max_freq ? LPOMAXFREQ : LPOMINFREQ;
  1309. else if (slowclk == SCC_SS_XTAL)
  1310. return max_freq ? (XTALMAXFREQ / div)
  1311. : (XTALMINFREQ / div);
  1312. else if (slowclk == SCC_SS_PCI)
  1313. return max_freq ? (PCIMAXFREQ / div)
  1314. : (PCIMINFREQ / div);
  1315. } else {
  1316. /* Chipc rev 10 is InstaClock */
  1317. div = R_REG(&cc->system_clk_ctl) >> SYCC_CD_SHIFT;
  1318. div = 4 * (div + 1);
  1319. return max_freq ? XTALMAXFREQ : (XTALMINFREQ / div);
  1320. }
  1321. return 0;
  1322. }
  1323. static void
  1324. ai_clkctl_setdelay(struct si_info *sii, struct chipcregs __iomem *cc)
  1325. {
  1326. uint slowmaxfreq, pll_delay, slowclk;
  1327. uint pll_on_delay, fref_sel_delay;
  1328. pll_delay = PLL_DELAY;
  1329. /*
  1330. * If the slow clock is not sourced by the xtal then
  1331. * add the xtal_on_delay since the xtal will also be
  1332. * powered down by dynamic clk control logic.
  1333. */
  1334. slowclk = ai_slowclk_src(sii);
  1335. if (slowclk != SCC_SS_XTAL)
  1336. pll_delay += XTAL_ON_DELAY;
  1337. /* Starting with 4318 it is ILP that is used for the delays */
  1338. slowmaxfreq =
  1339. ai_slowclk_freq(sii, (sii->pub.ccrev >= 10) ? false : true, cc);
  1340. pll_on_delay = ((slowmaxfreq * pll_delay) + 999999) / 1000000;
  1341. fref_sel_delay = ((slowmaxfreq * FREF_DELAY) + 999999) / 1000000;
  1342. W_REG(&cc->pll_on_delay, pll_on_delay);
  1343. W_REG(&cc->fref_sel_delay, fref_sel_delay);
  1344. }
  1345. /* initialize power control delay registers */
  1346. void ai_clkctl_init(struct si_pub *sih)
  1347. {
  1348. struct si_info *sii;
  1349. uint origidx = 0;
  1350. struct chipcregs __iomem *cc;
  1351. bool fast;
  1352. if (!(sih->cccaps & CC_CAP_PWR_CTL))
  1353. return;
  1354. sii = (struct si_info *)sih;
  1355. fast = SI_FAST(sii);
  1356. if (!fast) {
  1357. origidx = sii->curidx;
  1358. cc = (struct chipcregs __iomem *)
  1359. ai_setcore(sih, CC_CORE_ID, 0);
  1360. if (cc == NULL)
  1361. return;
  1362. } else {
  1363. cc = (struct chipcregs __iomem *) CCREGS_FAST(sii);
  1364. if (cc == NULL)
  1365. return;
  1366. }
  1367. /* set all Instaclk chip ILP to 1 MHz */
  1368. if (sih->ccrev >= 10)
  1369. SET_REG(&cc->system_clk_ctl, SYCC_CD_MASK,
  1370. (ILP_DIV_1MHZ << SYCC_CD_SHIFT));
  1371. ai_clkctl_setdelay(sii, cc);
  1372. if (!fast)
  1373. ai_setcoreidx(sih, origidx);
  1374. }
  1375. /*
  1376. * return the value suitable for writing to the
  1377. * dot11 core FAST_PWRUP_DELAY register
  1378. */
  1379. u16 ai_clkctl_fast_pwrup_delay(struct si_pub *sih)
  1380. {
  1381. struct si_info *sii;
  1382. uint origidx = 0;
  1383. struct chipcregs __iomem *cc;
  1384. uint slowminfreq;
  1385. u16 fpdelay;
  1386. uint intr_val = 0;
  1387. bool fast;
  1388. sii = (struct si_info *)sih;
  1389. if (sih->cccaps & CC_CAP_PMU) {
  1390. INTR_OFF(sii, intr_val);
  1391. fpdelay = si_pmu_fast_pwrup_delay(sih);
  1392. INTR_RESTORE(sii, intr_val);
  1393. return fpdelay;
  1394. }
  1395. if (!(sih->cccaps & CC_CAP_PWR_CTL))
  1396. return 0;
  1397. fast = SI_FAST(sii);
  1398. fpdelay = 0;
  1399. if (!fast) {
  1400. origidx = sii->curidx;
  1401. INTR_OFF(sii, intr_val);
  1402. cc = (struct chipcregs __iomem *)
  1403. ai_setcore(sih, CC_CORE_ID, 0);
  1404. if (cc == NULL)
  1405. goto done;
  1406. } else {
  1407. cc = (struct chipcregs __iomem *) CCREGS_FAST(sii);
  1408. if (cc == NULL)
  1409. goto done;
  1410. }
  1411. slowminfreq = ai_slowclk_freq(sii, false, cc);
  1412. fpdelay = (((R_REG(&cc->pll_on_delay) + 2) * 1000000) +
  1413. (slowminfreq - 1)) / slowminfreq;
  1414. done:
  1415. if (!fast) {
  1416. ai_setcoreidx(sih, origidx);
  1417. INTR_RESTORE(sii, intr_val);
  1418. }
  1419. return fpdelay;
  1420. }
  1421. /* turn primary xtal and/or pll off/on */
  1422. int ai_clkctl_xtal(struct si_pub *sih, uint what, bool on)
  1423. {
  1424. struct si_info *sii;
  1425. u32 in, out, outen;
  1426. sii = (struct si_info *)sih;
  1427. /* pcie core doesn't have any mapping to control the xtal pu */
  1428. if (PCIE(sii))
  1429. return -1;
  1430. pci_read_config_dword(sii->pbus, PCI_GPIO_IN, &in);
  1431. pci_read_config_dword(sii->pbus, PCI_GPIO_OUT, &out);
  1432. pci_read_config_dword(sii->pbus, PCI_GPIO_OUTEN, &outen);
  1433. /*
  1434. * Avoid glitching the clock if GPRS is already using it.
  1435. * We can't actually read the state of the PLLPD so we infer it
  1436. * by the value of XTAL_PU which *is* readable via gpioin.
  1437. */
  1438. if (on && (in & PCI_CFG_GPIO_XTAL))
  1439. return 0;
  1440. if (what & XTAL)
  1441. outen |= PCI_CFG_GPIO_XTAL;
  1442. if (what & PLL)
  1443. outen |= PCI_CFG_GPIO_PLL;
  1444. if (on) {
  1445. /* turn primary xtal on */
  1446. if (what & XTAL) {
  1447. out |= PCI_CFG_GPIO_XTAL;
  1448. if (what & PLL)
  1449. out |= PCI_CFG_GPIO_PLL;
  1450. pci_write_config_dword(sii->pbus,
  1451. PCI_GPIO_OUT, out);
  1452. pci_write_config_dword(sii->pbus,
  1453. PCI_GPIO_OUTEN, outen);
  1454. udelay(XTAL_ON_DELAY);
  1455. }
  1456. /* turn pll on */
  1457. if (what & PLL) {
  1458. out &= ~PCI_CFG_GPIO_PLL;
  1459. pci_write_config_dword(sii->pbus,
  1460. PCI_GPIO_OUT, out);
  1461. mdelay(2);
  1462. }
  1463. } else {
  1464. if (what & XTAL)
  1465. out &= ~PCI_CFG_GPIO_XTAL;
  1466. if (what & PLL)
  1467. out |= PCI_CFG_GPIO_PLL;
  1468. pci_write_config_dword(sii->pbus,
  1469. PCI_GPIO_OUT, out);
  1470. pci_write_config_dword(sii->pbus,
  1471. PCI_GPIO_OUTEN, outen);
  1472. }
  1473. return 0;
  1474. }
  1475. /* clk control mechanism through chipcommon, no policy checking */
  1476. static bool _ai_clkctl_cc(struct si_info *sii, uint mode)
  1477. {
  1478. uint origidx = 0;
  1479. struct chipcregs __iomem *cc;
  1480. u32 scc;
  1481. uint intr_val = 0;
  1482. bool fast = SI_FAST(sii);
  1483. /* chipcommon cores prior to rev6 don't support dynamic clock control */
  1484. if (sii->pub.ccrev < 6)
  1485. return false;
  1486. if (!fast) {
  1487. INTR_OFF(sii, intr_val);
  1488. origidx = sii->curidx;
  1489. cc = (struct chipcregs __iomem *)
  1490. ai_setcore(&sii->pub, CC_CORE_ID, 0);
  1491. } else {
  1492. cc = (struct chipcregs __iomem *) CCREGS_FAST(sii);
  1493. if (cc == NULL)
  1494. goto done;
  1495. }
  1496. if (!(sii->pub.cccaps & CC_CAP_PWR_CTL) && (sii->pub.ccrev < 20))
  1497. goto done;
  1498. switch (mode) {
  1499. case CLK_FAST: /* FORCEHT, fast (pll) clock */
  1500. if (sii->pub.ccrev < 10) {
  1501. /*
  1502. * don't forget to force xtal back
  1503. * on before we clear SCC_DYN_XTAL..
  1504. */
  1505. ai_clkctl_xtal(&sii->pub, XTAL, ON);
  1506. SET_REG(&cc->slow_clk_ctl,
  1507. (SCC_XC | SCC_FS | SCC_IP), SCC_IP);
  1508. } else if (sii->pub.ccrev < 20) {
  1509. OR_REG(&cc->system_clk_ctl, SYCC_HR);
  1510. } else {
  1511. OR_REG(&cc->clk_ctl_st, CCS_FORCEHT);
  1512. }
  1513. /* wait for the PLL */
  1514. if (sii->pub.cccaps & CC_CAP_PMU) {
  1515. u32 htavail = CCS_HTAVAIL;
  1516. SPINWAIT(((R_REG(&cc->clk_ctl_st) & htavail)
  1517. == 0), PMU_MAX_TRANSITION_DLY);
  1518. } else {
  1519. udelay(PLL_DELAY);
  1520. }
  1521. break;
  1522. case CLK_DYNAMIC: /* enable dynamic clock control */
  1523. if (sii->pub.ccrev < 10) {
  1524. scc = R_REG(&cc->slow_clk_ctl);
  1525. scc &= ~(SCC_FS | SCC_IP | SCC_XC);
  1526. if ((scc & SCC_SS_MASK) != SCC_SS_XTAL)
  1527. scc |= SCC_XC;
  1528. W_REG(&cc->slow_clk_ctl, scc);
  1529. /*
  1530. * for dynamic control, we have to
  1531. * release our xtal_pu "force on"
  1532. */
  1533. if (scc & SCC_XC)
  1534. ai_clkctl_xtal(&sii->pub, XTAL, OFF);
  1535. } else if (sii->pub.ccrev < 20) {
  1536. /* Instaclock */
  1537. AND_REG(&cc->system_clk_ctl, ~SYCC_HR);
  1538. } else {
  1539. AND_REG(&cc->clk_ctl_st, ~CCS_FORCEHT);
  1540. }
  1541. break;
  1542. default:
  1543. break;
  1544. }
  1545. done:
  1546. if (!fast) {
  1547. ai_setcoreidx(&sii->pub, origidx);
  1548. INTR_RESTORE(sii, intr_val);
  1549. }
  1550. return mode == CLK_FAST;
  1551. }
  1552. /*
  1553. * clock control policy function throught chipcommon
  1554. *
  1555. * set dynamic clk control mode (forceslow, forcefast, dynamic)
  1556. * returns true if we are forcing fast clock
  1557. * this is a wrapper over the next internal function
  1558. * to allow flexible policy settings for outside caller
  1559. */
  1560. bool ai_clkctl_cc(struct si_pub *sih, uint mode)
  1561. {
  1562. struct si_info *sii;
  1563. sii = (struct si_info *)sih;
  1564. /* chipcommon cores prior to rev6 don't support dynamic clock control */
  1565. if (sih->ccrev < 6)
  1566. return false;
  1567. if (PCI_FORCEHT(sii))
  1568. return mode == CLK_FAST;
  1569. return _ai_clkctl_cc(sii, mode);
  1570. }
  1571. /* Build device path */
  1572. int ai_devpath(struct si_pub *sih, char *path, int size)
  1573. {
  1574. int slen;
  1575. if (!path || size <= 0)
  1576. return -1;
  1577. slen = snprintf(path, (size_t) size, "pci/%u/%u/",
  1578. ((struct si_info *)sih)->pbus->bus->number,
  1579. PCI_SLOT(((struct pci_dev *)
  1580. (((struct si_info *)(sih))->pbus))->devfn));
  1581. if (slen < 0 || slen >= size) {
  1582. path[0] = '\0';
  1583. return -1;
  1584. }
  1585. return 0;
  1586. }
  1587. void ai_pci_up(struct si_pub *sih)
  1588. {
  1589. struct si_info *sii;
  1590. sii = (struct si_info *)sih;
  1591. if (PCI_FORCEHT(sii))
  1592. _ai_clkctl_cc(sii, CLK_FAST);
  1593. if (PCIE(sii))
  1594. pcicore_up(sii->pch, SI_PCIUP);
  1595. }
  1596. /* Unconfigure and/or apply various WARs when system is going to sleep mode */
  1597. void ai_pci_sleep(struct si_pub *sih)
  1598. {
  1599. struct si_info *sii;
  1600. sii = (struct si_info *)sih;
  1601. pcicore_sleep(sii->pch);
  1602. }
  1603. /* Unconfigure and/or apply various WARs when going down */
  1604. void ai_pci_down(struct si_pub *sih)
  1605. {
  1606. struct si_info *sii;
  1607. sii = (struct si_info *)sih;
  1608. /* release FORCEHT since chip is going to "down" state */
  1609. if (PCI_FORCEHT(sii))
  1610. _ai_clkctl_cc(sii, CLK_DYNAMIC);
  1611. pcicore_down(sii->pch, SI_PCIDOWN);
  1612. }
  1613. /*
  1614. * Configure the pci core for pci client (NIC) action
  1615. * coremask is the bitvec of cores by index to be enabled.
  1616. */
  1617. void ai_pci_setup(struct si_pub *sih, uint coremask)
  1618. {
  1619. struct si_info *sii;
  1620. struct sbpciregs __iomem *regs = NULL;
  1621. u32 siflag = 0, w;
  1622. uint idx = 0;
  1623. sii = (struct si_info *)sih;
  1624. if (PCI(sii)) {
  1625. /* get current core index */
  1626. idx = sii->curidx;
  1627. /* we interrupt on this backplane flag number */
  1628. siflag = ai_flag(sih);
  1629. /* switch over to pci core */
  1630. regs = ai_setcoreidx(sih, sii->pub.buscoreidx);
  1631. }
  1632. /*
  1633. * Enable sb->pci interrupts. Assume
  1634. * PCI rev 2.3 support was added in pci core rev 6 and things changed..
  1635. */
  1636. if (PCIE(sii) || (PCI(sii) && ((sii->pub.buscorerev) >= 6))) {
  1637. /* pci config write to set this core bit in PCIIntMask */
  1638. pci_read_config_dword(sii->pbus, PCI_INT_MASK, &w);
  1639. w |= (coremask << PCI_SBIM_SHIFT);
  1640. pci_write_config_dword(sii->pbus, PCI_INT_MASK, w);
  1641. } else {
  1642. /* set sbintvec bit for our flag number */
  1643. ai_setint(sih, siflag);
  1644. }
  1645. if (PCI(sii)) {
  1646. pcicore_pci_setup(sii->pch, regs);
  1647. /* switch back to previous core */
  1648. ai_setcoreidx(sih, idx);
  1649. }
  1650. }
  1651. /*
  1652. * Fixup SROMless PCI device's configuration.
  1653. * The current core may be changed upon return.
  1654. */
  1655. int ai_pci_fixcfg(struct si_pub *sih)
  1656. {
  1657. uint origidx;
  1658. void __iomem *regs = NULL;
  1659. struct si_info *sii = (struct si_info *)sih;
  1660. /* Fixup PI in SROM shadow area to enable the correct PCI core access */
  1661. /* save the current index */
  1662. origidx = ai_coreidx(&sii->pub);
  1663. /* check 'pi' is correct and fix it if not */
  1664. regs = ai_setcore(&sii->pub, sii->pub.buscoretype, 0);
  1665. if (sii->pub.buscoretype == PCIE_CORE_ID)
  1666. pcicore_fixcfg_pcie(sii->pch,
  1667. (struct sbpcieregs __iomem *)regs);
  1668. else if (sii->pub.buscoretype == PCI_CORE_ID)
  1669. pcicore_fixcfg_pci(sii->pch, (struct sbpciregs __iomem *)regs);
  1670. /* restore the original index */
  1671. ai_setcoreidx(&sii->pub, origidx);
  1672. pcicore_hwup(sii->pch);
  1673. return 0;
  1674. }
  1675. /* mask&set gpiocontrol bits */
  1676. u32 ai_gpiocontrol(struct si_pub *sih, u32 mask, u32 val, u8 priority)
  1677. {
  1678. uint regoff;
  1679. regoff = offsetof(struct chipcregs, gpiocontrol);
  1680. return ai_corereg(sih, SI_CC_IDX, regoff, mask, val);
  1681. }
  1682. void ai_chipcontrl_epa4331(struct si_pub *sih, bool on)
  1683. {
  1684. struct si_info *sii;
  1685. struct chipcregs __iomem *cc;
  1686. uint origidx;
  1687. u32 val;
  1688. sii = (struct si_info *)sih;
  1689. origidx = ai_coreidx(sih);
  1690. cc = (struct chipcregs __iomem *) ai_setcore(sih, CC_CORE_ID, 0);
  1691. val = R_REG(&cc->chipcontrol);
  1692. if (on) {
  1693. if (sih->chippkg == 9 || sih->chippkg == 0xb)
  1694. /* Ext PA Controls for 4331 12x9 Package */
  1695. W_REG(&cc->chipcontrol, val |
  1696. CCTRL4331_EXTPA_EN |
  1697. CCTRL4331_EXTPA_ON_GPIO2_5);
  1698. else
  1699. /* Ext PA Controls for 4331 12x12 Package */
  1700. W_REG(&cc->chipcontrol,
  1701. val | CCTRL4331_EXTPA_EN);
  1702. } else {
  1703. val &= ~(CCTRL4331_EXTPA_EN | CCTRL4331_EXTPA_ON_GPIO2_5);
  1704. W_REG(&cc->chipcontrol, val);
  1705. }
  1706. ai_setcoreidx(sih, origidx);
  1707. }
  1708. /* Enable BT-COEX & Ex-PA for 4313 */
  1709. void ai_epa_4313war(struct si_pub *sih)
  1710. {
  1711. struct si_info *sii;
  1712. struct chipcregs __iomem *cc;
  1713. uint origidx;
  1714. sii = (struct si_info *)sih;
  1715. origidx = ai_coreidx(sih);
  1716. cc = ai_setcore(sih, CC_CORE_ID, 0);
  1717. /* EPA Fix */
  1718. W_REG(&cc->gpiocontrol,
  1719. R_REG(&cc->gpiocontrol) | GPIO_CTRL_EPA_EN_MASK);
  1720. ai_setcoreidx(sih, origidx);
  1721. }
  1722. /* check if the device is removed */
  1723. bool ai_deviceremoved(struct si_pub *sih)
  1724. {
  1725. u32 w;
  1726. struct si_info *sii;
  1727. sii = (struct si_info *)sih;
  1728. pci_read_config_dword(sii->pbus, PCI_VENDOR_ID, &w);
  1729. if ((w & 0xFFFF) != PCI_VENDOR_ID_BROADCOM)
  1730. return true;
  1731. return false;
  1732. }
  1733. bool ai_is_sprom_available(struct si_pub *sih)
  1734. {
  1735. if (sih->ccrev >= 31) {
  1736. struct si_info *sii;
  1737. uint origidx;
  1738. struct chipcregs __iomem *cc;
  1739. u32 sromctrl;
  1740. if ((sih->cccaps & CC_CAP_SROM) == 0)
  1741. return false;
  1742. sii = (struct si_info *)sih;
  1743. origidx = sii->curidx;
  1744. cc = ai_setcoreidx(sih, SI_CC_IDX);
  1745. sromctrl = R_REG(&cc->sromcontrol);
  1746. ai_setcoreidx(sih, origidx);
  1747. return sromctrl & SRC_PRESENT;
  1748. }
  1749. switch (sih->chip) {
  1750. case BCM4313_CHIP_ID:
  1751. return (sih->chipst & CST4313_SPROM_PRESENT) != 0;
  1752. default:
  1753. return true;
  1754. }
  1755. }
  1756. bool ai_is_otp_disabled(struct si_pub *sih)
  1757. {
  1758. switch (sih->chip) {
  1759. case BCM4313_CHIP_ID:
  1760. return (sih->chipst & CST4313_OTP_PRESENT) == 0;
  1761. /* These chips always have their OTP on */
  1762. case BCM43224_CHIP_ID:
  1763. case BCM43225_CHIP_ID:
  1764. default:
  1765. return false;
  1766. }
  1767. }