RE: [PATCH 2/2] soundwire: record Peripheral scale_index

From: Liao, Bard

Date: Tue Apr 21 2026 - 21:17:54 EST




> -----Original Message-----
> From: Bard Liao <yung-chuan.liao@xxxxxxxxxxxxxxx>
> Sent: Wednesday, March 25, 2026 7:42 PM
> To: linux-sound@xxxxxxxxxxxxxxx; vkoul@xxxxxxxxxx
> Cc: vinod.koul@xxxxxxxxxx; linux-kernel@xxxxxxxxxxxxxxx; pierre-
> louis.bossart@xxxxxxxxx; peter.ujfalusi@xxxxxxxxxxxxxxx; Liao, Bard
> <bard.liao@xxxxxxxxx>
> Subject: [PATCH 2/2] soundwire: record Peripheral scale_index
>
> Currently, we program bus clock scale index unconditionally. It is not
> necessary if the new index is the same as the current one.
>
> Signed-off-by: Bard Liao <yung-chuan.liao@xxxxxxxxxxxxxxx>
> Reviewed-by: Simon Trimmer <simont@xxxxxxxxxxxxxxxxxxxxx>
> Reviewed-by: Péter Ujfalusi <peter.ujfalusi@xxxxxxxxxxxxxxx>
> Reviewed-by: Ranjani Sridharan <ranjani.sridharan@xxxxxxxxxxxxxxx>
> ---
> drivers/soundwire/bus.c | 1 +
> drivers/soundwire/stream.c | 4 ++++
> include/linux/soundwire/sdw.h | 2 ++
> 3 files changed, 7 insertions(+)
>
> diff --git a/drivers/soundwire/bus.c b/drivers/soundwire/bus.c
> index fe5316d93fef..acecbdcf52ec 100644
> --- a/drivers/soundwire/bus.c
> +++ b/drivers/soundwire/bus.c
> @@ -1411,6 +1411,7 @@ static int sdw_slave_set_frequency(struct
> sdw_slave *slave)
> dev_err(&slave->dev,
> "SDW_SCP_BUSCLOCK_SCALE_B1 write failed:%d\n",
> ret);
>
> + slave->scale_index = scale_index;
> return ret;
> }
>
> diff --git a/drivers/soundwire/stream.c b/drivers/soundwire/stream.c
> index 0b9626838028..a6f0255c1c25 100644
> --- a/drivers/soundwire/stream.c
> +++ b/drivers/soundwire/stream.c
> @@ -697,6 +697,9 @@ static int sdw_program_params(struct sdw_bus
> *bus, bool prepare)
> if (scale_index < 0)
> return scale_index;
>
> + if (scale_index == slave->scale_index)
> + continue;
> +
> /* Skip the unattached Peripherals */
> if (!completion_done(&slave->enumeration_complete)) {
> dev_warn(&slave->dev,
> @@ -709,6 +712,7 @@ static int sdw_program_params(struct sdw_bus
> *bus, bool prepare)
> dev_err(&slave->dev, "SDW_SCP_BUSCLOCK_SCALE
> register write failed\n");
> return ret;
> }
> + slave->scale_index = scale_index;
> }
>
> manager_runtime:
> diff --git a/include/linux/soundwire/sdw.h b/include/linux/soundwire/sdw.h
> index 6147eb1fb210..0845182f75f9 100644
> --- a/include/linux/soundwire/sdw.h
> +++ b/include/linux/soundwire/sdw.h
> @@ -661,6 +661,7 @@ struct sdw_slave_ops {
> * protocol for SoundWire mockup devices
> * @sdw_dev_lock: mutex used to protect callbacks/remove races
> * @sdca_data: structure containing all device data for SDCA helpers
> + * @scale_index: current bus clock scaling index
> */
> struct sdw_slave {
> struct sdw_slave_id id;
> @@ -686,6 +687,7 @@ struct sdw_slave {
> bool is_mockup_device;
> struct mutex sdw_dev_lock; /* protect callbacks/remove races */
> struct sdca_device_data sdca_data;
> + unsigned int scale_index;

We need to store the scale index for both banks.
Will update in v2.

> };
>
> #define dev_to_sdw_dev(_dev) container_of(_dev, struct sdw_slave, dev)
> --
> 2.43.0