How to control the tca9539 gpio pins in kernel.

I try to control tca9539 pins as follow:

dts:
reset-gpios = <&gpio_i2c_0_74 4 0>;

kernel:
int gpio;
gpio = of_get_named_gpio(ep, “reset-gpios”, 0);

and gpio vaule is always 0.

How to get the correct gpio number and if “gpio_set_value()” can set gpio to high or low.

hello suchb,

according to the device tree below,

<i>$l4t-r32.2/kernel_src/hardware/nvidia/platform/t18x/quill-dev/kernel-dts/quill-dev-platforms/tegra186-cvb-prod-p2597-b00-p3310-1000-a00-00.dtsi</i>

                gpio_i2c_0_74: gpio@74 {
                        compatible = "ti,tca9539";
                        reg = <0x74>;
                        gpio-controller;
                        #gpio-cells = <2>;
                        vcc-supply = <&battery_reg>;
                        enable-touch-rails {
                                gpio-hog;
                                gpios = <1 0 2 0>;
                                output-high;
                                label = "enable-touch-rail_1", "enable-touch-rail_2";
                        };
                };

could you please try to get the GPIO name by “gpio_i2c_0_74” directly.
thanks

Thank you JerryChang,

Where can I find the following explanations for these words:
enable-touch-rails
gpio-hog
label

I really don’t understand what you mean about “could you please try to get the GPIO name by “gpio_i2c_0_74” directly.”

Could you give me more specific explanation.

Thanks.

hello suchb,

On the TX2 dev kit, the I/Os on gpio_i2c_0_74 (I2C_GP1 addr:0x74) were used for external device control like M.2, LCD.

By Default,
TX2 has two TCA on i2c0 at address 0x74 and 0x77.
you would need to make sure that the new TCA they added is having a new address or on a different i2c bus,
for example,

gpio_i2c_0_74: gpio@74 {

gpio_i2c_0_77: gpio@77 {

Thank you JerryChang,
In my case I use i2c0 and tca9539 i2caddr is 0x74. When system startup I can control all the tca9539 pins in shell:
i2cset -f -y 0 0x74 0x6 0xXX

tca9539 is successfully probed:
[ 0.519084] gpiochip_setup_dev: registered GPIOs 240 to 255 on device: gpiochip2 (tca9539)

The problem that bothers me is How to control tca9539 pins(like P04 P14…) in kernel driver code.
I want to use some of those pins as reset and standy signal.

bellow is some of my modify but failed to get vaild gpio of tca9539:

dts:
	i2c@3160000 {
                ......

		gpio_i2c_0_74: gpio@74 {
			compatible = "ti,tca9539";
			reg = <0x74>;
			gpio-controller;
			#gpio-cells = <2>;
			vcc-supply = <&battery_reg>;
		};
                ......
        };


        i2c@31e0000 {
                ......
                device@1f {
                        ......

                        enable-active-low;
			reset-gpios = <&gpio_i2c_0_74 4 0>; //P04
                        
                        ......
       };


kernel:

       gpio = of_get_named_gpio(ep, "standby-gpios", 0);

please also check Topic 1058267 for reference of controlling GPIO.