intel.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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. * @mic_privacy: ACE version supports microphone privacy
  23. * @link_mask: global mask needed for power-up/down sequences
  24. * @cdns: Cadence master descriptor
  25. * @list: used to walk-through all masters exposed by the same controller
  26. * @hbus: hdac_bus pointer, needed for power management
  27. */
  28. struct sdw_intel_link_res {
  29. const struct sdw_intel_hw_ops *hw_ops;
  30. void __iomem *mmio_base; /* not strictly needed, useful for debug */
  31. void __iomem *registers;
  32. u32 ip_offset;
  33. void __iomem *shim;
  34. void __iomem *shim_vs;
  35. void __iomem *alh;
  36. int irq;
  37. const struct sdw_intel_ops *ops;
  38. struct device *dev;
  39. struct mutex *shim_lock; /* protect shared registers */
  40. u32 *shim_mask;
  41. u32 clock_stop_quirks;
  42. bool mic_privacy;
  43. u32 link_mask;
  44. struct sdw_cdns *cdns;
  45. struct list_head list;
  46. struct hdac_bus *hbus;
  47. };
  48. /**
  49. * struct sdw_intel_bpt - SoundWire Intel BPT context
  50. * @bpt_tx_stream: BPT TX stream
  51. * @dmab_tx_bdl: BPT TX buffer descriptor list
  52. * @bpt_rx_stream: BPT RX stream
  53. * @dmab_rx_bdl: BPT RX buffer descriptor list
  54. * @pdi0_buffer_size: PDI0 buffer size
  55. * @pdi1_buffer_size: PDI1 buffer size
  56. * @num_frames: number of frames
  57. * @data_per_frame: data per frame
  58. */
  59. struct sdw_intel_bpt {
  60. struct hdac_ext_stream *bpt_tx_stream;
  61. struct snd_dma_buffer dmab_tx_bdl;
  62. struct hdac_ext_stream *bpt_rx_stream;
  63. struct snd_dma_buffer dmab_rx_bdl;
  64. unsigned int pdi0_buffer_size;
  65. unsigned int pdi1_buffer_size;
  66. unsigned int num_frames;
  67. unsigned int data_per_frame;
  68. };
  69. struct sdw_intel {
  70. struct sdw_cdns cdns;
  71. int instance;
  72. struct sdw_intel_link_res *link_res;
  73. bool startup_done;
  74. struct sdw_intel_bpt bpt_ctx;
  75. #ifdef CONFIG_DEBUG_FS
  76. struct dentry *debugfs;
  77. #endif
  78. };
  79. struct sdw_intel_prop {
  80. u16 clde;
  81. u16 doaise2;
  82. u16 dodse2;
  83. u16 clds;
  84. u16 clss;
  85. u16 doaise;
  86. u16 doais;
  87. u16 dodse;
  88. u16 dods;
  89. };
  90. enum intel_pdi_type {
  91. INTEL_PDI_IN = 0,
  92. INTEL_PDI_OUT = 1,
  93. INTEL_PDI_BD = 2,
  94. };
  95. /*
  96. * Read, write helpers for HW registers
  97. */
  98. static inline int intel_readl(void __iomem *base, int offset)
  99. {
  100. return readl(base + offset);
  101. }
  102. static inline void intel_writel(void __iomem *base, int offset, int value)
  103. {
  104. writel(value, base + offset);
  105. }
  106. static inline u16 intel_readw(void __iomem *base, int offset)
  107. {
  108. return readw(base + offset);
  109. }
  110. static inline void intel_writew(void __iomem *base, int offset, u16 value)
  111. {
  112. writew(value, base + offset);
  113. }
  114. #define cdns_to_intel(_cdns) container_of(_cdns, struct sdw_intel, cdns)
  115. #define INTEL_MASTER_RESET_ITERATIONS 10
  116. #define SDW_INTEL_DELAYED_ENUMERATION_MS 100
  117. #define SDW_INTEL_CHECK_OPS(sdw, cb) ((sdw) && (sdw)->link_res && (sdw)->link_res->hw_ops && \
  118. (sdw)->link_res->hw_ops->cb)
  119. #define SDW_INTEL_OPS(sdw, cb) ((sdw)->link_res->hw_ops->cb)
  120. #ifdef CONFIG_DEBUG_FS
  121. void intel_ace2x_debugfs_init(struct sdw_intel *sdw);
  122. void intel_ace2x_debugfs_exit(struct sdw_intel *sdw);
  123. #else
  124. static inline void intel_ace2x_debugfs_init(struct sdw_intel *sdw) {}
  125. static inline void intel_ace2x_debugfs_exit(struct sdw_intel *sdw) {}
  126. #endif
  127. static inline void sdw_intel_debugfs_init(struct sdw_intel *sdw)
  128. {
  129. if (SDW_INTEL_CHECK_OPS(sdw, debugfs_init))
  130. SDW_INTEL_OPS(sdw, debugfs_init)(sdw);
  131. }
  132. static inline void sdw_intel_debugfs_exit(struct sdw_intel *sdw)
  133. {
  134. if (SDW_INTEL_CHECK_OPS(sdw, debugfs_exit))
  135. SDW_INTEL_OPS(sdw, debugfs_exit)(sdw);
  136. }
  137. static inline int sdw_intel_register_dai(struct sdw_intel *sdw)
  138. {
  139. if (SDW_INTEL_CHECK_OPS(sdw, register_dai))
  140. return SDW_INTEL_OPS(sdw, register_dai)(sdw);
  141. return -ENOTSUPP;
  142. }
  143. static inline void sdw_intel_check_clock_stop(struct sdw_intel *sdw)
  144. {
  145. if (SDW_INTEL_CHECK_OPS(sdw, check_clock_stop))
  146. SDW_INTEL_OPS(sdw, check_clock_stop)(sdw);
  147. }
  148. static inline int sdw_intel_start_bus(struct sdw_intel *sdw)
  149. {
  150. if (SDW_INTEL_CHECK_OPS(sdw, start_bus))
  151. return SDW_INTEL_OPS(sdw, start_bus)(sdw);
  152. return -ENOTSUPP;
  153. }
  154. static inline int sdw_intel_start_bus_after_reset(struct sdw_intel *sdw)
  155. {
  156. if (SDW_INTEL_CHECK_OPS(sdw, start_bus_after_reset))
  157. return SDW_INTEL_OPS(sdw, start_bus_after_reset)(sdw);
  158. return -ENOTSUPP;
  159. }
  160. static inline int sdw_intel_start_bus_after_clock_stop(struct sdw_intel *sdw)
  161. {
  162. if (SDW_INTEL_CHECK_OPS(sdw, start_bus_after_clock_stop))
  163. return SDW_INTEL_OPS(sdw, start_bus_after_clock_stop)(sdw);
  164. return -ENOTSUPP;
  165. }
  166. static inline int sdw_intel_stop_bus(struct sdw_intel *sdw, bool clock_stop)
  167. {
  168. if (SDW_INTEL_CHECK_OPS(sdw, stop_bus))
  169. return SDW_INTEL_OPS(sdw, stop_bus)(sdw, clock_stop);
  170. return -ENOTSUPP;
  171. }
  172. static inline int sdw_intel_link_power_up(struct sdw_intel *sdw)
  173. {
  174. if (SDW_INTEL_CHECK_OPS(sdw, link_power_up))
  175. return SDW_INTEL_OPS(sdw, link_power_up)(sdw);
  176. return -ENOTSUPP;
  177. }
  178. static inline int sdw_intel_link_power_down(struct sdw_intel *sdw)
  179. {
  180. if (SDW_INTEL_CHECK_OPS(sdw, link_power_down))
  181. return SDW_INTEL_OPS(sdw, link_power_down)(sdw);
  182. return -ENOTSUPP;
  183. }
  184. static inline int sdw_intel_shim_check_wake(struct sdw_intel *sdw)
  185. {
  186. if (SDW_INTEL_CHECK_OPS(sdw, shim_check_wake))
  187. return SDW_INTEL_OPS(sdw, shim_check_wake)(sdw);
  188. return -ENOTSUPP;
  189. }
  190. static inline void sdw_intel_shim_wake(struct sdw_intel *sdw, bool wake_enable)
  191. {
  192. if (SDW_INTEL_CHECK_OPS(sdw, shim_wake))
  193. SDW_INTEL_OPS(sdw, shim_wake)(sdw, wake_enable);
  194. }
  195. static inline void sdw_intel_sync_arm(struct sdw_intel *sdw)
  196. {
  197. if (SDW_INTEL_CHECK_OPS(sdw, sync_arm))
  198. SDW_INTEL_OPS(sdw, sync_arm)(sdw);
  199. }
  200. static inline int sdw_intel_sync_go_unlocked(struct sdw_intel *sdw)
  201. {
  202. if (SDW_INTEL_CHECK_OPS(sdw, sync_go_unlocked))
  203. return SDW_INTEL_OPS(sdw, sync_go_unlocked)(sdw);
  204. return -ENOTSUPP;
  205. }
  206. static inline int sdw_intel_sync_go(struct sdw_intel *sdw)
  207. {
  208. if (SDW_INTEL_CHECK_OPS(sdw, sync_go))
  209. return SDW_INTEL_OPS(sdw, sync_go)(sdw);
  210. return -ENOTSUPP;
  211. }
  212. static inline bool sdw_intel_sync_check_cmdsync_unlocked(struct sdw_intel *sdw)
  213. {
  214. if (SDW_INTEL_CHECK_OPS(sdw, sync_check_cmdsync_unlocked))
  215. return SDW_INTEL_OPS(sdw, sync_check_cmdsync_unlocked)(sdw);
  216. return false;
  217. }
  218. static inline int sdw_intel_get_link_count(struct sdw_intel *sdw)
  219. {
  220. if (SDW_INTEL_CHECK_OPS(sdw, get_link_count))
  221. return SDW_INTEL_OPS(sdw, get_link_count)(sdw);
  222. return 4; /* default on older generations */
  223. }
  224. /* common bus management */
  225. int intel_start_bus(struct sdw_intel *sdw);
  226. int intel_start_bus_after_reset(struct sdw_intel *sdw);
  227. void intel_check_clock_stop(struct sdw_intel *sdw);
  228. int intel_start_bus_after_clock_stop(struct sdw_intel *sdw);
  229. int intel_stop_bus(struct sdw_intel *sdw, bool clock_stop);
  230. /* common bank switch routines */
  231. int intel_pre_bank_switch(struct sdw_intel *sdw);
  232. int intel_post_bank_switch(struct sdw_intel *sdw);
  233. #endif /* __SDW_INTEL_LOCAL_H */