Loading...
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_gpio.h>
25#include <linux/of_address.h>
26#include <linux/module.h>
27#include <linux/gpio/driver.h>
28
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
38
39static const struct of_device_id gef_gpio_ids[] = {
40 {
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,
49 },
50 { }
51};
52MODULE_DEVICE_TABLE(of, gef_gpio_ids);
53
54static int __init gef_gpio_probe(struct platform_device *pdev)
55{
56 const struct of_device_id *of_id =
57 of_match_device(gef_gpio_ids, &pdev->dev);
58 struct gpio_chip *gc;
59 void __iomem *regs;
60 int ret;
61
62 gc = devm_kzalloc(&pdev->dev, sizeof(*gc), GFP_KERNEL);
63 if (!gc)
64 return -ENOMEM;
65
66 regs = of_iomap(pdev->dev.of_node, 0);
67 if (!regs)
68 return -ENOMEM;
69
70 ret = bgpio_init(gc, &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;
76 }
77
78 /* Setup pointers to chip functions */
79 gc->label = devm_kstrdup(&pdev->dev, pdev->dev.of_node->full_name,
80 GFP_KERNEL);
81 if (!gc->label) {
82 ret = -ENOMEM;
83 goto err0;
84 }
85
86 gc->base = -1;
87 gc->ngpio = (u16)(uintptr_t)of_id->data;
88 gc->of_gpio_n_cells = 2;
89 gc->of_node = pdev->dev.of_node;
90
91 /* This function adds a memory mapped GPIO chip */
92 ret = devm_gpiochip_add_data(&pdev->dev, gc, NULL);
93 if (ret)
94 goto err0;
95
96 return 0;
97err0:
98 iounmap(regs);
99 pr_err("%s: GPIO chip registration failed\n",
100 pdev->dev.of_node->full_name);
101 return ret;
102};
103
104static struct platform_driver gef_gpio_driver = {
105 .driver = {
106 .name = "gef-gpio",
107 .of_match_table = gef_gpio_ids,
108 },
109};
110module_platform_driver_probe(gef_gpio_driver, gef_gpio_probe);
111
112MODULE_DESCRIPTION("GE I/O FPGA GPIO driver");
113MODULE_AUTHOR("Martyn Welch <martyn.welch@ge.com");
114MODULE_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 struct gpio_chip *gc;
56 void __iomem *regs;
57 int ret;
58
59 gc = devm_kzalloc(&pdev->dev, sizeof(*gc), GFP_KERNEL);
60 if (!gc)
61 return -ENOMEM;
62
63 regs = of_iomap(pdev->dev.of_node, 0);
64 if (!regs)
65 return -ENOMEM;
66
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);
70 if (ret) {
71 dev_err(&pdev->dev, "bgpio_init failed\n");
72 goto err0;
73 }
74
75 /* Setup pointers to chip functions */
76 gc->label = devm_kasprintf(&pdev->dev, GFP_KERNEL, "%pOF", pdev->dev.of_node);
77 if (!gc->label) {
78 ret = -ENOMEM;
79 goto err0;
80 }
81
82 gc->base = -1;
83 gc->ngpio = (u16)(uintptr_t)of_device_get_match_data(&pdev->dev);
84 gc->of_gpio_n_cells = 2;
85 gc->of_node = pdev->dev.of_node;
86
87 /* This function adds a memory mapped GPIO chip */
88 ret = devm_gpiochip_add_data(&pdev->dev, gc, NULL);
89 if (ret)
90 goto err0;
91
92 return 0;
93err0:
94 iounmap(regs);
95 pr_err("%pOF: GPIO chip registration failed\n", pdev->dev.of_node);
96 return ret;
97};
98
99static struct platform_driver gef_gpio_driver = {
100 .driver = {
101 .name = "gef-gpio",
102 .of_match_table = gef_gpio_ids,
103 },
104};
105module_platform_driver_probe(gef_gpio_driver, gef_gpio_probe);
106
107MODULE_DESCRIPTION("GE I/O FPGA GPIO driver");
108MODULE_AUTHOR("Martyn Welch <martyn.welch@ge.com");
109MODULE_LICENSE("GPL");