From: Richard Fitzgerald <rf@opensource.cirrus.com>
To: <tiwai@suse.com>, <soyer@irl.hu>, <shenghao-ding@ti.com>
Cc: <perex@perex.cz>, <linux-kernel@vger.kernel.org>,
<linux-sound@vger.kernel.org>, <alsa-devel@alsa-project.org>,
<patches@opensource.cirrus.com>,
Richard Fitzgerald <rf@opensource.cirrus.com>
Subject: [PATCH 1/2] ALSA: hda: realtek: Re-work CS35L41 fixups to re-use for other amps
Date: Wed, 24 Jan 2024 11:26:06 +0000 [thread overview]
Message-ID: <20240124112607.77614-2-rf@opensource.cirrus.com> (raw)
In-Reply-To: <20240124112607.77614-1-rf@opensource.cirrus.com>
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 <rf@opensource.cirrus.com>
---
Can someone test that this doesn't break the two TAS2781 fixups?
---
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 19f2eb26659d..2e2906d2dd1c 100644
--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -6841,11 +6841,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);
@@ -6859,32 +6860,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;
@@ -6899,10 +6880,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)
@@ -6916,83 +6898,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 */
--
2.30.2
next prev parent reply other threads:[~2024-01-24 11:26 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-24 11:26 [PATCH 0/2] ALSA: hda: Move component binding support into separate library Richard Fitzgerald
2024-01-24 11:26 ` Richard Fitzgerald [this message]
2024-01-24 11:26 ` [PATCH 2/2] ALSA: hda: realtek: Move hda_component implementation to module Richard Fitzgerald
2024-01-24 13:43 ` [PATCH 0/2] ALSA: hda: Move component binding support into separate library Takashi Iwai
2024-01-25 9:05 ` Takashi Iwai
2024-01-24 21:55 ` Gergo Koteles
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240124112607.77614-2-rf@opensource.cirrus.com \
--to=rf@opensource.cirrus.com \
--cc=alsa-devel@alsa-project.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=patches@opensource.cirrus.com \
--cc=perex@perex.cz \
--cc=shenghao-ding@ti.com \
--cc=soyer@irl.hu \
--cc=tiwai@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).