在软件上,我们首先通过函数gpiochip_add注册一个gpio_chip对应的gpio_desc到全局数组gpio描述符中。其中,一个描述符对应一个GPIO,所以如果我们要使用多个GPIO,那么就在gpio_chip结构体的ngpio指定个数,base为起始的GPIO号。 //每个引脚分配一个gpio_desc数据结构structgpio_desc {structgpio_chip *chip; unsignedlon...
struct gpio_chip struct gpio_device struct gpio_desc 相关初始化流程 数据结构关系图 总结 在linux内核中GPIO的控制是一个相对独立的子模块,纵然硬件决定着他和PINCTRL有着千丝万缕的关系,但内核还是把他和PINCTRL分开来。PINCTRL就像是一个顾全大局的大哥,把驱动所需要的gpio的状态抽象为一个个state结合PM等其他内...
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)1...
struct gpio_device { //它是系统中第几个GPIO控制器 int id; struct device dev; struct cdev chrdev; struct device *mockdev; struct module *owner; //含有各类操作函数 struct gpio_chip *chip; //每一个gpio引脚用一个gpio_desc来表示 struct gpio_desc *descs; //这些GPIO的号码基值 int base; ...
pinctrl 子系统和 gpio 子系统虽然难度不大,但在内核里的使用率非常高,本文争取一次性把相关内容介绍一遍。 pinctrl 数据结构 使用struct pinctrl_desc 抽象一个 pin controller,该结构的定义如下: struct pinctrl_desc { const char *name; const struct pinctrl_pin_desc *pins; ...
struct gpio_descs { unsigned int ndescs; struct gpio_desc *desc[]; } 一个GPIO描述符可以使用如下函数释放: void gpiod_put(struct gpio_desc *desc) void gpiod_put_array(struct gpio_descs *descs) 需要注意GPIO描述符被释放后不可再使用,而且不允许使用第一个函数来释放通过序列获取得到GPIO描述...
https://www.kernel.org/doc/Documentation/gpio/consumer.txt #头文件 我们需要包含头文件 #include <linux/gpio/consumer.h> 1. 看头文件里面包含的函数列表 desc_to_gpio devm_get_gpiod_from_chi devm_gpiod_get devm_gpiod_get_array devm_gpiod_get_array_op ...
struct gpio_descs {unsigned int ndescs;struct gpio_desc *desc[];} 一个GPIO描述符可以使用如下函数释放: void gpiod_put(struct gpio_desc *desc)void gpiod_put_array(struct gpio_descs *descs) 需要注意GPIO描述符被释放后不可再使用,而且不允许使用第一个函数来释放通过序列获取得到GPIO描述符。
structgroup_desc{constchar*name;int*pins;intnum_pins;void*data;}; 1.2.GPIO子系统¶ 在pinctrl子系统中把pin脚初始化成了普通GPIO后,就可以使用GPIO子系统的接口去操作IO口的电平、中断等。驱动开发者在设备树中添加gpio相关信息, 然后就可以在驱动程序中使用gpio子系统提供的API函数来操作GPIO,极大的方便了...
在gpio 子系统中,用 struct gpio_desc 来描述一个 gpio 引脚,gpiod_xxx() 都是围绕着 strcut gpio_desc 进行操作的。 完整的接口定义位于 linux/gpio/consumer.h,大约共有 70个 API。 常用API: 获得/释放 一个或者一组 gpio: [devm]_gpiod_get*() [devm]_gpiod_put*() 设置/查询 输入或者输出 gpi...