Lines Matching full:serial
22 * The multiplexed serial ports are using the interrupt and
60 #include <linux/serial.h>
203 on which serial port it is used on. */
230 int (*write_data) (struct hso_serial *serial);
233 * working on the serial receive buffers
290 /* Serial driver functions */
294 static int put_rxbuf_data(struct urb *urb, struct hso_serial *serial);
295 static void hso_kick_transmit(struct hso_serial *serial);
312 static int hso_mux_serial_read(struct hso_serial *serial);
368 /* serial structures */
515 static int hso_urb_to_index(struct hso_serial *serial, struct urb *urb) in hso_urb_to_index() argument
519 for (idx = 0; idx < serial->num_rx_urbs; idx++) in hso_urb_to_index()
520 if (serial->rx_urb[idx] == urb) in hso_urb_to_index()
522 dev_err(serial->parent->dev, "hso_urb_to_index failed\n"); in hso_urb_to_index()
601 struct hso_serial *serial = NULL; in get_serial_by_index() local
606 serial = dev2ser(serial_table[index]); in get_serial_by_index()
609 return serial; in get_serial_by_index()
612 static int obtain_minor(struct hso_serial *serial) in obtain_minor() argument
620 serial_table[index] = serial->parent; in obtain_minor()
621 serial->minor = index; in obtain_minor()
628 pr_err("%s: no free serial devices in table\n", __func__); in obtain_minor()
632 static void release_minor(struct hso_serial *serial) in release_minor() argument
637 serial_table[serial->minor] = NULL; in release_minor()
1040 /* Serial driver functions */
1083 struct hso_serial *serial = tty->driver_data; in _hso_serial_set_termios() local
1085 if (!serial) { in _hso_serial_set_termios()
1090 hso_dbg(0x8, "port %d\n", serial->minor); in _hso_serial_set_termios()
1109 static void hso_resubmit_rx_bulk_urb(struct hso_serial *serial, struct urb *urb) in hso_resubmit_rx_bulk_urb() argument
1114 usb_fill_bulk_urb(urb, serial->parent->usb, in hso_resubmit_rx_bulk_urb()
1115 usb_rcvbulkpipe(serial->parent->usb, in hso_resubmit_rx_bulk_urb()
1116 serial->in_endp-> in hso_resubmit_rx_bulk_urb()
1118 urb->transfer_buffer, serial->rx_data_length, in hso_resubmit_rx_bulk_urb()
1119 hso_std_serial_read_bulk_callback, serial); in hso_resubmit_rx_bulk_urb()
1124 dev_err(&urb->dev->dev, "%s failed submit serial rx_urb %d\n", in hso_resubmit_rx_bulk_urb()
1132 static void put_rxbuf_data_and_resubmit_bulk_urb(struct hso_serial *serial) in put_rxbuf_data_and_resubmit_bulk_urb() argument
1137 while (serial->rx_urb_filled[serial->curr_rx_urb_idx]) { in put_rxbuf_data_and_resubmit_bulk_urb()
1138 curr_urb = serial->rx_urb[serial->curr_rx_urb_idx]; in put_rxbuf_data_and_resubmit_bulk_urb()
1139 count = put_rxbuf_data(curr_urb, serial); in put_rxbuf_data_and_resubmit_bulk_urb()
1143 serial->curr_rx_urb_idx++; in put_rxbuf_data_and_resubmit_bulk_urb()
1144 if (serial->curr_rx_urb_idx >= serial->num_rx_urbs) in put_rxbuf_data_and_resubmit_bulk_urb()
1145 serial->curr_rx_urb_idx = 0; in put_rxbuf_data_and_resubmit_bulk_urb()
1146 hso_resubmit_rx_bulk_urb(serial, curr_urb); in put_rxbuf_data_and_resubmit_bulk_urb()
1151 static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial) in put_rxbuf_data_and_resubmit_ctrl_urb() argument
1156 urb = serial->rx_urb[0]; in put_rxbuf_data_and_resubmit_ctrl_urb()
1157 if (serial->port.count > 0) { in put_rxbuf_data_and_resubmit_ctrl_urb()
1158 count = put_rxbuf_data(urb, serial); in put_rxbuf_data_and_resubmit_ctrl_urb()
1165 (serial->rx_state == RX_PENDING))) { in put_rxbuf_data_and_resubmit_ctrl_urb()
1166 serial->rx_state = RX_SENT; in put_rxbuf_data_and_resubmit_ctrl_urb()
1167 hso_mux_serial_read(serial); in put_rxbuf_data_and_resubmit_ctrl_urb()
1169 serial->rx_state = RX_IDLE; in put_rxbuf_data_and_resubmit_ctrl_urb()
1176 struct hso_serial *serial = urb->context; in hso_std_serial_read_bulk_callback() local
1183 if (!serial) { in hso_std_serial_read_bulk_callback()
1184 hso_dbg(0x1, "serial == NULL\n"); in hso_std_serial_read_bulk_callback()
1188 handle_usb_error(status, __func__, serial->parent); in hso_std_serial_read_bulk_callback()
1196 if (serial->port.count == 0) in hso_std_serial_read_bulk_callback()
1199 if (serial->parent->port_spec & HSO_INFO_CRC_BUG) in hso_std_serial_read_bulk_callback()
1200 fix_crc_bug(urb, serial->in_endp->wMaxPacketSize); in hso_std_serial_read_bulk_callback()
1202 spin_lock_irqsave(&serial->serial_lock, flags); in hso_std_serial_read_bulk_callback()
1203 serial->rx_urb_filled[hso_urb_to_index(serial, urb)] = 1; in hso_std_serial_read_bulk_callback()
1204 put_rxbuf_data_and_resubmit_bulk_urb(serial); in hso_std_serial_read_bulk_callback()
1205 spin_unlock_irqrestore(&serial->serial_lock, flags); in hso_std_serial_read_bulk_callback()
1214 struct hso_serial *serial = from_tasklet(serial, t, in hso_unthrottle_tasklet() local
1218 spin_lock_irqsave(&serial->serial_lock, flags); in hso_unthrottle_tasklet()
1219 if ((serial->parent->port_spec & HSO_INTF_MUX)) in hso_unthrottle_tasklet()
1220 put_rxbuf_data_and_resubmit_ctrl_urb(serial); in hso_unthrottle_tasklet()
1222 put_rxbuf_data_and_resubmit_bulk_urb(serial); in hso_unthrottle_tasklet()
1223 spin_unlock_irqrestore(&serial->serial_lock, flags); in hso_unthrottle_tasklet()
1228 struct hso_serial *serial = tty->driver_data; in hso_unthrottle() local
1230 tasklet_hi_schedule(&serial->unthrottle_tasklet); in hso_unthrottle()
1233 /* open the requested serial port */
1236 struct hso_serial *serial = get_serial_by_index(tty->index); in hso_serial_open() local
1240 if (serial == NULL || serial->magic != HSO_SERIAL_MAGIC) { in hso_serial_open()
1247 mutex_lock(&serial->parent->mutex); in hso_serial_open()
1248 result = usb_autopm_get_interface(serial->parent->interface); in hso_serial_open()
1252 hso_dbg(0x1, "Opening %d\n", serial->minor); in hso_serial_open()
1255 tty->driver_data = serial; in hso_serial_open()
1256 tty_port_tty_set(&serial->port, tty); in hso_serial_open()
1259 serial->port.count++; in hso_serial_open()
1260 if (serial->port.count == 1) { in hso_serial_open()
1261 serial->rx_state = RX_IDLE; in hso_serial_open()
1264 tasklet_setup(&serial->unthrottle_tasklet, in hso_serial_open()
1266 result = hso_start_serial_device(serial->parent, GFP_KERNEL); in hso_serial_open()
1268 hso_stop_serial_device(serial->parent); in hso_serial_open()
1269 serial->port.count--; in hso_serial_open()
1271 kref_get(&serial->parent->ref); in hso_serial_open()
1277 usb_autopm_put_interface(serial->parent->interface); in hso_serial_open()
1283 mutex_unlock(&serial->parent->mutex); in hso_serial_open()
1287 /* close the requested serial port */
1290 struct hso_serial *serial = tty->driver_data; in hso_serial_close() local
1293 hso_dbg(0x1, "Closing serial port\n"); in hso_serial_close()
1296 if (serial == NULL) in hso_serial_close()
1299 mutex_lock(&serial->parent->mutex); in hso_serial_close()
1300 usb_gone = serial->parent->usb_gone; in hso_serial_close()
1303 usb_autopm_get_interface(serial->parent->interface); in hso_serial_close()
1307 serial->port.count--; in hso_serial_close()
1309 if (serial->port.count <= 0) { in hso_serial_close()
1310 serial->port.count = 0; in hso_serial_close()
1311 tty_port_tty_set(&serial->port, NULL); in hso_serial_close()
1313 hso_stop_serial_device(serial->parent); in hso_serial_close()
1314 tasklet_kill(&serial->unthrottle_tasklet); in hso_serial_close()
1318 usb_autopm_put_interface(serial->parent->interface); in hso_serial_close()
1320 mutex_unlock(&serial->parent->mutex); in hso_serial_close()
1323 /* close the requested serial port */
1327 struct hso_serial *serial = tty->driver_data; in hso_serial_write() local
1331 if (serial == NULL) { in hso_serial_write()
1332 pr_err("%s: serial is NULL\n", __func__); in hso_serial_write()
1336 spin_lock_irqsave(&serial->serial_lock, flags); in hso_serial_write()
1338 count = min_t(size_t, serial->tx_data_length - serial->tx_buffer_count, in hso_serial_write()
1340 memcpy(serial->tx_buffer + serial->tx_buffer_count, buf, count); in hso_serial_write()
1341 serial->tx_buffer_count += count; in hso_serial_write()
1343 spin_unlock_irqrestore(&serial->serial_lock, flags); in hso_serial_write()
1345 hso_kick_transmit(serial); in hso_serial_write()
1353 struct hso_serial *serial = tty->driver_data; in hso_serial_write_room() local
1357 spin_lock_irqsave(&serial->serial_lock, flags); in hso_serial_write_room()
1358 room = serial->tx_data_length - serial->tx_buffer_count; in hso_serial_write_room()
1359 spin_unlock_irqrestore(&serial->serial_lock, flags); in hso_serial_write_room()
1367 struct hso_serial *serial = tty->driver_data; in hso_serial_cleanup() local
1369 if (!serial) in hso_serial_cleanup()
1372 kref_put(&serial->parent->ref, hso_serial_ref_free); in hso_serial_cleanup()
1379 struct hso_serial *serial = tty->driver_data; in hso_serial_set_termios() local
1388 spin_lock_irqsave(&serial->serial_lock, flags); in hso_serial_set_termios()
1389 if (serial->port.count) in hso_serial_set_termios()
1393 spin_unlock_irqrestore(&serial->serial_lock, flags); in hso_serial_set_termios()
1401 struct hso_serial *serial = tty->driver_data; in hso_serial_chars_in_buffer() local
1406 if (serial == NULL) in hso_serial_chars_in_buffer()
1409 spin_lock_irqsave(&serial->serial_lock, flags); in hso_serial_chars_in_buffer()
1410 chars = serial->tx_buffer_count; in hso_serial_chars_in_buffer()
1411 spin_unlock_irqrestore(&serial->serial_lock, flags); in hso_serial_chars_in_buffer()
1415 static int tiocmget_submit_urb(struct hso_serial *serial, in tiocmget_submit_urb() argument
1421 if (serial->parent->usb_gone) in tiocmget_submit_urb()
1429 tiocmget_intr_callback, serial, in tiocmget_submit_urb()
1442 struct hso_serial *serial = urb->context; in tiocmget_intr_callback() local
1453 if (!serial) in tiocmget_intr_callback()
1456 handle_usb_error(status, __func__, serial->parent); in tiocmget_intr_callback()
1461 tiocmget = serial->tiocmget; in tiocmget_intr_callback()
1464 BUG_ON((serial->parent->port_spec & HSO_PORT_MASK) != HSO_PORT_MODEM); in tiocmget_intr_callback()
1466 usb = serial->parent->usb; in tiocmget_intr_callback()
1467 interface = serial->parent->interface; in tiocmget_intr_callback()
1481 "hso received invalid serial state notification\n"); in tiocmget_intr_callback()
1491 spin_lock_irqsave(&serial->serial_lock, flags); in tiocmget_intr_callback()
1514 spin_unlock_irqrestore(&serial->serial_lock, flags); in tiocmget_intr_callback()
1520 tiocmget_submit_urb(serial, in tiocmget_intr_callback()
1522 serial->parent->usb); in tiocmget_intr_callback()
1526 * next few functions largely stolen from drivers/serial/serial_core.c
1534 hso_wait_modem_status(struct hso_serial *serial, unsigned long arg) in hso_wait_modem_status() argument
1541 tiocmget = serial->tiocmget; in hso_wait_modem_status()
1547 spin_lock_irq(&serial->serial_lock); in hso_wait_modem_status()
1549 spin_unlock_irq(&serial->serial_lock); in hso_wait_modem_status()
1552 spin_lock_irq(&serial->serial_lock); in hso_wait_modem_status()
1554 spin_unlock_irq(&serial->serial_lock); in hso_wait_modem_status()
1577 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
1586 struct hso_serial *serial = tty->driver_data; in hso_get_count() local
1587 struct hso_tiocmget *tiocmget = serial->tiocmget; in hso_get_count()
1593 spin_lock_irq(&serial->serial_lock); in hso_get_count()
1595 spin_unlock_irq(&serial->serial_lock); in hso_get_count()
1616 struct hso_serial *serial = tty->driver_data; in hso_serial_tiocmget() local
1621 if (!serial) { in hso_serial_tiocmget()
1625 spin_lock_irq(&serial->serial_lock); in hso_serial_tiocmget()
1626 retval = ((serial->rts_state) ? TIOCM_RTS : 0) | in hso_serial_tiocmget()
1627 ((serial->dtr_state) ? TIOCM_DTR : 0); in hso_serial_tiocmget()
1628 tiocmget = serial->tiocmget; in hso_serial_tiocmget()
1640 spin_unlock_irq(&serial->serial_lock); in hso_serial_tiocmget()
1650 struct hso_serial *serial = tty->driver_data; in hso_serial_tiocmset() local
1654 if (!serial) { in hso_serial_tiocmset()
1659 if ((serial->parent->port_spec & HSO_PORT_MASK) != HSO_PORT_MODEM) in hso_serial_tiocmset()
1662 interface = serial->parent->interface; in hso_serial_tiocmset()
1665 spin_lock_irqsave(&serial->serial_lock, flags); in hso_serial_tiocmset()
1667 serial->rts_state = 1; in hso_serial_tiocmset()
1669 serial->dtr_state = 1; in hso_serial_tiocmset()
1672 serial->rts_state = 0; in hso_serial_tiocmset()
1674 serial->dtr_state = 0; in hso_serial_tiocmset()
1676 if (serial->dtr_state) in hso_serial_tiocmset()
1678 if (serial->rts_state) in hso_serial_tiocmset()
1681 spin_unlock_irqrestore(&serial->serial_lock, flags); in hso_serial_tiocmset()
1683 return usb_control_msg(serial->parent->usb, in hso_serial_tiocmset()
1684 usb_sndctrlpipe(serial->parent->usb, 0), 0x22, in hso_serial_tiocmset()
1692 struct hso_serial *serial = tty->driver_data; in hso_serial_ioctl() local
1696 if (!serial) in hso_serial_ioctl()
1700 ret = hso_wait_modem_status(serial, arg); in hso_serial_ioctl()
1711 static void hso_kick_transmit(struct hso_serial *serial) in hso_kick_transmit() argument
1716 spin_lock_irqsave(&serial->serial_lock, flags); in hso_kick_transmit()
1717 if (!serial->tx_buffer_count) in hso_kick_transmit()
1720 if (serial->tx_urb_used) in hso_kick_transmit()
1724 if (hso_get_activity(serial->parent) == -EAGAIN) in hso_kick_transmit()
1728 swap(serial->tx_buffer, serial->tx_data); in hso_kick_transmit()
1729 serial->tx_data_count = serial->tx_buffer_count; in hso_kick_transmit()
1730 serial->tx_buffer_count = 0; in hso_kick_transmit()
1732 /* If serial->tx_data is set, it means we switched buffers */ in hso_kick_transmit()
1733 if (serial->tx_data && serial->write_data) { in hso_kick_transmit()
1734 res = serial->write_data(serial); in hso_kick_transmit()
1736 serial->tx_urb_used = 1; in hso_kick_transmit()
1739 spin_unlock_irqrestore(&serial->serial_lock, flags); in hso_kick_transmit()
1742 /* make a request (for reading and writing data to muxed serial port) */
1743 static int mux_device_request(struct hso_serial *serial, u8 type, u16 port, in mux_device_request() argument
1752 if (!serial || !ctrl_urb || !ctrl_req) { in mux_device_request()
1768 pipe = usb_rcvctrlpipe(serial->parent->usb, 0); in mux_device_request()
1775 pipe = usb_sndctrlpipe(serial->parent->usb, 0); in mux_device_request()
1785 serial->parent->usb, in mux_device_request()
1788 ctrl_urb_data, size, ctrl_callback, serial); in mux_device_request()
1803 static int hso_mux_serial_read(struct hso_serial *serial) in hso_mux_serial_read() argument
1805 if (!serial) in hso_mux_serial_read()
1809 memset(serial->rx_data[0], 0, CTRL_URB_RX_SIZE); in hso_mux_serial_read()
1812 if (serial->num_rx_urbs != 1) { in hso_mux_serial_read()
1813 dev_err(&serial->parent->interface->dev, in hso_mux_serial_read()
1818 return mux_device_request(serial, in hso_mux_serial_read()
1820 serial->parent->port_spec & HSO_PORT_MASK, in hso_mux_serial_read()
1821 serial->rx_urb[0], in hso_mux_serial_read()
1822 &serial->ctrl_req_rx, in hso_mux_serial_read()
1823 serial->rx_data[0], serial->rx_data_length); in hso_mux_serial_read()
1826 /* used for muxed serial port callback (muxed serial read) */
1830 struct hso_serial *serial; in intr_callback() local
1856 serial = get_serial_by_shared_int_and_type(shared_int, in intr_callback()
1858 if (serial != NULL) { in intr_callback()
1861 spin_lock_irqsave(&serial->serial_lock, flags); in intr_callback()
1862 if (serial->rx_state == RX_IDLE && in intr_callback()
1863 serial->port.count > 0) { in intr_callback()
1866 if (!serial->rx_urb_filled[0]) { in intr_callback()
1867 serial->rx_state = RX_SENT; in intr_callback()
1868 hso_mux_serial_read(serial); in intr_callback()
1870 serial->rx_state = RX_PENDING; in intr_callback()
1875 spin_unlock_irqrestore(&serial->serial_lock, in intr_callback()
1884 /* called for writing to muxed serial port */
1885 static int hso_mux_serial_write_data(struct hso_serial *serial) in hso_mux_serial_write_data() argument
1887 if (NULL == serial) in hso_mux_serial_write_data()
1890 return mux_device_request(serial, in hso_mux_serial_write_data()
1892 serial->parent->port_spec & HSO_PORT_MASK, in hso_mux_serial_write_data()
1893 serial->tx_urb, in hso_mux_serial_write_data()
1894 &serial->ctrl_req_tx, in hso_mux_serial_write_data()
1895 serial->tx_data, serial->tx_data_count); in hso_mux_serial_write_data()
1901 struct hso_serial *serial = urb->context; in hso_std_serial_write_bulk_callback() local
1906 if (!serial) { in hso_std_serial_write_bulk_callback()
1907 hso_dbg(0x1, "serial == NULL\n"); in hso_std_serial_write_bulk_callback()
1911 spin_lock_irqsave(&serial->serial_lock, flags); in hso_std_serial_write_bulk_callback()
1912 serial->tx_urb_used = 0; in hso_std_serial_write_bulk_callback()
1913 spin_unlock_irqrestore(&serial->serial_lock, flags); in hso_std_serial_write_bulk_callback()
1915 handle_usb_error(status, __func__, serial->parent); in hso_std_serial_write_bulk_callback()
1918 hso_put_activity(serial->parent); in hso_std_serial_write_bulk_callback()
1919 tty_port_tty_wakeup(&serial->port); in hso_std_serial_write_bulk_callback()
1920 hso_kick_transmit(serial); in hso_std_serial_write_bulk_callback()
1925 /* called for writing diag or CS serial port */
1926 static int hso_std_serial_write_data(struct hso_serial *serial) in hso_std_serial_write_data() argument
1928 int count = serial->tx_data_count; in hso_std_serial_write_data()
1931 usb_fill_bulk_urb(serial->tx_urb, in hso_std_serial_write_data()
1932 serial->parent->usb, in hso_std_serial_write_data()
1933 usb_sndbulkpipe(serial->parent->usb, in hso_std_serial_write_data()
1934 serial->out_endp-> in hso_std_serial_write_data()
1936 serial->tx_data, serial->tx_data_count, in hso_std_serial_write_data()
1937 hso_std_serial_write_bulk_callback, serial); in hso_std_serial_write_data()
1939 result = usb_submit_urb(serial->tx_urb, GFP_ATOMIC); in hso_std_serial_write_data()
1941 dev_warn(&serial->parent->usb->dev, in hso_std_serial_write_data()
1949 /* callback after read or write on muxed serial port */
1952 struct hso_serial *serial = urb->context; in ctrl_callback() local
1958 if (!serial) in ctrl_callback()
1961 spin_lock_irqsave(&serial->serial_lock, flags); in ctrl_callback()
1962 serial->tx_urb_used = 0; in ctrl_callback()
1963 spin_unlock_irqrestore(&serial->serial_lock, flags); in ctrl_callback()
1965 handle_usb_error(status, __func__, serial->parent); in ctrl_callback()
1978 serial->rx_urb_filled[0] = 1; in ctrl_callback()
1979 spin_lock_irqsave(&serial->serial_lock, flags); in ctrl_callback()
1980 put_rxbuf_data_and_resubmit_ctrl_urb(serial); in ctrl_callback()
1981 spin_unlock_irqrestore(&serial->serial_lock, flags); in ctrl_callback()
1983 hso_put_activity(serial->parent); in ctrl_callback()
1984 tty_port_tty_wakeup(&serial->port); in ctrl_callback()
1986 hso_kick_transmit(serial); in ctrl_callback()
1990 /* handle RX data for serial port */
1991 static int put_rxbuf_data(struct urb *urb, struct hso_serial *serial) in put_rxbuf_data() argument
1997 if (urb == NULL || serial == NULL) { in put_rxbuf_data()
1998 hso_dbg(0x1, "serial = NULL\n"); in put_rxbuf_data()
2002 tty = tty_port_tty_get(&serial->port); in put_rxbuf_data()
2011 count = tty_buffer_request_room(&serial->port, urb->actual_length); in put_rxbuf_data()
2013 tty_insert_flip_string(&serial->port, urb->transfer_buffer, in put_rxbuf_data()
2015 tty_flip_buffer_push(&serial->port); in put_rxbuf_data()
2017 dev_warn(&serial->parent->usb->dev, in put_rxbuf_data()
2023 serial->rx_urb_filled[hso_urb_to_index(serial, urb)] = 0; in put_rxbuf_data()
2136 struct hso_serial *serial = dev2ser(hso_dev); in hso_start_serial_device() local
2138 if (!serial) in hso_start_serial_device()
2143 if (!(serial->parent->port_spec & HSO_INTF_MUX)) { in hso_start_serial_device()
2144 for (i = 0; i < serial->num_rx_urbs; i++) { in hso_start_serial_device()
2145 usb_fill_bulk_urb(serial->rx_urb[i], in hso_start_serial_device()
2146 serial->parent->usb, in hso_start_serial_device()
2147 usb_rcvbulkpipe(serial->parent->usb, in hso_start_serial_device()
2148 serial->in_endp-> in hso_start_serial_device()
2151 serial->rx_data[i], in hso_start_serial_device()
2152 serial->rx_data_length, in hso_start_serial_device()
2154 serial); in hso_start_serial_device()
2155 result = usb_submit_urb(serial->rx_urb[i], flags); in hso_start_serial_device()
2157 dev_warn(&serial->parent->usb->dev, in hso_start_serial_device()
2164 mutex_lock(&serial->shared_int->shared_int_lock); in hso_start_serial_device()
2165 if (!serial->shared_int->use_count) { in hso_start_serial_device()
2167 hso_mux_submit_intr_urb(serial->shared_int, in hso_start_serial_device()
2170 serial->shared_int->use_count++; in hso_start_serial_device()
2171 mutex_unlock(&serial->shared_int->shared_int_lock); in hso_start_serial_device()
2173 if (serial->tiocmget) in hso_start_serial_device()
2174 tiocmget_submit_urb(serial, in hso_start_serial_device()
2175 serial->tiocmget, in hso_start_serial_device()
2176 serial->parent->usb); in hso_start_serial_device()
2183 struct hso_serial *serial = dev2ser(hso_dev); in hso_stop_serial_device() local
2186 if (!serial) in hso_stop_serial_device()
2189 for (i = 0; i < serial->num_rx_urbs; i++) { in hso_stop_serial_device()
2190 if (serial->rx_urb[i]) { in hso_stop_serial_device()
2191 usb_kill_urb(serial->rx_urb[i]); in hso_stop_serial_device()
2192 serial->rx_urb_filled[i] = 0; in hso_stop_serial_device()
2195 serial->curr_rx_urb_idx = 0; in hso_stop_serial_device()
2197 if (serial->tx_urb) in hso_stop_serial_device()
2198 usb_kill_urb(serial->tx_urb); in hso_stop_serial_device()
2200 if (serial->shared_int) { in hso_stop_serial_device()
2201 mutex_lock(&serial->shared_int->shared_int_lock); in hso_stop_serial_device()
2202 if (serial->shared_int->use_count && in hso_stop_serial_device()
2203 (--serial->shared_int->use_count == 0)) { in hso_stop_serial_device()
2206 urb = serial->shared_int->shared_intr_urb; in hso_stop_serial_device()
2210 mutex_unlock(&serial->shared_int->shared_int_lock); in hso_stop_serial_device()
2212 tiocmget = serial->tiocmget; in hso_stop_serial_device()
2221 static void hso_serial_tty_unregister(struct hso_serial *serial) in hso_serial_tty_unregister() argument
2223 tty_unregister_device(tty_drv, serial->minor); in hso_serial_tty_unregister()
2224 release_minor(serial); in hso_serial_tty_unregister()
2227 static void hso_serial_common_free(struct hso_serial *serial) in hso_serial_common_free() argument
2231 for (i = 0; i < serial->num_rx_urbs; i++) { in hso_serial_common_free()
2233 usb_free_urb(serial->rx_urb[i]); in hso_serial_common_free()
2235 kfree(serial->rx_data[i]); in hso_serial_common_free()
2239 usb_free_urb(serial->tx_urb); in hso_serial_common_free()
2240 kfree(serial->tx_buffer); in hso_serial_common_free()
2241 kfree(serial->tx_data); in hso_serial_common_free()
2242 tty_port_destroy(&serial->port); in hso_serial_common_free()
2245 static int hso_serial_common_create(struct hso_serial *serial, int num_urbs, in hso_serial_common_create() argument
2250 tty_port_init(&serial->port); in hso_serial_common_create()
2252 if (obtain_minor(serial)) in hso_serial_common_create()
2256 serial->parent->dev = tty_port_register_device_attr(&serial->port, in hso_serial_common_create()
2257 tty_drv, serial->minor, &serial->parent->interface->dev, in hso_serial_common_create()
2258 serial->parent, hso_serial_dev_groups); in hso_serial_common_create()
2259 if (IS_ERR(serial->parent->dev)) { in hso_serial_common_create()
2260 release_minor(serial); in hso_serial_common_create()
2264 serial->magic = HSO_SERIAL_MAGIC; in hso_serial_common_create()
2265 spin_lock_init(&serial->serial_lock); in hso_serial_common_create()
2266 serial->num_rx_urbs = num_urbs; in hso_serial_common_create()
2271 serial->rx_data_length = rx_size; in hso_serial_common_create()
2272 for (i = 0; i < serial->num_rx_urbs; i++) { in hso_serial_common_create()
2273 serial->rx_urb[i] = usb_alloc_urb(0, GFP_KERNEL); in hso_serial_common_create()
2274 if (!serial->rx_urb[i]) in hso_serial_common_create()
2276 serial->rx_urb[i]->transfer_buffer = NULL; in hso_serial_common_create()
2277 serial->rx_urb[i]->transfer_buffer_length = 0; in hso_serial_common_create()
2278 serial->rx_data[i] = kzalloc(serial->rx_data_length, in hso_serial_common_create()
2280 if (!serial->rx_data[i]) in hso_serial_common_create()
2285 serial->tx_urb = usb_alloc_urb(0, GFP_KERNEL); in hso_serial_common_create()
2286 if (!serial->tx_urb) in hso_serial_common_create()
2288 serial->tx_urb->transfer_buffer = NULL; in hso_serial_common_create()
2289 serial->tx_urb->transfer_buffer_length = 0; in hso_serial_common_create()
2291 serial->tx_data_count = 0; in hso_serial_common_create()
2292 serial->tx_buffer_count = 0; in hso_serial_common_create()
2293 serial->tx_data_length = tx_size; in hso_serial_common_create()
2294 serial->tx_data = kzalloc(serial->tx_data_length, GFP_KERNEL); in hso_serial_common_create()
2295 if (!serial->tx_data) in hso_serial_common_create()
2298 serial->tx_buffer = kzalloc(serial->tx_data_length, GFP_KERNEL); in hso_serial_common_create()
2299 if (!serial->tx_buffer) in hso_serial_common_create()
2304 hso_serial_tty_unregister(serial); in hso_serial_common_create()
2306 hso_serial_common_free(serial); in hso_serial_common_create()
2569 static void hso_free_tiomget(struct hso_serial *serial) in hso_free_tiomget() argument
2572 if (!serial) in hso_free_tiomget()
2574 tiocmget = serial->tiocmget; in hso_free_tiomget()
2578 serial->tiocmget = NULL; in hso_free_tiomget()
2588 struct hso_serial *serial = dev2ser(hso_dev); in hso_free_serial_device() local
2590 if (!serial) in hso_free_serial_device()
2593 hso_serial_common_free(serial); in hso_free_serial_device()
2595 if (serial->shared_int) { in hso_free_serial_device()
2596 mutex_lock(&serial->shared_int->shared_int_lock); in hso_free_serial_device()
2597 if (--serial->shared_int->ref_count == 0) in hso_free_serial_device()
2598 hso_free_shared_int(serial->shared_int); in hso_free_serial_device()
2600 mutex_unlock(&serial->shared_int->shared_int_lock); in hso_free_serial_device()
2602 hso_free_tiomget(serial); in hso_free_serial_device()
2603 kfree(serial); in hso_free_serial_device()
2612 struct hso_serial *serial; in hso_create_bulk_serial_device() local
2620 serial = kzalloc(sizeof(*serial), GFP_KERNEL); in hso_create_bulk_serial_device()
2621 if (!serial) in hso_create_bulk_serial_device()
2624 serial->parent = hso_dev; in hso_create_bulk_serial_device()
2625 hso_dev->port_data.dev_serial = serial; in hso_create_bulk_serial_device()
2629 serial->tiocmget = kzalloc(sizeof(struct hso_tiocmget), in hso_create_bulk_serial_device()
2631 if (!serial->tiocmget) in hso_create_bulk_serial_device()
2633 serial->tiocmget->serial_state_notification in hso_create_bulk_serial_device()
2636 if (!serial->tiocmget->serial_state_notification) in hso_create_bulk_serial_device()
2638 tiocmget = serial->tiocmget; in hso_create_bulk_serial_device()
2657 if (hso_serial_common_create(serial, num_urbs, BULK_URB_RX_SIZE, in hso_create_bulk_serial_device()
2661 serial->in_endp = hso_get_ep(interface, USB_ENDPOINT_XFER_BULK, in hso_create_bulk_serial_device()
2663 if (!serial->in_endp) { in hso_create_bulk_serial_device()
2669 (serial->out_endp = in hso_create_bulk_serial_device()
2675 serial->write_data = hso_std_serial_write_data; in hso_create_bulk_serial_device()
2684 hso_serial_tty_unregister(serial); in hso_create_bulk_serial_device()
2685 hso_serial_common_free(serial); in hso_create_bulk_serial_device()
2687 hso_free_tiomget(serial); in hso_create_bulk_serial_device()
2688 kfree(serial); in hso_create_bulk_serial_device()
2700 struct hso_serial *serial; in hso_create_mux_serial_device() local
2714 serial = kzalloc(sizeof(*serial), GFP_KERNEL); in hso_create_mux_serial_device()
2715 if (!serial) in hso_create_mux_serial_device()
2718 hso_dev->port_data.dev_serial = serial; in hso_create_mux_serial_device()
2719 serial->parent = hso_dev; in hso_create_mux_serial_device()
2722 (serial, 1, CTRL_URB_RX_SIZE, CTRL_URB_TX_SIZE)) in hso_create_mux_serial_device()
2725 serial->tx_data_length--; in hso_create_mux_serial_device()
2726 serial->write_data = hso_mux_serial_write_data; in hso_create_mux_serial_device()
2728 serial->shared_int = mux; in hso_create_mux_serial_device()
2729 mutex_lock(&serial->shared_int->shared_int_lock); in hso_create_mux_serial_device()
2730 serial->shared_int->ref_count++; in hso_create_mux_serial_device()
2731 mutex_unlock(&serial->shared_int->shared_int_lock); in hso_create_mux_serial_device()
2740 kfree(serial); in hso_create_mux_serial_device()
3022 /* Stop all serial ports */ in hso_suspend()
3051 /* Start all serial ports */ in hso_resume()
3100 struct hso_serial *serial; in hso_free_interface() local
3106 serial = dev2ser(serial_table[i]); in hso_free_interface()
3107 tty_port_tty_hangup(&serial->port, false); in hso_free_interface()
3108 mutex_lock(&serial->parent->mutex); in hso_free_interface()
3109 serial->parent->usb_gone = 1; in hso_free_interface()
3110 mutex_unlock(&serial->parent->mutex); in hso_free_interface()
3113 hso_serial_tty_unregister(serial); in hso_free_interface()
3114 kref_put(&serial->parent->ref, hso_serial_ref_free); in hso_free_interface()
3178 /* interrupt urb needs to be submitted, used for serial read of muxed port */
3200 /* operations setup of the serial interface */