* [PATCH v3 01/12] ASoC: codecs: wcd937x: set the comp soundwire port correctly
2025-09-05 15:44 [PATCH v3 00/12] ASoC: codecs: wcd93xxx: remove code duplication Srinivas Kandagatla
@ 2025-09-05 15:44 ` Srinivas Kandagatla
2025-09-05 16:14 ` Dmitry Baryshkov
2025-09-05 15:44 ` [PATCH v3 02/12] soundwire: bus: add of_sdw_find_device_by_node helper Srinivas Kandagatla
` (10 subsequent siblings)
11 siblings, 1 reply; 24+ messages in thread
From: Srinivas Kandagatla @ 2025-09-05 15:44 UTC (permalink / raw)
To: broonie
Cc: lgirdwood, tiwai, vkoul, srini, yung-chuan.liao,
pierre-louis.bossart, linux-arm-msm, linux-kernel, neil.armstrong,
krzysztof.kozlowski, dmitry.baryshkov, linux-sound,
Srinivas Kandagatla, Stable
For some reason we endup with setting soundwire port for
HPHL_COMP and HPHR_COMP as zero, this can potentially result
in a memory corruption due to accessing and setting -1 th element of
port_map array.
Fixes: 82be8c62a38c ("ASoC: codecs: wcd937x: add basic controls")
Cc: <Stable@vger.kernel.org>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
---
sound/soc/codecs/wcd937x.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/sound/soc/codecs/wcd937x.c b/sound/soc/codecs/wcd937x.c
index 3b0a8cc314e0..de2dff3c56d3 100644
--- a/sound/soc/codecs/wcd937x.c
+++ b/sound/soc/codecs/wcd937x.c
@@ -2046,9 +2046,9 @@ static const struct snd_kcontrol_new wcd937x_snd_controls[] = {
SOC_ENUM_EXT("RX HPH Mode", rx_hph_mode_mux_enum,
wcd937x_rx_hph_mode_get, wcd937x_rx_hph_mode_put),
- SOC_SINGLE_EXT("HPHL_COMP Switch", SND_SOC_NOPM, 0, 1, 0,
+ SOC_SINGLE_EXT("HPHL_COMP Switch", WCD937X_COMP_L, 0, 1, 0,
wcd937x_get_compander, wcd937x_set_compander),
- SOC_SINGLE_EXT("HPHR_COMP Switch", SND_SOC_NOPM, 1, 1, 0,
+ SOC_SINGLE_EXT("HPHR_COMP Switch", WCD937X_COMP_R, 1, 1, 0,
wcd937x_get_compander, wcd937x_set_compander),
SOC_SINGLE_TLV("HPHL Volume", WCD937X_HPH_L_EN, 0, 20, 1, line_gain),
--
2.50.0
^ permalink raw reply related [flat|nested] 24+ messages in thread* Re: [PATCH v3 01/12] ASoC: codecs: wcd937x: set the comp soundwire port correctly
2025-09-05 15:44 ` [PATCH v3 01/12] ASoC: codecs: wcd937x: set the comp soundwire port correctly Srinivas Kandagatla
@ 2025-09-05 16:14 ` Dmitry Baryshkov
2025-09-05 16:47 ` Srinivas Kandagatla
0 siblings, 1 reply; 24+ messages in thread
From: Dmitry Baryshkov @ 2025-09-05 16:14 UTC (permalink / raw)
To: Srinivas Kandagatla
Cc: broonie, lgirdwood, tiwai, vkoul, srini, yung-chuan.liao,
pierre-louis.bossart, linux-arm-msm, linux-kernel, neil.armstrong,
krzysztof.kozlowski, linux-sound, Stable
On Fri, Sep 05, 2025 at 04:44:19PM +0100, Srinivas Kandagatla wrote:
> For some reason we endup with setting soundwire port for
> HPHL_COMP and HPHR_COMP as zero, this can potentially result
> in a memory corruption due to accessing and setting -1 th element of
> port_map array.
Nit: if passing 0 here might result in a memory corrution, then
corresponding code should be fixed to warn loudly and ignore that 0.
>
> Fixes: 82be8c62a38c ("ASoC: codecs: wcd937x: add basic controls")
> Cc: <Stable@vger.kernel.org>
> Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
> ---
> sound/soc/codecs/wcd937x.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/sound/soc/codecs/wcd937x.c b/sound/soc/codecs/wcd937x.c
> index 3b0a8cc314e0..de2dff3c56d3 100644
> --- a/sound/soc/codecs/wcd937x.c
> +++ b/sound/soc/codecs/wcd937x.c
> @@ -2046,9 +2046,9 @@ static const struct snd_kcontrol_new wcd937x_snd_controls[] = {
> SOC_ENUM_EXT("RX HPH Mode", rx_hph_mode_mux_enum,
> wcd937x_rx_hph_mode_get, wcd937x_rx_hph_mode_put),
>
> - SOC_SINGLE_EXT("HPHL_COMP Switch", SND_SOC_NOPM, 0, 1, 0,
> + SOC_SINGLE_EXT("HPHL_COMP Switch", WCD937X_COMP_L, 0, 1, 0,
> wcd937x_get_compander, wcd937x_set_compander),
> - SOC_SINGLE_EXT("HPHR_COMP Switch", SND_SOC_NOPM, 1, 1, 0,
> + SOC_SINGLE_EXT("HPHR_COMP Switch", WCD937X_COMP_R, 1, 1, 0,
> wcd937x_get_compander, wcd937x_set_compander),
>
> SOC_SINGLE_TLV("HPHL Volume", WCD937X_HPH_L_EN, 0, 20, 1, line_gain),
> --
> 2.50.0
>
--
With best wishes
Dmitry
^ permalink raw reply [flat|nested] 24+ messages in thread* Re: [PATCH v3 01/12] ASoC: codecs: wcd937x: set the comp soundwire port correctly
2025-09-05 16:14 ` Dmitry Baryshkov
@ 2025-09-05 16:47 ` Srinivas Kandagatla
0 siblings, 0 replies; 24+ messages in thread
From: Srinivas Kandagatla @ 2025-09-05 16:47 UTC (permalink / raw)
To: Dmitry Baryshkov
Cc: broonie, lgirdwood, tiwai, vkoul, srini, yung-chuan.liao,
pierre-louis.bossart, linux-arm-msm, linux-kernel, neil.armstrong,
krzysztof.kozlowski, linux-sound, Stable
On 9/5/25 5:14 PM, Dmitry Baryshkov wrote:
> On Fri, Sep 05, 2025 at 04:44:19PM +0100, Srinivas Kandagatla wrote:
>> For some reason we endup with setting soundwire port for
>> HPHL_COMP and HPHR_COMP as zero, this can potentially result
>> in a memory corruption due to accessing and setting -1 th element of
>> port_map array.
>
> Nit: if passing 0 here might result in a memory corrution, then
> corresponding code should be fixed to warn loudly and ignore that 0.
Agreed, This is something that should be fixed at source am on it.
--srini
>
>>
>> Fixes: 82be8c62a38c ("ASoC: codecs: wcd937x: add basic controls")
>> Cc: <Stable@vger.kernel.org>
>> Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
>> ---
>> sound/soc/codecs/wcd937x.c | 4 ++--
>> 1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/sound/soc/codecs/wcd937x.c b/sound/soc/codecs/wcd937x.c
>> index 3b0a8cc314e0..de2dff3c56d3 100644
>> --- a/sound/soc/codecs/wcd937x.c
>> +++ b/sound/soc/codecs/wcd937x.c
>> @@ -2046,9 +2046,9 @@ static const struct snd_kcontrol_new wcd937x_snd_controls[] = {
>> SOC_ENUM_EXT("RX HPH Mode", rx_hph_mode_mux_enum,
>> wcd937x_rx_hph_mode_get, wcd937x_rx_hph_mode_put),
>>
>> - SOC_SINGLE_EXT("HPHL_COMP Switch", SND_SOC_NOPM, 0, 1, 0,
>> + SOC_SINGLE_EXT("HPHL_COMP Switch", WCD937X_COMP_L, 0, 1, 0,
>> wcd937x_get_compander, wcd937x_set_compander),
>> - SOC_SINGLE_EXT("HPHR_COMP Switch", SND_SOC_NOPM, 1, 1, 0,
>> + SOC_SINGLE_EXT("HPHR_COMP Switch", WCD937X_COMP_R, 1, 1, 0,
>> wcd937x_get_compander, wcd937x_set_compander),
>>
>> SOC_SINGLE_TLV("HPHL Volume", WCD937X_HPH_L_EN, 0, 20, 1, line_gain),
>> --
>> 2.50.0
>>
>
^ permalink raw reply [flat|nested] 24+ messages in thread
* [PATCH v3 02/12] soundwire: bus: add of_sdw_find_device_by_node helper
2025-09-05 15:44 [PATCH v3 00/12] ASoC: codecs: wcd93xxx: remove code duplication Srinivas Kandagatla
2025-09-05 15:44 ` [PATCH v3 01/12] ASoC: codecs: wcd937x: set the comp soundwire port correctly Srinivas Kandagatla
@ 2025-09-05 15:44 ` Srinivas Kandagatla
2025-09-05 15:44 ` [PATCH v3 03/12] soundwire: bus: add sdw_slave_get_current_bank helper Srinivas Kandagatla
` (9 subsequent siblings)
11 siblings, 0 replies; 24+ messages in thread
From: Srinivas Kandagatla @ 2025-09-05 15:44 UTC (permalink / raw)
To: broonie
Cc: lgirdwood, tiwai, vkoul, srini, yung-chuan.liao,
pierre-louis.bossart, linux-arm-msm, linux-kernel, neil.armstrong,
krzysztof.kozlowski, dmitry.baryshkov, linux-sound,
Srinivas Kandagatla
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>
Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
Acked-by: Vinod Koul <vkoul@kernel.org>
---
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 0832776262ac..096213956d31 100644
--- a/include/linux/soundwire/sdw.h
+++ b/include/linux/soundwire/sdw.h
@@ -19,6 +19,7 @@
struct dentry;
struct fwnode_handle;
+struct device_node;
struct sdw_bus;
struct sdw_slave;
@@ -1086,6 +1087,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 */
@@ -1119,6 +1122,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.50.0
^ permalink raw reply related [flat|nested] 24+ messages in thread* [PATCH v3 03/12] soundwire: bus: add sdw_slave_get_current_bank helper
2025-09-05 15:44 [PATCH v3 00/12] ASoC: codecs: wcd93xxx: remove code duplication Srinivas Kandagatla
2025-09-05 15:44 ` [PATCH v3 01/12] ASoC: codecs: wcd937x: set the comp soundwire port correctly Srinivas Kandagatla
2025-09-05 15:44 ` [PATCH v3 02/12] soundwire: bus: add of_sdw_find_device_by_node helper Srinivas Kandagatla
@ 2025-09-05 15:44 ` Srinivas Kandagatla
2025-09-05 16:42 ` Dmitry Baryshkov
2025-09-05 15:44 ` [PATCH v3 04/12] ASoC: codecs: wcdxxxx: use of_sdw_find_device_by_node helper Srinivas Kandagatla
` (8 subsequent siblings)
11 siblings, 1 reply; 24+ messages in thread
From: Srinivas Kandagatla @ 2025-09-05 15:44 UTC (permalink / raw)
To: broonie
Cc: lgirdwood, tiwai, vkoul, srini, yung-chuan.liao,
pierre-louis.bossart, linux-arm-msm, linux-kernel, neil.armstrong,
krzysztof.kozlowski, dmitry.baryshkov, linux-sound,
Srinivas Kandagatla
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>
Acked-by: Vinod Koul <vkoul@kernel.org>
---
drivers/soundwire/bus.c | 12 ++++++++++++
include/linux/soundwire/sdw.h | 8 ++++++++
2 files changed, 20 insertions(+)
diff --git a/drivers/soundwire/bus.c b/drivers/soundwire/bus.c
index 4fd5cac799c5..55c1db816534 100644
--- a/drivers/soundwire/bus.c
+++ b/drivers/soundwire/bus.c
@@ -1360,6 +1360,18 @@ 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 *slave)
+{
+ int tmp;
+
+ tmp = sdw_read(slave, SDW_SCP_CTRL);
+ if (tmp < 0)
+ return tmp;
+
+ return FIELD_GET(SDW_SCP_STAT_CURR_BANK, tmp);
+}
+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 096213956d31..e6a3476bcef1 100644
--- a/include/linux/soundwire/sdw.h
+++ b/include/linux/soundwire/sdw.h
@@ -1089,6 +1089,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 */
@@ -1128,6 +1130,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.50.0
^ permalink raw reply related [flat|nested] 24+ messages in thread* Re: [PATCH v3 03/12] soundwire: bus: add sdw_slave_get_current_bank helper
2025-09-05 15:44 ` [PATCH v3 03/12] soundwire: bus: add sdw_slave_get_current_bank helper Srinivas Kandagatla
@ 2025-09-05 16:42 ` Dmitry Baryshkov
0 siblings, 0 replies; 24+ messages in thread
From: Dmitry Baryshkov @ 2025-09-05 16:42 UTC (permalink / raw)
To: Srinivas Kandagatla
Cc: broonie, lgirdwood, tiwai, vkoul, srini, yung-chuan.liao,
pierre-louis.bossart, linux-arm-msm, linux-kernel, neil.armstrong,
krzysztof.kozlowski, linux-sound
On Fri, Sep 05, 2025 at 04:44:21PM +0100, Srinivas Kandagatla wrote:
> 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>
> Acked-by: Vinod Koul <vkoul@kernel.org>
> ---
> drivers/soundwire/bus.c | 12 ++++++++++++
> include/linux/soundwire/sdw.h | 8 ++++++++
> 2 files changed, 20 insertions(+)
>
Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
--
With best wishes
Dmitry
^ permalink raw reply [flat|nested] 24+ messages in thread
* [PATCH v3 04/12] ASoC: codecs: wcdxxxx: use of_sdw_find_device_by_node helper
2025-09-05 15:44 [PATCH v3 00/12] ASoC: codecs: wcd93xxx: remove code duplication Srinivas Kandagatla
` (2 preceding siblings ...)
2025-09-05 15:44 ` [PATCH v3 03/12] soundwire: bus: add sdw_slave_get_current_bank helper Srinivas Kandagatla
@ 2025-09-05 15:44 ` Srinivas Kandagatla
2025-09-05 15:44 ` [PATCH v3 05/12] ASoC: codecs: wcdxxxx: use sdw_slave_get_current_bank helper Srinivas Kandagatla
` (7 subsequent siblings)
11 siblings, 0 replies; 24+ messages in thread
From: Srinivas Kandagatla @ 2025-09-05 15:44 UTC (permalink / raw)
To: broonie
Cc: lgirdwood, tiwai, vkoul, srini, yung-chuan.liao,
pierre-louis.bossart, linux-arm-msm, linux-kernel, neil.armstrong,
krzysztof.kozlowski, dmitry.baryshkov, linux-sound,
Srinivas Kandagatla
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>
Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@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 de2dff3c56d3..b78f37c582ca 100644
--- a/sound/soc/codecs/wcd937x.c
+++ b/sound/soc/codecs/wcd937x.c
@@ -2788,7 +2788,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;
@@ -2797,7 +2797,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 3ab21bb5846e..49e5dce6f8c9 100644
--- a/sound/soc/codecs/wcd937x.h
+++ b/sound/soc/codecs/wcd937x.h
@@ -549,8 +549,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 e822cc145250..a7514d716086 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 711f373ece24..e2cb0758bca7 100644
--- a/sound/soc/codecs/wcd938x.c
+++ b/sound/soc/codecs/wcd938x.c
@@ -3400,7 +3400,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;
@@ -3409,7 +3409,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 64f082e474c1..5a56c79a8922 100644
--- a/sound/soc/codecs/wcd939x.c
+++ b/sound/soc/codecs/wcd939x.c
@@ -3383,7 +3383,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;
@@ -3392,7 +3392,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.50.0
^ permalink raw reply related [flat|nested] 24+ messages in thread* [PATCH v3 05/12] ASoC: codecs: wcdxxxx: use sdw_slave_get_current_bank helper
2025-09-05 15:44 [PATCH v3 00/12] ASoC: codecs: wcd93xxx: remove code duplication Srinivas Kandagatla
` (3 preceding siblings ...)
2025-09-05 15:44 ` [PATCH v3 04/12] ASoC: codecs: wcdxxxx: use of_sdw_find_device_by_node helper Srinivas Kandagatla
@ 2025-09-05 15:44 ` Srinivas Kandagatla
2025-09-05 15:44 ` [PATCH v3 06/12] ASoC: codecs: wcd: add common helper for wcd codecs Srinivas Kandagatla
` (6 subsequent siblings)
11 siblings, 0 replies; 24+ messages in thread
From: Srinivas Kandagatla @ 2025-09-05 15:44 UTC (permalink / raw)
To: broonie
Cc: lgirdwood, tiwai, vkoul, srini, yung-chuan.liao,
pierre-louis.bossart, linux-arm-msm, linux-kernel, neil.armstrong,
krzysztof.kozlowski, dmitry.baryshkov, linux-sound,
Srinivas Kandagatla
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>
Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
Acked-by: Vinod Koul <vkoul@kernel.org>
---
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 a7514d716086..8bcd8396f375 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 e2cb0758bca7..f8d7bf27a6ed 100644
--- a/sound/soc/codecs/wcd938x.c
+++ b/sound/soc/codecs/wcd938x.c
@@ -1094,8 +1094,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 5a56c79a8922..85730ae40c2c 100644
--- a/sound/soc/codecs/wcd939x.c
+++ b/sound/soc/codecs/wcd939x.c
@@ -1017,7 +1017,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.50.0
^ permalink raw reply related [flat|nested] 24+ messages in thread* [PATCH v3 06/12] ASoC: codecs: wcd: add common helper for wcd codecs
2025-09-05 15:44 [PATCH v3 00/12] ASoC: codecs: wcd93xxx: remove code duplication Srinivas Kandagatla
` (4 preceding siblings ...)
2025-09-05 15:44 ` [PATCH v3 05/12] ASoC: codecs: wcdxxxx: use sdw_slave_get_current_bank helper Srinivas Kandagatla
@ 2025-09-05 15:44 ` Srinivas Kandagatla
2025-09-05 16:42 ` Dmitry Baryshkov
2025-09-06 20:23 ` kernel test robot
2025-09-05 15:44 ` [PATCH v3 07/12] ASoC: codecs: wcd-common: move WCD_SDW_CH to common Srinivas Kandagatla
` (5 subsequent siblings)
11 siblings, 2 replies; 24+ messages in thread
From: Srinivas Kandagatla @ 2025-09-05 15:44 UTC (permalink / raw)
To: broonie
Cc: lgirdwood, tiwai, vkoul, srini, yung-chuan.liao,
pierre-louis.bossart, linux-arm-msm, linux-kernel, neil.armstrong,
krzysztof.kozlowski, dmitry.baryshkov, linux-sound,
Srinivas Kandagatla
All the Qualcomm WCD codecs have most of its code duplicated across all
these 3/4 drivers. This is an attempt to remove those duplicate
parts by adding a common helper library for these codecs.
To start with move all the micbias parsing and voltage settings these
are identical in WCD934x, WCD937x, WCD938x and WCD939x codec driver.
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
---
sound/soc/codecs/Kconfig | 8 ++++
sound/soc/codecs/Makefile | 2 +
sound/soc/codecs/wcd-common.c | 70 +++++++++++++++++++++++++++
sound/soc/codecs/wcd-common.h | 27 +++++++++++
sound/soc/codecs/wcd934x.c | 82 +++++++++----------------------
sound/soc/codecs/wcd937x.c | 75 +++++++----------------------
sound/soc/codecs/wcd937x.h | 6 +--
sound/soc/codecs/wcd938x.c | 88 +++++++---------------------------
sound/soc/codecs/wcd939x.c | 90 +++++++----------------------------
9 files changed, 183 insertions(+), 265 deletions(-)
create mode 100644 sound/soc/codecs/wcd-common.c
create mode 100644 sound/soc/codecs/wcd-common.h
diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig
index b8d58d2fe326..f8476914e4ba 100644
--- a/sound/soc/codecs/Kconfig
+++ b/sound/soc/codecs/Kconfig
@@ -2251,12 +2251,16 @@ config SND_SOC_UDA1380
config SND_SOC_WCD_CLASSH
tristate
+config SND_SOC_WCD_COMMON
+ tristate
+
config SND_SOC_WCD9335
tristate "WCD9335 Codec"
depends on SLIMBUS
select REGMAP_SLIMBUS
select REGMAP_IRQ
select SND_SOC_WCD_CLASSH
+ select SND_SOC_WCD_COMMON
help
The WCD9335 is a standalone Hi-Fi audio CODEC IC, supports
Qualcomm Technologies, Inc. (QTI) multimedia solutions,
@@ -2272,6 +2276,7 @@ config SND_SOC_WCD934X
select REGMAP_IRQ
select REGMAP_SLIMBUS
select SND_SOC_WCD_CLASSH
+ select SND_SOC_WCD_COMMON
select SND_SOC_WCD_MBHC
depends on MFD_WCD934X || COMPILE_TEST
help
@@ -2283,6 +2288,7 @@ config SND_SOC_WCD937X
tristate
depends on SOUNDWIRE || !SOUNDWIRE
select SND_SOC_WCD_CLASSH
+ select SND_SOC_WCD_COMMON
config SND_SOC_WCD937X_SDW
tristate "WCD9370/WCD9375 Codec - SDW"
@@ -2302,6 +2308,7 @@ config SND_SOC_WCD938X
tristate
depends on SOUNDWIRE || !SOUNDWIRE
select SND_SOC_WCD_CLASSH
+ select SND_SOC_WCD_COMMON
select MULTIPLEXER
config SND_SOC_WCD938X_SDW
@@ -2321,6 +2328,7 @@ config SND_SOC_WCD939X
depends on SOUNDWIRE || !SOUNDWIRE
depends on TYPEC || !TYPEC
select SND_SOC_WCD_CLASSH
+ select SND_SOC_WCD_COMMON
config SND_SOC_WCD939X_SDW
tristate "WCD9390/WCD9395 Codec - SDW"
diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile
index a476d6c45451..8d9bc03ecc60 100644
--- a/sound/soc/codecs/Makefile
+++ b/sound/soc/codecs/Makefile
@@ -341,6 +341,7 @@ snd-soc-uda1334-y := uda1334.o
snd-soc-uda1342-y := uda1342.o
snd-soc-uda1380-y := uda1380.o
snd-soc-wcd-classh-y := wcd-clsh-v2.o
+snd-soc-wcd-common-y := wcd-common.o
snd-soc-wcd-mbhc-y := wcd-mbhc-v2.o
snd-soc-wcd9335-y := wcd9335.o
snd-soc-wcd934x-y := wcd934x.o
@@ -764,6 +765,7 @@ obj-$(CONFIG_SND_SOC_UDA1334) += snd-soc-uda1334.o
obj-$(CONFIG_SND_SOC_UDA1342) += snd-soc-uda1342.o
obj-$(CONFIG_SND_SOC_UDA1380) += snd-soc-uda1380.o
obj-$(CONFIG_SND_SOC_WCD_CLASSH) += snd-soc-wcd-classh.o
+obj-$(CONFIG_SND_SOC_WCD_COMMON) += snd-soc-wcd-common.o
obj-$(CONFIG_SND_SOC_WCD_MBHC) += snd-soc-wcd-mbhc.o
obj-$(CONFIG_SND_SOC_WCD9335) += snd-soc-wcd9335.o
obj-$(CONFIG_SND_SOC_WCD934X) += snd-soc-wcd934x.o
diff --git a/sound/soc/codecs/wcd-common.c b/sound/soc/codecs/wcd-common.c
new file mode 100644
index 000000000000..25c0a48ff858
--- /dev/null
+++ b/sound/soc/codecs/wcd-common.c
@@ -0,0 +1,70 @@
+// SPDX-License-Identifier: GPL-2.0-only
+// Copyright (c) 2025, Qualcomm Technologies, Inc. and/or its subsidiaries.
+
+#include <linux/export.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/device.h>
+#include <linux/of.h>
+#include <linux/printk.h>
+
+#include "wcd-common.h"
+
+#define WCD_MIN_MICBIAS_MV 1000
+#define WCD_DEF_MICBIAS_MV 1800
+#define WCD_MAX_MICBIAS_MV 2850
+
+int wcd_get_micb_vout_ctl_val(struct device *dev, u32 micb_mv)
+{
+ /* min micbias voltage is 1V and maximum is 2.85V */
+ if (micb_mv < WCD_MIN_MICBIAS_MV || micb_mv > WCD_MAX_MICBIAS_MV) {
+ dev_err(dev, "Unsupported micbias voltage (%u mV)\n", micb_mv);
+ return -EINVAL;
+ }
+
+ return (micb_mv - WCD_MIN_MICBIAS_MV) / 50;
+}
+EXPORT_SYMBOL_GPL(wcd_get_micb_vout_ctl_val);
+
+static int wcd_get_micbias_val(struct device *dev, int micb_num, u32 *micb_mv)
+{
+ char micbias[32];
+ int mv;
+
+ sprintf(micbias, "qcom,micbias%d-microvolt", micb_num);
+
+ if (of_property_read_u32(dev->of_node, micbias, &mv)) {
+ dev_err(dev, "%s value not found, using default\n", micbias);
+ mv = WCD_DEF_MICBIAS_MV;
+ } else {
+ /* convert it to milli volts */
+ mv = mv/1000;
+ }
+ if (micb_mv)
+ *micb_mv = mv;
+
+ mv = wcd_get_micb_vout_ctl_val(dev, mv);
+ if (mv < 0) {
+ dev_err(dev, "Unsupported %s voltage (%d mV), falling back to default (%d mV)\n",
+ micbias, mv, WCD_DEF_MICBIAS_MV);
+ return wcd_get_micb_vout_ctl_val(dev, WCD_DEF_MICBIAS_MV);
+ }
+
+ return mv;
+}
+
+int wcd_dt_parse_micbias_info(struct wcd_common *common)
+{
+ int i;
+
+ for (i = 0; i < common->max_bias; i++) {
+ common->micb_vout[i] = wcd_get_micbias_val(common->dev, i+1, &common->micb_mv[i]);
+ if (common->micb_vout[i] < 0)
+ return -EINVAL;
+ }
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(wcd_dt_parse_micbias_info);
+MODULE_DESCRIPTION("Common Qualcomm WCD Codec helpers driver");
+MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/wcd-common.h b/sound/soc/codecs/wcd-common.h
new file mode 100644
index 000000000000..42d84e42d40f
--- /dev/null
+++ b/sound/soc/codecs/wcd-common.h
@@ -0,0 +1,27 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (c) 2025, Qualcomm Technologies, Inc. and/or its subsidiaries.
+ */
+
+#ifndef __WCD_COMMON_H__
+#define __WCD_COMMON_H___
+
+struct device;
+struct sdw_slave;
+struct sdw_bus_params;
+struct irq_domain;
+enum sdw_slave_status;
+
+#define WCD_MAX_MICBIAS 4
+
+struct wcd_common {
+ struct device *dev;
+ int max_bias;
+ u32 micb_mv[WCD_MAX_MICBIAS];
+ u32 micb_vout[WCD_MAX_MICBIAS];
+};
+
+int wcd_get_micb_vout_ctl_val(struct device *dev, u32 micb_mv);
+int wcd_dt_parse_micbias_info(struct wcd_common *common);
+
+#endif /* __WCD_COMMON_H___ */
diff --git a/sound/soc/codecs/wcd934x.c b/sound/soc/codecs/wcd934x.c
index 1bb7e1dc7e6b..d10b457e6c9a 100644
--- a/sound/soc/codecs/wcd934x.c
+++ b/sound/soc/codecs/wcd934x.c
@@ -21,6 +21,7 @@
#include <sound/soc-dapm.h>
#include <sound/tlv.h>
#include "wcd-clsh-v2.h"
+#include "wcd-common.h"
#include "wcd-mbhc-v2.h"
#include <dt-bindings/sound/qcom,wcd934x.h>
@@ -116,9 +117,6 @@
#define WCD934X_DEC_PWR_LVL_DF 0x00
#define WCD934X_DEC_PWR_LVL_HYBRID WCD934X_DEC_PWR_LVL_DF
-#define WCD934X_DEF_MICBIAS_MV 1800
-#define WCD934X_MAX_MICBIAS_MV 2850
-
#define WCD_IIR_FILTER_SIZE (sizeof(u32) * BAND_MAX)
#define WCD_IIR_FILTER_CTL(xname, iidx, bidx) \
@@ -530,6 +528,7 @@ struct wcd934x_codec {
struct slim_device *sdev;
struct slim_device *sidev;
struct wcd_clsh_ctrl *clsh_ctrl;
+ struct wcd_common common;
struct snd_soc_component *component;
struct wcd934x_slim_ch rx_chs[WCD934X_RX_MAX];
struct wcd934x_slim_ch tx_chs[WCD934X_TX_MAX];
@@ -555,7 +554,6 @@ struct wcd934x_codec {
struct mutex micb_lock;
u32 micb_ref[WCD934X_MAX_MICBIAS];
u32 pullup_ref[WCD934X_MAX_MICBIAS];
- u32 micb2_mv;
};
#define to_wcd934x_codec(_hw) container_of(_hw, struct wcd934x_codec, hw)
@@ -2168,55 +2166,24 @@ static struct clk *wcd934x_register_mclk_output(struct wcd934x_codec *wcd)
return NULL;
}
-static int wcd934x_get_micbias_val(struct device *dev, const char *micbias,
- u32 *micb_mv)
-{
- int mv;
-
- if (of_property_read_u32(dev->parent->of_node, micbias, &mv)) {
- dev_err(dev, "%s value not found, using default\n", micbias);
- mv = WCD934X_DEF_MICBIAS_MV;
- } else {
- /* convert it to milli volts */
- mv = mv/1000;
- }
-
- if (mv < 1000 || mv > 2850) {
- dev_err(dev, "%s value not in valid range, using default\n",
- micbias);
- mv = WCD934X_DEF_MICBIAS_MV;
- }
-
- if (micb_mv)
- *micb_mv = mv;
-
- return (mv - 1000) / 50;
-}
-
static int wcd934x_init_dmic(struct snd_soc_component *comp)
{
- int vout_ctl_1, vout_ctl_2, vout_ctl_3, vout_ctl_4;
struct wcd934x_codec *wcd = dev_get_drvdata(comp->dev);
u32 def_dmic_rate, dmic_clk_drv;
+ int ret;
- vout_ctl_1 = wcd934x_get_micbias_val(comp->dev,
- "qcom,micbias1-microvolt", NULL);
- vout_ctl_2 = wcd934x_get_micbias_val(comp->dev,
- "qcom,micbias2-microvolt",
- &wcd->micb2_mv);
- vout_ctl_3 = wcd934x_get_micbias_val(comp->dev,
- "qcom,micbias3-microvolt", NULL);
- vout_ctl_4 = wcd934x_get_micbias_val(comp->dev,
- "qcom,micbias4-microvolt", NULL);
+ ret = wcd_dt_parse_mbhc_data(comp->dev, &wcd->mbhc_cfg);
+ if (ret)
+ return ret;
snd_soc_component_update_bits(comp, WCD934X_ANA_MICB1,
- WCD934X_MICB_VAL_MASK, vout_ctl_1);
+ WCD934X_MICB_VAL_MASK, wcd->common.micb_vout[0]);
snd_soc_component_update_bits(comp, WCD934X_ANA_MICB2,
- WCD934X_MICB_VAL_MASK, vout_ctl_2);
+ WCD934X_MICB_VAL_MASK, wcd->common.micb_vout[1]);
snd_soc_component_update_bits(comp, WCD934X_ANA_MICB3,
- WCD934X_MICB_VAL_MASK, vout_ctl_3);
+ WCD934X_MICB_VAL_MASK, wcd->common.micb_vout[2]);
snd_soc_component_update_bits(comp, WCD934X_ANA_MICB4,
- WCD934X_MICB_VAL_MASK, vout_ctl_4);
+ WCD934X_MICB_VAL_MASK, wcd->common.micb_vout[3]);
if (wcd->rate == WCD934X_MCLK_CLK_9P6MHZ)
def_dmic_rate = WCD9XXX_DMIC_SAMPLE_RATE_4P8MHZ;
@@ -2517,15 +2484,6 @@ static void wcd934x_mbhc_micb_ramp_control(struct snd_soc_component *component,
}
}
-static int wcd934x_get_micb_vout_ctl_val(u32 micb_mv)
-{
- /* min micbias voltage is 1V and maximum is 2.85V */
- if (micb_mv < 1000 || micb_mv > 2850)
- return -EINVAL;
-
- return (micb_mv - 1000) / 50;
-}
-
static int wcd934x_mbhc_micb_adjust_voltage(struct snd_soc_component *component,
int req_volt, int micb_num)
{
@@ -2562,7 +2520,7 @@ static int wcd934x_mbhc_micb_adjust_voltage(struct snd_soc_component *component,
cur_vout_ctl = snd_soc_component_read_field(component, micb_reg,
WCD934X_MICB_VAL_MASK);
- req_vout_ctl = wcd934x_get_micb_vout_ctl_val(req_volt);
+ req_vout_ctl = wcd_get_micb_vout_ctl_val(component->dev, req_volt);
if (req_vout_ctl < 0) {
ret = -EINVAL;
goto exit;
@@ -2610,10 +2568,10 @@ static int wcd934x_mbhc_micb_ctrl_threshold_mic(struct snd_soc_component *compon
* voltage needed to detect threshold microphone, then do
* not change the micbias, just return.
*/
- if (wcd934x->micb2_mv >= WCD_MBHC_THR_HS_MICB_MV)
+ if (wcd934x->common.micb_mv[1] >= WCD_MBHC_THR_HS_MICB_MV)
return 0;
- micb_mv = req_en ? WCD_MBHC_THR_HS_MICB_MV : wcd934x->micb2_mv;
+ micb_mv = req_en ? WCD_MBHC_THR_HS_MICB_MV : wcd934x->common.micb_mv[1];
rc = wcd934x_mbhc_micb_adjust_voltage(component, micb_mv, MIC_BIAS_2);
@@ -3036,7 +2994,7 @@ static void wcd934x_mbhc_deinit(struct snd_soc_component *component)
static int wcd934x_comp_probe(struct snd_soc_component *component)
{
struct wcd934x_codec *wcd = dev_get_drvdata(component->dev);
- int i;
+ int i, ret;
snd_soc_component_init_regmap(component, wcd->regmap);
wcd->component = component;
@@ -3054,7 +3012,12 @@ static int wcd934x_comp_probe(struct snd_soc_component *component)
for (i = 0; i < NUM_CODEC_DAIS; i++)
INIT_LIST_HEAD(&wcd->dai[i].slim_ch_list);
- wcd934x_init_dmic(component);
+
+ ret = wcd934x_init_dmic(component);
+ if (ret) {
+ dev_err(component->dev, "Failed to Initialize micbias\n");
+ return ret;
+ }
if (wcd934x_mbhc_init(component))
dev_err(component->dev, "Failed to Initialize MBHC\n");
@@ -5860,14 +5823,13 @@ static int wcd934x_codec_parse_data(struct wcd934x_codec *wcd)
cfg->anc_micbias = MIC_BIAS_2;
cfg->v_hs_max = WCD_MBHC_HS_V_MAX;
cfg->num_btn = WCD934X_MBHC_MAX_BUTTONS;
- cfg->micb_mv = wcd->micb2_mv;
+ cfg->micb_mv = wcd->common.micb_mv[1];
cfg->linein_th = 5000;
cfg->hs_thr = 1700;
cfg->hph_thr = 50;
wcd_dt_parse_mbhc_data(dev, cfg);
-
return 0;
}
@@ -5888,6 +5850,8 @@ static int wcd934x_codec_probe(struct platform_device *pdev)
wcd->sdev = to_slim_device(data->dev);
mutex_init(&wcd->sysclk_mutex);
mutex_init(&wcd->micb_lock);
+ wcd->common.dev = dev->parent;
+ wcd->common.max_bias = 4;
ret = wcd934x_codec_parse_data(wcd);
if (ret)
diff --git a/sound/soc/codecs/wcd937x.c b/sound/soc/codecs/wcd937x.c
index b78f37c582ca..5c8faff3976d 100644
--- a/sound/soc/codecs/wcd937x.c
+++ b/sound/soc/codecs/wcd937x.c
@@ -21,6 +21,7 @@
#include <sound/tlv.h>
#include "wcd-clsh-v2.h"
+#include "wcd-common.h"
#include "wcd-mbhc-v2.h"
#include "wcd937x.h"
@@ -85,6 +86,7 @@ struct wcd937x_priv {
struct wcd_mbhc_config mbhc_cfg;
struct wcd_mbhc_intr intr_ids;
struct wcd_clsh_ctrl *clsh_info;
+ struct wcd_common common;
struct irq_domain *virq;
struct regmap_irq_chip_data *irq_chip;
struct snd_soc_jack *jack;
@@ -93,9 +95,6 @@ struct wcd937x_priv {
s32 pullup_ref[WCD937X_MAX_MICBIAS];
u32 hph_mode;
int ear_rx_path;
- u32 micb1_mv;
- u32 micb2_mv;
- u32 micb3_mv;
int hphr_pdm_wd_int;
int hphl_pdm_wd_int;
int aux_pdm_wd_int;
@@ -872,15 +871,6 @@ static int wcd937x_enable_rx3(struct snd_soc_dapm_widget *w,
return 0;
}
-static int wcd937x_get_micb_vout_ctl_val(u32 micb_mv)
-{
- if (micb_mv < 1000 || micb_mv > 2850) {
- pr_err("Unsupported micbias voltage (%u mV)\n", micb_mv);
- return -EINVAL;
- }
-
- return (micb_mv - 1000) / 50;
-}
static int wcd937x_tx_swr_ctrl(struct snd_soc_dapm_widget *w,
struct snd_kcontrol *kcontrol, int event)
@@ -1481,7 +1471,7 @@ static int wcd937x_mbhc_micb_adjust_voltage(struct snd_soc_component *component,
cur_vout_ctl = snd_soc_component_read_field(component, micb_reg,
WCD937X_MICB_VOUT_MASK);
- req_vout_ctl = wcd937x_get_micb_vout_ctl_val(req_volt);
+ req_vout_ctl = wcd_get_micb_vout_ctl_val(component->dev, req_volt);
if (req_vout_ctl < 0) {
ret = -EINVAL;
goto exit;
@@ -2436,22 +2426,14 @@ static const struct snd_soc_dapm_route wcd9375_audio_map[] = {
{ "DMIC6_MIXER", "Switch", "DMIC6" },
};
-static int wcd937x_set_micbias_data(struct wcd937x_priv *wcd937x)
+static void wcd937x_set_micbias_data(struct device *dev, struct wcd937x_priv *wcd937x)
{
- int vout_ctl[3];
-
- /* Set micbias voltage */
- vout_ctl[0] = wcd937x_get_micb_vout_ctl_val(wcd937x->micb1_mv);
- vout_ctl[1] = wcd937x_get_micb_vout_ctl_val(wcd937x->micb2_mv);
- vout_ctl[2] = wcd937x_get_micb_vout_ctl_val(wcd937x->micb3_mv);
- if ((vout_ctl[0] | vout_ctl[1] | vout_ctl[2]) < 0)
- return -EINVAL;
-
- regmap_update_bits(wcd937x->regmap, WCD937X_ANA_MICB1, WCD937X_ANA_MICB_VOUT, vout_ctl[0]);
- regmap_update_bits(wcd937x->regmap, WCD937X_ANA_MICB2, WCD937X_ANA_MICB_VOUT, vout_ctl[1]);
- regmap_update_bits(wcd937x->regmap, WCD937X_ANA_MICB3, WCD937X_ANA_MICB_VOUT, vout_ctl[2]);
-
- return 0;
+ regmap_update_bits(wcd937x->regmap, WCD937X_ANA_MICB1, WCD937X_ANA_MICB_VOUT,
+ wcd937x->commmon.micb_vout[0]);
+ regmap_update_bits(wcd937x->regmap, WCD937X_ANA_MICB2, WCD937X_ANA_MICB_VOUT,
+ wcd937x->commmon.micb_vout[1]);
+ regmap_update_bits(wcd937x->regmap, WCD937X_ANA_MICB3, WCD937X_ANA_MICB_VOUT,
+ wcd937x->commmon.micb_vout[2]);
}
static irqreturn_t wcd937x_wd_handle_irq(int irq, void *data)
@@ -2630,31 +2612,6 @@ static const struct snd_soc_component_driver soc_codec_dev_wcd937x = {
.endianness = 1,
};
-static void wcd937x_dt_parse_micbias_info(struct device *dev, struct wcd937x_priv *wcd)
-{
- struct device_node *np = dev->of_node;
- u32 prop_val = 0;
- int ret = 0;
-
- ret = of_property_read_u32(np, "qcom,micbias1-microvolt", &prop_val);
- if (!ret)
- wcd->micb1_mv = prop_val / 1000;
- else
- dev_warn(dev, "Micbias1 DT property not found\n");
-
- ret = of_property_read_u32(np, "qcom,micbias2-microvolt", &prop_val);
- if (!ret)
- wcd->micb2_mv = prop_val / 1000;
- else
- dev_warn(dev, "Micbias2 DT property not found\n");
-
- ret = of_property_read_u32(np, "qcom,micbias3-microvolt", &prop_val);
- if (!ret)
- wcd->micb3_mv = prop_val / 1000;
- else
- dev_warn(dev, "Micbias3 DT property not found\n");
-}
-
static bool wcd937x_swap_gnd_mic(struct snd_soc_component *component)
{
int value;
@@ -2848,11 +2805,7 @@ static int wcd937x_bind(struct device *dev)
wcd937x->sdw_priv[AIF1_PB]->slave_irq = wcd937x->virq;
wcd937x->sdw_priv[AIF1_CAP]->slave_irq = wcd937x->virq;
- ret = wcd937x_set_micbias_data(wcd937x);
- if (ret < 0) {
- dev_err(dev, "Bad micbias pdata\n");
- return ret;
- }
+ wcd937x_set_micbias_data(dev, wcd937x);
ret = snd_soc_register_component(dev, &soc_codec_dev_wcd937x,
wcd937x_dais, ARRAY_SIZE(wcd937x_dais));
@@ -2920,6 +2873,8 @@ static int wcd937x_probe(struct platform_device *pdev)
dev_set_drvdata(dev, wcd937x);
mutex_init(&wcd937x->micb_lock);
+ wcd937x->common.dev = dev;
+ wcd937x->common.max_bias = 3;
wcd937x->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW);
if (IS_ERR(wcd937x->reset_gpio))
@@ -2939,7 +2894,9 @@ static int wcd937x_probe(struct platform_device *pdev)
if (ret)
return dev_err_probe(dev, ret, "Failed to get and enable supplies\n");
- wcd937x_dt_parse_micbias_info(dev, wcd937x);
+ ret = wcd_dt_parse_micbias_info(dev, &wcd937x->common);
+ if (ret)
+ return dev_err_probe(dev, ret, "Failed to get micbias\n");
cfg->mbhc_micbias = MIC_BIAS_2;
cfg->anc_micbias = MIC_BIAS_2;
diff --git a/sound/soc/codecs/wcd937x.h b/sound/soc/codecs/wcd937x.h
index 49e5dce6f8c9..0f96b7108a7e 100644
--- a/sound/soc/codecs/wcd937x.h
+++ b/sound/soc/codecs/wcd937x.h
@@ -550,21 +550,21 @@ int wcd937x_sdw_hw_params(struct wcd937x_sdw_priv *wcd,
struct snd_soc_dai *dai);
#else
-int wcd937x_sdw_free(struct wcd937x_sdw_priv *wcd,
+static inline int wcd937x_sdw_free(struct wcd937x_sdw_priv *wcd,
struct snd_pcm_substream *substream,
struct snd_soc_dai *dai)
{
return -EOPNOTSUPP;
}
-int wcd937x_sdw_set_sdw_stream(struct wcd937x_sdw_priv *wcd,
+static inline int wcd937x_sdw_set_sdw_stream(struct wcd937x_sdw_priv *wcd,
struct snd_soc_dai *dai,
void *stream, int direction)
{
return -EOPNOTSUPP;
}
-int wcd937x_sdw_hw_params(struct wcd937x_sdw_priv *wcd,
+static inline int wcd937x_sdw_hw_params(struct wcd937x_sdw_priv *wcd,
struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *params,
struct snd_soc_dai *dai)
diff --git a/sound/soc/codecs/wcd938x.c b/sound/soc/codecs/wcd938x.c
index f8d7bf27a6ed..c8b6e543986d 100644
--- a/sound/soc/codecs/wcd938x.c
+++ b/sound/soc/codecs/wcd938x.c
@@ -22,6 +22,7 @@
#include <linux/regulator/consumer.h>
#include "wcd-clsh-v2.h"
+#include "wcd-common.h"
#include "wcd-mbhc-v2.h"
#include "wcd938x.h"
@@ -155,6 +156,7 @@ struct wcd938x_priv {
struct wcd_mbhc_config mbhc_cfg;
struct wcd_mbhc_intr intr_ids;
struct wcd_clsh_ctrl *clsh_info;
+ struct wcd_common common;
struct irq_domain *virq;
struct regmap_irq_chip_data *irq_chip;
struct snd_soc_jack *jack;
@@ -169,10 +171,6 @@ struct wcd938x_priv {
struct gpio_desc *us_euro_gpio;
struct mux_control *us_euro_mux;
unsigned int mux_state;
- u32 micb1_mv;
- u32 micb2_mv;
- u32 micb3_mv;
- u32 micb4_mv;
int hphr_pdm_wd_int;
int hphl_pdm_wd_int;
int aux_pdm_wd_int;
@@ -1974,15 +1972,6 @@ static void wcd938x_mbhc_micb_ramp_control(struct snd_soc_component *component,
}
}
-static int wcd938x_get_micb_vout_ctl_val(u32 micb_mv)
-{
- /* min micbias voltage is 1V and maximum is 2.85V */
- if (micb_mv < 1000 || micb_mv > 2850)
- return -EINVAL;
-
- return (micb_mv - 1000) / 50;
-}
-
static int wcd938x_mbhc_micb_adjust_voltage(struct snd_soc_component *component,
int req_volt, int micb_num)
{
@@ -2019,7 +2008,7 @@ static int wcd938x_mbhc_micb_adjust_voltage(struct snd_soc_component *component,
cur_vout_ctl = snd_soc_component_read_field(component, micb_reg,
WCD938X_MICB_VOUT_MASK);
- req_vout_ctl = wcd938x_get_micb_vout_ctl_val(req_volt);
+ req_vout_ctl = wcd_get_micb_vout_ctl_val(component->dev, req_volt);
if (req_vout_ctl < 0) {
ret = -EINVAL;
goto exit;
@@ -2067,10 +2056,10 @@ static int wcd938x_mbhc_micb_ctrl_threshold_mic(struct snd_soc_component *compon
* voltage needed to detect threshold microphone, then do
* not change the micbias, just return.
*/
- if (wcd938x->micb2_mv >= WCD_MBHC_THR_HS_MICB_MV)
+ if (wcd938x->common.micb_mv[2] >= WCD_MBHC_THR_HS_MICB_MV)
return 0;
- micb_mv = req_en ? WCD_MBHC_THR_HS_MICB_MV : wcd938x->micb2_mv;
+ micb_mv = req_en ? WCD_MBHC_THR_HS_MICB_MV : wcd938x->common.micb_mv[2];
return wcd938x_mbhc_micb_adjust_voltage(component, micb_mv, MIC_BIAS_2);
}
@@ -2975,28 +2964,16 @@ static const struct snd_soc_dapm_route wcd938x_audio_map[] = {
{"EAR", NULL, "EAR PGA"},
};
-static int wcd938x_set_micbias_data(struct wcd938x_priv *wcd938x)
+static void wcd938x_set_micbias_data(struct device *dev, struct wcd938x_priv *wcd938x)
{
- int vout_ctl_1, vout_ctl_2, vout_ctl_3, vout_ctl_4;
-
- /* set micbias voltage */
- vout_ctl_1 = wcd938x_get_micb_vout_ctl_val(wcd938x->micb1_mv);
- vout_ctl_2 = wcd938x_get_micb_vout_ctl_val(wcd938x->micb2_mv);
- vout_ctl_3 = wcd938x_get_micb_vout_ctl_val(wcd938x->micb3_mv);
- vout_ctl_4 = wcd938x_get_micb_vout_ctl_val(wcd938x->micb4_mv);
- if (vout_ctl_1 < 0 || vout_ctl_2 < 0 || vout_ctl_3 < 0 || vout_ctl_4 < 0)
- return -EINVAL;
-
regmap_update_bits(wcd938x->regmap, WCD938X_ANA_MICB1,
- WCD938X_MICB_VOUT_MASK, vout_ctl_1);
+ WCD938X_MICB_VOUT_MASK, wcd938x->common.micb_vout[0]);
regmap_update_bits(wcd938x->regmap, WCD938X_ANA_MICB2,
- WCD938X_MICB_VOUT_MASK, vout_ctl_2);
+ WCD938X_MICB_VOUT_MASK, wcd938x->common.micb_vout[1]);
regmap_update_bits(wcd938x->regmap, WCD938X_ANA_MICB3,
- WCD938X_MICB_VOUT_MASK, vout_ctl_3);
+ WCD938X_MICB_VOUT_MASK, wcd938x->common.micb_vout[2]);
regmap_update_bits(wcd938x->regmap, WCD938X_ANA_MICB4,
- WCD938X_MICB_VOUT_MASK, vout_ctl_4);
-
- return 0;
+ WCD938X_MICB_VOUT_MASK, wcd938x->common.micb_vout[3]);
}
static irqreturn_t wcd938x_wd_handle_irq(int irq, void *data)
@@ -3200,37 +3177,6 @@ static const struct snd_soc_component_driver soc_codec_dev_wcd938x = {
.endianness = 1,
};
-static void wcd938x_dt_parse_micbias_info(struct device *dev, struct wcd938x_priv *wcd)
-{
- struct device_node *np = dev->of_node;
- u32 prop_val = 0;
- int rc = 0;
-
- rc = of_property_read_u32(np, "qcom,micbias1-microvolt", &prop_val);
- if (!rc)
- wcd->micb1_mv = prop_val/1000;
- else
- dev_info(dev, "%s: Micbias1 DT property not found\n", __func__);
-
- rc = of_property_read_u32(np, "qcom,micbias2-microvolt", &prop_val);
- if (!rc)
- wcd->micb2_mv = prop_val/1000;
- else
- dev_info(dev, "%s: Micbias2 DT property not found\n", __func__);
-
- rc = of_property_read_u32(np, "qcom,micbias3-microvolt", &prop_val);
- if (!rc)
- wcd->micb3_mv = prop_val/1000;
- else
- dev_info(dev, "%s: Micbias3 DT property not found\n", __func__);
-
- rc = of_property_read_u32(np, "qcom,micbias4-microvolt", &prop_val);
- if (!rc)
- wcd->micb4_mv = prop_val/1000;
- else
- dev_info(dev, "%s: Micbias4 DT property not found\n", __func__);
-}
-
static bool wcd938x_swap_gnd_mic(struct snd_soc_component *component)
{
struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
@@ -3295,13 +3241,15 @@ static int wcd938x_populate_dt_data(struct wcd938x_priv *wcd938x, struct device
if (ret)
return dev_err_probe(dev, ret, "Failed to get and enable supplies\n");
- wcd938x_dt_parse_micbias_info(dev, wcd938x);
+ ret = wcd_dt_parse_micbias_info(&wcd938x->common);
+ if (ret)
+ return dev_err_probe(dev, ret, "Failed to get and enable supplies\n");
cfg->mbhc_micbias = MIC_BIAS_2;
cfg->anc_micbias = MIC_BIAS_2;
cfg->v_hs_max = WCD_MBHC_HS_V_MAX;
cfg->num_btn = WCD938X_MBHC_MAX_BUTTONS;
- cfg->micb_mv = wcd938x->micb2_mv;
+ cfg->micb_mv = wcd938x->common.micb_mv[2];
cfg->linein_th = 5000;
cfg->hs_thr = 1700;
cfg->hph_thr = 50;
@@ -3457,11 +3405,7 @@ static int wcd938x_bind(struct device *dev)
wcd938x->sdw_priv[AIF1_PB]->slave_irq = wcd938x->virq;
wcd938x->sdw_priv[AIF1_CAP]->slave_irq = wcd938x->virq;
- ret = wcd938x_set_micbias_data(wcd938x);
- if (ret < 0) {
- dev_err(dev, "%s: bad micbias pdata\n", __func__);
- goto err_remove_rx_link;
- }
+ wcd938x_set_micbias_data(dev, wcd938x);
ret = snd_soc_register_component(dev, &soc_codec_dev_wcd938x,
wcd938x_dais, ARRAY_SIZE(wcd938x_dais));
@@ -3550,6 +3494,8 @@ static int wcd938x_probe(struct platform_device *pdev)
dev_set_drvdata(dev, wcd938x);
mutex_init(&wcd938x->micb_lock);
+ wcd938x->common.dev = dev;
+ wcd938x->common.max_bias = 4;
ret = wcd938x_populate_dt_data(wcd938x, dev);
if (ret)
diff --git a/sound/soc/codecs/wcd939x.c b/sound/soc/codecs/wcd939x.c
index 85730ae40c2c..59c920c50c00 100644
--- a/sound/soc/codecs/wcd939x.c
+++ b/sound/soc/codecs/wcd939x.c
@@ -28,6 +28,7 @@
#include <linux/usb/typec_altmode.h>
#include "wcd-clsh-v2.h"
+#include "wcd-common.h"
#include "wcd-mbhc-v2.h"
#include "wcd939x.h"
@@ -191,6 +192,7 @@ struct wcd939x_priv {
struct wcd_mbhc_config mbhc_cfg;
struct wcd_mbhc_intr intr_ids;
struct wcd_clsh_ctrl *clsh_info;
+ struct wcd_common common;
struct irq_domain *virq;
struct regmap_irq_chip_data *irq_chip;
struct snd_soc_jack *jack;
@@ -201,10 +203,6 @@ struct wcd939x_priv {
u32 tx_mode[TX_ADC_MAX];
int variant;
struct gpio_desc *reset_gpio;
- u32 micb1_mv;
- u32 micb2_mv;
- u32 micb3_mv;
- u32 micb4_mv;
int hphr_pdm_wd_int;
int hphl_pdm_wd_int;
int ear_pdm_wd_int;
@@ -1919,17 +1917,6 @@ static void wcd939x_mbhc_micb_ramp_control(struct snd_soc_component *component,
}
}
-static int wcd939x_get_micb_vout_ctl_val(u32 micb_mv)
-{
- /* min micbias voltage is 1V and maximum is 2.85V */
- if (micb_mv < 1000 || micb_mv > 2850) {
- pr_err("%s: unsupported micbias voltage\n", __func__);
- return -EINVAL;
- }
-
- return (micb_mv - 1000) / 50;
-}
-
static int wcd939x_mbhc_micb_adjust_voltage(struct snd_soc_component *component,
int req_volt, int micb_num)
{
@@ -1969,7 +1956,7 @@ static int wcd939x_mbhc_micb_adjust_voltage(struct snd_soc_component *component,
cur_vout_ctl = snd_soc_component_read_field(component, micb_reg,
WCD939X_MICB_VOUT_CTL);
- req_vout_ctl = wcd939x_get_micb_vout_ctl_val(req_volt);
+ req_vout_ctl = wcd_get_micb_vout_ctl_val(component->dev, req_volt);
if (req_vout_ctl < 0) {
ret = req_vout_ctl;
goto exit;
@@ -2021,10 +2008,10 @@ static int wcd939x_mbhc_micb_ctrl_threshold_mic(struct snd_soc_component *compon
* voltage needed to detect threshold microphone, then do
* not change the micbias, just return.
*/
- if (wcd939x->micb2_mv >= WCD_MBHC_THR_HS_MICB_MV)
+ if (wcd939x->common.micb_mv[1] >= WCD_MBHC_THR_HS_MICB_MV)
return 0;
- micb_mv = req_en ? WCD_MBHC_THR_HS_MICB_MV : wcd939x->micb2_mv;
+ micb_mv = req_en ? WCD_MBHC_THR_HS_MICB_MV : wcd939x->common.micb_mv[1];
return wcd939x_mbhc_micb_adjust_voltage(component, micb_mv, MIC_BIAS_2);
}
@@ -2895,28 +2882,16 @@ static const struct snd_soc_dapm_route wcd939x_audio_map[] = {
{"EAR", NULL, "EAR PGA"},
};
-static int wcd939x_set_micbias_data(struct wcd939x_priv *wcd939x)
+static void wcd939x_set_micbias_data(struct device *dev, struct wcd939x_priv *wcd939x)
{
- int vout_ctl_1, vout_ctl_2, vout_ctl_3, vout_ctl_4;
-
- /* set micbias voltage */
- vout_ctl_1 = wcd939x_get_micb_vout_ctl_val(wcd939x->micb1_mv);
- vout_ctl_2 = wcd939x_get_micb_vout_ctl_val(wcd939x->micb2_mv);
- vout_ctl_3 = wcd939x_get_micb_vout_ctl_val(wcd939x->micb3_mv);
- vout_ctl_4 = wcd939x_get_micb_vout_ctl_val(wcd939x->micb4_mv);
- if (vout_ctl_1 < 0 || vout_ctl_2 < 0 || vout_ctl_3 < 0 || vout_ctl_4 < 0)
- return -EINVAL;
-
regmap_update_bits(wcd939x->regmap, WCD939X_ANA_MICB1,
- WCD939X_MICB_VOUT_CTL, vout_ctl_1);
+ WCD939X_MICB_VOUT_CTL, wcd939x->common.micb_vout[0]);
regmap_update_bits(wcd939x->regmap, WCD939X_ANA_MICB2,
- WCD939X_MICB_VOUT_CTL, vout_ctl_2);
+ WCD939X_MICB_VOUT_CTL, wcd939x->common.micb_vout[1]);
regmap_update_bits(wcd939x->regmap, WCD939X_ANA_MICB3,
- WCD939X_MICB_VOUT_CTL, vout_ctl_3);
+ WCD939X_MICB_VOUT_CTL, wcd939x->common.micb_vout[2]);
regmap_update_bits(wcd939x->regmap, WCD939X_ANA_MICB4,
- WCD939X_MICB_VOUT_CTL, vout_ctl_4);
-
- return 0;
+ WCD939X_MICB_VOUT_CTL, wcd939x->common.micb_vout[3]);
}
static irqreturn_t wcd939x_wd_handle_irq(int irq, void *data)
@@ -3186,37 +3161,6 @@ static int wcd939x_typec_mux_set(struct typec_mux_dev *mux,
}
#endif /* CONFIG_TYPEC */
-static void wcd939x_dt_parse_micbias_info(struct device *dev, struct wcd939x_priv *wcd)
-{
- struct device_node *np = dev->of_node;
- u32 prop_val = 0;
- int rc = 0;
-
- rc = of_property_read_u32(np, "qcom,micbias1-microvolt", &prop_val);
- if (!rc)
- wcd->micb1_mv = prop_val / 1000;
- else
- dev_info(dev, "%s: Micbias1 DT property not found\n", __func__);
-
- rc = of_property_read_u32(np, "qcom,micbias2-microvolt", &prop_val);
- if (!rc)
- wcd->micb2_mv = prop_val / 1000;
- else
- dev_info(dev, "%s: Micbias2 DT property not found\n", __func__);
-
- rc = of_property_read_u32(np, "qcom,micbias3-microvolt", &prop_val);
- if (!rc)
- wcd->micb3_mv = prop_val / 1000;
- else
- dev_info(dev, "%s: Micbias3 DT property not found\n", __func__);
-
- rc = of_property_read_u32(np, "qcom,micbias4-microvolt", &prop_val);
- if (!rc)
- wcd->micb4_mv = prop_val / 1000;
- else
- dev_info(dev, "%s: Micbias4 DT property not found\n", __func__);
-}
-
#if IS_ENABLED(CONFIG_TYPEC)
static bool wcd939x_swap_gnd_mic(struct snd_soc_component *component)
{
@@ -3252,13 +3196,15 @@ static int wcd939x_populate_dt_data(struct wcd939x_priv *wcd939x, struct device
if (ret)
return dev_err_probe(dev, ret, "Failed to get and enable supplies\n");
- wcd939x_dt_parse_micbias_info(dev, wcd939x);
+ ret = wcd_dt_parse_micbias_info(&wcd939x->common);
+ if (ret)
+ return dev_err_probe(dev, ret, "Failed to get micbias\n");
cfg->mbhc_micbias = MIC_BIAS_2;
cfg->anc_micbias = MIC_BIAS_2;
cfg->v_hs_max = WCD_MBHC_HS_V_MAX;
cfg->num_btn = WCD939X_MBHC_MAX_BUTTONS;
- cfg->micb_mv = wcd939x->micb2_mv;
+ cfg->micb_mv = wcd939x->common.micb_mv[1];
cfg->linein_th = 5000;
cfg->hs_thr = 1700;
cfg->hph_thr = 50;
@@ -3444,11 +3390,7 @@ static int wcd939x_bind(struct device *dev)
wcd939x->sdw_priv[AIF1_PB]->slave_irq = wcd939x->virq;
wcd939x->sdw_priv[AIF1_CAP]->slave_irq = wcd939x->virq;
- ret = wcd939x_set_micbias_data(wcd939x);
- if (ret < 0) {
- dev_err(dev, "%s: bad micbias pdata\n", __func__);
- goto err_remove_rx_link;
- }
+ wcd939x_set_micbias_data(dev, wcd939x);
/* Check WCD9395 version */
regmap_read(wcd939x->regmap, WCD939X_DIGITAL_CHIP_ID1, &id1);
@@ -3613,6 +3555,8 @@ static int wcd939x_probe(struct platform_device *pdev)
dev_set_drvdata(dev, wcd939x);
mutex_init(&wcd939x->micb_lock);
+ wcd939x->common.dev = dev;
+ wcd939x->common.max_bias = 4;
ret = wcd939x_populate_dt_data(wcd939x, dev);
if (ret) {
--
2.50.0
^ permalink raw reply related [flat|nested] 24+ messages in thread* Re: [PATCH v3 06/12] ASoC: codecs: wcd: add common helper for wcd codecs
2025-09-05 15:44 ` [PATCH v3 06/12] ASoC: codecs: wcd: add common helper for wcd codecs Srinivas Kandagatla
@ 2025-09-05 16:42 ` Dmitry Baryshkov
2025-09-06 20:23 ` kernel test robot
1 sibling, 0 replies; 24+ messages in thread
From: Dmitry Baryshkov @ 2025-09-05 16:42 UTC (permalink / raw)
To: Srinivas Kandagatla
Cc: broonie, lgirdwood, tiwai, vkoul, srini, yung-chuan.liao,
pierre-louis.bossart, linux-arm-msm, linux-kernel, neil.armstrong,
krzysztof.kozlowski, linux-sound
On Fri, Sep 05, 2025 at 04:44:24PM +0100, Srinivas Kandagatla wrote:
> All the Qualcomm WCD codecs have most of its code duplicated across all
> these 3/4 drivers. This is an attempt to remove those duplicate
> parts by adding a common helper library for these codecs.
>
> To start with move all the micbias parsing and voltage settings these
> are identical in WCD934x, WCD937x, WCD938x and WCD939x codec driver.
>
> Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
> ---
> sound/soc/codecs/Kconfig | 8 ++++
> sound/soc/codecs/Makefile | 2 +
> sound/soc/codecs/wcd-common.c | 70 +++++++++++++++++++++++++++
> sound/soc/codecs/wcd-common.h | 27 +++++++++++
> sound/soc/codecs/wcd934x.c | 82 +++++++++----------------------
> sound/soc/codecs/wcd937x.c | 75 +++++++----------------------
> sound/soc/codecs/wcd937x.h | 6 +--
> sound/soc/codecs/wcd938x.c | 88 +++++++---------------------------
> sound/soc/codecs/wcd939x.c | 90 +++++++----------------------------
> 9 files changed, 183 insertions(+), 265 deletions(-)
> create mode 100644 sound/soc/codecs/wcd-common.c
> create mode 100644 sound/soc/codecs/wcd-common.h
>
Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
--
With best wishes
Dmitry
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH v3 06/12] ASoC: codecs: wcd: add common helper for wcd codecs
2025-09-05 15:44 ` [PATCH v3 06/12] ASoC: codecs: wcd: add common helper for wcd codecs Srinivas Kandagatla
2025-09-05 16:42 ` Dmitry Baryshkov
@ 2025-09-06 20:23 ` kernel test robot
2025-09-07 9:44 ` Srinivas Kandagatla
1 sibling, 1 reply; 24+ messages in thread
From: kernel test robot @ 2025-09-06 20:23 UTC (permalink / raw)
To: Srinivas Kandagatla, broonie
Cc: oe-kbuild-all, lgirdwood, tiwai, vkoul, srini, yung-chuan.liao,
pierre-louis.bossart, linux-arm-msm, linux-kernel, neil.armstrong,
krzysztof.kozlowski, dmitry.baryshkov, linux-sound,
Srinivas Kandagatla
Hi Srinivas,
kernel test robot noticed the following build errors:
[auto build test ERROR on broonie-sound/for-next]
[also build test ERROR on linus/master v6.17-rc4 next-20250905]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Srinivas-Kandagatla/ASoC-codecs-wcd937x-set-the-comp-soundwire-port-correctly/20250905-234841
base: https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next
patch link: https://lore.kernel.org/r/20250905154430.12268-7-srinivas.kandagatla%40oss.qualcomm.com
patch subject: [PATCH v3 06/12] ASoC: codecs: wcd: add common helper for wcd codecs
config: x86_64-buildonly-randconfig-001-20250907 (https://download.01.org/0day-ci/archive/20250907/202509070437.ko5lmTb9-lkp@intel.com/config)
compiler: gcc-13 (Debian 13.3.0-16) 13.3.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250907/202509070437.ko5lmTb9-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202509070437.ko5lmTb9-lkp@intel.com/
All error/warnings (new ones prefixed by >>):
sound/soc/codecs/wcd937x.c: In function 'wcd937x_mbhc_micb_ctrl_threshold_mic':
>> sound/soc/codecs/wcd937x.c:1522:20: error: 'struct wcd937x_priv' has no member named 'micb2_mv'
1522 | if (wcd937x->micb2_mv >= WCD_MBHC_THR_HS_MICB_MV)
| ^~
sound/soc/codecs/wcd937x.c:1525:61: error: 'struct wcd937x_priv' has no member named 'micb2_mv'
1525 | micb_mv = req_en ? WCD_MBHC_THR_HS_MICB_MV : wcd937x->micb2_mv;
| ^~
sound/soc/codecs/wcd937x.c: In function 'wcd937x_set_micbias_data':
>> sound/soc/codecs/wcd937x.c:2432:34: error: 'struct wcd937x_priv' has no member named 'commmon'; did you mean 'common'?
2432 | wcd937x->commmon.micb_vout[0]);
| ^~~~~~~
| common
sound/soc/codecs/wcd937x.c:2434:34: error: 'struct wcd937x_priv' has no member named 'commmon'; did you mean 'common'?
2434 | wcd937x->commmon.micb_vout[1]);
| ^~~~~~~
| common
sound/soc/codecs/wcd937x.c:2436:34: error: 'struct wcd937x_priv' has no member named 'commmon'; did you mean 'common'?
2436 | wcd937x->commmon.micb_vout[2]);
| ^~~~~~~
| common
sound/soc/codecs/wcd937x.c: In function 'wcd937x_probe':
>> sound/soc/codecs/wcd937x.c:2897:41: error: passing argument 1 of 'wcd_dt_parse_micbias_info' from incompatible pointer type [-Werror=incompatible-pointer-types]
2897 | ret = wcd_dt_parse_micbias_info(dev, &wcd937x->common);
| ^~~
| |
| struct device *
In file included from sound/soc/codecs/wcd937x.c:24:
sound/soc/codecs/wcd-common.h:25:50: note: expected 'struct wcd_common *' but argument is of type 'struct device *'
25 | int wcd_dt_parse_micbias_info(struct wcd_common *common);
| ~~~~~~~~~~~~~~~~~~~^~~~~~
>> sound/soc/codecs/wcd937x.c:2897:15: error: too many arguments to function 'wcd_dt_parse_micbias_info'
2897 | ret = wcd_dt_parse_micbias_info(dev, &wcd937x->common);
| ^~~~~~~~~~~~~~~~~~~~~~~~~
sound/soc/codecs/wcd-common.h:25:5: note: declared here
25 | int wcd_dt_parse_micbias_info(struct wcd_common *common);
| ^~~~~~~~~~~~~~~~~~~~~~~~~
sound/soc/codecs/wcd937x.c:2905:31: error: 'struct wcd937x_priv' has no member named 'micb2_mv'
2905 | cfg->micb_mv = wcd937x->micb2_mv;
| ^~
cc1: some warnings being treated as errors
--
sound/soc/codecs/wcd-common.c: In function 'wcd_dt_parse_micbias_info':
>> sound/soc/codecs/wcd-common.c:34:41: warning: '-microvolt' directive writing 10 bytes into a region of size between 9 and 19 [-Wformat-overflow=]
34 | sprintf(micbias, "qcom,micbias%d-microvolt", micb_num);
| ^~~~~~~~~~
In function 'wcd_get_micbias_val',
inlined from 'wcd_dt_parse_micbias_info' at sound/soc/codecs/wcd-common.c:61:26:
sound/soc/codecs/wcd-common.c:34:9: note: 'sprintf' output between 24 and 34 bytes into a destination of size 32
34 | sprintf(micbias, "qcom,micbias%d-microvolt", micb_num);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
vim +1522 sound/soc/codecs/wcd937x.c
9be3ec196da41b Prasad Kumpatla 2024-05-24 1508
9be3ec196da41b Prasad Kumpatla 2024-05-24 1509 static int wcd937x_mbhc_micb_ctrl_threshold_mic(struct snd_soc_component *component,
9be3ec196da41b Prasad Kumpatla 2024-05-24 1510 int micb_num, bool req_en)
9be3ec196da41b Prasad Kumpatla 2024-05-24 1511 {
9be3ec196da41b Prasad Kumpatla 2024-05-24 1512 struct wcd937x_priv *wcd937x = snd_soc_component_get_drvdata(component);
9be3ec196da41b Prasad Kumpatla 2024-05-24 1513 int micb_mv;
9be3ec196da41b Prasad Kumpatla 2024-05-24 1514
9be3ec196da41b Prasad Kumpatla 2024-05-24 1515 if (micb_num != MIC_BIAS_2)
9be3ec196da41b Prasad Kumpatla 2024-05-24 1516 return -EINVAL;
9be3ec196da41b Prasad Kumpatla 2024-05-24 1517 /*
9be3ec196da41b Prasad Kumpatla 2024-05-24 1518 * If device tree micbias level is already above the minimum
9be3ec196da41b Prasad Kumpatla 2024-05-24 1519 * voltage needed to detect threshold microphone, then do
9be3ec196da41b Prasad Kumpatla 2024-05-24 1520 * not change the micbias, just return.
9be3ec196da41b Prasad Kumpatla 2024-05-24 1521 */
9be3ec196da41b Prasad Kumpatla 2024-05-24 @1522 if (wcd937x->micb2_mv >= WCD_MBHC_THR_HS_MICB_MV)
9be3ec196da41b Prasad Kumpatla 2024-05-24 1523 return 0;
9be3ec196da41b Prasad Kumpatla 2024-05-24 1524
9be3ec196da41b Prasad Kumpatla 2024-05-24 1525 micb_mv = req_en ? WCD_MBHC_THR_HS_MICB_MV : wcd937x->micb2_mv;
9be3ec196da41b Prasad Kumpatla 2024-05-24 1526
9be3ec196da41b Prasad Kumpatla 2024-05-24 1527 return wcd937x_mbhc_micb_adjust_voltage(component, micb_mv, MIC_BIAS_2);
9be3ec196da41b Prasad Kumpatla 2024-05-24 1528 }
9be3ec196da41b Prasad Kumpatla 2024-05-24 1529
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 24+ messages in thread* Re: [PATCH v3 06/12] ASoC: codecs: wcd: add common helper for wcd codecs
2025-09-06 20:23 ` kernel test robot
@ 2025-09-07 9:44 ` Srinivas Kandagatla
0 siblings, 0 replies; 24+ messages in thread
From: Srinivas Kandagatla @ 2025-09-07 9:44 UTC (permalink / raw)
To: kernel test robot, Srinivas Kandagatla, broonie
Cc: oe-kbuild-all, lgirdwood, tiwai, vkoul, srini, yung-chuan.liao,
pierre-louis.bossart, linux-arm-msm, linux-kernel, neil.armstrong,
krzysztof.kozlowski, dmitry.baryshkov, linux-sound
On 9/6/25 9:23 PM, kernel test robot wrote:
> Hi Srinivas,
>
> kernel test robot noticed the following build errors:
>
> [auto build test ERROR on broonie-sound/for-next]
> [also build test ERROR on linus/master v6.17-rc4 next-20250905]
> [If your patch is applied to the wrong git tree, kindly drop us a note.
> And when submitting patch, we suggest to use '--base' as documented in
> https://git-scm.com/docs/git-format-patch#_base_tree_information]
>
> url: https://github.com/intel-lab-lkp/linux/commits/Srinivas-Kandagatla/ASoC-codecs-wcd937x-set-the-comp-soundwire-port-correctly/20250905-234841
> base: https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next
> patch link: https://lore.kernel.org/r/20250905154430.12268-7-srinivas.kandagatla%40oss.qualcomm.com
> patch subject: [PATCH v3 06/12] ASoC: codecs: wcd: add common helper for wcd codecs
> config: x86_64-buildonly-randconfig-001-20250907 (https://download.01.org/0day-ci/archive/20250907/202509070437.ko5lmTb9-lkp@intel.com/config)
> compiler: gcc-13 (Debian 13.3.0-16) 13.3.0
> reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250907/202509070437.ko5lmTb9-lkp@intel.com/reproduce)
>
> If you fix the issue in a separate patch/commit (i.e. not just a new version of
> the same patch/commit), kindly add following tags
> | Reported-by: kernel test robot <lkp@intel.com>
> | Closes: https://lore.kernel.org/oe-kbuild-all/202509070437.ko5lmTb9-lkp@intel.com/
>
> All error/warnings (new ones prefixed by >>):
>
> sound/soc/codecs/wcd937x.c: In function 'wcd937x_mbhc_micb_ctrl_threshold_mic':
>>> sound/soc/codecs/wcd937x.c:1522:20: error: 'struct wcd937x_priv' has no member named 'micb2_mv'
> 1522 | if (wcd937x->micb2_mv >= WCD_MBHC_THR_HS_MICB_MV)
> | ^~
Thanks for the report,
Sorry about this, I was blindly assuming that wcd937x was part of arm64
defconfig. And there was a typo in the header too,
This is now fixed in v4.
--srini
> sound/soc/codecs/wcd937x.c:1525:61: error: 'struct wcd937x_priv' has no member named 'micb2_mv'
> 1525 | micb_mv = req_en ? WCD_MBHC_THR_HS_MICB_MV : wcd937x->micb2_mv;
> | ^~
> sound/soc/codecs/wcd937x.c: In function 'wcd937x_set_micbias_data':
>>> sound/soc/codecs/wcd937x.c:2432:34: error: 'struct wcd937x_priv' has no member named 'commmon'; did you mean 'common'?
> 2432 | wcd937x->commmon.micb_vout[0]);
> | ^~~~~~~
> | common
> sound/soc/codecs/wcd937x.c:2434:34: error: 'struct wcd937x_priv' has no member named 'commmon'; did you mean 'common'?
> 2434 | wcd937x->commmon.micb_vout[1]);
> | ^~~~~~~
> | common
> sound/soc/codecs/wcd937x.c:2436:34: error: 'struct wcd937x_priv' has no member named 'commmon'; did you mean 'common'?
> 2436 | wcd937x->commmon.micb_vout[2]);
> | ^~~~~~~
> | common
> sound/soc/codecs/wcd937x.c: In function 'wcd937x_probe':
>>> sound/soc/codecs/wcd937x.c:2897:41: error: passing argument 1 of 'wcd_dt_parse_micbias_info' from incompatible pointer type [-Werror=incompatible-pointer-types]
> 2897 | ret = wcd_dt_parse_micbias_info(dev, &wcd937x->common);
> | ^~~
> | |
> | struct device *
> In file included from sound/soc/codecs/wcd937x.c:24:
> sound/soc/codecs/wcd-common.h:25:50: note: expected 'struct wcd_common *' but argument is of type 'struct device *'
> 25 | int wcd_dt_parse_micbias_info(struct wcd_common *common);
> | ~~~~~~~~~~~~~~~~~~~^~~~~~
>>> sound/soc/codecs/wcd937x.c:2897:15: error: too many arguments to function 'wcd_dt_parse_micbias_info'
> 2897 | ret = wcd_dt_parse_micbias_info(dev, &wcd937x->common);
> | ^~~~~~~~~~~~~~~~~~~~~~~~~
> sound/soc/codecs/wcd-common.h:25:5: note: declared here
> 25 | int wcd_dt_parse_micbias_info(struct wcd_common *common);
> | ^~~~~~~~~~~~~~~~~~~~~~~~~
> sound/soc/codecs/wcd937x.c:2905:31: error: 'struct wcd937x_priv' has no member named 'micb2_mv'
> 2905 | cfg->micb_mv = wcd937x->micb2_mv;
> | ^~
> cc1: some warnings being treated as errors
> --
> sound/soc/codecs/wcd-common.c: In function 'wcd_dt_parse_micbias_info':
>>> sound/soc/codecs/wcd-common.c:34:41: warning: '-microvolt' directive writing 10 bytes into a region of size between 9 and 19 [-Wformat-overflow=]
> 34 | sprintf(micbias, "qcom,micbias%d-microvolt", micb_num);
> | ^~~~~~~~~~
> In function 'wcd_get_micbias_val',
> inlined from 'wcd_dt_parse_micbias_info' at sound/soc/codecs/wcd-common.c:61:26:
> sound/soc/codecs/wcd-common.c:34:9: note: 'sprintf' output between 24 and 34 bytes into a destination of size 32
> 34 | sprintf(micbias, "qcom,micbias%d-microvolt", micb_num);
> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
>
> vim +1522 sound/soc/codecs/wcd937x.c
>
> 9be3ec196da41b Prasad Kumpatla 2024-05-24 1508
> 9be3ec196da41b Prasad Kumpatla 2024-05-24 1509 static int wcd937x_mbhc_micb_ctrl_threshold_mic(struct snd_soc_component *component,
> 9be3ec196da41b Prasad Kumpatla 2024-05-24 1510 int micb_num, bool req_en)
> 9be3ec196da41b Prasad Kumpatla 2024-05-24 1511 {
> 9be3ec196da41b Prasad Kumpatla 2024-05-24 1512 struct wcd937x_priv *wcd937x = snd_soc_component_get_drvdata(component);
> 9be3ec196da41b Prasad Kumpatla 2024-05-24 1513 int micb_mv;
> 9be3ec196da41b Prasad Kumpatla 2024-05-24 1514
> 9be3ec196da41b Prasad Kumpatla 2024-05-24 1515 if (micb_num != MIC_BIAS_2)
> 9be3ec196da41b Prasad Kumpatla 2024-05-24 1516 return -EINVAL;
> 9be3ec196da41b Prasad Kumpatla 2024-05-24 1517 /*
> 9be3ec196da41b Prasad Kumpatla 2024-05-24 1518 * If device tree micbias level is already above the minimum
> 9be3ec196da41b Prasad Kumpatla 2024-05-24 1519 * voltage needed to detect threshold microphone, then do
> 9be3ec196da41b Prasad Kumpatla 2024-05-24 1520 * not change the micbias, just return.
> 9be3ec196da41b Prasad Kumpatla 2024-05-24 1521 */
> 9be3ec196da41b Prasad Kumpatla 2024-05-24 @1522 if (wcd937x->micb2_mv >= WCD_MBHC_THR_HS_MICB_MV)
> 9be3ec196da41b Prasad Kumpatla 2024-05-24 1523 return 0;
> 9be3ec196da41b Prasad Kumpatla 2024-05-24 1524
> 9be3ec196da41b Prasad Kumpatla 2024-05-24 1525 micb_mv = req_en ? WCD_MBHC_THR_HS_MICB_MV : wcd937x->micb2_mv;
> 9be3ec196da41b Prasad Kumpatla 2024-05-24 1526
> 9be3ec196da41b Prasad Kumpatla 2024-05-24 1527 return wcd937x_mbhc_micb_adjust_voltage(component, micb_mv, MIC_BIAS_2);
> 9be3ec196da41b Prasad Kumpatla 2024-05-24 1528 }
> 9be3ec196da41b Prasad Kumpatla 2024-05-24 1529
>
^ permalink raw reply [flat|nested] 24+ messages in thread
* [PATCH v3 07/12] ASoC: codecs: wcd-common: move WCD_SDW_CH to common
2025-09-05 15:44 [PATCH v3 00/12] ASoC: codecs: wcd93xxx: remove code duplication Srinivas Kandagatla
` (5 preceding siblings ...)
2025-09-05 15:44 ` [PATCH v3 06/12] ASoC: codecs: wcd: add common helper for wcd codecs Srinivas Kandagatla
@ 2025-09-05 15:44 ` Srinivas Kandagatla
2025-09-06 21:15 ` kernel test robot
2025-09-05 15:44 ` [PATCH v3 08/12] ASoC: codecs: wcd-common: move component ops " Srinivas Kandagatla
` (4 subsequent siblings)
11 siblings, 1 reply; 24+ messages in thread
From: Srinivas Kandagatla @ 2025-09-05 15:44 UTC (permalink / raw)
To: broonie
Cc: lgirdwood, tiwai, vkoul, srini, yung-chuan.liao,
pierre-louis.bossart, linux-arm-msm, linux-kernel, neil.armstrong,
krzysztof.kozlowski, dmitry.baryshkov, linux-sound,
Srinivas Kandagatla
sdw_ch_info and WCD_SDW_CH macro is duplicated across wcd937x, wcd938x,
wcd939x soundwire codec drivers. Move this to wcd common driver to
remove this code duplication.
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
---
sound/soc/codecs/wcd-common.h | 11 +++++++++++
sound/soc/codecs/wcd937x-sdw.c | 4 ++--
sound/soc/codecs/wcd937x.h | 16 ++--------------
sound/soc/codecs/wcd938x-sdw.c | 5 +++--
sound/soc/codecs/wcd938x.c | 2 +-
sound/soc/codecs/wcd938x.h | 13 +------------
sound/soc/codecs/wcd939x-sdw.c | 5 +++--
sound/soc/codecs/wcd939x.c | 2 +-
sound/soc/codecs/wcd939x.h | 13 +------------
9 files changed, 25 insertions(+), 46 deletions(-)
diff --git a/sound/soc/codecs/wcd-common.h b/sound/soc/codecs/wcd-common.h
index 42d84e42d40f..ca602718c9ba 100644
--- a/sound/soc/codecs/wcd-common.h
+++ b/sound/soc/codecs/wcd-common.h
@@ -14,6 +14,17 @@ enum sdw_slave_status;
#define WCD_MAX_MICBIAS 4
+struct wcd_sdw_ch_info {
+ int port_num;
+ unsigned int ch_mask;
+};
+
+#define WCD_SDW_CH(id, pn, cmask) \
+ [id] = { \
+ .port_num = pn, \
+ .ch_mask = cmask, \
+ }
+
struct wcd_common {
struct device *dev;
int max_bias;
diff --git a/sound/soc/codecs/wcd937x-sdw.c b/sound/soc/codecs/wcd937x-sdw.c
index e7cc699bd8bc..8f2819163527 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 struct wcd937x_sdw_ch_info wcd937x_sdw_rx_ch_info[] = {
+static struct wcd_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 struct wcd937x_sdw_ch_info wcd937x_sdw_rx_ch_info[] = {
WCD_SDW_CH(WCD937X_DSD_R, WCD937X_DSD_PORT, BIT(1)),
};
-static struct wcd937x_sdw_ch_info wcd937x_sdw_tx_ch_info[] = {
+static struct wcd_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)),
diff --git a/sound/soc/codecs/wcd937x.h b/sound/soc/codecs/wcd937x.h
index 0f96b7108a7e..3d0ba3cc0ee6 100644
--- a/sound/soc/codecs/wcd937x.h
+++ b/sound/soc/codecs/wcd937x.h
@@ -7,6 +7,7 @@
#include <linux/soundwire/sdw.h>
#include <linux/soundwire/sdw_type.h>
+#include "wcd-common.h"
#define WCD937X_BASE_ADDRESS 0x3000
#define WCD937X_ANA_BIAS 0x3001
@@ -507,26 +508,13 @@ enum wcd937x_rx_sdw_ports {
WCD937X_MAX_SWR_PORTS = WCD937X_DSD_PORT,
};
-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;
struct wcd937x_sdw_priv {
struct sdw_slave *sdev;
struct sdw_stream_config sconfig;
struct sdw_stream_runtime *sruntime;
struct sdw_port_config port_config[WCD937X_MAX_SWR_PORTS];
- struct wcd937x_sdw_ch_info *ch_info;
+ struct wcd_sdw_ch_info *ch_info;
bool port_enable[WCD937X_MAX_SWR_CH_IDS];
unsigned int master_channel_map[SDW_MAX_PORTS];
int active_ports;
diff --git a/sound/soc/codecs/wcd938x-sdw.c b/sound/soc/codecs/wcd938x-sdw.c
index 8bcd8396f375..1dc13b6fabfa 100644
--- a/sound/soc/codecs/wcd938x-sdw.c
+++ b/sound/soc/codecs/wcd938x-sdw.c
@@ -18,10 +18,11 @@
#include <sound/soc.h>
#include <sound/soc-dapm.h>
#include "wcd938x.h"
+#include "wcd-common.h"
#define SWRS_SCP_HOST_CLK_DIV2_CTL_BANK(m) (0xE0 + 0x10 * (m))
-static const struct wcd938x_sdw_ch_info wcd938x_sdw_rx_ch_info[] = {
+static const struct wcd_sdw_ch_info wcd938x_sdw_rx_ch_info[] = {
WCD_SDW_CH(WCD938X_HPH_L, WCD938X_HPH_PORT, BIT(0)),
WCD_SDW_CH(WCD938X_HPH_R, WCD938X_HPH_PORT, BIT(1)),
WCD_SDW_CH(WCD938X_CLSH, WCD938X_CLSH_PORT, BIT(0)),
@@ -32,7 +33,7 @@ static const struct wcd938x_sdw_ch_info wcd938x_sdw_rx_ch_info[] = {
WCD_SDW_CH(WCD938X_DSD_R, WCD938X_DSD_PORT, BIT(1)),
};
-static const struct wcd938x_sdw_ch_info wcd938x_sdw_tx_ch_info[] = {
+static const struct wcd_sdw_ch_info wcd938x_sdw_tx_ch_info[] = {
WCD_SDW_CH(WCD938X_ADC1, WCD938X_ADC_1_2_PORT, BIT(0)),
WCD_SDW_CH(WCD938X_ADC2, WCD938X_ADC_1_2_PORT, BIT(1)),
WCD_SDW_CH(WCD938X_ADC3, WCD938X_ADC_3_4_PORT, BIT(0)),
diff --git a/sound/soc/codecs/wcd938x.c b/sound/soc/codecs/wcd938x.c
index c8b6e543986d..e495f98972f1 100644
--- a/sound/soc/codecs/wcd938x.c
+++ b/sound/soc/codecs/wcd938x.c
@@ -394,7 +394,7 @@ static int wcd938x_io_init(struct wcd938x_priv *wcd938x)
}
-static int wcd938x_sdw_connect_port(const struct wcd938x_sdw_ch_info *ch_info,
+static int wcd938x_sdw_connect_port(const struct wcd_sdw_ch_info *ch_info,
struct sdw_port_config *port_config,
u8 enable)
{
diff --git a/sound/soc/codecs/wcd938x.h b/sound/soc/codecs/wcd938x.h
index 54ee56b7fbd6..c18610466d7d 100644
--- a/sound/soc/codecs/wcd938x.h
+++ b/sound/soc/codecs/wcd938x.h
@@ -587,17 +587,6 @@
#define WCD938X_MAX_SWR_CH_IDS 15
-struct wcd938x_sdw_ch_info {
- int port_num;
- unsigned int ch_mask;
-};
-
-#define WCD_SDW_CH(id, pn, cmask) \
- [id] = { \
- .port_num = pn, \
- .ch_mask = cmask, \
- }
-
enum wcd938x_tx_sdw_ports {
WCD938X_ADC_1_2_PORT = 1,
WCD938X_ADC_3_4_PORT,
@@ -649,7 +638,7 @@ struct wcd938x_sdw_priv {
struct sdw_stream_config sconfig;
struct sdw_stream_runtime *sruntime;
struct sdw_port_config port_config[WCD938X_MAX_SWR_PORTS];
- const struct wcd938x_sdw_ch_info *ch_info;
+ const struct wcd_sdw_ch_info *ch_info;
bool port_enable[WCD938X_MAX_SWR_CH_IDS];
int active_ports;
bool is_tx;
diff --git a/sound/soc/codecs/wcd939x-sdw.c b/sound/soc/codecs/wcd939x-sdw.c
index 477d6cf27d32..97a829e3ce4f 100644
--- a/sound/soc/codecs/wcd939x-sdw.c
+++ b/sound/soc/codecs/wcd939x-sdw.c
@@ -20,10 +20,11 @@
#include <sound/soc.h>
#include <sound/soc-dapm.h>
#include "wcd939x.h"
+#include "wcd-common.h"
#define SWRS_SCP_HOST_CLK_DIV2_CTL_BANK(m) (0xE0 + 0x10 * (m))
-static const struct wcd939x_sdw_ch_info wcd939x_sdw_rx_ch_info[] = {
+static const struct wcd_sdw_ch_info wcd939x_sdw_rx_ch_info[] = {
WCD_SDW_CH(WCD939X_HPH_L, WCD939X_HPH_PORT, BIT(0)),
WCD_SDW_CH(WCD939X_HPH_R, WCD939X_HPH_PORT, BIT(1)),
WCD_SDW_CH(WCD939X_CLSH, WCD939X_CLSH_PORT, BIT(0)),
@@ -36,7 +37,7 @@ static const struct wcd939x_sdw_ch_info wcd939x_sdw_rx_ch_info[] = {
WCD_SDW_CH(WCD939X_HIFI_PCM_R, WCD939X_HIFI_PCM_PORT, BIT(1)),
};
-static const struct wcd939x_sdw_ch_info wcd939x_sdw_tx_ch_info[] = {
+static const struct wcd_sdw_ch_info wcd939x_sdw_tx_ch_info[] = {
WCD_SDW_CH(WCD939X_ADC1, WCD939X_ADC_1_4_PORT, BIT(0)),
WCD_SDW_CH(WCD939X_ADC2, WCD939X_ADC_1_4_PORT, BIT(1)),
WCD_SDW_CH(WCD939X_ADC3, WCD939X_ADC_1_4_PORT, BIT(2)),
diff --git a/sound/soc/codecs/wcd939x.c b/sound/soc/codecs/wcd939x.c
index 59c920c50c00..a414cd99b946 100644
--- a/sound/soc/codecs/wcd939x.c
+++ b/sound/soc/codecs/wcd939x.c
@@ -413,7 +413,7 @@ static int wcd939x_io_init(struct snd_soc_component *component)
return 0;
}
-static int wcd939x_sdw_connect_port(const struct wcd939x_sdw_ch_info *ch_info,
+static int wcd939x_sdw_connect_port(const struct wcd_sdw_ch_info *ch_info,
struct sdw_port_config *port_config,
u8 enable)
{
diff --git a/sound/soc/codecs/wcd939x.h b/sound/soc/codecs/wcd939x.h
index e70445b1a4bc..ca6353222ea0 100644
--- a/sound/soc/codecs/wcd939x.h
+++ b/sound/soc/codecs/wcd939x.h
@@ -844,17 +844,6 @@
#define WCD939X_MAX_SWR_CH_IDS (15)
-struct wcd939x_sdw_ch_info {
- int port_num;
- unsigned int ch_mask;
-};
-
-#define WCD_SDW_CH(id, pn, cmask) \
- [id] = { \
- .port_num = pn, \
- .ch_mask = cmask, \
- }
-
enum wcd939x_tx_sdw_ports {
WCD939X_ADC_1_4_PORT = 1,
WCD939X_ADC_DMIC_1_2_PORT,
@@ -909,7 +898,7 @@ struct wcd939x_sdw_priv {
struct sdw_stream_config sconfig;
struct sdw_stream_runtime *sruntime;
struct sdw_port_config port_config[WCD939X_MAX_SWR_PORTS];
- const struct wcd939x_sdw_ch_info *ch_info;
+ const struct wcd_sdw_ch_info *ch_info;
bool port_enable[WCD939X_MAX_SWR_CH_IDS];
int active_ports;
bool is_tx;
--
2.50.0
^ permalink raw reply related [flat|nested] 24+ messages in thread* Re: [PATCH v3 07/12] ASoC: codecs: wcd-common: move WCD_SDW_CH to common
2025-09-05 15:44 ` [PATCH v3 07/12] ASoC: codecs: wcd-common: move WCD_SDW_CH to common Srinivas Kandagatla
@ 2025-09-06 21:15 ` kernel test robot
0 siblings, 0 replies; 24+ messages in thread
From: kernel test robot @ 2025-09-06 21:15 UTC (permalink / raw)
To: Srinivas Kandagatla, broonie
Cc: oe-kbuild-all, lgirdwood, tiwai, vkoul, srini, yung-chuan.liao,
pierre-louis.bossart, linux-arm-msm, linux-kernel, neil.armstrong,
krzysztof.kozlowski, dmitry.baryshkov, linux-sound,
Srinivas Kandagatla
Hi Srinivas,
kernel test robot noticed the following build errors:
[auto build test ERROR on broonie-sound/for-next]
[also build test ERROR on linus/master v6.17-rc4 next-20250905]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Srinivas-Kandagatla/ASoC-codecs-wcd937x-set-the-comp-soundwire-port-correctly/20250905-234841
base: https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next
patch link: https://lore.kernel.org/r/20250905154430.12268-8-srinivas.kandagatla%40oss.qualcomm.com
patch subject: [PATCH v3 07/12] ASoC: codecs: wcd-common: move WCD_SDW_CH to common
config: x86_64-buildonly-randconfig-001-20250907 (https://download.01.org/0day-ci/archive/20250907/202509070539.WhfiRSpY-lkp@intel.com/config)
compiler: gcc-13 (Debian 13.3.0-16) 13.3.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250907/202509070539.WhfiRSpY-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202509070539.WhfiRSpY-lkp@intel.com/
All errors (new ones prefixed by >>):
In file included from sound/soc/codecs/wcd937x.h:10,
from sound/soc/codecs/wcd937x.c:26:
>> sound/soc/codecs/wcd-common.h:17:8: error: redefinition of 'struct wcd_sdw_ch_info'
17 | struct wcd_sdw_ch_info {
| ^~~~~~~~~~~~~~~
In file included from sound/soc/codecs/wcd937x.c:24:
sound/soc/codecs/wcd-common.h:17:8: note: originally defined here
17 | struct wcd_sdw_ch_info {
| ^~~~~~~~~~~~~~~
>> sound/soc/codecs/wcd-common.h:28:8: error: redefinition of 'struct wcd_common'
28 | struct wcd_common {
| ^~~~~~~~~~
sound/soc/codecs/wcd-common.h:28:8: note: originally defined here
28 | struct wcd_common {
| ^~~~~~~~~~
>> sound/soc/codecs/wcd-common.h:36:5: error: conflicting types for 'wcd_dt_parse_micbias_info'; have 'int(struct wcd_common *)'
36 | int wcd_dt_parse_micbias_info(struct wcd_common *common);
| ^~~~~~~~~~~~~~~~~~~~~~~~~
sound/soc/codecs/wcd-common.h:36:5: note: previous declaration of 'wcd_dt_parse_micbias_info' with type 'int(struct wcd_common *)'
36 | int wcd_dt_parse_micbias_info(struct wcd_common *common);
| ^~~~~~~~~~~~~~~~~~~~~~~~~
sound/soc/codecs/wcd937x.c: In function 'wcd937x_connect_port':
>> sound/soc/codecs/wcd937x.c:1186:53: error: initialization of 'const struct wcd937x_sdw_ch_info *' from incompatible pointer type 'struct wcd_sdw_ch_info *' [-Werror=incompatible-pointer-types]
1186 | const struct wcd937x_sdw_ch_info *ch_info = &wcd->ch_info[ch_id];
| ^
>> sound/soc/codecs/wcd937x.c:1187:30: error: invalid use of undefined type 'const struct wcd937x_sdw_ch_info'
1187 | u8 port_num = ch_info->port_num;
| ^~
sound/soc/codecs/wcd937x.c:1188:29: error: invalid use of undefined type 'const struct wcd937x_sdw_ch_info'
1188 | u8 ch_mask = ch_info->ch_mask;
| ^~
sound/soc/codecs/wcd937x.c:1195:31: error: invalid use of undefined type 'const struct wcd937x_sdw_ch_info'
1195 | mstr_ch_mask = ch_info->master_ch_mask;
| ^~
sound/soc/codecs/wcd937x.c: In function 'wcd937x_mbhc_micb_ctrl_threshold_mic':
sound/soc/codecs/wcd937x.c:1522:20: error: 'struct wcd937x_priv' has no member named 'micb2_mv'
1522 | if (wcd937x->micb2_mv >= WCD_MBHC_THR_HS_MICB_MV)
| ^~
sound/soc/codecs/wcd937x.c:1525:61: error: 'struct wcd937x_priv' has no member named 'micb2_mv'
1525 | micb_mv = req_en ? WCD_MBHC_THR_HS_MICB_MV : wcd937x->micb2_mv;
| ^~
sound/soc/codecs/wcd937x.c: In function 'wcd937x_set_micbias_data':
sound/soc/codecs/wcd937x.c:2432:34: error: 'struct wcd937x_priv' has no member named 'commmon'; did you mean 'common'?
2432 | wcd937x->commmon.micb_vout[0]);
| ^~~~~~~
| common
sound/soc/codecs/wcd937x.c:2434:34: error: 'struct wcd937x_priv' has no member named 'commmon'; did you mean 'common'?
2434 | wcd937x->commmon.micb_vout[1]);
| ^~~~~~~
| common
sound/soc/codecs/wcd937x.c:2436:34: error: 'struct wcd937x_priv' has no member named 'commmon'; did you mean 'common'?
2436 | wcd937x->commmon.micb_vout[2]);
| ^~~~~~~
| common
sound/soc/codecs/wcd937x.c: In function 'wcd937x_probe':
sound/soc/codecs/wcd937x.c:2897:41: error: passing argument 1 of 'wcd_dt_parse_micbias_info' from incompatible pointer type [-Werror=incompatible-pointer-types]
2897 | ret = wcd_dt_parse_micbias_info(dev, &wcd937x->common);
| ^~~
| |
| struct device *
sound/soc/codecs/wcd-common.h:36:50: note: expected 'struct wcd_common *' but argument is of type 'struct device *'
36 | int wcd_dt_parse_micbias_info(struct wcd_common *common);
| ~~~~~~~~~~~~~~~~~~~^~~~~~
sound/soc/codecs/wcd937x.c:2897:15: error: too many arguments to function 'wcd_dt_parse_micbias_info'
2897 | ret = wcd_dt_parse_micbias_info(dev, &wcd937x->common);
| ^~~~~~~~~~~~~~~~~~~~~~~~~
sound/soc/codecs/wcd-common.h:36:5: note: declared here
36 | int wcd_dt_parse_micbias_info(struct wcd_common *common);
| ^~~~~~~~~~~~~~~~~~~~~~~~~
sound/soc/codecs/wcd937x.c:2905:31: error: 'struct wcd937x_priv' has no member named 'micb2_mv'
2905 | cfg->micb_mv = wcd937x->micb2_mv;
| ^~
cc1: some warnings being treated as errors
--
sound/soc/codecs/wcd937x-sdw.c: In function 'wcd9370_probe':
>> sound/soc/codecs/wcd937x-sdw.c:1075:40: error: 'struct wcd_sdw_ch_info' has no member named 'master_ch_mask'
1075 | wcd->ch_info[i].master_ch_mask = WCD937X_SWRM_CH_MASK(master_ch_mask[i]);
| ^
sound/soc/codecs/wcd937x-sdw.c:1092:40: error: 'struct wcd_sdw_ch_info' has no member named 'master_ch_mask'
1092 | wcd->ch_info[i].master_ch_mask = WCD937X_SWRM_CH_MASK(master_ch_mask[i]);
| ^
vim +17 sound/soc/codecs/wcd-common.h
16
> 17 struct wcd_sdw_ch_info {
18 int port_num;
19 unsigned int ch_mask;
20 };
21
22 #define WCD_SDW_CH(id, pn, cmask) \
23 [id] = { \
24 .port_num = pn, \
25 .ch_mask = cmask, \
26 }
27
> 28 struct wcd_common {
29 struct device *dev;
30 int max_bias;
31 u32 micb_mv[WCD_MAX_MICBIAS];
32 u32 micb_vout[WCD_MAX_MICBIAS];
33 };
34
35 int wcd_get_micb_vout_ctl_val(struct device *dev, u32 micb_mv);
> 36 int wcd_dt_parse_micbias_info(struct wcd_common *common);
37
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 24+ messages in thread
* [PATCH v3 08/12] ASoC: codecs: wcd-common: move component ops to common
2025-09-05 15:44 [PATCH v3 00/12] ASoC: codecs: wcd93xxx: remove code duplication Srinivas Kandagatla
` (6 preceding siblings ...)
2025-09-05 15:44 ` [PATCH v3 07/12] ASoC: codecs: wcd-common: move WCD_SDW_CH to common Srinivas Kandagatla
@ 2025-09-05 15:44 ` Srinivas Kandagatla
2025-09-05 15:44 ` [PATCH v3 09/12] ASoC: codecs: wcd939x: get regmap directly Srinivas Kandagatla
` (3 subsequent siblings)
11 siblings, 0 replies; 24+ messages in thread
From: Srinivas Kandagatla @ 2025-09-05 15:44 UTC (permalink / raw)
To: broonie
Cc: lgirdwood, tiwai, vkoul, srini, yung-chuan.liao,
pierre-louis.bossart, linux-arm-msm, linux-kernel, neil.armstrong,
krzysztof.kozlowski, dmitry.baryshkov, linux-sound,
Srinivas Kandagatla
component_ops for wcd97x, wcd938x, wcd939x soundwire codecs are exactly
identlical, move them to common driver to remove this duplicate code.
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
---
sound/soc/codecs/wcd-common.c | 27 +++++++++++++++++++++++++++
sound/soc/codecs/wcd-common.h | 1 +
sound/soc/codecs/wcd937x-sdw.c | 29 ++---------------------------
sound/soc/codecs/wcd938x-sdw.c | 20 ++------------------
sound/soc/codecs/wcd939x-sdw.c | 29 ++---------------------------
5 files changed, 34 insertions(+), 72 deletions(-)
diff --git a/sound/soc/codecs/wcd-common.c b/sound/soc/codecs/wcd-common.c
index 25c0a48ff858..585d3e036900 100644
--- a/sound/soc/codecs/wcd-common.c
+++ b/sound/soc/codecs/wcd-common.c
@@ -7,6 +7,8 @@
#include <linux/device.h>
#include <linux/of.h>
#include <linux/printk.h>
+#include <linux/component.h>
+#include <linux/pm_runtime.h>
#include "wcd-common.h"
@@ -66,5 +68,30 @@ int wcd_dt_parse_micbias_info(struct wcd_common *common)
return 0;
}
EXPORT_SYMBOL_GPL(wcd_dt_parse_micbias_info);
+
+static int wcd_sdw_component_bind(struct device *dev, struct device *master, void *data)
+{
+ pm_runtime_set_autosuspend_delay(dev, 3000);
+ pm_runtime_use_autosuspend(dev);
+ pm_runtime_mark_last_busy(dev);
+ pm_runtime_set_active(dev);
+ pm_runtime_enable(dev);
+
+ return 0;
+}
+
+static void wcd_sdw_component_unbind(struct device *dev, struct device *master, void *data)
+{
+ pm_runtime_disable(dev);
+ pm_runtime_set_suspended(dev);
+ pm_runtime_dont_use_autosuspend(dev);
+}
+
+const struct component_ops wcd_sdw_component_ops = {
+ .bind = wcd_sdw_component_bind,
+ .unbind = wcd_sdw_component_unbind,
+};
+EXPORT_SYMBOL_GPL(wcd_sdw_component_ops);
+
MODULE_DESCRIPTION("Common Qualcomm WCD Codec helpers driver");
MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/wcd-common.h b/sound/soc/codecs/wcd-common.h
index ca602718c9ba..85e5818b9b0c 100644
--- a/sound/soc/codecs/wcd-common.h
+++ b/sound/soc/codecs/wcd-common.h
@@ -32,6 +32,7 @@ struct wcd_common {
u32 micb_vout[WCD_MAX_MICBIAS];
};
+extern const struct component_ops wcd_sdw_component_ops;
int wcd_get_micb_vout_ctl_val(struct device *dev, u32 micb_mv);
int wcd_dt_parse_micbias_info(struct wcd_common *common);
diff --git a/sound/soc/codecs/wcd937x-sdw.c b/sound/soc/codecs/wcd937x-sdw.c
index 8f2819163527..59c353cafd31 100644
--- a/sound/soc/codecs/wcd937x-sdw.c
+++ b/sound/soc/codecs/wcd937x-sdw.c
@@ -983,31 +983,6 @@ static const struct sdw_slave_ops wcd9370_slave_ops = {
.interrupt_callback = wcd9370_interrupt_callback,
};
-static int wcd937x_sdw_component_bind(struct device *dev,
- struct device *master, void *data)
-{
- pm_runtime_set_autosuspend_delay(dev, 3000);
- pm_runtime_use_autosuspend(dev);
- pm_runtime_mark_last_busy(dev);
- pm_runtime_set_active(dev);
- pm_runtime_enable(dev);
-
- return 0;
-}
-
-static void wcd937x_sdw_component_unbind(struct device *dev,
- struct device *master, void *data)
-{
- pm_runtime_disable(dev);
- pm_runtime_set_suspended(dev);
- pm_runtime_dont_use_autosuspend(dev);
-}
-
-static const struct component_ops wcd937x_sdw_component_ops = {
- .bind = wcd937x_sdw_component_bind,
- .unbind = wcd937x_sdw_component_unbind,
-};
-
static int wcd9370_probe(struct sdw_slave *pdev,
const struct sdw_device_id *id)
{
@@ -1093,7 +1068,7 @@ static int wcd9370_probe(struct sdw_slave *pdev,
}
- ret = component_add(dev, &wcd937x_sdw_component_ops);
+ ret = component_add(dev, &wcd_sdw_component_ops);
if (ret)
return ret;
@@ -1107,7 +1082,7 @@ static int wcd9370_remove(struct sdw_slave *pdev)
{
struct device *dev = &pdev->dev;
- component_del(dev, &wcd937x_sdw_component_ops);
+ component_del(dev, &wcd_sdw_component_ops);
return 0;
}
diff --git a/sound/soc/codecs/wcd938x-sdw.c b/sound/soc/codecs/wcd938x-sdw.c
index 1dc13b6fabfa..92714aef09d5 100644
--- a/sound/soc/codecs/wcd938x-sdw.c
+++ b/sound/soc/codecs/wcd938x-sdw.c
@@ -1182,22 +1182,6 @@ static const struct sdw_slave_ops wcd9380_slave_ops = {
.bus_config = wcd9380_bus_config,
};
-static int wcd938x_sdw_component_bind(struct device *dev,
- struct device *master, void *data)
-{
- return 0;
-}
-
-static void wcd938x_sdw_component_unbind(struct device *dev,
- struct device *master, void *data)
-{
-}
-
-static const struct component_ops wcd938x_sdw_component_ops = {
- .bind = wcd938x_sdw_component_bind,
- .unbind = wcd938x_sdw_component_unbind,
-};
-
static int wcd9380_probe(struct sdw_slave *pdev,
const struct sdw_device_id *id)
{
@@ -1262,7 +1246,7 @@ static int wcd9380_probe(struct sdw_slave *pdev,
pm_runtime_set_active(dev);
pm_runtime_enable(dev);
- ret = component_add(dev, &wcd938x_sdw_component_ops);
+ ret = component_add(dev, &wcd_sdw_component_ops);
if (ret)
goto err_disable_rpm;
@@ -1280,7 +1264,7 @@ static int wcd9380_remove(struct sdw_slave *pdev)
{
struct device *dev = &pdev->dev;
- component_del(dev, &wcd938x_sdw_component_ops);
+ component_del(dev, &wcd_sdw_component_ops);
pm_runtime_disable(dev);
pm_runtime_set_suspended(dev);
diff --git a/sound/soc/codecs/wcd939x-sdw.c b/sound/soc/codecs/wcd939x-sdw.c
index 97a829e3ce4f..6aecad2a28aa 100644
--- a/sound/soc/codecs/wcd939x-sdw.c
+++ b/sound/soc/codecs/wcd939x-sdw.c
@@ -1378,31 +1378,6 @@ static const struct sdw_slave_ops wcd9390_slave_ops = {
.bus_config = wcd9390_bus_config,
};
-static int wcd939x_sdw_component_bind(struct device *dev, struct device *master,
- void *data)
-{
- pm_runtime_set_autosuspend_delay(dev, 3000);
- pm_runtime_use_autosuspend(dev);
- pm_runtime_mark_last_busy(dev);
- pm_runtime_set_active(dev);
- pm_runtime_enable(dev);
-
- return 0;
-}
-
-static void wcd939x_sdw_component_unbind(struct device *dev,
- struct device *master, void *data)
-{
- pm_runtime_disable(dev);
- pm_runtime_set_suspended(dev);
- pm_runtime_dont_use_autosuspend(dev);
-}
-
-static const struct component_ops wcd939x_sdw_component_ops = {
- .bind = wcd939x_sdw_component_bind,
- .unbind = wcd939x_sdw_component_unbind,
-};
-
static int wcd9390_probe(struct sdw_slave *pdev, const struct sdw_device_id *id)
{
struct device *dev = &pdev->dev;
@@ -1466,7 +1441,7 @@ static int wcd9390_probe(struct sdw_slave *pdev, const struct sdw_device_id *id)
regcache_cache_only(wcd->regmap, true);
}
- ret = component_add(dev, &wcd939x_sdw_component_ops);
+ ret = component_add(dev, &wcd_sdw_component_ops);
if (ret)
return ret;
@@ -1481,7 +1456,7 @@ static int wcd9390_remove(struct sdw_slave *pdev)
struct device *dev = &pdev->dev;
struct wcd939x_sdw_priv *wcd = dev_get_drvdata(dev);
- component_del(dev, &wcd939x_sdw_component_ops);
+ component_del(dev, &wcd_sdw_component_ops);
if (wcd->regmap)
regmap_exit(wcd->regmap);
--
2.50.0
^ permalink raw reply related [flat|nested] 24+ messages in thread* [PATCH v3 09/12] ASoC: codecs: wcd939x: get regmap directly
2025-09-05 15:44 [PATCH v3 00/12] ASoC: codecs: wcd93xxx: remove code duplication Srinivas Kandagatla
` (7 preceding siblings ...)
2025-09-05 15:44 ` [PATCH v3 08/12] ASoC: codecs: wcd-common: move component ops " Srinivas Kandagatla
@ 2025-09-05 15:44 ` Srinivas Kandagatla
2025-09-05 16:43 ` Dmitry Baryshkov
2025-09-05 15:44 ` [PATCH v3 10/12] ASoC: codecs: wcd-common: move status_update callback to common Srinivas Kandagatla
` (2 subsequent siblings)
11 siblings, 1 reply; 24+ messages in thread
From: Srinivas Kandagatla @ 2025-09-05 15:44 UTC (permalink / raw)
To: broonie
Cc: lgirdwood, tiwai, vkoul, srini, yung-chuan.liao,
pierre-louis.bossart, linux-arm-msm, linux-kernel, neil.armstrong,
krzysztof.kozlowski, dmitry.baryshkov, linux-sound,
Srinivas Kandagatla
for some reason we ended up with a boiler plate for dev_get_regmap in
wcd939x codec and started exporting a symbol for this. Remove this
redundant wrapper and direclty get regmap.
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
---
sound/soc/codecs/wcd939x-sdw.c | 9 ---------
sound/soc/codecs/wcd939x.c | 6 +++---
sound/soc/codecs/wcd939x.h | 6 ------
3 files changed, 3 insertions(+), 18 deletions(-)
diff --git a/sound/soc/codecs/wcd939x-sdw.c b/sound/soc/codecs/wcd939x-sdw.c
index 6aecad2a28aa..38da706d80be 100644
--- a/sound/soc/codecs/wcd939x-sdw.c
+++ b/sound/soc/codecs/wcd939x-sdw.c
@@ -187,15 +187,6 @@ int wcd939x_sdw_set_sdw_stream(struct wcd939x_sdw_priv *wcd,
}
EXPORT_SYMBOL_GPL(wcd939x_sdw_set_sdw_stream);
-struct regmap *wcd939x_swr_get_regmap(struct wcd939x_sdw_priv *wcd)
-{
- if (wcd->regmap)
- return wcd->regmap;
-
- return ERR_PTR(-EINVAL);
-}
-EXPORT_SYMBOL_GPL(wcd939x_swr_get_regmap);
-
static int wcd9390_update_status(struct sdw_slave *slave,
enum sdw_slave_status status)
{
diff --git a/sound/soc/codecs/wcd939x.c b/sound/soc/codecs/wcd939x.c
index a414cd99b946..e74e6f013131 100644
--- a/sound/soc/codecs/wcd939x.c
+++ b/sound/soc/codecs/wcd939x.c
@@ -3374,10 +3374,10 @@ static int wcd939x_bind(struct device *dev)
}
/* Get regmap from TX SoundWire device */
- wcd939x->regmap = wcd939x_swr_get_regmap(wcd939x->sdw_priv[AIF1_CAP]);
- if (IS_ERR(wcd939x->regmap)) {
+ wcd939x->regmap = wcd939x->sdw_priv[AIF1_CAP]->regmap;
+ if (!wcd939x->regmap) {
dev_err(dev, "could not get TX device regmap\n");
- ret = PTR_ERR(wcd939x->regmap);
+ ret = -ENODEV;
goto err_remove_rx_link;
}
diff --git a/sound/soc/codecs/wcd939x.h b/sound/soc/codecs/wcd939x.h
index ca6353222ea0..6bd2366587a8 100644
--- a/sound/soc/codecs/wcd939x.h
+++ b/sound/soc/codecs/wcd939x.h
@@ -918,8 +918,6 @@ int wcd939x_sdw_hw_params(struct wcd939x_sdw_priv *wcd,
struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *params,
struct snd_soc_dai *dai);
-
-struct regmap *wcd939x_swr_get_regmap(struct wcd939x_sdw_priv *wcd);
#else
static inline int wcd939x_sdw_free(struct wcd939x_sdw_priv *wcd,
@@ -944,10 +942,6 @@ static inline int wcd939x_sdw_hw_params(struct wcd939x_sdw_priv *wcd,
return -EOPNOTSUPP;
}
-struct regmap *wcd939x_swr_get_regmap(struct wcd939x_sdw_priv *wcd)
-{
- return PTR_ERR(-EINVAL);
-}
#endif /* CONFIG_SND_SOC_WCD939X_SDW */
#endif /* __WCD939X_H__ */
--
2.50.0
^ permalink raw reply related [flat|nested] 24+ messages in thread* Re: [PATCH v3 09/12] ASoC: codecs: wcd939x: get regmap directly
2025-09-05 15:44 ` [PATCH v3 09/12] ASoC: codecs: wcd939x: get regmap directly Srinivas Kandagatla
@ 2025-09-05 16:43 ` Dmitry Baryshkov
0 siblings, 0 replies; 24+ messages in thread
From: Dmitry Baryshkov @ 2025-09-05 16:43 UTC (permalink / raw)
To: Srinivas Kandagatla
Cc: broonie, lgirdwood, tiwai, vkoul, srini, yung-chuan.liao,
pierre-louis.bossart, linux-arm-msm, linux-kernel, neil.armstrong,
krzysztof.kozlowski, linux-sound
On Fri, Sep 05, 2025 at 04:44:27PM +0100, Srinivas Kandagatla wrote:
> for some reason we ended up with a boiler plate for dev_get_regmap in
> wcd939x codec and started exporting a symbol for this. Remove this
> redundant wrapper and direclty get regmap.
>
> Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
> ---
> sound/soc/codecs/wcd939x-sdw.c | 9 ---------
> sound/soc/codecs/wcd939x.c | 6 +++---
> sound/soc/codecs/wcd939x.h | 6 ------
> 3 files changed, 3 insertions(+), 18 deletions(-)
>
Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
>
--
With best wishes
Dmitry
^ permalink raw reply [flat|nested] 24+ messages in thread
* [PATCH v3 10/12] ASoC: codecs: wcd-common: move status_update callback to common
2025-09-05 15:44 [PATCH v3 00/12] ASoC: codecs: wcd93xxx: remove code duplication Srinivas Kandagatla
` (8 preceding siblings ...)
2025-09-05 15:44 ` [PATCH v3 09/12] ASoC: codecs: wcd939x: get regmap directly Srinivas Kandagatla
@ 2025-09-05 15:44 ` Srinivas Kandagatla
2025-09-05 16:44 ` Dmitry Baryshkov
2025-09-05 15:44 ` [PATCH v3 11/12] ASoC: codecs: wcd938x: get regmap directly Srinivas Kandagatla
2025-09-05 15:44 ` [PATCH v3 12/12] ASoC: codecs: wcd937x: " Srinivas Kandagatla
11 siblings, 1 reply; 24+ messages in thread
From: Srinivas Kandagatla @ 2025-09-05 15:44 UTC (permalink / raw)
To: broonie
Cc: lgirdwood, tiwai, vkoul, srini, yung-chuan.liao,
pierre-louis.bossart, linux-arm-msm, linux-kernel, neil.armstrong,
krzysztof.kozlowski, dmitry.baryshkov, linux-sound,
Srinivas Kandagatla
Soundwire update_status, bus_config and interrupt callbacks for wcd937x,
wcd938x, wcd939x soundwire codecs are exactly identlical, move them to
common driver to remove this duplicate code.
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
---
sound/soc/codecs/wcd-common.c | 46 ++++++++++++++++++++++++++++++++++
sound/soc/codecs/wcd-common.h | 5 ++++
sound/soc/codecs/wcd937x-sdw.c | 28 +++------------------
sound/soc/codecs/wcd938x-sdw.c | 41 +++---------------------------
sound/soc/codecs/wcd939x-sdw.c | 42 +++----------------------------
5 files changed, 62 insertions(+), 100 deletions(-)
diff --git a/sound/soc/codecs/wcd-common.c b/sound/soc/codecs/wcd-common.c
index 585d3e036900..6aaa6e2c955a 100644
--- a/sound/soc/codecs/wcd-common.c
+++ b/sound/soc/codecs/wcd-common.c
@@ -9,6 +9,9 @@
#include <linux/printk.h>
#include <linux/component.h>
#include <linux/pm_runtime.h>
+#include <linux/soundwire/sdw.h>
+#include <linux/soundwire/sdw_type.h>
+#include <linux/regmap.h>
#include "wcd-common.h"
@@ -16,6 +19,8 @@
#define WCD_DEF_MICBIAS_MV 1800
#define WCD_MAX_MICBIAS_MV 2850
+#define SWRS_SCP_HOST_CLK_DIV2_CTL_BANK(m) (0xE0 + 0x10 * (m))
+
int wcd_get_micb_vout_ctl_val(struct device *dev, u32 micb_mv)
{
/* min micbias voltage is 1V and maximum is 2.85V */
@@ -93,5 +98,46 @@ const struct component_ops wcd_sdw_component_ops = {
};
EXPORT_SYMBOL_GPL(wcd_sdw_component_ops);
+int wcd_update_status(struct sdw_slave *slave, enum sdw_slave_status status)
+{
+ struct regmap *regmap = dev_get_regmap(&slave->dev, NULL);
+
+ if (regmap && status == SDW_SLAVE_ATTACHED) {
+ /* Write out any cached changes that happened between probe and attach */
+ regcache_cache_only(regmap, false);
+ return regcache_sync(regmap);
+ }
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(wcd_update_status);
+
+int wcd_bus_config(struct sdw_slave *slave, struct sdw_bus_params *params)
+{
+ sdw_write(slave, SWRS_SCP_HOST_CLK_DIV2_CTL_BANK(params->next_bank), 0x01);
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(wcd_bus_config);
+
+int wcd_interrupt_callback(struct sdw_slave *slave, struct irq_domain *slave_irq,
+ unsigned int wcd_intr_status0, unsigned int wcd_intr_status1,
+ unsigned int wcd_intr_status2)
+{
+ struct regmap *regmap = dev_get_regmap(&slave->dev, NULL);
+ u32 sts1, sts2, sts3;
+
+ do {
+ handle_nested_irq(irq_find_mapping(slave_irq, 0));
+ regmap_read(regmap, wcd_intr_status0, &sts1);
+ regmap_read(regmap, wcd_intr_status1, &sts2);
+ regmap_read(regmap, wcd_intr_status2, &sts3);
+
+ } while (sts1 || sts2 || sts3);
+
+ return IRQ_HANDLED;
+}
+EXPORT_SYMBOL_GPL(wcd_interrupt_callback);
+
MODULE_DESCRIPTION("Common Qualcomm WCD Codec helpers driver");
MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/wcd-common.h b/sound/soc/codecs/wcd-common.h
index 85e5818b9b0c..a844908de433 100644
--- a/sound/soc/codecs/wcd-common.h
+++ b/sound/soc/codecs/wcd-common.h
@@ -35,5 +35,10 @@ struct wcd_common {
extern const struct component_ops wcd_sdw_component_ops;
int wcd_get_micb_vout_ctl_val(struct device *dev, u32 micb_mv);
int wcd_dt_parse_micbias_info(struct wcd_common *common);
+int wcd_update_status(struct sdw_slave *slave, enum sdw_slave_status status);
+int wcd_bus_config(struct sdw_slave *slave, struct sdw_bus_params *params);
+int wcd_interrupt_callback(struct sdw_slave *slave, struct irq_domain *slave_irq,
+ unsigned int wcd_intr_status0, unsigned int wcd_intr_status1,
+ unsigned int wcd_intr_status2);
#endif /* __WCD_COMMON_H___ */
diff --git a/sound/soc/codecs/wcd937x-sdw.c b/sound/soc/codecs/wcd937x-sdw.c
index 59c353cafd31..1878d67e3fa1 100644
--- a/sound/soc/codecs/wcd937x-sdw.c
+++ b/sound/soc/codecs/wcd937x-sdw.c
@@ -112,19 +112,6 @@ int wcd937x_sdw_hw_params(struct wcd937x_sdw_priv *wcd,
}
EXPORT_SYMBOL_GPL(wcd937x_sdw_hw_params);
-static int wcd9370_update_status(struct sdw_slave *slave, enum sdw_slave_status status)
-{
- struct wcd937x_sdw_priv *wcd = dev_get_drvdata(&slave->dev);
-
- if (wcd->regmap && status == SDW_SLAVE_ATTACHED) {
- /* Write out any cached changes that happened between probe and attach */
- regcache_cache_only(wcd->regmap, false);
- return regcache_sync(wcd->regmap);
- }
-
- return 0;
-}
-
/*
* Handle Soundwire out-of-band interrupt event by triggering
* the first irq of the slave_irq irq domain, which then will
@@ -135,18 +122,9 @@ static int wcd9370_interrupt_callback(struct sdw_slave *slave,
struct sdw_slave_intr_status *status)
{
struct wcd937x_sdw_priv *wcd = dev_get_drvdata(&slave->dev);
- struct irq_domain *slave_irq = wcd->slave_irq;
- u32 sts1, sts2, sts3;
-
- do {
- handle_nested_irq(irq_find_mapping(slave_irq, 0));
- regmap_read(wcd->regmap, WCD937X_DIGITAL_INTR_STATUS_0, &sts1);
- regmap_read(wcd->regmap, WCD937X_DIGITAL_INTR_STATUS_1, &sts2);
- regmap_read(wcd->regmap, WCD937X_DIGITAL_INTR_STATUS_2, &sts3);
-
- } while (sts1 || sts2 || sts3);
- return IRQ_HANDLED;
+ return wcd_interrupt_callback(slave, wcd->slave_irq, WCD937X_DIGITAL_INTR_STATUS_0,
+ WCD937X_DIGITAL_INTR_STATUS_1, WCD937X_DIGITAL_INTR_STATUS_2);
}
static const struct reg_default wcd937x_defaults[] = {
@@ -979,7 +957,7 @@ static const struct regmap_config wcd937x_regmap_config = {
};
static const struct sdw_slave_ops wcd9370_slave_ops = {
- .update_status = wcd9370_update_status,
+ .update_status = wcd_update_status,
.interrupt_callback = wcd9370_interrupt_callback,
};
diff --git a/sound/soc/codecs/wcd938x-sdw.c b/sound/soc/codecs/wcd938x-sdw.c
index 92714aef09d5..add907cb2706 100644
--- a/sound/soc/codecs/wcd938x-sdw.c
+++ b/sound/soc/codecs/wcd938x-sdw.c
@@ -20,8 +20,6 @@
#include "wcd938x.h"
#include "wcd-common.h"
-#define SWRS_SCP_HOST_CLK_DIV2_CTL_BANK(m) (0xE0 + 0x10 * (m))
-
static const struct wcd_sdw_ch_info wcd938x_sdw_rx_ch_info[] = {
WCD_SDW_CH(WCD938X_HPH_L, WCD938X_HPH_PORT, BIT(0)),
WCD_SDW_CH(WCD938X_HPH_R, WCD938X_HPH_PORT, BIT(1)),
@@ -142,44 +140,13 @@ int wcd938x_sdw_set_sdw_stream(struct wcd938x_sdw_priv *wcd,
}
EXPORT_SYMBOL_GPL(wcd938x_sdw_set_sdw_stream);
-static int wcd9380_update_status(struct sdw_slave *slave,
- enum sdw_slave_status status)
-{
- struct wcd938x_sdw_priv *wcd = dev_get_drvdata(&slave->dev);
-
- if (wcd->regmap && (status == SDW_SLAVE_ATTACHED)) {
- /* Write out any cached changes that happened between probe and attach */
- regcache_cache_only(wcd->regmap, false);
- return regcache_sync(wcd->regmap);
- }
-
- return 0;
-}
-
-static int wcd9380_bus_config(struct sdw_slave *slave,
- struct sdw_bus_params *params)
-{
- sdw_write(slave, SWRS_SCP_HOST_CLK_DIV2_CTL_BANK(params->next_bank), 0x01);
-
- return 0;
-}
-
static int wcd9380_interrupt_callback(struct sdw_slave *slave,
struct sdw_slave_intr_status *status)
{
struct wcd938x_sdw_priv *wcd = dev_get_drvdata(&slave->dev);
- struct irq_domain *slave_irq = wcd->slave_irq;
- u32 sts1, sts2, sts3;
-
- do {
- handle_nested_irq(irq_find_mapping(slave_irq, 0));
- regmap_read(wcd->regmap, WCD938X_DIGITAL_INTR_STATUS_0, &sts1);
- regmap_read(wcd->regmap, WCD938X_DIGITAL_INTR_STATUS_1, &sts2);
- regmap_read(wcd->regmap, WCD938X_DIGITAL_INTR_STATUS_2, &sts3);
-
- } while (sts1 || sts2 || sts3);
- return IRQ_HANDLED;
+ return wcd_interrupt_callback(slave, wcd->slave_irq, WCD938X_DIGITAL_INTR_STATUS_0,
+ WCD938X_DIGITAL_INTR_STATUS_1, WCD938X_DIGITAL_INTR_STATUS_2);
}
static const struct reg_default wcd938x_defaults[] = {
@@ -1177,9 +1144,9 @@ static const struct regmap_config wcd938x_regmap_config = {
};
static const struct sdw_slave_ops wcd9380_slave_ops = {
- .update_status = wcd9380_update_status,
+ .update_status = wcd_update_status,
.interrupt_callback = wcd9380_interrupt_callback,
- .bus_config = wcd9380_bus_config,
+ .bus_config = wcd_bus_config,
};
static int wcd9380_probe(struct sdw_slave *pdev,
diff --git a/sound/soc/codecs/wcd939x-sdw.c b/sound/soc/codecs/wcd939x-sdw.c
index 38da706d80be..d369100a2457 100644
--- a/sound/soc/codecs/wcd939x-sdw.c
+++ b/sound/soc/codecs/wcd939x-sdw.c
@@ -22,8 +22,6 @@
#include "wcd939x.h"
#include "wcd-common.h"
-#define SWRS_SCP_HOST_CLK_DIV2_CTL_BANK(m) (0xE0 + 0x10 * (m))
-
static const struct wcd_sdw_ch_info wcd939x_sdw_rx_ch_info[] = {
WCD_SDW_CH(WCD939X_HPH_L, WCD939X_HPH_PORT, BIT(0)),
WCD_SDW_CH(WCD939X_HPH_R, WCD939X_HPH_PORT, BIT(1)),
@@ -187,29 +185,6 @@ int wcd939x_sdw_set_sdw_stream(struct wcd939x_sdw_priv *wcd,
}
EXPORT_SYMBOL_GPL(wcd939x_sdw_set_sdw_stream);
-static int wcd9390_update_status(struct sdw_slave *slave,
- enum sdw_slave_status status)
-{
- struct wcd939x_sdw_priv *wcd = dev_get_drvdata(&slave->dev);
-
- if (wcd->regmap && status == SDW_SLAVE_ATTACHED) {
- /* Write out any cached changes that happened between probe and attach */
- regcache_cache_only(wcd->regmap, false);
- return regcache_sync(wcd->regmap);
- }
-
- return 0;
-}
-
-static int wcd9390_bus_config(struct sdw_slave *slave,
- struct sdw_bus_params *params)
-{
- sdw_write(slave, SWRS_SCP_HOST_CLK_DIV2_CTL_BANK(params->next_bank),
- 0x01);
-
- return 0;
-}
-
/*
* Handle Soundwire out-of-band interrupt event by triggering
* the first irq of the slave_irq irq domain, which then will
@@ -220,18 +195,9 @@ static int wcd9390_interrupt_callback(struct sdw_slave *slave,
struct sdw_slave_intr_status *status)
{
struct wcd939x_sdw_priv *wcd = dev_get_drvdata(&slave->dev);
- struct irq_domain *slave_irq = wcd->slave_irq;
- u32 sts1, sts2, sts3;
-
- do {
- handle_nested_irq(irq_find_mapping(slave_irq, 0));
- regmap_read(wcd->regmap, WCD939X_DIGITAL_INTR_STATUS_0, &sts1);
- regmap_read(wcd->regmap, WCD939X_DIGITAL_INTR_STATUS_1, &sts2);
- regmap_read(wcd->regmap, WCD939X_DIGITAL_INTR_STATUS_2, &sts3);
-
- } while (sts1 || sts2 || sts3);
- return IRQ_HANDLED;
+ return wcd_interrupt_callback(slave, wcd->slave_irq, WCD939X_DIGITAL_INTR_STATUS_0,
+ WCD939X_DIGITAL_INTR_STATUS_1, WCD939X_DIGITAL_INTR_STATUS_2);
}
static const struct reg_default wcd939x_defaults[] = {
@@ -1364,9 +1330,9 @@ static const struct regmap_config wcd939x_regmap_config = {
};
static const struct sdw_slave_ops wcd9390_slave_ops = {
- .update_status = wcd9390_update_status,
+ .update_status = wcd_update_status,
.interrupt_callback = wcd9390_interrupt_callback,
- .bus_config = wcd9390_bus_config,
+ .bus_config = wcd_bus_config,
};
static int wcd9390_probe(struct sdw_slave *pdev, const struct sdw_device_id *id)
--
2.50.0
^ permalink raw reply related [flat|nested] 24+ messages in thread* Re: [PATCH v3 10/12] ASoC: codecs: wcd-common: move status_update callback to common
2025-09-05 15:44 ` [PATCH v3 10/12] ASoC: codecs: wcd-common: move status_update callback to common Srinivas Kandagatla
@ 2025-09-05 16:44 ` Dmitry Baryshkov
0 siblings, 0 replies; 24+ messages in thread
From: Dmitry Baryshkov @ 2025-09-05 16:44 UTC (permalink / raw)
To: Srinivas Kandagatla
Cc: broonie, lgirdwood, tiwai, vkoul, srini, yung-chuan.liao,
pierre-louis.bossart, linux-arm-msm, linux-kernel, neil.armstrong,
krzysztof.kozlowski, linux-sound
On Fri, Sep 05, 2025 at 04:44:28PM +0100, Srinivas Kandagatla wrote:
> Soundwire update_status, bus_config and interrupt callbacks for wcd937x,
> wcd938x, wcd939x soundwire codecs are exactly identlical, move them to
> common driver to remove this duplicate code.
>
> Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
> ---
> sound/soc/codecs/wcd-common.c | 46 ++++++++++++++++++++++++++++++++++
> sound/soc/codecs/wcd-common.h | 5 ++++
> sound/soc/codecs/wcd937x-sdw.c | 28 +++------------------
> sound/soc/codecs/wcd938x-sdw.c | 41 +++---------------------------
> sound/soc/codecs/wcd939x-sdw.c | 42 +++----------------------------
> 5 files changed, 62 insertions(+), 100 deletions(-)
>
Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
--
With best wishes
Dmitry
^ permalink raw reply [flat|nested] 24+ messages in thread
* [PATCH v3 11/12] ASoC: codecs: wcd938x: get regmap directly
2025-09-05 15:44 [PATCH v3 00/12] ASoC: codecs: wcd93xxx: remove code duplication Srinivas Kandagatla
` (9 preceding siblings ...)
2025-09-05 15:44 ` [PATCH v3 10/12] ASoC: codecs: wcd-common: move status_update callback to common Srinivas Kandagatla
@ 2025-09-05 15:44 ` Srinivas Kandagatla
2025-09-05 16:45 ` Dmitry Baryshkov
2025-09-05 15:44 ` [PATCH v3 12/12] ASoC: codecs: wcd937x: " Srinivas Kandagatla
11 siblings, 1 reply; 24+ messages in thread
From: Srinivas Kandagatla @ 2025-09-05 15:44 UTC (permalink / raw)
To: broonie
Cc: lgirdwood, tiwai, vkoul, srini, yung-chuan.liao,
pierre-louis.bossart, linux-arm-msm, linux-kernel, neil.armstrong,
krzysztof.kozlowski, dmitry.baryshkov, linux-sound,
Srinivas Kandagatla
Remove usage of dev_get_regmap, as this its more efficient to directly
reference the pointer.
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
---
sound/soc/codecs/wcd938x.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/sound/soc/codecs/wcd938x.c b/sound/soc/codecs/wcd938x.c
index e495f98972f1..e1a4783b984c 100644
--- a/sound/soc/codecs/wcd938x.c
+++ b/sound/soc/codecs/wcd938x.c
@@ -3389,7 +3389,7 @@ static int wcd938x_bind(struct device *dev)
goto err_remove_tx_link;
}
- wcd938x->regmap = dev_get_regmap(&wcd938x->tx_sdw_dev->dev, NULL);
+ wcd938x->regmap = wcd938x->sdw_priv[AIF1_CAP]->regmap;
if (!wcd938x->regmap) {
dev_err(dev, "could not get TX device regmap\n");
ret = -EINVAL;
--
2.50.0
^ permalink raw reply related [flat|nested] 24+ messages in thread* Re: [PATCH v3 11/12] ASoC: codecs: wcd938x: get regmap directly
2025-09-05 15:44 ` [PATCH v3 11/12] ASoC: codecs: wcd938x: get regmap directly Srinivas Kandagatla
@ 2025-09-05 16:45 ` Dmitry Baryshkov
0 siblings, 0 replies; 24+ messages in thread
From: Dmitry Baryshkov @ 2025-09-05 16:45 UTC (permalink / raw)
To: Srinivas Kandagatla
Cc: broonie, lgirdwood, tiwai, vkoul, srini, yung-chuan.liao,
pierre-louis.bossart, linux-arm-msm, linux-kernel, neil.armstrong,
krzysztof.kozlowski, linux-sound
On Fri, Sep 05, 2025 at 04:44:29PM +0100, Srinivas Kandagatla wrote:
> Remove usage of dev_get_regmap, as this its more efficient to directly
> reference the pointer.
>
> Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
> ---
> sound/soc/codecs/wcd938x.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
--
With best wishes
Dmitry
^ permalink raw reply [flat|nested] 24+ messages in thread
* [PATCH v3 12/12] ASoC: codecs: wcd937x: get regmap directly
2025-09-05 15:44 [PATCH v3 00/12] ASoC: codecs: wcd93xxx: remove code duplication Srinivas Kandagatla
` (10 preceding siblings ...)
2025-09-05 15:44 ` [PATCH v3 11/12] ASoC: codecs: wcd938x: get regmap directly Srinivas Kandagatla
@ 2025-09-05 15:44 ` Srinivas Kandagatla
2025-09-05 16:45 ` Dmitry Baryshkov
11 siblings, 1 reply; 24+ messages in thread
From: Srinivas Kandagatla @ 2025-09-05 15:44 UTC (permalink / raw)
To: broonie
Cc: lgirdwood, tiwai, vkoul, srini, yung-chuan.liao,
pierre-louis.bossart, linux-arm-msm, linux-kernel, neil.armstrong,
krzysztof.kozlowski, dmitry.baryshkov, linux-sound,
Srinivas Kandagatla
Remove usage of dev_get_regmap, as this its more efficient to directly
reference the pointer.
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
---
sound/soc/codecs/wcd937x.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/sound/soc/codecs/wcd937x.c b/sound/soc/codecs/wcd937x.c
index 5c8faff3976d..2064d707ab0a 100644
--- a/sound/soc/codecs/wcd937x.c
+++ b/sound/soc/codecs/wcd937x.c
@@ -2790,7 +2790,7 @@ static int wcd937x_bind(struct device *dev)
return -EINVAL;
}
- wcd937x->regmap = dev_get_regmap(&wcd937x->tx_sdw_dev->dev, NULL);
+ wcd937x->regmap = wcd937x->sdw_priv[AIF1_CAP]->regmap;
if (!wcd937x->regmap) {
dev_err(dev, "could not get TX device regmap\n");
return -EINVAL;
--
2.50.0
^ permalink raw reply related [flat|nested] 24+ messages in thread* Re: [PATCH v3 12/12] ASoC: codecs: wcd937x: get regmap directly
2025-09-05 15:44 ` [PATCH v3 12/12] ASoC: codecs: wcd937x: " Srinivas Kandagatla
@ 2025-09-05 16:45 ` Dmitry Baryshkov
0 siblings, 0 replies; 24+ messages in thread
From: Dmitry Baryshkov @ 2025-09-05 16:45 UTC (permalink / raw)
To: Srinivas Kandagatla
Cc: broonie, lgirdwood, tiwai, vkoul, srini, yung-chuan.liao,
pierre-louis.bossart, linux-arm-msm, linux-kernel, neil.armstrong,
krzysztof.kozlowski, linux-sound
On Fri, Sep 05, 2025 at 04:44:30PM +0100, Srinivas Kandagatla wrote:
> Remove usage of dev_get_regmap, as this its more efficient to directly
> reference the pointer.
>
> Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
> ---
> sound/soc/codecs/wcd937x.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
--
With best wishes
Dmitry
^ permalink raw reply [flat|nested] 24+ messages in thread