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/consumermodnameN classnameN refexplicitutagnamehhh ubh)}(hhh]hChinese (Traditional)}hh2sbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget,/translations/zh_TW/driver-api/gpio/consumermodnameN classnameN refexplicituh1hhh ubh)}(hhh]hItalian}hhFsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget,/translations/it_IT/driver-api/gpio/consumermodnameN classnameN refexplicituh1hhh ubh)}(hhh]hJapanese}hhZsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget,/translations/ja_JP/driver-api/gpio/consumermodnameN classnameN refexplicituh1hhh ubh)}(hhh]hKorean}hhnsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget,/translations/ko_KR/driver-api/gpio/consumermodnameN classnameN refexplicituh1hhh ubh)}(hhh]hSpanish}hhsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget,/translations/sp_SP/driver-api/gpio/consumermodnameN classnameN refexplicituh1hhh ubeh}(h]h ]h"]h$]h&]current_languageEnglishuh1h hh _documenthsourceNlineNubhsection)}(hhh](htitle)}(h"GPIO Descriptor Consumer Interfaceh]h"GPIO Descriptor Consumer Interface}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhhhF/var/lib/git/docbuild/linux/Documentation/driver-api/gpio/consumer.rsthKubh paragraph)}(hEThis document describes the consumer interface of the GPIO framework.h]hEThis document describes the consumer interface of the GPIO framework.}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhhhhubh)}(hhh](h)}(hGuidelines for GPIOs consumersh]hGuidelines for GPIOs consumers}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhhhhhK ubh)}(hDrivers that can't work without standard GPIO calls should have Kconfig entries that depend on GPIOLIB or select GPIOLIB. The functions that allow a driver to obtain and use GPIOs are available by including the following file::h]hDrivers that can’t work without standard GPIO calls should have Kconfig entries that depend on GPIOLIB or select GPIOLIB. The functions that allow a driver to obtain and use GPIOs are available by including the following file:}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK hhhhubh literal_block)}(h #include h]h #include }hhsbah}(h]h ]h"]h$]h&] xml:spacepreserveuh1hhhhKhhhhubh)}(hThere are static inline stubs for all functions in the header file in the case where GPIOLIB is disabled. When these stubs are called they will emit warnings. These stubs are used for two use cases:h]hThere are static inline stubs for all functions in the header file in the case where GPIOLIB is disabled. When these stubs are called they will emit warnings. These stubs are used for two use cases:}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhhhhubh bullet_list)}(hhh](h list_item)}(hSimple compile coverage with e.g. COMPILE_TEST - it does not matter that the current platform does not enable or select GPIOLIB because we are not going to execute the system anyway. h]h)}(hSimple compile coverage with e.g. COMPILE_TEST - it does not matter that the current platform does not enable or select GPIOLIB because we are not going to execute the system anyway.h]hSimple compile coverage with e.g. COMPILE_TEST - it does not matter that the current platform does not enable or select GPIOLIB because we are not going to execute the system anyway.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj ubah}(h]h ]h"]h$]h&]uh1j hjhhhhhNubj )}(hX}Truly optional GPIOLIB support - where the driver does not really make use of the GPIOs on certain compile-time configurations for certain systems, but will use it under other compile-time configurations. In this case the consumer must make sure not to call into these functions, or the user will be met with console warnings that may be perceived as intimidating. Combining truly optional GPIOLIB usage with calls to ``[devm_]gpiod_get_optional()`` is a *bad idea*, and will result in weird error messages. Use the ordinary getter functions with optional GPIOLIB: some open coding of error handling should be expected when you do this. h]h)}(hX|Truly optional GPIOLIB support - where the driver does not really make use of the GPIOs on certain compile-time configurations for certain systems, but will use it under other compile-time configurations. In this case the consumer must make sure not to call into these functions, or the user will be met with console warnings that may be perceived as intimidating. Combining truly optional GPIOLIB usage with calls to ``[devm_]gpiod_get_optional()`` is a *bad idea*, and will result in weird error messages. Use the ordinary getter functions with optional GPIOLIB: some open coding of error handling should be expected when you do this.h](hXTruly optional GPIOLIB support - where the driver does not really make use of the GPIOs on certain compile-time configurations for certain systems, but will use it under other compile-time configurations. In this case the consumer must make sure not to call into these functions, or the user will be met with console warnings that may be perceived as intimidating. Combining truly optional GPIOLIB usage with calls to }(hj)hhhNhNubhliteral)}(h``[devm_]gpiod_get_optional()``h]hevm_]gpiod_get_optional()}(hj3hhhNhNubah}(h]h ]h"]h$]h&]uh1j1hj)ubh is a }(hj)hhhNhNubhemphasis)}(h *bad idea*h]hbad idea}(hjGhhhNhNubah}(h]h ]h"]h$]h&]uh1jEhj)ubh, and will result in weird error messages. Use the ordinary getter functions with optional GPIOLIB: some open coding of error handling should be expected when you do this.}(hj)hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhj%ubah}(h]h ]h"]h$]h&]uh1j hjhhhhhNubeh}(h]h ]h"]h$]h&]bullet-uh1jhhhKhhhhubh)}(hXVAll the functions that work with the descriptor-based GPIO interface are prefixed with ``gpiod_``. The ``gpio_`` prefix is used for the legacy interface. No other function in the kernel should use these prefixes. The use of the legacy functions is strongly discouraged, new code should use and descriptors exclusively.h](hWAll the functions that work with the descriptor-based GPIO interface are prefixed with }(hjmhhhNhNubj2)}(h ``gpiod_``h]hgpiod_}(hjuhhhNhNubah}(h]h ]h"]h$]h&]uh1j1hjmubh. The }(hjmhhhNhNubj2)}(h ``gpio_``h]hgpio_}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j1hjmubh prefix is used for the legacy interface. No other function in the kernel should use these prefixes. The use of the legacy functions is strongly discouraged, new code should use and descriptors exclusively.}(hjmhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK#hhhhubeh}(h]guidelines-for-gpios-consumersah ]h"]guidelines for gpios consumersah$]h&]uh1hhhhhhhhK ubh)}(hhh](h)}(hObtaining and Disposing GPIOsh]hObtaining and Disposing GPIOs}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhK+ubh)}(hX=With the descriptor-based interface, GPIOs are identified with an opaque, non-forgeable handler that must be obtained through a call to one of the gpiod_get() functions. Like many other kernel subsystems, gpiod_get() takes the device that will use the GPIO and the function the requested GPIO is supposed to fulfill::h]hX<With the descriptor-based interface, GPIOs are identified with an opaque, non-forgeable handler that must be obtained through a call to one of the gpiod_get() functions. Like many other kernel subsystems, gpiod_get() takes the device that will use the GPIO and the function the requested GPIO is supposed to fulfill:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK-hjhhubh)}(hwstruct gpio_desc *gpiod_get(struct device *dev, const char *con_id, enum gpiod_flags flags)h]hwstruct gpio_desc *gpiod_get(struct device *dev, const char *con_id, enum gpiod_flags flags)}hjsbah}(h]h ]h"]h$]h&]hhuh1hhhhK3hjhhubh)}(hIf a function is implemented by using several GPIOs together (e.g. a simple LED device that displays digits), an additional index argument can be specified::h]hIf a function is implemented by using several GPIOs together (e.g. a simple LED device that displays digits), an additional index argument can be specified:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK6hjhhubh)}(hstruct gpio_desc *gpiod_get_index(struct device *dev, const char *con_id, unsigned int idx, enum gpiod_flags flags)h]hstruct gpio_desc *gpiod_get_index(struct device *dev, const char *con_id, unsigned int idx, enum gpiod_flags flags)}hjsbah}(h]h ]h"]h$]h&]hhuh1hhhhK9hjhhubh)}(hzFor a more detailed description of the con_id parameter in the DeviceTree case see Documentation/driver-api/gpio/board.rsth]hzFor a more detailed description of the con_id parameter in the DeviceTree case see Documentation/driver-api/gpio/board.rst}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK=hjhhubh)}(hlThe flags parameter is used to optionally specify a direction and initial value for the GPIO. Values can be:h]hlThe flags parameter is used to optionally specify a direction and initial value for the GPIO. Values can be:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK@hjhhubj)}(hhh](j )}(hwGPIOD_ASIS or 0 to not initialize the GPIO at all. The direction must be set later with one of the dedicated functions.h]h)}(hwGPIOD_ASIS or 0 to not initialize the GPIO at all. The direction must be set later with one of the dedicated functions.h]hwGPIOD_ASIS or 0 to not initialize the GPIO at all. The direction must be set later with one of the dedicated functions.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKChjubah}(h]h ]h"]h$]h&]uh1j hj hhhhhNubj )}(h)GPIOD_IN to initialize the GPIO as input.h]h)}(hj)h]h)GPIOD_IN to initialize the GPIO as input.}(hj+hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKEhj'ubah}(h]h ]h"]h$]h&]uh1j hj hhhhhNubj )}(hAGPIOD_OUT_LOW to initialize the GPIO as output with a value of 0.h]h)}(hj@h]hAGPIOD_OUT_LOW to initialize the GPIO as output with a value of 0.}(hjBhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKFhj>ubah}(h]h ]h"]h$]h&]uh1j hj hhhhhNubj )}(hBGPIOD_OUT_HIGH to initialize the GPIO as output with a value of 1.h]h)}(hjWh]hBGPIOD_OUT_HIGH to initialize the GPIO as output with a value of 1.}(hjYhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKGhjUubah}(h]h ]h"]h$]h&]uh1j hj hhhhhNubj )}(hqGPIOD_OUT_LOW_OPEN_DRAIN same as GPIOD_OUT_LOW but also enforce the line to be electrically used with open drain.h]h)}(hqGPIOD_OUT_LOW_OPEN_DRAIN same as GPIOD_OUT_LOW but also enforce the line to be electrically used with open drain.h]hqGPIOD_OUT_LOW_OPEN_DRAIN same as GPIOD_OUT_LOW but also enforce the line to be electrically used with open drain.}(hjphhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKHhjlubah}(h]h ]h"]h$]h&]uh1j hj hhhhhNubj )}(htGPIOD_OUT_HIGH_OPEN_DRAIN same as GPIOD_OUT_HIGH but also enforce the line to be electrically used with open drain. h]h)}(hsGPIOD_OUT_HIGH_OPEN_DRAIN same as GPIOD_OUT_HIGH but also enforce the line to be electrically used with open drain.h]hsGPIOD_OUT_HIGH_OPEN_DRAIN same as GPIOD_OUT_HIGH but also enforce the line to be electrically used with open drain.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKJhjubah}(h]h ]h"]h$]h&]uh1j hj hhhhhNubeh}(h]h ]h"]h$]h&]jk*uh1jhhhKChjhhubh)}(hNote that the initial value is *logical* and the physical line level depends on whether the line is configured active high or active low (see :ref:`active_low_semantics`).h](hNote that the initial value is }(hjhhhNhNubjF)}(h *logical*h]hlogical}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jEhjubhf and the physical line level depends on whether the line is configured active high or active low (see }(hjhhhNhNubh)}(h:ref:`active_low_semantics`h]hinline)}(hjh]hactive_low_semantics}(hjhhhNhNubah}(h]h ](xrefstdstd-refeh"]h$]h&]uh1jhjubah}(h]h ]h"]h$]h&]refdocdriver-api/gpio/consumer refdomainjreftyperef refexplicitrefwarn reftargetactive_low_semanticsuh1hhhhKMhjubh).}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKMhjhhubh)}(hX8The two last flags are used for use cases where open drain is mandatory, such as I2C: if the line is not already configured as open drain in the mappings (see board.rst), then open drain will be enforced anyway and a warning will be printed that the board configuration needs to be updated to match the use case.h]hX8The two last flags are used for use cases where open drain is mandatory, such as I2C: if the line is not already configured as open drain in the mappings (see board.rst), then open drain will be enforced anyway and a warning will be printed that the board configuration needs to be updated to match the use case.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKQhjhhubh)}(hXBoth functions return either a valid GPIO descriptor, or an error code checkable with IS_ERR() (they will never return a NULL pointer). -ENOENT will be returned if and only if no GPIO has been assigned to the device/function/index triplet, other error codes are used for cases where a GPIO has been assigned but an error occurred while trying to acquire it. This is useful to discriminate between mere errors and an absence of GPIO for optional GPIO parameters. For the common pattern where a GPIO is optional, the gpiod_get_optional() and gpiod_get_index_optional() functions can be used. These functions return NULL instead of -ENOENT if no GPIO has been assigned to the requested function::h]hXBoth functions return either a valid GPIO descriptor, or an error code checkable with IS_ERR() (they will never return a NULL pointer). -ENOENT will be returned if and only if no GPIO has been assigned to the device/function/index triplet, other error codes are used for cases where a GPIO has been assigned but an error occurred while trying to acquire it. This is useful to discriminate between mere errors and an absence of GPIO for optional GPIO parameters. For the common pattern where a GPIO is optional, the gpiod_get_optional() and gpiod_get_index_optional() functions can be used. These functions return NULL instead of -ENOENT if no GPIO has been assigned to the requested function:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKVhjhhubh)}(hXstruct gpio_desc *gpiod_get_optional(struct device *dev, const char *con_id, enum gpiod_flags flags) struct gpio_desc *gpiod_get_index_optional(struct device *dev, const char *con_id, unsigned int index, enum gpiod_flags flags)h]hXstruct gpio_desc *gpiod_get_optional(struct device *dev, const char *con_id, enum gpiod_flags flags) struct gpio_desc *gpiod_get_index_optional(struct device *dev, const char *con_id, unsigned int index, enum gpiod_flags flags)}hjsbah}(h]h ]h"]h$]h&]hhuh1hhhhK`hjhhubh)}(hXRNote that gpio_get*_optional() functions (and their managed variants), unlike the rest of gpiolib API, also return NULL when gpiolib support is disabled. This is helpful to driver authors, since they do not need to special case -ENOSYS return codes. System integrators should however be careful to enable gpiolib on systems that need it.h]hXRNote that gpio_get*_optional() functions (and their managed variants), unlike the rest of gpiolib API, also return NULL when gpiolib support is disabled. This is helpful to driver authors, since they do not need to special case -ENOSYS return codes. System integrators should however be careful to enable gpiolib on systems that need it.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKihjhhubh)}(hPFor a function using multiple GPIOs all of those can be obtained with one call::h]hOFor a function using multiple GPIOs all of those can be obtained with one call:}(hj$hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKohjhhubh)}(hstruct gpio_descs *gpiod_get_array(struct device *dev, const char *con_id, enum gpiod_flags flags)h]hstruct gpio_descs *gpiod_get_array(struct device *dev, const char *con_id, enum gpiod_flags flags)}hj2sbah}(h]h ]h"]h$]h&]hhuh1hhhhKqhjhhubh)}(hThis function returns a struct gpio_descs which contains an array of descriptors. It also contains a pointer to a gpiolib private structure which, if passed back to get/set array functions, may speed up I/O processing::h]hThis function returns a struct gpio_descs which contains an array of descriptors. It also contains a pointer to a gpiolib private structure which, if passed back to get/set array functions, may speed up I/O processing:}(hj@hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKuhjhhubh)}(hustruct gpio_descs { struct gpio_array *info; unsigned int ndescs; struct gpio_desc *desc[]; }h]hustruct gpio_descs { struct gpio_array *info; unsigned int ndescs; struct gpio_desc *desc[]; }}hjNsbah}(h]h ]h"]h$]h&]hhuh1hhhhKyhjhhubh)}(hqThe following function returns NULL instead of -ENOENT if no GPIOs have been assigned to the requested function::h]hpThe following function returns NULL instead of -ENOENT if no GPIOs have been assigned to the requested function:}(hj\hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hstruct gpio_descs *gpiod_get_array_optional(struct device *dev, const char *con_id, enum gpiod_flags flags)h]hstruct gpio_descs *gpiod_get_array_optional(struct device *dev, const char *con_id, enum gpiod_flags flags)}hjjsbah}(h]h ]h"]h$]h&]hhuh1hhhhKhjhhubh)}(h=Device-managed variants of these functions are also defined::h]hTo access such GPIOs, a different set of accessors is defined:}(hjBhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(h{int gpiod_get_value_cansleep(const struct gpio_desc *desc) void gpiod_set_value_cansleep(struct gpio_desc *desc, int value)h]h{int gpiod_get_value_cansleep(const struct gpio_desc *desc) void gpiod_set_value_cansleep(struct gpio_desc *desc, int value)}hjPsbah}(h]h ]h"]h$]h&]hhuh1hhhhKhjhhubh)}(hAccessing such GPIOs requires a context which may sleep, for example a threaded IRQ handler, and those accessors must be used instead of spinlock-safe accessors without the cansleep() name suffix.h]hAccessing such GPIOs requires a context which may sleep, for example a threaded IRQ handler, and those accessors must be used instead of spinlock-safe accessors without the cansleep() name suffix.}(hj^hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hOther than the fact that these accessors might sleep, and will work on GPIOs that can't be accessed from hardIRQ handlers, these calls act the same as the spinlock-safe calls.h]hOther than the fact that these accessors might sleep, and will work on GPIOs that can’t be accessed from hardIRQ handlers, these calls act the same as the spinlock-safe calls.}(hjlhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubhtarget)}(h.. _active_low_semantics:h]h}(h]h ]h"]h$]h&]refidactive-low-semanticsuh1jzhMhjhhhhubeh}(h]gpio-access-that-may-sleepah ]h"]gpio access that may sleepah$]h&]uh1hhjhhhhhKubh)}(hhh](h)}(h'The active low and open drain semanticsh]h'The active low and open drain semantics}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhMubh)}(hXAs a consumer should not have to care about the physical line level, all of the gpiod_set_value_xxx() or gpiod_set_array_value_xxx() functions operate with the *logical* value. With this they take the active low property into account. This means that they check whether the GPIO is configured to be active low, and if so, they manipulate the passed value before the physical line level is driven.h](hAs a consumer should not have to care about the physical line level, all of the gpiod_set_value_xxx() or gpiod_set_array_value_xxx() functions operate with the }(hjhhhNhNubjF)}(h *logical*h]hlogical}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jEhjubh value. With this they take the active low property into account. This means that they check whether the GPIO is configured to be active low, and if so, they manipulate the passed value before the physical line level is driven.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM hjhhubh)}(hX%The same is applicable for open drain or open source output lines: those do not actively drive their output high (open drain) or low (open source), they just switch their output to a high impedance value. The consumer should not need to care. (For details read about open drain in driver.rst.)h]hX%The same is applicable for open drain or open source output lines: those do not actively drive their output high (open drain) or low (open source), they just switch their output to a high impedance value. The consumer should not need to care. (For details read about open drain in driver.rst.)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hWith this, all the gpiod_set_(array)_value_xxx() functions interpret the parameter "value" as "active" ("1") or "inactive" ("0"). The physical line level will be driven accordingly.h]hWith this, all the gpiod_set_(array)_value_xxx() functions interpret the parameter “value” as “active” (“1”) or “inactive” (“0”). The physical line level will be driven accordingly.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hAs an example, if the active low property for a dedicated GPIO is set, and the gpiod_set_(array)_value_xxx() passes "active" ("1"), the physical line level will be driven low.h]hAs an example, if the active low property for a dedicated GPIO is set, and the gpiod_set_(array)_value_xxx() passes “active” (“1”), the physical line level will be driven low.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hTo summarize::h]h To summarize:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hXFunction (example) line property physical line gpiod_set_raw_value(desc, 0); don't care low gpiod_set_raw_value(desc, 1); don't care high gpiod_set_value(desc, 0); default (active high) low gpiod_set_value(desc, 1); default (active high) high gpiod_set_value(desc, 0); active low high gpiod_set_value(desc, 1); active low low gpiod_set_value(desc, 0); open drain low gpiod_set_value(desc, 1); open drain high impedance gpiod_set_value(desc, 0); open source high impedance gpiod_set_value(desc, 1); open source highh]hXFunction (example) line property physical line gpiod_set_raw_value(desc, 0); don't care low gpiod_set_raw_value(desc, 1); don't care high gpiod_set_value(desc, 0); default (active high) low gpiod_set_value(desc, 1); default (active high) high gpiod_set_value(desc, 0); active low high gpiod_set_value(desc, 1); active low low gpiod_set_value(desc, 0); open drain low gpiod_set_value(desc, 1); open drain high impedance gpiod_set_value(desc, 0); open source high impedance gpiod_set_value(desc, 1); open source high}hjsbah}(h]h ]h"]h$]h&]hhuh1hhhhMhjhhubh)}(hXIt is possible to override these semantics using the set_raw/get_raw functions but it should be avoided as much as possible, especially by system-agnostic drivers which should not need to care about the actual physical line level and worry about the logical value instead.h]hXIt is possible to override these semantics using the set_raw/get_raw functions but it should be avoided as much as possible, especially by system-agnostic drivers which should not need to care about the actual physical line level and worry about the logical value instead.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM+hjhhubeh}(h]('the-active-low-and-open-drain-semanticsjeh ]h"]('the active low and open drain semanticsactive_low_semanticseh$]h&]uh1hhjhhhhhMexpect_referenced_by_name}jj|sexpect_referenced_by_id}jj|subh)}(hhh](h)}(hAccessing raw GPIO valuesh]hAccessing raw GPIO values}(hj%hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj"hhhhhM2ubh)}(hConsumers exist that need to manage the logical state of a GPIO line, i.e. the value their device will actually receive, no matter what lies between it and the GPIO line.h]hConsumers exist that need to manage the logical state of a GPIO line, i.e. the value their device will actually receive, no matter what lies between it and the GPIO line.}(hj3hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM3hj"hhubh)}(hrThe following set of calls ignore the active-low or open drain property of a GPIO and work on the raw line value::h]hqThe following set of calls ignore the active-low or open drain property of a GPIO and work on the raw line value:}(hjAhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM7hj"hhubh)}(hX7int gpiod_get_raw_value(const struct gpio_desc *desc) void gpiod_set_raw_value(struct gpio_desc *desc, int value) int gpiod_get_raw_value_cansleep(const struct gpio_desc *desc) void gpiod_set_raw_value_cansleep(struct gpio_desc *desc, int value) int gpiod_direction_output_raw(struct gpio_desc *desc, int value)h]hX7int gpiod_get_raw_value(const struct gpio_desc *desc) void gpiod_set_raw_value(struct gpio_desc *desc, int value) int gpiod_get_raw_value_cansleep(const struct gpio_desc *desc) void gpiod_set_raw_value_cansleep(struct gpio_desc *desc, int value) int gpiod_direction_output_raw(struct gpio_desc *desc, int value)}hjOsbah}(h]h ]h"]h$]h&]hhuh1hhhhM:hj"hhubh)}(hZThe active low state of a GPIO can also be queried and toggled using the following calls::h]hYThe active low state of a GPIO can also be queried and toggled using the following calls:}(hj]hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM@hj"hhubh)}(hjint gpiod_is_active_low(const struct gpio_desc *desc) void gpiod_toggle_active_low(struct gpio_desc *desc)h]hjint gpiod_is_active_low(const struct gpio_desc *desc) void gpiod_toggle_active_low(struct gpio_desc *desc)}hjksbah}(h]h ]h"]h$]h&]hhuh1hhhhMChj"hhubh)}(hNote that these functions should only be used with great moderation; a driver should not have to care about the physical line level or open drain semantics.h]hNote that these functions should only be used with great moderation; a driver should not have to care about the physical line level or open drain semantics.}(hjyhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMFhj"hhubeh}(h]accessing-raw-gpio-valuesah ]h"]accessing raw gpio valuesah$]h&]uh1hhjhhhhhM2ubh)}(hhh](h)}(h1Access multiple GPIOs with a single function callh]h1Access multiple GPIOs with a single function call}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhMKubh)}(hDThe following functions get or set the values of an array of GPIOs::h]hCThe following functions get or set the values of an array of GPIOs:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMLhjhhubh)}(hXint gpiod_get_array_value(unsigned int array_size, struct gpio_desc **desc_array, struct gpio_array *array_info, unsigned long *value_bitmap); int gpiod_get_raw_array_value(unsigned int array_size, struct gpio_desc **desc_array, struct gpio_array *array_info, unsigned long *value_bitmap); int gpiod_get_array_value_cansleep(unsigned int array_size, struct gpio_desc **desc_array, struct gpio_array *array_info, unsigned long *value_bitmap); int gpiod_get_raw_array_value_cansleep(unsigned int array_size, struct gpio_desc **desc_array, struct gpio_array *array_info, unsigned long *value_bitmap); int gpiod_set_array_value(unsigned int array_size, struct gpio_desc **desc_array, struct gpio_array *array_info, unsigned long *value_bitmap) int gpiod_set_raw_array_value(unsigned int array_size, struct gpio_desc **desc_array, struct gpio_array *array_info, unsigned long *value_bitmap) int gpiod_set_array_value_cansleep(unsigned int array_size, struct gpio_desc **desc_array, struct gpio_array *array_info, unsigned long *value_bitmap) int gpiod_set_raw_array_value_cansleep(unsigned int array_size, struct gpio_desc **desc_array, struct gpio_array *array_info, unsigned long *value_bitmap)h]hXint gpiod_get_array_value(unsigned int array_size, struct gpio_desc **desc_array, struct gpio_array *array_info, unsigned long *value_bitmap); int gpiod_get_raw_array_value(unsigned int array_size, struct gpio_desc **desc_array, struct gpio_array *array_info, unsigned long *value_bitmap); int gpiod_get_array_value_cansleep(unsigned int array_size, struct gpio_desc **desc_array, struct gpio_array *array_info, unsigned long *value_bitmap); int gpiod_get_raw_array_value_cansleep(unsigned int array_size, struct gpio_desc **desc_array, struct gpio_array *array_info, unsigned long *value_bitmap); int gpiod_set_array_value(unsigned int array_size, struct gpio_desc **desc_array, struct gpio_array *array_info, unsigned long *value_bitmap) int gpiod_set_raw_array_value(unsigned int array_size, struct gpio_desc **desc_array, struct gpio_array *array_info, unsigned long *value_bitmap) int gpiod_set_array_value_cansleep(unsigned int array_size, struct gpio_desc **desc_array, struct gpio_array *array_info, unsigned long *value_bitmap) int gpiod_set_raw_array_value_cansleep(unsigned int array_size, struct gpio_desc **desc_array, struct gpio_array *array_info, unsigned long *value_bitmap)}hjsbah}(h]h ]h"]h$]h&]hhuh1hhhhMNhjhhubh)}(hXFThe array can be an arbitrary set of GPIOs. The functions will try to access GPIOs belonging to the same bank or chip simultaneously if supported by the corresponding chip driver. In that case a significantly improved performance can be expected. If simultaneous access is not possible the GPIOs will be accessed sequentially.h]hXFThe array can be an arbitrary set of GPIOs. The functions will try to access GPIOs belonging to the same bank or chip simultaneously if supported by the corresponding chip driver. In that case a significantly improved performance can be expected. If simultaneous access is not possible the GPIOs will be accessed sequentially.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMphjhhubh)}(h"The functions take four arguments:h]h"The functions take four arguments:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMvhjhhubh block_quote)}(hX* array_size - the number of array elements * desc_array - an array of GPIO descriptors * array_info - optional information obtained from gpiod_get_array() * value_bitmap - a bitmap to store the GPIOs' values (get) or a bitmap of values to assign to the GPIOs (set) h]j)}(hhh](j )}(h,array_size - the number of array elementsh]h)}(hjh]h,array_size - the number of array elements}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMxhjubah}(h]h ]h"]h$]h&]uh1j hjubj )}(h,desc_array - an array of GPIO descriptorsh]h)}(hjh]h,desc_array - an array of GPIO descriptors}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMyhjubah}(h]h ]h"]h$]h&]uh1j hjubj )}(hDarray_info - optional information obtained from gpiod_get_array()h]h)}(hjh]hDarray_info - optional information obtained from gpiod_get_array()}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMzhjubah}(h]h ]h"]h$]h&]uh1j hjubj )}(hmvalue_bitmap - a bitmap to store the GPIOs' values (get) or a bitmap of values to assign to the GPIOs (set) h]h)}(hlvalue_bitmap - a bitmap to store the GPIOs' values (get) or a bitmap of values to assign to the GPIOs (set)h]hnvalue_bitmap - a bitmap to store the GPIOs’ values (get) or a bitmap of values to assign to the GPIOs (set)}(hj*hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM{hj&ubah}(h]h ]h"]h$]h&]uh1j hjubeh}(h]h ]h"]h$]h&]jkjuh1jhhhMxhjubah}(h]h ]h"]h$]h&]uh1jhhhMxhjhhubh)}(hXThe descriptor array can be obtained using the gpiod_get_array() function or one of its variants. If the group of descriptors returned by that function matches the desired group of GPIOs, those GPIOs can be accessed by simply using the struct gpio_descs returned by gpiod_get_array()::h]hXThe descriptor array can be obtained using the gpiod_get_array() function or one of its variants. If the group of descriptors returned by that function matches the desired group of GPIOs, those GPIOs can be accessed by simply using the struct gpio_descs returned by gpiod_get_array():}(hjJhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM~hjhhubh)}(hstruct gpio_descs *my_gpio_descs = gpiod_get_array(...); gpiod_set_array_value(my_gpio_descs->ndescs, my_gpio_descs->desc, my_gpio_descs->info, my_gpio_value_bitmap);h]hstruct gpio_descs *my_gpio_descs = gpiod_get_array(...); gpiod_set_array_value(my_gpio_descs->ndescs, my_gpio_descs->desc, my_gpio_descs->info, my_gpio_value_bitmap);}hjXsbah}(h]h ]h"]h$]h&]hhuh1hhhhMhjhhubh)}(hXKIt is also possible to access a completely arbitrary array of descriptors. The descriptors may be obtained using any combination of gpiod_get() and gpiod_get_array(). Afterwards the array of descriptors has to be setup manually before it can be passed to one of the above functions. In that case, array_info should be set to NULL.h]hXKIt is also possible to access a completely arbitrary array of descriptors. The descriptors may be obtained using any combination of gpiod_get() and gpiod_get_array(). Afterwards the array of descriptors has to be setup manually before it can be passed to one of the above functions. In that case, array_info should be set to NULL.}(hjfhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hxNote that for optimal performance GPIOs belonging to the same chip should be contiguous within the array of descriptors.h]hxNote that for optimal performance GPIOs belonging to the same chip should be contiguous within the array of descriptors.}(hjthhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hX Still better performance may be achieved if array indexes of the descriptors match hardware pin numbers of a single chip. If an array passed to a get/set array function matches the one obtained from gpiod_get_array() and array_info associated with the array is also passed, the function may take a fast bitmap processing path, passing the value_bitmap argument directly to the respective .get/set_multiple() callback of the chip. That allows for utilization of GPIO banks as data I/O ports without much loss of performance.h]hX Still better performance may be achieved if array indexes of the descriptors match hardware pin numbers of a single chip. If an array passed to a get/set array function matches the one obtained from gpiod_get_array() and array_info associated with the array is also passed, the function may take a fast bitmap processing path, passing the value_bitmap argument directly to the respective .get/set_multiple() callback of the chip. That allows for utilization of GPIO banks as data I/O ports without much loss of performance.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hX3The return value of gpiod_get_array_value() and its variants is 0 on success or negative on error. Note the difference to gpiod_get_value(), which returns 0 or 1 on success to convey the GPIO value. With the array functions, the GPIO values are stored in value_array rather than passed back as return value.h]hX3The return value of gpiod_get_array_value() and its variants is 0 on success or negative on error. Note the difference to gpiod_get_value(), which returns 0 or 1 on success to convey the GPIO value. With the array functions, the GPIO values are stored in value_array rather than passed back as return value.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubeh}(h]1access-multiple-gpios-with-a-single-function-callah ]h"]1access multiple gpios with a single function callah$]h&]uh1hhjhhhhhMKubh)}(hhh](h)}(hGPIOs mapped to IRQsh]hGPIOs mapped to IRQs}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhMubh)}(hGPIO lines can quite often be used as IRQs. You can get the IRQ number corresponding to a given GPIO using the following call::h]h~GPIO lines can quite often be used as IRQs. You can get the IRQ number corresponding to a given GPIO using the following call:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(h.int gpiod_to_irq(const struct gpio_desc *desc)h]h.int gpiod_to_irq(const struct gpio_desc *desc)}hjsbah}(h]h ]h"]h$]h&]hhuh1hhhhMhjhhubh)}(hXkIt will return an IRQ number, or a negative errno code if the mapping can't be done (most likely because that particular GPIO cannot be used as IRQ). It is an unchecked error to use a GPIO that wasn't set up as an input using gpiod_direction_input(), or to use an IRQ number that didn't originally come from gpiod_to_irq(). gpiod_to_irq() is not allowed to sleep.h]hXqIt will return an IRQ number, or a negative errno code if the mapping can’t be done (most likely because that particular GPIO cannot be used as IRQ). It is an unchecked error to use a GPIO that wasn’t set up as an input using gpiod_direction_input(), or to use an IRQ number that didn’t originally come from gpiod_to_irq(). gpiod_to_irq() is not allowed to sleep.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hXDNon-error values returned from gpiod_to_irq() can be passed to request_irq() or free_irq(). They will often be stored into IRQ resources for platform devices, by the board-specific initialization code. Note that IRQ trigger options are part of the IRQ interface, e.g. IRQF_TRIGGER_FALLING, as are system wakeup capabilities.h]hXDNon-error values returned from gpiod_to_irq() can be passed to request_irq() or free_irq(). They will often be stored into IRQ resources for platform devices, by the board-specific initialization code. Note that IRQ trigger options are part of the IRQ interface, e.g. IRQF_TRIGGER_FALLING, as are system wakeup capabilities.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubeh}(h]gpios-mapped-to-irqsah ]h"]gpios mapped to irqsah$]h&]uh1hhjhhhhhMubeh}(h] using-gpiosah ]h"] using gpiosah$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(hGPIOs and ACPIh]hGPIOs and ACPI}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhMubh)}(hOn ACPI systems, GPIOs are described by GpioIo()/GpioInt() resources listed by the _CRS configuration objects of devices. Those resources do not provide connection IDs (names) for GPIOs, so it is necessary to use an additional mechanism for this purpose.h]hOn ACPI systems, GPIOs are described by GpioIo()/GpioInt() resources listed by the _CRS configuration objects of devices. Those resources do not provide connection IDs (names) for GPIOs, so it is necessary to use an additional mechanism for this purpose.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hXSystems compliant with ACPI 5.1 or newer may provide a _DSD configuration object which, among other things, may be used to provide connection IDs for specific GPIOs described by the GpioIo()/GpioInt() resources in _CRS. If that is the case, it will be handled by the GPIO subsystem automatically. However, if the _DSD is not present, the mappings between GpioIo()/GpioInt() resources and GPIO connection IDs need to be provided by device drivers.h]hXSystems compliant with ACPI 5.1 or newer may provide a _DSD configuration object which, among other things, may be used to provide connection IDs for specific GPIOs described by the GpioIo()/GpioInt() resources in _CRS. If that is the case, it will be handled by the GPIO subsystem automatically. However, if the _DSD is not present, the mappings between GpioIo()/GpioInt() resources and GPIO connection IDs need to be provided by device drivers.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hJFor details refer to Documentation/firmware-guide/acpi/gpio-properties.rsth]hJFor details refer to Documentation/firmware-guide/acpi/gpio-properties.rst}(hj,hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubeh}(h]gpios-and-acpiah ]h"]gpios and acpiah$]h&]uh1hhhhhhhhMubh)}(hhh](h)}(h*Interacting With the Legacy GPIO Subsystemh]h*Interacting With the Legacy GPIO Subsystem}(hjEhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjBhhhhhMubh)}(hXGMany kernel subsystems and drivers still handle GPIOs using the legacy integer-based interface. It is strongly recommended to update these to the new gpiod interface. For cases where both interfaces need to be used, the following two functions allow to convert a GPIO descriptor into the GPIO integer namespace and vice-versa::h]hXFMany kernel subsystems and drivers still handle GPIOs using the legacy integer-based interface. It is strongly recommended to update these to the new gpiod interface. For cases where both interfaces need to be used, the following two functions allow to convert a GPIO descriptor into the GPIO integer namespace and vice-versa:}(hjShhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjBhhubh)}(h\int desc_to_gpio(const struct gpio_desc *desc) struct gpio_desc *gpio_to_desc(unsigned gpio)h]h\int desc_to_gpio(const struct gpio_desc *desc) struct gpio_desc *gpio_to_desc(unsigned gpio)}hjasbah}(h]h ]h"]h$]h&]hhuh1hhhhMhjBhhubh)}(hXThe GPIO number returned by desc_to_gpio() can safely be used as a parameter of the gpio\_*() functions for as long as the GPIO descriptor `desc` is not freed. All the same, a GPIO number passed to gpio_to_desc() must first be properly acquired using e.g. gpio_request_one(), and the returned GPIO descriptor is only considered valid until that GPIO number is released using gpio_free().h](hThe GPIO number returned by desc_to_gpio() can safely be used as a parameter of the gpio_*() functions for as long as the GPIO descriptor }(hjohhhNhNubhtitle_reference)}(h`desc`h]hdesc}(hjyhhhNhNubah}(h]h ]h"]h$]h&]uh1jwhjoubh is not freed. All the same, a GPIO number passed to gpio_to_desc() must first be properly acquired using e.g. gpio_request_one(), and the returned GPIO descriptor is only considered valid until that GPIO number is released using gpio_free().}(hjohhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjBhhubh)}(hZFreeing a GPIO obtained by one API with the other API is forbidden and an unchecked error.h]hZFreeing a GPIO obtained by one API with the other API is forbidden and an unchecked error.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjBhhubeh}(h]*interacting-with-the-legacy-gpio-subsystemah ]h"]*interacting with the legacy gpio subsystemah$]h&]uh1hhhhhhhhMubeh}(h]"gpio-descriptor-consumer-interfaceah ]h"]"gpio descriptor consumer interfaceah$]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}j]j|asnameids}(jjjjjjjjjjjjjjjjjjjjjjjjj?j<jju nametypes}(jjjjjjjjjjjjj?juh}(jhjhjjjjjjjjjjjjjjjj"jjjjj<jjjBu 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]hsystem_message)}(hhh]h)}(hhh]h:Hyperlink target "active-low-semantics" is not referenced.}hj< sbah}(h]h ]h"]h$]h&]uh1hhj9 ubah}(h]h ]h"]h$]h&]levelKtypeINFOsourcehlineMuh1j7 uba transformerN include_log] decorationNhhub.