aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/serial/pl2303.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/serial/pl2303.c')
-rw-r--r--drivers/usb/serial/pl2303.c65
1 files changed, 28 insertions, 37 deletions
diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c
index 04390dff926a..b93b3b30dec5 100644
--- a/drivers/usb/serial/pl2303.c
+++ b/drivers/usb/serial/pl2303.c
@@ -273,46 +273,44 @@ static void pl2303_encode_baudrate(struct tty_struct *tty,
273 struct usb_serial_port *port, 273 struct usb_serial_port *port,
274 u8 buf[4]) 274 u8 buf[4])
275{ 275{
276 const int baud_sup[] = { 75, 150, 300, 600, 1200, 1800, 2400, 3600,
277 4800, 7200, 9600, 14400, 19200, 28800, 38400,
278 57600, 115200, 230400, 460800, 500000, 614400,
279 921600, 1228800, 2457600, 3000000, 6000000 };
280
276 struct usb_serial *serial = port->serial; 281 struct usb_serial *serial = port->serial;
277 struct pl2303_serial_private *spriv = usb_get_serial_data(serial); 282 struct pl2303_serial_private *spriv = usb_get_serial_data(serial);
278 int baud; 283 int baud;
284 int i;
279 285
286 /*
287 * NOTE: Only the values defined in baud_sup are supported!
288 * => if unsupported values are set, the PL2303 seems to use
289 * 9600 baud (at least my PL2303X always does)
290 */
280 baud = tty_get_baud_rate(tty); 291 baud = tty_get_baud_rate(tty);
281 dev_dbg(&port->dev, "baud requested = %d\n", baud); 292 dev_dbg(&port->dev, "baud requested = %d\n", baud);
282 if (!baud) 293 if (!baud)
283 return; 294 return;
284 295
285 if (spriv->type != HX || baud <= 115200) { 296 /* Set baudrate to nearest supported value */
286 /* 297 for (i = 0; i < ARRAY_SIZE(baud_sup); ++i) {
287 * NOTE: Only the values defined in baud_sup are supported ! 298 if (baud_sup[i] > baud)
288 * => if unsupported values are set, the PL2303 seems to 299 break;
289 * use 9600 baud (at least my PL2303X always does) 300 }
290 */
291 const int baud_sup[] = { 75, 150, 300, 600, 1200, 1800, 2400,
292 3600, 4800, 7200, 9600, 14400, 19200,
293 28800, 38400, 57600, 115200, 230400,
294 460800, 500000, 614400, 921600,
295 1228800, 2457600, 3000000, 6000000 };
296 int i;
297
298 /* Set baudrate to nearest supported value */
299 for (i = 0; i < ARRAY_SIZE(baud_sup); ++i) {
300 if (baud_sup[i] > baud)
301 break;
302 }
303 301
304 if (i == ARRAY_SIZE(baud_sup)) 302 if (i == ARRAY_SIZE(baud_sup))
305 baud = baud_sup[i - 1]; 303 baud = baud_sup[i - 1];
306 else if (i > 0 304 else if (i > 0 && (baud_sup[i] - baud) > (baud - baud_sup[i - 1]))
307 && (baud_sup[i] - baud) > (baud - baud_sup[i - 1])) 305 baud = baud_sup[i - 1];
308 baud = baud_sup[i - 1]; 306 else
309 else 307 baud = baud_sup[i];
310 baud = baud_sup[i];
311 308
312 /* type_0, type_1 only support up to 1228800 baud */ 309 /* type_0, type_1 only support up to 1228800 baud */
313 if (spriv->type != HX) 310 if (spriv->type != HX)
314 baud = min_t(int, baud, 1228800); 311 baud = min_t(int, baud, 1228800);
315 312
313 if (spriv->type != HX || baud <= 115200) {
316 /* Direct (standard) baud rate encoding method */ 314 /* Direct (standard) baud rate encoding method */
317 put_unaligned_le32(baud, buf); 315 put_unaligned_le32(baud, buf);
318 } else { 316 } else {
@@ -333,17 +331,10 @@ static void pl2303_encode_baudrate(struct tty_struct *tty,
333 * => 8 < B < 16: device seems to work not properly 331 * => 8 < B < 16: device seems to work not properly
334 * => B <= 8: device uses the max. value B = 512 instead 332 * => B <= 8: device uses the max. value B = 512 instead
335 */ 333 */
336 unsigned int A, B;
337 334
338 /* Respect the specified baud rate limits */
339 baud = max_t(int, baud, 75);
340 if (spriv->type == HX)
341 baud = min_t(int, baud, 6000000);
342 else
343 baud = min_t(int, baud, 1228800);
344 /* Determine factors A and B */ 335 /* Determine factors A and B */
345 A = 0; 336 unsigned int A = 0;
346 B = 12000000 * 32 / baud; /* 12MHz */ 337 unsigned int B = 12000000 * 32 / baud; /* 12MHz */
347 B <<= 1; /* Add one bit for rounding */ 338 B <<= 1; /* Add one bit for rounding */
348 while (B > (512 << 1) && A <= 14) { 339 while (B > (512 << 1) && A <= 14) {
349 A += 2; 340 A += 2;