Skip to contentSkip to conversation

arm: gpio: Add set_flags callback to the Tegra gpio driver

PATCH Superseded Lukasz Majewski 2 participants 4 messages Sep 19, 2025 – Sep 22, 2025

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arm: gpio: Add set_flags callback to the Tegra gpio driver

In some Tegra SoC (like e.g. T30) there is a possibility that one will configure at early boot state a pin as GPIO (to use it for e.g. carrier board detection). However, afterwards (i.e. in Linux) the same pin will be used as the special function one.

Current Tegra gpio driver doesn't allow this, so callback for set_flags() has been defined to properly setup the GPIO when required. For now following flags are supported:
- GPIOD_IS_AF (i.e. "alternate function").
- GPIOD_IS_IN
- GPIOD_IS_OUT

In long term the tegra_gpio_set_flags() is going to replace direction_{input|output} callbacks.

---
 drivers/gpio/tegra_gpio.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
drivers/gpio/tegra_gpio.c +24 -0
index 3d1e18854f2..1e8bd051875 100644
@@ -258,6 +258,29 @@ static int tegra_gpio_rfree(struct udevice *dev, unsigned int offset)
 	return 0;
 }
 
+static int tegra_gpio_set_flags(struct udevice *dev, unsigned int offset,
+				ulong flags)
+{
+	struct tegra_port_info *state = dev_get_priv(dev);
+	int gpio = state->base_gpio + offset;
+
+	debug("gpio_set_flags: pin = %d (port %d:bit %d), flag = %d\n",
+	      gpio, GPIO_FULLPORT(gpio), GPIO_BIT(gpio), flags);
+
+	if (flags & GPIOD_IS_AF) {
+		set_config(gpio, CFG_SFIO);
+		return 0;
+	} else if (flags & GPIOD_IS_IN) {
+		return tegra_gpio_direction_input(dev, offset);
+	} else if (flags & GPIOD_IS_OUT) {
+		bool value = flags & GPIOD_IS_OUT_ACTIVE;
+
+		return tegra_gpio_direction_output(dev, offset, value);
+	}
+
+	return -EINVAL;
+}
+
 static const struct dm_gpio_ops gpio_tegra_ops = {
 	.direction_input	= tegra_gpio_direction_input,
 	.direction_output	= tegra_gpio_direction_output,
@@ -266,6 +289,7 @@ static const struct dm_gpio_ops gpio_tegra_ops = {
 	.get_function		= tegra_gpio_get_function,
 	.xlate			= tegra_gpio_xlate,
 	.rfree			= tegra_gpio_rfree,
+	.set_flags		= tegra_gpio_set_flags,
 };
 
 /*
Signature · 1 line
2.39.5
#1 lore raw

пт, 19 вер. 2025 р. о 13:11 Lukasz Majewski <[email protected]> пише:

Quoted 8 lines

In some Tegra SoC (like e.g. T30) there is a possibility that one will configure at early boot state a pin as GPIO (to use it for e.g. carrier board detection). However, afterwards (i.e. in Linux) the same pin will be used as the special function one.

Current Tegra gpio driver doesn't allow this, so callback for set_flags() has been defined to properly setup the GPIO when required.

Please write the commit message in the imperative mood.

Quoted 8 lines

For now following flags are supported:
- GPIOD_IS_AF (i.e. "alternate function").
- GPIOD_IS_IN
- GPIOD_IS_OUT

In long term the tegra_gpio_set_flags() is going to replace direction_{input|output} callbacks.

It is not a book chapter, describe what the commit does briefly.

Quoted 12 lines
---
 drivers/gpio/tegra_gpio.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
drivers/gpio/tegra_gpio.c +0 -0
index 3d1e18854f2..1e8bd051875 100644
@@ -258,6 +258,29 @@ static int tegra_gpio_rfree(struct udevice *dev, unsigned int offset)
        return 0;
 }

drivers/gpio/tegra_gpio.c static int tegra_gpio_rfree(struct udevice *dev, unsigned int offset) · line 269

Quoted 10 lines
drivers/gpio/tegra_gpio.c +9 -0
 
+static int tegra_gpio_set_flags(struct udevice *dev, unsigned int offset,
+                               ulong flags)
+{
+       struct tegra_port_info *state = dev_get_priv(dev);
+       int gpio = state->base_gpio + offset;
+
+       debug("gpio_set_flags: pin = %d (port %d:bit %d), flag = %d\n",
+             gpio, GPIO_FULLPORT(gpio), GPIO_BIT(gpio), flags);
+

Have you even built this code yourself? "flags" is of type ulong, not int

Quoted 18 lines
drivers/gpio/tegra_gpio.c +14 -0
+       if (flags & GPIOD_IS_AF) {
+               set_config(gpio, CFG_SFIO);
+               return 0;
+       } else if (flags & GPIOD_IS_IN) {
+               return tegra_gpio_direction_input(dev, offset);
+       } else if (flags & GPIOD_IS_OUT) {
+               bool value = flags & GPIOD_IS_OUT_ACTIVE;
+
+               return tegra_gpio_direction_output(dev, offset, value);
+       }
+
+       return -EINVAL;
+}
+
 static const struct dm_gpio_ops gpio_tegra_ops = {
        .direction_input        = tegra_gpio_direction_input,
        .direction_output       = tegra_gpio_direction_output,

drivers/gpio/tegra_gpio.c static const struct dm_gpio_ops gpio_tegra_ops = { · line 292

Quoted 4 lines
drivers/gpio/tegra_gpio.c +1 -0
@@ -266,6 +289,7 @@ static const struct dm_gpio_ops gpio_tegra_ops = {
        .get_function           = tegra_gpio_get_function,
        .xlate                  = tegra_gpio_xlate,
        .rfree                  = tegra_gpio_rfree,
+       .set_flags              = tegra_gpio_set_flags,

If you are already touching this anyway, then touch it properly. Since set_flags op is meant to remove direction ops, then remove latter too.

Quoted 6 lines
drivers/gpio/tegra_gpio.c +0 -1
 };
 
 /*
--

2.39.5

This commit causes regression on LG P990 board, backlight is located on gpio i2c line and with this patch gpio i2c refuses to work

(bootloader) Core: 114 devices, 27 uclasses, devicetree: separate
(bootloader) MMC: sdhci@c8000400: 1, sdhci@c8000600: 0
(bootloader) Loading Environment from MMC... Reading from MMC(0)... *** (bootloader) Warning - bad CRC, using default environment (bootloader)
(bootloader) Can't get i2c-5 gpios! Error: -22
(bootloader) Can't get i2c-5 gpios! Error: -16

(bootloader) In:    serial,usbkbd,button-kbd
(bootloader) Out:   serial,vidconsole
(bootloader) Err:   serial,vidconsole
(bootloader) Net:   No ethernet found.

(bootloader)
(bootloader) Autoboot in 0 seconds

#2 lore raw

Hi Svyatoslav,

Quoted 18 lines

пт, 19 вер. 2025 р. о 13:11 Lukasz Majewski <[email protected]> пише:

Quoted 9 lines

In some Tegra SoC (like e.g. T30) there is a possibility that one will configure at early boot state a pin as GPIO (to use it for e.g. carrier board detection). However, afterwards (i.e. in Linux) the same pin will be used as the special function one.

Current Tegra gpio driver doesn't allow this, so callback for set_flags() has been defined to properly setup the GPIO when required.

Please write the commit message in the imperative mood.

Quoted 5 lines

For now following flags are supported:
- GPIOD_IS_AF (i.e. "alternate function").
- GPIOD_IS_IN
- GPIOD_IS_OUT

Quoted 5 lines
Quoted 3 lines

In long term the tegra_gpio_set_flags() is going to replace direction_{input|output} callbacks.

It is not a book chapter, describe what the commit does briefly.

Sorry, but the commit message is a pretty nice form of the documentation.

For example when you come back to a project, after a few years each extra sentence is priceless.

Quoted 14 lines
Quoted 14 lines
---
 drivers/gpio/tegra_gpio.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
drivers/gpio/tegra_gpio.c +0 -0
index 3d1e18854f2..1e8bd051875 100644
@@ -258,6 +258,29 @@ static int tegra_gpio_rfree(struct udevice
 *dev, unsigned int offset) return 0;
 }
 
Quoted 14 lines

drivers/gpio/tegra_gpio.c static int tegra_gpio_rfree(struct udevice *dev, unsigned int offset) · line 269

Quoted 11 lines
drivers/gpio/tegra_gpio.c +9 -0
+static int tegra_gpio_set_flags(struct udevice *dev, unsigned int
 offset,
+                               ulong flags)
+{
+       struct tegra_port_info *state = dev_get_priv(dev);
+       int gpio = state->base_gpio + offset;
+
+       debug("gpio_set_flags: pin = %d (port %d:bit %d), flag =
 %d\n",
+             gpio, GPIO_FULLPORT(gpio), GPIO_BIT(gpio), flags);
+  

Have you even built this code yourself? "flags" is of type ulong, not int

It was compiling, but I will double check it.

Quoted 19 lines
Quoted 19 lines
drivers/gpio/tegra_gpio.c +14 -0
+       if (flags & GPIOD_IS_AF) {
+               set_config(gpio, CFG_SFIO);
+               return 0;
+       } else if (flags & GPIOD_IS_IN) {
+               return tegra_gpio_direction_input(dev, offset);
+       } else if (flags & GPIOD_IS_OUT) {
+               bool value = flags & GPIOD_IS_OUT_ACTIVE;
+
+               return tegra_gpio_direction_output(dev, offset,
 value);
+       }
+
+       return -EINVAL;
+}
+

static const struct dm_gpio_ops gpio_tegra_ops = {
.direction_input = tegra_gpio_direction_input,
.direction_output = tegra_gpio_direction_output,

Quoted 9 lines

drivers/gpio/tegra_gpio.c static const struct dm_gpio_ops gpio_tegra_ops · line 292

Quoted 5 lines
drivers/gpio/tegra_gpio.c +1 -0
@@ -266,6 +289,7 @@ static const struct dm_gpio_ops gpio_tegra_ops
 = { .get_function           = tegra_gpio_get_function,
        .xlate                  = tegra_gpio_xlate,
        .rfree                  = tegra_gpio_rfree,
+       .set_flags              = tegra_gpio_set_flags,  

If you are already touching this anyway, then touch it properly. Since set_flags op is meant to remove direction ops, then remove latter too.

Ok.

Quoted 17 lines
Quoted 6 lines
drivers/gpio/tegra_gpio.c +0 -1
 };
 
 /*
--

2.39.5

This commit causes regression on LG P990 board, backlight is located on gpio i2c line and with this patch gpio i2c refuses to work

(bootloader) Core: 114 devices, 27 uclasses, devicetree: separate
(bootloader) MMC: sdhci@c8000400: 1, sdhci@c8000600: 0
(bootloader) Loading Environment from MMC... Reading from MMC(0)... *** (bootloader) Warning - bad CRC, using default environment (bootloader)
(bootloader) Can't get i2c-5 gpios! Error: -22 (bootloader) Can't get i2c-5 gpios! Error: -16

Quoted 6 lines
(bootloader) In:    serial,usbkbd,button-kbd
(bootloader) Out:   serial,vidconsole
(bootloader) Err:   serial,vidconsole
(bootloader) Net:   No ethernet found.

(bootloader)
(bootloader) Autoboot in 0 seconds

Apparently, some flags are not yet supported - like GPIOD_PULL_UP/DOWN or GPIOD_OPEN_DRAIN.

Is this the one from u-boot/board/lg/star/star.c function star_fix_panel()?

Or is it somewhere else - for example in drivers/i2c/i2c-gpio.c ?

For the latter it looks like I do support all the required flags.

At least on my Colibri T30 it works correctly - so extra help is appreciated.

Signature · 10 lines
Best regards,

Lukasz Majewski

--
Nabla Software Engineering GmbH
HRB 40522 Augsburg
Phone: +49 821 45592596
E-Mail: [email protected]
Geschftsfhrer : Stefano Babic
#3 lore raw

пн, 22 вер. 2025 р. о 11:08 Łukasz Majewski <[email protected]> пише:

Quoted 119 lines

Hi Svyatoslav,

Quoted 18 lines

пт, 19 вер. 2025 р. о 13:11 Lukasz Majewski <[email protected]> пише:

Quoted 9 lines

In some Tegra SoC (like e.g. T30) there is a possibility that one will configure at early boot state a pin as GPIO (to use it for e.g. carrier board detection). However, afterwards (i.e. in Linux) the same pin will be used as the special function one.

Current Tegra gpio driver doesn't allow this, so callback for set_flags() has been defined to properly setup the GPIO when required.

Please write the commit message in the imperative mood.

Quoted 5 lines

For now following flags are supported:
- GPIOD_IS_AF (i.e. "alternate function").
- GPIOD_IS_IN
- GPIOD_IS_OUT

Quoted 5 lines
Quoted 3 lines

In long term the tegra_gpio_set_flags() is going to replace direction_{input|output} callbacks.

It is not a book chapter, describe what the commit does briefly.

Sorry, but the commit message is a pretty nice form of the documentation.

For example when you come back to a project, after a few years each extra sentence is priceless.

Quoted 14 lines
Quoted 14 lines
---
 drivers/gpio/tegra_gpio.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
drivers/gpio/tegra_gpio.c +0 -0
index 3d1e18854f2..1e8bd051875 100644
@@ -258,6 +258,29 @@ static int tegra_gpio_rfree(struct udevice
 *dev, unsigned int offset) return 0;
 }
 
Quoted 14 lines

drivers/gpio/tegra_gpio.c static int tegra_gpio_rfree(struct udevice *dev, unsigned int offset) · line 269

Quoted 11 lines
drivers/gpio/tegra_gpio.c +9 -0
+static int tegra_gpio_set_flags(struct udevice *dev, unsigned int
 offset,
+                               ulong flags)
+{
+       struct tegra_port_info *state = dev_get_priv(dev);
+       int gpio = state->base_gpio + offset;
+
+       debug("gpio_set_flags: pin = %d (port %d:bit %d), flag =
 %d\n",
+             gpio, GPIO_FULLPORT(gpio), GPIO_BIT(gpio), flags);
+

Have you even built this code yourself? "flags" is of type ulong, not int

It was compiling, but I will double check it.

Quoted 19 lines
Quoted 19 lines
drivers/gpio/tegra_gpio.c +14 -0
+       if (flags & GPIOD_IS_AF) {
+               set_config(gpio, CFG_SFIO);
+               return 0;
+       } else if (flags & GPIOD_IS_IN) {
+               return tegra_gpio_direction_input(dev, offset);
+       } else if (flags & GPIOD_IS_OUT) {
+               bool value = flags & GPIOD_IS_OUT_ACTIVE;
+
+               return tegra_gpio_direction_output(dev, offset,
 value);
+       }
+
+       return -EINVAL;
+}
+

static const struct dm_gpio_ops gpio_tegra_ops = {
.direction_input = tegra_gpio_direction_input,
.direction_output = tegra_gpio_direction_output,

Quoted 9 lines

drivers/gpio/tegra_gpio.c static const struct dm_gpio_ops gpio_tegra_ops · line 292

Quoted 5 lines
drivers/gpio/tegra_gpio.c +1 -0
@@ -266,6 +289,7 @@ static const struct dm_gpio_ops gpio_tegra_ops
 = { .get_function           = tegra_gpio_get_function,
        .xlate                  = tegra_gpio_xlate,
        .rfree                  = tegra_gpio_rfree,
+       .set_flags              = tegra_gpio_set_flags,

If you are already touching this anyway, then touch it properly. Since set_flags op is meant to remove direction ops, then remove latter too.

Ok.

Quoted 17 lines
Quoted 6 lines
drivers/gpio/tegra_gpio.c +0 -1
 };
 
 /*
--

2.39.5

This commit causes regression on LG P990 board, backlight is located on gpio i2c line and with this patch gpio i2c refuses to work

(bootloader) Core: 114 devices, 27 uclasses, devicetree: separate
(bootloader) MMC: sdhci@c8000400: 1, sdhci@c8000600: 0
(bootloader) Loading Environment from MMC... Reading from MMC(0)... *** (bootloader) Warning - bad CRC, using default environment (bootloader)
(bootloader) Can't get i2c-5 gpios! Error: -22 (bootloader) Can't get i2c-5 gpios! Error: -16

Quoted 6 lines
(bootloader) In:    serial,usbkbd,button-kbd
(bootloader) Out:   serial,vidconsole
(bootloader) Err:   serial,vidconsole
(bootloader) Net:   No ethernet found.

(bootloader)
(bootloader) Autoboot in 0 seconds

Quoted 8 lines

Apparently, some flags are not yet supported - like GPIOD_PULL_UP/DOWN or GPIOD_OPEN_DRAIN.

Is this the one from u-boot/board/lg/star/star.c function star_fix_panel()?

Or is it somewhere else - for example in drivers/i2c/i2c-gpio.c ?

I have told that it comes from i2c-gpio

Quoted 16 lines

For the latter it looks like I do support all the required flags.

At least on my Colibri T30 it works correctly - so extra help is appreciated.

--
Best regards,

Lukasz Majewski

--
Nabla Software Engineering GmbH
HRB 40522 Augsburg
Phone: +49 821 45592596
E-Mail: [email protected]
Geschftsfhrer : Stefano Babic