pinctrl: intel: Implement intel_gpio_get_direction callback
Subsystems (3)
PATCH 1/1 pinctrl: intel: Implement intel_gpio_get_direction callback
Allows querying GPIO direction from the pad config register. If the pad is not in GPIO mode, return an error.
---
This is needed by the drivers for the UP Squared board, an APL-based platform. (For now, these drivers are out-of-tree.)
An earlier version of this patch was reviewed some time ago by Andy Shevchenko outside of the mailing lists:
<https://github.com/emutex/ubilinux-kernel/commit/708a776f2ffd1b1c>
drivers/pinctrl/intel/pinctrl-intel.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
drivers/pinctrl/intel/pinctrl-intel.c +19 -0
@@ -788,6 +788,24 @@ static void intel_gpio_set(struct gpio_chip *chip, unsigned offset, int value)raw_spin_unlock_irqrestore (&pctrl->lock, flags); } +static int intel_gpio_get_direction (struct gpio_chip *chip,unsigned int offset) +{ +struct intel_pinctrl *pctrl =gpiochip_get_data (chip); +void __iomem *reg; +u32 padcfg0; + + reg =intel_get_padcfg (pctrl, offset,PADCFG0 ); +if (!reg) +return -EINVAL ; + + padcfg0 =readl (reg); + +if (padcfg0 &PADCFG0_PMODE_MASK ) +return -EINVAL ; + +return !!(padcfg0 &PADCFG0_GPIOTXDIS ); +} +static int intel_gpio_direction_input (struct gpio_chip *chip,unsigned offset) {return pinctrl_gpio_direction_input (chip->base + offset);
@@ -804,6 +822,7 @@ static const struct gpio_chip intel_gpio_chip = { .owner = THIS_MODULE, .request = gpiochip_generic_request, .free = gpiochip_generic_free, + .get_direction = intel_gpio_get_direction, .direction_input = intel_gpio_direction_input, .direction_output = intel_gpio_direction_output, .get = intel_gpio_get,
Signature · 1 line
2.16.2
(Fix Andy's Cc: - apologies)
Quoted 53 lines · Javier Arteaga
Allows querying GPIO direction from the pad config register. If the pad is not in GPIO mode, return an error.
Signed-off-by Javier Arteaga <[email protected]>---
This is needed by the drivers for the UP Squared board, an APL-based platform. (For now, these drivers are out-of-tree.)An earlier version of this patch was reviewed some time ago by Andy Shevchenko outside of the mailing lists:
<https://github.com/emutex/ubilinux-kernel/commit/708a776f2ffd1b1c>drivers/pinctrl/intel/pinctrl-intel.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)drivers/pinctrl/intel/pinctrl-intel.c +19
-0@@ -788,6 +788,24 @@ static void intel_gpio_set(struct gpio_chip *chip, unsigned offset, int value)raw_spin_unlock_irqrestore (&pctrl->lock, flags); } +static int intel_gpio_get_direction (struct gpio_chip *chip,unsigned int offset) +{ +struct intel_pinctrl *pctrl =gpiochip_get_data (chip); +void __iomem *reg; +u32 padcfg0; + + reg =intel_get_padcfg (pctrl, offset,PADCFG0 ); +if (!reg) +return -EINVAL ; + + padcfg0 =readl (reg); + +if (padcfg0 &PADCFG0_PMODE_MASK ) +return -EINVAL ; + +return !!(padcfg0 &PADCFG0_GPIOTXDIS ); +} +static int intel_gpio_direction_input (struct gpio_chip *chip,unsigned offset) {return pinctrl_gpio_direction_input (chip->base + offset);@@ -804,6 +822,7 @@ static const struct gpio_chip intel_gpio_chip = { .owner = THIS_MODULE, .request = gpiochip_generic_request, .free = gpiochip_generic_free, + .get_direction = intel_gpio_get_direction, .direction_input = intel_gpio_direction_input, .direction_output = intel_gpio_direction_output, .get = intel_gpio_get,
Andy Shevchenko
Reviewed-byQuoted 15 lines · Javier Arteaga
(Fix Andy's Cc: - apologies)
Quoted 12 lines · Javier Arteaga
Allows querying GPIO direction from the pad config register. If the pad is not in GPIO mode, return an error.
Signed-off-by Javier Arteaga <[email protected]>---
This is needed by the drivers for the UP Squared board, an APL-based platform. (For now, these drivers are out-of-tree.)An earlier version of this patch was reviewed some time ago by Andy Shevchenko outside of the mailing lists:
<https://github.com/emutex/ubilinux-kernel/commit/708a776f2ffd1b1c>
Yes, this one look good!
Quoted 27 lines
Quoted 26 lines
drivers/pinctrl/intel/pinctrl-intel.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)drivers/pinctrl/intel/pinctrl-intel.c +12
-0@@ -788,6 +788,24 @@ static void intel_gpio_set(struct gpio_chip *chip, unsigned offset, int value)raw_spin_unlock_irqrestore (&pctrl->lock, flags); } +static int intel_gpio_get_direction (struct gpio_chip *chip,unsigned int offset) +{ +struct intel_pinctrl *pctrl =gpiochip_get_data (chip); +void __iomem *reg; +u32 padcfg0; + + reg =intel_get_padcfg (pctrl, offset,PADCFG0 ); +if (!reg) +return -EINVAL ; + + padcfg0 =readl (reg); +
Quoted 2 lines
drivers/pinctrl/intel/pinctrl-intel.c static void intel_gpio_set(struct gpio_chip *chip, unsigned offset, int value) · line 804
Quoted 2 lines
drivers/pinctrl/intel/pinctrl-intel.c +2
-0+if (padcfg0 &PADCFG0_PMODE_MASK ) +return -EINVAL ;
Actually we might return direction of GPIO function while pin is in some other mode, though it would probably make not much sense in practice.
Quoted 18 lines
Quoted 18 lines
drivers/pinctrl/intel/pinctrl-intel.c +4
-0+ +return !!(padcfg0 &PADCFG0_GPIOTXDIS ); +} + static int intel_gpio_direction_input(struct gpio_chip *chip,unsigned offset)
{drivers/pinctrl/intel/pinctrl-intel.c +1
-0return pinctrl_gpio_direction_input (chip->base + offset);@@ -804,6 +822,7 @@ static const struct gpio_chip intel_gpio_chip = { .owner = THIS_MODULE, .request = gpiochip_generic_request, .free = gpiochip_generic_free, + .get_direction = intel_gpio_get_direction, .direction_input = intel_gpio_direction_input, .direction_output = intel_gpio_direction_output,.get =
intel_gpio_get,
Signature · 2 lines
Andy Shevchenko <[email protected]> Intel Finland Oy
Quoted 6 lines · Andy Shevchenko
Quoted 3 lines · Javier Arteaga
Quoted 3 lines
+static int
intel_gpio_get_direction(struct gpio_chip *chip, unsigned int offset)
+{
Quoted 6 lines
Quoted 2 lines
drivers/pinctrl/intel/pinctrl-intel.c static void intel_gpio_set(struct gpio_chip *chip, unsigned offset, int value) · line 804
Quoted 2 lines
drivers/pinctrl/intel/pinctrl-intel.c +2
-0+if (padcfg0 &PADCFG0_PMODE_MASK ) +return -EINVAL ;Actually we might return direction of GPIO function while pin is in some
other mode, though it would probably make not much sense in practice.
One more though, this is a call back for GPIO function anyway, so, above condition should never happen. I think it's safe to remove it completely.
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/pinctrl/intel/pinctrl-intel.c +3
-0+ +return !!(padcfg0 &PADCFG0_GPIOTXDIS ); +}
Signature · 2 lines
Andy Shevchenko <[email protected]> Intel Finland Oy
Quoted 14 lines · Andy Shevchenko
Quoted 6 lines · Andy Shevchenko
Quoted 3 lines · Javier Arteaga
Quoted 3 lines
+static int
intel_gpio_get_direction(struct gpio_chip *chip, unsigned int offset)
+{Quoted 6 lines
Quoted 2 lines
drivers/pinctrl/intel/pinctrl-intel.c static void intel_gpio_set(struct gpio_chip *chip, unsigned offset, int value) · line 804
Quoted 2 lines
drivers/pinctrl/intel/pinctrl-intel.c +2
-0+if (padcfg0 &PADCFG0_PMODE_MASK ) +return -EINVAL ;Actually we might return direction of GPIO function while pin is in some
other mode, though it would probably make not much sense in practice.
Quoted 3 lines
One more though, this is a call back for GPIO function anyway, so, above condition should never happen. I think it's safe to remove it completely.
The story behind that check is likely *not* a valid usecase: the current iteration of the UP board drivers use gpiod_get_direction() *while* requesting GPIOs to mirror SoC GPIO config on the on-board FPGA. So the direction doesn't make sense for pins set to function mode.
As per your other feedback that driver should be reworked anyway - that's not a reason to keep the check. I just thought it's a bit more defensive, and saw there's some precedent of doing this:
f002d07c56c7 ("gpio: tegra: Implement gpio_get_direction callback")
That being said I don't have a strong argument either way :) I'll resend if you still feel it's unnecessary.
Thanks for reviewing!
Quoted 12 lines · Andy Shevchenko
Quoted 11 lines · Javier Arteaga
(Fix Andy's Cc: - apologies)
Quoted 8 lines · Javier Arteaga
Allows querying GPIO direction from the pad config register. If the pad is not in GPIO mode, return an error.
Signed-off-by Javier Arteaga <[email protected]>---
This is needed by the drivers for the UP Squared board, an APL-based platform. (For now, these drivers are out-of-tree.)
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
An earlier version of this patch was reviewed some time ago by Andy Shevchenko outside of the mailing lists:
<https://github.com/emutex/ubilinux-kernel/commit/708a776f2ffd1b1c>Yes, this one look good!
Reviewed-by Andy Shevchenko <[email protected]>