2 * Driver for GE FPGA based GPIO
4 * Author: Martyn Welch <martyn.welch@ge.com>
6 * 2008 (c) GE Intelligent Platforms Embedded Systems, Inc.
8 * This file is licensed under the terms of the GNU General Public License
9 * version 2. This program is licensed "as is" without any warranty of any
10 * kind, whether express or implied.
15 * Configuration of output modes (totem-pole/open-drain)
16 * Interrupt configuration - interrupts are always generated the FPGA relies on
17 * the I/O interrupt controllers mask to stop them propergating
20 #include <linux/kernel.h>
22 #include <linux/slab.h>
23 #include <linux/of_device.h>
24 #include <linux/of_address.h>
25 #include <linux/module.h>
26 #include <linux/gpio/driver.h>
28 #define GEF_GPIO_DIRECT 0x00
29 #define GEF_GPIO_IN 0x04
30 #define GEF_GPIO_OUT 0x08
31 #define GEF_GPIO_TRIG 0x0C
32 #define GEF_GPIO_POLAR_A 0x10
33 #define GEF_GPIO_POLAR_B 0x14
34 #define GEF_GPIO_INT_STAT 0x18
35 #define GEF_GPIO_OVERRUN 0x1C
36 #define GEF_GPIO_MODE 0x20
38 static const struct of_device_id gef_gpio_ids[] = {
40 .compatible = "gef,sbc610-gpio",
43 .compatible = "gef,sbc310-gpio",
46 .compatible = "ge,imp3a-gpio",
51 MODULE_DEVICE_TABLE(of, gef_gpio_ids);
53 static int __init gef_gpio_probe(struct platform_device *pdev)
59 gc = devm_kzalloc(&pdev->dev, sizeof(*gc), GFP_KERNEL);
63 regs = of_iomap(pdev->dev.of_node, 0);
67 ret = bgpio_init(gc, &pdev->dev, 4, regs + GEF_GPIO_IN,
68 regs + GEF_GPIO_OUT, NULL, NULL,
69 regs + GEF_GPIO_DIRECT, BGPIOF_BIG_ENDIAN_BYTE_ORDER);
71 dev_err(&pdev->dev, "bgpio_init failed\n");
75 /* Setup pointers to chip functions */
76 gc->label = devm_kasprintf(&pdev->dev, GFP_KERNEL, "%pOF", pdev->dev.of_node);
83 gc->ngpio = (u16)(uintptr_t)of_device_get_match_data(&pdev->dev);
84 gc->of_gpio_n_cells = 2;
86 /* This function adds a memory mapped GPIO chip */
87 ret = devm_gpiochip_add_data(&pdev->dev, gc, NULL);
94 pr_err("%pOF: GPIO chip registration failed\n", pdev->dev.of_node);
98 static struct platform_driver gef_gpio_driver = {
101 .of_match_table = gef_gpio_ids,
104 module_platform_driver_probe(gef_gpio_driver, gef_gpio_probe);
106 MODULE_DESCRIPTION("GE I/O FPGA GPIO driver");
107 MODULE_AUTHOR("Martyn Welch <martyn.welch@ge.com");
108 MODULE_LICENSE("GPL");