From patchwork Sat Oct 11 17:45:16 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Ignatov X-Patchwork-Id: 398887 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 8C5B11400EA for ; Sun, 12 Oct 2014 04:46:28 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751880AbaJKRq1 (ORCPT ); Sat, 11 Oct 2014 13:46:27 -0400 Received: from mail-la0-f50.google.com ([209.85.215.50]:46431 "EHLO mail-la0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752677AbaJKRq1 (ORCPT ); Sat, 11 Oct 2014 13:46:27 -0400 Received: by mail-la0-f50.google.com with SMTP id s18so4939864lam.9 for ; Sat, 11 Oct 2014 10:46:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=RnLlvRhdNZnAAcSey1ym+XvRkdhOlrrbaO5bb6MO9Lg=; b=SAmvkbQA8v1d091Z7NB+0Y07yuckSa9EfGoERVNPGplMlKCSQQSBka4ahI7lFaXpNX Y8NAadvaZD23c5wvSzHKQkp6WskvOwegPmOtZ/jsLERR2pxTcgXPIct0FMR73OXnlgFw GEH/HjcVXYjyjW2gMYbHDp++RvB7lNXmu0Q5dpiKEud7kjZIwhCqW703/R6pq20hoLSg E34ILZiCKLka2XMBZoaD4GqjW6pRi5auxBjhkvm5KxnTTb9GKQqsnErVNZ2EApnnbD/U cwV5wpC7ZB8N8dsz14iPeDMqN0wwvQI5308OPI+20fJ6LmTuymNicVyzznehGEws5NEu K2IA== X-Received: by 10.152.205.38 with SMTP id ld6mr3695678lac.97.1413049585608; Sat, 11 Oct 2014 10:46:25 -0700 (PDT) Received: from nyapad (37-146-217-42.broadband.corbina.ru. [37.146.217.42]) by mx.google.com with ESMTPSA id je9sm2907205lac.6.2014.10.11.10.46.23 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 11 Oct 2014 10:46:24 -0700 (PDT) Received: by nyapad (sSMTP sendmail emulation); Sat, 11 Oct 2014 21:45:52 +0400 From: Alexey Ignatov To: linux-gpio@vger.kernel.org Cc: Alexey Ignatov Subject: [PATCH] gpiolib: allow exporting gpios with custom names Date: Sat, 11 Oct 2014 21:45:16 +0400 Message-Id: <1413049516-27021-1-git-send-email-lexszero@gmail.com> X-Mailer: git-send-email 1.8.5.3 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org This allows exporting gpio pins to sysfs with custom names. Before this patch only gpiochip-supplied names was used, or generic gpio%d. Added gpiod_export_name() and gpio_export_name() functions. gpio_request_one() now uses new behaviour with 'label' as gpio name. Signed-off-by: Alexey Ignatov --- drivers/gpio/gpiolib-sysfs.c | 16 +++++++++++++++- drivers/gpio/gpiolib.h | 1 + include/asm-generic/gpio.h | 6 ++++++ include/linux/gpio/consumer.h | 2 ++ 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c index 5f2150b..7c56a50 100644 --- a/drivers/gpio/gpiolib-sysfs.c +++ b/drivers/gpio/gpiolib-sysfs.c @@ -561,7 +561,9 @@ int gpiod_export(struct gpio_desc *desc, bool direction_may_change) spin_unlock_irqrestore(&gpio_lock, flags); offset = gpio_chip_hwgpio(desc); - if (desc->chip->names && desc->chip->names[offset]) + if (desc->ioname) + ioname = desc->ioname; + else if (desc->chip->names && desc->chip->names[offset]) ioname = desc->chip->names[offset]; dev = device_create(&gpio_class, desc->chip->dev, MKDEV(0, 0), @@ -602,6 +604,18 @@ fail_unlock: } EXPORT_SYMBOL_GPL(gpiod_export); +int gpiod_export_name(struct gpio_desc *desc, bool direction_may_change, + const char *name) +{ + if (!desc) { + pr_debug("%s: invalid gpio descriptor\n", __func__); + return -EINVAL; + } + desc->ioname = name; + return gpiod_export(desc, direction_may_change); +} +EXPORT_SYMBOL_GPL(gpiod_export_name); + static int match_export(struct device *dev, const void *data) { return dev_get_drvdata(dev) == data; diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h index 9db2b6a..9df4bcf 100644 --- a/drivers/gpio/gpiolib.h +++ b/drivers/gpio/gpiolib.h @@ -64,6 +64,7 @@ extern struct list_head gpio_chips; struct gpio_desc { struct gpio_chip *chip; + const char *ioname; unsigned long flags; /* flag symbols are bit numbers */ #define FLAG_REQUESTED 0 diff --git a/include/asm-generic/gpio.h b/include/asm-generic/gpio.h index c1d4105..7957b22 100644 --- a/include/asm-generic/gpio.h +++ b/include/asm-generic/gpio.h @@ -123,6 +123,12 @@ static inline int gpio_export(unsigned gpio, bool direction_may_change) return gpiod_export(gpio_to_desc(gpio), direction_may_change); } +static inline int gpio_export_name(unsigned gpio, bool direction_may_change, + const char *name) +{ + return gpiod_export_name(gpio_to_desc(gpio), direction_may_change, name); +} + static inline int gpio_export_link(struct device *dev, const char *name, unsigned gpio) { diff --git a/include/linux/gpio/consumer.h b/include/linux/gpio/consumer.h index 12f146f..2f4c129 100644 --- a/include/linux/gpio/consumer.h +++ b/include/linux/gpio/consumer.h @@ -324,6 +324,8 @@ static inline int desc_to_gpio(const struct gpio_desc *desc) #if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_GPIO_SYSFS) int gpiod_export(struct gpio_desc *desc, bool direction_may_change); +int gpiod_export_name(struct gpio_desc *desc, bool direction_may_change, + const char *name); int gpiod_export_link(struct device *dev, const char *name, struct gpio_desc *desc); int gpiod_sysfs_set_active_low(struct gpio_desc *desc, int value);