aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/serial/mos7720.c
diff options
context:
space:
mode:
authorMike Dunn <mikedunn@newsguy.com>2010-04-15 17:02:09 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2010-05-20 16:21:39 -0400
commit63b917678fe6d63e633462b5be5a309511bcf3ca (patch)
tree2d03d66392268b94d0f1b69a7a194470b99a2013 /drivers/usb/serial/mos7720.c
parentb69578df7e98659b7d94c905971a6d1025b431ad (diff)
USB: usbserial: mos7720: cleanup, consolidation, replace send_mos_cmd with {read,write}_mos_reg
No functionality added or bugs fixed, just improved code consistency and (hopefully) readability by replacing send_mos_cmd with the register read & write functions that were used for parallel port registers. Also shortens overall file length. Thoroughly tested, with emphasis on regression testing the serial port. Signed-off-by: Mike Dunn <mikedunn@newsguy.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb/serial/mos7720.c')
-rw-r--r--drivers/usb/serial/mos7720.c388
1 files changed, 122 insertions, 266 deletions
diff --git a/drivers/usb/serial/mos7720.c b/drivers/usb/serial/mos7720.c
index 2d35d11d04e3..30922a7e3347 100644
--- a/drivers/usb/serial/mos7720.c
+++ b/drivers/usb/serial/mos7720.c
@@ -39,16 +39,13 @@
39/* 39/*
40 * Version Information 40 * Version Information
41 */ 41 */
42#define DRIVER_VERSION "2.0" 42#define DRIVER_VERSION "2.1"
43#define DRIVER_AUTHOR "Aspire Communications pvt Ltd." 43#define DRIVER_AUTHOR "Aspire Communications pvt Ltd."
44#define DRIVER_DESC "Moschip USB Serial Driver" 44#define DRIVER_DESC "Moschip USB Serial Driver"
45 45
46/* default urb timeout */ 46/* default urb timeout */
47#define MOS_WDR_TIMEOUT (HZ * 5) 47#define MOS_WDR_TIMEOUT (HZ * 5)
48 48
49#define MOS_PORT1 0x0200
50#define MOS_PORT2 0x0300
51#define MOS_VENREG 0x0000
52#define MOS_MAX_PORT 0x02 49#define MOS_MAX_PORT 0x02
53#define MOS_WRITE 0x0E 50#define MOS_WRITE 0x0E
54#define MOS_READ 0x0D 51#define MOS_READ 0x0D
@@ -126,6 +123,10 @@ struct mos7715_parport {
126/* lock guards against dereferencing NULL ptr in parport ops callbacks */ 123/* lock guards against dereferencing NULL ptr in parport ops callbacks */
127static DEFINE_SPINLOCK(release_lock); 124static DEFINE_SPINLOCK(release_lock);
128 125
126#endif /* CONFIG_USB_SERIAL_MOS7715_PARPORT */
127
128static const unsigned int dummy; /* for clarity in register access fns */
129
129enum mos_regs { 130enum mos_regs {
130 THR, /* serial port regs */ 131 THR, /* serial port regs */
131 RHR, 132 RHR,
@@ -184,32 +185,35 @@ static inline __u16 get_reg_index(enum mos_regs reg)
184 * Return the correct value for the upper byte of the Wvalue field of 185 * Return the correct value for the upper byte of the Wvalue field of
185 * the setup packet for a control endpoint message. 186 * the setup packet for a control endpoint message.
186 */ 187 */
187static inline __u16 get_reg_value(enum mos_regs reg) 188static inline __u16 get_reg_value(enum mos_regs reg,
189 unsigned int serial_portnum)
188{ 190{
189 if (reg >= SP1_REG) /* control reg */ 191 if (reg >= SP1_REG) /* control reg */
190 return 0x0000; 192 return 0x0000;
191 else /* parallel port reg (7715 only) */ 193
194 else if (reg >= DPR) /* parallel port reg (7715 only) */
192 return 0x0100; 195 return 0x0100;
196
197 else /* serial port reg */
198 return (serial_portnum + 2) << 8;
193} 199}
194 200
195/* 201/*
196 * Write data byte to the specified device register. The data is embedded in 202 * Write data byte to the specified device register. The data is embedded in
197 * the value field of the setup packet. 203 * the value field of the setup packet. serial_portnum is ignored for registers
204 * not specific to a particular serial port.
198 */ 205 */
199static int write_parport_reg(struct mos7715_parport *mos_parport, 206static int write_mos_reg(struct usb_serial *serial, unsigned int serial_portnum,
200 enum mos_regs reg, __u8 data) 207 enum mos_regs reg, __u8 data)
201{ 208{
202 struct usb_serial *serial = mos_parport->serial;
203 struct usb_device *usbdev = serial->dev; 209 struct usb_device *usbdev = serial->dev;
204 unsigned int pipe = usb_sndctrlpipe(usbdev, 0); 210 unsigned int pipe = usb_sndctrlpipe(usbdev, 0);
205 __u8 request = (__u8)0x0e; 211 __u8 request = (__u8)0x0e;
206 __u8 requesttype = (__u8)0x40; 212 __u8 requesttype = (__u8)0x40;
207 __u16 value = get_reg_value(reg) + data;
208 __u16 index = get_reg_index(reg); 213 __u16 index = get_reg_index(reg);
209 __u16 size = 0; 214 __u16 value = get_reg_value(reg, serial_portnum) + data;
210 int status; 215 int status = usb_control_msg(usbdev, pipe, request, requesttype, value,
211 status = usb_control_msg(usbdev, pipe, request, requesttype, value, 216 index, NULL, 0, MOS_WDR_TIMEOUT);
212 index, NULL, size, MOS_WDR_TIMEOUT);
213 if (status < 0) 217 if (status < 0)
214 dev_err(&usbdev->dev, 218 dev_err(&usbdev->dev,
215 "mos7720: usb_control_msg() failed: %d", status); 219 "mos7720: usb_control_msg() failed: %d", status);
@@ -218,31 +222,33 @@ static int write_parport_reg(struct mos7715_parport *mos_parport,
218 222
219/* 223/*
220 * Read data byte from the specified device register. The data returned by the 224 * Read data byte from the specified device register. The data returned by the
221 * device is embedded in the value field of the setup packet. 225 * device is embedded in the value field of the setup packet. serial_portnum is
226 * ignored for registers that are not specific to a particular serial port.
222 */ 227 */
223static int read_parport_reg(struct mos7715_parport *mos_parport, 228static int read_mos_reg(struct usb_serial *serial, unsigned int serial_portnum,
224 enum mos_regs reg, __u8 *data) 229 enum mos_regs reg, __u8 *data)
225{ 230{
226 struct usb_device *usbdev = mos_parport->serial->dev; 231 struct usb_device *usbdev = serial->dev;
227 unsigned int pipe = usb_rcvctrlpipe(usbdev, 0); 232 unsigned int pipe = usb_rcvctrlpipe(usbdev, 0);
228 __u8 request = (__u8)0x0d; 233 __u8 request = (__u8)0x0d;
229 __u8 requesttype = (__u8)0xc0; 234 __u8 requesttype = (__u8)0xc0;
230 __u16 value = get_reg_value(reg);
231 __u16 index = get_reg_index(reg); 235 __u16 index = get_reg_index(reg);
232 __u16 size = 1; 236 __u16 value = get_reg_value(reg, serial_portnum);
233 int status = usb_control_msg(usbdev, pipe, request, requesttype, value, 237 int status = usb_control_msg(usbdev, pipe, request, requesttype, value,
234 index, data, size, MOS_WDR_TIMEOUT); 238 index, data, 1, MOS_WDR_TIMEOUT);
235 if (status < 0) 239 if (status < 0)
236 dev_err(&usbdev->dev, 240 dev_err(&usbdev->dev,
237 "mos7720: usb_control_msg() failed: %d", status); 241 "mos7720: usb_control_msg() failed: %d", status);
238 return status; 242 return status;
239} 243}
240 244
245#ifdef CONFIG_USB_SERIAL_MOS7715_PARPORT
246
241static inline int mos7715_change_mode(struct mos7715_parport *mos_parport, 247static inline int mos7715_change_mode(struct mos7715_parport *mos_parport,
242 enum mos7715_pp_modes mode) 248 enum mos7715_pp_modes mode)
243{ 249{
244 mos_parport->shadowECR = mode; 250 mos_parport->shadowECR = mode;
245 write_parport_reg(mos_parport, ECR, mos_parport->shadowECR); 251 write_mos_reg(mos_parport->serial, dummy, ECR, mos_parport->shadowECR);
246 return 0; 252 return 0;
247} 253}
248 254
@@ -367,7 +373,7 @@ static int write_parport_reg_nonblock(struct mos7715_parport *mos_parport,
367 } 373 }
368 setup.bRequestType = (__u8)0x40; 374 setup.bRequestType = (__u8)0x40;
369 setup.bRequest = (__u8)0x0e; 375 setup.bRequest = (__u8)0x0e;
370 setup.wValue = get_reg_value(reg); 376 setup.wValue = get_reg_value(reg, dummy);
371 setup.wIndex = get_reg_index(reg); 377 setup.wIndex = get_reg_index(reg);
372 setup.wLength = 0; 378 setup.wLength = 0;
373 usb_fill_control_urb(urbtrack->urb, usbdev, 379 usb_fill_control_urb(urbtrack->urb, usbdev,
@@ -474,7 +480,7 @@ static void parport_mos7715_write_data(struct parport *pp, unsigned char d)
474 if (parport_prologue(pp) < 0) 480 if (parport_prologue(pp) < 0)
475 return; 481 return;
476 mos7715_change_mode(mos_parport, SPP); 482 mos7715_change_mode(mos_parport, SPP);
477 write_parport_reg(mos_parport, DPR, (__u8)d); 483 write_mos_reg(mos_parport->serial, dummy, DPR, (__u8)d);
478 parport_epilogue(pp); 484 parport_epilogue(pp);
479} 485}
480 486
@@ -485,7 +491,7 @@ static unsigned char parport_mos7715_read_data(struct parport *pp)
485 dbg("%s called", __func__); 491 dbg("%s called", __func__);
486 if (parport_prologue(pp) < 0) 492 if (parport_prologue(pp) < 0)
487 return 0; 493 return 0;
488 read_parport_reg(mos_parport, DPR, &d); 494 read_mos_reg(mos_parport->serial, dummy, DPR, &d);
489 parport_epilogue(pp); 495 parport_epilogue(pp);
490 return d; 496 return d;
491} 497}
@@ -498,7 +504,7 @@ static void parport_mos7715_write_control(struct parport *pp, unsigned char d)
498 if (parport_prologue(pp) < 0) 504 if (parport_prologue(pp) < 0)
499 return; 505 return;
500 data = ((__u8)d & 0x0f) | (mos_parport->shadowDCR & 0xf0); 506 data = ((__u8)d & 0x0f) | (mos_parport->shadowDCR & 0xf0);
501 write_parport_reg(mos_parport, DCR, data); 507 write_mos_reg(mos_parport->serial, dummy, DCR, data);
502 mos_parport->shadowDCR = data; 508 mos_parport->shadowDCR = data;
503 parport_epilogue(pp); 509 parport_epilogue(pp);
504} 510}
@@ -531,7 +537,7 @@ static unsigned char parport_mos7715_frob_control(struct parport *pp,
531 if (parport_prologue(pp) < 0) 537 if (parport_prologue(pp) < 0)
532 return 0; 538 return 0;
533 mos_parport->shadowDCR = (mos_parport->shadowDCR & (~mask)) ^ val; 539 mos_parport->shadowDCR = (mos_parport->shadowDCR & (~mask)) ^ val;
534 write_parport_reg(mos_parport, DCR, mos_parport->shadowDCR); 540 write_mos_reg(mos_parport->serial, dummy, DCR, mos_parport->shadowDCR);
535 dcr = mos_parport->shadowDCR & 0x0f; 541 dcr = mos_parport->shadowDCR & 0x0f;
536 parport_epilogue(pp); 542 parport_epilogue(pp);
537 return dcr; 543 return dcr;
@@ -570,7 +576,7 @@ static void parport_mos7715_data_forward(struct parport *pp)
570 return; 576 return;
571 mos7715_change_mode(mos_parport, PS2); 577 mos7715_change_mode(mos_parport, PS2);
572 mos_parport->shadowDCR &= ~0x20; 578 mos_parport->shadowDCR &= ~0x20;
573 write_parport_reg(mos_parport, DCR, mos_parport->shadowDCR); 579 write_mos_reg(mos_parport->serial, dummy, DCR, mos_parport->shadowDCR);
574 parport_epilogue(pp); 580 parport_epilogue(pp);
575} 581}
576 582
@@ -582,7 +588,7 @@ static void parport_mos7715_data_reverse(struct parport *pp)
582 return; 588 return;
583 mos7715_change_mode(mos_parport, PS2); 589 mos7715_change_mode(mos_parport, PS2);
584 mos_parport->shadowDCR |= 0x20; 590 mos_parport->shadowDCR |= 0x20;
585 write_parport_reg(mos_parport, DCR, mos_parport->shadowDCR); 591 write_mos_reg(mos_parport->serial, dummy, DCR, mos_parport->shadowDCR);
586 parport_epilogue(pp); 592 parport_epilogue(pp);
587} 593}
588 594
@@ -705,14 +711,14 @@ static int mos7715_parport_init(struct usb_serial *serial)
705 init_completion(&mos_parport->syncmsg_compl); 711 init_completion(&mos_parport->syncmsg_compl);
706 712
707 /* cycle parallel port reset bit */ 713 /* cycle parallel port reset bit */
708 write_parport_reg(mos_parport, PP_REG, (__u8)0x80); 714 write_mos_reg(mos_parport->serial, dummy, PP_REG, (__u8)0x80);
709 write_parport_reg(mos_parport, PP_REG, (__u8)0x00); 715 write_mos_reg(mos_parport->serial, dummy, PP_REG, (__u8)0x00);
710 716
711 /* initialize device registers */ 717 /* initialize device registers */
712 mos_parport->shadowDCR = DCR_INIT_VAL; 718 mos_parport->shadowDCR = DCR_INIT_VAL;
713 write_parport_reg(mos_parport, DCR, mos_parport->shadowDCR); 719 write_mos_reg(mos_parport->serial, dummy, DCR, mos_parport->shadowDCR);
714 mos_parport->shadowECR = ECR_INIT_VAL; 720 mos_parport->shadowECR = ECR_INIT_VAL;
715 write_parport_reg(mos_parport, ECR, mos_parport->shadowECR); 721 write_mos_reg(mos_parport->serial, dummy, ECR, mos_parport->shadowECR);
716 722
717 /* register with parport core */ 723 /* register with parport core */
718 mos_parport->pp = parport_register_port(0, PARPORT_IRQ_NONE, 724 mos_parport->pp = parport_register_port(0, PARPORT_IRQ_NONE,
@@ -754,7 +760,6 @@ static void mos7720_interrupt_callback(struct urb *urb)
754 case -ECONNRESET: 760 case -ECONNRESET:
755 case -ENOENT: 761 case -ENOENT:
756 case -ESHUTDOWN: 762 case -ESHUTDOWN:
757 case -ENODEV:
758 /* this urb is terminated, clean up */ 763 /* this urb is terminated, clean up */
759 dbg("%s - urb shutting down with status: %d", __func__, 764 dbg("%s - urb shutting down with status: %d", __func__,
760 status); 765 status);
@@ -981,56 +986,6 @@ static void mos7720_bulk_out_data_callback(struct urb *urb)
981} 986}
982 987
983/* 988/*
984 * send_mos_cmd
985 * this function will be used for sending command to device
986 */
987static int send_mos_cmd(struct usb_serial *serial, __u8 request, __u16 value,
988 __u16 index, u8 *data)
989{
990 int status;
991 u8 *buf;
992 u16 product = le16_to_cpu(serial->dev->descriptor.idProduct);
993
994 if (value < MOS_MAX_PORT) {
995 if (product == MOSCHIP_DEVICE_ID_7715)
996 value = 0x0200; /* identifies the 7715's serial port */
997 else
998 value = value*0x100+0x200;
999 } else {
1000 value = 0x0000;
1001 if ((product == MOSCHIP_DEVICE_ID_7715) &&
1002 (index != 0x08)) {
1003 dbg("serial->product== MOSCHIP_DEVICE_ID_7715");
1004 /* index = 0x01 ; */
1005 }
1006 }
1007
1008 if (request == MOS_WRITE) {
1009 value = value + *data;
1010 status = usb_control_msg(serial->dev,
1011 usb_sndctrlpipe(serial->dev, 0), MOS_WRITE,
1012 0x40, value, index, NULL, 0, MOS_WDR_TIMEOUT);
1013 } else {
1014 buf = kmalloc(1, GFP_KERNEL);
1015 if (!buf) {
1016 status = -ENOMEM;
1017 goto out;
1018 }
1019 status = usb_control_msg(serial->dev,
1020 usb_rcvctrlpipe(serial->dev, 0), MOS_READ,
1021 0xc0, value, index, buf, 1, MOS_WDR_TIMEOUT);
1022 *data = *buf;
1023 kfree(buf);
1024 }
1025out:
1026 if (status < 0)
1027 dbg("Command Write failed Value %x index %x", value, index);
1028
1029 return status;
1030}
1031
1032
1033/*
1034 * mos77xx_probe 989 * mos77xx_probe
1035 * this function installs the appropriate read interrupt endpoint callback 990 * this function installs the appropriate read interrupt endpoint callback
1036 * depending on whether the device is a 7720 or 7715, thus avoiding costly 991 * depending on whether the device is a 7720 or 7715, thus avoiding costly
@@ -1066,7 +1021,7 @@ static int mos7720_open(struct tty_struct *tty, struct usb_serial_port *port)
1066 struct moschip_port *mos7720_port; 1021 struct moschip_port *mos7720_port;
1067 int response; 1022 int response;
1068 int port_number; 1023 int port_number;
1069 char data; 1024 __u8 data;
1070 int allocated_urbs = 0; 1025 int allocated_urbs = 0;
1071 int j; 1026 int j;
1072 1027
@@ -1122,65 +1077,35 @@ static int mos7720_open(struct tty_struct *tty, struct usb_serial_port *port)
1122 * 0x08 : SP1/2 Control Reg 1077 * 0x08 : SP1/2 Control Reg
1123 */ 1078 */
1124 port_number = port->number - port->serial->minor; 1079 port_number = port->number - port->serial->minor;
1125 send_mos_cmd(port->serial, MOS_READ, port_number, UART_LSR, &data); 1080 read_mos_reg(serial, port_number, LSR, &data);
1081
1126 dbg("SS::%p LSR:%x", mos7720_port, data); 1082 dbg("SS::%p LSR:%x", mos7720_port, data);
1127 1083
1128 dbg("Check:Sending Command .........."); 1084 dbg("Check:Sending Command ..........");
1129 1085
1130 data = 0x02; 1086 write_mos_reg(serial, dummy, SP1_REG, 0x02);
1131 send_mos_cmd(serial, MOS_WRITE, MOS_MAX_PORT, 0x01, &data); 1087 write_mos_reg(serial, dummy, SP2_REG, 0x02);
1132 data = 0x02;
1133 send_mos_cmd(serial, MOS_WRITE, MOS_MAX_PORT, 0x02, &data);
1134 1088
1135 data = 0x00; 1089 write_mos_reg(serial, port_number, IER, 0x00);
1136 send_mos_cmd(serial, MOS_WRITE, port_number, 0x01, &data); 1090 write_mos_reg(serial, port_number, FCR, 0x00);
1137 data = 0x00;
1138 send_mos_cmd(serial, MOS_WRITE, port_number, 0x02, &data);
1139 1091
1140 data = 0xCF; 1092 write_mos_reg(serial, port_number, FCR, 0xcf);
1141 send_mos_cmd(serial, MOS_WRITE, port_number, 0x02, &data); 1093 mos7720_port->shadowLCR = 0x03;
1142 data = 0x03; 1094 write_mos_reg(serial, port_number, LCR, mos7720_port->shadowLCR);
1143 mos7720_port->shadowLCR = data; 1095 mos7720_port->shadowMCR = 0x0b;
1144 send_mos_cmd(serial, MOS_WRITE, port_number, 0x03, &data); 1096 write_mos_reg(serial, port_number, MCR, mos7720_port->shadowMCR);
1145 data = 0x0b;
1146 mos7720_port->shadowMCR = data;
1147 send_mos_cmd(serial, MOS_WRITE, port_number, 0x04, &data);
1148 data = 0x0b;
1149 send_mos_cmd(serial, MOS_WRITE, port_number, 0x04, &data);
1150
1151 data = 0x00;
1152 send_mos_cmd(serial, MOS_READ, MOS_MAX_PORT, 0x08, &data);
1153 data = 0x00;
1154 send_mos_cmd(serial, MOS_WRITE, MOS_MAX_PORT, 0x08, &data);
1155
1156/* data = 0x00;
1157 send_mos_cmd(serial, MOS_READ, MOS_MAX_PORT, port_number + 1, &data);
1158 data = 0x03;
1159 send_mos_cmd(serial, MOS_WRITE, MOS_MAX_PORT, port_number + 1, &data);
1160 data = 0x00;
1161 send_mos_cmd(port->serial, MOS_WRITE, MOS_MAX_PORT,
1162 port_number + 1, &data);
1163*/
1164 data = 0x00;
1165 send_mos_cmd(serial, MOS_READ, MOS_MAX_PORT, 0x08, &data);
1166 1097
1098 write_mos_reg(serial, port_number, SP_CONTROL_REG, 0x00);
1099 read_mos_reg(serial, dummy, SP_CONTROL_REG, &data);
1167 data = data | (port->number - port->serial->minor + 1); 1100 data = data | (port->number - port->serial->minor + 1);
1168 send_mos_cmd(serial, MOS_WRITE, MOS_MAX_PORT, 0x08, &data); 1101 write_mos_reg(serial, dummy, SP_CONTROL_REG, data);
1169 1102 mos7720_port->shadowLCR = 0x83;
1170 data = 0x83; 1103 write_mos_reg(serial, port_number, LCR, mos7720_port->shadowLCR);
1171 mos7720_port->shadowLCR = data; 1104 write_mos_reg(serial, port_number, THR, 0x0c);
1172 send_mos_cmd(serial, MOS_WRITE, port_number, 0x03, &data); 1105 write_mos_reg(serial, port_number, IER, 0x00);
1173 data = 0x0c; 1106 mos7720_port->shadowLCR = 0x03;
1174 send_mos_cmd(serial, MOS_WRITE, port_number, 0x00, &data); 1107 write_mos_reg(serial, port_number, LCR, mos7720_port->shadowLCR);
1175 data = 0x00; 1108 write_mos_reg(serial, port_number, IER, 0x0c);
1176 send_mos_cmd(serial, MOS_WRITE, port_number, 0x01, &data);
1177 data = 0x03;
1178 mos7720_port->shadowLCR = data;
1179 send_mos_cmd(serial, MOS_WRITE, port_number, 0x03, &data);
1180 data = 0x0c;
1181 send_mos_cmd(serial, MOS_WRITE, port_number, 0x01, &data);
1182 data = 0x0c;
1183 send_mos_cmd(serial, MOS_WRITE, port_number, 0x01, &data);
1184 1109
1185 response = usb_submit_urb(port->read_urb, GFP_KERNEL); 1110 response = usb_submit_urb(port->read_urb, GFP_KERNEL);
1186 if (response) 1111 if (response)
@@ -1236,7 +1161,6 @@ static void mos7720_close(struct usb_serial_port *port)
1236{ 1161{
1237 struct usb_serial *serial; 1162 struct usb_serial *serial;
1238 struct moschip_port *mos7720_port; 1163 struct moschip_port *mos7720_port;
1239 char data;
1240 int j; 1164 int j;
1241 1165
1242 dbg("mos7720_close:entering..."); 1166 dbg("mos7720_close:entering...");
@@ -1269,13 +1193,10 @@ static void mos7720_close(struct usb_serial_port *port)
1269 /* these commands must not be issued if the device has 1193 /* these commands must not be issued if the device has
1270 * been disconnected */ 1194 * been disconnected */
1271 if (!serial->disconnected) { 1195 if (!serial->disconnected) {
1272 data = 0x00; 1196 write_mos_reg(serial, port->number - port->serial->minor,
1273 send_mos_cmd(serial, MOS_WRITE, 1197 MCR, 0x00);
1274 port->number - port->serial->minor, 0x04, &data); 1198 write_mos_reg(serial, port->number - port->serial->minor,
1275 1199 IER, 0x00);
1276 data = 0x00;
1277 send_mos_cmd(serial, MOS_WRITE,
1278 port->number - port->serial->minor, 0x01, &data);
1279 } 1200 }
1280 mutex_unlock(&serial->disc_mutex); 1201 mutex_unlock(&serial->disc_mutex);
1281 mos7720_port->open = 0; 1202 mos7720_port->open = 0;
@@ -1304,8 +1225,8 @@ static void mos7720_break(struct tty_struct *tty, int break_state)
1304 data = mos7720_port->shadowLCR & ~UART_LCR_SBC; 1225 data = mos7720_port->shadowLCR & ~UART_LCR_SBC;
1305 1226
1306 mos7720_port->shadowLCR = data; 1227 mos7720_port->shadowLCR = data;
1307 send_mos_cmd(serial, MOS_WRITE, port->number - port->serial->minor, 1228 write_mos_reg(serial, port->number - port->serial->minor,
1308 0x03, &data); 1229 LCR, mos7720_port->shadowLCR);
1309 1230
1310 return; 1231 return;
1311} 1232}
@@ -1450,9 +1371,8 @@ static void mos7720_throttle(struct tty_struct *tty)
1450 /* if we are implementing RTS/CTS, toggle that line */ 1371 /* if we are implementing RTS/CTS, toggle that line */
1451 if (tty->termios->c_cflag & CRTSCTS) { 1372 if (tty->termios->c_cflag & CRTSCTS) {
1452 mos7720_port->shadowMCR &= ~UART_MCR_RTS; 1373 mos7720_port->shadowMCR &= ~UART_MCR_RTS;
1453 status = send_mos_cmd(port->serial, MOS_WRITE, 1374 write_mos_reg(port->serial, port->number - port->serial->minor,
1454 port->number - port->serial->minor, 1375 MCR, mos7720_port->shadowMCR);
1455 UART_MCR, &mos7720_port->shadowMCR);
1456 if (status != 0) 1376 if (status != 0)
1457 return; 1377 return;
1458 } 1378 }
@@ -1485,9 +1405,8 @@ static void mos7720_unthrottle(struct tty_struct *tty)
1485 /* if we are implementing RTS/CTS, toggle that line */ 1405 /* if we are implementing RTS/CTS, toggle that line */
1486 if (tty->termios->c_cflag & CRTSCTS) { 1406 if (tty->termios->c_cflag & CRTSCTS) {
1487 mos7720_port->shadowMCR |= UART_MCR_RTS; 1407 mos7720_port->shadowMCR |= UART_MCR_RTS;
1488 status = send_mos_cmd(port->serial, MOS_WRITE, 1408 write_mos_reg(port->serial, port->number - port->serial->minor,
1489 port->number - port->serial->minor, 1409 MCR, mos7720_port->shadowMCR);
1490 UART_MCR, &mos7720_port->shadowMCR);
1491 if (status != 0) 1410 if (status != 0)
1492 return; 1411 return;
1493 } 1412 }
@@ -1497,11 +1416,10 @@ static void mos7720_unthrottle(struct tty_struct *tty)
1497static int set_higher_rates(struct moschip_port *mos7720_port, 1416static int set_higher_rates(struct moschip_port *mos7720_port,
1498 unsigned int baud) 1417 unsigned int baud)
1499{ 1418{
1500 unsigned char data;
1501 struct usb_serial_port *port; 1419 struct usb_serial_port *port;
1502 struct usb_serial *serial; 1420 struct usb_serial *serial;
1503 int port_number; 1421 int port_number;
1504 1422 enum mos_regs sp_reg;
1505 if (mos7720_port == NULL) 1423 if (mos7720_port == NULL)
1506 return -EINVAL; 1424 return -EINVAL;
1507 1425
@@ -1514,59 +1432,35 @@ static int set_higher_rates(struct moschip_port *mos7720_port,
1514 dbg("Sending Setting Commands .........."); 1432 dbg("Sending Setting Commands ..........");
1515 port_number = port->number - port->serial->minor; 1433 port_number = port->number - port->serial->minor;
1516 1434
1517 data = 0x000; 1435 write_mos_reg(serial, port_number, IER, 0x00);
1518 send_mos_cmd(serial, MOS_WRITE, port_number, 0x01, &data); 1436 write_mos_reg(serial, port_number, FCR, 0x00);
1519 data = 0x000; 1437 write_mos_reg(serial, port_number, FCR, 0xcf);
1520 send_mos_cmd(serial, MOS_WRITE, port_number, 0x02, &data); 1438 mos7720_port->shadowMCR = 0x0b;
1521 data = 0x0CF; 1439 write_mos_reg(serial, port_number, MCR, mos7720_port->shadowMCR);
1522 send_mos_cmd(serial, MOS_WRITE, port->number, 0x02, &data); 1440 write_mos_reg(serial, dummy, SP_CONTROL_REG, 0x00);
1523 data = 0x00b;
1524 mos7720_port->shadowMCR = data;
1525 send_mos_cmd(serial, MOS_WRITE, port_number, 0x04, &data);
1526 data = 0x00b;
1527 send_mos_cmd(serial, MOS_WRITE, port_number, 0x04, &data);
1528
1529 data = 0x000;
1530 send_mos_cmd(serial, MOS_READ, MOS_MAX_PORT, 0x08, &data);
1531 data = 0x000;
1532 send_mos_cmd(serial, MOS_WRITE, MOS_MAX_PORT, 0x08, &data);
1533
1534 1441
1535 /*********************************************** 1442 /***********************************************
1536 * Set for higher rates * 1443 * Set for higher rates *
1537 ***********************************************/ 1444 ***********************************************/
1538
1539 /* writing baud rate verbatum into uart clock field clearly not right */ 1445 /* writing baud rate verbatum into uart clock field clearly not right */
1540 data = baud * 0x10; 1446 if (port_number == 0)
1541 send_mos_cmd(serial, MOS_WRITE, MOS_MAX_PORT, port_number + 1, &data); 1447 sp_reg = SP1_REG;
1542 1448 else
1543 data = 0x003; 1449 sp_reg = SP2_REG;
1544 send_mos_cmd(serial, MOS_READ, MOS_MAX_PORT, 0x08, &data); 1450 write_mos_reg(serial, dummy, sp_reg, baud * 0x10);
1545 data = 0x003; 1451 write_mos_reg(serial, dummy, SP_CONTROL_REG, 0x03);
1546 send_mos_cmd(serial, MOS_WRITE, MOS_MAX_PORT, 0x08, &data); 1452 mos7720_port->shadowMCR = 0x2b;
1547 1453 write_mos_reg(serial, port_number, MCR, mos7720_port->shadowMCR);
1548 data = 0x02b;
1549 mos7720_port->shadowMCR = data;
1550 send_mos_cmd(serial, MOS_WRITE, port_number, 0x04, &data);
1551 data = 0x02b;
1552 send_mos_cmd(serial, MOS_WRITE, port_number, 0x04, &data);
1553 1454
1554 /*********************************************** 1455 /***********************************************
1555 * Set DLL/DLM 1456 * Set DLL/DLM
1556 ***********************************************/ 1457 ***********************************************/
1557 1458 mos7720_port->shadowLCR = mos7720_port->shadowLCR | UART_LCR_DLAB;
1558 data = mos7720_port->shadowLCR | UART_LCR_DLAB; 1459 write_mos_reg(serial, port_number, LCR, mos7720_port->shadowLCR);
1559 mos7720_port->shadowLCR = data; 1460 write_mos_reg(serial, port_number, DLL, 0x01);
1560 send_mos_cmd(serial, MOS_WRITE, port_number, 0x03, &data); 1461 write_mos_reg(serial, port_number, DLM, 0x00);
1561 1462 mos7720_port->shadowLCR = mos7720_port->shadowLCR & ~UART_LCR_DLAB;
1562 data = 0x001; /* DLL */ 1463 write_mos_reg(serial, port_number, LCR, mos7720_port->shadowLCR);
1563 send_mos_cmd(serial, MOS_WRITE, port_number, 0x00, &data);
1564 data = 0x000; /* DLM */
1565 send_mos_cmd(serial, MOS_WRITE, port_number, 0x01, &data);
1566
1567 data = mos7720_port->shadowLCR & ~UART_LCR_DLAB;
1568 mos7720_port->shadowLCR = data;
1569 send_mos_cmd(serial, MOS_WRITE, port_number, 0x03, &data);
1570 1464
1571 return 0; 1465 return 0;
1572} 1466}
@@ -1654,7 +1548,6 @@ static int send_cmd_write_baud_rate(struct moschip_port *mos7720_port,
1654 struct usb_serial *serial; 1548 struct usb_serial *serial;
1655 int divisor; 1549 int divisor;
1656 int status; 1550 int status;
1657 unsigned char data;
1658 unsigned char number; 1551 unsigned char number;
1659 1552
1660 if (mos7720_port == NULL) 1553 if (mos7720_port == NULL)
@@ -1676,21 +1569,16 @@ static int send_cmd_write_baud_rate(struct moschip_port *mos7720_port,
1676 } 1569 }
1677 1570
1678 /* Enable access to divisor latch */ 1571 /* Enable access to divisor latch */
1679 data = mos7720_port->shadowLCR | UART_LCR_DLAB; 1572 mos7720_port->shadowLCR = mos7720_port->shadowLCR | UART_LCR_DLAB;
1680 mos7720_port->shadowLCR = data; 1573 write_mos_reg(serial, number, LCR, mos7720_port->shadowLCR);
1681 send_mos_cmd(serial, MOS_WRITE, number, UART_LCR, &data);
1682 1574
1683 /* Write the divisor */ 1575 /* Write the divisor */
1684 data = ((unsigned char)(divisor & 0xff)); 1576 write_mos_reg(serial, number, DLL, (__u8)(divisor & 0xff));
1685 send_mos_cmd(serial, MOS_WRITE, number, 0x00, &data); 1577 write_mos_reg(serial, number, DLM, (__u8)((divisor & 0xff00) >> 8));
1686
1687 data = ((unsigned char)((divisor & 0xff00) >> 8));
1688 send_mos_cmd(serial, MOS_WRITE, number, 0x01, &data);
1689 1578
1690 /* Disable access to divisor latch */ 1579 /* Disable access to divisor latch */
1691 data = mos7720_port->shadowLCR & ~UART_LCR_DLAB; 1580 mos7720_port->shadowLCR = mos7720_port->shadowLCR & ~UART_LCR_DLAB;
1692 mos7720_port->shadowLCR = data; 1581 write_mos_reg(serial, number, LCR, mos7720_port->shadowLCR);
1693 send_mos_cmd(serial, MOS_WRITE, number, 0x03, &data);
1694 1582
1695 return status; 1583 return status;
1696} 1584}
@@ -1715,7 +1603,6 @@ static void change_port_settings(struct tty_struct *tty,
1715 __u8 lStop; 1603 __u8 lStop;
1716 int status; 1604 int status;
1717 int port_number; 1605 int port_number;
1718 char data;
1719 1606
1720 if (mos7720_port == NULL) 1607 if (mos7720_port == NULL)
1721 return ; 1608 return ;
@@ -1794,30 +1681,19 @@ static void change_port_settings(struct tty_struct *tty,
1794 1681
1795 /* Update the LCR with the correct value */ 1682 /* Update the LCR with the correct value */
1796 mos7720_port->shadowLCR &= 1683 mos7720_port->shadowLCR &=
1797 ~(LCR_BITS_MASK | LCR_STOP_MASK | LCR_PAR_MASK); 1684 ~(LCR_BITS_MASK | LCR_STOP_MASK | LCR_PAR_MASK);
1798 mos7720_port->shadowLCR |= (lData | lParity | lStop); 1685 mos7720_port->shadowLCR |= (lData | lParity | lStop);
1799 1686
1800 1687
1801 /* Disable Interrupts */ 1688 /* Disable Interrupts */
1802 data = 0x00; 1689 write_mos_reg(serial, port_number, IER, 0x00);
1803 send_mos_cmd(serial, MOS_WRITE, port->number - port->serial->minor, 1690 write_mos_reg(serial, port_number, FCR, 0x00);
1804 UART_IER, &data); 1691 write_mos_reg(serial, port_number, FCR, 0xcf);
1805
1806 data = 0x00;
1807 send_mos_cmd(serial, MOS_WRITE, port_number, UART_FCR, &data);
1808
1809 data = 0xcf;
1810 send_mos_cmd(serial, MOS_WRITE, port_number, UART_FCR, &data);
1811 1692
1812 /* Send the updated LCR value to the mos7720 */ 1693 /* Send the updated LCR value to the mos7720 */
1813 data = mos7720_port->shadowLCR; 1694 write_mos_reg(serial, port_number, LCR, mos7720_port->shadowLCR);
1814 send_mos_cmd(serial, MOS_WRITE, port_number, UART_LCR, &data); 1695 mos7720_port->shadowMCR = 0x0b;
1815 1696 write_mos_reg(serial, port_number, MCR, mos7720_port->shadowMCR);
1816 data = 0x00b;
1817 mos7720_port->shadowMCR = data;
1818 send_mos_cmd(serial, MOS_WRITE, port_number, 0x04, &data);
1819 data = 0x00b;
1820 send_mos_cmd(serial, MOS_WRITE, port_number, 0x04, &data);
1821 1697
1822 /* set up the MCR register and send it to the mos7720 */ 1698 /* set up the MCR register and send it to the mos7720 */
1823 mos7720_port->shadowMCR = UART_MCR_OUT2; 1699 mos7720_port->shadowMCR = UART_MCR_OUT2;
@@ -1828,21 +1704,15 @@ static void change_port_settings(struct tty_struct *tty,
1828 mos7720_port->shadowMCR |= (UART_MCR_XONANY); 1704 mos7720_port->shadowMCR |= (UART_MCR_XONANY);
1829 /* To set hardware flow control to the specified * 1705 /* To set hardware flow control to the specified *
1830 * serial port, in SP1/2_CONTROL_REG */ 1706 * serial port, in SP1/2_CONTROL_REG */
1831 if (port->number) { 1707 if (port->number)
1832 data = 0x001; 1708 write_mos_reg(serial, dummy, SP_CONTROL_REG, 0x01);
1833 send_mos_cmd(serial, MOS_WRITE, MOS_MAX_PORT, 1709 else
1834 0x08, &data); 1710 write_mos_reg(serial, dummy, SP_CONTROL_REG, 0x02);
1835 } else { 1711
1836 data = 0x002; 1712 } else
1837 send_mos_cmd(serial, MOS_WRITE, MOS_MAX_PORT,
1838 0x08, &data);
1839 }
1840 } else {
1841 mos7720_port->shadowMCR &= ~(UART_MCR_XONANY); 1713 mos7720_port->shadowMCR &= ~(UART_MCR_XONANY);
1842 }
1843 1714
1844 data = mos7720_port->shadowMCR; 1715 write_mos_reg(serial, port_number, MCR, mos7720_port->shadowMCR);
1845 send_mos_cmd(serial, MOS_WRITE, port_number, UART_MCR, &data);
1846 1716
1847 /* Determine divisor based on baud rate */ 1717 /* Determine divisor based on baud rate */
1848 baud = tty_get_baud_rate(tty); 1718 baud = tty_get_baud_rate(tty);
@@ -1855,8 +1725,7 @@ static void change_port_settings(struct tty_struct *tty,
1855 if (baud >= 230400) { 1725 if (baud >= 230400) {
1856 set_higher_rates(mos7720_port, baud); 1726 set_higher_rates(mos7720_port, baud);
1857 /* Enable Interrupts */ 1727 /* Enable Interrupts */
1858 data = 0x0c; 1728 write_mos_reg(serial, port_number, IER, 0x0c);
1859 send_mos_cmd(serial, MOS_WRITE, port_number, UART_IER, &data);
1860 return; 1729 return;
1861 } 1730 }
1862 1731
@@ -1867,8 +1736,7 @@ static void change_port_settings(struct tty_struct *tty,
1867 if (cflag & CBAUD) 1736 if (cflag & CBAUD)
1868 tty_encode_baud_rate(tty, baud, baud); 1737 tty_encode_baud_rate(tty, baud, baud);
1869 /* Enable Interrupts */ 1738 /* Enable Interrupts */
1870 data = 0x0c; 1739 write_mos_reg(serial, port_number, IER, 0x0c);
1871 send_mos_cmd(serial, MOS_WRITE, port_number, UART_IER, &data);
1872 1740
1873 if (port->read_urb->status != -EINPROGRESS) { 1741 if (port->read_urb->status != -EINPROGRESS) {
1874 port->read_urb->dev = serial->dev; 1742 port->read_urb->dev = serial->dev;
@@ -1959,8 +1827,7 @@ static int get_lsr_info(struct tty_struct *tty,
1959 1827
1960 count = mos7720_chars_in_buffer(tty); 1828 count = mos7720_chars_in_buffer(tty);
1961 if (count == 0) { 1829 if (count == 0) {
1962 send_mos_cmd(port->serial, MOS_READ, port_number, 1830 read_mos_reg(port->serial, port_number, LSR, &data);
1963 UART_LSR, &data);
1964 if ((data & (UART_LSR_TEMT | UART_LSR_THRE)) 1831 if ((data & (UART_LSR_TEMT | UART_LSR_THRE))
1965 == (UART_LSR_TEMT | UART_LSR_THRE)) { 1832 == (UART_LSR_TEMT | UART_LSR_THRE)) {
1966 dbg("%s -- Empty", __func__); 1833 dbg("%s -- Empty", __func__);
@@ -1998,13 +1865,11 @@ static int mos7720_tiocmget(struct tty_struct *tty, struct file *file)
1998} 1865}
1999 1866
2000static int mos7720_tiocmset(struct tty_struct *tty, struct file *file, 1867static int mos7720_tiocmset(struct tty_struct *tty, struct file *file,
2001 unsigned int set, unsigned int clear) 1868 unsigned int set, unsigned int clear)
2002{ 1869{
2003 struct usb_serial_port *port = tty->driver_data; 1870 struct usb_serial_port *port = tty->driver_data;
2004 struct moschip_port *mos7720_port = usb_get_serial_port_data(port); 1871 struct moschip_port *mos7720_port = usb_get_serial_port_data(port);
2005 unsigned int mcr ; 1872 unsigned int mcr ;
2006 unsigned char lmcr;
2007
2008 dbg("%s - port %d", __func__, port->number); 1873 dbg("%s - port %d", __func__, port->number);
2009 dbg("he was at tiocmget"); 1874 dbg("he was at tiocmget");
2010 1875
@@ -2025,10 +1890,8 @@ static int mos7720_tiocmset(struct tty_struct *tty, struct file *file,
2025 mcr &= ~UART_MCR_LOOP; 1890 mcr &= ~UART_MCR_LOOP;
2026 1891
2027 mos7720_port->shadowMCR = mcr; 1892 mos7720_port->shadowMCR = mcr;
2028 lmcr = mos7720_port->shadowMCR; 1893 write_mos_reg(port->serial, port->number - port->serial->minor,
2029 1894 MCR, mos7720_port->shadowMCR);
2030 send_mos_cmd(port->serial, MOS_WRITE,
2031 port->number - port->serial->minor, UART_MCR, &lmcr);
2032 1895
2033 return 0; 1896 return 0;
2034} 1897}
@@ -2038,7 +1901,6 @@ static int set_modem_info(struct moschip_port *mos7720_port, unsigned int cmd,
2038{ 1901{
2039 unsigned int mcr ; 1902 unsigned int mcr ;
2040 unsigned int arg; 1903 unsigned int arg;
2041 unsigned char data;
2042 1904
2043 struct usb_serial_port *port; 1905 struct usb_serial_port *port;
2044 1906
@@ -2073,10 +1935,8 @@ static int set_modem_info(struct moschip_port *mos7720_port, unsigned int cmd,
2073 } 1935 }
2074 1936
2075 mos7720_port->shadowMCR = mcr; 1937 mos7720_port->shadowMCR = mcr;
2076 1938 write_mos_reg(port->serial, port->number - port->serial->minor,
2077 data = mos7720_port->shadowMCR; 1939 MCR, mos7720_port->shadowMCR);
2078 send_mos_cmd(port->serial, MOS_WRITE,
2079 port->number - port->serial->minor, UART_MCR, &data);
2080 1940
2081 return 0; 1941 return 0;
2082} 1942}
@@ -2269,11 +2129,7 @@ static int mos7720_startup(struct usb_serial *serial)
2269 } 2129 }
2270#endif 2130#endif
2271 /* LSR For Port 1 */ 2131 /* LSR For Port 1 */
2272 send_mos_cmd(serial, MOS_READ, 0x00, UART_LSR, &data); 2132 read_mos_reg(serial, 0, LSR, &data);
2273 dbg("LSR:%x", data);
2274
2275 /* LSR For Port 2 */
2276 send_mos_cmd(serial, MOS_READ, 0x01, UART_LSR, &data);
2277 dbg("LSR:%x", data); 2133 dbg("LSR:%x", data);
2278 2134
2279 return 0; 2135 return 0;