aiutils.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  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. /* chipcommon being the first core: */
  36. #define SI_CC_IDX 0
  37. /* SOC Interconnect types (aka chip types) */
  38. #define SOCI_AI 1
  39. /* A register that is common to all cores to
  40. * communicate w/PMU regarding clock control.
  41. */
  42. #define SI_CLK_CTL_ST 0x1e0 /* clock control and status */
  43. /* clk_ctl_st register */
  44. #define CCS_FORCEALP 0x00000001 /* force ALP request */
  45. #define CCS_FORCEHT 0x00000002 /* force HT request */
  46. #define CCS_FORCEILP 0x00000004 /* force ILP request */
  47. #define CCS_ALPAREQ 0x00000008 /* ALP Avail Request */
  48. #define CCS_HTAREQ 0x00000010 /* HT Avail Request */
  49. #define CCS_FORCEHWREQOFF 0x00000020 /* Force HW Clock Request Off */
  50. #define CCS_ERSRC_REQ_MASK 0x00000700 /* external resource requests */
  51. #define CCS_ERSRC_REQ_SHIFT 8
  52. #define CCS_ALPAVAIL 0x00010000 /* ALP is available */
  53. #define CCS_HTAVAIL 0x00020000 /* HT is available */
  54. #define CCS_BP_ON_APL 0x00040000 /* RO: running on ALP clock */
  55. #define CCS_BP_ON_HT 0x00080000 /* RO: running on HT clock */
  56. #define CCS_ERSRC_STS_MASK 0x07000000 /* external resource status */
  57. #define CCS_ERSRC_STS_SHIFT 24
  58. /* HT avail in chipc and pcmcia on 4328a0 */
  59. #define CCS0_HTAVAIL 0x00010000
  60. /* ALP avail in chipc and pcmcia on 4328a0 */
  61. #define CCS0_ALPAVAIL 0x00020000
  62. /* Not really related to SOC Interconnect, but a couple of software
  63. * conventions for the use the flash space:
  64. */
  65. /* Minumum amount of flash we support */
  66. #define FLASH_MIN 0x00020000 /* Minimum flash size */
  67. #define CC_SROM_OTP 0x800 /* SROM/OTP address space */
  68. /* gpiotimerval */
  69. #define GPIO_ONTIME_SHIFT 16
  70. /* Fields in clkdiv */
  71. #define CLKD_OTP 0x000f0000
  72. #define CLKD_OTP_SHIFT 16
  73. /* Package IDs */
  74. #define BCM4717_PKG_ID 9 /* 4717 package id */
  75. #define BCM4718_PKG_ID 10 /* 4718 package id */
  76. #define BCM43224_FAB_SMIC 0xa /* the chip is manufactured by SMIC */
  77. /* these are router chips */
  78. #define BCM4716_CHIP_ID 0x4716 /* 4716 chipcommon chipid */
  79. #define BCM47162_CHIP_ID 47162 /* 47162 chipcommon chipid */
  80. #define BCM4748_CHIP_ID 0x4748 /* 4716 chipcommon chipid (OTP, RBBU) */
  81. /* dynamic clock control defines */
  82. #define LPOMINFREQ 25000 /* low power oscillator min */
  83. #define LPOMAXFREQ 43000 /* low power oscillator max */
  84. #define XTALMINFREQ 19800000 /* 20 MHz - 1% */
  85. #define XTALMAXFREQ 20200000 /* 20 MHz + 1% */
  86. #define PCIMINFREQ 25000000 /* 25 MHz */
  87. #define PCIMAXFREQ 34000000 /* 33 MHz + fudge */
  88. #define ILP_DIV_5MHZ 0 /* ILP = 5 MHz */
  89. #define ILP_DIV_1MHZ 4 /* ILP = 1 MHz */
  90. /* clkctl xtal what flags */
  91. #define XTAL 0x1 /* primary crystal oscillator (2050) */
  92. #define PLL 0x2 /* main chip pll */
  93. /* clkctl clk mode */
  94. #define CLK_FAST 0 /* force fast (pll) clock */
  95. #define CLK_DYNAMIC 2 /* enable dynamic clock control */
  96. /* GPIO usage priorities */
  97. #define GPIO_DRV_PRIORITY 0 /* Driver */
  98. #define GPIO_APP_PRIORITY 1 /* Application */
  99. #define GPIO_HI_PRIORITY 2 /* Highest priority. Ignore GPIO
  100. * reservation
  101. */
  102. /* GPIO pull up/down */
  103. #define GPIO_PULLUP 0
  104. #define GPIO_PULLDN 1
  105. /* GPIO event regtype */
  106. #define GPIO_REGEVT 0 /* GPIO register event */
  107. #define GPIO_REGEVT_INTMSK 1 /* GPIO register event int mask */
  108. #define GPIO_REGEVT_INTPOL 2 /* GPIO register event int polarity */
  109. /* device path */
  110. #define SI_DEVPATH_BUFSZ 16 /* min buffer size in bytes */
  111. /* SI routine enumeration: to be used by update function with multiple hooks */
  112. #define SI_DOATTACH 1
  113. #define SI_PCIDOWN 2
  114. #define SI_PCIUP 3
  115. /*
  116. * Data structure to export all chip specific common variables
  117. * public (read-only) portion of aiutils handle returned by si_attach()
  118. */
  119. struct si_pub {
  120. uint buscoretype; /* PCI_CORE_ID, PCIE_CORE_ID, PCMCIA_CORE_ID */
  121. uint buscorerev; /* buscore rev */
  122. int ccrev; /* chip common core rev */
  123. u32 cccaps; /* chip common capabilities */
  124. int pmurev; /* pmu core rev */
  125. u32 pmucaps; /* pmu capabilities */
  126. uint boardtype; /* board type */
  127. uint boardvendor; /* board vendor */
  128. uint chip; /* chip number */
  129. uint chiprev; /* chip revision */
  130. uint chippkg; /* chip package option */
  131. };
  132. struct pci_dev;
  133. struct gpioh_item {
  134. void *arg;
  135. bool level;
  136. void (*handler) (u32 stat, void *arg);
  137. u32 event;
  138. struct gpioh_item *next;
  139. };
  140. /* misc si info needed by some of the routines */
  141. struct si_info {
  142. struct si_pub pub; /* back plane public state (must be first) */
  143. struct pci_dev *pbus; /* handle to pci bus */
  144. uint dev_coreid; /* the core provides driver functions */
  145. void *intr_arg; /* interrupt callback function arg */
  146. u32 (*intrsoff_fn) (void *intr_arg); /* turns chip interrupts off */
  147. /* restore chip interrupts */
  148. void (*intrsrestore_fn) (void *intr_arg, u32 arg);
  149. /* check if interrupts are enabled */
  150. bool (*intrsenabled_fn) (void *intr_arg);
  151. struct pcicore_info *pch; /* PCI/E core handle */
  152. struct list_head var_list; /* list of srom variables */
  153. void __iomem *curmap; /* current regs va */
  154. void __iomem *regs[SI_MAXCORES]; /* other regs va */
  155. u32 chipst; /* chip status */
  156. uint curidx; /* current core index */
  157. uint buscoreidx; /* buscore index */
  158. uint numcores; /* # discovered cores */
  159. uint coreid[SI_MAXCORES]; /* id of each core */
  160. u32 coresba[SI_MAXCORES]; /* backplane address of each core */
  161. void *regs2[SI_MAXCORES]; /* 2nd virtual address per core (usbh20) */
  162. u32 coresba2[SI_MAXCORES]; /* 2nd phys address per core (usbh20) */
  163. u32 coresba_size[SI_MAXCORES]; /* backplane address space size */
  164. u32 coresba2_size[SI_MAXCORES]; /* second address space size */
  165. void *curwrap; /* current wrapper va */
  166. void *wrappers[SI_MAXCORES]; /* other cores wrapper va */
  167. u32 wrapba[SI_MAXCORES]; /* address of controlling wrapper */
  168. u32 cia[SI_MAXCORES]; /* erom cia entry for each core */
  169. u32 cib[SI_MAXCORES]; /* erom cia entry for each core */
  170. u32 oob_router; /* oob router registers for axi */
  171. };
  172. /*
  173. * Many of the routines below take an 'sih' handle as their first arg.
  174. * Allocate this by calling si_attach(). Free it by calling si_detach().
  175. * At any one time, the sih is logically focused on one particular si core
  176. * (the "current core").
  177. * Use si_setcore() or si_setcoreidx() to change the association to another core
  178. */
  179. /* AMBA Interconnect exported externs */
  180. extern uint ai_flag(struct si_pub *sih);
  181. extern void ai_setint(struct si_pub *sih, int siflag);
  182. extern uint ai_coreidx(struct si_pub *sih);
  183. extern uint ai_corevendor(struct si_pub *sih);
  184. extern uint ai_corerev(struct si_pub *sih);
  185. extern bool ai_iscoreup(struct si_pub *sih);
  186. extern u32 ai_core_cflags(struct si_pub *sih, u32 mask, u32 val);
  187. extern void ai_core_cflags_wo(struct si_pub *sih, u32 mask, u32 val);
  188. extern u32 ai_core_sflags(struct si_pub *sih, u32 mask, u32 val);
  189. extern uint ai_corereg(struct si_pub *sih, uint coreidx, uint regoff, uint mask,
  190. uint val);
  191. extern void ai_core_reset(struct si_pub *sih, u32 bits, u32 resetbits);
  192. extern void ai_core_disable(struct si_pub *sih, u32 bits);
  193. extern int ai_numaddrspaces(struct si_pub *sih);
  194. extern u32 ai_addrspace(struct si_pub *sih, uint asidx);
  195. extern u32 ai_addrspacesize(struct si_pub *sih, uint asidx);
  196. extern void ai_write_wrap_reg(struct si_pub *sih, u32 offset, u32 val);
  197. /* === exported functions === */
  198. extern struct si_pub *ai_attach(void __iomem *regs, struct pci_dev *sdh);
  199. extern void ai_detach(struct si_pub *sih);
  200. extern uint ai_coreid(struct si_pub *sih);
  201. extern uint ai_corerev(struct si_pub *sih);
  202. extern uint ai_corereg(struct si_pub *sih, uint coreidx, uint regoff, uint mask,
  203. uint val);
  204. extern void ai_write_wrapperreg(struct si_pub *sih, u32 offset, u32 val);
  205. extern u32 ai_core_cflags(struct si_pub *sih, u32 mask, u32 val);
  206. extern u32 ai_core_sflags(struct si_pub *sih, u32 mask, u32 val);
  207. extern bool ai_iscoreup(struct si_pub *sih);
  208. extern uint ai_findcoreidx(struct si_pub *sih, uint coreid, uint coreunit);
  209. extern void __iomem *ai_setcoreidx(struct si_pub *sih, uint coreidx);
  210. extern void __iomem *ai_setcore(struct si_pub *sih, uint coreid, uint coreunit);
  211. extern void __iomem *ai_switch_core(struct si_pub *sih, uint coreid,
  212. uint *origidx, uint *intr_val);
  213. extern void ai_restore_core(struct si_pub *sih, uint coreid, uint intr_val);
  214. extern void ai_core_reset(struct si_pub *sih, u32 bits, u32 resetbits);
  215. extern void ai_core_disable(struct si_pub *sih, u32 bits);
  216. extern u32 ai_alp_clock(struct si_pub *sih);
  217. extern u32 ai_ilp_clock(struct si_pub *sih);
  218. extern void ai_pci_setup(struct si_pub *sih, uint coremask);
  219. extern void ai_setint(struct si_pub *sih, int siflag);
  220. extern bool ai_backplane64(struct si_pub *sih);
  221. extern void ai_register_intr_callback(struct si_pub *sih, void *intrsoff_fn,
  222. void *intrsrestore_fn,
  223. void *intrsenabled_fn, void *intr_arg);
  224. extern void ai_deregister_intr_callback(struct si_pub *sih);
  225. extern void ai_clkctl_init(struct si_pub *sih);
  226. extern u16 ai_clkctl_fast_pwrup_delay(struct si_pub *sih);
  227. extern bool ai_clkctl_cc(struct si_pub *sih, uint mode);
  228. extern int ai_clkctl_xtal(struct si_pub *sih, uint what, bool on);
  229. extern bool ai_deviceremoved(struct si_pub *sih);
  230. extern u32 ai_gpiocontrol(struct si_pub *sih, u32 mask, u32 val,
  231. u8 priority);
  232. /* OTP status */
  233. extern bool ai_is_otp_disabled(struct si_pub *sih);
  234. /* SPROM availability */
  235. extern bool ai_is_sprom_available(struct si_pub *sih);
  236. /*
  237. * Build device path. Path size must be >= SI_DEVPATH_BUFSZ.
  238. * The returned path is NULL terminated and has trailing '/'.
  239. * Return 0 on success, nonzero otherwise.
  240. */
  241. extern int ai_devpath(struct si_pub *sih, char *path, int size);
  242. extern void ai_pci_sleep(struct si_pub *sih);
  243. extern void ai_pci_down(struct si_pub *sih);
  244. extern void ai_pci_up(struct si_pub *sih);
  245. extern int ai_pci_fixcfg(struct si_pub *sih);
  246. extern void ai_chipcontrl_epa4331(struct si_pub *sih, bool on);
  247. /* Enable Ex-PA for 4313 */
  248. extern void ai_epa_4313war(struct si_pub *sih);
  249. static inline uint ai_get_buscoretype(struct si_pub *sih)
  250. {
  251. return sih->buscoretype;
  252. }
  253. static inline uint ai_get_buscorerev(struct si_pub *sih)
  254. {
  255. return sih->buscorerev;
  256. }
  257. static inline int ai_get_ccrev(struct si_pub *sih)
  258. {
  259. return sih->ccrev;
  260. }
  261. static inline u32 ai_get_cccaps(struct si_pub *sih)
  262. {
  263. return sih->cccaps;
  264. }
  265. static inline int ai_get_pmurev(struct si_pub *sih)
  266. {
  267. return sih->pmurev;
  268. }
  269. static inline u32 ai_get_pmucaps(struct si_pub *sih)
  270. {
  271. return sih->pmucaps;
  272. }
  273. static inline uint ai_get_boardtype(struct si_pub *sih)
  274. {
  275. return sih->boardtype;
  276. }
  277. static inline uint ai_get_boardvendor(struct si_pub *sih)
  278. {
  279. return sih->boardvendor;
  280. }
  281. static inline uint ai_get_chip_id(struct si_pub *sih)
  282. {
  283. return sih->chip;
  284. }
  285. static inline uint ai_get_chiprev(struct si_pub *sih)
  286. {
  287. return sih->chiprev;
  288. }
  289. static inline uint ai_get_chippkg(struct si_pub *sih)
  290. {
  291. return sih->chippkg;
  292. }
  293. #endif /* _BRCM_AIUTILS_H_ */