lpass-cdc.h 11 KB

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