1. xxx.dts 中有如下驅動的資源描述:
1 imx6-led{ 2 compatible = "imx6,led"; 3 led-green = <&gpio1 8 GPIO_ACTIVE_LOW>; 4 status = "okay"; 5 };
GPIO_ACTIVE_LOW 表示低電平,與之相反的是GPIO_ACTIVE_HIGH 。
2. 獲取第三個參數的代碼如下:
1 #include <linux/of.h> 2 #include <linux/of_gpio.h> 3
4
5 6 static int imx6_led_probe(struct platform_device *pdev) 7 { int gpio, flag; 8 struct device_node *led_node = pdev->dev.of_node; 9 10 gpio = of_get_named_gpio_flags(led_node, "led-green", 0, &flag); 11 if (!gpio_is_valid(gpio)){ 12 printk("invalid led-green: %d\n",gpio); 13 return -1; 14 } 15 if (gpio_request(gpio, "led_green")) { 16 printk("gpio %d request failed!\n",gpio); 17 return ret; 18 } 19 gpio_direction_output(gpio, flag);//flag 即第三個參數“GPIO_ACTIVE_LOW” 20 ////////xxxxxxxxxx
21 ////////xxxxxxxxxx
22 23 }
of_get_named_gpio_flags 從設備樹中讀取 led-green 的 GPIO 配置編號和標志,
標致即第三個參數“GPIO_ACTIVE_LOW”