Skip to contentSkip to conversation

pinctrl: vt8500: Ensure value reg is updated when setting direction

PATCH In review Alexey Charkov 3 participants 3 messages Apr 29, 2014 – May 9, 2014 Pin control

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pinctrl: vt8500: Ensure value reg is updated when setting direction

Current code only touches the direction register when setting direction to output, which breaks logic like

echo high > /sys/class/gpio/gpio0/direction

which is expected to also set the value. This patch also adds a call to update the value register when setting direction to output.

---
 drivers/pinctrl/vt8500/pinctrl-wmt.c | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)
drivers/pinctrl/vt8500/pinctrl-wmt.c +12 -11
index 9802b67..2c61281 100644
@@ -523,17 +523,6 @@ static int wmt_gpio_get_direction(struct gpio_chip *chip, unsigned offset)
 		return GPIOF_DIR_IN;
 }
 
-static int wmt_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
-{
-	return pinctrl_gpio_direction_input(chip->base + offset);
-}
-
-static int wmt_gpio_direction_output(struct gpio_chip *chip, unsigned offset,
-				     int value)
-{
-	return pinctrl_gpio_direction_output(chip->base + offset);
-}
-
 static int wmt_gpio_get_value(struct gpio_chip *chip, unsigned offset)
 {
 	struct wmt_pinctrl_data *data = dev_get_drvdata(chip->dev);
@@ -568,6 +557,18 @@ static void wmt_gpio_set_value(struct gpio_chip *chip, unsigned offset,
 		wmt_clearbits(data, reg_data_out, BIT(bit));
 }
 
+static int wmt_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
+{
+	return pinctrl_gpio_direction_input(chip->base + offset);
+}
+
+static int wmt_gpio_direction_output(struct gpio_chip *chip, unsigned offset,
+				     int value)
+{
+	wmt_gpio_set_value(chip, offset, value);
+	return pinctrl_gpio_direction_output(chip->base + offset);
+}
+
 static struct gpio_chip wmt_gpio_chip = {
 	.label = "gpio-wmt",
 	.owner = THIS_MODULE,
Signature · 1 line
1.9.1
Acked-by on v1 1/1
#1 lore raw
Quoted 44 lines · Alexey Charkov

Current code only touches the direction register when setting direction to output, which breaks logic like

echo high > /sys/class/gpio/gpio0/direction

which is expected to also set the value. This patch also adds a call to update the value register when setting direction to output.

---
  drivers/pinctrl/vt8500/pinctrl-wmt.c | 23 ++++++++++++-----------
  1 file changed, 12 insertions(+), 11 deletions(-)
drivers/pinctrl/vt8500/pinctrl-wmt.c +5 -11
index 9802b67..2c61281 100644
@@ -523,17 +523,6 @@ static int wmt_gpio_get_direction(struct gpio_chip *chip, unsigned offset)
  		return GPIOF_DIR_IN;
  }
 
-static int wmt_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
-{
-	return pinctrl_gpio_direction_input(chip->base + offset);
-}
-
-static int wmt_gpio_direction_output(struct gpio_chip *chip, unsigned offset,
-				     int value)
-{
-	return pinctrl_gpio_direction_output(chip->base + offset);
-}
-
  static int wmt_gpio_get_value(struct gpio_chip *chip, unsigned offset)
  {
  	struct wmt_pinctrl_data *data = dev_get_drvdata(chip->dev);
@@ -568,6 +557,18 @@ static void wmt_gpio_set_value(struct gpio_chip *chip, unsigned offset,
  		wmt_clearbits(data, reg_data_out, BIT(bit));
  }
 
+static int wmt_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
+{
+	return pinctrl_gpio_direction_input(chip->base + offset);
+}
+

drivers/pinctrl/vt8500/pinctrl-wmt.c static void wmt_gpio_set_value(struct gpio_chip *chip, unsigned offset, · line 574

Quoted 10 lines
drivers/pinctrl/vt8500/pinctrl-wmt.c +7 -0
+static int wmt_gpio_direction_output(struct gpio_chip *chip, unsigned offset,
+				     int value)
+{
+	wmt_gpio_set_value(chip, offset, value);
+	return pinctrl_gpio_direction_output(chip->base + offset);
+}
+
  static struct gpio_chip wmt_gpio_chip = {
  	.label = "gpio-wmt",
  	.owner = THIS_MODULE,

Didn't notice that this was an option in the gpio documentation but it makes obvious sense. Regards
Tony P

#2 lore raw
In reply to Alexey Charkov
Quoted 9 lines · Alexey Charkov

Current code only touches the direction register when setting direction to output, which breaks logic like

echo high > /sys/class/gpio/gpio0/direction

which is expected to also set the value. This patch also adds a call to update the value register when setting direction to output.

Patch applied for fixes with Tony's ACK.

Yours,
Linus Walleij