aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/serial/option.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/serial/option.c')
-rw-r--r--drivers/usb/serial/option.c203
1 files changed, 90 insertions, 113 deletions
diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c
index e9256408757f..92d0f925d053 100644
--- a/drivers/usb/serial/option.c
+++ b/drivers/usb/serial/option.c
@@ -45,29 +45,29 @@
45#include "usb-serial.h" 45#include "usb-serial.h"
46 46
47/* Function prototypes */ 47/* Function prototypes */
48static int option_open (struct usb_serial_port *port, struct file *filp); 48static int option_open(struct usb_serial_port *port, struct file *filp);
49static void option_close (struct usb_serial_port *port, struct file *filp); 49static void option_close(struct usb_serial_port *port, struct file *filp);
50static int option_startup (struct usb_serial *serial); 50static int option_startup(struct usb_serial *serial);
51static void option_shutdown (struct usb_serial *serial); 51static void option_shutdown(struct usb_serial *serial);
52static void option_rx_throttle (struct usb_serial_port *port); 52static void option_rx_throttle(struct usb_serial_port *port);
53static void option_rx_unthrottle (struct usb_serial_port *port); 53static void option_rx_unthrottle(struct usb_serial_port *port);
54static int option_write_room (struct usb_serial_port *port); 54static int option_write_room(struct usb_serial_port *port);
55 55
56static void option_instat_callback(struct urb *urb, struct pt_regs *regs); 56static void option_instat_callback(struct urb *urb, struct pt_regs *regs);
57 57
58static int option_write (struct usb_serial_port *port, 58static int option_write(struct usb_serial_port *port,
59 const unsigned char *buf, int count); 59 const unsigned char *buf, int count);
60 60
61static int option_chars_in_buffer (struct usb_serial_port *port); 61static int option_chars_in_buffer(struct usb_serial_port *port);
62static int option_ioctl (struct usb_serial_port *port, struct file *file, 62static int option_ioctl(struct usb_serial_port *port, struct file *file,
63 unsigned int cmd, unsigned long arg); 63 unsigned int cmd, unsigned long arg);
64static void option_set_termios (struct usb_serial_port *port, 64static void option_set_termios(struct usb_serial_port *port,
65 struct termios *old); 65 struct termios *old);
66static void option_break_ctl (struct usb_serial_port *port, int break_state); 66static void option_break_ctl(struct usb_serial_port *port, int break_state);
67static int option_tiocmget (struct usb_serial_port *port, struct file *file); 67static int option_tiocmget(struct usb_serial_port *port, struct file *file);
68static int option_tiocmset (struct usb_serial_port *port, struct file *file, 68static int option_tiocmset(struct usb_serial_port *port, struct file *file,
69 unsigned int set, unsigned int clear); 69 unsigned int set, unsigned int clear);
70static int option_send_setup (struct usb_serial_port *port); 70static int option_send_setup(struct usb_serial_port *port);
71 71
72/* Vendor and product IDs */ 72/* Vendor and product IDs */
73#define OPTION_VENDOR_ID 0x0AF0 73#define OPTION_VENDOR_ID 0x0AF0
@@ -76,7 +76,6 @@ static int option_send_setup (struct usb_serial_port *port);
76#define OPTION_PRODUCT_FUSION 0x6000 76#define OPTION_PRODUCT_FUSION 0x6000
77#define OPTION_PRODUCT_FUSION2 0x6300 77#define OPTION_PRODUCT_FUSION2 0x6300
78 78
79
80static struct usb_device_id option_ids[] = { 79static struct usb_device_id option_ids[] = {
81 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_OLD) }, 80 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_OLD) },
82 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_FUSION) }, 81 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_FUSION) },
@@ -129,7 +128,6 @@ static int debug;
129#define debug 0 128#define debug 0
130#endif 129#endif
131 130
132
133/* per port private data */ 131/* per port private data */
134 132
135#define N_IN_URB 4 133#define N_IN_URB 4
@@ -156,10 +154,8 @@ struct option_port_private {
156 unsigned long tx_start_time[N_OUT_URB]; 154 unsigned long tx_start_time[N_OUT_URB];
157}; 155};
158 156
159
160/* Functions used by new usb-serial code. */ 157/* Functions used by new usb-serial code. */
161static int __init 158static int __init option_init(void)
162option_init (void)
163{ 159{
164 int retval; 160 int retval;
165 retval = usb_serial_register(&option_3port_device); 161 retval = usb_serial_register(&option_3port_device);
@@ -179,8 +175,7 @@ failed_3port_device_register:
179 return retval; 175 return retval;
180} 176}
181 177
182static void __exit 178static void __exit option_exit(void)
183option_exit (void)
184{ 179{
185 usb_deregister (&option_driver); 180 usb_deregister (&option_driver);
186 usb_serial_deregister (&option_3port_device); 181 usb_serial_deregister (&option_3port_device);
@@ -189,39 +184,31 @@ option_exit (void)
189module_init(option_init); 184module_init(option_init);
190module_exit(option_exit); 185module_exit(option_exit);
191 186
192static void 187static void option_rx_throttle(struct usb_serial_port *port)
193option_rx_throttle (struct usb_serial_port *port)
194{ 188{
195 dbg("%s", __FUNCTION__); 189 dbg("%s", __FUNCTION__);
196} 190}
197 191
198 192static void option_rx_unthrottle(struct usb_serial_port *port)
199static void
200option_rx_unthrottle (struct usb_serial_port *port)
201{ 193{
202 dbg("%s", __FUNCTION__); 194 dbg("%s", __FUNCTION__);
203} 195}
204 196
205 197static void option_break_ctl(struct usb_serial_port *port, int break_state)
206static void
207option_break_ctl (struct usb_serial_port *port, int break_state)
208{ 198{
209 /* Unfortunately, I don't know how to send a break */ 199 /* Unfortunately, I don't know how to send a break */
210 dbg("%s", __FUNCTION__); 200 dbg("%s", __FUNCTION__);
211} 201}
212 202
213 203static void option_set_termios(struct usb_serial_port *port,
214static void 204 struct termios *old_termios)
215option_set_termios (struct usb_serial_port *port,
216 struct termios *old_termios)
217{ 205{
218 dbg("%s", __FUNCTION__); 206 dbg("%s", __FUNCTION__);
219 207
220 option_send_setup(port); 208 option_send_setup(port);
221} 209}
222 210
223static int 211static int option_tiocmget(struct usb_serial_port *port, struct file *file)
224option_tiocmget (struct usb_serial_port *port, struct file *file)
225{ 212{
226 unsigned int value; 213 unsigned int value;
227 struct option_port_private *portdata; 214 struct option_port_private *portdata;
@@ -238,9 +225,8 @@ option_tiocmget (struct usb_serial_port *port, struct file *file)
238 return value; 225 return value;
239} 226}
240 227
241static int 228static int option_tiocmset(struct usb_serial_port *port, struct file *file,
242option_tiocmset (struct usb_serial_port *port, struct file *file, 229 unsigned int set, unsigned int clear)
243 unsigned int set, unsigned int clear)
244{ 230{
245 struct option_port_private *portdata; 231 struct option_port_private *portdata;
246 232
@@ -258,17 +244,15 @@ option_tiocmset (struct usb_serial_port *port, struct file *file,
258 return option_send_setup(port); 244 return option_send_setup(port);
259} 245}
260 246
261static int 247static int option_ioctl(struct usb_serial_port *port, struct file *file,
262option_ioctl (struct usb_serial_port *port, struct file *file, 248 unsigned int cmd, unsigned long arg)
263 unsigned int cmd, unsigned long arg)
264{ 249{
265 return -ENOIOCTLCMD; 250 return -ENOIOCTLCMD;
266} 251}
267 252
268/* Write */ 253/* Write */
269static int 254static int option_write(struct usb_serial_port *port,
270option_write (struct usb_serial_port *port, 255 const unsigned char *buf, int count)
271 const unsigned char *buf, int count)
272{ 256{
273 struct option_port_private *portdata; 257 struct option_port_private *portdata;
274 int i; 258 int i;
@@ -289,28 +273,29 @@ option_write (struct usb_serial_port *port,
289 273
290 this_urb = portdata->out_urbs[i]; 274 this_urb = portdata->out_urbs[i];
291 if (this_urb->status == -EINPROGRESS) { 275 if (this_urb->status == -EINPROGRESS) {
292 if (this_urb->transfer_flags & URB_ASYNC_UNLINK) 276 if (time_before(jiffies,
293 continue; 277 portdata->tx_start_time[i] + 10 * HZ))
294 if (time_before(jiffies, portdata->tx_start_time[i] + 10 * HZ))
295 continue; 278 continue;
296 this_urb->transfer_flags |= URB_ASYNC_UNLINK;
297 usb_unlink_urb(this_urb); 279 usb_unlink_urb(this_urb);
298 continue; 280 continue;
299 } 281 }
300 if (this_urb->status != 0) 282 if (this_urb->status != 0)
301 dbg("usb_write %p failed (err=%d)", this_urb, this_urb->status); 283 dbg("usb_write %p failed (err=%d)",
284 this_urb, this_urb->status);
302 285
303 dbg("%s: endpoint %d buf %d", __FUNCTION__, usb_pipeendpoint(this_urb->pipe), i); 286 dbg("%s: endpoint %d buf %d", __FUNCTION__,
287 usb_pipeendpoint(this_urb->pipe), i);
304 288
305 /* send the data */ 289 /* send the data */
306 memcpy (this_urb->transfer_buffer, buf, todo); 290 memcpy (this_urb->transfer_buffer, buf, todo);
307 this_urb->transfer_buffer_length = todo; 291 this_urb->transfer_buffer_length = todo;
308 292
309 this_urb->transfer_flags &= ~URB_ASYNC_UNLINK;
310 this_urb->dev = port->serial->dev; 293 this_urb->dev = port->serial->dev;
311 err = usb_submit_urb(this_urb, GFP_ATOMIC); 294 err = usb_submit_urb(this_urb, GFP_ATOMIC);
312 if (err) { 295 if (err) {
313 dbg("usb_submit_urb %p (write bulk) failed (%d, has %d)", this_urb, err, this_urb->status); 296 dbg("usb_submit_urb %p (write bulk) failed "
297 "(%d, has %d)", this_urb,
298 err, this_urb->status);
314 continue; 299 continue;
315 } 300 }
316 portdata->tx_start_time[i] = jiffies; 301 portdata->tx_start_time[i] = jiffies;
@@ -323,8 +308,7 @@ option_write (struct usb_serial_port *port,
323 return count; 308 return count;
324} 309}
325 310
326static void 311static void option_indat_callback(struct urb *urb, struct pt_regs *regs)
327option_indat_callback (struct urb *urb, struct pt_regs *regs)
328{ 312{
329 int i, err; 313 int i, err;
330 int endpoint; 314 int endpoint;
@@ -357,14 +341,14 @@ option_indat_callback (struct urb *urb, struct pt_regs *regs)
357 if (port->open_count && urb->status != -ESHUTDOWN) { 341 if (port->open_count && urb->status != -ESHUTDOWN) {
358 err = usb_submit_urb(urb, GFP_ATOMIC); 342 err = usb_submit_urb(urb, GFP_ATOMIC);
359 if (err) 343 if (err)
360 printk(KERN_ERR "%s: resubmit read urb failed. (%d)", __FUNCTION__, err); 344 printk(KERN_ERR "%s: resubmit read urb failed. "
345 "(%d)", __FUNCTION__, err);
361 } 346 }
362 } 347 }
363 return; 348 return;
364} 349}
365 350
366static void 351static void option_outdat_callback(struct urb *urb, struct pt_regs *regs)
367option_outdat_callback (struct urb *urb, struct pt_regs *regs)
368{ 352{
369 struct usb_serial_port *port; 353 struct usb_serial_port *port;
370 354
@@ -376,8 +360,7 @@ option_outdat_callback (struct urb *urb, struct pt_regs *regs)
376 schedule_work(&port->work); 360 schedule_work(&port->work);
377} 361}
378 362
379static void 363static void option_instat_callback(struct urb *urb, struct pt_regs *regs)
380option_instat_callback (struct urb *urb, struct pt_regs *regs)
381{ 364{
382 int err; 365 int err;
383 struct usb_serial_port *port = (struct usb_serial_port *) urb->context; 366 struct usb_serial_port *port = (struct usb_serial_port *) urb->context;
@@ -395,10 +378,12 @@ option_instat_callback (struct urb *urb, struct pt_regs *regs)
395 dbg("%s: NULL req_pkt\n", __FUNCTION__); 378 dbg("%s: NULL req_pkt\n", __FUNCTION__);
396 return; 379 return;
397 } 380 }
398 if ((req_pkt->bRequestType == 0xA1) && (req_pkt->bRequest == 0x20)) { 381 if ((req_pkt->bRequestType == 0xA1) &&
382 (req_pkt->bRequest == 0x20)) {
399 int old_dcd_state; 383 int old_dcd_state;
400 unsigned char signals = *((unsigned char *) 384 unsigned char signals = *((unsigned char *)
401 urb->transfer_buffer + sizeof(struct usb_ctrlrequest)); 385 urb->transfer_buffer +
386 sizeof(struct usb_ctrlrequest));
402 387
403 dbg("%s: signal x%x", __FUNCTION__, signals); 388 dbg("%s: signal x%x", __FUNCTION__, signals);
404 389
@@ -408,12 +393,13 @@ option_instat_callback (struct urb *urb, struct pt_regs *regs)
408 portdata->dsr_state = ((signals & 0x02) ? 1 : 0); 393 portdata->dsr_state = ((signals & 0x02) ? 1 : 0);
409 portdata->ri_state = ((signals & 0x08) ? 1 : 0); 394 portdata->ri_state = ((signals & 0x08) ? 1 : 0);
410 395
411 if (port->tty && !C_CLOCAL(port->tty) 396 if (port->tty && !C_CLOCAL(port->tty) &&
412 && old_dcd_state && !portdata->dcd_state) { 397 old_dcd_state && !portdata->dcd_state)
413 tty_hangup(port->tty); 398 tty_hangup(port->tty);
414 } 399 } else {
415 } else 400 dbg("%s: type %x req %x", __FUNCTION__,
416 dbg("%s: type %x req %x", __FUNCTION__, req_pkt->bRequestType,req_pkt->bRequest); 401 req_pkt->bRequestType,req_pkt->bRequest);
402 }
417 } else 403 } else
418 dbg("%s: error %d", __FUNCTION__, urb->status); 404 dbg("%s: error %d", __FUNCTION__, urb->status);
419 405
@@ -422,13 +408,12 @@ option_instat_callback (struct urb *urb, struct pt_regs *regs)
422 urb->dev = serial->dev; 408 urb->dev = serial->dev;
423 err = usb_submit_urb(urb, GFP_ATOMIC); 409 err = usb_submit_urb(urb, GFP_ATOMIC);
424 if (err) 410 if (err)
425 dbg("%s: resubmit intr urb failed. (%d)", __FUNCTION__, err); 411 dbg("%s: resubmit intr urb failed. (%d)",
412 __FUNCTION__, err);
426 } 413 }
427} 414}
428 415
429 416static int option_write_room(struct usb_serial_port *port)
430static int
431option_write_room (struct usb_serial_port *port)
432{ 417{
433 struct option_port_private *portdata; 418 struct option_port_private *portdata;
434 int i; 419 int i;
@@ -447,9 +432,7 @@ option_write_room (struct usb_serial_port *port)
447 return data_len; 432 return data_len;
448} 433}
449 434
450 435static int option_chars_in_buffer(struct usb_serial_port *port)
451static int
452option_chars_in_buffer (struct usb_serial_port *port)
453{ 436{
454 struct option_port_private *portdata; 437 struct option_port_private *portdata;
455 int i; 438 int i;
@@ -467,9 +450,7 @@ option_chars_in_buffer (struct usb_serial_port *port)
467 return data_len; 450 return data_len;
468} 451}
469 452
470 453static int option_open(struct usb_serial_port *port, struct file *filp)
471static int
472option_open (struct usb_serial_port *port, struct file *filp)
473{ 454{
474 struct option_port_private *portdata; 455 struct option_port_private *portdata;
475 struct usb_serial *serial = port->serial; 456 struct usb_serial *serial = port->serial;
@@ -490,17 +471,21 @@ option_open (struct usb_serial_port *port, struct file *filp)
490 if (! urb) 471 if (! urb)
491 continue; 472 continue;
492 if (urb->dev != serial->dev) { 473 if (urb->dev != serial->dev) {
493 dbg("%s: dev %p != %p", __FUNCTION__, urb->dev, serial->dev); 474 dbg("%s: dev %p != %p", __FUNCTION__,
475 urb->dev, serial->dev);
494 continue; 476 continue;
495 } 477 }
496 478
497 /* make sure endpoint data toggle is synchronized with the device */ 479 /*
498 480 * make sure endpoint data toggle is synchronized with the
481 * device
482 */
499 usb_clear_halt(urb->dev, urb->pipe); 483 usb_clear_halt(urb->dev, urb->pipe);
500 484
501 err = usb_submit_urb(urb, GFP_KERNEL); 485 err = usb_submit_urb(urb, GFP_KERNEL);
502 if (err) { 486 if (err) {
503 dbg("%s: submit urb %d failed (%d) %d", __FUNCTION__, i, err, 487 dbg("%s: submit urb %d failed (%d) %d",
488 __FUNCTION__, i, err,
504 urb->transfer_buffer_length); 489 urb->transfer_buffer_length);
505 } 490 }
506 } 491 }
@@ -511,7 +496,8 @@ option_open (struct usb_serial_port *port, struct file *filp)
511 if (! urb) 496 if (! urb)
512 continue; 497 continue;
513 urb->dev = serial->dev; 498 urb->dev = serial->dev;
514 /* usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe), usb_pipeout(urb->pipe), 0); */ 499 /* usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe),
500 usb_pipeout(urb->pipe), 0); */
515 } 501 }
516 502
517 port->tty->low_latency = 1; 503 port->tty->low_latency = 1;
@@ -521,17 +507,13 @@ option_open (struct usb_serial_port *port, struct file *filp)
521 return (0); 507 return (0);
522} 508}
523 509
524static inline void 510static inline void stop_urb(struct urb *urb)
525stop_urb (struct urb *urb)
526{ 511{
527 if (urb && urb->status == -EINPROGRESS) { 512 if (urb && urb->status == -EINPROGRESS)
528 urb->transfer_flags &= ~URB_ASYNC_UNLINK;
529 usb_kill_urb(urb); 513 usb_kill_urb(urb);
530 }
531} 514}
532 515
533static void 516static void option_close(struct usb_serial_port *port, struct file *filp)
534option_close (struct usb_serial_port *port, struct file *filp)
535{ 517{
536 int i; 518 int i;
537 struct usb_serial *serial = port->serial; 519 struct usb_serial *serial = port->serial;
@@ -555,12 +537,10 @@ option_close (struct usb_serial_port *port, struct file *filp)
555 port->tty = NULL; 537 port->tty = NULL;
556} 538}
557 539
558
559/* Helper functions used by option_setup_urbs */ 540/* Helper functions used by option_setup_urbs */
560static struct urb * 541static struct urb *option_setup_urb(struct usb_serial *serial, int endpoint,
561option_setup_urb (struct usb_serial *serial, int endpoint, 542 int dir, void *ctx, char *buf, int len,
562 int dir, void *ctx, char *buf, int len, 543 void (*callback)(struct urb *, struct pt_regs *regs))
563 void (*callback)(struct urb *, struct pt_regs *regs))
564{ 544{
565 struct urb *urb; 545 struct urb *urb;
566 546
@@ -582,8 +562,7 @@ option_setup_urb (struct usb_serial *serial, int endpoint,
582} 562}
583 563
584/* Setup urbs */ 564/* Setup urbs */
585static void 565static void option_setup_urbs(struct usb_serial *serial)
586option_setup_urbs (struct usb_serial *serial)
587{ 566{
588 int j; 567 int j;
589 struct usb_serial_port *port; 568 struct usb_serial_port *port;
@@ -609,9 +588,7 @@ option_setup_urbs (struct usb_serial *serial)
609 } 588 }
610} 589}
611 590
612 591static int option_send_setup(struct usb_serial_port *port)
613static int
614option_send_setup (struct usb_serial_port *port)
615{ 592{
616 struct usb_serial *serial = port->serial; 593 struct usb_serial *serial = port->serial;
617 struct option_port_private *portdata; 594 struct option_port_private *portdata;
@@ -627,16 +604,15 @@ option_send_setup (struct usb_serial_port *port)
627 if (portdata->rts_state) 604 if (portdata->rts_state)
628 val |= 0x02; 605 val |= 0x02;
629 606
630 return usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), 607 return usb_control_msg(serial->dev,
631 0x22,0x21,val,0,NULL,0,USB_CTRL_SET_TIMEOUT); 608 usb_rcvctrlpipe(serial->dev, 0),
609 0x22,0x21,val,0,NULL,0,USB_CTRL_SET_TIMEOUT);
632 } 610 }
633 611
634 return 0; 612 return 0;
635} 613}
636 614
637 615static int option_startup(struct usb_serial *serial)
638static int
639option_startup (struct usb_serial *serial)
640{ 616{
641 int i, err; 617 int i, err;
642 struct usb_serial_port *port; 618 struct usb_serial_port *port;
@@ -647,9 +623,10 @@ option_startup (struct usb_serial *serial)
647 /* Now setup per port private data */ 623 /* Now setup per port private data */
648 for (i = 0; i < serial->num_ports; i++) { 624 for (i = 0; i < serial->num_ports; i++) {
649 port = serial->port[i]; 625 port = serial->port[i];
650 portdata = kmalloc(sizeof(struct option_port_private), GFP_KERNEL); 626 portdata = kmalloc(sizeof(*portdata), GFP_KERNEL);
651 if (!portdata) { 627 if (!portdata) {
652 dbg("%s: kmalloc for option_port_private (%d) failed!.", __FUNCTION__, i); 628 dbg("%s: kmalloc for option_port_private (%d) failed!.",
629 __FUNCTION__, i);
653 return (1); 630 return (1);
654 } 631 }
655 memset(portdata, 0, sizeof(struct option_port_private)); 632 memset(portdata, 0, sizeof(struct option_port_private));
@@ -660,7 +637,8 @@ option_startup (struct usb_serial *serial)
660 continue; 637 continue;
661 err = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); 638 err = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
662 if (err) 639 if (err)
663 dbg("%s: submit irq_in urb failed %d", __FUNCTION__, err); 640 dbg("%s: submit irq_in urb failed %d",
641 __FUNCTION__, err);
664 } 642 }
665 643
666 option_setup_urbs(serial); 644 option_setup_urbs(serial);
@@ -668,8 +646,7 @@ option_startup (struct usb_serial *serial)
668 return (0); 646 return (0);
669} 647}
670 648
671static void 649static void option_shutdown(struct usb_serial *serial)
672option_shutdown (struct usb_serial *serial)
673{ 650{
674 int i, j; 651 int i, j;
675 struct usb_serial_port *port; 652 struct usb_serial_port *port;