2 * MOXA ART SoCs GPIO driver.
4 * Copyright (C) 2013 Jonas Jensen
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.
13 #include <linux/err.h>
14 #include <linux/init.h>
15 #include <linux/irq.h>
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>
25 #include <linux/gpio/driver.h>
27 #define GPIO_DATA_OUT 0x00
28 #define GPIO_DATA_IN 0x04
29 #define GPIO_PIN_DIRECTION 0x08
31 static int moxart_gpio_probe(struct platform_device *pdev)
33 struct device *dev = &pdev->dev;
39 gc = devm_kzalloc(dev, sizeof(*gc), GFP_KERNEL);
43 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
44 base = devm_ioremap_resource(dev, res);
48 ret = bgpio_init(gc, dev, 4, base + GPIO_DATA_IN,
49 base + GPIO_DATA_OUT, NULL,
50 base + GPIO_PIN_DIRECTION, NULL,
51 BGPIOF_READ_OUTPUT_REG_SET);
53 dev_err(&pdev->dev, "bgpio_init failed\n");
57 gc->label = "moxart-gpio";
58 gc->request = gpiochip_generic_request;
59 gc->free = gpiochip_generic_free;
60 gc->bgpio_data = gc->read_reg(gc->reg_set);
64 gc->owner = THIS_MODULE;
66 ret = gpiochip_add_data(gc, NULL);
68 dev_err(dev, "%s: gpiochip_add failed\n",
69 dev->of_node->full_name);
76 static const struct of_device_id moxart_gpio_match[] = {
77 { .compatible = "moxa,moxart-gpio" },
81 static struct platform_driver moxart_gpio_driver = {
83 .name = "moxart-gpio",
84 .of_match_table = moxart_gpio_match,
86 .probe = moxart_gpio_probe,
88 module_platform_driver(moxart_gpio_driver);
90 MODULE_DESCRIPTION("MOXART GPIO chip driver");
91 MODULE_LICENSE("GPL");