3 * Controls the Moschip 7720 usb to dual port serial convertor
5 * Copyright 2006 Moschip Semiconductor Tech. Ltd.
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, version 2 of the License.
12 * Vijaya Kumar <vijaykumar.gn@gmail.com>
13 * Ajay Kumar <naanuajay@yahoo.com>
14 * Gurudeva <ngurudeva@yahoo.com>
16 * Cleaned up from the original by:
17 * Greg Kroah-Hartman <gregkh@suse.de>
19 * Originally based on drivers/usb/serial/io_edgeport.c which is:
20 * Copyright (C) 2000 Inside Out Networks, All rights reserved.
21 * Copyright (C) 2001-2002 Greg Kroah-Hartman <greg@kroah.com>
23 #include <linux/kernel.h>
24 #include <linux/errno.h>
25 #include <linux/init.h>
26 #include <linux/slab.h>
27 #include <linux/tty.h>
28 #include <linux/tty_driver.h>
29 #include <linux/tty_flip.h>
30 #include <linux/module.h>
31 #include <linux/spinlock.h>
32 #include <linux/serial.h>
33 #include <linux/serial_reg.h>
34 #include <linux/usb.h>
35 #include <linux/usb/serial.h>
36 #include <linux/uaccess.h>
42 #define DRIVER_VERSION "1.0.0.4F"
43 #define DRIVER_AUTHOR "Aspire Communications pvt Ltd."
44 #define DRIVER_DESC "Moschip USB Serial Driver"
46 /* default urb timeout */
47 #define MOS_WDR_TIMEOUT (HZ * 5)
49 #define MOS_PORT1 0x0200
50 #define MOS_PORT2 0x0300
51 #define MOS_VENREG 0x0000
52 #define MOS_MAX_PORT 0x02
53 #define MOS_WRITE 0x0E
56 /* Interrupt Rotinue Defines */
57 #define SERIAL_IIR_RLS 0x06
58 #define SERIAL_IIR_RDA 0x04
59 #define SERIAL_IIR_CTI 0x0c
60 #define SERIAL_IIR_THR 0x02
61 #define SERIAL_IIR_MS 0x00
63 #define NUM_URBS 16 /* URB Count */
64 #define URB_TRANSFER_BUFFER_SIZE 32 /* URB Size */
66 /* This structure holds all of the local port information */
68 __u8 shadowLCR; /* last LCR value received */
69 __u8 shadowMCR; /* last MCR value received */
70 __u8 shadowMSR; /* last MSR value received */
72 struct async_icount icount;
73 struct usb_serial_port *port; /* loop back to the owner */
74 struct urb *write_urb_pool[NUM_URBS];
77 /* This structure holds all of the individual serial device information */
78 struct moschip_serial {
79 int interrupt_started;
84 static struct usb_serial_driver moschip7720_2port_driver;
86 #define USB_VENDOR_ID_MOSCHIP 0x9710
87 #define MOSCHIP_DEVICE_ID_7720 0x7720
88 #define MOSCHIP_DEVICE_ID_7715 0x7715
90 static const struct usb_device_id moschip_port_id_table[] = {
91 { USB_DEVICE(USB_VENDOR_ID_MOSCHIP, MOSCHIP_DEVICE_ID_7720) },
92 { USB_DEVICE(USB_VENDOR_ID_MOSCHIP, MOSCHIP_DEVICE_ID_7715) },
93 { } /* terminating entry */
95 MODULE_DEVICE_TABLE(usb, moschip_port_id_table);
99 * mos7720_interrupt_callback
100 * this is the callback function for when we have received data on the
101 * interrupt endpoint.
103 static void mos7720_interrupt_callback(struct urb *urb)
107 int status = urb->status;
121 /* this urb is terminated, clean up */
122 dbg("%s - urb shutting down with status: %d", __func__,
126 dbg("%s - nonzero urb status received: %d", __func__,
131 length = urb->actual_length;
132 data = urb->transfer_buffer;
134 /* Moschip get 4 bytes
135 * Byte 1 IIR Port 1 (port.number is 0)
136 * Byte 2 IIR Port 2 (port.number is 1)
137 * Byte 3 --------------
138 * Byte 4 FIFO status for both */
140 /* the above description is inverted
141 * oneukum 2007-03-14 */
143 if (unlikely(length != 4)) {
144 dbg("Wrong data !!!");
151 if ((sp1 | sp2) & 0x01) {
152 /* No Interrupt Pending in both the ports */
153 dbg("No Interrupt !!!");
155 switch (sp1 & 0x0f) {
157 dbg("Serial Port 1: Receiver status error or address "
158 "bit detected in 9-bit mode\n");
161 dbg("Serial Port 1: Receiver time out");
164 dbg("Serial Port 1: Modem status change");
168 switch (sp2 & 0x0f) {
170 dbg("Serial Port 2: Receiver status error or address "
171 "bit detected in 9-bit mode");
174 dbg("Serial Port 2: Receiver time out");
177 dbg("Serial Port 2: Modem status change");
183 result = usb_submit_urb(urb, GFP_ATOMIC);
185 dev_err(&urb->dev->dev,
186 "%s - Error %d submitting control urb\n",
192 * mos7715_interrupt_callback
193 * this is the 7715's callback function for when we have received data on
194 * the interrupt endpoint.
196 static void mos7715_interrupt_callback(struct urb *urb)
200 int status = urb->status;
211 /* this urb is terminated, clean up */
212 dbg("%s - urb shutting down with status: %d", __func__,
216 dbg("%s - nonzero urb status received: %d", __func__,
221 length = urb->actual_length;
222 data = urb->transfer_buffer;
224 /* Structure of data from 7715 device:
225 * Byte 1: IIR serial Port
227 * Byte 2: DSR parallel port
228 * Byte 4: FIFO status for both */
230 if (unlikely(length != 4)) {
231 dbg("Wrong data !!!");
236 if (!(iir & 0x01)) { /* serial port interrupt pending */
237 switch (iir & 0x0f) {
239 dbg("Serial Port: Receiver status error or address "
240 "bit detected in 9-bit mode\n");
243 dbg("Serial Port: Receiver time out");
246 dbg("Serial Port: Modem status change");
252 result = usb_submit_urb(urb, GFP_ATOMIC);
254 dev_err(&urb->dev->dev,
255 "%s - Error %d submitting control urb\n",
261 * mos7720_bulk_in_callback
262 * this is the callback function for when we have received data on the
265 static void mos7720_bulk_in_callback(struct urb *urb)
268 unsigned char *data ;
269 struct usb_serial_port *port;
270 struct moschip_port *mos7720_port;
271 struct tty_struct *tty;
272 int status = urb->status;
275 dbg("nonzero read bulk status received: %d", status);
279 mos7720_port = urb->context;
281 dbg("NULL mos7720_port pointer");
285 port = mos7720_port->port;
287 dbg("Entering...%s", __func__);
289 data = urb->transfer_buffer;
291 tty = tty_port_tty_get(&port->port);
292 if (tty && urb->actual_length) {
293 tty_buffer_request_room(tty, urb->actual_length);
294 tty_insert_flip_string(tty, data, urb->actual_length);
295 tty_flip_buffer_push(tty);
299 if (!port->read_urb) {
300 dbg("URB KILLED !!!");
304 if (port->read_urb->status != -EINPROGRESS) {
305 port->read_urb->dev = port->serial->dev;
307 retval = usb_submit_urb(port->read_urb, GFP_ATOMIC);
309 dbg("usb_submit_urb(read bulk) failed, retval = %d",
315 * mos7720_bulk_out_data_callback
316 * this is the callback function for when we have finished sending serial
317 * data on the bulk out endpoint.
319 static void mos7720_bulk_out_data_callback(struct urb *urb)
321 struct moschip_port *mos7720_port;
322 struct tty_struct *tty;
323 int status = urb->status;
326 dbg("nonzero write bulk status received:%d", status);
330 mos7720_port = urb->context;
332 dbg("NULL mos7720_port pointer");
336 dbg("Entering .........");
338 tty = tty_port_tty_get(&mos7720_port->port->port);
340 if (tty && mos7720_port->open)
347 * this function will be used for sending command to device
349 static int send_mos_cmd(struct usb_serial *serial, __u8 request, __u16 value,
350 __u16 index, u8 *data)
354 u16 product = le16_to_cpu(serial->dev->descriptor.idProduct);
356 if (value < MOS_MAX_PORT) {
357 if (product == MOSCHIP_DEVICE_ID_7715)
358 value = 0x0200; /* identifies the 7715's serial port */
360 value = value*0x100+0x200;
363 if ((product == MOSCHIP_DEVICE_ID_7715) &&
365 dbg("serial->product== MOSCHIP_DEVICE_ID_7715");
370 if (request == MOS_WRITE) {
371 value = value + *data;
372 status = usb_control_msg(serial->dev,
373 usb_sndctrlpipe(serial->dev, 0), MOS_WRITE,
374 0x40, value, index, NULL, 0, MOS_WDR_TIMEOUT);
376 buf = kmalloc(1, GFP_KERNEL);
381 status = usb_control_msg(serial->dev,
382 usb_rcvctrlpipe(serial->dev, 0), MOS_READ,
383 0xc0, value, index, buf, 1, MOS_WDR_TIMEOUT);
389 dbg("Command Write failed Value %x index %x", value, index);
397 * this function installs the appropriate read interrupt endpoint callback
398 * depending on whether the device is a 7720 or 7715, thus avoiding costly
399 * run-time checks in the high-frequency callback routine itself.
401 static int mos77xx_probe(struct usb_serial *serial,
402 const struct usb_device_id *id)
404 if (id->idProduct == MOSCHIP_DEVICE_ID_7715)
405 moschip7720_2port_driver.read_int_callback =
406 mos7715_interrupt_callback;
408 moschip7720_2port_driver.read_int_callback =
409 mos7720_interrupt_callback;
414 static int mos77xx_calc_num_ports(struct usb_serial *serial)
416 u16 product = le16_to_cpu(serial->dev->descriptor.idProduct);
417 if (product == MOSCHIP_DEVICE_ID_7715)
423 static int mos7720_open(struct tty_struct *tty, struct usb_serial_port *port)
425 struct usb_serial *serial;
426 struct usb_serial_port *port0;
428 struct moschip_serial *mos7720_serial;
429 struct moschip_port *mos7720_port;
433 int allocated_urbs = 0;
436 serial = port->serial;
438 mos7720_port = usb_get_serial_port_data(port);
439 if (mos7720_port == NULL)
442 port0 = serial->port[0];
444 mos7720_serial = usb_get_serial_data(serial);
446 if (mos7720_serial == NULL || port0 == NULL)
449 usb_clear_halt(serial->dev, port->write_urb->pipe);
450 usb_clear_halt(serial->dev, port->read_urb->pipe);
452 /* Initialising the write urb pool */
453 for (j = 0; j < NUM_URBS; ++j) {
454 urb = usb_alloc_urb(0, GFP_KERNEL);
455 mos7720_port->write_urb_pool[j] = urb;
458 dev_err(&port->dev, "No more urbs???\n");
462 urb->transfer_buffer = kmalloc(URB_TRANSFER_BUFFER_SIZE,
464 if (!urb->transfer_buffer) {
466 "%s-out of memory for urb buffers.\n",
468 usb_free_urb(mos7720_port->write_urb_pool[j]);
469 mos7720_port->write_urb_pool[j] = NULL;
478 /* Initialize MCS7720 -- Write Init values to corresponding Registers
490 * 0x08 : SP1/2 Control Reg
492 port_number = port->number - port->serial->minor;
493 send_mos_cmd(port->serial, MOS_READ, port_number, UART_LSR, &data);
494 dbg("SS::%p LSR:%x", mos7720_port, data);
496 dbg("Check:Sending Command ..........");
499 send_mos_cmd(serial, MOS_WRITE, MOS_MAX_PORT, 0x01, &data);
501 send_mos_cmd(serial, MOS_WRITE, MOS_MAX_PORT, 0x02, &data);
504 send_mos_cmd(serial, MOS_WRITE, port_number, 0x01, &data);
506 send_mos_cmd(serial, MOS_WRITE, port_number, 0x02, &data);
509 send_mos_cmd(serial, MOS_WRITE, port_number, 0x02, &data);
511 mos7720_port->shadowLCR = data;
512 send_mos_cmd(serial, MOS_WRITE, port_number, 0x03, &data);
514 mos7720_port->shadowMCR = data;
515 send_mos_cmd(serial, MOS_WRITE, port_number, 0x04, &data);
517 send_mos_cmd(serial, MOS_WRITE, port_number, 0x04, &data);
520 send_mos_cmd(serial, MOS_READ, MOS_MAX_PORT, 0x08, &data);
522 send_mos_cmd(serial, MOS_WRITE, MOS_MAX_PORT, 0x08, &data);
525 send_mos_cmd(serial, MOS_READ, MOS_MAX_PORT, port_number + 1, &data);
527 send_mos_cmd(serial, MOS_WRITE, MOS_MAX_PORT, port_number + 1, &data);
529 send_mos_cmd(port->serial, MOS_WRITE, MOS_MAX_PORT,
530 port_number + 1, &data);
533 send_mos_cmd(serial, MOS_READ, MOS_MAX_PORT, 0x08, &data);
535 data = data | (port->number - port->serial->minor + 1);
536 send_mos_cmd(serial, MOS_WRITE, MOS_MAX_PORT, 0x08, &data);
539 mos7720_port->shadowLCR = data;
540 send_mos_cmd(serial, MOS_WRITE, port_number, 0x03, &data);
542 send_mos_cmd(serial, MOS_WRITE, port_number, 0x00, &data);
544 send_mos_cmd(serial, MOS_WRITE, port_number, 0x01, &data);
546 mos7720_port->shadowLCR = data;
547 send_mos_cmd(serial, MOS_WRITE, port_number, 0x03, &data);
549 send_mos_cmd(serial, MOS_WRITE, port_number, 0x01, &data);
551 send_mos_cmd(serial, MOS_WRITE, port_number, 0x01, &data);
553 /* see if we've set up our endpoint info yet *
554 * (can't set it up in mos7720_startup as the *
555 * structures were not set up at that time.) */
556 if (!mos7720_serial->interrupt_started) {
557 dbg("Interrupt buffer NULL !!!");
559 /* not set up yet, so do it now */
560 mos7720_serial->interrupt_started = 1;
562 dbg("To Submit URB !!!");
564 /* set up our interrupt urb */
565 usb_fill_int_urb(port0->interrupt_in_urb, serial->dev,
566 usb_rcvintpipe(serial->dev,
567 port->interrupt_in_endpointAddress),
568 port0->interrupt_in_buffer,
569 port0->interrupt_in_urb->transfer_buffer_length,
570 mos7720_interrupt_callback, mos7720_port,
571 port0->interrupt_in_urb->interval);
573 /* start interrupt read for this mos7720 this interrupt *
574 * will continue as long as the mos7720 is connected */
575 dbg("Submit URB over !!!");
576 response = usb_submit_urb(port0->interrupt_in_urb, GFP_KERNEL);
579 "%s - Error %d submitting control urb\n",
583 /* set up our bulk in urb */
584 usb_fill_bulk_urb(port->read_urb, serial->dev,
585 usb_rcvbulkpipe(serial->dev,
586 port->bulk_in_endpointAddress),
587 port->bulk_in_buffer,
588 port->read_urb->transfer_buffer_length,
589 mos7720_bulk_in_callback, mos7720_port);
590 response = usb_submit_urb(port->read_urb, GFP_KERNEL);
592 dev_err(&port->dev, "%s - Error %d submitting read urb\n",
595 /* initialize our icount structure */
596 memset(&(mos7720_port->icount), 0x00, sizeof(mos7720_port->icount));
598 /* initialize our port settings */
599 mos7720_port->shadowMCR = UART_MCR_OUT2; /* Must set to enable ints! */
601 /* send a open port command */
602 mos7720_port->open = 1;
608 * mos7720_chars_in_buffer
609 * this function is called by the tty driver when it wants to know how many
610 * bytes of data we currently have outstanding in the port (data that has
611 * been written, but hasn't made it out the port yet)
612 * If successful, we return the number of bytes left to be written in the
614 * Otherwise we return a negative error number.
616 static int mos7720_chars_in_buffer(struct tty_struct *tty)
618 struct usb_serial_port *port = tty->driver_data;
621 struct moschip_port *mos7720_port;
623 dbg("%s:entering ...........", __func__);
625 mos7720_port = usb_get_serial_port_data(port);
626 if (mos7720_port == NULL) {
627 dbg("%s:leaving ...........", __func__);
631 for (i = 0; i < NUM_URBS; ++i) {
632 if (mos7720_port->write_urb_pool[i] &&
633 mos7720_port->write_urb_pool[i]->status == -EINPROGRESS)
634 chars += URB_TRANSFER_BUFFER_SIZE;
636 dbg("%s - returns %d", __func__, chars);
640 static void mos7720_close(struct usb_serial_port *port)
642 struct usb_serial *serial;
643 struct moschip_port *mos7720_port;
647 dbg("mos7720_close:entering...");
649 serial = port->serial;
651 mos7720_port = usb_get_serial_port_data(port);
652 if (mos7720_port == NULL)
655 for (j = 0; j < NUM_URBS; ++j)
656 usb_kill_urb(mos7720_port->write_urb_pool[j]);
658 /* Freeing Write URBs */
659 for (j = 0; j < NUM_URBS; ++j) {
660 if (mos7720_port->write_urb_pool[j]) {
661 kfree(mos7720_port->write_urb_pool[j]->transfer_buffer);
662 usb_free_urb(mos7720_port->write_urb_pool[j]);
666 /* While closing port, shutdown all bulk read, write *
667 * and interrupt read if they exists, otherwise nop */
668 dbg("Shutdown bulk write");
669 usb_kill_urb(port->write_urb);
670 dbg("Shutdown bulk read");
671 usb_kill_urb(port->read_urb);
673 mutex_lock(&serial->disc_mutex);
674 /* these commands must not be issued if the device has
675 * been disconnected */
676 if (!serial->disconnected) {
678 send_mos_cmd(serial, MOS_WRITE,
679 port->number - port->serial->minor, 0x04, &data);
682 send_mos_cmd(serial, MOS_WRITE,
683 port->number - port->serial->minor, 0x01, &data);
685 mutex_unlock(&serial->disc_mutex);
686 mos7720_port->open = 0;
688 dbg("Leaving %s", __func__);
691 static void mos7720_break(struct tty_struct *tty, int break_state)
693 struct usb_serial_port *port = tty->driver_data;
695 struct usb_serial *serial;
696 struct moschip_port *mos7720_port;
698 dbg("Entering %s", __func__);
700 serial = port->serial;
702 mos7720_port = usb_get_serial_port_data(port);
703 if (mos7720_port == NULL)
706 if (break_state == -1)
707 data = mos7720_port->shadowLCR | UART_LCR_SBC;
709 data = mos7720_port->shadowLCR & ~UART_LCR_SBC;
711 mos7720_port->shadowLCR = data;
712 send_mos_cmd(serial, MOS_WRITE, port->number - port->serial->minor,
720 * this function is called by the tty driver when it wants to know how many
721 * bytes of data we can accept for a specific port.
722 * If successful, we return the amount of room that we have for this port
723 * Otherwise we return a negative error number.
725 static int mos7720_write_room(struct tty_struct *tty)
727 struct usb_serial_port *port = tty->driver_data;
728 struct moschip_port *mos7720_port;
732 dbg("%s:entering ...........", __func__);
734 mos7720_port = usb_get_serial_port_data(port);
735 if (mos7720_port == NULL) {
736 dbg("%s:leaving ...........", __func__);
741 for (i = 0; i < NUM_URBS; ++i) {
742 if (mos7720_port->write_urb_pool[i] &&
743 mos7720_port->write_urb_pool[i]->status != -EINPROGRESS)
744 room += URB_TRANSFER_BUFFER_SIZE;
747 dbg("%s - returns %d", __func__, room);
751 static int mos7720_write(struct tty_struct *tty, struct usb_serial_port *port,
752 const unsigned char *data, int count)
759 struct moschip_port *mos7720_port;
760 struct usb_serial *serial;
762 const unsigned char *current_position = data;
764 dbg("%s:entering ...........", __func__);
766 serial = port->serial;
768 mos7720_port = usb_get_serial_port_data(port);
769 if (mos7720_port == NULL) {
770 dbg("mos7720_port is NULL");
774 /* try to find a free urb in the list */
777 for (i = 0; i < NUM_URBS; ++i) {
778 if (mos7720_port->write_urb_pool[i] &&
779 mos7720_port->write_urb_pool[i]->status != -EINPROGRESS) {
780 urb = mos7720_port->write_urb_pool[i];
787 dbg("%s - no more free urbs", __func__);
791 if (urb->transfer_buffer == NULL) {
792 urb->transfer_buffer = kmalloc(URB_TRANSFER_BUFFER_SIZE,
794 if (urb->transfer_buffer == NULL) {
795 dev_err(&port->dev, "%s no more kernel memory...\n",
800 transfer_size = min(count, URB_TRANSFER_BUFFER_SIZE);
802 memcpy(urb->transfer_buffer, current_position, transfer_size);
803 usb_serial_debug_data(debug, &port->dev, __func__, transfer_size,
804 urb->transfer_buffer);
806 /* fill urb with data and submit */
807 usb_fill_bulk_urb(urb, serial->dev,
808 usb_sndbulkpipe(serial->dev,
809 port->bulk_out_endpointAddress),
810 urb->transfer_buffer, transfer_size,
811 mos7720_bulk_out_data_callback, mos7720_port);
813 /* send it down the pipe */
814 status = usb_submit_urb(urb, GFP_ATOMIC);
816 dev_err(&port->dev, "%s - usb_submit_urb(write bulk) failed "
817 "with status = %d\n", __func__, status);
821 bytes_sent = transfer_size;
827 static void mos7720_throttle(struct tty_struct *tty)
829 struct usb_serial_port *port = tty->driver_data;
830 struct moschip_port *mos7720_port;
833 dbg("%s- port %d", __func__, port->number);
835 mos7720_port = usb_get_serial_port_data(port);
837 if (mos7720_port == NULL)
840 if (!mos7720_port->open) {
841 dbg("port not opened");
845 dbg("%s: Entering ..........", __func__);
847 /* if we are implementing XON/XOFF, send the stop character */
849 unsigned char stop_char = STOP_CHAR(tty);
850 status = mos7720_write(tty, port, &stop_char, 1);
855 /* if we are implementing RTS/CTS, toggle that line */
856 if (tty->termios->c_cflag & CRTSCTS) {
857 mos7720_port->shadowMCR &= ~UART_MCR_RTS;
858 status = send_mos_cmd(port->serial, MOS_WRITE,
859 port->number - port->serial->minor,
860 UART_MCR, &mos7720_port->shadowMCR);
866 static void mos7720_unthrottle(struct tty_struct *tty)
868 struct usb_serial_port *port = tty->driver_data;
869 struct moschip_port *mos7720_port = usb_get_serial_port_data(port);
872 if (mos7720_port == NULL)
875 if (!mos7720_port->open) {
876 dbg("%s - port not opened", __func__);
880 dbg("%s: Entering ..........", __func__);
882 /* if we are implementing XON/XOFF, send the start character */
884 unsigned char start_char = START_CHAR(tty);
885 status = mos7720_write(tty, port, &start_char, 1);
890 /* if we are implementing RTS/CTS, toggle that line */
891 if (tty->termios->c_cflag & CRTSCTS) {
892 mos7720_port->shadowMCR |= UART_MCR_RTS;
893 status = send_mos_cmd(port->serial, MOS_WRITE,
894 port->number - port->serial->minor,
895 UART_MCR, &mos7720_port->shadowMCR);
901 static int set_higher_rates(struct moschip_port *mos7720_port,
905 struct usb_serial_port *port;
906 struct usb_serial *serial;
909 if (mos7720_port == NULL)
912 port = mos7720_port->port;
913 serial = port->serial;
915 /***********************************************
916 * Init Sequence for higher rates
917 ***********************************************/
918 dbg("Sending Setting Commands ..........");
919 port_number = port->number - port->serial->minor;
922 send_mos_cmd(serial, MOS_WRITE, port_number, 0x01, &data);
924 send_mos_cmd(serial, MOS_WRITE, port_number, 0x02, &data);
926 send_mos_cmd(serial, MOS_WRITE, port->number, 0x02, &data);
928 mos7720_port->shadowMCR = data;
929 send_mos_cmd(serial, MOS_WRITE, port_number, 0x04, &data);
931 send_mos_cmd(serial, MOS_WRITE, port_number, 0x04, &data);
934 send_mos_cmd(serial, MOS_READ, MOS_MAX_PORT, 0x08, &data);
936 send_mos_cmd(serial, MOS_WRITE, MOS_MAX_PORT, 0x08, &data);
939 /***********************************************
940 * Set for higher rates *
941 ***********************************************/
944 send_mos_cmd(serial, MOS_WRITE, MOS_MAX_PORT, port_number + 1, &data);
947 send_mos_cmd(serial, MOS_READ, MOS_MAX_PORT, 0x08, &data);
949 send_mos_cmd(serial, MOS_WRITE, MOS_MAX_PORT, 0x08, &data);
952 mos7720_port->shadowMCR = data;
953 send_mos_cmd(serial, MOS_WRITE, port_number, 0x04, &data);
955 send_mos_cmd(serial, MOS_WRITE, port_number, 0x04, &data);
957 /***********************************************
959 ***********************************************/
961 data = mos7720_port->shadowLCR | UART_LCR_DLAB;
962 mos7720_port->shadowLCR = data;
963 send_mos_cmd(serial, MOS_WRITE, port_number, 0x03, &data);
965 data = 0x001; /* DLL */
966 send_mos_cmd(serial, MOS_WRITE, port_number, 0x00, &data);
967 data = 0x000; /* DLM */
968 send_mos_cmd(serial, MOS_WRITE, port_number, 0x01, &data);
970 data = mos7720_port->shadowLCR & ~UART_LCR_DLAB;
971 mos7720_port->shadowLCR = data;
972 send_mos_cmd(serial, MOS_WRITE, port_number, 0x03, &data);
977 /* baud rate information */
978 struct divisor_table_entry {
983 /* Define table of divisors for moschip 7720 hardware *
984 * These assume a 3.6864MHz crystal, the standard /16, and *
986 static struct divisor_table_entry divisor_table[] = {
988 { 110, 1047}, /* 2094.545455 => 230450 => .0217 % over */
989 { 134, 857}, /* 1713.011152 => 230398.5 => .00065% under */
1005 /*****************************************************************************
1006 * calc_baud_rate_divisor
1007 * this function calculates the proper baud rate divisor for the specified
1009 *****************************************************************************/
1010 static int calc_baud_rate_divisor(int baudrate, int *divisor)
1018 dbg("%s - %d", __func__, baudrate);
1020 for (i = 0; i < ARRAY_SIZE(divisor_table); i++) {
1021 if (divisor_table[i].baudrate == baudrate) {
1022 *divisor = divisor_table[i].divisor;
1027 /* After trying for all the standard baud rates *
1028 * Try calculating the divisor for this baud rate */
1029 if (baudrate > 75 && baudrate < 230400) {
1030 /* get the divisor */
1031 custom = (__u16)(230400L / baudrate);
1033 /* Check for round off */
1034 round1 = (__u16)(2304000L / baudrate);
1035 round = (__u16)(round1 - (custom * 10));
1040 dbg("Baud %d = %d", baudrate, custom);
1044 dbg("Baud calculation Failed...");
1049 * send_cmd_write_baud_rate
1050 * this function sends the proper command to change the baud rate of the
1053 static int send_cmd_write_baud_rate(struct moschip_port *mos7720_port,
1056 struct usb_serial_port *port;
1057 struct usb_serial *serial;
1061 unsigned char number;
1063 if (mos7720_port == NULL)
1066 port = mos7720_port->port;
1067 serial = port->serial;
1069 dbg("%s: Entering ..........", __func__);
1071 number = port->number - port->serial->minor;
1072 dbg("%s - port = %d, baud = %d", __func__, port->number, baudrate);
1074 /* Calculate the Divisor */
1075 status = calc_baud_rate_divisor(baudrate, &divisor);
1077 dev_err(&port->dev, "%s - bad baud rate\n", __func__);
1081 /* Enable access to divisor latch */
1082 data = mos7720_port->shadowLCR | UART_LCR_DLAB;
1083 mos7720_port->shadowLCR = data;
1084 send_mos_cmd(serial, MOS_WRITE, number, UART_LCR, &data);
1086 /* Write the divisor */
1087 data = ((unsigned char)(divisor & 0xff));
1088 send_mos_cmd(serial, MOS_WRITE, number, 0x00, &data);
1090 data = ((unsigned char)((divisor & 0xff00) >> 8));
1091 send_mos_cmd(serial, MOS_WRITE, number, 0x01, &data);
1093 /* Disable access to divisor latch */
1094 data = mos7720_port->shadowLCR & ~UART_LCR_DLAB;
1095 mos7720_port->shadowLCR = data;
1096 send_mos_cmd(serial, MOS_WRITE, number, 0x03, &data);
1102 * change_port_settings
1103 * This routine is called to set the UART on the device to match
1104 * the specified new settings.
1106 static void change_port_settings(struct tty_struct *tty,
1107 struct moschip_port *mos7720_port,
1108 struct ktermios *old_termios)
1110 struct usb_serial_port *port;
1111 struct usb_serial *serial;
1123 if (mos7720_port == NULL)
1126 port = mos7720_port->port;
1127 serial = port->serial;
1128 port_number = port->number - port->serial->minor;
1130 dbg("%s - port %d", __func__, port->number);
1132 if (!mos7720_port->open) {
1133 dbg("%s - port not opened", __func__);
1137 dbg("%s: Entering ..........", __func__);
1139 lData = UART_LCR_WLEN8;
1140 lStop = 0x00; /* 1 stop bit */
1141 lParity = 0x00; /* No parity */
1143 cflag = tty->termios->c_cflag;
1144 iflag = tty->termios->c_iflag;
1146 /* Change the number of bits */
1147 switch (cflag & CSIZE) {
1149 lData = UART_LCR_WLEN5;
1154 lData = UART_LCR_WLEN6;
1159 lData = UART_LCR_WLEN7;
1164 lData = UART_LCR_WLEN8;
1168 /* Change the Parity bit */
1169 if (cflag & PARENB) {
1170 if (cflag & PARODD) {
1171 lParity = UART_LCR_PARITY;
1172 dbg("%s - parity = odd", __func__);
1174 lParity = (UART_LCR_EPAR | UART_LCR_PARITY);
1175 dbg("%s - parity = even", __func__);
1179 dbg("%s - parity = none", __func__);
1183 lParity = lParity | 0x20;
1185 /* Change the Stop bit */
1186 if (cflag & CSTOPB) {
1187 lStop = UART_LCR_STOP;
1188 dbg("%s - stop bits = 2", __func__);
1191 dbg("%s - stop bits = 1", __func__);
1194 #define LCR_BITS_MASK 0x03 /* Mask for bits/char field */
1195 #define LCR_STOP_MASK 0x04 /* Mask for stop bits field */
1196 #define LCR_PAR_MASK 0x38 /* Mask for parity field */
1198 /* Update the LCR with the correct value */
1199 mos7720_port->shadowLCR &=
1200 ~(LCR_BITS_MASK | LCR_STOP_MASK | LCR_PAR_MASK);
1201 mos7720_port->shadowLCR |= (lData | lParity | lStop);
1204 /* Disable Interrupts */
1206 send_mos_cmd(serial, MOS_WRITE, port->number - port->serial->minor,
1210 send_mos_cmd(serial, MOS_WRITE, port_number, UART_FCR, &data);
1213 send_mos_cmd(serial, MOS_WRITE, port_number, UART_FCR, &data);
1215 /* Send the updated LCR value to the mos7720 */
1216 data = mos7720_port->shadowLCR;
1217 send_mos_cmd(serial, MOS_WRITE, port_number, UART_LCR, &data);
1220 mos7720_port->shadowMCR = data;
1221 send_mos_cmd(serial, MOS_WRITE, port_number, 0x04, &data);
1223 send_mos_cmd(serial, MOS_WRITE, port_number, 0x04, &data);
1225 /* set up the MCR register and send it to the mos7720 */
1226 mos7720_port->shadowMCR = UART_MCR_OUT2;
1228 mos7720_port->shadowMCR |= (UART_MCR_DTR | UART_MCR_RTS);
1230 if (cflag & CRTSCTS) {
1231 mos7720_port->shadowMCR |= (UART_MCR_XONANY);
1232 /* To set hardware flow control to the specified *
1233 * serial port, in SP1/2_CONTROL_REG */
1236 send_mos_cmd(serial, MOS_WRITE, MOS_MAX_PORT,
1240 send_mos_cmd(serial, MOS_WRITE, MOS_MAX_PORT,
1244 mos7720_port->shadowMCR &= ~(UART_MCR_XONANY);
1247 data = mos7720_port->shadowMCR;
1248 send_mos_cmd(serial, MOS_WRITE, port_number, UART_MCR, &data);
1250 /* Determine divisor based on baud rate */
1251 baud = tty_get_baud_rate(tty);
1253 /* pick a default, any default... */
1254 dbg("Picked default baud...");
1258 if (baud >= 230400) {
1259 set_higher_rates(mos7720_port, baud);
1260 /* Enable Interrupts */
1262 send_mos_cmd(serial, MOS_WRITE, port_number, UART_IER, &data);
1266 dbg("%s - baud rate = %d", __func__, baud);
1267 status = send_cmd_write_baud_rate(mos7720_port, baud);
1268 /* FIXME: needs to write actual resulting baud back not just
1271 tty_encode_baud_rate(tty, baud, baud);
1272 /* Enable Interrupts */
1274 send_mos_cmd(serial, MOS_WRITE, port_number, UART_IER, &data);
1276 if (port->read_urb->status != -EINPROGRESS) {
1277 port->read_urb->dev = serial->dev;
1279 status = usb_submit_urb(port->read_urb, GFP_ATOMIC);
1281 dbg("usb_submit_urb(read bulk) failed, status = %d",
1288 * mos7720_set_termios
1289 * this function is called by the tty driver when it wants to change the
1290 * termios structure.
1292 static void mos7720_set_termios(struct tty_struct *tty,
1293 struct usb_serial_port *port, struct ktermios *old_termios)
1297 struct usb_serial *serial;
1298 struct moschip_port *mos7720_port;
1300 serial = port->serial;
1302 mos7720_port = usb_get_serial_port_data(port);
1304 if (mos7720_port == NULL)
1307 if (!mos7720_port->open) {
1308 dbg("%s - port not opened", __func__);
1312 dbg("setting termios - ASPIRE");
1314 cflag = tty->termios->c_cflag;
1316 dbg("%s - cflag %08x iflag %08x", __func__,
1317 tty->termios->c_cflag,
1318 RELEVANT_IFLAG(tty->termios->c_iflag));
1320 dbg("%s - old cflag %08x old iflag %08x", __func__,
1321 old_termios->c_cflag,
1322 RELEVANT_IFLAG(old_termios->c_iflag));
1324 dbg("%s - port %d", __func__, port->number);
1326 /* change the port settings to the new ones specified */
1327 change_port_settings(tty, mos7720_port, old_termios);
1329 if (!port->read_urb) {
1330 dbg("URB KILLED !!!!!");
1334 if (port->read_urb->status != -EINPROGRESS) {
1335 port->read_urb->dev = serial->dev;
1336 status = usb_submit_urb(port->read_urb, GFP_ATOMIC);
1338 dbg("usb_submit_urb(read bulk) failed, status = %d",
1345 * get_lsr_info - get line status register info
1347 * Purpose: Let user call ioctl() to get info when the UART physically
1348 * is emptied. On bus types like RS485, the transmitter must
1349 * release the bus after transmitting. This must be done when
1350 * the transmit shift register is empty, not be done when the
1351 * transmit holding register is empty. This functionality
1352 * allows an RS485 driver to be written in user space.
1354 static int get_lsr_info(struct tty_struct *tty,
1355 struct moschip_port *mos7720_port, unsigned int __user *value)
1357 struct usb_serial_port *port = tty->driver_data;
1358 unsigned int result = 0;
1359 unsigned char data = 0;
1360 int port_number = port->number - port->serial->minor;
1363 count = mos7720_chars_in_buffer(tty);
1365 send_mos_cmd(port->serial, MOS_READ, port_number,
1367 if ((data & (UART_LSR_TEMT | UART_LSR_THRE))
1368 == (UART_LSR_TEMT | UART_LSR_THRE)) {
1369 dbg("%s -- Empty", __func__);
1370 result = TIOCSER_TEMT;
1373 if (copy_to_user(value, &result, sizeof(int)))
1378 static int mos7720_tiocmget(struct tty_struct *tty, struct file *file)
1380 struct usb_serial_port *port = tty->driver_data;
1381 struct moschip_port *mos7720_port = usb_get_serial_port_data(port);
1382 unsigned int result = 0;
1386 dbg("%s - port %d", __func__, port->number);
1388 mcr = mos7720_port->shadowMCR;
1389 msr = mos7720_port->shadowMSR;
1391 result = ((mcr & UART_MCR_DTR) ? TIOCM_DTR : 0) /* 0x002 */
1392 | ((mcr & UART_MCR_RTS) ? TIOCM_RTS : 0) /* 0x004 */
1393 | ((msr & UART_MSR_CTS) ? TIOCM_CTS : 0) /* 0x020 */
1394 | ((msr & UART_MSR_DCD) ? TIOCM_CAR : 0) /* 0x040 */
1395 | ((msr & UART_MSR_RI) ? TIOCM_RI : 0) /* 0x080 */
1396 | ((msr & UART_MSR_DSR) ? TIOCM_DSR : 0); /* 0x100 */
1398 dbg("%s -- %x", __func__, result);
1403 static int mos7720_tiocmset(struct tty_struct *tty, struct file *file,
1404 unsigned int set, unsigned int clear)
1406 struct usb_serial_port *port = tty->driver_data;
1407 struct moschip_port *mos7720_port = usb_get_serial_port_data(port);
1411 dbg("%s - port %d", __func__, port->number);
1412 dbg("he was at tiocmget");
1414 mcr = mos7720_port->shadowMCR;
1416 if (set & TIOCM_RTS)
1417 mcr |= UART_MCR_RTS;
1418 if (set & TIOCM_DTR)
1419 mcr |= UART_MCR_DTR;
1420 if (set & TIOCM_LOOP)
1421 mcr |= UART_MCR_LOOP;
1423 if (clear & TIOCM_RTS)
1424 mcr &= ~UART_MCR_RTS;
1425 if (clear & TIOCM_DTR)
1426 mcr &= ~UART_MCR_DTR;
1427 if (clear & TIOCM_LOOP)
1428 mcr &= ~UART_MCR_LOOP;
1430 mos7720_port->shadowMCR = mcr;
1431 lmcr = mos7720_port->shadowMCR;
1433 send_mos_cmd(port->serial, MOS_WRITE,
1434 port->number - port->serial->minor, UART_MCR, &lmcr);
1439 static int set_modem_info(struct moschip_port *mos7720_port, unsigned int cmd,
1440 unsigned int __user *value)
1446 struct usb_serial_port *port;
1448 if (mos7720_port == NULL)
1451 port = (struct usb_serial_port *)mos7720_port->port;
1452 mcr = mos7720_port->shadowMCR;
1454 if (copy_from_user(&arg, value, sizeof(int)))
1459 if (arg & TIOCM_RTS)
1460 mcr |= UART_MCR_RTS;
1461 if (arg & TIOCM_DTR)
1462 mcr |= UART_MCR_RTS;
1463 if (arg & TIOCM_LOOP)
1464 mcr |= UART_MCR_LOOP;
1468 if (arg & TIOCM_RTS)
1469 mcr &= ~UART_MCR_RTS;
1470 if (arg & TIOCM_DTR)
1471 mcr &= ~UART_MCR_RTS;
1472 if (arg & TIOCM_LOOP)
1473 mcr &= ~UART_MCR_LOOP;
1478 mos7720_port->shadowMCR = mcr;
1480 data = mos7720_port->shadowMCR;
1481 send_mos_cmd(port->serial, MOS_WRITE,
1482 port->number - port->serial->minor, UART_MCR, &data);
1487 static int get_serial_info(struct moschip_port *mos7720_port,
1488 struct serial_struct __user *retinfo)
1490 struct serial_struct tmp;
1495 memset(&tmp, 0, sizeof(tmp));
1497 tmp.type = PORT_16550A;
1498 tmp.line = mos7720_port->port->serial->minor;
1499 tmp.port = mos7720_port->port->number;
1501 tmp.flags = ASYNC_SKIP_TEST | ASYNC_AUTO_IRQ;
1502 tmp.xmit_fifo_size = NUM_URBS * URB_TRANSFER_BUFFER_SIZE;
1503 tmp.baud_base = 9600;
1504 tmp.close_delay = 5*HZ;
1505 tmp.closing_wait = 30*HZ;
1507 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
1512 static int mos7720_ioctl(struct tty_struct *tty, struct file *file,
1513 unsigned int cmd, unsigned long arg)
1515 struct usb_serial_port *port = tty->driver_data;
1516 struct moschip_port *mos7720_port;
1517 struct async_icount cnow;
1518 struct async_icount cprev;
1519 struct serial_icounter_struct icount;
1521 mos7720_port = usb_get_serial_port_data(port);
1522 if (mos7720_port == NULL)
1525 dbg("%s - port %d, cmd = 0x%x", __func__, port->number, cmd);
1529 dbg("%s (%d) TIOCSERGETLSR", __func__, port->number);
1530 return get_lsr_info(tty, mos7720_port,
1531 (unsigned int __user *)arg);
1534 /* FIXME: These should be using the mode methods */
1537 dbg("%s (%d) TIOCMSET/TIOCMBIC/TIOCMSET",
1538 __func__, port->number);
1539 return set_modem_info(mos7720_port, cmd,
1540 (unsigned int __user *)arg);
1543 dbg("%s (%d) TIOCGSERIAL", __func__, port->number);
1544 return get_serial_info(mos7720_port,
1545 (struct serial_struct __user *)arg);
1548 dbg("%s (%d) TIOCMIWAIT", __func__, port->number);
1549 cprev = mos7720_port->icount;
1551 if (signal_pending(current))
1552 return -ERESTARTSYS;
1553 cnow = mos7720_port->icount;
1554 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
1555 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts)
1556 return -EIO; /* no change => error */
1557 if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
1558 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
1559 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
1560 ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts))) {
1569 cnow = mos7720_port->icount;
1570 icount.cts = cnow.cts;
1571 icount.dsr = cnow.dsr;
1572 icount.rng = cnow.rng;
1573 icount.dcd = cnow.dcd;
1574 icount.rx = cnow.rx;
1575 icount.tx = cnow.tx;
1576 icount.frame = cnow.frame;
1577 icount.overrun = cnow.overrun;
1578 icount.parity = cnow.parity;
1579 icount.brk = cnow.brk;
1580 icount.buf_overrun = cnow.buf_overrun;
1582 dbg("%s (%d) TIOCGICOUNT RX=%d, TX=%d", __func__,
1583 port->number, icount.rx, icount.tx);
1584 if (copy_to_user((void __user *)arg, &icount, sizeof(icount)))
1589 return -ENOIOCTLCMD;
1592 static int mos7720_startup(struct usb_serial *serial)
1594 struct moschip_serial *mos7720_serial;
1595 struct moschip_port *mos7720_port;
1596 struct usb_device *dev;
1599 u16 product = le16_to_cpu(serial->dev->descriptor.idProduct);
1601 dbg("%s: Entering ..........", __func__);
1604 dbg("Invalid Handler");
1610 /* create our private serial structure */
1611 mos7720_serial = kzalloc(sizeof(struct moschip_serial), GFP_KERNEL);
1612 if (mos7720_serial == NULL) {
1613 dev_err(&dev->dev, "%s - Out of memory\n", __func__);
1617 usb_set_serial_data(serial, mos7720_serial);
1620 * The 7715 uses the first bulk in/out endpoint pair for the parallel
1621 * port, and the second for the serial port. Because the usbserial core
1622 * assumes both pairs are serial ports, we must engage in a bit of
1623 * subterfuge and swap the pointers for ports 0 and 1 in order to make
1624 * port 0 point to the serial port. However, both moschip devices use a
1625 * single interrupt-in endpoint for both ports (as mentioned a little
1626 * further down), and this endpoint was assigned to port 0. So after
1627 * the swap, we must copy the interrupt endpoint elements from port 1
1628 * (as newly assigned) to port 0, and null out port 1 pointers.
1630 if (product == MOSCHIP_DEVICE_ID_7715) {
1631 struct usb_serial_port *tmp = serial->port[0];
1632 serial->port[0] = serial->port[1];
1633 serial->port[1] = tmp;
1634 serial->port[0]->interrupt_in_urb = tmp->interrupt_in_urb;
1635 serial->port[0]->interrupt_in_buffer = tmp->interrupt_in_buffer;
1636 serial->port[0]->interrupt_in_endpointAddress =
1637 tmp->interrupt_in_endpointAddress;
1638 serial->port[1]->interrupt_in_urb = NULL;
1639 serial->port[1]->interrupt_in_buffer = NULL;
1642 /* we set up the pointers to the endpoints in the mos7720_open *
1643 * function, as the structures aren't created yet. */
1645 /* set up port private structures */
1646 for (i = 0; i < serial->num_ports; ++i) {
1647 mos7720_port = kzalloc(sizeof(struct moschip_port), GFP_KERNEL);
1648 if (mos7720_port == NULL) {
1649 dev_err(&dev->dev, "%s - Out of memory\n", __func__);
1650 usb_set_serial_data(serial, NULL);
1651 kfree(mos7720_serial);
1655 /* Initialize all port interrupt end point to port 0 int
1656 * endpoint. Our device has only one interrupt endpoint
1657 * common to all ports */
1658 serial->port[i]->interrupt_in_endpointAddress =
1659 serial->port[0]->interrupt_in_endpointAddress;
1661 mos7720_port->port = serial->port[i];
1662 usb_set_serial_port_data(serial->port[i], mos7720_port);
1664 dbg("port number is %d", serial->port[i]->number);
1665 dbg("serial number is %d", serial->minor);
1669 /* setting configuration feature to one */
1670 usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
1671 (__u8)0x03, 0x00, 0x01, 0x00, NULL, 0x00, 5*HZ);
1673 /* LSR For Port 1 */
1674 send_mos_cmd(serial, MOS_READ, 0x00, UART_LSR, &data);
1675 dbg("LSR:%x", data);
1677 /* LSR For Port 2 */
1678 send_mos_cmd(serial, MOS_READ, 0x01, UART_LSR, &data);
1679 dbg("LSR:%x", data);
1684 static void mos7720_release(struct usb_serial *serial)
1688 /* free private structure allocated for serial port */
1689 for (i = 0; i < serial->num_ports; ++i)
1690 kfree(usb_get_serial_port_data(serial->port[i]));
1692 /* free private structure allocated for serial device */
1693 kfree(usb_get_serial_data(serial));
1696 static struct usb_driver usb_driver = {
1697 .name = "moschip7720",
1698 .probe = usb_serial_probe,
1699 .disconnect = usb_serial_disconnect,
1700 .id_table = moschip_port_id_table,
1704 static struct usb_serial_driver moschip7720_2port_driver = {
1706 .owner = THIS_MODULE,
1707 .name = "moschip7720",
1709 .description = "Moschip 2 port adapter",
1710 .usb_driver = &usb_driver,
1711 .id_table = moschip_port_id_table,
1712 .calc_num_ports = mos77xx_calc_num_ports,
1713 .open = mos7720_open,
1714 .close = mos7720_close,
1715 .throttle = mos7720_throttle,
1716 .unthrottle = mos7720_unthrottle,
1717 .probe = mos77xx_probe,
1718 .attach = mos7720_startup,
1719 .release = mos7720_release,
1720 .ioctl = mos7720_ioctl,
1721 .tiocmget = mos7720_tiocmget,
1722 .tiocmset = mos7720_tiocmset,
1723 .set_termios = mos7720_set_termios,
1724 .write = mos7720_write,
1725 .write_room = mos7720_write_room,
1726 .chars_in_buffer = mos7720_chars_in_buffer,
1727 .break_ctl = mos7720_break,
1728 .read_bulk_callback = mos7720_bulk_in_callback,
1729 .read_int_callback = NULL /* dynamically assigned in probe() */
1732 static int __init moschip7720_init(void)
1736 dbg("%s: Entering ..........", __func__);
1738 /* Register with the usb serial */
1739 retval = usb_serial_register(&moschip7720_2port_driver);
1741 goto failed_port_device_register;
1743 printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":"
1746 /* Register with the usb */
1747 retval = usb_register(&usb_driver);
1749 goto failed_usb_register;
1753 failed_usb_register:
1754 usb_serial_deregister(&moschip7720_2port_driver);
1756 failed_port_device_register:
1760 static void __exit moschip7720_exit(void)
1762 usb_deregister(&usb_driver);
1763 usb_serial_deregister(&moschip7720_2port_driver);
1766 module_init(moschip7720_init);
1767 module_exit(moschip7720_exit);
1769 /* Module information */
1770 MODULE_AUTHOR(DRIVER_AUTHOR);
1771 MODULE_DESCRIPTION(DRIVER_DESC);
1772 MODULE_LICENSE("GPL");
1774 module_param(debug, bool, S_IRUGO | S_IWUSR);
1775 MODULE_PARM_DESC(debug, "Debug enabled or not");