Martyn Welch | 965dc5f | 2008-11-07 14:15:42 +0000 | [diff] [blame] | 1 | /* |
Martyn Welch | 948e78c | 2010-03-01 14:41:59 +0000 | [diff] [blame] | 2 | * Driver for GE FPGA based GPIO |
Martyn Welch | 965dc5f | 2008-11-07 14:15:42 +0000 | [diff] [blame] | 3 | * |
Martyn Welch | 948e78c | 2010-03-01 14:41:59 +0000 | [diff] [blame] | 4 | * Author: Martyn Welch <martyn.welch@ge.com> |
Martyn Welch | 965dc5f | 2008-11-07 14:15:42 +0000 | [diff] [blame] | 5 | * |
Martyn Welch | 948e78c | 2010-03-01 14:41:59 +0000 | [diff] [blame] | 6 | * 2008 (c) GE Intelligent Platforms Embedded Systems, Inc. |
Martyn Welch | 965dc5f | 2008-11-07 14:15:42 +0000 | [diff] [blame] | 7 | * |
| 8 | * This file is licensed under the terms of the GNU General Public License |
| 9 | * version 2. This program is licensed "as is" without any warranty of any |
| 10 | * kind, whether express or implied. |
| 11 | */ |
| 12 | |
| 13 | /* TODO |
| 14 | * |
| 15 | * Configuration of output modes (totem-pole/open-drain) |
| 16 | * Interrupt configuration - interrupts are always generated the FPGA relies on |
Martyn Welch | 6518bb6 | 2012-03-12 17:12:58 +0000 | [diff] [blame] | 17 | * the I/O interrupt controllers mask to stop them propergating |
Martyn Welch | 965dc5f | 2008-11-07 14:15:42 +0000 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | #include <linux/kernel.h> |
Martyn Welch | 965dc5f | 2008-11-07 14:15:42 +0000 | [diff] [blame] | 21 | #include <linux/io.h> |
Kamlakant Patel | a0b66e3 | 2015-01-19 10:52:06 +0530 | [diff] [blame] | 22 | #include <linux/slab.h> |
Martyn Welch | 965dc5f | 2008-11-07 14:15:42 +0000 | [diff] [blame] | 23 | #include <linux/of_device.h> |
Martyn Welch | 965dc5f | 2008-11-07 14:15:42 +0000 | [diff] [blame] | 24 | #include <linux/of_gpio.h> |
Kamlakant Patel | 866010f | 2014-12-01 17:39:37 +0530 | [diff] [blame] | 25 | #include <linux/of_address.h> |
Paul Gortmaker | 7dfe293 | 2011-05-27 13:23:32 -0400 | [diff] [blame] | 26 | #include <linux/module.h> |
Linus Walleij | 0f4630f | 2015-12-04 14:02:58 +0100 | [diff] [blame] | 27 | #include <linux/gpio/driver.h> |
Martyn Welch | 965dc5f | 2008-11-07 14:15:42 +0000 | [diff] [blame] | 28 | |
| 29 | #define GEF_GPIO_DIRECT 0x00 |
| 30 | #define GEF_GPIO_IN 0x04 |
| 31 | #define GEF_GPIO_OUT 0x08 |
| 32 | #define GEF_GPIO_TRIG 0x0C |
| 33 | #define GEF_GPIO_POLAR_A 0x10 |
| 34 | #define GEF_GPIO_POLAR_B 0x14 |
| 35 | #define GEF_GPIO_INT_STAT 0x18 |
| 36 | #define GEF_GPIO_OVERRUN 0x1C |
| 37 | #define GEF_GPIO_MODE 0x20 |
| 38 | |
Alexander Shiyan | 9dacc6d | 2014-04-12 09:41:31 +0400 | [diff] [blame] | 39 | static const struct of_device_id gef_gpio_ids[] = { |
| 40 | { |
| 41 | .compatible = "gef,sbc610-gpio", |
| 42 | .data = (void *)19, |
| 43 | }, { |
| 44 | .compatible = "gef,sbc310-gpio", |
| 45 | .data = (void *)6, |
| 46 | }, { |
| 47 | .compatible = "ge,imp3a-gpio", |
| 48 | .data = (void *)16, |
| 49 | }, |
| 50 | { } |
Martyn Welch | 965dc5f | 2008-11-07 14:15:42 +0000 | [diff] [blame] | 51 | }; |
Alexander Shiyan | 9dacc6d | 2014-04-12 09:41:31 +0400 | [diff] [blame] | 52 | MODULE_DEVICE_TABLE(of, gef_gpio_ids); |
| 53 | |
| 54 | static int __init gef_gpio_probe(struct platform_device *pdev) |
| 55 | { |
| 56 | const struct of_device_id *of_id = |
| 57 | of_match_device(gef_gpio_ids, &pdev->dev); |
Linus Walleij | 0f4630f | 2015-12-04 14:02:58 +0100 | [diff] [blame] | 58 | struct gpio_chip *gc; |
Kamlakant Patel | 866010f | 2014-12-01 17:39:37 +0530 | [diff] [blame] | 59 | void __iomem *regs; |
| 60 | int ret; |
Alexander Shiyan | 9dacc6d | 2014-04-12 09:41:31 +0400 | [diff] [blame] | 61 | |
Linus Walleij | 0f4630f | 2015-12-04 14:02:58 +0100 | [diff] [blame] | 62 | gc = devm_kzalloc(&pdev->dev, sizeof(*gc), GFP_KERNEL); |
| 63 | if (!gc) |
Alexander Shiyan | 9dacc6d | 2014-04-12 09:41:31 +0400 | [diff] [blame] | 64 | return -ENOMEM; |
| 65 | |
Kamlakant Patel | 866010f | 2014-12-01 17:39:37 +0530 | [diff] [blame] | 66 | regs = of_iomap(pdev->dev.of_node, 0); |
| 67 | if (!regs) |
| 68 | return -ENOMEM; |
| 69 | |
Linus Walleij | 0f4630f | 2015-12-04 14:02:58 +0100 | [diff] [blame] | 70 | ret = bgpio_init(gc, &pdev->dev, 4, regs + GEF_GPIO_IN, |
Kamlakant Patel | 866010f | 2014-12-01 17:39:37 +0530 | [diff] [blame] | 71 | regs + GEF_GPIO_OUT, NULL, NULL, |
| 72 | regs + GEF_GPIO_DIRECT, BGPIOF_BIG_ENDIAN_BYTE_ORDER); |
| 73 | if (ret) { |
| 74 | dev_err(&pdev->dev, "bgpio_init failed\n"); |
| 75 | goto err0; |
| 76 | } |
| 77 | |
Alexander Shiyan | 9dacc6d | 2014-04-12 09:41:31 +0400 | [diff] [blame] | 78 | /* Setup pointers to chip functions */ |
Linus Walleij | 0f4630f | 2015-12-04 14:02:58 +0100 | [diff] [blame] | 79 | gc->label = devm_kstrdup(&pdev->dev, pdev->dev.of_node->full_name, |
Axel Lin | 74b18de | 2015-01-21 09:50:06 +0800 | [diff] [blame] | 80 | GFP_KERNEL); |
Linus Walleij | 0f4630f | 2015-12-04 14:02:58 +0100 | [diff] [blame] | 81 | if (!gc->label) { |
Axel Lin | 74b18de | 2015-01-21 09:50:06 +0800 | [diff] [blame] | 82 | ret = -ENOMEM; |
Kamlakant Patel | 866010f | 2014-12-01 17:39:37 +0530 | [diff] [blame] | 83 | goto err0; |
Axel Lin | 74b18de | 2015-01-21 09:50:06 +0800 | [diff] [blame] | 84 | } |
Kamlakant Patel | 866010f | 2014-12-01 17:39:37 +0530 | [diff] [blame] | 85 | |
Linus Walleij | 0f4630f | 2015-12-04 14:02:58 +0100 | [diff] [blame] | 86 | gc->base = -1; |
| 87 | gc->ngpio = (u16)(uintptr_t)of_id->data; |
| 88 | gc->of_gpio_n_cells = 2; |
| 89 | gc->of_node = pdev->dev.of_node; |
Alexander Shiyan | 9dacc6d | 2014-04-12 09:41:31 +0400 | [diff] [blame] | 90 | |
| 91 | /* This function adds a memory mapped GPIO chip */ |
Laxman Dewangan | ad2261c | 2016-02-22 17:43:28 +0530 | [diff] [blame] | 92 | ret = devm_gpiochip_add_data(&pdev->dev, gc, NULL); |
Kamlakant Patel | 866010f | 2014-12-01 17:39:37 +0530 | [diff] [blame] | 93 | if (ret) |
Axel Lin | 74b18de | 2015-01-21 09:50:06 +0800 | [diff] [blame] | 94 | goto err0; |
Kamlakant Patel | 866010f | 2014-12-01 17:39:37 +0530 | [diff] [blame] | 95 | |
| 96 | return 0; |
Kamlakant Patel | 866010f | 2014-12-01 17:39:37 +0530 | [diff] [blame] | 97 | err0: |
| 98 | iounmap(regs); |
| 99 | pr_err("%s: GPIO chip registration failed\n", |
| 100 | pdev->dev.of_node->full_name); |
| 101 | return ret; |
Alexander Shiyan | 9dacc6d | 2014-04-12 09:41:31 +0400 | [diff] [blame] | 102 | }; |
| 103 | |
| 104 | static struct platform_driver gef_gpio_driver = { |
| 105 | .driver = { |
| 106 | .name = "gef-gpio", |
Alexander Shiyan | 9dacc6d | 2014-04-12 09:41:31 +0400 | [diff] [blame] | 107 | .of_match_table = gef_gpio_ids, |
| 108 | }, |
| 109 | }; |
| 110 | module_platform_driver_probe(gef_gpio_driver, gef_gpio_probe); |
Martyn Welch | 965dc5f | 2008-11-07 14:15:42 +0000 | [diff] [blame] | 111 | |
Martyn Welch | 948e78c | 2010-03-01 14:41:59 +0000 | [diff] [blame] | 112 | MODULE_DESCRIPTION("GE I/O FPGA GPIO driver"); |
| 113 | MODULE_AUTHOR("Martyn Welch <martyn.welch@ge.com"); |
Martyn Welch | 965dc5f | 2008-11-07 14:15:42 +0000 | [diff] [blame] | 114 | MODULE_LICENSE("GPL"); |