u-boot: Read GPIO in SPL before DT init

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

u-boot: Read GPIO in SPL before DT init

368 Views
MB_stek
Contributor III

Hi,

we're using mainline u-boot v2025.01 on an imx8mm (on a custom board) and in order to select the u-boot device tree, I'm trying to read a GPI (gpio1_4) before the u-boot device tree gets initialized. However, reading the GPIO always gives "0" while the pin is actually (physically) on "1".

static iomux_v3_cfg_t const boardtype_pad[] = {
    IMX8MM_PAD_GPIO1_IO14_GPIO1_IO14 | MUX_PAD_CTRL(0x19)
};

void board_init_f(ulong dummy)
{
    int gpio1_14 = 0;
    uint32_t gpio1_dr;
    imx_iomux_v3_setup_multiple_pads(boardtype_pad,
					 ARRAY_SIZE(boardtype_pad));
    gpio_direction_input(IMX_GPIO_NR(1, 14));
    
    memcpy(&gpio1_dr, (void *)0x30200000, 4);
    gpio1_14 = (gpio1_dr & 0b0100000000000000) >> 14;
    printf("gpio1_dr = %#010x\n", gpio1_dr);
    printf("gpio1,14 = %i\n", gpio1_14);
}

We're using DM for GPIO, so the normal way of reading the GPIO would be to use the corresponding DM functions, which indeed work and the read result is "1" as expected:

int gpio1_14_dm = 0;	
uclass_get_device_by_name(UCLASS_GPIO,
			"gpio@30200000", &dev);
gpio_request_by_name(dev, "board-type", 0, &board_type, 
            GPIOD_IS_IN);
gpio1_14_dm = dm_gpio_get_value(&board_type);

However, we can't use the DM functions here since we need to read the GPIO before device tree initialization...

When I read the GPIO using above DM functions and then reading the DR register directly as shown above, also the DR read is successful and gives the correct GPIO value.

So, I'm assuming I'm only missing some initialization of the GPIO (which the DM functions obviously do), but I can't figure out, what. Maybe some clock init (but I couldn't find a clock relevant for GPIO1 in the imx8mm user manual)? Also, the DIR register should be 0x0 upon startup, so all pins set to input, which should also work without explicit initialization.

Anybody an idea what I could be missing here?

Kind regards,

Markus

Labels (1)
Tags (2)
0 Kudos
Reply
2 Replies

346 Views
Zhiming_Liu
NXP TechSupport
NXP TechSupport

Hi @MB_stek 

You can try to disable CONFIG_DM_GPIO and use gpio_get_value in drivers/gpio/mxc_gpio.c


Best Regards,
Zhiming

0 Kudos
Reply

315 Views
MB_stek
Contributor III

Hi Zhiming,

thanks for the hint!

Will give it a try to figure out more about the issue I'm seeing. However, I would prefer to still use DM for the rest of the SPL code if possible.

Kind regards,

Markus