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 */
608 wake_up_interruptible(&tty->write_wait);
611 /* schedule_work(&ATEN2011_port->port->work); */
616 #ifdef ATENSerialProbe
617 static int ATEN2011_serial_probe(struct usb_serial *serial,
618 const struct usb_device_id *id)
621 /*need to implement the mode_reg reading and updating\
622 structures usb_serial_ device_type\
623 (i.e num_ports, num_bulkin,bulkout etc) */
624 /* Also we can update the changes attach */
629 static int ATEN2011_open(struct tty_struct *tty, struct usb_serial_port *port,
634 struct usb_serial *serial;
638 struct ATENINTL_serial *ATEN2011_serial;
639 struct ATENINTL_port *ATEN2011_port;
640 struct ktermios tmp_termios;
643 serial = port->serial;
645 ATEN2011_port = usb_get_serial_port_data(port);
647 if (ATEN2011_port == NULL)
650 ATEN2011_serial = usb_get_serial_data(serial);
651 if (ATEN2011_serial == NULL)
654 /* increment the number of opened ports counter here */
655 ATEN2011_serial->NoOfOpenPorts++;
657 usb_clear_halt(serial->dev, port->write_urb->pipe);
658 usb_clear_halt(serial->dev, port->read_urb->pipe);
660 /* Initialising the write urb pool */
661 for (j = 0; j < NUM_URBS; ++j) {
662 urb = usb_alloc_urb(0, GFP_ATOMIC);
663 ATEN2011_port->write_urb_pool[j] = urb;
666 err("No more urbs???");
670 urb->transfer_buffer = NULL;
671 urb->transfer_buffer =
672 kmalloc(URB_TRANSFER_BUFFER_SIZE, GFP_KERNEL);
673 if (!urb->transfer_buffer) {
674 err("%s-out of memory for urb buffers.", __func__);
679 /*****************************************************************************
680 * Initialize ATEN2011 -- Write Init values to corresponding Registers
688 * 0x08 : SP1/2 Control Reg
689 *****************************************************************************/
691 /* NEED to check the fallowing Block */
694 status = get_reg_sync(port, ATEN2011_port->SpRegOffset, &Data);
696 dbg("Reading Spreg failed");
700 status = set_reg_sync(port, ATEN2011_port->SpRegOffset, Data);
702 dbg("writing Spreg failed");
707 status = set_reg_sync(port, ATEN2011_port->SpRegOffset, Data);
709 dbg("writing Spreg failed");
713 /* End of block to be checked */
714 /**************************CHECK***************************/
720 status = set_uart_reg(port, SCRATCH_PAD_REGISTER, Data);
722 dbg("Writing SCRATCH_PAD_REGISTER failed status-0x%x", status);
725 dbg("SCRATCH_PAD_REGISTER Writing success status%d", status);
727 /**************************CHECK***************************/
730 status = get_reg_sync(port, ATEN2011_port->ControlRegOffset, &Data);
732 dbg("Reading Controlreg failed");
735 Data |= 0x08; /* Driver done bit */
736 Data |= 0x20; /* rx_disable */
739 set_reg_sync(port, ATEN2011_port->ControlRegOffset, Data);
741 dbg("writing Controlreg failed");
745 * do register settings here
746 * Set all regs to the device default values.
747 * First Disable all interrupts.
751 status = set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data);
753 dbg("disableing interrupts failed");
756 /* Set FIFO_CONTROL_REGISTER to the default value */
758 status = set_uart_reg(port, FIFO_CONTROL_REGISTER, Data);
760 dbg("Writing FIFO_CONTROL_REGISTER failed");
764 Data = 0xcf; /* chk */
765 status = set_uart_reg(port, FIFO_CONTROL_REGISTER, Data);
767 dbg("Writing FIFO_CONTROL_REGISTER failed");
771 Data = 0x03; /* LCR_BITS_8 */
772 status = set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
773 ATEN2011_port->shadowLCR = Data;
775 Data = 0x0b; /* MCR_DTR|MCR_RTS|MCR_MASTER_IE */
776 status = set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
777 ATEN2011_port->shadowMCR = Data;
781 status = get_uart_reg(port, LINE_CONTROL_REGISTER, &Data);
782 ATEN2011_port->shadowLCR = Data;
784 Data |= SERIAL_LCR_DLAB; /* data latch enable in LCR 0x80 */
785 status = set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
788 status = set_uart_reg(port, DIVISOR_LATCH_LSB, Data);
791 status = set_uart_reg(port, DIVISOR_LATCH_MSB, Data);
794 status = get_uart_reg(port, LINE_CONTROL_REGISTER, &Data);
796 /* Data = ATEN2011_port->shadowLCR; */ /* data latch disable */
797 Data = Data & ~SERIAL_LCR_DLAB;
798 status = set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
799 ATEN2011_port->shadowLCR = Data;
801 /* clearing Bulkin and Bulkout Fifo */
803 status = get_reg_sync(port, ATEN2011_port->SpRegOffset, &Data);
806 status = set_reg_sync(port, ATEN2011_port->SpRegOffset, Data);
809 status = set_reg_sync(port, ATEN2011_port->SpRegOffset, Data);
810 /* Finally enable all interrupts */
813 status = set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data);
815 /* clearing rx_disable */
817 status = get_reg_sync(port, ATEN2011_port->ControlRegOffset, &Data);
819 status = set_reg_sync(port, ATEN2011_port->ControlRegOffset, Data);
823 status = get_reg_sync(port, ATEN2011_port->ControlRegOffset, &Data);
826 status = set_reg_sync(port, ATEN2011_port->ControlRegOffset, Data);
828 /* force low_latency on so that our tty_push actually forces *
829 * the data through,otherwise it is scheduled, and with *
830 * high data rates (like with OHCI) data can get lost. */
833 tty->low_latency = 1;
835 * Check to see if we've set up our endpoint info yet
836 * (can't set it up in ATEN2011_startup as the structures
837 * were not set up at that time.)
839 if (ATEN2011_serial->NoOfOpenPorts == 1) {
840 /* start the status polling here */
841 ATEN2011_serial->status_polling_started = 1;
842 /* If not yet set, Set here */
843 ATEN2011_serial->interrupt_in_buffer =
844 serial->port[0]->interrupt_in_buffer;
845 ATEN2011_serial->interrupt_in_endpoint =
846 serial->port[0]->interrupt_in_endpointAddress;
847 ATEN2011_serial->interrupt_read_urb =
848 serial->port[0]->interrupt_in_urb;
850 /* set up interrupt urb */
851 usb_fill_int_urb(ATEN2011_serial->interrupt_read_urb,
853 usb_rcvintpipe(serial->dev,
855 interrupt_in_endpoint),
856 ATEN2011_serial->interrupt_in_buffer,
857 ATEN2011_serial->interrupt_read_urb->
858 transfer_buffer_length,
859 ATEN2011_interrupt_callback, ATEN2011_serial,
860 ATEN2011_serial->interrupt_read_urb->interval);
862 /* start interrupt read for ATEN2011 *
863 * will continue as long as ATEN2011 is connected */
866 usb_submit_urb(ATEN2011_serial->interrupt_read_urb,
869 dbg("%s - Error %d submitting interrupt urb",
876 * See if we've set up our endpoint info yet
877 * (can't set it up in ATEN2011_startup as the
878 * structures were not set up at that time.)
881 dbg("port number is %d", port->number);
882 dbg("serial number is %d", port->serial->minor);
883 dbg("Bulkin endpoint is %d", port->bulk_in_endpointAddress);
884 dbg("BulkOut endpoint is %d", port->bulk_out_endpointAddress);
885 dbg("Interrupt endpoint is %d",
886 port->interrupt_in_endpointAddress);
887 dbg("port's number in the device is %d", ATEN2011_port->port_num);
888 ATEN2011_port->bulk_in_buffer = port->bulk_in_buffer;
889 ATEN2011_port->bulk_in_endpoint = port->bulk_in_endpointAddress;
890 ATEN2011_port->read_urb = port->read_urb;
891 ATEN2011_port->bulk_out_endpoint = port->bulk_out_endpointAddress;
893 minor = port->serial->minor;
894 if (minor == SERIAL_TTY_NO_MINOR)
897 /* set up our bulk in urb */
898 if ((ATEN2011_serial->ATEN2011_spectrum_2or4ports == 2)
899 && (((__u16) port->number - (__u16) (minor)) != 0)) {
900 usb_fill_bulk_urb(ATEN2011_port->read_urb, serial->dev,
901 usb_rcvbulkpipe(serial->dev,
903 bulk_in_endpointAddress +
904 2)), port->bulk_in_buffer,
905 ATEN2011_port->read_urb->
906 transfer_buffer_length,
907 ATEN2011_bulk_in_callback, ATEN2011_port);
909 usb_fill_bulk_urb(ATEN2011_port->read_urb,
911 usb_rcvbulkpipe(serial->dev,
913 bulk_in_endpointAddress),
914 port->bulk_in_buffer,
915 ATEN2011_port->read_urb->
916 transfer_buffer_length,
917 ATEN2011_bulk_in_callback, ATEN2011_port);
919 dbg("ATEN2011_open: bulkin endpoint is %d",
920 port->bulk_in_endpointAddress);
921 response = usb_submit_urb(ATEN2011_port->read_urb, GFP_KERNEL);
923 err("%s - Error %d submitting control urb", __func__,
927 /* initialize our wait queues */
928 init_waitqueue_head(&ATEN2011_port->wait_chase);
929 init_waitqueue_head(&ATEN2011_port->wait_command);
931 /* initialize our icount structure */
932 memset(&(ATEN2011_port->icount), 0x00, sizeof(ATEN2011_port->icount));
934 /* initialize our port settings */
935 ATEN2011_port->shadowMCR = MCR_MASTER_IE; /* Must set to enable ints! */
936 ATEN2011_port->chaseResponsePending = 0;
937 /* send a open port command */
938 ATEN2011_port->open = 1;
939 /* ATEN2011_change_port_settings(ATEN2011_port,old_termios); */
941 ATEN2011_set_termios(tty, port, &tmp_termios);
942 ATEN2011_port->icount.tx = 0;
943 ATEN2011_port->icount.rx = 0;
945 dbg("usb_serial serial:%x ATEN2011_port:%x\nATEN2011_serial:%x usb_serial_port port:%x",
946 (unsigned int)serial, (unsigned int)ATEN2011_port,
947 (unsigned int)ATEN2011_serial, (unsigned int)port);
953 static int ATEN2011_chars_in_buffer(struct tty_struct *tty)
955 struct usb_serial_port *port = tty->driver_data;
958 struct ATENINTL_port *ATEN2011_port;
960 /* dbg("%s"," ATEN2011_chars_in_buffer:entering ..........."); */
962 ATEN2011_port = usb_get_serial_port_data(port);
963 if (ATEN2011_port == NULL) {
964 dbg("%s", "ATEN2011_break:leaving ...........");
968 for (i = 0; i < NUM_URBS; ++i)
969 if (ATEN2011_port->write_urb_pool[i]->status == -EINPROGRESS)
970 chars += URB_TRANSFER_BUFFER_SIZE;
972 dbg("%s - returns %d", __func__, chars);
977 static void ATEN2011_block_until_tx_empty(struct tty_struct *tty,
978 struct ATENINTL_port *ATEN2011_port)
980 int timeout = HZ / 10;
985 count = ATEN2011_chars_in_buffer(tty);
987 /* Check for Buffer status */
991 /* Block the thread for a while */
992 interruptible_sleep_on_timeout(&ATEN2011_port->wait_chase,
995 /* No activity.. count down section */
998 dbg("%s - TIMEOUT", __func__);
1001 /* Reset timout value back to seconds */
1007 static void ATEN2011_close(struct tty_struct *tty, struct usb_serial_port *port,
1010 struct usb_serial *serial;
1011 struct ATENINTL_serial *ATEN2011_serial;
1012 struct ATENINTL_port *ATEN2011_port;
1016 dbg("%s", "ATEN2011_close:entering...");
1017 serial = port->serial;
1019 /* take the Adpater and port's private data */
1020 ATEN2011_serial = usb_get_serial_data(serial);
1021 ATEN2011_port = usb_get_serial_port_data(port);
1022 if ((ATEN2011_serial == NULL) || (ATEN2011_port == NULL))
1026 /* flush and block(wait) until tx is empty */
1027 ATEN2011_block_until_tx_empty(tty, ATEN2011_port);
1029 /* kill the ports URB's */
1030 for (no_urbs = 0; no_urbs < NUM_URBS; no_urbs++)
1031 usb_kill_urb(ATEN2011_port->write_urb_pool[no_urbs]);
1032 /* Freeing Write URBs */
1033 for (no_urbs = 0; no_urbs < NUM_URBS; ++no_urbs) {
1034 kfree(ATEN2011_port->write_urb_pool[no_urbs]->transfer_buffer);
1035 usb_free_urb(ATEN2011_port->write_urb_pool[no_urbs]);
1037 /* While closing port, shutdown all bulk read, write *
1038 * and interrupt read if they exists */
1040 if (ATEN2011_port->write_urb) {
1041 dbg("%s", "Shutdown bulk write");
1042 usb_kill_urb(ATEN2011_port->write_urb);
1044 if (ATEN2011_port->read_urb) {
1045 dbg("%s", "Shutdown bulk read");
1046 usb_kill_urb(ATEN2011_port->read_urb);
1048 if ((&ATEN2011_port->control_urb)) {
1049 dbg("%s", "Shutdown control read");
1050 /* usb_kill_urb (ATEN2011_port->control_urb); */
1054 /* if(ATEN2011_port->ctrl_buf != NULL) */
1055 /* kfree(ATEN2011_port->ctrl_buf); */
1056 /* decrement the no.of open ports counter of an individual USB-serial adapter. */
1057 ATEN2011_serial->NoOfOpenPorts--;
1058 dbg("NoOfOpenPorts in close%d:in port%d",
1059 ATEN2011_serial->NoOfOpenPorts, port->number);
1060 if (ATEN2011_serial->NoOfOpenPorts == 0) {
1061 /* stop the stus polling here */
1062 ATEN2011_serial->status_polling_started = 0;
1063 if (ATEN2011_serial->interrupt_read_urb) {
1064 dbg("%s", "Shutdown interrupt_read_urb");
1065 /* ATEN2011_serial->interrupt_in_buffer=NULL; */
1066 /* usb_kill_urb (ATEN2011_serial->interrupt_read_urb); */
1069 if (ATEN2011_port->write_urb) {
1070 /* if this urb had a transfer buffer already (old tx) free it */
1071 kfree(ATEN2011_port->write_urb->transfer_buffer);
1072 usb_free_urb(ATEN2011_port->write_urb);
1075 /* clear the MCR & IER */
1077 set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
1079 set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data);
1081 ATEN2011_port->open = 0;
1082 dbg("%s", "Leaving ............");
1086 static void ATEN2011_block_until_chase_response(struct tty_struct *tty,
1087 struct ATENINTL_port
1090 int timeout = 1 * HZ;
1095 count = ATEN2011_chars_in_buffer(tty);
1097 /* Check for Buffer status */
1099 ATEN2011_port->chaseResponsePending = 0;
1103 /* Block the thread for a while */
1104 interruptible_sleep_on_timeout(&ATEN2011_port->wait_chase,
1106 /* No activity.. count down section */
1109 dbg("%s - TIMEOUT", __func__);
1112 /* Reset timout value back to seconds */
1119 static void ATEN2011_break(struct tty_struct *tty, int break_state)
1121 struct usb_serial_port *port = tty->driver_data;
1123 struct usb_serial *serial;
1124 struct ATENINTL_serial *ATEN2011_serial;
1125 struct ATENINTL_port *ATEN2011_port;
1127 dbg("%s", "Entering ...........");
1128 dbg("ATEN2011_break: Start");
1130 serial = port->serial;
1132 ATEN2011_serial = usb_get_serial_data(serial);
1133 ATEN2011_port = usb_get_serial_port_data(port);
1135 if ((ATEN2011_serial == NULL) || (ATEN2011_port == NULL))
1138 /* flush and chase */
1139 ATEN2011_port->chaseResponsePending = 1;
1142 /* flush and block until tx is empty */
1143 ATEN2011_block_until_chase_response(tty, ATEN2011_port);
1146 if (break_state == -1)
1147 data = ATEN2011_port->shadowLCR | LCR_SET_BREAK;
1149 data = ATEN2011_port->shadowLCR & ~LCR_SET_BREAK;
1151 ATEN2011_port->shadowLCR = data;
1152 dbg("ATEN2011_break ATEN2011_port->shadowLCR is %x",
1153 ATEN2011_port->shadowLCR);
1154 set_uart_reg(port, LINE_CONTROL_REGISTER, ATEN2011_port->shadowLCR);
1159 static int ATEN2011_write_room(struct tty_struct *tty)
1161 struct usb_serial_port *port = tty->driver_data;
1164 struct ATENINTL_port *ATEN2011_port;
1166 ATEN2011_port = usb_get_serial_port_data(port);
1167 if (ATEN2011_port == NULL) {
1168 dbg("%s", "ATEN2011_break:leaving ...........");
1172 for (i = 0; i < NUM_URBS; ++i)
1173 if (ATEN2011_port->write_urb_pool[i]->status != -EINPROGRESS)
1174 room += URB_TRANSFER_BUFFER_SIZE;
1176 dbg("%s - returns %d", __func__, room);
1181 static int ATEN2011_write(struct tty_struct *tty, struct usb_serial_port *port,
1182 const unsigned char *data, int count)
1190 struct ATENINTL_port *ATEN2011_port;
1191 struct usb_serial *serial;
1192 struct ATENINTL_serial *ATEN2011_serial;
1194 const unsigned char *current_position = data;
1195 unsigned char *data1;
1196 dbg("%s", "entering ...........");
1198 serial = port->serial;
1200 ATEN2011_port = usb_get_serial_port_data(port);
1201 if (ATEN2011_port == NULL) {
1202 dbg("%s", "ATEN2011_port is NULL");
1206 ATEN2011_serial = usb_get_serial_data(serial);
1207 if (ATEN2011_serial == NULL) {
1208 dbg("%s", "ATEN2011_serial is NULL");
1212 /* try to find a free urb in the list */
1215 for (i = 0; i < NUM_URBS; ++i) {
1216 if (ATEN2011_port->write_urb_pool[i]->status != -EINPROGRESS) {
1217 urb = ATEN2011_port->write_urb_pool[i];
1224 dbg("%s - no more free urbs", __func__);
1228 if (urb->transfer_buffer == NULL) {
1229 urb->transfer_buffer =
1230 kmalloc(URB_TRANSFER_BUFFER_SIZE, GFP_KERNEL);
1232 if (urb->transfer_buffer == NULL) {
1233 err("%s no more kernel memory...", __func__);
1237 transfer_size = min(count, URB_TRANSFER_BUFFER_SIZE);
1239 memcpy(urb->transfer_buffer, current_position, transfer_size);
1240 /* usb_serial_debug_data (__FILE__, __func__, transfer_size, urb->transfer_buffer); */
1242 /* fill urb with data and submit */
1243 minor = port->serial->minor;
1244 if (minor == SERIAL_TTY_NO_MINOR)
1246 if ((ATEN2011_serial->ATEN2011_spectrum_2or4ports == 2)
1247 && (((__u16) port->number - (__u16) (minor)) != 0)) {
1248 usb_fill_bulk_urb(urb, ATEN2011_serial->serial->dev,
1249 usb_sndbulkpipe(ATEN2011_serial->serial->dev,
1251 bulk_out_endpointAddress) +
1252 2), urb->transfer_buffer,
1254 ATEN2011_bulk_out_data_callback,
1258 usb_fill_bulk_urb(urb,
1259 ATEN2011_serial->serial->dev,
1260 usb_sndbulkpipe(ATEN2011_serial->serial->dev,
1262 bulk_out_endpointAddress),
1263 urb->transfer_buffer, transfer_size,
1264 ATEN2011_bulk_out_data_callback,
1267 data1 = urb->transfer_buffer;
1268 dbg("bulkout endpoint is %d", port->bulk_out_endpointAddress);
1269 /* for(i=0;i < urb->actual_length;i++) */
1270 /* dbg("Data is %c ",data1[i]); */
1272 /* send it down the pipe */
1273 status = usb_submit_urb(urb, GFP_ATOMIC);
1276 err("%s - usb_submit_urb(write bulk) failed with status = %d",
1278 bytes_sent = status;
1281 bytes_sent = transfer_size;
1282 ATEN2011_port->icount.tx += transfer_size;
1283 dbg("ATEN2011_port->icount.tx is %d:", ATEN2011_port->icount.tx);
1289 static void ATEN2011_throttle(struct tty_struct *tty)
1291 struct usb_serial_port *port = tty->driver_data;
1292 struct ATENINTL_port *ATEN2011_port;
1295 dbg("- port %d", port->number);
1297 ATEN2011_port = usb_get_serial_port_data(port);
1299 if (ATEN2011_port == NULL)
1302 if (!ATEN2011_port->open) {
1303 dbg("%s", "port not opened");
1307 dbg("%s", "Entering .......... ");
1310 dbg("%s - no tty available", __func__);
1314 /* if we are implementing XON/XOFF, send the stop character */
1316 unsigned char stop_char = STOP_CHAR(tty);
1317 status = ATEN2011_write(tty, port, &stop_char, 1);
1322 /* if we are implementing RTS/CTS, toggle that line */
1323 if (tty->termios->c_cflag & CRTSCTS) {
1324 ATEN2011_port->shadowMCR &= ~MCR_RTS;
1325 status = set_uart_reg(port, MODEM_CONTROL_REGISTER,
1326 ATEN2011_port->shadowMCR);
1334 static void ATEN2011_unthrottle(struct tty_struct *tty)
1336 struct usb_serial_port *port = tty->driver_data;
1338 struct ATENINTL_port *ATEN2011_port = usb_get_serial_port_data(port);
1340 if (ATEN2011_port == NULL)
1343 if (!ATEN2011_port->open) {
1344 dbg("%s - port not opened", __func__);
1348 dbg("%s", "Entering .......... ");
1351 dbg("%s - no tty available", __func__);
1355 /* if we are implementing XON/XOFF, send the start character */
1357 unsigned char start_char = START_CHAR(tty);
1358 status = ATEN2011_write(tty, port, &start_char, 1);
1363 /* if we are implementing RTS/CTS, toggle that line */
1364 if (tty->termios->c_cflag & CRTSCTS) {
1365 ATEN2011_port->shadowMCR |= MCR_RTS;
1366 status = set_uart_reg(port, MODEM_CONTROL_REGISTER,
1367 ATEN2011_port->shadowMCR);
1375 static int ATEN2011_tiocmget(struct tty_struct *tty, struct file *file)
1377 struct usb_serial_port *port = tty->driver_data;
1378 struct ATENINTL_port *ATEN2011_port;
1379 unsigned int result;
1382 /* unsigned int mcr; */
1384 ATEN2011_port = usb_get_serial_port_data(port);
1386 dbg("%s - port %d", __func__, port->number);
1388 if (ATEN2011_port == NULL)
1391 status = get_uart_reg(port, MODEM_STATUS_REGISTER, &msr);
1392 status = get_uart_reg(port, MODEM_CONTROL_REGISTER, &mcr);
1393 /* mcr = ATEN2011_port->shadowMCR; */
1394 /* COMMENT2: the Fallowing three line are commented for updating only MSR values */
1395 result = ((mcr & MCR_DTR) ? TIOCM_DTR : 0)
1396 | ((mcr & MCR_RTS) ? TIOCM_RTS : 0)
1397 | ((mcr & MCR_LOOPBACK) ? TIOCM_LOOP : 0)
1398 | ((msr & ATEN2011_MSR_CTS) ? TIOCM_CTS : 0)
1399 | ((msr & ATEN2011_MSR_CD) ? TIOCM_CAR : 0)
1400 | ((msr & ATEN2011_MSR_RI) ? TIOCM_RI : 0)
1401 | ((msr & ATEN2011_MSR_DSR) ? TIOCM_DSR : 0);
1403 dbg("%s - 0x%04X", __func__, result);
1408 static int ATEN2011_tiocmset(struct tty_struct *tty, struct file *file,
1409 unsigned int set, unsigned int clear)
1411 struct usb_serial_port *port = tty->driver_data;
1412 struct ATENINTL_port *ATEN2011_port;
1414 unsigned int status;
1416 dbg("%s - port %d", __func__, port->number);
1418 ATEN2011_port = usb_get_serial_port_data(port);
1420 if (ATEN2011_port == NULL)
1423 mcr = ATEN2011_port->shadowMCR;
1424 if (clear & TIOCM_RTS)
1426 if (clear & TIOCM_DTR)
1428 if (clear & TIOCM_LOOP)
1429 mcr &= ~MCR_LOOPBACK;
1431 if (set & TIOCM_RTS)
1433 if (set & TIOCM_DTR)
1435 if (set & TIOCM_LOOP)
1436 mcr |= MCR_LOOPBACK;
1438 ATEN2011_port->shadowMCR = mcr;
1440 status = set_uart_reg(port, MODEM_CONTROL_REGISTER, mcr);
1442 dbg("setting MODEM_CONTROL_REGISTER Failed");
1449 static void ATEN2011_set_termios(struct tty_struct *tty,
1450 struct usb_serial_port *port,
1451 struct ktermios *old_termios)
1455 struct usb_serial *serial;
1456 struct ATENINTL_port *ATEN2011_port;
1458 dbg("ATEN2011_set_termios: START");
1460 serial = port->serial;
1462 ATEN2011_port = usb_get_serial_port_data(port);
1464 if (ATEN2011_port == NULL)
1467 if (!ATEN2011_port->open) {
1468 dbg("%s - port not opened", __func__);
1472 dbg("%s", "setting termios - ");
1474 cflag = tty->termios->c_cflag;
1477 dbg("%s %s", __func__, "cflag is NULL");
1481 /* check that they really want us to change something */
1483 if ((cflag == old_termios->c_cflag) &&
1484 (RELEVANT_IFLAG(tty->termios->c_iflag) ==
1485 RELEVANT_IFLAG(old_termios->c_iflag))) {
1486 dbg("%s", "Nothing to change");
1491 dbg("%s - clfag %08x iflag %08x", __func__,
1492 tty->termios->c_cflag, RELEVANT_IFLAG(tty->termios->c_iflag));
1495 dbg("%s - old clfag %08x old iflag %08x", __func__,
1496 old_termios->c_cflag, RELEVANT_IFLAG(old_termios->c_iflag));
1499 dbg("%s - port %d", __func__, port->number);
1501 /* change the port settings to the new ones specified */
1503 ATEN2011_change_port_settings(tty, ATEN2011_port, old_termios);
1505 if (!ATEN2011_port->read_urb) {
1506 dbg("%s", "URB KILLED !!!!!");
1510 if (ATEN2011_port->read_urb->status != -EINPROGRESS) {
1511 ATEN2011_port->read_urb->dev = serial->dev;
1512 status = usb_submit_urb(ATEN2011_port->read_urb, GFP_ATOMIC);
1515 (" usb_submit_urb(read bulk) failed, status = %d",
1522 static int get_lsr_info(struct tty_struct *tty,
1523 struct ATENINTL_port *ATEN2011_port,
1524 unsigned int __user *value)
1527 unsigned int result = 0;
1529 count = ATEN2011_chars_in_buffer(tty);
1531 dbg("%s -- Empty", __func__);
1532 result = TIOCSER_TEMT;
1535 if (copy_to_user(value, &result, sizeof(int)))
1540 static int get_number_bytes_avail(struct tty_struct *tty,
1541 struct ATENINTL_port *ATEN2011_port,
1542 unsigned int __user *value)
1544 unsigned int result = 0;
1547 return -ENOIOCTLCMD;
1549 result = tty->read_cnt;
1551 dbg("%s(%d) = %d", __func__, ATEN2011_port->port->number, result);
1552 if (copy_to_user(value, &result, sizeof(int)))
1555 return -ENOIOCTLCMD;
1558 static int set_modem_info(struct ATENINTL_port *ATEN2011_port, unsigned int cmd,
1559 unsigned int __user *value)
1565 struct usb_serial_port *port;
1567 if (ATEN2011_port == NULL)
1570 port = (struct usb_serial_port *)ATEN2011_port->port;
1572 mcr = ATEN2011_port->shadowMCR;
1574 if (copy_from_user(&arg, value, sizeof(int)))
1579 if (arg & TIOCM_RTS)
1581 if (arg & TIOCM_DTR)
1583 if (arg & TIOCM_LOOP)
1584 mcr |= MCR_LOOPBACK;
1588 if (arg & TIOCM_RTS)
1590 if (arg & TIOCM_DTR)
1592 if (arg & TIOCM_LOOP)
1593 mcr &= ~MCR_LOOPBACK;
1597 /* turn off the RTS and DTR and LOOPBACK
1598 * and then only turn on what was asked to */
1599 mcr &= ~(MCR_RTS | MCR_DTR | MCR_LOOPBACK);
1600 mcr |= ((arg & TIOCM_RTS) ? MCR_RTS : 0);
1601 mcr |= ((arg & TIOCM_DTR) ? MCR_DTR : 0);
1602 mcr |= ((arg & TIOCM_LOOP) ? MCR_LOOPBACK : 0);
1606 ATEN2011_port->shadowMCR = mcr;
1608 Data = ATEN2011_port->shadowMCR;
1609 status = set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
1611 dbg("setting MODEM_CONTROL_REGISTER Failed");
1618 static int get_modem_info(struct ATENINTL_port *ATEN2011_port,
1619 unsigned int __user *value)
1621 unsigned int result = 0;
1623 unsigned int mcr = ATEN2011_port->shadowMCR;
1626 status = get_uart_reg(ATEN2011_port->port, MODEM_STATUS_REGISTER, &msr);
1627 result = ((mcr & MCR_DTR) ? TIOCM_DTR : 0) /* 0x002 */
1628 |((mcr & MCR_RTS) ? TIOCM_RTS : 0) /* 0x004 */
1629 |((msr & ATEN2011_MSR_CTS) ? TIOCM_CTS : 0) /* 0x020 */
1630 |((msr & ATEN2011_MSR_CD) ? TIOCM_CAR : 0) /* 0x040 */
1631 |((msr & ATEN2011_MSR_RI) ? TIOCM_RI : 0) /* 0x080 */
1632 |((msr & ATEN2011_MSR_DSR) ? TIOCM_DSR : 0); /* 0x100 */
1634 dbg("%s -- %x", __func__, result);
1636 if (copy_to_user(value, &result, sizeof(int)))
1641 static int get_serial_info(struct ATENINTL_port *ATEN2011_port,
1642 struct serial_struct __user *retinfo)
1644 struct serial_struct tmp;
1646 if (ATEN2011_port == NULL)
1652 memset(&tmp, 0, sizeof(tmp));
1654 tmp.type = PORT_16550A;
1655 tmp.line = ATEN2011_port->port->serial->minor;
1656 if (tmp.line == SERIAL_TTY_NO_MINOR)
1658 tmp.port = ATEN2011_port->port->number;
1660 tmp.flags = ASYNC_SKIP_TEST | ASYNC_AUTO_IRQ;
1661 tmp.xmit_fifo_size = NUM_URBS * URB_TRANSFER_BUFFER_SIZE;
1662 tmp.baud_base = 9600;
1663 tmp.close_delay = 5 * HZ;
1664 tmp.closing_wait = 30 * HZ;
1666 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
1671 static int ATEN2011_ioctl(struct tty_struct *tty, struct file *file,
1672 unsigned int cmd, unsigned long arg)
1674 struct usb_serial_port *port = tty->driver_data;
1675 struct ATENINTL_port *ATEN2011_port;
1676 struct async_icount cnow;
1677 struct async_icount cprev;
1678 struct serial_icounter_struct icount;
1680 unsigned int __user *user_arg = (unsigned int __user *)arg;
1682 ATEN2011_port = usb_get_serial_port_data(port);
1684 if (ATEN2011_port == NULL)
1687 dbg("%s - port %d, cmd = 0x%x", __func__, port->number, cmd);
1690 /* return number of bytes available */
1693 dbg("%s (%d) TIOCINQ", __func__, port->number);
1694 return get_number_bytes_avail(tty, ATEN2011_port, user_arg);
1698 dbg("%s (%d) TIOCOUTQ", __func__, port->number);
1699 return put_user(ATEN2011_chars_in_buffer(tty), user_arg);
1703 dbg("%s (%d) TIOCSERGETLSR", __func__, port->number);
1704 return get_lsr_info(tty, ATEN2011_port, user_arg);
1710 dbg("%s (%d) TIOCMSET/TIOCMBIC/TIOCMSET", __func__,
1712 ATENret = set_modem_info(ATEN2011_port, cmd, user_arg);
1716 dbg("%s (%d) TIOCMGET", __func__, port->number);
1717 return get_modem_info(ATEN2011_port, user_arg);
1720 dbg("%s (%d) TIOCGSERIAL", __func__, port->number);
1721 return get_serial_info(ATEN2011_port,
1722 (struct serial_struct __user *)arg);
1725 dbg("%s (%d) TIOCSSERIAL", __func__, port->number);
1729 dbg("%s (%d) TIOCMIWAIT", __func__, port->number);
1730 cprev = ATEN2011_port->icount;
1732 /* see if a signal did it */
1733 if (signal_pending(current))
1734 return -ERESTARTSYS;
1735 cnow = ATEN2011_port->icount;
1736 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
1737 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts)
1738 return -EIO; /* no change => error */
1739 if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
1740 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
1741 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
1742 ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts))) {
1751 cnow = ATEN2011_port->icount;
1752 icount.cts = cnow.cts;
1753 icount.dsr = cnow.dsr;
1754 icount.rng = cnow.rng;
1755 icount.dcd = cnow.dcd;
1756 icount.rx = cnow.rx;
1757 icount.tx = cnow.tx;
1758 icount.frame = cnow.frame;
1759 icount.overrun = cnow.overrun;
1760 icount.parity = cnow.parity;
1761 icount.brk = cnow.brk;
1762 icount.buf_overrun = cnow.buf_overrun;
1764 dbg("%s (%d) TIOCGICOUNT RX=%d, TX=%d", __func__,
1765 port->number, icount.rx, icount.tx);
1766 if (copy_to_user((void __user *)arg, &icount, sizeof(icount)))
1774 return -ENOIOCTLCMD;
1777 static int ATEN2011_calc_baud_rate_divisor(int baudRate, int *divisor,
1780 dbg("%s - %d", __func__, baudRate);
1782 if (baudRate <= 115200) {
1783 *divisor = 115200 / baudRate;
1786 if ((baudRate > 115200) && (baudRate <= 230400)) {
1787 *divisor = 230400 / baudRate;
1788 *clk_sel_val = 0x10;
1789 } else if ((baudRate > 230400) && (baudRate <= 403200)) {
1790 *divisor = 403200 / baudRate;
1791 *clk_sel_val = 0x20;
1792 } else if ((baudRate > 403200) && (baudRate <= 460800)) {
1793 *divisor = 460800 / baudRate;
1794 *clk_sel_val = 0x30;
1795 } else if ((baudRate > 460800) && (baudRate <= 806400)) {
1796 *divisor = 806400 / baudRate;
1797 *clk_sel_val = 0x40;
1798 } else if ((baudRate > 806400) && (baudRate <= 921600)) {
1799 *divisor = 921600 / baudRate;
1800 *clk_sel_val = 0x50;
1801 } else if ((baudRate > 921600) && (baudRate <= 1572864)) {
1802 *divisor = 1572864 / baudRate;
1803 *clk_sel_val = 0x60;
1804 } else if ((baudRate > 1572864) && (baudRate <= 3145728)) {
1805 *divisor = 3145728 / baudRate;
1806 *clk_sel_val = 0x70;
1811 static int ATEN2011_send_cmd_write_baud_rate(struct ATENINTL_port
1812 *ATEN2011_port, int baudRate)
1817 unsigned char number;
1819 struct usb_serial_port *port;
1822 if (ATEN2011_port == NULL)
1825 port = (struct usb_serial_port *)ATEN2011_port->port;
1827 dbg("%s", "Entering .......... ");
1829 minor = ATEN2011_port->port->serial->minor;
1830 if (minor == SERIAL_TTY_NO_MINOR)
1832 number = ATEN2011_port->port->number - minor;
1834 dbg("%s - port = %d, baud = %d", __func__,
1835 ATEN2011_port->port->number, baudRate);
1836 /* reset clk_uart_sel in spregOffset */
1837 if (baudRate > 115200) {
1838 #ifdef HW_flow_control
1840 * NOTE: need to see the pther register to modify
1841 * setting h/w flow control bit to 1;
1843 /* Data = ATEN2011_port->shadowMCR; */
1845 ATEN2011_port->shadowMCR = Data;
1846 status = set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
1848 dbg("Writing spreg failed in set_serial_baud");
1854 #ifdef HW_flow_control
1855 /* setting h/w flow control bit to 0; */
1856 /* Data = ATEN2011_port->shadowMCR; */
1858 ATEN2011_port->shadowMCR = Data;
1859 status = set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
1861 dbg("Writing spreg failed in set_serial_baud");
1868 if (1) /* baudRate <= 115200) */ {
1872 ATEN2011_calc_baud_rate_divisor(baudRate, &divisor,
1874 status = get_reg_sync(port, ATEN2011_port->SpRegOffset, &Data);
1876 dbg("reading spreg failed in set_serial_baud");
1879 Data = (Data & 0x8f) | clk_sel_val;
1880 status = set_reg_sync(port, ATEN2011_port->SpRegOffset, Data);
1882 dbg("Writing spreg failed in set_serial_baud");
1885 /* Calculate the Divisor */
1888 err("%s - bad baud rate", __func__);
1889 dbg("%s", "bad baud rate");
1892 /* Enable access to divisor latch */
1893 Data = ATEN2011_port->shadowLCR | SERIAL_LCR_DLAB;
1894 ATEN2011_port->shadowLCR = Data;
1895 set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
1897 /* Write the divisor */
1898 Data = (unsigned char)(divisor & 0xff);
1899 dbg("set_serial_baud Value to write DLL is %x", Data);
1900 set_uart_reg(port, DIVISOR_LATCH_LSB, Data);
1902 Data = (unsigned char)((divisor & 0xff00) >> 8);
1903 dbg("set_serial_baud Value to write DLM is %x", Data);
1904 set_uart_reg(port, DIVISOR_LATCH_MSB, Data);
1906 /* Disable access to divisor latch */
1907 Data = ATEN2011_port->shadowLCR & ~SERIAL_LCR_DLAB;
1908 ATEN2011_port->shadowLCR = Data;
1909 set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
1916 static void ATEN2011_change_port_settings(struct tty_struct *tty,
1917 struct ATENINTL_port *ATEN2011_port,
1918 struct ktermios *old_termios)
1928 struct usb_serial_port *port;
1929 struct usb_serial *serial;
1931 if (ATEN2011_port == NULL)
1934 port = (struct usb_serial_port *)ATEN2011_port->port;
1936 serial = port->serial;
1938 dbg("%s - port %d", __func__, ATEN2011_port->port->number);
1940 if (!ATEN2011_port->open) {
1941 dbg("%s - port not opened", __func__);
1945 if ((!tty) || (!tty->termios)) {
1946 dbg("%s - no tty structures", __func__);
1950 dbg("%s", "Entering .......... ");
1954 lParity = LCR_PAR_NONE;
1956 cflag = tty->termios->c_cflag;
1957 iflag = tty->termios->c_iflag;
1959 /* Change the number of bits */
1961 /* 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 */
1962 /* if(cflag & CSIZE) */
1964 switch (cflag & CSIZE) {
1982 /* Change the Parity bit */
1983 if (cflag & PARENB) {
1984 if (cflag & PARODD) {
1985 lParity = LCR_PAR_ODD;
1986 dbg("%s - parity = odd", __func__);
1988 lParity = LCR_PAR_EVEN;
1989 dbg("%s - parity = even", __func__);
1993 dbg("%s - parity = none", __func__);
1997 lParity = lParity | 0x20;
1999 /* Change the Stop bit */
2000 if (cflag & CSTOPB) {
2002 dbg("%s - stop bits = 2", __func__);
2005 dbg("%s - stop bits = 1", __func__);
2008 /* Update the LCR with the correct value */
2009 ATEN2011_port->shadowLCR &=
2010 ~(LCR_BITS_MASK | LCR_STOP_MASK | LCR_PAR_MASK);
2011 ATEN2011_port->shadowLCR |= (lData | lParity | lStop);
2014 ("ATEN2011_change_port_settings ATEN2011_port->shadowLCR is %x",
2015 ATEN2011_port->shadowLCR);
2016 /* Disable Interrupts */
2018 set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data);
2021 set_uart_reg(port, FIFO_CONTROL_REGISTER, Data);
2024 set_uart_reg(port, FIFO_CONTROL_REGISTER, Data);
2026 /* Send the updated LCR value to the ATEN2011 */
2027 Data = ATEN2011_port->shadowLCR;
2029 set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
2032 ATEN2011_port->shadowMCR = Data;
2033 set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
2035 set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
2037 /* set up the MCR register and send it to the ATEN2011 */
2039 ATEN2011_port->shadowMCR = MCR_MASTER_IE;
2041 ATEN2011_port->shadowMCR |= (MCR_DTR | MCR_RTS);
2043 if (cflag & CRTSCTS)
2044 ATEN2011_port->shadowMCR |= (MCR_XON_ANY);
2046 ATEN2011_port->shadowMCR &= ~(MCR_XON_ANY);
2048 Data = ATEN2011_port->shadowMCR;
2049 set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
2051 /* Determine divisor based on baud rate */
2052 baud = tty_get_baud_rate(tty);
2055 /* pick a default, any default... */
2056 dbg("%s", "Picked default baud...");
2060 dbg("%s - baud rate = %d", __func__, baud);
2061 status = ATEN2011_send_cmd_write_baud_rate(ATEN2011_port, baud);
2063 /* Enable Interrupts */
2065 set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data);
2067 if (ATEN2011_port->read_urb->status != -EINPROGRESS) {
2068 ATEN2011_port->read_urb->dev = serial->dev;
2070 status = usb_submit_urb(ATEN2011_port->read_urb, GFP_ATOMIC);
2074 (" usb_submit_urb(read bulk) failed, status = %d",
2079 ("ATEN2011_change_port_settings ATEN2011_port->shadowLCR is End %x",
2080 ATEN2011_port->shadowLCR);
2085 static int ATEN2011_calc_num_ports(struct usb_serial *serial)
2090 int ATEN2011_2or4ports;
2091 ret = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
2092 ATEN_RDREQ, ATEN_RD_RTYPE, 0, GPIO_REGISTER,
2093 &Data, VENDOR_READ_LENGTH, ATEN_WDR_TIMEOUT);
2095 /* ghostgum: here is where the problem appears to bet */
2096 /* Which of the following are needed? */
2097 /* Greg used the serial->type->num_ports=2 */
2098 /* But the code in the ATEN2011_open relies on serial->num_ports=2 */
2099 if ((Data & 0x01) == 0) {
2100 ATEN2011_2or4ports = 2;
2101 serial->type->num_ports = 2;
2102 serial->num_ports = 2;
2104 /* else if(serial->interface->cur_altsetting->desc.bNumEndpoints == 9) */
2106 ATEN2011_2or4ports = 4;
2107 serial->type->num_ports = 4;
2108 serial->num_ports = 4;
2112 return ATEN2011_2or4ports;
2115 static int ATEN2011_startup(struct usb_serial *serial)
2117 struct ATENINTL_serial *ATEN2011_serial;
2118 struct ATENINTL_port *ATEN2011_port;
2119 struct usb_device *dev;
2124 dbg("%s", " ATEN2011_startup :entering..........");
2127 dbg("%s", "Invalid Handler");
2133 dbg("%s", "Entering...");
2135 /* create our private serial structure */
2136 ATEN2011_serial = kzalloc(sizeof(struct ATENINTL_serial), GFP_KERNEL);
2137 if (ATEN2011_serial == NULL) {
2138 err("%s - Out of memory", __func__);
2142 /* resetting the private structure field values to zero */
2143 memset(ATEN2011_serial, 0, sizeof(struct ATENINTL_serial));
2145 ATEN2011_serial->serial = serial;
2146 /* initilize status polling flag to 0 */
2147 ATEN2011_serial->status_polling_started = 0;
2149 usb_set_serial_data(serial, ATEN2011_serial);
2150 ATEN2011_serial->ATEN2011_spectrum_2or4ports =
2151 ATEN2011_calc_num_ports(serial);
2152 /* we set up the pointers to the endpoints in the ATEN2011_open *
2153 * function, as the structures aren't created yet. */
2155 /* set up port private structures */
2156 for (i = 0; i < serial->num_ports; ++i) {
2158 kmalloc(sizeof(struct ATENINTL_port), GFP_KERNEL);
2159 if (ATEN2011_port == NULL) {
2160 err("%s - Out of memory", __func__);
2161 usb_set_serial_data(serial, NULL);
2162 kfree(ATEN2011_serial);
2165 memset(ATEN2011_port, 0, sizeof(struct ATENINTL_port));
2168 * Initialize all port interrupt end point to port 0
2169 * int endpoint. Our device has only one interrupt end point
2170 * comman to all port
2172 /* serial->port[i]->interrupt_in_endpointAddress = serial->port[0]->interrupt_in_endpointAddress; */
2174 ATEN2011_port->port = serial->port[i];
2175 usb_set_serial_port_data(serial->port[i], ATEN2011_port);
2177 minor = serial->port[i]->serial->minor;
2178 if (minor == SERIAL_TTY_NO_MINOR)
2180 ATEN2011_port->port_num =
2181 ((serial->port[i]->number - minor) + 1);
2183 if (ATEN2011_port->port_num == 1) {
2184 ATEN2011_port->SpRegOffset = 0x0;
2185 ATEN2011_port->ControlRegOffset = 0x1;
2186 ATEN2011_port->DcrRegOffset = 0x4;
2187 } else if ((ATEN2011_port->port_num == 2)
2188 && (ATEN2011_serial->ATEN2011_spectrum_2or4ports ==
2190 ATEN2011_port->SpRegOffset = 0x8;
2191 ATEN2011_port->ControlRegOffset = 0x9;
2192 ATEN2011_port->DcrRegOffset = 0x16;
2193 } else if ((ATEN2011_port->port_num == 2)
2194 && (ATEN2011_serial->ATEN2011_spectrum_2or4ports ==
2196 ATEN2011_port->SpRegOffset = 0xa;
2197 ATEN2011_port->ControlRegOffset = 0xb;
2198 ATEN2011_port->DcrRegOffset = 0x19;
2199 } else if ((ATEN2011_port->port_num == 3)
2200 && (ATEN2011_serial->ATEN2011_spectrum_2or4ports ==
2202 ATEN2011_port->SpRegOffset = 0xa;
2203 ATEN2011_port->ControlRegOffset = 0xb;
2204 ATEN2011_port->DcrRegOffset = 0x19;
2205 } else if ((ATEN2011_port->port_num == 4)
2206 && (ATEN2011_serial->ATEN2011_spectrum_2or4ports ==
2208 ATEN2011_port->SpRegOffset = 0xc;
2209 ATEN2011_port->ControlRegOffset = 0xd;
2210 ATEN2011_port->DcrRegOffset = 0x1c;
2213 usb_set_serial_port_data(serial->port[i], ATEN2011_port);
2215 /* enable rx_disable bit in control register */
2217 status = get_reg_sync(serial->port[i],
2218 ATEN2011_port->ControlRegOffset, &Data);
2220 dbg("Reading ControlReg failed status-0x%x",
2225 ("ControlReg Reading success val is %x, status%d",
2227 Data |= 0x08; /* setting driver done bit */
2228 Data |= 0x04; /* sp1_bit to have cts change reflect in modem status reg */
2230 /* Data |= 0x20; */ /* rx_disable bit */
2231 status = set_reg_sync(serial->port[i],
2232 ATEN2011_port->ControlRegOffset, Data);
2235 ("Writing ControlReg failed(rx_disable) status-0x%x",
2240 ("ControlReg Writing success(rx_disable) status%d",
2244 * Write default values in DCR (i.e 0x01 in DCR0, 0x05 in DCR2
2248 status = set_reg_sync(serial->port[i],
2249 (__u16)(ATEN2011_port->DcrRegOffset + 0),
2252 dbg("Writing DCR0 failed status-0x%x", status);
2255 dbg("DCR0 Writing success status%d", status);
2258 status = set_reg_sync(serial->port[i],
2259 (__u16)(ATEN2011_port->DcrRegOffset + 1),
2262 dbg("Writing DCR1 failed status-0x%x", status);
2265 dbg("DCR1 Writing success status%d", status);
2268 status = set_reg_sync(serial->port[i],
2269 (__u16)(ATEN2011_port->DcrRegOffset + 2),
2272 dbg("Writing DCR2 failed status-0x%x", status);
2275 dbg("DCR2 Writing success status%d", status);
2277 /* write values in clkstart0x0 and clkmulti 0x20 */
2279 status = set_reg_sync(serial->port[i], CLK_START_VALUE_REGISTER,
2283 ("Writing CLK_START_VALUE_REGISTER failed status-0x%x",
2288 ("CLK_START_VALUE_REGISTER Writing success status%d",
2292 status = set_reg_sync(serial->port[i], CLK_MULTI_REGISTER,
2296 ("Writing CLK_MULTI_REGISTER failed status-0x%x",
2300 dbg("CLK_MULTI_REGISTER Writing success status%d",
2303 /* Zero Length flag register */
2304 if ((ATEN2011_port->port_num != 1)
2305 && (ATEN2011_serial->ATEN2011_spectrum_2or4ports == 2)) {
2308 status = set_reg_sync(serial->port[i],
2309 (__u16)(ZLP_REG1 + ((__u16)ATEN2011_port->port_num)),
2311 dbg("ZLIP offset%x",
2313 ((__u16) ATEN2011_port->port_num)));
2316 ("Writing ZLP_REG%d failed status-0x%x",
2320 dbg("ZLP_REG%d Writing success status%d",
2324 status = set_reg_sync(serial->port[i],
2325 (__u16)(ZLP_REG1 + ((__u16)ATEN2011_port->port_num) - 0x1),
2327 dbg("ZLIP offset%x",
2329 ((__u16) ATEN2011_port->port_num) -
2333 ("Writing ZLP_REG%d failed status-0x%x",
2337 dbg("ZLP_REG%d Writing success status%d",
2341 ATEN2011_port->control_urb = usb_alloc_urb(0, GFP_ATOMIC);
2342 ATEN2011_port->ctrl_buf = kmalloc(16, GFP_KERNEL);
2346 /* Zero Length flag enable */
2348 status = set_reg_sync(serial->port[0], ZLP_REG5, Data);
2350 dbg("Writing ZLP_REG5 failed status-0x%x", status);
2353 dbg("ZLP_REG5 Writing success status%d", status);
2355 /* setting configuration feature to one */
2356 usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
2357 (__u8) 0x03, 0x00, 0x01, 0x00, NULL, 0x00, 5 * HZ);
2361 static void ATEN2011_shutdown(struct usb_serial *serial)
2364 struct ATENINTL_port *ATEN2011_port;
2366 /* check for the ports to be closed,close the ports and disconnect */
2368 /* free private structure allocated for serial port *
2369 * stop reads and writes on all ports */
2371 for (i = 0; i < serial->num_ports; ++i) {
2372 ATEN2011_port = usb_get_serial_port_data(serial->port[i]);
2373 kfree(ATEN2011_port->ctrl_buf);
2374 usb_kill_urb(ATEN2011_port->control_urb);
2375 kfree(ATEN2011_port);
2376 usb_set_serial_port_data(serial->port[i], NULL);
2379 /* free private structure allocated for serial device */
2381 kfree(usb_get_serial_data(serial));
2382 usb_set_serial_data(serial, NULL);
2385 static struct usb_serial_driver aten_serial_driver = {
2387 .owner = THIS_MODULE,
2390 .description = DRIVER_DESC,
2391 .id_table = id_table,
2392 .open = ATEN2011_open,
2393 .close = ATEN2011_close,
2394 .write = ATEN2011_write,
2395 .write_room = ATEN2011_write_room,
2396 .chars_in_buffer = ATEN2011_chars_in_buffer,
2397 .throttle = ATEN2011_throttle,
2398 .unthrottle = ATEN2011_unthrottle,
2399 .calc_num_ports = ATEN2011_calc_num_ports,
2401 .ioctl = ATEN2011_ioctl,
2402 .set_termios = ATEN2011_set_termios,
2403 .break_ctl = ATEN2011_break,
2404 .tiocmget = ATEN2011_tiocmget,
2405 .tiocmset = ATEN2011_tiocmset,
2406 .attach = ATEN2011_startup,
2407 .shutdown = ATEN2011_shutdown,
2408 .read_bulk_callback = ATEN2011_bulk_in_callback,
2409 .read_int_callback = ATEN2011_interrupt_callback,
2412 static struct usb_driver aten_driver = {
2414 .probe = usb_serial_probe,
2415 .disconnect = usb_serial_disconnect,
2416 .id_table = id_table,
2419 static int __init aten_init(void)
2423 /* Register with the usb serial */
2424 retval = usb_serial_register(&aten_serial_driver);
2428 printk(KERN_INFO KBUILD_MODNAME ":"
2429 DRIVER_DESC " " DRIVER_VERSION "\n");
2431 /* Register with the usb */
2432 retval = usb_register(&aten_driver);
2434 usb_serial_deregister(&aten_serial_driver);
2439 static void __exit aten_exit(void)
2441 usb_deregister(&aten_driver);
2442 usb_serial_deregister(&aten_serial_driver);
2445 module_init(aten_init);
2446 module_exit(aten_exit);
2448 /* Module information */
2449 MODULE_DESCRIPTION(DRIVER_DESC);
2450 MODULE_LICENSE("GPL");
2452 MODULE_PARM_DESC(debug, "Debug enabled or not");