Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0+ */
0002 /*
0003  * Helpers for controlling modem lines via GPIO
0004  *
0005  * Copyright (C) 2014 Paratronic S.A.
0006  */
0007 
0008 #ifndef __SERIAL_MCTRL_GPIO__
0009 #define __SERIAL_MCTRL_GPIO__
0010 
0011 #include <linux/err.h>
0012 #include <linux/device.h>
0013 #include <linux/gpio/consumer.h>
0014 
0015 struct uart_port;
0016 
0017 enum mctrl_gpio_idx {
0018     UART_GPIO_CTS,
0019     UART_GPIO_DSR,
0020     UART_GPIO_DCD,
0021     UART_GPIO_RNG,
0022     UART_GPIO_RI = UART_GPIO_RNG,
0023     UART_GPIO_RTS,
0024     UART_GPIO_DTR,
0025     UART_GPIO_MAX,
0026 };
0027 
0028 /*
0029  * Opaque descriptor for modem lines controlled by GPIOs
0030  */
0031 struct mctrl_gpios;
0032 
0033 #ifdef CONFIG_GPIOLIB
0034 
0035 /*
0036  * Set state of the modem control output lines via GPIOs.
0037  */
0038 void mctrl_gpio_set(struct mctrl_gpios *gpios, unsigned int mctrl);
0039 
0040 /*
0041  * Get state of the modem control input lines from GPIOs.
0042  * The mctrl flags are updated and returned.
0043  */
0044 unsigned int mctrl_gpio_get(struct mctrl_gpios *gpios, unsigned int *mctrl);
0045 
0046 /*
0047  * Get state of the modem control output lines from GPIOs.
0048  * The mctrl flags are updated and returned.
0049  */
0050 unsigned int
0051 mctrl_gpio_get_outputs(struct mctrl_gpios *gpios, unsigned int *mctrl);
0052 
0053 /*
0054  * Returns the associated struct gpio_desc to the modem line gidx
0055  */
0056 struct gpio_desc *mctrl_gpio_to_gpiod(struct mctrl_gpios *gpios,
0057                       enum mctrl_gpio_idx gidx);
0058 
0059 /*
0060  * Request and set direction of modem control line GPIOs and set up irq
0061  * handling.
0062  * devm_* functions are used, so there's no need to call mctrl_gpio_free().
0063  * Returns a pointer to the allocated mctrl structure if ok, -ENOMEM on
0064  * allocation error.
0065  */
0066 struct mctrl_gpios *mctrl_gpio_init(struct uart_port *port, unsigned int idx);
0067 
0068 /*
0069  * Request and set direction of modem control line GPIOs.
0070  * devm_* functions are used, so there's no need to call mctrl_gpio_free().
0071  * Returns a pointer to the allocated mctrl structure if ok, -ENOMEM on
0072  * allocation error.
0073  */
0074 struct mctrl_gpios *mctrl_gpio_init_noauto(struct device *dev,
0075                        unsigned int idx);
0076 
0077 /*
0078  * Free the mctrl_gpios structure.
0079  * Normally, this function will not be called, as the GPIOs will
0080  * be disposed of by the resource management code.
0081  */
0082 void mctrl_gpio_free(struct device *dev, struct mctrl_gpios *gpios);
0083 
0084 /*
0085  * Enable gpio interrupts to report status line changes.
0086  */
0087 void mctrl_gpio_enable_ms(struct mctrl_gpios *gpios);
0088 
0089 /*
0090  * Disable gpio interrupts to report status line changes.
0091  */
0092 void mctrl_gpio_disable_ms(struct mctrl_gpios *gpios);
0093 
0094 /*
0095  * Enable gpio wakeup interrupts to enable wake up source.
0096  */
0097 void mctrl_gpio_enable_irq_wake(struct mctrl_gpios *gpios);
0098 
0099 /*
0100  * Disable gpio wakeup interrupts to enable wake up source.
0101  */
0102 void mctrl_gpio_disable_irq_wake(struct mctrl_gpios *gpios);
0103 
0104 #else /* GPIOLIB */
0105 
0106 static inline
0107 void mctrl_gpio_set(struct mctrl_gpios *gpios, unsigned int mctrl)
0108 {
0109 }
0110 
0111 static inline
0112 unsigned int mctrl_gpio_get(struct mctrl_gpios *gpios, unsigned int *mctrl)
0113 {
0114     return *mctrl;
0115 }
0116 
0117 static inline unsigned int
0118 mctrl_gpio_get_outputs(struct mctrl_gpios *gpios, unsigned int *mctrl)
0119 {
0120     return *mctrl;
0121 }
0122 
0123 static inline
0124 struct gpio_desc *mctrl_gpio_to_gpiod(struct mctrl_gpios *gpios,
0125                       enum mctrl_gpio_idx gidx)
0126 {
0127     return NULL;
0128 }
0129 
0130 static inline
0131 struct mctrl_gpios *mctrl_gpio_init(struct uart_port *port, unsigned int idx)
0132 {
0133     return NULL;
0134 }
0135 
0136 static inline
0137 struct mctrl_gpios *mctrl_gpio_init_noauto(struct device *dev, unsigned int idx)
0138 {
0139     return NULL;
0140 }
0141 
0142 static inline
0143 void mctrl_gpio_free(struct device *dev, struct mctrl_gpios *gpios)
0144 {
0145 }
0146 
0147 static inline void mctrl_gpio_enable_ms(struct mctrl_gpios *gpios)
0148 {
0149 }
0150 
0151 static inline void mctrl_gpio_disable_ms(struct mctrl_gpios *gpios)
0152 {
0153 }
0154 
0155 static inline void mctrl_gpio_enable_irq_wake(struct mctrl_gpios *gpios)
0156 {
0157 }
0158 
0159 static inline void mctrl_gpio_disable_irq_wake(struct mctrl_gpios *gpios)
0160 {
0161 }
0162 
0163 #endif /* GPIOLIB */
0164 
0165 #endif