From: Alexandre Courbot <acourbot@nvidia.com>
To: Grant Likely <grant.likely@secretlab.ca>,
Linus Walleij <linus.walleij@linaro.org>,
Arnd Bergmann <arnd@arndb.de>
Cc: linux-arch@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, gnurou@gmail.com,
Alexandre Courbot <acourbot@nvidia.com>
Subject: [PATCH 7/9] gpiolib: let gpio_chip reference its descriptors
Date: Sun, 3 Feb 2013 01:29:30 +0900 [thread overview]
Message-ID: <1359822572-26009-9-git-send-email-acourbot@nvidia.com> (raw)
In-Reply-To: <1359822572-26009-1-git-send-email-acourbot@nvidia.com>
Add a pointer to the gpio_chip structure that references the array of
GPIO descriptors belonging to the chip, and update gpiolib code to use
this pointer instead of the global gpio_desc[] array. This is another
step towards the removal of the gpio_desc[] global array.
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
---
drivers/gpio/gpiolib.c | 39 +++++++++++++++++++++++----------------
include/asm-generic/gpio.h | 3 +++
2 files changed, 26 insertions(+), 16 deletions(-)
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 82c40bd..9599b9a 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -72,6 +72,8 @@ struct gpio_desc {
};
static struct gpio_desc gpio_desc[ARCH_NR_GPIOS];
+#define GPIO_OFFSET_VALID(chip, offset) (offset >= 0 && offset < chip->ngpio)
+
static LIST_HEAD(gpio_chips);
#ifdef CONFIG_GPIO_SYSFS
@@ -112,7 +114,7 @@ static inline void desc_set_label(struct gpio_desc *d, const char *label)
*/
static int gpio_chip_hwgpio(const struct gpio_desc *desc)
{
- return (desc - &gpio_desc[0]) - desc->chip->base;
+ return desc - &desc->chip->desc[0];
}
/**
@@ -133,7 +135,7 @@ static struct gpio_desc *gpio_to_desc(unsigned gpio)
*/
static int desc_to_gpio(const struct gpio_desc *desc)
{
- return desc - &gpio_desc[0];
+ return desc->chip->base + gpio_chip_hwgpio(desc);
}
@@ -1006,9 +1008,9 @@ static int gpiochip_export(struct gpio_chip *chip)
unsigned gpio;
spin_lock_irqsave(&gpio_lock, flags);
- gpio = chip->base;
- while (gpio_desc[gpio].chip == chip)
- gpio_desc[gpio++].chip = NULL;
+ gpio = 0;
+ while (gpio < chip->ngpio)
+ chip->desc[gpio++].chip = NULL;
spin_unlock_irqrestore(&gpio_lock, flags);
pr_debug("%s: chip %s status %d\n", __func__,
@@ -1164,8 +1166,11 @@ int gpiochip_add(struct gpio_chip *chip)
status = gpiochip_add_to_list(chip);
if (status == 0) {
- for (id = base; id < base + chip->ngpio; id++) {
- gpio_desc[id].chip = chip;
+ chip->desc = &gpio_desc[chip->base];
+
+ for (id = 0; id < chip->ngpio; id++) {
+ struct gpio_desc *desc = &chip->desc[id];
+ desc->chip = chip;
/* REVISIT: most hardware initializes GPIOs as
* inputs (often with pullups enabled) so power
@@ -1174,7 +1179,7 @@ int gpiochip_add(struct gpio_chip *chip)
* and in case chip->get_direction is not set,
* we may expose the wrong direction in sysfs.
*/
- gpio_desc[id].flags = !chip->direction_input
+ desc->flags = !chip->direction_input
? (1 << FLAG_IS_OUT)
: 0;
}
@@ -1227,15 +1232,15 @@ int gpiochip_remove(struct gpio_chip *chip)
gpiochip_remove_pin_ranges(chip);
of_gpiochip_remove(chip);
- for (id = chip->base; id < chip->base + chip->ngpio; id++) {
- if (test_bit(FLAG_REQUESTED, &gpio_desc[id].flags)) {
+ for (id = 0; id < chip->ngpio; id++) {
+ if (test_bit(FLAG_REQUESTED, &chip->desc[id].flags)) {
status = -EBUSY;
break;
}
}
if (status == 0) {
- for (id = chip->base; id < chip->base + chip->ngpio; id++)
- gpio_desc[id].chip = NULL;
+ for (id = 0; id < chip->ngpio; id++)
+ chip->desc[id].chip = NULL;
list_del(&chip->list);
}
@@ -1560,11 +1565,13 @@ EXPORT_SYMBOL_GPL(gpio_free_array);
*/
const char *gpiochip_is_requested(struct gpio_chip *chip, unsigned offset)
{
- unsigned gpio = chip->base + offset;
- struct gpio_desc *desc = &gpio_desc[gpio];
+ struct gpio_desc *desc;
- if (!gpio_is_valid(gpio) || desc->chip != chip)
+ if (!GPIO_OFFSET_VALID(chip, offset))
return NULL;
+
+ desc = &chip->desc[offset];
+
if (test_bit(FLAG_REQUESTED, &desc->flags) == 0)
return NULL;
#ifdef CONFIG_DEBUG_FS
@@ -2003,7 +2010,7 @@ static void gpiolib_dbg_show(struct seq_file *s, struct gpio_chip *chip)
{
unsigned i;
unsigned gpio = chip->base;
- struct gpio_desc *gdesc = &gpio_desc[gpio];
+ struct gpio_desc *gdesc = &chip->desc[0];
int is_out;
for (i = 0; i < chip->ngpio; i++, gpio++, gdesc++) {
diff --git a/include/asm-generic/gpio.h b/include/asm-generic/gpio.h
index b562f95..bde6469 100644
--- a/include/asm-generic/gpio.h
+++ b/include/asm-generic/gpio.h
@@ -47,6 +47,7 @@ struct gpio;
struct seq_file;
struct module;
struct device_node;
+struct gpio_desc;
/**
* struct gpio_chip - abstract a GPIO controller
@@ -76,6 +77,7 @@ struct device_node;
* negative during registration, requests dynamic ID allocation.
* @ngpio: the number of GPIOs handled by this controller; the last GPIO
* handled is (base + ngpio - 1).
+ * @desc: array of ngpio descriptors. Private.
* @can_sleep: flag must be set iff get()/set() methods sleep, as they
* must while accessing GPIO expander chips over I2C or SPI
* @names: if set, must be an array of strings to use as alternative
@@ -126,6 +128,7 @@ struct gpio_chip {
struct gpio_chip *chip);
int base;
u16 ngpio;
+ struct gpio_desc *desc;
const char *const *names;
unsigned can_sleep:1;
unsigned exported:1;
--
1.8.1.1
next prev parent reply other threads:[~2013-02-02 16:27 UTC|newest]
Thread overview: 63+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-02 16:29 [PATCH 0/9] gpiolib: remove gpio_desc[] static array Alexandre Courbot
2013-02-02 16:29 ` Alexandre Courbot
2013-02-02 16:29 ` [PATCH 1/9] gpiolib: link all gpio_chips using a list Alexandre Courbot
2013-02-02 16:29 ` Alexandre Courbot
2013-02-05 17:00 ` Linus Walleij
2013-02-09 9:20 ` Grant Likely
2013-02-09 9:20 ` Grant Likely
2013-02-02 16:29 ` [PATCH 2/9] gpiolib: use gpio_chips list in gpiolib_sysfs_init Alexandre Courbot
2013-02-02 16:29 ` Alexandre Courbot
2013-02-05 17:04 ` Linus Walleij
2013-02-09 9:22 ` Grant Likely
2013-02-09 9:22 ` Grant Likely
2013-02-02 16:29 ` [PATCH 3/9] gpiolib: use gpio_chips list in gpiochip_find Alexandre Courbot
2013-02-02 16:29 ` Alexandre Courbot
2013-02-05 17:05 ` Linus Walleij
2013-02-09 9:25 ` Grant Likely
2013-02-09 9:25 ` Grant Likely
2013-02-02 16:29 ` [PATCH 4/9] gpiolib: use gpio_chips list in sysfs ops Alexandre Courbot
2013-02-02 16:29 ` Alexandre Courbot
2013-02-05 17:15 ` Linus Walleij
2013-02-05 17:15 ` Linus Walleij
2013-02-09 9:37 ` Grant Likely
2013-02-09 9:37 ` Grant Likely
2013-02-09 13:53 ` Alexandre Courbot
2013-02-02 16:29 ` [PATCH 5/9] gpiolib: use gpio_chips list in gpiochip_find_base Alexandre Courbot
2013-02-02 16:29 ` Alexandre Courbot
2013-02-05 17:21 ` Linus Walleij
2013-02-06 4:48 ` Alex Courbot
2013-02-09 9:47 ` Grant Likely
2013-02-09 9:47 ` Grant Likely
2013-02-02 16:29 ` [PATCH 6/9] gpiolib: use descriptors internally Alexandre Courbot
2013-02-02 16:29 ` Alexandre Courbot
2013-02-05 17:53 ` Linus Walleij
2013-02-07 6:57 ` Alexandre Courbot
2013-02-09 9:17 ` Grant Likely
2013-02-09 9:17 ` Grant Likely
2013-02-11 14:09 ` Linus Walleij
2013-02-11 15:40 ` Paul Mundt
2013-02-11 15:40 ` Paul Mundt
2013-02-11 17:39 ` Stephen Warren
2013-02-12 12:29 ` Linus Walleij
2013-02-12 15:59 ` Paul Mundt
2013-02-12 17:18 ` Arnd Bergmann
2013-02-09 13:11 ` Grant Likely
2013-02-09 13:11 ` Grant Likely
2013-02-09 14:15 ` Alexandre Courbot
2013-02-09 13:24 ` Grant Likely
2013-02-09 13:24 ` Grant Likely
2013-02-09 14:18 ` Alexandre Courbot
2013-02-02 16:29 ` Alexandre Courbot [this message]
2013-02-05 18:00 ` [PATCH 7/9] gpiolib: let gpio_chip reference its descriptors Linus Walleij
2013-02-09 13:28 ` Grant Likely
2013-02-02 16:29 ` [PATCH 8/9] gpiolib: use gpio_chips list in gpio_to_desc Alexandre Courbot
2013-02-05 18:01 ` Linus Walleij
2013-02-05 18:01 ` Linus Walleij
2013-02-09 9:58 ` Grant Likely
2013-02-09 9:58 ` Grant Likely
2013-02-09 14:21 ` Alexandre Courbot
2013-02-09 14:21 ` Alexandre Courbot
2013-02-09 14:37 ` Grant Likely
2013-02-02 16:29 ` [PATCH 9/9] gpiolib: dynamically allocate descriptors array Alexandre Courbot
2013-02-02 16:29 ` Alexandre Courbot
2013-02-05 18:02 ` Linus Walleij
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=1359822572-26009-9-git-send-email-acourbot@nvidia.com \
--to=acourbot@nvidia.com \
--cc=arnd@arndb.de \
--cc=gnurou@gmail.com \
--cc=grant.likely@secretlab.ca \
--cc=linus.walleij@linaro.org \
--cc=linux-arch@vger.kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.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).