gpio-ge.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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_address.h>
  23. #include <linux/module.h>
  24. #include <linux/gpio/driver.h>
  25. #define GEF_GPIO_DIRECT 0x00
  26. #define GEF_GPIO_IN 0x04
  27. #define GEF_GPIO_OUT 0x08
  28. #define GEF_GPIO_TRIG 0x0C
  29. #define GEF_GPIO_POLAR_A 0x10
  30. #define GEF_GPIO_POLAR_B 0x14
  31. #define GEF_GPIO_INT_STAT 0x18
  32. #define GEF_GPIO_OVERRUN 0x1C
  33. #define GEF_GPIO_MODE 0x20
  34. static const struct of_device_id gef_gpio_ids[] = {
  35. {
  36. .compatible = "gef,sbc610-gpio",
  37. .data = (void *)19,
  38. }, {
  39. .compatible = "gef,sbc310-gpio",
  40. .data = (void *)6,
  41. }, {
  42. .compatible = "ge,imp3a-gpio",
  43. .data = (void *)16,
  44. },
  45. { }
  46. };
  47. MODULE_DEVICE_TABLE(of, gef_gpio_ids);
  48. static int __init gef_gpio_probe(struct platform_device *pdev)
  49. {
  50. struct gpio_chip *gc;
  51. void __iomem *regs;
  52. int ret;
  53. gc = devm_kzalloc(&pdev->dev, sizeof(*gc), GFP_KERNEL);
  54. if (!gc)
  55. return -ENOMEM;
  56. regs = of_iomap(pdev->dev.of_node, 0);
  57. if (!regs)
  58. return -ENOMEM;
  59. ret = bgpio_init(gc, &pdev->dev, 4, regs + GEF_GPIO_IN,
  60. regs + GEF_GPIO_OUT, NULL, NULL,
  61. regs + GEF_GPIO_DIRECT, BGPIOF_BIG_ENDIAN_BYTE_ORDER);
  62. if (ret) {
  63. dev_err(&pdev->dev, "bgpio_init failed\n");
  64. goto err0;
  65. }
  66. /* Setup pointers to chip functions */
  67. gc->label = devm_kasprintf(&pdev->dev, GFP_KERNEL, "%pOF", pdev->dev.of_node);
  68. if (!gc->label) {
  69. ret = -ENOMEM;
  70. goto err0;
  71. }
  72. gc->base = -1;
  73. gc->ngpio = (u16)(uintptr_t)of_device_get_match_data(&pdev->dev);
  74. gc->of_gpio_n_cells = 2;
  75. gc->of_node = pdev->dev.of_node;
  76. /* This function adds a memory mapped GPIO chip */
  77. ret = devm_gpiochip_add_data(&pdev->dev, gc, NULL);
  78. if (ret)
  79. goto err0;
  80. return 0;
  81. err0:
  82. iounmap(regs);
  83. pr_err("%pOF: GPIO chip registration failed\n", pdev->dev.of_node);
  84. return ret;
  85. };
  86. static struct platform_driver gef_gpio_driver = {
  87. .driver = {
  88. .name = "gef-gpio",
  89. .of_match_table = gef_gpio_ids,
  90. },
  91. };
  92. module_platform_driver_probe(gef_gpio_driver, gef_gpio_probe);
  93. MODULE_DESCRIPTION("GE I/O FPGA GPIO driver");
  94. MODULE_AUTHOR("Martyn Welch <martyn.welch@ge.com");
  95. MODULE_LICENSE("GPL");