1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * mxuport.c - MOXA UPort series driver
4 *
5 * Copyright (c) 2006 Moxa Technologies Co., Ltd.
6 * Copyright (c) 2013 Andrew Lunn <andrew@lunn.ch>
7 *
8 * Supports the following Moxa USB to serial converters:
9 * 2 ports : UPort 1250, UPort 1250I
10 * 4 ports : UPort 1410, UPort 1450, UPort 1450I
11 * 8 ports : UPort 1610-8, UPort 1650-8
12 * 16 ports : UPort 1610-16, UPort 1650-16
13 */
14
15 #include <linux/kernel.h>
16 #include <linux/module.h>
17 #include <linux/firmware.h>
18 #include <linux/jiffies.h>
19 #include <linux/serial.h>
20 #include <linux/serial_reg.h>
21 #include <linux/slab.h>
22 #include <linux/tty.h>
23 #include <linux/tty_flip.h>
24 #include <linux/usb.h>
25 #include <linux/usb/serial.h>
26 #include <linux/unaligned.h>
27
28 /* Definitions for the vendor ID and device ID */
29 #define MX_USBSERIAL_VID 0x110A
30 #define MX_UPORT1250_PID 0x1250
31 #define MX_UPORT1251_PID 0x1251
32 #define MX_UPORT1410_PID 0x1410
33 #define MX_UPORT1450_PID 0x1450
34 #define MX_UPORT1451_PID 0x1451
35 #define MX_UPORT1618_PID 0x1618
36 #define MX_UPORT1658_PID 0x1658
37 #define MX_UPORT1613_PID 0x1613
38 #define MX_UPORT1653_PID 0x1653
39
40 /* Definitions for USB info */
41 #define HEADER_SIZE 4
42 #define EVENT_LENGTH 8
43 #define DOWN_BLOCK_SIZE 64
44
45 /* Definitions for firmware info */
46 #define VER_ADDR_1 0x20
47 #define VER_ADDR_2 0x24
48 #define VER_ADDR_3 0x28
49
50 /* Definitions for USB vendor request */
51 #define RQ_VENDOR_NONE 0x00
52 #define RQ_VENDOR_SET_BAUD 0x01 /* Set baud rate */
53 #define RQ_VENDOR_SET_LINE 0x02 /* Set line status */
54 #define RQ_VENDOR_SET_CHARS 0x03 /* Set Xon/Xoff chars */
55 #define RQ_VENDOR_SET_RTS 0x04 /* Set RTS */
56 #define RQ_VENDOR_SET_DTR 0x05 /* Set DTR */
57 #define RQ_VENDOR_SET_XONXOFF 0x06 /* Set auto Xon/Xoff */
58 #define RQ_VENDOR_SET_RX_HOST_EN 0x07 /* Set RX host enable */
59 #define RQ_VENDOR_SET_OPEN 0x08 /* Set open/close port */
60 #define RQ_VENDOR_PURGE 0x09 /* Purge Rx/Tx buffer */
61 #define RQ_VENDOR_SET_MCR 0x0A /* Set MCR register */
62 #define RQ_VENDOR_SET_BREAK 0x0B /* Set Break signal */
63
64 #define RQ_VENDOR_START_FW_DOWN 0x0C /* Start firmware download */
65 #define RQ_VENDOR_STOP_FW_DOWN 0x0D /* Stop firmware download */
66 #define RQ_VENDOR_QUERY_FW_READY 0x0E /* Query if new firmware ready */
67
68 #define RQ_VENDOR_SET_FIFO_DISABLE 0x0F /* Set fifo disable */
69 #define RQ_VENDOR_SET_INTERFACE 0x10 /* Set interface */
70 #define RQ_VENDOR_SET_HIGH_PERFOR 0x11 /* Set hi-performance */
71
72 #define RQ_VENDOR_ERASE_BLOCK 0x12 /* Erase flash block */
73 #define RQ_VENDOR_WRITE_PAGE 0x13 /* Write flash page */
74 #define RQ_VENDOR_PREPARE_WRITE 0x14 /* Prepare write flash */
75 #define RQ_VENDOR_CONFIRM_WRITE 0x15 /* Confirm write flash */
76 #define RQ_VENDOR_LOCATE 0x16 /* Locate the device */
77
78 #define RQ_VENDOR_START_ROM_DOWN 0x17 /* Start firmware download */
79 #define RQ_VENDOR_ROM_DATA 0x18 /* Rom file data */
80 #define RQ_VENDOR_STOP_ROM_DOWN 0x19 /* Stop firmware download */
81 #define RQ_VENDOR_FW_DATA 0x20 /* Firmware data */
82
83 #define RQ_VENDOR_RESET_DEVICE 0x23 /* Try to reset the device */
84 #define RQ_VENDOR_QUERY_FW_CONFIG 0x24
85
86 #define RQ_VENDOR_GET_VERSION 0x81 /* Get firmware version */
87 #define RQ_VENDOR_GET_PAGE 0x82 /* Read flash page */
88 #define RQ_VENDOR_GET_ROM_PROC 0x83 /* Get ROM process state */
89
90 #define RQ_VENDOR_GET_INQUEUE 0x84 /* Data in input buffer */
91 #define RQ_VENDOR_GET_OUTQUEUE 0x85 /* Data in output buffer */
92
93 #define RQ_VENDOR_GET_MSR 0x86 /* Get modem status register */
94
95 /* Definitions for UPort event type */
96 #define UPORT_EVENT_NONE 0 /* None */
97 #define UPORT_EVENT_TXBUF_THRESHOLD 1 /* Tx buffer threshold */
98 #define UPORT_EVENT_SEND_NEXT 2 /* Send next */
99 #define UPORT_EVENT_MSR 3 /* Modem status */
100 #define UPORT_EVENT_LSR 4 /* Line status */
101 #define UPORT_EVENT_MCR 5 /* Modem control */
102
103 /* Definitions for serial event type */
104 #define SERIAL_EV_CTS 0x0008 /* CTS changed state */
105 #define SERIAL_EV_DSR 0x0010 /* DSR changed state */
106 #define SERIAL_EV_RLSD 0x0020 /* RLSD changed state */
107
108 /* Definitions for modem control event type */
109 #define SERIAL_EV_XOFF 0x40 /* XOFF received */
110
111 /* Definitions for line control of communication */
112 #define MX_WORDLENGTH_5 5
113 #define MX_WORDLENGTH_6 6
114 #define MX_WORDLENGTH_7 7
115 #define MX_WORDLENGTH_8 8
116
117 #define MX_PARITY_NONE 0
118 #define MX_PARITY_ODD 1
119 #define MX_PARITY_EVEN 2
120 #define MX_PARITY_MARK 3
121 #define MX_PARITY_SPACE 4
122
123 #define MX_STOP_BITS_1 0
124 #define MX_STOP_BITS_1_5 1
125 #define MX_STOP_BITS_2 2
126
127 #define MX_RTS_DISABLE 0x0
128 #define MX_RTS_ENABLE 0x1
129 #define MX_RTS_HW 0x2
130 #define MX_RTS_NO_CHANGE 0x3 /* Flag, not valid register value*/
131
132 #define MX_INT_RS232 0
133 #define MX_INT_2W_RS485 1
134 #define MX_INT_RS422 2
135 #define MX_INT_4W_RS485 3
136
137 /* Definitions for holding reason */
138 #define MX_WAIT_FOR_CTS 0x0001
139 #define MX_WAIT_FOR_DSR 0x0002
140 #define MX_WAIT_FOR_DCD 0x0004
141 #define MX_WAIT_FOR_XON 0x0008
142 #define MX_WAIT_FOR_START_TX 0x0010
143 #define MX_WAIT_FOR_UNTHROTTLE 0x0020
144 #define MX_WAIT_FOR_LOW_WATER 0x0040
145 #define MX_WAIT_FOR_SEND_NEXT 0x0080
146
147 /* This structure holds all of the local port information */
148 struct mxuport_port {
149 u8 mcr_state; /* Last MCR state */
150 u8 msr_state; /* Last MSR state */
151 struct mutex mutex; /* Protects mcr_state */
152 spinlock_t spinlock; /* Protects msr_state */
153 };
154
155 /* Encode number of ports (2..16 or undefined) */
156 #define MX_PORTS_MASK GENMASK(3, 0)
157 #define MX_PORTS_OFFSET 1
158 #define MX_PORTS(n) (((n) - MX_PORTS_OFFSET) & MX_PORTS_MASK)
159
160 /* Table of devices that work with this driver */
161 static const struct usb_device_id mxuport_idtable[] = {
162 { USB_DEVICE(MX_USBSERIAL_VID, MX_UPORT1250_PID),
163 .driver_info = MX_PORTS(2) },
164 { USB_DEVICE(MX_USBSERIAL_VID, MX_UPORT1251_PID),
165 .driver_info = MX_PORTS(2) },
166 { USB_DEVICE(MX_USBSERIAL_VID, MX_UPORT1410_PID),
167 .driver_info = MX_PORTS(4) },
168 { USB_DEVICE(MX_USBSERIAL_VID, MX_UPORT1450_PID),
169 .driver_info = MX_PORTS(4) },
170 { USB_DEVICE(MX_USBSERIAL_VID, MX_UPORT1451_PID),
171 .driver_info = MX_PORTS(4) },
172 { USB_DEVICE(MX_USBSERIAL_VID, MX_UPORT1618_PID),
173 .driver_info = MX_PORTS(8) },
174 { USB_DEVICE(MX_USBSERIAL_VID, MX_UPORT1658_PID),
175 .driver_info = MX_PORTS(8) },
176 { USB_DEVICE(MX_USBSERIAL_VID, MX_UPORT1613_PID),
177 .driver_info = MX_PORTS(16) },
178 { USB_DEVICE(MX_USBSERIAL_VID, MX_UPORT1653_PID),
179 .driver_info = MX_PORTS(16) },
180 {} /* Terminating entry */
181 };
182
183 MODULE_DEVICE_TABLE(usb, mxuport_idtable);
184
185 /*
186 * Add a four byte header containing the port number and the number of
187 * bytes of data in the message. Return the number of bytes in the
188 * buffer.
189 */
mxuport_prepare_write_buffer(struct usb_serial_port * port,void * dest,size_t size)190 static int mxuport_prepare_write_buffer(struct usb_serial_port *port,
191 void *dest, size_t size)
192 {
193 u8 *buf = dest;
194 int count;
195
196 count = kfifo_out_locked(&port->write_fifo, buf + HEADER_SIZE,
197 size - HEADER_SIZE,
198 &port->lock);
199
200 put_unaligned_be16(port->port_number, buf);
201 put_unaligned_be16(count, buf + 2);
202
203 dev_dbg(&port->dev, "%s - size %zd count %d\n", __func__,
204 size, count);
205
206 return count + HEADER_SIZE;
207 }
208
209 /* Read the given buffer in from the control pipe. */
mxuport_recv_ctrl_urb(struct usb_serial * serial,u8 request,u16 value,u16 index,u8 * data,size_t size)210 static int mxuport_recv_ctrl_urb(struct usb_serial *serial,
211 u8 request, u16 value, u16 index,
212 u8 *data, size_t size)
213 {
214 int status;
215
216 status = usb_control_msg(serial->dev,
217 usb_rcvctrlpipe(serial->dev, 0),
218 request,
219 (USB_DIR_IN | USB_TYPE_VENDOR |
220 USB_RECIP_DEVICE), value, index,
221 data, size,
222 USB_CTRL_GET_TIMEOUT);
223 if (status < 0) {
224 dev_err(&serial->interface->dev,
225 "%s - usb_control_msg failed (%d)\n",
226 __func__, status);
227 return status;
228 }
229
230 if (status != size) {
231 dev_err(&serial->interface->dev,
232 "%s - short read (%d / %zd)\n",
233 __func__, status, size);
234 return -EIO;
235 }
236
237 return status;
238 }
239
240 /* Write the given buffer out to the control pipe. */
mxuport_send_ctrl_data_urb(struct usb_serial * serial,u8 request,u16 value,u16 index,u8 * data,size_t size)241 static int mxuport_send_ctrl_data_urb(struct usb_serial *serial,
242 u8 request,
243 u16 value, u16 index,
244 u8 *data, size_t size)
245 {
246 int status;
247
248 status = usb_control_msg(serial->dev,
249 usb_sndctrlpipe(serial->dev, 0),
250 request,
251 (USB_DIR_OUT | USB_TYPE_VENDOR |
252 USB_RECIP_DEVICE), value, index,
253 data, size,
254 USB_CTRL_SET_TIMEOUT);
255 if (status < 0) {
256 dev_err(&serial->interface->dev,
257 "%s - usb_control_msg failed (%d)\n",
258 __func__, status);
259 return status;
260 }
261
262 return 0;
263 }
264
265 /* Send a vendor request without any data */
mxuport_send_ctrl_urb(struct usb_serial * serial,u8 request,u16 value,u16 index)266 static int mxuport_send_ctrl_urb(struct usb_serial *serial,
267 u8 request, u16 value, u16 index)
268 {
269 return mxuport_send_ctrl_data_urb(serial, request, value, index,
270 NULL, 0);
271 }
272
273 /*
274 * mxuport_throttle - throttle function of driver
275 *
276 * This function is called by the tty driver when it wants to stop the
277 * data being read from the port. Since all the data comes over one
278 * bulk in endpoint, we cannot stop submitting urbs by setting
279 * port->throttle. Instead tell the device to stop sending us data for
280 * the port.
281 */
mxuport_throttle(struct tty_struct * tty)282 static void mxuport_throttle(struct tty_struct *tty)
283 {
284 struct usb_serial_port *port = tty->driver_data;
285 struct usb_serial *serial = port->serial;
286
287 dev_dbg(&port->dev, "%s\n", __func__);
288
289 mxuport_send_ctrl_urb(serial, RQ_VENDOR_SET_RX_HOST_EN,
290 0, port->port_number);
291 }
292
293 /*
294 * mxuport_unthrottle - unthrottle function of driver
295 *
296 * This function is called by the tty driver when it wants to resume
297 * the data being read from the port. Tell the device it can resume
298 * sending us received data from the port.
299 */
mxuport_unthrottle(struct tty_struct * tty)300 static void mxuport_unthrottle(struct tty_struct *tty)
301 {
302
303 struct usb_serial_port *port = tty->driver_data;
304 struct usb_serial *serial = port->serial;
305
306 dev_dbg(&port->dev, "%s\n", __func__);
307
308 mxuport_send_ctrl_urb(serial, RQ_VENDOR_SET_RX_HOST_EN,
309 1, port->port_number);
310 }
311
312 /*
313 * Processes one chunk of data received for a port. Mostly a copy of
314 * usb_serial_generic_process_read_urb().
315 */
mxuport_process_read_urb_data(struct usb_serial_port * port,char * data,int size)316 static void mxuport_process_read_urb_data(struct usb_serial_port *port,
317 char *data, int size)
318 {
319 int i;
320
321 if (port->sysrq) {
322 for (i = 0; i < size; i++, data++) {
323 if (!usb_serial_handle_sysrq_char(port, *data))
324 tty_insert_flip_char(&port->port, *data,
325 TTY_NORMAL);
326 }
327 } else {
328 tty_insert_flip_string(&port->port, data, size);
329 }
330 tty_flip_buffer_push(&port->port);
331 }
332
mxuport_msr_event(struct usb_serial_port * port,u8 buf[4])333 static void mxuport_msr_event(struct usb_serial_port *port, u8 buf[4])
334 {
335 struct mxuport_port *mxport = usb_get_serial_port_data(port);
336 u8 rcv_msr_hold = buf[2] & 0xF0;
337 u16 rcv_msr_event = get_unaligned_be16(buf);
338 unsigned long flags;
339
340 if (rcv_msr_event == 0)
341 return;
342
343 /* Update MSR status */
344 spin_lock_irqsave(&mxport->spinlock, flags);
345
346 dev_dbg(&port->dev, "%s - current MSR status = 0x%x\n",
347 __func__, mxport->msr_state);
348
349 if (rcv_msr_hold & UART_MSR_CTS) {
350 mxport->msr_state |= UART_MSR_CTS;
351 dev_dbg(&port->dev, "%s - CTS high\n", __func__);
352 } else {
353 mxport->msr_state &= ~UART_MSR_CTS;
354 dev_dbg(&port->dev, "%s - CTS low\n", __func__);
355 }
356
357 if (rcv_msr_hold & UART_MSR_DSR) {
358 mxport->msr_state |= UART_MSR_DSR;
359 dev_dbg(&port->dev, "%s - DSR high\n", __func__);
360 } else {
361 mxport->msr_state &= ~UART_MSR_DSR;
362 dev_dbg(&port->dev, "%s - DSR low\n", __func__);
363 }
364
365 if (rcv_msr_hold & UART_MSR_DCD) {
366 mxport->msr_state |= UART_MSR_DCD;
367 dev_dbg(&port->dev, "%s - DCD high\n", __func__);
368 } else {
369 mxport->msr_state &= ~UART_MSR_DCD;
370 dev_dbg(&port->dev, "%s - DCD low\n", __func__);
371 }
372 spin_unlock_irqrestore(&mxport->spinlock, flags);
373
374 if (rcv_msr_event &
375 (SERIAL_EV_CTS | SERIAL_EV_DSR | SERIAL_EV_RLSD)) {
376
377 if (rcv_msr_event & SERIAL_EV_CTS) {
378 port->icount.cts++;
379 dev_dbg(&port->dev, "%s - CTS change\n", __func__);
380 }
381
382 if (rcv_msr_event & SERIAL_EV_DSR) {
383 port->icount.dsr++;
384 dev_dbg(&port->dev, "%s - DSR change\n", __func__);
385 }
386
387 if (rcv_msr_event & SERIAL_EV_RLSD) {
388 port->icount.dcd++;
389 dev_dbg(&port->dev, "%s - DCD change\n", __func__);
390 }
391 wake_up_interruptible(&port->port.delta_msr_wait);
392 }
393 }
394
mxuport_lsr_event(struct usb_serial_port * port,u8 buf[4])395 static void mxuport_lsr_event(struct usb_serial_port *port, u8 buf[4])
396 {
397 u8 lsr_event = buf[2];
398
399 if (lsr_event & UART_LSR_BI) {
400 port->icount.brk++;
401 dev_dbg(&port->dev, "%s - break error\n", __func__);
402 }
403
404 if (lsr_event & UART_LSR_FE) {
405 port->icount.frame++;
406 dev_dbg(&port->dev, "%s - frame error\n", __func__);
407 }
408
409 if (lsr_event & UART_LSR_PE) {
410 port->icount.parity++;
411 dev_dbg(&port->dev, "%s - parity error\n", __func__);
412 }
413
414 if (lsr_event & UART_LSR_OE) {
415 port->icount.overrun++;
416 dev_dbg(&port->dev, "%s - overrun error\n", __func__);
417 }
418 }
419
420 /*
421 * When something interesting happens, modem control lines XON/XOFF
422 * etc, the device sends an event. Process these events.
423 */
mxuport_process_read_urb_event(struct usb_serial_port * port,u8 buf[4],u32 event)424 static void mxuport_process_read_urb_event(struct usb_serial_port *port,
425 u8 buf[4], u32 event)
426 {
427 dev_dbg(&port->dev, "%s - receive event : %04x\n", __func__, event);
428
429 switch (event) {
430 case UPORT_EVENT_SEND_NEXT:
431 /*
432 * Sent as part of the flow control on device buffers.
433 * Not currently used.
434 */
435 break;
436 case UPORT_EVENT_MSR:
437 mxuport_msr_event(port, buf);
438 break;
439 case UPORT_EVENT_LSR:
440 mxuport_lsr_event(port, buf);
441 break;
442 case UPORT_EVENT_MCR:
443 /*
444 * Event to indicate a change in XON/XOFF from the
445 * peer. Currently not used. We just continue
446 * sending the device data and it will buffer it if
447 * needed. This event could be used for flow control
448 * between the host and the device.
449 */
450 break;
451 default:
452 dev_dbg(&port->dev, "Unexpected event\n");
453 break;
454 }
455 }
456
457 /*
458 * One URB can contain data for multiple ports. Demultiplex the data,
459 * checking the port exists, is opened and the message is valid.
460 */
mxuport_process_read_urb_demux_data(struct urb * urb)461 static void mxuport_process_read_urb_demux_data(struct urb *urb)
462 {
463 struct usb_serial_port *port = urb->context;
464 struct usb_serial *serial = port->serial;
465 u8 *data = urb->transfer_buffer;
466 u8 *end = data + urb->actual_length;
467 struct usb_serial_port *demux_port;
468 u8 *ch;
469 u16 rcv_port;
470 u16 rcv_len;
471
472 while (data < end) {
473 if (data + HEADER_SIZE > end) {
474 dev_warn(&port->dev, "%s - message with short header\n",
475 __func__);
476 return;
477 }
478
479 rcv_port = get_unaligned_be16(data);
480 if (rcv_port >= serial->num_ports) {
481 dev_warn(&port->dev, "%s - message for invalid port\n",
482 __func__);
483 return;
484 }
485
486 demux_port = serial->port[rcv_port];
487 rcv_len = get_unaligned_be16(data + 2);
488 if (!rcv_len || data + HEADER_SIZE + rcv_len > end) {
489 dev_warn(&port->dev, "%s - short data\n", __func__);
490 return;
491 }
492
493 if (tty_port_initialized(&demux_port->port)) {
494 ch = data + HEADER_SIZE;
495 mxuport_process_read_urb_data(demux_port, ch, rcv_len);
496 } else {
497 dev_dbg(&demux_port->dev, "%s - data for closed port\n",
498 __func__);
499 }
500 data += HEADER_SIZE + rcv_len;
501 }
502 }
503
504 /*
505 * One URB can contain events for multiple ports. Demultiplex the event,
506 * checking the port exists, and is opened.
507 */
mxuport_process_read_urb_demux_event(struct urb * urb)508 static void mxuport_process_read_urb_demux_event(struct urb *urb)
509 {
510 struct usb_serial_port *port = urb->context;
511 struct usb_serial *serial = port->serial;
512 u8 *data = urb->transfer_buffer;
513 u8 *end = data + urb->actual_length;
514 struct usb_serial_port *demux_port;
515 u8 *ch;
516 u16 rcv_port;
517 u16 rcv_event;
518
519 while (data < end) {
520 if (data + EVENT_LENGTH > end) {
521 dev_warn(&port->dev, "%s - message with short event\n",
522 __func__);
523 return;
524 }
525
526 rcv_port = get_unaligned_be16(data);
527 if (rcv_port >= serial->num_ports) {
528 dev_warn(&port->dev, "%s - message for invalid port\n",
529 __func__);
530 return;
531 }
532
533 demux_port = serial->port[rcv_port];
534 if (tty_port_initialized(&demux_port->port)) {
535 ch = data + HEADER_SIZE;
536 rcv_event = get_unaligned_be16(data + 2);
537 mxuport_process_read_urb_event(demux_port, ch,
538 rcv_event);
539 } else {
540 dev_dbg(&demux_port->dev,
541 "%s - event for closed port\n", __func__);
542 }
543 data += EVENT_LENGTH;
544 }
545 }
546
547 /*
548 * This is called when we have received data on the bulk in
549 * endpoint. Depending on which port it was received on, it can
550 * contain serial data or events.
551 */
mxuport_process_read_urb(struct urb * urb)552 static void mxuport_process_read_urb(struct urb *urb)
553 {
554 struct usb_serial_port *port = urb->context;
555 struct usb_serial *serial = port->serial;
556
557 if (port == serial->port[0])
558 mxuport_process_read_urb_demux_data(urb);
559
560 if (port == serial->port[1])
561 mxuport_process_read_urb_demux_event(urb);
562 }
563
564 /*
565 * Ask the device how many bytes it has queued to be sent out. If
566 * there are none, return true.
567 */
mxuport_tx_empty(struct usb_serial_port * port)568 static bool mxuport_tx_empty(struct usb_serial_port *port)
569 {
570 struct usb_serial *serial = port->serial;
571 bool is_empty = true;
572 u32 txlen;
573 u8 *len_buf;
574 int err;
575
576 len_buf = kzalloc(4, GFP_KERNEL);
577 if (!len_buf)
578 goto out;
579
580 err = mxuport_recv_ctrl_urb(serial, RQ_VENDOR_GET_OUTQUEUE, 0,
581 port->port_number, len_buf, 4);
582 if (err < 0)
583 goto out;
584
585 txlen = get_unaligned_be32(len_buf);
586 dev_dbg(&port->dev, "%s - tx len = %u\n", __func__, txlen);
587
588 if (txlen != 0)
589 is_empty = false;
590
591 out:
592 kfree(len_buf);
593 return is_empty;
594 }
595
mxuport_set_mcr(struct usb_serial_port * port,u8 mcr_state)596 static int mxuport_set_mcr(struct usb_serial_port *port, u8 mcr_state)
597 {
598 struct usb_serial *serial = port->serial;
599 int err;
600
601 dev_dbg(&port->dev, "%s - %02x\n", __func__, mcr_state);
602
603 err = mxuport_send_ctrl_urb(serial, RQ_VENDOR_SET_MCR,
604 mcr_state, port->port_number);
605 if (err)
606 dev_err(&port->dev, "%s - failed to change MCR\n", __func__);
607
608 return err;
609 }
610
mxuport_set_dtr(struct usb_serial_port * port,int on)611 static int mxuport_set_dtr(struct usb_serial_port *port, int on)
612 {
613 struct mxuport_port *mxport = usb_get_serial_port_data(port);
614 struct usb_serial *serial = port->serial;
615 int err;
616
617 mutex_lock(&mxport->mutex);
618
619 err = mxuport_send_ctrl_urb(serial, RQ_VENDOR_SET_DTR,
620 !!on, port->port_number);
621 if (!err) {
622 if (on)
623 mxport->mcr_state |= UART_MCR_DTR;
624 else
625 mxport->mcr_state &= ~UART_MCR_DTR;
626 }
627
628 mutex_unlock(&mxport->mutex);
629
630 return err;
631 }
632
mxuport_set_rts(struct usb_serial_port * port,u8 state)633 static int mxuport_set_rts(struct usb_serial_port *port, u8 state)
634 {
635 struct mxuport_port *mxport = usb_get_serial_port_data(port);
636 struct usb_serial *serial = port->serial;
637 int err;
638 u8 mcr_state;
639
640 mutex_lock(&mxport->mutex);
641 mcr_state = mxport->mcr_state;
642
643 switch (state) {
644 case MX_RTS_DISABLE:
645 mcr_state &= ~UART_MCR_RTS;
646 break;
647 case MX_RTS_ENABLE:
648 mcr_state |= UART_MCR_RTS;
649 break;
650 case MX_RTS_HW:
651 /*
652 * Do not update mxport->mcr_state when doing hardware
653 * flow control.
654 */
655 break;
656 default:
657 /*
658 * Should not happen, but somebody might try passing
659 * MX_RTS_NO_CHANGE, which is not valid.
660 */
661 err = -EINVAL;
662 goto out;
663 }
664 err = mxuport_send_ctrl_urb(serial, RQ_VENDOR_SET_RTS,
665 state, port->port_number);
666 if (!err)
667 mxport->mcr_state = mcr_state;
668
669 out:
670 mutex_unlock(&mxport->mutex);
671
672 return err;
673 }
674
mxuport_dtr_rts(struct usb_serial_port * port,int on)675 static void mxuport_dtr_rts(struct usb_serial_port *port, int on)
676 {
677 struct mxuport_port *mxport = usb_get_serial_port_data(port);
678 u8 mcr_state;
679 int err;
680
681 mutex_lock(&mxport->mutex);
682 mcr_state = mxport->mcr_state;
683
684 if (on)
685 mcr_state |= (UART_MCR_RTS | UART_MCR_DTR);
686 else
687 mcr_state &= ~(UART_MCR_RTS | UART_MCR_DTR);
688
689 err = mxuport_set_mcr(port, mcr_state);
690 if (!err)
691 mxport->mcr_state = mcr_state;
692
693 mutex_unlock(&mxport->mutex);
694 }
695
mxuport_tiocmset(struct tty_struct * tty,unsigned int set,unsigned int clear)696 static int mxuport_tiocmset(struct tty_struct *tty, unsigned int set,
697 unsigned int clear)
698 {
699 struct usb_serial_port *port = tty->driver_data;
700 struct mxuport_port *mxport = usb_get_serial_port_data(port);
701 int err;
702 u8 mcr_state;
703
704 mutex_lock(&mxport->mutex);
705 mcr_state = mxport->mcr_state;
706
707 if (set & TIOCM_RTS)
708 mcr_state |= UART_MCR_RTS;
709
710 if (set & TIOCM_DTR)
711 mcr_state |= UART_MCR_DTR;
712
713 if (clear & TIOCM_RTS)
714 mcr_state &= ~UART_MCR_RTS;
715
716 if (clear & TIOCM_DTR)
717 mcr_state &= ~UART_MCR_DTR;
718
719 err = mxuport_set_mcr(port, mcr_state);
720 if (!err)
721 mxport->mcr_state = mcr_state;
722
723 mutex_unlock(&mxport->mutex);
724
725 return err;
726 }
727
mxuport_tiocmget(struct tty_struct * tty)728 static int mxuport_tiocmget(struct tty_struct *tty)
729 {
730 struct mxuport_port *mxport;
731 struct usb_serial_port *port = tty->driver_data;
732 unsigned int result;
733 unsigned long flags;
734 unsigned int msr;
735 unsigned int mcr;
736
737 mxport = usb_get_serial_port_data(port);
738
739 mutex_lock(&mxport->mutex);
740 spin_lock_irqsave(&mxport->spinlock, flags);
741
742 msr = mxport->msr_state;
743 mcr = mxport->mcr_state;
744
745 spin_unlock_irqrestore(&mxport->spinlock, flags);
746 mutex_unlock(&mxport->mutex);
747
748 result = (((mcr & UART_MCR_DTR) ? TIOCM_DTR : 0) | /* 0x002 */
749 ((mcr & UART_MCR_RTS) ? TIOCM_RTS : 0) | /* 0x004 */
750 ((msr & UART_MSR_CTS) ? TIOCM_CTS : 0) | /* 0x020 */
751 ((msr & UART_MSR_DCD) ? TIOCM_CAR : 0) | /* 0x040 */
752 ((msr & UART_MSR_RI) ? TIOCM_RI : 0) | /* 0x080 */
753 ((msr & UART_MSR_DSR) ? TIOCM_DSR : 0)); /* 0x100 */
754
755 dev_dbg(&port->dev, "%s - 0x%04x\n", __func__, result);
756
757 return result;
758 }
759
mxuport_set_termios_flow(struct tty_struct * tty,const struct ktermios * old_termios,struct usb_serial_port * port,struct usb_serial * serial)760 static int mxuport_set_termios_flow(struct tty_struct *tty,
761 const struct ktermios *old_termios,
762 struct usb_serial_port *port,
763 struct usb_serial *serial)
764 {
765 u8 xon = START_CHAR(tty);
766 u8 xoff = STOP_CHAR(tty);
767 int enable;
768 int err;
769 u8 *buf;
770 u8 rts;
771
772 buf = kmalloc(2, GFP_KERNEL);
773 if (!buf)
774 return -ENOMEM;
775
776 /* S/W flow control settings */
777 if (I_IXOFF(tty) || I_IXON(tty)) {
778 enable = 1;
779 buf[0] = xon;
780 buf[1] = xoff;
781
782 err = mxuport_send_ctrl_data_urb(serial, RQ_VENDOR_SET_CHARS,
783 0, port->port_number,
784 buf, 2);
785 if (err)
786 goto out;
787
788 dev_dbg(&port->dev, "%s - XON = 0x%02x, XOFF = 0x%02x\n",
789 __func__, xon, xoff);
790 } else {
791 enable = 0;
792 }
793
794 err = mxuport_send_ctrl_urb(serial, RQ_VENDOR_SET_XONXOFF,
795 enable, port->port_number);
796 if (err)
797 goto out;
798
799 rts = MX_RTS_NO_CHANGE;
800
801 /* H/W flow control settings */
802 if (!old_termios ||
803 C_CRTSCTS(tty) != (old_termios->c_cflag & CRTSCTS)) {
804 if (C_CRTSCTS(tty))
805 rts = MX_RTS_HW;
806 else
807 rts = MX_RTS_ENABLE;
808 }
809
810 if (C_BAUD(tty)) {
811 if (old_termios && (old_termios->c_cflag & CBAUD) == B0) {
812 /* Raise DTR and RTS */
813 if (C_CRTSCTS(tty))
814 rts = MX_RTS_HW;
815 else
816 rts = MX_RTS_ENABLE;
817 mxuport_set_dtr(port, 1);
818 }
819 } else {
820 /* Drop DTR and RTS */
821 rts = MX_RTS_DISABLE;
822 mxuport_set_dtr(port, 0);
823 }
824
825 if (rts != MX_RTS_NO_CHANGE)
826 err = mxuport_set_rts(port, rts);
827
828 out:
829 kfree(buf);
830 return err;
831 }
832
mxuport_set_termios(struct tty_struct * tty,struct usb_serial_port * port,const struct ktermios * old_termios)833 static void mxuport_set_termios(struct tty_struct *tty,
834 struct usb_serial_port *port,
835 const struct ktermios *old_termios)
836 {
837 struct usb_serial *serial = port->serial;
838 u8 *buf;
839 u8 data_bits;
840 u8 stop_bits;
841 u8 parity;
842 int baud;
843 int err;
844
845 if (old_termios &&
846 !tty_termios_hw_change(&tty->termios, old_termios) &&
847 tty->termios.c_iflag == old_termios->c_iflag) {
848 dev_dbg(&port->dev, "%s - nothing to change\n", __func__);
849 return;
850 }
851
852 buf = kmalloc(4, GFP_KERNEL);
853 if (!buf)
854 return;
855
856 /* Set data bit of termios */
857 switch (C_CSIZE(tty)) {
858 case CS5:
859 data_bits = MX_WORDLENGTH_5;
860 break;
861 case CS6:
862 data_bits = MX_WORDLENGTH_6;
863 break;
864 case CS7:
865 data_bits = MX_WORDLENGTH_7;
866 break;
867 case CS8:
868 default:
869 data_bits = MX_WORDLENGTH_8;
870 break;
871 }
872
873 /* Set parity of termios */
874 if (C_PARENB(tty)) {
875 if (C_CMSPAR(tty)) {
876 if (C_PARODD(tty))
877 parity = MX_PARITY_MARK;
878 else
879 parity = MX_PARITY_SPACE;
880 } else {
881 if (C_PARODD(tty))
882 parity = MX_PARITY_ODD;
883 else
884 parity = MX_PARITY_EVEN;
885 }
886 } else {
887 parity = MX_PARITY_NONE;
888 }
889
890 /* Set stop bit of termios */
891 if (C_CSTOPB(tty))
892 stop_bits = MX_STOP_BITS_2;
893 else
894 stop_bits = MX_STOP_BITS_1;
895
896 buf[0] = data_bits;
897 buf[1] = parity;
898 buf[2] = stop_bits;
899 buf[3] = 0;
900
901 err = mxuport_send_ctrl_data_urb(serial, RQ_VENDOR_SET_LINE,
902 0, port->port_number, buf, 4);
903 if (err)
904 goto out;
905
906 err = mxuport_set_termios_flow(tty, old_termios, port, serial);
907 if (err)
908 goto out;
909
910 baud = tty_get_baud_rate(tty);
911 if (!baud)
912 baud = 9600;
913
914 /* Note: Little Endian */
915 put_unaligned_le32(baud, buf);
916
917 err = mxuport_send_ctrl_data_urb(serial, RQ_VENDOR_SET_BAUD,
918 0, port->port_number,
919 buf, 4);
920 if (err)
921 goto out;
922
923 dev_dbg(&port->dev, "baud_rate : %d\n", baud);
924 dev_dbg(&port->dev, "data_bits : %d\n", data_bits);
925 dev_dbg(&port->dev, "parity : %d\n", parity);
926 dev_dbg(&port->dev, "stop_bits : %d\n", stop_bits);
927
928 out:
929 kfree(buf);
930 }
931
932 /*
933 * Determine how many ports this device has dynamically. It will be
934 * called after the probe() callback is called, but before attach().
935 */
mxuport_calc_num_ports(struct usb_serial * serial,struct usb_serial_endpoints * epds)936 static int mxuport_calc_num_ports(struct usb_serial *serial,
937 struct usb_serial_endpoints *epds)
938 {
939 unsigned long features = (unsigned long)usb_get_serial_data(serial);
940 int num_ports;
941 int i;
942
943 if (features & MX_PORTS_MASK) {
944 num_ports = (features & MX_PORTS_MASK) + MX_PORTS_OFFSET;
945 } else {
946 dev_warn(&serial->interface->dev,
947 "unknown device, assuming two ports\n");
948 num_ports = 2;
949 }
950
951 /*
952 * Setup bulk-out endpoint multiplexing. All ports share the same
953 * bulk-out endpoint.
954 */
955 BUILD_BUG_ON(ARRAY_SIZE(epds->bulk_out) < 16);
956
957 /*
958 * The bulk-out buffers must be large enough for the four-byte header
959 * (and following data), but assume anything smaller than eight bytes
960 * is broken.
961 */
962 if (usb_endpoint_maxp(epds->bulk_out[0]) < 8)
963 return -EINVAL;
964
965 for (i = 1; i < num_ports; ++i)
966 epds->bulk_out[i] = epds->bulk_out[0];
967
968 epds->num_bulk_out = num_ports;
969
970 return num_ports;
971 }
972
973 /* Get the version of the firmware currently running. */
mxuport_get_fw_version(struct usb_serial * serial,u32 * version)974 static int mxuport_get_fw_version(struct usb_serial *serial, u32 *version)
975 {
976 u8 *ver_buf;
977 int err;
978
979 ver_buf = kzalloc(4, GFP_KERNEL);
980 if (!ver_buf)
981 return -ENOMEM;
982
983 /* Get firmware version from SDRAM */
984 err = mxuport_recv_ctrl_urb(serial, RQ_VENDOR_GET_VERSION, 0, 0,
985 ver_buf, 4);
986 if (err != 4) {
987 err = -EIO;
988 goto out;
989 }
990
991 *version = (ver_buf[0] << 16) | (ver_buf[1] << 8) | ver_buf[2];
992 err = 0;
993 out:
994 kfree(ver_buf);
995 return err;
996 }
997
998 /* Given a firmware blob, download it to the device. */
mxuport_download_fw(struct usb_serial * serial,const struct firmware * fw_p)999 static int mxuport_download_fw(struct usb_serial *serial,
1000 const struct firmware *fw_p)
1001 {
1002 u8 *fw_buf;
1003 size_t txlen;
1004 size_t fwidx;
1005 int err;
1006
1007 fw_buf = kmalloc(DOWN_BLOCK_SIZE, GFP_KERNEL);
1008 if (!fw_buf)
1009 return -ENOMEM;
1010
1011 dev_dbg(&serial->interface->dev, "Starting firmware download...\n");
1012 err = mxuport_send_ctrl_urb(serial, RQ_VENDOR_START_FW_DOWN, 0, 0);
1013 if (err)
1014 goto out;
1015
1016 fwidx = 0;
1017 do {
1018 txlen = min_t(size_t, (fw_p->size - fwidx), DOWN_BLOCK_SIZE);
1019
1020 memcpy(fw_buf, &fw_p->data[fwidx], txlen);
1021 err = mxuport_send_ctrl_data_urb(serial, RQ_VENDOR_FW_DATA,
1022 0, 0, fw_buf, txlen);
1023 if (err) {
1024 mxuport_send_ctrl_urb(serial, RQ_VENDOR_STOP_FW_DOWN,
1025 0, 0);
1026 goto out;
1027 }
1028
1029 fwidx += txlen;
1030 usleep_range(1000, 2000);
1031
1032 } while (fwidx < fw_p->size);
1033
1034 msleep(1000);
1035 err = mxuport_send_ctrl_urb(serial, RQ_VENDOR_STOP_FW_DOWN, 0, 0);
1036 if (err)
1037 goto out;
1038
1039 msleep(1000);
1040 err = mxuport_send_ctrl_urb(serial, RQ_VENDOR_QUERY_FW_READY, 0, 0);
1041
1042 out:
1043 kfree(fw_buf);
1044 return err;
1045 }
1046
mxuport_probe(struct usb_serial * serial,const struct usb_device_id * id)1047 static int mxuport_probe(struct usb_serial *serial,
1048 const struct usb_device_id *id)
1049 {
1050 u16 productid = le16_to_cpu(serial->dev->descriptor.idProduct);
1051 const struct firmware *fw_p = NULL;
1052 u32 version;
1053 int local_ver;
1054 char buf[32];
1055 int err;
1056
1057 /* Load our firmware */
1058 err = mxuport_send_ctrl_urb(serial, RQ_VENDOR_QUERY_FW_CONFIG, 0, 0);
1059 if (err) {
1060 mxuport_send_ctrl_urb(serial, RQ_VENDOR_RESET_DEVICE, 0, 0);
1061 return err;
1062 }
1063
1064 err = mxuport_get_fw_version(serial, &version);
1065 if (err < 0)
1066 return err;
1067
1068 dev_dbg(&serial->interface->dev, "Device firmware version v%x.%x.%x\n",
1069 (version & 0xff0000) >> 16,
1070 (version & 0xff00) >> 8,
1071 (version & 0xff));
1072
1073 snprintf(buf, sizeof(buf) - 1, "moxa/moxa-%04x.fw", productid);
1074
1075 err = request_firmware(&fw_p, buf, &serial->interface->dev);
1076 if (err) {
1077 dev_warn(&serial->interface->dev, "Firmware %s not found\n",
1078 buf);
1079
1080 /* Use the firmware already in the device */
1081 err = 0;
1082 } else {
1083 if (fw_p->size <= VER_ADDR_3) {
1084 dev_err(&serial->interface->dev,
1085 "Firmware %s is too short\n", buf);
1086 err = -EINVAL;
1087 goto out;
1088 }
1089
1090 local_ver = ((fw_p->data[VER_ADDR_1] << 16) |
1091 (fw_p->data[VER_ADDR_2] << 8) |
1092 fw_p->data[VER_ADDR_3]);
1093 dev_dbg(&serial->interface->dev,
1094 "Available firmware version v%x.%x.%x\n",
1095 fw_p->data[VER_ADDR_1], fw_p->data[VER_ADDR_2],
1096 fw_p->data[VER_ADDR_3]);
1097 if (local_ver > version) {
1098 err = mxuport_download_fw(serial, fw_p);
1099 if (err)
1100 goto out;
1101 err = mxuport_get_fw_version(serial, &version);
1102 if (err < 0)
1103 goto out;
1104 }
1105 }
1106
1107 dev_info(&serial->interface->dev,
1108 "Using device firmware version v%x.%x.%x\n",
1109 (version & 0xff0000) >> 16,
1110 (version & 0xff00) >> 8,
1111 (version & 0xff));
1112
1113 /*
1114 * Contains the features of this hardware. Store away for
1115 * later use, eg, number of ports.
1116 */
1117 usb_set_serial_data(serial, (void *)id->driver_info);
1118 out:
1119 if (fw_p)
1120 release_firmware(fw_p);
1121 return err;
1122 }
1123
1124
mxuport_port_probe(struct usb_serial_port * port)1125 static int mxuport_port_probe(struct usb_serial_port *port)
1126 {
1127 struct usb_serial *serial = port->serial;
1128 struct mxuport_port *mxport;
1129 int err;
1130
1131 mxport = devm_kzalloc(&port->dev, sizeof(struct mxuport_port),
1132 GFP_KERNEL);
1133 if (!mxport)
1134 return -ENOMEM;
1135
1136 mutex_init(&mxport->mutex);
1137 spin_lock_init(&mxport->spinlock);
1138
1139 /* Set the port private data */
1140 usb_set_serial_port_data(port, mxport);
1141
1142 /* Set FIFO (Enable) */
1143 err = mxuport_send_ctrl_urb(serial, RQ_VENDOR_SET_FIFO_DISABLE,
1144 0, port->port_number);
1145 if (err)
1146 return err;
1147
1148 /* Set transmission mode (Hi-Performance) */
1149 err = mxuport_send_ctrl_urb(serial, RQ_VENDOR_SET_HIGH_PERFOR,
1150 0, port->port_number);
1151 if (err)
1152 return err;
1153
1154 /* Set interface (RS-232) */
1155 return mxuport_send_ctrl_urb(serial, RQ_VENDOR_SET_INTERFACE,
1156 MX_INT_RS232,
1157 port->port_number);
1158 }
1159
mxuport_attach(struct usb_serial * serial)1160 static int mxuport_attach(struct usb_serial *serial)
1161 {
1162 struct usb_serial_port *port0 = serial->port[0];
1163 struct usb_serial_port *port1 = serial->port[1];
1164 int err;
1165
1166 /*
1167 * All data from the ports is received on the first bulk in
1168 * endpoint, with a multiplex header. The second bulk in is
1169 * used for events.
1170 *
1171 * Start to read from the device.
1172 */
1173 err = usb_serial_generic_submit_read_urbs(port0, GFP_KERNEL);
1174 if (err)
1175 return err;
1176
1177 err = usb_serial_generic_submit_read_urbs(port1, GFP_KERNEL);
1178 if (err) {
1179 usb_serial_generic_close(port0);
1180 return err;
1181 }
1182
1183 return 0;
1184 }
1185
mxuport_release(struct usb_serial * serial)1186 static void mxuport_release(struct usb_serial *serial)
1187 {
1188 struct usb_serial_port *port0 = serial->port[0];
1189 struct usb_serial_port *port1 = serial->port[1];
1190
1191 usb_serial_generic_close(port1);
1192 usb_serial_generic_close(port0);
1193 }
1194
mxuport_open(struct tty_struct * tty,struct usb_serial_port * port)1195 static int mxuport_open(struct tty_struct *tty, struct usb_serial_port *port)
1196 {
1197 struct mxuport_port *mxport = usb_get_serial_port_data(port);
1198 struct usb_serial *serial = port->serial;
1199 int err;
1200
1201 /* Set receive host (enable) */
1202 err = mxuport_send_ctrl_urb(serial, RQ_VENDOR_SET_RX_HOST_EN,
1203 1, port->port_number);
1204 if (err)
1205 return err;
1206
1207 err = mxuport_send_ctrl_urb(serial, RQ_VENDOR_SET_OPEN,
1208 1, port->port_number);
1209 if (err) {
1210 mxuport_send_ctrl_urb(serial, RQ_VENDOR_SET_RX_HOST_EN,
1211 0, port->port_number);
1212 return err;
1213 }
1214
1215 /* Initial port termios */
1216 if (tty)
1217 mxuport_set_termios(tty, port, NULL);
1218
1219 /*
1220 * TODO: use RQ_VENDOR_GET_MSR, once we know what it
1221 * returns.
1222 */
1223 mxport->msr_state = 0;
1224
1225 return err;
1226 }
1227
mxuport_close(struct usb_serial_port * port)1228 static void mxuport_close(struct usb_serial_port *port)
1229 {
1230 struct usb_serial *serial = port->serial;
1231
1232 mxuport_send_ctrl_urb(serial, RQ_VENDOR_SET_OPEN, 0,
1233 port->port_number);
1234
1235 mxuport_send_ctrl_urb(serial, RQ_VENDOR_SET_RX_HOST_EN, 0,
1236 port->port_number);
1237 }
1238
1239 /* Send a break to the port. */
mxuport_break_ctl(struct tty_struct * tty,int break_state)1240 static int mxuport_break_ctl(struct tty_struct *tty, int break_state)
1241 {
1242 struct usb_serial_port *port = tty->driver_data;
1243 struct usb_serial *serial = port->serial;
1244 int enable;
1245
1246 if (break_state == -1) {
1247 enable = 1;
1248 dev_dbg(&port->dev, "%s - sending break\n", __func__);
1249 } else {
1250 enable = 0;
1251 dev_dbg(&port->dev, "%s - clearing break\n", __func__);
1252 }
1253
1254 return mxuport_send_ctrl_urb(serial, RQ_VENDOR_SET_BREAK,
1255 enable, port->port_number);
1256 }
1257
mxuport_resume(struct usb_serial * serial)1258 static int mxuport_resume(struct usb_serial *serial)
1259 {
1260 struct usb_serial_port *port;
1261 int c = 0;
1262 int i;
1263 int r;
1264
1265 for (i = 0; i < 2; i++) {
1266 port = serial->port[i];
1267
1268 r = usb_serial_generic_submit_read_urbs(port, GFP_NOIO);
1269 if (r < 0)
1270 c++;
1271 }
1272
1273 for (i = 0; i < serial->num_ports; i++) {
1274 port = serial->port[i];
1275 if (!tty_port_initialized(&port->port))
1276 continue;
1277
1278 r = usb_serial_generic_write_start(port, GFP_NOIO);
1279 if (r < 0)
1280 c++;
1281 }
1282
1283 return c ? -EIO : 0;
1284 }
1285
1286 static struct usb_serial_driver mxuport_device = {
1287 .driver = {
1288 .name = "mxuport",
1289 },
1290 .description = "MOXA UPort",
1291 .id_table = mxuport_idtable,
1292 .num_bulk_in = 2,
1293 .num_bulk_out = 1,
1294 .probe = mxuport_probe,
1295 .port_probe = mxuport_port_probe,
1296 .attach = mxuport_attach,
1297 .release = mxuport_release,
1298 .calc_num_ports = mxuport_calc_num_ports,
1299 .open = mxuport_open,
1300 .close = mxuport_close,
1301 .set_termios = mxuport_set_termios,
1302 .break_ctl = mxuport_break_ctl,
1303 .tx_empty = mxuport_tx_empty,
1304 .tiocmiwait = usb_serial_generic_tiocmiwait,
1305 .get_icount = usb_serial_generic_get_icount,
1306 .throttle = mxuport_throttle,
1307 .unthrottle = mxuport_unthrottle,
1308 .tiocmget = mxuport_tiocmget,
1309 .tiocmset = mxuport_tiocmset,
1310 .dtr_rts = mxuport_dtr_rts,
1311 .process_read_urb = mxuport_process_read_urb,
1312 .prepare_write_buffer = mxuport_prepare_write_buffer,
1313 .resume = mxuport_resume,
1314 };
1315
1316 static struct usb_serial_driver *const serial_drivers[] = {
1317 &mxuport_device, NULL
1318 };
1319
1320 module_usb_serial_driver(serial_drivers, mxuport_idtable);
1321
1322 MODULE_AUTHOR("Andrew Lunn <andrew@lunn.ch>");
1323 MODULE_AUTHOR("<support@moxa.com>");
1324 MODULE_DESCRIPTION("Moxa UPORT USB Serial driver");
1325 MODULE_LICENSE("GPL");
1326