aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/serial/mct_u232.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/serial/mct_u232.c')
-rw-r--r--drivers/usb/serial/mct_u232.c104
1 files changed, 44 insertions, 60 deletions
diff --git a/drivers/usb/serial/mct_u232.c b/drivers/usb/serial/mct_u232.c
index df98cffdba65..f3947712e137 100644
--- a/drivers/usb/serial/mct_u232.c
+++ b/drivers/usb/serial/mct_u232.c
@@ -45,8 +45,6 @@
45#define DRIVER_AUTHOR "Wolfgang Grandegger <wolfgang@ces.ch>" 45#define DRIVER_AUTHOR "Wolfgang Grandegger <wolfgang@ces.ch>"
46#define DRIVER_DESC "Magic Control Technology USB-RS232 converter driver" 46#define DRIVER_DESC "Magic Control Technology USB-RS232 converter driver"
47 47
48static bool debug;
49
50/* 48/*
51 * Function prototypes 49 * Function prototypes
52 */ 50 */
@@ -214,7 +212,7 @@ static int mct_u232_set_baud_rate(struct tty_struct *tty,
214 value, rc); 212 value, rc);
215 else 213 else
216 tty_encode_baud_rate(tty, speed, speed); 214 tty_encode_baud_rate(tty, speed, speed);
217 dbg("set_baud_rate: value: 0x%x, divisor: 0x%x", value, divisor); 215 dev_dbg(&port->dev, "set_baud_rate: value: 0x%x, divisor: 0x%x\n", value, divisor);
218 216
219 /* Mimic the MCT-supplied Windows driver (version 1.21P.0104), which 217 /* Mimic the MCT-supplied Windows driver (version 1.21P.0104), which
220 always sends two extra USB 'device request' messages after the 218 always sends two extra USB 'device request' messages after the
@@ -247,8 +245,8 @@ static int mct_u232_set_baud_rate(struct tty_struct *tty,
247 if (port && C_CRTSCTS(tty)) 245 if (port && C_CRTSCTS(tty))
248 cts_enable_byte = 1; 246 cts_enable_byte = 1;
249 247
250 dbg("set_baud_rate: send second control message, data = %02X", 248 dev_dbg(&port->dev, "set_baud_rate: send second control message, data = %02X\n",
251 cts_enable_byte); 249 cts_enable_byte);
252 buf[0] = cts_enable_byte; 250 buf[0] = cts_enable_byte;
253 rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), 251 rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
254 MCT_U232_SET_CTS_REQUEST, 252 MCT_U232_SET_CTS_REQUEST,
@@ -263,7 +261,8 @@ static int mct_u232_set_baud_rate(struct tty_struct *tty,
263 return rc; 261 return rc;
264} /* mct_u232_set_baud_rate */ 262} /* mct_u232_set_baud_rate */
265 263
266static int mct_u232_set_line_ctrl(struct usb_serial *serial, unsigned char lcr) 264static int mct_u232_set_line_ctrl(struct usb_serial_port *port,
265 unsigned char lcr)
267{ 266{
268 int rc; 267 int rc;
269 unsigned char *buf; 268 unsigned char *buf;
@@ -273,20 +272,19 @@ static int mct_u232_set_line_ctrl(struct usb_serial *serial, unsigned char lcr)
273 return -ENOMEM; 272 return -ENOMEM;
274 273
275 buf[0] = lcr; 274 buf[0] = lcr;
276 rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), 275 rc = usb_control_msg(port->serial->dev, usb_sndctrlpipe(port->serial->dev, 0),
277 MCT_U232_SET_LINE_CTRL_REQUEST, 276 MCT_U232_SET_LINE_CTRL_REQUEST,
278 MCT_U232_SET_REQUEST_TYPE, 277 MCT_U232_SET_REQUEST_TYPE,
279 0, 0, buf, MCT_U232_SET_LINE_CTRL_SIZE, 278 0, 0, buf, MCT_U232_SET_LINE_CTRL_SIZE,
280 WDR_TIMEOUT); 279 WDR_TIMEOUT);
281 if (rc < 0) 280 if (rc < 0)
282 dev_err(&serial->dev->dev, 281 dev_err(&port->dev, "Set LINE CTRL 0x%x failed (error = %d)\n", lcr, rc);
283 "Set LINE CTRL 0x%x failed (error = %d)\n", lcr, rc); 282 dev_dbg(&port->dev, "set_line_ctrl: 0x%x\n", lcr);
284 dbg("set_line_ctrl: 0x%x", lcr);
285 kfree(buf); 283 kfree(buf);
286 return rc; 284 return rc;
287} /* mct_u232_set_line_ctrl */ 285} /* mct_u232_set_line_ctrl */
288 286
289static int mct_u232_set_modem_ctrl(struct usb_serial *serial, 287static int mct_u232_set_modem_ctrl(struct usb_serial_port *port,
290 unsigned int control_state) 288 unsigned int control_state)
291{ 289{
292 int rc; 290 int rc;
@@ -304,25 +302,24 @@ static int mct_u232_set_modem_ctrl(struct usb_serial *serial,
304 mcr |= MCT_U232_MCR_RTS; 302 mcr |= MCT_U232_MCR_RTS;
305 303
306 buf[0] = mcr; 304 buf[0] = mcr;
307 rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), 305 rc = usb_control_msg(port->serial->dev, usb_sndctrlpipe(port->serial->dev, 0),
308 MCT_U232_SET_MODEM_CTRL_REQUEST, 306 MCT_U232_SET_MODEM_CTRL_REQUEST,
309 MCT_U232_SET_REQUEST_TYPE, 307 MCT_U232_SET_REQUEST_TYPE,
310 0, 0, buf, MCT_U232_SET_MODEM_CTRL_SIZE, 308 0, 0, buf, MCT_U232_SET_MODEM_CTRL_SIZE,
311 WDR_TIMEOUT); 309 WDR_TIMEOUT);
312 kfree(buf); 310 kfree(buf);
313 311
314 dbg("set_modem_ctrl: state=0x%x ==> mcr=0x%x", control_state, mcr); 312 dev_dbg(&port->dev, "set_modem_ctrl: state=0x%x ==> mcr=0x%x\n", control_state, mcr);
315 313
316 if (rc < 0) { 314 if (rc < 0) {
317 dev_err(&serial->dev->dev, 315 dev_err(&port->dev, "Set MODEM CTRL 0x%x failed (error = %d)\n", mcr, rc);
318 "Set MODEM CTRL 0x%x failed (error = %d)\n", mcr, rc);
319 return rc; 316 return rc;
320 } 317 }
321 return 0; 318 return 0;
322} /* mct_u232_set_modem_ctrl */ 319} /* mct_u232_set_modem_ctrl */
323 320
324static int mct_u232_get_modem_stat(struct usb_serial *serial, 321static int mct_u232_get_modem_stat(struct usb_serial_port *port,
325 unsigned char *msr) 322 unsigned char *msr)
326{ 323{
327 int rc; 324 int rc;
328 unsigned char *buf; 325 unsigned char *buf;
@@ -332,19 +329,18 @@ static int mct_u232_get_modem_stat(struct usb_serial *serial,
332 *msr = 0; 329 *msr = 0;
333 return -ENOMEM; 330 return -ENOMEM;
334 } 331 }
335 rc = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), 332 rc = usb_control_msg(port->serial->dev, usb_rcvctrlpipe(port->serial->dev, 0),
336 MCT_U232_GET_MODEM_STAT_REQUEST, 333 MCT_U232_GET_MODEM_STAT_REQUEST,
337 MCT_U232_GET_REQUEST_TYPE, 334 MCT_U232_GET_REQUEST_TYPE,
338 0, 0, buf, MCT_U232_GET_MODEM_STAT_SIZE, 335 0, 0, buf, MCT_U232_GET_MODEM_STAT_SIZE,
339 WDR_TIMEOUT); 336 WDR_TIMEOUT);
340 if (rc < 0) { 337 if (rc < 0) {
341 dev_err(&serial->dev->dev, 338 dev_err(&port->dev, "Get MODEM STATus failed (error = %d)\n", rc);
342 "Get MODEM STATus failed (error = %d)\n", rc);
343 *msr = 0; 339 *msr = 0;
344 } else { 340 } else {
345 *msr = buf[0]; 341 *msr = buf[0];
346 } 342 }
347 dbg("get_modem_stat: 0x%x", *msr); 343 dev_dbg(&port->dev, "get_modem_stat: 0x%x\n", *msr);
348 kfree(buf); 344 kfree(buf);
349 return rc; 345 return rc;
350} /* mct_u232_get_modem_stat */ 346} /* mct_u232_get_modem_stat */
@@ -363,8 +359,8 @@ static void mct_u232_msr_to_icount(struct async_icount *icount,
363 icount->dcd++; 359 icount->dcd++;
364} /* mct_u232_msr_to_icount */ 360} /* mct_u232_msr_to_icount */
365 361
366static void mct_u232_msr_to_state(unsigned int *control_state, 362static void mct_u232_msr_to_state(struct usb_serial_port *port,
367 unsigned char msr) 363 unsigned int *control_state, unsigned char msr)
368{ 364{
369 /* Translate Control Line states */ 365 /* Translate Control Line states */
370 if (msr & MCT_U232_MSR_DSR) 366 if (msr & MCT_U232_MSR_DSR)
@@ -383,7 +379,7 @@ static void mct_u232_msr_to_state(unsigned int *control_state,
383 *control_state |= TIOCM_CD; 379 *control_state |= TIOCM_CD;
384 else 380 else
385 *control_state &= ~TIOCM_CD; 381 *control_state &= ~TIOCM_CD;
386 dbg("msr_to_state: msr=0x%x ==> state=0x%x", msr, *control_state); 382 dev_dbg(&port->dev, "msr_to_state: msr=0x%x ==> state=0x%x\n", msr, *control_state);
387} /* mct_u232_msr_to_state */ 383} /* mct_u232_msr_to_state */
388 384
389/* 385/*
@@ -465,14 +461,14 @@ static int mct_u232_open(struct tty_struct *tty, struct usb_serial_port *port)
465 control_state = priv->control_state; 461 control_state = priv->control_state;
466 last_lcr = priv->last_lcr; 462 last_lcr = priv->last_lcr;
467 spin_unlock_irqrestore(&priv->lock, flags); 463 spin_unlock_irqrestore(&priv->lock, flags);
468 mct_u232_set_modem_ctrl(serial, control_state); 464 mct_u232_set_modem_ctrl(port, control_state);
469 mct_u232_set_line_ctrl(serial, last_lcr); 465 mct_u232_set_line_ctrl(port, last_lcr);
470 466
471 /* Read modem status and update control state */ 467 /* Read modem status and update control state */
472 mct_u232_get_modem_stat(serial, &last_msr); 468 mct_u232_get_modem_stat(port, &last_msr);
473 spin_lock_irqsave(&priv->lock, flags); 469 spin_lock_irqsave(&priv->lock, flags);
474 priv->last_msr = last_msr; 470 priv->last_msr = last_msr;
475 mct_u232_msr_to_state(&priv->control_state, priv->last_msr); 471 mct_u232_msr_to_state(port, &priv->control_state, priv->last_msr);
476 spin_unlock_irqrestore(&priv->lock, flags); 472 spin_unlock_irqrestore(&priv->lock, flags);
477 473
478 retval = usb_submit_urb(port->read_urb, GFP_KERNEL); 474 retval = usb_submit_urb(port->read_urb, GFP_KERNEL);
@@ -512,7 +508,7 @@ static void mct_u232_dtr_rts(struct usb_serial_port *port, int on)
512 priv->control_state &= ~(TIOCM_DTR | TIOCM_RTS); 508 priv->control_state &= ~(TIOCM_DTR | TIOCM_RTS);
513 control_state = priv->control_state; 509 control_state = priv->control_state;
514 spin_unlock_irq(&priv->lock); 510 spin_unlock_irq(&priv->lock);
515 mct_u232_set_modem_ctrl(port->serial, control_state); 511 mct_u232_set_modem_ctrl(port, control_state);
516 } 512 }
517 mutex_unlock(&port->serial->disc_mutex); 513 mutex_unlock(&port->serial->disc_mutex);
518} 514}
@@ -532,7 +528,6 @@ static void mct_u232_read_int_callback(struct urb *urb)
532{ 528{
533 struct usb_serial_port *port = urb->context; 529 struct usb_serial_port *port = urb->context;
534 struct mct_u232_private *priv = usb_get_serial_port_data(port); 530 struct mct_u232_private *priv = usb_get_serial_port_data(port);
535 struct usb_serial *serial = port->serial;
536 struct tty_struct *tty; 531 struct tty_struct *tty;
537 unsigned char *data = urb->transfer_buffer; 532 unsigned char *data = urb->transfer_buffer;
538 int retval; 533 int retval;
@@ -547,22 +542,16 @@ static void mct_u232_read_int_callback(struct urb *urb)
547 case -ENOENT: 542 case -ENOENT:
548 case -ESHUTDOWN: 543 case -ESHUTDOWN:
549 /* this urb is terminated, clean up */ 544 /* this urb is terminated, clean up */
550 dbg("%s - urb shutting down with status: %d", 545 dev_dbg(&port->dev, "%s - urb shutting down with status: %d\n",
551 __func__, status); 546 __func__, status);
552 return; 547 return;
553 default: 548 default:
554 dbg("%s - nonzero urb status received: %d", 549 dev_dbg(&port->dev, "%s - nonzero urb status received: %d\n",
555 __func__, status); 550 __func__, status);
556 goto exit; 551 goto exit;
557 } 552 }
558 553
559 if (!serial) { 554 usb_serial_debug_data(&port->dev, __func__, urb->actual_length, data);
560 dbg("%s - bad serial pointer, exiting", __func__);
561 return;
562 }
563
564 usb_serial_debug_data(debug, &port->dev, __func__,
565 urb->actual_length, data);
566 555
567 /* 556 /*
568 * Work-a-round: handle the 'usual' bulk-in pipe here 557 * Work-a-round: handle the 'usual' bulk-in pipe here
@@ -588,7 +577,7 @@ static void mct_u232_read_int_callback(struct urb *urb)
588 priv->last_msr = data[MCT_U232_MSR_INDEX]; 577 priv->last_msr = data[MCT_U232_MSR_INDEX];
589 578
590 /* Record Control Line states */ 579 /* Record Control Line states */
591 mct_u232_msr_to_state(&priv->control_state, priv->last_msr); 580 mct_u232_msr_to_state(port, &priv->control_state, priv->last_msr);
592 581
593 mct_u232_msr_to_icount(&priv->icount, priv->last_msr); 582 mct_u232_msr_to_icount(&priv->icount, priv->last_msr);
594 583
@@ -656,18 +645,18 @@ static void mct_u232_set_termios(struct tty_struct *tty,
656 645
657 /* reassert DTR and RTS on transition from B0 */ 646 /* reassert DTR and RTS on transition from B0 */
658 if ((old_cflag & CBAUD) == B0) { 647 if ((old_cflag & CBAUD) == B0) {
659 dbg("%s: baud was B0", __func__); 648 dev_dbg(&port->dev, "%s: baud was B0\n", __func__);
660 control_state |= TIOCM_DTR | TIOCM_RTS; 649 control_state |= TIOCM_DTR | TIOCM_RTS;
661 mct_u232_set_modem_ctrl(serial, control_state); 650 mct_u232_set_modem_ctrl(port, control_state);
662 } 651 }
663 652
664 mct_u232_set_baud_rate(tty, serial, port, tty_get_baud_rate(tty)); 653 mct_u232_set_baud_rate(tty, serial, port, tty_get_baud_rate(tty));
665 654
666 if ((cflag & CBAUD) == B0) { 655 if ((cflag & CBAUD) == B0) {
667 dbg("%s: baud is B0", __func__); 656 dev_dbg(&port->dev, "%s: baud is B0\n", __func__);
668 /* Drop RTS and DTR */ 657 /* Drop RTS and DTR */
669 control_state &= ~(TIOCM_DTR | TIOCM_RTS); 658 control_state &= ~(TIOCM_DTR | TIOCM_RTS);
670 mct_u232_set_modem_ctrl(serial, control_state); 659 mct_u232_set_modem_ctrl(port, control_state);
671 } 660 }
672 661
673 /* 662 /*
@@ -704,7 +693,7 @@ static void mct_u232_set_termios(struct tty_struct *tty,
704 last_lcr |= (cflag & CSTOPB) ? 693 last_lcr |= (cflag & CSTOPB) ?
705 MCT_U232_STOP_BITS_2 : MCT_U232_STOP_BITS_1; 694 MCT_U232_STOP_BITS_2 : MCT_U232_STOP_BITS_1;
706 695
707 mct_u232_set_line_ctrl(serial, last_lcr); 696 mct_u232_set_line_ctrl(port, last_lcr);
708 697
709 /* save off the modified port settings */ 698 /* save off the modified port settings */
710 spin_lock_irqsave(&priv->lock, flags); 699 spin_lock_irqsave(&priv->lock, flags);
@@ -716,7 +705,6 @@ static void mct_u232_set_termios(struct tty_struct *tty,
716static void mct_u232_break_ctl(struct tty_struct *tty, int break_state) 705static void mct_u232_break_ctl(struct tty_struct *tty, int break_state)
717{ 706{
718 struct usb_serial_port *port = tty->driver_data; 707 struct usb_serial_port *port = tty->driver_data;
719 struct usb_serial *serial = port->serial;
720 struct mct_u232_private *priv = usb_get_serial_port_data(port); 708 struct mct_u232_private *priv = usb_get_serial_port_data(port);
721 unsigned char lcr; 709 unsigned char lcr;
722 unsigned long flags; 710 unsigned long flags;
@@ -728,7 +716,7 @@ static void mct_u232_break_ctl(struct tty_struct *tty, int break_state)
728 lcr |= MCT_U232_SET_BREAK; 716 lcr |= MCT_U232_SET_BREAK;
729 spin_unlock_irqrestore(&priv->lock, flags); 717 spin_unlock_irqrestore(&priv->lock, flags);
730 718
731 mct_u232_set_line_ctrl(serial, lcr); 719 mct_u232_set_line_ctrl(port, lcr);
732} /* mct_u232_break_ctl */ 720} /* mct_u232_break_ctl */
733 721
734 722
@@ -750,7 +738,6 @@ static int mct_u232_tiocmset(struct tty_struct *tty,
750 unsigned int set, unsigned int clear) 738 unsigned int set, unsigned int clear)
751{ 739{
752 struct usb_serial_port *port = tty->driver_data; 740 struct usb_serial_port *port = tty->driver_data;
753 struct usb_serial *serial = port->serial;
754 struct mct_u232_private *priv = usb_get_serial_port_data(port); 741 struct mct_u232_private *priv = usb_get_serial_port_data(port);
755 unsigned int control_state; 742 unsigned int control_state;
756 unsigned long flags; 743 unsigned long flags;
@@ -769,7 +756,7 @@ static int mct_u232_tiocmset(struct tty_struct *tty,
769 756
770 priv->control_state = control_state; 757 priv->control_state = control_state;
771 spin_unlock_irqrestore(&priv->lock, flags); 758 spin_unlock_irqrestore(&priv->lock, flags);
772 return mct_u232_set_modem_ctrl(serial, control_state); 759 return mct_u232_set_modem_ctrl(port, control_state);
773} 760}
774 761
775static void mct_u232_throttle(struct tty_struct *tty) 762static void mct_u232_throttle(struct tty_struct *tty)
@@ -784,7 +771,7 @@ static void mct_u232_throttle(struct tty_struct *tty)
784 priv->control_state &= ~TIOCM_RTS; 771 priv->control_state &= ~TIOCM_RTS;
785 control_state = priv->control_state; 772 control_state = priv->control_state;
786 spin_unlock_irq(&priv->lock); 773 spin_unlock_irq(&priv->lock);
787 (void) mct_u232_set_modem_ctrl(port->serial, control_state); 774 mct_u232_set_modem_ctrl(port, control_state);
788 } else { 775 } else {
789 spin_unlock_irq(&priv->lock); 776 spin_unlock_irq(&priv->lock);
790 } 777 }
@@ -802,7 +789,7 @@ static void mct_u232_unthrottle(struct tty_struct *tty)
802 priv->control_state |= TIOCM_RTS; 789 priv->control_state |= TIOCM_RTS;
803 control_state = priv->control_state; 790 control_state = priv->control_state;
804 spin_unlock_irq(&priv->lock); 791 spin_unlock_irq(&priv->lock);
805 (void) mct_u232_set_modem_ctrl(port->serial, control_state); 792 mct_u232_set_modem_ctrl(port, control_state);
806 } else { 793 } else {
807 spin_unlock_irq(&priv->lock); 794 spin_unlock_irq(&priv->lock);
808 } 795 }
@@ -817,13 +804,13 @@ static int mct_u232_ioctl(struct tty_struct *tty,
817 struct async_icount cnow, cprev; 804 struct async_icount cnow, cprev;
818 unsigned long flags; 805 unsigned long flags;
819 806
820 dbg("%s - port %d, cmd = 0x%x", __func__, port->number, cmd); 807 dev_dbg(&port->dev, "%s - cmd = 0x%x\n", __func__, cmd);
821 808
822 switch (cmd) { 809 switch (cmd) {
823 810
824 case TIOCMIWAIT: 811 case TIOCMIWAIT:
825 812
826 dbg("%s (%d) TIOCMIWAIT", __func__, port->number); 813 dev_dbg(&port->dev, "%s TIOCMIWAIT", __func__);
827 814
828 spin_lock_irqsave(&mct_u232_port->lock, flags); 815 spin_lock_irqsave(&mct_u232_port->lock, flags);
829 cprev = mct_u232_port->icount; 816 cprev = mct_u232_port->icount;
@@ -879,8 +866,8 @@ static int mct_u232_get_icount(struct tty_struct *tty,
879 866
880 spin_unlock_irqrestore(&mct_u232_port->lock, flags); 867 spin_unlock_irqrestore(&mct_u232_port->lock, flags);
881 868
882 dbg("%s (%d) TIOCGICOUNT RX=%d, TX=%d", 869 dev_dbg(&port->dev, "%s TIOCGICOUNT RX=%d, TX=%d\n",
883 __func__, port->number, icount->rx, icount->tx); 870 __func__, icount->rx, icount->tx);
884 return 0; 871 return 0;
885} 872}
886 873
@@ -889,6 +876,3 @@ module_usb_serial_driver(serial_drivers, id_table);
889MODULE_AUTHOR(DRIVER_AUTHOR); 876MODULE_AUTHOR(DRIVER_AUTHOR);
890MODULE_DESCRIPTION(DRIVER_DESC); 877MODULE_DESCRIPTION(DRIVER_DESC);
891MODULE_LICENSE("GPL"); 878MODULE_LICENSE("GPL");
892
893module_param(debug, bool, S_IRUGO | S_IWUSR);
894MODULE_PARM_DESC(debug, "Debug enabled or not");