Merge tag 'block-5.11-2021-01-24' of git://git.kernel.dk/linux-block
[linux-block.git] / drivers / tty / serial / serial_mctrl_gpio.h
CommitLineData
4f5f5887 1/* SPDX-License-Identifier: GPL-2.0+ */
84130aac
RG
2/*
3 * Helpers for controlling modem lines via GPIO
4 *
5 * Copyright (C) 2014 Paratronic S.A.
84130aac
RG
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
ce59e48f
UKK
15struct uart_port;
16
84130aac
RG
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,
84130aac
RG
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/*
bf5cee68 41 * Get state of the modem control input lines from GPIOs.
84130aac
RG
42 * The mctrl flags are updated and returned.
43 */
44unsigned int mctrl_gpio_get(struct mctrl_gpios *gpios, unsigned int *mctrl);
45
bf5cee68
YY
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
84130aac
RG
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
ce59e48f 59/*
03e970bb 60 * Request and set direction of modem control line GPIOs and set up irq
ce59e48f
UKK
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
84130aac 68/*
03e970bb 69 * Request and set direction of modem control line GPIOs.
84130aac
RG
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 */
7d8c70d8
UKK
74struct mctrl_gpios *mctrl_gpio_init_noauto(struct device *dev,
75 unsigned int idx);
84130aac
RG
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
ce59e48f
UKK
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
84130aac
RG
94#else /* GPIOLIB */
95
96static inline
97void mctrl_gpio_set(struct mctrl_gpios *gpios, unsigned int mctrl)
98{
99}
100
101static inline
102unsigned int mctrl_gpio_get(struct mctrl_gpios *gpios, unsigned int *mctrl)
103{
104 return *mctrl;
105}
106
bf5cee68
YY
107static inline unsigned int
108mctrl_gpio_get_outputs(struct mctrl_gpios *gpios, unsigned int *mctrl)
109{
110 return *mctrl;
111}
112
84130aac
RG
113static inline
114struct gpio_desc *mctrl_gpio_to_gpiod(struct mctrl_gpios *gpios,
115 enum mctrl_gpio_idx gidx)
116{
e8b2a618 117 return NULL;
84130aac
RG
118}
119
ce59e48f
UKK
120static inline
121struct mctrl_gpios *mctrl_gpio_init(struct uart_port *port, unsigned int idx)
122{
e8b2a618 123 return NULL;
ce59e48f
UKK
124}
125
84130aac 126static inline
7d8c70d8 127struct mctrl_gpios *mctrl_gpio_init_noauto(struct device *dev, unsigned int idx)
84130aac 128{
e8b2a618 129 return NULL;
84130aac
RG
130}
131
132static inline
133void mctrl_gpio_free(struct device *dev, struct mctrl_gpios *gpios)
134{
135}
136
1b306f99 137static inline void mctrl_gpio_enable_ms(struct mctrl_gpios *gpios)
ce59e48f
UKK
138{
139}
140
1b306f99 141static inline void mctrl_gpio_disable_ms(struct mctrl_gpios *gpios)
ce59e48f
UKK
142{
143}
144
84130aac
RG
145#endif /* GPIOLIB */
146
147#endif