Transitionning GPIO from kernel 4 to 6

Hello everyone, i saw the declaration of GPIO changed from kernel 4 to kernel 6, for example , here is what cat /sys/kernel/debug/gpio returns me from differents kernels

Kernel 4

root@BB:~# cat /sys/kernel/debug/gpio
GPIOs 0-31, platform/44e07000.gpio, gpio:
gpio-6 ( |cd ) in lo IRQ
gpio-22 ( |sysfs ) in lo
gpio-23 ( |sysfs ) in hi

GPIOs 32-63, platform/4804c000.gpio, gpio:
gpio-34 ( |sysfs ) in hi
gpio-35 ( |spi-gpio-reset ) out hi
gpio-36 ( |sysfs ) in hi
gpio-44 ( |sysfs ) in hi
gpio-45 ( |sysfs ) in hi
gpio-48 ( |omap-serial-rts ) out lo
gpio-50 ( |omap-serial-cts ) out lo
gpio-51 ( |omap-serial-cts ) out lo
gpio-53 ( |? ) out lo
gpio-54 ( |? ) out lo
gpio-55 ( |? ) out hi
gpio-56 ( |? ) out lo
gpio-59 ( |clk_mcasp0 ) out lo
gpio-60 ( |omap-serial-rts ) out lo
gpio-61 ( |sysfs ) in hi
gpio-62 ( |sysfs ) in lo

GPIOs 64-95, platform/481ac000.gpio, gpio:
gpio-67 ( |watchdog ) out hi

GPIOs 96-127, platform/481ae000.gpio, gpio:
gpio-114 ( |sysfs ) in hi
gpio-115 ( |omap-serial-rts ) out lo

GPIOs 508-511, spi/spi2.1, spi2.1, can sleep:
gpio-508 ( |sysfs ) out lo
gpio-509 ( |sysfs ) out lo
gpio-510 ( |sysfs ) out lo
gpio-511 ( |sysfs ) out hi

Kernel 6, with no gpio binded, lost all my leds and my gpio extension :

root@BB:~# cat /sys/kernel/debug/gpio
gpiochip0: GPIOs 512-543, parent: platform/4804c000.gpio, gpio-0-31:
gpio-512 (P8_25 [mmc1_dat0] )
gpio-513 ([mmc1_dat1] )
gpio-514 (P8_5 [mmc1_dat2] )
gpio-515 (P8_6 [mmc1_dat3] )
gpio-516 (P8_23 [mmc1_dat4] )
gpio-517 (P8_22 [mmc1_dat5] )
gpio-518 (P8_3 [mmc1_dat6] )
gpio-519 (P8_4 [mmc1_dat7] )
gpio-520 (NC |PHY reset ) out hi ACTIVE LOW
gpio-521 (NC )
gpio-522 (NC )
gpio-523 (NC )
gpio-524 (P8_12 )
gpio-525 (P8_11 )
gpio-526 (P8_16 )
gpio-527 (P8_15 )
gpio-528 (P9_15A )
gpio-529 (P9_23 )
gpio-530 (P9_14 [ehrpwm1a] )
gpio-531 (P9_16 [ehrpwm1b] )
gpio-532 ([emmc rst] )
gpio-533 ([usr0 led] |beaglebone:green:usr) out lo
gpio-534 ([usr1 led] |beaglebone:green:usr) out lo
gpio-535 ([usr2 led] |beaglebone:green:usr) out hi
gpio-536 ([usr3 led] |beaglebone:green:usr) out lo
gpio-537 ([hdmi irq] )
gpio-538 ([usb vbus oc] )
gpio-539 ([hdmi audio] |enable ) out lo
gpio-540 (P9_12 )
gpio-541 (P8_26 )
gpio-542 (P8_21 [emmc] )
gpio-543 (P8_20 [emmc] )

gpiochip1: GPIOs 544-575, parent: platform/481ac000.gpio, gpio-32-63:
gpio-544 (P9_15B )
gpio-545 (P8_18 )
gpio-546 (P8_7 )
gpio-547 (P8_8 |watchdog ) out lo ACTIVE LOW
gpio-548 (P8_10 )
gpio-549 (P8_9 )
gpio-550 (P8_45 [hdmi] )
gpio-551 (P8_46 [hdmi] )
gpio-552 (P8_43 [hdmi] )
gpio-553 (P8_44 [hdmi] )
gpio-554 (P8_41 [hdmi] )
gpio-555 (P8_42 [hdmi] )
gpio-556 (P8_39 [hdmi] )
gpio-557 (P8_40 [hdmi] )
gpio-558 (P8_37 [hdmi] )
gpio-559 (P8_38 [hdmi] )
gpio-560 (P8_36 [hdmi] )
gpio-561 (P8_34 [hdmi] )
gpio-562 ([rmii1_rxd3] )
gpio-563 ([rmii1_rxd2] )
gpio-564 ([rmii1_rxd1] )
gpio-565 ([rmii1_rxd0] )
gpio-566 (P8_27 [hdmi] )
gpio-567 (P8_29 [hdmi] )
gpio-568 (P8_28 [hdmi] )
gpio-569 (P8_30 [hdmi] )
gpio-570 ([mmc0_dat3] )
gpio-571 ([mmc0_dat2] )
gpio-572 ([mmc0_dat1] )
gpio-573 ([mmc0_dat0] )
gpio-574 ([mmc0_clk] )
gpio-575 ([mmc0_cmd] )

gpiochip2: GPIOs 576-607, parent: platform/481ae000.gpio, gpio-64-95:
gpio-576 ([mii col] )
gpio-577 ([mii crs] )
gpio-578 ([mii rx err] )
gpio-579 ([mii tx en] )
gpio-580 ([mii rx dv] )
gpio-581 ([i2c0 sda] )
gpio-582 ([i2c0 scl] )
gpio-583 ([jtag emu0] )
gpio-584 ([jtag emu1] )
gpio-585 ([mii tx clk] )
gpio-586 ([mii rx clk] )
gpio-587 (NC )
gpio-588 (NC )
gpio-589 ([usb vbus en] )
gpio-590 (P9_31 [spi1_sclk] )
gpio-591 (P9_29 [spi1_d0] )
gpio-592 (P9_30 [spi1_d1] )
gpio-593 (P9_28 [spi1_cs0] )
gpio-594 (P9_42B [ecappwm0] )
gpio-595 (P9_27 )
gpio-596 (P9_41A )
gpio-597 (P9_25 )
gpio-598 (NC )
gpio-599 (NC )
gpio-600 (NC )
gpio-601 (NC )
gpio-602 (NC )
gpio-603 (NC )
gpio-604 (NC )
gpio-605 (NC )
gpio-606 (NC )
gpio-607 (NC )
gpiochip3: GPIOs 608-639, parent: platform/44e07000.gpio, gpio-96-127:
gpio-608 ([mdio_data] )
gpio-609 ([mdio_clk] )
gpio-610 (P9_22 [spi0_sclk] )
gpio-611 (P9_21 [spi0_d0] )
gpio-612 (P9_18 [spi0_d1] )
gpio-613 (P9_17 [spi0_cs0] )
gpio-614 ([mmc0_cd] |cd ) in lo IRQ ACTIVE LOW
gpio-615 (P9_42A [ecappwm0] )
gpio-616 (P8_35 [lcd d12] )
gpio-617 (P8_33 [lcd d13] )
gpio-618 (P8_31 [lcd d14] )
gpio-619 (P8_32 [lcd d15] )
gpio-620 (P9_20 [i2c2_sda] )
gpio-621 (P9_19 [i2c2_scl] )
gpio-622 (P9_26 [uart1_rxd] )
gpio-623 (P9_24 [uart1_txd] )
gpio-624 ([rmii1_txd3] )
gpio-625 ([rmii1_txd2] )
gpio-626 ([usb0_drvvbus] )
gpio-627 ([hdmi cec] )
gpio-628 (P9_41B )
gpio-629 ([rmii1_txd1] )
gpio-630 (P8_19 [ehrpwm2a] )
gpio-631 (P8_13 [ehrpwm2b] )
gpio-632 (NC )
gpio-633 (NC )
gpio-634 (P8_14 )
gpio-635 (P8_17 )
gpio-636 ([rmii1_txd0] )
gpio-637 ([rmii1_refclk] )
gpio-638 (P9_11 [uart4_rxd] )
gpio-639 (P9_13 [uart4_txd] )

gpiochip4: GPIOs 640-647, parent: spi/spi1.1, spi1.1, can sleep:
gpio-640 (Led9 )
gpio-641 (Led10 )
gpio-642 (Led11 )
gpio-643 (Led12 )

how should i proceed to make my gpio works and bind them, because at the moment i lost my gpio by upgrading the kernel, can anyone explain me ? i canā€™t find good explanation on the internet, thanks everyone

Correct removal of ā€˜sys/class/gpioā€™ has accelerated on mainline.

A proper fix depends on what state utilize your I/Oā€¦

Outputsā€¦
Inputsā€¦
PRUā€¦
SPI/i2c/etcā€¦

Based on how you use them, there is a way to support both 4.x/5.x and 6.x at the same time.

Regards,

@RobertCNelson How do i find this way ? i would sincerely like your help, i struggle since 2 weeks

Just changing the number on my script of GPIO declaration should work ? for example gpio114 into the new number like apparently gpio594 because apparently it seems to correspond, i still donā€™t know what does P9_42A and P9_42B means, why is it separated whereas in the past i had something in simply P9_42, if you could enlight me, thanks you

That wonā€™t last foreverā€¦

Start with the basics, you have a bunch of I/O you currently useā€¦

Some are outputs, inputs, etcā€¦

What pins do you have that are pure output that you toggle on/offā€¦

I donā€™t toggle any @RobertCNelson, i donā€™t know how i should do, can you give me some detail, would help me a lot

here is an example of my script :

echo ā€œpreparation AP GPIO 1_30ā€
echo 62 > /sys/class/gpio/export;
echo ā€œinā€ > /sys/class/gpio/gpio62/direction;
ln -sf /sys/class/gpio/gpio62/value /Distrib/Data/Firmware/LinuxCoreBoard/gpio/gpio62

echo ā€œpreparation gpio input\nā€

param1 1_13

echo 45 > /sys/class/gpio/export;
echo ā€œinā€ > /sys/class/gpio/gpio45/direction;
echo 1 > /sys/class/gpio/gpio45/active_low;
ln -sf /sys/class/gpio/gpio45/value /Distrib/Data/Firmware/LinuxCoreBoard/gpio/gpio45

param 2 0_23

echo 23 > /sys/class/gpio/export;
echo ā€œinā€ > /sys/class/gpio/gpio23/direction;
echo 1 > /sys/class/gpio/gpio23/active_low;
ln -sf /sys/class/gpio/gpio23/value /Distrib/Data/Firmware/LinuxCoreBoard/gpio/gpio23

#param 3 1_2
echo 34 > /sys/class/gpio/export;
echo ā€œinā€ > /sys/class/gpio/gpio34/direction;
echo 1 > /sys/class/gpio/gpio34/active_low;
ln -sf /sys/class/gpio/gpio34/value /Distrib/Data/Firmware/LinuxCoreBoard/gpio/gpio34

#param 4 0_22
echo 22 > /sys/class/gpio/export;
echo ā€œinā€ > /sys/class/gpio/gpio22/direction;
echo 1 > /sys/class/gpio/gpio22/active_low;
ln -sf /sys/class/gpio/gpio22/value /Distrib/Data/Firmware/LinuxCoreBoard/gpio/gpio22

#param 5 1_4
echo 36 > /sys/class/gpio/export;
echo ā€œinā€ > /sys/class/gpio/gpio36/direction;
echo 1 > /sys/class/gpio/gpio36/active_low;
ln -sf /sys/class/gpio/gpio36/value /Distrib/Data/Firmware/LinuxCoreBoard/gpio/gpio36

#param 6 1_12
echo 44 > /sys/class/gpio/export;
echo ā€œinā€ > /sys/class/gpio/gpio44/direction;
echo 1 > /sys/class/gpio/gpio44/active_low;
ln -sf /sys/class/gpio/gpio44/value /Distrib/Data/Firmware/LinuxCoreBoard/gpio/gpio44

Please list what your pins do thenā€¦

they are linked to a switch with a on/off position @RobertCNelson

echo ā€œpreparation AP GPIO 1_30ā€
echo 62 > /sys/class/gpio/export;
echo ā€œinā€ > /sys/class/gpio/gpio62/direction;
ln -sf /sys/class/gpio/gpio62/value /Distrib/Data/Firmware/LinuxCoreBoard/gpio/gpio62

echo ā€œpreparation gpio input\nā€

param1 1_13

echo 45 > /sys/class/gpio/export;
echo ā€œinā€ > /sys/class/gpio/gpio45/direction;
echo 1 > /sys/class/gpio/gpio45/active_low;
ln -sf /sys/class/gpio/gpio45/value /Distrib/Data/Firmware/LinuxCoreBoard/gpio/gpio45

param 2 0_23

echo 23 > /sys/class/gpio/export;
echo ā€œinā€ > /sys/class/gpio/gpio23/direction;
echo 1 > /sys/class/gpio/gpio23/active_low;
ln -sf /sys/class/gpio/gpio23/value /Distrib/Data/Firmware/LinuxCoreBoard/gpio/gpio23

#param 3 1_2
echo 34 > /sys/class/gpio/export;
echo ā€œinā€ > /sys/class/gpio/gpio34/direction;
echo 1 > /sys/class/gpio/gpio34/active_low;
ln -sf /sys/class/gpio/gpio34/value /Distrib/Data/Firmware/LinuxCoreBoard/gpio/gpio34

#param 4 0_22
echo 22 > /sys/class/gpio/export;
echo ā€œinā€ > /sys/class/gpio/gpio22/direction;
echo 1 > /sys/class/gpio/gpio22/active_low;
ln -sf /sys/class/gpio/gpio22/value /Distrib/Data/Firmware/LinuxCoreBoard/gpio/gpio22

#param 5 1_4
echo 36 > /sys/class/gpio/export;
echo ā€œinā€ > /sys/class/gpio/gpio36/direction;
echo 1 > /sys/class/gpio/gpio36/active_low;
ln -sf /sys/class/gpio/gpio36/value /Distrib/Data/Firmware/LinuxCoreBoard/gpio/gpio36

#param 6 1_12
echo 44 > /sys/class/gpio/export;
echo ā€œinā€ > /sys/class/gpio/gpio44/direction;
echo 1 > /sys/class/gpio/gpio44/active_low;
ln -sf /sys/class/gpio/gpio44/value /Distrib/Data/Firmware/LinuxCoreBoard/gpio/gpio44

So two optionsā€¦ gpio-key device-tree or libgpiodā€¦

I work on too many boards, so the ā€œxxā€ offsets donā€™t help meā€¦ what are the P8/P9 numbers?

Regards,

sure @RobertCNelson

What is gpiokey device tree ? a program ? i already struggle a lot sorry

And here is the equivalence ā€œgpio-0-31ā€ for example match one by one in the new number, i hope iā€™m comprehensible.

gpiochip0: GPIOs 512-543, parent: platform/4804c000.gpio, gpio-0-31:
gpio-512 (P8_25 [mmc1_dat0] )
gpio-513 ([mmc1_dat1] )
gpio-514 (P8_5 [mmc1_dat2] )
gpio-515 (P8_6 [mmc1_dat3] )
gpio-516 (P8_23 [mmc1_dat4] )
gpio-517 (P8_22 [mmc1_dat5] )
gpio-518 (P8_3 [mmc1_dat6] )
gpio-519 (P8_4 [mmc1_dat7] )
gpio-520 (NC |PHY reset ) out hi ACTIVE LOW
gpio-521 (NC )
gpio-522 (NC )
gpio-523 (NC )
gpio-524 (P8_12 )
gpio-525 (P8_11 )
gpio-526 (P8_16 )
gpio-527 (P8_15 )
gpio-528 (P9_15A )
gpio-529 (P9_23 )
gpio-530 (P9_14 [ehrpwm1a] )
gpio-531 (P9_16 [ehrpwm1b] )
gpio-532 ([emmc rst] )
gpio-533 ([usr0 led] |beaglebone:green:usr) out lo
gpio-534 ([usr1 led] |beaglebone:green:usr) out lo
gpio-535 ([usr2 led] |beaglebone:green:usr) out hi
gpio-536 ([usr3 led] |beaglebone:green:usr) out lo
gpio-537 ([hdmi irq] )
gpio-538 ([usb vbus oc] )
gpio-539 ([hdmi audio] |enable ) out lo
gpio-540 (P9_12 )
gpio-541 (P8_26 )
gpio-542 (P8_21 [emmc] )
gpio-543 (P8_20 [emmc] )

gpiochip1: GPIOs 544-575, parent: platform/481ac000.gpio, gpio-32-63:
gpio-544 (P9_15B )
gpio-545 (P8_18 )
gpio-546 (P8_7 )
gpio-547 (P8_8 |watchdog ) out lo ACTIVE LOW
gpio-548 (P8_10 )
gpio-549 (P8_9 )
gpio-550 (P8_45 [hdmi] )
gpio-551 (P8_46 [hdmi] )
gpio-552 (P8_43 [hdmi] )
gpio-553 (P8_44 [hdmi] )
gpio-554 (P8_41 [hdmi] )
gpio-555 (P8_42 [hdmi] )
gpio-556 (P8_39 [hdmi] )
gpio-557 (P8_40 [hdmi] )
gpio-558 (P8_37 [hdmi] )
gpio-559 (P8_38 [hdmi] )
gpio-560 (P8_36 [hdmi] )
gpio-561 (P8_34 [hdmi] )
gpio-562 ([rmii1_rxd3] )
gpio-563 ([rmii1_rxd2] )
gpio-564 ([rmii1_rxd1] )
gpio-565 ([rmii1_rxd0] )
gpio-566 (P8_27 [hdmi] )
gpio-567 (P8_29 [hdmi] )
gpio-568 (P8_28 [hdmi] )
gpio-569 (P8_30 [hdmi] )
gpio-570 ([mmc0_dat3] )
gpio-571 ([mmc0_dat2] )
gpio-572 ([mmc0_dat1] )
gpio-573 ([mmc0_dat0] )
gpio-574 ([mmc0_clk] )
gpio-575 ([mmc0_cmd] )

gpiochip2: GPIOs 576-607, parent: platform/481ae000.gpio, gpio-64-95:
gpio-576 ([mii col] )
gpio-577 ([mii crs] )
gpio-578 ([mii rx err] )
gpio-579 ([mii tx en] )
gpio-580 ([mii rx dv] )
gpio-581 ([i2c0 sda] )
gpio-582 ([i2c0 scl] )
gpio-583 ([jtag emu0] )
gpio-584 ([jtag emu1] )
gpio-585 ([mii tx clk] )
gpio-586 ([mii rx clk] )
gpio-587 (NC )
gpio-588 (NC )
gpio-589 ([usb vbus en] )
gpio-590 (P9_31 [spi1_sclk] )
gpio-591 (P9_29 [spi1_d0] )
gpio-592 (P9_30 [spi1_d1] )
gpio-593 (P9_28 [spi1_cs0] )
gpio-594 (P9_42B [ecappwm0] )
gpio-595 (P9_27 )
gpio-596 (P9_41A )
gpio-597 (P9_25 )
gpio-598 (NC )
gpio-599 (NC )
gpio-600 (NC )
gpio-601 (NC )
gpio-602 (NC )
gpio-603 (NC )
gpio-604 (NC )
gpio-605 (NC )
gpio-606 (NC )
gpio-607 (NC )
gpiochip3: GPIOs 608-639, parent: platform/44e07000.gpio, gpio-96-127:
gpio-608 ([mdio_data] )
gpio-609 ([mdio_clk] )
gpio-610 (P9_22 [spi0_sclk] )
gpio-611 (P9_21 [spi0_d0] )
gpio-612 (P9_18 [spi0_d1] )
gpio-613 (P9_17 [spi0_cs0] )
gpio-614 ([mmc0_cd] |cd ) in lo IRQ ACTIVE LOW
gpio-615 (P9_42A [ecappwm0] )
gpio-616 (P8_35 [lcd d12] )
gpio-617 (P8_33 [lcd d13] )
gpio-618 (P8_31 [lcd d14] )
gpio-619 (P8_32 [lcd d15] )
gpio-620 (P9_20 [i2c2_sda] )
gpio-621 (P9_19 [i2c2_scl] )
gpio-622 (P9_26 [uart1_rxd] )
gpio-623 (P9_24 [uart1_txd] )
gpio-624 ([rmii1_txd3] )
gpio-625 ([rmii1_txd2] )
gpio-626 ([usb0_drvvbus] )
gpio-627 ([hdmi cec] )
gpio-628 (P9_41B )
gpio-629 ([rmii1_txd1] )
gpio-630 (P8_19 [ehrpwm2a] )
gpio-631 (P8_13 [ehrpwm2b] )
gpio-632 (NC )
gpio-633 (NC )
gpio-634 (P8_14 )
gpio-635 (P8_17 )
gpio-636 ([rmii1_txd0] )
gpio-637 ([rmii1_refclk] )
gpio-638 (P9_11 [uart4_rxd] )
gpio-639 (P9_13 [uart4_txd] )

gpiochip4: GPIOs 640-647, parent: spi/spi1.1, spi1.1, can sleep:
gpio-640 (Led9 )
gpio-641 (Led10 )
gpio-642 (Led11 )
gpio-643 (Led12 )

On some of the newer boards such as the BBAI64 some of the header pins go to multiple CPU pads. This is either to provide backwards compatibility to the BBB, or to include extra functionality. These pins in the devicetree are labelled Px_xxA and Px_xxB.

It is important if using one of these pins to make sure that the matching pin is set to GPIO input with no pull ups or pull downs to prevent damage to the processor.

so taking the AI64 as an example, P8.32 can be a uart tx pin. This set by this macro.
BONE_PIN(P8_32, uart, P8_32A(PIN_INPUT, 7) P8_32B(PIN_OUTPUT, 14)) /* uart5_txd */

The UART TX functionality is provided by 1 pad on the processor (wherever P8_32B goes to) and the other pad that is connected to P8_32A is set as a GPIO input pin. Both processors pads go to a single header pin P8.32.

2 Likes

This is exactly why itā€™s always such a good idea to study the schematic!

Super explanation @benedict.hewson.

thanks for these explanation, according to my cat /sys/kernel/debug/gpio command in both kernel, how should i declare my gpio with sysfs ? i cant install libgpio on my software, library have built up too much dependencies and installing one will suppress another its so complicated, can i still get my gpio with sysfs ? and how should i do it for example ? should i just replace the numbers in my scripts ?

Well if you know the correct GPIO numbers to export and it works then of course you can still do it that way.

Of course the pin muxing will need to be set correctly to make sure the given pins are GPIO pins.

Eventually it is likely to break though, so you should plan on doing things differently and not rely on exporting the gpio pins.

Or you do as @RobertCNelson suggests and setup gpio-key entries for you inputs. Not sure how this integrates with /dev/input/event. A possible downside in doing this is if you need to read the state when you run. A gpio-key GPIO pin will only send the event when the key changes state.

Outputs can be defined as leds and can be accessed through /sys/class/leds/
I think at least for the BBAi64 most of the gpio pins have leds setup but disabled. You can create an overlay to enable the outputs and set your own name.

thanks a lot ! @benedict.hewson

just to be clear, for example an input that was on gpio61 before, i search for this gpio in the new cat /sys/kernel/debug/gpio file :

gpiochip1: GPIOs 544-575, parent: platform/481ac000.gpio, gpio-32-63:
gpio-544 (P9_15B )
gpio-545 (P8_18 )
gpio-546 (P8_7 )
gpio-547 (P8_8 |watchdog ) out lo ACTIVE LOW
gpio-548 (P8_10 )
gpio-549 (P8_9 )
gpio-550 (P8_45 [hdmi] )
gpio-551 (P8_46 [hdmi] )
gpio-552 (P8_43 [hdmi] )
gpio-553 (P8_44 [hdmi] )
gpio-554 (P8_41 [hdmi] )
gpio-555 (P8_42 [hdmi] )
gpio-556 (P8_39 [hdmi] )
gpio-557 (P8_40 [hdmi] )
gpio-558 (P8_37 [hdmi] )
gpio-559 (P8_38 [hdmi] )
gpio-560 (P8_36 [hdmi] )
gpio-561 (P8_34 [hdmi] )
gpio-562 ([rmii1_rxd3] )
gpio-563 ([rmii1_rxd2] )
gpio-564 ([rmii1_rxd1] )
gpio-565 ([rmii1_rxd0] )
gpio-566 (P8_27 [hdmi] )
gpio-567 (P8_29 [hdmi] )
gpio-568 (P8_28 [hdmi] )
gpio-569 (P8_30 [hdmi] )
gpio-570 ([mmc0_dat3] )
gpio-571 ([mmc0_dat2] )
gpio-572 ([mmc0_dat1] )
gpio-573 ([mmc0_dat0] )
gpio-574 ([mmc0_clk] )
gpio-575 ([mmc0_cmd] )

so i can determine the new number is 573, and then i do

echo 573 > /sys/class/gpio/export;

echo ā€œinā€ > /sys/class/gpio/gpio573/direction;

echo 0 > /sys/class/gpio/gpio573/active_low;

but i still donā€™t have the input, it worked for some led that were output, according to you it is because of the pin muxing in the device tree ?

i declared this pin in the i2c0 block like that, the 61 pin is the last line Param7 :

&am33xx_pinmux {

i2c0_pins: i2c0-pins {

  pinctrl-single,pins = <

  	AM33XX_PADCONF(AM335X_PIN_I2C0_SDA, PIN_INPUT_PULLUP, MUX_MODE0)	/* i2c0_sda.i2c0_sda */

  	AM33XX_PADCONF(AM335X_PIN_I2C0_SCL, PIN_INPUT_PULLUP, MUX_MODE0)	/* i2c0_scl.i2c0_scl */



  	AM33XX_IOPAD( 0x880, PIN_INPUT | MUX_MODE7 )	/* Auto protection  GPIO 1_30	(U9)		/sys/class/gpio/gpio62/	OK*/

  	AM33XX_IOPAD( 0x83c, PIN_INPUT | MUX_MODE5 ) 	/* RTC debug 		GPIO 1_15 	(U13) 		gpmc_ad15.pr1_ecap0_ecap_capin_apwm_o */

  	AM33XX_IOPAD( 0x898, PIN_INPUT | MUX_MODE7 )	/* Accelerometer 	GPIO 2_4 	(U6)		/sys/class/gpio/gpio68/	OK*/

  	AM33XX_IOPAD( 0x82c, PIN_INPUT | MUX_MODE7 )	/* ADC interrupt 	GPIO 0_27 	(U12)		/sys/class/gpio/gpio27 OK*/

  	

  	AM33XX_IOPAD( 0x834, PIN_INPUT | MUX_MODE7 ) 	/* param1 			GPIO 1_13 	(R12)		gpmc_ad13.gpio1[13] */

  	AM33XX_IOPAD( 0x824, PIN_INPUT | MUX_MODE7 ) 	/* param2 			GPIO 0_23 	(T10)		gpmc_ad9.gpio0[23] */

  	AM33XX_IOPAD( 0x808, PIN_INPUT | MUX_MODE7 )	/* Param3			GPIO 1_2  	(R8)		/sys/class/gpio/gpio34/ OK*/

  	AM33XX_IOPAD( 0x820, PIN_INPUT | MUX_MODE7 )	/* Param4			GPIO 0_22 	(U10)		*/

  	AM33XX_IOPAD( 0x810, PIN_INPUT | MUX_MODE7 ) 	/* Param5			GPIO1_4	  	(U8) 		gpmc_ad4.gpio1[4] */

  	AM33XX_IOPAD( 0x830, PIN_INPUT | MUX_MODE7 )	/* Param6			> GPIO 1_12 	(T12)	 	gpmc_ad12.gpio1[12] */
  	AM33XX_IOPAD( 0x87c, PIN_INPUT | MUX_MODE7 ) 	/* Param7			GPIO1_29  	(V6) 		gpmc_csn0.gpio1[29]

NOā€¦ do not just throw them in the i2c0_pins nodeā€¦

Hereā€™s a gpio_keys example:

	gpio_keys: volume-keys {
		compatible = "gpio-keys";
		autorepeat;

		switch-9 {
			label = "volume-up";
			linux,code = <115>;
			gpios = <&gpio0 2 GPIO_ACTIVE_LOW>;
			wakeup-source;
		};

		switch-10 {
			label = "volume-down";
			linux,code = <114>;
			gpios = <&gpio0 3 GPIO_ACTIVE_LOW>;
			wakeup-source;
		};
	};

Those keys are defined as:


	volume_keys_s0: volume-keys-s0-pins {
		pinctrl-single,pins = <
			AM33XX_PADCONF(AM335X_PIN_SPI0_SCLK, PIN_INPUT_PULLDOWN, MUX_MODE7)	/* spi0_sclk.gpio0_2 */
			AM33XX_PADCONF(AM335X_PIN_SPI0_D0, PIN_INPUT_PULLDOWN, MUX_MODE7)	/* spi0_d0.gpio0_3 */
		>;
	};

enabled thru:

&am33xx_pinmux {
	pinctrl-names = "default";
	pinctrl-0 = <&matrix_keypad_s0 &volume_keys_s0 &clkout2_pin>;

Full device-tree: am335x-evm.dts Ā« omap Ā« ti Ā« dts Ā« boot Ā« arm Ā« arch - kernel/git/torvalds/linux.git - Linux kernel source tree

gpio-key: gpio-keys.yaml Ā« input Ā« bindings Ā« devicetree Ā« Documentation - kernel/git/torvalds/linux.git - Linux kernel source tree

you can route them to real ā€˜keysā€™ or just use evdev to see eventsā€¦

Another example: am335x-shc.dts Ā« omap Ā« ti Ā« dts Ā« boot Ā« arm Ā« arch - kernel/git/torvalds/linux.git - Linux kernel source tree

Regards,

@RobertCNelson Thanks ! i tried this :

&am33xx_pinmux {

        gpio_test: gpio_test {

            pinctrl-single,pins = <

				//0x090 0x7	/*GPIO 2_2		/sys/class/gpio/gpio66/ OK*/

				0x008 0x7	/*GPIO 1_2 		/sys/class/gpio/gpio34/ OK*/

				0x018 0x7	/*GPIO 1_6 		/sys/class/gpio/gpio38/	OK*/

				0x098 0x7	/*GPIO 2_4 		/sys/class/gpio/gpio68/	OK*/

				0x094 0x7	/*GPIO 2_3 		/sys/class/gpio/gpio67/	OK*/

				0x028 0x7	/*GPIO 0_26 	/sys/class/gpio/gpio26/ OK*/

				0x038 0x7	/*GPIO 1_14 	/sys/class/gpio/gpio46/	OK*/

				0x08c 0x7	/*R1 GPIO 2_1	/sys/class/gpio/gpio65/	OK*/

				0x084 0x7	/*R2 GPIO1_31 	/sys/class/gpio/gpio63/ OK*/

				0x014 0x7	/*R3 GPIO 1_5 	/sys/class/gpio/gpio37/	OK*/

				0x004 0x7	/*R4 GPIO 1_1 	/sys/class/gpio/gpio33/	OK*/

				0x080 0x27	/*AP GPIO 1_30	/sys/class/gpio/gpio62/	OK*/

			>;

        };

};

Still didnt work, should i enable something in the kernel configuration ? i donā€™t know what iā€™m missing

I think/believe that adding pinmux declaration like you have done, does not actually set the pinmux, it is only giving a name to a set of pinmux configs that are used elsewhere. You can define multiple pinctrls for the same pin and this is done in the BBAi64 devicetree

It is only when they are included in a relevant section using pinctrl-x = <&your_pin_mux>; that the pin muxing is actually performed.

I would imagine by default the GPIO pins are set to input at reset, but you would need to check the datasheet. The fact that exporting them does not work, could be down to other factors.

ok thanks @benedict.hewson ! so i tried something like the"input" at the bottom, should it work , if not what should i change :

leds {
pinctrl-names = ā€œdefaultā€;
pinctrl-0 = <&user_leds_s0>;

	compatible = "gpio-leds";

	led2 {
		label = "beaglebone:green:usr0";
		gpios = <&gpio1 21 GPIO_ACTIVE_HIGH>;
		linux,default-trigger = "heartbeat";
		default-state = "off";
	};

	led3 {
		label = "beaglebone:green:usr1";
		gpios = <&gpio1 22 GPIO_ACTIVE_HIGH>;
		linux,default-trigger = "mmc0";
		default-state = "off";
	};

	led4 {
		label = "beaglebone:green:usr2";
		gpios = <&gpio1 23 GPIO_ACTIVE_HIGH>;
		linux,default-trigger = "cpu0";
		default-state = "off";
	};

	led5 {
		label = "beaglebone:green:usr3";
		gpios = <&gpio1 24 GPIO_ACTIVE_HIGH>;
		linux,default-trigger = "mmc1";
		default-state = "off";
	};
	input_gpio {
            label = "gpio_input";
            gpios = <&gpio3 114 GPIO_ACTIVE_HIGH>;
        };
};

If you need an output then you could do that and use the /sys/class/led interface to control it.

However the led driver will probably grab the gpio pin, so you canā€™t then export it. It will also probably make the GPIO port an output as it is expecting to drive an led.

Not sure how you would go about doing something for an input assuming you donā€™t use gpio-keys ( which will also grab the pin, so no exporting)

In other systems I have used there is often a section that configures pins, not tied to any specific peripheral and I have always added my config stuff there as needed. Donā€™t think anything similar exists for the BB although I have not gone through the various dts files. Over the years they have changed quite a bit.

If you really want to use the latest kernel you should use libgpio. Sooner or later you will have no choice.