serial_mctrl_gpio.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. enum mctrl_gpio_idx {
  23. UART_GPIO_CTS,
  24. UART_GPIO_DSR,
  25. UART_GPIO_DCD,
  26. UART_GPIO_RNG,
  27. UART_GPIO_RI = UART_GPIO_RNG,
  28. UART_GPIO_RTS,
  29. UART_GPIO_DTR,
  30. UART_GPIO_OUT1,
  31. UART_GPIO_OUT2,
  32. UART_GPIO_MAX,
  33. };
  34. /*
  35. * Opaque descriptor for modem lines controlled by GPIOs
  36. */
  37. struct mctrl_gpios;
  38. #ifdef CONFIG_GPIOLIB
  39. /*
  40. * Set state of the modem control output lines via GPIOs.
  41. */
  42. void mctrl_gpio_set(struct mctrl_gpios *gpios, unsigned int mctrl);
  43. /*
  44. * Get state of the modem control output lines from GPIOs.
  45. * The mctrl flags are updated and returned.
  46. */
  47. unsigned int mctrl_gpio_get(struct mctrl_gpios *gpios, unsigned int *mctrl);
  48. /*
  49. * Returns the associated struct gpio_desc to the modem line gidx
  50. */
  51. struct gpio_desc *mctrl_gpio_to_gpiod(struct mctrl_gpios *gpios,
  52. enum mctrl_gpio_idx gidx);
  53. /*
  54. * Request and set direction of modem control lines GPIOs.
  55. * devm_* functions are used, so there's no need to call mctrl_gpio_free().
  56. * Returns a pointer to the allocated mctrl structure if ok, -ENOMEM on
  57. * allocation error.
  58. */
  59. struct mctrl_gpios *mctrl_gpio_init(struct device *dev, unsigned int idx);
  60. /*
  61. * Free the mctrl_gpios structure.
  62. * Normally, this function will not be called, as the GPIOs will
  63. * be disposed of by the resource management code.
  64. */
  65. void mctrl_gpio_free(struct device *dev, struct mctrl_gpios *gpios);
  66. #else /* GPIOLIB */
  67. static inline
  68. void mctrl_gpio_set(struct mctrl_gpios *gpios, unsigned int mctrl)
  69. {
  70. }
  71. static inline
  72. unsigned int mctrl_gpio_get(struct mctrl_gpios *gpios, unsigned int *mctrl)
  73. {
  74. return *mctrl;
  75. }
  76. static inline
  77. struct gpio_desc *mctrl_gpio_to_gpiod(struct mctrl_gpios *gpios,
  78. enum mctrl_gpio_idx gidx)
  79. {
  80. return ERR_PTR(-ENOSYS);
  81. }
  82. static inline
  83. struct mctrl_gpios *mctrl_gpio_init(struct device *dev, unsigned int idx)
  84. {
  85. return ERR_PTR(-ENOSYS);
  86. }
  87. static inline
  88. void mctrl_gpio_free(struct device *dev, struct mctrl_gpios *gpios)
  89. {
  90. }
  91. #endif /* GPIOLIB */
  92. #endif