Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

gpio: Document line value semantics

It is not clearly documented that the GPIO driver API expect the
driver to get/set the physical level of the GPIO line and the
consumer API will get/set the logic level. Document this in
relevant places.

Reported-by: David Jander <david@protonic.nl>
Signed-off-by: Linus Walleij <linusw@kernel.org>
Link: https://patch.msgid.link/20260306-gpio-doc-levels-v1-1-19928739e400@kernel.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>

authored by

Linus Walleij and committed by
Bartosz Golaszewski
5645f805 3671411e

+35 -2
+27
Documentation/driver-api/gpio/driver.rst
··· 87 87 contexts). Normally this should not be required. 88 88 89 89 90 + GPIO level semantics 91 + -------------------- 92 + 93 + The gpip_chip .get/set[_multiple]() line values are clamped to the boolean 94 + space [0, 1], low level or high level. 95 + 96 + Low and high values are defined as physical low on the line in/out to the 97 + connector such as a physical pad, pin or rail. 98 + 99 + The GPIO library has internal logic to handle lines that are active low, such 100 + as indicated by overstrike or #name in a schematic, and the driver should not 101 + try to second-guess the logic value of a line. 102 + 103 + The way GPIO values are handled by the consumers is that the library present 104 + the *logical* value to the consumer. A line is *asserted* if its *logical* 105 + value is 1, and *de-asserted* if its logical value is 0. If inversion is 106 + required, this is handled by gpiolib and configured using hardware descriptions 107 + such as device tree or ACPI that can clearly indicate if a line is active 108 + high or low. 109 + 110 + Since electronics commonly insert inverters as driving stages or protection 111 + buffers in front of a GPIO line it is necessary that this semantic is part 112 + of the hardware description, so that consumers such as kernel drivers need 113 + not worry about this, and can for example assert a RESET line tied to a GPIO 114 + pin by setting it to logic 1 even if it is physically active low. 115 + 116 + 90 117 GPIO electrical configuration 91 118 ----------------------------- 92 119
+8 -2
include/linux/gpio/driver.h
··· 343 343 * @direction_output: configures signal "offset" as output, returns 0 on 344 344 * success or a negative error number. This can be omitted on input-only 345 345 * or output-only gpio chips. 346 - * @get: returns value for signal "offset", 0=low, 1=high, or negative error 346 + * @get: returns value for signal "offset", 0=low, 1=high, or negative error. 347 + * the low and high values are defined as physical low on the line 348 + * in/out to the connector such as a physical pad, pin or rail. The GPIO 349 + * library has internal logic to handle lines that are active low, such 350 + * as indicated by overstrike or #name in a schematic, and the driver 351 + * should not try to second-guess the logic value of a line. 347 352 * @get_multiple: reads values for multiple signals defined by "mask" and 348 353 * stores them in "bits", returns 0 on success or negative error 349 354 * @set: assigns output value for signal "offset", returns 0 on success or 350 - * negative error value 355 + * negative error value. The output value follows the same semantic 356 + * rules as for @get. 351 357 * @set_multiple: assigns output values for multiple signals defined by 352 358 * "mask", returns 0 on success or negative error value 353 359 * @set_config: optional hook for all kinds of settings. Uses the same