Skip to contentSkip to conversation

gpio: tegra: Implement gpio_get_direction callback

PATCH Superseded Laxman Dewangan 4 participants 4 messages Apr 29, 2016 – Apr 30, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 gpio: tegra: Implement gpio_get_direction callback

Implement gpio_get_direction() callback for Tegra GPIO. The direction is only valid if the pin is configured as GPIO. If pin is not configured in GPIO mode then this function return error.

---
This patch is based on discussion on series
Re: [PATCH V5 0/4] gpio: tegra: Cleanups and support for debounce

Quoted 1 line

From Linus W:

It would be nice if you also implement .get_direction() which makes debugfs and initial reading of the state of the lines more accurate.

V1->V2:
- Rearrange the calls to optimise the register access and avoid much indenting based on Stephen's and Jon review.

 drivers/gpio/gpio-tegra.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
drivers/gpio/gpio-tegra.c +16 -0
index b3ddd92..ec891a27 100644
@@ -191,6 +191,21 @@ static int tegra_gpio_direction_output(struct gpio_chip *chip, unsigned offset,
 	return 0;
 }
 
+static int tegra_gpio_get_direction(struct gpio_chip *chip, unsigned offset)
+{
+	struct tegra_gpio_info *tgi = gpiochip_get_data(chip);
+	u32 pin_mask = BIT(GPIO_BIT(offset));
+	u32 cnf, oe;
+
+	cnf = tegra_gpio_readl(tgi, GPIO_CNF(tgi, offset));
+	if (!(cnf & pin_mask))
+		return -EINVAL;
+
+	oe = tegra_gpio_readl(tgi, GPIO_OE(tgi, offset));
+
+	return (oe & pin_mask) ? GPIOF_DIR_OUT : GPIOF_DIR_IN;
+}
+
 static int tegra_gpio_set_debounce(struct gpio_chip *chip, unsigned int offset,
 				   unsigned int debounce)
 {
@@ -575,6 +590,7 @@ static int tegra_gpio_probe(struct platform_device *pdev)
 	tgi->gc.get			= tegra_gpio_get;
 	tgi->gc.direction_output	= tegra_gpio_direction_output;
 	tgi->gc.set			= tegra_gpio_set;
+	tgi->gc.get_direction		= tegra_gpio_get_direction;
 	tgi->gc.to_irq			= tegra_gpio_to_irq;
 	tgi->gc.base			= 0;
 	tgi->gc.ngpio			= tgi->bank_count * 32;
Signature · 1 line
2.1.4
Reviewed-by on v2 1/1
#1 lore raw
Quoted 4 lines · Laxman Dewangan

Implement gpio_get_direction() callback for Tegra GPIO. The direction is only valid if the pin is configured as GPIO. If pin is not configured in GPIO mode then this function return error.

maintainer Acked-by on v2 1/1
#2 lore raw
In reply to Laxman Dewangan
Quoted 48 lines · Laxman Dewangan

Implement gpio_get_direction() callback for Tegra GPIO. The direction is only valid if the pin is configured as GPIO. If pin is not configured in GPIO mode then this function return error.

---
This patch is based on discussion on series
Re: [PATCH V5 0/4] gpio: tegra: Cleanups and support for debounce From Linus W:
It would be nice if you also implement .get_direction() which makes debugfs and initial reading of the state of the lines more accurate.

V1->V2:
- Rearrange the calls to optimise the register access and avoid much indenting based on Stephen's and Jon review.

 drivers/gpio/gpio-tegra.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
drivers/gpio/gpio-tegra.c +15 -0
index b3ddd92..ec891a27 100644
@@ -191,6 +191,21 @@ static int tegra_gpio_direction_output(struct gpio_chip *chip, unsigned offset,
 	return 0;
 }
 
+static int tegra_gpio_get_direction(struct gpio_chip *chip, unsigned offset)
+{
+	struct tegra_gpio_info *tgi = gpiochip_get_data(chip);
+	u32 pin_mask = BIT(GPIO_BIT(offset));
+	u32 cnf, oe;
+
+	cnf = tegra_gpio_readl(tgi, GPIO_CNF(tgi, offset));
+	if (!(cnf & pin_mask))
+		return -EINVAL;
+
+	oe = tegra_gpio_readl(tgi, GPIO_OE(tgi, offset));
+
+	return (oe & pin_mask) ? GPIOF_DIR_OUT : GPIOF_DIR_IN;
+}
+
 static int tegra_gpio_set_debounce(struct gpio_chip *chip, unsigned int offset,
 				   unsigned int debounce)
 {

drivers/gpio/gpio-tegra.c static int tegra_gpio_probe(struct platform_device *pdev) · line 596

Quoted 7 lines
drivers/gpio/gpio-tegra.c +1 -0
@@ -575,6 +590,7 @@ static int tegra_gpio_probe(struct platform_device *pdev)
 	tgi->gc.get			= tegra_gpio_get;
 	tgi->gc.direction_output	= tegra_gpio_direction_output;
 	tgi->gc.set			= tegra_gpio_set;
+	tgi->gc.get_direction		= tegra_gpio_get_direction;
 	tgi->gc.to_irq			= tegra_gpio_to_irq;
 	tgi->gc.base			= 0;
 	tgi->gc.ngpio			= tgi->bank_count * 32;

Cheers
Jon