Merge branch 'fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/evalenti/linux...
[linux/fpc-iii.git] / drivers / tty / serial / serial_mctrl_gpio.h
blob9716db283290697165002860430ab77bdb2ace00
1 /*
2 * Helpers for controlling modem lines via GPIO
4 * Copyright (C) 2014 Paratronic S.A.
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.
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.
18 #ifndef __SERIAL_MCTRL_GPIO__
19 #define __SERIAL_MCTRL_GPIO__
21 #include <linux/err.h>
22 #include <linux/device.h>
23 #include <linux/gpio/consumer.h>
25 struct uart_port;
27 enum mctrl_gpio_idx {
28 UART_GPIO_CTS,
29 UART_GPIO_DSR,
30 UART_GPIO_DCD,
31 UART_GPIO_RNG,
32 UART_GPIO_RI = UART_GPIO_RNG,
33 UART_GPIO_RTS,
34 UART_GPIO_DTR,
35 UART_GPIO_OUT1,
36 UART_GPIO_OUT2,
37 UART_GPIO_MAX,
41 * Opaque descriptor for modem lines controlled by GPIOs
43 struct mctrl_gpios;
45 #ifdef CONFIG_GPIOLIB
48 * Set state of the modem control output lines via GPIOs.
50 void mctrl_gpio_set(struct mctrl_gpios *gpios, unsigned int mctrl);
53 * Get state of the modem control output lines from GPIOs.
54 * The mctrl flags are updated and returned.
56 unsigned int mctrl_gpio_get(struct mctrl_gpios *gpios, unsigned int *mctrl);
59 * Returns the associated struct gpio_desc to the modem line gidx
61 struct gpio_desc *mctrl_gpio_to_gpiod(struct mctrl_gpios *gpios,
62 enum mctrl_gpio_idx gidx);
65 * Request and set direction of modem control lines GPIOs and sets up irq
66 * handling.
67 * devm_* functions are used, so there's no need to call mctrl_gpio_free().
68 * Returns a pointer to the allocated mctrl structure if ok, -ENOMEM on
69 * allocation error.
71 struct mctrl_gpios *mctrl_gpio_init(struct uart_port *port, unsigned int idx);
74 * Request and set direction of modem control lines GPIOs.
75 * devm_* functions are used, so there's no need to call mctrl_gpio_free().
76 * Returns a pointer to the allocated mctrl structure if ok, -ENOMEM on
77 * allocation error.
79 struct mctrl_gpios *mctrl_gpio_init_noauto(struct device *dev,
80 unsigned int idx);
83 * Free the mctrl_gpios structure.
84 * Normally, this function will not be called, as the GPIOs will
85 * be disposed of by the resource management code.
87 void mctrl_gpio_free(struct device *dev, struct mctrl_gpios *gpios);
90 * Enable gpio interrupts to report status line changes.
92 void mctrl_gpio_enable_ms(struct mctrl_gpios *gpios);
95 * Disable gpio interrupts to report status line changes.
97 void mctrl_gpio_disable_ms(struct mctrl_gpios *gpios);
99 #else /* GPIOLIB */
101 static inline
102 void mctrl_gpio_set(struct mctrl_gpios *gpios, unsigned int mctrl)
106 static inline
107 unsigned int mctrl_gpio_get(struct mctrl_gpios *gpios, unsigned int *mctrl)
109 return *mctrl;
112 static inline
113 struct gpio_desc *mctrl_gpio_to_gpiod(struct mctrl_gpios *gpios,
114 enum mctrl_gpio_idx gidx)
116 return ERR_PTR(-ENOSYS);
119 static inline
120 struct mctrl_gpios *mctrl_gpio_init(struct uart_port *port, unsigned int idx)
122 return ERR_PTR(-ENOSYS);
125 static inline
126 struct mctrl_gpios *mctrl_gpio_init_noauto(struct device *dev, unsigned int idx)
128 return ERR_PTR(-ENOSYS);
131 static inline
132 void mctrl_gpio_free(struct device *dev, struct mctrl_gpios *gpios)
136 static inline void mctrl_gpio_enable_ms(struct mctrl_gpios *gpios)
140 static inline void mctrl_gpio_disable_ms(struct mctrl_gpios *gpios)
144 #endif /* GPIOLIB */
146 #endif