Loading...
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * Driver for GE FPGA based GPIO
4 *
5 * Author: Martyn Welch <martyn.welch@ge.com>
6 *
7 * 2008 (c) GE Intelligent Platforms Embedded Systems, Inc.
8 */
9
10/*
11 * TODO:
12 *
13 * Configuration of output modes (totem-pole/open-drain).
14 * Interrupt configuration - interrupts are always generated, the FPGA relies
15 * on the I/O interrupt controllers mask to stop them from being propagated.
16 */
17
18#include <linux/gpio/driver.h>
19#include <linux/io.h>
20#include <linux/kernel.h>
21#include <linux/mod_devicetable.h>
22#include <linux/module.h>
23#include <linux/platform_device.h>
24#include <linux/property.h>
25#include <linux/slab.h>
26
27#define GEF_GPIO_DIRECT 0x00
28#define GEF_GPIO_IN 0x04
29#define GEF_GPIO_OUT 0x08
30#define GEF_GPIO_TRIG 0x0C
31#define GEF_GPIO_POLAR_A 0x10
32#define GEF_GPIO_POLAR_B 0x14
33#define GEF_GPIO_INT_STAT 0x18
34#define GEF_GPIO_OVERRUN 0x1C
35#define GEF_GPIO_MODE 0x20
36
37static const struct of_device_id gef_gpio_ids[] = {
38 {
39 .compatible = "gef,sbc610-gpio",
40 .data = (void *)19,
41 }, {
42 .compatible = "gef,sbc310-gpio",
43 .data = (void *)6,
44 }, {
45 .compatible = "ge,imp3a-gpio",
46 .data = (void *)16,
47 },
48 { }
49};
50MODULE_DEVICE_TABLE(of, gef_gpio_ids);
51
52static int __init gef_gpio_probe(struct platform_device *pdev)
53{
54 struct device *dev = &pdev->dev;
55 struct gpio_chip *gc;
56 void __iomem *regs;
57 int ret;
58
59 gc = devm_kzalloc(dev, sizeof(*gc), GFP_KERNEL);
60 if (!gc)
61 return -ENOMEM;
62
63 regs = devm_platform_ioremap_resource(pdev, 0);
64 if (IS_ERR(regs))
65 return PTR_ERR(regs);
66
67 ret = bgpio_init(gc, dev, 4, regs + GEF_GPIO_IN, regs + GEF_GPIO_OUT,
68 NULL, NULL, regs + GEF_GPIO_DIRECT,
69 BGPIOF_BIG_ENDIAN_BYTE_ORDER);
70 if (ret)
71 return dev_err_probe(dev, ret, "bgpio_init failed\n");
72
73 /* Setup pointers to chip functions */
74 gc->label = devm_kasprintf(dev, GFP_KERNEL, "%pfw", dev_fwnode(dev));
75 if (!gc->label)
76 return -ENOMEM;
77
78 gc->base = -1;
79 gc->ngpio = (uintptr_t)device_get_match_data(dev);
80
81 /* This function adds a memory mapped GPIO chip */
82 ret = devm_gpiochip_add_data(dev, gc, NULL);
83 if (ret)
84 return dev_err_probe(dev, ret, "GPIO chip registration failed\n");
85
86 return 0;
87};
88
89static struct platform_driver gef_gpio_driver = {
90 .driver = {
91 .name = "gef-gpio",
92 .of_match_table = gef_gpio_ids,
93 },
94};
95module_platform_driver_probe(gef_gpio_driver, gef_gpio_probe);
96
97MODULE_DESCRIPTION("GE I/O FPGA GPIO driver");
98MODULE_AUTHOR("Martyn Welch <martyn.welch@ge.com>");
99MODULE_LICENSE("GPL");
1/*
2 * Driver for GE FPGA based GPIO
3 *
4 * Author: Martyn Welch <martyn.welch@ge.com>
5 *
6 * 2008 (c) GE Intelligent Platforms Embedded Systems, Inc.
7 *
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.
11 */
12
13/* TODO
14 *
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
18 */
19
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_address.h>
25#include <linux/module.h>
26#include <linux/gpio/driver.h>
27
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
37
38static const struct of_device_id gef_gpio_ids[] = {
39 {
40 .compatible = "gef,sbc610-gpio",
41 .data = (void *)19,
42 }, {
43 .compatible = "gef,sbc310-gpio",
44 .data = (void *)6,
45 }, {
46 .compatible = "ge,imp3a-gpio",
47 .data = (void *)16,
48 },
49 { }
50};
51MODULE_DEVICE_TABLE(of, gef_gpio_ids);
52
53static int __init gef_gpio_probe(struct platform_device *pdev)
54{
55 const struct of_device_id *of_id =
56 of_match_device(gef_gpio_ids, &pdev->dev);
57 struct gpio_chip *gc;
58 void __iomem *regs;
59 int ret;
60
61 gc = devm_kzalloc(&pdev->dev, sizeof(*gc), GFP_KERNEL);
62 if (!gc)
63 return -ENOMEM;
64
65 regs = of_iomap(pdev->dev.of_node, 0);
66 if (!regs)
67 return -ENOMEM;
68
69 ret = bgpio_init(gc, &pdev->dev, 4, regs + GEF_GPIO_IN,
70 regs + GEF_GPIO_OUT, NULL, NULL,
71 regs + GEF_GPIO_DIRECT, BGPIOF_BIG_ENDIAN_BYTE_ORDER);
72 if (ret) {
73 dev_err(&pdev->dev, "bgpio_init failed\n");
74 goto err0;
75 }
76
77 /* Setup pointers to chip functions */
78 gc->label = devm_kasprintf(&pdev->dev, GFP_KERNEL, "%pOF", pdev->dev.of_node);
79 if (!gc->label) {
80 ret = -ENOMEM;
81 goto err0;
82 }
83
84 gc->base = -1;
85 gc->ngpio = (u16)(uintptr_t)of_id->data;
86 gc->of_gpio_n_cells = 2;
87 gc->of_node = pdev->dev.of_node;
88
89 /* This function adds a memory mapped GPIO chip */
90 ret = devm_gpiochip_add_data(&pdev->dev, gc, NULL);
91 if (ret)
92 goto err0;
93
94 return 0;
95err0:
96 iounmap(regs);
97 pr_err("%pOF: GPIO chip registration failed\n", pdev->dev.of_node);
98 return ret;
99};
100
101static struct platform_driver gef_gpio_driver = {
102 .driver = {
103 .name = "gef-gpio",
104 .of_match_table = gef_gpio_ids,
105 },
106};
107module_platform_driver_probe(gef_gpio_driver, gef_gpio_probe);
108
109MODULE_DESCRIPTION("GE I/O FPGA GPIO driver");
110MODULE_AUTHOR("Martyn Welch <martyn.welch@ge.com");
111MODULE_LICENSE("GPL");