zoukankan      html  css  js  c++  java
  • [gpio]devm_gpiod_get_optional用法

    转自:https://blog.csdn.net/kris_fei/article/details/78932904

    latform: RK3399 
    OS: Android 7.1 
    Board: Firefly-RK3399

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

    devm_gpiod_get_optional -> 
     devm_gpiod_get_index_optional -> //index为0 
      devm_gpiod_get_index -> 
       gpiod_get_index

    可以看到devm_gpiod_get_optional只是对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的名字。

    例如在显示驱动看到的去查找名字为”enable”的gpio
    panel-simple.c:

    panel->enable_gpio = devm_gpiod_get_optional(dev, "enable", 0);

    在使用mipi屏幕的主dts就有enable pin的定义
    rk3399-firefly-mipi.dts:

    enable-gpios = <&gpio1 1 GPIO_ACTIVE_HIGH>;

    那么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,以此类推。

  • 相关阅读:
    左划删除
    UILabel 添加图片
    Swift-11-委托模式
    Swift-11-协议(Protocols)
    Swift-10--错误处理
    Swift-09-可空链式调用(Optional Chaining)
    Swift-08-闭包引起的循环强引用
    Swift-07-析构器deinit
    Swift-06-闭包
    【转】HTML5标签使用的常见误区
  • 原文地址:https://www.cnblogs.com/aaronLinux/p/9485562.html
Copyright © 2011-2022 走看看