aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/serial/ch341.c
diff options
context:
space:
mode:
authorJohan Hovold <johan@kernel.org>2020-06-30 11:57:56 +0200
committerJohan Hovold <johan@kernel.org>2020-06-30 12:07:00 +0200
commit86f6da2951db571255ea0b1af7c6115ab870b757 (patch)
tree2267012f6b9c682ae3a8801105a6f97c6be6fe08 /drivers/usb/serial/ch341.c
parentUSB: serial: ch341: name prescaler, divisor registers (diff)
downloadlinux-dev-86f6da2951db571255ea0b1af7c6115ab870b757.tar.xz
linux-dev-86f6da2951db571255ea0b1af7c6115ab870b757.zip
USB: serial: ch341: add min and max line-speed macros
The line-speed algorithm clamps the requested value to the supported range instead of bailing out on unsupported values. Provide min and max macros and indicate how they are derived instead of hardcoding the limits. Note that the algorithm depends on the minimum rate (45.78 bps) being rounded up (and the maximum rate being rounded down) to avoid special casing. Suggested-by: Michael Hanselmann <public@hansmi.ch> Link: https://lore.kernel.org/r/20200630095756.GZ3334@localhost Signed-off-by: Johan Hovold <johan@kernel.org>
Diffstat (limited to 'drivers/usb/serial/ch341.c')
-rw-r--r--drivers/usb/serial/ch341.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/drivers/usb/serial/ch341.c b/drivers/usb/serial/ch341.c
index 684d595e7630..55a1c6dbeeb2 100644
--- a/drivers/usb/serial/ch341.c
+++ b/drivers/usb/serial/ch341.c
@@ -156,6 +156,10 @@ static const speed_t ch341_min_rates[] = {
CH341_MIN_RATE(3),
};
+/* Supported range is 46 to 3000000 bps. */
+#define CH341_MIN_BPS DIV_ROUND_UP(CH341_CLKRATE, CH341_CLK_DIV(0, 0) * 256)
+#define CH341_MAX_BPS (CH341_CLKRATE / (CH341_CLK_DIV(3, 0) * 2))
+
/*
* The device line speed is given by the following equation:
*
@@ -177,7 +181,7 @@ static int ch341_get_divisor(struct ch341_private *priv)
* Clamp to supported range, this makes the (ps < 0) and (div < 2)
* sanity checks below redundant.
*/
- speed = clamp(speed, 46U, 3000000U);
+ speed = clamp_val(speed, CH341_MIN_BPS, CH341_MAX_BPS);
/*
* Start with highest possible base clock (fact = 1) that will give a