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/uaccess.h>
25 #include <linux/usb.h>
26 #include <linux/usb/serial.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 */
99 struct ATENINTL_port {
100 int port_num; /*Actual port number in the device(1,2,etc)*/
101 __u8 bulk_out_endpoint; /* the bulk out endpoint handle */
102 unsigned char *bulk_out_buffer; /* buffer used for the bulk out endpoint */
103 struct urb *write_urb; /* write URB for this port */
104 __u8 bulk_in_endpoint; /* the bulk in endpoint handle */
105 unsigned char *bulk_in_buffer; /* the buffer we use for the bulk in endpoint */
106 struct urb *read_urb; /* read URB for this port */
107 __u8 shadowLCR; /* last LCR value received */
108 __u8 shadowMCR; /* last MCR value received */
110 char chaseResponsePending;
111 wait_queue_head_t wait_chase; /* for handling sleeping while waiting for chase to finish */
112 wait_queue_head_t wait_command; /* for handling sleeping while waiting for command to finish */
113 struct async_icount icount;
114 struct usb_serial_port *port; /* loop back to the owner of this object */
117 __u8 ControlRegOffset;
119 /* for processing control URBS in interrupt context */
120 struct urb *control_urb;
124 struct urb *write_urb_pool[NUM_URBS];
125 /* we pass a pointer to this as the arguement sent to cypress_set_termios old_termios */
126 struct ktermios tmp_termios; /* stores the old termios settings */
127 spinlock_t lock; /* private lock */
130 /* This structure holds all of the individual serial device information */
131 struct ATENINTL_serial {
132 __u8 interrupt_in_endpoint; /* the interrupt endpoint handle */
133 unsigned char *interrupt_in_buffer; /* the buffer we use for the interrupt endpoint */
134 struct urb *interrupt_read_urb; /* our interrupt urb */
135 __u8 bulk_in_endpoint; /* the bulk in endpoint handle */
136 unsigned char *bulk_in_buffer; /* the buffer we use for the bulk in endpoint */
137 struct urb *read_urb; /* our bulk read urb */
138 __u8 bulk_out_endpoint; /* the bulk out endpoint handle */
139 struct usb_serial *serial; /* loop back to the owner of this object */
140 int ATEN2011_spectrum_2or4ports; /* this says the number of ports in the device */
141 /* Indicates about the no.of opened ports of an individual USB-serial adapater. */
142 unsigned int NoOfOpenPorts;
143 /* a flag for Status endpoint polling */
144 unsigned char status_polling_started;
147 static void ATEN2011_set_termios(struct tty_struct *tty,
148 struct usb_serial_port *port,
149 struct ktermios *old_termios);
150 static void ATEN2011_change_port_settings(struct tty_struct *tty,
151 struct ATENINTL_port *ATEN2011_port,
152 struct ktermios *old_termios);
154 /*************************************
155 * Bit definitions for each register *
156 *************************************/
157 #define LCR_BITS_5 0x00 /* 5 bits/char */
158 #define LCR_BITS_6 0x01 /* 6 bits/char */
159 #define LCR_BITS_7 0x02 /* 7 bits/char */
160 #define LCR_BITS_8 0x03 /* 8 bits/char */
161 #define LCR_BITS_MASK 0x03 /* Mask for bits/char field */
163 #define LCR_STOP_1 0x00 /* 1 stop bit */
164 #define LCR_STOP_1_5 0x04 /* 1.5 stop bits (if 5 bits/char) */
165 #define LCR_STOP_2 0x04 /* 2 stop bits (if 6-8 bits/char) */
166 #define LCR_STOP_MASK 0x04 /* Mask for stop bits field */
168 #define LCR_PAR_NONE 0x00 /* No parity */
169 #define LCR_PAR_ODD 0x08 /* Odd parity */
170 #define LCR_PAR_EVEN 0x18 /* Even parity */
171 #define LCR_PAR_MARK 0x28 /* Force parity bit to 1 */
172 #define LCR_PAR_SPACE 0x38 /* Force parity bit to 0 */
173 #define LCR_PAR_MASK 0x38 /* Mask for parity field */
175 #define LCR_SET_BREAK 0x40 /* Set Break condition */
176 #define LCR_DL_ENABLE 0x80 /* Enable access to divisor latch */
178 #define MCR_DTR 0x01 /* Assert DTR */
179 #define MCR_RTS 0x02 /* Assert RTS */
180 #define MCR_OUT1 0x04 /* Loopback only: Sets state of RI */
181 #define MCR_MASTER_IE 0x08 /* Enable interrupt outputs */
182 #define MCR_LOOPBACK 0x10 /* Set internal (digital) loopback mode */
183 #define MCR_XON_ANY 0x20 /* Enable any char to exit XOFF mode */
185 #define ATEN2011_MSR_CTS 0x10 /* Current state of CTS */
186 #define ATEN2011_MSR_DSR 0x20 /* Current state of DSR */
187 #define ATEN2011_MSR_RI 0x40 /* Current state of RI */
188 #define ATEN2011_MSR_CD 0x80 /* Current state of CD */
194 * Version Information
196 #define DRIVER_VERSION "2.0"
197 #define DRIVER_DESC "ATENINTL 2011 USB Serial Adapter"
200 * Defines used for sending commands to port
203 #define ATEN_WDR_TIMEOUT (50) /* default urb timeout */
206 #define ATEN_RD_RTYPE 0xC0
207 #define ATEN_WR_RTYPE 0x40
208 #define ATEN_RDREQ 0x0D
209 #define ATEN_WRREQ 0x0E
210 #define ATEN_CTRL_TIMEOUT 500
211 #define VENDOR_READ_LENGTH (0x01)
213 /* set to 1 for RS485 mode and 0 for RS232 mode */
214 /* FIXME make this somehow dynamic and not build time specific */
215 static int RS485mode;
217 static int set_reg_sync(struct usb_serial_port *port, __u16 reg, __u16 val)
219 struct usb_device *dev = port->serial->dev;
222 dbg("%s: is %x, value %x", __func__, reg, val);
224 return usb_control_msg(dev, usb_sndctrlpipe(dev, 0), ATEN_WRREQ,
225 ATEN_WR_RTYPE, val, reg, NULL, 0,
229 static int get_reg_sync(struct usb_serial_port *port, __u16 reg, __u16 *val)
231 struct usb_device *dev = port->serial->dev;
234 ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), ATEN_RDREQ,
235 ATEN_RD_RTYPE, 0, reg, val, VENDOR_READ_LENGTH,
237 dbg("%s: offset is %x, return val %x", __func__, reg, *val);
238 *val = (*val) & 0x00ff;
242 static int set_uart_reg(struct usb_serial_port *port, __u16 reg, __u16 val)
244 struct usb_device *dev = port->serial->dev;
245 struct ATENINTL_serial *a_serial;
248 a_serial = usb_get_serial_data(port->serial);
249 minor = port->serial->minor;
250 if (minor == SERIAL_TTY_NO_MINOR)
255 * For the UART control registers,
256 * the application number need to be Or'ed
258 if (a_serial->ATEN2011_spectrum_2or4ports == 4)
259 val |= (((__u16)port->number - minor) + 1) << 8;
261 if (((__u16) port->number - minor) == 0)
262 val |= (((__u16)port->number - minor) + 1) << 8;
264 val |= (((__u16)port->number - minor) + 2) << 8;
266 dbg("%s: application number is %x", __func__, val);
268 return usb_control_msg(dev, usb_sndctrlpipe(dev, 0), ATEN_WRREQ,
269 ATEN_WR_RTYPE, val, reg, NULL, 0,
273 static int get_uart_reg(struct usb_serial_port *port, __u16 reg, __u16 *val)
275 struct usb_device *dev = port->serial->dev;
278 struct ATENINTL_serial *a_serial;
279 __u16 minor = port->serial->minor;
281 a_serial = usb_get_serial_data(port->serial);
282 if (minor == SERIAL_TTY_NO_MINOR)
285 /* wval is same as application number */
286 if (a_serial->ATEN2011_spectrum_2or4ports == 4)
287 wval = (((__u16)port->number - minor) + 1) << 8;
289 if (((__u16) port->number - minor) == 0)
290 wval = (((__u16) port->number - minor) + 1) << 8;
292 wval = (((__u16) port->number - minor) + 2) << 8;
294 dbg("%s: application number is %x", __func__, wval);
295 ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), ATEN_RDREQ,
296 ATEN_RD_RTYPE, wval, reg, val, VENDOR_READ_LENGTH,
298 *val = (*val) & 0x00ff;
302 static int handle_newMsr(struct ATENINTL_port *port, __u8 newMsr)
304 struct ATENINTL_port *ATEN2011_port;
305 struct async_icount *icount;
306 ATEN2011_port = port;
307 icount = &ATEN2011_port->icount;
309 (ATEN_MSR_DELTA_CTS | ATEN_MSR_DELTA_DSR | ATEN_MSR_DELTA_RI |
310 ATEN_MSR_DELTA_CD)) {
311 icount = &ATEN2011_port->icount;
313 /* update input line counters */
314 if (newMsr & ATEN_MSR_DELTA_CTS)
316 if (newMsr & ATEN_MSR_DELTA_DSR)
318 if (newMsr & ATEN_MSR_DELTA_CD)
320 if (newMsr & ATEN_MSR_DELTA_RI)
327 static int handle_newLsr(struct ATENINTL_port *port, __u8 newLsr)
329 struct async_icount *icount;
331 dbg("%s - %02x", __func__, newLsr);
333 if (newLsr & SERIAL_LSR_BI) {
335 * Parity and Framing errors only count if they occur exclusive
336 * of a break being received.
338 newLsr &= (__u8) (SERIAL_LSR_OE | SERIAL_LSR_BI);
341 /* update input line counters */
342 icount = &port->icount;
343 if (newLsr & SERIAL_LSR_BI)
345 if (newLsr & SERIAL_LSR_OE)
347 if (newLsr & SERIAL_LSR_PE)
349 if (newLsr & SERIAL_LSR_FE)
355 static void ATEN2011_control_callback(struct urb *urb)
358 struct ATENINTL_port *ATEN2011_port;
361 switch (urb->status) {
368 /* this urb is terminated, clean up */
369 dbg("%s - urb shutting down with status: %d", __func__,
373 dbg("%s - nonzero urb status received: %d", __func__,
378 ATEN2011_port = (struct ATENINTL_port *)urb->context;
380 dbg("%s urb buffer size is %d", __func__, urb->actual_length);
381 dbg("%s ATEN2011_port->MsrLsr is %d port %d", __func__,
382 ATEN2011_port->MsrLsr, ATEN2011_port->port_num);
383 data = urb->transfer_buffer;
384 regval = (__u8) data[0];
385 dbg("%s data is %x", __func__, regval);
386 if (ATEN2011_port->MsrLsr == 0)
387 handle_newMsr(ATEN2011_port, regval);
388 else if (ATEN2011_port->MsrLsr == 1)
389 handle_newLsr(ATEN2011_port, regval);
395 static int ATEN2011_get_reg(struct ATENINTL_port *ATEN, __u16 Wval, __u16 reg,
398 struct usb_device *dev = ATEN->port->serial->dev;
399 struct usb_ctrlrequest *dr = NULL;
400 unsigned char *buffer = NULL;
402 buffer = (__u8 *) ATEN->ctrl_buf;
404 dr = (void *)(buffer + 2);
405 dr->bRequestType = ATEN_RD_RTYPE;
406 dr->bRequest = ATEN_RDREQ;
407 dr->wValue = cpu_to_le16(Wval);
408 dr->wIndex = cpu_to_le16(reg);
409 dr->wLength = cpu_to_le16(2);
411 usb_fill_control_urb(ATEN->control_urb, dev, usb_rcvctrlpipe(dev, 0),
412 (unsigned char *)dr, buffer, 2,
413 ATEN2011_control_callback, ATEN);
414 ATEN->control_urb->transfer_buffer_length = 2;
415 ret = usb_submit_urb(ATEN->control_urb, GFP_ATOMIC);
419 static void ATEN2011_interrupt_callback(struct urb *urb)
423 struct ATENINTL_port *ATEN2011_port;
424 struct ATENINTL_serial *ATEN2011_serial;
425 struct usb_serial *serial;
433 dbg("%s", " : Entering");
435 ATEN2011_serial = (struct ATENINTL_serial *)urb->context;
437 switch (urb->status) {
444 /* this urb is terminated, clean up */
445 dbg("%s - urb shutting down with status: %d", __func__,
449 dbg("%s - nonzero urb status received: %d", __func__,
453 length = urb->actual_length;
454 data = urb->transfer_buffer;
456 serial = ATEN2011_serial->serial;
458 /* ATENINTL get 5 bytes
459 * Byte 1 IIR Port 1 (port.number is 0)
460 * Byte 2 IIR Port 2 (port.number is 1)
461 * Byte 3 IIR Port 3 (port.number is 2)
462 * Byte 4 IIR Port 4 (port.number is 3)
463 * Byte 5 FIFO status for both */
465 if (length && length > 5) {
466 dbg("%s", "Wrong data !!!");
471 if (ATEN2011_serial->ATEN2011_spectrum_2or4ports == 4) {
472 sp[0] = (__u8) data[0];
473 sp[1] = (__u8) data[1];
474 sp[2] = (__u8) data[2];
475 sp[3] = (__u8) data[3];
478 sp[0] = (__u8) data[0];
479 sp[1] = (__u8) data[2];
480 /* sp[2]=(__u8)data[2]; */
481 /* sp[3]=(__u8)data[3]; */
485 for (i = 0; i < serial->num_ports; i++) {
486 ATEN2011_port = usb_get_serial_port_data(serial->port[i]);
487 minor = serial->minor;
488 if (minor == SERIAL_TTY_NO_MINOR)
490 if ((ATEN2011_serial->ATEN2011_spectrum_2or4ports == 2)
493 (((__u16) serial->port[i]->number -
494 (__u16) (minor)) + 2) << 8;
497 (((__u16) serial->port[i]->number -
498 (__u16) (minor)) + 1) << 8;
499 if (ATEN2011_port->open != 0) {
501 dbg("SP%d No Interrupt !!!", i);
503 switch (sp[i] & 0x0f) {
505 dbg("Serial Port %d: Receiver status error or address bit detected in 9-bit mode", i);
506 ATEN2011_port->MsrLsr = 1;
507 ATEN2011_get_reg(ATEN2011_port, wval,
508 LINE_STATUS_REGISTER,
512 dbg("Serial Port %d: Modem status change", i);
513 ATEN2011_port->MsrLsr = 0;
514 ATEN2011_get_reg(ATEN2011_port, wval,
515 MODEM_STATUS_REGISTER,
524 if (ATEN2011_serial->status_polling_started == 0)
527 result = usb_submit_urb(urb, GFP_ATOMIC);
529 dev_err(&urb->dev->dev,
530 "%s - Error %d submitting interrupt urb\n",
537 static void ATEN2011_bulk_in_callback(struct urb *urb)
541 struct usb_serial *serial;
542 struct usb_serial_port *port;
543 struct ATENINTL_serial *ATEN2011_serial;
544 struct ATENINTL_port *ATEN2011_port;
545 struct tty_struct *tty;
548 dbg("nonzero read bulk status received: %d", urb->status);
552 ATEN2011_port = (struct ATENINTL_port *)urb->context;
554 port = (struct usb_serial_port *)ATEN2011_port->port;
555 serial = port->serial;
557 dbg("%s", "Entering...");
559 data = urb->transfer_buffer;
560 ATEN2011_serial = usb_get_serial_data(serial);
562 if (urb->actual_length) {
563 tty = tty_port_tty_get(&ATEN2011_port->port->port);
565 tty_buffer_request_room(tty, urb->actual_length);
566 tty_insert_flip_string(tty, data, urb->actual_length);
567 tty_flip_buffer_push(tty);
571 ATEN2011_port->icount.rx += urb->actual_length;
572 dbg("ATEN2011_port->icount.rx is %d:",
573 ATEN2011_port->icount.rx);
576 if (!ATEN2011_port->read_urb) {
577 dbg("%s", "URB KILLED !!!");
581 if (ATEN2011_port->read_urb->status != -EINPROGRESS) {
582 ATEN2011_port->read_urb->dev = serial->dev;
584 status = usb_submit_urb(ATEN2011_port->read_urb, GFP_ATOMIC);
586 dbg("usb_submit_urb(read bulk) failed, status = %d", status);
590 static void ATEN2011_bulk_out_data_callback(struct urb *urb)
592 struct ATENINTL_port *ATEN2011_port;
593 struct tty_struct *tty;
596 dbg("nonzero write bulk status received:%d", urb->status);
600 ATEN2011_port = (struct ATENINTL_port *)urb->context;
602 dbg("%s", "Entering .........");
604 tty = tty_port_tty_get(&ATEN2011_port->port->port);
606 if (tty && ATEN2011_port->open)
607 /* tell the tty driver that something has changed */
610 /* schedule_work(&ATEN2011_port->port->work); */
615 #ifdef ATENSerialProbe
616 static int ATEN2011_serial_probe(struct usb_serial *serial,
617 const struct usb_device_id *id)
620 /*need to implement the mode_reg reading and updating\
621 structures usb_serial_ device_type\
622 (i.e num_ports, num_bulkin,bulkout etc) */
623 /* Also we can update the changes attach */
628 static int ATEN2011_open(struct tty_struct *tty, struct usb_serial_port *port,
633 struct usb_serial *serial;
637 struct ATENINTL_serial *ATEN2011_serial;
638 struct ATENINTL_port *ATEN2011_port;
639 struct ktermios tmp_termios;
642 serial = port->serial;
644 ATEN2011_port = usb_get_serial_port_data(port);
646 if (ATEN2011_port == NULL)
649 ATEN2011_serial = usb_get_serial_data(serial);
650 if (ATEN2011_serial == NULL)
653 /* increment the number of opened ports counter here */
654 ATEN2011_serial->NoOfOpenPorts++;
656 usb_clear_halt(serial->dev, port->write_urb->pipe);
657 usb_clear_halt(serial->dev, port->read_urb->pipe);
659 /* Initialising the write urb pool */
660 for (j = 0; j < NUM_URBS; ++j) {
661 urb = usb_alloc_urb(0, GFP_ATOMIC);
662 ATEN2011_port->write_urb_pool[j] = urb;
665 err("No more urbs???");
669 urb->transfer_buffer = NULL;
670 urb->transfer_buffer =
671 kmalloc(URB_TRANSFER_BUFFER_SIZE, GFP_KERNEL);
672 if (!urb->transfer_buffer) {
673 err("%s-out of memory for urb buffers.", __func__);
678 /*****************************************************************************
679 * Initialize ATEN2011 -- Write Init values to corresponding Registers
687 * 0x08 : SP1/2 Control Reg
688 *****************************************************************************/
690 /* NEED to check the fallowing Block */
693 status = get_reg_sync(port, ATEN2011_port->SpRegOffset, &Data);
695 dbg("Reading Spreg failed");
699 status = set_reg_sync(port, ATEN2011_port->SpRegOffset, Data);
701 dbg("writing Spreg failed");
706 status = set_reg_sync(port, ATEN2011_port->SpRegOffset, Data);
708 dbg("writing Spreg failed");
712 /* End of block to be checked */
713 /**************************CHECK***************************/
719 status = set_uart_reg(port, SCRATCH_PAD_REGISTER, Data);
721 dbg("Writing SCRATCH_PAD_REGISTER failed status-0x%x", status);
724 dbg("SCRATCH_PAD_REGISTER Writing success status%d", status);
726 /**************************CHECK***************************/
729 status = get_reg_sync(port, ATEN2011_port->ControlRegOffset, &Data);
731 dbg("Reading Controlreg failed");
734 Data |= 0x08; /* Driver done bit */
735 Data |= 0x20; /* rx_disable */
738 set_reg_sync(port, ATEN2011_port->ControlRegOffset, Data);
740 dbg("writing Controlreg failed");
744 * do register settings here
745 * Set all regs to the device default values.
746 * First Disable all interrupts.
750 status = set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data);
752 dbg("disableing interrupts failed");
755 /* Set FIFO_CONTROL_REGISTER to the default value */
757 status = set_uart_reg(port, FIFO_CONTROL_REGISTER, Data);
759 dbg("Writing FIFO_CONTROL_REGISTER failed");
763 Data = 0xcf; /* chk */
764 status = set_uart_reg(port, FIFO_CONTROL_REGISTER, Data);
766 dbg("Writing FIFO_CONTROL_REGISTER failed");
770 Data = 0x03; /* LCR_BITS_8 */
771 status = set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
772 ATEN2011_port->shadowLCR = Data;
774 Data = 0x0b; /* MCR_DTR|MCR_RTS|MCR_MASTER_IE */
775 status = set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
776 ATEN2011_port->shadowMCR = Data;
780 status = get_uart_reg(port, LINE_CONTROL_REGISTER, &Data);
781 ATEN2011_port->shadowLCR = Data;
783 Data |= SERIAL_LCR_DLAB; /* data latch enable in LCR 0x80 */
784 status = set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
787 status = set_uart_reg(port, DIVISOR_LATCH_LSB, Data);
790 status = set_uart_reg(port, DIVISOR_LATCH_MSB, Data);
793 status = get_uart_reg(port, LINE_CONTROL_REGISTER, &Data);
795 /* Data = ATEN2011_port->shadowLCR; */ /* data latch disable */
796 Data = Data & ~SERIAL_LCR_DLAB;
797 status = set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
798 ATEN2011_port->shadowLCR = Data;
800 /* clearing Bulkin and Bulkout Fifo */
802 status = get_reg_sync(port, ATEN2011_port->SpRegOffset, &Data);
805 status = set_reg_sync(port, ATEN2011_port->SpRegOffset, Data);
808 status = set_reg_sync(port, ATEN2011_port->SpRegOffset, Data);
809 /* Finally enable all interrupts */
812 status = set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data);
814 /* clearing rx_disable */
816 status = get_reg_sync(port, ATEN2011_port->ControlRegOffset, &Data);
818 status = set_reg_sync(port, ATEN2011_port->ControlRegOffset, Data);
822 status = get_reg_sync(port, ATEN2011_port->ControlRegOffset, &Data);
825 status = set_reg_sync(port, ATEN2011_port->ControlRegOffset, Data);
828 * Check to see if we've set up our endpoint info yet
829 * (can't set it up in ATEN2011_startup as the structures
830 * were not set up at that time.)
832 if (ATEN2011_serial->NoOfOpenPorts == 1) {
833 /* start the status polling here */
834 ATEN2011_serial->status_polling_started = 1;
835 /* If not yet set, Set here */
836 ATEN2011_serial->interrupt_in_buffer =
837 serial->port[0]->interrupt_in_buffer;
838 ATEN2011_serial->interrupt_in_endpoint =
839 serial->port[0]->interrupt_in_endpointAddress;
840 ATEN2011_serial->interrupt_read_urb =
841 serial->port[0]->interrupt_in_urb;
843 /* set up interrupt urb */
844 usb_fill_int_urb(ATEN2011_serial->interrupt_read_urb,
846 usb_rcvintpipe(serial->dev,
848 interrupt_in_endpoint),
849 ATEN2011_serial->interrupt_in_buffer,
850 ATEN2011_serial->interrupt_read_urb->
851 transfer_buffer_length,
852 ATEN2011_interrupt_callback, ATEN2011_serial,
853 ATEN2011_serial->interrupt_read_urb->interval);
855 /* start interrupt read for ATEN2011 *
856 * will continue as long as ATEN2011 is connected */
859 usb_submit_urb(ATEN2011_serial->interrupt_read_urb,
862 dbg("%s - Error %d submitting interrupt urb",
869 * See if we've set up our endpoint info yet
870 * (can't set it up in ATEN2011_startup as the
871 * structures were not set up at that time.)
874 dbg("port number is %d", port->number);
875 dbg("serial number is %d", port->serial->minor);
876 dbg("Bulkin endpoint is %d", port->bulk_in_endpointAddress);
877 dbg("BulkOut endpoint is %d", port->bulk_out_endpointAddress);
878 dbg("Interrupt endpoint is %d",
879 port->interrupt_in_endpointAddress);
880 dbg("port's number in the device is %d", ATEN2011_port->port_num);
881 ATEN2011_port->bulk_in_buffer = port->bulk_in_buffer;
882 ATEN2011_port->bulk_in_endpoint = port->bulk_in_endpointAddress;
883 ATEN2011_port->read_urb = port->read_urb;
884 ATEN2011_port->bulk_out_endpoint = port->bulk_out_endpointAddress;
886 minor = port->serial->minor;
887 if (minor == SERIAL_TTY_NO_MINOR)
890 /* set up our bulk in urb */
891 if ((ATEN2011_serial->ATEN2011_spectrum_2or4ports == 2)
892 && (((__u16) port->number - (__u16) (minor)) != 0)) {
893 usb_fill_bulk_urb(ATEN2011_port->read_urb, serial->dev,
894 usb_rcvbulkpipe(serial->dev,
896 bulk_in_endpointAddress +
897 2)), port->bulk_in_buffer,
898 ATEN2011_port->read_urb->
899 transfer_buffer_length,
900 ATEN2011_bulk_in_callback, ATEN2011_port);
902 usb_fill_bulk_urb(ATEN2011_port->read_urb,
904 usb_rcvbulkpipe(serial->dev,
906 bulk_in_endpointAddress),
907 port->bulk_in_buffer,
908 ATEN2011_port->read_urb->
909 transfer_buffer_length,
910 ATEN2011_bulk_in_callback, ATEN2011_port);
912 dbg("ATEN2011_open: bulkin endpoint is %d",
913 port->bulk_in_endpointAddress);
914 response = usb_submit_urb(ATEN2011_port->read_urb, GFP_KERNEL);
916 err("%s - Error %d submitting control urb", __func__,
920 /* initialize our wait queues */
921 init_waitqueue_head(&ATEN2011_port->wait_chase);
922 init_waitqueue_head(&ATEN2011_port->wait_command);
924 /* initialize our icount structure */
925 memset(&(ATEN2011_port->icount), 0x00, sizeof(ATEN2011_port->icount));
927 /* initialize our port settings */
928 ATEN2011_port->shadowMCR = MCR_MASTER_IE; /* Must set to enable ints! */
929 ATEN2011_port->chaseResponsePending = 0;
930 /* send a open port command */
931 ATEN2011_port->open = 1;
932 /* ATEN2011_change_port_settings(ATEN2011_port,old_termios); */
934 ATEN2011_set_termios(tty, port, &tmp_termios);
935 ATEN2011_port->icount.tx = 0;
936 ATEN2011_port->icount.rx = 0;
938 dbg("usb_serial serial:%x ATEN2011_port:%x\nATEN2011_serial:%x usb_serial_port port:%x",
939 (unsigned int)serial, (unsigned int)ATEN2011_port,
940 (unsigned int)ATEN2011_serial, (unsigned int)port);
946 static int ATEN2011_chars_in_buffer(struct tty_struct *tty)
948 struct usb_serial_port *port = tty->driver_data;
951 struct ATENINTL_port *ATEN2011_port;
953 /* dbg("%s"," ATEN2011_chars_in_buffer:entering ..........."); */
955 ATEN2011_port = usb_get_serial_port_data(port);
956 if (ATEN2011_port == NULL) {
957 dbg("%s", "ATEN2011_break:leaving ...........");
961 for (i = 0; i < NUM_URBS; ++i)
962 if (ATEN2011_port->write_urb_pool[i]->status == -EINPROGRESS)
963 chars += URB_TRANSFER_BUFFER_SIZE;
965 dbg("%s - returns %d", __func__, chars);
970 static void ATEN2011_block_until_tx_empty(struct tty_struct *tty,
971 struct ATENINTL_port *ATEN2011_port)
973 int timeout = HZ / 10;
978 count = ATEN2011_chars_in_buffer(tty);
980 /* Check for Buffer status */
984 /* Block the thread for a while */
985 interruptible_sleep_on_timeout(&ATEN2011_port->wait_chase,
988 /* No activity.. count down section */
991 dbg("%s - TIMEOUT", __func__);
994 /* Reset timout value back to seconds */
1000 static void ATEN2011_close(struct tty_struct *tty, struct usb_serial_port *port,
1003 struct usb_serial *serial;
1004 struct ATENINTL_serial *ATEN2011_serial;
1005 struct ATENINTL_port *ATEN2011_port;
1009 dbg("%s", "ATEN2011_close:entering...");
1010 serial = port->serial;
1012 /* take the Adpater and port's private data */
1013 ATEN2011_serial = usb_get_serial_data(serial);
1014 ATEN2011_port = usb_get_serial_port_data(port);
1015 if ((ATEN2011_serial == NULL) || (ATEN2011_port == NULL))
1019 /* flush and block(wait) until tx is empty */
1020 ATEN2011_block_until_tx_empty(tty, ATEN2011_port);
1022 /* kill the ports URB's */
1023 for (no_urbs = 0; no_urbs < NUM_URBS; no_urbs++)
1024 usb_kill_urb(ATEN2011_port->write_urb_pool[no_urbs]);
1025 /* Freeing Write URBs */
1026 for (no_urbs = 0; no_urbs < NUM_URBS; ++no_urbs) {
1027 kfree(ATEN2011_port->write_urb_pool[no_urbs]->transfer_buffer);
1028 usb_free_urb(ATEN2011_port->write_urb_pool[no_urbs]);
1030 /* While closing port, shutdown all bulk read, write *
1031 * and interrupt read if they exists */
1033 if (ATEN2011_port->write_urb) {
1034 dbg("%s", "Shutdown bulk write");
1035 usb_kill_urb(ATEN2011_port->write_urb);
1037 if (ATEN2011_port->read_urb) {
1038 dbg("%s", "Shutdown bulk read");
1039 usb_kill_urb(ATEN2011_port->read_urb);
1041 if ((&ATEN2011_port->control_urb)) {
1042 dbg("%s", "Shutdown control read");
1043 /* usb_kill_urb (ATEN2011_port->control_urb); */
1047 /* if(ATEN2011_port->ctrl_buf != NULL) */
1048 /* kfree(ATEN2011_port->ctrl_buf); */
1049 /* decrement the no.of open ports counter of an individual USB-serial adapter. */
1050 ATEN2011_serial->NoOfOpenPorts--;
1051 dbg("NoOfOpenPorts in close%d:in port%d",
1052 ATEN2011_serial->NoOfOpenPorts, port->number);
1053 if (ATEN2011_serial->NoOfOpenPorts == 0) {
1054 /* stop the stus polling here */
1055 ATEN2011_serial->status_polling_started = 0;
1056 if (ATEN2011_serial->interrupt_read_urb) {
1057 dbg("%s", "Shutdown interrupt_read_urb");
1058 /* ATEN2011_serial->interrupt_in_buffer=NULL; */
1059 /* usb_kill_urb (ATEN2011_serial->interrupt_read_urb); */
1062 if (ATEN2011_port->write_urb) {
1063 /* if this urb had a transfer buffer already (old tx) free it */
1064 kfree(ATEN2011_port->write_urb->transfer_buffer);
1065 usb_free_urb(ATEN2011_port->write_urb);
1068 /* clear the MCR & IER */
1070 set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
1072 set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data);
1074 ATEN2011_port->open = 0;
1075 dbg("%s", "Leaving ............");
1079 static void ATEN2011_block_until_chase_response(struct tty_struct *tty,
1080 struct ATENINTL_port
1083 int timeout = 1 * HZ;
1088 count = ATEN2011_chars_in_buffer(tty);
1090 /* Check for Buffer status */
1092 ATEN2011_port->chaseResponsePending = 0;
1096 /* Block the thread for a while */
1097 interruptible_sleep_on_timeout(&ATEN2011_port->wait_chase,
1099 /* No activity.. count down section */
1102 dbg("%s - TIMEOUT", __func__);
1105 /* Reset timout value back to seconds */
1112 static void ATEN2011_break(struct tty_struct *tty, int break_state)
1114 struct usb_serial_port *port = tty->driver_data;
1116 struct usb_serial *serial;
1117 struct ATENINTL_serial *ATEN2011_serial;
1118 struct ATENINTL_port *ATEN2011_port;
1120 dbg("%s", "Entering ...........");
1121 dbg("ATEN2011_break: Start");
1123 serial = port->serial;
1125 ATEN2011_serial = usb_get_serial_data(serial);
1126 ATEN2011_port = usb_get_serial_port_data(port);
1128 if ((ATEN2011_serial == NULL) || (ATEN2011_port == NULL))
1131 /* flush and chase */
1132 ATEN2011_port->chaseResponsePending = 1;
1135 /* flush and block until tx is empty */
1136 ATEN2011_block_until_chase_response(tty, ATEN2011_port);
1139 if (break_state == -1)
1140 data = ATEN2011_port->shadowLCR | LCR_SET_BREAK;
1142 data = ATEN2011_port->shadowLCR & ~LCR_SET_BREAK;
1144 ATEN2011_port->shadowLCR = data;
1145 dbg("ATEN2011_break ATEN2011_port->shadowLCR is %x",
1146 ATEN2011_port->shadowLCR);
1147 set_uart_reg(port, LINE_CONTROL_REGISTER, ATEN2011_port->shadowLCR);
1152 static int ATEN2011_write_room(struct tty_struct *tty)
1154 struct usb_serial_port *port = tty->driver_data;
1157 struct ATENINTL_port *ATEN2011_port;
1159 ATEN2011_port = usb_get_serial_port_data(port);
1160 if (ATEN2011_port == NULL) {
1161 dbg("%s", "ATEN2011_break:leaving ...........");
1165 for (i = 0; i < NUM_URBS; ++i)
1166 if (ATEN2011_port->write_urb_pool[i]->status != -EINPROGRESS)
1167 room += URB_TRANSFER_BUFFER_SIZE;
1169 dbg("%s - returns %d", __func__, room);
1174 static int ATEN2011_write(struct tty_struct *tty, struct usb_serial_port *port,
1175 const unsigned char *data, int count)
1183 struct ATENINTL_port *ATEN2011_port;
1184 struct usb_serial *serial;
1185 struct ATENINTL_serial *ATEN2011_serial;
1187 const unsigned char *current_position = data;
1188 unsigned char *data1;
1189 dbg("%s", "entering ...........");
1191 serial = port->serial;
1193 ATEN2011_port = usb_get_serial_port_data(port);
1194 if (ATEN2011_port == NULL) {
1195 dbg("%s", "ATEN2011_port is NULL");
1199 ATEN2011_serial = usb_get_serial_data(serial);
1200 if (ATEN2011_serial == NULL) {
1201 dbg("%s", "ATEN2011_serial is NULL");
1205 /* try to find a free urb in the list */
1208 for (i = 0; i < NUM_URBS; ++i) {
1209 if (ATEN2011_port->write_urb_pool[i]->status != -EINPROGRESS) {
1210 urb = ATEN2011_port->write_urb_pool[i];
1217 dbg("%s - no more free urbs", __func__);
1221 if (urb->transfer_buffer == NULL) {
1222 urb->transfer_buffer =
1223 kmalloc(URB_TRANSFER_BUFFER_SIZE, GFP_KERNEL);
1225 if (urb->transfer_buffer == NULL) {
1226 err("%s no more kernel memory...", __func__);
1230 transfer_size = min(count, URB_TRANSFER_BUFFER_SIZE);
1232 memcpy(urb->transfer_buffer, current_position, transfer_size);
1233 /* usb_serial_debug_data (__FILE__, __func__, transfer_size, urb->transfer_buffer); */
1235 /* fill urb with data and submit */
1236 minor = port->serial->minor;
1237 if (minor == SERIAL_TTY_NO_MINOR)
1239 if ((ATEN2011_serial->ATEN2011_spectrum_2or4ports == 2)
1240 && (((__u16) port->number - (__u16) (minor)) != 0)) {
1241 usb_fill_bulk_urb(urb, ATEN2011_serial->serial->dev,
1242 usb_sndbulkpipe(ATEN2011_serial->serial->dev,
1244 bulk_out_endpointAddress) +
1245 2), urb->transfer_buffer,
1247 ATEN2011_bulk_out_data_callback,
1251 usb_fill_bulk_urb(urb,
1252 ATEN2011_serial->serial->dev,
1253 usb_sndbulkpipe(ATEN2011_serial->serial->dev,
1255 bulk_out_endpointAddress),
1256 urb->transfer_buffer, transfer_size,
1257 ATEN2011_bulk_out_data_callback,
1260 data1 = urb->transfer_buffer;
1261 dbg("bulkout endpoint is %d", port->bulk_out_endpointAddress);
1262 /* for(i=0;i < urb->actual_length;i++) */
1263 /* dbg("Data is %c ",data1[i]); */
1265 /* send it down the pipe */
1266 status = usb_submit_urb(urb, GFP_ATOMIC);
1269 err("%s - usb_submit_urb(write bulk) failed with status = %d",
1271 bytes_sent = status;
1274 bytes_sent = transfer_size;
1275 ATEN2011_port->icount.tx += transfer_size;
1276 dbg("ATEN2011_port->icount.tx is %d:", ATEN2011_port->icount.tx);
1282 static void ATEN2011_throttle(struct tty_struct *tty)
1284 struct usb_serial_port *port = tty->driver_data;
1285 struct ATENINTL_port *ATEN2011_port;
1288 dbg("- port %d", port->number);
1290 ATEN2011_port = usb_get_serial_port_data(port);
1292 if (ATEN2011_port == NULL)
1295 if (!ATEN2011_port->open) {
1296 dbg("%s", "port not opened");
1300 dbg("%s", "Entering .......... ");
1303 dbg("%s - no tty available", __func__);
1307 /* if we are implementing XON/XOFF, send the stop character */
1309 unsigned char stop_char = STOP_CHAR(tty);
1310 status = ATEN2011_write(tty, port, &stop_char, 1);
1315 /* if we are implementing RTS/CTS, toggle that line */
1316 if (tty->termios->c_cflag & CRTSCTS) {
1317 ATEN2011_port->shadowMCR &= ~MCR_RTS;
1318 status = set_uart_reg(port, MODEM_CONTROL_REGISTER,
1319 ATEN2011_port->shadowMCR);
1327 static void ATEN2011_unthrottle(struct tty_struct *tty)
1329 struct usb_serial_port *port = tty->driver_data;
1331 struct ATENINTL_port *ATEN2011_port = usb_get_serial_port_data(port);
1333 if (ATEN2011_port == NULL)
1336 if (!ATEN2011_port->open) {
1337 dbg("%s - port not opened", __func__);
1341 dbg("%s", "Entering .......... ");
1344 dbg("%s - no tty available", __func__);
1348 /* if we are implementing XON/XOFF, send the start character */
1350 unsigned char start_char = START_CHAR(tty);
1351 status = ATEN2011_write(tty, port, &start_char, 1);
1356 /* if we are implementing RTS/CTS, toggle that line */
1357 if (tty->termios->c_cflag & CRTSCTS) {
1358 ATEN2011_port->shadowMCR |= MCR_RTS;
1359 status = set_uart_reg(port, MODEM_CONTROL_REGISTER,
1360 ATEN2011_port->shadowMCR);
1368 static int ATEN2011_tiocmget(struct tty_struct *tty, struct file *file)
1370 struct usb_serial_port *port = tty->driver_data;
1371 struct ATENINTL_port *ATEN2011_port;
1372 unsigned int result;
1375 /* unsigned int mcr; */
1377 ATEN2011_port = usb_get_serial_port_data(port);
1379 dbg("%s - port %d", __func__, port->number);
1381 if (ATEN2011_port == NULL)
1384 status = get_uart_reg(port, MODEM_STATUS_REGISTER, &msr);
1385 status = get_uart_reg(port, MODEM_CONTROL_REGISTER, &mcr);
1386 /* mcr = ATEN2011_port->shadowMCR; */
1387 /* COMMENT2: the Fallowing three line are commented for updating only MSR values */
1388 result = ((mcr & MCR_DTR) ? TIOCM_DTR : 0)
1389 | ((mcr & MCR_RTS) ? TIOCM_RTS : 0)
1390 | ((mcr & MCR_LOOPBACK) ? TIOCM_LOOP : 0)
1391 | ((msr & ATEN2011_MSR_CTS) ? TIOCM_CTS : 0)
1392 | ((msr & ATEN2011_MSR_CD) ? TIOCM_CAR : 0)
1393 | ((msr & ATEN2011_MSR_RI) ? TIOCM_RI : 0)
1394 | ((msr & ATEN2011_MSR_DSR) ? TIOCM_DSR : 0);
1396 dbg("%s - 0x%04X", __func__, result);
1401 static int ATEN2011_tiocmset(struct tty_struct *tty, struct file *file,
1402 unsigned int set, unsigned int clear)
1404 struct usb_serial_port *port = tty->driver_data;
1405 struct ATENINTL_port *ATEN2011_port;
1407 unsigned int status;
1409 dbg("%s - port %d", __func__, port->number);
1411 ATEN2011_port = usb_get_serial_port_data(port);
1413 if (ATEN2011_port == NULL)
1416 mcr = ATEN2011_port->shadowMCR;
1417 if (clear & TIOCM_RTS)
1419 if (clear & TIOCM_DTR)
1421 if (clear & TIOCM_LOOP)
1422 mcr &= ~MCR_LOOPBACK;
1424 if (set & TIOCM_RTS)
1426 if (set & TIOCM_DTR)
1428 if (set & TIOCM_LOOP)
1429 mcr |= MCR_LOOPBACK;
1431 ATEN2011_port->shadowMCR = mcr;
1433 status = set_uart_reg(port, MODEM_CONTROL_REGISTER, mcr);
1435 dbg("setting MODEM_CONTROL_REGISTER Failed");
1442 static void ATEN2011_set_termios(struct tty_struct *tty,
1443 struct usb_serial_port *port,
1444 struct ktermios *old_termios)
1448 struct usb_serial *serial;
1449 struct ATENINTL_port *ATEN2011_port;
1451 dbg("ATEN2011_set_termios: START");
1453 serial = port->serial;
1455 ATEN2011_port = usb_get_serial_port_data(port);
1457 if (ATEN2011_port == NULL)
1460 if (!ATEN2011_port->open) {
1461 dbg("%s - port not opened", __func__);
1465 dbg("%s", "setting termios - ");
1467 cflag = tty->termios->c_cflag;
1469 dbg("%s - cflag %08x iflag %08x", __func__,
1470 tty->termios->c_cflag, RELEVANT_IFLAG(tty->termios->c_iflag));
1473 dbg("%s - old clfag %08x old iflag %08x", __func__,
1474 old_termios->c_cflag, RELEVANT_IFLAG(old_termios->c_iflag));
1477 dbg("%s - port %d", __func__, port->number);
1479 /* change the port settings to the new ones specified */
1481 ATEN2011_change_port_settings(tty, ATEN2011_port, old_termios);
1483 if (!ATEN2011_port->read_urb) {
1484 dbg("%s", "URB KILLED !!!!!");
1488 if (ATEN2011_port->read_urb->status != -EINPROGRESS) {
1489 ATEN2011_port->read_urb->dev = serial->dev;
1490 status = usb_submit_urb(ATEN2011_port->read_urb, GFP_ATOMIC);
1493 (" usb_submit_urb(read bulk) failed, status = %d",
1500 static int get_lsr_info(struct tty_struct *tty,
1501 struct ATENINTL_port *ATEN2011_port,
1502 unsigned int __user *value)
1505 unsigned int result = 0;
1507 count = ATEN2011_chars_in_buffer(tty);
1509 dbg("%s -- Empty", __func__);
1510 result = TIOCSER_TEMT;
1513 if (copy_to_user(value, &result, sizeof(int)))
1518 static int get_number_bytes_avail(struct tty_struct *tty,
1519 struct ATENINTL_port *ATEN2011_port,
1520 unsigned int __user *value)
1522 unsigned int result = 0;
1525 return -ENOIOCTLCMD;
1527 result = tty->read_cnt;
1529 dbg("%s(%d) = %d", __func__, ATEN2011_port->port->number, result);
1530 if (copy_to_user(value, &result, sizeof(int)))
1533 return -ENOIOCTLCMD;
1536 static int set_modem_info(struct ATENINTL_port *ATEN2011_port, unsigned int cmd,
1537 unsigned int __user *value)
1543 struct usb_serial_port *port;
1545 if (ATEN2011_port == NULL)
1548 port = (struct usb_serial_port *)ATEN2011_port->port;
1550 mcr = ATEN2011_port->shadowMCR;
1552 if (copy_from_user(&arg, value, sizeof(int)))
1557 if (arg & TIOCM_RTS)
1559 if (arg & TIOCM_DTR)
1561 if (arg & TIOCM_LOOP)
1562 mcr |= MCR_LOOPBACK;
1566 if (arg & TIOCM_RTS)
1568 if (arg & TIOCM_DTR)
1570 if (arg & TIOCM_LOOP)
1571 mcr &= ~MCR_LOOPBACK;
1575 /* turn off the RTS and DTR and LOOPBACK
1576 * and then only turn on what was asked to */
1577 mcr &= ~(MCR_RTS | MCR_DTR | MCR_LOOPBACK);
1578 mcr |= ((arg & TIOCM_RTS) ? MCR_RTS : 0);
1579 mcr |= ((arg & TIOCM_DTR) ? MCR_DTR : 0);
1580 mcr |= ((arg & TIOCM_LOOP) ? MCR_LOOPBACK : 0);
1584 ATEN2011_port->shadowMCR = mcr;
1586 Data = ATEN2011_port->shadowMCR;
1587 status = set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
1589 dbg("setting MODEM_CONTROL_REGISTER Failed");
1596 static int get_modem_info(struct ATENINTL_port *ATEN2011_port,
1597 unsigned int __user *value)
1599 unsigned int result = 0;
1601 unsigned int mcr = ATEN2011_port->shadowMCR;
1604 status = get_uart_reg(ATEN2011_port->port, MODEM_STATUS_REGISTER, &msr);
1605 result = ((mcr & MCR_DTR) ? TIOCM_DTR : 0) /* 0x002 */
1606 |((mcr & MCR_RTS) ? TIOCM_RTS : 0) /* 0x004 */
1607 |((msr & ATEN2011_MSR_CTS) ? TIOCM_CTS : 0) /* 0x020 */
1608 |((msr & ATEN2011_MSR_CD) ? TIOCM_CAR : 0) /* 0x040 */
1609 |((msr & ATEN2011_MSR_RI) ? TIOCM_RI : 0) /* 0x080 */
1610 |((msr & ATEN2011_MSR_DSR) ? TIOCM_DSR : 0); /* 0x100 */
1612 dbg("%s -- %x", __func__, result);
1614 if (copy_to_user(value, &result, sizeof(int)))
1619 static int get_serial_info(struct ATENINTL_port *ATEN2011_port,
1620 struct serial_struct __user *retinfo)
1622 struct serial_struct tmp;
1624 if (ATEN2011_port == NULL)
1630 memset(&tmp, 0, sizeof(tmp));
1632 tmp.type = PORT_16550A;
1633 tmp.line = ATEN2011_port->port->serial->minor;
1634 if (tmp.line == SERIAL_TTY_NO_MINOR)
1636 tmp.port = ATEN2011_port->port->number;
1638 tmp.flags = ASYNC_SKIP_TEST | ASYNC_AUTO_IRQ;
1639 tmp.xmit_fifo_size = NUM_URBS * URB_TRANSFER_BUFFER_SIZE;
1640 tmp.baud_base = 9600;
1641 tmp.close_delay = 5 * HZ;
1642 tmp.closing_wait = 30 * HZ;
1644 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
1649 static int ATEN2011_ioctl(struct tty_struct *tty, struct file *file,
1650 unsigned int cmd, unsigned long arg)
1652 struct usb_serial_port *port = tty->driver_data;
1653 struct ATENINTL_port *ATEN2011_port;
1654 struct async_icount cnow;
1655 struct async_icount cprev;
1656 struct serial_icounter_struct icount;
1658 unsigned int __user *user_arg = (unsigned int __user *)arg;
1660 ATEN2011_port = usb_get_serial_port_data(port);
1662 if (ATEN2011_port == NULL)
1665 dbg("%s - port %d, cmd = 0x%x", __func__, port->number, cmd);
1668 /* return number of bytes available */
1671 dbg("%s (%d) TIOCINQ", __func__, port->number);
1672 return get_number_bytes_avail(tty, ATEN2011_port, user_arg);
1676 dbg("%s (%d) TIOCOUTQ", __func__, port->number);
1677 return put_user(ATEN2011_chars_in_buffer(tty), user_arg);
1681 dbg("%s (%d) TIOCSERGETLSR", __func__, port->number);
1682 return get_lsr_info(tty, ATEN2011_port, user_arg);
1688 dbg("%s (%d) TIOCMSET/TIOCMBIC/TIOCMSET", __func__,
1690 ATENret = set_modem_info(ATEN2011_port, cmd, user_arg);
1694 dbg("%s (%d) TIOCMGET", __func__, port->number);
1695 return get_modem_info(ATEN2011_port, user_arg);
1698 dbg("%s (%d) TIOCGSERIAL", __func__, port->number);
1699 return get_serial_info(ATEN2011_port,
1700 (struct serial_struct __user *)arg);
1703 dbg("%s (%d) TIOCSSERIAL", __func__, port->number);
1707 dbg("%s (%d) TIOCMIWAIT", __func__, port->number);
1708 cprev = ATEN2011_port->icount;
1710 /* see if a signal did it */
1711 if (signal_pending(current))
1712 return -ERESTARTSYS;
1713 cnow = ATEN2011_port->icount;
1714 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
1715 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts)
1716 return -EIO; /* no change => error */
1717 if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
1718 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
1719 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
1720 ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts))) {
1729 cnow = ATEN2011_port->icount;
1730 icount.cts = cnow.cts;
1731 icount.dsr = cnow.dsr;
1732 icount.rng = cnow.rng;
1733 icount.dcd = cnow.dcd;
1734 icount.rx = cnow.rx;
1735 icount.tx = cnow.tx;
1736 icount.frame = cnow.frame;
1737 icount.overrun = cnow.overrun;
1738 icount.parity = cnow.parity;
1739 icount.brk = cnow.brk;
1740 icount.buf_overrun = cnow.buf_overrun;
1742 dbg("%s (%d) TIOCGICOUNT RX=%d, TX=%d", __func__,
1743 port->number, icount.rx, icount.tx);
1744 if (copy_to_user((void __user *)arg, &icount, sizeof(icount)))
1752 return -ENOIOCTLCMD;
1755 static int ATEN2011_calc_baud_rate_divisor(int baudRate, int *divisor,
1758 dbg("%s - %d", __func__, baudRate);
1760 if (baudRate <= 115200) {
1761 *divisor = 115200 / baudRate;
1764 if ((baudRate > 115200) && (baudRate <= 230400)) {
1765 *divisor = 230400 / baudRate;
1766 *clk_sel_val = 0x10;
1767 } else if ((baudRate > 230400) && (baudRate <= 403200)) {
1768 *divisor = 403200 / baudRate;
1769 *clk_sel_val = 0x20;
1770 } else if ((baudRate > 403200) && (baudRate <= 460800)) {
1771 *divisor = 460800 / baudRate;
1772 *clk_sel_val = 0x30;
1773 } else if ((baudRate > 460800) && (baudRate <= 806400)) {
1774 *divisor = 806400 / baudRate;
1775 *clk_sel_val = 0x40;
1776 } else if ((baudRate > 806400) && (baudRate <= 921600)) {
1777 *divisor = 921600 / baudRate;
1778 *clk_sel_val = 0x50;
1779 } else if ((baudRate > 921600) && (baudRate <= 1572864)) {
1780 *divisor = 1572864 / baudRate;
1781 *clk_sel_val = 0x60;
1782 } else if ((baudRate > 1572864) && (baudRate <= 3145728)) {
1783 *divisor = 3145728 / baudRate;
1784 *clk_sel_val = 0x70;
1789 static int ATEN2011_send_cmd_write_baud_rate(struct ATENINTL_port
1790 *ATEN2011_port, int baudRate)
1795 unsigned char number;
1797 struct usb_serial_port *port;
1800 if (ATEN2011_port == NULL)
1803 port = (struct usb_serial_port *)ATEN2011_port->port;
1805 dbg("%s", "Entering .......... ");
1807 minor = ATEN2011_port->port->serial->minor;
1808 if (minor == SERIAL_TTY_NO_MINOR)
1810 number = ATEN2011_port->port->number - minor;
1812 dbg("%s - port = %d, baud = %d", __func__,
1813 ATEN2011_port->port->number, baudRate);
1814 /* reset clk_uart_sel in spregOffset */
1815 if (baudRate > 115200) {
1816 #ifdef HW_flow_control
1818 * NOTE: need to see the pther register to modify
1819 * setting h/w flow control bit to 1;
1821 /* Data = ATEN2011_port->shadowMCR; */
1823 ATEN2011_port->shadowMCR = Data;
1824 status = set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
1826 dbg("Writing spreg failed in set_serial_baud");
1832 #ifdef HW_flow_control
1833 /* setting h/w flow control bit to 0; */
1834 /* Data = ATEN2011_port->shadowMCR; */
1836 ATEN2011_port->shadowMCR = Data;
1837 status = set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
1839 dbg("Writing spreg failed in set_serial_baud");
1846 if (1) /* baudRate <= 115200) */ {
1850 ATEN2011_calc_baud_rate_divisor(baudRate, &divisor,
1852 status = get_reg_sync(port, ATEN2011_port->SpRegOffset, &Data);
1854 dbg("reading spreg failed in set_serial_baud");
1857 Data = (Data & 0x8f) | clk_sel_val;
1858 status = set_reg_sync(port, ATEN2011_port->SpRegOffset, Data);
1860 dbg("Writing spreg failed in set_serial_baud");
1863 /* Calculate the Divisor */
1866 err("%s - bad baud rate", __func__);
1867 dbg("%s", "bad baud rate");
1870 /* Enable access to divisor latch */
1871 Data = ATEN2011_port->shadowLCR | SERIAL_LCR_DLAB;
1872 ATEN2011_port->shadowLCR = Data;
1873 set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
1875 /* Write the divisor */
1876 Data = (unsigned char)(divisor & 0xff);
1877 dbg("set_serial_baud Value to write DLL is %x", Data);
1878 set_uart_reg(port, DIVISOR_LATCH_LSB, Data);
1880 Data = (unsigned char)((divisor & 0xff00) >> 8);
1881 dbg("set_serial_baud Value to write DLM is %x", Data);
1882 set_uart_reg(port, DIVISOR_LATCH_MSB, Data);
1884 /* Disable access to divisor latch */
1885 Data = ATEN2011_port->shadowLCR & ~SERIAL_LCR_DLAB;
1886 ATEN2011_port->shadowLCR = Data;
1887 set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
1894 static void ATEN2011_change_port_settings(struct tty_struct *tty,
1895 struct ATENINTL_port *ATEN2011_port,
1896 struct ktermios *old_termios)
1906 struct usb_serial_port *port;
1907 struct usb_serial *serial;
1909 if (ATEN2011_port == NULL)
1912 port = (struct usb_serial_port *)ATEN2011_port->port;
1914 serial = port->serial;
1916 dbg("%s - port %d", __func__, ATEN2011_port->port->number);
1918 if (!ATEN2011_port->open) {
1919 dbg("%s - port not opened", __func__);
1923 if ((!tty) || (!tty->termios)) {
1924 dbg("%s - no tty structures", __func__);
1928 dbg("%s", "Entering .......... ");
1932 lParity = LCR_PAR_NONE;
1934 cflag = tty->termios->c_cflag;
1935 iflag = tty->termios->c_iflag;
1937 /* Change the number of bits */
1939 /* 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 */
1940 /* if(cflag & CSIZE) */
1942 switch (cflag & CSIZE) {
1960 /* Change the Parity bit */
1961 if (cflag & PARENB) {
1962 if (cflag & PARODD) {
1963 lParity = LCR_PAR_ODD;
1964 dbg("%s - parity = odd", __func__);
1966 lParity = LCR_PAR_EVEN;
1967 dbg("%s - parity = even", __func__);
1971 dbg("%s - parity = none", __func__);
1975 lParity = lParity | 0x20;
1977 /* Change the Stop bit */
1978 if (cflag & CSTOPB) {
1980 dbg("%s - stop bits = 2", __func__);
1983 dbg("%s - stop bits = 1", __func__);
1986 /* Update the LCR with the correct value */
1987 ATEN2011_port->shadowLCR &=
1988 ~(LCR_BITS_MASK | LCR_STOP_MASK | LCR_PAR_MASK);
1989 ATEN2011_port->shadowLCR |= (lData | lParity | lStop);
1992 ("ATEN2011_change_port_settings ATEN2011_port->shadowLCR is %x",
1993 ATEN2011_port->shadowLCR);
1994 /* Disable Interrupts */
1996 set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data);
1999 set_uart_reg(port, FIFO_CONTROL_REGISTER, Data);
2002 set_uart_reg(port, FIFO_CONTROL_REGISTER, Data);
2004 /* Send the updated LCR value to the ATEN2011 */
2005 Data = ATEN2011_port->shadowLCR;
2007 set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
2010 ATEN2011_port->shadowMCR = Data;
2011 set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
2013 set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
2015 /* set up the MCR register and send it to the ATEN2011 */
2017 ATEN2011_port->shadowMCR = MCR_MASTER_IE;
2019 ATEN2011_port->shadowMCR |= (MCR_DTR | MCR_RTS);
2021 if (cflag & CRTSCTS)
2022 ATEN2011_port->shadowMCR |= (MCR_XON_ANY);
2024 ATEN2011_port->shadowMCR &= ~(MCR_XON_ANY);
2026 Data = ATEN2011_port->shadowMCR;
2027 set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
2029 /* Determine divisor based on baud rate */
2030 baud = tty_get_baud_rate(tty);
2033 /* pick a default, any default... */
2034 dbg("%s", "Picked default baud...");
2038 dbg("%s - baud rate = %d", __func__, baud);
2039 status = ATEN2011_send_cmd_write_baud_rate(ATEN2011_port, baud);
2041 /* Enable Interrupts */
2043 set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data);
2045 if (ATEN2011_port->read_urb->status != -EINPROGRESS) {
2046 ATEN2011_port->read_urb->dev = serial->dev;
2048 status = usb_submit_urb(ATEN2011_port->read_urb, GFP_ATOMIC);
2052 (" usb_submit_urb(read bulk) failed, status = %d",
2057 ("ATEN2011_change_port_settings ATEN2011_port->shadowLCR is End %x",
2058 ATEN2011_port->shadowLCR);
2063 static int ATEN2011_calc_num_ports(struct usb_serial *serial)
2068 int ATEN2011_2or4ports;
2069 ret = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
2070 ATEN_RDREQ, ATEN_RD_RTYPE, 0, GPIO_REGISTER,
2071 &Data, VENDOR_READ_LENGTH, ATEN_WDR_TIMEOUT);
2073 /* ghostgum: here is where the problem appears to bet */
2074 /* Which of the following are needed? */
2075 /* Greg used the serial->type->num_ports=2 */
2076 /* But the code in the ATEN2011_open relies on serial->num_ports=2 */
2077 if ((Data & 0x01) == 0) {
2078 ATEN2011_2or4ports = 2;
2079 serial->type->num_ports = 2;
2080 serial->num_ports = 2;
2082 /* else if(serial->interface->cur_altsetting->desc.bNumEndpoints == 9) */
2084 ATEN2011_2or4ports = 4;
2085 serial->type->num_ports = 4;
2086 serial->num_ports = 4;
2090 return ATEN2011_2or4ports;
2093 static int ATEN2011_startup(struct usb_serial *serial)
2095 struct ATENINTL_serial *ATEN2011_serial;
2096 struct ATENINTL_port *ATEN2011_port;
2097 struct usb_device *dev;
2102 dbg("%s", " ATEN2011_startup :entering..........");
2105 dbg("%s", "Invalid Handler");
2111 dbg("%s", "Entering...");
2113 /* create our private serial structure */
2114 ATEN2011_serial = kzalloc(sizeof(struct ATENINTL_serial), GFP_KERNEL);
2115 if (ATEN2011_serial == NULL) {
2116 err("%s - Out of memory", __func__);
2120 /* resetting the private structure field values to zero */
2121 memset(ATEN2011_serial, 0, sizeof(struct ATENINTL_serial));
2123 ATEN2011_serial->serial = serial;
2124 /* initilize status polling flag to 0 */
2125 ATEN2011_serial->status_polling_started = 0;
2127 usb_set_serial_data(serial, ATEN2011_serial);
2128 ATEN2011_serial->ATEN2011_spectrum_2or4ports =
2129 ATEN2011_calc_num_ports(serial);
2130 /* we set up the pointers to the endpoints in the ATEN2011_open *
2131 * function, as the structures aren't created yet. */
2133 /* set up port private structures */
2134 for (i = 0; i < serial->num_ports; ++i) {
2136 kmalloc(sizeof(struct ATENINTL_port), GFP_KERNEL);
2137 if (ATEN2011_port == NULL) {
2138 err("%s - Out of memory", __func__);
2139 usb_set_serial_data(serial, NULL);
2140 kfree(ATEN2011_serial);
2143 memset(ATEN2011_port, 0, sizeof(struct ATENINTL_port));
2146 * Initialize all port interrupt end point to port 0
2147 * int endpoint. Our device has only one interrupt end point
2148 * comman to all port
2150 /* serial->port[i]->interrupt_in_endpointAddress = serial->port[0]->interrupt_in_endpointAddress; */
2152 ATEN2011_port->port = serial->port[i];
2153 usb_set_serial_port_data(serial->port[i], ATEN2011_port);
2155 minor = serial->port[i]->serial->minor;
2156 if (minor == SERIAL_TTY_NO_MINOR)
2158 ATEN2011_port->port_num =
2159 ((serial->port[i]->number - minor) + 1);
2161 if (ATEN2011_port->port_num == 1) {
2162 ATEN2011_port->SpRegOffset = 0x0;
2163 ATEN2011_port->ControlRegOffset = 0x1;
2164 ATEN2011_port->DcrRegOffset = 0x4;
2165 } else if ((ATEN2011_port->port_num == 2)
2166 && (ATEN2011_serial->ATEN2011_spectrum_2or4ports ==
2168 ATEN2011_port->SpRegOffset = 0x8;
2169 ATEN2011_port->ControlRegOffset = 0x9;
2170 ATEN2011_port->DcrRegOffset = 0x16;
2171 } else if ((ATEN2011_port->port_num == 2)
2172 && (ATEN2011_serial->ATEN2011_spectrum_2or4ports ==
2174 ATEN2011_port->SpRegOffset = 0xa;
2175 ATEN2011_port->ControlRegOffset = 0xb;
2176 ATEN2011_port->DcrRegOffset = 0x19;
2177 } else if ((ATEN2011_port->port_num == 3)
2178 && (ATEN2011_serial->ATEN2011_spectrum_2or4ports ==
2180 ATEN2011_port->SpRegOffset = 0xa;
2181 ATEN2011_port->ControlRegOffset = 0xb;
2182 ATEN2011_port->DcrRegOffset = 0x19;
2183 } else if ((ATEN2011_port->port_num == 4)
2184 && (ATEN2011_serial->ATEN2011_spectrum_2or4ports ==
2186 ATEN2011_port->SpRegOffset = 0xc;
2187 ATEN2011_port->ControlRegOffset = 0xd;
2188 ATEN2011_port->DcrRegOffset = 0x1c;
2191 usb_set_serial_port_data(serial->port[i], ATEN2011_port);
2193 /* enable rx_disable bit in control register */
2195 status = get_reg_sync(serial->port[i],
2196 ATEN2011_port->ControlRegOffset, &Data);
2198 dbg("Reading ControlReg failed status-0x%x",
2203 ("ControlReg Reading success val is %x, status%d",
2205 Data |= 0x08; /* setting driver done bit */
2206 Data |= 0x04; /* sp1_bit to have cts change reflect in modem status reg */
2208 /* Data |= 0x20; */ /* rx_disable bit */
2209 status = set_reg_sync(serial->port[i],
2210 ATEN2011_port->ControlRegOffset, Data);
2213 ("Writing ControlReg failed(rx_disable) status-0x%x",
2218 ("ControlReg Writing success(rx_disable) status%d",
2222 * Write default values in DCR (i.e 0x01 in DCR0, 0x05 in DCR2
2226 status = set_reg_sync(serial->port[i],
2227 (__u16)(ATEN2011_port->DcrRegOffset + 0),
2230 dbg("Writing DCR0 failed status-0x%x", status);
2233 dbg("DCR0 Writing success status%d", status);
2236 status = set_reg_sync(serial->port[i],
2237 (__u16)(ATEN2011_port->DcrRegOffset + 1),
2240 dbg("Writing DCR1 failed status-0x%x", status);
2243 dbg("DCR1 Writing success status%d", status);
2246 status = set_reg_sync(serial->port[i],
2247 (__u16)(ATEN2011_port->DcrRegOffset + 2),
2250 dbg("Writing DCR2 failed status-0x%x", status);
2253 dbg("DCR2 Writing success status%d", status);
2255 /* write values in clkstart0x0 and clkmulti 0x20 */
2257 status = set_reg_sync(serial->port[i], CLK_START_VALUE_REGISTER,
2261 ("Writing CLK_START_VALUE_REGISTER failed status-0x%x",
2266 ("CLK_START_VALUE_REGISTER Writing success status%d",
2270 status = set_reg_sync(serial->port[i], CLK_MULTI_REGISTER,
2274 ("Writing CLK_MULTI_REGISTER failed status-0x%x",
2278 dbg("CLK_MULTI_REGISTER Writing success status%d",
2281 /* Zero Length flag register */
2282 if ((ATEN2011_port->port_num != 1)
2283 && (ATEN2011_serial->ATEN2011_spectrum_2or4ports == 2)) {
2286 status = set_reg_sync(serial->port[i],
2287 (__u16)(ZLP_REG1 + ((__u16)ATEN2011_port->port_num)),
2289 dbg("ZLIP offset%x",
2291 ((__u16) ATEN2011_port->port_num)));
2294 ("Writing ZLP_REG%d failed status-0x%x",
2298 dbg("ZLP_REG%d Writing success status%d",
2302 status = set_reg_sync(serial->port[i],
2303 (__u16)(ZLP_REG1 + ((__u16)ATEN2011_port->port_num) - 0x1),
2305 dbg("ZLIP offset%x",
2307 ((__u16) ATEN2011_port->port_num) -
2311 ("Writing ZLP_REG%d failed status-0x%x",
2315 dbg("ZLP_REG%d Writing success status%d",
2319 ATEN2011_port->control_urb = usb_alloc_urb(0, GFP_ATOMIC);
2320 ATEN2011_port->ctrl_buf = kmalloc(16, GFP_KERNEL);
2324 /* Zero Length flag enable */
2326 status = set_reg_sync(serial->port[0], ZLP_REG5, Data);
2328 dbg("Writing ZLP_REG5 failed status-0x%x", status);
2331 dbg("ZLP_REG5 Writing success status%d", status);
2333 /* setting configuration feature to one */
2334 usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
2335 (__u8) 0x03, 0x00, 0x01, 0x00, NULL, 0x00, 5 * HZ);
2339 static void ATEN2011_shutdown(struct usb_serial *serial)
2342 struct ATENINTL_port *ATEN2011_port;
2344 /* check for the ports to be closed,close the ports and disconnect */
2346 /* free private structure allocated for serial port *
2347 * stop reads and writes on all ports */
2349 for (i = 0; i < serial->num_ports; ++i) {
2350 ATEN2011_port = usb_get_serial_port_data(serial->port[i]);
2351 kfree(ATEN2011_port->ctrl_buf);
2352 usb_kill_urb(ATEN2011_port->control_urb);
2353 kfree(ATEN2011_port);
2354 usb_set_serial_port_data(serial->port[i], NULL);
2357 /* free private structure allocated for serial device */
2359 kfree(usb_get_serial_data(serial));
2360 usb_set_serial_data(serial, NULL);
2363 static struct usb_serial_driver aten_serial_driver = {
2365 .owner = THIS_MODULE,
2368 .description = DRIVER_DESC,
2369 .id_table = id_table,
2370 .open = ATEN2011_open,
2371 .close = ATEN2011_close,
2372 .write = ATEN2011_write,
2373 .write_room = ATEN2011_write_room,
2374 .chars_in_buffer = ATEN2011_chars_in_buffer,
2375 .throttle = ATEN2011_throttle,
2376 .unthrottle = ATEN2011_unthrottle,
2377 .calc_num_ports = ATEN2011_calc_num_ports,
2379 .ioctl = ATEN2011_ioctl,
2380 .set_termios = ATEN2011_set_termios,
2381 .break_ctl = ATEN2011_break,
2382 .tiocmget = ATEN2011_tiocmget,
2383 .tiocmset = ATEN2011_tiocmset,
2384 .attach = ATEN2011_startup,
2385 .shutdown = ATEN2011_shutdown,
2386 .read_bulk_callback = ATEN2011_bulk_in_callback,
2387 .read_int_callback = ATEN2011_interrupt_callback,
2390 static struct usb_driver aten_driver = {
2392 .probe = usb_serial_probe,
2393 .disconnect = usb_serial_disconnect,
2394 .id_table = id_table,
2397 static int __init aten_init(void)
2401 /* Register with the usb serial */
2402 retval = usb_serial_register(&aten_serial_driver);
2406 printk(KERN_INFO KBUILD_MODNAME ":"
2407 DRIVER_DESC " " DRIVER_VERSION "\n");
2409 /* Register with the usb */
2410 retval = usb_register(&aten_driver);
2412 usb_serial_deregister(&aten_serial_driver);
2417 static void __exit aten_exit(void)
2419 usb_deregister(&aten_driver);
2420 usb_serial_deregister(&aten_serial_driver);
2423 module_init(aten_init);
2424 module_exit(aten_exit);
2426 /* Module information */
2427 MODULE_DESCRIPTION(DRIVER_DESC);
2428 MODULE_LICENSE("GPL");
2430 MODULE_PARM_DESC(debug, "Debug enabled or not");