forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-09-20 cf4ce59b3b70238352c7f1729f0f7223214828ad
kernel/sound/soc/codecs/es8316.c
....@@ -1,33 +1,28 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * es8316.c -- es8316 ALSA SoC audio driver
34 * Copyright Everest Semiconductor Co.,Ltd
45 *
56 * Authors: David Yang <yangxiaohua@everest-semi.com>,
67 * Daniel Drake <drake@endlessm.com>
7
- *
8
- * This program is free software; you can redistribute it and/or modify
9
- * it under the terms of the GNU General Public License version 2 as
10
- * published by the Free Software Foundation.
118 */
129
1310 #include <linux/module.h>
1411 #include <linux/acpi.h>
1512 #include <linux/clk.h>
1613 #include <linux/delay.h>
17
-#include <linux/extcon.h>
18
-#include <linux/gpio.h>
1914 #include <linux/i2c.h>
2015 #include <linux/mod_devicetable.h>
21
-#include <linux/of_gpio.h>
16
+#include <linux/mutex.h>
2217 #include <linux/regmap.h>
2318 #include <sound/pcm.h>
2419 #include <sound/pcm_params.h>
2520 #include <sound/soc.h>
2621 #include <sound/soc-dapm.h>
2722 #include <sound/tlv.h>
23
+#include <sound/jack.h>
2824 #include "es8316.h"
2925
30
-#define ES8316_EXTCON_ID EXTCON_JACK_HEADPHONE
3126 /* In slave mode at single speed, the codec is documented as accepting 5
3227 * MCLK/LRCK ratios, but we also add ratio 400, which is commonly used on
3328 * Intel Cherry Trail platforms (19.2MHz MCLK, 48kHz LRCK).
....@@ -38,16 +33,16 @@
3833 };
3934
4035 struct es8316_priv {
36
+ struct mutex lock;
37
+ struct clk *mclk;
38
+ struct regmap *regmap;
39
+ struct snd_soc_component *component;
40
+ struct snd_soc_jack *jack;
41
+ int irq;
4142 unsigned int sysclk;
4243 unsigned int allowed_rates[NR_SUPPORTED_MCLK_LRCK_RATIOS];
4344 struct snd_pcm_hw_constraint_list sysclk_constraints;
44
- struct clk *mclk;
45
-
46
- struct gpio_desc *gpiod_spk_ctl;
47
- bool muted;
48
- bool hp_inserted;
49
- struct notifier_block extcon_nb;
50
- int pwr_count;
45
+ bool jd_inverted;
5146 };
5247
5348 /*
....@@ -57,7 +52,12 @@
5752 static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(adc_vol_tlv, -9600, 50, 1);
5853 static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(alc_max_gain_tlv, -650, 150, 0);
5954 static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(alc_min_gain_tlv, -1200, 150, 0);
60
-static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(alc_target_tlv, -1650, 150, 0);
55
+
56
+static const SNDRV_CTL_TLVD_DECLARE_DB_RANGE(alc_target_tlv,
57
+ 0, 10, TLV_DB_SCALE_ITEM(-1650, 150, 0),
58
+ 11, 11, TLV_DB_SCALE_ITEM(-150, 0, 0),
59
+);
60
+
6161 static const SNDRV_CTL_TLVD_DECLARE_DB_RANGE(hpmixer_gain_tlv,
6262 0, 4, TLV_DB_SCALE_ITEM(-1200, 150, 0),
6363 8, 11, TLV_DB_SCALE_ITEM(-450, 150, 0),
....@@ -94,7 +94,7 @@
9494 SOC_DOUBLE_TLV("Headphone Playback Volume", ES8316_CPHP_ICAL_VOL,
9595 4, 0, 3, 1, hpout_vol_tlv),
9696 SOC_DOUBLE_TLV("Headphone Mixer Volume", ES8316_HPMIX_VOL,
97
- 0, 4, 11, 0, hpmixer_gain_tlv),
97
+ 4, 0, 11, 0, hpmixer_gain_tlv),
9898
9999 SOC_ENUM("Playback Polarity", dacpol),
100100 SOC_DOUBLE_R_TLV("DAC Playback Volume", ES8316_DAC_VOLL,
....@@ -104,6 +104,7 @@
104104 SOC_SINGLE("DAC Notch Filter Switch", ES8316_DAC_SET2, 6, 1, 0),
105105 SOC_SINGLE("DAC Double Fs Switch", ES8316_DAC_SET2, 7, 1, 0),
106106 SOC_SINGLE("DAC Stereo Enhancement", ES8316_DAC_SET3, 0, 7, 0),
107
+ SOC_SINGLE("DAC Mono Mix Switch", ES8316_DAC_SET3, 3, 1, 0),
107108
108109 SOC_ENUM("Capture Polarity", adcpol),
109110 SOC_SINGLE("Mic Boost Switch", ES8316_ADC_D2SEPGA, 0, 1, 0),
....@@ -119,7 +120,7 @@
119120 alc_max_gain_tlv),
120121 SOC_SINGLE_TLV("ALC Capture Min Volume", ES8316_ADC_ALC2, 0, 28, 0,
121122 alc_min_gain_tlv),
122
- SOC_SINGLE_TLV("ALC Capture Target Volume", ES8316_ADC_ALC3, 4, 10, 0,
123
+ SOC_SINGLE_TLV("ALC Capture Target Volume", ES8316_ADC_ALC3, 4, 11, 0,
123124 alc_target_tlv),
124125 SOC_SINGLE("ALC Capture Hold Time", ES8316_ADC_ALC3, 0, 10, 0),
125126 SOC_SINGLE("ALC Capture Decay Time", ES8316_ADC_ALC4, 4, 10, 0),
....@@ -152,7 +153,7 @@
152153 "dmic data at high level",
153154 "dmic data at low level",
154155 };
155
-static const unsigned int es8316_dmic_values[] = { 0, 1, 2 };
156
+static const unsigned int es8316_dmic_values[] = { 0, 2, 3 };
156157 static const struct soc_enum es8316_dmic_src_enum =
157158 SOC_VALUE_ENUM_SINGLE(ES8316_ADC_DMIC, 0, 3,
158159 ARRAY_SIZE(es8316_dmic_txt),
....@@ -168,8 +169,6 @@
168169 "lin-rin with Boost",
169170 "lin-rin with Boost and PGA"
170171 };
171
-
172
-static const unsigned int es8316_hpmux_values[] = { 0, 1, 2, 3 };
173172
174173 static SOC_ENUM_SINGLE_DECL(es8316_left_hpmux_enum, ES8316_HPMIX_SEL,
175174 4, es8316_hpmux_texts);
....@@ -200,8 +199,6 @@
200199 "RDATA TO LDAC, RDATA TO RDAC",
201200 "RDATA TO LDAC, LDATA TO RDAC",
202201 };
203
-
204
-static const unsigned int es8316_dacsrc_values[] = { 0, 1, 2, 3 };
205202
206203 static SOC_ENUM_SINGLE_DECL(es8316_dacsrc_mux_enum, ES8316_DAC_SET1,
207204 6, es8316_dacsrc_texts);
....@@ -368,13 +365,19 @@
368365 {
369366 struct snd_soc_component *component = codec_dai->component;
370367 struct es8316_priv *es8316 = snd_soc_component_get_drvdata(component);
371
- int i;
368
+ int i, ret;
372369 int count = 0;
373370
374371 es8316->sysclk = freq;
372
+ es8316->sysclk_constraints.list = NULL;
373
+ es8316->sysclk_constraints.count = 0;
375374
376375 if (freq == 0)
377376 return 0;
377
+
378
+ ret = clk_set_rate(es8316->mclk, freq);
379
+ if (ret)
380
+ return ret;
378381
379382 /* Limit supported sample rates to ones that can be autodetected
380383 * by the codec running in slave mode.
....@@ -386,8 +389,10 @@
386389 es8316->allowed_rates[count++] = freq / ratio;
387390 }
388391
389
- es8316->sysclk_constraints.list = es8316->allowed_rates;
390
- es8316->sysclk_constraints.count = count;
392
+ if (count) {
393
+ es8316->sysclk_constraints.list = es8316->allowed_rates;
394
+ es8316->sysclk_constraints.count = count;
395
+ }
391396
392397 return 0;
393398 }
....@@ -449,17 +454,10 @@
449454 struct snd_soc_component *component = dai->component;
450455 struct es8316_priv *es8316 = snd_soc_component_get_drvdata(component);
451456
452
- if (es8316->sysclk == 0) {
453
- dev_err(component->dev, "No sysclk provided\n");
454
- return -EINVAL;
455
- }
456
-
457
- /* The set of sample rates that can be supported depends on the
458
- * MCLK supplied to the CODEC.
459
- */
460
- snd_pcm_hw_constraint_list(substream->runtime, 0,
461
- SNDRV_PCM_HW_PARAM_RATE,
462
- &es8316->sysclk_constraints);
457
+ if (es8316->sysclk_constraints.list)
458
+ snd_pcm_hw_constraint_list(substream->runtime, 0,
459
+ SNDRV_PCM_HW_PARAM_RATE,
460
+ &es8316->sysclk_constraints);
463461
464462 return 0;
465463 }
....@@ -471,11 +469,19 @@
471469 struct snd_soc_component *component = dai->component;
472470 struct es8316_priv *es8316 = snd_soc_component_get_drvdata(component);
473471 u8 wordlen = 0;
472
+ int i;
474473
475
- if (!es8316->sysclk) {
476
- dev_err(component->dev, "No MCLK configured\n");
477
- return -EINVAL;
474
+ /* Validate supported sample rates that are autodetected from MCLK */
475
+ for (i = 0; i < NR_SUPPORTED_MCLK_LRCK_RATIOS; i++) {
476
+ const unsigned int ratio = supported_mclk_lrck_ratios[i];
477
+
478
+ if (es8316->sysclk % ratio != 0)
479
+ continue;
480
+ if (es8316->sysclk / ratio == params_rate(params))
481
+ break;
478482 }
483
+ if (i == NR_SUPPORTED_MCLK_LRCK_RATIOS)
484
+ return -EINVAL;
479485
480486 switch (params_format(params)) {
481487 case SNDRV_PCM_FORMAT_S16_LE:
....@@ -501,75 +507,10 @@
501507 return 0;
502508 }
503509
504
-static void es8316_enable_spk(struct es8316_priv *es8316, bool enable)
510
+static int es8316_mute(struct snd_soc_dai *dai, int mute, int direction)
505511 {
506
- if (!es8316 || !es8316->gpiod_spk_ctl)
507
- return;
508
- gpiod_set_value(es8316->gpiod_spk_ctl, enable);
509
-}
510
-
511
-static int es8316_extcon_notifier(struct notifier_block *self, unsigned long event, void *ptr)
512
-{
513
- struct es8316_priv *es8316 = container_of(self, struct es8316_priv,
514
- extcon_nb);
515
-
516
- if (event) {
517
- es8316->hp_inserted = true;
518
- es8316_enable_spk(es8316, false);
519
- } else {
520
- es8316->hp_inserted = false;
521
- }
522
- return NOTIFY_DONE;
523
-}
524
-
525
-static int es8316_mute(struct snd_soc_dai *dai, int mute)
526
-{
527
- struct snd_soc_component *component = dai->component;
528
- struct es8316_priv *es8316 = snd_soc_component_get_drvdata(component);
529
- unsigned int val = mute ? 0x20 : 0;
530
-
531
- es8316->muted = mute;
532
- if (mute) {
533
- es8316_enable_spk(es8316, false);
534
- msleep(100);
535
- snd_soc_component_update_bits(dai->component, ES8316_DAC_SET1, 0x20, val);
536
- } else {
537
- snd_soc_component_update_bits(dai->component, ES8316_DAC_SET1, 0x20, val);
538
- msleep(130);
539
- if (!es8316->hp_inserted)
540
- es8316_enable_spk(es8316, true);
541
- }
542
- return 0;
543
-}
544
-
545
-static int es8316_set_bias_level(struct snd_soc_component *component,
546
- enum snd_soc_bias_level level)
547
-{
548
- struct es8316_priv *es8316 = snd_soc_component_get_drvdata(component);
549
- int ret;
550
-
551
- switch (level) {
552
- case SND_SOC_BIAS_ON:
553
- break;
554
- case SND_SOC_BIAS_PREPARE:
555
- if (IS_ERR(es8316->mclk))
556
- break;
557
-
558
- if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_ON) {
559
- clk_disable_unprepare(es8316->mclk);
560
- } else {
561
- ret = clk_prepare_enable(es8316->mclk);
562
- if (ret)
563
- return ret;
564
- }
565
- break;
566
-
567
- case SND_SOC_BIAS_STANDBY:
568
- break;
569
-
570
- case SND_SOC_BIAS_OFF:
571
- break;
572
- }
512
+ snd_soc_component_update_bits(dai->component, ES8316_DAC_SET1, 0x20,
513
+ mute ? 0x20 : 0);
573514 return 0;
574515 }
575516
....@@ -581,7 +522,8 @@
581522 .hw_params = es8316_pcm_hw_params,
582523 .set_fmt = es8316_set_dai_fmt,
583524 .set_sysclk = es8316_set_dai_sysclk,
584
- .digital_mute = es8316_mute,
525
+ .mute_stream = es8316_mute,
526
+ .no_capture_mute = 1,
585527 };
586528
587529 static struct snd_soc_dai_driver es8316_dai = {
....@@ -604,18 +546,189 @@
604546 .symmetric_rates = 1,
605547 };
606548
549
+static void es8316_enable_micbias_for_mic_gnd_short_detect(
550
+ struct snd_soc_component *component)
551
+{
552
+ struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component);
553
+
554
+ snd_soc_dapm_mutex_lock(dapm);
555
+ snd_soc_dapm_force_enable_pin_unlocked(dapm, "Bias");
556
+ snd_soc_dapm_force_enable_pin_unlocked(dapm, "Analog power");
557
+ snd_soc_dapm_force_enable_pin_unlocked(dapm, "Mic Bias");
558
+ snd_soc_dapm_sync_unlocked(dapm);
559
+ snd_soc_dapm_mutex_unlock(dapm);
560
+
561
+ msleep(20);
562
+}
563
+
564
+static void es8316_disable_micbias_for_mic_gnd_short_detect(
565
+ struct snd_soc_component *component)
566
+{
567
+ struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component);
568
+
569
+ snd_soc_dapm_mutex_lock(dapm);
570
+ snd_soc_dapm_disable_pin_unlocked(dapm, "Mic Bias");
571
+ snd_soc_dapm_disable_pin_unlocked(dapm, "Analog power");
572
+ snd_soc_dapm_disable_pin_unlocked(dapm, "Bias");
573
+ snd_soc_dapm_sync_unlocked(dapm);
574
+ snd_soc_dapm_mutex_unlock(dapm);
575
+}
576
+
577
+static irqreturn_t es8316_irq(int irq, void *data)
578
+{
579
+ struct es8316_priv *es8316 = data;
580
+ struct snd_soc_component *comp = es8316->component;
581
+ unsigned int flags;
582
+
583
+ mutex_lock(&es8316->lock);
584
+
585
+ regmap_read(es8316->regmap, ES8316_GPIO_FLAG, &flags);
586
+ if (flags == 0x00)
587
+ goto out; /* Powered-down / reset */
588
+
589
+ /* Catch spurious IRQ before set_jack is called */
590
+ if (!es8316->jack)
591
+ goto out;
592
+
593
+ if (es8316->jd_inverted)
594
+ flags ^= ES8316_GPIO_FLAG_HP_NOT_INSERTED;
595
+
596
+ dev_dbg(comp->dev, "gpio flags %#04x\n", flags);
597
+ if (flags & ES8316_GPIO_FLAG_HP_NOT_INSERTED) {
598
+ /* Jack removed, or spurious IRQ? */
599
+ if (es8316->jack->status & SND_JACK_MICROPHONE)
600
+ es8316_disable_micbias_for_mic_gnd_short_detect(comp);
601
+
602
+ if (es8316->jack->status & SND_JACK_HEADPHONE) {
603
+ snd_soc_jack_report(es8316->jack, 0,
604
+ SND_JACK_HEADSET | SND_JACK_BTN_0);
605
+ dev_dbg(comp->dev, "jack unplugged\n");
606
+ }
607
+ } else if (!(es8316->jack->status & SND_JACK_HEADPHONE)) {
608
+ /* Jack inserted, determine type */
609
+ es8316_enable_micbias_for_mic_gnd_short_detect(comp);
610
+ regmap_read(es8316->regmap, ES8316_GPIO_FLAG, &flags);
611
+ if (es8316->jd_inverted)
612
+ flags ^= ES8316_GPIO_FLAG_HP_NOT_INSERTED;
613
+ dev_dbg(comp->dev, "gpio flags %#04x\n", flags);
614
+ if (flags & ES8316_GPIO_FLAG_HP_NOT_INSERTED) {
615
+ /* Jack unplugged underneath us */
616
+ es8316_disable_micbias_for_mic_gnd_short_detect(comp);
617
+ } else if (flags & ES8316_GPIO_FLAG_GM_NOT_SHORTED) {
618
+ /* Open, headset */
619
+ snd_soc_jack_report(es8316->jack,
620
+ SND_JACK_HEADSET,
621
+ SND_JACK_HEADSET);
622
+ /* Keep mic-gnd-short detection on for button press */
623
+ } else {
624
+ /* Shorted, headphones */
625
+ snd_soc_jack_report(es8316->jack,
626
+ SND_JACK_HEADPHONE,
627
+ SND_JACK_HEADSET);
628
+ /* No longer need mic-gnd-short detection */
629
+ es8316_disable_micbias_for_mic_gnd_short_detect(comp);
630
+ }
631
+ } else if (es8316->jack->status & SND_JACK_MICROPHONE) {
632
+ /* Interrupt while jack inserted, report button state */
633
+ if (flags & ES8316_GPIO_FLAG_GM_NOT_SHORTED) {
634
+ /* Open, button release */
635
+ snd_soc_jack_report(es8316->jack, 0, SND_JACK_BTN_0);
636
+ } else {
637
+ /* Short, button press */
638
+ snd_soc_jack_report(es8316->jack,
639
+ SND_JACK_BTN_0,
640
+ SND_JACK_BTN_0);
641
+ }
642
+ }
643
+
644
+out:
645
+ mutex_unlock(&es8316->lock);
646
+ return IRQ_HANDLED;
647
+}
648
+
649
+static void es8316_enable_jack_detect(struct snd_soc_component *component,
650
+ struct snd_soc_jack *jack)
651
+{
652
+ struct es8316_priv *es8316 = snd_soc_component_get_drvdata(component);
653
+
654
+ /*
655
+ * Init es8316->jd_inverted here and not in the probe, as we cannot
656
+ * guarantee that the bytchr-es8316 driver, which might set this
657
+ * property, will probe before us.
658
+ */
659
+ es8316->jd_inverted = device_property_read_bool(component->dev,
660
+ "everest,jack-detect-inverted");
661
+
662
+ mutex_lock(&es8316->lock);
663
+
664
+ es8316->jack = jack;
665
+
666
+ if (es8316->jack->status & SND_JACK_MICROPHONE)
667
+ es8316_enable_micbias_for_mic_gnd_short_detect(component);
668
+
669
+ snd_soc_component_update_bits(component, ES8316_GPIO_DEBOUNCE,
670
+ ES8316_GPIO_ENABLE_INTERRUPT,
671
+ ES8316_GPIO_ENABLE_INTERRUPT);
672
+
673
+ mutex_unlock(&es8316->lock);
674
+
675
+ /* Enable irq and sync initial jack state */
676
+ enable_irq(es8316->irq);
677
+ es8316_irq(es8316->irq, es8316);
678
+}
679
+
680
+static void es8316_disable_jack_detect(struct snd_soc_component *component)
681
+{
682
+ struct es8316_priv *es8316 = snd_soc_component_get_drvdata(component);
683
+
684
+ disable_irq(es8316->irq);
685
+
686
+ mutex_lock(&es8316->lock);
687
+
688
+ snd_soc_component_update_bits(component, ES8316_GPIO_DEBOUNCE,
689
+ ES8316_GPIO_ENABLE_INTERRUPT, 0);
690
+
691
+ if (es8316->jack->status & SND_JACK_MICROPHONE) {
692
+ es8316_disable_micbias_for_mic_gnd_short_detect(component);
693
+ snd_soc_jack_report(es8316->jack, 0, SND_JACK_BTN_0);
694
+ }
695
+
696
+ es8316->jack = NULL;
697
+
698
+ mutex_unlock(&es8316->lock);
699
+}
700
+
701
+static int es8316_set_jack(struct snd_soc_component *component,
702
+ struct snd_soc_jack *jack, void *data)
703
+{
704
+ if (jack)
705
+ es8316_enable_jack_detect(component, jack);
706
+ else
707
+ es8316_disable_jack_detect(component);
708
+
709
+ return 0;
710
+}
711
+
607712 static int es8316_probe(struct snd_soc_component *component)
608713 {
609714 struct es8316_priv *es8316 = snd_soc_component_get_drvdata(component);
610
- int ret = 0;
715
+ int ret;
611716
612
- es8316->mclk = devm_clk_get(component->dev, "mclk");
613
- if (PTR_ERR(es8316->mclk) == -EPROBE_DEFER)
614
- return -EPROBE_DEFER;
717
+ es8316->component = component;
718
+
719
+ es8316->mclk = devm_clk_get_optional(component->dev, "mclk");
720
+ if (IS_ERR(es8316->mclk)) {
721
+ dev_err(component->dev, "unable to get mclk\n");
722
+ return PTR_ERR(es8316->mclk);
723
+ }
724
+ if (!es8316->mclk)
725
+ dev_warn(component->dev, "assuming static mclk\n");
615726
616727 ret = clk_prepare_enable(es8316->mclk);
617
- if (ret)
728
+ if (ret) {
729
+ dev_err(component->dev, "unable to enable mclk\n");
618730 return ret;
731
+ }
619732
620733 /* Reset codec and enable current state machine */
621734 snd_soc_component_write(component, ES8316_RESET, 0x3f);
....@@ -649,7 +762,7 @@
649762 static const struct snd_soc_component_driver soc_component_dev_es8316 = {
650763 .probe = es8316_probe,
651764 .remove = es8316_remove,
652
- .set_bias_level = es8316_set_bias_level,
765
+ .set_jack = es8316_set_jack,
653766 .controls = es8316_snd_controls,
654767 .num_controls = ARRAY_SIZE(es8316_snd_controls),
655768 .dapm_widgets = es8316_dapm_widgets,
....@@ -661,60 +774,57 @@
661774 .non_legacy_dai_naming = 1,
662775 };
663776
777
+static const struct regmap_range es8316_volatile_ranges[] = {
778
+ regmap_reg_range(ES8316_GPIO_FLAG, ES8316_GPIO_FLAG),
779
+};
780
+
781
+static const struct regmap_access_table es8316_volatile_table = {
782
+ .yes_ranges = es8316_volatile_ranges,
783
+ .n_yes_ranges = ARRAY_SIZE(es8316_volatile_ranges),
784
+};
785
+
664786 static const struct regmap_config es8316_regmap = {
665787 .reg_bits = 8,
666788 .val_bits = 8,
667789 .max_register = 0x53,
790
+ .volatile_table = &es8316_volatile_table,
668791 .cache_type = REGCACHE_RBTREE,
669792 };
670793
671794 static int es8316_i2c_probe(struct i2c_client *i2c_client,
672795 const struct i2c_device_id *id)
673796 {
797
+ struct device *dev = &i2c_client->dev;
674798 struct es8316_priv *es8316;
675
- struct extcon_dev *edev;
676
- struct regmap *regmap;
677
- int ret = -1;
799
+ int ret;
678800
679801 es8316 = devm_kzalloc(&i2c_client->dev, sizeof(struct es8316_priv),
680802 GFP_KERNEL);
681803 if (es8316 == NULL)
682804 return -ENOMEM;
683
- es8316->hp_inserted = false;
684
- es8316->muted = true;
805
+
685806 i2c_set_clientdata(i2c_client, es8316);
686807
687
- regmap = devm_regmap_init_i2c(i2c_client, &es8316_regmap);
688
- if (IS_ERR(regmap))
689
- return PTR_ERR(regmap);
690
- es8316->gpiod_spk_ctl = devm_gpiod_get_optional(&i2c_client->dev,
691
- "spk-con",
692
- GPIOD_OUT_LOW);
693
- if (IS_ERR(es8316->gpiod_spk_ctl)) {
694
- ret = IS_ERR(es8316->gpiod_spk_ctl);
695
- es8316->gpiod_spk_ctl = NULL;
696
- dev_warn(&i2c_client->dev, "cannot get spk-con-gpio %d\n", ret);
697
- }
698
- if (device_property_read_bool(&i2c_client->dev, "extcon")) {
699
- edev = extcon_get_edev_by_phandle(&i2c_client->dev, 0);
700
- if (IS_ERR(edev)) {
701
- if (PTR_ERR(edev) == -EPROBE_DEFER)
702
- return -EPROBE_DEFER;
703
- dev_err(&i2c_client->dev, "Invalid or missing extcon\n");
704
- return PTR_ERR(edev);
705
- }
706
- es8316->extcon_nb.notifier_call = es8316_extcon_notifier;
707
- ret = devm_extcon_register_notifier(&i2c_client->dev, edev,
708
- ES8316_EXTCON_ID,
709
- &es8316->extcon_nb);
710
- if (ret < 0) {
711
- dev_err(&i2c_client->dev, "register notifier fail\n");
712
- return ret;
808
+ es8316->regmap = devm_regmap_init_i2c(i2c_client, &es8316_regmap);
809
+ if (IS_ERR(es8316->regmap))
810
+ return PTR_ERR(es8316->regmap);
811
+
812
+ es8316->irq = i2c_client->irq;
813
+ mutex_init(&es8316->lock);
814
+
815
+ if (es8316->irq > 0) {
816
+ ret = devm_request_threaded_irq(dev, es8316->irq, NULL, es8316_irq,
817
+ IRQF_TRIGGER_HIGH | IRQF_ONESHOT | IRQF_NO_AUTOEN,
818
+ "es8316", es8316);
819
+ if (ret) {
820
+ dev_warn(dev, "Failed to get IRQ %d: %d\n", es8316->irq, ret);
821
+ es8316->irq = -ENXIO;
713822 }
714823 }
824
+
715825 return devm_snd_soc_register_component(&i2c_client->dev,
716
- &soc_component_dev_es8316,
717
- &es8316_dai, 1);
826
+ &soc_component_dev_es8316,
827
+ &es8316_dai, 1);
718828 }
719829
720830 static const struct i2c_device_id es8316_i2c_id[] = {
....@@ -729,11 +839,13 @@
729839 };
730840 MODULE_DEVICE_TABLE(of, es8316_of_match);
731841
842
+#ifdef CONFIG_ACPI
732843 static const struct acpi_device_id es8316_acpi_match[] = {
733844 {"ESSX8316", 0},
734845 {},
735846 };
736847 MODULE_DEVICE_TABLE(acpi, es8316_acpi_match);
848
+#endif
737849
738850 static struct i2c_driver es8316_i2c_driver = {
739851 .driver = {