[PATCH 2/2] soundwire: record Peripheral scale_index

Bard Liao posted 2 patches 1 week, 1 day ago
[PATCH 2/2] soundwire: record Peripheral scale_index
Posted by Bard Liao 1 week, 1 day ago
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@linux.intel.com>
Reviewed-by: Simon Trimmer <simont@opensource.cirrus.com>
Reviewed-by: Péter Ujfalusi <peter.ujfalusi@linux.intel.com>
Reviewed-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
---
 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;
 };
 
 #define dev_to_sdw_dev(_dev) container_of(_dev, struct sdw_slave, dev)
-- 
2.43.0