blob: 219eba0223bbb7c927002a10e55748456554c05e [file] [log] [blame]
Greg Kroah-Hartmane3b3d0f2017-11-06 18:11:51 +01001// SPDX-License-Identifier: GPL-2.0+
Richard Genoud84130aa2014-05-13 20:20:43 +02002/*
3 * Helpers for controlling modem lines via GPIO
4 *
5 * Copyright (C) 2014 Paratronic S.A.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 */
18
19#ifndef __SERIAL_MCTRL_GPIO__
20#define __SERIAL_MCTRL_GPIO__
21
22#include <linux/err.h>
23#include <linux/device.h>
24#include <linux/gpio/consumer.h>
25
Uwe Kleine-Königce59e482015-09-30 10:19:41 +020026struct uart_port;
27
Richard Genoud84130aa2014-05-13 20:20:43 +020028enum mctrl_gpio_idx {
29 UART_GPIO_CTS,
30 UART_GPIO_DSR,
31 UART_GPIO_DCD,
32 UART_GPIO_RNG,
33 UART_GPIO_RI = UART_GPIO_RNG,
34 UART_GPIO_RTS,
35 UART_GPIO_DTR,
Richard Genoud84130aa2014-05-13 20:20:43 +020036 UART_GPIO_MAX,
37};
38
39/*
40 * Opaque descriptor for modem lines controlled by GPIOs
41 */
42struct mctrl_gpios;
43
44#ifdef CONFIG_GPIOLIB
45
46/*
47 * Set state of the modem control output lines via GPIOs.
48 */
49void mctrl_gpio_set(struct mctrl_gpios *gpios, unsigned int mctrl);
50
51/*
Yegor Yefremovbf5cee62016-05-31 10:59:16 +020052 * Get state of the modem control input lines from GPIOs.
Richard Genoud84130aa2014-05-13 20:20:43 +020053 * The mctrl flags are updated and returned.
54 */
55unsigned int mctrl_gpio_get(struct mctrl_gpios *gpios, unsigned int *mctrl);
56
57/*
Yegor Yefremovbf5cee62016-05-31 10:59:16 +020058 * Get state of the modem control output lines from GPIOs.
59 * The mctrl flags are updated and returned.
60 */
61unsigned int
62mctrl_gpio_get_outputs(struct mctrl_gpios *gpios, unsigned int *mctrl);
63
64/*
Richard Genoud84130aa2014-05-13 20:20:43 +020065 * Returns the associated struct gpio_desc to the modem line gidx
66 */
67struct gpio_desc *mctrl_gpio_to_gpiod(struct mctrl_gpios *gpios,
68 enum mctrl_gpio_idx gidx);
69
70/*
Geert Uytterhoeven03e970b2016-04-14 12:01:32 +020071 * Request and set direction of modem control line GPIOs and set up irq
Uwe Kleine-Königce59e482015-09-30 10:19:41 +020072 * handling.
73 * devm_* functions are used, so there's no need to call mctrl_gpio_free().
74 * Returns a pointer to the allocated mctrl structure if ok, -ENOMEM on
75 * allocation error.
76 */
77struct mctrl_gpios *mctrl_gpio_init(struct uart_port *port, unsigned int idx);
78
79/*
Geert Uytterhoeven03e970b2016-04-14 12:01:32 +020080 * Request and set direction of modem control line GPIOs.
Richard Genoud84130aa2014-05-13 20:20:43 +020081 * devm_* functions are used, so there's no need to call mctrl_gpio_free().
82 * Returns a pointer to the allocated mctrl structure if ok, -ENOMEM on
83 * allocation error.
84 */
Uwe Kleine-König7d8c70d2015-09-30 10:19:40 +020085struct mctrl_gpios *mctrl_gpio_init_noauto(struct device *dev,
86 unsigned int idx);
Richard Genoud84130aa2014-05-13 20:20:43 +020087
88/*
89 * Free the mctrl_gpios structure.
90 * Normally, this function will not be called, as the GPIOs will
91 * be disposed of by the resource management code.
92 */
93void mctrl_gpio_free(struct device *dev, struct mctrl_gpios *gpios);
94
Uwe Kleine-Königce59e482015-09-30 10:19:41 +020095/*
96 * Enable gpio interrupts to report status line changes.
97 */
98void mctrl_gpio_enable_ms(struct mctrl_gpios *gpios);
99
100/*
101 * Disable gpio interrupts to report status line changes.
102 */
103void mctrl_gpio_disable_ms(struct mctrl_gpios *gpios);
104
Richard Genoud84130aa2014-05-13 20:20:43 +0200105#else /* GPIOLIB */
106
107static inline
108void mctrl_gpio_set(struct mctrl_gpios *gpios, unsigned int mctrl)
109{
110}
111
112static inline
113unsigned int mctrl_gpio_get(struct mctrl_gpios *gpios, unsigned int *mctrl)
114{
115 return *mctrl;
116}
117
Yegor Yefremovbf5cee62016-05-31 10:59:16 +0200118static inline unsigned int
119mctrl_gpio_get_outputs(struct mctrl_gpios *gpios, unsigned int *mctrl)
120{
121 return *mctrl;
122}
123
Richard Genoud84130aa2014-05-13 20:20:43 +0200124static inline
125struct gpio_desc *mctrl_gpio_to_gpiod(struct mctrl_gpios *gpios,
126 enum mctrl_gpio_idx gidx)
127{
128 return ERR_PTR(-ENOSYS);
129}
130
131static inline
Uwe Kleine-Königce59e482015-09-30 10:19:41 +0200132struct mctrl_gpios *mctrl_gpio_init(struct uart_port *port, unsigned int idx)
133{
134 return ERR_PTR(-ENOSYS);
135}
136
137static inline
Uwe Kleine-König7d8c70d2015-09-30 10:19:40 +0200138struct mctrl_gpios *mctrl_gpio_init_noauto(struct device *dev, unsigned int idx)
Richard Genoud84130aa2014-05-13 20:20:43 +0200139{
140 return ERR_PTR(-ENOSYS);
141}
142
143static inline
144void mctrl_gpio_free(struct device *dev, struct mctrl_gpios *gpios)
145{
146}
147
Arnd Bergmann1b306f92015-10-12 17:04:14 +0200148static inline void mctrl_gpio_enable_ms(struct mctrl_gpios *gpios)
Uwe Kleine-Königce59e482015-09-30 10:19:41 +0200149{
150}
151
Arnd Bergmann1b306f92015-10-12 17:04:14 +0200152static inline void mctrl_gpio_disable_ms(struct mctrl_gpios *gpios)
Uwe Kleine-Königce59e482015-09-30 10:19:41 +0200153{
154}
155
Richard Genoud84130aa2014-05-13 20:20:43 +0200156#endif /* GPIOLIB */
157
158#endif