firmware: arm_scmi: Port genpd driver to the new scmi_power_proto_ops interface
authorCristian Marussi <cristian.marussi@arm.com>
Tue, 16 Mar 2021 12:48:40 +0000 (12:48 +0000)
committerSudeep Holla <sudeep.holla@arm.com>
Mon, 29 Mar 2021 09:00:35 +0000 (10:00 +0100)
Port the scmi genpd driver to the new SCMI power interface based on
protocol handles and common devm_get_ops().

Link: https://lore.kernel.org/r/20210316124903.35011-16-cristian.marussi@arm.com
Tested-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>
Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
drivers/firmware/arm_scmi/scmi_pm_domain.c

index 9e44479..9d36d5c 100644 (file)
@@ -2,7 +2,7 @@
 /*
  * SCMI Generic power domain support.
  *
- * Copyright (C) 2018 ARM Ltd.
+ * Copyright (C) 2018-2021 ARM Ltd.
  */
 
 #include <linux/err.h>
 #include <linux/pm_domain.h>
 #include <linux/scmi_protocol.h>
 
+static const struct scmi_power_proto_ops *power_ops;
+
 struct scmi_pm_domain {
        struct generic_pm_domain genpd;
-       const struct scmi_handle *handle;
+       const struct scmi_protocol_handle *ph;
        const char *name;
        u32 domain;
 };
@@ -25,16 +27,15 @@ static int scmi_pd_power(struct generic_pm_domain *domain, bool power_on)
        int ret;
        u32 state, ret_state;
        struct scmi_pm_domain *pd = to_scmi_pd(domain);
-       const struct scmi_power_ops *ops = pd->handle->power_ops;
 
        if (power_on)
                state = SCMI_POWER_STATE_GENERIC_ON;
        else
                state = SCMI_POWER_STATE_GENERIC_OFF;
 
-       ret = ops->state_set(pd->handle, pd->domain, state);
+       ret = power_ops->state_set(pd->ph, pd->domain, state);
        if (!ret)
-               ret = ops->state_get(pd->handle, pd->domain, &ret_state);
+               ret = power_ops->state_get(pd->ph, pd->domain, &ret_state);
        if (!ret && state != ret_state)
                return -EIO;
 
@@ -60,11 +61,16 @@ static int scmi_pm_domain_probe(struct scmi_device *sdev)
        struct genpd_onecell_data *scmi_pd_data;
        struct generic_pm_domain **domains;
        const struct scmi_handle *handle = sdev->handle;
+       struct scmi_protocol_handle *ph;
 
-       if (!handle || !handle->power_ops)
+       if (!handle)
                return -ENODEV;
 
-       num_domains = handle->power_ops->num_domains_get(handle);
+       power_ops = handle->devm_protocol_get(sdev, SCMI_PROTOCOL_POWER, &ph);
+       if (IS_ERR(power_ops))
+               return PTR_ERR(power_ops);
+
+       num_domains = power_ops->num_domains_get(ph);
        if (num_domains < 0) {
                dev_err(dev, "number of domains not found\n");
                return num_domains;
@@ -85,14 +91,14 @@ static int scmi_pm_domain_probe(struct scmi_device *sdev)
        for (i = 0; i < num_domains; i++, scmi_pd++) {
                u32 state;
 
-               if (handle->power_ops->state_get(handle, i, &state)) {
+               if (power_ops->state_get(ph, i, &state)) {
                        dev_warn(dev, "failed to get state for domain %d\n", i);
                        continue;
                }
 
                scmi_pd->domain = i;
-               scmi_pd->handle = handle;
-               scmi_pd->name = handle->power_ops->name_get(handle, i);
+               scmi_pd->ph = ph;
+               scmi_pd->name = power_ops->name_get(ph, i);
                scmi_pd->genpd.name = scmi_pd->name;
                scmi_pd->genpd.power_off = scmi_pd_power_off;
                scmi_pd->genpd.power_on = scmi_pd_power_on;