Jonas Jensen | 0299b77 | 2013-11-29 12:11:34 +0100 | [diff] [blame] | 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> |
Jonas Jensen | 0299b77 | 2013-11-29 12:11:34 +0100 | [diff] [blame] | 17 | #include <linux/platform_device.h> |
Jonas Jensen | 0299b77 | 2013-11-29 12:11:34 +0100 | [diff] [blame] | 18 | #include <linux/of_address.h> |
| 19 | #include <linux/of_gpio.h> |
| 20 | #include <linux/pinctrl/consumer.h> |
| 21 | #include <linux/delay.h> |
| 22 | #include <linux/timer.h> |
| 23 | #include <linux/bitops.h> |
Linus Walleij | 0f4630f | 2015-12-04 14:02:58 +0100 | [diff] [blame] | 24 | #include <linux/gpio/driver.h> |
Jonas Jensen | 0299b77 | 2013-11-29 12:11:34 +0100 | [diff] [blame] | 25 | |
| 26 | #define GPIO_DATA_OUT 0x00 |
| 27 | #define GPIO_DATA_IN 0x04 |
| 28 | #define GPIO_PIN_DIRECTION 0x08 |
| 29 | |
Jonas Jensen | 0299b77 | 2013-11-29 12:11:34 +0100 | [diff] [blame] | 30 | static int moxart_gpio_probe(struct platform_device *pdev) |
| 31 | { |
| 32 | struct device *dev = &pdev->dev; |
| 33 | struct resource *res; |
Linus Walleij | 0f4630f | 2015-12-04 14:02:58 +0100 | [diff] [blame] | 34 | struct gpio_chip *gc; |
Kamlakant Patel | 3c01b9a | 2014-12-01 17:39:34 +0530 | [diff] [blame] | 35 | void __iomem *base; |
Jonas Jensen | 0299b77 | 2013-11-29 12:11:34 +0100 | [diff] [blame] | 36 | int ret; |
| 37 | |
Linus Walleij | 0f4630f | 2015-12-04 14:02:58 +0100 | [diff] [blame] | 38 | gc = devm_kzalloc(dev, sizeof(*gc), GFP_KERNEL); |
| 39 | if (!gc) |
Jonas Jensen | 0299b77 | 2013-11-29 12:11:34 +0100 | [diff] [blame] | 40 | return -ENOMEM; |
Jonas Jensen | 0299b77 | 2013-11-29 12:11:34 +0100 | [diff] [blame] | 41 | |
| 42 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Kamlakant Patel | 3c01b9a | 2014-12-01 17:39:34 +0530 | [diff] [blame] | 43 | base = devm_ioremap_resource(dev, res); |
| 44 | if (IS_ERR(base)) |
| 45 | return PTR_ERR(base); |
Jonas Jensen | 0299b77 | 2013-11-29 12:11:34 +0100 | [diff] [blame] | 46 | |
Linus Walleij | 0f4630f | 2015-12-04 14:02:58 +0100 | [diff] [blame] | 47 | ret = bgpio_init(gc, dev, 4, base + GPIO_DATA_IN, |
Vladimir Zapolskiy | f306633 | 2015-04-29 18:35:00 +0300 | [diff] [blame] | 48 | base + GPIO_DATA_OUT, NULL, |
| 49 | base + GPIO_PIN_DIRECTION, NULL, |
| 50 | BGPIOF_READ_OUTPUT_REG_SET); |
Kamlakant Patel | 3c01b9a | 2014-12-01 17:39:34 +0530 | [diff] [blame] | 51 | if (ret) { |
| 52 | dev_err(&pdev->dev, "bgpio_init failed\n"); |
| 53 | return ret; |
| 54 | } |
Jonas Jensen | 0299b77 | 2013-11-29 12:11:34 +0100 | [diff] [blame] | 55 | |
Linus Walleij | 0f4630f | 2015-12-04 14:02:58 +0100 | [diff] [blame] | 56 | gc->label = "moxart-gpio"; |
| 57 | gc->request = gpiochip_generic_request; |
| 58 | gc->free = gpiochip_generic_free; |
Linus Walleij | 0f4630f | 2015-12-04 14:02:58 +0100 | [diff] [blame] | 59 | gc->base = 0; |
Linus Walleij | 0f4630f | 2015-12-04 14:02:58 +0100 | [diff] [blame] | 60 | gc->owner = THIS_MODULE; |
Kamlakant Patel | 3c01b9a | 2014-12-01 17:39:34 +0530 | [diff] [blame] | 61 | |
Laxman Dewangan | 33bde5c | 2016-02-22 17:43:28 +0530 | [diff] [blame] | 62 | ret = devm_gpiochip_add_data(dev, gc, NULL); |
Jonas Jensen | 0299b77 | 2013-11-29 12:11:34 +0100 | [diff] [blame] | 63 | if (ret) { |
| 64 | dev_err(dev, "%s: gpiochip_add failed\n", |
| 65 | dev->of_node->full_name); |
| 66 | return ret; |
| 67 | } |
| 68 | |
Kamlakant Patel | 3c01b9a | 2014-12-01 17:39:34 +0530 | [diff] [blame] | 69 | return ret; |
Jonas Jensen | 0299b77 | 2013-11-29 12:11:34 +0100 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | static const struct of_device_id moxart_gpio_match[] = { |
| 73 | { .compatible = "moxa,moxart-gpio" }, |
| 74 | { } |
| 75 | }; |
| 76 | |
| 77 | static struct platform_driver moxart_gpio_driver = { |
| 78 | .driver = { |
| 79 | .name = "moxart-gpio", |
Jonas Jensen | 0299b77 | 2013-11-29 12:11:34 +0100 | [diff] [blame] | 80 | .of_match_table = moxart_gpio_match, |
| 81 | }, |
| 82 | .probe = moxart_gpio_probe, |
| 83 | }; |
Paul Gortmaker | 4bb9f72 | 2016-03-27 11:44:44 -0400 | [diff] [blame] | 84 | builtin_platform_driver(moxart_gpio_driver); |