Gpio contorl

I add IO control in my driver, I can’t control io;
I call the following function in function lkt4304_r probe.

why?

  static int lkt4304_reset(void)
{
    int ret;
    printk("llkt4304_reset\n"); 
    ret = gpio_request(66, "lkt4304");
    if (ret) {
        printk("lkt4304_reset :Unable to request power GPIO\n");
        return ret;
    }

    ret = gpio_direction_output(66,GPIOF_DIR_OUT);
    if (ret) {
        printk("lkt4304_reset :Unable to gpio_direction_output\n");
        return ret;
    }
    gpio_set_value(66,0);

    msleep(200);
    gpio_set_value(66,1);
    gpio_free(66);


    return 0;
}

Now use the following instruction instead of the lkt4304_reset( function,
echo 66 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio66/direction
echo 0 > /sys/class/gpio/gpio66/value
echo 1 > /sys/class/gpio/gpio66/value

hello tpwang2000,

may I know which GPIO pin you’re actually used for gpio-66?
you may also refer to pinmux spreadsheets for reference,
thanks

it is right , I can control the hardware ,the GPIO is GPIO_PI_02,the number is 66
using the following commond
echo 66 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio66/direction
echo 0 > /sys/class/gpio/gpio66/value
echo 1 > /sys/class/gpio/gpio66/value

and I add my driver lkt4304 in the directory(kernerl/drivers/i2c), config = Y

My hardware is reset by gpio-66

hello tpwang2000,

according to device tree setting, this pin has default configuration as output-low.
for example,

 	gpio@6000d000 {
 		gpio-init-names = "default";
 		gpio-init-0 = <&gpio_default>;
 
 		gpio_default: default {
 			gpio-output-low = <
                            ...
                            TEGRA_GPIO(I, 2)
                            >

since there’s already has pin definition, could you please have a try to control GPIO directly in the kernel driver with the API, i.e. gpio_set_value()
thanks

I do it,in the function lkt4304_reset,
then I call the function lkt4304_reset in the function lkt4304_probe

gpio_set_value(66,0);
gpio_set_value(66,1);

but can not control it

I do it,in the function lkt4304_reset,
then I call the function lkt4304_reset in the function lkt4304_probe

gpio_set_value(66,0);
gpio_set_value(66,1);

but can not control it
static int lkt4304_reset(void)
{
int ret;
printk(“llkt4304_reset\n”);
ret = gpio_request(66, “lkt4304”);
if (ret) {
printk(“lkt4304_reset :Unable to request power GPIO\n”);
return ret;
}

    ret = gpio_direction_output(66,GPIOF_DIR_OUT);
    if (ret) {
        printk("lkt4304_reset :Unable to gpio_direction_output\n");
        return ret;
    }
    gpio_set_value(66,0);

    msleep(200);
    gpio_set_value(66,1);
    gpio_free(66);


    return 0;
}

hello tpwang2000,

I meant please exclude gpio_request and gpio_direction_output;
please calling gpio_set_value() directly to control the pin for verification.

Modify this function lkt4304_reset as following?

static int lkt4304_reset(void)
{
	int ret;
	printk(“llkt4304_reset\n”);
	gpio_set_value(66,0);
	msleep(200);
	gpio_set_value(66,1);
	return 0;
}

hello tpwang2000,

this GPIO control should works once your kernel function, lkt4304_reset() being called.
BTW, how you monitor the GPIO state changes, are you probing the pin state?
thanks

Maybe

but I call lkt4304_reset(),
But after I use it, the driver doesn’t work properly

I test the dirvier, the error is following:

nano@nano-desktop:/sys/class/gpio$ lkt_case_normal
cmd index?d->0x00
cmd index?d->0x01
cmd index?[ 3252.896019] tegra-i2c 7000c000.i2c: no acknowledge from address 0x28
d->0x02
cmd index?d->0x03
cmd index?d->0x04
cmd index?d->0x05
cmd index?d->0x06
write random_cmd size =-1, cmp=7
[ 3252.917068] tegra-i2c 7000c000.i2c: no acknowledge from address 0x28
read file size=-1
[ 3252.935103] tegra-i2c 7000c000.i2c: no acknowledge from address 0x28
cry wr_size=-1,cmp=15
[ 3252.954395] tegra-i2c 7000c000.i2c: no acknowledge from address 0x28
read_cmd=-1,cmp=7
[ 3252.975562] tegra-i2c 7000c000.i2c: no acknowledge from address 0x28

when I use the following commond,My driver is OK

why?
echo 66 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio66/direction
echo 0 > /sys/class/gpio/gpio66/value
echo 1 > /sys/class/gpio/gpio66/value

And when I run the command: sudo ./apply_binaries.sh
I reported the following error
Preparing to unpack …/python3-jetson-gpio_2.0.11_arm64.deb …
qemu: Unsupported syscall: 278

ubuntu@ubuntu:~/nano/R32.4.4/Linux_for_Tegra$ sudo ./apply_binaries.sh
[sudo] password for ubuntu:
Using rootfs directory of: /home/ubuntu/nano/R32.4.4/Linux_for_Tegra/rootfs
/home/ubuntu/nano/R32.4.4/Linux_for_Tegra/nv_tegra/nv-apply-debs.sh
Root file system directory is /home/ubuntu/nano/R32.4.4/Linux_for_Tegra/rootfs
Copying public debian packages to rootfs
Start L4T BSP package installation
QEMU binary is not available, looking for QEMU from host system
Found /usr/bin/qemu-aarch64-static
Installing QEMU binary in rootfs
~/nano/R32.4.4/Linux_for_Tegra/rootfs ~/nano/R32.4.4/Linux_for_Tegra
Installing BSP Debian packages in /home/ubuntu/nano/R32.4.4/Linux_for_Tegra/rootfs
(Reading database … 142191 files and directories currently installed.)
Preparing to unpack …/nvidia-l4t-core_32.4.4-20201016124427_arm64.deb …
Pre-installing… skip compatibility checking.
Unpacking nvidia-l4t-core (32.4.4-20201016124427) over (32.4.4-20201016124427) …
Setting up nvidia-l4t-core (32.4.4-20201016124427) …
(Reading database … 142191 files and directories currently installed.)
Preparing to unpack …/jetson-gpio-common_2.0.11_arm64.deb …
Unpacking jetson-gpio-common (2.0.11) over (2.0.11) …
Preparing to unpack …/python3-jetson-gpio_2.0.11_arm64.deb …
qemu: Unsupported syscall: 278
Unpacking python3-jetson-gpio (2.0.11) over (2.0.11) …
Preparing to unpack …/python-jetson-gpio_2.0.11_arm64.deb …
Unpacking python-jetson-gpio (2.0.11) over (2.0.11) …
Preparing to unpack …/nvidia-l4t-3d-core_32.4.4-20201016124427_arm64.deb …
Unpacking nvidia-l4t-3d-core (32.4.4-20201016124427) over (32.4.4-20201016124427) …
Preparing to unpack …/nvidia-l4t-apt-source_32.4.4-20201016124427_arm64.deb …
Unpacking nvidia-l4t-apt-source (32.4.4-20201016124427) over (32.4.4-20201016124427) …
Preparing to unpack …/nvidia-l4t-camera_32.4.4-20201016124427_arm64.deb …
Unpacking nvidia-l4t-camera (32.4.4-20201016124427) over (32.4.4-20201016124427) …
Preparing to unpack …/nvidia-l4t-configs_32.4.4-20201016124427_arm64.deb …
Unpacking nvidia-l4t-configs (32.4.4-20201016124427) over (32.4.4-20201016124427) …
Preparing to unpack …/nvidia-l4t-cuda_32.4.4-20201016124427_arm64.deb …
Unpacking nvidia-l4t-cuda (32.4.4-20201016124427) over (32.4.4-20201016124427) …
Preparing to unpack …/nvidia-l4t-firmware_32.4.4-20201016124427_arm64.deb …
Unpacking nvidia-l4t-firmware (32.4.4-20201016124427) over (32.4.4-20201016124427) …
Preparing to unpack …/nvidia-l4t-graphics-demos_32.4.4-20201016124427_arm64.deb …
Unpacking nvidia-l4t-graphics-demos (32.4.4-20201016124427) over (32.4.4-20201016124427) …

Can I keep the DEB file I download when I update? in the path “/var/cache/apt/archives”
when finish apt install,the system auoremove /var/cache/apt/archives/*.deb
wo hope that I can keep it

hello tpwang2000,

you should resolve this issue, it usually caused by regulator issue to make i2c not working.

when not using lkt4304_reset() , the I2c is working, but must using the following commond
echo 66 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio66/direction
echo 0 > /sys/class/gpio/gpio66/value
echo 1 > /sys/class/gpio/gpio66/value

when using lkt4304_reset() ,it is not working

hello tpwang2000,

what’s the full process of your lkt4304 kernel driver?
it seems to me you’re having reset function to clean some settings to make i2c not works.
those APIs to control GPIO perform same as linux commands you had point-out.

please resolve i2c no acknowledge issue.
thanks

Lk4304 is a device driver written by me. After the driver is loaded, I need to reset the “reset pin”. When I load the driver, I use “echo 1> / sys / class / gpio / gpio66 / value” to pull the reset pin up. my driver can work normally

But when using “gpio_set_value(66,1);”, the driver is not work, so the I2c is right (I call lkt4304_reset in the function lkt4304_probe )

My meanning, why using “echo” and “gpio_set_value” ,The result is different

hello tpwang2000,

what’s the pin state after you use the kernel API to set gpio?
please also check with, gpio_get_value(unsigned int gpio)