serial_mctrl_gpio.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. * Helpers for controlling modem lines via GPIO
  3. *
  4. * Copyright (C) 2014 Paratronic S.A.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. */
  17. #ifndef __SERIAL_MCTRL_GPIO__
  18. #define __SERIAL_MCTRL_GPIO__
  19. #include <linux/err.h>
  20. #include <linux/device.h>
  21. #include <linux/gpio/consumer.h>
  22. struct uart_port;
  23. enum mctrl_gpio_idx {
  24. UART_GPIO_CTS,
  25. UART_GPIO_DSR,
  26. UART_GPIO_DCD,
  27. UART_GPIO_RNG,
  28. UART_GPIO_RI = UART_GPIO_RNG,
  29. UART_GPIO_RTS,
  30. UART_GPIO_DTR,
  31. UART_GPIO_OUT1,
  32. UART_GPIO_OUT2,
  33. UART_GPIO_MAX,
  34. };
  35. /*
  36. * Opaque descriptor for modem lines controlled by GPIOs
  37. */
  38. struct mctrl_gpios;
  39. #ifdef CONFIG_GPIOLIB
  40. /*
  41. * Set state of the modem control output lines via GPIOs.
  42. */
  43. void mctrl_gpio_set(struct mctrl_gpios *gpios, unsigned int mctrl);
  44. /*
  45. * Get state of the modem control output lines from GPIOs.
  46. * The mctrl flags are updated and returned.
  47. */
  48. unsigned int mctrl_gpio_get(struct mctrl_gpios *gpios, unsigned int *mctrl);
  49. /*
  50. * Returns the associated struct gpio_desc to the modem line gidx
  51. */
  52. struct gpio_desc *mctrl_gpio_to_gpiod(struct mctrl_gpios *gpios,
  53. enum mctrl_gpio_idx gidx);
  54. /*
  55. * Request and set direction of modem control lines GPIOs and sets up irq
  56. * handling.
  57. * devm_* functions are used, so there's no need to call mctrl_gpio_free().
  58. * Returns a pointer to the allocated mctrl structure if ok, -ENOMEM on
  59. * allocation error.
  60. */
  61. struct mctrl_gpios *mctrl_gpio_init(struct uart_port *port, unsigned int idx);
  62. /*
  63. * Request and set direction of modem control lines GPIOs.
  64. * devm_* functions are used, so there's no need to call mctrl_gpio_free().
  65. * Returns a pointer to the allocated mctrl structure if ok, -ENOMEM on
  66. * allocation error.
  67. */
  68. struct mctrl_gpios *mctrl_gpio_init_noauto(struct device *dev,
  69. unsigned int idx);
  70. /*
  71. * Free the mctrl_gpios structure.
  72. * Normally, this function will not be called, as the GPIOs will
  73. * be disposed of by the resource management code.
  74. */
  75. void mctrl_gpio_free(struct device *dev, struct mctrl_gpios *gpios);
  76. /*
  77. * Enable gpio interrupts to report status line changes.
  78. */
  79. void mctrl_gpio_enable_ms(struct mctrl_gpios *gpios);
  80. /*
  81. * Disable gpio interrupts to report status line changes.
  82. */
  83. void mctrl_gpio_disable_ms(struct mctrl_gpios *gpios);
  84. #else /* GPIOLIB */
  85. static inline
  86. void mctrl_gpio_set(struct mctrl_gpios *gpios, unsigned int mctrl)
  87. {
  88. }
  89. static inline
  90. unsigned int mctrl_gpio_get(struct mctrl_gpios *gpios, unsigned int *mctrl)
  91. {
  92. return *mctrl;
  93. }
  94. static inline
  95. struct gpio_desc *mctrl_gpio_to_gpiod(struct mctrl_gpios *gpios,
  96. enum mctrl_gpio_idx gidx)
  97. {
  98. return ERR_PTR(-ENOSYS);
  99. }
  100. static inline
  101. struct mctrl_gpios *mctrl_gpio_init(struct uart_port *port, unsigned int idx)
  102. {
  103. return ERR_PTR(-ENOSYS);
  104. }
  105. static inline
  106. struct mctrl_gpios *mctrl_gpio_init_noauto(struct device *dev, unsigned int idx)
  107. {
  108. return ERR_PTR(-ENOSYS);
  109. }
  110. static inline
  111. void mctrl_gpio_free(struct device *dev, struct mctrl_gpios *gpios)
  112. {
  113. }
  114. static inline void mctrl_gpio_enable_ms(struct mctrl_gpios *gpios)
  115. {
  116. }
  117. static inline void mctrl_gpio_disable_ms(struct mctrl_gpios *gpios)
  118. {
  119. }
  120. #endif /* GPIOLIB */
  121. #endif