The CS35L41 Amplifier contains a DSP, capable of running firmware.
The firmware can run algorithms such as Speaker Protection, to ensure
that playback at high gains do not harm the speakers.
Adding support for CS35L41 firmware into the CS35L41 HDA driver also
allows us to support several extra features, such as hiberation
and interrupts.
The chain adds support in stages:
- General fixes to improve generalization and code re-use inside
the CS35L41 HDA driver.
- Add support for interrupts into the driver, which is required
for complete support of the firmware.
- Refactor ASoC CS35L41 code which deals with firmware to allow
for code re-use inside the CS35L41 HDA driver.
- Add support for loading firmware and tuning files from file system,
and creating alsa controls to control it.
- Support firmware load paths for different hardware systems.
- Support suspend/resume in the driver when using firmware. The firmware
supports hibernation, which allows the CS35L41 to drop into a low
power mode during suspend.
- Support the ability to unload firmware, swap and reload the firmware.
This is to allow different firmware to run during calibration.
The intended use-case is to load the firmware once on boot, and the driver
autmatically tries to load the firmware after it binds to the HDA driver.
This behaviour can be switched off using a kconfig, if desired.
changes since v7:
- Use private_data rather than private_value to save control info
- Clean up alsa control memory allocation/deallocation
- Remove unnecessary whitespace
- Get subsystem id from codec, rather than saving it separately
changes since v6:
- Fix warning by kernel test robot <[email protected]>
changes since v5:
- Fix warning by kernel test robot <[email protected]>
changes since v4:
- Fully remove tlv remnants from control add apis
- Remove unnecessary debug
- Rename variable to be more generic
- Remove redundent length check from read/write control apis
- Use SNDRV_CTL_ELEM_IFACE_CARD for firmware load controls
- Make kcontrol add/remove synchronous
- Load firmware asynchronous when loading via control
- Used cached controls when reloading firmware; only delete
controls when removing the driver itself
- Improve kcontrol remove
- Fix control write + notify
- Cleanup of unnecessary code
- Fix race condition when loading firmware before playback
- Ensure errors are properly propogated
- Fix include for Module parameters
Stefan Binding (13):
ALSA: hda: hda_cs_dsp_ctl: Add Library to support CS_DSP ALSA controls
ALSA: hda: hda_cs_dsp_ctl: Add apis to write the controls directly
ALSA: hda: cs35l41: Save codec object inside component struct
ALSA: hda: cs35l41: Save Subsystem ID inside CS35L41 Driver
ALSA: hda: cs35l41: Support reading subsystem id from ACPI
ALSA: hda: cs35l41: Support multiple load paths for firmware
ALSA: hda: cs35l41: Support Speaker ID for laptops
ALSA: hda: cs35l41: Support Hibernation during Suspend
ALSA: hda: cs35l41: Read Speaker Calibration data from UEFI variables
ALSA: hda: hda_cs_dsp_ctl: Add fw id strings
ALSA: hda: cs35l41: Add defaulted values into dsp bypass config
sequence
ALSA: hda: cs35l41: Support Firmware switching and reloading
ALSA: hda: cs35l41: Add module parameter to control firmware load
Vitaly Rodionov (1):
ALSA: hda: cs35l41: Add initial DSP support and firmware loading
MAINTAINERS | 1 +
include/sound/cs35l41.h | 4 +
sound/pci/hda/Kconfig | 8 +
sound/pci/hda/Makefile | 2 +
sound/pci/hda/cs35l41_hda.c | 883 +++++++++++++++++++++++++++++++-
sound/pci/hda/cs35l41_hda.h | 39 ++
sound/pci/hda/cs35l41_hda_i2c.c | 1 +
sound/pci/hda/cs35l41_hda_spi.c | 1 +
sound/pci/hda/hda_component.h | 3 +
sound/pci/hda/hda_cs_dsp_ctl.c | 240 +++++++++
sound/pci/hda/hda_cs_dsp_ctl.h | 39 ++
sound/pci/hda/patch_realtek.c | 26 +-
12 files changed, 1242 insertions(+), 5 deletions(-)
create mode 100644 sound/pci/hda/hda_cs_dsp_ctl.c
create mode 100644 sound/pci/hda/hda_cs_dsp_ctl.h
--
2.34.1
From: Stefan Binding <[email protected]>
The Subsystem ID is read from the HDA driver, and will
be used by the CS35L41 driver to be able to uniquely
identify the laptop, which is required to be able to
define firmware to be used by specific models.
Signed-off-by: Stefan Binding <[email protected]>
Signed-off-by: Vitaly Rodionov <[email protected]>
---
sound/pci/hda/cs35l41_hda.c | 3 +++
sound/pci/hda/cs35l41_hda.h | 1 +
2 files changed, 4 insertions(+)
diff --git a/sound/pci/hda/cs35l41_hda.c b/sound/pci/hda/cs35l41_hda.c
index e0d236eae93e..b6e94e7b482a 100644
--- a/sound/pci/hda/cs35l41_hda.c
+++ b/sound/pci/hda/cs35l41_hda.c
@@ -355,6 +355,9 @@ static int cs35l41_hda_bind(struct device *dev, struct device *master, void *mas
return -EBUSY;
comps->dev = dev;
+ if (!cs35l41->acpi_subsystem_id)
+ cs35l41->acpi_subsystem_id = devm_kasprintf(dev, GFP_KERNEL, "%.8x",
+ comps->codec->core.subsystem_id);
cs35l41->codec = comps->codec;
strscpy(comps->name, dev_name(dev), sizeof(comps->name));
comps->playback_hook = cs35l41_hda_playback_hook;
diff --git a/sound/pci/hda/cs35l41_hda.h b/sound/pci/hda/cs35l41_hda.h
index 5814af050944..b57f59a1ba49 100644
--- a/sound/pci/hda/cs35l41_hda.h
+++ b/sound/pci/hda/cs35l41_hda.h
@@ -42,6 +42,7 @@ struct cs35l41_hda {
int channel_index;
unsigned volatile long irq_errors;
const char *amp_name;
+ const char *acpi_subsystem_id;
struct mutex fw_mutex;
struct regmap_irq_chip_data *irq_data;
bool firmware_running;
--
2.34.1
From: Stefan Binding <[email protected]>
The config sequences for running with and without firmware and DSP
are different. The original behavior assumed that we would only
run without DSP only in the case where firmware load failed.
This meant the non-firmware sequence was written with the assumtion
that various registers would be set to their default value.
However, to support the ability to unload the firmware, the
non-firmware register sequence must be updated to update all
required registers, including values that would be defaulted,
in case the firmware sequence, which could have already run,
has changed their value.
Signed-off-by: Stefan Binding <[email protected]>
Signed-off-by: Vitaly Rodionov <[email protected]>
---
sound/pci/hda/cs35l41_hda.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/sound/pci/hda/cs35l41_hda.c b/sound/pci/hda/cs35l41_hda.c
index 68f18463d829..27ed5cd0d8bb 100644
--- a/sound/pci/hda/cs35l41_hda.c
+++ b/sound/pci/hda/cs35l41_hda.c
@@ -35,11 +35,24 @@
static const struct reg_sequence cs35l41_hda_config[] = {
{ CS35L41_PLL_CLK_CTRL, 0x00000430 }, // 3072000Hz, BCLK Input, PLL_REFCLK_EN = 1
+ { CS35L41_DSP_CLK_CTRL, 0x00000003 }, // DSP CLK EN
{ CS35L41_GLOBAL_CLK_CTRL, 0x00000003 }, // GLOBAL_FS = 48 kHz
{ CS35L41_SP_ENABLES, 0x00010000 }, // ASP_RX1_EN = 1
{ CS35L41_SP_RATE_CTRL, 0x00000021 }, // ASP_BCLK_FREQ = 3.072 MHz
{ CS35L41_SP_FORMAT, 0x20200200 }, // 32 bits RX/TX slots, I2S, clk consumer
+ { CS35L41_SP_HIZ_CTRL, 0x00000002 }, // Hi-Z unused
+ { CS35L41_SP_TX_WL, 0x00000018 }, // 24 cycles/slot
+ { CS35L41_SP_RX_WL, 0x00000018 }, // 24 cycles/slot
{ CS35L41_DAC_PCM1_SRC, 0x00000008 }, // DACPCM1_SRC = ASPRX1
+ { CS35L41_ASP_TX1_SRC, 0x00000018 }, // ASPTX1 SRC = VMON
+ { CS35L41_ASP_TX2_SRC, 0x00000019 }, // ASPTX2 SRC = IMON
+ { CS35L41_ASP_TX3_SRC, 0x00000032 }, // ASPTX3 SRC = ERRVOL
+ { CS35L41_ASP_TX4_SRC, 0x00000033 }, // ASPTX4 SRC = CLASSH_TGT
+ { CS35L41_DSP1_RX1_SRC, 0x00000008 }, // DSP1RX1 SRC = ASPRX1
+ { CS35L41_DSP1_RX2_SRC, 0x00000009 }, // DSP1RX2 SRC = ASPRX2
+ { CS35L41_DSP1_RX3_SRC, 0x00000018 }, // DSP1RX3 SRC = VMON
+ { CS35L41_DSP1_RX4_SRC, 0x00000019 }, // DSP1RX4 SRC = IMON
+ { CS35L41_DSP1_RX5_SRC, 0x00000020 }, // DSP1RX5 SRC = ERRVOL
{ CS35L41_AMP_DIG_VOL_CTRL, 0x00000000 }, // AMP_VOL_PCM 0.0 dB
{ CS35L41_AMP_GAIN_CTRL, 0x00000084 }, // AMP_GAIN_PCM 4.5 dB
};
--
2.34.1
From: Stefan Binding <[email protected]>
This is required for ALSA control support.
Signed-off-by: Stefan Binding <[email protected]>
Signed-off-by: Vitaly Rodionov <[email protected]>
---
sound/pci/hda/cs35l41_hda.c | 1 +
sound/pci/hda/cs35l41_hda.h | 1 +
sound/pci/hda/hda_component.h | 1 +
sound/pci/hda/patch_realtek.c | 1 +
4 files changed, 4 insertions(+)
diff --git a/sound/pci/hda/cs35l41_hda.c b/sound/pci/hda/cs35l41_hda.c
index cce27a86267f..bbbaafac50c3 100644
--- a/sound/pci/hda/cs35l41_hda.c
+++ b/sound/pci/hda/cs35l41_hda.c
@@ -117,6 +117,7 @@ static int cs35l41_hda_bind(struct device *dev, struct device *master, void *mas
return -EBUSY;
comps->dev = dev;
+ cs35l41->codec = comps->codec;
strscpy(comps->name, dev_name(dev), sizeof(comps->name));
comps->playback_hook = cs35l41_hda_playback_hook;
diff --git a/sound/pci/hda/cs35l41_hda.h b/sound/pci/hda/cs35l41_hda.h
index a52ffd1f7999..aaf9e16684c2 100644
--- a/sound/pci/hda/cs35l41_hda.h
+++ b/sound/pci/hda/cs35l41_hda.h
@@ -32,6 +32,7 @@ struct cs35l41_hda {
struct regmap *regmap;
struct gpio_desc *reset_gpio;
struct cs35l41_hw_cfg hw_cfg;
+ struct hda_codec *codec;
int irq;
int index;
diff --git a/sound/pci/hda/hda_component.h b/sound/pci/hda/hda_component.h
index e26c896a13f3..534e845b9cd1 100644
--- a/sound/pci/hda/hda_component.h
+++ b/sound/pci/hda/hda_component.h
@@ -14,5 +14,6 @@
struct hda_component {
struct device *dev;
char name[HDA_MAX_NAME_SIZE];
+ struct hda_codec *codec;
void (*playback_hook)(struct device *dev, int action);
};
diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
index cee69fa7e246..0369e19cd4bd 100644
--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -6654,6 +6654,7 @@ static void cs35l41_generic_fixup(struct hda_codec *cdc, int action, const char
"%s-%s:00-cs35l41-hda.%d", bus, hid, i);
if (!name)
return;
+ spec->comps[i].codec = cdc;
component_match_add(dev, &spec->match, component_compare_dev_name, name);
}
ret = component_master_add_with_match(dev, &comp_master_ops, spec->match);
--
2.34.1
From: Stefan Binding <[email protected]>
On some laptop models, the ACPI contains the unique
Subsystem ID, and this value should be preferred
over the value from the HDA driver.
Signed-off-by: Stefan Binding <[email protected]>
Signed-off-by: Vitaly Rodionov <[email protected]>
---
sound/pci/hda/cs35l41_hda.c | 36 ++++++++++++++++++++++++++++++++++++
1 file changed, 36 insertions(+)
diff --git a/sound/pci/hda/cs35l41_hda.c b/sound/pci/hda/cs35l41_hda.c
index b6e94e7b482a..2af3bb5ea1fb 100644
--- a/sound/pci/hda/cs35l41_hda.c
+++ b/sound/pci/hda/cs35l41_hda.c
@@ -544,6 +544,36 @@ static int cs35l41_hda_apply_properties(struct cs35l41_hda *cs35l41)
return cs35l41_hda_channel_map(cs35l41->dev, 0, NULL, 1, &hw_cfg->spk_pos);
}
+static int cs35l41_get_acpi_sub_string(struct device *dev, struct acpi_device *adev,
+ const char **subsysid)
+{
+ struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
+ union acpi_object *obj;
+ acpi_status status;
+ int ret = 0;
+
+ status = acpi_evaluate_object(adev->handle, "_SUB", NULL, &buffer);
+ if (ACPI_SUCCESS(status)) {
+ obj = buffer.pointer;
+ if (obj->type == ACPI_TYPE_STRING) {
+ *subsysid = devm_kstrdup(dev, obj->string.pointer, GFP_KERNEL);
+ if (*subsysid == NULL) {
+ dev_err(dev, "Cannot allocate Subsystem ID");
+ ret = -ENOMEM;
+ }
+ } else {
+ dev_warn(dev, "Warning ACPI _SUB did not return a string\n");
+ ret = -ENODEV;
+ }
+ acpi_os_free(buffer.pointer);
+ } else {
+ dev_dbg(dev, "Warning ACPI _SUB failed: %#x\n", status);
+ ret = -ENODEV;
+ }
+
+ return ret;
+}
+
static int cs35l41_hda_read_acpi(struct cs35l41_hda *cs35l41, const char *hid, int id)
{
struct cs35l41_hw_cfg *hw_cfg = &cs35l41->hw_cfg;
@@ -563,6 +593,12 @@ static int cs35l41_hda_read_acpi(struct cs35l41_hda *cs35l41, const char *hid, i
physdev = get_device(acpi_get_first_physical_node(adev));
acpi_dev_put(adev);
+ ret = cs35l41_get_acpi_sub_string(cs35l41->dev, adev, &cs35l41->acpi_subsystem_id);
+ if (ret)
+ dev_info(cs35l41->dev, "No Subsystem ID found in ACPI: %d", ret);
+ else
+ dev_dbg(cs35l41->dev, "Subsystem ID %s found", cs35l41->acpi_subsystem_id);
+
property = "cirrus,dev-index";
ret = device_property_count_u32(physdev, property);
if (ret <= 0)
--
2.34.1
From: Stefan Binding <[email protected]>
CS35L41 supports hibernation during suspend when using
DSP firmware.
When the driver suspends it will hibernate the part, if
firmware is running, and resume will wake from hibernation.
CS35L41 driver will suspend/resume when requested by
hda driver.
Note that suspend/resume and hibernation is only supported
when firmware is running.
Signed-off-by: Stefan Binding <[email protected]>
Signed-off-by: Vitaly Rodionov <[email protected]>
---
sound/pci/hda/cs35l41_hda.c | 109 +++++++++++++++++++++++++++++++-
sound/pci/hda/cs35l41_hda.h | 2 +
sound/pci/hda/cs35l41_hda_i2c.c | 1 +
sound/pci/hda/cs35l41_hda_spi.c | 1 +
sound/pci/hda/hda_component.h | 2 +
sound/pci/hda/patch_realtek.c | 25 +++++++-
6 files changed, 136 insertions(+), 4 deletions(-)
diff --git a/sound/pci/hda/cs35l41_hda.c b/sound/pci/hda/cs35l41_hda.c
index 8ca571706cd8..4f818229e62e 100644
--- a/sound/pci/hda/cs35l41_hda.c
+++ b/sound/pci/hda/cs35l41_hda.c
@@ -10,6 +10,7 @@
#include <linux/module.h>
#include <sound/hda_codec.h>
#include <sound/soc.h>
+#include <linux/pm_runtime.h>
#include "hda_local.h"
#include "hda_auto_parser.h"
#include "hda_jack.h"
@@ -435,6 +436,75 @@ static int cs35l41_hda_channel_map(struct device *dev, unsigned int tx_num, unsi
rx_slot);
}
+static int cs35l41_runtime_suspend(struct device *dev)
+{
+ struct cs35l41_hda *cs35l41 = dev_get_drvdata(dev);
+
+ dev_dbg(cs35l41->dev, "Suspend\n");
+
+ if (!cs35l41->firmware_running)
+ return 0;
+
+ if (cs35l41_enter_hibernate(cs35l41->dev, cs35l41->regmap, cs35l41->hw_cfg.bst_type) < 0)
+ return 0;
+
+ regcache_cache_only(cs35l41->regmap, true);
+ regcache_mark_dirty(cs35l41->regmap);
+
+ return 0;
+}
+
+static int cs35l41_runtime_resume(struct device *dev)
+{
+ struct cs35l41_hda *cs35l41 = dev_get_drvdata(dev);
+ int ret;
+
+ dev_dbg(cs35l41->dev, "Resume.\n");
+
+ if (cs35l41->hw_cfg.bst_type == CS35L41_EXT_BOOST_NO_VSPK_SWITCH) {
+ dev_dbg(cs35l41->dev, "System does not support Resume\n");
+ return 0;
+ }
+
+ if (!cs35l41->firmware_running)
+ return 0;
+
+ regcache_cache_only(cs35l41->regmap, false);
+
+ ret = cs35l41_exit_hibernate(cs35l41->dev, cs35l41->regmap);
+ if (ret) {
+ regcache_cache_only(cs35l41->regmap, true);
+ return ret;
+ }
+
+ /* Test key needs to be unlocked to allow the OTP settings to re-apply */
+ cs35l41_test_key_unlock(cs35l41->dev, cs35l41->regmap);
+ ret = regcache_sync(cs35l41->regmap);
+ cs35l41_test_key_lock(cs35l41->dev, cs35l41->regmap);
+ if (ret) {
+ dev_err(cs35l41->dev, "Failed to restore register cache: %d\n", ret);
+ return ret;
+ }
+
+ if (cs35l41->hw_cfg.bst_type == CS35L41_EXT_BOOST)
+ cs35l41_init_boost(cs35l41->dev, cs35l41->regmap, &cs35l41->hw_cfg);
+
+ return 0;
+}
+
+static int cs35l41_hda_suspend_hook(struct device *dev)
+{
+ dev_dbg(dev, "Request Suspend\n");
+ pm_runtime_mark_last_busy(dev);
+ return pm_runtime_put_autosuspend(dev);
+}
+
+static int cs35l41_hda_resume_hook(struct device *dev)
+{
+ dev_dbg(dev, "Request Resume\n");
+ return pm_runtime_get_sync(dev);
+}
+
static int cs35l41_smart_amp(struct cs35l41_hda *cs35l41)
{
int halo_sts;
@@ -492,19 +562,27 @@ static int cs35l41_hda_bind(struct device *dev, struct device *master, void *mas
if (comps->dev)
return -EBUSY;
+ pm_runtime_get_sync(dev);
+
comps->dev = dev;
if (!cs35l41->acpi_subsystem_id)
cs35l41->acpi_subsystem_id = devm_kasprintf(dev, GFP_KERNEL, "%.8x",
comps->codec->core.subsystem_id);
cs35l41->codec = comps->codec;
strscpy(comps->name, dev_name(dev), sizeof(comps->name));
- comps->playback_hook = cs35l41_hda_playback_hook;
mutex_lock(&cs35l41->fw_mutex);
if (cs35l41_smart_amp(cs35l41) < 0)
dev_warn(cs35l41->dev, "Cannot Run Firmware, reverting to dsp bypass...\n");
mutex_unlock(&cs35l41->fw_mutex);
+ comps->playback_hook = cs35l41_hda_playback_hook;
+ comps->suspend_hook = cs35l41_hda_suspend_hook;
+ comps->resume_hook = cs35l41_hda_resume_hook;
+
+ pm_runtime_mark_last_busy(dev);
+ pm_runtime_put_autosuspend(dev);
+
return 0;
}
@@ -600,7 +678,7 @@ static const struct regmap_irq cs35l41_reg_irqs[] = {
CS35L41_REG_IRQ(IRQ1_STATUS1, AMP_SHORT_ERR),
};
-static const struct regmap_irq_chip cs35l41_regmap_irq_chip = {
+static struct regmap_irq_chip cs35l41_regmap_irq_chip = {
.name = "cs35l41 IRQ1 Controller",
.status_base = CS35L41_IRQ1_STATUS1,
.mask_base = CS35L41_IRQ1_MASK1,
@@ -608,6 +686,7 @@ static const struct regmap_irq_chip cs35l41_regmap_irq_chip = {
.num_regs = 4,
.irqs = cs35l41_reg_irqs,
.num_irqs = ARRAY_SIZE(cs35l41_reg_irqs),
+ .runtime_pm = true,
};
static int cs35l41_hda_apply_properties(struct cs35l41_hda *cs35l41)
@@ -1017,13 +1096,23 @@ int cs35l41_hda_probe(struct device *dev, const char *device_name, int id, int i
mutex_init(&cs35l41->fw_mutex);
+ pm_runtime_set_autosuspend_delay(cs35l41->dev, 3000);
+ pm_runtime_use_autosuspend(cs35l41->dev);
+ pm_runtime_mark_last_busy(cs35l41->dev);
+ pm_runtime_set_active(cs35l41->dev);
+ pm_runtime_get_noresume(cs35l41->dev);
+ pm_runtime_enable(cs35l41->dev);
+
ret = cs35l41_hda_apply_properties(cs35l41);
if (ret)
- goto err;
+ goto err_pm;
+
+ pm_runtime_put_autosuspend(cs35l41->dev);
ret = component_add(cs35l41->dev, &cs35l41_hda_comp_ops);
if (ret) {
dev_err(cs35l41->dev, "Register component failed: %d\n", ret);
+ pm_runtime_disable(cs35l41->dev);
goto err;
}
@@ -1031,6 +1120,10 @@ int cs35l41_hda_probe(struct device *dev, const char *device_name, int id, int i
return 0;
+err_pm:
+ pm_runtime_disable(cs35l41->dev);
+ pm_runtime_put_noidle(cs35l41->dev);
+
err:
if (cs35l41_safe_reset(cs35l41->regmap, cs35l41->hw_cfg.bst_type))
gpiod_set_value_cansleep(cs35l41->reset_gpio, 0);
@@ -1044,17 +1137,27 @@ void cs35l41_hda_remove(struct device *dev)
{
struct cs35l41_hda *cs35l41 = dev_get_drvdata(dev);
+ pm_runtime_get_sync(cs35l41->dev);
+ pm_runtime_disable(cs35l41->dev);
+
if (cs35l41->halo_initialized)
cs35l41_remove_dsp(cs35l41);
component_del(cs35l41->dev, &cs35l41_hda_comp_ops);
+ pm_runtime_put_noidle(cs35l41->dev);
+
if (cs35l41_safe_reset(cs35l41->regmap, cs35l41->hw_cfg.bst_type))
gpiod_set_value_cansleep(cs35l41->reset_gpio, 0);
gpiod_put(cs35l41->reset_gpio);
}
EXPORT_SYMBOL_NS_GPL(cs35l41_hda_remove, SND_HDA_SCODEC_CS35L41);
+const struct dev_pm_ops cs35l41_hda_pm_ops = {
+ SET_RUNTIME_PM_OPS(cs35l41_runtime_suspend, cs35l41_runtime_resume, NULL)
+};
+EXPORT_SYMBOL_NS_GPL(cs35l41_hda_pm_ops, SND_HDA_SCODEC_CS35L41);
+
MODULE_DESCRIPTION("CS35L41 HDA Driver");
MODULE_IMPORT_NS(SND_HDA_CS_DSP_CONTROLS);
MODULE_AUTHOR("Lucas Tanure, Cirrus Logic Inc, <[email protected]>");
diff --git a/sound/pci/hda/cs35l41_hda.h b/sound/pci/hda/cs35l41_hda.h
index a9dbc1c19248..439c4b705328 100644
--- a/sound/pci/hda/cs35l41_hda.h
+++ b/sound/pci/hda/cs35l41_hda.h
@@ -57,6 +57,8 @@ enum halo_state {
HALO_STATE_CODE_RUN
};
+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);
diff --git a/sound/pci/hda/cs35l41_hda_i2c.c b/sound/pci/hda/cs35l41_hda_i2c.c
index e810b278fb91..a669090a18e8 100644
--- a/sound/pci/hda/cs35l41_hda_i2c.c
+++ b/sound/pci/hda/cs35l41_hda_i2c.c
@@ -55,6 +55,7 @@ static struct i2c_driver cs35l41_i2c_driver = {
.driver = {
.name = "cs35l41-hda",
.acpi_match_table = ACPI_PTR(cs35l41_acpi_hda_match),
+ .pm = &cs35l41_hda_pm_ops,
},
.id_table = cs35l41_hda_i2c_id,
.probe = cs35l41_hda_i2c_probe,
diff --git a/sound/pci/hda/cs35l41_hda_spi.c b/sound/pci/hda/cs35l41_hda_spi.c
index 22e088f28438..d7f15e2abe66 100644
--- a/sound/pci/hda/cs35l41_hda_spi.c
+++ b/sound/pci/hda/cs35l41_hda_spi.c
@@ -50,6 +50,7 @@ static struct spi_driver cs35l41_spi_driver = {
.driver = {
.name = "cs35l41-hda",
.acpi_match_table = ACPI_PTR(cs35l41_acpi_hda_match),
+ .pm = &cs35l41_hda_pm_ops,
},
.id_table = cs35l41_hda_spi_id,
.probe = cs35l41_hda_spi_probe,
diff --git a/sound/pci/hda/hda_component.h b/sound/pci/hda/hda_component.h
index 534e845b9cd1..1223621bd62c 100644
--- a/sound/pci/hda/hda_component.h
+++ b/sound/pci/hda/hda_component.h
@@ -16,4 +16,6 @@ struct hda_component {
char name[HDA_MAX_NAME_SIZE];
struct hda_codec *codec;
void (*playback_hook)(struct device *dev, int action);
+ int (*suspend_hook)(struct device *dev);
+ int (*resume_hook)(struct device *dev);
};
diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
index 0369e19cd4bd..0060cfc8389e 100644
--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -4021,15 +4021,22 @@ static void alc5505_dsp_init(struct hda_codec *codec)
static int alc269_suspend(struct hda_codec *codec)
{
struct alc_spec *spec = codec->spec;
+ int i;
if (spec->has_alc5505_dsp)
alc5505_dsp_suspend(codec);
+
+ for (i = 0; i < HDA_MAX_COMPONENTS; i++)
+ if (spec->comps[i].suspend_hook)
+ spec->comps[i].suspend_hook(spec->comps[i].dev);
+
return alc_suspend(codec);
}
static int alc269_resume(struct hda_codec *codec)
{
struct alc_spec *spec = codec->spec;
+ int i;
if (spec->codec_variant == ALC269_TYPE_ALC269VB)
alc269vb_toggle_power_output(codec, 0);
@@ -4060,6 +4067,10 @@ static int alc269_resume(struct hda_codec *codec)
if (spec->has_alc5505_dsp)
alc5505_dsp_resume(codec);
+ for (i = 0; i < HDA_MAX_COMPONENTS; i++)
+ if (spec->comps[i].resume_hook)
+ spec->comps[i].resume_hook(spec->comps[i].dev);
+
return 0;
}
#endif /* CONFIG_PM */
@@ -6610,8 +6621,20 @@ static int comp_bind(struct device *dev)
{
struct hda_codec *cdc = dev_to_hda_codec(dev);
struct alc_spec *spec = cdc->spec;
+ int ret, i;
+
+ ret = component_bind_all(dev, spec->comps);
+ if (ret)
+ return ret;
- return component_bind_all(dev, spec->comps);
+ if (snd_hdac_is_power_on(&cdc->core)) {
+ codec_dbg(cdc, "Resuming after bind.\n");
+ for (i = 0; i < HDA_MAX_COMPONENTS; i++)
+ if (spec->comps[i].resume_hook)
+ spec->comps[i].resume_hook(spec->comps[i].dev);
+ }
+
+ return 0;
}
static void comp_unbind(struct device *dev)
--
2.34.1
From: Stefan Binding <[email protected]>
The cs35l41 part contains a DSP which is able to run firmware.
The cs_dsp library can be used to control the DSP.
These controls can be exposed to userspace using ALSA controls.
This library adds apis to be able to interface between
cs_dsp and hda drivers and expose the relevant controls as
ALSA controls.
Signed-off-by: Stefan Binding <[email protected]>
Signed-off-by: Vitaly Rodionov <[email protected]>
---
MAINTAINERS | 1 +
sound/pci/hda/Kconfig | 4 +
sound/pci/hda/Makefile | 2 +
sound/pci/hda/hda_cs_dsp_ctl.c | 193 +++++++++++++++++++++++++++++++++
sound/pci/hda/hda_cs_dsp_ctl.h | 33 ++++++
5 files changed, 233 insertions(+)
create mode 100644 sound/pci/hda/hda_cs_dsp_ctl.c
create mode 100644 sound/pci/hda/hda_cs_dsp_ctl.h
diff --git a/MAINTAINERS b/MAINTAINERS
index 3547b6eddbab..4438e206d648 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -4803,6 +4803,7 @@ S: Maintained
F: Documentation/devicetree/bindings/sound/cirrus,cs*
F: include/dt-bindings/sound/cs*
F: sound/pci/hda/cs*
+F: sound/pci/hda/hda_cs_dsp_ctl.*
F: sound/soc/codecs/cs*
CIRRUS LOGIC DSP FIRMWARE DRIVER
diff --git a/sound/pci/hda/Kconfig b/sound/pci/hda/Kconfig
index 79ade4787d95..d1fd6cf82beb 100644
--- a/sound/pci/hda/Kconfig
+++ b/sound/pci/hda/Kconfig
@@ -94,6 +94,10 @@ config SND_HDA_PATCH_LOADER
config SND_HDA_SCODEC_CS35L41
tristate
+config SND_HDA_CS_DSP_CONTROLS
+ tristate
+ depends on CS_DSP
+
config SND_HDA_SCODEC_CS35L41_I2C
tristate "Build CS35L41 HD-audio side codec support for I2C Bus"
depends on I2C
diff --git a/sound/pci/hda/Makefile b/sound/pci/hda/Makefile
index 3e7bc608d45f..00d306104484 100644
--- a/sound/pci/hda/Makefile
+++ b/sound/pci/hda/Makefile
@@ -31,6 +31,7 @@ snd-hda-codec-hdmi-objs := patch_hdmi.o hda_eld.o
snd-hda-scodec-cs35l41-objs := cs35l41_hda.o
snd-hda-scodec-cs35l41-i2c-objs := cs35l41_hda_i2c.o
snd-hda-scodec-cs35l41-spi-objs := cs35l41_hda_spi.o
+snd-hda-cs-dsp-ctls-objs := hda_cs_dsp_ctl.o
# common driver
obj-$(CONFIG_SND_HDA) := snd-hda-codec.o
@@ -54,6 +55,7 @@ obj-$(CONFIG_SND_HDA_CODEC_HDMI) += snd-hda-codec-hdmi.o
obj-$(CONFIG_SND_HDA_SCODEC_CS35L41) += snd-hda-scodec-cs35l41.o
obj-$(CONFIG_SND_HDA_SCODEC_CS35L41_I2C) += snd-hda-scodec-cs35l41-i2c.o
obj-$(CONFIG_SND_HDA_SCODEC_CS35L41_SPI) += snd-hda-scodec-cs35l41-spi.o
+obj-$(CONFIG_SND_HDA_CS_DSP_CONTROLS) += snd-hda-cs-dsp-ctls.o
# this must be the last entry after codec drivers;
# otherwise the codec patches won't be hooked before the PCI probe
diff --git a/sound/pci/hda/hda_cs_dsp_ctl.c b/sound/pci/hda/hda_cs_dsp_ctl.c
new file mode 100644
index 000000000000..74e2c5bd1b08
--- /dev/null
+++ b/sound/pci/hda/hda_cs_dsp_ctl.c
@@ -0,0 +1,193 @@
+// SPDX-License-Identifier: GPL-2.0
+//
+// HDA DSP ALSA Control Driver
+//
+// Copyright 2022 Cirrus Logic, Inc.
+//
+// Author: Stefan Binding <[email protected]>
+
+#include <linux/module.h>
+#include <sound/soc.h>
+#include <linux/firmware/cirrus/cs_dsp.h>
+#include <linux/firmware/cirrus/wmfw.h>
+#include "hda_cs_dsp_ctl.h"
+
+#define ADSP_MAX_STD_CTRL_SIZE 512
+
+struct hda_cs_dsp_coeff_ctl {
+ struct cs_dsp_coeff_ctl *cs_ctl;
+ struct snd_card *card;
+ struct snd_kcontrol *kctl;
+};
+
+static const char * const hda_cs_dsp_fw_text[HDA_CS_DSP_NUM_FW] = {
+ [HDA_CS_DSP_FW_SPK_PROT] = "Prot",
+ [HDA_CS_DSP_FW_SPK_CALI] = "Cali",
+ [HDA_CS_DSP_FW_SPK_DIAG] = "Diag",
+ [HDA_CS_DSP_FW_MISC] = "Misc",
+};
+
+static int hda_cs_dsp_coeff_info(struct snd_kcontrol *kctl, struct snd_ctl_elem_info *uinfo)
+{
+ struct hda_cs_dsp_coeff_ctl *ctl = (struct hda_cs_dsp_coeff_ctl *)snd_kcontrol_chip(kctl);
+ struct cs_dsp_coeff_ctl *cs_ctl = ctl->cs_ctl;
+
+ uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
+ uinfo->count = cs_ctl->len;
+
+ return 0;
+}
+
+static int hda_cs_dsp_coeff_put(struct snd_kcontrol *kctl, struct snd_ctl_elem_value *ucontrol)
+{
+ struct hda_cs_dsp_coeff_ctl *ctl = (struct hda_cs_dsp_coeff_ctl *)snd_kcontrol_chip(kctl);
+ struct cs_dsp_coeff_ctl *cs_ctl = ctl->cs_ctl;
+ char *p = ucontrol->value.bytes.data;
+ int ret = 0;
+
+ mutex_lock(&cs_ctl->dsp->pwr_lock);
+ ret = cs_dsp_coeff_write_ctrl(cs_ctl, 0, p, cs_ctl->len);
+ mutex_unlock(&cs_ctl->dsp->pwr_lock);
+
+ return ret;
+}
+
+static int hda_cs_dsp_coeff_get(struct snd_kcontrol *kctl, struct snd_ctl_elem_value *ucontrol)
+{
+ struct hda_cs_dsp_coeff_ctl *ctl = (struct hda_cs_dsp_coeff_ctl *)snd_kcontrol_chip(kctl);
+ struct cs_dsp_coeff_ctl *cs_ctl = ctl->cs_ctl;
+ char *p = ucontrol->value.bytes.data;
+ int ret;
+
+ mutex_lock(&cs_ctl->dsp->pwr_lock);
+ ret = cs_dsp_coeff_read_ctrl(cs_ctl, 0, p, cs_ctl->len);
+ mutex_unlock(&cs_ctl->dsp->pwr_lock);
+
+ return ret;
+}
+
+static unsigned int wmfw_convert_flags(unsigned int in)
+{
+ unsigned int out, rd, wr, vol;
+
+ rd = SNDRV_CTL_ELEM_ACCESS_READ;
+ wr = SNDRV_CTL_ELEM_ACCESS_WRITE;
+ vol = SNDRV_CTL_ELEM_ACCESS_VOLATILE;
+
+ out = 0;
+
+ if (in) {
+ out |= rd;
+ if (in & WMFW_CTL_FLAG_WRITEABLE)
+ out |= wr;
+ if (in & WMFW_CTL_FLAG_VOLATILE)
+ out |= vol;
+ } else {
+ out |= rd | wr | vol;
+ }
+
+ return out;
+}
+
+static int hda_cs_dsp_add_kcontrol(struct hda_cs_dsp_coeff_ctl *ctl, const char *name)
+{
+ struct cs_dsp_coeff_ctl *cs_ctl = ctl->cs_ctl;
+ struct snd_kcontrol_new kcontrol = {0};
+ struct snd_kcontrol *kctl;
+ int ret = 0;
+
+ if (cs_ctl->len > ADSP_MAX_STD_CTRL_SIZE) {
+ dev_err(cs_ctl->dsp->dev, "KControl %s: length %zu exceeds maximum %d\n", name,
+ cs_ctl->len, ADSP_MAX_STD_CTRL_SIZE);
+ return -EINVAL;
+ }
+
+ kcontrol.name = name;
+ kcontrol.info = hda_cs_dsp_coeff_info;
+ kcontrol.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
+ kcontrol.access = wmfw_convert_flags(cs_ctl->flags);
+ kcontrol.get = hda_cs_dsp_coeff_get;
+ kcontrol.put = hda_cs_dsp_coeff_put;
+
+ /* Save ctl inside private_data, ctl is owned by cs_dsp,
+ * and will be freed when cs_dsp removes the control */
+ kctl = snd_ctl_new1(&kcontrol, (void *)ctl);
+ if (!kctl) {
+ ret = -ENOMEM;
+ return ret;
+ }
+
+ ret = snd_ctl_add(ctl->card, kctl);
+ if (ret) {
+ dev_err(cs_ctl->dsp->dev, "Failed to add KControl %s = %d\n", kcontrol.name, ret);
+ return ret;
+ }
+
+ dev_dbg(cs_ctl->dsp->dev, "Added KControl: %s\n", kcontrol.name);
+ ctl->kctl = kctl;
+
+ return 0;
+}
+
+int hda_cs_dsp_control_add(struct cs_dsp_coeff_ctl *cs_ctl, struct hda_cs_dsp_ctl_info *info)
+{
+ struct cs_dsp *cs_dsp = cs_ctl->dsp;
+ char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
+ struct hda_cs_dsp_coeff_ctl *ctl;
+ const char *region_name;
+ int ret;
+
+ if (cs_ctl->flags & WMFW_CTL_FLAG_SYS)
+ return 0;
+
+ region_name = cs_dsp_mem_region_name(cs_ctl->alg_region.type);
+ if (!region_name) {
+ dev_err(cs_dsp->dev, "Unknown region type: %d\n", cs_ctl->alg_region.type);
+ return -EINVAL;
+ }
+
+ ret = scnprintf(name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN, "%s %s %.12s %x", info->device_name,
+ cs_dsp->name, hda_cs_dsp_fw_text[info->fw_type], cs_ctl->alg_region.alg);
+
+ if (cs_ctl->subname) {
+ int avail = SNDRV_CTL_ELEM_ID_NAME_MAXLEN - ret - 2;
+ int skip = 0;
+
+ /* Truncate the subname from the start if it is too long */
+ if (cs_ctl->subname_len > avail)
+ skip = cs_ctl->subname_len - avail;
+
+ snprintf(name + ret, SNDRV_CTL_ELEM_ID_NAME_MAXLEN - ret,
+ " %.*s", cs_ctl->subname_len - skip, cs_ctl->subname + skip);
+ }
+
+ ctl = kzalloc(sizeof(*ctl), GFP_KERNEL);
+ if (!ctl)
+ return -ENOMEM;
+
+ ctl->cs_ctl = cs_ctl;
+ ctl->card = info->card;
+ cs_ctl->priv = ctl;
+
+ ret = hda_cs_dsp_add_kcontrol(ctl, name);
+ if (ret) {
+ dev_err(cs_dsp->dev, "Error (%d) adding control %s\n", ret, name);
+ kfree(ctl);
+ return ret;
+ }
+
+ return 0;
+}
+EXPORT_SYMBOL_NS_GPL(hda_cs_dsp_control_add, SND_HDA_CS_DSP_CONTROLS);
+
+void hda_cs_dsp_control_remove(struct cs_dsp_coeff_ctl *cs_ctl)
+{
+ struct hda_cs_dsp_coeff_ctl *ctl = cs_ctl->priv;
+
+ kfree(ctl);
+}
+EXPORT_SYMBOL_NS_GPL(hda_cs_dsp_control_remove, SND_HDA_CS_DSP_CONTROLS);
+
+MODULE_DESCRIPTION("CS_DSP ALSA Control HDA Library");
+MODULE_AUTHOR("Stefan Binding, <[email protected]>");
+MODULE_LICENSE("GPL");
diff --git a/sound/pci/hda/hda_cs_dsp_ctl.h b/sound/pci/hda/hda_cs_dsp_ctl.h
new file mode 100644
index 000000000000..1c6d0fc9a2cc
--- /dev/null
+++ b/sound/pci/hda/hda_cs_dsp_ctl.h
@@ -0,0 +1,33 @@
+/* SPDX-License-Identifier: GPL-2.0
+ *
+ * HDA DSP ALSA Control Driver
+ *
+ * Copyright 2022 Cirrus Logic, Inc.
+ *
+ * Author: Stefan Binding <[email protected]>
+ */
+
+#ifndef __HDA_CS_DSP_CTL_H__
+#define __HDA_CS_DSP_CTL_H__
+
+#include <sound/soc.h>
+#include <linux/firmware/cirrus/cs_dsp.h>
+
+enum hda_cs_dsp_fw_id {
+ HDA_CS_DSP_FW_SPK_PROT,
+ HDA_CS_DSP_FW_SPK_CALI,
+ HDA_CS_DSP_FW_SPK_DIAG,
+ HDA_CS_DSP_FW_MISC,
+ HDA_CS_DSP_NUM_FW
+};
+
+struct hda_cs_dsp_ctl_info {
+ struct snd_card *card;
+ enum hda_cs_dsp_fw_id fw_type;
+ const char *device_name;
+};
+
+int hda_cs_dsp_control_add(struct cs_dsp_coeff_ctl *cs_ctl, struct hda_cs_dsp_ctl_info *info);
+void hda_cs_dsp_control_remove(struct cs_dsp_coeff_ctl *cs_ctl);
+
+#endif /*__HDA_CS_DSP_CTL_H__*/
--
2.34.1
From: Stefan Binding <[email protected]>
Some Laptops use a number of gpios to define which vendor is
used for a particular laptop.
Different coefficient files are used for different vendors.
Signed-off-by: Stefan Binding <[email protected]>
Signed-off-by: Vitaly Rodionov <[email protected]>
---
sound/pci/hda/cs35l41_hda.c | 174 ++++++++++++++++++++++++++++++++++--
sound/pci/hda/cs35l41_hda.h | 1 +
2 files changed, 166 insertions(+), 9 deletions(-)
diff --git a/sound/pci/hda/cs35l41_hda.c b/sound/pci/hda/cs35l41_hda.c
index b3561d72df2a..8ca571706cd8 100644
--- a/sound/pci/hda/cs35l41_hda.c
+++ b/sound/pci/hda/cs35l41_hda.c
@@ -86,13 +86,19 @@ static const struct cs_dsp_client_ops client_ops = {
static int cs35l41_request_firmware_file(struct cs35l41_hda *cs35l41,
const struct firmware **firmware, char **filename,
const char *dir, const char *ssid, const char *amp_name,
- const char *filetype)
+ int spkid, const char *filetype)
{
const char * const dsp_name = cs35l41->cs_dsp.name;
char *s, c;
int ret = 0;
- if (ssid && amp_name)
+ if (spkid > -1 && ssid && amp_name)
+ *filename = kasprintf(GFP_KERNEL, "%s%s-%s-%s-%s-spkid%d-%s.%s", dir, CS35L41_PART,
+ dsp_name, "spk-prot", ssid, spkid, amp_name, filetype);
+ else if (spkid > -1 && ssid)
+ *filename = kasprintf(GFP_KERNEL, "%s%s-%s-%s-%s-spkid%d.%s", dir, CS35L41_PART,
+ dsp_name, "spk-prot", ssid, spkid, filetype);
+ else if (ssid && amp_name)
*filename = kasprintf(GFP_KERNEL, "%s%s-%s-%s-%s-%s.%s", dir, CS35L41_PART,
dsp_name, "spk-prot", ssid, amp_name,
filetype);
@@ -130,6 +136,93 @@ static int cs35l41_request_firmware_file(struct cs35l41_hda *cs35l41,
return ret;
}
+static int cs35l41_request_firmware_files_spkid(struct cs35l41_hda *cs35l41,
+ const struct firmware **wmfw_firmware,
+ char **wmfw_filename,
+ const struct firmware **coeff_firmware,
+ char **coeff_filename)
+{
+ int ret;
+
+ /* try cirrus/part-dspN-fwtype-sub<-spkidN><-ampname>.wmfw */
+ ret = cs35l41_request_firmware_file(cs35l41, wmfw_firmware, wmfw_filename,
+ CS35L41_FIRMWARE_ROOT,
+ cs35l41->acpi_subsystem_id, cs35l41->amp_name,
+ cs35l41->speaker_id, "wmfw");
+ if (!ret) {
+ /* try cirrus/part-dspN-fwtype-sub<-spkidN><-ampname>.bin */
+ cs35l41_request_firmware_file(cs35l41, coeff_firmware, coeff_filename,
+ CS35L41_FIRMWARE_ROOT,
+ cs35l41->acpi_subsystem_id, cs35l41->amp_name,
+ cs35l41->speaker_id, "bin");
+ return 0;
+ }
+
+ /* try cirrus/part-dspN-fwtype-sub<-ampname>.wmfw */
+ ret = cs35l41_request_firmware_file(cs35l41, wmfw_firmware, wmfw_filename,
+ CS35L41_FIRMWARE_ROOT, cs35l41->acpi_subsystem_id,
+ cs35l41->amp_name, -1, "wmfw");
+ if (!ret) {
+ /* try cirrus/part-dspN-fwtype-sub<-spkidN><-ampname>.bin */
+ cs35l41_request_firmware_file(cs35l41, coeff_firmware, coeff_filename,
+ CS35L41_FIRMWARE_ROOT, cs35l41->acpi_subsystem_id,
+ cs35l41->amp_name, cs35l41->speaker_id, "bin");
+ return 0;
+ }
+
+ /* try cirrus/part-dspN-fwtype-sub<-spkidN>.wmfw */
+ ret = cs35l41_request_firmware_file(cs35l41, wmfw_firmware, wmfw_filename,
+ CS35L41_FIRMWARE_ROOT, cs35l41->acpi_subsystem_id,
+ NULL, cs35l41->speaker_id, "wmfw");
+ if (!ret) {
+ /* try cirrus/part-dspN-fwtype-sub<-spkidN><-ampname>.bin */
+ ret = cs35l41_request_firmware_file(cs35l41, coeff_firmware, coeff_filename,
+ CS35L41_FIRMWARE_ROOT,
+ cs35l41->acpi_subsystem_id,
+ cs35l41->amp_name, cs35l41->speaker_id, "bin");
+ if (ret)
+ /* try cirrus/part-dspN-fwtype-sub<-spkidN>.bin */
+ cs35l41_request_firmware_file(cs35l41, coeff_firmware, coeff_filename,
+ CS35L41_FIRMWARE_ROOT,
+ cs35l41->acpi_subsystem_id,
+ NULL, cs35l41->speaker_id, "bin");
+ return 0;
+ }
+
+ /* try cirrus/part-dspN-fwtype-sub.wmfw */
+ ret = cs35l41_request_firmware_file(cs35l41, wmfw_firmware, wmfw_filename,
+ CS35L41_FIRMWARE_ROOT, cs35l41->acpi_subsystem_id,
+ NULL, -1, "wmfw");
+ if (!ret) {
+ /* try cirrus/part-dspN-fwtype-sub<-spkidN><-ampname>.bin */
+ ret = cs35l41_request_firmware_file(cs35l41, coeff_firmware, coeff_filename,
+ CS35L41_FIRMWARE_ROOT,
+ cs35l41->acpi_subsystem_id,
+ cs35l41->amp_name, cs35l41->speaker_id, "bin");
+ if (ret)
+ /* try cirrus/part-dspN-fwtype-sub<-spkidN>.bin */
+ cs35l41_request_firmware_file(cs35l41, coeff_firmware, coeff_filename,
+ CS35L41_FIRMWARE_ROOT,
+ cs35l41->acpi_subsystem_id,
+ NULL, cs35l41->speaker_id, "bin");
+ return 0;
+ }
+
+ /* fallback try cirrus/part-dspN-fwtype.wmfw */
+ ret = cs35l41_request_firmware_file(cs35l41, wmfw_firmware, wmfw_filename,
+ CS35L41_FIRMWARE_ROOT, NULL, NULL, -1, "wmfw");
+ if (!ret) {
+ /* fallback try cirrus/part-dspN-fwtype.bin */
+ cs35l41_request_firmware_file(cs35l41, coeff_firmware, coeff_filename,
+ CS35L41_FIRMWARE_ROOT, NULL, NULL, -1, "bin");
+ return 0;
+ }
+
+ dev_warn(cs35l41->dev, "Failed to request firmware\n");
+
+ return ret;
+}
+
static int cs35l41_request_firmware_files(struct cs35l41_hda *cs35l41,
const struct firmware **wmfw_firmware,
char **wmfw_filename,
@@ -138,43 +231,48 @@ static int cs35l41_request_firmware_files(struct cs35l41_hda *cs35l41,
{
int ret;
+ if (cs35l41->speaker_id > -1)
+ return cs35l41_request_firmware_files_spkid(cs35l41, wmfw_firmware, wmfw_filename,
+ coeff_firmware, coeff_filename);
+
/* try cirrus/part-dspN-fwtype-sub<-ampname>.wmfw */
ret = cs35l41_request_firmware_file(cs35l41, wmfw_firmware, wmfw_filename,
CS35L41_FIRMWARE_ROOT, cs35l41->acpi_subsystem_id,
- cs35l41->amp_name, "wmfw");
+ cs35l41->amp_name, -1, "wmfw");
if (!ret) {
/* try cirrus/part-dspN-fwtype-sub<-ampname>.bin */
cs35l41_request_firmware_file(cs35l41, coeff_firmware, coeff_filename,
CS35L41_FIRMWARE_ROOT, cs35l41->acpi_subsystem_id,
- cs35l41->amp_name, "bin");
+ cs35l41->amp_name, -1, "bin");
return 0;
}
/* try cirrus/part-dspN-fwtype-sub.wmfw */
ret = cs35l41_request_firmware_file(cs35l41, wmfw_firmware, wmfw_filename,
CS35L41_FIRMWARE_ROOT, cs35l41->acpi_subsystem_id,
- NULL, "wmfw");
+ NULL, -1, "wmfw");
if (!ret) {
/* try cirrus/part-dspN-fwtype-sub<-ampname>.bin */
ret = cs35l41_request_firmware_file(cs35l41, coeff_firmware, coeff_filename,
CS35L41_FIRMWARE_ROOT,
cs35l41->acpi_subsystem_id,
- cs35l41->amp_name, "bin");
+ cs35l41->amp_name, -1, "bin");
if (ret)
/* try cirrus/part-dspN-fwtype-sub.bin */
cs35l41_request_firmware_file(cs35l41, coeff_firmware, coeff_filename,
CS35L41_FIRMWARE_ROOT,
- cs35l41->acpi_subsystem_id, NULL, "bin");
+ cs35l41->acpi_subsystem_id,
+ NULL, -1, "bin");
return 0;
}
/* fallback try cirrus/part-dspN-fwtype.wmfw */
ret = cs35l41_request_firmware_file(cs35l41, wmfw_firmware, wmfw_filename,
- CS35L41_FIRMWARE_ROOT, NULL, NULL, "wmfw");
+ CS35L41_FIRMWARE_ROOT, NULL, NULL, -1, "wmfw");
if (!ret) {
/* fallback try cirrus/part-dspN-fwtype.bin */
cs35l41_request_firmware_file(cs35l41, coeff_firmware, coeff_filename,
- CS35L41_FIRMWARE_ROOT, NULL, NULL, "bin");
+ CS35L41_FIRMWARE_ROOT, NULL, NULL, -1, "bin");
return 0;
}
@@ -614,6 +712,61 @@ static int cs35l41_get_acpi_sub_string(struct device *dev, struct acpi_device *a
return ret;
}
+static int cs35l41_get_speaker_id(struct device *dev, int amp_index,
+ int num_amps, int fixed_gpio_id)
+{
+ struct gpio_desc *speaker_id_desc;
+ int speaker_id = -ENODEV;
+
+ if (fixed_gpio_id >= 0) {
+ dev_dbg(dev, "Found Fixed Speaker ID GPIO (index = %d)\n", fixed_gpio_id);
+ speaker_id_desc = gpiod_get_index(dev, NULL, fixed_gpio_id, GPIOD_IN);
+ if (IS_ERR(speaker_id_desc)) {
+ speaker_id = PTR_ERR(speaker_id_desc);
+ return speaker_id;
+ }
+ speaker_id = gpiod_get_value_cansleep(speaker_id_desc);
+ gpiod_put(speaker_id_desc);
+ dev_dbg(dev, "Speaker ID = %d\n", speaker_id);
+ } else {
+ int base_index;
+ int gpios_per_amp;
+ int count;
+ int tmp;
+ int i;
+
+ count = gpiod_count(dev, "spk-id");
+ if (count > 0) {
+ speaker_id = 0;
+ gpios_per_amp = count / num_amps;
+ base_index = gpios_per_amp * amp_index;
+
+ if (count % num_amps)
+ return -EINVAL;
+
+ dev_dbg(dev, "Found %d Speaker ID GPIOs per Amp\n", gpios_per_amp);
+
+ for (i = 0; i < gpios_per_amp; i++) {
+ speaker_id_desc = gpiod_get_index(dev, "spk-id", i + base_index,
+ GPIOD_IN);
+ if (IS_ERR(speaker_id_desc)) {
+ speaker_id = PTR_ERR(speaker_id_desc);
+ break;
+ }
+ tmp = gpiod_get_value_cansleep(speaker_id_desc);
+ gpiod_put(speaker_id_desc);
+ if (tmp < 0) {
+ speaker_id = tmp;
+ break;
+ }
+ speaker_id |= tmp << i;
+ }
+ dev_dbg(dev, "Speaker ID = %d\n", speaker_id);
+ }
+ }
+ return speaker_id;
+}
+
static int cs35l41_hda_read_acpi(struct cs35l41_hda *cs35l41, const char *hid, int id)
{
struct cs35l41_hw_cfg *hw_cfg = &cs35l41->hw_cfg;
@@ -719,6 +872,8 @@ static int cs35l41_hda_read_acpi(struct cs35l41_hda *cs35l41, const char *hid, i
else
hw_cfg->bst_cap = -1;
+ cs35l41->speaker_id = cs35l41_get_speaker_id(physdev, cs35l41->index, nval, -1);
+
if (hw_cfg->bst_ind > 0 || hw_cfg->bst_cap > 0 || hw_cfg->bst_ipk > 0)
hw_cfg->bst_type = CS35L41_INT_BOOST;
else
@@ -752,6 +907,7 @@ static int cs35l41_hda_read_acpi(struct cs35l41_hda *cs35l41, const char *hid, i
cs35l41->channel_index = 0;
cs35l41->reset_gpio = gpiod_get_index(physdev, NULL, 0, GPIOD_OUT_HIGH);
cs35l41->hw_cfg.bst_type = CS35L41_EXT_BOOST_NO_VSPK_SWITCH;
+ cs35l41->speaker_id = cs35l41_get_speaker_id(physdev, 0, 0, 2);
hw_cfg->gpio2.func = CS35L41_GPIO2_INT_OPEN_DRAIN;
hw_cfg->gpio2.valid = true;
cs35l41->hw_cfg.valid = true;
diff --git a/sound/pci/hda/cs35l41_hda.h b/sound/pci/hda/cs35l41_hda.h
index b57f59a1ba49..a9dbc1c19248 100644
--- a/sound/pci/hda/cs35l41_hda.h
+++ b/sound/pci/hda/cs35l41_hda.h
@@ -43,6 +43,7 @@ struct cs35l41_hda {
unsigned volatile long irq_errors;
const char *amp_name;
const char *acpi_subsystem_id;
+ int speaker_id;
struct mutex fw_mutex;
struct regmap_irq_chip_data *irq_data;
bool firmware_running;
--
2.34.1
From: Stefan Binding <[email protected]>
To be able to support different firmwares and tuning
for different models, the driver needs to be able to
load a different firmware and coefficient file based
on its Subsystem ID.
The driver attempts to load the firmware in the
following order:
/lib/firmware/cirrus/cs35l41-dsp1-<fw-type>-<ssid>-dev<#>.wmfw
/lib/firmware/cirrus/cs35l41-dsp1-<fw-type>-<ssid>.wmfw
/lib/firmware/cirrus/cs35l41-dsp1-<fw-type>.wmfw
Signed-off-by: Stefan Binding <[email protected]>
Signed-off-by: Vitaly Rodionov <[email protected]>
---
sound/pci/hda/cs35l41_hda.c | 52 ++++++++++++++++++++++++++++++++-----
1 file changed, 46 insertions(+), 6 deletions(-)
diff --git a/sound/pci/hda/cs35l41_hda.c b/sound/pci/hda/cs35l41_hda.c
index 2af3bb5ea1fb..b3561d72df2a 100644
--- a/sound/pci/hda/cs35l41_hda.c
+++ b/sound/pci/hda/cs35l41_hda.c
@@ -85,14 +85,23 @@ static const struct cs_dsp_client_ops client_ops = {
static int cs35l41_request_firmware_file(struct cs35l41_hda *cs35l41,
const struct firmware **firmware, char **filename,
- const char *dir, const char *filetype)
+ const char *dir, const char *ssid, const char *amp_name,
+ const char *filetype)
{
const char * const dsp_name = cs35l41->cs_dsp.name;
char *s, c;
int ret = 0;
- *filename = kasprintf(GFP_KERNEL, "%s%s-%s-%s.%s", dir, CS35L41_PART, dsp_name, "spk-prot",
- filetype);
+ if (ssid && amp_name)
+ *filename = kasprintf(GFP_KERNEL, "%s%s-%s-%s-%s-%s.%s", dir, CS35L41_PART,
+ dsp_name, "spk-prot", ssid, amp_name,
+ filetype);
+ else if (ssid)
+ *filename = kasprintf(GFP_KERNEL, "%s%s-%s-%s-%s.%s", dir, CS35L41_PART,
+ dsp_name, "spk-prot", ssid, filetype);
+ else
+ *filename = kasprintf(GFP_KERNEL, "%s%s-%s-%s.%s", dir, CS35L41_PART,
+ dsp_name, "spk-prot", filetype);
if (*filename == NULL)
return -ENOMEM;
@@ -129,12 +138,43 @@ static int cs35l41_request_firmware_files(struct cs35l41_hda *cs35l41,
{
int ret;
- /* cirrus/part-dspN-fwtype.wmfw */
+ /* try cirrus/part-dspN-fwtype-sub<-ampname>.wmfw */
+ ret = cs35l41_request_firmware_file(cs35l41, wmfw_firmware, wmfw_filename,
+ CS35L41_FIRMWARE_ROOT, cs35l41->acpi_subsystem_id,
+ cs35l41->amp_name, "wmfw");
+ if (!ret) {
+ /* try cirrus/part-dspN-fwtype-sub<-ampname>.bin */
+ cs35l41_request_firmware_file(cs35l41, coeff_firmware, coeff_filename,
+ CS35L41_FIRMWARE_ROOT, cs35l41->acpi_subsystem_id,
+ cs35l41->amp_name, "bin");
+ return 0;
+ }
+
+ /* try cirrus/part-dspN-fwtype-sub.wmfw */
+ ret = cs35l41_request_firmware_file(cs35l41, wmfw_firmware, wmfw_filename,
+ CS35L41_FIRMWARE_ROOT, cs35l41->acpi_subsystem_id,
+ NULL, "wmfw");
+ if (!ret) {
+ /* try cirrus/part-dspN-fwtype-sub<-ampname>.bin */
+ ret = cs35l41_request_firmware_file(cs35l41, coeff_firmware, coeff_filename,
+ CS35L41_FIRMWARE_ROOT,
+ cs35l41->acpi_subsystem_id,
+ cs35l41->amp_name, "bin");
+ if (ret)
+ /* try cirrus/part-dspN-fwtype-sub.bin */
+ cs35l41_request_firmware_file(cs35l41, coeff_firmware, coeff_filename,
+ CS35L41_FIRMWARE_ROOT,
+ cs35l41->acpi_subsystem_id, NULL, "bin");
+ return 0;
+ }
+
+ /* fallback try cirrus/part-dspN-fwtype.wmfw */
ret = cs35l41_request_firmware_file(cs35l41, wmfw_firmware, wmfw_filename,
- CS35L41_FIRMWARE_ROOT, "wmfw");
+ CS35L41_FIRMWARE_ROOT, NULL, NULL, "wmfw");
if (!ret) {
+ /* fallback try cirrus/part-dspN-fwtype.bin */
cs35l41_request_firmware_file(cs35l41, coeff_firmware, coeff_filename,
- CS35L41_FIRMWARE_ROOT, "bin");
+ CS35L41_FIRMWARE_ROOT, NULL, NULL, "bin");
return 0;
}
--
2.34.1
From: Stefan Binding <[email protected]>
By default, the driver will automatically load DSP firmware
for the amps, if available. Adding this option allows the
autoload to be optional, which allows for different configurations.
Signed-off-by: Stefan Binding <[email protected]>
Signed-off-by: Vitaly Rodionov <[email protected]>
---
sound/pci/hda/cs35l41_hda.c | 21 ++++++++++++++++-----
1 file changed, 16 insertions(+), 5 deletions(-)
diff --git a/sound/pci/hda/cs35l41_hda.c b/sound/pci/hda/cs35l41_hda.c
index 5ae0b439d7e9..aa3d8fb3b2a2 100644
--- a/sound/pci/hda/cs35l41_hda.c
+++ b/sound/pci/hda/cs35l41_hda.c
@@ -8,6 +8,7 @@
#include <linux/acpi.h>
#include <linux/module.h>
+#include <linux/moduleparam.h>
#include <sound/hda_codec.h>
#include <sound/soc.h>
#include <linux/pm_runtime.h>
@@ -32,6 +33,11 @@
#define CAL_DSP_CTL_TYPE 5
#define CAL_DSP_CTL_ALG 205
+static bool firmware_autostart = 1;
+module_param(firmware_autostart, bool, 0444);
+MODULE_PARM_DESC(firmware_autostart, "Allow automatic firmware download on boot"
+ "(0=Disable, 1=Enable) (default=1); ");
+
static const struct reg_sequence cs35l41_hda_config[] = {
{ CS35L41_PLL_CLK_CTRL, 0x00000430 }, // 3072000Hz, BCLK Input, PLL_REFCLK_EN = 1
{ CS35L41_DSP_CLK_CTRL, 0x00000003 }, // DSP CLK EN
@@ -843,11 +849,16 @@ static int cs35l41_hda_bind(struct device *dev, struct device *master, void *mas
cs35l41->firmware_type = HDA_CS_DSP_FW_SPK_PROT;
- cs35l41->request_fw_load = true;
- mutex_lock(&cs35l41->fw_mutex);
- if (cs35l41_smart_amp(cs35l41) < 0)
- dev_warn(cs35l41->dev, "Cannot Run Firmware, reverting to dsp bypass...\n");
- mutex_unlock(&cs35l41->fw_mutex);
+ if (firmware_autostart) {
+ dev_dbg(cs35l41->dev, "Firmware Autostart.\n");
+ cs35l41->request_fw_load = true;
+ mutex_lock(&cs35l41->fw_mutex);
+ if (cs35l41_smart_amp(cs35l41) < 0)
+ dev_warn(cs35l41->dev, "Cannot Run Firmware, reverting to dsp bypass...\n");
+ mutex_unlock(&cs35l41->fw_mutex);
+ } else {
+ dev_dbg(cs35l41->dev, "Firmware Autostart is disabled.\n");
+ }
ret = cs35l41_create_controls(cs35l41);
--
2.34.1
From: Vitaly Rodionov <[email protected]>
This patch adds support for the CS35L41 DSP.
The DSP allows for extra features, such as running
speaker protection algorithms and hibernations.
To utilize these features, the driver must load
firmware into the DSP, as well as various tuning
files which allow for customization for specific
models.
Signed-off-by: Vitaly Rodionov <[email protected]>
Signed-off-by: Vitaly Rodionov <[email protected]>
---
include/sound/cs35l41.h | 4 +
sound/pci/hda/Kconfig | 4 +
sound/pci/hda/cs35l41_hda.c | 251 +++++++++++++++++++++++++++++++++++-
sound/pci/hda/cs35l41_hda.h | 13 ++
4 files changed, 271 insertions(+), 1 deletion(-)
diff --git a/include/sound/cs35l41.h b/include/sound/cs35l41.h
index a66ef37184fd..9ac5918269a5 100644
--- a/include/sound/cs35l41.h
+++ b/include/sound/cs35l41.h
@@ -665,6 +665,10 @@
#define CS35L41_BST_EN_DEFAULT 0x2
#define CS35L41_AMP_EN_SHIFT 0
#define CS35L41_AMP_EN_MASK 1
+#define CS35L41_VMON_EN_MASK 0x1000
+#define CS35L41_VMON_EN_SHIFT 12
+#define CS35L41_IMON_EN_MASK 0x2000
+#define CS35L41_IMON_EN_SHIFT 13
#define CS35L41_PDN_DONE_MASK 0x00800000
#define CS35L41_PDN_DONE_SHIFT 23
diff --git a/sound/pci/hda/Kconfig b/sound/pci/hda/Kconfig
index d1fd6cf82beb..1c378cca5dac 100644
--- a/sound/pci/hda/Kconfig
+++ b/sound/pci/hda/Kconfig
@@ -106,6 +106,8 @@ config SND_HDA_SCODEC_CS35L41_I2C
select SND_HDA_GENERIC
select SND_SOC_CS35L41_LIB
select SND_HDA_SCODEC_CS35L41
+ select SND_HDA_CS_DSP_CONTROLS
+ select CS_DSP
select REGMAP_IRQ
help
Say Y or M here to include CS35L41 I2C HD-audio side codec support
@@ -122,6 +124,8 @@ config SND_HDA_SCODEC_CS35L41_SPI
select SND_HDA_GENERIC
select SND_SOC_CS35L41_LIB
select SND_HDA_SCODEC_CS35L41
+ select SND_HDA_CS_DSP_CONTROLS
+ select CS_DSP
select REGMAP_IRQ
help
Say Y or M here to include CS35L41 SPI HD-audio side codec support
diff --git a/sound/pci/hda/cs35l41_hda.c b/sound/pci/hda/cs35l41_hda.c
index bbbaafac50c3..e0d236eae93e 100644
--- a/sound/pci/hda/cs35l41_hda.c
+++ b/sound/pci/hda/cs35l41_hda.c
@@ -9,12 +9,22 @@
#include <linux/acpi.h>
#include <linux/module.h>
#include <sound/hda_codec.h>
+#include <sound/soc.h>
#include "hda_local.h"
#include "hda_auto_parser.h"
#include "hda_jack.h"
#include "hda_generic.h"
#include "hda_component.h"
#include "cs35l41_hda.h"
+#include "hda_cs_dsp_ctl.h"
+
+#define CS35L41_FIRMWARE_ROOT "cirrus/"
+#define CS35L41_PART "cs35l41"
+#define FW_NAME "CSPL"
+
+#define HALO_STATE_DSP_CTL_NAME "HALO_STATE"
+#define HALO_STATE_DSP_CTL_TYPE 5
+#define HALO_STATE_DSP_CTL_ALG 262308
static const struct reg_sequence cs35l41_hda_config[] = {
{ CS35L41_PLL_CLK_CTRL, 0x00000430 }, // 3072000Hz, BCLK Input, PLL_REFCLK_EN = 1
@@ -27,11 +37,172 @@ static const struct reg_sequence cs35l41_hda_config[] = {
{ CS35L41_AMP_GAIN_CTRL, 0x00000084 }, // AMP_GAIN_PCM 4.5 dB
};
+static const struct reg_sequence cs35l41_hda_config_dsp[] = {
+ { CS35L41_PLL_CLK_CTRL, 0x00000430 }, // 3072000Hz, BCLK Input, PLL_REFCLK_EN = 1
+ { CS35L41_DSP_CLK_CTRL, 0x00000003 }, // DSP CLK EN
+ { CS35L41_GLOBAL_CLK_CTRL, 0x00000003 }, // GLOBAL_FS = 48 kHz
+ { CS35L41_SP_ENABLES, 0x00010001 }, // ASP_RX1_EN = 1, ASP_TX1_EN = 1
+ { CS35L41_SP_RATE_CTRL, 0x00000021 }, // ASP_BCLK_FREQ = 3.072 MHz
+ { CS35L41_SP_FORMAT, 0x20200200 }, // 32 bits RX/TX slots, I2S, clk consumer
+ { CS35L41_SP_HIZ_CTRL, 0x00000003 }, // Hi-Z unused/disabled
+ { CS35L41_SP_TX_WL, 0x00000018 }, // 24 cycles/slot
+ { CS35L41_SP_RX_WL, 0x00000018 }, // 24 cycles/slot
+ { CS35L41_DAC_PCM1_SRC, 0x00000032 }, // DACPCM1_SRC = ERR_VOL
+ { CS35L41_ASP_TX1_SRC, 0x00000018 }, // ASPTX1 SRC = VMON
+ { CS35L41_ASP_TX2_SRC, 0x00000019 }, // ASPTX2 SRC = IMON
+ { CS35L41_ASP_TX3_SRC, 0x00000028 }, // ASPTX3 SRC = VPMON
+ { CS35L41_ASP_TX4_SRC, 0x00000029 }, // ASPTX4 SRC = VBSTMON
+ { CS35L41_DSP1_RX1_SRC, 0x00000008 }, // DSP1RX1 SRC = ASPRX1
+ { CS35L41_DSP1_RX2_SRC, 0x00000008 }, // DSP1RX2 SRC = ASPRX1
+ { CS35L41_DSP1_RX3_SRC, 0x00000018 }, // DSP1RX3 SRC = VMON
+ { CS35L41_DSP1_RX4_SRC, 0x00000019 }, // DSP1RX4 SRC = IMON
+ { CS35L41_DSP1_RX5_SRC, 0x00000029 }, // DSP1RX5 SRC = VBSTMON
+ { CS35L41_AMP_DIG_VOL_CTRL, 0x00000000 }, // AMP_VOL_PCM 0.0 dB
+ { CS35L41_AMP_GAIN_CTRL, 0x00000233 }, // AMP_GAIN_PCM = 17.5dB AMP_GAIN_PDM = 19.5dB
+};
+
static const struct reg_sequence cs35l41_hda_mute[] = {
{ CS35L41_AMP_GAIN_CTRL, 0x00000000 }, // AMP_GAIN_PCM 0.5 dB
{ CS35L41_AMP_DIG_VOL_CTRL, 0x0000A678 }, // AMP_VOL_PCM Mute
};
+static int cs35l41_control_add(struct cs_dsp_coeff_ctl *cs_ctl)
+{
+ struct cs35l41_hda *cs35l41 = container_of(cs_ctl->dsp, struct cs35l41_hda, cs_dsp);
+ struct hda_cs_dsp_ctl_info info;
+
+ info.device_name = cs35l41->amp_name;
+ info.fw_type = HDA_CS_DSP_FW_SPK_PROT;
+ info.card = cs35l41->codec->card;
+
+ return hda_cs_dsp_control_add(cs_ctl, &info);
+}
+
+static const struct cs_dsp_client_ops client_ops = {
+ .control_add = cs35l41_control_add,
+ .control_remove = hda_cs_dsp_control_remove,
+};
+
+static int cs35l41_request_firmware_file(struct cs35l41_hda *cs35l41,
+ const struct firmware **firmware, char **filename,
+ const char *dir, const char *filetype)
+{
+ const char * const dsp_name = cs35l41->cs_dsp.name;
+ char *s, c;
+ int ret = 0;
+
+ *filename = kasprintf(GFP_KERNEL, "%s%s-%s-%s.%s", dir, CS35L41_PART, dsp_name, "spk-prot",
+ filetype);
+
+ if (*filename == NULL)
+ return -ENOMEM;
+
+ /*
+ * Make sure that filename is lower-case and any non alpha-numeric
+ * characters except full stop and '/' are replaced with hyphens.
+ */
+ s = *filename;
+ while (*s) {
+ c = *s;
+ if (isalnum(c))
+ *s = tolower(c);
+ else if (c != '.' && c != '/')
+ *s = '-';
+ s++;
+ }
+
+ ret = firmware_request_nowarn(firmware, *filename, cs35l41->dev);
+ if (ret != 0) {
+ dev_dbg(cs35l41->dev, "Failed to request '%s'\n", *filename);
+ kfree(*filename);
+ *filename = NULL;
+ }
+
+ return ret;
+}
+
+static int cs35l41_request_firmware_files(struct cs35l41_hda *cs35l41,
+ const struct firmware **wmfw_firmware,
+ char **wmfw_filename,
+ const struct firmware **coeff_firmware,
+ char **coeff_filename)
+{
+ int ret;
+
+ /* cirrus/part-dspN-fwtype.wmfw */
+ ret = cs35l41_request_firmware_file(cs35l41, wmfw_firmware, wmfw_filename,
+ CS35L41_FIRMWARE_ROOT, "wmfw");
+ if (!ret) {
+ cs35l41_request_firmware_file(cs35l41, coeff_firmware, coeff_filename,
+ CS35L41_FIRMWARE_ROOT, "bin");
+ return 0;
+ }
+
+ dev_warn(cs35l41->dev, "Failed to request firmware\n");
+
+ return ret;
+}
+
+static int cs35l41_init_dsp(struct cs35l41_hda *cs35l41)
+{
+ const struct firmware *coeff_firmware = NULL;
+ const struct firmware *wmfw_firmware = NULL;
+ struct cs_dsp *dsp = &cs35l41->cs_dsp;
+ char *coeff_filename = NULL;
+ char *wmfw_filename = NULL;
+ int ret;
+
+ if (!cs35l41->halo_initialized) {
+ cs35l41_configure_cs_dsp(cs35l41->dev, cs35l41->regmap, dsp);
+ dsp->client_ops = &client_ops;
+
+ ret = cs_dsp_halo_init(&cs35l41->cs_dsp);
+ if (ret)
+ return ret;
+ cs35l41->halo_initialized = true;
+ }
+
+ ret = cs35l41_request_firmware_files(cs35l41, &wmfw_firmware, &wmfw_filename,
+ &coeff_firmware, &coeff_filename);
+ if (ret < 0)
+ return ret;
+
+ dev_dbg(cs35l41->dev, "Loading WMFW Firmware: %s\n", wmfw_filename);
+ if (coeff_filename)
+ dev_dbg(cs35l41->dev, "Loading Coefficient File: %s\n", coeff_filename);
+ else
+ dev_warn(cs35l41->dev, "No Coefficient File available.\n");
+
+ ret = cs_dsp_power_up(dsp, wmfw_firmware, wmfw_filename, coeff_firmware, coeff_filename,
+ FW_NAME);
+
+ release_firmware(wmfw_firmware);
+ release_firmware(coeff_firmware);
+ kfree(wmfw_filename);
+ kfree(coeff_filename);
+
+ return ret;
+}
+
+static void cs35l41_shutdown_dsp(struct cs35l41_hda *cs35l41)
+{
+ struct cs_dsp *dsp = &cs35l41->cs_dsp;
+
+ cs_dsp_stop(dsp);
+ cs_dsp_power_down(dsp);
+ cs35l41->firmware_running = false;
+ dev_dbg(cs35l41->dev, "Unloaded Firmware\n");
+}
+
+static void cs35l41_remove_dsp(struct cs35l41_hda *cs35l41)
+{
+ struct cs_dsp *dsp = &cs35l41->cs_dsp;
+
+ cs35l41_shutdown_dsp(cs35l41);
+ cs_dsp_remove(dsp);
+ cs35l41->halo_initialized = false;
+}
+
/* Protection release cycle to get the speaker out of Safe-Mode */
static void cs35l41_error_release(struct device *dev, struct regmap *regmap, unsigned int mask)
{
@@ -53,9 +224,22 @@ static void cs35l41_hda_playback_hook(struct device *dev, int action)
struct regmap *reg = cs35l41->regmap;
int ret = 0;
+ mutex_lock(&cs35l41->fw_mutex);
+
switch (action) {
case HDA_GEN_PCM_ACT_OPEN:
- regmap_multi_reg_write(reg, cs35l41_hda_config, ARRAY_SIZE(cs35l41_hda_config));
+ if (cs35l41->firmware_running) {
+ regmap_multi_reg_write(reg, cs35l41_hda_config_dsp,
+ ARRAY_SIZE(cs35l41_hda_config_dsp));
+ regmap_update_bits(cs35l41->regmap, CS35L41_PWR_CTRL2,
+ CS35L41_VMON_EN_MASK | CS35L41_IMON_EN_MASK,
+ 1 << CS35L41_VMON_EN_SHIFT | 1 << CS35L41_IMON_EN_SHIFT);
+ cs35l41_set_cspl_mbox_cmd(cs35l41->dev, cs35l41->regmap,
+ CSPL_MBOX_CMD_RESUME);
+ } else {
+ regmap_multi_reg_write(reg, cs35l41_hda_config,
+ ARRAY_SIZE(cs35l41_hda_config));
+ }
ret = regmap_update_bits(reg, CS35L41_PWR_CTRL2,
CS35L41_AMP_EN_MASK, 1 << CS35L41_AMP_EN_SHIFT);
if (cs35l41->hw_cfg.bst_type == CS35L41_EXT_BOOST)
@@ -73,6 +257,13 @@ static void cs35l41_hda_playback_hook(struct device *dev, int action)
CS35L41_AMP_EN_MASK, 0 << CS35L41_AMP_EN_SHIFT);
if (cs35l41->hw_cfg.bst_type == CS35L41_EXT_BOOST)
regmap_write(reg, CS35L41_GPIO1_CTRL1, 0x00000001);
+ if (cs35l41->firmware_running) {
+ cs35l41_set_cspl_mbox_cmd(cs35l41->dev, cs35l41->regmap,
+ CSPL_MBOX_CMD_PAUSE);
+ regmap_update_bits(cs35l41->regmap, CS35L41_PWR_CTRL2,
+ CS35L41_VMON_EN_MASK | CS35L41_IMON_EN_MASK,
+ 0 << CS35L41_VMON_EN_SHIFT | 0 << CS35L41_IMON_EN_SHIFT);
+ }
cs35l41_irq_release(cs35l41);
break;
default:
@@ -80,6 +271,8 @@ static void cs35l41_hda_playback_hook(struct device *dev, int action)
break;
}
+ mutex_unlock(&cs35l41->fw_mutex);
+
if (ret)
dev_err(cs35l41->dev, "Regmap access fail: %d\n", ret);
}
@@ -104,6 +297,51 @@ static int cs35l41_hda_channel_map(struct device *dev, unsigned int tx_num, unsi
rx_slot);
}
+static int cs35l41_smart_amp(struct cs35l41_hda *cs35l41)
+{
+ int halo_sts;
+ int ret;
+
+ ret = cs35l41_init_dsp(cs35l41);
+ if (ret) {
+ dev_warn(cs35l41->dev, "Cannot Initialize Firmware. Error: %d\n", ret);
+ goto clean_dsp;
+ }
+
+ ret = cs35l41_write_fs_errata(cs35l41->dev, cs35l41->regmap);
+ if (ret) {
+ dev_err(cs35l41->dev, "Cannot Write FS Errata: %d\n", ret);
+ goto clean_dsp;
+ }
+
+ ret = cs_dsp_run(&cs35l41->cs_dsp);
+ if (ret) {
+ dev_err(cs35l41->dev, "Fail to start dsp: %d\n", ret);
+ goto clean_dsp;
+ }
+
+ ret = read_poll_timeout(hda_cs_dsp_read_ctl, ret,
+ be32_to_cpu(halo_sts) == HALO_STATE_CODE_RUN,
+ 1000, 15000, false, &cs35l41->cs_dsp, HALO_STATE_DSP_CTL_NAME,
+ HALO_STATE_DSP_CTL_TYPE, HALO_STATE_DSP_CTL_ALG,
+ &halo_sts, sizeof(halo_sts));
+
+ if (ret) {
+ dev_err(cs35l41->dev, "Timeout waiting for HALO Core to start. State: %d\n",
+ halo_sts);
+ goto clean_dsp;
+ }
+
+ cs35l41_set_cspl_mbox_cmd(cs35l41->dev, cs35l41->regmap, CSPL_MBOX_CMD_PAUSE);
+ cs35l41->firmware_running = true;
+
+ return 0;
+
+clean_dsp:
+ cs35l41_shutdown_dsp(cs35l41);
+ return ret;
+}
+
static int cs35l41_hda_bind(struct device *dev, struct device *master, void *master_data)
{
struct cs35l41_hda *cs35l41 = dev_get_drvdata(dev);
@@ -121,6 +359,11 @@ static int cs35l41_hda_bind(struct device *dev, struct device *master, void *mas
strscpy(comps->name, dev_name(dev), sizeof(comps->name));
comps->playback_hook = cs35l41_hda_playback_hook;
+ mutex_lock(&cs35l41->fw_mutex);
+ if (cs35l41_smart_amp(cs35l41) < 0)
+ dev_warn(cs35l41->dev, "Cannot Run Firmware, reverting to dsp bypass...\n");
+ mutex_unlock(&cs35l41->fw_mutex);
+
return 0;
}
@@ -537,6 +780,8 @@ int cs35l41_hda_probe(struct device *dev, const char *device_name, int id, int i
if (ret)
goto err;
+ mutex_init(&cs35l41->fw_mutex);
+
ret = cs35l41_hda_apply_properties(cs35l41);
if (ret)
goto err;
@@ -564,6 +809,9 @@ void cs35l41_hda_remove(struct device *dev)
{
struct cs35l41_hda *cs35l41 = dev_get_drvdata(dev);
+ if (cs35l41->halo_initialized)
+ cs35l41_remove_dsp(cs35l41);
+
component_del(cs35l41->dev, &cs35l41_hda_comp_ops);
if (cs35l41_safe_reset(cs35l41->regmap, cs35l41->hw_cfg.bst_type))
@@ -573,5 +821,6 @@ void cs35l41_hda_remove(struct device *dev)
EXPORT_SYMBOL_NS_GPL(cs35l41_hda_remove, SND_HDA_SCODEC_CS35L41);
MODULE_DESCRIPTION("CS35L41 HDA Driver");
+MODULE_IMPORT_NS(SND_HDA_CS_DSP_CONTROLS);
MODULE_AUTHOR("Lucas Tanure, Cirrus Logic Inc, <[email protected]>");
MODULE_LICENSE("GPL");
diff --git a/sound/pci/hda/cs35l41_hda.h b/sound/pci/hda/cs35l41_hda.h
index aaf9e16684c2..5814af050944 100644
--- a/sound/pci/hda/cs35l41_hda.h
+++ b/sound/pci/hda/cs35l41_hda.h
@@ -15,6 +15,9 @@
#include <linux/device.h>
#include <sound/cs35l41.h>
+#include <linux/firmware/cirrus/cs_dsp.h>
+#include <linux/firmware/cirrus/wmfw.h>
+
enum cs35l41_hda_spk_pos {
CS35l41_LEFT,
CS35l41_RIGHT,
@@ -39,7 +42,17 @@ struct cs35l41_hda {
int channel_index;
unsigned volatile long irq_errors;
const char *amp_name;
+ struct mutex fw_mutex;
struct regmap_irq_chip_data *irq_data;
+ bool firmware_running;
+ bool halo_initialized;
+ struct cs_dsp cs_dsp;
+};
+
+enum halo_state {
+ HALO_STATE_CODE_INIT_DOWNLOAD = 0,
+ HALO_STATE_CODE_START,
+ HALO_STATE_CODE_RUN
};
int cs35l41_hda_probe(struct device *dev, const char *device_name, int id, int irq,
--
2.34.1
On Thu, 30 Jun 2022 02:23:21 +0200,
Vitaly Rodionov wrote:
>
> The CS35L41 Amplifier contains a DSP, capable of running firmware.
> The firmware can run algorithms such as Speaker Protection, to ensure
> that playback at high gains do not harm the speakers.
> Adding support for CS35L41 firmware into the CS35L41 HDA driver also
> allows us to support several extra features, such as hiberation
> and interrupts.
>
> The chain adds support in stages:
> - General fixes to improve generalization and code re-use inside
> the CS35L41 HDA driver.
> - Add support for interrupts into the driver, which is required
> for complete support of the firmware.
> - Refactor ASoC CS35L41 code which deals with firmware to allow
> for code re-use inside the CS35L41 HDA driver.
> - Add support for loading firmware and tuning files from file system,
> and creating alsa controls to control it.
> - Support firmware load paths for different hardware systems.
> - Support suspend/resume in the driver when using firmware. The firmware
> supports hibernation, which allows the CS35L41 to drop into a low
> power mode during suspend.
> - Support the ability to unload firmware, swap and reload the firmware.
> This is to allow different firmware to run during calibration.
>
> The intended use-case is to load the firmware once on boot, and the driver
> autmatically tries to load the firmware after it binds to the HDA driver.
> This behaviour can be switched off using a kconfig, if desired.
>
> changes since v7:
> - Use private_data rather than private_value to save control info
> - Clean up alsa control memory allocation/deallocation
> - Remove unnecessary whitespace
> - Get subsystem id from codec, rather than saving it separately
>
> changes since v6:
> - Fix warning by kernel test robot <[email protected]>
>
> changes since v5:
> - Fix warning by kernel test robot <[email protected]>
>
> changes since v4:
> - Fully remove tlv remnants from control add apis
> - Remove unnecessary debug
> - Rename variable to be more generic
> - Remove redundent length check from read/write control apis
>
>
> - Use SNDRV_CTL_ELEM_IFACE_CARD for firmware load controls
> - Make kcontrol add/remove synchronous
> - Load firmware asynchronous when loading via control
> - Used cached controls when reloading firmware; only delete
> controls when removing the driver itself
>
>
> - Improve kcontrol remove
> - Fix control write + notify
> - Cleanup of unnecessary code
> - Fix race condition when loading firmware before playback
> - Ensure errors are properly propogated
> - Fix include for Module parameters
>
> Stefan Binding (13):
> ALSA: hda: hda_cs_dsp_ctl: Add Library to support CS_DSP ALSA controls
> ALSA: hda: hda_cs_dsp_ctl: Add apis to write the controls directly
> ALSA: hda: cs35l41: Save codec object inside component struct
> ALSA: hda: cs35l41: Save Subsystem ID inside CS35L41 Driver
> ALSA: hda: cs35l41: Support reading subsystem id from ACPI
> ALSA: hda: cs35l41: Support multiple load paths for firmware
> ALSA: hda: cs35l41: Support Speaker ID for laptops
> ALSA: hda: cs35l41: Support Hibernation during Suspend
> ALSA: hda: cs35l41: Read Speaker Calibration data from UEFI variables
> ALSA: hda: hda_cs_dsp_ctl: Add fw id strings
> ALSA: hda: cs35l41: Add defaulted values into dsp bypass config
> sequence
> ALSA: hda: cs35l41: Support Firmware switching and reloading
> ALSA: hda: cs35l41: Add module parameter to control firmware load
>
> Vitaly Rodionov (1):
> ALSA: hda: cs35l41: Add initial DSP support and firmware loading
Thanks, this version looks better than previous ones, and I'm fine to
apply as is, to make things going forward. But this seems requiring
the prerequisite in ASoC codec side.
Mark, could you send a PR to merge into my tree so that I can apply
those series?
And, one still uncertain thing is about the handling of system
suspend/resume, especially about the firmware loading work. e.g. what
happens if a f/w work is in run and the system goes to suspend at the
very same time? Or does the S3/S4 work in general at all?
Takashi
On Mon, 04 Jul 2022 14:50:06 +0200,
Takashi Iwai wrote:
>
> On Thu, 30 Jun 2022 02:23:21 +0200,
> Vitaly Rodionov wrote:
> >
> > The CS35L41 Amplifier contains a DSP, capable of running firmware.
> > The firmware can run algorithms such as Speaker Protection, to ensure
> > that playback at high gains do not harm the speakers.
> > Adding support for CS35L41 firmware into the CS35L41 HDA driver also
> > allows us to support several extra features, such as hiberation
> > and interrupts.
> >
> > The chain adds support in stages:
> > - General fixes to improve generalization and code re-use inside
> > the CS35L41 HDA driver.
> > - Add support for interrupts into the driver, which is required
> > for complete support of the firmware.
> > - Refactor ASoC CS35L41 code which deals with firmware to allow
> > for code re-use inside the CS35L41 HDA driver.
> > - Add support for loading firmware and tuning files from file system,
> > and creating alsa controls to control it.
> > - Support firmware load paths for different hardware systems.
> > - Support suspend/resume in the driver when using firmware. The firmware
> > supports hibernation, which allows the CS35L41 to drop into a low
> > power mode during suspend.
> > - Support the ability to unload firmware, swap and reload the firmware.
> > This is to allow different firmware to run during calibration.
> >
> > The intended use-case is to load the firmware once on boot, and the driver
> > autmatically tries to load the firmware after it binds to the HDA driver.
> > This behaviour can be switched off using a kconfig, if desired.
> >
> > changes since v7:
> > - Use private_data rather than private_value to save control info
> > - Clean up alsa control memory allocation/deallocation
> > - Remove unnecessary whitespace
> > - Get subsystem id from codec, rather than saving it separately
> >
> > changes since v6:
> > - Fix warning by kernel test robot <[email protected]>
> >
> > changes since v5:
> > - Fix warning by kernel test robot <[email protected]>
> >
> > changes since v4:
> > - Fully remove tlv remnants from control add apis
> > - Remove unnecessary debug
> > - Rename variable to be more generic
> > - Remove redundent length check from read/write control apis
> >
> >
> > - Use SNDRV_CTL_ELEM_IFACE_CARD for firmware load controls
> > - Make kcontrol add/remove synchronous
> > - Load firmware asynchronous when loading via control
> > - Used cached controls when reloading firmware; only delete
> > controls when removing the driver itself
> >
> >
> > - Improve kcontrol remove
> > - Fix control write + notify
> > - Cleanup of unnecessary code
> > - Fix race condition when loading firmware before playback
> > - Ensure errors are properly propogated
> > - Fix include for Module parameters
> >
> > Stefan Binding (13):
> > ALSA: hda: hda_cs_dsp_ctl: Add Library to support CS_DSP ALSA controls
> > ALSA: hda: hda_cs_dsp_ctl: Add apis to write the controls directly
> > ALSA: hda: cs35l41: Save codec object inside component struct
> > ALSA: hda: cs35l41: Save Subsystem ID inside CS35L41 Driver
> > ALSA: hda: cs35l41: Support reading subsystem id from ACPI
> > ALSA: hda: cs35l41: Support multiple load paths for firmware
> > ALSA: hda: cs35l41: Support Speaker ID for laptops
> > ALSA: hda: cs35l41: Support Hibernation during Suspend
> > ALSA: hda: cs35l41: Read Speaker Calibration data from UEFI variables
> > ALSA: hda: hda_cs_dsp_ctl: Add fw id strings
> > ALSA: hda: cs35l41: Add defaulted values into dsp bypass config
> > sequence
> > ALSA: hda: cs35l41: Support Firmware switching and reloading
> > ALSA: hda: cs35l41: Add module parameter to control firmware load
> >
> > Vitaly Rodionov (1):
> > ALSA: hda: cs35l41: Add initial DSP support and firmware loading
>
> Thanks, this version looks better than previous ones, and I'm fine to
> apply as is, to make things going forward. But this seems requiring
> the prerequisite in ASoC codec side.
>
> Mark, could you send a PR to merge into my tree so that I can apply
> those series?
Mark?
This series need the ASoC for-next change as prerequisite.
thanks,
Takashi
On Sat, 09 Jul 2022 18:27:34 +0200,
Takashi Iwai wrote:
>
> On Mon, 04 Jul 2022 14:50:06 +0200,
> Takashi Iwai wrote:
> >
> > On Thu, 30 Jun 2022 02:23:21 +0200,
> > Vitaly Rodionov wrote:
> > >
> > > The CS35L41 Amplifier contains a DSP, capable of running firmware.
> > > The firmware can run algorithms such as Speaker Protection, to ensure
> > > that playback at high gains do not harm the speakers.
> > > Adding support for CS35L41 firmware into the CS35L41 HDA driver also
> > > allows us to support several extra features, such as hiberation
> > > and interrupts.
> > >
> > > The chain adds support in stages:
> > > - General fixes to improve generalization and code re-use inside
> > > the CS35L41 HDA driver.
> > > - Add support for interrupts into the driver, which is required
> > > for complete support of the firmware.
> > > - Refactor ASoC CS35L41 code which deals with firmware to allow
> > > for code re-use inside the CS35L41 HDA driver.
> > > - Add support for loading firmware and tuning files from file system,
> > > and creating alsa controls to control it.
> > > - Support firmware load paths for different hardware systems.
> > > - Support suspend/resume in the driver when using firmware. The firmware
> > > supports hibernation, which allows the CS35L41 to drop into a low
> > > power mode during suspend.
> > > - Support the ability to unload firmware, swap and reload the firmware.
> > > This is to allow different firmware to run during calibration.
> > >
> > > The intended use-case is to load the firmware once on boot, and the driver
> > > autmatically tries to load the firmware after it binds to the HDA driver.
> > > This behaviour can be switched off using a kconfig, if desired.
> > >
> > > changes since v7:
> > > - Use private_data rather than private_value to save control info
> > > - Clean up alsa control memory allocation/deallocation
> > > - Remove unnecessary whitespace
> > > - Get subsystem id from codec, rather than saving it separately
> > >
> > > changes since v6:
> > > - Fix warning by kernel test robot <[email protected]>
> > >
> > > changes since v5:
> > > - Fix warning by kernel test robot <[email protected]>
> > >
> > > changes since v4:
> > > - Fully remove tlv remnants from control add apis
> > > - Remove unnecessary debug
> > > - Rename variable to be more generic
> > > - Remove redundent length check from read/write control apis
> > >
> > >
> > > - Use SNDRV_CTL_ELEM_IFACE_CARD for firmware load controls
> > > - Make kcontrol add/remove synchronous
> > > - Load firmware asynchronous when loading via control
> > > - Used cached controls when reloading firmware; only delete
> > > controls when removing the driver itself
> > >
> > >
> > > - Improve kcontrol remove
> > > - Fix control write + notify
> > > - Cleanup of unnecessary code
> > > - Fix race condition when loading firmware before playback
> > > - Ensure errors are properly propogated
> > > - Fix include for Module parameters
> > >
> > > Stefan Binding (13):
> > > ALSA: hda: hda_cs_dsp_ctl: Add Library to support CS_DSP ALSA controls
> > > ALSA: hda: hda_cs_dsp_ctl: Add apis to write the controls directly
> > > ALSA: hda: cs35l41: Save codec object inside component struct
> > > ALSA: hda: cs35l41: Save Subsystem ID inside CS35L41 Driver
> > > ALSA: hda: cs35l41: Support reading subsystem id from ACPI
> > > ALSA: hda: cs35l41: Support multiple load paths for firmware
> > > ALSA: hda: cs35l41: Support Speaker ID for laptops
> > > ALSA: hda: cs35l41: Support Hibernation during Suspend
> > > ALSA: hda: cs35l41: Read Speaker Calibration data from UEFI variables
> > > ALSA: hda: hda_cs_dsp_ctl: Add fw id strings
> > > ALSA: hda: cs35l41: Add defaulted values into dsp bypass config
> > > sequence
> > > ALSA: hda: cs35l41: Support Firmware switching and reloading
> > > ALSA: hda: cs35l41: Add module parameter to control firmware load
> > >
> > > Vitaly Rodionov (1):
> > > ALSA: hda: cs35l41: Add initial DSP support and firmware loading
> >
> > Thanks, this version looks better than previous ones, and I'm fine to
> > apply as is, to make things going forward. But this seems requiring
> > the prerequisite in ASoC codec side.
> >
> > Mark, could you send a PR to merge into my tree so that I can apply
> > those series?
>
> Mark?
>
> This series need the ASoC for-next change as prerequisite.
Mark? It's been preventing the merge.
Takashi
On Thu, 14 Jul 2022 11:03:16 +0200,
Takashi Iwai wrote:
>
> On Thu, 30 Jun 2022 02:23:22 +0200,
> Vitaly Rodionov wrote:
> > --- a/sound/pci/hda/Kconfig
> > +++ b/sound/pci/hda/Kconfig
> > @@ -94,6 +94,10 @@ config SND_HDA_PATCH_LOADER
> > config SND_HDA_SCODEC_CS35L41
> > tristate
> >
> > +config SND_HDA_CS_DSP_CONTROLS
> > + tristate
> > + depends on CS_DSP
> > +
> > config SND_HDA_SCODEC_CS35L41_I2C
> > tristate "Build CS35L41 HD-audio side codec support for I2C Bus"
> > depends on I2C
>
> This change alone doesn't give anything useful, unfortunately.
>
> The above form (without prompt) is basically only to be "selected" by
> others. And when selected, the "depends" there is just ignored, so
> it's useless.
>
> That is, a proper way would be something like:
>
> config SND_HDA_CS_DSP_CONTROLS
> tristate
>
> config SND_HDA_SCODEC_CS35L41
> ....
> select SND_HDA_CS_DSP_CONTROLS if CS_DSP
>
> ... if you want / need to enable CONFIG_SND_HDA_CS_DSP_CONTROLS
> conditionally.
And now I see that the patch 4 has those selects (but select both
SND_HDA_CS_DSP_CONTROLS and CS_DSP). So what we need here is to drop
the superfluous "depends on CS_DSP" and mention in the description
that the Kconfig will be actually enabled in the later patch.
thanks,
Takashi
On Thu, 30 Jun 2022 02:23:22 +0200,
Vitaly Rodionov wrote:
> --- a/sound/pci/hda/Kconfig
> +++ b/sound/pci/hda/Kconfig
> @@ -94,6 +94,10 @@ config SND_HDA_PATCH_LOADER
> config SND_HDA_SCODEC_CS35L41
> tristate
>
> +config SND_HDA_CS_DSP_CONTROLS
> + tristate
> + depends on CS_DSP
> +
> config SND_HDA_SCODEC_CS35L41_I2C
> tristate "Build CS35L41 HD-audio side codec support for I2C Bus"
> depends on I2C
This change alone doesn't give anything useful, unfortunately.
The above form (without prompt) is basically only to be "selected" by
others. And when selected, the "depends" there is just ignored, so
it's useless.
That is, a proper way would be something like:
config SND_HDA_CS_DSP_CONTROLS
tristate
config SND_HDA_SCODEC_CS35L41
....
select SND_HDA_CS_DSP_CONTROLS if CS_DSP
... if you want / need to enable CONFIG_SND_HDA_CS_DSP_CONTROLS
conditionally.
thanks,
Takashi
On Thu, 14 Jul 2022 11:06:16 +0200,
Takashi Iwai wrote:
>
> On Thu, 14 Jul 2022 11:03:16 +0200,
> Takashi Iwai wrote:
> >
> > On Thu, 30 Jun 2022 02:23:22 +0200,
> > Vitaly Rodionov wrote:
> > > --- a/sound/pci/hda/Kconfig
> > > +++ b/sound/pci/hda/Kconfig
> > > @@ -94,6 +94,10 @@ config SND_HDA_PATCH_LOADER
> > > config SND_HDA_SCODEC_CS35L41
> > > tristate
> > >
> > > +config SND_HDA_CS_DSP_CONTROLS
> > > + tristate
> > > + depends on CS_DSP
> > > +
> > > config SND_HDA_SCODEC_CS35L41_I2C
> > > tristate "Build CS35L41 HD-audio side codec support for I2C Bus"
> > > depends on I2C
> >
> > This change alone doesn't give anything useful, unfortunately.
> >
> > The above form (without prompt) is basically only to be "selected" by
> > others. And when selected, the "depends" there is just ignored, so
> > it's useless.
> >
> > That is, a proper way would be something like:
> >
> > config SND_HDA_CS_DSP_CONTROLS
> > tristate
> >
> > config SND_HDA_SCODEC_CS35L41
> > ....
> > select SND_HDA_CS_DSP_CONTROLS if CS_DSP
> >
> > ... if you want / need to enable CONFIG_SND_HDA_CS_DSP_CONTROLS
> > conditionally.
>
> And now I see that the patch 4 has those selects (but select both
> SND_HDA_CS_DSP_CONTROLS and CS_DSP). So what we need here is to drop
> the superfluous "depends on CS_DSP" and mention in the description
> that the Kconfig will be actually enabled in the later patch.
But no need for resubmission; I fixed this locally.
So I applied up to the patch 8. At patch 9, it can't build because of
the lack of ASoC side change.
Still waiting for *ANY* reaction from Mark... Sigh.
thanks,
Takashi
On Wed, 06 Jul 2022 12:40:36 +0200,
Vitaly Rodionov wrote:
>
>
> Hi Takashi,
>
> On 04/07/2022 13:50, Takashi Iwai wrote:
>
> On Thu, 30 Jun 2022 02:23:21 +0200,
> Vitaly Rodionov wrote:
>
> The CS35L41 Amplifier contains a DSP, capable of running firmware.
> The firmware can run algorithms such as Speaker Protection, to ensure
> that playback at high gains do not harm the speakers.
> Adding support for CS35L41 firmware into the CS35L41 HDA driver also
> allows us to support several extra features, such as hiberation
> and interrupts.
>
> The chain adds support in stages:
> - General fixes to improve generalization and code re-use inside
> the CS35L41 HDA driver.
> - Add support for interrupts into the driver, which is required
> for complete support of the firmware.
> - Refactor ASoC CS35L41 code which deals with firmware to allow
> for code re-use inside the CS35L41 HDA driver.
> - Add support for loading firmware and tuning files from file system,
> and creating alsa controls to control it.
> - Support firmware load paths for different hardware systems.
> - Support suspend/resume in the driver when using firmware. The firmware
> supports hibernation, which allows the CS35L41 to drop into a low
> power mode during suspend.
> - Support the ability to unload firmware, swap and reload the firmware.
> This is to allow different firmware to run during calibration.
>
> The intended use-case is to load the firmware once on boot, and the driver
> autmatically tries to load the firmware after it binds to the HDA driver.
> This behaviour can be switched off using a kconfig, if desired.
>
> changes since v7:
> - Use private_data rather than private_value to save control info
> - Clean up alsa control memory allocation/deallocation
> - Remove unnecessary whitespace
> - Get subsystem id from codec, rather than saving it separately
>
> changes since v6:
> - Fix warning by kernel test robot <[email protected]>
>
> changes since v5:
> - Fix warning by kernel test robot <[email protected]>
>
> changes since v4:
> - Fully remove tlv remnants from control add apis
> - Remove unnecessary debug
> - Rename variable to be more generic
> - Remove redundent length check from read/write control apis
>
> - Use SNDRV_CTL_ELEM_IFACE_CARD for firmware load controls
> - Make kcontrol add/remove synchronous
> - Load firmware asynchronous when loading via control
> - Used cached controls when reloading firmware; only delete
> controls when removing the driver itself
>
> - Improve kcontrol remove
> - Fix control write + notify
> - Cleanup of unnecessary code
> - Fix race condition when loading firmware before playback
> - Ensure errors are properly propogated
> - Fix include for Module parameters
>
> Stefan Binding (13):
> ALSA: hda: hda_cs_dsp_ctl: Add Library to support CS_DSP ALSA controls
> ALSA: hda: hda_cs_dsp_ctl: Add apis to write the controls directly
> ALSA: hda: cs35l41: Save codec object inside component struct
> ALSA: hda: cs35l41: Save Subsystem ID inside CS35L41 Driver
> ALSA: hda: cs35l41: Support reading subsystem id from ACPI
> ALSA: hda: cs35l41: Support multiple load paths for firmware
> ALSA: hda: cs35l41: Support Speaker ID for laptops
> ALSA: hda: cs35l41: Support Hibernation during Suspend
> ALSA: hda: cs35l41: Read Speaker Calibration data from UEFI variables
> ALSA: hda: hda_cs_dsp_ctl: Add fw id strings
> ALSA: hda: cs35l41: Add defaulted values into dsp bypass config
> sequence
> ALSA: hda: cs35l41: Support Firmware switching and reloading
> ALSA: hda: cs35l41: Add module parameter to control firmware load
>
> Vitaly Rodionov (1):
> ALSA: hda: cs35l41: Add initial DSP support and firmware loading
>
> Thanks, this version looks better than previous ones, and I'm fine to
> apply as is, to make things going forward. But this seems requiring
> the prerequisite in ASoC codec side.
>
> Mark, could you send a PR to merge into my tree so that I can apply
> those series?
>
> And, one still uncertain thing is about the handling of system
> suspend/resume, especially about the firmware loading work. e.g. what
> happens if a f/w work is in run and the system goes to suspend at the
> very same time? Or does the S3/S4 work in general at all?
>
> Sorry for the delay, but your comments raised our attention and we wanted to
> run extensive testing again to make sure there is no hidden issue. No issues
> were found during tests. When we start FW download work we call "resume", so
> the resume counter should be incremented and suspend will not happen till we
> finish the download process.
Now all patches have been merged to for-next branch.
thanks,
Takashi