USB: mos7720: remove unused code
[linux-2.6-block.git] / drivers / usb / serial / digi_acceleport.c
CommitLineData
1da177e4
LT
1/*
2* Digi AccelePort USB-4 and USB-2 Serial Converters
3*
4* Copyright 2000 by Digi International
5*
6* This program is free software; you can redistribute it and/or modify
7* it under the terms of the GNU General Public License as published by
8* the Free Software Foundation; either version 2 of the License, or
9* (at your option) any later version.
10*
11* Shamelessly based on Brian Warner's keyspan_pda.c and Greg Kroah-Hartman's
12* usb-serial driver.
13*
14* Peter Berger (pberger@brimson.com)
15* Al Borchers (borchers@steinerpoint.com)
1da177e4
LT
16*/
17
1da177e4
LT
18#include <linux/kernel.h>
19#include <linux/errno.h>
20#include <linux/init.h>
21#include <linux/slab.h>
22#include <linux/tty.h>
23#include <linux/tty_driver.h>
24#include <linux/tty_flip.h>
25#include <linux/module.h>
26#include <linux/spinlock.h>
27#include <linux/workqueue.h>
41ad427d 28#include <linux/uaccess.h>
1da177e4
LT
29#include <linux/usb.h>
30#include <linux/wait.h>
a969888c 31#include <linux/usb/serial.h>
1da177e4
LT
32
33/* Defines */
34
35/*
36 * Version Information
37 */
38#define DRIVER_VERSION "v1.80.1.2"
39#define DRIVER_AUTHOR "Peter Berger <pberger@brimson.com>, Al Borchers <borchers@steinerpoint.com>"
40#define DRIVER_DESC "Digi AccelePort USB-2/USB-4 Serial Converter driver"
41
42/* port output buffer length -- must be <= transfer buffer length - 2 */
43/* so we can be sure to send the full buffer in one urb */
44#define DIGI_OUT_BUF_SIZE 8
45
46/* port input buffer length -- must be >= transfer buffer length - 3 */
47/* so we can be sure to hold at least one full buffer from one urb */
48#define DIGI_IN_BUF_SIZE 64
49
50/* retry timeout while sleeping */
51#define DIGI_RETRY_TIMEOUT (HZ/10)
52
53/* timeout while waiting for tty output to drain in close */
54/* this delay is used twice in close, so the total delay could */
55/* be twice this value */
56#define DIGI_CLOSE_TIMEOUT (5*HZ)
57
58
59/* AccelePort USB Defines */
60
61/* ids */
62#define DIGI_VENDOR_ID 0x05c5
63#define DIGI_2_ID 0x0002 /* USB-2 */
64#define DIGI_4_ID 0x0004 /* USB-4 */
65
66/* commands
67 * "INB": can be used on the in-band endpoint
68 * "OOB": can be used on the out-of-band endpoint
69 */
70#define DIGI_CMD_SET_BAUD_RATE 0 /* INB, OOB */
71#define DIGI_CMD_SET_WORD_SIZE 1 /* INB, OOB */
72#define DIGI_CMD_SET_PARITY 2 /* INB, OOB */
73#define DIGI_CMD_SET_STOP_BITS 3 /* INB, OOB */
74#define DIGI_CMD_SET_INPUT_FLOW_CONTROL 4 /* INB, OOB */
75#define DIGI_CMD_SET_OUTPUT_FLOW_CONTROL 5 /* INB, OOB */
76#define DIGI_CMD_SET_DTR_SIGNAL 6 /* INB, OOB */
77#define DIGI_CMD_SET_RTS_SIGNAL 7 /* INB, OOB */
78#define DIGI_CMD_READ_INPUT_SIGNALS 8 /* OOB */
79#define DIGI_CMD_IFLUSH_FIFO 9 /* OOB */
80#define DIGI_CMD_RECEIVE_ENABLE 10 /* INB, OOB */
81#define DIGI_CMD_BREAK_CONTROL 11 /* INB, OOB */
82#define DIGI_CMD_LOCAL_LOOPBACK 12 /* INB, OOB */
83#define DIGI_CMD_TRANSMIT_IDLE 13 /* INB, OOB */
84#define DIGI_CMD_READ_UART_REGISTER 14 /* OOB */
85#define DIGI_CMD_WRITE_UART_REGISTER 15 /* INB, OOB */
86#define DIGI_CMD_AND_UART_REGISTER 16 /* INB, OOB */
87#define DIGI_CMD_OR_UART_REGISTER 17 /* INB, OOB */
88#define DIGI_CMD_SEND_DATA 18 /* INB */
89#define DIGI_CMD_RECEIVE_DATA 19 /* INB */
90#define DIGI_CMD_RECEIVE_DISABLE 20 /* INB */
91#define DIGI_CMD_GET_PORT_TYPE 21 /* OOB */
92
93/* baud rates */
94#define DIGI_BAUD_50 0
95#define DIGI_BAUD_75 1
96#define DIGI_BAUD_110 2
97#define DIGI_BAUD_150 3
98#define DIGI_BAUD_200 4
99#define DIGI_BAUD_300 5
100#define DIGI_BAUD_600 6
101#define DIGI_BAUD_1200 7
102#define DIGI_BAUD_1800 8
103#define DIGI_BAUD_2400 9
104#define DIGI_BAUD_4800 10
105#define DIGI_BAUD_7200 11
106#define DIGI_BAUD_9600 12
107#define DIGI_BAUD_14400 13
108#define DIGI_BAUD_19200 14
109#define DIGI_BAUD_28800 15
110#define DIGI_BAUD_38400 16
111#define DIGI_BAUD_57600 17
112#define DIGI_BAUD_76800 18
113#define DIGI_BAUD_115200 19
114#define DIGI_BAUD_153600 20
115#define DIGI_BAUD_230400 21
116#define DIGI_BAUD_460800 22
117
118/* arguments */
119#define DIGI_WORD_SIZE_5 0
120#define DIGI_WORD_SIZE_6 1
121#define DIGI_WORD_SIZE_7 2
122#define DIGI_WORD_SIZE_8 3
123
124#define DIGI_PARITY_NONE 0
125#define DIGI_PARITY_ODD 1
126#define DIGI_PARITY_EVEN 2
127#define DIGI_PARITY_MARK 3
128#define DIGI_PARITY_SPACE 4
129
130#define DIGI_STOP_BITS_1 0
131#define DIGI_STOP_BITS_2 1
132
133#define DIGI_INPUT_FLOW_CONTROL_XON_XOFF 1
134#define DIGI_INPUT_FLOW_CONTROL_RTS 2
135#define DIGI_INPUT_FLOW_CONTROL_DTR 4
136
137#define DIGI_OUTPUT_FLOW_CONTROL_XON_XOFF 1
138#define DIGI_OUTPUT_FLOW_CONTROL_CTS 2
139#define DIGI_OUTPUT_FLOW_CONTROL_DSR 4
140
141#define DIGI_DTR_INACTIVE 0
142#define DIGI_DTR_ACTIVE 1
143#define DIGI_DTR_INPUT_FLOW_CONTROL 2
144
145#define DIGI_RTS_INACTIVE 0
146#define DIGI_RTS_ACTIVE 1
147#define DIGI_RTS_INPUT_FLOW_CONTROL 2
148#define DIGI_RTS_TOGGLE 3
149
150#define DIGI_FLUSH_TX 1
151#define DIGI_FLUSH_RX 2
152#define DIGI_RESUME_TX 4 /* clears xoff condition */
153
154#define DIGI_TRANSMIT_NOT_IDLE 0
155#define DIGI_TRANSMIT_IDLE 1
156
157#define DIGI_DISABLE 0
158#define DIGI_ENABLE 1
159
160#define DIGI_DEASSERT 0
161#define DIGI_ASSERT 1
162
163/* in band status codes */
164#define DIGI_OVERRUN_ERROR 4
165#define DIGI_PARITY_ERROR 8
166#define DIGI_FRAMING_ERROR 16
167#define DIGI_BREAK_ERROR 32
168
169/* out of band status */
170#define DIGI_NO_ERROR 0
171#define DIGI_BAD_FIRST_PARAMETER 1
172#define DIGI_BAD_SECOND_PARAMETER 2
173#define DIGI_INVALID_LINE 3
174#define DIGI_INVALID_OPCODE 4
175
176/* input signals */
177#define DIGI_READ_INPUT_SIGNALS_SLOT 1
178#define DIGI_READ_INPUT_SIGNALS_ERR 2
179#define DIGI_READ_INPUT_SIGNALS_BUSY 4
180#define DIGI_READ_INPUT_SIGNALS_PE 8
181#define DIGI_READ_INPUT_SIGNALS_CTS 16
182#define DIGI_READ_INPUT_SIGNALS_DSR 32
183#define DIGI_READ_INPUT_SIGNALS_RI 64
184#define DIGI_READ_INPUT_SIGNALS_DCD 128
185
186
187/* Structures */
188
189struct digi_serial {
190 spinlock_t ds_serial_lock;
191 struct usb_serial_port *ds_oob_port; /* out-of-band port */
192 int ds_oob_port_num; /* index of out-of-band port */
193 int ds_device_started;
194};
195
196struct digi_port {
197 spinlock_t dp_port_lock;
198 int dp_port_num;
199 int dp_out_buf_len;
200 unsigned char dp_out_buf[DIGI_OUT_BUF_SIZE];
1da177e4
LT
201 int dp_write_urb_in_use;
202 unsigned int dp_modem_signals;
203 wait_queue_head_t dp_modem_change_wait;
204 int dp_transmit_idle;
205 wait_queue_head_t dp_transmit_idle_wait;
206 int dp_throttled;
207 int dp_throttle_restart;
208 wait_queue_head_t dp_flush_wait;
1da177e4
LT
209 wait_queue_head_t dp_close_wait; /* wait queue for close */
210 struct work_struct dp_wakeup_work;
c4028958 211 struct usb_serial_port *dp_port;
1da177e4
LT
212};
213
214
215/* Local Function Declarations */
216
c6d61269 217static void digi_wakeup_write(struct usb_serial_port *port);
c4028958 218static void digi_wakeup_write_lock(struct work_struct *work);
c6d61269
AC
219static int digi_write_oob_command(struct usb_serial_port *port,
220 unsigned char *buf, int count, int interruptible);
221static int digi_write_inb_command(struct usb_serial_port *port,
222 unsigned char *buf, int count, unsigned long timeout);
223static int digi_set_modem_signals(struct usb_serial_port *port,
224 unsigned int modem_signals, int interruptible);
225static int digi_transmit_idle(struct usb_serial_port *port,
226 unsigned long timeout);
41ad427d
AC
227static void digi_rx_throttle(struct tty_struct *tty);
228static void digi_rx_unthrottle(struct tty_struct *tty);
95da310e
AC
229static void digi_set_termios(struct tty_struct *tty,
230 struct usb_serial_port *port, struct ktermios *old_termios);
231static void digi_break_ctl(struct tty_struct *tty, int break_state);
60b33c13 232static int digi_tiocmget(struct tty_struct *tty);
20b9d177
AC
233static int digi_tiocmset(struct tty_struct *tty, unsigned int set,
234 unsigned int clear);
95da310e 235static int digi_write(struct tty_struct *tty, struct usb_serial_port *port,
20b9d177 236 const unsigned char *buf, int count);
c6d61269 237static void digi_write_bulk_callback(struct urb *urb);
95da310e
AC
238static int digi_write_room(struct tty_struct *tty);
239static int digi_chars_in_buffer(struct tty_struct *tty);
a509a7e4 240static int digi_open(struct tty_struct *tty, struct usb_serial_port *port);
335f8514 241static void digi_close(struct usb_serial_port *port);
335f8514 242static void digi_dtr_rts(struct usb_serial_port *port, int on);
c6d61269
AC
243static int digi_startup_device(struct usb_serial *serial);
244static int digi_startup(struct usb_serial *serial);
f9c99bb8
AS
245static void digi_disconnect(struct usb_serial *serial);
246static void digi_release(struct usb_serial *serial);
c6d61269
AC
247static void digi_read_bulk_callback(struct urb *urb);
248static int digi_read_inb_callback(struct urb *urb);
249static int digi_read_oob_callback(struct urb *urb);
1da177e4
LT
250
251
252/* Statics */
253
254static int debug;
255
7d40d7e8 256static const struct usb_device_id id_table_combined[] = {
1da177e4
LT
257 { USB_DEVICE(DIGI_VENDOR_ID, DIGI_2_ID) },
258 { USB_DEVICE(DIGI_VENDOR_ID, DIGI_4_ID) },
259 { } /* Terminating entry */
260};
261
7d40d7e8 262static const struct usb_device_id id_table_2[] = {
1da177e4
LT
263 { USB_DEVICE(DIGI_VENDOR_ID, DIGI_2_ID) },
264 { } /* Terminating entry */
265};
266
7d40d7e8 267static const struct usb_device_id id_table_4[] = {
1da177e4
LT
268 { USB_DEVICE(DIGI_VENDOR_ID, DIGI_4_ID) },
269 { } /* Terminating entry */
270};
271
41ad427d 272MODULE_DEVICE_TABLE(usb, id_table_combined);
1da177e4
LT
273
274static struct usb_driver digi_driver = {
1da177e4
LT
275 .name = "digi_acceleport",
276 .probe = usb_serial_probe,
277 .disconnect = usb_serial_disconnect,
278 .id_table = id_table_combined,
ba9dc657 279 .no_dynamic_id = 1,
1da177e4
LT
280};
281
282
283/* device info needed for the Digi serial converter */
284
ea65370d 285static struct usb_serial_driver digi_acceleport_2_device = {
18fcac35 286 .driver = {
269bda1c
GKH
287 .owner = THIS_MODULE,
288 .name = "digi_2",
18fcac35 289 },
269bda1c 290 .description = "Digi 2 port USB adapter",
d9b1b787 291 .usb_driver = &digi_driver,
1da177e4 292 .id_table = id_table_2,
1da177e4
LT
293 .num_ports = 3,
294 .open = digi_open,
295 .close = digi_close,
335f8514 296 .dtr_rts = digi_dtr_rts,
1da177e4
LT
297 .write = digi_write,
298 .write_room = digi_write_room,
299 .write_bulk_callback = digi_write_bulk_callback,
300 .read_bulk_callback = digi_read_bulk_callback,
301 .chars_in_buffer = digi_chars_in_buffer,
302 .throttle = digi_rx_throttle,
303 .unthrottle = digi_rx_unthrottle,
1da177e4
LT
304 .set_termios = digi_set_termios,
305 .break_ctl = digi_break_ctl,
306 .tiocmget = digi_tiocmget,
307 .tiocmset = digi_tiocmset,
308 .attach = digi_startup,
f9c99bb8
AS
309 .disconnect = digi_disconnect,
310 .release = digi_release,
1da177e4
LT
311};
312
ea65370d 313static struct usb_serial_driver digi_acceleport_4_device = {
18fcac35 314 .driver = {
269bda1c
GKH
315 .owner = THIS_MODULE,
316 .name = "digi_4",
18fcac35 317 },
269bda1c 318 .description = "Digi 4 port USB adapter",
d9b1b787 319 .usb_driver = &digi_driver,
1da177e4 320 .id_table = id_table_4,
1da177e4
LT
321 .num_ports = 4,
322 .open = digi_open,
323 .close = digi_close,
324 .write = digi_write,
325 .write_room = digi_write_room,
326 .write_bulk_callback = digi_write_bulk_callback,
327 .read_bulk_callback = digi_read_bulk_callback,
328 .chars_in_buffer = digi_chars_in_buffer,
329 .throttle = digi_rx_throttle,
330 .unthrottle = digi_rx_unthrottle,
1da177e4
LT
331 .set_termios = digi_set_termios,
332 .break_ctl = digi_break_ctl,
333 .tiocmget = digi_tiocmget,
334 .tiocmset = digi_tiocmset,
335 .attach = digi_startup,
f9c99bb8
AS
336 .disconnect = digi_disconnect,
337 .release = digi_release,
1da177e4
LT
338};
339
340
341/* Functions */
342
343/*
41ad427d
AC
344 * Cond Wait Interruptible Timeout Irqrestore
345 *
346 * Do spin_unlock_irqrestore and interruptible_sleep_on_timeout
347 * so that wake ups are not lost if they occur between the unlock
348 * and the sleep. In other words, spin_unlock_irqrestore and
349 * interruptible_sleep_on_timeout are "atomic" with respect to
350 * wake ups. This is used to implement condition variables.
351 *
352 * interruptible_sleep_on_timeout is deprecated and has been replaced
353 * with the equivalent code.
354 */
1da177e4 355
c6d61269 356static long cond_wait_interruptible_timeout_irqrestore(
1da177e4 357 wait_queue_head_t *q, long timeout,
c6d61269 358 spinlock_t *lock, unsigned long flags)
5a33956a 359__releases(lock)
1da177e4
LT
360{
361 DEFINE_WAIT(wait);
362
45f23f18 363 prepare_to_wait(q, &wait, TASK_INTERRUPTIBLE);
1da177e4
LT
364 spin_unlock_irqrestore(lock, flags);
365 timeout = schedule_timeout(timeout);
366 finish_wait(q, &wait);
367
368 return timeout;
1da177e4
LT
369}
370
371
372/*
41ad427d
AC
373 * Digi Wakeup Write
374 *
375 * Wake up port, line discipline, and tty processes sleeping
376 * on writes.
377 */
1da177e4 378
c4028958 379static void digi_wakeup_write_lock(struct work_struct *work)
1da177e4 380{
41ad427d
AC
381 struct digi_port *priv =
382 container_of(work, struct digi_port, dp_wakeup_work);
c4028958 383 struct usb_serial_port *port = priv->dp_port;
1da177e4 384 unsigned long flags;
1da177e4 385
c6d61269
AC
386 spin_lock_irqsave(&priv->dp_port_lock, flags);
387 digi_wakeup_write(port);
388 spin_unlock_irqrestore(&priv->dp_port_lock, flags);
1da177e4
LT
389}
390
c6d61269 391static void digi_wakeup_write(struct usb_serial_port *port)
1da177e4 392{
4a90f09b 393 struct tty_struct *tty = tty_port_tty_get(&port->port);
4287341d
AC
394 if (tty) {
395 tty_wakeup(tty);
396 tty_kref_put(tty);
397 }
1da177e4
LT
398}
399
400
401/*
41ad427d
AC
402 * Digi Write OOB Command
403 *
404 * Write commands on the out of band port. Commands are 4
405 * bytes each, multiple commands can be sent at once, and
406 * no command will be split across USB packets. Returns 0
407 * if successful, -EINTR if interrupted while sleeping and
408 * the interruptible flag is true, or a negative error
409 * returned by usb_submit_urb.
410 */
1da177e4 411
c6d61269
AC
412static int digi_write_oob_command(struct usb_serial_port *port,
413 unsigned char *buf, int count, int interruptible)
1da177e4
LT
414{
415
416 int ret = 0;
417 int len;
418 struct usb_serial_port *oob_port = (struct usb_serial_port *)((struct digi_serial *)(usb_get_serial_data(port->serial)))->ds_oob_port;
419 struct digi_port *oob_priv = usb_get_serial_port_data(oob_port);
420 unsigned long flags = 0;
421
c6d61269 422 dbg("digi_write_oob_command: TOP: port=%d, count=%d", oob_priv->dp_port_num, count);
1da177e4 423
c6d61269 424 spin_lock_irqsave(&oob_priv->dp_port_lock, flags);
41ad427d 425 while (count > 0) {
50de36f7 426 while (oob_priv->dp_write_urb_in_use) {
1da177e4
LT
427 cond_wait_interruptible_timeout_irqrestore(
428 &oob_port->write_wait, DIGI_RETRY_TIMEOUT,
c6d61269
AC
429 &oob_priv->dp_port_lock, flags);
430 if (interruptible && signal_pending(current))
431 return -EINTR;
432 spin_lock_irqsave(&oob_priv->dp_port_lock, flags);
1da177e4
LT
433 }
434
435 /* len must be a multiple of 4, so commands are not split */
c6d61269
AC
436 len = min(count, oob_port->bulk_out_size);
437 if (len > 4)
1da177e4 438 len &= ~3;
c6d61269 439 memcpy(oob_port->write_urb->transfer_buffer, buf, len);
1da177e4
LT
440 oob_port->write_urb->transfer_buffer_length = len;
441 oob_port->write_urb->dev = port->serial->dev;
41ad427d
AC
442 ret = usb_submit_urb(oob_port->write_urb, GFP_ATOMIC);
443 if (ret == 0) {
1da177e4
LT
444 oob_priv->dp_write_urb_in_use = 1;
445 count -= len;
446 buf += len;
447 }
1da177e4 448 }
c6d61269
AC
449 spin_unlock_irqrestore(&oob_priv->dp_port_lock, flags);
450 if (ret)
194343d9
GKH
451 dev_err(&port->dev, "%s: usb_submit_urb failed, ret=%d\n",
452 __func__, ret);
c6d61269 453 return ret;
1da177e4
LT
454
455}
456
457
458/*
41ad427d
AC
459 * Digi Write In Band Command
460 *
461 * Write commands on the given port. Commands are 4
462 * bytes each, multiple commands can be sent at once, and
463 * no command will be split across USB packets. If timeout
464 * is non-zero, write in band command will return after
465 * waiting unsuccessfully for the URB status to clear for
466 * timeout ticks. Returns 0 if successful, or a negative
467 * error returned by digi_write.
468 */
1da177e4 469
c6d61269
AC
470static int digi_write_inb_command(struct usb_serial_port *port,
471 unsigned char *buf, int count, unsigned long timeout)
1da177e4 472{
1da177e4
LT
473 int ret = 0;
474 int len;
475 struct digi_port *priv = usb_get_serial_port_data(port);
476 unsigned char *data = port->write_urb->transfer_buffer;
477 unsigned long flags = 0;
478
c6d61269
AC
479 dbg("digi_write_inb_command: TOP: port=%d, count=%d",
480 priv->dp_port_num, count);
1da177e4 481
c6d61269 482 if (timeout)
1da177e4
LT
483 timeout += jiffies;
484 else
485 timeout = ULONG_MAX;
486
c6d61269 487 spin_lock_irqsave(&priv->dp_port_lock, flags);
41ad427d 488 while (count > 0 && ret == 0) {
50de36f7
GKH
489 while (priv->dp_write_urb_in_use &&
490 time_before(jiffies, timeout)) {
1da177e4
LT
491 cond_wait_interruptible_timeout_irqrestore(
492 &port->write_wait, DIGI_RETRY_TIMEOUT,
c6d61269
AC
493 &priv->dp_port_lock, flags);
494 if (signal_pending(current))
495 return -EINTR;
496 spin_lock_irqsave(&priv->dp_port_lock, flags);
1da177e4
LT
497 }
498
499 /* len must be a multiple of 4 and small enough to */
500 /* guarantee the write will send buffered data first, */
501 /* so commands are in order with data and not split */
c6d61269
AC
502 len = min(count, port->bulk_out_size-2-priv->dp_out_buf_len);
503 if (len > 4)
1da177e4
LT
504 len &= ~3;
505
506 /* write any buffered data first */
c6d61269 507 if (priv->dp_out_buf_len > 0) {
1da177e4
LT
508 data[0] = DIGI_CMD_SEND_DATA;
509 data[1] = priv->dp_out_buf_len;
c6d61269
AC
510 memcpy(data + 2, priv->dp_out_buf,
511 priv->dp_out_buf_len);
512 memcpy(data + 2 + priv->dp_out_buf_len, buf, len);
1da177e4 513 port->write_urb->transfer_buffer_length
c6d61269 514 = priv->dp_out_buf_len + 2 + len;
1da177e4 515 } else {
c6d61269 516 memcpy(data, buf, len);
1da177e4
LT
517 port->write_urb->transfer_buffer_length = len;
518 }
519 port->write_urb->dev = port->serial->dev;
520
41ad427d
AC
521 ret = usb_submit_urb(port->write_urb, GFP_ATOMIC);
522 if (ret == 0) {
1da177e4
LT
523 priv->dp_write_urb_in_use = 1;
524 priv->dp_out_buf_len = 0;
525 count -= len;
526 buf += len;
527 }
528
529 }
c6d61269 530 spin_unlock_irqrestore(&priv->dp_port_lock, flags);
1da177e4 531
c6d61269 532 if (ret)
194343d9
GKH
533 dev_err(&port->dev,
534 "%s: usb_submit_urb failed, ret=%d, port=%d\n",
441b62c1 535 __func__, ret, priv->dp_port_num);
c6d61269 536 return ret;
1da177e4
LT
537}
538
539
540/*
41ad427d
AC
541 * Digi Set Modem Signals
542 *
543 * Sets or clears DTR and RTS on the port, according to the
544 * modem_signals argument. Use TIOCM_DTR and TIOCM_RTS flags
545 * for the modem_signals argument. Returns 0 if successful,
546 * -EINTR if interrupted while sleeping, or a non-zero error
547 * returned by usb_submit_urb.
548 */
1da177e4 549
c6d61269
AC
550static int digi_set_modem_signals(struct usb_serial_port *port,
551 unsigned int modem_signals, int interruptible)
1da177e4
LT
552{
553
554 int ret;
555 struct digi_port *port_priv = usb_get_serial_port_data(port);
41ad427d 556 struct usb_serial_port *oob_port = (struct usb_serial_port *) ((struct digi_serial *)(usb_get_serial_data(port->serial)))->ds_oob_port;
1da177e4
LT
557 struct digi_port *oob_priv = usb_get_serial_port_data(oob_port);
558 unsigned char *data = oob_port->write_urb->transfer_buffer;
559 unsigned long flags = 0;
560
561
c6d61269
AC
562 dbg("digi_set_modem_signals: TOP: port=%d, modem_signals=0x%x",
563 port_priv->dp_port_num, modem_signals);
1da177e4 564
c6d61269
AC
565 spin_lock_irqsave(&oob_priv->dp_port_lock, flags);
566 spin_lock(&port_priv->dp_port_lock);
1da177e4 567
50de36f7 568 while (oob_priv->dp_write_urb_in_use) {
c6d61269 569 spin_unlock(&port_priv->dp_port_lock);
1da177e4
LT
570 cond_wait_interruptible_timeout_irqrestore(
571 &oob_port->write_wait, DIGI_RETRY_TIMEOUT,
c6d61269
AC
572 &oob_priv->dp_port_lock, flags);
573 if (interruptible && signal_pending(current))
574 return -EINTR;
575 spin_lock_irqsave(&oob_priv->dp_port_lock, flags);
576 spin_lock(&port_priv->dp_port_lock);
1da177e4 577 }
1da177e4
LT
578 data[0] = DIGI_CMD_SET_DTR_SIGNAL;
579 data[1] = port_priv->dp_port_num;
41ad427d
AC
580 data[2] = (modem_signals & TIOCM_DTR) ?
581 DIGI_DTR_ACTIVE : DIGI_DTR_INACTIVE;
1da177e4 582 data[3] = 0;
1da177e4
LT
583 data[4] = DIGI_CMD_SET_RTS_SIGNAL;
584 data[5] = port_priv->dp_port_num;
41ad427d
AC
585 data[6] = (modem_signals & TIOCM_RTS) ?
586 DIGI_RTS_ACTIVE : DIGI_RTS_INACTIVE;
1da177e4
LT
587 data[7] = 0;
588
589 oob_port->write_urb->transfer_buffer_length = 8;
590 oob_port->write_urb->dev = port->serial->dev;
591
41ad427d
AC
592 ret = usb_submit_urb(oob_port->write_urb, GFP_ATOMIC);
593 if (ret == 0) {
1da177e4
LT
594 oob_priv->dp_write_urb_in_use = 1;
595 port_priv->dp_modem_signals =
596 (port_priv->dp_modem_signals&~(TIOCM_DTR|TIOCM_RTS))
597 | (modem_signals&(TIOCM_DTR|TIOCM_RTS));
598 }
c6d61269
AC
599 spin_unlock(&port_priv->dp_port_lock);
600 spin_unlock_irqrestore(&oob_priv->dp_port_lock, flags);
601 if (ret)
194343d9
GKH
602 dev_err(&port->dev, "%s: usb_submit_urb failed, ret=%d\n",
603 __func__, ret);
c6d61269 604 return ret;
1da177e4
LT
605}
606
1da177e4 607/*
41ad427d
AC
608 * Digi Transmit Idle
609 *
610 * Digi transmit idle waits, up to timeout ticks, for the transmitter
611 * to go idle. It returns 0 if successful or a negative error.
612 *
613 * There are race conditions here if more than one process is calling
614 * digi_transmit_idle on the same port at the same time. However, this
615 * is only called from close, and only one process can be in close on a
616 * port at a time, so its ok.
617 */
1da177e4 618
c6d61269
AC
619static int digi_transmit_idle(struct usb_serial_port *port,
620 unsigned long timeout)
1da177e4 621{
1da177e4
LT
622 int ret;
623 unsigned char buf[2];
624 struct digi_port *priv = usb_get_serial_port_data(port);
625 unsigned long flags = 0;
626
c6d61269 627 spin_lock_irqsave(&priv->dp_port_lock, flags);
1da177e4 628 priv->dp_transmit_idle = 0;
c6d61269 629 spin_unlock_irqrestore(&priv->dp_port_lock, flags);
1da177e4
LT
630
631 buf[0] = DIGI_CMD_TRANSMIT_IDLE;
632 buf[1] = 0;
633
634 timeout += jiffies;
635
41ad427d
AC
636 ret = digi_write_inb_command(port, buf, 2, timeout - jiffies);
637 if (ret != 0)
c6d61269 638 return ret;
1da177e4 639
c6d61269 640 spin_lock_irqsave(&priv->dp_port_lock, flags);
1da177e4 641
41ad427d 642 while (time_before(jiffies, timeout) && !priv->dp_transmit_idle) {
1da177e4
LT
643 cond_wait_interruptible_timeout_irqrestore(
644 &priv->dp_transmit_idle_wait, DIGI_RETRY_TIMEOUT,
c6d61269
AC
645 &priv->dp_port_lock, flags);
646 if (signal_pending(current))
647 return -EINTR;
648 spin_lock_irqsave(&priv->dp_port_lock, flags);
1da177e4 649 }
1da177e4 650 priv->dp_transmit_idle = 0;
c6d61269
AC
651 spin_unlock_irqrestore(&priv->dp_port_lock, flags);
652 return 0;
1da177e4
LT
653
654}
655
656
95da310e 657static void digi_rx_throttle(struct tty_struct *tty)
1da177e4 658{
1da177e4 659 unsigned long flags;
95da310e 660 struct usb_serial_port *port = tty->driver_data;
1da177e4
LT
661 struct digi_port *priv = usb_get_serial_port_data(port);
662
663
c6d61269 664 dbg("digi_rx_throttle: TOP: port=%d", priv->dp_port_num);
1da177e4
LT
665
666 /* stop receiving characters by not resubmitting the read urb */
c6d61269 667 spin_lock_irqsave(&priv->dp_port_lock, flags);
1da177e4
LT
668 priv->dp_throttled = 1;
669 priv->dp_throttle_restart = 0;
c6d61269 670 spin_unlock_irqrestore(&priv->dp_port_lock, flags);
1da177e4
LT
671}
672
673
95da310e 674static void digi_rx_unthrottle(struct tty_struct *tty)
1da177e4 675{
1da177e4 676 int ret = 0;
1da177e4 677 unsigned long flags;
95da310e 678 struct usb_serial_port *port = tty->driver_data;
1da177e4 679 struct digi_port *priv = usb_get_serial_port_data(port);
1da177e4 680
c6d61269 681 dbg("digi_rx_unthrottle: TOP: port=%d", priv->dp_port_num);
1da177e4 682
c6d61269 683 spin_lock_irqsave(&priv->dp_port_lock, flags);
1da177e4 684
1da177e4 685 /* restart read chain */
c6d61269 686 if (priv->dp_throttle_restart) {
1da177e4 687 port->read_urb->dev = port->serial->dev;
c6d61269 688 ret = usb_submit_urb(port->read_urb, GFP_ATOMIC);
1da177e4
LT
689 }
690
ba6b702f
JH
691 /* turn throttle off */
692 priv->dp_throttled = 0;
693 priv->dp_throttle_restart = 0;
694
c6d61269 695 spin_unlock_irqrestore(&priv->dp_port_lock, flags);
1da177e4 696
c6d61269 697 if (ret)
194343d9
GKH
698 dev_err(&port->dev,
699 "%s: usb_submit_urb failed, ret=%d, port=%d\n",
441b62c1 700 __func__, ret, priv->dp_port_num);
1da177e4
LT
701}
702
703
41ad427d 704static void digi_set_termios(struct tty_struct *tty,
95da310e 705 struct usb_serial_port *port, struct ktermios *old_termios)
1da177e4 706{
1da177e4 707 struct digi_port *priv = usb_get_serial_port_data(port);
c6d61269
AC
708 unsigned int iflag = tty->termios->c_iflag;
709 unsigned int cflag = tty->termios->c_cflag;
1da177e4
LT
710 unsigned int old_iflag = old_termios->c_iflag;
711 unsigned int old_cflag = old_termios->c_cflag;
712 unsigned char buf[32];
713 unsigned int modem_signals;
41ad427d 714 int arg, ret;
1da177e4 715 int i = 0;
c6d61269 716 speed_t baud;
1da177e4 717
c6d61269 718 dbg("digi_set_termios: TOP: port=%d, iflag=0x%x, old_iflag=0x%x, cflag=0x%x, old_cflag=0x%x", priv->dp_port_num, iflag, old_iflag, cflag, old_cflag);
1da177e4
LT
719
720 /* set baud rate */
41ad427d
AC
721 baud = tty_get_baud_rate(tty);
722 if (baud != tty_termios_baud_rate(old_termios)) {
1da177e4
LT
723 arg = -1;
724
725 /* reassert DTR and (maybe) RTS on transition from B0 */
c6d61269 726 if ((old_cflag&CBAUD) == B0) {
1da177e4
LT
727 /* don't set RTS if using hardware flow control */
728 /* and throttling input */
729 modem_signals = TIOCM_DTR;
c6d61269
AC
730 if (!(tty->termios->c_cflag & CRTSCTS) ||
731 !test_bit(TTY_THROTTLED, &tty->flags))
1da177e4 732 modem_signals |= TIOCM_RTS;
c6d61269 733 digi_set_modem_signals(port, modem_signals, 1);
1da177e4 734 }
c6d61269 735 switch (baud) {
41ad427d
AC
736 /* drop DTR and RTS on transition to B0 */
737 case 0: digi_set_modem_signals(port, 0, 1); break;
738 case 50: arg = DIGI_BAUD_50; break;
739 case 75: arg = DIGI_BAUD_75; break;
740 case 110: arg = DIGI_BAUD_110; break;
741 case 150: arg = DIGI_BAUD_150; break;
742 case 200: arg = DIGI_BAUD_200; break;
743 case 300: arg = DIGI_BAUD_300; break;
744 case 600: arg = DIGI_BAUD_600; break;
745 case 1200: arg = DIGI_BAUD_1200; break;
746 case 1800: arg = DIGI_BAUD_1800; break;
747 case 2400: arg = DIGI_BAUD_2400; break;
748 case 4800: arg = DIGI_BAUD_4800; break;
749 case 9600: arg = DIGI_BAUD_9600; break;
750 case 19200: arg = DIGI_BAUD_19200; break;
751 case 38400: arg = DIGI_BAUD_38400; break;
752 case 57600: arg = DIGI_BAUD_57600; break;
753 case 115200: arg = DIGI_BAUD_115200; break;
754 case 230400: arg = DIGI_BAUD_230400; break;
755 case 460800: arg = DIGI_BAUD_460800; break;
756 default:
757 arg = DIGI_BAUD_9600;
758 baud = 9600;
759 break;
1da177e4 760 }
c6d61269 761 if (arg != -1) {
1da177e4
LT
762 buf[i++] = DIGI_CMD_SET_BAUD_RATE;
763 buf[i++] = priv->dp_port_num;
764 buf[i++] = arg;
765 buf[i++] = 0;
766 }
1da177e4 767 }
1da177e4 768 /* set parity */
7fa36a99
AC
769 tty->termios->c_cflag &= ~CMSPAR;
770
c6d61269
AC
771 if ((cflag&(PARENB|PARODD)) != (old_cflag&(PARENB|PARODD))) {
772 if (cflag&PARENB) {
773 if (cflag&PARODD)
1da177e4
LT
774 arg = DIGI_PARITY_ODD;
775 else
776 arg = DIGI_PARITY_EVEN;
777 } else {
778 arg = DIGI_PARITY_NONE;
779 }
1da177e4
LT
780 buf[i++] = DIGI_CMD_SET_PARITY;
781 buf[i++] = priv->dp_port_num;
782 buf[i++] = arg;
783 buf[i++] = 0;
1da177e4 784 }
1da177e4 785 /* set word size */
c6d61269 786 if ((cflag&CSIZE) != (old_cflag&CSIZE)) {
1da177e4 787 arg = -1;
c6d61269 788 switch (cflag&CSIZE) {
1da177e4
LT
789 case CS5: arg = DIGI_WORD_SIZE_5; break;
790 case CS6: arg = DIGI_WORD_SIZE_6; break;
791 case CS7: arg = DIGI_WORD_SIZE_7; break;
792 case CS8: arg = DIGI_WORD_SIZE_8; break;
793 default:
c6d61269
AC
794 dbg("digi_set_termios: can't handle word size %d",
795 (cflag&CSIZE));
1da177e4
LT
796 break;
797 }
798
c6d61269 799 if (arg != -1) {
1da177e4
LT
800 buf[i++] = DIGI_CMD_SET_WORD_SIZE;
801 buf[i++] = priv->dp_port_num;
802 buf[i++] = arg;
803 buf[i++] = 0;
804 }
805
806 }
807
808 /* set stop bits */
c6d61269 809 if ((cflag&CSTOPB) != (old_cflag&CSTOPB)) {
1da177e4 810
c6d61269 811 if ((cflag&CSTOPB))
1da177e4
LT
812 arg = DIGI_STOP_BITS_2;
813 else
814 arg = DIGI_STOP_BITS_1;
815
816 buf[i++] = DIGI_CMD_SET_STOP_BITS;
817 buf[i++] = priv->dp_port_num;
818 buf[i++] = arg;
819 buf[i++] = 0;
820
821 }
822
823 /* set input flow control */
c6d61269
AC
824 if ((iflag&IXOFF) != (old_iflag&IXOFF)
825 || (cflag&CRTSCTS) != (old_cflag&CRTSCTS)) {
1da177e4 826 arg = 0;
c6d61269 827 if (iflag&IXOFF)
1da177e4
LT
828 arg |= DIGI_INPUT_FLOW_CONTROL_XON_XOFF;
829 else
830 arg &= ~DIGI_INPUT_FLOW_CONTROL_XON_XOFF;
831
c6d61269 832 if (cflag&CRTSCTS) {
1da177e4
LT
833 arg |= DIGI_INPUT_FLOW_CONTROL_RTS;
834
835 /* On USB-4 it is necessary to assert RTS prior */
836 /* to selecting RTS input flow control. */
837 buf[i++] = DIGI_CMD_SET_RTS_SIGNAL;
838 buf[i++] = priv->dp_port_num;
839 buf[i++] = DIGI_RTS_ACTIVE;
840 buf[i++] = 0;
841
842 } else {
843 arg &= ~DIGI_INPUT_FLOW_CONTROL_RTS;
844 }
1da177e4
LT
845 buf[i++] = DIGI_CMD_SET_INPUT_FLOW_CONTROL;
846 buf[i++] = priv->dp_port_num;
847 buf[i++] = arg;
848 buf[i++] = 0;
1da177e4
LT
849 }
850
851 /* set output flow control */
7fa36a99
AC
852 if ((iflag & IXON) != (old_iflag & IXON)
853 || (cflag & CRTSCTS) != (old_cflag & CRTSCTS)) {
1da177e4 854 arg = 0;
7fa36a99 855 if (iflag & IXON)
1da177e4
LT
856 arg |= DIGI_OUTPUT_FLOW_CONTROL_XON_XOFF;
857 else
858 arg &= ~DIGI_OUTPUT_FLOW_CONTROL_XON_XOFF;
859
7fa36a99 860 if (cflag & CRTSCTS) {
1da177e4
LT
861 arg |= DIGI_OUTPUT_FLOW_CONTROL_CTS;
862 } else {
863 arg &= ~DIGI_OUTPUT_FLOW_CONTROL_CTS;
c6d61269 864 tty->hw_stopped = 0;
1da177e4
LT
865 }
866
867 buf[i++] = DIGI_CMD_SET_OUTPUT_FLOW_CONTROL;
868 buf[i++] = priv->dp_port_num;
869 buf[i++] = arg;
870 buf[i++] = 0;
1da177e4
LT
871 }
872
873 /* set receive enable/disable */
7fa36a99
AC
874 if ((cflag & CREAD) != (old_cflag & CREAD)) {
875 if (cflag & CREAD)
1da177e4
LT
876 arg = DIGI_ENABLE;
877 else
878 arg = DIGI_DISABLE;
879
880 buf[i++] = DIGI_CMD_RECEIVE_ENABLE;
881 buf[i++] = priv->dp_port_num;
882 buf[i++] = arg;
883 buf[i++] = 0;
1da177e4 884 }
41ad427d
AC
885 ret = digi_write_oob_command(port, buf, i, 1);
886 if (ret != 0)
c6d61269 887 dbg("digi_set_termios: write oob failed, ret=%d", ret);
7fa36a99 888 tty_encode_baud_rate(tty, baud, baud);
1da177e4
LT
889}
890
891
95da310e 892static void digi_break_ctl(struct tty_struct *tty, int break_state)
1da177e4 893{
95da310e 894 struct usb_serial_port *port = tty->driver_data;
1da177e4
LT
895 unsigned char buf[4];
896
1da177e4
LT
897 buf[0] = DIGI_CMD_BREAK_CONTROL;
898 buf[1] = 2; /* length */
899 buf[2] = break_state ? 1 : 0;
900 buf[3] = 0; /* pad */
c6d61269 901 digi_write_inb_command(port, buf, 4, 0);
1da177e4
LT
902}
903
904
60b33c13 905static int digi_tiocmget(struct tty_struct *tty)
1da177e4 906{
95da310e 907 struct usb_serial_port *port = tty->driver_data;
1da177e4
LT
908 struct digi_port *priv = usb_get_serial_port_data(port);
909 unsigned int val;
910 unsigned long flags;
911
441b62c1 912 dbg("%s: TOP: port=%d", __func__, priv->dp_port_num);
1da177e4 913
c6d61269 914 spin_lock_irqsave(&priv->dp_port_lock, flags);
1da177e4 915 val = priv->dp_modem_signals;
c6d61269 916 spin_unlock_irqrestore(&priv->dp_port_lock, flags);
1da177e4
LT
917 return val;
918}
919
920
20b9d177
AC
921static int digi_tiocmset(struct tty_struct *tty,
922 unsigned int set, unsigned int clear)
1da177e4 923{
95da310e 924 struct usb_serial_port *port = tty->driver_data;
1da177e4
LT
925 struct digi_port *priv = usb_get_serial_port_data(port);
926 unsigned int val;
927 unsigned long flags;
928
441b62c1 929 dbg("%s: TOP: port=%d", __func__, priv->dp_port_num);
1da177e4 930
c6d61269 931 spin_lock_irqsave(&priv->dp_port_lock, flags);
1da177e4 932 val = (priv->dp_modem_signals & ~clear) | set;
c6d61269
AC
933 spin_unlock_irqrestore(&priv->dp_port_lock, flags);
934 return digi_set_modem_signals(port, val, 1);
1da177e4
LT
935}
936
937
95da310e
AC
938static int digi_write(struct tty_struct *tty, struct usb_serial_port *port,
939 const unsigned char *buf, int count)
1da177e4
LT
940{
941
41ad427d 942 int ret, data_len, new_len;
1da177e4
LT
943 struct digi_port *priv = usb_get_serial_port_data(port);
944 unsigned char *data = port->write_urb->transfer_buffer;
945 unsigned long flags = 0;
946
c6d61269
AC
947 dbg("digi_write: TOP: port=%d, count=%d, in_interrupt=%ld",
948 priv->dp_port_num, count, in_interrupt());
1da177e4
LT
949
950 /* copy user data (which can sleep) before getting spin lock */
c6d61269
AC
951 count = min(count, port->bulk_out_size-2);
952 count = min(64, count);
1da177e4
LT
953
954 /* be sure only one write proceeds at a time */
955 /* there are races on the port private buffer */
c6d61269 956 spin_lock_irqsave(&priv->dp_port_lock, flags);
1da177e4
LT
957
958 /* wait for urb status clear to submit another urb */
50de36f7 959 if (priv->dp_write_urb_in_use) {
1da177e4 960 /* buffer data if count is 1 (probably put_char) if possible */
c6d61269 961 if (count == 1 && priv->dp_out_buf_len < DIGI_OUT_BUF_SIZE) {
1da177e4
LT
962 priv->dp_out_buf[priv->dp_out_buf_len++] = *buf;
963 new_len = 1;
964 } else {
965 new_len = 0;
966 }
c6d61269
AC
967 spin_unlock_irqrestore(&priv->dp_port_lock, flags);
968 return new_len;
1da177e4
LT
969 }
970
971 /* allow space for any buffered data and for new data, up to */
972 /* transfer buffer size - 2 (for command and length bytes) */
973 new_len = min(count, port->bulk_out_size-2-priv->dp_out_buf_len);
974 data_len = new_len + priv->dp_out_buf_len;
975
c6d61269
AC
976 if (data_len == 0) {
977 spin_unlock_irqrestore(&priv->dp_port_lock, flags);
978 return 0;
1da177e4
LT
979 }
980
981 port->write_urb->transfer_buffer_length = data_len+2;
982 port->write_urb->dev = port->serial->dev;
983
984 *data++ = DIGI_CMD_SEND_DATA;
985 *data++ = data_len;
986
987 /* copy in buffered data first */
c6d61269 988 memcpy(data, priv->dp_out_buf, priv->dp_out_buf_len);
1da177e4
LT
989 data += priv->dp_out_buf_len;
990
991 /* copy in new data */
c6d61269 992 memcpy(data, buf, new_len);
1da177e4 993
41ad427d
AC
994 ret = usb_submit_urb(port->write_urb, GFP_ATOMIC);
995 if (ret == 0) {
1da177e4
LT
996 priv->dp_write_urb_in_use = 1;
997 ret = new_len;
998 priv->dp_out_buf_len = 0;
999 }
1000
1001 /* return length of new data written, or error */
c6d61269
AC
1002 spin_unlock_irqrestore(&priv->dp_port_lock, flags);
1003 if (ret < 0)
194343d9
GKH
1004 dev_err(&port->dev,
1005 "%s: usb_submit_urb failed, ret=%d, port=%d\n",
441b62c1 1006 __func__, ret, priv->dp_port_num);
c6d61269
AC
1007 dbg("digi_write: returning %d", ret);
1008 return ret;
1da177e4 1009
41ad427d 1010}
1da177e4 1011
c6d61269 1012static void digi_write_bulk_callback(struct urb *urb)
1da177e4
LT
1013{
1014
cdc97792 1015 struct usb_serial_port *port = urb->context;
1da177e4
LT
1016 struct usb_serial *serial;
1017 struct digi_port *priv;
1018 struct digi_serial *serial_priv;
1019 int ret = 0;
85d75107 1020 int status = urb->status;
1da177e4 1021
50de36f7 1022 dbg("digi_write_bulk_callback: TOP, status=%d", status);
1da177e4
LT
1023
1024 /* port and serial sanity check */
41ad427d 1025 if (port == NULL || (priv = usb_get_serial_port_data(port)) == NULL) {
109f34e7 1026 pr_err("%s: port or port->private is NULL, status=%d\n",
194343d9 1027 __func__, status);
1da177e4
LT
1028 return;
1029 }
1030 serial = port->serial;
41ad427d 1031 if (serial == NULL || (serial_priv = usb_get_serial_data(serial)) == NULL) {
194343d9
GKH
1032 dev_err(&port->dev,
1033 "%s: serial or serial->private is NULL, status=%d\n",
1034 __func__, status);
1da177e4
LT
1035 return;
1036 }
1037
1038 /* handle oob callback */
c6d61269
AC
1039 if (priv->dp_port_num == serial_priv->ds_oob_port_num) {
1040 dbg("digi_write_bulk_callback: oob callback");
1041 spin_lock(&priv->dp_port_lock);
1da177e4 1042 priv->dp_write_urb_in_use = 0;
c6d61269
AC
1043 wake_up_interruptible(&port->write_wait);
1044 spin_unlock(&priv->dp_port_lock);
1da177e4
LT
1045 return;
1046 }
1047
1f87158e 1048 /* try to send any buffered data on this port */
c6d61269 1049 spin_lock(&priv->dp_port_lock);
1da177e4 1050 priv->dp_write_urb_in_use = 0;
1f87158e 1051 if (priv->dp_out_buf_len > 0) {
1da177e4
LT
1052 *((unsigned char *)(port->write_urb->transfer_buffer))
1053 = (unsigned char)DIGI_CMD_SEND_DATA;
41ad427d 1054 *((unsigned char *)(port->write_urb->transfer_buffer) + 1)
1da177e4 1055 = (unsigned char)priv->dp_out_buf_len;
41ad427d
AC
1056 port->write_urb->transfer_buffer_length =
1057 priv->dp_out_buf_len + 2;
1da177e4 1058 port->write_urb->dev = serial->dev;
41ad427d 1059 memcpy(port->write_urb->transfer_buffer + 2, priv->dp_out_buf,
c6d61269 1060 priv->dp_out_buf_len);
41ad427d
AC
1061 ret = usb_submit_urb(port->write_urb, GFP_ATOMIC);
1062 if (ret == 0) {
1da177e4
LT
1063 priv->dp_write_urb_in_use = 1;
1064 priv->dp_out_buf_len = 0;
1065 }
1da177e4 1066 }
1da177e4 1067 /* wake up processes sleeping on writes immediately */
c6d61269 1068 digi_wakeup_write(port);
1da177e4
LT
1069 /* also queue up a wakeup at scheduler time, in case we */
1070 /* lost the race in write_chan(). */
1071 schedule_work(&priv->dp_wakeup_work);
1072
c6d61269 1073 spin_unlock(&priv->dp_port_lock);
1f87158e 1074 if (ret && ret != -EPERM)
194343d9
GKH
1075 dev_err(&port->dev,
1076 "%s: usb_submit_urb failed, ret=%d, port=%d\n",
441b62c1 1077 __func__, ret, priv->dp_port_num);
1da177e4
LT
1078}
1079
95da310e 1080static int digi_write_room(struct tty_struct *tty)
1da177e4 1081{
95da310e 1082 struct usb_serial_port *port = tty->driver_data;
1da177e4 1083 struct digi_port *priv = usb_get_serial_port_data(port);
95da310e 1084 int room;
1da177e4
LT
1085 unsigned long flags = 0;
1086
c6d61269 1087 spin_lock_irqsave(&priv->dp_port_lock, flags);
1da177e4 1088
50de36f7 1089 if (priv->dp_write_urb_in_use)
1da177e4
LT
1090 room = 0;
1091 else
1092 room = port->bulk_out_size - 2 - priv->dp_out_buf_len;
1093
c6d61269
AC
1094 spin_unlock_irqrestore(&priv->dp_port_lock, flags);
1095 dbg("digi_write_room: port=%d, room=%d", priv->dp_port_num, room);
1096 return room;
1da177e4
LT
1097
1098}
1099
95da310e 1100static int digi_chars_in_buffer(struct tty_struct *tty)
1da177e4 1101{
95da310e 1102 struct usb_serial_port *port = tty->driver_data;
1da177e4
LT
1103 struct digi_port *priv = usb_get_serial_port_data(port);
1104
50de36f7 1105 if (priv->dp_write_urb_in_use) {
c6d61269
AC
1106 dbg("digi_chars_in_buffer: port=%d, chars=%d",
1107 priv->dp_port_num, port->bulk_out_size - 2);
1108 /* return(port->bulk_out_size - 2); */
1109 return 256;
1da177e4 1110 } else {
c6d61269
AC
1111 dbg("digi_chars_in_buffer: port=%d, chars=%d",
1112 priv->dp_port_num, priv->dp_out_buf_len);
1113 return priv->dp_out_buf_len;
1da177e4
LT
1114 }
1115
1116}
1117
335f8514
AC
1118static void digi_dtr_rts(struct usb_serial_port *port, int on)
1119{
1120 /* Adjust DTR and RTS */
1121 digi_set_modem_signals(port, on * (TIOCM_DTR|TIOCM_RTS), 1);
1122}
1123
a509a7e4 1124static int digi_open(struct tty_struct *tty, struct usb_serial_port *port)
1da177e4 1125{
1da177e4
LT
1126 int ret;
1127 unsigned char buf[32];
1128 struct digi_port *priv = usb_get_serial_port_data(port);
606d099c 1129 struct ktermios not_termios;
1da177e4 1130
1f87158e 1131 dbg("digi_open: TOP: port=%d", priv->dp_port_num);
1da177e4
LT
1132
1133 /* be sure the device is started up */
c6d61269
AC
1134 if (digi_startup_device(port->serial) != 0)
1135 return -ENXIO;
1da177e4 1136
1da177e4
LT
1137 /* read modem signals automatically whenever they change */
1138 buf[0] = DIGI_CMD_READ_INPUT_SIGNALS;
1139 buf[1] = priv->dp_port_num;
1140 buf[2] = DIGI_ENABLE;
1141 buf[3] = 0;
1142
1143 /* flush fifos */
1144 buf[4] = DIGI_CMD_IFLUSH_FIFO;
1145 buf[5] = priv->dp_port_num;
1146 buf[6] = DIGI_FLUSH_TX | DIGI_FLUSH_RX;
1147 buf[7] = 0;
1148
41ad427d
AC
1149 ret = digi_write_oob_command(port, buf, 8, 1);
1150 if (ret != 0)
c6d61269 1151 dbg("digi_open: write oob failed, ret=%d", ret);
1da177e4
LT
1152
1153 /* set termios settings */
95da310e
AC
1154 if (tty) {
1155 not_termios.c_cflag = ~tty->termios->c_cflag;
1156 not_termios.c_iflag = ~tty->termios->c_iflag;
1157 digi_set_termios(tty, port, &not_termios);
1158 }
c6d61269 1159 return 0;
1da177e4
LT
1160}
1161
1162
335f8514 1163static void digi_close(struct usb_serial_port *port)
1da177e4
LT
1164{
1165 DEFINE_WAIT(wait);
1166 int ret;
1167 unsigned char buf[32];
1da177e4 1168 struct digi_port *priv = usb_get_serial_port_data(port);
1da177e4 1169
1f87158e 1170 dbg("digi_close: TOP: port=%d", priv->dp_port_num);
1da177e4 1171
0915f490 1172 mutex_lock(&port->serial->disc_mutex);
1da177e4 1173 /* if disconnected, just clear flags */
0915f490 1174 if (port->serial->disconnected)
1da177e4
LT
1175 goto exit;
1176
1da177e4 1177 if (port->serial->dev) {
335f8514
AC
1178 /* FIXME: Transmit idle belongs in the wait_unti_sent path */
1179 digi_transmit_idle(port, DIGI_CLOSE_TIMEOUT);
1da177e4
LT
1180
1181 /* disable input flow control */
1182 buf[0] = DIGI_CMD_SET_INPUT_FLOW_CONTROL;
1183 buf[1] = priv->dp_port_num;
1184 buf[2] = DIGI_DISABLE;
1185 buf[3] = 0;
1186
1187 /* disable output flow control */
1188 buf[4] = DIGI_CMD_SET_OUTPUT_FLOW_CONTROL;
1189 buf[5] = priv->dp_port_num;
1190 buf[6] = DIGI_DISABLE;
1191 buf[7] = 0;
1192
1193 /* disable reading modem signals automatically */
1194 buf[8] = DIGI_CMD_READ_INPUT_SIGNALS;
1195 buf[9] = priv->dp_port_num;
1196 buf[10] = DIGI_DISABLE;
1197 buf[11] = 0;
1198
1199 /* disable receive */
1200 buf[12] = DIGI_CMD_RECEIVE_ENABLE;
1201 buf[13] = priv->dp_port_num;
1202 buf[14] = DIGI_DISABLE;
1203 buf[15] = 0;
1204
1205 /* flush fifos */
1206 buf[16] = DIGI_CMD_IFLUSH_FIFO;
1207 buf[17] = priv->dp_port_num;
1208 buf[18] = DIGI_FLUSH_TX | DIGI_FLUSH_RX;
1209 buf[19] = 0;
1210
41ad427d
AC
1211 ret = digi_write_oob_command(port, buf, 20, 0);
1212 if (ret != 0)
c6d61269 1213 dbg("digi_close: write oob failed, ret=%d", ret);
1da177e4
LT
1214
1215 /* wait for final commands on oob port to complete */
41ad427d
AC
1216 prepare_to_wait(&priv->dp_flush_wait, &wait,
1217 TASK_INTERRUPTIBLE);
1da177e4
LT
1218 schedule_timeout(DIGI_CLOSE_TIMEOUT);
1219 finish_wait(&priv->dp_flush_wait, &wait);
1220
1221 /* shutdown any outstanding bulk writes */
1222 usb_kill_urb(port->write_urb);
1223 }
1da177e4 1224exit:
0915f490 1225 spin_lock_irq(&priv->dp_port_lock);
1da177e4 1226 priv->dp_write_urb_in_use = 0;
c6d61269 1227 wake_up_interruptible(&priv->dp_close_wait);
0915f490
ON
1228 spin_unlock_irq(&priv->dp_port_lock);
1229 mutex_unlock(&port->serial->disc_mutex);
c6d61269 1230 dbg("digi_close: done");
1da177e4
LT
1231}
1232
1233
1234/*
41ad427d
AC
1235 * Digi Startup Device
1236 *
1237 * Starts reads on all ports. Must be called AFTER startup, with
1238 * urbs initialized. Returns 0 if successful, non-zero error otherwise.
1239 */
1da177e4 1240
c6d61269 1241static int digi_startup_device(struct usb_serial *serial)
1da177e4 1242{
41ad427d 1243 int i, ret = 0;
1da177e4
LT
1244 struct digi_serial *serial_priv = usb_get_serial_data(serial);
1245 struct usb_serial_port *port;
1246
1da177e4 1247 /* be sure this happens exactly once */
c6d61269
AC
1248 spin_lock(&serial_priv->ds_serial_lock);
1249 if (serial_priv->ds_device_started) {
1250 spin_unlock(&serial_priv->ds_serial_lock);
1251 return 0;
1da177e4
LT
1252 }
1253 serial_priv->ds_device_started = 1;
c6d61269 1254 spin_unlock(&serial_priv->ds_serial_lock);
1da177e4
LT
1255
1256 /* start reading from each bulk in endpoint for the device */
1257 /* set USB_DISABLE_SPD flag for write bulk urbs */
c6d61269 1258 for (i = 0; i < serial->type->num_ports + 1; i++) {
1da177e4 1259 port = serial->port[i];
1da177e4 1260 port->write_urb->dev = port->serial->dev;
41ad427d
AC
1261 ret = usb_submit_urb(port->read_urb, GFP_KERNEL);
1262 if (ret != 0) {
194343d9
GKH
1263 dev_err(&port->dev,
1264 "%s: usb_submit_urb failed, ret=%d, port=%d\n",
1265 __func__, ret, i);
1da177e4
LT
1266 break;
1267 }
1da177e4 1268 }
c6d61269 1269 return ret;
1da177e4
LT
1270}
1271
1272
c6d61269 1273static int digi_startup(struct usb_serial *serial)
1da177e4
LT
1274{
1275
1276 int i;
1277 struct digi_port *priv;
1278 struct digi_serial *serial_priv;
1279
c6d61269 1280 dbg("digi_startup: TOP");
1da177e4
LT
1281
1282 /* allocate the private data structures for all ports */
1283 /* number of regular ports + 1 for the out-of-band port */
41ad427d 1284 for (i = 0; i < serial->type->num_ports + 1; i++) {
1da177e4 1285 /* allocate port private structure */
c6d61269
AC
1286 priv = kmalloc(sizeof(struct digi_port), GFP_KERNEL);
1287 if (priv == NULL) {
1288 while (--i >= 0)
1289 kfree(usb_get_serial_port_data(serial->port[i]));
1290 return 1; /* error */
1da177e4
LT
1291 }
1292
1293 /* initialize port private structure */
c6d61269 1294 spin_lock_init(&priv->dp_port_lock);
1da177e4
LT
1295 priv->dp_port_num = i;
1296 priv->dp_out_buf_len = 0;
1da177e4
LT
1297 priv->dp_write_urb_in_use = 0;
1298 priv->dp_modem_signals = 0;
c6d61269 1299 init_waitqueue_head(&priv->dp_modem_change_wait);
1da177e4 1300 priv->dp_transmit_idle = 0;
c6d61269 1301 init_waitqueue_head(&priv->dp_transmit_idle_wait);
1da177e4
LT
1302 priv->dp_throttled = 0;
1303 priv->dp_throttle_restart = 0;
c6d61269 1304 init_waitqueue_head(&priv->dp_flush_wait);
c6d61269 1305 init_waitqueue_head(&priv->dp_close_wait);
c4028958
DH
1306 INIT_WORK(&priv->dp_wakeup_work, digi_wakeup_write_lock);
1307 priv->dp_port = serial->port[i];
1da177e4 1308 /* initialize write wait queue for this port */
c6d61269 1309 init_waitqueue_head(&serial->port[i]->write_wait);
1da177e4
LT
1310
1311 usb_set_serial_port_data(serial->port[i], priv);
1312 }
1313
1314 /* allocate serial private structure */
c6d61269
AC
1315 serial_priv = kmalloc(sizeof(struct digi_serial), GFP_KERNEL);
1316 if (serial_priv == NULL) {
1317 for (i = 0; i < serial->type->num_ports + 1; i++)
1318 kfree(usb_get_serial_port_data(serial->port[i]));
1319 return 1; /* error */
1da177e4
LT
1320 }
1321
1322 /* initialize serial private structure */
c6d61269 1323 spin_lock_init(&serial_priv->ds_serial_lock);
1da177e4
LT
1324 serial_priv->ds_oob_port_num = serial->type->num_ports;
1325 serial_priv->ds_oob_port = serial->port[serial_priv->ds_oob_port_num];
1326 serial_priv->ds_device_started = 0;
1327 usb_set_serial_data(serial, serial_priv);
1328
c6d61269 1329 return 0;
1da177e4
LT
1330}
1331
1332
f9c99bb8 1333static void digi_disconnect(struct usb_serial *serial)
1da177e4 1334{
1da177e4 1335 int i;
f9c99bb8 1336 dbg("digi_disconnect: TOP, in_interrupt()=%ld", in_interrupt());
1da177e4
LT
1337
1338 /* stop reads and writes on all ports */
c6d61269 1339 for (i = 0; i < serial->type->num_ports + 1; i++) {
1da177e4
LT
1340 usb_kill_urb(serial->port[i]->read_urb);
1341 usb_kill_urb(serial->port[i]->write_urb);
1342 }
f9c99bb8
AS
1343}
1344
1345
1346static void digi_release(struct usb_serial *serial)
1347{
1348 int i;
1349 dbg("digi_release: TOP, in_interrupt()=%ld", in_interrupt());
1da177e4
LT
1350
1351 /* free the private data structures for all ports */
1352 /* number of regular ports + 1 for the out-of-band port */
41ad427d 1353 for (i = 0; i < serial->type->num_ports + 1; i++)
c6d61269
AC
1354 kfree(usb_get_serial_port_data(serial->port[i]));
1355 kfree(usb_get_serial_data(serial));
1da177e4
LT
1356}
1357
1358
c6d61269 1359static void digi_read_bulk_callback(struct urb *urb)
1da177e4 1360{
cdc97792 1361 struct usb_serial_port *port = urb->context;
1da177e4
LT
1362 struct digi_port *priv;
1363 struct digi_serial *serial_priv;
1364 int ret;
85d75107 1365 int status = urb->status;
1da177e4 1366
c6d61269 1367 dbg("digi_read_bulk_callback: TOP");
1da177e4
LT
1368
1369 /* port sanity check, do not resubmit if port is not valid */
194343d9
GKH
1370 if (port == NULL)
1371 return;
1372 priv = usb_get_serial_port_data(port);
1373 if (priv == NULL) {
1374 dev_err(&port->dev, "%s: port->private is NULL, status=%d\n",
1375 __func__, status);
1da177e4
LT
1376 return;
1377 }
c6d61269 1378 if (port->serial == NULL ||
41ad427d 1379 (serial_priv = usb_get_serial_data(port->serial)) == NULL) {
194343d9
GKH
1380 dev_err(&port->dev, "%s: serial is bad or serial->private "
1381 "is NULL, status=%d\n", __func__, status);
1da177e4
LT
1382 return;
1383 }
1384
1385 /* do not resubmit urb if it has any status error */
85d75107 1386 if (status) {
194343d9
GKH
1387 dev_err(&port->dev,
1388 "%s: nonzero read bulk status: status=%d, port=%d\n",
1389 __func__, status, priv->dp_port_num);
1da177e4
LT
1390 return;
1391 }
1392
1393 /* handle oob or inb callback, do not resubmit if error */
c6d61269
AC
1394 if (priv->dp_port_num == serial_priv->ds_oob_port_num) {
1395 if (digi_read_oob_callback(urb) != 0)
1da177e4
LT
1396 return;
1397 } else {
c6d61269 1398 if (digi_read_inb_callback(urb) != 0)
1da177e4
LT
1399 return;
1400 }
1401
1402 /* continue read */
1403 urb->dev = port->serial->dev;
41ad427d 1404 ret = usb_submit_urb(urb, GFP_ATOMIC);
1f87158e 1405 if (ret != 0 && ret != -EPERM) {
194343d9
GKH
1406 dev_err(&port->dev,
1407 "%s: failed resubmitting urb, ret=%d, port=%d\n",
1408 __func__, ret, priv->dp_port_num);
1da177e4
LT
1409 }
1410
1411}
1412
41ad427d
AC
1413/*
1414 * Digi Read INB Callback
1415 *
1416 * Digi Read INB Callback handles reads on the in band ports, sending
1417 * the data on to the tty subsystem. When called we know port and
1418 * port->private are not NULL and port->serial has been validated.
1419 * It returns 0 if successful, 1 if successful but the port is
1420 * throttled, and -1 if the sanity checks failed.
1421 */
1da177e4 1422
c6d61269 1423static int digi_read_inb_callback(struct urb *urb)
1da177e4
LT
1424{
1425
cdc97792 1426 struct usb_serial_port *port = urb->context;
4a90f09b 1427 struct tty_struct *tty;
1da177e4
LT
1428 struct digi_port *priv = usb_get_serial_port_data(port);
1429 int opcode = ((unsigned char *)urb->transfer_buffer)[0];
1430 int len = ((unsigned char *)urb->transfer_buffer)[1];
85d75107 1431 int port_status = ((unsigned char *)urb->transfer_buffer)[2];
41ad427d
AC
1432 unsigned char *data = ((unsigned char *)urb->transfer_buffer) + 3;
1433 int flag, throttled;
85d75107 1434 int status = urb->status;
1da177e4
LT
1435
1436 /* do not process callbacks on closed ports */
1437 /* but do continue the read chain */
1f87158e 1438 if (urb->status == -ENOENT)
c6d61269 1439 return 0;
1da177e4
LT
1440
1441 /* short/multiple packet check */
c6d61269 1442 if (urb->actual_length != len + 2) {
194343d9 1443 dev_err(&port->dev, "%s: INCOMPLETE OR MULTIPLE PACKET, "
50de36f7 1444 "status=%d, port=%d, opcode=%d, len=%d, "
194343d9
GKH
1445 "actual_length=%d, status=%d\n", __func__, status,
1446 priv->dp_port_num, opcode, len, urb->actual_length,
1447 port_status);
c6d61269 1448 return -1;
1da177e4
LT
1449 }
1450
4a90f09b 1451 tty = tty_port_tty_get(&port->port);
c6d61269 1452 spin_lock(&priv->dp_port_lock);
1da177e4
LT
1453
1454 /* check for throttle; if set, do not resubmit read urb */
1455 /* indicate the read chain needs to be restarted on unthrottle */
1456 throttled = priv->dp_throttled;
c6d61269 1457 if (throttled)
1da177e4
LT
1458 priv->dp_throttle_restart = 1;
1459
1460 /* receive data */
4287341d 1461 if (tty && opcode == DIGI_CMD_RECEIVE_DATA) {
85d75107 1462 /* get flag from port_status */
1da177e4
LT
1463 flag = 0;
1464
1465 /* overrun is special, not associated with a char */
c6d61269
AC
1466 if (port_status & DIGI_OVERRUN_ERROR)
1467 tty_insert_flip_char(tty, 0, TTY_OVERRUN);
1da177e4
LT
1468
1469 /* break takes precedence over parity, */
1470 /* which takes precedence over framing errors */
c6d61269 1471 if (port_status & DIGI_BREAK_ERROR)
1da177e4 1472 flag = TTY_BREAK;
c6d61269 1473 else if (port_status & DIGI_PARITY_ERROR)
1da177e4 1474 flag = TTY_PARITY;
c6d61269 1475 else if (port_status & DIGI_FRAMING_ERROR)
1da177e4 1476 flag = TTY_FRAME;
1da177e4 1477
85d75107 1478 /* data length is len-1 (one byte of len is port_status) */
1da177e4 1479 --len;
c6d61269 1480 if (len > 0) {
70ced221
JH
1481 tty_insert_flip_string_fixed_flag(tty, data, flag,
1482 len);
c6d61269 1483 tty_flip_buffer_push(tty);
1da177e4 1484 }
1da177e4 1485 }
c6d61269 1486 spin_unlock(&priv->dp_port_lock);
4a90f09b 1487 tty_kref_put(tty);
1da177e4 1488
c6d61269 1489 if (opcode == DIGI_CMD_RECEIVE_DISABLE)
441b62c1 1490 dbg("%s: got RECEIVE_DISABLE", __func__);
c6d61269 1491 else if (opcode != DIGI_CMD_RECEIVE_DATA)
441b62c1 1492 dbg("%s: unknown opcode: %d", __func__, opcode);
1da177e4 1493
41ad427d 1494 return throttled ? 1 : 0;
1da177e4
LT
1495
1496}
1497
1498
41ad427d
AC
1499/*
1500 * Digi Read OOB Callback
1501 *
1502 * Digi Read OOB Callback handles reads on the out of band port.
1503 * When called we know port and port->private are not NULL and
1504 * the port->serial is valid. It returns 0 if successful, and
1505 * -1 if the sanity checks failed.
1506 */
1da177e4 1507
c6d61269 1508static int digi_read_oob_callback(struct urb *urb)
1da177e4
LT
1509{
1510
cdc97792 1511 struct usb_serial_port *port = urb->context;
1da177e4 1512 struct usb_serial *serial = port->serial;
4a90f09b 1513 struct tty_struct *tty;
1da177e4
LT
1514 struct digi_port *priv = usb_get_serial_port_data(port);
1515 int opcode, line, status, val;
1516 int i;
41ad427d 1517 unsigned int rts;
1da177e4 1518
c6d61269
AC
1519 dbg("digi_read_oob_callback: port=%d, len=%d",
1520 priv->dp_port_num, urb->actual_length);
1da177e4
LT
1521
1522 /* handle each oob command */
41ad427d 1523 for (i = 0; i < urb->actual_length - 3;) {
1da177e4
LT
1524 opcode = ((unsigned char *)urb->transfer_buffer)[i++];
1525 line = ((unsigned char *)urb->transfer_buffer)[i++];
1526 status = ((unsigned char *)urb->transfer_buffer)[i++];
1527 val = ((unsigned char *)urb->transfer_buffer)[i++];
1528
c6d61269
AC
1529 dbg("digi_read_oob_callback: opcode=%d, line=%d, status=%d, val=%d",
1530 opcode, line, status, val);
1da177e4 1531
c6d61269 1532 if (status != 0 || line >= serial->type->num_ports)
1da177e4
LT
1533 continue;
1534
1535 port = serial->port[line];
1536
41ad427d
AC
1537 priv = usb_get_serial_port_data(port);
1538 if (priv == NULL)
1da177e4
LT
1539 return -1;
1540
4a90f09b 1541 tty = tty_port_tty_get(&port->port);
4287341d 1542
41ad427d 1543 rts = 0;
4287341d
AC
1544 if (tty)
1545 rts = tty->termios->c_cflag & CRTSCTS;
4a90f09b 1546
4287341d 1547 if (tty && opcode == DIGI_CMD_READ_INPUT_SIGNALS) {
c6d61269 1548 spin_lock(&priv->dp_port_lock);
1da177e4 1549 /* convert from digi flags to termiox flags */
c6d61269 1550 if (val & DIGI_READ_INPUT_SIGNALS_CTS) {
1da177e4
LT
1551 priv->dp_modem_signals |= TIOCM_CTS;
1552 /* port must be open to use tty struct */
41ad427d 1553 if (rts) {
4a90f09b 1554 tty->hw_stopped = 0;
c6d61269 1555 digi_wakeup_write(port);
1da177e4
LT
1556 }
1557 } else {
1558 priv->dp_modem_signals &= ~TIOCM_CTS;
1559 /* port must be open to use tty struct */
41ad427d 1560 if (rts)
4a90f09b 1561 tty->hw_stopped = 1;
1da177e4 1562 }
c6d61269 1563 if (val & DIGI_READ_INPUT_SIGNALS_DSR)
1da177e4
LT
1564 priv->dp_modem_signals |= TIOCM_DSR;
1565 else
1566 priv->dp_modem_signals &= ~TIOCM_DSR;
c6d61269 1567 if (val & DIGI_READ_INPUT_SIGNALS_RI)
1da177e4
LT
1568 priv->dp_modem_signals |= TIOCM_RI;
1569 else
1570 priv->dp_modem_signals &= ~TIOCM_RI;
c6d61269 1571 if (val & DIGI_READ_INPUT_SIGNALS_DCD)
1da177e4
LT
1572 priv->dp_modem_signals |= TIOCM_CD;
1573 else
1574 priv->dp_modem_signals &= ~TIOCM_CD;
1575
c6d61269
AC
1576 wake_up_interruptible(&priv->dp_modem_change_wait);
1577 spin_unlock(&priv->dp_port_lock);
1578 } else if (opcode == DIGI_CMD_TRANSMIT_IDLE) {
1579 spin_lock(&priv->dp_port_lock);
1da177e4 1580 priv->dp_transmit_idle = 1;
c6d61269
AC
1581 wake_up_interruptible(&priv->dp_transmit_idle_wait);
1582 spin_unlock(&priv->dp_port_lock);
1583 } else if (opcode == DIGI_CMD_IFLUSH_FIFO) {
1584 wake_up_interruptible(&priv->dp_flush_wait);
1da177e4 1585 }
4a90f09b 1586 tty_kref_put(tty);
1da177e4 1587 }
c6d61269 1588 return 0;
1da177e4
LT
1589
1590}
1591
c6d61269 1592static int __init digi_init(void)
1da177e4
LT
1593{
1594 int retval;
1595 retval = usb_serial_register(&digi_acceleport_2_device);
1596 if (retval)
1597 goto failed_acceleport_2_device;
1598 retval = usb_serial_register(&digi_acceleport_4_device);
41ad427d 1599 if (retval)
1da177e4
LT
1600 goto failed_acceleport_4_device;
1601 retval = usb_register(&digi_driver);
1602 if (retval)
1603 goto failed_usb_register;
c197a8db
GKH
1604 printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":"
1605 DRIVER_DESC "\n");
1da177e4
LT
1606 return 0;
1607failed_usb_register:
1608 usb_serial_deregister(&digi_acceleport_4_device);
1609failed_acceleport_4_device:
1610 usb_serial_deregister(&digi_acceleport_2_device);
1611failed_acceleport_2_device:
1612 return retval;
1613}
1614
1da177e4
LT
1615static void __exit digi_exit (void)
1616{
c6d61269
AC
1617 usb_deregister(&digi_driver);
1618 usb_serial_deregister(&digi_acceleport_2_device);
1619 usb_serial_deregister(&digi_acceleport_4_device);
1da177e4
LT
1620}
1621
1622
1623module_init(digi_init);
1624module_exit(digi_exit);
1625
1626
c6d61269
AC
1627MODULE_AUTHOR(DRIVER_AUTHOR);
1628MODULE_DESCRIPTION(DRIVER_DESC);
1da177e4
LT
1629MODULE_LICENSE("GPL");
1630
1631module_param(debug, bool, S_IRUGO | S_IWUSR);
1632MODULE_PARM_DESC(debug, "Debug enabled or not");