Browse Source

gpio: dwapb: Call directly into the gpiochip to read value

We were going out through the (legacy) gpio API to read the value
of a line to set up polarity inversion. This is abusive. Do something
less abusive by looking up the actual struct gpio_chip *
instance and calling .get() directly on it.

Acked-by: Hoan Tran <hotran@apm.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Linus Walleij 7 years ago
parent
commit
62c16234bb
1 changed files with 30 additions and 7 deletions
  1. 30 7
      drivers/gpio/gpio-dwapb.c

+ 30 - 7
drivers/gpio/gpio-dwapb.c

@@ -9,8 +9,6 @@
  */
  */
 #include <linux/acpi.h>
 #include <linux/acpi.h>
 #include <linux/gpio/driver.h>
 #include <linux/gpio/driver.h>
-/* FIXME: for gpio_get_value(), replace this with direct register read */
-#include <linux/gpio.h>
 #include <linux/err.h>
 #include <linux/err.h>
 #include <linux/init.h>
 #include <linux/init.h>
 #include <linux/interrupt.h>
 #include <linux/interrupt.h>
@@ -153,16 +151,40 @@ static int dwapb_gpio_to_irq(struct gpio_chip *gc, unsigned offset)
 	return irq_find_mapping(gpio->domain, offset);
 	return irq_find_mapping(gpio->domain, offset);
 }
 }
 
 
+static struct dwapb_gpio_port *dwapb_offs_to_port(struct dwapb_gpio *gpio, unsigned int offs)
+{
+	struct dwapb_gpio_port *port;
+	int i;
+
+	for (i = 0; i < gpio->nr_ports; i++) {
+		port = &gpio->ports[i];
+		if (port->idx == offs / 32)
+			return port;
+	}
+
+	return NULL;
+}
+
 static void dwapb_toggle_trigger(struct dwapb_gpio *gpio, unsigned int offs)
 static void dwapb_toggle_trigger(struct dwapb_gpio *gpio, unsigned int offs)
 {
 {
-	u32 v = dwapb_read(gpio, GPIO_INT_POLARITY);
+	struct dwapb_gpio_port *port = dwapb_offs_to_port(gpio, offs);
+	struct gpio_chip *gc;
+	u32 pol;
+	int val;
+
+	if (!port)
+		return;
+	gc = &port->gc;
 
 
-	if (gpio_get_value(gpio->ports[0].gc.base + offs))
-		v &= ~BIT(offs);
+	pol = dwapb_read(gpio, GPIO_INT_POLARITY);
+	/* Just read the current value right out of the data register */
+	val = gc->get(gc, offs % 32);
+	if (val)
+		pol &= ~BIT(offs);
 	else
 	else
-		v |= BIT(offs);
+		pol |= BIT(offs);
 
 
-	dwapb_write(gpio, GPIO_INT_POLARITY, v);
+	dwapb_write(gpio, GPIO_INT_POLARITY, pol);
 }
 }
 
 
 static u32 dwapb_do_irq(struct dwapb_gpio *gpio)
 static u32 dwapb_do_irq(struct dwapb_gpio *gpio)
@@ -481,6 +503,7 @@ static int dwapb_gpio_add_port(struct dwapb_gpio *gpio,
 	dirout = gpio->regs + GPIO_SWPORTA_DDR +
 	dirout = gpio->regs + GPIO_SWPORTA_DDR +
 		(pp->idx * GPIO_SWPORT_DDR_STRIDE);
 		(pp->idx * GPIO_SWPORT_DDR_STRIDE);
 
 
+	/* This registers 32 GPIO lines per port */
 	err = bgpio_init(&port->gc, gpio->dev, 4, dat, set, NULL, dirout,
 	err = bgpio_init(&port->gc, gpio->dev, 4, dat, set, NULL, dirout,
 			 NULL, 0);
 			 NULL, 0);
 	if (err) {
 	if (err) {