Lines Matching +full:serial +full:- +full:id

1 // SPDX-License-Identifier: GPL-2.0
3 * USB Serial Converter driver
5 * Copyright (C) 2009 - 2013 Johan Hovold (jhovold@gmail.com)
6 * Copyright (C) 1999 - 2012 Greg Kroah-Hartman (greg@kroah.com)
13 * See Documentation/usb/usb-serial.rst for more information on using this
33 #include <linux/serial.h>
35 #include <linux/usb/serial.h>
39 #define DRIVER_AUTHOR "Greg Kroah-Hartman <gregkh@linuxfoundation.org>"
40 #define DRIVER_DESC "USB Serial Driver core"
46 the MODULE_DEVICE_TABLE declarations in each serial driver
48 via modprobe, and modprobe will load usbserial because the serial
57 * Look up the serial port structure. If it is found and it hasn't been
63 struct usb_serial *serial; in usb_serial_port_get_by_minor() local
71 serial = port->serial; in usb_serial_port_get_by_minor()
72 mutex_lock(&serial->disc_mutex); in usb_serial_port_get_by_minor()
73 if (serial->disconnected) { in usb_serial_port_get_by_minor()
74 mutex_unlock(&serial->disc_mutex); in usb_serial_port_get_by_minor()
77 kref_get(&serial->kref); in usb_serial_port_get_by_minor()
84 static int allocate_minors(struct usb_serial *serial, int num_ports) in allocate_minors() argument
90 dev_dbg(&serial->interface->dev, "%s %d\n", __func__, num_ports); in allocate_minors()
94 port = serial->port[i]; in allocate_minors()
99 port->minor = minor; in allocate_minors()
100 port->port_number = i; in allocate_minors()
102 serial->minors_reserved = 1; in allocate_minors()
108 idr_remove(&serial_minors, serial->port[j]->minor); in allocate_minors()
113 static void release_minors(struct usb_serial *serial) in release_minors() argument
118 for (i = 0; i < serial->num_ports; ++i) in release_minors()
119 idr_remove(&serial_minors, serial->port[i]->minor); in release_minors()
121 serial->minors_reserved = 0; in release_minors()
124 int usb_serial_claim_interface(struct usb_serial *serial, struct usb_interface *intf) in usb_serial_claim_interface() argument
126 struct usb_driver *driver = serial->type->usb_driver; in usb_serial_claim_interface()
129 if (serial->sibling) in usb_serial_claim_interface()
130 return -EBUSY; in usb_serial_claim_interface()
132 ret = usb_driver_claim_interface(driver, intf, serial); in usb_serial_claim_interface()
134 dev_err(&serial->interface->dev, in usb_serial_claim_interface()
139 serial->sibling = intf; in usb_serial_claim_interface()
145 static void release_sibling(struct usb_serial *serial, struct usb_interface *intf) in release_sibling() argument
147 struct usb_driver *driver = serial->type->usb_driver; in release_sibling()
150 if (!serial->sibling) in release_sibling()
153 if (intf == serial->sibling) in release_sibling()
154 sibling = serial->interface; in release_sibling()
156 sibling = serial->sibling; in release_sibling()
164 struct usb_serial *serial; in destroy_serial() local
168 serial = to_usb_serial(kref); in destroy_serial()
171 if (serial->minors_reserved) in destroy_serial()
172 release_minors(serial); in destroy_serial()
174 if (serial->attached && serial->type->release) in destroy_serial()
175 serial->type->release(serial); in destroy_serial()
178 for (i = 0; i < serial->num_port_pointers; ++i) { in destroy_serial()
179 port = serial->port[i]; in destroy_serial()
181 port->serial = NULL; in destroy_serial()
182 put_device(&port->dev); in destroy_serial()
186 usb_put_intf(serial->interface); in destroy_serial()
187 usb_put_dev(serial->dev); in destroy_serial()
188 kfree(serial); in destroy_serial()
191 void usb_serial_put(struct usb_serial *serial) in usb_serial_put() argument
193 kref_put(&serial->kref, destroy_serial); in usb_serial_put()
201 * serial_install - install tty
206 * USB serial settings but permit them to be overridden by
207 * serial->type->init_termios on first open.
216 int idx = tty->index; in serial_install()
217 struct usb_serial *serial; in serial_install() local
220 int retval = -ENODEV; in serial_install()
226 serial = port->serial; in serial_install()
227 if (!try_module_get(serial->type->driver.owner)) in serial_install()
230 init_termios = (driver->termios[idx] == NULL); in serial_install()
236 mutex_unlock(&serial->disc_mutex); in serial_install()
239 if (init_termios && serial->type->init_termios) in serial_install()
240 serial->type->init_termios(tty); in serial_install()
242 tty->driver_data = port; in serial_install()
247 module_put(serial->type->driver.owner); in serial_install()
249 usb_serial_put(serial); in serial_install()
250 mutex_unlock(&serial->disc_mutex); in serial_install()
258 struct usb_serial *serial = port->serial; in serial_port_activate() local
261 mutex_lock(&serial->disc_mutex); in serial_port_activate()
262 if (serial->disconnected) { in serial_port_activate()
263 retval = -ENODEV; in serial_port_activate()
267 retval = usb_autopm_get_interface(serial->interface); in serial_port_activate()
271 retval = port->serial->type->open(tty, port); in serial_port_activate()
273 usb_autopm_put_interface(serial->interface); in serial_port_activate()
275 mutex_unlock(&serial->disc_mutex); in serial_port_activate()
285 struct usb_serial_port *port = tty->driver_data; in serial_open()
287 dev_dbg(&port->dev, "%s\n", __func__); in serial_open()
289 return tty_port_open(&port->port, tty, filp); in serial_open()
293 * serial_port_shutdown - shut down hardware
296 * Shut down a USB serial port. Serialized against activate by the
298 * of calls by the tty-port initialized flag.
306 struct usb_serial_driver *drv = port->serial->type; in serial_port_shutdown()
308 if (drv->close) in serial_port_shutdown()
309 drv->close(port); in serial_port_shutdown()
311 usb_autopm_put_interface(port->serial->interface); in serial_port_shutdown()
316 struct usb_serial_port *port = tty->driver_data; in serial_hangup()
318 dev_dbg(&port->dev, "%s\n", __func__); in serial_hangup()
320 tty_port_hangup(&port->port); in serial_hangup()
325 struct usb_serial_port *port = tty->driver_data; in serial_close()
327 dev_dbg(&port->dev, "%s\n", __func__); in serial_close()
329 tty_port_close(&port->port, tty, filp); in serial_close()
333 * serial_cleanup - free resources post close/hangup
343 struct usb_serial_port *port = tty->driver_data; in serial_cleanup()
344 struct usb_serial *serial; in serial_cleanup() local
347 dev_dbg(&port->dev, "%s\n", __func__); in serial_cleanup()
352 if (port->port.console) in serial_cleanup()
355 tty->driver_data = NULL; in serial_cleanup()
357 serial = port->serial; in serial_cleanup()
358 owner = serial->type->driver.owner; in serial_cleanup()
360 usb_serial_put(serial); in serial_cleanup()
366 struct usb_serial_port *port = tty->driver_data; in serial_write()
367 int retval = -ENODEV; in serial_write()
369 if (port->serial->dev->state == USB_STATE_NOTATTACHED) in serial_write()
372 dev_dbg(&port->dev, "%s - %zu byte(s)\n", __func__, count); in serial_write()
374 retval = port->serial->type->write(tty, port, buf, count); in serial_write()
383 struct usb_serial_port *port = tty->driver_data; in serial_write_room()
385 dev_dbg(&port->dev, "%s\n", __func__); in serial_write_room()
387 return port->serial->type->write_room(tty); in serial_write_room()
392 struct usb_serial_port *port = tty->driver_data; in serial_chars_in_buffer()
393 struct usb_serial *serial = port->serial; in serial_chars_in_buffer() local
395 dev_dbg(&port->dev, "%s\n", __func__); in serial_chars_in_buffer()
397 if (serial->disconnected) in serial_chars_in_buffer()
400 return serial->type->chars_in_buffer(tty); in serial_chars_in_buffer()
405 struct usb_serial_port *port = tty->driver_data; in serial_wait_until_sent()
406 struct usb_serial *serial = port->serial; in serial_wait_until_sent() local
408 dev_dbg(&port->dev, "%s\n", __func__); in serial_wait_until_sent()
410 if (!port->serial->type->wait_until_sent) in serial_wait_until_sent()
413 mutex_lock(&serial->disc_mutex); in serial_wait_until_sent()
414 if (!serial->disconnected) in serial_wait_until_sent()
415 port->serial->type->wait_until_sent(tty, timeout); in serial_wait_until_sent()
416 mutex_unlock(&serial->disc_mutex); in serial_wait_until_sent()
421 struct usb_serial_port *port = tty->driver_data; in serial_throttle()
423 dev_dbg(&port->dev, "%s\n", __func__); in serial_throttle()
425 if (port->serial->type->throttle) in serial_throttle()
426 port->serial->type->throttle(tty); in serial_throttle()
431 struct usb_serial_port *port = tty->driver_data; in serial_unthrottle()
433 dev_dbg(&port->dev, "%s\n", __func__); in serial_unthrottle()
435 if (port->serial->type->unthrottle) in serial_unthrottle()
436 port->serial->type->unthrottle(tty); in serial_unthrottle()
441 struct usb_serial_port *port = tty->driver_data; in serial_get_serial()
442 struct tty_port *tport = &port->port; in serial_get_serial()
445 mutex_lock(&tport->mutex); in serial_get_serial()
447 close_delay = jiffies_to_msecs(tport->close_delay) / 10; in serial_get_serial()
448 closing_wait = tport->closing_wait; in serial_get_serial()
452 ss->line = port->minor; in serial_get_serial()
453 ss->close_delay = close_delay; in serial_get_serial()
454 ss->closing_wait = closing_wait; in serial_get_serial()
456 if (port->serial->type->get_serial) in serial_get_serial()
457 port->serial->type->get_serial(tty, ss); in serial_get_serial()
459 mutex_unlock(&tport->mutex); in serial_get_serial()
466 struct usb_serial_port *port = tty->driver_data; in serial_set_serial()
467 struct tty_port *tport = &port->port; in serial_set_serial()
471 close_delay = msecs_to_jiffies(ss->close_delay * 10); in serial_set_serial()
472 closing_wait = ss->closing_wait; in serial_set_serial()
476 mutex_lock(&tport->mutex); in serial_set_serial()
479 if (close_delay != tport->close_delay || in serial_set_serial()
480 closing_wait != tport->closing_wait) { in serial_set_serial()
481 ret = -EPERM; in serial_set_serial()
486 if (port->serial->type->set_serial) { in serial_set_serial()
487 ret = port->serial->type->set_serial(tty, ss); in serial_set_serial()
492 tport->close_delay = close_delay; in serial_set_serial()
493 tport->closing_wait = closing_wait; in serial_set_serial()
495 mutex_unlock(&tport->mutex); in serial_set_serial()
503 struct usb_serial_port *port = tty->driver_data; in serial_ioctl()
504 int retval = -ENOIOCTLCMD; in serial_ioctl()
506 dev_dbg(&port->dev, "%s - cmd 0x%04x\n", __func__, cmd); in serial_ioctl()
510 if (port->serial->type->tiocmiwait) in serial_ioctl()
511 retval = port->serial->type->tiocmiwait(tty, arg); in serial_ioctl()
514 if (port->serial->type->ioctl) in serial_ioctl()
515 retval = port->serial->type->ioctl(tty, cmd, arg); in serial_ioctl()
524 struct usb_serial_port *port = tty->driver_data; in serial_set_termios()
526 dev_dbg(&port->dev, "%s\n", __func__); in serial_set_termios()
528 if (port->serial->type->set_termios) in serial_set_termios()
529 port->serial->type->set_termios(tty, port, old); in serial_set_termios()
531 tty_termios_copy_hw(&tty->termios, old); in serial_set_termios()
536 struct usb_serial_port *port = tty->driver_data; in serial_break()
538 dev_dbg(&port->dev, "%s\n", __func__); in serial_break()
540 if (port->serial->type->break_ctl) in serial_break()
541 return port->serial->type->break_ctl(tty, break_state); in serial_break()
543 return -ENOTTY; in serial_break()
548 struct usb_serial *serial; in serial_proc_show() local
558 serial = port->serial; in serial_proc_show()
561 if (serial->type->driver.owner) in serial_proc_show()
563 module_name(serial->type->driver.owner)); in serial_proc_show()
565 serial->type->description); in serial_proc_show()
567 le16_to_cpu(serial->dev->descriptor.idVendor), in serial_proc_show()
568 le16_to_cpu(serial->dev->descriptor.idProduct)); in serial_proc_show()
569 seq_printf(m, " num_ports:%d", serial->num_ports); in serial_proc_show()
570 seq_printf(m, " port:%d", port->port_number); in serial_proc_show()
571 usb_make_path(serial->dev, tmp, sizeof(tmp)); in serial_proc_show()
575 usb_serial_put(serial); in serial_proc_show()
576 mutex_unlock(&serial->disc_mutex); in serial_proc_show()
583 struct usb_serial_port *port = tty->driver_data; in serial_tiocmget()
585 dev_dbg(&port->dev, "%s\n", __func__); in serial_tiocmget()
587 if (port->serial->type->tiocmget) in serial_tiocmget()
588 return port->serial->type->tiocmget(tty); in serial_tiocmget()
589 return -ENOTTY; in serial_tiocmget()
595 struct usb_serial_port *port = tty->driver_data; in serial_tiocmset()
597 dev_dbg(&port->dev, "%s\n", __func__); in serial_tiocmset()
599 if (port->serial->type->tiocmset) in serial_tiocmset()
600 return port->serial->type->tiocmset(tty, set, clear); in serial_tiocmset()
601 return -ENOTTY; in serial_tiocmset()
607 struct usb_serial_port *port = tty->driver_data; in serial_get_icount()
609 dev_dbg(&port->dev, "%s\n", __func__); in serial_get_icount()
611 if (port->serial->type->get_icount) in serial_get_icount()
612 return port->serial->type->get_icount(tty, icount); in serial_get_icount()
613 return -ENOTTY; in serial_get_icount()
618 * disciplines have an annoying habit of calling tty->write from
623 schedule_work(&port->work); in usb_serial_port_softint()
632 tty_port_tty_wakeup(&port->port); in usb_serial_port_work()
639 for (i = 0; i < ARRAY_SIZE(port->read_urbs); ++i) in usb_serial_port_poison_urbs()
640 usb_poison_urb(port->read_urbs[i]); in usb_serial_port_poison_urbs()
641 for (i = 0; i < ARRAY_SIZE(port->write_urbs); ++i) in usb_serial_port_poison_urbs()
642 usb_poison_urb(port->write_urbs[i]); in usb_serial_port_poison_urbs()
644 usb_poison_urb(port->interrupt_in_urb); in usb_serial_port_poison_urbs()
645 usb_poison_urb(port->interrupt_out_urb); in usb_serial_port_poison_urbs()
652 for (i = 0; i < ARRAY_SIZE(port->read_urbs); ++i) in usb_serial_port_unpoison_urbs()
653 usb_unpoison_urb(port->read_urbs[i]); in usb_serial_port_unpoison_urbs()
654 for (i = 0; i < ARRAY_SIZE(port->write_urbs); ++i) in usb_serial_port_unpoison_urbs()
655 usb_unpoison_urb(port->write_urbs[i]); in usb_serial_port_unpoison_urbs()
657 usb_unpoison_urb(port->interrupt_in_urb); in usb_serial_port_unpoison_urbs()
658 usb_unpoison_urb(port->interrupt_out_urb); in usb_serial_port_unpoison_urbs()
668 usb_free_urb(port->interrupt_in_urb); in usb_serial_port_release()
669 usb_free_urb(port->interrupt_out_urb); in usb_serial_port_release()
670 for (i = 0; i < ARRAY_SIZE(port->read_urbs); ++i) { in usb_serial_port_release()
671 usb_free_urb(port->read_urbs[i]); in usb_serial_port_release()
672 kfree(port->bulk_in_buffers[i]); in usb_serial_port_release()
674 for (i = 0; i < ARRAY_SIZE(port->write_urbs); ++i) { in usb_serial_port_release()
675 usb_free_urb(port->write_urbs[i]); in usb_serial_port_release()
676 kfree(port->bulk_out_buffers[i]); in usb_serial_port_release()
678 kfifo_free(&port->write_fifo); in usb_serial_port_release()
679 kfree(port->interrupt_in_buffer); in usb_serial_port_release()
680 kfree(port->interrupt_out_buffer); in usb_serial_port_release()
681 tty_port_destroy(&port->port); in usb_serial_port_release()
689 struct usb_serial *serial; in create_serial() local
691 serial = kzalloc(sizeof(*serial), GFP_KERNEL); in create_serial()
692 if (!serial) in create_serial()
694 serial->dev = usb_get_dev(dev); in create_serial()
695 serial->type = driver; in create_serial()
696 serial->interface = usb_get_intf(interface); in create_serial()
697 kref_init(&serial->kref); in create_serial()
698 mutex_init(&serial->disc_mutex); in create_serial()
699 serial->minors_reserved = 0; in create_serial()
701 return serial; in create_serial()
709 spin_lock(&drv->dynids.lock); in match_dynamic_id()
710 list_for_each_entry(dynid, &drv->dynids.list, node) { in match_dynamic_id()
711 if (usb_match_one_id(intf, &dynid->id)) { in match_dynamic_id()
712 spin_unlock(&drv->dynids.lock); in match_dynamic_id()
713 return &dynid->id; in match_dynamic_id()
716 spin_unlock(&drv->dynids.lock); in match_dynamic_id()
723 const struct usb_device_id *id; in get_iface_id() local
725 id = usb_match_id(intf, drv->id_table); in get_iface_id()
726 if (id) { in get_iface_id()
727 dev_dbg(&intf->dev, "static descriptor matches\n"); in get_iface_id()
730 id = match_dynamic_id(intf, drv); in get_iface_id()
731 if (id) in get_iface_id()
732 dev_dbg(&intf->dev, "dynamic descriptor matches\n"); in get_iface_id()
734 return id; in get_iface_id()
741 const struct usb_device_id *id = NULL; in search_serial_device() local
743 struct usb_driver *driver = to_usb_driver(iface->dev.driver); in search_serial_device()
745 /* Check if the usb id matches a known device */ in search_serial_device()
747 if (drv->usb_driver == driver) in search_serial_device()
748 id = get_iface_id(drv, iface); in search_serial_device()
749 if (id) in search_serial_device()
759 struct usb_serial_driver *drv = p->serial->type; in serial_port_carrier_raised()
761 if (drv->carrier_raised) in serial_port_carrier_raised()
762 return drv->carrier_raised(p); in serial_port_carrier_raised()
763 /* No carrier control - don't block */ in serial_port_carrier_raised()
770 struct usb_serial_driver *drv = p->serial->type; in serial_port_dtr_rts()
772 if (drv->dtr_rts) in serial_port_dtr_rts()
773 drv->dtr_rts(p, on); in serial_port_dtr_rts()
781 return sprintf(buf, "%u\n", port->port_number); in port_number_show()
798 static void store_endpoint(struct usb_serial *serial, in store_endpoint() argument
802 struct device *dev = &serial->interface->dev; in store_endpoint()
803 u8 addr = epd->bEndpointAddress; in store_endpoint()
806 if (epds->num_bulk_in == ARRAY_SIZE(epds->bulk_in)) in store_endpoint()
809 epds->bulk_in[epds->num_bulk_in++] = epd; in store_endpoint()
811 if (epds->num_bulk_out == ARRAY_SIZE(epds->bulk_out)) in store_endpoint()
814 epds->bulk_out[epds->num_bulk_out++] = epd; in store_endpoint()
816 if (epds->num_interrupt_in == ARRAY_SIZE(epds->interrupt_in)) in store_endpoint()
819 epds->interrupt_in[epds->num_interrupt_in++] = epd; in store_endpoint()
821 if (epds->num_interrupt_out == ARRAY_SIZE(epds->interrupt_out)) in store_endpoint()
824 epds->interrupt_out[epds->num_interrupt_out++] = epd; in store_endpoint()
828 static void find_endpoints(struct usb_serial *serial, in find_endpoints() argument
836 iface_desc = intf->cur_altsetting; in find_endpoints()
837 for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) { in find_endpoints()
838 epd = &iface_desc->endpoint[i].desc; in find_endpoints()
839 store_endpoint(serial, epds, epd); in find_endpoints()
846 struct usb_serial_driver *type = port->serial->type; in setup_port_bulk_in()
847 struct usb_device *udev = port->serial->dev; in setup_port_bulk_in()
851 buffer_size = max_t(int, type->bulk_in_size, usb_endpoint_maxp(epd)); in setup_port_bulk_in()
852 port->bulk_in_size = buffer_size; in setup_port_bulk_in()
853 port->bulk_in_endpointAddress = epd->bEndpointAddress; in setup_port_bulk_in()
855 for (i = 0; i < ARRAY_SIZE(port->read_urbs); ++i) { in setup_port_bulk_in()
856 set_bit(i, &port->read_urbs_free); in setup_port_bulk_in()
857 port->read_urbs[i] = usb_alloc_urb(0, GFP_KERNEL); in setup_port_bulk_in()
858 if (!port->read_urbs[i]) in setup_port_bulk_in()
859 return -ENOMEM; in setup_port_bulk_in()
860 port->bulk_in_buffers[i] = kmalloc(buffer_size, GFP_KERNEL); in setup_port_bulk_in()
861 if (!port->bulk_in_buffers[i]) in setup_port_bulk_in()
862 return -ENOMEM; in setup_port_bulk_in()
863 usb_fill_bulk_urb(port->read_urbs[i], udev, in setup_port_bulk_in()
864 usb_rcvbulkpipe(udev, epd->bEndpointAddress), in setup_port_bulk_in()
865 port->bulk_in_buffers[i], buffer_size, in setup_port_bulk_in()
866 type->read_bulk_callback, port); in setup_port_bulk_in()
869 port->read_urb = port->read_urbs[0]; in setup_port_bulk_in()
870 port->bulk_in_buffer = port->bulk_in_buffers[0]; in setup_port_bulk_in()
878 struct usb_serial_driver *type = port->serial->type; in setup_port_bulk_out()
879 struct usb_device *udev = port->serial->dev; in setup_port_bulk_out()
883 if (kfifo_alloc(&port->write_fifo, PAGE_SIZE, GFP_KERNEL)) in setup_port_bulk_out()
884 return -ENOMEM; in setup_port_bulk_out()
885 if (type->bulk_out_size) in setup_port_bulk_out()
886 buffer_size = type->bulk_out_size; in setup_port_bulk_out()
889 port->bulk_out_size = buffer_size; in setup_port_bulk_out()
890 port->bulk_out_endpointAddress = epd->bEndpointAddress; in setup_port_bulk_out()
892 for (i = 0; i < ARRAY_SIZE(port->write_urbs); ++i) { in setup_port_bulk_out()
893 set_bit(i, &port->write_urbs_free); in setup_port_bulk_out()
894 port->write_urbs[i] = usb_alloc_urb(0, GFP_KERNEL); in setup_port_bulk_out()
895 if (!port->write_urbs[i]) in setup_port_bulk_out()
896 return -ENOMEM; in setup_port_bulk_out()
897 port->bulk_out_buffers[i] = kmalloc(buffer_size, GFP_KERNEL); in setup_port_bulk_out()
898 if (!port->bulk_out_buffers[i]) in setup_port_bulk_out()
899 return -ENOMEM; in setup_port_bulk_out()
900 usb_fill_bulk_urb(port->write_urbs[i], udev, in setup_port_bulk_out()
901 usb_sndbulkpipe(udev, epd->bEndpointAddress), in setup_port_bulk_out()
902 port->bulk_out_buffers[i], buffer_size, in setup_port_bulk_out()
903 type->write_bulk_callback, port); in setup_port_bulk_out()
906 port->write_urb = port->write_urbs[0]; in setup_port_bulk_out()
907 port->bulk_out_buffer = port->bulk_out_buffers[0]; in setup_port_bulk_out()
915 struct usb_serial_driver *type = port->serial->type; in setup_port_interrupt_in()
916 struct usb_device *udev = port->serial->dev; in setup_port_interrupt_in()
919 port->interrupt_in_urb = usb_alloc_urb(0, GFP_KERNEL); in setup_port_interrupt_in()
920 if (!port->interrupt_in_urb) in setup_port_interrupt_in()
921 return -ENOMEM; in setup_port_interrupt_in()
923 port->interrupt_in_endpointAddress = epd->bEndpointAddress; in setup_port_interrupt_in()
924 port->interrupt_in_buffer = kmalloc(buffer_size, GFP_KERNEL); in setup_port_interrupt_in()
925 if (!port->interrupt_in_buffer) in setup_port_interrupt_in()
926 return -ENOMEM; in setup_port_interrupt_in()
927 usb_fill_int_urb(port->interrupt_in_urb, udev, in setup_port_interrupt_in()
928 usb_rcvintpipe(udev, epd->bEndpointAddress), in setup_port_interrupt_in()
929 port->interrupt_in_buffer, buffer_size, in setup_port_interrupt_in()
930 type->read_int_callback, port, in setup_port_interrupt_in()
931 epd->bInterval); in setup_port_interrupt_in()
939 struct usb_serial_driver *type = port->serial->type; in setup_port_interrupt_out()
940 struct usb_device *udev = port->serial->dev; in setup_port_interrupt_out()
943 port->interrupt_out_urb = usb_alloc_urb(0, GFP_KERNEL); in setup_port_interrupt_out()
944 if (!port->interrupt_out_urb) in setup_port_interrupt_out()
945 return -ENOMEM; in setup_port_interrupt_out()
947 port->interrupt_out_size = buffer_size; in setup_port_interrupt_out()
948 port->interrupt_out_endpointAddress = epd->bEndpointAddress; in setup_port_interrupt_out()
949 port->interrupt_out_buffer = kmalloc(buffer_size, GFP_KERNEL); in setup_port_interrupt_out()
950 if (!port->interrupt_out_buffer) in setup_port_interrupt_out()
951 return -ENOMEM; in setup_port_interrupt_out()
952 usb_fill_int_urb(port->interrupt_out_urb, udev, in setup_port_interrupt_out()
953 usb_sndintpipe(udev, epd->bEndpointAddress), in setup_port_interrupt_out()
954 port->interrupt_out_buffer, buffer_size, in setup_port_interrupt_out()
955 type->write_int_callback, port, in setup_port_interrupt_out()
956 epd->bInterval); in setup_port_interrupt_out()
962 const struct usb_device_id *id) in usb_serial_probe() argument
964 struct device *ddev = &interface->dev; in usb_serial_probe()
966 struct usb_serial *serial = NULL; in usb_serial_probe() local
980 return -ENODEV; in usb_serial_probe()
983 if (!try_module_get(type->driver.owner)) { in usb_serial_probe()
986 return -EIO; in usb_serial_probe()
990 serial = create_serial(dev, interface, type); in usb_serial_probe()
991 if (!serial) { in usb_serial_probe()
992 retval = -ENOMEM; in usb_serial_probe()
997 if (type->probe) { in usb_serial_probe()
998 const struct usb_device_id *id; in usb_serial_probe() local
1000 id = get_iface_id(type, interface); in usb_serial_probe()
1001 retval = type->probe(serial, id); in usb_serial_probe()
1012 retval = -ENOMEM; in usb_serial_probe()
1016 find_endpoints(serial, epds, interface); in usb_serial_probe()
1017 if (serial->sibling) in usb_serial_probe()
1018 find_endpoints(serial, epds, serial->sibling); in usb_serial_probe()
1020 if (epds->num_bulk_in < type->num_bulk_in || in usb_serial_probe()
1021 epds->num_bulk_out < type->num_bulk_out || in usb_serial_probe()
1022 epds->num_interrupt_in < type->num_interrupt_in || in usb_serial_probe()
1023 epds->num_interrupt_out < type->num_interrupt_out) { in usb_serial_probe()
1025 retval = -ENODEV; in usb_serial_probe()
1029 if (type->calc_num_ports) { in usb_serial_probe()
1030 retval = type->calc_num_ports(serial, epds); in usb_serial_probe()
1037 num_ports = type->num_ports; in usb_serial_probe()
1044 serial->num_ports = (unsigned char)num_ports; in usb_serial_probe()
1045 serial->num_bulk_in = epds->num_bulk_in; in usb_serial_probe()
1046 serial->num_bulk_out = epds->num_bulk_out; in usb_serial_probe()
1047 serial->num_interrupt_in = epds->num_interrupt_in; in usb_serial_probe()
1048 serial->num_interrupt_out = epds->num_interrupt_out; in usb_serial_probe()
1051 dev_info(ddev, "%s converter detected\n", type->description); in usb_serial_probe()
1056 max_endpoints = max(epds->num_bulk_in, epds->num_bulk_out); in usb_serial_probe()
1057 max_endpoints = max(max_endpoints, epds->num_interrupt_in); in usb_serial_probe()
1058 max_endpoints = max(max_endpoints, epds->num_interrupt_out); in usb_serial_probe()
1059 max_endpoints = max(max_endpoints, serial->num_ports); in usb_serial_probe()
1060 serial->num_port_pointers = max_endpoints; in usb_serial_probe()
1066 retval = -ENOMEM; in usb_serial_probe()
1069 tty_port_init(&port->port); in usb_serial_probe()
1070 port->port.ops = &serial_port_ops; in usb_serial_probe()
1071 port->serial = serial; in usb_serial_probe()
1072 spin_lock_init(&port->lock); in usb_serial_probe()
1075 INIT_WORK(&port->work, usb_serial_port_work); in usb_serial_probe()
1076 serial->port[i] = port; in usb_serial_probe()
1077 port->dev.parent = &interface->dev; in usb_serial_probe()
1078 port->dev.driver = NULL; in usb_serial_probe()
1079 port->dev.bus = &usb_serial_bus_type; in usb_serial_probe()
1080 port->dev.release = &usb_serial_port_release; in usb_serial_probe()
1081 port->dev.groups = usb_serial_port_groups; in usb_serial_probe()
1082 device_initialize(&port->dev); in usb_serial_probe()
1086 for (i = 0; i < epds->num_bulk_in; ++i) { in usb_serial_probe()
1087 retval = setup_port_bulk_in(serial->port[i], epds->bulk_in[i]); in usb_serial_probe()
1092 for (i = 0; i < epds->num_bulk_out; ++i) { in usb_serial_probe()
1093 retval = setup_port_bulk_out(serial->port[i], in usb_serial_probe()
1094 epds->bulk_out[i]); in usb_serial_probe()
1099 if (serial->type->read_int_callback) { in usb_serial_probe()
1100 for (i = 0; i < epds->num_interrupt_in; ++i) { in usb_serial_probe()
1101 retval = setup_port_interrupt_in(serial->port[i], in usb_serial_probe()
1102 epds->interrupt_in[i]); in usb_serial_probe()
1106 } else if (epds->num_interrupt_in) { in usb_serial_probe()
1110 if (serial->type->write_int_callback) { in usb_serial_probe()
1111 for (i = 0; i < epds->num_interrupt_out; ++i) { in usb_serial_probe()
1112 retval = setup_port_interrupt_out(serial->port[i], in usb_serial_probe()
1113 epds->interrupt_out[i]); in usb_serial_probe()
1117 } else if (epds->num_interrupt_out) { in usb_serial_probe()
1121 usb_set_intfdata(interface, serial); in usb_serial_probe()
1124 if (type->attach) { in usb_serial_probe()
1125 retval = type->attach(serial); in usb_serial_probe()
1128 serial->attached = 1; in usb_serial_probe()
1131 serial port as it's about to disappear */ in usb_serial_probe()
1132 serial->num_ports = 0; in usb_serial_probe()
1136 serial->attached = 1; in usb_serial_probe()
1139 retval = allocate_minors(serial, num_ports); in usb_serial_probe()
1141 dev_err(ddev, "No more free serial minor numbers\n"); in usb_serial_probe()
1147 port = serial->port[i]; in usb_serial_probe()
1148 dev_set_name(&port->dev, "ttyUSB%d", port->minor); in usb_serial_probe()
1149 dev_dbg(ddev, "registering %s\n", dev_name(&port->dev)); in usb_serial_probe()
1150 device_enable_async_suspend(&port->dev); in usb_serial_probe()
1152 retval = device_add(&port->dev); in usb_serial_probe()
1158 usb_serial_console_init(serial->port[0]->minor); in usb_serial_probe()
1161 module_put(type->driver.owner); in usb_serial_probe()
1167 release_sibling(serial, interface); in usb_serial_probe()
1168 usb_serial_put(serial); in usb_serial_probe()
1170 module_put(type->driver.owner); in usb_serial_probe()
1178 struct usb_serial *serial = usb_get_intfdata(interface); in usb_serial_disconnect() local
1179 struct device *dev = &interface->dev; in usb_serial_disconnect()
1184 if (!serial) in usb_serial_disconnect()
1187 usb_serial_console_disconnect(serial); in usb_serial_disconnect()
1189 mutex_lock(&serial->disc_mutex); in usb_serial_disconnect()
1191 serial->disconnected = 1; in usb_serial_disconnect()
1192 mutex_unlock(&serial->disc_mutex); in usb_serial_disconnect()
1194 for (i = 0; i < serial->num_ports; ++i) { in usb_serial_disconnect()
1195 port = serial->port[i]; in usb_serial_disconnect()
1196 tty = tty_port_tty_get(&port->port); in usb_serial_disconnect()
1202 wake_up_interruptible(&port->port.delta_msr_wait); in usb_serial_disconnect()
1203 cancel_work_sync(&port->work); in usb_serial_disconnect()
1204 if (device_is_registered(&port->dev)) in usb_serial_disconnect()
1205 device_del(&port->dev); in usb_serial_disconnect()
1207 if (serial->type->disconnect) in usb_serial_disconnect()
1208 serial->type->disconnect(serial); in usb_serial_disconnect()
1210 release_sibling(serial, interface); in usb_serial_disconnect()
1213 usb_serial_put(serial); in usb_serial_disconnect()
1219 struct usb_serial *serial = usb_get_intfdata(intf); in usb_serial_suspend() local
1223 if (serial->suspend_count++) in usb_serial_suspend()
1227 * serial->type->suspend() MUST return 0 in system sleep context, in usb_serial_suspend()
1231 if (serial->type->suspend) { in usb_serial_suspend()
1232 r = serial->type->suspend(serial, message); in usb_serial_suspend()
1234 serial->suspend_count--; in usb_serial_suspend()
1239 for (i = 0; i < serial->num_ports; ++i) in usb_serial_suspend()
1240 usb_serial_port_poison_urbs(serial->port[i]); in usb_serial_suspend()
1246 static void usb_serial_unpoison_port_urbs(struct usb_serial *serial) in usb_serial_unpoison_port_urbs() argument
1250 for (i = 0; i < serial->num_ports; ++i) in usb_serial_unpoison_port_urbs()
1251 usb_serial_port_unpoison_urbs(serial->port[i]); in usb_serial_unpoison_port_urbs()
1256 struct usb_serial *serial = usb_get_intfdata(intf); in usb_serial_resume() local
1260 if (--serial->suspend_count) in usb_serial_resume()
1263 usb_serial_unpoison_port_urbs(serial); in usb_serial_resume()
1265 if (serial->type->resume) in usb_serial_resume()
1266 rv = serial->type->resume(serial); in usb_serial_resume()
1268 rv = usb_serial_generic_resume(serial); in usb_serial_resume()
1276 struct usb_serial *serial = usb_get_intfdata(intf); in usb_serial_reset_resume() local
1280 if (--serial->suspend_count) in usb_serial_reset_resume()
1283 usb_serial_unpoison_port_urbs(serial); in usb_serial_reset_resume()
1285 if (serial->type->reset_resume) { in usb_serial_reset_resume()
1286 rv = serial->type->reset_resume(serial); in usb_serial_reset_resume()
1288 rv = -EOPNOTSUPP; in usb_serial_reset_resume()
1289 intf->needs_binding = 1; in usb_serial_reset_resume()
1333 pr_err("%s - registering bus driver failed\n", __func__); in usb_serial_init()
1337 usb_serial_tty_driver->driver_name = "usbserial"; in usb_serial_init()
1338 usb_serial_tty_driver->name = "ttyUSB"; in usb_serial_init()
1339 usb_serial_tty_driver->major = USB_SERIAL_TTY_MAJOR; in usb_serial_init()
1340 usb_serial_tty_driver->minor_start = 0; in usb_serial_init()
1341 usb_serial_tty_driver->type = TTY_DRIVER_TYPE_SERIAL; in usb_serial_init()
1342 usb_serial_tty_driver->subtype = SERIAL_TYPE_NORMAL; in usb_serial_init()
1343 usb_serial_tty_driver->init_termios = tty_std_termios; in usb_serial_init()
1344 usb_serial_tty_driver->init_termios.c_cflag = B9600 | CS8 | CREAD in usb_serial_init()
1346 usb_serial_tty_driver->init_termios.c_ispeed = 9600; in usb_serial_init()
1347 usb_serial_tty_driver->init_termios.c_ospeed = 9600; in usb_serial_init()
1351 pr_err("%s - tty_register_driver failed\n", __func__); in usb_serial_init()
1358 pr_err("%s - registering generic driver failed\n", __func__); in usb_serial_init()
1369 pr_err("%s - returning with error %d\n", __func__, result); in usb_serial_init()
1393 if (!type->function) { \
1394 type->function = usb_serial_generic_##function; \
1396 type->driver.name); \
1407 if (device->tx_empty) in usb_serial_operations_init()
1420 return -ENODEV; in usb_serial_register()
1422 if (!driver->description) in usb_serial_register()
1423 driver->description = driver->driver.name; in usb_serial_register()
1424 if (!driver->usb_driver) { in usb_serial_register()
1425 WARN(1, "Serial driver %s has no usb_driver\n", in usb_serial_register()
1426 driver->description); in usb_serial_register()
1427 return -EINVAL; in usb_serial_register()
1431 driver->driver.suppress_bind_attrs = true; in usb_serial_register()
1437 list_add(&driver->driver_list, &usb_serial_driver_list); in usb_serial_register()
1441 pr_err("problem %d when registering driver %s\n", retval, driver->description); in usb_serial_register()
1442 list_del(&driver->driver_list); in usb_serial_register()
1444 pr_info("USB Serial support registered for %s\n", driver->description); in usb_serial_register()
1452 pr_info("USB Serial deregistering driver %s\n", device->description); in usb_serial_deregister()
1455 list_del(&device->driver_list); in usb_serial_deregister()
1462 * __usb_serial_register_drivers - register drivers for a usb-serial module
1463 * @serial_drivers: NULL-terminated array of pointers to drivers to be registered
1480 * udriver must be registered before any of the serial drivers, in __usb_serial_register_drivers()
1481 * because the store_new_id() routine for the serial drivers (in in __usb_serial_register_drivers()
1485 * the serial drivers are registered, because the probe would in __usb_serial_register_drivers()
1486 * simply fail for lack of a matching serial driver. in __usb_serial_register_drivers()
1489 * Suspend/resume support is implemented in the usb-serial core, in __usb_serial_register_drivers()
1490 * so fill in the PM-related fields in udriver. in __usb_serial_register_drivers()
1494 return -ENOMEM; in __usb_serial_register_drivers()
1496 udriver->name = name; in __usb_serial_register_drivers()
1497 udriver->no_dynamic_id = 1; in __usb_serial_register_drivers()
1498 udriver->supports_autosuspend = 1; in __usb_serial_register_drivers()
1499 udriver->suspend = usb_serial_suspend; in __usb_serial_register_drivers()
1500 udriver->resume = usb_serial_resume; in __usb_serial_register_drivers()
1501 udriver->probe = usb_serial_probe; in __usb_serial_register_drivers()
1502 udriver->disconnect = usb_serial_disconnect; in __usb_serial_register_drivers()
1506 if ((*sd)->reset_resume) { in __usb_serial_register_drivers()
1507 udriver->reset_resume = usb_serial_reset_resume; in __usb_serial_register_drivers()
1517 (*sd)->usb_driver = udriver; in __usb_serial_register_drivers()
1518 (*sd)->driver.owner = owner; in __usb_serial_register_drivers()
1525 udriver->id_table = id_table; in __usb_serial_register_drivers()
1526 rc = driver_attach(&udriver->driver); in __usb_serial_register_drivers()
1530 while (sd-- > serial_drivers) in __usb_serial_register_drivers()
1540 * usb_serial_deregister_drivers - deregister drivers for a usb-serial module
1541 * @serial_drivers: NULL-terminated array of pointers to drivers to be deregistered
1549 struct usb_driver *udriver = (*serial_drivers)->usb_driver; in usb_serial_deregister_drivers()