* [PATCH] gpio: Added timbgpio
@ 2009-06-03 8:07 Richard Röjfors
2009-06-04 7:51 ` Andrew Morton
0 siblings, 1 reply; 5+ messages in thread
From: Richard Röjfors @ 2009-06-03 8:07 UTC (permalink / raw)
To: linux-kernel; +Cc: 'Richard Röjfors'
Supplied is a GPIO driver for the Timberdale FPGA found on the
Intel Atom board Russellville.
Signed-off-by: Richard Röjfors <richard.rojfors.ext@mocean-labs.com>
---
Index: linux-2.6.30-rc7/drivers/gpio/timbgpio.h
===================================================================
--- linux-2.6.30-rc7/drivers/gpio/timbgpio.h (revision 0)
+++ linux-2.6.30-rc7/drivers/gpio/timbgpio.h (revision 864)
@@ -0,0 +1,48 @@
+/*
+ * timbgpio.h timberdale FPGA GPIO driver defines
+ * Copyright (c) 2009 Intel Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+/* Supports:
+ * Timberdale FPGA GPIO
+ */
+
+#ifndef _TIMBGPIO_H_
+#define _TIMBGPIO_H_
+
+#include <linux/mutex.h>
+#include <linux/gpio.h>
+
+#define TIMB_NR_GPIOS 16
+
+#define TGPIOVAL 0
+#define TGPIODIR 0x04
+#define TGPIOINT 0x08
+#define TGPIOINT_STATUS 0x0c
+#define TGPIOINT_PENDING 0x10
+#define TGPIOINT_CLR 0x14
+#define TGPIOFLK 0x18
+#define TGPIOLVL 0x1c
+
+struct timbgpio {
+ void __iomem *membase;
+ struct resource rscr;
+ struct mutex lock; /* mutual exclusion */
+ struct pci_dev *pdev;
+ struct gpio_chip gpio;
+};
+
+#endif
Index: linux-2.6.30-rc7/drivers/gpio/timbgpio.c
===================================================================
--- linux-2.6.30-rc7/drivers/gpio/timbgpio.c (revision 0)
+++ linux-2.6.30-rc7/drivers/gpio/timbgpio.c (revision 864)
@@ -0,0 +1,275 @@
+/*
+ * timbgpio.c timberdale FPGA GPIO driver
+ * Copyright (c) 2009 Intel Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+/* Supports:
+ * Timberdale FPGA GPIO
+ */
+
+#include <linux/module.h>
+#include <linux/gpio.h>
+#include <linux/pci.h>
+#include <linux/platform_device.h>
+#include <linux/interrupt.h>
+
+#include "timbgpio.h"
+
+static u32 timbgpio_configure(struct gpio_chip *gpio, unsigned nr,
+ unsigned off, unsigned val)
+{
+ struct timbgpio *tgpio = container_of(gpio, struct timbgpio, gpio);
+
+ u32 config, oldconfig, wconfig;
+
+ mutex_lock(&tgpio->lock);
+ config = ioread32(tgpio->membase + off);
+ oldconfig = config;
+
+ if (val)
+ config |= (1 << nr);
+ else
+ config &= ~(1 << nr);
+
+ iowrite32(config, tgpio->membase + off);
+ wconfig = ioread32(tgpio->membase + off);
+ mutex_unlock(&tgpio->lock);
+
+ return oldconfig;
+}
+
+static int timbgpio_gpio_direction_input(struct gpio_chip *gpio, unsigned nr)
+{
+ timbgpio_configure(gpio, nr, TGPIODIR, 1);
+ return 0;
+}
+
+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)
+{
+ timbgpio_configure(gpio, nr, TGPIODIR, 0);
+ return 0;
+}
+
+
+
+static void timbgpio_gpio_set(struct gpio_chip *gpio,
+ unsigned nr, int val)
+{
+ timbgpio_configure(gpio, nr, TGPIOVAL, val);
+}
+
+/*
+ * Function to control flank or level triggered GPIO pin
+ * @nr - pin
+ * @ val - 1: flank, 0: level
+ *
+ */
+static void timbgpio_gpio_flnk_lvl_ctrl(struct gpio_chip *gpio,
+ unsigned nr, int val)
+{
+ timbgpio_configure(gpio, nr, TGPIOFLK, val);
+}
+EXPORT_SYMBOL(timbgpio_gpio_flnk_lvl_ctrl);
+
+/*
+ * Enable or disable interrupt
+ *
+ */
+static void timbgpio_gpio_int_ctrl(struct gpio_chip *gpio,
+ unsigned nr, int val)
+{
+ timbgpio_configure(gpio, nr, TGPIOINT, val);
+}
+EXPORT_SYMBOL(timbgpio_gpio_int_ctrl);
+
+/*
+ * @val - 1: Asserted high or on positive flank, 0: Asserted low or on negative flank
+ *
+ */
+static void timbgpio_gpio_lvl_ctrl(struct gpio_chip *gpio,
+ unsigned nr, int val)
+{
+ timbgpio_configure(gpio, nr, TGPIOLVL, val);
+}
+EXPORT_SYMBOL(timbgpio_gpio_lvl_ctrl);
+
+static void timbgpio_gpio_int_clr(struct gpio_chip *gpio,
+ unsigned nr, int val)
+{
+ timbgpio_configure(gpio, nr, TGPIOINT_CLR, val);
+}
+EXPORT_SYMBOL(timbgpio_gpio_int_clr);
+
+
+static irqreturn_t timbgpio_handleinterrupt(int irq, void *devid)
+{
+ struct timbgpio *tgpio = (struct timbgpio *)devid;
+
+ iowrite32(0xffffffff, tgpio->membase + TGPIOINT_CLR);
+
+ return IRQ_HANDLED;
+}
+
+static int timbgpio_probe(struct platform_device *dev)
+{
+ int err, irq;
+ struct gpio_chip *gc;
+ struct timbgpio *tgpio;
+ struct resource *iomem, *rscr;
+
+ iomem = platform_get_resource(dev, IORESOURCE_MEM, 0);
+ if (!iomem) {
+ err = -EINVAL;
+ goto err_mem;
+ }
+
+ tgpio = kzalloc(sizeof(*tgpio), GFP_KERNEL);
+ if (!tgpio) {
+ err = -EINVAL;
+ goto err_mem;
+ }
+
+ mutex_init(&tgpio->lock);
+
+ rscr = &tgpio->rscr;
+ rscr->name = "timb-gpio";
+ rscr->start = iomem->start;
+ rscr->end = iomem->end;
+ rscr->flags = IORESOURCE_MEM;
+
+ err = request_resource(iomem, rscr);
+ if (err)
+ goto err_request;
+
+ tgpio->membase = ioremap(rscr->start, resource_size(rscr));
+ if (!tgpio->membase) {
+ err = -ENOMEM;
+ goto err_ioremap;
+ }
+
+ gc = &tgpio->gpio;
+
+ gc->label = "timbgpio";
+ gc->owner = THIS_MODULE;
+ 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->dbg_show = NULL;
+ gc->base = 0;
+ gc->ngpio = TIMB_NR_GPIOS;
+ gc->can_sleep = 0;
+
+ err = gpiochip_add(gc);
+ if (err)
+ goto err_chipadd;
+
+ platform_set_drvdata(dev, tgpio);
+
+ /* register interrupt */
+ irq = platform_get_irq(dev, 0);
+ if (irq < 0)
+ goto err_get_irq;
+
+ /* clear pending interrupts */
+ iowrite32(0xffffffff, tgpio->membase + TGPIOINT_CLR);
+ iowrite32(0x0, tgpio->membase + TGPIOINT);
+
+ /* request IRQ */
+ err = request_irq(irq, timbgpio_handleinterrupt, IRQF_SHARED,
+ "timb-gpio", tgpio);
+ if (err) {
+ printk(KERN_ERR "timbgpio: Failed to request IRQ\n");
+ goto err_get_irq;
+ }
+
+ return err;
+
+err_get_irq:
+ err = gpiochip_remove(&tgpio->gpio);
+ if (err)
+ printk(KERN_ERR "timbgpio: failed to remove gpio_chip\n");
+err_chipadd:
+ iounmap(tgpio->membase);
+err_ioremap:
+ release_resource(&tgpio->rscr);
+err_request:
+ kfree(tgpio);
+err_mem:
+ printk(KERN_ERR "timberdale: Failed to register GPIOs: %d\n", err);
+
+ return err;
+}
+
+static int timbgpio_remove(struct platform_device *dev)
+{
+ int err;
+ struct timbgpio *tgpio = platform_get_drvdata(dev);
+
+ /* disable interrupts */
+ iowrite32(0x0, tgpio->membase + TGPIOINT);
+
+ free_irq(platform_get_irq(dev, 0), tgpio);
+ err = gpiochip_remove(&tgpio->gpio);
+ if (err)
+ printk(KERN_ERR "timbgpio: failed to remove gpio_chip\n");
+
+ iounmap(tgpio->membase);
+ release_resource(&tgpio->rscr);
+ kfree(tgpio);
+
+ return 0;
+}
+
+static struct platform_driver timbgpio_platform_driver = {
+ .driver = {
+ .name = "timb-gpio",
+ .owner = THIS_MODULE,
+ },
+ .probe = timbgpio_probe,
+ .remove = timbgpio_remove,
+};
+
+/*--------------------------------------------------------------------------*/
+
+static int __init timbgpio_init(void)
+{
+ return platform_driver_register(&timbgpio_platform_driver);
+}
+
+static void __exit timbgpio_exit(void)
+{
+ platform_driver_unregister(&timbgpio_platform_driver);
+}
+
+module_init(timbgpio_init);
+module_exit(timbgpio_exit);
+
+MODULE_DESCRIPTION("Timberdale GPIO driver");
+MODULE_LICENSE("GPL v2");
+MODULE_AUTHOR("Mocean Laboratories");
+MODULE_ALIAS("platform:timb-gpio");
+
Index: linux-2.6.30-rc7/drivers/gpio/Kconfig
===================================================================
--- linux-2.6.30-rc7/drivers/gpio/Kconfig (revision 861)
+++ linux-2.6.30-rc7/drivers/gpio/Kconfig (working copy)
@@ -161,6 +161,12 @@
If unsure, say N.
+config GPIO_TIMBERDALE
+ tristate "Support for timberdale GPIO"
+ depends on MFD_TIMBERDALE && GPIOLIB
+ ---help---
+ Add support for GPIO usage of some pins of the timberdale FPGA.
+
comment "SPI GPIO expanders:"
config GPIO_MAX7301
Index: linux-2.6.30-rc7/drivers/gpio/Makefile
===================================================================
--- linux-2.6.30-rc7/drivers/gpio/Makefile (revision 861)
+++ linux-2.6.30-rc7/drivers/gpio/Makefile (working copy)
@@ -12,3 +12,5 @@
obj-$(CONFIG_GPIO_TWL4030) += twl4030-gpio.o
obj-$(CONFIG_GPIO_XILINX) += xilinx_gpio.o
obj-$(CONFIG_GPIO_BT8XX) += bt8xxgpio.o
+obj-$(CONFIG_GPIO_TIMBERDALE) += timbgpio.o
+
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] gpio: Added timbgpio
2009-06-03 8:07 [PATCH] gpio: Added timbgpio Richard Röjfors
@ 2009-06-04 7:51 ` Andrew Morton
2009-06-04 12:53 ` Richard Röjfors
0 siblings, 1 reply; 5+ messages in thread
From: Andrew Morton @ 2009-06-04 7:51 UTC (permalink / raw)
To: Richard Röjfors; +Cc: linux-kernel
On Wed, 03 Jun 2009 10:07:48 +0200 Richard R____jfors <richard.rojfors.ext@mocean-labs.com> wrote:
> Supplied is a GPIO driver for the Timberdale FPGA found on the
> Intel Atom board Russellville.
>
> ...
>
> +EXPORT_SYMBOL(timbgpio_gpio_flnk_lvl_ctrl);
> +EXPORT_SYMBOL(timbgpio_gpio_int_ctrl);
> +EXPORT_SYMBOL(timbgpio_gpio_lvl_ctrl);
> +EXPORT_SYMBOL(timbgpio_gpio_int_clr);
Why all these module exports?
> ...
>
> +config GPIO_TIMBERDALE
> + tristate "Support for timberdale GPIO"
> + depends on MFD_TIMBERDALE && GPIOLIB
> + ---help---
> + Add support for GPIO usage of some pins of the timberdale FPGA.
> +
I cannot find anything which sets MFD_TIMBERDALE anywhere?
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] gpio: Added timbgpio
2009-06-04 7:51 ` Andrew Morton
@ 2009-06-04 12:53 ` Richard Röjfors
2009-06-04 18:53 ` Andrew Morton
0 siblings, 1 reply; 5+ messages in thread
From: Richard Röjfors @ 2009-06-04 12:53 UTC (permalink / raw)
To: Andrew Morton; +Cc: linux-kernel
Andrew Morton wrote:
> On Wed, 03 Jun 2009 10:07:48 +0200 Richard R____jfors <richard.rojfors.ext@mocean-labs.com> wrote:
>
>> Supplied is a GPIO driver for the Timberdale FPGA found on the
>> Intel Atom board Russellville.
>>
>> ...
>>
>> +EXPORT_SYMBOL(timbgpio_gpio_flnk_lvl_ctrl);
>> +EXPORT_SYMBOL(timbgpio_gpio_int_ctrl);
>> +EXPORT_SYMBOL(timbgpio_gpio_lvl_ctrl);
>> +EXPORT_SYMBOL(timbgpio_gpio_int_clr);
>
> Why all these module exports?
Internal stuff, I will remove it.
>> ...
>>
>> +config GPIO_TIMBERDALE
>> + tristate "Support for timberdale GPIO"
>> + depends on MFD_TIMBERDALE && GPIOLIB
>> + ---help---
>> + Add support for GPIO usage of some pins of the timberdale FPGA.
>> +
>
> I cannot find anything which sets MFD_TIMBERDALE anywhere?
Sorry, I realize I have to come back with a bigger patch set.
Timberdale is the MFD driver for the FPGA which among other expose this GPIO device.
This patch set will depend on patches in i2c-ocores and xilinx_spi which I have posted
earlier on the corresponding mailinglists.
Shall I repost those driver changes within this patch set, or can I leave them out?
--Richard
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] gpio: Added timbgpio
2009-06-04 12:53 ` Richard Röjfors
@ 2009-06-04 18:53 ` Andrew Morton
0 siblings, 0 replies; 5+ messages in thread
From: Andrew Morton @ 2009-06-04 18:53 UTC (permalink / raw)
To: Richard Röjfors; +Cc: linux-kernel
On Thu, 04 Jun 2009 14:53:04 +0200 Richard R____jfors <richard.rojfors.ext@mocean-labs.com> wrote:
> Timberdale is the MFD driver for the FPGA which among other expose this GPIO device.
> This patch set will depend on patches in i2c-ocores and xilinx_spi which I have posted
> earlier on the corresponding mailinglists.
> Shall I repost those driver changes within this patch set, or can I leave them out?
Resend everything in a single sequence-numbered patchset, Ccing every
relevant person (including myself) and mailing list on everything.
That should cover it ;)
Please also identify any merging-order interdependencies between the
individual patches.
If it all looks OK then the chances are that I'll merge it all into my
tree and than shall take care of maintainer-bugging for you.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH] gpio: Added timbgpio
@ 2009-10-06 14:16 Richard Röjfors
0 siblings, 0 replies; 5+ messages in thread
From: Richard Röjfors @ 2009-10-06 14:16 UTC (permalink / raw)
To: Linux Kernel Mailing List; +Cc: david-b, Andrew Morton
Supplied is a GPIO driver for the Timberdale FPGA found on the
Intel Atom board Russellville.
The GPIO driver also have a IRQ-chip to support interrupts
on the pins.
Signed-off-by: Richard Röjfors <richard.rojfors@mocean-labs.com>
---
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index 2ad0128..743ede6 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -196,6 +196,12 @@ config GPIO_LANGWELL
help
Say Y here to support Intel Moorestown platform GPIO.
+config GPIO_TIMBERDALE
+ bool "Support for timberdale GPIO IP"
+ depends on MFD_TIMBERDALE && GPIOLIB && HAS_IOMEM
+ ---help---
+ Add support for the GPIO IP in the timberdale FPGA.
+
comment "SPI GPIO expanders:"
config GPIO_MAX7301
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index 00a532c..2ff686b 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -13,6 +13,7 @@ obj-$(CONFIG_GPIO_MCP23S08) += mcp23s08.o
obj-$(CONFIG_GPIO_PCA953X) += pca953x.o
obj-$(CONFIG_GPIO_PCF857X) += pcf857x.o
obj-$(CONFIG_GPIO_PL061) += pl061.o
+obj-$(CONFIG_GPIO_TIMBERDALE) += timbgpio.o
obj-$(CONFIG_GPIO_TWL4030) += twl4030-gpio.o
obj-$(CONFIG_GPIO_UCB1400) += ucb1400_gpio.o
obj-$(CONFIG_GPIO_XILINX) += xilinx_gpio.o
diff --git a/drivers/gpio/timbgpio.c b/drivers/gpio/timbgpio.c
new file mode 100644
index 0000000..a4d344b
--- /dev/null
+++ b/drivers/gpio/timbgpio.c
@@ -0,0 +1,342 @@
+/*
+ * timbgpio.c timberdale FPGA GPIO driver
+ * Copyright (c) 2009 Intel Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+/* Supports:
+ * Timberdale FPGA GPIO
+ */
+
+#include <linux/module.h>
+#include <linux/gpio.h>
+#include <linux/platform_device.h>
+#include <linux/io.h>
+#include <linux/timb_gpio.h>
+#include <linux/interrupt.h>
+
+#define DRIVER_NAME "timb-gpio"
+
+#define TGPIOVAL 0x00
+#define TGPIODIR 0x04
+#define TGPIO_IER 0x08
+#define TGPIO_ISR 0x0c
+#define TGPIO_IPR 0x10
+#define TGPIO_ICR 0x14
+#define TGPIO_FLR 0x18
+#define TGPIO_LVR 0x1c
+
+struct timbgpio {
+ void __iomem *membase;
+ spinlock_t lock; /* mutual exclusion */
+ struct gpio_chip gpio;
+ int irq_base;
+};
+
+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);
+
+ if (tgpio->irq_base <= 0)
+ return -EINVAL;
+
+ return tgpio->irq_base + offset;
+}
+
+/*
+ * GPIO IRQ
+ */
+static void timbgpio_irq_disable(unsigned irq)
+{
+ struct timbgpio *tgpio = get_irq_chip_data(irq);
+ int offset = irq - tgpio->irq_base;
+
+ timbgpio_update_bit(&tgpio->gpio, offset, TGPIO_IER, 0);
+}
+
+static void timbgpio_irq_enable(unsigned irq)
+{
+ struct timbgpio *tgpio = get_irq_chip_data(irq);
+ int offset = irq - tgpio->irq_base;
+
+ timbgpio_update_bit(&tgpio->gpio, offset, TGPIO_IER, 1);
+}
+
+static int timbgpio_irq_type(unsigned irq, unsigned trigger)
+{
+ struct timbgpio *tgpio = get_irq_chip_data(irq);
+ int offset = irq - tgpio->irq_base;
+ unsigned long flags;
+ u32 lvr, flr;
+
+ if (offset < 0 || offset > tgpio->gpio.ngpio)
+ return -EINVAL;
+
+ spin_lock_irqsave(&tgpio->lock, flags);
+
+ lvr = ioread32(tgpio->membase + TGPIO_LVR);
+ flr = ioread32(tgpio->membase + TGPIO_FLR);
+
+ if (trigger & (IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) {
+ flr &= ~(1 << offset);
+ if (trigger & IRQ_TYPE_LEVEL_HIGH)
+ lvr |= 1 << offset;
+ else
+ lvr &= ~(1 << offset);
+ }
+
+ if ((trigger & IRQ_TYPE_EDGE_BOTH) == IRQ_TYPE_EDGE_BOTH)
+ return -EINVAL;
+ else {
+ flr |= 1 << offset;
+ /* opposite compared to the datasheet, but it mirrors the
+ * reality
+ */
+ if (trigger & IRQ_TYPE_EDGE_FALLING)
+ lvr |= 1 << offset;
+ else
+ lvr &= ~(1 << offset);
+ }
+
+ iowrite32(lvr, tgpio->membase + TGPIO_LVR);
+ iowrite32(flr, tgpio->membase + TGPIO_FLR);
+ iowrite32(1 << offset, tgpio->membase + TGPIO_ICR);
+ spin_unlock_irqrestore(&tgpio->lock, flags);
+
+ return 0;
+}
+
+static void timbgpio_irq(unsigned int irq, struct irq_desc *desc)
+{
+ struct timbgpio *tgpio = get_irq_data(irq);
+ unsigned long ipr;
+ int offset;
+
+ desc->chip->ack(irq);
+ ipr = ioread32(tgpio->membase + TGPIO_IPR);
+ iowrite32(ipr, tgpio->membase + TGPIO_ICR);
+
+ for_each_bit(offset, &ipr, tgpio->gpio.ngpio)
+ generic_handle_irq(timbgpio_to_irq(&tgpio->gpio, offset));
+}
+
+static struct irq_chip timbgpio_irqchip = {
+ .name = "GPIO",
+ .enable = timbgpio_irq_enable,
+ .disable = timbgpio_irq_disable,
+ .set_type = timbgpio_irq_type,
+};
+
+static int __devinit timbgpio_probe(struct platform_device *pdev)
+{
+ int err, i;
+ struct gpio_chip *gc;
+ struct timbgpio *tgpio;
+ struct resource *iomem;
+ struct timbgpio_platform_data *pdata = pdev->dev.platform_data;
+ int irq = platform_get_irq(pdev, 0);
+
+ if (!pdata || pdata->nr_pins > 32) {
+ err = -EINVAL;
+ goto err_mem;
+ }
+
+ iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ if (!iomem) {
+ err = -EINVAL;
+ goto err_mem;
+ }
+
+ tgpio = kzalloc(sizeof(*tgpio), GFP_KERNEL);
+ if (!tgpio) {
+ err = -EINVAL;
+ goto err_mem;
+ }
+ tgpio->irq_base = pdata->irq_base;
+
+ spin_lock_init(&tgpio->lock);
+
+ if (!request_mem_region(iomem->start, resource_size(iomem),
+ DRIVER_NAME)) {
+ err = -EBUSY;
+ goto err_request;
+ }
+
+ tgpio->membase = ioremap(iomem->start, resource_size(iomem));
+ if (!tgpio->membase) {
+ err = -ENOMEM;
+ goto err_ioremap;
+ }
+
+ 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 = 0;
+
+ err = gpiochip_add(gc);
+ if (err)
+ goto err_chipadd;
+
+ platform_set_drvdata(pdev, tgpio);
+
+ /* make sure to disable interrupts */
+ iowrite32(0x0, tgpio->membase + TGPIO_IER);
+
+ if (irq < 0 || tgpio->irq_base <= 0)
+ return 0;
+
+ for (i = 0; i < pdata->nr_pins; i++) {
+ set_irq_chip_and_handler_name(tgpio->irq_base + i,
+ &timbgpio_irqchip, handle_simple_irq, "mux");
+ set_irq_chip_data(tgpio->irq_base + i, tgpio);
+#ifdef CONFIG_ARM
+ set_irq_flags(tgpio->irq_base + i, IRQF_VALID | IRQF_PROBE);
+#endif
+ }
+
+ set_irq_data(irq, tgpio);
+ set_irq_chained_handler(irq, timbgpio_irq);
+
+ return 0;
+
+err_chipadd:
+ iounmap(tgpio->membase);
+err_ioremap:
+ release_mem_region(iomem->start, resource_size(iomem));
+err_request:
+ kfree(tgpio);
+err_mem:
+ printk(KERN_ERR DRIVER_NAME": Failed to register GPIOs: %d\n", err);
+
+ return err;
+}
+
+static int __devexit timbgpio_remove(struct platform_device *pdev)
+{
+ int err;
+ struct timbgpio_platform_data *pdata = pdev->dev.platform_data;
+ struct timbgpio *tgpio = platform_get_drvdata(pdev);
+ struct resource *iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ int irq = platform_get_irq(pdev, 0);
+
+ if (irq >= 0 && tgpio->irq_base > 0) {
+ int i;
+ for (i = 0; i < pdata->nr_pins; i++) {
+ set_irq_chip(tgpio->irq_base + i, NULL);
+ set_irq_chip_data(tgpio->irq_base + i, NULL);
+ }
+
+ set_irq_handler(irq, NULL);
+ set_irq_data(irq, NULL);
+ }
+
+ err = gpiochip_remove(&tgpio->gpio);
+ if (err)
+ printk(KERN_ERR DRIVER_NAME": failed to remove gpio_chip\n");
+
+ iounmap(tgpio->membase);
+ release_mem_region(iomem->start, resource_size(iomem));
+ kfree(tgpio);
+
+ platform_set_drvdata(pdev, NULL);
+
+ return 0;
+}
+
+static struct platform_driver timbgpio_platform_driver = {
+ .driver = {
+ .name = DRIVER_NAME,
+ .owner = THIS_MODULE,
+ },
+ .probe = timbgpio_probe,
+ .remove = timbgpio_remove,
+};
+
+/*--------------------------------------------------------------------------*/
+
+static int __init timbgpio_init(void)
+{
+ return platform_driver_register(&timbgpio_platform_driver);
+}
+
+static void __exit timbgpio_exit(void)
+{
+ platform_driver_unregister(&timbgpio_platform_driver);
+}
+
+module_init(timbgpio_init);
+module_exit(timbgpio_exit);
+
+MODULE_DESCRIPTION("Timberdale GPIO driver");
+MODULE_LICENSE("GPL v2");
+MODULE_AUTHOR("Mocean Laboratories");
+MODULE_ALIAS("platform:"DRIVER_NAME);
+
diff --git a/include/linux/timb_gpio.h b/include/linux/timb_gpio.h
new file mode 100644
index 0000000..ce456ea
--- /dev/null
+++ b/include/linux/timb_gpio.h
@@ -0,0 +1,37 @@
+/*
+ * timb_gpio.h timberdale FPGA GPIO driver, platform data definition
+ * Copyright (c) 2009 Intel Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef _LINUX_TIMB_GPIO_H
+#define _LINUX_TIMB_GPIO_H
+
+/**
+ * struct timbgpio_platform_data - Platform data of the Timberdale GPIO driver
+ * @gpio_base The number of the first GPIO pin, set to -1 for
+ * dynamic number allocation.
+ * @nr_pins Number of pins that is supported by the hardware (1-32)
+ * @irq_base If IRQ is supported by the hardware, this is the base
+ * number of IRQ:s. One IRQ per pin will be used. Set to
+ * -1 if IRQ:s is not supported.
+ */
+struct timbgpio_platform_data {
+ int gpio_base;
+ int nr_pins;
+ int irq_base;
+};
+
+#endif
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2009-10-06 14:47 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-06-03 8:07 [PATCH] gpio: Added timbgpio Richard Röjfors
2009-06-04 7:51 ` Andrew Morton
2009-06-04 12:53 ` Richard Röjfors
2009-06-04 18:53 ` Andrew Morton
2009-10-06 14:16 Richard Röjfors
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.