Skip to contentSkip to conversation

soundwire/ASoC: add mockup codec support

PATCH In review Bard Liao 4 participants 16 messages Jul 14, 2021 – Aug 2, 2021

Subsystems (4)
lore
Share & tools
lore

Bard Liao

author maintainer
#0 lore raw

cover soundwire/ASoC: add mockup codec support

Adding mockup SoundWire codec is useful to debug driver/topology changes without having any actual device connected.

Bard Liao (2):
soundwire: stream: don't abort bank switch on Command_Ignored/-ENODATA
soundwire: stream: don't program mockup device ports

Pierre-Louis Bossart (8):
ASoC: codecs: add SoundWire mockup device support
ASoC: soc-acpi: cnl: add table for SoundWire mockup devices
ASoC: soc-acpi: tgl: add table for SoundWire mockup devices
ASoC: Intel: boards: sof_sdw: add SoundWire mockup codecs for tests
soundwire: add flag to ignore all command/control for mockup devices
soundwire: bus: squelch error returned by mockup devices
soundwire: cadence: add debugfs interface for PDI loopbacks
soundwire: cadence: override PDI configurations to create loopback

 drivers/soundwire/bus.c                       |  10 +-
 drivers/soundwire/cadence_master.c            | 174 ++++++++--
 drivers/soundwire/cadence_master.h            |   3 +
 drivers/soundwire/stream.c                    |   5 +-
 include/linux/soundwire/sdw.h                 |   3 +
 sound/soc/codecs/Kconfig                      |  18 +
 sound/soc/codecs/Makefile                     |   2 +
 sound/soc/codecs/sdw-mockup.c                 | 312 ++++++++++++++++++
 sound/soc/intel/boards/Kconfig                |   1 +
 sound/soc/intel/boards/sof_sdw.c              |  41 +++
 sound/soc/intel/common/Makefile               |   3 +-
 .../intel/common/soc-acpi-intel-cnl-match.c   |  15 +
 .../common/soc-acpi-intel-sdw-mockup-match.c  | 166 ++++++++++
 .../common/soc-acpi-intel-sdw-mockup-match.h  |  17 +
 .../intel/common/soc-acpi-intel-tgl-match.c   |  23 ++
 15 files changed, 754 insertions(+), 39 deletions(-)
 create mode 100644 sound/soc/codecs/sdw-mockup.c
 create mode 100644 sound/soc/intel/common/soc-acpi-intel-sdw-mockup-match.c
 create mode 100644 sound/soc/intel/common/soc-acpi-intel-sdw-mockup-match.h
Signature · 1 line
2.17.1
author maintainer
#1 lore raw

PATCH 1/10 ASoC: codecs: add SoundWire mockup device support

From: Pierre-Louis Bossart <[email protected]>

To test the host controller and bus management code, it is currently required to have a physical SoundWire peripheral attached to the bus. To help with pre-silicon or early hardware enablement, it would be very useful to have a SoundWire 'mockup' device that is exposed in platform firmware but does not drive any signal on the bus.

This is different to the existing ASoC 'dummy' codec uses for I2S/TDM, the SoundWire spec makes it clear that a device that is not attached to the bus is not permitted to interact with the bus, be it for command/control or data.

This patch exposes a 'mockup' device, with a minimalist driver, with 4 partID values reserved by Intel for such test configurations. The mockup device exposes one full-duplex DAI based on 2 ports (DP1 for playback and DP8 for capture). The capture data port is just virtual, such a mockup device is prevented by the SoundWire specification from presenting any data generated by a Source port without being Attached.

All the callbacks exposed by the SoundWire Slave interface are populated, even if they just return immediately. This is intentional to describe what a minimal codec driver should do and implement and help new codec vendors provide support for their devices.

---
 sound/soc/codecs/Kconfig      |  18 ++
 sound/soc/codecs/Makefile     |   2 +
 sound/soc/codecs/sdw-mockup.c | 310 ++++++++++++++++++++++++++++++++++
 3 files changed, 330 insertions(+)
 create mode 100644 sound/soc/codecs/sdw-mockup.c
sound/soc/codecs/Kconfig +18 -0
index 7ebae3f09435..9e3e4db3d75d 100644
@@ -187,6 +187,7 @@ config SND_SOC_ALL_CODECS
 	imply SND_SOC_RT715_SDCA_SDW
 	imply SND_SOC_RT1308_SDW
 	imply SND_SOC_RT1316_SDW
+	imply SND_SOC_SDW_MOCKUP
 	imply SND_SOC_SGTL5000
 	imply SND_SOC_SI476X
 	imply SND_SOC_SIMPLE_AMPLIFIER
@@ -1287,6 +1288,23 @@ config SND_SOC_RT715_SDCA_SDW
 	select REGMAP_SOUNDWIRE
 	select REGMAP_SOUNDWIRE_MBQ
 
+config SND_SOC_SDW_MOCKUP
+	tristate "SoundWire mockup codec"
+	depends on EXPERT
+	depends on SOUNDWIRE
+	help
+	  This option enables a SoundWire mockup codec that does not drive the
+	  bus, take part in the command/command protocol or generate data on a
+	  Source port.
+	  This option is only intended to be used for tests on a device
+	  with a connector, in combination with a bus analyzer, or to test new
+	  topologies that differ from the actual hardware layout.
+	  This mockup device could be totally virtual but could also be a
+	  real physical one with one key restriction: it is not allowed by the
+	  SoundWire specification to be configured via a sideband mechanism and
+	  generate audio data for capture. However, nothing prevents such a
+	  peripheral device from snooping the bus.
+
 #Freescale sgtl5000 codec
 config SND_SOC_SGTL5000
 	tristate "Freescale SGTL5000 CODEC"
sound/soc/codecs/Makefile +2 -0
index de8b83dd2c76..d656b1405473 100644
@@ -203,6 +203,7 @@ snd-soc-rt711-objs := rt711.o rt711-sdw.o
 snd-soc-rt711-sdca-objs := rt711-sdca.o rt711-sdca-sdw.o
 snd-soc-rt715-objs := rt715.o rt715-sdw.o
 snd-soc-rt715-sdca-objs := rt715-sdca.o rt715-sdca-sdw.o
+snd-soc-sdw-mockup-objs := sdw-mockup.o
 snd-soc-sgtl5000-objs := sgtl5000.o
 snd-soc-alc5623-objs := alc5623.o
 snd-soc-alc5632-objs := alc5632.o
@@ -530,6 +531,7 @@ obj-$(CONFIG_SND_SOC_RT711)     += snd-soc-rt711.o
 obj-$(CONFIG_SND_SOC_RT711_SDCA_SDW)     += snd-soc-rt711-sdca.o
 obj-$(CONFIG_SND_SOC_RT715)     += snd-soc-rt715.o
 obj-$(CONFIG_SND_SOC_RT715_SDCA_SDW)     += snd-soc-rt715-sdca.o
+obj-$(CONFIG_SND_SOC_SDW_MOCKUP)     += snd-soc-sdw-mockup.o
 obj-$(CONFIG_SND_SOC_SGTL5000)  += snd-soc-sgtl5000.o
 obj-$(CONFIG_SND_SOC_SIGMADSP)	+= snd-soc-sigmadsp.o
 obj-$(CONFIG_SND_SOC_SIGMADSP_I2C)	+= snd-soc-sigmadsp-i2c.o
sound/soc/codecs/sdw-mockup.c new file +310 -0

310 lines not on this page · raw message

Signature · 1 line
2.17.1
author maintainer
#2 lore raw

PATCH 2/10 ASoC: soc-acpi: cnl: add table for SoundWire mockup devices

In reply to Bard Liao

From: Pierre-Louis Bossart <[email protected]>

Add support for two configurations with SoundWire mockup devices that emulate the two CometLake configurations with one and two amps. This patch helps test the SOF firmware on an UpExtreme board without any hardware connected, e.g. by doing a loopback of the playback stream on capture streams.

The mapping of the partIDs is as follows:

0xAAAA: generic full-duplex codec (not currently used) 0xAA55: headset codec (mock-up of RT711/RT5682) - full-duplex 0x55AA: amplifier (mock-up of RT1308/RT1316/Maxim 98373) - playback with IV sense feedback
0x5555: mic codec (mock-up of RT715) - capture-only

The tables are added in a separate file to allow for mockup codecs to be added on other platforms, but the mapping to specific topologies remains platform-specific.

---
 sound/soc/intel/common/Makefile               |   3 +-
 .../intel/common/soc-acpi-intel-cnl-match.c   |  15 ++
 .../common/soc-acpi-intel-sdw-mockup-match.c  | 166 ++++++++++++++++++
 .../common/soc-acpi-intel-sdw-mockup-match.h  |  17 ++
 4 files changed, 200 insertions(+), 1 deletion(-)
 create mode 100644 sound/soc/intel/common/soc-acpi-intel-sdw-mockup-match.c
 create mode 100644 sound/soc/intel/common/soc-acpi-intel-sdw-mockup-match.h
sound/soc/intel/common/Makefile +2 -1
index 12a205ccdeeb..fef0b2d1de68 100644
@@ -9,7 +9,8 @@ snd-soc-acpi-intel-match-objs := soc-acpi-intel-byt-match.o soc-acpi-intel-cht-m
 	soc-acpi-intel-cml-match.o soc-acpi-intel-icl-match.o \
 	soc-acpi-intel-tgl-match.o soc-acpi-intel-ehl-match.o \
 	soc-acpi-intel-jsl-match.o soc-acpi-intel-adl-match.o \
-	soc-acpi-intel-hda-match.o
+	soc-acpi-intel-hda-match.o \
+	soc-acpi-intel-sdw-mockup-match.o
 
 obj-$(CONFIG_SND_SOC_INTEL_SST) += snd-soc-sst-dsp.o snd-soc-sst-ipc.o
 obj-$(CONFIG_SND_SOC_ACPI_INTEL_MATCH) += snd-soc-acpi-intel-match.o
sound/soc/intel/common/soc-acpi-intel-cnl-match.c +15 -0
index 39dad32564e6..94b650767e11 100644
@@ -9,6 +9,7 @@
 #include <sound/soc-acpi.h>
 #include <sound/soc-acpi-intel-match.h>
 #include "../skylake/skl.h"
+#include "soc-acpi-intel-sdw-mockup-match.h"
 
 static struct skl_machine_pdata cnl_pdata = {
 	.use_tplg_pcm = true,
@@ -60,6 +61,20 @@ struct snd_soc_acpi_mach snd_soc_acpi_intel_cnl_sdw_machines[] = {
 		.sof_fw_filename = "sof-cnl.ri",
 		.sof_tplg_filename = "sof-cnl-rt5682-sdw2.tplg"
 	},
+	{
+		.link_mask = GENMASK(3, 0),
+		.links = sdw_mockup_headset_2amps_mic,
+		.drv_name = "sof_sdw",
+		.sof_fw_filename = "sof-cnl.ri",
+		.sof_tplg_filename = "sof-cml-rt711-rt1308-rt715.tplg",
+	},
+	{
+		.link_mask = BIT(0) | BIT(1) | BIT(3),
+		.links = sdw_mockup_headset_1amp_mic,
+		.drv_name = "sof_sdw",
+		.sof_fw_filename = "sof-cnl.ri",
+		.sof_tplg_filename = "sof-cml-rt711-rt1308-mono-rt715.tplg",
+	},
 	{}
 };
 EXPORT_SYMBOL_GPL(snd_soc_acpi_intel_cnl_sdw_machines);
sound/soc/intel/common/soc-acpi-intel-sdw-mockup-match.c new file +166 -0

166 lines not on this page · raw message

sound/soc/intel/common/soc-acpi-intel-sdw-mockup-match.h new file +17 -0
new file mode 100644
index 000000000000..c99eecd19e03
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * soc-acpi-intel-sdw-mockup-match.h - tables and support for SoundWire
+ * mockup device ACPI enumeration.
+ *
+ * Copyright (c) 2021, Intel Corporation.
+ *
+ */
+
+#ifndef _SND_SOC_ACPI_INTEL_SDW_MOCKUP_MATCH
+#define _SND_SOC_ACPI_INTEL_SDW_MOCKUP_MATCH
+
+extern const struct snd_soc_acpi_link_adr sdw_mockup_headset_1amp_mic[];
+extern const struct snd_soc_acpi_link_adr sdw_mockup_headset_2amps_mic[];
+extern const struct snd_soc_acpi_link_adr sdw_mockup_mic_headset_1amp[];
+
+#endif
Signature · 1 line
2.17.1
author maintainer
#3 lore raw

PATCH 3/10 ASoC: soc-acpi: tgl: add table for SoundWire mockup devices

In reply to Bard Liao

From: Pierre-Louis Bossart <[email protected]>

Follow the same idea as for CNL/UpExtreme and add mockup test first. They will only be selected if the SSDT is modified to add such mockup devices.

---
 .../intel/common/soc-acpi-intel-tgl-match.c   | 23 +++++++++++++++++++
 1 file changed, 23 insertions(+)
sound/soc/intel/common/soc-acpi-intel-tgl-match.c +23 -0
index 66595e3ab13f..e2488f0eaff8 100644
@@ -8,6 +8,7 @@
 
 #include <sound/soc-acpi.h>
 #include <sound/soc-acpi-intel-match.h>
+#include "soc-acpi-intel-sdw-mockup-match.h"
 
 static const struct snd_soc_acpi_codecs tgl_codecs = {
 	.num_codecs = 1,
@@ -351,6 +352,28 @@ EXPORT_SYMBOL_GPL(snd_soc_acpi_intel_tgl_machines);
 
 /* 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 */
+	{
+		.link_mask = GENMASK(3, 0),
+		.links = sdw_mockup_headset_2amps_mic,
+		.drv_name = "sof_sdw",
+		.sof_fw_filename = "sof-tgl.ri",
+		.sof_tplg_filename = "sof-tgl-rt711-rt1308-rt715.tplg",
+	},
+	{
+		.link_mask = BIT(0) | BIT(1) | BIT(3),
+		.links = sdw_mockup_headset_1amp_mic,
+		.drv_name = "sof_sdw",
+		.sof_fw_filename = "sof-tgl.ri",
+		.sof_tplg_filename = "sof-tgl-rt711-rt1308-mono-rt715.tplg",
+	},
+	{
+		.link_mask = BIT(0) | BIT(1) | BIT(2),
+		.links = sdw_mockup_mic_headset_1amp,
+		.drv_name = "sof_sdw",
+		.sof_fw_filename = "sof-tgl.ri",
+		.sof_tplg_filename = "sof-tgl-rt715-rt711-rt1308-mono.tplg",
+	},
 	{
 		.link_mask = 0x7,
 		.links = tgl_sdw_rt711_link1_rt1308_link2_rt715_link0,
Signature · 1 line
2.17.1
author maintainer
#4 lore raw

PATCH 4/10 ASoC: Intel: boards: sof_sdw: add SoundWire mockup codecs for tests

In reply to Bard Liao

From: Pierre-Louis Bossart <[email protected]>

Add support for SoundWire mockup devices. The configurations assume the same topology as the CML SoundWire devices and can be used to test the SOF firmware on a development board (RVP, UpExtreme) without any hardware connected.

---
 sound/soc/intel/boards/Kconfig   |  1 +
 sound/soc/intel/boards/sof_sdw.c | 41 ++++++++++++++++++++++++++++++++
 2 files changed, 42 insertions(+)
sound/soc/intel/boards/Kconfig +1 -0
index 7e29b0d911e2..046955bf717c 100644
@@ -602,6 +602,7 @@ config SND_SOC_INTEL_SOUNDWIRE_SOF_MACH
 	select SND_SOC_DMIC
 	select SND_SOC_INTEL_HDA_DSP_COMMON
 	select SND_SOC_INTEL_SOF_MAXIM_COMMON
+	select SND_SOC_SDW_MOCKUP
 	help
 	  Add support for Intel SoundWire-based platforms connected to
 	  MAX98373, RT700, RT711, RT1308 and RT715
sound/soc/intel/boards/sof_sdw.c +41 -0

53 lines not on this page · raw message

Signature · 1 line
2.17.1
author maintainer
#5 lore raw

PATCH 5/10 soundwire: stream: don't abort bank switch on Command_Ignored/-ENODATA

In reply to Bard Liao

This change is needed for support of mockup devices, which by construction will not provide any answer to a bank switch, but it's also legit for regular cases.

If for some reason a device loses sync and cannot handle a bank switch, we should go ahead anyways. The devices can always resync later.

The only case where the error flow should be used is when there is a Command_Aborted composite answer from SoundWire devices.

---
 drivers/soundwire/stream.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/soundwire/stream.c +1 -1
index 1a18308f4ef4..d84aaf115c13 100644
@@ -697,7 +697,7 @@ static int sdw_bank_switch(struct sdw_bus *bus, int m_rt_count)
 	else
 		ret = sdw_transfer(bus, wr_msg);
 
-	if (ret < 0) {
+	if (ret < 0 && ret != -ENODATA) {
 		dev_err(bus->dev, "Slave frame_ctrl reg write failed\n");
 		goto error;
 	}
Signature · 1 line
2.17.1
author maintainer
#6 lore raw

PATCH 6/10 soundwire: add flag to ignore all command/control for mockup devices

In reply to Bard Liao

From: Pierre-Louis Bossart <[email protected]>

SoundWire mockup devices don't take part in the command/control protocol, so all commands will complete with -ENODATA or Command_Ignored results. With a flag, we can suppress such errors in the bus management and make it appear as if all read/writes succeed.

---
 include/linux/soundwire/sdw.h | 3 +++
 sound/soc/codecs/sdw-mockup.c | 2 ++
 2 files changed, 5 insertions(+)
include/linux/soundwire/sdw.h +3 -0
index a48ac3e77301..76ce3f3ac0f2 100644
@@ -661,6 +661,8 @@ struct sdw_slave_ops {
  * initialized
  * @first_interrupt_done: status flag tracking if the interrupt handling
  * for a Slave happens for the first time after enumeration
+ * @is_mockup_device: status flag used to squelch errors in the command/control
+ * protocol for SoundWire mockup devices
  */
 struct sdw_slave {
 	struct sdw_slave_id id;
@@ -683,6 +685,7 @@ struct sdw_slave {
 	struct completion initialization_complete;
 	u32 unattach_request;
 	bool first_interrupt_done;
+	bool is_mockup_device;
 };
 
 #define dev_to_sdw_dev(_dev) container_of(_dev, struct sdw_slave, dev)
sound/soc/codecs/sdw-mockup.c +2 -0
index a4f79eb2c69d..8ea13cfa9f8e 100644
@@ -263,6 +263,8 @@ static int sdw_mockup_sdw_probe(struct sdw_slave *slave,
 	dev_set_drvdata(dev, sdw_mockup);
 	sdw_mockup->slave = slave;
 
+	slave->is_mockup_device = true;
+
 	ret =  devm_snd_soc_register_component(dev,
 					       &snd_soc_sdw_mockup_component,
 					       sdw_mockup_dai,
Signature · 1 line
2.17.1
author maintainer
#7 lore raw

PATCH 7/10 soundwire: bus: squelch error returned by mockup devices

In reply to Bard Liao

From: Pierre-Louis Bossart <[email protected]>

All read and writes from/to SoundWire mockup devices will return -ENODATA/Command_Ignored, this patch forces a Command_OK result to let the bus perform the required configurations, e.g. for the Data Ports, which will only have an effect on the Master side.

---
 drivers/soundwire/bus.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/soundwire/bus.c +8 -2
index 278a4fbdb88d..baa236cb5484 100644
@@ -390,7 +390,10 @@ sdw_nread_no_pm(struct sdw_slave *slave, u32 addr, size_t count, u8 *val)
 	if (ret < 0)
 		return ret;
 
-	return sdw_transfer(slave->bus, &msg);
+	ret = sdw_transfer(slave->bus, &msg);
+	if (slave->is_mockup_device)
+		ret = 0;
+	return ret;
 }
 
 static int
@@ -404,7 +407,10 @@ sdw_nwrite_no_pm(struct sdw_slave *slave, u32 addr, size_t count, const u8 *val)
 	if (ret < 0)
 		return ret;
 
-	return sdw_transfer(slave->bus, &msg);
+	ret = sdw_transfer(slave->bus, &msg);
+	if (slave->is_mockup_device)
+		ret = 0;
+	return ret;
 }
 
 int sdw_write_no_pm(struct sdw_slave *slave, u32 addr, u8 value)
Signature · 1 line
2.17.1
author maintainer
#8 lore raw

PATCH 8/10 soundwire: stream: don't program mockup device ports

In reply to Bard Liao

Mockup devices don't take part in command/control operations and their virtual ports shall not be programmed.

---
 drivers/soundwire/stream.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/soundwire/stream.c +3 -0
index d84aaf115c13..5d4f6b308ef7 100644
@@ -133,6 +133,9 @@ static int sdw_program_slave_port_params(struct sdw_bus *bus,
 	int ret;
 	u8 wbuf;
 
+	if (s_rt->slave->is_mockup_device)
+		return 0;
+
 	dpn_prop = sdw_get_slave_dpn_prop(s_rt->slave,
 					  s_rt->direction,
 					  t_params->port_num);
Signature · 1 line
2.17.1
author maintainer
#9 lore raw

PATCH 9/10 soundwire: cadence: add debugfs interface for PDI loopbacks

In reply to Bard Liao

From: Pierre-Louis Bossart <[email protected]>

For debug, it's interesting to create a loopback stream for each link and use debugfs to set a source and target PDI. The target PDI would need to be an RX port and use the same register configurations as the source PDI. This capability allows e.g. for the headphone playback stream to be snooped on the headset capture stream, or alternatively for the addition of a dedicated loopback stream, in addition of regular capture for that link.

This patch only adds the debugfs part, the port/PDI handling will be handled in the next patches.

---
 drivers/soundwire/cadence_master.c | 44 ++++++++++++++++++++++++++++++
 drivers/soundwire/cadence_master.h |  3 ++
 2 files changed, 47 insertions(+)
drivers/soundwire/cadence_master.c +44 -0
index 9a9b6110e763..3e740fcebdfe 100644
@@ -450,6 +450,40 @@ static int cdns_parity_error_injection(void *data, u64 value)
 DEFINE_DEBUGFS_ATTRIBUTE(cdns_parity_error_fops, NULL,
 			 cdns_parity_error_injection, "%llu\n");
 
+static int cdns_set_pdi_loopback_source(void *data, u64 value)
+{
+	struct sdw_cdns *cdns = data;
+	unsigned int pdi_out_num = cdns->pcm.num_bd + cdns->pcm.num_out;
+
+	if (value > pdi_out_num)
+		return -EINVAL;
+
+	/* Userspace changed the hardware state behind the kernel's back */
+	add_taint(TAINT_USER, LOCKDEP_STILL_OK);
+
+	cdns->pdi_loopback_source = value;
+
+	return 0;
+}
+DEFINE_DEBUGFS_ATTRIBUTE(cdns_pdi_loopback_source_fops, NULL, cdns_set_pdi_loopback_source, "%llu\n");
+
+static int cdns_set_pdi_loopback_target(void *data, u64 value)
+{
+	struct sdw_cdns *cdns = data;
+	unsigned int pdi_in_num = cdns->pcm.num_bd + cdns->pcm.num_in;
+
+	if (value > pdi_in_num)
+		return -EINVAL;
+
+	/* Userspace changed the hardware state behind the kernel's back */
+	add_taint(TAINT_USER, LOCKDEP_STILL_OK);
+
+	cdns->pdi_loopback_target = value;
+
+	return 0;
+}
+DEFINE_DEBUGFS_ATTRIBUTE(cdns_pdi_loopback_target_fops, NULL, cdns_set_pdi_loopback_target, "%llu\n");
+
 /**
  * sdw_cdns_debugfs_init() - Cadence debugfs init
  * @cdns: Cadence instance
@@ -464,6 +498,16 @@ void sdw_cdns_debugfs_init(struct sdw_cdns *cdns, struct dentry *root)
 
 	debugfs_create_file("cdns-parity-error-injection", 0200, root, cdns,
 			    &cdns_parity_error_fops);
+
+	cdns->pdi_loopback_source = -1;
+	cdns->pdi_loopback_target = -1;
+
+	debugfs_create_file("cdns-pdi-loopback-source", 0200, root, cdns,
+			    &cdns_pdi_loopback_source_fops);
+
+	debugfs_create_file("cdns-pdi-loopback-target", 0200, root, cdns,
+			    &cdns_pdi_loopback_target_fops);
+
 }
 EXPORT_SYMBOL_GPL(sdw_cdns_debugfs_init);
 
drivers/soundwire/cadence_master.h +3 -0
index 0e7f8b35bb21..6c039d456ba8 100644
@@ -129,6 +129,9 @@ struct sdw_cdns {
 	struct sdw_cdns_streams pcm;
 	struct sdw_cdns_streams pdm;
 
+	int pdi_loopback_source;
+	int pdi_loopback_target;
+
 	void __iomem *registers;
 
 	bool link_up;
Signature · 1 line
2.17.1
author maintainer
#10 lore raw

PATCH 10/10 soundwire: cadence: override PDI configurations to create loopback

In reply to Bard Liao

From: Pierre-Louis Bossart <[email protected]>

When we set a source PDI, the target PDI parameters will be overridden by the source register values. The loopback streams can be independently enabled on each link.

While the loopback source and target can be configured before any stream is active on each link, the loopback stream should only be prepared/triggered when the playback stream is prepared. Otherwise all registers might be programmed to their reset values and the loopback will not succeed. The SoundWire bus driver currently does not allow two streams to be triggered at the same time, so the playback will have to be started first, and later the loopback.

---
 drivers/soundwire/cadence_master.c | 130 +++++++++++++++++++++--------
 1 file changed, 95 insertions(+), 35 deletions(-)
drivers/soundwire/cadence_master.c +95 -35
index 3e740fcebdfe..c7372519452b 100644
@@ -1329,20 +1329,37 @@ static int cdns_port_params(struct sdw_bus *bus,
 			    struct sdw_port_params *p_params, unsigned int bank)
 {
 	struct sdw_cdns *cdns = bus_to_cdns(bus);
-	int dpn_config = 0, dpn_config_off;
+	int dpn_config_off_source;
+	int dpn_config_off_target;
+	int target_num = p_params->num;
+	int source_num = p_params->num;
+	bool override = false;
+	int dpn_config;
 
-	if (bank)
-		dpn_config_off = CDNS_DPN_B1_CONFIG(p_params->num);
-	else
-		dpn_config_off = CDNS_DPN_B0_CONFIG(p_params->num);
+	if (target_num == cdns->pdi_loopback_target &&
+	    cdns->pdi_loopback_source != -1) {
+		source_num = cdns->pdi_loopback_source;
+		override = true;
+	}
 
-	dpn_config = cdns_readl(cdns, dpn_config_off);
+	if (bank) {
+		dpn_config_off_source = CDNS_DPN_B1_CONFIG(source_num);
+		dpn_config_off_target = CDNS_DPN_B1_CONFIG(target_num);
+	} else {
+		dpn_config_off_source = CDNS_DPN_B0_CONFIG(source_num);
+		dpn_config_off_target = CDNS_DPN_B0_CONFIG(target_num);
+	}
 
-	u32p_replace_bits(&dpn_config, (p_params->bps - 1), CDNS_DPN_CONFIG_WL);
-	u32p_replace_bits(&dpn_config, p_params->flow_mode, CDNS_DPN_CONFIG_PORT_FLOW);
-	u32p_replace_bits(&dpn_config, p_params->data_mode, CDNS_DPN_CONFIG_PORT_DAT);
+	dpn_config = cdns_readl(cdns, dpn_config_off_source);
 
-	cdns_writel(cdns, dpn_config_off, dpn_config);
+	/* use port params if there is no loopback, otherwise use source as is */
+	if (!override) {
+		u32p_replace_bits(&dpn_config, p_params->bps - 1, CDNS_DPN_CONFIG_WL);
+		u32p_replace_bits(&dpn_config, p_params->flow_mode, CDNS_DPN_CONFIG_PORT_FLOW);
+		u32p_replace_bits(&dpn_config, p_params->data_mode, CDNS_DPN_CONFIG_PORT_DAT);
+	}
+
+	cdns_writel(cdns, dpn_config_off_target, dpn_config);
 
 	return 0;
 }
@@ -1352,11 +1369,27 @@ static int cdns_transport_params(struct sdw_bus *bus,
 				 enum sdw_reg_bank bank)
 {
 	struct sdw_cdns *cdns = bus_to_cdns(bus);
-	int dpn_offsetctrl = 0, dpn_offsetctrl_off;
-	int dpn_config = 0, dpn_config_off;
-	int dpn_hctrl = 0, dpn_hctrl_off;
-	int num = t_params->port_num;
-	int dpn_samplectrl_off;
+	int dpn_config;
+	int dpn_config_off_source;
+	int dpn_config_off_target;
+	int dpn_hctrl;
+	int dpn_hctrl_off_source;
+	int dpn_hctrl_off_target;
+	int dpn_offsetctrl;
+	int dpn_offsetctrl_off_source;
+	int dpn_offsetctrl_off_target;
+	int dpn_samplectrl;
+	int dpn_samplectrl_off_source;
+	int dpn_samplectrl_off_target;
+	int source_num = t_params->port_num;
+	int target_num = t_params->port_num;
+	bool override = false;
+
+	if (target_num == cdns->pdi_loopback_target &&
+	    cdns->pdi_loopback_source != -1) {
+		source_num = cdns->pdi_loopback_source;
+		override = true;
+	}
 
 	/*
 	 * Note: Only full data port is supported on the Master side for
@@ -1364,32 +1397,59 @@ static int cdns_transport_params(struct sdw_bus *bus,
 	 */
 
 	if (bank) {
-		dpn_config_off = CDNS_DPN_B1_CONFIG(num);
-		dpn_samplectrl_off = CDNS_DPN_B1_SAMPLE_CTRL(num);
-		dpn_hctrl_off = CDNS_DPN_B1_HCTRL(num);
-		dpn_offsetctrl_off = CDNS_DPN_B1_OFFSET_CTRL(num);
+		dpn_config_off_source = CDNS_DPN_B1_CONFIG(source_num);
+		dpn_hctrl_off_source = CDNS_DPN_B1_HCTRL(source_num);
+		dpn_offsetctrl_off_source = CDNS_DPN_B1_OFFSET_CTRL(source_num);
+		dpn_samplectrl_off_source = CDNS_DPN_B1_SAMPLE_CTRL(source_num);
+
+		dpn_config_off_target = CDNS_DPN_B1_CONFIG(target_num);
+		dpn_hctrl_off_target = CDNS_DPN_B1_HCTRL(target_num);
+		dpn_offsetctrl_off_target = CDNS_DPN_B1_OFFSET_CTRL(target_num);
+		dpn_samplectrl_off_target = CDNS_DPN_B1_SAMPLE_CTRL(target_num);
+
 	} else {
-		dpn_config_off = CDNS_DPN_B0_CONFIG(num);
-		dpn_samplectrl_off = CDNS_DPN_B0_SAMPLE_CTRL(num);
-		dpn_hctrl_off = CDNS_DPN_B0_HCTRL(num);
-		dpn_offsetctrl_off = CDNS_DPN_B0_OFFSET_CTRL(num);
+		dpn_config_off_source = CDNS_DPN_B0_CONFIG(source_num);
+		dpn_hctrl_off_source = CDNS_DPN_B0_HCTRL(source_num);
+		dpn_offsetctrl_off_source = CDNS_DPN_B0_OFFSET_CTRL(source_num);
+		dpn_samplectrl_off_source = CDNS_DPN_B0_SAMPLE_CTRL(source_num);
+
+		dpn_config_off_target = CDNS_DPN_B0_CONFIG(target_num);
+		dpn_hctrl_off_target = CDNS_DPN_B0_HCTRL(target_num);
+		dpn_offsetctrl_off_target = CDNS_DPN_B0_OFFSET_CTRL(target_num);
+		dpn_samplectrl_off_target = CDNS_DPN_B0_SAMPLE_CTRL(target_num);
 	}
 
-	dpn_config = cdns_readl(cdns, dpn_config_off);
-	u32p_replace_bits(&dpn_config, t_params->blk_grp_ctrl, CDNS_DPN_CONFIG_BGC);
-	u32p_replace_bits(&dpn_config, t_params->blk_pkg_mode, CDNS_DPN_CONFIG_BPM);
-	cdns_writel(cdns, dpn_config_off, dpn_config);
+	dpn_config = cdns_readl(cdns, dpn_config_off_source);
+	if (!override) {
+		u32p_replace_bits(&dpn_config, t_params->blk_grp_ctrl, CDNS_DPN_CONFIG_BGC);
+		u32p_replace_bits(&dpn_config, t_params->blk_pkg_mode, CDNS_DPN_CONFIG_BPM);
+	}
+	cdns_writel(cdns, dpn_config_off_target, dpn_config);
 
-	u32p_replace_bits(&dpn_offsetctrl, t_params->offset1, CDNS_DPN_OFFSET_CTRL_1);
-	u32p_replace_bits(&dpn_offsetctrl, t_params->offset2, CDNS_DPN_OFFSET_CTRL_2);
-	cdns_writel(cdns, dpn_offsetctrl_off,  dpn_offsetctrl);
+	if (!override) {
+		dpn_offsetctrl = 0;
+		u32p_replace_bits(&dpn_offsetctrl, t_params->offset1, CDNS_DPN_OFFSET_CTRL_1);
+		u32p_replace_bits(&dpn_offsetctrl, t_params->offset2, CDNS_DPN_OFFSET_CTRL_2);
+	} else {
+		dpn_offsetctrl = cdns_readl(cdns, dpn_offsetctrl_off_source);
+	}
+	cdns_writel(cdns, dpn_offsetctrl_off_target,  dpn_offsetctrl);
 
-	u32p_replace_bits(&dpn_hctrl, t_params->hstart, CDNS_DPN_HCTRL_HSTART);
-	u32p_replace_bits(&dpn_hctrl, t_params->hstop, CDNS_DPN_HCTRL_HSTOP);
-	u32p_replace_bits(&dpn_hctrl, t_params->lane_ctrl, CDNS_DPN_HCTRL_LCTRL);
+	if (!override) {
+		dpn_hctrl = 0;
+		u32p_replace_bits(&dpn_hctrl, t_params->hstart, CDNS_DPN_HCTRL_HSTART);
+		u32p_replace_bits(&dpn_hctrl, t_params->hstop, CDNS_DPN_HCTRL_HSTOP);
+		u32p_replace_bits(&dpn_hctrl, t_params->lane_ctrl, CDNS_DPN_HCTRL_LCTRL);
+	} else {
+		dpn_hctrl = cdns_readl(cdns, dpn_hctrl_off_source);
+	}
+	cdns_writel(cdns, dpn_hctrl_off_target, dpn_hctrl);
 
-	cdns_writel(cdns, dpn_hctrl_off, dpn_hctrl);
-	cdns_writel(cdns, dpn_samplectrl_off, (t_params->sample_interval - 1));
+	if (!override)
+		dpn_samplectrl = t_params->sample_interval - 1;
+	else
+		dpn_samplectrl = cdns_readl(cdns, dpn_samplectrl_off_source);
+	cdns_writel(cdns, dpn_samplectrl_off_target, dpn_samplectrl);
 
 	return 0;
 }
Signature · 1 line
2.17.1
maintainer
#11 lore raw
In reply to Bard Liao
Quoted 2 lines · Bard Liao

Adding mockup SoundWire codec is useful to debug driver/topology changes without having any actual device connected.

The following changes since commit e73f0f0ee7541171d89f2e2491130c7771ba58d3:

Linux 5.14-rc1 (2021-07-11 15:07:40 -0700)

are available in the Git repository at:

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git tags/asoc-sdw-mockup-codec

for you to fetch changes up to 0ccac3bcf3564cbcba483dec20c7550939873f59:

ASoC: Intel: boards: sof_sdw: add SoundWire mockup codecs for tests (2021-07-14 18:02:07 +0100)

----------------------------------------------------------------
ASoC: Add mockup SoundWire CODEC

Useful for bringup testing, not for production usage.

----------------------------------------------------------------
Pierre-Louis Bossart (4):
ASoC: codecs: add SoundWire mockup device support
ASoC: soc-acpi: cnl: add table for SoundWire mockup devices
ASoC: soc-acpi: tgl: add table for SoundWire mockup devices
ASoC: Intel: boards: sof_sdw: add SoundWire mockup codecs for tests

 sound/soc/codecs/Kconfig                           |  18 ++
 sound/soc/codecs/Makefile                          |   2 +
 sound/soc/codecs/sdw-mockup.c                      | 310 +++++++++++++++++++++
 sound/soc/intel/boards/Kconfig                     |   1 +
 sound/soc/intel/boards/sof_sdw.c                   |  41 +++
 sound/soc/intel/common/Makefile                    |   3 +-
 sound/soc/intel/common/soc-acpi-intel-cnl-match.c  |  15 +
 .../intel/common/soc-acpi-intel-sdw-mockup-match.c | 166 +++++++++++
 .../intel/common/soc-acpi-intel-sdw-mockup-match.h |  17 ++
 sound/soc/intel/common/soc-acpi-intel-tgl-match.c  |  23 ++
 10 files changed, 595 insertions(+), 1 deletion(-)
 create mode 100644 sound/soc/codecs/sdw-mockup.c
 create mode 100644 sound/soc/intel/common/soc-acpi-intel-sdw-mockup-match.c
 create mode 100644 sound/soc/intel/common/soc-acpi-intel-sdw-mockup-match.h
maintainer
#12 lore raw
Quoted 8 lines · Mark Brown
Quoted 2 lines · Bard Liao

Adding mockup SoundWire codec is useful to debug driver/topology changes without having any actual device connected.

The following changes since commit e73f0f0ee7541171d89f2e2491130c7771ba58d3:

Linux 5.14-rc1 (2021-07-11 15:07:40 -0700)

Quoted 7 lines

are available in the Git repository at:

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git tags/asoc-sdw-mockup-codec

for you to fetch changes up to 0ccac3bcf3564cbcba483dec20c7550939873f59:

ASoC: Intel: boards: sof_sdw: add SoundWire mockup codecs for tests (2021-07-14 18:02:07 +0100)

Thank You! Merged to sdw-next

Signature · 1 line
~Vinod
maintainer
#13 lore raw

Re: (subset) [PATCH 00/10] soundwire/ASoC: add mockup codec support

In reply to Bard Liao
Quoted 8 lines · Bard Liao

Adding mockup SoundWire codec is useful to debug driver/topology changes without having any actual device connected.

Bard Liao (2):
soundwire: stream: don't abort bank switch on Command_Ignored/-ENODATA
soundwire: stream: don't program mockup device ports

[...]

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next

Thanks!

[01/10] ASoC: codecs: add SoundWire mockup device support

        commit: 81d3d3d0bf09e606dbc1e3daad1c7cef3976fca2
[02/10] ASoC: soc-acpi: cnl: add table for SoundWire mockup devices
        commit: 2694cda7a4393fbd436e28474832a053e70e0733
[03/10] ASoC: soc-acpi: tgl: add table for SoundWire mockup devices
        commit: 3025d398c436d313f9b6b5c1f53918efeafcf5dc
[04/10] ASoC: Intel: boards: sof_sdw: add SoundWire mockup codecs for tests
        commit: 0ccac3bcf3564cbcba483dec20c7550939873f59

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark

#14 lore raw

RE: (subset) [PATCH 00/10] soundwire/ASoC: add mockup codec support

Hi Vinod,

Do you have any comment on the SoundWire part?

Quoted 56 lines

-----Original Message-----
From: Mark Brown <[email protected]>
Sent: Thursday, July 15, 2021 3:36 AM
To: [email protected]; [email protected]; Bard Liao <yung- [email protected]>
Cc: Mark Brown <[email protected]>; [email protected]; pierre- [email protected]; [email protected]; Liao, Bard <[email protected]>; [email protected]; [email protected]; [email protected]; Kale, Sanyog R <[email protected]>
Subject: Re: (subset) [PATCH 00/10] soundwire/ASoC: add mockup codec support

Quoted 5 lines · Bard Liao

Adding mockup SoundWire codec is useful to debug driver/topology changes without having any actual device connected.

Bard Liao (2):
soundwire: stream: don't abort bank switch on Command_Ignored/-

ENODATA

Quoted 3 lines

soundwire: stream: don't program mockup device ports

[...]

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next

Thanks!

[01/10] ASoC: codecs: add SoundWire mockup device support

        commit: 81d3d3d0bf09e606dbc1e3daad1c7cef3976fca2
[02/10] ASoC: soc-acpi: cnl: add table for SoundWire mockup devices
        commit: 2694cda7a4393fbd436e28474832a053e70e0733
[03/10] ASoC: soc-acpi: tgl: add table for SoundWire mockup devices
        commit: 3025d398c436d313f9b6b5c1f53918efeafcf5dc
[04/10] ASoC: Intel: boards: sof_sdw: add SoundWire mockup codecs for tests
        commit: 0ccac3bcf3564cbcba483dec20c7550939873f59

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark

maintainer
#15 lore raw
In reply to Bard Liao
Quoted 2 lines · Bard Liao

Adding mockup SoundWire codec is useful to debug driver/topology changes without having any actual device connected.

Applied sdw patches to sdw-next, thanks

Signature · 1 line
~Vinod