serial_mctrl_gpio.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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_MAX,
  32. };
  33. /*
  34. * Opaque descriptor for modem lines controlled by GPIOs
  35. */
  36. struct mctrl_gpios;
  37. #ifdef CONFIG_GPIOLIB
  38. /*
  39. * Set state of the modem control output lines via GPIOs.
  40. */
  41. void mctrl_gpio_set(struct mctrl_gpios *gpios, unsigned int mctrl);
  42. /*
  43. * Get state of the modem control input lines from GPIOs.
  44. * The mctrl flags are updated and returned.
  45. */
  46. unsigned int mctrl_gpio_get(struct mctrl_gpios *gpios, unsigned int *mctrl);
  47. /*
  48. * Get state of the modem control output lines from GPIOs.
  49. * The mctrl flags are updated and returned.
  50. */
  51. unsigned int
  52. mctrl_gpio_get_outputs(struct mctrl_gpios *gpios, unsigned int *mctrl);
  53. /*
  54. * Returns the associated struct gpio_desc to the modem line gidx
  55. */
  56. struct gpio_desc *mctrl_gpio_to_gpiod(struct mctrl_gpios *gpios,
  57. enum mctrl_gpio_idx gidx);
  58. /*
  59. * Request and set direction of modem control line GPIOs and set up irq
  60. * handling.
  61. * devm_* functions are used, so there's no need to call mctrl_gpio_free().
  62. * Returns a pointer to the allocated mctrl structure if ok, -ENOMEM on
  63. * allocation error.
  64. */
  65. struct mctrl_gpios *mctrl_gpio_init(struct uart_port *port, unsigned int idx);
  66. /*
  67. * Request and set direction of modem control line GPIOs.
  68. * devm_* functions are used, so there's no need to call mctrl_gpio_free().
  69. * Returns a pointer to the allocated mctrl structure if ok, -ENOMEM on
  70. * allocation error.
  71. */
  72. struct mctrl_gpios *mctrl_gpio_init_noauto(struct device *dev,
  73. unsigned int idx);
  74. /*
  75. * Free the mctrl_gpios structure.
  76. * Normally, this function will not be called, as the GPIOs will
  77. * be disposed of by the resource management code.
  78. */
  79. void mctrl_gpio_free(struct device *dev, struct mctrl_gpios *gpios);
  80. /*
  81. * Enable gpio interrupts to report status line changes.
  82. */
  83. void mctrl_gpio_enable_ms(struct mctrl_gpios *gpios);
  84. /*
  85. * Disable gpio interrupts to report status line changes.
  86. */
  87. void mctrl_gpio_disable_ms(struct mctrl_gpios *gpios);
  88. #else /* GPIOLIB */
  89. static inline
  90. void mctrl_gpio_set(struct mctrl_gpios *gpios, unsigned int mctrl)
  91. {
  92. }
  93. static inline
  94. unsigned int mctrl_gpio_get(struct mctrl_gpios *gpios, unsigned int *mctrl)
  95. {
  96. return *mctrl;
  97. }
  98. static inline unsigned int
  99. mctrl_gpio_get_outputs(struct mctrl_gpios *gpios, unsigned int *mctrl)
  100. {
  101. return *mctrl;
  102. }
  103. static inline
  104. struct gpio_desc *mctrl_gpio_to_gpiod(struct mctrl_gpios *gpios,
  105. enum mctrl_gpio_idx gidx)
  106. {
  107. return ERR_PTR(-ENOSYS);
  108. }
  109. static inline
  110. struct mctrl_gpios *mctrl_gpio_init(struct uart_port *port, unsigned int idx)
  111. {
  112. return ERR_PTR(-ENOSYS);
  113. }
  114. static inline
  115. struct mctrl_gpios *mctrl_gpio_init_noauto(struct device *dev, unsigned int idx)
  116. {
  117. return ERR_PTR(-ENOSYS);
  118. }
  119. static inline
  120. void mctrl_gpio_free(struct device *dev, struct mctrl_gpios *gpios)
  121. {
  122. }
  123. static inline void mctrl_gpio_enable_ms(struct mctrl_gpios *gpios)
  124. {
  125. }
  126. static inline void mctrl_gpio_disable_ms(struct mctrl_gpios *gpios)
  127. {
  128. }
  129. #endif /* GPIOLIB */
  130. #endif