From patchwork Wed Dec 9 13:11:19 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 57957 Delivered-To: patch@linaro.org Received: by 10.112.147.194 with SMTP id tm2csp658225lbb; Wed, 9 Dec 2015 05:11:27 -0800 (PST) X-Received: by 10.66.232.170 with SMTP id tp10mr7838688pac.38.1449666687792; Wed, 09 Dec 2015 05:11:27 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id hm2si12659966pac.186.2015.12.09.05.11.27; Wed, 09 Dec 2015 05:11:27 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-gpio-owner@vger.kernel.org; dkim=neutral (body hash did not verify) header.i=@linaro-org.20150623.gappssmtp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753598AbbLINL1 (ORCPT + 4 others); Wed, 9 Dec 2015 08:11:27 -0500 Received: from mail-lb0-f181.google.com ([209.85.217.181]:36437 "EHLO mail-lb0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753145AbbLINL0 (ORCPT ); Wed, 9 Dec 2015 08:11:26 -0500 Received: by lbblt2 with SMTP id lt2so29789667lbb.3 for ; Wed, 09 Dec 2015 05:11:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=K7vuJ0J96CNpvcdgxDONoPpmInrKEqQSa5qQwwQx710=; b=RGOUjiZsZGTyfEzdq/i4ExWbbqihclETlEoAdtcxnX/28cLQ+3Vq5+1fOdFjqFdGLw Dti6yT008XgPCgPJDqYw5sB6BUwmaovAsGmJ3n4LabVO7YQkmMUQidinoP1qQ/omE/YN 1JgDbQ5OUrK69DiTkr6OkBiAxJ5ShRuq7dowL806o3707diX6VW0x/Mqf/uiB2tiQYMG 1aQ5WyttshCkrUX3efEppQKHg/VnSPEzwfOogxF+d71l+tLPYikfPLwMJYxSRqiI/+IN UaSQBZFAY4vXjNvB/2nR8rSsuMgvWjFIKKiOEeQ4KUUK3JCmipCGlpoJB2ZwFdsWkUfX J4nw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=K7vuJ0J96CNpvcdgxDONoPpmInrKEqQSa5qQwwQx710=; b=RmxM+Vv4gcQHc3e6M11+1OjpiO1hOP115sUwBtacGgwv3gJ4cSyEdc+gnRQaPZ298a qy3SoYQpMAbfPvgdkgY226hK5YTYHFf7l3AWdlEfNslnDwDkd3uliCtfIoXNySn4PaqC Zzr0Baf03QC5zTJJVEijhrFaCMDtgJVst/by0rUmeyDQ4tSV6Pum8F7iRVASCsoM3Rfz x/llDkKgx3xDx8SdTDiKEztJZq8yy4RVAOCeh0a8F1ndMLz3GDPJElsYWRopBQzmepow jv9RCwtDaDx+4uk4d7HvbAK3t3WuH6TpvhjAvr7UK8FvVochh8qLbiJk5oZ8+YTBbqPo Q0/A== X-Gm-Message-State: ALoCoQnwuNv+sbEISkEvUwbI+szYw/5ucyTmpz+AiJ1ULMfglb/oO3sU+TKUoZB1xMB6KlpNA/tvfMhF2EXfHZH6tojU1NdhhQ== X-Received: by 10.112.129.233 with SMTP id nz9mr2351596lbb.112.1449666684792; Wed, 09 Dec 2015 05:11:24 -0800 (PST) Received: from localhost.localdomain ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id 88sm1429769lfq.3.2015.12.09.05.11.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 09 Dec 2015 05:11:24 -0800 (PST) From: Linus Walleij To: linux-gpio@vger.kernel.org, Johan Hovold , Alexandre Courbot , Michael Welling , Markus Pargmann Cc: Linus Walleij Subject: [PATCH 002/182] gpio: add a data pointer to gpio_chip Date: Wed, 9 Dec 2015 14:11:19 +0100 Message-Id: <1449666679-29707-1-git-send-email-linus.walleij@linaro.org> X-Mailer: git-send-email 2.4.3 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org 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(-) -- 2.4.3 -- To unsubscribe from this list: send the line "unsubscribe linux-gpio" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index e63bebc9ae60..6d40cf9426d3 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -297,7 +297,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 * @@ -305,7 +305,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. @@ -313,7 +313,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; @@ -325,6 +325,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; @@ -411,7 +413,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 b02c43be7859..f066742061f2 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 @@ -92,6 +93,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, @@ -166,7 +168,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)); @@ -175,6 +181,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