问题描述
调用gpio_request函数申请gpio,但是返回-22,一共遇到过两次,因此记录一下。
原因分析:
错误返回值定义文件为errno-base.h
其中22定义如下
#define EINVAL 22 /* Invalid argument */
表示参数无效,
我申请的gpio为9,编号为921,申请gpio8都可以,为什么9不行,设备树也没有发现其他模块使用该gpio。
最后一路追源码才发现,
在路径HLOS/kernel/xxx/drivers/pinctrl/qcom/pinctrl-xxx.c
中,存在一个变量
static const int xxx_reserved_gpios[] = {
0, 1, 2, 3, 9, -1
};
这个将里边写到的io口都作为了保留,gpio_request无法进行申请。
解决方案:
将xxx_reserved_gpios数组里的要用到的io口删掉就好了。
static const int xxx_reserved_gpios[] = {
0, 1, 2, 3, -1
};