wcd-mbhc-legacy.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /* Copyright (c) 2015-2021, The Linux Foundation. All rights reserved.
  3. */
  4. #include <linux/module.h>
  5. #include <linux/init.h>
  6. #include <linux/slab.h>
  7. #include <linux/of_gpio.h>
  8. #include <linux/platform_device.h>
  9. #include <linux/device.h>
  10. #include <linux/printk.h>
  11. #include <linux/ratelimit.h>
  12. #include <linux/list.h>
  13. #include <linux/bitops.h>
  14. #include <linux/delay.h>
  15. #include <linux/pm_runtime.h>
  16. #include <linux/kernel.h>
  17. #include <linux/input.h>
  18. #include <linux/firmware.h>
  19. #include <linux/completion.h>
  20. #include <sound/soc.h>
  21. #include <sound/jack.h>
  22. #include "wcd-mbhc-legacy.h"
  23. #include <asoc/wcd-mbhc-v2.h>
  24. static int det_extn_cable_en;
  25. module_param(det_extn_cable_en, int, 0664);
  26. MODULE_PARM_DESC(det_extn_cable_en, "enable/disable extn cable detect");
  27. static bool wcd_mbhc_detect_anc_plug_type(struct wcd_mbhc *mbhc)
  28. {
  29. bool anc_mic_found = false;
  30. u16 val, hs_comp_res, btn_status = 0;
  31. unsigned long retry = 0;
  32. int valid_plug_cnt = 0, invalid_plug_cnt = 0;
  33. int btn_status_cnt = 0;
  34. bool is_check_btn_press = false;
  35. if (mbhc->mbhc_cfg->anc_micbias < MIC_BIAS_1 ||
  36. mbhc->mbhc_cfg->anc_micbias > MIC_BIAS_4)
  37. return false;
  38. if (!mbhc->mbhc_cb->mbhc_micbias_control)
  39. return false;
  40. WCD_MBHC_REG_READ(WCD_MBHC_FSM_EN, val);
  41. if (val)
  42. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_FSM_EN, 0);
  43. mbhc->mbhc_cb->mbhc_micbias_control(mbhc->component,
  44. mbhc->mbhc_cfg->anc_micbias,
  45. MICB_ENABLE);
  46. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_MUX_CTL, 0x2);
  47. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_ANC_DET_EN, 1);
  48. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_FSM_EN, 1);
  49. /*
  50. * wait for button debounce time 20ms. If 4-pole plug is inserted
  51. * into 5-pole jack, then there will be a button press interrupt
  52. * during anc plug detection. In that case though Hs_comp_res is 0,
  53. * it should not be declared as ANC plug type
  54. */
  55. usleep_range(20000, 20100);
  56. /*
  57. * After enabling FSM, to handle slow insertion scenarios,
  58. * check hs_comp_result for few times to see if the IN3 voltage
  59. * is below the Vref
  60. */
  61. do {
  62. if (wcd_swch_level_remove(mbhc)) {
  63. pr_debug("%s: Switch level is low\n", __func__);
  64. goto exit;
  65. }
  66. pr_debug("%s: Retry attempt %lu\n", __func__, retry + 1);
  67. WCD_MBHC_REG_READ(WCD_MBHC_HS_COMP_RESULT, hs_comp_res);
  68. if (!hs_comp_res) {
  69. valid_plug_cnt++;
  70. is_check_btn_press = true;
  71. } else
  72. invalid_plug_cnt++;
  73. /* Wait 1ms before taking another reading */
  74. usleep_range(1000, 1100);
  75. WCD_MBHC_REG_READ(WCD_MBHC_FSM_STATUS, btn_status);
  76. if (btn_status)
  77. btn_status_cnt++;
  78. retry++;
  79. } while (retry < ANC_DETECT_RETRY_CNT);
  80. pr_debug("%s: valid: %d, invalid: %d, btn_status_cnt: %d\n",
  81. __func__, valid_plug_cnt, invalid_plug_cnt, btn_status_cnt);
  82. /* decision logic */
  83. if ((valid_plug_cnt > invalid_plug_cnt) && is_check_btn_press &&
  84. (btn_status_cnt == 0))
  85. anc_mic_found = true;
  86. exit:
  87. if (!val)
  88. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_FSM_EN, 0);
  89. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_ANC_DET_EN, 0);
  90. mbhc->mbhc_cb->mbhc_micbias_control(mbhc->component,
  91. mbhc->mbhc_cfg->anc_micbias,
  92. MICB_DISABLE);
  93. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_MUX_CTL, 0x0);
  94. pr_debug("%s: anc mic %sfound\n", __func__,
  95. anc_mic_found ? "" : "not ");
  96. return anc_mic_found;
  97. }
  98. /* To determine if cross connection occurred */
  99. static int wcd_check_cross_conn(struct wcd_mbhc *mbhc)
  100. {
  101. u16 swap_res = 0;
  102. enum wcd_mbhc_plug_type plug_type = MBHC_PLUG_TYPE_NONE;
  103. s16 reg1 = 0;
  104. bool hphl_sch_res = 0, hphr_sch_res = 0;
  105. if (wcd_swch_level_remove(mbhc)) {
  106. pr_debug("%s: Switch level is low\n", __func__);
  107. return -EINVAL;
  108. }
  109. /* If PA is enabled, dont check for cross-connection */
  110. if (mbhc->mbhc_cb->hph_pa_on_status)
  111. if (mbhc->mbhc_cb->hph_pa_on_status(mbhc->component))
  112. return false;
  113. WCD_MBHC_REG_READ(WCD_MBHC_ELECT_SCHMT_ISRC, reg1);
  114. /*
  115. * Check if there is any cross connection,
  116. * Micbias and schmitt trigger (HPHL-HPHR)
  117. * needs to be enabled. For some codecs like wcd9335,
  118. * pull-up will already be enabled when this function
  119. * is called for cross-connection identification. No
  120. * need to enable micbias in that case.
  121. */
  122. wcd_enable_curr_micbias(mbhc, WCD_MBHC_EN_MB);
  123. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_ELECT_SCHMT_ISRC, 2);
  124. WCD_MBHC_REG_READ(WCD_MBHC_ELECT_RESULT, swap_res);
  125. pr_debug("%s: swap_res%x\n", __func__, swap_res);
  126. /*
  127. * Read reg hphl and hphr schmitt result with cross connection
  128. * bit. These bits will both be "0" in case of cross connection
  129. * otherwise, they stay at 1
  130. */
  131. WCD_MBHC_REG_READ(WCD_MBHC_HPHL_SCHMT_RESULT, hphl_sch_res);
  132. WCD_MBHC_REG_READ(WCD_MBHC_HPHR_SCHMT_RESULT, hphr_sch_res);
  133. if (!(hphl_sch_res || hphr_sch_res)) {
  134. plug_type = MBHC_PLUG_TYPE_GND_MIC_SWAP;
  135. pr_debug("%s: Cross connection identified\n", __func__);
  136. } else {
  137. pr_debug("%s: No Cross connection found\n", __func__);
  138. }
  139. /* Disable schmitt trigger and restore micbias */
  140. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_ELECT_SCHMT_ISRC, reg1);
  141. pr_debug("%s: leave, plug type: %d\n", __func__, plug_type);
  142. return (plug_type == MBHC_PLUG_TYPE_GND_MIC_SWAP) ? true : false;
  143. }
  144. static bool wcd_is_special_headset(struct wcd_mbhc *mbhc)
  145. {
  146. struct snd_soc_component *component = mbhc->component;
  147. int delay = 0, rc;
  148. bool ret = false;
  149. u16 hs_comp_res;
  150. bool is_spl_hs = false;
  151. /*
  152. * Increase micbias to 2.7V to detect headsets with
  153. * threshold on microphone
  154. */
  155. if (mbhc->mbhc_cb->mbhc_micbias_control &&
  156. !mbhc->mbhc_cb->mbhc_micb_ctrl_thr_mic) {
  157. pr_debug("%s: callback fn micb_ctrl_thr_mic not defined\n",
  158. __func__);
  159. return false;
  160. } else if (mbhc->mbhc_cb->mbhc_micb_ctrl_thr_mic) {
  161. rc = mbhc->mbhc_cb->mbhc_micb_ctrl_thr_mic(component,
  162. MIC_BIAS_2, true);
  163. if (rc) {
  164. pr_err("%s: Micbias control for thr mic failed, rc: %d\n",
  165. __func__, rc);
  166. return false;
  167. }
  168. }
  169. wcd_enable_curr_micbias(mbhc, WCD_MBHC_EN_MB);
  170. pr_debug("%s: special headset, start register writes\n", __func__);
  171. WCD_MBHC_REG_READ(WCD_MBHC_HS_COMP_RESULT, hs_comp_res);
  172. while (!is_spl_hs) {
  173. if (mbhc->hs_detect_work_stop) {
  174. pr_debug("%s: stop requested: %d\n", __func__,
  175. mbhc->hs_detect_work_stop);
  176. break;
  177. }
  178. delay = delay + 50;
  179. if (mbhc->mbhc_cb->mbhc_common_micb_ctrl) {
  180. mbhc->mbhc_cb->mbhc_common_micb_ctrl(component,
  181. MBHC_COMMON_MICB_PRECHARGE,
  182. true);
  183. mbhc->mbhc_cb->mbhc_common_micb_ctrl(component,
  184. MBHC_COMMON_MICB_SET_VAL,
  185. true);
  186. }
  187. /* Wait for 50msec for MICBIAS to settle down */
  188. msleep(50);
  189. if (mbhc->mbhc_cb->set_auto_zeroing)
  190. mbhc->mbhc_cb->set_auto_zeroing(component, true);
  191. /* Wait for 50msec for FSM to update result values */
  192. msleep(50);
  193. WCD_MBHC_REG_READ(WCD_MBHC_HS_COMP_RESULT, hs_comp_res);
  194. if (!(hs_comp_res)) {
  195. pr_debug("%s: Special headset detected in %d msecs\n",
  196. __func__, (delay * 2));
  197. is_spl_hs = true;
  198. }
  199. if (delay == SPECIAL_HS_DETECT_TIME_MS) {
  200. pr_debug("%s: Spl headset didn't get detect in 4 sec\n",
  201. __func__);
  202. break;
  203. }
  204. }
  205. if (is_spl_hs) {
  206. pr_debug("%s: Headset with threshold found\n", __func__);
  207. mbhc->micbias_enable = true;
  208. ret = true;
  209. }
  210. if (mbhc->mbhc_cb->mbhc_common_micb_ctrl)
  211. mbhc->mbhc_cb->mbhc_common_micb_ctrl(component,
  212. MBHC_COMMON_MICB_PRECHARGE,
  213. false);
  214. if (mbhc->mbhc_cb->set_micbias_value && !mbhc->micbias_enable)
  215. mbhc->mbhc_cb->set_micbias_value(component);
  216. if (mbhc->mbhc_cb->set_auto_zeroing)
  217. mbhc->mbhc_cb->set_auto_zeroing(component, false);
  218. if (mbhc->mbhc_cb->mbhc_micb_ctrl_thr_mic &&
  219. !mbhc->micbias_enable)
  220. mbhc->mbhc_cb->mbhc_micb_ctrl_thr_mic(component, MIC_BIAS_2,
  221. false);
  222. pr_debug("%s: leave, micb_enable: %d\n", __func__,
  223. mbhc->micbias_enable);
  224. return ret;
  225. }
  226. static void wcd_mbhc_update_fsm_source(struct wcd_mbhc *mbhc,
  227. enum wcd_mbhc_plug_type plug_type)
  228. {
  229. bool micbias2;
  230. micbias2 = mbhc->mbhc_cb->micbias_enable_status(mbhc,
  231. MIC_BIAS_2);
  232. switch (plug_type) {
  233. case MBHC_PLUG_TYPE_HEADPHONE:
  234. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_BTN_ISRC_CTL, 3);
  235. break;
  236. case MBHC_PLUG_TYPE_HEADSET:
  237. case MBHC_PLUG_TYPE_ANC_HEADPHONE:
  238. if (!mbhc->is_hs_recording && !micbias2)
  239. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_BTN_ISRC_CTL, 3);
  240. break;
  241. default:
  242. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_BTN_ISRC_CTL, 0);
  243. break;
  244. };
  245. }
  246. static void wcd_enable_mbhc_supply(struct wcd_mbhc *mbhc,
  247. enum wcd_mbhc_plug_type plug_type)
  248. {
  249. struct snd_soc_component *component = mbhc->component;
  250. /*
  251. * Do not disable micbias if recording is going on or
  252. * headset is inserted on the other side of the extn
  253. * cable. If headset has been detected current source
  254. * needs to be kept enabled for button detection to work.
  255. * If the accessory type is invalid or unsupported, we
  256. * dont need to enable either of them.
  257. */
  258. if (det_extn_cable_en && mbhc->is_extn_cable &&
  259. mbhc->mbhc_cb && mbhc->mbhc_cb->extn_use_mb &&
  260. mbhc->mbhc_cb->extn_use_mb(component)) {
  261. if (plug_type == MBHC_PLUG_TYPE_HEADPHONE ||
  262. plug_type == MBHC_PLUG_TYPE_HEADSET)
  263. wcd_enable_curr_micbias(mbhc, WCD_MBHC_EN_MB);
  264. } else {
  265. if (plug_type == MBHC_PLUG_TYPE_HEADSET) {
  266. if (mbhc->is_hs_recording || mbhc->micbias_enable) {
  267. wcd_enable_curr_micbias(mbhc, WCD_MBHC_EN_MB);
  268. } else if ((test_bit(WCD_MBHC_EVENT_PA_HPHL,
  269. &mbhc->event_state)) ||
  270. (test_bit(WCD_MBHC_EVENT_PA_HPHR,
  271. &mbhc->event_state))) {
  272. wcd_enable_curr_micbias(mbhc,
  273. WCD_MBHC_EN_PULLUP);
  274. } else {
  275. wcd_enable_curr_micbias(mbhc, WCD_MBHC_EN_CS);
  276. }
  277. } else if (plug_type == MBHC_PLUG_TYPE_HEADPHONE) {
  278. wcd_enable_curr_micbias(mbhc, WCD_MBHC_EN_CS);
  279. } else {
  280. wcd_enable_curr_micbias(mbhc, WCD_MBHC_EN_NONE);
  281. }
  282. }
  283. }
  284. static bool wcd_mbhc_check_for_spl_headset(struct wcd_mbhc *mbhc,
  285. int *spl_hs_cnt)
  286. {
  287. u16 hs_comp_res_1_8v = 0, hs_comp_res_2_7v = 0;
  288. bool spl_hs = false;
  289. if (!mbhc->mbhc_cb->mbhc_micb_ctrl_thr_mic)
  290. goto done;
  291. if (!spl_hs_cnt) {
  292. pr_err("%s: spl_hs_cnt is NULL\n", __func__);
  293. goto done;
  294. }
  295. /* Read back hs_comp_res @ 1.8v Micbias */
  296. WCD_MBHC_REG_READ(WCD_MBHC_HS_COMP_RESULT, hs_comp_res_1_8v);
  297. if (!hs_comp_res_1_8v) {
  298. spl_hs = false;
  299. goto done;
  300. }
  301. /* Bump up MB2 to 2.7v */
  302. mbhc->mbhc_cb->mbhc_micb_ctrl_thr_mic(mbhc->component,
  303. mbhc->mbhc_cfg->mbhc_micbias, true);
  304. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_FSM_EN, 0);
  305. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_FSM_EN, 1);
  306. usleep_range(10000, 10100);
  307. /* Read back HS_COMP_RESULT */
  308. WCD_MBHC_REG_READ(WCD_MBHC_HS_COMP_RESULT, hs_comp_res_2_7v);
  309. if (!hs_comp_res_2_7v && hs_comp_res_1_8v)
  310. spl_hs = true;
  311. if (spl_hs)
  312. *spl_hs_cnt += 1;
  313. /* MB2 back to 1.8v */
  314. if (*spl_hs_cnt != WCD_MBHC_SPL_HS_CNT) {
  315. mbhc->mbhc_cb->mbhc_micb_ctrl_thr_mic(mbhc->component,
  316. mbhc->mbhc_cfg->mbhc_micbias, false);
  317. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_FSM_EN, 0);
  318. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_FSM_EN, 1);
  319. usleep_range(10000, 10100);
  320. }
  321. if (spl_hs)
  322. pr_debug("%s: Detected special HS (%d)\n", __func__, spl_hs);
  323. done:
  324. return spl_hs;
  325. }
  326. /* should be called under interrupt context that hold suspend */
  327. static void wcd_schedule_hs_detect_plug(struct wcd_mbhc *mbhc,
  328. struct work_struct *work)
  329. {
  330. pr_debug("%s: scheduling correct_swch_plug\n", __func__);
  331. WCD_MBHC_RSC_ASSERT_LOCKED(mbhc);
  332. mbhc->hs_detect_work_stop = false;
  333. mbhc->mbhc_cb->lock_sleep(mbhc, true);
  334. schedule_work(work);
  335. }
  336. /* called under codec_resource_lock acquisition */
  337. static void wcd_cancel_hs_detect_plug(struct wcd_mbhc *mbhc,
  338. struct work_struct *work)
  339. {
  340. pr_debug("%s: Canceling correct_plug_swch\n", __func__);
  341. mbhc->hs_detect_work_stop = true;
  342. WCD_MBHC_RSC_UNLOCK(mbhc);
  343. if (cancel_work_sync(work)) {
  344. pr_debug("%s: correct_plug_swch is canceled\n",
  345. __func__);
  346. mbhc->mbhc_cb->lock_sleep(mbhc, false);
  347. }
  348. WCD_MBHC_RSC_LOCK(mbhc);
  349. }
  350. /* called under codec_resource_lock acquisition */
  351. static void wcd_mbhc_detect_plug_type(struct wcd_mbhc *mbhc)
  352. {
  353. struct snd_soc_component *component = mbhc->component;
  354. bool micbias1 = false;
  355. pr_debug("%s: enter\n", __func__);
  356. WCD_MBHC_RSC_ASSERT_LOCKED(mbhc);
  357. if (mbhc->mbhc_cb->hph_pull_down_ctrl)
  358. mbhc->mbhc_cb->hph_pull_down_ctrl(component, false);
  359. if (mbhc->mbhc_cb->micbias_enable_status)
  360. micbias1 = mbhc->mbhc_cb->micbias_enable_status(mbhc,
  361. MIC_BIAS_1);
  362. if (mbhc->mbhc_cb->set_cap_mode)
  363. mbhc->mbhc_cb->set_cap_mode(component, micbias1, true);
  364. if (mbhc->mbhc_cb->mbhc_micbias_control)
  365. mbhc->mbhc_cb->mbhc_micbias_control(component, MIC_BIAS_2,
  366. MICB_ENABLE);
  367. else
  368. wcd_enable_curr_micbias(mbhc, WCD_MBHC_EN_MB);
  369. /* Re-initialize button press completion object */
  370. reinit_completion(&mbhc->btn_press_compl);
  371. wcd_schedule_hs_detect_plug(mbhc, &mbhc->correct_plug_swch);
  372. pr_debug("%s: leave\n", __func__);
  373. }
  374. static void wcd_correct_swch_plug(struct work_struct *work)
  375. {
  376. struct wcd_mbhc *mbhc;
  377. struct snd_soc_component *component;
  378. enum wcd_mbhc_plug_type plug_type = MBHC_PLUG_TYPE_INVALID;
  379. unsigned long timeout;
  380. u16 hs_comp_res = 0, hphl_sch = 0, mic_sch = 0, btn_result = 0;
  381. bool wrk_complete = false;
  382. int pt_gnd_mic_swap_cnt = 0;
  383. int no_gnd_mic_swap_cnt = 0;
  384. bool is_pa_on = false, spl_hs = false, spl_hs_reported = false;
  385. bool micbias2 = false;
  386. bool micbias1 = false;
  387. int ret = 0;
  388. int rc, spl_hs_count = 0;
  389. int cross_conn;
  390. int try = 0;
  391. pr_debug("%s: enter\n", __func__);
  392. mbhc = container_of(work, struct wcd_mbhc, correct_plug_swch);
  393. component = mbhc->component;
  394. /*
  395. * Enable micbias/pullup for detection in correct work.
  396. * This work will get scheduled from detect_plug_type which
  397. * will already request for pullup/micbias. If the pullup/micbias
  398. * is handled with ref-counts by individual codec drivers, there is
  399. * no need to enabale micbias/pullup here
  400. */
  401. wcd_enable_curr_micbias(mbhc, WCD_MBHC_EN_MB);
  402. /* Enable HW FSM */
  403. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_FSM_EN, 1);
  404. /*
  405. * Check for any button press interrupts before starting 3-sec
  406. * loop.
  407. */
  408. rc = wait_for_completion_timeout(&mbhc->btn_press_compl,
  409. msecs_to_jiffies(WCD_MBHC_BTN_PRESS_COMPL_TIMEOUT_MS));
  410. WCD_MBHC_REG_READ(WCD_MBHC_BTN_RESULT, btn_result);
  411. WCD_MBHC_REG_READ(WCD_MBHC_HS_COMP_RESULT, hs_comp_res);
  412. if (!rc) {
  413. pr_debug("%s No btn press interrupt\n", __func__);
  414. if (!btn_result && !hs_comp_res)
  415. plug_type = MBHC_PLUG_TYPE_HEADSET;
  416. else if (!btn_result && hs_comp_res)
  417. plug_type = MBHC_PLUG_TYPE_HIGH_HPH;
  418. else
  419. plug_type = MBHC_PLUG_TYPE_INVALID;
  420. } else {
  421. if (!btn_result && !hs_comp_res)
  422. plug_type = MBHC_PLUG_TYPE_HEADPHONE;
  423. else
  424. plug_type = MBHC_PLUG_TYPE_INVALID;
  425. }
  426. do {
  427. cross_conn = wcd_check_cross_conn(mbhc);
  428. try++;
  429. } while (try < mbhc->swap_thr);
  430. /*
  431. * Check for cross connection 4 times.
  432. * Consider the result of the fourth iteration.
  433. */
  434. if (cross_conn > 0) {
  435. pr_debug("%s: cross con found, start polling\n",
  436. __func__);
  437. plug_type = MBHC_PLUG_TYPE_GND_MIC_SWAP;
  438. pr_debug("%s: Plug found, plug type is %d\n",
  439. __func__, plug_type);
  440. goto correct_plug_type;
  441. }
  442. if ((plug_type == MBHC_PLUG_TYPE_HEADSET ||
  443. plug_type == MBHC_PLUG_TYPE_HEADPHONE) &&
  444. (!wcd_swch_level_remove(mbhc))) {
  445. WCD_MBHC_RSC_LOCK(mbhc);
  446. if (mbhc->current_plug == MBHC_PLUG_TYPE_HIGH_HPH)
  447. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_ELECT_DETECTION_TYPE,
  448. 0);
  449. wcd_mbhc_find_plug_and_report(mbhc, plug_type);
  450. WCD_MBHC_RSC_UNLOCK(mbhc);
  451. }
  452. correct_plug_type:
  453. timeout = jiffies + msecs_to_jiffies(HS_DETECT_PLUG_TIME_MS);
  454. while (!time_after(jiffies, timeout)) {
  455. if (mbhc->hs_detect_work_stop) {
  456. pr_debug("%s: stop requested: %d\n", __func__,
  457. mbhc->hs_detect_work_stop);
  458. wcd_enable_curr_micbias(mbhc,
  459. WCD_MBHC_EN_NONE);
  460. if (mbhc->mbhc_cb->mbhc_micb_ctrl_thr_mic &&
  461. mbhc->micbias_enable) {
  462. mbhc->mbhc_cb->mbhc_micb_ctrl_thr_mic(
  463. mbhc->component, MIC_BIAS_2, false);
  464. if (mbhc->mbhc_cb->set_micbias_value)
  465. mbhc->mbhc_cb->set_micbias_value(
  466. mbhc->component);
  467. mbhc->micbias_enable = false;
  468. }
  469. goto exit;
  470. }
  471. if (mbhc->btn_press_intr) {
  472. wcd_cancel_btn_work(mbhc);
  473. mbhc->btn_press_intr = false;
  474. }
  475. /* Toggle FSM */
  476. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_FSM_EN, 0);
  477. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_FSM_EN, 1);
  478. /* allow sometime and re-check stop requested again */
  479. msleep(20);
  480. if (mbhc->hs_detect_work_stop) {
  481. pr_debug("%s: stop requested: %d\n", __func__,
  482. mbhc->hs_detect_work_stop);
  483. wcd_enable_curr_micbias(mbhc,
  484. WCD_MBHC_EN_NONE);
  485. if (mbhc->mbhc_cb->mbhc_micb_ctrl_thr_mic &&
  486. mbhc->micbias_enable) {
  487. mbhc->mbhc_cb->mbhc_micb_ctrl_thr_mic(
  488. mbhc->component, MIC_BIAS_2, false);
  489. if (mbhc->mbhc_cb->set_micbias_value)
  490. mbhc->mbhc_cb->set_micbias_value(
  491. mbhc->component);
  492. mbhc->micbias_enable = false;
  493. }
  494. goto exit;
  495. }
  496. WCD_MBHC_REG_READ(WCD_MBHC_HS_COMP_RESULT, hs_comp_res);
  497. pr_debug("%s: hs_comp_res: %x\n", __func__, hs_comp_res);
  498. if (mbhc->mbhc_cb->hph_pa_on_status)
  499. is_pa_on = mbhc->mbhc_cb->hph_pa_on_status(component);
  500. /*
  501. * instead of hogging system by contineous polling, wait for
  502. * sometime and re-check stop request again.
  503. */
  504. msleep(180);
  505. if (hs_comp_res && (spl_hs_count < WCD_MBHC_SPL_HS_CNT)) {
  506. spl_hs = wcd_mbhc_check_for_spl_headset(mbhc,
  507. &spl_hs_count);
  508. if (spl_hs_count == WCD_MBHC_SPL_HS_CNT) {
  509. hs_comp_res = 0;
  510. spl_hs = true;
  511. mbhc->micbias_enable = true;
  512. }
  513. }
  514. if ((!hs_comp_res) && (!is_pa_on)) {
  515. /* Check for cross connection*/
  516. ret = wcd_check_cross_conn(mbhc);
  517. if (ret < 0) {
  518. continue;
  519. } else if (ret > 0) {
  520. pt_gnd_mic_swap_cnt++;
  521. no_gnd_mic_swap_cnt = 0;
  522. if (pt_gnd_mic_swap_cnt <
  523. mbhc->swap_thr) {
  524. continue;
  525. } else if (pt_gnd_mic_swap_cnt >
  526. mbhc->swap_thr) {
  527. /*
  528. * This is due to GND/MIC switch didn't
  529. * work, Report unsupported plug.
  530. */
  531. pr_debug("%s: switch didn't work\n",
  532. __func__);
  533. plug_type = MBHC_PLUG_TYPE_GND_MIC_SWAP;
  534. goto report;
  535. } else {
  536. plug_type = MBHC_PLUG_TYPE_GND_MIC_SWAP;
  537. }
  538. } else {
  539. no_gnd_mic_swap_cnt++;
  540. pt_gnd_mic_swap_cnt = 0;
  541. plug_type = MBHC_PLUG_TYPE_HEADSET;
  542. if ((no_gnd_mic_swap_cnt <
  543. GND_MIC_SWAP_THRESHOLD) &&
  544. (spl_hs_count != WCD_MBHC_SPL_HS_CNT)) {
  545. continue;
  546. } else {
  547. no_gnd_mic_swap_cnt = 0;
  548. }
  549. }
  550. if ((pt_gnd_mic_swap_cnt == mbhc->swap_thr) &&
  551. (plug_type == MBHC_PLUG_TYPE_GND_MIC_SWAP)) {
  552. /*
  553. * if switch is toggled, check again,
  554. * otherwise report unsupported plug
  555. */
  556. if (mbhc->mbhc_cfg->swap_gnd_mic &&
  557. mbhc->mbhc_cfg->swap_gnd_mic(component,
  558. true)) {
  559. pr_debug("%s: US_EU gpio present,flip switch\n"
  560. , __func__);
  561. continue;
  562. }
  563. }
  564. }
  565. WCD_MBHC_REG_READ(WCD_MBHC_HPHL_SCHMT_RESULT, hphl_sch);
  566. WCD_MBHC_REG_READ(WCD_MBHC_MIC_SCHMT_RESULT, mic_sch);
  567. if (hs_comp_res && !(hphl_sch || mic_sch)) {
  568. pr_debug("%s: cable is extension cable\n", __func__);
  569. plug_type = MBHC_PLUG_TYPE_HIGH_HPH;
  570. wrk_complete = true;
  571. } else {
  572. pr_debug("%s: cable might be headset: %d\n", __func__,
  573. plug_type);
  574. if (!(plug_type == MBHC_PLUG_TYPE_GND_MIC_SWAP)) {
  575. plug_type = MBHC_PLUG_TYPE_HEADSET;
  576. if (!spl_hs_reported &&
  577. spl_hs_count == WCD_MBHC_SPL_HS_CNT) {
  578. spl_hs_reported = true;
  579. WCD_MBHC_RSC_LOCK(mbhc);
  580. wcd_mbhc_find_plug_and_report(mbhc,
  581. plug_type);
  582. WCD_MBHC_RSC_UNLOCK(mbhc);
  583. continue;
  584. } else if (spl_hs_reported)
  585. continue;
  586. /*
  587. * Report headset only if not already reported
  588. * and if there is not button press without
  589. * release
  590. */
  591. if (((mbhc->current_plug !=
  592. MBHC_PLUG_TYPE_HEADSET) &&
  593. (mbhc->current_plug !=
  594. MBHC_PLUG_TYPE_ANC_HEADPHONE)) &&
  595. !wcd_swch_level_remove(mbhc) &&
  596. !mbhc->btn_press_intr) {
  597. pr_debug("%s: cable is %sheadset\n",
  598. __func__,
  599. ((spl_hs_count ==
  600. WCD_MBHC_SPL_HS_CNT) ?
  601. "special ":""));
  602. goto report;
  603. }
  604. }
  605. wrk_complete = false;
  606. }
  607. }
  608. if (!wrk_complete && mbhc->btn_press_intr) {
  609. pr_debug("%s: Can be slow insertion of headphone\n", __func__);
  610. wcd_cancel_btn_work(mbhc);
  611. /* Report as headphone only if previously
  612. * not reported as lineout
  613. */
  614. if (!mbhc->force_linein)
  615. plug_type = MBHC_PLUG_TYPE_HEADPHONE;
  616. }
  617. /*
  618. * If plug_tye is headset, we might have already reported either in
  619. * detect_plug-type or in above while loop, no need to report again
  620. */
  621. if (!wrk_complete && ((plug_type == MBHC_PLUG_TYPE_HEADSET) ||
  622. (plug_type == MBHC_PLUG_TYPE_ANC_HEADPHONE))) {
  623. pr_debug("%s: plug_type:0x%x already reported\n",
  624. __func__, mbhc->current_plug);
  625. goto enable_supply;
  626. }
  627. if (plug_type == MBHC_PLUG_TYPE_HIGH_HPH &&
  628. (!det_extn_cable_en)) {
  629. if (wcd_is_special_headset(mbhc)) {
  630. pr_debug("%s: Special headset found %d\n",
  631. __func__, plug_type);
  632. plug_type = MBHC_PLUG_TYPE_HEADSET;
  633. goto report;
  634. }
  635. }
  636. report:
  637. if (wcd_swch_level_remove(mbhc)) {
  638. pr_debug("%s: Switch level is low\n", __func__);
  639. goto exit;
  640. }
  641. if (plug_type == MBHC_PLUG_TYPE_GND_MIC_SWAP && mbhc->btn_press_intr) {
  642. pr_debug("%s: insertion of headphone with swap\n", __func__);
  643. wcd_cancel_btn_work(mbhc);
  644. plug_type = MBHC_PLUG_TYPE_HEADPHONE;
  645. }
  646. pr_debug("%s: Valid plug found, plug type %d wrk_cmpt %d btn_intr %d\n",
  647. __func__, plug_type, wrk_complete,
  648. mbhc->btn_press_intr);
  649. WCD_MBHC_RSC_LOCK(mbhc);
  650. wcd_mbhc_find_plug_and_report(mbhc, plug_type);
  651. WCD_MBHC_RSC_UNLOCK(mbhc);
  652. enable_supply:
  653. if (mbhc->mbhc_cb->mbhc_micbias_control)
  654. wcd_mbhc_update_fsm_source(mbhc, plug_type);
  655. else
  656. wcd_enable_mbhc_supply(mbhc, plug_type);
  657. exit:
  658. if (mbhc->mbhc_cb->mbhc_micbias_control &&
  659. !mbhc->micbias_enable)
  660. mbhc->mbhc_cb->mbhc_micbias_control(component, MIC_BIAS_2,
  661. MICB_DISABLE);
  662. /*
  663. * If plug type is corrected from special headset to headphone,
  664. * clear the micbias enable flag, set micbias back to 1.8V and
  665. * disable micbias.
  666. */
  667. if (plug_type == MBHC_PLUG_TYPE_HEADPHONE &&
  668. mbhc->micbias_enable) {
  669. if (mbhc->mbhc_cb->mbhc_micbias_control)
  670. mbhc->mbhc_cb->mbhc_micbias_control(
  671. component, MIC_BIAS_2,
  672. MICB_DISABLE);
  673. if (mbhc->mbhc_cb->mbhc_micb_ctrl_thr_mic)
  674. mbhc->mbhc_cb->mbhc_micb_ctrl_thr_mic(
  675. component,
  676. MIC_BIAS_2, false);
  677. if (mbhc->mbhc_cb->set_micbias_value) {
  678. mbhc->mbhc_cb->set_micbias_value(component);
  679. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_MICB_CTRL, 0);
  680. }
  681. mbhc->micbias_enable = false;
  682. }
  683. if (mbhc->mbhc_cb->micbias_enable_status) {
  684. micbias1 = mbhc->mbhc_cb->micbias_enable_status(mbhc,
  685. MIC_BIAS_1);
  686. micbias2 = mbhc->mbhc_cb->micbias_enable_status(mbhc,
  687. MIC_BIAS_2);
  688. }
  689. if (mbhc->mbhc_cfg->detect_extn_cable &&
  690. ((plug_type == MBHC_PLUG_TYPE_HEADPHONE) ||
  691. (plug_type == MBHC_PLUG_TYPE_HEADSET)) &&
  692. !mbhc->hs_detect_work_stop) {
  693. WCD_MBHC_RSC_LOCK(mbhc);
  694. wcd_mbhc_hs_elec_irq(mbhc, WCD_MBHC_ELEC_HS_REM, true);
  695. WCD_MBHC_RSC_UNLOCK(mbhc);
  696. }
  697. if (mbhc->mbhc_cb->set_cap_mode)
  698. mbhc->mbhc_cb->set_cap_mode(component, micbias1, micbias2);
  699. if (mbhc->mbhc_cb->hph_pull_down_ctrl)
  700. mbhc->mbhc_cb->hph_pull_down_ctrl(component, true);
  701. mbhc->mbhc_cb->lock_sleep(mbhc, false);
  702. pr_debug("%s: leave\n", __func__);
  703. }
  704. static irqreturn_t wcd_mbhc_hs_rem_irq(int irq, void *data)
  705. {
  706. struct wcd_mbhc *mbhc = data;
  707. u8 hs_comp_result = 0, hphl_sch = 0, mic_sch = 0;
  708. static u16 hphl_trigerred;
  709. static u16 mic_trigerred;
  710. unsigned long timeout;
  711. bool removed = true;
  712. int retry = 0;
  713. bool hphpa_on = false;
  714. u8 moisture_status = 0;
  715. pr_debug("%s: enter\n", __func__);
  716. WCD_MBHC_RSC_LOCK(mbhc);
  717. timeout = jiffies +
  718. msecs_to_jiffies(WCD_FAKE_REMOVAL_MIN_PERIOD_MS);
  719. do {
  720. retry++;
  721. /*
  722. * read the result register every 10ms to look for
  723. * any change in HS_COMP_RESULT bit
  724. */
  725. usleep_range(10000, 10100);
  726. WCD_MBHC_REG_READ(WCD_MBHC_HS_COMP_RESULT, hs_comp_result);
  727. pr_debug("%s: Check result reg for fake removal: hs_comp_res %x\n",
  728. __func__, hs_comp_result);
  729. if ((!hs_comp_result) &&
  730. retry > FAKE_REM_RETRY_ATTEMPTS) {
  731. removed = false;
  732. break;
  733. }
  734. } while (!time_after(jiffies, timeout));
  735. if (wcd_swch_level_remove(mbhc)) {
  736. pr_debug("%s: Switch level is low ", __func__);
  737. goto exit;
  738. }
  739. pr_debug("%s: headset %s actually removed\n", __func__,
  740. removed ? "" : "not ");
  741. WCD_MBHC_REG_READ(WCD_MBHC_HPHL_SCHMT_RESULT, hphl_sch);
  742. WCD_MBHC_REG_READ(WCD_MBHC_MIC_SCHMT_RESULT, mic_sch);
  743. WCD_MBHC_REG_READ(WCD_MBHC_HS_COMP_RESULT, hs_comp_result);
  744. if (removed) {
  745. if (mbhc->mbhc_cfg->moisture_en) {
  746. if (mbhc->mbhc_cb->hph_pa_on_status)
  747. if (
  748. mbhc->mbhc_cb->hph_pa_on_status(
  749. mbhc->component)) {
  750. hphpa_on = true;
  751. WCD_MBHC_REG_UPDATE_BITS(
  752. WCD_MBHC_HPHL_PA_EN, 0);
  753. WCD_MBHC_REG_UPDATE_BITS(
  754. WCD_MBHC_HPH_PA_EN, 0);
  755. }
  756. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_HPHR_GND, 1);
  757. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_HPHL_GND, 1);
  758. /* wait for 50ms to get moisture status */
  759. usleep_range(50000, 50100);
  760. WCD_MBHC_REG_READ(
  761. WCD_MBHC_MOISTURE_STATUS, moisture_status);
  762. }
  763. if (mbhc->mbhc_cfg->moisture_en && !moisture_status) {
  764. pr_debug("%s: moisture present in jack\n", __func__);
  765. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_L_DET_EN, 0);
  766. WCD_MBHC_REG_UPDATE_BITS(
  767. WCD_MBHC_MECH_DETECTION_TYPE, 1);
  768. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_L_DET_EN, 1);
  769. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_FSM_EN, 0);
  770. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_BTN_ISRC_CTL, 0);
  771. mbhc->btn_press_intr = false;
  772. mbhc->is_btn_press = false;
  773. if (mbhc->current_plug == MBHC_PLUG_TYPE_HEADSET) {
  774. wcd_mbhc_report_plug(
  775. mbhc, 0, SND_JACK_HEADSET);
  776. extcon_set_state_sync(mbhc->extdev, EXTCON_JACK_MICROPHONE, 0);
  777. } else if (mbhc->current_plug ==
  778. MBHC_PLUG_TYPE_HEADPHONE)
  779. wcd_mbhc_report_plug(
  780. mbhc, 0, SND_JACK_HEADPHONE);
  781. extcon_set_state_sync(mbhc->extdev, EXTCON_JACK_HEADPHONE, 0);
  782. } else if (mbhc->current_plug ==
  783. MBHC_PLUG_TYPE_GND_MIC_SWAP)
  784. #if IS_ENABLED(CONFIG_AUDIO_QGKI)
  785. wcd_mbhc_report_plug(
  786. mbhc, 0, SND_JACK_UNSUPPORTED);
  787. #endif /* CONFIG_AUDIO_QGKI */
  788. extcon_set_state_sync(mbhc->extdev, EXTCON_MECHANICAL, 0);
  789. } else if (mbhc->current_plug ==
  790. MBHC_PLUG_TYPE_HIGH_HPH) {
  791. wcd_mbhc_report_plug(
  792. mbhc, 0, SND_JACK_LINEOUT);
  793. extcon_set_state_sync(mbhc->extdev, EXTCON_JACK_LINE_OUT, 0);
  794. }
  795. } else {
  796. if (!(hphl_sch && mic_sch && hs_comp_result)) {
  797. /*
  798. * extension cable is still plugged in
  799. * report it as LINEOUT device
  800. */
  801. goto report_unplug;
  802. } else {
  803. if (!mic_sch) {
  804. mic_trigerred++;
  805. pr_debug(
  806. "%s: Removal MIC trigerred %d\n",
  807. __func__, mic_trigerred);
  808. }
  809. if (!hphl_sch) {
  810. hphl_trigerred++;
  811. pr_debug(
  812. "%s: Removal HPHL trigerred %d\n",
  813. __func__, hphl_trigerred);
  814. }
  815. if (mic_trigerred && hphl_trigerred) {
  816. /*
  817. * extension cable is still plugged in
  818. * report it as LINEOUT device
  819. */
  820. goto report_unplug;
  821. }
  822. }
  823. }
  824. }
  825. exit:
  826. WCD_MBHC_RSC_UNLOCK(mbhc);
  827. pr_debug("%s: leave\n", __func__);
  828. return IRQ_HANDLED;
  829. report_unplug:
  830. wcd_mbhc_elec_hs_report_unplug(mbhc);
  831. if (hphpa_on) {
  832. hphpa_on = false;
  833. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_HPHL_PA_EN, 1);
  834. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_HPHR_PA_EN, 1);
  835. }
  836. hphl_trigerred = 0;
  837. mic_trigerred = 0;
  838. WCD_MBHC_RSC_UNLOCK(mbhc);
  839. pr_debug("%s: leave\n", __func__);
  840. return IRQ_HANDLED;
  841. }
  842. static irqreturn_t wcd_mbhc_hs_ins_irq(int irq, void *data)
  843. {
  844. struct wcd_mbhc *mbhc = data;
  845. bool detection_type = 0, hphl_sch = 0, mic_sch = 0;
  846. u16 elect_result = 0;
  847. static u16 hphl_trigerred;
  848. static u16 mic_trigerred;
  849. pr_debug("%s: enter\n", __func__);
  850. if (!mbhc->mbhc_cfg->detect_extn_cable) {
  851. pr_debug("%s: Returning as Extension cable feature not enabled\n",
  852. __func__);
  853. return IRQ_HANDLED;
  854. }
  855. WCD_MBHC_RSC_LOCK(mbhc);
  856. WCD_MBHC_REG_READ(WCD_MBHC_ELECT_DETECTION_TYPE, detection_type);
  857. WCD_MBHC_REG_READ(WCD_MBHC_ELECT_RESULT, elect_result);
  858. pr_debug("%s: detection_type %d, elect_result %x\n", __func__,
  859. detection_type, elect_result);
  860. if (detection_type) {
  861. /* check if both Left and MIC Schmitt triggers are triggered */
  862. WCD_MBHC_REG_READ(WCD_MBHC_HPHL_SCHMT_RESULT, hphl_sch);
  863. WCD_MBHC_REG_READ(WCD_MBHC_MIC_SCHMT_RESULT, mic_sch);
  864. if (hphl_sch && mic_sch) {
  865. /* Go for plug type determination */
  866. pr_debug("%s: Go for plug type determination\n",
  867. __func__);
  868. goto determine_plug;
  869. } else {
  870. if (mic_sch) {
  871. mic_trigerred++;
  872. pr_debug("%s: Insertion MIC trigerred %d\n",
  873. __func__, mic_trigerred);
  874. WCD_MBHC_REG_UPDATE_BITS(
  875. WCD_MBHC_ELECT_SCHMT_ISRC,
  876. 0);
  877. msleep(20);
  878. WCD_MBHC_REG_UPDATE_BITS(
  879. WCD_MBHC_ELECT_SCHMT_ISRC,
  880. 1);
  881. }
  882. if (hphl_sch) {
  883. hphl_trigerred++;
  884. pr_debug("%s: Insertion HPHL trigerred %d\n",
  885. __func__, hphl_trigerred);
  886. }
  887. if (mic_trigerred && hphl_trigerred) {
  888. /* Go for plug type determination */
  889. pr_debug("%s: Go for plug type determination\n",
  890. __func__);
  891. goto determine_plug;
  892. }
  893. }
  894. }
  895. WCD_MBHC_RSC_UNLOCK(mbhc);
  896. pr_debug("%s: leave\n", __func__);
  897. return IRQ_HANDLED;
  898. determine_plug:
  899. /*
  900. * Disable HPHL trigger and MIC Schmitt triggers.
  901. * Setup for insertion detection.
  902. */
  903. pr_debug("%s: Disable insertion interrupt\n", __func__);
  904. wcd_mbhc_hs_elec_irq(mbhc, WCD_MBHC_ELEC_HS_INS,
  905. false);
  906. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_ELECT_SCHMT_ISRC, 0);
  907. hphl_trigerred = 0;
  908. mic_trigerred = 0;
  909. mbhc->is_extn_cable = true;
  910. mbhc->btn_press_intr = false;
  911. wcd_mbhc_detect_plug_type(mbhc);
  912. WCD_MBHC_RSC_UNLOCK(mbhc);
  913. pr_debug("%s: leave\n", __func__);
  914. return IRQ_HANDLED;
  915. }
  916. static struct wcd_mbhc_fn mbhc_fn = {
  917. .wcd_mbhc_hs_ins_irq = wcd_mbhc_hs_ins_irq,
  918. .wcd_mbhc_hs_rem_irq = wcd_mbhc_hs_rem_irq,
  919. .wcd_mbhc_detect_plug_type = wcd_mbhc_detect_plug_type,
  920. .wcd_mbhc_detect_anc_plug_type = wcd_mbhc_detect_anc_plug_type,
  921. .wcd_cancel_hs_detect_plug = wcd_cancel_hs_detect_plug,
  922. };
  923. /* Function: wcd_mbhc_legacy_init
  924. * @mbhc: MBHC function pointer
  925. * Description: Initialize MBHC legacy based function pointers to MBHC structure
  926. */
  927. void wcd_mbhc_legacy_init(struct wcd_mbhc *mbhc)
  928. {
  929. if (!mbhc) {
  930. pr_err("%s: mbhc is NULL\n", __func__);
  931. return;
  932. }
  933. mbhc->mbhc_fn = &mbhc_fn;
  934. INIT_WORK(&mbhc->correct_plug_swch, wcd_correct_swch_plug);
  935. }
  936. EXPORT_SYMBOL(wcd_mbhc_legacy_init);