[PATCH 5/5 v7] regulator: core: Only support passing enable GPIO descriptors

2018-11-18 Thread Linus Walleij
Now that we changed all providers to pass descriptors into the core
for enable GPIOs instead of a global GPIO number, delete the support
for passing GPIO numbers in, and we get a cleanup and size reduction
in the core, and from a GPIO point of view we use the modern, cleaner
interface.

Signed-off-by: Linus Walleij 
---
ChangeLog v6->v7:
- Resend with the rest.
ChangeLog v4->v6:
- Rebase on top of the other changes.
- Renumber to fit the rest of the series.
ChangeLog v3->v4:
- Also drop ena_gpio_invert from driver data
ChangeLog v2->v3:
- Resending.
ChangeLog v1->v2:
- Rebase the patch on the other changes.
---
 drivers/regulator/core.c | 32 ++--
 include/linux/regulator/driver.h | 12 +---
 2 files changed, 7 insertions(+), 37 deletions(-)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 109bd2bee868..0eb5c48f1162 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -23,7 +23,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -2015,35 +2014,19 @@ static int regulator_ena_gpio_request(struct 
regulator_dev *rdev,
 {
struct regulator_enable_gpio *pin;
struct gpio_desc *gpiod;
-   int ret;
 
-   if (config->ena_gpiod)
-   gpiod = config->ena_gpiod;
-   else
-   gpiod = gpio_to_desc(config->ena_gpio);
+   gpiod = config->ena_gpiod;
 
list_for_each_entry(pin, _ena_gpio_list, list) {
if (pin->gpiod == gpiod) {
-   rdev_dbg(rdev, "GPIO %d is already used\n",
-   config->ena_gpio);
+   rdev_dbg(rdev, "GPIO is already used\n");
goto update_ena_gpio_to_rdev;
}
}
 
-   if (!config->ena_gpiod) {
-   ret = gpio_request_one(config->ena_gpio,
-  GPIOF_DIR_OUT | config->ena_gpio_flags,
-  rdev_get_name(rdev));
-   if (ret)
-   return ret;
-   }
-
pin = kzalloc(sizeof(struct regulator_enable_gpio), GFP_KERNEL);
-   if (pin == NULL) {
-   if (!config->ena_gpiod)
-   gpio_free(config->ena_gpio);
+   if (pin == NULL)
return -ENOMEM;
-   }
 
pin->gpiod = gpiod;
list_add(>list, _ena_gpio_list);
@@ -2066,7 +2049,6 @@ static void regulator_ena_gpio_free(struct regulator_dev 
*rdev)
if (pin->gpiod == rdev->ena_pin->gpiod) {
if (pin->request_count <= 1) {
pin->request_count = 0;
-   gpiod_put(pin->gpiod);
list_del(>list);
kfree(pin);
rdev->ena_pin = NULL;
@@ -4336,15 +4318,13 @@ regulator_register(const struct regulator_desc 
*regulator_desc,
goto clean;
}
 
-   if (config->ena_gpiod ||
-   ((config->ena_gpio || config->ena_gpio_initialized) &&
-gpio_is_valid(config->ena_gpio))) {
+   if (config->ena_gpiod) {
mutex_lock(_list_mutex);
ret = regulator_ena_gpio_request(rdev, config);
mutex_unlock(_list_mutex);
if (ret != 0) {
-   rdev_err(rdev, "Failed to request enable GPIO%d: %d\n",
-config->ena_gpio, ret);
+   rdev_err(rdev, "Failed to request enable GPIO: %d\n",
+ret);
goto clean;
}
}
diff --git a/include/linux/regulator/driver.h b/include/linux/regulator/driver.h
index a9c030192147..10ee158eac00 100644
--- a/include/linux/regulator/driver.h
+++ b/include/linux/regulator/driver.h
@@ -400,13 +400,7 @@ struct regulator_desc {
  *   NULL).
  * @regmap: regmap to use for core regmap helpers if dev_get_regmap() 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_gpiod: GPIO descriptor controlling regulator enable.
- * @ena_gpio_invert: Sense for GPIO enable control.
- * @ena_gpio_flags: Flags to use when calling gpio_request_one()
+ * @ena_gpiod: GPIO controlling regulator enable.
  */
 struct regulator_config {
struct device *dev;
@@ -415,11 +409,7 @@ struct regulator_config {
struct device_node *of_node;
struct regmap *regmap;
 
-   bool ena_gpio_initialized;
-   int ena_gpio;
struct gpio_desc *ena_gpiod;
-   unsigned int ena_gpio_invert:1;
-   unsigned int ena_gpio_flags;
 };
 
 /*
-- 
2.19.1



[PATCH 5/5 v7] regulator: core: Only support passing enable GPIO descriptors

2018-11-18 Thread Linus Walleij
Now that we changed all providers to pass descriptors into the core
for enable GPIOs instead of a global GPIO number, delete the support
for passing GPIO numbers in, and we get a cleanup and size reduction
in the core, and from a GPIO point of view we use the modern, cleaner
interface.

Signed-off-by: Linus Walleij 
---
ChangeLog v6->v7:
- Resend with the rest.
ChangeLog v4->v6:
- Rebase on top of the other changes.
- Renumber to fit the rest of the series.
ChangeLog v3->v4:
- Also drop ena_gpio_invert from driver data
ChangeLog v2->v3:
- Resending.
ChangeLog v1->v2:
- Rebase the patch on the other changes.
---
 drivers/regulator/core.c | 32 ++--
 include/linux/regulator/driver.h | 12 +---
 2 files changed, 7 insertions(+), 37 deletions(-)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 109bd2bee868..0eb5c48f1162 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -23,7 +23,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -2015,35 +2014,19 @@ static int regulator_ena_gpio_request(struct 
regulator_dev *rdev,
 {
struct regulator_enable_gpio *pin;
struct gpio_desc *gpiod;
-   int ret;
 
-   if (config->ena_gpiod)
-   gpiod = config->ena_gpiod;
-   else
-   gpiod = gpio_to_desc(config->ena_gpio);
+   gpiod = config->ena_gpiod;
 
list_for_each_entry(pin, _ena_gpio_list, list) {
if (pin->gpiod == gpiod) {
-   rdev_dbg(rdev, "GPIO %d is already used\n",
-   config->ena_gpio);
+   rdev_dbg(rdev, "GPIO is already used\n");
goto update_ena_gpio_to_rdev;
}
}
 
-   if (!config->ena_gpiod) {
-   ret = gpio_request_one(config->ena_gpio,
-  GPIOF_DIR_OUT | config->ena_gpio_flags,
-  rdev_get_name(rdev));
-   if (ret)
-   return ret;
-   }
-
pin = kzalloc(sizeof(struct regulator_enable_gpio), GFP_KERNEL);
-   if (pin == NULL) {
-   if (!config->ena_gpiod)
-   gpio_free(config->ena_gpio);
+   if (pin == NULL)
return -ENOMEM;
-   }
 
pin->gpiod = gpiod;
list_add(>list, _ena_gpio_list);
@@ -2066,7 +2049,6 @@ static void regulator_ena_gpio_free(struct regulator_dev 
*rdev)
if (pin->gpiod == rdev->ena_pin->gpiod) {
if (pin->request_count <= 1) {
pin->request_count = 0;
-   gpiod_put(pin->gpiod);
list_del(>list);
kfree(pin);
rdev->ena_pin = NULL;
@@ -4336,15 +4318,13 @@ regulator_register(const struct regulator_desc 
*regulator_desc,
goto clean;
}
 
-   if (config->ena_gpiod ||
-   ((config->ena_gpio || config->ena_gpio_initialized) &&
-gpio_is_valid(config->ena_gpio))) {
+   if (config->ena_gpiod) {
mutex_lock(_list_mutex);
ret = regulator_ena_gpio_request(rdev, config);
mutex_unlock(_list_mutex);
if (ret != 0) {
-   rdev_err(rdev, "Failed to request enable GPIO%d: %d\n",
-config->ena_gpio, ret);
+   rdev_err(rdev, "Failed to request enable GPIO: %d\n",
+ret);
goto clean;
}
}
diff --git a/include/linux/regulator/driver.h b/include/linux/regulator/driver.h
index a9c030192147..10ee158eac00 100644
--- a/include/linux/regulator/driver.h
+++ b/include/linux/regulator/driver.h
@@ -400,13 +400,7 @@ struct regulator_desc {
  *   NULL).
  * @regmap: regmap to use for core regmap helpers if dev_get_regmap() 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_gpiod: GPIO descriptor controlling regulator enable.
- * @ena_gpio_invert: Sense for GPIO enable control.
- * @ena_gpio_flags: Flags to use when calling gpio_request_one()
+ * @ena_gpiod: GPIO controlling regulator enable.
  */
 struct regulator_config {
struct device *dev;
@@ -415,11 +409,7 @@ struct regulator_config {
struct device_node *of_node;
struct regmap *regmap;
 
-   bool ena_gpio_initialized;
-   int ena_gpio;
struct gpio_desc *ena_gpiod;
-   unsigned int ena_gpio_invert:1;
-   unsigned int ena_gpio_flags;
 };
 
 /*
-- 
2.19.1