wcd-mbhc-legacy.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029
  1. // SPDX-License-Identifier: GPL-2.0
  2. /* Copyright (c) 2015-2018, 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 "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->codec,
  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->codec,
  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->codec))
  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_codec *codec = mbhc->codec;
  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(codec,
  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(codec,
  181. MBHC_COMMON_MICB_PRECHARGE,
  182. true);
  183. mbhc->mbhc_cb->mbhc_common_micb_ctrl(codec,
  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(codec, 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(codec,
  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(codec);
  216. if (mbhc->mbhc_cb->set_auto_zeroing)
  217. mbhc->mbhc_cb->set_auto_zeroing(codec, false);
  218. if (mbhc->mbhc_cb->mbhc_micb_ctrl_thr_mic &&
  219. !mbhc->micbias_enable)
  220. mbhc->mbhc_cb->mbhc_micb_ctrl_thr_mic(codec, 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_codec *codec = mbhc->codec;
  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(codec)) {
  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->codec,
  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->codec,
  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_codec *codec = mbhc->codec;
  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(codec, 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(codec, micbias1, true);
  364. if (mbhc->mbhc_cb->mbhc_micbias_control)
  365. mbhc->mbhc_cb->mbhc_micbias_control(codec, 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_codec *codec;
  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. codec = mbhc->codec;
  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->codec, MIC_BIAS_2, false);
  464. if (mbhc->mbhc_cb->set_micbias_value)
  465. mbhc->mbhc_cb->set_micbias_value(
  466. mbhc->codec);
  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->codec, MIC_BIAS_2, false);
  489. if (mbhc->mbhc_cb->set_micbias_value)
  490. mbhc->mbhc_cb->set_micbias_value(
  491. mbhc->codec);
  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(codec);
  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(codec,
  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(codec, 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. codec, 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. codec,
  676. MIC_BIAS_2, false);
  677. if (mbhc->mbhc_cb->set_micbias_value) {
  678. mbhc->mbhc_cb->set_micbias_value(codec);
  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(codec, micbias1, micbias2);
  699. if (mbhc->mbhc_cb->hph_pull_down_ctrl)
  700. mbhc->mbhc_cb->hph_pull_down_ctrl(codec, 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(mbhc->codec)) {
  749. hphpa_on = true;
  750. WCD_MBHC_REG_UPDATE_BITS(
  751. WCD_MBHC_HPHL_PA_EN, 0);
  752. WCD_MBHC_REG_UPDATE_BITS(
  753. WCD_MBHC_HPH_PA_EN, 0);
  754. }
  755. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_HPHR_GND, 1);
  756. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_HPHL_GND, 1);
  757. /* wait for 50ms to get moisture status */
  758. usleep_range(50000, 50100);
  759. WCD_MBHC_REG_READ(
  760. WCD_MBHC_MOISTURE_STATUS, moisture_status);
  761. }
  762. if (mbhc->mbhc_cfg->moisture_en && !moisture_status) {
  763. pr_debug("%s: moisture present in jack\n", __func__);
  764. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_L_DET_EN, 0);
  765. WCD_MBHC_REG_UPDATE_BITS(
  766. WCD_MBHC_MECH_DETECTION_TYPE, 1);
  767. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_L_DET_EN, 1);
  768. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_FSM_EN, 0);
  769. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_BTN_ISRC_CTL, 0);
  770. mbhc->btn_press_intr = false;
  771. mbhc->is_btn_press = false;
  772. if (mbhc->current_plug == MBHC_PLUG_TYPE_HEADSET)
  773. wcd_mbhc_report_plug(
  774. mbhc, 0, SND_JACK_HEADSET);
  775. else if (mbhc->current_plug ==
  776. MBHC_PLUG_TYPE_HEADPHONE)
  777. wcd_mbhc_report_plug(
  778. mbhc, 0, SND_JACK_HEADPHONE);
  779. else if (mbhc->current_plug ==
  780. MBHC_PLUG_TYPE_GND_MIC_SWAP)
  781. wcd_mbhc_report_plug(
  782. mbhc, 0, SND_JACK_UNSUPPORTED);
  783. else if (mbhc->current_plug ==
  784. MBHC_PLUG_TYPE_HIGH_HPH)
  785. wcd_mbhc_report_plug(
  786. mbhc, 0, SND_JACK_LINEOUT);
  787. } else {
  788. if (!(hphl_sch && mic_sch && hs_comp_result)) {
  789. /*
  790. * extension cable is still plugged in
  791. * report it as LINEOUT device
  792. */
  793. goto report_unplug;
  794. } else {
  795. if (!mic_sch) {
  796. mic_trigerred++;
  797. pr_debug(
  798. "%s: Removal MIC trigerred %d\n",
  799. __func__, mic_trigerred);
  800. }
  801. if (!hphl_sch) {
  802. hphl_trigerred++;
  803. pr_debug(
  804. "%s: Removal HPHL trigerred %d\n",
  805. __func__, hphl_trigerred);
  806. }
  807. if (mic_trigerred && hphl_trigerred) {
  808. /*
  809. * extension cable is still plugged in
  810. * report it as LINEOUT device
  811. */
  812. goto report_unplug;
  813. }
  814. }
  815. }
  816. }
  817. exit:
  818. WCD_MBHC_RSC_UNLOCK(mbhc);
  819. pr_debug("%s: leave\n", __func__);
  820. return IRQ_HANDLED;
  821. report_unplug:
  822. wcd_mbhc_elec_hs_report_unplug(mbhc);
  823. if (hphpa_on) {
  824. hphpa_on = false;
  825. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_HPHL_PA_EN, 1);
  826. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_HPH_PA_EN, 1);
  827. }
  828. hphl_trigerred = 0;
  829. mic_trigerred = 0;
  830. WCD_MBHC_RSC_UNLOCK(mbhc);
  831. pr_debug("%s: leave\n", __func__);
  832. return IRQ_HANDLED;
  833. }
  834. static irqreturn_t wcd_mbhc_hs_ins_irq(int irq, void *data)
  835. {
  836. struct wcd_mbhc *mbhc = data;
  837. bool detection_type = 0, hphl_sch = 0, mic_sch = 0;
  838. u16 elect_result = 0;
  839. static u16 hphl_trigerred;
  840. static u16 mic_trigerred;
  841. pr_debug("%s: enter\n", __func__);
  842. if (!mbhc->mbhc_cfg->detect_extn_cable) {
  843. pr_debug("%s: Returning as Extension cable feature not enabled\n",
  844. __func__);
  845. return IRQ_HANDLED;
  846. }
  847. WCD_MBHC_RSC_LOCK(mbhc);
  848. WCD_MBHC_REG_READ(WCD_MBHC_ELECT_DETECTION_TYPE, detection_type);
  849. WCD_MBHC_REG_READ(WCD_MBHC_ELECT_RESULT, elect_result);
  850. pr_debug("%s: detection_type %d, elect_result %x\n", __func__,
  851. detection_type, elect_result);
  852. if (detection_type) {
  853. /* check if both Left and MIC Schmitt triggers are triggered */
  854. WCD_MBHC_REG_READ(WCD_MBHC_HPHL_SCHMT_RESULT, hphl_sch);
  855. WCD_MBHC_REG_READ(WCD_MBHC_MIC_SCHMT_RESULT, mic_sch);
  856. if (hphl_sch && mic_sch) {
  857. /* Go for plug type determination */
  858. pr_debug("%s: Go for plug type determination\n",
  859. __func__);
  860. goto determine_plug;
  861. } else {
  862. if (mic_sch) {
  863. mic_trigerred++;
  864. pr_debug("%s: Insertion MIC trigerred %d\n",
  865. __func__, mic_trigerred);
  866. WCD_MBHC_REG_UPDATE_BITS(
  867. WCD_MBHC_ELECT_SCHMT_ISRC,
  868. 0);
  869. msleep(20);
  870. WCD_MBHC_REG_UPDATE_BITS(
  871. WCD_MBHC_ELECT_SCHMT_ISRC,
  872. 1);
  873. }
  874. if (hphl_sch) {
  875. hphl_trigerred++;
  876. pr_debug("%s: Insertion HPHL trigerred %d\n",
  877. __func__, hphl_trigerred);
  878. }
  879. if (mic_trigerred && hphl_trigerred) {
  880. /* Go for plug type determination */
  881. pr_debug("%s: Go for plug type determination\n",
  882. __func__);
  883. goto determine_plug;
  884. }
  885. }
  886. }
  887. WCD_MBHC_RSC_UNLOCK(mbhc);
  888. pr_debug("%s: leave\n", __func__);
  889. return IRQ_HANDLED;
  890. determine_plug:
  891. /*
  892. * Disable HPHL trigger and MIC Schmitt triggers.
  893. * Setup for insertion detection.
  894. */
  895. pr_debug("%s: Disable insertion interrupt\n", __func__);
  896. wcd_mbhc_hs_elec_irq(mbhc, WCD_MBHC_ELEC_HS_INS,
  897. false);
  898. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_ELECT_SCHMT_ISRC, 0);
  899. hphl_trigerred = 0;
  900. mic_trigerred = 0;
  901. mbhc->is_extn_cable = true;
  902. mbhc->btn_press_intr = false;
  903. wcd_mbhc_detect_plug_type(mbhc);
  904. WCD_MBHC_RSC_UNLOCK(mbhc);
  905. pr_debug("%s: leave\n", __func__);
  906. return IRQ_HANDLED;
  907. }
  908. static struct wcd_mbhc_fn mbhc_fn = {
  909. .wcd_mbhc_hs_ins_irq = wcd_mbhc_hs_ins_irq,
  910. .wcd_mbhc_hs_rem_irq = wcd_mbhc_hs_rem_irq,
  911. .wcd_mbhc_detect_plug_type = wcd_mbhc_detect_plug_type,
  912. .wcd_mbhc_detect_anc_plug_type = wcd_mbhc_detect_anc_plug_type,
  913. .wcd_cancel_hs_detect_plug = wcd_cancel_hs_detect_plug,
  914. };
  915. /* Function: wcd_mbhc_legacy_init
  916. * @mbhc: MBHC function pointer
  917. * Description: Initialize MBHC legacy based function pointers to MBHC structure
  918. */
  919. void wcd_mbhc_legacy_init(struct wcd_mbhc *mbhc)
  920. {
  921. if (!mbhc) {
  922. pr_err("%s: mbhc is NULL\n", __func__);
  923. return;
  924. }
  925. mbhc->mbhc_fn = &mbhc_fn;
  926. INIT_WORK(&mbhc->correct_plug_swch, wcd_correct_swch_plug);
  927. }
  928. EXPORT_SYMBOL(wcd_mbhc_legacy_init);