Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp5965423ybv; Tue, 18 Feb 2020 07:19:11 -0800 (PST) X-Google-Smtp-Source: APXvYqzWGzxpEgueC2FasZPZYGkbxxMaJiY/vnTcSew6T4+l9JuP2WPXtDu8xBenyV628PRN/mUl X-Received: by 2002:aca:a810:: with SMTP id r16mr1521692oie.116.1582039151527; Tue, 18 Feb 2020 07:19:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582039151; cv=none; d=google.com; s=arc-20160816; b=0zZU4I8tHN8upvgxAXwv/9HUNG4fqgYFsoI3OK5587ADun+OZS5IgE0S2BQmWtqobp a4n4OFYDOhZt22QUj/3yROQX4wjDAFTJCRAo2/Cg+wqtalRlsEWp0Mgmz21uW7eat0/1 a76HWN39Z2ekx77CKhRbjRedFxIU/7lBqwuJaNkOpvHrU2Td0p896zsNjk+YDpX5CaYV asKellIFXmWcaxxS71sdVJqmINns5CxktOfqE5PRGhw5AzapjjHO1KAlLWy0Ps8kKsL+ wqVxP9uWt8ZzjKFHx+/YKOy03PCs9hq3oexmDdRwVexUKoYKLWoR7xlkN8sz1Bvrv6tf 11HQ== 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=SoLpsb+tqUmKw1pK9A9NmyzlxEPOXl77qiDlG9eNArg=; b=DF0cotvtozDWbz8n9gj6t4Pevsy6RIAyOCghCia+Y2OocfupAXbfNJeV/Wt4vC1EGS 8XiyIscEiVeG6MwmBw2/UmtL1DrOJjXPqMKLve4j0ZP0WpWZtTtpTOr3yF/lioqmDX5A 0B4LnnlyVmsE4c1itNfugOpaONWkfn7UVRYuAclRhmE8Djin+0kfspZVuMiKPc37AhNT 76k/ITM9HGU7Cht9C+t0yFjE/MnhxPD8JQMf6OL3+59Lj1dOqb7WLct4gL8dD27p+9P7 ranmLTILWdoplHQ+DQ104B1moFVgx3cc5wluAEvALEffK7arfjVxjDSlIq57PckAGWAw 6b+w== 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 k6si1825052otn.172.2020.02.18.07.18.59; Tue, 18 Feb 2020 07:19:11 -0800 (PST) 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 S1727462AbgBRPSn (ORCPT + 99 others); Tue, 18 Feb 2020 10:18:43 -0500 Received: from albert.telenet-ops.be ([195.130.137.90]:50688 "EHLO albert.telenet-ops.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727036AbgBRPS3 (ORCPT ); Tue, 18 Feb 2020 10:18:29 -0500 Received: from ramsan ([84.195.182.253]) by albert.telenet-ops.be with bizsmtp id 4FJD2200d5USYZQ06FJEkV; Tue, 18 Feb 2020 16:18:26 +0100 Received: from rox.of.borg ([192.168.97.57]) by ramsan with esmtp (Exim 4.90_1) (envelope-from ) id 1j44dZ-0006yL-TP; Tue, 18 Feb 2020 16:18:13 +0100 Received: from geert by rox.of.borg with local (Exim 4.90_1) (envelope-from ) id 1j44dZ-000235-Rm; Tue, 18 Feb 2020 16:18:13 +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 v5 4/5] docs: gpio: Add GPIO Aggregator documentation Date: Tue, 18 Feb 2020 16:18:11 +0100 Message-Id: <20200218151812.7816-5-geert+renesas@glider.be> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200218151812.7816-1-geert+renesas@glider.be> References: <20200218151812.7816-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 --- 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 | 102 ++++++++++++++++++ Documentation/admin-guide/gpio/index.rst | 1 + 2 files changed, 103 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..114f72be33c2571e --- /dev/null +++ b/Documentation/admin-guide/gpio/gpio-aggregator.rst @@ -0,0 +1,102 @@ +.. SPDX-License-Identifier: GPL-2.0-only + +GPIO Aggregator +=============== + +The GPIO Aggregator allows 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 allows access control for individual 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 or name, 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 + 19 of "e6052000.gpio" and GPIOs 20-21 of "gpiochip2" into a new + gpio_chip: + + .. code-block:: bash + + echo 'e6052000.gpio 19 gpiochip2 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 "gpio-aggregator.0": + + .. code-block:: bash + + 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 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:: bash + + echo gpio-aggregator > /sys/bus/platform/devices/door/driver_override + echo door > /sys/bus/platform/drivers/gpio-aggregator/bind 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