wcd-mbhc-v2.h 17 KB

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