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: 923956 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="ce9qb4kg"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 40y2324BFNz9ry1 for ; Fri, 1 Jun 2018 21:21:34 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751495AbeFALVd (ORCPT ); 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-Google-Smtp-Source: ADUXVKI9E8O93quDPdhWRVK1FaW2XrNfE2UWugGSb+nItv0c9tffYdqvLc7FC7J/aTrtqyxu3hl0Tw== 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(+) 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);