uboot - Device tree binding and dm_gpio_lookup_name("x",&desc)

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

uboot - Device tree binding and dm_gpio_lookup_name("x",&desc)

跳至解决方案
306 次查看
DavidFlir
Contributor II

For an imx91 based project I am stuck with defining my first GPIO as output.

I have read several posts where examples towards the device trees are explained but I am still getting the `-22` return value.

Defined in device tree:

	gpio_reset: gpio-reset {
		compatible = "gpio-reset";
		pinctrl-names = "default";
		reset-gpios = <&gpio1 8 GPIO_ACTIVE_LOW>;
		status = "okay";
		label = "RSTO";
		gpio-name = "RSTO";
		line-name = "RSTO";
        };

Here I tried adding label,gpio-name and line-name. Not sure which one is needed.


Then in function

static void board_gpio_init(void){
	struct gpio_desc desc;
	int ret;

	/* De-assert RSTO */
	ret = dm_gpio_lookup_name("RSTO", &desc);
	if (ret) {
		printf("%s lookup 'RSTO' failed ret = %d\n", __func__, ret);
		return;
	}
...
}

This always returns -22 and it's the first pin to look up.



Then I thought let's try a proven example code based on leds,

	gpio-leds {
		compatible = "gpio-leds";
		pinctrl-names = "default";
		pinctrl-0 = <&pinctrl_gpio_led>;

		led-0 {
			gpios = <&gpio3 26 GPIO_ACTIVE_HIGH>;
			default-state = "on";
		};
		led-1 {
			gpios = <&gpio3 27 GPIO_ACTIVE_HIGH>;
			default-state = "on";
		};

	};

Then
	ret = dm_gpio_lookup_name("led-1", &desc);

also returns -22
标记 (2)
0 项奖励
回复
1 解答
262 次查看
danielchen
NXP TechSupport
NXP TechSupport

HI @DavidFlir 

I would suggest you refer to the function in gpio-uclass.c

danielchen_0-1754466845499.png

 

Regards

Daniel

在原帖中查看解决方案

5 回复数
292 次查看
DavidFlir
Contributor II

I did find a missing _defconfig setting called 

CONFIG_IMX_RGPIO2P=y
 
with this setting I am able to do a succesful
ret = dm_gpio_lookup_name("gpio1_8", &desc);

But I still did not figure out how I can use the names defined in the .dts file instead of this gpio1_8.
`
0 项奖励
回复
271 次查看
danielchen
NXP TechSupport
NXP TechSupport

Hi David:

The dm_gpio_lookup_name() function does not parse gpio-name, or line-name from the device tree. It only understands the format "gpioX_Y" where

X is the GPIO controller

Y is the pin number.

 

If you are working in the Linux Kernel (not U-BOOT), you can use

struct gpio_desc *rst_gpio;
rst_gpio = devm_gpiod_get(&pdev->dev, "reset", GPIOD_OUT_LOW);

 

And define in DTS

reset-gpios = <&gpio1 8 GPIO_ACTIVE_LOW>;
gpio-names = "reset";

 

Regards

Daniel

0 项奖励
回复
265 次查看
DavidFlir
Contributor II

Thanks for reply!

I did notice this example:

https://github.com/nxp-imx/uboot-imx/blob/9383f8387dc76524524da69992db96c22195a57c/board/freescale/i...

ret = dm_gpio_lookup_name("adp5585-gpio4", &exp_sel_desc);
this seems to be another allowed format besides "gpioX_Y"
 
It's defined as
	adp5585: io-expander@34 {
		compatible = "adi,adp5585-00", "adi,adp5585";
		reg = <0x34>;
		#gpio-cells = <2>;
		gpio-controller;
		#pwm-cells = <3>;
		gpio-reserved-ranges = <5 1>;

		exp-sel-hog {
			gpio-hog;
			gpios = <4 GPIO_ACTIVE_HIGH>;
			output-low;
		};

So how can I check how the syntax should be? for instance: is it connecting with a ''_" or "-"... ?

0 项奖励
回复
263 次查看
danielchen
NXP TechSupport
NXP TechSupport

HI @DavidFlir 

I would suggest you refer to the function in gpio-uclass.c

danielchen_0-1754466845499.png

 

Regards

Daniel

260 次查看
DavidFlir
Contributor II

Ok so finding out which ports are actual available just requires a print like,

		len = uc_priv->bank_name ? strlen(uc_priv->bank_name) : 0;
		printf("%s: lookup %s\n", __func__,uc_priv->bank_name);
		if (!strncasecmp(name, uc_priv->bank_name, len)) {

And then I get to see the available&correct names on my console!

file location is `uboot/drivers/gpio/gpio-uclass.c`