linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Johan Hovold <johan@kernel.org>
To: Johanna Abrahamsson <johanna@mjao.org>
Cc: linux-usb@vger.kernel.org, johan@kernel.org, gregkh@linuxfoundation.org
Subject: USB: serial: cp210x: add minimun baud rate for CP2105 SCI
Date: Mon, 4 Feb 2019 17:01:29 +0100	[thread overview]
Message-ID: <20190204160129.GG4686@localhost> (raw)

On Mon, Feb 04, 2019 at 04:57:00PM +0100, Johan Hovold wrote:
> On Mon, Feb 04, 2019 at 12:21:30PM +0100, Johanna Abrahamsson wrote:
> > From: Johanna Abrahamsson <johanna.abrahamsson@afconsult.com>
> > 
> > This patch adds a minimum baud rate of 2400 for CP2105 SCI
> > 
> > According to the datasheet for CP2105, the SCI supports 2400 as the
> > lowest baud rate. As this is not heeded in the current code, an error
> > message 'failed set req 0x1e size 4 status: -32' when trying to set a
> > lower baud rate such as 300.
> 
> Good to hear to you found the root cause of that failed baudrate
> request.
> 
> > Since this is, as far as I can tell, the only cp210x chip with a minimum
> > baud rate higher than 300, I've added a special case to
> > cp210x_change_speed rather than adding a min_speed field in
> > cp210x_serial_private.
> 
> But please do add a min_speed field instead of special casing which
> tends to make the code harder to read.
> 
> > Signed-off-by: Johanna Abrahamsson <johanna.abrahamsson@afconsult.com>
> > ---
> >  drivers/usb/serial/cp210x.c | 7 +++++--
> >  1 file changed, 5 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c
> > index 336a3c0f9f2c..181abf7bb8c0 100644
> > --- a/drivers/usb/serial/cp210x.c
> > +++ b/drivers/usb/serial/cp210x.c
> > @@ -1111,9 +1111,12 @@ static void cp210x_change_speed(struct tty_struct *tty,
> >  	 */
> >  	if (priv->use_actual_rate)
> >  		baud = cp210x_get_actual_rate(serial, baud);
> > -	else if (baud < 1000000)
> > +	else if (baud < 1000000) {
> > +		if (priv->partnum == CP210X_PARTNUM_CP2105 &&
> > +		    cp210x_interface_num(serial) == 1)
> > +			baud = clamp(baud, 2400u, priv->max_speed);
> >  		baud = cp210x_get_an205_rate(baud);
> 
> We already have a clamp in place in cp210x_get_actual_rate() so just add
> a similar construct to cp210x_get_actual_rate() and amend
> cp210x_init_max_speed() as needed.

Or better still, move the clamp from cp210x_get_actual_rate() to above
these conditionals and make sure to honour min_speed. Then you can drop
the final else-if here too.

> > -	else if (baud > priv->max_speed)
> > +	} else if (baud > priv->max_speed)
> >  		baud = priv->max_speed;
> >  
> >  	dev_dbg(&port->dev, "%s - setting baud rate to %u\n", __func__, baud);

Johan

             reply	other threads:[~2019-02-04 16:01 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-04 16:01 Johan Hovold [this message]
  -- strict thread matches above, loose matches on Subject: below --
2019-02-04 15:57 USB: serial: cp210x: add minimun baud rate for CP2105 SCI Johan Hovold
2019-02-04 11:21 Johanna Abrahamsson

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=20190204160129.GG4686@localhost \
    --to=johan@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=johanna@mjao.org \
    --cc=linux-usb@vger.kernel.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).