All of lore.kernel.org
 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

* Re: gpio: rdc321x: Question about rdc_gpio_direction_input implementation
  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
  0 siblings, 1 reply; 3+ messages in thread
From: Florian Fainelli @ 2014-04-11  4:53 UTC (permalink / raw)
  To: Axel Lin; +Cc: Linus Walleij, Alexandre Courbot, linux-gpio

Hi Axel,

2014-04-10 20:28 GMT-07:00 Axel Lin <axel.lin@ingics.com>:
> 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.

The datasheet is available here:
http://www.atekmicro.com/download/r8610/R8610-G.pdf

I do not have access to the hardware at this very moment, but I should
be able to give this a try. I do not think GPIO input was tested at
all, the GPIO LEDs and such were driven as active outputs.

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

-- 
Florian

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

* Re: gpio: rdc321x: Question about rdc_gpio_direction_input implementation
  2014-04-11  4:53 ` Florian Fainelli
@ 2014-04-11  5:56   ` Axel Lin
  0 siblings, 0 replies; 3+ messages in thread
From: Axel Lin @ 2014-04-11  5:56 UTC (permalink / raw)
  To: Florian Fainelli; +Cc: Linus Walleij, Alexandre Courbot, linux-gpio

2014-04-11 12:53 GMT+08:00 Florian Fainelli <florian@openwrt.org>:
> Hi Axel,
>
> 2014-04-10 20:28 GMT-07:00 Axel Lin <axel.lin@ingics.com>:
>> 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.
>
> The datasheet is available here:
> http://www.atekmicro.com/download/r8610/R8610-G.pdf
>
> I do not have access to the hardware at this very moment, but I should
> be able to give this a try. I do not think GPIO input was tested at
> all, the GPIO LEDs and such were driven as active outputs.
>
Just check the datasheet and I got confused.

The bits in reg1_ctrl_base/reg2_ctrl_base register is to enable/disable GPIOx
function.
However, I cannot find the register to set gpio direction.

There is a note in 4.4 says
"Note 4: Programmed by the GPIO mode & dir. Register. ".
But I cannot find the GPIO mode & dir. Register.

Regards,
Axel

^ permalink raw reply	[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 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.