ALSA: hda: cs35l41: Support systems with missing _DSD properties
PATCH 1/1 ALSA: hda: cs35l41: Support systems with missing _DSD properties
Some systems using CS35L41 with HDA were released without some required _DSD properties in ACPI. To support these special cases, add an api to configure the correct properties for systems with this issue.
This initial commit moves the no _DSD support for Lenovo Legion Laptops (CLSA0100, CLSA0101) into a new framework which can be extended to support additional laptops in the future.
--- sound/pci/hda/Makefile | 2 +- sound/pci/hda/cs35l41_hda.c | 65 ++++++------------------- sound/pci/hda/cs35l41_hda.h | 1 + sound/pci/hda/cs35l41_hda_property.c | 73 ++++++++++++++++++++++++++++ sound/pci/hda/cs35l41_hda_property.h | 18 +++++++ 5 files changed, 108 insertions(+), 51 deletions(-) create mode 100644 sound/pci/hda/cs35l41_hda_property.c create mode 100644 sound/pci/hda/cs35l41_hda_property.h
sound/pci/hda/Makefile +1 -1
@@ -28,7 +28,7 @@ snd-hda-codec-via-objs := patch_via.o snd-hda-codec-hdmi-objs := patch_hdmi.o hda_eld.o # side codecs -snd-hda-scodec-cs35l41-objs := cs35l41_hda.o +snd-hda-scodec-cs35l41-objs := cs35l41_hda.o cs35l41_hda_property.o snd-hda-scodec-cs35l41-i2c-objs := cs35l41_hda_i2c.o snd-hda-scodec-cs35l41-spi-objs := cs35l41_hda_spi.o snd-hda-scodec-cs35l56-objs := cs35l56_hda.o
sound/pci/hda/cs35l41_hda.c +15 -50
97 lines not on this page · raw message
sound/pci/hda/cs35l41_hda.h +1 -0
@@ -83,5 +83,6 @@ extern const struct dev_pm_ops cs35l41_hda_pm_ops;int cs35l41_hda_probe (struct device *dev,const char *device_name,int id,int irq,struct regmap *regmap);void cs35l41_hda_remove (struct device *dev); +int cs35l41_get_speaker_id (struct device *dev,int amp_index,int num_amps,int fixed_gpio_id);#endif /*__CS35L41_HDA_H__*/
sound/pci/hda/cs35l41_hda_property.c new file +73 -0
73 lines not on this page · raw message
sound/pci/hda/cs35l41_hda_property.h new file +18 -0
@@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0 +* +* CS35L41 ALSA HDA Property driver +* +* Copyright 2023 Cirrus Logic, Inc. +* +* Author: Stefan Binding <[email protected]> +*/ + +#ifndef CS35L41_HDA_PROP_H +#define CS35L41_HDA_PROP_H + +#include <linux/device.h> +#include "cs35l41_hda.h" + +int cs35l41_add_dsd_properties (struct cs35l41_hda *cs35l41,struct device *physdev,int id, +const char *hid); +#endif /* CS35L41_HDA_PROP_H */
Signature · 1 line
2.34.1
Quoted 11 lines · Stefan Binding
Some systems using CS35L41 with HDA were released without some required
_DSDproperties in ACPI. To support these special cases, add an api to configure the correct properties for systems with this issue.This initial commit moves the no
_DSDsupport for Lenovo Legion Laptops (CLSA0100, CLSA0101) into a new framework which can be extended to support additional laptops in the future.Signed-off-by Stefan Binding <[email protected]>
OK, we need to give up and accept the bitter reality :) Now applied. Thanks.
Takashi
Quoted 288 lines · Stefan Binding
Some systems using CS35L41 with HDA were released without some required
_DSDproperties in ACPI. To support these special cases, add an api to configure the correct properties for systems with this issue.This initial commit moves the no
_DSDsupport for Lenovo Legion Laptops (CLSA0100, CLSA0101) into a new framework which can be extended to support additional laptops in the future.Signed-off-by Stefan Binding <[email protected]>---
sound/pci/hda/Makefile | 2 +- sound/pci/hda/cs35l41_hda.c | 65 ++++++------------------- sound/pci/hda/cs35l41_hda.h | 1 +sound/pci/hda/cs35l41_hda_property.c| 73
++++++++++++++++++++++++++++
sound/pci/hda/cs35l41_hda_property.h | 18 +++++++5 files changed, 108 insertions(+), 51 deletions(-)create mode 100644
sound/pci/hda/cs35l41_hda_property.ccreate mode 100644sound/pci/hda/cs35l41_hda_property.hsound/pci/hda/Makefile +0
-0@@ -28,7 +28,7 @@ snd-hda-codec-via-objs := patch_via.osnd-hda-codec-hdmi-objs := patch_hdmi.o hda_eld.o
# side codecssound/pci/hda/Makefile +1
-1-snd-hda-scodec-cs35l41-objs := cs35l41_hda.o +snd-hda-scodec-cs35l41-objs := cs35l41_hda.ocs35l41_hda_property.o snd-hda-scodec-cs35l41-i2c-objs := cs35l41_hda_i2c.o snd-hda-scodec-cs35l41-spi-objs := cs35l41_hda_spi.o snd-hda-scodec-cs35l56-objs := cs35l56_hda.o
sound/pci/hda/cs35l41_hda.c +1
-0@@ -19,6 +19,7 @@ #include "hda_component.h" #include "cs35l41_hda.h" #include "hda_cs_dsp_ctl.h" +#include "cs35l41_hda_property.h"
#defineCS35L41_FIRMWARE_ROOT"cirrus/"
#defineCS35L41_PART"cs35l41"sound/pci/hda/cs35l41_hda.c +0
-0@@ -1315,8 +1316,7 @@ static int cs35l41_hda_apply_properties(struct cs35l41_hda *cs35l41) return cs35l41_hda_channel_map(cs35l41->dev, 0, NULL, 1, &hw_cfg->spk_pos); }sound/pci/hda/cs35l41_hda.c +1
-2-static int cs35l41_get_speaker_id (struct device *dev,int amp_index, - int num_amps, int fixed_gpio_id) +int cs35l41_get_speaker_id(struct device *dev, int amp_index, int
num_amps, intfixed_gpio_id)
{
structgpio_desc*speaker_id_desc;
intspeaker_id=-ENODEV;sound/pci/hda/cs35l41_hda.c +0
-0@@ -1370,49 +1370,6 @@ static int cs35l41_get_speaker_id(struct device *dev, int amp_index, return speaker_id; }
-/*
- * Device CLSA010(0/1) doesn't have_DSDso agpiod_getby the label reset won't work.
- * And devices created by serial-multi-instantiate don't have their device struct
- * pointing to the correct fwnode, soacpi_devmust be used here.
- * And devm functions expect that the device requesting the resource has the correct
- * fwnode.
- */
-static int cs35l41_no_acpi_dsd(structcs35l41_hda*cs35l41, struct device *physdev, int id,
- const char *hid)sound/pci/hda/cs35l41_hda.c +0
-7-{ - struct cs35l41_hw_cfg *hw_cfg = &cs35l41->hw_cfg; - - /* check I2C address to assign the index */ - cs35l41->index = id == 0x40 ? 0 : 1; - cs35l41->channel_index = 0; - cs35l41->reset_gpio = gpiod_get_index(physdev, NULL, 0,
GPIOD_OUT_HIGH);
- cs35l41->speaker_id =cs35l41_get_speaker_id(physdev, 0, 0, 2);
- hw_cfg->spk_pos =cs35l41->index;
- hw_cfg->gpio2.func =CS35L41_INTERRUPT;
- hw_cfg->gpio2.valid = true;
- hw_cfg->valid = true;
-
- if (strncmp(hid, "CLSA0100", 8)== 0) {
- hw_cfg->bst_type =CS35L41_EXT_BOOST_NO_VSPK_SWITCH; - } else if (strncmp(hid, "CLSA0101", 8)== 0) {
- hw_cfg->bst_type =CS35L41_EXT_BOOST;
- hw_cfg->gpio1.func =CS35l41_VSPK_SWITCH; - hw_cfg->gpio1.valid = true;
- } else {
- /*
- * Note: CLSA010(0/1) are special cases which use a slightly different design.
- * All other HIDs e.g. CSC3551 require valid ACPI_DSDproperties to be supported.
- */
- dev_err(cs35l41->dev, "Error: ACPI_DSDProperties are missing for HID %s.\n", hid);
- hw_cfg->valid = false;
- hw_cfg->gpio1.valid = false;
- hw_cfg->gpio2.valid = false;
- return-EINVAL;
- }sound/pci/hda/cs35l41_hda.c +0
-4- - return 0; -} -static int
cs35l41_hda_read_acpi(struct cs35l41_hda *cs35l41, const char *hid, int id)
{
structcs35l41_hw_cfg*hw_cfg=&cs35l41->hw_cfg;sound/pci/hda/cs35l41_hda.c +0
-0@@ -1438,12 +1395,17 @@ static int cs35l41_hda_read_acpi(struct
cs35l41_hda*cs35l41, const char *hid, i
sub = NULL;
cs35l41->acpi_subsystem_id = sub;
+ ret =cs35l41_add_dsd_properties(cs35l41, physdev, id, hid); + if (!ret) {
+ dev_info(cs35l41->dev, "Using extra_DSDproperties, bypassing_DSDin ACPI\n");
+ gotoput_physdev;
+ }
+
property = "cirrus,dev-index";
ret =device_property_count_u32(physdev, property); - if (ret <= 0) {
- ret =cs35l41_no_acpi_dsd(cs35l41, physdev, id, hid); - gotoerr_put_physdev;
- }
+ if (ret <= 0)
+ goto err;
+
if (ret >ARRAY_SIZE(values)) {
ret =-EINVAL;
goto err;sound/pci/hda/cs35l41_hda.c +0
-0@@ -1533,7 +1495,10 @@ static int cs35l41_hda_read_acpi(struct
cs35l41_hda*cs35l41, const char *hid, i
err:
dev_err(cs35l41->dev, "Failed property %s: %d\n", property, ret);sound/pci/hda/cs35l41_hda.c +4
-1-err_put_physdev: + hw_cfg->valid = false; + hw_cfg->gpio1.valid = false; + hw_cfg->gpio2.valid = false; +put_physdev:put_device(physdev);
return ret;sound/pci/hda/cs35l41_hda.h +1
-0@@ -83,5 +83,6 @@ extern const struct dev_pm_ops cs35l41_hda_pm_ops; int cs35l41_hda_probe(struct device *dev, const char *device_name,int id,int irq, struct regmap *regmap); void cs35l41_hda_remove(struct device *dev); +int cs35l41_get_speaker_id (struct device *dev,int amp_index,int num_amps,int fixed_gpio_id);
#endif /*__CS35L41_HDA_H__*/sound/pci/hda/cs35l41_hda_property.c new file +14
-0@@ -0,0 +1,73 @@ +// SPDX-License-Identifier: GPL-2.0 +// +// CS35L41 ALSA HDA Property driver +// +// Copyright 2023 Cirrus Logic, Inc. +// +// Author: Stefan Binding <[email protected]> + +#include <linux/gpio/consumer.h> +#include <linux/string.h> +#include "cs35l41_hda_property.h" + +/* +* Device CLSA010(0/1) doesn't have _DSD so a gpiod_get by the label reset won't work.
+ * And devices created by serial-multi-instantiate don't have their device struct
+ * pointing to the correct fwnode, soacpi_devmust be used here.
+ * And devm functions expect that the device requesting the resource has the correct
+ * fwnode.
+ */
+static int lenovo_legion_no_acpi(structcs35l41_hda*cs35l41, struct device *physdev, int id,
+ const char *hid)sound/pci/hda/cs35l41_hda_property.c new file +7
-0+{ + struct cs35l41_hw_cfg *hw_cfg = &cs35l41->hw_cfg; + + /* check I2C address to assign the index */ + cs35l41->index = id == 0x40 ? 0 : 1; + cs35l41->channel_index = 0; + cs35l41->reset_gpio = gpiod_get_index(physdev, NULL, 0,
GPIOD_OUT_HIGH);
+ cs35l41->speaker_id =cs35l41_get_speaker_id(physdev, 0, 0, 2);
+ hw_cfg->spk_pos =cs35l41->index;
+ hw_cfg->gpio2.func =CS35L41_INTERRUPT;
+ hw_cfg->gpio2.valid = true;
+ hw_cfg->valid = true;sound/pci/hda/cs35l41_hda_property.c new file +16
-0+ + if (strcmp(hid, "CLSA0100") == 0) { + hw_cfg->bst_type = CS35L41_EXT_BOOST_NO_VSPK_SWITCH; + } else if (strcmp(hid, "CLSA0101") == 0) { + hw_cfg->bst_type = CS35L41_EXT_BOOST; + hw_cfg->gpio1.func = CS35l41_VSPK_SWITCH; + hw_cfg->gpio1.valid = true; + } + + return 0; +} + +struct cs35l41_prop_model { + const char *hid; + const char *ssid; + int (*add_prop)(struct cs35l41_hda *cs35l41, struct device*physdev, int id,
+ const char *hid);sound/pci/hda/cs35l41_hda_property.c new file +9
-0+}; + +const struct cs35l41_prop_model cs35l41_prop_model_table[] = { + { "CLSA0100", NULL, lenovo_legion_no_acpi }, + { "CLSA0101", NULL, lenovo_legion_no_acpi }, + {} +}; + +int cs35l41_add_dsd_properties(struct cs35l41_hda *cs35l41, structdevice *physdev, int id,
+ const char *hid)sound/pci/hda/cs35l41_hda_property.c new file +4
-0+{ + const struct cs35l41_prop_model *model; + + for (model = cs35l41_prop_model_table; model->hid > 0;model++) {
+ if (!strcmp(model->hid, hid) && + (!model->ssid ||
+ (cs35l41->acpi_subsystem_id&& + !strcmp(model->ssid, cs35l41-Quoted 1 line
acpi_subsystem_id))))+ return
model->add_prop(cs35l41, physdev, id, hid);
+ }sound/pci/hda/cs35l41_hda_property.c new file +3
-0+ + return -ENOENT; +}sound/pci/hda/cs35l41_hda_property.h new file +16
-0@@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0 +* +* CS35L41 ALSA HDA Property driver +* +* Copyright 2023 Cirrus Logic, Inc. +* +* Author: Stefan Binding <[email protected]> +*/ + +#ifndef CS35L41_HDA_PROP_H +#define CS35L41_HDA_PROP_H + +#include <linux/device.h> +#include "cs35l41_hda.h" + +int cs35l41_add_dsd_properties(struct cs35l41_hda *cs35l41, struct
Quoted 3 lines
device *physdev, int id,
+ const char *hid);
+#endif /*CS35L41_HDA_PROP_H*/
Hi Stefan,
It's great to see progress here. I've had only a brief look and I haven't applied the patch as of yet since I have only SPI connected devices, so I must ask - are you planning any kind of extra support for the SPI connected devices?
My understanding of these SPI devs are that they are still missing the "cs-gpios" block in the ACPI and that they likely won't wok without it even with this patch.
Cheers,
Luke.