devm_gpiod_get_index用法

 

调用流程:
在看显示模块的代码时看到一个函数devm_gpiod_get_index(), 之前没接触过,它的调用如下:

  devm_gpiod_get_index -> //index为0 
   gpiod_get_index

可以看到devm_gpiod_get_index只是对gpiod_get_index的包装而已,并且index为0。index参数后面会提。

函数参数:

struct gpio_desc *__must_check devm_gpiod_get_index(struct device *dev,
const char *con_id,
unsigned int idx,
enum gpiod_flags flags);

重点关注第二个和第三个参数。

gpiod_get_index()到底用来干什么?
答:gpiod_get_index()本质上和gpio_request()是一个功能,是申请gpio的,只是它是从device tree去查找,
因此看到第二个参数”con_id”是字符串类型,也就是gpio的名字。

例如在SD卡驱动看到的去查找名字为”cd-gpios”的gpio
simple.c:

ctx->cd_gpio = devm_gpiod_get_optional(dev, "cd", 0);

在使用SD卡驱动的主dts就有cd pin的定义
xxx.dts:

    cd-gpios = <&gpio2 12 GPIO_ACTIVE_LOW>;

那么index又有什么用呢?
内核文档有个例子,比如gpio如下定义:

led-gpios = <&gpio 15 GPIO_ACTIVE_HIGH>, /* red */
<&gpio 16 GPIO_ACTIVE_HIGH>, /* green */
<&gpio 17 GPIO_ACTIVE_HIGH>; /* blue */

如果index是0,那么对应的就是gpio 15;  如果index是1,那么对应就是gpio 16,以此类推。

 

  • 0
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值