Merge branch 'fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/jesse/openvswitch
[deliverable/linux.git] / drivers / usb / serial / mos7840.c
CommitLineData
3f542974
PS
1/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15 *
16 * Clean ups from Moschip version and a few ioctl implementations by:
17 * Paul B Schroeder <pschroeder "at" uplogix "dot" com>
18 *
19 * Originally based on drivers/usb/serial/io_edgeport.c which is:
20 * Copyright (C) 2000 Inside Out Networks, All rights reserved.
21 * Copyright (C) 2001-2002 Greg Kroah-Hartman <greg@kroah.com>
22 *
23 */
24
25#include <linux/kernel.h>
26#include <linux/errno.h>
27#include <linux/init.h>
28#include <linux/slab.h>
29#include <linux/tty.h>
30#include <linux/tty_driver.h>
31#include <linux/tty_flip.h>
32#include <linux/module.h>
33#include <linux/serial.h>
34#include <linux/usb.h>
35#include <linux/usb/serial.h>
880af9db 36#include <linux/uaccess.h>
3f542974
PS
37
38/*
39 * Version Information
40 */
37768adf 41#define DRIVER_VERSION "1.3.2"
3f542974
PS
42#define DRIVER_DESC "Moschip 7840/7820 USB Serial Driver"
43
44/*
45 * 16C50 UART register defines
46 */
47
48#define LCR_BITS_5 0x00 /* 5 bits/char */
49#define LCR_BITS_6 0x01 /* 6 bits/char */
50#define LCR_BITS_7 0x02 /* 7 bits/char */
51#define LCR_BITS_8 0x03 /* 8 bits/char */
52#define LCR_BITS_MASK 0x03 /* Mask for bits/char field */
53
54#define LCR_STOP_1 0x00 /* 1 stop bit */
55#define LCR_STOP_1_5 0x04 /* 1.5 stop bits (if 5 bits/char) */
56#define LCR_STOP_2 0x04 /* 2 stop bits (if 6-8 bits/char) */
57#define LCR_STOP_MASK 0x04 /* Mask for stop bits field */
58
59#define LCR_PAR_NONE 0x00 /* No parity */
60#define LCR_PAR_ODD 0x08 /* Odd parity */
61#define LCR_PAR_EVEN 0x18 /* Even parity */
62#define LCR_PAR_MARK 0x28 /* Force parity bit to 1 */
63#define LCR_PAR_SPACE 0x38 /* Force parity bit to 0 */
64#define LCR_PAR_MASK 0x38 /* Mask for parity field */
65
66#define LCR_SET_BREAK 0x40 /* Set Break condition */
67#define LCR_DL_ENABLE 0x80 /* Enable access to divisor latch */
68
69#define MCR_DTR 0x01 /* Assert DTR */
70#define MCR_RTS 0x02 /* Assert RTS */
71#define MCR_OUT1 0x04 /* Loopback only: Sets state of RI */
72#define MCR_MASTER_IE 0x08 /* Enable interrupt outputs */
73#define MCR_LOOPBACK 0x10 /* Set internal (digital) loopback mode */
74#define MCR_XON_ANY 0x20 /* Enable any char to exit XOFF mode */
75
76#define MOS7840_MSR_CTS 0x10 /* Current state of CTS */
77#define MOS7840_MSR_DSR 0x20 /* Current state of DSR */
78#define MOS7840_MSR_RI 0x40 /* Current state of RI */
79#define MOS7840_MSR_CD 0x80 /* Current state of CD */
80
81/*
82 * Defines used for sending commands to port
83 */
84
1e658489 85#define MOS_WDR_TIMEOUT 5000 /* default urb timeout */
3f542974
PS
86
87#define MOS_PORT1 0x0200
88#define MOS_PORT2 0x0300
89#define MOS_VENREG 0x0000
90#define MOS_MAX_PORT 0x02
91#define MOS_WRITE 0x0E
92#define MOS_READ 0x0D
93
94/* Requests */
95#define MCS_RD_RTYPE 0xC0
96#define MCS_WR_RTYPE 0x40
97#define MCS_RDREQ 0x0D
98#define MCS_WRREQ 0x0E
99#define MCS_CTRL_TIMEOUT 500
100#define VENDOR_READ_LENGTH (0x01)
101
102#define MAX_NAME_LEN 64
103
880af9db
AC
104#define ZLP_REG1 0x3A /* Zero_Flag_Reg1 58 */
105#define ZLP_REG5 0x3E /* Zero_Flag_Reg5 62 */
3f542974
PS
106
107/* For higher baud Rates use TIOCEXBAUD */
108#define TIOCEXBAUD 0x5462
109
110/* vendor id and device id defines */
111
11e1abb4 112/* The native mos7840/7820 component */
3f542974
PS
113#define USB_VENDOR_ID_MOSCHIP 0x9710
114#define MOSCHIP_DEVICE_ID_7840 0x7840
115#define MOSCHIP_DEVICE_ID_7820 0x7820
0eafe4de 116#define MOSCHIP_DEVICE_ID_7810 0x7810
11e1abb4
DL
117/* The native component can have its vendor/device id's overridden
118 * in vendor-specific implementations. Such devices can be handled
68e24113 119 * by making a change here, in id_table.
11e1abb4 120 */
870408c8
DL
121#define USB_VENDOR_ID_BANDB 0x0856
122#define BANDB_DEVICE_ID_USO9ML2_2 0xAC22
123#define BANDB_DEVICE_ID_USO9ML2_2P 0xBC00
124#define BANDB_DEVICE_ID_USO9ML2_4 0xAC24
125#define BANDB_DEVICE_ID_USO9ML2_4P 0xBC01
126#define BANDB_DEVICE_ID_US9ML2_2 0xAC29
127#define BANDB_DEVICE_ID_US9ML2_4 0xAC30
128#define BANDB_DEVICE_ID_USPTL4_2 0xAC31
129#define BANDB_DEVICE_ID_USPTL4_4 0xAC32
130#define BANDB_DEVICE_ID_USOPTL4_2 0xAC42
131#define BANDB_DEVICE_ID_USOPTL4_2P 0xBC02
132#define BANDB_DEVICE_ID_USOPTL4_4 0xAC44
133#define BANDB_DEVICE_ID_USOPTL4_4P 0xBC03
134#define BANDB_DEVICE_ID_USOPTL2_4 0xAC24
3f542974 135
9d498bea
RL
136/* This driver also supports
137 * ATEN UC2324 device using Moschip MCS7840
138 * ATEN UC2322 device using Moschip MCS7820
139 */
e9b8cffa
TC
140#define USB_VENDOR_ID_ATENINTL 0x0557
141#define ATENINTL_DEVICE_ID_UC2324 0x2011
9d498bea 142#define ATENINTL_DEVICE_ID_UC2322 0x7820
e9b8cffa 143
11e1abb4 144/* Interrupt Routine Defines */
3f542974
PS
145
146#define SERIAL_IIR_RLS 0x06
147#define SERIAL_IIR_MS 0x00
148
149/*
150 * Emulation of the bit mask on the LINE STATUS REGISTER.
151 */
152#define SERIAL_LSR_DR 0x0001
153#define SERIAL_LSR_OE 0x0002
154#define SERIAL_LSR_PE 0x0004
155#define SERIAL_LSR_FE 0x0008
156#define SERIAL_LSR_BI 0x0010
157
158#define MOS_MSR_DELTA_CTS 0x10
159#define MOS_MSR_DELTA_DSR 0x20
160#define MOS_MSR_DELTA_RI 0x40
161#define MOS_MSR_DELTA_CD 0x80
162
880af9db 163/* Serial Port register Address */
3f542974
PS
164#define INTERRUPT_ENABLE_REGISTER ((__u16)(0x01))
165#define FIFO_CONTROL_REGISTER ((__u16)(0x02))
166#define LINE_CONTROL_REGISTER ((__u16)(0x03))
167#define MODEM_CONTROL_REGISTER ((__u16)(0x04))
168#define LINE_STATUS_REGISTER ((__u16)(0x05))
169#define MODEM_STATUS_REGISTER ((__u16)(0x06))
170#define SCRATCH_PAD_REGISTER ((__u16)(0x07))
171#define DIVISOR_LATCH_LSB ((__u16)(0x00))
172#define DIVISOR_LATCH_MSB ((__u16)(0x01))
173
174#define CLK_MULTI_REGISTER ((__u16)(0x02))
175#define CLK_START_VALUE_REGISTER ((__u16)(0x03))
093ea2d3 176#define GPIO_REGISTER ((__u16)(0x07))
3f542974
PS
177
178#define SERIAL_LCR_DLAB ((__u16)(0x0080))
179
180/*
181 * URB POOL related defines
182 */
183#define NUM_URBS 16 /* URB Count */
184#define URB_TRANSFER_BUFFER_SIZE 32 /* URB Size */
185
0eafe4de
D
186/* LED on/off milliseconds*/
187#define LED_ON_MS 500
188#define LED_OFF_MS 500
189
190static int device_type;
3f542974 191
b9c87663 192static const struct usb_device_id id_table[] = {
3f542974
PS
193 {USB_DEVICE(USB_VENDOR_ID_MOSCHIP, MOSCHIP_DEVICE_ID_7840)},
194 {USB_DEVICE(USB_VENDOR_ID_MOSCHIP, MOSCHIP_DEVICE_ID_7820)},
0eafe4de 195 {USB_DEVICE(USB_VENDOR_ID_MOSCHIP, MOSCHIP_DEVICE_ID_7810)},
acf509ae 196 {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USO9ML2_2)},
870408c8 197 {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USO9ML2_2P)},
acf509ae 198 {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USO9ML2_4)},
870408c8 199 {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USO9ML2_4P)},
acf509ae
CB
200 {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_US9ML2_2)},
201 {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_US9ML2_4)},
202 {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USPTL4_2)},
203 {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USPTL4_4)},
11e1abb4 204 {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL4_2)},
870408c8 205 {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL4_2P)},
acf509ae 206 {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL4_4)},
870408c8 207 {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL4_4P)},
27f1281d 208 {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL2_4)},
e9b8cffa 209 {USB_DEVICE(USB_VENDOR_ID_ATENINTL, ATENINTL_DEVICE_ID_UC2324)},
9d498bea 210 {USB_DEVICE(USB_VENDOR_ID_ATENINTL, ATENINTL_DEVICE_ID_UC2322)},
3f542974
PS
211 {} /* terminating entry */
212};
68e24113 213MODULE_DEVICE_TABLE(usb, id_table);
3f542974
PS
214
215/* This structure holds all of the local port information */
216
217struct moschip_port {
218 int port_num; /*Actual port number in the device(1,2,etc) */
219 struct urb *write_urb; /* write URB for this port */
220 struct urb *read_urb; /* read URB for this port */
0de9a702 221 struct urb *int_urb;
3f542974
PS
222 __u8 shadowLCR; /* last LCR value received */
223 __u8 shadowMCR; /* last MCR value received */
224 char open;
0de9a702
ON
225 char open_ports;
226 char zombie;
3f542974
PS
227 wait_queue_head_t wait_chase; /* for handling sleeping while waiting for chase to finish */
228 wait_queue_head_t delta_msr_wait; /* for handling sleeping while waiting for msr change to happen */
229 int delta_msr_cond;
230 struct async_icount icount;
231 struct usb_serial_port *port; /* loop back to the owner of this object */
232
880af9db 233 /* Offsets */
3f542974
PS
234 __u8 SpRegOffset;
235 __u8 ControlRegOffset;
236 __u8 DcrRegOffset;
880af9db 237 /* for processing control URBS in interrupt context */
3f542974 238 struct urb *control_urb;
0de9a702 239 struct usb_ctrlrequest *dr;
3f542974
PS
240 char *ctrl_buf;
241 int MsrLsr;
242
0de9a702 243 spinlock_t pool_lock;
3f542974 244 struct urb *write_urb_pool[NUM_URBS];
0de9a702 245 char busy[NUM_URBS];
50de36f7 246 bool read_urb_busy;
3f542974 247
0eafe4de
D
248 /* For device(s) with LED indicator */
249 bool has_led;
250 bool led_flag;
251 struct timer_list led_timer1; /* Timer for LED on */
252 struct timer_list led_timer2; /* Timer for LED off */
253};
3f542974 254
90ab5ee9 255static bool debug;
3f542974
PS
256
257/*
258 * mos7840_set_reg_sync
259 * To set the Control register by calling usb_fill_control_urb function
260 * by passing usb_sndctrlpipe function as parameter.
261 */
262
263static int mos7840_set_reg_sync(struct usb_serial_port *port, __u16 reg,
264 __u16 val)
265{
266 struct usb_device *dev = port->serial->dev;
267 val = val & 0x00ff;
84fe6e79 268 dbg("mos7840_set_reg_sync offset is %x, value %x", reg, val);
3f542974
PS
269
270 return usb_control_msg(dev, usb_sndctrlpipe(dev, 0), MCS_WRREQ,
271 MCS_WR_RTYPE, val, reg, NULL, 0,
272 MOS_WDR_TIMEOUT);
273}
274
275/*
276 * mos7840_get_reg_sync
277 * To set the Uart register by calling usb_fill_control_urb function by
278 * passing usb_rcvctrlpipe function as parameter.
279 */
280
281static int mos7840_get_reg_sync(struct usb_serial_port *port, __u16 reg,
880af9db 282 __u16 *val)
3f542974
PS
283{
284 struct usb_device *dev = port->serial->dev;
285 int ret = 0;
9e221a35
JH
286 u8 *buf;
287
288 buf = kmalloc(VENDOR_READ_LENGTH, GFP_KERNEL);
289 if (!buf)
290 return -ENOMEM;
3f542974
PS
291
292 ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), MCS_RDREQ,
9e221a35 293 MCS_RD_RTYPE, 0, reg, buf, VENDOR_READ_LENGTH,
3f542974 294 MOS_WDR_TIMEOUT);
9e221a35 295 *val = buf[0];
84fe6e79 296 dbg("mos7840_get_reg_sync offset is %x, return val %x", reg, *val);
9e221a35
JH
297
298 kfree(buf);
3f542974
PS
299 return ret;
300}
301
302/*
303 * mos7840_set_uart_reg
304 * To set the Uart register by calling usb_fill_control_urb function by
305 * passing usb_sndctrlpipe function as parameter.
306 */
307
308static int mos7840_set_uart_reg(struct usb_serial_port *port, __u16 reg,
309 __u16 val)
310{
311
312 struct usb_device *dev = port->serial->dev;
313 val = val & 0x00ff;
880af9db
AC
314 /* For the UART control registers, the application number need
315 to be Or'ed */
0de9a702 316 if (port->serial->num_ports == 4) {
880af9db
AC
317 val |= (((__u16) port->number -
318 (__u16) (port->serial->minor)) + 1) << 8;
84fe6e79 319 dbg("mos7840_set_uart_reg application number is %x", val);
3f542974
PS
320 } else {
321 if (((__u16) port->number - (__u16) (port->serial->minor)) == 0) {
880af9db 322 val |= (((__u16) port->number -
3f542974 323 (__u16) (port->serial->minor)) + 1) << 8;
84fe6e79 324 dbg("mos7840_set_uart_reg application number is %x",
3f542974
PS
325 val);
326 } else {
327 val |=
328 (((__u16) port->number -
329 (__u16) (port->serial->minor)) + 2) << 8;
84fe6e79 330 dbg("mos7840_set_uart_reg application number is %x",
3f542974
PS
331 val);
332 }
333 }
334 return usb_control_msg(dev, usb_sndctrlpipe(dev, 0), MCS_WRREQ,
335 MCS_WR_RTYPE, val, reg, NULL, 0,
336 MOS_WDR_TIMEOUT);
337
338}
339
340/*
341 * mos7840_get_uart_reg
342 * To set the Control register by calling usb_fill_control_urb function
343 * by passing usb_rcvctrlpipe function as parameter.
344 */
345static int mos7840_get_uart_reg(struct usb_serial_port *port, __u16 reg,
880af9db 346 __u16 *val)
3f542974
PS
347{
348 struct usb_device *dev = port->serial->dev;
349 int ret = 0;
350 __u16 Wval;
9e221a35
JH
351 u8 *buf;
352
353 buf = kmalloc(VENDOR_READ_LENGTH, GFP_KERNEL);
354 if (!buf)
355 return -ENOMEM;
3f542974 356
84fe6e79 357 /* dbg("application number is %4x",
880af9db
AC
358 (((__u16)port->number - (__u16)(port->serial->minor))+1)<<8); */
359 /* Wval is same as application number */
0de9a702 360 if (port->serial->num_ports == 4) {
3f542974
PS
361 Wval =
362 (((__u16) port->number - (__u16) (port->serial->minor)) +
363 1) << 8;
84fe6e79 364 dbg("mos7840_get_uart_reg application number is %x", Wval);
3f542974
PS
365 } else {
366 if (((__u16) port->number - (__u16) (port->serial->minor)) == 0) {
880af9db 367 Wval = (((__u16) port->number -
3f542974 368 (__u16) (port->serial->minor)) + 1) << 8;
84fe6e79 369 dbg("mos7840_get_uart_reg application number is %x",
3f542974
PS
370 Wval);
371 } else {
880af9db 372 Wval = (((__u16) port->number -
3f542974 373 (__u16) (port->serial->minor)) + 2) << 8;
84fe6e79 374 dbg("mos7840_get_uart_reg application number is %x",
3f542974
PS
375 Wval);
376 }
377 }
378 ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), MCS_RDREQ,
9e221a35 379 MCS_RD_RTYPE, Wval, reg, buf, VENDOR_READ_LENGTH,
3f542974 380 MOS_WDR_TIMEOUT);
9e221a35
JH
381 *val = buf[0];
382
383 kfree(buf);
3f542974
PS
384 return ret;
385}
386
387static void mos7840_dump_serial_port(struct moschip_port *mos7840_port)
388{
389
84fe6e79
TC
390 dbg("***************************************");
391 dbg("SpRegOffset is %2x", mos7840_port->SpRegOffset);
392 dbg("ControlRegOffset is %2x", mos7840_port->ControlRegOffset);
393 dbg("DCRRegOffset is %2x", mos7840_port->DcrRegOffset);
394 dbg("***************************************");
3f542974
PS
395
396}
397
398/************************************************************************/
399/************************************************************************/
400/* I N T E R F A C E F U N C T I O N S */
401/* I N T E R F A C E F U N C T I O N S */
402/************************************************************************/
403/************************************************************************/
404
405static inline void mos7840_set_port_private(struct usb_serial_port *port,
406 struct moschip_port *data)
407{
408 usb_set_serial_port_data(port, (void *)data);
409}
410
411static inline struct moschip_port *mos7840_get_port_private(struct
412 usb_serial_port
413 *port)
414{
415 return (struct moschip_port *)usb_get_serial_port_data(port);
416}
417
0de9a702 418static void mos7840_handle_new_msr(struct moschip_port *port, __u8 new_msr)
3f542974
PS
419{
420 struct moschip_port *mos7840_port;
421 struct async_icount *icount;
422 mos7840_port = port;
423 icount = &mos7840_port->icount;
424 if (new_msr &
425 (MOS_MSR_DELTA_CTS | MOS_MSR_DELTA_DSR | MOS_MSR_DELTA_RI |
426 MOS_MSR_DELTA_CD)) {
427 icount = &mos7840_port->icount;
428
429 /* update input line counters */
430 if (new_msr & MOS_MSR_DELTA_CTS) {
431 icount->cts++;
0de9a702 432 smp_wmb();
3f542974
PS
433 }
434 if (new_msr & MOS_MSR_DELTA_DSR) {
435 icount->dsr++;
0de9a702 436 smp_wmb();
3f542974
PS
437 }
438 if (new_msr & MOS_MSR_DELTA_CD) {
439 icount->dcd++;
0de9a702 440 smp_wmb();
3f542974
PS
441 }
442 if (new_msr & MOS_MSR_DELTA_RI) {
443 icount->rng++;
0de9a702 444 smp_wmb();
3f542974
PS
445 }
446 }
3f542974
PS
447}
448
0de9a702 449static void mos7840_handle_new_lsr(struct moschip_port *port, __u8 new_lsr)
3f542974
PS
450{
451 struct async_icount *icount;
452
441b62c1 453 dbg("%s - %02x", __func__, new_lsr);
3f542974
PS
454
455 if (new_lsr & SERIAL_LSR_BI) {
880af9db
AC
456 /*
457 * Parity and Framing errors only count if they
458 * occur exclusive of a break being
459 * received.
460 */
3f542974
PS
461 new_lsr &= (__u8) (SERIAL_LSR_OE | SERIAL_LSR_BI);
462 }
463
464 /* update input line counters */
465 icount = &port->icount;
466 if (new_lsr & SERIAL_LSR_BI) {
467 icount->brk++;
0de9a702 468 smp_wmb();
3f542974
PS
469 }
470 if (new_lsr & SERIAL_LSR_OE) {
471 icount->overrun++;
0de9a702 472 smp_wmb();
3f542974
PS
473 }
474 if (new_lsr & SERIAL_LSR_PE) {
475 icount->parity++;
0de9a702 476 smp_wmb();
3f542974
PS
477 }
478 if (new_lsr & SERIAL_LSR_FE) {
479 icount->frame++;
0de9a702 480 smp_wmb();
3f542974 481 }
3f542974
PS
482}
483
484/************************************************************************/
485/************************************************************************/
486/* U S B C A L L B A C K F U N C T I O N S */
487/* U S B C A L L B A C K F U N C T I O N S */
488/************************************************************************/
489/************************************************************************/
490
7d12e780 491static void mos7840_control_callback(struct urb *urb)
3f542974
PS
492{
493 unsigned char *data;
494 struct moschip_port *mos7840_port;
495 __u8 regval = 0x0;
0de9a702 496 int result = 0;
0643c724 497 int status = urb->status;
3f542974 498
cdc97792 499 mos7840_port = urb->context;
0de9a702 500
0643c724 501 switch (status) {
3f542974
PS
502 case 0:
503 /* success */
504 break;
505 case -ECONNRESET:
506 case -ENOENT:
507 case -ESHUTDOWN:
508 /* this urb is terminated, clean up */
441b62c1 509 dbg("%s - urb shutting down with status: %d", __func__,
0643c724 510 status);
3f542974
PS
511 return;
512 default:
441b62c1 513 dbg("%s - nonzero urb status received: %d", __func__,
0643c724 514 status);
3f542974
PS
515 goto exit;
516 }
517
84fe6e79
TC
518 dbg("%s urb buffer size is %d", __func__, urb->actual_length);
519 dbg("%s mos7840_port->MsrLsr is %d port %d", __func__,
3f542974
PS
520 mos7840_port->MsrLsr, mos7840_port->port_num);
521 data = urb->transfer_buffer;
522 regval = (__u8) data[0];
84fe6e79 523 dbg("%s data is %x", __func__, regval);
3f542974
PS
524 if (mos7840_port->MsrLsr == 0)
525 mos7840_handle_new_msr(mos7840_port, regval);
526 else if (mos7840_port->MsrLsr == 1)
527 mos7840_handle_new_lsr(mos7840_port, regval);
528
0de9a702
ON
529exit:
530 spin_lock(&mos7840_port->pool_lock);
531 if (!mos7840_port->zombie)
532 result = usb_submit_urb(mos7840_port->int_urb, GFP_ATOMIC);
533 spin_unlock(&mos7840_port->pool_lock);
534 if (result) {
535 dev_err(&urb->dev->dev,
536 "%s - Error %d submitting interrupt urb\n",
441b62c1 537 __func__, result);
0de9a702 538 }
3f542974
PS
539}
540
541static int mos7840_get_reg(struct moschip_port *mcs, __u16 Wval, __u16 reg,
880af9db 542 __u16 *val)
3f542974
PS
543{
544 struct usb_device *dev = mcs->port->serial->dev;
0de9a702
ON
545 struct usb_ctrlrequest *dr = mcs->dr;
546 unsigned char *buffer = mcs->ctrl_buf;
547 int ret;
3f542974 548
3f542974
PS
549 dr->bRequestType = MCS_RD_RTYPE;
550 dr->bRequest = MCS_RDREQ;
880af9db 551 dr->wValue = cpu_to_le16(Wval); /* 0 */
3f542974
PS
552 dr->wIndex = cpu_to_le16(reg);
553 dr->wLength = cpu_to_le16(2);
554
555 usb_fill_control_urb(mcs->control_urb, dev, usb_rcvctrlpipe(dev, 0),
556 (unsigned char *)dr, buffer, 2,
557 mos7840_control_callback, mcs);
558 mcs->control_urb->transfer_buffer_length = 2;
559 ret = usb_submit_urb(mcs->control_urb, GFP_ATOMIC);
560 return ret;
561}
562
0eafe4de
D
563static void mos7840_set_led_callback(struct urb *urb)
564{
565 switch (urb->status) {
566 case 0:
567 /* Success */
568 break;
569 case -ECONNRESET:
570 case -ENOENT:
571 case -ESHUTDOWN:
572 /* This urb is terminated, clean up */
573 dbg("%s - urb shutting down with status: %d", __func__,
574 urb->status);
575 break;
576 default:
577 dbg("%s - nonzero urb status received: %d", __func__,
578 urb->status);
579 }
580}
581
582static void mos7840_set_led_async(struct moschip_port *mcs, __u16 wval,
583 __u16 reg)
584{
585 struct usb_device *dev = mcs->port->serial->dev;
586 struct usb_ctrlrequest *dr = mcs->dr;
587
588 dr->bRequestType = MCS_WR_RTYPE;
589 dr->bRequest = MCS_WRREQ;
590 dr->wValue = cpu_to_le16(wval);
591 dr->wIndex = cpu_to_le16(reg);
592 dr->wLength = cpu_to_le16(0);
593
594 usb_fill_control_urb(mcs->control_urb, dev, usb_sndctrlpipe(dev, 0),
595 (unsigned char *)dr, NULL, 0, mos7840_set_led_callback, NULL);
596
597 usb_submit_urb(mcs->control_urb, GFP_ATOMIC);
598}
599
600static void mos7840_set_led_sync(struct usb_serial_port *port, __u16 reg,
601 __u16 val)
602{
603 struct usb_device *dev = port->serial->dev;
604
605 usb_control_msg(dev, usb_sndctrlpipe(dev, 0), MCS_WRREQ, MCS_WR_RTYPE,
606 val, reg, NULL, 0, MOS_WDR_TIMEOUT);
607}
608
609static void mos7840_led_off(unsigned long arg)
610{
611 struct moschip_port *mcs = (struct moschip_port *) arg;
612
613 /* Turn off LED */
614 mos7840_set_led_async(mcs, 0x0300, MODEM_CONTROL_REGISTER);
615 mod_timer(&mcs->led_timer2,
616 jiffies + msecs_to_jiffies(LED_OFF_MS));
617}
618
619static void mos7840_led_flag_off(unsigned long arg)
620{
621 struct moschip_port *mcs = (struct moschip_port *) arg;
622
623 mcs->led_flag = false;
624}
625
3f542974
PS
626/*****************************************************************************
627 * mos7840_interrupt_callback
628 * this is the callback function for when we have received data on the
629 * interrupt endpoint.
630 *****************************************************************************/
631
7d12e780 632static void mos7840_interrupt_callback(struct urb *urb)
3f542974
PS
633{
634 int result;
635 int length;
636 struct moschip_port *mos7840_port;
637 struct usb_serial *serial;
638 __u16 Data;
639 unsigned char *data;
640 __u8 sp[5], st;
0de9a702
ON
641 int i, rv = 0;
642 __u16 wval, wreg = 0;
0643c724 643 int status = urb->status;
3f542974 644
0643c724 645 switch (status) {
3f542974
PS
646 case 0:
647 /* success */
648 break;
649 case -ECONNRESET:
650 case -ENOENT:
651 case -ESHUTDOWN:
652 /* this urb is terminated, clean up */
441b62c1 653 dbg("%s - urb shutting down with status: %d", __func__,
0643c724 654 status);
3f542974
PS
655 return;
656 default:
441b62c1 657 dbg("%s - nonzero urb status received: %d", __func__,
0643c724 658 status);
3f542974
PS
659 goto exit;
660 }
661
662 length = urb->actual_length;
663 data = urb->transfer_buffer;
664
cdc97792 665 serial = urb->context;
3f542974
PS
666
667 /* Moschip get 5 bytes
668 * Byte 1 IIR Port 1 (port.number is 0)
669 * Byte 2 IIR Port 2 (port.number is 1)
670 * Byte 3 IIR Port 3 (port.number is 2)
671 * Byte 4 IIR Port 4 (port.number is 3)
672 * Byte 5 FIFO status for both */
673
674 if (length && length > 5) {
84fe6e79 675 dbg("%s", "Wrong data !!!");
3f542974
PS
676 return;
677 }
678
679 sp[0] = (__u8) data[0];
680 sp[1] = (__u8) data[1];
681 sp[2] = (__u8) data[2];
682 sp[3] = (__u8) data[3];
683 st = (__u8) data[4];
684
685 for (i = 0; i < serial->num_ports; i++) {
686 mos7840_port = mos7840_get_port_private(serial->port[i]);
687 wval =
688 (((__u16) serial->port[i]->number -
689 (__u16) (serial->minor)) + 1) << 8;
690 if (mos7840_port->open) {
691 if (sp[i] & 0x01) {
84fe6e79 692 dbg("SP%d No Interrupt !!!", i);
3f542974
PS
693 } else {
694 switch (sp[i] & 0x0f) {
695 case SERIAL_IIR_RLS:
696 dbg("Serial Port %d: Receiver status error or ", i);
84fe6e79 697 dbg("address bit detected in 9-bit mode");
3f542974 698 mos7840_port->MsrLsr = 1;
0de9a702 699 wreg = LINE_STATUS_REGISTER;
3f542974
PS
700 break;
701 case SERIAL_IIR_MS:
84fe6e79 702 dbg("Serial Port %d: Modem status change", i);
3f542974 703 mos7840_port->MsrLsr = 0;
0de9a702 704 wreg = MODEM_STATUS_REGISTER;
3f542974
PS
705 break;
706 }
0de9a702
ON
707 spin_lock(&mos7840_port->pool_lock);
708 if (!mos7840_port->zombie) {
709 rv = mos7840_get_reg(mos7840_port, wval, wreg, &Data);
710 } else {
711 spin_unlock(&mos7840_port->pool_lock);
712 return;
713 }
714 spin_unlock(&mos7840_port->pool_lock);
3f542974
PS
715 }
716 }
717 }
880af9db
AC
718 if (!(rv < 0))
719 /* the completion handler for the control urb will resubmit */
0de9a702
ON
720 return;
721exit:
3f542974
PS
722 result = usb_submit_urb(urb, GFP_ATOMIC);
723 if (result) {
724 dev_err(&urb->dev->dev,
725 "%s - Error %d submitting interrupt urb\n",
441b62c1 726 __func__, result);
3f542974 727 }
3f542974
PS
728}
729
730static int mos7840_port_paranoia_check(struct usb_serial_port *port,
731 const char *function)
732{
733 if (!port) {
734 dbg("%s - port == NULL", function);
735 return -1;
736 }
737 if (!port->serial) {
738 dbg("%s - port->serial == NULL", function);
739 return -1;
740 }
741
742 return 0;
743}
744
745/* Inline functions to check the sanity of a pointer that is passed to us */
746static int mos7840_serial_paranoia_check(struct usb_serial *serial,
747 const char *function)
748{
749 if (!serial) {
750 dbg("%s - serial == NULL", function);
751 return -1;
752 }
753 if (!serial->type) {
754 dbg("%s - serial->type == NULL!", function);
755 return -1;
756 }
757
758 return 0;
759}
760
761static struct usb_serial *mos7840_get_usb_serial(struct usb_serial_port *port,
762 const char *function)
763{
764 /* if no port was specified, or it fails a paranoia check */
765 if (!port ||
766 mos7840_port_paranoia_check(port, function) ||
767 mos7840_serial_paranoia_check(port->serial, function)) {
880af9db
AC
768 /* then say that we don't have a valid usb_serial thing,
769 * which will end up genrating -ENODEV return values */
3f542974
PS
770 return NULL;
771 }
772
773 return port->serial;
774}
775
776/*****************************************************************************
777 * mos7840_bulk_in_callback
778 * this is the callback function for when we have received data on the
779 * bulk in endpoint.
780 *****************************************************************************/
781
7d12e780 782static void mos7840_bulk_in_callback(struct urb *urb)
3f542974 783{
0643c724 784 int retval;
3f542974
PS
785 unsigned char *data;
786 struct usb_serial *serial;
787 struct usb_serial_port *port;
788 struct moschip_port *mos7840_port;
789 struct tty_struct *tty;
0643c724 790 int status = urb->status;
3f542974 791
cdc97792 792 mos7840_port = urb->context;
3f542974 793 if (!mos7840_port) {
84fe6e79 794 dbg("%s", "NULL mos7840_port pointer");
50de36f7
GKH
795 return;
796 }
797
798 if (status) {
799 dbg("nonzero read bulk status received: %d", status);
800 mos7840_port->read_urb_busy = false;
3f542974
PS
801 return;
802 }
803
804 port = (struct usb_serial_port *)mos7840_port->port;
441b62c1 805 if (mos7840_port_paranoia_check(port, __func__)) {
84fe6e79 806 dbg("%s", "Port Paranoia failed");
50de36f7 807 mos7840_port->read_urb_busy = false;
3f542974
PS
808 return;
809 }
810
441b62c1 811 serial = mos7840_get_usb_serial(port, __func__);
3f542974 812 if (!serial) {
84fe6e79 813 dbg("%s", "Bad serial pointer");
50de36f7 814 mos7840_port->read_urb_busy = false;
3f542974
PS
815 return;
816 }
817
3f542974
PS
818 data = urb->transfer_buffer;
819
3f542974 820 if (urb->actual_length) {
4a90f09b 821 tty = tty_port_tty_get(&mos7840_port->port->port);
3f542974 822 if (tty) {
3f542974 823 tty_insert_flip_string(tty, data, urb->actual_length);
84fe6e79 824 dbg(" %s ", data);
3f542974 825 tty_flip_buffer_push(tty);
4a90f09b 826 tty_kref_put(tty);
3f542974
PS
827 }
828 mos7840_port->icount.rx += urb->actual_length;
0de9a702 829 smp_wmb();
84fe6e79 830 dbg("mos7840_port->icount.rx is %d:",
3f542974
PS
831 mos7840_port->icount.rx);
832 }
833
834 if (!mos7840_port->read_urb) {
84fe6e79 835 dbg("%s", "URB KILLED !!!");
50de36f7 836 mos7840_port->read_urb_busy = false;
3f542974
PS
837 return;
838 }
839
0eafe4de
D
840 /* Turn on LED */
841 if (mos7840_port->has_led && !mos7840_port->led_flag) {
842 mos7840_port->led_flag = true;
843 mos7840_set_led_async(mos7840_port, 0x0301,
844 MODEM_CONTROL_REGISTER);
845 mod_timer(&mos7840_port->led_timer1,
846 jiffies + msecs_to_jiffies(LED_ON_MS));
847 }
3f542974 848
50de36f7 849 mos7840_port->read_urb_busy = true;
0643c724 850 retval = usb_submit_urb(mos7840_port->read_urb, GFP_ATOMIC);
0de9a702 851
0643c724 852 if (retval) {
50de36f7
GKH
853 dbg("usb_submit_urb(read bulk) failed, retval = %d", retval);
854 mos7840_port->read_urb_busy = false;
3f542974
PS
855 }
856}
857
858/*****************************************************************************
859 * mos7840_bulk_out_data_callback
880af9db
AC
860 * this is the callback function for when we have finished sending
861 * serial data on the bulk out endpoint.
3f542974
PS
862 *****************************************************************************/
863
7d12e780 864static void mos7840_bulk_out_data_callback(struct urb *urb)
3f542974
PS
865{
866 struct moschip_port *mos7840_port;
867 struct tty_struct *tty;
0643c724 868 int status = urb->status;
0de9a702
ON
869 int i;
870
cdc97792 871 mos7840_port = urb->context;
0de9a702
ON
872 spin_lock(&mos7840_port->pool_lock);
873 for (i = 0; i < NUM_URBS; i++) {
874 if (urb == mos7840_port->write_urb_pool[i]) {
875 mos7840_port->busy[i] = 0;
876 break;
877 }
878 }
879 spin_unlock(&mos7840_port->pool_lock);
880
0643c724 881 if (status) {
84fe6e79 882 dbg("nonzero write bulk status received:%d", status);
3f542974
PS
883 return;
884 }
885
441b62c1 886 if (mos7840_port_paranoia_check(mos7840_port->port, __func__)) {
84fe6e79 887 dbg("%s", "Port Paranoia failed");
3f542974
PS
888 return;
889 }
890
4a90f09b 891 tty = tty_port_tty_get(&mos7840_port->port->port);
b963a844
JS
892 if (tty && mos7840_port->open)
893 tty_wakeup(tty);
4a90f09b 894 tty_kref_put(tty);
3f542974
PS
895
896}
897
898/************************************************************************/
899/* D R I V E R T T Y I N T E R F A C E F U N C T I O N S */
900/************************************************************************/
901#ifdef MCSSerialProbe
902static int mos7840_serial_probe(struct usb_serial *serial,
903 const struct usb_device_id *id)
904{
905
906 /*need to implement the mode_reg reading and updating\
907 structures usb_serial_ device_type\
908 (i.e num_ports, num_bulkin,bulkout etc) */
909 /* Also we can update the changes attach */
910 return 1;
911}
912#endif
913
914/*****************************************************************************
915 * mos7840_open
916 * this function is called by the tty driver when a port is opened
917 * If successful, we return 0
918 * Otherwise we return a negative error number.
919 *****************************************************************************/
920
a509a7e4 921static int mos7840_open(struct tty_struct *tty, struct usb_serial_port *port)
3f542974
PS
922{
923 int response;
924 int j;
925 struct usb_serial *serial;
926 struct urb *urb;
927 __u16 Data;
928 int status;
929 struct moschip_port *mos7840_port;
0de9a702 930 struct moschip_port *port0;
3f542974 931
441b62c1 932 if (mos7840_port_paranoia_check(port, __func__)) {
84fe6e79 933 dbg("%s", "Port Paranoia failed");
3f542974
PS
934 return -ENODEV;
935 }
936
3f542974
PS
937 serial = port->serial;
938
441b62c1 939 if (mos7840_serial_paranoia_check(serial, __func__)) {
84fe6e79 940 dbg("%s", "Serial Paranoia failed");
3f542974
PS
941 return -ENODEV;
942 }
943
944 mos7840_port = mos7840_get_port_private(port);
0de9a702 945 port0 = mos7840_get_port_private(serial->port[0]);
3f542974 946
0de9a702 947 if (mos7840_port == NULL || port0 == NULL)
3f542974
PS
948 return -ENODEV;
949
950 usb_clear_halt(serial->dev, port->write_urb->pipe);
951 usb_clear_halt(serial->dev, port->read_urb->pipe);
0de9a702 952 port0->open_ports++;
3f542974
PS
953
954 /* Initialising the write urb pool */
955 for (j = 0; j < NUM_URBS; ++j) {
0de9a702 956 urb = usb_alloc_urb(0, GFP_KERNEL);
3f542974
PS
957 mos7840_port->write_urb_pool[j] = urb;
958
959 if (urb == NULL) {
194343d9 960 dev_err(&port->dev, "No more urbs???\n");
3f542974
PS
961 continue;
962 }
963
880af9db
AC
964 urb->transfer_buffer = kmalloc(URB_TRANSFER_BUFFER_SIZE,
965 GFP_KERNEL);
3f542974 966 if (!urb->transfer_buffer) {
0de9a702
ON
967 usb_free_urb(urb);
968 mos7840_port->write_urb_pool[j] = NULL;
194343d9
GKH
969 dev_err(&port->dev,
970 "%s-out of memory for urb buffers.\n",
971 __func__);
3f542974
PS
972 continue;
973 }
974 }
975
976/*****************************************************************************
977 * Initialize MCS7840 -- Write Init values to corresponding Registers
978 *
979 * Register Index
980 * 1 : IER
981 * 2 : FCR
982 * 3 : LCR
983 * 4 : MCR
984 *
985 * 0x08 : SP1/2 Control Reg
986 *****************************************************************************/
987
880af9db 988 /* NEED to check the following Block */
3f542974 989
3f542974
PS
990 Data = 0x0;
991 status = mos7840_get_reg_sync(port, mos7840_port->SpRegOffset, &Data);
992 if (status < 0) {
84fe6e79 993 dbg("Reading Spreg failed");
3f542974
PS
994 return -1;
995 }
996 Data |= 0x80;
997 status = mos7840_set_reg_sync(port, mos7840_port->SpRegOffset, Data);
998 if (status < 0) {
84fe6e79 999 dbg("writing Spreg failed");
3f542974
PS
1000 return -1;
1001 }
1002
1003 Data &= ~0x80;
1004 status = mos7840_set_reg_sync(port, mos7840_port->SpRegOffset, Data);
1005 if (status < 0) {
84fe6e79 1006 dbg("writing Spreg failed");
3f542974
PS
1007 return -1;
1008 }
880af9db 1009 /* End of block to be checked */
3f542974 1010
3f542974 1011 Data = 0x0;
880af9db
AC
1012 status = mos7840_get_reg_sync(port, mos7840_port->ControlRegOffset,
1013 &Data);
3f542974 1014 if (status < 0) {
84fe6e79 1015 dbg("Reading Controlreg failed");
3f542974
PS
1016 return -1;
1017 }
880af9db
AC
1018 Data |= 0x08; /* Driver done bit */
1019 Data |= 0x20; /* rx_disable */
1020 status = mos7840_set_reg_sync(port,
1021 mos7840_port->ControlRegOffset, Data);
3f542974 1022 if (status < 0) {
84fe6e79 1023 dbg("writing Controlreg failed");
3f542974
PS
1024 return -1;
1025 }
880af9db
AC
1026 /* do register settings here */
1027 /* Set all regs to the device default values. */
1028 /***********************************
1029 * First Disable all interrupts.
1030 ***********************************/
3f542974 1031 Data = 0x00;
3f542974
PS
1032 status = mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data);
1033 if (status < 0) {
84fe6e79 1034 dbg("disabling interrupts failed");
3f542974
PS
1035 return -1;
1036 }
880af9db 1037 /* Set FIFO_CONTROL_REGISTER to the default value */
3f542974 1038 Data = 0x00;
3f542974
PS
1039 status = mos7840_set_uart_reg(port, FIFO_CONTROL_REGISTER, Data);
1040 if (status < 0) {
84fe6e79 1041 dbg("Writing FIFO_CONTROL_REGISTER failed");
3f542974
PS
1042 return -1;
1043 }
1044
1045 Data = 0xcf;
3f542974
PS
1046 status = mos7840_set_uart_reg(port, FIFO_CONTROL_REGISTER, Data);
1047 if (status < 0) {
84fe6e79 1048 dbg("Writing FIFO_CONTROL_REGISTER failed");
3f542974
PS
1049 return -1;
1050 }
1051
1052 Data = 0x03;
3f542974
PS
1053 status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
1054 mos7840_port->shadowLCR = Data;
1055
1056 Data = 0x0b;
3f542974
PS
1057 status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
1058 mos7840_port->shadowMCR = Data;
1059
1060 Data = 0x00;
3f542974
PS
1061 status = mos7840_get_uart_reg(port, LINE_CONTROL_REGISTER, &Data);
1062 mos7840_port->shadowLCR = Data;
1063
880af9db 1064 Data |= SERIAL_LCR_DLAB; /* data latch enable in LCR 0x80 */
3f542974
PS
1065 status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
1066
1067 Data = 0x0c;
3f542974
PS
1068 status = mos7840_set_uart_reg(port, DIVISOR_LATCH_LSB, Data);
1069
1070 Data = 0x0;
3f542974
PS
1071 status = mos7840_set_uart_reg(port, DIVISOR_LATCH_MSB, Data);
1072
1073 Data = 0x00;
3f542974
PS
1074 status = mos7840_get_uart_reg(port, LINE_CONTROL_REGISTER, &Data);
1075
1076 Data = Data & ~SERIAL_LCR_DLAB;
3f542974
PS
1077 status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
1078 mos7840_port->shadowLCR = Data;
1079
880af9db 1080 /* clearing Bulkin and Bulkout Fifo */
3f542974 1081 Data = 0x0;
3f542974
PS
1082 status = mos7840_get_reg_sync(port, mos7840_port->SpRegOffset, &Data);
1083
1084 Data = Data | 0x0c;
3f542974
PS
1085 status = mos7840_set_reg_sync(port, mos7840_port->SpRegOffset, Data);
1086
1087 Data = Data & ~0x0c;
3f542974 1088 status = mos7840_set_reg_sync(port, mos7840_port->SpRegOffset, Data);
880af9db 1089 /* Finally enable all interrupts */
3f542974 1090 Data = 0x0c;
3f542974
PS
1091 status = mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data);
1092
880af9db 1093 /* clearing rx_disable */
3f542974 1094 Data = 0x0;
880af9db
AC
1095 status = mos7840_get_reg_sync(port, mos7840_port->ControlRegOffset,
1096 &Data);
3f542974 1097 Data = Data & ~0x20;
880af9db
AC
1098 status = mos7840_set_reg_sync(port, mos7840_port->ControlRegOffset,
1099 Data);
3f542974 1100
880af9db 1101 /* rx_negate */
3f542974 1102 Data = 0x0;
880af9db
AC
1103 status = mos7840_get_reg_sync(port, mos7840_port->ControlRegOffset,
1104 &Data);
3f542974 1105 Data = Data | 0x10;
880af9db
AC
1106 status = mos7840_set_reg_sync(port, mos7840_port->ControlRegOffset,
1107 Data);
3f542974 1108
880af9db
AC
1109 /* Check to see if we've set up our endpoint info yet *
1110 * (can't set it up in mos7840_startup as the structures *
1111 * were not set up at that time.) */
0de9a702 1112 if (port0->open_ports == 1) {
3f542974 1113 if (serial->port[0]->interrupt_in_buffer == NULL) {
3f542974 1114 /* set up interrupt urb */
3f542974 1115 usb_fill_int_urb(serial->port[0]->interrupt_in_urb,
880af9db
AC
1116 serial->dev,
1117 usb_rcvintpipe(serial->dev,
1118 serial->port[0]->interrupt_in_endpointAddress),
1119 serial->port[0]->interrupt_in_buffer,
1120 serial->port[0]->interrupt_in_urb->
1121 transfer_buffer_length,
1122 mos7840_interrupt_callback,
1123 serial,
1124 serial->port[0]->interrupt_in_urb->interval);
3f542974
PS
1125
1126 /* start interrupt read for mos7840 *
1127 * will continue as long as mos7840 is connected */
1128
1129 response =
1130 usb_submit_urb(serial->port[0]->interrupt_in_urb,
1131 GFP_KERNEL);
1132 if (response) {
194343d9
GKH
1133 dev_err(&port->dev, "%s - Error %d submitting "
1134 "interrupt urb\n", __func__, response);
3f542974
PS
1135 }
1136
1137 }
1138
1139 }
1140
1141 /* see if we've set up our endpoint info yet *
1142 * (can't set it up in mos7840_startup as the *
1143 * structures were not set up at that time.) */
1144
84fe6e79
TC
1145 dbg("port number is %d", port->number);
1146 dbg("serial number is %d", port->serial->minor);
1147 dbg("Bulkin endpoint is %d", port->bulk_in_endpointAddress);
1148 dbg("BulkOut endpoint is %d", port->bulk_out_endpointAddress);
1149 dbg("Interrupt endpoint is %d", port->interrupt_in_endpointAddress);
1150 dbg("port's number in the device is %d", mos7840_port->port_num);
3f542974
PS
1151 mos7840_port->read_urb = port->read_urb;
1152
1153 /* set up our bulk in urb */
093ea2d3
DL
1154 if ((serial->num_ports == 2)
1155 && ((((__u16)port->number -
1156 (__u16)(port->serial->minor)) % 2) != 0)) {
1157 usb_fill_bulk_urb(mos7840_port->read_urb,
1158 serial->dev,
1159 usb_rcvbulkpipe(serial->dev,
1160 (port->bulk_in_endpointAddress) + 2),
1161 port->bulk_in_buffer,
1162 mos7840_port->read_urb->transfer_buffer_length,
1163 mos7840_bulk_in_callback, mos7840_port);
1164 } else {
1165 usb_fill_bulk_urb(mos7840_port->read_urb,
1166 serial->dev,
1167 usb_rcvbulkpipe(serial->dev,
1168 port->bulk_in_endpointAddress),
1169 port->bulk_in_buffer,
1170 mos7840_port->read_urb->transfer_buffer_length,
1171 mos7840_bulk_in_callback, mos7840_port);
1172 }
3f542974 1173
84fe6e79 1174 dbg("mos7840_open: bulkin endpoint is %d",
3f542974 1175 port->bulk_in_endpointAddress);
50de36f7 1176 mos7840_port->read_urb_busy = true;
3f542974
PS
1177 response = usb_submit_urb(mos7840_port->read_urb, GFP_KERNEL);
1178 if (response) {
194343d9
GKH
1179 dev_err(&port->dev, "%s - Error %d submitting control urb\n",
1180 __func__, response);
50de36f7 1181 mos7840_port->read_urb_busy = false;
3f542974
PS
1182 }
1183
1184 /* initialize our wait queues */
1185 init_waitqueue_head(&mos7840_port->wait_chase);
1186 init_waitqueue_head(&mos7840_port->delta_msr_wait);
1187
1188 /* initialize our icount structure */
1189 memset(&(mos7840_port->icount), 0x00, sizeof(mos7840_port->icount));
1190
1191 /* initialize our port settings */
880af9db
AC
1192 /* Must set to enable ints! */
1193 mos7840_port->shadowMCR = MCR_MASTER_IE;
3f542974
PS
1194 /* send a open port command */
1195 mos7840_port->open = 1;
880af9db 1196 /* mos7840_change_port_settings(mos7840_port,old_termios); */
3f542974
PS
1197 mos7840_port->icount.tx = 0;
1198 mos7840_port->icount.rx = 0;
1199
84fe6e79 1200 dbg("usb_serial serial:%p mos7840_port:%p\n usb_serial_port port:%p",
880af9db 1201 serial, mos7840_port, port);
3f542974
PS
1202
1203 return 0;
3f542974
PS
1204}
1205
1206/*****************************************************************************
1207 * mos7840_chars_in_buffer
1208 * this function is called by the tty driver when it wants to know how many
1209 * bytes of data we currently have outstanding in the port (data that has
1210 * been written, but hasn't made it out the port yet)
1211 * If successful, we return the number of bytes left to be written in the
1212 * system,
95da310e 1213 * Otherwise we return zero.
3f542974
PS
1214 *****************************************************************************/
1215
95da310e 1216static int mos7840_chars_in_buffer(struct tty_struct *tty)
3f542974 1217{
95da310e 1218 struct usb_serial_port *port = tty->driver_data;
3f542974
PS
1219 int i;
1220 int chars = 0;
0de9a702 1221 unsigned long flags;
3f542974
PS
1222 struct moschip_port *mos7840_port;
1223
441b62c1 1224 if (mos7840_port_paranoia_check(port, __func__)) {
84fe6e79 1225 dbg("%s", "Invalid port");
95da310e 1226 return 0;
3f542974
PS
1227 }
1228
1229 mos7840_port = mos7840_get_port_private(port);
3363155b 1230 if (mos7840_port == NULL)
95da310e 1231 return 0;
3f542974 1232
880af9db 1233 spin_lock_irqsave(&mos7840_port->pool_lock, flags);
5c263b92
MF
1234 for (i = 0; i < NUM_URBS; ++i) {
1235 if (mos7840_port->busy[i]) {
1236 struct urb *urb = mos7840_port->write_urb_pool[i];
1237 chars += urb->transfer_buffer_length;
1238 }
1239 }
880af9db 1240 spin_unlock_irqrestore(&mos7840_port->pool_lock, flags);
441b62c1 1241 dbg("%s - returns %d", __func__, chars);
0de9a702 1242 return chars;
3f542974
PS
1243
1244}
1245
3f542974
PS
1246/*****************************************************************************
1247 * mos7840_close
1248 * this function is called by the tty driver when a port is closed
1249 *****************************************************************************/
1250
335f8514 1251static void mos7840_close(struct usb_serial_port *port)
3f542974
PS
1252{
1253 struct usb_serial *serial;
1254 struct moschip_port *mos7840_port;
0de9a702 1255 struct moschip_port *port0;
3f542974
PS
1256 int j;
1257 __u16 Data;
1258
441b62c1 1259 if (mos7840_port_paranoia_check(port, __func__)) {
84fe6e79 1260 dbg("%s", "Port Paranoia failed");
3f542974
PS
1261 return;
1262 }
1263
441b62c1 1264 serial = mos7840_get_usb_serial(port, __func__);
3f542974 1265 if (!serial) {
84fe6e79 1266 dbg("%s", "Serial Paranoia failed");
3f542974
PS
1267 return;
1268 }
1269
1270 mos7840_port = mos7840_get_port_private(port);
0de9a702 1271 port0 = mos7840_get_port_private(serial->port[0]);
3f542974 1272
0de9a702 1273 if (mos7840_port == NULL || port0 == NULL)
3f542974 1274 return;
3f542974
PS
1275
1276 for (j = 0; j < NUM_URBS; ++j)
1277 usb_kill_urb(mos7840_port->write_urb_pool[j]);
1278
1279 /* Freeing Write URBs */
1280 for (j = 0; j < NUM_URBS; ++j) {
1281 if (mos7840_port->write_urb_pool[j]) {
1282 if (mos7840_port->write_urb_pool[j]->transfer_buffer)
1283 kfree(mos7840_port->write_urb_pool[j]->
1284 transfer_buffer);
1285
1286 usb_free_urb(mos7840_port->write_urb_pool[j]);
1287 }
1288 }
1289
3f542974
PS
1290 /* While closing port, shutdown all bulk read, write *
1291 * and interrupt read if they exists */
1292 if (serial->dev) {
3f542974 1293 if (mos7840_port->write_urb) {
84fe6e79 1294 dbg("%s", "Shutdown bulk write");
3f542974
PS
1295 usb_kill_urb(mos7840_port->write_urb);
1296 }
3f542974 1297 if (mos7840_port->read_urb) {
84fe6e79 1298 dbg("%s", "Shutdown bulk read");
3f542974 1299 usb_kill_urb(mos7840_port->read_urb);
50de36f7 1300 mos7840_port->read_urb_busy = false;
3f542974
PS
1301 }
1302 if ((&mos7840_port->control_urb)) {
84fe6e79 1303 dbg("%s", "Shutdown control read");
880af9db 1304 /*/ usb_kill_urb (mos7840_port->control_urb); */
3f542974
PS
1305 }
1306 }
880af9db
AC
1307/* if(mos7840_port->ctrl_buf != NULL) */
1308/* kfree(mos7840_port->ctrl_buf); */
0de9a702 1309 port0->open_ports--;
84fe6e79 1310 dbg("mos7840_num_open_ports in close%d:in port%d",
0de9a702
ON
1311 port0->open_ports, port->number);
1312 if (port0->open_ports == 0) {
3f542974 1313 if (serial->port[0]->interrupt_in_urb) {
84fe6e79 1314 dbg("%s", "Shutdown interrupt_in_urb");
0de9a702 1315 usb_kill_urb(serial->port[0]->interrupt_in_urb);
3f542974
PS
1316 }
1317 }
1318
1319 if (mos7840_port->write_urb) {
1320 /* if this urb had a transfer buffer already (old tx) free it */
880af9db 1321 if (mos7840_port->write_urb->transfer_buffer != NULL)
3f542974 1322 kfree(mos7840_port->write_urb->transfer_buffer);
3f542974
PS
1323 usb_free_urb(mos7840_port->write_urb);
1324 }
1325
1326 Data = 0x0;
1327 mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
1328
1329 Data = 0x00;
1330 mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data);
1331
1332 mos7840_port->open = 0;
3f542974
PS
1333}
1334
1335/************************************************************************
1336 *
1337 * mos7840_block_until_chase_response
1338 *
1339 * This function will block the close until one of the following:
1340 * 1. Response to our Chase comes from mos7840
dc0d5c1e 1341 * 2. A timeout of 10 seconds without activity has expired
3f542974
PS
1342 * (1K of mos7840 data @ 2400 baud ==> 4 sec to empty)
1343 *
1344 ************************************************************************/
1345
95da310e
AC
1346static void mos7840_block_until_chase_response(struct tty_struct *tty,
1347 struct moschip_port *mos7840_port)
3f542974 1348{
1e658489 1349 int timeout = msecs_to_jiffies(1000);
3f542974
PS
1350 int wait = 10;
1351 int count;
1352
1353 while (1) {
95da310e 1354 count = mos7840_chars_in_buffer(tty);
3f542974
PS
1355
1356 /* Check for Buffer status */
880af9db 1357 if (count <= 0)
3f542974 1358 return;
3f542974
PS
1359
1360 /* Block the thread for a while */
1361 interruptible_sleep_on_timeout(&mos7840_port->wait_chase,
1362 timeout);
1363 /* No activity.. count down section */
1364 wait--;
1365 if (wait == 0) {
441b62c1 1366 dbg("%s - TIMEOUT", __func__);
3f542974
PS
1367 return;
1368 } else {
dc0d5c1e 1369 /* Reset timeout value back to seconds */
3f542974
PS
1370 wait = 10;
1371 }
1372 }
1373
1374}
1375
1376/*****************************************************************************
1377 * mos7840_break
1378 * this function sends a break to the port
1379 *****************************************************************************/
95da310e 1380static void mos7840_break(struct tty_struct *tty, int break_state)
3f542974 1381{
95da310e 1382 struct usb_serial_port *port = tty->driver_data;
3f542974
PS
1383 unsigned char data;
1384 struct usb_serial *serial;
1385 struct moschip_port *mos7840_port;
1386
441b62c1 1387 if (mos7840_port_paranoia_check(port, __func__)) {
84fe6e79 1388 dbg("%s", "Port Paranoia failed");
3f542974
PS
1389 return;
1390 }
1391
441b62c1 1392 serial = mos7840_get_usb_serial(port, __func__);
3f542974 1393 if (!serial) {
84fe6e79 1394 dbg("%s", "Serial Paranoia failed");
3f542974
PS
1395 return;
1396 }
1397
1398 mos7840_port = mos7840_get_port_private(port);
1399
880af9db 1400 if (mos7840_port == NULL)
3f542974 1401 return;
3f542974 1402
95da310e 1403 if (serial->dev)
3f542974 1404 /* flush and block until tx is empty */
95da310e 1405 mos7840_block_until_chase_response(tty, mos7840_port);
3f542974 1406
95da310e 1407 if (break_state == -1)
3f542974 1408 data = mos7840_port->shadowLCR | LCR_SET_BREAK;
95da310e 1409 else
3f542974 1410 data = mos7840_port->shadowLCR & ~LCR_SET_BREAK;
3f542974 1411
6b447f04 1412 /* FIXME: no locking on shadowLCR anywhere in driver */
3f542974 1413 mos7840_port->shadowLCR = data;
84fe6e79 1414 dbg("mcs7840_break mos7840_port->shadowLCR is %x",
3f542974
PS
1415 mos7840_port->shadowLCR);
1416 mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER,
1417 mos7840_port->shadowLCR);
3f542974
PS
1418}
1419
1420/*****************************************************************************
1421 * mos7840_write_room
1422 * this function is called by the tty driver when it wants to know how many
1423 * bytes of data we can accept for a specific port.
1424 * If successful, we return the amount of room that we have for this port
1425 * Otherwise we return a negative error number.
1426 *****************************************************************************/
1427
95da310e 1428static int mos7840_write_room(struct tty_struct *tty)
3f542974 1429{
95da310e 1430 struct usb_serial_port *port = tty->driver_data;
3f542974
PS
1431 int i;
1432 int room = 0;
0de9a702 1433 unsigned long flags;
3f542974
PS
1434 struct moschip_port *mos7840_port;
1435
441b62c1 1436 if (mos7840_port_paranoia_check(port, __func__)) {
84fe6e79
TC
1437 dbg("%s", "Invalid port");
1438 dbg("%s", " mos7840_write_room:leaving ...........");
3f542974
PS
1439 return -1;
1440 }
1441
1442 mos7840_port = mos7840_get_port_private(port);
1443 if (mos7840_port == NULL) {
84fe6e79 1444 dbg("%s", "mos7840_break:leaving ...........");
3f542974
PS
1445 return -1;
1446 }
1447
0de9a702 1448 spin_lock_irqsave(&mos7840_port->pool_lock, flags);
3f542974 1449 for (i = 0; i < NUM_URBS; ++i) {
880af9db 1450 if (!mos7840_port->busy[i])
3f542974 1451 room += URB_TRANSFER_BUFFER_SIZE;
3f542974 1452 }
0de9a702 1453 spin_unlock_irqrestore(&mos7840_port->pool_lock, flags);
3f542974 1454
0de9a702 1455 room = (room == 0) ? 0 : room - URB_TRANSFER_BUFFER_SIZE + 1;
441b62c1 1456 dbg("%s - returns %d", __func__, room);
0de9a702 1457 return room;
3f542974
PS
1458
1459}
1460
1461/*****************************************************************************
1462 * mos7840_write
1463 * this function is called by the tty driver when data should be written to
1464 * the port.
1465 * If successful, we return the number of bytes written, otherwise we
1466 * return a negative error number.
1467 *****************************************************************************/
1468
95da310e 1469static int mos7840_write(struct tty_struct *tty, struct usb_serial_port *port,
3f542974
PS
1470 const unsigned char *data, int count)
1471{
1472 int status;
1473 int i;
1474 int bytes_sent = 0;
1475 int transfer_size;
0de9a702 1476 unsigned long flags;
3f542974
PS
1477
1478 struct moschip_port *mos7840_port;
1479 struct usb_serial *serial;
1480 struct urb *urb;
880af9db 1481 /* __u16 Data; */
3f542974
PS
1482 const unsigned char *current_position = data;
1483 unsigned char *data1;
3f542974
PS
1484
1485#ifdef NOTMOS7840
1486 Data = 0x00;
3f542974
PS
1487 status = mos7840_get_uart_reg(port, LINE_CONTROL_REGISTER, &Data);
1488 mos7840_port->shadowLCR = Data;
84fe6e79
TC
1489 dbg("mos7840_write: LINE_CONTROL_REGISTER is %x", Data);
1490 dbg("mos7840_write: mos7840_port->shadowLCR is %x",
3f542974
PS
1491 mos7840_port->shadowLCR);
1492
880af9db
AC
1493 /* Data = 0x03; */
1494 /* status = mos7840_set_uart_reg(port,LINE_CONTROL_REGISTER,Data); */
1495 /* mos7840_port->shadowLCR=Data;//Need to add later */
3f542974 1496
880af9db 1497 Data |= SERIAL_LCR_DLAB; /* data latch enable in LCR 0x80 */
3f542974
PS
1498 status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
1499
880af9db
AC
1500 /* Data = 0x0c; */
1501 /* status = mos7840_set_uart_reg(port,DIVISOR_LATCH_LSB,Data); */
3f542974 1502 Data = 0x00;
3f542974 1503 status = mos7840_get_uart_reg(port, DIVISOR_LATCH_LSB, &Data);
84fe6e79 1504 dbg("mos7840_write:DLL value is %x", Data);
3f542974
PS
1505
1506 Data = 0x0;
3f542974 1507 status = mos7840_get_uart_reg(port, DIVISOR_LATCH_MSB, &Data);
84fe6e79 1508 dbg("mos7840_write:DLM value is %x", Data);
3f542974
PS
1509
1510 Data = Data & ~SERIAL_LCR_DLAB;
84fe6e79 1511 dbg("mos7840_write: mos7840_port->shadowLCR is %x",
3f542974 1512 mos7840_port->shadowLCR);
3f542974
PS
1513 status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
1514#endif
1515
441b62c1 1516 if (mos7840_port_paranoia_check(port, __func__)) {
84fe6e79 1517 dbg("%s", "Port Paranoia failed");
3f542974
PS
1518 return -1;
1519 }
1520
1521 serial = port->serial;
441b62c1 1522 if (mos7840_serial_paranoia_check(serial, __func__)) {
84fe6e79 1523 dbg("%s", "Serial Paranoia failed");
3f542974
PS
1524 return -1;
1525 }
1526
1527 mos7840_port = mos7840_get_port_private(port);
1528 if (mos7840_port == NULL) {
84fe6e79 1529 dbg("%s", "mos7840_port is NULL");
3f542974
PS
1530 return -1;
1531 }
1532
1533 /* try to find a free urb in the list */
1534 urb = NULL;
1535
0de9a702 1536 spin_lock_irqsave(&mos7840_port->pool_lock, flags);
3f542974 1537 for (i = 0; i < NUM_URBS; ++i) {
0de9a702
ON
1538 if (!mos7840_port->busy[i]) {
1539 mos7840_port->busy[i] = 1;
3f542974 1540 urb = mos7840_port->write_urb_pool[i];
84fe6e79 1541 dbg("URB:%d", i);
3f542974
PS
1542 break;
1543 }
1544 }
0de9a702 1545 spin_unlock_irqrestore(&mos7840_port->pool_lock, flags);
3f542974
PS
1546
1547 if (urb == NULL) {
441b62c1 1548 dbg("%s - no more free urbs", __func__);
3f542974
PS
1549 goto exit;
1550 }
1551
1552 if (urb->transfer_buffer == NULL) {
1553 urb->transfer_buffer =
1554 kmalloc(URB_TRANSFER_BUFFER_SIZE, GFP_KERNEL);
1555
1556 if (urb->transfer_buffer == NULL) {
22a416c4 1557 dev_err_console(port, "%s no more kernel memory...\n",
194343d9 1558 __func__);
3f542974
PS
1559 goto exit;
1560 }
1561 }
1562 transfer_size = min(count, URB_TRANSFER_BUFFER_SIZE);
1563
97c4965d 1564 memcpy(urb->transfer_buffer, current_position, transfer_size);
3f542974
PS
1565
1566 /* fill urb with data and submit */
093ea2d3
DL
1567 if ((serial->num_ports == 2)
1568 && ((((__u16)port->number -
1569 (__u16)(port->serial->minor)) % 2) != 0)) {
1570 usb_fill_bulk_urb(urb,
1571 serial->dev,
1572 usb_sndbulkpipe(serial->dev,
1573 (port->bulk_out_endpointAddress) + 2),
1574 urb->transfer_buffer,
1575 transfer_size,
1576 mos7840_bulk_out_data_callback, mos7840_port);
1577 } else {
1578 usb_fill_bulk_urb(urb,
1579 serial->dev,
1580 usb_sndbulkpipe(serial->dev,
1581 port->bulk_out_endpointAddress),
1582 urb->transfer_buffer,
1583 transfer_size,
1584 mos7840_bulk_out_data_callback, mos7840_port);
1585 }
3f542974
PS
1586
1587 data1 = urb->transfer_buffer;
84fe6e79 1588 dbg("bulkout endpoint is %d", port->bulk_out_endpointAddress);
3f542974 1589
0eafe4de
D
1590 /* Turn on LED */
1591 if (mos7840_port->has_led && !mos7840_port->led_flag) {
1592 mos7840_port->led_flag = true;
1593 mos7840_set_led_sync(port, MODEM_CONTROL_REGISTER, 0x0301);
1594 mod_timer(&mos7840_port->led_timer1,
1595 jiffies + msecs_to_jiffies(LED_ON_MS));
1596 }
1597
3f542974
PS
1598 /* send it down the pipe */
1599 status = usb_submit_urb(urb, GFP_ATOMIC);
1600
1601 if (status) {
0de9a702 1602 mos7840_port->busy[i] = 0;
22a416c4 1603 dev_err_console(port, "%s - usb_submit_urb(write bulk) failed "
194343d9 1604 "with status = %d\n", __func__, status);
3f542974
PS
1605 bytes_sent = status;
1606 goto exit;
1607 }
1608 bytes_sent = transfer_size;
1609 mos7840_port->icount.tx += transfer_size;
0de9a702 1610 smp_wmb();
84fe6e79 1611 dbg("mos7840_port->icount.tx is %d:", mos7840_port->icount.tx);
95da310e 1612exit:
3f542974
PS
1613 return bytes_sent;
1614
1615}
1616
1617/*****************************************************************************
1618 * mos7840_throttle
1619 * this function is called by the tty driver when it wants to stop the data
1620 * being read from the port.
1621 *****************************************************************************/
1622
95da310e 1623static void mos7840_throttle(struct tty_struct *tty)
3f542974 1624{
95da310e 1625 struct usb_serial_port *port = tty->driver_data;
3f542974 1626 struct moschip_port *mos7840_port;
3f542974
PS
1627 int status;
1628
441b62c1 1629 if (mos7840_port_paranoia_check(port, __func__)) {
84fe6e79 1630 dbg("%s", "Invalid port");
3f542974
PS
1631 return;
1632 }
1633
84fe6e79 1634 dbg("- port %d", port->number);
3f542974
PS
1635
1636 mos7840_port = mos7840_get_port_private(port);
1637
1638 if (mos7840_port == NULL)
1639 return;
1640
1641 if (!mos7840_port->open) {
84fe6e79 1642 dbg("%s", "port not opened");
3f542974
PS
1643 return;
1644 }
1645
3f542974
PS
1646 /* if we are implementing XON/XOFF, send the stop character */
1647 if (I_IXOFF(tty)) {
1648 unsigned char stop_char = STOP_CHAR(tty);
95da310e
AC
1649 status = mos7840_write(tty, port, &stop_char, 1);
1650 if (status <= 0)
3f542974 1651 return;
3f542974 1652 }
3f542974
PS
1653 /* if we are implementing RTS/CTS, toggle that line */
1654 if (tty->termios->c_cflag & CRTSCTS) {
1655 mos7840_port->shadowMCR &= ~MCR_RTS;
95da310e 1656 status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER,
3f542974 1657 mos7840_port->shadowMCR);
95da310e 1658 if (status < 0)
3f542974 1659 return;
3f542974 1660 }
3f542974
PS
1661}
1662
1663/*****************************************************************************
1664 * mos7840_unthrottle
880af9db
AC
1665 * this function is called by the tty driver when it wants to resume
1666 * the data being read from the port (called after mos7840_throttle is
1667 * called)
3f542974 1668 *****************************************************************************/
95da310e 1669static void mos7840_unthrottle(struct tty_struct *tty)
3f542974 1670{
95da310e 1671 struct usb_serial_port *port = tty->driver_data;
3f542974
PS
1672 int status;
1673 struct moschip_port *mos7840_port = mos7840_get_port_private(port);
1674
441b62c1 1675 if (mos7840_port_paranoia_check(port, __func__)) {
84fe6e79 1676 dbg("%s", "Invalid port");
3f542974
PS
1677 return;
1678 }
1679
1680 if (mos7840_port == NULL)
1681 return;
1682
1683 if (!mos7840_port->open) {
441b62c1 1684 dbg("%s - port not opened", __func__);
3f542974
PS
1685 return;
1686 }
1687
3f542974
PS
1688 /* if we are implementing XON/XOFF, send the start character */
1689 if (I_IXOFF(tty)) {
1690 unsigned char start_char = START_CHAR(tty);
95da310e
AC
1691 status = mos7840_write(tty, port, &start_char, 1);
1692 if (status <= 0)
3f542974 1693 return;
3f542974
PS
1694 }
1695
1696 /* if we are implementing RTS/CTS, toggle that line */
1697 if (tty->termios->c_cflag & CRTSCTS) {
1698 mos7840_port->shadowMCR |= MCR_RTS;
95da310e 1699 status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER,
3f542974 1700 mos7840_port->shadowMCR);
95da310e 1701 if (status < 0)
3f542974 1702 return;
3f542974 1703 }
3f542974
PS
1704}
1705
60b33c13 1706static int mos7840_tiocmget(struct tty_struct *tty)
3f542974 1707{
95da310e 1708 struct usb_serial_port *port = tty->driver_data;
3f542974
PS
1709 struct moschip_port *mos7840_port;
1710 unsigned int result;
1711 __u16 msr;
1712 __u16 mcr;
880af9db 1713 int status;
3f542974
PS
1714 mos7840_port = mos7840_get_port_private(port);
1715
3f542974
PS
1716 if (mos7840_port == NULL)
1717 return -ENODEV;
1718
1719 status = mos7840_get_uart_reg(port, MODEM_STATUS_REGISTER, &msr);
1720 status = mos7840_get_uart_reg(port, MODEM_CONTROL_REGISTER, &mcr);
1721 result = ((mcr & MCR_DTR) ? TIOCM_DTR : 0)
1722 | ((mcr & MCR_RTS) ? TIOCM_RTS : 0)
1723 | ((mcr & MCR_LOOPBACK) ? TIOCM_LOOP : 0)
1724 | ((msr & MOS7840_MSR_CTS) ? TIOCM_CTS : 0)
1725 | ((msr & MOS7840_MSR_CD) ? TIOCM_CAR : 0)
1726 | ((msr & MOS7840_MSR_RI) ? TIOCM_RI : 0)
1727 | ((msr & MOS7840_MSR_DSR) ? TIOCM_DSR : 0);
1728
441b62c1 1729 dbg("%s - 0x%04X", __func__, result);
3f542974
PS
1730
1731 return result;
1732}
1733
20b9d177 1734static int mos7840_tiocmset(struct tty_struct *tty,
3f542974
PS
1735 unsigned int set, unsigned int clear)
1736{
95da310e 1737 struct usb_serial_port *port = tty->driver_data;
3f542974
PS
1738 struct moschip_port *mos7840_port;
1739 unsigned int mcr;
87521c46 1740 int status;
3f542974 1741
3f542974
PS
1742 mos7840_port = mos7840_get_port_private(port);
1743
1744 if (mos7840_port == NULL)
1745 return -ENODEV;
1746
e2984494 1747 /* FIXME: What locks the port registers ? */
3f542974
PS
1748 mcr = mos7840_port->shadowMCR;
1749 if (clear & TIOCM_RTS)
1750 mcr &= ~MCR_RTS;
1751 if (clear & TIOCM_DTR)
1752 mcr &= ~MCR_DTR;
1753 if (clear & TIOCM_LOOP)
1754 mcr &= ~MCR_LOOPBACK;
1755
1756 if (set & TIOCM_RTS)
1757 mcr |= MCR_RTS;
1758 if (set & TIOCM_DTR)
1759 mcr |= MCR_DTR;
1760 if (set & TIOCM_LOOP)
1761 mcr |= MCR_LOOPBACK;
1762
1763 mos7840_port->shadowMCR = mcr;
1764
3f542974
PS
1765 status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, mcr);
1766 if (status < 0) {
84fe6e79 1767 dbg("setting MODEM_CONTROL_REGISTER Failed");
87521c46 1768 return status;
3f542974
PS
1769 }
1770
1771 return 0;
1772}
1773
1774/*****************************************************************************
1775 * mos7840_calc_baud_rate_divisor
1776 * this function calculates the proper baud rate divisor for the specified
1777 * baud rate.
1778 *****************************************************************************/
1779static int mos7840_calc_baud_rate_divisor(int baudRate, int *divisor,
880af9db 1780 __u16 *clk_sel_val)
3f542974 1781{
441b62c1 1782 dbg("%s - %d", __func__, baudRate);
3f542974
PS
1783
1784 if (baudRate <= 115200) {
1785 *divisor = 115200 / baudRate;
1786 *clk_sel_val = 0x0;
1787 }
1788 if ((baudRate > 115200) && (baudRate <= 230400)) {
1789 *divisor = 230400 / baudRate;
1790 *clk_sel_val = 0x10;
1791 } else if ((baudRate > 230400) && (baudRate <= 403200)) {
1792 *divisor = 403200 / baudRate;
1793 *clk_sel_val = 0x20;
1794 } else if ((baudRate > 403200) && (baudRate <= 460800)) {
1795 *divisor = 460800 / baudRate;
1796 *clk_sel_val = 0x30;
1797 } else if ((baudRate > 460800) && (baudRate <= 806400)) {
1798 *divisor = 806400 / baudRate;
1799 *clk_sel_val = 0x40;
1800 } else if ((baudRate > 806400) && (baudRate <= 921600)) {
1801 *divisor = 921600 / baudRate;
1802 *clk_sel_val = 0x50;
1803 } else if ((baudRate > 921600) && (baudRate <= 1572864)) {
1804 *divisor = 1572864 / baudRate;
1805 *clk_sel_val = 0x60;
1806 } else if ((baudRate > 1572864) && (baudRate <= 3145728)) {
1807 *divisor = 3145728 / baudRate;
1808 *clk_sel_val = 0x70;
1809 }
1810 return 0;
1811
1812#ifdef NOTMCS7840
1813
1814 for (i = 0; i < ARRAY_SIZE(mos7840_divisor_table); i++) {
1815 if (mos7840_divisor_table[i].BaudRate == baudrate) {
1816 *divisor = mos7840_divisor_table[i].Divisor;
1817 return 0;
1818 }
1819 }
1820
1821 /* After trying for all the standard baud rates *
1822 * Try calculating the divisor for this baud rate */
1823
1824 if (baudrate > 75 && baudrate < 230400) {
1825 /* get the divisor */
1826 custom = (__u16) (230400L / baudrate);
1827
1828 /* Check for round off */
1829 round1 = (__u16) (2304000L / baudrate);
1830 round = (__u16) (round1 - (custom * 10));
880af9db 1831 if (round > 4)
3f542974 1832 custom++;
3f542974
PS
1833 *divisor = custom;
1834
84fe6e79 1835 dbg(" Baud %d = %d", baudrate, custom);
3f542974
PS
1836 return 0;
1837 }
1838
84fe6e79 1839 dbg("%s", " Baud calculation Failed...");
3f542974
PS
1840 return -1;
1841#endif
1842}
1843
1844/*****************************************************************************
1845 * mos7840_send_cmd_write_baud_rate
1846 * this function sends the proper command to change the baud rate of the
1847 * specified port.
1848 *****************************************************************************/
1849
1850static int mos7840_send_cmd_write_baud_rate(struct moschip_port *mos7840_port,
1851 int baudRate)
1852{
1853 int divisor = 0;
1854 int status;
1855 __u16 Data;
1856 unsigned char number;
1857 __u16 clk_sel_val;
1858 struct usb_serial_port *port;
1859
1860 if (mos7840_port == NULL)
1861 return -1;
1862
1863 port = (struct usb_serial_port *)mos7840_port->port;
441b62c1 1864 if (mos7840_port_paranoia_check(port, __func__)) {
84fe6e79 1865 dbg("%s", "Invalid port");
3f542974
PS
1866 return -1;
1867 }
1868
441b62c1 1869 if (mos7840_serial_paranoia_check(port->serial, __func__)) {
84fe6e79 1870 dbg("%s", "Invalid Serial");
3f542974
PS
1871 return -1;
1872 }
1873
3f542974
PS
1874 number = mos7840_port->port->number - mos7840_port->port->serial->minor;
1875
441b62c1 1876 dbg("%s - port = %d, baud = %d", __func__,
3f542974 1877 mos7840_port->port->number, baudRate);
880af9db 1878 /* reset clk_uart_sel in spregOffset */
3f542974
PS
1879 if (baudRate > 115200) {
1880#ifdef HW_flow_control
880af9db
AC
1881 /* NOTE: need to see the pther register to modify */
1882 /* setting h/w flow control bit to 1 */
3f542974
PS
1883 Data = 0x2b;
1884 mos7840_port->shadowMCR = Data;
880af9db
AC
1885 status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER,
1886 Data);
3f542974 1887 if (status < 0) {
84fe6e79 1888 dbg("Writing spreg failed in set_serial_baud");
3f542974
PS
1889 return -1;
1890 }
1891#endif
1892
1893 } else {
1894#ifdef HW_flow_control
093ea2d3 1895 /* setting h/w flow control bit to 0 */
3f542974
PS
1896 Data = 0xb;
1897 mos7840_port->shadowMCR = Data;
880af9db
AC
1898 status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER,
1899 Data);
3f542974 1900 if (status < 0) {
84fe6e79 1901 dbg("Writing spreg failed in set_serial_baud");
3f542974
PS
1902 return -1;
1903 }
1904#endif
1905
1906 }
1907
880af9db 1908 if (1) { /* baudRate <= 115200) */
3f542974
PS
1909 clk_sel_val = 0x0;
1910 Data = 0x0;
880af9db 1911 status = mos7840_calc_baud_rate_divisor(baudRate, &divisor,
3f542974 1912 &clk_sel_val);
880af9db
AC
1913 status = mos7840_get_reg_sync(port, mos7840_port->SpRegOffset,
1914 &Data);
3f542974 1915 if (status < 0) {
84fe6e79 1916 dbg("reading spreg failed in set_serial_baud");
3f542974
PS
1917 return -1;
1918 }
1919 Data = (Data & 0x8f) | clk_sel_val;
880af9db
AC
1920 status = mos7840_set_reg_sync(port, mos7840_port->SpRegOffset,
1921 Data);
3f542974 1922 if (status < 0) {
84fe6e79 1923 dbg("Writing spreg failed in set_serial_baud");
3f542974
PS
1924 return -1;
1925 }
1926 /* Calculate the Divisor */
1927
1928 if (status) {
194343d9 1929 dev_err(&port->dev, "%s - bad baud rate\n", __func__);
3f542974
PS
1930 return status;
1931 }
1932 /* Enable access to divisor latch */
1933 Data = mos7840_port->shadowLCR | SERIAL_LCR_DLAB;
1934 mos7840_port->shadowLCR = Data;
1935 mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
1936
1937 /* Write the divisor */
1938 Data = (unsigned char)(divisor & 0xff);
84fe6e79 1939 dbg("set_serial_baud Value to write DLL is %x", Data);
3f542974
PS
1940 mos7840_set_uart_reg(port, DIVISOR_LATCH_LSB, Data);
1941
1942 Data = (unsigned char)((divisor & 0xff00) >> 8);
84fe6e79 1943 dbg("set_serial_baud Value to write DLM is %x", Data);
3f542974
PS
1944 mos7840_set_uart_reg(port, DIVISOR_LATCH_MSB, Data);
1945
1946 /* Disable access to divisor latch */
1947 Data = mos7840_port->shadowLCR & ~SERIAL_LCR_DLAB;
1948 mos7840_port->shadowLCR = Data;
1949 mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
1950
1951 }
3f542974
PS
1952 return status;
1953}
1954
1955/*****************************************************************************
1956 * mos7840_change_port_settings
1957 * This routine is called to set the UART on the device to match
1958 * the specified new settings.
1959 *****************************************************************************/
1960
95da310e
AC
1961static void mos7840_change_port_settings(struct tty_struct *tty,
1962 struct moschip_port *mos7840_port, struct ktermios *old_termios)
3f542974 1963{
3f542974
PS
1964 int baud;
1965 unsigned cflag;
1966 unsigned iflag;
1967 __u8 lData;
1968 __u8 lParity;
1969 __u8 lStop;
1970 int status;
1971 __u16 Data;
1972 struct usb_serial_port *port;
1973 struct usb_serial *serial;
1974
1975 if (mos7840_port == NULL)
1976 return;
1977
1978 port = (struct usb_serial_port *)mos7840_port->port;
1979
441b62c1 1980 if (mos7840_port_paranoia_check(port, __func__)) {
84fe6e79 1981 dbg("%s", "Invalid port");
3f542974
PS
1982 return;
1983 }
1984
441b62c1 1985 if (mos7840_serial_paranoia_check(port->serial, __func__)) {
84fe6e79 1986 dbg("%s", "Invalid Serial");
3f542974
PS
1987 return;
1988 }
1989
1990 serial = port->serial;
1991
441b62c1 1992 dbg("%s - port %d", __func__, mos7840_port->port->number);
3f542974
PS
1993
1994 if (!mos7840_port->open) {
441b62c1 1995 dbg("%s - port not opened", __func__);
3f542974
PS
1996 return;
1997 }
1998
3f542974
PS
1999 lData = LCR_BITS_8;
2000 lStop = LCR_STOP_1;
2001 lParity = LCR_PAR_NONE;
2002
2003 cflag = tty->termios->c_cflag;
2004 iflag = tty->termios->c_iflag;
2005
2006 /* Change the number of bits */
2007 if (cflag & CSIZE) {
2008 switch (cflag & CSIZE) {
2009 case CS5:
2010 lData = LCR_BITS_5;
2011 break;
2012
2013 case CS6:
2014 lData = LCR_BITS_6;
2015 break;
2016
2017 case CS7:
2018 lData = LCR_BITS_7;
2019 break;
2020 default:
2021 case CS8:
2022 lData = LCR_BITS_8;
2023 break;
2024 }
2025 }
2026 /* Change the Parity bit */
2027 if (cflag & PARENB) {
2028 if (cflag & PARODD) {
2029 lParity = LCR_PAR_ODD;
441b62c1 2030 dbg("%s - parity = odd", __func__);
3f542974
PS
2031 } else {
2032 lParity = LCR_PAR_EVEN;
441b62c1 2033 dbg("%s - parity = even", __func__);
3f542974
PS
2034 }
2035
2036 } else {
441b62c1 2037 dbg("%s - parity = none", __func__);
3f542974
PS
2038 }
2039
880af9db 2040 if (cflag & CMSPAR)
3f542974 2041 lParity = lParity | 0x20;
3f542974
PS
2042
2043 /* Change the Stop bit */
2044 if (cflag & CSTOPB) {
2045 lStop = LCR_STOP_2;
441b62c1 2046 dbg("%s - stop bits = 2", __func__);
3f542974
PS
2047 } else {
2048 lStop = LCR_STOP_1;
441b62c1 2049 dbg("%s - stop bits = 1", __func__);
3f542974
PS
2050 }
2051
2052 /* Update the LCR with the correct value */
2053 mos7840_port->shadowLCR &=
2054 ~(LCR_BITS_MASK | LCR_STOP_MASK | LCR_PAR_MASK);
2055 mos7840_port->shadowLCR |= (lData | lParity | lStop);
2056
84fe6e79 2057 dbg("mos7840_change_port_settings mos7840_port->shadowLCR is %x",
3f542974
PS
2058 mos7840_port->shadowLCR);
2059 /* Disable Interrupts */
2060 Data = 0x00;
2061 mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data);
2062
2063 Data = 0x00;
2064 mos7840_set_uart_reg(port, FIFO_CONTROL_REGISTER, Data);
2065
2066 Data = 0xcf;
2067 mos7840_set_uart_reg(port, FIFO_CONTROL_REGISTER, Data);
2068
2069 /* Send the updated LCR value to the mos7840 */
2070 Data = mos7840_port->shadowLCR;
2071
2072 mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
2073
2074 Data = 0x00b;
2075 mos7840_port->shadowMCR = Data;
2076 mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
2077 Data = 0x00b;
2078 mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
2079
2080 /* set up the MCR register and send it to the mos7840 */
2081
2082 mos7840_port->shadowMCR = MCR_MASTER_IE;
880af9db 2083 if (cflag & CBAUD)
3f542974 2084 mos7840_port->shadowMCR |= (MCR_DTR | MCR_RTS);
3f542974 2085
880af9db 2086 if (cflag & CRTSCTS)
3f542974 2087 mos7840_port->shadowMCR |= (MCR_XON_ANY);
880af9db 2088 else
3f542974 2089 mos7840_port->shadowMCR &= ~(MCR_XON_ANY);
3f542974
PS
2090
2091 Data = mos7840_port->shadowMCR;
2092 mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
2093
2094 /* Determine divisor based on baud rate */
2095 baud = tty_get_baud_rate(tty);
2096
2097 if (!baud) {
2098 /* pick a default, any default... */
84fe6e79 2099 dbg("%s", "Picked default baud...");
3f542974
PS
2100 baud = 9600;
2101 }
2102
441b62c1 2103 dbg("%s - baud rate = %d", __func__, baud);
3f542974
PS
2104 status = mos7840_send_cmd_write_baud_rate(mos7840_port, baud);
2105
2106 /* Enable Interrupts */
2107 Data = 0x0c;
2108 mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data);
2109
50de36f7 2110 if (mos7840_port->read_urb_busy == false) {
50de36f7 2111 mos7840_port->read_urb_busy = true;
3f542974 2112 status = usb_submit_urb(mos7840_port->read_urb, GFP_ATOMIC);
3f542974 2113 if (status) {
50de36f7 2114 dbg("usb_submit_urb(read bulk) failed, status = %d",
3f542974 2115 status);
50de36f7 2116 mos7840_port->read_urb_busy = false;
3f542974
PS
2117 }
2118 }
2119 wake_up(&mos7840_port->delta_msr_wait);
2120 mos7840_port->delta_msr_cond = 1;
84fe6e79 2121 dbg("mos7840_change_port_settings mos7840_port->shadowLCR is End %x",
3f542974 2122 mos7840_port->shadowLCR);
3f542974
PS
2123}
2124
2125/*****************************************************************************
2126 * mos7840_set_termios
2127 * this function is called by the tty driver when it wants to change
2128 * the termios structure
2129 *****************************************************************************/
2130
95da310e
AC
2131static void mos7840_set_termios(struct tty_struct *tty,
2132 struct usb_serial_port *port,
606d099c 2133 struct ktermios *old_termios)
3f542974
PS
2134{
2135 int status;
2136 unsigned int cflag;
2137 struct usb_serial *serial;
2138 struct moschip_port *mos7840_port;
3363155b 2139
441b62c1 2140 if (mos7840_port_paranoia_check(port, __func__)) {
84fe6e79 2141 dbg("%s", "Invalid port");
3f542974
PS
2142 return;
2143 }
2144
2145 serial = port->serial;
2146
441b62c1 2147 if (mos7840_serial_paranoia_check(serial, __func__)) {
84fe6e79 2148 dbg("%s", "Invalid Serial");
3f542974
PS
2149 return;
2150 }
2151
2152 mos7840_port = mos7840_get_port_private(port);
2153
2154 if (mos7840_port == NULL)
2155 return;
2156
3f542974 2157 if (!mos7840_port->open) {
441b62c1 2158 dbg("%s - port not opened", __func__);
3f542974
PS
2159 return;
2160 }
2161
84fe6e79 2162 dbg("%s", "setting termios - ");
3f542974
PS
2163
2164 cflag = tty->termios->c_cflag;
2165
441b62c1 2166 dbg("%s - clfag %08x iflag %08x", __func__,
3f542974 2167 tty->termios->c_cflag, RELEVANT_IFLAG(tty->termios->c_iflag));
441b62c1 2168 dbg("%s - old clfag %08x old iflag %08x", __func__,
3d3ddce5 2169 old_termios->c_cflag, RELEVANT_IFLAG(old_termios->c_iflag));
441b62c1 2170 dbg("%s - port %d", __func__, port->number);
3f542974
PS
2171
2172 /* change the port settings to the new ones specified */
2173
95da310e 2174 mos7840_change_port_settings(tty, mos7840_port, old_termios);
3f542974
PS
2175
2176 if (!mos7840_port->read_urb) {
84fe6e79 2177 dbg("%s", "URB KILLED !!!!!");
3f542974
PS
2178 return;
2179 }
2180
50de36f7 2181 if (mos7840_port->read_urb_busy == false) {
50de36f7 2182 mos7840_port->read_urb_busy = true;
3f542974
PS
2183 status = usb_submit_urb(mos7840_port->read_urb, GFP_ATOMIC);
2184 if (status) {
50de36f7 2185 dbg("usb_submit_urb(read bulk) failed, status = %d",
3f542974 2186 status);
50de36f7 2187 mos7840_port->read_urb_busy = false;
3f542974
PS
2188 }
2189 }
3f542974
PS
2190}
2191
2192/*****************************************************************************
2193 * mos7840_get_lsr_info - get line status register info
2194 *
2195 * Purpose: Let user call ioctl() to get info when the UART physically
2196 * is emptied. On bus types like RS485, the transmitter must
2197 * release the bus after transmitting. This must be done when
2198 * the transmit shift register is empty, not be done when the
2199 * transmit holding register is empty. This functionality
2200 * allows an RS485 driver to be written in user space.
2201 *****************************************************************************/
2202
95da310e 2203static int mos7840_get_lsr_info(struct tty_struct *tty,
97c4965d 2204 unsigned int __user *value)
3f542974
PS
2205{
2206 int count;
2207 unsigned int result = 0;
2208
95da310e 2209 count = mos7840_chars_in_buffer(tty);
3f542974 2210 if (count == 0) {
441b62c1 2211 dbg("%s -- Empty", __func__);
3f542974
PS
2212 result = TIOCSER_TEMT;
2213 }
2214
2215 if (copy_to_user(value, &result, sizeof(int)))
2216 return -EFAULT;
2217 return 0;
2218}
2219
3f542974
PS
2220/*****************************************************************************
2221 * mos7840_get_serial_info
2222 * function to get information about serial port
2223 *****************************************************************************/
2224
2225static int mos7840_get_serial_info(struct moschip_port *mos7840_port,
97c4965d 2226 struct serial_struct __user *retinfo)
3f542974
PS
2227{
2228 struct serial_struct tmp;
2229
2230 if (mos7840_port == NULL)
2231 return -1;
2232
2233 if (!retinfo)
2234 return -EFAULT;
2235
2236 memset(&tmp, 0, sizeof(tmp));
2237
2238 tmp.type = PORT_16550A;
2239 tmp.line = mos7840_port->port->serial->minor;
2240 tmp.port = mos7840_port->port->number;
2241 tmp.irq = 0;
2242 tmp.flags = ASYNC_SKIP_TEST | ASYNC_AUTO_IRQ;
2243 tmp.xmit_fifo_size = NUM_URBS * URB_TRANSFER_BUFFER_SIZE;
2244 tmp.baud_base = 9600;
2245 tmp.close_delay = 5 * HZ;
2246 tmp.closing_wait = 30 * HZ;
2247
2248 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
2249 return -EFAULT;
2250 return 0;
2251}
2252
0bca1b91
AC
2253static int mos7840_get_icount(struct tty_struct *tty,
2254 struct serial_icounter_struct *icount)
2255{
2256 struct usb_serial_port *port = tty->driver_data;
2257 struct moschip_port *mos7840_port;
2258 struct async_icount cnow;
2259
2260 mos7840_port = mos7840_get_port_private(port);
2261 cnow = mos7840_port->icount;
2262
2263 smp_rmb();
2264 icount->cts = cnow.cts;
2265 icount->dsr = cnow.dsr;
2266 icount->rng = cnow.rng;
2267 icount->dcd = cnow.dcd;
2268 icount->rx = cnow.rx;
2269 icount->tx = cnow.tx;
2270 icount->frame = cnow.frame;
2271 icount->overrun = cnow.overrun;
2272 icount->parity = cnow.parity;
2273 icount->brk = cnow.brk;
2274 icount->buf_overrun = cnow.buf_overrun;
2275
2276 dbg("%s (%d) TIOCGICOUNT RX=%d, TX=%d", __func__,
2277 port->number, icount->rx, icount->tx);
2278 return 0;
2279}
2280
3f542974
PS
2281/*****************************************************************************
2282 * SerialIoctl
2283 * this function handles any ioctl calls to the driver
2284 *****************************************************************************/
2285
00a0d0d6 2286static int mos7840_ioctl(struct tty_struct *tty,
3f542974
PS
2287 unsigned int cmd, unsigned long arg)
2288{
95da310e 2289 struct usb_serial_port *port = tty->driver_data;
97c4965d 2290 void __user *argp = (void __user *)arg;
3f542974 2291 struct moschip_port *mos7840_port;
3f542974
PS
2292
2293 struct async_icount cnow;
2294 struct async_icount cprev;
3f542974 2295
441b62c1 2296 if (mos7840_port_paranoia_check(port, __func__)) {
84fe6e79 2297 dbg("%s", "Invalid port");
3f542974
PS
2298 return -1;
2299 }
2300
2301 mos7840_port = mos7840_get_port_private(port);
3f542974
PS
2302
2303 if (mos7840_port == NULL)
2304 return -1;
2305
441b62c1 2306 dbg("%s - port %d, cmd = 0x%x", __func__, port->number, cmd);
3f542974
PS
2307
2308 switch (cmd) {
2309 /* return number of bytes available */
2310
3f542974 2311 case TIOCSERGETLSR:
441b62c1 2312 dbg("%s (%d) TIOCSERGETLSR", __func__, port->number);
95da310e 2313 return mos7840_get_lsr_info(tty, argp);
3f542974 2314
3f542974 2315 case TIOCGSERIAL:
441b62c1 2316 dbg("%s (%d) TIOCGSERIAL", __func__, port->number);
97c4965d 2317 return mos7840_get_serial_info(mos7840_port, argp);
3f542974
PS
2318
2319 case TIOCSSERIAL:
441b62c1 2320 dbg("%s (%d) TIOCSSERIAL", __func__, port->number);
3f542974
PS
2321 break;
2322
2323 case TIOCMIWAIT:
441b62c1 2324 dbg("%s (%d) TIOCMIWAIT", __func__, port->number);
3f542974
PS
2325 cprev = mos7840_port->icount;
2326 while (1) {
880af9db 2327 /* interruptible_sleep_on(&mos7840_port->delta_msr_wait); */
3f542974
PS
2328 mos7840_port->delta_msr_cond = 0;
2329 wait_event_interruptible(mos7840_port->delta_msr_wait,
2330 (mos7840_port->
2331 delta_msr_cond == 1));
2332
2333 /* see if a signal did it */
2334 if (signal_pending(current))
2335 return -ERESTARTSYS;
2336 cnow = mos7840_port->icount;
0de9a702 2337 smp_rmb();
3f542974
PS
2338 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
2339 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts)
2340 return -EIO; /* no change => error */
2341 if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
2342 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
2343 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
2344 ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts))) {
2345 return 0;
2346 }
2347 cprev = cnow;
2348 }
2349 /* NOTREACHED */
2350 break;
2351
3f542974
PS
2352 default:
2353 break;
2354 }
3f542974
PS
2355 return -ENOIOCTLCMD;
2356}
2357
0eafe4de
D
2358static int mos7810_check(struct usb_serial *serial)
2359{
2360 int i, pass_count = 0;
2361 __u16 data = 0, mcr_data = 0;
2362 __u16 test_pattern = 0x55AA;
2363
2364 /* Store MCR setting */
2365 usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
2366 MCS_RDREQ, MCS_RD_RTYPE, 0x0300, MODEM_CONTROL_REGISTER,
2367 &mcr_data, VENDOR_READ_LENGTH, MOS_WDR_TIMEOUT);
2368
2369 for (i = 0; i < 16; i++) {
2370 /* Send the 1-bit test pattern out to MCS7810 test pin */
2371 usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
2372 MCS_WRREQ, MCS_WR_RTYPE,
2373 (0x0300 | (((test_pattern >> i) & 0x0001) << 1)),
2374 MODEM_CONTROL_REGISTER, NULL, 0, MOS_WDR_TIMEOUT);
2375
2376 /* Read the test pattern back */
2377 usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
2378 MCS_RDREQ, MCS_RD_RTYPE, 0, GPIO_REGISTER, &data,
2379 VENDOR_READ_LENGTH, MOS_WDR_TIMEOUT);
2380
2381 /* If this is a MCS7810 device, both test patterns must match */
2382 if (((test_pattern >> i) ^ (~data >> 1)) & 0x0001)
2383 break;
2384
2385 pass_count++;
2386 }
2387
2388 /* Restore MCR setting */
2389 usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), MCS_WRREQ,
2390 MCS_WR_RTYPE, 0x0300 | mcr_data, MODEM_CONTROL_REGISTER, NULL,
2391 0, MOS_WDR_TIMEOUT);
2392
2393 if (pass_count == 16)
2394 return 1;
2395
2396 return 0;
2397}
2398
3f542974
PS
2399static int mos7840_calc_num_ports(struct usb_serial *serial)
2400{
0eafe4de 2401 __u16 data = 0x00;
093ea2d3
DL
2402 int mos7840_num_ports;
2403
0eafe4de
D
2404 usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
2405 MCS_RDREQ, MCS_RD_RTYPE, 0, GPIO_REGISTER, &data,
093ea2d3
DL
2406 VENDOR_READ_LENGTH, MOS_WDR_TIMEOUT);
2407
0eafe4de
D
2408 if (serial->dev->descriptor.idProduct == MOSCHIP_DEVICE_ID_7810 ||
2409 serial->dev->descriptor.idProduct == MOSCHIP_DEVICE_ID_7820) {
2410 device_type = serial->dev->descriptor.idProduct;
093ea2d3 2411 } else {
0eafe4de
D
2412 /* For a MCS7840 device GPIO0 must be set to 1 */
2413 if ((data & 0x01) == 1)
2414 device_type = MOSCHIP_DEVICE_ID_7840;
2415 else if (mos7810_check(serial))
2416 device_type = MOSCHIP_DEVICE_ID_7810;
2417 else
2418 device_type = MOSCHIP_DEVICE_ID_7820;
3f542974 2419 }
093ea2d3 2420
0eafe4de
D
2421 mos7840_num_ports = (device_type >> 4) & 0x000F;
2422 serial->num_bulk_in = mos7840_num_ports;
2423 serial->num_bulk_out = mos7840_num_ports;
2424 serial->num_ports = mos7840_num_ports;
2425
3f542974
PS
2426 return mos7840_num_ports;
2427}
2428
2429/****************************************************************************
2430 * mos7840_startup
2431 ****************************************************************************/
2432
2433static int mos7840_startup(struct usb_serial *serial)
2434{
2435 struct moschip_port *mos7840_port;
2436 struct usb_device *dev;
2437 int i, status;
3f542974 2438 __u16 Data;
3f542974
PS
2439
2440 if (!serial) {
84fe6e79 2441 dbg("%s", "Invalid Handler");
3f542974
PS
2442 return -1;
2443 }
2444
2445 dev = serial->dev;
2446
3f542974
PS
2447 /* we set up the pointers to the endpoints in the mos7840_open *
2448 * function, as the structures aren't created yet. */
2449
2450 /* set up port private structures */
2451 for (i = 0; i < serial->num_ports; ++i) {
84fe6e79 2452 dbg ("mos7840_startup: configuring port %d............", i);
7ac9da10 2453 mos7840_port = kzalloc(sizeof(struct moschip_port), GFP_KERNEL);
3f542974 2454 if (mos7840_port == NULL) {
194343d9 2455 dev_err(&dev->dev, "%s - Out of memory\n", __func__);
0de9a702
ON
2456 status = -ENOMEM;
2457 i--; /* don't follow NULL pointer cleaning up */
2458 goto error;
3f542974 2459 }
3f542974 2460
880af9db
AC
2461 /* Initialize all port interrupt end point to port 0 int
2462 * endpoint. Our device has only one interrupt end point
2463 * common to all port */
3f542974
PS
2464
2465 mos7840_port->port = serial->port[i];
2466 mos7840_set_port_private(serial->port[i], mos7840_port);
0de9a702 2467 spin_lock_init(&mos7840_port->pool_lock);
3f542974 2468
37768adf
TC
2469 /* minor is not initialised until later by
2470 * usb-serial.c:get_free_serial() and cannot therefore be used
2471 * to index device instances */
2472 mos7840_port->port_num = i + 1;
2473 dbg ("serial->port[i]->number = %d", serial->port[i]->number);
2474 dbg ("serial->port[i]->serial->minor = %d", serial->port[i]->serial->minor);
2475 dbg ("mos7840_port->port_num = %d", mos7840_port->port_num);
2476 dbg ("serial->minor = %d", serial->minor);
3f542974
PS
2477
2478 if (mos7840_port->port_num == 1) {
2479 mos7840_port->SpRegOffset = 0x0;
2480 mos7840_port->ControlRegOffset = 0x1;
2481 mos7840_port->DcrRegOffset = 0x4;
2482 } else if ((mos7840_port->port_num == 2)
0de9a702 2483 && (serial->num_ports == 4)) {
3f542974
PS
2484 mos7840_port->SpRegOffset = 0x8;
2485 mos7840_port->ControlRegOffset = 0x9;
2486 mos7840_port->DcrRegOffset = 0x16;
2487 } else if ((mos7840_port->port_num == 2)
0de9a702 2488 && (serial->num_ports == 2)) {
3f542974
PS
2489 mos7840_port->SpRegOffset = 0xa;
2490 mos7840_port->ControlRegOffset = 0xb;
2491 mos7840_port->DcrRegOffset = 0x19;
2492 } else if ((mos7840_port->port_num == 3)
0de9a702 2493 && (serial->num_ports == 4)) {
3f542974
PS
2494 mos7840_port->SpRegOffset = 0xa;
2495 mos7840_port->ControlRegOffset = 0xb;
2496 mos7840_port->DcrRegOffset = 0x19;
2497 } else if ((mos7840_port->port_num == 4)
0de9a702 2498 && (serial->num_ports == 4)) {
3f542974
PS
2499 mos7840_port->SpRegOffset = 0xc;
2500 mos7840_port->ControlRegOffset = 0xd;
2501 mos7840_port->DcrRegOffset = 0x1c;
2502 }
2503 mos7840_dump_serial_port(mos7840_port);
3f542974
PS
2504 mos7840_set_port_private(serial->port[i], mos7840_port);
2505
880af9db
AC
2506 /* enable rx_disable bit in control register */
2507 status = mos7840_get_reg_sync(serial->port[i],
2508 mos7840_port->ControlRegOffset, &Data);
3f542974 2509 if (status < 0) {
84fe6e79 2510 dbg("Reading ControlReg failed status-0x%x", status);
3f542974
PS
2511 break;
2512 } else
84fe6e79 2513 dbg("ControlReg Reading success val is %x, status%d",
3f542974 2514 Data, status);
880af9db
AC
2515 Data |= 0x08; /* setting driver done bit */
2516 Data |= 0x04; /* sp1_bit to have cts change reflect in
2517 modem status reg */
3f542974 2518
880af9db
AC
2519 /* Data |= 0x20; //rx_disable bit */
2520 status = mos7840_set_reg_sync(serial->port[i],
3f542974
PS
2521 mos7840_port->ControlRegOffset, Data);
2522 if (status < 0) {
84fe6e79 2523 dbg("Writing ControlReg failed(rx_disable) status-0x%x", status);
3f542974
PS
2524 break;
2525 } else
84fe6e79 2526 dbg("ControlReg Writing success(rx_disable) status%d",
3f542974
PS
2527 status);
2528
880af9db
AC
2529 /* Write default values in DCR (i.e 0x01 in DCR0, 0x05 in DCR2
2530 and 0x24 in DCR3 */
3f542974 2531 Data = 0x01;
880af9db
AC
2532 status = mos7840_set_reg_sync(serial->port[i],
2533 (__u16) (mos7840_port->DcrRegOffset + 0), Data);
3f542974 2534 if (status < 0) {
84fe6e79 2535 dbg("Writing DCR0 failed status-0x%x", status);
3f542974
PS
2536 break;
2537 } else
84fe6e79 2538 dbg("DCR0 Writing success status%d", status);
3f542974
PS
2539
2540 Data = 0x05;
880af9db
AC
2541 status = mos7840_set_reg_sync(serial->port[i],
2542 (__u16) (mos7840_port->DcrRegOffset + 1), Data);
3f542974 2543 if (status < 0) {
84fe6e79 2544 dbg("Writing DCR1 failed status-0x%x", status);
3f542974
PS
2545 break;
2546 } else
84fe6e79 2547 dbg("DCR1 Writing success status%d", status);
3f542974
PS
2548
2549 Data = 0x24;
880af9db
AC
2550 status = mos7840_set_reg_sync(serial->port[i],
2551 (__u16) (mos7840_port->DcrRegOffset + 2), Data);
3f542974 2552 if (status < 0) {
84fe6e79 2553 dbg("Writing DCR2 failed status-0x%x", status);
3f542974
PS
2554 break;
2555 } else
84fe6e79 2556 dbg("DCR2 Writing success status%d", status);
3f542974 2557
880af9db 2558 /* write values in clkstart0x0 and clkmulti 0x20 */
3f542974 2559 Data = 0x0;
880af9db 2560 status = mos7840_set_reg_sync(serial->port[i],
3f542974
PS
2561 CLK_START_VALUE_REGISTER, Data);
2562 if (status < 0) {
84fe6e79 2563 dbg("Writing CLK_START_VALUE_REGISTER failed status-0x%x", status);
3f542974
PS
2564 break;
2565 } else
84fe6e79 2566 dbg("CLK_START_VALUE_REGISTER Writing success status%d", status);
3f542974
PS
2567
2568 Data = 0x20;
880af9db
AC
2569 status = mos7840_set_reg_sync(serial->port[i],
2570 CLK_MULTI_REGISTER, Data);
3f542974 2571 if (status < 0) {
84fe6e79 2572 dbg("Writing CLK_MULTI_REGISTER failed status-0x%x",
3f542974 2573 status);
0de9a702 2574 goto error;
3f542974 2575 } else
84fe6e79 2576 dbg("CLK_MULTI_REGISTER Writing success status%d",
3f542974
PS
2577 status);
2578
880af9db 2579 /* write value 0x0 to scratchpad register */
3f542974 2580 Data = 0x00;
880af9db
AC
2581 status = mos7840_set_uart_reg(serial->port[i],
2582 SCRATCH_PAD_REGISTER, Data);
3f542974 2583 if (status < 0) {
84fe6e79 2584 dbg("Writing SCRATCH_PAD_REGISTER failed status-0x%x",
3f542974
PS
2585 status);
2586 break;
2587 } else
84fe6e79 2588 dbg("SCRATCH_PAD_REGISTER Writing success status%d",
3f542974
PS
2589 status);
2590
880af9db 2591 /* Zero Length flag register */
3f542974 2592 if ((mos7840_port->port_num != 1)
0de9a702 2593 && (serial->num_ports == 2)) {
3f542974
PS
2594
2595 Data = 0xff;
3f542974 2596 status = mos7840_set_reg_sync(serial->port[i],
880af9db
AC
2597 (__u16) (ZLP_REG1 +
2598 ((__u16)mos7840_port->port_num)), Data);
84fe6e79 2599 dbg("ZLIP offset %x",
3f542974 2600 (__u16) (ZLP_REG1 +
880af9db 2601 ((__u16) mos7840_port->port_num)));
3f542974 2602 if (status < 0) {
84fe6e79 2603 dbg("Writing ZLP_REG%d failed status-0x%x",
3f542974
PS
2604 i + 2, status);
2605 break;
2606 } else
84fe6e79 2607 dbg("ZLP_REG%d Writing success status%d",
3f542974
PS
2608 i + 2, status);
2609 } else {
2610 Data = 0xff;
3f542974 2611 status = mos7840_set_reg_sync(serial->port[i],
880af9db
AC
2612 (__u16) (ZLP_REG1 +
2613 ((__u16)mos7840_port->port_num) - 0x1), Data);
84fe6e79 2614 dbg("ZLIP offset %x",
3f542974
PS
2615 (__u16) (ZLP_REG1 +
2616 ((__u16) mos7840_port->port_num) - 0x1));
2617 if (status < 0) {
84fe6e79 2618 dbg("Writing ZLP_REG%d failed status-0x%x",
3f542974
PS
2619 i + 1, status);
2620 break;
2621 } else
84fe6e79 2622 dbg("ZLP_REG%d Writing success status%d",
3f542974
PS
2623 i + 1, status);
2624
2625 }
0de9a702 2626 mos7840_port->control_urb = usb_alloc_urb(0, GFP_KERNEL);
3f542974 2627 mos7840_port->ctrl_buf = kmalloc(16, GFP_KERNEL);
880af9db
AC
2628 mos7840_port->dr = kmalloc(sizeof(struct usb_ctrlrequest),
2629 GFP_KERNEL);
2630 if (!mos7840_port->control_urb || !mos7840_port->ctrl_buf ||
2631 !mos7840_port->dr) {
0de9a702
ON
2632 status = -ENOMEM;
2633 goto error;
2634 }
0eafe4de
D
2635
2636 mos7840_port->has_led = false;
2637
2638 /* Initialize LED timers */
2639 if (device_type == MOSCHIP_DEVICE_ID_7810) {
2640 mos7840_port->has_led = true;
2641
2642 init_timer(&mos7840_port->led_timer1);
2643 mos7840_port->led_timer1.function = mos7840_led_off;
2644 mos7840_port->led_timer1.expires =
2645 jiffies + msecs_to_jiffies(LED_ON_MS);
2646 mos7840_port->led_timer1.data =
2647 (unsigned long)mos7840_port;
2648
2649 init_timer(&mos7840_port->led_timer2);
2650 mos7840_port->led_timer2.function =
2651 mos7840_led_flag_off;
2652 mos7840_port->led_timer2.expires =
2653 jiffies + msecs_to_jiffies(LED_OFF_MS);
2654 mos7840_port->led_timer2.data =
2655 (unsigned long)mos7840_port;
2656
2657 mos7840_port->led_flag = false;
2658
2659 /* Turn off LED */
2660 mos7840_set_led_sync(serial->port[i],
2661 MODEM_CONTROL_REGISTER, 0x0300);
2662 }
3f542974 2663 }
84fe6e79 2664 dbg ("mos7840_startup: all ports configured...........");
3f542974 2665
880af9db 2666 /* Zero Length flag enable */
3f542974 2667 Data = 0x0f;
3f542974
PS
2668 status = mos7840_set_reg_sync(serial->port[0], ZLP_REG5, Data);
2669 if (status < 0) {
84fe6e79 2670 dbg("Writing ZLP_REG5 failed status-0x%x", status);
7ced46c3 2671 goto error;
3f542974 2672 } else
84fe6e79 2673 dbg("ZLP_REG5 Writing success status%d", status);
3f542974
PS
2674
2675 /* setting configuration feature to one */
2676 usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
1e658489 2677 (__u8) 0x03, 0x00, 0x01, 0x00, NULL, 0x00, MOS_WDR_TIMEOUT);
3f542974 2678 return 0;
0de9a702
ON
2679error:
2680 for (/* nothing */; i >= 0; i--) {
2681 mos7840_port = mos7840_get_port_private(serial->port[i]);
2682
2683 kfree(mos7840_port->dr);
2684 kfree(mos7840_port->ctrl_buf);
2685 usb_free_urb(mos7840_port->control_urb);
2686 kfree(mos7840_port);
2687 serial->port[i] = NULL;
2688 }
2689 return status;
3f542974
PS
2690}
2691
2692/****************************************************************************
f9c99bb8 2693 * mos7840_disconnect
3f542974
PS
2694 * This function is called whenever the device is removed from the usb bus.
2695 ****************************************************************************/
2696
f9c99bb8 2697static void mos7840_disconnect(struct usb_serial *serial)
3f542974
PS
2698{
2699 int i;
0de9a702 2700 unsigned long flags;
3f542974 2701 struct moschip_port *mos7840_port;
3f542974
PS
2702
2703 if (!serial) {
84fe6e79 2704 dbg("%s", "Invalid Handler");
3f542974
PS
2705 return;
2706 }
2707
880af9db 2708 /* check for the ports to be closed,close the ports and disconnect */
3f542974
PS
2709
2710 /* free private structure allocated for serial port *
2711 * stop reads and writes on all ports */
2712
2713 for (i = 0; i < serial->num_ports; ++i) {
2714 mos7840_port = mos7840_get_port_private(serial->port[i]);
37768adf
TC
2715 dbg ("mos7840_port %d = %p", i, mos7840_port);
2716 if (mos7840_port) {
2717 spin_lock_irqsave(&mos7840_port->pool_lock, flags);
2718 mos7840_port->zombie = 1;
2719 spin_unlock_irqrestore(&mos7840_port->pool_lock, flags);
2720 usb_kill_urb(mos7840_port->control_urb);
f9c99bb8
AS
2721 }
2722 }
f9c99bb8
AS
2723}
2724
2725/****************************************************************************
2726 * mos7840_release
2727 * This function is called when the usb_serial structure is freed.
2728 ****************************************************************************/
2729
2730static void mos7840_release(struct usb_serial *serial)
2731{
2732 int i;
2733 struct moschip_port *mos7840_port;
f9c99bb8
AS
2734
2735 if (!serial) {
2736 dbg("%s", "Invalid Handler");
2737 return;
2738 }
2739
2740 /* check for the ports to be closed,close the ports and disconnect */
2741
2742 /* free private structure allocated for serial port *
2743 * stop reads and writes on all ports */
2744
2745 for (i = 0; i < serial->num_ports; ++i) {
2746 mos7840_port = mos7840_get_port_private(serial->port[i]);
2747 dbg("mos7840_port %d = %p", i, mos7840_port);
2748 if (mos7840_port) {
0eafe4de
D
2749 if (mos7840_port->has_led) {
2750 /* Turn off LED */
2751 mos7840_set_led_sync(mos7840_port->port,
2752 MODEM_CONTROL_REGISTER, 0x0300);
2753
2754 del_timer_sync(&mos7840_port->led_timer1);
2755 del_timer_sync(&mos7840_port->led_timer2);
2756 }
37768adf
TC
2757 kfree(mos7840_port->ctrl_buf);
2758 kfree(mos7840_port->dr);
2759 kfree(mos7840_port);
2760 }
3f542974 2761 }
3f542974
PS
2762}
2763
2764static struct usb_serial_driver moschip7840_4port_device = {
2765 .driver = {
2766 .owner = THIS_MODULE,
2767 .name = "mos7840",
2768 },
2769 .description = DRIVER_DESC,
68e24113 2770 .id_table = id_table,
3f542974 2771 .num_ports = 4,
3f542974
PS
2772 .open = mos7840_open,
2773 .close = mos7840_close,
2774 .write = mos7840_write,
2775 .write_room = mos7840_write_room,
2776 .chars_in_buffer = mos7840_chars_in_buffer,
2777 .throttle = mos7840_throttle,
2778 .unthrottle = mos7840_unthrottle,
2779 .calc_num_ports = mos7840_calc_num_ports,
2780#ifdef MCSSerialProbe
2781 .probe = mos7840_serial_probe,
2782#endif
2783 .ioctl = mos7840_ioctl,
2784 .set_termios = mos7840_set_termios,
2785 .break_ctl = mos7840_break,
2786 .tiocmget = mos7840_tiocmget,
2787 .tiocmset = mos7840_tiocmset,
0bca1b91 2788 .get_icount = mos7840_get_icount,
3f542974 2789 .attach = mos7840_startup,
f9c99bb8
AS
2790 .disconnect = mos7840_disconnect,
2791 .release = mos7840_release,
3f542974
PS
2792 .read_bulk_callback = mos7840_bulk_in_callback,
2793 .read_int_callback = mos7840_interrupt_callback,
2794};
2795
4d2a7aff
AS
2796static struct usb_serial_driver * const serial_drivers[] = {
2797 &moschip7840_4port_device, NULL
2798};
2799
68e24113 2800module_usb_serial_driver(serial_drivers, id_table);
3f542974 2801
3f542974
PS
2802MODULE_DESCRIPTION(DRIVER_DESC);
2803MODULE_LICENSE("GPL");
2804
2805module_param(debug, bool, S_IRUGO | S_IWUSR);
2806MODULE_PARM_DESC(debug, "Debug enabled or not");
This page took 1.033286 seconds and 5 git commands to generate.