gpio-ge.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. const struct of_device_id *of_id =
  51. of_match_device(gef_gpio_ids, &pdev->dev);
  52. struct gpio_chip *gc;
  53. void __iomem *regs;
  54. int ret;
  55. gc = devm_kzalloc(&pdev->dev, sizeof(*gc), GFP_KERNEL);
  56. if (!gc)
  57. return -ENOMEM;
  58. regs = of_iomap(pdev->dev.of_node, 0);
  59. if (!regs)
  60. return -ENOMEM;
  61. ret = bgpio_init(gc, &pdev->dev, 4, regs + GEF_GPIO_IN,
  62. regs + GEF_GPIO_OUT, NULL, NULL,
  63. regs + GEF_GPIO_DIRECT, BGPIOF_BIG_ENDIAN_BYTE_ORDER);
  64. if (ret) {
  65. dev_err(&pdev->dev, "bgpio_init failed\n");
  66. goto err0;
  67. }
  68. /* Setup pointers to chip functions */
  69. gc->label = devm_kasprintf(&pdev->dev, GFP_KERNEL, "%pOF", pdev->dev.of_node);
  70. if (!gc->label) {
  71. ret = -ENOMEM;
  72. goto err0;
  73. }
  74. gc->base = -1;
  75. gc->ngpio = (u16)(uintptr_t)of_id->data;
  76. gc->of_gpio_n_cells = 2;
  77. gc->of_node = pdev->dev.of_node;
  78. /* This function adds a memory mapped GPIO chip */
  79. ret = devm_gpiochip_add_data(&pdev->dev, gc, NULL);
  80. if (ret)
  81. goto err0;
  82. return 0;
  83. err0:
  84. iounmap(regs);
  85. pr_err("%pOF: GPIO chip registration failed\n", pdev->dev.of_node);
  86. return ret;
  87. };
  88. static struct platform_driver gef_gpio_driver = {
  89. .driver = {
  90. .name = "gef-gpio",
  91. .of_match_table = gef_gpio_ids,
  92. },
  93. };
  94. module_platform_driver_probe(gef_gpio_driver, gef_gpio_probe);
  95. MODULE_DESCRIPTION("GE I/O FPGA GPIO driver");
  96. MODULE_AUTHOR("Martyn Welch <martyn.welch@ge.com");
  97. MODULE_LICENSE("GPL");