gpiod-在devicetree中使用标签 [英] gpiod - use labels in devicetree
问题描述
我想使用 libgpiod
通过自定义板上的用户空间来控制一些GPIO.我有一个i.MX6UL处理器,它具有数百个引脚,我将仅使用其中的8个引脚(作为GPIO).
I want to use libgpiod
to control a few GPIOs via userspace on a custom board. I have an i.MX6UL processor, which has hundreds of pins, I'll use only 8 of them (as GPIOs).
我读到有关 libgpiod
的信息,因为它正在替换旧的sysfs API,并且很高兴您可以为每个GPIO指定标签.处理器的GPIO块类似于以下代码块,并且已经设置了 gpio-controller
属性.(摘自Linux内核v4.14)
I read about the libgpiod
as it is replacing the old sysfs API, and I'm happy that you can specify labels for each GPIO. The GPIO block of the processor looks like the following code block and has already the gpio-controller
property set. (Taken from Linux kernel v4.14)
gpio2: gpio@20a0000 {
compatible = "fsl,imx6ul-gpio", "fsl,imx35-gpio";
reg = <0x020a0000 0x4000>;
interrupts = <GIC_SPI 68 IRQ_TYPE_LEVEL_HIGH>,
<GIC_SPI 69 IRQ_TYPE_LEVEL_HIGH>;
gpio-controller;
#gpio-cells = <2>;
interrupt-controller;
#interrupt-cells = <2>;
gpio-ranges = <&iomuxc 0 49 16>, <&iomuxc 16 111 6>;
};
我想使用该控制器的单个引脚,因此添加了以下代码块:
I want to use a single pin of this controller, so I added the following block:
&gpio2 {
resetl0 {
//gpio-hog;
output-high;
line-name = "COBO0_ResetL";
gpios = <15 1>;
};
};
如果没有 gpio-hog
属性, gpioinfo
工具将无法显示标签,如果我省略了output-high/low.使用该属性,可以正确显示标签,但是gpio被标记为 used
,因此我无法从用户空间进行控制.(设备或资源繁忙)
Without the gpio-hog
property, the gpioinfo
tool is unable to show me the labels, same if I omit the output-high/low. With the property, the label is correctly displayed, but the gpio is marked as used
, so I cannot control from userspace. (Device or resource busy)
简而言之:我需要一种在设备树中设置标签的方法,可以从用户空间读取标签并控制gpios.我已经在RPi设备树中看到 gpio-line-names
,但是当只使用一个库时,我不想将整个库指定为NC. libgpiod
是否可以?怎么样?
So in short:
I need a way to set a label in device tree, which I'm able to read from userspace and to control the gpios. I already saw the gpio-line-names
in the RPi devicetree, but I don't want to specify the whole bank as NC, when using only one. Is it possible with libgpiod
? How?
推荐答案
我在Odroid-N2内核v5.4上进行了测试.
I tested on Odroid-N2 kernel v5.4.
meson-g12b-odroid-n2.dts
meson-g12b-odroid-n2.dts
&gpio {
gpio-line-names =
/* GPIOZ */
"", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "",
/* GPIOH */
"", "", "", "", "", "", "", "",
"",
/* BOOT */
"", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "",
/* GPIOC */
"", "", "", "", "", "", "", "",
/* GPIOA */
"44", "46", "45", "47",
"26", "", "", "",
"", "", "", "42",
"32", "7", "27", "28",
/* GPIOX */
"16", "18", "22", "11",
"13", "33", "35", "15",
"19", "21", "24", "23",
"8", "0", "29", "31",
"12", "3", "5", "36";
usb-hub {
gpio-hog;
gpios = <GPIOH_4 GPIO_ACTIVE_HIGH>;
output-high;
line-name = "usb-hub-reset";
};
};
gpioinfo
gpiochip0 - 85 lines:
...
line 20: unnamed "usb-hub-reset" input active-high [used]
...
line 49: "44" unused input active-high
line 50: "46" unused input active-high
line 51: "45" unused input active-high
line 52: "47" unused input active-high
line 53: "26" unused input active-high
...
line 60: "42" unused input active-high
line 61: "32" unused input active-high
line 62: "7" unused input active-high
line 63: "27" unused input active-high
line 64: "28" unused input active-high
line 65: "16" unused input active-high
line 66: "18" unused input active-high
line 67: "22" unused input active-high
line 68: "11" unused input active-high
line 69: "13" unused input active-high
line 70: "33" unused input active-high
line 71: "35" unused input active-high
line 72: "15" unused input active-high
line 73: "19" unused input active-high
line 74: "21" unused input active-high
line 75: "24" unused input active-high
line 76: "23" unused input active-high
line 77: "8" unused input active-high
line 78: "0" unused input active-high
line 79: "29" unused input active-high
line 80: "31" unused input active-high
line 81: "12" unused input active-high
line 82: "3" unused input active-high
line 83: "5" unused input active-high
line 84: "36" unused input active-high
...
gpioinfo
将"gpio-line-names"显示为名称,将"line-name"显示为使用者.
gpioinfo
displayed 'gpio-line-names' as a name and 'line-name' as a consumer.
这篇关于gpiod-在devicetree中使用标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!