Skip to contentSkip to conversation

gpio: rdc321x: Question about rdc_gpio_direction_input implementation

PATCH Axel Lin 2 participants 3 messages Apr 11, 2014 GPIO

lore
Share & tools
lore

Axel Lin

author
#0 lore 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.

drivers/gpio/gpio-rdc321x.c +0 -1
index 88577c3..ccef383 100644
@@ -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;
}

/*

#1 lore raw

Hi Axel,

2014-04-10 20:28 GMT-07:00 Axel Lin <[email protected]>:

Quoted 7 lines

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.

Quoted 38 lines
drivers/gpio/gpio-rdc321x.c +21 -2
index 88577c3..ccef383 100644
@@ -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;
 }
 

/*

Signature · 1 line
Florian
author
#2 lore raw

2014-04-11 12:53 GMT+08:00 Florian Fainelli <[email protected]>:

Quoted 11 lines

Hi Axel,

2014-04-10 20:28 GMT-07:00 Axel Lin <[email protected]>:

Quoted 7 lines

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.

Quoted 7 lines

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