Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp4874742ybb; Tue, 24 Mar 2020 06:57:47 -0700 (PDT) X-Google-Smtp-Source: ADFU+vunWv38cK/7dSgAyKGmeNfuVhYRi7/zAj+lJmy7RSrNyFhrvoDlo35IHk/m+HICdNkirBRu X-Received: by 2002:a9d:6b98:: with SMTP id b24mr6364146otq.242.1585058266902; Tue, 24 Mar 2020 06:57:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585058266; cv=none; d=google.com; s=arc-20160816; b=XlS41bbHZqYSH6DC0VhlRqop/fZyM4yquvdkwc2MRQtcn7SSR6RRXP+K7xX7vj3IbD fk/SHOy8bwBfk9Z5mNUjqsZRhLrMAsm9vItFYtWgbDXtRzw2Wn2bh3oVVZRghsrykAmF 1idJ5FqTX8dU2EpzwpUk3GSExqEeKWysdJPY4RjMGUeB/i113jwHBG77vSbuiyRThsDV 3ifKqVWVrrdTNyKHb+J24USH+4I/biUhnCAyIO4x2nfQF1pAXwEISZd45o/JfrU5HqRE GF2dwwVkseHNf7TDVkQXlTJ8hCDM/rIqHkUQA5EKVp281dvEf+bpxRFrl6ASc8ydJvjc tMKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=sB5ottOtz1Z2icbn7R7mGCZPjnak1/EyEBA+BX0F03o=; b=RAlPl6AARs3B+jsgqKFx7BbrRvpBCostlpSNZ34vgfsVRjNx6npNKjkuBocI1a7KcP zQOqk/raK3cVONybq2792BDgJNDC0apkDtjJYzJTXkzVQ5uhfOmdcCbg8APHX069huXP AtC8ZZTinQAWbZrnZX6eeJ38H99DZQ93aoE39DjCwCIRBxICyXWER164rRQjiV+rT4MY x6pep47UXdzOVCzCw/vdgFLprnyqzgrgcstx9vUxc+jiB5di19aCXss1QyOzzmp6I/Av XOzeIdMKAsAMvCvxSomCTtZ6iCAT5cON5UWEN+q1XxlMJP+9fKiRpCVrFd053OGYZeyb H8Ng== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f63si8753634oib.85.2020.03.24.06.57.33; Tue, 24 Mar 2020 06:57:46 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727931AbgCXN5K (ORCPT + 99 others); Tue, 24 Mar 2020 09:57:10 -0400 Received: from albert.telenet-ops.be ([195.130.137.90]:55886 "EHLO albert.telenet-ops.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727379AbgCXN5J (ORCPT ); Tue, 24 Mar 2020 09:57:09 -0400 Received: from ramsan ([84.195.182.253]) by albert.telenet-ops.be with bizsmtp id JDwu2200T5USYZQ06DwuaB; Tue, 24 Mar 2020 14:57:06 +0100 Received: from rox.of.borg ([192.168.97.57]) by ramsan with esmtp (Exim 4.90_1) (envelope-from ) id 1jGk34-0006Ot-OI; Tue, 24 Mar 2020 14:56:54 +0100 Received: from geert by rox.of.borg with local (Exim 4.90_1) (envelope-from ) id 1jGk34-0001ko-MP; Tue, 24 Mar 2020 14:56:54 +0100 From: Geert Uytterhoeven To: Linus Walleij , Bartosz Golaszewski , Jonathan Corbet , Harish Jenny K N , Eugeniu Rosca Cc: Alexander Graf , Peter Maydell , Paolo Bonzini , Phil Reid , Marc Zyngier , Christoffer Dall , Magnus Damm , Rob Herring , Mark Rutland , linux-gpio@vger.kernel.org, linux-doc@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org, qemu-devel@nongnu.org, Geert Uytterhoeven Subject: [PATCH v6 7/8] docs: gpio: Add GPIO Aggregator documentation Date: Tue, 24 Mar 2020 14:56:52 +0100 Message-Id: <20200324135653.6676-7-geert+renesas@glider.be> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200324135653.6676-1-geert+renesas@glider.be> References: <20200324135328.5796-1-geert+renesas@glider.be> <20200324135653.6676-1-geert+renesas@glider.be> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Document the GPIO Aggregator, and the two typical use-cases. Signed-off-by: Geert Uytterhoeven Reviewed-by: Ulrich Hecht Reviewed-by: Eugeniu Rosca Tested-by: Eugeniu Rosca --- v6: - Fix "allows" without object: -> provides a mechanism to aggregate GPIOs, -> provides access control for a set of one or more GPIOs, -> allows the user to communicate, - Drop "gpiochipN" support, - Extend example, v5: - Add Reviewed-by, Tested-by, - Fix inconsistent indentation, v4: - Add Reviewed-by, - Drop controversial GPIO repeater, - Clarify industrial control use case, - Fix typo s/communicated/communicate/, - Replace abstract frobnicator example by concrete door example with gpio-line-names, v3: - New. --- .../admin-guide/gpio/gpio-aggregator.rst | 111 ++++++++++++++++++ Documentation/admin-guide/gpio/index.rst | 1 + 2 files changed, 112 insertions(+) create mode 100644 Documentation/admin-guide/gpio/gpio-aggregator.rst diff --git a/Documentation/admin-guide/gpio/gpio-aggregator.rst b/Documentation/admin-guide/gpio/gpio-aggregator.rst new file mode 100644 index 0000000000000000..5cd1e7221756504c --- /dev/null +++ b/Documentation/admin-guide/gpio/gpio-aggregator.rst @@ -0,0 +1,111 @@ +.. SPDX-License-Identifier: GPL-2.0-only + +GPIO Aggregator +=============== + +The GPIO Aggregator provides a mechanism to aggregate GPIOs, and expose them as +a new gpio_chip. This supports the following use cases. + + +Aggregating GPIOs using Sysfs +----------------------------- + +GPIO controllers are exported to userspace using /dev/gpiochip* character +devices. Access control to these devices is provided by standard UNIX file +system permissions, on an all-or-nothing basis: either a GPIO controller is +accessible for a user, or it is not. + +The GPIO Aggregator provides access control for a set of one or more GPIOs, by +aggregating them into a new gpio_chip, which can be assigned to a group or user +using standard UNIX file ownership and permissions. Furthermore, this +simplifies and hardens exporting GPIOs to a virtual machine, as the VM can just +grab the full GPIO controller, and no longer needs to care about which GPIOs to +grab and which not, reducing the attack surface. + +Aggregated GPIO controllers are instantiated and destroyed by writing to +write-only attribute files in sysfs. + + /sys/bus/platform/drivers/gpio-aggregator/ + + "new_device" ... + Userspace may ask the kernel to instantiate an aggregated GPIO + controller by writing a string describing the GPIOs to + aggregate to the "new_device" file, using the format + + .. code-block:: none + + [] [ ] ... + + Where: + + "" ... + is a GPIO line name, + + "" ... + is a GPIO chip label, and + + "" ... + is a comma-separated list of GPIO offsets and/or + GPIO offset ranges denoted by dashes. + + Example: Instantiate a new GPIO aggregator by aggregating GPIO + line 19 of "e6052000.gpio" and GPIO lines 20-21 of + "e6050000.gpio" into a new gpio_chip: + + .. code-block:: sh + + $ echo 'e6052000.gpio 19 e6050000.gpio 20-21' > new_device + + "delete_device" ... + Userspace may ask the kernel to destroy an aggregated GPIO + controller after use by writing its device name to the + "delete_device" file. + + Example: Destroy the previously-created aggregated GPIO + controller, assumed to be "gpio-aggregator.0": + + .. code-block:: sh + + $ echo gpio-aggregator.0 > delete_device + + +Generic GPIO Driver +------------------- + +The GPIO Aggregator can also be used as a generic driver for a simple +GPIO-operated device described in DT, without a dedicated in-kernel driver. +This is useful in industrial control, and is not unlike e.g. spidev, which +allows the user to communicate with an SPI device from userspace. + +Binding a device to the GPIO Aggregator is performed either by modifying the +gpio-aggregator driver, or by writing to the "driver_override" file in Sysfs. + +Example: If "door" is a GPIO-operated device described in DT, using its own +compatible value:: + + door { + compatible = "myvendor,mydoor"; + + gpios = <&gpio2 19 GPIO_ACTIVE_HIGH>, + <&gpio2 20 GPIO_ACTIVE_LOW>; + gpio-line-names = "open", "lock"; + }; + +it can be bound to the GPIO Aggregator by either: + +1. Adding its compatible value to ``gpio_aggregator_dt_ids[]``, +2. Binding manually using "driver_override": + +.. code-block:: sh + + $ echo gpio-aggregator > /sys/bus/platform/devices/door/driver_override + $ echo door > /sys/bus/platform/drivers/gpio-aggregator/bind + +After that, a new gpiochip "door" has been created: + +.. code-block:: sh + + $ gpioinfo door + gpiochip12 - 2 lines: + line 0: "open" unused input active-high + line 1: "lock" unused input active-high diff --git a/Documentation/admin-guide/gpio/index.rst b/Documentation/admin-guide/gpio/index.rst index a244ba4e87d5398a..ef2838638e967777 100644 --- a/Documentation/admin-guide/gpio/index.rst +++ b/Documentation/admin-guide/gpio/index.rst @@ -7,6 +7,7 @@ gpio .. toctree:: :maxdepth: 1 + gpio-aggregator sysfs .. only:: subproject and html -- 2.17.1