Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp34854532rwd; Sun, 9 Jul 2023 22:05:33 -0700 (PDT) X-Google-Smtp-Source: APBJJlHKTd8sEQs2cKrdjAffxsbLh9BdLBou0rxQwhUXVbYh0TYhvwe4bV/F/ms0IdNN+7IpP5ZG X-Received: by 2002:a17:902:ea0b:b0:1b8:8262:7333 with SMTP id s11-20020a170902ea0b00b001b882627333mr10872720plg.51.1688965532886; Sun, 09 Jul 2023 22:05:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688965532; cv=none; d=google.com; s=arc-20160816; b=dtsm+5979YJiAY1uFpJQSXqQK2jqR34qC4Jl6MBasMLtvuoyUM4KEWpghcvd3h/6tX V2cZ7WEEj1oCSZB2DTLl8/CfRKutKxfu7BtTVkah9oZcHL2LuGh4cVRBWyYy/ipVT8Lw hSMdXFWrIqL59jh3ptj1uweEo14ybv0zXSYj86WOPlueLpXGkFejjIOb8hL+ySFGd+wX LlAKpVMK5PhRyunhkAW2jLCJaVnyOE+H9rqJk4Rbu9jdKeDwq0FQBGnA4NbZpd1JGiWl JkhBCcNMdKaG4Rwh7TbtV683aQ1UUCs6odhGFqIDEZmaOhZW+PfXee0PyKBt0SLVAeTf M15A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=1tLAUT+FW06hkr0A3aVkpGyBe68yPMELhJCBMjfYJtw=; fh=BroPXX66tPvgIHSU4eCs7LQywgpU/Ao9O2+2Ysdt5c0=; b=b3JD9Up4liEWAU79oEPaWXriBOn1A/A9hnvws8HkNJXHYV1VhaONlPcN7XHGZrQMUZ B5ChvTirl+M5cJCCnp953JtfSilCi5WCvtZiM/vcoMdqdTLtnWqXnf3LCYWvLUY55ltl m4v0Om46WGBLe0Uwz0IR/n8rQGVtWvTfufPU9OAYPIn6Pbwp50yMGUNFG1gHW3vRvWNC j1kOhUvSXDNwTBNtFw2yhvz6DizkuMZcjqawgOCjddzsNIGMCnj6Frai1XjmxhyWvS6A HbHGdRi3kRkvQMXnV0+hWC2RU8QfXoM3Qsu79vf0p5i+Y0iQ2EcsIawHBBrH503G7XRM 2ZWA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i6-20020a170902c94600b001add2ba445asi8802810pla.259.2023.07.09.22.05.19; Sun, 09 Jul 2023 22:05:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230213AbjGJENB (ORCPT + 99 others); Mon, 10 Jul 2023 00:13:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42020 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230256AbjGJEM5 (ORCPT ); Mon, 10 Jul 2023 00:12:57 -0400 Received: from n169-112.mail.139.com (n169-112.mail.139.com [120.232.169.112]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 92C91E5; Sun, 9 Jul 2023 21:12:51 -0700 (PDT) X-RM-TagInfo: emlType=0 X-RM-SPAM: X-RM-SPAM-FLAG: 00000000 Received: from localhost.localdomain (unknown[183.194.159.125]) by rmsmtp-lg-appmail-26-12031 (RichMail) with SMTP id 2eff64ab852fc25-b3e01; Mon, 10 Jul 2023 12:12:35 +0800 (CST) X-RM-TRANSID: 2eff64ab852fc25-b3e01 From: Shenghao Ding <13916275206@139.com> To: broonie@kernel.org, devicetree@vger.kernel.org, krzysztof.kozlowski+dt@linaro.org, robh+dt@kernel.org, lgirdwood@gmail.com, perex@perex.cz, pierre-louis.bossart@linux.intel.com Cc: kevin-lu@ti.com, shenghao-ding@ti.com, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, liam.r.girdwood@intel.com, mengdong.lin@intel.com, x1077012@ti.com, peeyush@ti.com, navada@ti.com, tiwai@suse.de, Shenghao Ding <13916275206@139.com> Subject: [PATCH v2 1/3] ALSA: hda/tas2781: Add tas2781 HDA driver Date: Mon, 10 Jul 2023 12:12:15 +0800 Message-Id: <20230710041217.151099-1-13916275206@139.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00, FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,FROM_LOCAL_DIGITS, FROM_LOCAL_HEX,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Integrate tas2781 configs for Lenovo Laptops. All of the tas2781s in the laptop will be aggregated as one audio device. The code support realtek as the primary codec. Rename "struct cs35l41_dev_name" to "struct scodec_dev_name" for all other side codecs instead of the certain one. Signed-off-by: Shenghao Ding <13916275206@139.com> --- Changes in v2: - simplify the check of vendor id with Lenovo - ThinkPad is one of Lenovo's brands, they suggested me to use ALC269_FIXUP_THINKPAD_ACPI. - Add comments on ACARD_SINGLE_RANGE_EXT_TLV - Add the range check for tas_priv->tasdevice[] in tas2781_acpi_get_i2c_res. - remove acpi_subsystem_id - Issue in Laptop 0x17aa38be ACPI talbe caused codec->bus->pci->subsystem_device is not equal to (codec->core.subsystem_id & 0xffff) in snd_hda_pick_fixup. The former is 0x3802 and the latter is 0x38be leads to getting the wrong fixup_id and enter into the wrong entry. Although, this issue has been raised to the laptop manufacturer, but the ACPI table is locked, cannot be changed any more. Correct the wrong entry in the code. - Rename "struct cs35l41_dev_name" to "struct scodec_dev_name" for all other side codecs instead of one certain codec. - Ignore the checkpatch complaints in alc269_fixup_tbl - Drop the hunk which is irrelevant with my code in alc_fixup_headset_mode_alc255_no_hp_mic - Add tiwai@suse.de into Cc list - remove useless index - combine ALC287_FIXUP_TAS2781_I2C_2 and ALC287_FIXUP_TAS2781_I2C_4 together as ALC287_FIXUP_TAS2781_I2C, The code view all the tas2781s in the laptop as one instance. - delete the white space at the end of the line in alc_fixup_headset_mode_alc255_no_hp_mic --- sound/pci/hda/patch_realtek.c | 104 +++++++++++++++++++++++++++++++++- 1 file changed, 101 insertions(+), 3 deletions(-) diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c index e2f8b608de82..d730497af57d 100644 --- a/sound/pci/hda/patch_realtek.c +++ b/sound/pci/hda/patch_realtek.c @@ -6705,7 +6705,7 @@ static void comp_generic_playback_hook(struct hda_pcm_stream *hinfo, struct hda_ } } -struct cs35l41_dev_name { +struct scodec_dev_name { const char *bus; const char *hid; int index; @@ -6714,7 +6714,7 @@ struct cs35l41_dev_name { /* match the device name in a slightly relaxed manner */ static int comp_match_cs35l41_dev_name(struct device *dev, void *data) { - struct cs35l41_dev_name *p = data; + struct scodec_dev_name *p = data; const char *d = dev_name(dev); int n = strlen(p->bus); char tmp[32]; @@ -6730,12 +6730,32 @@ static int comp_match_cs35l41_dev_name(struct device *dev, void *data) return !strcmp(d + n, tmp); } +static int comp_match_tas2781_dev_name(struct device *dev, + void *data) +{ + struct scodec_dev_name *p = data; + const char *d = dev_name(dev); + int n = strlen(p->bus); + char tmp[32]; + + /* check the bus name */ + if (strncmp(d, p->bus, n)) + return 0; + /* skip the bus number */ + if (isdigit(d[n])) + n++; + /* the rest must be exact matching */ + snprintf(tmp, sizeof(tmp), "-%s:00", p->hid); + + return !strcmp(d + n, tmp); +} + static void cs35l41_generic_fixup(struct hda_codec *cdc, int action, const char *bus, const char *hid, int count) { struct device *dev = hda_codec_dev(cdc); struct alc_spec *spec = cdc->spec; - struct cs35l41_dev_name *rec; + struct scodec_dev_name *rec; int ret, i; switch (action) { @@ -6763,6 +6783,41 @@ static void cs35l41_generic_fixup(struct hda_codec *cdc, int action, const char } } +static void tas2781_generic_fixup(struct hda_codec *cdc, int action, + const char *bus, const char *hid) +{ + struct device *dev = hda_codec_dev(cdc); + struct alc_spec *spec = cdc->spec; + struct scodec_dev_name *rec; + int ret; + + switch (action) { + case HDA_FIXUP_ACT_PRE_PROBE: + rec = devm_kmalloc(dev, sizeof(*rec), GFP_KERNEL); + if (!rec) + return; + rec->bus = bus; + rec->hid = hid; + rec->index = 0; + spec->comps[0].codec = cdc; + component_match_add(dev, &spec->match, + comp_match_tas2781_dev_name, rec); + ret = component_master_add_with_match(dev, &comp_master_ops, + spec->match); + if (ret) + codec_err(cdc, + "Fail to register component aggregator %d\n", + ret); + else + spec->gen.pcm_playback_hook = + comp_generic_playback_hook; + break; + case HDA_FIXUP_ACT_FREE: + component_master_del(dev, &comp_master_ops); + break; + } +} + static void cs35l41_fixup_i2c_two(struct hda_codec *cdc, const struct hda_fixup *fix, int action) { cs35l41_generic_fixup(cdc, action, "i2c", "CSC3551", 2); @@ -6790,6 +6845,12 @@ static void alc287_fixup_legion_16ithg6_speakers(struct hda_codec *cdc, const st cs35l41_generic_fixup(cdc, action, "i2c", "CLSA0101", 2); } +static void tas2781_fixup_i2c(struct hda_codec *cdc, + const struct hda_fixup *fix, int action) +{ + tas2781_generic_fixup(cdc, action, "i2c", "TIAS2781"); +} + /* for alc295_fixup_hp_top_speakers */ #include "hp_x360_helper.c" @@ -7213,6 +7274,7 @@ enum { ALC287_FIXUP_YOGA9_14IAP7_BASS_SPK_PIN, ALC295_FIXUP_DELL_INSPIRON_TOP_SPEAKERS, ALC236_FIXUP_DELL_DUAL_CODECS, + ALC287_FIXUP_TAS2781_I2C, }; /* A special fixup for Lenovo C940 and Yoga Duet 7; @@ -9283,6 +9345,12 @@ static const struct hda_fixup alc269_fixups[] = { .chained = true, .chain_id = ALC255_FIXUP_DELL1_MIC_NO_PRESENCE, }, + [ALC287_FIXUP_TAS2781_I2C] = { + .type = HDA_FIXUP_FUNC, + .v.func = tas2781_fixup_i2c, + .chained = true, + .chain_id = ALC269_FIXUP_THINKPAD_ACPI, + }, }; static const struct snd_pci_quirk alc269_fixup_tbl[] = { @@ -9846,6 +9914,20 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = { SND_PCI_QUIRK(0x17aa, 0x3853, "Lenovo Yoga 7 15ITL5", ALC287_FIXUP_YOGA7_14ITL_SPEAKERS), SND_PCI_QUIRK(0x17aa, 0x3855, "Legion 7 16ITHG6", ALC287_FIXUP_LEGION_16ITHG6), SND_PCI_QUIRK(0x17aa, 0x3869, "Lenovo Yoga7 14IAL7", ALC287_FIXUP_YOGA9_14IAP7_BASS_SPK_PIN), + SND_PCI_QUIRK(0x17aa, 0x387d, "Yoga S780-16 pro Quad AAC", ALC287_FIXUP_TAS2781_I2C), + SND_PCI_QUIRK(0x17aa, 0x387e, "Yoga S780-16 pro Quad YC", ALC287_FIXUP_TAS2781_I2C), + SND_PCI_QUIRK(0x17aa, 0x3881, "YB9 dual powe mode2 YC", ALC287_FIXUP_TAS2781_I2C), + SND_PCI_QUIRK(0x17aa, 0x3884, "Y780 YG DUAL", ALC287_FIXUP_TAS2781_I2C), + SND_PCI_QUIRK(0x17aa, 0x3886, "Y780 VECO DUAL", ALC287_FIXUP_TAS2781_I2C), + SND_PCI_QUIRK(0x17aa, 0x38a7, "Y780P AMD YG dual", ALC287_FIXUP_TAS2781_I2C), + SND_PCI_QUIRK(0x17aa, 0x38a8, "Y780P AMD VECO dual", ALC287_FIXUP_TAS2781_I2C), + SND_PCI_QUIRK(0x17aa, 0x38ba, "Yoga S780-14.5 Air AMD quad YC", ALC287_FIXUP_TAS2781_I2C), + SND_PCI_QUIRK(0x17aa, 0x38bb, "Yoga S780-14.5 Air AMD quad AAC", ALC287_FIXUP_TAS2781_I2C), + SND_PCI_QUIRK(0x17aa, 0x38be, "Yoga S980-14.5 proX YC Dual", ALC287_FIXUP_TAS2781_I2C), + SND_PCI_QUIRK(0x17aa, 0x38bf, "Yoga S980-14.5 proX LX Dual", ALC287_FIXUP_TAS2781_I2C), + SND_PCI_QUIRK(0x17aa, 0x38c3, "Y980 DUAL", ALC287_FIXUP_TAS2781_I2C), + SND_PCI_QUIRK(0x17aa, 0x38cb, "Y790 YG DUAL", ALC287_FIXUP_TAS2781_I2C), + SND_PCI_QUIRK(0x17aa, 0x38cd, "Y790 VECO DUAL", ALC287_FIXUP_TAS2781_I2C), SND_PCI_QUIRK(0x17aa, 0x3902, "Lenovo E50-80", ALC269_FIXUP_DMIC_THINKPAD_ACPI), SND_PCI_QUIRK(0x17aa, 0x3977, "IdeaPad S210", ALC283_FIXUP_INT_MIC), SND_PCI_QUIRK(0x17aa, 0x3978, "Lenovo B50-70", ALC269_FIXUP_DMIC_THINKPAD_ACPI), @@ -10761,6 +10843,22 @@ static int patch_alc269(struct hda_codec *codec) codec->fixup_id = HDA_FIXUP_ID_NOT_SET; } + /* FIXME: Issue in Laptop 0x17aa38be ACPI talbe caused + * codec->bus->pci->subsystem_device is not equal to + * (codec->core.subsystem_id & 0xffff) in snd_hda_pick_fixup. + * The former is 0x3802 and the latter is 0x38be leads to getting the + * wrong fixup_id and enter into the wrong entry. Although, this issue + * has been raised to the laptop manufacturer, but the ACPI table is + * locked, cannot be changed any more. Correct the wrong entry in the + * code. + */ + if (codec->fixup_id == ALC287_FIXUP_YOGA7_14ITL_SPEAKERS && + codec->core.vendor_id == 0x10ec0287 && + codec->core.subsystem_id == 0x17aa38be) { + codec_dbg(codec, "Clear wrong fixup for 17aa38be\n"); + codec->fixup_id = ALC287_FIXUP_TAS2781_I2C; + } + snd_hda_pick_pin_fixup(codec, alc269_pin_fixup_tbl, alc269_fixups, true); snd_hda_pick_pin_fixup(codec, alc269_fallback_pin_fixup_tbl, alc269_fixups, false); snd_hda_pick_fixup(codec, NULL, alc269_fixup_vendor_tbl, -- 2.34.1