]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/usb/serial/f81534.c
USB: serial: f81534: clean up calc_num_ports
[karo-tx-linux.git] / drivers / usb / serial / f81534.c
1 /*
2  * F81532/F81534 USB to Serial Ports Bridge
3  *
4  * F81532 => 2 Serial Ports
5  * F81534 => 4 Serial Ports
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * Copyright (C) 2016 Feature Integration Technology Inc., (Fintek)
13  * Copyright (C) 2016 Tom Tsai (Tom_Tsai@fintek.com.tw)
14  * Copyright (C) 2016 Peter Hong (Peter_Hong@fintek.com.tw)
15  *
16  * The F81532/F81534 had 1 control endpoint for setting, 1 endpoint bulk-out
17  * for all serial port TX and 1 endpoint bulk-in for all serial port read in
18  * (Read Data/MSR/LSR).
19  *
20  * Write URB is fixed with 512bytes, per serial port used 128Bytes.
21  * It can be described by f81534_prepare_write_buffer()
22  *
23  * Read URB is 512Bytes max, per serial port used 128Bytes.
24  * It can be described by f81534_process_read_urb() and maybe received with
25  * 128x1,2,3,4 bytes.
26  *
27  */
28 #include <linux/slab.h>
29 #include <linux/tty.h>
30 #include <linux/tty_flip.h>
31 #include <linux/usb.h>
32 #include <linux/usb/serial.h>
33 #include <linux/serial_reg.h>
34 #include <linux/module.h>
35 #include <linux/uaccess.h>
36
37 /* Serial Port register Address */
38 #define F81534_UART_BASE_ADDRESS        0x1200
39 #define F81534_UART_OFFSET              0x10
40 #define F81534_DIVISOR_LSB_REG          (0x00 + F81534_UART_BASE_ADDRESS)
41 #define F81534_DIVISOR_MSB_REG          (0x01 + F81534_UART_BASE_ADDRESS)
42 #define F81534_FIFO_CONTROL_REG         (0x02 + F81534_UART_BASE_ADDRESS)
43 #define F81534_LINE_CONTROL_REG         (0x03 + F81534_UART_BASE_ADDRESS)
44 #define F81534_MODEM_CONTROL_REG        (0x04 + F81534_UART_BASE_ADDRESS)
45 #define F81534_MODEM_STATUS_REG         (0x06 + F81534_UART_BASE_ADDRESS)
46 #define F81534_CONFIG1_REG              (0x09 + F81534_UART_BASE_ADDRESS)
47
48 #define F81534_DEF_CONF_ADDRESS_START   0x3000
49 #define F81534_DEF_CONF_SIZE            8
50
51 #define F81534_CUSTOM_ADDRESS_START     0x2f00
52 #define F81534_CUSTOM_DATA_SIZE         0x10
53 #define F81534_CUSTOM_NO_CUSTOM_DATA    0xff
54 #define F81534_CUSTOM_VALID_TOKEN       0xf0
55 #define F81534_CONF_OFFSET              1
56
57 #define F81534_MAX_DATA_BLOCK           64
58 #define F81534_MAX_BUS_RETRY            20
59
60 /* Default URB timeout for USB operations */
61 #define F81534_USB_MAX_RETRY            10
62 #define F81534_USB_TIMEOUT              1000
63 #define F81534_SET_GET_REGISTER         0xA0
64
65 #define F81534_NUM_PORT                 4
66 #define F81534_UNUSED_PORT              0xff
67 #define F81534_WRITE_BUFFER_SIZE        512
68
69 #define DRIVER_DESC                     "Fintek F81532/F81534"
70 #define FINTEK_VENDOR_ID_1              0x1934
71 #define FINTEK_VENDOR_ID_2              0x2C42
72 #define FINTEK_DEVICE_ID                0x1202
73 #define F81534_MAX_TX_SIZE              124
74 #define F81534_MAX_RX_SIZE              124
75 #define F81534_RECEIVE_BLOCK_SIZE       128
76 #define F81534_MAX_RECEIVE_BLOCK_SIZE   512
77
78 #define F81534_TOKEN_RECEIVE            0x01
79 #define F81534_TOKEN_WRITE              0x02
80 #define F81534_TOKEN_TX_EMPTY           0x03
81 #define F81534_TOKEN_MSR_CHANGE         0x04
82
83 /*
84  * We used interal SPI bus to access FLASH section. We must wait the SPI bus to
85  * idle if we performed any command.
86  *
87  * SPI Bus status register: F81534_BUS_REG_STATUS
88  *      Bit 0/1 : BUSY
89  *      Bit 2   : IDLE
90  */
91 #define F81534_BUS_BUSY                 (BIT(0) | BIT(1))
92 #define F81534_BUS_IDLE                 BIT(2)
93 #define F81534_BUS_READ_DATA            0x1004
94 #define F81534_BUS_REG_STATUS           0x1003
95 #define F81534_BUS_REG_START            0x1002
96 #define F81534_BUS_REG_END              0x1001
97
98 #define F81534_CMD_READ                 0x03
99
100 #define F81534_DEFAULT_BAUD_RATE        9600
101 #define F81534_MAX_BAUDRATE             115200
102
103 #define F81534_PORT_CONF_DISABLE_PORT   BIT(3)
104 #define F81534_PORT_CONF_NOT_EXIST_PORT BIT(7)
105 #define F81534_PORT_UNAVAILABLE         \
106         (F81534_PORT_CONF_DISABLE_PORT | F81534_PORT_CONF_NOT_EXIST_PORT)
107
108 #define F81534_1X_RXTRIGGER             0xc3
109 #define F81534_8X_RXTRIGGER             0xcf
110
111 static const struct usb_device_id f81534_id_table[] = {
112         { USB_DEVICE(FINTEK_VENDOR_ID_1, FINTEK_DEVICE_ID) },
113         { USB_DEVICE(FINTEK_VENDOR_ID_2, FINTEK_DEVICE_ID) },
114         {}                      /* Terminating entry */
115 };
116
117 #define F81534_TX_EMPTY_BIT             0
118
119 struct f81534_serial_private {
120         u8 conf_data[F81534_DEF_CONF_SIZE];
121         int tty_idx[F81534_NUM_PORT];
122         u8 setting_idx;
123         int opened_port;
124         struct mutex urb_mutex;
125 };
126
127 struct f81534_port_private {
128         struct mutex mcr_mutex;
129         unsigned long tx_empty;
130         spinlock_t msr_lock;
131         u8 shadow_mcr;
132         u8 shadow_msr;
133         u8 phy_num;
134 };
135
136 static int f81534_logic_to_phy_port(struct usb_serial *serial,
137                                         struct usb_serial_port *port)
138 {
139         struct f81534_serial_private *serial_priv =
140                         usb_get_serial_data(port->serial);
141         int count = 0;
142         int i;
143
144         for (i = 0; i < F81534_NUM_PORT; ++i) {
145                 if (serial_priv->conf_data[i] & F81534_PORT_UNAVAILABLE)
146                         continue;
147
148                 if (port->port_number == count)
149                         return i;
150
151                 ++count;
152         }
153
154         return -ENODEV;
155 }
156
157 static int f81534_set_register(struct usb_serial *serial, u16 reg, u8 data)
158 {
159         struct usb_interface *interface = serial->interface;
160         struct usb_device *dev = serial->dev;
161         size_t count = F81534_USB_MAX_RETRY;
162         int status;
163         u8 *tmp;
164
165         tmp = kmalloc(sizeof(u8), GFP_KERNEL);
166         if (!tmp)
167                 return -ENOMEM;
168
169         *tmp = data;
170
171         /*
172          * Our device maybe not reply when heavily loading, We'll retry for
173          * F81534_USB_MAX_RETRY times.
174          */
175         while (count--) {
176                 status = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
177                                          F81534_SET_GET_REGISTER,
178                                          USB_TYPE_VENDOR | USB_DIR_OUT,
179                                          reg, 0, tmp, sizeof(u8),
180                                          F81534_USB_TIMEOUT);
181                 if (status > 0) {
182                         status = 0;
183                         break;
184                 } else if (status == 0) {
185                         status = -EIO;
186                 }
187         }
188
189         if (status < 0) {
190                 dev_err(&interface->dev, "%s: reg: %x data: %x failed: %d\n",
191                                 __func__, reg, data, status);
192         }
193
194         kfree(tmp);
195         return status;
196 }
197
198 static int f81534_get_register(struct usb_serial *serial, u16 reg, u8 *data)
199 {
200         struct usb_interface *interface = serial->interface;
201         struct usb_device *dev = serial->dev;
202         size_t count = F81534_USB_MAX_RETRY;
203         int status;
204         u8 *tmp;
205
206         tmp = kmalloc(sizeof(u8), GFP_KERNEL);
207         if (!tmp)
208                 return -ENOMEM;
209
210         /*
211          * Our device maybe not reply when heavily loading, We'll retry for
212          * F81534_USB_MAX_RETRY times.
213          */
214         while (count--) {
215                 status = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
216                                          F81534_SET_GET_REGISTER,
217                                          USB_TYPE_VENDOR | USB_DIR_IN,
218                                          reg, 0, tmp, sizeof(u8),
219                                          F81534_USB_TIMEOUT);
220                 if (status > 0) {
221                         status = 0;
222                         break;
223                 } else if (status == 0) {
224                         status = -EIO;
225                 }
226         }
227
228         if (status < 0) {
229                 dev_err(&interface->dev, "%s: reg: %x failed: %d\n", __func__,
230                                 reg, status);
231                 goto end;
232         }
233
234         *data = *tmp;
235
236 end:
237         kfree(tmp);
238         return status;
239 }
240
241 static int f81534_set_port_register(struct usb_serial_port *port, u16 reg,
242                                         u8 data)
243 {
244         struct f81534_port_private *port_priv = usb_get_serial_port_data(port);
245
246         return f81534_set_register(port->serial,
247                         reg + port_priv->phy_num * F81534_UART_OFFSET, data);
248 }
249
250 static int f81534_get_port_register(struct usb_serial_port *port, u16 reg,
251                                         u8 *data)
252 {
253         struct f81534_port_private *port_priv = usb_get_serial_port_data(port);
254
255         return f81534_get_register(port->serial,
256                         reg + port_priv->phy_num * F81534_UART_OFFSET, data);
257 }
258
259 /*
260  * If we try to access the internal flash via SPI bus, we should check the bus
261  * status for every command. e.g., F81534_BUS_REG_START/F81534_BUS_REG_END
262  */
263 static int f81534_wait_for_spi_idle(struct usb_serial *serial)
264 {
265         size_t count = F81534_MAX_BUS_RETRY;
266         u8 tmp;
267         int status;
268
269         do {
270                 status = f81534_get_register(serial, F81534_BUS_REG_STATUS,
271                                                 &tmp);
272                 if (status)
273                         return status;
274
275                 if (tmp & F81534_BUS_BUSY)
276                         continue;
277
278                 if (tmp & F81534_BUS_IDLE)
279                         break;
280
281         } while (--count);
282
283         if (!count) {
284                 dev_err(&serial->interface->dev,
285                                 "%s: timed out waiting for idle SPI bus\n",
286                                 __func__);
287                 return -EIO;
288         }
289
290         return f81534_set_register(serial, F81534_BUS_REG_STATUS,
291                                 tmp & ~F81534_BUS_IDLE);
292 }
293
294 static int f81534_get_spi_register(struct usb_serial *serial, u16 reg,
295                                         u8 *data)
296 {
297         int status;
298
299         status = f81534_get_register(serial, reg, data);
300         if (status)
301                 return status;
302
303         return f81534_wait_for_spi_idle(serial);
304 }
305
306 static int f81534_set_spi_register(struct usb_serial *serial, u16 reg, u8 data)
307 {
308         int status;
309
310         status = f81534_set_register(serial, reg, data);
311         if (status)
312                 return status;
313
314         return f81534_wait_for_spi_idle(serial);
315 }
316
317 static int f81534_read_flash(struct usb_serial *serial, u32 address,
318                                 size_t size, u8 *buf)
319 {
320         u8 tmp_buf[F81534_MAX_DATA_BLOCK];
321         size_t block = 0;
322         size_t read_size;
323         size_t count;
324         int status;
325         int offset;
326         u16 reg_tmp;
327
328         status = f81534_set_spi_register(serial, F81534_BUS_REG_START,
329                                         F81534_CMD_READ);
330         if (status)
331                 return status;
332
333         status = f81534_set_spi_register(serial, F81534_BUS_REG_START,
334                                         (address >> 16) & 0xff);
335         if (status)
336                 return status;
337
338         status = f81534_set_spi_register(serial, F81534_BUS_REG_START,
339                                         (address >> 8) & 0xff);
340         if (status)
341                 return status;
342
343         status = f81534_set_spi_register(serial, F81534_BUS_REG_START,
344                                         (address >> 0) & 0xff);
345         if (status)
346                 return status;
347
348         /* Continuous read mode */
349         do {
350                 read_size = min_t(size_t, F81534_MAX_DATA_BLOCK, size);
351
352                 for (count = 0; count < read_size; ++count) {
353                         /* To write F81534_BUS_REG_END when final byte */
354                         if (size <= F81534_MAX_DATA_BLOCK &&
355                                         read_size == count + 1)
356                                 reg_tmp = F81534_BUS_REG_END;
357                         else
358                                 reg_tmp = F81534_BUS_REG_START;
359
360                         /*
361                          * Dummy code, force IC to generate a read pulse, the
362                          * set of value 0xf1 is dont care (any value is ok)
363                          */
364                         status = f81534_set_spi_register(serial, reg_tmp,
365                                         0xf1);
366                         if (status)
367                                 return status;
368
369                         status = f81534_get_spi_register(serial,
370                                                 F81534_BUS_READ_DATA,
371                                                 &tmp_buf[count]);
372                         if (status)
373                                 return status;
374
375                         offset = count + block * F81534_MAX_DATA_BLOCK;
376                         buf[offset] = tmp_buf[count];
377                 }
378
379                 size -= read_size;
380                 ++block;
381         } while (size);
382
383         return 0;
384 }
385
386 static void f81534_prepare_write_buffer(struct usb_serial_port *port, u8 *buf)
387 {
388         struct f81534_port_private *port_priv = usb_get_serial_port_data(port);
389         int phy_num = port_priv->phy_num;
390         u8 tx_len;
391         int i;
392
393         /*
394          * The block layout is fixed with 4x128 Bytes, per 128 Bytes a port.
395          * index 0: port phy idx (e.g., 0,1,2,3)
396          * index 1: only F81534_TOKEN_WRITE
397          * index 2: serial TX out length
398          * index 3: fix to 0
399          * index 4~127: serial out data block
400          */
401         for (i = 0; i < F81534_NUM_PORT; ++i) {
402                 buf[i * F81534_RECEIVE_BLOCK_SIZE] = i;
403                 buf[i * F81534_RECEIVE_BLOCK_SIZE + 1] = F81534_TOKEN_WRITE;
404                 buf[i * F81534_RECEIVE_BLOCK_SIZE + 2] = 0;
405                 buf[i * F81534_RECEIVE_BLOCK_SIZE + 3] = 0;
406         }
407
408         tx_len = kfifo_out_locked(&port->write_fifo,
409                                 &buf[phy_num * F81534_RECEIVE_BLOCK_SIZE + 4],
410                                 F81534_MAX_TX_SIZE, &port->lock);
411
412         buf[phy_num * F81534_RECEIVE_BLOCK_SIZE + 2] = tx_len;
413 }
414
415 static int f81534_submit_writer(struct usb_serial_port *port, gfp_t mem_flags)
416 {
417         struct f81534_port_private *port_priv = usb_get_serial_port_data(port);
418         struct urb *urb;
419         unsigned long flags;
420         int result;
421
422         /* Check is any data in write_fifo */
423         spin_lock_irqsave(&port->lock, flags);
424
425         if (kfifo_is_empty(&port->write_fifo)) {
426                 spin_unlock_irqrestore(&port->lock, flags);
427                 return 0;
428         }
429
430         spin_unlock_irqrestore(&port->lock, flags);
431
432         /* Check H/W is TXEMPTY */
433         if (!test_and_clear_bit(F81534_TX_EMPTY_BIT, &port_priv->tx_empty))
434                 return 0;
435
436         urb = port->write_urbs[0];
437         f81534_prepare_write_buffer(port, port->bulk_out_buffers[0]);
438         urb->transfer_buffer_length = F81534_WRITE_BUFFER_SIZE;
439
440         result = usb_submit_urb(urb, mem_flags);
441         if (result) {
442                 set_bit(F81534_TX_EMPTY_BIT, &port_priv->tx_empty);
443                 dev_err(&port->dev, "%s: submit failed: %d\n", __func__,
444                                 result);
445                 return result;
446         }
447
448         usb_serial_port_softint(port);
449         return 0;
450 }
451
452 static u32 f81534_calc_baud_divisor(u32 baudrate, u32 clockrate)
453 {
454         if (!baudrate)
455                 return 0;
456
457         /* Round to nearest divisor */
458         return DIV_ROUND_CLOSEST(clockrate, baudrate);
459 }
460
461 static int f81534_set_port_config(struct usb_serial_port *port, u32 baudrate,
462                                         u8 lcr)
463 {
464         u32 divisor;
465         int status;
466         u8 value;
467
468         if (baudrate <= 1200)
469                 value = F81534_1X_RXTRIGGER;    /* 128 FIFO & TL: 1x */
470         else
471                 value = F81534_8X_RXTRIGGER;    /* 128 FIFO & TL: 8x */
472
473         status = f81534_set_port_register(port, F81534_CONFIG1_REG, value);
474         if (status) {
475                 dev_err(&port->dev, "%s: CONFIG1 setting failed\n", __func__);
476                 return status;
477         }
478
479         if (baudrate <= 1200)
480                 value = UART_FCR_TRIGGER_1 | UART_FCR_ENABLE_FIFO; /* TL: 1 */
481         else
482                 value = UART_FCR_R_TRIG_11 | UART_FCR_ENABLE_FIFO; /* TL: 14 */
483
484         status = f81534_set_port_register(port, F81534_FIFO_CONTROL_REG,
485                                                 value);
486         if (status) {
487                 dev_err(&port->dev, "%s: FCR setting failed\n", __func__);
488                 return status;
489         }
490
491         divisor = f81534_calc_baud_divisor(baudrate, F81534_MAX_BAUDRATE);
492         value = UART_LCR_DLAB;
493         status = f81534_set_port_register(port, F81534_LINE_CONTROL_REG,
494                                                 value);
495         if (status) {
496                 dev_err(&port->dev, "%s: set LCR failed\n", __func__);
497                 return status;
498         }
499
500         value = divisor & 0xff;
501         status = f81534_set_port_register(port, F81534_DIVISOR_LSB_REG, value);
502         if (status) {
503                 dev_err(&port->dev, "%s: set DLAB LSB failed\n", __func__);
504                 return status;
505         }
506
507         value = (divisor >> 8) & 0xff;
508         status = f81534_set_port_register(port, F81534_DIVISOR_MSB_REG, value);
509         if (status) {
510                 dev_err(&port->dev, "%s: set DLAB MSB failed\n", __func__);
511                 return status;
512         }
513
514         status = f81534_set_port_register(port, F81534_LINE_CONTROL_REG, lcr);
515         if (status) {
516                 dev_err(&port->dev, "%s: set LCR failed\n", __func__);
517                 return status;
518         }
519
520         return 0;
521 }
522
523 static int f81534_update_mctrl(struct usb_serial_port *port, unsigned int set,
524                                 unsigned int clear)
525 {
526         struct f81534_port_private *port_priv = usb_get_serial_port_data(port);
527         int status;
528         u8 tmp;
529
530         if (((set | clear) & (TIOCM_DTR | TIOCM_RTS)) == 0)
531                 return 0;       /* no change */
532
533         mutex_lock(&port_priv->mcr_mutex);
534
535         /* 'Set' takes precedence over 'Clear' */
536         clear &= ~set;
537
538         /* Always enable UART_MCR_OUT2 */
539         tmp = UART_MCR_OUT2 | port_priv->shadow_mcr;
540
541         if (clear & TIOCM_DTR)
542                 tmp &= ~UART_MCR_DTR;
543
544         if (clear & TIOCM_RTS)
545                 tmp &= ~UART_MCR_RTS;
546
547         if (set & TIOCM_DTR)
548                 tmp |= UART_MCR_DTR;
549
550         if (set & TIOCM_RTS)
551                 tmp |= UART_MCR_RTS;
552
553         status = f81534_set_port_register(port, F81534_MODEM_CONTROL_REG, tmp);
554         if (status < 0) {
555                 dev_err(&port->dev, "%s: MCR write failed\n", __func__);
556                 mutex_unlock(&port_priv->mcr_mutex);
557                 return status;
558         }
559
560         port_priv->shadow_mcr = tmp;
561         mutex_unlock(&port_priv->mcr_mutex);
562         return 0;
563 }
564
565 /*
566  * This function will search the data area with token F81534_CUSTOM_VALID_TOKEN
567  * for latest configuration index. If nothing found
568  * (*index = F81534_CUSTOM_NO_CUSTOM_DATA), We'll load default configure in
569  * F81534_DEF_CONF_ADDRESS_START section.
570  *
571  * Due to we only use block0 to save data, so *index should be 0 or
572  * F81534_CUSTOM_NO_CUSTOM_DATA.
573  */
574 static int f81534_find_config_idx(struct usb_serial *serial, u8 *index)
575 {
576         u8 tmp;
577         int status;
578
579         status = f81534_read_flash(serial, F81534_CUSTOM_ADDRESS_START, 1,
580                                         &tmp);
581         if (status) {
582                 dev_err(&serial->interface->dev, "%s: read failed: %d\n",
583                                 __func__, status);
584                 return status;
585         }
586
587         /* We'll use the custom data when the data is valid. */
588         if (tmp == F81534_CUSTOM_VALID_TOKEN)
589                 *index = 0;
590         else
591                 *index = F81534_CUSTOM_NO_CUSTOM_DATA;
592
593         return 0;
594 }
595
596 /*
597  * We had 2 generation of F81532/534 IC. All has an internal storage.
598  *
599  * 1st is pure USB-to-TTL RS232 IC and designed for 4 ports only, no any
600  * internal data will used. All mode and gpio control should manually set
601  * by AP or Driver and all storage space value are 0xff. The
602  * f81534_calc_num_ports() will run to final we marked as "oldest version"
603  * for this IC.
604  *
605  * 2rd is designed to more generic to use any transceiver and this is our
606  * mass production type. We'll save data in F81534_CUSTOM_ADDRESS_START
607  * (0x2f00) with 9bytes. The 1st byte is a indicater. If the token is
608  * F81534_CUSTOM_VALID_TOKEN(0xf0), the IC is 2nd gen type, the following
609  * 4bytes save port mode (0:RS232/1:RS485 Invert/2:RS485), and the last
610  * 4bytes save GPIO state(value from 0~7 to represent 3 GPIO output pin).
611  * The f81534_calc_num_ports() will run to "new style" with checking
612  * F81534_PORT_UNAVAILABLE section.
613  */
614 static int f81534_calc_num_ports(struct usb_serial *serial,
615                                         struct usb_serial_endpoints *epds)
616 {
617         struct device *dev = &serial->interface->dev;
618         int size_bulk_in = usb_endpoint_maxp(epds->bulk_in[0]);
619         int size_bulk_out = usb_endpoint_maxp(epds->bulk_out[0]);
620         u8 setting[F81534_CUSTOM_DATA_SIZE];
621         u8 setting_idx;
622         u8 num_port = 0;
623         int status;
624         size_t i;
625
626         if (size_bulk_out != F81534_WRITE_BUFFER_SIZE ||
627                         size_bulk_in != F81534_MAX_RECEIVE_BLOCK_SIZE) {
628                 dev_err(dev, "unsupported endpoint max packet size\n");
629                 return -ENODEV;
630         }
631
632         /* Check had custom setting */
633         status = f81534_find_config_idx(serial, &setting_idx);
634         if (status) {
635                 dev_err(&serial->interface->dev, "%s: find idx failed: %d\n",
636                                 __func__, status);
637                 return status;
638         }
639
640         /*
641          * We'll read custom data only when data available, otherwise we'll
642          * read default value instead.
643          */
644         if (setting_idx != F81534_CUSTOM_NO_CUSTOM_DATA) {
645                 status = f81534_read_flash(serial,
646                                                 F81534_CUSTOM_ADDRESS_START +
647                                                 F81534_CONF_OFFSET,
648                                                 sizeof(setting), setting);
649                 if (status) {
650                         dev_err(&serial->interface->dev,
651                                         "%s: get custom data failed: %d\n",
652                                         __func__, status);
653                         return status;
654                 }
655
656                 dev_dbg(&serial->interface->dev,
657                                 "%s: read config from block: %d\n", __func__,
658                                 setting_idx);
659         } else {
660                 /* Read default board setting */
661                 status = f81534_read_flash(serial,
662                                 F81534_DEF_CONF_ADDRESS_START, F81534_NUM_PORT,
663                                 setting);
664
665                 if (status) {
666                         dev_err(&serial->interface->dev,
667                                         "%s: read failed: %d\n", __func__,
668                                         status);
669                         return status;
670                 }
671
672                 dev_dbg(&serial->interface->dev, "%s: read default config\n",
673                                 __func__);
674         }
675
676         /* New style, find all possible ports */
677         for (i = 0; i < F81534_NUM_PORT; ++i) {
678                 if (setting[i] & F81534_PORT_UNAVAILABLE)
679                         continue;
680
681                 ++num_port;
682         }
683
684         if (!num_port) {
685                 dev_warn(&serial->interface->dev,
686                         "no config found, assuming 4 ports\n");
687                 num_port = 4;           /* Nothing found, oldest version IC */
688         }
689
690         return num_port;
691 }
692
693 static void f81534_set_termios(struct tty_struct *tty,
694                                 struct usb_serial_port *port,
695                                 struct ktermios *old_termios)
696 {
697         u8 new_lcr = 0;
698         int status;
699         u32 baud;
700
701         if (C_BAUD(tty) == B0)
702                 f81534_update_mctrl(port, 0, TIOCM_DTR | TIOCM_RTS);
703         else if (old_termios && (old_termios->c_cflag & CBAUD) == B0)
704                 f81534_update_mctrl(port, TIOCM_DTR | TIOCM_RTS, 0);
705
706         if (C_PARENB(tty)) {
707                 new_lcr |= UART_LCR_PARITY;
708
709                 if (!C_PARODD(tty))
710                         new_lcr |= UART_LCR_EPAR;
711
712                 if (C_CMSPAR(tty))
713                         new_lcr |= UART_LCR_SPAR;
714         }
715
716         if (C_CSTOPB(tty))
717                 new_lcr |= UART_LCR_STOP;
718
719         switch (C_CSIZE(tty)) {
720         case CS5:
721                 new_lcr |= UART_LCR_WLEN5;
722                 break;
723         case CS6:
724                 new_lcr |= UART_LCR_WLEN6;
725                 break;
726         case CS7:
727                 new_lcr |= UART_LCR_WLEN7;
728                 break;
729         default:
730         case CS8:
731                 new_lcr |= UART_LCR_WLEN8;
732                 break;
733         }
734
735         baud = tty_get_baud_rate(tty);
736         if (!baud)
737                 return;
738
739         if (baud > F81534_MAX_BAUDRATE) {
740                 if (old_termios)
741                         baud = tty_termios_baud_rate(old_termios);
742                 else
743                         baud = F81534_DEFAULT_BAUD_RATE;
744
745                 tty_encode_baud_rate(tty, baud, baud);
746         }
747
748         dev_dbg(&port->dev, "%s: baud: %d\n", __func__, baud);
749
750         status = f81534_set_port_config(port, baud, new_lcr);
751         if (status < 0) {
752                 dev_err(&port->dev, "%s: set port config failed: %d\n",
753                                 __func__, status);
754         }
755 }
756
757 static int f81534_submit_read_urb(struct usb_serial *serial, gfp_t flags)
758 {
759         return usb_serial_generic_submit_read_urbs(serial->port[0], flags);
760 }
761
762 static void f81534_msr_changed(struct usb_serial_port *port, u8 msr)
763 {
764         struct f81534_port_private *port_priv = usb_get_serial_port_data(port);
765         struct tty_struct *tty;
766         unsigned long flags;
767         u8 old_msr;
768
769         if (!(msr & UART_MSR_ANY_DELTA))
770                 return;
771
772         spin_lock_irqsave(&port_priv->msr_lock, flags);
773         old_msr = port_priv->shadow_msr;
774         port_priv->shadow_msr = msr;
775         spin_unlock_irqrestore(&port_priv->msr_lock, flags);
776
777         dev_dbg(&port->dev, "%s: MSR from %02x to %02x\n", __func__, old_msr,
778                         msr);
779
780         /* Update input line counters */
781         if (msr & UART_MSR_DCTS)
782                 port->icount.cts++;
783         if (msr & UART_MSR_DDSR)
784                 port->icount.dsr++;
785         if (msr & UART_MSR_DDCD)
786                 port->icount.dcd++;
787         if (msr & UART_MSR_TERI)
788                 port->icount.rng++;
789
790         wake_up_interruptible(&port->port.delta_msr_wait);
791
792         if (!(msr & UART_MSR_DDCD))
793                 return;
794
795         dev_dbg(&port->dev, "%s: DCD Changed: phy_num: %d from %x to %x\n",
796                         __func__, port_priv->phy_num, old_msr, msr);
797
798         tty = tty_port_tty_get(&port->port);
799         if (!tty)
800                 return;
801
802         usb_serial_handle_dcd_change(port, tty, msr & UART_MSR_DCD);
803         tty_kref_put(tty);
804 }
805
806 static int f81534_read_msr(struct usb_serial_port *port)
807 {
808         struct f81534_port_private *port_priv = usb_get_serial_port_data(port);
809         unsigned long flags;
810         int status;
811         u8 msr;
812
813         /* Get MSR initial value */
814         status = f81534_get_port_register(port, F81534_MODEM_STATUS_REG, &msr);
815         if (status)
816                 return status;
817
818         /* Force update current state */
819         spin_lock_irqsave(&port_priv->msr_lock, flags);
820         port_priv->shadow_msr = msr;
821         spin_unlock_irqrestore(&port_priv->msr_lock, flags);
822
823         return 0;
824 }
825
826 static int f81534_open(struct tty_struct *tty, struct usb_serial_port *port)
827 {
828         struct f81534_serial_private *serial_priv =
829                         usb_get_serial_data(port->serial);
830         struct f81534_port_private *port_priv = usb_get_serial_port_data(port);
831         int status;
832
833         status = f81534_set_port_register(port,
834                                 F81534_FIFO_CONTROL_REG, UART_FCR_ENABLE_FIFO |
835                                 UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT);
836         if (status) {
837                 dev_err(&port->dev, "%s: Clear FIFO failed: %d\n", __func__,
838                                 status);
839                 return status;
840         }
841
842         if (tty)
843                 f81534_set_termios(tty, port, NULL);
844
845         status = f81534_read_msr(port);
846         if (status)
847                 return status;
848
849         mutex_lock(&serial_priv->urb_mutex);
850
851         /* Submit Read URBs for first port opened */
852         if (!serial_priv->opened_port) {
853                 status = f81534_submit_read_urb(port->serial, GFP_KERNEL);
854                 if (status)
855                         goto exit;
856         }
857
858         serial_priv->opened_port++;
859
860 exit:
861         mutex_unlock(&serial_priv->urb_mutex);
862
863         set_bit(F81534_TX_EMPTY_BIT, &port_priv->tx_empty);
864         return status;
865 }
866
867 static void f81534_close(struct usb_serial_port *port)
868 {
869         struct f81534_serial_private *serial_priv =
870                         usb_get_serial_data(port->serial);
871         struct usb_serial_port *port0 = port->serial->port[0];
872         unsigned long flags;
873         size_t i;
874
875         usb_kill_urb(port->write_urbs[0]);
876
877         spin_lock_irqsave(&port->lock, flags);
878         kfifo_reset_out(&port->write_fifo);
879         spin_unlock_irqrestore(&port->lock, flags);
880
881         /* Kill Read URBs when final port closed */
882         mutex_lock(&serial_priv->urb_mutex);
883         serial_priv->opened_port--;
884
885         if (!serial_priv->opened_port) {
886                 for (i = 0; i < ARRAY_SIZE(port0->read_urbs); ++i)
887                         usb_kill_urb(port0->read_urbs[i]);
888         }
889
890         mutex_unlock(&serial_priv->urb_mutex);
891 }
892
893 static int f81534_get_serial_info(struct usb_serial_port *port,
894                                   struct serial_struct __user *retinfo)
895 {
896         struct f81534_port_private *port_priv;
897         struct serial_struct tmp;
898
899         port_priv = usb_get_serial_port_data(port);
900
901         memset(&tmp, 0, sizeof(tmp));
902
903         tmp.type = PORT_16550A;
904         tmp.port = port->port_number;
905         tmp.line = port->minor;
906         tmp.baud_base = F81534_MAX_BAUDRATE;
907
908         if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
909                 return -EFAULT;
910
911         return 0;
912 }
913
914 static int f81534_ioctl(struct tty_struct *tty, unsigned int cmd,
915                         unsigned long arg)
916 {
917         struct usb_serial_port *port = tty->driver_data;
918         struct serial_struct __user *buf = (struct serial_struct __user *)arg;
919
920         switch (cmd) {
921         case TIOCGSERIAL:
922                 return f81534_get_serial_info(port, buf);
923         default:
924                 break;
925         }
926
927         return -ENOIOCTLCMD;
928 }
929
930 static void f81534_process_per_serial_block(struct usb_serial_port *port,
931                 u8 *data)
932 {
933         struct f81534_port_private *port_priv = usb_get_serial_port_data(port);
934         int phy_num = data[0];
935         size_t read_size = 0;
936         size_t i;
937         char tty_flag;
938         int status;
939         u8 lsr;
940
941         /*
942          * The block layout is 128 Bytes
943          * index 0: port phy idx (e.g., 0,1,2,3),
944          * index 1: It's could be
945          *                      F81534_TOKEN_RECEIVE
946          *                      F81534_TOKEN_TX_EMPTY
947          *                      F81534_TOKEN_MSR_CHANGE
948          * index 2: serial in size (data+lsr, must be even)
949          *                      meaningful for F81534_TOKEN_RECEIVE only
950          * index 3: current MSR with this device
951          * index 4~127: serial in data block (data+lsr, must be even)
952          */
953         switch (data[1]) {
954         case F81534_TOKEN_TX_EMPTY:
955                 set_bit(F81534_TX_EMPTY_BIT, &port_priv->tx_empty);
956
957                 /* Try to submit writer */
958                 status = f81534_submit_writer(port, GFP_ATOMIC);
959                 if (status)
960                         dev_err(&port->dev, "%s: submit failed\n", __func__);
961                 return;
962
963         case F81534_TOKEN_MSR_CHANGE:
964                 f81534_msr_changed(port, data[3]);
965                 return;
966
967         case F81534_TOKEN_RECEIVE:
968                 read_size = data[2];
969                 if (read_size > F81534_MAX_RX_SIZE) {
970                         dev_err(&port->dev,
971                                 "%s: phy: %d read_size: %zu larger than: %d\n",
972                                 __func__, phy_num, read_size,
973                                 F81534_MAX_RX_SIZE);
974                         return;
975                 }
976
977                 break;
978
979         default:
980                 dev_warn(&port->dev, "%s: unknown token: %02x\n", __func__,
981                                 data[1]);
982                 return;
983         }
984
985         for (i = 4; i < 4 + read_size; i += 2) {
986                 tty_flag = TTY_NORMAL;
987                 lsr = data[i + 1];
988
989                 if (lsr & UART_LSR_BRK_ERROR_BITS) {
990                         if (lsr & UART_LSR_BI) {
991                                 tty_flag = TTY_BREAK;
992                                 port->icount.brk++;
993                                 usb_serial_handle_break(port);
994                         } else if (lsr & UART_LSR_PE) {
995                                 tty_flag = TTY_PARITY;
996                                 port->icount.parity++;
997                         } else if (lsr & UART_LSR_FE) {
998                                 tty_flag = TTY_FRAME;
999                                 port->icount.frame++;
1000                         }
1001
1002                         if (lsr & UART_LSR_OE) {
1003                                 port->icount.overrun++;
1004                                 tty_insert_flip_char(&port->port, 0,
1005                                                 TTY_OVERRUN);
1006                         }
1007                 }
1008
1009                 if (port->port.console && port->sysrq) {
1010                         if (usb_serial_handle_sysrq_char(port, data[i]))
1011                                 continue;
1012                 }
1013
1014                 tty_insert_flip_char(&port->port, data[i], tty_flag);
1015         }
1016
1017         tty_flip_buffer_push(&port->port);
1018 }
1019
1020 static void f81534_process_read_urb(struct urb *urb)
1021 {
1022         struct f81534_serial_private *serial_priv;
1023         struct usb_serial_port *port;
1024         struct usb_serial *serial;
1025         u8 *buf;
1026         int phy_port_num;
1027         int tty_port_num;
1028         size_t i;
1029
1030         if (!urb->actual_length ||
1031                         urb->actual_length % F81534_RECEIVE_BLOCK_SIZE) {
1032                 return;
1033         }
1034
1035         port = urb->context;
1036         serial = port->serial;
1037         buf = urb->transfer_buffer;
1038         serial_priv = usb_get_serial_data(serial);
1039
1040         for (i = 0; i < urb->actual_length; i += F81534_RECEIVE_BLOCK_SIZE) {
1041                 phy_port_num = buf[i];
1042                 if (phy_port_num >= F81534_NUM_PORT) {
1043                         dev_err(&port->dev,
1044                                 "%s: phy_port_num: %d larger than: %d\n",
1045                                 __func__, phy_port_num, F81534_NUM_PORT);
1046                         continue;
1047                 }
1048
1049                 tty_port_num = serial_priv->tty_idx[phy_port_num];
1050                 port = serial->port[tty_port_num];
1051
1052                 if (tty_port_initialized(&port->port))
1053                         f81534_process_per_serial_block(port, &buf[i]);
1054         }
1055 }
1056
1057 static void f81534_write_usb_callback(struct urb *urb)
1058 {
1059         struct usb_serial_port *port = urb->context;
1060
1061         switch (urb->status) {
1062         case 0:
1063                 break;
1064         case -ENOENT:
1065         case -ECONNRESET:
1066         case -ESHUTDOWN:
1067                 dev_dbg(&port->dev, "%s - urb stopped: %d\n",
1068                                 __func__, urb->status);
1069                 return;
1070         case -EPIPE:
1071                 dev_err(&port->dev, "%s - urb stopped: %d\n",
1072                                 __func__, urb->status);
1073                 return;
1074         default:
1075                 dev_dbg(&port->dev, "%s - nonzero urb status: %d\n",
1076                                 __func__, urb->status);
1077                 break;
1078         }
1079 }
1080
1081 static int f81534_setup_ports(struct usb_serial *serial)
1082 {
1083         struct usb_serial_port *port;
1084         u8 port0_out_address;
1085         int buffer_size;
1086         size_t i;
1087
1088         /*
1089          * In our system architecture, we had 2 or 4 serial ports,
1090          * but only get 1 set of bulk in/out endpoints.
1091          *
1092          * The usb-serial subsystem will generate port 0 data,
1093          * but port 1/2/3 will not. It's will generate write URB and buffer
1094          * by following code and use the port0 read URB for read operation.
1095          */
1096         for (i = 1; i < serial->num_ports; ++i) {
1097                 port0_out_address = serial->port[0]->bulk_out_endpointAddress;
1098                 buffer_size = serial->port[0]->bulk_out_size;
1099                 port = serial->port[i];
1100
1101                 if (kfifo_alloc(&port->write_fifo, PAGE_SIZE, GFP_KERNEL))
1102                         return -ENOMEM;
1103
1104                 port->bulk_out_size = buffer_size;
1105                 port->bulk_out_endpointAddress = port0_out_address;
1106
1107                 port->write_urbs[0] = usb_alloc_urb(0, GFP_KERNEL);
1108                 if (!port->write_urbs[0])
1109                         return -ENOMEM;
1110
1111                 port->bulk_out_buffers[0] = kzalloc(buffer_size, GFP_KERNEL);
1112                 if (!port->bulk_out_buffers[0])
1113                         return -ENOMEM;
1114
1115                 usb_fill_bulk_urb(port->write_urbs[0], serial->dev,
1116                                 usb_sndbulkpipe(serial->dev,
1117                                         port0_out_address),
1118                                 port->bulk_out_buffers[0], buffer_size,
1119                                 serial->type->write_bulk_callback, port);
1120
1121                 port->write_urb = port->write_urbs[0];
1122                 port->bulk_out_buffer = port->bulk_out_buffers[0];
1123         }
1124
1125         return 0;
1126 }
1127
1128 static int f81534_attach(struct usb_serial *serial)
1129 {
1130         struct f81534_serial_private *serial_priv;
1131         int index = 0;
1132         int status;
1133         int i;
1134
1135         serial_priv = devm_kzalloc(&serial->interface->dev,
1136                                         sizeof(*serial_priv), GFP_KERNEL);
1137         if (!serial_priv)
1138                 return -ENOMEM;
1139
1140         usb_set_serial_data(serial, serial_priv);
1141
1142         mutex_init(&serial_priv->urb_mutex);
1143
1144         status = f81534_setup_ports(serial);
1145         if (status)
1146                 return status;
1147
1148         /* Check had custom setting */
1149         status = f81534_find_config_idx(serial, &serial_priv->setting_idx);
1150         if (status) {
1151                 dev_err(&serial->interface->dev, "%s: find idx failed: %d\n",
1152                                 __func__, status);
1153                 return status;
1154         }
1155
1156         /*
1157          * We'll read custom data only when data available, otherwise we'll
1158          * read default value instead.
1159          */
1160         if (serial_priv->setting_idx == F81534_CUSTOM_NO_CUSTOM_DATA) {
1161                 /*
1162                  * The default configuration layout:
1163                  *      byte 0/1/2/3: uart setting
1164                  */
1165                 status = f81534_read_flash(serial,
1166                                         F81534_DEF_CONF_ADDRESS_START,
1167                                         F81534_DEF_CONF_SIZE,
1168                                         serial_priv->conf_data);
1169                 if (status) {
1170                         dev_err(&serial->interface->dev,
1171                                         "%s: read reserve data failed: %d\n",
1172                                         __func__, status);
1173                         return status;
1174                 }
1175         } else {
1176                 /* Only read 8 bytes for mode & GPIO */
1177                 status = f81534_read_flash(serial,
1178                                                 F81534_CUSTOM_ADDRESS_START +
1179                                                 F81534_CONF_OFFSET,
1180                                                 sizeof(serial_priv->conf_data),
1181                                                 serial_priv->conf_data);
1182                 if (status) {
1183                         dev_err(&serial->interface->dev,
1184                                         "%s: idx: %d get data failed: %d\n",
1185                                         __func__, serial_priv->setting_idx,
1186                                         status);
1187                         return status;
1188                 }
1189         }
1190
1191         /* Assign phy-to-logic mapping */
1192         for (i = 0; i < F81534_NUM_PORT; ++i) {
1193                 if (serial_priv->conf_data[i] & F81534_PORT_UNAVAILABLE)
1194                         continue;
1195
1196                 serial_priv->tty_idx[i] = index++;
1197                 dev_dbg(&serial->interface->dev,
1198                                 "%s: phy_num: %d, tty_idx: %d\n", __func__, i,
1199                                 serial_priv->tty_idx[i]);
1200         }
1201
1202         return 0;
1203 }
1204
1205 static int f81534_port_probe(struct usb_serial_port *port)
1206 {
1207         struct f81534_port_private *port_priv;
1208         int ret;
1209
1210         port_priv = devm_kzalloc(&port->dev, sizeof(*port_priv), GFP_KERNEL);
1211         if (!port_priv)
1212                 return -ENOMEM;
1213
1214         spin_lock_init(&port_priv->msr_lock);
1215         mutex_init(&port_priv->mcr_mutex);
1216
1217         /* Assign logic-to-phy mapping */
1218         ret = f81534_logic_to_phy_port(port->serial, port);
1219         if (ret < 0)
1220                 return ret;
1221
1222         port_priv->phy_num = ret;
1223         usb_set_serial_port_data(port, port_priv);
1224         dev_dbg(&port->dev, "%s: port_number: %d, phy_num: %d\n", __func__,
1225                         port->port_number, port_priv->phy_num);
1226
1227         return 0;
1228 }
1229
1230 static int f81534_tiocmget(struct tty_struct *tty)
1231 {
1232         struct usb_serial_port *port = tty->driver_data;
1233         struct f81534_port_private *port_priv = usb_get_serial_port_data(port);
1234         int status;
1235         int r;
1236         u8 msr;
1237         u8 mcr;
1238
1239         /* Read current MSR from device */
1240         status = f81534_get_port_register(port, F81534_MODEM_STATUS_REG, &msr);
1241         if (status)
1242                 return status;
1243
1244         mutex_lock(&port_priv->mcr_mutex);
1245         mcr = port_priv->shadow_mcr;
1246         mutex_unlock(&port_priv->mcr_mutex);
1247
1248         r = (mcr & UART_MCR_DTR ? TIOCM_DTR : 0) |
1249             (mcr & UART_MCR_RTS ? TIOCM_RTS : 0) |
1250             (msr & UART_MSR_CTS ? TIOCM_CTS : 0) |
1251             (msr & UART_MSR_DCD ? TIOCM_CAR : 0) |
1252             (msr & UART_MSR_RI ? TIOCM_RI : 0) |
1253             (msr & UART_MSR_DSR ? TIOCM_DSR : 0);
1254
1255         return r;
1256 }
1257
1258 static int f81534_tiocmset(struct tty_struct *tty, unsigned int set,
1259                                 unsigned int clear)
1260 {
1261         struct usb_serial_port *port = tty->driver_data;
1262
1263         return f81534_update_mctrl(port, set, clear);
1264 }
1265
1266 static void f81534_dtr_rts(struct usb_serial_port *port, int on)
1267 {
1268         if (on)
1269                 f81534_update_mctrl(port, TIOCM_DTR | TIOCM_RTS, 0);
1270         else
1271                 f81534_update_mctrl(port, 0, TIOCM_DTR | TIOCM_RTS);
1272 }
1273
1274 static int f81534_write(struct tty_struct *tty, struct usb_serial_port *port,
1275                         const u8 *buf, int count)
1276 {
1277         int bytes_out, status;
1278
1279         if (!count)
1280                 return 0;
1281
1282         bytes_out = kfifo_in_locked(&port->write_fifo, buf, count,
1283                                         &port->lock);
1284
1285         status = f81534_submit_writer(port, GFP_ATOMIC);
1286         if (status) {
1287                 dev_err(&port->dev, "%s: submit failed\n", __func__);
1288                 return status;
1289         }
1290
1291         return bytes_out;
1292 }
1293
1294 static bool f81534_tx_empty(struct usb_serial_port *port)
1295 {
1296         struct f81534_port_private *port_priv = usb_get_serial_port_data(port);
1297
1298         return test_bit(F81534_TX_EMPTY_BIT, &port_priv->tx_empty);
1299 }
1300
1301 static int f81534_resume(struct usb_serial *serial)
1302 {
1303         struct f81534_serial_private *serial_priv =
1304                         usb_get_serial_data(serial);
1305         struct usb_serial_port *port;
1306         int error = 0;
1307         int status;
1308         size_t i;
1309
1310         /*
1311          * We'll register port 0 bulkin when port had opened, It'll take all
1312          * port received data, MSR register change and TX_EMPTY information.
1313          */
1314         mutex_lock(&serial_priv->urb_mutex);
1315
1316         if (serial_priv->opened_port) {
1317                 status = f81534_submit_read_urb(serial, GFP_NOIO);
1318                 if (status) {
1319                         mutex_unlock(&serial_priv->urb_mutex);
1320                         return status;
1321                 }
1322         }
1323
1324         mutex_unlock(&serial_priv->urb_mutex);
1325
1326         for (i = 0; i < serial->num_ports; i++) {
1327                 port = serial->port[i];
1328                 if (!tty_port_initialized(&port->port))
1329                         continue;
1330
1331                 status = f81534_submit_writer(port, GFP_NOIO);
1332                 if (status) {
1333                         dev_err(&port->dev, "%s: submit failed\n", __func__);
1334                         ++error;
1335                 }
1336         }
1337
1338         if (error)
1339                 return -EIO;
1340
1341         return 0;
1342 }
1343
1344 static struct usb_serial_driver f81534_device = {
1345         .driver = {
1346                    .owner = THIS_MODULE,
1347                    .name = "f81534",
1348         },
1349         .description =          DRIVER_DESC,
1350         .id_table =             f81534_id_table,
1351         .num_bulk_in =          1,
1352         .num_bulk_out =         1,
1353         .open =                 f81534_open,
1354         .close =                f81534_close,
1355         .write =                f81534_write,
1356         .tx_empty =             f81534_tx_empty,
1357         .calc_num_ports =       f81534_calc_num_ports,
1358         .attach =               f81534_attach,
1359         .port_probe =           f81534_port_probe,
1360         .dtr_rts =              f81534_dtr_rts,
1361         .process_read_urb =     f81534_process_read_urb,
1362         .ioctl =                f81534_ioctl,
1363         .tiocmget =             f81534_tiocmget,
1364         .tiocmset =             f81534_tiocmset,
1365         .write_bulk_callback =  f81534_write_usb_callback,
1366         .set_termios =          f81534_set_termios,
1367         .resume =               f81534_resume,
1368 };
1369
1370 static struct usb_serial_driver *const serial_drivers[] = {
1371         &f81534_device, NULL
1372 };
1373
1374 module_usb_serial_driver(serial_drivers, f81534_id_table);
1375
1376 MODULE_DEVICE_TABLE(usb, f81534_id_table);
1377 MODULE_DESCRIPTION(DRIVER_DESC);
1378 MODULE_AUTHOR("Peter Hong <Peter_Hong@fintek.com.tw>");
1379 MODULE_AUTHOR("Tom Tsai <Tom_Tsai@fintek.com.tw>");
1380 MODULE_LICENSE("GPL");