Merge tag 'pm+acpi-4.6-rc1-3' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael...
[linux-2.6-block.git] / drivers / gpio / gpio-moxart.c
CommitLineData
0299b77b
JJ
1/*
2 * MOXA ART SoCs GPIO driver.
3 *
4 * Copyright (C) 2013 Jonas Jensen
5 *
6 * Jonas Jensen <jonas.jensen@gmail.com>
7 *
8 * This file is licensed under the terms of the GNU General Public
9 * License version 2. This program is licensed "as is" without any
10 * warranty of any kind, whether express or implied.
11 */
12
13#include <linux/err.h>
14#include <linux/init.h>
15#include <linux/irq.h>
16#include <linux/io.h>
0299b77b
JJ
17#include <linux/platform_device.h>
18#include <linux/module.h>
19#include <linux/of_address.h>
20#include <linux/of_gpio.h>
21#include <linux/pinctrl/consumer.h>
22#include <linux/delay.h>
23#include <linux/timer.h>
24#include <linux/bitops.h>
0f4630f3 25#include <linux/gpio/driver.h>
0299b77b
JJ
26
27#define GPIO_DATA_OUT 0x00
28#define GPIO_DATA_IN 0x04
29#define GPIO_PIN_DIRECTION 0x08
30
0299b77b
JJ
31static int moxart_gpio_probe(struct platform_device *pdev)
32{
33 struct device *dev = &pdev->dev;
34 struct resource *res;
0f4630f3 35 struct gpio_chip *gc;
3c01b9a8 36 void __iomem *base;
0299b77b
JJ
37 int ret;
38
0f4630f3
LW
39 gc = devm_kzalloc(dev, sizeof(*gc), GFP_KERNEL);
40 if (!gc)
0299b77b 41 return -ENOMEM;
0299b77b
JJ
42
43 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
3c01b9a8
KP
44 base = devm_ioremap_resource(dev, res);
45 if (IS_ERR(base))
46 return PTR_ERR(base);
0299b77b 47
0f4630f3 48 ret = bgpio_init(gc, dev, 4, base + GPIO_DATA_IN,
f3066339
VZ
49 base + GPIO_DATA_OUT, NULL,
50 base + GPIO_PIN_DIRECTION, NULL,
51 BGPIOF_READ_OUTPUT_REG_SET);
3c01b9a8
KP
52 if (ret) {
53 dev_err(&pdev->dev, "bgpio_init failed\n");
54 return ret;
55 }
0299b77b 56
0f4630f3
LW
57 gc->label = "moxart-gpio";
58 gc->request = gpiochip_generic_request;
59 gc->free = gpiochip_generic_free;
0f4630f3 60 gc->base = 0;
0f4630f3 61 gc->owner = THIS_MODULE;
3c01b9a8 62
33bde5c5 63 ret = devm_gpiochip_add_data(dev, gc, NULL);
0299b77b
JJ
64 if (ret) {
65 dev_err(dev, "%s: gpiochip_add failed\n",
66 dev->of_node->full_name);
67 return ret;
68 }
69
3c01b9a8 70 return ret;
0299b77b
JJ
71}
72
73static const struct of_device_id moxart_gpio_match[] = {
74 { .compatible = "moxa,moxart-gpio" },
75 { }
76};
77
78static struct platform_driver moxart_gpio_driver = {
79 .driver = {
80 .name = "moxart-gpio",
0299b77b
JJ
81 .of_match_table = moxart_gpio_match,
82 },
83 .probe = moxart_gpio_probe,
84};
85module_platform_driver(moxart_gpio_driver);
86
87MODULE_DESCRIPTION("MOXART GPIO chip driver");
88MODULE_LICENSE("GPL");
89MODULE_AUTHOR("Jonas Jensen <jonas.jensen@gmail.com>");