@@ -783,6 +783,7 @@ config GPIO_SODAVILLE
config GPIO_TIMBERDALE
bool "Support for timberdale GPIO IP"
depends on MFD_TIMBERDALE
+ select GPIO_GENERIC
---help---
Add support for the GPIO IP in the timberdale FPGA.
@@ -28,7 +28,7 @@
#include <linux/timb_gpio.h>
#include <linux/interrupt.h>
#include <linux/slab.h>
-
+#include <linux/basic_mmio_gpio.h>
#define DRIVER_NAME "timb-gpio"
#define TGPIOVAL 0x00
@@ -50,52 +50,6 @@ struct timbgpio {
unsigned long last_ier;
};
-static int timbgpio_update_bit(struct gpio_chip *gpio, unsigned index,
- unsigned offset, bool enabled)
-{
- struct timbgpio *tgpio = container_of(gpio, struct timbgpio, gpio);
- u32 reg;
-
- spin_lock(&tgpio->lock);
- reg = ioread32(tgpio->membase + offset);
-
- if (enabled)
- reg |= (1 << index);
- else
- reg &= ~(1 << index);
-
- iowrite32(reg, tgpio->membase + offset);
- spin_unlock(&tgpio->lock);
-
- return 0;
-}
-
-static int timbgpio_gpio_direction_input(struct gpio_chip *gpio, unsigned nr)
-{
- return timbgpio_update_bit(gpio, nr, TGPIODIR, true);
-}
-
-static int timbgpio_gpio_get(struct gpio_chip *gpio, unsigned nr)
-{
- struct timbgpio *tgpio = container_of(gpio, struct timbgpio, gpio);
- u32 value;
-
- value = ioread32(tgpio->membase + TGPIOVAL);
- return (value & (1 << nr)) ? 1 : 0;
-}
-
-static int timbgpio_gpio_direction_output(struct gpio_chip *gpio,
- unsigned nr, int val)
-{
- return timbgpio_update_bit(gpio, nr, TGPIODIR, false);
-}
-
-static void timbgpio_gpio_set(struct gpio_chip *gpio,
- unsigned nr, int val)
-{
- timbgpio_update_bit(gpio, nr, TGPIOVAL, val != 0);
-}
-
static int timbgpio_to_irq(struct gpio_chip *gpio, unsigned offset)
{
struct timbgpio *tgpio = container_of(gpio, struct timbgpio, gpio);
@@ -225,7 +179,7 @@ static int timbgpio_probe(struct platform_device *pdev)
{
int err, i;
struct device *dev = &pdev->dev;
- struct gpio_chip *gc;
+ struct bgpio_chip *bgc;
struct timbgpio *tgpio;
struct resource *iomem;
struct timbgpio_platform_data *pdata = dev_get_platdata(&pdev->dev);
@@ -247,6 +201,11 @@ static int timbgpio_probe(struct platform_device *pdev)
dev_err(dev, "Memory alloc failed\n");
return -EINVAL;
}
+
+ bgc = devm_kzalloc(dev, sizeof(*bgc), GFP_KERNEL);
+ if (!bgc)
+ return -EINVAL;
+
tgpio->irq_base = pdata->irq_base;
spin_lock_init(&tgpio->lock);
@@ -263,22 +222,25 @@ static int timbgpio_probe(struct platform_device *pdev)
return -ENOMEM;
}
- gc = &tgpio->gpio;
-
- gc->label = dev_name(&pdev->dev);
- gc->owner = THIS_MODULE;
- gc->dev = &pdev->dev;
- gc->direction_input = timbgpio_gpio_direction_input;
- gc->get = timbgpio_gpio_get;
- gc->direction_output = timbgpio_gpio_direction_output;
- gc->set = timbgpio_gpio_set;
- gc->to_irq = (irq >= 0 && tgpio->irq_base > 0) ? timbgpio_to_irq : NULL;
- gc->dbg_show = NULL;
- gc->base = pdata->gpio_base;
- gc->ngpio = pdata->nr_pins;
- gc->can_sleep = false;
-
- err = gpiochip_add(gc);
+ err = bgpio_init(bgc, dev, 4, tgpio->membase + TGPIOVAL,
+ NULL, NULL, tgpio->membase + TGPIODIR, NULL, 0);
+
+ if (err) {
+ dev_err(&pdev->dev, "bgpio_init failed\n");
+ return err;
+ }
+ bgc->gc.label = dev_name(&pdev->dev);
+ bgc->gc.owner = THIS_MODULE;
+ bgc->gc.dev = &pdev->dev;
+ bgc->gc.to_irq = (irq >= 0 && tgpio->irq_base > 0) ?
+ timbgpio_to_irq : NULL;
+ bgc->gc.dbg_show = NULL;
+ bgc->gc.base = pdata->gpio_base;
+ bgc->gc.ngpio = pdata->nr_pins;
+ bgc->gc.can_sleep = false;
+
+ tgpio->gpio = bgc->gc;
+ err = gpiochip_add(&bgc->gc);
if (err)
return err;