lpass-cdc.h 12 KB

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