ALSA: hda: Move component binding support into separate library
cover ALSA: hda: Move component binding support into separate library
The Cirrus Logic amplifiers are currently paired with Realtek HDA codecs. But they could be used with other codecs. To prepare for this, these two patches move the manager side of the component binding out of the Realtek driver into a library module.
The first patch tweaks the CS35L41 code so that it is not hardcoded to CS35L41, and changes the TAS2781 handling so that it re-uses that code instead of having a near-identical copy of it.
Can someone please test that these two patches don't break TAS2781? I have checked that they should work in theory but I don't have hardware to test on.
Richard Fitzgerald (2):
ALSA: hda: realtek: Re-work CS35L41 fixups to re-use for other amps
ALSA: hda: realtek: Move hda_component implementation to module
MAINTAINERS | 1 + sound/pci/hda/Kconfig | 4 + sound/pci/hda/Makefile | 2 + sound/pci/hda/hda_component.c | 169 ++++++++++++++++++++++++++ sound/pci/hda/hda_component.h | 59 +++++++++ sound/pci/hda/patch_realtek.c | 217 ++++------------------------------ 6 files changed, 261 insertions(+), 191 deletions(-) create mode 100644 sound/pci/hda/hda_component.c
Signature · 1 line
2.30.2
PATCH 1/2 ALSA: hda: realtek: Re-work CS35L41 fixups to re-use for other amps
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.
---
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(-)
sound/pci/hda/patch_realtek.c +15 -68
@@ -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 charreturn ; 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 */
Signature · 1 line
2.30.2
PATCH 2/2 ALSA: hda: realtek: Move hda_component implementation to module
In reply to Richard FitzgeraldMove the generic parts of the hda_component implementation into a new hda_component module. This will allow other HDA codecs to add support for the component binding API without duplicating all the code.
---
Can someone test that this doesn't break the two TAS2781 fixups?
--- MAINTAINERS | 1 + sound/pci/hda/Kconfig | 4 + sound/pci/hda/Makefile | 2 + sound/pci/hda/hda_component.c | 169 ++++++++++++++++++++++++++++++++++ sound/pci/hda/hda_component.h | 59 ++++++++++++ sound/pci/hda/patch_realtek.c | 146 ++++------------------------- 6 files changed, 252 insertions(+), 129 deletions(-) create mode 100644 sound/pci/hda/hda_component.c
MAINTAINERS +1 -0
@@ -5014,6 +5014,7 @@ F: include/linux/mfd/cs42l43* F: include/sound/cs* F: sound/pci/hda/cirrus* F: sound/pci/hda/cs* +F: sound/pci/hda/hda_component* F: sound/pci/hda/hda_cs_dsp_ctl.* F: sound/soc/codecs/cs*
sound/pci/hda/Kconfig +4 -0
@@ -116,6 +116,9 @@ config SND_HDA_CS_DSP_CONTROLS tristate select FW_CS_DSP +config SND_HDA_SCODEC_COMPONENT + tristate + config SND_HDA_SCODEC_CS35L41_I2C tristate "Build CS35L41 HD-audio side codec support for I2C Bus" depends on I2C
@@ -201,6 +204,7 @@ config SND_HDA_CODEC_REALTEK tristate "Build Realtek HD-audio codec support" select SND_HDA_GENERIC select SND_HDA_GENERIC_LEDS + select SND_HDA_SCODEC_COMPONENT help Say Y or M here to include Realtek HD-audio codec support in snd-hda-intel driver, such as ALC880.
sound/pci/hda/Makefile +2 -0
@@ -37,6 +37,7 @@ snd-hda-scodec-cs35l56-objs := cs35l56_hda.o snd-hda-scodec-cs35l56-i2c-objs := cs35l56_hda_i2c.o snd-hda-scodec-cs35l56-spi-objs := cs35l56_hda_spi.o snd-hda-cs-dsp-ctls-objs := hda_cs_dsp_ctl.o +snd-hda-scodec-component-objs := hda_component.o snd-hda-scodec-tas2781-i2c-objs := tas2781_hda_i2c.o # common driver
@@ -67,6 +68,7 @@ obj-$(CONFIG_SND_HDA_SCODEC_CS35L56) += snd-hda-scodec-cs35l56.o obj-$(CONFIG_SND_HDA_SCODEC_CS35L56_I2C) += snd-hda-scodec-cs35l56-i2c.o obj-$(CONFIG_SND_HDA_SCODEC_CS35L56_SPI) += snd-hda-scodec-cs35l56-spi.o obj-$(CONFIG_SND_HDA_CS_DSP_CONTROLS) += snd-hda-cs-dsp-ctls.o +obj-$(CONFIG_SND_HDA_SCODEC_COMPONENT) += snd-hda-scodec-component.o obj-$(CONFIG_SND_HDA_SCODEC_TAS2781_I2C) += snd-hda-scodec-tas2781-i2c.o # this must be the last entry after codec drivers;
sound/pci/hda/hda_component.c new file +169 -0
169 lines not on this page · raw message
sound/pci/hda/hda_component.h +59 -0
62 lines not on this page · raw message
sound/pci/hda/patch_realtek.c +17 -129
207 lines not on this page · raw message
Signature · 1 line
2.30.2
Quoted 10 lines · Richard Fitzgerald
The Cirrus Logic amplifiers are currently paired with Realtek HDA codecs. But they could be used with other codecs. To prepare for this, these two patches move the manager side of the component binding out of the Realtek driver into a library module.
The first patch tweaks the CS35L41 code so that it is not hardcoded to CS35L41, and changes the TAS2781 handling so that it re-uses that code instead of having a near-identical copy of it.
Quoted 7 lines
Can someone please test that these two patches don't break TAS2781? I have checked that they should work in theory but I don't have hardware to test on.
Richard Fitzgerald (2):
ALSA: hda: realtek: Re-work CS35L41 fixups to re-use for other amps
ALSA: hda: realtek: Movehda_componentimplementation to module
Through a quick glance, it looks good.
I'll wait for the verification for TAS codec for a while.
thanks,
Takashi
Quoted 17 lines · Takashi Iwai
Quoted 14 lines · Richard Fitzgerald
The Cirrus Logic amplifiers are currently paired with Realtek HDA codecs. But they could be used with other codecs. To prepare for this, these two patches move the manager side of the component binding out of the Realtek driver into a library module.
The first patch tweaks the CS35L41 code so that it is not hardcoded to CS35L41, and changes the TAS2781 handling so that it re-uses that code instead of having a near-identical copy of it.
Can someone please test that these two patches don't break TAS2781? I have checked that they should work in theory but I don't have hardware to test on.
Quoted 6 lines
Quoted 3 lines
Richard Fitzgerald (2):
ALSA: hda: realtek: Re-work CS35L41 fixups to re-use for other amps
ALSA: hda: realtek: Movehda_componentimplementation to moduleThrough a quick glance, it looks good.
I'll wait for the verification for TAS codec for a while.
Now applied to for-next branch.
thanks,
Takashi
Hi Richard,
Quoted 5 lines · Richard Fitzgerald
The Cirrus Logic amplifiers are currently paired with Realtek HDA codecs. But they could be used with other codecs. To prepare for this, these two patches move the manager side of the component binding out of the Realtek driver into a library module.
Quoted 8 lines
The first patch tweaks the CS35L41 code so that it is not hardcoded to CS35L41, and changes the TAS2781 handling so that it re-uses that code instead of having a near-identical copy of it.
Can someone please test that these two patches don't break TAS2781? I have checked that they should work in theory but I don't have hardware to test on.
It works on a Lenovo Yoga 7 14ARB7 laptop.
Regards,
Gergo
Quoted 13 lines
Richard Fitzgerald (2):
ALSA: hda: realtek: Re-work CS35L41 fixups to re-use for other amps
ALSA: hda: realtek: Movehda_componentimplementation to moduleMAINTAINERS | 1 + sound/pci/hda/Kconfig | 4 + sound/pci/hda/Makefile | 2 + sound/pci/hda/hda_component.c | 169 ++++++++++++++++++++++++++ sound/pci/hda/hda_component.h | 59 +++++++++ sound/pci/hda/patch_realtek.c | 217 ++++------------------------------ 6 files changed, 261 insertions(+), 191 deletions(-) create mode 100644 sound/pci/hda/hda_component.c