轉自: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,以此類推。