]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
regulator: Add ena_gpio_initialized to regulator_config
authorMarkus Pargmann <mpa@pengutronix.de>
Wed, 8 Oct 2014 13:47:05 +0000 (15:47 +0200)
committerMark Brown <broonie@kernel.org>
Mon, 20 Oct 2014 11:23:45 +0000 (12:23 +0100)
Most drivers do not set the ena_gpio field of struct regulator_config
before passing it to the regulator core. This is fine as long as the
gpio identifier that is passed is a positive integer. But the gpio
identifier 0 is also valid. So we are not able to decide wether we got a
real gpio identifier or not based on a 0 in ena_gpio.

To be able to decide if it is a valid gpio that got passed, this patch
adds a ena_gpio_initialized field that should be set if was initialized
with a correct value, either a gpio >= 0 or a negative error number. The
core then checks if ena_gpio or ena_gpio_initialized before handling it
as a gpio. This way we maintain backwards compatibility and fix the
behaviour for gpio number 0.

Signed-off-by: Markus Pargmann <mpa@pengutronix.de>
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/regulator/core.c
include/linux/regulator/driver.h

index cd87c0c37034de32ad2f2c7ae2085d4761041761..55a87a2722d87174435c8f2d55e9b1e1a1b63391 100644 (file)
@@ -3650,7 +3650,8 @@ regulator_register(const struct regulator_desc *regulator_desc,
 
        dev_set_drvdata(&rdev->dev, rdev);
 
-       if (config->ena_gpio && gpio_is_valid(config->ena_gpio)) {
+       if ((config->ena_gpio || config->ena_gpio_initialized) &&
+           gpio_is_valid(config->ena_gpio)) {
                ret = regulator_ena_gpio_request(rdev, config);
                if (ret != 0) {
                        rdev_err(rdev, "Failed to request enable GPIO%d: %d\n",
index fc0ee0ce8325e1162b95034d00721d7f6dcf3764..28da08e4671f809c66aed0139486f07bfe4bf5ed 100644 (file)
@@ -301,6 +301,9 @@ struct regulator_desc {
  *           NULL).
  * @regmap: regmap to use for core regmap helpers if dev_get_regulator() is
  *          insufficient.
+ * @ena_gpio_initialized: GPIO controlling regulator enable was properly
+ *                        initialized, meaning that >= 0 is a valid gpio
+ *                        identifier and < 0 is a non existent gpio.
  * @ena_gpio: GPIO controlling regulator enable.
  * @ena_gpio_invert: Sense for GPIO enable control.
  * @ena_gpio_flags: Flags to use when calling gpio_request_one()
@@ -312,6 +315,7 @@ struct regulator_config {
        struct device_node *of_node;
        struct regmap *regmap;
 
+       bool ena_gpio_initialized;
        int ena_gpio;
        unsigned int ena_gpio_invert:1;
        unsigned int ena_gpio_flags;