1 // SPDX-License-Identifier: GPL-2.0-only
2 // Copyright(c) 2021 Intel Corporation.
3 
4 /*
5  * Intel SOF Machine Driver with es8336 Codec
6  */
7 
8 #include <linux/device.h>
9 #include <linux/dmi.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"
23 
24 /* jd-inv + terminating entry */
25 #define MAX_NO_PROPS 2
26 
27 #define SOF_ES8336_SSP_CODEC(quirk)		((quirk) & GENMASK(3, 0))
28 #define SOF_ES8336_SSP_CODEC_MASK		(GENMASK(3, 0))
29 
30 #define SOF_ES8336_TGL_GPIO_QUIRK		BIT(4)
31 #define SOF_ES8336_ENABLE_DMIC			BIT(5)
32 #define SOF_ES8336_JD_INVERTED			BIT(6)
33 
34 static unsigned long quirk;
35 
36 static int quirk_override = -1;
37 module_param_named(quirk, quirk_override, int, 0444);
38 MODULE_PARM_DESC(quirk, "Board-specific quirk override");
39 
40 struct sof_es8336_private {
41 	struct device *codec_dev;
42 	struct gpio_desc *gpio_pa;
43 	struct snd_soc_jack jack;
44 	struct list_head hdmi_pcm_list;
45 	bool speaker_en;
46 };
47 
48 struct sof_hdmi_pcm {
49 	struct list_head head;
50 	struct snd_soc_dai *codec_dai;
51 	int device;
52 };
53 
54 static const struct acpi_gpio_params pa_enable_gpio = { 0, 0, true };
55 static const struct acpi_gpio_mapping acpi_es8336_gpios[] = {
56 	{ "pa-enable-gpios", &pa_enable_gpio, 1 },
57 	{ }
58 };
59 
60 static const struct acpi_gpio_params quirk_pa_enable_gpio = { 1, 0, true };
61 static const struct acpi_gpio_mapping quirk_acpi_es8336_gpios[] = {
62 	{ "pa-enable-gpios", &quirk_pa_enable_gpio, 1 },
63 	{ }
64 };
65 
66 static const struct acpi_gpio_mapping *gpio_mapping = acpi_es8336_gpios;
67 
68 static void log_quirks(struct device *dev)
69 {
70 	dev_info(dev, "quirk mask %#lx\n", quirk);
71 	dev_info(dev, "quirk SSP%ld\n",  SOF_ES8336_SSP_CODEC(quirk));
72 	if (quirk & SOF_ES8336_ENABLE_DMIC)
73 		dev_info(dev, "quirk DMIC enabled\n");
74 	if (quirk & SOF_ES8336_TGL_GPIO_QUIRK)
75 		dev_info(dev, "quirk TGL GPIO enabled\n");
76 	if (quirk & SOF_ES8336_JD_INVERTED)
77 		dev_info(dev, "quirk JD inverted enabled\n");
78 }
79 
80 static int sof_es8316_speaker_power_event(struct snd_soc_dapm_widget *w,
81 					  struct snd_kcontrol *kcontrol, int event)
82 {
83 	struct snd_soc_card *card = w->dapm->card;
84 	struct sof_es8336_private *priv = snd_soc_card_get_drvdata(card);
85 
86 	if (SND_SOC_DAPM_EVENT_ON(event))
87 		priv->speaker_en = false;
88 	else
89 		priv->speaker_en = true;
90 
91 	gpiod_set_value_cansleep(priv->gpio_pa, priv->speaker_en);
92 
93 	return 0;
94 }
95 
96 static const struct snd_soc_dapm_widget sof_es8316_widgets[] = {
97 	SND_SOC_DAPM_SPK("Speaker", NULL),
98 	SND_SOC_DAPM_HP("Headphone", NULL),
99 	SND_SOC_DAPM_MIC("Headset Mic", NULL),
100 	SND_SOC_DAPM_MIC("Internal Mic", NULL),
101 
102 	SND_SOC_DAPM_SUPPLY("Speaker Power", SND_SOC_NOPM, 0, 0,
103 			    sof_es8316_speaker_power_event,
104 			    SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU),
105 };
106 
107 static const struct snd_soc_dapm_widget dmic_widgets[] = {
108 	SND_SOC_DAPM_MIC("SoC DMIC", NULL),
109 };
110 
111 static const struct snd_soc_dapm_route sof_es8316_audio_map[] = {
112 	{"Headphone", NULL, "HPOL"},
113 	{"Headphone", NULL, "HPOR"},
114 
115 	/*
116 	 * There is no separate speaker output instead the speakers are muxed to
117 	 * the HP outputs. The mux is controlled by the "Speaker Power" supply.
118 	 */
119 	{"Speaker", NULL, "HPOL"},
120 	{"Speaker", NULL, "HPOR"},
121 	{"Speaker", NULL, "Speaker Power"},
122 };
123 
124 static const struct snd_soc_dapm_route sof_es8316_intmic_in1_map[] = {
125 	{"MIC1", NULL, "Internal Mic"},
126 	{"MIC2", NULL, "Headset Mic"},
127 };
128 
129 static const struct snd_soc_dapm_route dmic_map[] = {
130 	/* digital mics */
131 	{"DMic", NULL, "SoC DMIC"},
132 };
133 
134 static const struct snd_kcontrol_new sof_es8316_controls[] = {
135 	SOC_DAPM_PIN_SWITCH("Speaker"),
136 	SOC_DAPM_PIN_SWITCH("Headphone"),
137 	SOC_DAPM_PIN_SWITCH("Headset Mic"),
138 	SOC_DAPM_PIN_SWITCH("Internal Mic"),
139 };
140 
141 static struct snd_soc_jack_pin sof_es8316_jack_pins[] = {
142 	{
143 		.pin	= "Headphone",
144 		.mask	= SND_JACK_HEADPHONE,
145 	},
146 	{
147 		.pin	= "Headset Mic",
148 		.mask	= SND_JACK_MICROPHONE,
149 	},
150 };
151 
152 static int dmic_init(struct snd_soc_pcm_runtime *runtime)
153 {
154 	struct snd_soc_card *card = runtime->card;
155 	int ret;
156 
157 	ret = snd_soc_dapm_new_controls(&card->dapm, dmic_widgets,
158 					ARRAY_SIZE(dmic_widgets));
159 	if (ret) {
160 		dev_err(card->dev, "DMic widget addition failed: %d\n", ret);
161 		return ret;
162 	}
163 
164 	ret = snd_soc_dapm_add_routes(&card->dapm, dmic_map,
165 				      ARRAY_SIZE(dmic_map));
166 	if (ret)
167 		dev_err(card->dev, "DMic map addition failed: %d\n", ret);
168 
169 	return ret;
170 }
171 
172 static int sof_hdmi_init(struct snd_soc_pcm_runtime *runtime)
173 {
174 	struct sof_es8336_private *priv = snd_soc_card_get_drvdata(runtime->card);
175 	struct snd_soc_dai *dai = asoc_rtd_to_codec(runtime, 0);
176 	struct sof_hdmi_pcm *pcm;
177 
178 	pcm = devm_kzalloc(runtime->card->dev, sizeof(*pcm), GFP_KERNEL);
179 	if (!pcm)
180 		return -ENOMEM;
181 
182 	/* dai_link id is 1:1 mapped to the PCM device */
183 	pcm->device = runtime->dai_link->id;
184 	pcm->codec_dai = dai;
185 
186 	list_add_tail(&pcm->head, &priv->hdmi_pcm_list);
187 
188 	return 0;
189 }
190 
191 static int sof_es8316_init(struct snd_soc_pcm_runtime *runtime)
192 {
193 	struct snd_soc_component *codec = asoc_rtd_to_codec(runtime, 0)->component;
194 	struct snd_soc_card *card = runtime->card;
195 	struct sof_es8336_private *priv = snd_soc_card_get_drvdata(card);
196 	const struct snd_soc_dapm_route *custom_map;
197 	int num_routes;
198 	int ret;
199 
200 	card->dapm.idle_bias_off = true;
201 
202 	custom_map = sof_es8316_intmic_in1_map;
203 	num_routes = ARRAY_SIZE(sof_es8316_intmic_in1_map);
204 
205 	ret = snd_soc_dapm_add_routes(&card->dapm, custom_map, num_routes);
206 	if (ret)
207 		return ret;
208 
209 	ret = snd_soc_card_jack_new(card, "Headset",
210 				    SND_JACK_HEADSET | SND_JACK_BTN_0,
211 				    &priv->jack, sof_es8316_jack_pins,
212 				    ARRAY_SIZE(sof_es8316_jack_pins));
213 	if (ret) {
214 		dev_err(card->dev, "jack creation failed %d\n", ret);
215 		return ret;
216 	}
217 
218 	snd_jack_set_key(priv->jack.jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
219 
220 	snd_soc_component_set_jack(codec, &priv->jack, NULL);
221 
222 	return 0;
223 }
224 
225 static void sof_es8316_exit(struct snd_soc_pcm_runtime *rtd)
226 {
227 	struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
228 
229 	snd_soc_component_set_jack(component, NULL, NULL);
230 }
231 
232 static int sof_es8336_quirk_cb(const struct dmi_system_id *id)
233 {
234 	quirk = (unsigned long)id->driver_data;
235 
236 	if (quirk & SOF_ES8336_TGL_GPIO_QUIRK)
237 		gpio_mapping = quirk_acpi_es8336_gpios;
238 
239 	return 1;
240 }
241 
242 /*
243  * this table should only be used to add GPIO or jack-detection quirks
244  * that cannot be detected from ACPI tables. The SSP and DMIC
245  * information are providing by the platform driver and are aligned
246  * with the topology used.
247  *
248  * If the GPIO support is missing, the quirk parameter can be used to
249  * enable speakers. In that case it's recommended to keep the SSP and DMIC
250  * information consistent, overriding the SSP and DMIC can only be done
251  * if the topology file is modified as well.
252  */
253 static const struct dmi_system_id sof_es8336_quirk_table[] = {
254 	{
255 		.callback = sof_es8336_quirk_cb,
256 		.matches = {
257 			DMI_MATCH(DMI_SYS_VENDOR, "IP3 tech"),
258 			DMI_MATCH(DMI_BOARD_NAME, "WN1"),
259 		},
260 		.driver_data = (void *)(SOF_ES8336_TGL_GPIO_QUIRK)
261 	},
262 	{}
263 };
264 
265 static int sof_es8336_hw_params(struct snd_pcm_substream *substream,
266 				struct snd_pcm_hw_params *params)
267 {
268 	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
269 	struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
270 	const int sysclk = 19200000;
271 	int ret;
272 
273 	ret = snd_soc_dai_set_sysclk(codec_dai, 1, sysclk, SND_SOC_CLOCK_OUT);
274 	if (ret < 0) {
275 		dev_err(rtd->dev, "%s, Failed to set ES8336 SYSCLK: %d\n",
276 			__func__, ret);
277 		return ret;
278 	}
279 
280 	return 0;
281 }
282 
283 /* machine stream operations */
284 static struct snd_soc_ops sof_es8336_ops = {
285 	.hw_params = sof_es8336_hw_params,
286 };
287 
288 static struct snd_soc_dai_link_component platform_component[] = {
289 	{
290 		/* name might be overridden during probe */
291 		.name = "0000:00:1f.3"
292 	}
293 };
294 
295 SND_SOC_DAILINK_DEF(es8336_codec,
296 	DAILINK_COMP_ARRAY(COMP_CODEC("i2c-ESSX8336:00", "ES8316 HiFi")));
297 
298 static struct snd_soc_dai_link_component dmic_component[] = {
299 	{
300 		.name = "dmic-codec",
301 		.dai_name = "dmic-hifi",
302 	}
303 };
304 
305 static int sof_es8336_late_probe(struct snd_soc_card *card)
306 {
307 	struct sof_es8336_private *priv = snd_soc_card_get_drvdata(card);
308 	struct sof_hdmi_pcm *pcm;
309 
310 	if (list_empty(&priv->hdmi_pcm_list))
311 		return -ENOENT;
312 
313 	pcm = list_first_entry(&priv->hdmi_pcm_list, struct sof_hdmi_pcm, head);
314 
315 	return hda_dsp_hdmi_build_controls(card, pcm->codec_dai->component);
316 }
317 
318 /* SoC card */
319 static struct snd_soc_card sof_es8336_card = {
320 	.name = "essx8336", /* sof- prefix added automatically */
321 	.owner = THIS_MODULE,
322 	.dapm_widgets = sof_es8316_widgets,
323 	.num_dapm_widgets = ARRAY_SIZE(sof_es8316_widgets),
324 	.dapm_routes = sof_es8316_audio_map,
325 	.num_dapm_routes = ARRAY_SIZE(sof_es8316_audio_map),
326 	.controls = sof_es8316_controls,
327 	.num_controls = ARRAY_SIZE(sof_es8316_controls),
328 	.fully_routed = true,
329 	.late_probe = sof_es8336_late_probe,
330 	.num_links = 1,
331 };
332 
333 static struct snd_soc_dai_link *sof_card_dai_links_create(struct device *dev,
334 							  int ssp_codec,
335 							  int dmic_be_num,
336 							  int hdmi_num)
337 {
338 	struct snd_soc_dai_link_component *cpus;
339 	struct snd_soc_dai_link *links;
340 	struct snd_soc_dai_link_component *idisp_components;
341 	int hdmi_id_offset = 0;
342 	int id = 0;
343 	int i;
344 
345 	links = devm_kcalloc(dev, sof_es8336_card.num_links,
346 			     sizeof(struct snd_soc_dai_link), GFP_KERNEL);
347 	cpus = devm_kcalloc(dev, sof_es8336_card.num_links,
348 			    sizeof(struct snd_soc_dai_link_component), GFP_KERNEL);
349 	if (!links || !cpus)
350 		goto devm_err;
351 
352 	/* codec SSP */
353 	links[id].name = devm_kasprintf(dev, GFP_KERNEL,
354 					"SSP%d-Codec", ssp_codec);
355 	if (!links[id].name)
356 		goto devm_err;
357 
358 	links[id].id = id;
359 	links[id].codecs = es8336_codec;
360 	links[id].num_codecs = ARRAY_SIZE(es8336_codec);
361 	links[id].platforms = platform_component;
362 	links[id].num_platforms = ARRAY_SIZE(platform_component);
363 	links[id].init = sof_es8316_init;
364 	links[id].exit = sof_es8316_exit;
365 	links[id].ops = &sof_es8336_ops;
366 	links[id].nonatomic = true;
367 	links[id].dpcm_playback = 1;
368 	links[id].dpcm_capture = 1;
369 	links[id].no_pcm = 1;
370 	links[id].cpus = &cpus[id];
371 	links[id].num_cpus = 1;
372 
373 	links[id].cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL,
374 						  "SSP%d Pin",
375 						  ssp_codec);
376 	if (!links[id].cpus->dai_name)
377 		goto devm_err;
378 
379 	id++;
380 
381 	/* dmic */
382 	if (dmic_be_num > 0) {
383 		/* at least we have dmic01 */
384 		links[id].name = "dmic01";
385 		links[id].cpus = &cpus[id];
386 		links[id].cpus->dai_name = "DMIC01 Pin";
387 		links[id].init = dmic_init;
388 		if (dmic_be_num > 1) {
389 			/* set up 2 BE links at most */
390 			links[id + 1].name = "dmic16k";
391 			links[id + 1].cpus = &cpus[id + 1];
392 			links[id + 1].cpus->dai_name = "DMIC16k Pin";
393 			dmic_be_num = 2;
394 		}
395 	} else {
396 		/* HDMI dai link starts at 3 according to current topology settings */
397 		hdmi_id_offset = 2;
398 	}
399 
400 	for (i = 0; i < dmic_be_num; i++) {
401 		links[id].id = id;
402 		links[id].num_cpus = 1;
403 		links[id].codecs = dmic_component;
404 		links[id].num_codecs = ARRAY_SIZE(dmic_component);
405 		links[id].platforms = platform_component;
406 		links[id].num_platforms = ARRAY_SIZE(platform_component);
407 		links[id].ignore_suspend = 1;
408 		links[id].dpcm_capture = 1;
409 		links[id].no_pcm = 1;
410 
411 		id++;
412 	}
413 
414 	/* HDMI */
415 	if (hdmi_num > 0) {
416 		idisp_components = devm_kzalloc(dev,
417 						sizeof(struct snd_soc_dai_link_component) *
418 						hdmi_num, GFP_KERNEL);
419 		if (!idisp_components)
420 			goto devm_err;
421 	}
422 
423 	for (i = 1; i <= hdmi_num; i++) {
424 		links[id].name = devm_kasprintf(dev, GFP_KERNEL,
425 						"iDisp%d", i);
426 		if (!links[id].name)
427 			goto devm_err;
428 
429 		links[id].id = id + hdmi_id_offset;
430 		links[id].cpus = &cpus[id];
431 		links[id].num_cpus = 1;
432 		links[id].cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL,
433 							  "iDisp%d Pin", i);
434 		if (!links[id].cpus->dai_name)
435 			goto devm_err;
436 
437 		idisp_components[i - 1].name = "ehdaudio0D2";
438 		idisp_components[i - 1].dai_name = devm_kasprintf(dev,
439 								  GFP_KERNEL,
440 								  "intel-hdmi-hifi%d",
441 								  i);
442 		if (!idisp_components[i - 1].dai_name)
443 			goto devm_err;
444 
445 		links[id].codecs = &idisp_components[i - 1];
446 		links[id].num_codecs = 1;
447 		links[id].platforms = platform_component;
448 		links[id].num_platforms = ARRAY_SIZE(platform_component);
449 		links[id].init = sof_hdmi_init;
450 		links[id].dpcm_playback = 1;
451 		links[id].no_pcm = 1;
452 
453 		id++;
454 	}
455 
456 	return links;
457 
458 devm_err:
459 	return NULL;
460 }
461 
462 static char soc_components[30];
463 
464  /* i2c-<HID>:00 with HID being 8 chars */
465 static char codec_name[SND_ACPI_I2C_ID_LEN];
466 
467 static int sof_es8336_probe(struct platform_device *pdev)
468 {
469 	struct device *dev = &pdev->dev;
470 	struct snd_soc_card *card;
471 	struct snd_soc_acpi_mach *mach = pdev->dev.platform_data;
472 	struct property_entry props[MAX_NO_PROPS] = {};
473 	struct sof_es8336_private *priv;
474 	struct fwnode_handle *fwnode;
475 	struct acpi_device *adev;
476 	struct snd_soc_dai_link *dai_links;
477 	struct device *codec_dev;
478 	unsigned int cnt = 0;
479 	int dmic_be_num = 0;
480 	int hdmi_num = 3;
481 	int ret;
482 
483 	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
484 	if (!priv)
485 		return -ENOMEM;
486 
487 	card = &sof_es8336_card;
488 	card->dev = dev;
489 
490 	/* check GPIO DMI quirks */
491 	dmi_check_system(sof_es8336_quirk_table);
492 
493 	if (!mach->mach_params.i2s_link_mask) {
494 		dev_warn(dev, "No I2S link information provided, using SSP0. This may need to be modified with the quirk module parameter\n");
495 	} else {
496 		/*
497 		 * Set configuration based on platform NHLT.
498 		 * In this machine driver, we can only support one SSP for the
499 		 * ES8336 link, the else-if below are intentional.
500 		 * In some cases multiple SSPs can be reported by NHLT, starting MSB-first
501 		 * seems to pick the right connection.
502 		 */
503 		unsigned long ssp = 0;
504 
505 		if (mach->mach_params.i2s_link_mask & BIT(2))
506 			ssp = SOF_ES8336_SSP_CODEC(2);
507 		else if (mach->mach_params.i2s_link_mask & BIT(1))
508 			ssp = SOF_ES8336_SSP_CODEC(1);
509 		else  if (mach->mach_params.i2s_link_mask & BIT(0))
510 			ssp = SOF_ES8336_SSP_CODEC(0);
511 
512 		quirk |= ssp;
513 	}
514 
515 	if (mach->mach_params.dmic_num)
516 		quirk |= SOF_ES8336_ENABLE_DMIC;
517 
518 	if (quirk_override != -1) {
519 		dev_info(dev, "Overriding quirk 0x%lx => 0x%x\n",
520 			 quirk, quirk_override);
521 		quirk = quirk_override;
522 	}
523 	log_quirks(dev);
524 
525 	if (quirk & SOF_ES8336_ENABLE_DMIC)
526 		dmic_be_num = 2;
527 
528 	sof_es8336_card.num_links += dmic_be_num + hdmi_num;
529 	dai_links = sof_card_dai_links_create(dev,
530 					      SOF_ES8336_SSP_CODEC(quirk),
531 					      dmic_be_num, hdmi_num);
532 	if (!dai_links)
533 		return -ENOMEM;
534 
535 	sof_es8336_card.dai_link = dai_links;
536 
537 	/* fixup codec name based on HID */
538 	adev = acpi_dev_get_first_match_dev(mach->id, NULL, -1);
539 	if (adev) {
540 		snprintf(codec_name, sizeof(codec_name),
541 			 "i2c-%s", acpi_dev_name(adev));
542 		put_device(&adev->dev);
543 		dai_links[0].codecs->name = codec_name;
544 
545 		/* also fixup codec dai name if relevant */
546 		if (!strncmp(mach->id, "ESSX8326", SND_ACPI_I2C_ID_LEN))
547 			dai_links[0].codecs->dai_name = "ES8326 HiFi";
548 	} else {
549 		dev_err(dev, "Error cannot find '%s' dev\n", mach->id);
550 		return -ENXIO;
551 	}
552 
553 	ret = snd_soc_fixup_dai_links_platform_name(&sof_es8336_card,
554 						    mach->mach_params.platform);
555 	if (ret)
556 		return ret;
557 
558 	codec_dev = acpi_get_first_physical_node(adev);
559 	if (!codec_dev)
560 		return -EPROBE_DEFER;
561 	priv->codec_dev = get_device(codec_dev);
562 
563 	if (quirk & SOF_ES8336_JD_INVERTED)
564 		props[cnt++] = PROPERTY_ENTRY_BOOL("everest,jack-detect-inverted");
565 
566 	if (cnt) {
567 		fwnode = fwnode_create_software_node(props, NULL);
568 		if (IS_ERR(fwnode)) {
569 			put_device(codec_dev);
570 			return PTR_ERR(fwnode);
571 		}
572 
573 		ret = device_add_software_node(codec_dev, to_software_node(fwnode));
574 
575 		fwnode_handle_put(fwnode);
576 
577 		if (ret) {
578 			put_device(codec_dev);
579 			return ret;
580 		}
581 	}
582 
583 	/* get speaker enable GPIO */
584 	ret = devm_acpi_dev_add_driver_gpios(codec_dev, gpio_mapping);
585 	if (ret)
586 		dev_warn(codec_dev, "unable to add GPIO mapping table\n");
587 
588 	priv->gpio_pa = gpiod_get_optional(codec_dev, "pa-enable", GPIOD_OUT_LOW);
589 	if (IS_ERR(priv->gpio_pa)) {
590 		ret = dev_err_probe(dev, PTR_ERR(priv->gpio_pa),
591 				    "could not get pa-enable GPIO\n");
592 		goto err_put_codec;
593 	}
594 
595 	INIT_LIST_HEAD(&priv->hdmi_pcm_list);
596 
597 	snd_soc_card_set_drvdata(card, priv);
598 
599 	if (mach->mach_params.dmic_num > 0) {
600 		snprintf(soc_components, sizeof(soc_components),
601 			 "cfg-dmics:%d", mach->mach_params.dmic_num);
602 		card->components = soc_components;
603 	}
604 
605 	ret = devm_snd_soc_register_card(dev, card);
606 	if (ret) {
607 		gpiod_put(priv->gpio_pa);
608 		dev_err(dev, "snd_soc_register_card failed: %d\n", ret);
609 		goto err_put_codec;
610 	}
611 	platform_set_drvdata(pdev, &sof_es8336_card);
612 	return 0;
613 
614 err_put_codec:
615 	device_remove_software_node(priv->codec_dev);
616 	put_device(codec_dev);
617 	return ret;
618 }
619 
620 static int sof_es8336_remove(struct platform_device *pdev)
621 {
622 	struct snd_soc_card *card = platform_get_drvdata(pdev);
623 	struct sof_es8336_private *priv = snd_soc_card_get_drvdata(card);
624 
625 	gpiod_put(priv->gpio_pa);
626 	device_remove_software_node(priv->codec_dev);
627 	put_device(priv->codec_dev);
628 
629 	return 0;
630 }
631 
632 static struct platform_driver sof_es8336_driver = {
633 	.driver = {
634 		.name = "sof-essx8336",
635 		.pm = &snd_soc_pm_ops,
636 	},
637 	.probe = sof_es8336_probe,
638 	.remove = sof_es8336_remove,
639 };
640 module_platform_driver(sof_es8336_driver);
641 
642 MODULE_DESCRIPTION("ASoC Intel(R) SOF + ES8336 Machine driver");
643 MODULE_LICENSE("GPL");
644 MODULE_ALIAS("platform:sof-essx8336");
645 MODULE_IMPORT_NS(SND_SOC_INTEL_HDA_DSP_COMMON);
646