wcd-mbhc-v2.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /* Copyright (c) 2014-2021, The Linux Foundation. All rights reserved.
  3. * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
  4. */
  5. #ifndef __WCD_MBHC_V2_H__
  6. #define __WCD_MBHC_V2_H__
  7. #include <linux/wait.h>
  8. #include <linux/stringify.h>
  9. #include <linux/power_supply.h>
  10. #include <linux/extcon.h>
  11. #include <linux/extcon-provider.h>
  12. #include "wcdcal-hwdep.h"
  13. #include <sound/jack.h>
  14. #define TOMBAK_MBHC_NC 0
  15. #define TOMBAK_MBHC_NO 1
  16. #define WCD_MBHC_DEF_BUTTONS 8
  17. #define WCD_MBHC_KEYCODE_NUM 8
  18. #define WCD_MBHC_USLEEP_RANGE_MARGIN_US 100
  19. #define WCD_MBHC_THR_HS_MICB_MV 2700
  20. /* z value defined in Ohms */
  21. #define WCD_MONO_HS_MIN_THR 2
  22. #define WCD_MBHC_STRINGIFY(s) __stringify(s)
  23. #define WCD_MBHC_REGISTER(rid, rreg, rmask, rshift, rinvert) \
  24. { .id = rid, .reg = rreg, .mask = rmask, .offset = rshift, .invert = rinvert }
  25. #define WCD_MBHC_RSC_LOCK(mbhc) \
  26. { \
  27. pr_debug("%s: Acquiring BCL\n", __func__); \
  28. mutex_lock(&mbhc->codec_resource_lock); \
  29. pr_debug("%s: Acquiring BCL done\n", __func__); \
  30. }
  31. #define WCD_MBHC_RSC_UNLOCK(mbhc) \
  32. { \
  33. pr_debug("%s: Release BCL\n", __func__); \
  34. mutex_unlock(&mbhc->codec_resource_lock); \
  35. }
  36. #define WCD_MBHC_RSC_ASSERT_LOCKED(mbhc) \
  37. { \
  38. WARN_ONCE(!mutex_is_locked(&mbhc->codec_resource_lock), \
  39. "%s: BCL should have acquired\n", __func__); \
  40. }
  41. /*
  42. * Macros to update and read mbhc register bits. Check for
  43. * "0" before updating or reading the register, because it
  44. * is possible that one codec wants to write to that bit and
  45. * other codec does not.
  46. */
  47. #define WCD_MBHC_REG_UPDATE_BITS(function, val) \
  48. do { \
  49. if (mbhc->wcd_mbhc_regs[function].reg) { \
  50. snd_soc_component_update_bits(mbhc->component, \
  51. mbhc->wcd_mbhc_regs[function].reg, \
  52. mbhc->wcd_mbhc_regs[function].mask, \
  53. val << (mbhc->wcd_mbhc_regs[function].offset)); \
  54. } \
  55. } while (0)
  56. #define WCD_MBHC_REG_READ(function, val) \
  57. do { \
  58. if (mbhc->wcd_mbhc_regs[function].reg) { \
  59. val = (((snd_soc_component_read(mbhc->component, \
  60. mbhc->wcd_mbhc_regs[function].reg)) & \
  61. (mbhc->wcd_mbhc_regs[function].mask)) >> \
  62. (mbhc->wcd_mbhc_regs[function].offset)); \
  63. } else { \
  64. val = -EINVAL; \
  65. } \
  66. } while (0)
  67. #define WCD_MBHC_CAL_SIZE(buttons, rload) ( \
  68. sizeof(struct wcd_mbhc_general_cfg) + \
  69. sizeof(struct wcd_mbhc_plug_detect_cfg) + \
  70. ((sizeof(s16) + sizeof(s16)) * buttons) + \
  71. sizeof(struct wcd_mbhc_plug_type_cfg) + \
  72. sizeof(struct wcd_mbhc_btn_detect_cfg) + \
  73. sizeof(struct wcd_mbhc_imped_detect_cfg) + \
  74. ((sizeof(u16) + sizeof(u16)) * rload) \
  75. )
  76. #define WCD_MBHC_CAL_GENERAL_PTR(cali) ( \
  77. (struct wcd_mbhc_general_cfg *) cali)
  78. #define WCD_MBHC_CAL_PLUG_DET_PTR(cali) ( \
  79. (struct wcd_mbhc_plug_detect_cfg *) \
  80. &(WCD_MBHC_CAL_GENERAL_PTR(cali)[1]))
  81. #define WCD_MBHC_CAL_PLUG_TYPE_PTR(cali) ( \
  82. (struct wcd_mbhc_plug_type_cfg *) \
  83. &(WCD_MBHC_CAL_PLUG_DET_PTR(cali)[1]))
  84. #define WCD_MBHC_CAL_BTN_DET_PTR(cali) ( \
  85. (struct wcd_mbhc_btn_detect_cfg *) \
  86. &(WCD_MBHC_CAL_PLUG_TYPE_PTR(cali)[1]))
  87. #define WCD_MBHC_CAL_IMPED_DET_PTR(cali) ( \
  88. (struct wcd_mbhc_imped_detect_cfg *) \
  89. (((void *)&WCD_MBHC_CAL_BTN_DET_PTR(cali)[1]) + \
  90. (WCD_MBHC_CAL_BTN_DET_PTR(cali)->num_btn * \
  91. (sizeof(WCD_MBHC_CAL_BTN_DET_PTR(cali)->_v_btn_low[0]) + \
  92. sizeof(WCD_MBHC_CAL_BTN_DET_PTR(cali)->_v_btn_high[0])))) \
  93. )
  94. #define WCD_MBHC_CAL_MIN_SIZE ( \
  95. sizeof(struct wcd_mbhc_general_cfg) + \
  96. sizeof(struct wcd_mbhc_plug_detect_cfg) + \
  97. sizeof(struct wcd_mbhc_plug_type_cfg) + \
  98. sizeof(struct wcd_mbhc_btn_detect_cfg) + \
  99. sizeof(struct wcd_mbhc_imped_detect_cfg) + \
  100. (sizeof(u16)*2) \
  101. )
  102. #define WCD_MBHC_CAL_BTN_SZ(cfg_ptr) ( \
  103. sizeof(struct wcd_mbhc_btn_detect_cfg) + \
  104. (cfg_ptr->num_btn * (sizeof(cfg_ptr->_v_btn_low[0]) + \
  105. sizeof(cfg_ptr->_v_btn_high[0]))))
  106. #define WCD_MBHC_CAL_IMPED_MIN_SZ ( \
  107. sizeof(struct wcd_mbhc_imped_detect_cfg) + sizeof(u16) * 2)
  108. #define WCD_MBHC_CAL_IMPED_SZ(cfg_ptr) ( \
  109. sizeof(struct wcd_mbhc_imped_detect_cfg) + \
  110. (cfg_ptr->_n_rload * \
  111. (sizeof(cfg_ptr->_rload[0]) + sizeof(cfg_ptr->_alpha[0]))))
  112. #if IS_ENABLED(CONFIG_AUDIO_QGKI)
  113. #define WCD_MBHC_JACK_MASK (SND_JACK_HEADSET | SND_JACK_OC_HPHL | \
  114. SND_JACK_OC_HPHR | SND_JACK_LINEOUT | \
  115. SND_JACK_MECHANICAL | \
  116. SND_JACK_UNSUPPORTED)
  117. #else
  118. #define WCD_MBHC_JACK_MASK (SND_JACK_HEADSET | SND_JACK_LINEOUT | \
  119. SND_JACK_MECHANICAL)
  120. #endif /* CONFIG_AUDIO_QGKI */
  121. #define WCD_MBHC_JACK_BUTTON_MASK (SND_JACK_BTN_0 | SND_JACK_BTN_1 | \
  122. SND_JACK_BTN_2 | SND_JACK_BTN_3 | \
  123. SND_JACK_BTN_4 | SND_JACK_BTN_5)
  124. #define OCP_ATTEMPT 20
  125. #define HS_DETECT_PLUG_TIME_MS (3 * 1000)
  126. #define SPECIAL_HS_DETECT_TIME_MS (2 * 1000)
  127. #define MBHC_BUTTON_PRESS_THRESHOLD_MIN 250
  128. #define GND_MIC_SWAP_THRESHOLD 4
  129. #define GND_MIC_USBC_SWAP_THRESHOLD 2
  130. #define WCD_FAKE_REMOVAL_MIN_PERIOD_MS 100
  131. #define HS_VREF_MIN_VAL 1400
  132. #define FW_READ_ATTEMPTS 15
  133. #define FW_READ_TIMEOUT 4000000
  134. #define FAKE_REM_RETRY_ATTEMPTS 3
  135. #define HPHL_CROSS_CONN_THRESHOLD 100
  136. #define HPHR_CROSS_CONN_THRESHOLD 100
  137. #define WCD_MBHC_BTN_PRESS_COMPL_TIMEOUT_MS 50
  138. #define ANC_DETECT_RETRY_CNT 7
  139. #define WCD_MBHC_SPL_HS_CNT 1
  140. enum wcd_mbhc_detect_logic {
  141. WCD_DETECTION_LEGACY,
  142. WCD_DETECTION_ADC,
  143. };
  144. enum wcd_mbhc_cs_mb_en_flag {
  145. WCD_MBHC_EN_CS = 0,
  146. WCD_MBHC_EN_MB,
  147. WCD_MBHC_EN_PULLUP,
  148. WCD_MBHC_EN_NONE,
  149. };
  150. enum {
  151. WCD_MBHC_ELEC_HS_INS,
  152. WCD_MBHC_ELEC_HS_REM,
  153. };
  154. struct wcd_mbhc;
  155. enum wcd_mbhc_register_function {
  156. WCD_MBHC_L_DET_EN,
  157. WCD_MBHC_GND_DET_EN,
  158. WCD_MBHC_MECH_DETECTION_TYPE,
  159. WCD_MBHC_MIC_CLAMP_CTL,
  160. WCD_MBHC_ELECT_DETECTION_TYPE,
  161. WCD_MBHC_HS_L_DET_PULL_UP_CTRL,
  162. WCD_MBHC_HS_L_DET_PULL_UP_COMP_CTRL,
  163. WCD_MBHC_HPHL_PLUG_TYPE,
  164. WCD_MBHC_GND_PLUG_TYPE,
  165. WCD_MBHC_SW_HPH_LP_100K_TO_GND,
  166. WCD_MBHC_ELECT_SCHMT_ISRC,
  167. WCD_MBHC_FSM_EN,
  168. WCD_MBHC_INSREM_DBNC,
  169. WCD_MBHC_BTN_DBNC,
  170. WCD_MBHC_HS_VREF,
  171. WCD_MBHC_HS_COMP_RESULT,
  172. WCD_MBHC_IN2P_CLAMP_STATE,
  173. WCD_MBHC_MIC_SCHMT_RESULT,
  174. WCD_MBHC_HPHL_SCHMT_RESULT,
  175. WCD_MBHC_HPHR_SCHMT_RESULT,
  176. WCD_MBHC_OCP_FSM_EN,
  177. WCD_MBHC_BTN_RESULT,
  178. WCD_MBHC_BTN_ISRC_CTL,
  179. WCD_MBHC_ELECT_RESULT,
  180. WCD_MBHC_MICB_CTRL, /* Pull-up and micb control */
  181. WCD_MBHC_HPH_CNP_WG_TIME,
  182. WCD_MBHC_HPHR_PA_EN,
  183. WCD_MBHC_HPHL_PA_EN,
  184. WCD_MBHC_HPH_PA_EN,
  185. WCD_MBHC_SWCH_LEVEL_REMOVE,
  186. WCD_MBHC_PULLDOWN_CTRL,
  187. WCD_MBHC_ANC_DET_EN,
  188. WCD_MBHC_FSM_STATUS,
  189. WCD_MBHC_MUX_CTL,
  190. WCD_MBHC_MOISTURE_STATUS,
  191. WCD_MBHC_HPHR_GND,
  192. WCD_MBHC_HPHL_GND,
  193. WCD_MBHC_HPHL_OCP_DET_EN,
  194. WCD_MBHC_HPHR_OCP_DET_EN,
  195. WCD_MBHC_HPHL_OCP_STATUS,
  196. WCD_MBHC_HPHR_OCP_STATUS,
  197. WCD_MBHC_ADC_EN,
  198. WCD_MBHC_ADC_COMPLETE,
  199. WCD_MBHC_ADC_TIMEOUT,
  200. WCD_MBHC_ADC_RESULT,
  201. WCD_MBHC_MICB2_VOUT,
  202. WCD_MBHC_ADC_MODE,
  203. WCD_MBHC_DETECTION_DONE,
  204. WCD_MBHC_ELECT_ISRC_EN,
  205. WCD_MBHC_REG_FUNC_MAX,
  206. };
  207. enum wcd_mbhc_plug_type {
  208. MBHC_PLUG_TYPE_INVALID = -1,
  209. MBHC_PLUG_TYPE_NONE,
  210. MBHC_PLUG_TYPE_HEADSET,
  211. MBHC_PLUG_TYPE_HEADPHONE,
  212. MBHC_PLUG_TYPE_HIGH_HPH,
  213. MBHC_PLUG_TYPE_GND_MIC_SWAP,
  214. MBHC_PLUG_TYPE_ANC_HEADPHONE,
  215. };
  216. enum pa_dac_ack_flags {
  217. WCD_MBHC_HPHL_PA_OFF_ACK = 0,
  218. WCD_MBHC_HPHR_PA_OFF_ACK,
  219. };
  220. enum anc_ack_flags {
  221. WCD_MBHC_ANC0_OFF_ACK = 0,
  222. WCD_MBHC_ANC1_OFF_ACK,
  223. };
  224. enum wcd_mbhc_btn_det_mem {
  225. WCD_MBHC_BTN_DET_V_BTN_LOW,
  226. WCD_MBHC_BTN_DET_V_BTN_HIGH
  227. };
  228. enum {
  229. MIC_BIAS_1 = 1,
  230. MIC_BIAS_2,
  231. MIC_BIAS_3,
  232. MIC_BIAS_4
  233. };
  234. enum {
  235. MICB_PULLUP_ENABLE,
  236. MICB_PULLUP_DISABLE,
  237. MICB_ENABLE,
  238. MICB_DISABLE,
  239. };
  240. enum {
  241. MBHC_COMMON_MICB_PRECHARGE,
  242. MBHC_COMMON_MICB_SET_VAL,
  243. MBHC_COMMON_MICB_TAIL_CURR,
  244. };
  245. enum wcd_notify_event {
  246. WCD_EVENT_INVALID,
  247. /* events for micbias ON and OFF */
  248. WCD_EVENT_PRE_MICBIAS_2_OFF,
  249. WCD_EVENT_POST_MICBIAS_2_OFF,
  250. WCD_EVENT_PRE_MICBIAS_2_ON,
  251. WCD_EVENT_POST_MICBIAS_2_ON,
  252. WCD_EVENT_PRE_DAPM_MICBIAS_2_OFF,
  253. WCD_EVENT_POST_DAPM_MICBIAS_2_OFF,
  254. WCD_EVENT_PRE_DAPM_MICBIAS_2_ON,
  255. WCD_EVENT_POST_DAPM_MICBIAS_2_ON,
  256. /* events for PA ON and OFF */
  257. WCD_EVENT_PRE_HPHL_PA_ON,
  258. WCD_EVENT_POST_HPHL_PA_OFF,
  259. WCD_EVENT_PRE_HPHR_PA_ON,
  260. WCD_EVENT_POST_HPHR_PA_OFF,
  261. WCD_EVENT_PRE_HPHL_PA_OFF,
  262. WCD_EVENT_PRE_HPHR_PA_OFF,
  263. WCD_EVENT_OCP_OFF,
  264. WCD_EVENT_OCP_ON,
  265. WCD_EVENT_LAST,
  266. };
  267. enum wcd_mbhc_event_state {
  268. WCD_MBHC_EVENT_PA_HPHL,
  269. WCD_MBHC_EVENT_PA_HPHR,
  270. };
  271. struct wcd_mbhc_general_cfg {
  272. u8 t_ldoh;
  273. u8 t_bg_fast_settle;
  274. u8 t_shutdown_plug_rem;
  275. u8 mbhc_nsa;
  276. u8 mbhc_navg;
  277. u8 v_micbias_l;
  278. u8 v_micbias;
  279. u8 mbhc_reserved;
  280. u16 settle_wait;
  281. u16 t_micbias_rampup;
  282. u16 t_micbias_rampdown;
  283. u16 t_supply_bringup;
  284. } __packed;
  285. struct wcd_mbhc_plug_detect_cfg {
  286. u32 mic_current;
  287. u32 hph_current;
  288. u16 t_mic_pid;
  289. u16 t_ins_complete;
  290. u16 t_ins_retry;
  291. u16 v_removal_delta;
  292. u8 micbias_slow_ramp;
  293. u8 reserved0;
  294. u8 reserved1;
  295. u8 reserved2;
  296. } __packed;
  297. struct wcd_mbhc_plug_type_cfg {
  298. u8 av_detect;
  299. u8 mono_detect;
  300. u8 num_ins_tries;
  301. u8 reserved0;
  302. s16 v_no_mic;
  303. s16 v_av_min;
  304. s16 v_av_max;
  305. s16 v_hs_min;
  306. s16 v_hs_max;
  307. u16 reserved1;
  308. } __packed;
  309. struct wcd_mbhc_btn_detect_cfg {
  310. s8 c[8];
  311. u8 nc;
  312. u8 n_meas;
  313. u8 mbhc_nsc;
  314. u8 n_btn_meas;
  315. u8 n_btn_con;
  316. u8 num_btn;
  317. u8 reserved0;
  318. u8 reserved1;
  319. u16 t_poll;
  320. u16 t_bounce_wait;
  321. u16 t_rel_timeout;
  322. s16 v_btn_press_delta_sta;
  323. s16 v_btn_press_delta_cic;
  324. u16 t_btn0_timeout;
  325. s16 _v_btn_low[0]; /* v_btn_low[num_btn] */
  326. s16 _v_btn_high[0]; /* v_btn_high[num_btn] */
  327. u8 _n_ready[2];
  328. u8 _n_cic[2];
  329. u8 _gain[2];
  330. } __packed;
  331. struct wcd_mbhc_imped_detect_cfg {
  332. u8 _hs_imped_detect;
  333. u8 _n_rload;
  334. u8 _hph_keep_on;
  335. u8 _repeat_rload_calc;
  336. u16 _t_dac_ramp_time;
  337. u16 _rhph_high;
  338. u16 _rhph_low;
  339. u16 _rload[0]; /* rload[n_rload] */
  340. u16 _alpha[0]; /* alpha[n_rload] */
  341. u16 _beta[3];
  342. } __packed;
  343. enum wcd_mbhc_hph_type {
  344. WCD_MBHC_HPH_NONE = 0,
  345. WCD_MBHC_HPH_MONO,
  346. WCD_MBHC_HPH_STEREO,
  347. };
  348. /*
  349. * These enum definitions are directly mapped to the register
  350. * definitions
  351. */
  352. enum mbhc_moisture_vref {
  353. V_OFF,
  354. V_45_MV,
  355. V_100_MV,
  356. V_225_MV,
  357. };
  358. enum mbhc_hs_pullup_iref {
  359. I_DEFAULT = -1,
  360. I_OFF = 0,
  361. I_1P0_UA,
  362. I_2P0_UA,
  363. I_3P0_UA,
  364. };
  365. enum mbhc_hs_pullup_iref_v2 {
  366. HS_PULLUP_I_DEFAULT = -1,
  367. HS_PULLUP_I_3P0_UA = 0,
  368. HS_PULLUP_I_2P25_UA,
  369. HS_PULLUP_I_1P5_UA,
  370. HS_PULLUP_I_0P75_UA,
  371. HS_PULLUP_I_1P125_UA = 0x05,
  372. HS_PULLUP_I_0P375_UA = 0x07,
  373. HS_PULLUP_I_2P0_UA,
  374. HS_PULLUP_I_1P0_UA = 0x0A,
  375. HS_PULLUP_I_0P5_UA,
  376. HS_PULLUP_I_0P25_UA = 0x0F,
  377. HS_PULLUP_I_0P125_UA = 0x17,
  378. HS_PULLUP_I_OFF,
  379. };
  380. enum mbhc_moisture_rref {
  381. R_OFF,
  382. R_24_KOHM,
  383. R_84_KOHM,
  384. R_184_KOHM,
  385. };
  386. struct wcd_mbhc_config {
  387. bool read_fw_bin;
  388. void *calibration;
  389. bool detect_extn_cable;
  390. bool mono_stero_detection;
  391. bool (*swap_gnd_mic)(struct snd_soc_component *component, bool active);
  392. bool hs_ext_micbias;
  393. bool gnd_det_en;
  394. int key_code[WCD_MBHC_KEYCODE_NUM];
  395. uint32_t linein_th;
  396. bool moisture_en;
  397. int mbhc_micbias;
  398. int anc_micbias;
  399. bool enable_anc_mic_detect;
  400. u32 enable_usbc_analog;
  401. bool moisture_duty_cycle_en;
  402. bool usbss_hsj_connect_enable;
  403. };
  404. struct wcd_mbhc_intr {
  405. int mbhc_sw_intr;
  406. int mbhc_btn_press_intr;
  407. int mbhc_btn_release_intr;
  408. int mbhc_hs_ins_intr;
  409. int mbhc_hs_rem_intr;
  410. int hph_left_ocp;
  411. int hph_right_ocp;
  412. };
  413. struct wcd_mbhc_register {
  414. const char *id;
  415. u32 reg;
  416. u8 mask;
  417. u8 offset;
  418. u8 invert;
  419. };
  420. struct wcd_mbhc_cb {
  421. void (*update_cross_conn_thr)
  422. (struct wcd_mbhc *mbhc);
  423. void (*mbhc_surge_ctl)
  424. (struct wcd_mbhc *mbhc, bool surge_en);
  425. void (*mbhc_comp_autozero_control)
  426. (struct wcd_mbhc *mbhc, bool az_enable);
  427. void (*get_micbias_val)
  428. (struct wcd_mbhc *mbhc, int *mb);
  429. void (*bcs_enable)
  430. (struct wcd_mbhc *mbhc, bool bcs_enable);
  431. int (*enable_mb_source)(struct wcd_mbhc *mbhc, bool turn_on);
  432. void (*trim_btn_reg)(struct snd_soc_component *component);
  433. void (*compute_impedance)(struct wcd_mbhc *mbhc,
  434. uint32_t *zl, uint32_t *zr);
  435. void (*set_micbias_value)(struct snd_soc_component *component);
  436. void (*set_auto_zeroing)(struct snd_soc_component *component,
  437. bool enable);
  438. struct firmware_cal * (*get_hwdep_fw_cal)(struct wcd_mbhc *mbhc,
  439. enum wcd_cal_type);
  440. void (*set_cap_mode)(struct snd_soc_component *component,
  441. bool micbias1, bool micbias2);
  442. int (*register_notifier)(struct wcd_mbhc *mbhc,
  443. struct notifier_block *nblock,
  444. bool enable);
  445. int (*request_irq)(struct snd_soc_component *component,
  446. int irq, irq_handler_t handler,
  447. const char *name, void *data);
  448. void (*irq_control)(struct snd_soc_component *component,
  449. int irq, bool enable);
  450. int (*free_irq)(struct snd_soc_component *component,
  451. int irq, void *data);
  452. void (*clk_setup)(struct snd_soc_component *component, bool enable);
  453. int (*map_btn_code_to_num)(struct snd_soc_component *component);
  454. bool (*lock_sleep)(struct wcd_mbhc *mbhc, bool lock);
  455. bool (*micbias_enable_status)(struct wcd_mbhc *mbhc, int micb_num);
  456. void (*mbhc_bias)(struct snd_soc_component *component, bool enable);
  457. void (*mbhc_common_micb_ctrl)(struct snd_soc_component *component,
  458. int event, bool enable);
  459. void (*micb_internal)(struct snd_soc_component *component,
  460. int micb_num, bool enable);
  461. bool (*hph_pa_on_status)(struct snd_soc_component *component);
  462. void (*set_btn_thr)(struct snd_soc_component *component,
  463. s16 *btn_low, s16 *btn_high,
  464. int num_btn, bool is_micbias);
  465. void (*hph_pull_up_control)(struct snd_soc_component *component,
  466. enum mbhc_hs_pullup_iref);
  467. int (*mbhc_micbias_control)(struct snd_soc_component *component,
  468. int micb_num, int req);
  469. void (*mbhc_micb_ramp_control)(struct snd_soc_component *component,
  470. bool enable);
  471. void (*skip_imped_detect)(struct snd_soc_component *component);
  472. bool (*extn_use_mb)(struct snd_soc_component *component);
  473. int (*mbhc_micb_ctrl_thr_mic)(struct snd_soc_component *component,
  474. int micb_num, bool req_en);
  475. void (*mbhc_gnd_det_ctrl)(struct snd_soc_component *component,
  476. bool enable);
  477. void (*hph_pull_down_ctrl)(struct snd_soc_component *component,
  478. bool enable);
  479. void (*mbhc_moisture_config)(struct wcd_mbhc *mbhc);
  480. bool (*hph_register_recovery)(struct wcd_mbhc *mbhc);
  481. void (*update_anc_state)(struct snd_soc_component *component,
  482. bool enable, int anc_num);
  483. bool (*is_anc_on)(struct wcd_mbhc *mbhc);
  484. void (*hph_pull_up_control_v2)(struct snd_soc_component *component,
  485. int pull_up_cur);
  486. bool (*mbhc_get_moisture_status)(struct wcd_mbhc *mbhc);
  487. void (*mbhc_moisture_polling_ctrl)(struct wcd_mbhc *mbhc, bool enable);
  488. void (*mbhc_moisture_detect_en)(struct wcd_mbhc *mbhc, bool enable);
  489. void (*surge_reset_routine)(struct wcd_mbhc *mbhc);
  490. void (*zdet_leakage_resistance)(struct wcd_mbhc *mbhc, bool enable);
  491. };
  492. struct wcd_mbhc_fn {
  493. irqreturn_t (*wcd_mbhc_hs_ins_irq)(int irq, void *data);
  494. irqreturn_t (*wcd_mbhc_hs_rem_irq)(int irq, void *data);
  495. void (*wcd_mbhc_detect_plug_type)(struct wcd_mbhc *mbhc);
  496. bool (*wcd_mbhc_detect_anc_plug_type)(struct wcd_mbhc *mbhc);
  497. void (*wcd_cancel_hs_detect_plug)(struct wcd_mbhc *mbhc,
  498. struct work_struct *work);
  499. };
  500. struct wcd_mbhc {
  501. /* Delayed work to report long button press */
  502. struct delayed_work mbhc_btn_dwork;
  503. int buttons_pressed;
  504. struct wcd_mbhc_config *mbhc_cfg;
  505. const struct wcd_mbhc_cb *mbhc_cb;
  506. u32 hph_status; /* track headhpone status */
  507. u8 hphlocp_cnt; /* headphone left ocp retry */
  508. u8 hphrocp_cnt; /* headphone right ocp retry */
  509. wait_queue_head_t wait_btn_press;
  510. bool is_btn_press;
  511. u8 current_plug;
  512. bool in_swch_irq_handler;
  513. bool hphl_swh; /*track HPHL switch NC / NO */
  514. bool gnd_swh; /*track GND switch NC / NO */
  515. u32 hs_thr;
  516. u32 hph_thr;
  517. u32 micb_mv;
  518. u32 swap_thr;
  519. u32 moist_vref;
  520. u32 moist_iref;
  521. u32 moist_rref;
  522. u32 hphl_cross_conn_thr;
  523. u32 hphr_cross_conn_thr;
  524. u8 micbias1_cap_mode; /* track ext cap setting */
  525. u8 micbias2_cap_mode; /* track ext cap setting */
  526. bool hs_detect_work_stop;
  527. bool micbias_enable;
  528. bool btn_press_intr;
  529. bool is_hs_recording;
  530. bool is_extn_cable;
  531. bool skip_imped_detection;
  532. bool is_btn_already_regd;
  533. bool extn_cable_hph_rem;
  534. struct snd_soc_component *component;
  535. /* Work to perform MBHC Firmware Read */
  536. struct delayed_work mbhc_firmware_dwork;
  537. const struct firmware *mbhc_fw;
  538. struct firmware_cal *mbhc_cal;
  539. /* track PA/DAC state to sync with userspace */
  540. unsigned long hph_pa_dac_state;
  541. unsigned long hph_anc_state;
  542. unsigned long event_state;
  543. unsigned long jiffies_atreport;
  544. /* impedance of hphl and hphr */
  545. uint32_t zl, zr;
  546. bool impedance_detect;
  547. /* Holds type of Headset - Mono/Stereo */
  548. enum wcd_mbhc_hph_type hph_type;
  549. struct snd_soc_jack headset_jack;
  550. struct snd_soc_jack button_jack;
  551. struct mutex codec_resource_lock;
  552. /* Holds codec specific interrupt mapping */
  553. const struct wcd_mbhc_intr *intr_ids;
  554. /* Work to correct accessory type */
  555. struct work_struct correct_plug_swch;
  556. struct notifier_block nblock;
  557. struct wcd_mbhc_register *wcd_mbhc_regs;
  558. struct completion btn_press_compl;
  559. bool deinit_in_progress;
  560. /* Holds mbhc detection method - ADC/Legacy */
  561. unsigned int mbhc_detection_logic;
  562. unsigned long intr_status;
  563. bool is_hph_ocp_pending;
  564. struct wcd_mbhc_fn *mbhc_fn;
  565. bool force_linein;
  566. struct device_node *wcd_usbss_aatc_dev_np;
  567. struct device_node *fsa_aatc_dev_np;
  568. struct notifier_block aatc_dev_nb;
  569. struct extcon_dev *extdev;
  570. };
  571. void wcd_mbhc_find_plug_and_report(struct wcd_mbhc *mbhc,
  572. enum wcd_mbhc_plug_type plug_type);
  573. void wcd_mbhc_hs_elec_irq(struct wcd_mbhc *mbhc, int irq_type, bool enable);
  574. void wcd_mbhc_elec_hs_report_unplug(struct wcd_mbhc *mbhc);
  575. bool wcd_swch_level_remove(struct wcd_mbhc *mbhc);
  576. void wcd_enable_curr_micbias(const struct wcd_mbhc *mbhc,
  577. const enum wcd_mbhc_cs_mb_en_flag cs_mb_en);
  578. void wcd_mbhc_jack_report(struct wcd_mbhc *mbhc,
  579. struct snd_soc_jack *jack, int status, int mask);
  580. int wcd_cancel_btn_work(struct wcd_mbhc *mbhc);
  581. int wcd_mbhc_get_button_mask(struct wcd_mbhc *mbhc);
  582. void wcd_mbhc_report_plug(struct wcd_mbhc *mbhc, int insertion,
  583. enum snd_jack_types jack_type);
  584. #endif /* __WCD_MBHC_V2_H__ */