blob: ffbe4eed20573e9309653b2da694e459a6e5994e [file] [log] [blame]
Paul B Schroeder3f542972006-08-31 19:41:47 -05001/*
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>
Alan Cox880af9d2008-07-22 11:16:12 +010036#include <linux/uaccess.h>
Paul B Schroeder3f542972006-08-31 19:41:47 -050037
38/*
39 * Version Information
40 */
Tony Cook37768ad2009-04-18 22:42:18 +093041#define DRIVER_VERSION "1.3.2"
Paul B Schroeder3f542972006-08-31 19:41:47 -050042#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
Mark Ferrell1e658482012-07-24 13:38:31 -050085#define MOS_WDR_TIMEOUT 5000 /* default urb timeout */
Paul B Schroeder3f542972006-08-31 19:41:47 -050086
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
Alan Cox880af9d2008-07-22 11:16:12 +0100104#define ZLP_REG1 0x3A /* Zero_Flag_Reg1 58 */
105#define ZLP_REG5 0x3E /* Zero_Flag_Reg5 62 */
Paul B Schroeder3f542972006-08-31 19:41:47 -0500106
107/* For higher baud Rates use TIOCEXBAUD */
108#define TIOCEXBAUD 0x5462
109
110/* vendor id and device id defines */
111
David Ludlow11e1abb2008-02-25 17:30:52 -0500112/* The native mos7840/7820 component */
Paul B Schroeder3f542972006-08-31 19:41:47 -0500113#define USB_VENDOR_ID_MOSCHIP 0x9710
114#define MOSCHIP_DEVICE_ID_7840 0x7840
115#define MOSCHIP_DEVICE_ID_7820 0x7820
Donald0eafe4d2012-04-19 15:00:45 +0800116#define MOSCHIP_DEVICE_ID_7810 0x7810
David Ludlow11e1abb2008-02-25 17:30:52 -0500117/* The native component can have its vendor/device id's overridden
118 * in vendor-specific implementations. Such devices can be handled
Greg Kroah-Hartman68e24112012-05-08 15:46:14 -0700119 * by making a change here, in id_table.
David Ludlow11e1abb2008-02-25 17:30:52 -0500120 */
Dave Ludlow870408c2010-09-01 12:33:30 -0400121#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
Paul B Schroeder3f542972006-08-31 19:41:47 -0500135
Russell Lang9d498be2009-07-17 19:29:20 +1000136/* This driver also supports
137 * ATEN UC2324 device using Moschip MCS7840
138 * ATEN UC2322 device using Moschip MCS7820
139 */
Tony Cooke9b8cff2009-04-18 22:42:18 +0930140#define USB_VENDOR_ID_ATENINTL 0x0557
141#define ATENINTL_DEVICE_ID_UC2324 0x2011
Russell Lang9d498be2009-07-17 19:29:20 +1000142#define ATENINTL_DEVICE_ID_UC2322 0x7820
Tony Cooke9b8cff2009-04-18 22:42:18 +0930143
David Ludlow11e1abb2008-02-25 17:30:52 -0500144/* Interrupt Routine Defines */
Paul B Schroeder3f542972006-08-31 19:41:47 -0500145
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
Alan Cox880af9d2008-07-22 11:16:12 +0100163/* Serial Port register Address */
Paul B Schroeder3f542972006-08-31 19:41:47 -0500164#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))
Donald Lee093ea2d2012-03-14 15:26:33 +0800176#define GPIO_REGISTER ((__u16)(0x07))
Paul B Schroeder3f542972006-08-31 19:41:47 -0500177
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
Donald0eafe4d2012-04-19 15:00:45 +0800186/* LED on/off milliseconds*/
187#define LED_ON_MS 500
188#define LED_OFF_MS 500
189
190static int device_type;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500191
Tony Zelenoffb9c87662012-06-05 17:58:04 +0400192static const struct usb_device_id id_table[] = {
Paul B Schroeder3f542972006-08-31 19:41:47 -0500193 {USB_DEVICE(USB_VENDOR_ID_MOSCHIP, MOSCHIP_DEVICE_ID_7840)},
194 {USB_DEVICE(USB_VENDOR_ID_MOSCHIP, MOSCHIP_DEVICE_ID_7820)},
Donald0eafe4d2012-04-19 15:00:45 +0800195 {USB_DEVICE(USB_VENDOR_ID_MOSCHIP, MOSCHIP_DEVICE_ID_7810)},
Cliff Brakeacf509a2009-12-01 09:53:43 -0500196 {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USO9ML2_2)},
Dave Ludlow870408c2010-09-01 12:33:30 -0400197 {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USO9ML2_2P)},
Cliff Brakeacf509a2009-12-01 09:53:43 -0500198 {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USO9ML2_4)},
Dave Ludlow870408c2010-09-01 12:33:30 -0400199 {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USO9ML2_4P)},
Cliff Brakeacf509a2009-12-01 09:53:43 -0500200 {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)},
David Ludlow11e1abb2008-02-25 17:30:52 -0500204 {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL4_2)},
Dave Ludlow870408c2010-09-01 12:33:30 -0400205 {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL4_2P)},
Cliff Brakeacf509a2009-12-01 09:53:43 -0500206 {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL4_4)},
Dave Ludlow870408c2010-09-01 12:33:30 -0400207 {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL4_4P)},
Blaise Gassend27f12812009-12-18 15:23:38 -0800208 {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL2_4)},
Tony Cooke9b8cff2009-04-18 22:42:18 +0930209 {USB_DEVICE(USB_VENDOR_ID_ATENINTL, ATENINTL_DEVICE_ID_UC2324)},
Russell Lang9d498be2009-07-17 19:29:20 +1000210 {USB_DEVICE(USB_VENDOR_ID_ATENINTL, ATENINTL_DEVICE_ID_UC2322)},
Paul B Schroeder3f542972006-08-31 19:41:47 -0500211 {} /* terminating entry */
212};
Greg Kroah-Hartman68e24112012-05-08 15:46:14 -0700213MODULE_DEVICE_TABLE(usb, id_table);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500214
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 */
Oliver Neukum0de9a702007-03-16 20:28:28 +0100221 struct urb *int_urb;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500222 __u8 shadowLCR; /* last LCR value received */
223 __u8 shadowMCR; /* last MCR value received */
224 char open;
Oliver Neukum0de9a702007-03-16 20:28:28 +0100225 char open_ports;
226 char zombie;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500227 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
Alan Cox880af9d2008-07-22 11:16:12 +0100233 /* Offsets */
Paul B Schroeder3f542972006-08-31 19:41:47 -0500234 __u8 SpRegOffset;
235 __u8 ControlRegOffset;
236 __u8 DcrRegOffset;
Alan Cox880af9d2008-07-22 11:16:12 +0100237 /* for processing control URBS in interrupt context */
Paul B Schroeder3f542972006-08-31 19:41:47 -0500238 struct urb *control_urb;
Oliver Neukum0de9a702007-03-16 20:28:28 +0100239 struct usb_ctrlrequest *dr;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500240 char *ctrl_buf;
241 int MsrLsr;
242
Oliver Neukum0de9a702007-03-16 20:28:28 +0100243 spinlock_t pool_lock;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500244 struct urb *write_urb_pool[NUM_URBS];
Oliver Neukum0de9a702007-03-16 20:28:28 +0100245 char busy[NUM_URBS];
Greg Kroah-Hartman50de36f2008-12-10 16:00:30 -0800246 bool read_urb_busy;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500247
Donald0eafe4d2012-04-19 15:00:45 +0800248 /* 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};
Paul B Schroeder3f542972006-08-31 19:41:47 -0500254
Rusty Russell90ab5ee2012-01-13 09:32:20 +1030255static bool debug;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500256
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;
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700268 dev_dbg(&port->dev, "mos7840_set_reg_sync offset is %x, value %x\n", reg, val);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500269
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,
Alan Cox880af9d2008-07-22 11:16:12 +0100282 __u16 *val)
Paul B Schroeder3f542972006-08-31 19:41:47 -0500283{
284 struct usb_device *dev = port->serial->dev;
285 int ret = 0;
Johan Hovold9e221a32009-12-28 23:01:55 +0100286 u8 *buf;
287
288 buf = kmalloc(VENDOR_READ_LENGTH, GFP_KERNEL);
289 if (!buf)
290 return -ENOMEM;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500291
292 ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), MCS_RDREQ,
Johan Hovold9e221a32009-12-28 23:01:55 +0100293 MCS_RD_RTYPE, 0, reg, buf, VENDOR_READ_LENGTH,
Paul B Schroeder3f542972006-08-31 19:41:47 -0500294 MOS_WDR_TIMEOUT);
Johan Hovold9e221a32009-12-28 23:01:55 +0100295 *val = buf[0];
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700296 dev_dbg(&port->dev, "%s offset is %x, return val %x\n", __func__, reg, *val);
Johan Hovold9e221a32009-12-28 23:01:55 +0100297
298 kfree(buf);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500299 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;
Alan Cox880af9d2008-07-22 11:16:12 +0100314 /* For the UART control registers, the application number need
315 to be Or'ed */
Oliver Neukum0de9a702007-03-16 20:28:28 +0100316 if (port->serial->num_ports == 4) {
Alan Cox880af9d2008-07-22 11:16:12 +0100317 val |= (((__u16) port->number -
318 (__u16) (port->serial->minor)) + 1) << 8;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500319 } else {
320 if (((__u16) port->number - (__u16) (port->serial->minor)) == 0) {
Alan Cox880af9d2008-07-22 11:16:12 +0100321 val |= (((__u16) port->number -
Paul B Schroeder3f542972006-08-31 19:41:47 -0500322 (__u16) (port->serial->minor)) + 1) << 8;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500323 } else {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700324 val |= (((__u16) port->number -
Paul B Schroeder3f542972006-08-31 19:41:47 -0500325 (__u16) (port->serial->minor)) + 2) << 8;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500326 }
327 }
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700328 dev_dbg(&port->dev, "%s application number is %x\n", __func__, val);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500329 return usb_control_msg(dev, usb_sndctrlpipe(dev, 0), MCS_WRREQ,
330 MCS_WR_RTYPE, val, reg, NULL, 0,
331 MOS_WDR_TIMEOUT);
332
333}
334
335/*
336 * mos7840_get_uart_reg
337 * To set the Control register by calling usb_fill_control_urb function
338 * by passing usb_rcvctrlpipe function as parameter.
339 */
340static int mos7840_get_uart_reg(struct usb_serial_port *port, __u16 reg,
Alan Cox880af9d2008-07-22 11:16:12 +0100341 __u16 *val)
Paul B Schroeder3f542972006-08-31 19:41:47 -0500342{
343 struct usb_device *dev = port->serial->dev;
344 int ret = 0;
345 __u16 Wval;
Johan Hovold9e221a32009-12-28 23:01:55 +0100346 u8 *buf;
347
348 buf = kmalloc(VENDOR_READ_LENGTH, GFP_KERNEL);
349 if (!buf)
350 return -ENOMEM;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500351
Alan Cox880af9d2008-07-22 11:16:12 +0100352 /* Wval is same as application number */
Oliver Neukum0de9a702007-03-16 20:28:28 +0100353 if (port->serial->num_ports == 4) {
Paul B Schroeder3f542972006-08-31 19:41:47 -0500354 Wval =
355 (((__u16) port->number - (__u16) (port->serial->minor)) +
356 1) << 8;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500357 } else {
358 if (((__u16) port->number - (__u16) (port->serial->minor)) == 0) {
Alan Cox880af9d2008-07-22 11:16:12 +0100359 Wval = (((__u16) port->number -
Paul B Schroeder3f542972006-08-31 19:41:47 -0500360 (__u16) (port->serial->minor)) + 1) << 8;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500361 } else {
Alan Cox880af9d2008-07-22 11:16:12 +0100362 Wval = (((__u16) port->number -
Paul B Schroeder3f542972006-08-31 19:41:47 -0500363 (__u16) (port->serial->minor)) + 2) << 8;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500364 }
365 }
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700366 dev_dbg(&port->dev, "%s application number is %x\n", __func__, Wval);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500367 ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), MCS_RDREQ,
Johan Hovold9e221a32009-12-28 23:01:55 +0100368 MCS_RD_RTYPE, Wval, reg, buf, VENDOR_READ_LENGTH,
Paul B Schroeder3f542972006-08-31 19:41:47 -0500369 MOS_WDR_TIMEOUT);
Johan Hovold9e221a32009-12-28 23:01:55 +0100370 *val = buf[0];
371
372 kfree(buf);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500373 return ret;
374}
375
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700376static void mos7840_dump_serial_port(struct usb_serial_port *port,
377 struct moschip_port *mos7840_port)
Paul B Schroeder3f542972006-08-31 19:41:47 -0500378{
379
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700380 dev_dbg(&port->dev, "SpRegOffset is %2x\n", mos7840_port->SpRegOffset);
381 dev_dbg(&port->dev, "ControlRegOffset is %2x\n", mos7840_port->ControlRegOffset);
382 dev_dbg(&port->dev, "DCRRegOffset is %2x\n", mos7840_port->DcrRegOffset);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500383
384}
385
386/************************************************************************/
387/************************************************************************/
388/* I N T E R F A C E F U N C T I O N S */
389/* I N T E R F A C E F U N C T I O N S */
390/************************************************************************/
391/************************************************************************/
392
393static inline void mos7840_set_port_private(struct usb_serial_port *port,
394 struct moschip_port *data)
395{
396 usb_set_serial_port_data(port, (void *)data);
397}
398
399static inline struct moschip_port *mos7840_get_port_private(struct
400 usb_serial_port
401 *port)
402{
403 return (struct moschip_port *)usb_get_serial_port_data(port);
404}
405
Oliver Neukum0de9a702007-03-16 20:28:28 +0100406static void mos7840_handle_new_msr(struct moschip_port *port, __u8 new_msr)
Paul B Schroeder3f542972006-08-31 19:41:47 -0500407{
408 struct moschip_port *mos7840_port;
409 struct async_icount *icount;
410 mos7840_port = port;
411 icount = &mos7840_port->icount;
412 if (new_msr &
413 (MOS_MSR_DELTA_CTS | MOS_MSR_DELTA_DSR | MOS_MSR_DELTA_RI |
414 MOS_MSR_DELTA_CD)) {
415 icount = &mos7840_port->icount;
416
417 /* update input line counters */
418 if (new_msr & MOS_MSR_DELTA_CTS) {
419 icount->cts++;
Oliver Neukum0de9a702007-03-16 20:28:28 +0100420 smp_wmb();
Paul B Schroeder3f542972006-08-31 19:41:47 -0500421 }
422 if (new_msr & MOS_MSR_DELTA_DSR) {
423 icount->dsr++;
Oliver Neukum0de9a702007-03-16 20:28:28 +0100424 smp_wmb();
Paul B Schroeder3f542972006-08-31 19:41:47 -0500425 }
426 if (new_msr & MOS_MSR_DELTA_CD) {
427 icount->dcd++;
Oliver Neukum0de9a702007-03-16 20:28:28 +0100428 smp_wmb();
Paul B Schroeder3f542972006-08-31 19:41:47 -0500429 }
430 if (new_msr & MOS_MSR_DELTA_RI) {
431 icount->rng++;
Oliver Neukum0de9a702007-03-16 20:28:28 +0100432 smp_wmb();
Paul B Schroeder3f542972006-08-31 19:41:47 -0500433 }
434 }
Paul B Schroeder3f542972006-08-31 19:41:47 -0500435}
436
Oliver Neukum0de9a702007-03-16 20:28:28 +0100437static void mos7840_handle_new_lsr(struct moschip_port *port, __u8 new_lsr)
Paul B Schroeder3f542972006-08-31 19:41:47 -0500438{
439 struct async_icount *icount;
440
Paul B Schroeder3f542972006-08-31 19:41:47 -0500441 if (new_lsr & SERIAL_LSR_BI) {
Alan Cox880af9d2008-07-22 11:16:12 +0100442 /*
443 * Parity and Framing errors only count if they
444 * occur exclusive of a break being
445 * received.
446 */
Paul B Schroeder3f542972006-08-31 19:41:47 -0500447 new_lsr &= (__u8) (SERIAL_LSR_OE | SERIAL_LSR_BI);
448 }
449
450 /* update input line counters */
451 icount = &port->icount;
452 if (new_lsr & SERIAL_LSR_BI) {
453 icount->brk++;
Oliver Neukum0de9a702007-03-16 20:28:28 +0100454 smp_wmb();
Paul B Schroeder3f542972006-08-31 19:41:47 -0500455 }
456 if (new_lsr & SERIAL_LSR_OE) {
457 icount->overrun++;
Oliver Neukum0de9a702007-03-16 20:28:28 +0100458 smp_wmb();
Paul B Schroeder3f542972006-08-31 19:41:47 -0500459 }
460 if (new_lsr & SERIAL_LSR_PE) {
461 icount->parity++;
Oliver Neukum0de9a702007-03-16 20:28:28 +0100462 smp_wmb();
Paul B Schroeder3f542972006-08-31 19:41:47 -0500463 }
464 if (new_lsr & SERIAL_LSR_FE) {
465 icount->frame++;
Oliver Neukum0de9a702007-03-16 20:28:28 +0100466 smp_wmb();
Paul B Schroeder3f542972006-08-31 19:41:47 -0500467 }
Paul B Schroeder3f542972006-08-31 19:41:47 -0500468}
469
470/************************************************************************/
471/************************************************************************/
472/* U S B C A L L B A C K F U N C T I O N S */
473/* U S B C A L L B A C K F U N C T I O N S */
474/************************************************************************/
475/************************************************************************/
476
David Howells7d12e782006-10-05 14:55:46 +0100477static void mos7840_control_callback(struct urb *urb)
Paul B Schroeder3f542972006-08-31 19:41:47 -0500478{
479 unsigned char *data;
480 struct moschip_port *mos7840_port;
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700481 struct device *dev = &urb->dev->dev;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500482 __u8 regval = 0x0;
Oliver Neukum0de9a702007-03-16 20:28:28 +0100483 int result = 0;
Greg Kroah-Hartman0643c722007-06-15 15:44:13 -0700484 int status = urb->status;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500485
Ming Leicdc97792008-02-24 18:41:47 +0800486 mos7840_port = urb->context;
Oliver Neukum0de9a702007-03-16 20:28:28 +0100487
Greg Kroah-Hartman0643c722007-06-15 15:44:13 -0700488 switch (status) {
Paul B Schroeder3f542972006-08-31 19:41:47 -0500489 case 0:
490 /* success */
491 break;
492 case -ECONNRESET:
493 case -ENOENT:
494 case -ESHUTDOWN:
495 /* this urb is terminated, clean up */
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700496 dev_dbg(dev, "%s - urb shutting down with status: %d\n", __func__, status);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500497 return;
498 default:
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700499 dev_dbg(dev, "%s - nonzero urb status received: %d\n", __func__, status);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500500 goto exit;
501 }
502
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700503 dev_dbg(dev, "%s urb buffer size is %d\n", __func__, urb->actual_length);
504 dev_dbg(dev, "%s mos7840_port->MsrLsr is %d port %d\n", __func__,
505 mos7840_port->MsrLsr, mos7840_port->port_num);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500506 data = urb->transfer_buffer;
507 regval = (__u8) data[0];
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700508 dev_dbg(dev, "%s data is %x\n", __func__, regval);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500509 if (mos7840_port->MsrLsr == 0)
510 mos7840_handle_new_msr(mos7840_port, regval);
511 else if (mos7840_port->MsrLsr == 1)
512 mos7840_handle_new_lsr(mos7840_port, regval);
513
Oliver Neukum0de9a702007-03-16 20:28:28 +0100514exit:
515 spin_lock(&mos7840_port->pool_lock);
516 if (!mos7840_port->zombie)
517 result = usb_submit_urb(mos7840_port->int_urb, GFP_ATOMIC);
518 spin_unlock(&mos7840_port->pool_lock);
519 if (result) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700520 dev_err(dev, "%s - Error %d submitting interrupt urb\n",
Harvey Harrison441b62c2008-03-03 16:08:34 -0800521 __func__, result);
Oliver Neukum0de9a702007-03-16 20:28:28 +0100522 }
Paul B Schroeder3f542972006-08-31 19:41:47 -0500523}
524
525static int mos7840_get_reg(struct moschip_port *mcs, __u16 Wval, __u16 reg,
Alan Cox880af9d2008-07-22 11:16:12 +0100526 __u16 *val)
Paul B Schroeder3f542972006-08-31 19:41:47 -0500527{
528 struct usb_device *dev = mcs->port->serial->dev;
Oliver Neukum0de9a702007-03-16 20:28:28 +0100529 struct usb_ctrlrequest *dr = mcs->dr;
530 unsigned char *buffer = mcs->ctrl_buf;
531 int ret;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500532
Paul B Schroeder3f542972006-08-31 19:41:47 -0500533 dr->bRequestType = MCS_RD_RTYPE;
534 dr->bRequest = MCS_RDREQ;
Alan Cox880af9d2008-07-22 11:16:12 +0100535 dr->wValue = cpu_to_le16(Wval); /* 0 */
Paul B Schroeder3f542972006-08-31 19:41:47 -0500536 dr->wIndex = cpu_to_le16(reg);
537 dr->wLength = cpu_to_le16(2);
538
539 usb_fill_control_urb(mcs->control_urb, dev, usb_rcvctrlpipe(dev, 0),
540 (unsigned char *)dr, buffer, 2,
541 mos7840_control_callback, mcs);
542 mcs->control_urb->transfer_buffer_length = 2;
543 ret = usb_submit_urb(mcs->control_urb, GFP_ATOMIC);
544 return ret;
545}
546
Donald0eafe4d2012-04-19 15:00:45 +0800547static void mos7840_set_led_callback(struct urb *urb)
548{
549 switch (urb->status) {
550 case 0:
551 /* Success */
552 break;
553 case -ECONNRESET:
554 case -ENOENT:
555 case -ESHUTDOWN:
556 /* This urb is terminated, clean up */
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700557 dev_dbg(&urb->dev->dev, "%s - urb shutting down with status: %d",
558 __func__, urb->status);
Donald0eafe4d2012-04-19 15:00:45 +0800559 break;
560 default:
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700561 dev_dbg(&urb->dev->dev, "%s - nonzero urb status received: %d",
562 __func__, urb->status);
Donald0eafe4d2012-04-19 15:00:45 +0800563 }
564}
565
566static void mos7840_set_led_async(struct moschip_port *mcs, __u16 wval,
567 __u16 reg)
568{
569 struct usb_device *dev = mcs->port->serial->dev;
570 struct usb_ctrlrequest *dr = mcs->dr;
571
572 dr->bRequestType = MCS_WR_RTYPE;
573 dr->bRequest = MCS_WRREQ;
574 dr->wValue = cpu_to_le16(wval);
575 dr->wIndex = cpu_to_le16(reg);
576 dr->wLength = cpu_to_le16(0);
577
578 usb_fill_control_urb(mcs->control_urb, dev, usb_sndctrlpipe(dev, 0),
579 (unsigned char *)dr, NULL, 0, mos7840_set_led_callback, NULL);
580
581 usb_submit_urb(mcs->control_urb, GFP_ATOMIC);
582}
583
584static void mos7840_set_led_sync(struct usb_serial_port *port, __u16 reg,
585 __u16 val)
586{
587 struct usb_device *dev = port->serial->dev;
588
589 usb_control_msg(dev, usb_sndctrlpipe(dev, 0), MCS_WRREQ, MCS_WR_RTYPE,
590 val, reg, NULL, 0, MOS_WDR_TIMEOUT);
591}
592
593static void mos7840_led_off(unsigned long arg)
594{
595 struct moschip_port *mcs = (struct moschip_port *) arg;
596
597 /* Turn off LED */
598 mos7840_set_led_async(mcs, 0x0300, MODEM_CONTROL_REGISTER);
599 mod_timer(&mcs->led_timer2,
600 jiffies + msecs_to_jiffies(LED_OFF_MS));
601}
602
603static void mos7840_led_flag_off(unsigned long arg)
604{
605 struct moschip_port *mcs = (struct moschip_port *) arg;
606
607 mcs->led_flag = false;
608}
609
Paul B Schroeder3f542972006-08-31 19:41:47 -0500610/*****************************************************************************
611 * mos7840_interrupt_callback
612 * this is the callback function for when we have received data on the
613 * interrupt endpoint.
614 *****************************************************************************/
615
David Howells7d12e782006-10-05 14:55:46 +0100616static void mos7840_interrupt_callback(struct urb *urb)
Paul B Schroeder3f542972006-08-31 19:41:47 -0500617{
618 int result;
619 int length;
620 struct moschip_port *mos7840_port;
621 struct usb_serial *serial;
622 __u16 Data;
623 unsigned char *data;
624 __u8 sp[5], st;
Oliver Neukum0de9a702007-03-16 20:28:28 +0100625 int i, rv = 0;
626 __u16 wval, wreg = 0;
Greg Kroah-Hartman0643c722007-06-15 15:44:13 -0700627 int status = urb->status;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500628
Greg Kroah-Hartman0643c722007-06-15 15:44:13 -0700629 switch (status) {
Paul B Schroeder3f542972006-08-31 19:41:47 -0500630 case 0:
631 /* success */
632 break;
633 case -ECONNRESET:
634 case -ENOENT:
635 case -ESHUTDOWN:
636 /* this urb is terminated, clean up */
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700637 dev_dbg(&urb->dev->dev, "%s - urb shutting down with status: %d\n",
638 __func__, status);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500639 return;
640 default:
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700641 dev_dbg(&urb->dev->dev, "%s - nonzero urb status received: %d\n",
642 __func__, status);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500643 goto exit;
644 }
645
646 length = urb->actual_length;
647 data = urb->transfer_buffer;
648
Ming Leicdc97792008-02-24 18:41:47 +0800649 serial = urb->context;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500650
651 /* Moschip get 5 bytes
652 * Byte 1 IIR Port 1 (port.number is 0)
653 * Byte 2 IIR Port 2 (port.number is 1)
654 * Byte 3 IIR Port 3 (port.number is 2)
655 * Byte 4 IIR Port 4 (port.number is 3)
656 * Byte 5 FIFO status for both */
657
658 if (length && length > 5) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700659 dev_dbg(&urb->dev->dev, "%s", "Wrong data !!!\n");
Paul B Schroeder3f542972006-08-31 19:41:47 -0500660 return;
661 }
662
663 sp[0] = (__u8) data[0];
664 sp[1] = (__u8) data[1];
665 sp[2] = (__u8) data[2];
666 sp[3] = (__u8) data[3];
667 st = (__u8) data[4];
668
669 for (i = 0; i < serial->num_ports; i++) {
670 mos7840_port = mos7840_get_port_private(serial->port[i]);
671 wval =
672 (((__u16) serial->port[i]->number -
673 (__u16) (serial->minor)) + 1) << 8;
674 if (mos7840_port->open) {
675 if (sp[i] & 0x01) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700676 dev_dbg(&urb->dev->dev, "SP%d No Interrupt !!!\n", i);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500677 } else {
678 switch (sp[i] & 0x0f) {
679 case SERIAL_IIR_RLS:
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700680 dev_dbg(&urb->dev->dev, "Serial Port %d: Receiver status error or \n", i);
681 dev_dbg(&urb->dev->dev, "address bit detected in 9-bit mode\n");
Paul B Schroeder3f542972006-08-31 19:41:47 -0500682 mos7840_port->MsrLsr = 1;
Oliver Neukum0de9a702007-03-16 20:28:28 +0100683 wreg = LINE_STATUS_REGISTER;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500684 break;
685 case SERIAL_IIR_MS:
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700686 dev_dbg(&urb->dev->dev, "Serial Port %d: Modem status change\n", i);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500687 mos7840_port->MsrLsr = 0;
Oliver Neukum0de9a702007-03-16 20:28:28 +0100688 wreg = MODEM_STATUS_REGISTER;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500689 break;
690 }
Oliver Neukum0de9a702007-03-16 20:28:28 +0100691 spin_lock(&mos7840_port->pool_lock);
692 if (!mos7840_port->zombie) {
693 rv = mos7840_get_reg(mos7840_port, wval, wreg, &Data);
694 } else {
695 spin_unlock(&mos7840_port->pool_lock);
696 return;
697 }
698 spin_unlock(&mos7840_port->pool_lock);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500699 }
700 }
701 }
Alan Cox880af9d2008-07-22 11:16:12 +0100702 if (!(rv < 0))
703 /* the completion handler for the control urb will resubmit */
Oliver Neukum0de9a702007-03-16 20:28:28 +0100704 return;
705exit:
Paul B Schroeder3f542972006-08-31 19:41:47 -0500706 result = usb_submit_urb(urb, GFP_ATOMIC);
707 if (result) {
708 dev_err(&urb->dev->dev,
709 "%s - Error %d submitting interrupt urb\n",
Harvey Harrison441b62c2008-03-03 16:08:34 -0800710 __func__, result);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500711 }
Paul B Schroeder3f542972006-08-31 19:41:47 -0500712}
713
714static int mos7840_port_paranoia_check(struct usb_serial_port *port,
715 const char *function)
716{
717 if (!port) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700718 pr_debug("%s - port == NULL\n", function);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500719 return -1;
720 }
721 if (!port->serial) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700722 pr_debug("%s - port->serial == NULL\n", function);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500723 return -1;
724 }
725
726 return 0;
727}
728
729/* Inline functions to check the sanity of a pointer that is passed to us */
730static int mos7840_serial_paranoia_check(struct usb_serial *serial,
731 const char *function)
732{
733 if (!serial) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700734 pr_debug("%s - serial == NULL\n", function);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500735 return -1;
736 }
737 if (!serial->type) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700738 pr_debug("%s - serial->type == NULL!\n", function);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500739 return -1;
740 }
741
742 return 0;
743}
744
745static struct usb_serial *mos7840_get_usb_serial(struct usb_serial_port *port,
746 const char *function)
747{
748 /* if no port was specified, or it fails a paranoia check */
749 if (!port ||
750 mos7840_port_paranoia_check(port, function) ||
751 mos7840_serial_paranoia_check(port->serial, function)) {
Alan Cox880af9d2008-07-22 11:16:12 +0100752 /* then say that we don't have a valid usb_serial thing,
753 * which will end up genrating -ENODEV return values */
Paul B Schroeder3f542972006-08-31 19:41:47 -0500754 return NULL;
755 }
756
757 return port->serial;
758}
759
760/*****************************************************************************
761 * mos7840_bulk_in_callback
762 * this is the callback function for when we have received data on the
763 * bulk in endpoint.
764 *****************************************************************************/
765
David Howells7d12e782006-10-05 14:55:46 +0100766static void mos7840_bulk_in_callback(struct urb *urb)
Paul B Schroeder3f542972006-08-31 19:41:47 -0500767{
Greg Kroah-Hartman0643c722007-06-15 15:44:13 -0700768 int retval;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500769 unsigned char *data;
770 struct usb_serial *serial;
771 struct usb_serial_port *port;
772 struct moschip_port *mos7840_port;
773 struct tty_struct *tty;
Greg Kroah-Hartman0643c722007-06-15 15:44:13 -0700774 int status = urb->status;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500775
Ming Leicdc97792008-02-24 18:41:47 +0800776 mos7840_port = urb->context;
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700777 if (!mos7840_port)
Greg Kroah-Hartman50de36f2008-12-10 16:00:30 -0800778 return;
Greg Kroah-Hartman50de36f2008-12-10 16:00:30 -0800779
780 if (status) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700781 dev_dbg(&urb->dev->dev, "nonzero read bulk status received: %d\n", status);
Greg Kroah-Hartman50de36f2008-12-10 16:00:30 -0800782 mos7840_port->read_urb_busy = false;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500783 return;
784 }
785
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700786 port = mos7840_port->port;
Harvey Harrison441b62c2008-03-03 16:08:34 -0800787 if (mos7840_port_paranoia_check(port, __func__)) {
Greg Kroah-Hartman50de36f2008-12-10 16:00:30 -0800788 mos7840_port->read_urb_busy = false;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500789 return;
790 }
791
Harvey Harrison441b62c2008-03-03 16:08:34 -0800792 serial = mos7840_get_usb_serial(port, __func__);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500793 if (!serial) {
Greg Kroah-Hartman50de36f2008-12-10 16:00:30 -0800794 mos7840_port->read_urb_busy = false;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500795 return;
796 }
797
Paul B Schroeder3f542972006-08-31 19:41:47 -0500798 data = urb->transfer_buffer;
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700799 usb_serial_debug_data(debug, &port->dev, __func__, urb->actual_length, data);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500800
Paul B Schroeder3f542972006-08-31 19:41:47 -0500801 if (urb->actual_length) {
Alan Cox4a90f092008-10-13 10:39:46 +0100802 tty = tty_port_tty_get(&mos7840_port->port->port);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500803 if (tty) {
Paul B Schroeder3f542972006-08-31 19:41:47 -0500804 tty_insert_flip_string(tty, data, urb->actual_length);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500805 tty_flip_buffer_push(tty);
Alan Cox4a90f092008-10-13 10:39:46 +0100806 tty_kref_put(tty);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500807 }
808 mos7840_port->icount.rx += urb->actual_length;
Oliver Neukum0de9a702007-03-16 20:28:28 +0100809 smp_wmb();
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700810 dev_dbg(&port->dev, "mos7840_port->icount.rx is %d:\n", mos7840_port->icount.rx);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500811 }
812
813 if (!mos7840_port->read_urb) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700814 dev_dbg(&port->dev, "%s", "URB KILLED !!!\n");
Greg Kroah-Hartman50de36f2008-12-10 16:00:30 -0800815 mos7840_port->read_urb_busy = false;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500816 return;
817 }
818
Donald0eafe4d2012-04-19 15:00:45 +0800819 /* Turn on LED */
820 if (mos7840_port->has_led && !mos7840_port->led_flag) {
821 mos7840_port->led_flag = true;
822 mos7840_set_led_async(mos7840_port, 0x0301,
823 MODEM_CONTROL_REGISTER);
824 mod_timer(&mos7840_port->led_timer1,
825 jiffies + msecs_to_jiffies(LED_ON_MS));
826 }
Paul B Schroeder3f542972006-08-31 19:41:47 -0500827
Greg Kroah-Hartman50de36f2008-12-10 16:00:30 -0800828 mos7840_port->read_urb_busy = true;
Greg Kroah-Hartman0643c722007-06-15 15:44:13 -0700829 retval = usb_submit_urb(mos7840_port->read_urb, GFP_ATOMIC);
Oliver Neukum0de9a702007-03-16 20:28:28 +0100830
Greg Kroah-Hartman0643c722007-06-15 15:44:13 -0700831 if (retval) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700832 dev_dbg(&port->dev, "usb_submit_urb(read bulk) failed, retval = %d\n", retval);
Greg Kroah-Hartman50de36f2008-12-10 16:00:30 -0800833 mos7840_port->read_urb_busy = false;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500834 }
835}
836
837/*****************************************************************************
838 * mos7840_bulk_out_data_callback
Alan Cox880af9d2008-07-22 11:16:12 +0100839 * this is the callback function for when we have finished sending
840 * serial data on the bulk out endpoint.
Paul B Schroeder3f542972006-08-31 19:41:47 -0500841 *****************************************************************************/
842
David Howells7d12e782006-10-05 14:55:46 +0100843static void mos7840_bulk_out_data_callback(struct urb *urb)
Paul B Schroeder3f542972006-08-31 19:41:47 -0500844{
845 struct moschip_port *mos7840_port;
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700846 struct usb_serial_port *port;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500847 struct tty_struct *tty;
Greg Kroah-Hartman0643c722007-06-15 15:44:13 -0700848 int status = urb->status;
Oliver Neukum0de9a702007-03-16 20:28:28 +0100849 int i;
850
Ming Leicdc97792008-02-24 18:41:47 +0800851 mos7840_port = urb->context;
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700852 port = mos7840_port->port;
Oliver Neukum0de9a702007-03-16 20:28:28 +0100853 spin_lock(&mos7840_port->pool_lock);
854 for (i = 0; i < NUM_URBS; i++) {
855 if (urb == mos7840_port->write_urb_pool[i]) {
856 mos7840_port->busy[i] = 0;
857 break;
858 }
859 }
860 spin_unlock(&mos7840_port->pool_lock);
861
Greg Kroah-Hartman0643c722007-06-15 15:44:13 -0700862 if (status) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700863 dev_dbg(&port->dev, "nonzero write bulk status received:%d\n", status);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500864 return;
865 }
866
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700867 if (mos7840_port_paranoia_check(port, __func__))
Paul B Schroeder3f542972006-08-31 19:41:47 -0500868 return;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500869
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700870 tty = tty_port_tty_get(&port->port);
Jiri Slabyb963a842007-02-10 01:44:55 -0800871 if (tty && mos7840_port->open)
872 tty_wakeup(tty);
Alan Cox4a90f092008-10-13 10:39:46 +0100873 tty_kref_put(tty);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500874
875}
876
877/************************************************************************/
878/* 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 */
879/************************************************************************/
880#ifdef MCSSerialProbe
881static int mos7840_serial_probe(struct usb_serial *serial,
882 const struct usb_device_id *id)
883{
884
885 /*need to implement the mode_reg reading and updating\
886 structures usb_serial_ device_type\
887 (i.e num_ports, num_bulkin,bulkout etc) */
888 /* Also we can update the changes attach */
889 return 1;
890}
891#endif
892
893/*****************************************************************************
894 * mos7840_open
895 * this function is called by the tty driver when a port is opened
896 * If successful, we return 0
897 * Otherwise we return a negative error number.
898 *****************************************************************************/
899
Alan Coxa509a7e2009-09-19 13:13:26 -0700900static int mos7840_open(struct tty_struct *tty, struct usb_serial_port *port)
Paul B Schroeder3f542972006-08-31 19:41:47 -0500901{
902 int response;
903 int j;
904 struct usb_serial *serial;
905 struct urb *urb;
906 __u16 Data;
907 int status;
908 struct moschip_port *mos7840_port;
Oliver Neukum0de9a702007-03-16 20:28:28 +0100909 struct moschip_port *port0;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500910
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700911 if (mos7840_port_paranoia_check(port, __func__))
Paul B Schroeder3f542972006-08-31 19:41:47 -0500912 return -ENODEV;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500913
Paul B Schroeder3f542972006-08-31 19:41:47 -0500914 serial = port->serial;
915
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700916 if (mos7840_serial_paranoia_check(serial, __func__))
Paul B Schroeder3f542972006-08-31 19:41:47 -0500917 return -ENODEV;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500918
919 mos7840_port = mos7840_get_port_private(port);
Oliver Neukum0de9a702007-03-16 20:28:28 +0100920 port0 = mos7840_get_port_private(serial->port[0]);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500921
Oliver Neukum0de9a702007-03-16 20:28:28 +0100922 if (mos7840_port == NULL || port0 == NULL)
Paul B Schroeder3f542972006-08-31 19:41:47 -0500923 return -ENODEV;
924
925 usb_clear_halt(serial->dev, port->write_urb->pipe);
926 usb_clear_halt(serial->dev, port->read_urb->pipe);
Oliver Neukum0de9a702007-03-16 20:28:28 +0100927 port0->open_ports++;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500928
929 /* Initialising the write urb pool */
930 for (j = 0; j < NUM_URBS; ++j) {
Oliver Neukum0de9a702007-03-16 20:28:28 +0100931 urb = usb_alloc_urb(0, GFP_KERNEL);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500932 mos7840_port->write_urb_pool[j] = urb;
933
934 if (urb == NULL) {
Greg Kroah-Hartman194343d2008-08-20 16:56:34 -0700935 dev_err(&port->dev, "No more urbs???\n");
Paul B Schroeder3f542972006-08-31 19:41:47 -0500936 continue;
937 }
938
Alan Cox880af9d2008-07-22 11:16:12 +0100939 urb->transfer_buffer = kmalloc(URB_TRANSFER_BUFFER_SIZE,
940 GFP_KERNEL);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500941 if (!urb->transfer_buffer) {
Oliver Neukum0de9a702007-03-16 20:28:28 +0100942 usb_free_urb(urb);
943 mos7840_port->write_urb_pool[j] = NULL;
Greg Kroah-Hartman194343d2008-08-20 16:56:34 -0700944 dev_err(&port->dev,
945 "%s-out of memory for urb buffers.\n",
946 __func__);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500947 continue;
948 }
949 }
950
951/*****************************************************************************
952 * Initialize MCS7840 -- Write Init values to corresponding Registers
953 *
954 * Register Index
955 * 1 : IER
956 * 2 : FCR
957 * 3 : LCR
958 * 4 : MCR
959 *
960 * 0x08 : SP1/2 Control Reg
961 *****************************************************************************/
962
Alan Cox880af9d2008-07-22 11:16:12 +0100963 /* NEED to check the following Block */
Paul B Schroeder3f542972006-08-31 19:41:47 -0500964
Paul B Schroeder3f542972006-08-31 19:41:47 -0500965 Data = 0x0;
966 status = mos7840_get_reg_sync(port, mos7840_port->SpRegOffset, &Data);
967 if (status < 0) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700968 dev_dbg(&port->dev, "Reading Spreg failed\n");
Paul B Schroeder3f542972006-08-31 19:41:47 -0500969 return -1;
970 }
971 Data |= 0x80;
972 status = mos7840_set_reg_sync(port, mos7840_port->SpRegOffset, Data);
973 if (status < 0) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700974 dev_dbg(&port->dev, "writing Spreg failed\n");
Paul B Schroeder3f542972006-08-31 19:41:47 -0500975 return -1;
976 }
977
978 Data &= ~0x80;
979 status = mos7840_set_reg_sync(port, mos7840_port->SpRegOffset, Data);
980 if (status < 0) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700981 dev_dbg(&port->dev, "writing Spreg failed\n");
Paul B Schroeder3f542972006-08-31 19:41:47 -0500982 return -1;
983 }
Alan Cox880af9d2008-07-22 11:16:12 +0100984 /* End of block to be checked */
Paul B Schroeder3f542972006-08-31 19:41:47 -0500985
Paul B Schroeder3f542972006-08-31 19:41:47 -0500986 Data = 0x0;
Alan Cox880af9d2008-07-22 11:16:12 +0100987 status = mos7840_get_reg_sync(port, mos7840_port->ControlRegOffset,
988 &Data);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500989 if (status < 0) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700990 dev_dbg(&port->dev, "Reading Controlreg failed\n");
Paul B Schroeder3f542972006-08-31 19:41:47 -0500991 return -1;
992 }
Alan Cox880af9d2008-07-22 11:16:12 +0100993 Data |= 0x08; /* Driver done bit */
994 Data |= 0x20; /* rx_disable */
995 status = mos7840_set_reg_sync(port,
996 mos7840_port->ControlRegOffset, Data);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500997 if (status < 0) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700998 dev_dbg(&port->dev, "writing Controlreg failed\n");
Paul B Schroeder3f542972006-08-31 19:41:47 -0500999 return -1;
1000 }
Alan Cox880af9d2008-07-22 11:16:12 +01001001 /* do register settings here */
1002 /* Set all regs to the device default values. */
1003 /***********************************
1004 * First Disable all interrupts.
1005 ***********************************/
Paul B Schroeder3f542972006-08-31 19:41:47 -05001006 Data = 0x00;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001007 status = mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data);
1008 if (status < 0) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001009 dev_dbg(&port->dev, "disabling interrupts failed\n");
Paul B Schroeder3f542972006-08-31 19:41:47 -05001010 return -1;
1011 }
Alan Cox880af9d2008-07-22 11:16:12 +01001012 /* Set FIFO_CONTROL_REGISTER to the default value */
Paul B Schroeder3f542972006-08-31 19:41:47 -05001013 Data = 0x00;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001014 status = mos7840_set_uart_reg(port, FIFO_CONTROL_REGISTER, Data);
1015 if (status < 0) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001016 dev_dbg(&port->dev, "Writing FIFO_CONTROL_REGISTER failed\n");
Paul B Schroeder3f542972006-08-31 19:41:47 -05001017 return -1;
1018 }
1019
1020 Data = 0xcf;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001021 status = mos7840_set_uart_reg(port, FIFO_CONTROL_REGISTER, Data);
1022 if (status < 0) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001023 dev_dbg(&port->dev, "Writing FIFO_CONTROL_REGISTER failed\n");
Paul B Schroeder3f542972006-08-31 19:41:47 -05001024 return -1;
1025 }
1026
1027 Data = 0x03;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001028 status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
1029 mos7840_port->shadowLCR = Data;
1030
1031 Data = 0x0b;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001032 status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
1033 mos7840_port->shadowMCR = Data;
1034
1035 Data = 0x00;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001036 status = mos7840_get_uart_reg(port, LINE_CONTROL_REGISTER, &Data);
1037 mos7840_port->shadowLCR = Data;
1038
Alan Cox880af9d2008-07-22 11:16:12 +01001039 Data |= SERIAL_LCR_DLAB; /* data latch enable in LCR 0x80 */
Paul B Schroeder3f542972006-08-31 19:41:47 -05001040 status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
1041
1042 Data = 0x0c;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001043 status = mos7840_set_uart_reg(port, DIVISOR_LATCH_LSB, Data);
1044
1045 Data = 0x0;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001046 status = mos7840_set_uart_reg(port, DIVISOR_LATCH_MSB, Data);
1047
1048 Data = 0x00;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001049 status = mos7840_get_uart_reg(port, LINE_CONTROL_REGISTER, &Data);
1050
1051 Data = Data & ~SERIAL_LCR_DLAB;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001052 status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
1053 mos7840_port->shadowLCR = Data;
1054
Alan Cox880af9d2008-07-22 11:16:12 +01001055 /* clearing Bulkin and Bulkout Fifo */
Paul B Schroeder3f542972006-08-31 19:41:47 -05001056 Data = 0x0;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001057 status = mos7840_get_reg_sync(port, mos7840_port->SpRegOffset, &Data);
1058
1059 Data = Data | 0x0c;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001060 status = mos7840_set_reg_sync(port, mos7840_port->SpRegOffset, Data);
1061
1062 Data = Data & ~0x0c;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001063 status = mos7840_set_reg_sync(port, mos7840_port->SpRegOffset, Data);
Alan Cox880af9d2008-07-22 11:16:12 +01001064 /* Finally enable all interrupts */
Paul B Schroeder3f542972006-08-31 19:41:47 -05001065 Data = 0x0c;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001066 status = mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data);
1067
Alan Cox880af9d2008-07-22 11:16:12 +01001068 /* clearing rx_disable */
Paul B Schroeder3f542972006-08-31 19:41:47 -05001069 Data = 0x0;
Alan Cox880af9d2008-07-22 11:16:12 +01001070 status = mos7840_get_reg_sync(port, mos7840_port->ControlRegOffset,
1071 &Data);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001072 Data = Data & ~0x20;
Alan Cox880af9d2008-07-22 11:16:12 +01001073 status = mos7840_set_reg_sync(port, mos7840_port->ControlRegOffset,
1074 Data);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001075
Alan Cox880af9d2008-07-22 11:16:12 +01001076 /* rx_negate */
Paul B Schroeder3f542972006-08-31 19:41:47 -05001077 Data = 0x0;
Alan Cox880af9d2008-07-22 11:16:12 +01001078 status = mos7840_get_reg_sync(port, mos7840_port->ControlRegOffset,
1079 &Data);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001080 Data = Data | 0x10;
Alan Cox880af9d2008-07-22 11:16:12 +01001081 status = mos7840_set_reg_sync(port, mos7840_port->ControlRegOffset,
1082 Data);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001083
Alan Cox880af9d2008-07-22 11:16:12 +01001084 /* Check to see if we've set up our endpoint info yet *
1085 * (can't set it up in mos7840_startup as the structures *
1086 * were not set up at that time.) */
Oliver Neukum0de9a702007-03-16 20:28:28 +01001087 if (port0->open_ports == 1) {
Paul B Schroeder3f542972006-08-31 19:41:47 -05001088 if (serial->port[0]->interrupt_in_buffer == NULL) {
Paul B Schroeder3f542972006-08-31 19:41:47 -05001089 /* set up interrupt urb */
Paul B Schroeder3f542972006-08-31 19:41:47 -05001090 usb_fill_int_urb(serial->port[0]->interrupt_in_urb,
Alan Cox880af9d2008-07-22 11:16:12 +01001091 serial->dev,
1092 usb_rcvintpipe(serial->dev,
1093 serial->port[0]->interrupt_in_endpointAddress),
1094 serial->port[0]->interrupt_in_buffer,
1095 serial->port[0]->interrupt_in_urb->
1096 transfer_buffer_length,
1097 mos7840_interrupt_callback,
1098 serial,
1099 serial->port[0]->interrupt_in_urb->interval);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001100
1101 /* start interrupt read for mos7840 *
1102 * will continue as long as mos7840 is connected */
1103
1104 response =
1105 usb_submit_urb(serial->port[0]->interrupt_in_urb,
1106 GFP_KERNEL);
1107 if (response) {
Greg Kroah-Hartman194343d2008-08-20 16:56:34 -07001108 dev_err(&port->dev, "%s - Error %d submitting "
1109 "interrupt urb\n", __func__, response);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001110 }
1111
1112 }
1113
1114 }
1115
1116 /* see if we've set up our endpoint info yet *
1117 * (can't set it up in mos7840_startup as the *
1118 * structures were not set up at that time.) */
1119
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001120 dev_dbg(&port->dev, "port number is %d\n", port->number);
1121 dev_dbg(&port->dev, "serial number is %d\n", port->serial->minor);
1122 dev_dbg(&port->dev, "Bulkin endpoint is %d\n", port->bulk_in_endpointAddress);
1123 dev_dbg(&port->dev, "BulkOut endpoint is %d\n", port->bulk_out_endpointAddress);
1124 dev_dbg(&port->dev, "Interrupt endpoint is %d\n", port->interrupt_in_endpointAddress);
1125 dev_dbg(&port->dev, "port's number in the device is %d\n", mos7840_port->port_num);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001126 mos7840_port->read_urb = port->read_urb;
1127
1128 /* set up our bulk in urb */
Donald Lee093ea2d2012-03-14 15:26:33 +08001129 if ((serial->num_ports == 2)
1130 && ((((__u16)port->number -
1131 (__u16)(port->serial->minor)) % 2) != 0)) {
1132 usb_fill_bulk_urb(mos7840_port->read_urb,
1133 serial->dev,
1134 usb_rcvbulkpipe(serial->dev,
1135 (port->bulk_in_endpointAddress) + 2),
1136 port->bulk_in_buffer,
1137 mos7840_port->read_urb->transfer_buffer_length,
1138 mos7840_bulk_in_callback, mos7840_port);
1139 } else {
1140 usb_fill_bulk_urb(mos7840_port->read_urb,
1141 serial->dev,
1142 usb_rcvbulkpipe(serial->dev,
1143 port->bulk_in_endpointAddress),
1144 port->bulk_in_buffer,
1145 mos7840_port->read_urb->transfer_buffer_length,
1146 mos7840_bulk_in_callback, mos7840_port);
1147 }
Paul B Schroeder3f542972006-08-31 19:41:47 -05001148
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001149 dev_dbg(&port->dev, "%s: bulkin endpoint is %d\n", __func__, port->bulk_in_endpointAddress);
Greg Kroah-Hartman50de36f2008-12-10 16:00:30 -08001150 mos7840_port->read_urb_busy = true;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001151 response = usb_submit_urb(mos7840_port->read_urb, GFP_KERNEL);
1152 if (response) {
Greg Kroah-Hartman194343d2008-08-20 16:56:34 -07001153 dev_err(&port->dev, "%s - Error %d submitting control urb\n",
1154 __func__, response);
Greg Kroah-Hartman50de36f2008-12-10 16:00:30 -08001155 mos7840_port->read_urb_busy = false;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001156 }
1157
1158 /* initialize our wait queues */
1159 init_waitqueue_head(&mos7840_port->wait_chase);
1160 init_waitqueue_head(&mos7840_port->delta_msr_wait);
1161
1162 /* initialize our icount structure */
1163 memset(&(mos7840_port->icount), 0x00, sizeof(mos7840_port->icount));
1164
1165 /* initialize our port settings */
Alan Cox880af9d2008-07-22 11:16:12 +01001166 /* Must set to enable ints! */
1167 mos7840_port->shadowMCR = MCR_MASTER_IE;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001168 /* send a open port command */
1169 mos7840_port->open = 1;
Alan Cox880af9d2008-07-22 11:16:12 +01001170 /* mos7840_change_port_settings(mos7840_port,old_termios); */
Paul B Schroeder3f542972006-08-31 19:41:47 -05001171 mos7840_port->icount.tx = 0;
1172 mos7840_port->icount.rx = 0;
1173
Paul B Schroeder3f542972006-08-31 19:41:47 -05001174 return 0;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001175}
1176
1177/*****************************************************************************
1178 * mos7840_chars_in_buffer
1179 * this function is called by the tty driver when it wants to know how many
1180 * bytes of data we currently have outstanding in the port (data that has
1181 * been written, but hasn't made it out the port yet)
1182 * If successful, we return the number of bytes left to be written in the
1183 * system,
Alan Cox95da3102008-07-22 11:09:07 +01001184 * Otherwise we return zero.
Paul B Schroeder3f542972006-08-31 19:41:47 -05001185 *****************************************************************************/
1186
Alan Cox95da3102008-07-22 11:09:07 +01001187static int mos7840_chars_in_buffer(struct tty_struct *tty)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001188{
Alan Cox95da3102008-07-22 11:09:07 +01001189 struct usb_serial_port *port = tty->driver_data;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001190 int i;
1191 int chars = 0;
Oliver Neukum0de9a702007-03-16 20:28:28 +01001192 unsigned long flags;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001193 struct moschip_port *mos7840_port;
1194
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001195 if (mos7840_port_paranoia_check(port, __func__))
Alan Cox95da3102008-07-22 11:09:07 +01001196 return 0;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001197
1198 mos7840_port = mos7840_get_port_private(port);
Greg Kroah-Hartman33631552012-05-03 16:44:33 -07001199 if (mos7840_port == NULL)
Alan Cox95da3102008-07-22 11:09:07 +01001200 return 0;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001201
Alan Cox880af9d2008-07-22 11:16:12 +01001202 spin_lock_irqsave(&mos7840_port->pool_lock, flags);
Mark Ferrell5c263b92012-07-24 14:15:13 -05001203 for (i = 0; i < NUM_URBS; ++i) {
1204 if (mos7840_port->busy[i]) {
1205 struct urb *urb = mos7840_port->write_urb_pool[i];
1206 chars += urb->transfer_buffer_length;
1207 }
1208 }
Alan Cox880af9d2008-07-22 11:16:12 +01001209 spin_unlock_irqrestore(&mos7840_port->pool_lock, flags);
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001210 dev_dbg(&port->dev, "%s - returns %d\n", __func__, chars);
Oliver Neukum0de9a702007-03-16 20:28:28 +01001211 return chars;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001212
1213}
1214
Paul B Schroeder3f542972006-08-31 19:41:47 -05001215/*****************************************************************************
1216 * mos7840_close
1217 * this function is called by the tty driver when a port is closed
1218 *****************************************************************************/
1219
Alan Cox335f8512009-06-11 12:26:29 +01001220static void mos7840_close(struct usb_serial_port *port)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001221{
1222 struct usb_serial *serial;
1223 struct moschip_port *mos7840_port;
Oliver Neukum0de9a702007-03-16 20:28:28 +01001224 struct moschip_port *port0;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001225 int j;
1226 __u16 Data;
1227
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001228 if (mos7840_port_paranoia_check(port, __func__))
Paul B Schroeder3f542972006-08-31 19:41:47 -05001229 return;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001230
Harvey Harrison441b62c2008-03-03 16:08:34 -08001231 serial = mos7840_get_usb_serial(port, __func__);
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001232 if (!serial)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001233 return;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001234
1235 mos7840_port = mos7840_get_port_private(port);
Oliver Neukum0de9a702007-03-16 20:28:28 +01001236 port0 = mos7840_get_port_private(serial->port[0]);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001237
Oliver Neukum0de9a702007-03-16 20:28:28 +01001238 if (mos7840_port == NULL || port0 == NULL)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001239 return;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001240
1241 for (j = 0; j < NUM_URBS; ++j)
1242 usb_kill_urb(mos7840_port->write_urb_pool[j]);
1243
1244 /* Freeing Write URBs */
1245 for (j = 0; j < NUM_URBS; ++j) {
1246 if (mos7840_port->write_urb_pool[j]) {
1247 if (mos7840_port->write_urb_pool[j]->transfer_buffer)
1248 kfree(mos7840_port->write_urb_pool[j]->
1249 transfer_buffer);
1250
1251 usb_free_urb(mos7840_port->write_urb_pool[j]);
1252 }
1253 }
1254
Paul B Schroeder3f542972006-08-31 19:41:47 -05001255 /* While closing port, shutdown all bulk read, write *
1256 * and interrupt read if they exists */
1257 if (serial->dev) {
Paul B Schroeder3f542972006-08-31 19:41:47 -05001258 if (mos7840_port->write_urb) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001259 dev_dbg(&port->dev, "%s", "Shutdown bulk write\n");
Paul B Schroeder3f542972006-08-31 19:41:47 -05001260 usb_kill_urb(mos7840_port->write_urb);
1261 }
Paul B Schroeder3f542972006-08-31 19:41:47 -05001262 if (mos7840_port->read_urb) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001263 dev_dbg(&port->dev, "%s", "Shutdown bulk read\n");
Paul B Schroeder3f542972006-08-31 19:41:47 -05001264 usb_kill_urb(mos7840_port->read_urb);
Greg Kroah-Hartman50de36f2008-12-10 16:00:30 -08001265 mos7840_port->read_urb_busy = false;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001266 }
1267 if ((&mos7840_port->control_urb)) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001268 dev_dbg(&port->dev, "%s", "Shutdown control read\n");
Alan Cox880af9d2008-07-22 11:16:12 +01001269 /*/ usb_kill_urb (mos7840_port->control_urb); */
Paul B Schroeder3f542972006-08-31 19:41:47 -05001270 }
1271 }
Alan Cox880af9d2008-07-22 11:16:12 +01001272/* if(mos7840_port->ctrl_buf != NULL) */
1273/* kfree(mos7840_port->ctrl_buf); */
Oliver Neukum0de9a702007-03-16 20:28:28 +01001274 port0->open_ports--;
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001275 dev_dbg(&port->dev, "%s in close%d:in port%d\n", __func__, port0->open_ports, port->number);
Oliver Neukum0de9a702007-03-16 20:28:28 +01001276 if (port0->open_ports == 0) {
Paul B Schroeder3f542972006-08-31 19:41:47 -05001277 if (serial->port[0]->interrupt_in_urb) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001278 dev_dbg(&port->dev, "Shutdown interrupt_in_urb\n");
Oliver Neukum0de9a702007-03-16 20:28:28 +01001279 usb_kill_urb(serial->port[0]->interrupt_in_urb);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001280 }
1281 }
1282
1283 if (mos7840_port->write_urb) {
1284 /* if this urb had a transfer buffer already (old tx) free it */
Alan Cox880af9d2008-07-22 11:16:12 +01001285 if (mos7840_port->write_urb->transfer_buffer != NULL)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001286 kfree(mos7840_port->write_urb->transfer_buffer);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001287 usb_free_urb(mos7840_port->write_urb);
1288 }
1289
1290 Data = 0x0;
1291 mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
1292
1293 Data = 0x00;
1294 mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data);
1295
1296 mos7840_port->open = 0;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001297}
1298
1299/************************************************************************
1300 *
1301 * mos7840_block_until_chase_response
1302 *
1303 * This function will block the close until one of the following:
1304 * 1. Response to our Chase comes from mos7840
Joe Perchesdc0d5c12007-12-17 11:40:18 -08001305 * 2. A timeout of 10 seconds without activity has expired
Paul B Schroeder3f542972006-08-31 19:41:47 -05001306 * (1K of mos7840 data @ 2400 baud ==> 4 sec to empty)
1307 *
1308 ************************************************************************/
1309
Alan Cox95da3102008-07-22 11:09:07 +01001310static void mos7840_block_until_chase_response(struct tty_struct *tty,
1311 struct moschip_port *mos7840_port)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001312{
Mark Ferrell1e658482012-07-24 13:38:31 -05001313 int timeout = msecs_to_jiffies(1000);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001314 int wait = 10;
1315 int count;
1316
1317 while (1) {
Alan Cox95da3102008-07-22 11:09:07 +01001318 count = mos7840_chars_in_buffer(tty);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001319
1320 /* Check for Buffer status */
Alan Cox880af9d2008-07-22 11:16:12 +01001321 if (count <= 0)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001322 return;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001323
1324 /* Block the thread for a while */
1325 interruptible_sleep_on_timeout(&mos7840_port->wait_chase,
1326 timeout);
1327 /* No activity.. count down section */
1328 wait--;
1329 if (wait == 0) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001330 dev_dbg(&mos7840_port->port->dev, "%s - TIMEOUT\n", __func__);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001331 return;
1332 } else {
Joe Perchesdc0d5c12007-12-17 11:40:18 -08001333 /* Reset timeout value back to seconds */
Paul B Schroeder3f542972006-08-31 19:41:47 -05001334 wait = 10;
1335 }
1336 }
1337
1338}
1339
1340/*****************************************************************************
1341 * mos7840_break
1342 * this function sends a break to the port
1343 *****************************************************************************/
Alan Cox95da3102008-07-22 11:09:07 +01001344static void mos7840_break(struct tty_struct *tty, int break_state)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001345{
Alan Cox95da3102008-07-22 11:09:07 +01001346 struct usb_serial_port *port = tty->driver_data;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001347 unsigned char data;
1348 struct usb_serial *serial;
1349 struct moschip_port *mos7840_port;
1350
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001351 if (mos7840_port_paranoia_check(port, __func__))
Paul B Schroeder3f542972006-08-31 19:41:47 -05001352 return;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001353
Harvey Harrison441b62c2008-03-03 16:08:34 -08001354 serial = mos7840_get_usb_serial(port, __func__);
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001355 if (!serial)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001356 return;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001357
1358 mos7840_port = mos7840_get_port_private(port);
1359
Alan Cox880af9d2008-07-22 11:16:12 +01001360 if (mos7840_port == NULL)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001361 return;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001362
Alan Cox95da3102008-07-22 11:09:07 +01001363 if (serial->dev)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001364 /* flush and block until tx is empty */
Alan Cox95da3102008-07-22 11:09:07 +01001365 mos7840_block_until_chase_response(tty, mos7840_port);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001366
Alan Cox95da3102008-07-22 11:09:07 +01001367 if (break_state == -1)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001368 data = mos7840_port->shadowLCR | LCR_SET_BREAK;
Alan Cox95da3102008-07-22 11:09:07 +01001369 else
Paul B Schroeder3f542972006-08-31 19:41:47 -05001370 data = mos7840_port->shadowLCR & ~LCR_SET_BREAK;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001371
Alan Cox6b447f042009-01-02 13:48:56 +00001372 /* FIXME: no locking on shadowLCR anywhere in driver */
Paul B Schroeder3f542972006-08-31 19:41:47 -05001373 mos7840_port->shadowLCR = data;
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001374 dev_dbg(&port->dev, "%s mos7840_port->shadowLCR is %x\n", __func__, mos7840_port->shadowLCR);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001375 mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER,
1376 mos7840_port->shadowLCR);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001377}
1378
1379/*****************************************************************************
1380 * mos7840_write_room
1381 * this function is called by the tty driver when it wants to know how many
1382 * bytes of data we can accept for a specific port.
1383 * If successful, we return the amount of room that we have for this port
1384 * Otherwise we return a negative error number.
1385 *****************************************************************************/
1386
Alan Cox95da3102008-07-22 11:09:07 +01001387static int mos7840_write_room(struct tty_struct *tty)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001388{
Alan Cox95da3102008-07-22 11:09:07 +01001389 struct usb_serial_port *port = tty->driver_data;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001390 int i;
1391 int room = 0;
Oliver Neukum0de9a702007-03-16 20:28:28 +01001392 unsigned long flags;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001393 struct moschip_port *mos7840_port;
1394
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001395 if (mos7840_port_paranoia_check(port, __func__))
Paul B Schroeder3f542972006-08-31 19:41:47 -05001396 return -1;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001397
1398 mos7840_port = mos7840_get_port_private(port);
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001399 if (mos7840_port == NULL)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001400 return -1;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001401
Oliver Neukum0de9a702007-03-16 20:28:28 +01001402 spin_lock_irqsave(&mos7840_port->pool_lock, flags);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001403 for (i = 0; i < NUM_URBS; ++i) {
Alan Cox880af9d2008-07-22 11:16:12 +01001404 if (!mos7840_port->busy[i])
Paul B Schroeder3f542972006-08-31 19:41:47 -05001405 room += URB_TRANSFER_BUFFER_SIZE;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001406 }
Oliver Neukum0de9a702007-03-16 20:28:28 +01001407 spin_unlock_irqrestore(&mos7840_port->pool_lock, flags);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001408
Oliver Neukum0de9a702007-03-16 20:28:28 +01001409 room = (room == 0) ? 0 : room - URB_TRANSFER_BUFFER_SIZE + 1;
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001410 dev_dbg(&mos7840_port->port->dev, "%s - returns %d\n", __func__, room);
Oliver Neukum0de9a702007-03-16 20:28:28 +01001411 return room;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001412
1413}
1414
1415/*****************************************************************************
1416 * mos7840_write
1417 * this function is called by the tty driver when data should be written to
1418 * the port.
1419 * If successful, we return the number of bytes written, otherwise we
1420 * return a negative error number.
1421 *****************************************************************************/
1422
Alan Cox95da3102008-07-22 11:09:07 +01001423static int mos7840_write(struct tty_struct *tty, struct usb_serial_port *port,
Paul B Schroeder3f542972006-08-31 19:41:47 -05001424 const unsigned char *data, int count)
1425{
1426 int status;
1427 int i;
1428 int bytes_sent = 0;
1429 int transfer_size;
Oliver Neukum0de9a702007-03-16 20:28:28 +01001430 unsigned long flags;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001431
1432 struct moschip_port *mos7840_port;
1433 struct usb_serial *serial;
1434 struct urb *urb;
Alan Cox880af9d2008-07-22 11:16:12 +01001435 /* __u16 Data; */
Paul B Schroeder3f542972006-08-31 19:41:47 -05001436 const unsigned char *current_position = data;
1437 unsigned char *data1;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001438
1439#ifdef NOTMOS7840
1440 Data = 0x00;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001441 status = mos7840_get_uart_reg(port, LINE_CONTROL_REGISTER, &Data);
1442 mos7840_port->shadowLCR = Data;
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001443 dev_dbg(&port->dev, "%s: LINE_CONTROL_REGISTER is %x\n", __func__, Data);
1444 dev_dbg(&port->dev, "%s: mos7840_port->shadowLCR is %x\n", __func__, mos7840_port->shadowLCR);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001445
Alan Cox880af9d2008-07-22 11:16:12 +01001446 /* Data = 0x03; */
1447 /* status = mos7840_set_uart_reg(port,LINE_CONTROL_REGISTER,Data); */
1448 /* mos7840_port->shadowLCR=Data;//Need to add later */
Paul B Schroeder3f542972006-08-31 19:41:47 -05001449
Alan Cox880af9d2008-07-22 11:16:12 +01001450 Data |= SERIAL_LCR_DLAB; /* data latch enable in LCR 0x80 */
Paul B Schroeder3f542972006-08-31 19:41:47 -05001451 status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
1452
Alan Cox880af9d2008-07-22 11:16:12 +01001453 /* Data = 0x0c; */
1454 /* status = mos7840_set_uart_reg(port,DIVISOR_LATCH_LSB,Data); */
Paul B Schroeder3f542972006-08-31 19:41:47 -05001455 Data = 0x00;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001456 status = mos7840_get_uart_reg(port, DIVISOR_LATCH_LSB, &Data);
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001457 dev_dbg(&port->dev, "%s: DLL value is %x\n", __func__, Data);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001458
1459 Data = 0x0;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001460 status = mos7840_get_uart_reg(port, DIVISOR_LATCH_MSB, &Data);
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001461 dev_dbg(&port->dev, "%s: DLM value is %x\n", __func__, Data);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001462
1463 Data = Data & ~SERIAL_LCR_DLAB;
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001464 dev_dbg(&port->dev, "%s: mos7840_port->shadowLCR is %x\n", __func__, mos7840_port->shadowLCR);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001465 status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
1466#endif
1467
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001468 if (mos7840_port_paranoia_check(port, __func__))
Paul B Schroeder3f542972006-08-31 19:41:47 -05001469 return -1;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001470
1471 serial = port->serial;
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001472 if (mos7840_serial_paranoia_check(serial, __func__))
Paul B Schroeder3f542972006-08-31 19:41:47 -05001473 return -1;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001474
1475 mos7840_port = mos7840_get_port_private(port);
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001476 if (mos7840_port == NULL)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001477 return -1;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001478
1479 /* try to find a free urb in the list */
1480 urb = NULL;
1481
Oliver Neukum0de9a702007-03-16 20:28:28 +01001482 spin_lock_irqsave(&mos7840_port->pool_lock, flags);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001483 for (i = 0; i < NUM_URBS; ++i) {
Oliver Neukum0de9a702007-03-16 20:28:28 +01001484 if (!mos7840_port->busy[i]) {
1485 mos7840_port->busy[i] = 1;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001486 urb = mos7840_port->write_urb_pool[i];
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001487 dev_dbg(&port->dev, "URB:%d\n", i);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001488 break;
1489 }
1490 }
Oliver Neukum0de9a702007-03-16 20:28:28 +01001491 spin_unlock_irqrestore(&mos7840_port->pool_lock, flags);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001492
1493 if (urb == NULL) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001494 dev_dbg(&port->dev, "%s - no more free urbs\n", __func__);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001495 goto exit;
1496 }
1497
1498 if (urb->transfer_buffer == NULL) {
1499 urb->transfer_buffer =
1500 kmalloc(URB_TRANSFER_BUFFER_SIZE, GFP_KERNEL);
1501
1502 if (urb->transfer_buffer == NULL) {
Johan Hovold22a416c2012-02-10 13:20:51 +01001503 dev_err_console(port, "%s no more kernel memory...\n",
Greg Kroah-Hartman194343d2008-08-20 16:56:34 -07001504 __func__);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001505 goto exit;
1506 }
1507 }
1508 transfer_size = min(count, URB_TRANSFER_BUFFER_SIZE);
1509
Al Viro97c49652006-10-09 20:29:03 +01001510 memcpy(urb->transfer_buffer, current_position, transfer_size);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001511
1512 /* fill urb with data and submit */
Donald Lee093ea2d2012-03-14 15:26:33 +08001513 if ((serial->num_ports == 2)
1514 && ((((__u16)port->number -
1515 (__u16)(port->serial->minor)) % 2) != 0)) {
1516 usb_fill_bulk_urb(urb,
1517 serial->dev,
1518 usb_sndbulkpipe(serial->dev,
1519 (port->bulk_out_endpointAddress) + 2),
1520 urb->transfer_buffer,
1521 transfer_size,
1522 mos7840_bulk_out_data_callback, mos7840_port);
1523 } else {
1524 usb_fill_bulk_urb(urb,
1525 serial->dev,
1526 usb_sndbulkpipe(serial->dev,
1527 port->bulk_out_endpointAddress),
1528 urb->transfer_buffer,
1529 transfer_size,
1530 mos7840_bulk_out_data_callback, mos7840_port);
1531 }
Paul B Schroeder3f542972006-08-31 19:41:47 -05001532
1533 data1 = urb->transfer_buffer;
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001534 dev_dbg(&port->dev, "bulkout endpoint is %d\n", port->bulk_out_endpointAddress);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001535
Donald0eafe4d2012-04-19 15:00:45 +08001536 /* Turn on LED */
1537 if (mos7840_port->has_led && !mos7840_port->led_flag) {
1538 mos7840_port->led_flag = true;
1539 mos7840_set_led_sync(port, MODEM_CONTROL_REGISTER, 0x0301);
1540 mod_timer(&mos7840_port->led_timer1,
1541 jiffies + msecs_to_jiffies(LED_ON_MS));
1542 }
1543
Paul B Schroeder3f542972006-08-31 19:41:47 -05001544 /* send it down the pipe */
1545 status = usb_submit_urb(urb, GFP_ATOMIC);
1546
1547 if (status) {
Oliver Neukum0de9a702007-03-16 20:28:28 +01001548 mos7840_port->busy[i] = 0;
Johan Hovold22a416c2012-02-10 13:20:51 +01001549 dev_err_console(port, "%s - usb_submit_urb(write bulk) failed "
Greg Kroah-Hartman194343d2008-08-20 16:56:34 -07001550 "with status = %d\n", __func__, status);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001551 bytes_sent = status;
1552 goto exit;
1553 }
1554 bytes_sent = transfer_size;
1555 mos7840_port->icount.tx += transfer_size;
Oliver Neukum0de9a702007-03-16 20:28:28 +01001556 smp_wmb();
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001557 dev_dbg(&port->dev, "mos7840_port->icount.tx is %d:\n", mos7840_port->icount.tx);
Alan Cox95da3102008-07-22 11:09:07 +01001558exit:
Paul B Schroeder3f542972006-08-31 19:41:47 -05001559 return bytes_sent;
1560
1561}
1562
1563/*****************************************************************************
1564 * mos7840_throttle
1565 * this function is called by the tty driver when it wants to stop the data
1566 * being read from the port.
1567 *****************************************************************************/
1568
Alan Cox95da3102008-07-22 11:09:07 +01001569static void mos7840_throttle(struct tty_struct *tty)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001570{
Alan Cox95da3102008-07-22 11:09:07 +01001571 struct usb_serial_port *port = tty->driver_data;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001572 struct moschip_port *mos7840_port;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001573 int status;
1574
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001575 if (mos7840_port_paranoia_check(port, __func__))
Paul B Schroeder3f542972006-08-31 19:41:47 -05001576 return;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001577
1578 mos7840_port = mos7840_get_port_private(port);
1579
1580 if (mos7840_port == NULL)
1581 return;
1582
1583 if (!mos7840_port->open) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001584 dev_dbg(&port->dev, "%s", "port not opened\n");
Paul B Schroeder3f542972006-08-31 19:41:47 -05001585 return;
1586 }
1587
Paul B Schroeder3f542972006-08-31 19:41:47 -05001588 /* if we are implementing XON/XOFF, send the stop character */
1589 if (I_IXOFF(tty)) {
1590 unsigned char stop_char = STOP_CHAR(tty);
Alan Cox95da3102008-07-22 11:09:07 +01001591 status = mos7840_write(tty, port, &stop_char, 1);
1592 if (status <= 0)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001593 return;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001594 }
Paul B Schroeder3f542972006-08-31 19:41:47 -05001595 /* if we are implementing RTS/CTS, toggle that line */
1596 if (tty->termios->c_cflag & CRTSCTS) {
1597 mos7840_port->shadowMCR &= ~MCR_RTS;
Alan Cox95da3102008-07-22 11:09:07 +01001598 status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER,
Paul B Schroeder3f542972006-08-31 19:41:47 -05001599 mos7840_port->shadowMCR);
Alan Cox95da3102008-07-22 11:09:07 +01001600 if (status < 0)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001601 return;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001602 }
Paul B Schroeder3f542972006-08-31 19:41:47 -05001603}
1604
1605/*****************************************************************************
1606 * mos7840_unthrottle
Alan Cox880af9d2008-07-22 11:16:12 +01001607 * this function is called by the tty driver when it wants to resume
1608 * the data being read from the port (called after mos7840_throttle is
1609 * called)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001610 *****************************************************************************/
Alan Cox95da3102008-07-22 11:09:07 +01001611static void mos7840_unthrottle(struct tty_struct *tty)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001612{
Alan Cox95da3102008-07-22 11:09:07 +01001613 struct usb_serial_port *port = tty->driver_data;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001614 int status;
1615 struct moschip_port *mos7840_port = mos7840_get_port_private(port);
1616
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001617 if (mos7840_port_paranoia_check(port, __func__))
Paul B Schroeder3f542972006-08-31 19:41:47 -05001618 return;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001619
1620 if (mos7840_port == NULL)
1621 return;
1622
1623 if (!mos7840_port->open) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001624 dev_dbg(&port->dev, "%s - port not opened\n", __func__);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001625 return;
1626 }
1627
Paul B Schroeder3f542972006-08-31 19:41:47 -05001628 /* if we are implementing XON/XOFF, send the start character */
1629 if (I_IXOFF(tty)) {
1630 unsigned char start_char = START_CHAR(tty);
Alan Cox95da3102008-07-22 11:09:07 +01001631 status = mos7840_write(tty, port, &start_char, 1);
1632 if (status <= 0)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001633 return;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001634 }
1635
1636 /* if we are implementing RTS/CTS, toggle that line */
1637 if (tty->termios->c_cflag & CRTSCTS) {
1638 mos7840_port->shadowMCR |= MCR_RTS;
Alan Cox95da3102008-07-22 11:09:07 +01001639 status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER,
Paul B Schroeder3f542972006-08-31 19:41:47 -05001640 mos7840_port->shadowMCR);
Alan Cox95da3102008-07-22 11:09:07 +01001641 if (status < 0)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001642 return;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001643 }
Paul B Schroeder3f542972006-08-31 19:41:47 -05001644}
1645
Alan Cox60b33c12011-02-14 16:26:14 +00001646static int mos7840_tiocmget(struct tty_struct *tty)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001647{
Alan Cox95da3102008-07-22 11:09:07 +01001648 struct usb_serial_port *port = tty->driver_data;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001649 struct moschip_port *mos7840_port;
1650 unsigned int result;
1651 __u16 msr;
1652 __u16 mcr;
Alan Cox880af9d2008-07-22 11:16:12 +01001653 int status;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001654 mos7840_port = mos7840_get_port_private(port);
1655
Paul B Schroeder3f542972006-08-31 19:41:47 -05001656 if (mos7840_port == NULL)
1657 return -ENODEV;
1658
1659 status = mos7840_get_uart_reg(port, MODEM_STATUS_REGISTER, &msr);
1660 status = mos7840_get_uart_reg(port, MODEM_CONTROL_REGISTER, &mcr);
1661 result = ((mcr & MCR_DTR) ? TIOCM_DTR : 0)
1662 | ((mcr & MCR_RTS) ? TIOCM_RTS : 0)
1663 | ((mcr & MCR_LOOPBACK) ? TIOCM_LOOP : 0)
1664 | ((msr & MOS7840_MSR_CTS) ? TIOCM_CTS : 0)
1665 | ((msr & MOS7840_MSR_CD) ? TIOCM_CAR : 0)
1666 | ((msr & MOS7840_MSR_RI) ? TIOCM_RI : 0)
1667 | ((msr & MOS7840_MSR_DSR) ? TIOCM_DSR : 0);
1668
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001669 dev_dbg(&port->dev, "%s - 0x%04X\n", __func__, result);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001670
1671 return result;
1672}
1673
Alan Cox20b9d172011-02-14 16:26:50 +00001674static int mos7840_tiocmset(struct tty_struct *tty,
Paul B Schroeder3f542972006-08-31 19:41:47 -05001675 unsigned int set, unsigned int clear)
1676{
Alan Cox95da3102008-07-22 11:09:07 +01001677 struct usb_serial_port *port = tty->driver_data;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001678 struct moschip_port *mos7840_port;
1679 unsigned int mcr;
Roel Kluin87521c42008-04-17 06:16:24 +02001680 int status;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001681
Paul B Schroeder3f542972006-08-31 19:41:47 -05001682 mos7840_port = mos7840_get_port_private(port);
1683
1684 if (mos7840_port == NULL)
1685 return -ENODEV;
1686
Alan Coxe2984492008-02-20 20:51:45 +00001687 /* FIXME: What locks the port registers ? */
Paul B Schroeder3f542972006-08-31 19:41:47 -05001688 mcr = mos7840_port->shadowMCR;
1689 if (clear & TIOCM_RTS)
1690 mcr &= ~MCR_RTS;
1691 if (clear & TIOCM_DTR)
1692 mcr &= ~MCR_DTR;
1693 if (clear & TIOCM_LOOP)
1694 mcr &= ~MCR_LOOPBACK;
1695
1696 if (set & TIOCM_RTS)
1697 mcr |= MCR_RTS;
1698 if (set & TIOCM_DTR)
1699 mcr |= MCR_DTR;
1700 if (set & TIOCM_LOOP)
1701 mcr |= MCR_LOOPBACK;
1702
1703 mos7840_port->shadowMCR = mcr;
1704
Paul B Schroeder3f542972006-08-31 19:41:47 -05001705 status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, mcr);
1706 if (status < 0) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001707 dev_dbg(&port->dev, "setting MODEM_CONTROL_REGISTER Failed\n");
Roel Kluin87521c42008-04-17 06:16:24 +02001708 return status;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001709 }
1710
1711 return 0;
1712}
1713
1714/*****************************************************************************
1715 * mos7840_calc_baud_rate_divisor
1716 * this function calculates the proper baud rate divisor for the specified
1717 * baud rate.
1718 *****************************************************************************/
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001719static int mos7840_calc_baud_rate_divisor(struct usb_serial_port *port,
1720 int baudRate, int *divisor,
Alan Cox880af9d2008-07-22 11:16:12 +01001721 __u16 *clk_sel_val)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001722{
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001723 dev_dbg(&port->dev, "%s - %d\n", __func__, baudRate);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001724
1725 if (baudRate <= 115200) {
1726 *divisor = 115200 / baudRate;
1727 *clk_sel_val = 0x0;
1728 }
1729 if ((baudRate > 115200) && (baudRate <= 230400)) {
1730 *divisor = 230400 / baudRate;
1731 *clk_sel_val = 0x10;
1732 } else if ((baudRate > 230400) && (baudRate <= 403200)) {
1733 *divisor = 403200 / baudRate;
1734 *clk_sel_val = 0x20;
1735 } else if ((baudRate > 403200) && (baudRate <= 460800)) {
1736 *divisor = 460800 / baudRate;
1737 *clk_sel_val = 0x30;
1738 } else if ((baudRate > 460800) && (baudRate <= 806400)) {
1739 *divisor = 806400 / baudRate;
1740 *clk_sel_val = 0x40;
1741 } else if ((baudRate > 806400) && (baudRate <= 921600)) {
1742 *divisor = 921600 / baudRate;
1743 *clk_sel_val = 0x50;
1744 } else if ((baudRate > 921600) && (baudRate <= 1572864)) {
1745 *divisor = 1572864 / baudRate;
1746 *clk_sel_val = 0x60;
1747 } else if ((baudRate > 1572864) && (baudRate <= 3145728)) {
1748 *divisor = 3145728 / baudRate;
1749 *clk_sel_val = 0x70;
1750 }
1751 return 0;
1752
1753#ifdef NOTMCS7840
1754
1755 for (i = 0; i < ARRAY_SIZE(mos7840_divisor_table); i++) {
1756 if (mos7840_divisor_table[i].BaudRate == baudrate) {
1757 *divisor = mos7840_divisor_table[i].Divisor;
1758 return 0;
1759 }
1760 }
1761
1762 /* After trying for all the standard baud rates *
1763 * Try calculating the divisor for this baud rate */
1764
1765 if (baudrate > 75 && baudrate < 230400) {
1766 /* get the divisor */
1767 custom = (__u16) (230400L / baudrate);
1768
1769 /* Check for round off */
1770 round1 = (__u16) (2304000L / baudrate);
1771 round = (__u16) (round1 - (custom * 10));
Alan Cox880af9d2008-07-22 11:16:12 +01001772 if (round > 4)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001773 custom++;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001774 *divisor = custom;
1775
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001776 dev_dbg(&port->dev, " Baud %d = %d\n", baudrate, custom);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001777 return 0;
1778 }
1779
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001780 dev_dbg(&port->dev, "%s", " Baud calculation Failed...\n");
Paul B Schroeder3f542972006-08-31 19:41:47 -05001781 return -1;
1782#endif
1783}
1784
1785/*****************************************************************************
1786 * mos7840_send_cmd_write_baud_rate
1787 * this function sends the proper command to change the baud rate of the
1788 * specified port.
1789 *****************************************************************************/
1790
1791static int mos7840_send_cmd_write_baud_rate(struct moschip_port *mos7840_port,
1792 int baudRate)
1793{
1794 int divisor = 0;
1795 int status;
1796 __u16 Data;
1797 unsigned char number;
1798 __u16 clk_sel_val;
1799 struct usb_serial_port *port;
1800
1801 if (mos7840_port == NULL)
1802 return -1;
1803
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001804 port = mos7840_port->port;
1805 if (mos7840_port_paranoia_check(port, __func__))
Paul B Schroeder3f542972006-08-31 19:41:47 -05001806 return -1;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001807
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001808 if (mos7840_serial_paranoia_check(port->serial, __func__))
Paul B Schroeder3f542972006-08-31 19:41:47 -05001809 return -1;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001810
Paul B Schroeder3f542972006-08-31 19:41:47 -05001811 number = mos7840_port->port->number - mos7840_port->port->serial->minor;
1812
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001813 dev_dbg(&port->dev, "%s - port = %d, baud = %d\n", __func__,
1814 mos7840_port->port->number, baudRate);
Alan Cox880af9d2008-07-22 11:16:12 +01001815 /* reset clk_uart_sel in spregOffset */
Paul B Schroeder3f542972006-08-31 19:41:47 -05001816 if (baudRate > 115200) {
1817#ifdef HW_flow_control
Alan Cox880af9d2008-07-22 11:16:12 +01001818 /* NOTE: need to see the pther register to modify */
1819 /* setting h/w flow control bit to 1 */
Paul B Schroeder3f542972006-08-31 19:41:47 -05001820 Data = 0x2b;
1821 mos7840_port->shadowMCR = Data;
Alan Cox880af9d2008-07-22 11:16:12 +01001822 status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER,
1823 Data);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001824 if (status < 0) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001825 dev_dbg(&port->dev, "Writing spreg failed in set_serial_baud\n");
Paul B Schroeder3f542972006-08-31 19:41:47 -05001826 return -1;
1827 }
1828#endif
1829
1830 } else {
1831#ifdef HW_flow_control
Donald Lee093ea2d2012-03-14 15:26:33 +08001832 /* setting h/w flow control bit to 0 */
Paul B Schroeder3f542972006-08-31 19:41:47 -05001833 Data = 0xb;
1834 mos7840_port->shadowMCR = Data;
Alan Cox880af9d2008-07-22 11:16:12 +01001835 status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER,
1836 Data);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001837 if (status < 0) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001838 dev_dbg(&port->dev, "Writing spreg failed in set_serial_baud\n");
Paul B Schroeder3f542972006-08-31 19:41:47 -05001839 return -1;
1840 }
1841#endif
1842
1843 }
1844
Alan Cox880af9d2008-07-22 11:16:12 +01001845 if (1) { /* baudRate <= 115200) */
Paul B Schroeder3f542972006-08-31 19:41:47 -05001846 clk_sel_val = 0x0;
1847 Data = 0x0;
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001848 status = mos7840_calc_baud_rate_divisor(port, baudRate, &divisor,
Paul B Schroeder3f542972006-08-31 19:41:47 -05001849 &clk_sel_val);
Alan Cox880af9d2008-07-22 11:16:12 +01001850 status = mos7840_get_reg_sync(port, mos7840_port->SpRegOffset,
1851 &Data);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001852 if (status < 0) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001853 dev_dbg(&port->dev, "reading spreg failed in set_serial_baud\n");
Paul B Schroeder3f542972006-08-31 19:41:47 -05001854 return -1;
1855 }
1856 Data = (Data & 0x8f) | clk_sel_val;
Alan Cox880af9d2008-07-22 11:16:12 +01001857 status = mos7840_set_reg_sync(port, mos7840_port->SpRegOffset,
1858 Data);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001859 if (status < 0) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001860 dev_dbg(&port->dev, "Writing spreg failed in set_serial_baud\n");
Paul B Schroeder3f542972006-08-31 19:41:47 -05001861 return -1;
1862 }
1863 /* Calculate the Divisor */
1864
1865 if (status) {
Greg Kroah-Hartman194343d2008-08-20 16:56:34 -07001866 dev_err(&port->dev, "%s - bad baud rate\n", __func__);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001867 return status;
1868 }
1869 /* Enable access to divisor latch */
1870 Data = mos7840_port->shadowLCR | SERIAL_LCR_DLAB;
1871 mos7840_port->shadowLCR = Data;
1872 mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
1873
1874 /* Write the divisor */
1875 Data = (unsigned char)(divisor & 0xff);
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001876 dev_dbg(&port->dev, "set_serial_baud Value to write DLL is %x\n", Data);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001877 mos7840_set_uart_reg(port, DIVISOR_LATCH_LSB, Data);
1878
1879 Data = (unsigned char)((divisor & 0xff00) >> 8);
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001880 dev_dbg(&port->dev, "set_serial_baud Value to write DLM is %x\n", Data);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001881 mos7840_set_uart_reg(port, DIVISOR_LATCH_MSB, Data);
1882
1883 /* Disable access to divisor latch */
1884 Data = mos7840_port->shadowLCR & ~SERIAL_LCR_DLAB;
1885 mos7840_port->shadowLCR = Data;
1886 mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
1887
1888 }
Paul B Schroeder3f542972006-08-31 19:41:47 -05001889 return status;
1890}
1891
1892/*****************************************************************************
1893 * mos7840_change_port_settings
1894 * This routine is called to set the UART on the device to match
1895 * the specified new settings.
1896 *****************************************************************************/
1897
Alan Cox95da3102008-07-22 11:09:07 +01001898static void mos7840_change_port_settings(struct tty_struct *tty,
1899 struct moschip_port *mos7840_port, struct ktermios *old_termios)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001900{
Paul B Schroeder3f542972006-08-31 19:41:47 -05001901 int baud;
1902 unsigned cflag;
1903 unsigned iflag;
1904 __u8 lData;
1905 __u8 lParity;
1906 __u8 lStop;
1907 int status;
1908 __u16 Data;
1909 struct usb_serial_port *port;
1910 struct usb_serial *serial;
1911
1912 if (mos7840_port == NULL)
1913 return;
1914
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001915 port = mos7840_port->port;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001916
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001917 if (mos7840_port_paranoia_check(port, __func__))
Paul B Schroeder3f542972006-08-31 19:41:47 -05001918 return;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001919
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001920 if (mos7840_serial_paranoia_check(port->serial, __func__))
Paul B Schroeder3f542972006-08-31 19:41:47 -05001921 return;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001922
1923 serial = port->serial;
1924
Paul B Schroeder3f542972006-08-31 19:41:47 -05001925 if (!mos7840_port->open) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001926 dev_dbg(&port->dev, "%s - port not opened\n", __func__);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001927 return;
1928 }
1929
Paul B Schroeder3f542972006-08-31 19:41:47 -05001930 lData = LCR_BITS_8;
1931 lStop = LCR_STOP_1;
1932 lParity = LCR_PAR_NONE;
1933
1934 cflag = tty->termios->c_cflag;
1935 iflag = tty->termios->c_iflag;
1936
1937 /* Change the number of bits */
1938 if (cflag & CSIZE) {
1939 switch (cflag & CSIZE) {
1940 case CS5:
1941 lData = LCR_BITS_5;
1942 break;
1943
1944 case CS6:
1945 lData = LCR_BITS_6;
1946 break;
1947
1948 case CS7:
1949 lData = LCR_BITS_7;
1950 break;
1951 default:
1952 case CS8:
1953 lData = LCR_BITS_8;
1954 break;
1955 }
1956 }
1957 /* Change the Parity bit */
1958 if (cflag & PARENB) {
1959 if (cflag & PARODD) {
1960 lParity = LCR_PAR_ODD;
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001961 dev_dbg(&port->dev, "%s - parity = odd\n", __func__);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001962 } else {
1963 lParity = LCR_PAR_EVEN;
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001964 dev_dbg(&port->dev, "%s - parity = even\n", __func__);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001965 }
1966
1967 } else {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001968 dev_dbg(&port->dev, "%s - parity = none\n", __func__);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001969 }
1970
Alan Cox880af9d2008-07-22 11:16:12 +01001971 if (cflag & CMSPAR)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001972 lParity = lParity | 0x20;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001973
1974 /* Change the Stop bit */
1975 if (cflag & CSTOPB) {
1976 lStop = LCR_STOP_2;
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001977 dev_dbg(&port->dev, "%s - stop bits = 2\n", __func__);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001978 } else {
1979 lStop = LCR_STOP_1;
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001980 dev_dbg(&port->dev, "%s - stop bits = 1\n", __func__);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001981 }
1982
1983 /* Update the LCR with the correct value */
1984 mos7840_port->shadowLCR &=
1985 ~(LCR_BITS_MASK | LCR_STOP_MASK | LCR_PAR_MASK);
1986 mos7840_port->shadowLCR |= (lData | lParity | lStop);
1987
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001988 dev_dbg(&port->dev, "%s - mos7840_port->shadowLCR is %x\n", __func__,
1989 mos7840_port->shadowLCR);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001990 /* Disable Interrupts */
1991 Data = 0x00;
1992 mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data);
1993
1994 Data = 0x00;
1995 mos7840_set_uart_reg(port, FIFO_CONTROL_REGISTER, Data);
1996
1997 Data = 0xcf;
1998 mos7840_set_uart_reg(port, FIFO_CONTROL_REGISTER, Data);
1999
2000 /* Send the updated LCR value to the mos7840 */
2001 Data = mos7840_port->shadowLCR;
2002
2003 mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
2004
2005 Data = 0x00b;
2006 mos7840_port->shadowMCR = Data;
2007 mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
2008 Data = 0x00b;
2009 mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
2010
2011 /* set up the MCR register and send it to the mos7840 */
2012
2013 mos7840_port->shadowMCR = MCR_MASTER_IE;
Alan Cox880af9d2008-07-22 11:16:12 +01002014 if (cflag & CBAUD)
Paul B Schroeder3f542972006-08-31 19:41:47 -05002015 mos7840_port->shadowMCR |= (MCR_DTR | MCR_RTS);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002016
Alan Cox880af9d2008-07-22 11:16:12 +01002017 if (cflag & CRTSCTS)
Paul B Schroeder3f542972006-08-31 19:41:47 -05002018 mos7840_port->shadowMCR |= (MCR_XON_ANY);
Alan Cox880af9d2008-07-22 11:16:12 +01002019 else
Paul B Schroeder3f542972006-08-31 19:41:47 -05002020 mos7840_port->shadowMCR &= ~(MCR_XON_ANY);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002021
2022 Data = mos7840_port->shadowMCR;
2023 mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
2024
2025 /* Determine divisor based on baud rate */
2026 baud = tty_get_baud_rate(tty);
2027
2028 if (!baud) {
2029 /* pick a default, any default... */
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002030 dev_dbg(&port->dev, "%s", "Picked default baud...\n");
Paul B Schroeder3f542972006-08-31 19:41:47 -05002031 baud = 9600;
2032 }
2033
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002034 dev_dbg(&port->dev, "%s - baud rate = %d\n", __func__, baud);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002035 status = mos7840_send_cmd_write_baud_rate(mos7840_port, baud);
2036
2037 /* Enable Interrupts */
2038 Data = 0x0c;
2039 mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data);
2040
Greg Kroah-Hartman50de36f2008-12-10 16:00:30 -08002041 if (mos7840_port->read_urb_busy == false) {
Greg Kroah-Hartman50de36f2008-12-10 16:00:30 -08002042 mos7840_port->read_urb_busy = true;
Paul B Schroeder3f542972006-08-31 19:41:47 -05002043 status = usb_submit_urb(mos7840_port->read_urb, GFP_ATOMIC);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002044 if (status) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002045 dev_dbg(&port->dev, "usb_submit_urb(read bulk) failed, status = %d\n",
Paul B Schroeder3f542972006-08-31 19:41:47 -05002046 status);
Greg Kroah-Hartman50de36f2008-12-10 16:00:30 -08002047 mos7840_port->read_urb_busy = false;
Paul B Schroeder3f542972006-08-31 19:41:47 -05002048 }
2049 }
2050 wake_up(&mos7840_port->delta_msr_wait);
2051 mos7840_port->delta_msr_cond = 1;
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002052 dev_dbg(&port->dev, "%s - mos7840_port->shadowLCR is End %x\n", __func__,
2053 mos7840_port->shadowLCR);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002054}
2055
2056/*****************************************************************************
2057 * mos7840_set_termios
2058 * this function is called by the tty driver when it wants to change
2059 * the termios structure
2060 *****************************************************************************/
2061
Alan Cox95da3102008-07-22 11:09:07 +01002062static void mos7840_set_termios(struct tty_struct *tty,
2063 struct usb_serial_port *port,
Alan Cox606d0992006-12-08 02:38:45 -08002064 struct ktermios *old_termios)
Paul B Schroeder3f542972006-08-31 19:41:47 -05002065{
2066 int status;
2067 unsigned int cflag;
2068 struct usb_serial *serial;
2069 struct moschip_port *mos7840_port;
Greg Kroah-Hartman33631552012-05-03 16:44:33 -07002070
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002071 if (mos7840_port_paranoia_check(port, __func__))
Paul B Schroeder3f542972006-08-31 19:41:47 -05002072 return;
Paul B Schroeder3f542972006-08-31 19:41:47 -05002073
2074 serial = port->serial;
2075
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002076 if (mos7840_serial_paranoia_check(serial, __func__))
Paul B Schroeder3f542972006-08-31 19:41:47 -05002077 return;
Paul B Schroeder3f542972006-08-31 19:41:47 -05002078
2079 mos7840_port = mos7840_get_port_private(port);
2080
2081 if (mos7840_port == NULL)
2082 return;
2083
Paul B Schroeder3f542972006-08-31 19:41:47 -05002084 if (!mos7840_port->open) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002085 dev_dbg(&port->dev, "%s - port not opened\n", __func__);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002086 return;
2087 }
2088
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002089 dev_dbg(&port->dev, "%s", "setting termios - \n");
Paul B Schroeder3f542972006-08-31 19:41:47 -05002090
2091 cflag = tty->termios->c_cflag;
2092
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002093 dev_dbg(&port->dev, "%s - clfag %08x iflag %08x\n", __func__,
2094 tty->termios->c_cflag, RELEVANT_IFLAG(tty->termios->c_iflag));
2095 dev_dbg(&port->dev, "%s - old clfag %08x old iflag %08x\n", __func__,
2096 old_termios->c_cflag, RELEVANT_IFLAG(old_termios->c_iflag));
2097 dev_dbg(&port->dev, "%s - port %d\n", __func__, port->number);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002098
2099 /* change the port settings to the new ones specified */
2100
Alan Cox95da3102008-07-22 11:09:07 +01002101 mos7840_change_port_settings(tty, mos7840_port, old_termios);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002102
2103 if (!mos7840_port->read_urb) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002104 dev_dbg(&port->dev, "%s", "URB KILLED !!!!!\n");
Paul B Schroeder3f542972006-08-31 19:41:47 -05002105 return;
2106 }
2107
Greg Kroah-Hartman50de36f2008-12-10 16:00:30 -08002108 if (mos7840_port->read_urb_busy == false) {
Greg Kroah-Hartman50de36f2008-12-10 16:00:30 -08002109 mos7840_port->read_urb_busy = true;
Paul B Schroeder3f542972006-08-31 19:41:47 -05002110 status = usb_submit_urb(mos7840_port->read_urb, GFP_ATOMIC);
2111 if (status) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002112 dev_dbg(&port->dev, "usb_submit_urb(read bulk) failed, status = %d\n",
Paul B Schroeder3f542972006-08-31 19:41:47 -05002113 status);
Greg Kroah-Hartman50de36f2008-12-10 16:00:30 -08002114 mos7840_port->read_urb_busy = false;
Paul B Schroeder3f542972006-08-31 19:41:47 -05002115 }
2116 }
Paul B Schroeder3f542972006-08-31 19:41:47 -05002117}
2118
2119/*****************************************************************************
2120 * mos7840_get_lsr_info - get line status register info
2121 *
2122 * Purpose: Let user call ioctl() to get info when the UART physically
2123 * is emptied. On bus types like RS485, the transmitter must
2124 * release the bus after transmitting. This must be done when
2125 * the transmit shift register is empty, not be done when the
2126 * transmit holding register is empty. This functionality
2127 * allows an RS485 driver to be written in user space.
2128 *****************************************************************************/
2129
Alan Cox95da3102008-07-22 11:09:07 +01002130static int mos7840_get_lsr_info(struct tty_struct *tty,
Al Viro97c49652006-10-09 20:29:03 +01002131 unsigned int __user *value)
Paul B Schroeder3f542972006-08-31 19:41:47 -05002132{
2133 int count;
2134 unsigned int result = 0;
2135
Alan Cox95da3102008-07-22 11:09:07 +01002136 count = mos7840_chars_in_buffer(tty);
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002137 if (count == 0)
Paul B Schroeder3f542972006-08-31 19:41:47 -05002138 result = TIOCSER_TEMT;
Paul B Schroeder3f542972006-08-31 19:41:47 -05002139
2140 if (copy_to_user(value, &result, sizeof(int)))
2141 return -EFAULT;
2142 return 0;
2143}
2144
2145/*****************************************************************************
Paul B Schroeder3f542972006-08-31 19:41:47 -05002146 * mos7840_get_serial_info
2147 * function to get information about serial port
2148 *****************************************************************************/
2149
2150static int mos7840_get_serial_info(struct moschip_port *mos7840_port,
Al Viro97c49652006-10-09 20:29:03 +01002151 struct serial_struct __user *retinfo)
Paul B Schroeder3f542972006-08-31 19:41:47 -05002152{
2153 struct serial_struct tmp;
2154
2155 if (mos7840_port == NULL)
2156 return -1;
2157
2158 if (!retinfo)
2159 return -EFAULT;
2160
2161 memset(&tmp, 0, sizeof(tmp));
2162
2163 tmp.type = PORT_16550A;
2164 tmp.line = mos7840_port->port->serial->minor;
2165 tmp.port = mos7840_port->port->number;
2166 tmp.irq = 0;
2167 tmp.flags = ASYNC_SKIP_TEST | ASYNC_AUTO_IRQ;
2168 tmp.xmit_fifo_size = NUM_URBS * URB_TRANSFER_BUFFER_SIZE;
2169 tmp.baud_base = 9600;
2170 tmp.close_delay = 5 * HZ;
2171 tmp.closing_wait = 30 * HZ;
2172
2173 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
2174 return -EFAULT;
2175 return 0;
2176}
2177
Alan Cox0bca1b92010-09-16 18:21:40 +01002178static int mos7840_get_icount(struct tty_struct *tty,
2179 struct serial_icounter_struct *icount)
2180{
2181 struct usb_serial_port *port = tty->driver_data;
2182 struct moschip_port *mos7840_port;
2183 struct async_icount cnow;
2184
2185 mos7840_port = mos7840_get_port_private(port);
2186 cnow = mos7840_port->icount;
2187
2188 smp_rmb();
2189 icount->cts = cnow.cts;
2190 icount->dsr = cnow.dsr;
2191 icount->rng = cnow.rng;
2192 icount->dcd = cnow.dcd;
2193 icount->rx = cnow.rx;
2194 icount->tx = cnow.tx;
2195 icount->frame = cnow.frame;
2196 icount->overrun = cnow.overrun;
2197 icount->parity = cnow.parity;
2198 icount->brk = cnow.brk;
2199 icount->buf_overrun = cnow.buf_overrun;
2200
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002201 dev_dbg(&port->dev, "%s TIOCGICOUNT RX=%d, TX=%d\n", __func__,
2202 icount->rx, icount->tx);
Alan Cox0bca1b92010-09-16 18:21:40 +01002203 return 0;
2204}
2205
Paul B Schroeder3f542972006-08-31 19:41:47 -05002206/*****************************************************************************
2207 * SerialIoctl
2208 * this function handles any ioctl calls to the driver
2209 *****************************************************************************/
2210
Alan Cox00a0d0d2011-02-14 16:27:06 +00002211static int mos7840_ioctl(struct tty_struct *tty,
Paul B Schroeder3f542972006-08-31 19:41:47 -05002212 unsigned int cmd, unsigned long arg)
2213{
Alan Cox95da3102008-07-22 11:09:07 +01002214 struct usb_serial_port *port = tty->driver_data;
Al Viro97c49652006-10-09 20:29:03 +01002215 void __user *argp = (void __user *)arg;
Paul B Schroeder3f542972006-08-31 19:41:47 -05002216 struct moschip_port *mos7840_port;
Paul B Schroeder3f542972006-08-31 19:41:47 -05002217
2218 struct async_icount cnow;
2219 struct async_icount cprev;
Paul B Schroeder3f542972006-08-31 19:41:47 -05002220
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002221 if (mos7840_port_paranoia_check(port, __func__))
Paul B Schroeder3f542972006-08-31 19:41:47 -05002222 return -1;
Paul B Schroeder3f542972006-08-31 19:41:47 -05002223
2224 mos7840_port = mos7840_get_port_private(port);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002225
2226 if (mos7840_port == NULL)
2227 return -1;
2228
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002229 dev_dbg(&port->dev, "%s - cmd = 0x%x\n", __func__, cmd);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002230
2231 switch (cmd) {
2232 /* return number of bytes available */
2233
Paul B Schroeder3f542972006-08-31 19:41:47 -05002234 case TIOCSERGETLSR:
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002235 dev_dbg(&port->dev, "%s TIOCSERGETLSR\n", __func__);
Alan Cox95da3102008-07-22 11:09:07 +01002236 return mos7840_get_lsr_info(tty, argp);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002237
Paul B Schroeder3f542972006-08-31 19:41:47 -05002238 case TIOCGSERIAL:
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002239 dev_dbg(&port->dev, "%s TIOCGSERIAL\n", __func__);
Al Viro97c49652006-10-09 20:29:03 +01002240 return mos7840_get_serial_info(mos7840_port, argp);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002241
2242 case TIOCSSERIAL:
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002243 dev_dbg(&port->dev, "%s TIOCSSERIAL\n", __func__);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002244 break;
2245
2246 case TIOCMIWAIT:
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002247 dev_dbg(&port->dev, "%s TIOCMIWAIT\n", __func__);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002248 cprev = mos7840_port->icount;
2249 while (1) {
Alan Cox880af9d2008-07-22 11:16:12 +01002250 /* interruptible_sleep_on(&mos7840_port->delta_msr_wait); */
Paul B Schroeder3f542972006-08-31 19:41:47 -05002251 mos7840_port->delta_msr_cond = 0;
2252 wait_event_interruptible(mos7840_port->delta_msr_wait,
2253 (mos7840_port->
2254 delta_msr_cond == 1));
2255
2256 /* see if a signal did it */
2257 if (signal_pending(current))
2258 return -ERESTARTSYS;
2259 cnow = mos7840_port->icount;
Oliver Neukum0de9a702007-03-16 20:28:28 +01002260 smp_rmb();
Paul B Schroeder3f542972006-08-31 19:41:47 -05002261 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
2262 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts)
2263 return -EIO; /* no change => error */
2264 if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
2265 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
2266 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
2267 ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts))) {
2268 return 0;
2269 }
2270 cprev = cnow;
2271 }
2272 /* NOTREACHED */
2273 break;
2274
Paul B Schroeder3f542972006-08-31 19:41:47 -05002275 default:
2276 break;
2277 }
Paul B Schroeder3f542972006-08-31 19:41:47 -05002278 return -ENOIOCTLCMD;
2279}
2280
Donald0eafe4d2012-04-19 15:00:45 +08002281static int mos7810_check(struct usb_serial *serial)
2282{
2283 int i, pass_count = 0;
2284 __u16 data = 0, mcr_data = 0;
2285 __u16 test_pattern = 0x55AA;
2286
2287 /* Store MCR setting */
2288 usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
2289 MCS_RDREQ, MCS_RD_RTYPE, 0x0300, MODEM_CONTROL_REGISTER,
2290 &mcr_data, VENDOR_READ_LENGTH, MOS_WDR_TIMEOUT);
2291
2292 for (i = 0; i < 16; i++) {
2293 /* Send the 1-bit test pattern out to MCS7810 test pin */
2294 usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
2295 MCS_WRREQ, MCS_WR_RTYPE,
2296 (0x0300 | (((test_pattern >> i) & 0x0001) << 1)),
2297 MODEM_CONTROL_REGISTER, NULL, 0, MOS_WDR_TIMEOUT);
2298
2299 /* Read the test pattern back */
2300 usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
2301 MCS_RDREQ, MCS_RD_RTYPE, 0, GPIO_REGISTER, &data,
2302 VENDOR_READ_LENGTH, MOS_WDR_TIMEOUT);
2303
2304 /* If this is a MCS7810 device, both test patterns must match */
2305 if (((test_pattern >> i) ^ (~data >> 1)) & 0x0001)
2306 break;
2307
2308 pass_count++;
2309 }
2310
2311 /* Restore MCR setting */
2312 usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), MCS_WRREQ,
2313 MCS_WR_RTYPE, 0x0300 | mcr_data, MODEM_CONTROL_REGISTER, NULL,
2314 0, MOS_WDR_TIMEOUT);
2315
2316 if (pass_count == 16)
2317 return 1;
2318
2319 return 0;
2320}
2321
Paul B Schroeder3f542972006-08-31 19:41:47 -05002322static int mos7840_calc_num_ports(struct usb_serial *serial)
2323{
Donald0eafe4d2012-04-19 15:00:45 +08002324 __u16 data = 0x00;
Donald Lee093ea2d2012-03-14 15:26:33 +08002325 int mos7840_num_ports;
Paul B Schroeder3f542972006-08-31 19:41:47 -05002326
Donald0eafe4d2012-04-19 15:00:45 +08002327 usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
2328 MCS_RDREQ, MCS_RD_RTYPE, 0, GPIO_REGISTER, &data,
Donald Lee093ea2d2012-03-14 15:26:33 +08002329 VENDOR_READ_LENGTH, MOS_WDR_TIMEOUT);
2330
Donald0eafe4d2012-04-19 15:00:45 +08002331 if (serial->dev->descriptor.idProduct == MOSCHIP_DEVICE_ID_7810 ||
2332 serial->dev->descriptor.idProduct == MOSCHIP_DEVICE_ID_7820) {
2333 device_type = serial->dev->descriptor.idProduct;
Donald Lee093ea2d2012-03-14 15:26:33 +08002334 } else {
Donald0eafe4d2012-04-19 15:00:45 +08002335 /* For a MCS7840 device GPIO0 must be set to 1 */
2336 if ((data & 0x01) == 1)
2337 device_type = MOSCHIP_DEVICE_ID_7840;
2338 else if (mos7810_check(serial))
2339 device_type = MOSCHIP_DEVICE_ID_7810;
2340 else
2341 device_type = MOSCHIP_DEVICE_ID_7820;
Paul B Schroeder3f542972006-08-31 19:41:47 -05002342 }
Donald Lee093ea2d2012-03-14 15:26:33 +08002343
Donald0eafe4d2012-04-19 15:00:45 +08002344 mos7840_num_ports = (device_type >> 4) & 0x000F;
2345 serial->num_bulk_in = mos7840_num_ports;
2346 serial->num_bulk_out = mos7840_num_ports;
2347 serial->num_ports = mos7840_num_ports;
2348
Paul B Schroeder3f542972006-08-31 19:41:47 -05002349 return mos7840_num_ports;
2350}
2351
2352/****************************************************************************
2353 * mos7840_startup
2354 ****************************************************************************/
2355
2356static int mos7840_startup(struct usb_serial *serial)
2357{
2358 struct moschip_port *mos7840_port;
2359 struct usb_device *dev;
2360 int i, status;
Paul B Schroeder3f542972006-08-31 19:41:47 -05002361 __u16 Data;
Paul B Schroeder3f542972006-08-31 19:41:47 -05002362
Paul B Schroeder3f542972006-08-31 19:41:47 -05002363 dev = serial->dev;
2364
Paul B Schroeder3f542972006-08-31 19:41:47 -05002365 /* we set up the pointers to the endpoints in the mos7840_open *
2366 * function, as the structures aren't created yet. */
2367
2368 /* set up port private structures */
2369 for (i = 0; i < serial->num_ports; ++i) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002370 dev_dbg(&dev->dev, "mos7840_startup: configuring port %d............\n", i);
Burman Yan7ac9da12006-11-22 20:54:38 +02002371 mos7840_port = kzalloc(sizeof(struct moschip_port), GFP_KERNEL);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002372 if (mos7840_port == NULL) {
Greg Kroah-Hartman194343d2008-08-20 16:56:34 -07002373 dev_err(&dev->dev, "%s - Out of memory\n", __func__);
Oliver Neukum0de9a702007-03-16 20:28:28 +01002374 status = -ENOMEM;
2375 i--; /* don't follow NULL pointer cleaning up */
2376 goto error;
Paul B Schroeder3f542972006-08-31 19:41:47 -05002377 }
Paul B Schroeder3f542972006-08-31 19:41:47 -05002378
Alan Cox880af9d2008-07-22 11:16:12 +01002379 /* Initialize all port interrupt end point to port 0 int
2380 * endpoint. Our device has only one interrupt end point
2381 * common to all port */
Paul B Schroeder3f542972006-08-31 19:41:47 -05002382
2383 mos7840_port->port = serial->port[i];
2384 mos7840_set_port_private(serial->port[i], mos7840_port);
Oliver Neukum0de9a702007-03-16 20:28:28 +01002385 spin_lock_init(&mos7840_port->pool_lock);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002386
Tony Cook37768ad2009-04-18 22:42:18 +09302387 /* minor is not initialised until later by
2388 * usb-serial.c:get_free_serial() and cannot therefore be used
2389 * to index device instances */
2390 mos7840_port->port_num = i + 1;
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002391 dev_dbg(&dev->dev, "serial->port[i]->number = %d\n", serial->port[i]->number);
2392 dev_dbg(&dev->dev, "serial->port[i]->serial->minor = %d\n", serial->port[i]->serial->minor);
2393 dev_dbg(&dev->dev, "mos7840_port->port_num = %d\n", mos7840_port->port_num);
2394 dev_dbg(&dev->dev, "serial->minor = %d\n", serial->minor);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002395
2396 if (mos7840_port->port_num == 1) {
2397 mos7840_port->SpRegOffset = 0x0;
2398 mos7840_port->ControlRegOffset = 0x1;
2399 mos7840_port->DcrRegOffset = 0x4;
2400 } else if ((mos7840_port->port_num == 2)
Oliver Neukum0de9a702007-03-16 20:28:28 +01002401 && (serial->num_ports == 4)) {
Paul B Schroeder3f542972006-08-31 19:41:47 -05002402 mos7840_port->SpRegOffset = 0x8;
2403 mos7840_port->ControlRegOffset = 0x9;
2404 mos7840_port->DcrRegOffset = 0x16;
2405 } else if ((mos7840_port->port_num == 2)
Oliver Neukum0de9a702007-03-16 20:28:28 +01002406 && (serial->num_ports == 2)) {
Paul B Schroeder3f542972006-08-31 19:41:47 -05002407 mos7840_port->SpRegOffset = 0xa;
2408 mos7840_port->ControlRegOffset = 0xb;
2409 mos7840_port->DcrRegOffset = 0x19;
2410 } else if ((mos7840_port->port_num == 3)
Oliver Neukum0de9a702007-03-16 20:28:28 +01002411 && (serial->num_ports == 4)) {
Paul B Schroeder3f542972006-08-31 19:41:47 -05002412 mos7840_port->SpRegOffset = 0xa;
2413 mos7840_port->ControlRegOffset = 0xb;
2414 mos7840_port->DcrRegOffset = 0x19;
2415 } else if ((mos7840_port->port_num == 4)
Oliver Neukum0de9a702007-03-16 20:28:28 +01002416 && (serial->num_ports == 4)) {
Paul B Schroeder3f542972006-08-31 19:41:47 -05002417 mos7840_port->SpRegOffset = 0xc;
2418 mos7840_port->ControlRegOffset = 0xd;
2419 mos7840_port->DcrRegOffset = 0x1c;
2420 }
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002421 mos7840_dump_serial_port(serial->port[i], mos7840_port);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002422 mos7840_set_port_private(serial->port[i], mos7840_port);
2423
Alan Cox880af9d2008-07-22 11:16:12 +01002424 /* enable rx_disable bit in control register */
2425 status = mos7840_get_reg_sync(serial->port[i],
2426 mos7840_port->ControlRegOffset, &Data);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002427 if (status < 0) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002428 dev_dbg(&dev->dev, "Reading ControlReg failed status-0x%x\n", status);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002429 break;
2430 } else
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002431 dev_dbg(&dev->dev, "ControlReg Reading success val is %x, status%d\n", Data, status);
Alan Cox880af9d2008-07-22 11:16:12 +01002432 Data |= 0x08; /* setting driver done bit */
2433 Data |= 0x04; /* sp1_bit to have cts change reflect in
2434 modem status reg */
Paul B Schroeder3f542972006-08-31 19:41:47 -05002435
Alan Cox880af9d2008-07-22 11:16:12 +01002436 /* Data |= 0x20; //rx_disable bit */
2437 status = mos7840_set_reg_sync(serial->port[i],
Paul B Schroeder3f542972006-08-31 19:41:47 -05002438 mos7840_port->ControlRegOffset, Data);
2439 if (status < 0) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002440 dev_dbg(&dev->dev, "Writing ControlReg failed(rx_disable) status-0x%x\n", status);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002441 break;
2442 } else
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002443 dev_dbg(&dev->dev, "ControlReg Writing success(rx_disable) status%d\n", status);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002444
Alan Cox880af9d2008-07-22 11:16:12 +01002445 /* Write default values in DCR (i.e 0x01 in DCR0, 0x05 in DCR2
2446 and 0x24 in DCR3 */
Paul B Schroeder3f542972006-08-31 19:41:47 -05002447 Data = 0x01;
Alan Cox880af9d2008-07-22 11:16:12 +01002448 status = mos7840_set_reg_sync(serial->port[i],
2449 (__u16) (mos7840_port->DcrRegOffset + 0), Data);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002450 if (status < 0) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002451 dev_dbg(&dev->dev, "Writing DCR0 failed status-0x%x\n", status);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002452 break;
2453 } else
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002454 dev_dbg(&dev->dev, "DCR0 Writing success status%d\n", status);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002455
2456 Data = 0x05;
Alan Cox880af9d2008-07-22 11:16:12 +01002457 status = mos7840_set_reg_sync(serial->port[i],
2458 (__u16) (mos7840_port->DcrRegOffset + 1), Data);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002459 if (status < 0) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002460 dev_dbg(&dev->dev, "Writing DCR1 failed status-0x%x\n", status);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002461 break;
2462 } else
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002463 dev_dbg(&dev->dev, "DCR1 Writing success status%d\n", status);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002464
2465 Data = 0x24;
Alan Cox880af9d2008-07-22 11:16:12 +01002466 status = mos7840_set_reg_sync(serial->port[i],
2467 (__u16) (mos7840_port->DcrRegOffset + 2), Data);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002468 if (status < 0) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002469 dev_dbg(&dev->dev, "Writing DCR2 failed status-0x%x\n", status);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002470 break;
2471 } else
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002472 dev_dbg(&dev->dev, "DCR2 Writing success status%d\n", status);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002473
Alan Cox880af9d2008-07-22 11:16:12 +01002474 /* write values in clkstart0x0 and clkmulti 0x20 */
Paul B Schroeder3f542972006-08-31 19:41:47 -05002475 Data = 0x0;
Alan Cox880af9d2008-07-22 11:16:12 +01002476 status = mos7840_set_reg_sync(serial->port[i],
Paul B Schroeder3f542972006-08-31 19:41:47 -05002477 CLK_START_VALUE_REGISTER, Data);
2478 if (status < 0) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002479 dev_dbg(&dev->dev, "Writing CLK_START_VALUE_REGISTER failed status-0x%x\n", status);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002480 break;
2481 } else
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002482 dev_dbg(&dev->dev, "CLK_START_VALUE_REGISTER Writing success status%d\n", status);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002483
2484 Data = 0x20;
Alan Cox880af9d2008-07-22 11:16:12 +01002485 status = mos7840_set_reg_sync(serial->port[i],
2486 CLK_MULTI_REGISTER, Data);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002487 if (status < 0) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002488 dev_dbg(&dev->dev, "Writing CLK_MULTI_REGISTER failed status-0x%x\n", status);
Oliver Neukum0de9a702007-03-16 20:28:28 +01002489 goto error;
Paul B Schroeder3f542972006-08-31 19:41:47 -05002490 } else
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002491 dev_dbg(&dev->dev, "CLK_MULTI_REGISTER Writing success status%d\n", status);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002492
Alan Cox880af9d2008-07-22 11:16:12 +01002493 /* write value 0x0 to scratchpad register */
Paul B Schroeder3f542972006-08-31 19:41:47 -05002494 Data = 0x00;
Alan Cox880af9d2008-07-22 11:16:12 +01002495 status = mos7840_set_uart_reg(serial->port[i],
2496 SCRATCH_PAD_REGISTER, Data);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002497 if (status < 0) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002498 dev_dbg(&dev->dev, "Writing SCRATCH_PAD_REGISTER failed status-0x%x\n", status);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002499 break;
2500 } else
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002501 dev_dbg(&dev->dev, "SCRATCH_PAD_REGISTER Writing success status%d\n", status);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002502
Alan Cox880af9d2008-07-22 11:16:12 +01002503 /* Zero Length flag register */
Paul B Schroeder3f542972006-08-31 19:41:47 -05002504 if ((mos7840_port->port_num != 1)
Oliver Neukum0de9a702007-03-16 20:28:28 +01002505 && (serial->num_ports == 2)) {
Paul B Schroeder3f542972006-08-31 19:41:47 -05002506
2507 Data = 0xff;
Paul B Schroeder3f542972006-08-31 19:41:47 -05002508 status = mos7840_set_reg_sync(serial->port[i],
Alan Cox880af9d2008-07-22 11:16:12 +01002509 (__u16) (ZLP_REG1 +
2510 ((__u16)mos7840_port->port_num)), Data);
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002511 dev_dbg(&dev->dev, "ZLIP offset %x\n",
2512 (__u16)(ZLP_REG1 + ((__u16) mos7840_port->port_num)));
Paul B Schroeder3f542972006-08-31 19:41:47 -05002513 if (status < 0) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002514 dev_dbg(&dev->dev, "Writing ZLP_REG%d failed status-0x%x\n", i + 2, status);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002515 break;
2516 } else
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002517 dev_dbg(&dev->dev, "ZLP_REG%d Writing success status%d\n", i + 2, status);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002518 } else {
2519 Data = 0xff;
Paul B Schroeder3f542972006-08-31 19:41:47 -05002520 status = mos7840_set_reg_sync(serial->port[i],
Alan Cox880af9d2008-07-22 11:16:12 +01002521 (__u16) (ZLP_REG1 +
2522 ((__u16)mos7840_port->port_num) - 0x1), Data);
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002523 dev_dbg(&dev->dev, "ZLIP offset %x\n",
2524 (__u16)(ZLP_REG1 + ((__u16) mos7840_port->port_num) - 0x1));
Paul B Schroeder3f542972006-08-31 19:41:47 -05002525 if (status < 0) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002526 dev_dbg(&dev->dev, "Writing ZLP_REG%d failed status-0x%x\n", i + 1, status);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002527 break;
2528 } else
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002529 dev_dbg(&dev->dev, "ZLP_REG%d Writing success status%d\n", i + 1, status);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002530
2531 }
Oliver Neukum0de9a702007-03-16 20:28:28 +01002532 mos7840_port->control_urb = usb_alloc_urb(0, GFP_KERNEL);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002533 mos7840_port->ctrl_buf = kmalloc(16, GFP_KERNEL);
Alan Cox880af9d2008-07-22 11:16:12 +01002534 mos7840_port->dr = kmalloc(sizeof(struct usb_ctrlrequest),
2535 GFP_KERNEL);
2536 if (!mos7840_port->control_urb || !mos7840_port->ctrl_buf ||
2537 !mos7840_port->dr) {
Oliver Neukum0de9a702007-03-16 20:28:28 +01002538 status = -ENOMEM;
2539 goto error;
2540 }
Donald0eafe4d2012-04-19 15:00:45 +08002541
2542 mos7840_port->has_led = false;
2543
2544 /* Initialize LED timers */
2545 if (device_type == MOSCHIP_DEVICE_ID_7810) {
2546 mos7840_port->has_led = true;
2547
2548 init_timer(&mos7840_port->led_timer1);
2549 mos7840_port->led_timer1.function = mos7840_led_off;
2550 mos7840_port->led_timer1.expires =
2551 jiffies + msecs_to_jiffies(LED_ON_MS);
2552 mos7840_port->led_timer1.data =
2553 (unsigned long)mos7840_port;
2554
2555 init_timer(&mos7840_port->led_timer2);
2556 mos7840_port->led_timer2.function =
2557 mos7840_led_flag_off;
2558 mos7840_port->led_timer2.expires =
2559 jiffies + msecs_to_jiffies(LED_OFF_MS);
2560 mos7840_port->led_timer2.data =
2561 (unsigned long)mos7840_port;
2562
2563 mos7840_port->led_flag = false;
2564
2565 /* Turn off LED */
2566 mos7840_set_led_sync(serial->port[i],
2567 MODEM_CONTROL_REGISTER, 0x0300);
2568 }
Paul B Schroeder3f542972006-08-31 19:41:47 -05002569 }
2570
Alan Cox880af9d2008-07-22 11:16:12 +01002571 /* Zero Length flag enable */
Paul B Schroeder3f542972006-08-31 19:41:47 -05002572 Data = 0x0f;
Paul B Schroeder3f542972006-08-31 19:41:47 -05002573 status = mos7840_set_reg_sync(serial->port[0], ZLP_REG5, Data);
2574 if (status < 0) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002575 dev_dbg(&dev->dev, "Writing ZLP_REG5 failed status-0x%x\n", status);
Roel Kluin7ced46c2007-10-27 03:36:37 +02002576 goto error;
Paul B Schroeder3f542972006-08-31 19:41:47 -05002577 } else
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002578 dev_dbg(&dev->dev, "ZLP_REG5 Writing success status%d\n", status);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002579
2580 /* setting configuration feature to one */
2581 usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
Mark Ferrell1e658482012-07-24 13:38:31 -05002582 (__u8) 0x03, 0x00, 0x01, 0x00, NULL, 0x00, MOS_WDR_TIMEOUT);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002583 return 0;
Oliver Neukum0de9a702007-03-16 20:28:28 +01002584error:
2585 for (/* nothing */; i >= 0; i--) {
2586 mos7840_port = mos7840_get_port_private(serial->port[i]);
2587
2588 kfree(mos7840_port->dr);
2589 kfree(mos7840_port->ctrl_buf);
2590 usb_free_urb(mos7840_port->control_urb);
2591 kfree(mos7840_port);
2592 serial->port[i] = NULL;
2593 }
2594 return status;
Paul B Schroeder3f542972006-08-31 19:41:47 -05002595}
2596
2597/****************************************************************************
Alan Sternf9c99bb2009-06-02 11:53:55 -04002598 * mos7840_disconnect
Paul B Schroeder3f542972006-08-31 19:41:47 -05002599 * This function is called whenever the device is removed from the usb bus.
2600 ****************************************************************************/
2601
Alan Sternf9c99bb2009-06-02 11:53:55 -04002602static void mos7840_disconnect(struct usb_serial *serial)
Paul B Schroeder3f542972006-08-31 19:41:47 -05002603{
2604 int i;
Oliver Neukum0de9a702007-03-16 20:28:28 +01002605 unsigned long flags;
Paul B Schroeder3f542972006-08-31 19:41:47 -05002606 struct moschip_port *mos7840_port;
Paul B Schroeder3f542972006-08-31 19:41:47 -05002607
Alan Cox880af9d2008-07-22 11:16:12 +01002608 /* check for the ports to be closed,close the ports and disconnect */
Paul B Schroeder3f542972006-08-31 19:41:47 -05002609
2610 /* free private structure allocated for serial port *
2611 * stop reads and writes on all ports */
2612
2613 for (i = 0; i < serial->num_ports; ++i) {
2614 mos7840_port = mos7840_get_port_private(serial->port[i]);
Tony Cook37768ad2009-04-18 22:42:18 +09302615 if (mos7840_port) {
2616 spin_lock_irqsave(&mos7840_port->pool_lock, flags);
2617 mos7840_port->zombie = 1;
2618 spin_unlock_irqrestore(&mos7840_port->pool_lock, flags);
2619 usb_kill_urb(mos7840_port->control_urb);
Alan Sternf9c99bb2009-06-02 11:53:55 -04002620 }
2621 }
Alan Sternf9c99bb2009-06-02 11:53:55 -04002622}
2623
2624/****************************************************************************
2625 * mos7840_release
2626 * This function is called when the usb_serial structure is freed.
2627 ****************************************************************************/
2628
2629static void mos7840_release(struct usb_serial *serial)
2630{
2631 int i;
2632 struct moschip_port *mos7840_port;
Alan Sternf9c99bb2009-06-02 11:53:55 -04002633
Alan Sternf9c99bb2009-06-02 11:53:55 -04002634 /* check for the ports to be closed,close the ports and disconnect */
2635
2636 /* free private structure allocated for serial port *
2637 * stop reads and writes on all ports */
2638
2639 for (i = 0; i < serial->num_ports; ++i) {
2640 mos7840_port = mos7840_get_port_private(serial->port[i]);
Alan Sternf9c99bb2009-06-02 11:53:55 -04002641 if (mos7840_port) {
Donald0eafe4d2012-04-19 15:00:45 +08002642 if (mos7840_port->has_led) {
2643 /* Turn off LED */
2644 mos7840_set_led_sync(mos7840_port->port,
2645 MODEM_CONTROL_REGISTER, 0x0300);
2646
2647 del_timer_sync(&mos7840_port->led_timer1);
2648 del_timer_sync(&mos7840_port->led_timer2);
2649 }
Tony Cook37768ad2009-04-18 22:42:18 +09302650 kfree(mos7840_port->ctrl_buf);
2651 kfree(mos7840_port->dr);
2652 kfree(mos7840_port);
2653 }
Paul B Schroeder3f542972006-08-31 19:41:47 -05002654 }
Paul B Schroeder3f542972006-08-31 19:41:47 -05002655}
2656
2657static struct usb_serial_driver moschip7840_4port_device = {
2658 .driver = {
2659 .owner = THIS_MODULE,
2660 .name = "mos7840",
2661 },
2662 .description = DRIVER_DESC,
Greg Kroah-Hartman68e24112012-05-08 15:46:14 -07002663 .id_table = id_table,
Paul B Schroeder3f542972006-08-31 19:41:47 -05002664 .num_ports = 4,
Paul B Schroeder3f542972006-08-31 19:41:47 -05002665 .open = mos7840_open,
2666 .close = mos7840_close,
2667 .write = mos7840_write,
2668 .write_room = mos7840_write_room,
2669 .chars_in_buffer = mos7840_chars_in_buffer,
2670 .throttle = mos7840_throttle,
2671 .unthrottle = mos7840_unthrottle,
2672 .calc_num_ports = mos7840_calc_num_ports,
2673#ifdef MCSSerialProbe
2674 .probe = mos7840_serial_probe,
2675#endif
2676 .ioctl = mos7840_ioctl,
2677 .set_termios = mos7840_set_termios,
2678 .break_ctl = mos7840_break,
2679 .tiocmget = mos7840_tiocmget,
2680 .tiocmset = mos7840_tiocmset,
Alan Cox0bca1b92010-09-16 18:21:40 +01002681 .get_icount = mos7840_get_icount,
Paul B Schroeder3f542972006-08-31 19:41:47 -05002682 .attach = mos7840_startup,
Alan Sternf9c99bb2009-06-02 11:53:55 -04002683 .disconnect = mos7840_disconnect,
2684 .release = mos7840_release,
Paul B Schroeder3f542972006-08-31 19:41:47 -05002685 .read_bulk_callback = mos7840_bulk_in_callback,
2686 .read_int_callback = mos7840_interrupt_callback,
2687};
2688
Alan Stern4d2a7af2012-02-23 14:57:09 -05002689static struct usb_serial_driver * const serial_drivers[] = {
2690 &moschip7840_4port_device, NULL
2691};
2692
Greg Kroah-Hartman68e24112012-05-08 15:46:14 -07002693module_usb_serial_driver(serial_drivers, id_table);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002694
Paul B Schroeder3f542972006-08-31 19:41:47 -05002695MODULE_DESCRIPTION(DRIVER_DESC);
2696MODULE_LICENSE("GPL");
2697
2698module_param(debug, bool, S_IRUGO | S_IWUSR);
2699MODULE_PARM_DESC(debug, "Debug enabled or not");