From: Bard Liao <yung-chuan.liao@linux.intel.com>
To: linux-sound@vger.kernel.org, vkoul@kernel.org
Cc: vinod.koul@linaro.org, linux-kernel@vger.kernel.org,
pierre-louis.bossart@linux.dev, bard.liao@intel.com
Subject: [PATCH v3 07/14] Soundwire: stream: program BUSCLOCK_SCALE
Date: Wed, 18 Dec 2024 16:01:48 +0800 [thread overview]
Message-ID: <20241218080155.102405-8-yung-chuan.liao@linux.intel.com> (raw)
In-Reply-To: <20241218080155.102405-1-yung-chuan.liao@linux.intel.com>
We need to program bus clock scale to adjust the bus clock if current
bus clock doesn't fit the bandwidth.
Signed-off-by: Bard Liao <yung-chuan.liao@linux.intel.com>
Reviewed-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
---
drivers/soundwire/bus.c | 10 ++++++++++
drivers/soundwire/stream.c | 36 +++++++++++++++++++++++++++++++++++
include/linux/soundwire/sdw.h | 1 +
3 files changed, 47 insertions(+)
diff --git a/drivers/soundwire/bus.c b/drivers/soundwire/bus.c
index 215630d602ad..9b295fc9acd5 100644
--- a/drivers/soundwire/bus.c
+++ b/drivers/soundwire/bus.c
@@ -813,6 +813,16 @@ void sdw_extract_slave_id(struct sdw_bus *bus,
}
EXPORT_SYMBOL(sdw_extract_slave_id);
+bool is_clock_scaling_supported_by_slave(struct sdw_slave *slave)
+{
+ /*
+ * Dynamic scaling is a defined by SDCA. However, some devices expose the class ID but
+ * can't support dynamic scaling. We might need a quirk to handle such devices.
+ */
+ return slave->id.class_id;
+}
+EXPORT_SYMBOL(is_clock_scaling_supported_by_slave);
+
static int sdw_program_device_num(struct sdw_bus *bus, bool *programmed)
{
u8 buf[SDW_NUM_DEV_ID_REGISTERS] = {0};
diff --git a/drivers/soundwire/stream.c b/drivers/soundwire/stream.c
index 795017c8081a..bf04b941012c 100644
--- a/drivers/soundwire/stream.c
+++ b/drivers/soundwire/stream.c
@@ -629,8 +629,44 @@ static int sdw_notify_config(struct sdw_master_runtime *m_rt)
static int sdw_program_params(struct sdw_bus *bus, bool prepare)
{
struct sdw_master_runtime *m_rt;
+ struct sdw_slave *slave;
int ret = 0;
+ u32 addr1;
+ /* Check if all Peripherals comply with SDCA */
+ list_for_each_entry(slave, &bus->slaves, node) {
+ if (!slave->dev_num_sticky)
+ continue;
+ if (!is_clock_scaling_supported_by_slave(slave)) {
+ dev_dbg(&slave->dev, "The Peripheral doesn't comply with SDCA\n");
+ goto manager_runtime;
+ }
+ }
+
+ if (bus->params.next_bank)
+ addr1 = SDW_SCP_BUSCLOCK_SCALE_B1;
+ else
+ addr1 = SDW_SCP_BUSCLOCK_SCALE_B0;
+
+ /* Program SDW_SCP_BUSCLOCK_SCALE if all Peripherals comply with SDCA */
+ list_for_each_entry(slave, &bus->slaves, node) {
+ int scale_index;
+ u8 base;
+
+ if (!slave->dev_num_sticky)
+ continue;
+ scale_index = sdw_slave_get_scale_index(slave, &base);
+ if (scale_index < 0)
+ return scale_index;
+
+ 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;
+ }
+ }
+
+manager_runtime:
list_for_each_entry(m_rt, &bus->m_rt_list, bus_node) {
/*
diff --git a/include/linux/soundwire/sdw.h b/include/linux/soundwire/sdw.h
index 05a85e2bd96d..fc0a203c3ae0 100644
--- a/include/linux/soundwire/sdw.h
+++ b/include/linux/soundwire/sdw.h
@@ -1041,6 +1041,7 @@ int sdw_bus_exit_clk_stop(struct sdw_bus *bus);
int sdw_compare_devid(struct sdw_slave *slave, struct sdw_slave_id id);
void sdw_extract_slave_id(struct sdw_bus *bus, u64 addr, struct sdw_slave_id *id);
+bool is_clock_scaling_supported_by_slave(struct sdw_slave *slave);
#if IS_ENABLED(CONFIG_SOUNDWIRE)
--
2.43.0
next prev parent reply other threads:[~2024-12-18 8:02 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-18 8:01 [PATCH v3 00/14] soundwire: add multi-lane support Bard Liao
2024-12-18 8:01 ` [PATCH v3 01/14] soundwire: add lane field in sdw_port_runtime Bard Liao
2024-12-18 8:01 ` [PATCH v3 02/14] soundwire: mipi_disco: read lane mapping properties from ACPI Bard Liao
2024-12-18 8:01 ` [PATCH v3 03/14] soundwire: add lane_used_bandwidth in struct sdw_bus Bard Liao
2024-12-18 8:01 ` [PATCH v3 04/14] soundwire: stream: set DEPREPARED state earlier Bard Liao
2024-12-18 8:01 ` [PATCH v3 05/14] soundwire: generic_bandwidth_allocation: skip DEPREPARED streams Bard Liao
2024-12-18 8:01 ` [PATCH v3 06/14] Soundwire: add sdw_slave_get_scale_index helper Bard Liao
2024-12-18 8:01 ` Bard Liao [this message]
2024-12-18 8:01 ` [PATCH v3 08/14] Soundwire: generic_bandwidth_allocation: set frame shape on fly Bard Liao
2024-12-18 8:01 ` [PATCH v3 09/14] soundwire: generic_bandwidth_allocation: correct clk_freq check in sdw_select_row_col Bard Liao
2024-12-18 8:01 ` [PATCH v3 10/14] soundwire: generic_bandwidth_allocation: check required freq accurately Bard Liao
2024-12-18 8:01 ` [PATCH v3 11/14] soundwire: generic_bandwidth_allocation: select data lane Bard Liao
2024-12-18 8:01 ` [PATCH v3 12/14] soundwire: generic_bandwidth_allocation: add lane in sdw_group_params Bard Liao
2024-12-18 8:01 ` [PATCH v3 13/14] SoundWire: pass stream to compute_params() Bard Liao
2024-12-18 8:01 ` [PATCH v3 14/14] soundwire: generic_bandwidth_allocation: count the bandwidth of active streams only Bard Liao
2024-12-23 9:12 ` [PATCH v3 00/14] soundwire: add multi-lane support Vinod Koul
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241218080155.102405-8-yung-chuan.liao@linux.intel.com \
--to=yung-chuan.liao@linux.intel.com \
--cc=bard.liao@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=pierre-louis.bossart@linux.dev \
--cc=vinod.koul@linaro.org \
--cc=vkoul@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®