From patchwork Fri Jun 1 11:21:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 137506 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp801627lji; Fri, 1 Jun 2018 04:21:34 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJ6sNScFZWiV7l6pOF47U2BREsZZhcbDkgUV9xK3VVzXATafsIyyFrNOMa12tIvwbJBdIVD X-Received: by 2002:a65:4b49:: with SMTP id k9-v6mr8429538pgt.369.1527852094363; Fri, 01 Jun 2018 04:21:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527852094; cv=none; d=google.com; s=arc-20160816; b=JKEd0G5RHPKms6VwFn5Q2K4bchN8WCEbG+Vka2Oa+ZHvwk6E8zqve8kZ93XPodsAor ZIXkf9XoAfB8LqyjvTYGjiVwouaQsBnQVcudFlu/IwUUZjMvMieWtTkuJhBxAtukNHg7 TOhoH/NPQWiHo4pNYUM3ycD+TSkoJ0Vk8LN2tepKK2XXH3y86XezV0F1wtPGufdWDjDQ c3/DHqTwm1exAbvhBvOSZnvy8A4uAzLylp9FHQ+HbJWW/iJ6z/SjSl5FV5tCgiXm4s0U FSREiTfuGhgXE1fxdondjA0L96WGq+3FK6731UKYOaFGidq/xAWeXgz5Ib5gUxX0M7rX 9BWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=KRGnMEXJJgwHzM/GLiF5Mk5jHUXQctIfIYr8vnfu434=; b=vD4gORsoBd9eCqEUAVahcFixtFgsEmQIwevgq8JWnOWHwU5ZoA1vYlg0sQl4cgngKo hPw2P3xzdDxYRxjICyXbhjylvUIoNPOeGG+2GWfdRNt+ujmd0cVPed38C9lUvjfJjULZ gK7OKGRFfxarzZVH7RTK7eebzLbZzQCk6npTk1XDWxOYr4ou32XBg11GRs80TE5xp8lJ sgCADwckqdbb/JaI9gllvzhD6NgicfBFsBCbcseV1QQdChcy7KVmUvcXX8/1m6PNwXKO O8NG3IHxCKAN/gSdJuNKlsapzk7VHCCo3mOXoMnu8sKh3y9+mb9JirB3fVWkIaeft/SS Y0lw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=ce9qb4kg; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f5-v6si15529398pln.414.2018.06.01.04.21.34; Fri, 01 Jun 2018 04:21:34 -0700 (PDT) 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; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=ce9qb4kg; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751495AbeFALVd (ORCPT + 5 others); Fri, 1 Jun 2018 07:21:33 -0400 Received: from mail-lf0-f66.google.com ([209.85.215.66]:32999 "EHLO mail-lf0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751687AbeFALVd (ORCPT ); Fri, 1 Jun 2018 07:21:33 -0400 Received: by mail-lf0-f66.google.com with SMTP id y20-v6so14298884lfy.0 for ; Fri, 01 Jun 2018 04:21:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=bvSdO1AgWgU+WEKTfP+mD2NhPt4t8sdBq+tS4nHJnkk=; b=ce9qb4kgEnf+7oLAc9kyrjEhYDpt6bpGfk+2tuAcgncd9fomymJxl3/PMeuzS5eHGl 2BKJ1B5t1tJ4WADhyBrbr0IzFiGzp1/FceuUpV6KOmchc4mRpkXMFXz2dFo7rdljYMM+ h1muJinMlQKEHqOJMDuwYgunZ/X+oBhKfjtFk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=bvSdO1AgWgU+WEKTfP+mD2NhPt4t8sdBq+tS4nHJnkk=; b=uWArsAExByo6ohgbML6rbGRueH9lr7Qvc9Caf8rI3zAMatmaOxGOzumf9KHdCPco8i hQaiVjc7mJSlaI8jIX9OQgN5ZxtQdJo1sVYxBX+RR/R7C/LmbhhR6HLP4Ia2s15cqdRB COLtSl6lAj9C5bB475WXuJKdNMlLrkqF9m4YfNKRTGA6Uo/EuodLKhYWRO0Kv9KJZHYh mSaVzfNihxkjEhNzuW2Jl0sVP9LS0AYoyI+U6TDF5G+itl4BstU19GwZgGVfS/czxsDX 8ydJAMMgM3BGyA1l5zP5gcdrLA0PdFC0zBwRn5H3wqZ01VvpPqB5Tpe2U3F3dFvBQm6s mM8Q== X-Gm-Message-State: ALKqPwdk/l4PtXOzct6S9JEmfnN27p6ALJIFB5DmSenNEIpqx/z8uzE7 psgGa75kbsW1aUDKxkP1t7ndkw8Vsk0= X-Received: by 2002:a2e:128d:: with SMTP id 13-v6mr8132990ljs.102.1527852091430; Fri, 01 Jun 2018 04:21:31 -0700 (PDT) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id g22-v6sm168115lfh.38.2018.06.01.04.21.29 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Jun 2018 04:21:30 -0700 (PDT) From: Linus Walleij To: linux-gpio@vger.kernel.org Cc: Linus Walleij Subject: [PATCH] gpio: Add API to explicitly name a consumer Date: Fri, 1 Jun 2018 13:21:27 +0200 Message-Id: <20180601112127.3110-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.17.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org The GPIO (descriptor) API registers a "label" naming what is currently using the GPIO line. Typically this is taken from things like the device tree node, so "reset-gpios" will result in he line being labeled "reset". The technical effect is pretty much zero: the use is for debug and introspection, such as "lsgpio" and debugfs files. However sometimes the user want this cuddly feeling of listing all GPIO lines and seeing exactly what they are for and it gives a very fulfilling sense of control. Especially in the cases when the device tree node doesn't provide a good name, or anonymous GPIO lines assigned just to "gpios" in the device tree because the usage is implicit. For these cases it may be nice to be able to label the line directly and explicitly. Signed-off-by: Linus Walleij --- drivers/gpio/gpiolib.c | 13 +++++++++++++ include/linux/gpio/consumer.h | 7 +++++++ 2 files changed, 20 insertions(+) -- 2.17.0 -- 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 d8ccb500872f..1f664c55387e 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -3101,6 +3101,19 @@ int gpiod_cansleep(const struct gpio_desc *desc) } EXPORT_SYMBOL_GPL(gpiod_cansleep); +/** + * gpiod_set_consumer_name() - set the consumer name for the descriptor + * @desc: gpio to set the consumer name on + * @name: the new consumer name + */ +void gpiod_set_consumer_name(struct gpio_desc *desc, const char *name) +{ + VALIDATE_DESC_VOID(desc); + /* Just overwrite whatever the previous name was */ + desc->label = name; +} +EXPORT_SYMBOL_GPL(gpiod_set_consumer_name); + /** * gpiod_to_irq() - return the IRQ corresponding to a GPIO * @desc: gpio whose IRQ will be returned (already requested) diff --git a/include/linux/gpio/consumer.h b/include/linux/gpio/consumer.h index dbd065963296..7b97a045b794 100644 --- a/include/linux/gpio/consumer.h +++ b/include/linux/gpio/consumer.h @@ -145,6 +145,7 @@ int gpiod_is_active_low(const struct gpio_desc *desc); int gpiod_cansleep(const struct gpio_desc *desc); int gpiod_to_irq(const struct gpio_desc *desc); +void gpiod_set_consumer_name(struct gpio_desc *desc, const char *name); /* Convert between the old gpio_ and new gpiod_ interfaces */ struct gpio_desc *gpio_to_desc(unsigned gpio); @@ -465,6 +466,12 @@ static inline int gpiod_to_irq(const struct gpio_desc *desc) return -EINVAL; } +static inline void gpiod_set_consumer_name(struct gpio_desc *desc, const char *name) +{ + /* GPIO can never have been requested */ + WARN_ON(1); +} + static inline struct gpio_desc *gpio_to_desc(unsigned gpio) { return ERR_PTR(-EINVAL);