Skip to contentSkip to conversation

ASoC: Initial support for Cirrus Logic CS35L56

PATCH Superseded Richard Fitzgerald 2 participants 22 messages Feb 17, 2023 – Feb 22, 2023

Subsystems (6)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Richard Fitzgerald

author maintainer
#0 lore raw

cover ASoC: Initial support for Cirrus Logic CS35L56

The CS35L56 is a high-performance boosted mono audio amplifier. Supported control interfaces are I2C, SPI or SoundWire. Supported audio interfaces are I2S/TDM or SoundWire.

The CS35L56 has a self-booting firmware in ROM, with the ability to patch the firmware and/or apply tunings.
Patches #1 to #7 add support to cs_dsp and wm_adsp for self-booting firmware and the ability to apply a .bin file without having to apply a .wmfw.

Patch #8 adds the ASoC driver.

Patches #9 and #10 add support for this to the Intel sof_sdw machine driver.

Richard Fitzgerald (3):
ASoC: cs35l56: Add driver for Cirrus Logic CS35L56
ASoC: Intel: sof_sdw: Add support for Cirrus Logic CS35L56
ASoC: Intel: soc-acpi: Add CS35L56 Soundwire to TGL

Simon Trimmer (7):
firmware: cs_dsp: Introduce no_core_startstop for self-booting DSPs
ASoC: wm_adsp: Use no_core_startstop to prevent creating preload
control
firmware: cs_dsp: Support DSPs that don't require firmware download
ASoC: wm_adsp: Support DSPs that don't require firmware download
ASoC: wm_adsp: Expose the DSP boot work actions as wm_adsp_power_up()
ASoC: wm_adsp: Add support for loading bin files without wmfw
ASoC: wm_adsp: Simplify the logging of requested firmware files

 MAINTAINERS                                   |    2 +
 drivers/firmware/cirrus/cs_dsp.c              |   17 +-
 include/linux/firmware/cirrus/cs_dsp.h        |    1 +
 include/sound/cs35l56.h                       |  266 +++
 sound/soc/codecs/Kconfig                      |   34 +
 sound/soc/codecs/Makefile                     |   10 +
 sound/soc/codecs/cs35l56-i2c.c                |   83 +
 sound/soc/codecs/cs35l56-sdw.c                |  525 ++++++
 sound/soc/codecs/cs35l56-shared.c             |  387 +++++
 sound/soc/codecs/cs35l56-spi.c                |   81 +
 sound/soc/codecs/cs35l56.c                    | 1451 +++++++++++++++++
 sound/soc/codecs/cs35l56.h                    |   77 +
 sound/soc/codecs/wm_adsp.c                    |   63 +-
 sound/soc/codecs/wm_adsp.h                    |    3 +
 sound/soc/intel/boards/Kconfig                |    1 +
 sound/soc/intel/boards/Makefile               |    1 +
 sound/soc/intel/boards/sof_sdw.c              |    7 +
 sound/soc/intel/boards/sof_sdw_common.h       |    7 +
 sound/soc/intel/boards/sof_sdw_cs35l56.c      |  115 ++
 .../intel/common/soc-acpi-intel-tgl-match.c   |   57 +
 20 files changed, 3172 insertions(+), 16 deletions(-)
 create mode 100644 include/sound/cs35l56.h
 create mode 100644 sound/soc/codecs/cs35l56-i2c.c
 create mode 100644 sound/soc/codecs/cs35l56-sdw.c
 create mode 100644 sound/soc/codecs/cs35l56-shared.c
 create mode 100644 sound/soc/codecs/cs35l56-spi.c
 create mode 100644 sound/soc/codecs/cs35l56.c
 create mode 100644 sound/soc/codecs/cs35l56.h
 create mode 100644 sound/soc/intel/boards/sof_sdw_cs35l56.c
Signature · 1 line
2.30.2
author maintainer
#1 lore raw

PATCH 1/10 firmware: cs_dsp: Introduce no_core_startstop for self-booting DSPs

From: Simon Trimmer <[email protected]>

There are devices containing Halo Core DSPs that self-boot, cs_dsp is used to manage the running firmware but the host does not have direct control over starting and stopping the DSP and so cs_dsp should consider the DSP to be always running.

---
 drivers/firmware/cirrus/cs_dsp.c       | 14 +++++++++++++-
 include/linux/firmware/cirrus/cs_dsp.h |  1 +
 2 files changed, 14 insertions(+), 1 deletion(-)
drivers/firmware/cirrus/cs_dsp.c +13 -1
index f558b390fbfe..97b73a254380 100644
@@ -301,6 +301,7 @@ struct cs_dsp_ops {
 static const struct cs_dsp_ops cs_dsp_adsp1_ops;
 static const struct cs_dsp_ops cs_dsp_adsp2_ops[];
 static const struct cs_dsp_ops cs_dsp_halo_ops;
+static const struct cs_dsp_ops cs_dsp_halo_ao_ops;
 
 struct cs_dsp_buf {
 	struct list_head list;
@@ -2821,7 +2822,10 @@ EXPORT_SYMBOL_NS_GPL(cs_dsp_adsp2_init, FW_CS_DSP);
  */
 int cs_dsp_halo_init(struct cs_dsp *dsp)
 {
-	dsp->ops = &cs_dsp_halo_ops;
+	if (dsp->no_core_startstop)
+		dsp->ops = &cs_dsp_halo_ao_ops;
+	else
+		dsp->ops = &cs_dsp_halo_ops;
 
 	return cs_dsp_common_init(dsp);
 }
@@ -3187,6 +3191,14 @@ static const struct cs_dsp_ops cs_dsp_halo_ops = {
 	.stop_core = cs_dsp_halo_stop_core,
 };
 
+static const struct cs_dsp_ops cs_dsp_halo_ao_ops = {
+	.parse_sizes = cs_dsp_adsp2_parse_sizes,
+	.validate_version = cs_dsp_halo_validate_version,
+	.setup_algs = cs_dsp_halo_setup_algs,
+	.region_to_reg = cs_dsp_halo_region_to_reg,
+	.show_fw_status = cs_dsp_halo_show_fw_status,
+};
+
 /**
  * cs_dsp_chunk_write() - Format data to a DSP memory chunk
  * @ch: Pointer to the chunk structure
include/linux/firmware/cirrus/cs_dsp.h +1 -0
index cad828e21c72..29cd11d5a3cf 100644
@@ -156,6 +156,7 @@ struct cs_dsp {
 	unsigned int sysclk_reg;
 	unsigned int sysclk_mask;
 	unsigned int sysclk_shift;
+	bool no_core_startstop;
 
 	struct list_head alg_regions;
 
Signature · 1 line
2.30.2
author maintainer
#2 lore raw

PATCH 2/10 ASoC: wm_adsp: Use no_core_startstop to prevent creating preload control

In reply to Richard Fitzgerald

From: Simon Trimmer <[email protected]>

The no_core_startstop flag indicates a self-booting DSP - they are considered to be always running and therefore cannot be pre-loaded.

---
 sound/soc/codecs/wm_adsp.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
sound/soc/codecs/wm_adsp.c +4 -2
index ea0dbc634ecf..854d9366a745 100644
@@ -1102,8 +1102,10 @@ int wm_adsp2_component_probe(struct wm_adsp *dsp, struct snd_soc_component *comp
 {
 	char preload[32];
 
-	snprintf(preload, ARRAY_SIZE(preload), "%s Preload", dsp->cs_dsp.name);
-	snd_soc_component_disable_pin(component, preload);
+	if (!dsp->cs_dsp.no_core_startstop) {
+		snprintf(preload, ARRAY_SIZE(preload), "%s Preload", dsp->cs_dsp.name);
+		snd_soc_component_disable_pin(component, preload);
+	}
 
 	cs_dsp_init_debugfs(&dsp->cs_dsp, component->debugfs_root);
 
Signature · 1 line
2.30.2
author maintainer
#3 lore raw

PATCH 3/10 firmware: cs_dsp: Support DSPs that don't require firmware download

In reply to Richard Fitzgerald

From: Simon Trimmer <[email protected]>

When a DSP can self-boot from ROM it is not necessary to download firmware during the powering up sequence.

A DSP that required firmware download would fail in a previous configuration step if firmware was not available.

---
 drivers/firmware/cirrus/cs_dsp.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/firmware/cirrus/cs_dsp.c +3 -0
index 97b73a254380..513136a924cf 100644
@@ -1301,6 +1301,9 @@ static int cs_dsp_load(struct cs_dsp *dsp, const struct firmware *firmware,
 	int regions = 0;
 	int ret, offset, type;
 
+	if (!firmware)
+		return 0;
+
 	ret = -EINVAL;
 
 	pos = sizeof(*header) + sizeof(*adsp1_sizes) + sizeof(*footer);
Signature · 1 line
2.30.2
author maintainer
#4 lore raw

PATCH 4/10 ASoC: wm_adsp: Support DSPs that don't require firmware download

In reply to Richard Fitzgerald

From: Simon Trimmer <[email protected]>

When a DSP can self-boot from ROM it is not necessary to download firmware - when the DSP has the wmfw_optional flag set not finding a wmfw firmware file is a successful outcome and not an error condition.

---
 sound/soc/codecs/wm_adsp.c | 3 +++
 sound/soc/codecs/wm_adsp.h | 1 +
 2 files changed, 4 insertions(+)
sound/soc/codecs/wm_adsp.c +3 -0
index 854d9366a745..8176b6173de9 100644
@@ -850,6 +850,9 @@ static int wm_adsp_request_firmware_files(struct wm_adsp *dsp,
 		return 0;
 	}
 
+	if (dsp->wmfw_optional)
+		return 0;
+
 	adsp_err(dsp, "Failed to request firmware <%s>%s-%s-%s<-%s<%s>>.wmfw\n",
 		 cirrus_dir, dsp->part, dsp->fwf_name, wm_adsp_fw[dsp->fw].file,
 		 system_name, asoc_component_prefix);
sound/soc/codecs/wm_adsp.h +1 -0
index dc2f7a096e26..173dcae2c260 100644
@@ -34,6 +34,7 @@ struct wm_adsp {
 	unsigned int sys_config_size;
 
 	int fw;
+	bool wmfw_optional;
 
 	struct work_struct boot_work;
 	int (*pre_run)(struct wm_adsp *dsp);
Signature · 1 line
2.30.2
author maintainer
#5 lore raw

PATCH 5/10 ASoC: wm_adsp: Expose the DSP boot work actions as wm_adsp_power_up()

In reply to Richard Fitzgerald

From: Simon Trimmer <[email protected]>

To support self-booting DSPs that are considered always running, the work that is usually invoked as part of a DAPM sequence needs to be triggered by a client of wm_adsp as part of it's startup sequence.

These actions load firmware files that might create ALSA controls and apply configuration to the device.

---
 sound/soc/codecs/wm_adsp.c | 27 ++++++++++++++++++---------
 sound/soc/codecs/wm_adsp.h |  2 ++
 2 files changed, 20 insertions(+), 9 deletions(-)
sound/soc/codecs/wm_adsp.c +18 -9
index 8176b6173de9..d4bffa2f7005 100644
@@ -998,11 +998,8 @@ int wm_adsp2_preloader_put(struct snd_kcontrol *kcontrol,
 }
 EXPORT_SYMBOL_GPL(wm_adsp2_preloader_put);
 
-static void wm_adsp_boot_work(struct work_struct *work)
+int wm_adsp_power_up(struct wm_adsp *dsp)
 {
-	struct wm_adsp *dsp = container_of(work,
-					   struct wm_adsp,
-					   boot_work);
 	int ret = 0;
 	char *wmfw_filename = NULL;
 	const struct firmware *wmfw_firmware = NULL;
@@ -1013,16 +1010,28 @@ static void wm_adsp_boot_work(struct work_struct *work)
 					     &wmfw_firmware, &wmfw_filename,
 					     &coeff_firmware, &coeff_filename);
 	if (ret)
-		return;
+		return ret;
 
-	cs_dsp_power_up(&dsp->cs_dsp,
-			wmfw_firmware, wmfw_filename,
-			coeff_firmware, coeff_filename,
-			wm_adsp_fw_text[dsp->fw]);
+	ret = cs_dsp_power_up(&dsp->cs_dsp,
+			      wmfw_firmware, wmfw_filename,
+			      coeff_firmware, coeff_filename,
+			      wm_adsp_fw_text[dsp->fw]);
 
 	wm_adsp_release_firmware_files(dsp,
 				       wmfw_firmware, wmfw_filename,
 				       coeff_firmware, coeff_filename);
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(wm_adsp_power_up);
+
+static void wm_adsp_boot_work(struct work_struct *work)
+{
+	struct wm_adsp *dsp = container_of(work,
+					   struct wm_adsp,
+					   boot_work);
+
+	wm_adsp_power_up(dsp);
 }
 
 int wm_adsp_early_event(struct snd_soc_dapm_widget *w,
sound/soc/codecs/wm_adsp.h +2 -0
index 173dcae2c260..769904d34a87 100644
@@ -91,6 +91,8 @@ int wm_adsp1_event(struct snd_soc_dapm_widget *w,
 int wm_adsp_early_event(struct snd_soc_dapm_widget *w,
 			struct snd_kcontrol *kcontrol, int event);
 
+int wm_adsp_power_up(struct wm_adsp *dsp);
+
 irqreturn_t wm_adsp2_bus_error(int irq, void *data);
 irqreturn_t wm_halo_bus_error(int irq, void *data);
 irqreturn_t wm_halo_wdt_expire(int irq, void *data);
Signature · 1 line
2.30.2
author maintainer
#6 lore raw

PATCH 6/10 ASoC: wm_adsp: Add support for loading bin files without wmfw

In reply to Richard Fitzgerald

From: Simon Trimmer <[email protected]>

A self-booted DSP may have a file of coefficients to apply to the device even when there is no firmware to download.

---
 sound/soc/codecs/wm_adsp.c | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)
sound/soc/codecs/wm_adsp.c +22 -1
index d4bffa2f7005..c23c306dc38d 100644
@@ -850,8 +850,29 @@ static int wm_adsp_request_firmware_files(struct wm_adsp *dsp,
 		return 0;
 	}
 
-	if (dsp->wmfw_optional)
+	if (dsp->wmfw_optional) {
+		if (system_name) {
+			if (asoc_component_prefix)
+				wm_adsp_request_firmware_file(dsp, coeff_firmware, coeff_filename,
+							      cirrus_dir, system_name,
+							      asoc_component_prefix, "bin");
+
+			if (!*coeff_firmware)
+				wm_adsp_request_firmware_file(dsp, coeff_firmware, coeff_filename,
+							      cirrus_dir, system_name,
+							      NULL, "bin");
+		}
+
+		if (!*coeff_firmware)
+			wm_adsp_request_firmware_file(dsp, coeff_firmware, coeff_filename,
+						      "", NULL, NULL, "bin");
+
+		if (!*coeff_firmware)
+			wm_adsp_request_firmware_file(dsp, coeff_firmware, coeff_filename,
+						      cirrus_dir, NULL, NULL, "bin");
+
 		return 0;
+	}
 
 	adsp_err(dsp, "Failed to request firmware <%s>%s-%s-%s<-%s<%s>>.wmfw\n",
 		 cirrus_dir, dsp->part, dsp->fwf_name, wm_adsp_fw[dsp->fw].file,
Signature · 1 line
2.30.2
author maintainer
#7 lore raw

PATCH 7/10 ASoC: wm_adsp: Simplify the logging of requested firmware files

In reply to Richard Fitzgerald

From: Simon Trimmer <[email protected]>

This change makes the logging of firmware files more consistent and simplifies the code - a debug message is logged whether the requested file was found or not and this applies to both wmfw and bin files.

---
 sound/soc/codecs/wm_adsp.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
sound/soc/codecs/wm_adsp.c +2 -4
index c23c306dc38d..216120b68b64 100644
@@ -787,6 +787,8 @@ static int wm_adsp_request_firmware_file(struct wm_adsp *dsp,
 		adsp_dbg(dsp, "Failed to request '%s'\n", *filename);
 		kfree(*filename);
 		*filename = NULL;
+	} else {
+		adsp_dbg(dsp, "Found '%s'\n", *filename);
 	}
 
 	return ret;
@@ -807,7 +809,6 @@ static int wm_adsp_request_firmware_files(struct wm_adsp *dsp,
 		if (!wm_adsp_request_firmware_file(dsp, wmfw_firmware, wmfw_filename,
 						   cirrus_dir, system_name,
 						   asoc_component_prefix, "wmfw")) {
-			adsp_dbg(dsp, "Found '%s'\n", *wmfw_filename);
 			wm_adsp_request_firmware_file(dsp, coeff_firmware, coeff_filename,
 						      cirrus_dir, system_name,
 						      asoc_component_prefix, "bin");
@@ -819,7 +820,6 @@ static int wm_adsp_request_firmware_files(struct wm_adsp *dsp,
 		if (!wm_adsp_request_firmware_file(dsp, wmfw_firmware, wmfw_filename,
 						   cirrus_dir, system_name,
 						   NULL, "wmfw")) {
-			adsp_dbg(dsp, "Found '%s'\n", *wmfw_filename);
 			if (asoc_component_prefix)
 				wm_adsp_request_firmware_file(dsp, coeff_firmware, coeff_filename,
 							      cirrus_dir, system_name,
@@ -835,7 +835,6 @@ static int wm_adsp_request_firmware_files(struct wm_adsp *dsp,
 
 	if (!wm_adsp_request_firmware_file(dsp, wmfw_firmware, wmfw_filename,
 					   "", NULL, NULL, "wmfw")) {
-		adsp_dbg(dsp, "Found '%s'\n", *wmfw_filename);
 		wm_adsp_request_firmware_file(dsp, coeff_firmware, coeff_filename,
 					      "", NULL, NULL, "bin");
 		return 0;
@@ -844,7 +843,6 @@ static int wm_adsp_request_firmware_files(struct wm_adsp *dsp,
 	ret = wm_adsp_request_firmware_file(dsp, wmfw_firmware, wmfw_filename,
 					    cirrus_dir, NULL, NULL, "wmfw");
 	if (!ret) {
-		adsp_dbg(dsp, "Found '%s'\n", *wmfw_filename);
 		wm_adsp_request_firmware_file(dsp, coeff_firmware, coeff_filename,
 					      cirrus_dir, NULL, NULL, "bin");
 		return 0;
Signature · 1 line
2.30.2
author maintainer
#8 lore raw

PATCH 8/10 ASoC: cs35l56: Add driver for Cirrus Logic CS35L56

In reply to Richard Fitzgerald

The CS35L56 combines a high-performance mono audio amplifier, Class-H tracking inductive boost converter, Halo Core(TM) DSP and a DC-DC boost converter supporting Class-H tracking.

Supported control interfaces are I2C, SPI or SoundWire. Supported audio interfaces are I2S/TDM or SoundWire.

Most chip functionality is controlled by on-board ROM firmware that is always running. The driver must apply patch/tune to the firmware before using the CS35L56.

---
 MAINTAINERS                       |    1 +
 include/sound/cs35l56.h           |  266 ++++++
 sound/soc/codecs/Kconfig          |   34 +
 sound/soc/codecs/Makefile         |   10 +
 sound/soc/codecs/cs35l56-i2c.c    |   83 ++
 sound/soc/codecs/cs35l56-sdw.c    |  525 +++++++++++
 sound/soc/codecs/cs35l56-shared.c |  387 ++++++++
 sound/soc/codecs/cs35l56-spi.c    |   81 ++
 sound/soc/codecs/cs35l56.c        | 1451 +++++++++++++++++++++++++++++
 sound/soc/codecs/cs35l56.h        |   77 ++
 10 files changed, 2915 insertions(+)
 create mode 100644 include/sound/cs35l56.h
 create mode 100644 sound/soc/codecs/cs35l56-i2c.c
 create mode 100644 sound/soc/codecs/cs35l56-sdw.c
 create mode 100644 sound/soc/codecs/cs35l56-shared.c
 create mode 100644 sound/soc/codecs/cs35l56-spi.c
 create mode 100644 sound/soc/codecs/cs35l56.c
 create mode 100644 sound/soc/codecs/cs35l56.h
MAINTAINERS +1 -0
index 970adbcefc2f..3d7aaa42b854 100644
@@ -5035,6 +5035,7 @@ L:	[email protected]
 S:	Maintained
 F:	Documentation/devicetree/bindings/sound/cirrus,cs*
 F:	include/dt-bindings/sound/cs*
+F:	include/sound/cs*
 F:	sound/pci/hda/cs*
 F:	sound/pci/hda/hda_cs_dsp_ctl.*
 F:	sound/soc/codecs/cs*
include/sound/cs35l56.h new file +266 -0

266 lines not on this page · raw message

sound/soc/codecs/Kconfig +34 -0
index bd72c426a93d..e2dbbea68d11 100644
@@ -68,6 +68,9 @@ config SND_SOC_ALL_CODECS
 	imply SND_SOC_CS35L41_I2C
 	imply SND_SOC_CS35L45_I2C
 	imply SND_SOC_CS35L45_SPI
+	imply SND_SOC_CS35L56_I2C
+	imply SND_SOC_CS35L56_SPI
+	imply SND_SOC_CS35L56_SDW
 	imply SND_SOC_CS42L42
 	imply SND_SOC_CS42L42_SDW
 	imply SND_SOC_CS42L51_I2C
@@ -364,6 +367,7 @@ config SND_SOC_WM_ADSP
 	default y if SND_SOC_WM2200=y
 	default y if SND_SOC_CS35L41_SPI=y
 	default y if SND_SOC_CS35L41_I2C=y
+	default y if SND_SOC_CS35L56=y
 	default m if SND_SOC_MADERA=m
 	default m if SND_SOC_CS47L24=m
 	default m if SND_SOC_WM5102=m
@@ -371,6 +375,7 @@ config SND_SOC_WM_ADSP
 	default m if SND_SOC_WM2200=m
 	default m if SND_SOC_CS35L41_SPI=m
 	default m if SND_SOC_CS35L41_I2C=m
+	default m if SND_SOC_CS35L56=m
 
 config SND_SOC_AB8500_CODEC
 	tristate
@@ -711,6 +716,35 @@ config SND_SOC_CS35L45_I2C
 	  Enable support for Cirrus Logic CS35L45 smart speaker amplifier
 	  with I2C control.
 
+config SND_SOC_CS35L56
+	tristate
+
+config SND_SOC_CS35L56_SHARED
+	tristate
+
+config SND_SOC_CS35L56_I2C
+	tristate "Cirrus Logic CS35L56 CODEC (I2C)"
+	depends on I2C
+	select SERIAL_MULTI_INSTANTIATE
+	select REGMAP_I2C
+	select SND_SOC_CS35L56
+	select SND_SOC_CS35L56_SHARED
+
+config SND_SOC_CS35L56_SPI
+	tristate "Cirrus Logic CS35L56 CODEC (SPI)"
+	depends on SPI_MASTER
+	select SERIAL_MULTI_INSTANTIATE
+	select REGMAP_SPI
+	select SND_SOC_CS35L56
+	select SND_SOC_CS35L56_SHARED
+
+config SND_SOC_CS35L56_SDW
+	tristate "Cirrus Logic CS35L56 CODEC (SDW)"
+	depends on SOUNDWIRE
+	select REGMAP
+	select SND_SOC_CS35L56
+	select SND_SOC_CS35L56_SHARED
+
 config SND_SOC_CS42L42_CORE
 	tristate
 
sound/soc/codecs/Makefile +10 -0
index f1ca18f7946c..25ebce58a0ba 100644
@@ -66,6 +66,11 @@ snd-soc-cs35l41-i2c-objs := cs35l41-i2c.o
 snd-soc-cs35l45-objs := cs35l45.o cs35l45-tables.o
 snd-soc-cs35l45-spi-objs := cs35l45-spi.o
 snd-soc-cs35l45-i2c-objs := cs35l45-i2c.o
+snd-soc-cs35l56-objs := cs35l56.o
+snd-soc-cs35l56-shared-objs := cs35l56-shared.o
+snd-soc-cs35l56-i2c-objs := cs35l56-i2c.o
+snd-soc-cs35l56-spi-objs := cs35l56-spi.o
+snd-soc-cs35l56-sdw-objs := cs35l56-sdw.o
 snd-soc-cs42l42-objs := cs42l42.o
 snd-soc-cs42l42-i2c-objs := cs42l42-i2c.o
 snd-soc-cs42l42-sdw-objs := cs42l42-sdw.o
@@ -433,6 +438,11 @@ obj-$(CONFIG_SND_SOC_CS35L41_I2C)	+= snd-soc-cs35l41-i2c.o
 obj-$(CONFIG_SND_SOC_CS35L45)	+= snd-soc-cs35l45.o
 obj-$(CONFIG_SND_SOC_CS35L45_SPI)	+= snd-soc-cs35l45-spi.o
 obj-$(CONFIG_SND_SOC_CS35L45_I2C)	+= snd-soc-cs35l45-i2c.o
+obj-$(CONFIG_SND_SOC_CS35L56)	+= snd-soc-cs35l56.o
+obj-$(CONFIG_SND_SOC_CS35L56_SHARED)	+= snd-soc-cs35l56-shared.o
+obj-$(CONFIG_SND_SOC_CS35L56_I2C)	+= snd-soc-cs35l56-i2c.o
+obj-$(CONFIG_SND_SOC_CS35L56_SPI)	+= snd-soc-cs35l56-spi.o
+obj-$(CONFIG_SND_SOC_CS35L56_SDW)	+= snd-soc-cs35l56-sdw.o
 obj-$(CONFIG_SND_SOC_CS42L42_CORE)	+= snd-soc-cs42l42.o
 obj-$(CONFIG_SND_SOC_CS42L42)	+= snd-soc-cs42l42-i2c.o
 obj-$(CONFIG_SND_SOC_CS42L42_SDW)	+= snd-soc-cs42l42-sdw.o
sound/soc/codecs/cs35l56-i2c.c new file +83 -0

83 lines not on this page · raw message

sound/soc/codecs/cs35l56-sdw.c new file +525 -0

525 lines not on this page · raw message

sound/soc/codecs/cs35l56-shared.c new file +387 -0

387 lines not on this page · raw message

sound/soc/codecs/cs35l56-spi.c new file +81 -0

81 lines not on this page · raw message

sound/soc/codecs/cs35l56.c new file +1451 -0

1,451 lines not on this page · raw message

sound/soc/codecs/cs35l56.h new file +77 -0

77 lines not on this page · raw message

Signature · 1 line
2.30.2
#9 lore raw

Re: [PATCH 08/10] ASoC: cs35l56: Add driver for Cirrus Logic CS35L56

Quoted 5 lines
sound/soc/codecs/cs35l56-sdw.c new file +4 -0
+static int cs35l56_sdw_interrupt(struct sdw_slave *peripheral,
+				 struct sdw_slave_intr_status *status)
+{
+	struct cs35l56_private *cs35l56 = dev_get_drvdata(&peripheral->dev);

sound/soc/codecs/cs35l56-sdw.c line 207

Quoted 10 lines
sound/soc/codecs/cs35l56-sdw.c new file +10 -0
+
+	/* SoundWire core holds our pm_runtime when calling this function. */
+
+	dev_dbg(cs35l56->dev, "int control_port=%#x\n", status->control_port);
+
+	if ((status->control_port & SDW_SCP_INT1_IMPL_DEF) == 0)
+		return 0;
+
+	/* Prevent host controller suspending before we handle the interrupt */
+	pm_runtime_get_noresume(cs35l56->dev);

can this happen that the manager suspends in this function?

Or is this needed because of the queued work which the manager has no knowledge of?

Quoted 12 lines
sound/soc/codecs/cs35l56-sdw.c new file +12 -0
+
+	/*
+	 * Mask and clear until it has been handled. The read of GEN_INT_STAT_1
+	 * is required as per the SoundWire spec for interrupt status bits
+	 * to clear. GEN_INT_MASK_1 masks the _inputs_ to GEN_INT_STAT1.
+	 * None of the interrupts are time-critical so use the
+	 * power-efficient queue.
+	 */
+	sdw_write_no_pm(peripheral, CS35L56_SDW_GEN_INT_MASK_1, 0);
+	sdw_read_no_pm(peripheral, CS35L56_SDW_GEN_INT_STAT_1);
+	sdw_write_no_pm(peripheral, CS35L56_SDW_GEN_INT_STAT_1, 0xFF);
+	queue_work(system_power_efficient_wq, &cs35l56->sdw_irq_work);

sound/soc/codecs/cs35l56-sdw.c

Quoted 10 lines
sound/soc/codecs/cs35l56-sdw.c new file +9 -0
+
+	return 0;
+}
 
+static int __maybe_unused cs35l56_sdw_handle_unattach(struct cs35l56_private *cs35l56)
+{
+	struct sdw_slave *peripheral = cs35l56->sdw_peripheral;
+
+	if (peripheral->unattach_request) {
+		/* Cannot access registers until master re-attaches. */

not sure what the comment means, the manager does not attach. did you mean resume the bus?

Quoted 17 lines
sound/soc/codecs/cs35l56-sdw.c new file +17 -0
+		dev_dbg(cs35l56->dev, "Wait for initialization_complete\n");
+		if (!wait_for_completion_timeout(&peripheral->initialization_complete,
+						 msecs_to_jiffies(5000))) {
+			dev_err(cs35l56->dev, "initialization_complete timed out\n");
+			return -ETIMEDOUT;
+		}
+
+		peripheral->unattach_request = 0;
+
+		/*
+		 * Don't call regcache_mark_dirty(), we can't be sure that the
+		 * Manager really did issue a Bus Reset.
+		 */
+	}
+
+	return 0;
+}

...

Quoted 15 lines
sound/soc/codecs/cs35l56.c new file +15 -0
+static void cs35l56_dsp_work(struct work_struct *work)
+{
+	struct cs35l56_private *cs35l56 = container_of(work,
+						       struct cs35l56_private,
+						       dsp_work);
+	unsigned int reg;
+	unsigned int val;
+	int ret = 0;
+
+	if (!wait_for_completion_timeout(&cs35l56->init_completion,
+					 msecs_to_jiffies(5000))) {
+		dev_err(cs35l56->dev, "%s: init_completion timed out\n", __func__);
+		goto complete;
+	}
+

sound/soc/codecs/cs35l56.c line 871

Quoted 10 lines
sound/soc/codecs/cs35l56.c new file +10 -0
+	if (!cs35l56->init_done || cs35l56->removing)
+		goto complete;
+
+	cs35l56->dsp.part = devm_kasprintf(cs35l56->dev, GFP_KERNEL, "cs35l56%s-%02x",
+					   cs35l56->secured ? "s" : "", cs35l56->rev);
+
+	if (!cs35l56->dsp.part)
+		goto complete;
+
+	pm_runtime_get_sync(cs35l56->dev);

test that this is successful?

Quoted 43 lines
sound/soc/codecs/cs35l56.c new file +43 -0
+
+	/*
+	 * Disable SoundWire interrupts to prevent race with IRQ work.
+	 * Setting sdw_irq_no_unmask prevents the handler re-enabling
+	 * the SoundWire interrupt.
+	 */
+	if (cs35l56->sdw_peripheral) {
+		cs35l56->sdw_irq_no_unmask = true;
+		cancel_work_sync(&cs35l56->sdw_irq_work);
+		sdw_write_no_pm(cs35l56->sdw_peripheral, CS35L56_SDW_GEN_INT_MASK_1, 0);
+		sdw_read_no_pm(cs35l56->sdw_peripheral, CS35L56_SDW_GEN_INT_STAT_1);
+		sdw_write_no_pm(cs35l56->sdw_peripheral, CS35L56_SDW_GEN_INT_STAT_1, 0xFF);
+	}
+
+	ret = cs35l56_mbox_send(cs35l56, CS35L56_MBOX_CMD_SHUTDOWN);
+	if (ret) {
+		dev_dbg(cs35l56->dev, "%s: CS35L56_MBOX_CMD_SHUTDOWN ret %d\n", __func__, ret);
+		goto err;
+	}
+
+	if (cs35l56->rev < CS35L56_REVID_B0)
+		reg = CS35L56_DSP1_PM_CUR_STATE_A1;
+	else
+		reg = CS35L56_DSP1_PM_CUR_STATE;
+
+	ret = regmap_read_poll_timeout(cs35l56->regmap, reg,
+				       val, (val == CS35L56_HALO_STATE_SHUTDOWN),
+				       CS35L56_HALO_STATE_POLL_US,
+				       CS35L56_HALO_STATE_TIMEOUT_US);
+	if (ret < 0)
+		dev_err(cs35l56->dev, "Failed to poll PM_CUR_STATE to 1 is %d (ret %d)\n",
+			val, ret);
+
+	/* Use wm_adsp to load and apply the firmware patch and coefficient files */
+	ret = wm_adsp_power_up(&cs35l56->dsp);
+	if (ret) {
+		dev_dbg(cs35l56->dev, "%s: wm_adsp_power_up ret %d\n", __func__, ret);
+		goto err;
+	}
+
+	if (cs35l56->removing)
+		goto err;
+

sound/soc/codecs/cs35l56.c line 924

Quoted 10 lines
sound/soc/codecs/cs35l56.c new file +10 -0
+	mutex_lock(&cs35l56->irq_lock);
+
+	init_completion(&cs35l56->init_completion);
+
+	cs35l56_system_reset(cs35l56);
+
+	if (cs35l56->sdw_peripheral) {
+		if (!wait_for_completion_timeout(&cs35l56->init_completion,
+						 msecs_to_jiffies(5000))) {
+			dev_err(cs35l56->dev, "%s: init_completion timed out (SDW)\n", __func__);

shouldn't do the same routine as for a regular pm_runtime resume, including re-synching regmaps?

Quoted 25 lines
sound/soc/codecs/cs35l56.c new file +25 -0
+			goto err_unlock;
+		}
+	} else {
+		if (cs35l56_init(cs35l56))
+			goto err_unlock;
+	}
+
+	cs35l56->fw_patched = true;
+
+err_unlock:
+	mutex_unlock(&cs35l56->irq_lock);
+err:
+	pm_runtime_mark_last_busy(cs35l56->dev);
+	pm_runtime_put_autosuspend(cs35l56->dev);
+
+	/* Re-enable SoundWire interrupts */
+	if (cs35l56->sdw_peripheral) {
+		cs35l56->sdw_irq_no_unmask = false;
+		sdw_write_no_pm(cs35l56->sdw_peripheral, CS35L56_SDW_GEN_INT_MASK_1,
+				CS35L56_SDW_INT_MASK_CODEC_IRQ);
+	}
+
+complete:
+	complete_all(&cs35l56->dsp_ready_completion);
+}
author maintainer
#10 lore raw

Re: [PATCH 08/10] ASoC: cs35l56: Add driver for Cirrus Logic CS35L56

Quoted 18 lines · Pierre-Louis Bossart
Quoted 5 lines
sound/soc/codecs/cs35l56-sdw.c new file +4 -0
+static int cs35l56_sdw_interrupt(struct sdw_slave *peripheral,
+				 struct sdw_slave_intr_status *status)
+{
+	struct cs35l56_private *cs35l56 = dev_get_drvdata(&peripheral->dev);

sound/soc/codecs/cs35l56-sdw.c line 207

Quoted 10 lines
sound/soc/codecs/cs35l56-sdw.c new file +10 -0
+
+	/* SoundWire core holds our pm_runtime when calling this function. */
+
+	dev_dbg(cs35l56->dev, "int control_port=%#x\n", status->control_port);
+
+	if ((status->control_port & SDW_SCP_INT1_IMPL_DEF) == 0)
+		return 0;
+
+	/* Prevent host controller suspending before we handle the interrupt */
+	pm_runtime_get_noresume(cs35l56->dev);

can this happen that the manager suspends in this function?

Quoted 3 lines

Or is this needed because of the queued work which the manager has no knowledge of?

Because you issue a Bus-Reset when you suspend and clock-stop, if we didn't take our pm_runtime there is a small window of time where we could be reset before we've handled the interrupt. It's unlikely to happen but better to be safe than to rely on autosuspend delays.

Quoted 16 lines
Quoted 15 lines
sound/soc/codecs/cs35l56-sdw.c new file +15 -0
+
+	/*
+	 * Mask and clear until it has been handled. The read of GEN_INT_STAT_1
+	 * is required as per the SoundWire spec for interrupt status bits
+	 * to clear. GEN_INT_MASK_1 masks the _inputs_ to GEN_INT_STAT1.
+	 * None of the interrupts are time-critical so use the
+	 * power-efficient queue.
+	 */
+	sdw_write_no_pm(peripheral, CS35L56_SDW_GEN_INT_MASK_1, 0);
+	sdw_read_no_pm(peripheral, CS35L56_SDW_GEN_INT_STAT_1);
+	sdw_write_no_pm(peripheral, CS35L56_SDW_GEN_INT_STAT_1, 0xFF);
+	queue_work(system_power_efficient_wq, &cs35l56->sdw_irq_work);
+
+	return 0;
+}
Quoted 10 lines

sound/soc/codecs/cs35l56-sdw.c line 396

Quoted 6 lines
sound/soc/codecs/cs35l56-sdw.c new file +6 -0
+static int __maybe_unused cs35l56_sdw_handle_unattach(struct cs35l56_private *cs35l56)
+{
+	struct sdw_slave *peripheral = cs35l56->sdw_peripheral;
+
+	if (peripheral->unattach_request) {
+		/* Cannot access registers until master re-attaches. */

not sure what the comment means, the manager does not attach. did you mean resume the bus?

If the manager has forced us to reset we can't access the registers until the manager has recovered its state.

Quoted 38 lines
Quoted 17 lines
sound/soc/codecs/cs35l56-sdw.c new file +17 -0
+		dev_dbg(cs35l56->dev, "Wait for initialization_complete\n");
+		if (!wait_for_completion_timeout(&peripheral->initialization_complete,
+						 msecs_to_jiffies(5000))) {
+			dev_err(cs35l56->dev, "initialization_complete timed out\n");
+			return -ETIMEDOUT;
+		}
+
+		peripheral->unattach_request = 0;
+
+		/*
+		 * Don't call regcache_mark_dirty(), we can't be sure that the
+		 * Manager really did issue a Bus Reset.
+		 */
+	}
+
+	return 0;
+}

...

Quoted 19 lines
sound/soc/codecs/cs35l56.c new file +19 -0
+static void cs35l56_dsp_work(struct work_struct *work)
+{
+	struct cs35l56_private *cs35l56 = container_of(work,
+						       struct cs35l56_private,
+						       dsp_work);
+	unsigned int reg;
+	unsigned int val;
+	int ret = 0;
+
+	if (!wait_for_completion_timeout(&cs35l56->init_completion,
+					 msecs_to_jiffies(5000))) {
+		dev_err(cs35l56->dev, "%s: init_completion timed out\n", __func__);
+		goto complete;
+	}
+
+	if (!cs35l56->init_done || cs35l56->removing)
+		goto complete;
+
+	cs35l56->dsp.part = devm_kasprintf(cs35l56->dev, GFP_KERNEL, "cs35l56%s-%02x",
Quoted 9 lines

sound/soc/codecs/cs35l56.c line 871

Quoted 6 lines
sound/soc/codecs/cs35l56.c new file +6 -0
+					   cs35l56->secured ? "s" : "", cs35l56->rev);
+
+	if (!cs35l56->dsp.part)
+		goto complete;
+
+	pm_runtime_get_sync(cs35l56->dev);

test that this is successful?

Could do. Wasn't really expecting it to fail unless the hardware is already broken.

Quoted 48 lines
Quoted 48 lines
sound/soc/codecs/cs35l56.c new file +48 -0
+
+	/*
+	 * Disable SoundWire interrupts to prevent race with IRQ work.
+	 * Setting sdw_irq_no_unmask prevents the handler re-enabling
+	 * the SoundWire interrupt.
+	 */
+	if (cs35l56->sdw_peripheral) {
+		cs35l56->sdw_irq_no_unmask = true;
+		cancel_work_sync(&cs35l56->sdw_irq_work);
+		sdw_write_no_pm(cs35l56->sdw_peripheral, CS35L56_SDW_GEN_INT_MASK_1, 0);
+		sdw_read_no_pm(cs35l56->sdw_peripheral, CS35L56_SDW_GEN_INT_STAT_1);
+		sdw_write_no_pm(cs35l56->sdw_peripheral, CS35L56_SDW_GEN_INT_STAT_1, 0xFF);
+	}
+
+	ret = cs35l56_mbox_send(cs35l56, CS35L56_MBOX_CMD_SHUTDOWN);
+	if (ret) {
+		dev_dbg(cs35l56->dev, "%s: CS35L56_MBOX_CMD_SHUTDOWN ret %d\n", __func__, ret);
+		goto err;
+	}
+
+	if (cs35l56->rev < CS35L56_REVID_B0)
+		reg = CS35L56_DSP1_PM_CUR_STATE_A1;
+	else
+		reg = CS35L56_DSP1_PM_CUR_STATE;
+
+	ret = regmap_read_poll_timeout(cs35l56->regmap, reg,
+				       val, (val == CS35L56_HALO_STATE_SHUTDOWN),
+				       CS35L56_HALO_STATE_POLL_US,
+				       CS35L56_HALO_STATE_TIMEOUT_US);
+	if (ret < 0)
+		dev_err(cs35l56->dev, "Failed to poll PM_CUR_STATE to 1 is %d (ret %d)\n",
+			val, ret);
+
+	/* Use wm_adsp to load and apply the firmware patch and coefficient files */
+	ret = wm_adsp_power_up(&cs35l56->dsp);
+	if (ret) {
+		dev_dbg(cs35l56->dev, "%s: wm_adsp_power_up ret %d\n", __func__, ret);
+		goto err;
+	}
+
+	if (cs35l56->removing)
+		goto err;
+
+	mutex_lock(&cs35l56->irq_lock);
+
+	init_completion(&cs35l56->init_completion);
+
+	cs35l56_system_reset(cs35l56);
Quoted 9 lines

sound/soc/codecs/cs35l56.c line 924

Quoted 5 lines
sound/soc/codecs/cs35l56.c new file +5 -0
+
+	if (cs35l56->sdw_peripheral) {
+		if (!wait_for_completion_timeout(&cs35l56->init_completion,
+						 msecs_to_jiffies(5000))) {
+			dev_err(cs35l56->dev, "%s: init_completion timed out (SDW)\n", __func__);

shouldn't do the same routine as for a regular pm_runtime resume, including re-synching regmaps?

Not sure it would help. It's not the same as runtime_resume because we've changed the firmware and rebooted it (the firmware is retained in a runtime_suspend). We need to do some of the first-time init() code again, which we don't need to do in runtime_resume.

Also would create a circular dependency between this driver and the cs35l56-sdw driver. (We _could_ call our dev->pm->runtime_resume pointer but that's a bit ugly)

Quoted 26 lines
Quoted 26 lines
sound/soc/codecs/cs35l56.c new file +25 -0
+			goto err_unlock;
+		}
+	} else {
+		if (cs35l56_init(cs35l56))
+			goto err_unlock;
+	}
+
+	cs35l56->fw_patched = true;
+
+err_unlock:
+	mutex_unlock(&cs35l56->irq_lock);
+err:
+	pm_runtime_mark_last_busy(cs35l56->dev);
+	pm_runtime_put_autosuspend(cs35l56->dev);
+
+	/* Re-enable SoundWire interrupts */
+	if (cs35l56->sdw_peripheral) {
+		cs35l56->sdw_irq_no_unmask = false;
+		sdw_write_no_pm(cs35l56->sdw_peripheral, CS35L56_SDW_GEN_INT_MASK_1,
+				CS35L56_SDW_INT_MASK_CODEC_IRQ);
+	}
+
+complete:
+	complete_all(&cs35l56->dsp_ready_completion);
+}
#11 lore raw

Re: [PATCH 08/10] ASoC: cs35l56: Add driver for Cirrus Logic CS35L56

Quoted 23 lines · Richard Fitzgerald
Quoted 22 lines · Pierre-Louis Bossart
Quoted 17 lines
sound/soc/codecs/cs35l56-sdw.c new file +4 -0
+static int cs35l56_sdw_interrupt(struct sdw_slave *peripheral,
+                 struct sdw_slave_intr_status *status)
+{
+    struct cs35l56_private *cs35l56 =

dev_get_drvdata(&peripheral->dev);
+
+    /* SoundWire core holds our pm_runtime when calling this function. */
+
+    dev_dbg(cs35l56->dev, "int control_port=%#x\n", status->control_port);

sound/soc/codecs/cs35l56-sdw.c new file +5 -0
+
+    if ((status->control_port & SDW_SCP_INT1_IMPL_DEF) == 0)
+        return 0;
+
+    /* Prevent host controller suspending before we handle the
Quoted 2 lines

interrupt */
+    pm_runtime_get_noresume(cs35l56->dev);

can this happen that the manager suspends in this function?

Quoted 8 lines
Quoted 3 lines

Or is this needed because of the queued work which the manager has no knowledge of?

Because you issue a Bus-Reset when you suspend and clock-stop, if we didn't take our pm_runtime there is a small window of time where we could be reset before we've handled the interrupt. It's unlikely to happen but better to be safe than to rely on autosuspend delays.

What I meant is that the pm_runtime refcount should be increased prior to the SoundWire core using the interrupt_callback.

So the only window I see is in the second part of in the interrupt handling, before the workqueue is scheduled.

Quoted 30 lines
Quoted 18 lines
Quoted 17 lines

+
+    /*
+     * Mask and clear until it has been handled. The read of GEN_INT_STAT_1
+     * is required as per the SoundWire spec for interrupt status bits +     * to clear. GEN_INT_MASK_1 masks the _inputs_ to GEN_INT_STAT1. +     * None of the interrupts are time-critical so use the +     * power-efficient queue.
+     */
+    sdw_write_no_pm(peripheral, CS35L56_SDW_GEN_INT_MASK_1, 0); +    sdw_read_no_pm(peripheral, CS35L56_SDW_GEN_INT_STAT_1); +    sdw_write_no_pm(peripheral, CS35L56_SDW_GEN_INT_STAT_1, 0xFF); +    queue_work(system_power_efficient_wq, &cs35l56->sdw_irq_work);

sound/soc/codecs/cs35l56-sdw.c new file +3 -0
+
+    return 0;
+}
Quoted 11 lines

sound/soc/codecs/cs35l56-sdw.c line 396

Quoted 7 lines

+static int __maybe_unused cs35l56_sdw_handle_unattach(struct cs35l56_private *cs35l56)

sound/soc/codecs/cs35l56-sdw.c new file +5 -0
+{
+    struct sdw_slave *peripheral = cs35l56->sdw_peripheral;
+
+    if (peripheral->unattach_request) {
+        /* Cannot access registers until master re-attaches. */

not sure what the comment means, the manager does not attach. did you mean resume the bus?

Quoted 2 lines

If the manager has forced us to reset we can't access the registers until the manager has recovered its state.

"until the manager restarted the bus and re-enumerated devices" ?

Quoted 53 lines
Quoted 43 lines
Quoted 20 lines

+        dev_dbg(cs35l56->dev, "Wait for initialization_complete\n"); +        if (!wait_for_completion_timeout(&peripheral->initialization_complete, +                         msecs_to_jiffies(5000))) {
+            dev_err(cs35l56->dev, "initialization_complete timed out\n");
+            return -ETIMEDOUT;
+        }

sound/soc/codecs/cs35l56-sdw.c new file +11 -0
+
+        peripheral->unattach_request = 0;
+
+        /*
+         * Don't call regcache_mark_dirty(), we can't be sure that the
+         * Manager really did issue a Bus Reset.
+         */
+    }
+
+    return 0;
+}

...

Quoted 21 lines
sound/soc/codecs/cs35l56.c new file +12 -0
+static void cs35l56_dsp_work(struct work_struct *work)
+{
+    struct cs35l56_private *cs35l56 = container_of(work,
+                               struct cs35l56_private,
+                               dsp_work);
+    unsigned int reg;
+    unsigned int val;
+    int ret = 0;
+
+    if (!wait_for_completion_timeout(&cs35l56->init_completion,
+                     msecs_to_jiffies(5000))) {
+        dev_err(cs35l56->dev, "%s: init_completion timed out\n",

__func__);
+        goto complete;
+    }

sound/soc/codecs/cs35l56.c new file +5 -0
+
+    if (!cs35l56->init_done || cs35l56->removing)
+        goto complete;
+
+    cs35l56->dsp.part = devm_kasprintf(cs35l56->dev, GFP_KERNEL,

"cs35l56%s-%02x",

Quoted 9 lines

sound/soc/codecs/cs35l56.c line 871

Quoted 6 lines

+                       cs35l56->secured ? "s" : "", cs35l56->rev);

sound/soc/codecs/cs35l56.c new file +5 -0
+
+    if (!cs35l56->dsp.part)
+        goto complete;
+
+    pm_runtime_get_sync(cs35l56->dev);

test that this is successful?

Quoted 2 lines

Could do. Wasn't really expecting it to fail unless the hardware is already broken.

it's not supposed to happen indeed, but our CI caught a couple of issues over the last two years. Better add a check.

Quoted 67 lines
Quoted 57 lines
Quoted 57 lines

+
+    /*
+     * Disable SoundWire interrupts to prevent race with IRQ work. +     * Setting sdw_irq_no_unmask prevents the handler re-enabling +     * the SoundWire interrupt.
+     */
+    if (cs35l56->sdw_peripheral) {
+        cs35l56->sdw_irq_no_unmask = true;
+        cancel_work_sync(&cs35l56->sdw_irq_work);
+        sdw_write_no_pm(cs35l56->sdw_peripheral, CS35L56_SDW_GEN_INT_MASK_1, 0);
+        sdw_read_no_pm(cs35l56->sdw_peripheral, CS35L56_SDW_GEN_INT_STAT_1);
+        sdw_write_no_pm(cs35l56->sdw_peripheral, CS35L56_SDW_GEN_INT_STAT_1, 0xFF);
+    }
+
+    ret = cs35l56_mbox_send(cs35l56, CS35L56_MBOX_CMD_SHUTDOWN); +    if (ret) {
+        dev_dbg(cs35l56->dev, "%s: CS35L56_MBOX_CMD_SHUTDOWN ret %d\n", __func__, ret);
+        goto err;
+    }

sound/soc/codecs/cs35l56.c new file +12 -0
+
+    if (cs35l56->rev < CS35L56_REVID_B0)
+        reg = CS35L56_DSP1_PM_CUR_STATE_A1;
+    else
+        reg = CS35L56_DSP1_PM_CUR_STATE;
+
+    ret = regmap_read_poll_timeout(cs35l56->regmap, reg,
+                       val, (val == CS35L56_HALO_STATE_SHUTDOWN),
+                       CS35L56_HALO_STATE_POLL_US,
+                       CS35L56_HALO_STATE_TIMEOUT_US);
+    if (ret < 0)
+        dev_err(cs35l56->dev, "Failed to poll PM_CUR_STATE to 1 is

%d (ret %d)\n",
+            val, ret);
+
+    /* Use wm_adsp to load and apply the firmware patch and coefficient files */
+    ret = wm_adsp_power_up(&cs35l56->dsp);
+    if (ret) {
+        dev_dbg(cs35l56->dev, "%s: wm_adsp_power_up ret %d\n", __func__, ret);
+        goto err;
+    }

sound/soc/codecs/cs35l56.c new file +10 -0
+
+    if (cs35l56->removing)
+        goto err;
+
+    mutex_lock(&cs35l56->irq_lock);
+
+    init_completion(&cs35l56->init_completion);
+
+    cs35l56_system_reset(cs35l56);
+
Quoted 9 lines
Quoted 5 lines

+    if (cs35l56->sdw_peripheral) {
+        if (!wait_for_completion_timeout(&cs35l56->init_completion, +                         msecs_to_jiffies(5000))) {
+            dev_err(cs35l56->dev, "%s: init_completion timed out (SDW)\n", __func__);

shouldn't do the same routine as for a regular pm_runtime resume, including re-synching regmaps?

Quoted 8 lines

Not sure it would help. It's not the same as runtime_resume because we've changed the firmware and rebooted it (the firmware is retained in a runtime_suspend). We need to do some of the first-time init() code again, which we don't need to do in runtime_resume.

Also would create a circular dependency between this driver and the cs35l56-sdw driver. (We _could_ call our dev->pm->runtime_resume pointer but that's a bit ugly)

I wasn't suggesting using a pm_runtime suspend/resume cycle but rather use a common helper called from here and from the pm_runtime_resume.

It's a suggestion only.

Quoted 28 lines
Quoted 28 lines
Quoted 28 lines

+            goto err_unlock;
+        }
+    } else {
+        if (cs35l56_init(cs35l56))
+            goto err_unlock;
+    }

sound/soc/codecs/cs35l56.c new file +13 -0
+
+    cs35l56->fw_patched = true;
+
+err_unlock:
+    mutex_unlock(&cs35l56->irq_lock);
+err:
+    pm_runtime_mark_last_busy(cs35l56->dev);
+    pm_runtime_put_autosuspend(cs35l56->dev);
+
+    /* Re-enable SoundWire interrupts */
+    if (cs35l56->sdw_peripheral) {
+        cs35l56->sdw_irq_no_unmask = false;
+        sdw_write_no_pm(cs35l56->sdw_peripheral,

CS35L56_SDW_GEN_INT_MASK_1,
+                CS35L56_SDW_INT_MASK_CODEC_IRQ);
+    }

sound/soc/codecs/cs35l56.c new file +4 -0
+
+complete:
+    complete_all(&cs35l56->dsp_ready_completion);
+}
author maintainer
#12 lore raw

Re: [PATCH 08/10] ASoC: cs35l56: Add driver for Cirrus Logic CS35L56

Quoted 35 lines · Pierre-Louis Bossart
Quoted 23 lines · Richard Fitzgerald
Quoted 22 lines · Pierre-Louis Bossart
Quoted 17 lines
sound/soc/codecs/cs35l56-sdw.c new file +4 -0
+static int cs35l56_sdw_interrupt(struct sdw_slave *peripheral,
+                 struct sdw_slave_intr_status *status)
+{
+    struct cs35l56_private *cs35l56 =

dev_get_drvdata(&peripheral->dev);
+
+    /* SoundWire core holds our pm_runtime when calling this function. */
+
+    dev_dbg(cs35l56->dev, "int control_port=%#x\n", status->control_port);

sound/soc/codecs/cs35l56-sdw.c new file +5 -0
+
+    if ((status->control_port & SDW_SCP_INT1_IMPL_DEF) == 0)
+        return 0;
+
+    /* Prevent host controller suspending before we handle the
Quoted 2 lines

interrupt */
+    pm_runtime_get_noresume(cs35l56->dev);

can this happen that the manager suspends in this function?

Quoted 8 lines
Quoted 3 lines

Or is this needed because of the queued work which the manager has no knowledge of?

Because you issue a Bus-Reset when you suspend and clock-stop, if we didn't take our pm_runtime there is a small window of time where we could be reset before we've handled the interrupt. It's unlikely to happen but better to be safe than to rely on autosuspend delays.

Quoted 5 lines

What I meant is that the pm_runtime refcount should be increased prior to the SoundWire core using the interrupt_callback.

So the only window I see is in the second part of in the interrupt handling, before the workqueue is scheduled.

Yes, sorry I didn't explain well.
It's because we defer the handling to a workqueue job. It's to prevent the (small) chance of runtime-suspending and clock-stopping before the work queue function has had time to process the interrupt.

It only matters because the Intel controller issues a Bus-Reset when it comes out of clock stop.

Quoted 30 lines
Quoted 30 lines
Quoted 29 lines
Quoted 20 lines

+
+    /*
+     * Mask and clear until it has been handled. The read of GEN_INT_STAT_1
+     * is required as per the SoundWire spec for interrupt status bits +     * to clear. GEN_INT_MASK_1 masks the _inputs_ to GEN_INT_STAT1. +     * None of the interrupts are time-critical so use the +     * power-efficient queue.
+     */
+    sdw_write_no_pm(peripheral, CS35L56_SDW_GEN_INT_MASK_1, 0); +    sdw_read_no_pm(peripheral, CS35L56_SDW_GEN_INT_STAT_1); +    sdw_write_no_pm(peripheral, CS35L56_SDW_GEN_INT_STAT_1, 0xFF); +    queue_work(system_power_efficient_wq, &cs35l56->sdw_irq_work);

sound/soc/codecs/cs35l56-sdw.c new file +4 -0
+
+    return 0;
+}
 
+static int __maybe_unused cs35l56_sdw_handle_unattach(struct

cs35l56_private *cs35l56)

sound/soc/codecs/cs35l56-sdw.c line 396

Quoted 5 lines
sound/soc/codecs/cs35l56-sdw.c new file +5 -0
+{
+    struct sdw_slave *peripheral = cs35l56->sdw_peripheral;
+
+    if (peripheral->unattach_request) {
+        /* Cannot access registers until master re-attaches. */

not sure what the comment means, the manager does not attach. did you mean resume the bus?

Quoted 5 lines
Quoted 2 lines

If the manager has forced us to reset we can't access the registers until the manager has recovered its state.

"until the manager restarted the bus and re-enumerated devices" ?

I'll re-word the comment. And also change to "manager".

Quoted 53 lines
Quoted 53 lines
Quoted 52 lines
Quoted 20 lines

+        dev_dbg(cs35l56->dev, "Wait for initialization_complete\n"); +        if (!wait_for_completion_timeout(&peripheral->initialization_complete, +                         msecs_to_jiffies(5000))) {
+            dev_err(cs35l56->dev, "initialization_complete timed out\n");
+            return -ETIMEDOUT;
+        }

sound/soc/codecs/cs35l56-sdw.c new file +11 -0
+
+        peripheral->unattach_request = 0;
+
+        /*
+         * Don't call regcache_mark_dirty(), we can't be sure that the
+         * Manager really did issue a Bus Reset.
+         */
+    }
+
+    return 0;
+}

...

Quoted 22 lines
sound/soc/codecs/cs35l56.c new file +12 -0
+static void cs35l56_dsp_work(struct work_struct *work)
+{
+    struct cs35l56_private *cs35l56 = container_of(work,
+                               struct cs35l56_private,
+                               dsp_work);
+    unsigned int reg;
+    unsigned int val;
+    int ret = 0;
+
+    if (!wait_for_completion_timeout(&cs35l56->init_completion,
+                     msecs_to_jiffies(5000))) {
+        dev_err(cs35l56->dev, "%s: init_completion timed out\n",

__func__);
+        goto complete;
+    }

sound/soc/codecs/cs35l56.c new file +5 -0
+
+    if (!cs35l56->init_done || cs35l56->removing)
+        goto complete;
+
+    cs35l56->dsp.part = devm_kasprintf(cs35l56->dev, GFP_KERNEL,

"cs35l56%s-%02x",
+                       cs35l56->secured ? "s" : "", cs35l56->rev);

sound/soc/codecs/cs35l56.c line 871

Quoted 5 lines
sound/soc/codecs/cs35l56.c new file +5 -0
+
+    if (!cs35l56->dsp.part)
+        goto complete;
+
+    pm_runtime_get_sync(cs35l56->dev);

test that this is successful?

Quoted 6 lines
Quoted 2 lines

Could do. Wasn't really expecting it to fail unless the hardware is already broken.

it's not supposed to happen indeed, but our CI caught a couple of issues over the last two years. Better add a check.

No harm in checking for error.

Quoted 72 lines
Quoted 72 lines
Quoted 57 lines
Quoted 57 lines

+
+    /*
+     * Disable SoundWire interrupts to prevent race with IRQ work. +     * Setting sdw_irq_no_unmask prevents the handler re-enabling +     * the SoundWire interrupt.
+     */
+    if (cs35l56->sdw_peripheral) {
+        cs35l56->sdw_irq_no_unmask = true;
+        cancel_work_sync(&cs35l56->sdw_irq_work);
+        sdw_write_no_pm(cs35l56->sdw_peripheral, CS35L56_SDW_GEN_INT_MASK_1, 0);
+        sdw_read_no_pm(cs35l56->sdw_peripheral, CS35L56_SDW_GEN_INT_STAT_1);
+        sdw_write_no_pm(cs35l56->sdw_peripheral, CS35L56_SDW_GEN_INT_STAT_1, 0xFF);
+    }
+
+    ret = cs35l56_mbox_send(cs35l56, CS35L56_MBOX_CMD_SHUTDOWN); +    if (ret) {
+        dev_dbg(cs35l56->dev, "%s: CS35L56_MBOX_CMD_SHUTDOWN ret %d\n", __func__, ret);
+        goto err;
+    }

sound/soc/codecs/cs35l56.c new file +12 -0
+
+    if (cs35l56->rev < CS35L56_REVID_B0)
+        reg = CS35L56_DSP1_PM_CUR_STATE_A1;
+    else
+        reg = CS35L56_DSP1_PM_CUR_STATE;
+
+    ret = regmap_read_poll_timeout(cs35l56->regmap, reg,
+                       val, (val == CS35L56_HALO_STATE_SHUTDOWN),
+                       CS35L56_HALO_STATE_POLL_US,
+                       CS35L56_HALO_STATE_TIMEOUT_US);
+    if (ret < 0)
+        dev_err(cs35l56->dev, "Failed to poll PM_CUR_STATE to 1 is

%d (ret %d)\n",
+            val, ret);
+
+    /* Use wm_adsp to load and apply the firmware patch and coefficient files */
+    ret = wm_adsp_power_up(&cs35l56->dsp);
+    if (ret) {
+        dev_dbg(cs35l56->dev, "%s: wm_adsp_power_up ret %d\n", __func__, ret);
+        goto err;
+    }

sound/soc/codecs/cs35l56.c new file +10 -0
+
+    if (cs35l56->removing)
+        goto err;
+
+    mutex_lock(&cs35l56->irq_lock);
+
+    init_completion(&cs35l56->init_completion);
+
+    cs35l56_system_reset(cs35l56);
+
Quoted 9 lines
Quoted 5 lines

+    if (cs35l56->sdw_peripheral) {
+        if (!wait_for_completion_timeout(&cs35l56->init_completion, +                         msecs_to_jiffies(5000))) {
+            dev_err(cs35l56->dev, "%s: init_completion timed out (SDW)\n", __func__);

shouldn't do the same routine as for a regular pm_runtime resume, including re-synching regmaps?

Not sure it would help. It's not the same as runtime_resume because we've changed the firmware and rebooted it (the firmware is retained in a runtime_suspend). We need to do some of the first-time init() code again, which we don't need to do in runtime_resume.

Quoted 9 lines
Quoted 3 lines

Also would create a circular dependency between this driver and the cs35l56-sdw driver. (We _could_ call our dev->pm->runtime_resume pointer but that's a bit ugly)

I wasn't suggesting using a pm_runtime suspend/resume cycle but rather use a common helper called from here and from the pm_runtime_resume.

It's a suggestion only.

It's on my to-do list to see whether this is useful.

Effectively we're re-initializing and the code we want to re-use is what cs35l56_init() does after it issues SYSTEM_RESET. So cs35l56_init() is acting as the common code.

We're going to get an update_status() callback when it re-enumerates. The update_status() calls cs35l56_init() during the first enumeration. So we are re-using that same code path to call again cs35l56_init() and repeat the post-SYSTEM_RESET handling.

Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
Quoted 28 lines

+            goto err_unlock;
+        }
+    } else {
+        if (cs35l56_init(cs35l56))
+            goto err_unlock;
+    }

sound/soc/codecs/cs35l56.c new file +13 -0
+
+    cs35l56->fw_patched = true;
+
+err_unlock:
+    mutex_unlock(&cs35l56->irq_lock);
+err:
+    pm_runtime_mark_last_busy(cs35l56->dev);
+    pm_runtime_put_autosuspend(cs35l56->dev);
+
+    /* Re-enable SoundWire interrupts */
+    if (cs35l56->sdw_peripheral) {
+        cs35l56->sdw_irq_no_unmask = false;
+        sdw_write_no_pm(cs35l56->sdw_peripheral,

CS35L56_SDW_GEN_INT_MASK_1,
+                CS35L56_SDW_INT_MASK_CODEC_IRQ);
+    }

sound/soc/codecs/cs35l56.c new file +4 -0
+
+complete:
+    complete_all(&cs35l56->dsp_ready_completion);
+}
author maintainer
#13 lore raw

PATCH 9/10 ASoC: Intel: sof_sdw: Add support for Cirrus Logic CS35L56

In reply to Richard Fitzgerald

The CS35L56 is a high-performance mono boosted audio amplifier.

This patch adds the initialization for one, two or four amps.

All amps receive the same 2-channel (stereo) audio. Left/right channel-to-speaker mapping is not fixed. The CS35L56 on-board DSP adjusts the mapping based on current posture (orientation).

Each CS35L56 has 6 feedback channels for monitoring but to remain within limited SoundWire bandwidth only one channel per amp is enabled.

---
 MAINTAINERS                              |   1 +
 sound/soc/intel/boards/Kconfig           |   1 +
 sound/soc/intel/boards/Makefile          |   1 +
 sound/soc/intel/boards/sof_sdw.c         |   7 ++
 sound/soc/intel/boards/sof_sdw_common.h  |   7 ++
 sound/soc/intel/boards/sof_sdw_cs35l56.c | 115 +++++++++++++++++++++++
 6 files changed, 132 insertions(+)
 create mode 100644 sound/soc/intel/boards/sof_sdw_cs35l56.c
MAINTAINERS +1 -0
index 3d7aaa42b854..c40bae5e90ea 100644
@@ -5039,6 +5039,7 @@ F:	include/sound/cs*
 F:	sound/pci/hda/cs*
 F:	sound/pci/hda/hda_cs_dsp_ctl.*
 F:	sound/soc/codecs/cs*
+F:	sound/soc/intel/boards/sof_sdw_cs35l56.c
 
 CIRRUS LOGIC DSP FIRMWARE DRIVER
 M:	Simon Trimmer <[email protected]>
sound/soc/intel/boards/Kconfig +1 -0
index 99308ed85277..3e483bbf3ebe 100644
@@ -662,6 +662,7 @@ config SND_SOC_INTEL_SOUNDWIRE_SOF_MACH
 	depends on MFD_INTEL_LPSS || COMPILE_TEST
 	depends on SND_SOC_INTEL_USER_FRIENDLY_LONG_NAMES || COMPILE_TEST
 	depends on SOUNDWIRE
+	select SND_SOC_CS35L56_SDW
 	select SND_SOC_MAX98373_I2C
 	select SND_SOC_MAX98373_SDW
 	select SND_SOC_RT700_SDW
sound/soc/intel/boards/Makefile +1 -0
index d1fd7a2b32db..64e37f8e4a4b 100644
@@ -37,6 +37,7 @@ snd-soc-sof_da7219_max98373-objs := sof_da7219_max98373.o
 snd-soc-ehl-rt5660-objs := ehl_rt5660.o
 snd-soc-sof-ssp-amp-objs := sof_ssp_amp.o
 snd-soc-sof-sdw-objs += sof_sdw.o				\
+			sof_sdw_cs35l56.o			\
 			sof_sdw_max98373.o sof_sdw_rt_amp.o	\
 			sof_sdw_rt5682.o sof_sdw_rt700.o	\
 			sof_sdw_rt711.o sof_sdw_rt711_sdca.o 	\
sound/soc/intel/boards/sof_sdw.c +7 -0
index d2ed807abde9..6c679b4b963f 100644
@@ -544,6 +544,13 @@ static struct sof_sdw_codec_info codec_info_list[] = {
 		.exit = sof_sdw_rt711_exit,
 		.codec_type = SOF_SDW_CODEC_TYPE_JACK,
 	},
+	{
+		.part_id = 0x3556,
+		.direction = {true, true},
+		.dai_name = "cs35l56-sdw1",
+		.init = sof_sdw_cs35l56_init,
+		.codec_type = SOF_SDW_CODEC_TYPE_AMP,
+	},
 	{
 		.part_id = 0x1308,
 		.acpi_id = "10EC1308",
sound/soc/intel/boards/sof_sdw_common.h +7 -0
index 350010b0e5f4..1bb8e4a34c56 100644
@@ -102,6 +102,13 @@ int sof_sdw_hdmi_card_late_probe(struct snd_soc_card *card);
 /* DMIC support */
 int sof_sdw_dmic_init(struct snd_soc_pcm_runtime *rtd);
 
+/* CS35L56 support */
+int sof_sdw_cs35l56_init(struct snd_soc_card *card,
+			 const struct snd_soc_acpi_link_adr *link,
+			 struct snd_soc_dai_link *dai_links,
+			 struct sof_sdw_codec_info *info,
+			 bool playback);
+
 /* RT711 support */
 int sof_sdw_rt711_init(struct snd_soc_card *card,
 		       const struct snd_soc_acpi_link_adr *link,
sound/soc/intel/boards/sof_sdw_cs35l56.c new file +115 -0

115 lines not on this page · raw message

Signature · 1 line
2.30.2
#14 lore raw

Re: [PATCH 09/10] ASoC: Intel: sof_sdw: Add support for Cirrus Logic CS35L56

sound/soc/intel/boards/sof_sdw_cs35l56.c line 35

Quoted 9 lines
sound/soc/intel/boards/sof_sdw_cs35l56.c new file +8 -0
+static int cs35l56_init_multiple(struct snd_soc_pcm_runtime *rtd, int count)
+{
+	struct snd_soc_card *card = rtd->card;
+	struct snd_soc_dai *codec_dai;
+	int i, ret;
+
+	card->components = devm_kasprintf(card->dev, GFP_KERNEL,
+					  "%s hs:cs35l56",

the string is wrong here, this is an amplifier so it should be amp:cs35l56 or spk:cs36l56 (not sure which of the two we ended-up using).

Quoted 10 lines
sound/soc/intel/boards/sof_sdw_cs35l56.c new file +10 -0
+					  card->components);
+	if (!card->components)
+		return -ENOMEM;
+
+	ret = snd_soc_dapm_new_controls(&card->dapm,
+					cs35l56_sof_widgets, ARRAY_SIZE(cs35l56_sof_widgets));
+	if (ret) {
+		dev_err(card->dev, "Widgets add failed: %d\n", ret);
+		return ret;
+	}

sound/soc/intel/boards/sof_sdw_cs35l56.c line 55

Quoted 10 lines
sound/soc/intel/boards/sof_sdw_cs35l56.c new file +10 -0
+
+	ret = snd_soc_dapm_add_routes(&card->dapm, cs35l56_sof_map, count);
+	if (ret) {
+		dev_err(card->dev, "Map add %d failed: %d\n", count, ret);
+		return ret;
+	}
+
+	/* Enable one feedback TX per amp on different slots */
+	for_each_rtd_codec_dais(rtd, i, codec_dai) {
+		ret = snd_soc_dai_set_tdm_slot(codec_dai, 0x3, 1 << i, 4, 16);

TDM slots? Not getting how this would work with SoundWire?

Quoted 6 lines
sound/soc/intel/boards/sof_sdw_cs35l56.c new file +6 -0
+		if (ret < 0)
+			return ret;
+	}
+
+	return 0;
+}
author maintainer
#15 lore raw

Re: [PATCH 09/10] ASoC: Intel: sof_sdw: Add support for Cirrus Logic CS35L56

Quoted 13 lines · Pierre-Louis Bossart

sound/soc/intel/boards/sof_sdw_cs35l56.c line 35

Quoted 9 lines
sound/soc/intel/boards/sof_sdw_cs35l56.c new file +8 -0
+static int cs35l56_init_multiple(struct snd_soc_pcm_runtime *rtd, int count)
+{
+	struct snd_soc_card *card = rtd->card;
+	struct snd_soc_dai *codec_dai;
+	int i, ret;
+
+	card->components = devm_kasprintf(card->dev, GFP_KERNEL,
+					  "%s hs:cs35l56",

the string is wrong here, this is an amplifier so it should be amp:cs35l56 or spk:cs36l56 (not sure which of the two we ended-up using).

Will change it.

Quoted 14 lines
Quoted 14 lines
sound/soc/intel/boards/sof_sdw_cs35l56.c new file +14 -0
+					  card->components);
+	if (!card->components)
+		return -ENOMEM;
+
+	ret = snd_soc_dapm_new_controls(&card->dapm,
+					cs35l56_sof_widgets, ARRAY_SIZE(cs35l56_sof_widgets));
+	if (ret) {
+		dev_err(card->dev, "Widgets add failed: %d\n", ret);
+		return ret;
+	}
+
+	ret = snd_soc_dapm_add_routes(&card->dapm, cs35l56_sof_map, count);
+	if (ret) {
+		dev_err(card->dev, "Map add %d failed: %d\n", count, ret);
Quoted 9 lines

sound/soc/intel/boards/sof_sdw_cs35l56.c line 55

Quoted 6 lines
sound/soc/intel/boards/sof_sdw_cs35l56.c new file +6 -0
+		return ret;
+	}
+
+	/* Enable one feedback TX per amp on different slots */
+	for_each_rtd_codec_dais(rtd, i, codec_dai) {
+		ret = snd_soc_dai_set_tdm_slot(codec_dai, 0x3, 1 << i, 4, 16);

TDM slots? Not getting how this would work with SoundWire?

Strictly speaking Soundwire is TDM (the frame time is divided up into slots for each sample...).

The problem is if you have N amps on the dailink all feeding back audio on the same bus. Their DP slots are all programmed to the same positions in the frame, same as for the playback. So you have 4 amps all trying to send 6 audio channels in the same positions in the frame and you'll just get a ton of bus clash interrupts.

So we use the set_tdm_slot() like we do with I2S TDM to set which slots are active for each amp.

I can't see that there's any obvious "generic" way that the manager code can automatically figure out how many channels to enable on each amp and what order to map them, so we do it here. Just as with I2S TDM - you have many slots and many codecs but the machine driver has to tell it how to map those.

Quoted 6 lines
Quoted 6 lines
sound/soc/intel/boards/sof_sdw_cs35l56.c new file +6 -0
+		if (ret < 0)
+			return ret;
+	}
+
+	return 0;
+}
#16 lore raw

Re: [PATCH 09/10] ASoC: Intel: sof_sdw: Add support for Cirrus Logic CS35L56

Quoted 35 lines
Quoted 16 lines
Quoted 16 lines

+                      card->components);
+    if (!card->components)
+        return -ENOMEM;
+
+    ret = snd_soc_dapm_new_controls(&card->dapm,
+                    cs35l56_sof_widgets, ARRAY_SIZE(cs35l56_sof_widgets));
+    if (ret) {
+        dev_err(card->dev, "Widgets add failed: %d\n", ret); +        return ret;
+    }
+
+    ret = snd_soc_dapm_add_routes(&card->dapm, cs35l56_sof_map, count); +    if (ret) {
+        dev_err(card->dev, "Map add %d failed: %d\n", count, ret);

Quoted 9 lines
Quoted 6 lines

+        return ret;
+    }
+
+    /* Enable one feedback TX per amp on different slots */ +    for_each_rtd_codec_dais(rtd, i, codec_dai) {
+        ret = snd_soc_dai_set_tdm_slot(codec_dai, 0x3, 1 << i, 4, 16);

TDM slots? Not getting how this would work with SoundWire?

Strictly speaking Soundwire is TDM (the frame time is divided up into slots for each sample...).

The problem is if you have N amps on the dailink all feeding back audio on the same bus. Their DP slots are all programmed to the same positions in the frame, same as for the playback. So you have 4 amps all trying to send 6 audio channels in the same positions in the frame and you'll just get a ton of bus clash interrupts.

Quoted 8 lines

So we use the set_tdm_slot() like we do with I2S TDM to set which slots are active for each amp.

I can't see that there's any obvious "generic" way that the manager code can automatically figure out how many channels to enable on each amp and what order to map them, so we do it here. Just as with I2S TDM - you have many slots and many codecs but the machine driver has to tell it how to map those.

IIRC Bard did the same thing recently, and the order of the feedback channels is really defined by the order in which the peripheral devices are added in the dailink. See
https://github.com/thesofproject/linux/pull/4108

There's also another open related to the number of channels, we need to patch what the CPU DAI can handle, see
https://github.com/thesofproject/linux/pull/4136 or
https://github.com/thesofproject/linux/pull/4134

author maintainer
#17 lore raw

Re: [PATCH 09/10] ASoC: Intel: sof_sdw: Add support for Cirrus Logic CS35L56

Quoted 44 lines · Pierre-Louis Bossart
Quoted 35 lines
Quoted 16 lines
Quoted 16 lines

+                      card->components);
+    if (!card->components)
+        return -ENOMEM;
+
+    ret = snd_soc_dapm_new_controls(&card->dapm,
+                    cs35l56_sof_widgets, ARRAY_SIZE(cs35l56_sof_widgets));
+    if (ret) {
+        dev_err(card->dev, "Widgets add failed: %d\n", ret); +        return ret;
+    }
+
+    ret = snd_soc_dapm_add_routes(&card->dapm, cs35l56_sof_map, count); +    if (ret) {
+        dev_err(card->dev, "Map add %d failed: %d\n", count, ret);

Quoted 9 lines
Quoted 6 lines

+        return ret;
+    }
+
+    /* Enable one feedback TX per amp on different slots */ +    for_each_rtd_codec_dais(rtd, i, codec_dai) {
+        ret = snd_soc_dai_set_tdm_slot(codec_dai, 0x3, 1 << i, 4, 16);

TDM slots? Not getting how this would work with SoundWire?

Strictly speaking Soundwire is TDM (the frame time is divided up into slots for each sample...).

The problem is if you have N amps on the dailink all feeding back audio on the same bus. Their DP slots are all programmed to the same positions in the frame, same as for the playback. So you have 4 amps all trying to send 6 audio channels in the same positions in the frame and you'll just get a ton of bus clash interrupts.

Quoted 8 lines

So we use the set_tdm_slot() like we do with I2S TDM to set which slots are active for each amp.

I can't see that there's any obvious "generic" way that the manager code can automatically figure out how many channels to enable on each amp and what order to map them, so we do it here. Just as with I2S TDM - you have many slots and many codecs but the machine driver has to tell it how to map those.

Quoted 5 lines

IIRC Bard did the same thing recently, and the order of the feedback channels is really defined by the order in which the peripheral devices are added in the dailink. See
https://github.com/thesofproject/linux/pull/4108

I don't really see how it is determining how to split the channels. I see there is a discussion about that but I didn't see any explanation that I could understand.

Also that only seems to have been done for IPCv4. What if my system uses IPCv3 ?

Anyway, I'll drop the machine driver patches for now until the IPC code is stable and consistent behavior for v3 and v4.

Quoted 4 lines

There's also another open related to the number of channels, we need to patch what the CPU DAI can handle, see
https://github.com/thesofproject/linux/pull/4136 or
https://github.com/thesofproject/linux/pull/4134

author maintainer
#18 lore raw

PATCH 10/10 ASoC: Intel: soc-acpi: Add CS35L56 Soundwire to TGL

In reply to Richard Fitzgerald

This adds match entries for one or four CS35L56 on SDW0.

---
 .../intel/common/soc-acpi-intel-tgl-match.c   | 57 +++++++++++++++++++
 1 file changed, 57 insertions(+)
sound/soc/intel/common/soc-acpi-intel-tgl-match.c +57 -0
index ef19150e7b2e..dae76c96d9fe 100644
@@ -414,6 +414,51 @@ struct snd_soc_acpi_mach snd_soc_acpi_intel_tgl_machines[] = {
 };
 EXPORT_SYMBOL_GPL(snd_soc_acpi_intel_tgl_machines);
 
+static const struct snd_soc_acpi_adr_device cs35l56_sdw0_adr[] = {
+	{
+		.adr = 0x00003001fa355601,
+		.num_endpoints = 1,
+		.endpoints = &single_endpoint,
+		.name_prefix = "AMP1"
+	},
+	{
+		.adr = 0x00003101fa355601,
+		.num_endpoints = 1,
+		.endpoints = &single_endpoint,
+		.name_prefix = "AMP2"
+	},
+	{
+		.adr = 0x00003201fa355601,
+		.num_endpoints = 1,
+		.endpoints = &single_endpoint,
+		.name_prefix = "AMP3"
+	},
+	{
+		.adr = 0x00003301fa355601,
+		.num_endpoints = 1,
+		.endpoints = &single_endpoint,
+		.name_prefix = "AMP4"
+	},
+};
+
+static const struct snd_soc_acpi_link_adr up_extreme_cs35l56_sdw0_one[] = {
+	{
+		.mask = BIT(0),
+		.num_adr = 1,
+		.adr_d = cs35l56_sdw0_adr,
+	},
+	{}
+};
+
+static const struct snd_soc_acpi_link_adr up_extreme_cs35l56_sdw0_four[] = {
+	{
+		.mask = BIT(0),
+		.num_adr = 4,
+		.adr_d = cs35l56_sdw0_adr,
+	},
+	{}
+};
+
 /* this table is used when there is no I2S codec present */
 struct snd_soc_acpi_mach snd_soc_acpi_intel_tgl_sdw_machines[] = {
 	/* mockup tests need to be first */
@@ -501,6 +546,18 @@ struct snd_soc_acpi_mach snd_soc_acpi_intel_tgl_sdw_machines[] = {
 		.drv_name = "sof_sdw",
 		.sof_tplg_filename = "sof-tgl-rt711.tplg",
 	},
+	{
+		.link_mask = BIT(0),
+		.links = up_extreme_cs35l56_sdw0_four,
+		.drv_name = "sof_sdw",
+		.sof_tplg_filename = "sof-tgl-cs35l56-sdw0.tplg"
+	},
+	{
+		.link_mask = BIT(0),
+		.links = up_extreme_cs35l56_sdw0_one,
+		.drv_name = "sof_sdw",
+		.sof_tplg_filename = "sof-tgl-cs35l56-sdw0.tplg"
+	},
 	{},
 };
 EXPORT_SYMBOL_GPL(snd_soc_acpi_intel_tgl_sdw_machines);
Signature · 1 line
2.30.2
#19 lore raw

Re: [PATCH 10/10] ASoC: Intel: soc-acpi: Add CS35L56 Soundwire to TGL

Quoted 8 lines
sound/soc/intel/common/soc-acpi-intel-tgl-match.c +7 -0
+static const struct snd_soc_acpi_link_adr up_extreme_cs35l56_sdw0_one[] = {
+	{
+		.mask = BIT(0),
+		.num_adr = 1,
+		.adr_d = cs35l56_sdw0_adr,
+	},
+	{}

sound/soc/intel/common/soc-acpi-intel-tgl-match.c struct snd_soc_acpi_mach snd_soc_acpi_intel_tgl_machines[] = { · line 460

Quoted 10 lines
sound/soc/intel/common/soc-acpi-intel-tgl-match.c +10 -0
+};
+
+static const struct snd_soc_acpi_link_adr up_extreme_cs35l56_sdw0_four[] = {
+	{
+		.mask = BIT(0),
+		.num_adr = 4,
+		.adr_d = cs35l56_sdw0_adr,
+	},
+	{}
+};

If the machine driver has support for the 2-amplifier configuration, shouldn't it be present here as well?

Quoted 23 lines
sound/soc/intel/common/soc-acpi-intel-tgl-match.c +13 -0
+
 /* this table is used when there is no I2S codec present */
 struct snd_soc_acpi_mach snd_soc_acpi_intel_tgl_sdw_machines[] = {
 	/* mockup tests need to be first */
@@ -501,6 +546,18 @@ struct snd_soc_acpi_mach snd_soc_acpi_intel_tgl_sdw_machines[] = {
 		.drv_name = "sof_sdw",
 		.sof_tplg_filename = "sof-tgl-rt711.tplg",
 	},
+	{
+		.link_mask = BIT(0),
+		.links = up_extreme_cs35l56_sdw0_four,
+		.drv_name = "sof_sdw",
+		.sof_tplg_filename = "sof-tgl-cs35l56-sdw0.tplg"
+	},
+	{
+		.link_mask = BIT(0),
+		.links = up_extreme_cs35l56_sdw0_one,
+		.drv_name = "sof_sdw",
+		.sof_tplg_filename = "sof-tgl-cs35l56-sdw0.tplg"
+	},
 	{},
 };
 EXPORT_SYMBOL_GPL(snd_soc_acpi_intel_tgl_sdw_machines);
author maintainer
#20 lore raw

Re: [PATCH 10/10] ASoC: Intel: soc-acpi: Add CS35L56 Soundwire to TGL

Quoted 13 lines · Pierre-Louis Bossart
Quoted 13 lines
sound/soc/intel/common/soc-acpi-intel-tgl-match.c +12 -0
+static const struct snd_soc_acpi_link_adr up_extreme_cs35l56_sdw0_one[] = {
+	{
+		.mask = BIT(0),
+		.num_adr = 1,
+		.adr_d = cs35l56_sdw0_adr,
+	},
+	{}
+};
+
+static const struct snd_soc_acpi_link_adr up_extreme_cs35l56_sdw0_four[] = {
+	{
+		.mask = BIT(0),
Quoted 9 lines

sound/soc/intel/common/soc-acpi-intel-tgl-match.c struct snd_soc_acpi_mach snd_soc_acpi_intel_tgl_machines[] = { · line 460

Quoted 5 lines
sound/soc/intel/common/soc-acpi-intel-tgl-match.c +5 -0
+		.num_adr = 4,
+		.adr_d = cs35l56_sdw0_adr,
+	},
+	{}
+};

If the machine driver has support for the 2-amplifier configuration, shouldn't it be present here as well?

Not necessarily.
It's not a setup we're currently using on this initial TGL configuration.

The machine driver we'd expect to work on multiple hardware. The counting algorithm has to go through "2" anyway, and the code to handle that is so trivial we may as well include it.

Quoted 23 lines
Quoted 23 lines
sound/soc/intel/common/soc-acpi-intel-tgl-match.c +13 -0
+
  /* this table is used when there is no I2S codec present */
  struct snd_soc_acpi_mach snd_soc_acpi_intel_tgl_sdw_machines[] = {
  	/* mockup tests need to be first */
@@ -501,6 +546,18 @@ struct snd_soc_acpi_mach snd_soc_acpi_intel_tgl_sdw_machines[] = {
  		.drv_name = "sof_sdw",
  		.sof_tplg_filename = "sof-tgl-rt711.tplg",
  	},
+	{
+		.link_mask = BIT(0),
+		.links = up_extreme_cs35l56_sdw0_four,
+		.drv_name = "sof_sdw",
+		.sof_tplg_filename = "sof-tgl-cs35l56-sdw0.tplg"
+	},
+	{
+		.link_mask = BIT(0),
+		.links = up_extreme_cs35l56_sdw0_one,
+		.drv_name = "sof_sdw",
+		.sof_tplg_filename = "sof-tgl-cs35l56-sdw0.tplg"
+	},
  	{},
  };
  EXPORT_SYMBOL_GPL(snd_soc_acpi_intel_tgl_sdw_machines);
#21 lore raw

Re: [PATCH 10/10] ASoC: Intel: soc-acpi: Add CS35L56 Soundwire to TGL

Quoted 26 lines · Richard Fitzgerald
Quoted 15 lines · Pierre-Louis Bossart
Quoted 15 lines

+static const struct snd_soc_acpi_link_adr
up_extreme_cs35l56_sdw0_one[] = {
+    {
+        .mask = BIT(0),
+        .num_adr = 1,
+        .adr_d = cs35l56_sdw0_adr,
+    },
+    {}

sound/soc/intel/common/soc-acpi-intel-tgl-match.c +3 -0
+};
+
+static const struct snd_soc_acpi_link_adr

up_extreme_cs35l56_sdw0_four[] = {
+    {
+        .mask = BIT(0),

Quoted 9 lines
Quoted 5 lines

+        .num_adr = 4,
+        .adr_d = cs35l56_sdw0_adr,
+    },
+    {}
+};

If the machine driver has support for the 2-amplifier configuration, shouldn't it be present here as well?

Quoted 7 lines

Not necessarily.
It's not a setup we're currently using on this initial TGL configuration.

The machine driver we'd expect to work on multiple hardware. The counting algorithm has to go through "2" anyway, and the code to handle that is so trivial we may as well include it.

it's fine. usually we are more conservative and have a 1:1 match between the soc-acpi tables and machine driver, but it doesn't hurt to add the 2-amp case in the machine driver.