Lines Matching full:serial
3 * USB Serial Converter driver
13 * See Documentation/usb/usb-serial.rst for more information on using this
33 #include <linux/serial.h>
35 #include <linux/usb/serial.h>
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()
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()
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()
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()
206 * USB serial settings but permit them to be overridden by
207 * serial->type->init_termios on first open.
217 struct usb_serial *serial; in serial_install() local
226 serial = port->serial; in serial_install()
227 if (!try_module_get(serial->type->driver.owner)) 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()
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()
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()
296 * Shut down a USB serial port. Serialized against activate by the
306 struct usb_serial_driver *drv = port->serial->type; in serial_port_shutdown()
311 usb_autopm_put_interface(port->serial->interface); in serial_port_shutdown()
344 struct usb_serial *serial; in serial_cleanup() local
357 serial = port->serial; in serial_cleanup()
358 owner = serial->type->driver.owner; in serial_cleanup()
360 usb_serial_put(serial); in serial_cleanup()
369 if (port->serial->dev->state == USB_STATE_NOTATTACHED) in serial_write()
374 retval = port->serial->type->write(tty, port, buf, count); in serial_write()
387 return port->serial->type->write_room(tty); in serial_write_room()
393 struct usb_serial *serial = port->serial; in serial_chars_in_buffer() local
397 if (serial->disconnected) in serial_chars_in_buffer()
400 return serial->type->chars_in_buffer(tty); in serial_chars_in_buffer()
406 struct usb_serial *serial = port->serial; in serial_wait_until_sent() local
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()
425 if (port->serial->type->throttle) in serial_throttle()
426 port->serial->type->throttle(tty); in serial_throttle()
435 if (port->serial->type->unthrottle) in serial_unthrottle()
436 port->serial->type->unthrottle(tty); in serial_unthrottle()
456 if (port->serial->type->get_serial) in serial_get_serial()
457 port->serial->type->get_serial(tty, ss); in serial_get_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()
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()
528 if (port->serial->type->set_termios) in serial_set_termios()
529 port->serial->type->set_termios(tty, port, old); in serial_set_termios()
540 if (port->serial->type->break_ctl) in serial_break()
541 return port->serial->type->break_ctl(tty, break_state); 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()
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()
587 if (port->serial->type->tiocmget) in serial_tiocmget()
588 return port->serial->type->tiocmget(tty); in serial_tiocmget()
599 if (port->serial->type->tiocmset) in serial_tiocmset()
600 return port->serial->type->tiocmset(tty, set, clear); in serial_tiocmset()
611 if (port->serial->type->get_icount) in serial_get_icount()
612 return port->serial->type->get_icount(tty, icount); in serial_get_icount()
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()
759 struct usb_serial_driver *drv = p->serial->type; in serial_port_carrier_raised()
770 struct usb_serial_driver *drv = p->serial->type; in serial_port_dtr_rts()
798 static void store_endpoint(struct usb_serial *serial, in store_endpoint() argument
802 struct device *dev = &serial->interface->dev; in store_endpoint()
828 static void find_endpoints(struct usb_serial *serial, in find_endpoints() argument
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()
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()
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()
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()
966 struct usb_serial *serial = NULL; in usb_serial_probe() local
990 serial = create_serial(dev, interface, type); in usb_serial_probe()
991 if (!serial) { in usb_serial_probe()
1001 retval = type->probe(serial, id); 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()
1030 retval = type->calc_num_ports(serial, epds); 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()
1059 max_endpoints = max(max_endpoints, serial->num_ports); in usb_serial_probe()
1060 serial->num_port_pointers = max_endpoints; in usb_serial_probe()
1071 port->serial = serial; in usb_serial_probe()
1076 serial->port[i] = port; in usb_serial_probe()
1087 retval = setup_port_bulk_in(serial->port[i], epds->bulk_in[i]); in usb_serial_probe()
1093 retval = setup_port_bulk_out(serial->port[i], in usb_serial_probe()
1099 if (serial->type->read_int_callback) { in usb_serial_probe()
1101 retval = setup_port_interrupt_in(serial->port[i], in usb_serial_probe()
1110 if (serial->type->write_int_callback) { in usb_serial_probe()
1112 retval = setup_port_interrupt_out(serial->port[i], in usb_serial_probe()
1121 usb_set_intfdata(interface, serial); 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()
1158 usb_serial_console_init(serial->port[0]->minor); in usb_serial_probe()
1167 release_sibling(serial, interface); in usb_serial_probe()
1168 usb_serial_put(serial); in usb_serial_probe()
1178 struct usb_serial *serial = usb_get_intfdata(interface); in usb_serial_disconnect() local
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()
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()
1425 WARN(1, "Serial driver %s has no usb_driver\n", 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()
1462 * __usb_serial_register_drivers - register drivers for a usb-serial module
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()
1540 * usb_serial_deregister_drivers - deregister drivers for a usb-serial module