From 8db18bfba8b13e1115c1781f04ed57fef0c89d3e Mon Sep 17 00:00:00 2001 From: Bard Liao Date: Thu, 5 Feb 2026 10:50:33 +0800 Subject: [PATCH 1/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 --- 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 fb68738dfb9b84..e45aa91a0e8732 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 66ec70930d77ca..cde3383c54bb2e 100644 --- a/drivers/soundwire/stream.c +++ b/drivers/soundwire/stream.c @@ -699,11 +699,15 @@ 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; + ret = sdw_write_no_pm(slave, addr1, scale_index); if (ret < 0) { 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 f462717acf2062..ce8fb05f9a4fda 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; }; #define dev_to_sdw_dev(_dev) container_of(_dev, struct sdw_slave, dev) From 4e03732816655b93a2919f51ce789325f75eb402 Mon Sep 17 00:00:00 2001 From: Bard Liao Date: Fri, 6 Feb 2026 09:19:31 +0800 Subject: [PATCH 2/2] soundwire: don't program SDW_SCP_BUSCLOCK_SCALE on a unattaced Peripheral The SDW_SCP_BUSCLOCK_SCALE register will be programed when the Peripheral is attached. We can and should skip programing the SDW_SCP_BUSCLOCK_SCALE register when the Peripheral is unattached. Signed-off-by: Bard Liao --- drivers/soundwire/stream.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/soundwire/stream.c b/drivers/soundwire/stream.c index cde3383c54bb2e..b048fe5bb220c1 100644 --- a/drivers/soundwire/stream.c +++ b/drivers/soundwire/stream.c @@ -702,6 +702,12 @@ static int sdw_program_params(struct sdw_bus *bus, bool prepare) if (scale_index == slave->scale_index) continue; + /* Skip the unattached Peripherals */ + if (!completion_done(&slave->enumeration_complete)) { + dev_warn(&slave->dev, + "Not enumerated, skip programing BUSCLOCK_SCALE\n"); + continue; + } ret = sdw_write_no_pm(slave, addr1, scale_index); if (ret < 0) { dev_err(&slave->dev, "SDW_SCP_BUSCLOCK_SCALE register write failed\n");