From patchwork Tue Apr 19 13:39:17 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 66097 Delivered-To: patch@linaro.org Received: by 10.140.93.198 with SMTP id d64csp1857087qge; Tue, 19 Apr 2016 06:39:35 -0700 (PDT) X-Received: by 10.98.36.130 with SMTP id k2mr4137929pfk.128.1461073175539; Tue, 19 Apr 2016 06:39:35 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id zp15si12163686pab.241.2016.04.19.06.39.35; Tue, 19 Apr 2016 06:39:35 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of devicetree-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; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754464AbcDSNjc (ORCPT + 7 others); Tue, 19 Apr 2016 09:39:32 -0400 Received: from mail-lf0-f43.google.com ([209.85.215.43]:36321 "EHLO mail-lf0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754439AbcDSNja (ORCPT ); Tue, 19 Apr 2016 09:39:30 -0400 Received: by mail-lf0-f43.google.com with SMTP id g184so19178623lfb.3 for ; Tue, 19 Apr 2016 06:39:29 -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=4Ax4jdu6CsAz/qvhl1RBdQ/g92iOgS3byr02HsEHa7s=; b=k3Z+oooEDjuljyEO9/J1f2i5HgArGefo59tzqwkI7cYmexnDCDCkzJKALy/pnMkY5V A3KhFcxNi1KuIW+jUf2xBb4nMfLtJm9zCNhKFRgRWyo964kQ5jGv21q0hnKDLzNvM4G2 tSIe+pDZshqttmzqzaL31CzCDuB4odhSzHH+I= 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=4Ax4jdu6CsAz/qvhl1RBdQ/g92iOgS3byr02HsEHa7s=; b=a0ktRB7acbS3HK+f82gB3h8b1V+eWIO3Hwl0/+XmfKt34tU2dQ0nxNFpBk9Z21q7Tb Iw1W5w9DsfRsExV3CcPSd4fGmsJUtKNTQl0Z+CL824bK6HkU7xIrWwBHQi8+TP+Dy930 lBTgLypflcKXY5vZSnPH+bpub3zbyMghWc/nwYdHXdzP81SGgOkZIUMBVkkGnSp6rXWM vCU3hFXddWBXUNBJCFUFbvCsc3p9+hJ7HZjdWlme1pIOuukaxvlSGX93o1elN5KvCzlM dGroxb0t+9tB6mZORgikIgNL1hcF4za5EAaQmvKJhYGT7SSvtx0Dncqyzoo9LV7eOiaW MCMQ== X-Gm-Message-State: AOPr4FUH1B3Iovybf/wYHx+h5508D/c2q42yl70aLJN6syWwG22zB0fwfxg9B4Tavll4WYrd X-Received: by 10.25.161.75 with SMTP id k72mr1469778lfe.86.1461073168779; Tue, 19 Apr 2016 06:39:28 -0700 (PDT) Received: from localhost.localdomain ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id z21sm80976lff.0.2016.04.19.06.39.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Apr 2016 06:39:27 -0700 (PDT) From: Linus Walleij To: linux-gpio@vger.kernel.org, Alexandre Courbot , Johan Hovold , Michael Welling , Markus Pargmann , Arnd Bergmann Cc: Bamvor Jian Zhang , Grant Likely , Linus Walleij , Rob Herring , devicetree@vger.kernel.org Subject: [PATCH] gpio: of: make it possible to name GPIO lines Date: Tue, 19 Apr 2016 15:39:17 +0200 Message-Id: <1461073157-26574-1-git-send-email-linus.walleij@linaro.org> X-Mailer: git-send-email 2.4.11 Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Make it possible to name the producer side of a GPIO line using a "gpio-names" property array, modeled on the "clock-names" property from the clock bindings. This naming is especially useful for: - Debugging: lines are named after function, not just opaque offset numbers. - Exploration: systems where some or all GPIO lines are available to end users, such as prototyping, one-off's "makerspace usecases" users are helped by the names of the GPIO lines when tinkering. This usecase has been surfacing recently. The gpio-names attribute is completely optional. Cc: Rob Herring Cc: Grant Likely Cc: devicetree@vger.kernel.org Signed-off-by: Linus Walleij --- This has been discussed at some length now. Why we are not using hogs: these are consumer side, not producer side. The gpio-controller in DT (gpio_chip in Linux) is a producer, not a consumer. This patch is not about assigning initial values to GPIO lines. That is an orthogonal usecase. This is just about naming lines. --- Documentation/devicetree/bindings/gpio/gpio.txt | 19 +++++++++++ drivers/gpio/gpiolib-of.c | 43 +++++++++++++++++++++++++ 2 files changed, 62 insertions(+) -- 2.4.11 -- To unsubscribe from this list: send the line "unsubscribe devicetree" 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/Documentation/devicetree/bindings/gpio/gpio.txt b/Documentation/devicetree/bindings/gpio/gpio.txt index c88d2ccb05ca..6b371ab6098e 100644 --- a/Documentation/devicetree/bindings/gpio/gpio.txt +++ b/Documentation/devicetree/bindings/gpio/gpio.txt @@ -152,6 +152,21 @@ additional bitmask is needed to specify which GPIOs are actually in use, and which are dummies. The bindings for this case has not yet been specified, but should be specified if/when such hardware appears. +Optionally, a GPIO controller may have a "gpio-names" property. This is +an array of strings defining the names of the GPIO lines going out of the +GPIO controller. This name should be the most meaningful producer name +for the system, such as a rail name indicating the usage. Package names +such as pin name are discouraged: such lines have opaque names (since they +are by definition generic purpose) and such names are usually not very +helpful. For example "MMC-CD", "Red LED Vdd" and "ethernet reset" are +reasonable line names as they describe what the line is used for. "GPIO0" +is not a good name to give to a GPIO line. Placeholders are discouraged: +rather use the "" (blank string) if the use of the GPIO line is undefined +in your design. The names are assigned starting from line offset 0 from +left to right from the passed array. An incomplete array (where the number +of passed named are less than ngpios) will still be used up until the last +provided valid line index. + Example: gpio-controller@00000000 { @@ -160,6 +175,10 @@ gpio-controller@00000000 { gpio-controller; #gpio-cells = <2>; ngpios = <18>; + gpio-names = "MMC-CD", "MMC-WP", "VDD eth", "RST eth", "LED R", + "LED G", "LED B", "Col A", "Col B", "Col C", "Col D", + "Row A", "Row B", "Row C", "Row D", "NMI button", + "poweroff", "reset"; } The GPIO chip may contain GPIO hog definitions. GPIO hogging is a mechanism diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c index d81dbd8e90d9..b4e3a42e7aae 100644 --- a/drivers/gpio/gpiolib-of.c +++ b/drivers/gpio/gpiolib-of.c @@ -196,6 +196,42 @@ static struct gpio_desc *of_parse_own_gpio(struct device_node *np, } /** + * of_gpiochip_set_names() - set up the names of the lines + * @chip: GPIO chip whose lines should be named, if possible + */ +static int of_gpiochip_set_names(struct gpio_chip *gc) +{ + struct gpio_device *gdev = gc->gpiodev; + struct device_node *np = gc->of_node; + int i; + int nstrings; + + /* Do we even have the "gpio-names" property */ + if (!of_property_read_bool(np, "gpio-names")) + return 0; + + nstrings = of_property_count_strings(np, "gpio-names"); + for (i = 0; i < nstrings; i++) { + const char *name; + int ret; + + ret = of_property_read_string_index(np, + "gpio-names", + i, + &name); + if (!ret) + gdev->descs[i].name = name; + + /* Empty strings are OK */ + if (ret != -ENODATA) + dev_err(&gdev->dev, "unable to name line %d\n", + i); + } + + return 0; +} + +/** * of_gpiochip_scan_gpios - Scan gpio-controller for gpio definitions * @chip: gpio chip to act on * @@ -445,6 +481,13 @@ int of_gpiochip_add(struct gpio_chip *chip) if (status) return status; + /* If the chip defines names itself, these take precedence */ + if (!chip->names) { + status = of_gpiochip_set_names(chip); + if (status) + return status; + } + of_node_get(chip->of_node); return of_gpiochip_scan_gpios(chip);