sdw_intel.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. /* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) */
  2. /* Copyright(c) 2015-17 Intel Corporation. */
  3. #ifndef __SDW_INTEL_H
  4. #define __SDW_INTEL_H
  5. #include <linux/irqreturn.h>
  6. #include <linux/soundwire/sdw.h>
  7. #define SDW_SHIM_BASE 0x2C000
  8. #define SDW_ALH_BASE 0x2C800
  9. #define SDW_SHIM_BASE_ACE 0x38000
  10. #define SDW_ALH_BASE_ACE 0x24000
  11. #define SDW_LINK_BASE 0x30000
  12. #define SDW_LINK_SIZE 0x10000
  13. /* Intel SHIM Registers Definition */
  14. /* LCAP */
  15. #define SDW_SHIM_LCAP 0x0
  16. #define SDW_SHIM_LCAP_LCOUNT_MASK GENMASK(2, 0)
  17. /* LCTL */
  18. #define SDW_SHIM_LCTL 0x4
  19. #define SDW_SHIM_LCTL_SPA BIT(0)
  20. #define SDW_SHIM_LCTL_SPA_MASK GENMASK(3, 0)
  21. #define SDW_SHIM_LCTL_CPA BIT(8)
  22. #define SDW_SHIM_LCTL_CPA_MASK GENMASK(11, 8)
  23. /* SYNC */
  24. #define SDW_SHIM_SYNC 0xC
  25. #define SDW_SHIM_SYNC_SYNCPRD_VAL_24 (24000 / SDW_CADENCE_GSYNC_KHZ - 1)
  26. #define SDW_SHIM_SYNC_SYNCPRD_VAL_38_4 (38400 / SDW_CADENCE_GSYNC_KHZ - 1)
  27. #define SDW_SHIM_SYNC_SYNCPRD GENMASK(14, 0)
  28. #define SDW_SHIM_SYNC_SYNCCPU BIT(15)
  29. #define SDW_SHIM_SYNC_CMDSYNC_MASK GENMASK(19, 16)
  30. #define SDW_SHIM_SYNC_CMDSYNC BIT(16)
  31. #define SDW_SHIM_SYNC_SYNCGO BIT(24)
  32. /* Control stream capabililities and channel mask */
  33. #define SDW_SHIM_CTLSCAP(x) (0x010 + 0x60 * (x))
  34. #define SDW_SHIM_CTLS0CM(x) (0x012 + 0x60 * (x))
  35. #define SDW_SHIM_CTLS1CM(x) (0x014 + 0x60 * (x))
  36. #define SDW_SHIM_CTLS2CM(x) (0x016 + 0x60 * (x))
  37. #define SDW_SHIM_CTLS3CM(x) (0x018 + 0x60 * (x))
  38. /* PCM Stream capabilities */
  39. #define SDW_SHIM_PCMSCAP(x) (0x020 + 0x60 * (x))
  40. #define SDW_SHIM_PCMSCAP_ISS GENMASK(3, 0)
  41. #define SDW_SHIM_PCMSCAP_OSS GENMASK(7, 4)
  42. #define SDW_SHIM_PCMSCAP_BSS GENMASK(12, 8)
  43. /* PCM Stream Channel Map */
  44. #define SDW_SHIM_PCMSYCHM(x, y) (0x022 + (0x60 * (x)) + (0x2 * (y)))
  45. /* PCM Stream Channel Count */
  46. #define SDW_SHIM_PCMSYCHC(x, y) (0x042 + (0x60 * (x)) + (0x2 * (y)))
  47. #define SDW_SHIM_PCMSYCM_LCHN GENMASK(3, 0)
  48. #define SDW_SHIM_PCMSYCM_HCHN GENMASK(7, 4)
  49. #define SDW_SHIM_PCMSYCM_STREAM GENMASK(13, 8)
  50. #define SDW_SHIM_PCMSYCM_DIR BIT(15)
  51. /* IO control */
  52. #define SDW_SHIM_IOCTL(x) (0x06C + 0x60 * (x))
  53. #define SDW_SHIM_IOCTL_MIF BIT(0)
  54. #define SDW_SHIM_IOCTL_CO BIT(1)
  55. #define SDW_SHIM_IOCTL_COE BIT(2)
  56. #define SDW_SHIM_IOCTL_DO BIT(3)
  57. #define SDW_SHIM_IOCTL_DOE BIT(4)
  58. #define SDW_SHIM_IOCTL_BKE BIT(5)
  59. #define SDW_SHIM_IOCTL_WPDD BIT(6)
  60. #define SDW_SHIM_IOCTL_CIBD BIT(8)
  61. #define SDW_SHIM_IOCTL_DIBD BIT(9)
  62. /* Wake Enable*/
  63. #define SDW_SHIM_WAKEEN 0x190
  64. #define SDW_SHIM_WAKEEN_ENABLE BIT(0)
  65. /* Wake Status */
  66. #define SDW_SHIM_WAKESTS 0x192
  67. #define SDW_SHIM_WAKESTS_STATUS BIT(0)
  68. /* AC Timing control */
  69. #define SDW_SHIM_CTMCTL(x) (0x06E + 0x60 * (x))
  70. #define SDW_SHIM_CTMCTL_DACTQE BIT(0)
  71. #define SDW_SHIM_CTMCTL_DODS BIT(1)
  72. #define SDW_SHIM_CTMCTL_DOAIS GENMASK(4, 3)
  73. /* Intel ALH Register definitions */
  74. #define SDW_ALH_STRMZCFG(x) (0x000 + (0x4 * (x)))
  75. #define SDW_ALH_NUM_STREAMS 64
  76. #define SDW_ALH_STRMZCFG_DMAT_VAL 0x3
  77. #define SDW_ALH_STRMZCFG_DMAT GENMASK(7, 0)
  78. #define SDW_ALH_STRMZCFG_CHN GENMASK(19, 16)
  79. /**
  80. * struct sdw_intel_stream_params_data: configuration passed during
  81. * the @params_stream callback, e.g. for interaction with DSP
  82. * firmware.
  83. */
  84. struct sdw_intel_stream_params_data {
  85. int stream;
  86. struct snd_soc_dai *dai;
  87. struct snd_pcm_hw_params *hw_params;
  88. int link_id;
  89. int alh_stream_id;
  90. };
  91. /**
  92. * struct sdw_intel_stream_free_data: configuration passed during
  93. * the @free_stream callback, e.g. for interaction with DSP
  94. * firmware.
  95. */
  96. struct sdw_intel_stream_free_data {
  97. int stream;
  98. struct snd_soc_dai *dai;
  99. int link_id;
  100. };
  101. /**
  102. * struct sdw_intel_ops: Intel audio driver callback ops
  103. *
  104. */
  105. struct sdw_intel_ops {
  106. int (*params_stream)(struct device *dev,
  107. struct sdw_intel_stream_params_data *params_data);
  108. int (*free_stream)(struct device *dev,
  109. struct sdw_intel_stream_free_data *free_data);
  110. int (*trigger)(struct snd_soc_dai *dai, int cmd, int stream);
  111. };
  112. /**
  113. * struct sdw_intel_acpi_info - Soundwire Intel information found in ACPI tables
  114. * @handle: ACPI controller handle
  115. * @count: link count found with "sdw-master-count" property
  116. * @link_mask: bit-wise mask listing links enabled by BIOS menu
  117. *
  118. * this structure could be expanded to e.g. provide all the _ADR
  119. * information in case the link_mask is not sufficient to identify
  120. * platform capabilities.
  121. */
  122. struct sdw_intel_acpi_info {
  123. acpi_handle handle;
  124. int count;
  125. u32 link_mask;
  126. };
  127. struct sdw_intel_link_dev;
  128. /* Intel clock-stop/pm_runtime quirk definitions */
  129. /*
  130. * Force the clock to remain on during pm_runtime suspend. This might
  131. * be needed if Slave devices do not have an alternate clock source or
  132. * if the latency requirements are very strict.
  133. */
  134. #define SDW_INTEL_CLK_STOP_NOT_ALLOWED BIT(0)
  135. /*
  136. * Stop the bus during pm_runtime suspend. If set, a complete bus
  137. * reset and re-enumeration will be performed when the bus
  138. * restarts. This mode shall not be used if Slave devices can generate
  139. * in-band wakes.
  140. */
  141. #define SDW_INTEL_CLK_STOP_TEARDOWN BIT(1)
  142. /*
  143. * Stop the bus during pm_suspend if Slaves are not wake capable
  144. * (e.g. speaker amplifiers). The clock-stop mode is typically
  145. * slightly higher power than when the IP is completely powered-off.
  146. */
  147. #define SDW_INTEL_CLK_STOP_WAKE_CAPABLE_ONLY BIT(2)
  148. /*
  149. * Require a bus reset (and complete re-enumeration) when exiting
  150. * clock stop modes. This may be needed if the controller power was
  151. * turned off and all context lost. This quirk shall not be used if a
  152. * Slave device needs to remain enumerated and keep its context,
  153. * e.g. to provide the reasons for the wake, report acoustic events or
  154. * pass a history buffer.
  155. */
  156. #define SDW_INTEL_CLK_STOP_BUS_RESET BIT(3)
  157. struct sdw_intel_slave_id {
  158. int link_id;
  159. struct sdw_slave_id id;
  160. };
  161. /**
  162. * struct sdw_intel_ctx - context allocated by the controller
  163. * driver probe
  164. * @count: link count
  165. * @mmio_base: mmio base of SoundWire registers, only used to check
  166. * hardware capabilities after all power dependencies are settled.
  167. * @link_mask: bit-wise mask listing SoundWire links reported by the
  168. * Controller
  169. * @num_slaves: total number of devices exposed across all enabled links
  170. * @handle: ACPI parent handle
  171. * @ldev: information for each link (controller-specific and kept
  172. * opaque here)
  173. * @ids: array of slave_id, representing Slaves exposed across all enabled
  174. * links
  175. * @link_list: list to handle interrupts across all links
  176. * @shim_lock: mutex to handle concurrent rmw access to shared SHIM registers.
  177. * @shim_mask: flags to track initialization of SHIM shared registers
  178. * @shim_base: sdw shim base.
  179. * @alh_base: sdw alh base.
  180. */
  181. struct sdw_intel_ctx {
  182. int count;
  183. void __iomem *mmio_base;
  184. u32 link_mask;
  185. int num_slaves;
  186. acpi_handle handle;
  187. struct sdw_intel_link_dev **ldev;
  188. struct sdw_intel_slave_id *ids;
  189. struct list_head link_list;
  190. struct mutex shim_lock; /* lock for access to shared SHIM registers */
  191. u32 shim_mask;
  192. u32 shim_base;
  193. u32 alh_base;
  194. };
  195. /**
  196. * struct sdw_intel_res - Soundwire Intel global resource structure,
  197. * typically populated by the DSP driver
  198. *
  199. * @count: link count
  200. * @mmio_base: mmio base of SoundWire registers
  201. * @irq: interrupt number
  202. * @handle: ACPI parent handle
  203. * @parent: parent device
  204. * @ops: callback ops
  205. * @dev: device implementing hwparams and free callbacks
  206. * @link_mask: bit-wise mask listing links selected by the DSP driver
  207. * This mask may be a subset of the one reported by the controller since
  208. * machine-specific quirks are handled in the DSP driver.
  209. * @clock_stop_quirks: mask array of possible behaviors requested by the
  210. * DSP driver. The quirks are common for all links for now.
  211. * @shim_base: sdw shim base.
  212. * @alh_base: sdw alh base.
  213. */
  214. struct sdw_intel_res {
  215. int count;
  216. void __iomem *mmio_base;
  217. int irq;
  218. acpi_handle handle;
  219. struct device *parent;
  220. const struct sdw_intel_ops *ops;
  221. struct device *dev;
  222. u32 link_mask;
  223. u32 clock_stop_quirks;
  224. u32 shim_base;
  225. u32 alh_base;
  226. };
  227. /*
  228. * On Intel platforms, the SoundWire IP has dependencies on power
  229. * rails shared with the DSP, and the initialization steps are split
  230. * in three. First an ACPI scan to check what the firmware describes
  231. * in DSDT tables, then an allocation step (with no hardware
  232. * configuration but with all the relevant devices created) and last
  233. * the actual hardware configuration. The final stage is a global
  234. * interrupt enable which is controlled by the DSP driver. Splitting
  235. * these phases helps simplify the boot flow and make early decisions
  236. * on e.g. which machine driver to select (I2S mode, HDaudio or
  237. * SoundWire).
  238. */
  239. int sdw_intel_acpi_scan(acpi_handle *parent_handle,
  240. struct sdw_intel_acpi_info *info);
  241. void sdw_intel_process_wakeen_event(struct sdw_intel_ctx *ctx);
  242. struct sdw_intel_ctx *
  243. sdw_intel_probe(struct sdw_intel_res *res);
  244. int sdw_intel_startup(struct sdw_intel_ctx *ctx);
  245. void sdw_intel_exit(struct sdw_intel_ctx *ctx);
  246. void sdw_intel_enable_irq(void __iomem *mmio_base, bool enable);
  247. irqreturn_t sdw_intel_thread(int irq, void *dev_id);
  248. #define SDW_INTEL_QUIRK_MASK_BUS_DISABLE BIT(1)
  249. #endif