Path: blob/master/sound/hda/codecs/side-codecs/cs35l41_hda_property.c
29268 views
// SPDX-License-Identifier: GPL-2.01//2// CS35L41 ALSA HDA Property driver3//4// Copyright 2023 Cirrus Logic, Inc.5//6// Author: Stefan Binding <[email protected]>78#include <linux/acpi.h>9#include <linux/gpio/consumer.h>10#include <linux/string.h>11#include "cs35l41_hda_property.h"12#include <linux/spi/spi.h>1314#define MAX_AMPS 41516struct cs35l41_config {17const char *ssid;18int num_amps;19enum {20INTERNAL,21EXTERNAL22} boost_type;23u8 channel[MAX_AMPS];24int reset_gpio_index; /* -1 if no reset gpio */25int spkid_gpio_index; /* -1 if no spkid gpio */26int cs_gpio_index; /* -1 if no cs gpio, or cs-gpios already exists, max num amps == 2 */27int boost_ind_nanohenry; /* Required if boost_type == Internal */28int boost_peak_milliamp; /* Required if boost_type == Internal */29int boost_cap_microfarad; /* Required if boost_type == Internal */30};3132static const struct cs35l41_config cs35l41_config_table[] = {33{ "10251826", 2, EXTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, -1, -1, 0, 0, 0 },34{ "1025182C", 2, EXTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, -1, -1, 0, 0, 0 },35{ "10251844", 2, EXTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, -1, -1, 0, 0, 0 },36{ "10280B27", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 1000, 4500, 24 },37{ "10280B28", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 1000, 4500, 24 },38{ "10280BEB", 2, EXTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, -1, 0, 0, 0, 0 },39{ "10280C4D", 4, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, CS35L41_LEFT, CS35L41_RIGHT }, 0, 1, -1, 1000, 4500, 24 },40/*41* Device 103C89C6 does have _DSD, however it is setup to use the wrong boost type.42* We can override the _DSD to correct the boost type here.43* Since this laptop has valid ACPI, we do not need to handle cs-gpios, since that already exists44* in the ACPI. The Reset GPIO is also valid, so we can use the Reset defined in _DSD.45*/46{ "103C89C6", 2, INTERNAL, { CS35L41_RIGHT, CS35L41_LEFT, 0, 0 }, -1, -1, -1, 1000, 4500, 24 },47{ "103C8A28", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },48{ "103C8A29", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },49{ "103C8A2A", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },50{ "103C8A2B", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },51{ "103C8A2C", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },52{ "103C8A2D", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },53{ "103C8A2E", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },54{ "103C8A30", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },55{ "103C8A31", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },56{ "103C8A6E", 4, EXTERNAL, { CS35L41_LEFT, CS35L41_LEFT, CS35L41_RIGHT, CS35L41_RIGHT }, 0, -1, -1, 0, 0, 0 },57{ "103C8BB3", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },58{ "103C8BB4", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },59{ "103C8BDD", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },60{ "103C8BDE", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },61{ "103C8BDF", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },62{ "103C8BE0", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },63{ "103C8BE1", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },64{ "103C8BE2", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },65{ "103C8BE3", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },66{ "103C8BE5", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },67{ "103C8BE6", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },68{ "103C8BE7", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },69{ "103C8BE8", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },70{ "103C8BE9", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },71{ "103C8B3A", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },72{ "103C8C15", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4000, 24 },73{ "103C8C16", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4000, 24 },74{ "103C8C17", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4000, 24 },75{ "103C8C4D", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },76{ "103C8C4E", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },77{ "103C8C4F", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },78{ "103C8C50", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },79{ "103C8C51", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },80{ "103C8CDD", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },81{ "103C8CDE", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 3900, 24 },82{ "104312AF", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 1000, 4500, 24 },83{ "10431433", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4500, 24 },84{ "10431463", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4500, 24 },85{ "10431473", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, -1, 0, 1000, 4500, 24 },86{ "10431483", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, -1, 0, 1000, 4500, 24 },87{ "10431493", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 1000, 4500, 24 },88{ "104314D3", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 1000, 4500, 24 },89{ "104314E3", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4500, 24 },90{ "10431503", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4500, 24 },91{ "10431533", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4500, 24 },92{ "10431573", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 1000, 4500, 24 },93{ "10431663", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, -1, 0, 1000, 4500, 24 },94{ "10431683", 2, EXTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 0, 0, 0 },95{ "104316A3", 2, EXTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 0, 0, 0 },96{ "104316D3", 2, EXTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 0, 0, 0 },97{ "104316F3", 2, EXTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 0, 0, 0 },98{ "104317F3", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4500, 24 },99{ "10431863", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 1000, 4500, 24 },100{ "104318D3", 2, EXTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 0, 0, 0 },101{ "10431A83", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4500, 24 },102{ "10431B93", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 1000, 4500, 24 },103{ "10431C9F", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 1000, 4500, 24 },104{ "10431CAF", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 1000, 4500, 24 },105{ "10431CCF", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 1000, 4500, 24 },106{ "10431CDF", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 1000, 4500, 24 },107{ "10431CEF", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 1000, 4500, 24 },108{ "10431D1F", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4500, 24 },109{ "10431DA2", 2, EXTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 0, 0, 0 },110{ "10431E02", 2, EXTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 0, 0, 0 },111{ "10431E12", 2, EXTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 0, 0, 0 },112{ "10431EE2", 2, EXTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, -1, -1, 0, 0, 0 },113{ "10431F12", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4500, 24 },114{ "10431F1F", 2, EXTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, -1, 0, 0, 0, 0 },115{ "10431F62", 2, EXTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 0, 0, 0 },116{ "10433A20", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 1000, 4500, 24 },117{ "10433A30", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 1000, 4500, 24 },118{ "10433A40", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 1000, 4500, 24 },119{ "10433A50", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 1000, 4500, 24 },120{ "10433A60", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 1000, 4500, 24 },121{ "17AA3865", 2, EXTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, -1, -1, 0, 0, 0 },122{ "17AA3866", 2, EXTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, -1, -1, 0, 0, 0 },123{ "17AA386E", 2, EXTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 2, -1, 0, 0, 0 },124{ "17AA386F", 2, EXTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, -1, -1, 0, 0, 0 },125{ "17AA3877", 2, EXTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, -1, -1, 0, 0, 0 },126{ "17AA3878", 2, EXTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, -1, -1, 0, 0, 0 },127{ "17AA38A9", 2, EXTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 2, -1, 0, 0, 0 },128{ "17AA38AB", 2, EXTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 2, -1, 0, 0, 0 },129{ "17AA38B4", 2, EXTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 0, 0, 0 },130{ "17AA38B5", 2, EXTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 0, 0, 0 },131{ "17AA38B6", 2, EXTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 0, 0, 0 },132{ "17AA38B7", 2, EXTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 0, 0, 0 },133{ "17AA38C7", 4, INTERNAL, { CS35L41_RIGHT, CS35L41_LEFT, CS35L41_RIGHT, CS35L41_LEFT }, 0, 2, -1, 1000, 4500, 24 },134{ "17AA38C8", 4, INTERNAL, { CS35L41_RIGHT, CS35L41_LEFT, CS35L41_RIGHT, CS35L41_LEFT }, 0, 2, -1, 1000, 4500, 24 },135{ "17AA38F9", 2, EXTERNAL, { CS35L41_RIGHT, CS35L41_LEFT, 0, 0 }, 0, 2, -1, 0, 0, 0 },136{ "17AA38FA", 2, EXTERNAL, { CS35L41_RIGHT, CS35L41_LEFT, 0, 0 }, 0, 2, -1, 0, 0, 0 },137{ "17AA3929", 4, INTERNAL, { CS35L41_RIGHT, CS35L41_LEFT, CS35L41_RIGHT, CS35L41_LEFT }, 0, 2, -1, 1000, 4500, 24 },138{ "17AA392B", 4, INTERNAL, { CS35L41_RIGHT, CS35L41_LEFT, CS35L41_RIGHT, CS35L41_LEFT }, 0, 2, -1, 1000, 4500, 24 },139{}140};141142static int cs35l41_add_gpios(struct cs35l41_hda *cs35l41, struct device *physdev, int reset_gpio,143int spkid_gpio, int cs_gpio_index, int num_amps)144{145struct acpi_gpio_mapping *gpio_mapping = NULL;146struct acpi_gpio_params *reset_gpio_params = NULL;147struct acpi_gpio_params *spkid_gpio_params = NULL;148struct acpi_gpio_params *cs_gpio_params = NULL;149unsigned int num_entries = 0;150unsigned int reset_index, spkid_index, csgpio_index;151int i;152153/*154* GPIO Mapping only needs to be done once, since it would be available for subsequent amps155*/156if (cs35l41->dacpi->driver_gpios)157return 0;158159if (reset_gpio >= 0) {160reset_index = num_entries;161num_entries++;162}163164if (spkid_gpio >= 0) {165spkid_index = num_entries;166num_entries++;167}168169if ((cs_gpio_index >= 0) && (num_amps == 2)) {170csgpio_index = num_entries;171num_entries++;172}173174if (!num_entries)175return 0;176177/* must include termination entry */178num_entries++;179180gpio_mapping = devm_kcalloc(physdev, num_entries, sizeof(struct acpi_gpio_mapping),181GFP_KERNEL);182183if (!gpio_mapping)184goto err;185186if (reset_gpio >= 0) {187gpio_mapping[reset_index].name = "reset-gpios";188reset_gpio_params = devm_kcalloc(physdev, num_amps, sizeof(struct acpi_gpio_params),189GFP_KERNEL);190if (!reset_gpio_params)191goto err;192193for (i = 0; i < num_amps; i++)194reset_gpio_params[i].crs_entry_index = reset_gpio;195196gpio_mapping[reset_index].data = reset_gpio_params;197gpio_mapping[reset_index].size = num_amps;198}199200if (spkid_gpio >= 0) {201gpio_mapping[spkid_index].name = "spk-id-gpios";202spkid_gpio_params = devm_kcalloc(physdev, num_amps, sizeof(struct acpi_gpio_params),203GFP_KERNEL);204if (!spkid_gpio_params)205goto err;206207for (i = 0; i < num_amps; i++)208spkid_gpio_params[i].crs_entry_index = spkid_gpio;209210gpio_mapping[spkid_index].data = spkid_gpio_params;211gpio_mapping[spkid_index].size = num_amps;212}213214if ((cs_gpio_index >= 0) && (num_amps == 2)) {215gpio_mapping[csgpio_index].name = "cs-gpios";216/* only one GPIO CS is supported without using _DSD, obtained using index 0 */217cs_gpio_params = devm_kzalloc(physdev, sizeof(struct acpi_gpio_params), GFP_KERNEL);218if (!cs_gpio_params)219goto err;220221cs_gpio_params->crs_entry_index = cs_gpio_index;222223gpio_mapping[csgpio_index].data = cs_gpio_params;224gpio_mapping[csgpio_index].size = 1;225}226227return devm_acpi_dev_add_driver_gpios(physdev, gpio_mapping);228err:229devm_kfree(physdev, gpio_mapping);230devm_kfree(physdev, reset_gpio_params);231devm_kfree(physdev, spkid_gpio_params);232devm_kfree(physdev, cs_gpio_params);233return -ENOMEM;234}235236static int generic_dsd_config(struct cs35l41_hda *cs35l41, struct device *physdev, int id,237const char *hid)238{239struct cs35l41_hw_cfg *hw_cfg = &cs35l41->hw_cfg;240const struct cs35l41_config *cfg;241struct gpio_desc *cs_gpiod;242struct spi_device *spi;243bool dsd_found;244int ret;245int i;246247for (cfg = cs35l41_config_table; cfg->ssid; cfg++) {248if (!strcasecmp(cfg->ssid, cs35l41->acpi_subsystem_id))249break;250}251252if (!cfg->ssid)253return -ENOENT;254255if (!cs35l41->dacpi || cs35l41->dacpi != ACPI_COMPANION(physdev)) {256dev_err(cs35l41->dev, "ACPI Device does not match, cannot override _DSD.\n");257return -ENODEV;258}259260dev_info(cs35l41->dev, "Adding DSD properties for %s\n", cs35l41->acpi_subsystem_id);261262dsd_found = acpi_dev_has_props(cs35l41->dacpi);263264if (!dsd_found) {265ret = cs35l41_add_gpios(cs35l41, physdev, cfg->reset_gpio_index,266cfg->spkid_gpio_index, cfg->cs_gpio_index,267cfg->num_amps);268if (ret) {269dev_err(cs35l41->dev, "Error adding GPIO mapping: %d\n", ret);270return ret;271}272} else if (cfg->reset_gpio_index >= 0 || cfg->spkid_gpio_index >= 0) {273dev_warn(cs35l41->dev, "Cannot add Reset/Speaker ID/SPI CS GPIO Mapping, "274"_DSD already exists.\n");275}276277if (cs35l41->control_bus == SPI) {278cs35l41->index = id;279280/*281* Manually set the Chip Select for the second amp <cs_gpio_index> in the node.282* This is only supported for systems with 2 amps, since we cannot expand the283* default number of chip selects without using cs-gpios284* The CS GPIO must be set high prior to communicating with the first amp (which285* uses a native chip select), to ensure the second amp does not clash with the286* first.287*/288if (IS_ENABLED(CONFIG_SPI) && cfg->cs_gpio_index >= 0) {289spi = to_spi_device(cs35l41->dev);290291if (cfg->num_amps != 2) {292dev_warn(cs35l41->dev,293"Cannot update SPI CS, Number of Amps (%d) != 2\n",294cfg->num_amps);295} else if (dsd_found) {296dev_warn(cs35l41->dev,297"Cannot update SPI CS, _DSD already exists.\n");298} else {299/*300* This is obtained using driver_gpios, since only one GPIO for CS301* exists, this can be obtained using index 0.302*/303cs_gpiod = gpiod_get_index(physdev, "cs", 0, GPIOD_OUT_LOW);304if (IS_ERR(cs_gpiod)) {305dev_err(cs35l41->dev,306"Unable to get Chip Select GPIO descriptor\n");307return PTR_ERR(cs_gpiod);308}309if (id == 1) {310spi_set_csgpiod(spi, 0, cs_gpiod);311cs35l41->cs_gpio = cs_gpiod;312} else {313gpiod_set_value_cansleep(cs_gpiod, true);314gpiod_put(cs_gpiod);315}316spi_setup(spi);317}318}319} else {320if (cfg->num_amps > 2)321/*322* i2c addresses for 3/4 amps are used in order: 0x40, 0x41, 0x42, 0x43,323* subtracting 0x40 would give zero-based index324*/325cs35l41->index = id - 0x40;326else327/* i2c addr 0x40 for first amp (always), 0x41/0x42 for 2nd amp */328cs35l41->index = id == 0x40 ? 0 : 1;329}330331cs35l41->reset_gpio = fwnode_gpiod_get_index(acpi_fwnode_handle(cs35l41->dacpi), "reset",332cs35l41->index, GPIOD_OUT_LOW,333"cs35l41-reset");334cs35l41->speaker_id = cs35l41_get_speaker_id(physdev, cs35l41->index, cfg->num_amps, -1);335336hw_cfg->spk_pos = cfg->channel[cs35l41->index];337338cs35l41->channel_index = 0;339for (i = 0; i < cs35l41->index; i++)340if (cfg->channel[i] == hw_cfg->spk_pos)341cs35l41->channel_index++;342343if (cfg->boost_type == INTERNAL) {344hw_cfg->bst_type = CS35L41_INT_BOOST;345hw_cfg->bst_ind = cfg->boost_ind_nanohenry;346hw_cfg->bst_ipk = cfg->boost_peak_milliamp;347hw_cfg->bst_cap = cfg->boost_cap_microfarad;348hw_cfg->gpio1.func = CS35L41_NOT_USED;349hw_cfg->gpio1.valid = true;350} else {351hw_cfg->bst_type = CS35L41_EXT_BOOST;352hw_cfg->bst_ind = -1;353hw_cfg->bst_ipk = -1;354hw_cfg->bst_cap = -1;355hw_cfg->gpio1.func = CS35l41_VSPK_SWITCH;356hw_cfg->gpio1.valid = true;357}358359hw_cfg->gpio2.func = CS35L41_INTERRUPT;360hw_cfg->gpio2.valid = true;361hw_cfg->valid = true;362363return 0;364}365366/*367* Systems 103C8C66, 103C8C67, 103C8C68, 103C8C6A use a dual speaker id system - each speaker has368* its own speaker id.369*/370static int hp_i2c_int_2amp_dual_spkid(struct cs35l41_hda *cs35l41, struct device *physdev, int id,371const char *hid)372{373struct cs35l41_hw_cfg *hw_cfg = &cs35l41->hw_cfg;374375/* If _DSD exists for this laptop, we cannot support it through here */376if (acpi_dev_has_props(cs35l41->dacpi))377return -ENOENT;378379/* check I2C address to assign the index */380cs35l41->index = id == 0x40 ? 0 : 1;381cs35l41->channel_index = 0;382cs35l41->reset_gpio = gpiod_get_index(physdev, NULL, 0, GPIOD_OUT_HIGH);383if (cs35l41->index == 0)384cs35l41->speaker_id = cs35l41_get_speaker_id(physdev, 0, 0, 1);385else386cs35l41->speaker_id = cs35l41_get_speaker_id(physdev, 0, 0, 2);387hw_cfg->spk_pos = cs35l41->index;388hw_cfg->gpio2.func = CS35L41_INTERRUPT;389hw_cfg->gpio2.valid = true;390hw_cfg->valid = true;391392hw_cfg->bst_type = CS35L41_INT_BOOST;393hw_cfg->bst_ind = 1000;394hw_cfg->bst_ipk = 4100;395hw_cfg->bst_cap = 24;396hw_cfg->gpio1.func = CS35L41_NOT_USED;397hw_cfg->gpio1.valid = true;398399return 0;400}401402/*403* Device CLSA010(0/1) doesn't have _DSD so a gpiod_get by the label reset won't work.404* And devices created by serial-multi-instantiate don't have their device struct405* pointing to the correct fwnode, so acpi_dev must be used here.406* And devm functions expect that the device requesting the resource has the correct407* fwnode.408*/409static int lenovo_legion_no_acpi(struct cs35l41_hda *cs35l41, struct device *physdev, int id,410const char *hid)411{412struct cs35l41_hw_cfg *hw_cfg = &cs35l41->hw_cfg;413414/* check I2C address to assign the index */415cs35l41->index = id == 0x40 ? 0 : 1;416cs35l41->channel_index = 0;417cs35l41->reset_gpio = gpiod_get_index(physdev, NULL, 0, GPIOD_OUT_HIGH);418cs35l41->speaker_id = cs35l41_get_speaker_id(physdev, 0, 0, 2);419hw_cfg->spk_pos = cs35l41->index;420hw_cfg->gpio2.func = CS35L41_INTERRUPT;421hw_cfg->gpio2.valid = true;422hw_cfg->valid = true;423424if (strcmp(hid, "CLSA0100") == 0) {425hw_cfg->bst_type = CS35L41_EXT_BOOST_NO_VSPK_SWITCH;426} else if (strcmp(hid, "CLSA0101") == 0) {427hw_cfg->bst_type = CS35L41_EXT_BOOST;428hw_cfg->gpio1.func = CS35l41_VSPK_SWITCH;429hw_cfg->gpio1.valid = true;430}431432return 0;433}434435static int missing_speaker_id_gpio2(struct cs35l41_hda *cs35l41, struct device *physdev, int id,436const char *hid)437{438int ret;439440ret = cs35l41_add_gpios(cs35l41, physdev, -1, 2, -1, 2);441if (ret) {442dev_err(cs35l41->dev, "Error adding GPIO mapping: %d\n", ret);443return ret;444}445446return cs35l41_hda_parse_acpi(cs35l41, physdev, id);447}448449struct cs35l41_prop_model {450const char *hid;451const char *ssid;452int (*add_prop)(struct cs35l41_hda *cs35l41, struct device *physdev, int id,453const char *hid);454};455456static const struct cs35l41_prop_model cs35l41_prop_model_table[] = {457{ "CLSA0100", NULL, lenovo_legion_no_acpi },458{ "CLSA0101", NULL, lenovo_legion_no_acpi },459{ "CSC3551", "10251826", generic_dsd_config },460{ "CSC3551", "1025182C", generic_dsd_config },461{ "CSC3551", "10251844", generic_dsd_config },462{ "CSC3551", "10280B27", generic_dsd_config },463{ "CSC3551", "10280B28", generic_dsd_config },464{ "CSC3551", "10280BEB", generic_dsd_config },465{ "CSC3551", "10280C4D", generic_dsd_config },466{ "CSC3551", "103C89C6", generic_dsd_config },467{ "CSC3551", "103C8A28", generic_dsd_config },468{ "CSC3551", "103C8A29", generic_dsd_config },469{ "CSC3551", "103C8A2A", generic_dsd_config },470{ "CSC3551", "103C8A2B", generic_dsd_config },471{ "CSC3551", "103C8A2C", generic_dsd_config },472{ "CSC3551", "103C8A2D", generic_dsd_config },473{ "CSC3551", "103C8A2E", generic_dsd_config },474{ "CSC3551", "103C8A30", generic_dsd_config },475{ "CSC3551", "103C8A31", generic_dsd_config },476{ "CSC3551", "103C8A6E", generic_dsd_config },477{ "CSC3551", "103C8BB3", generic_dsd_config },478{ "CSC3551", "103C8BB4", generic_dsd_config },479{ "CSC3551", "103C8BDD", generic_dsd_config },480{ "CSC3551", "103C8BDE", generic_dsd_config },481{ "CSC3551", "103C8BDF", generic_dsd_config },482{ "CSC3551", "103C8BE0", generic_dsd_config },483{ "CSC3551", "103C8BE1", generic_dsd_config },484{ "CSC3551", "103C8BE2", generic_dsd_config },485{ "CSC3551", "103C8BE3", generic_dsd_config },486{ "CSC3551", "103C8BE5", generic_dsd_config },487{ "CSC3551", "103C8BE6", generic_dsd_config },488{ "CSC3551", "103C8BE7", generic_dsd_config },489{ "CSC3551", "103C8BE8", generic_dsd_config },490{ "CSC3551", "103C8BE9", generic_dsd_config },491{ "CSC3551", "103C8B3A", generic_dsd_config },492{ "CSC3551", "103C8C15", generic_dsd_config },493{ "CSC3551", "103C8C16", generic_dsd_config },494{ "CSC3551", "103C8C17", generic_dsd_config },495{ "CSC3551", "103C8C4D", generic_dsd_config },496{ "CSC3551", "103C8C4E", generic_dsd_config },497{ "CSC3551", "103C8C4F", generic_dsd_config },498{ "CSC3551", "103C8C50", generic_dsd_config },499{ "CSC3551", "103C8C51", generic_dsd_config },500{ "CSC3551", "103C8C66", hp_i2c_int_2amp_dual_spkid },501{ "CSC3551", "103C8C67", hp_i2c_int_2amp_dual_spkid },502{ "CSC3551", "103C8C68", hp_i2c_int_2amp_dual_spkid },503{ "CSC3551", "103C8C6A", hp_i2c_int_2amp_dual_spkid },504{ "CSC3551", "103C8CDD", generic_dsd_config },505{ "CSC3551", "103C8CDE", generic_dsd_config },506{ "CSC3551", "104312AF", generic_dsd_config },507{ "CSC3551", "10431433", generic_dsd_config },508{ "CSC3551", "10431463", generic_dsd_config },509{ "CSC3551", "10431473", generic_dsd_config },510{ "CSC3551", "10431483", generic_dsd_config },511{ "CSC3551", "10431493", generic_dsd_config },512{ "CSC3551", "104314D3", generic_dsd_config },513{ "CSC3551", "104314E3", generic_dsd_config },514{ "CSC3551", "10431503", generic_dsd_config },515{ "CSC3551", "10431533", generic_dsd_config },516{ "CSC3551", "10431573", generic_dsd_config },517{ "CSC3551", "10431663", generic_dsd_config },518{ "CSC3551", "10431683", generic_dsd_config },519{ "CSC3551", "104316A3", generic_dsd_config },520{ "CSC3551", "104316D3", generic_dsd_config },521{ "CSC3551", "104316F3", generic_dsd_config },522{ "CSC3551", "104317F3", generic_dsd_config },523{ "CSC3551", "10431863", generic_dsd_config },524{ "CSC3551", "104318D3", generic_dsd_config },525{ "CSC3551", "10431A63", missing_speaker_id_gpio2 },526{ "CSC3551", "10431A83", generic_dsd_config },527{ "CSC3551", "10431B93", generic_dsd_config },528{ "CSC3551", "10431C9F", generic_dsd_config },529{ "CSC3551", "10431CAF", generic_dsd_config },530{ "CSC3551", "10431CCF", generic_dsd_config },531{ "CSC3551", "10431CDF", generic_dsd_config },532{ "CSC3551", "10431CEF", generic_dsd_config },533{ "CSC3551", "10431D1F", generic_dsd_config },534{ "CSC3551", "10431DA2", generic_dsd_config },535{ "CSC3551", "10431E02", generic_dsd_config },536{ "CSC3551", "10431E12", generic_dsd_config },537{ "CSC3551", "10431EE2", generic_dsd_config },538{ "CSC3551", "10431F12", generic_dsd_config },539{ "CSC3551", "10431F1F", generic_dsd_config },540{ "CSC3551", "10431F62", generic_dsd_config },541{ "CSC3551", "10433A20", generic_dsd_config },542{ "CSC3551", "10433A30", generic_dsd_config },543{ "CSC3551", "10433A40", generic_dsd_config },544{ "CSC3551", "10433A50", generic_dsd_config },545{ "CSC3551", "10433A60", generic_dsd_config },546{ "CSC3551", "17AA3865", generic_dsd_config },547{ "CSC3551", "17AA3866", generic_dsd_config },548{ "CSC3551", "17AA386E", generic_dsd_config },549{ "CSC3551", "17AA386F", generic_dsd_config },550{ "CSC3551", "17AA3877", generic_dsd_config },551{ "CSC3551", "17AA3878", generic_dsd_config },552{ "CSC3551", "17AA38A9", generic_dsd_config },553{ "CSC3551", "17AA38AB", generic_dsd_config },554{ "CSC3551", "17AA38B4", generic_dsd_config },555{ "CSC3551", "17AA38B5", generic_dsd_config },556{ "CSC3551", "17AA38B6", generic_dsd_config },557{ "CSC3551", "17AA38B7", generic_dsd_config },558{ "CSC3551", "17AA38C7", generic_dsd_config },559{ "CSC3551", "17AA38C8", generic_dsd_config },560{ "CSC3551", "17AA38F9", generic_dsd_config },561{ "CSC3551", "17AA38FA", generic_dsd_config },562{ "CSC3551", "17AA3929", generic_dsd_config },563{ "CSC3551", "17AA392B", generic_dsd_config },564{}565};566567int cs35l41_add_dsd_properties(struct cs35l41_hda *cs35l41, struct device *physdev, int id,568const char *hid)569{570const struct cs35l41_prop_model *model;571572for (model = cs35l41_prop_model_table; model->hid; model++) {573if (!strcmp(model->hid, hid) &&574(!model->ssid ||575(cs35l41->acpi_subsystem_id &&576!strcasecmp(model->ssid, cs35l41->acpi_subsystem_id))))577return model->add_prop(cs35l41, physdev, id, hid);578}579580return -ENOENT;581}582583584