aiutils.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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. /* dynamic clock control defines */
  75. #define LPOMINFREQ 25000 /* low power oscillator min */
  76. #define LPOMAXFREQ 43000 /* low power oscillator max */
  77. #define XTALMINFREQ 19800000 /* 20 MHz - 1% */
  78. #define XTALMAXFREQ 20200000 /* 20 MHz + 1% */
  79. #define PCIMINFREQ 25000000 /* 25 MHz */
  80. #define PCIMAXFREQ 34000000 /* 33 MHz + fudge */
  81. #define ILP_DIV_5MHZ 0 /* ILP = 5 MHz */
  82. #define ILP_DIV_1MHZ 4 /* ILP = 1 MHz */
  83. /* clkctl xtal what flags */
  84. #define XTAL 0x1 /* primary crystal oscillator (2050) */
  85. #define PLL 0x2 /* main chip pll */
  86. /* GPIO usage priorities */
  87. #define GPIO_DRV_PRIORITY 0 /* Driver */
  88. #define GPIO_APP_PRIORITY 1 /* Application */
  89. #define GPIO_HI_PRIORITY 2 /* Highest priority. Ignore GPIO
  90. * reservation
  91. */
  92. /* GPIO pull up/down */
  93. #define GPIO_PULLUP 0
  94. #define GPIO_PULLDN 1
  95. /* GPIO event regtype */
  96. #define GPIO_REGEVT 0 /* GPIO register event */
  97. #define GPIO_REGEVT_INTMSK 1 /* GPIO register event int mask */
  98. #define GPIO_REGEVT_INTPOL 2 /* GPIO register event int polarity */
  99. /* device path */
  100. #define SI_DEVPATH_BUFSZ 16 /* min buffer size in bytes */
  101. /* SI routine enumeration: to be used by update function with multiple hooks */
  102. #define SI_DOATTACH 1
  103. #define SI_PCIDOWN 2
  104. #define SI_PCIUP 3
  105. /*
  106. * Data structure to export all chip specific common variables
  107. * public (read-only) portion of aiutils handle returned by si_attach()
  108. */
  109. struct si_pub {
  110. int ccrev; /* chip common core rev */
  111. u32 cccaps; /* chip common capabilities */
  112. int pmurev; /* pmu core rev */
  113. u32 pmucaps; /* pmu capabilities */
  114. uint boardtype; /* board type */
  115. uint boardvendor; /* board vendor */
  116. uint chip; /* chip number */
  117. uint chiprev; /* chip revision */
  118. uint chippkg; /* chip package option */
  119. };
  120. struct pci_dev;
  121. struct gpioh_item {
  122. void *arg;
  123. bool level;
  124. void (*handler) (u32 stat, void *arg);
  125. u32 event;
  126. struct gpioh_item *next;
  127. };
  128. /* misc si info needed by some of the routines */
  129. struct si_info {
  130. struct si_pub pub; /* back plane public state (must be first) */
  131. struct bcma_bus *icbus; /* handle to soc interconnect bus */
  132. struct pci_dev *pcibus; /* handle to pci bus */
  133. u32 chipst; /* chip status */
  134. };
  135. /*
  136. * Many of the routines below take an 'sih' handle as their first arg.
  137. * Allocate this by calling si_attach(). Free it by calling si_detach().
  138. * At any one time, the sih is logically focused on one particular si core
  139. * (the "current core").
  140. * Use si_setcore() or si_setcoreidx() to change the association to another core
  141. */
  142. /* AMBA Interconnect exported externs */
  143. u32 ai_core_cflags(struct bcma_device *core, u32 mask, u32 val);
  144. /* === exported functions === */
  145. struct si_pub *ai_attach(struct bcma_bus *pbus);
  146. void ai_detach(struct si_pub *sih);
  147. uint ai_cc_reg(struct si_pub *sih, uint regoff, u32 mask, u32 val);
  148. void ai_clkctl_init(struct si_pub *sih);
  149. u16 ai_clkctl_fast_pwrup_delay(struct si_pub *sih);
  150. bool ai_clkctl_cc(struct si_pub *sih, enum bcma_clkmode mode);
  151. bool ai_deviceremoved(struct si_pub *sih);
  152. /* Enable Ex-PA for 4313 */
  153. void ai_epa_4313war(struct si_pub *sih);
  154. static inline u32 ai_get_cccaps(struct si_pub *sih)
  155. {
  156. return sih->cccaps;
  157. }
  158. static inline int ai_get_pmurev(struct si_pub *sih)
  159. {
  160. return sih->pmurev;
  161. }
  162. static inline u32 ai_get_pmucaps(struct si_pub *sih)
  163. {
  164. return sih->pmucaps;
  165. }
  166. static inline uint ai_get_boardtype(struct si_pub *sih)
  167. {
  168. return sih->boardtype;
  169. }
  170. static inline uint ai_get_boardvendor(struct si_pub *sih)
  171. {
  172. return sih->boardvendor;
  173. }
  174. static inline uint ai_get_chip_id(struct si_pub *sih)
  175. {
  176. return sih->chip;
  177. }
  178. static inline uint ai_get_chiprev(struct si_pub *sih)
  179. {
  180. return sih->chiprev;
  181. }
  182. static inline uint ai_get_chippkg(struct si_pub *sih)
  183. {
  184. return sih->chippkg;
  185. }
  186. #endif /* _BRCM_AIUTILS_H_ */