aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/serial
diff options
context:
space:
mode:
authorJohan Hovold <jhovold@gmail.com>2012-11-18 07:23:30 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-11-21 16:33:55 -0500
commit70d25eeeba1b7e471fc4e05ad0d8c451aab3cf5e (patch)
tree7cc8bda9a7eeb973dafef6ac6bc51238a73bde73 /drivers/usb/serial
parent2a2c511ca62c87ead992bff0e3cd43a32b28e6e0 (diff)
USB: opticon: make private data port specific
Make private data port specific and move allocation and deallocation to port_probe and port_remove. Signed-off-by: Johan Hovold <jhovold@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/usb/serial')
-rw-r--r--drivers/usb/serial/opticon.c69
1 files changed, 37 insertions, 32 deletions
diff --git a/drivers/usb/serial/opticon.c b/drivers/usb/serial/opticon.c
index 2fb71d8c3a95..0178cc748c0a 100644
--- a/drivers/usb/serial/opticon.c
+++ b/drivers/usb/serial/opticon.c
@@ -168,7 +168,7 @@ static int send_control_msg(struct usb_serial_port *port, u8 requesttype,
168 168
169static int opticon_open(struct tty_struct *tty, struct usb_serial_port *port) 169static int opticon_open(struct tty_struct *tty, struct usb_serial_port *port)
170{ 170{
171 struct opticon_private *priv = usb_get_serial_data(port->serial); 171 struct opticon_private *priv = usb_get_serial_port_data(port);
172 unsigned long flags; 172 unsigned long flags;
173 int result = 0; 173 int result = 0;
174 174
@@ -198,7 +198,7 @@ static int opticon_open(struct tty_struct *tty, struct usb_serial_port *port)
198 198
199static void opticon_close(struct usb_serial_port *port) 199static void opticon_close(struct usb_serial_port *port)
200{ 200{
201 struct opticon_private *priv = usb_get_serial_data(port->serial); 201 struct opticon_private *priv = usb_get_serial_port_data(port);
202 202
203 /* shutdown our urbs */ 203 /* shutdown our urbs */
204 usb_kill_urb(priv->bulk_read_urb); 204 usb_kill_urb(priv->bulk_read_urb);
@@ -231,7 +231,7 @@ static void opticon_write_control_callback(struct urb *urb)
231static int opticon_write(struct tty_struct *tty, struct usb_serial_port *port, 231static int opticon_write(struct tty_struct *tty, struct usb_serial_port *port,
232 const unsigned char *buf, int count) 232 const unsigned char *buf, int count)
233{ 233{
234 struct opticon_private *priv = usb_get_serial_data(port->serial); 234 struct opticon_private *priv = usb_get_serial_port_data(port);
235 struct usb_serial *serial = port->serial; 235 struct usb_serial *serial = port->serial;
236 struct urb *urb; 236 struct urb *urb;
237 unsigned char *buffer; 237 unsigned char *buffer;
@@ -318,7 +318,7 @@ error_no_buffer:
318static int opticon_write_room(struct tty_struct *tty) 318static int opticon_write_room(struct tty_struct *tty)
319{ 319{
320 struct usb_serial_port *port = tty->driver_data; 320 struct usb_serial_port *port = tty->driver_data;
321 struct opticon_private *priv = usb_get_serial_data(port->serial); 321 struct opticon_private *priv = usb_get_serial_port_data(port);
322 unsigned long flags; 322 unsigned long flags;
323 323
324 /* 324 /*
@@ -340,7 +340,7 @@ static int opticon_write_room(struct tty_struct *tty)
340static void opticon_throttle(struct tty_struct *tty) 340static void opticon_throttle(struct tty_struct *tty)
341{ 341{
342 struct usb_serial_port *port = tty->driver_data; 342 struct usb_serial_port *port = tty->driver_data;
343 struct opticon_private *priv = usb_get_serial_data(port->serial); 343 struct opticon_private *priv = usb_get_serial_port_data(port);
344 unsigned long flags; 344 unsigned long flags;
345 345
346 spin_lock_irqsave(&priv->lock, flags); 346 spin_lock_irqsave(&priv->lock, flags);
@@ -352,7 +352,7 @@ static void opticon_throttle(struct tty_struct *tty)
352static void opticon_unthrottle(struct tty_struct *tty) 352static void opticon_unthrottle(struct tty_struct *tty)
353{ 353{
354 struct usb_serial_port *port = tty->driver_data; 354 struct usb_serial_port *port = tty->driver_data;
355 struct opticon_private *priv = usb_get_serial_data(port->serial); 355 struct opticon_private *priv = usb_get_serial_port_data(port);
356 unsigned long flags; 356 unsigned long flags;
357 int result, was_throttled; 357 int result, was_throttled;
358 358
@@ -374,7 +374,7 @@ static void opticon_unthrottle(struct tty_struct *tty)
374static int opticon_tiocmget(struct tty_struct *tty) 374static int opticon_tiocmget(struct tty_struct *tty)
375{ 375{
376 struct usb_serial_port *port = tty->driver_data; 376 struct usb_serial_port *port = tty->driver_data;
377 struct opticon_private *priv = usb_get_serial_data(port->serial); 377 struct opticon_private *priv = usb_get_serial_port_data(port);
378 unsigned long flags; 378 unsigned long flags;
379 int result = 0; 379 int result = 0;
380 380
@@ -394,7 +394,7 @@ static int opticon_tiocmset(struct tty_struct *tty,
394{ 394{
395 struct usb_serial_port *port = tty->driver_data; 395 struct usb_serial_port *port = tty->driver_data;
396 struct usb_serial *serial = port->serial; 396 struct usb_serial *serial = port->serial;
397 struct opticon_private *priv = usb_get_serial_data(port->serial); 397 struct opticon_private *priv = usb_get_serial_port_data(port);
398 unsigned long flags; 398 unsigned long flags;
399 bool rts; 399 bool rts;
400 bool changed = false; 400 bool changed = false;
@@ -455,7 +455,7 @@ static int opticon_ioctl(struct tty_struct *tty,
455 unsigned int cmd, unsigned long arg) 455 unsigned int cmd, unsigned long arg)
456{ 456{
457 struct usb_serial_port *port = tty->driver_data; 457 struct usb_serial_port *port = tty->driver_data;
458 struct opticon_private *priv = usb_get_serial_data(port->serial); 458 struct opticon_private *priv = usb_get_serial_port_data(port);
459 459
460 dev_dbg(&port->dev, "%s - port %d, cmd = 0x%x\n", __func__, port->number, cmd); 460 dev_dbg(&port->dev, "%s - port %d, cmd = 0x%x\n", __func__, port->number, cmd);
461 461
@@ -470,37 +470,37 @@ static int opticon_ioctl(struct tty_struct *tty,
470 470
471static int opticon_startup(struct usb_serial *serial) 471static int opticon_startup(struct usb_serial *serial)
472{ 472{
473 struct opticon_private *priv;
474 int retval = -ENOMEM;
475
476 if (!serial->num_bulk_in) { 473 if (!serial->num_bulk_in) {
477 dev_err(&serial->dev->dev, "no bulk in endpoint\n"); 474 dev_err(&serial->dev->dev, "no bulk in endpoint\n");
478 return -ENODEV; 475 return -ENODEV;
479 } 476 }
480 477
481 /* create our private serial structure */ 478 return 0;
479}
480
481static int opticon_port_probe(struct usb_serial_port *port)
482{
483 struct usb_serial *serial = port->serial;
484 struct opticon_private *priv;
485 int retval = -ENOMEM;
486
482 priv = kzalloc(sizeof(*priv), GFP_KERNEL); 487 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
483 if (priv == NULL) { 488 if (!priv)
484 dev_err(&serial->dev->dev, "%s - Out of memory\n", __func__);
485 return -ENOMEM; 489 return -ENOMEM;
486 } 490
487 spin_lock_init(&priv->lock); 491 spin_lock_init(&priv->lock);
488 priv->port = serial->port[0]; 492 priv->port = port;
489 493
490 priv->bulk_read_urb = usb_alloc_urb(0, GFP_KERNEL); 494 priv->bulk_read_urb = usb_alloc_urb(0, GFP_KERNEL);
491 if (!priv->bulk_read_urb) { 495 if (!priv->bulk_read_urb)
492 dev_err(&serial->dev->dev, "out of memory\n");
493 goto error; 496 goto error;
494 }
495 497
496 priv->buffer_size = 2 * priv->port->bulk_in_size; 498 priv->buffer_size = 2 * port->bulk_in_size;
497 priv->bulk_in_buffer = kmalloc(priv->buffer_size, GFP_KERNEL); 499 priv->bulk_in_buffer = kmalloc(priv->buffer_size, GFP_KERNEL);
498 if (!priv->bulk_in_buffer) { 500 if (!priv->bulk_in_buffer)
499 dev_err(&serial->dev->dev, "out of memory\n");
500 goto error; 501 goto error;
501 }
502 502
503 priv->bulk_address = priv->port->bulk_in_endpointAddress; 503 priv->bulk_address = port->bulk_in_endpointAddress;
504 504
505 usb_fill_bulk_urb(priv->bulk_read_urb, serial->dev, 505 usb_fill_bulk_urb(priv->bulk_read_urb, serial->dev,
506 usb_rcvbulkpipe(serial->dev, 506 usb_rcvbulkpipe(serial->dev,
@@ -508,9 +508,9 @@ static int opticon_startup(struct usb_serial *serial)
508 priv->bulk_in_buffer, priv->buffer_size, 508 priv->bulk_in_buffer, priv->buffer_size,
509 opticon_read_bulk_callback, priv); 509 opticon_read_bulk_callback, priv);
510 510
511 usb_set_serial_data(serial, priv); 511 usb_set_serial_port_data(port, priv);
512 return 0;
513 512
513 return 0;
514error: 514error:
515 usb_free_urb(priv->bulk_read_urb); 515 usb_free_urb(priv->bulk_read_urb);
516 kfree(priv->bulk_in_buffer); 516 kfree(priv->bulk_in_buffer);
@@ -518,18 +518,22 @@ error:
518 return retval; 518 return retval;
519} 519}
520 520
521static void opticon_release(struct usb_serial *serial) 521static int opticon_port_remove(struct usb_serial_port *port)
522{ 522{
523 struct opticon_private *priv = usb_get_serial_data(serial); 523 struct opticon_private *priv = usb_get_serial_port_data(port);
524 524
525 usb_free_urb(priv->bulk_read_urb); 525 usb_free_urb(priv->bulk_read_urb);
526 kfree(priv->bulk_in_buffer); 526 kfree(priv->bulk_in_buffer);
527 kfree(priv); 527 kfree(priv);
528
529 return 0;
528} 530}
529 531
530static int opticon_suspend(struct usb_serial *serial, pm_message_t message) 532static int opticon_suspend(struct usb_serial *serial, pm_message_t message)
531{ 533{
532 struct opticon_private *priv = usb_get_serial_data(serial); 534 struct opticon_private *priv;
535
536 priv = usb_get_serial_port_data(serial->port[0]);
533 537
534 usb_kill_urb(priv->bulk_read_urb); 538 usb_kill_urb(priv->bulk_read_urb);
535 return 0; 539 return 0;
@@ -537,8 +541,8 @@ static int opticon_suspend(struct usb_serial *serial, pm_message_t message)
537 541
538static int opticon_resume(struct usb_serial *serial) 542static int opticon_resume(struct usb_serial *serial)
539{ 543{
540 struct opticon_private *priv = usb_get_serial_data(serial);
541 struct usb_serial_port *port = serial->port[0]; 544 struct usb_serial_port *port = serial->port[0];
545 struct opticon_private *priv = usb_get_serial_port_data(port);
542 int result; 546 int result;
543 547
544 mutex_lock(&port->port.mutex); 548 mutex_lock(&port->port.mutex);
@@ -559,11 +563,12 @@ static struct usb_serial_driver opticon_device = {
559 .id_table = id_table, 563 .id_table = id_table,
560 .num_ports = 1, 564 .num_ports = 1,
561 .attach = opticon_startup, 565 .attach = opticon_startup,
566 .port_probe = opticon_port_probe,
567 .port_remove = opticon_port_remove,
562 .open = opticon_open, 568 .open = opticon_open,
563 .close = opticon_close, 569 .close = opticon_close,
564 .write = opticon_write, 570 .write = opticon_write,
565 .write_room = opticon_write_room, 571 .write_room = opticon_write_room,
566 .release = opticon_release,
567 .throttle = opticon_throttle, 572 .throttle = opticon_throttle,
568 .unthrottle = opticon_unthrottle, 573 .unthrottle = opticon_unthrottle,
569 .ioctl = opticon_ioctl, 574 .ioctl = opticon_ioctl,