serial_mctrl_gpio.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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.
  76. */
  77. void mctrl_gpio_disable_ms(struct mctrl_gpios *gpios);
  78. #else /* GPIOLIB */
  79. static inline
  80. void mctrl_gpio_set(struct mctrl_gpios *gpios, unsigned int mctrl)
  81. {
  82. }
  83. static inline
  84. unsigned int mctrl_gpio_get(struct mctrl_gpios *gpios, unsigned int *mctrl)
  85. {
  86. return *mctrl;
  87. }
  88. static inline unsigned int
  89. mctrl_gpio_get_outputs(struct mctrl_gpios *gpios, unsigned int *mctrl)
  90. {
  91. return *mctrl;
  92. }
  93. static inline
  94. struct gpio_desc *mctrl_gpio_to_gpiod(struct mctrl_gpios *gpios,
  95. enum mctrl_gpio_idx gidx)
  96. {
  97. return NULL;
  98. }
  99. static inline
  100. struct mctrl_gpios *mctrl_gpio_init(struct uart_port *port, unsigned int idx)
  101. {
  102. return NULL;
  103. }
  104. static inline
  105. struct mctrl_gpios *mctrl_gpio_init_noauto(struct device *dev, unsigned int idx)
  106. {
  107. return NULL;
  108. }
  109. static inline
  110. void mctrl_gpio_free(struct device *dev, struct mctrl_gpios *gpios)
  111. {
  112. }
  113. static inline void mctrl_gpio_enable_ms(struct mctrl_gpios *gpios)
  114. {
  115. }
  116. static inline void mctrl_gpio_disable_ms(struct mctrl_gpios *gpios)
  117. {
  118. }
  119. #endif /* GPIOLIB */
  120. #endif