Commit 35a17444 authored by Takashi Iwai's avatar Takashi Iwai

ALSA: hda/realtek: More robust component matching for CS35L41

As the previous commit implies, a system may have a different SPI bus
number that is embedded in the device string.  And, assuming the fixed
bus number is rather fragile; it may be assigned differently depending
on the configuration or on the boot environment.  Once when a bus
number change happens, the binding fails, resulting in the silence.

This patch tries to make the matching a bit more relaxed, allowing to
bind with a different bus number (or without it).  So the previous
fix, the introduction of ALC245_FIXUP_CS35L41_SPI1_2 fixup became
superfluous, and this is unified to ALC245_FIXUP_CS35L41_SPI_2.

Fixes: 225f6e1b ("ALSA: hda/realtek: Add quirk for HP Zbook Firefly 14 G9 model")
Link: https://lore.kernel.org/r/20220930084810.10435-1-tiwai@suse.deSigned-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 225f6e1b
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/input.h> #include <linux/input.h>
#include <linux/leds.h> #include <linux/leds.h>
#include <linux/ctype.h>
#include <sound/core.h> #include <sound/core.h>
#include <sound/jack.h> #include <sound/jack.h>
#include <sound/hda_codec.h> #include <sound/hda_codec.h>
...@@ -6704,23 +6705,51 @@ static void comp_generic_playback_hook(struct hda_pcm_stream *hinfo, struct hda_ ...@@ -6704,23 +6705,51 @@ static void comp_generic_playback_hook(struct hda_pcm_stream *hinfo, struct hda_
} }
} }
struct cs35l41_dev_name {
const char *bus;
const char *hid;
int index;
};
/* 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;
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-cs35l41-hda.%d", p->hid, p->index);
return !strcmp(d + n, tmp);
}
static void cs35l41_generic_fixup(struct hda_codec *cdc, int action, const char *bus, static void cs35l41_generic_fixup(struct hda_codec *cdc, int action, const char *bus,
const char *hid, int count) const char *hid, int count)
{ {
struct device *dev = hda_codec_dev(cdc); struct device *dev = hda_codec_dev(cdc);
struct alc_spec *spec = cdc->spec; struct alc_spec *spec = cdc->spec;
char *name; struct cs35l41_dev_name *rec;
int ret, i; int ret, i;
switch (action) { switch (action) {
case HDA_FIXUP_ACT_PRE_PROBE: case HDA_FIXUP_ACT_PRE_PROBE:
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
name = devm_kasprintf(dev, GFP_KERNEL, rec = devm_kmalloc(dev, sizeof(*rec), GFP_KERNEL);
"%s-%s:00-cs35l41-hda.%d", bus, hid, i); if (!rec)
if (!name)
return; return;
rec->bus = bus;
rec->hid = hid;
rec->index = i;
spec->comps[i].codec = cdc; spec->comps[i].codec = cdc;
component_match_add(dev, &spec->match, component_compare_dev_name, name); component_match_add(dev, &spec->match,
comp_match_cs35l41_dev_name, rec);
} }
ret = component_master_add_with_match(dev, &comp_master_ops, spec->match); ret = component_master_add_with_match(dev, &comp_master_ops, spec->match);
if (ret) if (ret)
...@@ -6738,17 +6767,12 @@ static void cs35l41_fixup_i2c_two(struct hda_codec *cdc, const struct hda_fixup ...@@ -6738,17 +6767,12 @@ static void cs35l41_fixup_i2c_two(struct hda_codec *cdc, const struct hda_fixup
static void cs35l41_fixup_spi_two(struct hda_codec *codec, const struct hda_fixup *fix, int action) static void cs35l41_fixup_spi_two(struct hda_codec *codec, const struct hda_fixup *fix, int action)
{ {
cs35l41_generic_fixup(codec, action, "spi0", "CSC3551", 2); cs35l41_generic_fixup(codec, action, "spi", "CSC3551", 2);
}
static void cs35l41_fixup_spi1_two(struct hda_codec *codec, const struct hda_fixup *fix, int action)
{
cs35l41_generic_fixup(codec, action, "spi1", "CSC3551", 2);
} }
static void cs35l41_fixup_spi_four(struct hda_codec *codec, const struct hda_fixup *fix, int action) static void cs35l41_fixup_spi_four(struct hda_codec *codec, const struct hda_fixup *fix, int action)
{ {
cs35l41_generic_fixup(codec, action, "spi0", "CSC3551", 4); cs35l41_generic_fixup(codec, action, "spi", "CSC3551", 4);
} }
static void alc287_fixup_legion_16achg6_speakers(struct hda_codec *cdc, const struct hda_fixup *fix, static void alc287_fixup_legion_16achg6_speakers(struct hda_codec *cdc, const struct hda_fixup *fix,
...@@ -7137,8 +7161,6 @@ enum { ...@@ -7137,8 +7161,6 @@ enum {
ALC287_FIXUP_CS35L41_I2C_2_HP_GPIO_LED, ALC287_FIXUP_CS35L41_I2C_2_HP_GPIO_LED,
ALC245_FIXUP_CS35L41_SPI_2, ALC245_FIXUP_CS35L41_SPI_2,
ALC245_FIXUP_CS35L41_SPI_2_HP_GPIO_LED, ALC245_FIXUP_CS35L41_SPI_2_HP_GPIO_LED,
ALC245_FIXUP_CS35L41_SPI1_2,
ALC245_FIXUP_CS35L41_SPI1_2_HP_GPIO_LED,
ALC245_FIXUP_CS35L41_SPI_4, ALC245_FIXUP_CS35L41_SPI_4,
ALC245_FIXUP_CS35L41_SPI_4_HP_GPIO_LED, ALC245_FIXUP_CS35L41_SPI_4_HP_GPIO_LED,
ALC285_FIXUP_HP_SPEAKERS_MICMUTE_LED, ALC285_FIXUP_HP_SPEAKERS_MICMUTE_LED,
...@@ -8986,16 +9008,6 @@ static const struct hda_fixup alc269_fixups[] = { ...@@ -8986,16 +9008,6 @@ static const struct hda_fixup alc269_fixups[] = {
.chained = true, .chained = true,
.chain_id = ALC285_FIXUP_HP_GPIO_LED, .chain_id = ALC285_FIXUP_HP_GPIO_LED,
}, },
[ALC245_FIXUP_CS35L41_SPI1_2] = {
.type = HDA_FIXUP_FUNC,
.v.func = cs35l41_fixup_spi1_two,
},
[ALC245_FIXUP_CS35L41_SPI1_2_HP_GPIO_LED] = {
.type = HDA_FIXUP_FUNC,
.v.func = cs35l41_fixup_spi1_two,
.chained = true,
.chain_id = ALC285_FIXUP_HP_GPIO_LED,
},
[ALC245_FIXUP_CS35L41_SPI_4] = { [ALC245_FIXUP_CS35L41_SPI_4] = {
.type = HDA_FIXUP_FUNC, .type = HDA_FIXUP_FUNC,
.v.func = cs35l41_fixup_spi_four, .v.func = cs35l41_fixup_spi_four,
...@@ -9358,7 +9370,7 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = { ...@@ -9358,7 +9370,7 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = {
SND_PCI_QUIRK(0x103c, 0x8aa3, "HP ProBook 450 G9 (MB 8AA1)", ALC236_FIXUP_HP_GPIO_LED), SND_PCI_QUIRK(0x103c, 0x8aa3, "HP ProBook 450 G9 (MB 8AA1)", ALC236_FIXUP_HP_GPIO_LED),
SND_PCI_QUIRK(0x103c, 0x8aa8, "HP EliteBook 640 G9 (MB 8AA6)", ALC236_FIXUP_HP_GPIO_LED), SND_PCI_QUIRK(0x103c, 0x8aa8, "HP EliteBook 640 G9 (MB 8AA6)", ALC236_FIXUP_HP_GPIO_LED),
SND_PCI_QUIRK(0x103c, 0x8aab, "HP EliteBook 650 G9 (MB 8AA9)", ALC236_FIXUP_HP_GPIO_LED), SND_PCI_QUIRK(0x103c, 0x8aab, "HP EliteBook 650 G9 (MB 8AA9)", ALC236_FIXUP_HP_GPIO_LED),
SND_PCI_QUIRK(0x103c, 0x8abb, "HP ZBook Firefly 14 G9", ALC245_FIXUP_CS35L41_SPI1_2_HP_GPIO_LED), SND_PCI_QUIRK(0x103c, 0x8abb, "HP ZBook Firefly 14 G9", ALC245_FIXUP_CS35L41_SPI_2_HP_GPIO_LED),
SND_PCI_QUIRK(0x103c, 0x8ad1, "HP EliteBook 840 14 inch G9 Notebook PC", ALC245_FIXUP_CS35L41_SPI_2_HP_GPIO_LED), SND_PCI_QUIRK(0x103c, 0x8ad1, "HP EliteBook 840 14 inch G9 Notebook PC", ALC245_FIXUP_CS35L41_SPI_2_HP_GPIO_LED),
SND_PCI_QUIRK(0x103c, 0x8ad2, "HP EliteBook 860 16 inch G9 Notebook PC", ALC245_FIXUP_CS35L41_SPI_2_HP_GPIO_LED), SND_PCI_QUIRK(0x103c, 0x8ad2, "HP EliteBook 860 16 inch G9 Notebook PC", ALC245_FIXUP_CS35L41_SPI_2_HP_GPIO_LED),
SND_PCI_QUIRK(0x1043, 0x103e, "ASUS X540SA", ALC256_FIXUP_ASUS_MIC), SND_PCI_QUIRK(0x1043, 0x103e, "ASUS X540SA", ALC256_FIXUP_ASUS_MIC),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment