blob: 35ad3f5c4c0e2cb5e5767b787ce763df482960de [file] [log] [blame]
Paul B Schroeder3f542972006-08-31 19:41:47 -05001/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15 *
16 * Clean ups from Moschip version and a few ioctl implementations by:
17 * Paul B Schroeder <pschroeder "at" uplogix "dot" com>
18 *
19 * Originally based on drivers/usb/serial/io_edgeport.c which is:
20 * Copyright (C) 2000 Inside Out Networks, All rights reserved.
21 * Copyright (C) 2001-2002 Greg Kroah-Hartman <greg@kroah.com>
22 *
23 */
24
25#include <linux/kernel.h>
26#include <linux/errno.h>
27#include <linux/init.h>
28#include <linux/slab.h>
29#include <linux/tty.h>
30#include <linux/tty_driver.h>
31#include <linux/tty_flip.h>
32#include <linux/module.h>
33#include <linux/serial.h>
34#include <linux/usb.h>
35#include <linux/usb/serial.h>
Alan Cox880af9d2008-07-22 11:16:12 +010036#include <linux/uaccess.h>
Paul B Schroeder3f542972006-08-31 19:41:47 -050037
38/*
39 * Version Information
40 */
Tony Cook37768ad2009-04-18 22:42:18 +093041#define DRIVER_VERSION "1.3.2"
Paul B Schroeder3f542972006-08-31 19:41:47 -050042#define DRIVER_DESC "Moschip 7840/7820 USB Serial Driver"
43
44/*
45 * 16C50 UART register defines
46 */
47
48#define LCR_BITS_5 0x00 /* 5 bits/char */
49#define LCR_BITS_6 0x01 /* 6 bits/char */
50#define LCR_BITS_7 0x02 /* 7 bits/char */
51#define LCR_BITS_8 0x03 /* 8 bits/char */
52#define LCR_BITS_MASK 0x03 /* Mask for bits/char field */
53
54#define LCR_STOP_1 0x00 /* 1 stop bit */
55#define LCR_STOP_1_5 0x04 /* 1.5 stop bits (if 5 bits/char) */
56#define LCR_STOP_2 0x04 /* 2 stop bits (if 6-8 bits/char) */
57#define LCR_STOP_MASK 0x04 /* Mask for stop bits field */
58
59#define LCR_PAR_NONE 0x00 /* No parity */
60#define LCR_PAR_ODD 0x08 /* Odd parity */
61#define LCR_PAR_EVEN 0x18 /* Even parity */
62#define LCR_PAR_MARK 0x28 /* Force parity bit to 1 */
63#define LCR_PAR_SPACE 0x38 /* Force parity bit to 0 */
64#define LCR_PAR_MASK 0x38 /* Mask for parity field */
65
66#define LCR_SET_BREAK 0x40 /* Set Break condition */
67#define LCR_DL_ENABLE 0x80 /* Enable access to divisor latch */
68
69#define MCR_DTR 0x01 /* Assert DTR */
70#define MCR_RTS 0x02 /* Assert RTS */
71#define MCR_OUT1 0x04 /* Loopback only: Sets state of RI */
72#define MCR_MASTER_IE 0x08 /* Enable interrupt outputs */
73#define MCR_LOOPBACK 0x10 /* Set internal (digital) loopback mode */
74#define MCR_XON_ANY 0x20 /* Enable any char to exit XOFF mode */
75
76#define MOS7840_MSR_CTS 0x10 /* Current state of CTS */
77#define MOS7840_MSR_DSR 0x20 /* Current state of DSR */
78#define MOS7840_MSR_RI 0x40 /* Current state of RI */
79#define MOS7840_MSR_CD 0x80 /* Current state of CD */
80
81/*
82 * Defines used for sending commands to port
83 */
84
Mark Ferrell1e658482012-07-24 13:38:31 -050085#define MOS_WDR_TIMEOUT 5000 /* default urb timeout */
Paul B Schroeder3f542972006-08-31 19:41:47 -050086
87#define MOS_PORT1 0x0200
88#define MOS_PORT2 0x0300
89#define MOS_VENREG 0x0000
90#define MOS_MAX_PORT 0x02
91#define MOS_WRITE 0x0E
92#define MOS_READ 0x0D
93
94/* Requests */
95#define MCS_RD_RTYPE 0xC0
96#define MCS_WR_RTYPE 0x40
97#define MCS_RDREQ 0x0D
98#define MCS_WRREQ 0x0E
99#define MCS_CTRL_TIMEOUT 500
100#define VENDOR_READ_LENGTH (0x01)
101
102#define MAX_NAME_LEN 64
103
Alan Cox880af9d2008-07-22 11:16:12 +0100104#define ZLP_REG1 0x3A /* Zero_Flag_Reg1 58 */
105#define ZLP_REG5 0x3E /* Zero_Flag_Reg5 62 */
Paul B Schroeder3f542972006-08-31 19:41:47 -0500106
107/* For higher baud Rates use TIOCEXBAUD */
108#define TIOCEXBAUD 0x5462
109
110/* vendor id and device id defines */
111
David Ludlow11e1abb2008-02-25 17:30:52 -0500112/* The native mos7840/7820 component */
Paul B Schroeder3f542972006-08-31 19:41:47 -0500113#define USB_VENDOR_ID_MOSCHIP 0x9710
114#define MOSCHIP_DEVICE_ID_7840 0x7840
115#define MOSCHIP_DEVICE_ID_7820 0x7820
Donald0eafe4d2012-04-19 15:00:45 +0800116#define MOSCHIP_DEVICE_ID_7810 0x7810
David Ludlow11e1abb2008-02-25 17:30:52 -0500117/* The native component can have its vendor/device id's overridden
118 * in vendor-specific implementations. Such devices can be handled
Greg Kroah-Hartman68e24112012-05-08 15:46:14 -0700119 * by making a change here, in id_table.
David Ludlow11e1abb2008-02-25 17:30:52 -0500120 */
Dave Ludlow870408c2010-09-01 12:33:30 -0400121#define USB_VENDOR_ID_BANDB 0x0856
122#define BANDB_DEVICE_ID_USO9ML2_2 0xAC22
123#define BANDB_DEVICE_ID_USO9ML2_2P 0xBC00
124#define BANDB_DEVICE_ID_USO9ML2_4 0xAC24
125#define BANDB_DEVICE_ID_USO9ML2_4P 0xBC01
126#define BANDB_DEVICE_ID_US9ML2_2 0xAC29
127#define BANDB_DEVICE_ID_US9ML2_4 0xAC30
128#define BANDB_DEVICE_ID_USPTL4_2 0xAC31
129#define BANDB_DEVICE_ID_USPTL4_4 0xAC32
130#define BANDB_DEVICE_ID_USOPTL4_2 0xAC42
131#define BANDB_DEVICE_ID_USOPTL4_2P 0xBC02
132#define BANDB_DEVICE_ID_USOPTL4_4 0xAC44
133#define BANDB_DEVICE_ID_USOPTL4_4P 0xBC03
134#define BANDB_DEVICE_ID_USOPTL2_4 0xAC24
Paul B Schroeder3f542972006-08-31 19:41:47 -0500135
Russell Lang9d498be2009-07-17 19:29:20 +1000136/* This driver also supports
137 * ATEN UC2324 device using Moschip MCS7840
138 * ATEN UC2322 device using Moschip MCS7820
139 */
Tony Cooke9b8cff2009-04-18 22:42:18 +0930140#define USB_VENDOR_ID_ATENINTL 0x0557
141#define ATENINTL_DEVICE_ID_UC2324 0x2011
Russell Lang9d498be2009-07-17 19:29:20 +1000142#define ATENINTL_DEVICE_ID_UC2322 0x7820
Tony Cooke9b8cff2009-04-18 22:42:18 +0930143
David Ludlow11e1abb2008-02-25 17:30:52 -0500144/* Interrupt Routine Defines */
Paul B Schroeder3f542972006-08-31 19:41:47 -0500145
146#define SERIAL_IIR_RLS 0x06
147#define SERIAL_IIR_MS 0x00
148
149/*
150 * Emulation of the bit mask on the LINE STATUS REGISTER.
151 */
152#define SERIAL_LSR_DR 0x0001
153#define SERIAL_LSR_OE 0x0002
154#define SERIAL_LSR_PE 0x0004
155#define SERIAL_LSR_FE 0x0008
156#define SERIAL_LSR_BI 0x0010
157
158#define MOS_MSR_DELTA_CTS 0x10
159#define MOS_MSR_DELTA_DSR 0x20
160#define MOS_MSR_DELTA_RI 0x40
161#define MOS_MSR_DELTA_CD 0x80
162
Alan Cox880af9d2008-07-22 11:16:12 +0100163/* Serial Port register Address */
Paul B Schroeder3f542972006-08-31 19:41:47 -0500164#define INTERRUPT_ENABLE_REGISTER ((__u16)(0x01))
165#define FIFO_CONTROL_REGISTER ((__u16)(0x02))
166#define LINE_CONTROL_REGISTER ((__u16)(0x03))
167#define MODEM_CONTROL_REGISTER ((__u16)(0x04))
168#define LINE_STATUS_REGISTER ((__u16)(0x05))
169#define MODEM_STATUS_REGISTER ((__u16)(0x06))
170#define SCRATCH_PAD_REGISTER ((__u16)(0x07))
171#define DIVISOR_LATCH_LSB ((__u16)(0x00))
172#define DIVISOR_LATCH_MSB ((__u16)(0x01))
173
174#define CLK_MULTI_REGISTER ((__u16)(0x02))
175#define CLK_START_VALUE_REGISTER ((__u16)(0x03))
Donald Lee093ea2d2012-03-14 15:26:33 +0800176#define GPIO_REGISTER ((__u16)(0x07))
Paul B Schroeder3f542972006-08-31 19:41:47 -0500177
178#define SERIAL_LCR_DLAB ((__u16)(0x0080))
179
180/*
181 * URB POOL related defines
182 */
183#define NUM_URBS 16 /* URB Count */
184#define URB_TRANSFER_BUFFER_SIZE 32 /* URB Size */
185
Donald0eafe4d2012-04-19 15:00:45 +0800186/* LED on/off milliseconds*/
187#define LED_ON_MS 500
188#define LED_OFF_MS 500
189
190static int device_type;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500191
Tony Zelenoffb9c87662012-06-05 17:58:04 +0400192static const struct usb_device_id id_table[] = {
Paul B Schroeder3f542972006-08-31 19:41:47 -0500193 {USB_DEVICE(USB_VENDOR_ID_MOSCHIP, MOSCHIP_DEVICE_ID_7840)},
194 {USB_DEVICE(USB_VENDOR_ID_MOSCHIP, MOSCHIP_DEVICE_ID_7820)},
Donald0eafe4d2012-04-19 15:00:45 +0800195 {USB_DEVICE(USB_VENDOR_ID_MOSCHIP, MOSCHIP_DEVICE_ID_7810)},
Cliff Brakeacf509a2009-12-01 09:53:43 -0500196 {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USO9ML2_2)},
Dave Ludlow870408c2010-09-01 12:33:30 -0400197 {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USO9ML2_2P)},
Cliff Brakeacf509a2009-12-01 09:53:43 -0500198 {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USO9ML2_4)},
Dave Ludlow870408c2010-09-01 12:33:30 -0400199 {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USO9ML2_4P)},
Cliff Brakeacf509a2009-12-01 09:53:43 -0500200 {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_US9ML2_2)},
201 {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_US9ML2_4)},
202 {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USPTL4_2)},
203 {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USPTL4_4)},
David Ludlow11e1abb2008-02-25 17:30:52 -0500204 {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL4_2)},
Dave Ludlow870408c2010-09-01 12:33:30 -0400205 {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL4_2P)},
Cliff Brakeacf509a2009-12-01 09:53:43 -0500206 {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL4_4)},
Dave Ludlow870408c2010-09-01 12:33:30 -0400207 {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL4_4P)},
Blaise Gassend27f12812009-12-18 15:23:38 -0800208 {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL2_4)},
Tony Cooke9b8cff2009-04-18 22:42:18 +0930209 {USB_DEVICE(USB_VENDOR_ID_ATENINTL, ATENINTL_DEVICE_ID_UC2324)},
Russell Lang9d498be2009-07-17 19:29:20 +1000210 {USB_DEVICE(USB_VENDOR_ID_ATENINTL, ATENINTL_DEVICE_ID_UC2322)},
Paul B Schroeder3f542972006-08-31 19:41:47 -0500211 {} /* terminating entry */
212};
Greg Kroah-Hartman68e24112012-05-08 15:46:14 -0700213MODULE_DEVICE_TABLE(usb, id_table);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500214
215/* This structure holds all of the local port information */
216
217struct moschip_port {
218 int port_num; /*Actual port number in the device(1,2,etc) */
219 struct urb *write_urb; /* write URB for this port */
220 struct urb *read_urb; /* read URB for this port */
Oliver Neukum0de9a702007-03-16 20:28:28 +0100221 struct urb *int_urb;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500222 __u8 shadowLCR; /* last LCR value received */
223 __u8 shadowMCR; /* last MCR value received */
224 char open;
Oliver Neukum0de9a702007-03-16 20:28:28 +0100225 char open_ports;
226 char zombie;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500227 wait_queue_head_t wait_chase; /* for handling sleeping while waiting for chase to finish */
228 wait_queue_head_t delta_msr_wait; /* for handling sleeping while waiting for msr change to happen */
229 int delta_msr_cond;
230 struct async_icount icount;
231 struct usb_serial_port *port; /* loop back to the owner of this object */
232
Alan Cox880af9d2008-07-22 11:16:12 +0100233 /* Offsets */
Paul B Schroeder3f542972006-08-31 19:41:47 -0500234 __u8 SpRegOffset;
235 __u8 ControlRegOffset;
236 __u8 DcrRegOffset;
Alan Cox880af9d2008-07-22 11:16:12 +0100237 /* for processing control URBS in interrupt context */
Paul B Schroeder3f542972006-08-31 19:41:47 -0500238 struct urb *control_urb;
Oliver Neukum0de9a702007-03-16 20:28:28 +0100239 struct usb_ctrlrequest *dr;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500240 char *ctrl_buf;
241 int MsrLsr;
242
Oliver Neukum0de9a702007-03-16 20:28:28 +0100243 spinlock_t pool_lock;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500244 struct urb *write_urb_pool[NUM_URBS];
Oliver Neukum0de9a702007-03-16 20:28:28 +0100245 char busy[NUM_URBS];
Greg Kroah-Hartman50de36f2008-12-10 16:00:30 -0800246 bool read_urb_busy;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500247
Donald0eafe4d2012-04-19 15:00:45 +0800248 /* For device(s) with LED indicator */
249 bool has_led;
250 bool led_flag;
251 struct timer_list led_timer1; /* Timer for LED on */
252 struct timer_list led_timer2; /* Timer for LED off */
253};
Paul B Schroeder3f542972006-08-31 19:41:47 -0500254
Paul B Schroeder3f542972006-08-31 19:41:47 -0500255/*
256 * mos7840_set_reg_sync
257 * To set the Control register by calling usb_fill_control_urb function
258 * by passing usb_sndctrlpipe function as parameter.
259 */
260
261static int mos7840_set_reg_sync(struct usb_serial_port *port, __u16 reg,
262 __u16 val)
263{
264 struct usb_device *dev = port->serial->dev;
265 val = val & 0x00ff;
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700266 dev_dbg(&port->dev, "mos7840_set_reg_sync offset is %x, value %x\n", reg, val);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500267
268 return usb_control_msg(dev, usb_sndctrlpipe(dev, 0), MCS_WRREQ,
269 MCS_WR_RTYPE, val, reg, NULL, 0,
270 MOS_WDR_TIMEOUT);
271}
272
273/*
274 * mos7840_get_reg_sync
275 * To set the Uart register by calling usb_fill_control_urb function by
276 * passing usb_rcvctrlpipe function as parameter.
277 */
278
279static int mos7840_get_reg_sync(struct usb_serial_port *port, __u16 reg,
Alan Cox880af9d2008-07-22 11:16:12 +0100280 __u16 *val)
Paul B Schroeder3f542972006-08-31 19:41:47 -0500281{
282 struct usb_device *dev = port->serial->dev;
283 int ret = 0;
Johan Hovold9e221a32009-12-28 23:01:55 +0100284 u8 *buf;
285
286 buf = kmalloc(VENDOR_READ_LENGTH, GFP_KERNEL);
287 if (!buf)
288 return -ENOMEM;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500289
290 ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), MCS_RDREQ,
Johan Hovold9e221a32009-12-28 23:01:55 +0100291 MCS_RD_RTYPE, 0, reg, buf, VENDOR_READ_LENGTH,
Paul B Schroeder3f542972006-08-31 19:41:47 -0500292 MOS_WDR_TIMEOUT);
Johan Hovold9e221a32009-12-28 23:01:55 +0100293 *val = buf[0];
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700294 dev_dbg(&port->dev, "%s offset is %x, return val %x\n", __func__, reg, *val);
Johan Hovold9e221a32009-12-28 23:01:55 +0100295
296 kfree(buf);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500297 return ret;
298}
299
300/*
301 * mos7840_set_uart_reg
302 * To set the Uart register by calling usb_fill_control_urb function by
303 * passing usb_sndctrlpipe function as parameter.
304 */
305
306static int mos7840_set_uart_reg(struct usb_serial_port *port, __u16 reg,
307 __u16 val)
308{
309
310 struct usb_device *dev = port->serial->dev;
311 val = val & 0x00ff;
Alan Cox880af9d2008-07-22 11:16:12 +0100312 /* For the UART control registers, the application number need
313 to be Or'ed */
Oliver Neukum0de9a702007-03-16 20:28:28 +0100314 if (port->serial->num_ports == 4) {
Alan Cox880af9d2008-07-22 11:16:12 +0100315 val |= (((__u16) port->number -
316 (__u16) (port->serial->minor)) + 1) << 8;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500317 } else {
318 if (((__u16) port->number - (__u16) (port->serial->minor)) == 0) {
Alan Cox880af9d2008-07-22 11:16:12 +0100319 val |= (((__u16) port->number -
Paul B Schroeder3f542972006-08-31 19:41:47 -0500320 (__u16) (port->serial->minor)) + 1) << 8;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500321 } else {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700322 val |= (((__u16) port->number -
Paul B Schroeder3f542972006-08-31 19:41:47 -0500323 (__u16) (port->serial->minor)) + 2) << 8;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500324 }
325 }
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700326 dev_dbg(&port->dev, "%s application number is %x\n", __func__, val);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500327 return usb_control_msg(dev, usb_sndctrlpipe(dev, 0), MCS_WRREQ,
328 MCS_WR_RTYPE, val, reg, NULL, 0,
329 MOS_WDR_TIMEOUT);
330
331}
332
333/*
334 * mos7840_get_uart_reg
335 * To set the Control register by calling usb_fill_control_urb function
336 * by passing usb_rcvctrlpipe function as parameter.
337 */
338static int mos7840_get_uart_reg(struct usb_serial_port *port, __u16 reg,
Alan Cox880af9d2008-07-22 11:16:12 +0100339 __u16 *val)
Paul B Schroeder3f542972006-08-31 19:41:47 -0500340{
341 struct usb_device *dev = port->serial->dev;
342 int ret = 0;
343 __u16 Wval;
Johan Hovold9e221a32009-12-28 23:01:55 +0100344 u8 *buf;
345
346 buf = kmalloc(VENDOR_READ_LENGTH, GFP_KERNEL);
347 if (!buf)
348 return -ENOMEM;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500349
Alan Cox880af9d2008-07-22 11:16:12 +0100350 /* Wval is same as application number */
Oliver Neukum0de9a702007-03-16 20:28:28 +0100351 if (port->serial->num_ports == 4) {
Paul B Schroeder3f542972006-08-31 19:41:47 -0500352 Wval =
353 (((__u16) port->number - (__u16) (port->serial->minor)) +
354 1) << 8;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500355 } else {
356 if (((__u16) port->number - (__u16) (port->serial->minor)) == 0) {
Alan Cox880af9d2008-07-22 11:16:12 +0100357 Wval = (((__u16) port->number -
Paul B Schroeder3f542972006-08-31 19:41:47 -0500358 (__u16) (port->serial->minor)) + 1) << 8;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500359 } else {
Alan Cox880af9d2008-07-22 11:16:12 +0100360 Wval = (((__u16) port->number -
Paul B Schroeder3f542972006-08-31 19:41:47 -0500361 (__u16) (port->serial->minor)) + 2) << 8;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500362 }
363 }
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700364 dev_dbg(&port->dev, "%s application number is %x\n", __func__, Wval);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500365 ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), MCS_RDREQ,
Johan Hovold9e221a32009-12-28 23:01:55 +0100366 MCS_RD_RTYPE, Wval, reg, buf, VENDOR_READ_LENGTH,
Paul B Schroeder3f542972006-08-31 19:41:47 -0500367 MOS_WDR_TIMEOUT);
Johan Hovold9e221a32009-12-28 23:01:55 +0100368 *val = buf[0];
369
370 kfree(buf);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500371 return ret;
372}
373
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700374static void mos7840_dump_serial_port(struct usb_serial_port *port,
375 struct moschip_port *mos7840_port)
Paul B Schroeder3f542972006-08-31 19:41:47 -0500376{
377
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700378 dev_dbg(&port->dev, "SpRegOffset is %2x\n", mos7840_port->SpRegOffset);
379 dev_dbg(&port->dev, "ControlRegOffset is %2x\n", mos7840_port->ControlRegOffset);
380 dev_dbg(&port->dev, "DCRRegOffset is %2x\n", mos7840_port->DcrRegOffset);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500381
382}
383
384/************************************************************************/
385/************************************************************************/
386/* I N T E R F A C E F U N C T I O N S */
387/* I N T E R F A C E F U N C T I O N S */
388/************************************************************************/
389/************************************************************************/
390
391static inline void mos7840_set_port_private(struct usb_serial_port *port,
392 struct moschip_port *data)
393{
394 usb_set_serial_port_data(port, (void *)data);
395}
396
397static inline struct moschip_port *mos7840_get_port_private(struct
398 usb_serial_port
399 *port)
400{
401 return (struct moschip_port *)usb_get_serial_port_data(port);
402}
403
Oliver Neukum0de9a702007-03-16 20:28:28 +0100404static void mos7840_handle_new_msr(struct moschip_port *port, __u8 new_msr)
Paul B Schroeder3f542972006-08-31 19:41:47 -0500405{
406 struct moschip_port *mos7840_port;
407 struct async_icount *icount;
408 mos7840_port = port;
409 icount = &mos7840_port->icount;
410 if (new_msr &
411 (MOS_MSR_DELTA_CTS | MOS_MSR_DELTA_DSR | MOS_MSR_DELTA_RI |
412 MOS_MSR_DELTA_CD)) {
413 icount = &mos7840_port->icount;
414
415 /* update input line counters */
416 if (new_msr & MOS_MSR_DELTA_CTS) {
417 icount->cts++;
Oliver Neukum0de9a702007-03-16 20:28:28 +0100418 smp_wmb();
Paul B Schroeder3f542972006-08-31 19:41:47 -0500419 }
420 if (new_msr & MOS_MSR_DELTA_DSR) {
421 icount->dsr++;
Oliver Neukum0de9a702007-03-16 20:28:28 +0100422 smp_wmb();
Paul B Schroeder3f542972006-08-31 19:41:47 -0500423 }
424 if (new_msr & MOS_MSR_DELTA_CD) {
425 icount->dcd++;
Oliver Neukum0de9a702007-03-16 20:28:28 +0100426 smp_wmb();
Paul B Schroeder3f542972006-08-31 19:41:47 -0500427 }
428 if (new_msr & MOS_MSR_DELTA_RI) {
429 icount->rng++;
Oliver Neukum0de9a702007-03-16 20:28:28 +0100430 smp_wmb();
Paul B Schroeder3f542972006-08-31 19:41:47 -0500431 }
432 }
Paul B Schroeder3f542972006-08-31 19:41:47 -0500433}
434
Oliver Neukum0de9a702007-03-16 20:28:28 +0100435static void mos7840_handle_new_lsr(struct moschip_port *port, __u8 new_lsr)
Paul B Schroeder3f542972006-08-31 19:41:47 -0500436{
437 struct async_icount *icount;
438
Paul B Schroeder3f542972006-08-31 19:41:47 -0500439 if (new_lsr & SERIAL_LSR_BI) {
Alan Cox880af9d2008-07-22 11:16:12 +0100440 /*
441 * Parity and Framing errors only count if they
442 * occur exclusive of a break being
443 * received.
444 */
Paul B Schroeder3f542972006-08-31 19:41:47 -0500445 new_lsr &= (__u8) (SERIAL_LSR_OE | SERIAL_LSR_BI);
446 }
447
448 /* update input line counters */
449 icount = &port->icount;
450 if (new_lsr & SERIAL_LSR_BI) {
451 icount->brk++;
Oliver Neukum0de9a702007-03-16 20:28:28 +0100452 smp_wmb();
Paul B Schroeder3f542972006-08-31 19:41:47 -0500453 }
454 if (new_lsr & SERIAL_LSR_OE) {
455 icount->overrun++;
Oliver Neukum0de9a702007-03-16 20:28:28 +0100456 smp_wmb();
Paul B Schroeder3f542972006-08-31 19:41:47 -0500457 }
458 if (new_lsr & SERIAL_LSR_PE) {
459 icount->parity++;
Oliver Neukum0de9a702007-03-16 20:28:28 +0100460 smp_wmb();
Paul B Schroeder3f542972006-08-31 19:41:47 -0500461 }
462 if (new_lsr & SERIAL_LSR_FE) {
463 icount->frame++;
Oliver Neukum0de9a702007-03-16 20:28:28 +0100464 smp_wmb();
Paul B Schroeder3f542972006-08-31 19:41:47 -0500465 }
Paul B Schroeder3f542972006-08-31 19:41:47 -0500466}
467
468/************************************************************************/
469/************************************************************************/
470/* U S B C A L L B A C K F U N C T I O N S */
471/* U S B C A L L B A C K F U N C T I O N S */
472/************************************************************************/
473/************************************************************************/
474
David Howells7d12e782006-10-05 14:55:46 +0100475static void mos7840_control_callback(struct urb *urb)
Paul B Schroeder3f542972006-08-31 19:41:47 -0500476{
477 unsigned char *data;
478 struct moschip_port *mos7840_port;
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700479 struct device *dev = &urb->dev->dev;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500480 __u8 regval = 0x0;
Oliver Neukum0de9a702007-03-16 20:28:28 +0100481 int result = 0;
Greg Kroah-Hartman0643c722007-06-15 15:44:13 -0700482 int status = urb->status;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500483
Ming Leicdc97792008-02-24 18:41:47 +0800484 mos7840_port = urb->context;
Oliver Neukum0de9a702007-03-16 20:28:28 +0100485
Greg Kroah-Hartman0643c722007-06-15 15:44:13 -0700486 switch (status) {
Paul B Schroeder3f542972006-08-31 19:41:47 -0500487 case 0:
488 /* success */
489 break;
490 case -ECONNRESET:
491 case -ENOENT:
492 case -ESHUTDOWN:
493 /* this urb is terminated, clean up */
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700494 dev_dbg(dev, "%s - urb shutting down with status: %d\n", __func__, status);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500495 return;
496 default:
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700497 dev_dbg(dev, "%s - nonzero urb status received: %d\n", __func__, status);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500498 goto exit;
499 }
500
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700501 dev_dbg(dev, "%s urb buffer size is %d\n", __func__, urb->actual_length);
502 dev_dbg(dev, "%s mos7840_port->MsrLsr is %d port %d\n", __func__,
503 mos7840_port->MsrLsr, mos7840_port->port_num);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500504 data = urb->transfer_buffer;
505 regval = (__u8) data[0];
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700506 dev_dbg(dev, "%s data is %x\n", __func__, regval);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500507 if (mos7840_port->MsrLsr == 0)
508 mos7840_handle_new_msr(mos7840_port, regval);
509 else if (mos7840_port->MsrLsr == 1)
510 mos7840_handle_new_lsr(mos7840_port, regval);
511
Oliver Neukum0de9a702007-03-16 20:28:28 +0100512exit:
513 spin_lock(&mos7840_port->pool_lock);
514 if (!mos7840_port->zombie)
515 result = usb_submit_urb(mos7840_port->int_urb, GFP_ATOMIC);
516 spin_unlock(&mos7840_port->pool_lock);
517 if (result) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700518 dev_err(dev, "%s - Error %d submitting interrupt urb\n",
Harvey Harrison441b62c2008-03-03 16:08:34 -0800519 __func__, result);
Oliver Neukum0de9a702007-03-16 20:28:28 +0100520 }
Paul B Schroeder3f542972006-08-31 19:41:47 -0500521}
522
523static int mos7840_get_reg(struct moschip_port *mcs, __u16 Wval, __u16 reg,
Alan Cox880af9d2008-07-22 11:16:12 +0100524 __u16 *val)
Paul B Schroeder3f542972006-08-31 19:41:47 -0500525{
526 struct usb_device *dev = mcs->port->serial->dev;
Oliver Neukum0de9a702007-03-16 20:28:28 +0100527 struct usb_ctrlrequest *dr = mcs->dr;
528 unsigned char *buffer = mcs->ctrl_buf;
529 int ret;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500530
Paul B Schroeder3f542972006-08-31 19:41:47 -0500531 dr->bRequestType = MCS_RD_RTYPE;
532 dr->bRequest = MCS_RDREQ;
Alan Cox880af9d2008-07-22 11:16:12 +0100533 dr->wValue = cpu_to_le16(Wval); /* 0 */
Paul B Schroeder3f542972006-08-31 19:41:47 -0500534 dr->wIndex = cpu_to_le16(reg);
535 dr->wLength = cpu_to_le16(2);
536
537 usb_fill_control_urb(mcs->control_urb, dev, usb_rcvctrlpipe(dev, 0),
538 (unsigned char *)dr, buffer, 2,
539 mos7840_control_callback, mcs);
540 mcs->control_urb->transfer_buffer_length = 2;
541 ret = usb_submit_urb(mcs->control_urb, GFP_ATOMIC);
542 return ret;
543}
544
Donald0eafe4d2012-04-19 15:00:45 +0800545static void mos7840_set_led_callback(struct urb *urb)
546{
547 switch (urb->status) {
548 case 0:
549 /* Success */
550 break;
551 case -ECONNRESET:
552 case -ENOENT:
553 case -ESHUTDOWN:
554 /* This urb is terminated, clean up */
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700555 dev_dbg(&urb->dev->dev, "%s - urb shutting down with status: %d",
556 __func__, urb->status);
Donald0eafe4d2012-04-19 15:00:45 +0800557 break;
558 default:
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700559 dev_dbg(&urb->dev->dev, "%s - nonzero urb status received: %d",
560 __func__, urb->status);
Donald0eafe4d2012-04-19 15:00:45 +0800561 }
562}
563
564static void mos7840_set_led_async(struct moschip_port *mcs, __u16 wval,
565 __u16 reg)
566{
567 struct usb_device *dev = mcs->port->serial->dev;
568 struct usb_ctrlrequest *dr = mcs->dr;
569
570 dr->bRequestType = MCS_WR_RTYPE;
571 dr->bRequest = MCS_WRREQ;
572 dr->wValue = cpu_to_le16(wval);
573 dr->wIndex = cpu_to_le16(reg);
574 dr->wLength = cpu_to_le16(0);
575
576 usb_fill_control_urb(mcs->control_urb, dev, usb_sndctrlpipe(dev, 0),
577 (unsigned char *)dr, NULL, 0, mos7840_set_led_callback, NULL);
578
579 usb_submit_urb(mcs->control_urb, GFP_ATOMIC);
580}
581
582static void mos7840_set_led_sync(struct usb_serial_port *port, __u16 reg,
583 __u16 val)
584{
585 struct usb_device *dev = port->serial->dev;
586
587 usb_control_msg(dev, usb_sndctrlpipe(dev, 0), MCS_WRREQ, MCS_WR_RTYPE,
588 val, reg, NULL, 0, MOS_WDR_TIMEOUT);
589}
590
591static void mos7840_led_off(unsigned long arg)
592{
593 struct moschip_port *mcs = (struct moschip_port *) arg;
594
595 /* Turn off LED */
596 mos7840_set_led_async(mcs, 0x0300, MODEM_CONTROL_REGISTER);
597 mod_timer(&mcs->led_timer2,
598 jiffies + msecs_to_jiffies(LED_OFF_MS));
599}
600
601static void mos7840_led_flag_off(unsigned long arg)
602{
603 struct moschip_port *mcs = (struct moschip_port *) arg;
604
605 mcs->led_flag = false;
606}
607
Paul B Schroeder3f542972006-08-31 19:41:47 -0500608/*****************************************************************************
609 * mos7840_interrupt_callback
610 * this is the callback function for when we have received data on the
611 * interrupt endpoint.
612 *****************************************************************************/
613
David Howells7d12e782006-10-05 14:55:46 +0100614static void mos7840_interrupt_callback(struct urb *urb)
Paul B Schroeder3f542972006-08-31 19:41:47 -0500615{
616 int result;
617 int length;
618 struct moschip_port *mos7840_port;
619 struct usb_serial *serial;
620 __u16 Data;
621 unsigned char *data;
622 __u8 sp[5], st;
Oliver Neukum0de9a702007-03-16 20:28:28 +0100623 int i, rv = 0;
624 __u16 wval, wreg = 0;
Greg Kroah-Hartman0643c722007-06-15 15:44:13 -0700625 int status = urb->status;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500626
Greg Kroah-Hartman0643c722007-06-15 15:44:13 -0700627 switch (status) {
Paul B Schroeder3f542972006-08-31 19:41:47 -0500628 case 0:
629 /* success */
630 break;
631 case -ECONNRESET:
632 case -ENOENT:
633 case -ESHUTDOWN:
634 /* this urb is terminated, clean up */
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700635 dev_dbg(&urb->dev->dev, "%s - urb shutting down with status: %d\n",
636 __func__, status);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500637 return;
638 default:
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700639 dev_dbg(&urb->dev->dev, "%s - nonzero urb status received: %d\n",
640 __func__, status);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500641 goto exit;
642 }
643
644 length = urb->actual_length;
645 data = urb->transfer_buffer;
646
Ming Leicdc97792008-02-24 18:41:47 +0800647 serial = urb->context;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500648
649 /* Moschip get 5 bytes
650 * Byte 1 IIR Port 1 (port.number is 0)
651 * Byte 2 IIR Port 2 (port.number is 1)
652 * Byte 3 IIR Port 3 (port.number is 2)
653 * Byte 4 IIR Port 4 (port.number is 3)
654 * Byte 5 FIFO status for both */
655
656 if (length && length > 5) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700657 dev_dbg(&urb->dev->dev, "%s", "Wrong data !!!\n");
Paul B Schroeder3f542972006-08-31 19:41:47 -0500658 return;
659 }
660
661 sp[0] = (__u8) data[0];
662 sp[1] = (__u8) data[1];
663 sp[2] = (__u8) data[2];
664 sp[3] = (__u8) data[3];
665 st = (__u8) data[4];
666
667 for (i = 0; i < serial->num_ports; i++) {
668 mos7840_port = mos7840_get_port_private(serial->port[i]);
669 wval =
670 (((__u16) serial->port[i]->number -
671 (__u16) (serial->minor)) + 1) << 8;
672 if (mos7840_port->open) {
673 if (sp[i] & 0x01) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700674 dev_dbg(&urb->dev->dev, "SP%d No Interrupt !!!\n", i);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500675 } else {
676 switch (sp[i] & 0x0f) {
677 case SERIAL_IIR_RLS:
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700678 dev_dbg(&urb->dev->dev, "Serial Port %d: Receiver status error or \n", i);
679 dev_dbg(&urb->dev->dev, "address bit detected in 9-bit mode\n");
Paul B Schroeder3f542972006-08-31 19:41:47 -0500680 mos7840_port->MsrLsr = 1;
Oliver Neukum0de9a702007-03-16 20:28:28 +0100681 wreg = LINE_STATUS_REGISTER;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500682 break;
683 case SERIAL_IIR_MS:
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700684 dev_dbg(&urb->dev->dev, "Serial Port %d: Modem status change\n", i);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500685 mos7840_port->MsrLsr = 0;
Oliver Neukum0de9a702007-03-16 20:28:28 +0100686 wreg = MODEM_STATUS_REGISTER;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500687 break;
688 }
Oliver Neukum0de9a702007-03-16 20:28:28 +0100689 spin_lock(&mos7840_port->pool_lock);
690 if (!mos7840_port->zombie) {
691 rv = mos7840_get_reg(mos7840_port, wval, wreg, &Data);
692 } else {
693 spin_unlock(&mos7840_port->pool_lock);
694 return;
695 }
696 spin_unlock(&mos7840_port->pool_lock);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500697 }
698 }
699 }
Alan Cox880af9d2008-07-22 11:16:12 +0100700 if (!(rv < 0))
701 /* the completion handler for the control urb will resubmit */
Oliver Neukum0de9a702007-03-16 20:28:28 +0100702 return;
703exit:
Paul B Schroeder3f542972006-08-31 19:41:47 -0500704 result = usb_submit_urb(urb, GFP_ATOMIC);
705 if (result) {
706 dev_err(&urb->dev->dev,
707 "%s - Error %d submitting interrupt urb\n",
Harvey Harrison441b62c2008-03-03 16:08:34 -0800708 __func__, result);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500709 }
Paul B Schroeder3f542972006-08-31 19:41:47 -0500710}
711
712static int mos7840_port_paranoia_check(struct usb_serial_port *port,
713 const char *function)
714{
715 if (!port) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700716 pr_debug("%s - port == NULL\n", function);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500717 return -1;
718 }
719 if (!port->serial) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700720 pr_debug("%s - port->serial == NULL\n", function);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500721 return -1;
722 }
723
724 return 0;
725}
726
727/* Inline functions to check the sanity of a pointer that is passed to us */
728static int mos7840_serial_paranoia_check(struct usb_serial *serial,
729 const char *function)
730{
731 if (!serial) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700732 pr_debug("%s - serial == NULL\n", function);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500733 return -1;
734 }
735 if (!serial->type) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700736 pr_debug("%s - serial->type == NULL!\n", function);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500737 return -1;
738 }
739
740 return 0;
741}
742
743static struct usb_serial *mos7840_get_usb_serial(struct usb_serial_port *port,
744 const char *function)
745{
746 /* if no port was specified, or it fails a paranoia check */
747 if (!port ||
748 mos7840_port_paranoia_check(port, function) ||
749 mos7840_serial_paranoia_check(port->serial, function)) {
Alan Cox880af9d2008-07-22 11:16:12 +0100750 /* then say that we don't have a valid usb_serial thing,
751 * which will end up genrating -ENODEV return values */
Paul B Schroeder3f542972006-08-31 19:41:47 -0500752 return NULL;
753 }
754
755 return port->serial;
756}
757
758/*****************************************************************************
759 * mos7840_bulk_in_callback
760 * this is the callback function for when we have received data on the
761 * bulk in endpoint.
762 *****************************************************************************/
763
David Howells7d12e782006-10-05 14:55:46 +0100764static void mos7840_bulk_in_callback(struct urb *urb)
Paul B Schroeder3f542972006-08-31 19:41:47 -0500765{
Greg Kroah-Hartman0643c722007-06-15 15:44:13 -0700766 int retval;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500767 unsigned char *data;
768 struct usb_serial *serial;
769 struct usb_serial_port *port;
770 struct moschip_port *mos7840_port;
771 struct tty_struct *tty;
Greg Kroah-Hartman0643c722007-06-15 15:44:13 -0700772 int status = urb->status;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500773
Ming Leicdc97792008-02-24 18:41:47 +0800774 mos7840_port = urb->context;
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700775 if (!mos7840_port)
Greg Kroah-Hartman50de36f2008-12-10 16:00:30 -0800776 return;
Greg Kroah-Hartman50de36f2008-12-10 16:00:30 -0800777
778 if (status) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700779 dev_dbg(&urb->dev->dev, "nonzero read bulk status received: %d\n", status);
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
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700784 port = mos7840_port->port;
Harvey Harrison441b62c2008-03-03 16:08:34 -0800785 if (mos7840_port_paranoia_check(port, __func__)) {
Greg Kroah-Hartman50de36f2008-12-10 16:00:30 -0800786 mos7840_port->read_urb_busy = false;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500787 return;
788 }
789
Harvey Harrison441b62c2008-03-03 16:08:34 -0800790 serial = mos7840_get_usb_serial(port, __func__);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500791 if (!serial) {
Greg Kroah-Hartman50de36f2008-12-10 16:00:30 -0800792 mos7840_port->read_urb_busy = false;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500793 return;
794 }
795
Paul B Schroeder3f542972006-08-31 19:41:47 -0500796 data = urb->transfer_buffer;
Greg Kroah-Hartman59d33f22012-09-18 09:58:57 +0100797 usb_serial_debug_data(&port->dev, __func__, urb->actual_length, data);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500798
Paul B Schroeder3f542972006-08-31 19:41:47 -0500799 if (urb->actual_length) {
Alan Cox4a90f092008-10-13 10:39:46 +0100800 tty = tty_port_tty_get(&mos7840_port->port->port);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500801 if (tty) {
Paul B Schroeder3f542972006-08-31 19:41:47 -0500802 tty_insert_flip_string(tty, data, urb->actual_length);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500803 tty_flip_buffer_push(tty);
Alan Cox4a90f092008-10-13 10:39:46 +0100804 tty_kref_put(tty);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500805 }
806 mos7840_port->icount.rx += urb->actual_length;
Oliver Neukum0de9a702007-03-16 20:28:28 +0100807 smp_wmb();
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700808 dev_dbg(&port->dev, "mos7840_port->icount.rx is %d:\n", mos7840_port->icount.rx);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500809 }
810
811 if (!mos7840_port->read_urb) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700812 dev_dbg(&port->dev, "%s", "URB KILLED !!!\n");
Greg Kroah-Hartman50de36f2008-12-10 16:00:30 -0800813 mos7840_port->read_urb_busy = false;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500814 return;
815 }
816
Donald0eafe4d2012-04-19 15:00:45 +0800817 /* Turn on LED */
818 if (mos7840_port->has_led && !mos7840_port->led_flag) {
819 mos7840_port->led_flag = true;
820 mos7840_set_led_async(mos7840_port, 0x0301,
821 MODEM_CONTROL_REGISTER);
822 mod_timer(&mos7840_port->led_timer1,
823 jiffies + msecs_to_jiffies(LED_ON_MS));
824 }
Paul B Schroeder3f542972006-08-31 19:41:47 -0500825
Greg Kroah-Hartman50de36f2008-12-10 16:00:30 -0800826 mos7840_port->read_urb_busy = true;
Greg Kroah-Hartman0643c722007-06-15 15:44:13 -0700827 retval = usb_submit_urb(mos7840_port->read_urb, GFP_ATOMIC);
Oliver Neukum0de9a702007-03-16 20:28:28 +0100828
Greg Kroah-Hartman0643c722007-06-15 15:44:13 -0700829 if (retval) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700830 dev_dbg(&port->dev, "usb_submit_urb(read bulk) failed, retval = %d\n", retval);
Greg Kroah-Hartman50de36f2008-12-10 16:00:30 -0800831 mos7840_port->read_urb_busy = false;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500832 }
833}
834
835/*****************************************************************************
836 * mos7840_bulk_out_data_callback
Alan Cox880af9d2008-07-22 11:16:12 +0100837 * this is the callback function for when we have finished sending
838 * serial data on the bulk out endpoint.
Paul B Schroeder3f542972006-08-31 19:41:47 -0500839 *****************************************************************************/
840
David Howells7d12e782006-10-05 14:55:46 +0100841static void mos7840_bulk_out_data_callback(struct urb *urb)
Paul B Schroeder3f542972006-08-31 19:41:47 -0500842{
843 struct moschip_port *mos7840_port;
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700844 struct usb_serial_port *port;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500845 struct tty_struct *tty;
Greg Kroah-Hartman0643c722007-06-15 15:44:13 -0700846 int status = urb->status;
Oliver Neukum0de9a702007-03-16 20:28:28 +0100847 int i;
848
Ming Leicdc97792008-02-24 18:41:47 +0800849 mos7840_port = urb->context;
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700850 port = mos7840_port->port;
Oliver Neukum0de9a702007-03-16 20:28:28 +0100851 spin_lock(&mos7840_port->pool_lock);
852 for (i = 0; i < NUM_URBS; i++) {
853 if (urb == mos7840_port->write_urb_pool[i]) {
854 mos7840_port->busy[i] = 0;
855 break;
856 }
857 }
858 spin_unlock(&mos7840_port->pool_lock);
859
Greg Kroah-Hartman0643c722007-06-15 15:44:13 -0700860 if (status) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700861 dev_dbg(&port->dev, "nonzero write bulk status received:%d\n", status);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500862 return;
863 }
864
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700865 if (mos7840_port_paranoia_check(port, __func__))
Paul B Schroeder3f542972006-08-31 19:41:47 -0500866 return;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500867
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700868 tty = tty_port_tty_get(&port->port);
Jiri Slabyb963a842007-02-10 01:44:55 -0800869 if (tty && mos7840_port->open)
870 tty_wakeup(tty);
Alan Cox4a90f092008-10-13 10:39:46 +0100871 tty_kref_put(tty);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500872
873}
874
875/************************************************************************/
876/* 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 */
877/************************************************************************/
878#ifdef MCSSerialProbe
879static int mos7840_serial_probe(struct usb_serial *serial,
880 const struct usb_device_id *id)
881{
882
883 /*need to implement the mode_reg reading and updating\
884 structures usb_serial_ device_type\
885 (i.e num_ports, num_bulkin,bulkout etc) */
886 /* Also we can update the changes attach */
887 return 1;
888}
889#endif
890
891/*****************************************************************************
892 * mos7840_open
893 * this function is called by the tty driver when a port is opened
894 * If successful, we return 0
895 * Otherwise we return a negative error number.
896 *****************************************************************************/
897
Alan Coxa509a7e2009-09-19 13:13:26 -0700898static int mos7840_open(struct tty_struct *tty, struct usb_serial_port *port)
Paul B Schroeder3f542972006-08-31 19:41:47 -0500899{
900 int response;
901 int j;
902 struct usb_serial *serial;
903 struct urb *urb;
904 __u16 Data;
905 int status;
906 struct moschip_port *mos7840_port;
Oliver Neukum0de9a702007-03-16 20:28:28 +0100907 struct moschip_port *port0;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500908
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700909 if (mos7840_port_paranoia_check(port, __func__))
Paul B Schroeder3f542972006-08-31 19:41:47 -0500910 return -ENODEV;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500911
Paul B Schroeder3f542972006-08-31 19:41:47 -0500912 serial = port->serial;
913
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700914 if (mos7840_serial_paranoia_check(serial, __func__))
Paul B Schroeder3f542972006-08-31 19:41:47 -0500915 return -ENODEV;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500916
917 mos7840_port = mos7840_get_port_private(port);
Oliver Neukum0de9a702007-03-16 20:28:28 +0100918 port0 = mos7840_get_port_private(serial->port[0]);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500919
Oliver Neukum0de9a702007-03-16 20:28:28 +0100920 if (mos7840_port == NULL || port0 == NULL)
Paul B Schroeder3f542972006-08-31 19:41:47 -0500921 return -ENODEV;
922
923 usb_clear_halt(serial->dev, port->write_urb->pipe);
924 usb_clear_halt(serial->dev, port->read_urb->pipe);
Oliver Neukum0de9a702007-03-16 20:28:28 +0100925 port0->open_ports++;
Paul B Schroeder3f542972006-08-31 19:41:47 -0500926
927 /* Initialising the write urb pool */
928 for (j = 0; j < NUM_URBS; ++j) {
Oliver Neukum0de9a702007-03-16 20:28:28 +0100929 urb = usb_alloc_urb(0, GFP_KERNEL);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500930 mos7840_port->write_urb_pool[j] = urb;
931
932 if (urb == NULL) {
Greg Kroah-Hartman194343d2008-08-20 16:56:34 -0700933 dev_err(&port->dev, "No more urbs???\n");
Paul B Schroeder3f542972006-08-31 19:41:47 -0500934 continue;
935 }
936
Alan Cox880af9d2008-07-22 11:16:12 +0100937 urb->transfer_buffer = kmalloc(URB_TRANSFER_BUFFER_SIZE,
938 GFP_KERNEL);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500939 if (!urb->transfer_buffer) {
Oliver Neukum0de9a702007-03-16 20:28:28 +0100940 usb_free_urb(urb);
941 mos7840_port->write_urb_pool[j] = NULL;
Greg Kroah-Hartman194343d2008-08-20 16:56:34 -0700942 dev_err(&port->dev,
943 "%s-out of memory for urb buffers.\n",
944 __func__);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500945 continue;
946 }
947 }
948
949/*****************************************************************************
950 * Initialize MCS7840 -- Write Init values to corresponding Registers
951 *
952 * Register Index
953 * 1 : IER
954 * 2 : FCR
955 * 3 : LCR
956 * 4 : MCR
957 *
958 * 0x08 : SP1/2 Control Reg
959 *****************************************************************************/
960
Alan Cox880af9d2008-07-22 11:16:12 +0100961 /* NEED to check the following Block */
Paul B Schroeder3f542972006-08-31 19:41:47 -0500962
Paul B Schroeder3f542972006-08-31 19:41:47 -0500963 Data = 0x0;
964 status = mos7840_get_reg_sync(port, mos7840_port->SpRegOffset, &Data);
965 if (status < 0) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700966 dev_dbg(&port->dev, "Reading Spreg failed\n");
Paul B Schroeder3f542972006-08-31 19:41:47 -0500967 return -1;
968 }
969 Data |= 0x80;
970 status = mos7840_set_reg_sync(port, mos7840_port->SpRegOffset, Data);
971 if (status < 0) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700972 dev_dbg(&port->dev, "writing Spreg failed\n");
Paul B Schroeder3f542972006-08-31 19:41:47 -0500973 return -1;
974 }
975
976 Data &= ~0x80;
977 status = mos7840_set_reg_sync(port, mos7840_port->SpRegOffset, Data);
978 if (status < 0) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700979 dev_dbg(&port->dev, "writing Spreg failed\n");
Paul B Schroeder3f542972006-08-31 19:41:47 -0500980 return -1;
981 }
Alan Cox880af9d2008-07-22 11:16:12 +0100982 /* End of block to be checked */
Paul B Schroeder3f542972006-08-31 19:41:47 -0500983
Paul B Schroeder3f542972006-08-31 19:41:47 -0500984 Data = 0x0;
Alan Cox880af9d2008-07-22 11:16:12 +0100985 status = mos7840_get_reg_sync(port, mos7840_port->ControlRegOffset,
986 &Data);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500987 if (status < 0) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700988 dev_dbg(&port->dev, "Reading Controlreg failed\n");
Paul B Schroeder3f542972006-08-31 19:41:47 -0500989 return -1;
990 }
Alan Cox880af9d2008-07-22 11:16:12 +0100991 Data |= 0x08; /* Driver done bit */
992 Data |= 0x20; /* rx_disable */
993 status = mos7840_set_reg_sync(port,
994 mos7840_port->ControlRegOffset, Data);
Paul B Schroeder3f542972006-08-31 19:41:47 -0500995 if (status < 0) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -0700996 dev_dbg(&port->dev, "writing Controlreg failed\n");
Paul B Schroeder3f542972006-08-31 19:41:47 -0500997 return -1;
998 }
Alan Cox880af9d2008-07-22 11:16:12 +0100999 /* do register settings here */
1000 /* Set all regs to the device default values. */
1001 /***********************************
1002 * First Disable all interrupts.
1003 ***********************************/
Paul B Schroeder3f542972006-08-31 19:41:47 -05001004 Data = 0x00;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001005 status = mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data);
1006 if (status < 0) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001007 dev_dbg(&port->dev, "disabling interrupts failed\n");
Paul B Schroeder3f542972006-08-31 19:41:47 -05001008 return -1;
1009 }
Alan Cox880af9d2008-07-22 11:16:12 +01001010 /* Set FIFO_CONTROL_REGISTER to the default value */
Paul B Schroeder3f542972006-08-31 19:41:47 -05001011 Data = 0x00;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001012 status = mos7840_set_uart_reg(port, FIFO_CONTROL_REGISTER, Data);
1013 if (status < 0) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001014 dev_dbg(&port->dev, "Writing FIFO_CONTROL_REGISTER failed\n");
Paul B Schroeder3f542972006-08-31 19:41:47 -05001015 return -1;
1016 }
1017
1018 Data = 0xcf;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001019 status = mos7840_set_uart_reg(port, FIFO_CONTROL_REGISTER, Data);
1020 if (status < 0) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001021 dev_dbg(&port->dev, "Writing FIFO_CONTROL_REGISTER failed\n");
Paul B Schroeder3f542972006-08-31 19:41:47 -05001022 return -1;
1023 }
1024
1025 Data = 0x03;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001026 status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
1027 mos7840_port->shadowLCR = Data;
1028
1029 Data = 0x0b;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001030 status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
1031 mos7840_port->shadowMCR = Data;
1032
1033 Data = 0x00;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001034 status = mos7840_get_uart_reg(port, LINE_CONTROL_REGISTER, &Data);
1035 mos7840_port->shadowLCR = Data;
1036
Alan Cox880af9d2008-07-22 11:16:12 +01001037 Data |= SERIAL_LCR_DLAB; /* data latch enable in LCR 0x80 */
Paul B Schroeder3f542972006-08-31 19:41:47 -05001038 status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
1039
1040 Data = 0x0c;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001041 status = mos7840_set_uart_reg(port, DIVISOR_LATCH_LSB, Data);
1042
1043 Data = 0x0;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001044 status = mos7840_set_uart_reg(port, DIVISOR_LATCH_MSB, Data);
1045
1046 Data = 0x00;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001047 status = mos7840_get_uart_reg(port, LINE_CONTROL_REGISTER, &Data);
1048
1049 Data = Data & ~SERIAL_LCR_DLAB;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001050 status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
1051 mos7840_port->shadowLCR = Data;
1052
Alan Cox880af9d2008-07-22 11:16:12 +01001053 /* clearing Bulkin and Bulkout Fifo */
Paul B Schroeder3f542972006-08-31 19:41:47 -05001054 Data = 0x0;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001055 status = mos7840_get_reg_sync(port, mos7840_port->SpRegOffset, &Data);
1056
1057 Data = Data | 0x0c;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001058 status = mos7840_set_reg_sync(port, mos7840_port->SpRegOffset, Data);
1059
1060 Data = Data & ~0x0c;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001061 status = mos7840_set_reg_sync(port, mos7840_port->SpRegOffset, Data);
Alan Cox880af9d2008-07-22 11:16:12 +01001062 /* Finally enable all interrupts */
Paul B Schroeder3f542972006-08-31 19:41:47 -05001063 Data = 0x0c;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001064 status = mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data);
1065
Alan Cox880af9d2008-07-22 11:16:12 +01001066 /* clearing rx_disable */
Paul B Schroeder3f542972006-08-31 19:41:47 -05001067 Data = 0x0;
Alan Cox880af9d2008-07-22 11:16:12 +01001068 status = mos7840_get_reg_sync(port, mos7840_port->ControlRegOffset,
1069 &Data);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001070 Data = Data & ~0x20;
Alan Cox880af9d2008-07-22 11:16:12 +01001071 status = mos7840_set_reg_sync(port, mos7840_port->ControlRegOffset,
1072 Data);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001073
Alan Cox880af9d2008-07-22 11:16:12 +01001074 /* rx_negate */
Paul B Schroeder3f542972006-08-31 19:41:47 -05001075 Data = 0x0;
Alan Cox880af9d2008-07-22 11:16:12 +01001076 status = mos7840_get_reg_sync(port, mos7840_port->ControlRegOffset,
1077 &Data);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001078 Data = Data | 0x10;
Alan Cox880af9d2008-07-22 11:16:12 +01001079 status = mos7840_set_reg_sync(port, mos7840_port->ControlRegOffset,
1080 Data);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001081
Alan Cox880af9d2008-07-22 11:16:12 +01001082 /* Check to see if we've set up our endpoint info yet *
1083 * (can't set it up in mos7840_startup as the structures *
1084 * were not set up at that time.) */
Oliver Neukum0de9a702007-03-16 20:28:28 +01001085 if (port0->open_ports == 1) {
Paul B Schroeder3f542972006-08-31 19:41:47 -05001086 if (serial->port[0]->interrupt_in_buffer == NULL) {
Paul B Schroeder3f542972006-08-31 19:41:47 -05001087 /* set up interrupt urb */
Paul B Schroeder3f542972006-08-31 19:41:47 -05001088 usb_fill_int_urb(serial->port[0]->interrupt_in_urb,
Alan Cox880af9d2008-07-22 11:16:12 +01001089 serial->dev,
1090 usb_rcvintpipe(serial->dev,
1091 serial->port[0]->interrupt_in_endpointAddress),
1092 serial->port[0]->interrupt_in_buffer,
1093 serial->port[0]->interrupt_in_urb->
1094 transfer_buffer_length,
1095 mos7840_interrupt_callback,
1096 serial,
1097 serial->port[0]->interrupt_in_urb->interval);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001098
1099 /* start interrupt read for mos7840 *
1100 * will continue as long as mos7840 is connected */
1101
1102 response =
1103 usb_submit_urb(serial->port[0]->interrupt_in_urb,
1104 GFP_KERNEL);
1105 if (response) {
Greg Kroah-Hartman194343d2008-08-20 16:56:34 -07001106 dev_err(&port->dev, "%s - Error %d submitting "
1107 "interrupt urb\n", __func__, response);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001108 }
1109
1110 }
1111
1112 }
1113
1114 /* see if we've set up our endpoint info yet *
1115 * (can't set it up in mos7840_startup as the *
1116 * structures were not set up at that time.) */
1117
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001118 dev_dbg(&port->dev, "port number is %d\n", port->number);
1119 dev_dbg(&port->dev, "serial number is %d\n", port->serial->minor);
1120 dev_dbg(&port->dev, "Bulkin endpoint is %d\n", port->bulk_in_endpointAddress);
1121 dev_dbg(&port->dev, "BulkOut endpoint is %d\n", port->bulk_out_endpointAddress);
1122 dev_dbg(&port->dev, "Interrupt endpoint is %d\n", port->interrupt_in_endpointAddress);
1123 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 -05001124 mos7840_port->read_urb = port->read_urb;
1125
1126 /* set up our bulk in urb */
Donald Lee093ea2d2012-03-14 15:26:33 +08001127 if ((serial->num_ports == 2)
1128 && ((((__u16)port->number -
1129 (__u16)(port->serial->minor)) % 2) != 0)) {
1130 usb_fill_bulk_urb(mos7840_port->read_urb,
1131 serial->dev,
1132 usb_rcvbulkpipe(serial->dev,
1133 (port->bulk_in_endpointAddress) + 2),
1134 port->bulk_in_buffer,
1135 mos7840_port->read_urb->transfer_buffer_length,
1136 mos7840_bulk_in_callback, mos7840_port);
1137 } else {
1138 usb_fill_bulk_urb(mos7840_port->read_urb,
1139 serial->dev,
1140 usb_rcvbulkpipe(serial->dev,
1141 port->bulk_in_endpointAddress),
1142 port->bulk_in_buffer,
1143 mos7840_port->read_urb->transfer_buffer_length,
1144 mos7840_bulk_in_callback, mos7840_port);
1145 }
Paul B Schroeder3f542972006-08-31 19:41:47 -05001146
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001147 dev_dbg(&port->dev, "%s: bulkin endpoint is %d\n", __func__, port->bulk_in_endpointAddress);
Greg Kroah-Hartman50de36f2008-12-10 16:00:30 -08001148 mos7840_port->read_urb_busy = true;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001149 response = usb_submit_urb(mos7840_port->read_urb, GFP_KERNEL);
1150 if (response) {
Greg Kroah-Hartman194343d2008-08-20 16:56:34 -07001151 dev_err(&port->dev, "%s - Error %d submitting control urb\n",
1152 __func__, response);
Greg Kroah-Hartman50de36f2008-12-10 16:00:30 -08001153 mos7840_port->read_urb_busy = false;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001154 }
1155
1156 /* initialize our wait queues */
1157 init_waitqueue_head(&mos7840_port->wait_chase);
1158 init_waitqueue_head(&mos7840_port->delta_msr_wait);
1159
1160 /* initialize our icount structure */
1161 memset(&(mos7840_port->icount), 0x00, sizeof(mos7840_port->icount));
1162
1163 /* initialize our port settings */
Alan Cox880af9d2008-07-22 11:16:12 +01001164 /* Must set to enable ints! */
1165 mos7840_port->shadowMCR = MCR_MASTER_IE;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001166 /* send a open port command */
1167 mos7840_port->open = 1;
Alan Cox880af9d2008-07-22 11:16:12 +01001168 /* mos7840_change_port_settings(mos7840_port,old_termios); */
Paul B Schroeder3f542972006-08-31 19:41:47 -05001169 mos7840_port->icount.tx = 0;
1170 mos7840_port->icount.rx = 0;
1171
Paul B Schroeder3f542972006-08-31 19:41:47 -05001172 return 0;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001173}
1174
1175/*****************************************************************************
1176 * mos7840_chars_in_buffer
1177 * this function is called by the tty driver when it wants to know how many
1178 * bytes of data we currently have outstanding in the port (data that has
1179 * been written, but hasn't made it out the port yet)
1180 * If successful, we return the number of bytes left to be written in the
1181 * system,
Alan Cox95da3102008-07-22 11:09:07 +01001182 * Otherwise we return zero.
Paul B Schroeder3f542972006-08-31 19:41:47 -05001183 *****************************************************************************/
1184
Alan Cox95da3102008-07-22 11:09:07 +01001185static int mos7840_chars_in_buffer(struct tty_struct *tty)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001186{
Alan Cox95da3102008-07-22 11:09:07 +01001187 struct usb_serial_port *port = tty->driver_data;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001188 int i;
1189 int chars = 0;
Oliver Neukum0de9a702007-03-16 20:28:28 +01001190 unsigned long flags;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001191 struct moschip_port *mos7840_port;
1192
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001193 if (mos7840_port_paranoia_check(port, __func__))
Alan Cox95da3102008-07-22 11:09:07 +01001194 return 0;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001195
1196 mos7840_port = mos7840_get_port_private(port);
Greg Kroah-Hartman33631552012-05-03 16:44:33 -07001197 if (mos7840_port == NULL)
Alan Cox95da3102008-07-22 11:09:07 +01001198 return 0;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001199
Alan Cox880af9d2008-07-22 11:16:12 +01001200 spin_lock_irqsave(&mos7840_port->pool_lock, flags);
Mark Ferrell5c263b92012-07-24 14:15:13 -05001201 for (i = 0; i < NUM_URBS; ++i) {
1202 if (mos7840_port->busy[i]) {
1203 struct urb *urb = mos7840_port->write_urb_pool[i];
1204 chars += urb->transfer_buffer_length;
1205 }
1206 }
Alan Cox880af9d2008-07-22 11:16:12 +01001207 spin_unlock_irqrestore(&mos7840_port->pool_lock, flags);
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001208 dev_dbg(&port->dev, "%s - returns %d\n", __func__, chars);
Oliver Neukum0de9a702007-03-16 20:28:28 +01001209 return chars;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001210
1211}
1212
Paul B Schroeder3f542972006-08-31 19:41:47 -05001213/*****************************************************************************
1214 * mos7840_close
1215 * this function is called by the tty driver when a port is closed
1216 *****************************************************************************/
1217
Alan Cox335f8512009-06-11 12:26:29 +01001218static void mos7840_close(struct usb_serial_port *port)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001219{
1220 struct usb_serial *serial;
1221 struct moschip_port *mos7840_port;
Oliver Neukum0de9a702007-03-16 20:28:28 +01001222 struct moschip_port *port0;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001223 int j;
1224 __u16 Data;
1225
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001226 if (mos7840_port_paranoia_check(port, __func__))
Paul B Schroeder3f542972006-08-31 19:41:47 -05001227 return;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001228
Harvey Harrison441b62c2008-03-03 16:08:34 -08001229 serial = mos7840_get_usb_serial(port, __func__);
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001230 if (!serial)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001231 return;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001232
1233 mos7840_port = mos7840_get_port_private(port);
Oliver Neukum0de9a702007-03-16 20:28:28 +01001234 port0 = mos7840_get_port_private(serial->port[0]);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001235
Oliver Neukum0de9a702007-03-16 20:28:28 +01001236 if (mos7840_port == NULL || port0 == NULL)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001237 return;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001238
1239 for (j = 0; j < NUM_URBS; ++j)
1240 usb_kill_urb(mos7840_port->write_urb_pool[j]);
1241
1242 /* Freeing Write URBs */
1243 for (j = 0; j < NUM_URBS; ++j) {
1244 if (mos7840_port->write_urb_pool[j]) {
1245 if (mos7840_port->write_urb_pool[j]->transfer_buffer)
1246 kfree(mos7840_port->write_urb_pool[j]->
1247 transfer_buffer);
1248
1249 usb_free_urb(mos7840_port->write_urb_pool[j]);
1250 }
1251 }
1252
Paul B Schroeder3f542972006-08-31 19:41:47 -05001253 /* While closing port, shutdown all bulk read, write *
1254 * and interrupt read if they exists */
1255 if (serial->dev) {
Paul B Schroeder3f542972006-08-31 19:41:47 -05001256 if (mos7840_port->write_urb) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001257 dev_dbg(&port->dev, "%s", "Shutdown bulk write\n");
Paul B Schroeder3f542972006-08-31 19:41:47 -05001258 usb_kill_urb(mos7840_port->write_urb);
1259 }
Paul B Schroeder3f542972006-08-31 19:41:47 -05001260 if (mos7840_port->read_urb) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001261 dev_dbg(&port->dev, "%s", "Shutdown bulk read\n");
Paul B Schroeder3f542972006-08-31 19:41:47 -05001262 usb_kill_urb(mos7840_port->read_urb);
Greg Kroah-Hartman50de36f2008-12-10 16:00:30 -08001263 mos7840_port->read_urb_busy = false;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001264 }
1265 if ((&mos7840_port->control_urb)) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001266 dev_dbg(&port->dev, "%s", "Shutdown control read\n");
Alan Cox880af9d2008-07-22 11:16:12 +01001267 /*/ usb_kill_urb (mos7840_port->control_urb); */
Paul B Schroeder3f542972006-08-31 19:41:47 -05001268 }
1269 }
Alan Cox880af9d2008-07-22 11:16:12 +01001270/* if(mos7840_port->ctrl_buf != NULL) */
1271/* kfree(mos7840_port->ctrl_buf); */
Oliver Neukum0de9a702007-03-16 20:28:28 +01001272 port0->open_ports--;
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001273 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 +01001274 if (port0->open_ports == 0) {
Paul B Schroeder3f542972006-08-31 19:41:47 -05001275 if (serial->port[0]->interrupt_in_urb) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001276 dev_dbg(&port->dev, "Shutdown interrupt_in_urb\n");
Oliver Neukum0de9a702007-03-16 20:28:28 +01001277 usb_kill_urb(serial->port[0]->interrupt_in_urb);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001278 }
1279 }
1280
1281 if (mos7840_port->write_urb) {
1282 /* if this urb had a transfer buffer already (old tx) free it */
Alan Cox880af9d2008-07-22 11:16:12 +01001283 if (mos7840_port->write_urb->transfer_buffer != NULL)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001284 kfree(mos7840_port->write_urb->transfer_buffer);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001285 usb_free_urb(mos7840_port->write_urb);
1286 }
1287
1288 Data = 0x0;
1289 mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
1290
1291 Data = 0x00;
1292 mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data);
1293
1294 mos7840_port->open = 0;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001295}
1296
1297/************************************************************************
1298 *
1299 * mos7840_block_until_chase_response
1300 *
1301 * This function will block the close until one of the following:
1302 * 1. Response to our Chase comes from mos7840
Joe Perchesdc0d5c12007-12-17 11:40:18 -08001303 * 2. A timeout of 10 seconds without activity has expired
Paul B Schroeder3f542972006-08-31 19:41:47 -05001304 * (1K of mos7840 data @ 2400 baud ==> 4 sec to empty)
1305 *
1306 ************************************************************************/
1307
Alan Cox95da3102008-07-22 11:09:07 +01001308static void mos7840_block_until_chase_response(struct tty_struct *tty,
1309 struct moschip_port *mos7840_port)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001310{
Mark Ferrell1e658482012-07-24 13:38:31 -05001311 int timeout = msecs_to_jiffies(1000);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001312 int wait = 10;
1313 int count;
1314
1315 while (1) {
Alan Cox95da3102008-07-22 11:09:07 +01001316 count = mos7840_chars_in_buffer(tty);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001317
1318 /* Check for Buffer status */
Alan Cox880af9d2008-07-22 11:16:12 +01001319 if (count <= 0)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001320 return;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001321
1322 /* Block the thread for a while */
1323 interruptible_sleep_on_timeout(&mos7840_port->wait_chase,
1324 timeout);
1325 /* No activity.. count down section */
1326 wait--;
1327 if (wait == 0) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001328 dev_dbg(&mos7840_port->port->dev, "%s - TIMEOUT\n", __func__);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001329 return;
1330 } else {
Joe Perchesdc0d5c12007-12-17 11:40:18 -08001331 /* Reset timeout value back to seconds */
Paul B Schroeder3f542972006-08-31 19:41:47 -05001332 wait = 10;
1333 }
1334 }
1335
1336}
1337
1338/*****************************************************************************
1339 * mos7840_break
1340 * this function sends a break to the port
1341 *****************************************************************************/
Alan Cox95da3102008-07-22 11:09:07 +01001342static void mos7840_break(struct tty_struct *tty, int break_state)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001343{
Alan Cox95da3102008-07-22 11:09:07 +01001344 struct usb_serial_port *port = tty->driver_data;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001345 unsigned char data;
1346 struct usb_serial *serial;
1347 struct moschip_port *mos7840_port;
1348
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001349 if (mos7840_port_paranoia_check(port, __func__))
Paul B Schroeder3f542972006-08-31 19:41:47 -05001350 return;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001351
Harvey Harrison441b62c2008-03-03 16:08:34 -08001352 serial = mos7840_get_usb_serial(port, __func__);
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001353 if (!serial)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001354 return;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001355
1356 mos7840_port = mos7840_get_port_private(port);
1357
Alan Cox880af9d2008-07-22 11:16:12 +01001358 if (mos7840_port == NULL)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001359 return;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001360
Alan Cox95da3102008-07-22 11:09:07 +01001361 if (serial->dev)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001362 /* flush and block until tx is empty */
Alan Cox95da3102008-07-22 11:09:07 +01001363 mos7840_block_until_chase_response(tty, mos7840_port);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001364
Alan Cox95da3102008-07-22 11:09:07 +01001365 if (break_state == -1)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001366 data = mos7840_port->shadowLCR | LCR_SET_BREAK;
Alan Cox95da3102008-07-22 11:09:07 +01001367 else
Paul B Schroeder3f542972006-08-31 19:41:47 -05001368 data = mos7840_port->shadowLCR & ~LCR_SET_BREAK;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001369
Alan Cox6b447f042009-01-02 13:48:56 +00001370 /* FIXME: no locking on shadowLCR anywhere in driver */
Paul B Schroeder3f542972006-08-31 19:41:47 -05001371 mos7840_port->shadowLCR = data;
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001372 dev_dbg(&port->dev, "%s mos7840_port->shadowLCR is %x\n", __func__, mos7840_port->shadowLCR);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001373 mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER,
1374 mos7840_port->shadowLCR);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001375}
1376
1377/*****************************************************************************
1378 * mos7840_write_room
1379 * this function is called by the tty driver when it wants to know how many
1380 * bytes of data we can accept for a specific port.
1381 * If successful, we return the amount of room that we have for this port
1382 * Otherwise we return a negative error number.
1383 *****************************************************************************/
1384
Alan Cox95da3102008-07-22 11:09:07 +01001385static int mos7840_write_room(struct tty_struct *tty)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001386{
Alan Cox95da3102008-07-22 11:09:07 +01001387 struct usb_serial_port *port = tty->driver_data;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001388 int i;
1389 int room = 0;
Oliver Neukum0de9a702007-03-16 20:28:28 +01001390 unsigned long flags;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001391 struct moschip_port *mos7840_port;
1392
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001393 if (mos7840_port_paranoia_check(port, __func__))
Paul B Schroeder3f542972006-08-31 19:41:47 -05001394 return -1;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001395
1396 mos7840_port = mos7840_get_port_private(port);
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001397 if (mos7840_port == NULL)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001398 return -1;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001399
Oliver Neukum0de9a702007-03-16 20:28:28 +01001400 spin_lock_irqsave(&mos7840_port->pool_lock, flags);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001401 for (i = 0; i < NUM_URBS; ++i) {
Alan Cox880af9d2008-07-22 11:16:12 +01001402 if (!mos7840_port->busy[i])
Paul B Schroeder3f542972006-08-31 19:41:47 -05001403 room += URB_TRANSFER_BUFFER_SIZE;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001404 }
Oliver Neukum0de9a702007-03-16 20:28:28 +01001405 spin_unlock_irqrestore(&mos7840_port->pool_lock, flags);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001406
Oliver Neukum0de9a702007-03-16 20:28:28 +01001407 room = (room == 0) ? 0 : room - URB_TRANSFER_BUFFER_SIZE + 1;
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001408 dev_dbg(&mos7840_port->port->dev, "%s - returns %d\n", __func__, room);
Oliver Neukum0de9a702007-03-16 20:28:28 +01001409 return room;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001410
1411}
1412
1413/*****************************************************************************
1414 * mos7840_write
1415 * this function is called by the tty driver when data should be written to
1416 * the port.
1417 * If successful, we return the number of bytes written, otherwise we
1418 * return a negative error number.
1419 *****************************************************************************/
1420
Alan Cox95da3102008-07-22 11:09:07 +01001421static int mos7840_write(struct tty_struct *tty, struct usb_serial_port *port,
Paul B Schroeder3f542972006-08-31 19:41:47 -05001422 const unsigned char *data, int count)
1423{
1424 int status;
1425 int i;
1426 int bytes_sent = 0;
1427 int transfer_size;
Oliver Neukum0de9a702007-03-16 20:28:28 +01001428 unsigned long flags;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001429
1430 struct moschip_port *mos7840_port;
1431 struct usb_serial *serial;
1432 struct urb *urb;
Alan Cox880af9d2008-07-22 11:16:12 +01001433 /* __u16 Data; */
Paul B Schroeder3f542972006-08-31 19:41:47 -05001434 const unsigned char *current_position = data;
1435 unsigned char *data1;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001436
1437#ifdef NOTMOS7840
1438 Data = 0x00;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001439 status = mos7840_get_uart_reg(port, LINE_CONTROL_REGISTER, &Data);
1440 mos7840_port->shadowLCR = Data;
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001441 dev_dbg(&port->dev, "%s: LINE_CONTROL_REGISTER is %x\n", __func__, Data);
1442 dev_dbg(&port->dev, "%s: mos7840_port->shadowLCR is %x\n", __func__, mos7840_port->shadowLCR);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001443
Alan Cox880af9d2008-07-22 11:16:12 +01001444 /* Data = 0x03; */
1445 /* status = mos7840_set_uart_reg(port,LINE_CONTROL_REGISTER,Data); */
1446 /* mos7840_port->shadowLCR=Data;//Need to add later */
Paul B Schroeder3f542972006-08-31 19:41:47 -05001447
Alan Cox880af9d2008-07-22 11:16:12 +01001448 Data |= SERIAL_LCR_DLAB; /* data latch enable in LCR 0x80 */
Paul B Schroeder3f542972006-08-31 19:41:47 -05001449 status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
1450
Alan Cox880af9d2008-07-22 11:16:12 +01001451 /* Data = 0x0c; */
1452 /* status = mos7840_set_uart_reg(port,DIVISOR_LATCH_LSB,Data); */
Paul B Schroeder3f542972006-08-31 19:41:47 -05001453 Data = 0x00;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001454 status = mos7840_get_uart_reg(port, DIVISOR_LATCH_LSB, &Data);
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001455 dev_dbg(&port->dev, "%s: DLL value is %x\n", __func__, Data);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001456
1457 Data = 0x0;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001458 status = mos7840_get_uart_reg(port, DIVISOR_LATCH_MSB, &Data);
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001459 dev_dbg(&port->dev, "%s: DLM value is %x\n", __func__, Data);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001460
1461 Data = Data & ~SERIAL_LCR_DLAB;
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001462 dev_dbg(&port->dev, "%s: mos7840_port->shadowLCR is %x\n", __func__, mos7840_port->shadowLCR);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001463 status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
1464#endif
1465
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001466 if (mos7840_port_paranoia_check(port, __func__))
Paul B Schroeder3f542972006-08-31 19:41:47 -05001467 return -1;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001468
1469 serial = port->serial;
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001470 if (mos7840_serial_paranoia_check(serial, __func__))
Paul B Schroeder3f542972006-08-31 19:41:47 -05001471 return -1;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001472
1473 mos7840_port = mos7840_get_port_private(port);
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001474 if (mos7840_port == NULL)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001475 return -1;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001476
1477 /* try to find a free urb in the list */
1478 urb = NULL;
1479
Oliver Neukum0de9a702007-03-16 20:28:28 +01001480 spin_lock_irqsave(&mos7840_port->pool_lock, flags);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001481 for (i = 0; i < NUM_URBS; ++i) {
Oliver Neukum0de9a702007-03-16 20:28:28 +01001482 if (!mos7840_port->busy[i]) {
1483 mos7840_port->busy[i] = 1;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001484 urb = mos7840_port->write_urb_pool[i];
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001485 dev_dbg(&port->dev, "URB:%d\n", i);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001486 break;
1487 }
1488 }
Oliver Neukum0de9a702007-03-16 20:28:28 +01001489 spin_unlock_irqrestore(&mos7840_port->pool_lock, flags);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001490
1491 if (urb == NULL) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001492 dev_dbg(&port->dev, "%s - no more free urbs\n", __func__);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001493 goto exit;
1494 }
1495
1496 if (urb->transfer_buffer == NULL) {
1497 urb->transfer_buffer =
1498 kmalloc(URB_TRANSFER_BUFFER_SIZE, GFP_KERNEL);
1499
1500 if (urb->transfer_buffer == NULL) {
Johan Hovold22a416c2012-02-10 13:20:51 +01001501 dev_err_console(port, "%s no more kernel memory...\n",
Greg Kroah-Hartman194343d2008-08-20 16:56:34 -07001502 __func__);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001503 goto exit;
1504 }
1505 }
1506 transfer_size = min(count, URB_TRANSFER_BUFFER_SIZE);
1507
Al Viro97c49652006-10-09 20:29:03 +01001508 memcpy(urb->transfer_buffer, current_position, transfer_size);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001509
1510 /* fill urb with data and submit */
Donald Lee093ea2d2012-03-14 15:26:33 +08001511 if ((serial->num_ports == 2)
1512 && ((((__u16)port->number -
1513 (__u16)(port->serial->minor)) % 2) != 0)) {
1514 usb_fill_bulk_urb(urb,
1515 serial->dev,
1516 usb_sndbulkpipe(serial->dev,
1517 (port->bulk_out_endpointAddress) + 2),
1518 urb->transfer_buffer,
1519 transfer_size,
1520 mos7840_bulk_out_data_callback, mos7840_port);
1521 } else {
1522 usb_fill_bulk_urb(urb,
1523 serial->dev,
1524 usb_sndbulkpipe(serial->dev,
1525 port->bulk_out_endpointAddress),
1526 urb->transfer_buffer,
1527 transfer_size,
1528 mos7840_bulk_out_data_callback, mos7840_port);
1529 }
Paul B Schroeder3f542972006-08-31 19:41:47 -05001530
1531 data1 = urb->transfer_buffer;
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001532 dev_dbg(&port->dev, "bulkout endpoint is %d\n", port->bulk_out_endpointAddress);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001533
Donald0eafe4d2012-04-19 15:00:45 +08001534 /* Turn on LED */
1535 if (mos7840_port->has_led && !mos7840_port->led_flag) {
1536 mos7840_port->led_flag = true;
1537 mos7840_set_led_sync(port, MODEM_CONTROL_REGISTER, 0x0301);
1538 mod_timer(&mos7840_port->led_timer1,
1539 jiffies + msecs_to_jiffies(LED_ON_MS));
1540 }
1541
Paul B Schroeder3f542972006-08-31 19:41:47 -05001542 /* send it down the pipe */
1543 status = usb_submit_urb(urb, GFP_ATOMIC);
1544
1545 if (status) {
Oliver Neukum0de9a702007-03-16 20:28:28 +01001546 mos7840_port->busy[i] = 0;
Johan Hovold22a416c2012-02-10 13:20:51 +01001547 dev_err_console(port, "%s - usb_submit_urb(write bulk) failed "
Greg Kroah-Hartman194343d2008-08-20 16:56:34 -07001548 "with status = %d\n", __func__, status);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001549 bytes_sent = status;
1550 goto exit;
1551 }
1552 bytes_sent = transfer_size;
1553 mos7840_port->icount.tx += transfer_size;
Oliver Neukum0de9a702007-03-16 20:28:28 +01001554 smp_wmb();
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001555 dev_dbg(&port->dev, "mos7840_port->icount.tx is %d:\n", mos7840_port->icount.tx);
Alan Cox95da3102008-07-22 11:09:07 +01001556exit:
Paul B Schroeder3f542972006-08-31 19:41:47 -05001557 return bytes_sent;
1558
1559}
1560
1561/*****************************************************************************
1562 * mos7840_throttle
1563 * this function is called by the tty driver when it wants to stop the data
1564 * being read from the port.
1565 *****************************************************************************/
1566
Alan Cox95da3102008-07-22 11:09:07 +01001567static void mos7840_throttle(struct tty_struct *tty)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001568{
Alan Cox95da3102008-07-22 11:09:07 +01001569 struct usb_serial_port *port = tty->driver_data;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001570 struct moschip_port *mos7840_port;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001571 int status;
1572
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001573 if (mos7840_port_paranoia_check(port, __func__))
Paul B Schroeder3f542972006-08-31 19:41:47 -05001574 return;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001575
1576 mos7840_port = mos7840_get_port_private(port);
1577
1578 if (mos7840_port == NULL)
1579 return;
1580
1581 if (!mos7840_port->open) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001582 dev_dbg(&port->dev, "%s", "port not opened\n");
Paul B Schroeder3f542972006-08-31 19:41:47 -05001583 return;
1584 }
1585
Paul B Schroeder3f542972006-08-31 19:41:47 -05001586 /* if we are implementing XON/XOFF, send the stop character */
1587 if (I_IXOFF(tty)) {
1588 unsigned char stop_char = STOP_CHAR(tty);
Alan Cox95da3102008-07-22 11:09:07 +01001589 status = mos7840_write(tty, port, &stop_char, 1);
1590 if (status <= 0)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001591 return;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001592 }
Paul B Schroeder3f542972006-08-31 19:41:47 -05001593 /* if we are implementing RTS/CTS, toggle that line */
Alan Coxadc8d742012-07-14 15:31:47 +01001594 if (tty->termios.c_cflag & CRTSCTS) {
Paul B Schroeder3f542972006-08-31 19:41:47 -05001595 mos7840_port->shadowMCR &= ~MCR_RTS;
Alan Cox95da3102008-07-22 11:09:07 +01001596 status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER,
Paul B Schroeder3f542972006-08-31 19:41:47 -05001597 mos7840_port->shadowMCR);
Alan Cox95da3102008-07-22 11:09:07 +01001598 if (status < 0)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001599 return;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001600 }
Paul B Schroeder3f542972006-08-31 19:41:47 -05001601}
1602
1603/*****************************************************************************
1604 * mos7840_unthrottle
Alan Cox880af9d2008-07-22 11:16:12 +01001605 * this function is called by the tty driver when it wants to resume
1606 * the data being read from the port (called after mos7840_throttle is
1607 * called)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001608 *****************************************************************************/
Alan Cox95da3102008-07-22 11:09:07 +01001609static void mos7840_unthrottle(struct tty_struct *tty)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001610{
Alan Cox95da3102008-07-22 11:09:07 +01001611 struct usb_serial_port *port = tty->driver_data;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001612 int status;
1613 struct moschip_port *mos7840_port = mos7840_get_port_private(port);
1614
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001615 if (mos7840_port_paranoia_check(port, __func__))
Paul B Schroeder3f542972006-08-31 19:41:47 -05001616 return;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001617
1618 if (mos7840_port == NULL)
1619 return;
1620
1621 if (!mos7840_port->open) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001622 dev_dbg(&port->dev, "%s - port not opened\n", __func__);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001623 return;
1624 }
1625
Paul B Schroeder3f542972006-08-31 19:41:47 -05001626 /* if we are implementing XON/XOFF, send the start character */
1627 if (I_IXOFF(tty)) {
1628 unsigned char start_char = START_CHAR(tty);
Alan Cox95da3102008-07-22 11:09:07 +01001629 status = mos7840_write(tty, port, &start_char, 1);
1630 if (status <= 0)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001631 return;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001632 }
1633
1634 /* if we are implementing RTS/CTS, toggle that line */
Alan Coxadc8d742012-07-14 15:31:47 +01001635 if (tty->termios.c_cflag & CRTSCTS) {
Paul B Schroeder3f542972006-08-31 19:41:47 -05001636 mos7840_port->shadowMCR |= MCR_RTS;
Alan Cox95da3102008-07-22 11:09:07 +01001637 status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER,
Paul B Schroeder3f542972006-08-31 19:41:47 -05001638 mos7840_port->shadowMCR);
Alan Cox95da3102008-07-22 11:09:07 +01001639 if (status < 0)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001640 return;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001641 }
Paul B Schroeder3f542972006-08-31 19:41:47 -05001642}
1643
Alan Cox60b33c12011-02-14 16:26:14 +00001644static int mos7840_tiocmget(struct tty_struct *tty)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001645{
Alan Cox95da3102008-07-22 11:09:07 +01001646 struct usb_serial_port *port = tty->driver_data;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001647 struct moschip_port *mos7840_port;
1648 unsigned int result;
1649 __u16 msr;
1650 __u16 mcr;
Alan Cox880af9d2008-07-22 11:16:12 +01001651 int status;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001652 mos7840_port = mos7840_get_port_private(port);
1653
Paul B Schroeder3f542972006-08-31 19:41:47 -05001654 if (mos7840_port == NULL)
1655 return -ENODEV;
1656
1657 status = mos7840_get_uart_reg(port, MODEM_STATUS_REGISTER, &msr);
1658 status = mos7840_get_uart_reg(port, MODEM_CONTROL_REGISTER, &mcr);
1659 result = ((mcr & MCR_DTR) ? TIOCM_DTR : 0)
1660 | ((mcr & MCR_RTS) ? TIOCM_RTS : 0)
1661 | ((mcr & MCR_LOOPBACK) ? TIOCM_LOOP : 0)
1662 | ((msr & MOS7840_MSR_CTS) ? TIOCM_CTS : 0)
1663 | ((msr & MOS7840_MSR_CD) ? TIOCM_CAR : 0)
1664 | ((msr & MOS7840_MSR_RI) ? TIOCM_RI : 0)
1665 | ((msr & MOS7840_MSR_DSR) ? TIOCM_DSR : 0);
1666
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001667 dev_dbg(&port->dev, "%s - 0x%04X\n", __func__, result);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001668
1669 return result;
1670}
1671
Alan Cox20b9d172011-02-14 16:26:50 +00001672static int mos7840_tiocmset(struct tty_struct *tty,
Paul B Schroeder3f542972006-08-31 19:41:47 -05001673 unsigned int set, unsigned int clear)
1674{
Alan Cox95da3102008-07-22 11:09:07 +01001675 struct usb_serial_port *port = tty->driver_data;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001676 struct moschip_port *mos7840_port;
1677 unsigned int mcr;
Roel Kluin87521c42008-04-17 06:16:24 +02001678 int status;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001679
Paul B Schroeder3f542972006-08-31 19:41:47 -05001680 mos7840_port = mos7840_get_port_private(port);
1681
1682 if (mos7840_port == NULL)
1683 return -ENODEV;
1684
Alan Coxe2984492008-02-20 20:51:45 +00001685 /* FIXME: What locks the port registers ? */
Paul B Schroeder3f542972006-08-31 19:41:47 -05001686 mcr = mos7840_port->shadowMCR;
1687 if (clear & TIOCM_RTS)
1688 mcr &= ~MCR_RTS;
1689 if (clear & TIOCM_DTR)
1690 mcr &= ~MCR_DTR;
1691 if (clear & TIOCM_LOOP)
1692 mcr &= ~MCR_LOOPBACK;
1693
1694 if (set & TIOCM_RTS)
1695 mcr |= MCR_RTS;
1696 if (set & TIOCM_DTR)
1697 mcr |= MCR_DTR;
1698 if (set & TIOCM_LOOP)
1699 mcr |= MCR_LOOPBACK;
1700
1701 mos7840_port->shadowMCR = mcr;
1702
Paul B Schroeder3f542972006-08-31 19:41:47 -05001703 status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, mcr);
1704 if (status < 0) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001705 dev_dbg(&port->dev, "setting MODEM_CONTROL_REGISTER Failed\n");
Roel Kluin87521c42008-04-17 06:16:24 +02001706 return status;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001707 }
1708
1709 return 0;
1710}
1711
1712/*****************************************************************************
1713 * mos7840_calc_baud_rate_divisor
1714 * this function calculates the proper baud rate divisor for the specified
1715 * baud rate.
1716 *****************************************************************************/
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001717static int mos7840_calc_baud_rate_divisor(struct usb_serial_port *port,
1718 int baudRate, int *divisor,
Alan Cox880af9d2008-07-22 11:16:12 +01001719 __u16 *clk_sel_val)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001720{
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001721 dev_dbg(&port->dev, "%s - %d\n", __func__, baudRate);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001722
1723 if (baudRate <= 115200) {
1724 *divisor = 115200 / baudRate;
1725 *clk_sel_val = 0x0;
1726 }
1727 if ((baudRate > 115200) && (baudRate <= 230400)) {
1728 *divisor = 230400 / baudRate;
1729 *clk_sel_val = 0x10;
1730 } else if ((baudRate > 230400) && (baudRate <= 403200)) {
1731 *divisor = 403200 / baudRate;
1732 *clk_sel_val = 0x20;
1733 } else if ((baudRate > 403200) && (baudRate <= 460800)) {
1734 *divisor = 460800 / baudRate;
1735 *clk_sel_val = 0x30;
1736 } else if ((baudRate > 460800) && (baudRate <= 806400)) {
1737 *divisor = 806400 / baudRate;
1738 *clk_sel_val = 0x40;
1739 } else if ((baudRate > 806400) && (baudRate <= 921600)) {
1740 *divisor = 921600 / baudRate;
1741 *clk_sel_val = 0x50;
1742 } else if ((baudRate > 921600) && (baudRate <= 1572864)) {
1743 *divisor = 1572864 / baudRate;
1744 *clk_sel_val = 0x60;
1745 } else if ((baudRate > 1572864) && (baudRate <= 3145728)) {
1746 *divisor = 3145728 / baudRate;
1747 *clk_sel_val = 0x70;
1748 }
1749 return 0;
1750
1751#ifdef NOTMCS7840
1752
1753 for (i = 0; i < ARRAY_SIZE(mos7840_divisor_table); i++) {
1754 if (mos7840_divisor_table[i].BaudRate == baudrate) {
1755 *divisor = mos7840_divisor_table[i].Divisor;
1756 return 0;
1757 }
1758 }
1759
1760 /* After trying for all the standard baud rates *
1761 * Try calculating the divisor for this baud rate */
1762
1763 if (baudrate > 75 && baudrate < 230400) {
1764 /* get the divisor */
1765 custom = (__u16) (230400L / baudrate);
1766
1767 /* Check for round off */
1768 round1 = (__u16) (2304000L / baudrate);
1769 round = (__u16) (round1 - (custom * 10));
Alan Cox880af9d2008-07-22 11:16:12 +01001770 if (round > 4)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001771 custom++;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001772 *divisor = custom;
1773
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001774 dev_dbg(&port->dev, " Baud %d = %d\n", baudrate, custom);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001775 return 0;
1776 }
1777
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001778 dev_dbg(&port->dev, "%s", " Baud calculation Failed...\n");
Paul B Schroeder3f542972006-08-31 19:41:47 -05001779 return -1;
1780#endif
1781}
1782
1783/*****************************************************************************
1784 * mos7840_send_cmd_write_baud_rate
1785 * this function sends the proper command to change the baud rate of the
1786 * specified port.
1787 *****************************************************************************/
1788
1789static int mos7840_send_cmd_write_baud_rate(struct moschip_port *mos7840_port,
1790 int baudRate)
1791{
1792 int divisor = 0;
1793 int status;
1794 __u16 Data;
1795 unsigned char number;
1796 __u16 clk_sel_val;
1797 struct usb_serial_port *port;
1798
1799 if (mos7840_port == NULL)
1800 return -1;
1801
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001802 port = mos7840_port->port;
1803 if (mos7840_port_paranoia_check(port, __func__))
Paul B Schroeder3f542972006-08-31 19:41:47 -05001804 return -1;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001805
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001806 if (mos7840_serial_paranoia_check(port->serial, __func__))
Paul B Schroeder3f542972006-08-31 19:41:47 -05001807 return -1;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001808
Paul B Schroeder3f542972006-08-31 19:41:47 -05001809 number = mos7840_port->port->number - mos7840_port->port->serial->minor;
1810
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001811 dev_dbg(&port->dev, "%s - port = %d, baud = %d\n", __func__,
1812 mos7840_port->port->number, baudRate);
Alan Cox880af9d2008-07-22 11:16:12 +01001813 /* reset clk_uart_sel in spregOffset */
Paul B Schroeder3f542972006-08-31 19:41:47 -05001814 if (baudRate > 115200) {
1815#ifdef HW_flow_control
Alan Cox880af9d2008-07-22 11:16:12 +01001816 /* NOTE: need to see the pther register to modify */
1817 /* setting h/w flow control bit to 1 */
Paul B Schroeder3f542972006-08-31 19:41:47 -05001818 Data = 0x2b;
1819 mos7840_port->shadowMCR = Data;
Alan Cox880af9d2008-07-22 11:16:12 +01001820 status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER,
1821 Data);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001822 if (status < 0) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001823 dev_dbg(&port->dev, "Writing spreg failed in set_serial_baud\n");
Paul B Schroeder3f542972006-08-31 19:41:47 -05001824 return -1;
1825 }
1826#endif
1827
1828 } else {
1829#ifdef HW_flow_control
Donald Lee093ea2d2012-03-14 15:26:33 +08001830 /* setting h/w flow control bit to 0 */
Paul B Schroeder3f542972006-08-31 19:41:47 -05001831 Data = 0xb;
1832 mos7840_port->shadowMCR = Data;
Alan Cox880af9d2008-07-22 11:16:12 +01001833 status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER,
1834 Data);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001835 if (status < 0) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001836 dev_dbg(&port->dev, "Writing spreg failed in set_serial_baud\n");
Paul B Schroeder3f542972006-08-31 19:41:47 -05001837 return -1;
1838 }
1839#endif
1840
1841 }
1842
Alan Cox880af9d2008-07-22 11:16:12 +01001843 if (1) { /* baudRate <= 115200) */
Paul B Schroeder3f542972006-08-31 19:41:47 -05001844 clk_sel_val = 0x0;
1845 Data = 0x0;
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001846 status = mos7840_calc_baud_rate_divisor(port, baudRate, &divisor,
Paul B Schroeder3f542972006-08-31 19:41:47 -05001847 &clk_sel_val);
Alan Cox880af9d2008-07-22 11:16:12 +01001848 status = mos7840_get_reg_sync(port, mos7840_port->SpRegOffset,
1849 &Data);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001850 if (status < 0) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001851 dev_dbg(&port->dev, "reading spreg failed in set_serial_baud\n");
Paul B Schroeder3f542972006-08-31 19:41:47 -05001852 return -1;
1853 }
1854 Data = (Data & 0x8f) | clk_sel_val;
Alan Cox880af9d2008-07-22 11:16:12 +01001855 status = mos7840_set_reg_sync(port, mos7840_port->SpRegOffset,
1856 Data);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001857 if (status < 0) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001858 dev_dbg(&port->dev, "Writing spreg failed in set_serial_baud\n");
Paul B Schroeder3f542972006-08-31 19:41:47 -05001859 return -1;
1860 }
1861 /* Calculate the Divisor */
1862
1863 if (status) {
Greg Kroah-Hartman194343d2008-08-20 16:56:34 -07001864 dev_err(&port->dev, "%s - bad baud rate\n", __func__);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001865 return status;
1866 }
1867 /* Enable access to divisor latch */
1868 Data = mos7840_port->shadowLCR | SERIAL_LCR_DLAB;
1869 mos7840_port->shadowLCR = Data;
1870 mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
1871
1872 /* Write the divisor */
1873 Data = (unsigned char)(divisor & 0xff);
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001874 dev_dbg(&port->dev, "set_serial_baud Value to write DLL is %x\n", Data);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001875 mos7840_set_uart_reg(port, DIVISOR_LATCH_LSB, Data);
1876
1877 Data = (unsigned char)((divisor & 0xff00) >> 8);
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001878 dev_dbg(&port->dev, "set_serial_baud Value to write DLM is %x\n", Data);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001879 mos7840_set_uart_reg(port, DIVISOR_LATCH_MSB, Data);
1880
1881 /* Disable access to divisor latch */
1882 Data = mos7840_port->shadowLCR & ~SERIAL_LCR_DLAB;
1883 mos7840_port->shadowLCR = Data;
1884 mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
1885
1886 }
Paul B Schroeder3f542972006-08-31 19:41:47 -05001887 return status;
1888}
1889
1890/*****************************************************************************
1891 * mos7840_change_port_settings
1892 * This routine is called to set the UART on the device to match
1893 * the specified new settings.
1894 *****************************************************************************/
1895
Alan Cox95da3102008-07-22 11:09:07 +01001896static void mos7840_change_port_settings(struct tty_struct *tty,
1897 struct moschip_port *mos7840_port, struct ktermios *old_termios)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001898{
Paul B Schroeder3f542972006-08-31 19:41:47 -05001899 int baud;
1900 unsigned cflag;
1901 unsigned iflag;
1902 __u8 lData;
1903 __u8 lParity;
1904 __u8 lStop;
1905 int status;
1906 __u16 Data;
1907 struct usb_serial_port *port;
1908 struct usb_serial *serial;
1909
1910 if (mos7840_port == NULL)
1911 return;
1912
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001913 port = mos7840_port->port;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001914
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001915 if (mos7840_port_paranoia_check(port, __func__))
Paul B Schroeder3f542972006-08-31 19:41:47 -05001916 return;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001917
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001918 if (mos7840_serial_paranoia_check(port->serial, __func__))
Paul B Schroeder3f542972006-08-31 19:41:47 -05001919 return;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001920
1921 serial = port->serial;
1922
Paul B Schroeder3f542972006-08-31 19:41:47 -05001923 if (!mos7840_port->open) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001924 dev_dbg(&port->dev, "%s - port not opened\n", __func__);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001925 return;
1926 }
1927
Paul B Schroeder3f542972006-08-31 19:41:47 -05001928 lData = LCR_BITS_8;
1929 lStop = LCR_STOP_1;
1930 lParity = LCR_PAR_NONE;
1931
Alan Coxadc8d742012-07-14 15:31:47 +01001932 cflag = tty->termios.c_cflag;
1933 iflag = tty->termios.c_iflag;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001934
1935 /* Change the number of bits */
1936 if (cflag & CSIZE) {
1937 switch (cflag & CSIZE) {
1938 case CS5:
1939 lData = LCR_BITS_5;
1940 break;
1941
1942 case CS6:
1943 lData = LCR_BITS_6;
1944 break;
1945
1946 case CS7:
1947 lData = LCR_BITS_7;
1948 break;
1949 default:
1950 case CS8:
1951 lData = LCR_BITS_8;
1952 break;
1953 }
1954 }
1955 /* Change the Parity bit */
1956 if (cflag & PARENB) {
1957 if (cflag & PARODD) {
1958 lParity = LCR_PAR_ODD;
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001959 dev_dbg(&port->dev, "%s - parity = odd\n", __func__);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001960 } else {
1961 lParity = LCR_PAR_EVEN;
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001962 dev_dbg(&port->dev, "%s - parity = even\n", __func__);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001963 }
1964
1965 } else {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001966 dev_dbg(&port->dev, "%s - parity = none\n", __func__);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001967 }
1968
Alan Cox880af9d2008-07-22 11:16:12 +01001969 if (cflag & CMSPAR)
Paul B Schroeder3f542972006-08-31 19:41:47 -05001970 lParity = lParity | 0x20;
Paul B Schroeder3f542972006-08-31 19:41:47 -05001971
1972 /* Change the Stop bit */
1973 if (cflag & CSTOPB) {
1974 lStop = LCR_STOP_2;
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001975 dev_dbg(&port->dev, "%s - stop bits = 2\n", __func__);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001976 } else {
1977 lStop = LCR_STOP_1;
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001978 dev_dbg(&port->dev, "%s - stop bits = 1\n", __func__);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001979 }
1980
1981 /* Update the LCR with the correct value */
1982 mos7840_port->shadowLCR &=
1983 ~(LCR_BITS_MASK | LCR_STOP_MASK | LCR_PAR_MASK);
1984 mos7840_port->shadowLCR |= (lData | lParity | lStop);
1985
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07001986 dev_dbg(&port->dev, "%s - mos7840_port->shadowLCR is %x\n", __func__,
1987 mos7840_port->shadowLCR);
Paul B Schroeder3f542972006-08-31 19:41:47 -05001988 /* Disable Interrupts */
1989 Data = 0x00;
1990 mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data);
1991
1992 Data = 0x00;
1993 mos7840_set_uart_reg(port, FIFO_CONTROL_REGISTER, Data);
1994
1995 Data = 0xcf;
1996 mos7840_set_uart_reg(port, FIFO_CONTROL_REGISTER, Data);
1997
1998 /* Send the updated LCR value to the mos7840 */
1999 Data = mos7840_port->shadowLCR;
2000
2001 mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
2002
2003 Data = 0x00b;
2004 mos7840_port->shadowMCR = Data;
2005 mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
2006 Data = 0x00b;
2007 mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
2008
2009 /* set up the MCR register and send it to the mos7840 */
2010
2011 mos7840_port->shadowMCR = MCR_MASTER_IE;
Alan Cox880af9d2008-07-22 11:16:12 +01002012 if (cflag & CBAUD)
Paul B Schroeder3f542972006-08-31 19:41:47 -05002013 mos7840_port->shadowMCR |= (MCR_DTR | MCR_RTS);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002014
Alan Cox880af9d2008-07-22 11:16:12 +01002015 if (cflag & CRTSCTS)
Paul B Schroeder3f542972006-08-31 19:41:47 -05002016 mos7840_port->shadowMCR |= (MCR_XON_ANY);
Alan Cox880af9d2008-07-22 11:16:12 +01002017 else
Paul B Schroeder3f542972006-08-31 19:41:47 -05002018 mos7840_port->shadowMCR &= ~(MCR_XON_ANY);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002019
2020 Data = mos7840_port->shadowMCR;
2021 mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
2022
2023 /* Determine divisor based on baud rate */
2024 baud = tty_get_baud_rate(tty);
2025
2026 if (!baud) {
2027 /* pick a default, any default... */
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002028 dev_dbg(&port->dev, "%s", "Picked default baud...\n");
Paul B Schroeder3f542972006-08-31 19:41:47 -05002029 baud = 9600;
2030 }
2031
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002032 dev_dbg(&port->dev, "%s - baud rate = %d\n", __func__, baud);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002033 status = mos7840_send_cmd_write_baud_rate(mos7840_port, baud);
2034
2035 /* Enable Interrupts */
2036 Data = 0x0c;
2037 mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data);
2038
Greg Kroah-Hartman50de36f2008-12-10 16:00:30 -08002039 if (mos7840_port->read_urb_busy == false) {
Greg Kroah-Hartman50de36f2008-12-10 16:00:30 -08002040 mos7840_port->read_urb_busy = true;
Paul B Schroeder3f542972006-08-31 19:41:47 -05002041 status = usb_submit_urb(mos7840_port->read_urb, GFP_ATOMIC);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002042 if (status) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002043 dev_dbg(&port->dev, "usb_submit_urb(read bulk) failed, status = %d\n",
Paul B Schroeder3f542972006-08-31 19:41:47 -05002044 status);
Greg Kroah-Hartman50de36f2008-12-10 16:00:30 -08002045 mos7840_port->read_urb_busy = false;
Paul B Schroeder3f542972006-08-31 19:41:47 -05002046 }
2047 }
2048 wake_up(&mos7840_port->delta_msr_wait);
2049 mos7840_port->delta_msr_cond = 1;
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002050 dev_dbg(&port->dev, "%s - mos7840_port->shadowLCR is End %x\n", __func__,
2051 mos7840_port->shadowLCR);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002052}
2053
2054/*****************************************************************************
2055 * mos7840_set_termios
2056 * this function is called by the tty driver when it wants to change
2057 * the termios structure
2058 *****************************************************************************/
2059
Alan Cox95da3102008-07-22 11:09:07 +01002060static void mos7840_set_termios(struct tty_struct *tty,
2061 struct usb_serial_port *port,
Alan Cox606d0992006-12-08 02:38:45 -08002062 struct ktermios *old_termios)
Paul B Schroeder3f542972006-08-31 19:41:47 -05002063{
2064 int status;
2065 unsigned int cflag;
2066 struct usb_serial *serial;
2067 struct moschip_port *mos7840_port;
Greg Kroah-Hartman33631552012-05-03 16:44:33 -07002068
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002069 if (mos7840_port_paranoia_check(port, __func__))
Paul B Schroeder3f542972006-08-31 19:41:47 -05002070 return;
Paul B Schroeder3f542972006-08-31 19:41:47 -05002071
2072 serial = port->serial;
2073
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002074 if (mos7840_serial_paranoia_check(serial, __func__))
Paul B Schroeder3f542972006-08-31 19:41:47 -05002075 return;
Paul B Schroeder3f542972006-08-31 19:41:47 -05002076
2077 mos7840_port = mos7840_get_port_private(port);
2078
2079 if (mos7840_port == NULL)
2080 return;
2081
Paul B Schroeder3f542972006-08-31 19:41:47 -05002082 if (!mos7840_port->open) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002083 dev_dbg(&port->dev, "%s - port not opened\n", __func__);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002084 return;
2085 }
2086
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002087 dev_dbg(&port->dev, "%s", "setting termios - \n");
Paul B Schroeder3f542972006-08-31 19:41:47 -05002088
Alan Coxadc8d742012-07-14 15:31:47 +01002089 cflag = tty->termios.c_cflag;
Paul B Schroeder3f542972006-08-31 19:41:47 -05002090
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002091 dev_dbg(&port->dev, "%s - clfag %08x iflag %08x\n", __func__,
Linus Torvaldsd9a80742012-10-01 13:23:01 -07002092 tty->termios.c_cflag, RELEVANT_IFLAG(tty->termios.c_iflag));
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002093 dev_dbg(&port->dev, "%s - old clfag %08x old iflag %08x\n", __func__,
2094 old_termios->c_cflag, RELEVANT_IFLAG(old_termios->c_iflag));
2095 dev_dbg(&port->dev, "%s - port %d\n", __func__, port->number);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002096
2097 /* change the port settings to the new ones specified */
2098
Alan Cox95da3102008-07-22 11:09:07 +01002099 mos7840_change_port_settings(tty, mos7840_port, old_termios);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002100
2101 if (!mos7840_port->read_urb) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002102 dev_dbg(&port->dev, "%s", "URB KILLED !!!!!\n");
Paul B Schroeder3f542972006-08-31 19:41:47 -05002103 return;
2104 }
2105
Greg Kroah-Hartman50de36f2008-12-10 16:00:30 -08002106 if (mos7840_port->read_urb_busy == false) {
Greg Kroah-Hartman50de36f2008-12-10 16:00:30 -08002107 mos7840_port->read_urb_busy = true;
Paul B Schroeder3f542972006-08-31 19:41:47 -05002108 status = usb_submit_urb(mos7840_port->read_urb, GFP_ATOMIC);
2109 if (status) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002110 dev_dbg(&port->dev, "usb_submit_urb(read bulk) failed, status = %d\n",
Paul B Schroeder3f542972006-08-31 19:41:47 -05002111 status);
Greg Kroah-Hartman50de36f2008-12-10 16:00:30 -08002112 mos7840_port->read_urb_busy = false;
Paul B Schroeder3f542972006-08-31 19:41:47 -05002113 }
2114 }
Paul B Schroeder3f542972006-08-31 19:41:47 -05002115}
2116
2117/*****************************************************************************
2118 * mos7840_get_lsr_info - get line status register info
2119 *
2120 * Purpose: Let user call ioctl() to get info when the UART physically
2121 * is emptied. On bus types like RS485, the transmitter must
2122 * release the bus after transmitting. This must be done when
2123 * the transmit shift register is empty, not be done when the
2124 * transmit holding register is empty. This functionality
2125 * allows an RS485 driver to be written in user space.
2126 *****************************************************************************/
2127
Alan Cox95da3102008-07-22 11:09:07 +01002128static int mos7840_get_lsr_info(struct tty_struct *tty,
Al Viro97c49652006-10-09 20:29:03 +01002129 unsigned int __user *value)
Paul B Schroeder3f542972006-08-31 19:41:47 -05002130{
2131 int count;
2132 unsigned int result = 0;
2133
Alan Cox95da3102008-07-22 11:09:07 +01002134 count = mos7840_chars_in_buffer(tty);
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002135 if (count == 0)
Paul B Schroeder3f542972006-08-31 19:41:47 -05002136 result = TIOCSER_TEMT;
Paul B Schroeder3f542972006-08-31 19:41:47 -05002137
2138 if (copy_to_user(value, &result, sizeof(int)))
2139 return -EFAULT;
2140 return 0;
2141}
2142
2143/*****************************************************************************
Paul B Schroeder3f542972006-08-31 19:41:47 -05002144 * mos7840_get_serial_info
2145 * function to get information about serial port
2146 *****************************************************************************/
2147
2148static int mos7840_get_serial_info(struct moschip_port *mos7840_port,
Al Viro97c49652006-10-09 20:29:03 +01002149 struct serial_struct __user *retinfo)
Paul B Schroeder3f542972006-08-31 19:41:47 -05002150{
2151 struct serial_struct tmp;
2152
2153 if (mos7840_port == NULL)
2154 return -1;
2155
2156 if (!retinfo)
2157 return -EFAULT;
2158
2159 memset(&tmp, 0, sizeof(tmp));
2160
2161 tmp.type = PORT_16550A;
2162 tmp.line = mos7840_port->port->serial->minor;
2163 tmp.port = mos7840_port->port->number;
2164 tmp.irq = 0;
2165 tmp.flags = ASYNC_SKIP_TEST | ASYNC_AUTO_IRQ;
2166 tmp.xmit_fifo_size = NUM_URBS * URB_TRANSFER_BUFFER_SIZE;
2167 tmp.baud_base = 9600;
2168 tmp.close_delay = 5 * HZ;
2169 tmp.closing_wait = 30 * HZ;
2170
2171 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
2172 return -EFAULT;
2173 return 0;
2174}
2175
Alan Cox0bca1b92010-09-16 18:21:40 +01002176static int mos7840_get_icount(struct tty_struct *tty,
2177 struct serial_icounter_struct *icount)
2178{
2179 struct usb_serial_port *port = tty->driver_data;
2180 struct moschip_port *mos7840_port;
2181 struct async_icount cnow;
2182
2183 mos7840_port = mos7840_get_port_private(port);
2184 cnow = mos7840_port->icount;
2185
2186 smp_rmb();
2187 icount->cts = cnow.cts;
2188 icount->dsr = cnow.dsr;
2189 icount->rng = cnow.rng;
2190 icount->dcd = cnow.dcd;
2191 icount->rx = cnow.rx;
2192 icount->tx = cnow.tx;
2193 icount->frame = cnow.frame;
2194 icount->overrun = cnow.overrun;
2195 icount->parity = cnow.parity;
2196 icount->brk = cnow.brk;
2197 icount->buf_overrun = cnow.buf_overrun;
2198
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002199 dev_dbg(&port->dev, "%s TIOCGICOUNT RX=%d, TX=%d\n", __func__,
2200 icount->rx, icount->tx);
Alan Cox0bca1b92010-09-16 18:21:40 +01002201 return 0;
2202}
2203
Paul B Schroeder3f542972006-08-31 19:41:47 -05002204/*****************************************************************************
2205 * SerialIoctl
2206 * this function handles any ioctl calls to the driver
2207 *****************************************************************************/
2208
Alan Cox00a0d0d2011-02-14 16:27:06 +00002209static int mos7840_ioctl(struct tty_struct *tty,
Paul B Schroeder3f542972006-08-31 19:41:47 -05002210 unsigned int cmd, unsigned long arg)
2211{
Alan Cox95da3102008-07-22 11:09:07 +01002212 struct usb_serial_port *port = tty->driver_data;
Al Viro97c49652006-10-09 20:29:03 +01002213 void __user *argp = (void __user *)arg;
Paul B Schroeder3f542972006-08-31 19:41:47 -05002214 struct moschip_port *mos7840_port;
Paul B Schroeder3f542972006-08-31 19:41:47 -05002215
2216 struct async_icount cnow;
2217 struct async_icount cprev;
Paul B Schroeder3f542972006-08-31 19:41:47 -05002218
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002219 if (mos7840_port_paranoia_check(port, __func__))
Paul B Schroeder3f542972006-08-31 19:41:47 -05002220 return -1;
Paul B Schroeder3f542972006-08-31 19:41:47 -05002221
2222 mos7840_port = mos7840_get_port_private(port);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002223
2224 if (mos7840_port == NULL)
2225 return -1;
2226
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002227 dev_dbg(&port->dev, "%s - cmd = 0x%x\n", __func__, cmd);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002228
2229 switch (cmd) {
2230 /* return number of bytes available */
2231
Paul B Schroeder3f542972006-08-31 19:41:47 -05002232 case TIOCSERGETLSR:
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002233 dev_dbg(&port->dev, "%s TIOCSERGETLSR\n", __func__);
Alan Cox95da3102008-07-22 11:09:07 +01002234 return mos7840_get_lsr_info(tty, argp);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002235
Paul B Schroeder3f542972006-08-31 19:41:47 -05002236 case TIOCGSERIAL:
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002237 dev_dbg(&port->dev, "%s TIOCGSERIAL\n", __func__);
Al Viro97c49652006-10-09 20:29:03 +01002238 return mos7840_get_serial_info(mos7840_port, argp);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002239
2240 case TIOCSSERIAL:
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002241 dev_dbg(&port->dev, "%s TIOCSSERIAL\n", __func__);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002242 break;
2243
2244 case TIOCMIWAIT:
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002245 dev_dbg(&port->dev, "%s TIOCMIWAIT\n", __func__);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002246 cprev = mos7840_port->icount;
2247 while (1) {
Alan Cox880af9d2008-07-22 11:16:12 +01002248 /* interruptible_sleep_on(&mos7840_port->delta_msr_wait); */
Paul B Schroeder3f542972006-08-31 19:41:47 -05002249 mos7840_port->delta_msr_cond = 0;
2250 wait_event_interruptible(mos7840_port->delta_msr_wait,
2251 (mos7840_port->
2252 delta_msr_cond == 1));
2253
2254 /* see if a signal did it */
2255 if (signal_pending(current))
2256 return -ERESTARTSYS;
2257 cnow = mos7840_port->icount;
Oliver Neukum0de9a702007-03-16 20:28:28 +01002258 smp_rmb();
Paul B Schroeder3f542972006-08-31 19:41:47 -05002259 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
2260 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts)
2261 return -EIO; /* no change => error */
2262 if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
2263 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
2264 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
2265 ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts))) {
2266 return 0;
2267 }
2268 cprev = cnow;
2269 }
2270 /* NOTREACHED */
2271 break;
2272
Paul B Schroeder3f542972006-08-31 19:41:47 -05002273 default:
2274 break;
2275 }
Paul B Schroeder3f542972006-08-31 19:41:47 -05002276 return -ENOIOCTLCMD;
2277}
2278
Donald0eafe4d2012-04-19 15:00:45 +08002279static int mos7810_check(struct usb_serial *serial)
2280{
2281 int i, pass_count = 0;
2282 __u16 data = 0, mcr_data = 0;
2283 __u16 test_pattern = 0x55AA;
2284
2285 /* Store MCR setting */
2286 usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
2287 MCS_RDREQ, MCS_RD_RTYPE, 0x0300, MODEM_CONTROL_REGISTER,
2288 &mcr_data, VENDOR_READ_LENGTH, MOS_WDR_TIMEOUT);
2289
2290 for (i = 0; i < 16; i++) {
2291 /* Send the 1-bit test pattern out to MCS7810 test pin */
2292 usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
2293 MCS_WRREQ, MCS_WR_RTYPE,
2294 (0x0300 | (((test_pattern >> i) & 0x0001) << 1)),
2295 MODEM_CONTROL_REGISTER, NULL, 0, MOS_WDR_TIMEOUT);
2296
2297 /* Read the test pattern back */
2298 usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
2299 MCS_RDREQ, MCS_RD_RTYPE, 0, GPIO_REGISTER, &data,
2300 VENDOR_READ_LENGTH, MOS_WDR_TIMEOUT);
2301
2302 /* If this is a MCS7810 device, both test patterns must match */
2303 if (((test_pattern >> i) ^ (~data >> 1)) & 0x0001)
2304 break;
2305
2306 pass_count++;
2307 }
2308
2309 /* Restore MCR setting */
2310 usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), MCS_WRREQ,
2311 MCS_WR_RTYPE, 0x0300 | mcr_data, MODEM_CONTROL_REGISTER, NULL,
2312 0, MOS_WDR_TIMEOUT);
2313
2314 if (pass_count == 16)
2315 return 1;
2316
2317 return 0;
2318}
2319
Paul B Schroeder3f542972006-08-31 19:41:47 -05002320static int mos7840_calc_num_ports(struct usb_serial *serial)
2321{
Donald0eafe4d2012-04-19 15:00:45 +08002322 __u16 data = 0x00;
Donald Lee093ea2d2012-03-14 15:26:33 +08002323 int mos7840_num_ports;
Paul B Schroeder3f542972006-08-31 19:41:47 -05002324
Donald0eafe4d2012-04-19 15:00:45 +08002325 usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
2326 MCS_RDREQ, MCS_RD_RTYPE, 0, GPIO_REGISTER, &data,
Donald Lee093ea2d2012-03-14 15:26:33 +08002327 VENDOR_READ_LENGTH, MOS_WDR_TIMEOUT);
2328
Donald0eafe4d2012-04-19 15:00:45 +08002329 if (serial->dev->descriptor.idProduct == MOSCHIP_DEVICE_ID_7810 ||
2330 serial->dev->descriptor.idProduct == MOSCHIP_DEVICE_ID_7820) {
2331 device_type = serial->dev->descriptor.idProduct;
Donald Lee093ea2d2012-03-14 15:26:33 +08002332 } else {
Donald0eafe4d2012-04-19 15:00:45 +08002333 /* For a MCS7840 device GPIO0 must be set to 1 */
2334 if ((data & 0x01) == 1)
2335 device_type = MOSCHIP_DEVICE_ID_7840;
2336 else if (mos7810_check(serial))
2337 device_type = MOSCHIP_DEVICE_ID_7810;
2338 else
2339 device_type = MOSCHIP_DEVICE_ID_7820;
Paul B Schroeder3f542972006-08-31 19:41:47 -05002340 }
Donald Lee093ea2d2012-03-14 15:26:33 +08002341
Donald0eafe4d2012-04-19 15:00:45 +08002342 mos7840_num_ports = (device_type >> 4) & 0x000F;
2343 serial->num_bulk_in = mos7840_num_ports;
2344 serial->num_bulk_out = mos7840_num_ports;
2345 serial->num_ports = mos7840_num_ports;
2346
Paul B Schroeder3f542972006-08-31 19:41:47 -05002347 return mos7840_num_ports;
2348}
2349
2350/****************************************************************************
2351 * mos7840_startup
2352 ****************************************************************************/
2353
2354static int mos7840_startup(struct usb_serial *serial)
2355{
2356 struct moschip_port *mos7840_port;
2357 struct usb_device *dev;
2358 int i, status;
Paul B Schroeder3f542972006-08-31 19:41:47 -05002359 __u16 Data;
Paul B Schroeder3f542972006-08-31 19:41:47 -05002360
Paul B Schroeder3f542972006-08-31 19:41:47 -05002361 dev = serial->dev;
2362
Paul B Schroeder3f542972006-08-31 19:41:47 -05002363 /* we set up the pointers to the endpoints in the mos7840_open *
2364 * function, as the structures aren't created yet. */
2365
2366 /* set up port private structures */
2367 for (i = 0; i < serial->num_ports; ++i) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002368 dev_dbg(&dev->dev, "mos7840_startup: configuring port %d............\n", i);
Burman Yan7ac9da12006-11-22 20:54:38 +02002369 mos7840_port = kzalloc(sizeof(struct moschip_port), GFP_KERNEL);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002370 if (mos7840_port == NULL) {
Greg Kroah-Hartman194343d2008-08-20 16:56:34 -07002371 dev_err(&dev->dev, "%s - Out of memory\n", __func__);
Oliver Neukum0de9a702007-03-16 20:28:28 +01002372 status = -ENOMEM;
2373 i--; /* don't follow NULL pointer cleaning up */
2374 goto error;
Paul B Schroeder3f542972006-08-31 19:41:47 -05002375 }
Paul B Schroeder3f542972006-08-31 19:41:47 -05002376
Alan Cox880af9d2008-07-22 11:16:12 +01002377 /* Initialize all port interrupt end point to port 0 int
2378 * endpoint. Our device has only one interrupt end point
2379 * common to all port */
Paul B Schroeder3f542972006-08-31 19:41:47 -05002380
2381 mos7840_port->port = serial->port[i];
2382 mos7840_set_port_private(serial->port[i], mos7840_port);
Oliver Neukum0de9a702007-03-16 20:28:28 +01002383 spin_lock_init(&mos7840_port->pool_lock);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002384
Tony Cook37768ad2009-04-18 22:42:18 +09302385 /* minor is not initialised until later by
2386 * usb-serial.c:get_free_serial() and cannot therefore be used
2387 * to index device instances */
2388 mos7840_port->port_num = i + 1;
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002389 dev_dbg(&dev->dev, "serial->port[i]->number = %d\n", serial->port[i]->number);
2390 dev_dbg(&dev->dev, "serial->port[i]->serial->minor = %d\n", serial->port[i]->serial->minor);
2391 dev_dbg(&dev->dev, "mos7840_port->port_num = %d\n", mos7840_port->port_num);
2392 dev_dbg(&dev->dev, "serial->minor = %d\n", serial->minor);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002393
2394 if (mos7840_port->port_num == 1) {
2395 mos7840_port->SpRegOffset = 0x0;
2396 mos7840_port->ControlRegOffset = 0x1;
2397 mos7840_port->DcrRegOffset = 0x4;
2398 } else if ((mos7840_port->port_num == 2)
Oliver Neukum0de9a702007-03-16 20:28:28 +01002399 && (serial->num_ports == 4)) {
Paul B Schroeder3f542972006-08-31 19:41:47 -05002400 mos7840_port->SpRegOffset = 0x8;
2401 mos7840_port->ControlRegOffset = 0x9;
2402 mos7840_port->DcrRegOffset = 0x16;
2403 } else if ((mos7840_port->port_num == 2)
Oliver Neukum0de9a702007-03-16 20:28:28 +01002404 && (serial->num_ports == 2)) {
Paul B Schroeder3f542972006-08-31 19:41:47 -05002405 mos7840_port->SpRegOffset = 0xa;
2406 mos7840_port->ControlRegOffset = 0xb;
2407 mos7840_port->DcrRegOffset = 0x19;
2408 } else if ((mos7840_port->port_num == 3)
Oliver Neukum0de9a702007-03-16 20:28:28 +01002409 && (serial->num_ports == 4)) {
Paul B Schroeder3f542972006-08-31 19:41:47 -05002410 mos7840_port->SpRegOffset = 0xa;
2411 mos7840_port->ControlRegOffset = 0xb;
2412 mos7840_port->DcrRegOffset = 0x19;
2413 } else if ((mos7840_port->port_num == 4)
Oliver Neukum0de9a702007-03-16 20:28:28 +01002414 && (serial->num_ports == 4)) {
Paul B Schroeder3f542972006-08-31 19:41:47 -05002415 mos7840_port->SpRegOffset = 0xc;
2416 mos7840_port->ControlRegOffset = 0xd;
2417 mos7840_port->DcrRegOffset = 0x1c;
2418 }
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002419 mos7840_dump_serial_port(serial->port[i], mos7840_port);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002420 mos7840_set_port_private(serial->port[i], mos7840_port);
2421
Alan Cox880af9d2008-07-22 11:16:12 +01002422 /* enable rx_disable bit in control register */
2423 status = mos7840_get_reg_sync(serial->port[i],
2424 mos7840_port->ControlRegOffset, &Data);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002425 if (status < 0) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002426 dev_dbg(&dev->dev, "Reading ControlReg failed 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 Reading success val is %x, status%d\n", Data, status);
Alan Cox880af9d2008-07-22 11:16:12 +01002430 Data |= 0x08; /* setting driver done bit */
2431 Data |= 0x04; /* sp1_bit to have cts change reflect in
2432 modem status reg */
Paul B Schroeder3f542972006-08-31 19:41:47 -05002433
Alan Cox880af9d2008-07-22 11:16:12 +01002434 /* Data |= 0x20; //rx_disable bit */
2435 status = mos7840_set_reg_sync(serial->port[i],
Paul B Schroeder3f542972006-08-31 19:41:47 -05002436 mos7840_port->ControlRegOffset, Data);
2437 if (status < 0) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002438 dev_dbg(&dev->dev, "Writing ControlReg failed(rx_disable) status-0x%x\n", status);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002439 break;
2440 } else
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002441 dev_dbg(&dev->dev, "ControlReg Writing success(rx_disable) status%d\n", status);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002442
Alan Cox880af9d2008-07-22 11:16:12 +01002443 /* Write default values in DCR (i.e 0x01 in DCR0, 0x05 in DCR2
2444 and 0x24 in DCR3 */
Paul B Schroeder3f542972006-08-31 19:41:47 -05002445 Data = 0x01;
Alan Cox880af9d2008-07-22 11:16:12 +01002446 status = mos7840_set_reg_sync(serial->port[i],
2447 (__u16) (mos7840_port->DcrRegOffset + 0), Data);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002448 if (status < 0) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002449 dev_dbg(&dev->dev, "Writing DCR0 failed status-0x%x\n", status);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002450 break;
2451 } else
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002452 dev_dbg(&dev->dev, "DCR0 Writing success status%d\n", status);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002453
2454 Data = 0x05;
Alan Cox880af9d2008-07-22 11:16:12 +01002455 status = mos7840_set_reg_sync(serial->port[i],
2456 (__u16) (mos7840_port->DcrRegOffset + 1), Data);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002457 if (status < 0) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002458 dev_dbg(&dev->dev, "Writing DCR1 failed status-0x%x\n", status);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002459 break;
2460 } else
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002461 dev_dbg(&dev->dev, "DCR1 Writing success status%d\n", status);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002462
2463 Data = 0x24;
Alan Cox880af9d2008-07-22 11:16:12 +01002464 status = mos7840_set_reg_sync(serial->port[i],
2465 (__u16) (mos7840_port->DcrRegOffset + 2), Data);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002466 if (status < 0) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002467 dev_dbg(&dev->dev, "Writing DCR2 failed status-0x%x\n", status);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002468 break;
2469 } else
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002470 dev_dbg(&dev->dev, "DCR2 Writing success status%d\n", status);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002471
Alan Cox880af9d2008-07-22 11:16:12 +01002472 /* write values in clkstart0x0 and clkmulti 0x20 */
Paul B Schroeder3f542972006-08-31 19:41:47 -05002473 Data = 0x0;
Alan Cox880af9d2008-07-22 11:16:12 +01002474 status = mos7840_set_reg_sync(serial->port[i],
Paul B Schroeder3f542972006-08-31 19:41:47 -05002475 CLK_START_VALUE_REGISTER, Data);
2476 if (status < 0) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002477 dev_dbg(&dev->dev, "Writing CLK_START_VALUE_REGISTER failed status-0x%x\n", status);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002478 break;
2479 } else
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002480 dev_dbg(&dev->dev, "CLK_START_VALUE_REGISTER Writing success status%d\n", status);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002481
2482 Data = 0x20;
Alan Cox880af9d2008-07-22 11:16:12 +01002483 status = mos7840_set_reg_sync(serial->port[i],
2484 CLK_MULTI_REGISTER, Data);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002485 if (status < 0) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002486 dev_dbg(&dev->dev, "Writing CLK_MULTI_REGISTER failed status-0x%x\n", status);
Oliver Neukum0de9a702007-03-16 20:28:28 +01002487 goto error;
Paul B Schroeder3f542972006-08-31 19:41:47 -05002488 } else
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002489 dev_dbg(&dev->dev, "CLK_MULTI_REGISTER Writing success status%d\n", status);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002490
Alan Cox880af9d2008-07-22 11:16:12 +01002491 /* write value 0x0 to scratchpad register */
Paul B Schroeder3f542972006-08-31 19:41:47 -05002492 Data = 0x00;
Alan Cox880af9d2008-07-22 11:16:12 +01002493 status = mos7840_set_uart_reg(serial->port[i],
2494 SCRATCH_PAD_REGISTER, Data);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002495 if (status < 0) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002496 dev_dbg(&dev->dev, "Writing SCRATCH_PAD_REGISTER failed status-0x%x\n", status);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002497 break;
2498 } else
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002499 dev_dbg(&dev->dev, "SCRATCH_PAD_REGISTER Writing success status%d\n", status);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002500
Alan Cox880af9d2008-07-22 11:16:12 +01002501 /* Zero Length flag register */
Paul B Schroeder3f542972006-08-31 19:41:47 -05002502 if ((mos7840_port->port_num != 1)
Oliver Neukum0de9a702007-03-16 20:28:28 +01002503 && (serial->num_ports == 2)) {
Paul B Schroeder3f542972006-08-31 19:41:47 -05002504
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)), 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)));
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 + 2, 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 + 2, status);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002516 } else {
2517 Data = 0xff;
Paul B Schroeder3f542972006-08-31 19:41:47 -05002518 status = mos7840_set_reg_sync(serial->port[i],
Alan Cox880af9d2008-07-22 11:16:12 +01002519 (__u16) (ZLP_REG1 +
2520 ((__u16)mos7840_port->port_num) - 0x1), Data);
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002521 dev_dbg(&dev->dev, "ZLIP offset %x\n",
2522 (__u16)(ZLP_REG1 + ((__u16) mos7840_port->port_num) - 0x1));
Paul B Schroeder3f542972006-08-31 19:41:47 -05002523 if (status < 0) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002524 dev_dbg(&dev->dev, "Writing ZLP_REG%d failed status-0x%x\n", i + 1, status);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002525 break;
2526 } else
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002527 dev_dbg(&dev->dev, "ZLP_REG%d Writing success status%d\n", i + 1, status);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002528
2529 }
Oliver Neukum0de9a702007-03-16 20:28:28 +01002530 mos7840_port->control_urb = usb_alloc_urb(0, GFP_KERNEL);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002531 mos7840_port->ctrl_buf = kmalloc(16, GFP_KERNEL);
Alan Cox880af9d2008-07-22 11:16:12 +01002532 mos7840_port->dr = kmalloc(sizeof(struct usb_ctrlrequest),
2533 GFP_KERNEL);
2534 if (!mos7840_port->control_urb || !mos7840_port->ctrl_buf ||
2535 !mos7840_port->dr) {
Oliver Neukum0de9a702007-03-16 20:28:28 +01002536 status = -ENOMEM;
2537 goto error;
2538 }
Donald0eafe4d2012-04-19 15:00:45 +08002539
2540 mos7840_port->has_led = false;
2541
2542 /* Initialize LED timers */
2543 if (device_type == MOSCHIP_DEVICE_ID_7810) {
2544 mos7840_port->has_led = true;
2545
2546 init_timer(&mos7840_port->led_timer1);
2547 mos7840_port->led_timer1.function = mos7840_led_off;
2548 mos7840_port->led_timer1.expires =
2549 jiffies + msecs_to_jiffies(LED_ON_MS);
2550 mos7840_port->led_timer1.data =
2551 (unsigned long)mos7840_port;
2552
2553 init_timer(&mos7840_port->led_timer2);
2554 mos7840_port->led_timer2.function =
2555 mos7840_led_flag_off;
2556 mos7840_port->led_timer2.expires =
2557 jiffies + msecs_to_jiffies(LED_OFF_MS);
2558 mos7840_port->led_timer2.data =
2559 (unsigned long)mos7840_port;
2560
2561 mos7840_port->led_flag = false;
2562
2563 /* Turn off LED */
2564 mos7840_set_led_sync(serial->port[i],
2565 MODEM_CONTROL_REGISTER, 0x0300);
2566 }
Paul B Schroeder3f542972006-08-31 19:41:47 -05002567 }
2568
Alan Cox880af9d2008-07-22 11:16:12 +01002569 /* Zero Length flag enable */
Paul B Schroeder3f542972006-08-31 19:41:47 -05002570 Data = 0x0f;
Paul B Schroeder3f542972006-08-31 19:41:47 -05002571 status = mos7840_set_reg_sync(serial->port[0], ZLP_REG5, Data);
2572 if (status < 0) {
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002573 dev_dbg(&dev->dev, "Writing ZLP_REG5 failed status-0x%x\n", status);
Roel Kluin7ced46c2007-10-27 03:36:37 +02002574 goto error;
Paul B Schroeder3f542972006-08-31 19:41:47 -05002575 } else
Greg Kroah-Hartman9c134a12012-09-14 16:06:04 -07002576 dev_dbg(&dev->dev, "ZLP_REG5 Writing success status%d\n", status);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002577
2578 /* setting configuration feature to one */
2579 usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
Mark Ferrell1e658482012-07-24 13:38:31 -05002580 (__u8) 0x03, 0x00, 0x01, 0x00, NULL, 0x00, MOS_WDR_TIMEOUT);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002581 return 0;
Oliver Neukum0de9a702007-03-16 20:28:28 +01002582error:
2583 for (/* nothing */; i >= 0; i--) {
2584 mos7840_port = mos7840_get_port_private(serial->port[i]);
2585
2586 kfree(mos7840_port->dr);
2587 kfree(mos7840_port->ctrl_buf);
2588 usb_free_urb(mos7840_port->control_urb);
2589 kfree(mos7840_port);
2590 serial->port[i] = NULL;
2591 }
2592 return status;
Paul B Schroeder3f542972006-08-31 19:41:47 -05002593}
2594
2595/****************************************************************************
Alan Sternf9c99bb2009-06-02 11:53:55 -04002596 * mos7840_disconnect
Paul B Schroeder3f542972006-08-31 19:41:47 -05002597 * This function is called whenever the device is removed from the usb bus.
2598 ****************************************************************************/
2599
Alan Sternf9c99bb2009-06-02 11:53:55 -04002600static void mos7840_disconnect(struct usb_serial *serial)
Paul B Schroeder3f542972006-08-31 19:41:47 -05002601{
2602 int i;
Oliver Neukum0de9a702007-03-16 20:28:28 +01002603 unsigned long flags;
Paul B Schroeder3f542972006-08-31 19:41:47 -05002604 struct moschip_port *mos7840_port;
Paul B Schroeder3f542972006-08-31 19:41:47 -05002605
Alan Cox880af9d2008-07-22 11:16:12 +01002606 /* check for the ports to be closed,close the ports and disconnect */
Paul B Schroeder3f542972006-08-31 19:41:47 -05002607
2608 /* free private structure allocated for serial port *
2609 * stop reads and writes on all ports */
2610
2611 for (i = 0; i < serial->num_ports; ++i) {
2612 mos7840_port = mos7840_get_port_private(serial->port[i]);
Tony Cook37768ad2009-04-18 22:42:18 +09302613 if (mos7840_port) {
2614 spin_lock_irqsave(&mos7840_port->pool_lock, flags);
2615 mos7840_port->zombie = 1;
2616 spin_unlock_irqrestore(&mos7840_port->pool_lock, flags);
2617 usb_kill_urb(mos7840_port->control_urb);
Alan Sternf9c99bb2009-06-02 11:53:55 -04002618 }
2619 }
Alan Sternf9c99bb2009-06-02 11:53:55 -04002620}
2621
2622/****************************************************************************
2623 * mos7840_release
2624 * This function is called when the usb_serial structure is freed.
2625 ****************************************************************************/
2626
2627static void mos7840_release(struct usb_serial *serial)
2628{
2629 int i;
2630 struct moschip_port *mos7840_port;
Alan Sternf9c99bb2009-06-02 11:53:55 -04002631
Alan Sternf9c99bb2009-06-02 11:53:55 -04002632 /* check for the ports to be closed,close the ports and disconnect */
2633
2634 /* free private structure allocated for serial port *
2635 * stop reads and writes on all ports */
2636
2637 for (i = 0; i < serial->num_ports; ++i) {
2638 mos7840_port = mos7840_get_port_private(serial->port[i]);
Alan Sternf9c99bb2009-06-02 11:53:55 -04002639 if (mos7840_port) {
Donald0eafe4d2012-04-19 15:00:45 +08002640 if (mos7840_port->has_led) {
2641 /* Turn off LED */
2642 mos7840_set_led_sync(mos7840_port->port,
2643 MODEM_CONTROL_REGISTER, 0x0300);
2644
2645 del_timer_sync(&mos7840_port->led_timer1);
2646 del_timer_sync(&mos7840_port->led_timer2);
2647 }
Johan Hovold65a4cdb2012-10-25 13:35:09 +02002648 usb_free_urb(mos7840_port->control_urb);
Tony Cook37768ad2009-04-18 22:42:18 +09302649 kfree(mos7840_port->ctrl_buf);
2650 kfree(mos7840_port->dr);
2651 kfree(mos7840_port);
2652 }
Paul B Schroeder3f542972006-08-31 19:41:47 -05002653 }
Paul B Schroeder3f542972006-08-31 19:41:47 -05002654}
2655
2656static struct usb_serial_driver moschip7840_4port_device = {
2657 .driver = {
2658 .owner = THIS_MODULE,
2659 .name = "mos7840",
2660 },
2661 .description = DRIVER_DESC,
Greg Kroah-Hartman68e24112012-05-08 15:46:14 -07002662 .id_table = id_table,
Paul B Schroeder3f542972006-08-31 19:41:47 -05002663 .num_ports = 4,
Paul B Schroeder3f542972006-08-31 19:41:47 -05002664 .open = mos7840_open,
2665 .close = mos7840_close,
2666 .write = mos7840_write,
2667 .write_room = mos7840_write_room,
2668 .chars_in_buffer = mos7840_chars_in_buffer,
2669 .throttle = mos7840_throttle,
2670 .unthrottle = mos7840_unthrottle,
2671 .calc_num_ports = mos7840_calc_num_ports,
2672#ifdef MCSSerialProbe
2673 .probe = mos7840_serial_probe,
2674#endif
2675 .ioctl = mos7840_ioctl,
2676 .set_termios = mos7840_set_termios,
2677 .break_ctl = mos7840_break,
2678 .tiocmget = mos7840_tiocmget,
2679 .tiocmset = mos7840_tiocmset,
Alan Cox0bca1b92010-09-16 18:21:40 +01002680 .get_icount = mos7840_get_icount,
Paul B Schroeder3f542972006-08-31 19:41:47 -05002681 .attach = mos7840_startup,
Alan Sternf9c99bb2009-06-02 11:53:55 -04002682 .disconnect = mos7840_disconnect,
2683 .release = mos7840_release,
Paul B Schroeder3f542972006-08-31 19:41:47 -05002684 .read_bulk_callback = mos7840_bulk_in_callback,
2685 .read_int_callback = mos7840_interrupt_callback,
2686};
2687
Alan Stern4d2a7af2012-02-23 14:57:09 -05002688static struct usb_serial_driver * const serial_drivers[] = {
2689 &moschip7840_4port_device, NULL
2690};
2691
Greg Kroah-Hartman68e24112012-05-08 15:46:14 -07002692module_usb_serial_driver(serial_drivers, id_table);
Paul B Schroeder3f542972006-08-31 19:41:47 -05002693
Paul B Schroeder3f542972006-08-31 19:41:47 -05002694MODULE_DESCRIPTION(DRIVER_DESC);
2695MODULE_LICENSE("GPL");