gpio-ge.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * Driver for GE FPGA based GPIO
  3. *
  4. * Author: Martyn Welch <martyn.welch@ge.com>
  5. *
  6. * 2008 (c) GE Intelligent Platforms Embedded Systems, Inc.
  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. /* TODO
  13. *
  14. * Configuration of output modes (totem-pole/open-drain)
  15. * Interrupt configuration - interrupts are always generated the FPGA relies on
  16. * the I/O interrupt controllers mask to stop them propergating
  17. */
  18. #include <linux/kernel.h>
  19. #include <linux/io.h>
  20. #include <linux/slab.h>
  21. #include <linux/of_device.h>
  22. #include <linux/of_gpio.h>
  23. #include <linux/of_address.h>
  24. #include <linux/module.h>
  25. #include <linux/basic_mmio_gpio.h>
  26. #define GEF_GPIO_DIRECT 0x00
  27. #define GEF_GPIO_IN 0x04
  28. #define GEF_GPIO_OUT 0x08
  29. #define GEF_GPIO_TRIG 0x0C
  30. #define GEF_GPIO_POLAR_A 0x10
  31. #define GEF_GPIO_POLAR_B 0x14
  32. #define GEF_GPIO_INT_STAT 0x18
  33. #define GEF_GPIO_OVERRUN 0x1C
  34. #define GEF_GPIO_MODE 0x20
  35. static const struct of_device_id gef_gpio_ids[] = {
  36. {
  37. .compatible = "gef,sbc610-gpio",
  38. .data = (void *)19,
  39. }, {
  40. .compatible = "gef,sbc310-gpio",
  41. .data = (void *)6,
  42. }, {
  43. .compatible = "ge,imp3a-gpio",
  44. .data = (void *)16,
  45. },
  46. { }
  47. };
  48. MODULE_DEVICE_TABLE(of, gef_gpio_ids);
  49. static int __init gef_gpio_probe(struct platform_device *pdev)
  50. {
  51. const struct of_device_id *of_id =
  52. of_match_device(gef_gpio_ids, &pdev->dev);
  53. struct bgpio_chip *bgc;
  54. void __iomem *regs;
  55. int ret;
  56. bgc = devm_kzalloc(&pdev->dev, sizeof(*bgc), GFP_KERNEL);
  57. if (!bgc)
  58. return -ENOMEM;
  59. regs = of_iomap(pdev->dev.of_node, 0);
  60. if (!regs)
  61. return -ENOMEM;
  62. ret = bgpio_init(bgc, &pdev->dev, 4, regs + GEF_GPIO_IN,
  63. regs + GEF_GPIO_OUT, NULL, NULL,
  64. regs + GEF_GPIO_DIRECT, BGPIOF_BIG_ENDIAN_BYTE_ORDER);
  65. if (ret) {
  66. dev_err(&pdev->dev, "bgpio_init failed\n");
  67. goto err0;
  68. }
  69. /* Setup pointers to chip functions */
  70. bgc->gc.label = devm_kstrdup(&pdev->dev, pdev->dev.of_node->full_name,
  71. GFP_KERNEL);
  72. if (!bgc->gc.label) {
  73. ret = -ENOMEM;
  74. goto err0;
  75. }
  76. bgc->gc.base = -1;
  77. bgc->gc.ngpio = (u16)(uintptr_t)of_id->data;
  78. bgc->gc.of_gpio_n_cells = 2;
  79. bgc->gc.of_node = pdev->dev.of_node;
  80. /* This function adds a memory mapped GPIO chip */
  81. ret = gpiochip_add(&bgc->gc);
  82. if (ret)
  83. goto err0;
  84. return 0;
  85. err0:
  86. iounmap(regs);
  87. pr_err("%s: GPIO chip registration failed\n",
  88. pdev->dev.of_node->full_name);
  89. return ret;
  90. };
  91. static struct platform_driver gef_gpio_driver = {
  92. .driver = {
  93. .name = "gef-gpio",
  94. .of_match_table = gef_gpio_ids,
  95. },
  96. };
  97. module_platform_driver_probe(gef_gpio_driver, gef_gpio_probe);
  98. MODULE_DESCRIPTION("GE I/O FPGA GPIO driver");
  99. MODULE_AUTHOR("Martyn Welch <martyn.welch@ge.com");
  100. MODULE_LICENSE("GPL");