mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/4] ASoC: codecs: wcd937x/8x/9x: cleanup
@ 2025-06-27 15:50 srinivas.kandagatla
  2025-06-27 15:51 ` [PATCH 1/4] soundwire: bus: add of_sdw_find_device_by_node helper srinivas.kandagatla
                   ` (3 more replies)
  0 siblings, 4 replies; 12+ messages in thread
From: srinivas.kandagatla @ 2025-06-27 15:50 UTC (permalink / raw)
  To: vkoul, broonie
  Cc: yung-chuan.liao, pierre-louis.bossart, lgirdwood, perex, tiwai,
	krzysztof.kozlowski, linux-kernel, linux-sound, linux-arm-msm,
	Srinivas Kandagatla

From: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>

All these 3 codecs have been duplicating two of the soundwire
functions. Noticed another new driver starting to do the same, its time
to make some helpers so that we do not duplicate these functions.

I have added two helpers of_sdw_find_device_by_node() and
sdw_slave_get_current_bank() in soundwire layer for the codecs to use them.

Srinivas Kandagatla (4):
  soundwire: bus: add of_sdw_find_device_by_node helper
  soundwire: bus: add sdw_slave_get_current_bank helper
  ASoC: codecs: wcdxxxx: use of_sdw_find_device_by_node helper
  ASoC: codecs: wcdxxxx: use sdw_slave_get_current_bank helper

 drivers/soundwire/bus.c        |  7 +++++++
 drivers/soundwire/slave.c      |  6 ++++++
 include/linux/soundwire/sdw.h  | 17 +++++++++++++++++
 sound/soc/codecs/wcd937x-sdw.c |  6 ------
 sound/soc/codecs/wcd937x.c     |  4 ++--
 sound/soc/codecs/wcd937x.h     |  2 --
 sound/soc/codecs/wcd938x-sdw.c | 17 -----------------
 sound/soc/codecs/wcd938x.c     |  7 +++----
 sound/soc/codecs/wcd938x.h     | 13 -------------
 sound/soc/codecs/wcd939x-sdw.c | 13 -------------
 sound/soc/codecs/wcd939x.c     |  6 +++---
 sound/soc/codecs/wcd939x.h     | 13 -------------
 12 files changed, 38 insertions(+), 73 deletions(-)

-- 
2.49.0


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

* [PATCH 1/4] soundwire: bus: add of_sdw_find_device_by_node helper
  2025-06-27 15:50 [PATCH 0/4] ASoC: codecs: wcd937x/8x/9x: cleanup srinivas.kandagatla
@ 2025-06-27 15:51 ` srinivas.kandagatla
  2025-06-27 16:29   ` Konrad Dybcio
                     ` (2 more replies)
  2025-06-27 15:51 ` [PATCH 2/4] soundwire: bus: add sdw_slave_get_current_bank helper srinivas.kandagatla
                   ` (2 subsequent siblings)
  3 siblings, 3 replies; 12+ messages in thread
From: srinivas.kandagatla @ 2025-06-27 15:51 UTC (permalink / raw)
  To: vkoul, broonie
  Cc: yung-chuan.liao, pierre-louis.bossart, lgirdwood, perex, tiwai,
	krzysztof.kozlowski, linux-kernel, linux-sound, linux-arm-msm,
	Srinivas Kandagatla

From: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>

There has been more than 3 instances of this helper in multiple codec
drivers, it does not make sense to keep duplicating this part of code.

Lets add a helper of_sdw_find_device_by_node for codec drivers to use it.

Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
---
 drivers/soundwire/slave.c     | 6 ++++++
 include/linux/soundwire/sdw.h | 9 +++++++++
 2 files changed, 15 insertions(+)

diff --git a/drivers/soundwire/slave.c b/drivers/soundwire/slave.c
index d2d99555ec5a..3d4d00188c26 100644
--- a/drivers/soundwire/slave.c
+++ b/drivers/soundwire/slave.c
@@ -273,4 +273,10 @@ int sdw_of_find_slaves(struct sdw_bus *bus)
 	return 0;
 }
 
+struct device *of_sdw_find_device_by_node(struct device_node *np)
+{
+	return bus_find_device_by_of_node(&sdw_bus_type, np);
+}
+EXPORT_SYMBOL_GPL(of_sdw_find_device_by_node);
+
 MODULE_IMPORT_NS("SND_SOC_SDCA");
diff --git a/include/linux/soundwire/sdw.h b/include/linux/soundwire/sdw.h
index 2362f621d94c..84d1a101b155 100644
--- a/include/linux/soundwire/sdw.h
+++ b/include/linux/soundwire/sdw.h
@@ -18,6 +18,7 @@
 
 struct dentry;
 struct fwnode_handle;
+struct device_node;
 
 struct sdw_bus;
 struct sdw_slave;
@@ -1080,6 +1081,8 @@ int sdw_stream_add_slave(struct sdw_slave *slave,
 int sdw_stream_remove_slave(struct sdw_slave *slave,
 			    struct sdw_stream_runtime *stream);
 
+struct device *of_sdw_find_device_by_node(struct device_node *np);
+
 int sdw_slave_get_scale_index(struct sdw_slave *slave, u8 *base);
 
 /* messaging and data APIs */
@@ -1113,6 +1116,12 @@ static inline int sdw_stream_remove_slave(struct sdw_slave *slave,
 	return -EINVAL;
 }
 
+static inline struct device *of_sdw_find_device_by_node(struct device_node *np)
+{
+	WARN_ONCE(1, "SoundWire API is disabled");
+	return NULL;
+}
+
 /* messaging and data APIs */
 static inline int sdw_read(struct sdw_slave *slave, u32 addr)
 {
-- 
2.49.0


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

* [PATCH 2/4] soundwire: bus: add sdw_slave_get_current_bank helper
  2025-06-27 15:50 [PATCH 0/4] ASoC: codecs: wcd937x/8x/9x: cleanup srinivas.kandagatla
  2025-06-27 15:51 ` [PATCH 1/4] soundwire: bus: add of_sdw_find_device_by_node helper srinivas.kandagatla
@ 2025-06-27 15:51 ` srinivas.kandagatla
  2025-06-27 15:54   ` Konrad Dybcio
  2025-06-27 15:51 ` [PATCH 3/4] ASoC: codecs: wcdxxxx: use of_sdw_find_device_by_node helper srinivas.kandagatla
  2025-06-27 15:51 ` [PATCH 4/4] ASoC: codecs: wcdxxxx: use sdw_slave_get_current_bank helper srinivas.kandagatla
  3 siblings, 1 reply; 12+ messages in thread
From: srinivas.kandagatla @ 2025-06-27 15:51 UTC (permalink / raw)
  To: vkoul, broonie
  Cc: yung-chuan.liao, pierre-louis.bossart, lgirdwood, perex, tiwai,
	krzysztof.kozlowski, linux-kernel, linux-sound, linux-arm-msm,
	Srinivas Kandagatla

From: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>

There has been 2 instances of this helper in codec drivers,
it does not make sense to keep duplicating this part of code.

Lets add a helper sdw_get_current_bank() for codec drivers to use it.

Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
---
 drivers/soundwire/bus.c       | 7 +++++++
 include/linux/soundwire/sdw.h | 8 ++++++++
 2 files changed, 15 insertions(+)

diff --git a/drivers/soundwire/bus.c b/drivers/soundwire/bus.c
index 39aecd34c641..58306c515ccc 100644
--- a/drivers/soundwire/bus.c
+++ b/drivers/soundwire/bus.c
@@ -1363,6 +1363,13 @@ int sdw_slave_get_scale_index(struct sdw_slave *slave, u8 *base)
 }
 EXPORT_SYMBOL(sdw_slave_get_scale_index);
 
+int sdw_slave_get_current_bank(struct sdw_slave *sdev)
+{
+	return FIELD_GET(SDW_SCP_STAT_CURR_BANK,
+			 sdw_read(sdev, SDW_SCP_CTRL));
+}
+EXPORT_SYMBOL_GPL(sdw_slave_get_current_bank);
+
 static int sdw_slave_set_frequency(struct sdw_slave *slave)
 {
 	int scale_index;
diff --git a/include/linux/soundwire/sdw.h b/include/linux/soundwire/sdw.h
index 84d1a101b155..41c36470ad2d 100644
--- a/include/linux/soundwire/sdw.h
+++ b/include/linux/soundwire/sdw.h
@@ -1083,6 +1083,8 @@ int sdw_stream_remove_slave(struct sdw_slave *slave,
 
 struct device *of_sdw_find_device_by_node(struct device_node *np);
 
+int sdw_slave_get_current_bank(struct sdw_slave *sdev);
+
 int sdw_slave_get_scale_index(struct sdw_slave *slave, u8 *base);
 
 /* messaging and data APIs */
@@ -1122,6 +1124,12 @@ static inline struct device *of_sdw_find_device_by_node(struct device_node *np)
 	return NULL;
 }
 
+static inline int sdw_slave_get_current_bank(struct sdw_slave *sdev)
+{
+	WARN_ONCE(1, "SoundWire API is disabled");
+	return -EINVAL;
+}
+
 /* messaging and data APIs */
 static inline int sdw_read(struct sdw_slave *slave, u32 addr)
 {
-- 
2.49.0


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

* [PATCH 3/4] ASoC: codecs: wcdxxxx: use of_sdw_find_device_by_node helper
  2025-06-27 15:50 [PATCH 0/4] ASoC: codecs: wcd937x/8x/9x: cleanup srinivas.kandagatla
  2025-06-27 15:51 ` [PATCH 1/4] soundwire: bus: add of_sdw_find_device_by_node helper srinivas.kandagatla
  2025-06-27 15:51 ` [PATCH 2/4] soundwire: bus: add sdw_slave_get_current_bank helper srinivas.kandagatla
@ 2025-06-27 15:51 ` srinivas.kandagatla
  2025-06-28  2:01   ` Dmitry Baryshkov
  2025-06-27 15:51 ` [PATCH 4/4] ASoC: codecs: wcdxxxx: use sdw_slave_get_current_bank helper srinivas.kandagatla
  3 siblings, 1 reply; 12+ messages in thread
From: srinivas.kandagatla @ 2025-06-27 15:51 UTC (permalink / raw)
  To: vkoul, broonie
  Cc: yung-chuan.liao, pierre-louis.bossart, lgirdwood, perex, tiwai,
	krzysztof.kozlowski, linux-kernel, linux-sound, linux-arm-msm,
	Srinivas Kandagatla

From: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>

use of_sdw_find_device_by_node helper function, rather than duplicating
this function in every codec driver.

Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
---
 sound/soc/codecs/wcd937x-sdw.c | 6 ------
 sound/soc/codecs/wcd937x.c     | 4 ++--
 sound/soc/codecs/wcd937x.h     | 2 --
 sound/soc/codecs/wcd938x-sdw.c | 7 -------
 sound/soc/codecs/wcd938x.c     | 4 ++--
 sound/soc/codecs/wcd938x.h     | 6 ------
 sound/soc/codecs/wcd939x-sdw.c | 6 ------
 sound/soc/codecs/wcd939x.c     | 4 ++--
 sound/soc/codecs/wcd939x.h     | 6 ------
 9 files changed, 6 insertions(+), 39 deletions(-)

diff --git a/sound/soc/codecs/wcd937x-sdw.c b/sound/soc/codecs/wcd937x-sdw.c
index 1bfe7383b311..e7cc699bd8bc 100644
--- a/sound/soc/codecs/wcd937x-sdw.c
+++ b/sound/soc/codecs/wcd937x-sdw.c
@@ -78,12 +78,6 @@ static struct sdw_dpn_prop wcd937x_dpn_prop[WCD937X_MAX_SWR_PORTS] = {
 	}
 };
 
-struct device *wcd937x_sdw_device_get(struct device_node *np)
-{
-	return bus_find_device_by_of_node(&sdw_bus_type, np);
-}
-EXPORT_SYMBOL_GPL(wcd937x_sdw_device_get);
-
 int wcd937x_sdw_hw_params(struct wcd937x_sdw_priv *wcd,
 			  struct snd_pcm_substream *substream,
 			  struct snd_pcm_hw_params *params,
diff --git a/sound/soc/codecs/wcd937x.c b/sound/soc/codecs/wcd937x.c
index 3b1a1518e764..ad1ec0a2b38d 100644
--- a/sound/soc/codecs/wcd937x.c
+++ b/sound/soc/codecs/wcd937x.c
@@ -2789,7 +2789,7 @@ static int wcd937x_bind(struct device *dev)
 		return ret;
 	}
 
-	wcd937x->rxdev = wcd937x_sdw_device_get(wcd937x->rxnode);
+	wcd937x->rxdev = of_sdw_find_device_by_node(wcd937x->rxnode);
 	if (!wcd937x->rxdev) {
 		dev_err(dev, "could not find slave with matching of node\n");
 		return -EINVAL;
@@ -2798,7 +2798,7 @@ static int wcd937x_bind(struct device *dev)
 	wcd937x->sdw_priv[AIF1_PB] = dev_get_drvdata(wcd937x->rxdev);
 	wcd937x->sdw_priv[AIF1_PB]->wcd937x = wcd937x;
 
-	wcd937x->txdev = wcd937x_sdw_device_get(wcd937x->txnode);
+	wcd937x->txdev = of_sdw_find_device_by_node(wcd937x->txnode);
 	if (!wcd937x->txdev) {
 		dev_err(dev, "could not find txslave with matching of node\n");
 		return -EINVAL;
diff --git a/sound/soc/codecs/wcd937x.h b/sound/soc/codecs/wcd937x.h
index 4ef57c496c37..09b87984cecc 100644
--- a/sound/soc/codecs/wcd937x.h
+++ b/sound/soc/codecs/wcd937x.h
@@ -550,8 +550,6 @@ int wcd937x_sdw_hw_params(struct wcd937x_sdw_priv *wcd,
 			  struct snd_pcm_hw_params *params,
 			  struct snd_soc_dai *dai);
 
-struct device *wcd937x_sdw_device_get(struct device_node *np);
-
 #else
 int wcd937x_sdw_free(struct wcd937x_sdw_priv *wcd,
 		     struct snd_pcm_substream *substream,
diff --git a/sound/soc/codecs/wcd938x-sdw.c b/sound/soc/codecs/wcd938x-sdw.c
index cabddadc90ef..b4a0b66b34df 100644
--- a/sound/soc/codecs/wcd938x-sdw.c
+++ b/sound/soc/codecs/wcd938x-sdw.c
@@ -82,13 +82,6 @@ static struct sdw_dpn_prop wcd938x_dpn_prop[WCD938X_MAX_SWR_PORTS] = {
 	}
 };
 
-struct device *wcd938x_sdw_device_get(struct device_node *np)
-{
-	return bus_find_device_by_of_node(&sdw_bus_type, np);
-
-}
-EXPORT_SYMBOL_GPL(wcd938x_sdw_device_get);
-
 int wcd938x_swr_get_current_bank(struct sdw_slave *sdev)
 {
 	int bank;
diff --git a/sound/soc/codecs/wcd938x.c b/sound/soc/codecs/wcd938x.c
index 8c9f67dedb83..7c345217298d 100644
--- a/sound/soc/codecs/wcd938x.c
+++ b/sound/soc/codecs/wcd938x.c
@@ -3412,7 +3412,7 @@ static int wcd938x_bind(struct device *dev)
 		return ret;
 	}
 
-	wcd938x->rxdev = wcd938x_sdw_device_get(wcd938x->rxnode);
+	wcd938x->rxdev = of_sdw_find_device_by_node(wcd938x->rxnode);
 	if (!wcd938x->rxdev) {
 		dev_err(dev, "could not find slave with matching of node\n");
 		ret = -EINVAL;
@@ -3421,7 +3421,7 @@ static int wcd938x_bind(struct device *dev)
 	wcd938x->sdw_priv[AIF1_PB] = dev_get_drvdata(wcd938x->rxdev);
 	wcd938x->sdw_priv[AIF1_PB]->wcd938x = wcd938x;
 
-	wcd938x->txdev = wcd938x_sdw_device_get(wcd938x->txnode);
+	wcd938x->txdev = of_sdw_find_device_by_node(wcd938x->txnode);
 	if (!wcd938x->txdev) {
 		dev_err(dev, "could not find txslave with matching of node\n");
 		ret = -EINVAL;
diff --git a/sound/soc/codecs/wcd938x.h b/sound/soc/codecs/wcd938x.h
index fb6a0e4ef337..dbafcae247f4 100644
--- a/sound/soc/codecs/wcd938x.h
+++ b/sound/soc/codecs/wcd938x.h
@@ -670,7 +670,6 @@ int wcd938x_sdw_hw_params(struct wcd938x_sdw_priv *wcd,
 			  struct snd_pcm_hw_params *params,
 			  struct snd_soc_dai *dai);
 
-struct device *wcd938x_sdw_device_get(struct device_node *np);
 int wcd938x_swr_get_current_bank(struct sdw_slave *sdev);
 
 #else
@@ -697,11 +696,6 @@ static inline int wcd938x_sdw_hw_params(struct wcd938x_sdw_priv *wcd,
 	return -EOPNOTSUPP;
 }
 
-static inline struct device *wcd938x_sdw_device_get(struct device_node *np)
-{
-	return NULL;
-}
-
 static inline int wcd938x_swr_get_current_bank(struct sdw_slave *sdev)
 {
 	return 0;
diff --git a/sound/soc/codecs/wcd939x-sdw.c b/sound/soc/codecs/wcd939x-sdw.c
index f7a9323a9fea..e487a1bb0194 100644
--- a/sound/soc/codecs/wcd939x-sdw.c
+++ b/sound/soc/codecs/wcd939x-sdw.c
@@ -128,12 +128,6 @@ static struct sdw_dpn_prop wcd939x_tx_dpn_prop[WCD939X_MAX_TX_SWR_PORTS] = {
 	}
 };
 
-struct device *wcd939x_sdw_device_get(struct device_node *np)
-{
-	return bus_find_device_by_of_node(&sdw_bus_type, np);
-}
-EXPORT_SYMBOL_GPL(wcd939x_sdw_device_get);
-
 unsigned int wcd939x_swr_get_current_bank(struct sdw_slave *sdev)
 {
 	return FIELD_GET(SDW_SCP_STAT_CURR_BANK,
diff --git a/sound/soc/codecs/wcd939x.c b/sound/soc/codecs/wcd939x.c
index 16c670e00aa8..0727af4789cb 100644
--- a/sound/soc/codecs/wcd939x.c
+++ b/sound/soc/codecs/wcd939x.c
@@ -3390,7 +3390,7 @@ static int wcd939x_bind(struct device *dev)
 		goto err_put_typec_switch;
 	}
 
-	wcd939x->rxdev = wcd939x_sdw_device_get(wcd939x->rxnode);
+	wcd939x->rxdev = of_sdw_find_device_by_node(wcd939x->rxnode);
 	if (!wcd939x->rxdev) {
 		dev_err(dev, "could not find slave with matching of node\n");
 		ret = -EINVAL;
@@ -3399,7 +3399,7 @@ static int wcd939x_bind(struct device *dev)
 	wcd939x->sdw_priv[AIF1_PB] = dev_get_drvdata(wcd939x->rxdev);
 	wcd939x->sdw_priv[AIF1_PB]->wcd939x = wcd939x;
 
-	wcd939x->txdev = wcd939x_sdw_device_get(wcd939x->txnode);
+	wcd939x->txdev = of_sdw_find_device_by_node(wcd939x->txnode);
 	if (!wcd939x->txdev) {
 		dev_err(dev, "could not find txslave with matching of node\n");
 		ret = -EINVAL;
diff --git a/sound/soc/codecs/wcd939x.h b/sound/soc/codecs/wcd939x.h
index 3204fb10b58d..3f189e5cafd5 100644
--- a/sound/soc/codecs/wcd939x.h
+++ b/sound/soc/codecs/wcd939x.h
@@ -930,7 +930,6 @@ int wcd939x_sdw_hw_params(struct wcd939x_sdw_priv *wcd,
 			  struct snd_pcm_hw_params *params,
 			  struct snd_soc_dai *dai);
 
-struct device *wcd939x_sdw_device_get(struct device_node *np);
 unsigned int wcd939x_swr_get_current_bank(struct sdw_slave *sdev);
 
 struct regmap *wcd939x_swr_get_regmap(struct wcd939x_sdw_priv *wcd);
@@ -958,11 +957,6 @@ static inline int wcd939x_sdw_hw_params(struct wcd939x_sdw_priv *wcd,
 	return -EOPNOTSUPP;
 }
 
-static inline struct device *wcd939x_sdw_device_get(struct device_node *np)
-{
-	return NULL;
-}
-
 static inline unsigned int wcd939x_swr_get_current_bank(struct sdw_slave *sdev)
 {
 	return 0;
-- 
2.49.0


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

* [PATCH 4/4] ASoC: codecs: wcdxxxx: use sdw_slave_get_current_bank helper
  2025-06-27 15:50 [PATCH 0/4] ASoC: codecs: wcd937x/8x/9x: cleanup srinivas.kandagatla
                   ` (2 preceding siblings ...)
  2025-06-27 15:51 ` [PATCH 3/4] ASoC: codecs: wcdxxxx: use of_sdw_find_device_by_node helper srinivas.kandagatla
@ 2025-06-27 15:51 ` srinivas.kandagatla
  3 siblings, 0 replies; 12+ messages in thread
From: srinivas.kandagatla @ 2025-06-27 15:51 UTC (permalink / raw)
  To: vkoul, broonie
  Cc: yung-chuan.liao, pierre-louis.bossart, lgirdwood, perex, tiwai,
	krzysztof.kozlowski, linux-kernel, linux-sound, linux-arm-msm,
	Srinivas Kandagatla

From: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>

use sdw_slave_get_current_bank() helper function, rather than duplicating
this function in every codec driver.

Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
---
 sound/soc/codecs/wcd938x-sdw.c | 10 ----------
 sound/soc/codecs/wcd938x.c     |  3 +--
 sound/soc/codecs/wcd938x.h     |  7 -------
 sound/soc/codecs/wcd939x-sdw.c |  7 -------
 sound/soc/codecs/wcd939x.c     |  2 +-
 sound/soc/codecs/wcd939x.h     |  7 -------
 6 files changed, 2 insertions(+), 34 deletions(-)

diff --git a/sound/soc/codecs/wcd938x-sdw.c b/sound/soc/codecs/wcd938x-sdw.c
index b4a0b66b34df..9e411d906354 100644
--- a/sound/soc/codecs/wcd938x-sdw.c
+++ b/sound/soc/codecs/wcd938x-sdw.c
@@ -82,16 +82,6 @@ static struct sdw_dpn_prop wcd938x_dpn_prop[WCD938X_MAX_SWR_PORTS] = {
 	}
 };
 
-int wcd938x_swr_get_current_bank(struct sdw_slave *sdev)
-{
-	int bank;
-
-	bank  = sdw_read(sdev, SDW_SCP_CTRL);
-
-	return ((bank & 0x40) ? 1 : 0);
-}
-EXPORT_SYMBOL_GPL(wcd938x_swr_get_current_bank);
-
 int wcd938x_sdw_hw_params(struct wcd938x_sdw_priv *wcd,
 			  struct snd_pcm_substream *substream,
 			  struct snd_pcm_hw_params *params,
diff --git a/sound/soc/codecs/wcd938x.c b/sound/soc/codecs/wcd938x.c
index 7c345217298d..7e1e99b22cb8 100644
--- a/sound/soc/codecs/wcd938x.c
+++ b/sound/soc/codecs/wcd938x.c
@@ -1097,8 +1097,7 @@ static int wcd938x_tx_swr_ctrl(struct snd_soc_dapm_widget *w,
 	int bank;
 	int rate;
 
-	bank = (wcd938x_swr_get_current_bank(wcd938x->sdw_priv[AIF1_CAP]->sdev)) ? 0 : 1;
-	bank = bank ? 0 : 1;
+	bank = sdw_slave_get_current_bank(wcd938x->sdw_priv[AIF1_CAP]->sdev);
 
 	switch (event) {
 	case SND_SOC_DAPM_PRE_PMU:
diff --git a/sound/soc/codecs/wcd938x.h b/sound/soc/codecs/wcd938x.h
index dbafcae247f4..54ee56b7fbd6 100644
--- a/sound/soc/codecs/wcd938x.h
+++ b/sound/soc/codecs/wcd938x.h
@@ -669,9 +669,6 @@ int wcd938x_sdw_hw_params(struct wcd938x_sdw_priv *wcd,
 			  struct snd_pcm_substream *substream,
 			  struct snd_pcm_hw_params *params,
 			  struct snd_soc_dai *dai);
-
-int wcd938x_swr_get_current_bank(struct sdw_slave *sdev);
-
 #else
 
 static inline int wcd938x_sdw_free(struct wcd938x_sdw_priv *wcd,
@@ -696,9 +693,5 @@ static inline int wcd938x_sdw_hw_params(struct wcd938x_sdw_priv *wcd,
 	return -EOPNOTSUPP;
 }
 
-static inline int wcd938x_swr_get_current_bank(struct sdw_slave *sdev)
-{
-	return 0;
-}
 #endif /* CONFIG_SND_SOC_WCD938X_SDW */
 #endif /* __WCD938X_H__ */
diff --git a/sound/soc/codecs/wcd939x-sdw.c b/sound/soc/codecs/wcd939x-sdw.c
index e487a1bb0194..477d6cf27d32 100644
--- a/sound/soc/codecs/wcd939x-sdw.c
+++ b/sound/soc/codecs/wcd939x-sdw.c
@@ -128,13 +128,6 @@ static struct sdw_dpn_prop wcd939x_tx_dpn_prop[WCD939X_MAX_TX_SWR_PORTS] = {
 	}
 };
 
-unsigned int wcd939x_swr_get_current_bank(struct sdw_slave *sdev)
-{
-	return FIELD_GET(SDW_SCP_STAT_CURR_BANK,
-			 sdw_read(sdev, SDW_SCP_CTRL));
-}
-EXPORT_SYMBOL_GPL(wcd939x_swr_get_current_bank);
-
 int wcd939x_sdw_hw_params(struct wcd939x_sdw_priv *wcd,
 			  struct snd_pcm_substream *substream,
 			  struct snd_pcm_hw_params *params,
diff --git a/sound/soc/codecs/wcd939x.c b/sound/soc/codecs/wcd939x.c
index 0727af4789cb..f59bda0ad089 100644
--- a/sound/soc/codecs/wcd939x.c
+++ b/sound/soc/codecs/wcd939x.c
@@ -1014,7 +1014,7 @@ static int wcd939x_tx_swr_ctrl(struct snd_soc_dapm_widget *w,
 	int bank;
 	int rate;
 
-	bank = wcd939x_swr_get_current_bank(wcd939x->sdw_priv[AIF1_CAP]->sdev);
+	bank = sdw_slave_get_current_bank(wcd939x->sdw_priv[AIF1_CAP]->sdev);
 
 	switch (event) {
 	case SND_SOC_DAPM_PRE_PMU:
diff --git a/sound/soc/codecs/wcd939x.h b/sound/soc/codecs/wcd939x.h
index 3f189e5cafd5..e70445b1a4bc 100644
--- a/sound/soc/codecs/wcd939x.h
+++ b/sound/soc/codecs/wcd939x.h
@@ -930,8 +930,6 @@ int wcd939x_sdw_hw_params(struct wcd939x_sdw_priv *wcd,
 			  struct snd_pcm_hw_params *params,
 			  struct snd_soc_dai *dai);
 
-unsigned int wcd939x_swr_get_current_bank(struct sdw_slave *sdev);
-
 struct regmap *wcd939x_swr_get_regmap(struct wcd939x_sdw_priv *wcd);
 #else
 
@@ -957,11 +955,6 @@ static inline int wcd939x_sdw_hw_params(struct wcd939x_sdw_priv *wcd,
 	return -EOPNOTSUPP;
 }
 
-static inline unsigned int wcd939x_swr_get_current_bank(struct sdw_slave *sdev)
-{
-	return 0;
-}
-
 struct regmap *wcd939x_swr_get_regmap(struct wcd939x_sdw_priv *wcd)
 {
 	return PTR_ERR(-EINVAL);
-- 
2.49.0


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

* Re: [PATCH 2/4] soundwire: bus: add sdw_slave_get_current_bank helper
  2025-06-27 15:51 ` [PATCH 2/4] soundwire: bus: add sdw_slave_get_current_bank helper srinivas.kandagatla
@ 2025-06-27 15:54   ` Konrad Dybcio
  2025-06-27 16:20     ` Srinivas Kandagatla
  0 siblings, 1 reply; 12+ messages in thread
From: Konrad Dybcio @ 2025-06-27 15:54 UTC (permalink / raw)
  To: srinivas.kandagatla, vkoul, broonie
  Cc: yung-chuan.liao, pierre-louis.bossart, lgirdwood, perex, tiwai,
	krzysztof.kozlowski, linux-kernel, linux-sound, linux-arm-msm

On 6/27/25 5:51 PM, srinivas.kandagatla@oss.qualcomm.com wrote:
> From: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
> 
> There has been 2 instances of this helper in codec drivers,
> it does not make sense to keep duplicating this part of code.
> 
> Lets add a helper sdw_get_current_bank() for codec drivers to use it.
> 
> Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
> ---
>  drivers/soundwire/bus.c       | 7 +++++++
>  include/linux/soundwire/sdw.h | 8 ++++++++
>  2 files changed, 15 insertions(+)
> 
> diff --git a/drivers/soundwire/bus.c b/drivers/soundwire/bus.c
> index 39aecd34c641..58306c515ccc 100644
> --- a/drivers/soundwire/bus.c
> +++ b/drivers/soundwire/bus.c
> @@ -1363,6 +1363,13 @@ int sdw_slave_get_scale_index(struct sdw_slave *slave, u8 *base)
>  }
>  EXPORT_SYMBOL(sdw_slave_get_scale_index);
>  
> +int sdw_slave_get_current_bank(struct sdw_slave *sdev)
> +{
> +	return FIELD_GET(SDW_SCP_STAT_CURR_BANK,
> +			 sdw_read(sdev, SDW_SCP_CTRL));

sdw_read can fail (miserably)

Konrad

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

* Re: [PATCH 2/4] soundwire: bus: add sdw_slave_get_current_bank helper
  2025-06-27 15:54   ` Konrad Dybcio
@ 2025-06-27 16:20     ` Srinivas Kandagatla
  0 siblings, 0 replies; 12+ messages in thread
From: Srinivas Kandagatla @ 2025-06-27 16:20 UTC (permalink / raw)
  To: Konrad Dybcio, vkoul, broonie
  Cc: yung-chuan.liao, pierre-louis.bossart, lgirdwood, perex, tiwai,
	krzysztof.kozlowski, linux-kernel, linux-sound, linux-arm-msm

On 6/27/25 4:54 PM, Konrad Dybcio wrote:
> On 6/27/25 5:51 PM, srinivas.kandagatla@oss.qualcomm.com wrote:
>> From: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
>>
>> There has been 2 instances of this helper in codec drivers,
>> it does not make sense to keep duplicating this part of code.
>>
>> Lets add a helper sdw_get_current_bank() for codec drivers to use it.
>>
>> Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
>> ---
>>  drivers/soundwire/bus.c       | 7 +++++++
>>  include/linux/soundwire/sdw.h | 8 ++++++++
>>  2 files changed, 15 insertions(+)
>>
>> diff --git a/drivers/soundwire/bus.c b/drivers/soundwire/bus.c
>> index 39aecd34c641..58306c515ccc 100644
>> --- a/drivers/soundwire/bus.c
>> +++ b/drivers/soundwire/bus.c
>> @@ -1363,6 +1363,13 @@ int sdw_slave_get_scale_index(struct sdw_slave *slave, u8 *base)
>>  }
>>  EXPORT_SYMBOL(sdw_slave_get_scale_index);
>>  
>> +int sdw_slave_get_current_bank(struct sdw_slave *sdev)
>> +{
>> +	return FIELD_GET(SDW_SCP_STAT_CURR_BANK,
>> +			 sdw_read(sdev, SDW_SCP_CTRL));
> 
> sdw_read can fail (miserably)
I agree, will add check in v2.


--srini
> 
> Konrad


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

* Re: [PATCH 1/4] soundwire: bus: add of_sdw_find_device_by_node helper
  2025-06-27 15:51 ` [PATCH 1/4] soundwire: bus: add of_sdw_find_device_by_node helper srinivas.kandagatla
@ 2025-06-27 16:29   ` Konrad Dybcio
  2025-06-27 17:46   ` Vinod Koul
  2025-06-28  2:02   ` Dmitry Baryshkov
  2 siblings, 0 replies; 12+ messages in thread
From: Konrad Dybcio @ 2025-06-27 16:29 UTC (permalink / raw)
  To: srinivas.kandagatla, vkoul, broonie
  Cc: yung-chuan.liao, pierre-louis.bossart, lgirdwood, perex, tiwai,
	krzysztof.kozlowski, linux-kernel, linux-sound, linux-arm-msm

On 6/27/25 5:51 PM, srinivas.kandagatla@oss.qualcomm.com wrote:
> From: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
> 
> There has been more than 3 instances of this helper in multiple codec
> drivers, it does not make sense to keep duplicating this part of code.
> 
> Lets add a helper of_sdw_find_device_by_node for codec drivers to use it.
> 
> Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
> ---

I think we can do the same with e.g.

sound/soc/sdw_utils/soc_sdw_rt_amp.c
281:            sdw_dev1 = bus_find_device_by_name(&sdw_bus_type, NULL, dai_links->codecs[0].name);
292:            sdw_dev2 = bus_find_device_by_name(&sdw_bus_type, NULL, dai_links->codecs[1].name);


and make sdw_bus_type private again

Konrad

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

* Re: [PATCH 1/4] soundwire: bus: add of_sdw_find_device_by_node helper
  2025-06-27 15:51 ` [PATCH 1/4] soundwire: bus: add of_sdw_find_device_by_node helper srinivas.kandagatla
  2025-06-27 16:29   ` Konrad Dybcio
@ 2025-06-27 17:46   ` Vinod Koul
  2025-06-28 20:29     ` Srinivas Kandagatla
  2025-06-28  2:02   ` Dmitry Baryshkov
  2 siblings, 1 reply; 12+ messages in thread
From: Vinod Koul @ 2025-06-27 17:46 UTC (permalink / raw)
  To: srinivas.kandagatla
  Cc: broonie, yung-chuan.liao, pierre-louis.bossart, lgirdwood, perex,
	tiwai, krzysztof.kozlowski, linux-kernel, linux-sound,
	linux-arm-msm

On 27-06-25, 16:51, srinivas.kandagatla@oss.qualcomm.com wrote:
> From: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
> 
> There has been more than 3 instances of this helper in multiple codec
> drivers, it does not make sense to keep duplicating this part of code.
> 
> Lets add a helper of_sdw_find_device_by_node for codec drivers to use it.
> 
> Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
> ---
>  drivers/soundwire/slave.c     | 6 ++++++
>  include/linux/soundwire/sdw.h | 9 +++++++++
>  2 files changed, 15 insertions(+)
> 
> diff --git a/drivers/soundwire/slave.c b/drivers/soundwire/slave.c
> index d2d99555ec5a..3d4d00188c26 100644
> --- a/drivers/soundwire/slave.c
> +++ b/drivers/soundwire/slave.c
> @@ -273,4 +273,10 @@ int sdw_of_find_slaves(struct sdw_bus *bus)
>  	return 0;
>  }
>  
> +struct device *of_sdw_find_device_by_node(struct device_node *np)
> +{
> +	return bus_find_device_by_of_node(&sdw_bus_type, np);
> +}
> +EXPORT_SYMBOL_GPL(of_sdw_find_device_by_node);

Helper for single code lines?? why!

> +
>  MODULE_IMPORT_NS("SND_SOC_SDCA");
> diff --git a/include/linux/soundwire/sdw.h b/include/linux/soundwire/sdw.h
> index 2362f621d94c..84d1a101b155 100644
> --- a/include/linux/soundwire/sdw.h
> +++ b/include/linux/soundwire/sdw.h
> @@ -18,6 +18,7 @@
>  
>  struct dentry;
>  struct fwnode_handle;
> +struct device_node;
>  
>  struct sdw_bus;
>  struct sdw_slave;
> @@ -1080,6 +1081,8 @@ int sdw_stream_add_slave(struct sdw_slave *slave,
>  int sdw_stream_remove_slave(struct sdw_slave *slave,
>  			    struct sdw_stream_runtime *stream);
>  
> +struct device *of_sdw_find_device_by_node(struct device_node *np);
> +
>  int sdw_slave_get_scale_index(struct sdw_slave *slave, u8 *base);
>  
>  /* messaging and data APIs */
> @@ -1113,6 +1116,12 @@ static inline int sdw_stream_remove_slave(struct sdw_slave *slave,
>  	return -EINVAL;
>  }
>  
> +static inline struct device *of_sdw_find_device_by_node(struct device_node *np)
> +{
> +	WARN_ONCE(1, "SoundWire API is disabled");
> +	return NULL;
> +}
> +
>  /* messaging and data APIs */
>  static inline int sdw_read(struct sdw_slave *slave, u32 addr)
>  {
> -- 
> 2.49.0

-- 
~Vinod

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

* Re: [PATCH 3/4] ASoC: codecs: wcdxxxx: use of_sdw_find_device_by_node helper
  2025-06-27 15:51 ` [PATCH 3/4] ASoC: codecs: wcdxxxx: use of_sdw_find_device_by_node helper srinivas.kandagatla
@ 2025-06-28  2:01   ` Dmitry Baryshkov
  0 siblings, 0 replies; 12+ messages in thread
From: Dmitry Baryshkov @ 2025-06-28  2:01 UTC (permalink / raw)
  To: srinivas.kandagatla
  Cc: vkoul, broonie, yung-chuan.liao, pierre-louis.bossart, lgirdwood,
	perex, tiwai, krzysztof.kozlowski, linux-kernel, linux-sound,
	linux-arm-msm

On Fri, Jun 27, 2025 at 04:51:02PM +0100, srinivas.kandagatla@oss.qualcomm.com wrote:
> From: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
> 
> use of_sdw_find_device_by_node helper function, rather than duplicating
> this function in every codec driver.
> 
> Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
> ---
>  sound/soc/codecs/wcd937x-sdw.c | 6 ------
>  sound/soc/codecs/wcd937x.c     | 4 ++--
>  sound/soc/codecs/wcd937x.h     | 2 --
>  sound/soc/codecs/wcd938x-sdw.c | 7 -------
>  sound/soc/codecs/wcd938x.c     | 4 ++--
>  sound/soc/codecs/wcd938x.h     | 6 ------
>  sound/soc/codecs/wcd939x-sdw.c | 6 ------
>  sound/soc/codecs/wcd939x.c     | 4 ++--
>  sound/soc/codecs/wcd939x.h     | 6 ------
>  9 files changed, 6 insertions(+), 39 deletions(-)
> 

Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>


-- 
With best wishes
Dmitry

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

* Re: [PATCH 1/4] soundwire: bus: add of_sdw_find_device_by_node helper
  2025-06-27 15:51 ` [PATCH 1/4] soundwire: bus: add of_sdw_find_device_by_node helper srinivas.kandagatla
  2025-06-27 16:29   ` Konrad Dybcio
  2025-06-27 17:46   ` Vinod Koul
@ 2025-06-28  2:02   ` Dmitry Baryshkov
  2 siblings, 0 replies; 12+ messages in thread
From: Dmitry Baryshkov @ 2025-06-28  2:02 UTC (permalink / raw)
  To: srinivas.kandagatla
  Cc: vkoul, broonie, yung-chuan.liao, pierre-louis.bossart, lgirdwood,
	perex, tiwai, krzysztof.kozlowski, linux-kernel, linux-sound,
	linux-arm-msm

On Fri, Jun 27, 2025 at 04:51:00PM +0100, srinivas.kandagatla@oss.qualcomm.com wrote:
> From: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
> 
> There has been more than 3 instances of this helper in multiple codec
> drivers, it does not make sense to keep duplicating this part of code.
> 
> Lets add a helper of_sdw_find_device_by_node for codec drivers to use it.
> 
> Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
> ---
>  drivers/soundwire/slave.c     | 6 ++++++
>  include/linux/soundwire/sdw.h | 9 +++++++++
>  2 files changed, 15 insertions(+)
> 

Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>


-- 
With best wishes
Dmitry

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

* Re: [PATCH 1/4] soundwire: bus: add of_sdw_find_device_by_node helper
  2025-06-27 17:46   ` Vinod Koul
@ 2025-06-28 20:29     ` Srinivas Kandagatla
  0 siblings, 0 replies; 12+ messages in thread
From: Srinivas Kandagatla @ 2025-06-28 20:29 UTC (permalink / raw)
  To: Vinod Koul
  Cc: broonie, yung-chuan.liao, pierre-louis.bossart, lgirdwood, perex,
	tiwai, krzysztof.kozlowski, linux-kernel, linux-sound,
	linux-arm-msm

On 6/27/25 6:46 PM, Vinod Koul wrote:
> On 27-06-25, 16:51, srinivas.kandagatla@oss.qualcomm.com wrote:
>> From: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
>>
>> There has been more than 3 instances of this helper in multiple codec
>> drivers, it does not make sense to keep duplicating this part of code.
>>
>> Lets add a helper of_sdw_find_device_by_node for codec drivers to use it.
>>
>> Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
>> ---
>>  drivers/soundwire/slave.c     | 6 ++++++
>>  include/linux/soundwire/sdw.h | 9 +++++++++
>>  2 files changed, 15 insertions(+)
>>
>> diff --git a/drivers/soundwire/slave.c b/drivers/soundwire/slave.c
>> index d2d99555ec5a..3d4d00188c26 100644
>> --- a/drivers/soundwire/slave.c
>> +++ b/drivers/soundwire/slave.c
>> @@ -273,4 +273,10 @@ int sdw_of_find_slaves(struct sdw_bus *bus)
>>  	return 0;
>>  }
>>  
>> +struct device *of_sdw_find_device_by_node(struct device_node *np)
>> +{
>> +	return bus_find_device_by_of_node(&sdw_bus_type, np);
>> +}
>> +EXPORT_SYMBOL_GPL(of_sdw_find_device_by_node);
> 
> Helper for single code lines?? why!
Two reasons,
1, there are already uses of this kinda helper in the current codec
drivers and even for platform driver has such export symbol
of_find_device_by_node().

2, sdw_bus_type can be made private at some point .

--srini
> 
>> +
>>  MODULE_IMPORT_NS("SND_SOC_SDCA");
>> diff --git a/include/linux/soundwire/sdw.h b/include/linux/soundwire/sdw.h
>> index 2362f621d94c..84d1a101b155 100644
>> --- a/include/linux/soundwire/sdw.h
>> +++ b/include/linux/soundwire/sdw.h
>> @@ -18,6 +18,7 @@
>>  
>>  struct dentry;
>>  struct fwnode_handle;
>> +struct device_node;
>>  
>>  struct sdw_bus;
>>  struct sdw_slave;
>> @@ -1080,6 +1081,8 @@ int sdw_stream_add_slave(struct sdw_slave *slave,
>>  int sdw_stream_remove_slave(struct sdw_slave *slave,
>>  			    struct sdw_stream_runtime *stream);
>>  
>> +struct device *of_sdw_find_device_by_node(struct device_node *np);
>> +
>>  int sdw_slave_get_scale_index(struct sdw_slave *slave, u8 *base);
>>  
>>  /* messaging and data APIs */
>> @@ -1113,6 +1116,12 @@ static inline int sdw_stream_remove_slave(struct sdw_slave *slave,
>>  	return -EINVAL;
>>  }
>>  
>> +static inline struct device *of_sdw_find_device_by_node(struct device_node *np)
>> +{
>> +	WARN_ONCE(1, "SoundWire API is disabled");
>> +	return NULL;
>> +}
>> +
>>  /* messaging and data APIs */
>>  static inline int sdw_read(struct sdw_slave *slave, u32 addr)
>>  {
>> -- 
>> 2.49.0
> 


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

end of thread, other threads:[~2025-06-28 20:29 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-06-27 15:50 [PATCH 0/4] ASoC: codecs: wcd937x/8x/9x: cleanup srinivas.kandagatla
2025-06-27 15:51 ` [PATCH 1/4] soundwire: bus: add of_sdw_find_device_by_node helper srinivas.kandagatla
2025-06-27 16:29   ` Konrad Dybcio
2025-06-27 17:46   ` Vinod Koul
2025-06-28 20:29     ` Srinivas Kandagatla
2025-06-28  2:02   ` Dmitry Baryshkov
2025-06-27 15:51 ` [PATCH 2/4] soundwire: bus: add sdw_slave_get_current_bank helper srinivas.kandagatla
2025-06-27 15:54   ` Konrad Dybcio
2025-06-27 16:20     ` Srinivas Kandagatla
2025-06-27 15:51 ` [PATCH 3/4] ASoC: codecs: wcdxxxx: use of_sdw_find_device_by_node helper srinivas.kandagatla
2025-06-28  2:01   ` Dmitry Baryshkov
2025-06-27 15:51 ` [PATCH 4/4] ASoC: codecs: wcdxxxx: use sdw_slave_get_current_bank helper srinivas.kandagatla

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

all inboxes | Powered by JetHome®