1 // SPDX-License-Identifier: GPL-2.0-only
2 // Copyright(c) 2021 Intel Corporation.
5 * Intel SOF Machine Driver with es8336 Codec
8 #include <linux/device.h>
10 #include <linux/gpio/consumer.h>
11 #include <linux/gpio/machine.h>
12 #include <linux/i2c.h>
13 #include <linux/input.h>
14 #include <linux/module.h>
15 #include <linux/platform_device.h>
16 #include <linux/slab.h>
17 #include <sound/jack.h>
18 #include <sound/pcm.h>
19 #include <sound/pcm_params.h>
20 #include <sound/soc.h>
21 #include <sound/soc-acpi.h>
22 #include "hda_dsp_common.h"
24 /* jd-inv + terminating entry */
25 #define MAX_NO_PROPS 2
27 #define SOF_ES8336_SSP_CODEC(quirk) ((quirk) & GENMASK(3, 0))
28 #define SOF_ES8336_SSP_CODEC_MASK (GENMASK(3, 0))
30 #define SOF_ES8336_SPEAKERS_EN_GPIO1_QUIRK BIT(4)
33 #define SOF_SSP_HDMI_CAPTURE_PRESENT BIT(14)
34 #define SOF_NO_OF_HDMI_CAPTURE_SSP_SHIFT 15
35 #define SOF_NO_OF_HDMI_CAPTURE_SSP_MASK (GENMASK(16, 15))
36 #define SOF_NO_OF_HDMI_CAPTURE_SSP(quirk) \
37 (((quirk) << SOF_NO_OF_HDMI_CAPTURE_SSP_SHIFT) & SOF_NO_OF_HDMI_CAPTURE_SSP_MASK)
39 #define SOF_HDMI_CAPTURE_1_SSP_SHIFT 7
40 #define SOF_HDMI_CAPTURE_1_SSP_MASK (GENMASK(9, 7))
41 #define SOF_HDMI_CAPTURE_1_SSP(quirk) \
42 (((quirk) << SOF_HDMI_CAPTURE_1_SSP_SHIFT) & SOF_HDMI_CAPTURE_1_SSP_MASK)
44 #define SOF_HDMI_CAPTURE_2_SSP_SHIFT 10
45 #define SOF_HDMI_CAPTURE_2_SSP_MASK (GENMASK(12, 10))
46 #define SOF_HDMI_CAPTURE_2_SSP(quirk) \
47 (((quirk) << SOF_HDMI_CAPTURE_2_SSP_SHIFT) & SOF_HDMI_CAPTURE_2_SSP_MASK)
49 #define SOF_ES8336_ENABLE_DMIC BIT(5)
50 #define SOF_ES8336_JD_INVERTED BIT(6)
51 #define SOF_ES8336_HEADPHONE_GPIO BIT(7)
52 #define SOC_ES8336_HEADSET_MIC1 BIT(8)
54 static unsigned long quirk;
56 static int quirk_override = -1;
57 module_param_named(quirk, quirk_override, int, 0444);
58 MODULE_PARM_DESC(quirk, "Board-specific quirk override");
60 struct sof_es8336_private {
61 struct device *codec_dev;
62 struct gpio_desc *gpio_speakers, *gpio_headphone;
63 struct snd_soc_jack jack;
64 struct list_head hdmi_pcm_list;
69 struct list_head head;
70 struct snd_soc_dai *codec_dai;
74 static const struct acpi_gpio_params enable_gpio0 = { 0, 0, true };
75 static const struct acpi_gpio_params enable_gpio1 = { 1, 0, true };
77 static const struct acpi_gpio_mapping acpi_speakers_enable_gpio0[] = {
78 { "speakers-enable-gpios", &enable_gpio0, 1, ACPI_GPIO_QUIRK_ONLY_GPIOIO },
82 static const struct acpi_gpio_mapping acpi_speakers_enable_gpio1[] = {
83 { "speakers-enable-gpios", &enable_gpio1, 1, ACPI_GPIO_QUIRK_ONLY_GPIOIO },
86 static const struct acpi_gpio_mapping acpi_enable_both_gpios[] = {
87 { "speakers-enable-gpios", &enable_gpio0, 1, ACPI_GPIO_QUIRK_ONLY_GPIOIO },
88 { "headphone-enable-gpios", &enable_gpio1, 1, ACPI_GPIO_QUIRK_ONLY_GPIOIO },
92 static const struct acpi_gpio_mapping acpi_enable_both_gpios_rev_order[] = {
93 { "speakers-enable-gpios", &enable_gpio1, 1, ACPI_GPIO_QUIRK_ONLY_GPIOIO },
94 { "headphone-enable-gpios", &enable_gpio0, 1, ACPI_GPIO_QUIRK_ONLY_GPIOIO },
98 static void log_quirks(struct device *dev)
100 dev_info(dev, "quirk mask %#lx\n", quirk);
101 dev_info(dev, "quirk SSP%ld\n", SOF_ES8336_SSP_CODEC(quirk));
102 if (quirk & SOF_ES8336_ENABLE_DMIC)
103 dev_info(dev, "quirk DMIC enabled\n");
104 if (quirk & SOF_ES8336_SPEAKERS_EN_GPIO1_QUIRK)
105 dev_info(dev, "Speakers GPIO1 quirk enabled\n");
106 if (quirk & SOF_ES8336_HEADPHONE_GPIO)
107 dev_info(dev, "quirk headphone GPIO enabled\n");
108 if (quirk & SOF_ES8336_JD_INVERTED)
109 dev_info(dev, "quirk JD inverted enabled\n");
110 if (quirk & SOC_ES8336_HEADSET_MIC1)
111 dev_info(dev, "quirk headset at mic1 port enabled\n");
114 static int sof_es8316_speaker_power_event(struct snd_soc_dapm_widget *w,
115 struct snd_kcontrol *kcontrol, int event)
117 struct snd_soc_card *card = w->dapm->card;
118 struct sof_es8336_private *priv = snd_soc_card_get_drvdata(card);
120 if (priv->speaker_en == !SND_SOC_DAPM_EVENT_ON(event))
123 priv->speaker_en = !SND_SOC_DAPM_EVENT_ON(event);
125 if (SND_SOC_DAPM_EVENT_ON(event))
128 gpiod_set_value_cansleep(priv->gpio_speakers, priv->speaker_en);
130 if (!(quirk & SOF_ES8336_HEADPHONE_GPIO))
133 if (SND_SOC_DAPM_EVENT_ON(event))
136 gpiod_set_value_cansleep(priv->gpio_headphone, priv->speaker_en);
141 static const struct snd_soc_dapm_widget sof_es8316_widgets[] = {
142 SND_SOC_DAPM_SPK("Speaker", NULL),
143 SND_SOC_DAPM_HP("Headphone", NULL),
144 SND_SOC_DAPM_MIC("Headset Mic", NULL),
145 SND_SOC_DAPM_MIC("Internal Mic", NULL),
147 SND_SOC_DAPM_SUPPLY("Speaker Power", SND_SOC_NOPM, 0, 0,
148 sof_es8316_speaker_power_event,
149 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU),
152 static const struct snd_soc_dapm_widget dmic_widgets[] = {
153 SND_SOC_DAPM_MIC("SoC DMIC", NULL),
156 static const struct snd_soc_dapm_route sof_es8316_audio_map[] = {
157 {"Headphone", NULL, "HPOL"},
158 {"Headphone", NULL, "HPOR"},
161 * There is no separate speaker output instead the speakers are muxed to
162 * the HP outputs. The mux is controlled Speaker and/or headphone switch.
164 {"Speaker", NULL, "HPOL"},
165 {"Speaker", NULL, "HPOR"},
166 {"Speaker", NULL, "Speaker Power"},
169 static const struct snd_soc_dapm_route sof_es8316_headset_mic2_map[] = {
170 {"MIC1", NULL, "Internal Mic"},
171 {"MIC2", NULL, "Headset Mic"},
174 static const struct snd_soc_dapm_route sof_es8316_headset_mic1_map[] = {
175 {"MIC2", NULL, "Internal Mic"},
176 {"MIC1", NULL, "Headset Mic"},
179 static const struct snd_soc_dapm_route dmic_map[] = {
181 {"DMic", NULL, "SoC DMIC"},
184 static const struct snd_kcontrol_new sof_es8316_controls[] = {
185 SOC_DAPM_PIN_SWITCH("Speaker"),
186 SOC_DAPM_PIN_SWITCH("Headphone"),
187 SOC_DAPM_PIN_SWITCH("Headset Mic"),
188 SOC_DAPM_PIN_SWITCH("Internal Mic"),
191 static struct snd_soc_jack_pin sof_es8316_jack_pins[] = {
194 .mask = SND_JACK_HEADPHONE,
197 .pin = "Headset Mic",
198 .mask = SND_JACK_MICROPHONE,
202 static int dmic_init(struct snd_soc_pcm_runtime *runtime)
204 struct snd_soc_card *card = runtime->card;
207 ret = snd_soc_dapm_new_controls(&card->dapm, dmic_widgets,
208 ARRAY_SIZE(dmic_widgets));
210 dev_err(card->dev, "DMic widget addition failed: %d\n", ret);
214 ret = snd_soc_dapm_add_routes(&card->dapm, dmic_map,
215 ARRAY_SIZE(dmic_map));
217 dev_err(card->dev, "DMic map addition failed: %d\n", ret);
222 static int sof_hdmi_init(struct snd_soc_pcm_runtime *runtime)
224 struct sof_es8336_private *priv = snd_soc_card_get_drvdata(runtime->card);
225 struct snd_soc_dai *dai = asoc_rtd_to_codec(runtime, 0);
226 struct sof_hdmi_pcm *pcm;
228 pcm = devm_kzalloc(runtime->card->dev, sizeof(*pcm), GFP_KERNEL);
232 /* dai_link id is 1:1 mapped to the PCM device */
233 pcm->device = runtime->dai_link->id;
234 pcm->codec_dai = dai;
236 list_add_tail(&pcm->head, &priv->hdmi_pcm_list);
241 static int sof_es8316_init(struct snd_soc_pcm_runtime *runtime)
243 struct snd_soc_component *codec = asoc_rtd_to_codec(runtime, 0)->component;
244 struct snd_soc_card *card = runtime->card;
245 struct sof_es8336_private *priv = snd_soc_card_get_drvdata(card);
246 const struct snd_soc_dapm_route *custom_map;
250 card->dapm.idle_bias_off = true;
252 if (quirk & SOC_ES8336_HEADSET_MIC1) {
253 custom_map = sof_es8316_headset_mic1_map;
254 num_routes = ARRAY_SIZE(sof_es8316_headset_mic1_map);
256 custom_map = sof_es8316_headset_mic2_map;
257 num_routes = ARRAY_SIZE(sof_es8316_headset_mic2_map);
260 ret = snd_soc_dapm_add_routes(&card->dapm, custom_map, num_routes);
264 ret = snd_soc_card_jack_new_pins(card, "Headset",
265 SND_JACK_HEADSET | SND_JACK_BTN_0,
266 &priv->jack, sof_es8316_jack_pins,
267 ARRAY_SIZE(sof_es8316_jack_pins));
269 dev_err(card->dev, "jack creation failed %d\n", ret);
273 snd_jack_set_key(priv->jack.jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
275 snd_soc_component_set_jack(codec, &priv->jack, NULL);
280 static void sof_es8316_exit(struct snd_soc_pcm_runtime *rtd)
282 struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
284 snd_soc_component_set_jack(component, NULL, NULL);
287 static int sof_es8336_quirk_cb(const struct dmi_system_id *id)
289 quirk = (unsigned long)id->driver_data;
295 * this table should only be used to add GPIO or jack-detection quirks
296 * that cannot be detected from ACPI tables. The SSP and DMIC
297 * information are providing by the platform driver and are aligned
298 * with the topology used.
300 * If the GPIO support is missing, the quirk parameter can be used to
301 * enable speakers. In that case it's recommended to keep the SSP and DMIC
302 * information consistent, overriding the SSP and DMIC can only be done
303 * if the topology file is modified as well.
305 static const struct dmi_system_id sof_es8336_quirk_table[] = {
307 .callback = sof_es8336_quirk_cb,
309 DMI_MATCH(DMI_SYS_VENDOR, "IP3 tech"),
310 DMI_MATCH(DMI_BOARD_NAME, "WN1"),
312 .driver_data = (void *)(SOF_ES8336_SPEAKERS_EN_GPIO1_QUIRK)
315 .callback = sof_es8336_quirk_cb,
317 DMI_MATCH(DMI_SYS_VENDOR, "HUAWEI"),
318 DMI_MATCH(DMI_BOARD_NAME, "BOHB-WAX9-PCB-B2"),
320 .driver_data = (void *)(SOF_ES8336_HEADPHONE_GPIO |
321 SOC_ES8336_HEADSET_MIC1)
326 static int sof_es8336_hw_params(struct snd_pcm_substream *substream,
327 struct snd_pcm_hw_params *params)
329 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
330 struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
331 const int sysclk = 19200000;
334 ret = snd_soc_dai_set_sysclk(codec_dai, 1, sysclk, SND_SOC_CLOCK_OUT);
336 dev_err(rtd->dev, "%s, Failed to set ES8336 SYSCLK: %d\n",
344 /* machine stream operations */
345 static struct snd_soc_ops sof_es8336_ops = {
346 .hw_params = sof_es8336_hw_params,
349 static struct snd_soc_dai_link_component platform_component[] = {
351 /* name might be overridden during probe */
352 .name = "0000:00:1f.3"
356 SND_SOC_DAILINK_DEF(es8336_codec,
357 DAILINK_COMP_ARRAY(COMP_CODEC("i2c-ESSX8336:00", "ES8316 HiFi")));
359 static struct snd_soc_dai_link_component dmic_component[] = {
361 .name = "dmic-codec",
362 .dai_name = "dmic-hifi",
366 static struct snd_soc_dai_link_component dummy_component[] = {
368 .name = "snd-soc-dummy",
369 .dai_name = "snd-soc-dummy-dai",
373 static int sof_es8336_late_probe(struct snd_soc_card *card)
375 struct sof_es8336_private *priv = snd_soc_card_get_drvdata(card);
376 struct sof_hdmi_pcm *pcm;
378 if (list_empty(&priv->hdmi_pcm_list))
381 pcm = list_first_entry(&priv->hdmi_pcm_list, struct sof_hdmi_pcm, head);
383 return hda_dsp_hdmi_build_controls(card, pcm->codec_dai->component);
387 static struct snd_soc_card sof_es8336_card = {
388 .name = "essx8336", /* sof- prefix added automatically */
389 .owner = THIS_MODULE,
390 .dapm_widgets = sof_es8316_widgets,
391 .num_dapm_widgets = ARRAY_SIZE(sof_es8316_widgets),
392 .dapm_routes = sof_es8316_audio_map,
393 .num_dapm_routes = ARRAY_SIZE(sof_es8316_audio_map),
394 .controls = sof_es8316_controls,
395 .num_controls = ARRAY_SIZE(sof_es8316_controls),
396 .fully_routed = true,
397 .late_probe = sof_es8336_late_probe,
401 static struct snd_soc_dai_link *sof_card_dai_links_create(struct device *dev,
406 struct snd_soc_dai_link_component *cpus;
407 struct snd_soc_dai_link *links;
408 struct snd_soc_dai_link_component *idisp_components;
409 int hdmi_id_offset = 0;
413 links = devm_kcalloc(dev, sof_es8336_card.num_links,
414 sizeof(struct snd_soc_dai_link), GFP_KERNEL);
415 cpus = devm_kcalloc(dev, sof_es8336_card.num_links,
416 sizeof(struct snd_soc_dai_link_component), GFP_KERNEL);
421 links[id].name = devm_kasprintf(dev, GFP_KERNEL,
422 "SSP%d-Codec", ssp_codec);
427 links[id].codecs = es8336_codec;
428 links[id].num_codecs = ARRAY_SIZE(es8336_codec);
429 links[id].platforms = platform_component;
430 links[id].num_platforms = ARRAY_SIZE(platform_component);
431 links[id].init = sof_es8316_init;
432 links[id].exit = sof_es8316_exit;
433 links[id].ops = &sof_es8336_ops;
434 links[id].nonatomic = true;
435 links[id].dpcm_playback = 1;
436 links[id].dpcm_capture = 1;
437 links[id].no_pcm = 1;
438 links[id].cpus = &cpus[id];
439 links[id].num_cpus = 1;
441 links[id].cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL,
444 if (!links[id].cpus->dai_name)
450 if (dmic_be_num > 0) {
451 /* at least we have dmic01 */
452 links[id].name = "dmic01";
453 links[id].cpus = &cpus[id];
454 links[id].cpus->dai_name = "DMIC01 Pin";
455 links[id].init = dmic_init;
456 if (dmic_be_num > 1) {
457 /* set up 2 BE links at most */
458 links[id + 1].name = "dmic16k";
459 links[id + 1].cpus = &cpus[id + 1];
460 links[id + 1].cpus->dai_name = "DMIC16k Pin";
464 /* HDMI dai link starts at 3 according to current topology settings */
468 for (i = 0; i < dmic_be_num; i++) {
470 links[id].num_cpus = 1;
471 links[id].codecs = dmic_component;
472 links[id].num_codecs = ARRAY_SIZE(dmic_component);
473 links[id].platforms = platform_component;
474 links[id].num_platforms = ARRAY_SIZE(platform_component);
475 links[id].ignore_suspend = 1;
476 links[id].dpcm_capture = 1;
477 links[id].no_pcm = 1;
484 idisp_components = devm_kzalloc(dev,
485 sizeof(struct snd_soc_dai_link_component) *
486 hdmi_num, GFP_KERNEL);
487 if (!idisp_components)
491 for (i = 1; i <= hdmi_num; i++) {
492 links[id].name = devm_kasprintf(dev, GFP_KERNEL,
497 links[id].id = id + hdmi_id_offset;
498 links[id].cpus = &cpus[id];
499 links[id].num_cpus = 1;
500 links[id].cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL,
502 if (!links[id].cpus->dai_name)
505 idisp_components[i - 1].name = "ehdaudio0D2";
506 idisp_components[i - 1].dai_name = devm_kasprintf(dev,
510 if (!idisp_components[i - 1].dai_name)
513 links[id].codecs = &idisp_components[i - 1];
514 links[id].num_codecs = 1;
515 links[id].platforms = platform_component;
516 links[id].num_platforms = ARRAY_SIZE(platform_component);
517 links[id].init = sof_hdmi_init;
518 links[id].dpcm_playback = 1;
519 links[id].no_pcm = 1;
525 if (quirk & SOF_SSP_HDMI_CAPTURE_PRESENT) {
526 int num_of_hdmi_ssp = (quirk & SOF_NO_OF_HDMI_CAPTURE_SSP_MASK) >>
527 SOF_NO_OF_HDMI_CAPTURE_SSP_SHIFT;
529 for (i = 1; i <= num_of_hdmi_ssp; i++) {
530 int port = (i == 1 ? (quirk & SOF_HDMI_CAPTURE_1_SSP_MASK) >>
531 SOF_HDMI_CAPTURE_1_SSP_SHIFT :
532 (quirk & SOF_HDMI_CAPTURE_2_SSP_MASK) >>
533 SOF_HDMI_CAPTURE_2_SSP_SHIFT);
535 links[id].cpus = &cpus[id];
536 links[id].cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL,
538 if (!links[id].cpus->dai_name)
540 links[id].name = devm_kasprintf(dev, GFP_KERNEL, "SSP%d-HDMI", port);
543 links[id].id = id + hdmi_id_offset;
544 links[id].codecs = dummy_component;
545 links[id].num_codecs = ARRAY_SIZE(dummy_component);
546 links[id].platforms = platform_component;
547 links[id].num_platforms = ARRAY_SIZE(platform_component);
548 links[id].dpcm_capture = 1;
549 links[id].no_pcm = 1;
550 links[id].num_cpus = 1;
561 static char soc_components[30];
563 /* i2c-<HID>:00 with HID being 8 chars */
564 static char codec_name[SND_ACPI_I2C_ID_LEN];
566 static int sof_es8336_probe(struct platform_device *pdev)
568 struct device *dev = &pdev->dev;
569 struct snd_soc_card *card;
570 struct snd_soc_acpi_mach *mach = pdev->dev.platform_data;
571 struct property_entry props[MAX_NO_PROPS] = {};
572 struct sof_es8336_private *priv;
573 struct fwnode_handle *fwnode;
574 struct acpi_device *adev;
575 struct snd_soc_dai_link *dai_links;
576 struct device *codec_dev;
577 const struct acpi_gpio_mapping *gpio_mapping;
578 unsigned int cnt = 0;
583 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
587 card = &sof_es8336_card;
590 if (pdev->id_entry && pdev->id_entry->driver_data)
591 quirk = (unsigned long)pdev->id_entry->driver_data;
593 /* check GPIO DMI quirks */
594 dmi_check_system(sof_es8336_quirk_table);
596 /* Use NHLT configuration only for Non-HDMI capture use case.
597 * Because more than one SSP will be enabled for HDMI capture hence wrong codec
600 if (mach->tplg_quirk_mask & SND_SOC_ACPI_TPLG_INTEL_SSP_NUMBER) {
601 if (!mach->mach_params.i2s_link_mask) {
602 dev_warn(dev, "No I2S link information provided, using SSP0. This may need to be modified with the quirk module parameter\n");
605 * Set configuration based on platform NHLT.
606 * In this machine driver, we can only support one SSP for the
608 * In some cases multiple SSPs can be reported by NHLT, starting MSB-first
609 * seems to pick the right connection.
613 /* fls returns 1-based results, SSPs indices are 0-based */
614 ssp = fls(mach->mach_params.i2s_link_mask) - 1;
620 if (mach->mach_params.dmic_num)
621 quirk |= SOF_ES8336_ENABLE_DMIC;
623 if (quirk_override != -1) {
624 dev_info(dev, "Overriding quirk 0x%lx => 0x%x\n",
625 quirk, quirk_override);
626 quirk = quirk_override;
630 if (quirk & SOF_ES8336_ENABLE_DMIC)
633 /* compute number of dai links */
634 sof_es8336_card.num_links = 1 + dmic_be_num + hdmi_num;
636 if (quirk & SOF_SSP_HDMI_CAPTURE_PRESENT)
637 sof_es8336_card.num_links += (quirk & SOF_NO_OF_HDMI_CAPTURE_SSP_MASK) >>
638 SOF_NO_OF_HDMI_CAPTURE_SSP_SHIFT;
640 dai_links = sof_card_dai_links_create(dev,
641 SOF_ES8336_SSP_CODEC(quirk),
642 dmic_be_num, hdmi_num);
646 sof_es8336_card.dai_link = dai_links;
648 /* fixup codec name based on HID */
649 adev = acpi_dev_get_first_match_dev(mach->id, NULL, -1);
651 snprintf(codec_name, sizeof(codec_name),
652 "i2c-%s", acpi_dev_name(adev));
653 put_device(&adev->dev);
654 dai_links[0].codecs->name = codec_name;
656 /* also fixup codec dai name if relevant */
657 if (!strncmp(mach->id, "ESSX8326", SND_ACPI_I2C_ID_LEN))
658 dai_links[0].codecs->dai_name = "ES8326 HiFi";
660 dev_err(dev, "Error cannot find '%s' dev\n", mach->id);
664 ret = snd_soc_fixup_dai_links_platform_name(&sof_es8336_card,
665 mach->mach_params.platform);
669 codec_dev = acpi_get_first_physical_node(adev);
671 return -EPROBE_DEFER;
672 priv->codec_dev = get_device(codec_dev);
674 if (quirk & SOF_ES8336_JD_INVERTED)
675 props[cnt++] = PROPERTY_ENTRY_BOOL("everest,jack-detect-inverted");
678 fwnode = fwnode_create_software_node(props, NULL);
679 if (IS_ERR(fwnode)) {
680 put_device(codec_dev);
681 return PTR_ERR(fwnode);
684 ret = device_add_software_node(codec_dev, to_software_node(fwnode));
686 fwnode_handle_put(fwnode);
689 put_device(codec_dev);
694 /* get speaker enable GPIO */
695 if (quirk & SOF_ES8336_HEADPHONE_GPIO) {
696 if (quirk & SOF_ES8336_SPEAKERS_EN_GPIO1_QUIRK)
697 gpio_mapping = acpi_enable_both_gpios;
699 gpio_mapping = acpi_enable_both_gpios_rev_order;
700 } else if (quirk & SOF_ES8336_SPEAKERS_EN_GPIO1_QUIRK) {
701 gpio_mapping = acpi_speakers_enable_gpio1;
703 gpio_mapping = acpi_speakers_enable_gpio0;
706 ret = devm_acpi_dev_add_driver_gpios(codec_dev, gpio_mapping);
708 dev_warn(codec_dev, "unable to add GPIO mapping table\n");
710 priv->gpio_speakers = gpiod_get_optional(codec_dev, "speakers-enable", GPIOD_OUT_LOW);
711 if (IS_ERR(priv->gpio_speakers)) {
712 ret = dev_err_probe(dev, PTR_ERR(priv->gpio_speakers),
713 "could not get speakers-enable GPIO\n");
717 priv->gpio_headphone = gpiod_get_optional(codec_dev, "headphone-enable", GPIOD_OUT_LOW);
718 if (IS_ERR(priv->gpio_headphone)) {
719 ret = dev_err_probe(dev, PTR_ERR(priv->gpio_headphone),
720 "could not get headphone-enable GPIO\n");
724 INIT_LIST_HEAD(&priv->hdmi_pcm_list);
726 snd_soc_card_set_drvdata(card, priv);
728 if (mach->mach_params.dmic_num > 0) {
729 snprintf(soc_components, sizeof(soc_components),
730 "cfg-dmics:%d", mach->mach_params.dmic_num);
731 card->components = soc_components;
734 ret = devm_snd_soc_register_card(dev, card);
736 gpiod_put(priv->gpio_speakers);
737 dev_err(dev, "snd_soc_register_card failed: %d\n", ret);
740 platform_set_drvdata(pdev, &sof_es8336_card);
744 device_remove_software_node(priv->codec_dev);
745 put_device(codec_dev);
749 static int sof_es8336_remove(struct platform_device *pdev)
751 struct snd_soc_card *card = platform_get_drvdata(pdev);
752 struct sof_es8336_private *priv = snd_soc_card_get_drvdata(card);
754 gpiod_put(priv->gpio_speakers);
755 device_remove_software_node(priv->codec_dev);
756 put_device(priv->codec_dev);
761 static const struct platform_device_id board_ids[] = {
763 .name = "sof-essx8336", /* default quirk == 0 */
766 .name = "adl_es83x6_c1_h02",
767 .driver_data = (kernel_ulong_t)(SOF_ES8336_SSP_CODEC(1) |
768 SOF_NO_OF_HDMI_CAPTURE_SSP(2) |
769 SOF_HDMI_CAPTURE_1_SSP(0) |
770 SOF_HDMI_CAPTURE_2_SSP(2) |
771 SOF_SSP_HDMI_CAPTURE_PRESENT |
772 SOF_ES8336_SPEAKERS_EN_GPIO1_QUIRK |
773 SOF_ES8336_JD_INVERTED),
777 MODULE_DEVICE_TABLE(platform, board_ids);
779 static struct platform_driver sof_es8336_driver = {
781 .name = "sof-essx8336",
782 .pm = &snd_soc_pm_ops,
784 .probe = sof_es8336_probe,
785 .remove = sof_es8336_remove,
786 .id_table = board_ids,
788 module_platform_driver(sof_es8336_driver);
790 MODULE_DESCRIPTION("ASoC Intel(R) SOF + ES8336 Machine driver");
791 MODULE_LICENSE("GPL");
792 MODULE_IMPORT_NS(SND_SOC_INTEL_HDA_DSP_COMMON);