forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-16 8d2a02b24d66aa359e83eebc1ed3c0f85367a1cb
kernel/drivers/usb/serial/mos7840.c
....@@ -89,16 +89,10 @@
8989 /* For higher baud Rates use TIOCEXBAUD */
9090 #define TIOCEXBAUD 0x5462
9191
92
-/* vendor id and device id defines */
93
-
94
-/* The native mos7840/7820 component */
95
-#define USB_VENDOR_ID_MOSCHIP 0x9710
96
-#define MOSCHIP_DEVICE_ID_7840 0x7840
97
-#define MOSCHIP_DEVICE_ID_7820 0x7820
98
-#define MOSCHIP_DEVICE_ID_7810 0x7810
99
-/* The native component can have its vendor/device id's overridden
100
- * in vendor-specific implementations. Such devices can be handled
101
- * by making a change here, in id_table.
92
+/*
93
+ * Vendor id and device id defines
94
+ *
95
+ * NOTE: Do not add new defines, add entries directly to the id_table instead.
10296 */
10397 #define USB_VENDOR_ID_BANDB 0x0856
10498 #define BANDB_DEVICE_ID_USO9ML2_2 0xAC22
....@@ -113,18 +107,6 @@
113107 #define BANDB_DEVICE_ID_USOPTL4_2P 0xBC02
114108 #define BANDB_DEVICE_ID_USOPTL4_4 0xAC44
115109 #define BANDB_DEVICE_ID_USOPTL4_4P 0xBC03
116
-
117
-/* This driver also supports
118
- * ATEN UC2324 device using Moschip MCS7840
119
- * ATEN UC2322 device using Moschip MCS7820
120
- * MOXA UPort 2210 device using Moschip MCS7820
121
- */
122
-#define USB_VENDOR_ID_ATENINTL 0x0557
123
-#define ATENINTL_DEVICE_ID_UC2324 0x2011
124
-#define ATENINTL_DEVICE_ID_UC2322 0x7820
125
-
126
-#define USB_VENDOR_ID_MOXA 0x110a
127
-#define MOXA_DEVICE_ID_2210 0x2210
128110
129111 /* Interrupt Routine Defines */
130112
....@@ -173,29 +155,36 @@
173155 #define LED_OFF_MS 500
174156
175157 enum mos7840_flag {
176
- MOS7840_FLAG_CTRL_BUSY,
177158 MOS7840_FLAG_LED_BUSY,
178159 };
179160
161
+#define MCS_PORT_MASK GENMASK(2, 0)
162
+#define MCS_PORTS(nr) ((nr) & MCS_PORT_MASK)
163
+#define MCS_LED BIT(3)
164
+
165
+#define MCS_DEVICE(vid, pid, flags) \
166
+ USB_DEVICE((vid), (pid)), .driver_info = (flags)
167
+
180168 static const struct usb_device_id id_table[] = {
181
- {USB_DEVICE(USB_VENDOR_ID_MOSCHIP, MOSCHIP_DEVICE_ID_7840)},
182
- {USB_DEVICE(USB_VENDOR_ID_MOSCHIP, MOSCHIP_DEVICE_ID_7820)},
183
- {USB_DEVICE(USB_VENDOR_ID_MOSCHIP, MOSCHIP_DEVICE_ID_7810)},
184
- {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USO9ML2_2)},
185
- {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USO9ML2_2P)},
186
- {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USO9ML2_4)},
187
- {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USO9ML2_4P)},
188
- {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_US9ML2_2)},
189
- {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_US9ML2_4)},
190
- {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USPTL4_2)},
191
- {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USPTL4_4)},
192
- {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL4_2)},
193
- {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL4_2P)},
194
- {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL4_4)},
195
- {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL4_4P)},
196
- {USB_DEVICE(USB_VENDOR_ID_ATENINTL, ATENINTL_DEVICE_ID_UC2324)},
197
- {USB_DEVICE(USB_VENDOR_ID_ATENINTL, ATENINTL_DEVICE_ID_UC2322)},
198
- {USB_DEVICE(USB_VENDOR_ID_MOXA, MOXA_DEVICE_ID_2210)},
169
+ { MCS_DEVICE(0x0557, 0x2011, MCS_PORTS(4)) }, /* ATEN UC2324 */
170
+ { MCS_DEVICE(0x0557, 0x7820, MCS_PORTS(2)) }, /* ATEN UC2322 */
171
+ { MCS_DEVICE(0x110a, 0x2210, MCS_PORTS(2)) }, /* Moxa UPort 2210 */
172
+ { MCS_DEVICE(0x9710, 0x7810, MCS_PORTS(1) | MCS_LED) }, /* ASIX MCS7810 */
173
+ { MCS_DEVICE(0x9710, 0x7820, MCS_PORTS(2)) }, /* MosChip MCS7820 */
174
+ { MCS_DEVICE(0x9710, 0x7840, MCS_PORTS(4)) }, /* MosChip MCS7840 */
175
+ { MCS_DEVICE(0x9710, 0x7843, MCS_PORTS(3)) }, /* ASIX MCS7840 3 port */
176
+ { USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USO9ML2_2) },
177
+ { USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USO9ML2_2P) },
178
+ { USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USO9ML2_4) },
179
+ { USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USO9ML2_4P) },
180
+ { USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_US9ML2_2) },
181
+ { USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_US9ML2_4) },
182
+ { USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USPTL4_2) },
183
+ { USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USPTL4_4) },
184
+ { USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL4_2) },
185
+ { USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL4_2P) },
186
+ { USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL4_4) },
187
+ { USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL4_4P) },
199188 {} /* terminating entry */
200189 };
201190 MODULE_DEVICE_TABLE(usb, id_table);
....@@ -207,19 +196,12 @@
207196 struct urb *read_urb; /* read URB for this port */
208197 __u8 shadowLCR; /* last LCR value received */
209198 __u8 shadowMCR; /* last MCR value received */
210
- char open;
211
- char open_ports;
212199 struct usb_serial_port *port; /* loop back to the owner of this object */
213200
214201 /* Offsets */
215202 __u8 SpRegOffset;
216203 __u8 ControlRegOffset;
217204 __u8 DcrRegOffset;
218
- /* for processing control URBS in interrupt context */
219
- struct urb *control_urb;
220
- struct usb_ctrlrequest *dr;
221
- char *ctrl_buf;
222
- int MsrLsr;
223205
224206 spinlock_t pool_lock;
225207 struct urb *write_urb_pool[NUM_URBS];
....@@ -301,15 +283,10 @@
301283 val = val & 0x00ff;
302284 /* For the UART control registers, the application number need
303285 to be Or'ed */
304
- if (port->serial->num_ports == 4) {
286
+ if (port->serial->num_ports == 2 && port->port_number != 0)
287
+ val |= ((__u16)port->port_number + 2) << 8;
288
+ else
305289 val |= ((__u16)port->port_number + 1) << 8;
306
- } else {
307
- if (port->port_number == 0) {
308
- val |= ((__u16)port->port_number + 1) << 8;
309
- } else {
310
- val |= ((__u16)port->port_number + 2) << 8;
311
- }
312
- }
313290 dev_dbg(&port->dev, "%s application number is %x\n", __func__, val);
314291 return usb_control_msg(dev, usb_sndctrlpipe(dev, 0), MCS_WRREQ,
315292 MCS_WR_RTYPE, val, reg, NULL, 0,
....@@ -335,15 +312,10 @@
335312 return -ENOMEM;
336313
337314 /* Wval is same as application number */
338
- if (port->serial->num_ports == 4) {
315
+ if (port->serial->num_ports == 2 && port->port_number != 0)
316
+ Wval = ((__u16)port->port_number + 2) << 8;
317
+ else
339318 Wval = ((__u16)port->port_number + 1) << 8;
340
- } else {
341
- if (port->port_number == 0) {
342
- Wval = ((__u16)port->port_number + 1) << 8;
343
- } else {
344
- Wval = ((__u16)port->port_number + 2) << 8;
345
- }
346
- }
347319 dev_dbg(&port->dev, "%s application number is %x\n", __func__, Wval);
348320 ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), MCS_RDREQ,
349321 MCS_RD_RTYPE, Wval, reg, buf, VENDOR_READ_LENGTH,
....@@ -371,149 +343,10 @@
371343
372344 /************************************************************************/
373345 /************************************************************************/
374
-/* I N T E R F A C E F U N C T I O N S */
375
-/* I N T E R F A C E F U N C T I O N S */
376
-/************************************************************************/
377
-/************************************************************************/
378
-
379
-static inline void mos7840_set_port_private(struct usb_serial_port *port,
380
- struct moschip_port *data)
381
-{
382
- usb_set_serial_port_data(port, (void *)data);
383
-}
384
-
385
-static inline struct moschip_port *mos7840_get_port_private(struct
386
- usb_serial_port
387
- *port)
388
-{
389
- return (struct moschip_port *)usb_get_serial_port_data(port);
390
-}
391
-
392
-static void mos7840_handle_new_msr(struct moschip_port *port, __u8 new_msr)
393
-{
394
- struct moschip_port *mos7840_port;
395
- struct async_icount *icount;
396
- mos7840_port = port;
397
- if (new_msr &
398
- (MOS_MSR_DELTA_CTS | MOS_MSR_DELTA_DSR | MOS_MSR_DELTA_RI |
399
- MOS_MSR_DELTA_CD)) {
400
- icount = &mos7840_port->port->icount;
401
-
402
- /* update input line counters */
403
- if (new_msr & MOS_MSR_DELTA_CTS)
404
- icount->cts++;
405
- if (new_msr & MOS_MSR_DELTA_DSR)
406
- icount->dsr++;
407
- if (new_msr & MOS_MSR_DELTA_CD)
408
- icount->dcd++;
409
- if (new_msr & MOS_MSR_DELTA_RI)
410
- icount->rng++;
411
-
412
- wake_up_interruptible(&port->port->port.delta_msr_wait);
413
- }
414
-}
415
-
416
-static void mos7840_handle_new_lsr(struct moschip_port *port, __u8 new_lsr)
417
-{
418
- struct async_icount *icount;
419
-
420
- if (new_lsr & SERIAL_LSR_BI) {
421
- /*
422
- * Parity and Framing errors only count if they
423
- * occur exclusive of a break being
424
- * received.
425
- */
426
- new_lsr &= (__u8) (SERIAL_LSR_OE | SERIAL_LSR_BI);
427
- }
428
-
429
- /* update input line counters */
430
- icount = &port->port->icount;
431
- if (new_lsr & SERIAL_LSR_BI)
432
- icount->brk++;
433
- if (new_lsr & SERIAL_LSR_OE)
434
- icount->overrun++;
435
- if (new_lsr & SERIAL_LSR_PE)
436
- icount->parity++;
437
- if (new_lsr & SERIAL_LSR_FE)
438
- icount->frame++;
439
-}
440
-
441
-/************************************************************************/
442
-/************************************************************************/
443346 /* U S B C A L L B A C K F U N C T I O N S */
444347 /* U S B C A L L B A C K F U N C T I O N S */
445348 /************************************************************************/
446349 /************************************************************************/
447
-
448
-static void mos7840_control_callback(struct urb *urb)
449
-{
450
- unsigned char *data;
451
- struct moschip_port *mos7840_port;
452
- struct device *dev = &urb->dev->dev;
453
- __u8 regval = 0x0;
454
- int status = urb->status;
455
-
456
- mos7840_port = urb->context;
457
-
458
- switch (status) {
459
- case 0:
460
- /* success */
461
- break;
462
- case -ECONNRESET:
463
- case -ENOENT:
464
- case -ESHUTDOWN:
465
- /* this urb is terminated, clean up */
466
- dev_dbg(dev, "%s - urb shutting down with status: %d\n", __func__, status);
467
- goto out;
468
- default:
469
- dev_dbg(dev, "%s - nonzero urb status received: %d\n", __func__, status);
470
- goto out;
471
- }
472
-
473
- dev_dbg(dev, "%s urb buffer size is %d\n", __func__, urb->actual_length);
474
- if (urb->actual_length < 1)
475
- goto out;
476
-
477
- dev_dbg(dev, "%s mos7840_port->MsrLsr is %d port %d\n", __func__,
478
- mos7840_port->MsrLsr, mos7840_port->port_num);
479
- data = urb->transfer_buffer;
480
- regval = (__u8) data[0];
481
- dev_dbg(dev, "%s data is %x\n", __func__, regval);
482
- if (mos7840_port->MsrLsr == 0)
483
- mos7840_handle_new_msr(mos7840_port, regval);
484
- else if (mos7840_port->MsrLsr == 1)
485
- mos7840_handle_new_lsr(mos7840_port, regval);
486
-out:
487
- clear_bit_unlock(MOS7840_FLAG_CTRL_BUSY, &mos7840_port->flags);
488
-}
489
-
490
-static int mos7840_get_reg(struct moschip_port *mcs, __u16 Wval, __u16 reg,
491
- __u16 *val)
492
-{
493
- struct usb_device *dev = mcs->port->serial->dev;
494
- struct usb_ctrlrequest *dr = mcs->dr;
495
- unsigned char *buffer = mcs->ctrl_buf;
496
- int ret;
497
-
498
- if (test_and_set_bit_lock(MOS7840_FLAG_CTRL_BUSY, &mcs->flags))
499
- return -EBUSY;
500
-
501
- dr->bRequestType = MCS_RD_RTYPE;
502
- dr->bRequest = MCS_RDREQ;
503
- dr->wValue = cpu_to_le16(Wval); /* 0 */
504
- dr->wIndex = cpu_to_le16(reg);
505
- dr->wLength = cpu_to_le16(2);
506
-
507
- usb_fill_control_urb(mcs->control_urb, dev, usb_rcvctrlpipe(dev, 0),
508
- (unsigned char *)dr, buffer, 2,
509
- mos7840_control_callback, mcs);
510
- mcs->control_urb->transfer_buffer_length = 2;
511
- ret = usb_submit_urb(mcs->control_urb, GFP_ATOMIC);
512
- if (ret)
513
- clear_bit_unlock(MOS7840_FLAG_CTRL_BUSY, &mcs->flags);
514
-
515
- return ret;
516
-}
517350
518351 static void mos7840_set_led_callback(struct urb *urb)
519352 {
....@@ -591,147 +424,6 @@
591424 }
592425
593426 /*****************************************************************************
594
- * mos7840_interrupt_callback
595
- * this is the callback function for when we have received data on the
596
- * interrupt endpoint.
597
- *****************************************************************************/
598
-
599
-static void mos7840_interrupt_callback(struct urb *urb)
600
-{
601
- int result;
602
- int length;
603
- struct moschip_port *mos7840_port;
604
- struct usb_serial *serial;
605
- __u16 Data;
606
- unsigned char *data;
607
- __u8 sp[5], st;
608
- int i, rv = 0;
609
- __u16 wval, wreg = 0;
610
- int status = urb->status;
611
-
612
- switch (status) {
613
- case 0:
614
- /* success */
615
- break;
616
- case -ECONNRESET:
617
- case -ENOENT:
618
- case -ESHUTDOWN:
619
- /* this urb is terminated, clean up */
620
- dev_dbg(&urb->dev->dev, "%s - urb shutting down with status: %d\n",
621
- __func__, status);
622
- return;
623
- default:
624
- dev_dbg(&urb->dev->dev, "%s - nonzero urb status received: %d\n",
625
- __func__, status);
626
- goto exit;
627
- }
628
-
629
- length = urb->actual_length;
630
- data = urb->transfer_buffer;
631
-
632
- serial = urb->context;
633
-
634
- /* Moschip get 5 bytes
635
- * Byte 1 IIR Port 1 (port.number is 0)
636
- * Byte 2 IIR Port 2 (port.number is 1)
637
- * Byte 3 IIR Port 3 (port.number is 2)
638
- * Byte 4 IIR Port 4 (port.number is 3)
639
- * Byte 5 FIFO status for both */
640
-
641
- if (length > 5) {
642
- dev_dbg(&urb->dev->dev, "%s", "Wrong data !!!\n");
643
- return;
644
- }
645
-
646
- sp[0] = (__u8) data[0];
647
- sp[1] = (__u8) data[1];
648
- sp[2] = (__u8) data[2];
649
- sp[3] = (__u8) data[3];
650
- st = (__u8) data[4];
651
-
652
- for (i = 0; i < serial->num_ports; i++) {
653
- mos7840_port = mos7840_get_port_private(serial->port[i]);
654
- wval = ((__u16)serial->port[i]->port_number + 1) << 8;
655
- if (mos7840_port->open) {
656
- if (sp[i] & 0x01) {
657
- dev_dbg(&urb->dev->dev, "SP%d No Interrupt !!!\n", i);
658
- } else {
659
- switch (sp[i] & 0x0f) {
660
- case SERIAL_IIR_RLS:
661
- dev_dbg(&urb->dev->dev, "Serial Port %d: Receiver status error or \n", i);
662
- dev_dbg(&urb->dev->dev, "address bit detected in 9-bit mode\n");
663
- mos7840_port->MsrLsr = 1;
664
- wreg = LINE_STATUS_REGISTER;
665
- break;
666
- case SERIAL_IIR_MS:
667
- dev_dbg(&urb->dev->dev, "Serial Port %d: Modem status change\n", i);
668
- mos7840_port->MsrLsr = 0;
669
- wreg = MODEM_STATUS_REGISTER;
670
- break;
671
- }
672
- rv = mos7840_get_reg(mos7840_port, wval, wreg, &Data);
673
- }
674
- }
675
- }
676
- if (!(rv < 0))
677
- /* the completion handler for the control urb will resubmit */
678
- return;
679
-exit:
680
- result = usb_submit_urb(urb, GFP_ATOMIC);
681
- if (result) {
682
- dev_err(&urb->dev->dev,
683
- "%s - Error %d submitting interrupt urb\n",
684
- __func__, result);
685
- }
686
-}
687
-
688
-static int mos7840_port_paranoia_check(struct usb_serial_port *port,
689
- const char *function)
690
-{
691
- if (!port) {
692
- pr_debug("%s - port == NULL\n", function);
693
- return -1;
694
- }
695
- if (!port->serial) {
696
- pr_debug("%s - port->serial == NULL\n", function);
697
- return -1;
698
- }
699
-
700
- return 0;
701
-}
702
-
703
-/* Inline functions to check the sanity of a pointer that is passed to us */
704
-static int mos7840_serial_paranoia_check(struct usb_serial *serial,
705
- const char *function)
706
-{
707
- if (!serial) {
708
- pr_debug("%s - serial == NULL\n", function);
709
- return -1;
710
- }
711
- if (!serial->type) {
712
- pr_debug("%s - serial->type == NULL!\n", function);
713
- return -1;
714
- }
715
-
716
- return 0;
717
-}
718
-
719
-static struct usb_serial *mos7840_get_usb_serial(struct usb_serial_port *port,
720
- const char *function)
721
-{
722
- /* if no port was specified, or it fails a paranoia check */
723
- if (!port ||
724
- mos7840_port_paranoia_check(port, function) ||
725
- mos7840_serial_paranoia_check(port->serial, function)) {
726
- /* then say that we don't have a valid usb_serial thing,
727
- * which will end up genrating -ENODEV return values */
728
- return NULL;
729
- }
730
-
731
- return port->serial;
732
-}
733
-
734
-/*****************************************************************************
735427 * mos7840_bulk_in_callback
736428 * this is the callback function for when we have received data on the
737429 * bulk in endpoint.
....@@ -739,31 +431,14 @@
739431
740432 static void mos7840_bulk_in_callback(struct urb *urb)
741433 {
434
+ struct moschip_port *mos7840_port = urb->context;
435
+ struct usb_serial_port *port = mos7840_port->port;
742436 int retval;
743437 unsigned char *data;
744
- struct usb_serial *serial;
745
- struct usb_serial_port *port;
746
- struct moschip_port *mos7840_port;
747438 int status = urb->status;
748
-
749
- mos7840_port = urb->context;
750
- if (!mos7840_port)
751
- return;
752439
753440 if (status) {
754441 dev_dbg(&urb->dev->dev, "nonzero read bulk status received: %d\n", status);
755
- mos7840_port->read_urb_busy = false;
756
- return;
757
- }
758
-
759
- port = mos7840_port->port;
760
- if (mos7840_port_paranoia_check(port, __func__)) {
761
- mos7840_port->read_urb_busy = false;
762
- return;
763
- }
764
-
765
- serial = mos7840_get_usb_serial(port, __func__);
766
- if (!serial) {
767442 mos7840_port->read_urb_busy = false;
768443 return;
769444 }
....@@ -777,12 +452,6 @@
777452 tty_flip_buffer_push(tport);
778453 port->icount.rx += urb->actual_length;
779454 dev_dbg(&port->dev, "icount.rx is %d:\n", port->icount.rx);
780
- }
781
-
782
- if (!mos7840_port->read_urb) {
783
- dev_dbg(&port->dev, "%s", "URB KILLED !!!\n");
784
- mos7840_port->read_urb_busy = false;
785
- return;
786455 }
787456
788457 if (mos7840_port->has_led)
....@@ -805,14 +474,12 @@
805474
806475 static void mos7840_bulk_out_data_callback(struct urb *urb)
807476 {
808
- struct moschip_port *mos7840_port;
809
- struct usb_serial_port *port;
477
+ struct moschip_port *mos7840_port = urb->context;
478
+ struct usb_serial_port *port = mos7840_port->port;
810479 int status = urb->status;
811480 unsigned long flags;
812481 int i;
813482
814
- mos7840_port = urb->context;
815
- port = mos7840_port->port;
816483 spin_lock_irqsave(&mos7840_port->pool_lock, flags);
817484 for (i = 0; i < NUM_URBS; i++) {
818485 if (urb == mos7840_port->write_urb_pool[i]) {
....@@ -827,11 +494,7 @@
827494 return;
828495 }
829496
830
- if (mos7840_port_paranoia_check(port, __func__))
831
- return;
832
-
833
- if (mos7840_port->open)
834
- tty_port_tty_wakeup(&port->port);
497
+ tty_port_tty_wakeup(&port->port);
835498
836499 }
837500
....@@ -848,32 +511,16 @@
848511
849512 static int mos7840_open(struct tty_struct *tty, struct usb_serial_port *port)
850513 {
514
+ struct moschip_port *mos7840_port = usb_get_serial_port_data(port);
515
+ struct usb_serial *serial = port->serial;
851516 int response;
852517 int j;
853
- struct usb_serial *serial;
854518 struct urb *urb;
855519 __u16 Data;
856520 int status;
857
- struct moschip_port *mos7840_port;
858
- struct moschip_port *port0;
859
-
860
- if (mos7840_port_paranoia_check(port, __func__))
861
- return -ENODEV;
862
-
863
- serial = port->serial;
864
-
865
- if (mos7840_serial_paranoia_check(serial, __func__))
866
- return -ENODEV;
867
-
868
- mos7840_port = mos7840_get_port_private(port);
869
- port0 = mos7840_get_port_private(serial->port[0]);
870
-
871
- if (mos7840_port == NULL || port0 == NULL)
872
- return -ENODEV;
873521
874522 usb_clear_halt(serial->dev, port->write_urb->pipe);
875523 usb_clear_halt(serial->dev, port->read_urb->pipe);
876
- port0->open_ports++;
877524
878525 /* Initialising the write urb pool */
879526 for (j = 0; j < NUM_URBS; ++j) {
....@@ -1024,41 +671,6 @@
1024671 status = mos7840_set_reg_sync(port, mos7840_port->ControlRegOffset,
1025672 Data);
1026673
1027
- /* Check to see if we've set up our endpoint info yet *
1028
- * (can't set it up in mos7840_startup as the structures *
1029
- * were not set up at that time.) */
1030
- if (port0->open_ports == 1) {
1031
- /* FIXME: Buffer never NULL, so URB is not submitted. */
1032
- if (serial->port[0]->interrupt_in_buffer == NULL) {
1033
- /* set up interrupt urb */
1034
- usb_fill_int_urb(serial->port[0]->interrupt_in_urb,
1035
- serial->dev,
1036
- usb_rcvintpipe(serial->dev,
1037
- serial->port[0]->interrupt_in_endpointAddress),
1038
- serial->port[0]->interrupt_in_buffer,
1039
- serial->port[0]->interrupt_in_urb->
1040
- transfer_buffer_length,
1041
- mos7840_interrupt_callback,
1042
- serial,
1043
- serial->port[0]->interrupt_in_urb->interval);
1044
-
1045
- /* start interrupt read for mos7840 */
1046
- response =
1047
- usb_submit_urb(serial->port[0]->interrupt_in_urb,
1048
- GFP_KERNEL);
1049
- if (response) {
1050
- dev_err(&port->dev, "%s - Error %d submitting "
1051
- "interrupt urb\n", __func__, response);
1052
- }
1053
-
1054
- }
1055
-
1056
- }
1057
-
1058
- /* see if we've set up our endpoint info yet *
1059
- * (can't set it up in mos7840_startup as the *
1060
- * structures were not set up at that time.) */
1061
-
1062674 dev_dbg(&port->dev, "port number is %d\n", port->port_number);
1063675 dev_dbg(&port->dev, "minor number is %d\n", port->minor);
1064676 dev_dbg(&port->dev, "Bulkin endpoint is %d\n", port->bulk_in_endpointAddress);
....@@ -1098,9 +710,6 @@
1098710 /* initialize our port settings */
1099711 /* Must set to enable ints! */
1100712 mos7840_port->shadowMCR = MCR_MASTER_IE;
1101
- /* send a open port command */
1102
- mos7840_port->open = 1;
1103
- /* mos7840_change_port_settings(mos7840_port,old_termios); */
1104713
1105714 return 0;
1106715 err:
....@@ -1127,17 +736,10 @@
1127736 static int mos7840_chars_in_buffer(struct tty_struct *tty)
1128737 {
1129738 struct usb_serial_port *port = tty->driver_data;
739
+ struct moschip_port *mos7840_port = usb_get_serial_port_data(port);
1130740 int i;
1131741 int chars = 0;
1132742 unsigned long flags;
1133
- struct moschip_port *mos7840_port;
1134
-
1135
- if (mos7840_port_paranoia_check(port, __func__))
1136
- return 0;
1137
-
1138
- mos7840_port = mos7840_get_port_private(port);
1139
- if (mos7840_port == NULL)
1140
- return 0;
1141743
1142744 spin_lock_irqsave(&mos7840_port->pool_lock, flags);
1143745 for (i = 0; i < NUM_URBS; ++i) {
....@@ -1159,24 +761,9 @@
1159761
1160762 static void mos7840_close(struct usb_serial_port *port)
1161763 {
1162
- struct usb_serial *serial;
1163
- struct moschip_port *mos7840_port;
1164
- struct moschip_port *port0;
764
+ struct moschip_port *mos7840_port = usb_get_serial_port_data(port);
1165765 int j;
1166766 __u16 Data;
1167
-
1168
- if (mos7840_port_paranoia_check(port, __func__))
1169
- return;
1170
-
1171
- serial = mos7840_get_usb_serial(port, __func__);
1172
- if (!serial)
1173
- return;
1174
-
1175
- mos7840_port = mos7840_get_port_private(port);
1176
- port0 = mos7840_get_port_private(serial->port[0]);
1177
-
1178
- if (mos7840_port == NULL || port0 == NULL)
1179
- return;
1180767
1181768 for (j = 0; j < NUM_URBS; ++j)
1182769 usb_kill_urb(mos7840_port->write_urb_pool[j]);
....@@ -1192,22 +779,11 @@
1192779 usb_kill_urb(mos7840_port->read_urb);
1193780 mos7840_port->read_urb_busy = false;
1194781
1195
- port0->open_ports--;
1196
- dev_dbg(&port->dev, "%s in close%d\n", __func__, port0->open_ports);
1197
- if (port0->open_ports == 0) {
1198
- if (serial->port[0]->interrupt_in_urb) {
1199
- dev_dbg(&port->dev, "Shutdown interrupt_in_urb\n");
1200
- usb_kill_urb(serial->port[0]->interrupt_in_urb);
1201
- }
1202
- }
1203
-
1204782 Data = 0x0;
1205783 mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
1206784
1207785 Data = 0x00;
1208786 mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data);
1209
-
1210
- mos7840_port->open = 0;
1211787 }
1212788
1213789 /*****************************************************************************
....@@ -1217,21 +793,8 @@
1217793 static void mos7840_break(struct tty_struct *tty, int break_state)
1218794 {
1219795 struct usb_serial_port *port = tty->driver_data;
796
+ struct moschip_port *mos7840_port = usb_get_serial_port_data(port);
1220797 unsigned char data;
1221
- struct usb_serial *serial;
1222
- struct moschip_port *mos7840_port;
1223
-
1224
- if (mos7840_port_paranoia_check(port, __func__))
1225
- return;
1226
-
1227
- serial = mos7840_get_usb_serial(port, __func__);
1228
- if (!serial)
1229
- return;
1230
-
1231
- mos7840_port = mos7840_get_port_private(port);
1232
-
1233
- if (mos7840_port == NULL)
1234
- return;
1235798
1236799 if (break_state == -1)
1237800 data = mos7840_port->shadowLCR | LCR_SET_BREAK;
....@@ -1256,17 +819,10 @@
1256819 static int mos7840_write_room(struct tty_struct *tty)
1257820 {
1258821 struct usb_serial_port *port = tty->driver_data;
822
+ struct moschip_port *mos7840_port = usb_get_serial_port_data(port);
1259823 int i;
1260824 int room = 0;
1261825 unsigned long flags;
1262
- struct moschip_port *mos7840_port;
1263
-
1264
- if (mos7840_port_paranoia_check(port, __func__))
1265
- return -1;
1266
-
1267
- mos7840_port = mos7840_get_port_private(port);
1268
- if (mos7840_port == NULL)
1269
- return -1;
1270826
1271827 spin_lock_irqsave(&mos7840_port->pool_lock, flags);
1272828 for (i = 0; i < NUM_URBS; ++i) {
....@@ -1292,29 +848,16 @@
1292848 static int mos7840_write(struct tty_struct *tty, struct usb_serial_port *port,
1293849 const unsigned char *data, int count)
1294850 {
851
+ struct moschip_port *mos7840_port = usb_get_serial_port_data(port);
852
+ struct usb_serial *serial = port->serial;
1295853 int status;
1296854 int i;
1297855 int bytes_sent = 0;
1298856 int transfer_size;
1299857 unsigned long flags;
1300
-
1301
- struct moschip_port *mos7840_port;
1302
- struct usb_serial *serial;
1303858 struct urb *urb;
1304859 /* __u16 Data; */
1305860 const unsigned char *current_position = data;
1306
- unsigned char *data1;
1307
-
1308
- if (mos7840_port_paranoia_check(port, __func__))
1309
- return -1;
1310
-
1311
- serial = port->serial;
1312
- if (mos7840_serial_paranoia_check(serial, __func__))
1313
- return -1;
1314
-
1315
- mos7840_port = mos7840_get_port_private(port);
1316
- if (mos7840_port == NULL)
1317
- return -1;
1318861
1319862 /* try to find a free urb in the list */
1320863 urb = NULL;
....@@ -1366,7 +909,6 @@
1366909 mos7840_bulk_out_data_callback, mos7840_port);
1367910 }
1368911
1369
- data1 = urb->transfer_buffer;
1370912 dev_dbg(&port->dev, "bulkout endpoint is %d\n", port->bulk_out_endpointAddress);
1371913
1372914 if (mos7840_port->has_led)
....@@ -1399,21 +941,8 @@
1399941 static void mos7840_throttle(struct tty_struct *tty)
1400942 {
1401943 struct usb_serial_port *port = tty->driver_data;
1402
- struct moschip_port *mos7840_port;
944
+ struct moschip_port *mos7840_port = usb_get_serial_port_data(port);
1403945 int status;
1404
-
1405
- if (mos7840_port_paranoia_check(port, __func__))
1406
- return;
1407
-
1408
- mos7840_port = mos7840_get_port_private(port);
1409
-
1410
- if (mos7840_port == NULL)
1411
- return;
1412
-
1413
- if (!mos7840_port->open) {
1414
- dev_dbg(&port->dev, "%s", "port not opened\n");
1415
- return;
1416
- }
1417946
1418947 /* if we are implementing XON/XOFF, send the stop character */
1419948 if (I_IXOFF(tty)) {
....@@ -1441,19 +970,8 @@
1441970 static void mos7840_unthrottle(struct tty_struct *tty)
1442971 {
1443972 struct usb_serial_port *port = tty->driver_data;
973
+ struct moschip_port *mos7840_port = usb_get_serial_port_data(port);
1444974 int status;
1445
- struct moschip_port *mos7840_port = mos7840_get_port_private(port);
1446
-
1447
- if (mos7840_port_paranoia_check(port, __func__))
1448
- return;
1449
-
1450
- if (mos7840_port == NULL)
1451
- return;
1452
-
1453
- if (!mos7840_port->open) {
1454
- dev_dbg(&port->dev, "%s - port not opened\n", __func__);
1455
- return;
1456
- }
1457975
1458976 /* if we are implementing XON/XOFF, send the start character */
1459977 if (I_IXOFF(tty)) {
....@@ -1476,15 +994,10 @@
1476994 static int mos7840_tiocmget(struct tty_struct *tty)
1477995 {
1478996 struct usb_serial_port *port = tty->driver_data;
1479
- struct moschip_port *mos7840_port;
1480997 unsigned int result;
1481998 __u16 msr;
1482999 __u16 mcr;
14831000 int status;
1484
- mos7840_port = mos7840_get_port_private(port);
1485
-
1486
- if (mos7840_port == NULL)
1487
- return -ENODEV;
14881001
14891002 status = mos7840_get_uart_reg(port, MODEM_STATUS_REGISTER, &msr);
14901003 if (status < 0)
....@@ -1509,14 +1022,9 @@
15091022 unsigned int set, unsigned int clear)
15101023 {
15111024 struct usb_serial_port *port = tty->driver_data;
1512
- struct moschip_port *mos7840_port;
1025
+ struct moschip_port *mos7840_port = usb_get_serial_port_data(port);
15131026 unsigned int mcr;
15141027 int status;
1515
-
1516
- mos7840_port = mos7840_get_port_private(port);
1517
-
1518
- if (mos7840_port == NULL)
1519
- return -ENODEV;
15201028
15211029 /* FIXME: What locks the port registers ? */
15221030 mcr = mos7840_port->shadowMCR;
....@@ -1594,24 +1102,11 @@
15941102 static int mos7840_send_cmd_write_baud_rate(struct moschip_port *mos7840_port,
15951103 int baudRate)
15961104 {
1105
+ struct usb_serial_port *port = mos7840_port->port;
15971106 int divisor = 0;
15981107 int status;
15991108 __u16 Data;
1600
- unsigned char number;
16011109 __u16 clk_sel_val;
1602
- struct usb_serial_port *port;
1603
-
1604
- if (mos7840_port == NULL)
1605
- return -1;
1606
-
1607
- port = mos7840_port->port;
1608
- if (mos7840_port_paranoia_check(port, __func__))
1609
- return -1;
1610
-
1611
- if (mos7840_serial_paranoia_check(port->serial, __func__))
1612
- return -1;
1613
-
1614
- number = mos7840_port->port->port_number;
16151110
16161111 dev_dbg(&port->dev, "%s - baud = %d\n", __func__, baudRate);
16171112 /* reset clk_uart_sel in spregOffset */
....@@ -1700,41 +1195,20 @@
17001195 static void mos7840_change_port_settings(struct tty_struct *tty,
17011196 struct moschip_port *mos7840_port, struct ktermios *old_termios)
17021197 {
1198
+ struct usb_serial_port *port = mos7840_port->port;
17031199 int baud;
17041200 unsigned cflag;
1705
- unsigned iflag;
17061201 __u8 lData;
17071202 __u8 lParity;
17081203 __u8 lStop;
17091204 int status;
17101205 __u16 Data;
1711
- struct usb_serial_port *port;
1712
- struct usb_serial *serial;
1713
-
1714
- if (mos7840_port == NULL)
1715
- return;
1716
-
1717
- port = mos7840_port->port;
1718
-
1719
- if (mos7840_port_paranoia_check(port, __func__))
1720
- return;
1721
-
1722
- if (mos7840_serial_paranoia_check(port->serial, __func__))
1723
- return;
1724
-
1725
- serial = port->serial;
1726
-
1727
- if (!mos7840_port->open) {
1728
- dev_dbg(&port->dev, "%s - port not opened\n", __func__);
1729
- return;
1730
- }
17311206
17321207 lData = LCR_BITS_8;
17331208 lStop = LCR_STOP_1;
17341209 lParity = LCR_PAR_NONE;
17351210
17361211 cflag = tty->termios.c_cflag;
1737
- iflag = tty->termios.c_iflag;
17381212
17391213 /* Change the number of bits */
17401214 switch (cflag & CSIZE) {
....@@ -1863,36 +1337,12 @@
18631337 struct usb_serial_port *port,
18641338 struct ktermios *old_termios)
18651339 {
1340
+ struct moschip_port *mos7840_port = usb_get_serial_port_data(port);
18661341 int status;
1867
- struct usb_serial *serial;
1868
- struct moschip_port *mos7840_port;
1869
-
1870
- if (mos7840_port_paranoia_check(port, __func__))
1871
- return;
1872
-
1873
- serial = port->serial;
1874
-
1875
- if (mos7840_serial_paranoia_check(serial, __func__))
1876
- return;
1877
-
1878
- mos7840_port = mos7840_get_port_private(port);
1879
-
1880
- if (mos7840_port == NULL)
1881
- return;
1882
-
1883
- if (!mos7840_port->open) {
1884
- dev_dbg(&port->dev, "%s - port not opened\n", __func__);
1885
- return;
1886
- }
18871342
18881343 /* change the port settings to the new ones specified */
18891344
18901345 mos7840_change_port_settings(tty, mos7840_port, old_termios);
1891
-
1892
- if (!mos7840_port->read_urb) {
1893
- dev_dbg(&port->dev, "%s", "URB KILLED !!!!!\n");
1894
- return;
1895
- }
18961346
18971347 if (!mos7840_port->read_urb_busy) {
18981348 mos7840_port->read_urb_busy = true;
....@@ -1936,27 +1386,20 @@
19361386 * function to get information about serial port
19371387 *****************************************************************************/
19381388
1939
-static int mos7840_get_serial_info(struct moschip_port *mos7840_port,
1940
- struct serial_struct __user *retinfo)
1389
+static int mos7840_get_serial_info(struct tty_struct *tty,
1390
+ struct serial_struct *ss)
19411391 {
1942
- struct serial_struct tmp;
1392
+ struct usb_serial_port *port = tty->driver_data;
1393
+ struct moschip_port *mos7840_port = usb_get_serial_port_data(port);
19431394
1944
- if (mos7840_port == NULL)
1945
- return -1;
1946
-
1947
- memset(&tmp, 0, sizeof(tmp));
1948
-
1949
- tmp.type = PORT_16550A;
1950
- tmp.line = mos7840_port->port->minor;
1951
- tmp.port = mos7840_port->port->port_number;
1952
- tmp.irq = 0;
1953
- tmp.xmit_fifo_size = NUM_URBS * URB_TRANSFER_BUFFER_SIZE;
1954
- tmp.baud_base = 9600;
1955
- tmp.close_delay = 5 * HZ;
1956
- tmp.closing_wait = 30 * HZ;
1957
-
1958
- if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
1959
- return -EFAULT;
1395
+ ss->type = PORT_16550A;
1396
+ ss->line = mos7840_port->port->minor;
1397
+ ss->port = mos7840_port->port->port_number;
1398
+ ss->irq = 0;
1399
+ ss->xmit_fifo_size = NUM_URBS * URB_TRANSFER_BUFFER_SIZE;
1400
+ ss->baud_base = 9600;
1401
+ ss->close_delay = 5 * HZ;
1402
+ ss->closing_wait = 30 * HZ;
19601403 return 0;
19611404 }
19621405
....@@ -1970,15 +1413,6 @@
19701413 {
19711414 struct usb_serial_port *port = tty->driver_data;
19721415 void __user *argp = (void __user *)arg;
1973
- struct moschip_port *mos7840_port;
1974
-
1975
- if (mos7840_port_paranoia_check(port, __func__))
1976
- return -1;
1977
-
1978
- mos7840_port = mos7840_get_port_private(port);
1979
-
1980
- if (mos7840_port == NULL)
1981
- return -1;
19821416
19831417 switch (cmd) {
19841418 /* return number of bytes available */
....@@ -1987,19 +1421,19 @@
19871421 dev_dbg(&port->dev, "%s TIOCSERGETLSR\n", __func__);
19881422 return mos7840_get_lsr_info(tty, argp);
19891423
1990
- case TIOCGSERIAL:
1991
- dev_dbg(&port->dev, "%s TIOCGSERIAL\n", __func__);
1992
- return mos7840_get_serial_info(mos7840_port, argp);
1993
-
1994
- case TIOCSSERIAL:
1995
- dev_dbg(&port->dev, "%s TIOCSSERIAL\n", __func__);
1996
- break;
19971424 default:
19981425 break;
19991426 }
20001427 return -ENOIOCTLCMD;
20011428 }
20021429
1430
+/*
1431
+ * Check if GPO (pin 42) is connected to GPI (pin 33) as recommended by ASIX
1432
+ * for MCS7810 by bit-banging a 16-bit word.
1433
+ *
1434
+ * Note that GPO is really RTS of the third port so this will toggle RTS of
1435
+ * port two or three on two- and four-port devices.
1436
+ */
20031437 static int mos7810_check(struct usb_serial *serial)
20041438 {
20051439 int i, pass_count = 0;
....@@ -2057,21 +1491,12 @@
20571491 static int mos7840_probe(struct usb_serial *serial,
20581492 const struct usb_device_id *id)
20591493 {
2060
- u16 product = le16_to_cpu(serial->dev->descriptor.idProduct);
2061
- u16 vid = le16_to_cpu(serial->dev->descriptor.idVendor);
1494
+ unsigned long device_flags = id->driver_info;
20621495 u8 *buf;
2063
- int device_type;
20641496
2065
- if (product == MOSCHIP_DEVICE_ID_7810 ||
2066
- product == MOSCHIP_DEVICE_ID_7820) {
2067
- device_type = product;
1497
+ /* Skip device-type detection if we already have device flags. */
1498
+ if (device_flags)
20681499 goto out;
2069
- }
2070
-
2071
- if (vid == USB_VENDOR_ID_MOXA && product == MOXA_DEVICE_ID_2210) {
2072
- device_type = MOSCHIP_DEVICE_ID_7820;
2073
- goto out;
2074
- }
20751500
20761501 buf = kzalloc(VENDOR_READ_LENGTH, GFP_KERNEL);
20771502 if (!buf)
....@@ -2083,15 +1508,15 @@
20831508
20841509 /* For a MCS7840 device GPIO0 must be set to 1 */
20851510 if (buf[0] & 0x01)
2086
- device_type = MOSCHIP_DEVICE_ID_7840;
1511
+ device_flags = MCS_PORTS(4);
20871512 else if (mos7810_check(serial))
2088
- device_type = MOSCHIP_DEVICE_ID_7810;
1513
+ device_flags = MCS_PORTS(1) | MCS_LED;
20891514 else
2090
- device_type = MOSCHIP_DEVICE_ID_7820;
1515
+ device_flags = MCS_PORTS(2);
20911516
20921517 kfree(buf);
20931518 out:
2094
- usb_set_serial_data(serial, (void *)(unsigned long)device_type);
1519
+ usb_set_serial_data(serial, (void *)device_flags);
20951520
20961521 return 0;
20971522 }
....@@ -2099,16 +1524,10 @@
20991524 static int mos7840_calc_num_ports(struct usb_serial *serial,
21001525 struct usb_serial_endpoints *epds)
21011526 {
2102
- int device_type = (unsigned long)usb_get_serial_data(serial);
2103
- int num_ports;
1527
+ unsigned long device_flags = (unsigned long)usb_get_serial_data(serial);
1528
+ int num_ports = MCS_PORTS(device_flags);
21041529
2105
- num_ports = (device_type >> 4) & 0x000F;
2106
-
2107
- /*
2108
- * num_ports is currently never zero as device_type is one of
2109
- * MOSCHIP_DEVICE_ID_78{1,2,4}0.
2110
- */
2111
- if (num_ports == 0)
1530
+ if (num_ports == 0 || num_ports > 4)
21121531 return -ENODEV;
21131532
21141533 if (epds->num_bulk_in < num_ports || epds->num_bulk_out < num_ports) {
....@@ -2119,10 +1538,27 @@
21191538 return num_ports;
21201539 }
21211540
1541
+static int mos7840_attach(struct usb_serial *serial)
1542
+{
1543
+ struct device *dev = &serial->interface->dev;
1544
+ int status;
1545
+ u16 val;
1546
+
1547
+ /* Zero Length flag enable */
1548
+ val = 0x0f;
1549
+ status = mos7840_set_reg_sync(serial->port[0], ZLP_REG5, val);
1550
+ if (status < 0)
1551
+ dev_dbg(dev, "Writing ZLP_REG5 failed status-0x%x\n", status);
1552
+ else
1553
+ dev_dbg(dev, "ZLP_REG5 Writing success status%d\n", status);
1554
+
1555
+ return status;
1556
+}
1557
+
21221558 static int mos7840_port_probe(struct usb_serial_port *port)
21231559 {
21241560 struct usb_serial *serial = port->serial;
2125
- int device_type = (unsigned long)usb_get_serial_data(serial);
1561
+ unsigned long device_flags = (unsigned long)usb_get_serial_data(serial);
21261562 struct moschip_port *mos7840_port;
21271563 int status;
21281564 int pnum;
....@@ -2143,7 +1579,6 @@
21431579 * common to all port */
21441580
21451581 mos7840_port->port = port;
2146
- mos7840_set_port_private(port, mos7840_port);
21471582 spin_lock_init(&mos7840_port->pool_lock);
21481583
21491584 /* minor is not initialised until later by
....@@ -2157,32 +1592,26 @@
21571592 mos7840_port->SpRegOffset = 0x0;
21581593 mos7840_port->ControlRegOffset = 0x1;
21591594 mos7840_port->DcrRegOffset = 0x4;
2160
- } else if ((mos7840_port->port_num == 2) && (serial->num_ports == 4)) {
2161
- mos7840_port->SpRegOffset = 0x8;
2162
- mos7840_port->ControlRegOffset = 0x9;
2163
- mos7840_port->DcrRegOffset = 0x16;
2164
- } else if ((mos7840_port->port_num == 2) && (serial->num_ports == 2)) {
2165
- mos7840_port->SpRegOffset = 0xa;
2166
- mos7840_port->ControlRegOffset = 0xb;
2167
- mos7840_port->DcrRegOffset = 0x19;
2168
- } else if ((mos7840_port->port_num == 3) && (serial->num_ports == 4)) {
2169
- mos7840_port->SpRegOffset = 0xa;
2170
- mos7840_port->ControlRegOffset = 0xb;
2171
- mos7840_port->DcrRegOffset = 0x19;
2172
- } else if ((mos7840_port->port_num == 4) && (serial->num_ports == 4)) {
2173
- mos7840_port->SpRegOffset = 0xc;
2174
- mos7840_port->ControlRegOffset = 0xd;
2175
- mos7840_port->DcrRegOffset = 0x1c;
1595
+ } else {
1596
+ u8 phy_num = mos7840_port->port_num;
1597
+
1598
+ /* Port 2 in the 2-port case uses registers of port 3 */
1599
+ if (serial->num_ports == 2)
1600
+ phy_num = 3;
1601
+
1602
+ mos7840_port->SpRegOffset = 0x8 + 2 * (phy_num - 2);
1603
+ mos7840_port->ControlRegOffset = 0x9 + 2 * (phy_num - 2);
1604
+ mos7840_port->DcrRegOffset = 0x16 + 3 * (phy_num - 2);
21761605 }
21771606 mos7840_dump_serial_port(port, mos7840_port);
2178
- mos7840_set_port_private(port, mos7840_port);
1607
+ usb_set_serial_port_data(port, mos7840_port);
21791608
21801609 /* enable rx_disable bit in control register */
21811610 status = mos7840_get_reg_sync(port,
21821611 mos7840_port->ControlRegOffset, &Data);
21831612 if (status < 0) {
21841613 dev_dbg(&port->dev, "Reading ControlReg failed status-0x%x\n", status);
2185
- goto out;
1614
+ goto error;
21861615 } else
21871616 dev_dbg(&port->dev, "ControlReg Reading success val is %x, status%d\n", Data, status);
21881617 Data |= 0x08; /* setting driver done bit */
....@@ -2194,7 +1623,7 @@
21941623 mos7840_port->ControlRegOffset, Data);
21951624 if (status < 0) {
21961625 dev_dbg(&port->dev, "Writing ControlReg failed(rx_disable) status-0x%x\n", status);
2197
- goto out;
1626
+ goto error;
21981627 } else
21991628 dev_dbg(&port->dev, "ControlReg Writing success(rx_disable) status%d\n", status);
22001629
....@@ -2205,7 +1634,7 @@
22051634 (__u16) (mos7840_port->DcrRegOffset + 0), Data);
22061635 if (status < 0) {
22071636 dev_dbg(&port->dev, "Writing DCR0 failed status-0x%x\n", status);
2208
- goto out;
1637
+ goto error;
22091638 } else
22101639 dev_dbg(&port->dev, "DCR0 Writing success status%d\n", status);
22111640
....@@ -2214,7 +1643,7 @@
22141643 (__u16) (mos7840_port->DcrRegOffset + 1), Data);
22151644 if (status < 0) {
22161645 dev_dbg(&port->dev, "Writing DCR1 failed status-0x%x\n", status);
2217
- goto out;
1646
+ goto error;
22181647 } else
22191648 dev_dbg(&port->dev, "DCR1 Writing success status%d\n", status);
22201649
....@@ -2223,7 +1652,7 @@
22231652 (__u16) (mos7840_port->DcrRegOffset + 2), Data);
22241653 if (status < 0) {
22251654 dev_dbg(&port->dev, "Writing DCR2 failed status-0x%x\n", status);
2226
- goto out;
1655
+ goto error;
22271656 } else
22281657 dev_dbg(&port->dev, "DCR2 Writing success status%d\n", status);
22291658
....@@ -2232,7 +1661,7 @@
22321661 status = mos7840_set_reg_sync(port, CLK_START_VALUE_REGISTER, Data);
22331662 if (status < 0) {
22341663 dev_dbg(&port->dev, "Writing CLK_START_VALUE_REGISTER failed status-0x%x\n", status);
2235
- goto out;
1664
+ goto error;
22361665 } else
22371666 dev_dbg(&port->dev, "CLK_START_VALUE_REGISTER Writing success status%d\n", status);
22381667
....@@ -2249,7 +1678,7 @@
22491678 status = mos7840_set_uart_reg(port, SCRATCH_PAD_REGISTER, Data);
22501679 if (status < 0) {
22511680 dev_dbg(&port->dev, "Writing SCRATCH_PAD_REGISTER failed status-0x%x\n", status);
2252
- goto out;
1681
+ goto error;
22531682 } else
22541683 dev_dbg(&port->dev, "SCRATCH_PAD_REGISTER Writing success status%d\n", status);
22551684
....@@ -2263,7 +1692,7 @@
22631692 (__u16)(ZLP_REG1 + ((__u16) mos7840_port->port_num)));
22641693 if (status < 0) {
22651694 dev_dbg(&port->dev, "Writing ZLP_REG%d failed status-0x%x\n", pnum + 2, status);
2266
- goto out;
1695
+ goto error;
22671696 } else
22681697 dev_dbg(&port->dev, "ZLP_REG%d Writing success status%d\n", pnum + 2, status);
22691698 } else {
....@@ -2275,27 +1704,16 @@
22751704 (__u16)(ZLP_REG1 + ((__u16) mos7840_port->port_num) - 0x1));
22761705 if (status < 0) {
22771706 dev_dbg(&port->dev, "Writing ZLP_REG%d failed status-0x%x\n", pnum + 1, status);
2278
- goto out;
1707
+ goto error;
22791708 } else
22801709 dev_dbg(&port->dev, "ZLP_REG%d Writing success status%d\n", pnum + 1, status);
22811710
22821711 }
2283
- mos7840_port->control_urb = usb_alloc_urb(0, GFP_KERNEL);
2284
- mos7840_port->ctrl_buf = kmalloc(16, GFP_KERNEL);
2285
- mos7840_port->dr = kmalloc(sizeof(struct usb_ctrlrequest),
2286
- GFP_KERNEL);
2287
- if (!mos7840_port->control_urb || !mos7840_port->ctrl_buf ||
2288
- !mos7840_port->dr) {
2289
- status = -ENOMEM;
2290
- goto error;
2291
- }
22921712
2293
- mos7840_port->has_led = false;
1713
+ mos7840_port->has_led = device_flags & MCS_LED;
22941714
22951715 /* Initialize LED timers */
2296
- if (device_type == MOSCHIP_DEVICE_ID_7810) {
2297
- mos7840_port->has_led = true;
2298
-
1716
+ if (mos7840_port->has_led) {
22991717 mos7840_port->led_urb = usb_alloc_urb(0, GFP_KERNEL);
23001718 mos7840_port->led_dr = kmalloc(sizeof(*mos7840_port->led_dr),
23011719 GFP_KERNEL);
....@@ -2315,24 +1733,11 @@
23151733 /* Turn off LED */
23161734 mos7840_set_led_sync(port, MODEM_CONTROL_REGISTER, 0x0300);
23171735 }
2318
-out:
2319
- if (pnum == serial->num_ports - 1) {
2320
- /* Zero Length flag enable */
2321
- Data = 0x0f;
2322
- status = mos7840_set_reg_sync(serial->port[0], ZLP_REG5, Data);
2323
- if (status < 0) {
2324
- dev_dbg(&port->dev, "Writing ZLP_REG5 failed status-0x%x\n", status);
2325
- goto error;
2326
- } else
2327
- dev_dbg(&port->dev, "ZLP_REG5 Writing success status%d\n", status);
2328
- }
1736
+
23291737 return 0;
23301738 error:
23311739 kfree(mos7840_port->led_dr);
23321740 usb_free_urb(mos7840_port->led_urb);
2333
- kfree(mos7840_port->dr);
2334
- kfree(mos7840_port->ctrl_buf);
2335
- usb_free_urb(mos7840_port->control_urb);
23361741 kfree(mos7840_port);
23371742
23381743 return status;
....@@ -2340,9 +1745,7 @@
23401745
23411746 static int mos7840_port_remove(struct usb_serial_port *port)
23421747 {
2343
- struct moschip_port *mos7840_port;
2344
-
2345
- mos7840_port = mos7840_get_port_private(port);
1748
+ struct moschip_port *mos7840_port = usb_get_serial_port_data(port);
23461749
23471750 if (mos7840_port->has_led) {
23481751 /* Turn off LED */
....@@ -2355,10 +1758,7 @@
23551758 usb_free_urb(mos7840_port->led_urb);
23561759 kfree(mos7840_port->led_dr);
23571760 }
2358
- usb_kill_urb(mos7840_port->control_urb);
2359
- usb_free_urb(mos7840_port->control_urb);
2360
- kfree(mos7840_port->ctrl_buf);
2361
- kfree(mos7840_port->dr);
1761
+
23621762 kfree(mos7840_port);
23631763
23641764 return 0;
....@@ -2381,17 +1781,17 @@
23811781 .unthrottle = mos7840_unthrottle,
23821782 .calc_num_ports = mos7840_calc_num_ports,
23831783 .probe = mos7840_probe,
1784
+ .attach = mos7840_attach,
23841785 .ioctl = mos7840_ioctl,
1786
+ .get_serial = mos7840_get_serial_info,
23851787 .set_termios = mos7840_set_termios,
23861788 .break_ctl = mos7840_break,
23871789 .tiocmget = mos7840_tiocmget,
23881790 .tiocmset = mos7840_tiocmset,
2389
- .tiocmiwait = usb_serial_generic_tiocmiwait,
23901791 .get_icount = usb_serial_generic_get_icount,
23911792 .port_probe = mos7840_port_probe,
23921793 .port_remove = mos7840_port_remove,
23931794 .read_bulk_callback = mos7840_bulk_in_callback,
2394
- .read_int_callback = mos7840_interrupt_callback,
23951795 };
23961796
23971797 static struct usb_serial_driver * const serial_drivers[] = {