]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
power: regulator: scmi: support SCMI multi-channel
authorEtienne Carriere <etienne.carriere@linaro.org>
Tue, 31 May 2022 16:09:27 +0000 (18:09 +0200)
committerTom Rini <trini@konsulko.com>
Thu, 23 Jun 2022 17:12:55 +0000 (13:12 -0400)
Update SCMI regulator controller driver to get its assigned SCMI channel
during initialization. This change allows SCMI voltage domain protocol
to use a dedicated channel when defined in the DT. The reference is
saved in SCMI regulator controller driver private data.

Cc: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Etienne Carriere <etienne.carriere@linaro.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>
drivers/power/regulator/scmi_regulator.c

index 3325ddaf23b5f2fbc84af7176ae4e078c2c99fdf..352daa9bbc9b07fa160488189a8f948dfa9effab 100644 (file)
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0+
 /*
- * Copyright (C) 2020-2021 Linaro Limited
+ * Copyright (C) 2020-2022 Linaro Limited
  */
 
 #define LOG_CATEGORY UCLASS_REGULATOR
@@ -25,9 +25,18 @@ struct scmi_regulator_platdata {
        u32 domain_id;
 };
 
+/**
+ * struct scmi_regulator_priv - Private data for SCMI voltage regulator
+ * @channel: Reference to the SCMI channel to use
+ */
+struct scmi_regulator_priv {
+       struct scmi_channel *channel;
+};
+
 static int scmi_voltd_set_enable(struct udevice *dev, bool enable)
 {
        struct scmi_regulator_platdata *pdata = dev_get_plat(dev);
+       struct scmi_regulator_priv *priv = dev_get_priv(dev);
        struct scmi_voltd_config_set_in in = {
                .domain_id = pdata->domain_id,
                .config = enable ? SCMI_VOLTD_CONFIG_ON : SCMI_VOLTD_CONFIG_OFF,
@@ -38,7 +47,7 @@ static int scmi_voltd_set_enable(struct udevice *dev, bool enable)
                                          in, out);
        int ret;
 
-       ret = devm_scmi_process_msg(dev, NULL, &msg);
+       ret = devm_scmi_process_msg(dev, priv->channel, &msg);
        if (ret)
                return ret;
 
@@ -52,6 +61,7 @@ static int scmi_voltd_set_enable(struct udevice *dev, bool enable)
 static int scmi_voltd_get_enable(struct udevice *dev)
 {
        struct scmi_regulator_platdata *pdata = dev_get_plat(dev);
+       struct scmi_regulator_priv *priv = dev_get_priv(dev);
        struct scmi_voltd_config_get_in in = {
                .domain_id = pdata->domain_id,
        };
@@ -61,7 +71,7 @@ static int scmi_voltd_get_enable(struct udevice *dev)
                                          in, out);
        int ret;
 
-       ret = devm_scmi_process_msg(dev, NULL, &msg);
+       ret = devm_scmi_process_msg(dev, priv->channel, &msg);
        if (ret < 0)
                return ret;
 
@@ -74,6 +84,7 @@ static int scmi_voltd_get_enable(struct udevice *dev)
 
 static int scmi_voltd_set_voltage_level(struct udevice *dev, int uV)
 {
+       struct scmi_regulator_priv *priv = dev_get_priv(dev);
        struct scmi_regulator_platdata *pdata = dev_get_plat(dev);
        struct scmi_voltd_level_set_in in = {
                .domain_id = pdata->domain_id,
@@ -85,7 +96,7 @@ static int scmi_voltd_set_voltage_level(struct udevice *dev, int uV)
                                          in, out);
        int ret;
 
-       ret = devm_scmi_process_msg(dev, NULL, &msg);
+       ret = devm_scmi_process_msg(dev, priv->channel, &msg);
        if (ret < 0)
                return ret;
 
@@ -94,6 +105,7 @@ static int scmi_voltd_set_voltage_level(struct udevice *dev, int uV)
 
 static int scmi_voltd_get_voltage_level(struct udevice *dev)
 {
+       struct scmi_regulator_priv *priv = dev_get_priv(dev);
        struct scmi_regulator_platdata *pdata = dev_get_plat(dev);
        struct scmi_voltd_level_get_in in = {
                .domain_id = pdata->domain_id,
@@ -104,7 +116,7 @@ static int scmi_voltd_get_voltage_level(struct udevice *dev)
                                          in, out);
        int ret;
 
-       ret = devm_scmi_process_msg(dev, NULL, &msg);
+       ret = devm_scmi_process_msg(dev, priv->channel, &msg);
        if (ret < 0)
                return ret;
 
@@ -132,6 +144,7 @@ static int scmi_regulator_of_to_plat(struct udevice *dev)
 static int scmi_regulator_probe(struct udevice *dev)
 {
        struct scmi_regulator_platdata *pdata = dev_get_plat(dev);
+       struct scmi_regulator_priv *priv = dev_get_priv(dev);
        struct scmi_voltd_attr_in in = { 0 };
        struct scmi_voltd_attr_out out = { 0 };
        struct scmi_msg scmi_msg = {
@@ -144,10 +157,14 @@ static int scmi_regulator_probe(struct udevice *dev)
        };
        int ret;
 
+       ret = devm_scmi_of_get_channel(dev->parent, &priv->channel);
+       if (ret)
+               return ret;
+
        /* Check voltage domain is known from SCMI server */
        in.domain_id = pdata->domain_id;
 
-       ret = devm_scmi_process_msg(dev, NULL, &scmi_msg);
+       ret = devm_scmi_process_msg(dev, priv->channel, &scmi_msg);
        if (ret) {
                dev_err(dev, "Failed to query voltage domain %u: %d\n",
                        pdata->domain_id, ret);
@@ -171,6 +188,7 @@ U_BOOT_DRIVER(scmi_regulator) = {
        .probe = scmi_regulator_probe,
        .of_to_plat = scmi_regulator_of_to_plat,
        .plat_auto = sizeof(struct scmi_regulator_platdata),
+       .priv_auto = sizeof(struct scmi_regulator_priv *),
 };
 
 static int scmi_regulator_bind(struct udevice *dev)