Linux 内核中的 gpiod_* 与 gpio_* 方法

gpiod_* vs gpio_* methods in the Linux Kernel

Linux 设备驱动程序编程中哪个 GPIO API 更可取,在什么条件下:gpio_set_value()gpiod_set_value()

一个以GPIO desc为对象,另一个以设备树解析出的GPIO为对象

对于所有新驱动程序,建议使用 gpiod_* API。旧 gpio_* API 现在已被弃用。

来自 this 提交:

gpiolib: export descriptor-based GPIO interface

This patch exports the gpiod_* family of API functions, a safer alternative to the legacy GPIO interface. Differences between the gpiod and legacy gpio APIs are:

  • gpio works with integers, whereas gpiod operates on opaque handlers which cannot be forged or used before proper acquisition
  • gpiod get/set functions are aware of the active low state of a GPIO
  • gpio consumers should now include <linux/gpio/consumer.h> to access the new interface, whereas chips drivers will use <linux/gpio/driver.h>

The legacy gpio API is now built as inline functions on top of gpiod.

有关新 gpiod 的详细信息,请参阅下一个链接 API: