wcd-mbhc-v2.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __WCD_MBHC_V2_H__
  3. #define __WCD_MBHC_V2_H__
  4. #include <sound/jack.h>
  5. #define WCD_MBHC_FIELD(id, rreg, rmask) \
  6. [id] = { .reg = rreg, .mask = rmask }
  7. enum wcd_mbhc_field_function {
  8. WCD_MBHC_L_DET_EN,
  9. WCD_MBHC_GND_DET_EN,
  10. WCD_MBHC_MECH_DETECTION_TYPE,
  11. WCD_MBHC_MIC_CLAMP_CTL,
  12. WCD_MBHC_ELECT_DETECTION_TYPE,
  13. WCD_MBHC_HS_L_DET_PULL_UP_CTRL,
  14. WCD_MBHC_HS_L_DET_PULL_UP_COMP_CTRL,
  15. WCD_MBHC_HPHL_PLUG_TYPE,
  16. WCD_MBHC_GND_PLUG_TYPE,
  17. WCD_MBHC_SW_HPH_LP_100K_TO_GND,
  18. WCD_MBHC_ELECT_SCHMT_ISRC,
  19. WCD_MBHC_FSM_EN,
  20. WCD_MBHC_INSREM_DBNC,
  21. WCD_MBHC_BTN_DBNC,
  22. WCD_MBHC_HS_VREF,
  23. WCD_MBHC_HS_COMP_RESULT,
  24. WCD_MBHC_IN2P_CLAMP_STATE,
  25. WCD_MBHC_MIC_SCHMT_RESULT,
  26. WCD_MBHC_HPHL_SCHMT_RESULT,
  27. WCD_MBHC_HPHR_SCHMT_RESULT,
  28. WCD_MBHC_OCP_FSM_EN,
  29. WCD_MBHC_BTN_RESULT,
  30. WCD_MBHC_BTN_ISRC_CTL,
  31. WCD_MBHC_ELECT_RESULT,
  32. WCD_MBHC_MICB_CTRL, /* Pull-up and micb control */
  33. WCD_MBHC_HPH_CNP_WG_TIME,
  34. WCD_MBHC_HPHR_PA_EN,
  35. WCD_MBHC_HPHL_PA_EN,
  36. WCD_MBHC_HPH_PA_EN,
  37. WCD_MBHC_SWCH_LEVEL_REMOVE,
  38. WCD_MBHC_PULLDOWN_CTRL,
  39. WCD_MBHC_ANC_DET_EN,
  40. WCD_MBHC_FSM_STATUS,
  41. WCD_MBHC_MUX_CTL,
  42. WCD_MBHC_MOISTURE_STATUS,
  43. WCD_MBHC_HPHR_GND,
  44. WCD_MBHC_HPHL_GND,
  45. WCD_MBHC_HPHL_OCP_DET_EN,
  46. WCD_MBHC_HPHR_OCP_DET_EN,
  47. WCD_MBHC_HPHL_OCP_STATUS,
  48. WCD_MBHC_HPHR_OCP_STATUS,
  49. WCD_MBHC_ADC_EN,
  50. WCD_MBHC_ADC_COMPLETE,
  51. WCD_MBHC_ADC_TIMEOUT,
  52. WCD_MBHC_ADC_RESULT,
  53. WCD_MBHC_MICB2_VOUT,
  54. WCD_MBHC_ADC_MODE,
  55. WCD_MBHC_DETECTION_DONE,
  56. WCD_MBHC_ELECT_ISRC_EN,
  57. WCD_MBHC_REG_FUNC_MAX,
  58. };
  59. #define WCD_MBHC_DEF_BUTTONS 8
  60. #define WCD_MBHC_KEYCODE_NUM 8
  61. #define WCD_MBHC_USLEEP_RANGE_MARGIN_US 100
  62. #define WCD_MBHC_THR_HS_MICB_MV 2700
  63. #define WCD_MONO_HS_MIN_THR 2
  64. enum wcd_mbhc_detect_logic {
  65. WCD_DETECTION_LEGACY,
  66. WCD_DETECTION_ADC,
  67. };
  68. enum wcd_mbhc_cs_mb_en_flag {
  69. WCD_MBHC_EN_CS = 0,
  70. WCD_MBHC_EN_MB,
  71. WCD_MBHC_EN_PULLUP,
  72. WCD_MBHC_EN_NONE,
  73. };
  74. enum {
  75. WCD_MBHC_ELEC_HS_INS,
  76. WCD_MBHC_ELEC_HS_REM,
  77. };
  78. enum wcd_mbhc_plug_type {
  79. MBHC_PLUG_TYPE_INVALID = -1,
  80. MBHC_PLUG_TYPE_NONE,
  81. MBHC_PLUG_TYPE_HEADSET,
  82. MBHC_PLUG_TYPE_HEADPHONE,
  83. MBHC_PLUG_TYPE_HIGH_HPH,
  84. MBHC_PLUG_TYPE_GND_MIC_SWAP,
  85. };
  86. enum pa_dac_ack_flags {
  87. WCD_MBHC_HPHL_PA_OFF_ACK = 0,
  88. WCD_MBHC_HPHR_PA_OFF_ACK,
  89. };
  90. enum wcd_mbhc_btn_det_mem {
  91. WCD_MBHC_BTN_DET_V_BTN_LOW,
  92. WCD_MBHC_BTN_DET_V_BTN_HIGH
  93. };
  94. enum {
  95. MIC_BIAS_1 = 1,
  96. MIC_BIAS_2,
  97. MIC_BIAS_3,
  98. MIC_BIAS_4
  99. };
  100. enum {
  101. MICB_PULLUP_ENABLE,
  102. MICB_PULLUP_DISABLE,
  103. MICB_ENABLE,
  104. MICB_DISABLE,
  105. };
  106. enum wcd_notify_event {
  107. WCD_EVENT_INVALID,
  108. /* events for micbias ON and OFF */
  109. WCD_EVENT_PRE_MICBIAS_2_OFF,
  110. WCD_EVENT_POST_MICBIAS_2_OFF,
  111. WCD_EVENT_PRE_MICBIAS_2_ON,
  112. WCD_EVENT_POST_MICBIAS_2_ON,
  113. WCD_EVENT_PRE_DAPM_MICBIAS_2_OFF,
  114. WCD_EVENT_POST_DAPM_MICBIAS_2_OFF,
  115. WCD_EVENT_PRE_DAPM_MICBIAS_2_ON,
  116. WCD_EVENT_POST_DAPM_MICBIAS_2_ON,
  117. /* events for PA ON and OFF */
  118. WCD_EVENT_PRE_HPHL_PA_ON,
  119. WCD_EVENT_POST_HPHL_PA_OFF,
  120. WCD_EVENT_PRE_HPHR_PA_ON,
  121. WCD_EVENT_POST_HPHR_PA_OFF,
  122. WCD_EVENT_PRE_HPHL_PA_OFF,
  123. WCD_EVENT_PRE_HPHR_PA_OFF,
  124. WCD_EVENT_OCP_OFF,
  125. WCD_EVENT_OCP_ON,
  126. WCD_EVENT_LAST,
  127. };
  128. enum wcd_mbhc_event_state {
  129. WCD_MBHC_EVENT_PA_HPHL,
  130. WCD_MBHC_EVENT_PA_HPHR,
  131. };
  132. enum wcd_mbhc_hph_type {
  133. WCD_MBHC_HPH_NONE = 0,
  134. WCD_MBHC_HPH_MONO,
  135. WCD_MBHC_HPH_STEREO,
  136. };
  137. /*
  138. * These enum definitions are directly mapped to the register
  139. * definitions
  140. */
  141. enum mbhc_hs_pullup_iref {
  142. I_DEFAULT = -1,
  143. I_OFF = 0,
  144. I_1P0_UA,
  145. I_2P0_UA,
  146. I_3P0_UA,
  147. };
  148. enum mbhc_hs_pullup_iref_v2 {
  149. HS_PULLUP_I_DEFAULT = -1,
  150. HS_PULLUP_I_3P0_UA = 0,
  151. HS_PULLUP_I_2P25_UA,
  152. HS_PULLUP_I_1P5_UA,
  153. HS_PULLUP_I_0P75_UA,
  154. HS_PULLUP_I_1P125_UA = 0x05,
  155. HS_PULLUP_I_0P375_UA = 0x07,
  156. HS_PULLUP_I_2P0_UA,
  157. HS_PULLUP_I_1P0_UA = 0x0A,
  158. HS_PULLUP_I_0P5_UA,
  159. HS_PULLUP_I_0P25_UA = 0x0F,
  160. HS_PULLUP_I_0P125_UA = 0x17,
  161. HS_PULLUP_I_OFF,
  162. };
  163. enum mbhc_moisture_rref {
  164. R_OFF,
  165. R_24_KOHM,
  166. R_84_KOHM,
  167. R_184_KOHM,
  168. };
  169. struct wcd_mbhc_config {
  170. int btn_high[WCD_MBHC_DEF_BUTTONS];
  171. int btn_low[WCD_MBHC_DEF_BUTTONS];
  172. int v_hs_max;
  173. int num_btn;
  174. bool mono_stero_detection;
  175. bool (*swap_gnd_mic)(struct snd_soc_component *component, bool active);
  176. bool hs_ext_micbias;
  177. bool gnd_det_en;
  178. uint32_t linein_th;
  179. bool moisture_en;
  180. int mbhc_micbias;
  181. int anc_micbias;
  182. bool moisture_duty_cycle_en;
  183. bool hphl_swh; /*track HPHL switch NC / NO */
  184. bool gnd_swh; /*track GND switch NC / NO */
  185. u32 hs_thr;
  186. u32 hph_thr;
  187. u32 micb_mv;
  188. u32 moist_vref;
  189. u32 moist_iref;
  190. u32 moist_rref;
  191. };
  192. struct wcd_mbhc_intr {
  193. int mbhc_sw_intr;
  194. int mbhc_btn_press_intr;
  195. int mbhc_btn_release_intr;
  196. int mbhc_hs_ins_intr;
  197. int mbhc_hs_rem_intr;
  198. int hph_left_ocp;
  199. int hph_right_ocp;
  200. };
  201. struct wcd_mbhc_field {
  202. u16 reg;
  203. u8 mask;
  204. };
  205. struct wcd_mbhc;
  206. struct wcd_mbhc_cb {
  207. void (*update_cross_conn_thr)(struct snd_soc_component *component);
  208. void (*get_micbias_val)(struct snd_soc_component *component, int *mb);
  209. void (*bcs_enable)(struct snd_soc_component *component, bool bcs_enable);
  210. void (*compute_impedance)(struct snd_soc_component *component,
  211. uint32_t *zl, uint32_t *zr);
  212. void (*set_micbias_value)(struct snd_soc_component *component);
  213. void (*set_auto_zeroing)(struct snd_soc_component *component,
  214. bool enable);
  215. void (*clk_setup)(struct snd_soc_component *component, bool enable);
  216. bool (*micbias_enable_status)(struct snd_soc_component *component, int micb_num);
  217. void (*mbhc_bias)(struct snd_soc_component *component, bool enable);
  218. void (*set_btn_thr)(struct snd_soc_component *component,
  219. int *btn_low, int *btn_high,
  220. int num_btn, bool is_micbias);
  221. void (*hph_pull_up_control)(struct snd_soc_component *component,
  222. enum mbhc_hs_pullup_iref);
  223. int (*mbhc_micbias_control)(struct snd_soc_component *component,
  224. int micb_num, int req);
  225. void (*mbhc_micb_ramp_control)(struct snd_soc_component *component,
  226. bool enable);
  227. bool (*extn_use_mb)(struct snd_soc_component *component);
  228. int (*mbhc_micb_ctrl_thr_mic)(struct snd_soc_component *component,
  229. int micb_num, bool req_en);
  230. void (*mbhc_gnd_det_ctrl)(struct snd_soc_component *component,
  231. bool enable);
  232. void (*hph_pull_down_ctrl)(struct snd_soc_component *component,
  233. bool enable);
  234. void (*mbhc_moisture_config)(struct snd_soc_component *component);
  235. void (*update_anc_state)(struct snd_soc_component *component,
  236. bool enable, int anc_num);
  237. void (*hph_pull_up_control_v2)(struct snd_soc_component *component,
  238. int pull_up_cur);
  239. bool (*mbhc_get_moisture_status)(struct snd_soc_component *component);
  240. void (*mbhc_moisture_polling_ctrl)(struct snd_soc_component *component, bool enable);
  241. void (*mbhc_moisture_detect_en)(struct snd_soc_component *component, bool enable);
  242. };
  243. #if IS_ENABLED(CONFIG_SND_SOC_WCD_MBHC)
  244. int wcd_dt_parse_mbhc_data(struct device *dev, struct wcd_mbhc_config *cfg);
  245. int wcd_mbhc_start(struct wcd_mbhc *mbhc, struct wcd_mbhc_config *mbhc_cfg,
  246. struct snd_soc_jack *jack);
  247. void wcd_mbhc_stop(struct wcd_mbhc *mbhc);
  248. void wcd_mbhc_set_hph_type(struct wcd_mbhc *mbhc, int hph_type);
  249. int wcd_mbhc_get_hph_type(struct wcd_mbhc *mbhc);
  250. struct wcd_mbhc *wcd_mbhc_init(struct snd_soc_component *component,
  251. const struct wcd_mbhc_cb *mbhc_cb,
  252. const struct wcd_mbhc_intr *mbhc_cdc_intr_ids,
  253. struct wcd_mbhc_field *fields,
  254. bool impedance_det_en);
  255. int wcd_mbhc_get_impedance(struct wcd_mbhc *mbhc, uint32_t *zl,
  256. uint32_t *zr);
  257. void wcd_mbhc_deinit(struct wcd_mbhc *mbhc);
  258. int wcd_mbhc_event_notify(struct wcd_mbhc *mbhc, unsigned long event);
  259. #else
  260. static inline int wcd_dt_parse_mbhc_data(struct device *dev,
  261. struct wcd_mbhc_config *cfg)
  262. {
  263. return -ENOTSUPP;
  264. }
  265. static inline void wcd_mbhc_stop(struct wcd_mbhc *mbhc)
  266. {
  267. }
  268. static inline struct wcd_mbhc *wcd_mbhc_init(struct snd_soc_component *component,
  269. const struct wcd_mbhc_cb *mbhc_cb,
  270. const struct wcd_mbhc_intr *mbhc_cdc_intr_ids,
  271. struct wcd_mbhc_field *fields,
  272. bool impedance_det_en)
  273. {
  274. return ERR_PTR(-ENOTSUPP);
  275. }
  276. static inline void wcd_mbhc_set_hph_type(struct wcd_mbhc *mbhc, int hph_type)
  277. {
  278. }
  279. static inline int wcd_mbhc_get_hph_type(struct wcd_mbhc *mbhc)
  280. {
  281. return -ENOTSUPP;
  282. }
  283. static inline int wcd_mbhc_event_notify(struct wcd_mbhc *mbhc, unsigned long event)
  284. {
  285. return -ENOTSUPP;
  286. }
  287. static inline int wcd_mbhc_start(struct wcd_mbhc *mbhc,
  288. struct wcd_mbhc_config *mbhc_cfg,
  289. struct snd_soc_jack *jack)
  290. {
  291. return 0;
  292. }
  293. static inline int wcd_mbhc_get_impedance(struct wcd_mbhc *mbhc,
  294. uint32_t *zl,
  295. uint32_t *zr)
  296. {
  297. *zl = 0;
  298. *zr = 0;
  299. return -EINVAL;
  300. }
  301. static inline void wcd_mbhc_deinit(struct wcd_mbhc *mbhc)
  302. {
  303. }
  304. #endif
  305. #endif /* __WCD_MBHC_V2_H__ */