All of lore.kernel.org
 help / color / mirror / Atom feed
From: Axel Lin <axel.lin@ingics.com>
To: Florian Fainelli <florian@openwrt.org>
Cc: Linus Walleij <linus.walleij@linaro.org>,
	Alexandre Courbot <gnurou@gmail.com>,
	linux-gpio@vger.kernel.org
Subject: gpio: rdc321x: Question about rdc_gpio_direction_input implementation
Date: Fri, 11 Apr 2014 11:28:44 +0800	[thread overview]
Message-ID: <1397186924.30538.2.camel@phoenix> (raw)

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;
 }
 
 /*



             reply	other threads:[~2014-04-11  3:28 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-11  3:28 Axel Lin [this message]
2014-04-11  4:53 ` gpio: rdc321x: Question about rdc_gpio_direction_input implementation Florian Fainelli
2014-04-11  5:56   ` Axel Lin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1397186924.30538.2.camel@phoenix \
    --to=axel.lin@ingics.com \
    --cc=florian@openwrt.org \
    --cc=gnurou@gmail.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.