aiutils.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. /*
  2. * Copyright (c) 2011 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. #ifndef _BRCM_AIUTILS_H_
  17. #define _BRCM_AIUTILS_H_
  18. #include "types.h"
  19. /*
  20. * SOC Interconnect Address Map.
  21. * All regions may not exist on all chips.
  22. */
  23. /* each core gets 4Kbytes for registers */
  24. #define SI_CORE_SIZE 0x1000
  25. /*
  26. * Max cores (this is arbitrary, for software
  27. * convenience and could be changed if we
  28. * make any larger chips
  29. */
  30. #define SI_MAXCORES 16
  31. /* Client Mode sb2pcitranslation2 size in bytes */
  32. #define SI_PCI_DMA_SZ 0x40000000
  33. /* PCIE Client Mode sb2pcitranslation2 (2 ZettaBytes), high 32 bits */
  34. #define SI_PCIE_DMA_H32 0x80000000
  35. /* core codes */
  36. #define NODEV_CORE_ID 0x700 /* Invalid coreid */
  37. #define CC_CORE_ID 0x800 /* chipcommon core */
  38. #define ILINE20_CORE_ID 0x801 /* iline20 core */
  39. #define SRAM_CORE_ID 0x802 /* sram core */
  40. #define SDRAM_CORE_ID 0x803 /* sdram core */
  41. #define PCI_CORE_ID 0x804 /* pci core */
  42. #define MIPS_CORE_ID 0x805 /* mips core */
  43. #define ENET_CORE_ID 0x806 /* enet mac core */
  44. #define CODEC_CORE_ID 0x807 /* v90 codec core */
  45. #define USB_CORE_ID 0x808 /* usb 1.1 host/device core */
  46. #define ADSL_CORE_ID 0x809 /* ADSL core */
  47. #define ILINE100_CORE_ID 0x80a /* iline100 core */
  48. #define IPSEC_CORE_ID 0x80b /* ipsec core */
  49. #define UTOPIA_CORE_ID 0x80c /* utopia core */
  50. #define PCMCIA_CORE_ID 0x80d /* pcmcia core */
  51. #define SOCRAM_CORE_ID 0x80e /* internal memory core */
  52. #define MEMC_CORE_ID 0x80f /* memc sdram core */
  53. #define OFDM_CORE_ID 0x810 /* OFDM phy core */
  54. #define EXTIF_CORE_ID 0x811 /* external interface core */
  55. #define D11_CORE_ID 0x812 /* 802.11 MAC core */
  56. #define APHY_CORE_ID 0x813 /* 802.11a phy core */
  57. #define BPHY_CORE_ID 0x814 /* 802.11b phy core */
  58. #define GPHY_CORE_ID 0x815 /* 802.11g phy core */
  59. #define MIPS33_CORE_ID 0x816 /* mips3302 core */
  60. #define USB11H_CORE_ID 0x817 /* usb 1.1 host core */
  61. #define USB11D_CORE_ID 0x818 /* usb 1.1 device core */
  62. #define USB20H_CORE_ID 0x819 /* usb 2.0 host core */
  63. #define USB20D_CORE_ID 0x81a /* usb 2.0 device core */
  64. #define SDIOH_CORE_ID 0x81b /* sdio host core */
  65. #define ROBO_CORE_ID 0x81c /* roboswitch core */
  66. #define ATA100_CORE_ID 0x81d /* parallel ATA core */
  67. #define SATAXOR_CORE_ID 0x81e /* serial ATA & XOR DMA core */
  68. #define GIGETH_CORE_ID 0x81f /* gigabit ethernet core */
  69. #define PCIE_CORE_ID 0x820 /* pci express core */
  70. #define NPHY_CORE_ID 0x821 /* 802.11n 2x2 phy core */
  71. #define SRAMC_CORE_ID 0x822 /* SRAM controller core */
  72. #define MINIMAC_CORE_ID 0x823 /* MINI MAC/phy core */
  73. #define ARM11_CORE_ID 0x824 /* ARM 1176 core */
  74. #define ARM7S_CORE_ID 0x825 /* ARM7tdmi-s core */
  75. #define LPPHY_CORE_ID 0x826 /* 802.11a/b/g phy core */
  76. #define PMU_CORE_ID 0x827 /* PMU core */
  77. #define SSNPHY_CORE_ID 0x828 /* 802.11n single-stream phy core */
  78. #define SDIOD_CORE_ID 0x829 /* SDIO device core */
  79. #define ARMCM3_CORE_ID 0x82a /* ARM Cortex M3 core */
  80. #define HTPHY_CORE_ID 0x82b /* 802.11n 4x4 phy core */
  81. #define MIPS74K_CORE_ID 0x82c /* mips 74k core */
  82. #define GMAC_CORE_ID 0x82d /* Gigabit MAC core */
  83. #define DMEMC_CORE_ID 0x82e /* DDR1/2 memory controller core */
  84. #define PCIERC_CORE_ID 0x82f /* PCIE Root Complex core */
  85. #define OCP_CORE_ID 0x830 /* OCP2OCP bridge core */
  86. #define SC_CORE_ID 0x831 /* shared common core */
  87. #define AHB_CORE_ID 0x832 /* OCP2AHB bridge core */
  88. #define SPIH_CORE_ID 0x833 /* SPI host core */
  89. #define I2S_CORE_ID 0x834 /* I2S core */
  90. #define DMEMS_CORE_ID 0x835 /* SDR/DDR1 memory controller core */
  91. #define DEF_SHIM_COMP 0x837 /* SHIM component in ubus/6362 */
  92. #define OOB_ROUTER_CORE_ID 0x367 /* OOB router core ID */
  93. #define DEF_AI_COMP 0xfff /* Default component, in ai chips it
  94. * maps all unused address ranges
  95. */
  96. /* chipcommon being the first core: */
  97. #define SI_CC_IDX 0
  98. /* SOC Interconnect types (aka chip types) */
  99. #define SOCI_AI 1
  100. /* Common core control flags */
  101. #define SICF_BIST_EN 0x8000
  102. #define SICF_PME_EN 0x4000
  103. #define SICF_CORE_BITS 0x3ffc
  104. #define SICF_FGC 0x0002
  105. #define SICF_CLOCK_EN 0x0001
  106. /* Common core status flags */
  107. #define SISF_BIST_DONE 0x8000
  108. #define SISF_BIST_ERROR 0x4000
  109. #define SISF_GATED_CLK 0x2000
  110. #define SISF_DMA64 0x1000
  111. #define SISF_CORE_BITS 0x0fff
  112. /* A register that is common to all cores to
  113. * communicate w/PMU regarding clock control.
  114. */
  115. #define SI_CLK_CTL_ST 0x1e0 /* clock control and status */
  116. /* clk_ctl_st register */
  117. #define CCS_FORCEALP 0x00000001 /* force ALP request */
  118. #define CCS_FORCEHT 0x00000002 /* force HT request */
  119. #define CCS_FORCEILP 0x00000004 /* force ILP request */
  120. #define CCS_ALPAREQ 0x00000008 /* ALP Avail Request */
  121. #define CCS_HTAREQ 0x00000010 /* HT Avail Request */
  122. #define CCS_FORCEHWREQOFF 0x00000020 /* Force HW Clock Request Off */
  123. #define CCS_ERSRC_REQ_MASK 0x00000700 /* external resource requests */
  124. #define CCS_ERSRC_REQ_SHIFT 8
  125. #define CCS_ALPAVAIL 0x00010000 /* ALP is available */
  126. #define CCS_HTAVAIL 0x00020000 /* HT is available */
  127. #define CCS_BP_ON_APL 0x00040000 /* RO: running on ALP clock */
  128. #define CCS_BP_ON_HT 0x00080000 /* RO: running on HT clock */
  129. #define CCS_ERSRC_STS_MASK 0x07000000 /* external resource status */
  130. #define CCS_ERSRC_STS_SHIFT 24
  131. /* HT avail in chipc and pcmcia on 4328a0 */
  132. #define CCS0_HTAVAIL 0x00010000
  133. /* ALP avail in chipc and pcmcia on 4328a0 */
  134. #define CCS0_ALPAVAIL 0x00020000
  135. /* Not really related to SOC Interconnect, but a couple of software
  136. * conventions for the use the flash space:
  137. */
  138. /* Minumum amount of flash we support */
  139. #define FLASH_MIN 0x00020000 /* Minimum flash size */
  140. #define CC_SROM_OTP 0x800 /* SROM/OTP address space */
  141. /* gpiotimerval */
  142. #define GPIO_ONTIME_SHIFT 16
  143. /* Fields in clkdiv */
  144. #define CLKD_OTP 0x000f0000
  145. #define CLKD_OTP_SHIFT 16
  146. /* Package IDs */
  147. #define BCM4717_PKG_ID 9 /* 4717 package id */
  148. #define BCM4718_PKG_ID 10 /* 4718 package id */
  149. #define BCM43224_FAB_SMIC 0xa /* the chip is manufactured by SMIC */
  150. /* these are router chips */
  151. #define BCM4716_CHIP_ID 0x4716 /* 4716 chipcommon chipid */
  152. #define BCM47162_CHIP_ID 47162 /* 47162 chipcommon chipid */
  153. #define BCM4748_CHIP_ID 0x4748 /* 4716 chipcommon chipid (OTP, RBBU) */
  154. /* dynamic clock control defines */
  155. #define LPOMINFREQ 25000 /* low power oscillator min */
  156. #define LPOMAXFREQ 43000 /* low power oscillator max */
  157. #define XTALMINFREQ 19800000 /* 20 MHz - 1% */
  158. #define XTALMAXFREQ 20200000 /* 20 MHz + 1% */
  159. #define PCIMINFREQ 25000000 /* 25 MHz */
  160. #define PCIMAXFREQ 34000000 /* 33 MHz + fudge */
  161. #define ILP_DIV_5MHZ 0 /* ILP = 5 MHz */
  162. #define ILP_DIV_1MHZ 4 /* ILP = 1 MHz */
  163. /* clkctl xtal what flags */
  164. #define XTAL 0x1 /* primary crystal oscillator (2050) */
  165. #define PLL 0x2 /* main chip pll */
  166. /* clkctl clk mode */
  167. #define CLK_FAST 0 /* force fast (pll) clock */
  168. #define CLK_DYNAMIC 2 /* enable dynamic clock control */
  169. /* GPIO usage priorities */
  170. #define GPIO_DRV_PRIORITY 0 /* Driver */
  171. #define GPIO_APP_PRIORITY 1 /* Application */
  172. #define GPIO_HI_PRIORITY 2 /* Highest priority. Ignore GPIO
  173. * reservation
  174. */
  175. /* GPIO pull up/down */
  176. #define GPIO_PULLUP 0
  177. #define GPIO_PULLDN 1
  178. /* GPIO event regtype */
  179. #define GPIO_REGEVT 0 /* GPIO register event */
  180. #define GPIO_REGEVT_INTMSK 1 /* GPIO register event int mask */
  181. #define GPIO_REGEVT_INTPOL 2 /* GPIO register event int polarity */
  182. /* device path */
  183. #define SI_DEVPATH_BUFSZ 16 /* min buffer size in bytes */
  184. /* SI routine enumeration: to be used by update function with multiple hooks */
  185. #define SI_DOATTACH 1
  186. #define SI_PCIDOWN 2
  187. #define SI_PCIUP 3
  188. /*
  189. * Data structure to export all chip specific common variables
  190. * public (read-only) portion of aiutils handle returned by si_attach()
  191. */
  192. struct si_pub {
  193. uint buscoretype; /* PCI_CORE_ID, PCIE_CORE_ID, PCMCIA_CORE_ID */
  194. uint buscorerev; /* buscore rev */
  195. uint buscoreidx; /* buscore index */
  196. int ccrev; /* chip common core rev */
  197. u32 cccaps; /* chip common capabilities */
  198. u32 cccaps_ext; /* chip common capabilities extension */
  199. int pmurev; /* pmu core rev */
  200. u32 pmucaps; /* pmu capabilities */
  201. uint boardtype; /* board type */
  202. uint boardvendor; /* board vendor */
  203. uint boardflags; /* board flags */
  204. uint boardflags2; /* board flags2 */
  205. uint chip; /* chip number */
  206. uint chiprev; /* chip revision */
  207. uint chippkg; /* chip package option */
  208. u32 chipst; /* chip status */
  209. bool issim; /* chip is in simulation or emulation */
  210. uint socirev; /* SOC interconnect rev */
  211. bool pci_pr32414;
  212. };
  213. struct pci_dev;
  214. struct gpioh_item {
  215. void *arg;
  216. bool level;
  217. void (*handler) (u32 stat, void *arg);
  218. u32 event;
  219. struct gpioh_item *next;
  220. };
  221. /* misc si info needed by some of the routines */
  222. struct si_info {
  223. struct si_pub pub; /* back plane public state (must be first) */
  224. struct pci_dev *pbus; /* handle to pci bus */
  225. uint dev_coreid; /* the core provides driver functions */
  226. void *intr_arg; /* interrupt callback function arg */
  227. u32 (*intrsoff_fn) (void *intr_arg); /* turns chip interrupts off */
  228. /* restore chip interrupts */
  229. void (*intrsrestore_fn) (void *intr_arg, u32 arg);
  230. /* check if interrupts are enabled */
  231. bool (*intrsenabled_fn) (void *intr_arg);
  232. struct pcicore_info *pch; /* PCI/E core handle */
  233. struct list_head var_list; /* list of srom variables */
  234. void __iomem *curmap; /* current regs va */
  235. void __iomem *regs[SI_MAXCORES]; /* other regs va */
  236. uint curidx; /* current core index */
  237. uint numcores; /* # discovered cores */
  238. uint coreid[SI_MAXCORES]; /* id of each core */
  239. u32 coresba[SI_MAXCORES]; /* backplane address of each core */
  240. void *regs2[SI_MAXCORES]; /* 2nd virtual address per core (usbh20) */
  241. u32 coresba2[SI_MAXCORES]; /* 2nd phys address per core (usbh20) */
  242. u32 coresba_size[SI_MAXCORES]; /* backplane address space size */
  243. u32 coresba2_size[SI_MAXCORES]; /* second address space size */
  244. void *curwrap; /* current wrapper va */
  245. void *wrappers[SI_MAXCORES]; /* other cores wrapper va */
  246. u32 wrapba[SI_MAXCORES]; /* address of controlling wrapper */
  247. u32 cia[SI_MAXCORES]; /* erom cia entry for each core */
  248. u32 cib[SI_MAXCORES]; /* erom cia entry for each core */
  249. u32 oob_router; /* oob router registers for axi */
  250. };
  251. /*
  252. * Many of the routines below take an 'sih' handle as their first arg.
  253. * Allocate this by calling si_attach(). Free it by calling si_detach().
  254. * At any one time, the sih is logically focused on one particular si core
  255. * (the "current core").
  256. * Use si_setcore() or si_setcoreidx() to change the association to another core
  257. */
  258. /* AMBA Interconnect exported externs */
  259. extern uint ai_flag(struct si_pub *sih);
  260. extern void ai_setint(struct si_pub *sih, int siflag);
  261. extern uint ai_coreidx(struct si_pub *sih);
  262. extern uint ai_corevendor(struct si_pub *sih);
  263. extern uint ai_corerev(struct si_pub *sih);
  264. extern bool ai_iscoreup(struct si_pub *sih);
  265. extern u32 ai_core_cflags(struct si_pub *sih, u32 mask, u32 val);
  266. extern void ai_core_cflags_wo(struct si_pub *sih, u32 mask, u32 val);
  267. extern u32 ai_core_sflags(struct si_pub *sih, u32 mask, u32 val);
  268. extern uint ai_corereg(struct si_pub *sih, uint coreidx, uint regoff, uint mask,
  269. uint val);
  270. extern void ai_core_reset(struct si_pub *sih, u32 bits, u32 resetbits);
  271. extern void ai_core_disable(struct si_pub *sih, u32 bits);
  272. extern int ai_numaddrspaces(struct si_pub *sih);
  273. extern u32 ai_addrspace(struct si_pub *sih, uint asidx);
  274. extern u32 ai_addrspacesize(struct si_pub *sih, uint asidx);
  275. extern void ai_write_wrap_reg(struct si_pub *sih, u32 offset, u32 val);
  276. /* === exported functions === */
  277. extern struct si_pub *ai_attach(void __iomem *regs, struct pci_dev *sdh);
  278. extern void ai_detach(struct si_pub *sih);
  279. extern uint ai_coreid(struct si_pub *sih);
  280. extern uint ai_corerev(struct si_pub *sih);
  281. extern uint ai_corereg(struct si_pub *sih, uint coreidx, uint regoff, uint mask,
  282. uint val);
  283. extern void ai_write_wrapperreg(struct si_pub *sih, u32 offset, u32 val);
  284. extern u32 ai_core_cflags(struct si_pub *sih, u32 mask, u32 val);
  285. extern u32 ai_core_sflags(struct si_pub *sih, u32 mask, u32 val);
  286. extern bool ai_iscoreup(struct si_pub *sih);
  287. extern uint ai_findcoreidx(struct si_pub *sih, uint coreid, uint coreunit);
  288. extern void __iomem *ai_setcoreidx(struct si_pub *sih, uint coreidx);
  289. extern void __iomem *ai_setcore(struct si_pub *sih, uint coreid, uint coreunit);
  290. extern void __iomem *ai_switch_core(struct si_pub *sih, uint coreid,
  291. uint *origidx, uint *intr_val);
  292. extern void ai_restore_core(struct si_pub *sih, uint coreid, uint intr_val);
  293. extern void ai_core_reset(struct si_pub *sih, u32 bits, u32 resetbits);
  294. extern void ai_core_disable(struct si_pub *sih, u32 bits);
  295. extern u32 ai_alp_clock(struct si_pub *sih);
  296. extern u32 ai_ilp_clock(struct si_pub *sih);
  297. extern void ai_pci_setup(struct si_pub *sih, uint coremask);
  298. extern void ai_setint(struct si_pub *sih, int siflag);
  299. extern bool ai_backplane64(struct si_pub *sih);
  300. extern void ai_register_intr_callback(struct si_pub *sih, void *intrsoff_fn,
  301. void *intrsrestore_fn,
  302. void *intrsenabled_fn, void *intr_arg);
  303. extern void ai_deregister_intr_callback(struct si_pub *sih);
  304. extern void ai_clkctl_init(struct si_pub *sih);
  305. extern u16 ai_clkctl_fast_pwrup_delay(struct si_pub *sih);
  306. extern bool ai_clkctl_cc(struct si_pub *sih, uint mode);
  307. extern int ai_clkctl_xtal(struct si_pub *sih, uint what, bool on);
  308. extern bool ai_deviceremoved(struct si_pub *sih);
  309. extern u32 ai_gpiocontrol(struct si_pub *sih, u32 mask, u32 val,
  310. u8 priority);
  311. /* OTP status */
  312. extern bool ai_is_otp_disabled(struct si_pub *sih);
  313. /* SPROM availability */
  314. extern bool ai_is_sprom_available(struct si_pub *sih);
  315. /*
  316. * Build device path. Path size must be >= SI_DEVPATH_BUFSZ.
  317. * The returned path is NULL terminated and has trailing '/'.
  318. * Return 0 on success, nonzero otherwise.
  319. */
  320. extern int ai_devpath(struct si_pub *sih, char *path, int size);
  321. extern void ai_pci_sleep(struct si_pub *sih);
  322. extern void ai_pci_down(struct si_pub *sih);
  323. extern void ai_pci_up(struct si_pub *sih);
  324. extern int ai_pci_fixcfg(struct si_pub *sih);
  325. extern void ai_chipcontrl_epa4331(struct si_pub *sih, bool on);
  326. /* Enable Ex-PA for 4313 */
  327. extern void ai_epa_4313war(struct si_pub *sih);
  328. #endif /* _BRCM_AIUTILS_H_ */