USB: serial: cp210x: generalise CP2102N line-speed handling
PATCH 4/5 USB: serial: cp210x: generalise CP2102N line-speed handling
Quoted 34 lines · Andy Shevchenko
Quoted 22 lines · Johan Hovold
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.(quoted diff) +16
-0+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; +}Review
Quoted 10 lines
(quoted diff) +0
-9- 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); - }
Quoted 3 lines
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 [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html