How do you toggle GPIO during Linux boot up?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How do you toggle GPIO during Linux boot up?

2,530 Views
bobbyeshleman1
Contributor I

I have a functioning U-Boot on my IMX6SX-based board.  I am using the imx6sxsabresd u-boot and Linux configurations.  I am able to toggle GPIO during U-Boot boot up.  I am attempting to toggle the exact same GPIO during Linux boot up so I can use the GPIO toggling as a debug marker (I do not have serial on Linux yet).

I am using source from imx-yocto-L4.9.88_2.0.0.

Below is my code in U-Boot that successfully toggles the GPIO (pin 6, pad 1).

static iomux_v3_cfg_t const test_gpio_pads[] = {
    MX6_PAD_GPIO1_IO06__GPIO1_IO_6 | MUX_PAD_CTRL(NO_PAD_CTRL),
    MX6_PAD_GPIO1_IO07__GPIO1_IO_7 | MUX_PAD_CTRL(NO_PAD_CTRL),
};

static void test_gpio(void)
{
    int i;

    imx_iomux_v3_setup_multiple_pads(test_gpio_pads, ARRAY_SIZE(test_gpio_pads));
    gpio_request(IMX_GPIO_NR(1, 6), "GPIO Pad 1 Pin 6");

    for(i=0; i<3; i++) {
        printf("%d: GPIO on\r\n", i);
        gpio_direction_output(IMX_GPIO_NR(1, 6), 1);
        gpio_set_value(IMX_GPIO_NR(1, 6), 1);
        mdelay(1000);
        printf("%d: GPIO off\r\n", i);
        gpio_direction_output(IMX_GPIO_NR(1, 6), 0);
        gpio_set_value(IMX_GPIO_NR(1, 6), 0);
        mdelay(1000);
    }
 
    printf("Ending GPIO test\r\n");
}

How would I do the equivalent in Linux?

Thanks in advance.

Labels (2)
0 Kudos
1 Reply

2,053 Views
igorpadykov
NXP Employee
NXP Employee

Hi Bobby

some gpio codes examples can be found in L4.9.88 linux/root/arch/arm/mach-imx folder, like

pm-imx7.c\mach-imx\arm\arch - linux-imx - i.MX Linux kernel 

Best regards
igor
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos