From patchwork Mon Mar 28 19:04:08 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kamal Mostafa X-Patchwork-Id: 602580 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) by ozlabs.org (Postfix) with ESMTP id 3qYjy32lblz9s48; Tue, 29 Mar 2016 06:04:27 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.76) (envelope-from ) id 1akcSc-0003Gu-IC; Mon, 28 Mar 2016 19:04:22 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.76) (envelope-from ) id 1akcST-0003Dk-53 for kernel-team@lists.ubuntu.com; Mon, 28 Mar 2016 19:04:13 +0000 Received: from 1.general.kamal.us.vpn ([10.172.68.52] helo=fourier) by youngberry.canonical.com with esmtpsa (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1akcSS-0003nW-N3; Mon, 28 Mar 2016 19:04:12 +0000 Received: from kamal by fourier with local (Exim 4.86_2) (envelope-from ) id 1akcSQ-0002uL-11; Mon, 28 Mar 2016 12:04:10 -0700 From: Kamal Mostafa To: Linus Walleij Subject: [4.2.y-ckt stable] Patch "gpio: add a data pointer to gpio_chip" has been added to the 4.2.y-ckt tree Date: Mon, 28 Mar 2016 12:04:08 -0700 Message-Id: <1459191849-11142-1-git-send-email-kamal@canonical.com> X-Mailer: git-send-email 2.7.4 X-Extended-Stable: 4.2 Cc: Kamal Mostafa , kernel-team@lists.ubuntu.com X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.14 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: kernel-team-bounces@lists.ubuntu.com This is a note to let you know that I have just added a patch titled gpio: add a data pointer to gpio_chip to the linux-4.2.y-queue branch of the 4.2.y-ckt extended stable tree which can be found at: http://kernel.ubuntu.com/git/ubuntu/linux.git/log/?h=linux-4.2.y-queue This patch is scheduled to be released in version 4.2.8-ckt7. If you, or anyone else, feels it should not be added to this tree, please reply to this email. For more information about the 4.2.y-ckt tree, see https://wiki.ubuntu.com/Kernel/Dev/ExtendedStable Thanks. -Kamal ---8<------------------------------------------------------------ From 70ee401bd6a72031056860d1d1c8139d4ac5cd3b 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 commit b08ea35a3296ee25c4cb53a977b752266dafa2c2 upstream. 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 [ kamal: 4.2-stable prereq ] Signed-off-by: Kamal Mostafa --- drivers/gpio/gpiolib.c | 10 ++++++---- include/linux/gpio/driver.h | 14 +++++++++++++- 2 files changed, 19 insertions(+), 5 deletions(-) -- 2.7.4 diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 3144d19..27c5079d 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -219,7 +219,7 @@ static int gpiochip_add_to_list(struct gpio_chip *chip) } /** - * 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 * @@ -227,7 +227,7 @@ static int gpiochip_add_to_list(struct gpio_chip *chip) * 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->dev device must be registered before * the gpio framework's arch_initcall(). Otherwise sysfs initialization * for GPIOs will fail rudely. @@ -235,7 +235,7 @@ static int gpiochip_add_to_list(struct gpio_chip *chip) * 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; @@ -247,6 +247,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; @@ -322,7 +324,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 c8393cd..f819425 100644 --- a/include/linux/gpio/driver.h +++ b/include/linux/gpio/driver.h @@ -22,6 +22,7 @@ struct seq_file; * @dev: optional 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 @@ -80,6 +81,7 @@ struct gpio_chip { struct device *dev; struct device *cdev; struct module *owner; + void *data; struct list_head list; int (*request)(struct gpio_chip *chip, @@ -153,7 +155,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)); @@ -162,6 +168,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