wcd-mbhc-v2.h 16 KB

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