3 * Controls the Moschip 7720 usb to dual port serial convertor
5 * Copyright 2006 Moschip Semiconductor Tech. Ltd.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, version 2 of the License.
12 * Vijaya Kumar <vijaykumar.gn@gmail.com>
13 * Ajay Kumar <naanuajay@yahoo.com>
14 * Gurudeva <ngurudeva@yahoo.com>
16 * Cleaned up from the original by:
17 * Greg Kroah-Hartman <gregkh@suse.de>
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>
23 #include <linux/kernel.h>
24 #include <linux/errno.h>
25 #include <linux/init.h>
26 #include <linux/slab.h>
27 #include <linux/tty.h>
28 #include <linux/tty_driver.h>
29 #include <linux/tty_flip.h>
30 #include <linux/module.h>
31 #include <linux/spinlock.h>
32 #include <linux/serial.h>
33 #include <linux/serial_reg.h>
34 #include <linux/usb.h>
35 #include <linux/usb/serial.h>
36 #include <linux/uaccess.h>
37 #include <linux/parport.h>
42 #define DRIVER_VERSION "2.0"
43 #define DRIVER_AUTHOR "Aspire Communications pvt Ltd."
44 #define DRIVER_DESC "Moschip USB Serial Driver"
46 /* default urb timeout */
47 #define MOS_WDR_TIMEOUT (HZ * 5)
49 #define MOS_PORT1 0x0200
50 #define MOS_PORT2 0x0300
51 #define MOS_VENREG 0x0000
52 #define MOS_MAX_PORT 0x02
53 #define MOS_WRITE 0x0E
56 /* Interrupt Rotinue Defines */
57 #define SERIAL_IIR_RLS 0x06
58 #define SERIAL_IIR_RDA 0x04
59 #define SERIAL_IIR_CTI 0x0c
60 #define SERIAL_IIR_THR 0x02
61 #define SERIAL_IIR_MS 0x00
63 #define NUM_URBS 16 /* URB Count */
64 #define URB_TRANSFER_BUFFER_SIZE 32 /* URB Size */
66 /* This structure holds all of the local serial port information */
68 __u8 shadowLCR
; /* last LCR value received */
69 __u8 shadowMCR
; /* last MCR value received */
70 __u8 shadowMSR
; /* last MSR value received */
72 struct async_icount icount
;
73 struct usb_serial_port
*port
; /* loop back to the owner */
74 struct urb
*write_urb_pool
[NUM_URBS
];
79 static struct usb_serial_driver moschip7720_2port_driver
;
81 #define USB_VENDOR_ID_MOSCHIP 0x9710
82 #define MOSCHIP_DEVICE_ID_7720 0x7720
83 #define MOSCHIP_DEVICE_ID_7715 0x7715
85 static const struct usb_device_id moschip_port_id_table
[] = {
86 { USB_DEVICE(USB_VENDOR_ID_MOSCHIP
, MOSCHIP_DEVICE_ID_7720
) },
87 { USB_DEVICE(USB_VENDOR_ID_MOSCHIP
, MOSCHIP_DEVICE_ID_7715
) },
88 { } /* terminating entry */
90 MODULE_DEVICE_TABLE(usb
, moschip_port_id_table
);
92 #ifdef CONFIG_USB_SERIAL_MOS7715_PARPORT
94 /* initial values for parport regs */
95 #define DCR_INIT_VAL 0x0c /* SLCTIN, nINIT */
96 #define ECR_INIT_VAL 0x00 /* SPP mode */
99 struct mos7715_parport
*mos_parport
;
100 struct list_head urblist_entry
;
101 struct kref ref_count
;
105 enum mos7715_pp_modes
{
107 PS2
= 1<<5, /* moschip calls this 'NIBBLE' mode */
108 PPF
= 2<<5, /* moschip calls this 'CB-FIFO mode */
111 struct mos7715_parport
{
112 struct parport
*pp
; /* back to containing struct */
113 struct kref ref_count
; /* to instance of this struct */
114 struct list_head deferred_urbs
; /* list deferred async urbs */
115 struct list_head active_urbs
; /* list async urbs in flight */
116 spinlock_t listlock
; /* protects list access */
117 bool msg_pending
; /* usb sync call pending */
118 struct completion syncmsg_compl
; /* usb sync call completed */
119 struct tasklet_struct urb_tasklet
; /* for sending deferred urbs */
120 struct usb_serial
*serial
; /* back to containing struct */
121 __u8 shadowECR
; /* parallel port regs... */
123 atomic_t shadowDSR
; /* updated in int-in callback */
126 /* lock guards against dereferencing NULL ptr in parport ops callbacks */
127 static DEFINE_SPINLOCK(release_lock
);
130 THR
, /* serial port regs */
142 DPR
, /* parallel port regs */
146 SP1_REG
, /* device control regs */
147 SP2_REG
, /* serial port 2 (7720 only) */
153 * Return the correct value for the Windex field of the setup packet
154 * for a control endpoint message. See the 7715 datasheet.
156 static inline __u16
get_reg_index(enum mos_regs reg
)
158 static const __u16 mos7715_index_lookup_table
[] = {
176 0x02, /* SP2_REG (7720 only) */
177 0x04, /* PP_REG (7715 only) */
178 0x08, /* SP_CONTROL_REG */
180 return mos7715_index_lookup_table
[reg
];
184 * Return the correct value for the upper byte of the Wvalue field of
185 * the setup packet for a control endpoint message.
187 static inline __u16
get_reg_value(enum mos_regs reg
)
189 if (reg
>= SP1_REG
) /* control reg */
191 else /* parallel port reg (7715 only) */
196 * Write data byte to the specified device register. The data is embedded in
197 * the value field of the setup packet.
199 static int write_parport_reg(struct mos7715_parport
*mos_parport
,
200 enum mos_regs reg
, __u8 data
)
202 struct usb_serial
*serial
= mos_parport
->serial
;
203 struct usb_device
*usbdev
= serial
->dev
;
204 unsigned int pipe
= usb_sndctrlpipe(usbdev
, 0);
205 __u8 request
= (__u8
)0x0e;
206 __u8 requesttype
= (__u8
)0x40;
207 __u16 value
= get_reg_value(reg
) + data
;
208 __u16 index
= get_reg_index(reg
);
211 status
= usb_control_msg(usbdev
, pipe
, request
, requesttype
, value
,
212 index
, NULL
, size
, MOS_WDR_TIMEOUT
);
214 dev_err(&usbdev
->dev
,
215 "mos7720: usb_control_msg() failed: %d", status
);
220 * Read data byte from the specified device register. The data returned by the
221 * device is embedded in the value field of the setup packet.
223 static int read_parport_reg(struct mos7715_parport
*mos_parport
,
224 enum mos_regs reg
, __u8
*data
)
226 struct usb_device
*usbdev
= mos_parport
->serial
->dev
;
227 unsigned int pipe
= usb_rcvctrlpipe(usbdev
, 0);
228 __u8 request
= (__u8
)0x0d;
229 __u8 requesttype
= (__u8
)0xc0;
230 __u16 value
= get_reg_value(reg
);
231 __u16 index
= get_reg_index(reg
);
233 int status
= usb_control_msg(usbdev
, pipe
, request
, requesttype
, value
,
234 index
, data
, size
, MOS_WDR_TIMEOUT
);
236 dev_err(&usbdev
->dev
,
237 "mos7720: usb_control_msg() failed: %d", status
);
241 static inline int mos7715_change_mode(struct mos7715_parport
*mos_parport
,
242 enum mos7715_pp_modes mode
)
244 mos_parport
->shadowECR
= mode
;
245 write_parport_reg(mos_parport
, ECR
, mos_parport
->shadowECR
);
249 static void destroy_mos_parport(struct kref
*kref
)
251 struct mos7715_parport
*mos_parport
=
252 container_of(kref
, struct mos7715_parport
, ref_count
);
254 dbg("%s called", __func__
);
258 static void destroy_urbtracker(struct kref
*kref
)
260 struct urbtracker
*urbtrack
=
261 container_of(kref
, struct urbtracker
, ref_count
);
262 struct mos7715_parport
*mos_parport
= urbtrack
->mos_parport
;
263 dbg("%s called", __func__
);
264 usb_free_urb(urbtrack
->urb
);
266 kref_put(&mos_parport
->ref_count
, destroy_mos_parport
);
270 * This runs as a tasklet when sending an urb in a non-blocking parallel
271 * port callback had to be deferred because the disconnect mutex could not be
272 * obtained at the time.
274 static void send_deferred_urbs(unsigned long _mos_parport
)
278 struct mos7715_parport
*mos_parport
= (void *)_mos_parport
;
279 struct urbtracker
*urbtrack
;
280 struct list_head
*cursor
, *next
;
282 dbg("%s called", __func__
);
284 /* if release function ran, game over */
285 if (unlikely(mos_parport
->serial
== NULL
))
288 /* try again to get the mutex */
289 if (!mutex_trylock(&mos_parport
->serial
->disc_mutex
)) {
290 dbg("%s: rescheduling tasklet", __func__
);
291 tasklet_schedule(&mos_parport
->urb_tasklet
);
295 /* if device disconnected, game over */
296 if (unlikely(mos_parport
->serial
->disconnected
)) {
297 mutex_unlock(&mos_parport
->serial
->disc_mutex
);
301 spin_lock_irqsave(&mos_parport
->listlock
, flags
);
302 if (list_empty(&mos_parport
->deferred_urbs
)) {
303 spin_unlock_irqrestore(&mos_parport
->listlock
, flags
);
304 mutex_unlock(&mos_parport
->serial
->disc_mutex
);
305 dbg("%s: deferred_urbs list empty", __func__
);
309 /* move contents of deferred_urbs list to active_urbs list and submit */
310 list_for_each_safe(cursor
, next
, &mos_parport
->deferred_urbs
)
311 list_move_tail(cursor
, &mos_parport
->active_urbs
);
312 list_for_each_entry(urbtrack
, &mos_parport
->active_urbs
,
314 ret_val
= usb_submit_urb(urbtrack
->urb
, GFP_ATOMIC
);
315 dbg("%s: urb submitted", __func__
);
317 dev_err(&mos_parport
->serial
->dev
->dev
,
318 "usb_submit_urb() failed: %d", ret_val
);
319 list_del(&urbtrack
->urblist_entry
);
320 kref_put(&urbtrack
->ref_count
, destroy_urbtracker
);
323 spin_unlock_irqrestore(&mos_parport
->listlock
, flags
);
324 mutex_unlock(&mos_parport
->serial
->disc_mutex
);
327 /* callback for parallel port control urbs submitted asynchronously */
328 static void async_complete(struct urb
*urb
)
330 struct urbtracker
*urbtrack
= urb
->context
;
331 int status
= urb
->status
;
332 dbg("%s called", __func__
);
333 if (unlikely(status
))
334 dbg("%s - nonzero urb status received: %d", __func__
, status
);
336 /* remove the urbtracker from the active_urbs list */
337 spin_lock(&urbtrack
->mos_parport
->listlock
);
338 list_del(&urbtrack
->urblist_entry
);
339 spin_unlock(&urbtrack
->mos_parport
->listlock
);
340 kref_put(&urbtrack
->ref_count
, destroy_urbtracker
);
343 static int write_parport_reg_nonblock(struct mos7715_parport
*mos_parport
,
344 enum mos_regs reg
, __u8 data
)
346 struct urbtracker
*urbtrack
;
349 struct usb_ctrlrequest setup
;
350 struct usb_serial
*serial
= mos_parport
->serial
;
351 struct usb_device
*usbdev
= serial
->dev
;
352 dbg("%s called", __func__
);
354 /* create and initialize the control urb and containing urbtracker */
355 urbtrack
= kmalloc(sizeof(struct urbtracker
), GFP_ATOMIC
);
356 if (urbtrack
== NULL
) {
357 dev_err(&usbdev
->dev
, "out of memory");
360 kref_get(&mos_parport
->ref_count
);
361 urbtrack
->mos_parport
= mos_parport
;
362 urbtrack
->urb
= usb_alloc_urb(0, GFP_ATOMIC
);
363 if (urbtrack
->urb
== NULL
) {
364 dev_err(&usbdev
->dev
, "out of urbs");
368 setup
.bRequestType
= (__u8
)0x40;
369 setup
.bRequest
= (__u8
)0x0e;
370 setup
.wValue
= get_reg_value(reg
);
371 setup
.wIndex
= get_reg_index(reg
);
373 usb_fill_control_urb(urbtrack
->urb
, usbdev
,
374 usb_sndctrlpipe(usbdev
, 0),
375 (unsigned char *)&setup
,
376 NULL
, 0, async_complete
, urbtrack
);
377 kref_init(&urbtrack
->ref_count
);
378 INIT_LIST_HEAD(&urbtrack
->urblist_entry
);
381 * get the disconnect mutex, or add tracker to the deferred_urbs list
382 * and schedule a tasklet to try again later
384 if (!mutex_trylock(&serial
->disc_mutex
)) {
385 spin_lock_irqsave(&mos_parport
->listlock
, flags
);
386 list_add_tail(&urbtrack
->urblist_entry
,
387 &mos_parport
->deferred_urbs
);
388 spin_unlock_irqrestore(&mos_parport
->listlock
, flags
);
389 tasklet_schedule(&mos_parport
->urb_tasklet
);
390 dbg("tasklet scheduled");
394 /* bail if device disconnected */
395 if (serial
->disconnected
) {
396 kref_put(&urbtrack
->ref_count
, destroy_urbtracker
);
397 mutex_unlock(&serial
->disc_mutex
);
401 /* add the tracker to the active_urbs list and submit */
402 spin_lock_irqsave(&mos_parport
->listlock
, flags
);
403 list_add_tail(&urbtrack
->urblist_entry
, &mos_parport
->active_urbs
);
404 spin_unlock_irqrestore(&mos_parport
->listlock
, flags
);
405 ret_val
= usb_submit_urb(urbtrack
->urb
, GFP_ATOMIC
);
406 mutex_unlock(&serial
->disc_mutex
);
408 dev_err(&usbdev
->dev
,
409 "%s: submit_urb() failed: %d", __func__
, ret_val
);
410 spin_lock_irqsave(&mos_parport
->listlock
, flags
);
411 list_del(&urbtrack
->urblist_entry
);
412 spin_unlock_irqrestore(&mos_parport
->listlock
, flags
);
413 kref_put(&urbtrack
->ref_count
, destroy_urbtracker
);
420 * This is the the common top part of all parallel port callback operations that
421 * send synchronous messages to the device. This implements convoluted locking
422 * that avoids two scenarios: (1) a port operation is called after usbserial
423 * has called our release function, at which point struct mos7715_parport has
424 * been destroyed, and (2) the device has been disconnected, but usbserial has
425 * not called the release function yet because someone has a serial port open.
426 * The shared release_lock prevents the first, and the mutex and disconnected
427 * flag maintained by usbserial covers the second. We also use the msg_pending
428 * flag to ensure that all synchronous usb messgage calls have completed before
429 * our release function can return.
431 static int parport_prologue(struct parport
*pp
)
433 struct mos7715_parport
*mos_parport
;
435 spin_lock(&release_lock
);
436 mos_parport
= pp
->private_data
;
437 if (unlikely(mos_parport
== NULL
)) {
438 /* release fn called, port struct destroyed */
439 spin_unlock(&release_lock
);
442 mos_parport
->msg_pending
= true; /* synch usb call pending */
443 INIT_COMPLETION(mos_parport
->syncmsg_compl
);
444 spin_unlock(&release_lock
);
446 mutex_lock(&mos_parport
->serial
->disc_mutex
);
447 if (mos_parport
->serial
->disconnected
) {
448 /* device disconnected */
449 mutex_unlock(&mos_parport
->serial
->disc_mutex
);
450 mos_parport
->msg_pending
= false;
451 complete(&mos_parport
->syncmsg_compl
);
459 * This is the the common bottom part of all parallel port functions that send
460 * synchronous messages to the device.
462 static inline void parport_epilogue(struct parport
*pp
)
464 struct mos7715_parport
*mos_parport
= pp
->private_data
;
465 mutex_unlock(&mos_parport
->serial
->disc_mutex
);
466 mos_parport
->msg_pending
= false;
467 complete(&mos_parport
->syncmsg_compl
);
470 static void parport_mos7715_write_data(struct parport
*pp
, unsigned char d
)
472 struct mos7715_parport
*mos_parport
= pp
->private_data
;
473 dbg("%s called: %2.2x", __func__
, d
);
474 if (parport_prologue(pp
) < 0)
476 mos7715_change_mode(mos_parport
, SPP
);
477 write_parport_reg(mos_parport
, DPR
, (__u8
)d
);
478 parport_epilogue(pp
);
481 static unsigned char parport_mos7715_read_data(struct parport
*pp
)
483 struct mos7715_parport
*mos_parport
= pp
->private_data
;
485 dbg("%s called", __func__
);
486 if (parport_prologue(pp
) < 0)
488 read_parport_reg(mos_parport
, DPR
, &d
);
489 parport_epilogue(pp
);
493 static void parport_mos7715_write_control(struct parport
*pp
, unsigned char d
)
495 struct mos7715_parport
*mos_parport
= pp
->private_data
;
497 dbg("%s called: %2.2x", __func__
, d
);
498 if (parport_prologue(pp
) < 0)
500 data
= ((__u8
)d
& 0x0f) | (mos_parport
->shadowDCR
& 0xf0);
501 write_parport_reg(mos_parport
, DCR
, data
);
502 mos_parport
->shadowDCR
= data
;
503 parport_epilogue(pp
);
506 static unsigned char parport_mos7715_read_control(struct parport
*pp
)
508 struct mos7715_parport
*mos_parport
= pp
->private_data
;
510 dbg("%s called", __func__
);
511 spin_lock(&release_lock
);
512 mos_parport
= pp
->private_data
;
513 if (unlikely(mos_parport
== NULL
)) {
514 spin_unlock(&release_lock
);
517 dcr
= mos_parport
->shadowDCR
& 0x0f;
518 spin_unlock(&release_lock
);
522 static unsigned char parport_mos7715_frob_control(struct parport
*pp
,
526 struct mos7715_parport
*mos_parport
= pp
->private_data
;
528 dbg("%s called", __func__
);
531 if (parport_prologue(pp
) < 0)
533 mos_parport
->shadowDCR
= (mos_parport
->shadowDCR
& (~mask
)) ^ val
;
534 write_parport_reg(mos_parport
, DCR
, mos_parport
->shadowDCR
);
535 dcr
= mos_parport
->shadowDCR
& 0x0f;
536 parport_epilogue(pp
);
540 static unsigned char parport_mos7715_read_status(struct parport
*pp
)
542 unsigned char status
;
543 struct mos7715_parport
*mos_parport
= pp
->private_data
;
544 dbg("%s called", __func__
);
545 spin_lock(&release_lock
);
546 mos_parport
= pp
->private_data
;
547 if (unlikely(mos_parport
== NULL
)) { /* release called */
548 spin_unlock(&release_lock
);
551 status
= atomic_read(&mos_parport
->shadowDSR
) & 0xf8;
552 spin_unlock(&release_lock
);
556 static void parport_mos7715_enable_irq(struct parport
*pp
)
558 dbg("%s called", __func__
);
560 static void parport_mos7715_disable_irq(struct parport
*pp
)
562 dbg("%s called", __func__
);
565 static void parport_mos7715_data_forward(struct parport
*pp
)
567 struct mos7715_parport
*mos_parport
= pp
->private_data
;
568 dbg("%s called", __func__
);
569 if (parport_prologue(pp
) < 0)
571 mos7715_change_mode(mos_parport
, PS2
);
572 mos_parport
->shadowDCR
&= ~0x20;
573 write_parport_reg(mos_parport
, DCR
, mos_parport
->shadowDCR
);
574 parport_epilogue(pp
);
577 static void parport_mos7715_data_reverse(struct parport
*pp
)
579 struct mos7715_parport
*mos_parport
= pp
->private_data
;
580 dbg("%s called", __func__
);
581 if (parport_prologue(pp
) < 0)
583 mos7715_change_mode(mos_parport
, PS2
);
584 mos_parport
->shadowDCR
|= 0x20;
585 write_parport_reg(mos_parport
, DCR
, mos_parport
->shadowDCR
);
586 parport_epilogue(pp
);
589 static void parport_mos7715_init_state(struct pardevice
*dev
,
590 struct parport_state
*s
)
592 dbg("%s called", __func__
);
593 s
->u
.pc
.ctr
= DCR_INIT_VAL
;
594 s
->u
.pc
.ecr
= ECR_INIT_VAL
;
597 /* N.B. Parport core code requires that this function not block */
598 static void parport_mos7715_save_state(struct parport
*pp
,
599 struct parport_state
*s
)
601 struct mos7715_parport
*mos_parport
;
602 dbg("%s called", __func__
);
603 spin_lock(&release_lock
);
604 mos_parport
= pp
->private_data
;
605 if (unlikely(mos_parport
== NULL
)) { /* release called */
606 spin_unlock(&release_lock
);
609 s
->u
.pc
.ctr
= mos_parport
->shadowDCR
;
610 s
->u
.pc
.ecr
= mos_parport
->shadowECR
;
611 spin_unlock(&release_lock
);
614 /* N.B. Parport core code requires that this function not block */
615 static void parport_mos7715_restore_state(struct parport
*pp
,
616 struct parport_state
*s
)
618 struct mos7715_parport
*mos_parport
;
619 dbg("%s called", __func__
);
620 spin_lock(&release_lock
);
621 mos_parport
= pp
->private_data
;
622 if (unlikely(mos_parport
== NULL
)) { /* release called */
623 spin_unlock(&release_lock
);
626 write_parport_reg_nonblock(mos_parport
, DCR
, mos_parport
->shadowDCR
);
627 write_parport_reg_nonblock(mos_parport
, ECR
, mos_parport
->shadowECR
);
628 spin_unlock(&release_lock
);
631 static size_t parport_mos7715_write_compat(struct parport
*pp
,
633 size_t len
, int flags
)
636 struct mos7715_parport
*mos_parport
= pp
->private_data
;
638 dbg("%s called: %u chars", __func__
, (unsigned int)len
);
639 if (parport_prologue(pp
) < 0)
641 mos7715_change_mode(mos_parport
, PPF
);
642 retval
= usb_bulk_msg(mos_parport
->serial
->dev
,
643 usb_sndbulkpipe(mos_parport
->serial
->dev
, 2),
644 (void *)buffer
, len
, &actual_len
,
646 parport_epilogue(pp
);
648 dev_err(&mos_parport
->serial
->dev
->dev
,
649 "mos7720: usb_bulk_msg() failed: %d", retval
);
655 static struct parport_operations parport_mos7715_ops
= {
656 .owner
= THIS_MODULE
,
657 .write_data
= parport_mos7715_write_data
,
658 .read_data
= parport_mos7715_read_data
,
660 .write_control
= parport_mos7715_write_control
,
661 .read_control
= parport_mos7715_read_control
,
662 .frob_control
= parport_mos7715_frob_control
,
664 .read_status
= parport_mos7715_read_status
,
666 .enable_irq
= parport_mos7715_enable_irq
,
667 .disable_irq
= parport_mos7715_disable_irq
,
669 .data_forward
= parport_mos7715_data_forward
,
670 .data_reverse
= parport_mos7715_data_reverse
,
672 .init_state
= parport_mos7715_init_state
,
673 .save_state
= parport_mos7715_save_state
,
674 .restore_state
= parport_mos7715_restore_state
,
676 .compat_write_data
= parport_mos7715_write_compat
,
678 .nibble_read_data
= parport_ieee1284_read_nibble
,
679 .byte_read_data
= parport_ieee1284_read_byte
,
683 * Allocate and initialize parallel port control struct, initialize
684 * the parallel port hardware device, and register with the parport subsystem.
686 static int mos7715_parport_init(struct usb_serial
*serial
)
688 struct mos7715_parport
*mos_parport
;
690 /* allocate and initialize parallel port control struct */
691 mos_parport
= kzalloc(sizeof(struct mos7715_parport
), GFP_KERNEL
);
692 if (mos_parport
== NULL
) {
693 dbg("mos7715_parport_init: kzalloc failed");
696 mos_parport
->msg_pending
= false;
697 kref_init(&mos_parport
->ref_count
);
698 spin_lock_init(&mos_parport
->listlock
);
699 INIT_LIST_HEAD(&mos_parport
->active_urbs
);
700 INIT_LIST_HEAD(&mos_parport
->deferred_urbs
);
701 usb_set_serial_data(serial
, mos_parport
); /* hijack private pointer */
702 mos_parport
->serial
= serial
;
703 tasklet_init(&mos_parport
->urb_tasklet
, send_deferred_urbs
,
704 (unsigned long) mos_parport
);
705 init_completion(&mos_parport
->syncmsg_compl
);
707 /* cycle parallel port reset bit */
708 write_parport_reg(mos_parport
, PP_REG
, (__u8
)0x80);
709 write_parport_reg(mos_parport
, PP_REG
, (__u8
)0x00);
711 /* initialize device registers */
712 mos_parport
->shadowDCR
= DCR_INIT_VAL
;
713 write_parport_reg(mos_parport
, DCR
, mos_parport
->shadowDCR
);
714 mos_parport
->shadowECR
= ECR_INIT_VAL
;
715 write_parport_reg(mos_parport
, ECR
, mos_parport
->shadowECR
);
717 /* register with parport core */
718 mos_parport
->pp
= parport_register_port(0, PARPORT_IRQ_NONE
,
720 &parport_mos7715_ops
);
721 if (mos_parport
->pp
== NULL
) {
722 dev_err(&serial
->interface
->dev
,
723 "Could not register parport\n");
724 kref_put(&mos_parport
->ref_count
, destroy_mos_parport
);
727 mos_parport
->pp
->private_data
= mos_parport
;
728 mos_parport
->pp
->modes
= PARPORT_MODE_COMPAT
| PARPORT_MODE_PCSPP
;
729 mos_parport
->pp
->dev
= &serial
->interface
->dev
;
730 parport_announce_port(mos_parport
->pp
);
734 #endif /* CONFIG_USB_SERIAL_MOS7715_PARPORT */
737 * mos7720_interrupt_callback
738 * this is the callback function for when we have received data on the
739 * interrupt endpoint.
741 static void mos7720_interrupt_callback(struct urb
*urb
)
745 int status
= urb
->status
;
758 /* this urb is terminated, clean up */
759 dbg("%s - urb shutting down with status: %d", __func__
,
763 dbg("%s - nonzero urb status received: %d", __func__
,
768 length
= urb
->actual_length
;
769 data
= urb
->transfer_buffer
;
771 /* Moschip get 4 bytes
772 * Byte 1 IIR Port 1 (port.number is 0)
773 * Byte 2 IIR Port 2 (port.number is 1)
774 * Byte 3 --------------
775 * Byte 4 FIFO status for both */
777 /* the above description is inverted
778 * oneukum 2007-03-14 */
780 if (unlikely(length
!= 4)) {
781 dbg("Wrong data !!!");
788 if ((sp1
| sp2
) & 0x01) {
789 /* No Interrupt Pending in both the ports */
790 dbg("No Interrupt !!!");
792 switch (sp1
& 0x0f) {
794 dbg("Serial Port 1: Receiver status error or address "
795 "bit detected in 9-bit mode\n");
798 dbg("Serial Port 1: Receiver time out");
801 /* dbg("Serial Port 1: Modem status change"); */
805 switch (sp2
& 0x0f) {
807 dbg("Serial Port 2: Receiver status error or address "
808 "bit detected in 9-bit mode");
811 dbg("Serial Port 2: Receiver time out");
814 /* dbg("Serial Port 2: Modem status change"); */
820 result
= usb_submit_urb(urb
, GFP_ATOMIC
);
822 dev_err(&urb
->dev
->dev
,
823 "%s - Error %d submitting control urb\n",
829 * mos7715_interrupt_callback
830 * this is the 7715's callback function for when we have received data on
831 * the interrupt endpoint.
833 static void mos7715_interrupt_callback(struct urb
*urb
)
837 int status
= urb
->status
;
849 /* this urb is terminated, clean up */
850 dbg("%s - urb shutting down with status: %d", __func__
,
854 dbg("%s - nonzero urb status received: %d", __func__
,
859 length
= urb
->actual_length
;
860 data
= urb
->transfer_buffer
;
862 /* Structure of data from 7715 device:
863 * Byte 1: IIR serial Port
865 * Byte 2: DSR parallel port
866 * Byte 4: FIFO status for both */
868 if (unlikely(length
!= 4)) {
869 dbg("Wrong data !!!");
874 if (!(iir
& 0x01)) { /* serial port interrupt pending */
875 switch (iir
& 0x0f) {
877 dbg("Serial Port: Receiver status error or address "
878 "bit detected in 9-bit mode\n");
881 dbg("Serial Port: Receiver time out");
884 /* dbg("Serial Port: Modem status change"); */
889 #ifdef CONFIG_USB_SERIAL_MOS7715_PARPORT
890 { /* update local copy of DSR reg */
891 struct usb_serial_port
*port
= urb
->context
;
892 struct mos7715_parport
*mos_parport
= port
->serial
->private;
893 if (unlikely(mos_parport
== NULL
))
895 atomic_set(&mos_parport
->shadowDSR
, data
[2]);
900 result
= usb_submit_urb(urb
, GFP_ATOMIC
);
902 dev_err(&urb
->dev
->dev
,
903 "%s - Error %d submitting control urb\n",
909 * mos7720_bulk_in_callback
910 * this is the callback function for when we have received data on the
913 static void mos7720_bulk_in_callback(struct urb
*urb
)
916 unsigned char *data
;
917 struct usb_serial_port
*port
;
918 struct tty_struct
*tty
;
919 int status
= urb
->status
;
922 dbg("nonzero read bulk status received: %d", status
);
928 dbg("Entering...%s", __func__
);
930 data
= urb
->transfer_buffer
;
932 tty
= tty_port_tty_get(&port
->port
);
933 if (tty
&& urb
->actual_length
) {
934 tty_insert_flip_string(tty
, data
, urb
->actual_length
);
935 tty_flip_buffer_push(tty
);
939 if (!port
->read_urb
) {
940 dbg("URB KILLED !!!");
944 if (port
->read_urb
->status
!= -EINPROGRESS
) {
945 port
->read_urb
->dev
= port
->serial
->dev
;
947 retval
= usb_submit_urb(port
->read_urb
, GFP_ATOMIC
);
949 dbg("usb_submit_urb(read bulk) failed, retval = %d",
955 * mos7720_bulk_out_data_callback
956 * this is the callback function for when we have finished sending serial
957 * data on the bulk out endpoint.
959 static void mos7720_bulk_out_data_callback(struct urb
*urb
)
961 struct moschip_port
*mos7720_port
;
962 struct tty_struct
*tty
;
963 int status
= urb
->status
;
966 dbg("nonzero write bulk status received:%d", status
);
970 mos7720_port
= urb
->context
;
972 dbg("NULL mos7720_port pointer");
976 tty
= tty_port_tty_get(&mos7720_port
->port
->port
);
978 if (tty
&& mos7720_port
->open
)
985 * this function will be used for sending command to device
987 static int send_mos_cmd(struct usb_serial
*serial
, __u8 request
, __u16 value
,
988 __u16 index
, u8
*data
)
992 u16 product
= le16_to_cpu(serial
->dev
->descriptor
.idProduct
);
994 if (value
< MOS_MAX_PORT
) {
995 if (product
== MOSCHIP_DEVICE_ID_7715
)
996 value
= 0x0200; /* identifies the 7715's serial port */
998 value
= value
*0x100+0x200;
1001 if ((product
== MOSCHIP_DEVICE_ID_7715
) &&
1003 dbg("serial->product== MOSCHIP_DEVICE_ID_7715");
1004 /* index = 0x01 ; */
1008 if (request
== MOS_WRITE
) {
1009 value
= value
+ *data
;
1010 status
= usb_control_msg(serial
->dev
,
1011 usb_sndctrlpipe(serial
->dev
, 0), MOS_WRITE
,
1012 0x40, value
, index
, NULL
, 0, MOS_WDR_TIMEOUT
);
1014 buf
= kmalloc(1, GFP_KERNEL
);
1019 status
= usb_control_msg(serial
->dev
,
1020 usb_rcvctrlpipe(serial
->dev
, 0), MOS_READ
,
1021 0xc0, value
, index
, buf
, 1, MOS_WDR_TIMEOUT
);
1027 dbg("Command Write failed Value %x index %x", value
, index
);
1035 * this function installs the appropriate read interrupt endpoint callback
1036 * depending on whether the device is a 7720 or 7715, thus avoiding costly
1037 * run-time checks in the high-frequency callback routine itself.
1039 static int mos77xx_probe(struct usb_serial
*serial
,
1040 const struct usb_device_id
*id
)
1042 if (id
->idProduct
== MOSCHIP_DEVICE_ID_7715
)
1043 moschip7720_2port_driver
.read_int_callback
=
1044 mos7715_interrupt_callback
;
1046 moschip7720_2port_driver
.read_int_callback
=
1047 mos7720_interrupt_callback
;
1052 static int mos77xx_calc_num_ports(struct usb_serial
*serial
)
1054 u16 product
= le16_to_cpu(serial
->dev
->descriptor
.idProduct
);
1055 if (product
== MOSCHIP_DEVICE_ID_7715
)
1061 static int mos7720_open(struct tty_struct
*tty
, struct usb_serial_port
*port
)
1063 struct usb_serial
*serial
;
1064 struct usb_serial_port
*port0
;
1066 struct moschip_port
*mos7720_port
;
1070 int allocated_urbs
= 0;
1073 serial
= port
->serial
;
1075 mos7720_port
= usb_get_serial_port_data(port
);
1076 if (mos7720_port
== NULL
)
1079 port0
= serial
->port
[0];
1081 usb_clear_halt(serial
->dev
, port
->write_urb
->pipe
);
1082 usb_clear_halt(serial
->dev
, port
->read_urb
->pipe
);
1084 /* Initialising the write urb pool */
1085 for (j
= 0; j
< NUM_URBS
; ++j
) {
1086 urb
= usb_alloc_urb(0, GFP_KERNEL
);
1087 mos7720_port
->write_urb_pool
[j
] = urb
;
1090 dev_err(&port
->dev
, "No more urbs???\n");
1094 urb
->transfer_buffer
= kmalloc(URB_TRANSFER_BUFFER_SIZE
,
1096 if (!urb
->transfer_buffer
) {
1098 "%s-out of memory for urb buffers.\n",
1100 usb_free_urb(mos7720_port
->write_urb_pool
[j
]);
1101 mos7720_port
->write_urb_pool
[j
] = NULL
;
1107 if (!allocated_urbs
)
1110 /* Initialize MCS7720 -- Write Init values to corresponding Registers
1122 * 0x08 : SP1/2 Control Reg
1124 port_number
= port
->number
- port
->serial
->minor
;
1125 send_mos_cmd(port
->serial
, MOS_READ
, port_number
, UART_LSR
, &data
);
1126 dbg("SS::%p LSR:%x", mos7720_port
, data
);
1128 dbg("Check:Sending Command ..........");
1131 send_mos_cmd(serial
, MOS_WRITE
, MOS_MAX_PORT
, 0x01, &data
);
1133 send_mos_cmd(serial
, MOS_WRITE
, MOS_MAX_PORT
, 0x02, &data
);
1136 send_mos_cmd(serial
, MOS_WRITE
, port_number
, 0x01, &data
);
1138 send_mos_cmd(serial
, MOS_WRITE
, port_number
, 0x02, &data
);
1141 send_mos_cmd(serial
, MOS_WRITE
, port_number
, 0x02, &data
);
1143 mos7720_port
->shadowLCR
= data
;
1144 send_mos_cmd(serial
, MOS_WRITE
, port_number
, 0x03, &data
);
1146 mos7720_port
->shadowMCR
= data
;
1147 send_mos_cmd(serial
, MOS_WRITE
, port_number
, 0x04, &data
);
1149 send_mos_cmd(serial
, MOS_WRITE
, port_number
, 0x04, &data
);
1152 send_mos_cmd(serial
, MOS_READ
, MOS_MAX_PORT
, 0x08, &data
);
1154 send_mos_cmd(serial
, MOS_WRITE
, MOS_MAX_PORT
, 0x08, &data
);
1157 send_mos_cmd(serial, MOS_READ, MOS_MAX_PORT, port_number + 1, &data);
1159 send_mos_cmd(serial, MOS_WRITE, MOS_MAX_PORT, port_number + 1, &data);
1161 send_mos_cmd(port->serial, MOS_WRITE, MOS_MAX_PORT,
1162 port_number + 1, &data);
1165 send_mos_cmd(serial
, MOS_READ
, MOS_MAX_PORT
, 0x08, &data
);
1167 data
= data
| (port
->number
- port
->serial
->minor
+ 1);
1168 send_mos_cmd(serial
, MOS_WRITE
, MOS_MAX_PORT
, 0x08, &data
);
1171 mos7720_port
->shadowLCR
= data
;
1172 send_mos_cmd(serial
, MOS_WRITE
, port_number
, 0x03, &data
);
1174 send_mos_cmd(serial
, MOS_WRITE
, port_number
, 0x00, &data
);
1176 send_mos_cmd(serial
, MOS_WRITE
, port_number
, 0x01, &data
);
1178 mos7720_port
->shadowLCR
= data
;
1179 send_mos_cmd(serial
, MOS_WRITE
, port_number
, 0x03, &data
);
1181 send_mos_cmd(serial
, MOS_WRITE
, port_number
, 0x01, &data
);
1183 send_mos_cmd(serial
, MOS_WRITE
, port_number
, 0x01, &data
);
1185 response
= usb_submit_urb(port
->read_urb
, GFP_KERNEL
);
1187 dev_err(&port
->dev
, "%s - Error %d submitting read urb\n",
1188 __func__
, response
);
1190 /* initialize our icount structure */
1191 memset(&(mos7720_port
->icount
), 0x00, sizeof(mos7720_port
->icount
));
1193 /* initialize our port settings */
1194 mos7720_port
->shadowMCR
= UART_MCR_OUT2
; /* Must set to enable ints! */
1196 /* send a open port command */
1197 mos7720_port
->open
= 1;
1203 * mos7720_chars_in_buffer
1204 * this function is called by the tty driver when it wants to know how many
1205 * bytes of data we currently have outstanding in the port (data that has
1206 * been written, but hasn't made it out the port yet)
1207 * If successful, we return the number of bytes left to be written in the
1209 * Otherwise we return a negative error number.
1211 static int mos7720_chars_in_buffer(struct tty_struct
*tty
)
1213 struct usb_serial_port
*port
= tty
->driver_data
;
1216 struct moschip_port
*mos7720_port
;
1218 dbg("%s:entering ...........", __func__
);
1220 mos7720_port
= usb_get_serial_port_data(port
);
1221 if (mos7720_port
== NULL
) {
1222 dbg("%s:leaving ...........", __func__
);
1226 for (i
= 0; i
< NUM_URBS
; ++i
) {
1227 if (mos7720_port
->write_urb_pool
[i
] &&
1228 mos7720_port
->write_urb_pool
[i
]->status
== -EINPROGRESS
)
1229 chars
+= URB_TRANSFER_BUFFER_SIZE
;
1231 dbg("%s - returns %d", __func__
, chars
);
1235 static void mos7720_close(struct usb_serial_port
*port
)
1237 struct usb_serial
*serial
;
1238 struct moschip_port
*mos7720_port
;
1242 dbg("mos7720_close:entering...");
1244 serial
= port
->serial
;
1246 mos7720_port
= usb_get_serial_port_data(port
);
1247 if (mos7720_port
== NULL
)
1250 for (j
= 0; j
< NUM_URBS
; ++j
)
1251 usb_kill_urb(mos7720_port
->write_urb_pool
[j
]);
1253 /* Freeing Write URBs */
1254 for (j
= 0; j
< NUM_URBS
; ++j
) {
1255 if (mos7720_port
->write_urb_pool
[j
]) {
1256 kfree(mos7720_port
->write_urb_pool
[j
]->transfer_buffer
);
1257 usb_free_urb(mos7720_port
->write_urb_pool
[j
]);
1261 /* While closing port, shutdown all bulk read, write *
1262 * and interrupt read if they exists, otherwise nop */
1263 dbg("Shutdown bulk write");
1264 usb_kill_urb(port
->write_urb
);
1265 dbg("Shutdown bulk read");
1266 usb_kill_urb(port
->read_urb
);
1268 mutex_lock(&serial
->disc_mutex
);
1269 /* these commands must not be issued if the device has
1270 * been disconnected */
1271 if (!serial
->disconnected
) {
1273 send_mos_cmd(serial
, MOS_WRITE
,
1274 port
->number
- port
->serial
->minor
, 0x04, &data
);
1277 send_mos_cmd(serial
, MOS_WRITE
,
1278 port
->number
- port
->serial
->minor
, 0x01, &data
);
1280 mutex_unlock(&serial
->disc_mutex
);
1281 mos7720_port
->open
= 0;
1283 dbg("Leaving %s", __func__
);
1286 static void mos7720_break(struct tty_struct
*tty
, int break_state
)
1288 struct usb_serial_port
*port
= tty
->driver_data
;
1290 struct usb_serial
*serial
;
1291 struct moschip_port
*mos7720_port
;
1293 dbg("Entering %s", __func__
);
1295 serial
= port
->serial
;
1297 mos7720_port
= usb_get_serial_port_data(port
);
1298 if (mos7720_port
== NULL
)
1301 if (break_state
== -1)
1302 data
= mos7720_port
->shadowLCR
| UART_LCR_SBC
;
1304 data
= mos7720_port
->shadowLCR
& ~UART_LCR_SBC
;
1306 mos7720_port
->shadowLCR
= data
;
1307 send_mos_cmd(serial
, MOS_WRITE
, port
->number
- port
->serial
->minor
,
1314 * mos7720_write_room
1315 * this function is called by the tty driver when it wants to know how many
1316 * bytes of data we can accept for a specific port.
1317 * If successful, we return the amount of room that we have for this port
1318 * Otherwise we return a negative error number.
1320 static int mos7720_write_room(struct tty_struct
*tty
)
1322 struct usb_serial_port
*port
= tty
->driver_data
;
1323 struct moschip_port
*mos7720_port
;
1327 dbg("%s:entering ...........", __func__
);
1329 mos7720_port
= usb_get_serial_port_data(port
);
1330 if (mos7720_port
== NULL
) {
1331 dbg("%s:leaving ...........", __func__
);
1335 /* FIXME: Locking */
1336 for (i
= 0; i
< NUM_URBS
; ++i
) {
1337 if (mos7720_port
->write_urb_pool
[i
] &&
1338 mos7720_port
->write_urb_pool
[i
]->status
!= -EINPROGRESS
)
1339 room
+= URB_TRANSFER_BUFFER_SIZE
;
1342 dbg("%s - returns %d", __func__
, room
);
1346 static int mos7720_write(struct tty_struct
*tty
, struct usb_serial_port
*port
,
1347 const unsigned char *data
, int count
)
1354 struct moschip_port
*mos7720_port
;
1355 struct usb_serial
*serial
;
1357 const unsigned char *current_position
= data
;
1359 dbg("%s:entering ...........", __func__
);
1361 serial
= port
->serial
;
1363 mos7720_port
= usb_get_serial_port_data(port
);
1364 if (mos7720_port
== NULL
) {
1365 dbg("mos7720_port is NULL");
1369 /* try to find a free urb in the list */
1372 for (i
= 0; i
< NUM_URBS
; ++i
) {
1373 if (mos7720_port
->write_urb_pool
[i
] &&
1374 mos7720_port
->write_urb_pool
[i
]->status
!= -EINPROGRESS
) {
1375 urb
= mos7720_port
->write_urb_pool
[i
];
1382 dbg("%s - no more free urbs", __func__
);
1386 if (urb
->transfer_buffer
== NULL
) {
1387 urb
->transfer_buffer
= kmalloc(URB_TRANSFER_BUFFER_SIZE
,
1389 if (urb
->transfer_buffer
== NULL
) {
1390 dev_err(&port
->dev
, "%s no more kernel memory...\n",
1395 transfer_size
= min(count
, URB_TRANSFER_BUFFER_SIZE
);
1397 memcpy(urb
->transfer_buffer
, current_position
, transfer_size
);
1398 usb_serial_debug_data(debug
, &port
->dev
, __func__
, transfer_size
,
1399 urb
->transfer_buffer
);
1401 /* fill urb with data and submit */
1402 usb_fill_bulk_urb(urb
, serial
->dev
,
1403 usb_sndbulkpipe(serial
->dev
,
1404 port
->bulk_out_endpointAddress
),
1405 urb
->transfer_buffer
, transfer_size
,
1406 mos7720_bulk_out_data_callback
, mos7720_port
);
1408 /* send it down the pipe */
1409 status
= usb_submit_urb(urb
, GFP_ATOMIC
);
1411 dev_err(&port
->dev
, "%s - usb_submit_urb(write bulk) failed "
1412 "with status = %d\n", __func__
, status
);
1413 bytes_sent
= status
;
1416 bytes_sent
= transfer_size
;
1422 static void mos7720_throttle(struct tty_struct
*tty
)
1424 struct usb_serial_port
*port
= tty
->driver_data
;
1425 struct moschip_port
*mos7720_port
;
1428 dbg("%s- port %d", __func__
, port
->number
);
1430 mos7720_port
= usb_get_serial_port_data(port
);
1432 if (mos7720_port
== NULL
)
1435 if (!mos7720_port
->open
) {
1436 dbg("port not opened");
1440 dbg("%s: Entering ..........", __func__
);
1442 /* if we are implementing XON/XOFF, send the stop character */
1444 unsigned char stop_char
= STOP_CHAR(tty
);
1445 status
= mos7720_write(tty
, port
, &stop_char
, 1);
1450 /* if we are implementing RTS/CTS, toggle that line */
1451 if (tty
->termios
->c_cflag
& CRTSCTS
) {
1452 mos7720_port
->shadowMCR
&= ~UART_MCR_RTS
;
1453 status
= send_mos_cmd(port
->serial
, MOS_WRITE
,
1454 port
->number
- port
->serial
->minor
,
1455 UART_MCR
, &mos7720_port
->shadowMCR
);
1461 static void mos7720_unthrottle(struct tty_struct
*tty
)
1463 struct usb_serial_port
*port
= tty
->driver_data
;
1464 struct moschip_port
*mos7720_port
= usb_get_serial_port_data(port
);
1467 if (mos7720_port
== NULL
)
1470 if (!mos7720_port
->open
) {
1471 dbg("%s - port not opened", __func__
);
1475 dbg("%s: Entering ..........", __func__
);
1477 /* if we are implementing XON/XOFF, send the start character */
1479 unsigned char start_char
= START_CHAR(tty
);
1480 status
= mos7720_write(tty
, port
, &start_char
, 1);
1485 /* if we are implementing RTS/CTS, toggle that line */
1486 if (tty
->termios
->c_cflag
& CRTSCTS
) {
1487 mos7720_port
->shadowMCR
|= UART_MCR_RTS
;
1488 status
= send_mos_cmd(port
->serial
, MOS_WRITE
,
1489 port
->number
- port
->serial
->minor
,
1490 UART_MCR
, &mos7720_port
->shadowMCR
);
1496 /* FIXME: this function does not work */
1497 static int set_higher_rates(struct moschip_port
*mos7720_port
,
1501 struct usb_serial_port
*port
;
1502 struct usb_serial
*serial
;
1505 if (mos7720_port
== NULL
)
1508 port
= mos7720_port
->port
;
1509 serial
= port
->serial
;
1511 /***********************************************
1512 * Init Sequence for higher rates
1513 ***********************************************/
1514 dbg("Sending Setting Commands ..........");
1515 port_number
= port
->number
- port
->serial
->minor
;
1518 send_mos_cmd(serial
, MOS_WRITE
, port_number
, 0x01, &data
);
1520 send_mos_cmd(serial
, MOS_WRITE
, port_number
, 0x02, &data
);
1522 send_mos_cmd(serial
, MOS_WRITE
, port
->number
, 0x02, &data
);
1524 mos7720_port
->shadowMCR
= data
;
1525 send_mos_cmd(serial
, MOS_WRITE
, port_number
, 0x04, &data
);
1527 send_mos_cmd(serial
, MOS_WRITE
, port_number
, 0x04, &data
);
1530 send_mos_cmd(serial
, MOS_READ
, MOS_MAX_PORT
, 0x08, &data
);
1532 send_mos_cmd(serial
, MOS_WRITE
, MOS_MAX_PORT
, 0x08, &data
);
1535 /***********************************************
1536 * Set for higher rates *
1537 ***********************************************/
1539 /* writing baud rate verbatum into uart clock field clearly not right */
1541 send_mos_cmd(serial
, MOS_WRITE
, MOS_MAX_PORT
, port_number
+ 1, &data
);
1544 send_mos_cmd(serial
, MOS_READ
, MOS_MAX_PORT
, 0x08, &data
);
1546 send_mos_cmd(serial
, MOS_WRITE
, MOS_MAX_PORT
, 0x08, &data
);
1549 mos7720_port
->shadowMCR
= data
;
1550 send_mos_cmd(serial
, MOS_WRITE
, port_number
, 0x04, &data
);
1552 send_mos_cmd(serial
, MOS_WRITE
, port_number
, 0x04, &data
);
1554 /***********************************************
1556 ***********************************************/
1558 data
= mos7720_port
->shadowLCR
| UART_LCR_DLAB
;
1559 mos7720_port
->shadowLCR
= data
;
1560 send_mos_cmd(serial
, MOS_WRITE
, port_number
, 0x03, &data
);
1562 data
= 0x001; /* DLL */
1563 send_mos_cmd(serial
, MOS_WRITE
, port_number
, 0x00, &data
);
1564 data
= 0x000; /* DLM */
1565 send_mos_cmd(serial
, MOS_WRITE
, port_number
, 0x01, &data
);
1567 data
= mos7720_port
->shadowLCR
& ~UART_LCR_DLAB
;
1568 mos7720_port
->shadowLCR
= data
;
1569 send_mos_cmd(serial
, MOS_WRITE
, port_number
, 0x03, &data
);
1574 /* baud rate information */
1575 struct divisor_table_entry
{
1580 /* Define table of divisors for moschip 7720 hardware *
1581 * These assume a 3.6864MHz crystal, the standard /16, and *
1583 static struct divisor_table_entry divisor_table
[] = {
1585 { 110, 1047}, /* 2094.545455 => 230450 => .0217 % over */
1586 { 134, 857}, /* 1713.011152 => 230398.5 => .00065% under */
1602 /*****************************************************************************
1603 * calc_baud_rate_divisor
1604 * this function calculates the proper baud rate divisor for the specified
1606 *****************************************************************************/
1607 static int calc_baud_rate_divisor(int baudrate
, int *divisor
)
1615 dbg("%s - %d", __func__
, baudrate
);
1617 for (i
= 0; i
< ARRAY_SIZE(divisor_table
); i
++) {
1618 if (divisor_table
[i
].baudrate
== baudrate
) {
1619 *divisor
= divisor_table
[i
].divisor
;
1624 /* After trying for all the standard baud rates *
1625 * Try calculating the divisor for this baud rate */
1626 if (baudrate
> 75 && baudrate
< 230400) {
1627 /* get the divisor */
1628 custom
= (__u16
)(230400L / baudrate
);
1630 /* Check for round off */
1631 round1
= (__u16
)(2304000L / baudrate
);
1632 round
= (__u16
)(round1
- (custom
* 10));
1637 dbg("Baud %d = %d", baudrate
, custom
);
1641 dbg("Baud calculation Failed...");
1646 * send_cmd_write_baud_rate
1647 * this function sends the proper command to change the baud rate of the
1650 static int send_cmd_write_baud_rate(struct moschip_port
*mos7720_port
,
1653 struct usb_serial_port
*port
;
1654 struct usb_serial
*serial
;
1658 unsigned char number
;
1660 if (mos7720_port
== NULL
)
1663 port
= mos7720_port
->port
;
1664 serial
= port
->serial
;
1666 dbg("%s: Entering ..........", __func__
);
1668 number
= port
->number
- port
->serial
->minor
;
1669 dbg("%s - port = %d, baud = %d", __func__
, port
->number
, baudrate
);
1671 /* Calculate the Divisor */
1672 status
= calc_baud_rate_divisor(baudrate
, &divisor
);
1674 dev_err(&port
->dev
, "%s - bad baud rate\n", __func__
);
1678 /* Enable access to divisor latch */
1679 data
= mos7720_port
->shadowLCR
| UART_LCR_DLAB
;
1680 mos7720_port
->shadowLCR
= data
;
1681 send_mos_cmd(serial
, MOS_WRITE
, number
, UART_LCR
, &data
);
1683 /* Write the divisor */
1684 data
= ((unsigned char)(divisor
& 0xff));
1685 send_mos_cmd(serial
, MOS_WRITE
, number
, 0x00, &data
);
1687 data
= ((unsigned char)((divisor
& 0xff00) >> 8));
1688 send_mos_cmd(serial
, MOS_WRITE
, number
, 0x01, &data
);
1690 /* Disable access to divisor latch */
1691 data
= mos7720_port
->shadowLCR
& ~UART_LCR_DLAB
;
1692 mos7720_port
->shadowLCR
= data
;
1693 send_mos_cmd(serial
, MOS_WRITE
, number
, 0x03, &data
);
1699 * change_port_settings
1700 * This routine is called to set the UART on the device to match
1701 * the specified new settings.
1703 static void change_port_settings(struct tty_struct
*tty
,
1704 struct moschip_port
*mos7720_port
,
1705 struct ktermios
*old_termios
)
1707 struct usb_serial_port
*port
;
1708 struct usb_serial
*serial
;
1720 if (mos7720_port
== NULL
)
1723 port
= mos7720_port
->port
;
1724 serial
= port
->serial
;
1725 port_number
= port
->number
- port
->serial
->minor
;
1727 dbg("%s - port %d", __func__
, port
->number
);
1729 if (!mos7720_port
->open
) {
1730 dbg("%s - port not opened", __func__
);
1734 dbg("%s: Entering ..........", __func__
);
1736 lData
= UART_LCR_WLEN8
;
1737 lStop
= 0x00; /* 1 stop bit */
1738 lParity
= 0x00; /* No parity */
1740 cflag
= tty
->termios
->c_cflag
;
1741 iflag
= tty
->termios
->c_iflag
;
1743 /* Change the number of bits */
1744 switch (cflag
& CSIZE
) {
1746 lData
= UART_LCR_WLEN5
;
1751 lData
= UART_LCR_WLEN6
;
1756 lData
= UART_LCR_WLEN7
;
1761 lData
= UART_LCR_WLEN8
;
1765 /* Change the Parity bit */
1766 if (cflag
& PARENB
) {
1767 if (cflag
& PARODD
) {
1768 lParity
= UART_LCR_PARITY
;
1769 dbg("%s - parity = odd", __func__
);
1771 lParity
= (UART_LCR_EPAR
| UART_LCR_PARITY
);
1772 dbg("%s - parity = even", __func__
);
1776 dbg("%s - parity = none", __func__
);
1780 lParity
= lParity
| 0x20;
1782 /* Change the Stop bit */
1783 if (cflag
& CSTOPB
) {
1784 lStop
= UART_LCR_STOP
;
1785 dbg("%s - stop bits = 2", __func__
);
1788 dbg("%s - stop bits = 1", __func__
);
1791 #define LCR_BITS_MASK 0x03 /* Mask for bits/char field */
1792 #define LCR_STOP_MASK 0x04 /* Mask for stop bits field */
1793 #define LCR_PAR_MASK 0x38 /* Mask for parity field */
1795 /* Update the LCR with the correct value */
1796 mos7720_port
->shadowLCR
&=
1797 ~(LCR_BITS_MASK
| LCR_STOP_MASK
| LCR_PAR_MASK
);
1798 mos7720_port
->shadowLCR
|= (lData
| lParity
| lStop
);
1801 /* Disable Interrupts */
1803 send_mos_cmd(serial
, MOS_WRITE
, port
->number
- port
->serial
->minor
,
1807 send_mos_cmd(serial
, MOS_WRITE
, port_number
, UART_FCR
, &data
);
1810 send_mos_cmd(serial
, MOS_WRITE
, port_number
, UART_FCR
, &data
);
1812 /* Send the updated LCR value to the mos7720 */
1813 data
= mos7720_port
->shadowLCR
;
1814 send_mos_cmd(serial
, MOS_WRITE
, port_number
, UART_LCR
, &data
);
1817 mos7720_port
->shadowMCR
= data
;
1818 send_mos_cmd(serial
, MOS_WRITE
, port_number
, 0x04, &data
);
1820 send_mos_cmd(serial
, MOS_WRITE
, port_number
, 0x04, &data
);
1822 /* set up the MCR register and send it to the mos7720 */
1823 mos7720_port
->shadowMCR
= UART_MCR_OUT2
;
1825 mos7720_port
->shadowMCR
|= (UART_MCR_DTR
| UART_MCR_RTS
);
1827 if (cflag
& CRTSCTS
) {
1828 mos7720_port
->shadowMCR
|= (UART_MCR_XONANY
);
1829 /* To set hardware flow control to the specified *
1830 * serial port, in SP1/2_CONTROL_REG */
1833 send_mos_cmd(serial
, MOS_WRITE
, MOS_MAX_PORT
,
1837 send_mos_cmd(serial
, MOS_WRITE
, MOS_MAX_PORT
,
1841 mos7720_port
->shadowMCR
&= ~(UART_MCR_XONANY
);
1844 data
= mos7720_port
->shadowMCR
;
1845 send_mos_cmd(serial
, MOS_WRITE
, port_number
, UART_MCR
, &data
);
1847 /* Determine divisor based on baud rate */
1848 baud
= tty_get_baud_rate(tty
);
1850 /* pick a default, any default... */
1851 dbg("Picked default baud...");
1855 if (baud
>= 230400) {
1856 set_higher_rates(mos7720_port
, baud
);
1857 /* Enable Interrupts */
1859 send_mos_cmd(serial
, MOS_WRITE
, port_number
, UART_IER
, &data
);
1863 dbg("%s - baud rate = %d", __func__
, baud
);
1864 status
= send_cmd_write_baud_rate(mos7720_port
, baud
);
1865 /* FIXME: needs to write actual resulting baud back not just
1868 tty_encode_baud_rate(tty
, baud
, baud
);
1869 /* Enable Interrupts */
1871 send_mos_cmd(serial
, MOS_WRITE
, port_number
, UART_IER
, &data
);
1873 if (port
->read_urb
->status
!= -EINPROGRESS
) {
1874 port
->read_urb
->dev
= serial
->dev
;
1876 status
= usb_submit_urb(port
->read_urb
, GFP_ATOMIC
);
1878 dbg("usb_submit_urb(read bulk) failed, status = %d",
1885 * mos7720_set_termios
1886 * this function is called by the tty driver when it wants to change the
1887 * termios structure.
1889 static void mos7720_set_termios(struct tty_struct
*tty
,
1890 struct usb_serial_port
*port
, struct ktermios
*old_termios
)
1894 struct usb_serial
*serial
;
1895 struct moschip_port
*mos7720_port
;
1897 serial
= port
->serial
;
1899 mos7720_port
= usb_get_serial_port_data(port
);
1901 if (mos7720_port
== NULL
)
1904 if (!mos7720_port
->open
) {
1905 dbg("%s - port not opened", __func__
);
1909 dbg("%s\n", "setting termios - ASPIRE");
1911 cflag
= tty
->termios
->c_cflag
;
1913 dbg("%s - cflag %08x iflag %08x", __func__
,
1914 tty
->termios
->c_cflag
,
1915 RELEVANT_IFLAG(tty
->termios
->c_iflag
));
1917 dbg("%s - old cflag %08x old iflag %08x", __func__
,
1918 old_termios
->c_cflag
,
1919 RELEVANT_IFLAG(old_termios
->c_iflag
));
1921 dbg("%s - port %d", __func__
, port
->number
);
1923 /* change the port settings to the new ones specified */
1924 change_port_settings(tty
, mos7720_port
, old_termios
);
1926 if (!port
->read_urb
) {
1927 dbg("%s", "URB KILLED !!!!!");
1931 if (port
->read_urb
->status
!= -EINPROGRESS
) {
1932 port
->read_urb
->dev
= serial
->dev
;
1933 status
= usb_submit_urb(port
->read_urb
, GFP_ATOMIC
);
1935 dbg("usb_submit_urb(read bulk) failed, status = %d",
1942 * get_lsr_info - get line status register info
1944 * Purpose: Let user call ioctl() to get info when the UART physically
1945 * is emptied. On bus types like RS485, the transmitter must
1946 * release the bus after transmitting. This must be done when
1947 * the transmit shift register is empty, not be done when the
1948 * transmit holding register is empty. This functionality
1949 * allows an RS485 driver to be written in user space.
1951 static int get_lsr_info(struct tty_struct
*tty
,
1952 struct moschip_port
*mos7720_port
, unsigned int __user
*value
)
1954 struct usb_serial_port
*port
= tty
->driver_data
;
1955 unsigned int result
= 0;
1956 unsigned char data
= 0;
1957 int port_number
= port
->number
- port
->serial
->minor
;
1960 count
= mos7720_chars_in_buffer(tty
);
1962 send_mos_cmd(port
->serial
, MOS_READ
, port_number
,
1964 if ((data
& (UART_LSR_TEMT
| UART_LSR_THRE
))
1965 == (UART_LSR_TEMT
| UART_LSR_THRE
)) {
1966 dbg("%s -- Empty", __func__
);
1967 result
= TIOCSER_TEMT
;
1970 if (copy_to_user(value
, &result
, sizeof(int)))
1975 static int mos7720_tiocmget(struct tty_struct
*tty
, struct file
*file
)
1977 struct usb_serial_port
*port
= tty
->driver_data
;
1978 struct moschip_port
*mos7720_port
= usb_get_serial_port_data(port
);
1979 unsigned int result
= 0;
1983 dbg("%s - port %d", __func__
, port
->number
);
1985 mcr
= mos7720_port
->shadowMCR
;
1986 msr
= mos7720_port
->shadowMSR
;
1988 result
= ((mcr
& UART_MCR_DTR
) ? TIOCM_DTR
: 0) /* 0x002 */
1989 | ((mcr
& UART_MCR_RTS
) ? TIOCM_RTS
: 0) /* 0x004 */
1990 | ((msr
& UART_MSR_CTS
) ? TIOCM_CTS
: 0) /* 0x020 */
1991 | ((msr
& UART_MSR_DCD
) ? TIOCM_CAR
: 0) /* 0x040 */
1992 | ((msr
& UART_MSR_RI
) ? TIOCM_RI
: 0) /* 0x080 */
1993 | ((msr
& UART_MSR_DSR
) ? TIOCM_DSR
: 0); /* 0x100 */
1995 dbg("%s -- %x", __func__
, result
);
2000 static int mos7720_tiocmset(struct tty_struct
*tty
, struct file
*file
,
2001 unsigned int set
, unsigned int clear
)
2003 struct usb_serial_port
*port
= tty
->driver_data
;
2004 struct moschip_port
*mos7720_port
= usb_get_serial_port_data(port
);
2008 dbg("%s - port %d", __func__
, port
->number
);
2009 dbg("he was at tiocmget");
2011 mcr
= mos7720_port
->shadowMCR
;
2013 if (set
& TIOCM_RTS
)
2014 mcr
|= UART_MCR_RTS
;
2015 if (set
& TIOCM_DTR
)
2016 mcr
|= UART_MCR_DTR
;
2017 if (set
& TIOCM_LOOP
)
2018 mcr
|= UART_MCR_LOOP
;
2020 if (clear
& TIOCM_RTS
)
2021 mcr
&= ~UART_MCR_RTS
;
2022 if (clear
& TIOCM_DTR
)
2023 mcr
&= ~UART_MCR_DTR
;
2024 if (clear
& TIOCM_LOOP
)
2025 mcr
&= ~UART_MCR_LOOP
;
2027 mos7720_port
->shadowMCR
= mcr
;
2028 lmcr
= mos7720_port
->shadowMCR
;
2030 send_mos_cmd(port
->serial
, MOS_WRITE
,
2031 port
->number
- port
->serial
->minor
, UART_MCR
, &lmcr
);
2036 static int set_modem_info(struct moschip_port
*mos7720_port
, unsigned int cmd
,
2037 unsigned int __user
*value
)
2043 struct usb_serial_port
*port
;
2045 if (mos7720_port
== NULL
)
2048 port
= (struct usb_serial_port
*)mos7720_port
->port
;
2049 mcr
= mos7720_port
->shadowMCR
;
2051 if (copy_from_user(&arg
, value
, sizeof(int)))
2056 if (arg
& TIOCM_RTS
)
2057 mcr
|= UART_MCR_RTS
;
2058 if (arg
& TIOCM_DTR
)
2059 mcr
|= UART_MCR_RTS
;
2060 if (arg
& TIOCM_LOOP
)
2061 mcr
|= UART_MCR_LOOP
;
2065 if (arg
& TIOCM_RTS
)
2066 mcr
&= ~UART_MCR_RTS
;
2067 if (arg
& TIOCM_DTR
)
2068 mcr
&= ~UART_MCR_RTS
;
2069 if (arg
& TIOCM_LOOP
)
2070 mcr
&= ~UART_MCR_LOOP
;
2075 mos7720_port
->shadowMCR
= mcr
;
2077 data
= mos7720_port
->shadowMCR
;
2078 send_mos_cmd(port
->serial
, MOS_WRITE
,
2079 port
->number
- port
->serial
->minor
, UART_MCR
, &data
);
2084 static int get_serial_info(struct moschip_port
*mos7720_port
,
2085 struct serial_struct __user
*retinfo
)
2087 struct serial_struct tmp
;
2092 memset(&tmp
, 0, sizeof(tmp
));
2094 tmp
.type
= PORT_16550A
;
2095 tmp
.line
= mos7720_port
->port
->serial
->minor
;
2096 tmp
.port
= mos7720_port
->port
->number
;
2098 tmp
.flags
= ASYNC_SKIP_TEST
| ASYNC_AUTO_IRQ
;
2099 tmp
.xmit_fifo_size
= NUM_URBS
* URB_TRANSFER_BUFFER_SIZE
;
2100 tmp
.baud_base
= 9600;
2101 tmp
.close_delay
= 5*HZ
;
2102 tmp
.closing_wait
= 30*HZ
;
2104 if (copy_to_user(retinfo
, &tmp
, sizeof(*retinfo
)))
2109 static int mos7720_ioctl(struct tty_struct
*tty
, struct file
*file
,
2110 unsigned int cmd
, unsigned long arg
)
2112 struct usb_serial_port
*port
= tty
->driver_data
;
2113 struct moschip_port
*mos7720_port
;
2114 struct async_icount cnow
;
2115 struct async_icount cprev
;
2116 struct serial_icounter_struct icount
;
2118 mos7720_port
= usb_get_serial_port_data(port
);
2119 if (mos7720_port
== NULL
)
2122 dbg("%s - port %d, cmd = 0x%x", __func__
, port
->number
, cmd
);
2126 dbg("%s (%d) TIOCSERGETLSR", __func__
, port
->number
);
2127 return get_lsr_info(tty
, mos7720_port
,
2128 (unsigned int __user
*)arg
);
2131 /* FIXME: These should be using the mode methods */
2134 dbg("%s (%d) TIOCMSET/TIOCMBIC/TIOCMSET",
2135 __func__
, port
->number
);
2136 return set_modem_info(mos7720_port
, cmd
,
2137 (unsigned int __user
*)arg
);
2140 dbg("%s (%d) TIOCGSERIAL", __func__
, port
->number
);
2141 return get_serial_info(mos7720_port
,
2142 (struct serial_struct __user
*)arg
);
2145 dbg("%s (%d) TIOCMIWAIT", __func__
, port
->number
);
2146 cprev
= mos7720_port
->icount
;
2148 if (signal_pending(current
))
2149 return -ERESTARTSYS
;
2150 cnow
= mos7720_port
->icount
;
2151 if (cnow
.rng
== cprev
.rng
&& cnow
.dsr
== cprev
.dsr
&&
2152 cnow
.dcd
== cprev
.dcd
&& cnow
.cts
== cprev
.cts
)
2153 return -EIO
; /* no change => error */
2154 if (((arg
& TIOCM_RNG
) && (cnow
.rng
!= cprev
.rng
)) ||
2155 ((arg
& TIOCM_DSR
) && (cnow
.dsr
!= cprev
.dsr
)) ||
2156 ((arg
& TIOCM_CD
) && (cnow
.dcd
!= cprev
.dcd
)) ||
2157 ((arg
& TIOCM_CTS
) && (cnow
.cts
!= cprev
.cts
))) {
2166 cnow
= mos7720_port
->icount
;
2167 icount
.cts
= cnow
.cts
;
2168 icount
.dsr
= cnow
.dsr
;
2169 icount
.rng
= cnow
.rng
;
2170 icount
.dcd
= cnow
.dcd
;
2171 icount
.rx
= cnow
.rx
;
2172 icount
.tx
= cnow
.tx
;
2173 icount
.frame
= cnow
.frame
;
2174 icount
.overrun
= cnow
.overrun
;
2175 icount
.parity
= cnow
.parity
;
2176 icount
.brk
= cnow
.brk
;
2177 icount
.buf_overrun
= cnow
.buf_overrun
;
2179 dbg("%s (%d) TIOCGICOUNT RX=%d, TX=%d", __func__
,
2180 port
->number
, icount
.rx
, icount
.tx
);
2181 if (copy_to_user((void __user
*)arg
, &icount
, sizeof(icount
)))
2186 return -ENOIOCTLCMD
;
2189 static int mos7720_startup(struct usb_serial
*serial
)
2191 struct moschip_port
*mos7720_port
;
2192 struct usb_device
*dev
;
2195 u16 product
= le16_to_cpu(serial
->dev
->descriptor
.idProduct
);
2198 dbg("%s: Entering ..........", __func__
);
2201 dbg("Invalid Handler");
2208 * The 7715 uses the first bulk in/out endpoint pair for the parallel
2209 * port, and the second for the serial port. Because the usbserial core
2210 * assumes both pairs are serial ports, we must engage in a bit of
2211 * subterfuge and swap the pointers for ports 0 and 1 in order to make
2212 * port 0 point to the serial port. However, both moschip devices use a
2213 * single interrupt-in endpoint for both ports (as mentioned a little
2214 * further down), and this endpoint was assigned to port 0. So after
2215 * the swap, we must copy the interrupt endpoint elements from port 1
2216 * (as newly assigned) to port 0, and null out port 1 pointers.
2218 if (product
== MOSCHIP_DEVICE_ID_7715
) {
2219 struct usb_serial_port
*tmp
= serial
->port
[0];
2220 serial
->port
[0] = serial
->port
[1];
2221 serial
->port
[1] = tmp
;
2222 serial
->port
[0]->interrupt_in_urb
= tmp
->interrupt_in_urb
;
2223 serial
->port
[0]->interrupt_in_buffer
= tmp
->interrupt_in_buffer
;
2224 serial
->port
[0]->interrupt_in_endpointAddress
=
2225 tmp
->interrupt_in_endpointAddress
;
2226 serial
->port
[1]->interrupt_in_urb
= NULL
;
2227 serial
->port
[1]->interrupt_in_buffer
= NULL
;
2231 /* set up serial port private structures */
2232 for (i
= 0; i
< serial
->num_ports
; ++i
) {
2233 mos7720_port
= kzalloc(sizeof(struct moschip_port
), GFP_KERNEL
);
2234 if (mos7720_port
== NULL
) {
2235 dev_err(&dev
->dev
, "%s - Out of memory\n", __func__
);
2239 /* Initialize all port interrupt end point to port 0 int
2240 * endpoint. Our device has only one interrupt endpoint
2241 * common to all ports */
2242 serial
->port
[i
]->interrupt_in_endpointAddress
=
2243 serial
->port
[0]->interrupt_in_endpointAddress
;
2245 mos7720_port
->port
= serial
->port
[i
];
2246 usb_set_serial_port_data(serial
->port
[i
], mos7720_port
);
2248 dbg("port number is %d", serial
->port
[i
]->number
);
2249 dbg("serial number is %d", serial
->minor
);
2253 /* setting configuration feature to one */
2254 usb_control_msg(serial
->dev
, usb_sndctrlpipe(serial
->dev
, 0),
2255 (__u8
)0x03, 0x00, 0x01, 0x00, NULL
, 0x00, 5*HZ
);
2257 /* start the interrupt urb */
2258 ret_val
= usb_submit_urb(serial
->port
[0]->interrupt_in_urb
, GFP_KERNEL
);
2261 "%s - Error %d submitting control urb\n",
2264 #ifdef CONFIG_USB_SERIAL_MOS7715_PARPORT
2265 if (product
== MOSCHIP_DEVICE_ID_7715
) {
2266 ret_val
= mos7715_parport_init(serial
);
2271 /* LSR For Port 1 */
2272 send_mos_cmd(serial
, MOS_READ
, 0x00, UART_LSR
, &data
);
2273 dbg("LSR:%x", data
);
2275 /* LSR For Port 2 */
2276 send_mos_cmd(serial
, MOS_READ
, 0x01, UART_LSR
, &data
);
2277 dbg("LSR:%x", data
);
2282 static void mos7720_release(struct usb_serial
*serial
)
2286 #ifdef CONFIG_USB_SERIAL_MOS7715_PARPORT
2287 /* close the parallel port */
2289 if (le16_to_cpu(serial
->dev
->descriptor
.idProduct
)
2290 == MOSCHIP_DEVICE_ID_7715
) {
2291 struct urbtracker
*urbtrack
;
2292 unsigned long flags
;
2293 struct mos7715_parport
*mos_parport
=
2294 usb_get_serial_data(serial
);
2296 /* prevent NULL ptr dereference in port callbacks */
2297 spin_lock(&release_lock
);
2298 mos_parport
->pp
->private_data
= NULL
;
2299 spin_unlock(&release_lock
);
2301 /* wait for synchronous usb calls to return */
2302 if (mos_parport
->msg_pending
)
2303 wait_for_completion_timeout(&mos_parport
->syncmsg_compl
,
2306 parport_remove_port(mos_parport
->pp
);
2307 usb_set_serial_data(serial
, NULL
);
2308 mos_parport
->serial
= NULL
;
2310 /* if tasklet currently scheduled, wait for it to complete */
2311 tasklet_kill(&mos_parport
->urb_tasklet
);
2313 /* unlink any urbs sent by the tasklet */
2314 spin_lock_irqsave(&mos_parport
->listlock
, flags
);
2315 list_for_each_entry(urbtrack
,
2316 &mos_parport
->active_urbs
,
2318 usb_unlink_urb(urbtrack
->urb
);
2319 spin_unlock_irqrestore(&mos_parport
->listlock
, flags
);
2321 kref_put(&mos_parport
->ref_count
, destroy_mos_parport
);
2324 /* free private structure allocated for serial port */
2325 for (i
= 0; i
< serial
->num_ports
; ++i
)
2326 kfree(usb_get_serial_port_data(serial
->port
[i
]));
2329 static struct usb_driver usb_driver
= {
2330 .name
= "moschip7720",
2331 .probe
= usb_serial_probe
,
2332 .disconnect
= usb_serial_disconnect
,
2333 .id_table
= moschip_port_id_table
,
2337 static struct usb_serial_driver moschip7720_2port_driver
= {
2339 .owner
= THIS_MODULE
,
2340 .name
= "moschip7720",
2342 .description
= "Moschip 2 port adapter",
2343 .usb_driver
= &usb_driver
,
2344 .id_table
= moschip_port_id_table
,
2345 .calc_num_ports
= mos77xx_calc_num_ports
,
2346 .open
= mos7720_open
,
2347 .close
= mos7720_close
,
2348 .throttle
= mos7720_throttle
,
2349 .unthrottle
= mos7720_unthrottle
,
2350 .probe
= mos77xx_probe
,
2351 .attach
= mos7720_startup
,
2352 .release
= mos7720_release
,
2353 .ioctl
= mos7720_ioctl
,
2354 .tiocmget
= mos7720_tiocmget
,
2355 .tiocmset
= mos7720_tiocmset
,
2356 .set_termios
= mos7720_set_termios
,
2357 .write
= mos7720_write
,
2358 .write_room
= mos7720_write_room
,
2359 .chars_in_buffer
= mos7720_chars_in_buffer
,
2360 .break_ctl
= mos7720_break
,
2361 .read_bulk_callback
= mos7720_bulk_in_callback
,
2362 .read_int_callback
= NULL
/* dynamically assigned in probe() */
2365 static int __init
moschip7720_init(void)
2369 dbg("%s: Entering ..........", __func__
);
2371 /* Register with the usb serial */
2372 retval
= usb_serial_register(&moschip7720_2port_driver
);
2374 goto failed_port_device_register
;
2376 printk(KERN_INFO KBUILD_MODNAME
": " DRIVER_VERSION
":"
2379 /* Register with the usb */
2380 retval
= usb_register(&usb_driver
);
2382 goto failed_usb_register
;
2386 failed_usb_register
:
2387 usb_serial_deregister(&moschip7720_2port_driver
);
2389 failed_port_device_register
:
2393 static void __exit
moschip7720_exit(void)
2395 usb_deregister(&usb_driver
);
2396 usb_serial_deregister(&moschip7720_2port_driver
);
2399 module_init(moschip7720_init
);
2400 module_exit(moschip7720_exit
);
2402 /* Module information */
2403 MODULE_AUTHOR(DRIVER_AUTHOR
);
2404 MODULE_DESCRIPTION(DRIVER_DESC
);
2405 MODULE_LICENSE("GPL");
2407 module_param(debug
, bool, S_IRUGO
| S_IWUSR
);
2408 MODULE_PARM_DESC(debug
, "Debug enabled or not");