From: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>
To: matti.vaittinen@fi.rohmeurope.com, mazziesaccount@gmail.com
Cc: Lee Jones <lee.jones@linaro.org>,
Jacek Anaszewski <jacek.anaszewski@gmail.com>,
Pavel Machek <pavel@ucw.cz>, Dan Murphy <dmurphy@ti.com>,
Rob Herring <robh+dt@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Liam Girdwood <lgirdwood@gmail.com>,
Mark Brown <broonie@kernel.org>, Jonathan Corbet <corbet@lwn.net>,
Michael Turquette <mturquette@baylibre.com>,
Stephen Boyd <sboyd@kernel.org>,
Linus Walleij <linus.walleij@linaro.org>,
Bartosz Golaszewski <bgolaszewski@baylibre.com>,
Alessandro Zummo <a.zummo@towertech.it>,
Alexandre Belloni <alexandre.belloni@bootlin.com>,
Mauro Carvalho Chehab <mchehab+samsung@kernel.org>,
Jeff Kirsher <jeffrey.t.kirsher@intel.com>,
Wolfram Sang <wsa+renesas@sang-engineering.com>,
Marek Szyprowski <m.szyprowski@samsung.com>,
Heiner Kallweit <hkallweit1@gmail.com>,
Nicholas Mc Guire <hofrat@osadl.org>,
Phil Edworthy <phil.edworthy@renesas.com>,
linux-leds@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org,
linux-clk@vger.kernel.org, linux-gpio@vger.kernel.org,
linux-rtc@vger.kernel.org
Subject: [PATCH v4 10/16] gpio: devres: Add devm_gpiod_get_parent_array
Date: Sat, 16 Nov 2019 20:59:58 +0200 [thread overview]
Message-ID: <8dd9dad2765d47fd6c6fec20566326d00e48a696.1573928775.git.matti.vaittinen@fi.rohmeurope.com> (raw)
In-Reply-To: <cover.1573928775.git.matti.vaittinen@fi.rohmeurope.com>
Bunch of MFD sub-devices which are instantiated by MFD do not have
own device-tree nodes but have (for example) the GPIO consumer
information in parent device's DT node. Add resource managed
devm_gpiod_get_array() for such devices so that they can get the
consumer information from parent DT while still binding the GPIO
reservation life-time to this sub-device life time.
If devm_gpiod_get_array is used as such - then unloading and then
re-loading the child device fails as the GPIOs reserved during first
load are not freed when driver for sub-device is unload (if parent
stays there).
Signed-off-by: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>
---
.../driver-api/driver-model/devres.rst | 1 +
drivers/gpio/gpiolib-devres.c | 65 ++++++++++++++-----
include/linux/gpio/consumer.h | 5 ++
3 files changed, 56 insertions(+), 15 deletions(-)
diff --git a/Documentation/driver-api/driver-model/devres.rst b/Documentation/driver-api/driver-model/devres.rst
index a100bef54952..1b8302ba405b 100644
--- a/Documentation/driver-api/driver-model/devres.rst
+++ b/Documentation/driver-api/driver-model/devres.rst
@@ -270,6 +270,7 @@ GPIO
devm_gpiod_get_index()
devm_gpiod_get_index_optional()
devm_gpiod_get_optional()
+ devm_gpiod_get_parent_array()
devm_gpiod_put()
devm_gpiod_unhinge()
devm_gpiochip_add_data()
diff --git a/drivers/gpio/gpiolib-devres.c b/drivers/gpio/gpiolib-devres.c
index 98e3c20d9730..584fa6edfd20 100644
--- a/drivers/gpio/gpiolib-devres.c
+++ b/drivers/gpio/gpiolib-devres.c
@@ -270,19 +270,11 @@ struct gpio_desc *__must_check devm_gpiod_get_index_optional(struct device *dev,
}
EXPORT_SYMBOL_GPL(devm_gpiod_get_index_optional);
-/**
- * devm_gpiod_get_array - Resource-managed gpiod_get_array()
- * @dev: GPIO consumer
- * @con_id: function within the GPIO consumer
- * @flags: optional GPIO initialization flags
- *
- * Managed gpiod_get_array(). GPIO descriptors returned from this function are
- * automatically disposed on driver detach. See gpiod_get_array() for detailed
- * information about behavior and return values.
- */
-struct gpio_descs *__must_check devm_gpiod_get_array(struct device *dev,
- const char *con_id,
- enum gpiod_flags flags)
+static struct gpio_descs *__must_check
+__devm_gpiod_get_array(struct device *gpiodev,
+ struct device *managed,
+ const char *con_id,
+ enum gpiod_flags flags)
{
struct gpio_descs **dr;
struct gpio_descs *descs;
@@ -292,19 +284,62 @@ struct gpio_descs *__must_check devm_gpiod_get_array(struct device *dev,
if (!dr)
return ERR_PTR(-ENOMEM);
- descs = gpiod_get_array(dev, con_id, flags);
+ descs = gpiod_get_array(gpiodev, con_id, flags);
if (IS_ERR(descs)) {
devres_free(dr);
return descs;
}
*dr = descs;
- devres_add(dev, dr);
+ if (managed)
+ devres_add(managed, dr);
+ else
+ devres_add(gpiodev, dr);
return descs;
}
+
+/**
+ * devm_gpiod_get_array - Resource-managed gpiod_get_array()
+ * @dev: GPIO consumer
+ * @con_id: function within the GPIO consumer
+ * @flags: optional GPIO initialization flags
+ *
+ * Managed gpiod_get_array(). GPIO descriptors returned from this function are
+ * automatically disposed on driver detach. See gpiod_get_array() for detailed
+ * information about behavior and return values.
+ */
+struct gpio_descs *__must_check devm_gpiod_get_array(struct device *dev,
+ const char *con_id,
+ enum gpiod_flags flags)
+{
+ return __devm_gpiod_get_array(dev, NULL, con_id, flags);
+}
EXPORT_SYMBOL_GPL(devm_gpiod_get_array);
+/**
+ * devm_gpiod_get_parent_array - Resource-managed gpiod_get_array for subdevices
+ * @dev: Managed device whose parent is the GPIO consumer
+ * @con_id: function within the GPIO consumer
+ * @flags: optional GPIO initialization flags
+ *
+ * Managed gpiod_get_array() for subdevices. This function is intended to be
+ * used by MFD sub-devices whose GPIO bindings are in parent (MFD) device but
+ * whose GPIO reservation should last only for the dub-device life time.
+ * Returns EINVAL if no parent device is found. Rest of the behaviour and
+ * return values are as documented for gpiod_get_array()
+ */
+struct gpio_descs *__must_check
+devm_gpiod_get_parent_array(struct device *dev,
+ const char *con_id,
+ enum gpiod_flags flags)
+{
+ if (!dev | !dev->parent)
+ return ERR_PTR(-EINVAL);
+ return __devm_gpiod_get_array(dev->parent, dev, con_id, flags);
+}
+EXPORT_SYMBOL_GPL(devm_gpiod_get_parent_array);
+
/**
* devm_gpiod_get_array_optional - Resource-managed gpiod_get_array_optional()
* @dev: GPIO consumer
diff --git a/include/linux/gpio/consumer.h b/include/linux/gpio/consumer.h
index b70af921c614..01a82b1c6828 100644
--- a/include/linux/gpio/consumer.h
+++ b/include/linux/gpio/consumer.h
@@ -103,6 +103,11 @@ struct gpio_descs *__must_check devm_gpiod_get_array(struct device *dev,
struct gpio_descs *__must_check
devm_gpiod_get_array_optional(struct device *dev, const char *con_id,
enum gpiod_flags flags);
+struct gpio_descs *__must_check
+devm_gpiod_get_parent_array(struct device *dev,
+ const char *con_id,
+ enum gpiod_flags flags);
+
void devm_gpiod_put(struct device *dev, struct gpio_desc *desc);
void devm_gpiod_unhinge(struct device *dev, struct gpio_desc *desc);
void devm_gpiod_put_array(struct device *dev, struct gpio_descs *descs);
--
2.21.0
--
Matti Vaittinen, Linux device drivers
ROHM Semiconductors, Finland SWDC
Kiviharjunlenkki 1E
90220 OULU
FINLAND
~~~ "I don't think so," said Rene Descartes. Just then he vanished ~~~
Simon says - in Latin please.
~~~ "non cogito me" dixit Rene Descarte, deinde evanescavit ~~~
Thanks to Simon Glass for the translation =]
next prev parent reply other threads:[~2019-11-16 19:00 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-16 18:55 [PATCH v4 00/16] Support ROHM BD71828 PMIC Matti Vaittinen
2019-11-16 18:55 ` [PATCH v4 01/16] dt-bindings: regulator: Document ROHM BD71282 regulator bindings Matti Vaittinen
2019-11-16 18:56 ` [PATCH v4 02/16] dt-bindings: leds: ROHM BD71282 PMIC LED driver Matti Vaittinen
2019-11-16 18:56 ` [PATCH v4 03/16] dt-bindings: mfd: Document ROHM BD71828 bindings Matti Vaittinen
2019-11-16 18:57 ` [PATCH v4 04/16] mfd: rohm PMICs - use platform_device_id to match MFD sub-devices Matti Vaittinen
2019-11-16 18:57 ` [PATCH v4 05/16] mfd: bd71828: Support ROHM BD71828 PMIC - core Matti Vaittinen
2019-11-16 18:58 ` [PATCH v4 06/16] mfd: input: bd71828: Add power-key support Matti Vaittinen
2019-11-16 18:58 ` [PATCH v4 07/16] clk: bd718x7: Support ROHM BD71828 clk block Matti Vaittinen
2019-11-16 18:59 ` [PATCH v4 08/16] regulator: bd718x7: Split driver to common and bd718x7 specific parts Matti Vaittinen
2019-11-16 18:59 ` [PATCH v4 09/16] regulator: bd71828: Basic support for ROHM bd71828 PMIC regulators Matti Vaittinen
2019-11-16 18:59 ` Matti Vaittinen [this message]
2019-11-16 19:00 ` [PATCH v4 11/16] docs: driver-model: Add missing managed GPIO array get functions Matti Vaittinen
2019-11-16 19:00 ` [PATCH v4 12/16] regulator: bd71828: Add GPIO based run-level control for regulators Matti Vaittinen
2019-11-16 19:01 ` [PATCH v4 13/16] rtc: bd70528 add BD71828 support Matti Vaittinen
2019-11-16 19:01 ` [PATCH v4 14/16] gpio: bd71828: Initial support for ROHM BD71828 PMIC GPIOs Matti Vaittinen
2019-11-16 19:02 ` [PATCH v4 15/16] leds: Add common LED binding parsing support to LED class/core Matti Vaittinen
2019-11-18 5:59 ` Dan Carpenter
2019-11-18 6:34 ` Vaittinen, Matti
2019-11-16 19:02 ` [PATCH v4 16/16] led: bd71828: Support LED outputs on ROHM BD71828 PMIC Matti Vaittinen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8dd9dad2765d47fd6c6fec20566326d00e48a696.1573928775.git.matti.vaittinen@fi.rohmeurope.com \
--to=matti.vaittinen@fi.rohmeurope.com \
--cc=a.zummo@towertech.it \
--cc=alexandre.belloni@bootlin.com \
--cc=bgolaszewski@baylibre.com \
--cc=broonie@kernel.org \
--cc=corbet@lwn.net \
--cc=devicetree@vger.kernel.org \
--cc=dmurphy@ti.com \
--cc=hkallweit1@gmail.com \
--cc=hofrat@osadl.org \
--cc=jacek.anaszewski@gmail.com \
--cc=jeffrey.t.kirsher@intel.com \
--cc=lee.jones@linaro.org \
--cc=lgirdwood@gmail.com \
--cc=linus.walleij@linaro.org \
--cc=linux-clk@vger.kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-leds@vger.kernel.org \
--cc=linux-rtc@vger.kernel.org \
--cc=m.szyprowski@samsung.com \
--cc=mark.rutland@arm.com \
--cc=mazziesaccount@gmail.com \
--cc=mchehab+samsung@kernel.org \
--cc=mturquette@baylibre.com \
--cc=pavel@ucw.cz \
--cc=phil.edworthy@renesas.com \
--cc=robh+dt@kernel.org \
--cc=sboyd@kernel.org \
--cc=wsa+renesas@sang-engineering.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).