From patchwork Mon May 27 15:55:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Chiu X-Patchwork-Id: 1939996 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Vp0hG0c2Rz20KL for ; Tue, 28 May 2024 01:59:25 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1sBckk-0000o2-Bh; Mon, 27 May 2024 15:59:14 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1sBckh-0000nU-Nl for kernel-team@lists.ubuntu.com; Mon, 27 May 2024 15:59:11 +0000 Received: from mail-pg1-f197.google.com (mail-pg1-f197.google.com [209.85.215.197]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 8F7003FB68 for ; Mon, 27 May 2024 15:59:11 +0000 (UTC) Received: by mail-pg1-f197.google.com with SMTP id 41be03b00d2f7-67631fbc1d5so4547340a12.2 for ; Mon, 27 May 2024 08:59:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716825550; x=1717430350; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9JN9Cyuwe+SWcH8vnZh17cg2Sm1kOOFYPP4YIXXnvh8=; b=MGTopOVr8uU2oXDkJI/Y7fXitSW1J0RcVOnV9kWHd53zXAsXvsssDWz19yjb09zTlC CDxQXAMhFAVSuZAIx9ZqmPAxtERx901T6+rd+quYZERAtuOc7IEBf6wu1qrLX3E9R1jx ndP62bS+Nz3i4UpFFoAaryAnxt5c3DBUPEC2Y6HqeXGtinUyDc6D2eKVaCZRm2IIy5D6 SzHssBYS5Y3emWtGM5frRlysD82yQYyee/xkOs/sAnKwreuMDGf6LNYgauuUBjyrfmDm XlK9muWQV/6XM+nsBZb1v7ys9iJB32+AxsCCHnWgtw6u6IOuqJhcd1bg22hrSHig7UyI Worw== X-Gm-Message-State: AOJu0YzL4xsmlRecG75uL2D1776L6j1Gg9zCIRRkh5e/rOVskRR21cN/ oj4S/u1h3RIcqe+yqrFNIN4ziYdyCH1ztIdZGWjAN4uwCOSDD9x9yDShDtA+97rEM5RuGK0hGvh mJ71ydznz13QzsihtaF3hAbu69w3Wx0dmm2YMwSauGz+7ZSBElVHn/hTbINTvAbMp72vIIBDn6f P8y0cC8w7gUGU1 X-Received: by 2002:a17:902:d491:b0:1f4:8bb3:60a6 with SMTP id d9443c01a7336-1f48bb360fdmr44267715ad.62.1716825549954; Mon, 27 May 2024 08:59:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFrU1geb7a2qYCjNsA+0maG341Oq+zBFDEkwTFykKZCfHBtHiVTva66RXYNcTcoVjMtE9YD1w== X-Received: by 2002:a17:902:d491:b0:1f4:8bb3:60a6 with SMTP id d9443c01a7336-1f48bb360fdmr44267485ad.62.1716825549409; Mon, 27 May 2024 08:59:09 -0700 (PDT) Received: from localhost.localdomain (220-136-200-183.dynamic-ip.hinet.net. [220.136.200.183]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f44c79b9f1sm62755425ad.76.2024.05.27.08.59.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 May 2024 08:59:09 -0700 (PDT) From: Chris Chiu To: kernel-team@lists.ubuntu.com Subject: [SRU][N][PATCH 1/2][ ALSA: hda: realtek: Re-work CS35L41 fixups to re-use for other amps Date: Mon, 27 May 2024 23:55:58 +0800 Message-Id: <20240527155559.561244-2-chris.chiu@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240527155559.561244-1-chris.chiu@canonical.com> References: <20240527155559.561244-1-chris.chiu@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Richard Fitzgerald BugLink: https://bugs.launchpad.net/bugs/2062135 Slightly re-work the code around cs35l41_generic_fixup() and the component binding search so that it can be re-used for other amps that use the component binding mechanism. The match string is stored in struct scodec_dev_name instead of hardcoding it in the match function. The tas2781 does not use the amp index as part of the driver name match. But its match format string does not include a field for the index, so snprintf() would safely ignore the p->index argument. Because of this there is no need for a special match function for this case, the CS35L41 code can be re-used. Signed-off-by: Richard Fitzgerald Tested-by: Gergo Koteles Link: https://lore.kernel.org/r/20240124112607.77614-2-rf@opensource.cirrus.com Signed-off-by: Takashi Iwai (cherry picked from commit cf0d956635e7dabc5e85f100e37a1d64a48becb4) Signed-off-by: Chris Chiu --- sound/pci/hda/patch_realtek.c | 83 +++++++---------------------------- 1 file changed, 15 insertions(+), 68 deletions(-) diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c index 1eab06d0d5ed..6e4b88cf3af4 100644 --- a/sound/pci/hda/patch_realtek.c +++ b/sound/pci/hda/patch_realtek.c @@ -6899,11 +6899,12 @@ static void comp_generic_playback_hook(struct hda_pcm_stream *hinfo, struct hda_ struct scodec_dev_name { const char *bus; const char *hid; + const char *match_str; int index; }; /* match the device name in a slightly relaxed manner */ -static int comp_match_cs35l41_dev_name(struct device *dev, void *data) +static int comp_match_dev_name(struct device *dev, void *data) { struct scodec_dev_name *p = data; const char *d = dev_name(dev); @@ -6917,32 +6918,12 @@ static int comp_match_cs35l41_dev_name(struct device *dev, void *data) if (isdigit(d[n])) n++; /* the rest must be exact matching */ - snprintf(tmp, sizeof(tmp), "-%s:00-cs35l41-hda.%d", p->hid, p->index); + snprintf(tmp, sizeof(tmp), p->match_str, p->hid, p->index); 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) +static void comp_generic_fixup(struct hda_codec *cdc, int action, const char *bus, + const char *hid, const char *match_str, int count) { struct device *dev = hda_codec_dev(cdc); struct alc_spec *spec = cdc->spec; @@ -6957,10 +6938,11 @@ static void cs35l41_generic_fixup(struct hda_codec *cdc, int action, const char return; rec->bus = bus; rec->hid = hid; + rec->match_str = match_str; rec->index = i; spec->comps[i].codec = cdc; component_match_add(dev, &spec->match, - comp_match_cs35l41_dev_name, rec); + comp_match_dev_name, rec); } ret = component_master_add_with_match(dev, &comp_master_ops, spec->match); if (ret) @@ -6974,83 +6956,48 @@ 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); + comp_generic_fixup(cdc, action, "i2c", "CSC3551", "-%s:00-cs35l41-hda.%d", 2); } static void cs35l41_fixup_i2c_four(struct hda_codec *cdc, const struct hda_fixup *fix, int action) { - cs35l41_generic_fixup(cdc, action, "i2c", "CSC3551", 4); + comp_generic_fixup(cdc, action, "i2c", "CSC3551", "-%s:00-cs35l41-hda.%d", 4); } static void cs35l41_fixup_spi_two(struct hda_codec *codec, const struct hda_fixup *fix, int action) { - cs35l41_generic_fixup(codec, action, "spi", "CSC3551", 2); + comp_generic_fixup(codec, action, "spi", "CSC3551", "-%s:00-cs35l41-hda.%d", 2); } static void cs35l41_fixup_spi_four(struct hda_codec *codec, const struct hda_fixup *fix, int action) { - cs35l41_generic_fixup(codec, action, "spi", "CSC3551", 4); + comp_generic_fixup(codec, action, "spi", "CSC3551", "-%s:00-cs35l41-hda.%d", 4); } static void alc287_fixup_legion_16achg6_speakers(struct hda_codec *cdc, const struct hda_fixup *fix, int action) { - cs35l41_generic_fixup(cdc, action, "i2c", "CLSA0100", 2); + comp_generic_fixup(cdc, action, "i2c", "CLSA0100", "-%s:00-cs35l41-hda.%d", 2); } static void alc287_fixup_legion_16ithg6_speakers(struct hda_codec *cdc, const struct hda_fixup *fix, int action) { - cs35l41_generic_fixup(cdc, action, "i2c", "CLSA0101", 2); + comp_generic_fixup(cdc, action, "i2c", "CLSA0101", "-%s:00-cs35l41-hda.%d", 2); } static void tas2781_fixup_i2c(struct hda_codec *cdc, const struct hda_fixup *fix, int action) { - tas2781_generic_fixup(cdc, action, "i2c", "TIAS2781"); + comp_generic_fixup(cdc, action, "i2c", "TIAS2781", "-%s:00", 1); } static void yoga7_14arb7_fixup_i2c(struct hda_codec *cdc, const struct hda_fixup *fix, int action) { - tas2781_generic_fixup(cdc, action, "i2c", "INT8866"); + comp_generic_fixup(cdc, action, "i2c", "INT8866", "-%s:00", 1); } /* for alc295_fixup_hp_top_speakers */