linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 1/4] regulator-core: support shared enable GPIO concept
@ 2013-01-15  4:35 Kim, Milo
  2013-01-27  6:00 ` Mark Brown
  0 siblings, 1 reply; 2+ messages in thread
From: Kim, Milo @ 2013-01-15  4:35 UTC (permalink / raw)
  To: Mark Brown; +Cc: Axel Lin, Girdwood, Liam, linux-kernel

 A Regulator can be enabled by external GPIO pin.
 This is configurable in the regulator_config.
 At this moment, this enable GPIO is owned by only one regulator device.
 In some devices, multiple regulators are enabled by shared one GPIO pin.
 This patch extends this limitation, enabling shared enable GPIO of regulators.

 New list for enable GPIO: 'regulator_ena_gpio_list'
   This manages enable GPIO list.

 New structure for supporting shared enable GPIO: 'regulator_enable_gpio'
   The enable count is used for balancing GPIO control count.
   The count is incremented when GPIO is enabled.
   On the other hand, it's decremented when GPIO is disabled.

 How it works
   If the GPIO is already used, skip requesting new GPIO usage.
   The GPIO is new one, request GPIO function and add it to the list of
   enable GPIO.
   This list is used for balancing enable GPIO count and pin control.

Signed-off-by: Milo(Woogyom) Kim <milo.kim@ti.com>
---
 drivers/regulator/core.c |   49 +++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 46 insertions(+), 3 deletions(-)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index de47880..1273090 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -51,6 +51,7 @@
 static DEFINE_MUTEX(regulator_list_mutex);
 static LIST_HEAD(regulator_list);
 static LIST_HEAD(regulator_map_list);
+static LIST_HEAD(regulator_ena_gpio_list);
 static bool has_full_constraints;
 static bool board_wants_dummy_regulator;
 
@@ -69,6 +70,18 @@ struct regulator_map {
 };
 
 /*
+ * struct regulator_enable_gpio
+ *
+ * Management for shared enable GPIO pin
+ */
+struct regulator_enable_gpio {
+	struct list_head list;
+	int gpio;
+	u32 enable_count;
+	struct regulator_dev *regulator;
+};
+
+/*
  * struct regulator
  *
  * One for each consumer device.
@@ -1456,6 +1469,38 @@ void devm_regulator_put(struct regulator *regulator)
 }
 EXPORT_SYMBOL_GPL(devm_regulator_put);
 
+/* Manage enable GPIO list. Same GPIO pin can be shared among regulators */
+static int regulator_ena_gpio_request(struct regulator_dev *rdev,
+				const struct regulator_config *config)
+{
+	struct regulator_enable_gpio *pin;
+	int ret;
+
+	list_for_each_entry(pin, &regulator_ena_gpio_list, list) {
+		if (pin->gpio == config->ena_gpio) {
+			rdev_info(rdev, "GPIO %d is already used\n",
+				config->ena_gpio);
+			return 0;
+		}
+	}
+
+	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)
+		return -ENOMEM;
+
+	pin->gpio = config->ena_gpio;
+	pin->regulator = rdev;
+	list_add(&pin->list, &regulator_ena_gpio_list);
+
+	return 0;
+}
+
 static int _regulator_do_enable(struct regulator_dev *rdev)
 {
 	int ret, delay;
@@ -3420,9 +3465,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
 	dev_set_drvdata(&rdev->dev, rdev);
 
 	if (config->ena_gpio && gpio_is_valid(config->ena_gpio)) {
-		ret = gpio_request_one(config->ena_gpio,
-				       GPIOF_DIR_OUT | config->ena_gpio_flags,
-				       rdev_get_name(rdev));
+		ret = regulator_ena_gpio_request(rdev, config);
 		if (ret != 0) {
 			rdev_err(rdev, "Failed to request enable GPIO%d: %d\n",
 				 config->ena_gpio, ret);
-- 
1.7.9.5


Best Regards,
Milo


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2 1/4] regulator-core: support shared enable GPIO concept
  2013-01-15  4:35 [PATCH v2 1/4] regulator-core: support shared enable GPIO concept Kim, Milo
@ 2013-01-27  6:00 ` Mark Brown
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Brown @ 2013-01-27  6:00 UTC (permalink / raw)
  To: Kim, Milo; +Cc: Axel Lin, Girdwood, Liam, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1639 bytes --]

On Tue, Jan 15, 2013 at 04:35:41AM +0000, Kim, Milo wrote:
>  A Regulator can be enabled by external GPIO pin.
>  This is configurable in the regulator_config.

Please use subject lines matching the subsystem - not doing this makes
it more likely that patches will be missed or responses delayed.  For
example, when looking at my patch queue for regulator patches I search
for "regulator:" in my review pending queue, patches that don't have
that won't turn up.  This should be "regulator: core: ...".

Anyway, this series looks pretty close now...

> +/* Manage enable GPIO list. Same GPIO pin can be shared among regulators */
> +static int regulator_ena_gpio_request(struct regulator_dev *rdev,
> +				const struct regulator_config *config)
> +{
> +	struct regulator_enable_gpio *pin;
> +	int ret;
> +
> +	list_for_each_entry(pin, &regulator_ena_gpio_list, list) {
> +		if (pin->gpio == config->ena_gpio) {
> +			rdev_info(rdev, "GPIO %d is already used\n",
> +				config->ena_gpio);
> +			return 0;

This log is going to get noisy once the GPIOs are shared.  A _dbg()
would be OK though.

> +	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)
> +		return -ENOMEM;

Should free the GPIO if there's an error here.

> +	pin->regulator = rdev;

Do we really want to keep track of the regulator here, again once we
start sharing pins...

We also need some matching code in the release path to free the GPIO and
struct when the regulator is removed.

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-01-27  6:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-01-15  4:35 [PATCH v2 1/4] regulator-core: support shared enable GPIO concept Kim, Milo
2013-01-27  6:00 ` Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).