Linux 4.1.16
[linux/fpc-iii.git] / drivers / gpio / gpio-ge.c
blobf9ac3f351753fe0bd6925fc4a0ee232672ab7be8
1 /*
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.
13 /* TODO
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>
21 #include <linux/io.h>
22 #include <linux/slab.h>
23 #include <linux/of_device.h>
24 #include <linux/of_gpio.h>
25 #include <linux/of_address.h>
26 #include <linux/module.h>
27 #include <linux/basic_mmio_gpio.h>
29 #define GEF_GPIO_DIRECT 0x00
30 #define GEF_GPIO_IN 0x04
31 #define GEF_GPIO_OUT 0x08
32 #define GEF_GPIO_TRIG 0x0C
33 #define GEF_GPIO_POLAR_A 0x10
34 #define GEF_GPIO_POLAR_B 0x14
35 #define GEF_GPIO_INT_STAT 0x18
36 #define GEF_GPIO_OVERRUN 0x1C
37 #define GEF_GPIO_MODE 0x20
39 static const struct of_device_id gef_gpio_ids[] = {
41 .compatible = "gef,sbc610-gpio",
42 .data = (void *)19,
43 }, {
44 .compatible = "gef,sbc310-gpio",
45 .data = (void *)6,
46 }, {
47 .compatible = "ge,imp3a-gpio",
48 .data = (void *)16,
50 { }
52 MODULE_DEVICE_TABLE(of, gef_gpio_ids);
54 static int __init gef_gpio_probe(struct platform_device *pdev)
56 const struct of_device_id *of_id =
57 of_match_device(gef_gpio_ids, &pdev->dev);
58 struct bgpio_chip *bgc;
59 void __iomem *regs;
60 int ret;
62 bgc = devm_kzalloc(&pdev->dev, sizeof(*bgc), GFP_KERNEL);
63 if (!bgc)
64 return -ENOMEM;
66 regs = of_iomap(pdev->dev.of_node, 0);
67 if (!regs)
68 return -ENOMEM;
70 ret = bgpio_init(bgc, &pdev->dev, 4, regs + GEF_GPIO_IN,
71 regs + GEF_GPIO_OUT, NULL, NULL,
72 regs + GEF_GPIO_DIRECT, BGPIOF_BIG_ENDIAN_BYTE_ORDER);
73 if (ret) {
74 dev_err(&pdev->dev, "bgpio_init failed\n");
75 goto err0;
78 /* Setup pointers to chip functions */
79 bgc->gc.label = devm_kstrdup(&pdev->dev, pdev->dev.of_node->full_name,
80 GFP_KERNEL);
81 if (!bgc->gc.label) {
82 ret = -ENOMEM;
83 goto err0;
86 bgc->gc.base = -1;
87 bgc->gc.ngpio = (u16)(uintptr_t)of_id->data;
88 bgc->gc.of_gpio_n_cells = 2;
89 bgc->gc.of_node = pdev->dev.of_node;
91 /* This function adds a memory mapped GPIO chip */
92 ret = gpiochip_add(&bgc->gc);
93 if (ret)
94 goto err0;
96 return 0;
97 err0:
98 iounmap(regs);
99 pr_err("%s: GPIO chip registration failed\n",
100 pdev->dev.of_node->full_name);
101 return ret;
104 static struct platform_driver gef_gpio_driver = {
105 .driver = {
106 .name = "gef-gpio",
107 .of_match_table = gef_gpio_ids,
110 module_platform_driver_probe(gef_gpio_driver, gef_gpio_probe);
112 MODULE_DESCRIPTION("GE I/O FPGA GPIO driver");
113 MODULE_AUTHOR("Martyn Welch <martyn.welch@ge.com");
114 MODULE_LICENSE("GPL");