lpass-cdc.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /* Copyright (c) 2018-2021, The Linux Foundation. All rights reserved.
  3. * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
  4. */
  5. #ifndef LPASS_CDC_H
  6. #define LPASS_CDC_H
  7. #include <sound/soc.h>
  8. #include <linux/regmap.h>
  9. #define LPASS_CDC_VERSION_1_0 0x0001
  10. #define LPASS_CDC_VERSION_1_1 0x0002
  11. #define LPASS_CDC_VERSION_1_2 0x0003
  12. #define LPASS_CDC_VERSION_2_0 0x0004
  13. #define LPASS_CDC_VERSION_2_1 0x0005
  14. #define LPASS_CDC_VERSION_2_5 0x0006
  15. #define LPASS_CDC_VERSION_2_6 0x0007
  16. enum {
  17. START_MACRO,
  18. TX_MACRO = START_MACRO,
  19. RX_MACRO,
  20. WSA_MACRO,
  21. VA_MACRO,
  22. WSA2_MACRO,
  23. MAX_MACRO
  24. };
  25. enum mclk_mux {
  26. MCLK_MUX0,
  27. MCLK_MUX1,
  28. MCLK_MUX_MAX
  29. };
  30. enum {
  31. LPASS_CDC_ADC0 = 1,
  32. LPASS_CDC_ADC1,
  33. LPASS_CDC_ADC2,
  34. LPASS_CDC_ADC3,
  35. LPASS_CDC_ADC_MAX
  36. };
  37. enum {
  38. LPASS_CDC_MACRO_EVT_RX_MUTE = 1, /* for RX mute/unmute */
  39. LPASS_CDC_MACRO_EVT_IMPED_TRUE, /* for imped true */
  40. LPASS_CDC_MACRO_EVT_IMPED_FALSE, /* for imped false */
  41. LPASS_CDC_MACRO_EVT_SSR_DOWN,
  42. LPASS_CDC_MACRO_EVT_SSR_UP,
  43. LPASS_CDC_MACRO_EVT_WAIT_VA_CLK_RESET,
  44. LPASS_CDC_MACRO_EVT_CLK_RESET,
  45. LPASS_CDC_MACRO_EVT_REG_WAKE_IRQ,
  46. LPASS_CDC_MACRO_EVT_RX_COMPANDER_SOFT_RST,
  47. LPASS_CDC_MACRO_EVT_BCS_CLK_OFF,
  48. LPASS_CDC_MACRO_EVT_SSR_GFMUX_UP,
  49. LPASS_CDC_MACRO_EVT_PRE_SSR_UP,
  50. LPASS_CDC_MACRO_EVT_RX_PA_GAIN_UPDATE,
  51. LPASS_CDC_MACRO_EVT_HPHL_HD2_ENABLE, /* Enable HD2 cfg for HPHL */
  52. LPASS_CDC_MACRO_EVT_HPHR_HD2_ENABLE, /* Enable HD2 cfg for HPHR */
  53. };
  54. enum {
  55. DMIC_TX = 0,
  56. DMIC_VA = 1,
  57. };
  58. struct macro_ops {
  59. int (*init)(struct snd_soc_component *component);
  60. int (*exit)(struct snd_soc_component *component);
  61. u16 num_dais;
  62. struct device *dev;
  63. struct snd_soc_dai_driver *dai_ptr;
  64. int (*mclk_fn)(struct device *dev, bool enable);
  65. int (*event_handler)(struct snd_soc_component *component, u16 event,
  66. u32 data);
  67. int (*reg_wake_irq)(struct snd_soc_component *component, u32 data);
  68. int (*set_port_map)(struct snd_soc_component *component, u32 uc,
  69. u32 size, void *data);
  70. int (*clk_div_get)(struct snd_soc_component *component);
  71. int (*reg_evt_listener)(struct snd_soc_component *component, bool en);
  72. int (*clk_enable)(struct snd_soc_component *c, bool en);
  73. char __iomem *io_base;
  74. u16 clk_id_req;
  75. u16 default_clk_id;
  76. };
  77. enum {
  78. G_21_DB = 0,
  79. G_19P5_DB,
  80. G_18_DB,
  81. G_16P5_DB,
  82. G_15_DB,
  83. G_13P5_DB,
  84. G_12_DB,
  85. G_10P5_DB,
  86. G_9_DB,
  87. G_7P5_DB,
  88. G_6_DB,
  89. G_4P5_DB,
  90. G_3_DB,
  91. G_1P5_DB,
  92. G_0_DB,
  93. G_M1P5_DB,
  94. G_M3_DB,
  95. G_M4P5_DB,
  96. G_M6_DB,
  97. G_MAX_DB,
  98. };
  99. enum {
  100. EXT_ABOVE_3S,
  101. CONFIG_1S,
  102. CONFIG_2S,
  103. CONFIG_3S,
  104. EXT_1S,
  105. EXT_2S,
  106. EXT_3S,
  107. CONFIG_MAX,
  108. };
  109. enum {
  110. WSA_4_OHMS = 0,
  111. WSA_6_OHMS,
  112. WSA_8_OHMS,
  113. WSA_32_OHMS,
  114. WSA_MAX_OHMS,
  115. };
  116. /*
  117. * PBR Thresholds from system_gain, bat_cfg, and rload
  118. * EXT_ABOVE_3S: WSA_4_OHMS, WSA_6_OHMS, WSA_8_OHMS, WSA_32_OHMS, CONFIG_1S: ...
  119. */
  120. static const int pbr_vth1_data[G_MAX_DB][CONFIG_MAX][WSA_MAX_OHMS] = {
  121. /* G_21_DB */
  122. {
  123. {0, 0, 0, 0}, {81, 92, 106, 0},
  124. {121, 148, 144, 0}, {158, 193, 192, 0}
  125. },
  126. /* G_19P5_DB */
  127. {
  128. {0, 0, 0, 0}, {96, 109, 126, 0},
  129. {143, 148, 203, 0}, {188, 198, 255, 0}
  130. },
  131. /* G_18_DB */
  132. {
  133. {0, 0, 0, 0}, {106, 130, 150, 0},
  134. {144, 209, 241, 0}, {192, 255, 255, 0}
  135. },
  136. /* G_16P5_DB */
  137. {
  138. {0, 0, 0, 0}, {135, 154, 178, 0},
  139. {202, 248, 255, 0}, {255, 255, 255, 0}
  140. },
  141. /* G_15_DB */
  142. {
  143. {0, 0, 0, 0}, {160, 183, 211, 0},
  144. {240, 255, 255, 0}, {255, 255, 255, 0}
  145. },
  146. /* G_13P5_DB */
  147. {
  148. {0, 0, 0, 0}, {190, 217, 251, 0},
  149. {255, 255, 255, 0}, {255, 255, 255, 0}
  150. },
  151. /* G_12_DB */
  152. {
  153. {0, 0, 0, 0}, {226, 255, 255, 0},
  154. {225, 255, 255, 0}, {255, 255, 255, 0}
  155. },
  156. };
  157. static const int pbr_vth2_data[G_MAX_DB][CONFIG_MAX][WSA_MAX_OHMS] = {
  158. { {0, 0, 0, 0}, {0, 0, 112, 0}, {0, 0, 151, 0}, {0, 0, 196, 0} }, /* G_21_DB */
  159. { {0, 0, 0, 0}, {0, 115, 0, 0}, {0, 155, 0, 0}, {0, 201, 0, 0} }, /* G_19P5_DB */
  160. { {0, 0, 0, 0}, {112, 0, 0, 0}, {150, 0, 0, 0}, {195, 0, 0, 0} }, /* G_18_DB */
  161. };
  162. static const int pbr_vth3_data[G_MAX_DB][CONFIG_MAX][WSA_MAX_OHMS] = {
  163. { {0, 0, 0, 0}, {0, 0, 118, 0}, {0, 0, 157, 0}, {0, 0, 199, 0} }, /* G_21_DB */
  164. { {0, 0, 0, 0}, {0, 122, 0, 0}, {0, 162, 0, 0}, {0, 205, 0, 0} }, /* G_19P5_DB */
  165. { {0, 0, 0, 0}, {118, 0, 0, 0}, {157, 0, 0, 0}, {199, 0, 0, 0} }, /* G_18_DB */
  166. };
  167. static const int pbr_vth4_data[G_MAX_DB][CONFIG_MAX][WSA_MAX_OHMS] = {
  168. { {0, 0, 0, 0}, {0, 0, 125, 0}, {0, 0, 163, 0}, {0, 0, 202, 0} }, /* G_21_DB */
  169. { {0, 0, 0, 0}, {0, 129, 0, 0}, {0, 168, 0, 0}, {0, 208, 0, 0} }, /* G_19P5_DB */
  170. { {0, 0, 0, 0}, {125, 0, 0, 0}, {163, 0, 0, 0}, {202, 0, 0, 0} }, /* G_18_DB */
  171. };
  172. static const int pbr_vth5_data[G_MAX_DB][CONFIG_MAX][WSA_MAX_OHMS] = {
  173. { {0, 0, 0, 0}, {0, 0, 131, 0}, {0, 0, 170, 0}, {0, 0, 205, 0} }, /* G_21_DB */
  174. { {0, 0, 0, 0}, {0, 135, 0, 0}, {0, 175, 0, 0}, {0, 211, 0, 0} }, /* G_19P5_DB */
  175. { {0, 0, 0, 0}, {131, 0, 0, 0}, {170, 0, 0, 0}, {205, 0, 0, 0} }, /* G_18_DB */
  176. };
  177. static const int pbr_vth6_data[G_MAX_DB][CONFIG_MAX][WSA_MAX_OHMS] = {
  178. { {0, 0, 0, 0}, {0, 0, 138, 0}, {0, 0, 176, 0}, {0, 0, 208, 0} }, /* G_21_DB */
  179. { {0, 0, 0, 0}, {0, 142, 0, 0}, {0, 182, 0, 0}, {0, 215, 0, 0} }, /* G_19P5_DB */
  180. { {0, 0, 0, 0}, {138, 0, 0, 0}, {176, 0, 0, 0}, {208, 0, 0, 0} }, /* G_18_DB */
  181. };
  182. static const int pbr_vth7_data[G_MAX_DB][CONFIG_MAX][WSA_MAX_OHMS] = {
  183. { {0, 0, 0, 0}, {0, 0, 144, 0}, {0, 0, 183, 0}, {0, 0, 212, 0} }, /* G_21_DB */
  184. { {0, 0, 0, 0}, {0, 148, 0, 0}, {0, 188, 0, 0}, {0, 218, 0, 0} }, /* G_19P5_DB */
  185. { {0, 0, 0, 0}, {0, 0, 144, 0}, {0, 0, 183, 0}, {0, 0, 212, 0} }, /* G_18_DB */
  186. };
  187. static const int pbr_vth8_data[G_MAX_DB][CONFIG_MAX][WSA_MAX_OHMS] = {
  188. { {0, 0, 0, 0}, {0, 0, 151, 0}, {0, 0, 189, 0}, {0, 0, 215, 0} }, /* G_21_DB */
  189. { {0, 0, 0, 0}, {0, 155, 0, 0}, {0, 195, 0, 0}, {0, 221, 0, 0} }, /* G_19P5_DB */
  190. { {0, 0, 0, 0}, {150, 0, 0, 0}, {189, 0, 0, 0}, {215, 0, 0, 0} }, /* G_18_DB */
  191. };
  192. static const int pbr_vth9_data[G_MAX_DB][CONFIG_MAX][WSA_MAX_OHMS] = {
  193. { {0, 0, 0, 0}, {0, 0, 157, 0}, {0, 0, 196, 0}, {0, 0, 218, 0} }, /* G_21_DB */
  194. { {0, 0, 0, 0}, {0, 162, 0, 0}, {0, 201, 0, 0}, {0, 225, 0, 0} }, /* G_19P5_DB */
  195. { {0, 0, 0, 0}, {157, 0, 0, 0}, {195, 0, 0, 0}, {218, 0, 0, 0} }, /* G_18_DB */
  196. };
  197. static const int pbr_vth10_data[G_MAX_DB][CONFIG_MAX][WSA_MAX_OHMS] = {
  198. { {0, 0, 0, 0}, {0, 0, 163, 0}, {0, 0, 202, 0}, {0, 0, 221, 0} }, /* G_21_DB */
  199. { {0, 0, 0, 0}, {0, 168, 0, 0}, {0, 208, 0, 0}, {0, 228, 0, 0} }, /* G_19P5_DB */
  200. { {0, 0, 0, 0}, {163, 0, 0, 0}, {202, 0, 0, 0}, {221, 0, 0, 0} }, /* G_18_DB */
  201. };
  202. static const int pbr_vth11_data[G_MAX_DB][CONFIG_MAX][WSA_MAX_OHMS] = {
  203. { {0, 0, 0, 0}, {0, 0, 170, 0}, {0, 0, 208, 0}, {0, 0, 225, 0} }, /* G_21_DB */
  204. { {0, 0, 0, 0}, {0, 175, 0, 0}, {0, 215, 0, 0}, {0, 231, 0, 0} }, /* G_19P5_DB */
  205. { {0, 0, 0, 0}, {170, 0, 0, 0}, {208, 0, 0, 0}, {224, 0, 0, 0} }, /* G_18_DB */
  206. };
  207. static const int pbr_vth12_data[G_MAX_DB][CONFIG_MAX][WSA_MAX_OHMS] = {
  208. { {0, 0, 0, 0}, {0, 0, 176, 0}, {0, 0, 215, 0}, {0, 0, 228, 0} }, /* G_21_DB */
  209. { {0, 0, 0, 0}, {0, 182, 0, 0}, {0, 221, 0, 0}, {0, 234, 0, 0} }, /* G_19P5_DB */
  210. { {0, 0, 0, 0}, {176, 0, 0, 0}, {215, 0, 0, 0}, {228, 0, 0, 0} }, /* G_18_DB */
  211. };
  212. static const int pbr_vth13_data[G_MAX_DB][CONFIG_MAX][WSA_MAX_OHMS] = {
  213. { {0, 0, 0, 0}, {0, 0, 183, 0}, {0, 0, 221, 0}, {0, 0, 231, 0} }, /* G_21_DB */
  214. { {0, 0, 0, 0}, {0, 188, 0, 0}, {0, 228, 0, 0}, {0, 238, 0, 0} }, /* G_19P5_DB */
  215. { {0, 0, 0, 0}, {183, 0, 0, 0}, {221, 0, 0, 0}, {231, 0, 0, 0} }, /* G_18_DB */
  216. };
  217. static const int pbr_vth14_data[G_MAX_DB][CONFIG_MAX][WSA_MAX_OHMS] = {
  218. { {0, 0, 0, 0}, {0, 0, 189, 0}, {0, 0, 228, 0}, {0, 0, 234, 0} }, /* G_21_DB */
  219. { {0, 0, 0, 0}, {0, 195, 0, 0}, {0, 234, 0, 0}, {0, 241, 0, 0} }, /* G_19P5_DB */
  220. { {0, 0, 0, 0}, {189, 0, 0, 0}, {228, 0, 0, 0}, {234, 0, 0, 0} }, /* G_18_DB */
  221. };
  222. static const int pbr_vth15_data[G_MAX_DB][CONFIG_MAX][WSA_MAX_OHMS] = {
  223. { {0, 0, 0, 0}, {0, 0, 196, 0}, {0, 0, 234, 0}, {0, 0, 237, 0} }, /* G_21_DB */
  224. { {0, 0, 0, 0}, {0, 201, 0, 0}, {0, 241, 0, 0}, {0, 244, 0, 0} }, /* G_19P5_DB */
  225. { {0, 0, 0, 0}, {195, 0, 0, 0}, {234, 0, 0, 0}, {237, 0, 0, 0} }, /* G_18_DB */
  226. };
  227. typedef int (*rsc_clk_cb_t)(struct device *dev, u16 event);
  228. #if IS_ENABLED(CONFIG_SND_SOC_LPASS_CDC)
  229. int lpass_cdc_register_res_clk(struct device *dev, rsc_clk_cb_t cb);
  230. void lpass_cdc_unregister_res_clk(struct device *dev);
  231. bool lpass_cdc_is_va_macro_registered(struct device *dev);
  232. int lpass_cdc_register_macro(struct device *dev, u16 macro_id,
  233. struct macro_ops *ops);
  234. void lpass_cdc_unregister_macro(struct device *dev, u16 macro_id);
  235. struct device *lpass_cdc_get_device_ptr(struct device *dev, u16 macro_id);
  236. struct device *lpass_cdc_get_rsc_clk_device_ptr(struct device *dev);
  237. int lpass_cdc_info_create_codec_entry(
  238. struct snd_info_entry *codec_root,
  239. struct snd_soc_component *component);
  240. int lpass_cdc_register_wake_irq(struct snd_soc_component *component, u32 data);
  241. void lpass_cdc_clear_amic_tx_hold(struct device *dev, u16 adc_n);
  242. int lpass_cdc_runtime_resume(struct device *dev);
  243. int lpass_cdc_runtime_suspend(struct device *dev);
  244. int lpass_cdc_set_port_map(struct snd_soc_component *component, u32 size, void *data);
  245. int lpass_cdc_register_event_listener(struct snd_soc_component *component,
  246. bool enable);
  247. void lpass_cdc_wsa_pa_on(struct device *dev, bool adie_lb);
  248. void lpass_cdc_notify_wcd_rx_clk(struct device *dev, bool is_native_on);
  249. bool lpass_cdc_check_core_votes(struct device *dev);
  250. int lpass_cdc_tx_mclk_enable(struct snd_soc_component *c, bool enable);
  251. int lpass_cdc_get_version(struct device *dev);
  252. int lpass_cdc_dmic_clk_enable(struct snd_soc_component *component,
  253. u32 dmic, u32 tx_mode, bool enable);
  254. /* RX MACRO utilities */
  255. int lpass_cdc_rx_set_fir_capability(struct snd_soc_component *component,
  256. bool capable);
  257. #else
  258. static inline int lpass_cdc_register_res_clk(struct device *dev, rsc_clk_cb_t cb)
  259. {
  260. return 0;
  261. }
  262. static inline void lpass_cdc_unregister_res_clk(struct device *dev)
  263. {
  264. }
  265. static bool lpass_cdc_is_va_macro_registered(struct device *dev)
  266. {
  267. return false;
  268. }
  269. static inline int lpass_cdc_register_macro(struct device *dev,
  270. u16 macro_id,
  271. struct macro_ops *ops)
  272. {
  273. return 0;
  274. }
  275. static inline void lpass_cdc_unregister_macro(struct device *dev, u16 macro_id)
  276. {
  277. }
  278. static inline struct device *lpass_cdc_get_device_ptr(struct device *dev,
  279. u16 macro_id)
  280. {
  281. return NULL;
  282. }
  283. static int lpass_cdc_info_create_codec_entry(
  284. struct snd_info_entry *codec_root,
  285. struct snd_soc_component *component)
  286. {
  287. return 0;
  288. }
  289. static inline void lpass_cdc_clear_amic_tx_hold(struct device *dev, u16 adc_n)
  290. {
  291. }
  292. static inline int lpass_cdc_register_wake_irq(struct snd_soc_component *component,
  293. u32 data)
  294. {
  295. return 0;
  296. }
  297. static inline int lpass_cdc_runtime_resume(struct device *dev)
  298. {
  299. return 0;
  300. }
  301. static int lpass_cdc_runtime_suspend(struct device *dev)
  302. {
  303. return 0;
  304. }
  305. static inline int lpass_cdc_set_port_map(struct snd_soc_component *component,
  306. u32 size, void *data)
  307. {
  308. return 0;
  309. }
  310. static inline int lpass_cdc_register_event_listener(
  311. struct snd_soc_component *component,
  312. bool enable)
  313. {
  314. return 0;
  315. }
  316. static void lpass_cdc_wsa_pa_on(struct device *dev, bool adie_lb)
  317. {
  318. }
  319. static void lpass_cdc_notify_wcd_rx_clk(struct device *dev, bool is_native_on)
  320. {
  321. }
  322. static inline bool lpass_cdc_check_core_votes(struct device *dev)
  323. {
  324. return false;
  325. }
  326. static int lpass_cdc_get_version(struct device *dev)
  327. {
  328. return 0;
  329. }
  330. static int lpass_cdc_dmic_clk_enable(struct snd_soc_component *component,
  331. u32 dmic, u32 tx_mode, bool enable)
  332. {
  333. return 0;
  334. }
  335. static int lpass_cdc_tx_mclk_enable(struct snd_soc_component *c, bool enable)
  336. {
  337. return 0;
  338. }
  339. /* RX MACRO utilities */
  340. static int lpass_cdc_rx_set_fir_capability(struct snd_soc_component *component,
  341. bool capable)
  342. {
  343. return 0;
  344. }
  345. #endif /* CONFIG_SND_SOC_LPASS_CDC */
  346. #endif /* LPASS_CDC_H */