Lines Matching +full:usb +full:- +full:to +full:- +full:serial

1 // SPDX-License-Identifier: GPL-2.0
3 * USB Serial Console driver
5 * Copyright (C) 2001 - 2002 Greg Kroah-Hartman (greg@kroah.com)
7 * Thanks to Randy Dunlap for the original version of this code.
18 #include <linux/serial.h>
19 #include <linux/usb.h>
20 #include <linux/usb/serial.h>
32 * ------------------------------------------------------------
33 * USB Serial console driver
35 * Much of the code here is copied from drivers/char/serial.c
36 * and implements a phony serial console in the same way that
37 * serial.c does so that in case some software queries it,
40 * Things that are different from the way the serial port code
41 * does things, is that we call the lower level usb-serial
42 * driver code to initialize the device, and we set the initial
44 * ------------------------------------------------------------
52 * serial.c code, except that the specifier is "ttyUSB" instead
64 struct usb_serial *serial; in usb_console_setup() local
78 bits = *s++ - '0'; in usb_console_setup()
109 * no need to check the index here: if the index is wrong, console in usb_console_setup()
112 port = usb_serial_port_get_by_minor(co->index); in usb_console_setup()
115 pr_err("No USB device connected to ttyUSB%i\n", co->index); in usb_console_setup()
116 return -ENODEV; in usb_console_setup()
118 serial = port->serial; in usb_console_setup()
120 retval = usb_autopm_get_interface(serial->interface); in usb_console_setup()
124 tty_port_tty_set(&port->port, NULL); in usb_console_setup()
126 info->port = port; in usb_console_setup()
128 ++port->port.count; in usb_console_setup()
129 if (!tty_port_initialized(&port->port)) { in usb_console_setup()
130 if (serial->type->set_termios) { in usb_console_setup()
133 * the termios structure, then later call set_termios to in usb_console_setup()
134 * configure according to command line arguments in usb_console_setup()
138 retval = -ENOMEM; in usb_console_setup()
141 kref_init(&tty->kref); in usb_console_setup()
142 tty->driver = usb_serial_tty_driver; in usb_console_setup()
143 tty->index = co->index; in usb_console_setup()
144 init_ldsem(&tty->ldisc_sem); in usb_console_setup()
145 spin_lock_init(&tty->files_lock); in usb_console_setup()
146 INIT_LIST_HEAD(&tty->tty_files); in usb_console_setup()
147 kref_get(&tty->driver->kref); in usb_console_setup()
148 __module_get(tty->driver->owner); in usb_console_setup()
149 tty->ops = &usb_console_fake_tty_ops; in usb_console_setup()
151 tty_port_tty_set(&port->port, tty); in usb_console_setup()
156 retval = serial->type->open(NULL, port); in usb_console_setup()
158 dev_err(&port->dev, "could not open USB console port\n"); in usb_console_setup()
162 if (serial->type->set_termios) { in usb_console_setup()
163 tty->termios.c_cflag = cflag; in usb_console_setup()
164 tty_termios_encode_baud_rate(&tty->termios, baud, baud); in usb_console_setup()
166 serial->type->set_termios(tty, port, &dummy); in usb_console_setup()
168 tty_port_tty_set(&port->port, NULL); in usb_console_setup()
172 tty_port_set_initialized(&port->port, true); in usb_console_setup()
176 --port->port.count; in usb_console_setup()
179 port->port.console = 1; in usb_console_setup()
181 mutex_unlock(&serial->disc_mutex); in usb_console_setup()
185 tty_port_tty_set(&port->port, NULL); in usb_console_setup()
188 port->port.count = 0; in usb_console_setup()
189 info->port = NULL; in usb_console_setup()
190 usb_autopm_put_interface(serial->interface); in usb_console_setup()
192 mutex_unlock(&serial->disc_mutex); in usb_console_setup()
193 usb_serial_put(serial); in usb_console_setup()
201 struct usb_serial_port *port = info->port; in usb_console_write()
202 struct usb_serial *serial; in usb_console_write() local
203 int retval = -ENODEV; in usb_console_write()
205 if (!port || port->serial->dev->state == USB_STATE_NOTATTACHED) in usb_console_write()
207 serial = port->serial; in usb_console_write()
212 dev_dbg(&port->dev, "%s - %d byte(s)\n", __func__, count); in usb_console_write()
214 if (!port->port.console) { in usb_console_write()
215 dev_dbg(&port->dev, "%s - port not opened\n", __func__); in usb_console_write()
230 /* pass on to the driver specific version of this function if in usb_console_write()
232 retval = serial->type->write(NULL, port, buf, i); in usb_console_write()
233 dev_dbg(&port->dev, "%s - write: %d\n", __func__, retval); in usb_console_write()
237 retval = serial->type->write(NULL, port, &cr, 1); in usb_console_write()
238 dev_dbg(&port->dev, "%s - write cr: %d\n", in usb_console_write()
242 count -= i; in usb_console_write()
248 struct tty_driver **p = (struct tty_driver **)co->data; in usb_console_device()
253 *index = co->index; in usb_console_device()
263 .index = -1,
267 void usb_serial_console_disconnect(struct usb_serial *serial) in usb_serial_console_disconnect() argument
269 if (serial->port[0] && serial->port[0] == usbcons_info.port) { in usb_serial_console_disconnect()
271 usb_serial_put(serial); in usb_serial_console_disconnect()
280 * in. If we call it earlier, then the callback to in usb_serial_console_init()
282 * the USB subsystem yet. in usb_serial_console_init()
291 pr_debug("registering the USB serial console.\n"); in usb_serial_console_init()
300 usbcons_info.port->port.console = 0; in usb_serial_console_exit()