gpio-moxart.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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/platform_device.h>
  17. #include <linux/of_address.h>
  18. #include <linux/of_gpio.h>
  19. #include <linux/pinctrl/consumer.h>
  20. #include <linux/delay.h>
  21. #include <linux/timer.h>
  22. #include <linux/bitops.h>
  23. #include <linux/gpio/driver.h>
  24. #define GPIO_DATA_OUT 0x00
  25. #define GPIO_DATA_IN 0x04
  26. #define GPIO_PIN_DIRECTION 0x08
  27. static int moxart_gpio_probe(struct platform_device *pdev)
  28. {
  29. struct device *dev = &pdev->dev;
  30. struct resource *res;
  31. struct gpio_chip *gc;
  32. void __iomem *base;
  33. int ret;
  34. gc = devm_kzalloc(dev, sizeof(*gc), GFP_KERNEL);
  35. if (!gc)
  36. return -ENOMEM;
  37. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  38. base = devm_ioremap_resource(dev, res);
  39. if (IS_ERR(base))
  40. return PTR_ERR(base);
  41. ret = bgpio_init(gc, dev, 4, base + GPIO_DATA_IN,
  42. base + GPIO_DATA_OUT, NULL,
  43. base + GPIO_PIN_DIRECTION, NULL,
  44. BGPIOF_READ_OUTPUT_REG_SET);
  45. if (ret) {
  46. dev_err(&pdev->dev, "bgpio_init failed\n");
  47. return ret;
  48. }
  49. gc->label = "moxart-gpio";
  50. gc->request = gpiochip_generic_request;
  51. gc->free = gpiochip_generic_free;
  52. gc->base = 0;
  53. gc->owner = THIS_MODULE;
  54. ret = devm_gpiochip_add_data(dev, gc, NULL);
  55. if (ret) {
  56. dev_err(dev, "%s: gpiochip_add failed\n",
  57. dev->of_node->full_name);
  58. return ret;
  59. }
  60. return ret;
  61. }
  62. static const struct of_device_id moxart_gpio_match[] = {
  63. { .compatible = "moxa,moxart-gpio" },
  64. { }
  65. };
  66. static struct platform_driver moxart_gpio_driver = {
  67. .driver = {
  68. .name = "moxart-gpio",
  69. .of_match_table = moxart_gpio_match,
  70. },
  71. .probe = moxart_gpio_probe,
  72. };
  73. builtin_platform_driver(moxart_gpio_driver);