public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 0/4] Add static channel mapping between soundwire master and slave
@ 2024-09-09 10:55 Mohammad Rafi Shaik
  2024-09-09 10:55 ` [PATCH v1 1/4] ASoC: dt-bindings: wcd938x-sdw: Add static channel mapping support Mohammad Rafi Shaik
                   ` (5 more replies)
  0 siblings, 6 replies; 11+ messages in thread
From: Mohammad Rafi Shaik @ 2024-09-09 10:55 UTC (permalink / raw)
  To: Srinivas Kandagatla, Liam Girdwood, Mark Brown, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Vinod Koul, Bard Liao,
	Jaroslav Kysela, Takashi Iwai
  Cc: Pierre-Louis Bossart, Sanyog Kale, linux-arm-msm, alsa-devel,
	linux-sound, devicetree, linux-kernel, quic_rohkumar, kernel,
	quic_pkumpatl, Mohammad Rafi Shaik

Add static channel map support between soundwire master and slave.
This patch series will resolve channel mask mismatch between master and slave.

Scenario: wcd937x AMIC2 usecase

                          Master                 Slave (wcd937x)
                     +--------------+           +--------------+
                     |  +--------+  |           |  +--------+  |
         AMIC1 ----->|  | PORT1  |  |           |  |   TX1  |  |<-----------AMIC1
         AMIC2 ----->|  |        |  |           |  |        |  |
                     |  +--------+  |           |  +--------+  |
                     |              |           |              |
         AMIC3 ----->|  +--------+  |           |  +--------+  |
                     |  |  PORT2 |  |           |  |   TX2  |  |<-----------AMIC2
                     |  |        |  |           |  |        |  |<-----------AMIC3
                     |  +--------+  |           |  +--------+  |
                     |              |           |              |
                     |  +--------+  |           |  +--------+  |
 DMIC0...DMIC3------>|  |  PORT3 |  |           |  |   TX3  |  |<-----------DMIC0...DMIC3
                     |  |        |  |           |  |        |  |<-----------MBHC
                     |  +--------+  |           |  +--------+  |
                     |              |           |              |
                     |  +--------+  |           |  +--------+  |
 DMIC4...DMIC37----->|  |  PORT4 |  |           |  |   TX4  |  |<-----------DMIC4...DMIC7
                     |  |        |  |           |  |        |  |
                     |  +--------+  |           |  +--------+  |
                     |              |           |              |
                     +------------- +           +--------------+

For AMIC2 usecase, The Slave need to configure TX2 Port with channel mask 1 and
for Master required PORT1 with channel mask 2,

In existing design master and slave configured with same channel mask, it will fail
AMIC2 usecase.

The New design will help to configure channel mapping between master and slave from
device tree.

Mohammad Rafi Shaik (4):
  ASoC: dt-bindings: wcd938x-sdw: Add static channel mapping support
  soundwire: stream: Add set_master_channel_map() to set static channel
    mapping
  soundwire: qcom: Add static channel mapping support in soundwire
    master
  ASoC: codecs: wcd937x: Add static channel mapping support in
    wcd937x-sdw

 .../bindings/sound/qcom,wcd937x-sdw.yaml      | 28 ++++++++++
 drivers/soundwire/qcom.c                      | 18 +++++++
 drivers/soundwire/stream.c                    | 16 ++++++
 include/linux/soundwire/sdw.h                 |  5 ++
 sound/soc/codecs/wcd937x-sdw.c                | 52 ++++++++++++++++---
 sound/soc/codecs/wcd937x.c                    | 12 ++++-
 sound/soc/codecs/wcd937x.h                    |  6 ++-
 7 files changed, 126 insertions(+), 11 deletions(-)


base-commit: 9aaeb87ce1e966169a57f53a02ba05b30880ffb8
-- 
2.25.1


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH v1 1/4] ASoC: dt-bindings: wcd938x-sdw: Add static channel mapping support
  2024-09-09 10:55 [PATCH v1 0/4] Add static channel mapping between soundwire master and slave Mohammad Rafi Shaik
@ 2024-09-09 10:55 ` Mohammad Rafi Shaik
  2024-09-10  7:45   ` Krzysztof Kozlowski
  2024-09-11 11:33   ` Dmitry Baryshkov
  2024-09-09 10:55 ` [PATCH v1 2/4] soundwire: stream: Add set_master_channel_map() to set static channel mapping Mohammad Rafi Shaik
                   ` (4 subsequent siblings)
  5 siblings, 2 replies; 11+ messages in thread
From: Mohammad Rafi Shaik @ 2024-09-09 10:55 UTC (permalink / raw)
  To: Srinivas Kandagatla, Liam Girdwood, Mark Brown, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Vinod Koul, Bard Liao,
	Jaroslav Kysela, Takashi Iwai
  Cc: Pierre-Louis Bossart, Sanyog Kale, linux-arm-msm, alsa-devel,
	linux-sound, devicetree, linux-kernel, quic_rohkumar, kernel,
	quic_pkumpatl, Mohammad Rafi Shaik

Add static channel mapping between master and slave rx/tx ports.

Signed-off-by: Mohammad Rafi Shaik <quic_mohs@quicinc.com>
---
 .../bindings/sound/qcom,wcd937x-sdw.yaml      | 28 +++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/Documentation/devicetree/bindings/sound/qcom,wcd937x-sdw.yaml b/Documentation/devicetree/bindings/sound/qcom,wcd937x-sdw.yaml
index d3cf8f59cb23..1db3c001ce98 100644
--- a/Documentation/devicetree/bindings/sound/qcom,wcd937x-sdw.yaml
+++ b/Documentation/devicetree/bindings/sound/qcom,wcd937x-sdw.yaml
@@ -58,6 +58,30 @@ properties:
     items:
       enum: [1, 2, 3, 4, 5]
 
+  qcom,tx-channel-mapping:
+    description: |
+      Specifies static channel mapping between slave and master tx port
+      channels.
+      In the order of slave port channels which is adc1, adc2, adc3, adc4,
+      dmic0, dmic1, mbhc, dmic2, dmic3, dmci4, dmic5, dmic6, dmic7.
+    $ref: /schemas/types.yaml#/definitions/uint8-array
+    minItems: 8
+    maxItems: 13
+    items:
+      enum: [1, 2, 4, 8]
+
+  qcom,rx-channel-mapping:
+    description: |
+      Specifies static channels mapping between slave and master rx port
+      channels.
+      In the order of slave port channels, which is
+      hph_l, hph_r, clsh, comp_l, comp_r, lo, dsd_r, dsd_l.
+    $ref: /schemas/types.yaml#/definitions/uint8-array
+    minItems: 8
+    maxItems: 8
+    items:
+      enum: [1, 2, 4, 8]
+
 required:
   - compatible
   - reg
@@ -74,6 +98,8 @@ examples:
             compatible = "sdw20217010a00";
             reg = <0 4>;
             qcom,rx-port-mapping = <1 2 3 4 5>;
+            qcom,rx-channel-mapping =  /bits/ 8 <0x01 0x02 0x01 0x01 0x02
+                                                 0x01 0x01 0x02>;
         };
     };
 
@@ -85,6 +111,8 @@ examples:
             compatible = "sdw20217010a00";
             reg = <0 3>;
             qcom,tx-port-mapping = <2 2 3 4>;
+            qcom,tx-channel-mapping = /bits/ 8 <0x01 0x02 0x01 0x01 0x02 0x04
+                                                0x04 0x08 0x01 0x02 0x04 0x8>;
         };
     };
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v1 2/4] soundwire: stream: Add set_master_channel_map() to set static channel mapping
  2024-09-09 10:55 [PATCH v1 0/4] Add static channel mapping between soundwire master and slave Mohammad Rafi Shaik
  2024-09-09 10:55 ` [PATCH v1 1/4] ASoC: dt-bindings: wcd938x-sdw: Add static channel mapping support Mohammad Rafi Shaik
@ 2024-09-09 10:55 ` Mohammad Rafi Shaik
  2024-09-09 14:50   ` Charles Keepax
  2024-09-09 10:55 ` [PATCH v1 3/4] soundwire: qcom: Add static channel mapping support in soundwire master Mohammad Rafi Shaik
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 11+ messages in thread
From: Mohammad Rafi Shaik @ 2024-09-09 10:55 UTC (permalink / raw)
  To: Srinivas Kandagatla, Liam Girdwood, Mark Brown, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Vinod Koul, Bard Liao,
	Jaroslav Kysela, Takashi Iwai
  Cc: Pierre-Louis Bossart, Sanyog Kale, linux-arm-msm, alsa-devel,
	linux-sound, devicetree, linux-kernel, quic_rohkumar, kernel,
	quic_pkumpatl, Mohammad Rafi Shaik

Add set_master_channel_map() to set the static channel map between
master and slave. Patch change will resolve the channel mask mismatch
between the master and slave.

The sdw_set_channel_map_stream() will triggered by a slave with active
port number and channel mask.

Signed-off-by: Mohammad Rafi Shaik <quic_mohs@quicinc.com>
---
 drivers/soundwire/stream.c    | 16 ++++++++++++++++
 include/linux/soundwire/sdw.h |  5 +++++
 2 files changed, 21 insertions(+)

diff --git a/drivers/soundwire/stream.c b/drivers/soundwire/stream.c
index f275143d7b18..8cfea2ccb5bd 100644
--- a/drivers/soundwire/stream.c
+++ b/drivers/soundwire/stream.c
@@ -1972,6 +1972,22 @@ int sdw_stream_remove_master(struct sdw_bus *bus,
 }
 EXPORT_SYMBOL(sdw_stream_remove_master);
 
+int sdw_set_channel_map_stream(struct sdw_stream_runtime *stream,
+			       int *ch_mask, unsigned int active_port_num)
+{
+	struct sdw_master_runtime *m_rt;
+	struct sdw_bus *bus;
+
+	list_for_each_entry(m_rt, &stream->master_list, stream_node) {
+		bus = m_rt->bus;
+		if (bus->ops->set_master_channel_map)
+			bus->ops->set_master_channel_map(bus, ch_mask, active_port_num);
+	}
+
+	return 0;
+}
+EXPORT_SYMBOL(sdw_set_channel_map_stream);
+
 /**
  * sdw_stream_add_slave() - Allocate and add master/slave runtime to a stream
  *
diff --git a/include/linux/soundwire/sdw.h b/include/linux/soundwire/sdw.h
index 5e0dd47a0412..264450763bab 100644
--- a/include/linux/soundwire/sdw.h
+++ b/include/linux/soundwire/sdw.h
@@ -857,6 +857,8 @@ struct sdw_master_ops {
 			(struct sdw_bus *bus);
 	int (*set_bus_conf)(struct sdw_bus *bus,
 			struct sdw_bus_params *params);
+	int (*set_master_channel_map)(struct sdw_bus *bus, int *ch_mask,
+				      unsigned int port_num);
 	int (*pre_bank_switch)(struct sdw_bus *bus);
 	int (*post_bank_switch)(struct sdw_bus *bus);
 	u32 (*read_ping_status)(struct sdw_bus *bus);
@@ -1049,6 +1051,9 @@ int sdw_bus_exit_clk_stop(struct sdw_bus *bus);
 int sdw_compare_devid(struct sdw_slave *slave, struct sdw_slave_id id);
 void sdw_extract_slave_id(struct sdw_bus *bus, u64 addr, struct sdw_slave_id *id);
 
+int sdw_set_channel_map_stream(struct sdw_stream_runtime *stream,
+			       int *ch_mask, unsigned int active_port_num);
+
 #if IS_ENABLED(CONFIG_SOUNDWIRE)
 
 int sdw_stream_add_slave(struct sdw_slave *slave,
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v1 3/4] soundwire: qcom: Add static channel mapping support in soundwire master
  2024-09-09 10:55 [PATCH v1 0/4] Add static channel mapping between soundwire master and slave Mohammad Rafi Shaik
  2024-09-09 10:55 ` [PATCH v1 1/4] ASoC: dt-bindings: wcd938x-sdw: Add static channel mapping support Mohammad Rafi Shaik
  2024-09-09 10:55 ` [PATCH v1 2/4] soundwire: stream: Add set_master_channel_map() to set static channel mapping Mohammad Rafi Shaik
@ 2024-09-09 10:55 ` Mohammad Rafi Shaik
  2024-09-09 10:55 ` [PATCH v1 4/4] ASoC: codecs: wcd937x: Add static channel mapping support in wcd937x-sdw Mohammad Rafi Shaik
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 11+ messages in thread
From: Mohammad Rafi Shaik @ 2024-09-09 10:55 UTC (permalink / raw)
  To: Srinivas Kandagatla, Liam Girdwood, Mark Brown, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Vinod Koul, Bard Liao,
	Jaroslav Kysela, Takashi Iwai
  Cc: Pierre-Louis Bossart, Sanyog Kale, linux-arm-msm, alsa-devel,
	linux-sound, devicetree, linux-kernel, quic_rohkumar, kernel,
	quic_pkumpatl, Mohammad Rafi Shaik

Add static channel mapping support in soundwire master.
The qcom_swrm_set_channel_map() will update the master channel mask
based on master port number.

Signed-off-by: Mohammad Rafi Shaik <quic_mohs@quicinc.com>
---
 drivers/soundwire/qcom.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/drivers/soundwire/qcom.c b/drivers/soundwire/qcom.c
index aed57002fd0e..65ed1ff7888f 100644
--- a/drivers/soundwire/qcom.c
+++ b/drivers/soundwire/qcom.c
@@ -156,6 +156,7 @@ struct qcom_swrm_port_config {
 	u8 word_length;
 	u8 blk_group_count;
 	u8 lane_control;
+	u8 ch_mask;
 };
 
 /*
@@ -1048,8 +1049,14 @@ static int qcom_swrm_port_enable(struct sdw_bus *bus,
 {
 	u32 reg = SWRM_DP_PORT_CTRL_BANK(enable_ch->port_num, bank);
 	struct qcom_swrm_ctrl *ctrl = to_qcom_sdw(bus);
+	struct qcom_swrm_port_config *pcfg;
 	u32 val;
 
+	pcfg = &ctrl->pconfig[enable_ch->port_num];
+
+	if (pcfg->ch_mask != SWR_INVALID_PARAM && pcfg->ch_mask != 0)
+		enable_ch->ch_mask = pcfg->ch_mask;
+
 	ctrl->reg_read(ctrl, reg, &val);
 
 	if (enable_ch->enable)
@@ -1060,6 +1067,16 @@ static int qcom_swrm_port_enable(struct sdw_bus *bus,
 	return ctrl->reg_write(ctrl, reg, val);
 }
 
+static int qcom_swrm_set_channel_map(struct sdw_bus *bus, int *ch_mask, unsigned int port_num)
+{
+	struct qcom_swrm_ctrl *ctrl = to_qcom_sdw(bus);
+
+	if (ch_mask && port_num)
+		ctrl->pconfig[port_num].ch_mask = ch_mask[port_num];
+
+	return 0;
+}
+
 static const struct sdw_master_port_ops qcom_swrm_port_ops = {
 	.dpn_set_port_params = qcom_swrm_port_params,
 	.dpn_set_port_transport_params = qcom_swrm_transport_params,
@@ -1070,6 +1087,7 @@ static const struct sdw_master_ops qcom_swrm_ops = {
 	.read_prop = qcom_swrm_read_prop,
 	.xfer_msg = qcom_swrm_xfer_msg,
 	.pre_bank_switch = qcom_swrm_pre_bank_switch,
+	.set_master_channel_map = qcom_swrm_set_channel_map,
 };
 
 static int qcom_swrm_compute_params(struct sdw_bus *bus)
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v1 4/4] ASoC: codecs: wcd937x: Add static channel mapping support in wcd937x-sdw
  2024-09-09 10:55 [PATCH v1 0/4] Add static channel mapping between soundwire master and slave Mohammad Rafi Shaik
                   ` (2 preceding siblings ...)
  2024-09-09 10:55 ` [PATCH v1 3/4] soundwire: qcom: Add static channel mapping support in soundwire master Mohammad Rafi Shaik
@ 2024-09-09 10:55 ` Mohammad Rafi Shaik
  2024-09-09 14:49 ` [PATCH v1 0/4] Add static channel mapping between soundwire master and slave Charles Keepax
  2024-09-09 16:03 ` Pierre-Louis Bossart
  5 siblings, 0 replies; 11+ messages in thread
From: Mohammad Rafi Shaik @ 2024-09-09 10:55 UTC (permalink / raw)
  To: Srinivas Kandagatla, Liam Girdwood, Mark Brown, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Vinod Koul, Bard Liao,
	Jaroslav Kysela, Takashi Iwai
  Cc: Pierre-Louis Bossart, Sanyog Kale, linux-arm-msm, alsa-devel,
	linux-sound, devicetree, linux-kernel, quic_rohkumar, kernel,
	quic_pkumpatl, Mohammad Rafi Shaik

Add static channel mapping between master and slave ports in
wcd937x-sdw. This patch will resolve the channel mask mismatch
between master and slave.

Signed-off-by: Mohammad Rafi Shaik <quic_mohs@quicinc.com>
---
 sound/soc/codecs/wcd937x-sdw.c | 52 ++++++++++++++++++++++++++++------
 sound/soc/codecs/wcd937x.c     | 12 ++++++--
 sound/soc/codecs/wcd937x.h     |  6 +++-
 3 files changed, 59 insertions(+), 11 deletions(-)

diff --git a/sound/soc/codecs/wcd937x-sdw.c b/sound/soc/codecs/wcd937x-sdw.c
index 0c33f7f3dc25..f59068ddc26f 100644
--- a/sound/soc/codecs/wcd937x-sdw.c
+++ b/sound/soc/codecs/wcd937x-sdw.c
@@ -19,7 +19,7 @@
 #include <sound/soc.h>
 #include "wcd937x.h"
 
-static const struct wcd937x_sdw_ch_info wcd937x_sdw_rx_ch_info[] = {
+static struct wcd937x_sdw_ch_info wcd937x_sdw_rx_ch_info[] = {
 	WCD_SDW_CH(WCD937X_HPH_L, WCD937X_HPH_PORT, BIT(0)),
 	WCD_SDW_CH(WCD937X_HPH_R, WCD937X_HPH_PORT, BIT(1)),
 	WCD_SDW_CH(WCD937X_CLSH, WCD937X_CLSH_PORT, BIT(0)),
@@ -30,7 +30,7 @@ static const struct wcd937x_sdw_ch_info wcd937x_sdw_rx_ch_info[] = {
 	WCD_SDW_CH(WCD937X_DSD_R, WCD937X_DSD_PORT, BIT(1)),
 };
 
-static const struct wcd937x_sdw_ch_info wcd937x_sdw_tx_ch_info[] = {
+static struct wcd937x_sdw_ch_info wcd937x_sdw_tx_ch_info[] = {
 	WCD_SDW_CH(WCD937X_ADC1, WCD937X_ADC_1_PORT, BIT(0)),
 	WCD_SDW_CH(WCD937X_ADC2, WCD937X_ADC_2_3_PORT, BIT(0)),
 	WCD_SDW_CH(WCD937X_ADC3, WCD937X_ADC_2_3_PORT, BIT(0)),
@@ -91,7 +91,7 @@ int wcd937x_sdw_hw_params(struct wcd937x_sdw_priv *wcd,
 {
 	struct sdw_port_config port_config[WCD937X_MAX_SWR_PORTS];
 	unsigned long ch_mask;
-	int i, j;
+	int i, j, ret = 0;
 
 	wcd->sconfig.ch_count = 1;
 	wcd->active_ports = 0;
@@ -112,9 +112,15 @@ int wcd937x_sdw_hw_params(struct wcd937x_sdw_priv *wcd,
 	wcd->sconfig.direction = wcd->is_tx ? SDW_DATA_DIR_TX : SDW_DATA_DIR_RX;
 	wcd->sconfig.type = SDW_STREAM_PCM;
 
-	return sdw_stream_add_slave(wcd->sdev, &wcd->sconfig,
-				    &port_config[0], wcd->active_ports,
-				    wcd->sruntime);
+	ret = sdw_stream_add_slave(wcd->sdev, &wcd->sconfig,
+				   &port_config[0], wcd->active_ports,
+				   wcd->sruntime);
+	if (!ret)
+		sdw_set_channel_map_stream(wcd->sruntime,
+					   wcd->master_channel_map,
+					   wcd->active_ports);
+
+	return ret;
 }
 EXPORT_SYMBOL_GPL(wcd937x_sdw_hw_params);
 
@@ -1019,7 +1025,9 @@ static int wcd9370_probe(struct sdw_slave *pdev,
 {
 	struct device *dev = &pdev->dev;
 	struct wcd937x_sdw_priv *wcd;
-	int ret;
+	u8 master_ch_mask[WCD937X_MAX_SWR_CH_IDS];
+	int master_ch_mask_size = 0;
+	int ret, i;
 
 	wcd = devm_kzalloc(dev, sizeof(*wcd), GFP_KERNEL);
 	if (!wcd)
@@ -1048,10 +1056,36 @@ static int wcd9370_probe(struct sdw_slave *pdev,
 				   SDW_SCP_INT1_PARITY;
 	pdev->prop.lane_control_support = true;
 	pdev->prop.simple_clk_stop_capable = true;
+
+	memset(master_ch_mask, 0, WCD937X_MAX_SWR_CH_IDS);
+
 	if (wcd->is_tx) {
-		pdev->prop.source_ports = GENMASK(WCD937X_MAX_TX_SWR_PORTS - 1, 0);
+		master_ch_mask_size = of_property_count_u8_elems(dev->of_node,
+								 "qcom,tx-channel-mapping");
+
+		if (master_ch_mask_size)
+			ret = of_property_read_u8_array(dev->of_node, "qcom,tx-channel-mapping",
+							master_ch_mask, master_ch_mask_size);
+	} else {
+		master_ch_mask_size = of_property_count_u8_elems(dev->of_node,
+								 "qcom,rx-channel-mapping");
+
+		if (master_ch_mask_size)
+			ret = of_property_read_u8_array(dev->of_node, "qcom,rx-channel-mapping",
+							master_ch_mask, master_ch_mask_size);
+	}
+
+	if (ret < 0)
+		dev_info(dev, "Static channel mapping not specified using device channel maps\n");
+
+	if (wcd->is_tx) {
+		pdev->prop.source_ports = GENMASK(WCD937X_MAX_TX_SWR_PORTS, 0);
 		pdev->prop.src_dpn_prop = wcd937x_dpn_prop;
 		wcd->ch_info = &wcd937x_sdw_tx_ch_info[0];
+
+		for (i = 0; i < master_ch_mask_size; i++)
+			wcd->ch_info[i].master_ch_mask = master_ch_mask[i];
+
 		pdev->prop.wake_capable = true;
 
 		wcd->regmap = devm_regmap_init_sdw(pdev, &wcd937x_regmap_config);
@@ -1065,6 +1099,8 @@ static int wcd9370_probe(struct sdw_slave *pdev,
 		pdev->prop.sink_ports = GENMASK(WCD937X_MAX_SWR_PORTS - 1, 0);
 		pdev->prop.sink_dpn_prop = wcd937x_dpn_prop;
 		wcd->ch_info = &wcd937x_sdw_rx_ch_info[0];
+		for (i = 0; i < master_ch_mask_size; i++)
+			wcd->ch_info[i].master_ch_mask = master_ch_mask[i];
 	}
 
 
diff --git a/sound/soc/codecs/wcd937x.c b/sound/soc/codecs/wcd937x.c
index af296b77a723..404effb8c31f 100644
--- a/sound/soc/codecs/wcd937x.c
+++ b/sound/soc/codecs/wcd937x.c
@@ -1192,13 +1192,21 @@ static int wcd937x_connect_port(struct wcd937x_sdw_priv *wcd, u8 port_idx, u8 ch
 	const struct wcd937x_sdw_ch_info *ch_info = &wcd->ch_info[ch_id];
 	u8 port_num = ch_info->port_num;
 	u8 ch_mask = ch_info->ch_mask;
+	u8 mstr_port_num, mstr_ch_mask;
+	struct sdw_slave *sdev = wcd->sdev;
 
 	port_config->num = port_num;
 
-	if (enable)
+	mstr_port_num = sdev->m_port_map[port_num];
+	mstr_ch_mask = ch_info->master_ch_mask;
+
+	if (enable) {
 		port_config->ch_mask |= ch_mask;
-	else
+		wcd->master_channel_map[mstr_port_num] |= mstr_ch_mask;
+	} else {
 		port_config->ch_mask &= ~ch_mask;
+		wcd->master_channel_map[mstr_port_num] &= ~mstr_ch_mask;
+	}
 
 	return 0;
 }
diff --git a/sound/soc/codecs/wcd937x.h b/sound/soc/codecs/wcd937x.h
index 35f3d48bd7dd..850aa943b7ab 100644
--- a/sound/soc/codecs/wcd937x.h
+++ b/sound/soc/codecs/wcd937x.h
@@ -506,12 +506,14 @@ enum wcd937x_rx_sdw_ports {
 struct wcd937x_sdw_ch_info {
 	int port_num;
 	unsigned int ch_mask;
+	unsigned int master_ch_mask;
 };
 
 #define WCD_SDW_CH(id, pn, cmask)	\
 	[id] = {			\
 		.port_num = pn,		\
 		.ch_mask = cmask,	\
+		.master_ch_mask = cmask,	\
 	}
 
 struct wcd937x_priv;
@@ -520,9 +522,11 @@ struct wcd937x_sdw_priv {
 	struct sdw_stream_config sconfig;
 	struct sdw_stream_runtime *sruntime;
 	struct sdw_port_config port_config[WCD937X_MAX_SWR_PORTS];
-	const struct wcd937x_sdw_ch_info *ch_info;
+	struct wcd937x_sdw_ch_info *ch_info;
 	bool port_enable[WCD937X_MAX_SWR_CH_IDS];
+	unsigned int master_channel_map[SDW_MAX_PORTS];
 	int active_ports;
+	int num_ports;
 	bool is_tx;
 	struct wcd937x_priv *wcd937x;
 	struct irq_domain *slave_irq;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH v1 0/4] Add static channel mapping between soundwire master and slave
  2024-09-09 10:55 [PATCH v1 0/4] Add static channel mapping between soundwire master and slave Mohammad Rafi Shaik
                   ` (3 preceding siblings ...)
  2024-09-09 10:55 ` [PATCH v1 4/4] ASoC: codecs: wcd937x: Add static channel mapping support in wcd937x-sdw Mohammad Rafi Shaik
@ 2024-09-09 14:49 ` Charles Keepax
  2024-09-09 15:10   ` Mark Brown
  2024-09-09 16:03 ` Pierre-Louis Bossart
  5 siblings, 1 reply; 11+ messages in thread
From: Charles Keepax @ 2024-09-09 14:49 UTC (permalink / raw)
  To: Mohammad Rafi Shaik
  Cc: Srinivas Kandagatla, Liam Girdwood, Mark Brown, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Vinod Koul, Bard Liao,
	Jaroslav Kysela, Takashi Iwai, Pierre-Louis Bossart, Sanyog Kale,
	linux-arm-msm, alsa-devel, linux-sound, devicetree, linux-kernel,
	quic_rohkumar, kernel, quic_pkumpatl

On Mon, Sep 09, 2024 at 04:25:43PM +0530, Mohammad Rafi Shaik wrote:
> Add static channel map support between soundwire master and slave.
> This patch series will resolve channel mask mismatch between master and slave.
> 
> Scenario: wcd937x AMIC2 usecase
> 
>                           Master                 Slave (wcd937x)
>                      +--------------+           +--------------+
>                      |  +--------+  |           |  +--------+  |
>          AMIC1 ----->|  | PORT1  |  |           |  |   TX1  |  |<-----------AMIC1
>          AMIC2 ----->|  |        |  |           |  |        |  |
>                      |  +--------+  |           |  +--------+  |
>                      |              |           |              |
>          AMIC3 ----->|  +--------+  |           |  +--------+  |
>                      |  |  PORT2 |  |           |  |   TX2  |  |<-----------AMIC2
>                      |  |        |  |           |  |        |  |<-----------AMIC3
>                      |  +--------+  |           |  +--------+  |
>                      |              |           |              |
>                      |  +--------+  |           |  +--------+  |
>  DMIC0...DMIC3------>|  |  PORT3 |  |           |  |   TX3  |  |<-----------DMIC0...DMIC3
>                      |  |        |  |           |  |        |  |<-----------MBHC
>                      |  +--------+  |           |  +--------+  |
>                      |              |           |              |
>                      |  +--------+  |           |  +--------+  |
>  DMIC4...DMIC37----->|  |  PORT4 |  |           |  |   TX4  |  |<-----------DMIC4...DMIC7
>                      |  |        |  |           |  |        |  |
>                      |  +--------+  |           |  +--------+  |
>                      |              |           |              |
>                      +------------- +           +--------------+
> 
> For AMIC2 usecase, The Slave need to configure TX2 Port with channel mask 1 and
> for Master required PORT1 with channel mask 2,
> 
> In existing design master and slave configured with same channel mask, it will fail
> AMIC2 usecase.

Apologies but I am not really following what exactly the issue is
here? How do these ports map to DAI links? It looks like you are
attempting to have AMIC2 produced by one DAI link, but consumed
by another?

Thanks,
Charles

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v1 2/4] soundwire: stream: Add set_master_channel_map() to set static channel mapping
  2024-09-09 10:55 ` [PATCH v1 2/4] soundwire: stream: Add set_master_channel_map() to set static channel mapping Mohammad Rafi Shaik
@ 2024-09-09 14:50   ` Charles Keepax
  0 siblings, 0 replies; 11+ messages in thread
From: Charles Keepax @ 2024-09-09 14:50 UTC (permalink / raw)
  To: Mohammad Rafi Shaik
  Cc: Srinivas Kandagatla, Liam Girdwood, Mark Brown, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Vinod Koul, Bard Liao,
	Jaroslav Kysela, Takashi Iwai, Pierre-Louis Bossart, Sanyog Kale,
	linux-arm-msm, alsa-devel, linux-sound, devicetree, linux-kernel,
	quic_rohkumar, kernel, quic_pkumpatl

On Mon, Sep 09, 2024 at 04:25:45PM +0530, Mohammad Rafi Shaik wrote:
> diff --git a/include/linux/soundwire/sdw.h b/include/linux/soundwire/sdw.h
> index 5e0dd47a0412..264450763bab 100644
> --- a/include/linux/soundwire/sdw.h
> +++ b/include/linux/soundwire/sdw.h
> @@ -857,6 +857,8 @@ struct sdw_master_ops {
>  			(struct sdw_bus *bus);
>  	int (*set_bus_conf)(struct sdw_bus *bus,
>  			struct sdw_bus_params *params);
> +	int (*set_master_channel_map)(struct sdw_bus *bus, int *ch_mask,
> +				      unsigned int port_num);

At the very least this needs some kernel doc to explain what the
new callback is for, I think also the commit message could use
some work to help us understand the purpose here.

Thanks,
Charles

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v1 0/4] Add static channel mapping between soundwire master and slave
  2024-09-09 14:49 ` [PATCH v1 0/4] Add static channel mapping between soundwire master and slave Charles Keepax
@ 2024-09-09 15:10   ` Mark Brown
  0 siblings, 0 replies; 11+ messages in thread
From: Mark Brown @ 2024-09-09 15:10 UTC (permalink / raw)
  To: Charles Keepax
  Cc: Mohammad Rafi Shaik, Srinivas Kandagatla, Liam Girdwood,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley, Vinod Koul,
	Bard Liao, Jaroslav Kysela, Takashi Iwai, Pierre-Louis Bossart,
	Sanyog Kale, linux-arm-msm, alsa-devel, linux-sound, devicetree,
	linux-kernel, quic_rohkumar, kernel, quic_pkumpatl

[-- Attachment #1: Type: text/plain, Size: 844 bytes --]

On Mon, Sep 09, 2024 at 03:49:47PM +0100, Charles Keepax wrote:
> On Mon, Sep 09, 2024 at 04:25:43PM +0530, Mohammad Rafi Shaik wrote:

> > Add static channel map support between soundwire master and slave.
> > This patch series will resolve channel mask mismatch between master and slave.

...

> > For AMIC2 usecase, The Slave need to configure TX2 Port with channel mask 1 and
> > for Master required PORT1 with channel mask 2,
> > 
> > In existing design master and slave configured with same channel mask, it will fail
> > AMIC2 usecase.

> Apologies but I am not really following what exactly the issue is
> here? How do these ports map to DAI links? It looks like you are
> attempting to have AMIC2 produced by one DAI link, but consumed
> by another?

Yes, and it's also not clear to me why this is device specific.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v1 0/4] Add static channel mapping between soundwire master and slave
  2024-09-09 10:55 [PATCH v1 0/4] Add static channel mapping between soundwire master and slave Mohammad Rafi Shaik
                   ` (4 preceding siblings ...)
  2024-09-09 14:49 ` [PATCH v1 0/4] Add static channel mapping between soundwire master and slave Charles Keepax
@ 2024-09-09 16:03 ` Pierre-Louis Bossart
  5 siblings, 0 replies; 11+ messages in thread
From: Pierre-Louis Bossart @ 2024-09-09 16:03 UTC (permalink / raw)
  To: Mohammad Rafi Shaik, Srinivas Kandagatla, Liam Girdwood,
	Mark Brown, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Vinod Koul, Bard Liao, Jaroslav Kysela, Takashi Iwai
  Cc: Sanyog Kale, linux-arm-msm, alsa-devel, linux-sound, devicetree,
	linux-kernel, quic_rohkumar, kernel, quic_pkumpatl



On 9/9/24 12:55, Mohammad Rafi Shaik wrote:
> Add static channel map support between soundwire master and slave.
> This patch series will resolve channel mask mismatch between master and slave.
> 
> Scenario: wcd937x AMIC2 usecase
> 
>                           Master                 Slave (wcd937x)
>                      +--------------+           +--------------+
>                      |  +--------+  |           |  +--------+  |
>          AMIC1 ----->|  | PORT1  |  |           |  |   TX1  |  |<-----------AMIC1
>          AMIC2 ----->|  |        |  |           |  |        |  |
>                      |  +--------+  |           |  +--------+  |
>                      |              |           |              |
>          AMIC3 ----->|  +--------+  |           |  +--------+  |
>                      |  |  PORT2 |  |           |  |   TX2  |  |<-----------AMIC2
>                      |  |        |  |           |  |        |  |<-----------AMIC3
>                      |  +--------+  |           |  +--------+  |
>                      |              |           |              |
>                      |  +--------+  |           |  +--------+  |
>  DMIC0...DMIC3------>|  |  PORT3 |  |           |  |   TX3  |  |<-----------DMIC0...DMIC3
>                      |  |        |  |           |  |        |  |<-----------MBHC
>                      |  +--------+  |           |  +--------+  |
>                      |              |           |              |
>                      |  +--------+  |           |  +--------+  |
>  DMIC4...DMIC37----->|  |  PORT4 |  |           |  |   TX4  |  |<-----------DMIC4...DMIC7
>                      |  |        |  |           |  |        |  |
>                      |  +--------+  |           |  +--------+  |
>                      |              |           |              |
>                      +------------- +           +--------------+
> 
> For AMIC2 usecase, The Slave need to configure TX2 Port with channel mask 1 and
> for Master required PORT1 with channel mask 2,
> 
> In existing design master and slave configured with same channel mask, it will fail
> AMIC2 usecase.
> 
> The New design will help to configure channel mapping between master and slave from
> device tree.

That's rather controversial...

In theory you already have the means to deal with a different channel
mapping in the hw_params callback for your manager and peripheral
devices. That's how we e.g. send a 2ch stream on the manager to two
separate amplifiers and program which channel is used by what amplifier.

The common part between manager and peripheral is the notion of
'stream', and you can add a different port/stream configuration for
manager and peripheral with sdw_stream_add_master() and
sdw_stream_add_slave() respectively.

Port1 and TX2 can be used by just setting the relevant port_config.num
value.

Likewise the port_config.ch_mask can be programmed at will to select the
relevant mappings. See e.g. rt1308_sdw_hw_params() in rt1308-sdw.c, the
mapping were handled with a set_tdm_slot() callback before.

In short, please re-visit your hw_params() implementation first and use
the existing 'stream' APIs.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v1 1/4] ASoC: dt-bindings: wcd938x-sdw: Add static channel mapping support
  2024-09-09 10:55 ` [PATCH v1 1/4] ASoC: dt-bindings: wcd938x-sdw: Add static channel mapping support Mohammad Rafi Shaik
@ 2024-09-10  7:45   ` Krzysztof Kozlowski
  2024-09-11 11:33   ` Dmitry Baryshkov
  1 sibling, 0 replies; 11+ messages in thread
From: Krzysztof Kozlowski @ 2024-09-10  7:45 UTC (permalink / raw)
  To: Mohammad Rafi Shaik
  Cc: Srinivas Kandagatla, Liam Girdwood, Mark Brown, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Vinod Koul, Bard Liao,
	Jaroslav Kysela, Takashi Iwai, Pierre-Louis Bossart, Sanyog Kale,
	linux-arm-msm, alsa-devel, linux-sound, devicetree, linux-kernel,
	quic_rohkumar, kernel, quic_pkumpatl

On Mon, Sep 09, 2024 at 04:25:44PM +0530, Mohammad Rafi Shaik wrote:
> Add static channel mapping between master and slave rx/tx ports.
> 

I see ongoing discussion, so if these property stay, grow the
description here to explain how this describes hardware or which part of
hardware you are covering.

> Signed-off-by: Mohammad Rafi Shaik <quic_mohs@quicinc.com>
> ---
>  .../bindings/sound/qcom,wcd937x-sdw.yaml      | 28 +++++++++++++++++++
>  1 file changed, 28 insertions(+)

Best regards,
Krzysztof


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v1 1/4] ASoC: dt-bindings: wcd938x-sdw: Add static channel mapping support
  2024-09-09 10:55 ` [PATCH v1 1/4] ASoC: dt-bindings: wcd938x-sdw: Add static channel mapping support Mohammad Rafi Shaik
  2024-09-10  7:45   ` Krzysztof Kozlowski
@ 2024-09-11 11:33   ` Dmitry Baryshkov
  1 sibling, 0 replies; 11+ messages in thread
From: Dmitry Baryshkov @ 2024-09-11 11:33 UTC (permalink / raw)
  To: Mohammad Rafi Shaik
  Cc: Srinivas Kandagatla, Liam Girdwood, Mark Brown, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Vinod Koul, Bard Liao,
	Jaroslav Kysela, Takashi Iwai, Pierre-Louis Bossart, Sanyog Kale,
	linux-arm-msm, alsa-devel, linux-sound, devicetree, linux-kernel,
	quic_rohkumar, kernel, quic_pkumpatl

On Mon, Sep 09, 2024 at 04:25:44PM GMT, Mohammad Rafi Shaik wrote:
> Add static channel mapping between master and slave rx/tx ports.
> 
> Signed-off-by: Mohammad Rafi Shaik <quic_mohs@quicinc.com>
> ---
>  .../bindings/sound/qcom,wcd937x-sdw.yaml      | 28 +++++++++++++++++++
>  1 file changed, 28 insertions(+)
> 
> diff --git a/Documentation/devicetree/bindings/sound/qcom,wcd937x-sdw.yaml b/Documentation/devicetree/bindings/sound/qcom,wcd937x-sdw.yaml
> index d3cf8f59cb23..1db3c001ce98 100644
> --- a/Documentation/devicetree/bindings/sound/qcom,wcd937x-sdw.yaml
> +++ b/Documentation/devicetree/bindings/sound/qcom,wcd937x-sdw.yaml
> @@ -58,6 +58,30 @@ properties:
>      items:
>        enum: [1, 2, 3, 4, 5]
>  
> +  qcom,tx-channel-mapping:
> +    description: |
> +      Specifies static channel mapping between slave and master tx port
> +      channels.
> +      In the order of slave port channels which is adc1, adc2, adc3, adc4,
> +      dmic0, dmic1, mbhc, dmic2, dmic3, dmci4, dmic5, dmic6, dmic7.
> +    $ref: /schemas/types.yaml#/definitions/uint8-array
> +    minItems: 8
> +    maxItems: 13
> +    items:
> +      enum: [1, 2, 4, 8]
> +
> +  qcom,rx-channel-mapping:
> +    description: |
> +      Specifies static channels mapping between slave and master rx port
> +      channels.
> +      In the order of slave port channels, which is
> +      hph_l, hph_r, clsh, comp_l, comp_r, lo, dsd_r, dsd_l.
> +    $ref: /schemas/types.yaml#/definitions/uint8-array
> +    minItems: 8
> +    maxItems: 8
> +    items:
> +      enum: [1, 2, 4, 8]

Can we please use sensible strings instead of a randomly-looking numbers?

> +
>  required:
>    - compatible
>    - reg
> @@ -74,6 +98,8 @@ examples:
>              compatible = "sdw20217010a00";
>              reg = <0 4>;
>              qcom,rx-port-mapping = <1 2 3 4 5>;
> +            qcom,rx-channel-mapping =  /bits/ 8 <0x01 0x02 0x01 0x01 0x02
> +                                                 0x01 0x01 0x02>;
>          };
>      };
>  
> @@ -85,6 +111,8 @@ examples:
>              compatible = "sdw20217010a00";
>              reg = <0 3>;
>              qcom,tx-port-mapping = <2 2 3 4>;
> +            qcom,tx-channel-mapping = /bits/ 8 <0x01 0x02 0x01 0x01 0x02 0x04
> +                                                0x04 0x08 0x01 0x02 0x04 0x8>;
>          };
>      };
>  
> -- 
> 2.25.1
> 

-- 
With best wishes
Dmitry

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2024-09-11 11:33 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-09 10:55 [PATCH v1 0/4] Add static channel mapping between soundwire master and slave Mohammad Rafi Shaik
2024-09-09 10:55 ` [PATCH v1 1/4] ASoC: dt-bindings: wcd938x-sdw: Add static channel mapping support Mohammad Rafi Shaik
2024-09-10  7:45   ` Krzysztof Kozlowski
2024-09-11 11:33   ` Dmitry Baryshkov
2024-09-09 10:55 ` [PATCH v1 2/4] soundwire: stream: Add set_master_channel_map() to set static channel mapping Mohammad Rafi Shaik
2024-09-09 14:50   ` Charles Keepax
2024-09-09 10:55 ` [PATCH v1 3/4] soundwire: qcom: Add static channel mapping support in soundwire master Mohammad Rafi Shaik
2024-09-09 10:55 ` [PATCH v1 4/4] ASoC: codecs: wcd937x: Add static channel mapping support in wcd937x-sdw Mohammad Rafi Shaik
2024-09-09 14:49 ` [PATCH v1 0/4] Add static channel mapping between soundwire master and slave Charles Keepax
2024-09-09 15:10   ` Mark Brown
2024-09-09 16:03 ` Pierre-Louis Bossart

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox