gpio-moxart.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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_request(struct gpio_chip *chip, unsigned offset)
  30. {
  31. return pinctrl_request_gpio(offset);
  32. }
  33. static void moxart_gpio_free(struct gpio_chip *chip, unsigned offset)
  34. {
  35. pinctrl_free_gpio(offset);
  36. }
  37. static int moxart_gpio_probe(struct platform_device *pdev)
  38. {
  39. struct device *dev = &pdev->dev;
  40. struct resource *res;
  41. struct bgpio_chip *bgc;
  42. void __iomem *base;
  43. int ret;
  44. bgc = devm_kzalloc(dev, sizeof(*bgc), GFP_KERNEL);
  45. if (!bgc)
  46. return -ENOMEM;
  47. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  48. base = devm_ioremap_resource(dev, res);
  49. if (IS_ERR(base))
  50. return PTR_ERR(base);
  51. ret = bgpio_init(bgc, dev, 4, base + GPIO_DATA_IN,
  52. base + GPIO_DATA_OUT, NULL,
  53. base + GPIO_PIN_DIRECTION, NULL,
  54. BGPIOF_READ_OUTPUT_REG_SET);
  55. if (ret) {
  56. dev_err(&pdev->dev, "bgpio_init failed\n");
  57. return ret;
  58. }
  59. bgc->gc.label = "moxart-gpio";
  60. bgc->gc.request = moxart_gpio_request;
  61. bgc->gc.free = moxart_gpio_free;
  62. bgc->data = bgc->read_reg(bgc->reg_set);
  63. bgc->gc.base = 0;
  64. bgc->gc.ngpio = 32;
  65. bgc->gc.dev = dev;
  66. bgc->gc.owner = THIS_MODULE;
  67. ret = gpiochip_add(&bgc->gc);
  68. if (ret) {
  69. dev_err(dev, "%s: gpiochip_add failed\n",
  70. dev->of_node->full_name);
  71. return ret;
  72. }
  73. return ret;
  74. }
  75. static const struct of_device_id moxart_gpio_match[] = {
  76. { .compatible = "moxa,moxart-gpio" },
  77. { }
  78. };
  79. static struct platform_driver moxart_gpio_driver = {
  80. .driver = {
  81. .name = "moxart-gpio",
  82. .of_match_table = moxart_gpio_match,
  83. },
  84. .probe = moxart_gpio_probe,
  85. };
  86. module_platform_driver(moxart_gpio_driver);
  87. MODULE_DESCRIPTION("MOXART GPIO chip driver");
  88. MODULE_LICENSE("GPL");
  89. MODULE_AUTHOR("Jonas Jensen <jonas.jensen@gmail.com>");