Merge tag 'arc-4.6-rc7-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/vgupta/arc
[deliverable/linux.git] / drivers / gpio / gpio-ge.c
CommitLineData
965dc5fc 1/*
948e78c3 2 * Driver for GE FPGA based GPIO
965dc5fc 3 *
948e78c3 4 * Author: Martyn Welch <martyn.welch@ge.com>
965dc5fc 5 *
948e78c3 6 * 2008 (c) GE Intelligent Platforms Embedded Systems, Inc.
965dc5fc
MW
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
6518bb69 17 * the I/O interrupt controllers mask to stop them propergating
965dc5fc
MW
18 */
19
20#include <linux/kernel.h>
965dc5fc 21#include <linux/io.h>
a0b66e3f 22#include <linux/slab.h>
965dc5fc 23#include <linux/of_device.h>
965dc5fc 24#include <linux/of_gpio.h>
866010fb 25#include <linux/of_address.h>
7dfe293c 26#include <linux/module.h>
0f4630f3 27#include <linux/gpio/driver.h>
965dc5fc
MW
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
9dacc6de
AS
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);
965dc5fc 53
9dacc6de 54static int __init gef_gpio_probe(struct platform_device *pdev)
965dc5fc 55{
9dacc6de
AS
56 const struct of_device_id *of_id =
57 of_match_device(gef_gpio_ids, &pdev->dev);
0f4630f3 58 struct gpio_chip *gc;
866010fb
KP
59 void __iomem *regs;
60 int ret;
9dacc6de 61
0f4630f3
LW
62 gc = devm_kzalloc(&pdev->dev, sizeof(*gc), GFP_KERNEL);
63 if (!gc)
9dacc6de
AS
64 return -ENOMEM;
65
866010fb
KP
66 regs = of_iomap(pdev->dev.of_node, 0);
67 if (!regs)
68 return -ENOMEM;
69
0f4630f3 70 ret = bgpio_init(gc, &pdev->dev, 4, regs + GEF_GPIO_IN,
866010fb
KP
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
9dacc6de 78 /* Setup pointers to chip functions */
0f4630f3 79 gc->label = devm_kstrdup(&pdev->dev, pdev->dev.of_node->full_name,
74b18de9 80 GFP_KERNEL);
0f4630f3 81 if (!gc->label) {
74b18de9 82 ret = -ENOMEM;
866010fb 83 goto err0;
74b18de9 84 }
866010fb 85
0f4630f3
LW
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;
9dacc6de
AS
90
91 /* This function adds a memory mapped GPIO chip */
ad2261ca 92 ret = devm_gpiochip_add_data(&pdev->dev, gc, NULL);
866010fb 93 if (ret)
74b18de9 94 goto err0;
866010fb
KP
95
96 return 0;
866010fb
KP
97err0:
98 iounmap(regs);
99 pr_err("%s: GPIO chip registration failed\n",
100 pdev->dev.of_node->full_name);
101 return ret;
9dacc6de 102};
e041013a 103
9dacc6de
AS
104static struct platform_driver gef_gpio_driver = {
105 .driver = {
106 .name = "gef-gpio",
9dacc6de
AS
107 .of_match_table = gef_gpio_ids,
108 },
965dc5fc 109};
9dacc6de 110module_platform_driver_probe(gef_gpio_driver, gef_gpio_probe);
965dc5fc 111
948e78c3
MW
112MODULE_DESCRIPTION("GE I/O FPGA GPIO driver");
113MODULE_AUTHOR("Martyn Welch <martyn.welch@ge.com");
965dc5fc 114MODULE_LICENSE("GPL");
This page took 0.433403 seconds and 5 git commands to generate.