blob: 8650b2916f874c8b1285e3f8fee4ae62ce954631 [file] [log] [blame]
Martyn Welch965dc5f2008-11-07 14:15:42 +00001/*
Martyn Welch948e78c2010-03-01 14:41:59 +00002 * Driver for GE FPGA based GPIO
Martyn Welch965dc5f2008-11-07 14:15:42 +00003 *
Martyn Welch948e78c2010-03-01 14:41:59 +00004 * Author: Martyn Welch <martyn.welch@ge.com>
Martyn Welch965dc5f2008-11-07 14:15:42 +00005 *
Martyn Welch948e78c2010-03-01 14:41:59 +00006 * 2008 (c) GE Intelligent Platforms Embedded Systems, Inc.
Martyn Welch965dc5f2008-11-07 14:15:42 +00007 *
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
Martyn Welch6518bb62012-03-12 17:12:58 +000017 * the I/O interrupt controllers mask to stop them propergating
Martyn Welch965dc5f2008-11-07 14:15:42 +000018 */
19
20#include <linux/kernel.h>
Martyn Welch965dc5f2008-11-07 14:15:42 +000021#include <linux/io.h>
Kamlakant Patela0b66e32015-01-19 10:52:06 +053022#include <linux/slab.h>
Martyn Welch965dc5f2008-11-07 14:15:42 +000023#include <linux/of_device.h>
Martyn Welch965dc5f2008-11-07 14:15:42 +000024#include <linux/of_gpio.h>
Kamlakant Patel866010f2014-12-01 17:39:37 +053025#include <linux/of_address.h>
Paul Gortmaker7dfe2932011-05-27 13:23:32 -040026#include <linux/module.h>
Linus Walleij0f4630f2015-12-04 14:02:58 +010027#include <linux/gpio/driver.h>
Martyn Welch965dc5f2008-11-07 14:15:42 +000028
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
Alexander Shiyan9dacc6d2014-04-12 09:41:31 +040039static 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 { }
Martyn Welch965dc5f2008-11-07 14:15:42 +000051};
Alexander Shiyan9dacc6d2014-04-12 09:41:31 +040052MODULE_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);
Linus Walleij0f4630f2015-12-04 14:02:58 +010058 struct gpio_chip *gc;
Kamlakant Patel866010f2014-12-01 17:39:37 +053059 void __iomem *regs;
60 int ret;
Alexander Shiyan9dacc6d2014-04-12 09:41:31 +040061
Linus Walleij0f4630f2015-12-04 14:02:58 +010062 gc = devm_kzalloc(&pdev->dev, sizeof(*gc), GFP_KERNEL);
63 if (!gc)
Alexander Shiyan9dacc6d2014-04-12 09:41:31 +040064 return -ENOMEM;
65
Kamlakant Patel866010f2014-12-01 17:39:37 +053066 regs = of_iomap(pdev->dev.of_node, 0);
67 if (!regs)
68 return -ENOMEM;
69
Linus Walleij0f4630f2015-12-04 14:02:58 +010070 ret = bgpio_init(gc, &pdev->dev, 4, regs + GEF_GPIO_IN,
Kamlakant Patel866010f2014-12-01 17:39:37 +053071 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
Alexander Shiyan9dacc6d2014-04-12 09:41:31 +040078 /* Setup pointers to chip functions */
Linus Walleij0f4630f2015-12-04 14:02:58 +010079 gc->label = devm_kstrdup(&pdev->dev, pdev->dev.of_node->full_name,
Axel Lin74b18de2015-01-21 09:50:06 +080080 GFP_KERNEL);
Linus Walleij0f4630f2015-12-04 14:02:58 +010081 if (!gc->label) {
Axel Lin74b18de2015-01-21 09:50:06 +080082 ret = -ENOMEM;
Kamlakant Patel866010f2014-12-01 17:39:37 +053083 goto err0;
Axel Lin74b18de2015-01-21 09:50:06 +080084 }
Kamlakant Patel866010f2014-12-01 17:39:37 +053085
Linus Walleij0f4630f2015-12-04 14:02:58 +010086 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;
Alexander Shiyan9dacc6d2014-04-12 09:41:31 +040090
91 /* This function adds a memory mapped GPIO chip */
Laxman Dewanganad2261c2016-02-22 17:43:28 +053092 ret = devm_gpiochip_add_data(&pdev->dev, gc, NULL);
Kamlakant Patel866010f2014-12-01 17:39:37 +053093 if (ret)
Axel Lin74b18de2015-01-21 09:50:06 +080094 goto err0;
Kamlakant Patel866010f2014-12-01 17:39:37 +053095
96 return 0;
Kamlakant Patel866010f2014-12-01 17:39:37 +053097err0:
98 iounmap(regs);
99 pr_err("%s: GPIO chip registration failed\n",
100 pdev->dev.of_node->full_name);
101 return ret;
Alexander Shiyan9dacc6d2014-04-12 09:41:31 +0400102};
103
104static struct platform_driver gef_gpio_driver = {
105 .driver = {
106 .name = "gef-gpio",
Alexander Shiyan9dacc6d2014-04-12 09:41:31 +0400107 .of_match_table = gef_gpio_ids,
108 },
109};
110module_platform_driver_probe(gef_gpio_driver, gef_gpio_probe);
Martyn Welch965dc5f2008-11-07 14:15:42 +0000111
Martyn Welch948e78c2010-03-01 14:41:59 +0000112MODULE_DESCRIPTION("GE I/O FPGA GPIO driver");
113MODULE_AUTHOR("Martyn Welch <martyn.welch@ge.com");
Martyn Welch965dc5f2008-11-07 14:15:42 +0000114MODULE_LICENSE("GPL");