Re: [PATCH 4/5] USB: serial: cp210x: generalise CP2102N line-speed handling

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx> 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@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux