xref: /linux/sound/pci/hda/cs35l41_hda_property.c (revision e96fddb32931d007db12b1fce9b5e8e4c080401b)
1 // SPDX-License-Identifier: GPL-2.0
2 //
3 // CS35L41 ALSA HDA Property driver
4 //
5 // Copyright 2023 Cirrus Logic, Inc.
6 //
7 // Author: Stefan Binding <sbinding@opensource.cirrus.com>
8 
9 #include <linux/acpi.h>
10 #include <linux/gpio/consumer.h>
11 #include <linux/string.h>
12 #include "cs35l41_hda_property.h"
13 #include <linux/spi/spi.h>
14 
15 #define MAX_AMPS 4
16 
17 struct cs35l41_config {
18 	const char *ssid;
19 	int num_amps;
20 	enum {
21 		INTERNAL,
22 		EXTERNAL
23 	} boost_type;
24 	u8 channel[MAX_AMPS];
25 	int reset_gpio_index; /* -1 if no reset gpio */
26 	int spkid_gpio_index; /* -1 if no spkid gpio */
27 	int cs_gpio_index; /* -1 if no cs gpio, or cs-gpios already exists, max num amps == 2 */
28 	int boost_ind_nanohenry; /* Required if boost_type == Internal */
29 	int boost_peak_milliamp; /* Required if boost_type == Internal */
30 	int boost_cap_microfarad; /* Required if boost_type == Internal */
31 };
32 
33 static const struct cs35l41_config cs35l41_config_table[] = {
34 	{ "10280B27", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 1000, 4500, 24 },
35 	{ "10280B28", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 1000, 4500, 24 },
36 	{ "10280BEB", 2, EXTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, -1, 0, 0, 0, 0 },
37 	{ "10280C4D", 4, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, CS35L41_LEFT, CS35L41_RIGHT }, 0, 1, -1, 1000, 4500, 24 },
38 /*
39  * Device 103C89C6 does have _DSD, however it is setup to use the wrong boost type.
40  * We can override the _DSD to correct the boost type here.
41  * Since this laptop has valid ACPI, we do not need to handle cs-gpios, since that already exists
42  * in the ACPI. The Reset GPIO is also valid, so we can use the Reset defined in _DSD.
43  */
44 	{ "103C89C6", 2, INTERNAL, { CS35L41_RIGHT, CS35L41_LEFT, 0, 0 }, -1, -1, -1, 1000, 4500, 24 },
45 	{ "103C8A28", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },
46 	{ "103C8A29", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },
47 	{ "103C8A2A", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },
48 	{ "103C8A2B", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },
49 	{ "103C8A2C", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },
50 	{ "103C8A2D", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },
51 	{ "103C8A2E", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },
52 	{ "103C8A30", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },
53 	{ "103C8A31", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },
54 	{ "103C8BB3", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },
55 	{ "103C8BB4", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },
56 	{ "103C8BDF", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },
57 	{ "103C8BE0", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },
58 	{ "103C8BE1", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },
59 	{ "103C8BE2", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },
60 	{ "103C8BE9", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },
61 	{ "103C8BDD", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },
62 	{ "103C8BDE", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },
63 	{ "103C8BE3", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },
64 	{ "103C8BE5", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },
65 	{ "103C8BE6", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },
66 	{ "103C8B3A", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },
67 	{ "104312AF", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 1000, 4500, 24 },
68 	{ "10431433", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4500, 24 },
69 	{ "10431463", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4500, 24 },
70 	{ "10431473", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, -1, 0, 1000, 4500, 24 },
71 	{ "10431483", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, -1, 0, 1000, 4500, 24 },
72 	{ "10431493", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 1000, 4500, 24 },
73 	{ "104314D3", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 1000, 4500, 24 },
74 	{ "104314E3", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4500, 24 },
75 	{ "10431503", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4500, 24 },
76 	{ "10431533", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4500, 24 },
77 	{ "10431573", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 1000, 4500, 24 },
78 	{ "10431663", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, -1, 0, 1000, 4500, 24 },
79 	{ "10431683", 2, EXTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 0, 0, 0 },
80 	{ "104316A3", 2, EXTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 0, 0, 0 },
81 	{ "104316D3", 2, EXTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 0, 0, 0 },
82 	{ "104316F3", 2, EXTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 0, 0, 0 },
83 	{ "104317F3", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4500, 24 },
84 	{ "10431863", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 1000, 4500, 24 },
85 	{ "104318D3", 2, EXTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 0, 0, 0 },
86 	{ "10431C9F", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 1000, 4500, 24 },
87 	{ "10431CAF", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 1000, 4500, 24 },
88 	{ "10431CCF", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 1000, 4500, 24 },
89 	{ "10431CDF", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 1000, 4500, 24 },
90 	{ "10431CEF", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 1000, 4500, 24 },
91 	{ "10431D1F", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4500, 24 },
92 	{ "10431DA2", 2, EXTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 0, 0, 0 },
93 	{ "10431E02", 2, EXTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 0, 0, 0 },
94 	{ "10431EE2", 2, EXTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, -1, -1, 0, 0, 0 },
95 	{ "10431F12", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4500, 24 },
96 	{ "10431F1F", 2, EXTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, -1, 0, 0, 0, 0 },
97 	{ "10431F62", 2, EXTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 0, 0, 0 },
98 	{ "17AA38B4", 2, EXTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 0, 0, 0 },
99 	{ "17AA38B5", 2, EXTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 0, 0, 0 },
100 	{ "17AA38B6", 2, EXTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 0, 0, 0 },
101 	{ "17AA38B7", 2, EXTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 0, 0, 0 },
102 	{}
103 };
104 
105 static int cs35l41_add_gpios(struct cs35l41_hda *cs35l41, struct device *physdev, int reset_gpio,
106 			     int spkid_gpio, int cs_gpio_index, int num_amps)
107 {
108 	struct acpi_gpio_mapping *gpio_mapping = NULL;
109 	struct acpi_gpio_params *reset_gpio_params = NULL;
110 	struct acpi_gpio_params *spkid_gpio_params = NULL;
111 	struct acpi_gpio_params *cs_gpio_params = NULL;
112 	unsigned int num_entries = 0;
113 	unsigned int reset_index, spkid_index, csgpio_index;
114 	int i;
115 
116 	/*
117 	 * GPIO Mapping only needs to be done once, since it would be available for subsequent amps
118 	 */
119 	if (cs35l41->dacpi->driver_gpios)
120 		return 0;
121 
122 	if (reset_gpio >= 0) {
123 		reset_index = num_entries;
124 		num_entries++;
125 	}
126 
127 	if (spkid_gpio >= 0) {
128 		spkid_index = num_entries;
129 		num_entries++;
130 	}
131 
132 	if ((cs_gpio_index >= 0)  && (num_amps == 2)) {
133 		csgpio_index = num_entries;
134 		num_entries++;
135 	}
136 
137 	if (!num_entries)
138 		return 0;
139 
140 	/* must include termination entry */
141 	num_entries++;
142 
143 	gpio_mapping = devm_kcalloc(physdev, num_entries, sizeof(struct acpi_gpio_mapping),
144 				    GFP_KERNEL);
145 
146 	if (!gpio_mapping)
147 		goto err;
148 
149 	if (reset_gpio >= 0) {
150 		gpio_mapping[reset_index].name = "reset-gpios";
151 		reset_gpio_params = devm_kcalloc(physdev, num_amps, sizeof(struct acpi_gpio_params),
152 						 GFP_KERNEL);
153 		if (!reset_gpio_params)
154 			goto err;
155 
156 		for (i = 0; i < num_amps; i++)
157 			reset_gpio_params[i].crs_entry_index = reset_gpio;
158 
159 		gpio_mapping[reset_index].data = reset_gpio_params;
160 		gpio_mapping[reset_index].size = num_amps;
161 	}
162 
163 	if (spkid_gpio >= 0) {
164 		gpio_mapping[spkid_index].name = "spk-id-gpios";
165 		spkid_gpio_params = devm_kcalloc(physdev, num_amps, sizeof(struct acpi_gpio_params),
166 						 GFP_KERNEL);
167 		if (!spkid_gpio_params)
168 			goto err;
169 
170 		for (i = 0; i < num_amps; i++)
171 			spkid_gpio_params[i].crs_entry_index = spkid_gpio;
172 
173 		gpio_mapping[spkid_index].data = spkid_gpio_params;
174 		gpio_mapping[spkid_index].size = num_amps;
175 	}
176 
177 	if ((cs_gpio_index >= 0) && (num_amps == 2)) {
178 		gpio_mapping[csgpio_index].name = "cs-gpios";
179 		/* only one GPIO CS is supported without using _DSD, obtained using index 0 */
180 		cs_gpio_params = devm_kzalloc(physdev, sizeof(struct acpi_gpio_params), GFP_KERNEL);
181 		if (!cs_gpio_params)
182 			goto err;
183 
184 		cs_gpio_params->crs_entry_index = cs_gpio_index;
185 
186 		gpio_mapping[csgpio_index].data = cs_gpio_params;
187 		gpio_mapping[csgpio_index].size = 1;
188 	}
189 
190 	return devm_acpi_dev_add_driver_gpios(physdev, gpio_mapping);
191 err:
192 	devm_kfree(physdev, gpio_mapping);
193 	devm_kfree(physdev, reset_gpio_params);
194 	devm_kfree(physdev, spkid_gpio_params);
195 	devm_kfree(physdev, cs_gpio_params);
196 	return -ENOMEM;
197 }
198 
199 static int generic_dsd_config(struct cs35l41_hda *cs35l41, struct device *physdev, int id,
200 			      const char *hid)
201 {
202 	struct cs35l41_hw_cfg *hw_cfg = &cs35l41->hw_cfg;
203 	const struct cs35l41_config *cfg;
204 	struct gpio_desc *cs_gpiod;
205 	struct spi_device *spi;
206 	bool dsd_found;
207 	int ret;
208 
209 	for (cfg = cs35l41_config_table; cfg->ssid; cfg++) {
210 		if (!strcasecmp(cfg->ssid, cs35l41->acpi_subsystem_id))
211 			break;
212 	}
213 
214 	if (!cfg->ssid)
215 		return -ENOENT;
216 
217 	if (!cs35l41->dacpi || cs35l41->dacpi != ACPI_COMPANION(physdev)) {
218 		dev_err(cs35l41->dev, "ACPI Device does not match, cannot override _DSD.\n");
219 		return -ENODEV;
220 	}
221 
222 	dev_info(cs35l41->dev, "Adding DSD properties for %s\n", cs35l41->acpi_subsystem_id);
223 
224 	dsd_found = acpi_dev_has_props(cs35l41->dacpi);
225 
226 	if (!dsd_found) {
227 		ret = cs35l41_add_gpios(cs35l41, physdev, cfg->reset_gpio_index,
228 						 cfg->spkid_gpio_index, cfg->cs_gpio_index,
229 						 cfg->num_amps);
230 		if (ret) {
231 			dev_err(cs35l41->dev, "Error adding GPIO mapping: %d\n", ret);
232 			return ret;
233 		}
234 	} else if (cfg->reset_gpio_index >= 0 || cfg->spkid_gpio_index >= 0) {
235 		dev_warn(cs35l41->dev, "Cannot add Reset/Speaker ID/SPI CS GPIO Mapping, "
236 			 "_DSD already exists.\n");
237 	}
238 
239 	if (cs35l41->control_bus == SPI) {
240 		cs35l41->index = id;
241 
242 		/*
243 		 * Manually set the Chip Select for the second amp <cs_gpio_index> in the node.
244 		 * This is only supported for systems with 2 amps, since we cannot expand the
245 		 * default number of chip selects without using cs-gpios
246 		 * The CS GPIO must be set high prior to communicating with the first amp (which
247 		 * uses a native chip select), to ensure the second amp does not clash with the
248 		 * first.
249 		 */
250 		if (IS_ENABLED(CONFIG_SPI) && cfg->cs_gpio_index >= 0) {
251 			spi = to_spi_device(cs35l41->dev);
252 
253 			if (cfg->num_amps != 2) {
254 				dev_warn(cs35l41->dev,
255 					 "Cannot update SPI CS, Number of Amps (%d) != 2\n",
256 					 cfg->num_amps);
257 			} else if (dsd_found) {
258 				dev_warn(cs35l41->dev,
259 					"Cannot update SPI CS, _DSD already exists.\n");
260 			} else {
261 				/*
262 				 * This is obtained using driver_gpios, since only one GPIO for CS
263 				 * exists, this can be obtained using index 0.
264 				 */
265 				cs_gpiod = gpiod_get_index(physdev, "cs", 0, GPIOD_OUT_LOW);
266 				if (IS_ERR(cs_gpiod)) {
267 					dev_err(cs35l41->dev,
268 						"Unable to get Chip Select GPIO descriptor\n");
269 					return PTR_ERR(cs_gpiod);
270 				}
271 				if (id == 1) {
272 					spi_set_csgpiod(spi, 0, cs_gpiod);
273 					cs35l41->cs_gpio = cs_gpiod;
274 				} else {
275 					gpiod_set_value_cansleep(cs_gpiod, true);
276 					gpiod_put(cs_gpiod);
277 				}
278 				spi_setup(spi);
279 			}
280 		}
281 	} else {
282 		if (cfg->num_amps > 2)
283 			/*
284 			 * i2c addresses for 3/4 amps are used in order: 0x40, 0x41, 0x42, 0x43,
285 			 * subtracting 0x40 would give zero-based index
286 			 */
287 			cs35l41->index = id - 0x40;
288 		else
289 			/* i2c addr 0x40 for first amp (always), 0x41/0x42 for 2nd amp */
290 			cs35l41->index = id == 0x40 ? 0 : 1;
291 	}
292 
293 	if (cfg->num_amps == 3)
294 		/* 3 amps means a center channel, so no duplicate channels */
295 		cs35l41->channel_index = 0;
296 	else
297 		/*
298 		 * if 4 amps, there are duplicate channels, so they need different indexes
299 		 * if 2 amps, no duplicate channels, channel_index would be 0
300 		 */
301 		cs35l41->channel_index = cs35l41->index / 2;
302 
303 	cs35l41->reset_gpio = fwnode_gpiod_get_index(acpi_fwnode_handle(cs35l41->dacpi), "reset",
304 						     cs35l41->index, GPIOD_OUT_LOW,
305 						     "cs35l41-reset");
306 	cs35l41->speaker_id = cs35l41_get_speaker_id(physdev, cs35l41->index, cfg->num_amps, -1);
307 
308 	hw_cfg->spk_pos = cfg->channel[cs35l41->index];
309 
310 	if (cfg->boost_type == INTERNAL) {
311 		hw_cfg->bst_type = CS35L41_INT_BOOST;
312 		hw_cfg->bst_ind = cfg->boost_ind_nanohenry;
313 		hw_cfg->bst_ipk = cfg->boost_peak_milliamp;
314 		hw_cfg->bst_cap = cfg->boost_cap_microfarad;
315 		hw_cfg->gpio1.func = CS35L41_NOT_USED;
316 		hw_cfg->gpio1.valid = true;
317 	} else {
318 		hw_cfg->bst_type = CS35L41_EXT_BOOST;
319 		hw_cfg->bst_ind = -1;
320 		hw_cfg->bst_ipk = -1;
321 		hw_cfg->bst_cap = -1;
322 		hw_cfg->gpio1.func = CS35l41_VSPK_SWITCH;
323 		hw_cfg->gpio1.valid = true;
324 	}
325 
326 	hw_cfg->gpio2.func = CS35L41_INTERRUPT;
327 	hw_cfg->gpio2.valid = true;
328 	hw_cfg->valid = true;
329 
330 	return 0;
331 }
332 
333 /*
334  * Device CLSA010(0/1) doesn't have _DSD so a gpiod_get by the label reset won't work.
335  * And devices created by serial-multi-instantiate don't have their device struct
336  * pointing to the correct fwnode, so acpi_dev must be used here.
337  * And devm functions expect that the device requesting the resource has the correct
338  * fwnode.
339  */
340 static int lenovo_legion_no_acpi(struct cs35l41_hda *cs35l41, struct device *physdev, int id,
341 				 const char *hid)
342 {
343 	struct cs35l41_hw_cfg *hw_cfg = &cs35l41->hw_cfg;
344 
345 	/* check I2C address to assign the index */
346 	cs35l41->index = id == 0x40 ? 0 : 1;
347 	cs35l41->channel_index = 0;
348 	cs35l41->reset_gpio = gpiod_get_index(physdev, NULL, 0, GPIOD_OUT_HIGH);
349 	cs35l41->speaker_id = cs35l41_get_speaker_id(physdev, 0, 0, 2);
350 	hw_cfg->spk_pos = cs35l41->index;
351 	hw_cfg->gpio2.func = CS35L41_INTERRUPT;
352 	hw_cfg->gpio2.valid = true;
353 	hw_cfg->valid = true;
354 
355 	if (strcmp(hid, "CLSA0100") == 0) {
356 		hw_cfg->bst_type = CS35L41_EXT_BOOST_NO_VSPK_SWITCH;
357 	} else if (strcmp(hid, "CLSA0101") == 0) {
358 		hw_cfg->bst_type = CS35L41_EXT_BOOST;
359 		hw_cfg->gpio1.func = CS35l41_VSPK_SWITCH;
360 		hw_cfg->gpio1.valid = true;
361 	}
362 
363 	return 0;
364 }
365 
366 struct cs35l41_prop_model {
367 	const char *hid;
368 	const char *ssid;
369 	int (*add_prop)(struct cs35l41_hda *cs35l41, struct device *physdev, int id,
370 			const char *hid);
371 };
372 
373 static const struct cs35l41_prop_model cs35l41_prop_model_table[] = {
374 	{ "CLSA0100", NULL, lenovo_legion_no_acpi },
375 	{ "CLSA0101", NULL, lenovo_legion_no_acpi },
376 	{ "CSC3551", "10280B27", generic_dsd_config },
377 	{ "CSC3551", "10280B28", generic_dsd_config },
378 	{ "CSC3551", "10280BEB", generic_dsd_config },
379 	{ "CSC3551", "10280C4D", generic_dsd_config },
380 	{ "CSC3551", "103C89C6", generic_dsd_config },
381 	{ "CSC3551", "103C8A28", generic_dsd_config },
382 	{ "CSC3551", "103C8A29", generic_dsd_config },
383 	{ "CSC3551", "103C8A2A", generic_dsd_config },
384 	{ "CSC3551", "103C8A2B", generic_dsd_config },
385 	{ "CSC3551", "103C8A2C", generic_dsd_config },
386 	{ "CSC3551", "103C8A2D", generic_dsd_config },
387 	{ "CSC3551", "103C8A2E", generic_dsd_config },
388 	{ "CSC3551", "103C8A30", generic_dsd_config },
389 	{ "CSC3551", "103C8A31", generic_dsd_config },
390 	{ "CSC3551", "103C8BB3", generic_dsd_config },
391 	{ "CSC3551", "103C8BB4", generic_dsd_config },
392 	{ "CSC3551", "103C8BDF", generic_dsd_config },
393 	{ "CSC3551", "103C8BE0", generic_dsd_config },
394 	{ "CSC3551", "103C8BE1", generic_dsd_config },
395 	{ "CSC3551", "103C8BE2", generic_dsd_config },
396 	{ "CSC3551", "103C8BE9", generic_dsd_config },
397 	{ "CSC3551", "103C8BDD", generic_dsd_config },
398 	{ "CSC3551", "103C8BDE", generic_dsd_config },
399 	{ "CSC3551", "103C8BE3", generic_dsd_config },
400 	{ "CSC3551", "103C8BE5", generic_dsd_config },
401 	{ "CSC3551", "103C8BE6", generic_dsd_config },
402 	{ "CSC3551", "103C8B3A", generic_dsd_config },
403 	{ "CSC3551", "104312AF", generic_dsd_config },
404 	{ "CSC3551", "10431433", generic_dsd_config },
405 	{ "CSC3551", "10431463", generic_dsd_config },
406 	{ "CSC3551", "10431473", generic_dsd_config },
407 	{ "CSC3551", "10431483", generic_dsd_config },
408 	{ "CSC3551", "10431493", generic_dsd_config },
409 	{ "CSC3551", "104314D3", generic_dsd_config },
410 	{ "CSC3551", "104314E3", generic_dsd_config },
411 	{ "CSC3551", "10431503", generic_dsd_config },
412 	{ "CSC3551", "10431533", generic_dsd_config },
413 	{ "CSC3551", "10431573", generic_dsd_config },
414 	{ "CSC3551", "10431663", generic_dsd_config },
415 	{ "CSC3551", "10431683", generic_dsd_config },
416 	{ "CSC3551", "104316A3", generic_dsd_config },
417 	{ "CSC3551", "104316D3", generic_dsd_config },
418 	{ "CSC3551", "104316F3", generic_dsd_config },
419 	{ "CSC3551", "104317F3", generic_dsd_config },
420 	{ "CSC3551", "10431863", generic_dsd_config },
421 	{ "CSC3551", "104318D3", generic_dsd_config },
422 	{ "CSC3551", "10431C9F", generic_dsd_config },
423 	{ "CSC3551", "10431CAF", generic_dsd_config },
424 	{ "CSC3551", "10431CCF", generic_dsd_config },
425 	{ "CSC3551", "10431CDF", generic_dsd_config },
426 	{ "CSC3551", "10431CEF", generic_dsd_config },
427 	{ "CSC3551", "10431D1F", generic_dsd_config },
428 	{ "CSC3551", "10431DA2", generic_dsd_config },
429 	{ "CSC3551", "10431E02", generic_dsd_config },
430 	{ "CSC3551", "10431EE2", generic_dsd_config },
431 	{ "CSC3551", "10431F12", generic_dsd_config },
432 	{ "CSC3551", "10431F1F", generic_dsd_config },
433 	{ "CSC3551", "10431F62", generic_dsd_config },
434 	{ "CSC3551", "17AA38B4", generic_dsd_config },
435 	{ "CSC3551", "17AA38B5", generic_dsd_config },
436 	{ "CSC3551", "17AA38B6", generic_dsd_config },
437 	{ "CSC3551", "17AA38B7", generic_dsd_config },
438 	{}
439 };
440 
441 int cs35l41_add_dsd_properties(struct cs35l41_hda *cs35l41, struct device *physdev, int id,
442 			       const char *hid)
443 {
444 	const struct cs35l41_prop_model *model;
445 
446 	for (model = cs35l41_prop_model_table; model->hid; model++) {
447 		if (!strcmp(model->hid, hid) &&
448 		    (!model->ssid ||
449 		     (cs35l41->acpi_subsystem_id &&
450 		      !strcasecmp(model->ssid, cs35l41->acpi_subsystem_id))))
451 			return model->add_prop(cs35l41, physdev, id, hid);
452 	}
453 
454 	return -ENOENT;
455 }
456