sphinx.addnodesdocument)}( rawsourcechildren]( translations LanguagesNode)}(hhh](h pending_xref)}(hhh]docutils.nodesTextChinese (Simplified)}parenthsba attributes}(ids]classes]names]dupnames]backrefs] refdomainstdreftypedoc reftarget)/translations/zh_CN/driver-api/gpio/boardmodnameN classnameN refexplicitutagnamehhh ubh)}(hhh]hChinese (Traditional)}hh2sbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget)/translations/zh_TW/driver-api/gpio/boardmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hItalian}hhFsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget)/translations/it_IT/driver-api/gpio/boardmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hJapanese}hhZsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget)/translations/ja_JP/driver-api/gpio/boardmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hKorean}hhnsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget)/translations/ko_KR/driver-api/gpio/boardmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hSpanish}hhsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget)/translations/sp_SP/driver-api/gpio/boardmodnameN classnameN refexplicituh1hhh ubeh}(h]h ]h"]h$]h&]current_languageEnglishuh1h hh _documenthsourceNlineNubhsection)}(hhh](htitle)}(h GPIO Mappingsh]h GPIO Mappings}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhhhC/var/lib/git/docbuild/linux/Documentation/driver-api/gpio/board.rsthKubh paragraph)}(hPThis document explains how GPIOs can be assigned to given devices and functions.h]hPThis document explains how GPIOs can be assigned to given devices and functions.}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhhhhubh)}(hXNAll platforms can enable the GPIO library, but if the platform strictly requires GPIO functionality to be present, it needs to select GPIOLIB from its Kconfig. Then, how GPIOs are mapped depends on what the platform uses to describe its hardware layout. Currently, mappings can be defined through device tree, ACPI, and platform data.h]hXNAll platforms can enable the GPIO library, but if the platform strictly requires GPIO functionality to be present, it needs to select GPIOLIB from its Kconfig. Then, how GPIOs are mapped depends on what the platform uses to describe its hardware layout. Currently, mappings can be defined through device tree, ACPI, and platform data.}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhhhhubh)}(hhh](h)}(h Device Treeh]h Device Tree}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhhhhhKubh)}(hGPIOs can easily be mapped to devices and functions in the device tree. The exact way to do it depends on the GPIO controller providing the GPIOs, see the device tree bindings for your controller.h]hGPIOs can easily be mapped to devices and functions in the device tree. The exact way to do it depends on the GPIO controller providing the GPIOs, see the device tree bindings for your controller.}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhhhhubh)}(hGPIOs mappings are defined in the consumer device's node, in a property named -gpios, where is the function the driver will request through gpiod_get(). For example::h]hGPIOs mappings are defined in the consumer device’s node, in a property named -gpios, where is the function the driver will request through gpiod_get(). For example:}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhhhhubh literal_block)}(hX"foo_device { compatible = "acme,foo"; ... led-gpios = <&gpio 15 GPIO_ACTIVE_HIGH>, /* red */ <&gpio 16 GPIO_ACTIVE_HIGH>, /* green */ <&gpio 17 GPIO_ACTIVE_HIGH>; /* blue */ power-gpios = <&gpio 1 GPIO_ACTIVE_LOW>; };h]hX"foo_device { compatible = "acme,foo"; ... led-gpios = <&gpio 15 GPIO_ACTIVE_HIGH>, /* red */ <&gpio 16 GPIO_ACTIVE_HIGH>, /* green */ <&gpio 17 GPIO_ACTIVE_HIGH>; /* blue */ power-gpios = <&gpio 1 GPIO_ACTIVE_LOW>; };}hjsbah}(h]h ]h"]h$]h&] xml:spacepreserveuh1jhhhKhhhhubh)}(hProperties named -gpio are also considered valid and old bindings use it but are only supported for compatibility reasons and should not be used for newer bindings since it has been deprecated.h]hProperties named -gpio are also considered valid and old bindings use it but are only supported for compatibility reasons and should not be used for newer bindings since it has been deprecated.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK!hhhhubh)}(h~This property will make GPIOs 15, 16 and 17 available to the driver under the "led" function, and GPIO 1 as the "power" GPIO::h]hThis property will make GPIOs 15, 16 and 17 available to the driver under the “led” function, and GPIO 1 as the “power” GPIO:}(hj"hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK%hhhhubj)}(hXstruct gpio_desc *red, *green, *blue, *power; red = gpiod_get_index(dev, "led", 0, GPIOD_OUT_HIGH); green = gpiod_get_index(dev, "led", 1, GPIOD_OUT_HIGH); blue = gpiod_get_index(dev, "led", 2, GPIOD_OUT_HIGH); power = gpiod_get(dev, "power", GPIOD_OUT_HIGH);h]hXstruct gpio_desc *red, *green, *blue, *power; red = gpiod_get_index(dev, "led", 0, GPIOD_OUT_HIGH); green = gpiod_get_index(dev, "led", 1, GPIOD_OUT_HIGH); blue = gpiod_get_index(dev, "led", 2, GPIOD_OUT_HIGH); power = gpiod_get(dev, "power", GPIOD_OUT_HIGH);}hj0sbah}(h]h ]h"]h$]h&]jjuh1jhhhK(hhhhubh)}(hzThe led GPIOs will be active high, while the power GPIO will be active low (i.e. gpiod_is_active_low(power) will be true).h]hzThe led GPIOs will be active high, while the power GPIO will be active low (i.e. gpiod_is_active_low(power) will be true).}(hj>hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK0hhhhubh)}(hX=The second parameter of the gpiod_get() functions, the con_id string, has to be the -prefix of the GPIO suffixes ("gpios" or "gpio", automatically looked up by the gpiod functions internally) used in the device tree. With above "led-gpios" example, use the prefix without the "-" as con_id parameter: "led".h]hXQThe second parameter of the gpiod_get() functions, the con_id string, has to be the -prefix of the GPIO suffixes (“gpios” or “gpio”, automatically looked up by the gpiod functions internally) used in the device tree. With above “led-gpios” example, use the prefix without the “-” as con_id parameter: “led”.}(hjLhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK3hhhhubh)}(hInternally, the GPIO subsystem prefixes the GPIO suffix ("gpios" or "gpio") with the string passed in con_id to get the resulting string (``snprintf(... "%s-%s", con_id, gpio_suffixes[]``).h](hInternally, the GPIO subsystem prefixes the GPIO suffix (“gpios” or “gpio”) with the string passed in con_id to get the resulting string (}(hjZhhhNhNubhliteral)}(h1``snprintf(... "%s-%s", con_id, gpio_suffixes[]``h]h-snprintf(... "%s-%s", con_id, gpio_suffixes[]}(hjdhhhNhNubah}(h]h ]h"]h$]h&]uh1jbhjZubh).}(hjZhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK8hhhhubeh}(h] device-treeah ]h"] device treeah$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(hACPIh]hACPI}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhK=ubh)}(hACPI also supports function names for GPIOs in a similar fashion to DT. The above DT example can be converted to an equivalent ACPI description with the help of _DSD (Device Specific Data), introduced in ACPI 5.1::h]hACPI also supports function names for GPIOs in a similar fashion to DT. The above DT example can be converted to an equivalent ACPI description with the help of _DSD (Device Specific Data), introduced in ACPI 5.1:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK>hjhhubj)}(hXDevice (FOO) { Name (_CRS, ResourceTemplate () { GpioIo (Exclusive, PullUp, 0, 0, IoRestrictionOutputOnly, "\\_SB.GPI0", 0, ResourceConsumer) { 15 } // red GpioIo (Exclusive, PullUp, 0, 0, IoRestrictionOutputOnly, "\\_SB.GPI0", 0, ResourceConsumer) { 16 } // green GpioIo (Exclusive, PullUp, 0, 0, IoRestrictionOutputOnly, "\\_SB.GPI0", 0, ResourceConsumer) { 17 } // blue GpioIo (Exclusive, PullNone, 0, 0, IoRestrictionOutputOnly, "\\_SB.GPI0", 0, ResourceConsumer) { 1 } // power }) Name (_DSD, Package () { ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"), Package () { Package () { "led-gpios", Package () { ^FOO, 0, 0, 1, ^FOO, 1, 0, 1, ^FOO, 2, 0, 1, } }, Package () { "power-gpios", Package () { ^FOO, 3, 0, 0 } }, } }) }h]hXDevice (FOO) { Name (_CRS, ResourceTemplate () { GpioIo (Exclusive, PullUp, 0, 0, IoRestrictionOutputOnly, "\\_SB.GPI0", 0, ResourceConsumer) { 15 } // red GpioIo (Exclusive, PullUp, 0, 0, IoRestrictionOutputOnly, "\\_SB.GPI0", 0, ResourceConsumer) { 16 } // green GpioIo (Exclusive, PullUp, 0, 0, IoRestrictionOutputOnly, "\\_SB.GPI0", 0, ResourceConsumer) { 17 } // blue GpioIo (Exclusive, PullNone, 0, 0, IoRestrictionOutputOnly, "\\_SB.GPI0", 0, ResourceConsumer) { 1 } // power }) Name (_DSD, Package () { ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"), Package () { Package () { "led-gpios", Package () { ^FOO, 0, 0, 1, ^FOO, 1, 0, 1, ^FOO, 2, 0, 1, } }, Package () { "power-gpios", Package () { ^FOO, 3, 0, 0 } }, } }) }}hjsbah}(h]h ]h"]h$]h&]jjuh1jhhhKBhjhhubh)}(hlFor more information about the ACPI GPIO bindings see Documentation/firmware-guide/acpi/gpio-properties.rst.h]hlFor more information about the ACPI GPIO bindings see Documentation/firmware-guide/acpi/gpio-properties.rst.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK^hjhhubeh}(h]acpiah ]h"]acpiah$]h&]uh1hhhhhhhhK=ubh)}(hhh](h)}(h Platform Datah]h Platform Data}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhKbubh)}(hFinally, GPIOs can be bound to devices and functions using platform data. Board files that desire to do so need to include the following header::h]hFinally, GPIOs can be bound to devices and functions using platform data. Board files that desire to do so need to include the following header:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKchjhhubj)}(h#include h]h#include }hjsbah}(h]h ]h"]h$]h&]jjuh1jhhhKfhjhhubh)}(hGPIOs are mapped by the means of tables of lookups, containing instances of the gpiod_lookup structure. Two macros are defined to help declaring such mappings::h]hGPIOs are mapped by the means of tables of lookups, containing instances of the gpiod_lookup structure. Two macros are defined to help declaring such mappings:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhhjhhubj)}(h`GPIO_LOOKUP(key, chip_hwnum, con_id, flags) GPIO_LOOKUP_IDX(key, chip_hwnum, con_id, idx, flags)h]h`GPIO_LOOKUP(key, chip_hwnum, con_id, flags) GPIO_LOOKUP_IDX(key, chip_hwnum, con_id, idx, flags)}hjsbah}(h]h ]h"]h$]h&]jjuh1jhhhKkhjhhubh)}(hwhereh]hwhere}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKnhjhhubh block_quote)}(hX- key is either the label of the gpiod_chip instance providing the GPIO, or the GPIO line name - chip_hwnum is the hardware number of the GPIO within the chip, or U16_MAX to indicate that key is a GPIO line name - con_id is the name of the GPIO function from the device point of view. It can be NULL, in which case it will match any function. - idx is the index of the GPIO within the function. - flags is defined to specify the following properties: * GPIO_ACTIVE_HIGH - GPIO line is active high * GPIO_ACTIVE_LOW - GPIO line is active low * GPIO_OPEN_DRAIN - GPIO line is set up as open drain * GPIO_OPEN_SOURCE - GPIO line is set up as open source * GPIO_PERSISTENT - GPIO line is persistent during suspend/resume and maintains its value * GPIO_TRANSITORY - GPIO line is transitory and may loose its electrical state during suspend/resume h]h bullet_list)}(hhh](h list_item)}(h\key is either the label of the gpiod_chip instance providing the GPIO, or the GPIO line nameh]h)}(h\key is either the label of the gpiod_chip instance providing the GPIO, or the GPIO line nameh]h\key is either the label of the gpiod_chip instance providing the GPIO, or the GPIO line name}(hj/hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKphj+ubah}(h]h ]h"]h$]h&]uh1j)hj&ubj*)}(hrchip_hwnum is the hardware number of the GPIO within the chip, or U16_MAX to indicate that key is a GPIO line nameh]h)}(hrchip_hwnum is the hardware number of the GPIO within the chip, or U16_MAX to indicate that key is a GPIO line nameh]hrchip_hwnum is the hardware number of the GPIO within the chip, or U16_MAX to indicate that key is a GPIO line name}(hjGhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKrhjCubah}(h]h ]h"]h$]h&]uh1j)hj&ubj*)}(hcon_id is the name of the GPIO function from the device point of view. It can be NULL, in which case it will match any function.h]hdefinition_list)}(hhh]hdefinition_list_item)}(hcon_id is the name of the GPIO function from the device point of view. It can be NULL, in which case it will match any function.h](hterm)}(hIcon_id is the name of the GPIO function from the device point of view. Ith]hIcon_id is the name of the GPIO function from the device point of view. It}(hjlhhhNhNubah}(h]h ]h"]h$]h&]uh1jjhhhKthjfubh definition)}(hhh]h)}(h6can be NULL, in which case it will match any function.h]h6can be NULL, in which case it will match any function.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKuhj|ubah}(h]h ]h"]h$]h&]uh1jzhjfubeh}(h]h ]h"]h$]h&]uh1jdhhhKthjaubah}(h]h ]h"]h$]h&]uh1j_hj[ubah}(h]h ]h"]h$]h&]uh1j)hj&ubj*)}(h1idx is the index of the GPIO within the function.h]h)}(hjh]h1idx is the index of the GPIO within the function.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKvhjubah}(h]h ]h"]h$]h&]uh1j)hj&ubj*)}(hX3flags is defined to specify the following properties: * GPIO_ACTIVE_HIGH - GPIO line is active high * GPIO_ACTIVE_LOW - GPIO line is active low * GPIO_OPEN_DRAIN - GPIO line is set up as open drain * GPIO_OPEN_SOURCE - GPIO line is set up as open source * GPIO_PERSISTENT - GPIO line is persistent during suspend/resume and maintains its value * GPIO_TRANSITORY - GPIO line is transitory and may loose its electrical state during suspend/resume h]j`)}(hhh]je)}(hXflags is defined to specify the following properties: * GPIO_ACTIVE_HIGH - GPIO line is active high * GPIO_ACTIVE_LOW - GPIO line is active low * GPIO_OPEN_DRAIN - GPIO line is set up as open drain * GPIO_OPEN_SOURCE - GPIO line is set up as open source * GPIO_PERSISTENT - GPIO line is persistent during suspend/resume and maintains its value * GPIO_TRANSITORY - GPIO line is transitory and may loose its electrical state during suspend/resume h](jk)}(h5flags is defined to specify the following properties:h]h5flags is defined to specify the following properties:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jjhhhKhjubj{)}(hhh]j%)}(hhh](j*)}(h0GPIO_ACTIVE_HIGH - GPIO line is active highh]h)}(hjh]h0GPIO_ACTIVE_HIGH - GPIO line is active high}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKxhjubah}(h]h ]h"]h$]h&]uh1j)hjubj*)}(h/GPIO_ACTIVE_LOW - GPIO line is active lowh]h)}(hjh]h/GPIO_ACTIVE_LOW - GPIO line is active low}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKyhjubah}(h]h ]h"]h$]h&]uh1j)hjubj*)}(h9GPIO_OPEN_DRAIN - GPIO line is set up as open drainh]h)}(hj h]h9GPIO_OPEN_DRAIN - GPIO line is set up as open drain}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKzhj ubah}(h]h ]h"]h$]h&]uh1j)hjubj*)}(h:GPIO_OPEN_SOURCE - GPIO line is set up as open sourceh]h)}(hj"h]h:GPIO_OPEN_SOURCE - GPIO line is set up as open source}(hj$hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK{hj ubah}(h]h ]h"]h$]h&]uh1j)hjubj*)}(huGPIO_PERSISTENT - GPIO line is persistent during suspend/resume and maintains its valueh]j`)}(hhh]je)}(h]GPIO_PERSISTENT - GPIO line is persistent during suspend/resume and maintains its valueh](jk)}(h6GPIO_PERSISTENT - GPIO line is persistent duringh]h6GPIO_PERSISTENT - GPIO line is persistent during}(hjBhhhNhNubah}(h]h ]h"]h$]h&]uh1jjhhhK|hj>ubj{)}(hhh]h)}(h&suspend/resume and maintains its valueh]h&suspend/resume and maintains its value}(hjShhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK}hjPubah}(h]h ]h"]h$]h&]uh1jzhj>ubeh}(h]h ]h"]h$]h&]uh1jdhhhK|hj;ubah}(h]h ]h"]h$]h&]uh1j_hj7ubah}(h]h ]h"]h$]h&]uh1j)hjubj*)}(hGPIO_TRANSITORY - GPIO line is transitory and may loose its electrical state during suspend/resume h]j`)}(hhh]je)}(hiGPIO_TRANSITORY - GPIO line is transitory and may loose its electrical state during suspend/resume h](jk)}(hAGPIO_TRANSITORY - GPIO line is transitory and may loose itsh]hAGPIO_TRANSITORY - GPIO line is transitory and may loose its}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jjhhhKhjubj{)}(hhh]h)}(h&electrical state during suspend/resumeh]h&electrical state during suspend/resume}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1jzhjubeh}(h]h ]h"]h$]h&]uh1jdhhhKhj}ubah}(h]h ]h"]h$]h&]uh1j_hjyubah}(h]h ]h"]h$]h&]uh1j)hjubeh}(h]h ]h"]h$]h&]bullet*uh1j$hhhKxhjubah}(h]h ]h"]h$]h&]uh1jzhjubeh}(h]h ]h"]h$]h&]uh1jdhhhKhjubah}(h]h ]h"]h$]h&]uh1j_hjubah}(h]h ]h"]h$]h&]uh1j)hj&ubeh}(h]h ]h"]h$]h&]j-uh1j$hhhKphj ubah}(h]h ]h"]h$]h&]uh1jhhhKphjhhubh)}(hHIn the future, these flags might be extended to support more properties.h]hHIn the future, these flags might be extended to support more properties.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubj`)}(hhh]je)}(hNote that: 1. GPIO line names are not guaranteed to be globally unique, so the first match found will be used. 2. GPIO_LOOKUP() is just a shortcut to GPIO_LOOKUP_IDX() where idx = 0. h](jk)}(h Note that:h]h Note that:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jjhhhKhjubj{)}(hhh]henumerated_list)}(hhh](j*)}(h`GPIO line names are not guaranteed to be globally unique, so the first match found will be used.h]h)}(h`GPIO line names are not guaranteed to be globally unique, so the first match found will be used.h]h`GPIO line names are not guaranteed to be globally unique, so the first match found will be used.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1j)hjubj*)}(hEGPIO_LOOKUP() is just a shortcut to GPIO_LOOKUP_IDX() where idx = 0. h]h)}(hDGPIO_LOOKUP() is just a shortcut to GPIO_LOOKUP_IDX() where idx = 0.h]hDGPIO_LOOKUP() is just a shortcut to GPIO_LOOKUP_IDX() where idx = 0.}(hj/hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj+ubah}(h]h ]h"]h$]h&]uh1j)hjubeh}(h]h ]h"]h$]h&]enumtypearabicprefixhsuffix.uh1jhj ubah}(h]h ]h"]h$]h&]uh1jzhjubeh}(h]h ]h"]h$]h&]uh1jdhhhKhjubah}(h]h ]h"]h$]h&]uh1j_hjhhhNhNubh)}(hXA lookup table can then be defined as follows, with an empty entry defining its end. The 'dev_id' field of the table is the identifier of the device that will make use of these GPIOs. It can be NULL, in which case it will be matched for calls to gpiod_get() with a NULL device.h]hXA lookup table can then be defined as follows, with an empty entry defining its end. The ‘dev_id’ field of the table is the identifier of the device that will make use of these GPIOs. It can be NULL, in which case it will be matched for calls to gpiod_get() with a NULL device.}(hj`hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubj)}(hXstruct gpiod_lookup_table gpios_table = { .dev_id = "foo.0", .table = { GPIO_LOOKUP_IDX("gpio.0", 15, "led", 0, GPIO_ACTIVE_HIGH), GPIO_LOOKUP_IDX("gpio.0", 16, "led", 1, GPIO_ACTIVE_HIGH), GPIO_LOOKUP_IDX("gpio.0", 17, "led", 2, GPIO_ACTIVE_HIGH), GPIO_LOOKUP("gpio.0", 1, "power", GPIO_ACTIVE_LOW), { }, }, };h]hXstruct gpiod_lookup_table gpios_table = { .dev_id = "foo.0", .table = { GPIO_LOOKUP_IDX("gpio.0", 15, "led", 0, GPIO_ACTIVE_HIGH), GPIO_LOOKUP_IDX("gpio.0", 16, "led", 1, GPIO_ACTIVE_HIGH), GPIO_LOOKUP_IDX("gpio.0", 17, "led", 2, GPIO_ACTIVE_HIGH), GPIO_LOOKUP("gpio.0", 1, "power", GPIO_ACTIVE_LOW), { }, }, };}hjnsbah}(h]h ]h"]h$]h&]jjforcelanguagechighlight_args}uh1jhhhKhjhhubh)}(h9And the table can be added by the board code as follows::h]h8And the table can be added by the board code as follows:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubj)}(h%gpiod_add_lookup_table(&gpios_table);h]h%gpiod_add_lookup_table(&gpios_table);}hjsbah}(h]h ]h"]h$]h&]jjuh1jhhhKhjhhubh)}(hQThe driver controlling "foo.0" will then be able to obtain its GPIOs as follows::h]hTThe driver controlling “foo.0” will then be able to obtain its GPIOs as follows:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubj)}(hXstruct gpio_desc *red, *green, *blue, *power; red = gpiod_get_index(dev, "led", 0, GPIOD_OUT_HIGH); green = gpiod_get_index(dev, "led", 1, GPIOD_OUT_HIGH); blue = gpiod_get_index(dev, "led", 2, GPIOD_OUT_HIGH); power = gpiod_get(dev, "power", GPIOD_OUT_HIGH);h]hXstruct gpio_desc *red, *green, *blue, *power; red = gpiod_get_index(dev, "led", 0, GPIOD_OUT_HIGH); green = gpiod_get_index(dev, "led", 1, GPIOD_OUT_HIGH); blue = gpiod_get_index(dev, "led", 2, GPIOD_OUT_HIGH); power = gpiod_get(dev, "power", GPIOD_OUT_HIGH);}hjsbah}(h]h ]h"]h$]h&]jjuh1jhhhKhjhhubh)}(hXgSince the "led" GPIOs are mapped as active-high, this example will switch their signals to 1, i.e. enabling the LEDs. And for the "power" GPIO, which is mapped as active-low, its actual signal will be 0 after this code. Contrary to the legacy integer GPIO interface, the active-low property is handled during mapping and is thus transparent to GPIO consumers.h]hXoSince the “led” GPIOs are mapped as active-high, this example will switch their signals to 1, i.e. enabling the LEDs. And for the “power” GPIO, which is mapped as active-low, its actual signal will be 0 after this code. Contrary to the legacy integer GPIO interface, the active-low property is handled during mapping and is thus transparent to GPIO consumers.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hmA set of functions such as gpiod_set_value() is available to work with the new descriptor-oriented interface.h]hmA set of functions such as gpiod_set_value() is available to work with the new descriptor-oriented interface.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hOBoards using platform data can also hog GPIO lines by defining GPIO hog tables.h]hOBoards using platform data can also hog GPIO lines by defining GPIO hog tables.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubj)}(h|struct gpiod_hog gpio_hog_table[] = { GPIO_HOG("gpio.0", 10, "foo", GPIO_ACTIVE_LOW, GPIOD_OUT_HIGH), { } };h]h|struct gpiod_hog gpio_hog_table[] = { GPIO_HOG("gpio.0", 10, "foo", GPIO_ACTIVE_LOW, GPIOD_OUT_HIGH), { } };}hjsbah}(h]h ]h"]h$]h&]jjj|j}j~j}uh1jhhhKhjhhubh)}(h9And the table can be added to the board code as follows::h]h8And the table can be added to the board code as follows:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubj)}(hgpiod_add_hogs(gpio_hog_table);h]hgpiod_add_hogs(gpio_hog_table);}hjsbah}(h]h ]h"]h$]h&]jjuh1jhhhKhjhhubh)}(hThe line will be hogged as soon as the gpiochip is created or - in case the chip was created earlier - when the hog table is registered.h]hThe line will be hogged as soon as the gpiochip is created or - in case the chip was created earlier - when the hog table is registered.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubeh}(h] platform-dataah ]h"] platform dataah$]h&]uh1hhhhhhhhKbubh)}(hhh](h)}(hArrays of pinsh]hArrays of pins}(hj'hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj$hhhhhKubh)}(hXIn addition to requesting pins belonging to a function one by one, a device may also request an array of pins assigned to the function. The way those pins are mapped to the device determines if the array qualifies for fast bitmap processing. If yes, a bitmap is passed over get/set array functions directly between a caller and a respective .get/set_multiple() callback of a GPIO chip.h]hXIn addition to requesting pins belonging to a function one by one, a device may also request an array of pins assigned to the function. The way those pins are mapped to the device determines if the array qualifies for fast bitmap processing. If yes, a bitmap is passed over get/set array functions directly between a caller and a respective .get/set_multiple() callback of a GPIO chip.}(hj5hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj$hhubh)}(h_In order to qualify for fast bitmap processing, the array must meet the following requirements:h]h_In order to qualify for fast bitmap processing, the array must meet the following requirements:}(hjChhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj$hhubj%)}(hhh](j*)}(h5pin hardware number of array member 0 must also be 0,h]h)}(hjVh]h5pin hardware number of array member 0 must also be 0,}(hjXhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjTubah}(h]h ]h"]h$]h&]uh1j)hjQhhhhhNubj*)}(hpin hardware numbers of consecutive array members which belong to the same chip as member 0 does must also match their array indexes. h]h)}(hpin hardware numbers of consecutive array members which belong to the same chip as member 0 does must also match their array indexes.h]hpin hardware numbers of consecutive array members which belong to the same chip as member 0 does must also match their array indexes.}(hjohhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjkubah}(h]h ]h"]h$]h&]uh1j)hjQhhhhhNubeh}(h]h ]h"]h$]h&]jjuh1j$hhhKhj$hhubh)}(hOtherwise fast bitmap processing path is not used in order to avoid consecutive pins which belong to the same chip but are not in hardware order being processed separately.h]hOtherwise fast bitmap processing path is not used in order to avoid consecutive pins which belong to the same chip but are not in hardware order being processed separately.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj$hhubh)}(hXKIf the array applies for fast bitmap processing path, pins which belong to different chips than member 0 does, as well as those with indexes different from their hardware pin numbers, are excluded from the fast path, both input and output. Moreover, open drain and open source pins are excluded from fast bitmap output processing.h]hXKIf the array applies for fast bitmap processing path, pins which belong to different chips than member 0 does, as well as those with indexes different from their hardware pin numbers, are excluded from the fast path, both input and output. Moreover, open drain and open source pins are excluded from fast bitmap output processing.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj$hhubeh}(h]arrays-of-pinsah ]h"]arrays of pinsah$]h&]uh1hhhhhhhhKubeh}(h] gpio-mappingsah ]h"] gpio mappingsah$]h&]uh1hhhhhhhhKubeh}(h]h ]h"]h$]h&]sourcehuh1hcurrent_sourceN current_lineNsettingsdocutils.frontendValues)}(hN generatorN datestampN source_linkN source_urlN toc_backlinksentryfootnote_backlinksK sectnum_xformKstrip_commentsNstrip_elements_with_classesN strip_classesN report_levelK halt_levelKexit_status_levelKdebugNwarning_streamN tracebackinput_encoding utf-8-siginput_encoding_error_handlerstrictoutput_encodingutf-8output_encoding_error_handlerjerror_encodingutf-8error_encoding_error_handlerbackslashreplace language_codeenrecord_dependenciesNconfigN id_prefixhauto_id_prefixid dump_settingsNdump_internalsNdump_transformsNdump_pseudo_xmlNexpose_internalsNstrict_visitorN_disable_configN_sourceh _destinationN _config_files]7/var/lib/git/docbuild/linux/Documentation/docutils.confafile_insertion_enabled raw_enabledKline_length_limitM'pep_referencesN pep_base_urlhttps://peps.python.org/pep_file_url_templatepep-%04drfc_referencesN rfc_base_url&https://datatracker.ietf.org/doc/html/ tab_widthKtrim_footnote_reference_spacesyntax_highlightlong smart_quotessmartquotes_locales]character_level_inline_markupdoctitle_xform docinfo_xformKsectsubtitle_xform image_loadinglinkembed_stylesheetcloak_email_addressessection_self_linkenvNubreporterNindirect_targets]substitution_defs}substitution_names}refnames}refids}nameids}(jjjj~jjj!jjju nametypes}(jjjj!juh}(jhj~hjjjjjj$u footnote_refs} citation_refs} autofootnotes]autofootnote_refs]symbol_footnotes]symbol_footnote_refs] footnotes] citations]autofootnote_startKsymbol_footnote_startK id_counter collectionsCounter}Rparse_messages]transform_messages] transformerN include_log] decorationNhhub.