gpio-moxart.c 2.1 KB

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