From 58383c78425e4ee1c077253cf297b641c861c02e Mon Sep 17 00:00:00 2001 From: Linus Walleij Date: Wed, 4 Nov 2015 09:56:26 +0100 Subject: gpio: change member .dev to .parent MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The name .dev in a struct is normally reserved for a struct device that is let us say a superclass to the thing described by the struct. struct gpio_chip stands out by confusingly using a struct device *dev to point to the parent device (such as a platform_device) that represents the hardware. As we want to give gpio_chip:s real devices, this is not working. We need to rename this member to parent. This was done by two coccinelle scripts, I guess it is possible to combine them into one, but I don't know such stuff. They look like this: @@ struct gpio_chip *var; @@ -var->dev +var->parent and: @@ struct gpio_chip var; @@ -var.dev +var.parent and: @@ struct bgpio_chip *var; @@ -var->gc.dev +var->gc.parent Plus a few instances of bgpio that I couldn't figure out how to teach Coccinelle to rewrite. This patch hits all over the place, but I *strongly* prefer this solution to any piecemal approaches that just exercise patch mechanics all over the place. It mainly hits drivers/gpio and drivers/pinctrl which is my own backyard anyway. Cc: Haavard Skinnemoen Cc: Rafał Miłecki Cc: Richard Purdie Cc: Mauro Carvalho Chehab Cc: Alek Du Cc: Jaroslav Kysela Cc: Takashi Iwai Acked-by: Dmitry Torokhov Acked-by: Greg Kroah-Hartman Acked-by: Lee Jones Acked-by: Jiri Kosina Acked-by: Hans-Christian Egtvedt Acked-by: Jacek Anaszewski Signed-off-by: Linus Walleij --- drivers/gpio/gpiolib.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'drivers/gpio/gpiolib.c') diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index a18f00fc1bb8..8b35457013da 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -205,8 +205,8 @@ static int gpiochip_add_to_list(struct gpio_chip *chip) if (pos != &gpio_chips && pos->prev != &gpio_chips) { _chip = list_entry(pos->prev, struct gpio_chip, list); if (_chip->base + _chip->ngpio > chip->base) { - dev_err(chip->dev, - "GPIO integer space overlap, cannot add chip\n"); + dev_err(chip->parent, + "GPIO integer space overlap, cannot add chip\n"); err = -EBUSY; } } @@ -267,7 +267,7 @@ static int gpiochip_set_desc_names(struct gpio_chip *gc) gpio = gpio_name_to_desc(gc->names[i]); if (gpio) - dev_warn(gc->dev, "Detected name collision for " + dev_warn(gc->parent, "Detected name collision for " "GPIO name '%s'\n", gc->names[i]); } @@ -348,8 +348,8 @@ int gpiochip_add(struct gpio_chip *chip) INIT_LIST_HEAD(&chip->pin_ranges); #endif - if (!chip->owner && chip->dev && chip->dev->driver) - chip->owner = chip->dev->driver->owner; + if (!chip->owner && chip->parent && chip->parent->driver) + chip->owner = chip->parent->driver->owner; status = gpiochip_set_desc_names(chip); if (status) @@ -424,7 +424,8 @@ void gpiochip_remove(struct gpio_chip *chip) spin_unlock_irqrestore(&gpio_lock, flags); if (requested) - dev_crit(chip->dev, "REMOVING GPIOCHIP WITH GPIOS STILL REQUESTED\n"); + dev_crit(chip->parent, + "REMOVING GPIOCHIP WITH GPIOS STILL REQUESTED\n"); kfree(chip->desc); chip->desc = NULL; @@ -683,11 +684,11 @@ int _gpiochip_irqchip_add(struct gpio_chip *gpiochip, if (!gpiochip || !irqchip) return -EINVAL; - if (!gpiochip->dev) { + if (!gpiochip->parent) { pr_err("missing gpiochip .dev parent pointer\n"); return -EINVAL; } - of_node = gpiochip->dev->of_node; + of_node = gpiochip->parent->of_node; #ifdef CONFIG_OF_GPIO /* * If the gpiochip has an assigned OF node this takes precedence @@ -2503,7 +2504,7 @@ static int gpiolib_seq_show(struct seq_file *s, void *v) seq_printf(s, "%sGPIOs %d-%d", (char *)s->private, chip->base, chip->base + chip->ngpio - 1); - dev = chip->dev; + dev = chip->parent; if (dev) seq_printf(s, ", %s/%s", dev->bus ? dev->bus->name : "no-bus", dev_name(dev)); -- cgit v1.2.3 From 9c3c9bc9cc980d8981f75109f3921576daf75723 Mon Sep 17 00:00:00 2001 From: Dmitry Torokhov Date: Wed, 11 Nov 2015 11:45:30 -0800 Subject: gpiolib: tighten up ACPI legacy gpio lookups We should not fall back to the legacy unnamed gpio lookup style if the driver requests gpios with different names, because we'll give out the same gpio twice. Let's keep track of the names that were used for the device and only do the fallback for the first name used. Signed-off-by: Dmitry Torokhov Acked-by: Mika Westerberg Signed-off-by: Linus Walleij --- drivers/gpio/gpiolib-acpi.c | 43 +++++++++++++++++++++++++++++++++++++++++++ drivers/gpio/gpiolib.c | 3 +++ drivers/gpio/gpiolib.h | 8 ++++++++ 3 files changed, 54 insertions(+) (limited to 'drivers/gpio/gpiolib.c') diff --git a/drivers/gpio/gpiolib-acpi.c b/drivers/gpio/gpiolib-acpi.c index e4620e14457f..07e571a1a377 100644 --- a/drivers/gpio/gpiolib-acpi.c +++ b/drivers/gpio/gpiolib-acpi.c @@ -925,3 +925,46 @@ int acpi_gpio_count(struct device *dev, const char *con_id) } return count; } + +struct acpi_crs_lookup { + struct list_head node; + struct acpi_device *adev; + const char *con_id; +}; + +static DEFINE_MUTEX(acpi_crs_lookup_lock); +static LIST_HEAD(acpi_crs_lookup_list); + +bool acpi_can_fallback_to_crs(struct acpi_device *adev, const char *con_id) +{ + struct acpi_crs_lookup *l, *lookup = NULL; + + /* Never allow fallback if the device has properties */ + if (adev->data.properties || adev->driver_gpios) + return false; + + mutex_lock(&acpi_crs_lookup_lock); + + list_for_each_entry(l, &acpi_crs_lookup_list, node) { + if (l->adev == adev) { + lookup = l; + break; + } + } + + if (!lookup) { + lookup = kmalloc(sizeof(*lookup), GFP_KERNEL); + if (lookup) { + lookup->adev = adev; + lookup->con_id = con_id; + list_add_tail(&lookup->node, &acpi_crs_lookup_list); + } + } + + mutex_unlock(&acpi_crs_lookup_lock); + + return lookup && + ((!lookup->con_id && !con_id) || + (lookup->con_id && con_id && + strcmp(lookup->con_id, con_id) == 0)); +} diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 8b35457013da..dfe09c06df49 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -1869,6 +1869,9 @@ static struct gpio_desc *acpi_find_gpio(struct device *dev, const char *con_id, /* Then from plain _CRS GPIOs */ if (IS_ERR(desc)) { + if (!acpi_can_fallback_to_crs(adev, con_id)) + return ERR_PTR(-ENOENT); + desc = acpi_get_gpiod_by_index(adev, NULL, idx, &info); if (IS_ERR(desc)) return desc; diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h index 98ab08c0aa2d..2b87cbd68478 100644 --- a/drivers/gpio/gpiolib.h +++ b/drivers/gpio/gpiolib.h @@ -47,6 +47,8 @@ struct gpio_desc *acpi_node_get_gpiod(struct fwnode_handle *fwnode, struct acpi_gpio_info *info); int acpi_gpio_count(struct device *dev, const char *con_id); + +bool acpi_can_fallback_to_crs(struct acpi_device *adev, const char *con_id); #else static inline void acpi_gpiochip_add(struct gpio_chip *chip) { } static inline void acpi_gpiochip_remove(struct gpio_chip *chip) { } @@ -73,6 +75,12 @@ static inline int acpi_gpio_count(struct device *dev, const char *con_id) { return -ENODEV; } + +static inline bool acpi_can_fallback_to_crs(struct acpi_device *adev, + const char *con_id) +{ + return false; +} #endif struct gpio_desc *of_get_named_gpiod_flags(struct device_node *np, -- cgit v1.2.3 From ed37915cb1fde446bd52069d7a708301b7e7b607 Mon Sep 17 00:00:00 2001 From: Bamvor Jian Zhang Date: Sat, 14 Nov 2015 16:43:20 +0800 Subject: gpiolib: keep comment consistent with code The commit f881bab038c9 ("gpio: keep the GPIO line names internal") change the error to warning in gpiochip_set_desc_names. Update the comment accordingly. Signed-off-by: Bamvor Jian Zhang Signed-off-by: Linus Walleij --- drivers/gpio/gpiolib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/gpio/gpiolib.c') diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index dfe09c06df49..44c8d8352748 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -252,7 +252,7 @@ static struct gpio_desc *gpio_name_to_desc(const char * const name) * Takes the names from gc->names and checks if they are all unique. If they * are, they are assigned to their gpio descriptors. * - * Returns -EEXIST if one of the names is already used for a different GPIO. + * Warning if one of the names is already used for a different GPIO. */ static int gpiochip_set_desc_names(struct gpio_chip *gc) { -- cgit v1.2.3 From ef7c7553039b3d1c847b38b0f1ea208f8d5d8370 Mon Sep 17 00:00:00 2001 From: Bamvor Jian Zhang Date: Mon, 16 Nov 2015 13:02:46 +0800 Subject: gpiolib: improve overlap check of range of gpio There are limitations for the current checker: 1. Could not check the overlap if the new gpiochip is the secondly gpiochip. 2. Could not check the overlap if the new gpiochip is overlap with the left of gpiochip. E.g. if we insert [c, d] between [a,b] and [e, f], and e >= c + d, it will successful even if c < a + b. 3. Allow overlap of base of different gpiochip. This patch fix these issues by checking the overlap of both right and left gpiochip in the same loop statement. Signed-off-by: Bamvor Jian Zhang [Tweaked to remove unnecessary ret variable] Signed-off-by: Linus Walleij --- drivers/gpio/gpiolib.c | 55 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 19 deletions(-) (limited to 'drivers/gpio/gpiolib.c') diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 44c8d8352748..eed70c36e8ac 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -182,7 +182,7 @@ EXPORT_SYMBOL_GPL(gpiod_get_direction); /* * Add a new chip to the global chips list, keeping the list of chips sorted - * by base order. + * by range(means [base, base + ngpio - 1]) order. * * Return -EBUSY if the new chip overlaps with some other chip's integer * space. @@ -190,31 +190,48 @@ EXPORT_SYMBOL_GPL(gpiod_get_direction); static int gpiochip_add_to_list(struct gpio_chip *chip) { struct list_head *pos; - struct gpio_chip *_chip; - int err = 0; + struct gpio_chip *iterator; + struct gpio_chip *previous = NULL; - /* find where to insert our chip */ - list_for_each(pos, &gpio_chips) { - _chip = list_entry(pos, struct gpio_chip, list); - /* shall we insert before _chip? */ - if (_chip->base >= chip->base + chip->ngpio) - break; + if (list_empty(&gpio_chips)) { + pos = gpio_chips.next; + goto found; } - /* are we stepping on the chip right before? */ - if (pos != &gpio_chips && pos->prev != &gpio_chips) { - _chip = list_entry(pos->prev, struct gpio_chip, list); - if (_chip->base + _chip->ngpio > chip->base) { - dev_err(chip->parent, - "GPIO integer space overlap, cannot add chip\n"); - err = -EBUSY; + list_for_each(pos, &gpio_chips) { + iterator = list_entry(pos, struct gpio_chip, list); + if (iterator->base >= chip->base + chip->ngpio) { + /* + * Iterator is the first GPIO chip so there is no + * previous one + */ + if (previous == NULL) { + goto found; + } else { + /* + * We found a valid range(means + * [base, base + ngpio - 1]) between previous + * and iterator chip. + */ + if (previous->base + previous->ngpio + <= chip->base) + goto found; + } } + previous = iterator; } - if (!err) - list_add_tail(&chip->list, pos); + /* We are beyond the last chip in the list */ + if (iterator->base + iterator->ngpio <= chip->base) + goto found; - return err; + dev_err(chip->parent, + "GPIO integer space overlap, cannot add chip\n"); + return -EBUSY; + +found: + list_add_tail(&chip->list, pos); + return 0; } /** -- cgit v1.2.3 From 5ed41cc4baaf4127661d2a8f8f2ee6e3085e0fa9 Mon Sep 17 00:00:00 2001 From: Bamvor Jian Zhang Date: Mon, 16 Nov 2015 13:02:47 +0800 Subject: gpiolib: do not allow to insert an empty gpiochip We need to check if number of gpio is positive if there is no such check in devicetree or acpi or whatever called before gpiochip_add. I suppose that devicetree and acpi do not allow insert gpiochip with zero number but I do not know if it is enough to ignore this check in gpiochip_add. Signed-off-by: Bamvor Jian Zhang Signed-off-by: Linus Walleij --- drivers/gpio/gpiolib.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'drivers/gpio/gpiolib.c') diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index eed70c36e8ac..89e01538e40e 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -325,6 +325,11 @@ int gpiochip_add(struct gpio_chip *chip) if (!descs) return -ENOMEM; + if (chip->ngpio == 0) { + chip_err(chip, "tried to insert a GPIO chip with zero lines\n"); + return -EINVAL; + } + spin_lock_irqsave(&gpio_lock, flags); if (base < 0) { -- cgit v1.2.3 From c88402c2e63d0dc957d4748e249dfc40ec954086 Mon Sep 17 00:00:00 2001 From: Bamvor Jian Zhang Date: Wed, 18 Nov 2015 17:07:07 +0800 Subject: gpiolib: make comment consistent with code Commit f4d566a8a0e6 ("gpio: change member .dev to .parent") changes member of gpiochip from .dev to .parent. Update the corresponding comment. Signed-off-by: Bamvor Jian Zhang Signed-off-by: Linus Walleij --- drivers/gpio/gpiolib.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'drivers/gpio/gpiolib.c') diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 89e01538e40e..e63bebc9ae60 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -306,7 +306,7 @@ static int gpiochip_set_desc_names(struct gpio_chip *gc) * different chip. Otherwise it returns zero as a success code. * * When gpiochip_add() is called very early during boot, so that GPIOs - * can be freely used, the chip->dev device must be registered before + * can be freely used, the chip->parent device must be registered before * the gpio framework's arch_initcall(). Otherwise sysfs initialization * for GPIOs will fail rudely. * @@ -714,7 +714,8 @@ int _gpiochip_irqchip_add(struct gpio_chip *gpiochip, #ifdef CONFIG_OF_GPIO /* * If the gpiochip has an assigned OF node this takes precedence - * FIXME: get rid of this and use gpiochip->dev->of_node everywhere + * FIXME: get rid of this and use gpiochip->parent->of_node + * everywhere */ if (gpiochip->of_node) of_node = gpiochip->of_node; -- cgit v1.2.3 From 723a63034eaf10ad36eff28496667f8e2a9f5da3 Mon Sep 17 00:00:00 2001 From: Linus Walleij Date: Mon, 21 Dec 2015 23:10:12 +0100 Subject: Revert "gpio: revert get() to non-errorprogating behaviour" This reverts commit 45ad7db90b42555c8107f18ec6d6a1e9bce34860. We have fixed all the drivers that were returning ambious values not clamped to [0,1] or an error code, so return the error propagating behaviour of the API. Signed-off-by: Linus Walleij --- drivers/gpio/gpiolib.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'drivers/gpio/gpiolib.c') diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index d72ac1fdcd98..975a548bd71e 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -1303,13 +1303,7 @@ static int _gpiod_get_raw_value(const struct gpio_desc *desc) chip = desc->chip; offset = gpio_chip_hwgpio(desc); value = chip->get ? chip->get(chip, offset) : -EIO; - /* - * FIXME: fix all drivers to clamp to [0,1] or return negative, - * then change this to: - * value = value < 0 ? value : !!value; - * so we can properly propagate error codes. - */ - value = !!value; + value = value < 0 ? value : !!value; trace_gpio_value(desc_to_gpio(desc), 1, value); return value; } -- cgit v1.2.3 From e28ecca6eac40646780b83edab81a496cea3d220 Mon Sep 17 00:00:00 2001 From: Sudip Mukherjee Date: Sun, 27 Dec 2015 19:06:50 +0530 Subject: gpio: fix warning about iterator We were getting build warning about "iterator" being used uninitialized. Use iterator properly to fix the build warning and in the process remove the variable "pos" which is not required now. Signed-off-by: Sudip Mukherjee Signed-off-by: Linus Walleij --- drivers/gpio/gpiolib.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'drivers/gpio/gpiolib.c') diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 975a548bd71e..ca6630207c66 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -189,23 +189,21 @@ EXPORT_SYMBOL_GPL(gpiod_get_direction); */ static int gpiochip_add_to_list(struct gpio_chip *chip) { - struct list_head *pos; struct gpio_chip *iterator; struct gpio_chip *previous = NULL; if (list_empty(&gpio_chips)) { - pos = gpio_chips.next; - goto found; + list_add_tail(&chip->list, &gpio_chips); + return 0; } - list_for_each(pos, &gpio_chips) { - iterator = list_entry(pos, struct gpio_chip, list); + list_for_each_entry(iterator, &gpio_chips, list) { if (iterator->base >= chip->base + chip->ngpio) { /* * Iterator is the first GPIO chip so there is no * previous one */ - if (previous == NULL) { + if (!previous) { goto found; } else { /* @@ -221,7 +219,13 @@ static int gpiochip_add_to_list(struct gpio_chip *chip) previous = iterator; } - /* We are beyond the last chip in the list */ + /* + * We are beyond the last chip in the list and iterator now + * points to the head. + * Let iterator point to the last chip in the list. + */ + + iterator = list_last_entry(&gpio_chips, struct gpio_chip, list); if (iterator->base + iterator->ngpio <= chip->base) goto found; @@ -230,7 +234,7 @@ static int gpiochip_add_to_list(struct gpio_chip *chip) return -EBUSY; found: - list_add_tail(&chip->list, pos); + list_add_tail(&chip->list, &iterator->list); return 0; } -- cgit v1.2.3 From b08ea35a3296ee25c4cb53a977b752266dafa2c2 Mon Sep 17 00:00:00 2001 From: Linus Walleij Date: Thu, 3 Dec 2015 15:14:13 +0100 Subject: gpio: add a data pointer to gpio_chip This adds a void * pointer to gpio_chip so that driver can assign and retrieve some states. This is done to get rid of container_of() calls for gpio_chips embedded inside state containers, so we can remove the need to have the gpio_chip or later (planned) struct gpio_device be dynamically allocated at registration time, so that its struct device can be properly reference counted and not bound to its parent device (e.g. a platform_device) but instead live on after unregistration if it is opened by e.g. a char device or sysfs. The data is added with the new function gpiochip_add_data() and for compatibility we add static inline wrapper function gpiochip_add() that will call gpiochip_add_data() with NULL as argument. The latter will be removed once we have exorcised gpiochip_add() from the kernel. gpiochip_get_data() is added as a static inline accessor for drivers to quickly get their data out. Signed-off-by: Linus Walleij --- drivers/gpio/gpiolib.c | 10 ++++++---- include/linux/gpio/driver.h | 14 +++++++++++++- 2 files changed, 19 insertions(+), 5 deletions(-) (limited to 'drivers/gpio/gpiolib.c') diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index ca6630207c66..905408b8d54b 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -301,7 +301,7 @@ static int gpiochip_set_desc_names(struct gpio_chip *gc) } /** - * gpiochip_add() - register a gpio_chip + * gpiochip_add_data() - register a gpio_chip * @chip: the chip to register, with chip->base initialized * Context: potentially before irqs will work * @@ -309,7 +309,7 @@ static int gpiochip_set_desc_names(struct gpio_chip *gc) * because the chip->base is invalid or already associated with a * different chip. Otherwise it returns zero as a success code. * - * When gpiochip_add() is called very early during boot, so that GPIOs + * When gpiochip_add_data() is called very early during boot, so that GPIOs * can be freely used, the chip->parent device must be registered before * the gpio framework's arch_initcall(). Otherwise sysfs initialization * for GPIOs will fail rudely. @@ -317,7 +317,7 @@ static int gpiochip_set_desc_names(struct gpio_chip *gc) * If chip->base is negative, this requests dynamic assignment of * a range of valid GPIOs. */ -int gpiochip_add(struct gpio_chip *chip) +int gpiochip_add_data(struct gpio_chip *chip, void *data) { unsigned long flags; int status = 0; @@ -329,6 +329,8 @@ int gpiochip_add(struct gpio_chip *chip) if (!descs) return -ENOMEM; + chip->data = data; + if (chip->ngpio == 0) { chip_err(chip, "tried to insert a GPIO chip with zero lines\n"); return -EINVAL; @@ -415,7 +417,7 @@ err_free_descs: chip->label ? : "generic"); return status; } -EXPORT_SYMBOL_GPL(gpiochip_add); +EXPORT_SYMBOL_GPL(gpiochip_add_data); /** * gpiochip_remove() - unregister a gpio_chip diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h index 990797589408..b833a5f9629a 100644 --- a/include/linux/gpio/driver.h +++ b/include/linux/gpio/driver.h @@ -23,6 +23,7 @@ struct seq_file; * @parent: optional parent device providing the GPIOs * @cdev: class device used by sysfs interface (may be NULL) * @owner: helps prevent removal of modules exporting active GPIOs + * @data: per-instance data assigned by the driver * @list: links gpio_chips together for traversal * @request: optional hook for chip-specific activation, such as * enabling module power and clock; may sleep @@ -91,6 +92,7 @@ struct gpio_chip { struct device *parent; struct device *cdev; struct module *owner; + void *data; struct list_head list; int (*request)(struct gpio_chip *chip, @@ -165,7 +167,11 @@ extern const char *gpiochip_is_requested(struct gpio_chip *chip, unsigned offset); /* add/remove chips */ -extern int gpiochip_add(struct gpio_chip *chip); +extern int gpiochip_add_data(struct gpio_chip *chip, void *data); +static inline int gpiochip_add(struct gpio_chip *chip) +{ + return gpiochip_add_data(chip, NULL); +} extern void gpiochip_remove(struct gpio_chip *chip); extern struct gpio_chip *gpiochip_find(void *data, int (*match)(struct gpio_chip *chip, void *data)); @@ -174,6 +180,12 @@ extern struct gpio_chip *gpiochip_find(void *data, int gpiochip_lock_as_irq(struct gpio_chip *chip, unsigned int offset); void gpiochip_unlock_as_irq(struct gpio_chip *chip, unsigned int offset); +/* get driver data */ +static inline void *gpiochip_get_data(struct gpio_chip *chip) +{ + return chip->data; +} + struct gpio_chip *gpiod_to_chip(const struct gpio_desc *desc); #ifdef CONFIG_GPIOLIB_IRQCHIP -- cgit v1.2.3 From 09dd5f9e240e738b4d5e2e602c3b66659babf068 Mon Sep 17 00:00:00 2001 From: Linus Walleij Date: Mon, 7 Dec 2015 15:31:58 +0100 Subject: gpio: fix misleading comment We are not relying on container_of() now that we have gpiochip_get_data(). Signed-off-by: Linus Walleij --- drivers/gpio/gpiolib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/gpio/gpiolib.c') diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 905408b8d54b..3db34e74bc34 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -688,7 +688,7 @@ static void gpiochip_irqchip_remove(struct gpio_chip *gpiochip) * gpiochip, providing an irq domain to translate the local IRQs to * global irqs in the gpiolib core, and making sure that the gpiochip * is passed as chip data to all related functions. Driver callbacks - * need to use container_of() to get their local state containers back + * need to use gpiochip_get_data() to get their local state containers back * from the gpiochip passed as chip data. An irqdomain will be stored * in the gpiochip that shall be used by the driver to handle IRQ number * translation. The gpiochip will need to be initialized and registered -- cgit v1.2.3 From 96098df125c0a966631ec114081d8f5630a0e4b8 Mon Sep 17 00:00:00 2001 From: Julien Grossholtz Date: Thu, 7 Jan 2016 16:46:45 -0500 Subject: gpiolib: fix chip order in gpio list In some situations the gpio_list order is not correct. As a consequence gpiochip_find_base returns the same base number twice. This happens when a first ship is added with manual base number, then other ships are added using automatic base number. To prevent this behaviour, this patch add the new chip after the last element of the gpio list. Signed-off-by: Julien Grossholtz Signed-off-by: Linus Walleij --- drivers/gpio/gpiolib.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'drivers/gpio/gpiolib.c') diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 3db34e74bc34..a1805734aef8 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -226,8 +226,10 @@ static int gpiochip_add_to_list(struct gpio_chip *chip) */ iterator = list_last_entry(&gpio_chips, struct gpio_chip, list); - if (iterator->base + iterator->ngpio <= chip->base) - goto found; + if (iterator->base + iterator->ngpio <= chip->base) { + list_add(&chip->list, &iterator->list); + return 0; + } dev_err(chip->parent, "GPIO integer space overlap, cannot add chip\n"); -- cgit v1.2.3