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> |
| 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> |
Kamlakant Patel | 3c01b9a | 2014-12-01 17:39:34 +0530 | [diff] [blame] | 26 | #include <linux/basic_mmio_gpio.h> |
Jonas Jensen | 0299b77 | 2013-11-29 12:11:34 +0100 | [diff] [blame] | 27 | |
| 28 | #define GPIO_DATA_OUT 0x00 |
| 29 | #define GPIO_DATA_IN 0x04 |
| 30 | #define GPIO_PIN_DIRECTION 0x08 |
| 31 | |
Jonas Jensen | 0299b77 | 2013-11-29 12:11:34 +0100 | [diff] [blame] | 32 | static int moxart_gpio_probe(struct platform_device *pdev) |
| 33 | { |
| 34 | struct device *dev = &pdev->dev; |
| 35 | struct resource *res; |
Kamlakant Patel | 3c01b9a | 2014-12-01 17:39:34 +0530 | [diff] [blame] | 36 | struct bgpio_chip *bgc; |
| 37 | void __iomem *base; |
Jonas Jensen | 0299b77 | 2013-11-29 12:11:34 +0100 | [diff] [blame] | 38 | int ret; |
| 39 | |
Kamlakant Patel | 3c01b9a | 2014-12-01 17:39:34 +0530 | [diff] [blame] | 40 | bgc = devm_kzalloc(dev, sizeof(*bgc), GFP_KERNEL); |
| 41 | if (!bgc) |
Jonas Jensen | 0299b77 | 2013-11-29 12:11:34 +0100 | [diff] [blame] | 42 | return -ENOMEM; |
Jonas Jensen | 0299b77 | 2013-11-29 12:11:34 +0100 | [diff] [blame] | 43 | |
| 44 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Kamlakant Patel | 3c01b9a | 2014-12-01 17:39:34 +0530 | [diff] [blame] | 45 | base = devm_ioremap_resource(dev, res); |
| 46 | if (IS_ERR(base)) |
| 47 | return PTR_ERR(base); |
Jonas Jensen | 0299b77 | 2013-11-29 12:11:34 +0100 | [diff] [blame] | 48 | |
Kamlakant Patel | 3c01b9a | 2014-12-01 17:39:34 +0530 | [diff] [blame] | 49 | ret = bgpio_init(bgc, dev, 4, base + GPIO_DATA_IN, |
Vladimir Zapolskiy | f306633 | 2015-04-29 18:35:00 +0300 | [diff] [blame] | 50 | base + GPIO_DATA_OUT, NULL, |
| 51 | base + GPIO_PIN_DIRECTION, NULL, |
| 52 | BGPIOF_READ_OUTPUT_REG_SET); |
Kamlakant Patel | 3c01b9a | 2014-12-01 17:39:34 +0530 | [diff] [blame] | 53 | if (ret) { |
| 54 | dev_err(&pdev->dev, "bgpio_init failed\n"); |
| 55 | return ret; |
| 56 | } |
Jonas Jensen | 0299b77 | 2013-11-29 12:11:34 +0100 | [diff] [blame] | 57 | |
Kamlakant Patel | 3c01b9a | 2014-12-01 17:39:34 +0530 | [diff] [blame] | 58 | bgc->gc.label = "moxart-gpio"; |
Jonas Gorski | 203f0da | 2015-10-11 17:34:16 +0200 | [diff] [blame] | 59 | bgc->gc.request = gpiochip_generic_request; |
| 60 | bgc->gc.free = gpiochip_generic_free; |
Kamlakant Patel | 3c01b9a | 2014-12-01 17:39:34 +0530 | [diff] [blame] | 61 | bgc->data = bgc->read_reg(bgc->reg_set); |
| 62 | bgc->gc.base = 0; |
| 63 | bgc->gc.ngpio = 32; |
| 64 | bgc->gc.dev = dev; |
| 65 | bgc->gc.owner = THIS_MODULE; |
| 66 | |
| 67 | ret = gpiochip_add(&bgc->gc); |
Jonas Jensen | 0299b77 | 2013-11-29 12:11:34 +0100 | [diff] [blame] | 68 | if (ret) { |
| 69 | dev_err(dev, "%s: gpiochip_add failed\n", |
| 70 | dev->of_node->full_name); |
| 71 | return ret; |
| 72 | } |
| 73 | |
Kamlakant Patel | 3c01b9a | 2014-12-01 17:39:34 +0530 | [diff] [blame] | 74 | return ret; |
Jonas Jensen | 0299b77 | 2013-11-29 12:11:34 +0100 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | static const struct of_device_id moxart_gpio_match[] = { |
| 78 | { .compatible = "moxa,moxart-gpio" }, |
| 79 | { } |
| 80 | }; |
| 81 | |
| 82 | static struct platform_driver moxart_gpio_driver = { |
| 83 | .driver = { |
| 84 | .name = "moxart-gpio", |
Jonas Jensen | 0299b77 | 2013-11-29 12:11:34 +0100 | [diff] [blame] | 85 | .of_match_table = moxart_gpio_match, |
| 86 | }, |
| 87 | .probe = moxart_gpio_probe, |
| 88 | }; |
| 89 | module_platform_driver(moxart_gpio_driver); |
| 90 | |
| 91 | MODULE_DESCRIPTION("MOXART GPIO chip driver"); |
| 92 | MODULE_LICENSE("GPL"); |
| 93 | MODULE_AUTHOR("Jonas Jensen <jonas.jensen@gmail.com>"); |