From: Johan Hovold <johan@kernel.org>
To: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: Johan Hovold <johan@kernel.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Karoly Pados <pados@pados.hu>, USB <linux-usb@vger.kernel.org>
Subject: [4/5] USB: serial: cp210x: generalise CP2102N line-speed handling
Date: Wed, 18 Jul 2018 14:37:27 +0200 [thread overview]
Message-ID: <20180718123727.GC10204@localhost> (raw)
On Wed, Jul 18, 2018 at 03:34:34PM +0300, Andy Shevchenko wrote:
> On Wed, Jul 18, 2018 at 3:25 PM, Johan Hovold <johan@kernel.org> wrote:
> > The CP2102N equations for determining the actual baud rate can be used
> > also for other device types, so let's factor it out.
> >
> > Note that this removes the now unused cp210x_is_cp2102n() helper.
>
>
> > +static speed_t cp210x_get_actual_rate(struct usb_serial *serial, speed_t baud)
> > +{
> > + struct cp210x_serial_private *priv = usb_get_serial_data(serial);
> > + unsigned int prescale = 1;
> > + unsigned int div;
> > +
> > + baud = clamp(baud, 300u, priv->max_speed);
> > +
> > + if (baud <= 365)
> > + prescale = 4;
> > +
> > + div = DIV_ROUND_CLOSEST(48000000, 2 * prescale * baud);
> > + baud = 48000000 / (2 * prescale * div);
> > +
> > + return baud;
> > +}
>
> > - if (cp210x_is_cp2102n(serial)) {
> > - int clk_div;
> > - int prescaler;
> > -
> > - baud = clamp(baud, 300u, priv->max_speed);
> > - prescaler = (baud <= 365) ? 4 : 1;
> > - clk_div = DIV_ROUND_CLOSEST(48000000, 2 * prescaler * baud);
> > - baud = 48000000 / (2 * prescaler * clk_div);
> > - }
>
> Looks like ping-pong type of changes.
> I think the factoring of this particular piece of code can be done in
> patch 3 in somewhat similar way.
Indeed, and it was done like this on purpose this time to save time (and
I did not want to rewrite Karoly's patch beyond recognition).
Johan
---
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next reply other threads:[~2018-07-18 12:37 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-18 12:37 Johan Hovold [this message]
-- strict thread matches above, loose matches on Subject: below --
2018-07-18 13:26 [4/5] USB: serial: cp210x: generalise CP2102N line-speed handling Greg Kroah-Hartman
2018-07-18 12:40 Andy Shevchenko
2018-07-18 12:34 Andy Shevchenko
2018-07-18 12:25 Johan Hovold
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=20180718123727.GC10204@localhost \
--to=johan@kernel.org \
--cc=andy.shevchenko@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-usb@vger.kernel.org \
--cc=pados@pados.hu \
/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).