Skip to contentSkip to conversation

enlarge gpiochip label size

libgpiod Attila Hannibál 1 participant 1 message Mar 4, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

Dear Community!

We use in our product an Arria10 SoC where we place several Intel/Alter PIOs in the FPGA design. These GPIOs are accessible using the corresponding device-tree entries
...

       label: gpio@0x130 {
              compatible = "altr,pio-18.1", "altr,pio-1.0";
              reg = <0x00000130 0x00000010>;
              altr,gpio-bank-width = <2>;
              resetvalue = <0>;
              #gpio-cells = <2>;
              gpio-controller;
       };

...

We use also the libgpiod framework to control the lines.
However, there is a problem with the generated label attribute of the gpiochip.
In case the gpio-controller is instantiated via device-tree like gpio-altera.c, it calls the common of_mm_gpiochip_add_data() function which fills the label as:
...
gc->label = kasprintf(GFP_KERNEL, "%pOF", np);
...
That generates a kind of "top-down path" to the gpio-controller itself, that is usually longer than 32 characters.
As a result a simple gpiodetect call will print the following output:
...
gpiochip0 [/soc/bridge@0xc0000000/gpio@0x1] (32 lines)
gpiochip1 [/soc/bridge@0xc0000000/gpio@0x1] (32 lines)
gpiochip10 [/soc/bridge@0xc0000000/gpio@0x1] (32 lines)
gpiochip11 [/soc/bridge@0xc0000000/gpio@0x1] (32 lines)
gpiochip12 [/soc/bridge@0xc0000000/gpio@0x1] (32 lines)
gpiochip13 [/soc/bridge@0xc0000000/gpio@0x1] (32 lines)
gpiochip14 [ffc02900.gpio] (29 lines)
gpiochip2 [/soc/bridge@0xc0000000/gpio@0x1] (32 lines)
gpiochip3 [/soc/bridge@0xc0000000/gpio@0x1] (32 lines)
gpiochip4 [/soc/bridge@0xc0000000/gpio@0x1] (32 lines)
gpiochip5 [/soc/bridge@0xc0000000/gpio@0x1] (32 lines)
gpiochip6 [/soc/bridge@0xc0000000/gpio@0x1] (32 lines)
gpiochip7 [/soc/bridge@0xc0000000/gpio@0x1] (32 lines)
gpiochip8 [/soc/bridge@0xc0000000/gpio@0x1] (32 lines)
gpiochip9 [/soc/bridge@0xc0000000/gpio@0x1] (32 lines)
...
As you can see - due to missing endings - it is almost impossible to determine which gpiochipX is which entry in the device-tree.

The 32 character wide limitation are defined in two places: one in the kernel UAPI header file and one in the core.c file of the libgpiod library. Since this information is passed through the ioctl interface both occurrences must be changed at the same time.
I'm attaching the corresponding 2 patch files.
After the modification the gpiodetect prints the labels (paths) correctly:
...
gpiochip0 [/soc/bridge@0xc0000000/bridge@0x001000000/gpio@0xa0] (32 lines)
gpiochip1 [/soc/bridge@0xc0000000/bridge@0x001000000/gpio@0xb0] (32 lines)
gpiochip10 [/soc/bridge@0xc0000000/bridge@0x001000000/gpio@0x190] (32 lines)
gpiochip11 [/soc/bridge@0xc0000000/bridge@0x001000000/gpio@0x1a0] (32 lines)
gpiochip12 [/soc/bridge@0xc0000000/bridge@0x001000000/gpio@0x1b0] (32 lines)
gpiochip13 [/soc/bridge@0xc0000000/bridge@0x001000000/gpio@0x280] (32 lines)
gpiochip14 [ffc02900.gpio] (29 lines)
gpiochip2 [/soc/bridge@0xc0000000/bridge@0x001000000/gpio@0xc0] (32 lines)
gpiochip3 [/soc/bridge@0xc0000000/bridge@0x001000000/gpio@0xd0] (32 lines)
gpiochip4 [/soc/bridge@0xc0000000/bridge@0x001000000/gpio@0x130] (32 lines)
gpiochip5 [/soc/bridge@0xc0000000/bridge@0x001000000/gpio@0x120] (32 lines)
gpiochip6 [/soc/bridge@0xc0000000/bridge@0x001000000/gpio@0x170] (32 lines)
gpiochip7 [/soc/bridge@0xc0000000/bridge@0x001000000/gpio@0x160] (32 lines)
gpiochip8 [/soc/bridge@0xc0000000/bridge@0x001000000/gpio@0x150] (32 lines)
gpiochip9 [/soc/bridge@0xc0000000/bridge@0x001000000/gpio@0x180] (32 lines)
...

Do you think that it is worth to add to the mainline source code?

Best regards
Attila

__________________________________________________
Attila Hannibál
Lead Software Engineer
Electronics and Embedded Systems

HEITEC Hungary Kft.
Kaposvár utca 14-18
H-1117 Budapest

Phone: +36 1 551 5153
Fax:     +36 1 551 5279
E-Mail:   mailto:[email protected]
Internet: https://www.heitec.hu

________________________________
IMPORTANT NOTICE / WICHTIGER HINWEIS
This communication contains information which is confidential and may also be privileged. It is for the exclusive use of the intended recipient(s). If you are not the intended recipient(s) please note that any distribution, copying or use of this communication or the information in it is strictly prohibited. If you have received this communication in error please notify us immediately by email or by telephone and then delete this email and any copies of it. Diese E-Mail koennte vertrauliche und/oder rechtlich geschuetzte Informationen enthalten. Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtuemlich erhalten haben, informieren Sie bitte sofort den Absender und vernichten Sie diese Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser Mail sind nicht gestattet.

Ez az email bizalmas és/vagy jog által védett információkat tartalmazhat. Amennyiben nem Ön az üzenet címzettje vagy tévedésbol kapta meg, kérjük informálja errol a feladót és törölje ezt az üzenetet. Az üzenetet engedély nélkül nem másolható vagy továbbítható.
________________________________

From 66c7df26cbd0e141e5fdacffce1215373a1c5022 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Attila=20Hannib=C3=A1l?= <[email protected]>
Date: Thu, 3 Mar 2022 11:07:57 +0000
Subject: [PATCH] label size increased

---
 include/uapi/linux/gpio.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/uapi/linux/gpio.h +1 -1
index 4ebfe0ac6c5b..da7a1b81d3e1 100644
@@ -23,7 +23,7 @@
  */
 struct gpiochip_info {
 	char name[32];
-	char label[32];
+	char label[64];
 	__u32 lines;
 };
 

From 5ca7d46a2546e0fb0ea23c1cfa15472c8638e832 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Attila=20Hannib=C3=A1l?= <[email protected]>
Date: Thu, 3 Mar 2022 13:06:09 +0100
Subject: [PATCH] label size increased

---
 lib/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/core.c +1 -1
index 05e5a46..07721a3 100644
@@ -57,7 +57,7 @@ struct gpiod_chip {
 	int fd;
 
 	char name[32];
-	char label[32];
+	char label[64];
 };
 
 static bool is_gpiochip_cdev(const char *path)