Loading...
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
8#ifndef __SERIAL_MCTRL_GPIO__
9#define __SERIAL_MCTRL_GPIO__
10
11#include <linux/err.h>
12#include <linux/device.h>
13#include <linux/gpio/consumer.h>
14
15struct uart_port;
16
17enum mctrl_gpio_idx {
18 UART_GPIO_CTS,
19 UART_GPIO_DSR,
20 UART_GPIO_DCD,
21 UART_GPIO_RNG,
22 UART_GPIO_RI = UART_GPIO_RNG,
23 UART_GPIO_RTS,
24 UART_GPIO_DTR,
25 UART_GPIO_MAX,
26};
27
28/*
29 * Opaque descriptor for modem lines controlled by GPIOs
30 */
31struct mctrl_gpios;
32
33#ifdef CONFIG_GPIOLIB
34
35/*
36 * Set state of the modem control output lines via GPIOs.
37 */
38void mctrl_gpio_set(struct mctrl_gpios *gpios, unsigned int mctrl);
39
40/*
41 * Get state of the modem control input lines from GPIOs.
42 * The mctrl flags are updated and returned.
43 */
44unsigned int mctrl_gpio_get(struct mctrl_gpios *gpios, unsigned int *mctrl);
45
46/*
47 * Get state of the modem control output lines from GPIOs.
48 * The mctrl flags are updated and returned.
49 */
50unsigned int
51mctrl_gpio_get_outputs(struct mctrl_gpios *gpios, unsigned int *mctrl);
52
53/*
54 * Returns the associated struct gpio_desc to the modem line gidx
55 */
56struct gpio_desc *mctrl_gpio_to_gpiod(struct mctrl_gpios *gpios,
57 enum mctrl_gpio_idx gidx);
58
59/*
60 * Request and set direction of modem control line GPIOs and set up irq
61 * handling.
62 * devm_* functions are used, so there's no need to call mctrl_gpio_free().
63 * Returns a pointer to the allocated mctrl structure if ok, -ENOMEM on
64 * allocation error.
65 */
66struct mctrl_gpios *mctrl_gpio_init(struct uart_port *port, unsigned int idx);
67
68/*
69 * Request and set direction of modem control line GPIOs.
70 * devm_* functions are used, so there's no need to call mctrl_gpio_free().
71 * Returns a pointer to the allocated mctrl structure if ok, -ENOMEM on
72 * allocation error.
73 */
74struct mctrl_gpios *mctrl_gpio_init_noauto(struct device *dev,
75 unsigned int idx);
76
77/*
78 * Free the mctrl_gpios structure.
79 * Normally, this function will not be called, as the GPIOs will
80 * be disposed of by the resource management code.
81 */
82void mctrl_gpio_free(struct device *dev, struct mctrl_gpios *gpios);
83
84/*
85 * Enable gpio interrupts to report status line changes.
86 */
87void mctrl_gpio_enable_ms(struct mctrl_gpios *gpios);
88
89/*
90 * Disable gpio interrupts to report status line changes.
91 */
92void mctrl_gpio_disable_ms(struct mctrl_gpios *gpios);
93
94/*
95 * Enable gpio wakeup interrupts to enable wake up source.
96 */
97void mctrl_gpio_enable_irq_wake(struct mctrl_gpios *gpios);
98
99/*
100 * Disable gpio wakeup interrupts to enable wake up source.
101 */
102void mctrl_gpio_disable_irq_wake(struct mctrl_gpios *gpios);
103
104#else /* GPIOLIB */
105
106static inline
107void mctrl_gpio_set(struct mctrl_gpios *gpios, unsigned int mctrl)
108{
109}
110
111static inline
112unsigned int mctrl_gpio_get(struct mctrl_gpios *gpios, unsigned int *mctrl)
113{
114 return *mctrl;
115}
116
117static inline unsigned int
118mctrl_gpio_get_outputs(struct mctrl_gpios *gpios, unsigned int *mctrl)
119{
120 return *mctrl;
121}
122
123static inline
124struct gpio_desc *mctrl_gpio_to_gpiod(struct mctrl_gpios *gpios,
125 enum mctrl_gpio_idx gidx)
126{
127 return NULL;
128}
129
130static inline
131struct mctrl_gpios *mctrl_gpio_init(struct uart_port *port, unsigned int idx)
132{
133 return NULL;
134}
135
136static inline
137struct mctrl_gpios *mctrl_gpio_init_noauto(struct device *dev, unsigned int idx)
138{
139 return NULL;
140}
141
142static inline
143void mctrl_gpio_free(struct device *dev, struct mctrl_gpios *gpios)
144{
145}
146
147static inline void mctrl_gpio_enable_ms(struct mctrl_gpios *gpios)
148{
149}
150
151static inline void mctrl_gpio_disable_ms(struct mctrl_gpios *gpios)
152{
153}
154
155static inline void mctrl_gpio_enable_irq_wake(struct mctrl_gpios *gpios)
156{
157}
158
159static inline void mctrl_gpio_disable_irq_wake(struct mctrl_gpios *gpios)
160{
161}
162
163#endif /* GPIOLIB */
164
165#endif
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
18#ifndef __SERIAL_MCTRL_GPIO__
19#define __SERIAL_MCTRL_GPIO__
20
21#include <linux/err.h>
22#include <linux/device.h>
23#include <linux/gpio/consumer.h>
24
25struct uart_port;
26
27enum 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,
38};
39
40/*
41 * Opaque descriptor for modem lines controlled by GPIOs
42 */
43struct mctrl_gpios;
44
45#ifdef CONFIG_GPIOLIB
46
47/*
48 * Set state of the modem control output lines via GPIOs.
49 */
50void mctrl_gpio_set(struct mctrl_gpios *gpios, unsigned int mctrl);
51
52/*
53 * Get state of the modem control output lines from GPIOs.
54 * The mctrl flags are updated and returned.
55 */
56unsigned int mctrl_gpio_get(struct mctrl_gpios *gpios, unsigned int *mctrl);
57
58/*
59 * Returns the associated struct gpio_desc to the modem line gidx
60 */
61struct gpio_desc *mctrl_gpio_to_gpiod(struct mctrl_gpios *gpios,
62 enum mctrl_gpio_idx gidx);
63
64/*
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.
70 */
71struct mctrl_gpios *mctrl_gpio_init(struct uart_port *port, unsigned int idx);
72
73/*
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.
78 */
79struct mctrl_gpios *mctrl_gpio_init_noauto(struct device *dev,
80 unsigned int idx);
81
82/*
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.
86 */
87void mctrl_gpio_free(struct device *dev, struct mctrl_gpios *gpios);
88
89/*
90 * Enable gpio interrupts to report status line changes.
91 */
92void mctrl_gpio_enable_ms(struct mctrl_gpios *gpios);
93
94/*
95 * Disable gpio interrupts to report status line changes.
96 */
97void mctrl_gpio_disable_ms(struct mctrl_gpios *gpios);
98
99#else /* GPIOLIB */
100
101static inline
102void mctrl_gpio_set(struct mctrl_gpios *gpios, unsigned int mctrl)
103{
104}
105
106static inline
107unsigned int mctrl_gpio_get(struct mctrl_gpios *gpios, unsigned int *mctrl)
108{
109 return *mctrl;
110}
111
112static inline
113struct gpio_desc *mctrl_gpio_to_gpiod(struct mctrl_gpios *gpios,
114 enum mctrl_gpio_idx gidx)
115{
116 return ERR_PTR(-ENOSYS);
117}
118
119static inline
120struct mctrl_gpios *mctrl_gpio_init(struct uart_port *port, unsigned int idx)
121{
122 return ERR_PTR(-ENOSYS);
123}
124
125static inline
126struct mctrl_gpios *mctrl_gpio_init_noauto(struct device *dev, unsigned int idx)
127{
128 return ERR_PTR(-ENOSYS);
129}
130
131static inline
132void mctrl_gpio_free(struct device *dev, struct mctrl_gpios *gpios)
133{
134}
135
136static inline void mctrl_gpio_enable_ms(struct mctrl_gpios *gpios)
137{
138}
139
140static inline void mctrl_gpio_disable_ms(struct mctrl_gpios *gpios)
141{
142}
143
144#endif /* GPIOLIB */
145
146#endif