From patchwork Thu Jul 13 16:29:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Xu X-Patchwork-Id: 703555 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 44B7BEB64DA for ; Sun, 16 Jul 2023 12:59:18 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 51584DEC; Sun, 16 Jul 2023 14:58:26 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 51584DEC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1689512356; bh=SZnIex+QsNXlpyXMzh6DjnwSWd4f8PPT0xYp7eyEjcI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=l6/TI5BZR0X7So1RayrPX2rVax37ANf0hkdTVIPd2B830fvrid7MyYVYpwD+tuwmB oMfPhReD+UxnLrBgt5otLdgMFYrJatSMlzNg/xC8MoJb8lP4yFpS9U0Hu4HEZTt9dT +5YnTxuT4quJDvb9wRft1gIaCPk7+lyPotvPAKko= Received: by alsa1.perex.cz (Postfix, from userid 50401) id 48BFDF80551; Sun, 16 Jul 2023 14:57:37 +0200 (CEST) Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id F2419F80564; Sun, 16 Jul 2023 14:57:36 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 8E34AF8027B; Thu, 13 Jul 2023 18:30:41 +0200 (CEST) Received: from AUS01-SY4-obe.outbound.protection.outlook.com (mail-sy4aus01olkn2081d.outbound.protection.outlook.com [IPv6:2a01:111:f403:7005::81d]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 90335F80236 for ; Thu, 13 Jul 2023 18:30:27 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 90335F80236 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=hotmail.com header.i=@hotmail.com header.a=rsa-sha256 header.s=selector1 header.b=N2yZ8FQz ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PyCZ5Gl8c90W6Ti0BMCHw0nCCbAwUw3jMqzgZ96NChZ5jyptAQG1tGwFSXY6Eqm3EK7lA7rJXn5yL+CVyLOR4gSl0sHJdn5BF7e/qdRlTLjPCL2dPkVCnh4U1j8iUAf/MpxA+YLdu16q03n8Bs51xRjhDh5DzSxuSWwjQeZt3xmxaD0PTeZNMM4dxAMp5WNDBmhH3HhYkGT4HdhpnHvGgVcdGq2pBh210L+wEmEx/S4pzcj4DzXOrrBDE0hmjF18D9Ak8dabXBYS8cN3MNlk1z2EFAIdI85rmAiD8frtt0kmALFBxyUPJl1AU82NlcUc+klqOqE/f+Ig/jGWWjvolQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=MiM5ACtRKWyqpRJouSb0PfBWJyX5BGcnRrnlOufDi78=; b=fdLJVYjzZLjUiHUguAxDc3P6RI9Rdf/kwJBmFrAVYHvWJoE06gmeAIDWXhQ7v8bDnE/5qNkBUI6EtL3BdyLFQoZRitkNk7Hchu72mc69S4Ij+lgdaLEDKwAMtqWpv94bD0Gvsj8qUuHVx7sRh7hOSDmxiW/hmvNiLAlUX6jPCRvWA0IzKn8mVTnOYGybZB6plvCH+WeHlZqpGqbklULIZZ29Hpfkr66dnwFLdnq16cyHeQSDqcmw+5+pU6c87NpjIAFSsmA4UvCH0DOTOLJjZkBRTiaABYmBzq/Ihp104IDxoloauWce9/Hp5dvV5IGMMtQ3RFglGN+Aw/l7G59IWQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hotmail.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=MiM5ACtRKWyqpRJouSb0PfBWJyX5BGcnRrnlOufDi78=; b=N2yZ8FQzj5U5u9H5Bg/DMkEJ4VJB0tXASoZkT1zoF7t2/vk9g6NX5OIXHiG1JbBVwkt6TqRpKA8Hp3e1P2JvP+eACls4p7nQCM2Xj3p6Ju3h18IQJU/fdKm9/3nUcBKdfbvXnQ04zazNCi1NVP0K/EtzOhHyOATkEpHf1AzsNfO+YYcJsetYgoeIZTVlUVO9whA99Ghi57r9XohamIM6P4MfGufqqAvkpNl5utUJkzAH2/nRCvaBqUCXq/jaRaM1VH2jfDKsJA9LmqhZrZ6kcJyJyaMuys7fYh3JwFnmdFOyfp5KYKXnZ25kQ4Ci6ZafwvKGLUQTKmx8jYyv2mqwgQ== Received: from SY4P282MB1835.AUSP282.PROD.OUTLOOK.COM (2603:10c6:10:c2::7) by SY6P282MB3254.AUSP282.PROD.OUTLOOK.COM (2603:10c6:10:165::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6588.26; Thu, 13 Jul 2023 16:30:22 +0000 Received: from SY4P282MB1835.AUSP282.PROD.OUTLOOK.COM ([fe80::8302:9e75:933d:b45]) by SY4P282MB1835.AUSP282.PROD.OUTLOOK.COM ([fe80::8302:9e75:933d:b45%6]) with mapi id 15.20.6588.024; Thu, 13 Jul 2023 16:30:22 +0000 From: David Xu To: James Schulman , David Rhodes , Richard Fitzgerald , Jaroslav Kysela , Takashi Iwai , "Luke D. Jones" , Stefan Binding , Andy Chi , Tim Crawford , Philipp Jungkamp , =?utf-8?q?Kacper_Michaj=C5=82ow?= , Matthew Anderson , Yuchi Yang , Yang Yingliang Cc: alsa-devel@alsa-project.org, patches@opensource.cirrus.com, linux-kernel@vger.kernel.org, David Xu Subject: [PATCH 1/2] ALSA: hda: cs35l41: Add fixups for machines without a valid ACPI _DSD Date: Fri, 14 Jul 2023 00:29:54 +0800 Message-ID: X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230713162955.34842-1-xuwd1@hotmail.com> References: <20230713162955.34842-1-xuwd1@hotmail.com> X-TMN: [hbySzE1Zt0HvzUIL2UX2tmwwydk0chI6] X-ClientProxiedBy: TYCP286CA0125.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:2b6::7) To SY4P282MB1835.AUSP282.PROD.OUTLOOK.COM (2603:10c6:10:c2::7) X-Microsoft-Original-Message-ID: <20230713162955.34842-2-xuwd1@hotmail.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SY4P282MB1835:EE_|SY6P282MB3254:EE_ X-MS-Office365-Filtering-Correlation-Id: 887fdd23-6430-4030-d2a2-08db83be746e X-MS-Exchange-SLBlob-MailProps: ZILSnhm0P3nN7ksDdJHhaEOcm48SSgzZjv94jAYU0fOIaN55HYBXz8rNf4ql+HrcD7unreFICMNmCvkFHDmrIaPQyTFWpoJDISvWK0uV5lRXh1AuwJG+0vvgT+CvxX619X4TMOU+RwffVwmLPVqZ3tUsk6txqPl5+X8QDlFS/+yX+3IZhDw/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OcKeuI9/rsIlxuOLvVZ8QLss6OERR5eJV8n8VNHPPl9vAXqBexJ9J+h7NABt3tPCeK9vdJLbzInA6An//jLXFyYWAKF+6iMxZgj86k0lq3/yvEySUesuBRQ9rt4GRcI0ftuoXIzKYrJb4/3mYflLa3lwofUfVFrZevBbYLf7tyeFZJAibXm8CIGlNivzUQ+QYPSh2aLnvSlmfs6t6hDFgcYSBEy4U7bE1RodZfgDVvdkSt+zLpI6nsDW4d3aYFdExCqMTEm2ZQohLiYec/3KaSr7nZdqFMLUnB+WLHJ6nowsujL+S0oNgtGJSkHuhbsL3Sr1gAuwjLWQ3cuY7BjqqplXYi8Z35aILHEWdZBqPFwSVA8Ad7IQNZfv4yIS7JNwDb6/oj3kQ7ydHgheDY+kAfWOgu7wVKIRzqXMoVHC4Dbvtxg== X-OriginatorOrg: sct-15-20-4755-11-msonline-outlook-746f3.templateTenant X-MS-Exchange-CrossTenant-Network-Message-Id: 887fdd23-6430-4030-d2a2-08db83be746e X-MS-Exchange-CrossTenant-AuthSource: SY4P282MB1835.AUSP282.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jul 2023 16:30:22.6508 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SY6P282MB3254 X-MailFrom: xuwd1@hotmail.com X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-alsa-devel.alsa-project.org-0; header-match-alsa-devel.alsa-project.org-1 Message-ID-Hash: D6R2JQJ67IAXOHLNXHGG7ANNSR3RSH3H X-Message-ID-Hash: D6R2JQJ67IAXOHLNXHGG7ANNSR3RSH3H X-Mailman-Approved-At: Sun, 16 Jul 2023 12:57:34 +0000 X-Mailman-Version: 3.3.8 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: As the comments added in commit 4d4c4bff4f8ed79d95e05 ("ALSA: hda: cs35l41: Clarify support for CSC3551 without _DSD Properties"), CSC3551 requires a valid _DSD to work and the current implementation just fails when no _DSD can be found for CSC3551. However it is a fact that many OEMs hardcoded the configurations needed by CSC3551 into their proprietary software for various 2022 and later laptop models, and this makes the Linux installations on these models cannot make any speaker sound. Meanwhile, at this point of time, we see no hope that these OEMs would ever fix this problem via a BIOS update. So to fix this bothering problem it might be worthwhile to add some model-specific fixups to apply some proper configurations to the cs35l41. To address the above problem, a configuration fixup function apply_cs35l41_fixup_cfg that would be called in cs35l41_no_acpi_dsd, along with a fixup table cs35l41_fixup_cfgtbl which is a array of fixup entry struct cs35l41_fixup_cfg are introduced. Each fixup entry records the ACPI _SUB(vender and device ID) to be matched, and a configuration to be applied to each of the cs35l41 device in CSC3551. More specifically for the design of this fixup mechanism, the maximum number of cs35l41 configurations inside a fixup entry is defined as a macro CS35L41_FIXUP_CFG_MAX_DEVICES, and the actual number of cs35l41 devices in a CSC3551 system is recorded in the num_device field in the fixup entry. The apply_cs35l41_fixup_cfg function is responsible for finding and applying a fixup for a specific model according to the model's ACPI _SUB. If no valid fixup can be applied, the fixup function fails and returns to the normal cs35l41_no_acpi_dsd execution flow. This patch now contains only several fixups for three Lenovo laptop models, namely 16IAH7, 16IAX7, and 16ARHA7 and this fixup mechanism has been verified to work on 16IAH7. As far as is known, several other laptop models from ASUS and HP also suffer from this no valid _DSD problem and could have it addressed with this fixup mechanism when proper fixup entries are inserted. Signed-off-by: David Xu --- sound/pci/hda/cs35l41_hda.c | 160 ++++++++++++++++++++++++++++++++++++ 1 file changed, 160 insertions(+) diff --git a/sound/pci/hda/cs35l41_hda.c b/sound/pci/hda/cs35l41_hda.c index ce5faa620517..d957458dd4e6 100644 --- a/sound/pci/hda/cs35l41_hda.c +++ b/sound/pci/hda/cs35l41_hda.c @@ -1211,6 +1211,159 @@ static int cs35l41_get_speaker_id(struct device *dev, int amp_index, return speaker_id; } +#define CS35L41_FIXUP_CFG_MAX_DEVICES 4 + +struct cs35l41_fixup_cfg { + unsigned short vender; + unsigned short device; + unsigned int num_device; /* The num of cs35l41 instances */ + /* cs35l41 instance ids, can be i2c index or spi index */ + int ids[CS35L41_FIXUP_CFG_MAX_DEVICES]; + unsigned int reset_gpio_idx[CS35L41_FIXUP_CFG_MAX_DEVICES]; + enum gpiod_flags reset_gpio_flags[CS35L41_FIXUP_CFG_MAX_DEVICES]; + int spkid_gpio_idx[CS35L41_FIXUP_CFG_MAX_DEVICES]; + unsigned int spk_pos[CS35L41_FIXUP_CFG_MAX_DEVICES]; + enum cs35l41_hda_gpio_function gpio1_func[CS35L41_FIXUP_CFG_MAX_DEVICES]; + enum cs35l41_hda_gpio_function gpio2_func[CS35L41_FIXUP_CFG_MAX_DEVICES]; + enum cs35l41_boost_type bst_type[CS35L41_FIXUP_CFG_MAX_DEVICES]; +}; + +static const struct cs35l41_fixup_cfg cs35l41_fixup_cfgtbl[] = { + { // Lenovo Legion Slim 7i 16IAH7 + .vender = 0x17aa, + .device = 0x386e, + .num_device = 2, + .ids = {0x40, 0x41}, + .reset_gpio_idx = {0, 0}, + .reset_gpio_flags = {GPIOD_OUT_LOW, GPIOD_OUT_LOW}, + .spkid_gpio_idx = {1, 1}, + .spk_pos = {0, 1}, + .gpio1_func = {CS35l41_VSPK_SWITCH, CS35l41_VSPK_SWITCH}, + .gpio2_func = {CS35L41_INTERRUPT, CS35L41_NOT_USED}, + .bst_type = {CS35L41_EXT_BOOST, CS35L41_EXT_BOOST} + }, + { // Lenovo Legion Slim 7i 16IAH7 type2 + .vender = 0x17aa, + .device = 0x3803, + .num_device = 2, + .ids = {0x40, 0x41}, + .reset_gpio_idx = {0, 0}, + .reset_gpio_flags = {GPIOD_OUT_LOW, GPIOD_OUT_LOW}, + .spkid_gpio_idx = {1, 1}, + .spk_pos = {0, 1}, + .gpio1_func = {CS35l41_VSPK_SWITCH, CS35l41_VSPK_SWITCH}, + .gpio2_func = {CS35L41_INTERRUPT, CS35L41_NOT_USED}, + .bst_type = {CS35L41_EXT_BOOST, CS35L41_EXT_BOOST} + }, + { // Lenovo Legion 7i 16IAX7 + .vender = 0x17aa, + .device = 0x3874, + .num_device = 2, + .ids = {0x40, 0x41}, + .reset_gpio_idx = {0, 0}, + .reset_gpio_flags = {GPIOD_OUT_LOW, GPIOD_OUT_LOW}, + .spkid_gpio_idx = {1, 1}, + .spk_pos = {0, 1}, + .gpio1_func = {CS35l41_VSPK_SWITCH, CS35l41_VSPK_SWITCH}, + .gpio2_func = {CS35L41_INTERRUPT, CS35L41_INTERRUPT}, + .bst_type = {CS35L41_EXT_BOOST, CS35L41_EXT_BOOST} + }, + { // Lenovo Legion 7i 16IAX7 type 2 + .vender = 0x17aa, + .device = 0x386f, + .num_device = 2, + .ids = {0x40, 0x41}, + .reset_gpio_idx = {0, 0}, + .reset_gpio_flags = {GPIOD_OUT_LOW, GPIOD_OUT_LOW}, + .spkid_gpio_idx = {1, 1}, + .spk_pos = {0, 1}, + .gpio1_func = {CS35l41_VSPK_SWITCH, CS35l41_VSPK_SWITCH}, + .gpio2_func = {CS35L41_INTERRUPT, CS35L41_INTERRUPT}, + .bst_type = {CS35L41_EXT_BOOST, CS35L41_EXT_BOOST} + }, + { // Lenovo Legion Slim 7 16ARHA7 + .vender = 0x17aa, + .device = 0x3877, + .num_device = 2, + .ids = {0x40, 0x41}, + .reset_gpio_idx = {0, 0}, + .reset_gpio_flags = {GPIOD_OUT_LOW, GPIOD_OUT_LOW}, + .spkid_gpio_idx = {1, 1}, + .spk_pos = {0, 1}, + .gpio1_func = {CS35l41_VSPK_SWITCH, CS35l41_VSPK_SWITCH}, + .gpio2_func = {CS35L41_INTERRUPT, CS35L41_INTERRUPT}, + .bst_type = {CS35L41_EXT_BOOST, CS35L41_EXT_BOOST} + }, + {} // terminator +}; + +static inline int cs35l41_fixup_get_index(const struct cs35l41_fixup_cfg *fixup, int cs35l41_addr) +{ + int i; + + for (i = 0; i < fixup->num_device; i++) { + if (fixup->ids[i] == cs35l41_addr) + return i; + } + return -ENODEV; +} + +static int apply_cs35l41_fixup_cfg(struct cs35l41_hda *cs35l41, + struct device *physdev, + int cs35l41_addr, + const struct cs35l41_fixup_cfg *fixup_tbl) +{ + const char *ssid; + unsigned int vendid; + unsigned int devid; + const struct cs35l41_fixup_cfg *cur_fixup; + struct cs35l41_hw_cfg *hw_cfg; + int cs35l41_index; + int ret; + int i; + + ssid = cs35l41->acpi_subsystem_id; + ret = sscanf(ssid, "%04x%04x", &vendid, &devid); + if (ret != 2) + return -EINVAL; + + hw_cfg = &cs35l41->hw_cfg; + for (cur_fixup = fixup_tbl; cur_fixup->vender; cur_fixup++) { + if (cur_fixup->vender == vendid && cur_fixup->device == devid) { + cs35l41_index = cs35l41_fixup_get_index(cur_fixup, cs35l41_addr); + if (cs35l41_index == -ENODEV) + return -ENODEV; + cs35l41->index = cs35l41_index; + cs35l41->reset_gpio = gpiod_get_index( + physdev, + NULL, + cur_fixup->reset_gpio_idx[cs35l41_index], + cur_fixup->reset_gpio_flags[cs35l41_index] + ); + cs35l41->speaker_id = cs35l41_get_speaker_id(physdev, + cs35l41_index, + cur_fixup->num_device, + cur_fixup->spkid_gpio_idx[cs35l41_index] + ); + hw_cfg->spk_pos = cur_fixup->spk_pos[cs35l41_index]; + cs35l41->channel_index = 0; + for (i = 0; i < cs35l41->index; i++) + if (cur_fixup->spk_pos[i] == hw_cfg->spk_pos) + cs35l41->channel_index++; + + hw_cfg->gpio1.func = cur_fixup->gpio1_func[cs35l41_index]; + hw_cfg->gpio1.valid = true; + hw_cfg->gpio2.func = cur_fixup->gpio2_func[cs35l41_index]; + hw_cfg->gpio2.valid = true; + hw_cfg->bst_type = cur_fixup->bst_type[cs35l41_index]; + dev_dbg(physdev, "Fixup applied.\n"); + break; + } + } + return 0; + +} + /* * Device CLSA010(0/1) doesn't have _DSD so a gpiod_get by the label reset won't work. * And devices created by serial-multi-instantiate don't have their device struct @@ -1221,6 +1374,7 @@ static int cs35l41_get_speaker_id(struct device *dev, int amp_index, static int cs35l41_no_acpi_dsd(struct cs35l41_hda *cs35l41, struct device *physdev, int id, const char *hid) { + int ret; struct cs35l41_hw_cfg *hw_cfg = &cs35l41->hw_cfg; /* check I2C address to assign the index */ @@ -1243,7 +1397,13 @@ static int cs35l41_no_acpi_dsd(struct cs35l41_hda *cs35l41, struct device *physd /* * Note: CLSA010(0/1) are special cases which use a slightly different design. * All other HIDs e.g. CSC3551 require valid ACPI _DSD properties to be supported. + * However many OEMs hardcoded the configurations into their proprietary software + * thus leaving our Linux installation with no speaker sound at all while we see + * no hope those OEMs would fix it. So we apply a ssid specific fixup to fix it. */ + if (apply_cs35l41_fixup_cfg(cs35l41, physdev, id, cs35l41_fixup_cfgtbl) == 0) + return 0; + dev_err(cs35l41->dev, "Error: ACPI _DSD Properties are missing for HID %s.\n", hid); hw_cfg->valid = false; hw_cfg->gpio1.valid = false;