linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* gpio: rdc321x: Question about rdc_gpio_direction_input implementation
@ 2014-04-11  3:28 Axel Lin
  2014-04-11  4:53 ` Florian Fainelli
  0 siblings, 1 reply; 3+ messages in thread
From: Axel Lin @ 2014-04-11  3:28 UTC (permalink / raw)
  To: Florian Fainelli; +Cc: Linus Walleij, Alexandre Courbot, linux-gpio

Hi Florian,
Current implementation in rdc_gpio_direction_input() looks wrong to me
because calling rdc_gpio_config(chip, gpio, 1) actually set the gpio to
OUTPUT HIGH rather than set the direction to INPUT.

I cannot find the datasheet, I'm wondering if below diff works.
Any chance to test it? I can send a formal patch if it works.

diff --git a/drivers/gpio/gpio-rdc321x.c b/drivers/gpio/gpio-rdc321x.c
index 88577c3..ccef383 100644
--- a/drivers/gpio/gpio-rdc321x.c
+++ b/drivers/gpio/gpio-rdc321x.c
@@ -119,10 +119,29 @@ unlock:
 	return err;
 }
 
-/* configure GPIO pin as input */
 static int rdc_gpio_direction_input(struct gpio_chip *chip, unsigned
gpio)
 {
-	return rdc_gpio_config(chip, gpio, 1);
+	struct rdc321x_gpio *gpch;
+	int reg, err;
+	u32 val;
+
+	gpch = container_of(chip, struct rdc321x_gpio, chip);
+	reg = gpio < 32 ? gpch->reg1_ctrl_base : gpch->reg2_ctrl_base;
+
+	spin_lock(&gpch->lock);
+
+	err = pci_read_config_dword(gpch->sb_pdev, reg, &val);
+	if (err)
+		goto unlock;
+
+	val &= ~(1 << (gpio & 0x1f));
+
+	err = pci_write_config_dword(gpch->sb_pdev, reg, val);
+
+unlock:
+	spin_unlock(&gpch->lock);
+
+	return err;
 }
 
 /*



^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-04-11  5:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-04-11  3:28 gpio: rdc321x: Question about rdc_gpio_direction_input implementation Axel Lin
2014-04-11  4:53 ` Florian Fainelli
2014-04-11  5:56   ` Axel Lin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).