23 #include <linux/kernel.h>
24 #include <linux/errno.h>
26 #include <linux/slab.h>
27 #include <linux/tty.h>
30 #include <linux/module.h>
32 #include <linux/serial.h>
37 #include <linux/parport.h>
42 #define DRIVER_VERSION "2.1"
43 #define DRIVER_AUTHOR "Aspire Communications pvt Ltd."
44 #define DRIVER_DESC "Moschip USB Serial Driver"
47 #define MOS_WDR_TIMEOUT (HZ * 5)
49 #define MOS_MAX_PORT 0x02
50 #define MOS_WRITE 0x0E
54 #define SERIAL_IIR_RLS 0x06
55 #define SERIAL_IIR_RDA 0x04
56 #define SERIAL_IIR_CTI 0x0c
57 #define SERIAL_IIR_THR 0x02
58 #define SERIAL_IIR_MS 0x00
61 #define URB_TRANSFER_BUFFER_SIZE 32
76 #define USB_VENDOR_ID_MOSCHIP 0x9710
77 #define MOSCHIP_DEVICE_ID_7720 0x7720
78 #define MOSCHIP_DEVICE_ID_7715 0x7715
87 #ifdef CONFIG_USB_SERIAL_MOS7715_PARPORT
90 #define DCR_INIT_VAL 0x0c
91 #define ECR_INIT_VAL 0x00
94 struct mos7715_parport *mos_parport;
96 struct kref ref_count;
100 enum mos7715_pp_modes {
106 struct mos7715_parport {
108 struct kref ref_count;
126 static const unsigned int dummy;
157 static const __u16 mos7715_index_lookup_table[] = {
179 return mos7715_index_lookup_table[
reg];
187 unsigned int serial_portnum)
196 return (serial_portnum + 2) << 8;
204 static int write_mos_reg(
struct usb_serial *
serial,
unsigned int serial_portnum,
207 struct usb_device *usbdev = serial->
dev;
208 unsigned int pipe = usb_sndctrlpipe(usbdev, 0);
217 "mos7720: usb_control_msg() failed: %d", status);
226 static int read_mos_reg(
struct usb_serial *serial,
unsigned int serial_portnum,
229 struct usb_device *usbdev = serial->
dev;
230 unsigned int pipe = usb_rcvctrlpipe(usbdev, 0);
233 __u16 index = get_reg_index(reg);
234 __u16 value = get_reg_value(reg, serial_portnum);
235 int status =
usb_control_msg(usbdev, pipe, request, requesttype, value,
239 "mos7720: usb_control_msg() failed: %d", status);
243 #ifdef CONFIG_USB_SERIAL_MOS7715_PARPORT
245 static inline int mos7715_change_mode(
struct mos7715_parport *mos_parport,
246 enum mos7715_pp_modes
mode)
248 mos_parport->shadowECR =
mode;
249 write_mos_reg(mos_parport->serial,
dummy,
ECR, mos_parport->shadowECR);
253 static void destroy_mos_parport(
struct kref *
kref)
255 struct mos7715_parport *mos_parport =
261 static void destroy_urbtracker(
struct kref *
kref)
263 struct urbtracker *urbtrack =
265 struct mos7715_parport *mos_parport = urbtrack->mos_parport;
269 kref_put(&mos_parport->ref_count, destroy_mos_parport);
277 static void send_deferred_urbs(
unsigned long _mos_parport)
281 struct mos7715_parport *mos_parport = (
void *)_mos_parport;
282 struct urbtracker *urbtrack, *
tmp;
290 dev = &mos_parport->serial->dev->dev;
294 dev_dbg(dev,
"%s: rescheduling tasklet\n", __func__);
295 tasklet_schedule(&mos_parport->urb_tasklet);
300 if (
unlikely(mos_parport->serial->disconnected)) {
306 if (list_empty(&mos_parport->deferred_urbs)) {
307 spin_unlock_irqrestore(&mos_parport->listlock, flags);
309 dev_dbg(dev,
"%s: deferred_urbs list empty\n", __func__);
315 list_move_tail(cursor, &mos_parport->active_urbs);
319 dev_dbg(dev,
"%s: urb submitted\n", __func__);
321 dev_err(dev,
"usb_submit_urb() failed: %d\n", ret_val);
323 kref_put(&urbtrack->ref_count, destroy_urbtracker);
326 spin_unlock_irqrestore(&mos_parport->listlock, flags);
331 static void async_complete(
struct urb *
urb)
333 struct urbtracker *urbtrack = urb->context;
334 int status = urb->status;
337 dev_dbg(&urb->dev->dev,
"%s - nonzero urb status received: %d\n", __func__, status);
340 spin_lock(&urbtrack->mos_parport->listlock);
342 spin_unlock(&urbtrack->mos_parport->listlock);
343 kref_put(&urbtrack->ref_count, destroy_urbtracker);
346 static int write_parport_reg_nonblock(
struct mos7715_parport *mos_parport,
349 struct urbtracker *urbtrack;
353 struct usb_serial *serial = mos_parport->serial;
354 struct usb_device *usbdev = serial->
dev;
358 if (urbtrack ==
NULL) {
359 dev_err(&usbdev->dev,
"out of memory");
362 kref_get(&mos_parport->ref_count);
363 urbtrack->mos_parport = mos_parport;
365 if (urbtrack->urb ==
NULL) {
366 dev_err(&usbdev->dev,
"out of urbs");
373 setup.wIndex = get_reg_index(reg);
375 usb_fill_control_urb(urbtrack->urb, usbdev,
376 usb_sndctrlpipe(usbdev, 0),
377 (
unsigned char *)&
setup,
378 NULL, 0, async_complete, urbtrack);
379 kref_init(&urbtrack->ref_count);
380 INIT_LIST_HEAD(&urbtrack->urblist_entry);
389 &mos_parport->deferred_urbs);
390 spin_unlock_irqrestore(&mos_parport->listlock, flags);
391 tasklet_schedule(&mos_parport->urb_tasklet);
392 dev_dbg(&usbdev->dev,
"tasklet scheduled");
398 kref_put(&urbtrack->ref_count, destroy_urbtracker);
405 list_add_tail(&urbtrack->urblist_entry, &mos_parport->active_urbs);
406 spin_unlock_irqrestore(&mos_parport->listlock, flags);
411 "%s: submit_urb() failed: %d", __func__, ret_val);
414 spin_unlock_irqrestore(&mos_parport->listlock, flags);
415 kref_put(&urbtrack->ref_count, destroy_urbtracker);
433 static int parport_prologue(
struct parport *
pp)
435 struct mos7715_parport *mos_parport;
437 spin_lock(&release_lock);
441 spin_unlock(&release_lock);
444 mos_parport->msg_pending =
true;
446 spin_unlock(&release_lock);
449 if (mos_parport->serial->disconnected) {
452 mos_parport->msg_pending =
false;
453 complete(&mos_parport->syncmsg_compl);
464 static inline void parport_epilogue(
struct parport *pp)
468 mos_parport->msg_pending =
false;
469 complete(&mos_parport->syncmsg_compl);
472 static void parport_mos7715_write_data(
struct parport *pp,
unsigned char d)
476 if (parport_prologue(pp) < 0)
478 mos7715_change_mode(mos_parport,
SPP);
479 write_mos_reg(mos_parport->serial,
dummy,
DPR, (
__u8)d);
480 parport_epilogue(pp);
483 static unsigned char parport_mos7715_read_data(
struct parport *pp)
488 if (parport_prologue(pp) < 0)
490 read_mos_reg(mos_parport->serial,
dummy,
DPR, &d);
491 parport_epilogue(pp);
495 static void parport_mos7715_write_control(
struct parport *pp,
unsigned char d)
500 if (parport_prologue(pp) < 0)
502 data = ((
__u8)d & 0x0f) | (mos_parport->shadowDCR & 0xf0);
503 write_mos_reg(mos_parport->serial,
dummy,
DCR, data);
504 mos_parport->shadowDCR =
data;
505 parport_epilogue(pp);
508 static unsigned char parport_mos7715_read_control(
struct parport *pp)
513 spin_lock(&release_lock);
516 spin_unlock(&release_lock);
519 dcr = mos_parport->shadowDCR & 0x0f;
520 spin_unlock(&release_lock);
524 static unsigned char parport_mos7715_frob_control(
struct parport *pp,
533 if (parport_prologue(pp) < 0)
535 mos_parport->shadowDCR = (mos_parport->shadowDCR & (~mask)) ^
val;
536 write_mos_reg(mos_parport->serial,
dummy,
DCR, mos_parport->shadowDCR);
537 dcr = mos_parport->shadowDCR & 0x0f;
538 parport_epilogue(pp);
542 static unsigned char parport_mos7715_read_status(
struct parport *pp)
547 spin_lock(&release_lock);
550 spin_unlock(&release_lock);
553 status =
atomic_read(&mos_parport->shadowDSR) & 0xf8;
554 spin_unlock(&release_lock);
558 static void parport_mos7715_enable_irq(
struct parport *pp)
562 static void parport_mos7715_disable_irq(
struct parport *pp)
566 static void parport_mos7715_data_forward(
struct parport *pp)
570 if (parport_prologue(pp) < 0)
572 mos7715_change_mode(mos_parport, PS2);
573 mos_parport->shadowDCR &= ~0x20;
574 write_mos_reg(mos_parport->serial,
dummy,
DCR, mos_parport->shadowDCR);
575 parport_epilogue(pp);
578 static void parport_mos7715_data_reverse(
struct parport *pp)
582 if (parport_prologue(pp) < 0)
584 mos7715_change_mode(mos_parport, PS2);
585 mos_parport->shadowDCR |= 0x20;
586 write_mos_reg(mos_parport->serial,
dummy,
DCR, mos_parport->shadowDCR);
587 parport_epilogue(pp);
590 static void parport_mos7715_init_state(
struct pardevice *dev,
593 s->
u.
pc.ctr = DCR_INIT_VAL;
594 s->
u.
pc.ecr = ECR_INIT_VAL;
598 static void parport_mos7715_save_state(
struct parport *pp,
601 struct mos7715_parport *mos_parport;
603 spin_lock(&release_lock);
606 spin_unlock(&release_lock);
609 s->
u.
pc.ctr = mos_parport->shadowDCR;
610 s->
u.
pc.ecr = mos_parport->shadowECR;
611 spin_unlock(&release_lock);
615 static void parport_mos7715_restore_state(
struct parport *pp,
618 struct mos7715_parport *mos_parport;
620 spin_lock(&release_lock);
623 spin_unlock(&release_lock);
626 write_parport_reg_nonblock(mos_parport,
DCR, mos_parport->shadowDCR);
627 write_parport_reg_nonblock(mos_parport,
ECR, mos_parport->shadowECR);
628 spin_unlock(&release_lock);
631 static size_t parport_mos7715_write_compat(
struct parport *pp,
633 size_t len,
int flags)
639 if (parport_prologue(pp) < 0)
641 mos7715_change_mode(mos_parport, PPF);
643 usb_sndbulkpipe(mos_parport->serial->dev, 2),
644 (
void *)buffer, len, &actual_len,
646 parport_epilogue(pp);
648 dev_err(&mos_parport->serial->dev->dev,
649 "mos7720: usb_bulk_msg() failed: %d", retval);
657 .write_data = parport_mos7715_write_data,
658 .read_data = parport_mos7715_read_data,
660 .write_control = parport_mos7715_write_control,
661 .read_control = parport_mos7715_read_control,
662 .frob_control = parport_mos7715_frob_control,
664 .read_status = parport_mos7715_read_status,
666 .enable_irq = parport_mos7715_enable_irq,
667 .disable_irq = parport_mos7715_disable_irq,
669 .data_forward = parport_mos7715_data_forward,
670 .data_reverse = parport_mos7715_data_reverse,
672 .init_state = parport_mos7715_init_state,
673 .save_state = parport_mos7715_save_state,
674 .restore_state = parport_mos7715_restore_state,
676 .compat_write_data = parport_mos7715_write_compat,
686 static int mos7715_parport_init(
struct usb_serial *serial)
688 struct mos7715_parport *mos_parport;
691 mos_parport = kzalloc(
sizeof(
struct mos7715_parport),
GFP_KERNEL);
692 if (mos_parport ==
NULL) {
693 dev_dbg(&serial->
dev->dev,
"%s: kzalloc failed\n", __func__);
696 mos_parport->msg_pending =
false;
697 kref_init(&mos_parport->ref_count);
699 INIT_LIST_HEAD(&mos_parport->active_urbs);
700 INIT_LIST_HEAD(&mos_parport->deferred_urbs);
701 usb_set_serial_data(serial, mos_parport);
702 mos_parport->serial =
serial;
703 tasklet_init(&mos_parport->urb_tasklet, send_deferred_urbs,
704 (
unsigned long) mos_parport);
705 init_completion(&mos_parport->syncmsg_compl);
712 mos_parport->shadowDCR = DCR_INIT_VAL;
713 write_mos_reg(mos_parport->serial,
dummy,
DCR, mos_parport->shadowDCR);
714 mos_parport->shadowECR = ECR_INIT_VAL;
715 write_mos_reg(mos_parport->serial,
dummy,
ECR, mos_parport->shadowECR);
720 &parport_mos7715_ops);
721 if (mos_parport->pp ==
NULL) {
723 "Could not register parport\n");
724 kref_put(&mos_parport->ref_count, destroy_mos_parport);
727 mos_parport->pp->private_data = mos_parport;
729 mos_parport->pp->dev = &serial->
interface->dev;
741 static void mos7720_interrupt_callback(
struct urb *urb)
745 int status = urb->status;
746 struct device *dev = &urb->dev->dev;
759 dev_dbg(dev,
"%s - urb shutting down with status: %d\n", __func__, status);
762 dev_dbg(dev,
"%s - nonzero urb status received: %d\n", __func__, status);
766 length = urb->actual_length;
767 data = urb->transfer_buffer;
779 dev_dbg(dev,
"Wrong data !!!\n");
786 if ((sp1 | sp2) & 0x01) {
788 dev_dbg(dev,
"No Interrupt !!!\n");
790 switch (sp1 & 0x0f) {
792 dev_dbg(dev,
"Serial Port 1: Receiver status error or address bit detected in 9-bit mode\n");
795 dev_dbg(dev,
"Serial Port 1: Receiver time out\n");
802 switch (sp2 & 0x0f) {
804 dev_dbg(dev,
"Serial Port 2: Receiver status error or address bit detected in 9-bit mode\n");
807 dev_dbg(dev,
"Serial Port 2: Receiver time out\n");
818 dev_err(dev,
"%s - Error %d submitting control urb\n", __func__, result);
826 static void mos7715_interrupt_callback(
struct urb *urb)
830 int status = urb->status;
831 struct device *dev = &urb->dev->dev;
844 dev_dbg(dev,
"%s - urb shutting down with status: %d\n", __func__, status);
847 dev_dbg(dev,
"%s - nonzero urb status received: %d\n", __func__, status);
851 length = urb->actual_length;
852 data = urb->transfer_buffer;
861 dev_dbg(dev,
"Wrong data !!!\n");
867 switch (iir & 0x0f) {
869 dev_dbg(dev,
"Serial Port: Receiver status error or address bit detected in 9-bit mode\n\n");
872 dev_dbg(dev,
"Serial Port: Receiver time out\n");
880 #ifdef CONFIG_USB_SERIAL_MOS7715_PARPORT
883 struct mos7715_parport *mos_parport = port->
serial->private;
893 dev_err(dev,
"%s - Error %d submitting control urb\n", __func__, result);
901 static void mos7720_bulk_in_callback(
struct urb *urb)
904 unsigned char *
data ;
907 int status = urb->status;
910 dev_dbg(&urb->dev->dev,
"nonzero read bulk status received: %d\n", status);
916 dev_dbg(&port->
dev,
"Entering...%s\n", __func__);
918 data = urb->transfer_buffer;
921 if (tty && urb->actual_length) {
922 tty_insert_flip_string(tty, data, urb->actual_length);
930 dev_dbg(&port->
dev,
"usb_submit_urb(read bulk) failed, retval = %d\n", retval);
939 static void mos7720_bulk_out_data_callback(
struct urb *urb)
943 int status = urb->status;
946 dev_dbg(&urb->dev->dev,
"nonzero write bulk status received:%d\n", status);
950 mos7720_port = urb->context;
952 dev_dbg(&urb->dev->dev,
"NULL mos7720_port pointer\n");
958 if (tty && mos7720_port->
open)
969 static int mos77xx_probe(
struct usb_serial *serial,
973 moschip7720_2port_driver.read_int_callback =
974 mos7715_interrupt_callback;
976 moschip7720_2port_driver.read_int_callback =
977 mos7720_interrupt_callback;
982 static int mos77xx_calc_num_ports(
struct usb_serial *serial)
999 int allocated_urbs = 0;
1004 mos7720_port = usb_get_serial_port_data(port);
1005 if (mos7720_port ==
NULL)
1023 if (!urb->transfer_buffer) {
1025 "%s-out of memory for urb buffers.\n",
1034 if (!allocated_urbs)
1052 read_mos_reg(serial, port_number,
LSR, &data);
1054 dev_dbg(&port->
dev,
"SS::%p LSR:%x\n", mos7720_port, data);
1059 write_mos_reg(serial, port_number,
IER, 0x00);
1060 write_mos_reg(serial, port_number,
FCR, 0x00);
1062 write_mos_reg(serial, port_number,
FCR, 0xcf);
1064 write_mos_reg(serial, port_number,
LCR, mos7720_port->
shadowLCR);
1066 write_mos_reg(serial, port_number,
MCR, mos7720_port->
shadowMCR);
1070 data = data | (port->
number - port->
serial->minor + 1);
1073 write_mos_reg(serial, port_number,
LCR, mos7720_port->
shadowLCR);
1074 write_mos_reg(serial, port_number,
THR, 0x0c);
1075 write_mos_reg(serial, port_number,
IER, 0x00);
1077 write_mos_reg(serial, port_number,
LCR, mos7720_port->
shadowLCR);
1078 write_mos_reg(serial, port_number,
IER, 0x0c);
1082 dev_err(&port->
dev,
"%s - Error %d submitting read urb\n",
1083 __func__, response);
1092 mos7720_port->
open = 1;
1106 static int mos7720_chars_in_buffer(
struct tty_struct *tty)
1113 mos7720_port = usb_get_serial_port_data(port);
1114 if (mos7720_port ==
NULL)
1122 dev_dbg(&port->
dev,
"%s - returns %d\n", __func__, chars);
1134 mos7720_port = usb_get_serial_port_data(port);
1135 if (mos7720_port ==
NULL)
1158 write_mos_reg(serial, port->
number - port->
serial->minor,
1160 write_mos_reg(serial, port->
number - port->
serial->minor,
1164 mos7720_port->
open = 0;
1167 static void mos7720_break(
struct tty_struct *tty,
int break_state)
1176 mos7720_port = usb_get_serial_port_data(port);
1177 if (mos7720_port ==
NULL)
1180 if (break_state == -1)
1186 write_mos_reg(serial, port->
number - port->
serial->minor,
1197 static int mos7720_write_room(
struct tty_struct *tty)
1204 mos7720_port = usb_get_serial_port_data(port);
1205 if (mos7720_port ==
NULL)
1215 dev_dbg(&port->
dev,
"%s - returns %d\n", __func__, room);
1220 const unsigned char *data,
int count)
1230 const unsigned char *current_position =
data;
1234 mos7720_port = usb_get_serial_port_data(port);
1235 if (mos7720_port ==
NULL)
1251 dev_dbg(&port->
dev,
"%s - no more free urbs\n", __func__);
1255 if (urb->transfer_buffer ==
NULL) {
1258 if (urb->transfer_buffer ==
NULL) {
1266 memcpy(urb->transfer_buffer, current_position, transfer_size);
1267 usb_serial_debug_data(&port->
dev, __func__, transfer_size,
1268 urb->transfer_buffer);
1271 usb_fill_bulk_urb(urb, serial->
dev,
1272 usb_sndbulkpipe(serial->
dev,
1274 urb->transfer_buffer, transfer_size,
1275 mos7720_bulk_out_data_callback, mos7720_port);
1281 "with status = %d\n", __func__, status);
1291 static void mos7720_throttle(
struct tty_struct *tty)
1297 mos7720_port = usb_get_serial_port_data(port);
1299 if (mos7720_port ==
NULL)
1302 if (!mos7720_port->
open) {
1303 dev_dbg(&port->
dev,
"%s - port not opened\n", __func__);
1309 unsigned char stop_char =
STOP_CHAR(tty);
1310 status = mos7720_write(tty, port, &stop_char, 1);
1316 if (tty->termios.c_cflag &
CRTSCTS) {
1325 static void mos7720_unthrottle(
struct tty_struct *tty)
1328 struct moschip_port *mos7720_port = usb_get_serial_port_data(port);
1331 if (mos7720_port ==
NULL)
1334 if (!mos7720_port->
open) {
1335 dev_dbg(&port->
dev,
"%s - port not opened\n", __func__);
1342 status = mos7720_write(tty, port, &start_char, 1);
1348 if (tty->termios.c_cflag &
CRTSCTS) {
1358 static int set_higher_rates(
struct moschip_port *mos7720_port,
1365 if (mos7720_port ==
NULL)
1368 port = mos7720_port->
port;
1374 dev_dbg(&port->
dev,
"Sending Setting Commands ..........\n");
1377 write_mos_reg(serial, port_number,
IER, 0x00);
1378 write_mos_reg(serial, port_number,
FCR, 0x00);
1379 write_mos_reg(serial, port_number,
FCR, 0xcf);
1381 write_mos_reg(serial, port_number,
MCR, mos7720_port->
shadowMCR);
1388 if (port_number == 0)
1392 write_mos_reg(serial,
dummy, sp_reg, baud * 0x10);
1395 write_mos_reg(serial, port_number,
MCR, mos7720_port->
shadowMCR);
1401 write_mos_reg(serial, port_number,
LCR, mos7720_port->
shadowLCR);
1402 write_mos_reg(serial, port_number,
DLL, 0x01);
1403 write_mos_reg(serial, port_number,
DLM, 0x00);
1405 write_mos_reg(serial, port_number,
LCR, mos7720_port->
shadowLCR);
1451 dev_dbg(&port->
dev,
"%s - %d\n", __func__, baudrate);
1453 for (i = 0; i <
ARRAY_SIZE(divisor_table); i++) {
1454 if (divisor_table[i].baudrate == baudrate) {
1455 *divisor = divisor_table[
i].
divisor;
1462 if (baudrate > 75 && baudrate < 230400) {
1464 custom = (
__u16)(230400L / baudrate);
1467 round1 = (
__u16)(2304000L / baudrate);
1468 round = (
__u16)(round1 - (custom * 10));
1473 dev_dbg(&port->
dev,
"Baud %d = %d\n", baudrate, custom);
1477 dev_dbg(&port->
dev,
"Baud calculation Failed...\n");
1486 static int send_cmd_write_baud_rate(
struct moschip_port *mos7720_port,
1495 if (mos7720_port ==
NULL)
1498 port = mos7720_port->
port;
1502 dev_dbg(&port->
dev,
"%s - baud = %d\n", __func__, baudrate);
1505 status = calc_baud_rate_divisor(port, baudrate, &divisor);
1507 dev_err(&port->
dev,
"%s - bad baud rate\n", __func__);
1513 write_mos_reg(serial, number,
LCR, mos7720_port->
shadowLCR);
1516 write_mos_reg(serial, number,
DLL, (
__u8)(divisor & 0xff));
1517 write_mos_reg(serial, number,
DLM, (
__u8)((divisor & 0xff00) >> 8));
1521 write_mos_reg(serial, number,
LCR, mos7720_port->
shadowLCR);
1531 static void change_port_settings(
struct tty_struct *tty,
1547 if (mos7720_port ==
NULL)
1550 port = mos7720_port->
port;
1554 if (!mos7720_port->
open) {
1555 dev_dbg(&port->
dev,
"%s - port not opened\n", __func__);
1563 cflag = tty->termios.c_cflag;
1564 iflag = tty->termios.c_iflag;
1567 switch (cflag &
CSIZE) {
1592 dev_dbg(&port->
dev,
"%s - parity = odd\n", __func__);
1595 dev_dbg(&port->
dev,
"%s - parity = even\n", __func__);
1599 dev_dbg(&port->
dev,
"%s - parity = none\n", __func__);
1603 lParity = lParity | 0x20;
1608 dev_dbg(&port->
dev,
"%s - stop bits = 2\n", __func__);
1611 dev_dbg(&port->
dev,
"%s - stop bits = 1\n", __func__);
1614 #define LCR_BITS_MASK 0x03
1615 #define LCR_STOP_MASK 0x04
1616 #define LCR_PAR_MASK 0x38
1621 mos7720_port->
shadowLCR |= (lData | lParity | lStop);
1625 write_mos_reg(serial, port_number,
IER, 0x00);
1626 write_mos_reg(serial, port_number,
FCR, 0x00);
1627 write_mos_reg(serial, port_number,
FCR, 0xcf);
1630 write_mos_reg(serial, port_number,
LCR, mos7720_port->
shadowLCR);
1632 write_mos_reg(serial, port_number,
MCR, mos7720_port->
shadowMCR);
1651 write_mos_reg(serial, port_number,
MCR, mos7720_port->
shadowMCR);
1657 dev_dbg(&port->
dev,
"Picked default baud...\n");
1661 if (baud >= 230400) {
1662 set_higher_rates(mos7720_port, baud);
1664 write_mos_reg(serial, port_number,
IER, 0x0c);
1668 dev_dbg(&port->
dev,
"%s - baud rate = %d\n", __func__, baud);
1669 status = send_cmd_write_baud_rate(mos7720_port, baud);
1675 write_mos_reg(serial, port_number,
IER, 0x0c);
1680 dev_dbg(&port->
dev,
"usb_submit_urb(read bulk) failed, status = %d\n", status);
1689 static void mos7720_set_termios(
struct tty_struct *tty,
1699 mos7720_port = usb_get_serial_port_data(port);
1701 if (mos7720_port ==
NULL)
1704 if (!mos7720_port->
open) {
1705 dev_dbg(&port->
dev,
"%s - port not opened\n", __func__);
1709 dev_dbg(&port->
dev,
"setting termios - ASPIRE\n");
1711 cflag = tty->termios.c_cflag;
1713 dev_dbg(&port->
dev,
"%s - cflag %08x iflag %08x\n", __func__,
1716 dev_dbg(&port->
dev,
"%s - old cflag %08x old iflag %08x\n", __func__,
1720 change_port_settings(tty, mos7720_port, old_termios);
1725 dev_dbg(&port->
dev,
"usb_submit_urb(read bulk) failed, status = %d\n", status);
1739 static int get_lsr_info(
struct tty_struct *tty,
1740 struct moschip_port *mos7720_port,
unsigned int __user *value)
1743 unsigned int result = 0;
1744 unsigned char data = 0;
1748 count = mos7720_chars_in_buffer(tty);
1750 read_mos_reg(port->
serial, port_number,
LSR, &data);
1753 dev_dbg(&port->
dev,
"%s -- Empty\n", __func__);
1762 static int mos7720_tiocmget(
struct tty_struct *tty)
1765 struct moschip_port *mos7720_port = usb_get_serial_port_data(port);
1766 unsigned int result = 0;
1783 static int mos7720_tiocmset(
struct tty_struct *tty,
1784 unsigned int set,
unsigned int clear)
1787 struct moschip_port *mos7720_port = usb_get_serial_port_data(port);
1813 static int mos7720_get_icount(
struct tty_struct *tty,
1820 mos7720_port = usb_get_serial_port_data(port);
1821 cnow = mos7720_port->icount;
1823 icount->
cts = cnow.cts;
1824 icount->
dsr = cnow.dsr;
1825 icount->
rng = cnow.rng;
1826 icount->
dcd = cnow.dcd;
1827 icount->
rx = cnow.rx;
1828 icount->
tx = cnow.tx;
1829 icount->
frame = cnow.frame;
1830 icount->
overrun = cnow.overrun;
1831 icount->
parity = cnow.parity;
1832 icount->
brk = cnow.brk;
1835 dev_dbg(&port->
dev,
"%s TIOCGICOUNT RX=%d, TX=%d\n", __func__,
1836 icount->
rx, icount->
tx);
1840 static int set_modem_info(
struct moschip_port *mos7720_port,
unsigned int cmd,
1841 unsigned int __user *value)
1848 if (mos7720_port ==
NULL)
1859 if (arg & TIOCM_RTS)
1861 if (arg & TIOCM_DTR)
1868 if (arg & TIOCM_RTS)
1870 if (arg & TIOCM_DTR)
1872 if (arg & TIOCM_LOOP)
1885 static int get_serial_info(
struct moschip_port *mos7720_port,
1893 memset(&tmp, 0,
sizeof(tmp));
1896 tmp.line = mos7720_port->
port->serial->minor;
1897 tmp.port = mos7720_port->
port->number;
1901 tmp.baud_base = 9600;
1902 tmp.close_delay = 5*
HZ;
1903 tmp.closing_wait = 30*
HZ;
1910 static int mos7720_ioctl(
struct tty_struct *tty,
1911 unsigned int cmd,
unsigned long arg)
1918 mos7720_port = usb_get_serial_port_data(port);
1919 if (mos7720_port ==
NULL)
1922 dev_dbg(&port->
dev,
"%s - cmd = 0x%x", __func__, cmd);
1926 dev_dbg(&port->
dev,
"%s TIOCSERGETLSR\n", __func__);
1927 return get_lsr_info(tty, mos7720_port,
1928 (
unsigned int __user *)arg);
1933 dev_dbg(&port->
dev,
"%s TIOCMSET/TIOCMBIC/TIOCMSET\n", __func__);
1934 return set_modem_info(mos7720_port, cmd,
1935 (
unsigned int __user *)arg);
1938 dev_dbg(&port->
dev,
"%s TIOCGSERIAL\n", __func__);
1939 return get_serial_info(mos7720_port,
1943 dev_dbg(&port->
dev,
"%s TIOCMIWAIT\n", __func__);
1944 cprev = mos7720_port->icount;
1948 cnow = mos7720_port->icount;
1949 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
1950 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts)
1952 if (((arg &
TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
1953 ((arg &
TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
1954 ((arg &
TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
1955 ((arg &
TIOCM_CTS) && (cnow.cts != cprev.cts))) {
1967 static int mos7720_startup(
struct usb_serial *serial)
1969 struct usb_device *
dev;
1994 serial->
port[0]->interrupt_in_endpointAddress =
1996 serial->
port[1]->interrupt_in_urb =
NULL;
1997 serial->
port[1]->interrupt_in_buffer =
NULL;
2002 (
__u8)0x03, 0x00, 0x01, 0x00,
NULL, 0x00, 5*
HZ);
2008 "%s - Error %d submitting control urb\n",
2011 #ifdef CONFIG_USB_SERIAL_MOS7715_PARPORT
2013 ret_val = mos7715_parport_init(serial);
2019 read_mos_reg(serial, 0,
LSR, &data);
2020 dev_dbg(&dev->dev,
"LSR:%x\n", data);
2025 static void mos7720_release(
struct usb_serial *serial)
2027 #ifdef CONFIG_USB_SERIAL_MOS7715_PARPORT
2032 struct urbtracker *urbtrack;
2033 unsigned long flags;
2034 struct mos7715_parport *mos_parport =
2035 usb_get_serial_data(serial);
2038 spin_lock(&release_lock);
2039 mos_parport->pp->private_data =
NULL;
2040 spin_unlock(&release_lock);
2043 if (mos_parport->msg_pending)
2048 usb_set_serial_data(serial,
NULL);
2049 mos_parport->serial =
NULL;
2057 &mos_parport->active_urbs,
2060 spin_unlock_irqrestore(&mos_parport->listlock, flags);
2062 kref_put(&mos_parport->ref_count, destroy_mos_parport);
2071 mos7720_port = kzalloc(
sizeof(*mos7720_port),
GFP_KERNEL);
2079 port->
serial->port[0]->interrupt_in_endpointAddress;
2082 usb_set_serial_port_data(port, mos7720_port);
2091 mos7720_port = usb_get_serial_port_data(port);
2092 kfree(mos7720_port);
2100 .name =
"moschip7720",
2102 .description =
"Moschip 2 port adapter",
2104 .calc_num_ports = mos77xx_calc_num_ports,
2105 .open = mos7720_open,
2106 .close = mos7720_close,
2107 .throttle = mos7720_throttle,
2108 .unthrottle = mos7720_unthrottle,
2109 .probe = mos77xx_probe,
2110 .attach = mos7720_startup,
2111 .release = mos7720_release,
2112 .port_probe = mos7720_port_probe,
2113 .port_remove = mos7720_port_remove,
2114 .ioctl = mos7720_ioctl,
2115 .tiocmget = mos7720_tiocmget,
2116 .tiocmset = mos7720_tiocmset,
2117 .get_icount = mos7720_get_icount,
2118 .set_termios = mos7720_set_termios,
2119 .write = mos7720_write,
2120 .write_room = mos7720_write_room,
2121 .chars_in_buffer = mos7720_chars_in_buffer,
2122 .break_ctl = mos7720_break,
2123 .read_bulk_callback = mos7720_bulk_in_callback,
2124 .read_int_callback =
NULL
2128 &moschip7720_2port_driver,
NULL