From nobody Mon Feb 9 10:30:18 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7594E12BF23 for ; Wed, 14 Feb 2024 18:30:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707935435; cv=none; b=RiO1hVzT9W07Hh/QHN7p8ErB/RqR0yXYCbimyG0YcndRzDumKeqF1J46utp0v+fCtNpDVpvLis1YkYLLOrsQQw9F4ACEGI6sF9RUOSJaKpdovk4y2bmyRZxVUXRUhDud4Lzar9wHkUr8NAcUC+v5PXZhtmfT0Pim5Jtpm4ARgYs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707935435; c=relaxed/simple; bh=L7rCObjeJJ/6znwFBtlQDxE88+afFeZnyW7f58K3Lx8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=A2ApI2Hjq7lLD6/Xj1LRQqYLpYFng5tN2Ov48qjQq8VnRUFFy3itQJwla3TVhhYIFGlv9NT/AIeuLWP2bPHmDCOk4Zox4cU0DKsoh/GBsUnm8ctSY6wqw3l2iBDebJau75EgFxpAIix7eSG+elg2aawvv+ygKZcuU34JEwgU//M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 9AB90DA7; Wed, 14 Feb 2024 10:31:13 -0800 (PST) Received: from pluto.fritz.box (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E92FE3F7B4; Wed, 14 Feb 2024 10:30:30 -0800 (PST) From: Cristian Marussi To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: sudeep.holla@arm.com, james.quinlan@broadcom.com, f.fainelli@gmail.com, vincent.guittot@linaro.org, peng.fan@oss.nxp.com, michal.simek@amd.com, quic_sibis@quicinc.com, quic_nkela@quicinc.com, souvik.chakravarty@arm.com, Cristian Marussi Subject: [PATCH 1/7] firmware: arm_scmi: Add a common helper to check if a message is supported Date: Wed, 14 Feb 2024 18:30:00 +0000 Message-ID: <20240214183006.3403207-2-cristian.marussi@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240214183006.3403207-1-cristian.marussi@arm.com> References: <20240214183006.3403207-1-cristian.marussi@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" A common helper is provided to check if a specific protocol message is supported or not. Signed-off-by: Cristian Marussi --- drivers/firmware/arm_scmi/driver.c | 34 +++++++++++++++++++++++++++ drivers/firmware/arm_scmi/protocols.h | 4 ++++ 2 files changed, 38 insertions(+) diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi= /driver.c index 3ea64b22cf0d..4a64ad5c21ee 100644 --- a/drivers/firmware/arm_scmi/driver.c +++ b/drivers/firmware/arm_scmi/driver.c @@ -1754,10 +1754,44 @@ static void scmi_common_fastchannel_db_ring(struct = scmi_fc_db_info *db) #endif } =20 +/** + * scmi_protocol_msg_check - Check protocol message attributes + * + * @ph: A reference to the protocol handle. + * @message_id: The ID of the message to check. + * @attributes: A parameter to optionally return the retrieved message + * attributes, in case of Success. + * + * An helper to check protocol message attributes for a specific protocol + * and message pair. + * + * Return: 0 on SUCCESS + */ +static int scmi_protocol_msg_check(const struct scmi_protocol_handle *ph, + u32 message_id, u32 *attributes) +{ + int ret; + struct scmi_xfer *t; + + ret =3D xfer_get_init(ph, PROTOCOL_MESSAGE_ATTRIBUTES, + sizeof(__le32), 0, &t); + if (ret) + return ret; + + put_unaligned_le32(message_id, t->tx.buf); + ret =3D do_xfer(ph, t); + if (!ret && attributes) + *attributes =3D get_unaligned_le32(t->rx.buf); + xfer_put(ph, t); + + return ret; +} + static const struct scmi_proto_helpers_ops helpers_ops =3D { .extended_name_get =3D scmi_common_extended_name_get, .iter_response_init =3D scmi_iterator_init, .iter_response_run =3D scmi_iterator_run, + .protocol_msg_check =3D scmi_protocol_msg_check, .fastchannel_init =3D scmi_common_fastchannel_init, .fastchannel_db_ring =3D scmi_common_fastchannel_db_ring, }; diff --git a/drivers/firmware/arm_scmi/protocols.h b/drivers/firmware/arm_s= cmi/protocols.h index e683c26f24eb..26a3edd49fea 100644 --- a/drivers/firmware/arm_scmi/protocols.h +++ b/drivers/firmware/arm_scmi/protocols.h @@ -251,6 +251,8 @@ struct scmi_fc_info { * provided in @ops. * @iter_response_run: A common helper to trigger the run of a previously * initialized iterator. + * @protocol_msg_check: A common helper to check is a specific protocol me= ssage + * is supported. * @fastchannel_init: A common helper used to initialize FC descriptors by * gathering FC descriptions from the SCMI platform server. * @fastchannel_db_ring: A common helper to ring a FC doorbell. @@ -264,6 +266,8 @@ struct scmi_proto_helpers_ops { unsigned int max_resources, u8 msg_id, size_t tx_size, void *priv); int (*iter_response_run)(void *iter); + int (*protocol_msg_check)(const struct scmi_protocol_handle *ph, + u32 message_id, u32 *attributes); void (*fastchannel_init)(const struct scmi_protocol_handle *ph, u8 describe_id, u32 message_id, u32 valid_size, u32 domain, --=20 2.43.0 From nobody Mon Feb 9 10:30:18 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3FC1612BF1C for ; Wed, 14 Feb 2024 18:30:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707935437; cv=none; b=HmageslhNHufQEYklkOly2FwqQPsoEymNTgyF/A0T0wXolX0WfZBTOncn3NZg4cuHSdfdcSJKZZDzXVM/2TLF6UzNL/fTwhXKkKeBQnnrxoe7MSe4QdWGaEb9lr+Bm3KA30koC4HdfC1SzR3jQFeknsU2cRdf/zFhu9e+s8sfrc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707935437; c=relaxed/simple; bh=aLQIYcBnbK+esT1CQfwNNNQB4YwDBeNIL7pYpzFWpYU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ivQzZYg3ShBEs1x34ivgVP0H+TDV5O43nQDbySxMrYts2ilFGWkAoyA3kZNQ4blHEKDxKEXdmLMgMIGbCC2pp4esMyokH80iJ7DU+nIE/pONMt9f8KAZT7Ye/qH9HmLcP0GXye/1sbBxG9ICXdFrsJspBI94k5OSAUEsEsQFnZM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 8B94A1476; Wed, 14 Feb 2024 10:31:15 -0800 (PST) Received: from pluto.fritz.box (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id DC2173F7B4; Wed, 14 Feb 2024 10:30:32 -0800 (PST) From: Cristian Marussi To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: sudeep.holla@arm.com, james.quinlan@broadcom.com, f.fainelli@gmail.com, vincent.guittot@linaro.org, peng.fan@oss.nxp.com, michal.simek@amd.com, quic_sibis@quicinc.com, quic_nkela@quicinc.com, souvik.chakravarty@arm.com, Cristian Marussi Subject: [PATCH 2/7] firmware: arm_scmi: Add support for v3.2 NEGOTIATE_PROTOCOL_VERSION Date: Wed, 14 Feb 2024 18:30:01 +0000 Message-ID: <20240214183006.3403207-3-cristian.marussi@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240214183006.3403207-1-cristian.marussi@arm.com> References: <20240214183006.3403207-1-cristian.marussi@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Freshly introduced NEGOTIATE_PROTOCOL_VERSION allows the agent to ascertain upfront if a specific, usually older, protocol version is supported by the platform. It is used by the agent in case the platform has advertised the support of a newer protocol version than the latest version supported by the agent, since backward compatibility cannot be automatically assumed. Emit a warning about possible incompatibility when negotiation was not possible or just print the successfully negotiated protocol. Signed-off-by: Cristian Marussi --- drivers/firmware/arm_scmi/driver.c | 65 ++++++++++++++++++++++++--- drivers/firmware/arm_scmi/protocols.h | 1 + 2 files changed, 61 insertions(+), 5 deletions(-) diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi= /driver.c index 4a64ad5c21ee..34d77802c990 100644 --- a/drivers/firmware/arm_scmi/driver.c +++ b/drivers/firmware/arm_scmi/driver.c @@ -86,6 +86,12 @@ struct scmi_xfers_info { * @users: A refcount to track effective users of this protocol. * @priv: Reference for optional protocol private data. * @version: Protocol version supported by the platform as detected at run= time. + * @negotiated_version: When the platform supports a newer protocol versio= n, + * the agent will try to negotiate with the platform the + * usage of the newest version known to it, since + * backward compatibility is NOT automatically assured. + * This field is NON-zero when a successful negotiation + * has completed. * @ph: An embedded protocol handle that will be passed down to protocol * initialization code to identify this instance. * @@ -99,6 +105,7 @@ struct scmi_protocol_instance { refcount_t users; void *priv; unsigned int version; + unsigned int negotiated_version; struct scmi_protocol_handle ph; }; =20 @@ -1815,6 +1822,44 @@ scmi_revision_area_get(const struct scmi_protocol_ha= ndle *ph) return pi->handle->version; } =20 +/** + * scmi_protocol_version_negotiate - Negotiate protocol version + * + * @ph: A reference to the protocol handle. + * + * An helper to negotiate a protocol version different from the latest + * advertised as supported from the platform: on Success backward + * compatibility is assured by the platform. + * + * Return: 0 on Success + */ +static int scmi_protocol_version_negotiate(struct scmi_protocol_handle *ph) +{ + int ret; + struct scmi_xfer *t; + struct scmi_protocol_instance *pi =3D ph_to_pi(ph); + + /* At first check if NEGOTIATE_PROTOCOL_VERSION is supported ... */ + ret =3D scmi_protocol_msg_check(ph, NEGOTIATE_PROTOCOL_VERSION, NULL); + if (ret) + return ret; + + /* ... then attempt protocol version negotiation */ + ret =3D xfer_get_init(ph, NEGOTIATE_PROTOCOL_VERSION, + sizeof(__le32), 0, &t); + if (ret) + return ret; + + put_unaligned_le32(pi->proto->supported_version, t->tx.buf); + ret =3D do_xfer(ph, t); + if (!ret) + pi->negotiated_version =3D pi->proto->supported_version; + + xfer_put(ph, t); + + return ret; +} + /** * scmi_alloc_init_protocol_instance - Allocate and initialize a protocol * instance descriptor. @@ -1887,11 +1932,21 @@ scmi_alloc_init_protocol_instance(struct scmi_info = *info, devres_close_group(handle->dev, pi->gid); dev_dbg(handle->dev, "Initialized protocol: 0x%X\n", pi->proto->id); =20 - if (pi->version > proto->supported_version) - dev_warn(handle->dev, - "Detected UNSUPPORTED higher version 0x%X for protocol 0x%X." - "Backward compatibility is NOT assured.\n", - pi->version, pi->proto->id); + if (pi->version > proto->supported_version) { + ret =3D scmi_protocol_version_negotiate(&pi->ph); + if (!ret) { + dev_info(handle->dev, + "Protocol 0x%X successfully negotiated version 0x%X\n", + proto->id, pi->negotiated_version); + } else { + dev_warn(handle->dev, + "Detected UNSUPPORTED higher version 0x%X for protocol 0x%X.\n", + pi->version, pi->proto->id); + dev_warn(handle->dev, + "Trying version 0x%X. Backward compatibility is NOT assured.\n", + pi->proto->supported_version); + } + } =20 return pi; =20 diff --git a/drivers/firmware/arm_scmi/protocols.h b/drivers/firmware/arm_s= cmi/protocols.h index 26a3edd49fea..693019fff0f6 100644 --- a/drivers/firmware/arm_scmi/protocols.h +++ b/drivers/firmware/arm_scmi/protocols.h @@ -33,6 +33,7 @@ enum scmi_common_cmd { PROTOCOL_VERSION =3D 0x0, PROTOCOL_ATTRIBUTES =3D 0x1, PROTOCOL_MESSAGE_ATTRIBUTES =3D 0x2, + NEGOTIATE_PROTOCOL_VERSION =3D 0x10, }; =20 /** --=20 2.43.0 From nobody Mon Feb 9 10:30:18 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5DA4812BF38 for ; Wed, 14 Feb 2024 18:30:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707935439; cv=none; b=Lrcu6tXW2Jiua/+jVKwSWGbHU31O8qTaKukeGMj90Xg1MuoqPgiQatbfv/biByt2rFg2ba9G7Zez9ECNwW6TMrFOG/3QerH+NLzMS6GfxW8bptanJm8SFW2ipen/r9Fa3t5UVtj1UzOqxQqRcLQw95Y/kUCSkEw3wq53QlvaDSw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707935439; c=relaxed/simple; bh=kKN6YUR8GBEY6aJ6XdGiwTYMxulxghywt7sHCnYQMJE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oTADOTT4g4IncfrsqfTvzF8ph8+/ugNDt31rDsudK0l740OLqC5OAQ7Rjn4A6kSk+hJbuM87UuX58OUF6jIjwEEzXIu53XczWHMsc3e+oD0pwWtSf6CyitHH7SjYebhaAFhTFy6+Ttu9qKYxQHuMoScc59UBhfYXSuNx+6sakT8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A678E1FB; Wed, 14 Feb 2024 10:31:17 -0800 (PST) Received: from pluto.fritz.box (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id CD7EB3F7B4; Wed, 14 Feb 2024 10:30:34 -0800 (PST) From: Cristian Marussi To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: sudeep.holla@arm.com, james.quinlan@broadcom.com, f.fainelli@gmail.com, vincent.guittot@linaro.org, peng.fan@oss.nxp.com, michal.simek@amd.com, quic_sibis@quicinc.com, quic_nkela@quicinc.com, souvik.chakravarty@arm.com, Cristian Marussi Subject: [PATCH 3/7] firmware: arm_scmi: Add Clock check for extended config support Date: Wed, 14 Feb 2024 18:30:02 +0000 Message-ID: <20240214183006.3403207-4-cristian.marussi@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240214183006.3403207-1-cristian.marussi@arm.com> References: <20240214183006.3403207-1-cristian.marussi@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" SCMI v3.2 added support to set/get Clock custom OEM types; such support is conditionally present, though, depending on an extended config attribute bit possibly advertised by the platform server on a per-domain base. Add a check to verify if OEM types are supported before allowing any kind of OEM-specific get/set operation and also a check around all Clock v3.2 features. Signed-off-by: Cristian Marussi --- base-commit: 7dd3d11f4dac301e958f00e18db4901a35cefc70 --- drivers/firmware/arm_scmi/clock.c | 33 +++++++++++++++++++++++++------ include/linux/scmi_protocol.h | 1 + 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/drivers/firmware/arm_scmi/clock.c b/drivers/firmware/arm_scmi/= clock.c index 959e48aba1b5..9d80ad95b467 100644 --- a/drivers/firmware/arm_scmi/clock.c +++ b/drivers/firmware/arm_scmi/clock.c @@ -54,6 +54,7 @@ struct scmi_msg_resp_clock_attributes { #define SUPPORTS_RATE_CHANGE_REQUESTED_NOTIF(x) ((x) & BIT(30)) #define SUPPORTS_EXTENDED_NAMES(x) ((x) & BIT(29)) #define SUPPORTS_PARENT_CLOCK(x) ((x) & BIT(28)) +#define SUPPORTS_EXTENDED_CONFIG(x) ((x) & BIT(27)) #define SUPPORTS_GET_PERMISSIONS(x) ((x) & BIT(1)) u8 name[SCMI_SHORT_NAME_MAX_SIZE]; __le32 clock_enable_latency; @@ -372,10 +373,14 @@ static int scmi_clock_attributes_get(const struct scm= i_protocol_handle *ph, clk->rate_changed_notifications =3D true; if (SUPPORTS_RATE_CHANGE_REQUESTED_NOTIF(attributes)) clk->rate_change_requested_notifications =3D true; - if (SUPPORTS_PARENT_CLOCK(attributes)) - scmi_clock_possible_parents(ph, clk_id, clk); - if (SUPPORTS_GET_PERMISSIONS(attributes)) - scmi_clock_get_permissions(ph, clk_id, clk); + if (PROTOCOL_REV_MAJOR(version) >=3D 0x3) { + if (SUPPORTS_PARENT_CLOCK(attributes)) + scmi_clock_possible_parents(ph, clk_id, clk); + if (SUPPORTS_GET_PERMISSIONS(attributes)) + scmi_clock_get_permissions(ph, clk_id, clk); + if (SUPPORTS_EXTENDED_CONFIG(attributes)) + clk->extended_config =3D true; + } } =20 return ret; @@ -684,7 +689,7 @@ scmi_clock_get_parent(const struct scmi_protocol_handle= *ph, u32 clk_id, return ret; } =20 -/* For SCMI clock v2.1 and onwards */ +/* For SCMI clock v3.0 and onwards */ static int scmi_clock_config_set_v2(const struct scmi_protocol_handle *ph, u32 clk_id, enum clk_state state, u8 oem_type, u32 oem_val, @@ -757,7 +762,7 @@ static int scmi_clock_disable(const struct scmi_protoco= l_handle *ph, u32 clk_id, NULL_OEM_TYPE, 0, atomic); } =20 -/* For SCMI clock v2.1 and onwards */ +/* For SCMI clock v3.0 and onwards */ static int scmi_clock_config_get_v2(const struct scmi_protocol_handle *ph, u32 clk_id, u8 oem_type, u32 *attributes, bool *enabled, @@ -844,6 +849,14 @@ static int scmi_clock_config_oem_set(const struct scmi= _protocol_handle *ph, bool atomic) { struct clock_info *ci =3D ph->get_priv(ph); + struct scmi_clock_info *clk; + + clk =3D scmi_clock_domain_lookup(ci, clk_id); + if (IS_ERR(clk)) + return PTR_ERR(clk); + + if (!clk->extended_config) + return -EOPNOTSUPP; =20 return ci->clock_config_set(ph, clk_id, CLK_STATE_UNCHANGED, oem_type, oem_val, atomic); @@ -854,6 +867,14 @@ static int scmi_clock_config_oem_get(const struct scmi= _protocol_handle *ph, u32 *attributes, bool atomic) { struct clock_info *ci =3D ph->get_priv(ph); + struct scmi_clock_info *clk; + + clk =3D scmi_clock_domain_lookup(ci, clk_id); + if (IS_ERR(clk)) + return PTR_ERR(clk); + + if (!clk->extended_config) + return -EOPNOTSUPP; =20 return ci->clock_config_get(ph, clk_id, oem_type, attributes, NULL, oem_val, atomic); diff --git a/include/linux/scmi_protocol.h b/include/linux/scmi_protocol.h index 0cc40af5519a..caeca3f51be2 100644 --- a/include/linux/scmi_protocol.h +++ b/include/linux/scmi_protocol.h @@ -50,6 +50,7 @@ struct scmi_clock_info { bool state_ctrl_forbidden; bool rate_ctrl_forbidden; bool parent_ctrl_forbidden; + bool extended_config; union { struct { int num_rates; --=20 2.43.0 From nobody Mon Feb 9 10:30:18 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 331ED12CD92 for ; Wed, 14 Feb 2024 18:30:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707935441; cv=none; b=J9zCxWjoq7+2QsjUBO/gmvDL91rNSAJIXps8HrfFmxf/i4QvQ+llYUgYI00xJ1wJaU1q0WPJJnpni4C1evT4AdQO2DtY7+0+SffdZysw56SK2yQfQiN5xxJ1iKRpOmcftFbZZppDli09Axgl0jmJ0v9oTNOVfAl/M+KleHpBY9Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707935441; c=relaxed/simple; bh=xq9MVF5FMpmg0wbRQ2f/6kGNHVmkgomTX1MR7bkw9HA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VTBas1Ku06BXPixxGwCAxK6G4J7Jl2ZVQvX7J8qioMQ5GfqViSQiyi1B5jvCLfwyftzgqklQ2BC8mVNvWJsQ8nHQqE5y1UWZL8peLxu7PYEDPFsBvaRlPz+Eb/1nMWuuUYXaEDKDU6O6uB7j2k04w4r397OFanQJZws7apA0uBA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 93EBADA7; Wed, 14 Feb 2024 10:31:19 -0800 (PST) Received: from pluto.fritz.box (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E2A7E3F7B4; Wed, 14 Feb 2024 10:30:36 -0800 (PST) From: Cristian Marussi To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: sudeep.holla@arm.com, james.quinlan@broadcom.com, f.fainelli@gmail.com, vincent.guittot@linaro.org, peng.fan@oss.nxp.com, michal.simek@amd.com, quic_sibis@quicinc.com, quic_nkela@quicinc.com, souvik.chakravarty@arm.com, Cristian Marussi Subject: [PATCH 4/7] firmware: arm_scmi: Add standard Clock OEM definitions Date: Wed, 14 Feb 2024 18:30:03 +0000 Message-ID: <20240214183006.3403207-5-cristian.marussi@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240214183006.3403207-1-cristian.marussi@arm.com> References: <20240214183006.3403207-1-cristian.marussi@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a common enum to define the standard Clock OEM types defined by the SCMI specification, so as to enable the configuration of such extended configuration properties with the existent clock protocol operations. Signed-off-by: Cristian Marussi --- drivers/firmware/arm_scmi/clock.c | 32 ++++++++++++++++++------------- include/linux/scmi_protocol.h | 14 +++++++++++--- 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/drivers/firmware/arm_scmi/clock.c b/drivers/firmware/arm_scmi/= clock.c index 9d80ad95b467..4e7f072142b9 100644 --- a/drivers/firmware/arm_scmi/clock.c +++ b/drivers/firmware/arm_scmi/clock.c @@ -163,10 +163,12 @@ struct clock_info { struct scmi_clock_info *clk; int (*clock_config_set)(const struct scmi_protocol_handle *ph, u32 clk_id, enum clk_state state, - u8 oem_type, u32 oem_val, bool atomic); + enum scmi_clock_oem_config oem_type, + u32 oem_val, bool atomic); int (*clock_config_get)(const struct scmi_protocol_handle *ph, - u32 clk_id, u8 oem_type, u32 *attributes, - bool *enabled, u32 *oem_val, bool atomic); + u32 clk_id, enum scmi_clock_oem_config oem_type, + u32 *attributes, bool *enabled, u32 *oem_val, + bool atomic); }; =20 static enum scmi_clock_protocol_cmd evt_2_cmd[] =3D { @@ -602,7 +604,8 @@ static int scmi_clock_rate_set(const struct scmi_protoc= ol_handle *ph, =20 static int scmi_clock_config_set(const struct scmi_protocol_handle *ph, u32 clk_id, - enum clk_state state, u8 __unused0, u32 __unused1, + enum clk_state state, + enum scmi_clock_oem_config __unused0, u32 __unused1, bool atomic) { int ret; @@ -692,7 +695,8 @@ scmi_clock_get_parent(const struct scmi_protocol_handle= *ph, u32 clk_id, /* For SCMI clock v3.0 and onwards */ static int scmi_clock_config_set_v2(const struct scmi_protocol_handle *ph, u32 clk_id, - enum clk_state state, u8 oem_type, u32 oem_val, + enum clk_state state, + enum scmi_clock_oem_config oem_type, u32 oem_val, bool atomic) { int ret; @@ -765,8 +769,8 @@ static int scmi_clock_disable(const struct scmi_protoco= l_handle *ph, u32 clk_id, /* For SCMI clock v3.0 and onwards */ static int scmi_clock_config_get_v2(const struct scmi_protocol_handle *ph, u32 clk_id, - u8 oem_type, u32 *attributes, bool *enabled, - u32 *oem_val, bool atomic) + enum scmi_clock_oem_config oem_type, u32 *attributes, + bool *enabled, u32 *oem_val, bool atomic) { int ret; u32 flags; @@ -807,8 +811,8 @@ scmi_clock_config_get_v2(const struct scmi_protocol_han= dle *ph, u32 clk_id, =20 static int scmi_clock_config_get(const struct scmi_protocol_handle *ph, u32 clk_id, - u8 oem_type, u32 *attributes, bool *enabled, - u32 *oem_val, bool atomic) + enum scmi_clock_oem_config oem_type, u32 *attributes, + bool *enabled, u32 *oem_val, bool atomic) { int ret; struct scmi_xfer *t; @@ -845,8 +849,9 @@ static int scmi_clock_state_get(const struct scmi_proto= col_handle *ph, } =20 static int scmi_clock_config_oem_set(const struct scmi_protocol_handle *ph, - u32 clk_id, u8 oem_type, u32 oem_val, - bool atomic) + u32 clk_id, + enum scmi_clock_oem_config oem_type, + u32 oem_val, bool atomic) { struct clock_info *ci =3D ph->get_priv(ph); struct scmi_clock_info *clk; @@ -863,8 +868,9 @@ static int scmi_clock_config_oem_set(const struct scmi_= protocol_handle *ph, } =20 static int scmi_clock_config_oem_get(const struct scmi_protocol_handle *ph, - u32 clk_id, u8 oem_type, u32 *oem_val, - u32 *attributes, bool atomic) + u32 clk_id, + enum scmi_clock_oem_config oem_type, + u32 *oem_val, u32 *attributes, bool atomic) { struct clock_info *ci =3D ph->get_priv(ph); struct scmi_clock_info *clk; diff --git a/include/linux/scmi_protocol.h b/include/linux/scmi_protocol.h index caeca3f51be2..24e8de581744 100644 --- a/include/linux/scmi_protocol.h +++ b/include/linux/scmi_protocol.h @@ -76,6 +76,13 @@ struct scmi_handle; struct scmi_device; struct scmi_protocol_handle; =20 +enum scmi_clock_oem_config { + SCMI_CLOCK_CFG_DUTY_CYCLE =3D 0x1, + SCMI_CLOCK_CFG_PHASE, + SCMI_CLOCK_CFG_OEM_START =3D 0x80, + SCMI_CLOCK_CFG_OEM_END =3D 0xFF, +}; + /** * struct scmi_clk_proto_ops - represents the various operations provided * by SCMI Clock Protocol @@ -108,10 +115,11 @@ struct scmi_clk_proto_ops { int (*state_get)(const struct scmi_protocol_handle *ph, u32 clk_id, bool *enabled, bool atomic); int (*config_oem_get)(const struct scmi_protocol_handle *ph, u32 clk_id, - u8 oem_type, u32 *oem_val, u32 *attributes, - bool atomic); + enum scmi_clock_oem_config oem_type, + u32 *oem_val, u32 *attributes, bool atomic); int (*config_oem_set)(const struct scmi_protocol_handle *ph, u32 clk_id, - u8 oem_type, u32 oem_val, bool atomic); + enum scmi_clock_oem_config oem_type, + u32 oem_val, bool atomic); int (*parent_get)(const struct scmi_protocol_handle *ph, u32 clk_id, u32 = *parent_id); int (*parent_set)(const struct scmi_protocol_handle *ph, u32 clk_id, u32 = parent_id); }; --=20 2.43.0 From nobody Mon Feb 9 10:30:18 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B7C1912D745 for ; Wed, 14 Feb 2024 18:30:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707935442; cv=none; b=hB0vQgERZdAjKngUgfzUubZ0JS9tCy51khsEt1HkqgdLIXPPxbVM5PDIJmQBDOt3sL8KQGP11rHijKt9/MK7PLYKewgAoY40DMwrPKYVA65Dz8bLf90/cvFWLc3iEfmp4cmCFDm+OSVWmFdX8vf1bljTwAhGqsxMk8FrU2tWuuw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707935442; c=relaxed/simple; bh=seWpBFlFjy02oiaHbxmblsXfECvB/RvpFemRUNdrD54=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=g9or2f7vJrP57lEWVZ51ffR+4/jATFtMVx7vGD9U7tmazx+IYYsnYaLye3apgUSYvuFpIUoVszNItumfM22pogxp4X1yY+26o59uc9cLQdu0pk0pQFSUS4enhwcM11v7q9tNboHKA2lt/uKv6jVgGSr/QYcruGtdmxOMWRsacaU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 87A5A1476; Wed, 14 Feb 2024 10:31:21 -0800 (PST) Received: from pluto.fritz.box (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D5F563F7B4; Wed, 14 Feb 2024 10:30:38 -0800 (PST) From: Cristian Marussi To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: sudeep.holla@arm.com, james.quinlan@broadcom.com, f.fainelli@gmail.com, vincent.guittot@linaro.org, peng.fan@oss.nxp.com, michal.simek@amd.com, quic_sibis@quicinc.com, quic_nkela@quicinc.com, souvik.chakravarty@arm.com, Cristian Marussi Subject: [PATCH 5/7] firmware: arm_scmi: Update supported Clock protocol version Date: Wed, 14 Feb 2024 18:30:04 +0000 Message-ID: <20240214183006.3403207-6-cristian.marussi@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240214183006.3403207-1-cristian.marussi@arm.com> References: <20240214183006.3403207-1-cristian.marussi@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Update supported Clock protocol version to v3.2 (0x30000) Signed-off-by: Cristian Marussi --- drivers/firmware/arm_scmi/clock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/firmware/arm_scmi/clock.c b/drivers/firmware/arm_scmi/= clock.c index 4e7f072142b9..ca1729fd42cf 100644 --- a/drivers/firmware/arm_scmi/clock.c +++ b/drivers/firmware/arm_scmi/clock.c @@ -13,7 +13,7 @@ #include "notify.h" =20 /* Updated only after ALL the mandatory features for that version are merg= ed */ -#define SCMI_PROTOCOL_SUPPORTED_VERSION 0x20000 +#define SCMI_PROTOCOL_SUPPORTED_VERSION 0x30000 =20 enum scmi_clock_protocol_cmd { CLOCK_ATTRIBUTES =3D 0x3, --=20 2.43.0 From nobody Mon Feb 9 10:30:18 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 72F9112C53C; Wed, 14 Feb 2024 18:30:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707935445; cv=none; b=fHv8LJs2CGhCq+Lz6zilPMMN1QiNkNXyOAYrDut3KgD2lgoAew/UmmDN0buMRVv5FBL/3tFTWpFhQrQYLvVe4+yLGYh+HvkXGaAB/wJmgflDK8cAZf6N52Z4xT/XGR5CPBGiQzjPOUh5eVolCD1TAzAC+2ynxb+MXPp+FW+Jsds= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707935445; c=relaxed/simple; bh=FAXe14bgrUJ605crID4nOzEAT9unDU7UAMXUqo6EjIA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WqZzYCorCSX9YwG9lBP1auGnmTRoeFK/TZ9gHJnBQ5kWwEL4a8de0RqVsWfHKY7YIeHeBJqKrgVYdniXdO9D/J5N3JBo0ndefSwtUUHggml9VPjQQWAmprXS/8SjGAVTNi4jnGf/ruAuT6pp3t0R3pDKRbN4AUfA6NbtdKWAq/I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D31D21FB; Wed, 14 Feb 2024 10:31:23 -0800 (PST) Received: from pluto.fritz.box (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C9AC83F7B4; Wed, 14 Feb 2024 10:30:40 -0800 (PST) From: Cristian Marussi To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: sudeep.holla@arm.com, james.quinlan@broadcom.com, f.fainelli@gmail.com, vincent.guittot@linaro.org, peng.fan@oss.nxp.com, michal.simek@amd.com, quic_sibis@quicinc.com, quic_nkela@quicinc.com, souvik.chakravarty@arm.com, Cristian Marussi , Michael Turquette , Stephen Boyd , linux-clk@vger.kernel.org Subject: [PATCH 6/7] clk: scmi: Allocate CLK operations dynamically Date: Wed, 14 Feb 2024 18:30:05 +0000 Message-ID: <20240214183006.3403207-7-cristian.marussi@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240214183006.3403207-1-cristian.marussi@arm.com> References: <20240214183006.3403207-1-cristian.marussi@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" SCMI Clocks descriptors expose and increasing number of properties that in turn lead to a different set of supported CLK operations to be associated dynamically with a clock. Providing statically pre-defined CLK operations structs for all the possible combinations of allowed properties is cumbersome and error-prone. Allocate per-clock operations descriptor dynamically and populate it with the strictly needed set of operations depending on the advertised clock properties. CC: Michael Turquette CC: Stephen Boyd CC: linux-clk@vger.kernel.org Signed-off-by: Cristian Marussi --- drivers/clk/clk-scmi.c | 129 ++++++++++++++++++++++------------------- 1 file changed, 70 insertions(+), 59 deletions(-) diff --git a/drivers/clk/clk-scmi.c b/drivers/clk/clk-scmi.c index 5747b6d651f0..b91a0dbd2fe0 100644 --- a/drivers/clk/clk-scmi.c +++ b/drivers/clk/clk-scmi.c @@ -158,51 +158,6 @@ static int scmi_clk_atomic_is_enabled(struct clk_hw *h= w) return !!enabled; } =20 -/* - * We can provide enable/disable/is_enabled atomic callbacks only if the - * underlying SCMI transport for an SCMI instance is configured to handle - * SCMI commands in an atomic manner. - * - * When no SCMI atomic transport support is available we instead provide o= nly - * the prepare/unprepare API, as allowed by the clock framework when atomic - * calls are not available. - * - * Two distinct sets of clk_ops are provided since we could have multiple = SCMI - * instances with different underlying transport quality, so they cannot be - * shared. - */ -static const struct clk_ops scmi_clk_ops =3D { - .recalc_rate =3D scmi_clk_recalc_rate, - .round_rate =3D scmi_clk_round_rate, - .set_rate =3D scmi_clk_set_rate, - .prepare =3D scmi_clk_enable, - .unprepare =3D scmi_clk_disable, - .set_parent =3D scmi_clk_set_parent, - .get_parent =3D scmi_clk_get_parent, - .determine_rate =3D scmi_clk_determine_rate, -}; - -static const struct clk_ops scmi_atomic_clk_ops =3D { - .recalc_rate =3D scmi_clk_recalc_rate, - .round_rate =3D scmi_clk_round_rate, - .set_rate =3D scmi_clk_set_rate, - .enable =3D scmi_clk_atomic_enable, - .disable =3D scmi_clk_atomic_disable, - .is_enabled =3D scmi_clk_atomic_is_enabled, - .set_parent =3D scmi_clk_set_parent, - .get_parent =3D scmi_clk_get_parent, - .determine_rate =3D scmi_clk_determine_rate, -}; - -static const struct clk_ops scmi_no_state_ctrl_clk_ops =3D { - .recalc_rate =3D scmi_clk_recalc_rate, - .round_rate =3D scmi_clk_round_rate, - .set_rate =3D scmi_clk_set_rate, - .set_parent =3D scmi_clk_set_parent, - .get_parent =3D scmi_clk_get_parent, - .determine_rate =3D scmi_clk_determine_rate, -}; - static int scmi_clk_ops_init(struct device *dev, struct scmi_clk *sclk, const struct clk_ops *scmi_ops) { @@ -239,6 +194,71 @@ static int scmi_clk_ops_init(struct device *dev, struc= t scmi_clk *sclk, return ret; } =20 +/** + * scmi_clk_ops_alloc() - Alloc and configure CLK ops + * @sclk: A reference to an SCMI clock descriptor + * @atomic_capable: A flag to indicate if atomic mode is supported by the + * transport + * @atomic_threshold: Platform atomic threshold value + * + * Allocate and configure a proper set of CLK operations depending on the + * specific SCMI clock characteristics and platform atomic operation capab= ility. + * + * We can provide enable/disable/is_enabled atomic callbacks only if the + * underlying SCMI transport for an SCMI instance is configured to handle + * SCMI commands in an atomic manner. + * + * When no SCMI atomic transport support is available we instead provide o= nly + * the prepare/unprepare API, as allowed by the clock framework when atomic + * calls are not available. + * + * Return: A pointer to the allocated and configured clk_ops on Success, + * NULL otherwise. + */ +static const struct clk_ops * +scmi_clk_ops_alloc(struct scmi_clk *sclk, bool atomic_capable, + unsigned int atomic_threshold) +{ + const struct scmi_clock_info *ci =3D sclk->info; + struct clk_ops *ops; + + ops =3D devm_kzalloc(sclk->dev, sizeof(*ops), GFP_KERNEL); + if (!ops) + return NULL; + + /* + * Note that when transport is atomic but SCMI protocol did not + * specify (or support) an enable_latency associated with a + * clock, we default to use atomic operations mode. + */ + if (!ci->state_ctrl_forbidden) { + if (atomic_capable && ci->enable_latency <=3D atomic_threshold) { + ops->enable =3D scmi_clk_atomic_enable; + ops->disable =3D scmi_clk_atomic_disable; + } else { + ops->prepare =3D scmi_clk_enable; + ops->unprepare =3D scmi_clk_disable; + } + } + + if (atomic_capable) + ops->is_enabled =3D scmi_clk_atomic_is_enabled; + + /* Rate ops */ + ops->recalc_rate =3D scmi_clk_recalc_rate; + ops->round_rate =3D scmi_clk_round_rate; + ops->determine_rate =3D scmi_clk_determine_rate; + if (!ci->rate_ctrl_forbidden) + ops->set_rate =3D scmi_clk_set_rate; + + /* Parent ops */ + ops->get_parent =3D scmi_clk_get_parent; + if (!ci->parent_ctrl_forbidden) + ops->set_parent =3D scmi_clk_set_parent; + + return ops; +} + static int scmi_clocks_probe(struct scmi_device *sdev) { int idx, count, err; @@ -294,18 +314,9 @@ static int scmi_clocks_probe(struct scmi_device *sdev) sclk->ph =3D ph; sclk->dev =3D dev; =20 - /* - * Note that when transport is atomic but SCMI protocol did not - * specify (or support) an enable_latency associated with a - * clock, we default to use atomic operations mode. - */ - if (sclk->info->state_ctrl_forbidden) - scmi_ops =3D &scmi_no_state_ctrl_clk_ops; - else if (is_atomic && - sclk->info->enable_latency <=3D atomic_threshold) - scmi_ops =3D &scmi_atomic_clk_ops; - else - scmi_ops =3D &scmi_clk_ops; + scmi_ops =3D scmi_clk_ops_alloc(sclk, is_atomic, atomic_threshold); + if (!scmi_ops) + return -ENOMEM; =20 /* Initialize clock parent data. */ if (sclk->info->num_parents > 0) { @@ -324,13 +335,13 @@ static int scmi_clocks_probe(struct scmi_device *sdev) if (err) { dev_err(dev, "failed to register clock %d\n", idx); devm_kfree(dev, sclk->parent_data); + devm_kfree(dev, scmi_ops); devm_kfree(dev, sclk); hws[idx] =3D NULL; } else { dev_dbg(dev, "Registered clock:%s%s\n", sclk->info->name, - scmi_ops =3D=3D &scmi_atomic_clk_ops ? - " (atomic ops)" : ""); + scmi_ops->enable ? " (atomic ops)" : ""); hws[idx] =3D &sclk->hw; } } --=20 2.43.0 From nobody Mon Feb 9 10:30:18 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C270412EBFB; Wed, 14 Feb 2024 18:30:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707935447; cv=none; b=o63yIyBWFqCrx08kbAqijk9srrW2klSPNWfKpyJUtN9QfIooqvd3Ek2I9rFERAwkJjm4W2AmJBf3+6b9yfBjYCH03a87XSh/E6zWdMasY+rlgEbQO+o9Cm/VEGILIKyxr6N1lvDLK8OrMBZOn8dJBYEf0Zj051uO+lGqAI7UPe8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707935447; c=relaxed/simple; bh=WYEne98DDgqD6wOMHk6cJ+Hy4mmBoGUxdY4E2T7jmSo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hVS4eoL602I4gi4Cqc8urm0eL2PWMEDOnU0oI3PLteoHzmepv+bKkB1eMd5nNS6ys3MRYGKuGW9EC0y124YIBUbt7wyq1g5V6uOUhE5Q63FgjEQWAe+zW3lHJ6J+D2CN20ruRmLXPUsJF09ufZZlJ4sxrPOjomdHSB2bCP0f2lE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 28EA7DA7; Wed, 14 Feb 2024 10:31:26 -0800 (PST) Received: from pluto.fritz.box (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 20E533F7B4; Wed, 14 Feb 2024 10:30:43 -0800 (PST) From: Cristian Marussi To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: sudeep.holla@arm.com, james.quinlan@broadcom.com, f.fainelli@gmail.com, vincent.guittot@linaro.org, peng.fan@oss.nxp.com, michal.simek@amd.com, quic_sibis@quicinc.com, quic_nkela@quicinc.com, souvik.chakravarty@arm.com, Cristian Marussi , Michael Turquette , Stephen Boyd , linux-clk@vger.kernel.org Subject: [PATCH 7/7] clk: scmi: Support get/set duty_cycle operations Date: Wed, 14 Feb 2024 18:30:06 +0000 Message-ID: <20240214183006.3403207-8-cristian.marussi@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240214183006.3403207-1-cristian.marussi@arm.com> References: <20240214183006.3403207-1-cristian.marussi@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Provide the CLK framework callbacks related to get/set clock duty cycle if the relared SCMI clock supports OEM extended configurations. CC: Michael Turquette CC: Stephen Boyd CC: linux-clk@vger.kernel.org Signed-off-by: Cristian Marussi Acked-by: Stephen Boyd --- drivers/clk/clk-scmi.c | 45 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/drivers/clk/clk-scmi.c b/drivers/clk/clk-scmi.c index b91a0dbd2fe0..9d3b1e749226 100644 --- a/drivers/clk/clk-scmi.c +++ b/drivers/clk/clk-scmi.c @@ -158,6 +158,45 @@ static int scmi_clk_atomic_is_enabled(struct clk_hw *h= w) return !!enabled; } =20 +static int scmi_clk_get_duty_cycle(struct clk_hw *hw, struct clk_duty *dut= y) +{ + int ret; + u32 val; + struct scmi_clk *clk =3D to_scmi_clk(hw); + + ret =3D scmi_proto_clk_ops->config_oem_get(clk->ph, clk->id, + SCMI_CLOCK_CFG_DUTY_CYCLE, + &val, NULL, false); + if (!ret) { + duty->num =3D val; + duty->den =3D 100; + } else { + dev_warn(clk->dev, + "Failed to get duty cycle for clock ID %d\n", clk->id); + } + + return ret; +} + +static int scmi_clk_set_duty_cycle(struct clk_hw *hw, struct clk_duty *dut= y) +{ + int ret; + u32 val; + struct scmi_clk *clk =3D to_scmi_clk(hw); + + /* SCMI OEM Duty Cycle is expressed as a percentage */ + val =3D (duty->num * 100) / duty->den; + ret =3D scmi_proto_clk_ops->config_oem_set(clk->ph, clk->id, + SCMI_CLOCK_CFG_DUTY_CYCLE, + val, false); + if (ret) + dev_warn(clk->dev, + "Failed to set duty cycle(%u/%u) for clock ID %d\n", + duty->num, duty->den, clk->id); + + return ret; +} + static int scmi_clk_ops_init(struct device *dev, struct scmi_clk *sclk, const struct clk_ops *scmi_ops) { @@ -256,6 +295,12 @@ scmi_clk_ops_alloc(struct scmi_clk *sclk, bool atomic_= capable, if (!ci->parent_ctrl_forbidden) ops->set_parent =3D scmi_clk_set_parent; =20 + /* Duty cycle */ + if (ci->extended_config) { + ops->get_duty_cycle =3D scmi_clk_get_duty_cycle; + ops->set_duty_cycle =3D scmi_clk_set_duty_cycle; + } + return ops; } =20 --=20 2.43.0