intel.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. /* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) */
  2. /* Copyright(c) 2015-17 Intel Corporation. */
  3. #ifndef __SDW_INTEL_LOCAL_H
  4. #define __SDW_INTEL_LOCAL_H
  5. struct hdac_bus;
  6. /**
  7. * struct sdw_intel_link_res - Soundwire Intel link resource structure,
  8. * typically populated by the controller driver.
  9. * @hw_ops: platform-specific ops
  10. * @mmio_base: mmio base of SoundWire registers
  11. * @registers: Link IO registers base
  12. * @ip_offset: offset for MCP_IP registers
  13. * @shim: Audio shim pointer
  14. * @shim_vs: Audio vendor-specific shim pointer
  15. * @alh: ALH (Audio Link Hub) pointer
  16. * @irq: Interrupt line
  17. * @ops: Shim callback ops
  18. * @dev: device implementing hw_params and free callbacks
  19. * @shim_lock: mutex to handle access to shared SHIM registers
  20. * @shim_mask: global pointer to check SHIM register initialization
  21. * @clock_stop_quirks: mask defining requested behavior on pm_suspend
  22. * @link_mask: global mask needed for power-up/down sequences
  23. * @cdns: Cadence master descriptor
  24. * @list: used to walk-through all masters exposed by the same controller
  25. * @hbus: hdac_bus pointer, needed for power management
  26. */
  27. struct sdw_intel_link_res {
  28. const struct sdw_intel_hw_ops *hw_ops;
  29. void __iomem *mmio_base; /* not strictly needed, useful for debug */
  30. void __iomem *registers;
  31. u32 ip_offset;
  32. void __iomem *shim;
  33. void __iomem *shim_vs;
  34. void __iomem *alh;
  35. int irq;
  36. const struct sdw_intel_ops *ops;
  37. struct device *dev;
  38. struct mutex *shim_lock; /* protect shared registers */
  39. u32 *shim_mask;
  40. u32 clock_stop_quirks;
  41. u32 link_mask;
  42. struct sdw_cdns *cdns;
  43. struct list_head list;
  44. struct hdac_bus *hbus;
  45. };
  46. struct sdw_intel {
  47. struct sdw_cdns cdns;
  48. int instance;
  49. struct sdw_intel_link_res *link_res;
  50. bool startup_done;
  51. #ifdef CONFIG_DEBUG_FS
  52. struct dentry *debugfs;
  53. #endif
  54. };
  55. struct sdw_intel_prop {
  56. u16 clde;
  57. u16 doaise2;
  58. u16 dodse2;
  59. u16 clds;
  60. u16 clss;
  61. u16 doaise;
  62. u16 doais;
  63. u16 dodse;
  64. u16 dods;
  65. };
  66. enum intel_pdi_type {
  67. INTEL_PDI_IN = 0,
  68. INTEL_PDI_OUT = 1,
  69. INTEL_PDI_BD = 2,
  70. };
  71. /*
  72. * Read, write helpers for HW registers
  73. */
  74. static inline int intel_readl(void __iomem *base, int offset)
  75. {
  76. return readl(base + offset);
  77. }
  78. static inline void intel_writel(void __iomem *base, int offset, int value)
  79. {
  80. writel(value, base + offset);
  81. }
  82. static inline u16 intel_readw(void __iomem *base, int offset)
  83. {
  84. return readw(base + offset);
  85. }
  86. static inline void intel_writew(void __iomem *base, int offset, u16 value)
  87. {
  88. writew(value, base + offset);
  89. }
  90. #define cdns_to_intel(_cdns) container_of(_cdns, struct sdw_intel, cdns)
  91. #define INTEL_MASTER_RESET_ITERATIONS 10
  92. #define SDW_INTEL_DELAYED_ENUMERATION_MS 100
  93. #define SDW_INTEL_CHECK_OPS(sdw, cb) ((sdw) && (sdw)->link_res && (sdw)->link_res->hw_ops && \
  94. (sdw)->link_res->hw_ops->cb)
  95. #define SDW_INTEL_OPS(sdw, cb) ((sdw)->link_res->hw_ops->cb)
  96. #ifdef CONFIG_DEBUG_FS
  97. void intel_ace2x_debugfs_init(struct sdw_intel *sdw);
  98. void intel_ace2x_debugfs_exit(struct sdw_intel *sdw);
  99. #else
  100. static inline void intel_ace2x_debugfs_init(struct sdw_intel *sdw) {}
  101. static inline void intel_ace2x_debugfs_exit(struct sdw_intel *sdw) {}
  102. #endif
  103. static inline void sdw_intel_debugfs_init(struct sdw_intel *sdw)
  104. {
  105. if (SDW_INTEL_CHECK_OPS(sdw, debugfs_init))
  106. SDW_INTEL_OPS(sdw, debugfs_init)(sdw);
  107. }
  108. static inline void sdw_intel_debugfs_exit(struct sdw_intel *sdw)
  109. {
  110. if (SDW_INTEL_CHECK_OPS(sdw, debugfs_exit))
  111. SDW_INTEL_OPS(sdw, debugfs_exit)(sdw);
  112. }
  113. static inline int sdw_intel_register_dai(struct sdw_intel *sdw)
  114. {
  115. if (SDW_INTEL_CHECK_OPS(sdw, register_dai))
  116. return SDW_INTEL_OPS(sdw, register_dai)(sdw);
  117. return -ENOTSUPP;
  118. }
  119. static inline void sdw_intel_check_clock_stop(struct sdw_intel *sdw)
  120. {
  121. if (SDW_INTEL_CHECK_OPS(sdw, check_clock_stop))
  122. SDW_INTEL_OPS(sdw, check_clock_stop)(sdw);
  123. }
  124. static inline int sdw_intel_start_bus(struct sdw_intel *sdw)
  125. {
  126. if (SDW_INTEL_CHECK_OPS(sdw, start_bus))
  127. return SDW_INTEL_OPS(sdw, start_bus)(sdw);
  128. return -ENOTSUPP;
  129. }
  130. static inline int sdw_intel_start_bus_after_reset(struct sdw_intel *sdw)
  131. {
  132. if (SDW_INTEL_CHECK_OPS(sdw, start_bus_after_reset))
  133. return SDW_INTEL_OPS(sdw, start_bus_after_reset)(sdw);
  134. return -ENOTSUPP;
  135. }
  136. static inline int sdw_intel_start_bus_after_clock_stop(struct sdw_intel *sdw)
  137. {
  138. if (SDW_INTEL_CHECK_OPS(sdw, start_bus_after_clock_stop))
  139. return SDW_INTEL_OPS(sdw, start_bus_after_clock_stop)(sdw);
  140. return -ENOTSUPP;
  141. }
  142. static inline int sdw_intel_stop_bus(struct sdw_intel *sdw, bool clock_stop)
  143. {
  144. if (SDW_INTEL_CHECK_OPS(sdw, stop_bus))
  145. return SDW_INTEL_OPS(sdw, stop_bus)(sdw, clock_stop);
  146. return -ENOTSUPP;
  147. }
  148. static inline int sdw_intel_link_power_up(struct sdw_intel *sdw)
  149. {
  150. if (SDW_INTEL_CHECK_OPS(sdw, link_power_up))
  151. return SDW_INTEL_OPS(sdw, link_power_up)(sdw);
  152. return -ENOTSUPP;
  153. }
  154. static inline int sdw_intel_link_power_down(struct sdw_intel *sdw)
  155. {
  156. if (SDW_INTEL_CHECK_OPS(sdw, link_power_down))
  157. return SDW_INTEL_OPS(sdw, link_power_down)(sdw);
  158. return -ENOTSUPP;
  159. }
  160. static inline int sdw_intel_shim_check_wake(struct sdw_intel *sdw)
  161. {
  162. if (SDW_INTEL_CHECK_OPS(sdw, shim_check_wake))
  163. return SDW_INTEL_OPS(sdw, shim_check_wake)(sdw);
  164. return -ENOTSUPP;
  165. }
  166. static inline void sdw_intel_shim_wake(struct sdw_intel *sdw, bool wake_enable)
  167. {
  168. if (SDW_INTEL_CHECK_OPS(sdw, shim_wake))
  169. SDW_INTEL_OPS(sdw, shim_wake)(sdw, wake_enable);
  170. }
  171. static inline void sdw_intel_sync_arm(struct sdw_intel *sdw)
  172. {
  173. if (SDW_INTEL_CHECK_OPS(sdw, sync_arm))
  174. SDW_INTEL_OPS(sdw, sync_arm)(sdw);
  175. }
  176. static inline int sdw_intel_sync_go_unlocked(struct sdw_intel *sdw)
  177. {
  178. if (SDW_INTEL_CHECK_OPS(sdw, sync_go_unlocked))
  179. return SDW_INTEL_OPS(sdw, sync_go_unlocked)(sdw);
  180. return -ENOTSUPP;
  181. }
  182. static inline int sdw_intel_sync_go(struct sdw_intel *sdw)
  183. {
  184. if (SDW_INTEL_CHECK_OPS(sdw, sync_go))
  185. return SDW_INTEL_OPS(sdw, sync_go)(sdw);
  186. return -ENOTSUPP;
  187. }
  188. static inline bool sdw_intel_sync_check_cmdsync_unlocked(struct sdw_intel *sdw)
  189. {
  190. if (SDW_INTEL_CHECK_OPS(sdw, sync_check_cmdsync_unlocked))
  191. return SDW_INTEL_OPS(sdw, sync_check_cmdsync_unlocked)(sdw);
  192. return false;
  193. }
  194. static inline int sdw_intel_get_link_count(struct sdw_intel *sdw)
  195. {
  196. if (SDW_INTEL_CHECK_OPS(sdw, get_link_count))
  197. return SDW_INTEL_OPS(sdw, get_link_count)(sdw);
  198. return 4; /* default on older generations */
  199. }
  200. /* common bus management */
  201. int intel_start_bus(struct sdw_intel *sdw);
  202. int intel_start_bus_after_reset(struct sdw_intel *sdw);
  203. void intel_check_clock_stop(struct sdw_intel *sdw);
  204. int intel_start_bus_after_clock_stop(struct sdw_intel *sdw);
  205. int intel_stop_bus(struct sdw_intel *sdw, bool clock_stop);
  206. /* common bank switch routines */
  207. int intel_pre_bank_switch(struct sdw_intel *sdw);
  208. int intel_post_bank_switch(struct sdw_intel *sdw);
  209. #endif /* __SDW_INTEL_LOCAL_H */