serial_mctrl_gpio.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Helpers for controlling modem lines via GPIO
  4. *
  5. * Copyright (C) 2014 Paratronic S.A.
  6. */
  7. #ifndef __SERIAL_MCTRL_GPIO__
  8. #define __SERIAL_MCTRL_GPIO__
  9. #include <linux/err.h>
  10. #include <linux/device.h>
  11. #include <linux/gpio/consumer.h>
  12. struct uart_port;
  13. enum mctrl_gpio_idx {
  14. UART_GPIO_CTS,
  15. UART_GPIO_DSR,
  16. UART_GPIO_DCD,
  17. UART_GPIO_RNG,
  18. UART_GPIO_RI = UART_GPIO_RNG,
  19. UART_GPIO_RTS,
  20. UART_GPIO_DTR,
  21. UART_GPIO_MAX,
  22. };
  23. /*
  24. * Opaque descriptor for modem lines controlled by GPIOs
  25. */
  26. struct mctrl_gpios;
  27. #ifdef CONFIG_GPIOLIB
  28. /*
  29. * Set state of the modem control output lines via GPIOs.
  30. */
  31. void mctrl_gpio_set(struct mctrl_gpios *gpios, unsigned int mctrl);
  32. /*
  33. * Get state of the modem control input lines from GPIOs.
  34. * The mctrl flags are updated and returned.
  35. */
  36. unsigned int mctrl_gpio_get(struct mctrl_gpios *gpios, unsigned int *mctrl);
  37. /*
  38. * Get state of the modem control output lines from GPIOs.
  39. * The mctrl flags are updated and returned.
  40. */
  41. unsigned int
  42. mctrl_gpio_get_outputs(struct mctrl_gpios *gpios, unsigned int *mctrl);
  43. /*
  44. * Returns the associated struct gpio_desc to the modem line gidx
  45. */
  46. struct gpio_desc *mctrl_gpio_to_gpiod(struct mctrl_gpios *gpios,
  47. enum mctrl_gpio_idx gidx);
  48. /*
  49. * Request and set direction of modem control line GPIOs and set up irq
  50. * handling.
  51. * devm_* functions are used, so there's no need to call mctrl_gpio_free().
  52. * Returns a pointer to the allocated mctrl structure if ok, -ENOMEM on
  53. * allocation error.
  54. */
  55. struct mctrl_gpios *mctrl_gpio_init(struct uart_port *port, unsigned int idx);
  56. /*
  57. * Request and set direction of modem control line GPIOs.
  58. * devm_* functions are used, so there's no need to call mctrl_gpio_free().
  59. * Returns a pointer to the allocated mctrl structure if ok, -ENOMEM on
  60. * allocation error.
  61. */
  62. struct mctrl_gpios *mctrl_gpio_init_noauto(struct device *dev,
  63. unsigned int idx);
  64. /*
  65. * Free the mctrl_gpios structure.
  66. * Normally, this function will not be called, as the GPIOs will
  67. * be disposed of by the resource management code.
  68. */
  69. void mctrl_gpio_free(struct device *dev, struct mctrl_gpios *gpios);
  70. /*
  71. * Enable gpio interrupts to report status line changes.
  72. */
  73. void mctrl_gpio_enable_ms(struct mctrl_gpios *gpios);
  74. /*
  75. * Disable gpio interrupts to report status line changes, and block until
  76. * any corresponding IRQ is processed
  77. */
  78. void mctrl_gpio_disable_ms_sync(struct mctrl_gpios *gpios);
  79. /*
  80. * Disable gpio interrupts to report status line changes, and return
  81. * immediately
  82. */
  83. void mctrl_gpio_disable_ms_no_sync(struct mctrl_gpios *gpios);
  84. /*
  85. * Enable gpio wakeup interrupts to enable wake up source.
  86. */
  87. void mctrl_gpio_enable_irq_wake(struct mctrl_gpios *gpios);
  88. /*
  89. * Disable gpio wakeup interrupts to enable wake up source.
  90. */
  91. void mctrl_gpio_disable_irq_wake(struct mctrl_gpios *gpios);
  92. #else /* GPIOLIB */
  93. static inline
  94. void mctrl_gpio_set(struct mctrl_gpios *gpios, unsigned int mctrl)
  95. {
  96. }
  97. static inline
  98. unsigned int mctrl_gpio_get(struct mctrl_gpios *gpios, unsigned int *mctrl)
  99. {
  100. return *mctrl;
  101. }
  102. static inline unsigned int
  103. mctrl_gpio_get_outputs(struct mctrl_gpios *gpios, unsigned int *mctrl)
  104. {
  105. return *mctrl;
  106. }
  107. static inline
  108. struct gpio_desc *mctrl_gpio_to_gpiod(struct mctrl_gpios *gpios,
  109. enum mctrl_gpio_idx gidx)
  110. {
  111. return NULL;
  112. }
  113. static inline
  114. struct mctrl_gpios *mctrl_gpio_init(struct uart_port *port, unsigned int idx)
  115. {
  116. return NULL;
  117. }
  118. static inline
  119. struct mctrl_gpios *mctrl_gpio_init_noauto(struct device *dev, unsigned int idx)
  120. {
  121. return NULL;
  122. }
  123. static inline
  124. void mctrl_gpio_free(struct device *dev, struct mctrl_gpios *gpios)
  125. {
  126. }
  127. static inline void mctrl_gpio_enable_ms(struct mctrl_gpios *gpios)
  128. {
  129. }
  130. static inline void mctrl_gpio_disable_ms_sync(struct mctrl_gpios *gpios)
  131. {
  132. }
  133. static inline void mctrl_gpio_disable_ms_no_sync(struct mctrl_gpios *gpios)
  134. {
  135. }
  136. static inline void mctrl_gpio_enable_irq_wake(struct mctrl_gpios *gpios)
  137. {
  138. }
  139. static inline void mctrl_gpio_disable_irq_wake(struct mctrl_gpios *gpios)
  140. {
  141. }
  142. #endif /* GPIOLIB */
  143. #endif