diff options
Diffstat (limited to 'drivers/regulator')
-rw-r--r-- | drivers/regulator/Kconfig | 2 | ||||
-rw-r--r-- | drivers/regulator/anatop-regulator.c | 11 | ||||
-rw-r--r-- | drivers/regulator/bcm2835.c | 8 | ||||
-rw-r--r-- | drivers/regulator/core.c | 421 | ||||
-rw-r--r-- | drivers/regulator/fixed.c | 38 | ||||
-rw-r--r-- | drivers/regulator/helpers.c | 2 | ||||
-rw-r--r-- | drivers/regulator/of_regulator.c | 2 | ||||
-rw-r--r-- | drivers/regulator/pfuze.c | 12 | ||||
-rw-r--r-- | drivers/regulator/rk808-regulator.c | 46 | ||||
-rw-r--r-- | drivers/regulator/scmi-regulator.c | 33 | ||||
-rw-r--r-- | drivers/regulator/stm32-pwr.c | 7 | ||||
-rw-r--r-- | drivers/regulator/stm32-vrefbuf.c | 11 | ||||
-rw-r--r-- | drivers/regulator/stpmic1_regulator.c | 22 |
13 files changed, 356 insertions, 259 deletions
diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig index 56abe3896e..17e217f0bb 100644 --- a/drivers/regulator/Kconfig +++ b/drivers/regulator/Kconfig @@ -20,7 +20,7 @@ config REGULATOR_BCM283X config REGULATOR_PFUZE bool "Freescale PFUZE100/200/3000 regulator driver" depends on I2C - depends on ARCH_IMX6 || ARCH_IMX8MQ + depends on ARCH_IMX || COMPILE_TEST config REGULATOR_STM32_PWR bool "STMicroelectronics STM32 PWR" diff --git a/drivers/regulator/anatop-regulator.c b/drivers/regulator/anatop-regulator.c index 3f8473ec07..4b4c174304 100644 --- a/drivers/regulator/anatop-regulator.c +++ b/drivers/regulator/anatop-regulator.c @@ -6,7 +6,7 @@ #include <common.h> #include <init.h> #include <mfd/syscon.h> -#include <regmap.h> +#include <linux/regmap.h> #include <regulator.h> struct anatop_regulator { @@ -33,9 +33,9 @@ static struct regulator_ops anatop_rops = { .list_voltage = regulator_list_voltage_linear, }; -static int anatop_regulator_probe(struct device_d *dev) +static int anatop_regulator_probe(struct device *dev) { - struct device_node *np = dev->device_node; + struct device_node *np = dev->of_node; struct device_node *anatop_np; struct regulator_desc *rdesc; struct regulator_dev *rdev; @@ -131,15 +131,16 @@ static int anatop_regulator_probe(struct device_d *dev) } } - return of_regulator_register(rdev, dev->device_node); + return of_regulator_register(rdev, dev->of_node); } static const struct of_device_id of_anatop_regulator_match_tbl[] = { { .compatible = "fsl,anatop-regulator", }, { /* end */ } }; +MODULE_DEVICE_TABLE(of, of_anatop_regulator_match_tbl); -static struct driver_d anatop_regulator_driver = { +static struct driver anatop_regulator_driver = { .name = "anatop_regulator", .probe = anatop_regulator_probe, .of_compatible = DRV_OF_COMPAT(of_anatop_regulator_match_tbl), diff --git a/drivers/regulator/bcm2835.c b/drivers/regulator/bcm2835.c index 71a1d1a55d..fa9fc47207 100644 --- a/drivers/regulator/bcm2835.c +++ b/drivers/regulator/bcm2835.c @@ -9,7 +9,7 @@ #include <init.h> #include <regulator.h> -#include <mach/mbox.h> +#include <mach/bcm283x/mbox.h> #define REG_DEV(_id, _name) \ { \ @@ -110,7 +110,7 @@ const static struct regulator_ops bcm2835_ops = { .is_enabled = regulator_bcm2835_is_enabled, }; -static int regulator_bcm2835_probe(struct device_d *dev) +static int regulator_bcm2835_probe(struct device *dev) { struct regulator_bcm2835 *rb; int ret, i; @@ -122,7 +122,7 @@ static int regulator_bcm2835_probe(struct device_d *dev) rb->rdev.desc = &rb->rdesc; rb->rdev.dev = dev; - ret = dev_regulator_register(&rb->rdev, rb->devname, NULL); + ret = dev_regulator_register(&rb->rdev, rb->devname); if (ret) return ret; } @@ -130,7 +130,7 @@ static int regulator_bcm2835_probe(struct device_d *dev) return 0; } -static struct driver_d regulator_bcm2835_driver = { +static struct driver regulator_bcm2835_driver = { .name = "regulator-bcm2835", .probe = regulator_bcm2835_probe, }; diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 4876f0f44b..bbba3b0b57 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -13,41 +13,39 @@ static LIST_HEAD(regulator_list); -struct regulator_internal { - struct list_head list; - struct device_node *node; - struct regulator_dev *rdev; - int enable_count; - int enable_time_us; - int min_uv; - int max_uv; - char *name; - const char *supply; - struct list_head consumer_list; -}; - struct regulator { - struct regulator_internal *ri; + struct regulator_dev *rdev; + struct regulator_dev *rdev_consumer; struct list_head list; - struct device_d *dev; + struct device *dev; }; +const char *rdev_get_name(struct regulator_dev *rdev) +{ + if (rdev->name) + return rdev->name; + + return ""; +} + static int regulator_map_voltage(struct regulator_dev *rdev, int min_uV, int max_uV) { if (rdev->desc->ops->list_voltage == regulator_list_voltage_linear) return regulator_map_voltage_linear(rdev, min_uV, max_uV); - return -ENOSYS; + if (rdev->desc->ops->list_voltage == regulator_list_voltage_linear_range) + return regulator_map_voltage_linear_range(rdev, min_uV, max_uV); + + return regulator_map_voltage_iterate(rdev, min_uV, max_uV); } -static int regulator_enable_internal(struct regulator_internal *ri) +static int regulator_enable_rdev(struct regulator_dev *rdev) { - struct regulator_dev *rdev = ri->rdev; int ret; - if (ri->enable_count) { - ri->enable_count++; + if (rdev->enable_count) { + rdev->enable_count++; return 0; } @@ -59,30 +57,29 @@ static int regulator_enable_internal(struct regulator_internal *ri) if (ret) return ret; - ret = rdev->desc->ops->enable(ri->rdev); + ret = rdev->desc->ops->enable(rdev); if (ret) { regulator_disable(rdev->supply); return ret; } - if (ri->enable_time_us) - udelay(ri->enable_time_us); + if (rdev->enable_time_us) + udelay(rdev->enable_time_us); - ri->enable_count++; + rdev->enable_count++; return 0; } -static int regulator_disable_internal(struct regulator_internal *ri) +static int regulator_disable_rdev(struct regulator_dev *rdev) { - struct regulator_dev *rdev = ri->rdev; int ret; - if (!ri->enable_count) + if (!rdev->enable_count) return -EINVAL; - if (ri->enable_count > 1) { - ri->enable_count--; + if (rdev->enable_count > 1) { + rdev->enable_count--; return 0; } @@ -97,15 +94,14 @@ static int regulator_disable_internal(struct regulator_internal *ri) if (ret) return ret; - ri->enable_count--; + rdev->enable_count--; - return regulator_disable(ri->rdev->supply); + return regulator_disable(rdev->supply); } -static int regulator_set_voltage_internal(struct regulator_internal *ri, +static int regulator_set_voltage_rdev(struct regulator_dev *rdev, int min_uV, int max_uV) { - struct regulator_dev *rdev = ri->rdev; const struct regulator_ops *ops = rdev->desc->ops; unsigned int selector; int best_val = 0; @@ -129,6 +125,32 @@ static int regulator_set_voltage_internal(struct regulator_internal *ri, return -ENOSYS; } +static int regulator_get_voltage_rdev(struct regulator_dev *rdev) +{ + int sel, ret; + + if (rdev->desc->ops->get_voltage_sel) { + sel = rdev->desc->ops->get_voltage_sel(rdev); + if (sel < 0) + return sel; + ret = rdev->desc->ops->list_voltage(rdev, sel); + } else if (rdev->desc->ops->get_voltage) { + ret = rdev->desc->ops->get_voltage(rdev); + } else if (rdev->desc->ops->list_voltage) { + ret = rdev->desc->ops->list_voltage(rdev, 0); + } else if (rdev->desc->fixed_uV && (rdev->desc->n_voltages == 1)) { + ret = rdev->desc->fixed_uV; + } else if (rdev->min_uv && rdev->min_uv == rdev->max_uv) { + ret = rdev->min_uv; + } else if (rdev->supply) { + ret = regulator_get_voltage(rdev->supply); + } else { + return -EINVAL; + } + + return ret; +} + static int regulator_resolve_supply(struct regulator_dev *rdev) { struct regulator *supply; @@ -141,6 +163,8 @@ static int regulator_resolve_supply(struct regulator_dev *rdev) if (!supply_name) return 0; + rdev_dbg(rdev, "resolving %s\n", supply_name); + supply = regulator_get(rdev->dev, supply_name); if (IS_ERR(supply)) { if (deep_probe_is_supported()) @@ -155,107 +179,167 @@ static int regulator_resolve_supply(struct regulator_dev *rdev) * we couldn't. If you want to get rid of this warning, consider * migrating your platform to have deep probe support. */ - dev_warn(rdev->dev, "Failed to get '%s' regulator (ignored).\n", + rdev_warn(rdev, "Failed to get '%s' regulator (ignored).\n", supply_name); return 0; } + if (supply) + supply->rdev_consumer = rdev; + rdev->supply = supply; + return 0; } -static struct regulator_internal * __regulator_register(struct regulator_dev *rd, const char *name) +static int regulator_init_voltage(struct regulator_dev *rdev) { - struct regulator_internal *ri; - int ret; + int target_min, target_max, current_uV, ret; - ri = xzalloc(sizeof(*ri)); - ri->rdev = rd; + if (!rdev->min_uv || !rdev->max_uv) + return 0; - INIT_LIST_HEAD(&ri->consumer_list); + current_uV = regulator_get_voltage_rdev(rdev); + if (current_uV < 0) { + /* This regulator can't be read and must be initialized */ + rdev_info(rdev, "Setting %d-%duV\n", rdev->min_uv, rdev->max_uv); + regulator_set_voltage_rdev(rdev, rdev->min_uv, rdev->max_uv); + current_uV = regulator_get_voltage_rdev(rdev); + } - list_add_tail(&ri->list, ®ulator_list); + if (current_uV < 0) { + if (current_uV != -EPROBE_DEFER) + rdev_err(rdev, + "failed to get the current voltage: %pe\n", + ERR_PTR(current_uV)); + return current_uV; + } + + /* + * If we're below the minimum voltage move up to the + * minimum voltage, if we're above the maximum voltage + * then move down to the maximum. + */ + target_min = current_uV; + target_max = current_uV; + + if (current_uV < rdev->min_uv) { + target_min = rdev->min_uv; + target_max = rdev->min_uv; + } + + if (current_uV > rdev->max_uv) { + target_min = rdev->max_uv; + target_max = rdev->max_uv; + } + + if (target_min != current_uV || target_max != current_uV) { + rdev_info(rdev, "Bringing %duV into %d-%duV\n", + current_uV, target_min, target_max); + ret = regulator_set_voltage_rdev(rdev, target_min, target_max); + if (ret < 0) { + rdev_err(rdev, + "failed to apply %d-%duV constraint: %pe\n", + target_min, target_max, ERR_PTR(ret)); + return ret; + } + } + + return 0; +} + +static int __regulator_register(struct regulator_dev *rdev, const char *name) +{ + int ret; + + INIT_LIST_HEAD(&rdev->consumer_list); + + list_add_tail(&rdev->list, ®ulator_list); if (name) - ri->name = xstrdup(name); + rdev->name = xstrdup(name); - if (rd->boot_on || rd->always_on) { - ret = regulator_resolve_supply(ri->rdev); + ret = regulator_init_voltage(rdev); + if (ret) + goto err; + + if (rdev->boot_on || rdev->always_on) { + ret = regulator_resolve_supply(rdev); if (ret < 0) goto err; - ret = regulator_enable_internal(ri); + ret = regulator_enable_rdev(rdev); if (ret && ret != -ENOSYS) goto err; } - return ri; + return 0; err: - list_del(&ri->list); - free(ri->name); - free(ri); + list_del(&rdev->list); + free((char *)rdev->name); - return ERR_PTR(ret); + return ret; } #ifdef CONFIG_OFDEVICE /* * of_regulator_register - register a regulator corresponding to a device_node - * @rd: the regulator device providing the ops + * rdev: the regulator device providing the ops * @node: the device_node this regulator corresponds to * * Return: 0 for success or a negative error code */ -int of_regulator_register(struct regulator_dev *rd, struct device_node *node) +int of_regulator_register(struct regulator_dev *rdev, struct device_node *node) { - struct regulator_internal *ri; const char *name; + int ret; - if (!rd || !node) + if (!rdev || !node) return -EINVAL; - rd->boot_on = of_property_read_bool(node, "regulator-boot-on"); - rd->always_on = of_property_read_bool(node, "regulator-always-on"); + rdev->boot_on = of_property_read_bool(node, "regulator-boot-on"); + rdev->always_on = of_property_read_bool(node, "regulator-always-on"); name = of_get_property(node, "regulator-name", NULL); if (!name) name = node->name; - ri = __regulator_register(rd, name); - if (IS_ERR(ri)) - return PTR_ERR(ri); + rdev->node = node; + node->dev = rdev->dev; - ri->node = node; - node->dev = rd->dev; + if (rdev->desc->off_on_delay) + rdev->enable_time_us = rdev->desc->off_on_delay; - if (rd->desc->off_on_delay) - ri->enable_time_us = rd->desc->off_on_delay; - - if (rd->desc->fixed_uV && rd->desc->n_voltages == 1) - ri->min_uv = ri->max_uv = rd->desc->fixed_uV; + if (rdev->desc->fixed_uV && rdev->desc->n_voltages == 1) + rdev->min_uv = rdev->max_uv = rdev->desc->fixed_uV; of_property_read_u32(node, "regulator-enable-ramp-delay", - &ri->enable_time_us); + &rdev->enable_time_us); of_property_read_u32(node, "regulator-min-microvolt", - &ri->min_uv); + &rdev->min_uv); of_property_read_u32(node, "regulator-max-microvolt", - &ri->max_uv); + &rdev->max_uv); + + ret = __regulator_register(rdev, name); + if (ret) + return ret; return 0; } -static struct regulator_internal *of_regulator_get(struct device_d *dev, const char *supply) +static struct regulator_dev *of_regulator_get(struct device *dev, + const char *supply) { char *propname; - struct regulator_internal *ri; + struct regulator_dev *rdev; struct device_node *node, *node_parent; int ret; /* * If the device does have a device node return the dummy regulator. */ - if (!dev->device_node) + if (!dev->of_node) return NULL; propname = basprintf("%s-supply", supply); @@ -264,10 +348,10 @@ static struct regulator_internal *of_regulator_get(struct device_d *dev, const c * If the device node does not contain a supply property, this device doesn't * need a regulator. Return the dummy regulator in this case. */ - if (!of_get_property(dev->device_node, propname, NULL)) { + if (!of_get_property(dev->of_node, propname, NULL)) { dev_dbg(dev, "No %s-supply node found, using dummy regulator\n", supply); - ri = NULL; + rdev = NULL; goto out; } @@ -275,16 +359,16 @@ static struct regulator_internal *of_regulator_get(struct device_d *dev, const c * The device node specifies a supply, so it's mandatory. Return an error when * something goes wrong below. */ - node = of_parse_phandle(dev->device_node, propname, 0); + node = of_parse_phandle(dev->of_node, propname, 0); if (!node) { dev_dbg(dev, "No %s node found\n", propname); - ri = ERR_PTR(-EINVAL); + rdev = ERR_PTR(-EINVAL); goto out; } ret = of_device_ensure_probed(node); if (ret) { - /* + /* * If "barebox,allow-dummy-supply" property is set for regulator * provider allow use of dummy regulator (NULL is returned). * Check regulator node and its parent if this setting is set @@ -295,18 +379,18 @@ static struct regulator_internal *of_regulator_get(struct device_d *dev, const c of_get_property(node_parent, "barebox,allow-dummy-supply", NULL)) { dev_dbg(dev, "Allow use of dummy regulator for " \ "%s-supply\n", supply); - ri = NULL; + rdev = NULL; goto out; } - ri = ERR_PTR(ret); + rdev = ERR_PTR(ret); goto out; } - list_for_each_entry(ri, ®ulator_list, list) { - if (ri->node == node) { - dev_dbg(dev, "Using %s regulator from %s\n", - propname, node->full_name); + list_for_each_entry(rdev, ®ulator_list, list) { + if (rdev->node == node) { + dev_dbg(dev, "Using %s regulator from %pOF\n", + propname, node); goto out; } } @@ -316,52 +400,54 @@ static struct regulator_internal *of_regulator_get(struct device_d *dev, const c * added in future initcalls, so, instead of reporting a * complete failure report probe deferral */ - ri = ERR_PTR(-EPROBE_DEFER); + rdev = ERR_PTR(-EPROBE_DEFER); out: free(propname); - return ri; + return rdev; } #else -static struct regulator_internal *of_regulator_get(struct device_d *dev, const char *supply) +static struct regulator_dev *of_regulator_get(struct device *dev, + const char *supply) { return NULL; } #endif -int dev_regulator_register(struct regulator_dev *rd, const char * name, const char* supply) +int dev_regulator_register(struct regulator_dev *rdev, const char *name) { - struct regulator_internal *ri; - - ri = __regulator_register(rd, name); + int ret; - ri->supply = supply; + ret = __regulator_register(rdev, name); + if (ret) + return ret; return 0; } -static struct regulator_internal *dev_regulator_get(struct device_d *dev, const char *supply) +static struct regulator_dev *dev_regulator_get(struct device *dev, + const char *supply) { - struct regulator_internal *ri; - struct regulator_internal *ret = NULL; + struct regulator_dev *rdev; + struct regulator_dev *ret = NULL; int match, best = 0; const char *dev_id = dev ? dev_name(dev) : NULL; - list_for_each_entry(ri, ®ulator_list, list) { + list_for_each_entry(rdev, ®ulator_list, list) { match = 0; - if (ri->name) { - if (!dev_id || strcmp(ri->name, dev_id)) + if (rdev->name) { + if (!dev_id || strcmp(rdev->name, dev_id)) continue; match += 2; } - if (ri->supply) { - if (!supply || strcmp(ri->supply, supply)) + if (rdev->desc->supply_name) { + if (!supply || strcmp(rdev->desc->supply_name, supply)) continue; match += 1; } if (match > best) { - ret = ri; + ret = rdev; if (match != 3) best = match; else @@ -382,64 +468,73 @@ static struct regulator_internal *dev_regulator_get(struct device_d *dev, const * * Return: a regulator object or an error pointer */ -struct regulator *regulator_get(struct device_d *dev, const char *supply) +struct regulator *regulator_get(struct device *dev, const char *supply) { - struct regulator_internal *ri = NULL; + struct regulator_dev *rdev = NULL; struct regulator *r; int ret; - if (dev->device_node) { - ri = of_regulator_get(dev, supply); - if (IS_ERR(ri)) - return ERR_CAST(ri); + if (dev->of_node && supply) { + rdev = of_regulator_get(dev, supply); + if (IS_ERR(rdev)) + return ERR_CAST(rdev); } - if (!ri) { - ri = dev_regulator_get(dev, supply); - if (IS_ERR(ri)) - return ERR_CAST(ri); + if (!rdev) { + rdev = dev_regulator_get(dev, supply); + if (IS_ERR(rdev)) + return ERR_CAST(rdev); } - if (!ri) + if (!rdev) return NULL; - ret = regulator_resolve_supply(ri->rdev); + ret = regulator_resolve_supply(rdev); if (ret < 0) return ERR_PTR(ret); r = xzalloc(sizeof(*r)); - r->ri = ri; + r->rdev = rdev; r->dev = dev; - list_add_tail(&r->list, &ri->consumer_list); + list_add_tail(&r->list, &rdev->consumer_list); return r; } -static struct regulator_internal *regulator_by_name(const char *name) +void regulator_put(struct regulator *r) { - struct regulator_internal *ri; + if (IS_ERR_OR_NULL(r)) + return; + list_del(&r->list); + free(r); +} - list_for_each_entry(ri, ®ulator_list, list) - if (ri->name && !strcmp(ri->name, name)) - return ri; +static struct regulator_dev *regulator_by_name(const char *name) +{ + struct regulator_dev *rdev; + + list_for_each_entry(rdev, ®ulator_list, list) { + if (rdev->name && !strcmp(rdev->name, name)) + return rdev; + } return NULL; } struct regulator *regulator_get_name(const char *name) { - struct regulator_internal *ri; + struct regulator_dev *rdev; struct regulator *r; - ri = regulator_by_name(name); - if (!ri) + rdev = regulator_by_name(name); + if (!rdev) return ERR_PTR(-ENODEV); r = xzalloc(sizeof(*r)); - r->ri = ri; + r->rdev = rdev; - list_add_tail(&r->list, &ri->consumer_list); + list_add_tail(&r->list, &rdev->consumer_list); return r; } @@ -458,7 +553,7 @@ int regulator_enable(struct regulator *r) if (!r) return 0; - return regulator_enable_internal(r->ri); + return regulator_enable_rdev(r->rdev); } /* @@ -475,7 +570,7 @@ int regulator_disable(struct regulator *r) if (!r) return 0; - return regulator_disable_internal(r->ri); + return regulator_disable_rdev(r->rdev); } int regulator_set_voltage(struct regulator *r, int min_uV, int max_uV) @@ -483,7 +578,7 @@ int regulator_set_voltage(struct regulator *r, int min_uV, int max_uV) if (!r) return 0; - return regulator_set_voltage_internal(r->ri, min_uV, max_uV); + return regulator_set_voltage_rdev(r->rdev, min_uV, max_uV); } /** @@ -500,7 +595,7 @@ int regulator_set_voltage(struct regulator *r, int min_uV, int max_uV) * acquired then any regulators that were allocated will be freed * before returning to the caller. */ -int regulator_bulk_get(struct device_d *dev, int num_consumers, +int regulator_bulk_get(struct device *dev, int num_consumers, struct regulator_bulk_data *consumers) { int i; @@ -627,61 +722,55 @@ EXPORT_SYMBOL_GPL(regulator_bulk_free); int regulator_get_voltage(struct regulator *regulator) { - struct regulator_internal *ri; - struct regulator_dev *rdev; - int sel, ret; - if (!regulator) return -EINVAL; - ri = regulator->ri; - rdev = ri->rdev; - - if (rdev->desc->ops->get_voltage_sel) { - sel = rdev->desc->ops->get_voltage_sel(rdev); - if (sel < 0) - return sel; - ret = rdev->desc->ops->list_voltage(rdev, sel); - } else if (rdev->desc->ops->get_voltage) { - ret = rdev->desc->ops->get_voltage(rdev); - } else if (rdev->desc->ops->list_voltage) { - ret = rdev->desc->ops->list_voltage(rdev, 0); - } else if (rdev->desc->fixed_uV && (rdev->desc->n_voltages == 1)) { - ret = rdev->desc->fixed_uV; - } else if (ri->min_uv && ri->min_uv == ri->max_uv) { - ret = ri->min_uv; - } else if (rdev->supply) { - ret = regulator_get_voltage(rdev->supply); - } else { - return -EINVAL; - } - - return ret; + return regulator_get_voltage_rdev(regulator->rdev); } EXPORT_SYMBOL_GPL(regulator_get_voltage); -static void regulator_print_one(struct regulator_internal *ri) +static int regulator_name_indent(unsigned flags) { + return 30 + (flags & REGULATOR_PRINT_DEVS ? 50 : 0); +} + +static void regulator_print_one(struct regulator_dev *rdev, int level, unsigned flags) +{ + const char *name = rdev->name; struct regulator *r; + char buf[256]; + + if (!rdev) + return; - printf("%-20s %6d %10d %10d\n", ri->name, ri->enable_count, ri->min_uv, ri->max_uv); + if (flags & REGULATOR_PRINT_DEVS) { + snprintf(buf, sizeof(buf), "%s %s", dev_name(rdev->dev), rdev->name); + name = buf; + } - if (!list_empty(&ri->consumer_list)) { - printf(" consumers:\n"); + printf("%*s%-*s %6d %10d %10d\n", level * 3, "", + regulator_name_indent(flags) - level * 3, + name, rdev->enable_count, rdev->min_uv, rdev->max_uv); - list_for_each_entry(r, &ri->consumer_list, list) - printf(" %s\n", r->dev ? dev_name(r->dev) : "none"); + list_for_each_entry(r, &rdev->consumer_list, list) { + if (r->rdev_consumer) + regulator_print_one(r->rdev_consumer, level + 1, flags); + else + printf("%*s%s\n", (level + 1) * 3, "", r->dev ? dev_name(r->dev) : "none"); } } /* * regulators_print - print informations about all regulators */ -void regulators_print(void) +void regulators_print(unsigned flags) { - struct regulator_internal *ri; + struct regulator_dev *rdev; - printf("%-20s %6s %10s %10s\n", "name", "enable", "min_uv", "max_uv"); - list_for_each_entry(ri, ®ulator_list, list) - regulator_print_one(ri); + printf("%-*s %6s %10s %10s\n", regulator_name_indent(flags), + "name", "enable", "min_uv", "max_uv"); + list_for_each_entry(rdev, ®ulator_list, list) { + if (!rdev->supply) + regulator_print_one(rdev, 0, flags); + } } diff --git a/drivers/regulator/fixed.c b/drivers/regulator/fixed.c index bdb01c0a95..0edb5ceb10 100644 --- a/drivers/regulator/fixed.c +++ b/drivers/regulator/fixed.c @@ -9,12 +9,10 @@ #include <init.h> #include <regulator.h> #include <of.h> -#include <of_gpio.h> -#include <gpio.h> -#include <gpiod.h> +#include <linux/gpio/consumer.h> struct regulator_fixed { - int gpio; + struct gpio_desc *gpio; struct regulator_dev rdev; struct regulator_desc rdesc; }; @@ -23,20 +21,14 @@ static int regulator_fixed_enable(struct regulator_dev *rdev) { struct regulator_fixed *fix = container_of(rdev, struct regulator_fixed, rdev); - if (!gpio_is_valid(fix->gpio)) - return 0; - - return gpio_direction_active(fix->gpio, true); + return gpiod_direction_output(fix->gpio, true); } static int regulator_fixed_disable(struct regulator_dev *rdev) { struct regulator_fixed *fix = container_of(rdev, struct regulator_fixed, rdev); - if (!gpio_is_valid(fix->gpio)) - return 0; - - return gpio_direction_active(fix->gpio, false); + return gpiod_direction_output(fix->gpio, false); } const static struct regulator_ops fixed_ops = { @@ -44,25 +36,22 @@ const static struct regulator_ops fixed_ops = { .disable = regulator_fixed_disable, }; -static int regulator_fixed_probe(struct device_d *dev) +static int regulator_fixed_probe(struct device *dev) { - struct device_node *np = dev->device_node; + struct device_node *np = dev->of_node; struct regulator_fixed *fix; u32 delay; int ret; - if (!dev->device_node) + if (!dev->of_node) return -EINVAL; fix = xzalloc(sizeof(*fix)); - fix->gpio = -EINVAL; - - if (of_get_property(np, "gpio", NULL)) { - fix->gpio = gpiod_get(dev, NULL, GPIOD_ASIS); - if (fix->gpio < 0) { - ret = fix->gpio; - goto err; - } + + fix->gpio = gpiod_get_optional(dev, NULL, GPIOD_ASIS); + if (IS_ERR(fix->gpio)) { + ret = PTR_ERR(fix->gpio); + goto err; } fix->rdesc.ops = &fixed_ops; @@ -90,8 +79,9 @@ static struct of_device_id regulator_fixed_of_ids[] = { { .compatible = "regulator-fixed", }, { } }; +MODULE_DEVICE_TABLE(of, regulator_fixed_of_ids); -static struct driver_d regulator_fixed_driver = { +static struct driver regulator_fixed_driver = { .name = "regulator-fixed", .probe = regulator_fixed_probe, .of_compatible = DRV_OF_COMPAT(regulator_fixed_of_ids), diff --git a/drivers/regulator/helpers.c b/drivers/regulator/helpers.c index fb689a6bfc..80102e2c10 100644 --- a/drivers/regulator/helpers.c +++ b/drivers/regulator/helpers.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-only #include <common.h> -#include <regmap.h> +#include <linux/regmap.h> #include <regulator.h> /** diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c index c536a82c43..10f75a4f1c 100644 --- a/drivers/regulator/of_regulator.c +++ b/drivers/regulator/of_regulator.c @@ -33,7 +33,7 @@ struct devm_of_regulator_matches { * * Returns the number of matches found or a negative error code on failure. */ -int of_regulator_match(struct device_d *dev, struct device_node *node, +int of_regulator_match(struct device *dev, struct device_node *node, struct of_regulator_match *matches, unsigned int num_matches) { diff --git a/drivers/regulator/pfuze.c b/drivers/regulator/pfuze.c index 5ef5dacc6f..3e8890b10c 100644 --- a/drivers/regulator/pfuze.c +++ b/drivers/regulator/pfuze.c @@ -10,13 +10,12 @@ #include <errno.h> #include <malloc.h> #include <of.h> -#include <regmap.h> +#include <linux/regmap.h> #include <mfd/pfuze.h> #include <i2c/i2c.h> #include <poweroff.h> -#include <mach/imx6.h> #define DRIVERNAME "pfuze" @@ -41,7 +40,7 @@ #define PFUZE100_VGENxSTBY BIT(5) struct pfuze { - struct device_d *dev; + struct device *dev; struct regmap *map; struct i2c_client *client; int revision; @@ -144,7 +143,7 @@ static const struct regmap_config pfuze_regmap_i2c_config = { .max_register = 127, }; -static int __init pfuze_probe(struct device_d *dev) +static int __init pfuze_probe(struct device *dev) { int ret; @@ -165,7 +164,7 @@ static int __init pfuze_probe(struct device_d *dev) if (pfuze_init_callback) pfuze_init_callback(pfuze_dev->map); - if (of_property_read_bool(dev->device_node, + if (of_property_read_bool(dev->of_node, "fsl,pmic-stby-poweroff")) return poweroff_handler_register_fn(pfuze_power_off_prepare); @@ -187,8 +186,9 @@ static __maybe_unused struct of_device_id pfuze_dt_ids[] = { { .compatible = "fsl,pfuze3001" }, { } }; +MODULE_DEVICE_TABLE(of, pfuze_dt_ids); -static struct driver_d pfuze_i2c_driver = { +static struct driver pfuze_i2c_driver = { .name = "pfuze-i2c", .probe = pfuze_probe, .id_table = pfuze_ids, diff --git a/drivers/regulator/rk808-regulator.c b/drivers/regulator/rk808-regulator.c index 39eadbd3eb..adb0262314 100644 --- a/drivers/regulator/rk808-regulator.c +++ b/drivers/regulator/rk808-regulator.c @@ -14,7 +14,7 @@ #include <init.h> #include <i2c/i2c.h> #include <of_device.h> -#include <regmap.h> +#include <linux/regmap.h> #include <linux/regulator/of_regulator.h> #include <regulator.h> #include <linux/mfd/rk808.h> @@ -526,19 +526,6 @@ static struct rk_regulator_cfg rk809_reg[] = { .enable_mask = ENABLE_MASK(RK817_ID_DCDC4), .enable_val = ENABLE_MASK(RK817_ID_DCDC4), .disable_val = DISABLE_VAL(RK817_ID_DCDC4), - }}, {{ - /* .name = "DCDC_REG5", */ - .supply_name = "vcc9", - .ops = &rk809_buck5_ops_range, - .n_voltages = RK809_BUCK5_SEL_CNT, - .linear_ranges = rk809_buck5_voltage_ranges, - .n_linear_ranges = ARRAY_SIZE(rk809_buck5_voltage_ranges), - .vsel_reg = RK809_BUCK5_CONFIG(0), - .vsel_mask = RK809_BUCK5_VSEL_MASK, - .enable_reg = RK817_POWER_EN_REG(3), - .enable_mask = ENABLE_MASK(1), - .enable_val = ENABLE_MASK(1), - .disable_val = DISABLE_VAL(1), }}, RK817_DESC(/* "LDO_REG1", */ "vcc5", 600, 3400, 25, RK817_LDO_ON_VSEL_REG(0), RK817_LDO_VSEL_MASK, @@ -576,6 +563,20 @@ static struct rk_regulator_cfg rk809_reg[] = { RK817_LDO_ON_VSEL_REG(8), RK817_LDO_VSEL_MASK, RK817_POWER_EN_REG(3), ENABLE_MASK(0), DISABLE_VAL(0), 400), + {{ + /* .name = "DCDC_REG5", */ + .supply_name = "vcc9", + .ops = &rk809_buck5_ops_range, + .n_voltages = RK809_BUCK5_SEL_CNT, + .linear_ranges = rk809_buck5_voltage_ranges, + .n_linear_ranges = ARRAY_SIZE(rk809_buck5_voltage_ranges), + .vsel_reg = RK809_BUCK5_CONFIG(0), + .vsel_mask = RK809_BUCK5_VSEL_MASK, + .enable_reg = RK817_POWER_EN_REG(3), + .enable_mask = ENABLE_MASK(1), + .enable_val = ENABLE_MASK(1), + .disable_val = DISABLE_VAL(1), + }}, RK817_DESC_SWITCH(/* "SWITCH_REG1", */ "vcc9", RK817_POWER_EN_REG(3), ENABLE_MASK(2), DISABLE_VAL(2)), RK817_DESC_SWITCH(/* "SWITCH_REG2", */ "vcc8", @@ -769,7 +770,7 @@ static int rk808_regulator_register(struct rk808 *rk808, int id, struct of_regulator_match *match, struct rk_regulator_cfg *cfg) { - struct device_d *dev = &rk808->i2c->dev; + struct device *dev = &rk808->i2c->dev; int ret; if (!match->of_node) { @@ -782,10 +783,9 @@ static int rk808_regulator_register(struct rk808 *rk808, int id, cfg->rdev.regmap = rk808->regmap; ret = of_regulator_register(&cfg->rdev, match->of_node); - if (ret) { - dev_err(dev, "failed to register %s regulator\n", match->name); - return ret; - } + if (ret) + return dev_err_probe(dev, ret, "failed to register %s regulator\n", + match->name); dev_dbg(dev, "registered %s\n", match->name); @@ -884,11 +884,11 @@ static struct of_regulator_match rk818_reg_matches[] = { }; static_assert(ARRAY_SIZE(rk818_reg_matches) == RK818_NUM_REGULATORS); -static int rk808_regulator_dt_parse(struct device_d *dev, +static int rk808_regulator_dt_parse(struct device *dev, struct of_regulator_match *matches, int nregulators) { - struct device_node *np = dev->device_node; + struct device_node *np = dev->of_node; np = of_get_child_by_name(np, "regulators"); if (!np) @@ -897,7 +897,7 @@ static int rk808_regulator_dt_parse(struct device_d *dev, return of_regulator_match(dev, np, matches, nregulators); } -static int rk808_regulator_probe(struct device_d *dev) +static int rk808_regulator_probe(struct device *dev) { struct rk808 *rk808 = dev->parent->priv; struct rk_regulator_cfg *regulators; @@ -950,7 +950,7 @@ static int rk808_regulator_probe(struct device_d *dev) return 0; } -static struct driver_d rk808_regulator_driver = { +static struct driver rk808_regulator_driver = { .name = "rk808-regulator", .probe = rk808_regulator_probe, }; diff --git a/drivers/regulator/scmi-regulator.c b/drivers/regulator/scmi-regulator.c index 3e6fd3ec60..6f22fa6420 100644 --- a/drivers/regulator/scmi-regulator.c +++ b/drivers/regulator/scmi-regulator.c @@ -44,7 +44,7 @@ struct scmi_regulator { struct scmi_device *sdev; struct scmi_protocol_handle *ph; struct regulator_dev rdev; - struct device_node *device_node; + struct device_node *of_node; struct scmi_reg_desc sdesc; }; @@ -213,7 +213,7 @@ scmi_config_discrete_regulator_mappings(struct scmi_regulator *sreg, static int scmi_regulator_common_init(struct scmi_regulator *sreg) { int ret; - struct device_d *dev = &sreg->sdev->dev; + struct device *dev = &sreg->sdev->dev; const struct scmi_voltage_info *vinfo; struct scmi_reg_desc *sdesc = &sreg->sdesc; @@ -231,8 +231,8 @@ static int scmi_regulator_common_init(struct scmi_regulator *sreg) * be non-negative from here on. */ if (vinfo->negative_volts_allowed) { - dev_warn(dev, "Negative voltages NOT supported...skip %s\n", - sreg->device_node->full_name); + dev_warn(dev, "Negative voltages NOT supported...skip %pOF\n", + sreg->of_node); return -EOPNOTSUPP; } @@ -264,8 +264,8 @@ static int process_scmi_regulator_of_node(struct scmi_device *sdev, if (rinfo->sregv[dom]) { dev_err(&sdev->dev, - "SCMI Voltage Domain %d already in use. Skipping: %s\n", - dom, np->full_name); + "SCMI Voltage Domain %d already in use. Skipping: %pOF\n", + dom, np); return -EINVAL; } @@ -278,11 +278,11 @@ static int process_scmi_regulator_of_node(struct scmi_device *sdev, rinfo->sregv[dom]->ph = ph; /* get hold of good nodes */ - rinfo->sregv[dom]->device_node = np; + rinfo->sregv[dom]->of_node = np; dev_dbg(&sdev->dev, - "Found SCMI Regulator entry -- OF node [%d] -> %s\n", - dom, np->full_name); + "Found SCMI Regulator entry -- OF node [%d] -> %pOF\n", + dom, np); return 0; } @@ -299,7 +299,7 @@ static int scmi_regulator_probe(struct scmi_device *sdev) if (!handle) return -ENODEV; - voltage_ops = handle->protocol_get(sdev, SCMI_PROTOCOL_VOLTAGE, &ph); + voltage_ops = handle->dev_protocol_get(sdev, SCMI_PROTOCOL_VOLTAGE, &ph); if (IS_ERR(voltage_ops)) return PTR_ERR(voltage_ops); @@ -335,7 +335,7 @@ static int scmi_regulator_probe(struct scmi_device *sdev) * plausible SCMI Voltage Domain number, all belonging to this SCMI * platform instance node (handle->dev->of_node). */ - np = of_find_node_by_name(handle->dev->device_node, "regulators"); + np = of_find_node_by_name(handle->dev->of_node, "regulators"); for_each_child_of_node(np, child) { ret = process_scmi_regulator_of_node(sdev, ph, child, rinfo); /* abort on any mem issue */ @@ -362,13 +362,16 @@ static int scmi_regulator_probe(struct scmi_device *sdev) if (ret) continue; - ret = of_regulator_register(&sreg->rdev, np); + sreg->rdev.desc = &sdesc->desc; + sreg->rdev.dev = &sdev->dev; + + ret = of_regulator_register(&sreg->rdev, sreg->of_node); if (ret) continue; - dev_info(&sdev->dev, - "Regulator %s registered for domain [%d]\n", - sreg->sdesc.name, sreg->id); + dev_dbg(&sdev->dev, + "Regulator %s registered for domain [%d]\n", + sreg->sdesc.name, sreg->id); } return 0; diff --git a/drivers/regulator/stm32-pwr.c b/drivers/regulator/stm32-pwr.c index 8cb0b0c12e..ca03529b7f 100644 --- a/drivers/regulator/stm32-pwr.c +++ b/drivers/regulator/stm32-pwr.c @@ -141,7 +141,7 @@ static const struct stm32_pwr_desc stm32_pwr_desc[] = { PWR_REG(PWR_USB33, "usb33", 3300000, USB_3_3_EN, "vdd_3v3_usbfs"), }; -static int stm32_pwr_regulator_probe(struct device_d *dev) +static int stm32_pwr_regulator_probe(struct device *dev) { struct stm32_pwr_reg *priv; struct device_node *child; @@ -152,7 +152,7 @@ static int stm32_pwr_regulator_probe(struct device_d *dev) if (IS_ERR(iores)) return PTR_ERR(iores); - for_each_child_of_node(dev->device_node, child) { + for_each_child_of_node(dev->of_node, child) { const struct stm32_pwr_desc *desc = NULL; for (i = 0; i < STM32PWR_REG_NUM_REGS; i++) { @@ -206,8 +206,9 @@ static const struct of_device_id stm32_pwr_of_match[] = { { .compatible = "st,stm32mp1,pwr-reg", }, { /* sentinel */ }, }; +MODULE_DEVICE_TABLE(of, stm32_pwr_of_match); -static struct driver_d stm32_pwr_driver = { +static struct driver stm32_pwr_driver = { .probe = stm32_pwr_regulator_probe, .name = "stm32-pwr-regulator", .of_compatible = stm32_pwr_of_match, diff --git a/drivers/regulator/stm32-vrefbuf.c b/drivers/regulator/stm32-vrefbuf.c index 77287c2b0e..18cf53e735 100644 --- a/drivers/regulator/stm32-vrefbuf.c +++ b/drivers/regulator/stm32-vrefbuf.c @@ -27,7 +27,7 @@ struct stm32_vrefbuf { void __iomem *base; struct clk *clk; - struct device_d *dev; + struct device *dev; struct regulator_dev rdev; }; @@ -140,7 +140,7 @@ static const struct stm32_vrefbuf_desc stm32_vrefbuf_regu = { .supply_name = "vdda", }; -static int stm32_vrefbuf_probe(struct device_d *dev) +static int stm32_vrefbuf_probe(struct device *dev) { struct stm32_vrefbuf *priv; struct regulator_dev *rdev; @@ -173,7 +173,7 @@ static int stm32_vrefbuf_probe(struct device_d *dev) rdev->dev = dev; rdev->desc = &stm32_vrefbuf_regu.desc; - ret = of_regulator_register(rdev, dev->device_node); + ret = of_regulator_register(rdev, dev->of_node); if (ret) { ret = PTR_ERR(rdev); dev_err(dev, "register failed with error %d\n", ret); @@ -192,7 +192,7 @@ err_clk_dis: return ret; } -static void stm32_vrefbuf_remove(struct device_d *dev) +static void stm32_vrefbuf_remove(struct device *dev) { struct stm32_vrefbuf *priv = dev->priv; @@ -203,8 +203,9 @@ static const struct of_device_id __maybe_unused stm32_vrefbuf_of_match[] = { { .compatible = "st,stm32-vrefbuf", }, {}, }; +MODULE_DEVICE_TABLE(of, stm32_vrefbuf_of_match); -static struct driver_d stm32_vrefbuf_driver = { +static struct driver stm32_vrefbuf_driver = { .probe = stm32_vrefbuf_probe, .name = "stm32-vrefbuf", .remove = stm32_vrefbuf_remove, diff --git a/drivers/regulator/stpmic1_regulator.c b/drivers/regulator/stpmic1_regulator.c index 63ed4468ed..3ed351b580 100644 --- a/drivers/regulator/stpmic1_regulator.c +++ b/drivers/regulator/stpmic1_regulator.c @@ -5,7 +5,7 @@ #include <common.h> #include <init.h> #include <of_device.h> -#include <regmap.h> +#include <linux/regmap.h> #include <linux/regulator/of_regulator.h> #include <regulator.h> #include <linux/mfd/stpmic1.h> @@ -126,6 +126,7 @@ static const struct regulator_ops stpmic1_ldo_ops = { .is_enabled = regulator_is_enabled_regmap, .enable = regulator_enable_regmap, .disable = regulator_disable_regmap, + .get_voltage_sel = regulator_get_voltage_sel_regmap, .set_voltage_sel = regulator_set_voltage_sel_regmap, }; @@ -135,6 +136,7 @@ static const struct regulator_ops stpmic1_ldo3_ops = { .is_enabled = regulator_is_enabled_regmap, .enable = regulator_enable_regmap, .disable = regulator_disable_regmap, + .get_voltage_sel = regulator_get_voltage_sel_regmap, .set_voltage_sel = regulator_set_voltage_sel_regmap, }; @@ -150,6 +152,7 @@ static const struct regulator_ops stpmic1_buck_ops = { .is_enabled = regulator_is_enabled_regmap, .enable = regulator_enable_regmap, .disable = regulator_disable_regmap, + .get_voltage_sel = regulator_get_voltage_sel_regmap, .set_voltage_sel = regulator_set_voltage_sel_regmap, }; @@ -182,6 +185,7 @@ static const struct regulator_ops stpmic1_switch_regul_ops = { .enable_mask = LDO_ENABLE_MASK, \ .enable_val = 1, \ .disable_val = 0, \ + .supply_name = #base, \ } #define REG_LDO3(ids, base) { \ @@ -195,6 +199,7 @@ static const struct regulator_ops stpmic1_switch_regul_ops = { .enable_mask = LDO_ENABLE_MASK, \ .enable_val = 1, \ .disable_val = 0, \ + .supply_name = #base, \ } #define REG_LDO4(ids, base) { \ @@ -205,6 +210,7 @@ static const struct regulator_ops stpmic1_switch_regul_ops = { .enable_mask = LDO_ENABLE_MASK, \ .enable_val = 1, \ .disable_val = 0, \ + .supply_name = #base, \ } #define REG_BUCK(ids, base) { \ @@ -218,6 +224,7 @@ static const struct regulator_ops stpmic1_switch_regul_ops = { .enable_mask = BUCK_ENABLE_MASK, \ .enable_val = 1, \ .disable_val = 0, \ + .supply_name = #base, \ } #define REG_VREF_DDR(ids, base) { \ @@ -228,6 +235,7 @@ static const struct regulator_ops stpmic1_switch_regul_ops = { .enable_mask = BUCK_ENABLE_MASK, \ .enable_val = 1, \ .disable_val = 0, \ + .supply_name = #base, \ } #define REG_BOOST(ids, base) { \ @@ -238,6 +246,7 @@ static const struct regulator_ops stpmic1_switch_regul_ops = { .enable_mask = BOOST_ENABLED, \ .enable_val = BOOST_ENABLED, \ .disable_val = 0, \ + .supply_name = #base, \ } #define REG_VBUS_OTG(ids, base) { \ @@ -248,6 +257,7 @@ static const struct regulator_ops stpmic1_switch_regul_ops = { .enable_mask = USBSW_OTG_SWITCH_ENABLED, \ .enable_val = USBSW_OTG_SWITCH_ENABLED, \ .disable_val = 0, \ + .supply_name = #base, \ } #define REG_SW_OUT(ids, base) { \ @@ -258,6 +268,7 @@ static const struct regulator_ops stpmic1_switch_regul_ops = { .enable_mask = SWIN_SWOUT_ENABLED, \ .enable_val = SWIN_SWOUT_ENABLED, \ .disable_val = 0, \ + .supply_name = #base, \ } static struct stpmic1_regulator_cfg stpmic1_regulator_cfgs[] = { @@ -376,7 +387,7 @@ static struct of_regulator_match stpmic1_matches[] = { MATCH(pwr_sw2, SW_OUT), }; -static int stpmic1_regulator_register(struct device_d *dev, int id, +static int stpmic1_regulator_register(struct device *dev, int id, struct of_regulator_match *match, struct stpmic1_regulator_cfg *cfg) { @@ -404,11 +415,11 @@ static int stpmic1_regulator_register(struct device_d *dev, int id, return 0; } -static int stpmic1_regulator_probe(struct device_d *dev) +static int stpmic1_regulator_probe(struct device *dev) { int i, ret; - ret = of_regulator_match(dev, dev->device_node, stpmic1_matches, + ret = of_regulator_match(dev, dev->of_node, stpmic1_matches, ARRAY_SIZE(stpmic1_matches)); if (ret < 0) { dev_err(dev, "Error in PMIC regulator device tree node"); @@ -431,8 +442,9 @@ static __maybe_unused const struct of_device_id stpmic1_regulator_of_match[] = { { .compatible = "st,stpmic1-regulators" }, { /* sentinel */ }, }; +MODULE_DEVICE_TABLE(of, stpmic1_regulator_of_match); -static struct driver_d stpmic1_regulator_driver = { +static struct driver stpmic1_regulator_driver = { .name = "stpmic1-regulator", .probe = stpmic1_regulator_probe, .of_compatible = DRV_OF_COMPAT(stpmic1_regulator_of_match), |