[PATCH v2 5/6] USB: serial: ch341: Compute minimum baud rate

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

 



The minimum baud rate was hardcoded, not computed. A patch later in the
series will make use of the minimum baud rate as well.

The (1 + ((x - 1) / y)) pattern is to force rounding up (mathematically
the minimum rate is about 45.78bps).

Signed-off-by: Michael Hanselmann <public@xxxxxxxxx>
---
 drivers/usb/serial/ch341.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/serial/ch341.c b/drivers/usb/serial/ch341.c
index 9407e12d9fbc..c820772e6a07 100644
--- a/drivers/usb/serial/ch341.c
+++ b/drivers/usb/serial/ch341.c
@@ -147,6 +147,8 @@ static int ch341_control_in(struct usb_device *dev,
 
 #define CH341_CLKRATE		48000000
 #define CH341_CLK_DIV(ps, fact)	(1 << (12 - 3 * (ps) - (fact)))
+#define CH341_MIN_BPS \
+	(unsigned int)(1 + (((CH341_CLKRATE) - 1) / (CH341_CLK_DIV(0, 0) * 256)))
 #define CH341_MIN_RATE(ps, fact) \
 	(CH341_CLKRATE / (CH341_CLK_DIV((ps), (fact)) * 256))
 
@@ -210,10 +212,10 @@ static int ch341_get_divisor(struct ch341_private *priv)
 	speed = priv->baud_rate;
 
 	/*
-	 * Clamp to supported range, this makes the (ps < 0) and (div < 2)
-	 * sanity checks below redundant.
+	 * Clamp to supported range, making the later range sanity checks
+	 * redundant.
 	 */
-	speed = clamp(speed, 46U, 3000000U);
+	speed = clamp(speed, CH341_MIN_BPS, 3000000U);
 
 	if (priv->quirks & CH341_QUIRK_LIMITED_PRESCALER) {
 		/*
-- 
2.20.1




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

  Powered by Linux