diff mbox series

[resend,1/2] gpio: mpc8xxx: don't modify gpdat when setting gpio as input

Message ID 20200128120423.16667-2-rasmus.villemoes@prevas.dk
State Accepted
Commit 1d7ad9fa051e5b3057bccb6384ab62e4f9c206b2
Delegated to: Tom Rini
Headers show
Series gpio: mpc8xxx: honour shadow register when writing gpdat | expand

Commit Message

Rasmus Villemoes Jan. 28, 2020, 12:04 p.m. UTC
Since some chips don't support reading back the value of output gpios
from the gpdat register, we should not do a RMW cycle (i.e., the
clrbits_be32) on the gpdat register when setting a gpio as input, as
that might accidentally change the value of some other (still
configured as output) gpio.

The extra indirection through mpc8xxx_gpio_set_in() does not help
readability, so just fold the gpdir update into
mpc8xxx_gpio_direction_input().

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
---
 drivers/gpio/mpc8xxx_gpio.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

Comments

Tom Rini March 31, 2020, 7:09 p.m. UTC | #1
On Tue, Jan 28, 2020 at 12:04:33PM +0000, Rasmus Villemoes wrote:

> Since some chips don't support reading back the value of output gpios
> from the gpdat register, we should not do a RMW cycle (i.e., the
> clrbits_be32) on the gpdat register when setting a gpio as input, as
> that might accidentally change the value of some other (still
> configured as output) gpio.
> 
> The extra indirection through mpc8xxx_gpio_set_in() does not help
> readability, so just fold the gpdir update into
> mpc8xxx_gpio_direction_input().
> 
> Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>

Applied to u-boot/master, thanks!
diff mbox series

Patch

diff --git a/drivers/gpio/mpc8xxx_gpio.c b/drivers/gpio/mpc8xxx_gpio.c
index 9964d69035..5438196fe0 100644
--- a/drivers/gpio/mpc8xxx_gpio.c
+++ b/drivers/gpio/mpc8xxx_gpio.c
@@ -57,13 +57,6 @@  static inline u32 mpc8xxx_gpio_get_dir(struct ccsr_gpio *base, u32 mask)
 	return in_be32(&base->gpdir) & mask;
 }
 
-static inline void mpc8xxx_gpio_set_in(struct ccsr_gpio *base, u32 gpios)
-{
-	clrbits_be32(&base->gpdat, gpios);
-	/* GPDIR register 0 -> input */
-	clrbits_be32(&base->gpdir, gpios);
-}
-
 static inline void mpc8xxx_gpio_set_low(struct ccsr_gpio *base, u32 gpios)
 {
 	clrbits_be32(&base->gpdat, gpios);
@@ -100,8 +93,11 @@  static inline void mpc8xxx_gpio_open_drain_off(struct ccsr_gpio *base,
 static int mpc8xxx_gpio_direction_input(struct udevice *dev, uint gpio)
 {
 	struct mpc8xxx_gpio_data *data = dev_get_priv(dev);
+	u32 mask = gpio_mask(gpio);
+
+	/* GPDIR register 0 -> input */
+	clrbits_be32(&data->base->gpdir, mask);
 
-	mpc8xxx_gpio_set_in(data->base, gpio_mask(gpio));
 	return 0;
 }