internal.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2018-2020, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #ifndef _WCD939X_INTERNAL_H
  7. #define _WCD939X_INTERNAL_H
  8. #include <asoc/wcd-mbhc-v2.h>
  9. #include <asoc/wcd-irq.h>
  10. #include <asoc/wcd-clsh.h>
  11. #include <soc/soundwire.h>
  12. #include "wcd939x-mbhc.h"
  13. #include "wcd939x.h"
  14. #define SWR_SCP_CONTROL 0x44
  15. #define SWR_SCP_HOST_CLK_DIV2_CTL_BANK 0xE0
  16. #define WCD939X_MAX_MICBIAS 4
  17. #define MAX_XTALK_SCALE 31
  18. #define MIN_XTALK_ALPHA 0
  19. #define MIN_K_TIMES_100 -90
  20. #define MAX_K_TIMES_100 10000
  21. #define MAX_USBCSS_HS_IMPEDANCE_MOHMS 20000
  22. /* Convert from vout ctl to micbias voltage in mV */
  23. #define WCD_VOUT_CTL_TO_MICB(v) (1000 + v * 50)
  24. #define MAX_PORT 8
  25. #define MAX_CH_PER_PORT 8
  26. #define TX_ADC_MAX 4
  27. #define SWR_NUM_PORTS 4
  28. enum {
  29. RX_CLK_9P6MHZ,
  30. RX_CLK_12P288MHZ,
  31. RX_CLK_11P2896MHZ,
  32. };
  33. enum {
  34. WCD939X_HPHL,
  35. WCD939X_HPHR,
  36. WCD939X_HPH_MAX,
  37. };
  38. enum {
  39. TX_HDR12 = 0,
  40. TX_HDR34,
  41. TX_HDR_MAX,
  42. };
  43. enum xtalk_mode {
  44. XTALK_NONE = 0,
  45. XTALK_DIGITAL = 1,
  46. XTALK_ANALOG = 2
  47. };
  48. extern struct regmap_config wcd939x_regmap_config;
  49. struct comp_coeff_val {
  50. u8 lsb;
  51. u8 msb;
  52. };
  53. struct codec_port_info {
  54. u32 slave_port_type;
  55. u32 master_port_type;
  56. u32 ch_mask;
  57. u32 num_ch;
  58. u32 ch_rate;
  59. };
  60. struct wcd939x_priv {
  61. struct device *dev;
  62. int variant;
  63. struct snd_soc_component *component;
  64. struct device_node *rst_np;
  65. struct regmap *regmap;
  66. struct swr_device *rx_swr_dev;
  67. struct swr_device *tx_swr_dev;
  68. s32 micb_ref[WCD939X_MAX_MICBIAS];
  69. s32 pullup_ref[WCD939X_MAX_MICBIAS];
  70. struct fw_info *fw_data;
  71. struct device_node *wcd_rst_np;
  72. struct mutex micb_lock;
  73. struct mutex wakeup_lock;
  74. s32 dmic_0_1_clk_cnt;
  75. s32 dmic_2_3_clk_cnt;
  76. s32 dmic_4_5_clk_cnt;
  77. s32 dmic_6_7_clk_cnt;
  78. int hdr_en[TX_HDR_MAX];
  79. /* class h specific info */
  80. struct wcd_clsh_cdc_info clsh_info;
  81. /* mbhc module */
  82. struct wcd939x_mbhc *mbhc;
  83. /*compander and xtalk*/
  84. int compander_enabled[WCD939X_HPH_MAX];
  85. int xtalk_enabled[WCD939X_HPH_MAX];
  86. u8 hph_pcm_enabled;
  87. u32 hph_mode;
  88. u32 tx_mode[TX_ADC_MAX];
  89. s32 adc_count;
  90. bool comp1_enable;
  91. bool comp2_enable;
  92. bool ldoh;
  93. bool bcs_dis;
  94. bool dapm_bias_off;
  95. bool in_2Vpk_mode;
  96. struct irq_domain *virq;
  97. struct wcd_irq_info irq_info;
  98. u32 rx_clk_cnt;
  99. int num_irq_regs;
  100. /* to track the status */
  101. unsigned long status_mask;
  102. u8 num_tx_ports;
  103. u8 num_rx_ports;
  104. struct codec_port_info
  105. tx_port_mapping[MAX_PORT][MAX_CH_PER_PORT];
  106. struct codec_port_info
  107. rx_port_mapping[MAX_PORT][MAX_CH_PER_PORT];
  108. struct swr_port_params tx_port_params[SWR_UC_MAX][SWR_NUM_PORTS];
  109. struct swr_dev_frame_config swr_tx_port_params[SWR_UC_MAX];
  110. struct regulator_bulk_data *supplies;
  111. struct notifier_block nblock;
  112. /* wcd callback to bolero */
  113. void *handle;
  114. int (*update_wcd_event)(void *handle, u16 event, u32 data);
  115. int (*register_notifier)(void *handle,
  116. struct notifier_block *nblock,
  117. bool enable);
  118. int (*wakeup)(void *handle, bool enable);
  119. u32 version;
  120. /* Entry for version info */
  121. struct snd_info_entry *entry;
  122. struct snd_info_entry *version_entry;
  123. struct snd_info_entry *variant_entry;
  124. int flyback_cur_det_disable;
  125. int ear_rx_path;
  126. bool dev_up;
  127. u8 tx_master_ch_map[WCD939X_MAX_SLAVE_CH_TYPES];
  128. bool usbc_hs_status;
  129. u8 rx_clk_config;
  130. /* wcd to swr dmic notification */
  131. bool notify_swr_dmic;
  132. struct blocking_notifier_head notifier;
  133. };
  134. struct wcd939x_micbias_setting {
  135. u8 ldoh_v;
  136. u32 cfilt1_mv;
  137. u32 micb1_mv;
  138. u32 micb2_mv;
  139. u32 micb3_mv;
  140. u32 micb4_mv;
  141. u8 bias1_cfilt_sel;
  142. };
  143. struct wcd939x_usbcss_hs_params {
  144. /* Resistance of ground-side internal FET for SBU1 */
  145. u32 r_gnd_sbu1_int_fet_mohms;
  146. /* Resistance of ground-side internal FET for SBU2 */
  147. u32 r_gnd_sbu2_int_fet_mohms;
  148. /* Customer-characterized resistance for the ground-side external FET */
  149. u32 r_gnd_ext_fet_customer_mohms;
  150. /* SW-computed resistance for the ground-side external FET */
  151. u32 r_gnd_ext_fet_mohms;
  152. /* Total ground-side parasitics between the WCD and external FET */
  153. u32 r_gnd_par_route1_mohms;
  154. /* Total ground-side parasitics between the external FET and connector */
  155. u32 r_gnd_par_route2_mohms;
  156. /* Total ground-side parasitics between the WCD and connector; sum of route1 and route2 */
  157. u32 r_gnd_par_tot_mohms;
  158. /* Total ground-side resistance for SBU1 */
  159. u32 r_gnd_sbu1_res_tot_mohms;
  160. /* Total ground-side resistance for SBU2 */
  161. u32 r_gnd_sbu2_res_tot_mohms;
  162. /* Customer-characterized positive parasitics introduced from the connector */
  163. u32 r_conn_par_load_pos_mohms;
  164. /* Resistance of left audio-side internal FET */
  165. u32 r_aud_int_fet_l_mohms;
  166. /* Resistance of right audio-side internal FET */
  167. u32 r_aud_int_fet_r_mohms;
  168. /* Resistance of left audio-side external FET */
  169. u32 r_aud_ext_fet_l_mohms;
  170. /* Resistance of right audio-side external FET */
  171. u32 r_aud_ext_fet_r_mohms;
  172. /* Total left audio-side resistance */
  173. u32 r_aud_res_tot_l_mohms;
  174. /* Total right audio-side resistance */
  175. u32 r_aud_res_tot_r_mohms;
  176. /* Surge switch resistance */
  177. u32 r_surge_mohms;
  178. /* Sum of left audio-side parasitics and the left side of the load */
  179. u32 r_load_eff_l_mohms;
  180. /* Sum of right audio-side parasitics and the right side of the load */
  181. u32 r_load_eff_r_mohms;
  182. /* Customer-characterized audio-side parasitics between the WCD and external FET,
  183. * in milliohms
  184. */
  185. u32 r3;
  186. /* Customer-characterized ground-side parasitics between the external FET and connector,
  187. * in milliohms
  188. */
  189. u32 r4;
  190. /* For digital crosstalk with remote sensed analog crosstalk mode, customer-characterized
  191. * ground path parasitic resistance between the WCD SBU pin and the external MOSFET,
  192. * in milliohms
  193. */
  194. u32 r5;
  195. /* For digital crosstalk with local sensed analog crosstalk mode, customer-characterized
  196. * ground path parasitic resistance between the WCD GSBU tap point and the external MOSFET,
  197. * in milliohms
  198. */
  199. u32 r6;
  200. /* For digital crosstalk with local sensed analog crosstalk mode, customer-characterized
  201. * ground path parasitic resistance between the WCD GSBU tap point and the WCD SBU pin,
  202. * in milliohms
  203. */
  204. u32 r7;
  205. /* Tap out linearizer constant for the audio path, multiplied by 100 from the original
  206. * constants to support decimal values up to the hundredth place
  207. */
  208. s32 k_aud_times_100;
  209. /* Tap out linearizer constant for the ground path, multiplied by 100 from the original
  210. * constants to support decimal values up to the hundredth place
  211. */
  212. s32 k_gnd_times_100;
  213. /* Fixed offset to be applied to audio taps */
  214. s32 aud_tap_offset;
  215. /* Fixed offset to be applied to ground taps */
  216. s32 gnd_tap_offset;
  217. /* Computed optimal d-xtalk left-side scale value */
  218. u8 scale_l;
  219. /* Computed optimal d-xtalk left-side alpha value */
  220. u8 alpha_l;
  221. /* Computed optimal d-xtalk right-side scale value */
  222. u8 scale_r;
  223. /* Computed optimal d-xtalk right-side alpha value */
  224. u8 alpha_r;
  225. /* Customer-tuned configuration for d-xtalk:
  226. * 0 for digital crosstalk disabled,
  227. * 1 for digital crosstalk with local sensed a-xtalk enabled, and
  228. * 2 for digital crosstalk with remote sensed a-xtalk enabled.
  229. */
  230. enum xtalk_mode xtalk_config;
  231. };
  232. struct wcd939x_pdata {
  233. struct device_node *rst_np;
  234. struct device_node *rx_slave;
  235. struct device_node *tx_slave;
  236. struct wcd939x_micbias_setting micbias;
  237. struct wcd939x_usbcss_hs_params usbcss_hs;
  238. struct cdc_regulator *regulator;
  239. int num_supplies;
  240. };
  241. struct wcd_ctrl_platform_data {
  242. void *handle;
  243. int (*update_wcd_event)(void *handle, u16 event, u32 data);
  244. int (*register_notifier)(void *handle,
  245. struct notifier_block *nblock,
  246. bool enable);
  247. };
  248. enum {
  249. WCD_RX1,
  250. WCD_RX2,
  251. WCD_RX3
  252. };
  253. enum {
  254. /* INTR_CTRL_INT_MASK_0 */
  255. WCD939X_IRQ_MBHC_BUTTON_PRESS_DET = 0,
  256. WCD939X_IRQ_MBHC_BUTTON_RELEASE_DET,
  257. WCD939X_IRQ_MBHC_ELECT_INS_REM_DET,
  258. WCD939X_IRQ_MBHC_ELECT_INS_REM_LEG_DET,
  259. WCD939X_IRQ_MBHC_SW_DET,
  260. WCD939X_IRQ_HPHR_OCP_INT,
  261. WCD939X_IRQ_HPHR_CNP_INT,
  262. WCD939X_IRQ_HPHL_OCP_INT,
  263. /* INTR_CTRL_INT_MASK_1 */
  264. WCD939X_IRQ_HPHL_CNP_INT,
  265. WCD939X_IRQ_EAR_CNP_INT,
  266. WCD939X_IRQ_EAR_SCD_INT,
  267. WCD939X_IRQ_HPHL_PDM_WD_INT,
  268. WCD939X_IRQ_HPHR_PDM_WD_INT,
  269. WCD939X_IRQ_EAR_PDM_WD_INT,
  270. /* INTR_CTRL_INT_MASK_2 */
  271. WCD939X_IRQ_MBHC_MOISTURE_INT,
  272. WCD939X_IRQ_HPHL_SURGE_DET_INT,
  273. WCD939X_IRQ_HPHR_SURGE_DET_INT,
  274. WCD939X_NUM_IRQS,
  275. };
  276. extern struct wcd939x_mbhc *wcd939x_soc_get_mbhc(
  277. struct snd_soc_component *component);
  278. extern void wcd939x_disable_bcs_before_slow_insert(
  279. struct snd_soc_component *component,
  280. bool bcs_disable);
  281. extern int wcd939x_mbhc_micb_adjust_voltage(struct snd_soc_component *component,
  282. int volt, int micb_num);
  283. extern int wcd939x_get_micb_vout_ctl_val(u32 micb_mv);
  284. extern int wcd939x_micbias_control(struct snd_soc_component *component,
  285. int micb_num, int req, bool is_dapm);
  286. #endif /* _WCD939X_INTERNAL_H */