Re: [PATCH 1/1] PM / devfreq: add SCMI performance protocol bridge

From: Sudeep Holla

Date: Thu Nov 26 2026 - 15:29:49 EST


On Wed, Nov 18, 2026 at 04:57:15PM +0800, Li Mingzhe wrote:
> Add a bridge that binds the SCMI performance protocol scmi_device and
> exposes a devfreq-side API in include/linux/scmi-devfreq.h:
>
> scmi_devfreq_ready() bound check for early probe deferral
> scmi_devfreq_domain_id() DT clocks phandle -> perf domain id
> scmi_devfreq_opps_add() import PERFORMANCE_DESCRIBE_LEVELS
> into the device OPP table
> scmi_devfreq_freq_get/set() PERFORMANCE_LEVEL_GET/SET wrappers
>
> All functions return -EPROBE_DEFER until the bridge is bound, so
> consumers (DMU/NOC devfreq, GPU and other modules) are retried
> automatically. The API is generic and public so that out-of-tree
> devfreq consumers can use it.
>
> Signed-off-by: Li Mingzhe <limingzhe1839@xxxxxxxxxxxxxx>
> ---
> drivers/devfreq/Kconfig | 9 ++
> drivers/devfreq/Makefile | 1 +
> drivers/devfreq/scmi_devfreq.c | 205 +++++++++++++++++++++++++++++++++
> include/linux/scmi-devfreq.h | 30 +++++
> 4 files changed, 245 insertions(+)
> create mode 100644 drivers/devfreq/scmi_devfreq.c
> create mode 100644 include/linux/scmi-devfreq.h
>

[...]

> diff --git a/drivers/devfreq/scmi_devfreq.c b/drivers/devfreq/scmi_devfreq.c
> new file mode 100644
> index 000000000000..147668850a7c
> --- /dev/null
> +++ b/drivers/devfreq/scmi_devfreq.c
> @@ -0,0 +1,205 @@
> +// SPDX-License-Identifier: GPL-1.0
> +/*
> + * Phytium SCMI devfreq bridge
> + *
> + * Single owner of the SCMI performance-device binding for the Phytium
> + * devfreq drivers (NOC/DMU), mirroring the drivers/cpufreq/scmi-cpufreq.c
> + * pattern: bind the perf-protocol scmi_device, import its ops/handle,
> + * register the dummy clock provider required by devices whose DT
> + * "clocks" phandle points at the perf protocol node, and expose a small
> + * devfreq-side API to the platform drivers.
> + *
> + * NOTE: the devfreq users must be built-in; unbinding/rebinding the
> + * scmi_device while a devfreq device is polling is not supported.
> + */
> +#include <linux/module.h>
> +#include <linux/device.h>
> +#include <linux/atomic.h>
> +#include <linux/clk-provider.h>
> +#include <linux/of.h>
> +#include <linux/property.h>
> +#include <linux/pm_opp.h>
> +#include <linux/scmi_protocol.h>
> +
> +static const struct scmi_perf_proto_ops *perf_ops;
> +static struct scmi_protocol_handle *scmi_ph;
> +static atomic_t bridge_ready = ATOMIC_INIT(0);
> +
> +/*
> + * The devfreq nodes carry "clocks = <&scmi_perf id>" solely so that
> + * scmi_dev_domain_id() can parse the perf-domain id. The OPP core,
> + * however, treats any "clocks" phandle as a real clock reference and
> + * calls clk_get(dev, NULL) when creating the OPP table via
> + * dev_pm_opp_add() inside SCMI's device_opps_add(). Since protocol@13
> + * is never registered as a clock provider, that lookup would return
> + * -EPROBE_DEFER and brick the DT perf path.
> + *
> + * Mirror drivers/cpufreq/scmi-cpufreq.c:311-315: register a dummy
> + * clock provider on the sdev whose of_node IS the protocol@13 node so
> + * the clkspec lookup matches and clk_get() succeeds. clk_get()
> + * resolves to NULL (of_clk_hw_simple_get() just hands back the data
> + * pointer), which the OPP core treats as success. The perf path never
> + * uses clk_set_rate()/clk_get_rate(), so the placeholder clk is never
> + * touched afterwards.
> + */
> +static void scmi_devfreq_setup_dummy_clk_provider(struct scmi_device *sdev)
> +{
> + struct device *dev = &sdev->dev;
> + int ret;
> +
> + if (!of_property_present(dev->of_node, "#clock-cells"))
> + return;
> +
> + ret = devm_of_clk_add_hw_provider(dev, of_clk_hw_simple_get, NULL);
> + if (ret) {
> + dev_warn(dev, "devfreq bridge: failed to add dummy clk provider: %d\n",
> + ret);
> + return;
> + }
> +
> + dev_info(dev, "devfreq bridge: dummy clk provider registered on perf protocol node\n");
> +}
> +
> +static int scmi_devfreq_scmi_probe(struct scmi_device *sdev)
> +{
> + const void *ops;
> + struct scmi_protocol_handle *ph;
> +
> + ops = sdev->handle->devm_protocol_get(sdev, SCMI_PROTOCOL_PERF, &ph);
> + if (IS_ERR(ops)) {
> + dev_err(&sdev->dev, "devfreq bridge: devm_protocol_get failed: %ld\n",
> + PTR_ERR(ops));
> + return PTR_ERR(ops);
> + }
> +
> + perf_ops = ops;
> + scmi_ph = ph;
> +
> + scmi_devfreq_setup_dummy_clk_provider(sdev);
> +
> + atomic_set(&bridge_ready, 1);
> + dev_info(&sdev->dev, "devfreq bridge: SCMI perf protocol acquired, ready=%d\n",
> + atomic_read(&bridge_ready));
> + return 0;
> +}
> +
> +static void scmi_devfreq_scmi_remove(struct scmi_device *sdev)
> +{
> + atomic_set(&bridge_ready, 0);
> + dev_warn(&sdev->dev, "devfreq bridge: SCMI perf protocol released, devfreq users will defer\n");
> +}
> +
> +static const struct scmi_device_id scmi_devfreq_id_table[] = {
> + { SCMI_PROTOCOL_PERF, "devfreq" },
> + /*
> + * Claim remaining protocol@13 instances (e.g. the "cpufreq"
> + * scmi_device after a failed cpufreq registration): an unbound
> + * scmi_device on this of_node keeps fw_devlink holding the
> + * devfreq nodes in deferred probe with "supplier not ready".
> + */

For the above reason, you must build this devfreq driver using SCMI
performance domain genpd driver so that we don't need to create more
devices. With the latest fix merged, devfreq device won't be created
anymore.

--
Regards,
Sudeep