aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/serial/mos7840.c
diff options
context:
space:
mode:
authorAlan Cox <alan@redhat.com>2008-07-22 06:16:12 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2008-07-22 16:03:26 -0400
commit880af9db2c35c5fedaef0de89473f202329934db (patch)
treea2cf814a6f8d916d90c13ac89997d388b008aa43 /drivers/usb/serial/mos7840.c
parent4944d40054d73b2f8d7d546f55c206eb3baf2710 (diff)
mos7840: remove loads of bogus assignments to status
Signed-off-by: Alan Cox <alan@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/usb/serial/mos7840.c')
-rw-r--r--drivers/usb/serial/mos7840.c400
1 files changed, 164 insertions, 236 deletions
diff --git a/drivers/usb/serial/mos7840.c b/drivers/usb/serial/mos7840.c
index 2b1fded6619d..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
@@ -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)
@@ -848,7 +847,8 @@ static int mos7840_open(struct tty_struct *tty,
848 continue; 847 continue;
849 } 848 }
850 849
851 urb->transfer_buffer = kmalloc(URB_TRANSFER_BUFFER_SIZE, GFP_KERNEL); 850 urb->transfer_buffer = kmalloc(URB_TRANSFER_BUFFER_SIZE,
851 GFP_KERNEL);
852 if (!urb->transfer_buffer) { 852 if (!urb->transfer_buffer) {
853 usb_free_urb(urb); 853 usb_free_urb(urb);
854 mos7840_port->write_urb_pool[j] = NULL; 854 mos7840_port->write_urb_pool[j] = NULL;
@@ -869,9 +869,8 @@ static int mos7840_open(struct tty_struct *tty,
869 * 0x08 : SP1/2 Control Reg 869 * 0x08 : SP1/2 Control Reg
870 *****************************************************************************/ 870 *****************************************************************************/
871 871
872//NEED to check the following Block 872 /* NEED to check the following Block */
873 873
874 status = 0;
875 Data = 0x0; 874 Data = 0x0;
876 status = mos7840_get_reg_sync(port, mos7840_port->SpRegOffset, &Data); 875 status = mos7840_get_reg_sync(port, mos7840_port->SpRegOffset, &Data);
877 if (status < 0) { 876 if (status < 0) {
@@ -891,36 +890,35 @@ static int mos7840_open(struct tty_struct *tty,
891 dbg("writing Spreg failed\n"); 890 dbg("writing Spreg failed\n");
892 return -1; 891 return -1;
893 } 892 }
894//End of block to be checked 893 /* End of block to be checked */
895 894
896 status = 0;
897 Data = 0x0; 895 Data = 0x0;
898 status = 896 status = mos7840_get_reg_sync(port, mos7840_port->ControlRegOffset,
899 mos7840_get_reg_sync(port, mos7840_port->ControlRegOffset, &Data); 897 &Data);
900 if (status < 0) { 898 if (status < 0) {
901 dbg("Reading Controlreg failed\n"); 899 dbg("Reading Controlreg failed\n");
902 return -1; 900 return -1;
903 } 901 }
904 Data |= 0x08; //Driver done bit 902 Data |= 0x08; /* Driver done bit */
905 Data |= 0x20; //rx_disable 903 Data |= 0x20; /* rx_disable */
906 status = mos7840_set_reg_sync(port, mos7840_port->ControlRegOffset, Data); 904 status = mos7840_set_reg_sync(port,
905 mos7840_port->ControlRegOffset, Data);
907 if (status < 0) { 906 if (status < 0) {
908 dbg("writing Controlreg failed\n"); 907 dbg("writing Controlreg failed\n");
909 return -1; 908 return -1;
910 } 909 }
911 //do register settings here 910 /* do register settings here */
912 // Set all regs to the device default values. 911 /* Set all regs to the device default values. */
913 //////////////////////////////////// 912 /***********************************
914 // First Disable all interrupts. 913 * First Disable all interrupts.
915 //////////////////////////////////// 914 ***********************************/
916
917 Data = 0x00; 915 Data = 0x00;
918 status = mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data); 916 status = mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data);
919 if (status < 0) { 917 if (status < 0) {
920 dbg("disableing interrupts failed\n"); 918 dbg("disableing interrupts failed\n");
921 return -1; 919 return -1;
922 } 920 }
923 // Set FIFO_CONTROL_REGISTER to the default value 921 /* Set FIFO_CONTROL_REGISTER to the default value */
924 Data = 0x00; 922 Data = 0x00;
925 status = mos7840_set_uart_reg(port, FIFO_CONTROL_REGISTER, Data); 923 status = mos7840_set_uart_reg(port, FIFO_CONTROL_REGISTER, Data);
926 if (status < 0) { 924 if (status < 0) {
@@ -947,90 +945,73 @@ static int mos7840_open(struct tty_struct *tty,
947 status = mos7840_get_uart_reg(port, LINE_CONTROL_REGISTER, &Data); 945 status = mos7840_get_uart_reg(port, LINE_CONTROL_REGISTER, &Data);
948 mos7840_port->shadowLCR = Data; 946 mos7840_port->shadowLCR = Data;
949 947
950 Data |= SERIAL_LCR_DLAB; //data latch enable in LCR 0x80 948 Data |= SERIAL_LCR_DLAB; /* data latch enable in LCR 0x80 */
951 status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data); 949 status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
952 950
953 Data = 0x0c; 951 Data = 0x0c;
954 status = 0;
955 status = mos7840_set_uart_reg(port, DIVISOR_LATCH_LSB, Data); 952 status = mos7840_set_uart_reg(port, DIVISOR_LATCH_LSB, Data);
956 953
957 Data = 0x0; 954 Data = 0x0;
958 status = 0;
959 status = mos7840_set_uart_reg(port, DIVISOR_LATCH_MSB, Data); 955 status = mos7840_set_uart_reg(port, DIVISOR_LATCH_MSB, Data);
960 956
961 Data = 0x00; 957 Data = 0x00;
962 status = 0;
963 status = mos7840_get_uart_reg(port, LINE_CONTROL_REGISTER, &Data); 958 status = mos7840_get_uart_reg(port, LINE_CONTROL_REGISTER, &Data);
964 959
965 Data = Data & ~SERIAL_LCR_DLAB; 960 Data = Data & ~SERIAL_LCR_DLAB;
966 status = 0;
967 status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data); 961 status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
968 mos7840_port->shadowLCR = Data; 962 mos7840_port->shadowLCR = Data;
969 963
970 //clearing Bulkin and Bulkout Fifo 964 /* clearing Bulkin and Bulkout Fifo */
971 Data = 0x0; 965 Data = 0x0;
972 status = 0;
973 status = mos7840_get_reg_sync(port, mos7840_port->SpRegOffset, &Data); 966 status = mos7840_get_reg_sync(port, mos7840_port->SpRegOffset, &Data);
974 967
975 Data = Data | 0x0c; 968 Data = Data | 0x0c;
976 status = 0;
977 status = mos7840_set_reg_sync(port, mos7840_port->SpRegOffset, Data); 969 status = mos7840_set_reg_sync(port, mos7840_port->SpRegOffset, Data);
978 970
979 Data = Data & ~0x0c; 971 Data = Data & ~0x0c;
980 status = 0;
981 status = mos7840_set_reg_sync(port, mos7840_port->SpRegOffset, Data); 972 status = mos7840_set_reg_sync(port, mos7840_port->SpRegOffset, Data);
982 //Finally enable all interrupts 973 /* Finally enable all interrupts */
983 Data = 0x0;
984 Data = 0x0c; 974 Data = 0x0c;
985 status = 0;
986 status = mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data); 975 status = mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data);
987 976
988 //clearing rx_disable 977 /* clearing rx_disable */
989 Data = 0x0; 978 Data = 0x0;
990 status = 0; 979 status = mos7840_get_reg_sync(port, mos7840_port->ControlRegOffset,
991 status = 980 &Data);
992 mos7840_get_reg_sync(port, mos7840_port->ControlRegOffset, &Data);
993 Data = Data & ~0x20; 981 Data = Data & ~0x20;
994 status = 0; 982 status = mos7840_set_reg_sync(port, mos7840_port->ControlRegOffset,
995 status = 983 Data);
996 mos7840_set_reg_sync(port, mos7840_port->ControlRegOffset, Data);
997 984
998 // rx_negate 985 /* rx_negate */
999 Data = 0x0; 986 Data = 0x0;
1000 status = 0; 987 status = mos7840_get_reg_sync(port, mos7840_port->ControlRegOffset,
1001 status = 988 &Data);
1002 mos7840_get_reg_sync(port, mos7840_port->ControlRegOffset, &Data);
1003 Data = Data | 0x10; 989 Data = Data | 0x10;
1004 status = 0; 990 status = mos7840_set_reg_sync(port, mos7840_port->ControlRegOffset,
1005 status = 991 Data);
1006 mos7840_set_reg_sync(port, mos7840_port->ControlRegOffset, Data);
1007 992
1008 /* force low_latency on so that our tty_push actually forces * 993 /* force low_latency on so that our tty_push actually forces *
1009 * the data through,otherwise it is scheduled, and with * 994 * the data through,otherwise it is scheduled, and with *
1010 * high data rates (like with OHCI) data can get lost. */ 995 * high data rates (like with OHCI) data can get lost. */
1011
1012 if (tty) 996 if (tty)
1013 tty->low_latency = 1; 997 tty->low_latency = 1;
1014/* Check to see if we've set up our endpoint info yet * 998
1015 * (can't set it up in mos7840_startup as the structures * 999 /* Check to see if we've set up our endpoint info yet *
1016 * were not set up at that time.) */ 1000 * (can't set it up in mos7840_startup as the structures *
1001 * were not set up at that time.) */
1017 if (port0->open_ports == 1) { 1002 if (port0->open_ports == 1) {
1018 if (serial->port[0]->interrupt_in_buffer == NULL) { 1003 if (serial->port[0]->interrupt_in_buffer == NULL) {
1019
1020 /* set up interrupt urb */ 1004 /* set up interrupt urb */
1021
1022 usb_fill_int_urb(serial->port[0]->interrupt_in_urb, 1005 usb_fill_int_urb(serial->port[0]->interrupt_in_urb,
1023 serial->dev, 1006 serial->dev,
1024 usb_rcvintpipe(serial->dev, 1007 usb_rcvintpipe(serial->dev,
1025 serial->port[0]-> 1008 serial->port[0]->interrupt_in_endpointAddress),
1026 interrupt_in_endpointAddress), 1009 serial->port[0]->interrupt_in_buffer,
1027 serial->port[0]->interrupt_in_buffer, 1010 serial->port[0]->interrupt_in_urb->
1028 serial->port[0]->interrupt_in_urb-> 1011 transfer_buffer_length,
1029 transfer_buffer_length, 1012 mos7840_interrupt_callback,
1030 mos7840_interrupt_callback, 1013 serial,
1031 serial, 1014 serial->port[0]->interrupt_in_urb->interval);
1032 serial->port[0]->interrupt_in_urb->
1033 interval);
1034 1015
1035 /* start interrupt read for mos7840 * 1016 /* start interrupt read for mos7840 *
1036 * will continue as long as mos7840 is connected */ 1017 * will continue as long as mos7840 is connected */
@@ -1085,14 +1066,16 @@ static int mos7840_open(struct tty_struct *tty,
1085 memset(&(mos7840_port->icount), 0x00, sizeof(mos7840_port->icount)); 1066 memset(&(mos7840_port->icount), 0x00, sizeof(mos7840_port->icount));
1086 1067
1087 /* initialize our port settings */ 1068 /* initialize our port settings */
1088 mos7840_port->shadowMCR = MCR_MASTER_IE; /* Must set to enable ints! */ 1069 /* Must set to enable ints! */
1070 mos7840_port->shadowMCR = MCR_MASTER_IE;
1089 /* send a open port command */ 1071 /* send a open port command */
1090 mos7840_port->open = 1; 1072 mos7840_port->open = 1;
1091 //mos7840_change_port_settings(mos7840_port,old_termios); 1073 /* mos7840_change_port_settings(mos7840_port,old_termios); */
1092 mos7840_port->icount.tx = 0; 1074 mos7840_port->icount.tx = 0;
1093 mos7840_port->icount.rx = 0; 1075 mos7840_port->icount.rx = 0;
1094 1076
1095 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);
1096 1079
1097 return 0; 1080 return 0;
1098 1081
@@ -1129,11 +1112,11 @@ static int mos7840_chars_in_buffer(struct tty_struct *tty)
1129 return 0; 1112 return 0;
1130 } 1113 }
1131 1114
1132 spin_lock_irqsave(&mos7840_port->pool_lock,flags); 1115 spin_lock_irqsave(&mos7840_port->pool_lock, flags);
1133 for (i = 0; i < NUM_URBS; ++i) 1116 for (i = 0; i < NUM_URBS; ++i)
1134 if (mos7840_port->busy[i]) 1117 if (mos7840_port->busy[i])
1135 chars += URB_TRANSFER_BUFFER_SIZE; 1118 chars += URB_TRANSFER_BUFFER_SIZE;
1136 spin_unlock_irqrestore(&mos7840_port->pool_lock,flags); 1119 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
@@ -1161,9 +1144,8 @@ static void mos7840_block_until_tx_empty(struct tty_struct *tty,
1161 count = mos7840_chars_in_buffer(tty); 1144 count = mos7840_chars_in_buffer(tty);
1162 1145
1163 /* Check for Buffer status */ 1146 /* Check for Buffer status */
1164 if (count <= 0) { 1147 if (count <= 0)
1165 return; 1148 return;
1166 }
1167 1149
1168 /* Block the thread for a while */ 1150 /* Block the thread for a while */
1169 interruptible_sleep_on_timeout(&mos7840_port->wait_chase, 1151 interruptible_sleep_on_timeout(&mos7840_port->wait_chase,
@@ -1245,11 +1227,11 @@ static void mos7840_close(struct tty_struct *tty,
1245 } 1227 }
1246 if ((&mos7840_port->control_urb)) { 1228 if ((&mos7840_port->control_urb)) {
1247 dbg("%s", "Shutdown control read\n"); 1229 dbg("%s", "Shutdown control read\n");
1248 // usb_kill_urb (mos7840_port->control_urb); 1230 /*/ usb_kill_urb (mos7840_port->control_urb); */
1249 } 1231 }
1250 } 1232 }
1251// if(mos7840_port->ctrl_buf != NULL) 1233/* if(mos7840_port->ctrl_buf != NULL) */
1252// kfree(mos7840_port->ctrl_buf); 1234/* kfree(mos7840_port->ctrl_buf); */
1253 port0->open_ports--; 1235 port0->open_ports--;
1254 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",
1255 port0->open_ports, port->number); 1237 port0->open_ports, port->number);
@@ -1262,10 +1244,8 @@ static void mos7840_close(struct tty_struct *tty,
1262 1244
1263 if (mos7840_port->write_urb) { 1245 if (mos7840_port->write_urb) {
1264 /* 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 */
1265 1247 if (mos7840_port->write_urb->transfer_buffer != NULL)
1266 if (mos7840_port->write_urb->transfer_buffer != NULL) {
1267 kfree(mos7840_port->write_urb->transfer_buffer); 1248 kfree(mos7840_port->write_urb->transfer_buffer);
1268 }
1269 usb_free_urb(mos7840_port->write_urb); 1249 usb_free_urb(mos7840_port->write_urb);
1270 } 1250 }
1271 1251
@@ -1302,9 +1282,8 @@ static void mos7840_block_until_chase_response(struct tty_struct *tty,
1302 count = mos7840_chars_in_buffer(tty); 1282 count = mos7840_chars_in_buffer(tty);
1303 1283
1304 /* Check for Buffer status */ 1284 /* Check for Buffer status */
1305 if (count <= 0) { 1285 if (count <= 0)
1306 return; 1286 return;
1307 }
1308 1287
1309 /* Block the thread for a while */ 1288 /* Block the thread for a while */
1310 interruptible_sleep_on_timeout(&mos7840_port->wait_chase, 1289 interruptible_sleep_on_timeout(&mos7840_port->wait_chase,
@@ -1349,9 +1328,8 @@ static void mos7840_break(struct tty_struct *tty, int break_state)
1349 1328
1350 mos7840_port = mos7840_get_port_private(port); 1329 mos7840_port = mos7840_get_port_private(port);
1351 1330
1352 if (mos7840_port == NULL) { 1331 if (mos7840_port == NULL)
1353 return; 1332 return;
1354 }
1355 1333
1356 if (serial->dev) 1334 if (serial->dev)
1357 /* flush and block until tx is empty */ 1335 /* flush and block until tx is empty */
@@ -1403,9 +1381,8 @@ static int mos7840_write_room(struct tty_struct *tty)
1403 1381
1404 spin_lock_irqsave(&mos7840_port->pool_lock, flags); 1382 spin_lock_irqsave(&mos7840_port->pool_lock, flags);
1405 for (i = 0; i < NUM_URBS; ++i) { 1383 for (i = 0; i < NUM_URBS; ++i) {
1406 if (!mos7840_port->busy[i]) { 1384 if (!mos7840_port->busy[i])
1407 room += URB_TRANSFER_BUFFER_SIZE; 1385 room += URB_TRANSFER_BUFFER_SIZE;
1408 }
1409 } 1386 }
1410 spin_unlock_irqrestore(&mos7840_port->pool_lock, flags); 1387 spin_unlock_irqrestore(&mos7840_port->pool_lock, flags);
1411 1388
@@ -1435,45 +1412,41 @@ static int mos7840_write(struct tty_struct *tty, struct usb_serial_port *port,
1435 struct moschip_port *mos7840_port; 1412 struct moschip_port *mos7840_port;
1436 struct usb_serial *serial; 1413 struct usb_serial *serial;
1437 struct urb *urb; 1414 struct urb *urb;
1438 //__u16 Data; 1415 /* __u16 Data; */
1439 const unsigned char *current_position = data; 1416 const unsigned char *current_position = data;
1440 unsigned char *data1; 1417 unsigned char *data1;
1441 dbg("%s \n", "entering ..........."); 1418 dbg("%s \n", "entering ...........");
1442 //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); */
1443 1421
1444#ifdef NOTMOS7840 1422#ifdef NOTMOS7840
1445 Data = 0x00; 1423 Data = 0x00;
1446 status = 0;
1447 status = mos7840_get_uart_reg(port, LINE_CONTROL_REGISTER, &Data); 1424 status = mos7840_get_uart_reg(port, LINE_CONTROL_REGISTER, &Data);
1448 mos7840_port->shadowLCR = Data; 1425 mos7840_port->shadowLCR = Data;
1449 dbg("mos7840_write: LINE_CONTROL_REGISTER is %x\n", Data); 1426 dbg("mos7840_write: LINE_CONTROL_REGISTER is %x\n", Data);
1450 dbg("mos7840_write: mos7840_port->shadowLCR is %x\n", 1427 dbg("mos7840_write: mos7840_port->shadowLCR is %x\n",
1451 mos7840_port->shadowLCR); 1428 mos7840_port->shadowLCR);
1452 1429
1453 //Data = 0x03; 1430 /* Data = 0x03; */
1454 //status = mos7840_set_uart_reg(port,LINE_CONTROL_REGISTER,Data); 1431 /* status = mos7840_set_uart_reg(port,LINE_CONTROL_REGISTER,Data); */
1455 //mos7840_port->shadowLCR=Data;//Need to add later 1432 /* mos7840_port->shadowLCR=Data;//Need to add later */
1456 1433
1457 Data |= SERIAL_LCR_DLAB; //data latch enable in LCR 0x80 1434 Data |= SERIAL_LCR_DLAB; /* data latch enable in LCR 0x80 */
1458 status = 0;
1459 status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data); 1435 status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
1460 1436
1461 //Data = 0x0c; 1437 /* Data = 0x0c; */
1462 //status = mos7840_set_uart_reg(port,DIVISOR_LATCH_LSB,Data); 1438 /* status = mos7840_set_uart_reg(port,DIVISOR_LATCH_LSB,Data); */
1463 Data = 0x00; 1439 Data = 0x00;
1464 status = 0;
1465 status = mos7840_get_uart_reg(port, DIVISOR_LATCH_LSB, &Data); 1440 status = mos7840_get_uart_reg(port, DIVISOR_LATCH_LSB, &Data);
1466 dbg("mos7840_write:DLL value is %x\n", Data); 1441 dbg("mos7840_write:DLL value is %x\n", Data);
1467 1442
1468 Data = 0x0; 1443 Data = 0x0;
1469 status = 0;
1470 status = mos7840_get_uart_reg(port, DIVISOR_LATCH_MSB, &Data); 1444 status = mos7840_get_uart_reg(port, DIVISOR_LATCH_MSB, &Data);
1471 dbg("mos7840_write:DLM value is %x\n", Data); 1445 dbg("mos7840_write:DLM value is %x\n", Data);
1472 1446
1473 Data = Data & ~SERIAL_LCR_DLAB; 1447 Data = Data & ~SERIAL_LCR_DLAB;
1474 dbg("mos7840_write: mos7840_port->shadowLCR is %x\n", 1448 dbg("mos7840_write: mos7840_port->shadowLCR is %x\n",
1475 mos7840_port->shadowLCR); 1449 mos7840_port->shadowLCR);
1476 status = 0;
1477 status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data); 1450 status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
1478#endif 1451#endif
1479 1452
@@ -1598,7 +1571,6 @@ static void mos7840_throttle(struct tty_struct *tty)
1598 /* if we are implementing RTS/CTS, toggle that line */ 1571 /* if we are implementing RTS/CTS, toggle that line */
1599 if (tty->termios->c_cflag & CRTSCTS) { 1572 if (tty->termios->c_cflag & CRTSCTS) {
1600 mos7840_port->shadowMCR &= ~MCR_RTS; 1573 mos7840_port->shadowMCR &= ~MCR_RTS;
1601 status = 0;
1602 status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, 1574 status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER,
1603 mos7840_port->shadowMCR); 1575 mos7840_port->shadowMCR);
1604 if (status < 0) 1576 if (status < 0)
@@ -1610,8 +1582,9 @@ static void mos7840_throttle(struct tty_struct *tty)
1610 1582
1611/***************************************************************************** 1583/*****************************************************************************
1612 * mos7840_unthrottle 1584 * mos7840_unthrottle
1613 * 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
1614 * 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)
1615 *****************************************************************************/ 1588 *****************************************************************************/
1616static void mos7840_unthrottle(struct tty_struct *tty) 1589static void mos7840_unthrottle(struct tty_struct *tty)
1617{ 1590{
@@ -1645,7 +1618,6 @@ static void mos7840_unthrottle(struct tty_struct *tty)
1645 /* if we are implementing RTS/CTS, toggle that line */ 1618 /* if we are implementing RTS/CTS, toggle that line */
1646 if (tty->termios->c_cflag & CRTSCTS) { 1619 if (tty->termios->c_cflag & CRTSCTS) {
1647 mos7840_port->shadowMCR |= MCR_RTS; 1620 mos7840_port->shadowMCR |= MCR_RTS;
1648 status = 0;
1649 status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, 1621 status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER,
1650 mos7840_port->shadowMCR); 1622 mos7840_port->shadowMCR);
1651 if (status < 0) 1623 if (status < 0)
@@ -1660,7 +1632,7 @@ static int mos7840_tiocmget(struct tty_struct *tty, struct file *file)
1660 unsigned int result; 1632 unsigned int result;
1661 __u16 msr; 1633 __u16 msr;
1662 __u16 mcr; 1634 __u16 mcr;
1663 int status = 0; 1635 int status;
1664 mos7840_port = mos7840_get_port_private(port); 1636 mos7840_port = mos7840_get_port_private(port);
1665 1637
1666 dbg("%s - port %d", __func__, port->number); 1638 dbg("%s - port %d", __func__, port->number);
@@ -1731,7 +1703,7 @@ static int mos7840_tiocmset(struct tty_struct *tty, struct file *file,
1731 * baud rate. 1703 * baud rate.
1732 *****************************************************************************/ 1704 *****************************************************************************/
1733static int mos7840_calc_baud_rate_divisor(int baudRate, int *divisor, 1705static int mos7840_calc_baud_rate_divisor(int baudRate, int *divisor,
1734 __u16 * clk_sel_val) 1706 __u16 *clk_sel_val)
1735{ 1707{
1736 1708
1737 dbg("%s - %d", __func__, baudRate); 1709 dbg("%s - %d", __func__, baudRate);
@@ -1783,9 +1755,8 @@ static int mos7840_calc_baud_rate_divisor(int baudRate, int *divisor,
1783 /* Check for round off */ 1755 /* Check for round off */
1784 round1 = (__u16) (2304000L / baudrate); 1756 round1 = (__u16) (2304000L / baudrate);
1785 round = (__u16) (round1 - (custom * 10)); 1757 round = (__u16) (round1 - (custom * 10));
1786 if (round > 4) { 1758 if (round > 4)
1787 custom++; 1759 custom++;
1788 }
1789 *divisor = custom; 1760 *divisor = custom;
1790 1761
1791 dbg(" Baud %d = %d\n", baudrate, custom); 1762 dbg(" Baud %d = %d\n", baudrate, custom);
@@ -1833,16 +1804,15 @@ static int mos7840_send_cmd_write_baud_rate(struct moschip_port *mos7840_port,
1833 1804
1834 dbg("%s - port = %d, baud = %d", __func__, 1805 dbg("%s - port = %d, baud = %d", __func__,
1835 mos7840_port->port->number, baudRate); 1806 mos7840_port->port->number, baudRate);
1836 //reset clk_uart_sel in spregOffset 1807 /* reset clk_uart_sel in spregOffset */
1837 if (baudRate > 115200) { 1808 if (baudRate > 115200) {
1838#ifdef HW_flow_control 1809#ifdef HW_flow_control
1839 //NOTE: need to see the pther register to modify 1810 /* NOTE: need to see the pther register to modify */
1840 //setting h/w flow control bit to 1; 1811 /* setting h/w flow control bit to 1 */
1841 status = 0;
1842 Data = 0x2b; 1812 Data = 0x2b;
1843 mos7840_port->shadowMCR = Data; 1813 mos7840_port->shadowMCR = Data;
1844 status = 1814 status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER,
1845 mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data); 1815 Data);
1846 if (status < 0) { 1816 if (status < 0) {
1847 dbg("Writing spreg failed in set_serial_baud\n"); 1817 dbg("Writing spreg failed in set_serial_baud\n");
1848 return -1; 1818 return -1;
@@ -1851,12 +1821,11 @@ static int mos7840_send_cmd_write_baud_rate(struct moschip_port *mos7840_port,
1851 1821
1852 } else { 1822 } else {
1853#ifdef HW_flow_control 1823#ifdef HW_flow_control
1854 //setting h/w flow control bit to 0; 1824 / *setting h/w flow control bit to 0 */
1855 status = 0;
1856 Data = 0xb; 1825 Data = 0xb;
1857 mos7840_port->shadowMCR = Data; 1826 mos7840_port->shadowMCR = Data;
1858 status = 1827 status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER,
1859 mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data); 1828 Data);
1860 if (status < 0) { 1829 if (status < 0) {
1861 dbg("Writing spreg failed in set_serial_baud\n"); 1830 dbg("Writing spreg failed in set_serial_baud\n");
1862 return -1; 1831 return -1;
@@ -1865,25 +1834,20 @@ static int mos7840_send_cmd_write_baud_rate(struct moschip_port *mos7840_port,
1865 1834
1866 } 1835 }
1867 1836
1868 if (1) //baudRate <= 115200) 1837 if (1) { /* baudRate <= 115200) */
1869 {
1870 clk_sel_val = 0x0; 1838 clk_sel_val = 0x0;
1871 Data = 0x0; 1839 Data = 0x0;
1872 status = 0; 1840 status = mos7840_calc_baud_rate_divisor(baudRate, &divisor,
1873 status =
1874 mos7840_calc_baud_rate_divisor(baudRate, &divisor,
1875 &clk_sel_val); 1841 &clk_sel_val);
1876 status = 1842 status = mos7840_get_reg_sync(port, mos7840_port->SpRegOffset,
1877 mos7840_get_reg_sync(port, mos7840_port->SpRegOffset, 1843 &Data);
1878 &Data);
1879 if (status < 0) { 1844 if (status < 0) {
1880 dbg("reading spreg failed in set_serial_baud\n"); 1845 dbg("reading spreg failed in set_serial_baud\n");
1881 return -1; 1846 return -1;
1882 } 1847 }
1883 Data = (Data & 0x8f) | clk_sel_val; 1848 Data = (Data & 0x8f) | clk_sel_val;
1884 status = 0; 1849 status = mos7840_set_reg_sync(port, mos7840_port->SpRegOffset,
1885 status = 1850 Data);
1886 mos7840_set_reg_sync(port, mos7840_port->SpRegOffset, Data);
1887 if (status < 0) { 1851 if (status < 0) {
1888 dbg("Writing spreg failed in set_serial_baud\n"); 1852 dbg("Writing spreg failed in set_serial_baud\n");
1889 return -1; 1853 return -1;
@@ -1915,7 +1879,6 @@ static int mos7840_send_cmd_write_baud_rate(struct moschip_port *mos7840_port,
1915 mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data); 1879 mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
1916 1880
1917 } 1881 }
1918
1919 return status; 1882 return status;
1920} 1883}
1921 1884
@@ -2006,9 +1969,8 @@ static void mos7840_change_port_settings(struct tty_struct *tty,
2006 dbg("%s - parity = none", __func__); 1969 dbg("%s - parity = none", __func__);
2007 } 1970 }
2008 1971
2009 if (cflag & CMSPAR) { 1972 if (cflag & CMSPAR)
2010 lParity = lParity | 0x20; 1973 lParity = lParity | 0x20;
2011 }
2012 1974
2013 /* Change the Stop bit */ 1975 /* Change the Stop bit */
2014 if (cflag & CSTOPB) { 1976 if (cflag & CSTOPB) {
@@ -2050,16 +2012,13 @@ static void mos7840_change_port_settings(struct tty_struct *tty,
2050 /* set up the MCR register and send it to the mos7840 */ 2012 /* set up the MCR register and send it to the mos7840 */
2051 2013
2052 mos7840_port->shadowMCR = MCR_MASTER_IE; 2014 mos7840_port->shadowMCR = MCR_MASTER_IE;
2053 if (cflag & CBAUD) { 2015 if (cflag & CBAUD)
2054 mos7840_port->shadowMCR |= (MCR_DTR | MCR_RTS); 2016 mos7840_port->shadowMCR |= (MCR_DTR | MCR_RTS);
2055 }
2056 2017
2057 if (cflag & CRTSCTS) { 2018 if (cflag & CRTSCTS)
2058 mos7840_port->shadowMCR |= (MCR_XON_ANY); 2019 mos7840_port->shadowMCR |= (MCR_XON_ANY);
2059 2020 else
2060 } else {
2061 mos7840_port->shadowMCR &= ~(MCR_XON_ANY); 2021 mos7840_port->shadowMCR &= ~(MCR_XON_ANY);
2062 }
2063 2022
2064 Data = mos7840_port->shadowMCR; 2023 Data = mos7840_port->shadowMCR;
2065 mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data); 2024 mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
@@ -2255,7 +2214,6 @@ static int mos7840_set_modem_info(struct moschip_port *mos7840_port,
2255 mos7840_port->shadowMCR = mcr; 2214 mos7840_port->shadowMCR = mcr;
2256 2215
2257 Data = mos7840_port->shadowMCR; 2216 Data = mos7840_port->shadowMCR;
2258 status = 0;
2259 status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data); 2217 status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
2260 if (status < 0) { 2218 if (status < 0) {
2261 dbg("setting MODEM_CONTROL_REGISTER Failed\n"); 2219 dbg("setting MODEM_CONTROL_REGISTER Failed\n");
@@ -2276,8 +2234,7 @@ static int mos7840_get_modem_info(struct moschip_port *mos7840_port,
2276 unsigned int result = 0; 2234 unsigned int result = 0;
2277 __u16 msr; 2235 __u16 msr;
2278 unsigned int mcr = mos7840_port->shadowMCR; 2236 unsigned int mcr = mos7840_port->shadowMCR;
2279 int status = 0; 2237 mos7840_get_uart_reg(mos7840_port->port,
2280 status = mos7840_get_uart_reg(mos7840_port->port,
2281 MODEM_STATUS_REGISTER, &msr); 2238 MODEM_STATUS_REGISTER, &msr);
2282 result = ((mcr & MCR_DTR) ? TIOCM_DTR : 0) /* 0x002 */ 2239 result = ((mcr & MCR_DTR) ? TIOCM_DTR : 0) /* 0x002 */
2283 |((mcr & MCR_RTS) ? TIOCM_RTS : 0) /* 0x004 */ 2240 |((mcr & MCR_RTS) ? TIOCM_RTS : 0) /* 0x004 */
@@ -2389,7 +2346,7 @@ static int mos7840_ioctl(struct tty_struct *tty, struct file *file,
2389 dbg("%s (%d) TIOCMIWAIT", __func__, port->number); 2346 dbg("%s (%d) TIOCMIWAIT", __func__, port->number);
2390 cprev = mos7840_port->icount; 2347 cprev = mos7840_port->icount;
2391 while (1) { 2348 while (1) {
2392 //interruptible_sleep_on(&mos7840_port->delta_msr_wait); 2349 /* interruptible_sleep_on(&mos7840_port->delta_msr_wait); */
2393 mos7840_port->delta_msr_cond = 0; 2350 mos7840_port->delta_msr_cond = 0;
2394 wait_event_interruptible(mos7840_port->delta_msr_wait, 2351 wait_event_interruptible(mos7840_port->delta_msr_wait,
2395 (mos7840_port-> 2352 (mos7840_port->
@@ -2494,8 +2451,9 @@ static int mos7840_startup(struct usb_serial *serial)
2494 goto error; 2451 goto error;
2495 } 2452 }
2496 2453
2497 /* Initialize all port interrupt end point to port 0 int endpoint * 2454 /* Initialize all port interrupt end point to port 0 int
2498 * 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 */
2499 2457
2500 mos7840_port->port = serial->port[i]; 2458 mos7840_port->port = serial->port[i];
2501 mos7840_set_port_private(serial->port[i], mos7840_port); 2459 mos7840_set_port_private(serial->port[i], mos7840_port);
@@ -2531,27 +2489,23 @@ static int mos7840_startup(struct usb_serial *serial)
2531 mos7840_port->DcrRegOffset = 0x1c; 2489 mos7840_port->DcrRegOffset = 0x1c;
2532 } 2490 }
2533 mos7840_dump_serial_port(mos7840_port); 2491 mos7840_dump_serial_port(mos7840_port);
2534
2535 mos7840_set_port_private(serial->port[i], mos7840_port); 2492 mos7840_set_port_private(serial->port[i], mos7840_port);
2536 2493
2537 //enable rx_disable bit in control register 2494 /* enable rx_disable bit in control register */
2538 2495 status = mos7840_get_reg_sync(serial->port[i],
2539 status = 2496 mos7840_port->ControlRegOffset, &Data);
2540 mos7840_get_reg_sync(serial->port[i],
2541 mos7840_port->ControlRegOffset, &Data);
2542 if (status < 0) { 2497 if (status < 0) {
2543 dbg("Reading ControlReg failed status-0x%x\n", status); 2498 dbg("Reading ControlReg failed status-0x%x\n", status);
2544 break; 2499 break;
2545 } else 2500 } else
2546 dbg("ControlReg Reading success val is %x, status%d\n", 2501 dbg("ControlReg Reading success val is %x, status%d\n",
2547 Data, status); 2502 Data, status);
2548 Data |= 0x08; //setting driver done bit 2503 Data |= 0x08; /* setting driver done bit */
2549 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 */
2550 2506
2551 //Data |= 0x20; //rx_disable bit 2507 /* Data |= 0x20; //rx_disable bit */
2552 status = 0; 2508 status = mos7840_set_reg_sync(serial->port[i],
2553 status =
2554 mos7840_set_reg_sync(serial->port[i],
2555 mos7840_port->ControlRegOffset, Data); 2509 mos7840_port->ControlRegOffset, Data);
2556 if (status < 0) { 2510 if (status < 0) {
2557 dbg("Writing ControlReg failed(rx_disable) status-0x%x\n", status); 2511 dbg("Writing ControlReg failed(rx_disable) status-0x%x\n", status);
@@ -2560,13 +2514,11 @@ static int mos7840_startup(struct usb_serial *serial)
2560 dbg("ControlReg Writing success(rx_disable) status%d\n", 2514 dbg("ControlReg Writing success(rx_disable) status%d\n",
2561 status); 2515 status);
2562 2516
2563 //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 */
2564 Data = 0x01; 2519 Data = 0x01;
2565 status = 0; 2520 status = mos7840_set_reg_sync(serial->port[i],
2566 status = 2521 (__u16) (mos7840_port->DcrRegOffset + 0), Data);
2567 mos7840_set_reg_sync(serial->port[i],
2568 (__u16) (mos7840_port->DcrRegOffset +
2569 0), Data);
2570 if (status < 0) { 2522 if (status < 0) {
2571 dbg("Writing DCR0 failed status-0x%x\n", status); 2523 dbg("Writing DCR0 failed status-0x%x\n", status);
2572 break; 2524 break;
@@ -2574,11 +2526,8 @@ static int mos7840_startup(struct usb_serial *serial)
2574 dbg("DCR0 Writing success status%d\n", status); 2526 dbg("DCR0 Writing success status%d\n", status);
2575 2527
2576 Data = 0x05; 2528 Data = 0x05;
2577 status = 0; 2529 status = mos7840_set_reg_sync(serial->port[i],
2578 status = 2530 (__u16) (mos7840_port->DcrRegOffset + 1), Data);
2579 mos7840_set_reg_sync(serial->port[i],
2580 (__u16) (mos7840_port->DcrRegOffset +
2581 1), Data);
2582 if (status < 0) { 2531 if (status < 0) {
2583 dbg("Writing DCR1 failed status-0x%x\n", status); 2532 dbg("Writing DCR1 failed status-0x%x\n", status);
2584 break; 2533 break;
@@ -2586,22 +2535,17 @@ static int mos7840_startup(struct usb_serial *serial)
2586 dbg("DCR1 Writing success status%d\n", status); 2535 dbg("DCR1 Writing success status%d\n", status);
2587 2536
2588 Data = 0x24; 2537 Data = 0x24;
2589 status = 0; 2538 status = mos7840_set_reg_sync(serial->port[i],
2590 status = 2539 (__u16) (mos7840_port->DcrRegOffset + 2), Data);
2591 mos7840_set_reg_sync(serial->port[i],
2592 (__u16) (mos7840_port->DcrRegOffset +
2593 2), Data);
2594 if (status < 0) { 2540 if (status < 0) {
2595 dbg("Writing DCR2 failed status-0x%x\n", status); 2541 dbg("Writing DCR2 failed status-0x%x\n", status);
2596 break; 2542 break;
2597 } else 2543 } else
2598 dbg("DCR2 Writing success status%d\n", status); 2544 dbg("DCR2 Writing success status%d\n", status);
2599 2545
2600 // write values in clkstart0x0 and clkmulti 0x20 2546 /* write values in clkstart0x0 and clkmulti 0x20 */
2601 Data = 0x0; 2547 Data = 0x0;
2602 status = 0; 2548 status = mos7840_set_reg_sync(serial->port[i],
2603 status =
2604 mos7840_set_reg_sync(serial->port[i],
2605 CLK_START_VALUE_REGISTER, Data); 2549 CLK_START_VALUE_REGISTER, Data);
2606 if (status < 0) { 2550 if (status < 0) {
2607 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);
@@ -2610,9 +2554,8 @@ static int mos7840_startup(struct usb_serial *serial)
2610 dbg("CLK_START_VALUE_REGISTER Writing success status%d\n", status); 2554 dbg("CLK_START_VALUE_REGISTER Writing success status%d\n", status);
2611 2555
2612 Data = 0x20; 2556 Data = 0x20;
2613 status = 2557 status = mos7840_set_reg_sync(serial->port[i],
2614 mos7840_set_reg_sync(serial->port[i], CLK_MULTI_REGISTER, 2558 CLK_MULTI_REGISTER, Data);
2615 Data);
2616 if (status < 0) { 2559 if (status < 0) {
2617 dbg("Writing CLK_MULTI_REGISTER failed status-0x%x\n", 2560 dbg("Writing CLK_MULTI_REGISTER failed status-0x%x\n",
2618 status); 2561 status);
@@ -2621,11 +2564,10 @@ static int mos7840_startup(struct usb_serial *serial)
2621 dbg("CLK_MULTI_REGISTER Writing success status%d\n", 2564 dbg("CLK_MULTI_REGISTER Writing success status%d\n",
2622 status); 2565 status);
2623 2566
2624 //write value 0x0 to scratchpad register 2567 /* write value 0x0 to scratchpad register */
2625 Data = 0x00; 2568 Data = 0x00;
2626 status = 2569 status = mos7840_set_uart_reg(serial->port[i],
2627 mos7840_set_uart_reg(serial->port[i], SCRATCH_PAD_REGISTER, 2570 SCRATCH_PAD_REGISTER, Data);
2628 Data);
2629 if (status < 0) { 2571 if (status < 0) {
2630 dbg("Writing SCRATCH_PAD_REGISTER failed status-0x%x\n", 2572 dbg("Writing SCRATCH_PAD_REGISTER failed status-0x%x\n",
2631 status); 2573 status);
@@ -2634,21 +2576,17 @@ static int mos7840_startup(struct usb_serial *serial)
2634 dbg("SCRATCH_PAD_REGISTER Writing success status%d\n", 2576 dbg("SCRATCH_PAD_REGISTER Writing success status%d\n",
2635 status); 2577 status);
2636 2578
2637 //Zero Length flag register 2579 /* Zero Length flag register */
2638 if ((mos7840_port->port_num != 1) 2580 if ((mos7840_port->port_num != 1)
2639 && (serial->num_ports == 2)) { 2581 && (serial->num_ports == 2)) {
2640 2582
2641 Data = 0xff; 2583 Data = 0xff;
2642 status = 0;
2643 status = mos7840_set_reg_sync(serial->port[i], 2584 status = mos7840_set_reg_sync(serial->port[i],
2644 (__u16) (ZLP_REG1 + 2585 (__u16) (ZLP_REG1 +
2645 ((__u16) 2586 ((__u16)mos7840_port->port_num)), Data);
2646 mos7840_port->
2647 port_num)),
2648 Data);
2649 dbg("ZLIP offset%x\n", 2587 dbg("ZLIP offset%x\n",
2650 (__u16) (ZLP_REG1 + 2588 (__u16) (ZLP_REG1 +
2651 ((__u16) mos7840_port->port_num))); 2589 ((__u16) mos7840_port->port_num)));
2652 if (status < 0) { 2590 if (status < 0) {
2653 dbg("Writing ZLP_REG%d failed status-0x%x\n", 2591 dbg("Writing ZLP_REG%d failed status-0x%x\n",
2654 i + 2, status); 2592 i + 2, status);
@@ -2658,13 +2596,9 @@ static int mos7840_startup(struct usb_serial *serial)
2658 i + 2, status); 2596 i + 2, status);
2659 } else { 2597 } else {
2660 Data = 0xff; 2598 Data = 0xff;
2661 status = 0;
2662 status = mos7840_set_reg_sync(serial->port[i], 2599 status = mos7840_set_reg_sync(serial->port[i],
2663 (__u16) (ZLP_REG1 + 2600 (__u16) (ZLP_REG1 +
2664 ((__u16) 2601 ((__u16)mos7840_port->port_num) - 0x1), Data);
2665 mos7840_port->
2666 port_num) -
2667 0x1), Data);
2668 dbg("ZLIP offset%x\n", 2602 dbg("ZLIP offset%x\n",
2669 (__u16) (ZLP_REG1 + 2603 (__u16) (ZLP_REG1 +
2670 ((__u16) mos7840_port->port_num) - 0x1)); 2604 ((__u16) mos7840_port->port_num) - 0x1));
@@ -2679,14 +2613,16 @@ static int mos7840_startup(struct usb_serial *serial)
2679 } 2613 }
2680 mos7840_port->control_urb = usb_alloc_urb(0, GFP_KERNEL); 2614 mos7840_port->control_urb = usb_alloc_urb(0, GFP_KERNEL);
2681 mos7840_port->ctrl_buf = kmalloc(16, GFP_KERNEL); 2615 mos7840_port->ctrl_buf = kmalloc(16, GFP_KERNEL);
2682 mos7840_port->dr = kmalloc(sizeof(struct usb_ctrlrequest), GFP_KERNEL); 2616 mos7840_port->dr = kmalloc(sizeof(struct usb_ctrlrequest),
2683 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) {
2684 status = -ENOMEM; 2620 status = -ENOMEM;
2685 goto error; 2621 goto error;
2686 } 2622 }
2687 } 2623 }
2688 2624
2689 //Zero Length flag enable 2625 /* Zero Length flag enable */
2690 Data = 0x0f; 2626 Data = 0x0f;
2691 status = mos7840_set_reg_sync(serial->port[0], ZLP_REG5, Data); 2627 status = mos7840_set_reg_sync(serial->port[0], ZLP_REG5, Data);
2692 if (status < 0) { 2628 if (status < 0) {
@@ -2729,7 +2665,7 @@ static void mos7840_shutdown(struct usb_serial *serial)
2729 return; 2665 return;
2730 } 2666 }
2731 2667
2732 /* 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 */
2733 2669
2734 /* free private structure allocated for serial port * 2670 /* free private structure allocated for serial port *
2735 * stop reads and writes on all ports */ 2671 * stop reads and writes on all ports */
@@ -2810,20 +2746,12 @@ static int __init moschip7840_init(void)
2810 2746
2811 /* Register with the usb */ 2747 /* Register with the usb */
2812 retval = usb_register(&io_driver); 2748 retval = usb_register(&io_driver);
2813
2814 if (retval)
2815 goto failed_usb_register;
2816
2817 if (retval == 0) { 2749 if (retval == 0) {
2818 dbg("%s\n", "Leaving..."); 2750 dbg("%s\n", "Leaving...");
2819 return 0; 2751 return 0;
2820 } 2752 }
2821
2822 failed_usb_register:
2823 usb_serial_deregister(&moschip7840_4port_device); 2753 usb_serial_deregister(&moschip7840_4port_device);
2824 2754failed_port_device_register:
2825 failed_port_device_register:
2826
2827 return retval; 2755 return retval;
2828} 2756}
2829 2757