From: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
There has been 2 instances of this helper in codec drivers,
it does not make sense to keep duplicating this part of code.
Lets add a helper sdw_get_current_bank() for codec drivers to use it.
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
---
drivers/soundwire/bus.c | 7 +++++++
include/linux/soundwire/sdw.h | 8 ++++++++
2 files changed, 15 insertions(+)
diff --git a/drivers/soundwire/bus.c b/drivers/soundwire/bus.c
index 39aecd34c641..58306c515ccc 100644
--- a/drivers/soundwire/bus.c
+++ b/drivers/soundwire/bus.c
@@ -1363,6 +1363,13 @@ int sdw_slave_get_scale_index(struct sdw_slave *slave, u8 *base)
}
EXPORT_SYMBOL(sdw_slave_get_scale_index);
+int sdw_slave_get_current_bank(struct sdw_slave *sdev)
+{
+ return FIELD_GET(SDW_SCP_STAT_CURR_BANK,
+ sdw_read(sdev, SDW_SCP_CTRL));
+}
+EXPORT_SYMBOL_GPL(sdw_slave_get_current_bank);
+
static int sdw_slave_set_frequency(struct sdw_slave *slave)
{
int scale_index;
diff --git a/include/linux/soundwire/sdw.h b/include/linux/soundwire/sdw.h
index 84d1a101b155..41c36470ad2d 100644
--- a/include/linux/soundwire/sdw.h
+++ b/include/linux/soundwire/sdw.h
@@ -1083,6 +1083,8 @@ int sdw_stream_remove_slave(struct sdw_slave *slave,
struct device *of_sdw_find_device_by_node(struct device_node *np);
+int sdw_slave_get_current_bank(struct sdw_slave *sdev);
+
int sdw_slave_get_scale_index(struct sdw_slave *slave, u8 *base);
/* messaging and data APIs */
@@ -1122,6 +1124,12 @@ static inline struct device *of_sdw_find_device_by_node(struct device_node *np)
return NULL;
}
+static inline int sdw_slave_get_current_bank(struct sdw_slave *sdev)
+{
+ WARN_ONCE(1, "SoundWire API is disabled");
+ return -EINVAL;
+}
+
/* messaging and data APIs */
static inline int sdw_read(struct sdw_slave *slave, u32 addr)
{
--
2.49.0
On 6/27/25 5:51 PM, srinivas.kandagatla@oss.qualcomm.com wrote:
> From: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
>
> There has been 2 instances of this helper in codec drivers,
> it does not make sense to keep duplicating this part of code.
>
> Lets add a helper sdw_get_current_bank() for codec drivers to use it.
>
> Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
> ---
> drivers/soundwire/bus.c | 7 +++++++
> include/linux/soundwire/sdw.h | 8 ++++++++
> 2 files changed, 15 insertions(+)
>
> diff --git a/drivers/soundwire/bus.c b/drivers/soundwire/bus.c
> index 39aecd34c641..58306c515ccc 100644
> --- a/drivers/soundwire/bus.c
> +++ b/drivers/soundwire/bus.c
> @@ -1363,6 +1363,13 @@ int sdw_slave_get_scale_index(struct sdw_slave *slave, u8 *base)
> }
> EXPORT_SYMBOL(sdw_slave_get_scale_index);
>
> +int sdw_slave_get_current_bank(struct sdw_slave *sdev)
> +{
> + return FIELD_GET(SDW_SCP_STAT_CURR_BANK,
> + sdw_read(sdev, SDW_SCP_CTRL));
sdw_read can fail (miserably)
Konrad
On 6/27/25 4:54 PM, Konrad Dybcio wrote:
> On 6/27/25 5:51 PM, srinivas.kandagatla@oss.qualcomm.com wrote:
>> From: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
>>
>> There has been 2 instances of this helper in codec drivers,
>> it does not make sense to keep duplicating this part of code.
>>
>> Lets add a helper sdw_get_current_bank() for codec drivers to use it.
>>
>> Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
>> ---
>> drivers/soundwire/bus.c | 7 +++++++
>> include/linux/soundwire/sdw.h | 8 ++++++++
>> 2 files changed, 15 insertions(+)
>>
>> diff --git a/drivers/soundwire/bus.c b/drivers/soundwire/bus.c
>> index 39aecd34c641..58306c515ccc 100644
>> --- a/drivers/soundwire/bus.c
>> +++ b/drivers/soundwire/bus.c
>> @@ -1363,6 +1363,13 @@ int sdw_slave_get_scale_index(struct sdw_slave *slave, u8 *base)
>> }
>> EXPORT_SYMBOL(sdw_slave_get_scale_index);
>>
>> +int sdw_slave_get_current_bank(struct sdw_slave *sdev)
>> +{
>> + return FIELD_GET(SDW_SCP_STAT_CURR_BANK,
>> + sdw_read(sdev, SDW_SCP_CTRL));
>
> sdw_read can fail (miserably)
I agree, will add check in v2.
--srini
>
> Konrad
© 2016 - 2026 Red Hat, Inc.