aiutils.c 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766
  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. /* Return the number of address spaces in current core */
  483. int ai_numaddrspaces(struct si_pub *sih)
  484. {
  485. return 2;
  486. }
  487. /* Return the address of the nth address space in the current core */
  488. u32 ai_addrspace(struct si_pub *sih, uint asidx)
  489. {
  490. struct si_info *sii;
  491. uint cidx;
  492. sii = (struct si_info *)sih;
  493. cidx = sii->curidx;
  494. if (asidx == 0)
  495. return sii->coresba[cidx];
  496. else if (asidx == 1)
  497. return sii->coresba2[cidx];
  498. else {
  499. /* Need to parse the erom again to find addr space */
  500. return 0;
  501. }
  502. }
  503. /* Return the size of the nth address space in the current core */
  504. u32 ai_addrspacesize(struct si_pub *sih, uint asidx)
  505. {
  506. struct si_info *sii;
  507. uint cidx;
  508. sii = (struct si_info *)sih;
  509. cidx = sii->curidx;
  510. if (asidx == 0)
  511. return sii->coresba_size[cidx];
  512. else if (asidx == 1)
  513. return sii->coresba2_size[cidx];
  514. else {
  515. /* Need to parse the erom again to find addr */
  516. return 0;
  517. }
  518. }
  519. uint ai_flag(struct si_pub *sih)
  520. {
  521. struct si_info *sii;
  522. struct aidmp *ai;
  523. sii = (struct si_info *)sih;
  524. ai = sii->curwrap;
  525. return R_REG(&ai->oobselouta30) & 0x1f;
  526. }
  527. void ai_setint(struct si_pub *sih, int siflag)
  528. {
  529. }
  530. uint ai_corevendor(struct si_pub *sih)
  531. {
  532. struct si_info *sii;
  533. u32 cia;
  534. sii = (struct si_info *)sih;
  535. cia = sii->cia[sii->curidx];
  536. return (cia & CIA_MFG_MASK) >> CIA_MFG_SHIFT;
  537. }
  538. uint ai_corerev(struct si_pub *sih)
  539. {
  540. struct si_info *sii;
  541. u32 cib;
  542. sii = (struct si_info *)sih;
  543. cib = sii->cib[sii->curidx];
  544. return (cib & CIB_REV_MASK) >> CIB_REV_SHIFT;
  545. }
  546. bool ai_iscoreup(struct si_pub *sih)
  547. {
  548. struct si_info *sii;
  549. struct aidmp *ai;
  550. sii = (struct si_info *)sih;
  551. ai = sii->curwrap;
  552. return (((R_REG(&ai->ioctrl) & (SICF_FGC | SICF_CLOCK_EN)) ==
  553. SICF_CLOCK_EN)
  554. && ((R_REG(&ai->resetctrl) & AIRC_RESET) == 0));
  555. }
  556. void ai_core_cflags_wo(struct si_pub *sih, u32 mask, u32 val)
  557. {
  558. struct si_info *sii;
  559. struct aidmp *ai;
  560. u32 w;
  561. sii = (struct si_info *)sih;
  562. ai = sii->curwrap;
  563. if (mask || val) {
  564. w = ((R_REG(&ai->ioctrl) & ~mask) | val);
  565. W_REG(&ai->ioctrl, w);
  566. }
  567. }
  568. u32 ai_core_cflags(struct si_pub *sih, u32 mask, u32 val)
  569. {
  570. struct si_info *sii;
  571. struct aidmp *ai;
  572. u32 w;
  573. sii = (struct si_info *)sih;
  574. ai = sii->curwrap;
  575. if (mask || val) {
  576. w = ((R_REG(&ai->ioctrl) & ~mask) | val);
  577. W_REG(&ai->ioctrl, w);
  578. }
  579. return R_REG(&ai->ioctrl);
  580. }
  581. /* return true if PCIE capability exists in the pci config space */
  582. static bool ai_ispcie(struct si_info *sii)
  583. {
  584. u8 cap_ptr;
  585. cap_ptr =
  586. pcicore_find_pci_capability(sii->pcibus, PCI_CAP_ID_EXP, NULL,
  587. NULL);
  588. if (!cap_ptr)
  589. return false;
  590. return true;
  591. }
  592. static bool ai_buscore_prep(struct si_info *sii)
  593. {
  594. /* kludge to enable the clock on the 4306 which lacks a slowclock */
  595. if (!ai_ispcie(sii))
  596. ai_clkctl_xtal(&sii->pub, XTAL | PLL, ON);
  597. return true;
  598. }
  599. u32 ai_core_sflags(struct si_pub *sih, u32 mask, u32 val)
  600. {
  601. struct si_info *sii;
  602. struct aidmp *ai;
  603. u32 w;
  604. sii = (struct si_info *)sih;
  605. ai = sii->curwrap;
  606. if (mask || val) {
  607. w = ((R_REG(&ai->iostatus) & ~mask) | val);
  608. W_REG(&ai->iostatus, w);
  609. }
  610. return R_REG(&ai->iostatus);
  611. }
  612. static bool
  613. ai_buscore_setup(struct si_info *sii, u32 savewin, uint *origidx)
  614. {
  615. bool pci, pcie;
  616. uint i;
  617. uint pciidx, pcieidx, pcirev, pcierev;
  618. struct chipcregs __iomem *cc;
  619. cc = ai_setcoreidx(&sii->pub, SI_CC_IDX);
  620. /* get chipcommon rev */
  621. sii->pub.ccrev = (int)ai_corerev(&sii->pub);
  622. /* get chipcommon chipstatus */
  623. if (ai_get_ccrev(&sii->pub) >= 11)
  624. sii->chipst = R_REG(&cc->chipstatus);
  625. /* get chipcommon capabilites */
  626. sii->pub.cccaps = R_REG(&cc->capabilities);
  627. /* get pmu rev and caps */
  628. if (ai_get_cccaps(&sii->pub) & CC_CAP_PMU) {
  629. sii->pub.pmucaps = R_REG(&cc->pmucapabilities);
  630. sii->pub.pmurev = sii->pub.pmucaps & PCAP_REV_MASK;
  631. }
  632. /* figure out bus/orignal core idx */
  633. sii->pub.buscoretype = NODEV_CORE_ID;
  634. sii->pub.buscorerev = NOREV;
  635. sii->buscoreidx = BADIDX;
  636. pci = pcie = false;
  637. pcirev = pcierev = NOREV;
  638. pciidx = pcieidx = BADIDX;
  639. for (i = 0; i < sii->numcores; i++) {
  640. uint cid, crev;
  641. ai_setcoreidx(&sii->pub, i);
  642. cid = ai_coreid(&sii->pub);
  643. crev = ai_corerev(&sii->pub);
  644. if (cid == PCI_CORE_ID) {
  645. pciidx = i;
  646. pcirev = crev;
  647. pci = true;
  648. } else if (cid == PCIE_CORE_ID) {
  649. pcieidx = i;
  650. pcierev = crev;
  651. pcie = true;
  652. }
  653. /* find the core idx before entering this func. */
  654. if ((savewin && (savewin == sii->coresba[i])) ||
  655. (cc == sii->regs[i]))
  656. *origidx = i;
  657. }
  658. if (pci && pcie) {
  659. if (ai_ispcie(sii))
  660. pci = false;
  661. else
  662. pcie = false;
  663. }
  664. if (pci) {
  665. sii->pub.buscoretype = PCI_CORE_ID;
  666. sii->pub.buscorerev = pcirev;
  667. sii->buscoreidx = pciidx;
  668. } else if (pcie) {
  669. sii->pub.buscoretype = PCIE_CORE_ID;
  670. sii->pub.buscorerev = pcierev;
  671. sii->buscoreidx = pcieidx;
  672. }
  673. /* fixup necessary chip/core configurations */
  674. if (!sii->pch) {
  675. sii->pch = pcicore_init(&sii->pub, sii->pcibus,
  676. sii->curmap + PCI_16KB0_PCIREGS_OFFSET);
  677. if (sii->pch == NULL)
  678. return false;
  679. }
  680. if (ai_pci_fixcfg(&sii->pub)) {
  681. /* si_doattach: si_pci_fixcfg failed */
  682. return false;
  683. }
  684. /* return to the original core */
  685. ai_setcoreidx(&sii->pub, *origidx);
  686. return true;
  687. }
  688. /*
  689. * get boardtype and boardrev
  690. */
  691. static __used void ai_nvram_process(struct si_info *sii)
  692. {
  693. uint w = 0;
  694. /* do a pci config read to get subsystem id and subvendor id */
  695. pci_read_config_dword(sii->pcibus, PCI_SUBSYSTEM_VENDOR_ID, &w);
  696. sii->pub.boardvendor = w & 0xffff;
  697. sii->pub.boardtype = (w >> 16) & 0xffff;
  698. }
  699. static struct si_info *ai_doattach(struct si_info *sii,
  700. struct bcma_bus *pbus)
  701. {
  702. void __iomem *regs = pbus->mmio;
  703. struct si_pub *sih = &sii->pub;
  704. u32 w, savewin;
  705. struct chipcregs __iomem *cc;
  706. uint socitype;
  707. uint origidx;
  708. memset((unsigned char *) sii, 0, sizeof(struct si_info));
  709. savewin = 0;
  710. sii->icbus = pbus;
  711. sii->buscoreidx = BADIDX;
  712. sii->pcibus = pbus->host_pci;
  713. sii->curmap = regs;
  714. sii->curwrap = sii->curmap + SI_CORE_SIZE;
  715. /* switch to Chipcommon core */
  716. bcma_read32(pbus->drv_cc.core, 0);
  717. savewin = SI_ENUM_BASE;
  718. cc = (struct chipcregs __iomem *) regs;
  719. /* bus/core/clk setup for register access */
  720. if (!ai_buscore_prep(sii))
  721. return NULL;
  722. /*
  723. * ChipID recognition.
  724. * We assume we can read chipid at offset 0 from the regs arg.
  725. * If we add other chiptypes (or if we need to support old sdio
  726. * hosts w/o chipcommon), some way of recognizing them needs to
  727. * be added here.
  728. */
  729. w = R_REG(&cc->chipid);
  730. socitype = (w & CID_TYPE_MASK) >> CID_TYPE_SHIFT;
  731. /* Might as wll fill in chip id rev & pkg */
  732. sih->chip = w & CID_ID_MASK;
  733. sih->chiprev = (w & CID_REV_MASK) >> CID_REV_SHIFT;
  734. sih->chippkg = (w & CID_PKG_MASK) >> CID_PKG_SHIFT;
  735. /* scan for cores */
  736. if (socitype == SOCI_AI) {
  737. SI_MSG("Found chip type AI (0x%08x)\n", w);
  738. /* pass chipc address instead of original core base */
  739. ai_scan(&sii->pub, pbus);
  740. } else {
  741. /* Found chip of unknown type */
  742. return NULL;
  743. }
  744. /* no cores found, bail out */
  745. if (sii->numcores == 0)
  746. return NULL;
  747. /* bus/core/clk setup */
  748. origidx = SI_CC_IDX;
  749. if (!ai_buscore_setup(sii, savewin, &origidx))
  750. goto exit;
  751. /* Init nvram from sprom/otp if they exist */
  752. if (srom_var_init(&sii->pub, cc))
  753. goto exit;
  754. ai_nvram_process(sii);
  755. /* === NVRAM, clock is ready === */
  756. cc = (struct chipcregs __iomem *) ai_setcore(sih, CC_CORE_ID, 0);
  757. W_REG(&cc->gpiopullup, 0);
  758. W_REG(&cc->gpiopulldown, 0);
  759. ai_setcoreidx(sih, origidx);
  760. /* PMU specific initializations */
  761. if (ai_get_cccaps(sih) & CC_CAP_PMU) {
  762. u32 xtalfreq;
  763. si_pmu_init(sih);
  764. si_pmu_chip_init(sih);
  765. xtalfreq = si_pmu_measure_alpclk(sih);
  766. si_pmu_pll_init(sih, xtalfreq);
  767. si_pmu_res_init(sih);
  768. si_pmu_swreg_init(sih);
  769. }
  770. /* setup the GPIO based LED powersave register */
  771. w = getintvar(sih, BRCMS_SROM_LEDDC);
  772. if (w == 0)
  773. w = DEFAULT_GPIOTIMERVAL;
  774. ai_cc_reg(sih, offsetof(struct chipcregs, gpiotimerval),
  775. ~0, w);
  776. if (PCIE(sih))
  777. pcicore_attach(sii->pch, SI_DOATTACH);
  778. if (ai_get_chip_id(sih) == BCM43224_CHIP_ID) {
  779. /*
  780. * enable 12 mA drive strenth for 43224 and
  781. * set chipControl register bit 15
  782. */
  783. if (ai_get_chiprev(sih) == 0) {
  784. SI_MSG("Applying 43224A0 WARs\n");
  785. ai_cc_reg(sih, offsetof(struct chipcregs, chipcontrol),
  786. CCTRL43224_GPIO_TOGGLE,
  787. CCTRL43224_GPIO_TOGGLE);
  788. si_pmu_chipcontrol(sih, 0, CCTRL_43224A0_12MA_LED_DRIVE,
  789. CCTRL_43224A0_12MA_LED_DRIVE);
  790. }
  791. if (ai_get_chiprev(sih) >= 1) {
  792. SI_MSG("Applying 43224B0+ WARs\n");
  793. si_pmu_chipcontrol(sih, 0, CCTRL_43224B0_12MA_LED_DRIVE,
  794. CCTRL_43224B0_12MA_LED_DRIVE);
  795. }
  796. }
  797. if (ai_get_chip_id(sih) == BCM4313_CHIP_ID) {
  798. /*
  799. * enable 12 mA drive strenth for 4313 and
  800. * set chipControl register bit 1
  801. */
  802. SI_MSG("Applying 4313 WARs\n");
  803. si_pmu_chipcontrol(sih, 0, CCTRL_4313_12MA_LED_DRIVE,
  804. CCTRL_4313_12MA_LED_DRIVE);
  805. }
  806. return sii;
  807. exit:
  808. if (sii->pch)
  809. pcicore_deinit(sii->pch);
  810. sii->pch = NULL;
  811. return NULL;
  812. }
  813. /*
  814. * Allocate a si handle and do the attach.
  815. */
  816. struct si_pub *
  817. ai_attach(struct bcma_bus *pbus)
  818. {
  819. struct si_info *sii;
  820. /* alloc struct si_info */
  821. sii = kmalloc(sizeof(struct si_info), GFP_ATOMIC);
  822. if (sii == NULL)
  823. return NULL;
  824. if (ai_doattach(sii, pbus) == NULL) {
  825. kfree(sii);
  826. return NULL;
  827. }
  828. return (struct si_pub *) sii;
  829. }
  830. /* may be called with core in reset */
  831. void ai_detach(struct si_pub *sih)
  832. {
  833. struct si_info *sii;
  834. struct si_pub *si_local = NULL;
  835. memcpy(&si_local, &sih, sizeof(struct si_pub **));
  836. sii = (struct si_info *)sih;
  837. if (sii == NULL)
  838. return;
  839. if (sii->pch)
  840. pcicore_deinit(sii->pch);
  841. sii->pch = NULL;
  842. srom_free_vars(sih);
  843. kfree(sii);
  844. }
  845. /* register driver interrupt disabling and restoring callback functions */
  846. void
  847. ai_register_intr_callback(struct si_pub *sih, void *intrsoff_fn,
  848. void *intrsrestore_fn,
  849. void *intrsenabled_fn, void *intr_arg)
  850. {
  851. struct si_info *sii;
  852. sii = (struct si_info *)sih;
  853. sii->intr_arg = intr_arg;
  854. sii->intrsoff_fn = (u32 (*)(void *)) intrsoff_fn;
  855. sii->intrsrestore_fn = (void (*) (void *, u32)) intrsrestore_fn;
  856. sii->intrsenabled_fn = (bool (*)(void *)) intrsenabled_fn;
  857. /* save current core id. when this function called, the current core
  858. * must be the core which provides driver functions(il, et, wl, etc.)
  859. */
  860. sii->dev_coreid = sii->coreid[sii->curidx];
  861. }
  862. void ai_deregister_intr_callback(struct si_pub *sih)
  863. {
  864. struct si_info *sii;
  865. sii = (struct si_info *)sih;
  866. sii->intrsoff_fn = NULL;
  867. }
  868. uint ai_coreid(struct si_pub *sih)
  869. {
  870. struct si_info *sii;
  871. sii = (struct si_info *)sih;
  872. return sii->coreid[sii->curidx];
  873. }
  874. uint ai_coreidx(struct si_pub *sih)
  875. {
  876. struct si_info *sii;
  877. sii = (struct si_info *)sih;
  878. return sii->curidx;
  879. }
  880. bool ai_backplane64(struct si_pub *sih)
  881. {
  882. return (ai_get_cccaps(sih) & CC_CAP_BKPLN64) != 0;
  883. }
  884. /* return index of coreid or BADIDX if not found */
  885. uint ai_findcoreidx(struct si_pub *sih, uint coreid, uint coreunit)
  886. {
  887. struct bcma_device *core;
  888. struct si_info *sii;
  889. uint found;
  890. sii = (struct si_info *)sih;
  891. found = 0;
  892. list_for_each_entry(core, &sii->icbus->cores, list)
  893. if (core->id.id == coreid) {
  894. if (found == coreunit)
  895. return core->core_index;
  896. found++;
  897. }
  898. return BADIDX;
  899. }
  900. /*
  901. * This function changes logical "focus" to the indicated core;
  902. * must be called with interrupts off.
  903. * Moreover, callers should keep interrupts off during switching
  904. * out of and back to d11 core.
  905. */
  906. void __iomem *ai_setcore(struct si_pub *sih, uint coreid, uint coreunit)
  907. {
  908. uint idx;
  909. idx = ai_findcoreidx(sih, coreid, coreunit);
  910. if (idx >= SI_MAXCORES)
  911. return NULL;
  912. return ai_setcoreidx(sih, idx);
  913. }
  914. /* Turn off interrupt as required by ai_setcore, before switch core */
  915. void __iomem *ai_switch_core(struct si_pub *sih, uint coreid, uint *origidx,
  916. uint *intr_val)
  917. {
  918. void __iomem *cc;
  919. struct si_info *sii;
  920. sii = (struct si_info *)sih;
  921. INTR_OFF(sii, *intr_val);
  922. *origidx = sii->curidx;
  923. cc = ai_setcore(sih, coreid, 0);
  924. return cc;
  925. }
  926. /* restore coreidx and restore interrupt */
  927. void ai_restore_core(struct si_pub *sih, uint coreid, uint intr_val)
  928. {
  929. struct si_info *sii;
  930. sii = (struct si_info *)sih;
  931. ai_setcoreidx(sih, coreid);
  932. INTR_RESTORE(sii, intr_val);
  933. }
  934. void ai_write_wrapperreg(struct si_pub *sih, u32 offset, u32 val)
  935. {
  936. struct si_info *sii = (struct si_info *)sih;
  937. u32 *w = (u32 *) sii->curwrap;
  938. W_REG(w + (offset / 4), val);
  939. return;
  940. }
  941. /*
  942. * Switch to 'coreidx', issue a single arbitrary 32bit register mask&set
  943. * operation, switch back to the original core, and return the new value.
  944. *
  945. * When using the silicon backplane, no fiddling with interrupts or core
  946. * switches is needed.
  947. *
  948. * Also, when using pci/pcie, we can optimize away the core switching for pci
  949. * registers and (on newer pci cores) chipcommon registers.
  950. */
  951. uint ai_cc_reg(struct si_pub *sih, uint regoff, u32 mask, u32 val)
  952. {
  953. struct bcma_device *cc;
  954. uint origidx = 0;
  955. u32 w;
  956. uint intr_val = 0;
  957. struct si_info *sii;
  958. sii = (struct si_info *)sih;
  959. cc = sii->icbus->drv_cc.core;
  960. INTR_OFF(sii, intr_val);
  961. /* save current core index */
  962. origidx = ai_coreidx(&sii->pub);
  963. /* mask and set */
  964. if (mask || val) {
  965. bcma_maskset32(cc, regoff, ~mask, val);
  966. }
  967. /* readback */
  968. w = bcma_read32(cc, regoff);
  969. /* restore core index */
  970. ai_setcoreidx(&sii->pub, origidx);
  971. INTR_RESTORE(sii, intr_val);
  972. return w;
  973. }
  974. void ai_core_disable(struct si_pub *sih, u32 bits)
  975. {
  976. struct si_info *sii;
  977. u32 dummy;
  978. struct aidmp *ai;
  979. sii = (struct si_info *)sih;
  980. ai = sii->curwrap;
  981. /* if core is already in reset, just return */
  982. if (R_REG(&ai->resetctrl) & AIRC_RESET)
  983. return;
  984. W_REG(&ai->ioctrl, bits);
  985. dummy = R_REG(&ai->ioctrl);
  986. udelay(10);
  987. W_REG(&ai->resetctrl, AIRC_RESET);
  988. udelay(1);
  989. }
  990. /* reset and re-enable a core
  991. * inputs:
  992. * bits - core specific bits that are set during and after reset sequence
  993. * resetbits - core specific bits that are set only during reset sequence
  994. */
  995. void ai_core_reset(struct si_pub *sih, u32 bits, u32 resetbits)
  996. {
  997. struct si_info *sii;
  998. struct aidmp *ai;
  999. u32 dummy;
  1000. sii = (struct si_info *)sih;
  1001. ai = sii->curwrap;
  1002. /*
  1003. * Must do the disable sequence first to work
  1004. * for arbitrary current core state.
  1005. */
  1006. ai_core_disable(sih, (bits | resetbits));
  1007. /*
  1008. * Now do the initialization sequence.
  1009. */
  1010. W_REG(&ai->ioctrl, (bits | SICF_FGC | SICF_CLOCK_EN));
  1011. dummy = R_REG(&ai->ioctrl);
  1012. W_REG(&ai->resetctrl, 0);
  1013. udelay(1);
  1014. W_REG(&ai->ioctrl, (bits | SICF_CLOCK_EN));
  1015. dummy = R_REG(&ai->ioctrl);
  1016. udelay(1);
  1017. }
  1018. /* return the slow clock source - LPO, XTAL, or PCI */
  1019. static uint ai_slowclk_src(struct si_info *sii)
  1020. {
  1021. struct chipcregs __iomem *cc;
  1022. u32 val;
  1023. if (ai_get_ccrev(&sii->pub) < 6) {
  1024. pci_read_config_dword(sii->pcibus, PCI_GPIO_OUT,
  1025. &val);
  1026. if (val & PCI_CFG_GPIO_SCS)
  1027. return SCC_SS_PCI;
  1028. return SCC_SS_XTAL;
  1029. } else if (ai_get_ccrev(&sii->pub) < 10) {
  1030. cc = (struct chipcregs __iomem *)
  1031. ai_setcoreidx(&sii->pub, sii->curidx);
  1032. return R_REG(&cc->slow_clk_ctl) & SCC_SS_MASK;
  1033. } else /* Insta-clock */
  1034. return SCC_SS_XTAL;
  1035. }
  1036. /*
  1037. * return the ILP (slowclock) min or max frequency
  1038. * precondition: we've established the chip has dynamic clk control
  1039. */
  1040. static uint ai_slowclk_freq(struct si_info *sii, bool max_freq,
  1041. struct chipcregs __iomem *cc)
  1042. {
  1043. u32 slowclk;
  1044. uint div;
  1045. slowclk = ai_slowclk_src(sii);
  1046. if (ai_get_ccrev(&sii->pub) < 6) {
  1047. if (slowclk == SCC_SS_PCI)
  1048. return max_freq ? (PCIMAXFREQ / 64)
  1049. : (PCIMINFREQ / 64);
  1050. else
  1051. return max_freq ? (XTALMAXFREQ / 32)
  1052. : (XTALMINFREQ / 32);
  1053. } else if (ai_get_ccrev(&sii->pub) < 10) {
  1054. div = 4 *
  1055. (((R_REG(&cc->slow_clk_ctl) & SCC_CD_MASK) >>
  1056. SCC_CD_SHIFT) + 1);
  1057. if (slowclk == SCC_SS_LPO)
  1058. return max_freq ? LPOMAXFREQ : LPOMINFREQ;
  1059. else if (slowclk == SCC_SS_XTAL)
  1060. return max_freq ? (XTALMAXFREQ / div)
  1061. : (XTALMINFREQ / div);
  1062. else if (slowclk == SCC_SS_PCI)
  1063. return max_freq ? (PCIMAXFREQ / div)
  1064. : (PCIMINFREQ / div);
  1065. } else {
  1066. /* Chipc rev 10 is InstaClock */
  1067. div = R_REG(&cc->system_clk_ctl) >> SYCC_CD_SHIFT;
  1068. div = 4 * (div + 1);
  1069. return max_freq ? XTALMAXFREQ : (XTALMINFREQ / div);
  1070. }
  1071. return 0;
  1072. }
  1073. static void
  1074. ai_clkctl_setdelay(struct si_info *sii, struct chipcregs __iomem *cc)
  1075. {
  1076. uint slowmaxfreq, pll_delay, slowclk;
  1077. uint pll_on_delay, fref_sel_delay;
  1078. pll_delay = PLL_DELAY;
  1079. /*
  1080. * If the slow clock is not sourced by the xtal then
  1081. * add the xtal_on_delay since the xtal will also be
  1082. * powered down by dynamic clk control logic.
  1083. */
  1084. slowclk = ai_slowclk_src(sii);
  1085. if (slowclk != SCC_SS_XTAL)
  1086. pll_delay += XTAL_ON_DELAY;
  1087. /* Starting with 4318 it is ILP that is used for the delays */
  1088. slowmaxfreq =
  1089. ai_slowclk_freq(sii,
  1090. (ai_get_ccrev(&sii->pub) >= 10) ? false : true, cc);
  1091. pll_on_delay = ((slowmaxfreq * pll_delay) + 999999) / 1000000;
  1092. fref_sel_delay = ((slowmaxfreq * FREF_DELAY) + 999999) / 1000000;
  1093. W_REG(&cc->pll_on_delay, pll_on_delay);
  1094. W_REG(&cc->fref_sel_delay, fref_sel_delay);
  1095. }
  1096. /* initialize power control delay registers */
  1097. void ai_clkctl_init(struct si_pub *sih)
  1098. {
  1099. struct si_info *sii;
  1100. uint origidx = 0;
  1101. struct chipcregs __iomem *cc;
  1102. if (!(ai_get_cccaps(sih) & CC_CAP_PWR_CTL))
  1103. return;
  1104. sii = (struct si_info *)sih;
  1105. origidx = sii->curidx;
  1106. cc = (struct chipcregs __iomem *)
  1107. ai_setcore(sih, CC_CORE_ID, 0);
  1108. if (cc == NULL)
  1109. return;
  1110. /* set all Instaclk chip ILP to 1 MHz */
  1111. if (ai_get_ccrev(sih) >= 10)
  1112. SET_REG(&cc->system_clk_ctl, SYCC_CD_MASK,
  1113. (ILP_DIV_1MHZ << SYCC_CD_SHIFT));
  1114. ai_clkctl_setdelay(sii, cc);
  1115. ai_setcoreidx(sih, origidx);
  1116. }
  1117. /*
  1118. * return the value suitable for writing to the
  1119. * dot11 core FAST_PWRUP_DELAY register
  1120. */
  1121. u16 ai_clkctl_fast_pwrup_delay(struct si_pub *sih)
  1122. {
  1123. struct si_info *sii;
  1124. uint origidx = 0;
  1125. struct chipcregs __iomem *cc;
  1126. uint slowminfreq;
  1127. u16 fpdelay;
  1128. uint intr_val = 0;
  1129. sii = (struct si_info *)sih;
  1130. if (ai_get_cccaps(sih) & CC_CAP_PMU) {
  1131. INTR_OFF(sii, intr_val);
  1132. fpdelay = si_pmu_fast_pwrup_delay(sih);
  1133. INTR_RESTORE(sii, intr_val);
  1134. return fpdelay;
  1135. }
  1136. if (!(ai_get_cccaps(sih) & CC_CAP_PWR_CTL))
  1137. return 0;
  1138. fpdelay = 0;
  1139. origidx = sii->curidx;
  1140. INTR_OFF(sii, intr_val);
  1141. cc = (struct chipcregs __iomem *)
  1142. ai_setcore(sih, CC_CORE_ID, 0);
  1143. if (cc == NULL)
  1144. goto done;
  1145. slowminfreq = ai_slowclk_freq(sii, false, cc);
  1146. fpdelay = (((R_REG(&cc->pll_on_delay) + 2) * 1000000) +
  1147. (slowminfreq - 1)) / slowminfreq;
  1148. done:
  1149. ai_setcoreidx(sih, origidx);
  1150. INTR_RESTORE(sii, intr_val);
  1151. return fpdelay;
  1152. }
  1153. /* turn primary xtal and/or pll off/on */
  1154. int ai_clkctl_xtal(struct si_pub *sih, uint what, bool on)
  1155. {
  1156. struct si_info *sii;
  1157. u32 in, out, outen;
  1158. sii = (struct si_info *)sih;
  1159. /* pcie core doesn't have any mapping to control the xtal pu */
  1160. if (PCIE(sih))
  1161. return -1;
  1162. pci_read_config_dword(sii->pcibus, PCI_GPIO_IN, &in);
  1163. pci_read_config_dword(sii->pcibus, PCI_GPIO_OUT, &out);
  1164. pci_read_config_dword(sii->pcibus, PCI_GPIO_OUTEN, &outen);
  1165. /*
  1166. * Avoid glitching the clock if GPRS is already using it.
  1167. * We can't actually read the state of the PLLPD so we infer it
  1168. * by the value of XTAL_PU which *is* readable via gpioin.
  1169. */
  1170. if (on && (in & PCI_CFG_GPIO_XTAL))
  1171. return 0;
  1172. if (what & XTAL)
  1173. outen |= PCI_CFG_GPIO_XTAL;
  1174. if (what & PLL)
  1175. outen |= PCI_CFG_GPIO_PLL;
  1176. if (on) {
  1177. /* turn primary xtal on */
  1178. if (what & XTAL) {
  1179. out |= PCI_CFG_GPIO_XTAL;
  1180. if (what & PLL)
  1181. out |= PCI_CFG_GPIO_PLL;
  1182. pci_write_config_dword(sii->pcibus,
  1183. PCI_GPIO_OUT, out);
  1184. pci_write_config_dword(sii->pcibus,
  1185. PCI_GPIO_OUTEN, outen);
  1186. udelay(XTAL_ON_DELAY);
  1187. }
  1188. /* turn pll on */
  1189. if (what & PLL) {
  1190. out &= ~PCI_CFG_GPIO_PLL;
  1191. pci_write_config_dword(sii->pcibus,
  1192. PCI_GPIO_OUT, out);
  1193. mdelay(2);
  1194. }
  1195. } else {
  1196. if (what & XTAL)
  1197. out &= ~PCI_CFG_GPIO_XTAL;
  1198. if (what & PLL)
  1199. out |= PCI_CFG_GPIO_PLL;
  1200. pci_write_config_dword(sii->pcibus,
  1201. PCI_GPIO_OUT, out);
  1202. pci_write_config_dword(sii->pcibus,
  1203. PCI_GPIO_OUTEN, outen);
  1204. }
  1205. return 0;
  1206. }
  1207. /* clk control mechanism through chipcommon, no policy checking */
  1208. static bool _ai_clkctl_cc(struct si_info *sii, uint mode)
  1209. {
  1210. uint origidx = 0;
  1211. struct chipcregs __iomem *cc;
  1212. u32 scc;
  1213. uint intr_val = 0;
  1214. /* chipcommon cores prior to rev6 don't support dynamic clock control */
  1215. if (ai_get_ccrev(&sii->pub) < 6)
  1216. return false;
  1217. INTR_OFF(sii, intr_val);
  1218. origidx = sii->curidx;
  1219. cc = (struct chipcregs __iomem *)
  1220. ai_setcore(&sii->pub, CC_CORE_ID, 0);
  1221. if (!(ai_get_cccaps(&sii->pub) & CC_CAP_PWR_CTL) &&
  1222. (ai_get_ccrev(&sii->pub) < 20))
  1223. goto done;
  1224. switch (mode) {
  1225. case CLK_FAST: /* FORCEHT, fast (pll) clock */
  1226. if (ai_get_ccrev(&sii->pub) < 10) {
  1227. /*
  1228. * don't forget to force xtal back
  1229. * on before we clear SCC_DYN_XTAL..
  1230. */
  1231. ai_clkctl_xtal(&sii->pub, XTAL, ON);
  1232. SET_REG(&cc->slow_clk_ctl,
  1233. (SCC_XC | SCC_FS | SCC_IP), SCC_IP);
  1234. } else if (ai_get_ccrev(&sii->pub) < 20) {
  1235. OR_REG(&cc->system_clk_ctl, SYCC_HR);
  1236. } else {
  1237. OR_REG(&cc->clk_ctl_st, CCS_FORCEHT);
  1238. }
  1239. /* wait for the PLL */
  1240. if (ai_get_cccaps(&sii->pub) & CC_CAP_PMU) {
  1241. u32 htavail = CCS_HTAVAIL;
  1242. SPINWAIT(((R_REG(&cc->clk_ctl_st) & htavail)
  1243. == 0), PMU_MAX_TRANSITION_DLY);
  1244. } else {
  1245. udelay(PLL_DELAY);
  1246. }
  1247. break;
  1248. case CLK_DYNAMIC: /* enable dynamic clock control */
  1249. if (ai_get_ccrev(&sii->pub) < 10) {
  1250. scc = R_REG(&cc->slow_clk_ctl);
  1251. scc &= ~(SCC_FS | SCC_IP | SCC_XC);
  1252. if ((scc & SCC_SS_MASK) != SCC_SS_XTAL)
  1253. scc |= SCC_XC;
  1254. W_REG(&cc->slow_clk_ctl, scc);
  1255. /*
  1256. * for dynamic control, we have to
  1257. * release our xtal_pu "force on"
  1258. */
  1259. if (scc & SCC_XC)
  1260. ai_clkctl_xtal(&sii->pub, XTAL, OFF);
  1261. } else if (ai_get_ccrev(&sii->pub) < 20) {
  1262. /* Instaclock */
  1263. AND_REG(&cc->system_clk_ctl, ~SYCC_HR);
  1264. } else {
  1265. AND_REG(&cc->clk_ctl_st, ~CCS_FORCEHT);
  1266. }
  1267. break;
  1268. default:
  1269. break;
  1270. }
  1271. done:
  1272. ai_setcoreidx(&sii->pub, origidx);
  1273. INTR_RESTORE(sii, intr_val);
  1274. return mode == CLK_FAST;
  1275. }
  1276. /*
  1277. * clock control policy function throught chipcommon
  1278. *
  1279. * set dynamic clk control mode (forceslow, forcefast, dynamic)
  1280. * returns true if we are forcing fast clock
  1281. * this is a wrapper over the next internal function
  1282. * to allow flexible policy settings for outside caller
  1283. */
  1284. bool ai_clkctl_cc(struct si_pub *sih, uint mode)
  1285. {
  1286. struct si_info *sii;
  1287. sii = (struct si_info *)sih;
  1288. /* chipcommon cores prior to rev6 don't support dynamic clock control */
  1289. if (ai_get_ccrev(sih) < 6)
  1290. return false;
  1291. if (PCI_FORCEHT(sih))
  1292. return mode == CLK_FAST;
  1293. return _ai_clkctl_cc(sii, mode);
  1294. }
  1295. /* Build device path */
  1296. int ai_devpath(struct si_pub *sih, char *path, int size)
  1297. {
  1298. int slen;
  1299. if (!path || size <= 0)
  1300. return -1;
  1301. slen = snprintf(path, (size_t) size, "pci/%u/%u/",
  1302. ((struct si_info *)sih)->pcibus->bus->number,
  1303. PCI_SLOT(((struct pci_dev *)
  1304. (((struct si_info *)(sih))->pcibus))->devfn));
  1305. if (slen < 0 || slen >= size) {
  1306. path[0] = '\0';
  1307. return -1;
  1308. }
  1309. return 0;
  1310. }
  1311. void ai_pci_up(struct si_pub *sih)
  1312. {
  1313. struct si_info *sii;
  1314. sii = (struct si_info *)sih;
  1315. if (PCI_FORCEHT(sih))
  1316. _ai_clkctl_cc(sii, CLK_FAST);
  1317. if (PCIE(sih))
  1318. pcicore_up(sii->pch, SI_PCIUP);
  1319. }
  1320. /* Unconfigure and/or apply various WARs when system is going to sleep mode */
  1321. void ai_pci_sleep(struct si_pub *sih)
  1322. {
  1323. struct si_info *sii;
  1324. sii = (struct si_info *)sih;
  1325. pcicore_sleep(sii->pch);
  1326. }
  1327. /* Unconfigure and/or apply various WARs when going down */
  1328. void ai_pci_down(struct si_pub *sih)
  1329. {
  1330. struct si_info *sii;
  1331. sii = (struct si_info *)sih;
  1332. /* release FORCEHT since chip is going to "down" state */
  1333. if (PCI_FORCEHT(sih))
  1334. _ai_clkctl_cc(sii, CLK_DYNAMIC);
  1335. pcicore_down(sii->pch, SI_PCIDOWN);
  1336. }
  1337. /*
  1338. * Configure the pci core for pci client (NIC) action
  1339. * coremask is the bitvec of cores by index to be enabled.
  1340. */
  1341. void ai_pci_setup(struct si_pub *sih, uint coremask)
  1342. {
  1343. struct si_info *sii;
  1344. struct sbpciregs __iomem *regs = NULL;
  1345. u32 siflag = 0, w;
  1346. uint idx = 0;
  1347. sii = (struct si_info *)sih;
  1348. if (PCI(sih)) {
  1349. /* get current core index */
  1350. idx = sii->curidx;
  1351. /* we interrupt on this backplane flag number */
  1352. siflag = ai_flag(sih);
  1353. /* switch over to pci core */
  1354. regs = ai_setcoreidx(sih, sii->buscoreidx);
  1355. }
  1356. /*
  1357. * Enable sb->pci interrupts. Assume
  1358. * PCI rev 2.3 support was added in pci core rev 6 and things changed..
  1359. */
  1360. if (PCIE(sih) || (PCI(sih) && (ai_get_buscorerev(sih) >= 6))) {
  1361. /* pci config write to set this core bit in PCIIntMask */
  1362. pci_read_config_dword(sii->pcibus, PCI_INT_MASK, &w);
  1363. w |= (coremask << PCI_SBIM_SHIFT);
  1364. pci_write_config_dword(sii->pcibus, PCI_INT_MASK, w);
  1365. } else {
  1366. /* set sbintvec bit for our flag number */
  1367. ai_setint(sih, siflag);
  1368. }
  1369. if (PCI(sih)) {
  1370. pcicore_pci_setup(sii->pch, regs);
  1371. /* switch back to previous core */
  1372. ai_setcoreidx(sih, idx);
  1373. }
  1374. }
  1375. /*
  1376. * Fixup SROMless PCI device's configuration.
  1377. * The current core may be changed upon return.
  1378. */
  1379. int ai_pci_fixcfg(struct si_pub *sih)
  1380. {
  1381. uint origidx;
  1382. void __iomem *regs = NULL;
  1383. struct si_info *sii = (struct si_info *)sih;
  1384. /* Fixup PI in SROM shadow area to enable the correct PCI core access */
  1385. /* save the current index */
  1386. origidx = ai_coreidx(&sii->pub);
  1387. /* check 'pi' is correct and fix it if not */
  1388. regs = ai_setcore(&sii->pub, ai_get_buscoretype(sih), 0);
  1389. if (ai_get_buscoretype(sih) == PCIE_CORE_ID)
  1390. pcicore_fixcfg_pcie(sii->pch,
  1391. (struct sbpcieregs __iomem *)regs);
  1392. else if (ai_get_buscoretype(sih) == PCI_CORE_ID)
  1393. pcicore_fixcfg_pci(sii->pch, (struct sbpciregs __iomem *)regs);
  1394. /* restore the original index */
  1395. ai_setcoreidx(&sii->pub, origidx);
  1396. pcicore_hwup(sii->pch);
  1397. return 0;
  1398. }
  1399. /* mask&set gpiocontrol bits */
  1400. u32 ai_gpiocontrol(struct si_pub *sih, u32 mask, u32 val, u8 priority)
  1401. {
  1402. uint regoff;
  1403. regoff = offsetof(struct chipcregs, gpiocontrol);
  1404. return ai_cc_reg(sih, regoff, mask, val);
  1405. }
  1406. void ai_chipcontrl_epa4331(struct si_pub *sih, bool on)
  1407. {
  1408. struct si_info *sii;
  1409. struct chipcregs __iomem *cc;
  1410. uint origidx;
  1411. u32 val;
  1412. sii = (struct si_info *)sih;
  1413. origidx = ai_coreidx(sih);
  1414. cc = (struct chipcregs __iomem *) ai_setcore(sih, CC_CORE_ID, 0);
  1415. val = R_REG(&cc->chipcontrol);
  1416. if (on) {
  1417. if (ai_get_chippkg(sih) == 9 || ai_get_chippkg(sih) == 0xb)
  1418. /* Ext PA Controls for 4331 12x9 Package */
  1419. W_REG(&cc->chipcontrol, val |
  1420. CCTRL4331_EXTPA_EN |
  1421. CCTRL4331_EXTPA_ON_GPIO2_5);
  1422. else
  1423. /* Ext PA Controls for 4331 12x12 Package */
  1424. W_REG(&cc->chipcontrol,
  1425. val | CCTRL4331_EXTPA_EN);
  1426. } else {
  1427. val &= ~(CCTRL4331_EXTPA_EN | CCTRL4331_EXTPA_ON_GPIO2_5);
  1428. W_REG(&cc->chipcontrol, val);
  1429. }
  1430. ai_setcoreidx(sih, origidx);
  1431. }
  1432. /* Enable BT-COEX & Ex-PA for 4313 */
  1433. void ai_epa_4313war(struct si_pub *sih)
  1434. {
  1435. struct si_info *sii;
  1436. struct chipcregs __iomem *cc;
  1437. uint origidx;
  1438. sii = (struct si_info *)sih;
  1439. origidx = ai_coreidx(sih);
  1440. cc = ai_setcore(sih, CC_CORE_ID, 0);
  1441. /* EPA Fix */
  1442. W_REG(&cc->gpiocontrol,
  1443. R_REG(&cc->gpiocontrol) | GPIO_CTRL_EPA_EN_MASK);
  1444. ai_setcoreidx(sih, origidx);
  1445. }
  1446. /* check if the device is removed */
  1447. bool ai_deviceremoved(struct si_pub *sih)
  1448. {
  1449. u32 w;
  1450. struct si_info *sii;
  1451. sii = (struct si_info *)sih;
  1452. pci_read_config_dword(sii->pcibus, PCI_VENDOR_ID, &w);
  1453. if ((w & 0xFFFF) != PCI_VENDOR_ID_BROADCOM)
  1454. return true;
  1455. return false;
  1456. }
  1457. bool ai_is_sprom_available(struct si_pub *sih)
  1458. {
  1459. struct si_info *sii = (struct si_info *)sih;
  1460. if (ai_get_ccrev(sih) >= 31) {
  1461. uint origidx;
  1462. struct chipcregs __iomem *cc;
  1463. u32 sromctrl;
  1464. if ((ai_get_cccaps(sih) & CC_CAP_SROM) == 0)
  1465. return false;
  1466. origidx = sii->curidx;
  1467. cc = ai_setcoreidx(sih, SI_CC_IDX);
  1468. sromctrl = R_REG(&cc->sromcontrol);
  1469. ai_setcoreidx(sih, origidx);
  1470. return sromctrl & SRC_PRESENT;
  1471. }
  1472. switch (ai_get_chip_id(sih)) {
  1473. case BCM4313_CHIP_ID:
  1474. return (sii->chipst & CST4313_SPROM_PRESENT) != 0;
  1475. default:
  1476. return true;
  1477. }
  1478. }
  1479. bool ai_is_otp_disabled(struct si_pub *sih)
  1480. {
  1481. struct si_info *sii = (struct si_info *)sih;
  1482. switch (ai_get_chip_id(sih)) {
  1483. case BCM4313_CHIP_ID:
  1484. return (sii->chipst & CST4313_OTP_PRESENT) == 0;
  1485. /* These chips always have their OTP on */
  1486. case BCM43224_CHIP_ID:
  1487. case BCM43225_CHIP_ID:
  1488. default:
  1489. return false;
  1490. }
  1491. }