blob: 636952769bc82bd251c31d51ea38821deed49b7a [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>
Kamlakant Patel866010f2014-12-01 17:39:37 +053024#include <linux/of_address.h>
Paul Gortmaker7dfe2932011-05-27 13:23:32 -040025#include <linux/module.h>
Linus Walleij0f4630f2015-12-04 14:02:58 +010026#include <linux/gpio/driver.h>
Martyn Welch965dc5f2008-11-07 14:15:42 +000027
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
Alexander Shiyan9dacc6d2014-04-12 09:41:31 +040038static 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 { }
Martyn Welch965dc5f2008-11-07 14:15:42 +000050};
Alexander Shiyan9dacc6d2014-04-12 09:41:31 +040051MODULE_DEVICE_TABLE(of, gef_gpio_ids);
52
53static int __init gef_gpio_probe(struct platform_device *pdev)
54{
Linus Walleij0f4630f2015-12-04 14:02:58 +010055 struct gpio_chip *gc;
Kamlakant Patel866010f2014-12-01 17:39:37 +053056 void __iomem *regs;
57 int ret;
Alexander Shiyan9dacc6d2014-04-12 09:41:31 +040058
Linus Walleij0f4630f2015-12-04 14:02:58 +010059 gc = devm_kzalloc(&pdev->dev, sizeof(*gc), GFP_KERNEL);
60 if (!gc)
Alexander Shiyan9dacc6d2014-04-12 09:41:31 +040061 return -ENOMEM;
62
Kamlakant Patel866010f2014-12-01 17:39:37 +053063 regs = of_iomap(pdev->dev.of_node, 0);
64 if (!regs)
65 return -ENOMEM;
66
Linus Walleij0f4630f2015-12-04 14:02:58 +010067 ret = bgpio_init(gc, &pdev->dev, 4, regs + GEF_GPIO_IN,
Kamlakant Patel866010f2014-12-01 17:39:37 +053068 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
Alexander Shiyan9dacc6d2014-04-12 09:41:31 +040075 /* Setup pointers to chip functions */
Rob Herring7eb6ce22017-07-18 16:43:03 -050076 gc->label = devm_kasprintf(&pdev->dev, GFP_KERNEL, "%pOF", pdev->dev.of_node);
Linus Walleij0f4630f2015-12-04 14:02:58 +010077 if (!gc->label) {
Axel Lin74b18de2015-01-21 09:50:06 +080078 ret = -ENOMEM;
Kamlakant Patel866010f2014-12-01 17:39:37 +053079 goto err0;
Axel Lin74b18de2015-01-21 09:50:06 +080080 }
Kamlakant Patel866010f2014-12-01 17:39:37 +053081
Linus Walleij0f4630f2015-12-04 14:02:58 +010082 gc->base = -1;
Thierry Reding668f0652018-05-03 14:46:24 +020083 gc->ngpio = (u16)(uintptr_t)of_device_get_match_data(&pdev->dev);
Linus Walleij0f4630f2015-12-04 14:02:58 +010084 gc->of_gpio_n_cells = 2;
85 gc->of_node = pdev->dev.of_node;
Alexander Shiyan9dacc6d2014-04-12 09:41:31 +040086
87 /* This function adds a memory mapped GPIO chip */
Laxman Dewanganad2261c2016-02-22 17:43:28 +053088 ret = devm_gpiochip_add_data(&pdev->dev, gc, NULL);
Kamlakant Patel866010f2014-12-01 17:39:37 +053089 if (ret)
Axel Lin74b18de2015-01-21 09:50:06 +080090 goto err0;
Kamlakant Patel866010f2014-12-01 17:39:37 +053091
92 return 0;
Kamlakant Patel866010f2014-12-01 17:39:37 +053093err0:
94 iounmap(regs);
Rob Herring7eb6ce22017-07-18 16:43:03 -050095 pr_err("%pOF: GPIO chip registration failed\n", pdev->dev.of_node);
Kamlakant Patel866010f2014-12-01 17:39:37 +053096 return ret;
Alexander Shiyan9dacc6d2014-04-12 09:41:31 +040097};
98
99static struct platform_driver gef_gpio_driver = {
100 .driver = {
101 .name = "gef-gpio",
Alexander Shiyan9dacc6d2014-04-12 09:41:31 +0400102 .of_match_table = gef_gpio_ids,
103 },
104};
105module_platform_driver_probe(gef_gpio_driver, gef_gpio_probe);
Martyn Welch965dc5f2008-11-07 14:15:42 +0000106
Martyn Welch948e78c2010-03-01 14:41:59 +0000107MODULE_DESCRIPTION("GE I/O FPGA GPIO driver");
108MODULE_AUTHOR("Martyn Welch <martyn.welch@ge.com");
Martyn Welch965dc5f2008-11-07 14:15:42 +0000109MODULE_LICENSE("GPL");