wcd-mbhc-adc.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020
  1. /* Copyright (c) 2017, The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. */
  12. #include <linux/module.h>
  13. #include <linux/init.h>
  14. #include <linux/slab.h>
  15. #include <linux/of_gpio.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/device.h>
  18. #include <linux/printk.h>
  19. #include <linux/ratelimit.h>
  20. #include <linux/list.h>
  21. #include <linux/bitops.h>
  22. #include <linux/delay.h>
  23. #include <linux/pm_runtime.h>
  24. #include <linux/kernel.h>
  25. #include <linux/input.h>
  26. #include <linux/firmware.h>
  27. #include <linux/completion.h>
  28. #include <sound/soc.h>
  29. #include <sound/jack.h>
  30. #include "wcd-mbhc-adc.h"
  31. #include "wcd-mbhc-v2.h"
  32. #define WCD_MBHC_ADC_HS_THRESHOLD_MV 1700
  33. #define WCD_MBHC_ADC_HPH_THRESHOLD_MV 75
  34. #define WCD_MBHC_ADC_MICBIAS_MV 1800
  35. static int wcd_mbhc_get_micbias(struct wcd_mbhc *mbhc)
  36. {
  37. int micbias = 0;
  38. u8 vout_ctl = 0;
  39. /* Read MBHC Micbias (Mic Bias2) voltage */
  40. WCD_MBHC_REG_READ(WCD_MBHC_MICB2_VOUT, vout_ctl);
  41. /* Formula for getting micbias from vout
  42. * micbias = 1.0V + VOUT_CTL * 50mV
  43. */
  44. micbias = 1000 + (vout_ctl * 50);
  45. pr_debug("%s: vout_ctl: %d, micbias: %d\n",
  46. __func__, vout_ctl, micbias);
  47. return micbias;
  48. }
  49. static int wcd_get_voltage_from_adc(u8 val, int micbias)
  50. {
  51. /* Formula for calculating voltage from ADC
  52. * Voltage = ADC_RESULT*12.5mV*V_MICBIAS/1.8
  53. */
  54. return ((val * 125 * micbias)/(WCD_MBHC_ADC_MICBIAS_MV * 10));
  55. }
  56. static int wcd_measure_adc_continuous(struct wcd_mbhc *mbhc)
  57. {
  58. u8 adc_result = 0;
  59. int output_mv = 0;
  60. int retry = 3;
  61. u8 adc_en = 0;
  62. pr_debug("%s: enter\n", __func__);
  63. /* Pre-requisites for ADC continuous measurement */
  64. /* Read legacy electircal detection and disable */
  65. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_ELECT_SCHMT_ISRC, 0x00);
  66. /* Set ADC to continuous measurement */
  67. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_ADC_MODE, 1);
  68. /* Read ADC Enable bit to restore after adc measurement */
  69. WCD_MBHC_REG_READ(WCD_MBHC_ADC_EN, adc_en);
  70. /* Disable ADC_ENABLE bit */
  71. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_ADC_EN, 0);
  72. /* Disable MBHC FSM */
  73. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_FSM_EN, 0);
  74. /* Set the MUX selection to IN2P */
  75. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_MUX_CTL, MUX_CTL_IN2P);
  76. /* Enable MBHC FSM */
  77. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_FSM_EN, 1);
  78. /* Enable ADC_ENABLE bit */
  79. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_ADC_EN, 1);
  80. while (retry--) {
  81. /* wait for 3 msec before reading ADC result */
  82. usleep_range(3000, 3100);
  83. /* Read ADC result */
  84. WCD_MBHC_REG_READ(WCD_MBHC_ADC_RESULT, adc_result);
  85. }
  86. /* Restore ADC Enable */
  87. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_ADC_EN, adc_en);
  88. /* Get voltage from ADC result */
  89. output_mv = wcd_get_voltage_from_adc(adc_result,
  90. wcd_mbhc_get_micbias(mbhc));
  91. pr_debug("%s: adc_result: 0x%x, output_mv: %d\n",
  92. __func__, adc_result, output_mv);
  93. return output_mv;
  94. }
  95. static int wcd_measure_adc_once(struct wcd_mbhc *mbhc, int mux_ctl)
  96. {
  97. u8 adc_timeout = 0;
  98. u8 adc_complete = 0;
  99. u8 adc_result = 0;
  100. int retry = 6;
  101. int ret = 0;
  102. int output_mv = 0;
  103. u8 adc_en = 0;
  104. pr_debug("%s: enter\n", __func__);
  105. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_ADC_MODE, 0);
  106. /* Read ADC Enable bit to restore after adc measurement */
  107. WCD_MBHC_REG_READ(WCD_MBHC_ADC_EN, adc_en);
  108. /* Trigger ADC one time measurement */
  109. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_ADC_EN, 0);
  110. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_FSM_EN, 0);
  111. /* Set the appropriate MUX selection */
  112. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_MUX_CTL, mux_ctl);
  113. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_FSM_EN, 1);
  114. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_ADC_EN, 1);
  115. while (retry--) {
  116. /* wait for 600usec to get adc results */
  117. usleep_range(600, 610);
  118. /* check for ADC Timeout */
  119. WCD_MBHC_REG_READ(WCD_MBHC_ADC_TIMEOUT, adc_timeout);
  120. if (adc_timeout)
  121. continue;
  122. /* Read ADC complete bit */
  123. WCD_MBHC_REG_READ(WCD_MBHC_ADC_COMPLETE, adc_complete);
  124. if (!adc_complete)
  125. continue;
  126. /* Read ADC result */
  127. WCD_MBHC_REG_READ(WCD_MBHC_ADC_RESULT, adc_result);
  128. pr_debug("%s: ADC result: 0x%x\n", __func__, adc_result);
  129. /* Get voltage from ADC result */
  130. output_mv = wcd_get_voltage_from_adc(adc_result,
  131. wcd_mbhc_get_micbias(mbhc));
  132. break;
  133. }
  134. /* Restore ADC Enable */
  135. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_ADC_EN, adc_en);
  136. if (retry <= 0) {
  137. pr_err("%s: adc complete: %d, adc timeout: %d\n",
  138. __func__, adc_complete, adc_timeout);
  139. ret = -EINVAL;
  140. } else {
  141. pr_debug("%s: adc complete: %d, adc timeout: %d output_mV: %d\n",
  142. __func__, adc_complete, adc_timeout, output_mv);
  143. ret = output_mv;
  144. }
  145. pr_debug("%s: leave\n", __func__);
  146. return ret;
  147. }
  148. static bool wcd_mbhc_adc_detect_anc_plug_type(struct wcd_mbhc *mbhc)
  149. {
  150. bool anc_mic_found = false;
  151. u16 fsm_en = 0;
  152. u8 det = 0;
  153. unsigned long retry = 0;
  154. int valid_plug_cnt = 0, invalid_plug_cnt = 0;
  155. int ret = 0;
  156. u8 elect_ctl = 0;
  157. u8 adc_mode = 0;
  158. u8 vref = 0;
  159. int vref_mv[] = {1650, 1500, 1600, 1700};
  160. if (mbhc->mbhc_cfg->anc_micbias < MIC_BIAS_1 ||
  161. mbhc->mbhc_cfg->anc_micbias > MIC_BIAS_4)
  162. return false;
  163. if (!mbhc->mbhc_cb->mbhc_micbias_control)
  164. return false;
  165. /* Disable Detection done for ADC operation */
  166. WCD_MBHC_REG_READ(WCD_MBHC_DETECTION_DONE, det);
  167. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_DETECTION_DONE, 0);
  168. /* Mask ADC COMPLETE interrupt */
  169. wcd_mbhc_hs_elec_irq(mbhc, WCD_MBHC_ELEC_HS_INS, false);
  170. WCD_MBHC_REG_READ(WCD_MBHC_FSM_EN, fsm_en);
  171. mbhc->mbhc_cb->mbhc_micbias_control(mbhc->codec,
  172. mbhc->mbhc_cfg->anc_micbias,
  173. MICB_ENABLE);
  174. /* Read legacy electircal detection and disable */
  175. WCD_MBHC_REG_READ(WCD_MBHC_ELECT_SCHMT_ISRC, elect_ctl);
  176. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_ELECT_SCHMT_ISRC, 0x00);
  177. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_ANC_DET_EN, 1);
  178. WCD_MBHC_REG_READ(WCD_MBHC_ADC_MODE, adc_mode);
  179. /*
  180. * wait for button debounce time 20ms. If 4-pole plug is inserted
  181. * into 5-pole jack, then there will be a button press interrupt
  182. * during anc plug detection. In that case though Hs_comp_res is 0,
  183. * it should not be declared as ANC plug type
  184. */
  185. usleep_range(20000, 20100);
  186. /*
  187. * After enabling FSM, to handle slow insertion scenarios,
  188. * check IN3 voltage is below the Vref
  189. */
  190. WCD_MBHC_REG_READ(WCD_MBHC_HS_VREF, vref);
  191. do {
  192. if (wcd_swch_level_remove(mbhc)) {
  193. pr_debug("%s: Switch level is low\n", __func__);
  194. goto done;
  195. }
  196. pr_debug("%s: Retry attempt %lu\n", __func__, retry + 1);
  197. ret = wcd_measure_adc_once(mbhc, MUX_CTL_IN3P);
  198. /* TODO - check the logic */
  199. if (ret && (ret < vref_mv[vref]))
  200. valid_plug_cnt++;
  201. else
  202. invalid_plug_cnt++;
  203. retry++;
  204. } while (retry < ANC_DETECT_RETRY_CNT);
  205. pr_debug("%s: valid: %d, invalid: %d\n", __func__, valid_plug_cnt,
  206. invalid_plug_cnt);
  207. /* decision logic */
  208. if (valid_plug_cnt > invalid_plug_cnt)
  209. anc_mic_found = true;
  210. done:
  211. /* Restore ADC mode */
  212. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_ADC_MODE, adc_mode);
  213. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_ANC_DET_EN, 0);
  214. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_FSM_EN, 0);
  215. /* Set the MUX selection to AUTO */
  216. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_MUX_CTL, MUX_CTL_AUTO);
  217. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_FSM_EN, 1);
  218. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_FSM_EN, fsm_en);
  219. /* Restore detection done */
  220. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_DETECTION_DONE, det);
  221. /* Restore electrical detection */
  222. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_ELECT_SCHMT_ISRC, elect_ctl);
  223. mbhc->mbhc_cb->mbhc_micbias_control(mbhc->codec,
  224. mbhc->mbhc_cfg->anc_micbias,
  225. MICB_DISABLE);
  226. pr_debug("%s: anc mic %sfound\n", __func__,
  227. anc_mic_found ? "" : "not ");
  228. return anc_mic_found;
  229. }
  230. /* To determine if cross connection occurred */
  231. static int wcd_check_cross_conn(struct wcd_mbhc *mbhc)
  232. {
  233. enum wcd_mbhc_plug_type plug_type = MBHC_PLUG_TYPE_NONE;
  234. int hphl_adc_res = 0, hphr_adc_res = 0;
  235. u8 fsm_en = 0;
  236. int ret = 0;
  237. u8 adc_mode = 0;
  238. u8 elect_ctl = 0;
  239. u8 adc_en = 0;
  240. pr_debug("%s: enter\n", __func__);
  241. /* Check for button press and plug detection */
  242. if (wcd_swch_level_remove(mbhc)) {
  243. pr_debug("%s: Switch level is low\n", __func__);
  244. return -EINVAL;
  245. }
  246. /* If PA is enabled, dont check for cross-connection */
  247. if (mbhc->mbhc_cb->hph_pa_on_status)
  248. if (mbhc->mbhc_cb->hph_pa_on_status(mbhc->codec))
  249. return -EINVAL;
  250. /* Read legacy electircal detection and disable */
  251. WCD_MBHC_REG_READ(WCD_MBHC_ELECT_SCHMT_ISRC, elect_ctl);
  252. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_ELECT_SCHMT_ISRC, 0x00);
  253. /* Read and set ADC to single measurement */
  254. WCD_MBHC_REG_READ(WCD_MBHC_ADC_MODE, adc_mode);
  255. /* Read ADC Enable bit to restore after adc measurement */
  256. WCD_MBHC_REG_READ(WCD_MBHC_ADC_EN, adc_en);
  257. /* Read FSM status */
  258. WCD_MBHC_REG_READ(WCD_MBHC_FSM_EN, fsm_en);
  259. /* Get adc result for HPH L */
  260. hphl_adc_res = wcd_measure_adc_once(mbhc, MUX_CTL_HPH_L);
  261. if (hphl_adc_res < 0) {
  262. pr_err("%s: hphl_adc_res adc measurement failed\n", __func__);
  263. ret = hphl_adc_res;
  264. goto done;
  265. }
  266. /* Get adc result for HPH R in mV */
  267. hphr_adc_res = wcd_measure_adc_once(mbhc, MUX_CTL_HPH_R);
  268. if (hphr_adc_res < 0) {
  269. pr_err("%s: hphr_adc_res adc measurement failed\n", __func__);
  270. ret = hphr_adc_res;
  271. goto done;
  272. }
  273. if (hphl_adc_res > 100 && hphr_adc_res > 100) {
  274. plug_type = MBHC_PLUG_TYPE_GND_MIC_SWAP;
  275. pr_debug("%s: Cross connection identified\n", __func__);
  276. } else {
  277. pr_debug("%s: No Cross connection found\n", __func__);
  278. }
  279. done:
  280. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_FSM_EN, 0);
  281. /* Set the MUX selection to Auto */
  282. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_MUX_CTL, MUX_CTL_AUTO);
  283. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_FSM_EN, 1);
  284. /* Restore ADC Enable */
  285. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_ADC_EN, adc_en);
  286. /* Restore ADC mode */
  287. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_ADC_MODE, adc_mode);
  288. /* Restore FSM state */
  289. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_FSM_EN, fsm_en);
  290. /* Restore electrical detection */
  291. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_ELECT_SCHMT_ISRC, elect_ctl);
  292. pr_debug("%s: leave, plug type: %d\n", __func__, plug_type);
  293. return (plug_type == MBHC_PLUG_TYPE_GND_MIC_SWAP) ? true : false;
  294. }
  295. static bool wcd_mbhc_adc_check_for_spl_headset(struct wcd_mbhc *mbhc,
  296. int *spl_hs_cnt)
  297. {
  298. bool spl_hs = false;
  299. int output_mv = 0;
  300. int adc_threshold = 0, adc_hph_threshold = 0;
  301. pr_debug("%s: enter\n", __func__);
  302. if (!mbhc->mbhc_cb->mbhc_micb_ctrl_thr_mic)
  303. goto exit;
  304. /* Bump up MB2 to 2.7V */
  305. mbhc->mbhc_cb->mbhc_micb_ctrl_thr_mic(mbhc->codec,
  306. mbhc->mbhc_cfg->mbhc_micbias, true);
  307. usleep_range(10000, 10100);
  308. /*
  309. * Use ADC single mode to minimize the chance of missing out
  310. * btn press/relesae for HEADSET type during correct work.
  311. */
  312. output_mv = wcd_measure_adc_once(mbhc, MUX_CTL_IN2P);
  313. adc_threshold = ((WCD_MBHC_ADC_HS_THRESHOLD_MV *
  314. wcd_mbhc_get_micbias(mbhc))/WCD_MBHC_ADC_MICBIAS_MV);
  315. adc_hph_threshold = ((WCD_MBHC_ADC_HPH_THRESHOLD_MV *
  316. wcd_mbhc_get_micbias(mbhc))/
  317. WCD_MBHC_ADC_MICBIAS_MV);
  318. if (output_mv > adc_threshold || output_mv < adc_hph_threshold) {
  319. spl_hs = false;
  320. } else {
  321. spl_hs = true;
  322. if (spl_hs_cnt)
  323. *spl_hs_cnt += 1;
  324. }
  325. /* MB2 back to 1.8v if the type is not special headset */
  326. if (spl_hs_cnt && (*spl_hs_cnt != WCD_MBHC_SPL_HS_CNT)) {
  327. mbhc->mbhc_cb->mbhc_micb_ctrl_thr_mic(mbhc->codec,
  328. mbhc->mbhc_cfg->mbhc_micbias, false);
  329. /* Add 10ms delay for micbias to settle */
  330. usleep_range(10000, 10100);
  331. }
  332. if (spl_hs)
  333. pr_debug("%s: Detected special HS (%d)\n", __func__, spl_hs);
  334. exit:
  335. pr_debug("%s: leave\n", __func__);
  336. return spl_hs;
  337. }
  338. static bool wcd_is_special_headset(struct wcd_mbhc *mbhc)
  339. {
  340. int delay = 0;
  341. bool ret = false;
  342. bool is_spl_hs = false;
  343. int output_mv = 0;
  344. int adc_threshold = 0;
  345. /*
  346. * Increase micbias to 2.7V to detect headsets with
  347. * threshold on microphone
  348. */
  349. if (mbhc->mbhc_cb->mbhc_micbias_control &&
  350. !mbhc->mbhc_cb->mbhc_micb_ctrl_thr_mic) {
  351. pr_debug("%s: callback fn micb_ctrl_thr_mic not defined\n",
  352. __func__);
  353. return false;
  354. } else if (mbhc->mbhc_cb->mbhc_micb_ctrl_thr_mic) {
  355. ret = mbhc->mbhc_cb->mbhc_micb_ctrl_thr_mic(mbhc->codec,
  356. MIC_BIAS_2, true);
  357. if (ret) {
  358. pr_err("%s: mbhc_micb_ctrl_thr_mic failed, ret: %d\n",
  359. __func__, ret);
  360. return false;
  361. }
  362. }
  363. adc_threshold = ((WCD_MBHC_ADC_HS_THRESHOLD_MV *
  364. wcd_mbhc_get_micbias(mbhc)) /
  365. WCD_MBHC_ADC_MICBIAS_MV);
  366. while (!is_spl_hs) {
  367. if (mbhc->hs_detect_work_stop) {
  368. pr_debug("%s: stop requested: %d\n", __func__,
  369. mbhc->hs_detect_work_stop);
  370. break;
  371. }
  372. delay += 50;
  373. /* Wait for 50ms for FSM to update result */
  374. msleep(50);
  375. output_mv = wcd_measure_adc_once(mbhc, MUX_CTL_IN2P);
  376. if (output_mv <= adc_threshold) {
  377. pr_debug("%s: Special headset detected in %d msecs\n",
  378. __func__, delay);
  379. is_spl_hs = true;
  380. }
  381. if (delay == SPECIAL_HS_DETECT_TIME_MS) {
  382. pr_debug("%s: Spl headset not found in 2 sec\n",
  383. __func__);
  384. break;
  385. }
  386. }
  387. if (is_spl_hs) {
  388. pr_debug("%s: Headset with threshold found\n", __func__);
  389. mbhc->micbias_enable = true;
  390. ret = true;
  391. }
  392. if (mbhc->mbhc_cb->mbhc_micb_ctrl_thr_mic &&
  393. !mbhc->micbias_enable)
  394. mbhc->mbhc_cb->mbhc_micb_ctrl_thr_mic(mbhc->codec, MIC_BIAS_2,
  395. false);
  396. pr_debug("%s: leave, micb_enable: %d\n", __func__,
  397. mbhc->micbias_enable);
  398. return ret;
  399. }
  400. static void wcd_mbhc_adc_update_fsm_source(struct wcd_mbhc *mbhc,
  401. enum wcd_mbhc_plug_type plug_type)
  402. {
  403. bool micbias2;
  404. micbias2 = mbhc->mbhc_cb->micbias_enable_status(mbhc,
  405. MIC_BIAS_2);
  406. switch (plug_type) {
  407. case MBHC_PLUG_TYPE_HEADPHONE:
  408. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_BTN_ISRC_CTL, 3);
  409. break;
  410. case MBHC_PLUG_TYPE_HEADSET:
  411. case MBHC_PLUG_TYPE_ANC_HEADPHONE:
  412. if (!mbhc->is_hs_recording && !micbias2)
  413. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_BTN_ISRC_CTL, 3);
  414. break;
  415. default:
  416. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_BTN_ISRC_CTL, 0);
  417. break;
  418. };
  419. }
  420. /* should be called under interrupt context that hold suspend */
  421. static void wcd_schedule_hs_detect_plug(struct wcd_mbhc *mbhc,
  422. struct work_struct *work)
  423. {
  424. pr_debug("%s: scheduling correct_swch_plug\n", __func__);
  425. WCD_MBHC_RSC_ASSERT_LOCKED(mbhc);
  426. mbhc->hs_detect_work_stop = false;
  427. mbhc->mbhc_cb->lock_sleep(mbhc, true);
  428. schedule_work(work);
  429. }
  430. /* called under codec_resource_lock acquisition */
  431. static void wcd_cancel_hs_detect_plug(struct wcd_mbhc *mbhc,
  432. struct work_struct *work)
  433. {
  434. pr_debug("%s: Canceling correct_plug_swch\n", __func__);
  435. mbhc->hs_detect_work_stop = true;
  436. WCD_MBHC_RSC_UNLOCK(mbhc);
  437. if (cancel_work_sync(work)) {
  438. pr_debug("%s: correct_plug_swch is canceled\n",
  439. __func__);
  440. mbhc->mbhc_cb->lock_sleep(mbhc, false);
  441. }
  442. WCD_MBHC_RSC_LOCK(mbhc);
  443. }
  444. /* called under codec_resource_lock acquisition */
  445. static void wcd_mbhc_adc_detect_plug_type(struct wcd_mbhc *mbhc)
  446. {
  447. struct snd_soc_codec *codec = mbhc->codec;
  448. pr_debug("%s: enter\n", __func__);
  449. WCD_MBHC_RSC_ASSERT_LOCKED(mbhc);
  450. if (mbhc->mbhc_cb->hph_pull_down_ctrl)
  451. mbhc->mbhc_cb->hph_pull_down_ctrl(codec, false);
  452. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_DETECTION_DONE, 0);
  453. if (mbhc->mbhc_cb->mbhc_micbias_control) {
  454. mbhc->mbhc_cb->mbhc_micbias_control(codec, MIC_BIAS_2,
  455. MICB_ENABLE);
  456. } else {
  457. pr_err("%s: Mic Bias is not enabled\n", __func__);
  458. return;
  459. }
  460. /* Re-initialize button press completion object */
  461. reinit_completion(&mbhc->btn_press_compl);
  462. wcd_schedule_hs_detect_plug(mbhc, &mbhc->correct_plug_swch);
  463. pr_debug("%s: leave\n", __func__);
  464. }
  465. static void wcd_micbias_disable(struct wcd_mbhc *mbhc)
  466. {
  467. if (mbhc->micbias_enable) {
  468. mbhc->mbhc_cb->mbhc_micb_ctrl_thr_mic(
  469. mbhc->codec, MIC_BIAS_2, false);
  470. if (mbhc->mbhc_cb->set_micbias_value)
  471. mbhc->mbhc_cb->set_micbias_value(
  472. mbhc->codec);
  473. mbhc->micbias_enable = false;
  474. }
  475. }
  476. static int wcd_mbhc_get_plug_from_adc(int adc_result)
  477. {
  478. enum wcd_mbhc_plug_type plug_type = MBHC_PLUG_TYPE_INVALID;
  479. if (adc_result < WCD_MBHC_ADC_HPH_THRESHOLD_MV)
  480. plug_type = MBHC_PLUG_TYPE_HEADPHONE;
  481. else if (adc_result > WCD_MBHC_ADC_HS_THRESHOLD_MV)
  482. plug_type = MBHC_PLUG_TYPE_HIGH_HPH;
  483. else
  484. plug_type = MBHC_PLUG_TYPE_HEADSET;
  485. pr_debug("%s: plug type is %d found\n", __func__, plug_type);
  486. return plug_type;
  487. }
  488. static void wcd_correct_swch_plug(struct work_struct *work)
  489. {
  490. struct wcd_mbhc *mbhc;
  491. struct snd_soc_codec *codec;
  492. enum wcd_mbhc_plug_type plug_type = MBHC_PLUG_TYPE_INVALID;
  493. unsigned long timeout;
  494. bool wrk_complete = false;
  495. int pt_gnd_mic_swap_cnt = 0;
  496. int no_gnd_mic_swap_cnt = 0;
  497. bool is_pa_on = false, spl_hs = false, spl_hs_reported = false;
  498. int ret = 0;
  499. int spl_hs_count = 0;
  500. int output_mv = 0;
  501. int cross_conn;
  502. int try = 0;
  503. pr_debug("%s: enter\n", __func__);
  504. mbhc = container_of(work, struct wcd_mbhc, correct_plug_swch);
  505. codec = mbhc->codec;
  506. WCD_MBHC_RSC_LOCK(mbhc);
  507. /* Mask ADC COMPLETE interrupt */
  508. wcd_mbhc_hs_elec_irq(mbhc, WCD_MBHC_ELEC_HS_INS, false);
  509. WCD_MBHC_RSC_UNLOCK(mbhc);
  510. /* Check for cross connection */
  511. do {
  512. cross_conn = wcd_check_cross_conn(mbhc);
  513. try++;
  514. } while (try < GND_MIC_SWAP_THRESHOLD);
  515. if (cross_conn > 0) {
  516. plug_type = MBHC_PLUG_TYPE_GND_MIC_SWAP;
  517. pr_debug("%s: cross connection found, Plug type %d\n",
  518. __func__, plug_type);
  519. goto correct_plug_type;
  520. }
  521. /* Find plug type */
  522. output_mv = wcd_measure_adc_continuous(mbhc);
  523. plug_type = wcd_mbhc_get_plug_from_adc(output_mv);
  524. /*
  525. * Report plug type if it is either headset or headphone
  526. * else start the 3 sec loop
  527. */
  528. if ((plug_type == MBHC_PLUG_TYPE_HEADSET ||
  529. plug_type == MBHC_PLUG_TYPE_HEADPHONE) &&
  530. (!wcd_swch_level_remove(mbhc))) {
  531. WCD_MBHC_RSC_LOCK(mbhc);
  532. wcd_mbhc_find_plug_and_report(mbhc, plug_type);
  533. WCD_MBHC_RSC_UNLOCK(mbhc);
  534. }
  535. /*
  536. * Set DETECTION_DONE bit for HEADSET and ANC_HEADPHONE,
  537. * so that btn press/release interrupt can be generated.
  538. */
  539. if (mbhc->current_plug == MBHC_PLUG_TYPE_HEADSET ||
  540. mbhc->current_plug == MBHC_PLUG_TYPE_ANC_HEADPHONE) {
  541. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_ADC_MODE, 0);
  542. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_ADC_EN, 0);
  543. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_DETECTION_DONE, 1);
  544. }
  545. correct_plug_type:
  546. timeout = jiffies + msecs_to_jiffies(HS_DETECT_PLUG_TIME_MS);
  547. while (!time_after(jiffies, timeout)) {
  548. if (mbhc->hs_detect_work_stop) {
  549. pr_debug("%s: stop requested: %d\n", __func__,
  550. mbhc->hs_detect_work_stop);
  551. wcd_micbias_disable(mbhc);
  552. goto exit;
  553. }
  554. /* allow sometime and re-check stop requested again */
  555. msleep(20);
  556. if (mbhc->hs_detect_work_stop) {
  557. pr_debug("%s: stop requested: %d\n", __func__,
  558. mbhc->hs_detect_work_stop);
  559. wcd_micbias_disable(mbhc);
  560. goto exit;
  561. }
  562. msleep(180);
  563. /*
  564. * Use ADC single mode to minimize the chance of missing out
  565. * btn press/release for HEADSET type during correct work.
  566. */
  567. output_mv = wcd_measure_adc_once(mbhc, MUX_CTL_IN2P);
  568. /*
  569. * instead of hogging system by contineous polling, wait for
  570. * sometime and re-check stop request again.
  571. */
  572. plug_type = wcd_mbhc_get_plug_from_adc(output_mv);
  573. if ((output_mv > WCD_MBHC_ADC_HS_THRESHOLD_MV) &&
  574. (spl_hs_count < WCD_MBHC_SPL_HS_CNT)) {
  575. spl_hs = wcd_mbhc_adc_check_for_spl_headset(mbhc,
  576. &spl_hs_count);
  577. if (spl_hs_count == WCD_MBHC_SPL_HS_CNT) {
  578. output_mv = WCD_MBHC_ADC_HS_THRESHOLD_MV;
  579. spl_hs = true;
  580. mbhc->micbias_enable = true;
  581. }
  582. }
  583. if (mbhc->mbhc_cb->hph_pa_on_status)
  584. is_pa_on = mbhc->mbhc_cb->hph_pa_on_status(mbhc->codec);
  585. if ((output_mv <= WCD_MBHC_ADC_HS_THRESHOLD_MV) &&
  586. (!is_pa_on)) {
  587. /* Check for cross connection*/
  588. ret = wcd_check_cross_conn(mbhc);
  589. if (ret < 0)
  590. continue;
  591. else if (ret > 0) {
  592. pt_gnd_mic_swap_cnt++;
  593. no_gnd_mic_swap_cnt = 0;
  594. if (pt_gnd_mic_swap_cnt <
  595. GND_MIC_SWAP_THRESHOLD) {
  596. continue;
  597. } else if (pt_gnd_mic_swap_cnt >
  598. GND_MIC_SWAP_THRESHOLD) {
  599. /*
  600. * This is due to GND/MIC switch didn't
  601. * work, Report unsupported plug.
  602. */
  603. pr_debug("%s: switch did not work\n",
  604. __func__);
  605. plug_type = MBHC_PLUG_TYPE_GND_MIC_SWAP;
  606. goto report;
  607. } else {
  608. plug_type = MBHC_PLUG_TYPE_GND_MIC_SWAP;
  609. }
  610. } else {
  611. no_gnd_mic_swap_cnt++;
  612. pt_gnd_mic_swap_cnt = 0;
  613. plug_type = wcd_mbhc_get_plug_from_adc(
  614. output_mv);
  615. if ((no_gnd_mic_swap_cnt <
  616. GND_MIC_SWAP_THRESHOLD) &&
  617. (spl_hs_count != WCD_MBHC_SPL_HS_CNT)) {
  618. continue;
  619. } else {
  620. no_gnd_mic_swap_cnt = 0;
  621. }
  622. }
  623. if ((pt_gnd_mic_swap_cnt == GND_MIC_SWAP_THRESHOLD) &&
  624. (plug_type == MBHC_PLUG_TYPE_GND_MIC_SWAP)) {
  625. /*
  626. * if switch is toggled, check again,
  627. * otherwise report unsupported plug
  628. */
  629. if (mbhc->mbhc_cfg->swap_gnd_mic &&
  630. mbhc->mbhc_cfg->swap_gnd_mic(codec,
  631. true)) {
  632. pr_debug("%s: US_EU gpio present,flip switch\n"
  633. , __func__);
  634. continue;
  635. }
  636. }
  637. }
  638. if (output_mv > WCD_MBHC_ADC_HS_THRESHOLD_MV) {
  639. pr_debug("%s: cable is extension cable\n", __func__);
  640. plug_type = MBHC_PLUG_TYPE_HIGH_HPH;
  641. wrk_complete = true;
  642. } else {
  643. pr_debug("%s: cable might be headset: %d\n", __func__,
  644. plug_type);
  645. if (plug_type != MBHC_PLUG_TYPE_GND_MIC_SWAP) {
  646. plug_type = wcd_mbhc_get_plug_from_adc(
  647. output_mv);
  648. if (!spl_hs_reported &&
  649. spl_hs_count == WCD_MBHC_SPL_HS_CNT) {
  650. spl_hs_reported = true;
  651. WCD_MBHC_RSC_LOCK(mbhc);
  652. wcd_mbhc_find_plug_and_report(mbhc,
  653. plug_type);
  654. WCD_MBHC_RSC_UNLOCK(mbhc);
  655. continue;
  656. } else if (spl_hs_reported)
  657. continue;
  658. /*
  659. * Report headset only if not already reported
  660. * and if there is not button press without
  661. * release
  662. */
  663. if ((mbhc->current_plug !=
  664. MBHC_PLUG_TYPE_HEADSET) &&
  665. (mbhc->current_plug !=
  666. MBHC_PLUG_TYPE_ANC_HEADPHONE) &&
  667. !wcd_swch_level_remove(mbhc)) {
  668. pr_debug("%s: cable is %s headset\n",
  669. __func__,
  670. ((spl_hs_count ==
  671. WCD_MBHC_SPL_HS_CNT) ?
  672. "special ":""));
  673. goto report;
  674. }
  675. }
  676. wrk_complete = false;
  677. }
  678. }
  679. if (!wrk_complete) {
  680. /*
  681. * If plug_tye is headset, we might have already reported either
  682. * in detect_plug-type or in above while loop, no need to report
  683. * again
  684. */
  685. if ((plug_type == MBHC_PLUG_TYPE_HEADSET) ||
  686. (plug_type == MBHC_PLUG_TYPE_ANC_HEADPHONE)) {
  687. pr_debug("%s: plug_type:0x%x already reported\n",
  688. __func__, mbhc->current_plug);
  689. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_ADC_MODE, 0);
  690. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_ADC_EN, 0);
  691. goto enable_supply;
  692. }
  693. }
  694. if (plug_type == MBHC_PLUG_TYPE_HIGH_HPH) {
  695. if (wcd_is_special_headset(mbhc)) {
  696. pr_debug("%s: Special headset found %d\n",
  697. __func__, plug_type);
  698. plug_type = MBHC_PLUG_TYPE_HEADSET;
  699. } else {
  700. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_ELECT_ISRC_EN, 1);
  701. }
  702. }
  703. report:
  704. if (wcd_swch_level_remove(mbhc)) {
  705. pr_debug("%s: Switch level is low\n", __func__);
  706. goto exit;
  707. }
  708. pr_debug("%s: Valid plug found, plug type %d wrk_cmpt %d btn_intr %d\n",
  709. __func__, plug_type, wrk_complete,
  710. mbhc->btn_press_intr);
  711. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_ADC_MODE, 0);
  712. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_ADC_EN, 0);
  713. WCD_MBHC_RSC_LOCK(mbhc);
  714. wcd_mbhc_find_plug_and_report(mbhc, plug_type);
  715. WCD_MBHC_RSC_UNLOCK(mbhc);
  716. enable_supply:
  717. /*
  718. * Set DETECTION_DONE bit for HEADSET and ANC_HEADPHONE,
  719. * so that btn press/release interrupt can be generated.
  720. * For other plug type, clear the bit.
  721. */
  722. if (plug_type == MBHC_PLUG_TYPE_HEADSET ||
  723. plug_type == MBHC_PLUG_TYPE_ANC_HEADPHONE)
  724. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_DETECTION_DONE, 1);
  725. else
  726. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_DETECTION_DONE, 0);
  727. if (mbhc->mbhc_cb->mbhc_micbias_control)
  728. wcd_mbhc_adc_update_fsm_source(mbhc, plug_type);
  729. exit:
  730. if (mbhc->mbhc_cb->mbhc_micbias_control &&
  731. !mbhc->micbias_enable)
  732. mbhc->mbhc_cb->mbhc_micbias_control(codec, MIC_BIAS_2,
  733. MICB_DISABLE);
  734. /*
  735. * If plug type is corrected from special headset to headphone,
  736. * clear the micbias enable flag, set micbias back to 1.8V and
  737. * disable micbias.
  738. */
  739. if (plug_type == MBHC_PLUG_TYPE_HEADPHONE &&
  740. mbhc->micbias_enable) {
  741. if (mbhc->mbhc_cb->mbhc_micbias_control)
  742. mbhc->mbhc_cb->mbhc_micbias_control(
  743. codec, MIC_BIAS_2,
  744. MICB_DISABLE);
  745. if (mbhc->mbhc_cb->mbhc_micb_ctrl_thr_mic)
  746. mbhc->mbhc_cb->mbhc_micb_ctrl_thr_mic(
  747. codec,
  748. MIC_BIAS_2, false);
  749. if (mbhc->mbhc_cb->set_micbias_value) {
  750. mbhc->mbhc_cb->set_micbias_value(codec);
  751. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_MICB_CTRL, 0);
  752. }
  753. mbhc->micbias_enable = false;
  754. }
  755. if (mbhc->mbhc_cfg->detect_extn_cable &&
  756. ((plug_type == MBHC_PLUG_TYPE_HEADPHONE) ||
  757. (plug_type == MBHC_PLUG_TYPE_HEADSET)) &&
  758. !mbhc->hs_detect_work_stop) {
  759. WCD_MBHC_RSC_LOCK(mbhc);
  760. wcd_mbhc_hs_elec_irq(mbhc, WCD_MBHC_ELEC_HS_REM, true);
  761. WCD_MBHC_RSC_UNLOCK(mbhc);
  762. }
  763. /*
  764. * Enable ADC COMPLETE interrupt for HEADPHONE.
  765. * Btn release may happen after the correct work, ADC COMPLETE
  766. * interrupt needs to be captured to correct plug type.
  767. */
  768. if (plug_type == MBHC_PLUG_TYPE_HEADPHONE) {
  769. WCD_MBHC_RSC_LOCK(mbhc);
  770. wcd_mbhc_hs_elec_irq(mbhc, WCD_MBHC_ELEC_HS_INS,
  771. true);
  772. WCD_MBHC_RSC_UNLOCK(mbhc);
  773. }
  774. if (mbhc->mbhc_cb->hph_pull_down_ctrl)
  775. mbhc->mbhc_cb->hph_pull_down_ctrl(codec, true);
  776. mbhc->mbhc_cb->lock_sleep(mbhc, false);
  777. pr_debug("%s: leave\n", __func__);
  778. }
  779. static irqreturn_t wcd_mbhc_adc_hs_rem_irq(int irq, void *data)
  780. {
  781. struct wcd_mbhc *mbhc = data;
  782. unsigned long timeout;
  783. int adc_threshold, output_mv, retry = 0;
  784. pr_debug("%s: enter\n", __func__);
  785. WCD_MBHC_RSC_LOCK(mbhc);
  786. timeout = jiffies +
  787. msecs_to_jiffies(WCD_FAKE_REMOVAL_MIN_PERIOD_MS);
  788. adc_threshold = ((WCD_MBHC_ADC_HS_THRESHOLD_MV *
  789. wcd_mbhc_get_micbias(mbhc)) /
  790. WCD_MBHC_ADC_MICBIAS_MV);
  791. do {
  792. retry++;
  793. /*
  794. * read output_mv every 10ms to look for
  795. * any change in IN2_P
  796. */
  797. usleep_range(10000, 10100);
  798. output_mv = wcd_measure_adc_once(mbhc, MUX_CTL_IN2P);
  799. pr_debug("%s: Check for fake removal: output_mv %d\n",
  800. __func__, output_mv);
  801. if ((output_mv <= adc_threshold) &&
  802. retry > FAKE_REM_RETRY_ATTEMPTS) {
  803. pr_debug("%s: headset is NOT actually removed\n",
  804. __func__);
  805. goto exit;
  806. }
  807. } while (!time_after(jiffies, timeout));
  808. if (wcd_swch_level_remove(mbhc)) {
  809. pr_debug("%s: Switch level is low ", __func__);
  810. goto exit;
  811. }
  812. /*
  813. * ADC COMPLETE and ELEC_REM interrupts are both enabled for HEADPHONE,
  814. * need to reject the ADC COMPLETE interrupt which follows ELEC_REM one
  815. * when HEADPHONE is removed.
  816. */
  817. if (mbhc->current_plug == MBHC_PLUG_TYPE_HEADPHONE)
  818. mbhc->extn_cable_hph_rem = true;
  819. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_DETECTION_DONE, 0);
  820. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_ADC_MODE, 0);
  821. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_ADC_EN, 0);
  822. wcd_mbhc_elec_hs_report_unplug(mbhc);
  823. exit:
  824. WCD_MBHC_RSC_UNLOCK(mbhc);
  825. pr_debug("%s: leave\n", __func__);
  826. return IRQ_HANDLED;
  827. }
  828. static irqreturn_t wcd_mbhc_adc_hs_ins_irq(int irq, void *data)
  829. {
  830. struct wcd_mbhc *mbhc = data;
  831. pr_debug("%s: enter\n", __func__);
  832. /*
  833. * ADC COMPLETE and ELEC_REM interrupts are both enabled for HEADPHONE,
  834. * need to reject the ADC COMPLETE interrupt which follows ELEC_REM one
  835. * when HEADPHONE is removed.
  836. */
  837. if (mbhc->extn_cable_hph_rem == true) {
  838. mbhc->extn_cable_hph_rem = false;
  839. pr_debug("%s: leave\n", __func__);
  840. return IRQ_HANDLED;
  841. }
  842. WCD_MBHC_RSC_LOCK(mbhc);
  843. /*
  844. * If current plug is headphone then there is no chance to
  845. * get ADC complete interrupt, so connected cable should be
  846. * headset not headphone.
  847. */
  848. if (mbhc->current_plug == MBHC_PLUG_TYPE_HEADPHONE) {
  849. wcd_mbhc_hs_elec_irq(mbhc, WCD_MBHC_ELEC_HS_INS, false);
  850. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_DETECTION_DONE, 1);
  851. wcd_mbhc_find_plug_and_report(mbhc, MBHC_PLUG_TYPE_HEADSET);
  852. WCD_MBHC_RSC_UNLOCK(mbhc);
  853. return IRQ_HANDLED;
  854. }
  855. if (!mbhc->mbhc_cfg->detect_extn_cable) {
  856. pr_debug("%s: Returning as Extension cable feature not enabled\n",
  857. __func__);
  858. WCD_MBHC_RSC_UNLOCK(mbhc);
  859. return IRQ_HANDLED;
  860. }
  861. pr_debug("%s: Disable electrical headset insertion interrupt\n",
  862. __func__);
  863. wcd_mbhc_hs_elec_irq(mbhc, WCD_MBHC_ELEC_HS_INS, false);
  864. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_ELECT_SCHMT_ISRC, 0);
  865. WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_ELECT_ISRC_EN, 0);
  866. mbhc->is_extn_cable = true;
  867. mbhc->btn_press_intr = false;
  868. wcd_mbhc_adc_detect_plug_type(mbhc);
  869. WCD_MBHC_RSC_UNLOCK(mbhc);
  870. pr_debug("%s: leave\n", __func__);
  871. return IRQ_HANDLED;
  872. }
  873. static struct wcd_mbhc_fn mbhc_fn = {
  874. .wcd_mbhc_hs_ins_irq = wcd_mbhc_adc_hs_ins_irq,
  875. .wcd_mbhc_hs_rem_irq = wcd_mbhc_adc_hs_rem_irq,
  876. .wcd_mbhc_detect_plug_type = wcd_mbhc_adc_detect_plug_type,
  877. .wcd_mbhc_detect_anc_plug_type = wcd_mbhc_adc_detect_anc_plug_type,
  878. .wcd_cancel_hs_detect_plug = wcd_cancel_hs_detect_plug,
  879. };
  880. /* Function: wcd_mbhc_adc_init
  881. * @mbhc: MBHC function pointer
  882. * Description: Initialize MBHC ADC related function pointers to MBHC structure
  883. */
  884. void wcd_mbhc_adc_init(struct wcd_mbhc *mbhc)
  885. {
  886. if (!mbhc) {
  887. pr_err("%s: mbhc is NULL\n", __func__);
  888. return;
  889. }
  890. mbhc->mbhc_fn = &mbhc_fn;
  891. INIT_WORK(&mbhc->correct_plug_swch, wcd_correct_swch_plug);
  892. }
  893. EXPORT_SYMBOL(wcd_mbhc_adc_init);