]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
power: regulator: gpio-regulator: Convert to use APIs which support live DT
authorPatrick Delaunay <patrick.delaunay@st.com>
Thu, 10 Sep 2020 16:18:17 +0000 (18:18 +0200)
committerTom Rini <trini@konsulko.com>
Fri, 23 Oct 2020 17:33:07 +0000 (13:33 -0400)
Use ofnode_ or dev_ APIs instead of fdt_ and fdtdec_ APIs so that the
driver can support live DT.

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
drivers/power/regulator/gpio-regulator.c

index 017a3644fe2a63d49ceddd2b1421910ec0de704f..28c9e222e2bca1e1b52c9275681cfec1586a14d9 100644 (file)
@@ -18,8 +18,6 @@
 
 #define GPIO_REGULATOR_MAX_STATES      2
 
-DECLARE_GLOBAL_DATA_PTR;
-
 struct gpio_regulator_platdata {
        struct regulator_common_platdata common;
        struct gpio_desc gpio; /* GPIO for regulator voltage control */
@@ -32,8 +30,6 @@ static int gpio_regulator_ofdata_to_platdata(struct udevice *dev)
        struct dm_regulator_uclass_platdata *uc_pdata;
        struct gpio_regulator_platdata *dev_pdata;
        struct gpio_desc *gpio;
-       const void *blob = gd->fdt_blob;
-       int node = dev_of_offset(dev);
        int ret, count, i, j;
        u32 states_array[GPIO_REGULATOR_MAX_STATES * 2];
 
@@ -57,12 +53,20 @@ static int gpio_regulator_ofdata_to_platdata(struct udevice *dev)
        if (ret)
                debug("regulator gpio - not found! Error: %d", ret);
 
-       count = fdtdec_get_int_array_count(blob, node, "states",
-                                          states_array,
-                                          ARRAY_SIZE(states_array));
+       ret = dev_read_size(dev, "states");
+       if (ret < 0)
+               return ret;
 
-       if (!count)
-               return -EINVAL;
+       count = ret / sizeof(states_array[0]);
+       if (count > ARRAY_SIZE(states_array)) {
+               debug("regulator gpio - to many states (%d > %d)",
+                     count / 2, GPIO_REGULATOR_MAX_STATES);
+               count = ARRAY_SIZE(states_array);
+       }
+
+       ret = dev_read_u32_array(dev, "states", states_array, count);
+       if (ret < 0)
+               return ret;
 
        for (i = 0, j = 0; i < count; i += 2) {
                dev_pdata->voltages[j] = states_array[i];