rogerjames99
Posts: 43
Joined: Fri Sep 28, 2012 2:58 pm

Problem with gpio-hog

Mon Dec 30, 2019 3:05 am

Hi,

I am trying to gpio-hog using the following overlay.

Code: Select all

// Overlay for rp41 module
/dts-v1/;
/plugin/;

/{
	compatible = "brcm,bcm2708";

	[email protected] {
		target = <&gpio>;
		__overlay__ {
                    selectEnable-line {
                    gpio-hog;
                    gpios = <2 0>;
                    output-low;
                    line-name = "selectEnable"
                    };
	       };
        };
};
This gives rise to errors like this.

Code: Select all

[    4.613928] requesting hog GPIO selectEnable (chip pinctrl-bcm2835, offset 2) failed, -517
I understand that this is caused by the pinctrl node having no valid gpio-ranges entry.

I recollect seeing an example that did have some pinctrl stuff in the overlay, but I cannot find it.

Any guidance on how to fix/work around this would be appreciated.

Roger.

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 2589
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Problem with gpio-hog

Mon Jan 06, 2020 2:48 pm

Apart from a missing semicolon after the "line-name" property, your overlay looks good. The problem is caused by the sequence of operations in the BCM2835's combined pinctrl and gpio driver.

Currently the driver creates and registers the GPIO half of the driver before the pinctrl side, but this fails with a GPIO hog. GPIO chips are registered with "gpiochip_add_data" which doesn't return until after hog processing, but requesting a hog results in a pinctrl operation that fails because the driver hasn't got round to registering the pinctrl driver yet.

I've created a Pull Request to the kernel that seems to fix this - if you are up to building your own kernel you can find my patch here: https://github.com/raspberrypi/linux/pull/3394

rogerjames99
Posts: 43
Joined: Fri Sep 28, 2012 2:58 pm

Re: Problem with gpio-hog

Mon Jan 06, 2020 8:10 pm

Thanks Phil,

Sorry about the missing semicolons. I had not realised I had posted a slightly out of date version of the file. Thanks for the pointer to the kernel patch.

I might not bother with hogs in the long run, as I am working on an embedded system with only one process accessing the gpio.

I am struggling to understand the pinctrl bunding stuff. I wonder if you could point me at the simplest way to establish pin direction and state, along with a pin name at early boot time. That would be very helpful. I am trying to put as much I can into device tree data and not hardcoded into a program.

Roger

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 2589
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Problem with gpio-hog

Mon Jan 06, 2020 8:21 pm

Have you tried the config.txt gpio setting?

rogerjames99
Posts: 43
Joined: Fri Sep 28, 2012 2:58 pm

Re: Problem with gpio-hog

Wed Jan 08, 2020 5:27 pm

I tried the config.,txt setting. But once again cannot get things to work. Here is what I put at the end of config.txt.

Code: Select all

[all]
#dtoverlay=vc4-fkms-v3d
gpio=2-13=op,dl
gpio=16=op,dl
gpio=17=ip
gpio=18-27=op,dl
This is what gpioinfo shows.

Code: Select all

gpiochip0 - 54 lines:
	line   0:      unnamed       unused   input  active-high 
	line   1:      unnamed       unused   input  active-high 
	line   2:      unnamed       unused   input  active-high 
	line   3:      unnamed       unused   input  active-high 
	line   4:      unnamed       unused   input  active-high 
	line   5:      unnamed       unused   input  active-high 
	line   6:      unnamed       unused   input  active-high 
	line   7:      unnamed       unused   input  active-high 
	line   8:      unnamed       unused   input  active-high 
	line   9:      unnamed       unused   input  active-high 
	line  10:      unnamed       unused   input  active-high 
	line  11:      unnamed       unused   input  active-high 
	line  12:      unnamed       unused   input  active-high 
	line  13:      unnamed       unused   input  active-high 
	line  14:      unnamed       unused   input  active-high 
	line  15:      unnamed       unused   input  active-high 
	line  16:      unnamed       unused   input  active-high 
	line  17:      unnamed       unused   input  active-high 
	line  18:      unnamed       unused   input  active-high 
	line  19:      unnamed       unused   input  active-high 
	line  20:      unnamed       unused   input  active-high 
	line  21:      unnamed       unused   input  active-high 
	line  22:      unnamed       unused   input  active-high 
	line  23:      unnamed       unused   input  active-high 
	line  24:      unnamed       unused   input  active-high 
	line  25:      unnamed       unused   input  active-high 
	line  26:      unnamed       unused   input  active-high 
	line  27:      unnamed       unused   input  active-high 
	line  28:      unnamed       unused   input  active-high 
	line  29:      unnamed       unused   input  active-high 
	line  30:      unnamed       unused   input  active-high 
	line  31:      unnamed       unused   input  active-high 
	line  32:      unnamed       unused   input  active-high 
	line  33:      unnamed       unused   input  active-high 
	line  34:      unnamed       unused   input  active-high 
	line  35:      unnamed       unused   input  active-high 
	line  36:      unnamed       unused   input  active-high 
	line  37:      unnamed       unused   input  active-high 
	line  38:      unnamed       unused   input  active-high 
	line  39:      unnamed       unused   input  active-high 
	line  40:      unnamed       unused   input  active-high 
	line  41:      unnamed       unused   input  active-high 
	line  42:      unnamed       "led0"  output  active-high [used]
	line  43:      unnamed       unused   input  active-high 
	line  44:      unnamed       unused   input  active-high 
	line  45:      unnamed       unused   input  active-high 
	line  46:      unnamed       unused   input  active-high 
	line  47:      unnamed       unused   input  active-high 
	line  48:      unnamed       unused   input  active-high 
	line  49:      unnamed       unused   input  active-high 
	line  50:      unnamed       unused   input  active-high 
	line  51:      unnamed       unused   input  active-high 
	line  52:      unnamed       unused   input  active-high 
	line  53:      unnamed       unused   input  active-high 
Am I wrong to assume that the settings of the lines to output would show up in gpioinfo?

I did this with a fresh copy of buster-lite with no changes made apart from the lines added to config.txt.

Roger

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 2589
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Problem with gpio-hog

Wed Jan 08, 2020 5:32 pm

raspi-gpio gives a more accurate picture of the current GPIO state. gpioinfo shows what Linux thinks it is set to, but since it doesn't read back the start-of-day state anything changed via dt-blob or config.txt won't show up.

rogerjames99
Posts: 43
Joined: Fri Sep 28, 2012 2:58 pm

Re: Problem with gpio-hog

Wed Jan 08, 2020 5:51 pm

Thanks Phil,

I was wondering if that was the case.

Maybe my device tree approach had been working in the end :-)
Roger

rogerjames99
Posts: 43
Joined: Fri Sep 28, 2012 2:58 pm

Re: Problem with gpio-hog

Wed Jan 08, 2020 9:41 pm

Phil ,

The config.txt approach isa working OK.
However I am not going to let this device tree stuff defeat me!

I tried my latest version of the overlay and it did not work. Any chance you can have a quick look at it and telll me what I am doing wrong.

Code: Select all

// Overlay for rp41 gpio line names
/dts-v1/;
/plugin/;

/{
    compatible = "brcm,bcm2708",
                 "brcm,bcm2710",
                 "brcm,bcm2711";
    [email protected] {
        target = <&gpio>;
        __overlay__ {
            gpio-line-names = 
                "",
                "",
                "SelectEnable",
                "Select1",
                "Select2",
                "Select4",
                "Select8",
                "Select16",
                "Select32",
                "Drive12V",
                "VoltsPotSelect",
                "Data",
                "Clock",
                "CurrentPotSelect",
                "",
                "",
                "SwitchClk",
                "Volts230",
                "PotSDI",
                "PotSCK",
                "DB0",
                "DB1",
                "DB2",
                "DB3",
                "DB4",
                "DB5",
                "DB6",
                "DB7",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "";
            rp41_gpio: rp41_gpio {
                brcm,pins =     <2 3 4 5 6 7 8 9 10 11 12 13 16 17 18 19 20 21 22 23 24 25 26 27>;
                brcm,function = <0 0 0 0 0 0 0 0 0  0  0  0  0  1  0  0  0  0  0  0  0  0  0  0>; 
            };
        };
    };
    [email protected] {
        target-path = "/";
        __overlay__ {
            rp41_pins: rp41_pins {
                pinctrl-names = "default";
                pinctrl-0 = <&rp41_gpio>;
                rp41-gpios =
                            <&gpio 0x2 0>,
                            <&gpio 0x3 0>,
                            <&gpio 0x4 0>,
                            <&gpio 0x5 0>,
                            <&gpio 0x6 0>,
                            <&gpio 0x7 0>,
                            <&gpio 0x8 0>,
                            <&gpio 0x9 0>,
                            <&gpio 0x10 0>,
                            <&gpio 0x11 0>,
                            <&gpio 0x12 0>,
                            <&gpio 0x13 0>,
                            <&gpio 0x16 0>,
                            <&gpio 0x17 1>,
                            <&gpio 0x18 0>,
                            <&gpio 0x19 0>,
                            <&gpio 0x20 0>,
                            <&gpio 0x21 0>,
                            <&gpio 0x22 0>,
                            <&gpio 0x23 0>,
                            <&gpio 0x24 0>,
                            <&gpio 0x25 0>,
                            <&gpio 0x26 0>,
                            <&gpio 0x27 0>;
            };
        };
    };
};
Cheers,
Roger

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 2589
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Problem with gpio-hog

Wed Jan 08, 2020 9:52 pm

Your new DT node (rp41_pins) has no compatible string - without one it will be ignored. pinctrl claims and configures pins on behalf of a driver, but releases them if the driver doesn't initialise (probe) correctly.

rogerjames99
Posts: 43
Joined: Fri Sep 28, 2012 2:58 pm

Re: Problem with gpio-hog

Wed Jan 08, 2020 11:07 pm

Hi Phil,

Do you monitor this 24/7 ;)

I am sat in the pub replying to it.

I had found a presentation online that said that provided the node was a direct child of root then a platform device node would be created. But also found another reference that said "use the &leds node to hang your pinctrl node off, because it is convenient and does not already have one".

I am stuck in a "maze of twisty passages all alike". I think I will have a few more pints!

Roger

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 2589
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Problem with gpio-hog

Thu Jan 09, 2020 1:09 pm

We need an active driver to hang pinctrl requests on, preferably one which doesn't already use pinctrl. In the absence of a driver specific to your application, the gpio-leds driver is a suitable candidate (but be aware that other overlays may try the same trick). The vga666 overlay is an example of the technique being used:

Code: Select all

...
	[email protected] {
		target = <&leds>;
		__overlay__ {
			pinctrl-names = "default";
			pinctrl-0 = <&vga666_pins>;
		};
	};
...
By the way, the compatible string used at the start of an overlay isn't currently used by the firmware or the kernel, but I'm trying to standardise on "brcm,bcm2835" for most overlays, and "brcm,bcm2711" for those that are specific to the extra features in a Pi 4. As well as being tidier, it helps automated tests to know which base DTBs an overlay should be applicable to.

rogerjames99
Posts: 43
Joined: Fri Sep 28, 2012 2:58 pm

Re: Problem with gpio-hog

Thu Jan 09, 2020 1:33 pm

Thanks Phil for your excellent concise reply.

I will use the leds node approach for the time being. In the future I might make a dummy driver module so that I can have a "rp41" node of my own to hang the pinctrl off, just for neatness and avoiding future conflicts. Things have certainly changed somewhat since I wrote my first Unix device driver way back in the 1970s.

Roger

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 2589
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Problem with gpio-hog

Thu Jan 09, 2020 1:37 pm

Things have certainly changed somewhat since I wrote my first Unix device driver way back in the 1970s.
Wow - you must be even older than I am. Or a very precocious young coder. ;)

rogerjames99
Posts: 43
Joined: Fri Sep 28, 2012 2:58 pm

Re: Problem with gpio-hog

Thu Jan 09, 2020 2:00 pm

Nearer to 70 than 60 (well only just). Started in the industry 1972 working at place in Belgravia (SIA) that had a nice CDC6600 for me to play with. Ended up running my own software company (Boldon James) with my business partner Pete. Sold that in 1999. Been trying to fully retire ever since. :D

This is going seriously OT ;)

Roger

rogerjames99
Posts: 43
Joined: Fri Sep 28, 2012 2:58 pm

Re: Problem with gpio-hog

Thu Jan 09, 2020 3:40 pm

This needs a younger brain. My apologies for being such a dumbo.

Here is my latest try.

Code: Select all

// Overlay for rp41 gpio line names
/dts-v1/;
/plugin/;

/{
    compatible = "brcm,bcm2835";
    [email protected] {
        target = <&leds>;
        __overlay__ {
            rp41_pins: rp41_pins {
                pinctrl-names = "default";
                pinctrl-0 = <&rp41_gpio>;
            };
        };
    };
    [email protected] {
        target = <&gpio>;
        __overlay__ {
            gpio-line-names = 
                "",
                "",
                "SelectEnable",
                "Select1",
                "Select2",
                "Select4",
                "Select8",
                "Select16",
                "Select32",
                "Drive12V",
                "VoltsPotSelect",
                "Data",
                "Clock",
                "CurrentPotSelect",
                "",
                "",
                "SwitchClk",
                "Volts230",
                "PotSDI",
                "PotSCK",
                "DB0",
                "DB1",
                "DB2",
                "DB3",
                "DB4",
                "DB5",
                "DB6",
                "DB7",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "";
            rp41_gpio: rp41_gpio {
                brcm,pins =     <2 3 4 5 6 7 8 9 10 11 12 13 16 17 18 19 20 21 22 23 24 25 26 27>;
                brcm,function = <0 0 0 0 0 0 0 0 0  0  0  0  0  1  0  0  0  0  0  0  0  0  0  0>; 
            };
        };
    };
};
Output from raspi-gpio get

Code: Select all

BANK0 (GPIO 0 to 27):
GPIO 0: level=0 fsel=1 func=OUTPUT pull=UP
GPIO 1: level=1 fsel=0 func=INPUT pull=UP
GPIO 2: level=1 fsel=0 func=INPUT pull=UP
GPIO 3: level=1 fsel=0 func=INPUT pull=UP
GPIO 4: level=1 fsel=0 func=INPUT pull=UP
GPIO 5: level=1 fsel=0 func=INPUT pull=UP
GPIO 6: level=1 fsel=0 func=INPUT pull=UP
GPIO 7: level=1 fsel=0 func=INPUT pull=UP
GPIO 8: level=1 fsel=0 func=INPUT pull=UP
GPIO 9: level=0 fsel=0 func=INPUT pull=DOWN
GPIO 10: level=0 fsel=0 func=INPUT pull=DOWN
GPIO 11: level=0 fsel=0 func=INPUT pull=DOWN
GPIO 12: level=0 fsel=0 func=INPUT pull=DOWN
GPIO 13: level=0 fsel=0 func=INPUT pull=DOWN
GPIO 14: level=1 fsel=2 alt=5 func=TXD1 pull=NONE
GPIO 15: level=1 fsel=2 alt=5 func=RXD1 pull=UP
GPIO 16: level=0 fsel=0 func=INPUT pull=DOWN
GPIO 17: level=0 fsel=0 func=INPUT pull=DOWN
GPIO 18: level=0 fsel=0 func=INPUT pull=DOWN
GPIO 19: level=0 fsel=0 func=INPUT pull=DOWN
GPIO 20: level=0 fsel=0 func=INPUT pull=DOWN
GPIO 21: level=0 fsel=0 func=INPUT pull=DOWN
GPIO 22: level=0 fsel=0 func=INPUT pull=DOWN
GPIO 23: level=0 fsel=0 func=INPUT pull=DOWN
GPIO 24: level=0 fsel=0 func=INPUT pull=DOWN
GPIO 25: level=0 fsel=0 func=INPUT pull=DOWN
GPIO 26: level=0 fsel=0 func=INPUT pull=DOWN
GPIO 27: level=0 fsel=0 func=INPUT pull=DOWN
BANK1 (GPIO 28 to 45):
GPIO 28: level=1 fsel=2 alt=5 func=RGMII_MDIO pull=UP
GPIO 29: level=0 fsel=2 alt=5 func=RGMII_MDC pull=DOWN
GPIO 30: level=0 fsel=7 alt=3 func=CTS0 pull=UP
GPIO 31: level=0 fsel=7 alt=3 func=RTS0 pull=NONE
GPIO 32: level=1 fsel=7 alt=3 func=TXD0 pull=NONE
GPIO 33: level=1 fsel=7 alt=3 func=RXD0 pull=UP
GPIO 34: level=1 fsel=7 alt=3 func=SD1_CLK pull=NONE
GPIO 35: level=1 fsel=7 alt=3 func=SD1_CMD pull=UP
GPIO 36: level=1 fsel=7 alt=3 func=SD1_DAT0 pull=UP
GPIO 37: level=1 fsel=7 alt=3 func=SD1_DAT1 pull=UP
GPIO 38: level=1 fsel=7 alt=3 func=SD1_DAT2 pull=UP
GPIO 39: level=1 fsel=7 alt=3 func=SD1_DAT3 pull=UP
GPIO 40: level=0 fsel=4 alt=0 func=PWM1_0 pull=NONE
GPIO 41: level=0 fsel=4 alt=0 func=PWM1_1 pull=NONE
GPIO 42: level=0 fsel=1 func=OUTPUT pull=UP
GPIO 43: level=1 fsel=0 func=INPUT pull=UP
GPIO 44: level=1 fsel=0 func=INPUT pull=UP
GPIO 45: level=1 fsel=0 func=INPUT pull=UP
BANK2 (GPIO 46 to 53):
GPIO 46: level=0 fsel=0 func=INPUT pull=DOWN
GPIO 47: level=0 fsel=0 func=INPUT pull=DOWN
GPIO 48: level=0 fsel=0 func=INPUT pull=DOWN
GPIO 49: level=0 fsel=0 func=INPUT pull=DOWN
GPIO 50: level=0 fsel=0 func=INPUT pull=DOWN
GPIO 51: level=0 fsel=0 func=INPUT pull=DOWN
GPIO 52: level=0 fsel=0 func=INPUT pull=DOWN
GPIO 53: level=0 fsel=0 func=INPUT pull=DOWN
Output from vcdbg

Code: Select all

002713.033: arasan: arasan_emmc_open
002715.206: arasan: arasan_emmc_set_clock C0: 0x00000000 C1: 0x000ef447 emmc: 200000000 actual: 200000 div: 0x000001f4 target: 200000 min: 100000 max: 400000 delay: 10
002831.949: arasan: arasan_emmc_set_clock C0: 0x00000000 C1: 0x000ef447 emmc: 200000000 actual: 200000 div: 0x000001f4 target: 200000 min: 100000 max: 400000 delay: 10
002839.103: arasan: arasan_emmc_set_clock C0: 0x00000f00 C1: 0x000e01c7 emmc: 200000000 actual: 130039 div: 0x00000301 target: 130000 min: 100000 max: 400000 delay: 15
002882.158: arasan: arasan_emmc_set_clock C0: 0x00000f06 C1: 0x000e0307 emmc: 200000000 actual: 33333333 div: 0x00000003 target: 40000000 min: 0 max: 40000000 delay: 1
003146.896: brfs: File read: /mfs/sd/config.txt
003147.682: brfs: File read: 1894 bytes
003192.955: brfs: File read: /mfs/sd/config.txt
003393.961: gpioman: gpioman_get_pin_num: pin DISPLAY_DSI_PORT not defined
003396.443: *** Restart logging
003396.484: brfs: File read: 1894 bytes
003400.266: hdmi: HDMI:hdmi_get_state is deprecated, use hdmi_get_display_state instead
003419.263: HDMI0: hdmi_pixel_encoding: 300000000

003419.274: HDMI1: hdmi_pixel_encoding: 300000000

003420.297: brfs: File read: /mfs/sd/cmdline.txt
003420.351: Read command line from file 'cmdline.txt':
003420.382: 'console=tty1 root=PARTUUID=6c586e13-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait'
003424.902: brfs: File read: 98 bytes
003429.656: brfs: File read: /mfs/sd/bcm2711-rpi-4-b.dtb
003429.693: Loading 'bcm2711-rpi-4-b.dtb' to 0x100 size 0x9e6f
003652.923: brfs: File read: 40559 bytes
003655.246: brfs: File read: /mfs/sd/config.txt
003656.113: dtparam: audio=on
003698.422: brfs: File read: 1894 bytes
003714.735: brfs: File read: /mfs/sd/overlays/vc4-fkms-v3d.dtbo
003781.913: Loaded overlay 'vc4-fkms-v3d'
003906.221: brfs: File read: 1255 bytes
003910.482: brfs: File read: /mfs/sd/overlays/rp41gpio.dtbo
003941.556: Loaded overlay 'rp41gpio'
005284.171: brfs: File read: 1211 bytes
005722.507: brfs: File read: /mfs/sd/kernel7l.img
005722.548: Loading 'kernel7l.img' to 0x8000 size 0x55e088
005722.591: Device tree loaded to 0x2eff5a00 (size 0xa5cc)
005724.959: gpioman: gpioman_get_pin_num: pin SDCARD_CONTROL_POWER not defined
008492.144: vchiq_core: vchiq_init_state: slot_zero = 0xded80000, is_master = 1
008494.854: hdmi: HDMI:hdmi_get_state is deprecated, use hdmi_get_display_state instead
008499.444: TV service:host side not connected, dropping notification 0x00000002, 0x00000002, 0x00000039
011195.306: brfs: File read: 5628040 bytes
011688.043: TV service:host side not connected, dropping notification 0x00000004, 0x00000004, 0x00000001
What on earth am I doing wrong? What have I missed? Do I need open something from userspace to activate this?

Roger

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 2589
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Problem with gpio-hog

Thu Jan 09, 2020 3:44 pm

You almost got it. What you didn't figure out is that the "leds" node replaces your rp41_pins node, i.e.:

Code: Select all

// Overlay for rp41 gpio line names
/dts-v1/;
/plugin/;

/{
    compatible = "brcm,bcm2835";
    [email protected] {
        target = <&leds>;
        __overlay__ {
            pinctrl-names = "default";
            pinctrl-0 = <&rp41_gpio>;
        };
    };
    [email protected] {
        target = <&gpio>;
        __overlay__ {
            gpio-line-names = 
                "",
                "",
                "SelectEnable",
                "Select1",
                "Select2",
                "Select4",
                "Select8",
                "Select16",
                "Select32",
                "Drive12V",
                "VoltsPotSelect",
                "Data",
                "Clock",
                "CurrentPotSelect",
                "",
                "",
                "SwitchClk",
                "Volts230",
                "PotSDI",
                "PotSCK",
                "DB0",
                "DB1",
                "DB2",
                "DB3",
                "DB4",
                "DB5",
                "DB6",
                "DB7",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "";
            rp41_gpio: rp41_gpio {
                brcm,pins =     <2 3 4 5 6 7 8 9 10 11 12 13 16 17 18 19 20 21 22 23 24 25 26 27>;
                brcm,function = <0 0 0 0 0 0 0 0 0  0  0  0  0  1  0  0  0  0  0  0  0  0  0  0>; 
            };
        };
    };
};
Give that a whirl...

By the way, I think calling your gpio/pinctrl node "rp41_pins" would be clearer.

rogerjames99
Posts: 43
Joined: Fri Sep 28, 2012 2:58 pm

Re: Problem with gpio-hog

Thu Jan 09, 2020 4:40 pm

Aargh. Did not work.

Code: Select all

// Overlay for rp41 gpio line names
/dts-v1/;
/plugin/;

/{
    compatible = "brcm,bcm2835";
    [email protected] {
        target = <&leds>;
        __overlay__ {
            pinctrl-names = "default";
            pinctrl-0 = <&rp41_pins>;
        };
    };
    [email protected] {
        target = <&gpio>;
        __overlay__ {
            gpio-line-names = 
                "",
                "",
                "SelectEnable",
                "Select1",
                "Select2",
                "Select4",
                "Select8",
                "Select16",
                "Select32",
                "Drive12V",
                "VoltsPotSelect",
                "Data",
                "Clock",
                "CurrentPotSelect",
                "",
                "",
                "SwitchClk",
                "Volts230",
                "PotSDI",
                "PotSCK",
                "DB0",
                "DB1",
                "DB2",
                "DB3",
                "DB4",
                "DB5",
                "DB6",
                "DB7",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "";
            rp41_pins: rp41_pins {
                brcm,pins =     <2 3 4 5 6 7 8 9 10 11 12 13 16 17 18 19 20 21 22 23 24 25 26 27>;
                brcm,function = <0 0 0 0 0 0 0 0 0  0  0  0  0  1  0  0  0  0  0  0  0  0  0  0>; 
            };
        };
    };
};
Tried on a pi3 and a pi4. Same as before. Pin names changed, but nothing else.

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 2589
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Problem with gpio-hog

Thu Jan 09, 2020 5:01 pm

That worked for me on a Pi 4:

Code: Select all

[email protected]:~$ raspi-gpio get 0-27
GPIO 0: level=1 fsel=0 func=INPUT pull=UP
GPIO 1: level=1 fsel=0 func=INPUT pull=UP
GPIO 2: level=1 fsel=0 func=INPUT pull=UP
GPIO 3: level=1 fsel=0 func=INPUT pull=UP
GPIO 4: level=1 fsel=0 func=INPUT pull=UP
GPIO 5: level=0 fsel=0 func=INPUT pull=UP
GPIO 6: level=1 fsel=0 func=INPUT pull=UP
GPIO 7: level=1 fsel=0 func=INPUT pull=UP
GPIO 8: level=1 fsel=0 func=INPUT pull=UP
GPIO 9: level=0 fsel=0 func=INPUT pull=DOWN
GPIO 10: level=0 fsel=0 func=INPUT pull=DOWN
GPIO 11: level=0 fsel=0 func=INPUT pull=DOWN
GPIO 12: level=0 fsel=0 func=INPUT pull=DOWN
GPIO 13: level=0 fsel=0 func=INPUT pull=DOWN
GPIO 14: level=1 fsel=4 alt=0 func=TXD0 pull=NONE
GPIO 15: level=1 fsel=4 alt=0 func=RXD0 pull=UP
GPIO 16: level=0 fsel=0 func=INPUT pull=DOWN
GPIO 17: level=0 fsel=1 func=OUTPUT pull=DOWN
GPIO 18: level=0 fsel=0 func=INPUT pull=DOWN
GPIO 19: level=0 fsel=0 func=INPUT pull=DOWN
GPIO 20: level=0 fsel=0 func=INPUT pull=DOWN
GPIO 21: level=0 fsel=0 func=INPUT pull=DOWN
GPIO 22: level=0 fsel=0 func=INPUT pull=DOWN
GPIO 23: level=0 fsel=0 func=INPUT pull=DOWN
GPIO 24: level=0 fsel=0 func=INPUT pull=DOWN
GPIO 25: level=0 fsel=0 func=INPUT pull=DOWN
GPIO 26: level=0 fsel=0 func=INPUT pull=DOWN
GPIO 27: level=0 fsel=0 func=INPUT pull=DOWN
However, you don't see it using gpioinfo:

Code: Select all

[email protected]:~$ gpioinfo
gpiochip0 - 54 lines:
        line   0:      unnamed       unused   input  active-high
        line   1:      unnamed       unused   input  active-high
        line   2: "SelectEnable" unused input active-high
        line   3:    "Select1"       unused   input  active-high
        line   4:    "Select2"       unused   input  active-high
        line   5:    "Select4"       unused   input  active-high
        line   6:    "Select8"       unused   input  active-high
        line   7:   "Select16"       unused   input  active-high
        line   8:   "Select32"       unused   input  active-high
        line   9:   "Drive12V"       unused   input  active-high
        line  10: "VoltsPotSelect" unused input active-high
        line  11:       "Data"       unused   input  active-high
        line  12:      "Clock"       unused   input  active-high
        line  13: "CurrentPotSelect" unused input active-high
        line  14:      unnamed       unused   input  active-high
        line  15:      unnamed       unused   input  active-high
        line  16:  "SwitchClk"       unused   input  active-high
        line  17:   "Volts230"       unused   input  active-high
        line  18:     "PotSDI"       unused   input  active-high
        line  19:     "PotSCK"       unused   input  active-high
        line  20:        "DB0"       unused   input  active-high
        line  21:        "DB1"       unused   input  active-high
        line  22:        "DB2"       unused   input  active-high
        line  23:        "DB3"       unused   input  active-high
        line  24:        "DB4"       unused   input  active-high
        line  25:        "DB5"       unused   input  active-high
        line  26:        "DB6"       unused   input  active-high
        line  27:        "DB7"       unused   input  active-high
This is because gpioinfo reports on the state of the "gpio" subsystem, and your overlay affects the "pinctrl" subsystem. Since both deal in pins, the difference is a bit subtle, but notice that GPIO 17 is an output driving low - there is no way to make it an output driving high through pinctrl (hmmm - perhaps the new generic pinctrl might...).

You can see evidence of pinctrl's involvement from /sys/kernel/debug/pinctrl (which unfortunately needs root privilege):

Code: Select all

[email protected]:~$ sudo -s
[email protected]:/home/pi# cd /sys/kernel/debug/pinctrl/*gpio*
[email protected]:/sys/kernel/debug/pinctrl/fe200000.gpio-pinctrl-bcm2835# cat pins
registered pins: 54
pin 0 (gpio0) function gpio_in in hi; irq 0 (none)
pin 1 (gpio1) function gpio_in in hi; irq 0 (none)
pin 2 (gpio2) function gpio_in in hi; irq 0 (none)
pin 3 (gpio3) function gpio_in in hi; irq 0 (none)
pin 4 (gpio4) function gpio_in in hi; irq 0 (none)
pin 5 (gpio5) function gpio_in in lo; irq 0 (none)
pin 6 (gpio6) function gpio_in in hi; irq 0 (none)
pin 7 (gpio7) function gpio_in in hi; irq 0 (none)
pin 8 (gpio8) function gpio_in in hi; irq 0 (none)
pin 9 (gpio9) function gpio_in in lo; irq 0 (none)
pin 10 (gpio10) function gpio_in in lo; irq 0 (none)
pin 11 (gpio11) function gpio_in in lo; irq 0 (none)
pin 12 (gpio12) function gpio_in in lo; irq 0 (none)
pin 13 (gpio13) function gpio_in in lo; irq 0 (none)
pin 14 (gpio14) function alt0 in hi; irq 0 (none)
pin 15 (gpio15) function alt0 in hi; irq 0 (none)
pin 16 (gpio16) function gpio_in in lo; irq 0 (none)
pin 17 (gpio17) function gpio_out in lo; irq 0 (none)
pin 18 (gpio18) function gpio_in in lo; irq 0 (none)
pin 19 (gpio19) function gpio_in in lo; irq 0 (none)
pin 20 (gpio20) function gpio_in in lo; irq 0 (none)
pin 21 (gpio21) function gpio_in in lo; irq 0 (none)
pin 22 (gpio22) function gpio_in in lo; irq 0 (none)
pin 23 (gpio23) function gpio_in in lo; irq 0 (none)
pin 24 (gpio24) function gpio_in in lo; irq 0 (none)
pin 25 (gpio25) function gpio_in in lo; irq 0 (none)
pin 26 (gpio26) function gpio_in in lo; irq 0 (none)
pin 27 (gpio27) function gpio_in in lo; irq 0 (none)
pin 28 (gpio28) function alt5 in hi; irq 0 (none)
pin 29 (gpio29) function alt5 in lo; irq 0 (none)
pin 30 (gpio30) function gpio_in in hi; irq 0 (none)
pin 31 (gpio31) function gpio_in in hi; irq 0 (none)
pin 32 (gpio32) function gpio_in in hi; irq 0 (none)
pin 33 (gpio33) function gpio_in in hi; irq 0 (none)
pin 34 (gpio34) function alt3 in hi; irq 0 (none)
pin 35 (gpio35) function alt3 in hi; irq 0 (none)
pin 36 (gpio36) function alt3 in hi; irq 0 (none)
pin 37 (gpio37) function alt3 in hi; irq 0 (none)
pin 38 (gpio38) function alt3 in hi; irq 0 (none)
pin 39 (gpio39) function alt3 in hi; irq 0 (none)
pin 40 (gpio40) function alt0 in lo; irq 0 (none)
pin 41 (gpio41) function alt0 in lo; irq 0 (none)
pin 42 (gpio42) function gpio_out in lo; irq 0 (none)
pin 43 (gpio43) function gpio_in in hi; irq 0 (none)
pin 44 (gpio44) function gpio_in in hi; irq 0 (none)
pin 45 (gpio45) function gpio_in in hi; irq 0 (none)
pin 46 (gpio46) function gpio_in in lo; irq 0 (none)
pin 47 (gpio47) function gpio_in in lo; irq 0 (none)
pin 48 (gpio48) function gpio_in in lo; irq 0 (none)
pin 49 (gpio49) function gpio_in in lo; irq 0 (none)
pin 50 (gpio50) function gpio_in in lo; irq 0 (none)
pin 51 (gpio51) function gpio_in in lo; irq 0 (none)
pin 52 (gpio52) function gpio_in in lo; irq 0 (none)
pin 53 (gpio53) function gpio_in in lo; irq 0 (none)
[email protected]:/sys/kernel/debug/pinctrl/fe200000.gpio-pinctrl-bcm2835# cat pinmux-pins
Pinmux settings per pin
Format: pin (name): mux_owner gpio_owner hog?
pin 0 (gpio0): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 1 (gpio1): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 2 (gpio2): leds (GPIO UNCLAIMED) function gpio_in group gpio2
pin 3 (gpio3): leds (GPIO UNCLAIMED) function gpio_in group gpio3
pin 4 (gpio4): leds (GPIO UNCLAIMED) function gpio_in group gpio4
pin 5 (gpio5): leds (GPIO UNCLAIMED) function gpio_in group gpio5
pin 6 (gpio6): leds (GPIO UNCLAIMED) function gpio_in group gpio6
pin 7 (gpio7): leds (GPIO UNCLAIMED) function gpio_in group gpio7
pin 8 (gpio8): leds (GPIO UNCLAIMED) function gpio_in group gpio8
pin 9 (gpio9): leds (GPIO UNCLAIMED) function gpio_in group gpio9
pin 10 (gpio10): leds (GPIO UNCLAIMED) function gpio_in group gpio10
pin 11 (gpio11): leds (GPIO UNCLAIMED) function gpio_in group gpio11
pin 12 (gpio12): leds (GPIO UNCLAIMED) function gpio_in group gpio12
pin 13 (gpio13): leds (GPIO UNCLAIMED) function gpio_in group gpio13
pin 14 (gpio14): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 15 (gpio15): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 16 (gpio16): leds (GPIO UNCLAIMED) function gpio_in group gpio16
pin 17 (gpio17): leds (GPIO UNCLAIMED) function gpio_out group gpio17
pin 18 (gpio18): leds (GPIO UNCLAIMED) function gpio_in group gpio18
pin 19 (gpio19): leds (GPIO UNCLAIMED) function gpio_in group gpio19
pin 20 (gpio20): leds (GPIO UNCLAIMED) function gpio_in group gpio20
pin 21 (gpio21): leds (GPIO UNCLAIMED) function gpio_in group gpio21
pin 22 (gpio22): leds (GPIO UNCLAIMED) function gpio_in group gpio22
pin 23 (gpio23): leds (GPIO UNCLAIMED) function gpio_in group gpio23
pin 24 (gpio24): leds (GPIO UNCLAIMED) function gpio_in group gpio24
pin 25 (gpio25): leds (GPIO UNCLAIMED) function gpio_in group gpio25
pin 26 (gpio26): leds (GPIO UNCLAIMED) function gpio_in group gpio26
pin 27 (gpio27): leds (GPIO UNCLAIMED) function gpio_in group gpio27
pin 28 (gpio28): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 29 (gpio29): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 30 (gpio30): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 31 (gpio31): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 32 (gpio32): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 33 (gpio33): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 34 (gpio34): fe300000.mmcnr (GPIO UNCLAIMED) function alt3 group gpio34
pin 35 (gpio35): fe300000.mmcnr (GPIO UNCLAIMED) function alt3 group gpio35
pin 36 (gpio36): fe300000.mmcnr (GPIO UNCLAIMED) function alt3 group gpio36
pin 37 (gpio37): fe300000.mmcnr (GPIO UNCLAIMED) function alt3 group gpio37
pin 38 (gpio38): fe300000.mmcnr (GPIO UNCLAIMED) function alt3 group gpio38
pin 39 (gpio39): fe300000.mmcnr (GPIO UNCLAIMED) function alt3 group gpio39
pin 40 (gpio40): soc:audio (GPIO UNCLAIMED) function alt0 group gpio40
pin 41 (gpio41): soc:audio (GPIO UNCLAIMED) function alt0 group gpio41
pin 42 (gpio42): (MUX UNCLAIMED) pinctrl-bcm2835:42
pin 43 (gpio43): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 44 (gpio44): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 45 (gpio45): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 46 (gpio46): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 47 (gpio47): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 48 (gpio48): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 49 (gpio49): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 50 (gpio50): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 51 (gpio51): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 52 (gpio52): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 53 (gpio53): (MUX UNCLAIMED) (GPIO UNCLAIMED)
[email protected]:/sys/kernel/debug/pinctrl/fe200000.gpio-pinctrl-bcm2835# exit
exit
[email protected]:~$

rogerjames99
Posts: 43
Joined: Fri Sep 28, 2012 2:58 pm

Re: Problem with gpio-hog

Thu Jan 09, 2020 5:38 pm

Oh dear. My mess up. I was using the constants from dt-bindings/bcm2835.h. I removed them so I did not have to use c preprocessor to make the includes work. Dont know how I managed to get the ones and zeroes reversed. Didnt notice that it was was actually working on pin 17 (but the wrong way round).

Mea culpa.

rogerjames99
Posts: 43
Joined: Fri Sep 28, 2012 2:58 pm

Re: Problem with gpio-hog

Thu Jan 09, 2020 5:55 pm

Yabber Dabber Doo.

All working now. I you were here you would have witnessed the spectacle of a portly old git dancing around the room with joy.

Thanks for your time and patience Phil.

Roger

Return to “Device Tree”