gpio-moxart.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. #include <linux/err.h>
  13. #include <linux/init.h>
  14. #include <linux/irq.h>
  15. #include <linux/io.h>
  16. #include <linux/gpio.h>
  17. #include <linux/platform_device.h>
  18. #include <linux/module.h>
  19. #include <linux/of_address.h>
  20. #include <linux/of_gpio.h>
  21. #include <linux/pinctrl/consumer.h>
  22. #include <linux/delay.h>
  23. #include <linux/timer.h>
  24. #include <linux/bitops.h>
  25. #include <linux/basic_mmio_gpio.h>
  26. #define GPIO_DATA_OUT 0x00
  27. #define GPIO_DATA_IN 0x04
  28. #define GPIO_PIN_DIRECTION 0x08
  29. static int moxart_gpio_probe(struct platform_device *pdev)
  30. {
  31. struct device *dev = &pdev->dev;
  32. struct resource *res;
  33. struct bgpio_chip *bgc;
  34. void __iomem *base;
  35. int ret;
  36. bgc = devm_kzalloc(dev, sizeof(*bgc), GFP_KERNEL);
  37. if (!bgc)
  38. return -ENOMEM;
  39. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  40. base = devm_ioremap_resource(dev, res);
  41. if (IS_ERR(base))
  42. return PTR_ERR(base);
  43. ret = bgpio_init(bgc, dev, 4, base + GPIO_DATA_IN,
  44. base + GPIO_DATA_OUT, NULL,
  45. base + GPIO_PIN_DIRECTION, NULL,
  46. BGPIOF_READ_OUTPUT_REG_SET);
  47. if (ret) {
  48. dev_err(&pdev->dev, "bgpio_init failed\n");
  49. return ret;
  50. }
  51. bgc->gc.label = "moxart-gpio";
  52. bgc->gc.request = gpiochip_generic_request;
  53. bgc->gc.free = gpiochip_generic_free;
  54. bgc->data = bgc->read_reg(bgc->reg_set);
  55. bgc->gc.base = 0;
  56. bgc->gc.ngpio = 32;
  57. bgc->gc.dev = dev;
  58. bgc->gc.owner = THIS_MODULE;
  59. ret = gpiochip_add(&bgc->gc);
  60. if (ret) {
  61. dev_err(dev, "%s: gpiochip_add failed\n",
  62. dev->of_node->full_name);
  63. return ret;
  64. }
  65. return ret;
  66. }
  67. static const struct of_device_id moxart_gpio_match[] = {
  68. { .compatible = "moxa,moxart-gpio" },
  69. { }
  70. };
  71. static struct platform_driver moxart_gpio_driver = {
  72. .driver = {
  73. .name = "moxart-gpio",
  74. .of_match_table = moxart_gpio_match,
  75. },
  76. .probe = moxart_gpio_probe,
  77. };
  78. module_platform_driver(moxart_gpio_driver);
  79. MODULE_DESCRIPTION("MOXART GPIO chip driver");
  80. MODULE_LICENSE("GPL");
  81. MODULE_AUTHOR("Jonas Jensen <jonas.jensen@gmail.com>");