2 * extcon-arizona.c - Extcon driver Wolfson Arizona devices
4 * Copyright (C) 2012 Wolfson Microelectronics plc
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
17 #include <linux/kernel.h>
18 #include <linux/module.h>
19 #include <linux/i2c.h>
20 #include <linux/slab.h>
21 #include <linux/interrupt.h>
22 #include <linux/err.h>
23 #include <linux/gpio/consumer.h>
24 #include <linux/gpio.h>
25 #include <linux/input.h>
26 #include <linux/platform_device.h>
27 #include <linux/pm_runtime.h>
28 #include <linux/property.h>
29 #include <linux/regulator/consumer.h>
30 #include <linux/extcon.h>
32 #include <sound/soc.h>
34 #include <linux/mfd/arizona/core.h>
35 #include <linux/mfd/arizona/pdata.h>
36 #include <linux/mfd/arizona/registers.h>
37 #include <dt-bindings/mfd/arizona.h>
39 #define ARIZONA_MAX_MICD_RANGE 8
41 #define ARIZONA_MICD_CLAMP_MODE_JDL 0x4
42 #define ARIZONA_MICD_CLAMP_MODE_JDH 0x5
43 #define ARIZONA_MICD_CLAMP_MODE_JDL_GP5H 0x9
44 #define ARIZONA_MICD_CLAMP_MODE_JDH_GP5H 0xb
46 #define ARIZONA_TST_CAP_DEFAULT 0x3
47 #define ARIZONA_TST_CAP_CLAMP 0x1
49 #define ARIZONA_HPDET_MAX 10000
51 #define HPDET_DEBOUNCE 500
52 #define DEFAULT_MICD_TIMEOUT 2000
54 #define QUICK_HEADPHONE_MAX_OHM 3
55 #define MICROPHONE_MIN_OHM 1257
56 #define MICROPHONE_MAX_OHM 30000
58 #define MICD_DBTIME_TWO_READINGS 2
59 #define MICD_DBTIME_FOUR_READINGS 4
61 #define MICD_LVL_1_TO_7 (ARIZONA_MICD_LVL_1 | ARIZONA_MICD_LVL_2 | \
62 ARIZONA_MICD_LVL_3 | ARIZONA_MICD_LVL_4 | \
63 ARIZONA_MICD_LVL_5 | ARIZONA_MICD_LVL_6 | \
66 #define MICD_LVL_0_TO_7 (ARIZONA_MICD_LVL_0 | MICD_LVL_1_TO_7)
68 #define MICD_LVL_0_TO_8 (MICD_LVL_0_TO_7 | ARIZONA_MICD_LVL_8)
70 struct arizona_extcon_info {
72 struct arizona *arizona;
74 struct regulator *micvdd;
75 struct input_dev *input;
80 const struct arizona_micd_config *micd_modes;
83 const struct arizona_micd_range *micd_ranges;
91 struct delayed_work hpdet_work;
92 struct delayed_work micd_detect_work;
93 struct delayed_work micd_timeout_work;
100 unsigned int hpdet_res[3];
106 int hpdet_ip_version;
108 struct extcon_dev *edev;
110 struct gpio_desc *micd_pol_gpio;
113 static const struct arizona_micd_config micd_default_modes[] = {
114 { ARIZONA_ACCDET_SRC, 1, 0 },
118 static const struct arizona_micd_range micd_default_ranges[] = {
119 { .max = 11, .key = BTN_0 },
120 { .max = 28, .key = BTN_1 },
121 { .max = 54, .key = BTN_2 },
122 { .max = 100, .key = BTN_3 },
123 { .max = 186, .key = BTN_4 },
124 { .max = 430, .key = BTN_5 },
127 /* The number of levels in arizona_micd_levels valid for button thresholds */
128 #define ARIZONA_NUM_MICD_BUTTON_LEVELS 64
130 static const int arizona_micd_levels[] = {
131 3, 6, 8, 11, 13, 16, 18, 21, 23, 26, 28, 31, 34, 36, 39, 41, 44, 46,
132 49, 52, 54, 57, 60, 62, 65, 67, 70, 73, 75, 78, 81, 83, 89, 94, 100,
133 105, 111, 116, 122, 127, 139, 150, 161, 173, 186, 196, 209, 220, 245,
134 270, 295, 321, 348, 375, 402, 430, 489, 550, 614, 681, 752, 903, 1071,
138 static const unsigned int arizona_cable[] = {
146 static void arizona_start_hpdet_acc_id(struct arizona_extcon_info *info);
148 static void arizona_extcon_hp_clamp(struct arizona_extcon_info *info,
151 struct arizona *arizona = info->arizona;
152 unsigned int mask = 0, val = 0;
153 unsigned int cap_sel = 0;
156 switch (arizona->type) {
159 mask = ARIZONA_HP1L_SHRTO | ARIZONA_HP1L_FLWR |
162 val = ARIZONA_HP1L_SHRTO;
163 cap_sel = ARIZONA_TST_CAP_CLAMP;
165 val = ARIZONA_HP1L_FLWR | ARIZONA_HP1L_SHRTI;
166 cap_sel = ARIZONA_TST_CAP_DEFAULT;
169 ret = regmap_update_bits(arizona->regmap,
170 ARIZONA_HP_TEST_CTRL_1,
171 ARIZONA_HP1_TST_CAP_SEL_MASK,
174 dev_warn(arizona->dev,
175 "Failed to set TST_CAP_SEL: %d\n", ret);
178 mask = ARIZONA_RMV_SHRT_HP1L;
180 val = ARIZONA_RMV_SHRT_HP1L;
184 mutex_lock(&arizona->dapm->card->dapm_mutex);
186 arizona->hpdet_clamp = clamp;
188 /* Keep the HP output stages disabled while doing the clamp */
190 ret = regmap_update_bits(arizona->regmap,
191 ARIZONA_OUTPUT_ENABLES_1,
193 ARIZONA_OUT1R_ENA, 0);
195 dev_warn(arizona->dev,
196 "Failed to disable headphone outputs: %d\n",
200 ret = regmap_update_bits(arizona->regmap, ARIZONA_HP_CTRL_1L,
203 dev_warn(arizona->dev, "Failed to do clamp: %d\n",
206 ret = regmap_update_bits(arizona->regmap, ARIZONA_HP_CTRL_1R,
209 dev_warn(arizona->dev, "Failed to do clamp: %d\n",
212 /* Restore the desired state while not doing the clamp */
214 ret = regmap_update_bits(arizona->regmap,
215 ARIZONA_OUTPUT_ENABLES_1,
217 ARIZONA_OUT1R_ENA, arizona->hp_ena);
219 dev_warn(arizona->dev,
220 "Failed to restore headphone outputs: %d\n",
224 mutex_unlock(&arizona->dapm->card->dapm_mutex);
227 static void arizona_extcon_set_mode(struct arizona_extcon_info *info, int mode)
229 struct arizona *arizona = info->arizona;
231 mode %= info->micd_num_modes;
233 if (arizona->pdata.micd_pol_gpio > 0)
234 gpio_set_value_cansleep(arizona->pdata.micd_pol_gpio,
235 info->micd_modes[mode].gpio);
237 gpiod_set_value_cansleep(info->micd_pol_gpio,
238 info->micd_modes[mode].gpio);
240 regmap_update_bits(arizona->regmap, ARIZONA_MIC_DETECT_1,
241 ARIZONA_MICD_BIAS_SRC_MASK,
242 info->micd_modes[mode].bias <<
243 ARIZONA_MICD_BIAS_SRC_SHIFT);
244 regmap_update_bits(arizona->regmap, ARIZONA_ACCESSORY_DETECT_MODE_1,
245 ARIZONA_ACCDET_SRC, info->micd_modes[mode].src);
247 info->micd_mode = mode;
249 dev_dbg(arizona->dev, "Set jack polarity to %d\n", mode);
252 static const char *arizona_extcon_get_micbias(struct arizona_extcon_info *info)
254 switch (info->micd_modes[0].bias) {
266 static void arizona_extcon_pulse_micbias(struct arizona_extcon_info *info)
268 struct arizona *arizona = info->arizona;
269 const char *widget = arizona_extcon_get_micbias(info);
270 struct snd_soc_dapm_context *dapm = arizona->dapm;
273 ret = snd_soc_dapm_force_enable_pin(dapm, widget);
275 dev_warn(arizona->dev, "Failed to enable %s: %d\n",
278 snd_soc_dapm_sync(dapm);
280 if (!arizona->pdata.micd_force_micbias) {
281 ret = snd_soc_dapm_disable_pin(arizona->dapm, widget);
283 dev_warn(arizona->dev, "Failed to disable %s: %d\n",
286 snd_soc_dapm_sync(dapm);
290 static void arizona_start_mic(struct arizona_extcon_info *info)
292 struct arizona *arizona = info->arizona;
297 /* Microphone detection can't use idle mode */
298 pm_runtime_get(info->dev);
300 if (info->detecting) {
301 ret = regulator_allow_bypass(info->micvdd, false);
303 dev_err(arizona->dev,
304 "Failed to regulate MICVDD: %d\n",
309 ret = regulator_enable(info->micvdd);
311 dev_err(arizona->dev, "Failed to enable MICVDD: %d\n",
315 if (info->micd_reva) {
316 regmap_write(arizona->regmap, 0x80, 0x3);
317 regmap_write(arizona->regmap, 0x294, 0);
318 regmap_write(arizona->regmap, 0x80, 0x0);
321 if (info->detecting && arizona->pdata.micd_software_compare)
322 mode = ARIZONA_ACCDET_MODE_ADC;
324 mode = ARIZONA_ACCDET_MODE_MIC;
326 regmap_update_bits(arizona->regmap,
327 ARIZONA_ACCESSORY_DETECT_MODE_1,
328 ARIZONA_ACCDET_MODE_MASK, mode);
330 arizona_extcon_pulse_micbias(info);
332 regmap_update_bits_check(arizona->regmap, ARIZONA_MIC_DETECT_1,
333 ARIZONA_MICD_ENA, ARIZONA_MICD_ENA,
336 regulator_disable(info->micvdd);
337 pm_runtime_put_autosuspend(info->dev);
341 static void arizona_stop_mic(struct arizona_extcon_info *info)
343 struct arizona *arizona = info->arizona;
344 const char *widget = arizona_extcon_get_micbias(info);
345 struct snd_soc_dapm_context *dapm = arizona->dapm;
349 regmap_update_bits_check(arizona->regmap, ARIZONA_MIC_DETECT_1,
353 ret = snd_soc_dapm_disable_pin(dapm, widget);
355 dev_warn(arizona->dev,
356 "Failed to disable %s: %d\n",
359 snd_soc_dapm_sync(dapm);
361 if (info->micd_reva) {
362 regmap_write(arizona->regmap, 0x80, 0x3);
363 regmap_write(arizona->regmap, 0x294, 2);
364 regmap_write(arizona->regmap, 0x80, 0x0);
367 ret = regulator_allow_bypass(info->micvdd, true);
369 dev_err(arizona->dev, "Failed to bypass MICVDD: %d\n",
374 regulator_disable(info->micvdd);
375 pm_runtime_mark_last_busy(info->dev);
376 pm_runtime_put_autosuspend(info->dev);
381 unsigned int threshold;
382 unsigned int factor_a;
383 unsigned int factor_b;
384 } arizona_hpdet_b_ranges[] = {
385 { 100, 5528, 362464 },
386 { 169, 11084, 6186851 },
387 { 169, 11065, 65460395 },
390 #define ARIZONA_HPDET_B_RANGE_MAX 0x3fb
395 } arizona_hpdet_c_ranges[] = {
402 static int arizona_hpdet_read(struct arizona_extcon_info *info)
404 struct arizona *arizona = info->arizona;
405 unsigned int val, range;
408 ret = regmap_read(arizona->regmap, ARIZONA_HEADPHONE_DETECT_2, &val);
410 dev_err(arizona->dev, "Failed to read HPDET status: %d\n",
415 switch (info->hpdet_ip_version) {
417 if (!(val & ARIZONA_HP_DONE)) {
418 dev_err(arizona->dev, "HPDET did not complete: %x\n",
423 val &= ARIZONA_HP_LVL_MASK;
427 if (!(val & ARIZONA_HP_DONE_B)) {
428 dev_err(arizona->dev, "HPDET did not complete: %x\n",
433 ret = regmap_read(arizona->regmap, ARIZONA_HP_DACVAL, &val);
435 dev_err(arizona->dev, "Failed to read HP value: %d\n",
440 regmap_read(arizona->regmap, ARIZONA_HEADPHONE_DETECT_1,
442 range = (range & ARIZONA_HP_IMPEDANCE_RANGE_MASK)
443 >> ARIZONA_HP_IMPEDANCE_RANGE_SHIFT;
445 if (range < ARRAY_SIZE(arizona_hpdet_b_ranges) - 1 &&
446 (val < arizona_hpdet_b_ranges[range].threshold ||
447 val >= ARIZONA_HPDET_B_RANGE_MAX)) {
449 dev_dbg(arizona->dev, "Moving to HPDET range %d\n",
451 regmap_update_bits(arizona->regmap,
452 ARIZONA_HEADPHONE_DETECT_1,
453 ARIZONA_HP_IMPEDANCE_RANGE_MASK,
455 ARIZONA_HP_IMPEDANCE_RANGE_SHIFT);
459 /* If we go out of range report top of range */
460 if (val < arizona_hpdet_b_ranges[range].threshold ||
461 val >= ARIZONA_HPDET_B_RANGE_MAX) {
462 dev_dbg(arizona->dev, "Measurement out of range\n");
463 return ARIZONA_HPDET_MAX;
466 dev_dbg(arizona->dev, "HPDET read %d in range %d\n",
469 val = arizona_hpdet_b_ranges[range].factor_b
471 arizona_hpdet_b_ranges[range].factor_a);
475 dev_warn(arizona->dev, "Unknown HPDET IP revision %d\n",
476 info->hpdet_ip_version);
478 if (!(val & ARIZONA_HP_DONE_B)) {
479 dev_err(arizona->dev, "HPDET did not complete: %x\n",
484 val &= ARIZONA_HP_LVL_B_MASK;
485 /* Convert to ohms, the value is in 0.5 ohm increments */
488 regmap_read(arizona->regmap, ARIZONA_HEADPHONE_DETECT_1,
490 range = (range & ARIZONA_HP_IMPEDANCE_RANGE_MASK)
491 >> ARIZONA_HP_IMPEDANCE_RANGE_SHIFT;
493 /* Skip up a range, or report? */
494 if (range < ARRAY_SIZE(arizona_hpdet_c_ranges) - 1 &&
495 (val >= arizona_hpdet_c_ranges[range].max)) {
497 dev_dbg(arizona->dev, "Moving to HPDET range %d-%d\n",
498 arizona_hpdet_c_ranges[range].min,
499 arizona_hpdet_c_ranges[range].max);
500 regmap_update_bits(arizona->regmap,
501 ARIZONA_HEADPHONE_DETECT_1,
502 ARIZONA_HP_IMPEDANCE_RANGE_MASK,
504 ARIZONA_HP_IMPEDANCE_RANGE_SHIFT);
508 if (range && (val < arizona_hpdet_c_ranges[range].min)) {
509 dev_dbg(arizona->dev, "Reporting range boundary %d\n",
510 arizona_hpdet_c_ranges[range].min);
511 val = arizona_hpdet_c_ranges[range].min;
515 dev_dbg(arizona->dev, "HP impedance %d ohms\n", val);
519 static int arizona_hpdet_do_id(struct arizona_extcon_info *info, int *reading,
522 struct arizona *arizona = info->arizona;
523 int id_gpio = arizona->pdata.hpdet_id_gpio;
526 * If we're using HPDET for accessory identification we need
527 * to take multiple measurements, step through them in sequence.
529 if (arizona->pdata.hpdet_acc_id) {
530 info->hpdet_res[info->num_hpdet_res++] = *reading;
532 /* Only check the mic directly if we didn't already ID it */
533 if (id_gpio && info->num_hpdet_res == 1) {
534 dev_dbg(arizona->dev, "Measuring mic\n");
536 regmap_update_bits(arizona->regmap,
537 ARIZONA_ACCESSORY_DETECT_MODE_1,
538 ARIZONA_ACCDET_MODE_MASK |
540 ARIZONA_ACCDET_MODE_HPR |
541 info->micd_modes[0].src);
543 gpio_set_value_cansleep(id_gpio, 1);
545 regmap_update_bits(arizona->regmap,
546 ARIZONA_HEADPHONE_DETECT_1,
547 ARIZONA_HP_POLL, ARIZONA_HP_POLL);
551 /* OK, got both. Now, compare... */
552 dev_dbg(arizona->dev, "HPDET measured %d %d\n",
553 info->hpdet_res[0], info->hpdet_res[1]);
555 /* Take the headphone impedance for the main report */
556 *reading = info->hpdet_res[0];
558 /* Sometimes we get false readings due to slow insert */
559 if (*reading >= ARIZONA_HPDET_MAX && !info->hpdet_retried) {
560 dev_dbg(arizona->dev, "Retrying high impedance\n");
561 info->num_hpdet_res = 0;
562 info->hpdet_retried = true;
563 arizona_start_hpdet_acc_id(info);
564 pm_runtime_put(info->dev);
569 * If we measure the mic as high impedance
571 if (!id_gpio || info->hpdet_res[1] > 50) {
572 dev_dbg(arizona->dev, "Detected mic\n");
574 info->detecting = true;
576 dev_dbg(arizona->dev, "Detected headphone\n");
579 /* Make sure everything is reset back to the real polarity */
580 regmap_update_bits(arizona->regmap,
581 ARIZONA_ACCESSORY_DETECT_MODE_1,
583 info->micd_modes[0].src);
589 static irqreturn_t arizona_hpdet_irq(int irq, void *data)
591 struct arizona_extcon_info *info = data;
592 struct arizona *arizona = info->arizona;
593 int id_gpio = arizona->pdata.hpdet_id_gpio;
594 unsigned int report = EXTCON_HEADPHONE;
598 mutex_lock(&info->lock);
600 /* If we got a spurious IRQ for some reason then ignore it */
601 if (!info->hpdet_active) {
602 dev_warn(arizona->dev, "Spurious HPDET IRQ\n");
603 mutex_unlock(&info->lock);
607 /* If the cable was removed while measuring ignore the result */
608 ret = extcon_get_cable_state_(info->edev, EXTCON_MECHANICAL);
610 dev_err(arizona->dev, "Failed to check cable state: %d\n",
614 dev_dbg(arizona->dev, "Ignoring HPDET for removed cable\n");
618 ret = arizona_hpdet_read(info);
625 /* Reset back to starting range */
626 regmap_update_bits(arizona->regmap,
627 ARIZONA_HEADPHONE_DETECT_1,
628 ARIZONA_HP_IMPEDANCE_RANGE_MASK | ARIZONA_HP_POLL,
631 ret = arizona_hpdet_do_id(info, &reading, &mic);
637 /* Report high impedence cables as line outputs */
639 report = EXTCON_LINE_OUT;
641 report = EXTCON_HEADPHONE;
643 ret = extcon_set_cable_state_(info->edev, report, true);
645 dev_err(arizona->dev, "Failed to report HP/line: %d\n",
649 /* Reset back to starting range */
650 regmap_update_bits(arizona->regmap,
651 ARIZONA_HEADPHONE_DETECT_1,
652 ARIZONA_HP_IMPEDANCE_RANGE_MASK | ARIZONA_HP_POLL,
655 arizona_extcon_hp_clamp(info, false);
658 gpio_set_value_cansleep(id_gpio, 0);
660 /* Revert back to MICDET mode */
661 regmap_update_bits(arizona->regmap,
662 ARIZONA_ACCESSORY_DETECT_MODE_1,
663 ARIZONA_ACCDET_MODE_MASK, ARIZONA_ACCDET_MODE_MIC);
665 /* If we have a mic then reenable MICDET */
666 if (mic || info->mic)
667 arizona_start_mic(info);
669 if (info->hpdet_active) {
670 pm_runtime_put_autosuspend(info->dev);
671 info->hpdet_active = false;
674 info->hpdet_done = true;
677 mutex_unlock(&info->lock);
682 static void arizona_identify_headphone(struct arizona_extcon_info *info)
684 struct arizona *arizona = info->arizona;
687 if (info->hpdet_done)
690 dev_dbg(arizona->dev, "Starting HPDET\n");
692 /* Make sure we keep the device enabled during the measurement */
693 pm_runtime_get(info->dev);
695 info->hpdet_active = true;
698 arizona_stop_mic(info);
700 arizona_extcon_hp_clamp(info, true);
702 ret = regmap_update_bits(arizona->regmap,
703 ARIZONA_ACCESSORY_DETECT_MODE_1,
704 ARIZONA_ACCDET_MODE_MASK,
705 arizona->pdata.hpdet_channel);
707 dev_err(arizona->dev, "Failed to set HPDET mode: %d\n", ret);
711 ret = regmap_update_bits(arizona->regmap, ARIZONA_HEADPHONE_DETECT_1,
712 ARIZONA_HP_POLL, ARIZONA_HP_POLL);
714 dev_err(arizona->dev, "Can't start HPDETL measurement: %d\n",
722 regmap_update_bits(arizona->regmap, ARIZONA_ACCESSORY_DETECT_MODE_1,
723 ARIZONA_ACCDET_MODE_MASK, ARIZONA_ACCDET_MODE_MIC);
725 /* Just report headphone */
726 ret = extcon_set_cable_state_(info->edev, EXTCON_HEADPHONE, true);
728 dev_err(arizona->dev, "Failed to report headphone: %d\n", ret);
731 arizona_start_mic(info);
733 info->hpdet_active = false;
736 static void arizona_start_hpdet_acc_id(struct arizona_extcon_info *info)
738 struct arizona *arizona = info->arizona;
743 dev_dbg(arizona->dev, "Starting identification via HPDET\n");
745 /* Make sure we keep the device enabled during the measurement */
746 pm_runtime_get_sync(info->dev);
748 info->hpdet_active = true;
750 arizona_extcon_hp_clamp(info, true);
752 ret = regmap_update_bits(arizona->regmap,
753 ARIZONA_ACCESSORY_DETECT_MODE_1,
754 ARIZONA_ACCDET_SRC | ARIZONA_ACCDET_MODE_MASK,
755 info->micd_modes[0].src |
756 arizona->pdata.hpdet_channel);
758 dev_err(arizona->dev, "Failed to set HPDET mode: %d\n", ret);
762 if (arizona->pdata.hpdet_acc_id_line) {
763 ret = regmap_update_bits(arizona->regmap,
764 ARIZONA_HEADPHONE_DETECT_1,
765 ARIZONA_HP_POLL, ARIZONA_HP_POLL);
767 dev_err(arizona->dev,
768 "Can't start HPDETL measurement: %d\n",
773 arizona_hpdet_do_id(info, &hp_reading, &mic);
779 regmap_update_bits(arizona->regmap, ARIZONA_ACCESSORY_DETECT_MODE_1,
780 ARIZONA_ACCDET_MODE_MASK, ARIZONA_ACCDET_MODE_MIC);
782 /* Just report headphone */
783 ret = extcon_set_cable_state_(info->edev, EXTCON_HEADPHONE, true);
785 dev_err(arizona->dev, "Failed to report headphone: %d\n", ret);
787 info->hpdet_active = false;
790 static void arizona_micd_timeout_work(struct work_struct *work)
792 struct arizona_extcon_info *info = container_of(work,
793 struct arizona_extcon_info,
794 micd_timeout_work.work);
796 mutex_lock(&info->lock);
798 dev_dbg(info->arizona->dev, "MICD timed out, reporting HP\n");
800 info->detecting = false;
802 arizona_identify_headphone(info);
804 arizona_stop_mic(info);
806 mutex_unlock(&info->lock);
809 static void arizona_micd_detect(struct work_struct *work)
811 struct arizona_extcon_info *info = container_of(work,
812 struct arizona_extcon_info,
813 micd_detect_work.work);
814 struct arizona *arizona = info->arizona;
815 unsigned int val = 0, lvl;
818 cancel_delayed_work_sync(&info->micd_timeout_work);
820 mutex_lock(&info->lock);
822 /* If the cable was removed while measuring ignore the result */
823 ret = extcon_get_cable_state_(info->edev, EXTCON_MECHANICAL);
825 dev_err(arizona->dev, "Failed to check cable state: %d\n",
827 mutex_unlock(&info->lock);
830 dev_dbg(arizona->dev, "Ignoring MICDET for removed cable\n");
831 mutex_unlock(&info->lock);
835 if (info->detecting && arizona->pdata.micd_software_compare) {
836 /* Must disable MICD before we read the ADCVAL */
837 regmap_update_bits(arizona->regmap, ARIZONA_MIC_DETECT_1,
838 ARIZONA_MICD_ENA, 0);
839 ret = regmap_read(arizona->regmap, ARIZONA_MIC_DETECT_4, &val);
841 dev_err(arizona->dev,
842 "Failed to read MICDET_ADCVAL: %d\n",
844 mutex_unlock(&info->lock);
848 dev_dbg(arizona->dev, "MICDET_ADCVAL: %x\n", val);
850 val &= ARIZONA_MICDET_ADCVAL_MASK;
851 if (val < ARRAY_SIZE(arizona_micd_levels))
852 val = arizona_micd_levels[val];
856 if (val <= QUICK_HEADPHONE_MAX_OHM)
857 val = ARIZONA_MICD_STS | ARIZONA_MICD_LVL_0;
858 else if (val <= MICROPHONE_MIN_OHM)
859 val = ARIZONA_MICD_STS | ARIZONA_MICD_LVL_1;
860 else if (val <= MICROPHONE_MAX_OHM)
861 val = ARIZONA_MICD_STS | ARIZONA_MICD_LVL_8;
863 val = ARIZONA_MICD_LVL_8;
866 for (i = 0; i < 10 && !(val & MICD_LVL_0_TO_8); i++) {
867 ret = regmap_read(arizona->regmap, ARIZONA_MIC_DETECT_3, &val);
869 dev_err(arizona->dev,
870 "Failed to read MICDET: %d\n", ret);
871 mutex_unlock(&info->lock);
875 dev_dbg(arizona->dev, "MICDET: %x\n", val);
877 if (!(val & ARIZONA_MICD_VALID)) {
878 dev_warn(arizona->dev,
879 "Microphone detection state invalid\n");
880 mutex_unlock(&info->lock);
885 if (i == 10 && !(val & MICD_LVL_0_TO_8)) {
886 dev_err(arizona->dev, "Failed to get valid MICDET value\n");
887 mutex_unlock(&info->lock);
891 /* Due to jack detect this should never happen */
892 if (!(val & ARIZONA_MICD_STS)) {
893 dev_warn(arizona->dev, "Detected open circuit\n");
895 arizona_stop_mic(info);
896 info->detecting = false;
897 arizona_identify_headphone(info);
901 /* If we got a high impedence we should have a headset, report it. */
902 if (info->detecting && (val & ARIZONA_MICD_LVL_8)) {
904 info->detecting = false;
906 arizona_identify_headphone(info);
908 ret = extcon_set_cable_state_(info->edev,
909 EXTCON_MICROPHONE, true);
911 dev_err(arizona->dev, "Headset report failed: %d\n",
914 /* Don't need to regulate for button detection */
915 ret = regulator_allow_bypass(info->micvdd, true);
917 dev_err(arizona->dev, "Failed to bypass MICVDD: %d\n",
924 /* If we detected a lower impedence during initial startup
925 * then we probably have the wrong polarity, flip it. Don't
926 * do this for the lowest impedences to speed up detection of
927 * plain headphones. If both polarities report a low
928 * impedence then give up and report headphones.
930 if (info->detecting && (val & MICD_LVL_1_TO_7)) {
931 if (info->jack_flips >= info->micd_num_modes * 10) {
932 dev_dbg(arizona->dev, "Detected HP/line\n");
934 info->detecting = false;
936 arizona_identify_headphone(info);
938 arizona_stop_mic(info);
941 if (info->micd_mode == info->micd_num_modes)
943 arizona_extcon_set_mode(info, info->micd_mode);
952 * If we're still detecting and we detect a short then we've
953 * got a headphone. Otherwise it's a button press.
955 if (val & MICD_LVL_0_TO_7) {
957 dev_dbg(arizona->dev, "Mic button detected\n");
959 lvl = val & ARIZONA_MICD_LVL_MASK;
960 lvl >>= ARIZONA_MICD_LVL_SHIFT;
962 for (i = 0; i < info->num_micd_ranges; i++)
963 input_report_key(info->input,
964 info->micd_ranges[i].key, 0);
967 WARN_ON(ffs(lvl) - 1 >= info->num_micd_ranges);
968 if (lvl && ffs(lvl) - 1 < info->num_micd_ranges) {
969 key = info->micd_ranges[ffs(lvl) - 1].key;
970 input_report_key(info->input, key, 1);
971 input_sync(info->input);
974 } else if (info->detecting) {
975 dev_dbg(arizona->dev, "Headphone detected\n");
976 info->detecting = false;
977 arizona_stop_mic(info);
979 arizona_identify_headphone(info);
981 dev_warn(arizona->dev, "Button with no mic: %x\n",
985 dev_dbg(arizona->dev, "Mic button released\n");
986 for (i = 0; i < info->num_micd_ranges; i++)
987 input_report_key(info->input,
988 info->micd_ranges[i].key, 0);
989 input_sync(info->input);
990 arizona_extcon_pulse_micbias(info);
994 if (info->detecting) {
995 if (arizona->pdata.micd_software_compare)
996 regmap_update_bits(arizona->regmap,
997 ARIZONA_MIC_DETECT_1,
1001 queue_delayed_work(system_power_efficient_wq,
1002 &info->micd_timeout_work,
1003 msecs_to_jiffies(info->micd_timeout));
1006 pm_runtime_mark_last_busy(info->dev);
1007 mutex_unlock(&info->lock);
1010 static irqreturn_t arizona_micdet(int irq, void *data)
1012 struct arizona_extcon_info *info = data;
1013 struct arizona *arizona = info->arizona;
1014 int debounce = arizona->pdata.micd_detect_debounce;
1016 cancel_delayed_work_sync(&info->micd_detect_work);
1017 cancel_delayed_work_sync(&info->micd_timeout_work);
1019 mutex_lock(&info->lock);
1020 if (!info->detecting)
1022 mutex_unlock(&info->lock);
1025 queue_delayed_work(system_power_efficient_wq,
1026 &info->micd_detect_work,
1027 msecs_to_jiffies(debounce));
1029 arizona_micd_detect(&info->micd_detect_work.work);
1034 static void arizona_hpdet_work(struct work_struct *work)
1036 struct arizona_extcon_info *info = container_of(work,
1037 struct arizona_extcon_info,
1040 mutex_lock(&info->lock);
1041 arizona_start_hpdet_acc_id(info);
1042 mutex_unlock(&info->lock);
1045 static irqreturn_t arizona_jackdet(int irq, void *data)
1047 struct arizona_extcon_info *info = data;
1048 struct arizona *arizona = info->arizona;
1049 unsigned int val, present, mask;
1050 bool cancelled_hp, cancelled_mic;
1053 cancelled_hp = cancel_delayed_work_sync(&info->hpdet_work);
1054 cancelled_mic = cancel_delayed_work_sync(&info->micd_timeout_work);
1056 pm_runtime_get_sync(info->dev);
1058 mutex_lock(&info->lock);
1060 if (info->micd_clamp) {
1061 mask = ARIZONA_MICD_CLAMP_STS;
1064 mask = ARIZONA_JD1_STS;
1065 if (arizona->pdata.jd_invert)
1068 present = ARIZONA_JD1_STS;
1071 ret = regmap_read(arizona->regmap, ARIZONA_AOD_IRQ_RAW_STATUS, &val);
1073 dev_err(arizona->dev, "Failed to read jackdet status: %d\n",
1075 mutex_unlock(&info->lock);
1076 pm_runtime_put_autosuspend(info->dev);
1081 if (val == info->last_jackdet) {
1082 dev_dbg(arizona->dev, "Suppressing duplicate JACKDET\n");
1084 queue_delayed_work(system_power_efficient_wq,
1086 msecs_to_jiffies(HPDET_DEBOUNCE));
1088 if (cancelled_mic) {
1089 int micd_timeout = info->micd_timeout;
1091 queue_delayed_work(system_power_efficient_wq,
1092 &info->micd_timeout_work,
1093 msecs_to_jiffies(micd_timeout));
1098 info->last_jackdet = val;
1100 if (info->last_jackdet == present) {
1101 dev_dbg(arizona->dev, "Detected jack\n");
1102 ret = extcon_set_cable_state_(info->edev,
1103 EXTCON_MECHANICAL, true);
1106 dev_err(arizona->dev, "Mechanical report failed: %d\n",
1109 if (!arizona->pdata.hpdet_acc_id) {
1110 info->detecting = true;
1112 info->jack_flips = 0;
1114 arizona_start_mic(info);
1116 queue_delayed_work(system_power_efficient_wq,
1118 msecs_to_jiffies(HPDET_DEBOUNCE));
1121 if (info->micd_clamp || !arizona->pdata.jd_invert)
1122 regmap_update_bits(arizona->regmap,
1123 ARIZONA_JACK_DETECT_DEBOUNCE,
1124 ARIZONA_MICD_CLAMP_DB |
1127 dev_dbg(arizona->dev, "Detected jack removal\n");
1129 arizona_stop_mic(info);
1131 info->num_hpdet_res = 0;
1132 for (i = 0; i < ARRAY_SIZE(info->hpdet_res); i++)
1133 info->hpdet_res[i] = 0;
1135 info->hpdet_done = false;
1136 info->hpdet_retried = false;
1138 for (i = 0; i < info->num_micd_ranges; i++)
1139 input_report_key(info->input,
1140 info->micd_ranges[i].key, 0);
1141 input_sync(info->input);
1143 ret = extcon_update_state(info->edev, 0xffffffff, 0);
1145 dev_err(arizona->dev, "Removal report failed: %d\n",
1148 regmap_update_bits(arizona->regmap,
1149 ARIZONA_JACK_DETECT_DEBOUNCE,
1150 ARIZONA_MICD_CLAMP_DB | ARIZONA_JD1_DB,
1151 ARIZONA_MICD_CLAMP_DB | ARIZONA_JD1_DB);
1154 if (arizona->pdata.micd_timeout)
1155 info->micd_timeout = arizona->pdata.micd_timeout;
1157 info->micd_timeout = DEFAULT_MICD_TIMEOUT;
1160 /* Clear trig_sts to make sure DCVDD is not forced up */
1161 regmap_write(arizona->regmap, ARIZONA_AOD_WKUP_AND_TRIG,
1162 ARIZONA_MICD_CLAMP_FALL_TRIG_STS |
1163 ARIZONA_MICD_CLAMP_RISE_TRIG_STS |
1164 ARIZONA_JD1_FALL_TRIG_STS |
1165 ARIZONA_JD1_RISE_TRIG_STS);
1167 mutex_unlock(&info->lock);
1169 pm_runtime_mark_last_busy(info->dev);
1170 pm_runtime_put_autosuspend(info->dev);
1175 /* Map a level onto a slot in the register bank */
1176 static void arizona_micd_set_level(struct arizona *arizona, int index,
1182 reg = ARIZONA_MIC_DETECT_LEVEL_4 - (index / 2);
1191 /* Program the level itself */
1192 regmap_update_bits(arizona->regmap, reg, mask, level);
1195 static int arizona_extcon_device_get_pdata(struct arizona *arizona)
1197 struct arizona_pdata *pdata = &arizona->pdata;
1198 unsigned int val = ARIZONA_ACCDET_MODE_HPL;
1200 device_property_read_u32(arizona->dev, "wlf,hpdet-channel", &val);
1202 case ARIZONA_ACCDET_MODE_HPL:
1203 case ARIZONA_ACCDET_MODE_HPR:
1204 pdata->hpdet_channel = val;
1207 dev_err(arizona->dev,
1208 "Wrong wlf,hpdet-channel DT value %d\n", val);
1209 pdata->hpdet_channel = ARIZONA_ACCDET_MODE_HPL;
1212 device_property_read_u32(arizona->dev, "wlf,micd-detect-debounce",
1213 &pdata->micd_detect_debounce);
1215 device_property_read_u32(arizona->dev, "wlf,micd-bias-start-time",
1216 &pdata->micd_bias_start_time);
1218 device_property_read_u32(arizona->dev, "wlf,micd-rate",
1221 device_property_read_u32(arizona->dev, "wlf,micd-dbtime",
1222 &pdata->micd_dbtime);
1224 device_property_read_u32(arizona->dev, "wlf,micd-timeout",
1225 &pdata->micd_timeout);
1227 pdata->micd_force_micbias = device_property_read_bool(arizona->dev,
1228 "wlf,micd-force-micbias");
1233 static int arizona_extcon_probe(struct platform_device *pdev)
1235 struct arizona *arizona = dev_get_drvdata(pdev->dev.parent);
1236 struct arizona_pdata *pdata = &arizona->pdata;
1237 struct arizona_extcon_info *info;
1239 unsigned int clamp_mode;
1240 int jack_irq_fall, jack_irq_rise;
1241 int ret, mode, i, j;
1243 if (!arizona->dapm || !arizona->dapm->card)
1244 return -EPROBE_DEFER;
1246 info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL);
1250 if (!dev_get_platdata(arizona->dev))
1251 arizona_extcon_device_get_pdata(arizona);
1253 info->micvdd = devm_regulator_get(&pdev->dev, "MICVDD");
1254 if (IS_ERR(info->micvdd)) {
1255 ret = PTR_ERR(info->micvdd);
1256 dev_err(arizona->dev, "Failed to get MICVDD: %d\n", ret);
1260 mutex_init(&info->lock);
1261 info->arizona = arizona;
1262 info->dev = &pdev->dev;
1263 info->last_jackdet = ~(ARIZONA_MICD_CLAMP_STS | ARIZONA_JD1_STS);
1264 INIT_DELAYED_WORK(&info->hpdet_work, arizona_hpdet_work);
1265 INIT_DELAYED_WORK(&info->micd_detect_work, arizona_micd_detect);
1266 INIT_DELAYED_WORK(&info->micd_timeout_work, arizona_micd_timeout_work);
1267 platform_set_drvdata(pdev, info);
1269 switch (arizona->type) {
1271 switch (arizona->rev) {
1273 info->micd_reva = true;
1276 info->micd_clamp = true;
1277 info->hpdet_ip_version = 1;
1283 switch (arizona->rev) {
1287 info->micd_clamp = true;
1288 info->hpdet_ip_version = 2;
1296 info->edev = devm_extcon_dev_allocate(&pdev->dev, arizona_cable);
1297 if (IS_ERR(info->edev)) {
1298 dev_err(&pdev->dev, "failed to allocate extcon device\n");
1302 ret = devm_extcon_dev_register(&pdev->dev, info->edev);
1304 dev_err(arizona->dev, "extcon_dev_register() failed: %d\n",
1309 info->input = devm_input_allocate_device(&pdev->dev);
1311 dev_err(arizona->dev, "Can't allocate input dev\n");
1316 info->input->name = "Headset";
1317 info->input->phys = "arizona/extcon";
1319 if (pdata->num_micd_configs) {
1320 info->micd_modes = pdata->micd_configs;
1321 info->micd_num_modes = pdata->num_micd_configs;
1323 info->micd_modes = micd_default_modes;
1324 info->micd_num_modes = ARRAY_SIZE(micd_default_modes);
1327 if (arizona->pdata.gpsw > 0)
1328 regmap_update_bits(arizona->regmap, ARIZONA_GP_SWITCH_1,
1329 ARIZONA_SW1_MODE_MASK, arizona->pdata.gpsw);
1331 if (arizona->pdata.micd_pol_gpio > 0) {
1332 if (info->micd_modes[0].gpio)
1333 mode = GPIOF_OUT_INIT_HIGH;
1335 mode = GPIOF_OUT_INIT_LOW;
1337 ret = devm_gpio_request_one(&pdev->dev,
1338 arizona->pdata.micd_pol_gpio,
1342 dev_err(arizona->dev, "Failed to request GPIO%d: %d\n",
1343 arizona->pdata.micd_pol_gpio, ret);
1347 if (info->micd_modes[0].gpio)
1348 mode = GPIOD_OUT_HIGH;
1350 mode = GPIOD_OUT_LOW;
1352 /* We can't use devm here because we need to do the get
1353 * against the MFD device, as that is where the of_node
1354 * will reside, but if we devm against that the GPIO
1355 * will not be freed if the extcon driver is unloaded.
1357 info->micd_pol_gpio = gpiod_get_optional(arizona->dev,
1360 if (IS_ERR(info->micd_pol_gpio)) {
1361 ret = PTR_ERR(info->micd_pol_gpio);
1362 dev_err(arizona->dev,
1363 "Failed to get microphone polarity GPIO: %d\n",
1369 if (arizona->pdata.hpdet_id_gpio > 0) {
1370 ret = devm_gpio_request_one(&pdev->dev,
1371 arizona->pdata.hpdet_id_gpio,
1375 dev_err(arizona->dev, "Failed to request GPIO%d: %d\n",
1376 arizona->pdata.hpdet_id_gpio, ret);
1381 if (arizona->pdata.micd_bias_start_time)
1382 regmap_update_bits(arizona->regmap, ARIZONA_MIC_DETECT_1,
1383 ARIZONA_MICD_BIAS_STARTTIME_MASK,
1384 arizona->pdata.micd_bias_start_time
1385 << ARIZONA_MICD_BIAS_STARTTIME_SHIFT);
1387 if (arizona->pdata.micd_rate)
1388 regmap_update_bits(arizona->regmap, ARIZONA_MIC_DETECT_1,
1389 ARIZONA_MICD_RATE_MASK,
1390 arizona->pdata.micd_rate
1391 << ARIZONA_MICD_RATE_SHIFT);
1393 switch (arizona->pdata.micd_dbtime) {
1394 case MICD_DBTIME_FOUR_READINGS:
1395 regmap_update_bits(arizona->regmap, ARIZONA_MIC_DETECT_1,
1396 ARIZONA_MICD_DBTIME_MASK,
1397 ARIZONA_MICD_DBTIME);
1399 case MICD_DBTIME_TWO_READINGS:
1400 regmap_update_bits(arizona->regmap, ARIZONA_MIC_DETECT_1,
1401 ARIZONA_MICD_DBTIME_MASK, 0);
1407 BUILD_BUG_ON(ARRAY_SIZE(arizona_micd_levels) <
1408 ARIZONA_NUM_MICD_BUTTON_LEVELS);
1410 if (arizona->pdata.num_micd_ranges) {
1411 info->micd_ranges = pdata->micd_ranges;
1412 info->num_micd_ranges = pdata->num_micd_ranges;
1414 info->micd_ranges = micd_default_ranges;
1415 info->num_micd_ranges = ARRAY_SIZE(micd_default_ranges);
1418 if (arizona->pdata.num_micd_ranges > ARIZONA_MAX_MICD_RANGE) {
1419 dev_err(arizona->dev, "Too many MICD ranges: %d\n",
1420 arizona->pdata.num_micd_ranges);
1423 if (info->num_micd_ranges > 1) {
1424 for (i = 1; i < info->num_micd_ranges; i++) {
1425 if (info->micd_ranges[i - 1].max >
1426 info->micd_ranges[i].max) {
1427 dev_err(arizona->dev,
1428 "MICD ranges must be sorted\n");
1435 /* Disable all buttons by default */
1436 regmap_update_bits(arizona->regmap, ARIZONA_MIC_DETECT_2,
1437 ARIZONA_MICD_LVL_SEL_MASK, 0x81);
1439 /* Set up all the buttons the user specified */
1440 for (i = 0; i < info->num_micd_ranges; i++) {
1441 for (j = 0; j < ARIZONA_NUM_MICD_BUTTON_LEVELS; j++)
1442 if (arizona_micd_levels[j] >= info->micd_ranges[i].max)
1445 if (j == ARIZONA_NUM_MICD_BUTTON_LEVELS) {
1446 dev_err(arizona->dev, "Unsupported MICD level %d\n",
1447 info->micd_ranges[i].max);
1452 dev_dbg(arizona->dev, "%d ohms for MICD threshold %d\n",
1453 arizona_micd_levels[j], i);
1455 arizona_micd_set_level(arizona, i, j);
1456 input_set_capability(info->input, EV_KEY,
1457 info->micd_ranges[i].key);
1459 /* Enable reporting of that range */
1460 regmap_update_bits(arizona->regmap, ARIZONA_MIC_DETECT_2,
1464 /* Set all the remaining keys to a maximum */
1465 for (; i < ARIZONA_MAX_MICD_RANGE; i++)
1466 arizona_micd_set_level(arizona, i, 0x3f);
1469 * If we have a clamp use it, activating in conjunction with
1470 * GPIO5 if that is connected for jack detect operation.
1472 if (info->micd_clamp) {
1473 if (arizona->pdata.jd_gpio5) {
1474 /* Put the GPIO into input mode with optional pull */
1476 if (arizona->pdata.jd_gpio5_nopull)
1477 val &= ~ARIZONA_GPN_PU;
1479 regmap_write(arizona->regmap, ARIZONA_GPIO5_CTRL,
1482 if (arizona->pdata.jd_invert)
1483 clamp_mode = ARIZONA_MICD_CLAMP_MODE_JDH_GP5H;
1485 clamp_mode = ARIZONA_MICD_CLAMP_MODE_JDL_GP5H;
1487 if (arizona->pdata.jd_invert)
1488 clamp_mode = ARIZONA_MICD_CLAMP_MODE_JDH;
1490 clamp_mode = ARIZONA_MICD_CLAMP_MODE_JDL;
1493 regmap_update_bits(arizona->regmap,
1494 ARIZONA_MICD_CLAMP_CONTROL,
1495 ARIZONA_MICD_CLAMP_MODE_MASK, clamp_mode);
1497 regmap_update_bits(arizona->regmap,
1498 ARIZONA_JACK_DETECT_DEBOUNCE,
1499 ARIZONA_MICD_CLAMP_DB,
1500 ARIZONA_MICD_CLAMP_DB);
1503 arizona_extcon_set_mode(info, 0);
1505 pm_runtime_enable(&pdev->dev);
1506 pm_runtime_idle(&pdev->dev);
1507 pm_runtime_get_sync(&pdev->dev);
1509 if (info->micd_clamp) {
1510 jack_irq_rise = ARIZONA_IRQ_MICD_CLAMP_RISE;
1511 jack_irq_fall = ARIZONA_IRQ_MICD_CLAMP_FALL;
1513 jack_irq_rise = ARIZONA_IRQ_JD_RISE;
1514 jack_irq_fall = ARIZONA_IRQ_JD_FALL;
1517 ret = arizona_request_irq(arizona, jack_irq_rise,
1518 "JACKDET rise", arizona_jackdet, info);
1520 dev_err(&pdev->dev, "Failed to get JACKDET rise IRQ: %d\n",
1525 ret = arizona_set_irq_wake(arizona, jack_irq_rise, 1);
1527 dev_err(&pdev->dev, "Failed to set JD rise IRQ wake: %d\n",
1532 ret = arizona_request_irq(arizona, jack_irq_fall,
1533 "JACKDET fall", arizona_jackdet, info);
1535 dev_err(&pdev->dev, "Failed to get JD fall IRQ: %d\n", ret);
1539 ret = arizona_set_irq_wake(arizona, jack_irq_fall, 1);
1541 dev_err(&pdev->dev, "Failed to set JD fall IRQ wake: %d\n",
1546 ret = arizona_request_irq(arizona, ARIZONA_IRQ_MICDET,
1547 "MICDET", arizona_micdet, info);
1549 dev_err(&pdev->dev, "Failed to get MICDET IRQ: %d\n", ret);
1553 ret = arizona_request_irq(arizona, ARIZONA_IRQ_HPDET,
1554 "HPDET", arizona_hpdet_irq, info);
1556 dev_err(&pdev->dev, "Failed to get HPDET IRQ: %d\n", ret);
1560 arizona_clk32k_enable(arizona);
1561 regmap_update_bits(arizona->regmap, ARIZONA_JACK_DETECT_DEBOUNCE,
1562 ARIZONA_JD1_DB, ARIZONA_JD1_DB);
1563 regmap_update_bits(arizona->regmap, ARIZONA_JACK_DETECT_ANALOGUE,
1564 ARIZONA_JD1_ENA, ARIZONA_JD1_ENA);
1566 ret = regulator_allow_bypass(info->micvdd, true);
1568 dev_warn(arizona->dev, "Failed to set MICVDD to bypass: %d\n",
1571 pm_runtime_put(&pdev->dev);
1573 ret = input_register_device(info->input);
1575 dev_err(&pdev->dev, "Can't register input device: %d\n", ret);
1582 arizona_free_irq(arizona, ARIZONA_IRQ_HPDET, info);
1584 arizona_free_irq(arizona, ARIZONA_IRQ_MICDET, info);
1586 arizona_set_irq_wake(arizona, jack_irq_fall, 0);
1588 arizona_free_irq(arizona, jack_irq_fall, info);
1590 arizona_set_irq_wake(arizona, jack_irq_rise, 0);
1592 arizona_free_irq(arizona, jack_irq_rise, info);
1594 gpiod_put(info->micd_pol_gpio);
1596 pm_runtime_disable(&pdev->dev);
1600 static int arizona_extcon_remove(struct platform_device *pdev)
1602 struct arizona_extcon_info *info = platform_get_drvdata(pdev);
1603 struct arizona *arizona = info->arizona;
1604 int jack_irq_rise, jack_irq_fall;
1606 gpiod_put(info->micd_pol_gpio);
1608 pm_runtime_disable(&pdev->dev);
1610 regmap_update_bits(arizona->regmap,
1611 ARIZONA_MICD_CLAMP_CONTROL,
1612 ARIZONA_MICD_CLAMP_MODE_MASK, 0);
1614 if (info->micd_clamp) {
1615 jack_irq_rise = ARIZONA_IRQ_MICD_CLAMP_RISE;
1616 jack_irq_fall = ARIZONA_IRQ_MICD_CLAMP_FALL;
1618 jack_irq_rise = ARIZONA_IRQ_JD_RISE;
1619 jack_irq_fall = ARIZONA_IRQ_JD_FALL;
1622 arizona_set_irq_wake(arizona, jack_irq_rise, 0);
1623 arizona_set_irq_wake(arizona, jack_irq_fall, 0);
1624 arizona_free_irq(arizona, ARIZONA_IRQ_HPDET, info);
1625 arizona_free_irq(arizona, ARIZONA_IRQ_MICDET, info);
1626 arizona_free_irq(arizona, jack_irq_rise, info);
1627 arizona_free_irq(arizona, jack_irq_fall, info);
1628 cancel_delayed_work_sync(&info->hpdet_work);
1629 regmap_update_bits(arizona->regmap, ARIZONA_JACK_DETECT_ANALOGUE,
1630 ARIZONA_JD1_ENA, 0);
1631 arizona_clk32k_disable(arizona);
1636 static struct platform_driver arizona_extcon_driver = {
1638 .name = "arizona-extcon",
1640 .probe = arizona_extcon_probe,
1641 .remove = arizona_extcon_remove,
1644 module_platform_driver(arizona_extcon_driver);
1646 MODULE_DESCRIPTION("Arizona Extcon driver");
1647 MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
1648 MODULE_LICENSE("GPL");
1649 MODULE_ALIAS("platform:extcon-arizona");