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_insert_flip_string(tty, data, urb->actual_length);
294 tty_flip_buffer_push(tty);
298 if (!port->read_urb) {
299 dbg("URB KILLED !!!");
303 if (port->read_urb->status != -EINPROGRESS) {
304 port->read_urb->dev = port->serial->dev;
306 retval = usb_submit_urb(port->read_urb, GFP_ATOMIC);
308 dbg("usb_submit_urb(read bulk) failed, retval = %d",
314 * mos7720_bulk_out_data_callback
315 * this is the callback function for when we have finished sending serial
316 * data on the bulk out endpoint.
318 static void mos7720_bulk_out_data_callback(struct urb *urb)
320 struct moschip_port *mos7720_port;
321 struct tty_struct *tty;
322 int status = urb->status;
325 dbg("nonzero write bulk status received:%d", status);
329 mos7720_port = urb->context;
331 dbg("NULL mos7720_port pointer");
335 dbg("Entering .........");
337 tty = tty_port_tty_get(&mos7720_port->port->port);
339 if (tty && mos7720_port->open)
346 * this function will be used for sending command to device
348 static int send_mos_cmd(struct usb_serial *serial, __u8 request, __u16 value,
349 __u16 index, u8 *data)
353 u16 product = le16_to_cpu(serial->dev->descriptor.idProduct);
355 if (value < MOS_MAX_PORT) {
356 if (product == MOSCHIP_DEVICE_ID_7715)
357 value = 0x0200; /* identifies the 7715's serial port */
359 value = value*0x100+0x200;
362 if ((product == MOSCHIP_DEVICE_ID_7715) &&
364 dbg("serial->product== MOSCHIP_DEVICE_ID_7715");
369 if (request == MOS_WRITE) {
370 value = value + *data;
371 status = usb_control_msg(serial->dev,
372 usb_sndctrlpipe(serial->dev, 0), MOS_WRITE,
373 0x40, value, index, NULL, 0, MOS_WDR_TIMEOUT);
375 buf = kmalloc(1, GFP_KERNEL);
380 status = usb_control_msg(serial->dev,
381 usb_rcvctrlpipe(serial->dev, 0), MOS_READ,
382 0xc0, value, index, buf, 1, MOS_WDR_TIMEOUT);
388 dbg("Command Write failed Value %x index %x", value, index);
396 * this function installs the appropriate read interrupt endpoint callback
397 * depending on whether the device is a 7720 or 7715, thus avoiding costly
398 * run-time checks in the high-frequency callback routine itself.
400 static int mos77xx_probe(struct usb_serial *serial,
401 const struct usb_device_id *id)
403 if (id->idProduct == MOSCHIP_DEVICE_ID_7715)
404 moschip7720_2port_driver.read_int_callback =
405 mos7715_interrupt_callback;
407 moschip7720_2port_driver.read_int_callback =
408 mos7720_interrupt_callback;
413 static int mos77xx_calc_num_ports(struct usb_serial *serial)
415 u16 product = le16_to_cpu(serial->dev->descriptor.idProduct);
416 if (product == MOSCHIP_DEVICE_ID_7715)
422 static int mos7720_open(struct tty_struct *tty, struct usb_serial_port *port)
424 struct usb_serial *serial;
425 struct usb_serial_port *port0;
427 struct moschip_serial *mos7720_serial;
428 struct moschip_port *mos7720_port;
432 int allocated_urbs = 0;
435 serial = port->serial;
437 mos7720_port = usb_get_serial_port_data(port);
438 if (mos7720_port == NULL)
441 port0 = serial->port[0];
443 mos7720_serial = usb_get_serial_data(serial);
445 if (mos7720_serial == NULL || port0 == NULL)
448 usb_clear_halt(serial->dev, port->write_urb->pipe);
449 usb_clear_halt(serial->dev, port->read_urb->pipe);
451 /* Initialising the write urb pool */
452 for (j = 0; j < NUM_URBS; ++j) {
453 urb = usb_alloc_urb(0, GFP_KERNEL);
454 mos7720_port->write_urb_pool[j] = urb;
457 dev_err(&port->dev, "No more urbs???\n");
461 urb->transfer_buffer = kmalloc(URB_TRANSFER_BUFFER_SIZE,
463 if (!urb->transfer_buffer) {
465 "%s-out of memory for urb buffers.\n",
467 usb_free_urb(mos7720_port->write_urb_pool[j]);
468 mos7720_port->write_urb_pool[j] = NULL;
477 /* Initialize MCS7720 -- Write Init values to corresponding Registers
489 * 0x08 : SP1/2 Control Reg
491 port_number = port->number - port->serial->minor;
492 send_mos_cmd(port->serial, MOS_READ, port_number, UART_LSR, &data);
493 dbg("SS::%p LSR:%x", mos7720_port, data);
495 dbg("Check:Sending Command ..........");
498 send_mos_cmd(serial, MOS_WRITE, MOS_MAX_PORT, 0x01, &data);
500 send_mos_cmd(serial, MOS_WRITE, MOS_MAX_PORT, 0x02, &data);
503 send_mos_cmd(serial, MOS_WRITE, port_number, 0x01, &data);
505 send_mos_cmd(serial, MOS_WRITE, port_number, 0x02, &data);
508 send_mos_cmd(serial, MOS_WRITE, port_number, 0x02, &data);
510 mos7720_port->shadowLCR = data;
511 send_mos_cmd(serial, MOS_WRITE, port_number, 0x03, &data);
513 mos7720_port->shadowMCR = data;
514 send_mos_cmd(serial, MOS_WRITE, port_number, 0x04, &data);
516 send_mos_cmd(serial, MOS_WRITE, port_number, 0x04, &data);
519 send_mos_cmd(serial, MOS_READ, MOS_MAX_PORT, 0x08, &data);
521 send_mos_cmd(serial, MOS_WRITE, MOS_MAX_PORT, 0x08, &data);
524 send_mos_cmd(serial, MOS_READ, MOS_MAX_PORT, port_number + 1, &data);
526 send_mos_cmd(serial, MOS_WRITE, MOS_MAX_PORT, port_number + 1, &data);
528 send_mos_cmd(port->serial, MOS_WRITE, MOS_MAX_PORT,
529 port_number + 1, &data);
532 send_mos_cmd(serial, MOS_READ, MOS_MAX_PORT, 0x08, &data);
534 data = data | (port->number - port->serial->minor + 1);
535 send_mos_cmd(serial, MOS_WRITE, MOS_MAX_PORT, 0x08, &data);
538 mos7720_port->shadowLCR = data;
539 send_mos_cmd(serial, MOS_WRITE, port_number, 0x03, &data);
541 send_mos_cmd(serial, MOS_WRITE, port_number, 0x00, &data);
543 send_mos_cmd(serial, MOS_WRITE, port_number, 0x01, &data);
545 mos7720_port->shadowLCR = data;
546 send_mos_cmd(serial, MOS_WRITE, port_number, 0x03, &data);
548 send_mos_cmd(serial, MOS_WRITE, port_number, 0x01, &data);
550 send_mos_cmd(serial, MOS_WRITE, port_number, 0x01, &data);
552 /* see if we've set up our endpoint info yet *
553 * (can't set it up in mos7720_startup as the *
554 * structures were not set up at that time.) */
555 if (!mos7720_serial->interrupt_started) {
556 dbg("Interrupt buffer NULL !!!");
558 /* not set up yet, so do it now */
559 mos7720_serial->interrupt_started = 1;
561 dbg("To Submit URB !!!");
563 /* set up our interrupt urb */
564 usb_fill_int_urb(port0->interrupt_in_urb, serial->dev,
565 usb_rcvintpipe(serial->dev,
566 port->interrupt_in_endpointAddress),
567 port0->interrupt_in_buffer,
568 port0->interrupt_in_urb->transfer_buffer_length,
569 mos7720_interrupt_callback, mos7720_port,
570 port0->interrupt_in_urb->interval);
572 /* start interrupt read for this mos7720 this interrupt *
573 * will continue as long as the mos7720 is connected */
574 dbg("Submit URB over !!!");
575 response = usb_submit_urb(port0->interrupt_in_urb, GFP_KERNEL);
578 "%s - Error %d submitting control urb\n",
582 /* set up our bulk in urb */
583 usb_fill_bulk_urb(port->read_urb, serial->dev,
584 usb_rcvbulkpipe(serial->dev,
585 port->bulk_in_endpointAddress),
586 port->bulk_in_buffer,
587 port->read_urb->transfer_buffer_length,
588 mos7720_bulk_in_callback, mos7720_port);
589 response = usb_submit_urb(port->read_urb, GFP_KERNEL);
591 dev_err(&port->dev, "%s - Error %d submitting read urb\n",
594 /* initialize our icount structure */
595 memset(&(mos7720_port->icount), 0x00, sizeof(mos7720_port->icount));
597 /* initialize our port settings */
598 mos7720_port->shadowMCR = UART_MCR_OUT2; /* Must set to enable ints! */
600 /* send a open port command */
601 mos7720_port->open = 1;
607 * mos7720_chars_in_buffer
608 * this function is called by the tty driver when it wants to know how many
609 * bytes of data we currently have outstanding in the port (data that has
610 * been written, but hasn't made it out the port yet)
611 * If successful, we return the number of bytes left to be written in the
613 * Otherwise we return a negative error number.
615 static int mos7720_chars_in_buffer(struct tty_struct *tty)
617 struct usb_serial_port *port = tty->driver_data;
620 struct moschip_port *mos7720_port;
622 dbg("%s:entering ...........", __func__);
624 mos7720_port = usb_get_serial_port_data(port);
625 if (mos7720_port == NULL) {
626 dbg("%s:leaving ...........", __func__);
630 for (i = 0; i < NUM_URBS; ++i) {
631 if (mos7720_port->write_urb_pool[i] &&
632 mos7720_port->write_urb_pool[i]->status == -EINPROGRESS)
633 chars += URB_TRANSFER_BUFFER_SIZE;
635 dbg("%s - returns %d", __func__, chars);
639 static void mos7720_close(struct usb_serial_port *port)
641 struct usb_serial *serial;
642 struct moschip_port *mos7720_port;
646 dbg("mos7720_close:entering...");
648 serial = port->serial;
650 mos7720_port = usb_get_serial_port_data(port);
651 if (mos7720_port == NULL)
654 for (j = 0; j < NUM_URBS; ++j)
655 usb_kill_urb(mos7720_port->write_urb_pool[j]);
657 /* Freeing Write URBs */
658 for (j = 0; j < NUM_URBS; ++j) {
659 if (mos7720_port->write_urb_pool[j]) {
660 kfree(mos7720_port->write_urb_pool[j]->transfer_buffer);
661 usb_free_urb(mos7720_port->write_urb_pool[j]);
665 /* While closing port, shutdown all bulk read, write *
666 * and interrupt read if they exists, otherwise nop */
667 dbg("Shutdown bulk write");
668 usb_kill_urb(port->write_urb);
669 dbg("Shutdown bulk read");
670 usb_kill_urb(port->read_urb);
672 mutex_lock(&serial->disc_mutex);
673 /* these commands must not be issued if the device has
674 * been disconnected */
675 if (!serial->disconnected) {
677 send_mos_cmd(serial, MOS_WRITE,
678 port->number - port->serial->minor, 0x04, &data);
681 send_mos_cmd(serial, MOS_WRITE,
682 port->number - port->serial->minor, 0x01, &data);
684 mutex_unlock(&serial->disc_mutex);
685 mos7720_port->open = 0;
687 dbg("Leaving %s", __func__);
690 static void mos7720_break(struct tty_struct *tty, int break_state)
692 struct usb_serial_port *port = tty->driver_data;
694 struct usb_serial *serial;
695 struct moschip_port *mos7720_port;
697 dbg("Entering %s", __func__);
699 serial = port->serial;
701 mos7720_port = usb_get_serial_port_data(port);
702 if (mos7720_port == NULL)
705 if (break_state == -1)
706 data = mos7720_port->shadowLCR | UART_LCR_SBC;
708 data = mos7720_port->shadowLCR & ~UART_LCR_SBC;
710 mos7720_port->shadowLCR = data;
711 send_mos_cmd(serial, MOS_WRITE, port->number - port->serial->minor,
719 * this function is called by the tty driver when it wants to know how many
720 * bytes of data we can accept for a specific port.
721 * If successful, we return the amount of room that we have for this port
722 * Otherwise we return a negative error number.
724 static int mos7720_write_room(struct tty_struct *tty)
726 struct usb_serial_port *port = tty->driver_data;
727 struct moschip_port *mos7720_port;
731 dbg("%s:entering ...........", __func__);
733 mos7720_port = usb_get_serial_port_data(port);
734 if (mos7720_port == NULL) {
735 dbg("%s:leaving ...........", __func__);
740 for (i = 0; i < NUM_URBS; ++i) {
741 if (mos7720_port->write_urb_pool[i] &&
742 mos7720_port->write_urb_pool[i]->status != -EINPROGRESS)
743 room += URB_TRANSFER_BUFFER_SIZE;
746 dbg("%s - returns %d", __func__, room);
750 static int mos7720_write(struct tty_struct *tty, struct usb_serial_port *port,
751 const unsigned char *data, int count)
758 struct moschip_port *mos7720_port;
759 struct usb_serial *serial;
761 const unsigned char *current_position = data;
763 dbg("%s:entering ...........", __func__);
765 serial = port->serial;
767 mos7720_port = usb_get_serial_port_data(port);
768 if (mos7720_port == NULL) {
769 dbg("mos7720_port is NULL");
773 /* try to find a free urb in the list */
776 for (i = 0; i < NUM_URBS; ++i) {
777 if (mos7720_port->write_urb_pool[i] &&
778 mos7720_port->write_urb_pool[i]->status != -EINPROGRESS) {
779 urb = mos7720_port->write_urb_pool[i];
786 dbg("%s - no more free urbs", __func__);
790 if (urb->transfer_buffer == NULL) {
791 urb->transfer_buffer = kmalloc(URB_TRANSFER_BUFFER_SIZE,
793 if (urb->transfer_buffer == NULL) {
794 dev_err(&port->dev, "%s no more kernel memory...\n",
799 transfer_size = min(count, URB_TRANSFER_BUFFER_SIZE);
801 memcpy(urb->transfer_buffer, current_position, transfer_size);
802 usb_serial_debug_data(debug, &port->dev, __func__, transfer_size,
803 urb->transfer_buffer);
805 /* fill urb with data and submit */
806 usb_fill_bulk_urb(urb, serial->dev,
807 usb_sndbulkpipe(serial->dev,
808 port->bulk_out_endpointAddress),
809 urb->transfer_buffer, transfer_size,
810 mos7720_bulk_out_data_callback, mos7720_port);
812 /* send it down the pipe */
813 status = usb_submit_urb(urb, GFP_ATOMIC);
815 dev_err(&port->dev, "%s - usb_submit_urb(write bulk) failed "
816 "with status = %d\n", __func__, status);
820 bytes_sent = transfer_size;
826 static void mos7720_throttle(struct tty_struct *tty)
828 struct usb_serial_port *port = tty->driver_data;
829 struct moschip_port *mos7720_port;
832 dbg("%s- port %d", __func__, port->number);
834 mos7720_port = usb_get_serial_port_data(port);
836 if (mos7720_port == NULL)
839 if (!mos7720_port->open) {
840 dbg("port not opened");
844 dbg("%s: Entering ..........", __func__);
846 /* if we are implementing XON/XOFF, send the stop character */
848 unsigned char stop_char = STOP_CHAR(tty);
849 status = mos7720_write(tty, port, &stop_char, 1);
854 /* if we are implementing RTS/CTS, toggle that line */
855 if (tty->termios->c_cflag & CRTSCTS) {
856 mos7720_port->shadowMCR &= ~UART_MCR_RTS;
857 status = send_mos_cmd(port->serial, MOS_WRITE,
858 port->number - port->serial->minor,
859 UART_MCR, &mos7720_port->shadowMCR);
865 static void mos7720_unthrottle(struct tty_struct *tty)
867 struct usb_serial_port *port = tty->driver_data;
868 struct moschip_port *mos7720_port = usb_get_serial_port_data(port);
871 if (mos7720_port == NULL)
874 if (!mos7720_port->open) {
875 dbg("%s - port not opened", __func__);
879 dbg("%s: Entering ..........", __func__);
881 /* if we are implementing XON/XOFF, send the start character */
883 unsigned char start_char = START_CHAR(tty);
884 status = mos7720_write(tty, port, &start_char, 1);
889 /* if we are implementing RTS/CTS, toggle that line */
890 if (tty->termios->c_cflag & CRTSCTS) {
891 mos7720_port->shadowMCR |= UART_MCR_RTS;
892 status = send_mos_cmd(port->serial, MOS_WRITE,
893 port->number - port->serial->minor,
894 UART_MCR, &mos7720_port->shadowMCR);
900 static int set_higher_rates(struct moschip_port *mos7720_port,
904 struct usb_serial_port *port;
905 struct usb_serial *serial;
908 if (mos7720_port == NULL)
911 port = mos7720_port->port;
912 serial = port->serial;
914 /***********************************************
915 * Init Sequence for higher rates
916 ***********************************************/
917 dbg("Sending Setting Commands ..........");
918 port_number = port->number - port->serial->minor;
921 send_mos_cmd(serial, MOS_WRITE, port_number, 0x01, &data);
923 send_mos_cmd(serial, MOS_WRITE, port_number, 0x02, &data);
925 send_mos_cmd(serial, MOS_WRITE, port->number, 0x02, &data);
927 mos7720_port->shadowMCR = data;
928 send_mos_cmd(serial, MOS_WRITE, port_number, 0x04, &data);
930 send_mos_cmd(serial, MOS_WRITE, port_number, 0x04, &data);
933 send_mos_cmd(serial, MOS_READ, MOS_MAX_PORT, 0x08, &data);
935 send_mos_cmd(serial, MOS_WRITE, MOS_MAX_PORT, 0x08, &data);
938 /***********************************************
939 * Set for higher rates *
940 ***********************************************/
943 send_mos_cmd(serial, MOS_WRITE, MOS_MAX_PORT, port_number + 1, &data);
946 send_mos_cmd(serial, MOS_READ, MOS_MAX_PORT, 0x08, &data);
948 send_mos_cmd(serial, MOS_WRITE, MOS_MAX_PORT, 0x08, &data);
951 mos7720_port->shadowMCR = data;
952 send_mos_cmd(serial, MOS_WRITE, port_number, 0x04, &data);
954 send_mos_cmd(serial, MOS_WRITE, port_number, 0x04, &data);
956 /***********************************************
958 ***********************************************/
960 data = mos7720_port->shadowLCR | UART_LCR_DLAB;
961 mos7720_port->shadowLCR = data;
962 send_mos_cmd(serial, MOS_WRITE, port_number, 0x03, &data);
964 data = 0x001; /* DLL */
965 send_mos_cmd(serial, MOS_WRITE, port_number, 0x00, &data);
966 data = 0x000; /* DLM */
967 send_mos_cmd(serial, MOS_WRITE, port_number, 0x01, &data);
969 data = mos7720_port->shadowLCR & ~UART_LCR_DLAB;
970 mos7720_port->shadowLCR = data;
971 send_mos_cmd(serial, MOS_WRITE, port_number, 0x03, &data);
976 /* baud rate information */
977 struct divisor_table_entry {
982 /* Define table of divisors for moschip 7720 hardware *
983 * These assume a 3.6864MHz crystal, the standard /16, and *
985 static struct divisor_table_entry divisor_table[] = {
987 { 110, 1047}, /* 2094.545455 => 230450 => .0217 % over */
988 { 134, 857}, /* 1713.011152 => 230398.5 => .00065% under */
1004 /*****************************************************************************
1005 * calc_baud_rate_divisor
1006 * this function calculates the proper baud rate divisor for the specified
1008 *****************************************************************************/
1009 static int calc_baud_rate_divisor(int baudrate, int *divisor)
1017 dbg("%s - %d", __func__, baudrate);
1019 for (i = 0; i < ARRAY_SIZE(divisor_table); i++) {
1020 if (divisor_table[i].baudrate == baudrate) {
1021 *divisor = divisor_table[i].divisor;
1026 /* After trying for all the standard baud rates *
1027 * Try calculating the divisor for this baud rate */
1028 if (baudrate > 75 && baudrate < 230400) {
1029 /* get the divisor */
1030 custom = (__u16)(230400L / baudrate);
1032 /* Check for round off */
1033 round1 = (__u16)(2304000L / baudrate);
1034 round = (__u16)(round1 - (custom * 10));
1039 dbg("Baud %d = %d", baudrate, custom);
1043 dbg("Baud calculation Failed...");
1048 * send_cmd_write_baud_rate
1049 * this function sends the proper command to change the baud rate of the
1052 static int send_cmd_write_baud_rate(struct moschip_port *mos7720_port,
1055 struct usb_serial_port *port;
1056 struct usb_serial *serial;
1060 unsigned char number;
1062 if (mos7720_port == NULL)
1065 port = mos7720_port->port;
1066 serial = port->serial;
1068 dbg("%s: Entering ..........", __func__);
1070 number = port->number - port->serial->minor;
1071 dbg("%s - port = %d, baud = %d", __func__, port->number, baudrate);
1073 /* Calculate the Divisor */
1074 status = calc_baud_rate_divisor(baudrate, &divisor);
1076 dev_err(&port->dev, "%s - bad baud rate\n", __func__);
1080 /* Enable access to divisor latch */
1081 data = mos7720_port->shadowLCR | UART_LCR_DLAB;
1082 mos7720_port->shadowLCR = data;
1083 send_mos_cmd(serial, MOS_WRITE, number, UART_LCR, &data);
1085 /* Write the divisor */
1086 data = ((unsigned char)(divisor & 0xff));
1087 send_mos_cmd(serial, MOS_WRITE, number, 0x00, &data);
1089 data = ((unsigned char)((divisor & 0xff00) >> 8));
1090 send_mos_cmd(serial, MOS_WRITE, number, 0x01, &data);
1092 /* Disable access to divisor latch */
1093 data = mos7720_port->shadowLCR & ~UART_LCR_DLAB;
1094 mos7720_port->shadowLCR = data;
1095 send_mos_cmd(serial, MOS_WRITE, number, 0x03, &data);
1101 * change_port_settings
1102 * This routine is called to set the UART on the device to match
1103 * the specified new settings.
1105 static void change_port_settings(struct tty_struct *tty,
1106 struct moschip_port *mos7720_port,
1107 struct ktermios *old_termios)
1109 struct usb_serial_port *port;
1110 struct usb_serial *serial;
1122 if (mos7720_port == NULL)
1125 port = mos7720_port->port;
1126 serial = port->serial;
1127 port_number = port->number - port->serial->minor;
1129 dbg("%s - port %d", __func__, port->number);
1131 if (!mos7720_port->open) {
1132 dbg("%s - port not opened", __func__);
1136 dbg("%s: Entering ..........", __func__);
1138 lData = UART_LCR_WLEN8;
1139 lStop = 0x00; /* 1 stop bit */
1140 lParity = 0x00; /* No parity */
1142 cflag = tty->termios->c_cflag;
1143 iflag = tty->termios->c_iflag;
1145 /* Change the number of bits */
1146 switch (cflag & CSIZE) {
1148 lData = UART_LCR_WLEN5;
1153 lData = UART_LCR_WLEN6;
1158 lData = UART_LCR_WLEN7;
1163 lData = UART_LCR_WLEN8;
1167 /* Change the Parity bit */
1168 if (cflag & PARENB) {
1169 if (cflag & PARODD) {
1170 lParity = UART_LCR_PARITY;
1171 dbg("%s - parity = odd", __func__);
1173 lParity = (UART_LCR_EPAR | UART_LCR_PARITY);
1174 dbg("%s - parity = even", __func__);
1178 dbg("%s - parity = none", __func__);
1182 lParity = lParity | 0x20;
1184 /* Change the Stop bit */
1185 if (cflag & CSTOPB) {
1186 lStop = UART_LCR_STOP;
1187 dbg("%s - stop bits = 2", __func__);
1190 dbg("%s - stop bits = 1", __func__);
1193 #define LCR_BITS_MASK 0x03 /* Mask for bits/char field */
1194 #define LCR_STOP_MASK 0x04 /* Mask for stop bits field */
1195 #define LCR_PAR_MASK 0x38 /* Mask for parity field */
1197 /* Update the LCR with the correct value */
1198 mos7720_port->shadowLCR &=
1199 ~(LCR_BITS_MASK | LCR_STOP_MASK | LCR_PAR_MASK);
1200 mos7720_port->shadowLCR |= (lData | lParity | lStop);
1203 /* Disable Interrupts */
1205 send_mos_cmd(serial, MOS_WRITE, port->number - port->serial->minor,
1209 send_mos_cmd(serial, MOS_WRITE, port_number, UART_FCR, &data);
1212 send_mos_cmd(serial, MOS_WRITE, port_number, UART_FCR, &data);
1214 /* Send the updated LCR value to the mos7720 */
1215 data = mos7720_port->shadowLCR;
1216 send_mos_cmd(serial, MOS_WRITE, port_number, UART_LCR, &data);
1219 mos7720_port->shadowMCR = data;
1220 send_mos_cmd(serial, MOS_WRITE, port_number, 0x04, &data);
1222 send_mos_cmd(serial, MOS_WRITE, port_number, 0x04, &data);
1224 /* set up the MCR register and send it to the mos7720 */
1225 mos7720_port->shadowMCR = UART_MCR_OUT2;
1227 mos7720_port->shadowMCR |= (UART_MCR_DTR | UART_MCR_RTS);
1229 if (cflag & CRTSCTS) {
1230 mos7720_port->shadowMCR |= (UART_MCR_XONANY);
1231 /* To set hardware flow control to the specified *
1232 * serial port, in SP1/2_CONTROL_REG */
1235 send_mos_cmd(serial, MOS_WRITE, MOS_MAX_PORT,
1239 send_mos_cmd(serial, MOS_WRITE, MOS_MAX_PORT,
1243 mos7720_port->shadowMCR &= ~(UART_MCR_XONANY);
1246 data = mos7720_port->shadowMCR;
1247 send_mos_cmd(serial, MOS_WRITE, port_number, UART_MCR, &data);
1249 /* Determine divisor based on baud rate */
1250 baud = tty_get_baud_rate(tty);
1252 /* pick a default, any default... */
1253 dbg("Picked default baud...");
1257 if (baud >= 230400) {
1258 set_higher_rates(mos7720_port, baud);
1259 /* Enable Interrupts */
1261 send_mos_cmd(serial, MOS_WRITE, port_number, UART_IER, &data);
1265 dbg("%s - baud rate = %d", __func__, baud);
1266 status = send_cmd_write_baud_rate(mos7720_port, baud);
1267 /* FIXME: needs to write actual resulting baud back not just
1270 tty_encode_baud_rate(tty, baud, baud);
1271 /* Enable Interrupts */
1273 send_mos_cmd(serial, MOS_WRITE, port_number, UART_IER, &data);
1275 if (port->read_urb->status != -EINPROGRESS) {
1276 port->read_urb->dev = serial->dev;
1278 status = usb_submit_urb(port->read_urb, GFP_ATOMIC);
1280 dbg("usb_submit_urb(read bulk) failed, status = %d",
1287 * mos7720_set_termios
1288 * this function is called by the tty driver when it wants to change the
1289 * termios structure.
1291 static void mos7720_set_termios(struct tty_struct *tty,
1292 struct usb_serial_port *port, struct ktermios *old_termios)
1296 struct usb_serial *serial;
1297 struct moschip_port *mos7720_port;
1299 serial = port->serial;
1301 mos7720_port = usb_get_serial_port_data(port);
1303 if (mos7720_port == NULL)
1306 if (!mos7720_port->open) {
1307 dbg("%s - port not opened", __func__);
1311 dbg("setting termios - ASPIRE");
1313 cflag = tty->termios->c_cflag;
1315 dbg("%s - cflag %08x iflag %08x", __func__,
1316 tty->termios->c_cflag,
1317 RELEVANT_IFLAG(tty->termios->c_iflag));
1319 dbg("%s - old cflag %08x old iflag %08x", __func__,
1320 old_termios->c_cflag,
1321 RELEVANT_IFLAG(old_termios->c_iflag));
1323 dbg("%s - port %d", __func__, port->number);
1325 /* change the port settings to the new ones specified */
1326 change_port_settings(tty, mos7720_port, old_termios);
1328 if (!port->read_urb) {
1329 dbg("URB KILLED !!!!!");
1333 if (port->read_urb->status != -EINPROGRESS) {
1334 port->read_urb->dev = serial->dev;
1335 status = usb_submit_urb(port->read_urb, GFP_ATOMIC);
1337 dbg("usb_submit_urb(read bulk) failed, status = %d",
1344 * get_lsr_info - get line status register info
1346 * Purpose: Let user call ioctl() to get info when the UART physically
1347 * is emptied. On bus types like RS485, the transmitter must
1348 * release the bus after transmitting. This must be done when
1349 * the transmit shift register is empty, not be done when the
1350 * transmit holding register is empty. This functionality
1351 * allows an RS485 driver to be written in user space.
1353 static int get_lsr_info(struct tty_struct *tty,
1354 struct moschip_port *mos7720_port, unsigned int __user *value)
1356 struct usb_serial_port *port = tty->driver_data;
1357 unsigned int result = 0;
1358 unsigned char data = 0;
1359 int port_number = port->number - port->serial->minor;
1362 count = mos7720_chars_in_buffer(tty);
1364 send_mos_cmd(port->serial, MOS_READ, port_number,
1366 if ((data & (UART_LSR_TEMT | UART_LSR_THRE))
1367 == (UART_LSR_TEMT | UART_LSR_THRE)) {
1368 dbg("%s -- Empty", __func__);
1369 result = TIOCSER_TEMT;
1372 if (copy_to_user(value, &result, sizeof(int)))
1377 static int mos7720_tiocmget(struct tty_struct *tty, struct file *file)
1379 struct usb_serial_port *port = tty->driver_data;
1380 struct moschip_port *mos7720_port = usb_get_serial_port_data(port);
1381 unsigned int result = 0;
1385 dbg("%s - port %d", __func__, port->number);
1387 mcr = mos7720_port->shadowMCR;
1388 msr = mos7720_port->shadowMSR;
1390 result = ((mcr & UART_MCR_DTR) ? TIOCM_DTR : 0) /* 0x002 */
1391 | ((mcr & UART_MCR_RTS) ? TIOCM_RTS : 0) /* 0x004 */
1392 | ((msr & UART_MSR_CTS) ? TIOCM_CTS : 0) /* 0x020 */
1393 | ((msr & UART_MSR_DCD) ? TIOCM_CAR : 0) /* 0x040 */
1394 | ((msr & UART_MSR_RI) ? TIOCM_RI : 0) /* 0x080 */
1395 | ((msr & UART_MSR_DSR) ? TIOCM_DSR : 0); /* 0x100 */
1397 dbg("%s -- %x", __func__, result);
1402 static int mos7720_tiocmset(struct tty_struct *tty, struct file *file,
1403 unsigned int set, unsigned int clear)
1405 struct usb_serial_port *port = tty->driver_data;
1406 struct moschip_port *mos7720_port = usb_get_serial_port_data(port);
1410 dbg("%s - port %d", __func__, port->number);
1411 dbg("he was at tiocmget");
1413 mcr = mos7720_port->shadowMCR;
1415 if (set & TIOCM_RTS)
1416 mcr |= UART_MCR_RTS;
1417 if (set & TIOCM_DTR)
1418 mcr |= UART_MCR_DTR;
1419 if (set & TIOCM_LOOP)
1420 mcr |= UART_MCR_LOOP;
1422 if (clear & TIOCM_RTS)
1423 mcr &= ~UART_MCR_RTS;
1424 if (clear & TIOCM_DTR)
1425 mcr &= ~UART_MCR_DTR;
1426 if (clear & TIOCM_LOOP)
1427 mcr &= ~UART_MCR_LOOP;
1429 mos7720_port->shadowMCR = mcr;
1430 lmcr = mos7720_port->shadowMCR;
1432 send_mos_cmd(port->serial, MOS_WRITE,
1433 port->number - port->serial->minor, UART_MCR, &lmcr);
1438 static int set_modem_info(struct moschip_port *mos7720_port, unsigned int cmd,
1439 unsigned int __user *value)
1445 struct usb_serial_port *port;
1447 if (mos7720_port == NULL)
1450 port = (struct usb_serial_port *)mos7720_port->port;
1451 mcr = mos7720_port->shadowMCR;
1453 if (copy_from_user(&arg, value, sizeof(int)))
1458 if (arg & TIOCM_RTS)
1459 mcr |= UART_MCR_RTS;
1460 if (arg & TIOCM_DTR)
1461 mcr |= UART_MCR_RTS;
1462 if (arg & TIOCM_LOOP)
1463 mcr |= UART_MCR_LOOP;
1467 if (arg & TIOCM_RTS)
1468 mcr &= ~UART_MCR_RTS;
1469 if (arg & TIOCM_DTR)
1470 mcr &= ~UART_MCR_RTS;
1471 if (arg & TIOCM_LOOP)
1472 mcr &= ~UART_MCR_LOOP;
1477 mos7720_port->shadowMCR = mcr;
1479 data = mos7720_port->shadowMCR;
1480 send_mos_cmd(port->serial, MOS_WRITE,
1481 port->number - port->serial->minor, UART_MCR, &data);
1486 static int get_serial_info(struct moschip_port *mos7720_port,
1487 struct serial_struct __user *retinfo)
1489 struct serial_struct tmp;
1494 memset(&tmp, 0, sizeof(tmp));
1496 tmp.type = PORT_16550A;
1497 tmp.line = mos7720_port->port->serial->minor;
1498 tmp.port = mos7720_port->port->number;
1500 tmp.flags = ASYNC_SKIP_TEST | ASYNC_AUTO_IRQ;
1501 tmp.xmit_fifo_size = NUM_URBS * URB_TRANSFER_BUFFER_SIZE;
1502 tmp.baud_base = 9600;
1503 tmp.close_delay = 5*HZ;
1504 tmp.closing_wait = 30*HZ;
1506 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
1511 static int mos7720_ioctl(struct tty_struct *tty, struct file *file,
1512 unsigned int cmd, unsigned long arg)
1514 struct usb_serial_port *port = tty->driver_data;
1515 struct moschip_port *mos7720_port;
1516 struct async_icount cnow;
1517 struct async_icount cprev;
1518 struct serial_icounter_struct icount;
1520 mos7720_port = usb_get_serial_port_data(port);
1521 if (mos7720_port == NULL)
1524 dbg("%s - port %d, cmd = 0x%x", __func__, port->number, cmd);
1528 dbg("%s (%d) TIOCSERGETLSR", __func__, port->number);
1529 return get_lsr_info(tty, mos7720_port,
1530 (unsigned int __user *)arg);
1533 /* FIXME: These should be using the mode methods */
1536 dbg("%s (%d) TIOCMSET/TIOCMBIC/TIOCMSET",
1537 __func__, port->number);
1538 return set_modem_info(mos7720_port, cmd,
1539 (unsigned int __user *)arg);
1542 dbg("%s (%d) TIOCGSERIAL", __func__, port->number);
1543 return get_serial_info(mos7720_port,
1544 (struct serial_struct __user *)arg);
1547 dbg("%s (%d) TIOCMIWAIT", __func__, port->number);
1548 cprev = mos7720_port->icount;
1550 if (signal_pending(current))
1551 return -ERESTARTSYS;
1552 cnow = mos7720_port->icount;
1553 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
1554 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts)
1555 return -EIO; /* no change => error */
1556 if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
1557 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
1558 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
1559 ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts))) {
1568 cnow = mos7720_port->icount;
1569 icount.cts = cnow.cts;
1570 icount.dsr = cnow.dsr;
1571 icount.rng = cnow.rng;
1572 icount.dcd = cnow.dcd;
1573 icount.rx = cnow.rx;
1574 icount.tx = cnow.tx;
1575 icount.frame = cnow.frame;
1576 icount.overrun = cnow.overrun;
1577 icount.parity = cnow.parity;
1578 icount.brk = cnow.brk;
1579 icount.buf_overrun = cnow.buf_overrun;
1581 dbg("%s (%d) TIOCGICOUNT RX=%d, TX=%d", __func__,
1582 port->number, icount.rx, icount.tx);
1583 if (copy_to_user((void __user *)arg, &icount, sizeof(icount)))
1588 return -ENOIOCTLCMD;
1591 static int mos7720_startup(struct usb_serial *serial)
1593 struct moschip_serial *mos7720_serial;
1594 struct moschip_port *mos7720_port;
1595 struct usb_device *dev;
1598 u16 product = le16_to_cpu(serial->dev->descriptor.idProduct);
1600 dbg("%s: Entering ..........", __func__);
1603 dbg("Invalid Handler");
1609 /* create our private serial structure */
1610 mos7720_serial = kzalloc(sizeof(struct moschip_serial), GFP_KERNEL);
1611 if (mos7720_serial == NULL) {
1612 dev_err(&dev->dev, "%s - Out of memory\n", __func__);
1616 usb_set_serial_data(serial, mos7720_serial);
1619 * The 7715 uses the first bulk in/out endpoint pair for the parallel
1620 * port, and the second for the serial port. Because the usbserial core
1621 * assumes both pairs are serial ports, we must engage in a bit of
1622 * subterfuge and swap the pointers for ports 0 and 1 in order to make
1623 * port 0 point to the serial port. However, both moschip devices use a
1624 * single interrupt-in endpoint for both ports (as mentioned a little
1625 * further down), and this endpoint was assigned to port 0. So after
1626 * the swap, we must copy the interrupt endpoint elements from port 1
1627 * (as newly assigned) to port 0, and null out port 1 pointers.
1629 if (product == MOSCHIP_DEVICE_ID_7715) {
1630 struct usb_serial_port *tmp = serial->port[0];
1631 serial->port[0] = serial->port[1];
1632 serial->port[1] = tmp;
1633 serial->port[0]->interrupt_in_urb = tmp->interrupt_in_urb;
1634 serial->port[0]->interrupt_in_buffer = tmp->interrupt_in_buffer;
1635 serial->port[0]->interrupt_in_endpointAddress =
1636 tmp->interrupt_in_endpointAddress;
1637 serial->port[1]->interrupt_in_urb = NULL;
1638 serial->port[1]->interrupt_in_buffer = NULL;
1641 /* we set up the pointers to the endpoints in the mos7720_open *
1642 * function, as the structures aren't created yet. */
1644 /* set up port private structures */
1645 for (i = 0; i < serial->num_ports; ++i) {
1646 mos7720_port = kzalloc(sizeof(struct moschip_port), GFP_KERNEL);
1647 if (mos7720_port == NULL) {
1648 dev_err(&dev->dev, "%s - Out of memory\n", __func__);
1649 usb_set_serial_data(serial, NULL);
1650 kfree(mos7720_serial);
1654 /* Initialize all port interrupt end point to port 0 int
1655 * endpoint. Our device has only one interrupt endpoint
1656 * common to all ports */
1657 serial->port[i]->interrupt_in_endpointAddress =
1658 serial->port[0]->interrupt_in_endpointAddress;
1660 mos7720_port->port = serial->port[i];
1661 usb_set_serial_port_data(serial->port[i], mos7720_port);
1663 dbg("port number is %d", serial->port[i]->number);
1664 dbg("serial number is %d", serial->minor);
1668 /* setting configuration feature to one */
1669 usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
1670 (__u8)0x03, 0x00, 0x01, 0x00, NULL, 0x00, 5*HZ);
1672 /* LSR For Port 1 */
1673 send_mos_cmd(serial, MOS_READ, 0x00, UART_LSR, &data);
1674 dbg("LSR:%x", data);
1676 /* LSR For Port 2 */
1677 send_mos_cmd(serial, MOS_READ, 0x01, UART_LSR, &data);
1678 dbg("LSR:%x", data);
1683 static void mos7720_release(struct usb_serial *serial)
1687 /* free private structure allocated for serial port */
1688 for (i = 0; i < serial->num_ports; ++i)
1689 kfree(usb_get_serial_port_data(serial->port[i]));
1691 /* free private structure allocated for serial device */
1692 kfree(usb_get_serial_data(serial));
1695 static struct usb_driver usb_driver = {
1696 .name = "moschip7720",
1697 .probe = usb_serial_probe,
1698 .disconnect = usb_serial_disconnect,
1699 .id_table = moschip_port_id_table,
1703 static struct usb_serial_driver moschip7720_2port_driver = {
1705 .owner = THIS_MODULE,
1706 .name = "moschip7720",
1708 .description = "Moschip 2 port adapter",
1709 .usb_driver = &usb_driver,
1710 .id_table = moschip_port_id_table,
1711 .calc_num_ports = mos77xx_calc_num_ports,
1712 .open = mos7720_open,
1713 .close = mos7720_close,
1714 .throttle = mos7720_throttle,
1715 .unthrottle = mos7720_unthrottle,
1716 .probe = mos77xx_probe,
1717 .attach = mos7720_startup,
1718 .release = mos7720_release,
1719 .ioctl = mos7720_ioctl,
1720 .tiocmget = mos7720_tiocmget,
1721 .tiocmset = mos7720_tiocmset,
1722 .set_termios = mos7720_set_termios,
1723 .write = mos7720_write,
1724 .write_room = mos7720_write_room,
1725 .chars_in_buffer = mos7720_chars_in_buffer,
1726 .break_ctl = mos7720_break,
1727 .read_bulk_callback = mos7720_bulk_in_callback,
1728 .read_int_callback = NULL /* dynamically assigned in probe() */
1731 static int __init moschip7720_init(void)
1735 dbg("%s: Entering ..........", __func__);
1737 /* Register with the usb serial */
1738 retval = usb_serial_register(&moschip7720_2port_driver);
1740 goto failed_port_device_register;
1742 printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":"
1745 /* Register with the usb */
1746 retval = usb_register(&usb_driver);
1748 goto failed_usb_register;
1752 failed_usb_register:
1753 usb_serial_deregister(&moschip7720_2port_driver);
1755 failed_port_device_register:
1759 static void __exit moschip7720_exit(void)
1761 usb_deregister(&usb_driver);
1762 usb_serial_deregister(&moschip7720_2port_driver);
1765 module_init(moschip7720_init);
1766 module_exit(moschip7720_exit);
1768 /* Module information */
1769 MODULE_AUTHOR(DRIVER_AUTHOR);
1770 MODULE_DESCRIPTION(DRIVER_DESC);
1771 MODULE_LICENSE("GPL");
1773 module_param(debug, bool, S_IRUGO | S_IWUSR);
1774 MODULE_PARM_DESC(debug, "Debug enabled or not");