lpass.h 11 KB

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