aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/serial/mos7720.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/serial/mos7720.c')
-rw-r--r--drivers/usb/serial/mos7720.c1130
1 files changed, 810 insertions, 320 deletions
diff --git a/drivers/usb/serial/mos7720.c b/drivers/usb/serial/mos7720.c
index 0d47f2c4d59f..30922a7e3347 100644
--- a/drivers/usb/serial/mos7720.c
+++ b/drivers/usb/serial/mos7720.c
@@ -34,21 +34,18 @@
34#include <linux/usb.h> 34#include <linux/usb.h>
35#include <linux/usb/serial.h> 35#include <linux/usb/serial.h>
36#include <linux/uaccess.h> 36#include <linux/uaccess.h>
37 37#include <linux/parport.h>
38 38
39/* 39/*
40 * Version Information 40 * Version Information
41 */ 41 */
42#define DRIVER_VERSION "1.0.0.4F" 42#define DRIVER_VERSION "2.1"
43#define DRIVER_AUTHOR "Aspire Communications pvt Ltd." 43#define DRIVER_AUTHOR "Aspire Communications pvt Ltd."
44#define DRIVER_DESC "Moschip USB Serial Driver" 44#define DRIVER_DESC "Moschip USB Serial Driver"
45 45
46/* default urb timeout */ 46/* default urb timeout */
47#define MOS_WDR_TIMEOUT (HZ * 5) 47#define MOS_WDR_TIMEOUT (HZ * 5)
48 48
49#define MOS_PORT1 0x0200
50#define MOS_PORT2 0x0300
51#define MOS_VENREG 0x0000
52#define MOS_MAX_PORT 0x02 49#define MOS_MAX_PORT 0x02
53#define MOS_WRITE 0x0E 50#define MOS_WRITE 0x0E
54#define MOS_READ 0x0D 51#define MOS_READ 0x0D
@@ -63,7 +60,7 @@
63#define NUM_URBS 16 /* URB Count */ 60#define NUM_URBS 16 /* URB Count */
64#define URB_TRANSFER_BUFFER_SIZE 32 /* URB Size */ 61#define URB_TRANSFER_BUFFER_SIZE 32 /* URB Size */
65 62
66/* This structure holds all of the local port information */ 63/* This structure holds all of the local serial port information */
67struct moschip_port { 64struct moschip_port {
68 __u8 shadowLCR; /* last LCR value received */ 65 __u8 shadowLCR; /* last LCR value received */
69 __u8 shadowMCR; /* last MCR value received */ 66 __u8 shadowMCR; /* last MCR value received */
@@ -74,11 +71,6 @@ struct moschip_port {
74 struct urb *write_urb_pool[NUM_URBS]; 71 struct urb *write_urb_pool[NUM_URBS];
75}; 72};
76 73
77/* This structure holds all of the individual serial device information */
78struct moschip_serial {
79 int interrupt_started;
80};
81
82static int debug; 74static int debug;
83 75
84static struct usb_serial_driver moschip7720_2port_driver; 76static struct usb_serial_driver moschip7720_2port_driver;
@@ -94,6 +86,658 @@ static const struct usb_device_id moschip_port_id_table[] = {
94}; 86};
95MODULE_DEVICE_TABLE(usb, moschip_port_id_table); 87MODULE_DEVICE_TABLE(usb, moschip_port_id_table);
96 88
89#ifdef CONFIG_USB_SERIAL_MOS7715_PARPORT
90
91/* initial values for parport regs */
92#define DCR_INIT_VAL 0x0c /* SLCTIN, nINIT */
93#define ECR_INIT_VAL 0x00 /* SPP mode */
94
95struct urbtracker {
96 struct mos7715_parport *mos_parport;
97 struct list_head urblist_entry;
98 struct kref ref_count;
99 struct urb *urb;
100};
101
102enum mos7715_pp_modes {
103 SPP = 0<<5,
104 PS2 = 1<<5, /* moschip calls this 'NIBBLE' mode */
105 PPF = 2<<5, /* moschip calls this 'CB-FIFO mode */
106};
107
108struct mos7715_parport {
109 struct parport *pp; /* back to containing struct */
110 struct kref ref_count; /* to instance of this struct */
111 struct list_head deferred_urbs; /* list deferred async urbs */
112 struct list_head active_urbs; /* list async urbs in flight */
113 spinlock_t listlock; /* protects list access */
114 bool msg_pending; /* usb sync call pending */
115 struct completion syncmsg_compl; /* usb sync call completed */
116 struct tasklet_struct urb_tasklet; /* for sending deferred urbs */
117 struct usb_serial *serial; /* back to containing struct */
118 __u8 shadowECR; /* parallel port regs... */
119 __u8 shadowDCR;
120 atomic_t shadowDSR; /* updated in int-in callback */
121};
122
123/* lock guards against dereferencing NULL ptr in parport ops callbacks */
124static DEFINE_SPINLOCK(release_lock);
125
126#endif /* CONFIG_USB_SERIAL_MOS7715_PARPORT */
127
128static const unsigned int dummy; /* for clarity in register access fns */
129
130enum mos_regs {
131 THR, /* serial port regs */
132 RHR,
133 IER,
134 FCR,
135 ISR,
136 LCR,
137 MCR,
138 LSR,
139 MSR,
140 SPR,
141 DLL,
142 DLM,
143 DPR, /* parallel port regs */
144 DSR,
145 DCR,
146 ECR,
147 SP1_REG, /* device control regs */
148 SP2_REG, /* serial port 2 (7720 only) */
149 PP_REG,
150 SP_CONTROL_REG,
151};
152
153/*
154 * Return the correct value for the Windex field of the setup packet
155 * for a control endpoint message. See the 7715 datasheet.
156 */
157static inline __u16 get_reg_index(enum mos_regs reg)
158{
159 static const __u16 mos7715_index_lookup_table[] = {
160 0x00, /* THR */
161 0x00, /* RHR */
162 0x01, /* IER */
163 0x02, /* FCR */
164 0x02, /* ISR */
165 0x03, /* LCR */
166 0x04, /* MCR */
167 0x05, /* LSR */
168 0x06, /* MSR */
169 0x07, /* SPR */
170 0x00, /* DLL */
171 0x01, /* DLM */
172 0x00, /* DPR */
173 0x01, /* DSR */
174 0x02, /* DCR */
175 0x0a, /* ECR */
176 0x01, /* SP1_REG */
177 0x02, /* SP2_REG (7720 only) */
178 0x04, /* PP_REG (7715 only) */
179 0x08, /* SP_CONTROL_REG */
180 };
181 return mos7715_index_lookup_table[reg];
182}
183
184/*
185 * Return the correct value for the upper byte of the Wvalue field of
186 * the setup packet for a control endpoint message.
187 */
188static inline __u16 get_reg_value(enum mos_regs reg,
189 unsigned int serial_portnum)
190{
191 if (reg >= SP1_REG) /* control reg */
192 return 0x0000;
193
194 else if (reg >= DPR) /* parallel port reg (7715 only) */
195 return 0x0100;
196
197 else /* serial port reg */
198 return (serial_portnum + 2) << 8;
199}
200
201/*
202 * Write data byte to the specified device register. The data is embedded in
203 * the value field of the setup packet. serial_portnum is ignored for registers
204 * not specific to a particular serial port.
205 */
206static int write_mos_reg(struct usb_serial *serial, unsigned int serial_portnum,
207 enum mos_regs reg, __u8 data)
208{
209 struct usb_device *usbdev = serial->dev;
210 unsigned int pipe = usb_sndctrlpipe(usbdev, 0);
211 __u8 request = (__u8)0x0e;
212 __u8 requesttype = (__u8)0x40;
213 __u16 index = get_reg_index(reg);
214 __u16 value = get_reg_value(reg, serial_portnum) + data;
215 int status = usb_control_msg(usbdev, pipe, request, requesttype, value,
216 index, NULL, 0, MOS_WDR_TIMEOUT);
217 if (status < 0)
218 dev_err(&usbdev->dev,
219 "mos7720: usb_control_msg() failed: %d", status);
220 return status;
221}
222
223/*
224 * Read data byte from the specified device register. The data returned by the
225 * device is embedded in the value field of the setup packet. serial_portnum is
226 * ignored for registers that are not specific to a particular serial port.
227 */
228static int read_mos_reg(struct usb_serial *serial, unsigned int serial_portnum,
229 enum mos_regs reg, __u8 *data)
230{
231 struct usb_device *usbdev = serial->dev;
232 unsigned int pipe = usb_rcvctrlpipe(usbdev, 0);
233 __u8 request = (__u8)0x0d;
234 __u8 requesttype = (__u8)0xc0;
235 __u16 index = get_reg_index(reg);
236 __u16 value = get_reg_value(reg, serial_portnum);
237 int status = usb_control_msg(usbdev, pipe, request, requesttype, value,
238 index, data, 1, MOS_WDR_TIMEOUT);
239 if (status < 0)
240 dev_err(&usbdev->dev,
241 "mos7720: usb_control_msg() failed: %d", status);
242 return status;
243}
244
245#ifdef CONFIG_USB_SERIAL_MOS7715_PARPORT
246
247static inline int mos7715_change_mode(struct mos7715_parport *mos_parport,
248 enum mos7715_pp_modes mode)
249{
250 mos_parport->shadowECR = mode;
251 write_mos_reg(mos_parport->serial, dummy, ECR, mos_parport->shadowECR);
252 return 0;
253}
254
255static void destroy_mos_parport(struct kref *kref)
256{
257 struct mos7715_parport *mos_parport =
258 container_of(kref, struct mos7715_parport, ref_count);
259
260 dbg("%s called", __func__);
261 kfree(mos_parport);
262}
263
264static void destroy_urbtracker(struct kref *kref)
265{
266 struct urbtracker *urbtrack =
267 container_of(kref, struct urbtracker, ref_count);
268 struct mos7715_parport *mos_parport = urbtrack->mos_parport;
269 dbg("%s called", __func__);
270 usb_free_urb(urbtrack->urb);
271 kfree(urbtrack);
272 kref_put(&mos_parport->ref_count, destroy_mos_parport);
273}
274
275/*
276 * This runs as a tasklet when sending an urb in a non-blocking parallel
277 * port callback had to be deferred because the disconnect mutex could not be
278 * obtained at the time.
279 */
280static void send_deferred_urbs(unsigned long _mos_parport)
281{
282 int ret_val;
283 unsigned long flags;
284 struct mos7715_parport *mos_parport = (void *)_mos_parport;
285 struct urbtracker *urbtrack;
286 struct list_head *cursor, *next;
287
288 dbg("%s called", __func__);
289
290 /* if release function ran, game over */
291 if (unlikely(mos_parport->serial == NULL))
292 return;
293
294 /* try again to get the mutex */
295 if (!mutex_trylock(&mos_parport->serial->disc_mutex)) {
296 dbg("%s: rescheduling tasklet", __func__);
297 tasklet_schedule(&mos_parport->urb_tasklet);
298 return;
299 }
300
301 /* if device disconnected, game over */
302 if (unlikely(mos_parport->serial->disconnected)) {
303 mutex_unlock(&mos_parport->serial->disc_mutex);
304 return;
305 }
306
307 spin_lock_irqsave(&mos_parport->listlock, flags);
308 if (list_empty(&mos_parport->deferred_urbs)) {
309 spin_unlock_irqrestore(&mos_parport->listlock, flags);
310 mutex_unlock(&mos_parport->serial->disc_mutex);
311 dbg("%s: deferred_urbs list empty", __func__);
312 return;
313 }
314
315 /* move contents of deferred_urbs list to active_urbs list and submit */
316 list_for_each_safe(cursor, next, &mos_parport->deferred_urbs)
317 list_move_tail(cursor, &mos_parport->active_urbs);
318 list_for_each_entry(urbtrack, &mos_parport->active_urbs,
319 urblist_entry) {
320 ret_val = usb_submit_urb(urbtrack->urb, GFP_ATOMIC);
321 dbg("%s: urb submitted", __func__);
322 if (ret_val) {
323 dev_err(&mos_parport->serial->dev->dev,
324 "usb_submit_urb() failed: %d", ret_val);
325 list_del(&urbtrack->urblist_entry);
326 kref_put(&urbtrack->ref_count, destroy_urbtracker);
327 }
328 }
329 spin_unlock_irqrestore(&mos_parport->listlock, flags);
330 mutex_unlock(&mos_parport->serial->disc_mutex);
331}
332
333/* callback for parallel port control urbs submitted asynchronously */
334static void async_complete(struct urb *urb)
335{
336 struct urbtracker *urbtrack = urb->context;
337 int status = urb->status;
338 dbg("%s called", __func__);
339 if (unlikely(status))
340 dbg("%s - nonzero urb status received: %d", __func__, status);
341
342 /* remove the urbtracker from the active_urbs list */
343 spin_lock(&urbtrack->mos_parport->listlock);
344 list_del(&urbtrack->urblist_entry);
345 spin_unlock(&urbtrack->mos_parport->listlock);
346 kref_put(&urbtrack->ref_count, destroy_urbtracker);
347}
348
349static int write_parport_reg_nonblock(struct mos7715_parport *mos_parport,
350 enum mos_regs reg, __u8 data)
351{
352 struct urbtracker *urbtrack;
353 int ret_val;
354 unsigned long flags;
355 struct usb_ctrlrequest setup;
356 struct usb_serial *serial = mos_parport->serial;
357 struct usb_device *usbdev = serial->dev;
358 dbg("%s called", __func__);
359
360 /* create and initialize the control urb and containing urbtracker */
361 urbtrack = kmalloc(sizeof(struct urbtracker), GFP_ATOMIC);
362 if (urbtrack == NULL) {
363 dev_err(&usbdev->dev, "out of memory");
364 return -ENOMEM;
365 }
366 kref_get(&mos_parport->ref_count);
367 urbtrack->mos_parport = mos_parport;
368 urbtrack->urb = usb_alloc_urb(0, GFP_ATOMIC);
369 if (urbtrack->urb == NULL) {
370 dev_err(&usbdev->dev, "out of urbs");
371 kfree(urbtrack);
372 return -ENOMEM;
373 }
374 setup.bRequestType = (__u8)0x40;
375 setup.bRequest = (__u8)0x0e;
376 setup.wValue = get_reg_value(reg, dummy);
377 setup.wIndex = get_reg_index(reg);
378 setup.wLength = 0;
379 usb_fill_control_urb(urbtrack->urb, usbdev,
380 usb_sndctrlpipe(usbdev, 0),
381 (unsigned char *)&setup,
382 NULL, 0, async_complete, urbtrack);
383 kref_init(&urbtrack->ref_count);
384 INIT_LIST_HEAD(&urbtrack->urblist_entry);
385
386 /*
387 * get the disconnect mutex, or add tracker to the deferred_urbs list
388 * and schedule a tasklet to try again later
389 */
390 if (!mutex_trylock(&serial->disc_mutex)) {
391 spin_lock_irqsave(&mos_parport->listlock, flags);
392 list_add_tail(&urbtrack->urblist_entry,
393 &mos_parport->deferred_urbs);
394 spin_unlock_irqrestore(&mos_parport->listlock, flags);
395 tasklet_schedule(&mos_parport->urb_tasklet);
396 dbg("tasklet scheduled");
397 return 0;
398 }
399
400 /* bail if device disconnected */
401 if (serial->disconnected) {
402 kref_put(&urbtrack->ref_count, destroy_urbtracker);
403 mutex_unlock(&serial->disc_mutex);
404 return -ENODEV;
405 }
406
407 /* add the tracker to the active_urbs list and submit */
408 spin_lock_irqsave(&mos_parport->listlock, flags);
409 list_add_tail(&urbtrack->urblist_entry, &mos_parport->active_urbs);
410 spin_unlock_irqrestore(&mos_parport->listlock, flags);
411 ret_val = usb_submit_urb(urbtrack->urb, GFP_ATOMIC);
412 mutex_unlock(&serial->disc_mutex);
413 if (ret_val) {
414 dev_err(&usbdev->dev,
415 "%s: submit_urb() failed: %d", __func__, ret_val);
416 spin_lock_irqsave(&mos_parport->listlock, flags);
417 list_del(&urbtrack->urblist_entry);
418 spin_unlock_irqrestore(&mos_parport->listlock, flags);
419 kref_put(&urbtrack->ref_count, destroy_urbtracker);
420 return ret_val;
421 }
422 return 0;
423}
424
425/*
426 * This is the the common top part of all parallel port callback operations that
427 * send synchronous messages to the device. This implements convoluted locking
428 * that avoids two scenarios: (1) a port operation is called after usbserial
429 * has called our release function, at which point struct mos7715_parport has
430 * been destroyed, and (2) the device has been disconnected, but usbserial has
431 * not called the release function yet because someone has a serial port open.
432 * The shared release_lock prevents the first, and the mutex and disconnected
433 * flag maintained by usbserial covers the second. We also use the msg_pending
434 * flag to ensure that all synchronous usb messgage calls have completed before
435 * our release function can return.
436 */
437static int parport_prologue(struct parport *pp)
438{
439 struct mos7715_parport *mos_parport;
440
441 spin_lock(&release_lock);
442 mos_parport = pp->private_data;
443 if (unlikely(mos_parport == NULL)) {
444 /* release fn called, port struct destroyed */
445 spin_unlock(&release_lock);
446 return -1;
447 }
448 mos_parport->msg_pending = true; /* synch usb call pending */
449 INIT_COMPLETION(mos_parport->syncmsg_compl);
450 spin_unlock(&release_lock);
451
452 mutex_lock(&mos_parport->serial->disc_mutex);
453 if (mos_parport->serial->disconnected) {
454 /* device disconnected */
455 mutex_unlock(&mos_parport->serial->disc_mutex);
456 mos_parport->msg_pending = false;
457 complete(&mos_parport->syncmsg_compl);
458 return -1;
459 }
460
461 return 0;
462}
463
464/*
465 * This is the the common bottom part of all parallel port functions that send
466 * synchronous messages to the device.
467 */
468static inline void parport_epilogue(struct parport *pp)
469{
470 struct mos7715_parport *mos_parport = pp->private_data;
471 mutex_unlock(&mos_parport->serial->disc_mutex);
472 mos_parport->msg_pending = false;
473 complete(&mos_parport->syncmsg_compl);
474}
475
476static void parport_mos7715_write_data(struct parport *pp, unsigned char d)
477{
478 struct mos7715_parport *mos_parport = pp->private_data;
479 dbg("%s called: %2.2x", __func__, d);
480 if (parport_prologue(pp) < 0)
481 return;
482 mos7715_change_mode(mos_parport, SPP);
483 write_mos_reg(mos_parport->serial, dummy, DPR, (__u8)d);
484 parport_epilogue(pp);
485}
486
487static unsigned char parport_mos7715_read_data(struct parport *pp)
488{
489 struct mos7715_parport *mos_parport = pp->private_data;
490 unsigned char d;
491 dbg("%s called", __func__);
492 if (parport_prologue(pp) < 0)
493 return 0;
494 read_mos_reg(mos_parport->serial, dummy, DPR, &d);
495 parport_epilogue(pp);
496 return d;
497}
498
499static void parport_mos7715_write_control(struct parport *pp, unsigned char d)
500{
501 struct mos7715_parport *mos_parport = pp->private_data;
502 __u8 data;
503 dbg("%s called: %2.2x", __func__, d);
504 if (parport_prologue(pp) < 0)
505 return;
506 data = ((__u8)d & 0x0f) | (mos_parport->shadowDCR & 0xf0);
507 write_mos_reg(mos_parport->serial, dummy, DCR, data);
508 mos_parport->shadowDCR = data;
509 parport_epilogue(pp);
510}
511
512static unsigned char parport_mos7715_read_control(struct parport *pp)
513{
514 struct mos7715_parport *mos_parport = pp->private_data;
515 __u8 dcr;
516 dbg("%s called", __func__);
517 spin_lock(&release_lock);
518 mos_parport = pp->private_data;
519 if (unlikely(mos_parport == NULL)) {
520 spin_unlock(&release_lock);
521 return 0;
522 }
523 dcr = mos_parport->shadowDCR & 0x0f;
524 spin_unlock(&release_lock);
525 return dcr;
526}
527
528static unsigned char parport_mos7715_frob_control(struct parport *pp,
529 unsigned char mask,
530 unsigned char val)
531{
532 struct mos7715_parport *mos_parport = pp->private_data;
533 __u8 dcr;
534 dbg("%s called", __func__);
535 mask &= 0x0f;
536 val &= 0x0f;
537 if (parport_prologue(pp) < 0)
538 return 0;
539 mos_parport->shadowDCR = (mos_parport->shadowDCR & (~mask)) ^ val;
540 write_mos_reg(mos_parport->serial, dummy, DCR, mos_parport->shadowDCR);
541 dcr = mos_parport->shadowDCR & 0x0f;
542 parport_epilogue(pp);
543 return dcr;
544}
545
546static unsigned char parport_mos7715_read_status(struct parport *pp)
547{
548 unsigned char status;
549 struct mos7715_parport *mos_parport = pp->private_data;
550 dbg("%s called", __func__);
551 spin_lock(&release_lock);
552 mos_parport = pp->private_data;
553 if (unlikely(mos_parport == NULL)) { /* release called */
554 spin_unlock(&release_lock);
555 return 0;
556 }
557 status = atomic_read(&mos_parport->shadowDSR) & 0xf8;
558 spin_unlock(&release_lock);
559 return status;
560}
561
562static void parport_mos7715_enable_irq(struct parport *pp)
563{
564 dbg("%s called", __func__);
565}
566static void parport_mos7715_disable_irq(struct parport *pp)
567{
568 dbg("%s called", __func__);
569}
570
571static void parport_mos7715_data_forward(struct parport *pp)
572{
573 struct mos7715_parport *mos_parport = pp->private_data;
574 dbg("%s called", __func__);
575 if (parport_prologue(pp) < 0)
576 return;
577 mos7715_change_mode(mos_parport, PS2);
578 mos_parport->shadowDCR &= ~0x20;
579 write_mos_reg(mos_parport->serial, dummy, DCR, mos_parport->shadowDCR);
580 parport_epilogue(pp);
581}
582
583static void parport_mos7715_data_reverse(struct parport *pp)
584{
585 struct mos7715_parport *mos_parport = pp->private_data;
586 dbg("%s called", __func__);
587 if (parport_prologue(pp) < 0)
588 return;
589 mos7715_change_mode(mos_parport, PS2);
590 mos_parport->shadowDCR |= 0x20;
591 write_mos_reg(mos_parport->serial, dummy, DCR, mos_parport->shadowDCR);
592 parport_epilogue(pp);
593}
594
595static void parport_mos7715_init_state(struct pardevice *dev,
596 struct parport_state *s)
597{
598 dbg("%s called", __func__);
599 s->u.pc.ctr = DCR_INIT_VAL;
600 s->u.pc.ecr = ECR_INIT_VAL;
601}
602
603/* N.B. Parport core code requires that this function not block */
604static void parport_mos7715_save_state(struct parport *pp,
605 struct parport_state *s)
606{
607 struct mos7715_parport *mos_parport;
608 dbg("%s called", __func__);
609 spin_lock(&release_lock);
610 mos_parport = pp->private_data;
611 if (unlikely(mos_parport == NULL)) { /* release called */
612 spin_unlock(&release_lock);
613 return;
614 }
615 s->u.pc.ctr = mos_parport->shadowDCR;
616 s->u.pc.ecr = mos_parport->shadowECR;
617 spin_unlock(&release_lock);
618}
619
620/* N.B. Parport core code requires that this function not block */
621static void parport_mos7715_restore_state(struct parport *pp,
622 struct parport_state *s)
623{
624 struct mos7715_parport *mos_parport;
625 dbg("%s called", __func__);
626 spin_lock(&release_lock);
627 mos_parport = pp->private_data;
628 if (unlikely(mos_parport == NULL)) { /* release called */
629 spin_unlock(&release_lock);
630 return;
631 }
632 write_parport_reg_nonblock(mos_parport, DCR, mos_parport->shadowDCR);
633 write_parport_reg_nonblock(mos_parport, ECR, mos_parport->shadowECR);
634 spin_unlock(&release_lock);
635}
636
637static size_t parport_mos7715_write_compat(struct parport *pp,
638 const void *buffer,
639 size_t len, int flags)
640{
641 int retval;
642 struct mos7715_parport *mos_parport = pp->private_data;
643 int actual_len;
644 dbg("%s called: %u chars", __func__, (unsigned int)len);
645 if (parport_prologue(pp) < 0)
646 return 0;
647 mos7715_change_mode(mos_parport, PPF);
648 retval = usb_bulk_msg(mos_parport->serial->dev,
649 usb_sndbulkpipe(mos_parport->serial->dev, 2),
650 (void *)buffer, len, &actual_len,
651 MOS_WDR_TIMEOUT);
652 parport_epilogue(pp);
653 if (retval) {
654 dev_err(&mos_parport->serial->dev->dev,
655 "mos7720: usb_bulk_msg() failed: %d", retval);
656 return 0;
657 }
658 return actual_len;
659}
660
661static struct parport_operations parport_mos7715_ops = {
662 .owner = THIS_MODULE,
663 .write_data = parport_mos7715_write_data,
664 .read_data = parport_mos7715_read_data,
665
666 .write_control = parport_mos7715_write_control,
667 .read_control = parport_mos7715_read_control,
668 .frob_control = parport_mos7715_frob_control,
669
670 .read_status = parport_mos7715_read_status,
671
672 .enable_irq = parport_mos7715_enable_irq,
673 .disable_irq = parport_mos7715_disable_irq,
674
675 .data_forward = parport_mos7715_data_forward,
676 .data_reverse = parport_mos7715_data_reverse,
677
678 .init_state = parport_mos7715_init_state,
679 .save_state = parport_mos7715_save_state,
680 .restore_state = parport_mos7715_restore_state,
681
682 .compat_write_data = parport_mos7715_write_compat,
683
684 .nibble_read_data = parport_ieee1284_read_nibble,
685 .byte_read_data = parport_ieee1284_read_byte,
686};
687
688/*
689 * Allocate and initialize parallel port control struct, initialize
690 * the parallel port hardware device, and register with the parport subsystem.
691 */
692static int mos7715_parport_init(struct usb_serial *serial)
693{
694 struct mos7715_parport *mos_parport;
695
696 /* allocate and initialize parallel port control struct */
697 mos_parport = kzalloc(sizeof(struct mos7715_parport), GFP_KERNEL);
698 if (mos_parport == NULL) {
699 dbg("mos7715_parport_init: kzalloc failed");
700 return -ENOMEM;
701 }
702 mos_parport->msg_pending = false;
703 kref_init(&mos_parport->ref_count);
704 spin_lock_init(&mos_parport->listlock);
705 INIT_LIST_HEAD(&mos_parport->active_urbs);
706 INIT_LIST_HEAD(&mos_parport->deferred_urbs);
707 usb_set_serial_data(serial, mos_parport); /* hijack private pointer */
708 mos_parport->serial = serial;
709 tasklet_init(&mos_parport->urb_tasklet, send_deferred_urbs,
710 (unsigned long) mos_parport);
711 init_completion(&mos_parport->syncmsg_compl);
712
713 /* cycle parallel port reset bit */
714 write_mos_reg(mos_parport->serial, dummy, PP_REG, (__u8)0x80);
715 write_mos_reg(mos_parport->serial, dummy, PP_REG, (__u8)0x00);
716
717 /* initialize device registers */
718 mos_parport->shadowDCR = DCR_INIT_VAL;
719 write_mos_reg(mos_parport->serial, dummy, DCR, mos_parport->shadowDCR);
720 mos_parport->shadowECR = ECR_INIT_VAL;
721 write_mos_reg(mos_parport->serial, dummy, ECR, mos_parport->shadowECR);
722
723 /* register with parport core */
724 mos_parport->pp = parport_register_port(0, PARPORT_IRQ_NONE,
725 PARPORT_DMA_NONE,
726 &parport_mos7715_ops);
727 if (mos_parport->pp == NULL) {
728 dev_err(&serial->interface->dev,
729 "Could not register parport\n");
730 kref_put(&mos_parport->ref_count, destroy_mos_parport);
731 return -EIO;
732 }
733 mos_parport->pp->private_data = mos_parport;
734 mos_parport->pp->modes = PARPORT_MODE_COMPAT | PARPORT_MODE_PCSPP;
735 mos_parport->pp->dev = &serial->interface->dev;
736 parport_announce_port(mos_parport->pp);
737
738 return 0;
739}
740#endif /* CONFIG_USB_SERIAL_MOS7715_PARPORT */
97 741
98/* 742/*
99 * mos7720_interrupt_callback 743 * mos7720_interrupt_callback
@@ -109,8 +753,6 @@ static void mos7720_interrupt_callback(struct urb *urb)
109 __u8 sp1; 753 __u8 sp1;
110 __u8 sp2; 754 __u8 sp2;
111 755
112 dbg(" : Entering");
113
114 switch (status) { 756 switch (status) {
115 case 0: 757 case 0:
116 /* success */ 758 /* success */
@@ -161,7 +803,7 @@ static void mos7720_interrupt_callback(struct urb *urb)
161 dbg("Serial Port 1: Receiver time out"); 803 dbg("Serial Port 1: Receiver time out");
162 break; 804 break;
163 case SERIAL_IIR_MS: 805 case SERIAL_IIR_MS:
164 dbg("Serial Port 1: Modem status change"); 806 /* dbg("Serial Port 1: Modem status change"); */
165 break; 807 break;
166 } 808 }
167 809
@@ -174,7 +816,7 @@ static void mos7720_interrupt_callback(struct urb *urb)
174 dbg("Serial Port 2: Receiver time out"); 816 dbg("Serial Port 2: Receiver time out");
175 break; 817 break;
176 case SERIAL_IIR_MS: 818 case SERIAL_IIR_MS:
177 dbg("Serial Port 2: Modem status change"); 819 /* dbg("Serial Port 2: Modem status change"); */
178 break; 820 break;
179 } 821 }
180 } 822 }
@@ -208,6 +850,7 @@ static void mos7715_interrupt_callback(struct urb *urb)
208 case -ECONNRESET: 850 case -ECONNRESET:
209 case -ENOENT: 851 case -ENOENT:
210 case -ESHUTDOWN: 852 case -ESHUTDOWN:
853 case -ENODEV:
211 /* this urb is terminated, clean up */ 854 /* this urb is terminated, clean up */
212 dbg("%s - urb shutting down with status: %d", __func__, 855 dbg("%s - urb shutting down with status: %d", __func__,
213 status); 856 status);
@@ -243,11 +886,21 @@ static void mos7715_interrupt_callback(struct urb *urb)
243 dbg("Serial Port: Receiver time out"); 886 dbg("Serial Port: Receiver time out");
244 break; 887 break;
245 case SERIAL_IIR_MS: 888 case SERIAL_IIR_MS:
246 dbg("Serial Port: Modem status change"); 889 /* dbg("Serial Port: Modem status change"); */
247 break; 890 break;
248 } 891 }
249 } 892 }
250 893
894#ifdef CONFIG_USB_SERIAL_MOS7715_PARPORT
895 { /* update local copy of DSR reg */
896 struct usb_serial_port *port = urb->context;
897 struct mos7715_parport *mos_parport = port->serial->private;
898 if (unlikely(mos_parport == NULL))
899 return;
900 atomic_set(&mos_parport->shadowDSR, data[2]);
901 }
902#endif
903
251exit: 904exit:
252 result = usb_submit_urb(urb, GFP_ATOMIC); 905 result = usb_submit_urb(urb, GFP_ATOMIC);
253 if (result) 906 if (result)
@@ -267,7 +920,6 @@ static void mos7720_bulk_in_callback(struct urb *urb)
267 int retval; 920 int retval;
268 unsigned char *data ; 921 unsigned char *data ;
269 struct usb_serial_port *port; 922 struct usb_serial_port *port;
270 struct moschip_port *mos7720_port;
271 struct tty_struct *tty; 923 struct tty_struct *tty;
272 int status = urb->status; 924 int status = urb->status;
273 925
@@ -276,13 +928,7 @@ static void mos7720_bulk_in_callback(struct urb *urb)
276 return; 928 return;
277 } 929 }
278 930
279 mos7720_port = urb->context; 931 port = urb->context;
280 if (!mos7720_port) {
281 dbg("NULL mos7720_port pointer");
282 return ;
283 }
284
285 port = mos7720_port->port;
286 932
287 dbg("Entering...%s", __func__); 933 dbg("Entering...%s", __func__);
288 934
@@ -332,8 +978,6 @@ static void mos7720_bulk_out_data_callback(struct urb *urb)
332 return ; 978 return ;
333 } 979 }
334 980
335 dbg("Entering .........");
336
337 tty = tty_port_tty_get(&mos7720_port->port->port); 981 tty = tty_port_tty_get(&mos7720_port->port->port);
338 982
339 if (tty && mos7720_port->open) 983 if (tty && mos7720_port->open)
@@ -342,56 +986,6 @@ static void mos7720_bulk_out_data_callback(struct urb *urb)
342} 986}
343 987
344/* 988/*
345 * send_mos_cmd
346 * this function will be used for sending command to device
347 */
348static int send_mos_cmd(struct usb_serial *serial, __u8 request, __u16 value,
349 __u16 index, u8 *data)
350{
351 int status;
352 u8 *buf;
353 u16 product = le16_to_cpu(serial->dev->descriptor.idProduct);
354
355 if (value < MOS_MAX_PORT) {
356 if (product == MOSCHIP_DEVICE_ID_7715)
357 value = 0x0200; /* identifies the 7715's serial port */
358 else
359 value = value*0x100+0x200;
360 } else {
361 value = 0x0000;
362 if ((product == MOSCHIP_DEVICE_ID_7715) &&
363 (index != 0x08)) {
364 dbg("serial->product== MOSCHIP_DEVICE_ID_7715");
365 /* index = 0x01 ; */
366 }
367 }
368
369 if (request == MOS_WRITE) {
370 value = value + *data;
371 status = usb_control_msg(serial->dev,
372 usb_sndctrlpipe(serial->dev, 0), MOS_WRITE,
373 0x40, value, index, NULL, 0, MOS_WDR_TIMEOUT);
374 } else {
375 buf = kmalloc(1, GFP_KERNEL);
376 if (!buf) {
377 status = -ENOMEM;
378 goto out;
379 }
380 status = usb_control_msg(serial->dev,
381 usb_rcvctrlpipe(serial->dev, 0), MOS_READ,
382 0xc0, value, index, buf, 1, MOS_WDR_TIMEOUT);
383 *data = *buf;
384 kfree(buf);
385 }
386out:
387 if (status < 0)
388 dbg("Command Write failed Value %x index %x", value, index);
389
390 return status;
391}
392
393
394/*
395 * mos77xx_probe 989 * mos77xx_probe
396 * this function installs the appropriate read interrupt endpoint callback 990 * this function installs the appropriate read interrupt endpoint callback
397 * depending on whether the device is a 7720 or 7715, thus avoiding costly 991 * depending on whether the device is a 7720 or 7715, thus avoiding costly
@@ -424,11 +1018,10 @@ static int mos7720_open(struct tty_struct *tty, struct usb_serial_port *port)
424 struct usb_serial *serial; 1018 struct usb_serial *serial;
425 struct usb_serial_port *port0; 1019 struct usb_serial_port *port0;
426 struct urb *urb; 1020 struct urb *urb;
427 struct moschip_serial *mos7720_serial;
428 struct moschip_port *mos7720_port; 1021 struct moschip_port *mos7720_port;
429 int response; 1022 int response;
430 int port_number; 1023 int port_number;
431 char data; 1024 __u8 data;
432 int allocated_urbs = 0; 1025 int allocated_urbs = 0;
433 int j; 1026 int j;
434 1027
@@ -440,11 +1033,6 @@ static int mos7720_open(struct tty_struct *tty, struct usb_serial_port *port)
440 1033
441 port0 = serial->port[0]; 1034 port0 = serial->port[0];
442 1035
443 mos7720_serial = usb_get_serial_data(serial);
444
445 if (mos7720_serial == NULL || port0 == NULL)
446 return -ENODEV;
447
448 usb_clear_halt(serial->dev, port->write_urb->pipe); 1036 usb_clear_halt(serial->dev, port->write_urb->pipe);
449 usb_clear_halt(serial->dev, port->read_urb->pipe); 1037 usb_clear_halt(serial->dev, port->read_urb->pipe);
450 1038
@@ -489,103 +1077,36 @@ static int mos7720_open(struct tty_struct *tty, struct usb_serial_port *port)
489 * 0x08 : SP1/2 Control Reg 1077 * 0x08 : SP1/2 Control Reg
490 */ 1078 */
491 port_number = port->number - port->serial->minor; 1079 port_number = port->number - port->serial->minor;
492 send_mos_cmd(port->serial, MOS_READ, port_number, UART_LSR, &data); 1080 read_mos_reg(serial, port_number, LSR, &data);
1081
493 dbg("SS::%p LSR:%x", mos7720_port, data); 1082 dbg("SS::%p LSR:%x", mos7720_port, data);
494 1083
495 dbg("Check:Sending Command .........."); 1084 dbg("Check:Sending Command ..........");
496 1085
497 data = 0x02; 1086 write_mos_reg(serial, dummy, SP1_REG, 0x02);
498 send_mos_cmd(serial, MOS_WRITE, MOS_MAX_PORT, 0x01, &data); 1087 write_mos_reg(serial, dummy, SP2_REG, 0x02);
499 data = 0x02;
500 send_mos_cmd(serial, MOS_WRITE, MOS_MAX_PORT, 0x02, &data);
501 1088
502 data = 0x00; 1089 write_mos_reg(serial, port_number, IER, 0x00);
503 send_mos_cmd(serial, MOS_WRITE, port_number, 0x01, &data); 1090 write_mos_reg(serial, port_number, FCR, 0x00);
504 data = 0x00;
505 send_mos_cmd(serial, MOS_WRITE, port_number, 0x02, &data);
506 1091
507 data = 0xCF; 1092 write_mos_reg(serial, port_number, FCR, 0xcf);
508 send_mos_cmd(serial, MOS_WRITE, port_number, 0x02, &data); 1093 mos7720_port->shadowLCR = 0x03;
509 data = 0x03; 1094 write_mos_reg(serial, port_number, LCR, mos7720_port->shadowLCR);
510 mos7720_port->shadowLCR = data; 1095 mos7720_port->shadowMCR = 0x0b;
511 send_mos_cmd(serial, MOS_WRITE, port_number, 0x03, &data); 1096 write_mos_reg(serial, port_number, MCR, mos7720_port->shadowMCR);
512 data = 0x0b;
513 mos7720_port->shadowMCR = data;
514 send_mos_cmd(serial, MOS_WRITE, port_number, 0x04, &data);
515 data = 0x0b;
516 send_mos_cmd(serial, MOS_WRITE, port_number, 0x04, &data);
517
518 data = 0x00;
519 send_mos_cmd(serial, MOS_READ, MOS_MAX_PORT, 0x08, &data);
520 data = 0x00;
521 send_mos_cmd(serial, MOS_WRITE, MOS_MAX_PORT, 0x08, &data);
522
523/* data = 0x00;
524 send_mos_cmd(serial, MOS_READ, MOS_MAX_PORT, port_number + 1, &data);
525 data = 0x03;
526 send_mos_cmd(serial, MOS_WRITE, MOS_MAX_PORT, port_number + 1, &data);
527 data = 0x00;
528 send_mos_cmd(port->serial, MOS_WRITE, MOS_MAX_PORT,
529 port_number + 1, &data);
530*/
531 data = 0x00;
532 send_mos_cmd(serial, MOS_READ, MOS_MAX_PORT, 0x08, &data);
533 1097
1098 write_mos_reg(serial, port_number, SP_CONTROL_REG, 0x00);
1099 read_mos_reg(serial, dummy, SP_CONTROL_REG, &data);
534 data = data | (port->number - port->serial->minor + 1); 1100 data = data | (port->number - port->serial->minor + 1);
535 send_mos_cmd(serial, MOS_WRITE, MOS_MAX_PORT, 0x08, &data); 1101 write_mos_reg(serial, dummy, SP_CONTROL_REG, data);
1102 mos7720_port->shadowLCR = 0x83;
1103 write_mos_reg(serial, port_number, LCR, mos7720_port->shadowLCR);
1104 write_mos_reg(serial, port_number, THR, 0x0c);
1105 write_mos_reg(serial, port_number, IER, 0x00);
1106 mos7720_port->shadowLCR = 0x03;
1107 write_mos_reg(serial, port_number, LCR, mos7720_port->shadowLCR);
1108 write_mos_reg(serial, port_number, IER, 0x0c);
536 1109
537 data = 0x83;
538 mos7720_port->shadowLCR = data;
539 send_mos_cmd(serial, MOS_WRITE, port_number, 0x03, &data);
540 data = 0x0c;
541 send_mos_cmd(serial, MOS_WRITE, port_number, 0x00, &data);
542 data = 0x00;
543 send_mos_cmd(serial, MOS_WRITE, port_number, 0x01, &data);
544 data = 0x03;
545 mos7720_port->shadowLCR = data;
546 send_mos_cmd(serial, MOS_WRITE, port_number, 0x03, &data);
547 data = 0x0c;
548 send_mos_cmd(serial, MOS_WRITE, port_number, 0x01, &data);
549 data = 0x0c;
550 send_mos_cmd(serial, MOS_WRITE, port_number, 0x01, &data);
551
552 /* see if we've set up our endpoint info yet *
553 * (can't set it up in mos7720_startup as the *
554 * structures were not set up at that time.) */
555 if (!mos7720_serial->interrupt_started) {
556 dbg("Interrupt buffer NULL !!!");
557
558 /* not set up yet, so do it now */
559 mos7720_serial->interrupt_started = 1;
560
561 dbg("To Submit URB !!!");
562
563 /* set up our interrupt urb */
564 usb_fill_int_urb(port0->interrupt_in_urb, serial->dev,
565 usb_rcvintpipe(serial->dev,
566 port->interrupt_in_endpointAddress),
567 port0->interrupt_in_buffer,
568 port0->interrupt_in_urb->transfer_buffer_length,
569 mos7720_interrupt_callback, mos7720_port,
570 port0->interrupt_in_urb->interval);
571
572 /* start interrupt read for this mos7720 this interrupt *
573 * will continue as long as the mos7720 is connected */
574 dbg("Submit URB over !!!");
575 response = usb_submit_urb(port0->interrupt_in_urb, GFP_KERNEL);
576 if (response)
577 dev_err(&port->dev,
578 "%s - Error %d submitting control urb\n",
579 __func__, response);
580 }
581
582 /* set up our bulk in urb */
583 usb_fill_bulk_urb(port->read_urb, serial->dev,
584 usb_rcvbulkpipe(serial->dev,
585 port->bulk_in_endpointAddress),
586 port->bulk_in_buffer,
587 port->read_urb->transfer_buffer_length,
588 mos7720_bulk_in_callback, mos7720_port);
589 response = usb_submit_urb(port->read_urb, GFP_KERNEL); 1110 response = usb_submit_urb(port->read_urb, GFP_KERNEL);
590 if (response) 1111 if (response)
591 dev_err(&port->dev, "%s - Error %d submitting read urb\n", 1112 dev_err(&port->dev, "%s - Error %d submitting read urb\n",
@@ -640,7 +1161,6 @@ static void mos7720_close(struct usb_serial_port *port)
640{ 1161{
641 struct usb_serial *serial; 1162 struct usb_serial *serial;
642 struct moschip_port *mos7720_port; 1163 struct moschip_port *mos7720_port;
643 char data;
644 int j; 1164 int j;
645 1165
646 dbg("mos7720_close:entering..."); 1166 dbg("mos7720_close:entering...");
@@ -673,13 +1193,10 @@ static void mos7720_close(struct usb_serial_port *port)
673 /* these commands must not be issued if the device has 1193 /* these commands must not be issued if the device has
674 * been disconnected */ 1194 * been disconnected */
675 if (!serial->disconnected) { 1195 if (!serial->disconnected) {
676 data = 0x00; 1196 write_mos_reg(serial, port->number - port->serial->minor,
677 send_mos_cmd(serial, MOS_WRITE, 1197 MCR, 0x00);
678 port->number - port->serial->minor, 0x04, &data); 1198 write_mos_reg(serial, port->number - port->serial->minor,
679 1199 IER, 0x00);
680 data = 0x00;
681 send_mos_cmd(serial, MOS_WRITE,
682 port->number - port->serial->minor, 0x01, &data);
683 } 1200 }
684 mutex_unlock(&serial->disc_mutex); 1201 mutex_unlock(&serial->disc_mutex);
685 mos7720_port->open = 0; 1202 mos7720_port->open = 0;
@@ -708,8 +1225,8 @@ static void mos7720_break(struct tty_struct *tty, int break_state)
708 data = mos7720_port->shadowLCR & ~UART_LCR_SBC; 1225 data = mos7720_port->shadowLCR & ~UART_LCR_SBC;
709 1226
710 mos7720_port->shadowLCR = data; 1227 mos7720_port->shadowLCR = data;
711 send_mos_cmd(serial, MOS_WRITE, port->number - port->serial->minor, 1228 write_mos_reg(serial, port->number - port->serial->minor,
712 0x03, &data); 1229 LCR, mos7720_port->shadowLCR);
713 1230
714 return; 1231 return;
715} 1232}
@@ -854,9 +1371,8 @@ static void mos7720_throttle(struct tty_struct *tty)
854 /* if we are implementing RTS/CTS, toggle that line */ 1371 /* if we are implementing RTS/CTS, toggle that line */
855 if (tty->termios->c_cflag & CRTSCTS) { 1372 if (tty->termios->c_cflag & CRTSCTS) {
856 mos7720_port->shadowMCR &= ~UART_MCR_RTS; 1373 mos7720_port->shadowMCR &= ~UART_MCR_RTS;
857 status = send_mos_cmd(port->serial, MOS_WRITE, 1374 write_mos_reg(port->serial, port->number - port->serial->minor,
858 port->number - port->serial->minor, 1375 MCR, mos7720_port->shadowMCR);
859 UART_MCR, &mos7720_port->shadowMCR);
860 if (status != 0) 1376 if (status != 0)
861 return; 1377 return;
862 } 1378 }
@@ -889,22 +1405,21 @@ static void mos7720_unthrottle(struct tty_struct *tty)
889 /* if we are implementing RTS/CTS, toggle that line */ 1405 /* if we are implementing RTS/CTS, toggle that line */
890 if (tty->termios->c_cflag & CRTSCTS) { 1406 if (tty->termios->c_cflag & CRTSCTS) {
891 mos7720_port->shadowMCR |= UART_MCR_RTS; 1407 mos7720_port->shadowMCR |= UART_MCR_RTS;
892 status = send_mos_cmd(port->serial, MOS_WRITE, 1408 write_mos_reg(port->serial, port->number - port->serial->minor,
893 port->number - port->serial->minor, 1409 MCR, mos7720_port->shadowMCR);
894 UART_MCR, &mos7720_port->shadowMCR);
895 if (status != 0) 1410 if (status != 0)
896 return; 1411 return;
897 } 1412 }
898} 1413}
899 1414
1415/* FIXME: this function does not work */
900static int set_higher_rates(struct moschip_port *mos7720_port, 1416static int set_higher_rates(struct moschip_port *mos7720_port,
901 unsigned int baud) 1417 unsigned int baud)
902{ 1418{
903 unsigned char data;
904 struct usb_serial_port *port; 1419 struct usb_serial_port *port;
905 struct usb_serial *serial; 1420 struct usb_serial *serial;
906 int port_number; 1421 int port_number;
907 1422 enum mos_regs sp_reg;
908 if (mos7720_port == NULL) 1423 if (mos7720_port == NULL)
909 return -EINVAL; 1424 return -EINVAL;
910 1425
@@ -917,58 +1432,35 @@ static int set_higher_rates(struct moschip_port *mos7720_port,
917 dbg("Sending Setting Commands .........."); 1432 dbg("Sending Setting Commands ..........");
918 port_number = port->number - port->serial->minor; 1433 port_number = port->number - port->serial->minor;
919 1434
920 data = 0x000; 1435 write_mos_reg(serial, port_number, IER, 0x00);
921 send_mos_cmd(serial, MOS_WRITE, port_number, 0x01, &data); 1436 write_mos_reg(serial, port_number, FCR, 0x00);
922 data = 0x000; 1437 write_mos_reg(serial, port_number, FCR, 0xcf);
923 send_mos_cmd(serial, MOS_WRITE, port_number, 0x02, &data); 1438 mos7720_port->shadowMCR = 0x0b;
924 data = 0x0CF; 1439 write_mos_reg(serial, port_number, MCR, mos7720_port->shadowMCR);
925 send_mos_cmd(serial, MOS_WRITE, port->number, 0x02, &data); 1440 write_mos_reg(serial, dummy, SP_CONTROL_REG, 0x00);
926 data = 0x00b;
927 mos7720_port->shadowMCR = data;
928 send_mos_cmd(serial, MOS_WRITE, port_number, 0x04, &data);
929 data = 0x00b;
930 send_mos_cmd(serial, MOS_WRITE, port_number, 0x04, &data);
931
932 data = 0x000;
933 send_mos_cmd(serial, MOS_READ, MOS_MAX_PORT, 0x08, &data);
934 data = 0x000;
935 send_mos_cmd(serial, MOS_WRITE, MOS_MAX_PORT, 0x08, &data);
936
937 1441
938 /*********************************************** 1442 /***********************************************
939 * Set for higher rates * 1443 * Set for higher rates *
940 ***********************************************/ 1444 ***********************************************/
941 1445 /* writing baud rate verbatum into uart clock field clearly not right */
942 data = baud * 0x10; 1446 if (port_number == 0)
943 send_mos_cmd(serial, MOS_WRITE, MOS_MAX_PORT, port_number + 1, &data); 1447 sp_reg = SP1_REG;
944 1448 else
945 data = 0x003; 1449 sp_reg = SP2_REG;
946 send_mos_cmd(serial, MOS_READ, MOS_MAX_PORT, 0x08, &data); 1450 write_mos_reg(serial, dummy, sp_reg, baud * 0x10);
947 data = 0x003; 1451 write_mos_reg(serial, dummy, SP_CONTROL_REG, 0x03);
948 send_mos_cmd(serial, MOS_WRITE, MOS_MAX_PORT, 0x08, &data); 1452 mos7720_port->shadowMCR = 0x2b;
949 1453 write_mos_reg(serial, port_number, MCR, mos7720_port->shadowMCR);
950 data = 0x02b;
951 mos7720_port->shadowMCR = data;
952 send_mos_cmd(serial, MOS_WRITE, port_number, 0x04, &data);
953 data = 0x02b;
954 send_mos_cmd(serial, MOS_WRITE, port_number, 0x04, &data);
955 1454
956 /*********************************************** 1455 /***********************************************
957 * Set DLL/DLM 1456 * Set DLL/DLM
958 ***********************************************/ 1457 ***********************************************/
959 1458 mos7720_port->shadowLCR = mos7720_port->shadowLCR | UART_LCR_DLAB;
960 data = mos7720_port->shadowLCR | UART_LCR_DLAB; 1459 write_mos_reg(serial, port_number, LCR, mos7720_port->shadowLCR);
961 mos7720_port->shadowLCR = data; 1460 write_mos_reg(serial, port_number, DLL, 0x01);
962 send_mos_cmd(serial, MOS_WRITE, port_number, 0x03, &data); 1461 write_mos_reg(serial, port_number, DLM, 0x00);
963 1462 mos7720_port->shadowLCR = mos7720_port->shadowLCR & ~UART_LCR_DLAB;
964 data = 0x001; /* DLL */ 1463 write_mos_reg(serial, port_number, LCR, mos7720_port->shadowLCR);
965 send_mos_cmd(serial, MOS_WRITE, port_number, 0x00, &data);
966 data = 0x000; /* DLM */
967 send_mos_cmd(serial, MOS_WRITE, port_number, 0x01, &data);
968
969 data = mos7720_port->shadowLCR & ~UART_LCR_DLAB;
970 mos7720_port->shadowLCR = data;
971 send_mos_cmd(serial, MOS_WRITE, port_number, 0x03, &data);
972 1464
973 return 0; 1465 return 0;
974} 1466}
@@ -1056,7 +1548,6 @@ static int send_cmd_write_baud_rate(struct moschip_port *mos7720_port,
1056 struct usb_serial *serial; 1548 struct usb_serial *serial;
1057 int divisor; 1549 int divisor;
1058 int status; 1550 int status;
1059 unsigned char data;
1060 unsigned char number; 1551 unsigned char number;
1061 1552
1062 if (mos7720_port == NULL) 1553 if (mos7720_port == NULL)
@@ -1078,21 +1569,16 @@ static int send_cmd_write_baud_rate(struct moschip_port *mos7720_port,
1078 } 1569 }
1079 1570
1080 /* Enable access to divisor latch */ 1571 /* Enable access to divisor latch */
1081 data = mos7720_port->shadowLCR | UART_LCR_DLAB; 1572 mos7720_port->shadowLCR = mos7720_port->shadowLCR | UART_LCR_DLAB;
1082 mos7720_port->shadowLCR = data; 1573 write_mos_reg(serial, number, LCR, mos7720_port->shadowLCR);
1083 send_mos_cmd(serial, MOS_WRITE, number, UART_LCR, &data);
1084 1574
1085 /* Write the divisor */ 1575 /* Write the divisor */
1086 data = ((unsigned char)(divisor & 0xff)); 1576 write_mos_reg(serial, number, DLL, (__u8)(divisor & 0xff));
1087 send_mos_cmd(serial, MOS_WRITE, number, 0x00, &data); 1577 write_mos_reg(serial, number, DLM, (__u8)((divisor & 0xff00) >> 8));
1088
1089 data = ((unsigned char)((divisor & 0xff00) >> 8));
1090 send_mos_cmd(serial, MOS_WRITE, number, 0x01, &data);
1091 1578
1092 /* Disable access to divisor latch */ 1579 /* Disable access to divisor latch */
1093 data = mos7720_port->shadowLCR & ~UART_LCR_DLAB; 1580 mos7720_port->shadowLCR = mos7720_port->shadowLCR & ~UART_LCR_DLAB;
1094 mos7720_port->shadowLCR = data; 1581 write_mos_reg(serial, number, LCR, mos7720_port->shadowLCR);
1095 send_mos_cmd(serial, MOS_WRITE, number, 0x03, &data);
1096 1582
1097 return status; 1583 return status;
1098} 1584}
@@ -1117,7 +1603,6 @@ static void change_port_settings(struct tty_struct *tty,
1117 __u8 lStop; 1603 __u8 lStop;
1118 int status; 1604 int status;
1119 int port_number; 1605 int port_number;
1120 char data;
1121 1606
1122 if (mos7720_port == NULL) 1607 if (mos7720_port == NULL)
1123 return ; 1608 return ;
@@ -1196,30 +1681,19 @@ static void change_port_settings(struct tty_struct *tty,
1196 1681
1197 /* Update the LCR with the correct value */ 1682 /* Update the LCR with the correct value */
1198 mos7720_port->shadowLCR &= 1683 mos7720_port->shadowLCR &=
1199 ~(LCR_BITS_MASK | LCR_STOP_MASK | LCR_PAR_MASK); 1684 ~(LCR_BITS_MASK | LCR_STOP_MASK | LCR_PAR_MASK);
1200 mos7720_port->shadowLCR |= (lData | lParity | lStop); 1685 mos7720_port->shadowLCR |= (lData | lParity | lStop);
1201 1686
1202 1687
1203 /* Disable Interrupts */ 1688 /* Disable Interrupts */
1204 data = 0x00; 1689 write_mos_reg(serial, port_number, IER, 0x00);
1205 send_mos_cmd(serial, MOS_WRITE, port->number - port->serial->minor, 1690 write_mos_reg(serial, port_number, FCR, 0x00);
1206 UART_IER, &data); 1691 write_mos_reg(serial, port_number, FCR, 0xcf);
1207
1208 data = 0x00;
1209 send_mos_cmd(serial, MOS_WRITE, port_number, UART_FCR, &data);
1210
1211 data = 0xcf;
1212 send_mos_cmd(serial, MOS_WRITE, port_number, UART_FCR, &data);
1213 1692
1214 /* Send the updated LCR value to the mos7720 */ 1693 /* Send the updated LCR value to the mos7720 */
1215 data = mos7720_port->shadowLCR; 1694 write_mos_reg(serial, port_number, LCR, mos7720_port->shadowLCR);
1216 send_mos_cmd(serial, MOS_WRITE, port_number, UART_LCR, &data); 1695 mos7720_port->shadowMCR = 0x0b;
1217 1696 write_mos_reg(serial, port_number, MCR, mos7720_port->shadowMCR);
1218 data = 0x00b;
1219 mos7720_port->shadowMCR = data;
1220 send_mos_cmd(serial, MOS_WRITE, port_number, 0x04, &data);
1221 data = 0x00b;
1222 send_mos_cmd(serial, MOS_WRITE, port_number, 0x04, &data);
1223 1697
1224 /* set up the MCR register and send it to the mos7720 */ 1698 /* set up the MCR register and send it to the mos7720 */
1225 mos7720_port->shadowMCR = UART_MCR_OUT2; 1699 mos7720_port->shadowMCR = UART_MCR_OUT2;
@@ -1230,21 +1704,15 @@ static void change_port_settings(struct tty_struct *tty,
1230 mos7720_port->shadowMCR |= (UART_MCR_XONANY); 1704 mos7720_port->shadowMCR |= (UART_MCR_XONANY);
1231 /* To set hardware flow control to the specified * 1705 /* To set hardware flow control to the specified *
1232 * serial port, in SP1/2_CONTROL_REG */ 1706 * serial port, in SP1/2_CONTROL_REG */
1233 if (port->number) { 1707 if (port->number)
1234 data = 0x001; 1708 write_mos_reg(serial, dummy, SP_CONTROL_REG, 0x01);
1235 send_mos_cmd(serial, MOS_WRITE, MOS_MAX_PORT, 1709 else
1236 0x08, &data); 1710 write_mos_reg(serial, dummy, SP_CONTROL_REG, 0x02);
1237 } else { 1711
1238 data = 0x002; 1712 } else
1239 send_mos_cmd(serial, MOS_WRITE, MOS_MAX_PORT,
1240 0x08, &data);
1241 }
1242 } else {
1243 mos7720_port->shadowMCR &= ~(UART_MCR_XONANY); 1713 mos7720_port->shadowMCR &= ~(UART_MCR_XONANY);
1244 }
1245 1714
1246 data = mos7720_port->shadowMCR; 1715 write_mos_reg(serial, port_number, MCR, mos7720_port->shadowMCR);
1247 send_mos_cmd(serial, MOS_WRITE, port_number, UART_MCR, &data);
1248 1716
1249 /* Determine divisor based on baud rate */ 1717 /* Determine divisor based on baud rate */
1250 baud = tty_get_baud_rate(tty); 1718 baud = tty_get_baud_rate(tty);
@@ -1257,8 +1725,7 @@ static void change_port_settings(struct tty_struct *tty,
1257 if (baud >= 230400) { 1725 if (baud >= 230400) {
1258 set_higher_rates(mos7720_port, baud); 1726 set_higher_rates(mos7720_port, baud);
1259 /* Enable Interrupts */ 1727 /* Enable Interrupts */
1260 data = 0x0c; 1728 write_mos_reg(serial, port_number, IER, 0x0c);
1261 send_mos_cmd(serial, MOS_WRITE, port_number, UART_IER, &data);
1262 return; 1729 return;
1263 } 1730 }
1264 1731
@@ -1269,8 +1736,7 @@ static void change_port_settings(struct tty_struct *tty,
1269 if (cflag & CBAUD) 1736 if (cflag & CBAUD)
1270 tty_encode_baud_rate(tty, baud, baud); 1737 tty_encode_baud_rate(tty, baud, baud);
1271 /* Enable Interrupts */ 1738 /* Enable Interrupts */
1272 data = 0x0c; 1739 write_mos_reg(serial, port_number, IER, 0x0c);
1273 send_mos_cmd(serial, MOS_WRITE, port_number, UART_IER, &data);
1274 1740
1275 if (port->read_urb->status != -EINPROGRESS) { 1741 if (port->read_urb->status != -EINPROGRESS) {
1276 port->read_urb->dev = serial->dev; 1742 port->read_urb->dev = serial->dev;
@@ -1308,7 +1774,7 @@ static void mos7720_set_termios(struct tty_struct *tty,
1308 return; 1774 return;
1309 } 1775 }
1310 1776
1311 dbg("setting termios - ASPIRE"); 1777 dbg("%s\n", "setting termios - ASPIRE");
1312 1778
1313 cflag = tty->termios->c_cflag; 1779 cflag = tty->termios->c_cflag;
1314 1780
@@ -1326,7 +1792,7 @@ static void mos7720_set_termios(struct tty_struct *tty,
1326 change_port_settings(tty, mos7720_port, old_termios); 1792 change_port_settings(tty, mos7720_port, old_termios);
1327 1793
1328 if (!port->read_urb) { 1794 if (!port->read_urb) {
1329 dbg("URB KILLED !!!!!"); 1795 dbg("%s", "URB KILLED !!!!!");
1330 return; 1796 return;
1331 } 1797 }
1332 1798
@@ -1361,8 +1827,7 @@ static int get_lsr_info(struct tty_struct *tty,
1361 1827
1362 count = mos7720_chars_in_buffer(tty); 1828 count = mos7720_chars_in_buffer(tty);
1363 if (count == 0) { 1829 if (count == 0) {
1364 send_mos_cmd(port->serial, MOS_READ, port_number, 1830 read_mos_reg(port->serial, port_number, LSR, &data);
1365 UART_LSR, &data);
1366 if ((data & (UART_LSR_TEMT | UART_LSR_THRE)) 1831 if ((data & (UART_LSR_TEMT | UART_LSR_THRE))
1367 == (UART_LSR_TEMT | UART_LSR_THRE)) { 1832 == (UART_LSR_TEMT | UART_LSR_THRE)) {
1368 dbg("%s -- Empty", __func__); 1833 dbg("%s -- Empty", __func__);
@@ -1400,13 +1865,11 @@ static int mos7720_tiocmget(struct tty_struct *tty, struct file *file)
1400} 1865}
1401 1866
1402static int mos7720_tiocmset(struct tty_struct *tty, struct file *file, 1867static int mos7720_tiocmset(struct tty_struct *tty, struct file *file,
1403 unsigned int set, unsigned int clear) 1868 unsigned int set, unsigned int clear)
1404{ 1869{
1405 struct usb_serial_port *port = tty->driver_data; 1870 struct usb_serial_port *port = tty->driver_data;
1406 struct moschip_port *mos7720_port = usb_get_serial_port_data(port); 1871 struct moschip_port *mos7720_port = usb_get_serial_port_data(port);
1407 unsigned int mcr ; 1872 unsigned int mcr ;
1408 unsigned char lmcr;
1409
1410 dbg("%s - port %d", __func__, port->number); 1873 dbg("%s - port %d", __func__, port->number);
1411 dbg("he was at tiocmget"); 1874 dbg("he was at tiocmget");
1412 1875
@@ -1427,10 +1890,8 @@ static int mos7720_tiocmset(struct tty_struct *tty, struct file *file,
1427 mcr &= ~UART_MCR_LOOP; 1890 mcr &= ~UART_MCR_LOOP;
1428 1891
1429 mos7720_port->shadowMCR = mcr; 1892 mos7720_port->shadowMCR = mcr;
1430 lmcr = mos7720_port->shadowMCR; 1893 write_mos_reg(port->serial, port->number - port->serial->minor,
1431 1894 MCR, mos7720_port->shadowMCR);
1432 send_mos_cmd(port->serial, MOS_WRITE,
1433 port->number - port->serial->minor, UART_MCR, &lmcr);
1434 1895
1435 return 0; 1896 return 0;
1436} 1897}
@@ -1440,7 +1901,6 @@ static int set_modem_info(struct moschip_port *mos7720_port, unsigned int cmd,
1440{ 1901{
1441 unsigned int mcr ; 1902 unsigned int mcr ;
1442 unsigned int arg; 1903 unsigned int arg;
1443 unsigned char data;
1444 1904
1445 struct usb_serial_port *port; 1905 struct usb_serial_port *port;
1446 1906
@@ -1475,10 +1935,8 @@ static int set_modem_info(struct moschip_port *mos7720_port, unsigned int cmd,
1475 } 1935 }
1476 1936
1477 mos7720_port->shadowMCR = mcr; 1937 mos7720_port->shadowMCR = mcr;
1478 1938 write_mos_reg(port->serial, port->number - port->serial->minor,
1479 data = mos7720_port->shadowMCR; 1939 MCR, mos7720_port->shadowMCR);
1480 send_mos_cmd(port->serial, MOS_WRITE,
1481 port->number - port->serial->minor, UART_MCR, &data);
1482 1940
1483 return 0; 1941 return 0;
1484} 1942}
@@ -1590,12 +2048,12 @@ static int mos7720_ioctl(struct tty_struct *tty, struct file *file,
1590 2048
1591static int mos7720_startup(struct usb_serial *serial) 2049static int mos7720_startup(struct usb_serial *serial)
1592{ 2050{
1593 struct moschip_serial *mos7720_serial;
1594 struct moschip_port *mos7720_port; 2051 struct moschip_port *mos7720_port;
1595 struct usb_device *dev; 2052 struct usb_device *dev;
1596 int i; 2053 int i;
1597 char data; 2054 char data;
1598 u16 product = le16_to_cpu(serial->dev->descriptor.idProduct); 2055 u16 product = le16_to_cpu(serial->dev->descriptor.idProduct);
2056 int ret_val;
1599 2057
1600 dbg("%s: Entering ..........", __func__); 2058 dbg("%s: Entering ..........", __func__);
1601 2059
@@ -1606,15 +2064,6 @@ static int mos7720_startup(struct usb_serial *serial)
1606 2064
1607 dev = serial->dev; 2065 dev = serial->dev;
1608 2066
1609 /* create our private serial structure */
1610 mos7720_serial = kzalloc(sizeof(struct moschip_serial), GFP_KERNEL);
1611 if (mos7720_serial == NULL) {
1612 dev_err(&dev->dev, "%s - Out of memory\n", __func__);
1613 return -ENOMEM;
1614 }
1615
1616 usb_set_serial_data(serial, mos7720_serial);
1617
1618 /* 2067 /*
1619 * The 7715 uses the first bulk in/out endpoint pair for the parallel 2068 * The 7715 uses the first bulk in/out endpoint pair for the parallel
1620 * port, and the second for the serial port. Because the usbserial core 2069 * port, and the second for the serial port. Because the usbserial core
@@ -1638,16 +2087,12 @@ static int mos7720_startup(struct usb_serial *serial)
1638 serial->port[1]->interrupt_in_buffer = NULL; 2087 serial->port[1]->interrupt_in_buffer = NULL;
1639 } 2088 }
1640 2089
1641 /* we set up the pointers to the endpoints in the mos7720_open *
1642 * function, as the structures aren't created yet. */
1643 2090
1644 /* set up port private structures */ 2091 /* set up serial port private structures */
1645 for (i = 0; i < serial->num_ports; ++i) { 2092 for (i = 0; i < serial->num_ports; ++i) {
1646 mos7720_port = kzalloc(sizeof(struct moschip_port), GFP_KERNEL); 2093 mos7720_port = kzalloc(sizeof(struct moschip_port), GFP_KERNEL);
1647 if (mos7720_port == NULL) { 2094 if (mos7720_port == NULL) {
1648 dev_err(&dev->dev, "%s - Out of memory\n", __func__); 2095 dev_err(&dev->dev, "%s - Out of memory\n", __func__);
1649 usb_set_serial_data(serial, NULL);
1650 kfree(mos7720_serial);
1651 return -ENOMEM; 2096 return -ENOMEM;
1652 } 2097 }
1653 2098
@@ -1669,12 +2114,22 @@ static int mos7720_startup(struct usb_serial *serial)
1669 usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), 2114 usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
1670 (__u8)0x03, 0x00, 0x01, 0x00, NULL, 0x00, 5*HZ); 2115 (__u8)0x03, 0x00, 0x01, 0x00, NULL, 0x00, 5*HZ);
1671 2116
1672 /* LSR For Port 1 */ 2117 /* start the interrupt urb */
1673 send_mos_cmd(serial, MOS_READ, 0x00, UART_LSR, &data); 2118 ret_val = usb_submit_urb(serial->port[0]->interrupt_in_urb, GFP_KERNEL);
1674 dbg("LSR:%x", data); 2119 if (ret_val)
2120 dev_err(&dev->dev,
2121 "%s - Error %d submitting control urb\n",
2122 __func__, ret_val);
1675 2123
1676 /* LSR For Port 2 */ 2124#ifdef CONFIG_USB_SERIAL_MOS7715_PARPORT
1677 send_mos_cmd(serial, MOS_READ, 0x01, UART_LSR, &data); 2125 if (product == MOSCHIP_DEVICE_ID_7715) {
2126 ret_val = mos7715_parport_init(serial);
2127 if (ret_val < 0)
2128 return ret_val;
2129 }
2130#endif
2131 /* LSR For Port 1 */
2132 read_mos_reg(serial, 0, LSR, &data);
1678 dbg("LSR:%x", data); 2133 dbg("LSR:%x", data);
1679 2134
1680 return 0; 2135 return 0;
@@ -1684,12 +2139,47 @@ static void mos7720_release(struct usb_serial *serial)
1684{ 2139{
1685 int i; 2140 int i;
1686 2141
2142#ifdef CONFIG_USB_SERIAL_MOS7715_PARPORT
2143 /* close the parallel port */
2144
2145 if (le16_to_cpu(serial->dev->descriptor.idProduct)
2146 == MOSCHIP_DEVICE_ID_7715) {
2147 struct urbtracker *urbtrack;
2148 unsigned long flags;
2149 struct mos7715_parport *mos_parport =
2150 usb_get_serial_data(serial);
2151
2152 /* prevent NULL ptr dereference in port callbacks */
2153 spin_lock(&release_lock);
2154 mos_parport->pp->private_data = NULL;
2155 spin_unlock(&release_lock);
2156
2157 /* wait for synchronous usb calls to return */
2158 if (mos_parport->msg_pending)
2159 wait_for_completion_timeout(&mos_parport->syncmsg_compl,
2160 MOS_WDR_TIMEOUT);
2161
2162 parport_remove_port(mos_parport->pp);
2163 usb_set_serial_data(serial, NULL);
2164 mos_parport->serial = NULL;
2165
2166 /* if tasklet currently scheduled, wait for it to complete */
2167 tasklet_kill(&mos_parport->urb_tasklet);
2168
2169 /* unlink any urbs sent by the tasklet */
2170 spin_lock_irqsave(&mos_parport->listlock, flags);
2171 list_for_each_entry(urbtrack,
2172 &mos_parport->active_urbs,
2173 urblist_entry)
2174 usb_unlink_urb(urbtrack->urb);
2175 spin_unlock_irqrestore(&mos_parport->listlock, flags);
2176
2177 kref_put(&mos_parport->ref_count, destroy_mos_parport);
2178 }
2179#endif
1687 /* free private structure allocated for serial port */ 2180 /* free private structure allocated for serial port */
1688 for (i = 0; i < serial->num_ports; ++i) 2181 for (i = 0; i < serial->num_ports; ++i)
1689 kfree(usb_get_serial_port_data(serial->port[i])); 2182 kfree(usb_get_serial_port_data(serial->port[i]));
1690
1691 /* free private structure allocated for serial device */
1692 kfree(usb_get_serial_data(serial));
1693} 2183}
1694 2184
1695static struct usb_driver usb_driver = { 2185static struct usb_driver usb_driver = {