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);
369 /* serial structures */
516 static int hso_urb_to_index(struct hso_serial *serial, struct urb *urb) in hso_urb_to_index() argument
520 for (idx = 0; idx < serial->num_rx_urbs; idx++) in hso_urb_to_index()
521 if (serial->rx_urb[idx] == urb) in hso_urb_to_index()
523 dev_err(serial->parent->dev, "hso_urb_to_index failed\n"); in hso_urb_to_index()
602 struct hso_serial *serial = NULL; in get_serial_by_index() local
607 serial = dev2ser(serial_table[index]); in get_serial_by_index()
610 return serial; in get_serial_by_index()
613 static int obtain_minor(struct hso_serial *serial) in obtain_minor() argument
621 serial_table[index] = serial->parent; in obtain_minor()
622 serial->minor = index; in obtain_minor()
629 pr_err("%s: no free serial devices in table\n", __func__); in obtain_minor()
633 static void release_minor(struct hso_serial *serial) in release_minor() argument
638 serial_table[serial->minor] = NULL; in release_minor()
1041 /* Serial driver functions */
1084 struct hso_serial *serial = tty->driver_data; in _hso_serial_set_termios() local
1086 if (!serial) { in _hso_serial_set_termios()
1091 hso_dbg(0x8, "port %d\n", serial->minor); in _hso_serial_set_termios()
1110 static void hso_resubmit_rx_bulk_urb(struct hso_serial *serial, struct urb *urb) in hso_resubmit_rx_bulk_urb() argument
1115 usb_fill_bulk_urb(urb, serial->parent->usb, in hso_resubmit_rx_bulk_urb()
1116 usb_rcvbulkpipe(serial->parent->usb, in hso_resubmit_rx_bulk_urb()
1117 serial->in_endp-> in hso_resubmit_rx_bulk_urb()
1119 urb->transfer_buffer, serial->rx_data_length, in hso_resubmit_rx_bulk_urb()
1120 hso_std_serial_read_bulk_callback, serial); in hso_resubmit_rx_bulk_urb()
1125 dev_err(&urb->dev->dev, "%s failed submit serial rx_urb %d\n", in hso_resubmit_rx_bulk_urb()
1133 static void put_rxbuf_data_and_resubmit_bulk_urb(struct hso_serial *serial) in put_rxbuf_data_and_resubmit_bulk_urb() argument
1138 while (serial->rx_urb_filled[serial->curr_rx_urb_idx]) { in put_rxbuf_data_and_resubmit_bulk_urb()
1139 curr_urb = serial->rx_urb[serial->curr_rx_urb_idx]; in put_rxbuf_data_and_resubmit_bulk_urb()
1140 count = put_rxbuf_data(curr_urb, serial); in put_rxbuf_data_and_resubmit_bulk_urb()
1144 serial->curr_rx_urb_idx++; in put_rxbuf_data_and_resubmit_bulk_urb()
1145 if (serial->curr_rx_urb_idx >= serial->num_rx_urbs) in put_rxbuf_data_and_resubmit_bulk_urb()
1146 serial->curr_rx_urb_idx = 0; in put_rxbuf_data_and_resubmit_bulk_urb()
1147 hso_resubmit_rx_bulk_urb(serial, curr_urb); in put_rxbuf_data_and_resubmit_bulk_urb()
1152 static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial) in put_rxbuf_data_and_resubmit_ctrl_urb() argument
1157 urb = serial->rx_urb[0]; in put_rxbuf_data_and_resubmit_ctrl_urb()
1158 if (serial->port.count > 0) { in put_rxbuf_data_and_resubmit_ctrl_urb()
1159 count = put_rxbuf_data(urb, serial); in put_rxbuf_data_and_resubmit_ctrl_urb()
1166 (serial->rx_state == RX_PENDING))) { in put_rxbuf_data_and_resubmit_ctrl_urb()
1167 serial->rx_state = RX_SENT; in put_rxbuf_data_and_resubmit_ctrl_urb()
1168 hso_mux_serial_read(serial); in put_rxbuf_data_and_resubmit_ctrl_urb()
1170 serial->rx_state = RX_IDLE; in put_rxbuf_data_and_resubmit_ctrl_urb()
1177 struct hso_serial *serial = urb->context; in hso_std_serial_read_bulk_callback() local
1184 if (!serial) { in hso_std_serial_read_bulk_callback()
1185 hso_dbg(0x1, "serial == NULL\n"); in hso_std_serial_read_bulk_callback()
1189 handle_usb_error(status, __func__, serial->parent); in hso_std_serial_read_bulk_callback()
1197 if (serial->port.count == 0) in hso_std_serial_read_bulk_callback()
1200 if (serial->parent->port_spec & HSO_INFO_CRC_BUG) in hso_std_serial_read_bulk_callback()
1201 fix_crc_bug(urb, serial->in_endp->wMaxPacketSize); in hso_std_serial_read_bulk_callback()
1203 spin_lock_irqsave(&serial->serial_lock, flags); in hso_std_serial_read_bulk_callback()
1204 serial->rx_urb_filled[hso_urb_to_index(serial, urb)] = 1; in hso_std_serial_read_bulk_callback()
1205 put_rxbuf_data_and_resubmit_bulk_urb(serial); in hso_std_serial_read_bulk_callback()
1206 spin_unlock_irqrestore(&serial->serial_lock, flags); in hso_std_serial_read_bulk_callback()
1215 struct hso_serial *serial = from_tasklet(serial, t, in hso_unthrottle_tasklet() local
1219 spin_lock_irqsave(&serial->serial_lock, flags); in hso_unthrottle_tasklet()
1220 if ((serial->parent->port_spec & HSO_INTF_MUX)) in hso_unthrottle_tasklet()
1221 put_rxbuf_data_and_resubmit_ctrl_urb(serial); in hso_unthrottle_tasklet()
1223 put_rxbuf_data_and_resubmit_bulk_urb(serial); in hso_unthrottle_tasklet()
1224 spin_unlock_irqrestore(&serial->serial_lock, flags); in hso_unthrottle_tasklet()
1229 struct hso_serial *serial = tty->driver_data; in hso_unthrottle() local
1231 tasklet_hi_schedule(&serial->unthrottle_tasklet); in hso_unthrottle()
1234 /* open the requested serial port */
1237 struct hso_serial *serial = get_serial_by_index(tty->index); in hso_serial_open() local
1241 if (serial == NULL || serial->magic != HSO_SERIAL_MAGIC) { in hso_serial_open()
1248 mutex_lock(&serial->parent->mutex); in hso_serial_open()
1249 result = usb_autopm_get_interface(serial->parent->interface); in hso_serial_open()
1253 hso_dbg(0x1, "Opening %d\n", serial->minor); in hso_serial_open()
1256 tty->driver_data = serial; in hso_serial_open()
1257 tty_port_tty_set(&serial->port, tty); in hso_serial_open()
1260 serial->port.count++; in hso_serial_open()
1261 if (serial->port.count == 1) { in hso_serial_open()
1262 serial->rx_state = RX_IDLE; in hso_serial_open()
1265 tasklet_setup(&serial->unthrottle_tasklet, in hso_serial_open()
1267 result = hso_start_serial_device(serial->parent, GFP_KERNEL); in hso_serial_open()
1269 hso_stop_serial_device(serial->parent); in hso_serial_open()
1270 serial->port.count--; in hso_serial_open()
1272 kref_get(&serial->parent->ref); in hso_serial_open()
1278 usb_autopm_put_interface(serial->parent->interface); in hso_serial_open()
1284 mutex_unlock(&serial->parent->mutex); in hso_serial_open()
1288 /* close the requested serial port */
1291 struct hso_serial *serial = tty->driver_data; in hso_serial_close() local
1294 hso_dbg(0x1, "Closing serial port\n"); in hso_serial_close()
1297 if (serial == NULL) in hso_serial_close()
1300 mutex_lock(&serial->parent->mutex); in hso_serial_close()
1301 usb_gone = serial->parent->usb_gone; in hso_serial_close()
1304 usb_autopm_get_interface(serial->parent->interface); in hso_serial_close()
1308 serial->port.count--; in hso_serial_close()
1310 if (serial->port.count <= 0) { in hso_serial_close()
1311 serial->port.count = 0; in hso_serial_close()
1312 tty_port_tty_set(&serial->port, NULL); in hso_serial_close()
1314 hso_stop_serial_device(serial->parent); in hso_serial_close()
1315 tasklet_kill(&serial->unthrottle_tasklet); in hso_serial_close()
1319 usb_autopm_put_interface(serial->parent->interface); in hso_serial_close()
1321 mutex_unlock(&serial->parent->mutex); in hso_serial_close()
1324 /* close the requested serial port */
1328 struct hso_serial *serial = tty->driver_data; in hso_serial_write() local
1332 if (serial == NULL) { in hso_serial_write()
1333 pr_err("%s: serial is NULL\n", __func__); in hso_serial_write()
1337 spin_lock_irqsave(&serial->serial_lock, flags); in hso_serial_write()
1339 count = min_t(size_t, serial->tx_data_length - serial->tx_buffer_count, in hso_serial_write()
1341 memcpy(serial->tx_buffer + serial->tx_buffer_count, buf, count); in hso_serial_write()
1342 serial->tx_buffer_count += count; in hso_serial_write()
1344 spin_unlock_irqrestore(&serial->serial_lock, flags); in hso_serial_write()
1346 hso_kick_transmit(serial); in hso_serial_write()
1354 struct hso_serial *serial = tty->driver_data; in hso_serial_write_room() local
1358 spin_lock_irqsave(&serial->serial_lock, flags); in hso_serial_write_room()
1359 room = serial->tx_data_length - serial->tx_buffer_count; in hso_serial_write_room()
1360 spin_unlock_irqrestore(&serial->serial_lock, flags); in hso_serial_write_room()
1368 struct hso_serial *serial = tty->driver_data; in hso_serial_cleanup() local
1370 if (!serial) in hso_serial_cleanup()
1373 kref_put(&serial->parent->ref, hso_serial_ref_free); in hso_serial_cleanup()
1380 struct hso_serial *serial = tty->driver_data; in hso_serial_set_termios() local
1389 spin_lock_irqsave(&serial->serial_lock, flags); in hso_serial_set_termios()
1390 if (serial->port.count) in hso_serial_set_termios()
1394 spin_unlock_irqrestore(&serial->serial_lock, flags); in hso_serial_set_termios()
1402 struct hso_serial *serial = tty->driver_data; in hso_serial_chars_in_buffer() local
1407 if (serial == NULL) in hso_serial_chars_in_buffer()
1410 spin_lock_irqsave(&serial->serial_lock, flags); in hso_serial_chars_in_buffer()
1411 chars = serial->tx_buffer_count; in hso_serial_chars_in_buffer()
1412 spin_unlock_irqrestore(&serial->serial_lock, flags); in hso_serial_chars_in_buffer()
1416 static int tiocmget_submit_urb(struct hso_serial *serial, in tiocmget_submit_urb() argument
1422 if (serial->parent->usb_gone) in tiocmget_submit_urb()
1430 tiocmget_intr_callback, serial, in tiocmget_submit_urb()
1443 struct hso_serial *serial = urb->context; in tiocmget_intr_callback() local
1454 if (!serial) in tiocmget_intr_callback()
1457 handle_usb_error(status, __func__, serial->parent); in tiocmget_intr_callback()
1462 tiocmget = serial->tiocmget; in tiocmget_intr_callback()
1465 BUG_ON((serial->parent->port_spec & HSO_PORT_MASK) != HSO_PORT_MODEM); in tiocmget_intr_callback()
1467 usb = serial->parent->usb; in tiocmget_intr_callback()
1468 interface = serial->parent->interface; in tiocmget_intr_callback()
1482 "hso received invalid serial state notification\n"); in tiocmget_intr_callback()
1492 spin_lock_irqsave(&serial->serial_lock, flags); in tiocmget_intr_callback()
1515 spin_unlock_irqrestore(&serial->serial_lock, flags); in tiocmget_intr_callback()
1521 tiocmget_submit_urb(serial, in tiocmget_intr_callback()
1523 serial->parent->usb); in tiocmget_intr_callback()
1527 * next few functions largely stolen from drivers/serial/serial_core.c
1535 hso_wait_modem_status(struct hso_serial *serial, unsigned long arg) in hso_wait_modem_status() argument
1542 tiocmget = serial->tiocmget; in hso_wait_modem_status()
1548 spin_lock_irq(&serial->serial_lock); in hso_wait_modem_status()
1550 spin_unlock_irq(&serial->serial_lock); in hso_wait_modem_status()
1553 spin_lock_irq(&serial->serial_lock); in hso_wait_modem_status()
1555 spin_unlock_irq(&serial->serial_lock); in hso_wait_modem_status()
1578 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
1587 struct hso_serial *serial = tty->driver_data; in hso_get_count() local
1588 struct hso_tiocmget *tiocmget = serial->tiocmget; in hso_get_count()
1594 spin_lock_irq(&serial->serial_lock); in hso_get_count()
1596 spin_unlock_irq(&serial->serial_lock); in hso_get_count()
1617 struct hso_serial *serial = tty->driver_data; in hso_serial_tiocmget() local
1622 if (!serial) { in hso_serial_tiocmget()
1626 spin_lock_irq(&serial->serial_lock); in hso_serial_tiocmget()
1627 retval = ((serial->rts_state) ? TIOCM_RTS : 0) | in hso_serial_tiocmget()
1628 ((serial->dtr_state) ? TIOCM_DTR : 0); in hso_serial_tiocmget()
1629 tiocmget = serial->tiocmget; in hso_serial_tiocmget()
1641 spin_unlock_irq(&serial->serial_lock); in hso_serial_tiocmget()
1651 struct hso_serial *serial = tty->driver_data; in hso_serial_tiocmset() local
1655 if (!serial) { in hso_serial_tiocmset()
1660 if ((serial->parent->port_spec & HSO_PORT_MASK) != HSO_PORT_MODEM) in hso_serial_tiocmset()
1663 interface = serial->parent->interface; in hso_serial_tiocmset()
1666 spin_lock_irqsave(&serial->serial_lock, flags); in hso_serial_tiocmset()
1668 serial->rts_state = 1; in hso_serial_tiocmset()
1670 serial->dtr_state = 1; in hso_serial_tiocmset()
1673 serial->rts_state = 0; in hso_serial_tiocmset()
1675 serial->dtr_state = 0; in hso_serial_tiocmset()
1677 if (serial->dtr_state) in hso_serial_tiocmset()
1679 if (serial->rts_state) in hso_serial_tiocmset()
1682 spin_unlock_irqrestore(&serial->serial_lock, flags); in hso_serial_tiocmset()
1684 return usb_control_msg(serial->parent->usb, in hso_serial_tiocmset()
1685 usb_sndctrlpipe(serial->parent->usb, 0), 0x22, in hso_serial_tiocmset()
1693 struct hso_serial *serial = tty->driver_data; in hso_serial_ioctl() local
1697 if (!serial) in hso_serial_ioctl()
1701 ret = hso_wait_modem_status(serial, arg); in hso_serial_ioctl()
1712 static void hso_kick_transmit(struct hso_serial *serial) in hso_kick_transmit() argument
1717 spin_lock_irqsave(&serial->serial_lock, flags); in hso_kick_transmit()
1718 if (!serial->tx_buffer_count) in hso_kick_transmit()
1721 if (serial->tx_urb_used) in hso_kick_transmit()
1725 if (hso_get_activity(serial->parent) == -EAGAIN) in hso_kick_transmit()
1729 swap(serial->tx_buffer, serial->tx_data); in hso_kick_transmit()
1730 serial->tx_data_count = serial->tx_buffer_count; in hso_kick_transmit()
1731 serial->tx_buffer_count = 0; in hso_kick_transmit()
1733 /* If serial->tx_data is set, it means we switched buffers */ in hso_kick_transmit()
1734 if (serial->tx_data && serial->write_data) { in hso_kick_transmit()
1735 res = serial->write_data(serial); in hso_kick_transmit()
1737 serial->tx_urb_used = 1; in hso_kick_transmit()
1740 spin_unlock_irqrestore(&serial->serial_lock, flags); in hso_kick_transmit()
1743 /* make a request (for reading and writing data to muxed serial port) */
1744 static int mux_device_request(struct hso_serial *serial, u8 type, u16 port, in mux_device_request() argument
1753 if (!serial || !ctrl_urb || !ctrl_req) { in mux_device_request()
1769 pipe = usb_rcvctrlpipe(serial->parent->usb, 0); in mux_device_request()
1776 pipe = usb_sndctrlpipe(serial->parent->usb, 0); in mux_device_request()
1786 serial->parent->usb, in mux_device_request()
1789 ctrl_urb_data, size, ctrl_callback, serial); in mux_device_request()
1804 static int hso_mux_serial_read(struct hso_serial *serial) in hso_mux_serial_read() argument
1806 if (!serial) in hso_mux_serial_read()
1810 memset(serial->rx_data[0], 0, CTRL_URB_RX_SIZE); in hso_mux_serial_read()
1813 if (serial->num_rx_urbs != 1) { in hso_mux_serial_read()
1814 dev_err(&serial->parent->interface->dev, in hso_mux_serial_read()
1819 return mux_device_request(serial, in hso_mux_serial_read()
1821 serial->parent->port_spec & HSO_PORT_MASK, in hso_mux_serial_read()
1822 serial->rx_urb[0], in hso_mux_serial_read()
1823 &serial->ctrl_req_rx, in hso_mux_serial_read()
1824 serial->rx_data[0], serial->rx_data_length); in hso_mux_serial_read()
1827 /* used for muxed serial port callback (muxed serial read) */
1831 struct hso_serial *serial; in intr_callback() local
1857 serial = get_serial_by_shared_int_and_type(shared_int, in intr_callback()
1859 if (serial != NULL) { in intr_callback()
1862 spin_lock_irqsave(&serial->serial_lock, flags); in intr_callback()
1863 if (serial->rx_state == RX_IDLE && in intr_callback()
1864 serial->port.count > 0) { in intr_callback()
1867 if (!serial->rx_urb_filled[0]) { in intr_callback()
1868 serial->rx_state = RX_SENT; in intr_callback()
1869 hso_mux_serial_read(serial); in intr_callback()
1871 serial->rx_state = RX_PENDING; in intr_callback()
1876 spin_unlock_irqrestore(&serial->serial_lock, in intr_callback()
1885 /* called for writing to muxed serial port */
1886 static int hso_mux_serial_write_data(struct hso_serial *serial) in hso_mux_serial_write_data() argument
1888 if (NULL == serial) in hso_mux_serial_write_data()
1891 return mux_device_request(serial, in hso_mux_serial_write_data()
1893 serial->parent->port_spec & HSO_PORT_MASK, in hso_mux_serial_write_data()
1894 serial->tx_urb, in hso_mux_serial_write_data()
1895 &serial->ctrl_req_tx, in hso_mux_serial_write_data()
1896 serial->tx_data, serial->tx_data_count); in hso_mux_serial_write_data()
1902 struct hso_serial *serial = urb->context; in hso_std_serial_write_bulk_callback() local
1907 if (!serial) { in hso_std_serial_write_bulk_callback()
1908 hso_dbg(0x1, "serial == NULL\n"); in hso_std_serial_write_bulk_callback()
1912 spin_lock_irqsave(&serial->serial_lock, flags); in hso_std_serial_write_bulk_callback()
1913 serial->tx_urb_used = 0; in hso_std_serial_write_bulk_callback()
1914 spin_unlock_irqrestore(&serial->serial_lock, flags); in hso_std_serial_write_bulk_callback()
1916 handle_usb_error(status, __func__, serial->parent); in hso_std_serial_write_bulk_callback()
1919 hso_put_activity(serial->parent); in hso_std_serial_write_bulk_callback()
1920 tty_port_tty_wakeup(&serial->port); in hso_std_serial_write_bulk_callback()
1921 hso_kick_transmit(serial); in hso_std_serial_write_bulk_callback()
1926 /* called for writing diag or CS serial port */
1927 static int hso_std_serial_write_data(struct hso_serial *serial) in hso_std_serial_write_data() argument
1929 int count = serial->tx_data_count; in hso_std_serial_write_data()
1932 usb_fill_bulk_urb(serial->tx_urb, in hso_std_serial_write_data()
1933 serial->parent->usb, in hso_std_serial_write_data()
1934 usb_sndbulkpipe(serial->parent->usb, in hso_std_serial_write_data()
1935 serial->out_endp-> in hso_std_serial_write_data()
1937 serial->tx_data, serial->tx_data_count, in hso_std_serial_write_data()
1938 hso_std_serial_write_bulk_callback, serial); in hso_std_serial_write_data()
1940 result = usb_submit_urb(serial->tx_urb, GFP_ATOMIC); in hso_std_serial_write_data()
1942 dev_warn(&serial->parent->usb->dev, in hso_std_serial_write_data()
1950 /* callback after read or write on muxed serial port */
1953 struct hso_serial *serial = urb->context; in ctrl_callback() local
1959 if (!serial) in ctrl_callback()
1962 spin_lock_irqsave(&serial->serial_lock, flags); in ctrl_callback()
1963 serial->tx_urb_used = 0; in ctrl_callback()
1964 spin_unlock_irqrestore(&serial->serial_lock, flags); in ctrl_callback()
1966 handle_usb_error(status, __func__, serial->parent); in ctrl_callback()
1979 serial->rx_urb_filled[0] = 1; in ctrl_callback()
1980 spin_lock_irqsave(&serial->serial_lock, flags); in ctrl_callback()
1981 put_rxbuf_data_and_resubmit_ctrl_urb(serial); in ctrl_callback()
1982 spin_unlock_irqrestore(&serial->serial_lock, flags); in ctrl_callback()
1984 hso_put_activity(serial->parent); in ctrl_callback()
1985 tty_port_tty_wakeup(&serial->port); in ctrl_callback()
1987 hso_kick_transmit(serial); in ctrl_callback()
1991 /* handle RX data for serial port */
1992 static int put_rxbuf_data(struct urb *urb, struct hso_serial *serial) in put_rxbuf_data() argument
1998 if (urb == NULL || serial == NULL) { in put_rxbuf_data()
1999 hso_dbg(0x1, "serial = NULL\n"); in put_rxbuf_data()
2003 tty = tty_port_tty_get(&serial->port); in put_rxbuf_data()
2012 count = tty_buffer_request_room(&serial->port, urb->actual_length); in put_rxbuf_data()
2014 tty_insert_flip_string(&serial->port, urb->transfer_buffer, in put_rxbuf_data()
2016 tty_flip_buffer_push(&serial->port); in put_rxbuf_data()
2018 dev_warn(&serial->parent->usb->dev, in put_rxbuf_data()
2024 serial->rx_urb_filled[hso_urb_to_index(serial, urb)] = 0; in put_rxbuf_data()
2137 struct hso_serial *serial = dev2ser(hso_dev); in hso_start_serial_device() local
2139 if (!serial) in hso_start_serial_device()
2144 if (!(serial->parent->port_spec & HSO_INTF_MUX)) { in hso_start_serial_device()
2145 for (i = 0; i < serial->num_rx_urbs; i++) { in hso_start_serial_device()
2146 usb_fill_bulk_urb(serial->rx_urb[i], in hso_start_serial_device()
2147 serial->parent->usb, in hso_start_serial_device()
2148 usb_rcvbulkpipe(serial->parent->usb, in hso_start_serial_device()
2149 serial->in_endp-> in hso_start_serial_device()
2152 serial->rx_data[i], in hso_start_serial_device()
2153 serial->rx_data_length, in hso_start_serial_device()
2155 serial); in hso_start_serial_device()
2156 result = usb_submit_urb(serial->rx_urb[i], flags); in hso_start_serial_device()
2158 dev_warn(&serial->parent->usb->dev, in hso_start_serial_device()
2165 mutex_lock(&serial->shared_int->shared_int_lock); in hso_start_serial_device()
2166 if (!serial->shared_int->use_count) { in hso_start_serial_device()
2168 hso_mux_submit_intr_urb(serial->shared_int, in hso_start_serial_device()
2171 serial->shared_int->use_count++; in hso_start_serial_device()
2172 mutex_unlock(&serial->shared_int->shared_int_lock); in hso_start_serial_device()
2174 if (serial->tiocmget) in hso_start_serial_device()
2175 tiocmget_submit_urb(serial, in hso_start_serial_device()
2176 serial->tiocmget, in hso_start_serial_device()
2177 serial->parent->usb); in hso_start_serial_device()
2184 struct hso_serial *serial = dev2ser(hso_dev); in hso_stop_serial_device() local
2187 if (!serial) in hso_stop_serial_device()
2190 for (i = 0; i < serial->num_rx_urbs; i++) { in hso_stop_serial_device()
2191 if (serial->rx_urb[i]) { in hso_stop_serial_device()
2192 usb_kill_urb(serial->rx_urb[i]); in hso_stop_serial_device()
2193 serial->rx_urb_filled[i] = 0; in hso_stop_serial_device()
2196 serial->curr_rx_urb_idx = 0; in hso_stop_serial_device()
2198 if (serial->tx_urb) in hso_stop_serial_device()
2199 usb_kill_urb(serial->tx_urb); in hso_stop_serial_device()
2201 if (serial->shared_int) { in hso_stop_serial_device()
2202 mutex_lock(&serial->shared_int->shared_int_lock); in hso_stop_serial_device()
2203 if (serial->shared_int->use_count && in hso_stop_serial_device()
2204 (--serial->shared_int->use_count == 0)) { in hso_stop_serial_device()
2207 urb = serial->shared_int->shared_intr_urb; in hso_stop_serial_device()
2211 mutex_unlock(&serial->shared_int->shared_int_lock); in hso_stop_serial_device()
2213 tiocmget = serial->tiocmget; in hso_stop_serial_device()
2222 static void hso_serial_tty_unregister(struct hso_serial *serial) in hso_serial_tty_unregister() argument
2224 tty_unregister_device(tty_drv, serial->minor); in hso_serial_tty_unregister()
2225 release_minor(serial); in hso_serial_tty_unregister()
2228 static void hso_serial_common_free(struct hso_serial *serial) in hso_serial_common_free() argument
2232 for (i = 0; i < serial->num_rx_urbs; i++) { in hso_serial_common_free()
2234 usb_free_urb(serial->rx_urb[i]); in hso_serial_common_free()
2236 kfree(serial->rx_data[i]); in hso_serial_common_free()
2240 usb_free_urb(serial->tx_urb); in hso_serial_common_free()
2241 kfree(serial->tx_buffer); in hso_serial_common_free()
2242 kfree(serial->tx_data); in hso_serial_common_free()
2243 tty_port_destroy(&serial->port); in hso_serial_common_free()
2246 static int hso_serial_common_create(struct hso_serial *serial, int num_urbs, in hso_serial_common_create() argument
2251 tty_port_init(&serial->port); in hso_serial_common_create()
2253 if (obtain_minor(serial)) in hso_serial_common_create()
2257 serial->parent->dev = tty_port_register_device_attr(&serial->port, in hso_serial_common_create()
2258 tty_drv, serial->minor, &serial->parent->interface->dev, in hso_serial_common_create()
2259 serial->parent, hso_serial_dev_groups); in hso_serial_common_create()
2260 if (IS_ERR(serial->parent->dev)) { in hso_serial_common_create()
2261 release_minor(serial); in hso_serial_common_create()
2265 serial->magic = HSO_SERIAL_MAGIC; in hso_serial_common_create()
2266 spin_lock_init(&serial->serial_lock); in hso_serial_common_create()
2267 serial->num_rx_urbs = num_urbs; in hso_serial_common_create()
2272 serial->rx_data_length = rx_size; in hso_serial_common_create()
2273 for (i = 0; i < serial->num_rx_urbs; i++) { in hso_serial_common_create()
2274 serial->rx_urb[i] = usb_alloc_urb(0, GFP_KERNEL); in hso_serial_common_create()
2275 if (!serial->rx_urb[i]) in hso_serial_common_create()
2277 serial->rx_urb[i]->transfer_buffer = NULL; in hso_serial_common_create()
2278 serial->rx_urb[i]->transfer_buffer_length = 0; in hso_serial_common_create()
2279 serial->rx_data[i] = kzalloc(serial->rx_data_length, in hso_serial_common_create()
2281 if (!serial->rx_data[i]) in hso_serial_common_create()
2286 serial->tx_urb = usb_alloc_urb(0, GFP_KERNEL); in hso_serial_common_create()
2287 if (!serial->tx_urb) in hso_serial_common_create()
2289 serial->tx_urb->transfer_buffer = NULL; in hso_serial_common_create()
2290 serial->tx_urb->transfer_buffer_length = 0; in hso_serial_common_create()
2292 serial->tx_data_count = 0; in hso_serial_common_create()
2293 serial->tx_buffer_count = 0; in hso_serial_common_create()
2294 serial->tx_data_length = tx_size; in hso_serial_common_create()
2295 serial->tx_data = kzalloc(serial->tx_data_length, GFP_KERNEL); in hso_serial_common_create()
2296 if (!serial->tx_data) in hso_serial_common_create()
2299 serial->tx_buffer = kzalloc(serial->tx_data_length, GFP_KERNEL); in hso_serial_common_create()
2300 if (!serial->tx_buffer) in hso_serial_common_create()
2305 hso_serial_tty_unregister(serial); in hso_serial_common_create()
2307 hso_serial_common_free(serial); in hso_serial_common_create()
2570 static void hso_free_tiomget(struct hso_serial *serial) in hso_free_tiomget() argument
2573 if (!serial) in hso_free_tiomget()
2575 tiocmget = serial->tiocmget; in hso_free_tiomget()
2579 serial->tiocmget = NULL; in hso_free_tiomget()
2589 struct hso_serial *serial = dev2ser(hso_dev); in hso_free_serial_device() local
2591 if (!serial) in hso_free_serial_device()
2594 hso_serial_common_free(serial); in hso_free_serial_device()
2596 if (serial->shared_int) { in hso_free_serial_device()
2597 mutex_lock(&serial->shared_int->shared_int_lock); in hso_free_serial_device()
2598 if (--serial->shared_int->ref_count == 0) in hso_free_serial_device()
2599 hso_free_shared_int(serial->shared_int); in hso_free_serial_device()
2601 mutex_unlock(&serial->shared_int->shared_int_lock); in hso_free_serial_device()
2603 hso_free_tiomget(serial); in hso_free_serial_device()
2604 kfree(serial); in hso_free_serial_device()
2613 struct hso_serial *serial; in hso_create_bulk_serial_device() local
2621 serial = kzalloc(sizeof(*serial), GFP_KERNEL); in hso_create_bulk_serial_device()
2622 if (!serial) in hso_create_bulk_serial_device()
2625 serial->parent = hso_dev; in hso_create_bulk_serial_device()
2626 hso_dev->port_data.dev_serial = serial; in hso_create_bulk_serial_device()
2630 serial->tiocmget = kzalloc(sizeof(struct hso_tiocmget), in hso_create_bulk_serial_device()
2632 if (!serial->tiocmget) in hso_create_bulk_serial_device()
2634 serial->tiocmget->serial_state_notification in hso_create_bulk_serial_device()
2637 if (!serial->tiocmget->serial_state_notification) in hso_create_bulk_serial_device()
2639 tiocmget = serial->tiocmget; in hso_create_bulk_serial_device()
2658 if (hso_serial_common_create(serial, num_urbs, BULK_URB_RX_SIZE, in hso_create_bulk_serial_device()
2662 serial->in_endp = hso_get_ep(interface, USB_ENDPOINT_XFER_BULK, in hso_create_bulk_serial_device()
2664 if (!serial->in_endp) { in hso_create_bulk_serial_device()
2670 (serial->out_endp = in hso_create_bulk_serial_device()
2676 serial->write_data = hso_std_serial_write_data; in hso_create_bulk_serial_device()
2685 hso_serial_tty_unregister(serial); in hso_create_bulk_serial_device()
2686 hso_serial_common_free(serial); in hso_create_bulk_serial_device()
2688 hso_free_tiomget(serial); in hso_create_bulk_serial_device()
2689 kfree(serial); in hso_create_bulk_serial_device()
2701 struct hso_serial *serial; in hso_create_mux_serial_device() local
2715 serial = kzalloc(sizeof(*serial), GFP_KERNEL); in hso_create_mux_serial_device()
2716 if (!serial) in hso_create_mux_serial_device()
2719 hso_dev->port_data.dev_serial = serial; in hso_create_mux_serial_device()
2720 serial->parent = hso_dev; in hso_create_mux_serial_device()
2723 (serial, 1, CTRL_URB_RX_SIZE, CTRL_URB_TX_SIZE)) in hso_create_mux_serial_device()
2726 serial->tx_data_length--; in hso_create_mux_serial_device()
2727 serial->write_data = hso_mux_serial_write_data; in hso_create_mux_serial_device()
2729 serial->shared_int = mux; in hso_create_mux_serial_device()
2730 mutex_lock(&serial->shared_int->shared_int_lock); in hso_create_mux_serial_device()
2731 serial->shared_int->ref_count++; in hso_create_mux_serial_device()
2732 mutex_unlock(&serial->shared_int->shared_int_lock); in hso_create_mux_serial_device()
2741 kfree(serial); in hso_create_mux_serial_device()
3023 /* Stop all serial ports */ in hso_suspend()
3052 /* Start all serial ports */ in hso_resume()
3101 struct hso_serial *serial; in hso_free_interface() local
3107 serial = dev2ser(serial_table[i]); in hso_free_interface()
3108 tty_port_tty_hangup(&serial->port, false); in hso_free_interface()
3109 mutex_lock(&serial->parent->mutex); in hso_free_interface()
3110 serial->parent->usb_gone = 1; in hso_free_interface()
3111 mutex_unlock(&serial->parent->mutex); in hso_free_interface()
3114 hso_serial_tty_unregister(serial); in hso_free_interface()
3115 kref_put(&serial->parent->ref, hso_serial_ref_free); in hso_free_interface()
3179 /* interrupt urb needs to be submitted, used for serial read of muxed port */
3201 /* operations setup of the serial interface */
3237 /* Initialise the serial table semaphore and table */ in hso_init()