Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jikos/hid
[linux-2.6-block.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>
866010fb 24#include <linux/of_address.h>
7dfe293c 25#include <linux/module.h>
0f4630f3 26#include <linux/gpio/driver.h>
965dc5fc
MW
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
9dacc6de
AS
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);
965dc5fc 52
9dacc6de 53static int __init gef_gpio_probe(struct platform_device *pdev)
965dc5fc 54{
9dacc6de
AS
55 const struct of_device_id *of_id =
56 of_match_device(gef_gpio_ids, &pdev->dev);
0f4630f3 57 struct gpio_chip *gc;
866010fb
KP
58 void __iomem *regs;
59 int ret;
9dacc6de 60
0f4630f3
LW
61 gc = devm_kzalloc(&pdev->dev, sizeof(*gc), GFP_KERNEL);
62 if (!gc)
9dacc6de
AS
63 return -ENOMEM;
64
866010fb
KP
65 regs = of_iomap(pdev->dev.of_node, 0);
66 if (!regs)
67 return -ENOMEM;
68
0f4630f3 69 ret = bgpio_init(gc, &pdev->dev, 4, regs + GEF_GPIO_IN,
866010fb
KP
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
9dacc6de 77 /* Setup pointers to chip functions */
7eb6ce2f 78 gc->label = devm_kasprintf(&pdev->dev, GFP_KERNEL, "%pOF", pdev->dev.of_node);
0f4630f3 79 if (!gc->label) {
74b18de9 80 ret = -ENOMEM;
866010fb 81 goto err0;
74b18de9 82 }
866010fb 83
0f4630f3
LW
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;
9dacc6de
AS
88
89 /* This function adds a memory mapped GPIO chip */
ad2261ca 90 ret = devm_gpiochip_add_data(&pdev->dev, gc, NULL);
866010fb 91 if (ret)
74b18de9 92 goto err0;
866010fb
KP
93
94 return 0;
866010fb
KP
95err0:
96 iounmap(regs);
7eb6ce2f 97 pr_err("%pOF: GPIO chip registration failed\n", pdev->dev.of_node);
866010fb 98 return ret;
9dacc6de 99};
e041013a 100
9dacc6de
AS
101static struct platform_driver gef_gpio_driver = {
102 .driver = {
103 .name = "gef-gpio",
9dacc6de
AS
104 .of_match_table = gef_gpio_ids,
105 },
965dc5fc 106};
9dacc6de 107module_platform_driver_probe(gef_gpio_driver, gef_gpio_probe);
965dc5fc 108
948e78c3
MW
109MODULE_DESCRIPTION("GE I/O FPGA GPIO driver");
110MODULE_AUTHOR("Martyn Welch <martyn.welch@ge.com");
965dc5fc 111MODULE_LICENSE("GPL");