aiutils.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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. int ccrev; /* chip common core rev */
  122. u32 cccaps; /* chip common capabilities */
  123. int pmurev; /* pmu core rev */
  124. u32 pmucaps; /* pmu capabilities */
  125. uint boardtype; /* board type */
  126. uint boardvendor; /* board vendor */
  127. uint chip; /* chip number */
  128. uint chiprev; /* chip revision */
  129. uint chippkg; /* chip package option */
  130. };
  131. struct pci_dev;
  132. struct gpioh_item {
  133. void *arg;
  134. bool level;
  135. void (*handler) (u32 stat, void *arg);
  136. u32 event;
  137. struct gpioh_item *next;
  138. };
  139. /* misc si info needed by some of the routines */
  140. struct si_info {
  141. struct si_pub pub; /* back plane public state (must be first) */
  142. struct bcma_bus *icbus; /* handle to soc interconnect bus */
  143. struct pci_dev *pcibus; /* handle to pci bus */
  144. struct pcicore_info *pch; /* PCI/E core handle */
  145. struct bcma_device *buscore;
  146. struct list_head var_list; /* list of srom variables */
  147. u32 chipst; /* chip status */
  148. };
  149. /*
  150. * Many of the routines below take an 'sih' handle as their first arg.
  151. * Allocate this by calling si_attach(). Free it by calling si_detach().
  152. * At any one time, the sih is logically focused on one particular si core
  153. * (the "current core").
  154. * Use si_setcore() or si_setcoreidx() to change the association to another core
  155. */
  156. /* AMBA Interconnect exported externs */
  157. extern struct bcma_device *ai_findcore(struct si_pub *sih,
  158. u16 coreid, u16 coreunit);
  159. extern u32 ai_core_cflags(struct bcma_device *core, u32 mask, u32 val);
  160. /* === exported functions === */
  161. extern struct si_pub *ai_attach(struct bcma_bus *pbus);
  162. extern void ai_detach(struct si_pub *sih);
  163. extern uint ai_cc_reg(struct si_pub *sih, uint regoff, u32 mask, u32 val);
  164. extern void ai_pci_setup(struct si_pub *sih, uint coremask);
  165. extern void ai_clkctl_init(struct si_pub *sih);
  166. extern u16 ai_clkctl_fast_pwrup_delay(struct si_pub *sih);
  167. extern bool ai_clkctl_cc(struct si_pub *sih, uint mode);
  168. extern int ai_clkctl_xtal(struct si_pub *sih, uint what, bool on);
  169. extern bool ai_deviceremoved(struct si_pub *sih);
  170. extern u32 ai_gpiocontrol(struct si_pub *sih, u32 mask, u32 val,
  171. u8 priority);
  172. /* OTP status */
  173. extern bool ai_is_otp_disabled(struct si_pub *sih);
  174. /* SPROM availability */
  175. extern bool ai_is_sprom_available(struct si_pub *sih);
  176. extern void ai_pci_sleep(struct si_pub *sih);
  177. extern void ai_pci_down(struct si_pub *sih);
  178. extern void ai_pci_up(struct si_pub *sih);
  179. extern int ai_pci_fixcfg(struct si_pub *sih);
  180. extern void ai_chipcontrl_epa4331(struct si_pub *sih, bool on);
  181. /* Enable Ex-PA for 4313 */
  182. extern void ai_epa_4313war(struct si_pub *sih);
  183. extern uint ai_get_buscoretype(struct si_pub *sih);
  184. extern uint ai_get_buscorerev(struct si_pub *sih);
  185. static inline int ai_get_ccrev(struct si_pub *sih)
  186. {
  187. return sih->ccrev;
  188. }
  189. static inline u32 ai_get_cccaps(struct si_pub *sih)
  190. {
  191. return sih->cccaps;
  192. }
  193. static inline int ai_get_pmurev(struct si_pub *sih)
  194. {
  195. return sih->pmurev;
  196. }
  197. static inline u32 ai_get_pmucaps(struct si_pub *sih)
  198. {
  199. return sih->pmucaps;
  200. }
  201. static inline uint ai_get_boardtype(struct si_pub *sih)
  202. {
  203. return sih->boardtype;
  204. }
  205. static inline uint ai_get_boardvendor(struct si_pub *sih)
  206. {
  207. return sih->boardvendor;
  208. }
  209. static inline uint ai_get_chip_id(struct si_pub *sih)
  210. {
  211. return sih->chip;
  212. }
  213. static inline uint ai_get_chiprev(struct si_pub *sih)
  214. {
  215. return sih->chiprev;
  216. }
  217. static inline uint ai_get_chippkg(struct si_pub *sih)
  218. {
  219. return sih->chippkg;
  220. }
  221. #endif /* _BRCM_AIUTILS_H_ */