Path: blob/master/Documentation/devicetree/bindings/gpio/gpio.txt
26308 views
Specifying GPIO information for devices1=======================================231) gpios property4-----------------56GPIO properties should be named "[<name>-]gpios", with <name> being the purpose7of this GPIO for the device. While a non-existent <name> is considered valid8for compatibility reasons (resolving to the "gpios" property), it is not allowed9for new bindings. Also, GPIO properties named "[<name>-]gpio" are valid and old10bindings use it, but are only supported for compatibility reasons and should not11be used for newer bindings since it has been deprecated.1213GPIO properties can contain one or more GPIO phandles, but only in exceptional14cases should they contain more than one. If your device uses several GPIOs with15distinct functions, reference each of them under its own property, giving it a16meaningful name. The only case where an array of GPIOs is accepted is when17several GPIOs serve the same function (e.g. a parallel data line).1819The exact purpose of each gpios property must be documented in the device tree20binding of the device.2122The following example could be used to describe GPIO pins used as device enable23and bit-banged data signals:2425gpio1: gpio1 {26gpio-controller;27#gpio-cells = <2>;28};29[...]3031data-gpios = <&gpio1 12 0>,32<&gpio1 13 0>,33<&gpio1 14 0>,34<&gpio1 15 0>;3536In the above example, &gpio1 uses 2 cells to specify a gpio. The first cell is37a local offset to the GPIO line and the second cell represent consumer flags,38such as if the consumer desire the line to be active low (inverted) or open39drain. This is the recommended practice.4041The exact meaning of each specifier cell is controller specific, and must be42documented in the device tree binding for the device, but it is strongly43recommended to use the two-cell approach.4445Most controllers are specifying a generic flag bitfield in the last cell, so46for these, use the macros defined in47include/dt-bindings/gpio/gpio.h whenever possible:4849Example of a node using GPIOs:5051node {52enable-gpios = <&qe_pio_e 18 GPIO_ACTIVE_HIGH>;53};5455GPIO_ACTIVE_HIGH is 0, so in this example gpio-specifier is "18 0" and encodes56GPIO pin number, and GPIO flags as accepted by the "qe_pio_e" gpio-controller.5758Optional standard bitfield specifiers for the last cell:5960- Bit 0: 0 means active high, 1 means active low61- Bit 1: 0 mean push-pull wiring, see:62https://en.wikipedia.org/wiki/Push-pull_output631 means single-ended wiring, see:64https://en.wikipedia.org/wiki/Single-ended_triode65- Bit 2: 0 means open-source, 1 means open drain, see:66https://en.wikipedia.org/wiki/Open_collector67- Bit 3: 0 means the output should be maintained during sleep/low-power mode681 means the output state can be lost during sleep/low-power mode69- Bit 4: 0 means no pull-up resistor should be enabled701 means a pull-up resistor should be enabled71This setting only applies to hardware with a simple on/off72control for pull-up configuration. If the hardware has more73elaborate pull-up configuration, it should be represented74using a pin control binding.75- Bit 5: 0 means no pull-down resistor should be enabled761 means a pull-down resistor should be enabled77This setting only applies to hardware with a simple on/off78control for pull-down configuration. If the hardware has more79elaborate pull-down configuration, it should be represented80using a pin control binding.81821.1) GPIO specifier best practices83----------------------------------8485A gpio-specifier should contain a flag indicating the GPIO polarity; active-86high or active-low. If it does, the following best practices should be87followed:8889The gpio-specifier's polarity flag should represent the physical level at the90GPIO controller that achieves (or represents, for inputs) a logically asserted91value at the device. The exact definition of logically asserted should be92defined by the binding for the device. If the board inverts the signal between93the GPIO controller and the device, then the gpio-specifier will represent the94opposite physical level than the signal at the device's pin.9596When the device's signal polarity is configurable, the binding for the97device must either:9899a) Define a single static polarity for the signal, with the expectation that100any software using that binding would statically program the device to use101that signal polarity.102103The static choice of polarity may be either:104105a1) (Preferred) Dictated by a binding-specific DT property.106107or:108109a2) Defined statically by the DT binding itself.110111In particular, the polarity cannot be derived from the gpio-specifier, since112that would prevent the DT from separately representing the two orthogonal113concepts of configurable signal polarity in the device, and possible board-114level signal inversion.115116or:117118b) Pick a single option for device signal polarity, and document this choice119in the binding. The gpio-specifier should represent the polarity of the signal120(at the GPIO controller) assuming that the device is configured for this121particular signal polarity choice. If software chooses to program the device122to generate or receive a signal of the opposite polarity, software will be123responsible for correctly interpreting (inverting) the GPIO signal at the GPIO124controller.1251262) gpio-controller nodes127------------------------128129Every GPIO controller node must contain both an empty "gpio-controller"130property, and a #gpio-cells integer property, which indicates the number of131cells in a gpio-specifier.132133Some system-on-chips (SoCs) use the concept of GPIO banks. A GPIO bank is an134instance of a hardware IP core on a silicon die, usually exposed to the135programmer as a coherent range of I/O addresses. Usually each such bank is136exposed in the device tree as an individual gpio-controller node, reflecting137the fact that the hardware was synthesized by reusing the same IP block a138few times over.139140Optionally, a GPIO controller may have a "ngpios" property. This property141indicates the number of in-use slots of available slots for GPIOs. The142typical example is something like this: the hardware register is 32 bits143wide, but only 18 of the bits have a physical counterpart. The driver is144generally written so that all 32 bits can be used, but the IP block is reused145in a lot of designs, some using all 32 bits, some using 18 and some using14612. In this case, setting "ngpios = <18>;" informs the driver that only the147first 18 GPIOs, at local offset 0 .. 17, are in use.148149If these GPIOs do not happen to be the first N GPIOs at offset 0...N-1, an150additional set of tuples is needed to specify which GPIOs are unusable, with151the gpio-reserved-ranges binding. This property indicates the start and size152of the GPIOs that can't be used.153154Optionally, a GPIO controller may have a "gpio-line-names" property. This is155an array of strings defining the names of the GPIO lines going out of the156GPIO controller.157158For lines which are routed to on-board devices, this name should be159the most meaningful producer name for the system, such as a rail name160indicating the usage. Package names, such as a pin name, are discouraged:161such lines have opaque names (since they are by definition general-purpose)162and such names are usually not very helpful. For example "MMC-CD", "Red LED163Vdd" and "ethernet reset" are reasonable line names as they describe what164the line is used for. "GPIO0" is not a good name to give to a GPIO line165that is hard-wired to a specific device.166167However, in the case of lines that are routed to a general purpose header168(e.g. the Raspberry Pi 40-pin header), and therefore are not hard-wired to169specific devices, using a pin number or the names on the header is fine170provided these are real (preferably unique) names. Using an SoC's pad name171or package name, or names made up from kernel-internal software constructs,172are strongly discouraged. For example "pin8 [gpio14/uart0_txd]" is fine173if the board's documentation labels pin 8 as such. However "PortB_24" (an174example of a name from an SoC's reference manual) would not be desirable.175176In either case placeholders are discouraged: rather use the "" (blank177string) if the use of the GPIO line is undefined in your design. Ideally,178try to add comments to the dts file describing the naming the convention179you have chosen, and specifying from where the names are derived.180181The names are assigned starting from line offset 0, from left to right,182from the passed array. An incomplete array (where the number of passed183names is less than ngpios) will be used up until the last provided valid184line index.185186Example:187188gpio-controller@00000000 {189compatible = "foo";190reg = <0x00000000 0x1000>;191gpio-controller;192#gpio-cells = <2>;193ngpios = <18>;194gpio-reserved-ranges = <0 4>, <12 2>;195gpio-line-names = "MMC-CD", "MMC-WP", "VDD eth", "RST eth", "LED R",196"LED G", "LED B", "Col A", "Col B", "Col C", "Col D",197"Row A", "Row B", "Row C", "Row D", "NMI button",198"poweroff", "reset";199}200201The GPIO chip may contain GPIO hog definitions. GPIO hogging is a mechanism202providing automatic GPIO request and configuration as part of the203gpio-controller's driver probe function.204205Each GPIO hog definition is represented as a child node of the GPIO controller.206Required properties:207- gpio-hog: A property specifying that this child node represents a GPIO hog.208- gpios: Store the GPIO information (id, flags, ...) for each GPIO to209affect. Shall contain an integer multiple of the number of cells210specified in its parent node (GPIO controller node).211Only one of the following properties scanned in the order shown below.212This means that when multiple properties are present they will be searched213in the order presented below and the first match is taken as the intended214configuration.215- input: A property specifying to set the GPIO direction as input.216- output-low A property specifying to set the GPIO direction as output with217the value low.218- output-high A property specifying to set the GPIO direction as output with219the value high.220221Optional properties:222- line-name: The GPIO label name. If not present the node name is used.223224Example of two SOC GPIO banks defined as gpio-controller nodes:225226qe_pio_a: gpio-controller@1400 {227compatible = "fsl,qe-pario-bank-a", "fsl,qe-pario-bank";228reg = <0x1400 0x18>;229gpio-controller;230#gpio-cells = <2>;231232line_b-hog {233gpio-hog;234gpios = <6 0>;235output-low;236line-name = "foo-bar-gpio";237};238};239240qe_pio_e: gpio-controller@1460 {241compatible = "fsl,qe-pario-bank-e", "fsl,qe-pario-bank";242reg = <0x1460 0x18>;243gpio-controller;244#gpio-cells = <2>;245};2462472.1) gpio- and pin-controller interaction248-----------------------------------------249250Some or all of the GPIOs provided by a GPIO controller may be routed to pins251on the package via a pin controller. This allows muxing those pins between252GPIO and other functions. It is a fairly common practice among silicon253engineers.2542552.2) Ordinary (numerical) GPIO ranges256-------------------------------------257258It is useful to represent which GPIOs correspond to which pins on which pin259controllers. The gpio-ranges property described below represents this with260a discrete set of ranges mapping pins from the pin controller local number space261to pins in the GPIO controller local number space.262263The format is: <[pin controller phandle], [GPIO controller offset],264[pin controller offset], [number of pins]>;265266The GPIO controller offset pertains to the GPIO controller node containing the267range definition.268269The pin controller node referenced by the phandle must conform to the bindings270described in pinctrl/pinctrl-bindings.txt.271272Each offset runs from 0 to N. It is perfectly fine to pile any number of273ranges with just one pin-to-GPIO line mapping if the ranges are concocted, but274in practice these ranges are often lumped in discrete sets.275276Example:277278gpio-ranges = <&foo 0 20 10>, <&bar 10 50 20>;279280This means:281- pins 20..29 on pin controller "foo" is mapped to GPIO line 0..9 and282- pins 50..69 on pin controller "bar" is mapped to GPIO line 10..29283284285Verbose example:286287qe_pio_e: gpio-controller@1460 {288#gpio-cells = <2>;289compatible = "fsl,qe-pario-bank-e", "fsl,qe-pario-bank";290reg = <0x1460 0x18>;291gpio-controller;292gpio-ranges = <&pinctrl1 0 20 10>, <&pinctrl2 10 50 20>;293};294295Here, a single GPIO controller has GPIOs 0..9 routed to pin controller296pinctrl1's pins 20..29, and GPIOs 10..29 routed to pin controller pinctrl2's297pins 50..69.2982993002.3) GPIO ranges from named pin groups301--------------------------------------302303It is also possible to use pin groups for gpio ranges when pin groups are the304easiest and most convenient mapping.305306Both both <pinctrl-base> and <count> must set to 0 when using named pin groups307names.308309The property gpio-ranges-group-names must contain exactly one string for each310range.311312Elements of gpio-ranges-group-names must contain the name of a pin group313defined in the respective pin controller. The number of pins/GPIO lines in the314range is the number of pins in that pin group. The number of pins of that315group is defined int the implementation and not in the device tree.316317If numerical and named pin groups are mixed, the string corresponding to a318numerical pin range in gpio-ranges-group-names must be empty.319320Example:321322gpio_pio_i: gpio-controller@14b0 {323#gpio-cells = <2>;324compatible = "fsl,qe-pario-bank-e", "fsl,qe-pario-bank";325reg = <0x1480 0x18>;326gpio-controller;327gpio-ranges = <&pinctrl1 0 20 10>,328<&pinctrl2 10 0 0>,329<&pinctrl1 15 0 10>,330<&pinctrl2 25 0 0>;331gpio-ranges-group-names = "",332"foo",333"",334"bar";335};336337Here, three GPIO ranges are defined referring to two pin controllers.338339pinctrl1 GPIO ranges are defined using pin numbers whereas the GPIO ranges340in pinctrl2 are defined using the pin groups named "foo" and "bar".341342Previous versions of this binding required all pin controller nodes that343were referenced by any gpio-ranges property to contain a property named344#gpio-range-cells with value <3>. This requirement is now deprecated.345However, that property may still exist in older device trees for346compatibility reasons, and would still be required even in new device347trees that need to be compatible with older software.348349350