1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * Helpers for controlling modem lines via GPIO
5 * Copyright (C) 2014 Paratronic S.A.
8 #ifndef __SERIAL_MCTRL_GPIO__
9 #define __SERIAL_MCTRL_GPIO__
11 #include <linux/err.h>
12 #include <linux/device.h>
13 #include <linux/gpio/consumer.h>
22 UART_GPIO_RI
= UART_GPIO_RNG
,
29 * Opaque descriptor for modem lines controlled by GPIOs
36 * Set state of the modem control output lines via GPIOs.
38 void mctrl_gpio_set(struct mctrl_gpios
*gpios
, unsigned int mctrl
);
41 * Get state of the modem control input lines from GPIOs.
42 * The mctrl flags are updated and returned.
44 unsigned int mctrl_gpio_get(struct mctrl_gpios
*gpios
, unsigned int *mctrl
);
47 * Get state of the modem control output lines from GPIOs.
48 * The mctrl flags are updated and returned.
51 mctrl_gpio_get_outputs(struct mctrl_gpios
*gpios
, unsigned int *mctrl
);
54 * Returns the associated struct gpio_desc to the modem line gidx
56 struct gpio_desc
*mctrl_gpio_to_gpiod(struct mctrl_gpios
*gpios
,
57 enum mctrl_gpio_idx gidx
);
60 * Request and set direction of modem control line GPIOs and set up irq
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
66 struct mctrl_gpios
*mctrl_gpio_init(struct uart_port
*port
, unsigned int idx
);
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
74 struct mctrl_gpios
*mctrl_gpio_init_noauto(struct device
*dev
,
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.
82 void mctrl_gpio_free(struct device
*dev
, struct mctrl_gpios
*gpios
);
85 * Enable gpio interrupts to report status line changes.
87 void mctrl_gpio_enable_ms(struct mctrl_gpios
*gpios
);
90 * Disable gpio interrupts to report status line changes.
92 void mctrl_gpio_disable_ms(struct mctrl_gpios
*gpios
);
97 void mctrl_gpio_set(struct mctrl_gpios
*gpios
, unsigned int mctrl
)
102 unsigned int mctrl_gpio_get(struct mctrl_gpios
*gpios
, unsigned int *mctrl
)
107 static inline unsigned int
108 mctrl_gpio_get_outputs(struct mctrl_gpios
*gpios
, unsigned int *mctrl
)
114 struct gpio_desc
*mctrl_gpio_to_gpiod(struct mctrl_gpios
*gpios
,
115 enum mctrl_gpio_idx gidx
)
121 struct mctrl_gpios
*mctrl_gpio_init(struct uart_port
*port
, unsigned int idx
)
127 struct mctrl_gpios
*mctrl_gpio_init_noauto(struct device
*dev
, unsigned int idx
)
133 void mctrl_gpio_free(struct device
*dev
, struct mctrl_gpios
*gpios
)
137 static inline void mctrl_gpio_enable_ms(struct mctrl_gpios
*gpios
)
141 static inline void mctrl_gpio_disable_ms(struct mctrl_gpios
*gpios
)