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_HPDET_MAX 10000
48 #define HPDET_DEBOUNCE 500
49 #define DEFAULT_MICD_TIMEOUT 2000
51 #define QUICK_HEADPHONE_MAX_OHM 3
52 #define MICROPHONE_MIN_OHM 1257
53 #define MICROPHONE_MAX_OHM 30000
55 #define MICD_DBTIME_TWO_READINGS 2
56 #define MICD_DBTIME_FOUR_READINGS 4
58 #define MICD_LVL_1_TO_7 (ARIZONA_MICD_LVL_1 | ARIZONA_MICD_LVL_2 | \
59 ARIZONA_MICD_LVL_3 | ARIZONA_MICD_LVL_4 | \
60 ARIZONA_MICD_LVL_5 | ARIZONA_MICD_LVL_6 | \
63 #define MICD_LVL_0_TO_7 (ARIZONA_MICD_LVL_0 | MICD_LVL_1_TO_7)
65 #define MICD_LVL_0_TO_8 (MICD_LVL_0_TO_7 | ARIZONA_MICD_LVL_8)
67 struct arizona_extcon_info {
69 struct arizona *arizona;
71 struct regulator *micvdd;
72 struct input_dev *input;
77 const struct arizona_micd_config *micd_modes;
80 const struct arizona_micd_range *micd_ranges;
88 struct delayed_work hpdet_work;
89 struct delayed_work micd_detect_work;
90 struct delayed_work micd_timeout_work;
97 unsigned int hpdet_res[3];
103 int hpdet_ip_version;
105 struct extcon_dev *edev;
107 struct gpio_desc *micd_pol_gpio;
110 static const struct arizona_micd_config micd_default_modes[] = {
111 { ARIZONA_ACCDET_SRC, 1, 0 },
115 static const struct arizona_micd_range micd_default_ranges[] = {
116 { .max = 11, .key = BTN_0 },
117 { .max = 28, .key = BTN_1 },
118 { .max = 54, .key = BTN_2 },
119 { .max = 100, .key = BTN_3 },
120 { .max = 186, .key = BTN_4 },
121 { .max = 430, .key = BTN_5 },
124 /* The number of levels in arizona_micd_levels valid for button thresholds */
125 #define ARIZONA_NUM_MICD_BUTTON_LEVELS 64
127 static const int arizona_micd_levels[] = {
128 3, 6, 8, 11, 13, 16, 18, 21, 23, 26, 28, 31, 34, 36, 39, 41, 44, 46,
129 49, 52, 54, 57, 60, 62, 65, 67, 70, 73, 75, 78, 81, 83, 89, 94, 100,
130 105, 111, 116, 122, 127, 139, 150, 161, 173, 186, 196, 209, 220, 245,
131 270, 295, 321, 348, 375, 402, 430, 489, 550, 614, 681, 752, 903, 1071,
135 static const unsigned int arizona_cable[] = {
143 static void arizona_start_hpdet_acc_id(struct arizona_extcon_info *info);
145 static void arizona_extcon_hp_clamp(struct arizona_extcon_info *info,
148 struct arizona *arizona = info->arizona;
149 unsigned int mask = 0, val = 0;
152 switch (arizona->type) {
155 mask = ARIZONA_HP1L_SHRTO | ARIZONA_HP1L_FLWR |
158 val = ARIZONA_HP1L_SHRTO;
160 val = ARIZONA_HP1L_FLWR | ARIZONA_HP1L_SHRTI;
163 mask = ARIZONA_RMV_SHRT_HP1L;
165 val = ARIZONA_RMV_SHRT_HP1L;
169 mutex_lock(&arizona->dapm->card->dapm_mutex);
171 arizona->hpdet_clamp = clamp;
173 /* Keep the HP output stages disabled while doing the clamp */
175 ret = regmap_update_bits(arizona->regmap,
176 ARIZONA_OUTPUT_ENABLES_1,
178 ARIZONA_OUT1R_ENA, 0);
180 dev_warn(arizona->dev,
181 "Failed to disable headphone outputs: %d\n",
185 ret = regmap_update_bits(arizona->regmap, ARIZONA_HP_CTRL_1L,
188 dev_warn(arizona->dev, "Failed to do clamp: %d\n",
191 ret = regmap_update_bits(arizona->regmap, ARIZONA_HP_CTRL_1R,
194 dev_warn(arizona->dev, "Failed to do clamp: %d\n",
197 /* Restore the desired state while not doing the clamp */
199 ret = regmap_update_bits(arizona->regmap,
200 ARIZONA_OUTPUT_ENABLES_1,
202 ARIZONA_OUT1R_ENA, arizona->hp_ena);
204 dev_warn(arizona->dev,
205 "Failed to restore headphone outputs: %d\n",
209 mutex_unlock(&arizona->dapm->card->dapm_mutex);
212 static void arizona_extcon_set_mode(struct arizona_extcon_info *info, int mode)
214 struct arizona *arizona = info->arizona;
216 mode %= info->micd_num_modes;
218 if (arizona->pdata.micd_pol_gpio > 0)
219 gpio_set_value_cansleep(arizona->pdata.micd_pol_gpio,
220 info->micd_modes[mode].gpio);
222 gpiod_set_value_cansleep(info->micd_pol_gpio,
223 info->micd_modes[mode].gpio);
225 regmap_update_bits(arizona->regmap, ARIZONA_MIC_DETECT_1,
226 ARIZONA_MICD_BIAS_SRC_MASK,
227 info->micd_modes[mode].bias <<
228 ARIZONA_MICD_BIAS_SRC_SHIFT);
229 regmap_update_bits(arizona->regmap, ARIZONA_ACCESSORY_DETECT_MODE_1,
230 ARIZONA_ACCDET_SRC, info->micd_modes[mode].src);
232 info->micd_mode = mode;
234 dev_dbg(arizona->dev, "Set jack polarity to %d\n", mode);
237 static const char *arizona_extcon_get_micbias(struct arizona_extcon_info *info)
239 switch (info->micd_modes[0].bias) {
251 static void arizona_extcon_pulse_micbias(struct arizona_extcon_info *info)
253 struct arizona *arizona = info->arizona;
254 const char *widget = arizona_extcon_get_micbias(info);
255 struct snd_soc_dapm_context *dapm = arizona->dapm;
258 ret = snd_soc_dapm_force_enable_pin(dapm, widget);
260 dev_warn(arizona->dev, "Failed to enable %s: %d\n",
263 snd_soc_dapm_sync(dapm);
265 if (!arizona->pdata.micd_force_micbias) {
266 ret = snd_soc_dapm_disable_pin(arizona->dapm, widget);
268 dev_warn(arizona->dev, "Failed to disable %s: %d\n",
271 snd_soc_dapm_sync(dapm);
275 static void arizona_start_mic(struct arizona_extcon_info *info)
277 struct arizona *arizona = info->arizona;
282 /* Microphone detection can't use idle mode */
283 pm_runtime_get(info->dev);
285 if (info->detecting) {
286 ret = regulator_allow_bypass(info->micvdd, false);
288 dev_err(arizona->dev,
289 "Failed to regulate MICVDD: %d\n",
294 ret = regulator_enable(info->micvdd);
296 dev_err(arizona->dev, "Failed to enable MICVDD: %d\n",
300 if (info->micd_reva) {
301 regmap_write(arizona->regmap, 0x80, 0x3);
302 regmap_write(arizona->regmap, 0x294, 0);
303 regmap_write(arizona->regmap, 0x80, 0x0);
306 if (info->detecting && arizona->pdata.micd_software_compare)
307 mode = ARIZONA_ACCDET_MODE_ADC;
309 mode = ARIZONA_ACCDET_MODE_MIC;
311 regmap_update_bits(arizona->regmap,
312 ARIZONA_ACCESSORY_DETECT_MODE_1,
313 ARIZONA_ACCDET_MODE_MASK, mode);
315 arizona_extcon_pulse_micbias(info);
317 regmap_update_bits_check(arizona->regmap, ARIZONA_MIC_DETECT_1,
318 ARIZONA_MICD_ENA, ARIZONA_MICD_ENA,
321 regulator_disable(info->micvdd);
322 pm_runtime_put_autosuspend(info->dev);
326 static void arizona_stop_mic(struct arizona_extcon_info *info)
328 struct arizona *arizona = info->arizona;
329 const char *widget = arizona_extcon_get_micbias(info);
330 struct snd_soc_dapm_context *dapm = arizona->dapm;
334 regmap_update_bits_check(arizona->regmap, ARIZONA_MIC_DETECT_1,
338 ret = snd_soc_dapm_disable_pin(dapm, widget);
340 dev_warn(arizona->dev,
341 "Failed to disable %s: %d\n",
344 snd_soc_dapm_sync(dapm);
346 if (info->micd_reva) {
347 regmap_write(arizona->regmap, 0x80, 0x3);
348 regmap_write(arizona->regmap, 0x294, 2);
349 regmap_write(arizona->regmap, 0x80, 0x0);
352 ret = regulator_allow_bypass(info->micvdd, true);
354 dev_err(arizona->dev, "Failed to bypass MICVDD: %d\n",
359 regulator_disable(info->micvdd);
360 pm_runtime_mark_last_busy(info->dev);
361 pm_runtime_put_autosuspend(info->dev);
366 unsigned int threshold;
367 unsigned int factor_a;
368 unsigned int factor_b;
369 } arizona_hpdet_b_ranges[] = {
370 { 100, 5528, 362464 },
371 { 169, 11084, 6186851 },
372 { 169, 11065, 65460395 },
375 #define ARIZONA_HPDET_B_RANGE_MAX 0x3fb
380 } arizona_hpdet_c_ranges[] = {
387 static int arizona_hpdet_read(struct arizona_extcon_info *info)
389 struct arizona *arizona = info->arizona;
390 unsigned int val, range;
393 ret = regmap_read(arizona->regmap, ARIZONA_HEADPHONE_DETECT_2, &val);
395 dev_err(arizona->dev, "Failed to read HPDET status: %d\n",
400 switch (info->hpdet_ip_version) {
402 if (!(val & ARIZONA_HP_DONE)) {
403 dev_err(arizona->dev, "HPDET did not complete: %x\n",
408 val &= ARIZONA_HP_LVL_MASK;
412 if (!(val & ARIZONA_HP_DONE_B)) {
413 dev_err(arizona->dev, "HPDET did not complete: %x\n",
418 ret = regmap_read(arizona->regmap, ARIZONA_HP_DACVAL, &val);
420 dev_err(arizona->dev, "Failed to read HP value: %d\n",
425 regmap_read(arizona->regmap, ARIZONA_HEADPHONE_DETECT_1,
427 range = (range & ARIZONA_HP_IMPEDANCE_RANGE_MASK)
428 >> ARIZONA_HP_IMPEDANCE_RANGE_SHIFT;
430 if (range < ARRAY_SIZE(arizona_hpdet_b_ranges) - 1 &&
431 (val < arizona_hpdet_b_ranges[range].threshold ||
432 val >= ARIZONA_HPDET_B_RANGE_MAX)) {
434 dev_dbg(arizona->dev, "Moving to HPDET range %d\n",
436 regmap_update_bits(arizona->regmap,
437 ARIZONA_HEADPHONE_DETECT_1,
438 ARIZONA_HP_IMPEDANCE_RANGE_MASK,
440 ARIZONA_HP_IMPEDANCE_RANGE_SHIFT);
444 /* If we go out of range report top of range */
445 if (val < arizona_hpdet_b_ranges[range].threshold ||
446 val >= ARIZONA_HPDET_B_RANGE_MAX) {
447 dev_dbg(arizona->dev, "Measurement out of range\n");
448 return ARIZONA_HPDET_MAX;
451 dev_dbg(arizona->dev, "HPDET read %d in range %d\n",
454 val = arizona_hpdet_b_ranges[range].factor_b
456 arizona_hpdet_b_ranges[range].factor_a);
460 dev_warn(arizona->dev, "Unknown HPDET IP revision %d\n",
461 info->hpdet_ip_version);
463 if (!(val & ARIZONA_HP_DONE_B)) {
464 dev_err(arizona->dev, "HPDET did not complete: %x\n",
469 val &= ARIZONA_HP_LVL_B_MASK;
470 /* Convert to ohms, the value is in 0.5 ohm increments */
473 regmap_read(arizona->regmap, ARIZONA_HEADPHONE_DETECT_1,
475 range = (range & ARIZONA_HP_IMPEDANCE_RANGE_MASK)
476 >> ARIZONA_HP_IMPEDANCE_RANGE_SHIFT;
478 /* Skip up a range, or report? */
479 if (range < ARRAY_SIZE(arizona_hpdet_c_ranges) - 1 &&
480 (val >= arizona_hpdet_c_ranges[range].max)) {
482 dev_dbg(arizona->dev, "Moving to HPDET range %d-%d\n",
483 arizona_hpdet_c_ranges[range].min,
484 arizona_hpdet_c_ranges[range].max);
485 regmap_update_bits(arizona->regmap,
486 ARIZONA_HEADPHONE_DETECT_1,
487 ARIZONA_HP_IMPEDANCE_RANGE_MASK,
489 ARIZONA_HP_IMPEDANCE_RANGE_SHIFT);
493 if (range && (val < arizona_hpdet_c_ranges[range].min)) {
494 dev_dbg(arizona->dev, "Reporting range boundary %d\n",
495 arizona_hpdet_c_ranges[range].min);
496 val = arizona_hpdet_c_ranges[range].min;
500 dev_dbg(arizona->dev, "HP impedance %d ohms\n", val);
504 static int arizona_hpdet_do_id(struct arizona_extcon_info *info, int *reading,
507 struct arizona *arizona = info->arizona;
508 int id_gpio = arizona->pdata.hpdet_id_gpio;
511 * If we're using HPDET for accessory identification we need
512 * to take multiple measurements, step through them in sequence.
514 if (arizona->pdata.hpdet_acc_id) {
515 info->hpdet_res[info->num_hpdet_res++] = *reading;
517 /* Only check the mic directly if we didn't already ID it */
518 if (id_gpio && info->num_hpdet_res == 1) {
519 dev_dbg(arizona->dev, "Measuring mic\n");
521 regmap_update_bits(arizona->regmap,
522 ARIZONA_ACCESSORY_DETECT_MODE_1,
523 ARIZONA_ACCDET_MODE_MASK |
525 ARIZONA_ACCDET_MODE_HPR |
526 info->micd_modes[0].src);
528 gpio_set_value_cansleep(id_gpio, 1);
530 regmap_update_bits(arizona->regmap,
531 ARIZONA_HEADPHONE_DETECT_1,
532 ARIZONA_HP_POLL, ARIZONA_HP_POLL);
536 /* OK, got both. Now, compare... */
537 dev_dbg(arizona->dev, "HPDET measured %d %d\n",
538 info->hpdet_res[0], info->hpdet_res[1]);
540 /* Take the headphone impedance for the main report */
541 *reading = info->hpdet_res[0];
543 /* Sometimes we get false readings due to slow insert */
544 if (*reading >= ARIZONA_HPDET_MAX && !info->hpdet_retried) {
545 dev_dbg(arizona->dev, "Retrying high impedance\n");
546 info->num_hpdet_res = 0;
547 info->hpdet_retried = true;
548 arizona_start_hpdet_acc_id(info);
549 pm_runtime_put(info->dev);
554 * If we measure the mic as high impedance
556 if (!id_gpio || info->hpdet_res[1] > 50) {
557 dev_dbg(arizona->dev, "Detected mic\n");
559 info->detecting = true;
561 dev_dbg(arizona->dev, "Detected headphone\n");
564 /* Make sure everything is reset back to the real polarity */
565 regmap_update_bits(arizona->regmap,
566 ARIZONA_ACCESSORY_DETECT_MODE_1,
568 info->micd_modes[0].src);
574 static irqreturn_t arizona_hpdet_irq(int irq, void *data)
576 struct arizona_extcon_info *info = data;
577 struct arizona *arizona = info->arizona;
578 int id_gpio = arizona->pdata.hpdet_id_gpio;
579 unsigned int report = EXTCON_HEADPHONE;
583 mutex_lock(&info->lock);
585 /* If we got a spurious IRQ for some reason then ignore it */
586 if (!info->hpdet_active) {
587 dev_warn(arizona->dev, "Spurious HPDET IRQ\n");
588 mutex_unlock(&info->lock);
592 /* If the cable was removed while measuring ignore the result */
593 ret = extcon_get_cable_state_(info->edev, EXTCON_MECHANICAL);
595 dev_err(arizona->dev, "Failed to check cable state: %d\n",
599 dev_dbg(arizona->dev, "Ignoring HPDET for removed cable\n");
603 ret = arizona_hpdet_read(info);
610 /* Reset back to starting range */
611 regmap_update_bits(arizona->regmap,
612 ARIZONA_HEADPHONE_DETECT_1,
613 ARIZONA_HP_IMPEDANCE_RANGE_MASK | ARIZONA_HP_POLL,
616 ret = arizona_hpdet_do_id(info, &reading, &mic);
622 /* Report high impedence cables as line outputs */
624 report = EXTCON_LINE_OUT;
626 report = EXTCON_HEADPHONE;
628 ret = extcon_set_cable_state_(info->edev, report, true);
630 dev_err(arizona->dev, "Failed to report HP/line: %d\n",
634 /* Reset back to starting range */
635 regmap_update_bits(arizona->regmap,
636 ARIZONA_HEADPHONE_DETECT_1,
637 ARIZONA_HP_IMPEDANCE_RANGE_MASK | ARIZONA_HP_POLL,
640 arizona_extcon_hp_clamp(info, false);
643 gpio_set_value_cansleep(id_gpio, 0);
645 /* Revert back to MICDET mode */
646 regmap_update_bits(arizona->regmap,
647 ARIZONA_ACCESSORY_DETECT_MODE_1,
648 ARIZONA_ACCDET_MODE_MASK, ARIZONA_ACCDET_MODE_MIC);
650 /* If we have a mic then reenable MICDET */
651 if (mic || info->mic)
652 arizona_start_mic(info);
654 if (info->hpdet_active) {
655 pm_runtime_put_autosuspend(info->dev);
656 info->hpdet_active = false;
659 info->hpdet_done = true;
662 mutex_unlock(&info->lock);
667 static void arizona_identify_headphone(struct arizona_extcon_info *info)
669 struct arizona *arizona = info->arizona;
672 if (info->hpdet_done)
675 dev_dbg(arizona->dev, "Starting HPDET\n");
677 /* Make sure we keep the device enabled during the measurement */
678 pm_runtime_get(info->dev);
680 info->hpdet_active = true;
683 arizona_stop_mic(info);
685 arizona_extcon_hp_clamp(info, true);
687 ret = regmap_update_bits(arizona->regmap,
688 ARIZONA_ACCESSORY_DETECT_MODE_1,
689 ARIZONA_ACCDET_MODE_MASK,
690 arizona->pdata.hpdet_channel);
692 dev_err(arizona->dev, "Failed to set HPDET mode: %d\n", ret);
696 ret = regmap_update_bits(arizona->regmap, ARIZONA_HEADPHONE_DETECT_1,
697 ARIZONA_HP_POLL, ARIZONA_HP_POLL);
699 dev_err(arizona->dev, "Can't start HPDETL measurement: %d\n",
707 regmap_update_bits(arizona->regmap, ARIZONA_ACCESSORY_DETECT_MODE_1,
708 ARIZONA_ACCDET_MODE_MASK, ARIZONA_ACCDET_MODE_MIC);
710 /* Just report headphone */
711 ret = extcon_set_cable_state_(info->edev, EXTCON_HEADPHONE, true);
713 dev_err(arizona->dev, "Failed to report headphone: %d\n", ret);
716 arizona_start_mic(info);
718 info->hpdet_active = false;
721 static void arizona_start_hpdet_acc_id(struct arizona_extcon_info *info)
723 struct arizona *arizona = info->arizona;
728 dev_dbg(arizona->dev, "Starting identification via HPDET\n");
730 /* Make sure we keep the device enabled during the measurement */
731 pm_runtime_get_sync(info->dev);
733 info->hpdet_active = true;
735 arizona_extcon_hp_clamp(info, true);
737 ret = regmap_update_bits(arizona->regmap,
738 ARIZONA_ACCESSORY_DETECT_MODE_1,
739 ARIZONA_ACCDET_SRC | ARIZONA_ACCDET_MODE_MASK,
740 info->micd_modes[0].src |
741 arizona->pdata.hpdet_channel);
743 dev_err(arizona->dev, "Failed to set HPDET mode: %d\n", ret);
747 if (arizona->pdata.hpdet_acc_id_line) {
748 ret = regmap_update_bits(arizona->regmap,
749 ARIZONA_HEADPHONE_DETECT_1,
750 ARIZONA_HP_POLL, ARIZONA_HP_POLL);
752 dev_err(arizona->dev,
753 "Can't start HPDETL measurement: %d\n",
758 arizona_hpdet_do_id(info, &hp_reading, &mic);
764 regmap_update_bits(arizona->regmap, ARIZONA_ACCESSORY_DETECT_MODE_1,
765 ARIZONA_ACCDET_MODE_MASK, ARIZONA_ACCDET_MODE_MIC);
767 /* Just report headphone */
768 ret = extcon_set_cable_state_(info->edev, EXTCON_HEADPHONE, true);
770 dev_err(arizona->dev, "Failed to report headphone: %d\n", ret);
772 info->hpdet_active = false;
775 static void arizona_micd_timeout_work(struct work_struct *work)
777 struct arizona_extcon_info *info = container_of(work,
778 struct arizona_extcon_info,
779 micd_timeout_work.work);
781 mutex_lock(&info->lock);
783 dev_dbg(info->arizona->dev, "MICD timed out, reporting HP\n");
785 info->detecting = false;
787 arizona_identify_headphone(info);
789 arizona_stop_mic(info);
791 mutex_unlock(&info->lock);
794 static void arizona_micd_detect(struct work_struct *work)
796 struct arizona_extcon_info *info = container_of(work,
797 struct arizona_extcon_info,
798 micd_detect_work.work);
799 struct arizona *arizona = info->arizona;
800 unsigned int val = 0, lvl;
803 cancel_delayed_work_sync(&info->micd_timeout_work);
805 mutex_lock(&info->lock);
807 /* If the cable was removed while measuring ignore the result */
808 ret = extcon_get_cable_state_(info->edev, EXTCON_MECHANICAL);
810 dev_err(arizona->dev, "Failed to check cable state: %d\n",
812 mutex_unlock(&info->lock);
815 dev_dbg(arizona->dev, "Ignoring MICDET for removed cable\n");
816 mutex_unlock(&info->lock);
820 if (info->detecting && arizona->pdata.micd_software_compare) {
821 /* Must disable MICD before we read the ADCVAL */
822 regmap_update_bits(arizona->regmap, ARIZONA_MIC_DETECT_1,
823 ARIZONA_MICD_ENA, 0);
824 ret = regmap_read(arizona->regmap, ARIZONA_MIC_DETECT_4, &val);
826 dev_err(arizona->dev,
827 "Failed to read MICDET_ADCVAL: %d\n",
829 mutex_unlock(&info->lock);
833 dev_dbg(arizona->dev, "MICDET_ADCVAL: %x\n", val);
835 val &= ARIZONA_MICDET_ADCVAL_MASK;
836 if (val < ARRAY_SIZE(arizona_micd_levels))
837 val = arizona_micd_levels[val];
841 if (val <= QUICK_HEADPHONE_MAX_OHM)
842 val = ARIZONA_MICD_STS | ARIZONA_MICD_LVL_0;
843 else if (val <= MICROPHONE_MIN_OHM)
844 val = ARIZONA_MICD_STS | ARIZONA_MICD_LVL_1;
845 else if (val <= MICROPHONE_MAX_OHM)
846 val = ARIZONA_MICD_STS | ARIZONA_MICD_LVL_8;
848 val = ARIZONA_MICD_LVL_8;
851 for (i = 0; i < 10 && !(val & MICD_LVL_0_TO_8); i++) {
852 ret = regmap_read(arizona->regmap, ARIZONA_MIC_DETECT_3, &val);
854 dev_err(arizona->dev,
855 "Failed to read MICDET: %d\n", ret);
856 mutex_unlock(&info->lock);
860 dev_dbg(arizona->dev, "MICDET: %x\n", val);
862 if (!(val & ARIZONA_MICD_VALID)) {
863 dev_warn(arizona->dev,
864 "Microphone detection state invalid\n");
865 mutex_unlock(&info->lock);
870 if (i == 10 && !(val & MICD_LVL_0_TO_8)) {
871 dev_err(arizona->dev, "Failed to get valid MICDET value\n");
872 mutex_unlock(&info->lock);
876 /* Due to jack detect this should never happen */
877 if (!(val & ARIZONA_MICD_STS)) {
878 dev_warn(arizona->dev, "Detected open circuit\n");
880 arizona_stop_mic(info);
881 info->detecting = false;
882 arizona_identify_headphone(info);
886 /* If we got a high impedence we should have a headset, report it. */
887 if (info->detecting && (val & ARIZONA_MICD_LVL_8)) {
889 info->detecting = false;
891 arizona_identify_headphone(info);
893 ret = extcon_set_cable_state_(info->edev,
894 EXTCON_MICROPHONE, true);
896 dev_err(arizona->dev, "Headset report failed: %d\n",
899 /* Don't need to regulate for button detection */
900 ret = regulator_allow_bypass(info->micvdd, true);
902 dev_err(arizona->dev, "Failed to bypass MICVDD: %d\n",
909 /* If we detected a lower impedence during initial startup
910 * then we probably have the wrong polarity, flip it. Don't
911 * do this for the lowest impedences to speed up detection of
912 * plain headphones. If both polarities report a low
913 * impedence then give up and report headphones.
915 if (info->detecting && (val & MICD_LVL_1_TO_7)) {
916 if (info->jack_flips >= info->micd_num_modes * 10) {
917 dev_dbg(arizona->dev, "Detected HP/line\n");
919 info->detecting = false;
921 arizona_identify_headphone(info);
923 arizona_stop_mic(info);
926 if (info->micd_mode == info->micd_num_modes)
928 arizona_extcon_set_mode(info, info->micd_mode);
937 * If we're still detecting and we detect a short then we've
938 * got a headphone. Otherwise it's a button press.
940 if (val & MICD_LVL_0_TO_7) {
942 dev_dbg(arizona->dev, "Mic button detected\n");
944 lvl = val & ARIZONA_MICD_LVL_MASK;
945 lvl >>= ARIZONA_MICD_LVL_SHIFT;
947 for (i = 0; i < info->num_micd_ranges; i++)
948 input_report_key(info->input,
949 info->micd_ranges[i].key, 0);
952 WARN_ON(ffs(lvl) - 1 >= info->num_micd_ranges);
953 if (lvl && ffs(lvl) - 1 < info->num_micd_ranges) {
954 key = info->micd_ranges[ffs(lvl) - 1].key;
955 input_report_key(info->input, key, 1);
956 input_sync(info->input);
959 } else if (info->detecting) {
960 dev_dbg(arizona->dev, "Headphone detected\n");
961 info->detecting = false;
962 arizona_stop_mic(info);
964 arizona_identify_headphone(info);
966 dev_warn(arizona->dev, "Button with no mic: %x\n",
970 dev_dbg(arizona->dev, "Mic button released\n");
971 for (i = 0; i < info->num_micd_ranges; i++)
972 input_report_key(info->input,
973 info->micd_ranges[i].key, 0);
974 input_sync(info->input);
975 arizona_extcon_pulse_micbias(info);
979 if (info->detecting) {
980 if (arizona->pdata.micd_software_compare)
981 regmap_update_bits(arizona->regmap,
982 ARIZONA_MIC_DETECT_1,
986 queue_delayed_work(system_power_efficient_wq,
987 &info->micd_timeout_work,
988 msecs_to_jiffies(info->micd_timeout));
991 pm_runtime_mark_last_busy(info->dev);
992 mutex_unlock(&info->lock);
995 static irqreturn_t arizona_micdet(int irq, void *data)
997 struct arizona_extcon_info *info = data;
998 struct arizona *arizona = info->arizona;
999 int debounce = arizona->pdata.micd_detect_debounce;
1001 cancel_delayed_work_sync(&info->micd_detect_work);
1002 cancel_delayed_work_sync(&info->micd_timeout_work);
1004 mutex_lock(&info->lock);
1005 if (!info->detecting)
1007 mutex_unlock(&info->lock);
1010 queue_delayed_work(system_power_efficient_wq,
1011 &info->micd_detect_work,
1012 msecs_to_jiffies(debounce));
1014 arizona_micd_detect(&info->micd_detect_work.work);
1019 static void arizona_hpdet_work(struct work_struct *work)
1021 struct arizona_extcon_info *info = container_of(work,
1022 struct arizona_extcon_info,
1025 mutex_lock(&info->lock);
1026 arizona_start_hpdet_acc_id(info);
1027 mutex_unlock(&info->lock);
1030 static irqreturn_t arizona_jackdet(int irq, void *data)
1032 struct arizona_extcon_info *info = data;
1033 struct arizona *arizona = info->arizona;
1034 unsigned int val, present, mask;
1035 bool cancelled_hp, cancelled_mic;
1038 cancelled_hp = cancel_delayed_work_sync(&info->hpdet_work);
1039 cancelled_mic = cancel_delayed_work_sync(&info->micd_timeout_work);
1041 pm_runtime_get_sync(info->dev);
1043 mutex_lock(&info->lock);
1045 if (arizona->pdata.jd_gpio5) {
1046 mask = ARIZONA_MICD_CLAMP_STS;
1047 if (arizona->pdata.jd_invert)
1048 present = ARIZONA_MICD_CLAMP_STS;
1052 mask = ARIZONA_JD1_STS;
1053 if (arizona->pdata.jd_invert)
1056 present = ARIZONA_JD1_STS;
1059 ret = regmap_read(arizona->regmap, ARIZONA_AOD_IRQ_RAW_STATUS, &val);
1061 dev_err(arizona->dev, "Failed to read jackdet status: %d\n",
1063 mutex_unlock(&info->lock);
1064 pm_runtime_put_autosuspend(info->dev);
1069 if (val == info->last_jackdet) {
1070 dev_dbg(arizona->dev, "Suppressing duplicate JACKDET\n");
1072 queue_delayed_work(system_power_efficient_wq,
1074 msecs_to_jiffies(HPDET_DEBOUNCE));
1076 if (cancelled_mic) {
1077 int micd_timeout = info->micd_timeout;
1079 queue_delayed_work(system_power_efficient_wq,
1080 &info->micd_timeout_work,
1081 msecs_to_jiffies(micd_timeout));
1086 info->last_jackdet = val;
1088 if (info->last_jackdet == present) {
1089 dev_dbg(arizona->dev, "Detected jack\n");
1090 ret = extcon_set_cable_state_(info->edev,
1091 EXTCON_MECHANICAL, true);
1094 dev_err(arizona->dev, "Mechanical report failed: %d\n",
1097 if (!arizona->pdata.hpdet_acc_id) {
1098 info->detecting = true;
1100 info->jack_flips = 0;
1102 arizona_start_mic(info);
1104 queue_delayed_work(system_power_efficient_wq,
1106 msecs_to_jiffies(HPDET_DEBOUNCE));
1109 regmap_update_bits(arizona->regmap,
1110 ARIZONA_JACK_DETECT_DEBOUNCE,
1111 ARIZONA_MICD_CLAMP_DB | ARIZONA_JD1_DB, 0);
1113 dev_dbg(arizona->dev, "Detected jack removal\n");
1115 arizona_stop_mic(info);
1117 info->num_hpdet_res = 0;
1118 for (i = 0; i < ARRAY_SIZE(info->hpdet_res); i++)
1119 info->hpdet_res[i] = 0;
1121 info->hpdet_done = false;
1122 info->hpdet_retried = false;
1124 for (i = 0; i < info->num_micd_ranges; i++)
1125 input_report_key(info->input,
1126 info->micd_ranges[i].key, 0);
1127 input_sync(info->input);
1129 ret = extcon_update_state(info->edev, 0xffffffff, 0);
1131 dev_err(arizona->dev, "Removal report failed: %d\n",
1134 regmap_update_bits(arizona->regmap,
1135 ARIZONA_JACK_DETECT_DEBOUNCE,
1136 ARIZONA_MICD_CLAMP_DB | ARIZONA_JD1_DB,
1137 ARIZONA_MICD_CLAMP_DB | ARIZONA_JD1_DB);
1140 if (arizona->pdata.micd_timeout)
1141 info->micd_timeout = arizona->pdata.micd_timeout;
1143 info->micd_timeout = DEFAULT_MICD_TIMEOUT;
1146 /* Clear trig_sts to make sure DCVDD is not forced up */
1147 regmap_write(arizona->regmap, ARIZONA_AOD_WKUP_AND_TRIG,
1148 ARIZONA_MICD_CLAMP_FALL_TRIG_STS |
1149 ARIZONA_MICD_CLAMP_RISE_TRIG_STS |
1150 ARIZONA_JD1_FALL_TRIG_STS |
1151 ARIZONA_JD1_RISE_TRIG_STS);
1153 mutex_unlock(&info->lock);
1155 pm_runtime_mark_last_busy(info->dev);
1156 pm_runtime_put_autosuspend(info->dev);
1161 /* Map a level onto a slot in the register bank */
1162 static void arizona_micd_set_level(struct arizona *arizona, int index,
1168 reg = ARIZONA_MIC_DETECT_LEVEL_4 - (index / 2);
1177 /* Program the level itself */
1178 regmap_update_bits(arizona->regmap, reg, mask, level);
1181 static int arizona_extcon_device_get_pdata(struct arizona *arizona)
1183 struct arizona_pdata *pdata = &arizona->pdata;
1184 unsigned int val = ARIZONA_ACCDET_MODE_HPL;
1186 device_property_read_u32(arizona->dev, "wlf,hpdet-channel", &val);
1188 case ARIZONA_ACCDET_MODE_HPL:
1189 case ARIZONA_ACCDET_MODE_HPR:
1190 pdata->hpdet_channel = val;
1193 dev_err(arizona->dev,
1194 "Wrong wlf,hpdet-channel DT value %d\n", val);
1195 pdata->hpdet_channel = ARIZONA_ACCDET_MODE_HPL;
1198 device_property_read_u32(arizona->dev, "wlf,micd-detect-debounce",
1199 &pdata->micd_detect_debounce);
1201 device_property_read_u32(arizona->dev, "wlf,micd-bias-start-time",
1202 &pdata->micd_bias_start_time);
1204 device_property_read_u32(arizona->dev, "wlf,micd-rate",
1207 device_property_read_u32(arizona->dev, "wlf,micd-dbtime",
1208 &pdata->micd_dbtime);
1210 device_property_read_u32(arizona->dev, "wlf,micd-timeout",
1211 &pdata->micd_timeout);
1213 pdata->micd_force_micbias = device_property_read_bool(arizona->dev,
1214 "wlf,micd-force-micbias");
1219 static int arizona_extcon_probe(struct platform_device *pdev)
1221 struct arizona *arizona = dev_get_drvdata(pdev->dev.parent);
1222 struct arizona_pdata *pdata = &arizona->pdata;
1223 struct arizona_extcon_info *info;
1225 unsigned int clamp_mode;
1226 int jack_irq_fall, jack_irq_rise;
1227 int ret, mode, i, j;
1229 if (!arizona->dapm || !arizona->dapm->card)
1230 return -EPROBE_DEFER;
1232 info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL);
1236 if (!dev_get_platdata(arizona->dev))
1237 arizona_extcon_device_get_pdata(arizona);
1239 info->micvdd = devm_regulator_get(&pdev->dev, "MICVDD");
1240 if (IS_ERR(info->micvdd)) {
1241 ret = PTR_ERR(info->micvdd);
1242 dev_err(arizona->dev, "Failed to get MICVDD: %d\n", ret);
1246 mutex_init(&info->lock);
1247 info->arizona = arizona;
1248 info->dev = &pdev->dev;
1249 info->last_jackdet = ~(ARIZONA_MICD_CLAMP_STS | ARIZONA_JD1_STS);
1250 INIT_DELAYED_WORK(&info->hpdet_work, arizona_hpdet_work);
1251 INIT_DELAYED_WORK(&info->micd_detect_work, arizona_micd_detect);
1252 INIT_DELAYED_WORK(&info->micd_timeout_work, arizona_micd_timeout_work);
1253 platform_set_drvdata(pdev, info);
1255 switch (arizona->type) {
1257 switch (arizona->rev) {
1259 info->micd_reva = true;
1262 info->micd_clamp = true;
1263 info->hpdet_ip_version = 1;
1269 switch (arizona->rev) {
1273 info->micd_clamp = true;
1274 info->hpdet_ip_version = 2;
1282 info->edev = devm_extcon_dev_allocate(&pdev->dev, arizona_cable);
1283 if (IS_ERR(info->edev)) {
1284 dev_err(&pdev->dev, "failed to allocate extcon device\n");
1288 ret = devm_extcon_dev_register(&pdev->dev, info->edev);
1290 dev_err(arizona->dev, "extcon_dev_register() failed: %d\n",
1295 info->input = devm_input_allocate_device(&pdev->dev);
1297 dev_err(arizona->dev, "Can't allocate input dev\n");
1302 info->input->name = "Headset";
1303 info->input->phys = "arizona/extcon";
1305 if (pdata->num_micd_configs) {
1306 info->micd_modes = pdata->micd_configs;
1307 info->micd_num_modes = pdata->num_micd_configs;
1309 info->micd_modes = micd_default_modes;
1310 info->micd_num_modes = ARRAY_SIZE(micd_default_modes);
1313 if (arizona->pdata.micd_pol_gpio > 0) {
1314 if (info->micd_modes[0].gpio)
1315 mode = GPIOF_OUT_INIT_HIGH;
1317 mode = GPIOF_OUT_INIT_LOW;
1319 ret = devm_gpio_request_one(&pdev->dev,
1320 arizona->pdata.micd_pol_gpio,
1324 dev_err(arizona->dev, "Failed to request GPIO%d: %d\n",
1325 arizona->pdata.micd_pol_gpio, ret);
1329 if (info->micd_modes[0].gpio)
1330 mode = GPIOD_OUT_HIGH;
1332 mode = GPIOD_OUT_LOW;
1334 /* We can't use devm here because we need to do the get
1335 * against the MFD device, as that is where the of_node
1336 * will reside, but if we devm against that the GPIO
1337 * will not be freed if the extcon driver is unloaded.
1339 info->micd_pol_gpio = gpiod_get_optional(arizona->dev,
1342 if (IS_ERR(info->micd_pol_gpio)) {
1343 ret = PTR_ERR(info->micd_pol_gpio);
1344 dev_err(arizona->dev,
1345 "Failed to get microphone polarity GPIO: %d\n",
1351 if (arizona->pdata.hpdet_id_gpio > 0) {
1352 ret = devm_gpio_request_one(&pdev->dev,
1353 arizona->pdata.hpdet_id_gpio,
1357 dev_err(arizona->dev, "Failed to request GPIO%d: %d\n",
1358 arizona->pdata.hpdet_id_gpio, ret);
1363 if (arizona->pdata.micd_bias_start_time)
1364 regmap_update_bits(arizona->regmap, ARIZONA_MIC_DETECT_1,
1365 ARIZONA_MICD_BIAS_STARTTIME_MASK,
1366 arizona->pdata.micd_bias_start_time
1367 << ARIZONA_MICD_BIAS_STARTTIME_SHIFT);
1369 if (arizona->pdata.micd_rate)
1370 regmap_update_bits(arizona->regmap, ARIZONA_MIC_DETECT_1,
1371 ARIZONA_MICD_RATE_MASK,
1372 arizona->pdata.micd_rate
1373 << ARIZONA_MICD_RATE_SHIFT);
1375 switch (arizona->pdata.micd_dbtime) {
1376 case MICD_DBTIME_FOUR_READINGS:
1377 regmap_update_bits(arizona->regmap, ARIZONA_MIC_DETECT_1,
1378 ARIZONA_MICD_DBTIME_MASK,
1379 ARIZONA_MICD_DBTIME);
1381 case MICD_DBTIME_TWO_READINGS:
1382 regmap_update_bits(arizona->regmap, ARIZONA_MIC_DETECT_1,
1383 ARIZONA_MICD_DBTIME_MASK, 0);
1389 BUILD_BUG_ON(ARRAY_SIZE(arizona_micd_levels) <
1390 ARIZONA_NUM_MICD_BUTTON_LEVELS);
1392 if (arizona->pdata.num_micd_ranges) {
1393 info->micd_ranges = pdata->micd_ranges;
1394 info->num_micd_ranges = pdata->num_micd_ranges;
1396 info->micd_ranges = micd_default_ranges;
1397 info->num_micd_ranges = ARRAY_SIZE(micd_default_ranges);
1400 if (arizona->pdata.num_micd_ranges > ARIZONA_MAX_MICD_RANGE) {
1401 dev_err(arizona->dev, "Too many MICD ranges: %d\n",
1402 arizona->pdata.num_micd_ranges);
1405 if (info->num_micd_ranges > 1) {
1406 for (i = 1; i < info->num_micd_ranges; i++) {
1407 if (info->micd_ranges[i - 1].max >
1408 info->micd_ranges[i].max) {
1409 dev_err(arizona->dev,
1410 "MICD ranges must be sorted\n");
1417 /* Disable all buttons by default */
1418 regmap_update_bits(arizona->regmap, ARIZONA_MIC_DETECT_2,
1419 ARIZONA_MICD_LVL_SEL_MASK, 0x81);
1421 /* Set up all the buttons the user specified */
1422 for (i = 0; i < info->num_micd_ranges; i++) {
1423 for (j = 0; j < ARIZONA_NUM_MICD_BUTTON_LEVELS; j++)
1424 if (arizona_micd_levels[j] >= info->micd_ranges[i].max)
1427 if (j == ARIZONA_NUM_MICD_BUTTON_LEVELS) {
1428 dev_err(arizona->dev, "Unsupported MICD level %d\n",
1429 info->micd_ranges[i].max);
1434 dev_dbg(arizona->dev, "%d ohms for MICD threshold %d\n",
1435 arizona_micd_levels[j], i);
1437 arizona_micd_set_level(arizona, i, j);
1438 input_set_capability(info->input, EV_KEY,
1439 info->micd_ranges[i].key);
1441 /* Enable reporting of that range */
1442 regmap_update_bits(arizona->regmap, ARIZONA_MIC_DETECT_2,
1446 /* Set all the remaining keys to a maximum */
1447 for (; i < ARIZONA_MAX_MICD_RANGE; i++)
1448 arizona_micd_set_level(arizona, i, 0x3f);
1451 * If we have a clamp use it, activating in conjunction with
1452 * GPIO5 if that is connected for jack detect operation.
1454 if (info->micd_clamp) {
1455 if (arizona->pdata.jd_gpio5) {
1456 /* Put the GPIO into input mode with optional pull */
1458 if (arizona->pdata.jd_gpio5_nopull)
1459 val &= ~ARIZONA_GPN_PU;
1461 regmap_write(arizona->regmap, ARIZONA_GPIO5_CTRL,
1464 if (arizona->pdata.jd_invert)
1465 clamp_mode = ARIZONA_MICD_CLAMP_MODE_JDH_GP5H;
1467 clamp_mode = ARIZONA_MICD_CLAMP_MODE_JDL_GP5H;
1469 if (arizona->pdata.jd_invert)
1470 clamp_mode = ARIZONA_MICD_CLAMP_MODE_JDH;
1472 clamp_mode = ARIZONA_MICD_CLAMP_MODE_JDL;
1475 regmap_update_bits(arizona->regmap,
1476 ARIZONA_MICD_CLAMP_CONTROL,
1477 ARIZONA_MICD_CLAMP_MODE_MASK, clamp_mode);
1479 regmap_update_bits(arizona->regmap,
1480 ARIZONA_JACK_DETECT_DEBOUNCE,
1481 ARIZONA_MICD_CLAMP_DB,
1482 ARIZONA_MICD_CLAMP_DB);
1485 arizona_extcon_set_mode(info, 0);
1487 pm_runtime_enable(&pdev->dev);
1488 pm_runtime_idle(&pdev->dev);
1489 pm_runtime_get_sync(&pdev->dev);
1491 if (arizona->pdata.jd_gpio5) {
1492 jack_irq_rise = ARIZONA_IRQ_MICD_CLAMP_RISE;
1493 jack_irq_fall = ARIZONA_IRQ_MICD_CLAMP_FALL;
1495 jack_irq_rise = ARIZONA_IRQ_JD_RISE;
1496 jack_irq_fall = ARIZONA_IRQ_JD_FALL;
1499 ret = arizona_request_irq(arizona, jack_irq_rise,
1500 "JACKDET rise", arizona_jackdet, info);
1502 dev_err(&pdev->dev, "Failed to get JACKDET rise IRQ: %d\n",
1507 ret = arizona_set_irq_wake(arizona, jack_irq_rise, 1);
1509 dev_err(&pdev->dev, "Failed to set JD rise IRQ wake: %d\n",
1514 ret = arizona_request_irq(arizona, jack_irq_fall,
1515 "JACKDET fall", arizona_jackdet, info);
1517 dev_err(&pdev->dev, "Failed to get JD fall IRQ: %d\n", ret);
1521 ret = arizona_set_irq_wake(arizona, jack_irq_fall, 1);
1523 dev_err(&pdev->dev, "Failed to set JD fall IRQ wake: %d\n",
1528 ret = arizona_request_irq(arizona, ARIZONA_IRQ_MICDET,
1529 "MICDET", arizona_micdet, info);
1531 dev_err(&pdev->dev, "Failed to get MICDET IRQ: %d\n", ret);
1535 ret = arizona_request_irq(arizona, ARIZONA_IRQ_HPDET,
1536 "HPDET", arizona_hpdet_irq, info);
1538 dev_err(&pdev->dev, "Failed to get HPDET IRQ: %d\n", ret);
1542 arizona_clk32k_enable(arizona);
1543 regmap_update_bits(arizona->regmap, ARIZONA_JACK_DETECT_DEBOUNCE,
1544 ARIZONA_JD1_DB, ARIZONA_JD1_DB);
1545 regmap_update_bits(arizona->regmap, ARIZONA_JACK_DETECT_ANALOGUE,
1546 ARIZONA_JD1_ENA, ARIZONA_JD1_ENA);
1548 ret = regulator_allow_bypass(info->micvdd, true);
1550 dev_warn(arizona->dev, "Failed to set MICVDD to bypass: %d\n",
1553 pm_runtime_put(&pdev->dev);
1555 ret = input_register_device(info->input);
1557 dev_err(&pdev->dev, "Can't register input device: %d\n", ret);
1564 arizona_free_irq(arizona, ARIZONA_IRQ_HPDET, info);
1566 arizona_free_irq(arizona, ARIZONA_IRQ_MICDET, info);
1568 arizona_set_irq_wake(arizona, jack_irq_fall, 0);
1570 arizona_free_irq(arizona, jack_irq_fall, info);
1572 arizona_set_irq_wake(arizona, jack_irq_rise, 0);
1574 arizona_free_irq(arizona, jack_irq_rise, info);
1576 gpiod_put(info->micd_pol_gpio);
1578 pm_runtime_disable(&pdev->dev);
1582 static int arizona_extcon_remove(struct platform_device *pdev)
1584 struct arizona_extcon_info *info = platform_get_drvdata(pdev);
1585 struct arizona *arizona = info->arizona;
1586 int jack_irq_rise, jack_irq_fall;
1588 gpiod_put(info->micd_pol_gpio);
1590 pm_runtime_disable(&pdev->dev);
1592 regmap_update_bits(arizona->regmap,
1593 ARIZONA_MICD_CLAMP_CONTROL,
1594 ARIZONA_MICD_CLAMP_MODE_MASK, 0);
1596 if (arizona->pdata.jd_gpio5) {
1597 jack_irq_rise = ARIZONA_IRQ_MICD_CLAMP_RISE;
1598 jack_irq_fall = ARIZONA_IRQ_MICD_CLAMP_FALL;
1600 jack_irq_rise = ARIZONA_IRQ_JD_RISE;
1601 jack_irq_fall = ARIZONA_IRQ_JD_FALL;
1604 arizona_set_irq_wake(arizona, jack_irq_rise, 0);
1605 arizona_set_irq_wake(arizona, jack_irq_fall, 0);
1606 arizona_free_irq(arizona, ARIZONA_IRQ_HPDET, info);
1607 arizona_free_irq(arizona, ARIZONA_IRQ_MICDET, info);
1608 arizona_free_irq(arizona, jack_irq_rise, info);
1609 arizona_free_irq(arizona, jack_irq_fall, info);
1610 cancel_delayed_work_sync(&info->hpdet_work);
1611 regmap_update_bits(arizona->regmap, ARIZONA_JACK_DETECT_ANALOGUE,
1612 ARIZONA_JD1_ENA, 0);
1613 arizona_clk32k_disable(arizona);
1618 static struct platform_driver arizona_extcon_driver = {
1620 .name = "arizona-extcon",
1622 .probe = arizona_extcon_probe,
1623 .remove = arizona_extcon_remove,
1626 module_platform_driver(arizona_extcon_driver);
1628 MODULE_DESCRIPTION("Arizona Extcon driver");
1629 MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
1630 MODULE_LICENSE("GPL");
1631 MODULE_ALIAS("platform:extcon-arizona");