From: chunkeey@gmail.com (Christian Lamparter)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v3 1/2] gpiolib: do not add duplicated GPIO Pin ranges
Date: Tue, 10 Apr 2018 16:18:15 +0200 [thread overview]
Message-ID: <20180410141816.30452-1-chunkeey@gmail.com> (raw)
look if a GPIO range with the same ID has already
been registered.
For pinctrls that are set up through devicetree, the
GPIO Range might be already set by the the gpio-ranges
property.
(see Documentation/devicetree/bindings/gpio/gpio.txt)
Signed-off-by: Christian Lamparter <chunkeey@gmail.com>
---
drivers/gpio/gpiolib.c | 41 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 41 insertions(+)
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 43aeb07343ec..3882e1ff85fa 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -2069,6 +2069,19 @@ int gpiochip_generic_config(struct gpio_chip *chip, unsigned offset,
}
EXPORT_SYMBOL_GPL(gpiochip_generic_config);
+static struct gpio_pin_range *gpiochip_find_by_id(struct gpio_chip *chip,
+ unsigned int id)
+{
+ struct gpio_pin_range *pin_range;
+ struct gpio_device *gdev = chip->gpiodev;
+
+ list_for_each_entry(pin_range, &gdev->pin_ranges, node) {
+ if (pin_range->range.id == id)
+ return pin_range;
+ }
+ return NULL;
+}
+
#ifdef CONFIG_PINCTRL
/**
@@ -2086,6 +2099,20 @@ int gpiochip_add_pingroup_range(struct gpio_chip *chip,
struct gpio_device *gdev = chip->gpiodev;
int ret;
+ /*
+ * look if a GPIO range with the same ID has already been registered.
+ * For pinctrls that are set up through devicetree, the GPIO Range
+ * might be already set by the the gpio-ranges property.
+ * (see Documentation/devicetree/bindings/gpio/gpio.txt)
+ */
+ pin_range = gpiochip_find_by_id(chip, gpio_offset);
+ if (pin_range) {
+ chip_dbg(chip, "found existing GPIO range %d->%d - skipping\n",
+ gpio_offset,
+ gpio_offset + pin_range->range.npins - 1);
+ return 0;
+ }
+
pin_range = kzalloc(sizeof(*pin_range), GFP_KERNEL);
if (!pin_range) {
chip_err(chip, "failed to allocate pin ranges\n");
@@ -2139,6 +2166,20 @@ int gpiochip_add_pin_range(struct gpio_chip *chip, const char *pinctl_name,
struct gpio_device *gdev = chip->gpiodev;
int ret;
+ /*
+ * look if a GPIO range with the same ID has already been registered.
+ * For pinctrls that are set up through devicetree, the GPIO Range
+ * might be already set by the the gpio-ranges property.
+ * (see Documentation/devicetree/bindings/gpio/gpio.txt)
+ */
+ pin_range = gpiochip_find_by_id(chip, gpio_offset);
+ if (pin_range) {
+ chip_dbg(chip, "found existing GPIO range %d->%d - skipping\n",
+ gpio_offset,
+ gpio_offset + pin_range->range.npins - 1);
+ return 0;
+ }
+
pin_range = kzalloc(sizeof(*pin_range), GFP_KERNEL);
if (!pin_range) {
chip_err(chip, "failed to allocate pin ranges\n");
--
2.17.0
next reply other threads:[~2018-04-10 14:18 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-10 14:18 Christian Lamparter [this message]
2018-04-10 14:18 ` [PATCH v3 2/2] pinctrl: msm: fix gpio-hog related boot issues Christian Lamparter
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=20180410141816.30452-1-chunkeey@gmail.com \
--to=chunkeey@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
/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).