From: yegor_sub1@visionsystems.de (Yegor Yefremov)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v6 1/3] tty/serial: Add GPIOLIB helpers for controlling modem lines
Date: Tue, 22 Apr 2014 15:08:43 +0200 [thread overview]
Message-ID: <535669DB.8010109@visionsystems.de> (raw)
In-Reply-To: <1394469951-21192-2-git-send-email-richard.genoud@gmail.com>
On 10.03.2014 17:45, 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>
....
> +
> +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);
Should this routine be renamed to msr_gpio_get() or perhaps better to give all values (inputs and outputs)?
I'm trying to port this approach to omap-serial to implement RS485 switching. I need to know if RTS is already on or not and set it accordingly.
What would be the best solution for this task using this new API?
Yegor
next prev parent reply other threads:[~2014-04-22 13:08 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-10 16:45 [PATCH v6 0/3] tty/serial: Add helpers to use GPIOs to control modem lines and implement atmel_serial.c Richard Genoud
2014-03-10 16:45 ` [PATCH v6 1/3] tty/serial: Add GPIOLIB helpers for controlling modem lines Richard Genoud
2014-03-17 23:23 ` Greg Kroah-Hartman
2014-03-18 10:13 ` Richard Genoud
2014-03-22 10:14 ` Richard Genoud
2014-04-02 15:09 ` Richard Genoud
2014-04-02 23:13 ` Greg Kroah-Hartman
2014-04-03 9:35 ` Richard Genoud
2014-04-22 13:08 ` Yegor Yefremov [this message]
2014-04-25 14:56 ` Richard Genoud
2014-04-25 18:37 ` Yegor Yefremov
2014-03-10 16:45 ` [PATCH v6 2/3] tty/serial: at91: use mctrl_gpio helpers Richard Genoud
2014-03-10 17:20 ` Nicolas Ferre
2014-03-10 16:45 ` [PATCH v6 3/3] tty/serial: at91: add interrupts for modem control lines Richard Genoud
2014-03-10 17:21 ` Nicolas Ferre
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=535669DB.8010109@visionsystems.de \
--to=yegor_sub1@visionsystems.de \
--cc=linux-arm-kernel@lists.infradead.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).