linux-serial.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Stefan Roese <sr@denx.de>
Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org,
	Yegor Yefremov <yegorslists@googlemail.com>,
	Mika Westerberg <mika.westerberg@linux.intel.com>,
	Giulio Benetti <giulio.benetti@micronovasrl.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Subject: Re: [PATCH 2/2 v5] tty/serial/8250: use mctrl_gpio helpers
Date: Wed, 12 Jun 2019 12:16:21 +0300	[thread overview]
Message-ID: <20190612091621.GA9224@smile.fi.intel.com> (raw)
In-Reply-To: <12e5180e-b4a0-e5fa-bcad-ddc8103d644c@denx.de>

On Wed, Jun 12, 2019 at 10:13:05AM +0200, Stefan Roese wrote:
> On 11.06.19 16:48, Andy Shevchenko wrote:
> > On Tue, Jun 11, 2019 at 04:02:54PM +0200, Stefan Roese wrote:
> > > On 11.06.19 14:44, Andy Shevchenko wrote:
> > > > On Tue, Jun 11, 2019 at 12:56:03PM +0200, Stefan Roese wrote:
> > 
> > > > >    static inline void serial8250_out_MCR(struct uart_8250_port *up, int value)
> > > > >    {
> > > > >    	serial_out(up, UART_MCR, value);
> > > > > +
> > > > > +	if (up->gpios) {
> > > > > +		int mctrl_gpio = 0;
> > > > > +
> > > > > +		if (value & UART_MCR_RTS)
> > > > > +			mctrl_gpio |= TIOCM_RTS;
> > > > > +		if (value & UART_MCR_DTR)
> > > > > +			mctrl_gpio |= TIOCM_DTR;
> > > > > +
> > > > > +		mctrl_gpio_set(up->gpios, mctrl_gpio);
> > > > > +	}
> > > > >    }
> > 
> > > > >    static inline int serial8250_in_MCR(struct uart_8250_port *up)
> > > > >    {
> > > > > -	return serial_in(up, UART_MCR);
> > > > > +	int mctrl;
> > > > > +
> > > > > +	mctrl = serial_in(up, UART_MCR);
> > > > > +
> > > > > +	if (up->gpios) {
> > > > > +		int mctrl_gpio = 0;
> > > > > +
> > > > > +		/* save current MCR values */
> > > > > +		if (mctrl & UART_MCR_RTS)
> > > > > +			mctrl_gpio |= TIOCM_RTS;
> > > > > +		if (mctrl & UART_MCR_DTR)
> > > > > +			mctrl_gpio |= TIOCM_DTR;
> > > > > +
> > > > > +		mctrl_gpio = mctrl_gpio_get_outputs(up->gpios, &mctrl_gpio);
> > > > > +		if (mctrl_gpio & TIOCM_RTS)
> > > > > +			mctrl |= UART_MCR_RTS;
> > > > > +		else
> > > > > +			mctrl &= ~UART_MCR_RTS;
> > > > > +
> > > > > +		if (mctrl_gpio & TIOCM_DTR)
> > > > > +			mctrl |= UART_MCR_DTR;
> > > > > +		else
> > > > > +			mctrl &= ~UART_MCR_DTR;
> > > > > +	}
> > > > > +
> > > > > +	return mctrl;
> > > > >    }
> > > > 
> > > > These are using OR logic with potentially volatile data. Shouldn't we mask
> > > > unused bits in UART_MCR in case of up->gpios != NULL?
> > > 
> > > Sorry, I don't see, which bits you are referring to? Could you please be
> > > a bit more specific with the variable / macro meant (example)?
> > 
> > I meant that we double write values in the out() which might have some
> > consequences, though I hope nothing wrong with it happens.
> 
> Where is the double write to a register? Sorry, I fail to spot it.

Not to the one register. From the functional point of view the same signal is
set up twice: once per UART register, once per GPIO pins.

> > In the in() we read the all bits in the register.
> > 
> > As now I look at the implementation of mctrl_gpio_get_outputs(),
> > I think we rather get helpers for conversion between TIOCM and UART_MCR values,
> > so, they can be used in get_mctrl() / set_mctrl() and above.
> 
> Do you something like this in mind?

More likely

static inline int serial8250_MCR_to_TIOCM(int mcr)
{
	int tiocm = 0;

	if (mcr & ...)
		tiocm |= ...;
	...

	return tiocm;
}

static inline int serial8250_TIOCM_to_MCR(int tiocm)
{
	... in a similar way ...
}

> Plus the use of these macros in this patch of course.

No macros, please.

-- 
With Best Regards,
Andy Shevchenko

  reply	other threads:[~2019-06-12  9:16 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-11 10:56 [PATCH 1/2 v5] serial: mctrl_gpio: Check if GPIO property exisits before requesting it Stefan Roese
2019-06-11 10:56 ` [PATCH 2/2 v5] tty/serial/8250: use mctrl_gpio helpers Stefan Roese
2019-06-11 12:44   ` Andy Shevchenko
2019-06-11 14:02     ` Stefan Roese
2019-06-11 14:48       ` Andy Shevchenko
2019-06-12  8:13         ` Stefan Roese
2019-06-12  9:16           ` Andy Shevchenko [this message]
2019-06-13  5:32             ` Stefan Roese
2019-06-13 11:05               ` Andy Shevchenko
2019-06-18  7:49   ` Greg Kroah-Hartman

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=20190612091621.GA9224@smile.fi.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=giulio.benetti@micronovasrl.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=mika.westerberg@linux.intel.com \
    --cc=sr@denx.de \
    --cc=yegorslists@googlemail.com \
    /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).