lpass.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2010-2011,2013-2015,2020 The Linux Foundation. All rights reserved.
  4. *
  5. * lpass.h - Definitions for the QTi LPASS
  6. */
  7. #ifndef __LPASS_H__
  8. #define __LPASS_H__
  9. #include <linux/clk.h>
  10. #include <linux/compiler.h>
  11. #include <linux/platform_device.h>
  12. #include <linux/regmap.h>
  13. #include <dt-bindings/sound/qcom,lpass.h>
  14. #include <dt-bindings/sound/qcom,q6afe.h>
  15. #include "lpass-hdmi.h"
  16. #define LPASS_AHBIX_CLOCK_FREQUENCY 131072000
  17. #define LPASS_MAX_PORTS (DISPLAY_PORT_RX_7 + 1)
  18. #define LPASS_MAX_MI2S_PORTS (8)
  19. #define LPASS_MAX_DMA_CHANNELS (8)
  20. #define LPASS_MAX_HDMI_DMA_CHANNELS (4)
  21. #define LPASS_MAX_CDC_DMA_CHANNELS (8)
  22. #define LPASS_MAX_VA_CDC_DMA_CHANNELS (8)
  23. #define LPASS_CDC_DMA_INTF_ONE_CHANNEL (0x01)
  24. #define LPASS_CDC_DMA_INTF_TWO_CHANNEL (0x03)
  25. #define LPASS_CDC_DMA_INTF_FOUR_CHANNEL (0x0F)
  26. #define LPASS_CDC_DMA_INTF_SIX_CHANNEL (0x3F)
  27. #define LPASS_CDC_DMA_INTF_EIGHT_CHANNEL (0xFF)
  28. #define LPASS_ACTIVE_PDS (4)
  29. #define LPASS_PROXY_PDS (8)
  30. #define QCOM_REGMAP_FIELD_ALLOC(d, m, f, mf) \
  31. do { \
  32. mf = devm_regmap_field_alloc(d, m, f); \
  33. if (IS_ERR(mf)) \
  34. return -EINVAL; \
  35. } while (0)
  36. static inline bool is_cdc_dma_port(int dai_id)
  37. {
  38. switch (dai_id) {
  39. case LPASS_CDC_DMA_RX0 ... LPASS_CDC_DMA_RX9:
  40. case LPASS_CDC_DMA_TX0 ... LPASS_CDC_DMA_TX8:
  41. case LPASS_CDC_DMA_VA_TX0 ... LPASS_CDC_DMA_VA_TX8:
  42. return true;
  43. }
  44. return false;
  45. }
  46. static inline bool is_rxtx_cdc_dma_port(int dai_id)
  47. {
  48. switch (dai_id) {
  49. case LPASS_CDC_DMA_RX0 ... LPASS_CDC_DMA_RX9:
  50. case LPASS_CDC_DMA_TX0 ... LPASS_CDC_DMA_TX8:
  51. return true;
  52. }
  53. return false;
  54. }
  55. struct lpaif_i2sctl {
  56. struct regmap_field *loopback;
  57. struct regmap_field *spken;
  58. struct regmap_field *spkmode;
  59. struct regmap_field *spkmono;
  60. struct regmap_field *micen;
  61. struct regmap_field *micmode;
  62. struct regmap_field *micmono;
  63. struct regmap_field *wssrc;
  64. struct regmap_field *bitwidth;
  65. };
  66. struct lpaif_dmactl {
  67. struct regmap_field *intf;
  68. struct regmap_field *bursten;
  69. struct regmap_field *wpscnt;
  70. struct regmap_field *fifowm;
  71. struct regmap_field *enable;
  72. struct regmap_field *dyncclk;
  73. struct regmap_field *burst8;
  74. struct regmap_field *burst16;
  75. struct regmap_field *dynburst;
  76. struct regmap_field *codec_enable;
  77. struct regmap_field *codec_pack;
  78. struct regmap_field *codec_intf;
  79. struct regmap_field *codec_fs_sel;
  80. struct regmap_field *codec_channel;
  81. struct regmap_field *codec_fs_delay;
  82. };
  83. /* Both the CPU DAI and platform drivers will access this data */
  84. struct lpass_data {
  85. /* AHB-I/X bus clocks inside the low-power audio subsystem (LPASS) */
  86. struct clk *ahbix_clk;
  87. /* MI2S system clock */
  88. struct clk *mi2s_osr_clk[LPASS_MAX_MI2S_PORTS];
  89. /* MI2S bit clock (derived from system clock by a divider */
  90. struct clk *mi2s_bit_clk[LPASS_MAX_MI2S_PORTS];
  91. struct clk *codec_mem0;
  92. struct clk *codec_mem1;
  93. struct clk *codec_mem2;
  94. struct clk *va_mem0;
  95. /* MI2S SD lines to use for playback/capture */
  96. unsigned int mi2s_playback_sd_mode[LPASS_MAX_MI2S_PORTS];
  97. unsigned int mi2s_capture_sd_mode[LPASS_MAX_MI2S_PORTS];
  98. /* The state of MI2S prepare dai_ops was called */
  99. bool mi2s_was_prepared[LPASS_MAX_MI2S_PORTS];
  100. int hdmi_port_enable;
  101. int codec_dma_enable;
  102. /* low-power audio interface (LPAIF) registers */
  103. void __iomem *lpaif;
  104. void __iomem *hdmiif;
  105. void __iomem *rxtx_lpaif;
  106. void __iomem *va_lpaif;
  107. u32 rxtx_cdc_dma_lpm_buf;
  108. u32 va_cdc_dma_lpm_buf;
  109. /* regmap backed by the low-power audio interface (LPAIF) registers */
  110. struct regmap *lpaif_map;
  111. struct regmap *hdmiif_map;
  112. struct regmap *rxtx_lpaif_map;
  113. struct regmap *va_lpaif_map;
  114. /* interrupts from the low-power audio interface (LPAIF) */
  115. int lpaif_irq;
  116. int hdmiif_irq;
  117. int rxtxif_irq;
  118. int vaif_irq;
  119. /* SOC specific variations in the LPASS IP integration */
  120. const struct lpass_variant *variant;
  121. /* bit map to keep track of static channel allocations */
  122. unsigned long dma_ch_bit_map;
  123. unsigned long hdmi_dma_ch_bit_map;
  124. unsigned long rxtx_dma_ch_bit_map;
  125. unsigned long va_dma_ch_bit_map;
  126. /* used it for handling interrupt per dma channel */
  127. struct snd_pcm_substream *substream[LPASS_MAX_DMA_CHANNELS];
  128. struct snd_pcm_substream *hdmi_substream[LPASS_MAX_HDMI_DMA_CHANNELS];
  129. struct snd_pcm_substream *rxtx_substream[LPASS_MAX_CDC_DMA_CHANNELS];
  130. struct snd_pcm_substream *va_substream[LPASS_MAX_CDC_DMA_CHANNELS];
  131. /* SOC specific clock list */
  132. struct clk_bulk_data *clks;
  133. int num_clks;
  134. /* Regmap fields of I2SCTL & DMACTL registers bitfields */
  135. struct lpaif_i2sctl *i2sctl;
  136. struct lpaif_dmactl *rd_dmactl;
  137. struct lpaif_dmactl *wr_dmactl;
  138. struct lpaif_dmactl *hdmi_rd_dmactl;
  139. /* Regmap fields of CODEC DMA CTRL registers */
  140. struct lpaif_dmactl *rxtx_rd_dmactl;
  141. struct lpaif_dmactl *rxtx_wr_dmactl;
  142. struct lpaif_dmactl *va_wr_dmactl;
  143. /* Regmap fields of HDMI_CTRL registers*/
  144. struct regmap_field *hdmitx_legacy_en;
  145. struct regmap_field *hdmitx_parity_calc_en;
  146. struct regmap_field *hdmitx_ch_msb[LPASS_MAX_HDMI_DMA_CHANNELS];
  147. struct regmap_field *hdmitx_ch_lsb[LPASS_MAX_HDMI_DMA_CHANNELS];
  148. struct lpass_hdmi_tx_ctl *tx_ctl;
  149. struct lpass_vbit_ctrl *vbit_ctl;
  150. struct lpass_hdmitx_dmactl *hdmi_tx_dmactl[LPASS_MAX_HDMI_DMA_CHANNELS];
  151. struct lpass_dp_metadata_ctl *meta_ctl;
  152. struct lpass_sstream_ctl *sstream_ctl;
  153. };
  154. /* Vairant data per each SOC */
  155. struct lpass_variant {
  156. u32 irq_reg_base;
  157. u32 irq_reg_stride;
  158. u32 irq_ports;
  159. u32 rdma_reg_base;
  160. u32 rdma_reg_stride;
  161. u32 rdma_channels;
  162. u32 hdmi_rdma_reg_base;
  163. u32 hdmi_rdma_reg_stride;
  164. u32 hdmi_rdma_channels;
  165. u32 wrdma_reg_base;
  166. u32 wrdma_reg_stride;
  167. u32 wrdma_channels;
  168. u32 rxtx_irq_reg_base;
  169. u32 rxtx_irq_reg_stride;
  170. u32 rxtx_irq_ports;
  171. u32 rxtx_rdma_reg_base;
  172. u32 rxtx_rdma_reg_stride;
  173. u32 rxtx_rdma_channels;
  174. u32 rxtx_wrdma_reg_base;
  175. u32 rxtx_wrdma_reg_stride;
  176. u32 rxtx_wrdma_channels;
  177. u32 va_irq_reg_base;
  178. u32 va_irq_reg_stride;
  179. u32 va_irq_ports;
  180. u32 va_rdma_reg_base;
  181. u32 va_rdma_reg_stride;
  182. u32 va_rdma_channels;
  183. u32 va_wrdma_reg_base;
  184. u32 va_wrdma_reg_stride;
  185. u32 va_wrdma_channels;
  186. u32 i2sctrl_reg_base;
  187. u32 i2sctrl_reg_stride;
  188. u32 i2s_ports;
  189. /* I2SCTL Register fields */
  190. struct reg_field loopback;
  191. struct reg_field spken;
  192. struct reg_field spkmode;
  193. struct reg_field spkmono;
  194. struct reg_field micen;
  195. struct reg_field micmode;
  196. struct reg_field micmono;
  197. struct reg_field wssrc;
  198. struct reg_field bitwidth;
  199. u32 hdmi_irq_reg_base;
  200. u32 hdmi_irq_reg_stride;
  201. u32 hdmi_irq_ports;
  202. /* HDMI specific controls */
  203. u32 hdmi_tx_ctl_addr;
  204. u32 hdmi_legacy_addr;
  205. u32 hdmi_vbit_addr;
  206. u32 hdmi_ch_lsb_addr;
  207. u32 hdmi_ch_msb_addr;
  208. u32 ch_stride;
  209. u32 hdmi_parity_addr;
  210. u32 hdmi_dmactl_addr;
  211. u32 hdmi_dma_stride;
  212. u32 hdmi_DP_addr;
  213. u32 hdmi_sstream_addr;
  214. /* HDMI SSTREAM CTRL fields */
  215. struct reg_field sstream_en;
  216. struct reg_field dma_sel;
  217. struct reg_field auto_bbit_en;
  218. struct reg_field layout;
  219. struct reg_field layout_sp;
  220. struct reg_field set_sp_on_en;
  221. struct reg_field dp_audio;
  222. struct reg_field dp_staffing_en;
  223. struct reg_field dp_sp_b_hw_en;
  224. /* HDMI DP METADATA CTL fields */
  225. struct reg_field mute;
  226. struct reg_field as_sdp_cc;
  227. struct reg_field as_sdp_ct;
  228. struct reg_field aif_db4;
  229. struct reg_field frequency;
  230. struct reg_field mst_index;
  231. struct reg_field dptx_index;
  232. /* HDMI TX CTRL fields */
  233. struct reg_field soft_reset;
  234. struct reg_field force_reset;
  235. /* HDMI TX DMA CTRL */
  236. struct reg_field use_hw_chs;
  237. struct reg_field use_hw_usr;
  238. struct reg_field hw_chs_sel;
  239. struct reg_field hw_usr_sel;
  240. /* HDMI VBIT CTRL */
  241. struct reg_field replace_vbit;
  242. struct reg_field vbit_stream;
  243. /* HDMI TX LEGACY */
  244. struct reg_field legacy_en;
  245. /* HDMI TX PARITY */
  246. struct reg_field calc_en;
  247. /* HDMI CH LSB */
  248. struct reg_field lsb_bits;
  249. /* HDMI CH MSB */
  250. struct reg_field msb_bits;
  251. struct reg_field hdmi_rdma_bursten;
  252. struct reg_field hdmi_rdma_wpscnt;
  253. struct reg_field hdmi_rdma_fifowm;
  254. struct reg_field hdmi_rdma_enable;
  255. struct reg_field hdmi_rdma_dyncclk;
  256. struct reg_field hdmi_rdma_burst8;
  257. struct reg_field hdmi_rdma_burst16;
  258. struct reg_field hdmi_rdma_dynburst;
  259. /* RD_DMA Register fields */
  260. struct reg_field rdma_intf;
  261. struct reg_field rdma_bursten;
  262. struct reg_field rdma_wpscnt;
  263. struct reg_field rdma_fifowm;
  264. struct reg_field rdma_enable;
  265. struct reg_field rdma_dyncclk;
  266. /* WR_DMA Register fields */
  267. struct reg_field wrdma_intf;
  268. struct reg_field wrdma_bursten;
  269. struct reg_field wrdma_wpscnt;
  270. struct reg_field wrdma_fifowm;
  271. struct reg_field wrdma_enable;
  272. struct reg_field wrdma_dyncclk;
  273. /* CDC RXTX RD_DMA */
  274. struct reg_field rxtx_rdma_intf;
  275. struct reg_field rxtx_rdma_bursten;
  276. struct reg_field rxtx_rdma_wpscnt;
  277. struct reg_field rxtx_rdma_fifowm;
  278. struct reg_field rxtx_rdma_enable;
  279. struct reg_field rxtx_rdma_dyncclk;
  280. struct reg_field rxtx_rdma_burst8;
  281. struct reg_field rxtx_rdma_burst16;
  282. struct reg_field rxtx_rdma_dynburst;
  283. struct reg_field rxtx_rdma_codec_enable;
  284. struct reg_field rxtx_rdma_codec_pack;
  285. struct reg_field rxtx_rdma_codec_intf;
  286. struct reg_field rxtx_rdma_codec_fs_sel;
  287. struct reg_field rxtx_rdma_codec_ch;
  288. struct reg_field rxtx_rdma_codec_fs_delay;
  289. /* CDC RXTX WR_DMA */
  290. struct reg_field rxtx_wrdma_intf;
  291. struct reg_field rxtx_wrdma_bursten;
  292. struct reg_field rxtx_wrdma_wpscnt;
  293. struct reg_field rxtx_wrdma_fifowm;
  294. struct reg_field rxtx_wrdma_enable;
  295. struct reg_field rxtx_wrdma_dyncclk;
  296. struct reg_field rxtx_wrdma_burst8;
  297. struct reg_field rxtx_wrdma_burst16;
  298. struct reg_field rxtx_wrdma_dynburst;
  299. struct reg_field rxtx_wrdma_codec_enable;
  300. struct reg_field rxtx_wrdma_codec_pack;
  301. struct reg_field rxtx_wrdma_codec_intf;
  302. struct reg_field rxtx_wrdma_codec_fs_sel;
  303. struct reg_field rxtx_wrdma_codec_ch;
  304. struct reg_field rxtx_wrdma_codec_fs_delay;
  305. /* CDC VA WR_DMA */
  306. struct reg_field va_wrdma_intf;
  307. struct reg_field va_wrdma_bursten;
  308. struct reg_field va_wrdma_wpscnt;
  309. struct reg_field va_wrdma_fifowm;
  310. struct reg_field va_wrdma_enable;
  311. struct reg_field va_wrdma_dyncclk;
  312. struct reg_field va_wrdma_burst8;
  313. struct reg_field va_wrdma_burst16;
  314. struct reg_field va_wrdma_dynburst;
  315. struct reg_field va_wrdma_codec_enable;
  316. struct reg_field va_wrdma_codec_pack;
  317. struct reg_field va_wrdma_codec_intf;
  318. struct reg_field va_wrdma_codec_fs_sel;
  319. struct reg_field va_wrdma_codec_ch;
  320. struct reg_field va_wrdma_codec_fs_delay;
  321. /**
  322. * on SOCs like APQ8016 the channel control bits start
  323. * at different offset to ipq806x
  324. **/
  325. u32 dmactl_audif_start;
  326. u32 wrdma_channel_start;
  327. u32 rxtx_wrdma_channel_start;
  328. u32 va_wrdma_channel_start;
  329. /* SOC specific initialization like clocks */
  330. int (*init)(struct platform_device *pdev);
  331. int (*exit)(struct platform_device *pdev);
  332. int (*alloc_dma_channel)(struct lpass_data *data, int direction, unsigned int dai_id);
  333. int (*free_dma_channel)(struct lpass_data *data, int ch, unsigned int dai_id);
  334. /* SOC specific dais */
  335. struct snd_soc_dai_driver *dai_driver;
  336. int num_dai;
  337. const char * const *dai_osr_clk_names;
  338. const char * const *dai_bit_clk_names;
  339. /* SOC specific clocks configuration */
  340. const char **clk_name;
  341. int num_clks;
  342. };
  343. struct lpass_pcm_data {
  344. int dma_ch;
  345. int i2s_port;
  346. };
  347. /* register the platform driver from the CPU DAI driver */
  348. int asoc_qcom_lpass_platform_register(struct platform_device *pdev);
  349. void asoc_qcom_lpass_cpu_platform_remove(struct platform_device *pdev);
  350. void asoc_qcom_lpass_cpu_platform_shutdown(struct platform_device *pdev);
  351. int asoc_qcom_lpass_cpu_platform_probe(struct platform_device *pdev);
  352. extern const struct snd_soc_dai_ops asoc_qcom_lpass_cpu_dai_ops;
  353. extern const struct snd_soc_dai_ops asoc_qcom_lpass_cpu_dai_ops2;
  354. extern const struct snd_soc_dai_ops asoc_qcom_lpass_cdc_dma_dai_ops;
  355. #endif /* __LPASS_H__ */