Debian Codegraph @

sound/soc/intel/common/soc-acpi-intel-ssp-common.c

raw
1 // SPDX-License-Identifier: GPL-2.0-only
2 //
3 // Copyright(c) 2023 Intel Corporation
4
5 #include <linux/device.h>
6 #include <sound/soc-acpi.h>
7 #include <sound/soc-acpi-intel-ssp-common.h>
8
9 /*
10 * Codec probe function
11 */
12 #define CODEC_MAP_ENTRY(n, s, h, t) \
13 { \
14 .name = n, \
15 .tplg_suffix = s, \
16 .acpi_hid = h, \
17 .codec_type = t, \
18 }
19
20 struct codec_map {
21 const char *name;
22 const char *tplg_suffix;
23 const char *acpi_hid;
24 enum snd_soc_acpi_intel_codec codec_type;
25 };
26
27 static const struct codec_map codecs[] = {
28 /* Cirrus Logic */
29 CODEC_MAP_ENTRY("CS42L42", "cs42l42", CS42L42_ACPI_HID, CODEC_CS42L42),
30
31 /* Dialog */
32 CODEC_MAP_ENTRY("DA7219", "da7219", DA7219_ACPI_HID, CODEC_DA7219),
33
34 /* Everest */
35 CODEC_MAP_ENTRY("ES8316", "es8336", ES8316_ACPI_HID, CODEC_ES8316),
36 CODEC_MAP_ENTRY("ES8326", "es8336", ES8326_ACPI_HID, CODEC_ES8326),
37 CODEC_MAP_ENTRY("ES8336", "es8336", ES8336_ACPI_HID, CODEC_ES8336),
38
39 /* Nuvoton */
40 CODEC_MAP_ENTRY("NAU8825", "nau8825", NAU8825_ACPI_HID, CODEC_NAU8825),
41
42 /* Realtek */
43 CODEC_MAP_ENTRY("RT5650", "rt5650", RT5650_ACPI_HID, CODEC_RT5650),
44 CODEC_MAP_ENTRY("RT5682", "rt5682", RT5682_ACPI_HID, CODEC_RT5682),
45 CODEC_MAP_ENTRY("RT5682S", "rt5682", RT5682S_ACPI_HID, CODEC_RT5682S),
46 };
47
48 static const struct codec_map amps[] = {
49 /* Cirrus Logic */
50 CODEC_MAP_ENTRY("CS35L41", "cs35l41", CS35L41_ACPI_HID, CODEC_CS35L41),
51
52 /* Maxim */
53 CODEC_MAP_ENTRY("MAX98357A", "max98357a", MAX_98357A_ACPI_HID, CODEC_MAX98357A),
54 CODEC_MAP_ENTRY("MAX98360A", "max98360a", MAX_98360A_ACPI_HID, CODEC_MAX98360A),
55 CODEC_MAP_ENTRY("MAX98373", "max98373", MAX_98373_ACPI_HID, CODEC_MAX98373),
56 CODEC_MAP_ENTRY("MAX98390", "max98390", MAX_98390_ACPI_HID, CODEC_MAX98390),
57
58 /* Nuvoton */
59 CODEC_MAP_ENTRY("NAU8318", "nau8318", NAU8318_ACPI_HID, CODEC_NAU8318),
60
61 /* Realtek */
62 CODEC_MAP_ENTRY("RT1011", "rt1011", RT1011_ACPI_HID, CODEC_RT1011),
63 CODEC_MAP_ENTRY("RT1015", "rt1015", RT1015_ACPI_HID, CODEC_RT1015),
64 CODEC_MAP_ENTRY("RT1015P", "rt1015", RT1015P_ACPI_HID, CODEC_RT1015P),
65 CODEC_MAP_ENTRY("RT1019P", "rt1019", RT1019P_ACPI_HID, CODEC_RT1019P),
66 CODEC_MAP_ENTRY("RT1308", "rt1308", RT1308_ACPI_HID, CODEC_RT1308),
67
68 /* Texas Instruments */
69 CODEC_MAP_ENTRY("TAS2563", "tas2563", TAS2563_ACPI_HID, CODEC_TAS2563),
70
71 /*
72 * Monolithic components
73 *
74 * Only put components that can serve as both the amp and the codec below this line.
75 * This will ensure that if the part is used just as a codec and there is an amp as well
76 * then the amp will be selected properly.
77 */
78 CODEC_MAP_ENTRY("RT5650", "rt5650", RT5650_ACPI_HID, CODEC_RT5650),
79 };
80
81 enum snd_soc_acpi_intel_codec
82 snd_soc_acpi_intel_detect_codec_type(struct device *dev)
83 {
84 int i;
85
86 for (i = 0; i < ARRAY_SIZE(codecs); i++) {
87 if (!acpi_dev_present(codecs[i].acpi_hid, NULL, -1))
88 continue;
89
90 dev_dbg(dev, "codec %s found\n", codecs[i].name);
91 return codecs[i].codec_type;
92 }
93
94 return CODEC_NONE;
95 }
96 EXPORT_SYMBOL_NS(snd_soc_acpi_intel_detect_codec_type, "SND_SOC_ACPI_INTEL_MATCH");
97
98 enum snd_soc_acpi_intel_codec
99 snd_soc_acpi_intel_detect_amp_type(struct device *dev)
100 {
101 int i;
102
103 for (i = 0; i < ARRAY_SIZE(amps); i++) {
104 if (!acpi_dev_present(amps[i].acpi_hid, NULL, -1))
105 continue;
106
107 dev_dbg(dev, "amp %s found\n", amps[i].name);
108 return amps[i].codec_type;
109 }
110
111 return CODEC_NONE;
112 }
113 EXPORT_SYMBOL_NS(snd_soc_acpi_intel_detect_amp_type, "SND_SOC_ACPI_INTEL_MATCH");
114
115 const char *
116 snd_soc_acpi_intel_get_codec_name(enum snd_soc_acpi_intel_codec codec_type)
117 {
118 int i;
119
120 for (i = 0; i < ARRAY_SIZE(codecs); i++) {
121 if (codecs[i].codec_type != codec_type)
122 continue;
123
124 return codecs[i].name;
125 }
126 for (i = 0; i < ARRAY_SIZE(amps); i++) {
127 if (amps[i].codec_type != codec_type)
128 continue;
129
130 return amps[i].name;
131 }
132
133 return NULL;
134 }
135 EXPORT_SYMBOL_NS(snd_soc_acpi_intel_get_codec_name, "SND_SOC_ACPI_INTEL_MATCH");
136
137 const char *
138 snd_soc_acpi_intel_get_codec_tplg_suffix(enum snd_soc_acpi_intel_codec codec_type)
139 {
140 int i;
141
142 for (i = 0; i < ARRAY_SIZE(codecs); i++) {
143 if (codecs[i].codec_type != codec_type)
144 continue;
145
146 return codecs[i].tplg_suffix;
147 }
148
149 return NULL;
150 }
151 EXPORT_SYMBOL_NS(snd_soc_acpi_intel_get_codec_tplg_suffix, "SND_SOC_ACPI_INTEL_MATCH");
152
153 const char *
154 snd_soc_acpi_intel_get_amp_tplg_suffix(enum snd_soc_acpi_intel_codec codec_type)
155 {
156 int i;
157
158 for (i = 0; i < ARRAY_SIZE(amps); i++) {
159 if (amps[i].codec_type != codec_type)
160 continue;
161
162 return amps[i].tplg_suffix;
163 }
164
165 return NULL;
166 }
167 EXPORT_SYMBOL_NS(snd_soc_acpi_intel_get_amp_tplg_suffix, "SND_SOC_ACPI_INTEL_MATCH");
168
169 MODULE_DESCRIPTION("ASoC Intel SOF Common Machine Driver Helpers");
170 MODULE_AUTHOR("Brent Lu <[email protected]>");
171 MODULE_LICENSE("GPL");