From: Yegor Yefremov <yegor_sub1@visionsystems.de>
To: Richard Genoud <richard.genoud@gmail.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Nicolas Ferre <nicolas.ferre@atmel.com>,
Linus Walleij <linus.walleij@linaro.org>,
Alexander Shiyan <shc_work@mail.ru>,
linux-serial@vger.kernel.org,
linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH RESEND 3/5] tty/serial: Add GPIOLIB helpers for controlling modem lines
Date: Tue, 20 May 2014 11:26:07 +0200 [thread overview]
Message-ID: <537B1FAF.9080706@visionsystems.de> (raw)
In-Reply-To: <1400005245-11943-4-git-send-email-richard.genoud@gmail.com>
On 13.05.2014 20:20, Richard Genoud wrote:
> This patch add some helpers to control modem lines (CTS/RTS/DSR...) via
> GPIO.
> This will be useful for many boards which have a serial controller that
> only handle CTS/RTS pins (or even just RX/TX).
>
> Signed-off-by: Richard Genoud <richard.genoud@gmail.com>
> Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Tested-by: Yegor Yefremov <yegorslists@googlemail.com>
> ---
> Documentation/serial/driver | 25 ++++++
> drivers/tty/serial/Kconfig | 3 +
> drivers/tty/serial/Makefile | 3 +
> drivers/tty/serial/serial_mctrl_gpio.c | 143 ++++++++++++++++++++++++++++++++
> drivers/tty/serial/serial_mctrl_gpio.h | 110 ++++++++++++++++++++++++
> 5 files changed, 284 insertions(+)
> create mode 100644 drivers/tty/serial/serial_mctrl_gpio.c
> create mode 100644 drivers/tty/serial/serial_mctrl_gpio.h
>
> diff --git a/Documentation/serial/driver b/Documentation/serial/driver
> index c3a7689..3bba1ae 100644
> --- a/Documentation/serial/driver
> +++ b/Documentation/serial/driver
> @@ -429,3 +429,28 @@ thus:
> struct uart_port port;
> int my_stuff;
> };
> +
> +Modem control lines via GPIO
> +----------------------------
> +
> +Some helpers are provided in order to set/get modem control lines via GPIO.
> +
> +mctrl_gpio_init(dev, idx):
> + This will get the {cts,rts,...}-gpios from device tree if they are
> + present and request them, set direction etc, and return an
> + allocated structure. devm_* functions are used, so there's no need
> + to call mctrl_gpio_free().
> +
> +mctrl_gpio_free(dev, gpios):
> + This will free the requested gpios in mctrl_gpio_init().
> + As devm_* function are used, there's generally no need to call
> + this function.
> +
> +mctrl_gpio_to_gpiod(gpios, gidx)
> + This returns the gpio structure associated to the modem line index.
> +
> +mctrl_gpio_set(gpios, mctrl):
> + This will sets the gpios according to the mctrl state.
> +
> +mctrl_gpio_get(gpios, mctrl):
> + This will update mctrl with the gpios values.
> diff --git a/drivers/tty/serial/Kconfig b/drivers/tty/serial/Kconfig
> index 5d9b01a..95afd31 100644
> --- a/drivers/tty/serial/Kconfig
> +++ b/drivers/tty/serial/Kconfig
> @@ -1510,4 +1510,7 @@ config SERIAL_ST_ASC_CONSOLE
>
> endmenu
>
> +config SERIAL_MCTRL_GPIO
> + tristate
> +
> endif # TTY
> diff --git a/drivers/tty/serial/Makefile b/drivers/tty/serial/Makefile
> index 3680854..bcf31da 100644
> --- a/drivers/tty/serial/Makefile
> +++ b/drivers/tty/serial/Makefile
> @@ -87,3 +87,6 @@ obj-$(CONFIG_SERIAL_EFM32_UART) += efm32-uart.o
> obj-$(CONFIG_SERIAL_ARC) += arc_uart.o
> obj-$(CONFIG_SERIAL_RP2) += rp2.o
> obj-$(CONFIG_SERIAL_FSL_LPUART) += fsl_lpuart.o
> +
> +# GPIOLIB helpers for modem control lines
> +obj-$(CONFIG_SERIAL_MCTRL_GPIO) += serial_mctrl_gpio.o
> diff --git a/drivers/tty/serial/serial_mctrl_gpio.c b/drivers/tty/serial/serial_mctrl_gpio.c
> new file mode 100644
> index 0000000..bf9560f
> --- /dev/null
> +++ b/drivers/tty/serial/serial_mctrl_gpio.c
> @@ -0,0 +1,143 @@
> +/*
> + * Helpers for controlling modem lines via GPIO
> + *
> + * Copyright (C) 2014 Paratronic S.A.
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; either version 2 of the License, or
> + * (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + *
> + */
> +
> +#include <linux/err.h>
> +#include <linux/device.h>
> +#include <linux/gpio/consumer.h>
> +#include <uapi/asm-generic/termios.h>
> +
> +#include "serial_mctrl_gpio.h"
> +
> +struct mctrl_gpios {
> + struct gpio_desc *gpio[UART_GPIO_MAX];
> +};
> +
> +static const struct {
> + const char *name;
> + unsigned int mctrl;
> + bool dir_out;
> +} mctrl_gpios_desc[UART_GPIO_MAX] = {
> + { "cts", TIOCM_CTS, false, },
> + { "dsr", TIOCM_DSR, false, },
> + { "dcd", TIOCM_CD, false, },
> + { "rng", TIOCM_RNG, false, },
> + { "rts", TIOCM_RTS, true, },
> + { "dtr", TIOCM_DTR, true, },
> + { "out1", TIOCM_OUT1, true, },
> + { "out2", TIOCM_OUT2, true, },
> +};
> +
> +void mctrl_gpio_set(struct mctrl_gpios *gpios, unsigned int mctrl)
> +{
> + enum mctrl_gpio_idx i;
> +
> + if (IS_ERR_OR_NULL(gpios))
> + return;
> +
> + for (i = 0; i < UART_GPIO_MAX; i++)
> + if (!IS_ERR_OR_NULL(gpios->gpio[i]) &&
> + mctrl_gpios_desc[i].dir_out)
> + gpiod_set_value(gpios->gpio[i],
> + !!(mctrl & mctrl_gpios_desc[i].mctrl));
> +}
> +EXPORT_SYMBOL_GPL(mctrl_gpio_set);
> +
> +struct gpio_desc *mctrl_gpio_to_gpiod(struct mctrl_gpios *gpios,
> + enum mctrl_gpio_idx gidx)
> +{
> + if (!IS_ERR_OR_NULL(gpios) && !IS_ERR_OR_NULL(gpios->gpio[gidx]))
> + return gpios->gpio[gidx];
> + else
> + return NULL;
> +}
> +EXPORT_SYMBOL_GPL(mctrl_gpio_to_gpiod);
> +
> +unsigned int mctrl_gpio_get(struct mctrl_gpios *gpios, unsigned int *mctrl)
> +{
> + enum mctrl_gpio_idx i;
> +
> + /*
> + * return it unchanged if the structure is not allocated
> + */
> + if (IS_ERR_OR_NULL(gpios))
> + return *mctrl;
> +
> + for (i = 0; i < UART_GPIO_MAX; i++) {
> + if (!IS_ERR_OR_NULL(gpios->gpio[i]) &&
> + !mctrl_gpios_desc[i].dir_out) {
> + if (gpiod_get_value(gpios->gpio[i]))
> + *mctrl |= mctrl_gpios_desc[i].mctrl;
> + else
> + *mctrl &= ~mctrl_gpios_desc[i].mctrl;
> + }
> + }
> +
> + return *mctrl;
> +}
> +EXPORT_SYMBOL_GPL(mctrl_gpio_get);
> +
> +struct mctrl_gpios *mctrl_gpio_init(struct device *dev, unsigned int idx)
> +{
> + struct mctrl_gpios *gpios;
> + enum mctrl_gpio_idx i;
> + int err;
> +
> + gpios = devm_kzalloc(dev, sizeof(*gpios), GFP_KERNEL);
> + if (!gpios)
> + return ERR_PTR(-ENOMEM);
> +
> + for (i = 0; i < UART_GPIO_MAX; i++) {
> + gpios->gpio[i] = devm_gpiod_get_index(dev,
> + mctrl_gpios_desc[i].name,
> + idx);
> +
> + /*
> + * The GPIOs are maybe not all filled,
> + * this is not an error.
> + */
> + if (IS_ERR_OR_NULL(gpios->gpio[i]))
> + continue;
> +
> + if (mctrl_gpios_desc[i].dir_out)
> + err = gpiod_direction_output(gpios->gpio[i], 0);
> + else
> + err = gpiod_direction_input(gpios->gpio[i]);
> + if (err) {
> + dev_dbg(dev, "Unable to set direction for %s GPIO",
> + mctrl_gpios_desc[i].name);
> + devm_gpiod_put(dev, gpios->gpio[i]);
> + gpios->gpio[i] = NULL;
> + }
> + }
> +
> + return gpios;
> +}
> +EXPORT_SYMBOL_GPL(mctrl_gpio_init);
> +
> +void mctrl_gpio_free(struct device *dev, struct mctrl_gpios *gpios)
> +{
> + enum mctrl_gpio_idx i;
> +
> + if (IS_ERR_OR_NULL(gpios))
> + return;
> +
> + for (i = 0; i < UART_GPIO_MAX; i++)
> + if (!IS_ERR_OR_NULL(gpios->gpio[i]))
> + devm_gpiod_put(dev, gpios->gpio[i]);
> + devm_kfree(dev, gpios);
> +}
> +EXPORT_SYMBOL_GPL(mctrl_gpio_free);
> diff --git a/drivers/tty/serial/serial_mctrl_gpio.h b/drivers/tty/serial/serial_mctrl_gpio.h
> new file mode 100644
> index 0000000..400ba04
> --- /dev/null
> +++ b/drivers/tty/serial/serial_mctrl_gpio.h
> @@ -0,0 +1,110 @@
> +/*
> + * Helpers for controlling modem lines via GPIO
> + *
> + * Copyright (C) 2014 Paratronic S.A.
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; either version 2 of the License, or
> + * (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + *
> + */
> +
> +#ifndef __SERIAL_MCTRL_GPIO__
> +#define __SERIAL_MCTRL_GPIO__
> +
> +#include <linux/err.h>
> +#include <linux/device.h>
> +#include <linux/gpio/consumer.h>
> +
> +enum mctrl_gpio_idx {
> + UART_GPIO_CTS,
> + UART_GPIO_DSR,
> + UART_GPIO_DCD,
> + UART_GPIO_RNG,
> + UART_GPIO_RI = UART_GPIO_RNG,
> + UART_GPIO_RTS,
> + UART_GPIO_DTR,
> + UART_GPIO_OUT1,
> + UART_GPIO_OUT2,
> + UART_GPIO_MAX,
> +};
> +
> +/*
> + * Opaque descriptor for modem lines controlled by GPIOs
> + */
> +struct mctrl_gpios;
> +
> +#ifdef CONFIG_GPIOLIB
> +
> +/*
> + * Set state of the modem control output lines via GPIOs.
> + */
> +void mctrl_gpio_set(struct mctrl_gpios *gpios, unsigned int mctrl);
> +
> +/*
> + * Get state of the modem control output lines from GPIOs.
> + * The mctrl flags are updated and returned.
> + */
> +unsigned int mctrl_gpio_get(struct mctrl_gpios *gpios, unsigned int *mctrl);
> +
> +/*
> + * Returns the associated struct gpio_desc to the modem line gidx
> + */
> +struct gpio_desc *mctrl_gpio_to_gpiod(struct mctrl_gpios *gpios,
> + enum mctrl_gpio_idx gidx);
> +
> +/*
> + * Request and set direction of modem control lines GPIOs.
> + * devm_* functions are used, so there's no need to call mctrl_gpio_free().
> + * Returns a pointer to the allocated mctrl structure if ok, -ENOMEM on
> + * allocation error.
> + */
> +struct mctrl_gpios *mctrl_gpio_init(struct device *dev, unsigned int idx);
> +
> +/*
> + * Free the mctrl_gpios structure.
> + * Normally, this function will not be called, as the GPIOs will
> + * be disposed of by the resource management code.
> + */
> +void mctrl_gpio_free(struct device *dev, struct mctrl_gpios *gpios);
> +
> +#else /* GPIOLIB */
> +
> +static inline
> +void mctrl_gpio_set(struct mctrl_gpios *gpios, unsigned int mctrl)
> +{
> +}
> +
> +static inline
> +unsigned int mctrl_gpio_get(struct mctrl_gpios *gpios, unsigned int *mctrl)
> +{
> + return *mctrl;
> +}
> +
> +static inline
> +struct gpio_desc *mctrl_gpio_to_gpiod(struct mctrl_gpios *gpios,
> + enum mctrl_gpio_idx gidx)
> +{
> + return ERR_PTR(-ENOSYS);
> +}
> +
> +static inline
> +struct mctrl_gpios *mctrl_gpio_init(struct device *dev, unsigned int idx)
> +{
> + return ERR_PTR(-ENOSYS);
> +}
> +
> +static inline
> +void mctrl_gpio_free(struct device *dev, struct mctrl_gpios *gpios)
> +{
> +}
> +
> +#endif /* GPIOLIB */
> +
> +#endif
WARNING: multiple messages have this Message-ID (diff)
From: yegor_sub1@visionsystems.de (Yegor Yefremov)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH RESEND 3/5] tty/serial: Add GPIOLIB helpers for controlling modem lines
Date: Tue, 20 May 2014 11:26:07 +0200 [thread overview]
Message-ID: <537B1FAF.9080706@visionsystems.de> (raw)
In-Reply-To: <1400005245-11943-4-git-send-email-richard.genoud@gmail.com>
On 13.05.2014 20:20, Richard Genoud wrote:
> This patch add some helpers to control modem lines (CTS/RTS/DSR...) via
> GPIO.
> This will be useful for many boards which have a serial controller that
> only handle CTS/RTS pins (or even just RX/TX).
>
> Signed-off-by: Richard Genoud <richard.genoud@gmail.com>
> Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Tested-by: Yegor Yefremov <yegorslists@googlemail.com>
> ---
> Documentation/serial/driver | 25 ++++++
> drivers/tty/serial/Kconfig | 3 +
> drivers/tty/serial/Makefile | 3 +
> drivers/tty/serial/serial_mctrl_gpio.c | 143 ++++++++++++++++++++++++++++++++
> drivers/tty/serial/serial_mctrl_gpio.h | 110 ++++++++++++++++++++++++
> 5 files changed, 284 insertions(+)
> create mode 100644 drivers/tty/serial/serial_mctrl_gpio.c
> create mode 100644 drivers/tty/serial/serial_mctrl_gpio.h
>
> diff --git a/Documentation/serial/driver b/Documentation/serial/driver
> index c3a7689..3bba1ae 100644
> --- a/Documentation/serial/driver
> +++ b/Documentation/serial/driver
> @@ -429,3 +429,28 @@ thus:
> struct uart_port port;
> int my_stuff;
> };
> +
> +Modem control lines via GPIO
> +----------------------------
> +
> +Some helpers are provided in order to set/get modem control lines via GPIO.
> +
> +mctrl_gpio_init(dev, idx):
> + This will get the {cts,rts,...}-gpios from device tree if they are
> + present and request them, set direction etc, and return an
> + allocated structure. devm_* functions are used, so there's no need
> + to call mctrl_gpio_free().
> +
> +mctrl_gpio_free(dev, gpios):
> + This will free the requested gpios in mctrl_gpio_init().
> + As devm_* function are used, there's generally no need to call
> + this function.
> +
> +mctrl_gpio_to_gpiod(gpios, gidx)
> + This returns the gpio structure associated to the modem line index.
> +
> +mctrl_gpio_set(gpios, mctrl):
> + This will sets the gpios according to the mctrl state.
> +
> +mctrl_gpio_get(gpios, mctrl):
> + This will update mctrl with the gpios values.
> diff --git a/drivers/tty/serial/Kconfig b/drivers/tty/serial/Kconfig
> index 5d9b01a..95afd31 100644
> --- a/drivers/tty/serial/Kconfig
> +++ b/drivers/tty/serial/Kconfig
> @@ -1510,4 +1510,7 @@ config SERIAL_ST_ASC_CONSOLE
>
> endmenu
>
> +config SERIAL_MCTRL_GPIO
> + tristate
> +
> endif # TTY
> diff --git a/drivers/tty/serial/Makefile b/drivers/tty/serial/Makefile
> index 3680854..bcf31da 100644
> --- a/drivers/tty/serial/Makefile
> +++ b/drivers/tty/serial/Makefile
> @@ -87,3 +87,6 @@ obj-$(CONFIG_SERIAL_EFM32_UART) += efm32-uart.o
> obj-$(CONFIG_SERIAL_ARC) += arc_uart.o
> obj-$(CONFIG_SERIAL_RP2) += rp2.o
> obj-$(CONFIG_SERIAL_FSL_LPUART) += fsl_lpuart.o
> +
> +# GPIOLIB helpers for modem control lines
> +obj-$(CONFIG_SERIAL_MCTRL_GPIO) += serial_mctrl_gpio.o
> diff --git a/drivers/tty/serial/serial_mctrl_gpio.c b/drivers/tty/serial/serial_mctrl_gpio.c
> new file mode 100644
> index 0000000..bf9560f
> --- /dev/null
> +++ b/drivers/tty/serial/serial_mctrl_gpio.c
> @@ -0,0 +1,143 @@
> +/*
> + * Helpers for controlling modem lines via GPIO
> + *
> + * Copyright (C) 2014 Paratronic S.A.
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; either version 2 of the License, or
> + * (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + *
> + */
> +
> +#include <linux/err.h>
> +#include <linux/device.h>
> +#include <linux/gpio/consumer.h>
> +#include <uapi/asm-generic/termios.h>
> +
> +#include "serial_mctrl_gpio.h"
> +
> +struct mctrl_gpios {
> + struct gpio_desc *gpio[UART_GPIO_MAX];
> +};
> +
> +static const struct {
> + const char *name;
> + unsigned int mctrl;
> + bool dir_out;
> +} mctrl_gpios_desc[UART_GPIO_MAX] = {
> + { "cts", TIOCM_CTS, false, },
> + { "dsr", TIOCM_DSR, false, },
> + { "dcd", TIOCM_CD, false, },
> + { "rng", TIOCM_RNG, false, },
> + { "rts", TIOCM_RTS, true, },
> + { "dtr", TIOCM_DTR, true, },
> + { "out1", TIOCM_OUT1, true, },
> + { "out2", TIOCM_OUT2, true, },
> +};
> +
> +void mctrl_gpio_set(struct mctrl_gpios *gpios, unsigned int mctrl)
> +{
> + enum mctrl_gpio_idx i;
> +
> + if (IS_ERR_OR_NULL(gpios))
> + return;
> +
> + for (i = 0; i < UART_GPIO_MAX; i++)
> + if (!IS_ERR_OR_NULL(gpios->gpio[i]) &&
> + mctrl_gpios_desc[i].dir_out)
> + gpiod_set_value(gpios->gpio[i],
> + !!(mctrl & mctrl_gpios_desc[i].mctrl));
> +}
> +EXPORT_SYMBOL_GPL(mctrl_gpio_set);
> +
> +struct gpio_desc *mctrl_gpio_to_gpiod(struct mctrl_gpios *gpios,
> + enum mctrl_gpio_idx gidx)
> +{
> + if (!IS_ERR_OR_NULL(gpios) && !IS_ERR_OR_NULL(gpios->gpio[gidx]))
> + return gpios->gpio[gidx];
> + else
> + return NULL;
> +}
> +EXPORT_SYMBOL_GPL(mctrl_gpio_to_gpiod);
> +
> +unsigned int mctrl_gpio_get(struct mctrl_gpios *gpios, unsigned int *mctrl)
> +{
> + enum mctrl_gpio_idx i;
> +
> + /*
> + * return it unchanged if the structure is not allocated
> + */
> + if (IS_ERR_OR_NULL(gpios))
> + return *mctrl;
> +
> + for (i = 0; i < UART_GPIO_MAX; i++) {
> + if (!IS_ERR_OR_NULL(gpios->gpio[i]) &&
> + !mctrl_gpios_desc[i].dir_out) {
> + if (gpiod_get_value(gpios->gpio[i]))
> + *mctrl |= mctrl_gpios_desc[i].mctrl;
> + else
> + *mctrl &= ~mctrl_gpios_desc[i].mctrl;
> + }
> + }
> +
> + return *mctrl;
> +}
> +EXPORT_SYMBOL_GPL(mctrl_gpio_get);
> +
> +struct mctrl_gpios *mctrl_gpio_init(struct device *dev, unsigned int idx)
> +{
> + struct mctrl_gpios *gpios;
> + enum mctrl_gpio_idx i;
> + int err;
> +
> + gpios = devm_kzalloc(dev, sizeof(*gpios), GFP_KERNEL);
> + if (!gpios)
> + return ERR_PTR(-ENOMEM);
> +
> + for (i = 0; i < UART_GPIO_MAX; i++) {
> + gpios->gpio[i] = devm_gpiod_get_index(dev,
> + mctrl_gpios_desc[i].name,
> + idx);
> +
> + /*
> + * The GPIOs are maybe not all filled,
> + * this is not an error.
> + */
> + if (IS_ERR_OR_NULL(gpios->gpio[i]))
> + continue;
> +
> + if (mctrl_gpios_desc[i].dir_out)
> + err = gpiod_direction_output(gpios->gpio[i], 0);
> + else
> + err = gpiod_direction_input(gpios->gpio[i]);
> + if (err) {
> + dev_dbg(dev, "Unable to set direction for %s GPIO",
> + mctrl_gpios_desc[i].name);
> + devm_gpiod_put(dev, gpios->gpio[i]);
> + gpios->gpio[i] = NULL;
> + }
> + }
> +
> + return gpios;
> +}
> +EXPORT_SYMBOL_GPL(mctrl_gpio_init);
> +
> +void mctrl_gpio_free(struct device *dev, struct mctrl_gpios *gpios)
> +{
> + enum mctrl_gpio_idx i;
> +
> + if (IS_ERR_OR_NULL(gpios))
> + return;
> +
> + for (i = 0; i < UART_GPIO_MAX; i++)
> + if (!IS_ERR_OR_NULL(gpios->gpio[i]))
> + devm_gpiod_put(dev, gpios->gpio[i]);
> + devm_kfree(dev, gpios);
> +}
> +EXPORT_SYMBOL_GPL(mctrl_gpio_free);
> diff --git a/drivers/tty/serial/serial_mctrl_gpio.h b/drivers/tty/serial/serial_mctrl_gpio.h
> new file mode 100644
> index 0000000..400ba04
> --- /dev/null
> +++ b/drivers/tty/serial/serial_mctrl_gpio.h
> @@ -0,0 +1,110 @@
> +/*
> + * Helpers for controlling modem lines via GPIO
> + *
> + * Copyright (C) 2014 Paratronic S.A.
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; either version 2 of the License, or
> + * (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + *
> + */
> +
> +#ifndef __SERIAL_MCTRL_GPIO__
> +#define __SERIAL_MCTRL_GPIO__
> +
> +#include <linux/err.h>
> +#include <linux/device.h>
> +#include <linux/gpio/consumer.h>
> +
> +enum mctrl_gpio_idx {
> + UART_GPIO_CTS,
> + UART_GPIO_DSR,
> + UART_GPIO_DCD,
> + UART_GPIO_RNG,
> + UART_GPIO_RI = UART_GPIO_RNG,
> + UART_GPIO_RTS,
> + UART_GPIO_DTR,
> + UART_GPIO_OUT1,
> + UART_GPIO_OUT2,
> + UART_GPIO_MAX,
> +};
> +
> +/*
> + * Opaque descriptor for modem lines controlled by GPIOs
> + */
> +struct mctrl_gpios;
> +
> +#ifdef CONFIG_GPIOLIB
> +
> +/*
> + * Set state of the modem control output lines via GPIOs.
> + */
> +void mctrl_gpio_set(struct mctrl_gpios *gpios, unsigned int mctrl);
> +
> +/*
> + * Get state of the modem control output lines from GPIOs.
> + * The mctrl flags are updated and returned.
> + */
> +unsigned int mctrl_gpio_get(struct mctrl_gpios *gpios, unsigned int *mctrl);
> +
> +/*
> + * Returns the associated struct gpio_desc to the modem line gidx
> + */
> +struct gpio_desc *mctrl_gpio_to_gpiod(struct mctrl_gpios *gpios,
> + enum mctrl_gpio_idx gidx);
> +
> +/*
> + * Request and set direction of modem control lines GPIOs.
> + * devm_* functions are used, so there's no need to call mctrl_gpio_free().
> + * Returns a pointer to the allocated mctrl structure if ok, -ENOMEM on
> + * allocation error.
> + */
> +struct mctrl_gpios *mctrl_gpio_init(struct device *dev, unsigned int idx);
> +
> +/*
> + * Free the mctrl_gpios structure.
> + * Normally, this function will not be called, as the GPIOs will
> + * be disposed of by the resource management code.
> + */
> +void mctrl_gpio_free(struct device *dev, struct mctrl_gpios *gpios);
> +
> +#else /* GPIOLIB */
> +
> +static inline
> +void mctrl_gpio_set(struct mctrl_gpios *gpios, unsigned int mctrl)
> +{
> +}
> +
> +static inline
> +unsigned int mctrl_gpio_get(struct mctrl_gpios *gpios, unsigned int *mctrl)
> +{
> + return *mctrl;
> +}
> +
> +static inline
> +struct gpio_desc *mctrl_gpio_to_gpiod(struct mctrl_gpios *gpios,
> + enum mctrl_gpio_idx gidx)
> +{
> + return ERR_PTR(-ENOSYS);
> +}
> +
> +static inline
> +struct mctrl_gpios *mctrl_gpio_init(struct device *dev, unsigned int idx)
> +{
> + return ERR_PTR(-ENOSYS);
> +}
> +
> +static inline
> +void mctrl_gpio_free(struct device *dev, struct mctrl_gpios *gpios)
> +{
> +}
> +
> +#endif /* GPIOLIB */
> +
> +#endif
next prev parent reply other threads:[~2014-05-20 9:26 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-13 18:20 [PATCH RESEND 0/5] tty/serial: Add helpers to use GPIOs to control modem lines and implement atmel_serial.c Richard Genoud
2014-05-13 18:20 ` Richard Genoud
2014-05-13 18:20 ` [PATCH RESEND 1/5] tty/serial: atmel_serial: Fix device tree documentation Richard Genoud
2014-05-13 18:20 ` Richard Genoud
2014-05-13 18:20 ` [PATCH RESEND 2/5] ARM: at91: gpio: implement get_direction Richard Genoud
2014-05-13 18:20 ` Richard Genoud
2014-05-13 18:20 ` [PATCH RESEND 3/5] tty/serial: Add GPIOLIB helpers for controlling modem lines Richard Genoud
2014-05-13 18:20 ` Richard Genoud
2014-05-20 9:26 ` Yegor Yefremov [this message]
2014-05-20 9:26 ` Yegor Yefremov
2014-05-28 19:45 ` Greg Kroah-Hartman
2014-05-28 19:45 ` Greg Kroah-Hartman
2014-05-28 19:47 ` Greg Kroah-Hartman
2014-05-28 19:47 ` Greg Kroah-Hartman
2014-05-13 18:20 ` [PATCH RESEND 4/5] tty/serial: at91: use mctrl_gpio helpers Richard Genoud
2014-05-13 18:20 ` Richard Genoud
2014-05-13 18:20 ` [PATCH RESEND 5/5] tty/serial: at91: add interrupts for modem control lines Richard Genoud
2014-05-13 18:20 ` Richard Genoud
2014-08-10 19:33 ` Peter Hurley
2014-08-10 19:33 ` Peter Hurley
2014-09-01 9:26 ` Richard Genoud
2014-09-01 9:26 ` Richard Genoud
2014-09-02 11:40 ` Peter Hurley
2014-09-02 11:40 ` Peter Hurley
2014-09-03 10:50 ` Richard Genoud
2014-09-03 10:50 ` Richard Genoud
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=537B1FAF.9080706@visionsystems.de \
--to=yegor_sub1@visionsystems.de \
--cc=gregkh@linuxfoundation.org \
--cc=linus.walleij@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-serial@vger.kernel.org \
--cc=nicolas.ferre@atmel.com \
--cc=richard.genoud@gmail.com \
--cc=shc_work@mail.ru \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.