aiutils.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  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_flag(struct si_pub *sih);
  183. extern void ai_setint(struct si_pub *sih, int siflag);
  184. extern uint ai_coreidx(struct si_pub *sih);
  185. extern uint ai_corevendor(struct si_pub *sih);
  186. extern uint ai_corerev(struct si_pub *sih);
  187. extern bool ai_iscoreup(struct si_pub *sih);
  188. extern u32 ai_core_cflags(struct si_pub *sih, u32 mask, u32 val);
  189. extern void ai_core_cflags_wo(struct si_pub *sih, u32 mask, u32 val);
  190. extern u32 ai_core_sflags(struct si_pub *sih, u32 mask, u32 val);
  191. extern uint ai_corereg(struct si_pub *sih, uint coreidx, uint regoff, uint mask,
  192. uint val);
  193. extern void ai_core_reset(struct si_pub *sih, u32 bits, u32 resetbits);
  194. extern void ai_core_disable(struct si_pub *sih, u32 bits);
  195. extern int ai_numaddrspaces(struct si_pub *sih);
  196. extern u32 ai_addrspace(struct si_pub *sih, uint asidx);
  197. extern u32 ai_addrspacesize(struct si_pub *sih, uint asidx);
  198. extern void ai_write_wrap_reg(struct si_pub *sih, u32 offset, u32 val);
  199. /* === exported functions === */
  200. extern struct si_pub *ai_attach(struct bcma_bus *pbus);
  201. extern void ai_detach(struct si_pub *sih);
  202. extern uint ai_coreid(struct si_pub *sih);
  203. extern uint ai_corerev(struct si_pub *sih);
  204. extern uint ai_corereg(struct si_pub *sih, uint coreidx, uint regoff, uint mask,
  205. uint val);
  206. extern void ai_write_wrapperreg(struct si_pub *sih, u32 offset, u32 val);
  207. extern u32 ai_core_cflags(struct si_pub *sih, u32 mask, u32 val);
  208. extern u32 ai_core_sflags(struct si_pub *sih, u32 mask, u32 val);
  209. extern bool ai_iscoreup(struct si_pub *sih);
  210. extern uint ai_findcoreidx(struct si_pub *sih, uint coreid, uint coreunit);
  211. extern void __iomem *ai_setcoreidx(struct si_pub *sih, uint coreidx);
  212. extern void __iomem *ai_setcore(struct si_pub *sih, uint coreid, uint coreunit);
  213. extern void __iomem *ai_switch_core(struct si_pub *sih, uint coreid,
  214. uint *origidx, uint *intr_val);
  215. extern void ai_restore_core(struct si_pub *sih, uint coreid, uint intr_val);
  216. extern void ai_core_reset(struct si_pub *sih, u32 bits, u32 resetbits);
  217. extern void ai_core_disable(struct si_pub *sih, u32 bits);
  218. extern u32 ai_alp_clock(struct si_pub *sih);
  219. extern u32 ai_ilp_clock(struct si_pub *sih);
  220. extern void ai_pci_setup(struct si_pub *sih, uint coremask);
  221. extern void ai_setint(struct si_pub *sih, int siflag);
  222. extern bool ai_backplane64(struct si_pub *sih);
  223. extern void ai_register_intr_callback(struct si_pub *sih, void *intrsoff_fn,
  224. void *intrsrestore_fn,
  225. void *intrsenabled_fn, void *intr_arg);
  226. extern void ai_deregister_intr_callback(struct si_pub *sih);
  227. extern void ai_clkctl_init(struct si_pub *sih);
  228. extern u16 ai_clkctl_fast_pwrup_delay(struct si_pub *sih);
  229. extern bool ai_clkctl_cc(struct si_pub *sih, uint mode);
  230. extern int ai_clkctl_xtal(struct si_pub *sih, uint what, bool on);
  231. extern bool ai_deviceremoved(struct si_pub *sih);
  232. extern u32 ai_gpiocontrol(struct si_pub *sih, u32 mask, u32 val,
  233. u8 priority);
  234. /* OTP status */
  235. extern bool ai_is_otp_disabled(struct si_pub *sih);
  236. /* SPROM availability */
  237. extern bool ai_is_sprom_available(struct si_pub *sih);
  238. /*
  239. * Build device path. Path size must be >= SI_DEVPATH_BUFSZ.
  240. * The returned path is NULL terminated and has trailing '/'.
  241. * Return 0 on success, nonzero otherwise.
  242. */
  243. extern int ai_devpath(struct si_pub *sih, char *path, int size);
  244. extern void ai_pci_sleep(struct si_pub *sih);
  245. extern void ai_pci_down(struct si_pub *sih);
  246. extern void ai_pci_up(struct si_pub *sih);
  247. extern int ai_pci_fixcfg(struct si_pub *sih);
  248. extern void ai_chipcontrl_epa4331(struct si_pub *sih, bool on);
  249. /* Enable Ex-PA for 4313 */
  250. extern void ai_epa_4313war(struct si_pub *sih);
  251. static inline uint ai_get_buscoretype(struct si_pub *sih)
  252. {
  253. return sih->buscoretype;
  254. }
  255. static inline uint ai_get_buscorerev(struct si_pub *sih)
  256. {
  257. return sih->buscorerev;
  258. }
  259. static inline int ai_get_ccrev(struct si_pub *sih)
  260. {
  261. return sih->ccrev;
  262. }
  263. static inline u32 ai_get_cccaps(struct si_pub *sih)
  264. {
  265. return sih->cccaps;
  266. }
  267. static inline int ai_get_pmurev(struct si_pub *sih)
  268. {
  269. return sih->pmurev;
  270. }
  271. static inline u32 ai_get_pmucaps(struct si_pub *sih)
  272. {
  273. return sih->pmucaps;
  274. }
  275. static inline uint ai_get_boardtype(struct si_pub *sih)
  276. {
  277. return sih->boardtype;
  278. }
  279. static inline uint ai_get_boardvendor(struct si_pub *sih)
  280. {
  281. return sih->boardvendor;
  282. }
  283. static inline uint ai_get_chip_id(struct si_pub *sih)
  284. {
  285. return sih->chip;
  286. }
  287. static inline uint ai_get_chiprev(struct si_pub *sih)
  288. {
  289. return sih->chiprev;
  290. }
  291. static inline uint ai_get_chippkg(struct si_pub *sih)
  292. {
  293. return sih->chippkg;
  294. }
  295. #endif /* _BRCM_AIUTILS_H_ */