标签:xxxxx turn print 设备 include dts 标致 class rect
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”
标签:xxxxx turn print 设备 include dts 标致 class rect
原文地址:https://www.cnblogs.com/-tbd-/p/13130190.html