From patchwork Mon Jan 15 16:22:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ludovic Desroches X-Patchwork-Id: 10164737 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7D158602C2 for ; Mon, 15 Jan 2018 16:24:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C1AE421E5A for ; Mon, 15 Jan 2018 16:24:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B4D89280CF; Mon, 15 Jan 2018 16:24:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3F78E21E5A for ; Mon, 15 Jan 2018 16:24:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=qFW+39L9/4ILeMX2mX1KwJUHCsDlbnOdk4yJ5kFDYJI=; b=PM6ptTMm7y+OTF beTp7Db1tC2bxxc+6KeRxS8rY/Xb/+KwS+dCvVqcFPIN+fscjQrXdbEllHNvpscy8mawMYmr4UACn fcpLPx/t+RQOSf9jbpZ7gVLc4h4FazW1wlwsHtozcJlGOipRbKS2GUnhJRv5YO2gYWRu3vNBjpmWS pvUr8QqFqENGNhe7iBWrffcFy7IpccyllFmW69Eq+d/zyw0Vz30bE+YK/YMqEq8zeDb1tH2s2XpF9 GWoBlC+z/GM1/gp/3xNmsE2Z0wD3lDGCXJLY2IOex6EclLN1h+9ESzH5rou2NceBTaZ0m5Y8vKnQ0 /FfC3rOm4glZfIOxXUZg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1eb7Yr-0003hB-Eh; Mon, 15 Jan 2018 16:24:37 +0000 Received: from esa3.microchip.iphmx.com ([68.232.153.233]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1eb7Ya-0003JC-7t for linux-arm-kernel@lists.infradead.org; Mon, 15 Jan 2018 16:24:22 +0000 X-IronPort-AV: E=Sophos;i="5.46,364,1511852400"; d="scan'208";a="10564927" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa3.microchip.iphmx.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 15 Jan 2018 09:24:12 -0700 Received: from ibiza.rfo.atmel.com (10.10.76.4) by chn-sv-exch07.mchp-main.com (10.10.76.108) with Microsoft SMTP Server id 14.3.352.0; Mon, 15 Jan 2018 09:24:11 -0700 From: Ludovic Desroches To: , Subject: [RFC PATCH 2/2] gpio: provide a consumer when requesting a gpio Date: Mon, 15 Jan 2018 17:22:33 +0100 Message-ID: <20180115162233.6205-3-ludovic.desroches@microchip.com> X-Mailer: git-send-email 2.12.2 In-Reply-To: <20180115162233.6205-1-ludovic.desroches@microchip.com> References: <20180115162233.6205-1-ludovic.desroches@microchip.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180115_082420_297256_4968048F X-CRM114-Status: GOOD ( 15.78 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: nicolas.free@microchip.com, linus.walleij@linaro.org, Ludovic Desroches , linux-kernel@vger.kernel.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP It can be useful for the pinmuxing layer to know which device is requesting a GPIO. Add a consumer variant for gpiod_request to reach this goal. GPIO chips managed by pin controllers should provide the new request_consumer operation. They can rely on gpiochip_generic_request_consumer instead of gpiochip_generic_request. Signed-off-by: Ludovic Desroches --- drivers/gpio/gpiolib.c | 40 +++++++++++++++++++++++++++++++++------- include/linux/gpio/driver.h | 5 +++++ 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 39a0144d5be5..e6645101ec74 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -1970,6 +1970,20 @@ int gpiochip_generic_request(struct gpio_chip *chip, unsigned offset) EXPORT_SYMBOL_GPL(gpiochip_generic_request); /** + * gpiochip_generic_request_consumer() - request the gpio function for a pin + * @chip: the gpiochip owning the GPIO + * @offset: the offset of the GPIO to request for GPIO function + * @consumer: name of the device requesting the GPIO + */ +int gpiochip_generic_request_consumer(struct gpio_chip *chip, unsigned offset, + const char *consumer) +{ + return pinctrl_gpio_request_consumer(chip->gpiodev->base + offset, + consumer); +} +EXPORT_SYMBOL_GPL(gpiochip_generic_request_consumer); + +/** * gpiochip_generic_free() - free the gpio function from a pin * @chip: the gpiochip to request the gpio function for * @offset: the offset of the GPIO to free from GPIO function @@ -2119,7 +2133,8 @@ EXPORT_SYMBOL_GPL(gpiochip_remove_pin_ranges); * on each other, and help provide better diagnostics in debugfs. * They're called even less than the "set direction" calls. */ -static int gpiod_request_commit(struct gpio_desc *desc, const char *label) +static int gpiod_request_commit(struct gpio_desc *desc, const char *label, + const char *consumer) { struct gpio_chip *chip = desc->gdev->chip; int status; @@ -2139,10 +2154,14 @@ static int gpiod_request_commit(struct gpio_desc *desc, const char *label) goto done; } - if (chip->request) { + if (chip->request || chip->request_consumer) { /* chip->request may sleep */ spin_unlock_irqrestore(&gpio_lock, flags); - status = chip->request(chip, gpio_chip_hwgpio(desc)); + if (chip->request_consumer) + status = chip->request_consumer(chip, + gpio_chip_hwgpio(desc), consumer); + else + status = chip->request(chip, gpio_chip_hwgpio(desc)); spin_lock_irqsave(&gpio_lock, flags); if (status < 0) { @@ -2200,7 +2219,8 @@ static int validate_desc(const struct gpio_desc *desc, const char *func) return; \ } while (0) -int gpiod_request(struct gpio_desc *desc, const char *label) +int gpiod_request_consumer(struct gpio_desc *desc, const char *label, + const char *consumer) { int status = -EPROBE_DEFER; struct gpio_device *gdev; @@ -2209,7 +2229,7 @@ int gpiod_request(struct gpio_desc *desc, const char *label) gdev = desc->gdev; if (try_module_get(gdev->owner)) { - status = gpiod_request_commit(desc, label); + status = gpiod_request_commit(desc, label, consumer); if (status < 0) module_put(gdev->owner); else @@ -2222,6 +2242,11 @@ int gpiod_request(struct gpio_desc *desc, const char *label) return status; } +int gpiod_request(struct gpio_desc *desc, const char *label) +{ + return gpiod_request_consumer(desc, label, NULL); +} + static bool gpiod_free_commit(struct gpio_desc *desc) { bool ret = false; @@ -2320,7 +2345,7 @@ struct gpio_desc *gpiochip_request_own_desc(struct gpio_chip *chip, u16 hwnum, return desc; } - err = gpiod_request_commit(desc, label); + err = gpiod_request_commit(desc, label, NULL); if (err < 0) return ERR_PTR(err); @@ -3672,7 +3697,8 @@ struct gpio_desc *__must_check gpiod_get_index(struct device *dev, } /* If a connection label was passed use that, else use the device name as label */ - status = gpiod_request(desc, con_id ? con_id : dev_name(dev)); + status = gpiod_request_consumer(desc, con_id ? con_id : dev_name(dev), + dev_name(dev)); if (status < 0) return ERR_PTR(status); diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h index 1ba9a331ec51..6bc5c57f0cbd 100644 --- a/include/linux/gpio/driver.h +++ b/include/linux/gpio/driver.h @@ -228,6 +228,9 @@ struct gpio_chip { int (*request)(struct gpio_chip *chip, unsigned offset); + int (*request_consumer)(struct gpio_chip *chip, + unsigned offset, + const char *consumer); void (*free)(struct gpio_chip *chip, unsigned offset); int (*get_direction)(struct gpio_chip *chip, @@ -500,6 +503,8 @@ static inline int gpiochip_irqchip_add_nested(struct gpio_chip *gpiochip, #endif /* CONFIG_GPIOLIB_IRQCHIP */ int gpiochip_generic_request(struct gpio_chip *chip, unsigned offset); +int gpiochip_generic_request_consumer(struct gpio_chip *chip, unsigned offset, + const char *consumer); void gpiochip_generic_free(struct gpio_chip *chip, unsigned offset); int gpiochip_generic_config(struct gpio_chip *chip, unsigned offset, unsigned long config);