linux-omap.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH v6 1/3] tty/serial: Add GPIOLIB helpers for controlling modem lines
       [not found] ` <1394469951-21192-2-git-send-email-richard.genoud@gmail.com>
@ 2014-04-22 13:08   ` Yegor Yefremov
  2014-04-25 14:56     ` Richard Genoud
  0 siblings, 1 reply; 3+ messages in thread
From: Yegor Yefremov @ 2014-04-22 13:08 UTC (permalink / raw)
  To: Richard Genoud, Greg Kroah-Hartman
  Cc: Alexander Shiyan, Richard Genoud, Linus Walleij, Nicolas Ferre,
	linux-serial, Uwe Kleine-König, linux-arm-kernel,
	linux-omap@vger.kernel.org, mpfj-list, balbi

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v6 1/3] tty/serial: Add GPIOLIB helpers for controlling modem lines
  2014-04-22 13:08   ` [PATCH v6 1/3] tty/serial: Add GPIOLIB helpers for controlling modem lines Yegor Yefremov
@ 2014-04-25 14:56     ` Richard Genoud
  2014-04-25 18:37       ` Yegor Yefremov
  0 siblings, 1 reply; 3+ messages in thread
From: Richard Genoud @ 2014-04-25 14:56 UTC (permalink / raw)
  To: yegor_sub1
  Cc: Richard Genoud, Greg Kroah-Hartman, Alexander Shiyan,
	Linus Walleij, Nicolas Ferre, linux-serial@vger.kernel.org,
	Uwe Kleine-König, linux-arm-kernel@lists.infradead.org,
	linux-omap@vger.kernel.org, mpfj-list, Felipe Balbi

2014-04-22 15:08 GMT+02:00 Yegor Yefremov <yegor_sub1@visionsystems.de>:
> 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?
Sorry, but I don't really get what you're trying to do.
Could you explain a little bit more ?

Richard.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v6 1/3] tty/serial: Add GPIOLIB helpers for controlling modem lines
  2014-04-25 14:56     ` Richard Genoud
@ 2014-04-25 18:37       ` Yegor Yefremov
  0 siblings, 0 replies; 3+ messages in thread
From: Yegor Yefremov @ 2014-04-25 18:37 UTC (permalink / raw)
  To: Richard Genoud
  Cc: Yegor Yefremov, Richard Genoud, Greg Kroah-Hartman,
	Alexander Shiyan, Linus Walleij, Nicolas Ferre,
	linux-serial@vger.kernel.org, Uwe Kleine-König,
	linux-arm-kernel@lists.infradead.org, linux-omap@vger.kernel.org,
	mpfj-list, Felipe Balbi

On Fri, Apr 25, 2014 at 4:56 PM, Richard Genoud
<richard.genoud@gmail.com> wrote:
> 2014-04-22 15:08 GMT+02:00 Yegor Yefremov <yegor_sub1@visionsystems.de>:
>> 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?
> Sorry, but I don't really get what you're trying to do.
> Could you explain a little bit more ?

Never mind, I've solved this in this patch:
http://www.spinics.net/lists/arm-kernel/msg325197.html via using

gpiod_set_value() and gpiod_get_value() directly.


Yegor

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-04-25 18:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <1394469951-21192-1-git-send-email-richard.genoud@gmail.com>
     [not found] ` <1394469951-21192-2-git-send-email-richard.genoud@gmail.com>
2014-04-22 13:08   ` [PATCH v6 1/3] tty/serial: Add GPIOLIB helpers for controlling modem lines Yegor Yefremov
2014-04-25 14:56     ` Richard Genoud
2014-04-25 18:37       ` Yegor Yefremov

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).