]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/gpio/gpio-moxart.c
Merge branch 'next' into for-linus
[karo-tx-linux.git] / drivers / gpio / gpio-moxart.c
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>
17 #include <linux/gpio.h>
18 #include <linux/platform_device.h>
19 #include <linux/module.h>
20 #include <linux/of_address.h>
21 #include <linux/of_gpio.h>
22 #include <linux/pinctrl/consumer.h>
23 #include <linux/delay.h>
24 #include <linux/timer.h>
25 #include <linux/bitops.h>
26 #include <linux/basic_mmio_gpio.h>
27
28 #define GPIO_DATA_OUT           0x00
29 #define GPIO_DATA_IN            0x04
30 #define GPIO_PIN_DIRECTION      0x08
31
32 static int moxart_gpio_request(struct gpio_chip *chip, unsigned offset)
33 {
34         return pinctrl_request_gpio(offset);
35 }
36
37 static void moxart_gpio_free(struct gpio_chip *chip, unsigned offset)
38 {
39         pinctrl_free_gpio(offset);
40 }
41
42 static int moxart_gpio_probe(struct platform_device *pdev)
43 {
44         struct device *dev = &pdev->dev;
45         struct resource *res;
46         struct bgpio_chip *bgc;
47         void __iomem *base;
48         int ret;
49
50         bgc = devm_kzalloc(dev, sizeof(*bgc), GFP_KERNEL);
51         if (!bgc)
52                 return -ENOMEM;
53
54         res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
55         base = devm_ioremap_resource(dev, res);
56         if (IS_ERR(base))
57                 return PTR_ERR(base);
58
59         ret = bgpio_init(bgc, dev, 4, base + GPIO_DATA_IN,
60                          base + GPIO_DATA_OUT, NULL,
61                          base + GPIO_PIN_DIRECTION, NULL,
62                          BGPIOF_READ_OUTPUT_REG_SET);
63         if (ret) {
64                 dev_err(&pdev->dev, "bgpio_init failed\n");
65                 return ret;
66         }
67
68         bgc->gc.label = "moxart-gpio";
69         bgc->gc.request = moxart_gpio_request;
70         bgc->gc.free = moxart_gpio_free;
71         bgc->data = bgc->read_reg(bgc->reg_set);
72         bgc->gc.base = 0;
73         bgc->gc.ngpio = 32;
74         bgc->gc.dev = dev;
75         bgc->gc.owner = THIS_MODULE;
76
77         ret = gpiochip_add(&bgc->gc);
78         if (ret) {
79                 dev_err(dev, "%s: gpiochip_add failed\n",
80                         dev->of_node->full_name);
81                 return ret;
82         }
83
84         return ret;
85 }
86
87 static const struct of_device_id moxart_gpio_match[] = {
88         { .compatible = "moxa,moxart-gpio" },
89         { }
90 };
91
92 static struct platform_driver moxart_gpio_driver = {
93         .driver = {
94                 .name           = "moxart-gpio",
95                 .of_match_table = moxart_gpio_match,
96         },
97         .probe  = moxart_gpio_probe,
98 };
99 module_platform_driver(moxart_gpio_driver);
100
101 MODULE_DESCRIPTION("MOXART GPIO chip driver");
102 MODULE_LICENSE("GPL");
103 MODULE_AUTHOR("Jonas Jensen <jonas.jensen@gmail.com>");