<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Using GPIO in u-boot with imx8qxp in i.MX Processors</title>
    <link>https://community.nxp.com/t5/i-MX-Processors/Using-GPIO-in-u-boot-with-imx8qxp/m-p/1778042#M217676</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I try to use a GPIO (connected to a micro switch) in my u-boot process as a boot option (with the u-boot commands "gpio input" and gpio read").&lt;/P&gt;&lt;P&gt;The GPIO I try to read is view under linux as GPIO 4, and declared in the linux dts as &lt;FONT face="courier new,courier"&gt;IMX8QXP_ESAI0_TX0_LSIO_GPIO0_IO04&lt;/FONT&gt;.&lt;/P&gt;&lt;P&gt;In my u-boot dts, I added a line &lt;FONT face="courier new,courier"&gt;SC_P_ESAI0_TX0_LSIO_GPIO0_IO04 0x00000060&lt;/FONT&gt; under iomuxc -&amp;gt;&amp;nbsp; imx8qxp-mek -&amp;gt; hoggrp.&lt;/P&gt;&lt;P&gt;I tried multiple syntax to get the GPIO, but that always end with the same error : &lt;FONT face="courier new,courier"&gt;GPIO: 'gpio0_4' not found&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;I so added some logs in gpio-uclass.c -&amp;gt; dm_gpio_lookup_name, and it looks like &lt;FONT face="courier new,courier"&gt;uclass_first_device(UCLASS_GPIO, &amp;amp;dev)&lt;/FONT&gt; return an empty list.&lt;/P&gt;&lt;P&gt;How could I use the GPIO in u-boot ? Is this a dts issue ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 20 Dec 2023 14:53:49 GMT</pubDate>
    <dc:creator>Anthony_R</dc:creator>
    <dc:date>2023-12-20T14:53:49Z</dc:date>
    <item>
      <title>Using GPIO in u-boot with imx8qxp</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/Using-GPIO-in-u-boot-with-imx8qxp/m-p/1778042#M217676</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I try to use a GPIO (connected to a micro switch) in my u-boot process as a boot option (with the u-boot commands "gpio input" and gpio read").&lt;/P&gt;&lt;P&gt;The GPIO I try to read is view under linux as GPIO 4, and declared in the linux dts as &lt;FONT face="courier new,courier"&gt;IMX8QXP_ESAI0_TX0_LSIO_GPIO0_IO04&lt;/FONT&gt;.&lt;/P&gt;&lt;P&gt;In my u-boot dts, I added a line &lt;FONT face="courier new,courier"&gt;SC_P_ESAI0_TX0_LSIO_GPIO0_IO04 0x00000060&lt;/FONT&gt; under iomuxc -&amp;gt;&amp;nbsp; imx8qxp-mek -&amp;gt; hoggrp.&lt;/P&gt;&lt;P&gt;I tried multiple syntax to get the GPIO, but that always end with the same error : &lt;FONT face="courier new,courier"&gt;GPIO: 'gpio0_4' not found&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;I so added some logs in gpio-uclass.c -&amp;gt; dm_gpio_lookup_name, and it looks like &lt;FONT face="courier new,courier"&gt;uclass_first_device(UCLASS_GPIO, &amp;amp;dev)&lt;/FONT&gt; return an empty list.&lt;/P&gt;&lt;P&gt;How could I use the GPIO in u-boot ? Is this a dts issue ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Dec 2023 14:53:49 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/Using-GPIO-in-u-boot-with-imx8qxp/m-p/1778042#M217676</guid>
      <dc:creator>Anthony_R</dc:creator>
      <dc:date>2023-12-20T14:53:49Z</dc:date>
    </item>
    <item>
      <title>Re: Using GPIO in u-boot with imx8qxp</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/Using-GPIO-in-u-boot-with-imx8qxp/m-p/1778852#M217730</link>
      <description>&lt;P&gt;Some news of my investigation on this topic :&amp;nbsp;&lt;FONT face="courier new,courier"&gt;uclass_first_device&lt;/FONT&gt; fail because it try to probe every devices it can found, and stop at the first failure.&lt;/P&gt;&lt;P&gt;So I went away of the u-boot commands, and write my own function to read that GPIO, as following :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-SPOILER&gt;&lt;LI-CODE lang="c"&gt;int get_gpio_cfg3_value(void){
	char* devicename = "gpio@5d080000";
	int offset = 4;

	struct gpio_dev_priv *uc_priv = NULL;
	struct udevice *dev;
	int ret;

	ret = uclass_find_device_by_name(UCLASS_GPIO,devicename,&amp;amp;dev);
	if(ret){
		printf("uclass_find_device_by_name failed with code %d\n", ret);
		return -1;
	}

	ret = device_probe(dev);
	if(ret){
		printf("device_probe failed with code %d\n", ret);
		return -1;
	}
			
	printf("dev found : %s %s %llx\n", dev-&amp;gt;name, dev-&amp;gt;driver-&amp;gt;name, dev-&amp;gt;uclass_priv);

	uc_priv = dev-&amp;gt;uclass_priv;
	if(!uc_priv){
		printf("dev_get_uclass_priv failed with code %d\n",ret);
		return -1;
	}

	printf("Bank name : %s, number of GPIO in dev : %d\n", uc_priv-&amp;gt;bank_name, uc_priv-&amp;gt;gpio_count);
	
	if (gpio_get_ops(dev)-&amp;gt;request) {
		ret = gpio_get_ops(dev)-&amp;gt;request(dev, offset, "cfg3");
		if(ret){
			printf("gpio ops.request failed with code %d\n",ret);
			return -1;
		}
	}else{
		printf("gpio request is NULL\n");
	}
	ret = gpio_get_ops(dev)-&amp;gt;direction_input(dev, offset);
	if(ret){
		printf("gpio direction_input failed with code %d\n",ret);
		return -1;
	}

	int value = gpio_get_ops(dev)-&amp;gt;get_value(dev, offset);

	printf("Value of GPIO %s%d is %d\n", uc_priv-&amp;gt;bank_name, offset, value);
	
	if(gpio_get_ops(dev)-&amp;gt;rfree){
		ret = gpio_get_ops(dev)-&amp;gt;rfree(dev, offset);
		if(ret){
			printf("gpio rfree failed  with code %d\n",ret);
			return -1;
		}
	}else{
		printf("gpio rfree is NULL\n");
	}
	return value;
}&lt;/LI-CODE&gt;&lt;/LI-SPOILER&gt;&lt;P&gt;With that code, I obtain the following output, and all seems to work as expected :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;dev found : gpio@5d080000 gpio_mxc fae62350&lt;BR /&gt;Bank name : GPIO0_, number of GPIO in dev : 32&lt;BR /&gt;gpio request is NULL&lt;BR /&gt;Value of GPIO GPIO0_4 is 0&lt;BR /&gt;gpio rfree is NUL&lt;/PRE&gt;&lt;P&gt;But, the value read is always 0, independent from my switch configuration. Under linux, using /sys/class/gpio/gpio4 works well.&lt;/P&gt;&lt;P&gt;I looked at mxc_gpio.c:mxc_gpio_get_value and I see no obvious reason for the real value to not being read as it just use readl on the register.&lt;BR /&gt;&lt;BR /&gt;Should I add something in my dts file ? Is it normal that the mxc_gpio driver does not provide any request/rfree function ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Dec 2023 17:59:01 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/Using-GPIO-in-u-boot-with-imx8qxp/m-p/1778852#M217730</guid>
      <dc:creator>Anthony_R</dc:creator>
      <dc:date>2023-12-21T17:59:01Z</dc:date>
    </item>
  </channel>
</rss>

