blob: f2c4bb709747a546406184cccf6c08d42e192753 [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 */
221 __u8 shadowLCR; /* last LCR value received */
222 __u8 shadowMCR; /* last MCR value received */
223 char open;
Oliver Neukum0de9a702007-03-16 20:28:28 +0100224 char open_ports;
225 char zombie;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500226 wait_queue_head_t wait_chase; /* for handling sleeping while waiting for chase to finish */
227 wait_queue_head_t delta_msr_wait; /* for handling sleeping while waiting for msr change to happen */
228 int delta_msr_cond;
229 struct async_icount icount;
230 struct usb_serial_port *port; /* loop back to the owner of this object */
231
Alan Cox880af9d2008-07-22 11:16:12 +0100232 /* Offsets */
Paul B Schroeder3f542972006-08-31 19:41:47 -0500233 __u8 SpRegOffset;
234 __u8 ControlRegOffset;
235 __u8 DcrRegOffset;
Alan Cox880af9d2008-07-22 11:16:12 +0100236 /* for processing control URBS in interrupt context */
Paul B Schroeder3f542972006-08-31 19:41:47 -0500237 struct urb *control_urb;
Oliver Neukum0de9a702007-03-16 20:28:28 +0100238 struct usb_ctrlrequest *dr;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500239 char *ctrl_buf;
240 int MsrLsr;
241
Oliver Neukum0de9a702007-03-16 20:28:28 +0100242 spinlock_t pool_lock;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500243 struct urb *write_urb_pool[NUM_URBS];
Oliver Neukum0de9a702007-03-16 20:28:28 +0100244 char busy[NUM_URBS];
Greg Kroah-Hartman50de36f2008-12-10 16:00:30 -0800245 bool read_urb_busy;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500246
Donald0eafe4d2012-04-19 15:00:45 +0800247 /* For device(s) with LED indicator */
248 bool has_led;
249 bool led_flag;
250 struct timer_list led_timer1; /* Timer for LED on */
251 struct timer_list led_timer2; /* Timer for LED off */
252};
Paul B Schroeder3f542972006-08-31 19:41:47 -0500253
Paul B Schroeder3f542972006-08-31 19:41:47 -0500254/*
255 * mos7840_set_reg_sync
256 * To set the Control register by calling usb_fill_control_urb function
257 * by passing usb_sndctrlpipe function as parameter.
258 */
259
260static int mos7840_set_reg_sync(struct usb_serial_port *port, __u16 reg,
261 __u16 val)
262{
263 struct usb_device *dev = port->serial->dev;
264 val = val & 0x00ff;
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700265 dev_dbg(&port->dev, "mos7840_set_reg_sync offset is %x, value %x\n", reg, val);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500266
267 return usb_control_msg(dev, usb_sndctrlpipe(dev, 0), MCS_WRREQ,
268 MCS_WR_RTYPE, val, reg, NULL, 0,
269 MOS_WDR_TIMEOUT);
270}
271
272/*
273 * mos7840_get_reg_sync
274 * To set the Uart register by calling usb_fill_control_urb function by
275 * passing usb_rcvctrlpipe function as parameter.
276 */
277
278static int mos7840_get_reg_sync(struct usb_serial_port *port, __u16 reg,
Alan Cox880af9d2008-07-22 11:16:12 +0100279 __u16 *val)
Paul B Schroeder3f542972006-08-31 19:41:47 -0500280{
281 struct usb_device *dev = port->serial->dev;
282 int ret = 0;
Johan Hovold9e221a32009-12-28 23:01:55 +0100283 u8 *buf;
284
285 buf = kmalloc(VENDOR_READ_LENGTH, GFP_KERNEL);
286 if (!buf)
287 return -ENOMEM;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500288
289 ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), MCS_RDREQ,
Johan Hovold9e221a32009-12-28 23:01:55 +0100290 MCS_RD_RTYPE, 0, reg, buf, VENDOR_READ_LENGTH,
Paul B Schroeder3f542972006-08-31 19:41:47 -0500291 MOS_WDR_TIMEOUT);
Johan Hovold9e221a32009-12-28 23:01:55 +0100292 *val = buf[0];
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700293 dev_dbg(&port->dev, "%s offset is %x, return val %x\n", __func__, reg, *val);
Johan Hovold9e221a32009-12-28 23:01:55 +0100294
295 kfree(buf);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500296 return ret;
297}
298
299/*
300 * mos7840_set_uart_reg
301 * To set the Uart register by calling usb_fill_control_urb function by
302 * passing usb_sndctrlpipe function as parameter.
303 */
304
305static int mos7840_set_uart_reg(struct usb_serial_port *port, __u16 reg,
306 __u16 val)
307{
308
309 struct usb_device *dev = port->serial->dev;
310 val = val & 0x00ff;
Alan Cox880af9d2008-07-22 11:16:12 +0100311 /* For the UART control registers, the application number need
312 to be Or'ed */
Oliver Neukum0de9a702007-03-16 20:28:28 +0100313 if (port->serial->num_ports == 4) {
Alan Cox880af9d2008-07-22 11:16:12 +0100314 val |= (((__u16) port->number -
315 (__u16) (port->serial->minor)) + 1) << 8;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500316 } else {
317 if (((__u16) port->number - (__u16) (port->serial->minor)) == 0) {
Alan Cox880af9d2008-07-22 11:16:12 +0100318 val |= (((__u16) port->number -
Paul B Schroeder3f542972006-08-31 19:41:47 -0500319 (__u16) (port->serial->minor)) + 1) << 8;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500320 } else {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700321 val |= (((__u16) port->number -
Paul B Schroeder3f542972006-08-31 19:41:47 -0500322 (__u16) (port->serial->minor)) + 2) << 8;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500323 }
324 }
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700325 dev_dbg(&port->dev, "%s application number is %x\n", __func__, val);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500326 return usb_control_msg(dev, usb_sndctrlpipe(dev, 0), MCS_WRREQ,
327 MCS_WR_RTYPE, val, reg, NULL, 0,
328 MOS_WDR_TIMEOUT);
329
330}
331
332/*
333 * mos7840_get_uart_reg
334 * To set the Control register by calling usb_fill_control_urb function
335 * by passing usb_rcvctrlpipe function as parameter.
336 */
337static int mos7840_get_uart_reg(struct usb_serial_port *port, __u16 reg,
Alan Cox880af9d2008-07-22 11:16:12 +0100338 __u16 *val)
Paul B Schroeder3f542972006-08-31 19:41:47 -0500339{
340 struct usb_device *dev = port->serial->dev;
341 int ret = 0;
342 __u16 Wval;
Johan Hovold9e221a32009-12-28 23:01:55 +0100343 u8 *buf;
344
345 buf = kmalloc(VENDOR_READ_LENGTH, GFP_KERNEL);
346 if (!buf)
347 return -ENOMEM;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500348
Alan Cox880af9d2008-07-22 11:16:12 +0100349 /* Wval is same as application number */
Oliver Neukum0de9a702007-03-16 20:28:28 +0100350 if (port->serial->num_ports == 4) {
Paul B Schroeder3f542972006-08-31 19:41:47 -0500351 Wval =
352 (((__u16) port->number - (__u16) (port->serial->minor)) +
353 1) << 8;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500354 } else {
355 if (((__u16) port->number - (__u16) (port->serial->minor)) == 0) {
Alan Cox880af9d2008-07-22 11:16:12 +0100356 Wval = (((__u16) port->number -
Paul B Schroeder3f542972006-08-31 19:41:47 -0500357 (__u16) (port->serial->minor)) + 1) << 8;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500358 } else {
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)) + 2) << 8;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500361 }
362 }
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700363 dev_dbg(&port->dev, "%s application number is %x\n", __func__, Wval);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500364 ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), MCS_RDREQ,
Johan Hovold9e221a32009-12-28 23:01:55 +0100365 MCS_RD_RTYPE, Wval, reg, buf, VENDOR_READ_LENGTH,
Paul B Schroeder3f542972006-08-31 19:41:47 -0500366 MOS_WDR_TIMEOUT);
Johan Hovold9e221a32009-12-28 23:01:55 +0100367 *val = buf[0];
368
369 kfree(buf);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500370 return ret;
371}
372
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700373static void mos7840_dump_serial_port(struct usb_serial_port *port,
374 struct moschip_port *mos7840_port)
Paul B Schroeder3f542972006-08-31 19:41:47 -0500375{
376
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700377 dev_dbg(&port->dev, "SpRegOffset is %2x\n", mos7840_port->SpRegOffset);
378 dev_dbg(&port->dev, "ControlRegOffset is %2x\n", mos7840_port->ControlRegOffset);
379 dev_dbg(&port->dev, "DCRRegOffset is %2x\n", mos7840_port->DcrRegOffset);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500380
381}
382
383/************************************************************************/
384/************************************************************************/
385/* I N T E R F A C E F U N C T I O N S */
386/* I N T E R F A C E F U N C T I O N S */
387/************************************************************************/
388/************************************************************************/
389
390static inline void mos7840_set_port_private(struct usb_serial_port *port,
391 struct moschip_port *data)
392{
393 usb_set_serial_port_data(port, (void *)data);
394}
395
396static inline struct moschip_port *mos7840_get_port_private(struct
397 usb_serial_port
398 *port)
399{
400 return (struct moschip_port *)usb_get_serial_port_data(port);
401}
402
Oliver Neukum0de9a702007-03-16 20:28:28 +0100403static void mos7840_handle_new_msr(struct moschip_port *port, __u8 new_msr)
Paul B Schroeder3f542972006-08-31 19:41:47 -0500404{
405 struct moschip_port *mos7840_port;
406 struct async_icount *icount;
407 mos7840_port = port;
408 icount = &mos7840_port->icount;
409 if (new_msr &
410 (MOS_MSR_DELTA_CTS | MOS_MSR_DELTA_DSR | MOS_MSR_DELTA_RI |
411 MOS_MSR_DELTA_CD)) {
412 icount = &mos7840_port->icount;
413
414 /* update input line counters */
415 if (new_msr & MOS_MSR_DELTA_CTS) {
416 icount->cts++;
Oliver Neukum0de9a702007-03-16 20:28:28 +0100417 smp_wmb();
Paul B Schroeder3f542972006-08-31 19:41:47 -0500418 }
419 if (new_msr & MOS_MSR_DELTA_DSR) {
420 icount->dsr++;
Oliver Neukum0de9a702007-03-16 20:28:28 +0100421 smp_wmb();
Paul B Schroeder3f542972006-08-31 19:41:47 -0500422 }
423 if (new_msr & MOS_MSR_DELTA_CD) {
424 icount->dcd++;
Oliver Neukum0de9a702007-03-16 20:28:28 +0100425 smp_wmb();
Paul B Schroeder3f542972006-08-31 19:41:47 -0500426 }
427 if (new_msr & MOS_MSR_DELTA_RI) {
428 icount->rng++;
Oliver Neukum0de9a702007-03-16 20:28:28 +0100429 smp_wmb();
Paul B Schroeder3f542972006-08-31 19:41:47 -0500430 }
431 }
Paul B Schroeder3f542972006-08-31 19:41:47 -0500432}
433
Oliver Neukum0de9a702007-03-16 20:28:28 +0100434static void mos7840_handle_new_lsr(struct moschip_port *port, __u8 new_lsr)
Paul B Schroeder3f542972006-08-31 19:41:47 -0500435{
436 struct async_icount *icount;
437
Paul B Schroeder3f542972006-08-31 19:41:47 -0500438 if (new_lsr & SERIAL_LSR_BI) {
Alan Cox880af9d2008-07-22 11:16:12 +0100439 /*
440 * Parity and Framing errors only count if they
441 * occur exclusive of a break being
442 * received.
443 */
Paul B Schroeder3f542972006-08-31 19:41:47 -0500444 new_lsr &= (__u8) (SERIAL_LSR_OE | SERIAL_LSR_BI);
445 }
446
447 /* update input line counters */
448 icount = &port->icount;
449 if (new_lsr & SERIAL_LSR_BI) {
450 icount->brk++;
Oliver Neukum0de9a702007-03-16 20:28:28 +0100451 smp_wmb();
Paul B Schroeder3f542972006-08-31 19:41:47 -0500452 }
453 if (new_lsr & SERIAL_LSR_OE) {
454 icount->overrun++;
Oliver Neukum0de9a702007-03-16 20:28:28 +0100455 smp_wmb();
Paul B Schroeder3f542972006-08-31 19:41:47 -0500456 }
457 if (new_lsr & SERIAL_LSR_PE) {
458 icount->parity++;
Oliver Neukum0de9a702007-03-16 20:28:28 +0100459 smp_wmb();
Paul B Schroeder3f542972006-08-31 19:41:47 -0500460 }
461 if (new_lsr & SERIAL_LSR_FE) {
462 icount->frame++;
Oliver Neukum0de9a702007-03-16 20:28:28 +0100463 smp_wmb();
Paul B Schroeder3f542972006-08-31 19:41:47 -0500464 }
Paul B Schroeder3f542972006-08-31 19:41:47 -0500465}
466
467/************************************************************************/
468/************************************************************************/
469/* U S B C A L L B A C K F U N C T I O N S */
470/* U S B C A L L B A C K F U N C T I O N S */
471/************************************************************************/
472/************************************************************************/
473
David Howells7d12e782006-10-05 14:55:46 +0100474static void mos7840_control_callback(struct urb *urb)
Paul B Schroeder3f542972006-08-31 19:41:47 -0500475{
476 unsigned char *data;
477 struct moschip_port *mos7840_port;
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700478 struct device *dev = &urb->dev->dev;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500479 __u8 regval = 0x0;
Greg Kroah-Hartman0643c722007-06-15 15:44:13 -0700480 int status = urb->status;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500481
Ming Leicdc97792008-02-24 18:41:47 +0800482 mos7840_port = urb->context;
Oliver Neukum0de9a702007-03-16 20:28:28 +0100483
Greg Kroah-Hartman0643c722007-06-15 15:44:13 -0700484 switch (status) {
Paul B Schroeder3f542972006-08-31 19:41:47 -0500485 case 0:
486 /* success */
487 break;
488 case -ECONNRESET:
489 case -ENOENT:
490 case -ESHUTDOWN:
491 /* this urb is terminated, clean up */
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700492 dev_dbg(dev, "%s - urb shutting down with status: %d\n", __func__, status);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500493 return;
494 default:
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700495 dev_dbg(dev, "%s - nonzero urb status received: %d\n", __func__, status);
Johan Hovold28c3ae92012-10-25 18:56:32 +0200496 return;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500497 }
498
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700499 dev_dbg(dev, "%s urb buffer size is %d\n", __func__, urb->actual_length);
500 dev_dbg(dev, "%s mos7840_port->MsrLsr is %d port %d\n", __func__,
501 mos7840_port->MsrLsr, mos7840_port->port_num);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500502 data = urb->transfer_buffer;
503 regval = (__u8) data[0];
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700504 dev_dbg(dev, "%s data is %x\n", __func__, regval);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500505 if (mos7840_port->MsrLsr == 0)
506 mos7840_handle_new_msr(mos7840_port, regval);
507 else if (mos7840_port->MsrLsr == 1)
508 mos7840_handle_new_lsr(mos7840_port, regval);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500509}
510
511static int mos7840_get_reg(struct moschip_port *mcs, __u16 Wval, __u16 reg,
Alan Cox880af9d2008-07-22 11:16:12 +0100512 __u16 *val)
Paul B Schroeder3f542972006-08-31 19:41:47 -0500513{
514 struct usb_device *dev = mcs->port->serial->dev;
Oliver Neukum0de9a702007-03-16 20:28:28 +0100515 struct usb_ctrlrequest *dr = mcs->dr;
516 unsigned char *buffer = mcs->ctrl_buf;
517 int ret;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500518
Paul B Schroeder3f542972006-08-31 19:41:47 -0500519 dr->bRequestType = MCS_RD_RTYPE;
520 dr->bRequest = MCS_RDREQ;
Alan Cox880af9d2008-07-22 11:16:12 +0100521 dr->wValue = cpu_to_le16(Wval); /* 0 */
Paul B Schroeder3f542972006-08-31 19:41:47 -0500522 dr->wIndex = cpu_to_le16(reg);
523 dr->wLength = cpu_to_le16(2);
524
525 usb_fill_control_urb(mcs->control_urb, dev, usb_rcvctrlpipe(dev, 0),
526 (unsigned char *)dr, buffer, 2,
527 mos7840_control_callback, mcs);
528 mcs->control_urb->transfer_buffer_length = 2;
529 ret = usb_submit_urb(mcs->control_urb, GFP_ATOMIC);
530 return ret;
531}
532
Donald0eafe4d2012-04-19 15:00:45 +0800533static void mos7840_set_led_callback(struct urb *urb)
534{
535 switch (urb->status) {
536 case 0:
537 /* Success */
538 break;
539 case -ECONNRESET:
540 case -ENOENT:
541 case -ESHUTDOWN:
542 /* This urb is terminated, clean up */
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700543 dev_dbg(&urb->dev->dev, "%s - urb shutting down with status: %d",
544 __func__, urb->status);
Donald0eafe4d2012-04-19 15:00:45 +0800545 break;
546 default:
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700547 dev_dbg(&urb->dev->dev, "%s - nonzero urb status received: %d",
548 __func__, urb->status);
Donald0eafe4d2012-04-19 15:00:45 +0800549 }
550}
551
552static void mos7840_set_led_async(struct moschip_port *mcs, __u16 wval,
553 __u16 reg)
554{
555 struct usb_device *dev = mcs->port->serial->dev;
556 struct usb_ctrlrequest *dr = mcs->dr;
557
558 dr->bRequestType = MCS_WR_RTYPE;
559 dr->bRequest = MCS_WRREQ;
560 dr->wValue = cpu_to_le16(wval);
561 dr->wIndex = cpu_to_le16(reg);
562 dr->wLength = cpu_to_le16(0);
563
564 usb_fill_control_urb(mcs->control_urb, dev, usb_sndctrlpipe(dev, 0),
565 (unsigned char *)dr, NULL, 0, mos7840_set_led_callback, NULL);
566
567 usb_submit_urb(mcs->control_urb, GFP_ATOMIC);
568}
569
570static void mos7840_set_led_sync(struct usb_serial_port *port, __u16 reg,
571 __u16 val)
572{
573 struct usb_device *dev = port->serial->dev;
574
575 usb_control_msg(dev, usb_sndctrlpipe(dev, 0), MCS_WRREQ, MCS_WR_RTYPE,
576 val, reg, NULL, 0, MOS_WDR_TIMEOUT);
577}
578
579static void mos7840_led_off(unsigned long arg)
580{
581 struct moschip_port *mcs = (struct moschip_port *) arg;
582
583 /* Turn off LED */
584 mos7840_set_led_async(mcs, 0x0300, MODEM_CONTROL_REGISTER);
585 mod_timer(&mcs->led_timer2,
586 jiffies + msecs_to_jiffies(LED_OFF_MS));
587}
588
589static void mos7840_led_flag_off(unsigned long arg)
590{
591 struct moschip_port *mcs = (struct moschip_port *) arg;
592
593 mcs->led_flag = false;
594}
595
Paul B Schroeder3f542972006-08-31 19:41:47 -0500596/*****************************************************************************
597 * mos7840_interrupt_callback
598 * this is the callback function for when we have received data on the
599 * interrupt endpoint.
600 *****************************************************************************/
601
David Howells7d12e782006-10-05 14:55:46 +0100602static void mos7840_interrupt_callback(struct urb *urb)
Paul B Schroeder3f542972006-08-31 19:41:47 -0500603{
604 int result;
605 int length;
606 struct moschip_port *mos7840_port;
607 struct usb_serial *serial;
608 __u16 Data;
609 unsigned char *data;
610 __u8 sp[5], st;
Oliver Neukum0de9a702007-03-16 20:28:28 +0100611 int i, rv = 0;
612 __u16 wval, wreg = 0;
Greg Kroah-Hartman0643c722007-06-15 15:44:13 -0700613 int status = urb->status;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500614
Greg Kroah-Hartman0643c722007-06-15 15:44:13 -0700615 switch (status) {
Paul B Schroeder3f542972006-08-31 19:41:47 -0500616 case 0:
617 /* success */
618 break;
619 case -ECONNRESET:
620 case -ENOENT:
621 case -ESHUTDOWN:
622 /* this urb is terminated, clean up */
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700623 dev_dbg(&urb->dev->dev, "%s - urb shutting down with status: %d\n",
624 __func__, status);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500625 return;
626 default:
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700627 dev_dbg(&urb->dev->dev, "%s - nonzero urb status received: %d\n",
628 __func__, status);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500629 goto exit;
630 }
631
632 length = urb->actual_length;
633 data = urb->transfer_buffer;
634
Ming Leicdc97792008-02-24 18:41:47 +0800635 serial = urb->context;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500636
637 /* Moschip get 5 bytes
638 * Byte 1 IIR Port 1 (port.number is 0)
639 * Byte 2 IIR Port 2 (port.number is 1)
640 * Byte 3 IIR Port 3 (port.number is 2)
641 * Byte 4 IIR Port 4 (port.number is 3)
642 * Byte 5 FIFO status for both */
643
644 if (length && length > 5) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700645 dev_dbg(&urb->dev->dev, "%s", "Wrong data !!!\n");
Paul B Schroeder3f542972006-08-31 19:41:47 -0500646 return;
647 }
648
649 sp[0] = (__u8) data[0];
650 sp[1] = (__u8) data[1];
651 sp[2] = (__u8) data[2];
652 sp[3] = (__u8) data[3];
653 st = (__u8) data[4];
654
655 for (i = 0; i < serial->num_ports; i++) {
656 mos7840_port = mos7840_get_port_private(serial->port[i]);
657 wval =
658 (((__u16) serial->port[i]->number -
659 (__u16) (serial->minor)) + 1) << 8;
660 if (mos7840_port->open) {
661 if (sp[i] & 0x01) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700662 dev_dbg(&urb->dev->dev, "SP%d No Interrupt !!!\n", i);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500663 } else {
664 switch (sp[i] & 0x0f) {
665 case SERIAL_IIR_RLS:
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700666 dev_dbg(&urb->dev->dev, "Serial Port %d: Receiver status error or \n", i);
667 dev_dbg(&urb->dev->dev, "address bit detected in 9-bit mode\n");
Paul B Schroeder3f542972006-08-31 19:41:47 -0500668 mos7840_port->MsrLsr = 1;
Oliver Neukum0de9a702007-03-16 20:28:28 +0100669 wreg = LINE_STATUS_REGISTER;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500670 break;
671 case SERIAL_IIR_MS:
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700672 dev_dbg(&urb->dev->dev, "Serial Port %d: Modem status change\n", i);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500673 mos7840_port->MsrLsr = 0;
Oliver Neukum0de9a702007-03-16 20:28:28 +0100674 wreg = MODEM_STATUS_REGISTER;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500675 break;
676 }
Oliver Neukum0de9a702007-03-16 20:28:28 +0100677 spin_lock(&mos7840_port->pool_lock);
678 if (!mos7840_port->zombie) {
679 rv = mos7840_get_reg(mos7840_port, wval, wreg, &Data);
680 } else {
681 spin_unlock(&mos7840_port->pool_lock);
682 return;
683 }
684 spin_unlock(&mos7840_port->pool_lock);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500685 }
686 }
687 }
Alan Cox880af9d2008-07-22 11:16:12 +0100688 if (!(rv < 0))
689 /* the completion handler for the control urb will resubmit */
Oliver Neukum0de9a702007-03-16 20:28:28 +0100690 return;
691exit:
Paul B Schroeder3f542972006-08-31 19:41:47 -0500692 result = usb_submit_urb(urb, GFP_ATOMIC);
693 if (result) {
694 dev_err(&urb->dev->dev,
695 "%s - Error %d submitting interrupt urb\n",
Harvey Harrison441b62c2008-03-03 16:08:34 -0800696 __func__, result);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500697 }
Paul B Schroeder3f542972006-08-31 19:41:47 -0500698}
699
700static int mos7840_port_paranoia_check(struct usb_serial_port *port,
701 const char *function)
702{
703 if (!port) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700704 pr_debug("%s - port == NULL\n", function);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500705 return -1;
706 }
707 if (!port->serial) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700708 pr_debug("%s - port->serial == NULL\n", function);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500709 return -1;
710 }
711
712 return 0;
713}
714
715/* Inline functions to check the sanity of a pointer that is passed to us */
716static int mos7840_serial_paranoia_check(struct usb_serial *serial,
717 const char *function)
718{
719 if (!serial) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700720 pr_debug("%s - serial == NULL\n", function);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500721 return -1;
722 }
723 if (!serial->type) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700724 pr_debug("%s - serial->type == NULL!\n", function);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500725 return -1;
726 }
727
728 return 0;
729}
730
731static struct usb_serial *mos7840_get_usb_serial(struct usb_serial_port *port,
732 const char *function)
733{
734 /* if no port was specified, or it fails a paranoia check */
735 if (!port ||
736 mos7840_port_paranoia_check(port, function) ||
737 mos7840_serial_paranoia_check(port->serial, function)) {
Alan Cox880af9d2008-07-22 11:16:12 +0100738 /* then say that we don't have a valid usb_serial thing,
739 * which will end up genrating -ENODEV return values */
Paul B Schroeder3f542972006-08-31 19:41:47 -0500740 return NULL;
741 }
742
743 return port->serial;
744}
745
746/*****************************************************************************
747 * mos7840_bulk_in_callback
748 * this is the callback function for when we have received data on the
749 * bulk in endpoint.
750 *****************************************************************************/
751
David Howells7d12e782006-10-05 14:55:46 +0100752static void mos7840_bulk_in_callback(struct urb *urb)
Paul B Schroeder3f542972006-08-31 19:41:47 -0500753{
Greg Kroah-Hartman0643c722007-06-15 15:44:13 -0700754 int retval;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500755 unsigned char *data;
756 struct usb_serial *serial;
757 struct usb_serial_port *port;
758 struct moschip_port *mos7840_port;
759 struct tty_struct *tty;
Greg Kroah-Hartman0643c722007-06-15 15:44:13 -0700760 int status = urb->status;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500761
Ming Leicdc97792008-02-24 18:41:47 +0800762 mos7840_port = urb->context;
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700763 if (!mos7840_port)
Greg Kroah-Hartman50de36f2008-12-10 16:00:30 -0800764 return;
Greg Kroah-Hartman50de36f2008-12-10 16:00:30 -0800765
766 if (status) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700767 dev_dbg(&urb->dev->dev, "nonzero read bulk status received: %d\n", status);
Greg Kroah-Hartman50de36f2008-12-10 16:00:30 -0800768 mos7840_port->read_urb_busy = false;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500769 return;
770 }
771
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700772 port = mos7840_port->port;
Harvey Harrison441b62c2008-03-03 16:08:34 -0800773 if (mos7840_port_paranoia_check(port, __func__)) {
Greg Kroah-Hartman50de36f2008-12-10 16:00:30 -0800774 mos7840_port->read_urb_busy = false;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500775 return;
776 }
777
Harvey Harrison441b62c2008-03-03 16:08:34 -0800778 serial = mos7840_get_usb_serial(port, __func__);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500779 if (!serial) {
Greg Kroah-Hartman50de36f2008-12-10 16:00:30 -0800780 mos7840_port->read_urb_busy = false;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500781 return;
782 }
783
Paul B Schroeder3f542972006-08-31 19:41:47 -0500784 data = urb->transfer_buffer;
Greg Kroah-Hartman59d33f22012-09-18 09:58:57 +0100785 usb_serial_debug_data(&port->dev, __func__, urb->actual_length, data);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500786
Paul B Schroeder3f542972006-08-31 19:41:47 -0500787 if (urb->actual_length) {
Alan Cox4a90f092008-10-13 10:39:46 +0100788 tty = tty_port_tty_get(&mos7840_port->port->port);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500789 if (tty) {
Paul B Schroeder3f542972006-08-31 19:41:47 -0500790 tty_insert_flip_string(tty, data, urb->actual_length);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500791 tty_flip_buffer_push(tty);
Alan Cox4a90f092008-10-13 10:39:46 +0100792 tty_kref_put(tty);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500793 }
794 mos7840_port->icount.rx += urb->actual_length;
Oliver Neukum0de9a702007-03-16 20:28:28 +0100795 smp_wmb();
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700796 dev_dbg(&port->dev, "mos7840_port->icount.rx is %d:\n", mos7840_port->icount.rx);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500797 }
798
799 if (!mos7840_port->read_urb) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700800 dev_dbg(&port->dev, "%s", "URB KILLED !!!\n");
Greg Kroah-Hartman50de36f2008-12-10 16:00:30 -0800801 mos7840_port->read_urb_busy = false;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500802 return;
803 }
804
Donald0eafe4d2012-04-19 15:00:45 +0800805 /* Turn on LED */
806 if (mos7840_port->has_led && !mos7840_port->led_flag) {
807 mos7840_port->led_flag = true;
808 mos7840_set_led_async(mos7840_port, 0x0301,
809 MODEM_CONTROL_REGISTER);
810 mod_timer(&mos7840_port->led_timer1,
811 jiffies + msecs_to_jiffies(LED_ON_MS));
812 }
Paul B Schroeder3f542972006-08-31 19:41:47 -0500813
Greg Kroah-Hartman50de36f2008-12-10 16:00:30 -0800814 mos7840_port->read_urb_busy = true;
Greg Kroah-Hartman0643c722007-06-15 15:44:13 -0700815 retval = usb_submit_urb(mos7840_port->read_urb, GFP_ATOMIC);
Oliver Neukum0de9a702007-03-16 20:28:28 +0100816
Greg Kroah-Hartman0643c722007-06-15 15:44:13 -0700817 if (retval) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700818 dev_dbg(&port->dev, "usb_submit_urb(read bulk) failed, retval = %d\n", retval);
Greg Kroah-Hartman50de36f2008-12-10 16:00:30 -0800819 mos7840_port->read_urb_busy = false;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500820 }
821}
822
823/*****************************************************************************
824 * mos7840_bulk_out_data_callback
Alan Cox880af9d2008-07-22 11:16:12 +0100825 * this is the callback function for when we have finished sending
826 * serial data on the bulk out endpoint.
Paul B Schroeder3f542972006-08-31 19:41:47 -0500827 *****************************************************************************/
828
David Howells7d12e782006-10-05 14:55:46 +0100829static void mos7840_bulk_out_data_callback(struct urb *urb)
Paul B Schroeder3f542972006-08-31 19:41:47 -0500830{
831 struct moschip_port *mos7840_port;
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700832 struct usb_serial_port *port;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500833 struct tty_struct *tty;
Greg Kroah-Hartman0643c722007-06-15 15:44:13 -0700834 int status = urb->status;
Oliver Neukum0de9a702007-03-16 20:28:28 +0100835 int i;
836
Ming Leicdc97792008-02-24 18:41:47 +0800837 mos7840_port = urb->context;
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700838 port = mos7840_port->port;
Oliver Neukum0de9a702007-03-16 20:28:28 +0100839 spin_lock(&mos7840_port->pool_lock);
840 for (i = 0; i < NUM_URBS; i++) {
841 if (urb == mos7840_port->write_urb_pool[i]) {
842 mos7840_port->busy[i] = 0;
843 break;
844 }
845 }
846 spin_unlock(&mos7840_port->pool_lock);
847
Greg Kroah-Hartman0643c722007-06-15 15:44:13 -0700848 if (status) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700849 dev_dbg(&port->dev, "nonzero write bulk status received:%d\n", status);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500850 return;
851 }
852
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700853 if (mos7840_port_paranoia_check(port, __func__))
Paul B Schroeder3f542972006-08-31 19:41:47 -0500854 return;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500855
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700856 tty = tty_port_tty_get(&port->port);
Jiri Slabyb963a842007-02-10 01:44:55 -0800857 if (tty && mos7840_port->open)
858 tty_wakeup(tty);
Alan Cox4a90f092008-10-13 10:39:46 +0100859 tty_kref_put(tty);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500860
861}
862
863/************************************************************************/
864/* 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 */
865/************************************************************************/
866#ifdef MCSSerialProbe
867static int mos7840_serial_probe(struct usb_serial *serial,
868 const struct usb_device_id *id)
869{
870
871 /*need to implement the mode_reg reading and updating\
872 structures usb_serial_ device_type\
873 (i.e num_ports, num_bulkin,bulkout etc) */
874 /* Also we can update the changes attach */
875 return 1;
876}
877#endif
878
879/*****************************************************************************
880 * mos7840_open
881 * this function is called by the tty driver when a port is opened
882 * If successful, we return 0
883 * Otherwise we return a negative error number.
884 *****************************************************************************/
885
Alan Coxa509a7e2009-09-19 13:13:26 -0700886static int mos7840_open(struct tty_struct *tty, struct usb_serial_port *port)
Paul B Schroeder3f542972006-08-31 19:41:47 -0500887{
888 int response;
889 int j;
890 struct usb_serial *serial;
891 struct urb *urb;
892 __u16 Data;
893 int status;
894 struct moschip_port *mos7840_port;
Oliver Neukum0de9a702007-03-16 20:28:28 +0100895 struct moschip_port *port0;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500896
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700897 if (mos7840_port_paranoia_check(port, __func__))
Paul B Schroeder3f542972006-08-31 19:41:47 -0500898 return -ENODEV;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500899
Paul B Schroeder3f542972006-08-31 19:41:47 -0500900 serial = port->serial;
901
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700902 if (mos7840_serial_paranoia_check(serial, __func__))
Paul B Schroeder3f542972006-08-31 19:41:47 -0500903 return -ENODEV;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500904
905 mos7840_port = mos7840_get_port_private(port);
Oliver Neukum0de9a702007-03-16 20:28:28 +0100906 port0 = mos7840_get_port_private(serial->port[0]);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500907
Oliver Neukum0de9a702007-03-16 20:28:28 +0100908 if (mos7840_port == NULL || port0 == NULL)
Paul B Schroeder3f542972006-08-31 19:41:47 -0500909 return -ENODEV;
910
911 usb_clear_halt(serial->dev, port->write_urb->pipe);
912 usb_clear_halt(serial->dev, port->read_urb->pipe);
Oliver Neukum0de9a702007-03-16 20:28:28 +0100913 port0->open_ports++;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500914
915 /* Initialising the write urb pool */
916 for (j = 0; j < NUM_URBS; ++j) {
Oliver Neukum0de9a702007-03-16 20:28:28 +0100917 urb = usb_alloc_urb(0, GFP_KERNEL);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500918 mos7840_port->write_urb_pool[j] = urb;
919
920 if (urb == NULL) {
Greg Kroah-Hartman194343d2008-08-20 16:56:34 -0700921 dev_err(&port->dev, "No more urbs???\n");
Paul B Schroeder3f542972006-08-31 19:41:47 -0500922 continue;
923 }
924
Alan Cox880af9d2008-07-22 11:16:12 +0100925 urb->transfer_buffer = kmalloc(URB_TRANSFER_BUFFER_SIZE,
926 GFP_KERNEL);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500927 if (!urb->transfer_buffer) {
Oliver Neukum0de9a702007-03-16 20:28:28 +0100928 usb_free_urb(urb);
929 mos7840_port->write_urb_pool[j] = NULL;
Greg Kroah-Hartman194343d2008-08-20 16:56:34 -0700930 dev_err(&port->dev,
931 "%s-out of memory for urb buffers.\n",
932 __func__);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500933 continue;
934 }
935 }
936
937/*****************************************************************************
938 * Initialize MCS7840 -- Write Init values to corresponding Registers
939 *
940 * Register Index
941 * 1 : IER
942 * 2 : FCR
943 * 3 : LCR
944 * 4 : MCR
945 *
946 * 0x08 : SP1/2 Control Reg
947 *****************************************************************************/
948
Alan Cox880af9d2008-07-22 11:16:12 +0100949 /* NEED to check the following Block */
Paul B Schroeder3f542972006-08-31 19:41:47 -0500950
Paul B Schroeder3f542972006-08-31 19:41:47 -0500951 Data = 0x0;
952 status = mos7840_get_reg_sync(port, mos7840_port->SpRegOffset, &Data);
953 if (status < 0) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700954 dev_dbg(&port->dev, "Reading Spreg failed\n");
Paul B Schroeder3f542972006-08-31 19:41:47 -0500955 return -1;
956 }
957 Data |= 0x80;
958 status = mos7840_set_reg_sync(port, mos7840_port->SpRegOffset, Data);
959 if (status < 0) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700960 dev_dbg(&port->dev, "writing Spreg failed\n");
Paul B Schroeder3f542972006-08-31 19:41:47 -0500961 return -1;
962 }
963
964 Data &= ~0x80;
965 status = mos7840_set_reg_sync(port, mos7840_port->SpRegOffset, Data);
966 if (status < 0) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700967 dev_dbg(&port->dev, "writing Spreg failed\n");
Paul B Schroeder3f542972006-08-31 19:41:47 -0500968 return -1;
969 }
Alan Cox880af9d2008-07-22 11:16:12 +0100970 /* End of block to be checked */
Paul B Schroeder3f542972006-08-31 19:41:47 -0500971
Paul B Schroeder3f542972006-08-31 19:41:47 -0500972 Data = 0x0;
Alan Cox880af9d2008-07-22 11:16:12 +0100973 status = mos7840_get_reg_sync(port, mos7840_port->ControlRegOffset,
974 &Data);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500975 if (status < 0) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700976 dev_dbg(&port->dev, "Reading Controlreg failed\n");
Paul B Schroeder3f542972006-08-31 19:41:47 -0500977 return -1;
978 }
Alan Cox880af9d2008-07-22 11:16:12 +0100979 Data |= 0x08; /* Driver done bit */
980 Data |= 0x20; /* rx_disable */
981 status = mos7840_set_reg_sync(port,
982 mos7840_port->ControlRegOffset, Data);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500983 if (status < 0) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700984 dev_dbg(&port->dev, "writing Controlreg failed\n");
Paul B Schroeder3f542972006-08-31 19:41:47 -0500985 return -1;
986 }
Alan Cox880af9d2008-07-22 11:16:12 +0100987 /* do register settings here */
988 /* Set all regs to the device default values. */
989 /***********************************
990 * First Disable all interrupts.
991 ***********************************/
Paul B Schroeder3f542972006-08-31 19:41:47 -0500992 Data = 0x00;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500993 status = mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data);
994 if (status < 0) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700995 dev_dbg(&port->dev, "disabling interrupts failed\n");
Paul B Schroeder3f542972006-08-31 19:41:47 -0500996 return -1;
997 }
Alan Cox880af9d2008-07-22 11:16:12 +0100998 /* Set FIFO_CONTROL_REGISTER to the default value */
Paul B Schroeder3f542972006-08-31 19:41:47 -0500999 Data = 0x00;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001000 status = mos7840_set_uart_reg(port, FIFO_CONTROL_REGISTER, Data);
1001 if (status < 0) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001002 dev_dbg(&port->dev, "Writing FIFO_CONTROL_REGISTER failed\n");
Paul B Schroeder3f542972006-08-31 19:41:47 -05001003 return -1;
1004 }
1005
1006 Data = 0xcf;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001007 status = mos7840_set_uart_reg(port, FIFO_CONTROL_REGISTER, Data);
1008 if (status < 0) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001009 dev_dbg(&port->dev, "Writing FIFO_CONTROL_REGISTER failed\n");
Paul B Schroeder3f542972006-08-31 19:41:47 -05001010 return -1;
1011 }
1012
1013 Data = 0x03;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001014 status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
1015 mos7840_port->shadowLCR = Data;
1016
1017 Data = 0x0b;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001018 status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
1019 mos7840_port->shadowMCR = Data;
1020
1021 Data = 0x00;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001022 status = mos7840_get_uart_reg(port, LINE_CONTROL_REGISTER, &Data);
1023 mos7840_port->shadowLCR = Data;
1024
Alan Cox880af9d2008-07-22 11:16:12 +01001025 Data |= SERIAL_LCR_DLAB; /* data latch enable in LCR 0x80 */
Paul B Schroeder3f542972006-08-31 19:41:47 -05001026 status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
1027
1028 Data = 0x0c;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001029 status = mos7840_set_uart_reg(port, DIVISOR_LATCH_LSB, Data);
1030
1031 Data = 0x0;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001032 status = mos7840_set_uart_reg(port, DIVISOR_LATCH_MSB, Data);
1033
1034 Data = 0x00;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001035 status = mos7840_get_uart_reg(port, LINE_CONTROL_REGISTER, &Data);
1036
1037 Data = Data & ~SERIAL_LCR_DLAB;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001038 status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
1039 mos7840_port->shadowLCR = Data;
1040
Alan Cox880af9d2008-07-22 11:16:12 +01001041 /* clearing Bulkin and Bulkout Fifo */
Paul B Schroeder3f542972006-08-31 19:41:47 -05001042 Data = 0x0;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001043 status = mos7840_get_reg_sync(port, mos7840_port->SpRegOffset, &Data);
1044
1045 Data = Data | 0x0c;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001046 status = mos7840_set_reg_sync(port, mos7840_port->SpRegOffset, Data);
1047
1048 Data = Data & ~0x0c;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001049 status = mos7840_set_reg_sync(port, mos7840_port->SpRegOffset, Data);
Alan Cox880af9d2008-07-22 11:16:12 +01001050 /* Finally enable all interrupts */
Paul B Schroeder3f542972006-08-31 19:41:47 -05001051 Data = 0x0c;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001052 status = mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data);
1053
Alan Cox880af9d2008-07-22 11:16:12 +01001054 /* clearing rx_disable */
Paul B Schroeder3f542972006-08-31 19:41:47 -05001055 Data = 0x0;
Alan Cox880af9d2008-07-22 11:16:12 +01001056 status = mos7840_get_reg_sync(port, mos7840_port->ControlRegOffset,
1057 &Data);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001058 Data = Data & ~0x20;
Alan Cox880af9d2008-07-22 11:16:12 +01001059 status = mos7840_set_reg_sync(port, mos7840_port->ControlRegOffset,
1060 Data);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001061
Alan Cox880af9d2008-07-22 11:16:12 +01001062 /* rx_negate */
Paul B Schroeder3f542972006-08-31 19:41:47 -05001063 Data = 0x0;
Alan Cox880af9d2008-07-22 11:16:12 +01001064 status = mos7840_get_reg_sync(port, mos7840_port->ControlRegOffset,
1065 &Data);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001066 Data = Data | 0x10;
Alan Cox880af9d2008-07-22 11:16:12 +01001067 status = mos7840_set_reg_sync(port, mos7840_port->ControlRegOffset,
1068 Data);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001069
Alan Cox880af9d2008-07-22 11:16:12 +01001070 /* Check to see if we've set up our endpoint info yet *
1071 * (can't set it up in mos7840_startup as the structures *
1072 * were not set up at that time.) */
Oliver Neukum0de9a702007-03-16 20:28:28 +01001073 if (port0->open_ports == 1) {
Paul B Schroeder3f542972006-08-31 19:41:47 -05001074 if (serial->port[0]->interrupt_in_buffer == NULL) {
Paul B Schroeder3f542972006-08-31 19:41:47 -05001075 /* set up interrupt urb */
Paul B Schroeder3f542972006-08-31 19:41:47 -05001076 usb_fill_int_urb(serial->port[0]->interrupt_in_urb,
Alan Cox880af9d2008-07-22 11:16:12 +01001077 serial->dev,
1078 usb_rcvintpipe(serial->dev,
1079 serial->port[0]->interrupt_in_endpointAddress),
1080 serial->port[0]->interrupt_in_buffer,
1081 serial->port[0]->interrupt_in_urb->
1082 transfer_buffer_length,
1083 mos7840_interrupt_callback,
1084 serial,
1085 serial->port[0]->interrupt_in_urb->interval);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001086
1087 /* start interrupt read for mos7840 *
1088 * will continue as long as mos7840 is connected */
1089
1090 response =
1091 usb_submit_urb(serial->port[0]->interrupt_in_urb,
1092 GFP_KERNEL);
1093 if (response) {
Greg Kroah-Hartman194343d2008-08-20 16:56:34 -07001094 dev_err(&port->dev, "%s - Error %d submitting "
1095 "interrupt urb\n", __func__, response);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001096 }
1097
1098 }
1099
1100 }
1101
1102 /* see if we've set up our endpoint info yet *
1103 * (can't set it up in mos7840_startup as the *
1104 * structures were not set up at that time.) */
1105
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001106 dev_dbg(&port->dev, "port number is %d\n", port->number);
1107 dev_dbg(&port->dev, "serial number is %d\n", port->serial->minor);
1108 dev_dbg(&port->dev, "Bulkin endpoint is %d\n", port->bulk_in_endpointAddress);
1109 dev_dbg(&port->dev, "BulkOut endpoint is %d\n", port->bulk_out_endpointAddress);
1110 dev_dbg(&port->dev, "Interrupt endpoint is %d\n", port->interrupt_in_endpointAddress);
1111 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 -05001112 mos7840_port->read_urb = port->read_urb;
1113
1114 /* set up our bulk in urb */
Donald Lee093ea2d2012-03-14 15:26:33 +08001115 if ((serial->num_ports == 2)
1116 && ((((__u16)port->number -
1117 (__u16)(port->serial->minor)) % 2) != 0)) {
1118 usb_fill_bulk_urb(mos7840_port->read_urb,
1119 serial->dev,
1120 usb_rcvbulkpipe(serial->dev,
1121 (port->bulk_in_endpointAddress) + 2),
1122 port->bulk_in_buffer,
1123 mos7840_port->read_urb->transfer_buffer_length,
1124 mos7840_bulk_in_callback, mos7840_port);
1125 } else {
1126 usb_fill_bulk_urb(mos7840_port->read_urb,
1127 serial->dev,
1128 usb_rcvbulkpipe(serial->dev,
1129 port->bulk_in_endpointAddress),
1130 port->bulk_in_buffer,
1131 mos7840_port->read_urb->transfer_buffer_length,
1132 mos7840_bulk_in_callback, mos7840_port);
1133 }
Paul B Schroeder3f542972006-08-31 19:41:47 -05001134
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001135 dev_dbg(&port->dev, "%s: bulkin endpoint is %d\n", __func__, port->bulk_in_endpointAddress);
Greg Kroah-Hartman50de36f2008-12-10 16:00:30 -08001136 mos7840_port->read_urb_busy = true;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001137 response = usb_submit_urb(mos7840_port->read_urb, GFP_KERNEL);
1138 if (response) {
Greg Kroah-Hartman194343d2008-08-20 16:56:34 -07001139 dev_err(&port->dev, "%s - Error %d submitting control urb\n",
1140 __func__, response);
Greg Kroah-Hartman50de36f2008-12-10 16:00:30 -08001141 mos7840_port->read_urb_busy = false;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001142 }
1143
1144 /* initialize our wait queues */
1145 init_waitqueue_head(&mos7840_port->wait_chase);
1146 init_waitqueue_head(&mos7840_port->delta_msr_wait);
1147
1148 /* initialize our icount structure */
1149 memset(&(mos7840_port->icount), 0x00, sizeof(mos7840_port->icount));
1150
1151 /* initialize our port settings */
Alan Cox880af9d2008-07-22 11:16:12 +01001152 /* Must set to enable ints! */
1153 mos7840_port->shadowMCR = MCR_MASTER_IE;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001154 /* send a open port command */
1155 mos7840_port->open = 1;
Alan Cox880af9d2008-07-22 11:16:12 +01001156 /* mos7840_change_port_settings(mos7840_port,old_termios); */
Paul B Schroeder3f542972006-08-31 19:41:47 -05001157 mos7840_port->icount.tx = 0;
1158 mos7840_port->icount.rx = 0;
1159
Paul B Schroeder3f542972006-08-31 19:41:47 -05001160 return 0;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001161}
1162
1163/*****************************************************************************
1164 * mos7840_chars_in_buffer
1165 * this function is called by the tty driver when it wants to know how many
1166 * bytes of data we currently have outstanding in the port (data that has
1167 * been written, but hasn't made it out the port yet)
1168 * If successful, we return the number of bytes left to be written in the
1169 * system,
Alan Cox95da3102008-07-22 11:09:07 +01001170 * Otherwise we return zero.
Paul B Schroeder3f542972006-08-31 19:41:47 -05001171 *****************************************************************************/
1172
Alan Cox95da3102008-07-22 11:09:07 +01001173static int mos7840_chars_in_buffer(struct tty_struct *tty)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001174{
Alan Cox95da3102008-07-22 11:09:07 +01001175 struct usb_serial_port *port = tty->driver_data;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001176 int i;
1177 int chars = 0;
Oliver Neukum0de9a702007-03-16 20:28:28 +01001178 unsigned long flags;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001179 struct moschip_port *mos7840_port;
1180
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001181 if (mos7840_port_paranoia_check(port, __func__))
Alan Cox95da3102008-07-22 11:09:07 +01001182 return 0;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001183
1184 mos7840_port = mos7840_get_port_private(port);
Greg Kroah-Hartman33631552012-05-03 16:44:33 -07001185 if (mos7840_port == NULL)
Alan Cox95da3102008-07-22 11:09:07 +01001186 return 0;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001187
Alan Cox880af9d2008-07-22 11:16:12 +01001188 spin_lock_irqsave(&mos7840_port->pool_lock, flags);
Mark Ferrell5c263b92012-07-24 14:15:13 -05001189 for (i = 0; i < NUM_URBS; ++i) {
1190 if (mos7840_port->busy[i]) {
1191 struct urb *urb = mos7840_port->write_urb_pool[i];
1192 chars += urb->transfer_buffer_length;
1193 }
1194 }
Alan Cox880af9d2008-07-22 11:16:12 +01001195 spin_unlock_irqrestore(&mos7840_port->pool_lock, flags);
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001196 dev_dbg(&port->dev, "%s - returns %d\n", __func__, chars);
Oliver Neukum0de9a702007-03-16 20:28:28 +01001197 return chars;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001198
1199}
1200
Paul B Schroeder3f542972006-08-31 19:41:47 -05001201/*****************************************************************************
1202 * mos7840_close
1203 * this function is called by the tty driver when a port is closed
1204 *****************************************************************************/
1205
Alan Cox335f8512009-06-11 12:26:29 +01001206static void mos7840_close(struct usb_serial_port *port)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001207{
1208 struct usb_serial *serial;
1209 struct moschip_port *mos7840_port;
Oliver Neukum0de9a702007-03-16 20:28:28 +01001210 struct moschip_port *port0;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001211 int j;
1212 __u16 Data;
1213
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001214 if (mos7840_port_paranoia_check(port, __func__))
Paul B Schroeder3f542972006-08-31 19:41:47 -05001215 return;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001216
Harvey Harrison441b62c2008-03-03 16:08:34 -08001217 serial = mos7840_get_usb_serial(port, __func__);
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001218 if (!serial)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001219 return;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001220
1221 mos7840_port = mos7840_get_port_private(port);
Oliver Neukum0de9a702007-03-16 20:28:28 +01001222 port0 = mos7840_get_port_private(serial->port[0]);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001223
Oliver Neukum0de9a702007-03-16 20:28:28 +01001224 if (mos7840_port == NULL || port0 == NULL)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001225 return;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001226
1227 for (j = 0; j < NUM_URBS; ++j)
1228 usb_kill_urb(mos7840_port->write_urb_pool[j]);
1229
1230 /* Freeing Write URBs */
1231 for (j = 0; j < NUM_URBS; ++j) {
1232 if (mos7840_port->write_urb_pool[j]) {
1233 if (mos7840_port->write_urb_pool[j]->transfer_buffer)
1234 kfree(mos7840_port->write_urb_pool[j]->
1235 transfer_buffer);
1236
1237 usb_free_urb(mos7840_port->write_urb_pool[j]);
1238 }
1239 }
1240
Paul B Schroeder3f542972006-08-31 19:41:47 -05001241 /* While closing port, shutdown all bulk read, write *
1242 * and interrupt read if they exists */
1243 if (serial->dev) {
Paul B Schroeder3f542972006-08-31 19:41:47 -05001244 if (mos7840_port->write_urb) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001245 dev_dbg(&port->dev, "%s", "Shutdown bulk write\n");
Paul B Schroeder3f542972006-08-31 19:41:47 -05001246 usb_kill_urb(mos7840_port->write_urb);
1247 }
Paul B Schroeder3f542972006-08-31 19:41:47 -05001248 if (mos7840_port->read_urb) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001249 dev_dbg(&port->dev, "%s", "Shutdown bulk read\n");
Paul B Schroeder3f542972006-08-31 19:41:47 -05001250 usb_kill_urb(mos7840_port->read_urb);
Greg Kroah-Hartman50de36f2008-12-10 16:00:30 -08001251 mos7840_port->read_urb_busy = false;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001252 }
1253 if ((&mos7840_port->control_urb)) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001254 dev_dbg(&port->dev, "%s", "Shutdown control read\n");
Alan Cox880af9d2008-07-22 11:16:12 +01001255 /*/ usb_kill_urb (mos7840_port->control_urb); */
Paul B Schroeder3f542972006-08-31 19:41:47 -05001256 }
1257 }
Alan Cox880af9d2008-07-22 11:16:12 +01001258/* if(mos7840_port->ctrl_buf != NULL) */
1259/* kfree(mos7840_port->ctrl_buf); */
Oliver Neukum0de9a702007-03-16 20:28:28 +01001260 port0->open_ports--;
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001261 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 +01001262 if (port0->open_ports == 0) {
Paul B Schroeder3f542972006-08-31 19:41:47 -05001263 if (serial->port[0]->interrupt_in_urb) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001264 dev_dbg(&port->dev, "Shutdown interrupt_in_urb\n");
Oliver Neukum0de9a702007-03-16 20:28:28 +01001265 usb_kill_urb(serial->port[0]->interrupt_in_urb);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001266 }
1267 }
1268
1269 if (mos7840_port->write_urb) {
1270 /* if this urb had a transfer buffer already (old tx) free it */
Alan Cox880af9d2008-07-22 11:16:12 +01001271 if (mos7840_port->write_urb->transfer_buffer != NULL)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001272 kfree(mos7840_port->write_urb->transfer_buffer);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001273 usb_free_urb(mos7840_port->write_urb);
1274 }
1275
1276 Data = 0x0;
1277 mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
1278
1279 Data = 0x00;
1280 mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data);
1281
1282 mos7840_port->open = 0;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001283}
1284
1285/************************************************************************
1286 *
1287 * mos7840_block_until_chase_response
1288 *
1289 * This function will block the close until one of the following:
1290 * 1. Response to our Chase comes from mos7840
Joe Perchesdc0d5c12007-12-17 11:40:18 -08001291 * 2. A timeout of 10 seconds without activity has expired
Paul B Schroeder3f542972006-08-31 19:41:47 -05001292 * (1K of mos7840 data @ 2400 baud ==> 4 sec to empty)
1293 *
1294 ************************************************************************/
1295
Alan Cox95da3102008-07-22 11:09:07 +01001296static void mos7840_block_until_chase_response(struct tty_struct *tty,
1297 struct moschip_port *mos7840_port)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001298{
Mark Ferrell1e658482012-07-24 13:38:31 -05001299 int timeout = msecs_to_jiffies(1000);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001300 int wait = 10;
1301 int count;
1302
1303 while (1) {
Alan Cox95da3102008-07-22 11:09:07 +01001304 count = mos7840_chars_in_buffer(tty);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001305
1306 /* Check for Buffer status */
Alan Cox880af9d2008-07-22 11:16:12 +01001307 if (count <= 0)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001308 return;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001309
1310 /* Block the thread for a while */
1311 interruptible_sleep_on_timeout(&mos7840_port->wait_chase,
1312 timeout);
1313 /* No activity.. count down section */
1314 wait--;
1315 if (wait == 0) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001316 dev_dbg(&mos7840_port->port->dev, "%s - TIMEOUT\n", __func__);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001317 return;
1318 } else {
Joe Perchesdc0d5c12007-12-17 11:40:18 -08001319 /* Reset timeout value back to seconds */
Paul B Schroeder3f542972006-08-31 19:41:47 -05001320 wait = 10;
1321 }
1322 }
1323
1324}
1325
1326/*****************************************************************************
1327 * mos7840_break
1328 * this function sends a break to the port
1329 *****************************************************************************/
Alan Cox95da3102008-07-22 11:09:07 +01001330static void mos7840_break(struct tty_struct *tty, int break_state)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001331{
Alan Cox95da3102008-07-22 11:09:07 +01001332 struct usb_serial_port *port = tty->driver_data;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001333 unsigned char data;
1334 struct usb_serial *serial;
1335 struct moschip_port *mos7840_port;
1336
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001337 if (mos7840_port_paranoia_check(port, __func__))
Paul B Schroeder3f542972006-08-31 19:41:47 -05001338 return;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001339
Harvey Harrison441b62c2008-03-03 16:08:34 -08001340 serial = mos7840_get_usb_serial(port, __func__);
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001341 if (!serial)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001342 return;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001343
1344 mos7840_port = mos7840_get_port_private(port);
1345
Alan Cox880af9d2008-07-22 11:16:12 +01001346 if (mos7840_port == NULL)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001347 return;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001348
Alan Cox95da3102008-07-22 11:09:07 +01001349 if (serial->dev)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001350 /* flush and block until tx is empty */
Alan Cox95da3102008-07-22 11:09:07 +01001351 mos7840_block_until_chase_response(tty, mos7840_port);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001352
Alan Cox95da3102008-07-22 11:09:07 +01001353 if (break_state == -1)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001354 data = mos7840_port->shadowLCR | LCR_SET_BREAK;
Alan Cox95da3102008-07-22 11:09:07 +01001355 else
Paul B Schroeder3f542972006-08-31 19:41:47 -05001356 data = mos7840_port->shadowLCR & ~LCR_SET_BREAK;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001357
Alan Cox6b447f042009-01-02 13:48:56 +00001358 /* FIXME: no locking on shadowLCR anywhere in driver */
Paul B Schroeder3f542972006-08-31 19:41:47 -05001359 mos7840_port->shadowLCR = data;
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001360 dev_dbg(&port->dev, "%s mos7840_port->shadowLCR is %x\n", __func__, mos7840_port->shadowLCR);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001361 mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER,
1362 mos7840_port->shadowLCR);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001363}
1364
1365/*****************************************************************************
1366 * mos7840_write_room
1367 * this function is called by the tty driver when it wants to know how many
1368 * bytes of data we can accept for a specific port.
1369 * If successful, we return the amount of room that we have for this port
1370 * Otherwise we return a negative error number.
1371 *****************************************************************************/
1372
Alan Cox95da3102008-07-22 11:09:07 +01001373static int mos7840_write_room(struct tty_struct *tty)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001374{
Alan Cox95da3102008-07-22 11:09:07 +01001375 struct usb_serial_port *port = tty->driver_data;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001376 int i;
1377 int room = 0;
Oliver Neukum0de9a702007-03-16 20:28:28 +01001378 unsigned long flags;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001379 struct moschip_port *mos7840_port;
1380
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001381 if (mos7840_port_paranoia_check(port, __func__))
Paul B Schroeder3f542972006-08-31 19:41:47 -05001382 return -1;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001383
1384 mos7840_port = mos7840_get_port_private(port);
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001385 if (mos7840_port == NULL)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001386 return -1;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001387
Oliver Neukum0de9a702007-03-16 20:28:28 +01001388 spin_lock_irqsave(&mos7840_port->pool_lock, flags);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001389 for (i = 0; i < NUM_URBS; ++i) {
Alan Cox880af9d2008-07-22 11:16:12 +01001390 if (!mos7840_port->busy[i])
Paul B Schroeder3f542972006-08-31 19:41:47 -05001391 room += URB_TRANSFER_BUFFER_SIZE;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001392 }
Oliver Neukum0de9a702007-03-16 20:28:28 +01001393 spin_unlock_irqrestore(&mos7840_port->pool_lock, flags);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001394
Oliver Neukum0de9a702007-03-16 20:28:28 +01001395 room = (room == 0) ? 0 : room - URB_TRANSFER_BUFFER_SIZE + 1;
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001396 dev_dbg(&mos7840_port->port->dev, "%s - returns %d\n", __func__, room);
Oliver Neukum0de9a702007-03-16 20:28:28 +01001397 return room;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001398
1399}
1400
1401/*****************************************************************************
1402 * mos7840_write
1403 * this function is called by the tty driver when data should be written to
1404 * the port.
1405 * If successful, we return the number of bytes written, otherwise we
1406 * return a negative error number.
1407 *****************************************************************************/
1408
Alan Cox95da3102008-07-22 11:09:07 +01001409static int mos7840_write(struct tty_struct *tty, struct usb_serial_port *port,
Paul B Schroeder3f542972006-08-31 19:41:47 -05001410 const unsigned char *data, int count)
1411{
1412 int status;
1413 int i;
1414 int bytes_sent = 0;
1415 int transfer_size;
Oliver Neukum0de9a702007-03-16 20:28:28 +01001416 unsigned long flags;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001417
1418 struct moschip_port *mos7840_port;
1419 struct usb_serial *serial;
1420 struct urb *urb;
Alan Cox880af9d2008-07-22 11:16:12 +01001421 /* __u16 Data; */
Paul B Schroeder3f542972006-08-31 19:41:47 -05001422 const unsigned char *current_position = data;
1423 unsigned char *data1;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001424
1425#ifdef NOTMOS7840
1426 Data = 0x00;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001427 status = mos7840_get_uart_reg(port, LINE_CONTROL_REGISTER, &Data);
1428 mos7840_port->shadowLCR = Data;
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001429 dev_dbg(&port->dev, "%s: LINE_CONTROL_REGISTER is %x\n", __func__, Data);
1430 dev_dbg(&port->dev, "%s: mos7840_port->shadowLCR is %x\n", __func__, mos7840_port->shadowLCR);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001431
Alan Cox880af9d2008-07-22 11:16:12 +01001432 /* Data = 0x03; */
1433 /* status = mos7840_set_uart_reg(port,LINE_CONTROL_REGISTER,Data); */
1434 /* mos7840_port->shadowLCR=Data;//Need to add later */
Paul B Schroeder3f542972006-08-31 19:41:47 -05001435
Alan Cox880af9d2008-07-22 11:16:12 +01001436 Data |= SERIAL_LCR_DLAB; /* data latch enable in LCR 0x80 */
Paul B Schroeder3f542972006-08-31 19:41:47 -05001437 status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
1438
Alan Cox880af9d2008-07-22 11:16:12 +01001439 /* Data = 0x0c; */
1440 /* status = mos7840_set_uart_reg(port,DIVISOR_LATCH_LSB,Data); */
Paul B Schroeder3f542972006-08-31 19:41:47 -05001441 Data = 0x00;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001442 status = mos7840_get_uart_reg(port, DIVISOR_LATCH_LSB, &Data);
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001443 dev_dbg(&port->dev, "%s: DLL value is %x\n", __func__, Data);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001444
1445 Data = 0x0;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001446 status = mos7840_get_uart_reg(port, DIVISOR_LATCH_MSB, &Data);
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001447 dev_dbg(&port->dev, "%s: DLM value is %x\n", __func__, Data);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001448
1449 Data = Data & ~SERIAL_LCR_DLAB;
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001450 dev_dbg(&port->dev, "%s: mos7840_port->shadowLCR is %x\n", __func__, mos7840_port->shadowLCR);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001451 status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
1452#endif
1453
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001454 if (mos7840_port_paranoia_check(port, __func__))
Paul B Schroeder3f542972006-08-31 19:41:47 -05001455 return -1;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001456
1457 serial = port->serial;
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001458 if (mos7840_serial_paranoia_check(serial, __func__))
Paul B Schroeder3f542972006-08-31 19:41:47 -05001459 return -1;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001460
1461 mos7840_port = mos7840_get_port_private(port);
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001462 if (mos7840_port == NULL)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001463 return -1;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001464
1465 /* try to find a free urb in the list */
1466 urb = NULL;
1467
Oliver Neukum0de9a702007-03-16 20:28:28 +01001468 spin_lock_irqsave(&mos7840_port->pool_lock, flags);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001469 for (i = 0; i < NUM_URBS; ++i) {
Oliver Neukum0de9a702007-03-16 20:28:28 +01001470 if (!mos7840_port->busy[i]) {
1471 mos7840_port->busy[i] = 1;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001472 urb = mos7840_port->write_urb_pool[i];
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001473 dev_dbg(&port->dev, "URB:%d\n", i);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001474 break;
1475 }
1476 }
Oliver Neukum0de9a702007-03-16 20:28:28 +01001477 spin_unlock_irqrestore(&mos7840_port->pool_lock, flags);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001478
1479 if (urb == NULL) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001480 dev_dbg(&port->dev, "%s - no more free urbs\n", __func__);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001481 goto exit;
1482 }
1483
1484 if (urb->transfer_buffer == NULL) {
1485 urb->transfer_buffer =
1486 kmalloc(URB_TRANSFER_BUFFER_SIZE, GFP_KERNEL);
1487
1488 if (urb->transfer_buffer == NULL) {
Johan Hovold22a416c2012-02-10 13:20:51 +01001489 dev_err_console(port, "%s no more kernel memory...\n",
Greg Kroah-Hartman194343d2008-08-20 16:56:34 -07001490 __func__);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001491 goto exit;
1492 }
1493 }
1494 transfer_size = min(count, URB_TRANSFER_BUFFER_SIZE);
1495
Al Viro97c49652006-10-09 20:29:03 +01001496 memcpy(urb->transfer_buffer, current_position, transfer_size);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001497
1498 /* fill urb with data and submit */
Donald Lee093ea2d2012-03-14 15:26:33 +08001499 if ((serial->num_ports == 2)
1500 && ((((__u16)port->number -
1501 (__u16)(port->serial->minor)) % 2) != 0)) {
1502 usb_fill_bulk_urb(urb,
1503 serial->dev,
1504 usb_sndbulkpipe(serial->dev,
1505 (port->bulk_out_endpointAddress) + 2),
1506 urb->transfer_buffer,
1507 transfer_size,
1508 mos7840_bulk_out_data_callback, mos7840_port);
1509 } else {
1510 usb_fill_bulk_urb(urb,
1511 serial->dev,
1512 usb_sndbulkpipe(serial->dev,
1513 port->bulk_out_endpointAddress),
1514 urb->transfer_buffer,
1515 transfer_size,
1516 mos7840_bulk_out_data_callback, mos7840_port);
1517 }
Paul B Schroeder3f542972006-08-31 19:41:47 -05001518
1519 data1 = urb->transfer_buffer;
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001520 dev_dbg(&port->dev, "bulkout endpoint is %d\n", port->bulk_out_endpointAddress);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001521
Donald0eafe4d2012-04-19 15:00:45 +08001522 /* Turn on LED */
1523 if (mos7840_port->has_led && !mos7840_port->led_flag) {
1524 mos7840_port->led_flag = true;
1525 mos7840_set_led_sync(port, MODEM_CONTROL_REGISTER, 0x0301);
1526 mod_timer(&mos7840_port->led_timer1,
1527 jiffies + msecs_to_jiffies(LED_ON_MS));
1528 }
1529
Paul B Schroeder3f542972006-08-31 19:41:47 -05001530 /* send it down the pipe */
1531 status = usb_submit_urb(urb, GFP_ATOMIC);
1532
1533 if (status) {
Oliver Neukum0de9a702007-03-16 20:28:28 +01001534 mos7840_port->busy[i] = 0;
Johan Hovold22a416c2012-02-10 13:20:51 +01001535 dev_err_console(port, "%s - usb_submit_urb(write bulk) failed "
Greg Kroah-Hartman194343d2008-08-20 16:56:34 -07001536 "with status = %d\n", __func__, status);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001537 bytes_sent = status;
1538 goto exit;
1539 }
1540 bytes_sent = transfer_size;
1541 mos7840_port->icount.tx += transfer_size;
Oliver Neukum0de9a702007-03-16 20:28:28 +01001542 smp_wmb();
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001543 dev_dbg(&port->dev, "mos7840_port->icount.tx is %d:\n", mos7840_port->icount.tx);
Alan Cox95da3102008-07-22 11:09:07 +01001544exit:
Paul B Schroeder3f542972006-08-31 19:41:47 -05001545 return bytes_sent;
1546
1547}
1548
1549/*****************************************************************************
1550 * mos7840_throttle
1551 * this function is called by the tty driver when it wants to stop the data
1552 * being read from the port.
1553 *****************************************************************************/
1554
Alan Cox95da3102008-07-22 11:09:07 +01001555static void mos7840_throttle(struct tty_struct *tty)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001556{
Alan Cox95da3102008-07-22 11:09:07 +01001557 struct usb_serial_port *port = tty->driver_data;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001558 struct moschip_port *mos7840_port;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001559 int status;
1560
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001561 if (mos7840_port_paranoia_check(port, __func__))
Paul B Schroeder3f542972006-08-31 19:41:47 -05001562 return;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001563
1564 mos7840_port = mos7840_get_port_private(port);
1565
1566 if (mos7840_port == NULL)
1567 return;
1568
1569 if (!mos7840_port->open) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001570 dev_dbg(&port->dev, "%s", "port not opened\n");
Paul B Schroeder3f542972006-08-31 19:41:47 -05001571 return;
1572 }
1573
Paul B Schroeder3f542972006-08-31 19:41:47 -05001574 /* if we are implementing XON/XOFF, send the stop character */
1575 if (I_IXOFF(tty)) {
1576 unsigned char stop_char = STOP_CHAR(tty);
Alan Cox95da3102008-07-22 11:09:07 +01001577 status = mos7840_write(tty, port, &stop_char, 1);
1578 if (status <= 0)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001579 return;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001580 }
Paul B Schroeder3f542972006-08-31 19:41:47 -05001581 /* if we are implementing RTS/CTS, toggle that line */
Alan Coxadc8d742012-07-14 15:31:47 +01001582 if (tty->termios.c_cflag & CRTSCTS) {
Paul B Schroeder3f542972006-08-31 19:41:47 -05001583 mos7840_port->shadowMCR &= ~MCR_RTS;
Alan Cox95da3102008-07-22 11:09:07 +01001584 status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER,
Paul B Schroeder3f542972006-08-31 19:41:47 -05001585 mos7840_port->shadowMCR);
Alan Cox95da3102008-07-22 11:09:07 +01001586 if (status < 0)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001587 return;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001588 }
Paul B Schroeder3f542972006-08-31 19:41:47 -05001589}
1590
1591/*****************************************************************************
1592 * mos7840_unthrottle
Alan Cox880af9d2008-07-22 11:16:12 +01001593 * this function is called by the tty driver when it wants to resume
1594 * the data being read from the port (called after mos7840_throttle is
1595 * called)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001596 *****************************************************************************/
Alan Cox95da3102008-07-22 11:09:07 +01001597static void mos7840_unthrottle(struct tty_struct *tty)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001598{
Alan Cox95da3102008-07-22 11:09:07 +01001599 struct usb_serial_port *port = tty->driver_data;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001600 int status;
1601 struct moschip_port *mos7840_port = mos7840_get_port_private(port);
1602
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001603 if (mos7840_port_paranoia_check(port, __func__))
Paul B Schroeder3f542972006-08-31 19:41:47 -05001604 return;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001605
1606 if (mos7840_port == NULL)
1607 return;
1608
1609 if (!mos7840_port->open) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001610 dev_dbg(&port->dev, "%s - port not opened\n", __func__);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001611 return;
1612 }
1613
Paul B Schroeder3f542972006-08-31 19:41:47 -05001614 /* if we are implementing XON/XOFF, send the start character */
1615 if (I_IXOFF(tty)) {
1616 unsigned char start_char = START_CHAR(tty);
Alan Cox95da3102008-07-22 11:09:07 +01001617 status = mos7840_write(tty, port, &start_char, 1);
1618 if (status <= 0)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001619 return;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001620 }
1621
1622 /* if we are implementing RTS/CTS, toggle that line */
Alan Coxadc8d742012-07-14 15:31:47 +01001623 if (tty->termios.c_cflag & CRTSCTS) {
Paul B Schroeder3f542972006-08-31 19:41:47 -05001624 mos7840_port->shadowMCR |= MCR_RTS;
Alan Cox95da3102008-07-22 11:09:07 +01001625 status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER,
Paul B Schroeder3f542972006-08-31 19:41:47 -05001626 mos7840_port->shadowMCR);
Alan Cox95da3102008-07-22 11:09:07 +01001627 if (status < 0)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001628 return;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001629 }
Paul B Schroeder3f542972006-08-31 19:41:47 -05001630}
1631
Alan Cox60b33c12011-02-14 16:26:14 +00001632static int mos7840_tiocmget(struct tty_struct *tty)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001633{
Alan Cox95da3102008-07-22 11:09:07 +01001634 struct usb_serial_port *port = tty->driver_data;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001635 struct moschip_port *mos7840_port;
1636 unsigned int result;
1637 __u16 msr;
1638 __u16 mcr;
Alan Cox880af9d2008-07-22 11:16:12 +01001639 int status;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001640 mos7840_port = mos7840_get_port_private(port);
1641
Paul B Schroeder3f542972006-08-31 19:41:47 -05001642 if (mos7840_port == NULL)
1643 return -ENODEV;
1644
1645 status = mos7840_get_uart_reg(port, MODEM_STATUS_REGISTER, &msr);
1646 status = mos7840_get_uart_reg(port, MODEM_CONTROL_REGISTER, &mcr);
1647 result = ((mcr & MCR_DTR) ? TIOCM_DTR : 0)
1648 | ((mcr & MCR_RTS) ? TIOCM_RTS : 0)
1649 | ((mcr & MCR_LOOPBACK) ? TIOCM_LOOP : 0)
1650 | ((msr & MOS7840_MSR_CTS) ? TIOCM_CTS : 0)
1651 | ((msr & MOS7840_MSR_CD) ? TIOCM_CAR : 0)
1652 | ((msr & MOS7840_MSR_RI) ? TIOCM_RI : 0)
1653 | ((msr & MOS7840_MSR_DSR) ? TIOCM_DSR : 0);
1654
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001655 dev_dbg(&port->dev, "%s - 0x%04X\n", __func__, result);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001656
1657 return result;
1658}
1659
Alan Cox20b9d172011-02-14 16:26:50 +00001660static int mos7840_tiocmset(struct tty_struct *tty,
Paul B Schroeder3f542972006-08-31 19:41:47 -05001661 unsigned int set, unsigned int clear)
1662{
Alan Cox95da3102008-07-22 11:09:07 +01001663 struct usb_serial_port *port = tty->driver_data;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001664 struct moschip_port *mos7840_port;
1665 unsigned int mcr;
Roel Kluin87521c42008-04-17 06:16:24 +02001666 int status;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001667
Paul B Schroeder3f542972006-08-31 19:41:47 -05001668 mos7840_port = mos7840_get_port_private(port);
1669
1670 if (mos7840_port == NULL)
1671 return -ENODEV;
1672
Alan Coxe2984492008-02-20 20:51:45 +00001673 /* FIXME: What locks the port registers ? */
Paul B Schroeder3f542972006-08-31 19:41:47 -05001674 mcr = mos7840_port->shadowMCR;
1675 if (clear & TIOCM_RTS)
1676 mcr &= ~MCR_RTS;
1677 if (clear & TIOCM_DTR)
1678 mcr &= ~MCR_DTR;
1679 if (clear & TIOCM_LOOP)
1680 mcr &= ~MCR_LOOPBACK;
1681
1682 if (set & TIOCM_RTS)
1683 mcr |= MCR_RTS;
1684 if (set & TIOCM_DTR)
1685 mcr |= MCR_DTR;
1686 if (set & TIOCM_LOOP)
1687 mcr |= MCR_LOOPBACK;
1688
1689 mos7840_port->shadowMCR = mcr;
1690
Paul B Schroeder3f542972006-08-31 19:41:47 -05001691 status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, mcr);
1692 if (status < 0) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001693 dev_dbg(&port->dev, "setting MODEM_CONTROL_REGISTER Failed\n");
Roel Kluin87521c42008-04-17 06:16:24 +02001694 return status;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001695 }
1696
1697 return 0;
1698}
1699
1700/*****************************************************************************
1701 * mos7840_calc_baud_rate_divisor
1702 * this function calculates the proper baud rate divisor for the specified
1703 * baud rate.
1704 *****************************************************************************/
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001705static int mos7840_calc_baud_rate_divisor(struct usb_serial_port *port,
1706 int baudRate, int *divisor,
Alan Cox880af9d2008-07-22 11:16:12 +01001707 __u16 *clk_sel_val)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001708{
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001709 dev_dbg(&port->dev, "%s - %d\n", __func__, baudRate);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001710
1711 if (baudRate <= 115200) {
1712 *divisor = 115200 / baudRate;
1713 *clk_sel_val = 0x0;
1714 }
1715 if ((baudRate > 115200) && (baudRate <= 230400)) {
1716 *divisor = 230400 / baudRate;
1717 *clk_sel_val = 0x10;
1718 } else if ((baudRate > 230400) && (baudRate <= 403200)) {
1719 *divisor = 403200 / baudRate;
1720 *clk_sel_val = 0x20;
1721 } else if ((baudRate > 403200) && (baudRate <= 460800)) {
1722 *divisor = 460800 / baudRate;
1723 *clk_sel_val = 0x30;
1724 } else if ((baudRate > 460800) && (baudRate <= 806400)) {
1725 *divisor = 806400 / baudRate;
1726 *clk_sel_val = 0x40;
1727 } else if ((baudRate > 806400) && (baudRate <= 921600)) {
1728 *divisor = 921600 / baudRate;
1729 *clk_sel_val = 0x50;
1730 } else if ((baudRate > 921600) && (baudRate <= 1572864)) {
1731 *divisor = 1572864 / baudRate;
1732 *clk_sel_val = 0x60;
1733 } else if ((baudRate > 1572864) && (baudRate <= 3145728)) {
1734 *divisor = 3145728 / baudRate;
1735 *clk_sel_val = 0x70;
1736 }
1737 return 0;
1738
1739#ifdef NOTMCS7840
1740
1741 for (i = 0; i < ARRAY_SIZE(mos7840_divisor_table); i++) {
1742 if (mos7840_divisor_table[i].BaudRate == baudrate) {
1743 *divisor = mos7840_divisor_table[i].Divisor;
1744 return 0;
1745 }
1746 }
1747
1748 /* After trying for all the standard baud rates *
1749 * Try calculating the divisor for this baud rate */
1750
1751 if (baudrate > 75 && baudrate < 230400) {
1752 /* get the divisor */
1753 custom = (__u16) (230400L / baudrate);
1754
1755 /* Check for round off */
1756 round1 = (__u16) (2304000L / baudrate);
1757 round = (__u16) (round1 - (custom * 10));
Alan Cox880af9d2008-07-22 11:16:12 +01001758 if (round > 4)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001759 custom++;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001760 *divisor = custom;
1761
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001762 dev_dbg(&port->dev, " Baud %d = %d\n", baudrate, custom);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001763 return 0;
1764 }
1765
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001766 dev_dbg(&port->dev, "%s", " Baud calculation Failed...\n");
Paul B Schroeder3f542972006-08-31 19:41:47 -05001767 return -1;
1768#endif
1769}
1770
1771/*****************************************************************************
1772 * mos7840_send_cmd_write_baud_rate
1773 * this function sends the proper command to change the baud rate of the
1774 * specified port.
1775 *****************************************************************************/
1776
1777static int mos7840_send_cmd_write_baud_rate(struct moschip_port *mos7840_port,
1778 int baudRate)
1779{
1780 int divisor = 0;
1781 int status;
1782 __u16 Data;
1783 unsigned char number;
1784 __u16 clk_sel_val;
1785 struct usb_serial_port *port;
1786
1787 if (mos7840_port == NULL)
1788 return -1;
1789
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001790 port = mos7840_port->port;
1791 if (mos7840_port_paranoia_check(port, __func__))
Paul B Schroeder3f542972006-08-31 19:41:47 -05001792 return -1;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001793
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001794 if (mos7840_serial_paranoia_check(port->serial, __func__))
Paul B Schroeder3f542972006-08-31 19:41:47 -05001795 return -1;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001796
Paul B Schroeder3f542972006-08-31 19:41:47 -05001797 number = mos7840_port->port->number - mos7840_port->port->serial->minor;
1798
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001799 dev_dbg(&port->dev, "%s - port = %d, baud = %d\n", __func__,
1800 mos7840_port->port->number, baudRate);
Alan Cox880af9d2008-07-22 11:16:12 +01001801 /* reset clk_uart_sel in spregOffset */
Paul B Schroeder3f542972006-08-31 19:41:47 -05001802 if (baudRate > 115200) {
1803#ifdef HW_flow_control
Alan Cox880af9d2008-07-22 11:16:12 +01001804 /* NOTE: need to see the pther register to modify */
1805 /* setting h/w flow control bit to 1 */
Paul B Schroeder3f542972006-08-31 19:41:47 -05001806 Data = 0x2b;
1807 mos7840_port->shadowMCR = Data;
Alan Cox880af9d2008-07-22 11:16:12 +01001808 status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER,
1809 Data);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001810 if (status < 0) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001811 dev_dbg(&port->dev, "Writing spreg failed in set_serial_baud\n");
Paul B Schroeder3f542972006-08-31 19:41:47 -05001812 return -1;
1813 }
1814#endif
1815
1816 } else {
1817#ifdef HW_flow_control
Donald Lee093ea2d2012-03-14 15:26:33 +08001818 /* setting h/w flow control bit to 0 */
Paul B Schroeder3f542972006-08-31 19:41:47 -05001819 Data = 0xb;
1820 mos7840_port->shadowMCR = Data;
Alan Cox880af9d2008-07-22 11:16:12 +01001821 status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER,
1822 Data);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001823 if (status < 0) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001824 dev_dbg(&port->dev, "Writing spreg failed in set_serial_baud\n");
Paul B Schroeder3f542972006-08-31 19:41:47 -05001825 return -1;
1826 }
1827#endif
1828
1829 }
1830
Alan Cox880af9d2008-07-22 11:16:12 +01001831 if (1) { /* baudRate <= 115200) */
Paul B Schroeder3f542972006-08-31 19:41:47 -05001832 clk_sel_val = 0x0;
1833 Data = 0x0;
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001834 status = mos7840_calc_baud_rate_divisor(port, baudRate, &divisor,
Paul B Schroeder3f542972006-08-31 19:41:47 -05001835 &clk_sel_val);
Alan Cox880af9d2008-07-22 11:16:12 +01001836 status = mos7840_get_reg_sync(port, mos7840_port->SpRegOffset,
1837 &Data);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001838 if (status < 0) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001839 dev_dbg(&port->dev, "reading spreg failed in set_serial_baud\n");
Paul B Schroeder3f542972006-08-31 19:41:47 -05001840 return -1;
1841 }
1842 Data = (Data & 0x8f) | clk_sel_val;
Alan Cox880af9d2008-07-22 11:16:12 +01001843 status = mos7840_set_reg_sync(port, mos7840_port->SpRegOffset,
1844 Data);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001845 if (status < 0) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001846 dev_dbg(&port->dev, "Writing spreg failed in set_serial_baud\n");
Paul B Schroeder3f542972006-08-31 19:41:47 -05001847 return -1;
1848 }
1849 /* Calculate the Divisor */
1850
1851 if (status) {
Greg Kroah-Hartman194343d2008-08-20 16:56:34 -07001852 dev_err(&port->dev, "%s - bad baud rate\n", __func__);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001853 return status;
1854 }
1855 /* Enable access to divisor latch */
1856 Data = mos7840_port->shadowLCR | SERIAL_LCR_DLAB;
1857 mos7840_port->shadowLCR = Data;
1858 mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
1859
1860 /* Write the divisor */
1861 Data = (unsigned char)(divisor & 0xff);
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001862 dev_dbg(&port->dev, "set_serial_baud Value to write DLL is %x\n", Data);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001863 mos7840_set_uart_reg(port, DIVISOR_LATCH_LSB, Data);
1864
1865 Data = (unsigned char)((divisor & 0xff00) >> 8);
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001866 dev_dbg(&port->dev, "set_serial_baud Value to write DLM is %x\n", Data);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001867 mos7840_set_uart_reg(port, DIVISOR_LATCH_MSB, Data);
1868
1869 /* Disable 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 }
Paul B Schroeder3f542972006-08-31 19:41:47 -05001875 return status;
1876}
1877
1878/*****************************************************************************
1879 * mos7840_change_port_settings
1880 * This routine is called to set the UART on the device to match
1881 * the specified new settings.
1882 *****************************************************************************/
1883
Alan Cox95da3102008-07-22 11:09:07 +01001884static void mos7840_change_port_settings(struct tty_struct *tty,
1885 struct moschip_port *mos7840_port, struct ktermios *old_termios)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001886{
Paul B Schroeder3f542972006-08-31 19:41:47 -05001887 int baud;
1888 unsigned cflag;
1889 unsigned iflag;
1890 __u8 lData;
1891 __u8 lParity;
1892 __u8 lStop;
1893 int status;
1894 __u16 Data;
1895 struct usb_serial_port *port;
1896 struct usb_serial *serial;
1897
1898 if (mos7840_port == NULL)
1899 return;
1900
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001901 port = mos7840_port->port;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001902
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001903 if (mos7840_port_paranoia_check(port, __func__))
Paul B Schroeder3f542972006-08-31 19:41:47 -05001904 return;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001905
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001906 if (mos7840_serial_paranoia_check(port->serial, __func__))
Paul B Schroeder3f542972006-08-31 19:41:47 -05001907 return;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001908
1909 serial = port->serial;
1910
Paul B Schroeder3f542972006-08-31 19:41:47 -05001911 if (!mos7840_port->open) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001912 dev_dbg(&port->dev, "%s - port not opened\n", __func__);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001913 return;
1914 }
1915
Paul B Schroeder3f542972006-08-31 19:41:47 -05001916 lData = LCR_BITS_8;
1917 lStop = LCR_STOP_1;
1918 lParity = LCR_PAR_NONE;
1919
Alan Coxadc8d742012-07-14 15:31:47 +01001920 cflag = tty->termios.c_cflag;
1921 iflag = tty->termios.c_iflag;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001922
1923 /* Change the number of bits */
1924 if (cflag & CSIZE) {
1925 switch (cflag & CSIZE) {
1926 case CS5:
1927 lData = LCR_BITS_5;
1928 break;
1929
1930 case CS6:
1931 lData = LCR_BITS_6;
1932 break;
1933
1934 case CS7:
1935 lData = LCR_BITS_7;
1936 break;
1937 default:
1938 case CS8:
1939 lData = LCR_BITS_8;
1940 break;
1941 }
1942 }
1943 /* Change the Parity bit */
1944 if (cflag & PARENB) {
1945 if (cflag & PARODD) {
1946 lParity = LCR_PAR_ODD;
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001947 dev_dbg(&port->dev, "%s - parity = odd\n", __func__);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001948 } else {
1949 lParity = LCR_PAR_EVEN;
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001950 dev_dbg(&port->dev, "%s - parity = even\n", __func__);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001951 }
1952
1953 } else {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001954 dev_dbg(&port->dev, "%s - parity = none\n", __func__);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001955 }
1956
Alan Cox880af9d2008-07-22 11:16:12 +01001957 if (cflag & CMSPAR)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001958 lParity = lParity | 0x20;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001959
1960 /* Change the Stop bit */
1961 if (cflag & CSTOPB) {
1962 lStop = LCR_STOP_2;
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001963 dev_dbg(&port->dev, "%s - stop bits = 2\n", __func__);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001964 } else {
1965 lStop = LCR_STOP_1;
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001966 dev_dbg(&port->dev, "%s - stop bits = 1\n", __func__);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001967 }
1968
1969 /* Update the LCR with the correct value */
1970 mos7840_port->shadowLCR &=
1971 ~(LCR_BITS_MASK | LCR_STOP_MASK | LCR_PAR_MASK);
1972 mos7840_port->shadowLCR |= (lData | lParity | lStop);
1973
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001974 dev_dbg(&port->dev, "%s - mos7840_port->shadowLCR is %x\n", __func__,
1975 mos7840_port->shadowLCR);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001976 /* Disable Interrupts */
1977 Data = 0x00;
1978 mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data);
1979
1980 Data = 0x00;
1981 mos7840_set_uart_reg(port, FIFO_CONTROL_REGISTER, Data);
1982
1983 Data = 0xcf;
1984 mos7840_set_uart_reg(port, FIFO_CONTROL_REGISTER, Data);
1985
1986 /* Send the updated LCR value to the mos7840 */
1987 Data = mos7840_port->shadowLCR;
1988
1989 mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
1990
1991 Data = 0x00b;
1992 mos7840_port->shadowMCR = Data;
1993 mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
1994 Data = 0x00b;
1995 mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
1996
1997 /* set up the MCR register and send it to the mos7840 */
1998
1999 mos7840_port->shadowMCR = MCR_MASTER_IE;
Alan Cox880af9d2008-07-22 11:16:12 +01002000 if (cflag & CBAUD)
Paul B Schroeder3f542972006-08-31 19:41:47 -05002001 mos7840_port->shadowMCR |= (MCR_DTR | MCR_RTS);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002002
Alan Cox880af9d2008-07-22 11:16:12 +01002003 if (cflag & CRTSCTS)
Paul B Schroeder3f542972006-08-31 19:41:47 -05002004 mos7840_port->shadowMCR |= (MCR_XON_ANY);
Alan Cox880af9d2008-07-22 11:16:12 +01002005 else
Paul B Schroeder3f542972006-08-31 19:41:47 -05002006 mos7840_port->shadowMCR &= ~(MCR_XON_ANY);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002007
2008 Data = mos7840_port->shadowMCR;
2009 mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
2010
2011 /* Determine divisor based on baud rate */
2012 baud = tty_get_baud_rate(tty);
2013
2014 if (!baud) {
2015 /* pick a default, any default... */
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002016 dev_dbg(&port->dev, "%s", "Picked default baud...\n");
Paul B Schroeder3f542972006-08-31 19:41:47 -05002017 baud = 9600;
2018 }
2019
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002020 dev_dbg(&port->dev, "%s - baud rate = %d\n", __func__, baud);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002021 status = mos7840_send_cmd_write_baud_rate(mos7840_port, baud);
2022
2023 /* Enable Interrupts */
2024 Data = 0x0c;
2025 mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data);
2026
Greg Kroah-Hartman50de36f2008-12-10 16:00:30 -08002027 if (mos7840_port->read_urb_busy == false) {
Greg Kroah-Hartman50de36f2008-12-10 16:00:30 -08002028 mos7840_port->read_urb_busy = true;
Paul B Schroeder3f542972006-08-31 19:41:47 -05002029 status = usb_submit_urb(mos7840_port->read_urb, GFP_ATOMIC);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002030 if (status) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002031 dev_dbg(&port->dev, "usb_submit_urb(read bulk) failed, status = %d\n",
Paul B Schroeder3f542972006-08-31 19:41:47 -05002032 status);
Greg Kroah-Hartman50de36f2008-12-10 16:00:30 -08002033 mos7840_port->read_urb_busy = false;
Paul B Schroeder3f542972006-08-31 19:41:47 -05002034 }
2035 }
2036 wake_up(&mos7840_port->delta_msr_wait);
2037 mos7840_port->delta_msr_cond = 1;
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002038 dev_dbg(&port->dev, "%s - mos7840_port->shadowLCR is End %x\n", __func__,
2039 mos7840_port->shadowLCR);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002040}
2041
2042/*****************************************************************************
2043 * mos7840_set_termios
2044 * this function is called by the tty driver when it wants to change
2045 * the termios structure
2046 *****************************************************************************/
2047
Alan Cox95da3102008-07-22 11:09:07 +01002048static void mos7840_set_termios(struct tty_struct *tty,
2049 struct usb_serial_port *port,
Alan Cox606d0992006-12-08 02:38:45 -08002050 struct ktermios *old_termios)
Paul B Schroeder3f542972006-08-31 19:41:47 -05002051{
2052 int status;
2053 unsigned int cflag;
2054 struct usb_serial *serial;
2055 struct moschip_port *mos7840_port;
Greg Kroah-Hartman33631552012-05-03 16:44:33 -07002056
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002057 if (mos7840_port_paranoia_check(port, __func__))
Paul B Schroeder3f542972006-08-31 19:41:47 -05002058 return;
Paul B Schroeder3f542972006-08-31 19:41:47 -05002059
2060 serial = port->serial;
2061
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002062 if (mos7840_serial_paranoia_check(serial, __func__))
Paul B Schroeder3f542972006-08-31 19:41:47 -05002063 return;
Paul B Schroeder3f542972006-08-31 19:41:47 -05002064
2065 mos7840_port = mos7840_get_port_private(port);
2066
2067 if (mos7840_port == NULL)
2068 return;
2069
Paul B Schroeder3f542972006-08-31 19:41:47 -05002070 if (!mos7840_port->open) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002071 dev_dbg(&port->dev, "%s - port not opened\n", __func__);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002072 return;
2073 }
2074
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002075 dev_dbg(&port->dev, "%s", "setting termios - \n");
Paul B Schroeder3f542972006-08-31 19:41:47 -05002076
Alan Coxadc8d742012-07-14 15:31:47 +01002077 cflag = tty->termios.c_cflag;
Paul B Schroeder3f542972006-08-31 19:41:47 -05002078
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002079 dev_dbg(&port->dev, "%s - clfag %08x iflag %08x\n", __func__,
Linus Torvaldsd9a80742012-10-01 13:23:01 -07002080 tty->termios.c_cflag, RELEVANT_IFLAG(tty->termios.c_iflag));
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002081 dev_dbg(&port->dev, "%s - old clfag %08x old iflag %08x\n", __func__,
2082 old_termios->c_cflag, RELEVANT_IFLAG(old_termios->c_iflag));
2083 dev_dbg(&port->dev, "%s - port %d\n", __func__, port->number);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002084
2085 /* change the port settings to the new ones specified */
2086
Alan Cox95da3102008-07-22 11:09:07 +01002087 mos7840_change_port_settings(tty, mos7840_port, old_termios);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002088
2089 if (!mos7840_port->read_urb) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002090 dev_dbg(&port->dev, "%s", "URB KILLED !!!!!\n");
Paul B Schroeder3f542972006-08-31 19:41:47 -05002091 return;
2092 }
2093
Greg Kroah-Hartman50de36f2008-12-10 16:00:30 -08002094 if (mos7840_port->read_urb_busy == false) {
Greg Kroah-Hartman50de36f2008-12-10 16:00:30 -08002095 mos7840_port->read_urb_busy = true;
Paul B Schroeder3f542972006-08-31 19:41:47 -05002096 status = usb_submit_urb(mos7840_port->read_urb, GFP_ATOMIC);
2097 if (status) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002098 dev_dbg(&port->dev, "usb_submit_urb(read bulk) failed, status = %d\n",
Paul B Schroeder3f542972006-08-31 19:41:47 -05002099 status);
Greg Kroah-Hartman50de36f2008-12-10 16:00:30 -08002100 mos7840_port->read_urb_busy = false;
Paul B Schroeder3f542972006-08-31 19:41:47 -05002101 }
2102 }
Paul B Schroeder3f542972006-08-31 19:41:47 -05002103}
2104
2105/*****************************************************************************
2106 * mos7840_get_lsr_info - get line status register info
2107 *
2108 * Purpose: Let user call ioctl() to get info when the UART physically
2109 * is emptied. On bus types like RS485, the transmitter must
2110 * release the bus after transmitting. This must be done when
2111 * the transmit shift register is empty, not be done when the
2112 * transmit holding register is empty. This functionality
2113 * allows an RS485 driver to be written in user space.
2114 *****************************************************************************/
2115
Alan Cox95da3102008-07-22 11:09:07 +01002116static int mos7840_get_lsr_info(struct tty_struct *tty,
Al Viro97c49652006-10-09 20:29:03 +01002117 unsigned int __user *value)
Paul B Schroeder3f542972006-08-31 19:41:47 -05002118{
2119 int count;
2120 unsigned int result = 0;
2121
Alan Cox95da3102008-07-22 11:09:07 +01002122 count = mos7840_chars_in_buffer(tty);
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002123 if (count == 0)
Paul B Schroeder3f542972006-08-31 19:41:47 -05002124 result = TIOCSER_TEMT;
Paul B Schroeder3f542972006-08-31 19:41:47 -05002125
2126 if (copy_to_user(value, &result, sizeof(int)))
2127 return -EFAULT;
2128 return 0;
2129}
2130
2131/*****************************************************************************
Paul B Schroeder3f542972006-08-31 19:41:47 -05002132 * mos7840_get_serial_info
2133 * function to get information about serial port
2134 *****************************************************************************/
2135
2136static int mos7840_get_serial_info(struct moschip_port *mos7840_port,
Al Viro97c49652006-10-09 20:29:03 +01002137 struct serial_struct __user *retinfo)
Paul B Schroeder3f542972006-08-31 19:41:47 -05002138{
2139 struct serial_struct tmp;
2140
2141 if (mos7840_port == NULL)
2142 return -1;
2143
2144 if (!retinfo)
2145 return -EFAULT;
2146
2147 memset(&tmp, 0, sizeof(tmp));
2148
2149 tmp.type = PORT_16550A;
2150 tmp.line = mos7840_port->port->serial->minor;
2151 tmp.port = mos7840_port->port->number;
2152 tmp.irq = 0;
2153 tmp.flags = ASYNC_SKIP_TEST | ASYNC_AUTO_IRQ;
2154 tmp.xmit_fifo_size = NUM_URBS * URB_TRANSFER_BUFFER_SIZE;
2155 tmp.baud_base = 9600;
2156 tmp.close_delay = 5 * HZ;
2157 tmp.closing_wait = 30 * HZ;
2158
2159 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
2160 return -EFAULT;
2161 return 0;
2162}
2163
Alan Cox0bca1b92010-09-16 18:21:40 +01002164static int mos7840_get_icount(struct tty_struct *tty,
2165 struct serial_icounter_struct *icount)
2166{
2167 struct usb_serial_port *port = tty->driver_data;
2168 struct moschip_port *mos7840_port;
2169 struct async_icount cnow;
2170
2171 mos7840_port = mos7840_get_port_private(port);
2172 cnow = mos7840_port->icount;
2173
2174 smp_rmb();
2175 icount->cts = cnow.cts;
2176 icount->dsr = cnow.dsr;
2177 icount->rng = cnow.rng;
2178 icount->dcd = cnow.dcd;
2179 icount->rx = cnow.rx;
2180 icount->tx = cnow.tx;
2181 icount->frame = cnow.frame;
2182 icount->overrun = cnow.overrun;
2183 icount->parity = cnow.parity;
2184 icount->brk = cnow.brk;
2185 icount->buf_overrun = cnow.buf_overrun;
2186
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002187 dev_dbg(&port->dev, "%s TIOCGICOUNT RX=%d, TX=%d\n", __func__,
2188 icount->rx, icount->tx);
Alan Cox0bca1b92010-09-16 18:21:40 +01002189 return 0;
2190}
2191
Paul B Schroeder3f542972006-08-31 19:41:47 -05002192/*****************************************************************************
2193 * SerialIoctl
2194 * this function handles any ioctl calls to the driver
2195 *****************************************************************************/
2196
Alan Cox00a0d0d2011-02-14 16:27:06 +00002197static int mos7840_ioctl(struct tty_struct *tty,
Paul B Schroeder3f542972006-08-31 19:41:47 -05002198 unsigned int cmd, unsigned long arg)
2199{
Alan Cox95da3102008-07-22 11:09:07 +01002200 struct usb_serial_port *port = tty->driver_data;
Al Viro97c49652006-10-09 20:29:03 +01002201 void __user *argp = (void __user *)arg;
Paul B Schroeder3f542972006-08-31 19:41:47 -05002202 struct moschip_port *mos7840_port;
Paul B Schroeder3f542972006-08-31 19:41:47 -05002203
2204 struct async_icount cnow;
2205 struct async_icount cprev;
Paul B Schroeder3f542972006-08-31 19:41:47 -05002206
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002207 if (mos7840_port_paranoia_check(port, __func__))
Paul B Schroeder3f542972006-08-31 19:41:47 -05002208 return -1;
Paul B Schroeder3f542972006-08-31 19:41:47 -05002209
2210 mos7840_port = mos7840_get_port_private(port);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002211
2212 if (mos7840_port == NULL)
2213 return -1;
2214
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002215 dev_dbg(&port->dev, "%s - cmd = 0x%x\n", __func__, cmd);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002216
2217 switch (cmd) {
2218 /* return number of bytes available */
2219
Paul B Schroeder3f542972006-08-31 19:41:47 -05002220 case TIOCSERGETLSR:
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002221 dev_dbg(&port->dev, "%s TIOCSERGETLSR\n", __func__);
Alan Cox95da3102008-07-22 11:09:07 +01002222 return mos7840_get_lsr_info(tty, argp);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002223
Paul B Schroeder3f542972006-08-31 19:41:47 -05002224 case TIOCGSERIAL:
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002225 dev_dbg(&port->dev, "%s TIOCGSERIAL\n", __func__);
Al Viro97c49652006-10-09 20:29:03 +01002226 return mos7840_get_serial_info(mos7840_port, argp);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002227
2228 case TIOCSSERIAL:
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002229 dev_dbg(&port->dev, "%s TIOCSSERIAL\n", __func__);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002230 break;
2231
2232 case TIOCMIWAIT:
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002233 dev_dbg(&port->dev, "%s TIOCMIWAIT\n", __func__);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002234 cprev = mos7840_port->icount;
2235 while (1) {
Alan Cox880af9d2008-07-22 11:16:12 +01002236 /* interruptible_sleep_on(&mos7840_port->delta_msr_wait); */
Paul B Schroeder3f542972006-08-31 19:41:47 -05002237 mos7840_port->delta_msr_cond = 0;
2238 wait_event_interruptible(mos7840_port->delta_msr_wait,
2239 (mos7840_port->
2240 delta_msr_cond == 1));
2241
2242 /* see if a signal did it */
2243 if (signal_pending(current))
2244 return -ERESTARTSYS;
2245 cnow = mos7840_port->icount;
Oliver Neukum0de9a702007-03-16 20:28:28 +01002246 smp_rmb();
Paul B Schroeder3f542972006-08-31 19:41:47 -05002247 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
2248 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts)
2249 return -EIO; /* no change => error */
2250 if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
2251 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
2252 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
2253 ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts))) {
2254 return 0;
2255 }
2256 cprev = cnow;
2257 }
2258 /* NOTREACHED */
2259 break;
2260
Paul B Schroeder3f542972006-08-31 19:41:47 -05002261 default:
2262 break;
2263 }
Paul B Schroeder3f542972006-08-31 19:41:47 -05002264 return -ENOIOCTLCMD;
2265}
2266
Donald0eafe4d2012-04-19 15:00:45 +08002267static int mos7810_check(struct usb_serial *serial)
2268{
2269 int i, pass_count = 0;
2270 __u16 data = 0, mcr_data = 0;
2271 __u16 test_pattern = 0x55AA;
2272
2273 /* Store MCR setting */
2274 usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
2275 MCS_RDREQ, MCS_RD_RTYPE, 0x0300, MODEM_CONTROL_REGISTER,
2276 &mcr_data, VENDOR_READ_LENGTH, MOS_WDR_TIMEOUT);
2277
2278 for (i = 0; i < 16; i++) {
2279 /* Send the 1-bit test pattern out to MCS7810 test pin */
2280 usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
2281 MCS_WRREQ, MCS_WR_RTYPE,
2282 (0x0300 | (((test_pattern >> i) & 0x0001) << 1)),
2283 MODEM_CONTROL_REGISTER, NULL, 0, MOS_WDR_TIMEOUT);
2284
2285 /* Read the test pattern back */
2286 usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
2287 MCS_RDREQ, MCS_RD_RTYPE, 0, GPIO_REGISTER, &data,
2288 VENDOR_READ_LENGTH, MOS_WDR_TIMEOUT);
2289
2290 /* If this is a MCS7810 device, both test patterns must match */
2291 if (((test_pattern >> i) ^ (~data >> 1)) & 0x0001)
2292 break;
2293
2294 pass_count++;
2295 }
2296
2297 /* Restore MCR setting */
2298 usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), MCS_WRREQ,
2299 MCS_WR_RTYPE, 0x0300 | mcr_data, MODEM_CONTROL_REGISTER, NULL,
2300 0, MOS_WDR_TIMEOUT);
2301
2302 if (pass_count == 16)
2303 return 1;
2304
2305 return 0;
2306}
2307
Paul B Schroeder3f542972006-08-31 19:41:47 -05002308static int mos7840_calc_num_ports(struct usb_serial *serial)
2309{
Donald0eafe4d2012-04-19 15:00:45 +08002310 __u16 data = 0x00;
Donald Lee093ea2d2012-03-14 15:26:33 +08002311 int mos7840_num_ports;
Paul B Schroeder3f542972006-08-31 19:41:47 -05002312
Donald0eafe4d2012-04-19 15:00:45 +08002313 usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
2314 MCS_RDREQ, MCS_RD_RTYPE, 0, GPIO_REGISTER, &data,
Donald Lee093ea2d2012-03-14 15:26:33 +08002315 VENDOR_READ_LENGTH, MOS_WDR_TIMEOUT);
2316
Donald0eafe4d2012-04-19 15:00:45 +08002317 if (serial->dev->descriptor.idProduct == MOSCHIP_DEVICE_ID_7810 ||
2318 serial->dev->descriptor.idProduct == MOSCHIP_DEVICE_ID_7820) {
2319 device_type = serial->dev->descriptor.idProduct;
Donald Lee093ea2d2012-03-14 15:26:33 +08002320 } else {
Donald0eafe4d2012-04-19 15:00:45 +08002321 /* For a MCS7840 device GPIO0 must be set to 1 */
2322 if ((data & 0x01) == 1)
2323 device_type = MOSCHIP_DEVICE_ID_7840;
2324 else if (mos7810_check(serial))
2325 device_type = MOSCHIP_DEVICE_ID_7810;
2326 else
2327 device_type = MOSCHIP_DEVICE_ID_7820;
Paul B Schroeder3f542972006-08-31 19:41:47 -05002328 }
Donald Lee093ea2d2012-03-14 15:26:33 +08002329
Donald0eafe4d2012-04-19 15:00:45 +08002330 mos7840_num_ports = (device_type >> 4) & 0x000F;
2331 serial->num_bulk_in = mos7840_num_ports;
2332 serial->num_bulk_out = mos7840_num_ports;
2333 serial->num_ports = mos7840_num_ports;
2334
Paul B Schroeder3f542972006-08-31 19:41:47 -05002335 return mos7840_num_ports;
2336}
2337
2338/****************************************************************************
2339 * mos7840_startup
2340 ****************************************************************************/
2341
2342static int mos7840_startup(struct usb_serial *serial)
2343{
2344 struct moschip_port *mos7840_port;
2345 struct usb_device *dev;
2346 int i, status;
Paul B Schroeder3f542972006-08-31 19:41:47 -05002347 __u16 Data;
Paul B Schroeder3f542972006-08-31 19:41:47 -05002348
Paul B Schroeder3f542972006-08-31 19:41:47 -05002349 dev = serial->dev;
2350
Paul B Schroeder3f542972006-08-31 19:41:47 -05002351 /* we set up the pointers to the endpoints in the mos7840_open *
2352 * function, as the structures aren't created yet. */
2353
2354 /* set up port private structures */
2355 for (i = 0; i < serial->num_ports; ++i) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002356 dev_dbg(&dev->dev, "mos7840_startup: configuring port %d............\n", i);
Burman Yan7ac9da12006-11-22 20:54:38 +02002357 mos7840_port = kzalloc(sizeof(struct moschip_port), GFP_KERNEL);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002358 if (mos7840_port == NULL) {
Greg Kroah-Hartman194343d2008-08-20 16:56:34 -07002359 dev_err(&dev->dev, "%s - Out of memory\n", __func__);
Oliver Neukum0de9a702007-03-16 20:28:28 +01002360 status = -ENOMEM;
2361 i--; /* don't follow NULL pointer cleaning up */
2362 goto error;
Paul B Schroeder3f542972006-08-31 19:41:47 -05002363 }
Paul B Schroeder3f542972006-08-31 19:41:47 -05002364
Alan Cox880af9d2008-07-22 11:16:12 +01002365 /* Initialize all port interrupt end point to port 0 int
2366 * endpoint. Our device has only one interrupt end point
2367 * common to all port */
Paul B Schroeder3f542972006-08-31 19:41:47 -05002368
2369 mos7840_port->port = serial->port[i];
2370 mos7840_set_port_private(serial->port[i], mos7840_port);
Oliver Neukum0de9a702007-03-16 20:28:28 +01002371 spin_lock_init(&mos7840_port->pool_lock);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002372
Tony Cook37768ad2009-04-18 22:42:18 +09302373 /* minor is not initialised until later by
2374 * usb-serial.c:get_free_serial() and cannot therefore be used
2375 * to index device instances */
2376 mos7840_port->port_num = i + 1;
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002377 dev_dbg(&dev->dev, "serial->port[i]->number = %d\n", serial->port[i]->number);
2378 dev_dbg(&dev->dev, "serial->port[i]->serial->minor = %d\n", serial->port[i]->serial->minor);
2379 dev_dbg(&dev->dev, "mos7840_port->port_num = %d\n", mos7840_port->port_num);
2380 dev_dbg(&dev->dev, "serial->minor = %d\n", serial->minor);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002381
2382 if (mos7840_port->port_num == 1) {
2383 mos7840_port->SpRegOffset = 0x0;
2384 mos7840_port->ControlRegOffset = 0x1;
2385 mos7840_port->DcrRegOffset = 0x4;
2386 } else if ((mos7840_port->port_num == 2)
Oliver Neukum0de9a702007-03-16 20:28:28 +01002387 && (serial->num_ports == 4)) {
Paul B Schroeder3f542972006-08-31 19:41:47 -05002388 mos7840_port->SpRegOffset = 0x8;
2389 mos7840_port->ControlRegOffset = 0x9;
2390 mos7840_port->DcrRegOffset = 0x16;
2391 } else if ((mos7840_port->port_num == 2)
Oliver Neukum0de9a702007-03-16 20:28:28 +01002392 && (serial->num_ports == 2)) {
Paul B Schroeder3f542972006-08-31 19:41:47 -05002393 mos7840_port->SpRegOffset = 0xa;
2394 mos7840_port->ControlRegOffset = 0xb;
2395 mos7840_port->DcrRegOffset = 0x19;
2396 } else if ((mos7840_port->port_num == 3)
Oliver Neukum0de9a702007-03-16 20:28:28 +01002397 && (serial->num_ports == 4)) {
Paul B Schroeder3f542972006-08-31 19:41:47 -05002398 mos7840_port->SpRegOffset = 0xa;
2399 mos7840_port->ControlRegOffset = 0xb;
2400 mos7840_port->DcrRegOffset = 0x19;
2401 } else if ((mos7840_port->port_num == 4)
Oliver Neukum0de9a702007-03-16 20:28:28 +01002402 && (serial->num_ports == 4)) {
Paul B Schroeder3f542972006-08-31 19:41:47 -05002403 mos7840_port->SpRegOffset = 0xc;
2404 mos7840_port->ControlRegOffset = 0xd;
2405 mos7840_port->DcrRegOffset = 0x1c;
2406 }
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002407 mos7840_dump_serial_port(serial->port[i], mos7840_port);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002408 mos7840_set_port_private(serial->port[i], mos7840_port);
2409
Alan Cox880af9d2008-07-22 11:16:12 +01002410 /* enable rx_disable bit in control register */
2411 status = mos7840_get_reg_sync(serial->port[i],
2412 mos7840_port->ControlRegOffset, &Data);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002413 if (status < 0) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002414 dev_dbg(&dev->dev, "Reading ControlReg failed status-0x%x\n", status);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002415 break;
2416 } else
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002417 dev_dbg(&dev->dev, "ControlReg Reading success val is %x, status%d\n", Data, status);
Alan Cox880af9d2008-07-22 11:16:12 +01002418 Data |= 0x08; /* setting driver done bit */
2419 Data |= 0x04; /* sp1_bit to have cts change reflect in
2420 modem status reg */
Paul B Schroeder3f542972006-08-31 19:41:47 -05002421
Alan Cox880af9d2008-07-22 11:16:12 +01002422 /* Data |= 0x20; //rx_disable bit */
2423 status = mos7840_set_reg_sync(serial->port[i],
Paul B Schroeder3f542972006-08-31 19:41:47 -05002424 mos7840_port->ControlRegOffset, Data);
2425 if (status < 0) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002426 dev_dbg(&dev->dev, "Writing ControlReg failed(rx_disable) status-0x%x\n", status);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002427 break;
2428 } else
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002429 dev_dbg(&dev->dev, "ControlReg Writing success(rx_disable) status%d\n", status);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002430
Alan Cox880af9d2008-07-22 11:16:12 +01002431 /* Write default values in DCR (i.e 0x01 in DCR0, 0x05 in DCR2
2432 and 0x24 in DCR3 */
Paul B Schroeder3f542972006-08-31 19:41:47 -05002433 Data = 0x01;
Alan Cox880af9d2008-07-22 11:16:12 +01002434 status = mos7840_set_reg_sync(serial->port[i],
2435 (__u16) (mos7840_port->DcrRegOffset + 0), Data);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002436 if (status < 0) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002437 dev_dbg(&dev->dev, "Writing DCR0 failed status-0x%x\n", status);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002438 break;
2439 } else
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002440 dev_dbg(&dev->dev, "DCR0 Writing success status%d\n", status);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002441
2442 Data = 0x05;
Alan Cox880af9d2008-07-22 11:16:12 +01002443 status = mos7840_set_reg_sync(serial->port[i],
2444 (__u16) (mos7840_port->DcrRegOffset + 1), Data);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002445 if (status < 0) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002446 dev_dbg(&dev->dev, "Writing DCR1 failed status-0x%x\n", status);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002447 break;
2448 } else
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002449 dev_dbg(&dev->dev, "DCR1 Writing success status%d\n", status);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002450
2451 Data = 0x24;
Alan Cox880af9d2008-07-22 11:16:12 +01002452 status = mos7840_set_reg_sync(serial->port[i],
2453 (__u16) (mos7840_port->DcrRegOffset + 2), Data);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002454 if (status < 0) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002455 dev_dbg(&dev->dev, "Writing DCR2 failed status-0x%x\n", status);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002456 break;
2457 } else
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002458 dev_dbg(&dev->dev, "DCR2 Writing success status%d\n", status);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002459
Alan Cox880af9d2008-07-22 11:16:12 +01002460 /* write values in clkstart0x0 and clkmulti 0x20 */
Paul B Schroeder3f542972006-08-31 19:41:47 -05002461 Data = 0x0;
Alan Cox880af9d2008-07-22 11:16:12 +01002462 status = mos7840_set_reg_sync(serial->port[i],
Paul B Schroeder3f542972006-08-31 19:41:47 -05002463 CLK_START_VALUE_REGISTER, Data);
2464 if (status < 0) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002465 dev_dbg(&dev->dev, "Writing CLK_START_VALUE_REGISTER failed status-0x%x\n", status);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002466 break;
2467 } else
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002468 dev_dbg(&dev->dev, "CLK_START_VALUE_REGISTER Writing success status%d\n", status);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002469
2470 Data = 0x20;
Alan Cox880af9d2008-07-22 11:16:12 +01002471 status = mos7840_set_reg_sync(serial->port[i],
2472 CLK_MULTI_REGISTER, Data);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002473 if (status < 0) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002474 dev_dbg(&dev->dev, "Writing CLK_MULTI_REGISTER failed status-0x%x\n", status);
Oliver Neukum0de9a702007-03-16 20:28:28 +01002475 goto error;
Paul B Schroeder3f542972006-08-31 19:41:47 -05002476 } else
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002477 dev_dbg(&dev->dev, "CLK_MULTI_REGISTER Writing success status%d\n", status);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002478
Alan Cox880af9d2008-07-22 11:16:12 +01002479 /* write value 0x0 to scratchpad register */
Paul B Schroeder3f542972006-08-31 19:41:47 -05002480 Data = 0x00;
Alan Cox880af9d2008-07-22 11:16:12 +01002481 status = mos7840_set_uart_reg(serial->port[i],
2482 SCRATCH_PAD_REGISTER, Data);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002483 if (status < 0) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002484 dev_dbg(&dev->dev, "Writing SCRATCH_PAD_REGISTER failed status-0x%x\n", status);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002485 break;
2486 } else
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002487 dev_dbg(&dev->dev, "SCRATCH_PAD_REGISTER Writing success status%d\n", status);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002488
Alan Cox880af9d2008-07-22 11:16:12 +01002489 /* Zero Length flag register */
Paul B Schroeder3f542972006-08-31 19:41:47 -05002490 if ((mos7840_port->port_num != 1)
Oliver Neukum0de9a702007-03-16 20:28:28 +01002491 && (serial->num_ports == 2)) {
Paul B Schroeder3f542972006-08-31 19:41:47 -05002492
2493 Data = 0xff;
Paul B Schroeder3f542972006-08-31 19:41:47 -05002494 status = mos7840_set_reg_sync(serial->port[i],
Alan Cox880af9d2008-07-22 11:16:12 +01002495 (__u16) (ZLP_REG1 +
2496 ((__u16)mos7840_port->port_num)), Data);
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002497 dev_dbg(&dev->dev, "ZLIP offset %x\n",
2498 (__u16)(ZLP_REG1 + ((__u16) mos7840_port->port_num)));
Paul B Schroeder3f542972006-08-31 19:41:47 -05002499 if (status < 0) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002500 dev_dbg(&dev->dev, "Writing ZLP_REG%d failed status-0x%x\n", i + 2, status);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002501 break;
2502 } else
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002503 dev_dbg(&dev->dev, "ZLP_REG%d Writing success status%d\n", i + 2, status);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002504 } else {
2505 Data = 0xff;
Paul B Schroeder3f542972006-08-31 19:41:47 -05002506 status = mos7840_set_reg_sync(serial->port[i],
Alan Cox880af9d2008-07-22 11:16:12 +01002507 (__u16) (ZLP_REG1 +
2508 ((__u16)mos7840_port->port_num) - 0x1), Data);
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002509 dev_dbg(&dev->dev, "ZLIP offset %x\n",
2510 (__u16)(ZLP_REG1 + ((__u16) mos7840_port->port_num) - 0x1));
Paul B Schroeder3f542972006-08-31 19:41:47 -05002511 if (status < 0) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002512 dev_dbg(&dev->dev, "Writing ZLP_REG%d failed status-0x%x\n", i + 1, status);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002513 break;
2514 } else
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002515 dev_dbg(&dev->dev, "ZLP_REG%d Writing success status%d\n", i + 1, status);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002516
2517 }
Oliver Neukum0de9a702007-03-16 20:28:28 +01002518 mos7840_port->control_urb = usb_alloc_urb(0, GFP_KERNEL);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002519 mos7840_port->ctrl_buf = kmalloc(16, GFP_KERNEL);
Alan Cox880af9d2008-07-22 11:16:12 +01002520 mos7840_port->dr = kmalloc(sizeof(struct usb_ctrlrequest),
2521 GFP_KERNEL);
2522 if (!mos7840_port->control_urb || !mos7840_port->ctrl_buf ||
2523 !mos7840_port->dr) {
Oliver Neukum0de9a702007-03-16 20:28:28 +01002524 status = -ENOMEM;
2525 goto error;
2526 }
Donald0eafe4d2012-04-19 15:00:45 +08002527
2528 mos7840_port->has_led = false;
2529
2530 /* Initialize LED timers */
2531 if (device_type == MOSCHIP_DEVICE_ID_7810) {
2532 mos7840_port->has_led = true;
2533
2534 init_timer(&mos7840_port->led_timer1);
2535 mos7840_port->led_timer1.function = mos7840_led_off;
2536 mos7840_port->led_timer1.expires =
2537 jiffies + msecs_to_jiffies(LED_ON_MS);
2538 mos7840_port->led_timer1.data =
2539 (unsigned long)mos7840_port;
2540
2541 init_timer(&mos7840_port->led_timer2);
2542 mos7840_port->led_timer2.function =
2543 mos7840_led_flag_off;
2544 mos7840_port->led_timer2.expires =
2545 jiffies + msecs_to_jiffies(LED_OFF_MS);
2546 mos7840_port->led_timer2.data =
2547 (unsigned long)mos7840_port;
2548
2549 mos7840_port->led_flag = false;
2550
2551 /* Turn off LED */
2552 mos7840_set_led_sync(serial->port[i],
2553 MODEM_CONTROL_REGISTER, 0x0300);
2554 }
Paul B Schroeder3f542972006-08-31 19:41:47 -05002555 }
2556
Alan Cox880af9d2008-07-22 11:16:12 +01002557 /* Zero Length flag enable */
Paul B Schroeder3f542972006-08-31 19:41:47 -05002558 Data = 0x0f;
Paul B Schroeder3f542972006-08-31 19:41:47 -05002559 status = mos7840_set_reg_sync(serial->port[0], ZLP_REG5, Data);
2560 if (status < 0) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002561 dev_dbg(&dev->dev, "Writing ZLP_REG5 failed status-0x%x\n", status);
Roel Kluin7ced46c2007-10-27 03:36:37 +02002562 goto error;
Paul B Schroeder3f542972006-08-31 19:41:47 -05002563 } else
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002564 dev_dbg(&dev->dev, "ZLP_REG5 Writing success status%d\n", status);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002565
2566 /* setting configuration feature to one */
2567 usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
Mark Ferrell1e658482012-07-24 13:38:31 -05002568 (__u8) 0x03, 0x00, 0x01, 0x00, NULL, 0x00, MOS_WDR_TIMEOUT);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002569 return 0;
Oliver Neukum0de9a702007-03-16 20:28:28 +01002570error:
2571 for (/* nothing */; i >= 0; i--) {
2572 mos7840_port = mos7840_get_port_private(serial->port[i]);
2573
2574 kfree(mos7840_port->dr);
2575 kfree(mos7840_port->ctrl_buf);
2576 usb_free_urb(mos7840_port->control_urb);
2577 kfree(mos7840_port);
Oliver Neukum0de9a702007-03-16 20:28:28 +01002578 }
2579 return status;
Paul B Schroeder3f542972006-08-31 19:41:47 -05002580}
2581
2582/****************************************************************************
Alan Sternf9c99bb2009-06-02 11:53:55 -04002583 * mos7840_disconnect
Paul B Schroeder3f542972006-08-31 19:41:47 -05002584 * This function is called whenever the device is removed from the usb bus.
2585 ****************************************************************************/
2586
Alan Sternf9c99bb2009-06-02 11:53:55 -04002587static void mos7840_disconnect(struct usb_serial *serial)
Paul B Schroeder3f542972006-08-31 19:41:47 -05002588{
2589 int i;
Oliver Neukum0de9a702007-03-16 20:28:28 +01002590 unsigned long flags;
Paul B Schroeder3f542972006-08-31 19:41:47 -05002591 struct moschip_port *mos7840_port;
Paul B Schroeder3f542972006-08-31 19:41:47 -05002592
Alan Cox880af9d2008-07-22 11:16:12 +01002593 /* check for the ports to be closed,close the ports and disconnect */
Paul B Schroeder3f542972006-08-31 19:41:47 -05002594
2595 /* free private structure allocated for serial port *
2596 * stop reads and writes on all ports */
2597
2598 for (i = 0; i < serial->num_ports; ++i) {
2599 mos7840_port = mos7840_get_port_private(serial->port[i]);
Tony Cook37768ad2009-04-18 22:42:18 +09302600 if (mos7840_port) {
2601 spin_lock_irqsave(&mos7840_port->pool_lock, flags);
2602 mos7840_port->zombie = 1;
2603 spin_unlock_irqrestore(&mos7840_port->pool_lock, flags);
2604 usb_kill_urb(mos7840_port->control_urb);
Alan Sternf9c99bb2009-06-02 11:53:55 -04002605 }
2606 }
Alan Sternf9c99bb2009-06-02 11:53:55 -04002607}
2608
2609/****************************************************************************
2610 * mos7840_release
2611 * This function is called when the usb_serial structure is freed.
2612 ****************************************************************************/
2613
2614static void mos7840_release(struct usb_serial *serial)
2615{
2616 int i;
2617 struct moschip_port *mos7840_port;
Alan Sternf9c99bb2009-06-02 11:53:55 -04002618
Alan Sternf9c99bb2009-06-02 11:53:55 -04002619 /* check for the ports to be closed,close the ports and disconnect */
2620
2621 /* free private structure allocated for serial port *
2622 * stop reads and writes on all ports */
2623
2624 for (i = 0; i < serial->num_ports; ++i) {
2625 mos7840_port = mos7840_get_port_private(serial->port[i]);
Alan Sternf9c99bb2009-06-02 11:53:55 -04002626 if (mos7840_port) {
Donald0eafe4d2012-04-19 15:00:45 +08002627 if (mos7840_port->has_led) {
2628 /* Turn off LED */
2629 mos7840_set_led_sync(mos7840_port->port,
2630 MODEM_CONTROL_REGISTER, 0x0300);
2631
2632 del_timer_sync(&mos7840_port->led_timer1);
2633 del_timer_sync(&mos7840_port->led_timer2);
2634 }
Johan Hovold65a4cdb2012-10-25 13:35:09 +02002635 usb_free_urb(mos7840_port->control_urb);
Tony Cook37768ad2009-04-18 22:42:18 +09302636 kfree(mos7840_port->ctrl_buf);
2637 kfree(mos7840_port->dr);
2638 kfree(mos7840_port);
2639 }
Paul B Schroeder3f542972006-08-31 19:41:47 -05002640 }
Paul B Schroeder3f542972006-08-31 19:41:47 -05002641}
2642
2643static struct usb_serial_driver moschip7840_4port_device = {
2644 .driver = {
2645 .owner = THIS_MODULE,
2646 .name = "mos7840",
2647 },
2648 .description = DRIVER_DESC,
Greg Kroah-Hartman68e24112012-05-08 15:46:14 -07002649 .id_table = id_table,
Paul B Schroeder3f542972006-08-31 19:41:47 -05002650 .num_ports = 4,
Paul B Schroeder3f542972006-08-31 19:41:47 -05002651 .open = mos7840_open,
2652 .close = mos7840_close,
2653 .write = mos7840_write,
2654 .write_room = mos7840_write_room,
2655 .chars_in_buffer = mos7840_chars_in_buffer,
2656 .throttle = mos7840_throttle,
2657 .unthrottle = mos7840_unthrottle,
2658 .calc_num_ports = mos7840_calc_num_ports,
2659#ifdef MCSSerialProbe
2660 .probe = mos7840_serial_probe,
2661#endif
2662 .ioctl = mos7840_ioctl,
2663 .set_termios = mos7840_set_termios,
2664 .break_ctl = mos7840_break,
2665 .tiocmget = mos7840_tiocmget,
2666 .tiocmset = mos7840_tiocmset,
Alan Cox0bca1b92010-09-16 18:21:40 +01002667 .get_icount = mos7840_get_icount,
Paul B Schroeder3f542972006-08-31 19:41:47 -05002668 .attach = mos7840_startup,
Alan Sternf9c99bb2009-06-02 11:53:55 -04002669 .disconnect = mos7840_disconnect,
2670 .release = mos7840_release,
Paul B Schroeder3f542972006-08-31 19:41:47 -05002671 .read_bulk_callback = mos7840_bulk_in_callback,
2672 .read_int_callback = mos7840_interrupt_callback,
2673};
2674
Alan Stern4d2a7af2012-02-23 14:57:09 -05002675static struct usb_serial_driver * const serial_drivers[] = {
2676 &moschip7840_4port_device, NULL
2677};
2678
Greg Kroah-Hartman68e24112012-05-08 15:46:14 -07002679module_usb_serial_driver(serial_drivers, id_table);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002680
Paul B Schroeder3f542972006-08-31 19:41:47 -05002681MODULE_DESCRIPTION(DRIVER_DESC);
2682MODULE_LICENSE("GPL");