aiutils.c 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641
  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. #define IS_SIM(chippkg) \
  290. ((chippkg == HDLSIM_PKG_ID) || (chippkg == HWSIM_PKG_ID))
  291. /*
  292. * Macros to disable/restore function core(D11, ENET, ILINE20, etc) interrupts
  293. * before after core switching to avoid invalid register accesss inside ISR.
  294. */
  295. #define INTR_OFF(si, intr_val) \
  296. if ((si)->intrsoff_fn && \
  297. (si)->coreid[(si)->curidx] == (si)->dev_coreid) \
  298. intr_val = (*(si)->intrsoff_fn)((si)->intr_arg)
  299. #define INTR_RESTORE(si, intr_val) \
  300. if ((si)->intrsrestore_fn && \
  301. (si)->coreid[(si)->curidx] == (si)->dev_coreid) \
  302. (*(si)->intrsrestore_fn)((si)->intr_arg, intr_val)
  303. #define PCI(sih) (ai_get_buscoretype(sih) == PCI_CORE_ID)
  304. #define PCIE(sih) (ai_get_buscoretype(sih) == PCIE_CORE_ID)
  305. #define PCI_FORCEHT(sih) (PCIE(sih) && (ai_get_chip_id(sih) == BCM4716_CHIP_ID))
  306. #ifdef BCMDBG
  307. #define SI_MSG(fmt, ...) pr_debug(fmt, ##__VA_ARGS__)
  308. #else
  309. #define SI_MSG(fmt, ...) no_printk(fmt, ##__VA_ARGS__)
  310. #endif /* BCMDBG */
  311. #define GOODCOREADDR(x, b) \
  312. (((x) >= (b)) && ((x) < ((b) + SI_MAXCORES * SI_CORE_SIZE)) && \
  313. IS_ALIGNED((x), SI_CORE_SIZE))
  314. struct aidmp {
  315. u32 oobselina30; /* 0x000 */
  316. u32 oobselina74; /* 0x004 */
  317. u32 PAD[6];
  318. u32 oobselinb30; /* 0x020 */
  319. u32 oobselinb74; /* 0x024 */
  320. u32 PAD[6];
  321. u32 oobselinc30; /* 0x040 */
  322. u32 oobselinc74; /* 0x044 */
  323. u32 PAD[6];
  324. u32 oobselind30; /* 0x060 */
  325. u32 oobselind74; /* 0x064 */
  326. u32 PAD[38];
  327. u32 oobselouta30; /* 0x100 */
  328. u32 oobselouta74; /* 0x104 */
  329. u32 PAD[6];
  330. u32 oobseloutb30; /* 0x120 */
  331. u32 oobseloutb74; /* 0x124 */
  332. u32 PAD[6];
  333. u32 oobseloutc30; /* 0x140 */
  334. u32 oobseloutc74; /* 0x144 */
  335. u32 PAD[6];
  336. u32 oobseloutd30; /* 0x160 */
  337. u32 oobseloutd74; /* 0x164 */
  338. u32 PAD[38];
  339. u32 oobsynca; /* 0x200 */
  340. u32 oobseloutaen; /* 0x204 */
  341. u32 PAD[6];
  342. u32 oobsyncb; /* 0x220 */
  343. u32 oobseloutben; /* 0x224 */
  344. u32 PAD[6];
  345. u32 oobsyncc; /* 0x240 */
  346. u32 oobseloutcen; /* 0x244 */
  347. u32 PAD[6];
  348. u32 oobsyncd; /* 0x260 */
  349. u32 oobseloutden; /* 0x264 */
  350. u32 PAD[38];
  351. u32 oobaextwidth; /* 0x300 */
  352. u32 oobainwidth; /* 0x304 */
  353. u32 oobaoutwidth; /* 0x308 */
  354. u32 PAD[5];
  355. u32 oobbextwidth; /* 0x320 */
  356. u32 oobbinwidth; /* 0x324 */
  357. u32 oobboutwidth; /* 0x328 */
  358. u32 PAD[5];
  359. u32 oobcextwidth; /* 0x340 */
  360. u32 oobcinwidth; /* 0x344 */
  361. u32 oobcoutwidth; /* 0x348 */
  362. u32 PAD[5];
  363. u32 oobdextwidth; /* 0x360 */
  364. u32 oobdinwidth; /* 0x364 */
  365. u32 oobdoutwidth; /* 0x368 */
  366. u32 PAD[37];
  367. u32 ioctrlset; /* 0x400 */
  368. u32 ioctrlclear; /* 0x404 */
  369. u32 ioctrl; /* 0x408 */
  370. u32 PAD[61];
  371. u32 iostatus; /* 0x500 */
  372. u32 PAD[127];
  373. u32 ioctrlwidth; /* 0x700 */
  374. u32 iostatuswidth; /* 0x704 */
  375. u32 PAD[62];
  376. u32 resetctrl; /* 0x800 */
  377. u32 resetstatus; /* 0x804 */
  378. u32 resetreadid; /* 0x808 */
  379. u32 resetwriteid; /* 0x80c */
  380. u32 PAD[60];
  381. u32 errlogctrl; /* 0x900 */
  382. u32 errlogdone; /* 0x904 */
  383. u32 errlogstatus; /* 0x908 */
  384. u32 errlogaddrlo; /* 0x90c */
  385. u32 errlogaddrhi; /* 0x910 */
  386. u32 errlogid; /* 0x914 */
  387. u32 errloguser; /* 0x918 */
  388. u32 errlogflags; /* 0x91c */
  389. u32 PAD[56];
  390. u32 intstatus; /* 0xa00 */
  391. u32 PAD[127];
  392. u32 config; /* 0xe00 */
  393. u32 PAD[63];
  394. u32 itcr; /* 0xf00 */
  395. u32 PAD[3];
  396. u32 itipooba; /* 0xf10 */
  397. u32 itipoobb; /* 0xf14 */
  398. u32 itipoobc; /* 0xf18 */
  399. u32 itipoobd; /* 0xf1c */
  400. u32 PAD[4];
  401. u32 itipoobaout; /* 0xf30 */
  402. u32 itipoobbout; /* 0xf34 */
  403. u32 itipoobcout; /* 0xf38 */
  404. u32 itipoobdout; /* 0xf3c */
  405. u32 PAD[4];
  406. u32 itopooba; /* 0xf50 */
  407. u32 itopoobb; /* 0xf54 */
  408. u32 itopoobc; /* 0xf58 */
  409. u32 itopoobd; /* 0xf5c */
  410. u32 PAD[4];
  411. u32 itopoobain; /* 0xf70 */
  412. u32 itopoobbin; /* 0xf74 */
  413. u32 itopoobcin; /* 0xf78 */
  414. u32 itopoobdin; /* 0xf7c */
  415. u32 PAD[4];
  416. u32 itopreset; /* 0xf90 */
  417. u32 PAD[15];
  418. u32 peripherialid4; /* 0xfd0 */
  419. u32 peripherialid5; /* 0xfd4 */
  420. u32 peripherialid6; /* 0xfd8 */
  421. u32 peripherialid7; /* 0xfdc */
  422. u32 peripherialid0; /* 0xfe0 */
  423. u32 peripherialid1; /* 0xfe4 */
  424. u32 peripherialid2; /* 0xfe8 */
  425. u32 peripherialid3; /* 0xfec */
  426. u32 componentid0; /* 0xff0 */
  427. u32 componentid1; /* 0xff4 */
  428. u32 componentid2; /* 0xff8 */
  429. u32 componentid3; /* 0xffc */
  430. };
  431. /* parse the enumeration rom to identify all cores */
  432. static void ai_scan(struct si_pub *sih, struct bcma_bus *bus)
  433. {
  434. struct si_info *sii = (struct si_info *)sih;
  435. struct bcma_device *core;
  436. uint idx;
  437. list_for_each_entry(core, &bus->cores, list) {
  438. idx = core->core_index;
  439. sii->cia[idx] = core->id.manuf << CIA_MFG_SHIFT;
  440. sii->cia[idx] |= core->id.id << CIA_CID_SHIFT;
  441. sii->cia[idx] |= core->id.class << CIA_CCL_SHIFT;
  442. sii->cib[idx] = core->id.rev << CIB_REV_SHIFT;
  443. sii->coreid[idx] = core->id.id;
  444. sii->coresba[idx] = core->addr;
  445. sii->coresba_size[idx] = 0x1000;
  446. sii->coresba2[idx] = 0;
  447. sii->coresba2_size[idx] = 0;
  448. sii->wrapba[idx] = core->wrap;
  449. sii->numcores++;
  450. }
  451. }
  452. static struct bcma_device *ai_find_bcma_core(struct si_pub *sih, uint coreidx)
  453. {
  454. struct si_info *sii = (struct si_info *)sih;
  455. struct bcma_device *core;
  456. list_for_each_entry(core, &sii->icbus->cores, list) {
  457. if (core->core_index == coreidx)
  458. return core;
  459. }
  460. return NULL;
  461. }
  462. /*
  463. * This function changes the logical "focus" to the indicated core.
  464. * Return the current core's virtual address. Since each core starts with the
  465. * same set of registers (BIST, clock control, etc), the returned address
  466. * contains the first register of this 'common' register block (not to be
  467. * confused with 'common core').
  468. */
  469. void __iomem *ai_setcoreidx(struct si_pub *sih, uint coreidx)
  470. {
  471. struct si_info *sii = (struct si_info *)sih;
  472. struct bcma_device *core;
  473. if (sii->curidx != coreidx) {
  474. core = ai_find_bcma_core(sih, coreidx);
  475. if (core == NULL)
  476. return NULL;
  477. (void)bcma_aread32(core, BCMA_IOST);
  478. sii->curidx = coreidx;
  479. }
  480. return sii->curmap;
  481. }
  482. uint ai_corerev(struct si_pub *sih)
  483. {
  484. struct si_info *sii;
  485. u32 cib;
  486. sii = (struct si_info *)sih;
  487. cib = sii->cib[sii->curidx];
  488. return (cib & CIB_REV_MASK) >> CIB_REV_SHIFT;
  489. }
  490. bool ai_iscoreup(struct si_pub *sih)
  491. {
  492. struct si_info *sii;
  493. struct aidmp *ai;
  494. sii = (struct si_info *)sih;
  495. ai = sii->curwrap;
  496. return (((R_REG(&ai->ioctrl) & (SICF_FGC | SICF_CLOCK_EN)) ==
  497. SICF_CLOCK_EN)
  498. && ((R_REG(&ai->resetctrl) & AIRC_RESET) == 0));
  499. }
  500. u32 ai_core_cflags(struct si_pub *sih, u32 mask, u32 val)
  501. {
  502. struct si_info *sii;
  503. struct aidmp *ai;
  504. u32 w;
  505. sii = (struct si_info *)sih;
  506. ai = sii->curwrap;
  507. if (mask || val) {
  508. w = ((R_REG(&ai->ioctrl) & ~mask) | val);
  509. W_REG(&ai->ioctrl, w);
  510. }
  511. return R_REG(&ai->ioctrl);
  512. }
  513. /* return true if PCIE capability exists in the pci config space */
  514. static bool ai_ispcie(struct si_info *sii)
  515. {
  516. u8 cap_ptr;
  517. cap_ptr =
  518. pcicore_find_pci_capability(sii->pcibus, PCI_CAP_ID_EXP, NULL,
  519. NULL);
  520. if (!cap_ptr)
  521. return false;
  522. return true;
  523. }
  524. static bool ai_buscore_prep(struct si_info *sii)
  525. {
  526. /* kludge to enable the clock on the 4306 which lacks a slowclock */
  527. if (!ai_ispcie(sii))
  528. ai_clkctl_xtal(&sii->pub, XTAL | PLL, ON);
  529. return true;
  530. }
  531. u32 ai_core_sflags(struct si_pub *sih, u32 mask, u32 val)
  532. {
  533. struct si_info *sii;
  534. struct aidmp *ai;
  535. u32 w;
  536. sii = (struct si_info *)sih;
  537. ai = sii->curwrap;
  538. if (mask || val) {
  539. w = ((R_REG(&ai->iostatus) & ~mask) | val);
  540. W_REG(&ai->iostatus, w);
  541. }
  542. return R_REG(&ai->iostatus);
  543. }
  544. static bool
  545. ai_buscore_setup(struct si_info *sii, u32 savewin, uint *origidx)
  546. {
  547. bool pci, pcie;
  548. uint i;
  549. uint pciidx, pcieidx, pcirev, pcierev;
  550. struct chipcregs __iomem *cc;
  551. cc = ai_setcoreidx(&sii->pub, SI_CC_IDX);
  552. /* get chipcommon rev */
  553. sii->pub.ccrev = (int)ai_corerev(&sii->pub);
  554. /* get chipcommon chipstatus */
  555. if (ai_get_ccrev(&sii->pub) >= 11)
  556. sii->chipst = R_REG(&cc->chipstatus);
  557. /* get chipcommon capabilites */
  558. sii->pub.cccaps = R_REG(&cc->capabilities);
  559. /* get pmu rev and caps */
  560. if (ai_get_cccaps(&sii->pub) & CC_CAP_PMU) {
  561. sii->pub.pmucaps = R_REG(&cc->pmucapabilities);
  562. sii->pub.pmurev = sii->pub.pmucaps & PCAP_REV_MASK;
  563. }
  564. /* figure out bus/orignal core idx */
  565. sii->pub.buscoretype = NODEV_CORE_ID;
  566. sii->pub.buscorerev = NOREV;
  567. sii->buscoreidx = BADIDX;
  568. pci = pcie = false;
  569. pcirev = pcierev = NOREV;
  570. pciidx = pcieidx = BADIDX;
  571. for (i = 0; i < sii->numcores; i++) {
  572. uint cid, crev;
  573. ai_setcoreidx(&sii->pub, i);
  574. cid = ai_coreid(&sii->pub);
  575. crev = ai_corerev(&sii->pub);
  576. if (cid == PCI_CORE_ID) {
  577. pciidx = i;
  578. pcirev = crev;
  579. pci = true;
  580. } else if (cid == PCIE_CORE_ID) {
  581. pcieidx = i;
  582. pcierev = crev;
  583. pcie = true;
  584. }
  585. /* find the core idx before entering this func. */
  586. if ((savewin && (savewin == sii->coresba[i])) ||
  587. (cc == sii->regs[i]))
  588. *origidx = i;
  589. }
  590. if (pci && pcie) {
  591. if (ai_ispcie(sii))
  592. pci = false;
  593. else
  594. pcie = false;
  595. }
  596. if (pci) {
  597. sii->pub.buscoretype = PCI_CORE_ID;
  598. sii->pub.buscorerev = pcirev;
  599. sii->buscoreidx = pciidx;
  600. } else if (pcie) {
  601. sii->pub.buscoretype = PCIE_CORE_ID;
  602. sii->pub.buscorerev = pcierev;
  603. sii->buscoreidx = pcieidx;
  604. }
  605. /* fixup necessary chip/core configurations */
  606. if (!sii->pch) {
  607. sii->pch = pcicore_init(&sii->pub, sii->pcibus,
  608. sii->curmap + PCI_16KB0_PCIREGS_OFFSET);
  609. if (sii->pch == NULL)
  610. return false;
  611. }
  612. if (ai_pci_fixcfg(&sii->pub)) {
  613. /* si_doattach: si_pci_fixcfg failed */
  614. return false;
  615. }
  616. /* return to the original core */
  617. ai_setcoreidx(&sii->pub, *origidx);
  618. return true;
  619. }
  620. /*
  621. * get boardtype and boardrev
  622. */
  623. static __used void ai_nvram_process(struct si_info *sii)
  624. {
  625. uint w = 0;
  626. /* do a pci config read to get subsystem id and subvendor id */
  627. pci_read_config_dword(sii->pcibus, PCI_SUBSYSTEM_VENDOR_ID, &w);
  628. sii->pub.boardvendor = w & 0xffff;
  629. sii->pub.boardtype = (w >> 16) & 0xffff;
  630. }
  631. static struct si_info *ai_doattach(struct si_info *sii,
  632. struct bcma_bus *pbus)
  633. {
  634. void __iomem *regs = pbus->mmio;
  635. struct si_pub *sih = &sii->pub;
  636. u32 w, savewin;
  637. struct chipcregs __iomem *cc;
  638. uint socitype;
  639. uint origidx;
  640. memset((unsigned char *) sii, 0, sizeof(struct si_info));
  641. savewin = 0;
  642. sii->icbus = pbus;
  643. sii->buscoreidx = BADIDX;
  644. sii->pcibus = pbus->host_pci;
  645. sii->curmap = regs;
  646. sii->curwrap = sii->curmap + SI_CORE_SIZE;
  647. /* switch to Chipcommon core */
  648. bcma_read32(pbus->drv_cc.core, 0);
  649. savewin = SI_ENUM_BASE;
  650. cc = (struct chipcregs __iomem *) regs;
  651. /* bus/core/clk setup for register access */
  652. if (!ai_buscore_prep(sii))
  653. return NULL;
  654. /*
  655. * ChipID recognition.
  656. * We assume we can read chipid at offset 0 from the regs arg.
  657. * If we add other chiptypes (or if we need to support old sdio
  658. * hosts w/o chipcommon), some way of recognizing them needs to
  659. * be added here.
  660. */
  661. w = R_REG(&cc->chipid);
  662. socitype = (w & CID_TYPE_MASK) >> CID_TYPE_SHIFT;
  663. /* Might as wll fill in chip id rev & pkg */
  664. sih->chip = w & CID_ID_MASK;
  665. sih->chiprev = (w & CID_REV_MASK) >> CID_REV_SHIFT;
  666. sih->chippkg = (w & CID_PKG_MASK) >> CID_PKG_SHIFT;
  667. /* scan for cores */
  668. if (socitype == SOCI_AI) {
  669. SI_MSG("Found chip type AI (0x%08x)\n", w);
  670. /* pass chipc address instead of original core base */
  671. ai_scan(&sii->pub, pbus);
  672. } else {
  673. /* Found chip of unknown type */
  674. return NULL;
  675. }
  676. /* no cores found, bail out */
  677. if (sii->numcores == 0)
  678. return NULL;
  679. /* bus/core/clk setup */
  680. origidx = SI_CC_IDX;
  681. if (!ai_buscore_setup(sii, savewin, &origidx))
  682. goto exit;
  683. /* Init nvram from sprom/otp if they exist */
  684. if (srom_var_init(&sii->pub, cc))
  685. goto exit;
  686. ai_nvram_process(sii);
  687. /* === NVRAM, clock is ready === */
  688. cc = (struct chipcregs __iomem *) ai_setcore(sih, CC_CORE_ID, 0);
  689. W_REG(&cc->gpiopullup, 0);
  690. W_REG(&cc->gpiopulldown, 0);
  691. ai_setcoreidx(sih, origidx);
  692. /* PMU specific initializations */
  693. if (ai_get_cccaps(sih) & CC_CAP_PMU) {
  694. u32 xtalfreq;
  695. si_pmu_init(sih);
  696. si_pmu_chip_init(sih);
  697. xtalfreq = si_pmu_measure_alpclk(sih);
  698. si_pmu_pll_init(sih, xtalfreq);
  699. si_pmu_res_init(sih);
  700. si_pmu_swreg_init(sih);
  701. }
  702. /* setup the GPIO based LED powersave register */
  703. w = getintvar(sih, BRCMS_SROM_LEDDC);
  704. if (w == 0)
  705. w = DEFAULT_GPIOTIMERVAL;
  706. ai_cc_reg(sih, offsetof(struct chipcregs, gpiotimerval),
  707. ~0, w);
  708. if (PCIE(sih))
  709. pcicore_attach(sii->pch, SI_DOATTACH);
  710. if (ai_get_chip_id(sih) == BCM43224_CHIP_ID) {
  711. /*
  712. * enable 12 mA drive strenth for 43224 and
  713. * set chipControl register bit 15
  714. */
  715. if (ai_get_chiprev(sih) == 0) {
  716. SI_MSG("Applying 43224A0 WARs\n");
  717. ai_cc_reg(sih, offsetof(struct chipcregs, chipcontrol),
  718. CCTRL43224_GPIO_TOGGLE,
  719. CCTRL43224_GPIO_TOGGLE);
  720. si_pmu_chipcontrol(sih, 0, CCTRL_43224A0_12MA_LED_DRIVE,
  721. CCTRL_43224A0_12MA_LED_DRIVE);
  722. }
  723. if (ai_get_chiprev(sih) >= 1) {
  724. SI_MSG("Applying 43224B0+ WARs\n");
  725. si_pmu_chipcontrol(sih, 0, CCTRL_43224B0_12MA_LED_DRIVE,
  726. CCTRL_43224B0_12MA_LED_DRIVE);
  727. }
  728. }
  729. if (ai_get_chip_id(sih) == BCM4313_CHIP_ID) {
  730. /*
  731. * enable 12 mA drive strenth for 4313 and
  732. * set chipControl register bit 1
  733. */
  734. SI_MSG("Applying 4313 WARs\n");
  735. si_pmu_chipcontrol(sih, 0, CCTRL_4313_12MA_LED_DRIVE,
  736. CCTRL_4313_12MA_LED_DRIVE);
  737. }
  738. return sii;
  739. exit:
  740. if (sii->pch)
  741. pcicore_deinit(sii->pch);
  742. sii->pch = NULL;
  743. return NULL;
  744. }
  745. /*
  746. * Allocate a si handle and do the attach.
  747. */
  748. struct si_pub *
  749. ai_attach(struct bcma_bus *pbus)
  750. {
  751. struct si_info *sii;
  752. /* alloc struct si_info */
  753. sii = kmalloc(sizeof(struct si_info), GFP_ATOMIC);
  754. if (sii == NULL)
  755. return NULL;
  756. if (ai_doattach(sii, pbus) == NULL) {
  757. kfree(sii);
  758. return NULL;
  759. }
  760. return (struct si_pub *) sii;
  761. }
  762. /* may be called with core in reset */
  763. void ai_detach(struct si_pub *sih)
  764. {
  765. struct si_info *sii;
  766. struct si_pub *si_local = NULL;
  767. memcpy(&si_local, &sih, sizeof(struct si_pub **));
  768. sii = (struct si_info *)sih;
  769. if (sii == NULL)
  770. return;
  771. if (sii->pch)
  772. pcicore_deinit(sii->pch);
  773. sii->pch = NULL;
  774. srom_free_vars(sih);
  775. kfree(sii);
  776. }
  777. /* register driver interrupt disabling and restoring callback functions */
  778. void
  779. ai_register_intr_callback(struct si_pub *sih, void *intrsoff_fn,
  780. void *intrsrestore_fn,
  781. void *intrsenabled_fn, void *intr_arg)
  782. {
  783. struct si_info *sii;
  784. sii = (struct si_info *)sih;
  785. sii->intr_arg = intr_arg;
  786. sii->intrsoff_fn = (u32 (*)(void *)) intrsoff_fn;
  787. sii->intrsrestore_fn = (void (*) (void *, u32)) intrsrestore_fn;
  788. sii->intrsenabled_fn = (bool (*)(void *)) intrsenabled_fn;
  789. /* save current core id. when this function called, the current core
  790. * must be the core which provides driver functions(il, et, wl, etc.)
  791. */
  792. sii->dev_coreid = sii->coreid[sii->curidx];
  793. }
  794. void ai_deregister_intr_callback(struct si_pub *sih)
  795. {
  796. struct si_info *sii;
  797. sii = (struct si_info *)sih;
  798. sii->intrsoff_fn = NULL;
  799. }
  800. uint ai_coreid(struct si_pub *sih)
  801. {
  802. struct si_info *sii;
  803. sii = (struct si_info *)sih;
  804. return sii->coreid[sii->curidx];
  805. }
  806. uint ai_coreidx(struct si_pub *sih)
  807. {
  808. struct si_info *sii;
  809. sii = (struct si_info *)sih;
  810. return sii->curidx;
  811. }
  812. /* return index of coreid or BADIDX if not found */
  813. uint ai_findcoreidx(struct si_pub *sih, uint coreid, uint coreunit)
  814. {
  815. struct bcma_device *core;
  816. struct si_info *sii;
  817. uint found;
  818. sii = (struct si_info *)sih;
  819. found = 0;
  820. list_for_each_entry(core, &sii->icbus->cores, list)
  821. if (core->id.id == coreid) {
  822. if (found == coreunit)
  823. return core->core_index;
  824. found++;
  825. }
  826. return BADIDX;
  827. }
  828. /*
  829. * This function changes logical "focus" to the indicated core;
  830. * must be called with interrupts off.
  831. * Moreover, callers should keep interrupts off during switching
  832. * out of and back to d11 core.
  833. */
  834. void __iomem *ai_setcore(struct si_pub *sih, uint coreid, uint coreunit)
  835. {
  836. uint idx;
  837. idx = ai_findcoreidx(sih, coreid, coreunit);
  838. if (idx >= SI_MAXCORES)
  839. return NULL;
  840. return ai_setcoreidx(sih, idx);
  841. }
  842. /* Turn off interrupt as required by ai_setcore, before switch core */
  843. void __iomem *ai_switch_core(struct si_pub *sih, uint coreid, uint *origidx,
  844. uint *intr_val)
  845. {
  846. void __iomem *cc;
  847. struct si_info *sii;
  848. sii = (struct si_info *)sih;
  849. INTR_OFF(sii, *intr_val);
  850. *origidx = sii->curidx;
  851. cc = ai_setcore(sih, coreid, 0);
  852. return cc;
  853. }
  854. /* restore coreidx and restore interrupt */
  855. void ai_restore_core(struct si_pub *sih, uint coreid, uint intr_val)
  856. {
  857. struct si_info *sii;
  858. sii = (struct si_info *)sih;
  859. ai_setcoreidx(sih, coreid);
  860. INTR_RESTORE(sii, intr_val);
  861. }
  862. /*
  863. * Switch to 'coreidx', issue a single arbitrary 32bit register mask&set
  864. * operation, switch back to the original core, and return the new value.
  865. *
  866. * When using the silicon backplane, no fiddling with interrupts or core
  867. * switches is needed.
  868. *
  869. * Also, when using pci/pcie, we can optimize away the core switching for pci
  870. * registers and (on newer pci cores) chipcommon registers.
  871. */
  872. uint ai_cc_reg(struct si_pub *sih, uint regoff, u32 mask, u32 val)
  873. {
  874. struct bcma_device *cc;
  875. uint origidx = 0;
  876. u32 w;
  877. uint intr_val = 0;
  878. struct si_info *sii;
  879. sii = (struct si_info *)sih;
  880. cc = sii->icbus->drv_cc.core;
  881. INTR_OFF(sii, intr_val);
  882. /* save current core index */
  883. origidx = ai_coreidx(&sii->pub);
  884. /* mask and set */
  885. if (mask || val) {
  886. bcma_maskset32(cc, regoff, ~mask, val);
  887. }
  888. /* readback */
  889. w = bcma_read32(cc, regoff);
  890. /* restore core index */
  891. ai_setcoreidx(&sii->pub, origidx);
  892. INTR_RESTORE(sii, intr_val);
  893. return w;
  894. }
  895. void ai_core_disable(struct si_pub *sih, u32 bits)
  896. {
  897. struct si_info *sii;
  898. u32 dummy;
  899. struct aidmp *ai;
  900. sii = (struct si_info *)sih;
  901. ai = sii->curwrap;
  902. /* if core is already in reset, just return */
  903. if (R_REG(&ai->resetctrl) & AIRC_RESET)
  904. return;
  905. W_REG(&ai->ioctrl, bits);
  906. dummy = R_REG(&ai->ioctrl);
  907. udelay(10);
  908. W_REG(&ai->resetctrl, AIRC_RESET);
  909. udelay(1);
  910. }
  911. /* reset and re-enable a core
  912. * inputs:
  913. * bits - core specific bits that are set during and after reset sequence
  914. * resetbits - core specific bits that are set only during reset sequence
  915. */
  916. void ai_core_reset(struct si_pub *sih, u32 bits, u32 resetbits)
  917. {
  918. struct si_info *sii;
  919. struct aidmp *ai;
  920. u32 dummy;
  921. sii = (struct si_info *)sih;
  922. ai = sii->curwrap;
  923. /*
  924. * Must do the disable sequence first to work
  925. * for arbitrary current core state.
  926. */
  927. ai_core_disable(sih, (bits | resetbits));
  928. /*
  929. * Now do the initialization sequence.
  930. */
  931. W_REG(&ai->ioctrl, (bits | SICF_FGC | SICF_CLOCK_EN));
  932. dummy = R_REG(&ai->ioctrl);
  933. W_REG(&ai->resetctrl, 0);
  934. udelay(1);
  935. W_REG(&ai->ioctrl, (bits | SICF_CLOCK_EN));
  936. dummy = R_REG(&ai->ioctrl);
  937. udelay(1);
  938. }
  939. /* return the slow clock source - LPO, XTAL, or PCI */
  940. static uint ai_slowclk_src(struct si_info *sii)
  941. {
  942. struct chipcregs __iomem *cc;
  943. u32 val;
  944. if (ai_get_ccrev(&sii->pub) < 6) {
  945. pci_read_config_dword(sii->pcibus, PCI_GPIO_OUT,
  946. &val);
  947. if (val & PCI_CFG_GPIO_SCS)
  948. return SCC_SS_PCI;
  949. return SCC_SS_XTAL;
  950. } else if (ai_get_ccrev(&sii->pub) < 10) {
  951. cc = (struct chipcregs __iomem *)
  952. ai_setcoreidx(&sii->pub, sii->curidx);
  953. return R_REG(&cc->slow_clk_ctl) & SCC_SS_MASK;
  954. } else /* Insta-clock */
  955. return SCC_SS_XTAL;
  956. }
  957. /*
  958. * return the ILP (slowclock) min or max frequency
  959. * precondition: we've established the chip has dynamic clk control
  960. */
  961. static uint ai_slowclk_freq(struct si_info *sii, bool max_freq,
  962. struct chipcregs __iomem *cc)
  963. {
  964. u32 slowclk;
  965. uint div;
  966. slowclk = ai_slowclk_src(sii);
  967. if (ai_get_ccrev(&sii->pub) < 6) {
  968. if (slowclk == SCC_SS_PCI)
  969. return max_freq ? (PCIMAXFREQ / 64)
  970. : (PCIMINFREQ / 64);
  971. else
  972. return max_freq ? (XTALMAXFREQ / 32)
  973. : (XTALMINFREQ / 32);
  974. } else if (ai_get_ccrev(&sii->pub) < 10) {
  975. div = 4 *
  976. (((R_REG(&cc->slow_clk_ctl) & SCC_CD_MASK) >>
  977. SCC_CD_SHIFT) + 1);
  978. if (slowclk == SCC_SS_LPO)
  979. return max_freq ? LPOMAXFREQ : LPOMINFREQ;
  980. else if (slowclk == SCC_SS_XTAL)
  981. return max_freq ? (XTALMAXFREQ / div)
  982. : (XTALMINFREQ / div);
  983. else if (slowclk == SCC_SS_PCI)
  984. return max_freq ? (PCIMAXFREQ / div)
  985. : (PCIMINFREQ / div);
  986. } else {
  987. /* Chipc rev 10 is InstaClock */
  988. div = R_REG(&cc->system_clk_ctl) >> SYCC_CD_SHIFT;
  989. div = 4 * (div + 1);
  990. return max_freq ? XTALMAXFREQ : (XTALMINFREQ / div);
  991. }
  992. return 0;
  993. }
  994. static void
  995. ai_clkctl_setdelay(struct si_info *sii, struct chipcregs __iomem *cc)
  996. {
  997. uint slowmaxfreq, pll_delay, slowclk;
  998. uint pll_on_delay, fref_sel_delay;
  999. pll_delay = PLL_DELAY;
  1000. /*
  1001. * If the slow clock is not sourced by the xtal then
  1002. * add the xtal_on_delay since the xtal will also be
  1003. * powered down by dynamic clk control logic.
  1004. */
  1005. slowclk = ai_slowclk_src(sii);
  1006. if (slowclk != SCC_SS_XTAL)
  1007. pll_delay += XTAL_ON_DELAY;
  1008. /* Starting with 4318 it is ILP that is used for the delays */
  1009. slowmaxfreq =
  1010. ai_slowclk_freq(sii,
  1011. (ai_get_ccrev(&sii->pub) >= 10) ? false : true, cc);
  1012. pll_on_delay = ((slowmaxfreq * pll_delay) + 999999) / 1000000;
  1013. fref_sel_delay = ((slowmaxfreq * FREF_DELAY) + 999999) / 1000000;
  1014. W_REG(&cc->pll_on_delay, pll_on_delay);
  1015. W_REG(&cc->fref_sel_delay, fref_sel_delay);
  1016. }
  1017. /* initialize power control delay registers */
  1018. void ai_clkctl_init(struct si_pub *sih)
  1019. {
  1020. struct si_info *sii;
  1021. uint origidx = 0;
  1022. struct chipcregs __iomem *cc;
  1023. if (!(ai_get_cccaps(sih) & CC_CAP_PWR_CTL))
  1024. return;
  1025. sii = (struct si_info *)sih;
  1026. origidx = sii->curidx;
  1027. cc = (struct chipcregs __iomem *)
  1028. ai_setcore(sih, CC_CORE_ID, 0);
  1029. if (cc == NULL)
  1030. return;
  1031. /* set all Instaclk chip ILP to 1 MHz */
  1032. if (ai_get_ccrev(sih) >= 10)
  1033. SET_REG(&cc->system_clk_ctl, SYCC_CD_MASK,
  1034. (ILP_DIV_1MHZ << SYCC_CD_SHIFT));
  1035. ai_clkctl_setdelay(sii, cc);
  1036. ai_setcoreidx(sih, origidx);
  1037. }
  1038. /*
  1039. * return the value suitable for writing to the
  1040. * dot11 core FAST_PWRUP_DELAY register
  1041. */
  1042. u16 ai_clkctl_fast_pwrup_delay(struct si_pub *sih)
  1043. {
  1044. struct si_info *sii;
  1045. uint origidx = 0;
  1046. struct chipcregs __iomem *cc;
  1047. uint slowminfreq;
  1048. u16 fpdelay;
  1049. uint intr_val = 0;
  1050. sii = (struct si_info *)sih;
  1051. if (ai_get_cccaps(sih) & CC_CAP_PMU) {
  1052. INTR_OFF(sii, intr_val);
  1053. fpdelay = si_pmu_fast_pwrup_delay(sih);
  1054. INTR_RESTORE(sii, intr_val);
  1055. return fpdelay;
  1056. }
  1057. if (!(ai_get_cccaps(sih) & CC_CAP_PWR_CTL))
  1058. return 0;
  1059. fpdelay = 0;
  1060. origidx = sii->curidx;
  1061. INTR_OFF(sii, intr_val);
  1062. cc = (struct chipcregs __iomem *)
  1063. ai_setcore(sih, CC_CORE_ID, 0);
  1064. if (cc == NULL)
  1065. goto done;
  1066. slowminfreq = ai_slowclk_freq(sii, false, cc);
  1067. fpdelay = (((R_REG(&cc->pll_on_delay) + 2) * 1000000) +
  1068. (slowminfreq - 1)) / slowminfreq;
  1069. done:
  1070. ai_setcoreidx(sih, origidx);
  1071. INTR_RESTORE(sii, intr_val);
  1072. return fpdelay;
  1073. }
  1074. /* turn primary xtal and/or pll off/on */
  1075. int ai_clkctl_xtal(struct si_pub *sih, uint what, bool on)
  1076. {
  1077. struct si_info *sii;
  1078. u32 in, out, outen;
  1079. sii = (struct si_info *)sih;
  1080. /* pcie core doesn't have any mapping to control the xtal pu */
  1081. if (PCIE(sih))
  1082. return -1;
  1083. pci_read_config_dword(sii->pcibus, PCI_GPIO_IN, &in);
  1084. pci_read_config_dword(sii->pcibus, PCI_GPIO_OUT, &out);
  1085. pci_read_config_dword(sii->pcibus, PCI_GPIO_OUTEN, &outen);
  1086. /*
  1087. * Avoid glitching the clock if GPRS is already using it.
  1088. * We can't actually read the state of the PLLPD so we infer it
  1089. * by the value of XTAL_PU which *is* readable via gpioin.
  1090. */
  1091. if (on && (in & PCI_CFG_GPIO_XTAL))
  1092. return 0;
  1093. if (what & XTAL)
  1094. outen |= PCI_CFG_GPIO_XTAL;
  1095. if (what & PLL)
  1096. outen |= PCI_CFG_GPIO_PLL;
  1097. if (on) {
  1098. /* turn primary xtal on */
  1099. if (what & XTAL) {
  1100. out |= PCI_CFG_GPIO_XTAL;
  1101. if (what & PLL)
  1102. out |= PCI_CFG_GPIO_PLL;
  1103. pci_write_config_dword(sii->pcibus,
  1104. PCI_GPIO_OUT, out);
  1105. pci_write_config_dword(sii->pcibus,
  1106. PCI_GPIO_OUTEN, outen);
  1107. udelay(XTAL_ON_DELAY);
  1108. }
  1109. /* turn pll on */
  1110. if (what & PLL) {
  1111. out &= ~PCI_CFG_GPIO_PLL;
  1112. pci_write_config_dword(sii->pcibus,
  1113. PCI_GPIO_OUT, out);
  1114. mdelay(2);
  1115. }
  1116. } else {
  1117. if (what & XTAL)
  1118. out &= ~PCI_CFG_GPIO_XTAL;
  1119. if (what & PLL)
  1120. out |= PCI_CFG_GPIO_PLL;
  1121. pci_write_config_dword(sii->pcibus,
  1122. PCI_GPIO_OUT, out);
  1123. pci_write_config_dword(sii->pcibus,
  1124. PCI_GPIO_OUTEN, outen);
  1125. }
  1126. return 0;
  1127. }
  1128. /* clk control mechanism through chipcommon, no policy checking */
  1129. static bool _ai_clkctl_cc(struct si_info *sii, uint mode)
  1130. {
  1131. uint origidx = 0;
  1132. struct chipcregs __iomem *cc;
  1133. u32 scc;
  1134. uint intr_val = 0;
  1135. /* chipcommon cores prior to rev6 don't support dynamic clock control */
  1136. if (ai_get_ccrev(&sii->pub) < 6)
  1137. return false;
  1138. INTR_OFF(sii, intr_val);
  1139. origidx = sii->curidx;
  1140. cc = (struct chipcregs __iomem *)
  1141. ai_setcore(&sii->pub, CC_CORE_ID, 0);
  1142. if (!(ai_get_cccaps(&sii->pub) & CC_CAP_PWR_CTL) &&
  1143. (ai_get_ccrev(&sii->pub) < 20))
  1144. goto done;
  1145. switch (mode) {
  1146. case CLK_FAST: /* FORCEHT, fast (pll) clock */
  1147. if (ai_get_ccrev(&sii->pub) < 10) {
  1148. /*
  1149. * don't forget to force xtal back
  1150. * on before we clear SCC_DYN_XTAL..
  1151. */
  1152. ai_clkctl_xtal(&sii->pub, XTAL, ON);
  1153. SET_REG(&cc->slow_clk_ctl,
  1154. (SCC_XC | SCC_FS | SCC_IP), SCC_IP);
  1155. } else if (ai_get_ccrev(&sii->pub) < 20) {
  1156. OR_REG(&cc->system_clk_ctl, SYCC_HR);
  1157. } else {
  1158. OR_REG(&cc->clk_ctl_st, CCS_FORCEHT);
  1159. }
  1160. /* wait for the PLL */
  1161. if (ai_get_cccaps(&sii->pub) & CC_CAP_PMU) {
  1162. u32 htavail = CCS_HTAVAIL;
  1163. SPINWAIT(((R_REG(&cc->clk_ctl_st) & htavail)
  1164. == 0), PMU_MAX_TRANSITION_DLY);
  1165. } else {
  1166. udelay(PLL_DELAY);
  1167. }
  1168. break;
  1169. case CLK_DYNAMIC: /* enable dynamic clock control */
  1170. if (ai_get_ccrev(&sii->pub) < 10) {
  1171. scc = R_REG(&cc->slow_clk_ctl);
  1172. scc &= ~(SCC_FS | SCC_IP | SCC_XC);
  1173. if ((scc & SCC_SS_MASK) != SCC_SS_XTAL)
  1174. scc |= SCC_XC;
  1175. W_REG(&cc->slow_clk_ctl, scc);
  1176. /*
  1177. * for dynamic control, we have to
  1178. * release our xtal_pu "force on"
  1179. */
  1180. if (scc & SCC_XC)
  1181. ai_clkctl_xtal(&sii->pub, XTAL, OFF);
  1182. } else if (ai_get_ccrev(&sii->pub) < 20) {
  1183. /* Instaclock */
  1184. AND_REG(&cc->system_clk_ctl, ~SYCC_HR);
  1185. } else {
  1186. AND_REG(&cc->clk_ctl_st, ~CCS_FORCEHT);
  1187. }
  1188. break;
  1189. default:
  1190. break;
  1191. }
  1192. done:
  1193. ai_setcoreidx(&sii->pub, origidx);
  1194. INTR_RESTORE(sii, intr_val);
  1195. return mode == CLK_FAST;
  1196. }
  1197. /*
  1198. * clock control policy function throught chipcommon
  1199. *
  1200. * set dynamic clk control mode (forceslow, forcefast, dynamic)
  1201. * returns true if we are forcing fast clock
  1202. * this is a wrapper over the next internal function
  1203. * to allow flexible policy settings for outside caller
  1204. */
  1205. bool ai_clkctl_cc(struct si_pub *sih, uint mode)
  1206. {
  1207. struct si_info *sii;
  1208. sii = (struct si_info *)sih;
  1209. /* chipcommon cores prior to rev6 don't support dynamic clock control */
  1210. if (ai_get_ccrev(sih) < 6)
  1211. return false;
  1212. if (PCI_FORCEHT(sih))
  1213. return mode == CLK_FAST;
  1214. return _ai_clkctl_cc(sii, mode);
  1215. }
  1216. void ai_pci_up(struct si_pub *sih)
  1217. {
  1218. struct si_info *sii;
  1219. sii = (struct si_info *)sih;
  1220. if (PCI_FORCEHT(sih))
  1221. _ai_clkctl_cc(sii, CLK_FAST);
  1222. if (PCIE(sih))
  1223. pcicore_up(sii->pch, SI_PCIUP);
  1224. }
  1225. /* Unconfigure and/or apply various WARs when system is going to sleep mode */
  1226. void ai_pci_sleep(struct si_pub *sih)
  1227. {
  1228. struct si_info *sii;
  1229. sii = (struct si_info *)sih;
  1230. pcicore_sleep(sii->pch);
  1231. }
  1232. /* Unconfigure and/or apply various WARs when going down */
  1233. void ai_pci_down(struct si_pub *sih)
  1234. {
  1235. struct si_info *sii;
  1236. sii = (struct si_info *)sih;
  1237. /* release FORCEHT since chip is going to "down" state */
  1238. if (PCI_FORCEHT(sih))
  1239. _ai_clkctl_cc(sii, CLK_DYNAMIC);
  1240. pcicore_down(sii->pch, SI_PCIDOWN);
  1241. }
  1242. /*
  1243. * Configure the pci core for pci client (NIC) action
  1244. * coremask is the bitvec of cores by index to be enabled.
  1245. */
  1246. void ai_pci_setup(struct si_pub *sih, uint coremask)
  1247. {
  1248. struct si_info *sii;
  1249. struct sbpciregs __iomem *regs = NULL;
  1250. u32 w;
  1251. uint idx = 0;
  1252. sii = (struct si_info *)sih;
  1253. if (PCI(sih)) {
  1254. /* get current core index */
  1255. idx = sii->curidx;
  1256. /* switch over to pci core */
  1257. regs = ai_setcoreidx(sih, sii->buscoreidx);
  1258. }
  1259. /*
  1260. * Enable sb->pci interrupts. Assume
  1261. * PCI rev 2.3 support was added in pci core rev 6 and things changed..
  1262. */
  1263. if (PCIE(sih) || (PCI(sih) && (ai_get_buscorerev(sih) >= 6))) {
  1264. /* pci config write to set this core bit in PCIIntMask */
  1265. pci_read_config_dword(sii->pcibus, PCI_INT_MASK, &w);
  1266. w |= (coremask << PCI_SBIM_SHIFT);
  1267. pci_write_config_dword(sii->pcibus, PCI_INT_MASK, w);
  1268. }
  1269. if (PCI(sih)) {
  1270. pcicore_pci_setup(sii->pch, regs);
  1271. /* switch back to previous core */
  1272. ai_setcoreidx(sih, idx);
  1273. }
  1274. }
  1275. /*
  1276. * Fixup SROMless PCI device's configuration.
  1277. * The current core may be changed upon return.
  1278. */
  1279. int ai_pci_fixcfg(struct si_pub *sih)
  1280. {
  1281. uint origidx;
  1282. void __iomem *regs = NULL;
  1283. struct si_info *sii = (struct si_info *)sih;
  1284. /* Fixup PI in SROM shadow area to enable the correct PCI core access */
  1285. /* save the current index */
  1286. origidx = ai_coreidx(&sii->pub);
  1287. /* check 'pi' is correct and fix it if not */
  1288. regs = ai_setcore(&sii->pub, ai_get_buscoretype(sih), 0);
  1289. if (ai_get_buscoretype(sih) == PCIE_CORE_ID)
  1290. pcicore_fixcfg_pcie(sii->pch,
  1291. (struct sbpcieregs __iomem *)regs);
  1292. else if (ai_get_buscoretype(sih) == PCI_CORE_ID)
  1293. pcicore_fixcfg_pci(sii->pch, (struct sbpciregs __iomem *)regs);
  1294. /* restore the original index */
  1295. ai_setcoreidx(&sii->pub, origidx);
  1296. pcicore_hwup(sii->pch);
  1297. return 0;
  1298. }
  1299. /* mask&set gpiocontrol bits */
  1300. u32 ai_gpiocontrol(struct si_pub *sih, u32 mask, u32 val, u8 priority)
  1301. {
  1302. uint regoff;
  1303. regoff = offsetof(struct chipcregs, gpiocontrol);
  1304. return ai_cc_reg(sih, regoff, mask, val);
  1305. }
  1306. void ai_chipcontrl_epa4331(struct si_pub *sih, bool on)
  1307. {
  1308. struct si_info *sii;
  1309. struct chipcregs __iomem *cc;
  1310. uint origidx;
  1311. u32 val;
  1312. sii = (struct si_info *)sih;
  1313. origidx = ai_coreidx(sih);
  1314. cc = (struct chipcregs __iomem *) ai_setcore(sih, CC_CORE_ID, 0);
  1315. val = R_REG(&cc->chipcontrol);
  1316. if (on) {
  1317. if (ai_get_chippkg(sih) == 9 || ai_get_chippkg(sih) == 0xb)
  1318. /* Ext PA Controls for 4331 12x9 Package */
  1319. W_REG(&cc->chipcontrol, val |
  1320. CCTRL4331_EXTPA_EN |
  1321. CCTRL4331_EXTPA_ON_GPIO2_5);
  1322. else
  1323. /* Ext PA Controls for 4331 12x12 Package */
  1324. W_REG(&cc->chipcontrol,
  1325. val | CCTRL4331_EXTPA_EN);
  1326. } else {
  1327. val &= ~(CCTRL4331_EXTPA_EN | CCTRL4331_EXTPA_ON_GPIO2_5);
  1328. W_REG(&cc->chipcontrol, val);
  1329. }
  1330. ai_setcoreidx(sih, origidx);
  1331. }
  1332. /* Enable BT-COEX & Ex-PA for 4313 */
  1333. void ai_epa_4313war(struct si_pub *sih)
  1334. {
  1335. struct si_info *sii;
  1336. struct chipcregs __iomem *cc;
  1337. uint origidx;
  1338. sii = (struct si_info *)sih;
  1339. origidx = ai_coreidx(sih);
  1340. cc = ai_setcore(sih, CC_CORE_ID, 0);
  1341. /* EPA Fix */
  1342. W_REG(&cc->gpiocontrol,
  1343. R_REG(&cc->gpiocontrol) | GPIO_CTRL_EPA_EN_MASK);
  1344. ai_setcoreidx(sih, origidx);
  1345. }
  1346. /* check if the device is removed */
  1347. bool ai_deviceremoved(struct si_pub *sih)
  1348. {
  1349. u32 w;
  1350. struct si_info *sii;
  1351. sii = (struct si_info *)sih;
  1352. pci_read_config_dword(sii->pcibus, PCI_VENDOR_ID, &w);
  1353. if ((w & 0xFFFF) != PCI_VENDOR_ID_BROADCOM)
  1354. return true;
  1355. return false;
  1356. }
  1357. bool ai_is_sprom_available(struct si_pub *sih)
  1358. {
  1359. struct si_info *sii = (struct si_info *)sih;
  1360. if (ai_get_ccrev(sih) >= 31) {
  1361. uint origidx;
  1362. struct chipcregs __iomem *cc;
  1363. u32 sromctrl;
  1364. if ((ai_get_cccaps(sih) & CC_CAP_SROM) == 0)
  1365. return false;
  1366. origidx = sii->curidx;
  1367. cc = ai_setcoreidx(sih, SI_CC_IDX);
  1368. sromctrl = R_REG(&cc->sromcontrol);
  1369. ai_setcoreidx(sih, origidx);
  1370. return sromctrl & SRC_PRESENT;
  1371. }
  1372. switch (ai_get_chip_id(sih)) {
  1373. case BCM4313_CHIP_ID:
  1374. return (sii->chipst & CST4313_SPROM_PRESENT) != 0;
  1375. default:
  1376. return true;
  1377. }
  1378. }
  1379. bool ai_is_otp_disabled(struct si_pub *sih)
  1380. {
  1381. struct si_info *sii = (struct si_info *)sih;
  1382. switch (ai_get_chip_id(sih)) {
  1383. case BCM4313_CHIP_ID:
  1384. return (sii->chipst & CST4313_OTP_PRESENT) == 0;
  1385. /* These chips always have their OTP on */
  1386. case BCM43224_CHIP_ID:
  1387. case BCM43225_CHIP_ID:
  1388. default:
  1389. return false;
  1390. }
  1391. }