Lines Matching +full:disable +full:- +full:report +full:- +full:mask

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * extcon-arizona.c - Extcon driver Wolfson Arizona devices
5 * Copyright (C) 2012-2014 Wolfson Microelectronics plc
26 #include <dt-bindings/mfd/arizona.h>
33 * The hardware supports 8 ranges / buttons, but the snd-jack interface
34 * only supports 6 buttons (button 0-5).
100 struct arizona *arizona = info->arizona; in arizona_extcon_hp_clamp()
101 unsigned int mask = 0, val = 0; in arizona_extcon_hp_clamp() local
105 switch (arizona->type) { in arizona_extcon_hp_clamp()
108 mask = 0; in arizona_extcon_hp_clamp()
112 mask = ARIZONA_HP1L_SHRTO | ARIZONA_HP1L_FLWR | in arizona_extcon_hp_clamp()
122 ret = regmap_update_bits(arizona->regmap, in arizona_extcon_hp_clamp()
127 dev_warn(arizona->dev, "Failed to set TST_CAP_SEL: %d\n", ret); in arizona_extcon_hp_clamp()
130 mask = ARIZONA_RMV_SHRT_HP1L; in arizona_extcon_hp_clamp()
136 snd_soc_dapm_mutex_lock(arizona->dapm); in arizona_extcon_hp_clamp()
138 arizona->hpdet_clamp = clamp; in arizona_extcon_hp_clamp()
142 ret = regmap_update_bits(arizona->regmap, in arizona_extcon_hp_clamp()
147 dev_warn(arizona->dev, "Failed to disable headphone outputs: %d\n", ret); in arizona_extcon_hp_clamp()
150 if (mask) { in arizona_extcon_hp_clamp()
151 ret = regmap_update_bits(arizona->regmap, ARIZONA_HP_CTRL_1L, in arizona_extcon_hp_clamp()
152 mask, val); in arizona_extcon_hp_clamp()
154 dev_warn(arizona->dev, "Failed to do clamp: %d\n", ret); in arizona_extcon_hp_clamp()
156 ret = regmap_update_bits(arizona->regmap, ARIZONA_HP_CTRL_1R, in arizona_extcon_hp_clamp()
157 mask, val); in arizona_extcon_hp_clamp()
159 dev_warn(arizona->dev, "Failed to do clamp: %d\n", ret); in arizona_extcon_hp_clamp()
164 ret = regmap_update_bits(arizona->regmap, in arizona_extcon_hp_clamp()
167 ARIZONA_OUT1R_ENA, arizona->hp_ena); in arizona_extcon_hp_clamp()
169 dev_warn(arizona->dev, "Failed to restore headphone outputs: %d\n", ret); in arizona_extcon_hp_clamp()
172 snd_soc_dapm_mutex_unlock(arizona->dapm); in arizona_extcon_hp_clamp()
177 struct arizona *arizona = info->arizona; in arizona_extcon_set_mode()
179 mode %= info->micd_num_modes; in arizona_extcon_set_mode()
181 gpiod_set_value_cansleep(info->micd_pol_gpio, in arizona_extcon_set_mode()
182 info->micd_modes[mode].gpio); in arizona_extcon_set_mode()
184 regmap_update_bits(arizona->regmap, ARIZONA_MIC_DETECT_1, in arizona_extcon_set_mode()
186 info->micd_modes[mode].bias << in arizona_extcon_set_mode()
188 regmap_update_bits(arizona->regmap, ARIZONA_ACCESSORY_DETECT_MODE_1, in arizona_extcon_set_mode()
189 ARIZONA_ACCDET_SRC, info->micd_modes[mode].src); in arizona_extcon_set_mode()
191 info->micd_mode = mode; in arizona_extcon_set_mode()
193 dev_dbg(arizona->dev, "Set jack polarity to %d\n", mode); in arizona_extcon_set_mode()
198 switch (info->micd_modes[0].bias) { in arizona_extcon_get_micbias()
212 struct arizona *arizona = info->arizona; in arizona_extcon_pulse_micbias()
214 struct snd_soc_dapm_context *dapm = arizona->dapm; in arizona_extcon_pulse_micbias()
220 dev_warn(arizona->dev, "Failed to enable %s: %d\n", widget, ret); in arizona_extcon_pulse_micbias()
224 if (!arizona->pdata.micd_force_micbias) { in arizona_extcon_pulse_micbias()
227 dev_warn(arizona->dev, "Failed to disable %s: %d\n", widget, ret); in arizona_extcon_pulse_micbias()
235 struct arizona *arizona = info->arizona; in arizona_start_mic()
241 pm_runtime_get_sync(arizona->dev); in arizona_start_mic()
243 if (info->detecting) { in arizona_start_mic()
244 ret = regulator_allow_bypass(info->micvdd, false); in arizona_start_mic()
246 dev_err(arizona->dev, "Failed to regulate MICVDD: %d\n", ret); in arizona_start_mic()
249 ret = regulator_enable(info->micvdd); in arizona_start_mic()
251 dev_err(arizona->dev, "Failed to enable MICVDD: %d\n", ret); in arizona_start_mic()
253 if (info->micd_reva) { in arizona_start_mic()
260 regmap_multi_reg_write(arizona->regmap, reva, ARRAY_SIZE(reva)); in arizona_start_mic()
263 if (info->detecting && arizona->pdata.micd_software_compare) in arizona_start_mic()
268 regmap_update_bits(arizona->regmap, in arizona_start_mic()
274 ret = regmap_update_bits_check(arizona->regmap, ARIZONA_MIC_DETECT_1, in arizona_start_mic()
278 dev_err(arizona->dev, "Failed to enable micd: %d\n", ret); in arizona_start_mic()
280 regulator_disable(info->micvdd); in arizona_start_mic()
281 pm_runtime_put_autosuspend(arizona->dev); in arizona_start_mic()
287 struct arizona *arizona = info->arizona; in arizona_stop_mic()
289 struct snd_soc_dapm_context *dapm = arizona->dapm; in arizona_stop_mic()
294 ret = regmap_update_bits_check(arizona->regmap, ARIZONA_MIC_DETECT_1, in arizona_stop_mic()
298 dev_err(arizona->dev, "Failed to disable micd: %d\n", ret); in arizona_stop_mic()
302 dev_warn(arizona->dev, "Failed to disable %s: %d\n", widget, ret); in arizona_stop_mic()
306 if (info->micd_reva) { in arizona_stop_mic()
313 regmap_multi_reg_write(arizona->regmap, reva, ARRAY_SIZE(reva)); in arizona_stop_mic()
316 ret = regulator_allow_bypass(info->micvdd, true); in arizona_stop_mic()
318 dev_err(arizona->dev, "Failed to bypass MICVDD: %d\n", ret); in arizona_stop_mic()
321 regulator_disable(info->micvdd); in arizona_stop_mic()
322 pm_runtime_mark_last_busy(arizona->dev); in arizona_stop_mic()
323 pm_runtime_put_autosuspend(arizona->dev); in arizona_stop_mic()
351 struct arizona *arizona = info->arizona; in arizona_hpdet_read()
355 ret = regmap_read(arizona->regmap, ARIZONA_HEADPHONE_DETECT_2, &val); in arizona_hpdet_read()
357 dev_err(arizona->dev, "Failed to read HPDET status: %d\n", ret); in arizona_hpdet_read()
361 switch (info->hpdet_ip_version) { in arizona_hpdet_read()
364 dev_err(arizona->dev, "HPDET did not complete: %x\n", val); in arizona_hpdet_read()
365 return -EAGAIN; in arizona_hpdet_read()
373 dev_err(arizona->dev, "HPDET did not complete: %x\n", val); in arizona_hpdet_read()
374 return -EAGAIN; in arizona_hpdet_read()
377 ret = regmap_read(arizona->regmap, ARIZONA_HP_DACVAL, &val); in arizona_hpdet_read()
379 dev_err(arizona->dev, "Failed to read HP value: %d\n", ret); in arizona_hpdet_read()
380 return -EAGAIN; in arizona_hpdet_read()
383 regmap_read(arizona->regmap, ARIZONA_HEADPHONE_DETECT_1, in arizona_hpdet_read()
388 if (range < ARRAY_SIZE(arizona_hpdet_b_ranges) - 1 && in arizona_hpdet_read()
392 dev_dbg(arizona->dev, "Moving to HPDET range %d\n", range); in arizona_hpdet_read()
393 regmap_update_bits(arizona->regmap, in arizona_hpdet_read()
398 return -EAGAIN; in arizona_hpdet_read()
401 /* If we go out of range report top of range */ in arizona_hpdet_read()
404 dev_dbg(arizona->dev, "Measurement out of range\n"); in arizona_hpdet_read()
408 dev_dbg(arizona->dev, "HPDET read %d in range %d\n", val, range); in arizona_hpdet_read()
411 / ((val * 100) - in arizona_hpdet_read()
417 dev_err(arizona->dev, "HPDET did not complete: %x\n", val); in arizona_hpdet_read()
418 return -EAGAIN; in arizona_hpdet_read()
425 regmap_read(arizona->regmap, ARIZONA_HEADPHONE_DETECT_1, in arizona_hpdet_read()
430 /* Skip up a range, or report? */ in arizona_hpdet_read()
431 if (range < ARRAY_SIZE(arizona_hpdet_c_ranges) - 1 && in arizona_hpdet_read()
434 dev_dbg(arizona->dev, "Moving to HPDET range %d-%d\n", in arizona_hpdet_read()
437 regmap_update_bits(arizona->regmap, in arizona_hpdet_read()
442 return -EAGAIN; in arizona_hpdet_read()
446 dev_dbg(arizona->dev, "Reporting range boundary %d\n", in arizona_hpdet_read()
453 dev_warn(arizona->dev, "Unknown HPDET IP revision %d\n", info->hpdet_ip_version); in arizona_hpdet_read()
454 return -EINVAL; in arizona_hpdet_read()
457 dev_dbg(arizona->dev, "HP impedance %d ohms\n", val); in arizona_hpdet_read()
464 struct arizona *arizona = info->arizona; in arizona_hpdet_do_id()
465 int id_gpio = arizona->pdata.hpdet_id_gpio; in arizona_hpdet_do_id()
467 if (!arizona->pdata.hpdet_acc_id) in arizona_hpdet_do_id()
474 info->hpdet_res[info->num_hpdet_res++] = *reading; in arizona_hpdet_do_id()
477 if (id_gpio && info->num_hpdet_res == 1) { in arizona_hpdet_do_id()
478 dev_dbg(arizona->dev, "Measuring mic\n"); in arizona_hpdet_do_id()
480 regmap_update_bits(arizona->regmap, in arizona_hpdet_do_id()
485 info->micd_modes[0].src); in arizona_hpdet_do_id()
489 regmap_update_bits(arizona->regmap, ARIZONA_HEADPHONE_DETECT_1, in arizona_hpdet_do_id()
491 return -EAGAIN; in arizona_hpdet_do_id()
495 dev_dbg(arizona->dev, "HPDET measured %d %d\n", in arizona_hpdet_do_id()
496 info->hpdet_res[0], info->hpdet_res[1]); in arizona_hpdet_do_id()
498 /* Take the headphone impedance for the main report */ in arizona_hpdet_do_id()
499 *reading = info->hpdet_res[0]; in arizona_hpdet_do_id()
502 if (*reading >= ARIZONA_HPDET_MAX && !info->hpdet_retried) { in arizona_hpdet_do_id()
503 dev_dbg(arizona->dev, "Retrying high impedance\n"); in arizona_hpdet_do_id()
504 info->num_hpdet_res = 0; in arizona_hpdet_do_id()
505 info->hpdet_retried = true; in arizona_hpdet_do_id()
507 pm_runtime_put(arizona->dev); in arizona_hpdet_do_id()
508 return -EAGAIN; in arizona_hpdet_do_id()
514 if (!id_gpio || info->hpdet_res[1] > 50) { in arizona_hpdet_do_id()
515 dev_dbg(arizona->dev, "Detected mic\n"); in arizona_hpdet_do_id()
517 info->detecting = true; in arizona_hpdet_do_id()
519 dev_dbg(arizona->dev, "Detected headphone\n"); in arizona_hpdet_do_id()
523 regmap_update_bits(arizona->regmap, ARIZONA_ACCESSORY_DETECT_MODE_1, in arizona_hpdet_do_id()
524 ARIZONA_ACCDET_SRC, info->micd_modes[0].src); in arizona_hpdet_do_id()
532 struct arizona *arizona = info->arizona; in arizona_hpdet_irq()
533 int id_gpio = arizona->pdata.hpdet_id_gpio; in arizona_hpdet_irq()
534 int ret, reading, state, report; in arizona_hpdet_irq() local
537 mutex_lock(&info->lock); in arizona_hpdet_irq()
540 if (!info->hpdet_active) { in arizona_hpdet_irq()
541 dev_warn(arizona->dev, "Spurious HPDET IRQ\n"); in arizona_hpdet_irq()
542 mutex_unlock(&info->lock); in arizona_hpdet_irq()
547 state = info->jack->status & SND_JACK_MECHANICAL; in arizona_hpdet_irq()
549 dev_dbg(arizona->dev, "Ignoring HPDET for removed cable\n"); in arizona_hpdet_irq()
554 if (ret == -EAGAIN) in arizona_hpdet_irq()
561 regmap_update_bits(arizona->regmap, in arizona_hpdet_irq()
567 if (ret == -EAGAIN) in arizona_hpdet_irq()
572 /* Report high impedence cables as line outputs */ in arizona_hpdet_irq()
574 report = SND_JACK_LINEOUT; in arizona_hpdet_irq()
576 report = SND_JACK_HEADPHONE; in arizona_hpdet_irq()
578 snd_soc_jack_report(info->jack, report, SND_JACK_LINEOUT | SND_JACK_HEADPHONE); in arizona_hpdet_irq()
582 regmap_update_bits(arizona->regmap, in arizona_hpdet_irq()
593 if (state && (mic || info->mic)) in arizona_hpdet_irq()
596 if (info->hpdet_active) { in arizona_hpdet_irq()
597 pm_runtime_put_autosuspend(arizona->dev); in arizona_hpdet_irq()
598 info->hpdet_active = false; in arizona_hpdet_irq()
603 info->hpdet_done = true; in arizona_hpdet_irq()
606 mutex_unlock(&info->lock); in arizona_hpdet_irq()
613 struct arizona *arizona = info->arizona; in arizona_identify_headphone()
616 if (info->hpdet_done) in arizona_identify_headphone()
619 dev_dbg(arizona->dev, "Starting HPDET\n"); in arizona_identify_headphone()
622 pm_runtime_get_sync(arizona->dev); in arizona_identify_headphone()
624 info->hpdet_active = true; in arizona_identify_headphone()
630 ret = regmap_update_bits(arizona->regmap, in arizona_identify_headphone()
633 arizona->pdata.hpdet_channel); in arizona_identify_headphone()
635 dev_err(arizona->dev, "Failed to set HPDET mode: %d\n", ret); in arizona_identify_headphone()
639 ret = regmap_update_bits(arizona->regmap, ARIZONA_HEADPHONE_DETECT_1, in arizona_identify_headphone()
642 dev_err(arizona->dev, "Can't start HPDETL measurement: %d\n", ret); in arizona_identify_headphone()
650 pm_runtime_put_autosuspend(arizona->dev); in arizona_identify_headphone()
652 /* Just report headphone */ in arizona_identify_headphone()
653 snd_soc_jack_report(info->jack, SND_JACK_HEADPHONE, in arizona_identify_headphone()
656 if (info->mic) in arizona_identify_headphone()
659 info->hpdet_active = false; in arizona_identify_headphone()
664 struct arizona *arizona = info->arizona; in arizona_start_hpdet_acc_id()
669 dev_dbg(arizona->dev, "Starting identification via HPDET\n"); in arizona_start_hpdet_acc_id()
672 pm_runtime_get_sync(arizona->dev); in arizona_start_hpdet_acc_id()
674 info->hpdet_active = true; in arizona_start_hpdet_acc_id()
678 ret = regmap_update_bits(arizona->regmap, in arizona_start_hpdet_acc_id()
681 info->micd_modes[0].src | in arizona_start_hpdet_acc_id()
682 arizona->pdata.hpdet_channel); in arizona_start_hpdet_acc_id()
684 dev_err(arizona->dev, "Failed to set HPDET mode: %d\n", ret); in arizona_start_hpdet_acc_id()
688 if (arizona->pdata.hpdet_acc_id_line) { in arizona_start_hpdet_acc_id()
689 ret = regmap_update_bits(arizona->regmap, in arizona_start_hpdet_acc_id()
693 dev_err(arizona->dev, "Can't start HPDETL measurement: %d\n", ret); in arizona_start_hpdet_acc_id()
703 /* Just report headphone */ in arizona_start_hpdet_acc_id()
704 snd_soc_jack_report(info->jack, SND_JACK_HEADPHONE, in arizona_start_hpdet_acc_id()
707 info->hpdet_active = false; in arizona_start_hpdet_acc_id()
716 mutex_lock(&info->lock); in arizona_micd_timeout_work()
718 dev_dbg(info->arizona->dev, "MICD timed out, reporting HP\n"); in arizona_micd_timeout_work()
720 info->detecting = false; in arizona_micd_timeout_work()
724 mutex_unlock(&info->lock); in arizona_micd_timeout_work()
729 struct arizona *arizona = info->arizona; in arizona_micd_adc_read()
733 /* Must disable MICD before we read the ADCVAL */ in arizona_micd_adc_read()
734 regmap_update_bits(arizona->regmap, ARIZONA_MIC_DETECT_1, in arizona_micd_adc_read()
737 ret = regmap_read(arizona->regmap, ARIZONA_MIC_DETECT_4, &val); in arizona_micd_adc_read()
739 dev_err(arizona->dev, "Failed to read MICDET_ADCVAL: %d\n", ret); in arizona_micd_adc_read()
743 dev_dbg(arizona->dev, "MICDET_ADCVAL: %x\n", val); in arizona_micd_adc_read()
765 struct arizona *arizona = info->arizona; in arizona_micd_read()
770 ret = regmap_read(arizona->regmap, ARIZONA_MIC_DETECT_3, &val); in arizona_micd_read()
772 dev_err(arizona->dev, "Failed to read MICDET: %d\n", ret); in arizona_micd_read()
776 dev_dbg(arizona->dev, "MICDET: %x\n", val); in arizona_micd_read()
779 dev_warn(arizona->dev, "Microphone detection state invalid\n"); in arizona_micd_read()
780 return -EINVAL; in arizona_micd_read()
785 dev_err(arizona->dev, "Failed to get valid MICDET value\n"); in arizona_micd_read()
786 return -EINVAL; in arizona_micd_read()
795 struct arizona *arizona = info->arizona; in arizona_micdet_reading()
798 if (info->detecting && arizona->pdata.micd_software_compare) in arizona_micdet_reading()
809 dev_warn(arizona->dev, "Detected open circuit\n"); in arizona_micdet_reading()
810 info->mic = false; in arizona_micdet_reading()
811 info->detecting = false; in arizona_micdet_reading()
816 /* If we got a high impedence we should have a headset, report it. */ in arizona_micdet_reading()
818 info->mic = true; in arizona_micdet_reading()
819 info->detecting = false; in arizona_micdet_reading()
823 snd_soc_jack_report(info->jack, SND_JACK_MICROPHONE, SND_JACK_MICROPHONE); in arizona_micdet_reading()
826 ret = regulator_allow_bypass(info->micvdd, true); in arizona_micdet_reading()
828 dev_err(arizona->dev, "Failed to bypass MICVDD: %d\n", ret); in arizona_micdet_reading()
836 * plain headphones. If both polarities report a low in arizona_micdet_reading()
837 * impedence then give up and report headphones. in arizona_micdet_reading()
840 if (info->jack_flips >= info->micd_num_modes * 10) { in arizona_micdet_reading()
841 dev_dbg(arizona->dev, "Detected HP/line\n"); in arizona_micdet_reading()
843 info->detecting = false; in arizona_micdet_reading()
847 info->micd_mode++; in arizona_micdet_reading()
848 if (info->micd_mode == info->micd_num_modes) in arizona_micdet_reading()
849 info->micd_mode = 0; in arizona_micdet_reading()
850 arizona_extcon_set_mode(info, info->micd_mode); in arizona_micdet_reading()
852 info->jack_flips++; in arizona_micdet_reading()
854 if (arizona->pdata.micd_software_compare) in arizona_micdet_reading()
855 regmap_update_bits(arizona->regmap, in arizona_micdet_reading()
861 &info->micd_timeout_work, in arizona_micdet_reading()
862 msecs_to_jiffies(arizona->pdata.micd_timeout)); in arizona_micdet_reading()
872 dev_dbg(arizona->dev, "Headphone detected\n"); in arizona_micdet_reading()
873 info->detecting = false; in arizona_micdet_reading()
883 struct arizona *arizona = info->arizona; in arizona_button_reading()
895 if (info->mic) { in arizona_button_reading()
896 dev_dbg(arizona->dev, "Mic button detected\n"); in arizona_button_reading()
901 if (lvl && ffs(lvl) - 1 < info->num_micd_ranges) { in arizona_button_reading()
902 key = ffs(lvl) - 1; in arizona_button_reading()
903 snd_soc_jack_report(info->jack, in arizona_button_reading()
905 info->micd_button_mask); in arizona_button_reading()
907 dev_err(arizona->dev, "Button out of range\n"); in arizona_button_reading()
910 dev_warn(arizona->dev, "Button with no mic: %x\n", val); in arizona_button_reading()
913 dev_dbg(arizona->dev, "Mic button released\n"); in arizona_button_reading()
914 snd_soc_jack_report(info->jack, 0, info->micd_button_mask); in arizona_button_reading()
926 struct arizona *arizona = info->arizona; in arizona_micd_detect()
928 cancel_delayed_work_sync(&info->micd_timeout_work); in arizona_micd_detect()
930 mutex_lock(&info->lock); in arizona_micd_detect()
933 if (!(info->jack->status & SND_JACK_MECHANICAL)) { in arizona_micd_detect()
934 dev_dbg(arizona->dev, "Ignoring MICDET for removed cable\n"); in arizona_micd_detect()
935 mutex_unlock(&info->lock); in arizona_micd_detect()
939 if (info->detecting) in arizona_micd_detect()
944 pm_runtime_mark_last_busy(arizona->dev); in arizona_micd_detect()
945 mutex_unlock(&info->lock); in arizona_micd_detect()
951 struct arizona *arizona = info->arizona; in arizona_micdet()
952 int debounce = arizona->pdata.micd_detect_debounce; in arizona_micdet()
954 cancel_delayed_work_sync(&info->micd_detect_work); in arizona_micdet()
955 cancel_delayed_work_sync(&info->micd_timeout_work); in arizona_micdet()
957 mutex_lock(&info->lock); in arizona_micdet()
958 if (!info->detecting) in arizona_micdet()
960 mutex_unlock(&info->lock); in arizona_micdet()
964 &info->micd_detect_work, in arizona_micdet()
967 arizona_micd_detect(&info->micd_detect_work.work); in arizona_micdet()
978 mutex_lock(&info->lock); in arizona_hpdet_work()
980 mutex_unlock(&info->lock); in arizona_hpdet_work()
985 struct arizona *arizona = info->arizona; in arizona_hpdet_wait()
990 ret = regmap_read(arizona->regmap, ARIZONA_HEADPHONE_DETECT_2, in arizona_hpdet_wait()
993 dev_err(arizona->dev, "Failed to read HPDET state: %d\n", ret); in arizona_hpdet_wait()
997 switch (info->hpdet_ip_version) { in arizona_hpdet_wait()
1011 dev_warn(arizona->dev, "HPDET did not appear to complete\n"); in arizona_hpdet_wait()
1013 return -ETIMEDOUT; in arizona_hpdet_wait()
1019 struct arizona *arizona = info->arizona; in arizona_jackdet()
1020 unsigned int val, present, mask; in arizona_jackdet() local
1024 cancelled_hp = cancel_delayed_work_sync(&info->hpdet_work); in arizona_jackdet()
1025 cancelled_mic = cancel_delayed_work_sync(&info->micd_timeout_work); in arizona_jackdet()
1027 pm_runtime_get_sync(arizona->dev); in arizona_jackdet()
1029 mutex_lock(&info->lock); in arizona_jackdet()
1031 if (info->micd_clamp) { in arizona_jackdet()
1032 mask = ARIZONA_MICD_CLAMP_STS; in arizona_jackdet()
1035 mask = ARIZONA_JD1_STS; in arizona_jackdet()
1036 if (arizona->pdata.jd_invert) in arizona_jackdet()
1042 ret = regmap_read(arizona->regmap, ARIZONA_AOD_IRQ_RAW_STATUS, &val); in arizona_jackdet()
1044 dev_err(arizona->dev, "Failed to read jackdet status: %d\n", ret); in arizona_jackdet()
1045 mutex_unlock(&info->lock); in arizona_jackdet()
1046 pm_runtime_put_autosuspend(arizona->dev); in arizona_jackdet()
1050 val &= mask; in arizona_jackdet()
1051 if (val == info->last_jackdet) { in arizona_jackdet()
1052 dev_dbg(arizona->dev, "Suppressing duplicate JACKDET\n"); in arizona_jackdet()
1055 &info->hpdet_work, in arizona_jackdet()
1059 int micd_timeout = arizona->pdata.micd_timeout; in arizona_jackdet()
1062 &info->micd_timeout_work, in arizona_jackdet()
1068 info->last_jackdet = val; in arizona_jackdet()
1070 if (info->last_jackdet == present) { in arizona_jackdet()
1071 dev_dbg(arizona->dev, "Detected jack\n"); in arizona_jackdet()
1072 snd_soc_jack_report(info->jack, SND_JACK_MECHANICAL, SND_JACK_MECHANICAL); in arizona_jackdet()
1074 info->detecting = true; in arizona_jackdet()
1075 info->mic = false; in arizona_jackdet()
1076 info->jack_flips = 0; in arizona_jackdet()
1078 if (!arizona->pdata.hpdet_acc_id) { in arizona_jackdet()
1082 &info->hpdet_work, in arizona_jackdet()
1086 if (info->micd_clamp || !arizona->pdata.jd_invert) in arizona_jackdet()
1087 regmap_update_bits(arizona->regmap, in arizona_jackdet()
1092 dev_dbg(arizona->dev, "Detected jack removal\n"); in arizona_jackdet()
1096 info->num_hpdet_res = 0; in arizona_jackdet()
1097 for (i = 0; i < ARRAY_SIZE(info->hpdet_res); i++) in arizona_jackdet()
1098 info->hpdet_res[i] = 0; in arizona_jackdet()
1099 info->mic = false; in arizona_jackdet()
1100 info->hpdet_done = false; in arizona_jackdet()
1101 info->hpdet_retried = false; in arizona_jackdet()
1103 snd_soc_jack_report(info->jack, 0, ARIZONA_JACK_MASK | info->micd_button_mask); in arizona_jackdet()
1114 regmap_update_bits(arizona->regmap, in arizona_jackdet()
1122 regmap_write(arizona->regmap, ARIZONA_AOD_WKUP_AND_TRIG, in arizona_jackdet()
1128 mutex_unlock(&info->lock); in arizona_jackdet()
1130 pm_runtime_mark_last_busy(arizona->dev); in arizona_jackdet()
1131 pm_runtime_put_autosuspend(arizona->dev); in arizona_jackdet()
1141 unsigned int mask; in arizona_micd_set_level() local
1143 reg = ARIZONA_MIC_DETECT_LEVEL_4 - (index / 2); in arizona_micd_set_level()
1146 mask = 0x3f00; in arizona_micd_set_level()
1149 mask = 0x3f; in arizona_micd_set_level()
1153 regmap_update_bits(arizona->regmap, reg, mask, level); in arizona_micd_set_level()
1159 const char * const prop = "wlf,micd-configs"; in arizona_extcon_get_micd_configs()
1166 nconfs = device_property_count_u32(arizona->dev, prop); in arizona_extcon_get_micd_configs()
1172 return -ENOMEM; in arizona_extcon_get_micd_configs()
1174 ret = device_property_read_u32_array(arizona->dev, prop, vals, nconfs); in arizona_extcon_get_micd_configs()
1182 ret = -ENOMEM; in arizona_extcon_get_micd_configs()
1192 arizona->pdata.micd_configs = micd_configs; in arizona_extcon_get_micd_configs()
1193 arizona->pdata.num_micd_configs = nconfs; in arizona_extcon_get_micd_configs()
1203 struct arizona_pdata *pdata = &arizona->pdata; in arizona_extcon_device_get_pdata()
1207 device_property_read_u32(arizona->dev, "wlf,hpdet-channel", &val); in arizona_extcon_device_get_pdata()
1211 pdata->hpdet_channel = val; in arizona_extcon_device_get_pdata()
1214 dev_err(arizona->dev, "Wrong wlf,hpdet-channel DT value %d\n", val); in arizona_extcon_device_get_pdata()
1215 pdata->hpdet_channel = ARIZONA_ACCDET_MODE_HPL; in arizona_extcon_device_get_pdata()
1218 device_property_read_u32(arizona->dev, "wlf,micd-detect-debounce", in arizona_extcon_device_get_pdata()
1219 &pdata->micd_detect_debounce); in arizona_extcon_device_get_pdata()
1221 device_property_read_u32(arizona->dev, "wlf,micd-bias-start-time", in arizona_extcon_device_get_pdata()
1222 &pdata->micd_bias_start_time); in arizona_extcon_device_get_pdata()
1224 device_property_read_u32(arizona->dev, "wlf,micd-rate", in arizona_extcon_device_get_pdata()
1225 &pdata->micd_rate); in arizona_extcon_device_get_pdata()
1227 device_property_read_u32(arizona->dev, "wlf,micd-dbtime", in arizona_extcon_device_get_pdata()
1228 &pdata->micd_dbtime); in arizona_extcon_device_get_pdata()
1230 device_property_read_u32(arizona->dev, "wlf,micd-timeout-ms", in arizona_extcon_device_get_pdata()
1231 &pdata->micd_timeout); in arizona_extcon_device_get_pdata()
1233 pdata->micd_force_micbias = device_property_read_bool(arizona->dev, in arizona_extcon_device_get_pdata()
1234 "wlf,micd-force-micbias"); in arizona_extcon_device_get_pdata()
1236 pdata->micd_software_compare = device_property_read_bool(arizona->dev, in arizona_extcon_device_get_pdata()
1237 "wlf,micd-software-compare"); in arizona_extcon_device_get_pdata()
1239 pdata->jd_invert = device_property_read_bool(arizona->dev, in arizona_extcon_device_get_pdata()
1240 "wlf,jd-invert"); in arizona_extcon_device_get_pdata()
1242 device_property_read_u32(arizona->dev, "wlf,gpsw", &pdata->gpsw); in arizona_extcon_device_get_pdata()
1244 pdata->jd_gpio5 = device_property_read_bool(arizona->dev, in arizona_extcon_device_get_pdata()
1245 "wlf,use-jd2"); in arizona_extcon_device_get_pdata()
1246 pdata->jd_gpio5_nopull = device_property_read_bool(arizona->dev, in arizona_extcon_device_get_pdata()
1247 "wlf,use-jd2-nopull"); in arizona_extcon_device_get_pdata()
1251 dev_err(arizona->dev, "Failed to read micd configs: %d\n", ret); in arizona_extcon_device_get_pdata()
1258 struct arizona *arizona = info->arizona; in arizona_jack_codec_dev_probe()
1259 struct arizona_pdata *pdata = &arizona->pdata; in arizona_jack_codec_dev_probe()
1262 if (!dev_get_platdata(arizona->dev)) in arizona_jack_codec_dev_probe()
1265 info->micvdd = devm_regulator_get(dev, "MICVDD"); in arizona_jack_codec_dev_probe()
1266 if (IS_ERR(info->micvdd)) in arizona_jack_codec_dev_probe()
1267 return dev_err_probe(arizona->dev, PTR_ERR(info->micvdd), "getting MICVDD\n"); in arizona_jack_codec_dev_probe()
1269 mutex_init(&info->lock); in arizona_jack_codec_dev_probe()
1270 info->last_jackdet = ~(ARIZONA_MICD_CLAMP_STS | ARIZONA_JD1_STS); in arizona_jack_codec_dev_probe()
1271 INIT_DELAYED_WORK(&info->hpdet_work, arizona_hpdet_work); in arizona_jack_codec_dev_probe()
1272 INIT_DELAYED_WORK(&info->micd_detect_work, arizona_micd_detect); in arizona_jack_codec_dev_probe()
1273 INIT_DELAYED_WORK(&info->micd_timeout_work, arizona_micd_timeout_work); in arizona_jack_codec_dev_probe()
1275 switch (arizona->type) { in arizona_jack_codec_dev_probe()
1277 switch (arizona->rev) { in arizona_jack_codec_dev_probe()
1279 info->micd_reva = true; in arizona_jack_codec_dev_probe()
1282 info->micd_clamp = true; in arizona_jack_codec_dev_probe()
1283 info->hpdet_ip_version = 1; in arizona_jack_codec_dev_probe()
1289 switch (arizona->rev) { in arizona_jack_codec_dev_probe()
1293 info->micd_clamp = true; in arizona_jack_codec_dev_probe()
1294 info->hpdet_ip_version = 2; in arizona_jack_codec_dev_probe()
1300 info->micd_clamp = true; in arizona_jack_codec_dev_probe()
1301 info->hpdet_ip_version = 2; in arizona_jack_codec_dev_probe()
1307 if (!pdata->micd_timeout) in arizona_jack_codec_dev_probe()
1308 pdata->micd_timeout = DEFAULT_MICD_TIMEOUT; in arizona_jack_codec_dev_probe()
1310 if (pdata->num_micd_configs) { in arizona_jack_codec_dev_probe()
1311 info->micd_modes = pdata->micd_configs; in arizona_jack_codec_dev_probe()
1312 info->micd_num_modes = pdata->num_micd_configs; in arizona_jack_codec_dev_probe()
1314 info->micd_modes = micd_default_modes; in arizona_jack_codec_dev_probe()
1315 info->micd_num_modes = ARRAY_SIZE(micd_default_modes); in arizona_jack_codec_dev_probe()
1318 if (arizona->pdata.gpsw > 0) in arizona_jack_codec_dev_probe()
1319 regmap_update_bits(arizona->regmap, ARIZONA_GP_SWITCH_1, in arizona_jack_codec_dev_probe()
1320 ARIZONA_SW1_MODE_MASK, arizona->pdata.gpsw); in arizona_jack_codec_dev_probe()
1322 if (pdata->micd_pol_gpio > 0) { in arizona_jack_codec_dev_probe()
1323 if (info->micd_modes[0].gpio) in arizona_jack_codec_dev_probe()
1328 ret = devm_gpio_request_one(dev, pdata->micd_pol_gpio, in arizona_jack_codec_dev_probe()
1331 dev_err(arizona->dev, "Failed to request GPIO%d: %d\n", in arizona_jack_codec_dev_probe()
1332 pdata->micd_pol_gpio, ret); in arizona_jack_codec_dev_probe()
1336 info->micd_pol_gpio = gpio_to_desc(pdata->micd_pol_gpio); in arizona_jack_codec_dev_probe()
1338 if (info->micd_modes[0].gpio) in arizona_jack_codec_dev_probe()
1348 info->micd_pol_gpio = gpiod_get_optional(arizona->dev, in arizona_jack_codec_dev_probe()
1349 "wlf,micd-pol", in arizona_jack_codec_dev_probe()
1351 if (IS_ERR(info->micd_pol_gpio)) { in arizona_jack_codec_dev_probe()
1352 ret = PTR_ERR(info->micd_pol_gpio); in arizona_jack_codec_dev_probe()
1353 dev_err_probe(arizona->dev, ret, "getting microphone polarity GPIO\n"); in arizona_jack_codec_dev_probe()
1358 if (arizona->pdata.hpdet_id_gpio > 0) { in arizona_jack_codec_dev_probe()
1359 ret = devm_gpio_request_one(dev, arizona->pdata.hpdet_id_gpio, in arizona_jack_codec_dev_probe()
1363 dev_err(arizona->dev, "Failed to request GPIO%d: %d\n", in arizona_jack_codec_dev_probe()
1364 arizona->pdata.hpdet_id_gpio, ret); in arizona_jack_codec_dev_probe()
1365 gpiod_put(info->micd_pol_gpio); in arizona_jack_codec_dev_probe()
1376 gpiod_put(info->micd_pol_gpio); in arizona_jack_codec_dev_remove()
1384 struct arizona *arizona = info->arizona; in arizona_jack_enable_jack_detect()
1385 struct arizona_pdata *pdata = &arizona->pdata; in arizona_jack_enable_jack_detect()
1391 if (arizona->pdata.micd_bias_start_time) in arizona_jack_enable_jack_detect()
1392 regmap_update_bits(arizona->regmap, ARIZONA_MIC_DETECT_1, in arizona_jack_enable_jack_detect()
1394 arizona->pdata.micd_bias_start_time in arizona_jack_enable_jack_detect()
1397 if (arizona->pdata.micd_rate) in arizona_jack_enable_jack_detect()
1398 regmap_update_bits(arizona->regmap, ARIZONA_MIC_DETECT_1, in arizona_jack_enable_jack_detect()
1400 arizona->pdata.micd_rate in arizona_jack_enable_jack_detect()
1403 switch (arizona->pdata.micd_dbtime) { in arizona_jack_enable_jack_detect()
1405 regmap_update_bits(arizona->regmap, ARIZONA_MIC_DETECT_1, in arizona_jack_enable_jack_detect()
1410 regmap_update_bits(arizona->regmap, ARIZONA_MIC_DETECT_1, in arizona_jack_enable_jack_detect()
1420 if (arizona->pdata.num_micd_ranges) { in arizona_jack_enable_jack_detect()
1421 info->micd_ranges = pdata->micd_ranges; in arizona_jack_enable_jack_detect()
1422 info->num_micd_ranges = pdata->num_micd_ranges; in arizona_jack_enable_jack_detect()
1424 info->micd_ranges = micd_default_ranges; in arizona_jack_enable_jack_detect()
1425 info->num_micd_ranges = ARRAY_SIZE(micd_default_ranges); in arizona_jack_enable_jack_detect()
1428 if (arizona->pdata.num_micd_ranges > ARIZONA_MAX_MICD_BUTTONS) { in arizona_jack_enable_jack_detect()
1429 dev_err(arizona->dev, "Too many MICD ranges: %d > %d\n", in arizona_jack_enable_jack_detect()
1430 arizona->pdata.num_micd_ranges, ARIZONA_MAX_MICD_BUTTONS); in arizona_jack_enable_jack_detect()
1431 return -EINVAL; in arizona_jack_enable_jack_detect()
1434 if (info->num_micd_ranges > 1) { in arizona_jack_enable_jack_detect()
1435 for (i = 1; i < info->num_micd_ranges; i++) { in arizona_jack_enable_jack_detect()
1436 if (info->micd_ranges[i - 1].max > in arizona_jack_enable_jack_detect()
1437 info->micd_ranges[i].max) { in arizona_jack_enable_jack_detect()
1438 dev_err(arizona->dev, "MICD ranges must be sorted\n"); in arizona_jack_enable_jack_detect()
1439 return -EINVAL; in arizona_jack_enable_jack_detect()
1444 /* Disable all buttons by default */ in arizona_jack_enable_jack_detect()
1445 regmap_update_bits(arizona->regmap, ARIZONA_MIC_DETECT_2, in arizona_jack_enable_jack_detect()
1449 for (i = 0; i < info->num_micd_ranges; i++) { in arizona_jack_enable_jack_detect()
1451 if (arizona_micd_levels[j] >= info->micd_ranges[i].max) in arizona_jack_enable_jack_detect()
1455 dev_err(arizona->dev, "Unsupported MICD level %d\n", in arizona_jack_enable_jack_detect()
1456 info->micd_ranges[i].max); in arizona_jack_enable_jack_detect()
1457 return -EINVAL; in arizona_jack_enable_jack_detect()
1460 dev_dbg(arizona->dev, "%d ohms for MICD threshold %d\n", in arizona_jack_enable_jack_detect()
1466 info->micd_button_mask |= SND_JACK_BTN_0 >> i; in arizona_jack_enable_jack_detect()
1467 snd_jack_set_key(jack->jack, SND_JACK_BTN_0 >> i, in arizona_jack_enable_jack_detect()
1468 info->micd_ranges[i].key); in arizona_jack_enable_jack_detect()
1471 regmap_update_bits(arizona->regmap, ARIZONA_MIC_DETECT_2, in arizona_jack_enable_jack_detect()
1483 if (info->micd_clamp) { in arizona_jack_enable_jack_detect()
1484 if (arizona->pdata.jd_gpio5) { in arizona_jack_enable_jack_detect()
1487 if (arizona->pdata.jd_gpio5_nopull) in arizona_jack_enable_jack_detect()
1490 regmap_write(arizona->regmap, ARIZONA_GPIO5_CTRL, in arizona_jack_enable_jack_detect()
1493 if (arizona->pdata.jd_invert) in arizona_jack_enable_jack_detect()
1498 if (arizona->pdata.jd_invert) in arizona_jack_enable_jack_detect()
1504 regmap_update_bits(arizona->regmap, in arizona_jack_enable_jack_detect()
1508 regmap_update_bits(arizona->regmap, in arizona_jack_enable_jack_detect()
1516 info->jack = jack; in arizona_jack_enable_jack_detect()
1518 pm_runtime_get_sync(arizona->dev); in arizona_jack_enable_jack_detect()
1520 if (info->micd_clamp) { in arizona_jack_enable_jack_detect()
1531 dev_err(arizona->dev, "Failed to get JACKDET rise IRQ: %d\n", ret); in arizona_jack_enable_jack_detect()
1537 dev_err(arizona->dev, "Failed to set JD rise IRQ wake: %d\n", ret); in arizona_jack_enable_jack_detect()
1544 dev_err(arizona->dev, "Failed to get JD fall IRQ: %d\n", ret); in arizona_jack_enable_jack_detect()
1550 dev_err(arizona->dev, "Failed to set JD fall IRQ wake: %d\n", ret); in arizona_jack_enable_jack_detect()
1557 dev_err(arizona->dev, "Failed to get MICDET IRQ: %d\n", ret); in arizona_jack_enable_jack_detect()
1564 dev_err(arizona->dev, "Failed to get HPDET IRQ: %d\n", ret); in arizona_jack_enable_jack_detect()
1569 regmap_update_bits(arizona->regmap, ARIZONA_JACK_DETECT_DEBOUNCE, in arizona_jack_enable_jack_detect()
1571 regmap_update_bits(arizona->regmap, ARIZONA_JACK_DETECT_ANALOGUE, in arizona_jack_enable_jack_detect()
1574 ret = regulator_allow_bypass(info->micvdd, true); in arizona_jack_enable_jack_detect()
1576 dev_warn(arizona->dev, "Failed to set MICVDD to bypass: %d\n", ret); in arizona_jack_enable_jack_detect()
1578 pm_runtime_put(arizona->dev); in arizona_jack_enable_jack_detect()
1593 pm_runtime_put(arizona->dev); in arizona_jack_enable_jack_detect()
1594 info->jack = NULL; in arizona_jack_enable_jack_detect()
1600 struct arizona *arizona = info->arizona; in arizona_jack_disable_jack_detect()
1605 if (!info->jack) in arizona_jack_disable_jack_detect()
1608 if (info->micd_clamp) { in arizona_jack_disable_jack_detect()
1622 cancel_delayed_work_sync(&info->hpdet_work); in arizona_jack_disable_jack_detect()
1623 cancel_delayed_work_sync(&info->micd_detect_work); in arizona_jack_disable_jack_detect()
1624 cancel_delayed_work_sync(&info->micd_timeout_work); in arizona_jack_disable_jack_detect()
1626 ret = regmap_update_bits_check(arizona->regmap, ARIZONA_MIC_DETECT_1, in arizona_jack_disable_jack_detect()
1630 dev_err(arizona->dev, "Failed to disable micd on remove: %d\n", ret); in arizona_jack_disable_jack_detect()
1632 regulator_disable(info->micvdd); in arizona_jack_disable_jack_detect()
1633 pm_runtime_put(arizona->dev); in arizona_jack_disable_jack_detect()
1636 regmap_update_bits(arizona->regmap, in arizona_jack_disable_jack_detect()
1639 regmap_update_bits(arizona->regmap, ARIZONA_JACK_DETECT_ANALOGUE, in arizona_jack_disable_jack_detect()
1642 info->jack = NULL; in arizona_jack_disable_jack_detect()