aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/serial/mos7840.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/serial/mos7840.c')
-rw-r--r--drivers/usb/serial/mos7840.c557
1 files changed, 226 insertions, 331 deletions
diff --git a/drivers/usb/serial/mos7840.c b/drivers/usb/serial/mos7840.c
index 78f2f6db494d..09d82062b973 100644
--- a/drivers/usb/serial/mos7840.c
+++ b/drivers/usb/serial/mos7840.c
@@ -33,7 +33,7 @@
33#include <linux/serial.h> 33#include <linux/serial.h>
34#include <linux/usb.h> 34#include <linux/usb.h>
35#include <linux/usb/serial.h> 35#include <linux/usb/serial.h>
36#include <asm/uaccess.h> 36#include <linux/uaccess.h>
37 37
38/* 38/*
39 * Version Information 39 * Version Information
@@ -82,8 +82,8 @@
82 * Defines used for sending commands to port 82 * Defines used for sending commands to port
83 */ 83 */
84 84
85#define WAIT_FOR_EVER (HZ * 0 ) /* timeout urb is wait for ever */ 85#define WAIT_FOR_EVER (HZ * 0) /* timeout urb is wait for ever */
86#define MOS_WDR_TIMEOUT (HZ * 5 ) /* default urb timeout */ 86#define MOS_WDR_TIMEOUT (HZ * 5) /* default urb timeout */
87 87
88#define MOS_PORT1 0x0200 88#define MOS_PORT1 0x0200
89#define MOS_PORT2 0x0300 89#define MOS_PORT2 0x0300
@@ -102,8 +102,8 @@
102 102
103#define MAX_NAME_LEN 64 103#define MAX_NAME_LEN 64
104 104
105#define ZLP_REG1 0x3A //Zero_Flag_Reg1 58 105#define ZLP_REG1 0x3A /* Zero_Flag_Reg1 58 */
106#define ZLP_REG5 0x3E //Zero_Flag_Reg5 62 106#define ZLP_REG5 0x3E /* Zero_Flag_Reg5 62 */
107 107
108/* For higher baud Rates use TIOCEXBAUD */ 108/* For higher baud Rates use TIOCEXBAUD */
109#define TIOCEXBAUD 0x5462 109#define TIOCEXBAUD 0x5462
@@ -142,7 +142,7 @@
142#define MOS_MSR_DELTA_RI 0x40 142#define MOS_MSR_DELTA_RI 0x40
143#define MOS_MSR_DELTA_CD 0x80 143#define MOS_MSR_DELTA_CD 0x80
144 144
145// Serial Port register Address 145/* Serial Port register Address */
146#define INTERRUPT_ENABLE_REGISTER ((__u16)(0x01)) 146#define INTERRUPT_ENABLE_REGISTER ((__u16)(0x01))
147#define FIFO_CONTROL_REGISTER ((__u16)(0x02)) 147#define FIFO_CONTROL_REGISTER ((__u16)(0x02))
148#define LINE_CONTROL_REGISTER ((__u16)(0x03)) 148#define LINE_CONTROL_REGISTER ((__u16)(0x03))
@@ -201,11 +201,11 @@ struct moschip_port {
201 struct async_icount icount; 201 struct async_icount icount;
202 struct usb_serial_port *port; /* loop back to the owner of this object */ 202 struct usb_serial_port *port; /* loop back to the owner of this object */
203 203
204 /*Offsets */ 204 /* Offsets */
205 __u8 SpRegOffset; 205 __u8 SpRegOffset;
206 __u8 ControlRegOffset; 206 __u8 ControlRegOffset;
207 __u8 DcrRegOffset; 207 __u8 DcrRegOffset;
208 //for processing control URBS in interrupt context 208 /* for processing control URBS in interrupt context */
209 struct urb *control_urb; 209 struct urb *control_urb;
210 struct usb_ctrlrequest *dr; 210 struct usb_ctrlrequest *dr;
211 char *ctrl_buf; 211 char *ctrl_buf;
@@ -244,7 +244,7 @@ static int mos7840_set_reg_sync(struct usb_serial_port *port, __u16 reg,
244 */ 244 */
245 245
246static int mos7840_get_reg_sync(struct usb_serial_port *port, __u16 reg, 246static int mos7840_get_reg_sync(struct usb_serial_port *port, __u16 reg,
247 __u16 * val) 247 __u16 *val)
248{ 248{
249 struct usb_device *dev = port->serial->dev; 249 struct usb_device *dev = port->serial->dev;
250 int ret = 0; 250 int ret = 0;
@@ -269,16 +269,15 @@ static int mos7840_set_uart_reg(struct usb_serial_port *port, __u16 reg,
269 269
270 struct usb_device *dev = port->serial->dev; 270 struct usb_device *dev = port->serial->dev;
271 val = val & 0x00ff; 271 val = val & 0x00ff;
272 // For the UART control registers, the application number need to be Or'ed 272 /* For the UART control registers, the application number need
273 to be Or'ed */
273 if (port->serial->num_ports == 4) { 274 if (port->serial->num_ports == 4) {
274 val |= 275 val |= (((__u16) port->number -
275 (((__u16) port->number - (__u16) (port->serial->minor)) + 276 (__u16) (port->serial->minor)) + 1) << 8;
276 1) << 8;
277 dbg("mos7840_set_uart_reg application number is %x\n", val); 277 dbg("mos7840_set_uart_reg application number is %x\n", val);
278 } else { 278 } else {
279 if (((__u16) port->number - (__u16) (port->serial->minor)) == 0) { 279 if (((__u16) port->number - (__u16) (port->serial->minor)) == 0) {
280 val |= 280 val |= (((__u16) port->number -
281 (((__u16) port->number -
282 (__u16) (port->serial->minor)) + 1) << 8; 281 (__u16) (port->serial->minor)) + 1) << 8;
283 dbg("mos7840_set_uart_reg application number is %x\n", 282 dbg("mos7840_set_uart_reg application number is %x\n",
284 val); 283 val);
@@ -302,14 +301,15 @@ static int mos7840_set_uart_reg(struct usb_serial_port *port, __u16 reg,
302 * by passing usb_rcvctrlpipe function as parameter. 301 * by passing usb_rcvctrlpipe function as parameter.
303 */ 302 */
304static int mos7840_get_uart_reg(struct usb_serial_port *port, __u16 reg, 303static int mos7840_get_uart_reg(struct usb_serial_port *port, __u16 reg,
305 __u16 * val) 304 __u16 *val)
306{ 305{
307 struct usb_device *dev = port->serial->dev; 306 struct usb_device *dev = port->serial->dev;
308 int ret = 0; 307 int ret = 0;
309 __u16 Wval; 308 __u16 Wval;
310 309
311 //dbg("application number is %4x \n",(((__u16)port->number - (__u16)(port->serial->minor))+1)<<8); 310 /* dbg("application number is %4x \n",
312 /*Wval is same as application number */ 311 (((__u16)port->number - (__u16)(port->serial->minor))+1)<<8); */
312 /* Wval is same as application number */
313 if (port->serial->num_ports == 4) { 313 if (port->serial->num_ports == 4) {
314 Wval = 314 Wval =
315 (((__u16) port->number - (__u16) (port->serial->minor)) + 315 (((__u16) port->number - (__u16) (port->serial->minor)) +
@@ -317,14 +317,12 @@ static int mos7840_get_uart_reg(struct usb_serial_port *port, __u16 reg,
317 dbg("mos7840_get_uart_reg application number is %x\n", Wval); 317 dbg("mos7840_get_uart_reg application number is %x\n", Wval);
318 } else { 318 } else {
319 if (((__u16) port->number - (__u16) (port->serial->minor)) == 0) { 319 if (((__u16) port->number - (__u16) (port->serial->minor)) == 0) {
320 Wval = 320 Wval = (((__u16) port->number -
321 (((__u16) port->number -
322 (__u16) (port->serial->minor)) + 1) << 8; 321 (__u16) (port->serial->minor)) + 1) << 8;
323 dbg("mos7840_get_uart_reg application number is %x\n", 322 dbg("mos7840_get_uart_reg application number is %x\n",
324 Wval); 323 Wval);
325 } else { 324 } else {
326 Wval = 325 Wval = (((__u16) port->number -
327 (((__u16) port->number -
328 (__u16) (port->serial->minor)) + 2) << 8; 326 (__u16) (port->serial->minor)) + 2) << 8;
329 dbg("mos7840_get_uart_reg application number is %x\n", 327 dbg("mos7840_get_uart_reg application number is %x\n",
330 Wval); 328 Wval);
@@ -406,11 +404,11 @@ static void mos7840_handle_new_lsr(struct moschip_port *port, __u8 new_lsr)
406 dbg("%s - %02x", __func__, new_lsr); 404 dbg("%s - %02x", __func__, new_lsr);
407 405
408 if (new_lsr & SERIAL_LSR_BI) { 406 if (new_lsr & SERIAL_LSR_BI) {
409 // 407 /*
410 // Parity and Framing errors only count if they 408 * Parity and Framing errors only count if they
411 // occur exclusive of a break being 409 * occur exclusive of a break being
412 // received. 410 * received.
413 // 411 */
414 new_lsr &= (__u8) (SERIAL_LSR_OE | SERIAL_LSR_BI); 412 new_lsr &= (__u8) (SERIAL_LSR_OE | SERIAL_LSR_BI);
415 } 413 }
416 414
@@ -492,7 +490,7 @@ exit:
492} 490}
493 491
494static int mos7840_get_reg(struct moschip_port *mcs, __u16 Wval, __u16 reg, 492static int mos7840_get_reg(struct moschip_port *mcs, __u16 Wval, __u16 reg,
495 __u16 * val) 493 __u16 *val)
496{ 494{
497 struct usb_device *dev = mcs->port->serial->dev; 495 struct usb_device *dev = mcs->port->serial->dev;
498 struct usb_ctrlrequest *dr = mcs->dr; 496 struct usb_ctrlrequest *dr = mcs->dr;
@@ -501,7 +499,7 @@ static int mos7840_get_reg(struct moschip_port *mcs, __u16 Wval, __u16 reg,
501 499
502 dr->bRequestType = MCS_RD_RTYPE; 500 dr->bRequestType = MCS_RD_RTYPE;
503 dr->bRequest = MCS_RDREQ; 501 dr->bRequest = MCS_RDREQ;
504 dr->wValue = cpu_to_le16(Wval); //0; 502 dr->wValue = cpu_to_le16(Wval); /* 0 */
505 dr->wIndex = cpu_to_le16(reg); 503 dr->wIndex = cpu_to_le16(reg);
506 dr->wLength = cpu_to_le16(2); 504 dr->wLength = cpu_to_le16(2);
507 505
@@ -607,7 +605,8 @@ static void mos7840_interrupt_callback(struct urb *urb)
607 } 605 }
608 } 606 }
609 } 607 }
610 if (!(rv < 0)) /* the completion handler for the control urb will resubmit */ 608 if (!(rv < 0))
609 /* the completion handler for the control urb will resubmit */
611 return; 610 return;
612exit: 611exit:
613 result = usb_submit_urb(urb, GFP_ATOMIC); 612 result = usb_submit_urb(urb, GFP_ATOMIC);
@@ -656,8 +655,8 @@ static struct usb_serial *mos7840_get_usb_serial(struct usb_serial_port *port,
656 if (!port || 655 if (!port ||
657 mos7840_port_paranoia_check(port, function) || 656 mos7840_port_paranoia_check(port, function) ||
658 mos7840_serial_paranoia_check(port->serial, function)) { 657 mos7840_serial_paranoia_check(port->serial, function)) {
659 /* then say that we don't have a valid usb_serial thing, which will 658 /* then say that we don't have a valid usb_serial thing,
660 * end up genrating -ENODEV return values */ 659 * which will end up genrating -ENODEV return values */
661 return NULL; 660 return NULL;
662 } 661 }
663 662
@@ -710,7 +709,7 @@ static void mos7840_bulk_in_callback(struct urb *urb)
710 dbg("%s", "Entering ........... \n"); 709 dbg("%s", "Entering ........... \n");
711 710
712 if (urb->actual_length) { 711 if (urb->actual_length) {
713 tty = mos7840_port->port->tty; 712 tty = mos7840_port->port->port.tty;
714 if (tty) { 713 if (tty) {
715 tty_buffer_request_room(tty, urb->actual_length); 714 tty_buffer_request_room(tty, urb->actual_length);
716 tty_insert_flip_string(tty, data, urb->actual_length); 715 tty_insert_flip_string(tty, data, urb->actual_length);
@@ -741,8 +740,8 @@ static void mos7840_bulk_in_callback(struct urb *urb)
741 740
742/***************************************************************************** 741/*****************************************************************************
743 * mos7840_bulk_out_data_callback 742 * mos7840_bulk_out_data_callback
744 * this is the callback function for when we have finished sending serial data 743 * this is the callback function for when we have finished sending
745 * on the bulk out endpoint. 744 * serial data on the bulk out endpoint.
746 *****************************************************************************/ 745 *****************************************************************************/
747 746
748static void mos7840_bulk_out_data_callback(struct urb *urb) 747static void mos7840_bulk_out_data_callback(struct urb *urb)
@@ -774,7 +773,7 @@ static void mos7840_bulk_out_data_callback(struct urb *urb)
774 773
775 dbg("%s \n", "Entering ........."); 774 dbg("%s \n", "Entering .........");
776 775
777 tty = mos7840_port->port->tty; 776 tty = mos7840_port->port->port.tty;
778 777
779 if (tty && mos7840_port->open) 778 if (tty && mos7840_port->open)
780 tty_wakeup(tty); 779 tty_wakeup(tty);
@@ -804,7 +803,8 @@ static int mos7840_serial_probe(struct usb_serial *serial,
804 * Otherwise we return a negative error number. 803 * Otherwise we return a negative error number.
805 *****************************************************************************/ 804 *****************************************************************************/
806 805
807static int mos7840_open(struct usb_serial_port *port, struct file *filp) 806static int mos7840_open(struct tty_struct *tty,
807 struct usb_serial_port *port, struct file *filp)
808{ 808{
809 int response; 809 int response;
810 int j; 810 int j;
@@ -847,7 +847,8 @@ static int mos7840_open(struct usb_serial_port *port, struct file *filp)
847 continue; 847 continue;
848 } 848 }
849 849
850 urb->transfer_buffer = kmalloc(URB_TRANSFER_BUFFER_SIZE, GFP_KERNEL); 850 urb->transfer_buffer = kmalloc(URB_TRANSFER_BUFFER_SIZE,
851 GFP_KERNEL);
851 if (!urb->transfer_buffer) { 852 if (!urb->transfer_buffer) {
852 usb_free_urb(urb); 853 usb_free_urb(urb);
853 mos7840_port->write_urb_pool[j] = NULL; 854 mos7840_port->write_urb_pool[j] = NULL;
@@ -868,9 +869,8 @@ static int mos7840_open(struct usb_serial_port *port, struct file *filp)
868 * 0x08 : SP1/2 Control Reg 869 * 0x08 : SP1/2 Control Reg
869 *****************************************************************************/ 870 *****************************************************************************/
870 871
871//NEED to check the following Block 872 /* NEED to check the following Block */
872 873
873 status = 0;
874 Data = 0x0; 874 Data = 0x0;
875 status = mos7840_get_reg_sync(port, mos7840_port->SpRegOffset, &Data); 875 status = mos7840_get_reg_sync(port, mos7840_port->SpRegOffset, &Data);
876 if (status < 0) { 876 if (status < 0) {
@@ -890,36 +890,35 @@ static int mos7840_open(struct usb_serial_port *port, struct file *filp)
890 dbg("writing Spreg failed\n"); 890 dbg("writing Spreg failed\n");
891 return -1; 891 return -1;
892 } 892 }
893//End of block to be checked 893 /* End of block to be checked */
894 894
895 status = 0;
896 Data = 0x0; 895 Data = 0x0;
897 status = 896 status = mos7840_get_reg_sync(port, mos7840_port->ControlRegOffset,
898 mos7840_get_reg_sync(port, mos7840_port->ControlRegOffset, &Data); 897 &Data);
899 if (status < 0) { 898 if (status < 0) {
900 dbg("Reading Controlreg failed\n"); 899 dbg("Reading Controlreg failed\n");
901 return -1; 900 return -1;
902 } 901 }
903 Data |= 0x08; //Driver done bit 902 Data |= 0x08; /* Driver done bit */
904 Data |= 0x20; //rx_disable 903 Data |= 0x20; /* rx_disable */
905 status = mos7840_set_reg_sync(port, mos7840_port->ControlRegOffset, Data); 904 status = mos7840_set_reg_sync(port,
905 mos7840_port->ControlRegOffset, Data);
906 if (status < 0) { 906 if (status < 0) {
907 dbg("writing Controlreg failed\n"); 907 dbg("writing Controlreg failed\n");
908 return -1; 908 return -1;
909 } 909 }
910 //do register settings here 910 /* do register settings here */
911 // Set all regs to the device default values. 911 /* Set all regs to the device default values. */
912 //////////////////////////////////// 912 /***********************************
913 // First Disable all interrupts. 913 * First Disable all interrupts.
914 //////////////////////////////////// 914 ***********************************/
915
916 Data = 0x00; 915 Data = 0x00;
917 status = mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data); 916 status = mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data);
918 if (status < 0) { 917 if (status < 0) {
919 dbg("disableing interrupts failed\n"); 918 dbg("disableing interrupts failed\n");
920 return -1; 919 return -1;
921 } 920 }
922 // Set FIFO_CONTROL_REGISTER to the default value 921 /* Set FIFO_CONTROL_REGISTER to the default value */
923 Data = 0x00; 922 Data = 0x00;
924 status = mos7840_set_uart_reg(port, FIFO_CONTROL_REGISTER, Data); 923 status = mos7840_set_uart_reg(port, FIFO_CONTROL_REGISTER, Data);
925 if (status < 0) { 924 if (status < 0) {
@@ -946,90 +945,73 @@ static int mos7840_open(struct usb_serial_port *port, struct file *filp)
946 status = mos7840_get_uart_reg(port, LINE_CONTROL_REGISTER, &Data); 945 status = mos7840_get_uart_reg(port, LINE_CONTROL_REGISTER, &Data);
947 mos7840_port->shadowLCR = Data; 946 mos7840_port->shadowLCR = Data;
948 947
949 Data |= SERIAL_LCR_DLAB; //data latch enable in LCR 0x80 948 Data |= SERIAL_LCR_DLAB; /* data latch enable in LCR 0x80 */
950 status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data); 949 status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
951 950
952 Data = 0x0c; 951 Data = 0x0c;
953 status = 0;
954 status = mos7840_set_uart_reg(port, DIVISOR_LATCH_LSB, Data); 952 status = mos7840_set_uart_reg(port, DIVISOR_LATCH_LSB, Data);
955 953
956 Data = 0x0; 954 Data = 0x0;
957 status = 0;
958 status = mos7840_set_uart_reg(port, DIVISOR_LATCH_MSB, Data); 955 status = mos7840_set_uart_reg(port, DIVISOR_LATCH_MSB, Data);
959 956
960 Data = 0x00; 957 Data = 0x00;
961 status = 0;
962 status = mos7840_get_uart_reg(port, LINE_CONTROL_REGISTER, &Data); 958 status = mos7840_get_uart_reg(port, LINE_CONTROL_REGISTER, &Data);
963 959
964 Data = Data & ~SERIAL_LCR_DLAB; 960 Data = Data & ~SERIAL_LCR_DLAB;
965 status = 0;
966 status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data); 961 status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
967 mos7840_port->shadowLCR = Data; 962 mos7840_port->shadowLCR = Data;
968 963
969 //clearing Bulkin and Bulkout Fifo 964 /* clearing Bulkin and Bulkout Fifo */
970 Data = 0x0; 965 Data = 0x0;
971 status = 0;
972 status = mos7840_get_reg_sync(port, mos7840_port->SpRegOffset, &Data); 966 status = mos7840_get_reg_sync(port, mos7840_port->SpRegOffset, &Data);
973 967
974 Data = Data | 0x0c; 968 Data = Data | 0x0c;
975 status = 0;
976 status = mos7840_set_reg_sync(port, mos7840_port->SpRegOffset, Data); 969 status = mos7840_set_reg_sync(port, mos7840_port->SpRegOffset, Data);
977 970
978 Data = Data & ~0x0c; 971 Data = Data & ~0x0c;
979 status = 0;
980 status = mos7840_set_reg_sync(port, mos7840_port->SpRegOffset, Data); 972 status = mos7840_set_reg_sync(port, mos7840_port->SpRegOffset, Data);
981 //Finally enable all interrupts 973 /* Finally enable all interrupts */
982 Data = 0x0;
983 Data = 0x0c; 974 Data = 0x0c;
984 status = 0;
985 status = mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data); 975 status = mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data);
986 976
987 //clearing rx_disable 977 /* clearing rx_disable */
988 Data = 0x0; 978 Data = 0x0;
989 status = 0; 979 status = mos7840_get_reg_sync(port, mos7840_port->ControlRegOffset,
990 status = 980 &Data);
991 mos7840_get_reg_sync(port, mos7840_port->ControlRegOffset, &Data);
992 Data = Data & ~0x20; 981 Data = Data & ~0x20;
993 status = 0; 982 status = mos7840_set_reg_sync(port, mos7840_port->ControlRegOffset,
994 status = 983 Data);
995 mos7840_set_reg_sync(port, mos7840_port->ControlRegOffset, Data);
996 984
997 // rx_negate 985 /* rx_negate */
998 Data = 0x0; 986 Data = 0x0;
999 status = 0; 987 status = mos7840_get_reg_sync(port, mos7840_port->ControlRegOffset,
1000 status = 988 &Data);
1001 mos7840_get_reg_sync(port, mos7840_port->ControlRegOffset, &Data);
1002 Data = Data | 0x10; 989 Data = Data | 0x10;
1003 status = 0; 990 status = mos7840_set_reg_sync(port, mos7840_port->ControlRegOffset,
1004 status = 991 Data);
1005 mos7840_set_reg_sync(port, mos7840_port->ControlRegOffset, Data);
1006 992
1007 /* force low_latency on so that our tty_push actually forces * 993 /* force low_latency on so that our tty_push actually forces *
1008 * the data through,otherwise it is scheduled, and with * 994 * the data through,otherwise it is scheduled, and with *
1009 * high data rates (like with OHCI) data can get lost. */ 995 * high data rates (like with OHCI) data can get lost. */
996 if (tty)
997 tty->low_latency = 1;
1010 998
1011 if (port->tty) 999 /* Check to see if we've set up our endpoint info yet *
1012 port->tty->low_latency = 1; 1000 * (can't set it up in mos7840_startup as the structures *
1013/* Check to see if we've set up our endpoint info yet * 1001 * were not set up at that time.) */
1014 * (can't set it up in mos7840_startup as the structures *
1015 * were not set up at that time.) */
1016 if (port0->open_ports == 1) { 1002 if (port0->open_ports == 1) {
1017 if (serial->port[0]->interrupt_in_buffer == NULL) { 1003 if (serial->port[0]->interrupt_in_buffer == NULL) {
1018
1019 /* set up interrupt urb */ 1004 /* set up interrupt urb */
1020
1021 usb_fill_int_urb(serial->port[0]->interrupt_in_urb, 1005 usb_fill_int_urb(serial->port[0]->interrupt_in_urb,
1022 serial->dev, 1006 serial->dev,
1023 usb_rcvintpipe(serial->dev, 1007 usb_rcvintpipe(serial->dev,
1024 serial->port[0]-> 1008 serial->port[0]->interrupt_in_endpointAddress),
1025 interrupt_in_endpointAddress), 1009 serial->port[0]->interrupt_in_buffer,
1026 serial->port[0]->interrupt_in_buffer, 1010 serial->port[0]->interrupt_in_urb->
1027 serial->port[0]->interrupt_in_urb-> 1011 transfer_buffer_length,
1028 transfer_buffer_length, 1012 mos7840_interrupt_callback,
1029 mos7840_interrupt_callback, 1013 serial,
1030 serial, 1014 serial->port[0]->interrupt_in_urb->interval);
1031 serial->port[0]->interrupt_in_urb->
1032 interval);
1033 1015
1034 /* start interrupt read for mos7840 * 1016 /* start interrupt read for mos7840 *
1035 * will continue as long as mos7840 is connected */ 1017 * will continue as long as mos7840 is connected */
@@ -1084,14 +1066,16 @@ static int mos7840_open(struct usb_serial_port *port, struct file *filp)
1084 memset(&(mos7840_port->icount), 0x00, sizeof(mos7840_port->icount)); 1066 memset(&(mos7840_port->icount), 0x00, sizeof(mos7840_port->icount));
1085 1067
1086 /* initialize our port settings */ 1068 /* initialize our port settings */
1087 mos7840_port->shadowMCR = MCR_MASTER_IE; /* Must set to enable ints! */ 1069 /* Must set to enable ints! */
1070 mos7840_port->shadowMCR = MCR_MASTER_IE;
1088 /* send a open port command */ 1071 /* send a open port command */
1089 mos7840_port->open = 1; 1072 mos7840_port->open = 1;
1090 //mos7840_change_port_settings(mos7840_port,old_termios); 1073 /* mos7840_change_port_settings(mos7840_port,old_termios); */
1091 mos7840_port->icount.tx = 0; 1074 mos7840_port->icount.tx = 0;
1092 mos7840_port->icount.rx = 0; 1075 mos7840_port->icount.rx = 0;
1093 1076
1094 dbg("\n\nusb_serial serial:%p mos7840_port:%p\n usb_serial_port port:%p\n\n", serial, mos7840_port, port); 1077 dbg("\n\nusb_serial serial:%p mos7840_port:%p\n usb_serial_port port:%p\n\n",
1078 serial, mos7840_port, port);
1095 1079
1096 return 0; 1080 return 0;
1097 1081
@@ -1104,11 +1088,12 @@ static int mos7840_open(struct usb_serial_port *port, struct file *filp)
1104 * been written, but hasn't made it out the port yet) 1088 * been written, but hasn't made it out the port yet)
1105 * If successful, we return the number of bytes left to be written in the 1089 * If successful, we return the number of bytes left to be written in the
1106 * system, 1090 * system,
1107 * Otherwise we return a negative error number. 1091 * Otherwise we return zero.
1108 *****************************************************************************/ 1092 *****************************************************************************/
1109 1093
1110static int mos7840_chars_in_buffer(struct usb_serial_port *port) 1094static int mos7840_chars_in_buffer(struct tty_struct *tty)
1111{ 1095{
1096 struct usb_serial_port *port = tty->driver_data;
1112 int i; 1097 int i;
1113 int chars = 0; 1098 int chars = 0;
1114 unsigned long flags; 1099 unsigned long flags;
@@ -1118,22 +1103,20 @@ static int mos7840_chars_in_buffer(struct usb_serial_port *port)
1118 1103
1119 if (mos7840_port_paranoia_check(port, __func__)) { 1104 if (mos7840_port_paranoia_check(port, __func__)) {
1120 dbg("%s", "Invalid port \n"); 1105 dbg("%s", "Invalid port \n");
1121 return -1; 1106 return 0;
1122 } 1107 }
1123 1108
1124 mos7840_port = mos7840_get_port_private(port); 1109 mos7840_port = mos7840_get_port_private(port);
1125 if (mos7840_port == NULL) { 1110 if (mos7840_port == NULL) {
1126 dbg("%s \n", "mos7840_break:leaving ..........."); 1111 dbg("%s \n", "mos7840_break:leaving ...........");
1127 return -1; 1112 return 0;
1128 } 1113 }
1129 1114
1130 spin_lock_irqsave(&mos7840_port->pool_lock,flags); 1115 spin_lock_irqsave(&mos7840_port->pool_lock, flags);
1131 for (i = 0; i < NUM_URBS; ++i) { 1116 for (i = 0; i < NUM_URBS; ++i)
1132 if (mos7840_port->busy[i]) { 1117 if (mos7840_port->busy[i])
1133 chars += URB_TRANSFER_BUFFER_SIZE; 1118 chars += URB_TRANSFER_BUFFER_SIZE;
1134 } 1119 spin_unlock_irqrestore(&mos7840_port->pool_lock, flags);
1135 }
1136 spin_unlock_irqrestore(&mos7840_port->pool_lock,flags);
1137 dbg("%s - returns %d", __func__, chars); 1120 dbg("%s - returns %d", __func__, chars);
1138 return chars; 1121 return chars;
1139 1122
@@ -1149,7 +1132,8 @@ static int mos7840_chars_in_buffer(struct usb_serial_port *port)
1149 * 3. A timeout of 3 seconds without activity has expired 1132 * 3. A timeout of 3 seconds without activity has expired
1150 * 1133 *
1151 ************************************************************************/ 1134 ************************************************************************/
1152static void mos7840_block_until_tx_empty(struct moschip_port *mos7840_port) 1135static void mos7840_block_until_tx_empty(struct tty_struct *tty,
1136 struct moschip_port *mos7840_port)
1153{ 1137{
1154 int timeout = HZ / 10; 1138 int timeout = HZ / 10;
1155 int wait = 30; 1139 int wait = 30;
@@ -1157,12 +1141,11 @@ static void mos7840_block_until_tx_empty(struct moschip_port *mos7840_port)
1157 1141
1158 while (1) { 1142 while (1) {
1159 1143
1160 count = mos7840_chars_in_buffer(mos7840_port->port); 1144 count = mos7840_chars_in_buffer(tty);
1161 1145
1162 /* Check for Buffer status */ 1146 /* Check for Buffer status */
1163 if (count <= 0) { 1147 if (count <= 0)
1164 return; 1148 return;
1165 }
1166 1149
1167 /* Block the thread for a while */ 1150 /* Block the thread for a while */
1168 interruptible_sleep_on_timeout(&mos7840_port->wait_chase, 1151 interruptible_sleep_on_timeout(&mos7840_port->wait_chase,
@@ -1185,7 +1168,8 @@ static void mos7840_block_until_tx_empty(struct moschip_port *mos7840_port)
1185 * this function is called by the tty driver when a port is closed 1168 * this function is called by the tty driver when a port is closed
1186 *****************************************************************************/ 1169 *****************************************************************************/
1187 1170
1188static void mos7840_close(struct usb_serial_port *port, struct file *filp) 1171static void mos7840_close(struct tty_struct *tty,
1172 struct usb_serial_port *port, struct file *filp)
1189{ 1173{
1190 struct usb_serial *serial; 1174 struct usb_serial *serial;
1191 struct moschip_port *mos7840_port; 1175 struct moschip_port *mos7840_port;
@@ -1226,32 +1210,28 @@ static void mos7840_close(struct usb_serial_port *port, struct file *filp)
1226 } 1210 }
1227 } 1211 }
1228 1212
1229 if (serial->dev) { 1213 if (serial->dev)
1230 /* flush and block until tx is empty */ 1214 /* flush and block until tx is empty */
1231 mos7840_block_until_tx_empty(mos7840_port); 1215 mos7840_block_until_tx_empty(tty, mos7840_port);
1232 }
1233 1216
1234 /* While closing port, shutdown all bulk read, write * 1217 /* While closing port, shutdown all bulk read, write *
1235 * and interrupt read if they exists */ 1218 * and interrupt read if they exists */
1236 if (serial->dev) { 1219 if (serial->dev) {
1237
1238 if (mos7840_port->write_urb) { 1220 if (mos7840_port->write_urb) {
1239 dbg("%s", "Shutdown bulk write\n"); 1221 dbg("%s", "Shutdown bulk write\n");
1240 usb_kill_urb(mos7840_port->write_urb); 1222 usb_kill_urb(mos7840_port->write_urb);
1241 } 1223 }
1242
1243 if (mos7840_port->read_urb) { 1224 if (mos7840_port->read_urb) {
1244 dbg("%s", "Shutdown bulk read\n"); 1225 dbg("%s", "Shutdown bulk read\n");
1245 usb_kill_urb(mos7840_port->read_urb); 1226 usb_kill_urb(mos7840_port->read_urb);
1246 } 1227 }
1247 if ((&mos7840_port->control_urb)) { 1228 if ((&mos7840_port->control_urb)) {
1248 dbg("%s", "Shutdown control read\n"); 1229 dbg("%s", "Shutdown control read\n");
1249 // usb_kill_urb (mos7840_port->control_urb); 1230 /*/ usb_kill_urb (mos7840_port->control_urb); */
1250
1251 } 1231 }
1252 } 1232 }
1253// if(mos7840_port->ctrl_buf != NULL) 1233/* if(mos7840_port->ctrl_buf != NULL) */
1254// kfree(mos7840_port->ctrl_buf); 1234/* kfree(mos7840_port->ctrl_buf); */
1255 port0->open_ports--; 1235 port0->open_ports--;
1256 dbg("mos7840_num_open_ports in close%d:in port%d\n", 1236 dbg("mos7840_num_open_ports in close%d:in port%d\n",
1257 port0->open_ports, port->number); 1237 port0->open_ports, port->number);
@@ -1264,10 +1244,8 @@ static void mos7840_close(struct usb_serial_port *port, struct file *filp)
1264 1244
1265 if (mos7840_port->write_urb) { 1245 if (mos7840_port->write_urb) {
1266 /* if this urb had a transfer buffer already (old tx) free it */ 1246 /* if this urb had a transfer buffer already (old tx) free it */
1267 1247 if (mos7840_port->write_urb->transfer_buffer != NULL)
1268 if (mos7840_port->write_urb->transfer_buffer != NULL) {
1269 kfree(mos7840_port->write_urb->transfer_buffer); 1248 kfree(mos7840_port->write_urb->transfer_buffer);
1270 }
1271 usb_free_urb(mos7840_port->write_urb); 1249 usb_free_urb(mos7840_port->write_urb);
1272 } 1250 }
1273 1251
@@ -1293,20 +1271,19 @@ static void mos7840_close(struct usb_serial_port *port, struct file *filp)
1293 * 1271 *
1294 ************************************************************************/ 1272 ************************************************************************/
1295 1273
1296static void mos7840_block_until_chase_response(struct moschip_port 1274static void mos7840_block_until_chase_response(struct tty_struct *tty,
1297 *mos7840_port) 1275 struct moschip_port *mos7840_port)
1298{ 1276{
1299 int timeout = 1 * HZ; 1277 int timeout = 1 * HZ;
1300 int wait = 10; 1278 int wait = 10;
1301 int count; 1279 int count;
1302 1280
1303 while (1) { 1281 while (1) {
1304 count = mos7840_chars_in_buffer(mos7840_port->port); 1282 count = mos7840_chars_in_buffer(tty);
1305 1283
1306 /* Check for Buffer status */ 1284 /* Check for Buffer status */
1307 if (count <= 0) { 1285 if (count <= 0)
1308 return; 1286 return;
1309 }
1310 1287
1311 /* Block the thread for a while */ 1288 /* Block the thread for a while */
1312 interruptible_sleep_on_timeout(&mos7840_port->wait_chase, 1289 interruptible_sleep_on_timeout(&mos7840_port->wait_chase,
@@ -1328,8 +1305,9 @@ static void mos7840_block_until_chase_response(struct moschip_port
1328 * mos7840_break 1305 * mos7840_break
1329 * this function sends a break to the port 1306 * this function sends a break to the port
1330 *****************************************************************************/ 1307 *****************************************************************************/
1331static void mos7840_break(struct usb_serial_port *port, int break_state) 1308static void mos7840_break(struct tty_struct *tty, int break_state)
1332{ 1309{
1310 struct usb_serial_port *port = tty->driver_data;
1333 unsigned char data; 1311 unsigned char data;
1334 struct usb_serial *serial; 1312 struct usb_serial *serial;
1335 struct moschip_port *mos7840_port; 1313 struct moschip_port *mos7840_port;
@@ -1350,21 +1328,17 @@ static void mos7840_break(struct usb_serial_port *port, int break_state)
1350 1328
1351 mos7840_port = mos7840_get_port_private(port); 1329 mos7840_port = mos7840_get_port_private(port);
1352 1330
1353 if (mos7840_port == NULL) { 1331 if (mos7840_port == NULL)
1354 return; 1332 return;
1355 }
1356
1357 if (serial->dev) {
1358 1333
1334 if (serial->dev)
1359 /* flush and block until tx is empty */ 1335 /* flush and block until tx is empty */
1360 mos7840_block_until_chase_response(mos7840_port); 1336 mos7840_block_until_chase_response(tty, mos7840_port);
1361 }
1362 1337
1363 if (break_state == -1) { 1338 if (break_state == -1)
1364 data = mos7840_port->shadowLCR | LCR_SET_BREAK; 1339 data = mos7840_port->shadowLCR | LCR_SET_BREAK;
1365 } else { 1340 else
1366 data = mos7840_port->shadowLCR & ~LCR_SET_BREAK; 1341 data = mos7840_port->shadowLCR & ~LCR_SET_BREAK;
1367 }
1368 1342
1369 mos7840_port->shadowLCR = data; 1343 mos7840_port->shadowLCR = data;
1370 dbg("mcs7840_break mos7840_port->shadowLCR is %x\n", 1344 dbg("mcs7840_break mos7840_port->shadowLCR is %x\n",
@@ -1383,8 +1357,9 @@ static void mos7840_break(struct usb_serial_port *port, int break_state)
1383 * Otherwise we return a negative error number. 1357 * Otherwise we return a negative error number.
1384 *****************************************************************************/ 1358 *****************************************************************************/
1385 1359
1386static int mos7840_write_room(struct usb_serial_port *port) 1360static int mos7840_write_room(struct tty_struct *tty)
1387{ 1361{
1362 struct usb_serial_port *port = tty->driver_data;
1388 int i; 1363 int i;
1389 int room = 0; 1364 int room = 0;
1390 unsigned long flags; 1365 unsigned long flags;
@@ -1406,9 +1381,8 @@ static int mos7840_write_room(struct usb_serial_port *port)
1406 1381
1407 spin_lock_irqsave(&mos7840_port->pool_lock, flags); 1382 spin_lock_irqsave(&mos7840_port->pool_lock, flags);
1408 for (i = 0; i < NUM_URBS; ++i) { 1383 for (i = 0; i < NUM_URBS; ++i) {
1409 if (!mos7840_port->busy[i]) { 1384 if (!mos7840_port->busy[i])
1410 room += URB_TRANSFER_BUFFER_SIZE; 1385 room += URB_TRANSFER_BUFFER_SIZE;
1411 }
1412 } 1386 }
1413 spin_unlock_irqrestore(&mos7840_port->pool_lock, flags); 1387 spin_unlock_irqrestore(&mos7840_port->pool_lock, flags);
1414 1388
@@ -1426,7 +1400,7 @@ static int mos7840_write_room(struct usb_serial_port *port)
1426 * return a negative error number. 1400 * return a negative error number.
1427 *****************************************************************************/ 1401 *****************************************************************************/
1428 1402
1429static int mos7840_write(struct usb_serial_port *port, 1403static int mos7840_write(struct tty_struct *tty, struct usb_serial_port *port,
1430 const unsigned char *data, int count) 1404 const unsigned char *data, int count)
1431{ 1405{
1432 int status; 1406 int status;
@@ -1438,45 +1412,41 @@ static int mos7840_write(struct usb_serial_port *port,
1438 struct moschip_port *mos7840_port; 1412 struct moschip_port *mos7840_port;
1439 struct usb_serial *serial; 1413 struct usb_serial *serial;
1440 struct urb *urb; 1414 struct urb *urb;
1441 //__u16 Data; 1415 /* __u16 Data; */
1442 const unsigned char *current_position = data; 1416 const unsigned char *current_position = data;
1443 unsigned char *data1; 1417 unsigned char *data1;
1444 dbg("%s \n", "entering ..........."); 1418 dbg("%s \n", "entering ...........");
1445 //dbg("mos7840_write: mos7840_port->shadowLCR is %x\n",mos7840_port->shadowLCR); 1419 /* dbg("mos7840_write: mos7840_port->shadowLCR is %x\n",
1420 mos7840_port->shadowLCR); */
1446 1421
1447#ifdef NOTMOS7840 1422#ifdef NOTMOS7840
1448 Data = 0x00; 1423 Data = 0x00;
1449 status = 0;
1450 status = mos7840_get_uart_reg(port, LINE_CONTROL_REGISTER, &Data); 1424 status = mos7840_get_uart_reg(port, LINE_CONTROL_REGISTER, &Data);
1451 mos7840_port->shadowLCR = Data; 1425 mos7840_port->shadowLCR = Data;
1452 dbg("mos7840_write: LINE_CONTROL_REGISTER is %x\n", Data); 1426 dbg("mos7840_write: LINE_CONTROL_REGISTER is %x\n", Data);
1453 dbg("mos7840_write: mos7840_port->shadowLCR is %x\n", 1427 dbg("mos7840_write: mos7840_port->shadowLCR is %x\n",
1454 mos7840_port->shadowLCR); 1428 mos7840_port->shadowLCR);
1455 1429
1456 //Data = 0x03; 1430 /* Data = 0x03; */
1457 //status = mos7840_set_uart_reg(port,LINE_CONTROL_REGISTER,Data); 1431 /* status = mos7840_set_uart_reg(port,LINE_CONTROL_REGISTER,Data); */
1458 //mos7840_port->shadowLCR=Data;//Need to add later 1432 /* mos7840_port->shadowLCR=Data;//Need to add later */
1459 1433
1460 Data |= SERIAL_LCR_DLAB; //data latch enable in LCR 0x80 1434 Data |= SERIAL_LCR_DLAB; /* data latch enable in LCR 0x80 */
1461 status = 0;
1462 status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data); 1435 status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
1463 1436
1464 //Data = 0x0c; 1437 /* Data = 0x0c; */
1465 //status = mos7840_set_uart_reg(port,DIVISOR_LATCH_LSB,Data); 1438 /* status = mos7840_set_uart_reg(port,DIVISOR_LATCH_LSB,Data); */
1466 Data = 0x00; 1439 Data = 0x00;
1467 status = 0;
1468 status = mos7840_get_uart_reg(port, DIVISOR_LATCH_LSB, &Data); 1440 status = mos7840_get_uart_reg(port, DIVISOR_LATCH_LSB, &Data);
1469 dbg("mos7840_write:DLL value is %x\n", Data); 1441 dbg("mos7840_write:DLL value is %x\n", Data);
1470 1442
1471 Data = 0x0; 1443 Data = 0x0;
1472 status = 0;
1473 status = mos7840_get_uart_reg(port, DIVISOR_LATCH_MSB, &Data); 1444 status = mos7840_get_uart_reg(port, DIVISOR_LATCH_MSB, &Data);
1474 dbg("mos7840_write:DLM value is %x\n", Data); 1445 dbg("mos7840_write:DLM value is %x\n", Data);
1475 1446
1476 Data = Data & ~SERIAL_LCR_DLAB; 1447 Data = Data & ~SERIAL_LCR_DLAB;
1477 dbg("mos7840_write: mos7840_port->shadowLCR is %x\n", 1448 dbg("mos7840_write: mos7840_port->shadowLCR is %x\n",
1478 mos7840_port->shadowLCR); 1449 mos7840_port->shadowLCR);
1479 status = 0;
1480 status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data); 1450 status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
1481#endif 1451#endif
1482 1452
@@ -1555,8 +1525,7 @@ static int mos7840_write(struct usb_serial_port *port,
1555 mos7840_port->icount.tx += transfer_size; 1525 mos7840_port->icount.tx += transfer_size;
1556 smp_wmb(); 1526 smp_wmb();
1557 dbg("mos7840_port->icount.tx is %d:\n", mos7840_port->icount.tx); 1527 dbg("mos7840_port->icount.tx is %d:\n", mos7840_port->icount.tx);
1558 exit: 1528exit:
1559
1560 return bytes_sent; 1529 return bytes_sent;
1561 1530
1562} 1531}
@@ -1567,10 +1536,10 @@ static int mos7840_write(struct usb_serial_port *port,
1567 * being read from the port. 1536 * being read from the port.
1568 *****************************************************************************/ 1537 *****************************************************************************/
1569 1538
1570static void mos7840_throttle(struct usb_serial_port *port) 1539static void mos7840_throttle(struct tty_struct *tty)
1571{ 1540{
1541 struct usb_serial_port *port = tty->driver_data;
1572 struct moschip_port *mos7840_port; 1542 struct moschip_port *mos7840_port;
1573 struct tty_struct *tty;
1574 int status; 1543 int status;
1575 1544
1576 if (mos7840_port_paranoia_check(port, __func__)) { 1545 if (mos7840_port_paranoia_check(port, __func__)) {
@@ -1592,32 +1561,20 @@ static void mos7840_throttle(struct usb_serial_port *port)
1592 1561
1593 dbg("%s", "Entering .......... \n"); 1562 dbg("%s", "Entering .......... \n");
1594 1563
1595 tty = port->tty;
1596 if (!tty) {
1597 dbg("%s - no tty available", __func__);
1598 return;
1599 }
1600
1601 /* if we are implementing XON/XOFF, send the stop character */ 1564 /* if we are implementing XON/XOFF, send the stop character */
1602 if (I_IXOFF(tty)) { 1565 if (I_IXOFF(tty)) {
1603 unsigned char stop_char = STOP_CHAR(tty); 1566 unsigned char stop_char = STOP_CHAR(tty);
1604 status = mos7840_write(port, &stop_char, 1); 1567 status = mos7840_write(tty, port, &stop_char, 1);
1605 if (status <= 0) { 1568 if (status <= 0)
1606 return; 1569 return;
1607 }
1608 } 1570 }
1609
1610 /* if we are implementing RTS/CTS, toggle that line */ 1571 /* if we are implementing RTS/CTS, toggle that line */
1611 if (tty->termios->c_cflag & CRTSCTS) { 1572 if (tty->termios->c_cflag & CRTSCTS) {
1612 mos7840_port->shadowMCR &= ~MCR_RTS; 1573 mos7840_port->shadowMCR &= ~MCR_RTS;
1613 status = 0; 1574 status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER,
1614 status =
1615 mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER,
1616 mos7840_port->shadowMCR); 1575 mos7840_port->shadowMCR);
1617 1576 if (status < 0)
1618 if (status < 0) {
1619 return; 1577 return;
1620 }
1621 } 1578 }
1622 1579
1623 return; 1580 return;
@@ -1625,12 +1582,13 @@ static void mos7840_throttle(struct usb_serial_port *port)
1625 1582
1626/***************************************************************************** 1583/*****************************************************************************
1627 * mos7840_unthrottle 1584 * mos7840_unthrottle
1628 * this function is called by the tty driver when it wants to resume the data 1585 * this function is called by the tty driver when it wants to resume
1629 * being read from the port (called after SerialThrottle is called) 1586 * the data being read from the port (called after mos7840_throttle is
1587 * called)
1630 *****************************************************************************/ 1588 *****************************************************************************/
1631static void mos7840_unthrottle(struct usb_serial_port *port) 1589static void mos7840_unthrottle(struct tty_struct *tty)
1632{ 1590{
1633 struct tty_struct *tty; 1591 struct usb_serial_port *port = tty->driver_data;
1634 int status; 1592 int status;
1635 struct moschip_port *mos7840_port = mos7840_get_port_private(port); 1593 struct moschip_port *mos7840_port = mos7840_get_port_private(port);
1636 1594
@@ -1649,43 +1607,32 @@ static void mos7840_unthrottle(struct usb_serial_port *port)
1649 1607
1650 dbg("%s", "Entering .......... \n"); 1608 dbg("%s", "Entering .......... \n");
1651 1609
1652 tty = port->tty;
1653 if (!tty) {
1654 dbg("%s - no tty available", __func__);
1655 return;
1656 }
1657
1658 /* if we are implementing XON/XOFF, send the start character */ 1610 /* if we are implementing XON/XOFF, send the start character */
1659 if (I_IXOFF(tty)) { 1611 if (I_IXOFF(tty)) {
1660 unsigned char start_char = START_CHAR(tty); 1612 unsigned char start_char = START_CHAR(tty);
1661 status = mos7840_write(port, &start_char, 1); 1613 status = mos7840_write(tty, port, &start_char, 1);
1662 if (status <= 0) { 1614 if (status <= 0)
1663 return; 1615 return;
1664 }
1665 } 1616 }
1666 1617
1667 /* if we are implementing RTS/CTS, toggle that line */ 1618 /* if we are implementing RTS/CTS, toggle that line */
1668 if (tty->termios->c_cflag & CRTSCTS) { 1619 if (tty->termios->c_cflag & CRTSCTS) {
1669 mos7840_port->shadowMCR |= MCR_RTS; 1620 mos7840_port->shadowMCR |= MCR_RTS;
1670 status = 0; 1621 status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER,
1671 status =
1672 mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER,
1673 mos7840_port->shadowMCR); 1622 mos7840_port->shadowMCR);
1674 if (status < 0) { 1623 if (status < 0)
1675 return; 1624 return;
1676 }
1677 } 1625 }
1678
1679 return;
1680} 1626}
1681 1627
1682static int mos7840_tiocmget(struct usb_serial_port *port, struct file *file) 1628static int mos7840_tiocmget(struct tty_struct *tty, struct file *file)
1683{ 1629{
1630 struct usb_serial_port *port = tty->driver_data;
1684 struct moschip_port *mos7840_port; 1631 struct moschip_port *mos7840_port;
1685 unsigned int result; 1632 unsigned int result;
1686 __u16 msr; 1633 __u16 msr;
1687 __u16 mcr; 1634 __u16 mcr;
1688 int status = 0; 1635 int status;
1689 mos7840_port = mos7840_get_port_private(port); 1636 mos7840_port = mos7840_get_port_private(port);
1690 1637
1691 dbg("%s - port %d", __func__, port->number); 1638 dbg("%s - port %d", __func__, port->number);
@@ -1708,9 +1655,10 @@ static int mos7840_tiocmget(struct usb_serial_port *port, struct file *file)
1708 return result; 1655 return result;
1709} 1656}
1710 1657
1711static int mos7840_tiocmset(struct usb_serial_port *port, struct file *file, 1658static int mos7840_tiocmset(struct tty_struct *tty, struct file *file,
1712 unsigned int set, unsigned int clear) 1659 unsigned int set, unsigned int clear)
1713{ 1660{
1661 struct usb_serial_port *port = tty->driver_data;
1714 struct moschip_port *mos7840_port; 1662 struct moschip_port *mos7840_port;
1715 unsigned int mcr; 1663 unsigned int mcr;
1716 int status; 1664 int status;
@@ -1755,7 +1703,7 @@ static int mos7840_tiocmset(struct usb_serial_port *port, struct file *file,
1755 * baud rate. 1703 * baud rate.
1756 *****************************************************************************/ 1704 *****************************************************************************/
1757static int mos7840_calc_baud_rate_divisor(int baudRate, int *divisor, 1705static int mos7840_calc_baud_rate_divisor(int baudRate, int *divisor,
1758 __u16 * clk_sel_val) 1706 __u16 *clk_sel_val)
1759{ 1707{
1760 1708
1761 dbg("%s - %d", __func__, baudRate); 1709 dbg("%s - %d", __func__, baudRate);
@@ -1807,9 +1755,8 @@ static int mos7840_calc_baud_rate_divisor(int baudRate, int *divisor,
1807 /* Check for round off */ 1755 /* Check for round off */
1808 round1 = (__u16) (2304000L / baudrate); 1756 round1 = (__u16) (2304000L / baudrate);
1809 round = (__u16) (round1 - (custom * 10)); 1757 round = (__u16) (round1 - (custom * 10));
1810 if (round > 4) { 1758 if (round > 4)
1811 custom++; 1759 custom++;
1812 }
1813 *divisor = custom; 1760 *divisor = custom;
1814 1761
1815 dbg(" Baud %d = %d\n", baudrate, custom); 1762 dbg(" Baud %d = %d\n", baudrate, custom);
@@ -1857,16 +1804,15 @@ static int mos7840_send_cmd_write_baud_rate(struct moschip_port *mos7840_port,
1857 1804
1858 dbg("%s - port = %d, baud = %d", __func__, 1805 dbg("%s - port = %d, baud = %d", __func__,
1859 mos7840_port->port->number, baudRate); 1806 mos7840_port->port->number, baudRate);
1860 //reset clk_uart_sel in spregOffset 1807 /* reset clk_uart_sel in spregOffset */
1861 if (baudRate > 115200) { 1808 if (baudRate > 115200) {
1862#ifdef HW_flow_control 1809#ifdef HW_flow_control
1863 //NOTE: need to see the pther register to modify 1810 /* NOTE: need to see the pther register to modify */
1864 //setting h/w flow control bit to 1; 1811 /* setting h/w flow control bit to 1 */
1865 status = 0;
1866 Data = 0x2b; 1812 Data = 0x2b;
1867 mos7840_port->shadowMCR = Data; 1813 mos7840_port->shadowMCR = Data;
1868 status = 1814 status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER,
1869 mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data); 1815 Data);
1870 if (status < 0) { 1816 if (status < 0) {
1871 dbg("Writing spreg failed in set_serial_baud\n"); 1817 dbg("Writing spreg failed in set_serial_baud\n");
1872 return -1; 1818 return -1;
@@ -1875,12 +1821,11 @@ static int mos7840_send_cmd_write_baud_rate(struct moschip_port *mos7840_port,
1875 1821
1876 } else { 1822 } else {
1877#ifdef HW_flow_control 1823#ifdef HW_flow_control
1878 //setting h/w flow control bit to 0; 1824 / *setting h/w flow control bit to 0 */
1879 status = 0;
1880 Data = 0xb; 1825 Data = 0xb;
1881 mos7840_port->shadowMCR = Data; 1826 mos7840_port->shadowMCR = Data;
1882 status = 1827 status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER,
1883 mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data); 1828 Data);
1884 if (status < 0) { 1829 if (status < 0) {
1885 dbg("Writing spreg failed in set_serial_baud\n"); 1830 dbg("Writing spreg failed in set_serial_baud\n");
1886 return -1; 1831 return -1;
@@ -1889,25 +1834,20 @@ static int mos7840_send_cmd_write_baud_rate(struct moschip_port *mos7840_port,
1889 1834
1890 } 1835 }
1891 1836
1892 if (1) //baudRate <= 115200) 1837 if (1) { /* baudRate <= 115200) */
1893 {
1894 clk_sel_val = 0x0; 1838 clk_sel_val = 0x0;
1895 Data = 0x0; 1839 Data = 0x0;
1896 status = 0; 1840 status = mos7840_calc_baud_rate_divisor(baudRate, &divisor,
1897 status =
1898 mos7840_calc_baud_rate_divisor(baudRate, &divisor,
1899 &clk_sel_val); 1841 &clk_sel_val);
1900 status = 1842 status = mos7840_get_reg_sync(port, mos7840_port->SpRegOffset,
1901 mos7840_get_reg_sync(port, mos7840_port->SpRegOffset, 1843 &Data);
1902 &Data);
1903 if (status < 0) { 1844 if (status < 0) {
1904 dbg("reading spreg failed in set_serial_baud\n"); 1845 dbg("reading spreg failed in set_serial_baud\n");
1905 return -1; 1846 return -1;
1906 } 1847 }
1907 Data = (Data & 0x8f) | clk_sel_val; 1848 Data = (Data & 0x8f) | clk_sel_val;
1908 status = 0; 1849 status = mos7840_set_reg_sync(port, mos7840_port->SpRegOffset,
1909 status = 1850 Data);
1910 mos7840_set_reg_sync(port, mos7840_port->SpRegOffset, Data);
1911 if (status < 0) { 1851 if (status < 0) {
1912 dbg("Writing spreg failed in set_serial_baud\n"); 1852 dbg("Writing spreg failed in set_serial_baud\n");
1913 return -1; 1853 return -1;
@@ -1939,7 +1879,6 @@ static int mos7840_send_cmd_write_baud_rate(struct moschip_port *mos7840_port,
1939 mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data); 1879 mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
1940 1880
1941 } 1881 }
1942
1943 return status; 1882 return status;
1944} 1883}
1945 1884
@@ -1949,10 +1888,9 @@ static int mos7840_send_cmd_write_baud_rate(struct moschip_port *mos7840_port,
1949 * the specified new settings. 1888 * the specified new settings.
1950 *****************************************************************************/ 1889 *****************************************************************************/
1951 1890
1952static void mos7840_change_port_settings(struct moschip_port *mos7840_port, 1891static void mos7840_change_port_settings(struct tty_struct *tty,
1953 struct ktermios *old_termios) 1892 struct moschip_port *mos7840_port, struct ktermios *old_termios)
1954{ 1893{
1955 struct tty_struct *tty;
1956 int baud; 1894 int baud;
1957 unsigned cflag; 1895 unsigned cflag;
1958 unsigned iflag; 1896 unsigned iflag;
@@ -1988,8 +1926,6 @@ static void mos7840_change_port_settings(struct moschip_port *mos7840_port,
1988 return; 1926 return;
1989 } 1927 }
1990 1928
1991 tty = mos7840_port->port->tty;
1992
1993 dbg("%s", "Entering .......... \n"); 1929 dbg("%s", "Entering .......... \n");
1994 1930
1995 lData = LCR_BITS_8; 1931 lData = LCR_BITS_8;
@@ -2033,9 +1969,8 @@ static void mos7840_change_port_settings(struct moschip_port *mos7840_port,
2033 dbg("%s - parity = none", __func__); 1969 dbg("%s - parity = none", __func__);
2034 } 1970 }
2035 1971
2036 if (cflag & CMSPAR) { 1972 if (cflag & CMSPAR)
2037 lParity = lParity | 0x20; 1973 lParity = lParity | 0x20;
2038 }
2039 1974
2040 /* Change the Stop bit */ 1975 /* Change the Stop bit */
2041 if (cflag & CSTOPB) { 1976 if (cflag & CSTOPB) {
@@ -2077,16 +2012,13 @@ static void mos7840_change_port_settings(struct moschip_port *mos7840_port,
2077 /* set up the MCR register and send it to the mos7840 */ 2012 /* set up the MCR register and send it to the mos7840 */
2078 2013
2079 mos7840_port->shadowMCR = MCR_MASTER_IE; 2014 mos7840_port->shadowMCR = MCR_MASTER_IE;
2080 if (cflag & CBAUD) { 2015 if (cflag & CBAUD)
2081 mos7840_port->shadowMCR |= (MCR_DTR | MCR_RTS); 2016 mos7840_port->shadowMCR |= (MCR_DTR | MCR_RTS);
2082 }
2083 2017
2084 if (cflag & CRTSCTS) { 2018 if (cflag & CRTSCTS)
2085 mos7840_port->shadowMCR |= (MCR_XON_ANY); 2019 mos7840_port->shadowMCR |= (MCR_XON_ANY);
2086 2020 else
2087 } else {
2088 mos7840_port->shadowMCR &= ~(MCR_XON_ANY); 2021 mos7840_port->shadowMCR &= ~(MCR_XON_ANY);
2089 }
2090 2022
2091 Data = mos7840_port->shadowMCR; 2023 Data = mos7840_port->shadowMCR;
2092 mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data); 2024 mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
@@ -2131,14 +2063,14 @@ static void mos7840_change_port_settings(struct moschip_port *mos7840_port,
2131 * the termios structure 2063 * the termios structure
2132 *****************************************************************************/ 2064 *****************************************************************************/
2133 2065
2134static void mos7840_set_termios(struct usb_serial_port *port, 2066static void mos7840_set_termios(struct tty_struct *tty,
2067 struct usb_serial_port *port,
2135 struct ktermios *old_termios) 2068 struct ktermios *old_termios)
2136{ 2069{
2137 int status; 2070 int status;
2138 unsigned int cflag; 2071 unsigned int cflag;
2139 struct usb_serial *serial; 2072 struct usb_serial *serial;
2140 struct moschip_port *mos7840_port; 2073 struct moschip_port *mos7840_port;
2141 struct tty_struct *tty;
2142 dbg("mos7840_set_termios: START\n"); 2074 dbg("mos7840_set_termios: START\n");
2143 if (mos7840_port_paranoia_check(port, __func__)) { 2075 if (mos7840_port_paranoia_check(port, __func__)) {
2144 dbg("%s", "Invalid port \n"); 2076 dbg("%s", "Invalid port \n");
@@ -2157,8 +2089,6 @@ static void mos7840_set_termios(struct usb_serial_port *port,
2157 if (mos7840_port == NULL) 2089 if (mos7840_port == NULL)
2158 return; 2090 return;
2159 2091
2160 tty = port->tty;
2161
2162 if (!mos7840_port->open) { 2092 if (!mos7840_port->open) {
2163 dbg("%s - port not opened", __func__); 2093 dbg("%s - port not opened", __func__);
2164 return; 2094 return;
@@ -2176,7 +2106,7 @@ static void mos7840_set_termios(struct usb_serial_port *port,
2176 2106
2177 /* change the port settings to the new ones specified */ 2107 /* change the port settings to the new ones specified */
2178 2108
2179 mos7840_change_port_settings(mos7840_port, old_termios); 2109 mos7840_change_port_settings(tty, mos7840_port, old_termios);
2180 2110
2181 if (!mos7840_port->read_urb) { 2111 if (!mos7840_port->read_urb) {
2182 dbg("%s", "URB KILLED !!!!!\n"); 2112 dbg("%s", "URB KILLED !!!!!\n");
@@ -2205,13 +2135,13 @@ static void mos7840_set_termios(struct usb_serial_port *port,
2205 * allows an RS485 driver to be written in user space. 2135 * allows an RS485 driver to be written in user space.
2206 *****************************************************************************/ 2136 *****************************************************************************/
2207 2137
2208static int mos7840_get_lsr_info(struct moschip_port *mos7840_port, 2138static int mos7840_get_lsr_info(struct tty_struct *tty,
2209 unsigned int __user *value) 2139 unsigned int __user *value)
2210{ 2140{
2211 int count; 2141 int count;
2212 unsigned int result = 0; 2142 unsigned int result = 0;
2213 2143
2214 count = mos7840_chars_in_buffer(mos7840_port->port); 2144 count = mos7840_chars_in_buffer(tty);
2215 if (count == 0) { 2145 if (count == 0) {
2216 dbg("%s -- Empty", __func__); 2146 dbg("%s -- Empty", __func__);
2217 result = TIOCSER_TEMT; 2147 result = TIOCSER_TEMT;
@@ -2227,6 +2157,8 @@ static int mos7840_get_lsr_info(struct moschip_port *mos7840_port,
2227 * function to set modem info 2157 * function to set modem info
2228 *****************************************************************************/ 2158 *****************************************************************************/
2229 2159
2160/* FIXME: Should be using the model control hooks */
2161
2230static int mos7840_set_modem_info(struct moschip_port *mos7840_port, 2162static int mos7840_set_modem_info(struct moschip_port *mos7840_port,
2231 unsigned int cmd, unsigned int __user *value) 2163 unsigned int cmd, unsigned int __user *value)
2232{ 2164{
@@ -2282,7 +2214,6 @@ static int mos7840_set_modem_info(struct moschip_port *mos7840_port,
2282 mos7840_port->shadowMCR = mcr; 2214 mos7840_port->shadowMCR = mcr;
2283 2215
2284 Data = mos7840_port->shadowMCR; 2216 Data = mos7840_port->shadowMCR;
2285 status = 0;
2286 status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data); 2217 status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
2287 if (status < 0) { 2218 if (status < 0) {
2288 dbg("setting MODEM_CONTROL_REGISTER Failed\n"); 2219 dbg("setting MODEM_CONTROL_REGISTER Failed\n");
@@ -2303,10 +2234,8 @@ static int mos7840_get_modem_info(struct moschip_port *mos7840_port,
2303 unsigned int result = 0; 2234 unsigned int result = 0;
2304 __u16 msr; 2235 __u16 msr;
2305 unsigned int mcr = mos7840_port->shadowMCR; 2236 unsigned int mcr = mos7840_port->shadowMCR;
2306 int status = 0; 2237 mos7840_get_uart_reg(mos7840_port->port,
2307 status = 2238 MODEM_STATUS_REGISTER, &msr);
2308 mos7840_get_uart_reg(mos7840_port->port, MODEM_STATUS_REGISTER,
2309 &msr);
2310 result = ((mcr & MCR_DTR) ? TIOCM_DTR : 0) /* 0x002 */ 2239 result = ((mcr & MCR_DTR) ? TIOCM_DTR : 0) /* 0x002 */
2311 |((mcr & MCR_RTS) ? TIOCM_RTS : 0) /* 0x004 */ 2240 |((mcr & MCR_RTS) ? TIOCM_RTS : 0) /* 0x004 */
2312 |((msr & MOS7840_MSR_CTS) ? TIOCM_CTS : 0) /* 0x020 */ 2241 |((msr & MOS7840_MSR_CTS) ? TIOCM_CTS : 0) /* 0x020 */
@@ -2359,12 +2288,12 @@ static int mos7840_get_serial_info(struct moschip_port *mos7840_port,
2359 * this function handles any ioctl calls to the driver 2288 * this function handles any ioctl calls to the driver
2360 *****************************************************************************/ 2289 *****************************************************************************/
2361 2290
2362static int mos7840_ioctl(struct usb_serial_port *port, struct file *file, 2291static int mos7840_ioctl(struct tty_struct *tty, struct file *file,
2363 unsigned int cmd, unsigned long arg) 2292 unsigned int cmd, unsigned long arg)
2364{ 2293{
2294 struct usb_serial_port *port = tty->driver_data;
2365 void __user *argp = (void __user *)arg; 2295 void __user *argp = (void __user *)arg;
2366 struct moschip_port *mos7840_port; 2296 struct moschip_port *mos7840_port;
2367 struct tty_struct *tty;
2368 2297
2369 struct async_icount cnow; 2298 struct async_icount cnow;
2370 struct async_icount cprev; 2299 struct async_icount cprev;
@@ -2381,8 +2310,6 @@ static int mos7840_ioctl(struct usb_serial_port *port, struct file *file,
2381 if (mos7840_port == NULL) 2310 if (mos7840_port == NULL)
2382 return -1; 2311 return -1;
2383 2312
2384 tty = mos7840_port->port->tty;
2385
2386 dbg("%s - port %d, cmd = 0x%x", __func__, port->number, cmd); 2313 dbg("%s - port %d, cmd = 0x%x", __func__, port->number, cmd);
2387 2314
2388 switch (cmd) { 2315 switch (cmd) {
@@ -2390,9 +2317,10 @@ static int mos7840_ioctl(struct usb_serial_port *port, struct file *file,
2390 2317
2391 case TIOCSERGETLSR: 2318 case TIOCSERGETLSR:
2392 dbg("%s (%d) TIOCSERGETLSR", __func__, port->number); 2319 dbg("%s (%d) TIOCSERGETLSR", __func__, port->number);
2393 return mos7840_get_lsr_info(mos7840_port, argp); 2320 return mos7840_get_lsr_info(tty, argp);
2394 return 0; 2321 return 0;
2395 2322
2323 /* FIXME: use the modem hooks and remove this */
2396 case TIOCMBIS: 2324 case TIOCMBIS:
2397 case TIOCMBIC: 2325 case TIOCMBIC:
2398 case TIOCMSET: 2326 case TIOCMSET:
@@ -2418,7 +2346,7 @@ static int mos7840_ioctl(struct usb_serial_port *port, struct file *file,
2418 dbg("%s (%d) TIOCMIWAIT", __func__, port->number); 2346 dbg("%s (%d) TIOCMIWAIT", __func__, port->number);
2419 cprev = mos7840_port->icount; 2347 cprev = mos7840_port->icount;
2420 while (1) { 2348 while (1) {
2421 //interruptible_sleep_on(&mos7840_port->delta_msr_wait); 2349 /* interruptible_sleep_on(&mos7840_port->delta_msr_wait); */
2422 mos7840_port->delta_msr_cond = 0; 2350 mos7840_port->delta_msr_cond = 0;
2423 wait_event_interruptible(mos7840_port->delta_msr_wait, 2351 wait_event_interruptible(mos7840_port->delta_msr_wait,
2424 (mos7840_port-> 2352 (mos7840_port->
@@ -2463,13 +2391,9 @@ static int mos7840_ioctl(struct usb_serial_port *port, struct file *file,
2463 if (copy_to_user(argp, &icount, sizeof(icount))) 2391 if (copy_to_user(argp, &icount, sizeof(icount)))
2464 return -EFAULT; 2392 return -EFAULT;
2465 return 0; 2393 return 0;
2466
2467 case TIOCEXBAUD:
2468 return 0;
2469 default: 2394 default:
2470 break; 2395 break;
2471 } 2396 }
2472
2473 return -ENOIOCTLCMD; 2397 return -ENOIOCTLCMD;
2474} 2398}
2475 2399
@@ -2527,8 +2451,9 @@ static int mos7840_startup(struct usb_serial *serial)
2527 goto error; 2451 goto error;
2528 } 2452 }
2529 2453
2530 /* Initialize all port interrupt end point to port 0 int endpoint * 2454 /* Initialize all port interrupt end point to port 0 int
2531 * Our device has only one interrupt end point comman to all port */ 2455 * endpoint. Our device has only one interrupt end point
2456 * common to all port */
2532 2457
2533 mos7840_port->port = serial->port[i]; 2458 mos7840_port->port = serial->port[i];
2534 mos7840_set_port_private(serial->port[i], mos7840_port); 2459 mos7840_set_port_private(serial->port[i], mos7840_port);
@@ -2564,27 +2489,23 @@ static int mos7840_startup(struct usb_serial *serial)
2564 mos7840_port->DcrRegOffset = 0x1c; 2489 mos7840_port->DcrRegOffset = 0x1c;
2565 } 2490 }
2566 mos7840_dump_serial_port(mos7840_port); 2491 mos7840_dump_serial_port(mos7840_port);
2567
2568 mos7840_set_port_private(serial->port[i], mos7840_port); 2492 mos7840_set_port_private(serial->port[i], mos7840_port);
2569 2493
2570 //enable rx_disable bit in control register 2494 /* enable rx_disable bit in control register */
2571 2495 status = mos7840_get_reg_sync(serial->port[i],
2572 status = 2496 mos7840_port->ControlRegOffset, &Data);
2573 mos7840_get_reg_sync(serial->port[i],
2574 mos7840_port->ControlRegOffset, &Data);
2575 if (status < 0) { 2497 if (status < 0) {
2576 dbg("Reading ControlReg failed status-0x%x\n", status); 2498 dbg("Reading ControlReg failed status-0x%x\n", status);
2577 break; 2499 break;
2578 } else 2500 } else
2579 dbg("ControlReg Reading success val is %x, status%d\n", 2501 dbg("ControlReg Reading success val is %x, status%d\n",
2580 Data, status); 2502 Data, status);
2581 Data |= 0x08; //setting driver done bit 2503 Data |= 0x08; /* setting driver done bit */
2582 Data |= 0x04; //sp1_bit to have cts change reflect in modem status reg 2504 Data |= 0x04; /* sp1_bit to have cts change reflect in
2505 modem status reg */
2583 2506
2584 //Data |= 0x20; //rx_disable bit 2507 /* Data |= 0x20; //rx_disable bit */
2585 status = 0; 2508 status = mos7840_set_reg_sync(serial->port[i],
2586 status =
2587 mos7840_set_reg_sync(serial->port[i],
2588 mos7840_port->ControlRegOffset, Data); 2509 mos7840_port->ControlRegOffset, Data);
2589 if (status < 0) { 2510 if (status < 0) {
2590 dbg("Writing ControlReg failed(rx_disable) status-0x%x\n", status); 2511 dbg("Writing ControlReg failed(rx_disable) status-0x%x\n", status);
@@ -2593,13 +2514,11 @@ static int mos7840_startup(struct usb_serial *serial)
2593 dbg("ControlReg Writing success(rx_disable) status%d\n", 2514 dbg("ControlReg Writing success(rx_disable) status%d\n",
2594 status); 2515 status);
2595 2516
2596 //Write default values in DCR (i.e 0x01 in DCR0, 0x05 in DCR2 and 0x24 in DCR3 2517 /* Write default values in DCR (i.e 0x01 in DCR0, 0x05 in DCR2
2518 and 0x24 in DCR3 */
2597 Data = 0x01; 2519 Data = 0x01;
2598 status = 0; 2520 status = mos7840_set_reg_sync(serial->port[i],
2599 status = 2521 (__u16) (mos7840_port->DcrRegOffset + 0), Data);
2600 mos7840_set_reg_sync(serial->port[i],
2601 (__u16) (mos7840_port->DcrRegOffset +
2602 0), Data);
2603 if (status < 0) { 2522 if (status < 0) {
2604 dbg("Writing DCR0 failed status-0x%x\n", status); 2523 dbg("Writing DCR0 failed status-0x%x\n", status);
2605 break; 2524 break;
@@ -2607,11 +2526,8 @@ static int mos7840_startup(struct usb_serial *serial)
2607 dbg("DCR0 Writing success status%d\n", status); 2526 dbg("DCR0 Writing success status%d\n", status);
2608 2527
2609 Data = 0x05; 2528 Data = 0x05;
2610 status = 0; 2529 status = mos7840_set_reg_sync(serial->port[i],
2611 status = 2530 (__u16) (mos7840_port->DcrRegOffset + 1), Data);
2612 mos7840_set_reg_sync(serial->port[i],
2613 (__u16) (mos7840_port->DcrRegOffset +
2614 1), Data);
2615 if (status < 0) { 2531 if (status < 0) {
2616 dbg("Writing DCR1 failed status-0x%x\n", status); 2532 dbg("Writing DCR1 failed status-0x%x\n", status);
2617 break; 2533 break;
@@ -2619,22 +2535,17 @@ static int mos7840_startup(struct usb_serial *serial)
2619 dbg("DCR1 Writing success status%d\n", status); 2535 dbg("DCR1 Writing success status%d\n", status);
2620 2536
2621 Data = 0x24; 2537 Data = 0x24;
2622 status = 0; 2538 status = mos7840_set_reg_sync(serial->port[i],
2623 status = 2539 (__u16) (mos7840_port->DcrRegOffset + 2), Data);
2624 mos7840_set_reg_sync(serial->port[i],
2625 (__u16) (mos7840_port->DcrRegOffset +
2626 2), Data);
2627 if (status < 0) { 2540 if (status < 0) {
2628 dbg("Writing DCR2 failed status-0x%x\n", status); 2541 dbg("Writing DCR2 failed status-0x%x\n", status);
2629 break; 2542 break;
2630 } else 2543 } else
2631 dbg("DCR2 Writing success status%d\n", status); 2544 dbg("DCR2 Writing success status%d\n", status);
2632 2545
2633 // write values in clkstart0x0 and clkmulti 0x20 2546 /* write values in clkstart0x0 and clkmulti 0x20 */
2634 Data = 0x0; 2547 Data = 0x0;
2635 status = 0; 2548 status = mos7840_set_reg_sync(serial->port[i],
2636 status =
2637 mos7840_set_reg_sync(serial->port[i],
2638 CLK_START_VALUE_REGISTER, Data); 2549 CLK_START_VALUE_REGISTER, Data);
2639 if (status < 0) { 2550 if (status < 0) {
2640 dbg("Writing CLK_START_VALUE_REGISTER failed status-0x%x\n", status); 2551 dbg("Writing CLK_START_VALUE_REGISTER failed status-0x%x\n", status);
@@ -2643,9 +2554,8 @@ static int mos7840_startup(struct usb_serial *serial)
2643 dbg("CLK_START_VALUE_REGISTER Writing success status%d\n", status); 2554 dbg("CLK_START_VALUE_REGISTER Writing success status%d\n", status);
2644 2555
2645 Data = 0x20; 2556 Data = 0x20;
2646 status = 2557 status = mos7840_set_reg_sync(serial->port[i],
2647 mos7840_set_reg_sync(serial->port[i], CLK_MULTI_REGISTER, 2558 CLK_MULTI_REGISTER, Data);
2648 Data);
2649 if (status < 0) { 2559 if (status < 0) {
2650 dbg("Writing CLK_MULTI_REGISTER failed status-0x%x\n", 2560 dbg("Writing CLK_MULTI_REGISTER failed status-0x%x\n",
2651 status); 2561 status);
@@ -2654,11 +2564,10 @@ static int mos7840_startup(struct usb_serial *serial)
2654 dbg("CLK_MULTI_REGISTER Writing success status%d\n", 2564 dbg("CLK_MULTI_REGISTER Writing success status%d\n",
2655 status); 2565 status);
2656 2566
2657 //write value 0x0 to scratchpad register 2567 /* write value 0x0 to scratchpad register */
2658 Data = 0x00; 2568 Data = 0x00;
2659 status = 2569 status = mos7840_set_uart_reg(serial->port[i],
2660 mos7840_set_uart_reg(serial->port[i], SCRATCH_PAD_REGISTER, 2570 SCRATCH_PAD_REGISTER, Data);
2661 Data);
2662 if (status < 0) { 2571 if (status < 0) {
2663 dbg("Writing SCRATCH_PAD_REGISTER failed status-0x%x\n", 2572 dbg("Writing SCRATCH_PAD_REGISTER failed status-0x%x\n",
2664 status); 2573 status);
@@ -2667,21 +2576,17 @@ static int mos7840_startup(struct usb_serial *serial)
2667 dbg("SCRATCH_PAD_REGISTER Writing success status%d\n", 2576 dbg("SCRATCH_PAD_REGISTER Writing success status%d\n",
2668 status); 2577 status);
2669 2578
2670 //Zero Length flag register 2579 /* Zero Length flag register */
2671 if ((mos7840_port->port_num != 1) 2580 if ((mos7840_port->port_num != 1)
2672 && (serial->num_ports == 2)) { 2581 && (serial->num_ports == 2)) {
2673 2582
2674 Data = 0xff; 2583 Data = 0xff;
2675 status = 0;
2676 status = mos7840_set_reg_sync(serial->port[i], 2584 status = mos7840_set_reg_sync(serial->port[i],
2677 (__u16) (ZLP_REG1 + 2585 (__u16) (ZLP_REG1 +
2678 ((__u16) 2586 ((__u16)mos7840_port->port_num)), Data);
2679 mos7840_port->
2680 port_num)),
2681 Data);
2682 dbg("ZLIP offset%x\n", 2587 dbg("ZLIP offset%x\n",
2683 (__u16) (ZLP_REG1 + 2588 (__u16) (ZLP_REG1 +
2684 ((__u16) mos7840_port->port_num))); 2589 ((__u16) mos7840_port->port_num)));
2685 if (status < 0) { 2590 if (status < 0) {
2686 dbg("Writing ZLP_REG%d failed status-0x%x\n", 2591 dbg("Writing ZLP_REG%d failed status-0x%x\n",
2687 i + 2, status); 2592 i + 2, status);
@@ -2691,13 +2596,9 @@ static int mos7840_startup(struct usb_serial *serial)
2691 i + 2, status); 2596 i + 2, status);
2692 } else { 2597 } else {
2693 Data = 0xff; 2598 Data = 0xff;
2694 status = 0;
2695 status = mos7840_set_reg_sync(serial->port[i], 2599 status = mos7840_set_reg_sync(serial->port[i],
2696 (__u16) (ZLP_REG1 + 2600 (__u16) (ZLP_REG1 +
2697 ((__u16) 2601 ((__u16)mos7840_port->port_num) - 0x1), Data);
2698 mos7840_port->
2699 port_num) -
2700 0x1), Data);
2701 dbg("ZLIP offset%x\n", 2602 dbg("ZLIP offset%x\n",
2702 (__u16) (ZLP_REG1 + 2603 (__u16) (ZLP_REG1 +
2703 ((__u16) mos7840_port->port_num) - 0x1)); 2604 ((__u16) mos7840_port->port_num) - 0x1));
@@ -2712,14 +2613,16 @@ static int mos7840_startup(struct usb_serial *serial)
2712 } 2613 }
2713 mos7840_port->control_urb = usb_alloc_urb(0, GFP_KERNEL); 2614 mos7840_port->control_urb = usb_alloc_urb(0, GFP_KERNEL);
2714 mos7840_port->ctrl_buf = kmalloc(16, GFP_KERNEL); 2615 mos7840_port->ctrl_buf = kmalloc(16, GFP_KERNEL);
2715 mos7840_port->dr = kmalloc(sizeof(struct usb_ctrlrequest), GFP_KERNEL); 2616 mos7840_port->dr = kmalloc(sizeof(struct usb_ctrlrequest),
2716 if (!mos7840_port->control_urb || !mos7840_port->ctrl_buf || !mos7840_port->dr) { 2617 GFP_KERNEL);
2618 if (!mos7840_port->control_urb || !mos7840_port->ctrl_buf ||
2619 !mos7840_port->dr) {
2717 status = -ENOMEM; 2620 status = -ENOMEM;
2718 goto error; 2621 goto error;
2719 } 2622 }
2720 } 2623 }
2721 2624
2722 //Zero Length flag enable 2625 /* Zero Length flag enable */
2723 Data = 0x0f; 2626 Data = 0x0f;
2724 status = mos7840_set_reg_sync(serial->port[0], ZLP_REG5, Data); 2627 status = mos7840_set_reg_sync(serial->port[0], ZLP_REG5, Data);
2725 if (status < 0) { 2628 if (status < 0) {
@@ -2762,7 +2665,7 @@ static void mos7840_shutdown(struct usb_serial *serial)
2762 return; 2665 return;
2763 } 2666 }
2764 2667
2765 /* check for the ports to be closed,close the ports and disconnect */ 2668 /* check for the ports to be closed,close the ports and disconnect */
2766 2669
2767 /* free private structure allocated for serial port * 2670 /* free private structure allocated for serial port *
2768 * stop reads and writes on all ports */ 2671 * stop reads and writes on all ports */
@@ -2843,20 +2746,12 @@ static int __init moschip7840_init(void)
2843 2746
2844 /* Register with the usb */ 2747 /* Register with the usb */
2845 retval = usb_register(&io_driver); 2748 retval = usb_register(&io_driver);
2846
2847 if (retval)
2848 goto failed_usb_register;
2849
2850 if (retval == 0) { 2749 if (retval == 0) {
2851 dbg("%s\n", "Leaving..."); 2750 dbg("%s\n", "Leaving...");
2852 return 0; 2751 return 0;
2853 } 2752 }
2854
2855 failed_usb_register:
2856 usb_serial_deregister(&moschip7840_4port_device); 2753 usb_serial_deregister(&moschip7840_4port_device);
2857 2754failed_port_device_register:
2858 failed_port_device_register:
2859
2860 return retval; 2755 return retval;
2861} 2756}
2862 2757