internal.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2018-2020, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #ifndef _WCD9378_INTERNAL_H
  7. #define _WCD9378_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 "wcd9378-mbhc.h"
  13. #include "wcd9378.h"
  14. #define SWR_SCP_CONTROL 0x44
  15. #define SWR_SCP_HOST_CLK_DIV2_CTL_BANK 0xE0
  16. #define WCD9378_MAX_MICBIAS 3
  17. #define SIM_MIC_NUM 3
  18. /* Convert from vout ctl to micbias voltage in mV */
  19. #define WCD_VOUT_CTL_TO_MICB(v) (1000 + v * 50)
  20. #define MAX_PORT 8
  21. #define MAX_CH_PER_PORT 8
  22. #define TX_ADC_MAX 3
  23. #define SWR_NUM_PORTS 4
  24. enum {
  25. TX_HDR12 = 0,
  26. TX_HDR34,
  27. TX_HDR_MAX,
  28. };
  29. enum {
  30. SIM_MIC0,
  31. SIM_MIC1,
  32. SIM_MIC2,
  33. SIM_JACK,
  34. MICB_VAL_NUM,
  35. };
  36. extern struct regmap_config wcd9378_regmap_config;
  37. struct codec_port_info {
  38. u32 slave_port_type;
  39. u32 master_port_type;
  40. u32 ch_mask;
  41. u32 num_ch;
  42. u32 ch_rate;
  43. };
  44. enum {
  45. RX_CLK_9P6MHZ,
  46. RX_CLK_12P288MHZ,
  47. RX_CLK_11P2896MHZ,
  48. };
  49. enum {
  50. RX_PATH,
  51. TX_PATH,
  52. };
  53. struct wcd9378_priv {
  54. struct device *dev;
  55. u32 sys_usage;
  56. /* to track the sys_usage status */
  57. unsigned long sys_usage_status;
  58. u32 wcd_mode;
  59. int variant;
  60. struct snd_soc_component *component;
  61. struct device_node *rst_np;
  62. struct regmap *regmap;
  63. struct swr_device *rx_swr_dev;
  64. struct swr_device *tx_swr_dev;
  65. s32 micb_ref[WCD9378_MAX_MICBIAS];
  66. s32 pullup_ref[WCD9378_MAX_MICBIAS];
  67. u32 micb_sel[SIM_MIC_NUM];
  68. u32 micb_val[MICB_VAL_NUM];
  69. struct device_node *wcd_rst_np;
  70. struct mutex micb_lock;
  71. struct mutex wakeup_lock;
  72. struct mutex sys_usage_lock;
  73. s32 dmic_0_1_clk_cnt;
  74. s32 dmic_2_3_clk_cnt;
  75. s32 dmic_4_5_clk_cnt;
  76. int hdr_en[TX_HDR_MAX];
  77. /* class h specific info */
  78. struct wcd_clsh_cdc_info clsh_info;
  79. /* mbhc module */
  80. struct wcd9378_mbhc *mbhc;
  81. u32 hph_mode;
  82. u16 hph_gain;
  83. u32 curr_micbias2;
  84. u32 rx2_clk_mode;
  85. u32 tx_mode[TX_ADC_MAX];
  86. s32 adc_count;
  87. bool comp1_enable;
  88. bool comp2_enable;
  89. bool ldoh;
  90. bool bcs_dis;
  91. bool dapm_bias_off;
  92. struct irq_domain *virq;
  93. struct wcd_irq_info irq_info;
  94. u32 rx_clk_cnt;
  95. int num_irq_regs;
  96. /* to track the status */
  97. unsigned long status_mask;
  98. u8 num_tx_ports;
  99. u8 num_rx_ports;
  100. struct codec_port_info
  101. tx_port_mapping[MAX_PORT][MAX_CH_PER_PORT];
  102. struct codec_port_info
  103. rx_port_mapping[MAX_PORT][MAX_CH_PER_PORT];
  104. struct swr_port_params tx_port_params[SWR_UC_MAX][SWR_NUM_PORTS];
  105. struct swr_dev_frame_config swr_tx_port_params[SWR_UC_MAX];
  106. struct regulator_bulk_data *supplies;
  107. struct notifier_block nblock;
  108. /* wcd callback to bolero */
  109. void *handle;
  110. int (*update_wcd_event)(void *handle, u16 event, u32 data);
  111. int (*register_notifier)(void *handle,
  112. struct notifier_block *nblock,
  113. bool enable);
  114. int (*wakeup)(void *handle, bool enable);
  115. u32 version;
  116. /* Entry for version info */
  117. struct snd_info_entry *entry;
  118. struct snd_info_entry *version_entry;
  119. struct snd_info_entry *variant_entry;
  120. int flyback_cur_det_disable;
  121. u8 tx_master_ch_map[WCD9378_MAX_SLAVE_CH_TYPES];
  122. bool usbc_hs_status;
  123. /* wcd to swr dmic notification */
  124. bool notify_swr_dmic;
  125. u8 swr_base_clk;
  126. u8 swr_clk_scale;
  127. struct blocking_notifier_head notifier;
  128. };
  129. struct wcd9378_micbias_setting {
  130. u8 ldoh_v;
  131. u32 cfilt1_mv;
  132. u32 micb1_mv;
  133. u32 micb2_mv;
  134. u32 micb3_mv;
  135. u32 micb1_usage_val;
  136. u32 micb2_usage_val;
  137. u32 micb3_usage_val;
  138. u8 bias1_cfilt_sel;
  139. };
  140. struct wcd9378_pdata {
  141. struct device_node *rst_np;
  142. struct device_node *rx_slave;
  143. struct device_node *tx_slave;
  144. struct wcd9378_micbias_setting micbias;
  145. struct cdc_regulator *regulator;
  146. int num_supplies;
  147. };
  148. struct wcd_ctrl_platform_data {
  149. void *handle;
  150. int (*update_wcd_event)(void *handle, u16 event, u32 data);
  151. int (*register_notifier)(void *handle,
  152. struct notifier_block *nblock,
  153. bool enable);
  154. };
  155. enum {
  156. WCD_RX1,
  157. WCD_RX2,
  158. WCD_RX3
  159. };
  160. enum {
  161. /* INTR_CTRL_INT_MASK_0 */
  162. WCD9378_IRQ_MBHC_BUTTON_PRESS_DET = 0,
  163. WCD9378_IRQ_MBHC_BUTTON_RELEASE_DET,
  164. WCD9378_IRQ_MBHC_ELECT_INS_REM_DET,
  165. WCD9378_IRQ_MBHC_ELECT_INS_REM_LEG_DET,
  166. WCD9378_IRQ_MBHC_SW_DET,
  167. WCD9378_IRQ_HPHR_OCP_INT,
  168. WCD9378_IRQ_HPHR_CNP_INT,
  169. WCD9378_IRQ_HPHL_OCP_INT,
  170. /* INTR_CTRL_INT_MASK_1 */
  171. WCD9378_IRQ_HPHL_CNP_INT,
  172. WCD9378_IRQ_EAR_CNP_INT,
  173. WCD9378_IRQ_EAR_SCD_INT,
  174. WCD9378_IRQ_AUX_CNP_INT,
  175. WCD9378_IRQ_AUX_SCD_INT,
  176. WCD9378_IRQ_HPHL_PDM_WD_INT,
  177. WCD9378_IRQ_HPHR_PDM_WD_INT,
  178. WCD9378_IRQ_AUX_PDM_WD_INT,
  179. /* INTR_CTRL_INT_MASK_2 */
  180. WCD9378_IRQ_LDORT_SCD_INT,
  181. WCD9378_IRQ_MBHC_MOISTURE_INT,
  182. WCD9378_IRQ_HPHL_SURGE_DET_INT,
  183. WCD9378_IRQ_HPHR_SURGE_DET_INT,
  184. WCD9378_IRQ_SAPU_PROT_MODE_CHG,
  185. WCD9378_NUM_IRQS,
  186. };
  187. extern struct wcd9378_mbhc *wcd9378_soc_get_mbhc(
  188. struct snd_soc_component *component);
  189. extern void wcd9378_disable_bcs_before_slow_insert(
  190. struct snd_soc_component *component,
  191. bool bcs_disable);
  192. extern int wcd9378_mbhc_micb_adjust_voltage(struct snd_soc_component *component,
  193. int volt, int micb_num);
  194. extern int wcd9378_get_micb_vout_ctl_val(u32 micb_mv);
  195. extern int wcd9378_micbias_control(struct snd_soc_component *component,
  196. int micb_num, int req, bool is_dapm);
  197. #endif /* _WCD9378_INTERNAL_H */