This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

AM625: Cant set GPIOs, neither output or input

Part Number: AM625

Hi:

Im trying to set a basic group of GPIOs on the Kernel's device tree but nothing seems to work, if I set a pin as Input, applying voltage to it does nothing (gpioget always return 0), setting it as output also does nothing (gpioset gpiochip1 <pin number>=1/0, no change on the pin)

here is the relevant sections of the device tree

&main_pmx0 {
 ...

	gpio1_pins_default: gpio1-default-pins {
		pinctrl-single,pins = <
			AM62X_IOPAD(0x00ac, PIN_OUTPUT, 7) /* (L21) GPMC0_CSn1.GPIO0_42 */
			AM62X_IOPAD(0x00b0, PIN_INPUT, 7) /* (K22) GPMC0_CSn2.GPIO0_43 */
			AM62X_IOPAD(0x0168, PIN_OUTPUT, 7) /* (AE21) RGMII2_TXC.GPIO0_88 */
			AM62X_IOPAD(0x00b8, PIN_OUTPUT, 7) /* (U22) VOUT0_DATA0.GPIO0_45 */
		>;
	};
};

&main_gpio0 {
	status = "okay";
    // pinctrl-names = "default";
	pinctrl-0 = <&gpio1_pins_default>;
	gpio-line-names = 
	 		  "", "", "", "", "", "", "", "", "", "",
			  "", "", "", "", "", "", "", "", "", "",
			  "", "", "", "", "", "", "", "", "", "",
			  "", "", "", "", "", "", "", "", "", "",
			  "", "", "mcu_boot", "factory_reset", "", "test_pin", "", "", "", "",
			  "", "", "", "", "", "", "", "", "", "",
			  "", "", "", "", "", "", "", "", "", "",
			  "", "", "", "", "", "", "", "", "", "",
			  "", "", "", "", "", "", "", "", "mcu_reset", "",
			  "", "";

	st_mcu_reset {
		gpios = <88 GPIO_ACTIVE_LOW>;
		output-low;
		line-name = "mcu_reset";
	};

	st_mcu_boot {
		gpios = <42 GPIO_ACTIVE_HIGH>;
		// gpio-hog;
		output-high;
		line-name = "mcu_boot";
	};

	factory_reset {
		gpios = <43 GPIO_ACTIVE_LOW>;
		input;
		line-name = "factory_reset";
	};
	
	test_pin {
		gpios = <45 GPIO_ACTIVE_HIGH>;
		output-high;
		line-name = "test_pin";
	};
};

Your help is much appreciated. 

  • Hello,

    1. Are you using a TI EVM or Custom Hardware?

    2. pinctrl-names = "default"; was commented out. The reference requires this. Is there a reason it was removed?

    3. Make sure that gpiochip1 is the correct chip number for GPIO0 which should have an address of 0x00600000/600000.gpio. Can you confirm this?

    4. Can you share the output of gpioinfo 1 ? Lets see if the names are represented. I am unsure if it would use the line-name under each pin or gpio-line-names under main_gpio0. Since both strings used are the exact same, try changing one of them and it will indicate which is being used.

    Best Regards,

    Anshu

  • Anshu:

    Thanks a lot for such a quick reply, here are the answers:

    1- Im using a non TI EVK 

    2- If I uncoment "pinctrl-names = "default"", gpioinfo 1 output is quite strange, only one name and less IOs:

    gpiochip1 - 52 lines:
            line   0:      unnamed       unused   input  active-high 
            ...
            line   8:      unnamed         "id"   input  active-high [used]
            ... 
            line  51:      unnamed       unused   input  active-high 

    3- gpio 0 and 1 are declared in k3-am65-main.dtsi:

    	main_gpio0: gpio@600000 {
    		compatible = "ti,am654-gpio", "ti,keystone-gpio";
    		reg = <0x0 0x600000 0x0 0x100>;
    		gpio-controller;
    		#gpio-cells = <2>;
    		interrupt-parent = <&intr_main_gpio>;
    		interrupts = <192>, <193>, <194>, <195>, <196>, <197>;
    		interrupt-controller;
    		#interrupt-cells = <2>;
    		ti,ngpio = <96>;
    		ti,davinci-gpio-unbanked = <0>;
    		clocks = <&k3_clks 57 0>;
    		clock-names = "gpio";
    	};
    
    	main_gpio1: gpio@601000 {
    		compatible = "ti,am654-gpio", "ti,keystone-gpio";
    		reg = <0x0 0x601000 0x0 0x100>;
    		gpio-controller;
    		#gpio-cells = <2>;
    		interrupt-parent = <&intr_main_gpio>;
    		interrupts = <200>, <201>, <202>, <203>, <204>, <205>;
    		interrupt-controller;
    		#interrupt-cells = <2>;
    		ti,ngpio = <90>;
    		ti,davinci-gpio-unbanked = <0>;
    		clocks = <&k3_clks 58 0>;
    		clock-names = "gpio";
    	};

    /sys/devices/platform/bus@f0000/601000.gpio/gpiochip1
    /sys/devices/platform/bus@f0000/bus@f0000:bus@4000000/4201000.gpio/gpiochip0
    
    cat /sys/kernel/debug/gpio
    gpiochip2: GPIOs 344-395, parent: platform/601000.gpio, 601000.gpio:
     gpio-352 (                    |id                  ) in  hi 
    
    gpiochip1: GPIOs 396-487, parent: platform/600000.gpio, 600000.gpio:
     gpio-438 (mcu_boot_1          )
     gpio-439 (factory_reset_1     )
     gpio-441 (test_pin_1          |test_pin_2          ) in  lo 
     gpio-484 (mcu_reset_1         )
    
    gpiochip0: GPIOs 488-511, parent: platform/4201000.gpio, 4201000.gpio:

    4- Made the following changes to the dtb

    &main_gpio0 {
    	status = "okay";
        // pinctrl-names = "default";
    	pinctrl-0 = <&gpio1_pins_default>;
    	gpio-line-names = 
    	 		  "", "", "", "", "", "", "", "", "", "",
    			  "", "", "", "", "", "", "", "", "", "",
    			  "", "", "", "", "", "", "", "", "", "",
    			  "", "", "", "", "", "", "", "", "", "",
    			  "", "", "mcu_boot_1", "factory_reset_1", "", "test_pin_1", "", "", "", "",
    			  "", "", "", "", "", "", "", "", "", "",
    			  "", "", "", "", "", "", "", "", "", "",
    			  "", "", "", "", "", "", "", "", "", "",
    			  "", "", "", "", "", "", "", "", "mcu_reset_1", "",
    			  "", "";
    	
    	// enet_pdown {
    	// 	gpio-hog;
    	// 	gpios = <9 GPIO_ACTIVE_LOW>;
    	// 	output-low;
    	// 	line-name = "enet_pdown";
    	// };
    
    	st_mcu_reset {
    		gpios = <88 GPIO_ACTIVE_LOW>;
    		output-low;
    		line-name = "mcu_reset_2";
    	};
    
    	st_mcu_boot {
    		gpios = <42 GPIO_ACTIVE_HIGH>;
    		output-high;
    		line-name = "mcu_boot_2";
    	};
    
    	factory_reset {
    		gpios = <43 GPIO_ACTIVE_LOW>;
    		input;
    		line-name = "factory_reset_2";
    	};
    	
    	test_pin {
    		gpios = <45 GPIO_ACTIVE_HIGH>;
    		gpio-hog;
    		output-high;
    		line-name = "test_pin_2";
    	};
    };

    gpioinfo 1
    gpiochip1 - 92 lines:
            line   0:      unnamed       unused   input  active-high 
            ...
            line  41:      unnamed       unused   input  active-high 
            line  42: "mcu_boot_1"       unused   input  active-high 
            line  43: "factory_reset_1" unused input active-high 
            line  44:      unnamed       unused   input  active-high 
            line  45: "test_pin_1" "test_pin_2"   input  active-high [used]
            ... 
            line  87:      unnamed       unused   input  active-high 
            line  88: "mcu_reset_1" unused input active-high 
            line  89:      unnamed       unused   input  active-high 
            ...

  • Hi Lisandro,

    gpio 0 and 1 are declared in k3-am65-main.dtsi:

    Can you clarify which device is being used? For AM62x, it should be k3-am625-main.dtsi.

    From the changes you made in section 4, seems like gpio-line-name changes the name and line-name changes the consumer.  Looks like GPIO0_45 (line 45: "test_pin_1" "test_pin_2" input active-high [used]) has the [used] tag. If you try to use gpioset or get on that pin, do you get a "Device or Resource Busy" error?

    A possible fix is removing/commenting out the line-name within the pin node. It might be looking for a consumer named "test_pin_2" or the respective name of each pin which causes the kernel to stop any changes, but the consumer may not exist.

    Best Regards,
    Anshu

  • Hi Anshu:

    Thanks again for your help.

    - You are right, main_gpio0 & 1 are defined in k3-am62-main.dtsi

    - "test_pin_1" was shown as [used] because I "hogged" it in an attempt to force the status during bootup with no luck

    - I have commented out the names in the pin nodes, still nothing. Last attempt was to comment all the pin nodes and leave only the names:

    &main_gpio0 {
    	// status = "okay";
    	pinctrl-0 = <&gpio1_pins_default>;
    	gpio-line-names = 
    	 		  "", "", "", "", "", "", "", "", "", "",
    			  "", "", "", "", "", "", "", "", "", "",
    			  "", "", "", "", "", "", "", "", "", "",
    			  "", "", "", "", "", "", "", "", "", "",
    			  "", "", "mcu_boot_1", "factory_reset_1", "", "test_pin_1", "", "", "", "",
    			  "", "", "", "", "", "", "", "", "", "",
    			  "", "", "", "", "", "", "", "", "", "",
    			  "", "", "", "", "", "", "", "", "", "",
    			  "", "", "", "", "", "", "", "", "mcu_reset_1", "",
    			  "", "";
    
    	// st_mcu_reset {
    	// 	gpios = <88 GPIO_ACTIVE_LOW>;
    	// 	output-low;
    	// };
    
    	// st_mcu_boot {
    	// 	gpios = <42 GPIO_ACTIVE_HIGH>;
    	// 	output-high;
    	// };
    
    	// factory_reset {
    	// 	gpios = <43 GPIO_ACTIVE_LOW>;
    	// 	input;
    	// };
    	
    	// test_pin {
    	// 	gpios = <&main_gpio0 45 GPIO_ACTIVE_HIGH>;
    	// 	output-high;
    	// };
    };

    - I also tried writing/reading both using sysfs and libgpiod, and the only thing I can see is that when setting the direction on sysfs, it gets reflected on gpioinfo, though nothing on the physical pins:

    cat /sys/kernel/debug/gpio                                                                                                                        
    gpiochip2: GPIOs 344-395, parent: platform/601000.gpio, 601000.gpio:                                                                                                      
     gpio-352 (                    |id                  ) in  hi                                                                                                              
                                                                                                                                                                               
    gpiochip1: GPIOs 396-487, parent: platform/600000.gpio, 600000.gpio:                                                                                                      
     gpio-438 (mcu_boot_1          )                                                                                                                                          
     gpio-439 (factory_reset_1     )                                                                                                                                          
     gpio-441 (test_pin_1          )                                                                                                                                          
     gpio-484 (mcu_reset_1         )
    
     ~# echo 441 > /sys/class/gpio/export                                                                                                                
     ~# echo out > /sys/class/gpio/gpio441/direction                                                                                                      
     ~# cat /sys/class/gpio/gpio441/direction                                                                                                            
    out                                                                                                                                                                        
     ~# echo 1 > /sys/class/gpio/gpio441/value                                                                                                            
     ~# cat /sys/class/gpio/gpio441/value                                                                                                                
    0                                                                                                                                                                          
     ~# gpioinfo 1                                                                                                                                        
    gpiochip1 - 92 lines:                                                                                                                                                      
            line   0:      unnamed       unused   input  active-high                                                                                                          
    ...        line  42: "mcu_boot_1"       unused   input  active-high                                                                                                          
            line  43: "factory_reset_1" unused input active-high                                                                                                              
            line  44:      unnamed       unused   input  active-high                                                                                                          
            line  45: "test_pin_1"      "sysfs"  output  active-high [used]                                                                                                    
    ...                                                                                                          
            line  91:      unnamed       unused   input  active-high

  • Hi Lisandro,

    Lets focus on one pin to ensure it is working correctly. For now, remove the naming. If one pin is confirmed working, then other pins can be added along with the names.

    Can you try setting up your device tree this way? This should be for GPIO0_42.

    &main_pmx0 { //add the pin definition under this node
    	gpio0_pins_default: gpio0-default-pins { //Changed it from 1 to 0 for consistency GPIO0
    		pinctrl-single,pins = <
    			AM62X_IOPAD(0x00ac, PIN_OUTPUT, 7) /* (L21) GPMC0_CSn1.GPIO0_42 */
    		>;
    	};
    };
    
    
    &main_gpio0 { //reference for the pin
    	pinctrl-names = "default";
    	pinctrl-0 = <&gpio0_pins_default>;
    };

    Then with this new device tree, try "gpioset 1 42=1" in the terminal. This should set GPIO0_42 (which is under gpiochip1) to high.

    Best Regards,
    Anshu

  • Thanks Anshu!!!

    The issue was 

    AM62X_IOPAD(0x0168, PIN_OUTPUT, 7) /* (AE21) RGMII2_TXC.GPIO0_88
    which was already in use by the rmii, changed that io to another pin and everything is working.
    Weirdly just that wrong declaration made all the other GPIOs to not work Shrug‍♂️
  • Thanks for showing your solution Lisandro. This ticket will be closed.