xref: /linux/sound/soc/intel/boards/sof_nuvoton_common.c (revision 0ea5c948cb64bab5bc7a5516774eb8536f05aa0d)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * This file defines data structures and functions used in Machine
4  * Driver for Intel platforms with Nuvoton Codecs.
5  *
6  * Copyright 2023 Intel Corporation.
7  */
8 #include <linux/module.h>
9 #include <sound/sof.h>
10 #include "sof_nuvoton_common.h"
11 
12 /*
13  * Nuvoton NAU8318
14  */
15 static const struct snd_kcontrol_new nau8318_kcontrols[] = {
16 	SOC_DAPM_PIN_SWITCH("Spk"),
17 };
18 
19 static const struct snd_soc_dapm_widget nau8318_widgets[] = {
20 	SND_SOC_DAPM_SPK("Spk", NULL),
21 };
22 
23 static const struct snd_soc_dapm_route nau8318_routes[] = {
24 	{ "Spk", NULL, "Speaker" },
25 };
26 
27 static struct snd_soc_dai_link_component nau8318_components[] = {
28 	{
29 		.name = NAU8318_DEV0_NAME,
30 		.dai_name = NAU8318_CODEC_DAI,
31 	}
32 };
33 
nau8318_init(struct snd_soc_pcm_runtime * rtd)34 static int nau8318_init(struct snd_soc_pcm_runtime *rtd)
35 {
36 	struct snd_soc_card *card = rtd->card;
37 	int ret;
38 
39 	ret = snd_soc_dapm_new_controls(&card->dapm, nau8318_widgets,
40 					ARRAY_SIZE(nau8318_widgets));
41 	if (ret) {
42 		dev_err(rtd->dev, "fail to add nau8318 widgets, ret %d\n", ret);
43 		return ret;
44 	}
45 
46 	ret = snd_soc_add_card_controls(card, nau8318_kcontrols,
47 					ARRAY_SIZE(nau8318_kcontrols));
48 	if (ret) {
49 		dev_err(rtd->dev, "fail to add nau8318 kcontrols, ret %d\n", ret);
50 		return ret;
51 	}
52 
53 	ret = snd_soc_dapm_add_routes(&card->dapm, nau8318_routes,
54 				      ARRAY_SIZE(nau8318_routes));
55 
56 	if (ret) {
57 		dev_err(rtd->dev, "fail to add nau8318 routes, ret %d\n", ret);
58 		return ret;
59 	}
60 
61 	return ret;
62 }
63 
nau8318_set_dai_link(struct snd_soc_dai_link * link)64 void nau8318_set_dai_link(struct snd_soc_dai_link *link)
65 {
66 	link->codecs = nau8318_components;
67 	link->num_codecs = ARRAY_SIZE(nau8318_components);
68 	link->init = nau8318_init;
69 }
70 EXPORT_SYMBOL_NS(nau8318_set_dai_link, SND_SOC_INTEL_SOF_NUVOTON_COMMON);
71 
72 MODULE_DESCRIPTION("ASoC Intel SOF Nuvoton helpers");
73 MODULE_LICENSE("GPL");
74