aiutils.h 11 KB

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