Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

USB: serial: belkin_sa: Various needed fixes

Use the baud rate stuff from the kernel don't parse CBAUD directly
Remove pointless and wrong 'no change' check

Could do with some good testing as well but again better than adding &&
BROKEN

(The use of BELKIN_SA_BAUD() might seem a bit odd but x/a = b and x/b =
a (rounded for integers)).



Signed-off-by: Alan Cox <alan@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>


authored by

Alan Cox and committed by
Greg Kroah-Hartman
9a8baec7 568c24ad

+26 -41
+26 -41
drivers/usb/serial/belkin_sa.c
··· 349 349 unsigned long flags; 350 350 unsigned long control_state; 351 351 int bad_flow_control; 352 + speed_t baud; 352 353 353 354 if ((!port->tty) || (!port->tty->termios)) { 354 355 dbg ("%s - no tty or termios structure", __FUNCTION__); ··· 365 364 bad_flow_control = priv->bad_flow_control; 366 365 spin_unlock_irqrestore(&priv->lock, flags); 367 366 368 - /* check that they really want us to change something */ 369 - if (old_termios) { 370 - if ((cflag == old_termios->c_cflag) && 371 - (RELEVANT_IFLAG(port->tty->termios->c_iflag) == RELEVANT_IFLAG(old_termios->c_iflag))) { 372 - dbg("%s - nothing to change...", __FUNCTION__); 373 - return; 374 - } 375 - old_iflag = old_termios->c_iflag; 376 - old_cflag = old_termios->c_cflag; 377 - } 367 + old_iflag = old_termios->c_iflag; 368 + old_cflag = old_termios->c_cflag; 378 369 379 370 /* Set the baud rate */ 380 371 if( (cflag&CBAUD) != (old_cflag&CBAUD) ) { ··· 380 387 if (BSA_USB_CMD(BELKIN_SA_SET_RTS_REQUEST, 1) < 0) 381 388 err("Set RTS error"); 382 389 } 390 + } 383 391 384 - switch(cflag & CBAUD) { 385 - case B0: /* handled below */ break; 386 - case B300: urb_value = BELKIN_SA_BAUD(300); break; 387 - case B600: urb_value = BELKIN_SA_BAUD(600); break; 388 - case B1200: urb_value = BELKIN_SA_BAUD(1200); break; 389 - case B2400: urb_value = BELKIN_SA_BAUD(2400); break; 390 - case B4800: urb_value = BELKIN_SA_BAUD(4800); break; 391 - case B9600: urb_value = BELKIN_SA_BAUD(9600); break; 392 - case B19200: urb_value = BELKIN_SA_BAUD(19200); break; 393 - case B38400: urb_value = BELKIN_SA_BAUD(38400); break; 394 - case B57600: urb_value = BELKIN_SA_BAUD(57600); break; 395 - case B115200: urb_value = BELKIN_SA_BAUD(115200); break; 396 - case B230400: urb_value = BELKIN_SA_BAUD(230400); break; 397 - default: err("BELKIN USB Serial Adapter: unsupported baudrate request, using default of 9600"); 398 - urb_value = BELKIN_SA_BAUD(9600); break; 399 - } 400 - if ((cflag & CBAUD) != B0 ) { 401 - if (BSA_USB_CMD(BELKIN_SA_SET_BAUDRATE_REQUEST, urb_value) < 0) 402 - err("Set baudrate error"); 403 - } else { 404 - /* Disable flow control */ 405 - if (BSA_USB_CMD(BELKIN_SA_SET_FLOW_CTRL_REQUEST, BELKIN_SA_FLOW_NONE) < 0) 406 - err("Disable flowcontrol error"); 392 + baud = tty_get_baud_rate(port->tty); 393 + urb_value = BELKIN_SA_BAUD(baud); 394 + /* Clip to maximum speed */ 395 + if (urb_value == 0) 396 + urb_value = 1; 397 + /* Turn it back into a resulting real baud rate */ 398 + baud = BELKIN_SA_BAUD(urb_value); 399 + /* FIXME: Once the tty updates are done then push this back to the tty */ 407 400 408 - /* Drop RTS and DTR */ 409 - control_state &= ~(TIOCM_DTR | TIOCM_RTS); 410 - if (BSA_USB_CMD(BELKIN_SA_SET_DTR_REQUEST, 0) < 0) 411 - err("DTR LOW error"); 412 - if (BSA_USB_CMD(BELKIN_SA_SET_RTS_REQUEST, 0) < 0) 413 - err("RTS LOW error"); 414 - } 401 + if ((cflag & CBAUD) != B0 ) { 402 + if (BSA_USB_CMD(BELKIN_SA_SET_BAUDRATE_REQUEST, urb_value) < 0) 403 + err("Set baudrate error"); 404 + } else { 405 + /* Disable flow control */ 406 + if (BSA_USB_CMD(BELKIN_SA_SET_FLOW_CTRL_REQUEST, BELKIN_SA_FLOW_NONE) < 0) 407 + err("Disable flowcontrol error"); 408 + /* Drop RTS and DTR */ 409 + control_state &= ~(TIOCM_DTR | TIOCM_RTS); 410 + if (BSA_USB_CMD(BELKIN_SA_SET_DTR_REQUEST, 0) < 0) 411 + err("DTR LOW error"); 412 + if (BSA_USB_CMD(BELKIN_SA_SET_RTS_REQUEST, 0) < 0) 413 + err("RTS LOW error"); 415 414 } 416 415 417 416 /* set the parity */ ··· 423 438 case CS6: urb_value = BELKIN_SA_DATA_BITS(6); break; 424 439 case CS7: urb_value = BELKIN_SA_DATA_BITS(7); break; 425 440 case CS8: urb_value = BELKIN_SA_DATA_BITS(8); break; 426 - default: err("CSIZE was not CS5-CS8, using default of 8"); 441 + default: dbg("CSIZE was not CS5-CS8, using default of 8"); 427 442 urb_value = BELKIN_SA_DATA_BITS(8); 428 443 break; 429 444 }