xref: /linux/sound/pci/hda/cs35l41_hda_property.c (revision b592ed2e1d78a475f781802e441c499ab446975b)
1ef4ba63fSStefan Binding // SPDX-License-Identifier: GPL-2.0
2ef4ba63fSStefan Binding //
3ef4ba63fSStefan Binding // CS35L41 ALSA HDA Property driver
4ef4ba63fSStefan Binding //
5ef4ba63fSStefan Binding // Copyright 2023 Cirrus Logic, Inc.
6ef4ba63fSStefan Binding //
7ef4ba63fSStefan Binding // Author: Stefan Binding <sbinding@opensource.cirrus.com>
8ef4ba63fSStefan Binding 
98c4c216dSStefan Binding #include <linux/acpi.h>
10ef4ba63fSStefan Binding #include <linux/gpio/consumer.h>
11ef4ba63fSStefan Binding #include <linux/string.h>
12ef4ba63fSStefan Binding #include "cs35l41_hda_property.h"
138c4c216dSStefan Binding #include <linux/spi/spi.h>
148c4c216dSStefan Binding 
158c4c216dSStefan Binding #define MAX_AMPS 4
168c4c216dSStefan Binding 
178c4c216dSStefan Binding struct cs35l41_config {
188c4c216dSStefan Binding 	const char *ssid;
198c4c216dSStefan Binding 	enum {
208c4c216dSStefan Binding 		SPI,
218c4c216dSStefan Binding 		I2C
228c4c216dSStefan Binding 	} bus;
238c4c216dSStefan Binding 	int num_amps;
248c4c216dSStefan Binding 	enum {
258c4c216dSStefan Binding 		INTERNAL,
268c4c216dSStefan Binding 		EXTERNAL
278c4c216dSStefan Binding 	} boost_type;
288c4c216dSStefan Binding 	u8 channel[MAX_AMPS];
298c4c216dSStefan Binding 	int reset_gpio_index; /* -1 if no reset gpio */
308c4c216dSStefan Binding 	int spkid_gpio_index; /* -1 if no spkid gpio */
318c4c216dSStefan Binding 	int cs_gpio_index; /* -1 if no cs gpio, or cs-gpios already exists, max num amps == 2 */
328c4c216dSStefan Binding 	int boost_ind_nanohenry; /* Required if boost_type == Internal */
338c4c216dSStefan Binding 	int boost_peak_milliamp; /* Required if boost_type == Internal */
348c4c216dSStefan Binding 	int boost_cap_microfarad; /* Required if boost_type == Internal */
358c4c216dSStefan Binding };
368c4c216dSStefan Binding 
378c4c216dSStefan Binding static const struct cs35l41_config cs35l41_config_table[] = {
388c4c216dSStefan Binding /*
398c4c216dSStefan Binding  * Device 103C89C6 does have _DSD, however it is setup to use the wrong boost type.
408c4c216dSStefan Binding  * We can override the _DSD to correct the boost type here.
418c4c216dSStefan Binding  * Since this laptop has valid ACPI, we do not need to handle cs-gpios, since that already exists
428c4c216dSStefan Binding  * in the ACPI. The Reset GPIO is also valid, so we can use the Reset defined in _DSD.
438c4c216dSStefan Binding  */
448c4c216dSStefan Binding 	{ "103C89C6", SPI, 2, INTERNAL, { CS35L41_RIGHT, CS35L41_LEFT, 0, 0 }, -1, -1, -1, 1000, 4500, 24 },
45*b592ed2eSStefan Binding 	{ "10431433", I2C, 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4500, 24 },
46*b592ed2eSStefan Binding 	{ "10431463", I2C, 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4500, 24 },
47*b592ed2eSStefan Binding 	{ "10431473", SPI, 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, -1, 0, 1000, 4500, 24 },
48*b592ed2eSStefan Binding 	{ "10431483", SPI, 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, -1, 0, 1000, 4500, 24 },
49*b592ed2eSStefan Binding 	{ "10431493", SPI, 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 1000, 4500, 24 },
50*b592ed2eSStefan Binding 	{ "104314D3", SPI, 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 1000, 4500, 24 },
51*b592ed2eSStefan Binding 	{ "104314E3", I2C, 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4500, 24 },
52*b592ed2eSStefan Binding 	{ "10431503", I2C, 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4500, 24 },
53*b592ed2eSStefan Binding 	{ "10431533", I2C, 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4500, 24 },
54*b592ed2eSStefan Binding 	{ "10431573", SPI, 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 1000, 4500, 24 },
55*b592ed2eSStefan Binding 	{ "10431663", SPI, 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, -1, 0, 1000, 4500, 24 },
56*b592ed2eSStefan Binding 	{ "104317F3", I2C, 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4500, 24 },
57*b592ed2eSStefan Binding 	{ "10431C9F", SPI, 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 1000, 4500, 24 },
58*b592ed2eSStefan Binding 	{ "10431CAF", SPI, 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 1000, 4500, 24 },
59*b592ed2eSStefan Binding 	{ "10431CCF", SPI, 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 1000, 4500, 24 },
60*b592ed2eSStefan Binding 	{ "10431CDF", SPI, 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 1000, 4500, 24 },
61*b592ed2eSStefan Binding 	{ "10431CEF", SPI, 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 1000, 4500, 24 },
62*b592ed2eSStefan Binding 	{ "10431D1F", I2C, 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4500, 24 },
638c4c216dSStefan Binding 	{}
648c4c216dSStefan Binding };
658c4c216dSStefan Binding 
668c4c216dSStefan Binding static int cs35l41_add_gpios(struct cs35l41_hda *cs35l41, struct device *physdev, int reset_gpio,
678c4c216dSStefan Binding 			     int spkid_gpio, int cs_gpio_index, int num_amps)
688c4c216dSStefan Binding {
698c4c216dSStefan Binding 	struct acpi_gpio_mapping *gpio_mapping;
708c4c216dSStefan Binding 	struct acpi_gpio_params *reset_gpio_params;
718c4c216dSStefan Binding 	struct acpi_gpio_params *spkid_gpio_params;
728c4c216dSStefan Binding 	struct acpi_gpio_params *cs_gpio_params;
738c4c216dSStefan Binding 	unsigned int num_entries = 0;
748c4c216dSStefan Binding 	unsigned int reset_index, spkid_index, csgpio_index;
758c4c216dSStefan Binding 	int i;
768c4c216dSStefan Binding 
778c4c216dSStefan Binding 	/*
788c4c216dSStefan Binding 	 * GPIO Mapping only needs to be done once, since it would be available for subsequent amps
798c4c216dSStefan Binding 	 */
808c4c216dSStefan Binding 	if (cs35l41->dacpi->driver_gpios)
818c4c216dSStefan Binding 		return 0;
828c4c216dSStefan Binding 
838c4c216dSStefan Binding 	if (reset_gpio >= 0) {
848c4c216dSStefan Binding 		reset_index = num_entries;
858c4c216dSStefan Binding 		num_entries++;
868c4c216dSStefan Binding 	}
878c4c216dSStefan Binding 
888c4c216dSStefan Binding 	if (spkid_gpio >= 0) {
898c4c216dSStefan Binding 		spkid_index = num_entries;
908c4c216dSStefan Binding 		num_entries++;
918c4c216dSStefan Binding 	}
928c4c216dSStefan Binding 
938c4c216dSStefan Binding 	if ((cs_gpio_index >= 0)  && (num_amps == 2)) {
948c4c216dSStefan Binding 		csgpio_index = num_entries;
958c4c216dSStefan Binding 		num_entries++;
968c4c216dSStefan Binding 	}
978c4c216dSStefan Binding 
988c4c216dSStefan Binding 	if (!num_entries)
998c4c216dSStefan Binding 		return 0;
1008c4c216dSStefan Binding 
1018c4c216dSStefan Binding 	/* must include termination entry */
1028c4c216dSStefan Binding 	num_entries++;
1038c4c216dSStefan Binding 
1048c4c216dSStefan Binding 	gpio_mapping = devm_kcalloc(physdev, num_entries, sizeof(struct acpi_gpio_mapping),
1058c4c216dSStefan Binding 				    GFP_KERNEL);
1068c4c216dSStefan Binding 
1078c4c216dSStefan Binding 	if (!gpio_mapping)
1088c4c216dSStefan Binding 		goto err;
1098c4c216dSStefan Binding 
1108c4c216dSStefan Binding 	if (reset_gpio >= 0) {
1118c4c216dSStefan Binding 		gpio_mapping[reset_index].name = "reset-gpios";
1128c4c216dSStefan Binding 		reset_gpio_params = devm_kcalloc(physdev, num_amps, sizeof(struct acpi_gpio_params),
1138c4c216dSStefan Binding 						 GFP_KERNEL);
1148c4c216dSStefan Binding 		if (!reset_gpio_params)
1158c4c216dSStefan Binding 			goto err;
1168c4c216dSStefan Binding 
1178c4c216dSStefan Binding 		for (i = 0; i < num_amps; i++)
1188c4c216dSStefan Binding 			reset_gpio_params[i].crs_entry_index = reset_gpio;
1198c4c216dSStefan Binding 
1208c4c216dSStefan Binding 		gpio_mapping[reset_index].data = reset_gpio_params;
1218c4c216dSStefan Binding 		gpio_mapping[reset_index].size = num_amps;
1228c4c216dSStefan Binding 	}
1238c4c216dSStefan Binding 
1248c4c216dSStefan Binding 	if (spkid_gpio >= 0) {
1258c4c216dSStefan Binding 		gpio_mapping[spkid_index].name = "spk-id-gpios";
1268c4c216dSStefan Binding 		spkid_gpio_params = devm_kcalloc(physdev, num_amps, sizeof(struct acpi_gpio_params),
1278c4c216dSStefan Binding 						 GFP_KERNEL);
1288c4c216dSStefan Binding 		if (!spkid_gpio_params)
1298c4c216dSStefan Binding 			goto err;
1308c4c216dSStefan Binding 
1318c4c216dSStefan Binding 		for (i = 0; i < num_amps; i++)
1328c4c216dSStefan Binding 			spkid_gpio_params[i].crs_entry_index = spkid_gpio;
1338c4c216dSStefan Binding 
1348c4c216dSStefan Binding 		gpio_mapping[spkid_index].data = spkid_gpio_params;
1358c4c216dSStefan Binding 		gpio_mapping[spkid_index].size = num_amps;
1368c4c216dSStefan Binding 	}
1378c4c216dSStefan Binding 
1388c4c216dSStefan Binding 	if ((cs_gpio_index >= 0) && (num_amps == 2)) {
1398c4c216dSStefan Binding 		gpio_mapping[csgpio_index].name = "cs-gpios";
1408c4c216dSStefan Binding 		/* only one GPIO CS is supported without using _DSD, obtained using index 0 */
1418c4c216dSStefan Binding 		cs_gpio_params = devm_kzalloc(physdev, sizeof(struct acpi_gpio_params), GFP_KERNEL);
1428c4c216dSStefan Binding 		if (!cs_gpio_params)
1438c4c216dSStefan Binding 			goto err;
1448c4c216dSStefan Binding 
1458c4c216dSStefan Binding 		cs_gpio_params->crs_entry_index = cs_gpio_index;
1468c4c216dSStefan Binding 
1478c4c216dSStefan Binding 		gpio_mapping[csgpio_index].data = cs_gpio_params;
1488c4c216dSStefan Binding 		gpio_mapping[csgpio_index].size = 1;
1498c4c216dSStefan Binding 	}
1508c4c216dSStefan Binding 
1518c4c216dSStefan Binding 	return devm_acpi_dev_add_driver_gpios(physdev, gpio_mapping);
1528c4c216dSStefan Binding err:
1538c4c216dSStefan Binding 	devm_kfree(physdev, gpio_mapping);
1548c4c216dSStefan Binding 	devm_kfree(physdev, reset_gpio_params);
1558c4c216dSStefan Binding 	devm_kfree(physdev, spkid_gpio_params);
1568c4c216dSStefan Binding 	devm_kfree(physdev, cs_gpio_params);
1578c4c216dSStefan Binding 	return -ENOMEM;
1588c4c216dSStefan Binding }
1598c4c216dSStefan Binding 
1608c4c216dSStefan Binding static int generic_dsd_config(struct cs35l41_hda *cs35l41, struct device *physdev, int id,
1618c4c216dSStefan Binding 			      const char *hid)
1628c4c216dSStefan Binding {
1638c4c216dSStefan Binding 	struct cs35l41_hw_cfg *hw_cfg = &cs35l41->hw_cfg;
1648c4c216dSStefan Binding 	const struct cs35l41_config *cfg;
1658c4c216dSStefan Binding 	struct gpio_desc *cs_gpiod;
1668c4c216dSStefan Binding 	struct spi_device *spi;
1678c4c216dSStefan Binding 	bool dsd_found;
1688c4c216dSStefan Binding 	int ret;
1698c4c216dSStefan Binding 
1708c4c216dSStefan Binding 	for (cfg = cs35l41_config_table; cfg->ssid; cfg++) {
1718c4c216dSStefan Binding 		if (!strcasecmp(cfg->ssid, cs35l41->acpi_subsystem_id))
1728c4c216dSStefan Binding 			break;
1738c4c216dSStefan Binding 	}
1748c4c216dSStefan Binding 
1758c4c216dSStefan Binding 	if (!cfg->ssid)
1768c4c216dSStefan Binding 		return -ENOENT;
1778c4c216dSStefan Binding 
1788c4c216dSStefan Binding 	if (!cs35l41->dacpi || cs35l41->dacpi != ACPI_COMPANION(physdev)) {
1798c4c216dSStefan Binding 		dev_err(cs35l41->dev, "ACPI Device does not match, cannot override _DSD.\n");
1808c4c216dSStefan Binding 		return -ENODEV;
1818c4c216dSStefan Binding 	}
1828c4c216dSStefan Binding 
1838c4c216dSStefan Binding 	dev_info(cs35l41->dev, "Adding DSD properties for %s\n", cs35l41->acpi_subsystem_id);
1848c4c216dSStefan Binding 
1858c4c216dSStefan Binding 	dsd_found = acpi_dev_has_props(cs35l41->dacpi);
1868c4c216dSStefan Binding 
1878c4c216dSStefan Binding 	if (!dsd_found) {
1888c4c216dSStefan Binding 		ret = cs35l41_add_gpios(cs35l41, physdev, cfg->reset_gpio_index,
1898c4c216dSStefan Binding 						 cfg->spkid_gpio_index, cfg->cs_gpio_index,
1908c4c216dSStefan Binding 						 cfg->num_amps);
1918c4c216dSStefan Binding 		if (ret) {
1928c4c216dSStefan Binding 			dev_err(cs35l41->dev, "Error adding GPIO mapping: %d\n", ret);
1938c4c216dSStefan Binding 			return ret;
1948c4c216dSStefan Binding 		}
1958c4c216dSStefan Binding 	} else if (cfg->reset_gpio_index >= 0 || cfg->spkid_gpio_index >= 0) {
1968c4c216dSStefan Binding 		dev_warn(cs35l41->dev, "Cannot add Reset/Speaker ID/SPI CS GPIO Mapping, "
1978c4c216dSStefan Binding 			 "_DSD already exists.\n");
1988c4c216dSStefan Binding 	}
1998c4c216dSStefan Binding 
2008c4c216dSStefan Binding 	if (cfg->bus == SPI) {
2018c4c216dSStefan Binding 		cs35l41->index = id;
2028c4c216dSStefan Binding 		/*
2038c4c216dSStefan Binding 		 * Manually set the Chip Select for the second amp <cs_gpio_index> in the node.
2048c4c216dSStefan Binding 		 * This is only supported for systems with 2 amps, since we cannot expand the
2058c4c216dSStefan Binding 		 * default number of chip selects without using cs-gpios
2068c4c216dSStefan Binding 		 * The CS GPIO must be set high prior to communicating with the first amp (which
2078c4c216dSStefan Binding 		 * uses a native chip select), to ensure the second amp does not clash with the
2088c4c216dSStefan Binding 		 * first.
2098c4c216dSStefan Binding 		 */
2108c4c216dSStefan Binding 		if (cfg->cs_gpio_index >= 0) {
2118c4c216dSStefan Binding 			spi = to_spi_device(cs35l41->dev);
2128c4c216dSStefan Binding 
2138c4c216dSStefan Binding 			if (cfg->num_amps != 2) {
2148c4c216dSStefan Binding 				dev_warn(cs35l41->dev,
2158c4c216dSStefan Binding 					 "Cannot update SPI CS, Number of Amps (%d) != 2\n",
2168c4c216dSStefan Binding 					 cfg->num_amps);
2178c4c216dSStefan Binding 			} else if (dsd_found) {
2188c4c216dSStefan Binding 				dev_warn(cs35l41->dev,
2198c4c216dSStefan Binding 					"Cannot update SPI CS, _DSD already exists.\n");
2208c4c216dSStefan Binding 			} else {
2218c4c216dSStefan Binding 				/*
2228c4c216dSStefan Binding 				 * This is obtained using driver_gpios, since only one GPIO for CS
2238c4c216dSStefan Binding 				 * exists, this can be obtained using index 0.
2248c4c216dSStefan Binding 				 */
2258c4c216dSStefan Binding 				cs_gpiod = gpiod_get_index(physdev, "cs", 0, GPIOD_OUT_LOW);
2268c4c216dSStefan Binding 				if (IS_ERR(cs_gpiod)) {
2278c4c216dSStefan Binding 					dev_err(cs35l41->dev,
2288c4c216dSStefan Binding 						"Unable to get Chip Select GPIO descriptor\n");
2298c4c216dSStefan Binding 					return PTR_ERR(cs_gpiod);
2308c4c216dSStefan Binding 				}
2318c4c216dSStefan Binding 				if (id == 1) {
2328c4c216dSStefan Binding 					spi_set_csgpiod(spi, 0, cs_gpiod);
2338c4c216dSStefan Binding 					cs35l41->cs_gpio = cs_gpiod;
2348c4c216dSStefan Binding 				} else {
2358c4c216dSStefan Binding 					gpiod_set_value_cansleep(cs_gpiod, true);
2368c4c216dSStefan Binding 					gpiod_put(cs_gpiod);
2378c4c216dSStefan Binding 				}
2388c4c216dSStefan Binding 				spi_setup(spi);
2398c4c216dSStefan Binding 			}
2408c4c216dSStefan Binding 		}
2418c4c216dSStefan Binding 	} else {
2428c4c216dSStefan Binding 		if (cfg->num_amps > 2)
2438c4c216dSStefan Binding 			/*
2448c4c216dSStefan Binding 			 * i2c addresses for 3/4 amps are used in order: 0x40, 0x41, 0x42, 0x43,
2458c4c216dSStefan Binding 			 * subtracting 0x40 would give zero-based index
2468c4c216dSStefan Binding 			 */
2478c4c216dSStefan Binding 			cs35l41->index = id - 0x40;
2488c4c216dSStefan Binding 		else
2498c4c216dSStefan Binding 			/* i2c addr 0x40 for first amp (always), 0x41/0x42 for 2nd amp */
2508c4c216dSStefan Binding 			cs35l41->index = id == 0x40 ? 0 : 1;
2518c4c216dSStefan Binding 	}
2528c4c216dSStefan Binding 
2538c4c216dSStefan Binding 	if (cfg->num_amps == 3)
2548c4c216dSStefan Binding 		/* 3 amps means a center channel, so no duplicate channels */
2558c4c216dSStefan Binding 		cs35l41->channel_index = 0;
2568c4c216dSStefan Binding 	else
2578c4c216dSStefan Binding 		/*
2588c4c216dSStefan Binding 		 * if 4 amps, there are duplicate channels, so they need different indexes
2598c4c216dSStefan Binding 		 * if 2 amps, no duplicate channels, channel_index would be 0
2608c4c216dSStefan Binding 		 */
2618c4c216dSStefan Binding 		cs35l41->channel_index = cs35l41->index / 2;
2628c4c216dSStefan Binding 
2638c4c216dSStefan Binding 	cs35l41->reset_gpio = fwnode_gpiod_get_index(acpi_fwnode_handle(cs35l41->dacpi), "reset",
2648c4c216dSStefan Binding 						     cs35l41->index, GPIOD_OUT_LOW,
2658c4c216dSStefan Binding 						     "cs35l41-reset");
2668c4c216dSStefan Binding 	cs35l41->speaker_id = cs35l41_get_speaker_id(physdev, cs35l41->index, cfg->num_amps, -1);
2678c4c216dSStefan Binding 
2688c4c216dSStefan Binding 	hw_cfg->spk_pos = cfg->channel[cs35l41->index];
2698c4c216dSStefan Binding 
2708c4c216dSStefan Binding 	if (cfg->boost_type == INTERNAL) {
2718c4c216dSStefan Binding 		hw_cfg->bst_type = CS35L41_INT_BOOST;
2728c4c216dSStefan Binding 		hw_cfg->bst_ind = cfg->boost_ind_nanohenry;
2738c4c216dSStefan Binding 		hw_cfg->bst_ipk = cfg->boost_peak_milliamp;
2748c4c216dSStefan Binding 		hw_cfg->bst_cap = cfg->boost_cap_microfarad;
2758c4c216dSStefan Binding 		hw_cfg->gpio1.func = CS35L41_NOT_USED;
2768c4c216dSStefan Binding 		hw_cfg->gpio1.valid = true;
2778c4c216dSStefan Binding 	} else {
2788c4c216dSStefan Binding 		hw_cfg->bst_type = CS35L41_EXT_BOOST;
2798c4c216dSStefan Binding 		hw_cfg->bst_ind = -1;
2808c4c216dSStefan Binding 		hw_cfg->bst_ipk = -1;
2818c4c216dSStefan Binding 		hw_cfg->bst_cap = -1;
2828c4c216dSStefan Binding 		hw_cfg->gpio1.func = CS35l41_VSPK_SWITCH;
2838c4c216dSStefan Binding 		hw_cfg->gpio1.valid = true;
2848c4c216dSStefan Binding 	}
2858c4c216dSStefan Binding 
2868c4c216dSStefan Binding 	hw_cfg->gpio2.func = CS35L41_INTERRUPT;
2878c4c216dSStefan Binding 	hw_cfg->gpio2.valid = true;
2888c4c216dSStefan Binding 	hw_cfg->valid = true;
2898c4c216dSStefan Binding 
2908c4c216dSStefan Binding 	return 0;
2918c4c216dSStefan Binding }
292ef4ba63fSStefan Binding 
293ef4ba63fSStefan Binding /*
294ef4ba63fSStefan Binding  * Device CLSA010(0/1) doesn't have _DSD so a gpiod_get by the label reset won't work.
295ef4ba63fSStefan Binding  * And devices created by serial-multi-instantiate don't have their device struct
296ef4ba63fSStefan Binding  * pointing to the correct fwnode, so acpi_dev must be used here.
297ef4ba63fSStefan Binding  * And devm functions expect that the device requesting the resource has the correct
298ef4ba63fSStefan Binding  * fwnode.
299ef4ba63fSStefan Binding  */
300ef4ba63fSStefan Binding static int lenovo_legion_no_acpi(struct cs35l41_hda *cs35l41, struct device *physdev, int id,
301ef4ba63fSStefan Binding 				 const char *hid)
302ef4ba63fSStefan Binding {
303ef4ba63fSStefan Binding 	struct cs35l41_hw_cfg *hw_cfg = &cs35l41->hw_cfg;
304ef4ba63fSStefan Binding 
305ef4ba63fSStefan Binding 	/* check I2C address to assign the index */
306ef4ba63fSStefan Binding 	cs35l41->index = id == 0x40 ? 0 : 1;
307ef4ba63fSStefan Binding 	cs35l41->channel_index = 0;
308ef4ba63fSStefan Binding 	cs35l41->reset_gpio = gpiod_get_index(physdev, NULL, 0, GPIOD_OUT_HIGH);
309ef4ba63fSStefan Binding 	cs35l41->speaker_id = cs35l41_get_speaker_id(physdev, 0, 0, 2);
310ef4ba63fSStefan Binding 	hw_cfg->spk_pos = cs35l41->index;
311ef4ba63fSStefan Binding 	hw_cfg->gpio2.func = CS35L41_INTERRUPT;
312ef4ba63fSStefan Binding 	hw_cfg->gpio2.valid = true;
313ef4ba63fSStefan Binding 	hw_cfg->valid = true;
314ef4ba63fSStefan Binding 
315ef4ba63fSStefan Binding 	if (strcmp(hid, "CLSA0100") == 0) {
316ef4ba63fSStefan Binding 		hw_cfg->bst_type = CS35L41_EXT_BOOST_NO_VSPK_SWITCH;
317ef4ba63fSStefan Binding 	} else if (strcmp(hid, "CLSA0101") == 0) {
318ef4ba63fSStefan Binding 		hw_cfg->bst_type = CS35L41_EXT_BOOST;
319ef4ba63fSStefan Binding 		hw_cfg->gpio1.func = CS35l41_VSPK_SWITCH;
320ef4ba63fSStefan Binding 		hw_cfg->gpio1.valid = true;
321ef4ba63fSStefan Binding 	}
322ef4ba63fSStefan Binding 
323ef4ba63fSStefan Binding 	return 0;
324ef4ba63fSStefan Binding }
325ef4ba63fSStefan Binding 
326ef4ba63fSStefan Binding struct cs35l41_prop_model {
327ef4ba63fSStefan Binding 	const char *hid;
328ef4ba63fSStefan Binding 	const char *ssid;
329ef4ba63fSStefan Binding 	int (*add_prop)(struct cs35l41_hda *cs35l41, struct device *physdev, int id,
330ef4ba63fSStefan Binding 			const char *hid);
331ef4ba63fSStefan Binding };
332ef4ba63fSStefan Binding 
3332e6f9790SYang Yingliang static const struct cs35l41_prop_model cs35l41_prop_model_table[] = {
334ef4ba63fSStefan Binding 	{ "CLSA0100", NULL, lenovo_legion_no_acpi },
335ef4ba63fSStefan Binding 	{ "CLSA0101", NULL, lenovo_legion_no_acpi },
3368c4c216dSStefan Binding 	{ "CSC3551", "103C89C6", generic_dsd_config },
337*b592ed2eSStefan Binding 	{ "CSC3551", "10431433", generic_dsd_config },
338*b592ed2eSStefan Binding 	{ "CSC3551", "10431463", generic_dsd_config },
339*b592ed2eSStefan Binding 	{ "CSC3551", "10431473", generic_dsd_config },
340*b592ed2eSStefan Binding 	{ "CSC3551", "10431483", generic_dsd_config },
341*b592ed2eSStefan Binding 	{ "CSC3551", "10431493", generic_dsd_config },
342*b592ed2eSStefan Binding 	{ "CSC3551", "104314D3", generic_dsd_config },
343*b592ed2eSStefan Binding 	{ "CSC3551", "104314E3", generic_dsd_config },
344*b592ed2eSStefan Binding 	{ "CSC3551", "10431503", generic_dsd_config },
345*b592ed2eSStefan Binding 	{ "CSC3551", "10431533", generic_dsd_config },
346*b592ed2eSStefan Binding 	{ "CSC3551", "10431573", generic_dsd_config },
347*b592ed2eSStefan Binding 	{ "CSC3551", "10431663", generic_dsd_config },
348*b592ed2eSStefan Binding 	{ "CSC3551", "104317F3", generic_dsd_config },
349*b592ed2eSStefan Binding 	{ "CSC3551", "10431C9F", generic_dsd_config },
350*b592ed2eSStefan Binding 	{ "CSC3551", "10431CAF", generic_dsd_config },
351*b592ed2eSStefan Binding 	{ "CSC3551", "10431CCF", generic_dsd_config },
352*b592ed2eSStefan Binding 	{ "CSC3551", "10431CDF", generic_dsd_config },
353*b592ed2eSStefan Binding 	{ "CSC3551", "10431CEF", generic_dsd_config },
354*b592ed2eSStefan Binding 	{ "CSC3551", "10431D1F", generic_dsd_config },
355ef4ba63fSStefan Binding 	{}
356ef4ba63fSStefan Binding };
357ef4ba63fSStefan Binding 
358ef4ba63fSStefan Binding int cs35l41_add_dsd_properties(struct cs35l41_hda *cs35l41, struct device *physdev, int id,
359ef4ba63fSStefan Binding 			       const char *hid)
360ef4ba63fSStefan Binding {
361ef4ba63fSStefan Binding 	const struct cs35l41_prop_model *model;
362ef4ba63fSStefan Binding 
36340989679STakashi Iwai 	for (model = cs35l41_prop_model_table; model->hid; model++) {
364ef4ba63fSStefan Binding 		if (!strcmp(model->hid, hid) &&
365ef4ba63fSStefan Binding 		    (!model->ssid ||
366ef4ba63fSStefan Binding 		     (cs35l41->acpi_subsystem_id &&
3678c4c216dSStefan Binding 		      !strcasecmp(model->ssid, cs35l41->acpi_subsystem_id))))
368ef4ba63fSStefan Binding 			return model->add_prop(cs35l41, physdev, id, hid);
369ef4ba63fSStefan Binding 	}
370ef4ba63fSStefan Binding 
371ef4ba63fSStefan Binding 	return -ENOENT;
372ef4ba63fSStefan Binding }
373