2 * Aten 2011 USB serial driver for 4 port devices
4 * Copyright (C) 2000 Inside Out Networks
5 * Copyright (C) 2001-2002, 2009 Greg Kroah-Hartman <greg@kroah.com>
6 * Copyright (C) 2009 Novell Inc.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
15 #include <linux/kernel.h>
16 #include <linux/errno.h>
17 #include <linux/init.h>
18 #include <linux/slab.h>
19 #include <linux/tty.h>
20 #include <linux/tty_driver.h>
21 #include <linux/tty_flip.h>
22 #include <linux/module.h>
23 #include <linux/serial.h>
24 #include <linux/usb.h>
25 #include <linux/usb/serial.h>
26 #include <asm/uaccess.h>
29 #define ZLP_REG1 0x3A /* Zero_Flag_Reg1 58 */
30 #define ZLP_REG2 0x3B /* Zero_Flag_Reg2 59 */
31 #define ZLP_REG3 0x3C /* Zero_Flag_Reg3 60 */
32 #define ZLP_REG4 0x3D /* Zero_Flag_Reg4 61 */
33 #define ZLP_REG5 0x3E /* Zero_Flag_Reg5 62 */
35 /* Interrupt Rotinue Defines */
36 #define SERIAL_IIR_RLS 0x06
37 #define SERIAL_IIR_RDA 0x04
38 #define SERIAL_IIR_CTI 0x0c
39 #define SERIAL_IIR_THR 0x02
40 #define SERIAL_IIR_MS 0x00
42 /* Emulation of the bit mask on the LINE STATUS REGISTER. */
43 #define SERIAL_LSR_DR 0x0001
44 #define SERIAL_LSR_OE 0x0002
45 #define SERIAL_LSR_PE 0x0004
46 #define SERIAL_LSR_FE 0x0008
47 #define SERIAL_LSR_BI 0x0010
48 #define SERIAL_LSR_THRE 0x0020
49 #define SERIAL_LSR_TEMT 0x0040
50 #define SERIAL_LSR_FIFOERR 0x0080
52 /* MSR bit defines(place holders) */
53 #define ATEN_MSR_DELTA_CTS 0x10
54 #define ATEN_MSR_DELTA_DSR 0x20
55 #define ATEN_MSR_DELTA_RI 0x40
56 #define ATEN_MSR_DELTA_CD 0x80
58 /* Serial Port register Address */
59 #define RECEIVE_BUFFER_REGISTER ((__u16)(0x00))
60 #define TRANSMIT_HOLDING_REGISTER ((__u16)(0x00))
61 #define INTERRUPT_ENABLE_REGISTER ((__u16)(0x01))
62 #define INTERRUPT_IDENT_REGISTER ((__u16)(0x02))
63 #define FIFO_CONTROL_REGISTER ((__u16)(0x02))
64 #define LINE_CONTROL_REGISTER ((__u16)(0x03))
65 #define MODEM_CONTROL_REGISTER ((__u16)(0x04))
66 #define LINE_STATUS_REGISTER ((__u16)(0x05))
67 #define MODEM_STATUS_REGISTER ((__u16)(0x06))
68 #define SCRATCH_PAD_REGISTER ((__u16)(0x07))
69 #define DIVISOR_LATCH_LSB ((__u16)(0x00))
70 #define DIVISOR_LATCH_MSB ((__u16)(0x01))
72 #define SP1_REGISTER ((__u16)(0x00))
73 #define CONTROL1_REGISTER ((__u16)(0x01))
74 #define CLK_MULTI_REGISTER ((__u16)(0x02))
75 #define CLK_START_VALUE_REGISTER ((__u16)(0x03))
76 #define DCR1_REGISTER ((__u16)(0x04))
77 #define GPIO_REGISTER ((__u16)(0x07))
79 #define SERIAL_LCR_DLAB ((__u16)(0x0080))
82 * URB POOL related defines
84 #define NUM_URBS 16 /* URB Count */
85 #define URB_TRANSFER_BUFFER_SIZE 32 /* URB Size */
87 #define USB_VENDOR_ID_ATENINTL 0x0557
88 #define ATENINTL_DEVICE_ID_2011 0x2011
89 #define ATENINTL_DEVICE_ID_7820 0x7820
91 static struct usb_device_id id_table [] = {
92 { USB_DEVICE(USB_VENDOR_ID_ATENINTL,ATENINTL_DEVICE_ID_2011) },
93 { USB_DEVICE(USB_VENDOR_ID_ATENINTL,ATENINTL_DEVICE_ID_7820) },
94 { } /* terminating entry */
96 MODULE_DEVICE_TABLE (usb, id_table);
98 /* This structure holds all of the local port information */
101 int port_num; /*Actual port number in the device(1,2,etc)*/
102 __u8 bulk_out_endpoint; /* the bulk out endpoint handle */
103 unsigned char *bulk_out_buffer; /* buffer used for the bulk out endpoint */
104 struct urb *write_urb; /* write URB for this port */
105 __u8 bulk_in_endpoint; /* the bulk in endpoint handle */
106 unsigned char *bulk_in_buffer; /* the buffer we use for the bulk in endpoint */
107 struct urb *read_urb; /* read URB for this port */
108 __u8 shadowLCR; /* last LCR value received */
109 __u8 shadowMCR; /* last MCR value received */
111 char chaseResponsePending;
112 wait_queue_head_t wait_chase; /* for handling sleeping while waiting for chase to finish */
113 wait_queue_head_t wait_command; /* for handling sleeping while waiting for command to finish */
114 struct async_icount icount;
115 struct usb_serial_port *port; /* loop back to the owner of this object */
118 __u8 ControlRegOffset;
120 /* for processing control URBS in interrupt context */
121 struct urb *control_urb;
125 struct urb *write_urb_pool[NUM_URBS];
126 /* we pass a pointer to this as the arguement sent to cypress_set_termios old_termios */
127 struct ktermios tmp_termios; /* stores the old termios settings */
128 spinlock_t lock; /* private lock */
132 /* This structure holds all of the individual serial device information */
133 struct ATENINTL_serial
135 __u8 interrupt_in_endpoint; /* the interrupt endpoint handle */
136 unsigned char *interrupt_in_buffer; /* the buffer we use for the interrupt endpoint */
137 struct urb * interrupt_read_urb; /* our interrupt urb */
138 __u8 bulk_in_endpoint; /* the bulk in endpoint handle */
139 unsigned char *bulk_in_buffer; /* the buffer we use for the bulk in endpoint */
140 struct urb *read_urb; /* our bulk read urb */
141 __u8 bulk_out_endpoint; /* the bulk out endpoint handle */
142 struct usb_serial *serial; /* loop back to the owner of this object */
143 int ATEN2011_spectrum_2or4ports; /* this says the number of ports in the device */
144 /* Indicates about the no.of opened ports of an individual USB-serial adapater. */
145 unsigned int NoOfOpenPorts;
146 /* a flag for Status endpoint polling */
147 unsigned char status_polling_started;
150 static void ATEN2011_set_termios(struct tty_struct *tty,
151 struct usb_serial_port *port,
152 struct ktermios *old_termios);
153 static void ATEN2011_change_port_settings(struct tty_struct *tty,
154 struct ATENINTL_port *ATEN2011_port,
155 struct ktermios *old_termios);
157 /*************************************
158 * Bit definitions for each register *
159 *************************************/
160 #define LCR_BITS_5 0x00 /* 5 bits/char */
161 #define LCR_BITS_6 0x01 /* 6 bits/char */
162 #define LCR_BITS_7 0x02 /* 7 bits/char */
163 #define LCR_BITS_8 0x03 /* 8 bits/char */
164 #define LCR_BITS_MASK 0x03 /* Mask for bits/char field */
166 #define LCR_STOP_1 0x00 /* 1 stop bit */
167 #define LCR_STOP_1_5 0x04 /* 1.5 stop bits (if 5 bits/char) */
168 #define LCR_STOP_2 0x04 /* 2 stop bits (if 6-8 bits/char) */
169 #define LCR_STOP_MASK 0x04 /* Mask for stop bits field */
171 #define LCR_PAR_NONE 0x00 /* No parity */
172 #define LCR_PAR_ODD 0x08 /* Odd parity */
173 #define LCR_PAR_EVEN 0x18 /* Even parity */
174 #define LCR_PAR_MARK 0x28 /* Force parity bit to 1 */
175 #define LCR_PAR_SPACE 0x38 /* Force parity bit to 0 */
176 #define LCR_PAR_MASK 0x38 /* Mask for parity field */
178 #define LCR_SET_BREAK 0x40 /* Set Break condition */
179 #define LCR_DL_ENABLE 0x80 /* Enable access to divisor latch */
181 #define MCR_DTR 0x01 /* Assert DTR */
182 #define MCR_RTS 0x02 /* Assert RTS */
183 #define MCR_OUT1 0x04 /* Loopback only: Sets state of RI */
184 #define MCR_MASTER_IE 0x08 /* Enable interrupt outputs */
185 #define MCR_LOOPBACK 0x10 /* Set internal (digital) loopback mode */
186 #define MCR_XON_ANY 0x20 /* Enable any char to exit XOFF mode */
188 #define ATEN2011_MSR_CTS 0x10 /* Current state of CTS */
189 #define ATEN2011_MSR_DSR 0x20 /* Current state of DSR */
190 #define ATEN2011_MSR_RI 0x40 /* Current state of RI */
191 #define ATEN2011_MSR_CD 0x80 /* Current state of CD */
197 * Version Information
199 #define DRIVER_VERSION "2.0"
200 #define DRIVER_DESC "ATENINTL 2011 USB Serial Adapter"
203 * Defines used for sending commands to port
206 #define ATEN_WDR_TIMEOUT (50) /* default urb timeout */
209 #define ATEN_RD_RTYPE 0xC0
210 #define ATEN_WR_RTYPE 0x40
211 #define ATEN_RDREQ 0x0D
212 #define ATEN_WRREQ 0x0E
213 #define ATEN_CTRL_TIMEOUT 500
214 #define VENDOR_READ_LENGTH (0x01)
216 /* set to 1 for RS485 mode and 0 for RS232 mode */
217 /* FIXME make this somehow dynamic and not build time specific */
218 static int RS485mode = 0;
220 static int set_reg_sync(struct usb_serial_port *port, __u16 reg, __u16 val)
222 struct usb_device *dev = port->serial->dev;
225 dbg("%s: is %x, value %x", __func__, reg, val);
227 return usb_control_msg(dev, usb_sndctrlpipe(dev, 0), ATEN_WRREQ,
228 ATEN_WR_RTYPE, val, reg, NULL, 0,
232 static int get_reg_sync(struct usb_serial_port *port, __u16 reg, __u16 *val)
234 struct usb_device *dev = port->serial->dev;
237 ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), ATEN_RDREQ,
238 ATEN_RD_RTYPE, 0, reg, val, VENDOR_READ_LENGTH,
240 dbg("%s: offset is %x, return val %x", __func__, reg, *val);
241 *val = (*val) & 0x00ff;
245 static int set_uart_reg(struct usb_serial_port *port, __u16 reg, __u16 val)
247 struct usb_device *dev = port->serial->dev;
248 struct ATENINTL_serial *a_serial;
251 a_serial = usb_get_serial_data(port->serial);
252 minor = port->serial->minor;
253 if (minor == SERIAL_TTY_NO_MINOR)
258 * For the UART control registers,
259 * the application number need to be Or'ed
261 if (a_serial->ATEN2011_spectrum_2or4ports == 4)
262 val |= (((__u16)port->number - minor) + 1) << 8;
264 if (((__u16) port->number - minor) == 0)
265 val |= (((__u16)port->number - minor) + 1) << 8;
267 val |= (((__u16)port->number - minor) + 2) << 8;
269 dbg("%s: application number is %x", __func__, val);
271 return usb_control_msg(dev, usb_sndctrlpipe(dev, 0), ATEN_WRREQ,
272 ATEN_WR_RTYPE, val, reg, NULL, 0,
276 static int get_uart_reg(struct usb_serial_port *port, __u16 reg, __u16 *val)
278 struct usb_device *dev = port->serial->dev;
281 struct ATENINTL_serial *a_serial;
282 __u16 minor = port->serial->minor;
284 a_serial = usb_get_serial_data(port->serial);
285 if (minor == SERIAL_TTY_NO_MINOR)
288 /* wval is same as application number */
289 if (a_serial->ATEN2011_spectrum_2or4ports == 4)
290 wval = (((__u16)port->number - minor) + 1) << 8;
292 if (((__u16) port->number - minor) == 0)
293 wval = (((__u16) port->number - minor) + 1) << 8;
295 wval = (((__u16) port->number - minor) + 2) << 8;
297 dbg("%s: application number is %x", __func__, wval);
298 ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), ATEN_RDREQ,
299 ATEN_RD_RTYPE, wval, reg, val, VENDOR_READ_LENGTH,
301 *val = (*val) & 0x00ff;
305 static int handle_newMsr(struct ATENINTL_port *port, __u8 newMsr)
307 struct ATENINTL_port *ATEN2011_port;
308 struct async_icount *icount;
309 ATEN2011_port = port;
310 icount = &ATEN2011_port->icount;
312 (ATEN_MSR_DELTA_CTS | ATEN_MSR_DELTA_DSR | ATEN_MSR_DELTA_RI |
313 ATEN_MSR_DELTA_CD)) {
314 icount = &ATEN2011_port->icount;
316 /* update input line counters */
317 if (newMsr & ATEN_MSR_DELTA_CTS) {
320 if (newMsr & ATEN_MSR_DELTA_DSR) {
323 if (newMsr & ATEN_MSR_DELTA_CD) {
326 if (newMsr & ATEN_MSR_DELTA_RI) {
334 static int handle_newLsr(struct ATENINTL_port *port, __u8 newLsr)
336 struct async_icount *icount;
338 dbg("%s - %02x", __FUNCTION__, newLsr);
340 if (newLsr & SERIAL_LSR_BI) {
342 * Parity and Framing errors only count if they occur exclusive
343 * of a break being received.
345 newLsr &= (__u8) (SERIAL_LSR_OE | SERIAL_LSR_BI);
348 /* update input line counters */
349 icount = &port->icount;
350 if (newLsr & SERIAL_LSR_BI) {
353 if (newLsr & SERIAL_LSR_OE) {
356 if (newLsr & SERIAL_LSR_PE) {
359 if (newLsr & SERIAL_LSR_FE) {
366 static void ATEN2011_control_callback(struct urb *urb)
369 struct ATENINTL_port *ATEN2011_port;
372 switch (urb->status) {
379 /* this urb is terminated, clean up */
380 dbg("%s - urb shutting down with status: %d", __FUNCTION__,
384 dbg("%s - nonzero urb status received: %d", __FUNCTION__,
389 ATEN2011_port = (struct ATENINTL_port *)urb->context;
391 dbg("%s urb buffer size is %d", __FUNCTION__, urb->actual_length);
392 dbg("%s ATEN2011_port->MsrLsr is %d port %d", __FUNCTION__,
393 ATEN2011_port->MsrLsr, ATEN2011_port->port_num);
394 data = urb->transfer_buffer;
395 regval = (__u8) data[0];
396 dbg("%s data is %x", __FUNCTION__, regval);
397 if (ATEN2011_port->MsrLsr == 0)
398 handle_newMsr(ATEN2011_port, regval);
399 else if (ATEN2011_port->MsrLsr == 1)
400 handle_newLsr(ATEN2011_port, regval);
406 static int ATEN2011_get_reg(struct ATENINTL_port *ATEN, __u16 Wval, __u16 reg,
409 struct usb_device *dev = ATEN->port->serial->dev;
410 struct usb_ctrlrequest *dr = NULL;
411 unsigned char *buffer = NULL;
413 buffer = (__u8 *) ATEN->ctrl_buf;
415 dr = (void *)(buffer + 2);
416 dr->bRequestType = ATEN_RD_RTYPE;
417 dr->bRequest = ATEN_RDREQ;
418 dr->wValue = cpu_to_le16(Wval);
419 dr->wIndex = cpu_to_le16(reg);
420 dr->wLength = cpu_to_le16(2);
422 usb_fill_control_urb(ATEN->control_urb, dev, usb_rcvctrlpipe(dev, 0),
423 (unsigned char *)dr, buffer, 2,
424 ATEN2011_control_callback, ATEN);
425 ATEN->control_urb->transfer_buffer_length = 2;
426 ret = usb_submit_urb(ATEN->control_urb, GFP_ATOMIC);
430 static void ATEN2011_interrupt_callback(struct urb *urb)
434 struct ATENINTL_port *ATEN2011_port;
435 struct ATENINTL_serial *ATEN2011_serial;
436 struct usb_serial *serial;
444 dbg("%s", " : Entering");
446 ATEN2011_serial = (struct ATENINTL_serial *)urb->context;
448 switch (urb->status) {
455 /* this urb is terminated, clean up */
456 dbg("%s - urb shutting down with status: %d", __FUNCTION__,
460 dbg("%s - nonzero urb status received: %d", __FUNCTION__,
464 length = urb->actual_length;
465 data = urb->transfer_buffer;
467 serial = ATEN2011_serial->serial;
469 /* ATENINTL get 5 bytes
470 * Byte 1 IIR Port 1 (port.number is 0)
471 * Byte 2 IIR Port 2 (port.number is 1)
472 * Byte 3 IIR Port 3 (port.number is 2)
473 * Byte 4 IIR Port 4 (port.number is 3)
474 * Byte 5 FIFO status for both */
476 if (length && length > 5) {
477 dbg("%s", "Wrong data !!!");
482 if (ATEN2011_serial->ATEN2011_spectrum_2or4ports == 4) {
483 sp[0] = (__u8) data[0];
484 sp[1] = (__u8) data[1];
485 sp[2] = (__u8) data[2];
486 sp[3] = (__u8) data[3];
489 sp[0] = (__u8) data[0];
490 sp[1] = (__u8) data[2];
491 /* sp[2]=(__u8)data[2]; */
492 /* sp[3]=(__u8)data[3]; */
496 for (i = 0; i < serial->num_ports; i++) {
497 ATEN2011_port = usb_get_serial_port_data(serial->port[i]);
498 minor = serial->minor;
499 if (minor == SERIAL_TTY_NO_MINOR)
501 if ((ATEN2011_serial->ATEN2011_spectrum_2or4ports == 2)
504 (((__u16) serial->port[i]->number -
505 (__u16) (minor)) + 2) << 8;
508 (((__u16) serial->port[i]->number -
509 (__u16) (minor)) + 1) << 8;
510 if (ATEN2011_port->open != 0) {
512 dbg("SP%d No Interrupt !!!", i);
514 switch (sp[i] & 0x0f) {
516 dbg("Serial Port %d: Receiver status error or address bit detected in 9-bit mode", i);
517 ATEN2011_port->MsrLsr = 1;
518 ATEN2011_get_reg(ATEN2011_port, wval,
519 LINE_STATUS_REGISTER,
523 dbg("Serial Port %d: Modem status change", i);
524 ATEN2011_port->MsrLsr = 0;
525 ATEN2011_get_reg(ATEN2011_port, wval,
526 MODEM_STATUS_REGISTER,
535 if (ATEN2011_serial->status_polling_started == 0)
538 result = usb_submit_urb(urb, GFP_ATOMIC);
540 dev_err(&urb->dev->dev,
541 "%s - Error %d submitting interrupt urb\n",
542 __FUNCTION__, result);
549 static void ATEN2011_bulk_in_callback(struct urb *urb)
553 struct usb_serial *serial;
554 struct usb_serial_port *port;
555 struct ATENINTL_serial *ATEN2011_serial;
556 struct ATENINTL_port *ATEN2011_port;
557 struct tty_struct *tty;
560 dbg("nonzero read bulk status received: %d", urb->status);
564 ATEN2011_port = (struct ATENINTL_port *)urb->context;
566 port = (struct usb_serial_port *)ATEN2011_port->port;
567 serial = port->serial;
569 dbg("%s", "Entering...");
571 data = urb->transfer_buffer;
572 ATEN2011_serial = usb_get_serial_data(serial);
574 if (urb->actual_length) {
575 tty = tty_port_tty_get(&ATEN2011_port->port->port);
577 tty_buffer_request_room(tty, urb->actual_length);
578 tty_insert_flip_string(tty, data, urb->actual_length);
579 tty_flip_buffer_push(tty);
583 ATEN2011_port->icount.rx += urb->actual_length;
584 dbg("ATEN2011_port->icount.rx is %d:",
585 ATEN2011_port->icount.rx);
588 if (!ATEN2011_port->read_urb) {
589 dbg("%s", "URB KILLED !!!");
593 if (ATEN2011_port->read_urb->status != -EINPROGRESS) {
594 ATEN2011_port->read_urb->dev = serial->dev;
596 status = usb_submit_urb(ATEN2011_port->read_urb, GFP_ATOMIC);
599 dbg("usb_submit_urb(read bulk) failed, status = %d", status);
604 static void ATEN2011_bulk_out_data_callback(struct urb *urb)
606 struct ATENINTL_port *ATEN2011_port;
607 struct tty_struct *tty;
610 dbg("nonzero write bulk status received:%d", urb->status);
614 ATEN2011_port = (struct ATENINTL_port *)urb->context;
616 dbg("%s", "Entering .........");
618 tty = tty_port_tty_get(&ATEN2011_port->port->port);
620 if (tty && ATEN2011_port->open) {
621 /* tell the tty driver that something has changed */
622 wake_up_interruptible(&tty->write_wait);
625 /* schedule_work(&ATEN2011_port->port->work); */
630 #ifdef ATENSerialProbe
631 static int ATEN2011_serial_probe(struct usb_serial *serial,
632 const struct usb_device_id *id)
635 /*need to implement the mode_reg reading and updating\
636 structures usb_serial_ device_type\
637 (i.e num_ports, num_bulkin,bulkout etc) */
638 /* Also we can update the changes attach */
643 static int ATEN2011_open(struct tty_struct *tty, struct usb_serial_port *port,
648 struct usb_serial *serial;
652 struct ATENINTL_serial *ATEN2011_serial;
653 struct ATENINTL_port *ATEN2011_port;
654 struct ktermios tmp_termios;
657 serial = port->serial;
659 ATEN2011_port = usb_get_serial_port_data(port);
661 if (ATEN2011_port == NULL)
664 if (ATEN2011_port->ctrl_buf==NULL)
666 ATEN2011_port->ctrl_buf = kmalloc(16,GFP_KERNEL);
667 if (ATEN2011_port->ctrl_buf == NULL) {
668 printk(", Can't allocate ctrl buff\n");
674 if(!ATEN2011_port->control_urb)
676 ATEN2011_port->control_urb=kmalloc(sizeof(struct urb),GFP_KERNEL);
680 ATEN2011_serial = usb_get_serial_data(serial);
682 if (ATEN2011_serial == NULL) {
685 /* increment the number of opened ports counter here */
686 ATEN2011_serial->NoOfOpenPorts++;
688 usb_clear_halt(serial->dev, port->write_urb->pipe);
689 usb_clear_halt(serial->dev, port->read_urb->pipe);
691 /* Initialising the write urb pool */
692 for (j = 0; j < NUM_URBS; ++j) {
693 urb = usb_alloc_urb(0, GFP_ATOMIC);
694 ATEN2011_port->write_urb_pool[j] = urb;
697 err("No more urbs???");
701 urb->transfer_buffer = NULL;
702 urb->transfer_buffer =
703 kmalloc(URB_TRANSFER_BUFFER_SIZE, GFP_KERNEL);
704 if (!urb->transfer_buffer) {
705 err("%s-out of memory for urb buffers.", __FUNCTION__);
710 /*****************************************************************************
711 * Initialize ATEN2011 -- Write Init values to corresponding Registers
719 * 0x08 : SP1/2 Control Reg
720 *****************************************************************************/
722 /* NEED to check the fallowing Block */
725 status = get_reg_sync(port, ATEN2011_port->SpRegOffset, &Data);
727 dbg("Reading Spreg failed");
731 status = set_reg_sync(port, ATEN2011_port->SpRegOffset, Data);
733 dbg("writing Spreg failed");
738 status = set_reg_sync(port, ATEN2011_port->SpRegOffset, Data);
740 dbg("writing Spreg failed");
744 /* End of block to be checked */
745 /**************************CHECK***************************/
751 status = set_uart_reg(port, SCRATCH_PAD_REGISTER, Data);
753 dbg("Writing SCRATCH_PAD_REGISTER failed status-0x%x", status);
756 dbg("SCRATCH_PAD_REGISTER Writing success status%d", status);
758 /**************************CHECK***************************/
761 status = get_reg_sync(port, ATEN2011_port->ControlRegOffset, &Data);
763 dbg("Reading Controlreg failed");
766 Data |= 0x08; /* Driver done bit */
767 Data |= 0x20; /* rx_disable */
770 set_reg_sync(port, ATEN2011_port->ControlRegOffset, Data);
772 dbg("writing Controlreg failed");
776 * do register settings here
777 * Set all regs to the device default values.
778 * First Disable all interrupts.
782 status = set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data);
784 dbg("disableing interrupts failed");
787 /* Set FIFO_CONTROL_REGISTER to the default value */
789 status = set_uart_reg(port, FIFO_CONTROL_REGISTER, Data);
791 dbg("Writing FIFO_CONTROL_REGISTER failed");
795 Data = 0xcf; /* chk */
796 status = set_uart_reg(port, FIFO_CONTROL_REGISTER, Data);
798 dbg("Writing FIFO_CONTROL_REGISTER failed");
802 Data = 0x03; /* LCR_BITS_8 */
803 status = set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
804 ATEN2011_port->shadowLCR = Data;
806 Data = 0x0b; /* MCR_DTR|MCR_RTS|MCR_MASTER_IE */
807 status = set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
808 ATEN2011_port->shadowMCR = Data;
812 status = get_uart_reg(port, LINE_CONTROL_REGISTER, &Data);
813 ATEN2011_port->shadowLCR = Data;
815 Data |= SERIAL_LCR_DLAB; /* data latch enable in LCR 0x80 */
816 status = set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
819 status = set_uart_reg(port, DIVISOR_LATCH_LSB, Data);
822 status = set_uart_reg(port, DIVISOR_LATCH_MSB, Data);
825 status = get_uart_reg(port, LINE_CONTROL_REGISTER, &Data);
827 /* Data = ATEN2011_port->shadowLCR; */ /* data latch disable */
828 Data = Data & ~SERIAL_LCR_DLAB;
829 status = set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
830 ATEN2011_port->shadowLCR = Data;
832 /* clearing Bulkin and Bulkout Fifo */
834 status = get_reg_sync(port, ATEN2011_port->SpRegOffset, &Data);
837 status = set_reg_sync(port, ATEN2011_port->SpRegOffset, Data);
840 status = set_reg_sync(port, ATEN2011_port->SpRegOffset, Data);
841 /* Finally enable all interrupts */
844 status = set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data);
846 /* clearing rx_disable */
848 status = get_reg_sync(port, ATEN2011_port->ControlRegOffset, &Data);
850 status = set_reg_sync(port, ATEN2011_port->ControlRegOffset, Data);
854 status = get_reg_sync(port, ATEN2011_port->ControlRegOffset, &Data);
857 status = set_reg_sync(port, ATEN2011_port->ControlRegOffset, Data);
859 /* force low_latency on so that our tty_push actually forces *
860 * the data through,otherwise it is scheduled, and with *
861 * high data rates (like with OHCI) data can get lost. */
864 tty->low_latency = 1;
866 * Check to see if we've set up our endpoint info yet
867 * (can't set it up in ATEN2011_startup as the structures
868 * were not set up at that time.)
870 if (ATEN2011_serial->NoOfOpenPorts == 1) {
871 /* start the status polling here */
872 ATEN2011_serial->status_polling_started = 1;
873 /* If not yet set, Set here */
874 ATEN2011_serial->interrupt_in_buffer =
875 serial->port[0]->interrupt_in_buffer;
876 ATEN2011_serial->interrupt_in_endpoint =
877 serial->port[0]->interrupt_in_endpointAddress;
878 ATEN2011_serial->interrupt_read_urb =
879 serial->port[0]->interrupt_in_urb;
881 /* set up interrupt urb */
882 usb_fill_int_urb(ATEN2011_serial->interrupt_read_urb,
884 usb_rcvintpipe(serial->dev,
886 interrupt_in_endpoint),
887 ATEN2011_serial->interrupt_in_buffer,
888 ATEN2011_serial->interrupt_read_urb->
889 transfer_buffer_length,
890 ATEN2011_interrupt_callback, ATEN2011_serial,
891 ATEN2011_serial->interrupt_read_urb->interval);
893 /* start interrupt read for ATEN2011 *
894 * will continue as long as ATEN2011 is connected */
897 usb_submit_urb(ATEN2011_serial->interrupt_read_urb,
900 dbg("%s - Error %d submitting interrupt urb",
901 __FUNCTION__, response);
907 * See if we've set up our endpoint info yet
908 * (can't set it up in ATEN2011_startup as the
909 * structures were not set up at that time.)
912 dbg("port number is %d", port->number);
913 dbg("serial number is %d", port->serial->minor);
914 dbg("Bulkin endpoint is %d", port->bulk_in_endpointAddress);
915 dbg("BulkOut endpoint is %d", port->bulk_out_endpointAddress);
916 dbg("Interrupt endpoint is %d",
917 port->interrupt_in_endpointAddress);
918 dbg("port's number in the device is %d", ATEN2011_port->port_num);
919 ATEN2011_port->bulk_in_buffer = port->bulk_in_buffer;
920 ATEN2011_port->bulk_in_endpoint = port->bulk_in_endpointAddress;
921 ATEN2011_port->read_urb = port->read_urb;
922 ATEN2011_port->bulk_out_endpoint = port->bulk_out_endpointAddress;
924 minor = port->serial->minor;
925 if (minor == SERIAL_TTY_NO_MINOR)
928 /* set up our bulk in urb */
929 if ((ATEN2011_serial->ATEN2011_spectrum_2or4ports == 2)
930 && (((__u16) port->number - (__u16) (minor)) != 0)) {
931 usb_fill_bulk_urb(ATEN2011_port->read_urb, serial->dev,
932 usb_rcvbulkpipe(serial->dev,
934 bulk_in_endpointAddress +
935 2)), port->bulk_in_buffer,
936 ATEN2011_port->read_urb->
937 transfer_buffer_length,
938 ATEN2011_bulk_in_callback, ATEN2011_port);
940 usb_fill_bulk_urb(ATEN2011_port->read_urb,
942 usb_rcvbulkpipe(serial->dev,
944 bulk_in_endpointAddress),
945 port->bulk_in_buffer,
946 ATEN2011_port->read_urb->
947 transfer_buffer_length,
948 ATEN2011_bulk_in_callback, ATEN2011_port);
950 dbg("ATEN2011_open: bulkin endpoint is %d",
951 port->bulk_in_endpointAddress);
952 response = usb_submit_urb(ATEN2011_port->read_urb, GFP_KERNEL);
954 err("%s - Error %d submitting control urb", __FUNCTION__,
958 /* initialize our wait queues */
959 init_waitqueue_head(&ATEN2011_port->wait_chase);
960 init_waitqueue_head(&ATEN2011_port->wait_command);
962 /* initialize our icount structure */
963 memset(&(ATEN2011_port->icount), 0x00, sizeof(ATEN2011_port->icount));
965 /* initialize our port settings */
966 ATEN2011_port->shadowMCR = MCR_MASTER_IE; /* Must set to enable ints! */
967 ATEN2011_port->chaseResponsePending = 0;
968 /* send a open port command */
969 ATEN2011_port->open = 1;
970 /* ATEN2011_change_port_settings(ATEN2011_port,old_termios); */
972 ATEN2011_set_termios(tty, port, &tmp_termios);
973 ATEN2011_port->icount.tx = 0;
974 ATEN2011_port->icount.rx = 0;
976 dbg("usb_serial serial:%x ATEN2011_port:%x\nATEN2011_serial:%x usb_serial_port port:%x",
977 (unsigned int)serial, (unsigned int)ATEN2011_port,
978 (unsigned int)ATEN2011_serial, (unsigned int)port);
984 static int ATEN2011_chars_in_buffer(struct tty_struct *tty)
986 struct usb_serial_port *port = tty->driver_data;
989 struct ATENINTL_port *ATEN2011_port;
991 /* dbg("%s"," ATEN2011_chars_in_buffer:entering ..........."); */
993 ATEN2011_port = usb_get_serial_port_data(port);
994 if (ATEN2011_port == NULL) {
995 dbg("%s", "ATEN2011_break:leaving ...........");
999 for (i = 0; i < NUM_URBS; ++i) {
1000 if (ATEN2011_port->write_urb_pool[i]->status == -EINPROGRESS) {
1001 chars += URB_TRANSFER_BUFFER_SIZE;
1004 dbg("%s - returns %d", __FUNCTION__, chars);
1009 static void ATEN2011_block_until_tx_empty(struct tty_struct *tty,
1010 struct ATENINTL_port *ATEN2011_port)
1012 int timeout = HZ / 10;
1018 count = ATEN2011_chars_in_buffer(tty);
1020 /* Check for Buffer status */
1025 /* Block the thread for a while */
1026 interruptible_sleep_on_timeout(&ATEN2011_port->wait_chase,
1029 /* No activity.. count down section */
1032 dbg("%s - TIMEOUT", __FUNCTION__);
1035 /* Reset timout value back to seconds */
1041 static void ATEN2011_close(struct tty_struct *tty, struct usb_serial_port *port,
1044 struct usb_serial *serial;
1045 struct ATENINTL_serial *ATEN2011_serial;
1046 struct ATENINTL_port *ATEN2011_port;
1050 dbg("%s", "ATEN2011_close:entering...");
1051 serial = port->serial;
1053 /* take the Adpater and port's private data */
1054 ATEN2011_serial = usb_get_serial_data(serial);
1055 ATEN2011_port = usb_get_serial_port_data(port);
1056 if ((ATEN2011_serial == NULL) || (ATEN2011_port == NULL)) {
1060 /* flush and block(wait) until tx is empty */
1061 ATEN2011_block_until_tx_empty(tty, ATEN2011_port);
1063 /* kill the ports URB's */
1064 for (no_urbs = 0; no_urbs < NUM_URBS; no_urbs++)
1065 usb_kill_urb(ATEN2011_port->write_urb_pool[no_urbs]);
1066 /* Freeing Write URBs */
1067 for (no_urbs = 0; no_urbs < NUM_URBS; ++no_urbs) {
1068 if (ATEN2011_port->write_urb_pool[no_urbs]) {
1069 if (ATEN2011_port->write_urb_pool[no_urbs]->
1071 kfree(ATEN2011_port->write_urb_pool[no_urbs]->
1073 usb_free_urb(ATEN2011_port->write_urb_pool[no_urbs]);
1076 /* While closing port, shutdown all bulk read, write *
1077 * and interrupt read if they exists */
1079 if (ATEN2011_port->write_urb) {
1080 dbg("%s", "Shutdown bulk write");
1081 usb_kill_urb(ATEN2011_port->write_urb);
1083 if (ATEN2011_port->read_urb) {
1084 dbg("%s", "Shutdown bulk read");
1085 usb_kill_urb(ATEN2011_port->read_urb);
1087 if ((&ATEN2011_port->control_urb)) {
1088 dbg("%s", "Shutdown control read");
1089 /* usb_kill_urb (ATEN2011_port->control_urb); */
1093 /* if(ATEN2011_port->ctrl_buf != NULL) */
1094 /* kfree(ATEN2011_port->ctrl_buf); */
1095 /* decrement the no.of open ports counter of an individual USB-serial adapter. */
1096 ATEN2011_serial->NoOfOpenPorts--;
1097 dbg("NoOfOpenPorts in close%d:in port%d",
1098 ATEN2011_serial->NoOfOpenPorts, port->number);
1099 if (ATEN2011_serial->NoOfOpenPorts == 0) {
1100 /* stop the stus polling here */
1101 ATEN2011_serial->status_polling_started = 0;
1102 if (ATEN2011_serial->interrupt_read_urb) {
1103 dbg("%s", "Shutdown interrupt_read_urb");
1104 /* ATEN2011_serial->interrupt_in_buffer=NULL; */
1105 /* usb_kill_urb (ATEN2011_serial->interrupt_read_urb); */
1108 if (ATEN2011_port->write_urb) {
1109 /* if this urb had a transfer buffer already (old tx) free it */
1110 if (ATEN2011_port->write_urb->transfer_buffer != NULL) {
1111 kfree(ATEN2011_port->write_urb->transfer_buffer);
1113 usb_free_urb(ATEN2011_port->write_urb);
1115 /* clear the MCR & IER */
1117 set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
1119 set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data);
1121 ATEN2011_port->open = 0;
1122 dbg("%s", "Leaving ............");
1126 static void ATEN2011_block_until_chase_response(struct tty_struct *tty,
1127 struct ATENINTL_port
1130 int timeout = 1 * HZ;
1135 count = ATEN2011_chars_in_buffer(tty);
1137 /* Check for Buffer status */
1139 ATEN2011_port->chaseResponsePending = 0;
1143 /* Block the thread for a while */
1144 interruptible_sleep_on_timeout(&ATEN2011_port->wait_chase,
1146 /* No activity.. count down section */
1149 dbg("%s - TIMEOUT", __FUNCTION__);
1152 /* Reset timout value back to seconds */
1159 static void ATEN2011_break(struct tty_struct *tty, int break_state)
1161 struct usb_serial_port *port = tty->driver_data;
1163 struct usb_serial *serial;
1164 struct ATENINTL_serial *ATEN2011_serial;
1165 struct ATENINTL_port *ATEN2011_port;
1167 dbg("%s", "Entering ...........");
1168 dbg("ATEN2011_break: Start");
1170 serial = port->serial;
1172 ATEN2011_serial = usb_get_serial_data(serial);
1173 ATEN2011_port = usb_get_serial_port_data(port);
1175 if ((ATEN2011_serial == NULL) || (ATEN2011_port == NULL)) {
1179 /* flush and chase */
1180 ATEN2011_port->chaseResponsePending = 1;
1184 /* flush and block until tx is empty */
1185 ATEN2011_block_until_chase_response(tty, ATEN2011_port);
1188 if (break_state == -1) {
1189 data = ATEN2011_port->shadowLCR | LCR_SET_BREAK;
1191 data = ATEN2011_port->shadowLCR & ~LCR_SET_BREAK;
1194 ATEN2011_port->shadowLCR = data;
1195 dbg("ATEN2011_break ATEN2011_port->shadowLCR is %x",
1196 ATEN2011_port->shadowLCR);
1197 set_uart_reg(port, LINE_CONTROL_REGISTER, ATEN2011_port->shadowLCR);
1202 static int ATEN2011_write_room(struct tty_struct *tty)
1204 struct usb_serial_port *port = tty->driver_data;
1207 struct ATENINTL_port *ATEN2011_port;
1209 ATEN2011_port = usb_get_serial_port_data(port);
1210 if (ATEN2011_port == NULL) {
1211 dbg("%s", "ATEN2011_break:leaving ...........");
1215 for (i = 0; i < NUM_URBS; ++i) {
1216 if (ATEN2011_port->write_urb_pool[i]->status != -EINPROGRESS) {
1217 room += URB_TRANSFER_BUFFER_SIZE;
1221 dbg("%s - returns %d", __FUNCTION__, room);
1226 static int ATEN2011_write(struct tty_struct *tty, struct usb_serial_port *port,
1227 const unsigned char *data, int count)
1235 struct ATENINTL_port *ATEN2011_port;
1236 struct usb_serial *serial;
1237 struct ATENINTL_serial *ATEN2011_serial;
1239 const unsigned char *current_position = data;
1240 unsigned char *data1;
1241 dbg("%s", "entering ...........");
1243 serial = port->serial;
1245 ATEN2011_port = usb_get_serial_port_data(port);
1246 if (ATEN2011_port == NULL) {
1247 dbg("%s", "ATEN2011_port is NULL");
1251 ATEN2011_serial = usb_get_serial_data(serial);
1252 if (ATEN2011_serial == NULL) {
1253 dbg("%s", "ATEN2011_serial is NULL");
1257 /* try to find a free urb in the list */
1260 for (i = 0; i < NUM_URBS; ++i) {
1261 if (ATEN2011_port->write_urb_pool[i]->status != -EINPROGRESS) {
1262 urb = ATEN2011_port->write_urb_pool[i];
1269 dbg("%s - no more free urbs", __FUNCTION__);
1273 if (urb->transfer_buffer == NULL) {
1274 urb->transfer_buffer =
1275 kmalloc(URB_TRANSFER_BUFFER_SIZE, GFP_KERNEL);
1277 if (urb->transfer_buffer == NULL) {
1278 err("%s no more kernel memory...", __FUNCTION__);
1282 transfer_size = min(count, URB_TRANSFER_BUFFER_SIZE);
1284 memcpy(urb->transfer_buffer, current_position, transfer_size);
1285 /* usb_serial_debug_data (__FILE__, __FUNCTION__, transfer_size, urb->transfer_buffer); */
1287 /* fill urb with data and submit */
1288 minor = port->serial->minor;
1289 if (minor == SERIAL_TTY_NO_MINOR) ;
1291 if ((ATEN2011_serial->ATEN2011_spectrum_2or4ports == 2)
1292 && (((__u16) port->number - (__u16) (minor)) != 0)) {
1293 usb_fill_bulk_urb(urb, ATEN2011_serial->serial->dev,
1294 usb_sndbulkpipe(ATEN2011_serial->serial->dev,
1296 bulk_out_endpointAddress) +
1297 2), urb->transfer_buffer,
1299 ATEN2011_bulk_out_data_callback,
1303 usb_fill_bulk_urb(urb,
1304 ATEN2011_serial->serial->dev,
1305 usb_sndbulkpipe(ATEN2011_serial->serial->dev,
1307 bulk_out_endpointAddress),
1308 urb->transfer_buffer, transfer_size,
1309 ATEN2011_bulk_out_data_callback,
1312 data1 = urb->transfer_buffer;
1313 dbg("bulkout endpoint is %d", port->bulk_out_endpointAddress);
1314 /* for(i=0;i < urb->actual_length;i++) */
1315 /* dbg("Data is %c ",data1[i]); */
1317 /* send it down the pipe */
1318 status = usb_submit_urb(urb, GFP_ATOMIC);
1321 err("%s - usb_submit_urb(write bulk) failed with status = %d",
1322 __FUNCTION__, status);
1323 bytes_sent = status;
1326 bytes_sent = transfer_size;
1327 ATEN2011_port->icount.tx += transfer_size;
1328 dbg("ATEN2011_port->icount.tx is %d:", ATEN2011_port->icount.tx);
1335 static void ATEN2011_throttle(struct tty_struct *tty)
1337 struct usb_serial_port *port = tty->driver_data;
1338 struct ATENINTL_port *ATEN2011_port;
1341 dbg("- port %d", port->number);
1343 ATEN2011_port = usb_get_serial_port_data(port);
1345 if (ATEN2011_port == NULL)
1348 if (!ATEN2011_port->open) {
1349 dbg("%s", "port not opened");
1353 dbg("%s", "Entering .......... ");
1356 dbg("%s - no tty available", __FUNCTION__);
1360 /* if we are implementing XON/XOFF, send the stop character */
1362 unsigned char stop_char = STOP_CHAR(tty);
1363 status = ATEN2011_write(tty, port, &stop_char, 1);
1369 /* if we are implementing RTS/CTS, toggle that line */
1370 if (tty->termios->c_cflag & CRTSCTS) {
1371 ATEN2011_port->shadowMCR &= ~MCR_RTS;
1372 status = set_uart_reg(port, MODEM_CONTROL_REGISTER,
1373 ATEN2011_port->shadowMCR);
1383 static void ATEN2011_unthrottle(struct tty_struct *tty)
1385 struct usb_serial_port *port = tty->driver_data;
1387 struct ATENINTL_port *ATEN2011_port = usb_get_serial_port_data(port);
1389 if (ATEN2011_port == NULL)
1392 if (!ATEN2011_port->open) {
1393 dbg("%s - port not opened", __FUNCTION__);
1397 dbg("%s", "Entering .......... ");
1400 dbg("%s - no tty available", __FUNCTION__);
1404 /* if we are implementing XON/XOFF, send the start character */
1406 unsigned char start_char = START_CHAR(tty);
1407 status = ATEN2011_write(tty, port, &start_char, 1);
1413 /* if we are implementing RTS/CTS, toggle that line */
1414 if (tty->termios->c_cflag & CRTSCTS) {
1415 ATEN2011_port->shadowMCR |= MCR_RTS;
1416 status = set_uart_reg(port, MODEM_CONTROL_REGISTER,
1417 ATEN2011_port->shadowMCR);
1426 static int ATEN2011_tiocmget(struct tty_struct *tty, struct file *file)
1428 struct usb_serial_port *port = tty->driver_data;
1429 struct ATENINTL_port *ATEN2011_port;
1430 unsigned int result;
1433 /* unsigned int mcr; */
1435 ATEN2011_port = usb_get_serial_port_data(port);
1437 dbg("%s - port %d", __FUNCTION__, port->number);
1439 if (ATEN2011_port == NULL)
1442 status = get_uart_reg(port, MODEM_STATUS_REGISTER, &msr);
1443 status = get_uart_reg(port, MODEM_CONTROL_REGISTER, &mcr);
1444 /* mcr = ATEN2011_port->shadowMCR; */
1445 /* COMMENT2: the Fallowing three line are commented for updating only MSR values */
1446 result = ((mcr & MCR_DTR) ? TIOCM_DTR : 0)
1447 | ((mcr & MCR_RTS) ? TIOCM_RTS : 0)
1448 | ((mcr & MCR_LOOPBACK) ? TIOCM_LOOP : 0)
1449 | ((msr & ATEN2011_MSR_CTS) ? TIOCM_CTS : 0)
1450 | ((msr & ATEN2011_MSR_CD) ? TIOCM_CAR : 0)
1451 | ((msr & ATEN2011_MSR_RI) ? TIOCM_RI : 0)
1452 | ((msr & ATEN2011_MSR_DSR) ? TIOCM_DSR : 0);
1454 dbg("%s - 0x%04X", __FUNCTION__, result);
1459 static int ATEN2011_tiocmset(struct tty_struct *tty, struct file *file,
1460 unsigned int set, unsigned int clear)
1462 struct usb_serial_port *port = tty->driver_data;
1463 struct ATENINTL_port *ATEN2011_port;
1465 unsigned int status;
1467 dbg("%s - port %d", __FUNCTION__, port->number);
1469 ATEN2011_port = usb_get_serial_port_data(port);
1471 if (ATEN2011_port == NULL)
1474 mcr = ATEN2011_port->shadowMCR;
1475 if (clear & TIOCM_RTS)
1477 if (clear & TIOCM_DTR)
1479 if (clear & TIOCM_LOOP)
1480 mcr &= ~MCR_LOOPBACK;
1482 if (set & TIOCM_RTS)
1484 if (set & TIOCM_DTR)
1486 if (set & TIOCM_LOOP)
1487 mcr |= MCR_LOOPBACK;
1489 ATEN2011_port->shadowMCR = mcr;
1491 status = set_uart_reg(port, MODEM_CONTROL_REGISTER, mcr);
1493 dbg("setting MODEM_CONTROL_REGISTER Failed");
1500 static void ATEN2011_set_termios(struct tty_struct *tty,
1501 struct usb_serial_port *port,
1502 struct ktermios *old_termios)
1506 struct usb_serial *serial;
1507 struct ATENINTL_port *ATEN2011_port;
1509 dbg("ATEN2011_set_termios: START");
1511 serial = port->serial;
1513 ATEN2011_port = usb_get_serial_port_data(port);
1515 if (ATEN2011_port == NULL)
1518 if (!ATEN2011_port->open) {
1519 dbg("%s - port not opened", __FUNCTION__);
1523 dbg("%s", "setting termios - ");
1525 cflag = tty->termios->c_cflag;
1528 dbg("%s %s", __FUNCTION__, "cflag is NULL");
1532 /* check that they really want us to change something */
1534 if ((cflag == old_termios->c_cflag) &&
1535 (RELEVANT_IFLAG(tty->termios->c_iflag) ==
1536 RELEVANT_IFLAG(old_termios->c_iflag))) {
1537 dbg("%s", "Nothing to change");
1542 dbg("%s - clfag %08x iflag %08x", __FUNCTION__,
1543 tty->termios->c_cflag, RELEVANT_IFLAG(tty->termios->c_iflag));
1546 dbg("%s - old clfag %08x old iflag %08x", __FUNCTION__,
1547 old_termios->c_cflag, RELEVANT_IFLAG(old_termios->c_iflag));
1550 dbg("%s - port %d", __FUNCTION__, port->number);
1552 /* change the port settings to the new ones specified */
1554 ATEN2011_change_port_settings(tty, ATEN2011_port, old_termios);
1556 if (!ATEN2011_port->read_urb) {
1557 dbg("%s", "URB KILLED !!!!!");
1561 if (ATEN2011_port->read_urb->status != -EINPROGRESS) {
1562 ATEN2011_port->read_urb->dev = serial->dev;
1563 status = usb_submit_urb(ATEN2011_port->read_urb, GFP_ATOMIC);
1566 (" usb_submit_urb(read bulk) failed, status = %d",
1573 static int get_lsr_info(struct tty_struct *tty,
1574 struct ATENINTL_port *ATEN2011_port,
1575 unsigned int __user *value)
1578 unsigned int result = 0;
1580 count = ATEN2011_chars_in_buffer(tty);
1582 dbg("%s -- Empty", __FUNCTION__);
1583 result = TIOCSER_TEMT;
1586 if (copy_to_user(value, &result, sizeof(int)))
1591 static int get_number_bytes_avail(struct tty_struct *tty,
1592 struct ATENINTL_port *ATEN2011_port,
1593 unsigned int __user *value)
1595 unsigned int result = 0;
1598 return -ENOIOCTLCMD;
1600 result = tty->read_cnt;
1602 dbg("%s(%d) = %d", __FUNCTION__, ATEN2011_port->port->number, result);
1603 if (copy_to_user(value, &result, sizeof(int)))
1606 return -ENOIOCTLCMD;
1609 static int set_modem_info(struct ATENINTL_port *ATEN2011_port, unsigned int cmd,
1610 unsigned int __user *value)
1616 struct usb_serial_port *port;
1618 if (ATEN2011_port == NULL)
1621 port = (struct usb_serial_port *)ATEN2011_port->port;
1623 mcr = ATEN2011_port->shadowMCR;
1625 if (copy_from_user(&arg, value, sizeof(int)))
1630 if (arg & TIOCM_RTS)
1632 if (arg & TIOCM_DTR)
1634 if (arg & TIOCM_LOOP)
1635 mcr |= MCR_LOOPBACK;
1639 if (arg & TIOCM_RTS)
1641 if (arg & TIOCM_DTR)
1643 if (arg & TIOCM_LOOP)
1644 mcr &= ~MCR_LOOPBACK;
1648 /* turn off the RTS and DTR and LOOPBACK
1649 * and then only turn on what was asked to */
1650 mcr &= ~(MCR_RTS | MCR_DTR | MCR_LOOPBACK);
1651 mcr |= ((arg & TIOCM_RTS) ? MCR_RTS : 0);
1652 mcr |= ((arg & TIOCM_DTR) ? MCR_DTR : 0);
1653 mcr |= ((arg & TIOCM_LOOP) ? MCR_LOOPBACK : 0);
1657 ATEN2011_port->shadowMCR = mcr;
1659 Data = ATEN2011_port->shadowMCR;
1660 status = set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
1662 dbg("setting MODEM_CONTROL_REGISTER Failed");
1669 static int get_modem_info(struct ATENINTL_port *ATEN2011_port,
1670 unsigned int __user *value)
1672 unsigned int result = 0;
1674 unsigned int mcr = ATEN2011_port->shadowMCR;
1677 status = get_uart_reg(ATEN2011_port->port, MODEM_STATUS_REGISTER, &msr);
1678 result = ((mcr & MCR_DTR) ? TIOCM_DTR : 0) /* 0x002 */
1679 |((mcr & MCR_RTS) ? TIOCM_RTS : 0) /* 0x004 */
1680 |((msr & ATEN2011_MSR_CTS) ? TIOCM_CTS : 0) /* 0x020 */
1681 |((msr & ATEN2011_MSR_CD) ? TIOCM_CAR : 0) /* 0x040 */
1682 |((msr & ATEN2011_MSR_RI) ? TIOCM_RI : 0) /* 0x080 */
1683 |((msr & ATEN2011_MSR_DSR) ? TIOCM_DSR : 0); /* 0x100 */
1685 dbg("%s -- %x", __FUNCTION__, result);
1687 if (copy_to_user(value, &result, sizeof(int)))
1692 static int get_serial_info(struct ATENINTL_port *ATEN2011_port,
1693 struct serial_struct __user *retinfo)
1695 struct serial_struct tmp;
1697 if (ATEN2011_port == NULL)
1703 memset(&tmp, 0, sizeof(tmp));
1705 tmp.type = PORT_16550A;
1706 tmp.line = ATEN2011_port->port->serial->minor;
1707 if (tmp.line == SERIAL_TTY_NO_MINOR)
1709 tmp.port = ATEN2011_port->port->number;
1711 tmp.flags = ASYNC_SKIP_TEST | ASYNC_AUTO_IRQ;
1712 tmp.xmit_fifo_size = NUM_URBS * URB_TRANSFER_BUFFER_SIZE;
1713 tmp.baud_base = 9600;
1714 tmp.close_delay = 5 * HZ;
1715 tmp.closing_wait = 30 * HZ;
1717 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
1722 static int ATEN2011_ioctl(struct tty_struct *tty, struct file *file,
1723 unsigned int cmd, unsigned long arg)
1725 struct usb_serial_port *port = tty->driver_data;
1726 struct ATENINTL_port *ATEN2011_port;
1727 struct async_icount cnow;
1728 struct async_icount cprev;
1729 struct serial_icounter_struct icount;
1731 unsigned int __user *user_arg = (unsigned int __user *)arg;
1733 ATEN2011_port = usb_get_serial_port_data(port);
1735 if (ATEN2011_port == NULL)
1738 dbg("%s - port %d, cmd = 0x%x", __FUNCTION__, port->number, cmd);
1741 /* return number of bytes available */
1744 dbg("%s (%d) TIOCINQ", __FUNCTION__, port->number);
1745 return get_number_bytes_avail(tty, ATEN2011_port, user_arg);
1749 dbg("%s (%d) TIOCOUTQ", __FUNCTION__, port->number);
1750 return put_user(ATEN2011_chars_in_buffer(tty), user_arg);
1754 dbg("%s (%d) TIOCSERGETLSR", __FUNCTION__, port->number);
1755 return get_lsr_info(tty, ATEN2011_port, user_arg);
1761 dbg("%s (%d) TIOCMSET/TIOCMBIC/TIOCMSET", __FUNCTION__,
1763 ATENret = set_modem_info(ATEN2011_port, cmd, user_arg);
1767 dbg("%s (%d) TIOCMGET", __FUNCTION__, port->number);
1768 return get_modem_info(ATEN2011_port, user_arg);
1771 dbg("%s (%d) TIOCGSERIAL", __FUNCTION__, port->number);
1772 return get_serial_info(ATEN2011_port,
1773 (struct serial_struct __user *)arg);
1776 dbg("%s (%d) TIOCSSERIAL", __FUNCTION__, port->number);
1780 dbg("%s (%d) TIOCMIWAIT", __FUNCTION__, port->number);
1781 cprev = ATEN2011_port->icount;
1783 /* see if a signal did it */
1784 if (signal_pending(current))
1785 return -ERESTARTSYS;
1786 cnow = ATEN2011_port->icount;
1787 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
1788 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts)
1789 return -EIO; /* no change => error */
1790 if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
1791 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
1792 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
1793 ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts))) {
1802 cnow = ATEN2011_port->icount;
1803 icount.cts = cnow.cts;
1804 icount.dsr = cnow.dsr;
1805 icount.rng = cnow.rng;
1806 icount.dcd = cnow.dcd;
1807 icount.rx = cnow.rx;
1808 icount.tx = cnow.tx;
1809 icount.frame = cnow.frame;
1810 icount.overrun = cnow.overrun;
1811 icount.parity = cnow.parity;
1812 icount.brk = cnow.brk;
1813 icount.buf_overrun = cnow.buf_overrun;
1815 dbg("%s (%d) TIOCGICOUNT RX=%d, TX=%d", __FUNCTION__,
1816 port->number, icount.rx, icount.tx);
1817 if (copy_to_user((void __user *)arg, &icount, sizeof(icount)))
1825 return -ENOIOCTLCMD;
1828 static int ATEN2011_calc_baud_rate_divisor(int baudRate, int *divisor,
1829 __u16 * clk_sel_val)
1831 dbg("%s - %d", __FUNCTION__, baudRate);
1833 if (baudRate <= 115200) {
1834 *divisor = 115200 / baudRate;
1837 if ((baudRate > 115200) && (baudRate <= 230400)) {
1838 *divisor = 230400 / baudRate;
1839 *clk_sel_val = 0x10;
1840 } else if ((baudRate > 230400) && (baudRate <= 403200)) {
1841 *divisor = 403200 / baudRate;
1842 *clk_sel_val = 0x20;
1843 } else if ((baudRate > 403200) && (baudRate <= 460800)) {
1844 *divisor = 460800 / baudRate;
1845 *clk_sel_val = 0x30;
1846 } else if ((baudRate > 460800) && (baudRate <= 806400)) {
1847 *divisor = 806400 / baudRate;
1848 *clk_sel_val = 0x40;
1849 } else if ((baudRate > 806400) && (baudRate <= 921600)) {
1850 *divisor = 921600 / baudRate;
1851 *clk_sel_val = 0x50;
1852 } else if ((baudRate > 921600) && (baudRate <= 1572864)) {
1853 *divisor = 1572864 / baudRate;
1854 *clk_sel_val = 0x60;
1855 } else if ((baudRate > 1572864) && (baudRate <= 3145728)) {
1856 *divisor = 3145728 / baudRate;
1857 *clk_sel_val = 0x70;
1862 static int ATEN2011_send_cmd_write_baud_rate(struct ATENINTL_port
1863 *ATEN2011_port, int baudRate)
1868 unsigned char number;
1870 struct usb_serial_port *port;
1873 if (ATEN2011_port == NULL)
1876 port = (struct usb_serial_port *)ATEN2011_port->port;
1878 dbg("%s", "Entering .......... ");
1880 minor = ATEN2011_port->port->serial->minor;
1881 if (minor == SERIAL_TTY_NO_MINOR)
1883 number = ATEN2011_port->port->number - minor;
1885 dbg("%s - port = %d, baud = %d", __FUNCTION__,
1886 ATEN2011_port->port->number, baudRate);
1887 /* reset clk_uart_sel in spregOffset */
1888 if (baudRate > 115200) {
1889 #ifdef HW_flow_control
1891 * NOTE: need to see the pther register to modify
1892 * setting h/w flow control bit to 1;
1894 /* Data = ATEN2011_port->shadowMCR; */
1896 ATEN2011_port->shadowMCR = Data;
1897 status = set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
1899 dbg("Writing spreg failed in set_serial_baud");
1905 #ifdef HW_flow_control
1906 /* setting h/w flow control bit to 0; */
1907 /* Data = ATEN2011_port->shadowMCR; */
1909 ATEN2011_port->shadowMCR = Data;
1910 status = set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
1912 dbg("Writing spreg failed in set_serial_baud");
1919 if (1) /* baudRate <= 115200) */
1924 ATEN2011_calc_baud_rate_divisor(baudRate, &divisor,
1926 status = get_reg_sync(port, ATEN2011_port->SpRegOffset, &Data);
1928 dbg("reading spreg failed in set_serial_baud");
1931 Data = (Data & 0x8f) | clk_sel_val;
1932 status = set_reg_sync(port, ATEN2011_port->SpRegOffset, Data);
1934 dbg("Writing spreg failed in set_serial_baud");
1937 /* Calculate the Divisor */
1940 err("%s - bad baud rate", __FUNCTION__);
1941 dbg("%s", "bad baud rate");
1944 /* Enable access to divisor latch */
1945 Data = ATEN2011_port->shadowLCR | SERIAL_LCR_DLAB;
1946 ATEN2011_port->shadowLCR = Data;
1947 set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
1949 /* Write the divisor */
1950 Data = (unsigned char)(divisor & 0xff);
1951 dbg("set_serial_baud Value to write DLL is %x", Data);
1952 set_uart_reg(port, DIVISOR_LATCH_LSB, Data);
1954 Data = (unsigned char)((divisor & 0xff00) >> 8);
1955 dbg("set_serial_baud Value to write DLM is %x", Data);
1956 set_uart_reg(port, DIVISOR_LATCH_MSB, Data);
1958 /* Disable access to divisor latch */
1959 Data = ATEN2011_port->shadowLCR & ~SERIAL_LCR_DLAB;
1960 ATEN2011_port->shadowLCR = Data;
1961 set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
1968 static void ATEN2011_change_port_settings(struct tty_struct *tty,
1969 struct ATENINTL_port *ATEN2011_port,
1970 struct ktermios *old_termios)
1980 struct usb_serial_port *port;
1981 struct usb_serial *serial;
1983 if (ATEN2011_port == NULL)
1986 port = (struct usb_serial_port *)ATEN2011_port->port;
1988 serial = port->serial;
1990 dbg("%s - port %d", __FUNCTION__, ATEN2011_port->port->number);
1992 if (!ATEN2011_port->open) {
1993 dbg("%s - port not opened", __FUNCTION__);
1997 if ((!tty) || (!tty->termios)) {
1998 dbg("%s - no tty structures", __FUNCTION__);
2002 dbg("%s", "Entering .......... ");
2006 lParity = LCR_PAR_NONE;
2008 cflag = tty->termios->c_cflag;
2009 iflag = tty->termios->c_iflag;
2011 /* Change the number of bits */
2013 /* COMMENT1: the below Line"if(cflag & CSIZE)" is added for the errors we get for serial loop data test i.e serial_loopback.pl -v */
2014 /* if(cflag & CSIZE) */
2016 switch (cflag & CSIZE) {
2034 /* Change the Parity bit */
2035 if (cflag & PARENB) {
2036 if (cflag & PARODD) {
2037 lParity = LCR_PAR_ODD;
2038 dbg("%s - parity = odd", __FUNCTION__);
2040 lParity = LCR_PAR_EVEN;
2041 dbg("%s - parity = even", __FUNCTION__);
2045 dbg("%s - parity = none", __FUNCTION__);
2048 if (cflag & CMSPAR) {
2049 lParity = lParity | 0x20;
2052 /* Change the Stop bit */
2053 if (cflag & CSTOPB) {
2055 dbg("%s - stop bits = 2", __FUNCTION__);
2058 dbg("%s - stop bits = 1", __FUNCTION__);
2061 /* Update the LCR with the correct value */
2062 ATEN2011_port->shadowLCR &=
2063 ~(LCR_BITS_MASK | LCR_STOP_MASK | LCR_PAR_MASK);
2064 ATEN2011_port->shadowLCR |= (lData | lParity | lStop);
2067 ("ATEN2011_change_port_settings ATEN2011_port->shadowLCR is %x",
2068 ATEN2011_port->shadowLCR);
2069 /* Disable Interrupts */
2071 set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data);
2074 set_uart_reg(port, FIFO_CONTROL_REGISTER, Data);
2077 set_uart_reg(port, FIFO_CONTROL_REGISTER, Data);
2079 /* Send the updated LCR value to the ATEN2011 */
2080 Data = ATEN2011_port->shadowLCR;
2082 set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
2085 ATEN2011_port->shadowMCR = Data;
2086 set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
2088 set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
2090 /* set up the MCR register and send it to the ATEN2011 */
2092 ATEN2011_port->shadowMCR = MCR_MASTER_IE;
2093 if (cflag & CBAUD) {
2094 ATEN2011_port->shadowMCR |= (MCR_DTR | MCR_RTS);
2097 if (cflag & CRTSCTS) {
2098 ATEN2011_port->shadowMCR |= (MCR_XON_ANY);
2101 ATEN2011_port->shadowMCR &= ~(MCR_XON_ANY);
2104 Data = ATEN2011_port->shadowMCR;
2105 set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
2107 /* Determine divisor based on baud rate */
2108 baud = tty_get_baud_rate(tty);
2111 /* pick a default, any default... */
2112 dbg("%s", "Picked default baud...");
2116 dbg("%s - baud rate = %d", __FUNCTION__, baud);
2117 status = ATEN2011_send_cmd_write_baud_rate(ATEN2011_port, baud);
2119 /* Enable Interrupts */
2121 set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data);
2123 if (ATEN2011_port->read_urb->status != -EINPROGRESS) {
2124 ATEN2011_port->read_urb->dev = serial->dev;
2126 status = usb_submit_urb(ATEN2011_port->read_urb, GFP_ATOMIC);
2130 (" usb_submit_urb(read bulk) failed, status = %d",
2135 ("ATEN2011_change_port_settings ATEN2011_port->shadowLCR is End %x",
2136 ATEN2011_port->shadowLCR);
2141 static int ATEN2011_calc_num_ports(struct usb_serial *serial)
2146 int ATEN2011_2or4ports;
2147 ret = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
2148 ATEN_RDREQ, ATEN_RD_RTYPE, 0, GPIO_REGISTER,
2149 &Data, VENDOR_READ_LENGTH, ATEN_WDR_TIMEOUT);
2151 /* ghostgum: here is where the problem appears to bet */
2152 /* Which of the following are needed? */
2153 /* Greg used the serial->type->num_ports=2 */
2154 /* But the code in the ATEN2011_open relies on serial->num_ports=2 */
2155 if ((Data & 0x01) == 0) {
2156 ATEN2011_2or4ports = 2;
2157 serial->type->num_ports = 2;
2158 serial->num_ports = 2;
2160 /* else if(serial->interface->cur_altsetting->desc.bNumEndpoints == 9) */
2162 ATEN2011_2or4ports = 4;
2163 serial->type->num_ports = 4;
2164 serial->num_ports = 4;
2168 return ATEN2011_2or4ports;
2171 static int ATEN2011_startup(struct usb_serial *serial)
2173 struct ATENINTL_serial *ATEN2011_serial;
2174 struct ATENINTL_port *ATEN2011_port;
2175 struct usb_device *dev;
2180 dbg("%s", " ATEN2011_startup :entering..........");
2183 dbg("%s", "Invalid Handler");
2189 dbg("%s", "Entering...");
2191 /* create our private serial structure */
2192 ATEN2011_serial = kzalloc(sizeof(struct ATENINTL_serial), GFP_KERNEL);
2193 if (ATEN2011_serial == NULL) {
2194 err("%s - Out of memory", __FUNCTION__);
2198 /* resetting the private structure field values to zero */
2199 memset(ATEN2011_serial, 0, sizeof(struct ATENINTL_serial));
2201 ATEN2011_serial->serial = serial;
2202 /* initilize status polling flag to 0 */
2203 ATEN2011_serial->status_polling_started = 0;
2205 usb_set_serial_data(serial, ATEN2011_serial);
2206 ATEN2011_serial->ATEN2011_spectrum_2or4ports =
2207 ATEN2011_calc_num_ports(serial);
2208 /* we set up the pointers to the endpoints in the ATEN2011_open *
2209 * function, as the structures aren't created yet. */
2211 /* set up port private structures */
2212 for (i = 0; i < serial->num_ports; ++i) {
2214 kmalloc(sizeof(struct ATENINTL_port), GFP_KERNEL);
2215 if (ATEN2011_port == NULL) {
2216 err("%s - Out of memory", __FUNCTION__);
2217 usb_set_serial_data(serial, NULL);
2218 kfree(ATEN2011_serial);
2221 memset(ATEN2011_port, 0, sizeof(struct ATENINTL_port));
2224 * Initialize all port interrupt end point to port 0
2225 * int endpoint. Our device has only one interrupt end point
2226 * comman to all port
2228 /* serial->port[i]->interrupt_in_endpointAddress = serial->port[0]->interrupt_in_endpointAddress; */
2230 ATEN2011_port->port = serial->port[i];
2231 usb_set_serial_port_data(serial->port[i], ATEN2011_port);
2233 minor = serial->port[i]->serial->minor;
2234 if (minor == SERIAL_TTY_NO_MINOR)
2236 ATEN2011_port->port_num =
2237 ((serial->port[i]->number - minor) + 1);
2239 if (ATEN2011_port->port_num == 1) {
2240 ATEN2011_port->SpRegOffset = 0x0;
2241 ATEN2011_port->ControlRegOffset = 0x1;
2242 ATEN2011_port->DcrRegOffset = 0x4;
2243 } else if ((ATEN2011_port->port_num == 2)
2244 && (ATEN2011_serial->ATEN2011_spectrum_2or4ports ==
2246 ATEN2011_port->SpRegOffset = 0x8;
2247 ATEN2011_port->ControlRegOffset = 0x9;
2248 ATEN2011_port->DcrRegOffset = 0x16;
2249 } else if ((ATEN2011_port->port_num == 2)
2250 && (ATEN2011_serial->ATEN2011_spectrum_2or4ports ==
2252 ATEN2011_port->SpRegOffset = 0xa;
2253 ATEN2011_port->ControlRegOffset = 0xb;
2254 ATEN2011_port->DcrRegOffset = 0x19;
2255 } else if ((ATEN2011_port->port_num == 3)
2256 && (ATEN2011_serial->ATEN2011_spectrum_2or4ports ==
2258 ATEN2011_port->SpRegOffset = 0xa;
2259 ATEN2011_port->ControlRegOffset = 0xb;
2260 ATEN2011_port->DcrRegOffset = 0x19;
2261 } else if ((ATEN2011_port->port_num == 4)
2262 && (ATEN2011_serial->ATEN2011_spectrum_2or4ports ==
2264 ATEN2011_port->SpRegOffset = 0xc;
2265 ATEN2011_port->ControlRegOffset = 0xd;
2266 ATEN2011_port->DcrRegOffset = 0x1c;
2269 usb_set_serial_port_data(serial->port[i], ATEN2011_port);
2271 /* enable rx_disable bit in control register */
2273 status = get_reg_sync(serial->port[i],
2274 ATEN2011_port->ControlRegOffset, &Data);
2276 dbg("Reading ControlReg failed status-0x%x",
2281 ("ControlReg Reading success val is %x, status%d",
2283 Data |= 0x08; /* setting driver done bit */
2284 Data |= 0x04; /* sp1_bit to have cts change reflect in modem status reg */
2286 /* Data |= 0x20; */ /* rx_disable bit */
2287 status = set_reg_sync(serial->port[i],
2288 ATEN2011_port->ControlRegOffset, Data);
2291 ("Writing ControlReg failed(rx_disable) status-0x%x",
2296 ("ControlReg Writing success(rx_disable) status%d",
2300 * Write default values in DCR (i.e 0x01 in DCR0, 0x05 in DCR2
2304 status = set_reg_sync(serial->port[i],
2305 (__u16)(ATEN2011_port->DcrRegOffset + 0),
2308 dbg("Writing DCR0 failed status-0x%x", status);
2311 dbg("DCR0 Writing success status%d", status);
2314 status = set_reg_sync(serial->port[i],
2315 (__u16)(ATEN2011_port->DcrRegOffset + 1),
2318 dbg("Writing DCR1 failed status-0x%x", status);
2321 dbg("DCR1 Writing success status%d", status);
2324 status = set_reg_sync(serial->port[i],
2325 (__u16)(ATEN2011_port->DcrRegOffset + 2),
2328 dbg("Writing DCR2 failed status-0x%x", status);
2331 dbg("DCR2 Writing success status%d", status);
2333 /* write values in clkstart0x0 and clkmulti 0x20 */
2335 status = set_reg_sync(serial->port[i], CLK_START_VALUE_REGISTER,
2339 ("Writing CLK_START_VALUE_REGISTER failed status-0x%x",
2344 ("CLK_START_VALUE_REGISTER Writing success status%d",
2348 status = set_reg_sync(serial->port[i], CLK_MULTI_REGISTER,
2352 ("Writing CLK_MULTI_REGISTER failed status-0x%x",
2356 dbg("CLK_MULTI_REGISTER Writing success status%d",
2359 /* Zero Length flag register */
2360 if ((ATEN2011_port->port_num != 1)
2361 && (ATEN2011_serial->ATEN2011_spectrum_2or4ports == 2)) {
2364 status = set_reg_sync(serial->port[i],
2365 (__u16)(ZLP_REG1 + ((__u16)ATEN2011_port->port_num)),
2367 dbg("ZLIP offset%x",
2369 ((__u16) ATEN2011_port->port_num)));
2372 ("Writing ZLP_REG%d failed status-0x%x",
2376 dbg("ZLP_REG%d Writing success status%d",
2380 status = set_reg_sync(serial->port[i],
2381 (__u16)(ZLP_REG1 + ((__u16)ATEN2011_port->port_num) - 0x1),
2383 dbg("ZLIP offset%x",
2385 ((__u16) ATEN2011_port->port_num) -
2389 ("Writing ZLP_REG%d failed status-0x%x",
2393 dbg("ZLP_REG%d Writing success status%d",
2397 ATEN2011_port->control_urb = usb_alloc_urb(0, GFP_ATOMIC);
2398 ATEN2011_port->ctrl_buf = kmalloc(16, GFP_KERNEL);
2402 /* Zero Length flag enable */
2404 status = set_reg_sync(serial->port[0], ZLP_REG5, Data);
2406 dbg("Writing ZLP_REG5 failed status-0x%x", status);
2409 dbg("ZLP_REG5 Writing success status%d", status);
2411 /* setting configuration feature to one */
2412 usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
2413 (__u8) 0x03, 0x00, 0x01, 0x00, NULL, 0x00, 5 * HZ);
2417 static void ATEN2011_shutdown(struct usb_serial *serial)
2420 struct ATENINTL_port *ATEN2011_port;
2422 /* check for the ports to be closed,close the ports and disconnect */
2424 /* free private structure allocated for serial port *
2425 * stop reads and writes on all ports */
2427 for (i = 0; i < serial->num_ports; ++i) {
2428 ATEN2011_port = usb_get_serial_port_data(serial->port[i]);
2429 kfree(ATEN2011_port->ctrl_buf);
2430 usb_kill_urb(ATEN2011_port->control_urb);
2431 kfree(ATEN2011_port);
2432 usb_set_serial_port_data(serial->port[i], NULL);
2435 /* free private structure allocated for serial device */
2437 kfree(usb_get_serial_data(serial));
2438 usb_set_serial_data(serial, NULL);
2441 static struct usb_serial_driver aten_serial_driver = {
2443 .owner = THIS_MODULE,
2446 .description = DRIVER_DESC,
2447 .id_table = id_table,
2448 .open = ATEN2011_open,
2449 .close = ATEN2011_close,
2450 .write = ATEN2011_write,
2451 .write_room = ATEN2011_write_room,
2452 .chars_in_buffer = ATEN2011_chars_in_buffer,
2453 .throttle = ATEN2011_throttle,
2454 .unthrottle = ATEN2011_unthrottle,
2455 .calc_num_ports = ATEN2011_calc_num_ports,
2457 .ioctl = ATEN2011_ioctl,
2458 .set_termios = ATEN2011_set_termios,
2459 .break_ctl = ATEN2011_break,
2460 .tiocmget = ATEN2011_tiocmget,
2461 .tiocmset = ATEN2011_tiocmset,
2462 .attach = ATEN2011_startup,
2463 .shutdown = ATEN2011_shutdown,
2464 .read_bulk_callback = ATEN2011_bulk_in_callback,
2465 .read_int_callback = ATEN2011_interrupt_callback,
2468 static struct usb_driver aten_driver = {
2470 .probe = usb_serial_probe,
2471 .disconnect = usb_serial_disconnect,
2472 .id_table = id_table,
2475 static int __init aten_init(void)
2479 /* Register with the usb serial */
2480 retval = usb_serial_register(&aten_serial_driver);
2484 printk(KERN_INFO KBUILD_MODNAME ":"
2485 DRIVER_DESC " " DRIVER_VERSION "\n");
2487 /* Register with the usb */
2488 retval = usb_register(&aten_driver);
2490 usb_serial_deregister(&aten_serial_driver);
2495 static void __exit aten_exit(void)
2497 usb_deregister(&aten_driver);
2498 usb_serial_deregister(&aten_serial_driver);
2501 module_init(aten_init);
2502 module_exit(aten_exit);
2504 /* Module information */
2505 MODULE_DESCRIPTION(DRIVER_DESC);
2506 MODULE_LICENSE("GPL");
2508 MODULE_PARM_DESC(debug, "Debug enabled or not");