2 * Aten 2011 USB serial driver for 4 port devices
4 * Copyright (C) 2000 Inside Out Networks
5 * Copyright (C) 2001-2002, 2009 Greg Kroah-Hartman <greg@kroah.com>
6 * Copyright (C) 2009 Novell Inc.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
15 #include <linux/kernel.h>
16 #include <linux/errno.h>
17 #include <linux/init.h>
18 #include <linux/slab.h>
19 #include <linux/tty.h>
20 #include <linux/tty_driver.h>
21 #include <linux/tty_flip.h>
22 #include <linux/module.h>
23 #include <linux/serial.h>
24 #include <linux/usb.h>
25 #include <linux/usb/serial.h>
26 #include <asm/uaccess.h>
29 #define ZLP_REG1 0x3A /* Zero_Flag_Reg1 58 */
30 #define ZLP_REG2 0x3B /* Zero_Flag_Reg2 59 */
31 #define ZLP_REG3 0x3C /* Zero_Flag_Reg3 60 */
32 #define ZLP_REG4 0x3D /* Zero_Flag_Reg4 61 */
33 #define ZLP_REG5 0x3E /* Zero_Flag_Reg5 62 */
35 /* Interrupt Rotinue Defines */
36 #define SERIAL_IIR_RLS 0x06
37 #define SERIAL_IIR_RDA 0x04
38 #define SERIAL_IIR_CTI 0x0c
39 #define SERIAL_IIR_THR 0x02
40 #define SERIAL_IIR_MS 0x00
42 /* Emulation of the bit mask on the LINE STATUS REGISTER. */
43 #define SERIAL_LSR_DR 0x0001
44 #define SERIAL_LSR_OE 0x0002
45 #define SERIAL_LSR_PE 0x0004
46 #define SERIAL_LSR_FE 0x0008
47 #define SERIAL_LSR_BI 0x0010
48 #define SERIAL_LSR_THRE 0x0020
49 #define SERIAL_LSR_TEMT 0x0040
50 #define SERIAL_LSR_FIFOERR 0x0080
52 /* MSR bit defines(place holders) */
53 #define ATEN_MSR_DELTA_CTS 0x10
54 #define ATEN_MSR_DELTA_DSR 0x20
55 #define ATEN_MSR_DELTA_RI 0x40
56 #define ATEN_MSR_DELTA_CD 0x80
58 /* Serial Port register Address */
59 #define RECEIVE_BUFFER_REGISTER ((__u16)(0x00))
60 #define TRANSMIT_HOLDING_REGISTER ((__u16)(0x00))
61 #define INTERRUPT_ENABLE_REGISTER ((__u16)(0x01))
62 #define INTERRUPT_IDENT_REGISTER ((__u16)(0x02))
63 #define FIFO_CONTROL_REGISTER ((__u16)(0x02))
64 #define LINE_CONTROL_REGISTER ((__u16)(0x03))
65 #define MODEM_CONTROL_REGISTER ((__u16)(0x04))
66 #define LINE_STATUS_REGISTER ((__u16)(0x05))
67 #define MODEM_STATUS_REGISTER ((__u16)(0x06))
68 #define SCRATCH_PAD_REGISTER ((__u16)(0x07))
69 #define DIVISOR_LATCH_LSB ((__u16)(0x00))
70 #define DIVISOR_LATCH_MSB ((__u16)(0x01))
72 #define SP1_REGISTER ((__u16)(0x00))
73 #define CONTROL1_REGISTER ((__u16)(0x01))
74 #define CLK_MULTI_REGISTER ((__u16)(0x02))
75 #define CLK_START_VALUE_REGISTER ((__u16)(0x03))
76 #define DCR1_REGISTER ((__u16)(0x04))
77 #define GPIO_REGISTER ((__u16)(0x07))
79 #define SERIAL_LCR_DLAB ((__u16)(0x0080))
82 * URB POOL related defines
84 #define NUM_URBS 16 /* URB Count */
85 #define URB_TRANSFER_BUFFER_SIZE 32 /* URB Size */
87 #define USB_VENDOR_ID_ATENINTL 0x0557
88 #define ATENINTL_DEVICE_ID_2011 0x2011
89 #define ATENINTL_DEVICE_ID_7820 0x7820
91 static struct usb_device_id id_table [] = {
92 { USB_DEVICE(USB_VENDOR_ID_ATENINTL,ATENINTL_DEVICE_ID_2011) },
93 { USB_DEVICE(USB_VENDOR_ID_ATENINTL,ATENINTL_DEVICE_ID_7820) },
94 { } /* terminating entry */
96 MODULE_DEVICE_TABLE (usb, id_table);
98 /* This structure holds all of the local port information */
101 int port_num; /*Actual port number in the device(1,2,etc)*/
102 __u8 bulk_out_endpoint; /* the bulk out endpoint handle */
103 unsigned char *bulk_out_buffer; /* buffer used for the bulk out endpoint */
104 struct urb *write_urb; /* write URB for this port */
105 __u8 bulk_in_endpoint; /* the bulk in endpoint handle */
106 unsigned char *bulk_in_buffer; /* the buffer we use for the bulk in endpoint */
107 struct urb *read_urb; /* read URB for this port */
108 __u8 shadowLCR; /* last LCR value received */
109 __u8 shadowMCR; /* last MCR value received */
111 char chaseResponsePending;
112 wait_queue_head_t wait_chase; /* for handling sleeping while waiting for chase to finish */
113 wait_queue_head_t wait_command; /* for handling sleeping while waiting for command to finish */
114 struct async_icount icount;
115 struct usb_serial_port *port; /* loop back to the owner of this object */
118 __u8 ControlRegOffset;
120 /* for processing control URBS in interrupt context */
121 struct urb *control_urb;
125 struct urb *write_urb_pool[NUM_URBS];
126 /* we pass a pointer to this as the arguement sent to cypress_set_termios old_termios */
127 struct ktermios tmp_termios; /* stores the old termios settings */
128 spinlock_t lock; /* private lock */
132 /* This structure holds all of the individual serial device information */
133 struct ATENINTL_serial
135 __u8 interrupt_in_endpoint; /* the interrupt endpoint handle */
136 unsigned char *interrupt_in_buffer; /* the buffer we use for the interrupt endpoint */
137 struct urb * interrupt_read_urb; /* our interrupt urb */
138 __u8 bulk_in_endpoint; /* the bulk in endpoint handle */
139 unsigned char *bulk_in_buffer; /* the buffer we use for the bulk in endpoint */
140 struct urb *read_urb; /* our bulk read urb */
141 __u8 bulk_out_endpoint; /* the bulk out endpoint handle */
142 struct usb_serial *serial; /* loop back to the owner of this object */
143 int ATEN2011_spectrum_2or4ports; /* this says the number of ports in the device */
144 /* Indicates about the no.of opened ports of an individual USB-serial adapater. */
145 unsigned int NoOfOpenPorts;
146 /* a flag for Status endpoint polling */
147 unsigned char status_polling_started;
150 static void ATEN2011_set_termios(struct tty_struct *tty,
151 struct usb_serial_port *port,
152 struct ktermios *old_termios);
153 static void ATEN2011_change_port_settings(struct tty_struct *tty,
154 struct ATENINTL_port *ATEN2011_port,
155 struct ktermios *old_termios);
157 /*************************************
158 * Bit definitions for each register *
159 *************************************/
160 #define LCR_BITS_5 0x00 /* 5 bits/char */
161 #define LCR_BITS_6 0x01 /* 6 bits/char */
162 #define LCR_BITS_7 0x02 /* 7 bits/char */
163 #define LCR_BITS_8 0x03 /* 8 bits/char */
164 #define LCR_BITS_MASK 0x03 /* Mask for bits/char field */
166 #define LCR_STOP_1 0x00 /* 1 stop bit */
167 #define LCR_STOP_1_5 0x04 /* 1.5 stop bits (if 5 bits/char) */
168 #define LCR_STOP_2 0x04 /* 2 stop bits (if 6-8 bits/char) */
169 #define LCR_STOP_MASK 0x04 /* Mask for stop bits field */
171 #define LCR_PAR_NONE 0x00 /* No parity */
172 #define LCR_PAR_ODD 0x08 /* Odd parity */
173 #define LCR_PAR_EVEN 0x18 /* Even parity */
174 #define LCR_PAR_MARK 0x28 /* Force parity bit to 1 */
175 #define LCR_PAR_SPACE 0x38 /* Force parity bit to 0 */
176 #define LCR_PAR_MASK 0x38 /* Mask for parity field */
178 #define LCR_SET_BREAK 0x40 /* Set Break condition */
179 #define LCR_DL_ENABLE 0x80 /* Enable access to divisor latch */
181 #define MCR_DTR 0x01 /* Assert DTR */
182 #define MCR_RTS 0x02 /* Assert RTS */
183 #define MCR_OUT1 0x04 /* Loopback only: Sets state of RI */
184 #define MCR_MASTER_IE 0x08 /* Enable interrupt outputs */
185 #define MCR_LOOPBACK 0x10 /* Set internal (digital) loopback mode */
186 #define MCR_XON_ANY 0x20 /* Enable any char to exit XOFF mode */
188 #define ATEN2011_MSR_CTS 0x10 /* Current state of CTS */
189 #define ATEN2011_MSR_DSR 0x20 /* Current state of DSR */
190 #define ATEN2011_MSR_RI 0x40 /* Current state of RI */
191 #define ATEN2011_MSR_CD 0x80 /* Current state of CD */
194 /* 1: Enables the debugging -- 0: Disable the debugging */
198 static int debug = 0;
199 #define DPRINTK(fmt, args...) printk( "%s: " fmt, __FUNCTION__ , ## args)
202 static int debug = 0;
203 #define DPRINTK(fmt, args...)
208 * Version Information
210 #define DRIVER_VERSION "2.0"
211 #define DRIVER_DESC "ATENINTL 2011 USB Serial Adapter"
214 * Defines used for sending commands to port
217 #define ATEN_WDR_TIMEOUT (50) /* default urb timeout */
220 #define ATEN_RD_RTYPE 0xC0
221 #define ATEN_WR_RTYPE 0x40
222 #define ATEN_RDREQ 0x0D
223 #define ATEN_WRREQ 0x0E
224 #define ATEN_CTRL_TIMEOUT 500
225 #define VENDOR_READ_LENGTH (0x01)
227 /* set to 1 for RS485 mode and 0 for RS232 mode */
228 /* FIXME make this somehow dynamic and not build time specific */
229 static int RS485mode = 0;
231 static int set_reg_sync(struct usb_serial_port *port, __u16 reg, __u16 val)
233 struct usb_device *dev = port->serial->dev;
236 dbg("%s: is %x, value %x\n", __func__, reg, val);
238 return usb_control_msg(dev, usb_sndctrlpipe(dev, 0), ATEN_WRREQ,
239 ATEN_WR_RTYPE, val, reg, NULL, 0,
243 static int get_reg_sync(struct usb_serial_port *port, __u16 reg, __u16 *val)
245 struct usb_device *dev = port->serial->dev;
248 ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), ATEN_RDREQ,
249 ATEN_RD_RTYPE, 0, reg, val, VENDOR_READ_LENGTH,
251 dbg("%s: offset is %x, return val %x\n", __func__, reg, *val);
252 *val = (*val) & 0x00ff;
256 static int set_uart_reg(struct usb_serial_port *port, __u16 reg, __u16 val)
258 struct usb_device *dev = port->serial->dev;
259 struct ATENINTL_serial *a_serial;
262 a_serial = usb_get_serial_data(port->serial);
263 minor = port->serial->minor;
264 if (minor == SERIAL_TTY_NO_MINOR)
269 * For the UART control registers,
270 * the application number need to be Or'ed
272 if (a_serial->ATEN2011_spectrum_2or4ports == 4)
273 val |= (((__u16)port->number - minor) + 1) << 8;
275 if (((__u16) port->number - minor) == 0)
276 val |= (((__u16)port->number - minor) + 1) << 8;
278 val |= (((__u16)port->number - minor) + 2) << 8;
280 dbg("%s: application number is %x\n", __func__, val);
282 return usb_control_msg(dev, usb_sndctrlpipe(dev, 0), ATEN_WRREQ,
283 ATEN_WR_RTYPE, val, reg, NULL, 0,
287 static int get_uart_reg(struct usb_serial_port *port, __u16 reg, __u16 *val)
289 struct usb_device *dev = port->serial->dev;
292 struct ATENINTL_serial *a_serial;
293 __u16 minor = port->serial->minor;
295 a_serial = usb_get_serial_data(port->serial);
296 if (minor == SERIAL_TTY_NO_MINOR)
299 /* wval is same as application number */
300 if (a_serial->ATEN2011_spectrum_2or4ports == 4)
301 wval = (((__u16)port->number - minor) + 1) << 8;
303 if (((__u16) port->number - minor) == 0)
304 wval = (((__u16) port->number - minor) + 1) << 8;
306 wval = (((__u16) port->number - minor) + 2) << 8;
308 dbg("%s: application number is %x\n", __func__, wval);
309 ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), ATEN_RDREQ,
310 ATEN_RD_RTYPE, wval, reg, val, VENDOR_READ_LENGTH,
312 *val = (*val) & 0x00ff;
316 static int handle_newMsr(struct ATENINTL_port *port, __u8 newMsr)
318 struct ATENINTL_port *ATEN2011_port;
319 struct async_icount *icount;
320 ATEN2011_port = port;
321 icount = &ATEN2011_port->icount;
323 (ATEN_MSR_DELTA_CTS | ATEN_MSR_DELTA_DSR | ATEN_MSR_DELTA_RI |
324 ATEN_MSR_DELTA_CD)) {
325 icount = &ATEN2011_port->icount;
327 /* update input line counters */
328 if (newMsr & ATEN_MSR_DELTA_CTS) {
331 if (newMsr & ATEN_MSR_DELTA_DSR) {
334 if (newMsr & ATEN_MSR_DELTA_CD) {
337 if (newMsr & ATEN_MSR_DELTA_RI) {
345 static int handle_newLsr(struct ATENINTL_port *port, __u8 newLsr)
347 struct async_icount *icount;
349 dbg("%s - %02x", __FUNCTION__, newLsr);
351 if (newLsr & SERIAL_LSR_BI) {
353 * Parity and Framing errors only count if they occur exclusive
354 * of a break being received.
356 newLsr &= (__u8) (SERIAL_LSR_OE | SERIAL_LSR_BI);
359 /* update input line counters */
360 icount = &port->icount;
361 if (newLsr & SERIAL_LSR_BI) {
364 if (newLsr & SERIAL_LSR_OE) {
367 if (newLsr & SERIAL_LSR_PE) {
370 if (newLsr & SERIAL_LSR_FE) {
377 static void ATEN2011_control_callback(struct urb *urb)
380 struct ATENINTL_port *ATEN2011_port;
384 DPRINTK("%s", "Invalid Pointer !!!!:\n");
388 switch (urb->status) {
395 /* this urb is terminated, clean up */
396 dbg("%s - urb shutting down with status: %d", __FUNCTION__,
400 dbg("%s - nonzero urb status received: %d", __FUNCTION__,
405 ATEN2011_port = (struct ATENINTL_port *)urb->context;
407 DPRINTK("%s urb buffer size is %d\n", __FUNCTION__, urb->actual_length);
408 DPRINTK("%s ATEN2011_port->MsrLsr is %d port %d\n", __FUNCTION__,
409 ATEN2011_port->MsrLsr, ATEN2011_port->port_num);
410 data = urb->transfer_buffer;
411 regval = (__u8) data[0];
412 DPRINTK("%s data is %x\n", __FUNCTION__, regval);
413 if (ATEN2011_port->MsrLsr == 0)
414 handle_newMsr(ATEN2011_port, regval);
415 else if (ATEN2011_port->MsrLsr == 1)
416 handle_newLsr(ATEN2011_port, regval);
422 static int ATEN2011_get_reg(struct ATENINTL_port *ATEN, __u16 Wval, __u16 reg,
425 struct usb_device *dev = ATEN->port->serial->dev;
426 struct usb_ctrlrequest *dr = NULL;
427 unsigned char *buffer = NULL;
429 buffer = (__u8 *) ATEN->ctrl_buf;
431 dr = (void *)(buffer + 2);
432 dr->bRequestType = ATEN_RD_RTYPE;
433 dr->bRequest = ATEN_RDREQ;
434 dr->wValue = cpu_to_le16(Wval);
435 dr->wIndex = cpu_to_le16(reg);
436 dr->wLength = cpu_to_le16(2);
438 usb_fill_control_urb(ATEN->control_urb, dev, usb_rcvctrlpipe(dev, 0),
439 (unsigned char *)dr, buffer, 2,
440 ATEN2011_control_callback, ATEN);
441 ATEN->control_urb->transfer_buffer_length = 2;
442 ret = usb_submit_urb(ATEN->control_urb, GFP_ATOMIC);
446 static void ATEN2011_interrupt_callback(struct urb *urb)
450 struct ATENINTL_port *ATEN2011_port;
451 struct ATENINTL_serial *ATEN2011_serial;
452 struct usb_serial *serial;
460 DPRINTK("%s", " : Entering\n");
462 ATEN2011_serial = (struct ATENINTL_serial *)urb->context;
464 DPRINTK("%s", "Invalid Pointer !!!!:\n");
468 switch (urb->status) {
475 /* this urb is terminated, clean up */
476 dbg("%s - urb shutting down with status: %d", __FUNCTION__,
480 dbg("%s - nonzero urb status received: %d", __FUNCTION__,
484 length = urb->actual_length;
485 data = urb->transfer_buffer;
487 serial = ATEN2011_serial->serial;
489 /* ATENINTL get 5 bytes
490 * Byte 1 IIR Port 1 (port.number is 0)
491 * Byte 2 IIR Port 2 (port.number is 1)
492 * Byte 3 IIR Port 3 (port.number is 2)
493 * Byte 4 IIR Port 4 (port.number is 3)
494 * Byte 5 FIFO status for both */
496 if (length && length > 5) {
497 DPRINTK("%s \n", "Wrong data !!!");
502 if (ATEN2011_serial->ATEN2011_spectrum_2or4ports == 4) {
503 sp[0] = (__u8) data[0];
504 sp[1] = (__u8) data[1];
505 sp[2] = (__u8) data[2];
506 sp[3] = (__u8) data[3];
509 sp[0] = (__u8) data[0];
510 sp[1] = (__u8) data[2];
511 /* sp[2]=(__u8)data[2]; */
512 /* sp[3]=(__u8)data[3]; */
516 for (i = 0; i < serial->num_ports; i++) {
517 ATEN2011_port = usb_get_serial_port_data(serial->port[i]);
518 minor = serial->minor;
519 if (minor == SERIAL_TTY_NO_MINOR)
521 if ((ATEN2011_serial->ATEN2011_spectrum_2or4ports == 2)
524 (((__u16) serial->port[i]->number -
525 (__u16) (minor)) + 2) << 8;
528 (((__u16) serial->port[i]->number -
529 (__u16) (minor)) + 1) << 8;
530 if (ATEN2011_port->open != 0) {
532 DPRINTK("SP%d No Interrupt !!!\n", i);
534 switch (sp[i] & 0x0f) {
537 ("Serial Port %d: Receiver status error or ",
540 ("address bit detected in 9-bit mode\n");
541 ATEN2011_port->MsrLsr = 1;
542 ATEN2011_get_reg(ATEN2011_port, wval,
543 LINE_STATUS_REGISTER,
548 ("Serial Port %d: Modem status change\n",
550 ATEN2011_port->MsrLsr = 0;
551 ATEN2011_get_reg(ATEN2011_port, wval,
552 MODEM_STATUS_REGISTER,
561 if (ATEN2011_serial->status_polling_started == 0)
564 result = usb_submit_urb(urb, GFP_ATOMIC);
566 dev_err(&urb->dev->dev,
567 "%s - Error %d submitting interrupt urb\n",
568 __FUNCTION__, result);
575 static void ATEN2011_bulk_in_callback(struct urb *urb)
579 struct usb_serial *serial;
580 struct usb_serial_port *port;
581 struct ATENINTL_serial *ATEN2011_serial;
582 struct ATENINTL_port *ATEN2011_port;
583 struct tty_struct *tty;
585 DPRINTK("%s", "Invalid Pointer !!!!:\n");
590 DPRINTK("nonzero read bulk status received: %d", urb->status);
594 ATEN2011_port = (struct ATENINTL_port *)urb->context;
595 if (!ATEN2011_port) {
596 DPRINTK("%s", "NULL ATEN2011_port pointer \n");
600 port = (struct usb_serial_port *)ATEN2011_port->port;
601 serial = port->serial;
603 DPRINTK("%s\n", "Entering... \n");
605 data = urb->transfer_buffer;
606 ATEN2011_serial = usb_get_serial_data(serial);
608 DPRINTK("%s", "Entering ........... \n");
610 if (urb->actual_length) {
611 tty = tty_port_tty_get(&ATEN2011_port->port->port);
613 tty_buffer_request_room(tty, urb->actual_length);
614 tty_insert_flip_string(tty, data, urb->actual_length);
615 DPRINTK(" %s \n", data);
616 tty_flip_buffer_push(tty);
620 ATEN2011_port->icount.rx += urb->actual_length;
621 DPRINTK("ATEN2011_port->icount.rx is %d:\n",
622 ATEN2011_port->icount.rx);
625 if (!ATEN2011_port->read_urb) {
626 DPRINTK("%s", "URB KILLED !!!\n");
630 if (ATEN2011_port->read_urb->status != -EINPROGRESS) {
631 ATEN2011_port->read_urb->dev = serial->dev;
633 status = usb_submit_urb(ATEN2011_port->read_urb, GFP_ATOMIC);
637 (" usb_submit_urb(read bulk) failed, status = %d",
643 static void ATEN2011_bulk_out_data_callback(struct urb *urb)
645 struct ATENINTL_port *ATEN2011_port;
646 struct tty_struct *tty;
648 DPRINTK("%s", "Invalid Pointer !!!!:\n");
653 DPRINTK("nonzero write bulk status received:%d\n", urb->status);
657 ATEN2011_port = (struct ATENINTL_port *)urb->context;
658 if (!ATEN2011_port) {
659 DPRINTK("%s", "NULL ATEN2011_port pointer \n");
663 DPRINTK("%s \n", "Entering .........");
665 tty = tty_port_tty_get(&ATEN2011_port->port->port);
667 if (tty && ATEN2011_port->open) {
668 /* tell the tty driver that something has changed */
669 wake_up_interruptible(&tty->write_wait);
672 /* schedule_work(&ATEN2011_port->port->work); */
677 #ifdef ATENSerialProbe
678 static int ATEN2011_serial_probe(struct usb_serial *serial,
679 const struct usb_device_id *id)
682 /*need to implement the mode_reg reading and updating\
683 structures usb_serial_ device_type\
684 (i.e num_ports, num_bulkin,bulkout etc) */
685 /* Also we can update the changes attach */
690 static int ATEN2011_open(struct tty_struct *tty, struct usb_serial_port *port,
695 struct usb_serial *serial;
699 struct ATENINTL_serial *ATEN2011_serial;
700 struct ATENINTL_port *ATEN2011_port;
701 struct ktermios tmp_termios;
704 serial = port->serial;
706 ATEN2011_port = usb_get_serial_port_data(port);
708 if (ATEN2011_port == NULL)
711 if (ATEN2011_port->ctrl_buf==NULL)
713 ATEN2011_port->ctrl_buf = kmalloc(16,GFP_KERNEL);
714 if (ATEN2011_port->ctrl_buf == NULL) {
715 printk(", Can't allocate ctrl buff\n");
721 if(!ATEN2011_port->control_urb)
723 ATEN2011_port->control_urb=kmalloc(sizeof(struct urb),GFP_KERNEL);
727 ATEN2011_serial = usb_get_serial_data(serial);
729 if (ATEN2011_serial == NULL) {
732 /* increment the number of opened ports counter here */
733 ATEN2011_serial->NoOfOpenPorts++;
735 usb_clear_halt(serial->dev, port->write_urb->pipe);
736 usb_clear_halt(serial->dev, port->read_urb->pipe);
738 /* Initialising the write urb pool */
739 for (j = 0; j < NUM_URBS; ++j) {
740 urb = usb_alloc_urb(0, GFP_ATOMIC);
741 ATEN2011_port->write_urb_pool[j] = urb;
744 err("No more urbs???");
748 urb->transfer_buffer = NULL;
749 urb->transfer_buffer =
750 kmalloc(URB_TRANSFER_BUFFER_SIZE, GFP_KERNEL);
751 if (!urb->transfer_buffer) {
752 err("%s-out of memory for urb buffers.", __FUNCTION__);
757 /*****************************************************************************
758 * Initialize ATEN2011 -- Write Init values to corresponding Registers
766 * 0x08 : SP1/2 Control Reg
767 *****************************************************************************/
769 /* NEED to check the fallowing Block */
772 status = get_reg_sync(port, ATEN2011_port->SpRegOffset, &Data);
774 DPRINTK("Reading Spreg failed\n");
778 status = set_reg_sync(port, ATEN2011_port->SpRegOffset, Data);
780 DPRINTK("writing Spreg failed\n");
785 status = set_reg_sync(port, ATEN2011_port->SpRegOffset, Data);
787 DPRINTK("writing Spreg failed\n");
791 /* End of block to be checked */
792 /**************************CHECK***************************/
798 status = set_uart_reg(port, SCRATCH_PAD_REGISTER, Data);
800 DPRINTK("Writing SCRATCH_PAD_REGISTER failed status-0x%x\n",
804 DPRINTK("SCRATCH_PAD_REGISTER Writing success status%d\n",
807 /**************************CHECK***************************/
810 status = get_reg_sync(port, ATEN2011_port->ControlRegOffset, &Data);
812 DPRINTK("Reading Controlreg failed\n");
815 Data |= 0x08; /* Driver done bit */
816 Data |= 0x20; /* rx_disable */
819 set_reg_sync(port, ATEN2011_port->ControlRegOffset, Data);
821 DPRINTK("writing Controlreg failed\n");
825 * do register settings here
826 * Set all regs to the device default values.
827 * First Disable all interrupts.
831 status = set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data);
833 DPRINTK("disableing interrupts failed\n");
836 /* Set FIFO_CONTROL_REGISTER to the default value */
838 status = set_uart_reg(port, FIFO_CONTROL_REGISTER, Data);
840 DPRINTK("Writing FIFO_CONTROL_REGISTER failed\n");
844 Data = 0xcf; /* chk */
845 status = set_uart_reg(port, FIFO_CONTROL_REGISTER, Data);
847 DPRINTK("Writing FIFO_CONTROL_REGISTER failed\n");
851 Data = 0x03; /* LCR_BITS_8 */
852 status = set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
853 ATEN2011_port->shadowLCR = Data;
855 Data = 0x0b; /* MCR_DTR|MCR_RTS|MCR_MASTER_IE */
856 status = set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
857 ATEN2011_port->shadowMCR = Data;
861 status = get_uart_reg(port, LINE_CONTROL_REGISTER, &Data);
862 ATEN2011_port->shadowLCR = Data;
864 Data |= SERIAL_LCR_DLAB; /* data latch enable in LCR 0x80 */
865 status = set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
868 status = set_uart_reg(port, DIVISOR_LATCH_LSB, Data);
871 status = set_uart_reg(port, DIVISOR_LATCH_MSB, Data);
874 status = get_uart_reg(port, LINE_CONTROL_REGISTER, &Data);
876 /* Data = ATEN2011_port->shadowLCR; */ /* data latch disable */
877 Data = Data & ~SERIAL_LCR_DLAB;
878 status = set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
879 ATEN2011_port->shadowLCR = Data;
881 /* clearing Bulkin and Bulkout Fifo */
883 status = get_reg_sync(port, ATEN2011_port->SpRegOffset, &Data);
886 status = set_reg_sync(port, ATEN2011_port->SpRegOffset, Data);
889 status = set_reg_sync(port, ATEN2011_port->SpRegOffset, Data);
890 /* Finally enable all interrupts */
893 status = set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data);
895 /* clearing rx_disable */
897 status = get_reg_sync(port, ATEN2011_port->ControlRegOffset, &Data);
899 status = set_reg_sync(port, ATEN2011_port->ControlRegOffset, Data);
903 status = get_reg_sync(port, ATEN2011_port->ControlRegOffset, &Data);
906 status = set_reg_sync(port, ATEN2011_port->ControlRegOffset, Data);
908 /* force low_latency on so that our tty_push actually forces *
909 * the data through,otherwise it is scheduled, and with *
910 * high data rates (like with OHCI) data can get lost. */
913 tty->low_latency = 1;
915 printk("port number is %d \n",port->number);
916 printk("serial number is %d \n",port->serial->minor);
917 printk("Bulkin endpoint is %d \n",port->bulk_in_endpointAddress);
918 printk("BulkOut endpoint is %d \n",port->bulk_out_endpointAddress);
919 printk("Interrupt endpoint is %d \n",port->interrupt_in_endpointAddress);
920 printk("port's number in the device is %d\n",ATEN2011_port->port_num);
923 * Check to see if we've set up our endpoint info yet
924 * (can't set it up in ATEN2011_startup as the structures
925 * were not set up at that time.)
927 if (ATEN2011_serial->NoOfOpenPorts == 1) {
928 /* start the status polling here */
929 ATEN2011_serial->status_polling_started = 1;
930 /* If not yet set, Set here */
931 ATEN2011_serial->interrupt_in_buffer =
932 serial->port[0]->interrupt_in_buffer;
933 ATEN2011_serial->interrupt_in_endpoint =
934 serial->port[0]->interrupt_in_endpointAddress;
935 ATEN2011_serial->interrupt_read_urb =
936 serial->port[0]->interrupt_in_urb;
938 /* set up interrupt urb */
939 usb_fill_int_urb(ATEN2011_serial->interrupt_read_urb,
941 usb_rcvintpipe(serial->dev,
943 interrupt_in_endpoint),
944 ATEN2011_serial->interrupt_in_buffer,
945 ATEN2011_serial->interrupt_read_urb->
946 transfer_buffer_length,
947 ATEN2011_interrupt_callback, ATEN2011_serial,
948 ATEN2011_serial->interrupt_read_urb->interval);
950 /* start interrupt read for ATEN2011 *
951 * will continue as long as ATEN2011 is connected */
954 usb_submit_urb(ATEN2011_serial->interrupt_read_urb,
957 DPRINTK("%s - Error %d submitting interrupt urb",
958 __FUNCTION__, response);
964 * See if we've set up our endpoint info yet
965 * (can't set it up in ATEN2011_startup as the
966 * structures were not set up at that time.)
969 DPRINTK("port number is %d \n", port->number);
970 DPRINTK("serial number is %d \n", port->serial->minor);
971 DPRINTK("Bulkin endpoint is %d \n", port->bulk_in_endpointAddress);
972 DPRINTK("BulkOut endpoint is %d \n", port->bulk_out_endpointAddress);
973 DPRINTK("Interrupt endpoint is %d \n",
974 port->interrupt_in_endpointAddress);
975 DPRINTK("port's number in the device is %d\n", ATEN2011_port->port_num);
976 ATEN2011_port->bulk_in_buffer = port->bulk_in_buffer;
977 ATEN2011_port->bulk_in_endpoint = port->bulk_in_endpointAddress;
978 ATEN2011_port->read_urb = port->read_urb;
979 ATEN2011_port->bulk_out_endpoint = port->bulk_out_endpointAddress;
981 minor = port->serial->minor;
982 if (minor == SERIAL_TTY_NO_MINOR)
985 /* set up our bulk in urb */
986 if ((ATEN2011_serial->ATEN2011_spectrum_2or4ports == 2)
987 && (((__u16) port->number - (__u16) (minor)) != 0)) {
988 usb_fill_bulk_urb(ATEN2011_port->read_urb, serial->dev,
989 usb_rcvbulkpipe(serial->dev,
991 bulk_in_endpointAddress +
992 2)), port->bulk_in_buffer,
993 ATEN2011_port->read_urb->
994 transfer_buffer_length,
995 ATEN2011_bulk_in_callback, ATEN2011_port);
997 usb_fill_bulk_urb(ATEN2011_port->read_urb,
999 usb_rcvbulkpipe(serial->dev,
1001 bulk_in_endpointAddress),
1002 port->bulk_in_buffer,
1003 ATEN2011_port->read_urb->
1004 transfer_buffer_length,
1005 ATEN2011_bulk_in_callback, ATEN2011_port);
1007 DPRINTK("ATEN2011_open: bulkin endpoint is %d\n",
1008 port->bulk_in_endpointAddress);
1009 response = usb_submit_urb(ATEN2011_port->read_urb, GFP_KERNEL);
1011 err("%s - Error %d submitting control urb", __FUNCTION__,
1015 /* initialize our wait queues */
1016 init_waitqueue_head(&ATEN2011_port->wait_chase);
1017 init_waitqueue_head(&ATEN2011_port->wait_command);
1019 /* initialize our icount structure */
1020 memset(&(ATEN2011_port->icount), 0x00, sizeof(ATEN2011_port->icount));
1022 /* initialize our port settings */
1023 ATEN2011_port->shadowMCR = MCR_MASTER_IE; /* Must set to enable ints! */
1024 ATEN2011_port->chaseResponsePending = 0;
1025 /* send a open port command */
1026 ATEN2011_port->open = 1;
1027 /* ATEN2011_change_port_settings(ATEN2011_port,old_termios); */
1029 ATEN2011_set_termios(tty, port, &tmp_termios);
1030 ATEN2011_port->icount.tx = 0;
1031 ATEN2011_port->icount.rx = 0;
1034 ("\n\nusb_serial serial:%x ATEN2011_port:%x\nATEN2011_serial:%x usb_serial_port port:%x\n\n",
1035 (unsigned int)serial, (unsigned int)ATEN2011_port,
1036 (unsigned int)ATEN2011_serial, (unsigned int)port);
1042 static int ATEN2011_chars_in_buffer(struct tty_struct *tty)
1044 struct usb_serial_port *port = tty->driver_data;
1047 struct ATENINTL_port *ATEN2011_port;
1049 /* DPRINTK("%s \n"," ATEN2011_chars_in_buffer:entering ..........."); */
1051 ATEN2011_port = usb_get_serial_port_data(port);
1052 if (ATEN2011_port == NULL) {
1053 DPRINTK("%s \n", "ATEN2011_break:leaving ...........");
1057 for (i = 0; i < NUM_URBS; ++i) {
1058 if (ATEN2011_port->write_urb_pool[i]->status == -EINPROGRESS) {
1059 chars += URB_TRANSFER_BUFFER_SIZE;
1062 dbg("%s - returns %d", __FUNCTION__, chars);
1067 static void ATEN2011_block_until_tx_empty(struct tty_struct *tty,
1068 struct ATENINTL_port *ATEN2011_port)
1070 int timeout = HZ / 10;
1076 count = ATEN2011_chars_in_buffer(tty);
1078 /* Check for Buffer status */
1083 /* Block the thread for a while */
1084 interruptible_sleep_on_timeout(&ATEN2011_port->wait_chase,
1087 /* No activity.. count down section */
1090 dbg("%s - TIMEOUT", __FUNCTION__);
1093 /* Reset timout value back to seconds */
1099 static void ATEN2011_close(struct tty_struct *tty, struct usb_serial_port *port,
1102 struct usb_serial *serial;
1103 struct ATENINTL_serial *ATEN2011_serial;
1104 struct ATENINTL_port *ATEN2011_port;
1108 DPRINTK("%s\n", "ATEN2011_close:entering...");
1109 serial = port->serial;
1111 /* take the Adpater and port's private data */
1112 ATEN2011_serial = usb_get_serial_data(serial);
1113 ATEN2011_port = usb_get_serial_port_data(port);
1114 if ((ATEN2011_serial == NULL) || (ATEN2011_port == NULL)) {
1118 /* flush and block(wait) until tx is empty */
1119 ATEN2011_block_until_tx_empty(tty, ATEN2011_port);
1121 /* kill the ports URB's */
1122 for (no_urbs = 0; no_urbs < NUM_URBS; no_urbs++)
1123 usb_kill_urb(ATEN2011_port->write_urb_pool[no_urbs]);
1124 /* Freeing Write URBs */
1125 for (no_urbs = 0; no_urbs < NUM_URBS; ++no_urbs) {
1126 if (ATEN2011_port->write_urb_pool[no_urbs]) {
1127 if (ATEN2011_port->write_urb_pool[no_urbs]->
1129 kfree(ATEN2011_port->write_urb_pool[no_urbs]->
1131 usb_free_urb(ATEN2011_port->write_urb_pool[no_urbs]);
1134 /* While closing port, shutdown all bulk read, write *
1135 * and interrupt read if they exists */
1137 if (ATEN2011_port->write_urb) {
1138 DPRINTK("%s", "Shutdown bulk write\n");
1139 usb_kill_urb(ATEN2011_port->write_urb);
1141 if (ATEN2011_port->read_urb) {
1142 DPRINTK("%s", "Shutdown bulk read\n");
1143 usb_kill_urb(ATEN2011_port->read_urb);
1145 if ((&ATEN2011_port->control_urb)) {
1146 DPRINTK("%s", "Shutdown control read\n");
1147 /* usb_kill_urb (ATEN2011_port->control_urb); */
1151 /* if(ATEN2011_port->ctrl_buf != NULL) */
1152 /* kfree(ATEN2011_port->ctrl_buf); */
1153 /* decrement the no.of open ports counter of an individual USB-serial adapter. */
1154 ATEN2011_serial->NoOfOpenPorts--;
1155 DPRINTK("NoOfOpenPorts in close%d:in port%d\n",
1156 ATEN2011_serial->NoOfOpenPorts, port->number);
1157 if (ATEN2011_serial->NoOfOpenPorts == 0) {
1158 /* stop the stus polling here */
1159 ATEN2011_serial->status_polling_started = 0;
1160 if (ATEN2011_serial->interrupt_read_urb) {
1161 DPRINTK("%s", "Shutdown interrupt_read_urb\n");
1162 /* ATEN2011_serial->interrupt_in_buffer=NULL; */
1163 /* usb_kill_urb (ATEN2011_serial->interrupt_read_urb); */
1166 if (ATEN2011_port->write_urb) {
1167 /* if this urb had a transfer buffer already (old tx) free it */
1168 if (ATEN2011_port->write_urb->transfer_buffer != NULL) {
1169 kfree(ATEN2011_port->write_urb->transfer_buffer);
1171 usb_free_urb(ATEN2011_port->write_urb);
1173 /* clear the MCR & IER */
1175 set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
1177 set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data);
1179 ATEN2011_port->open = 0;
1180 DPRINTK("%s \n", "Leaving ............");
1184 static void ATEN2011_block_until_chase_response(struct tty_struct *tty,
1185 struct ATENINTL_port
1188 int timeout = 1 * HZ;
1193 count = ATEN2011_chars_in_buffer(tty);
1195 /* Check for Buffer status */
1197 ATEN2011_port->chaseResponsePending = 0;
1201 /* Block the thread for a while */
1202 interruptible_sleep_on_timeout(&ATEN2011_port->wait_chase,
1204 /* No activity.. count down section */
1207 dbg("%s - TIMEOUT", __FUNCTION__);
1210 /* Reset timout value back to seconds */
1217 static void ATEN2011_break(struct tty_struct *tty, int break_state)
1219 struct usb_serial_port *port = tty->driver_data;
1221 struct usb_serial *serial;
1222 struct ATENINTL_serial *ATEN2011_serial;
1223 struct ATENINTL_port *ATEN2011_port;
1225 DPRINTK("%s \n", "Entering ...........");
1226 DPRINTK("ATEN2011_break: Start\n");
1228 serial = port->serial;
1230 ATEN2011_serial = usb_get_serial_data(serial);
1231 ATEN2011_port = usb_get_serial_port_data(port);
1233 if ((ATEN2011_serial == NULL) || (ATEN2011_port == NULL)) {
1237 /* flush and chase */
1238 ATEN2011_port->chaseResponsePending = 1;
1242 /* flush and block until tx is empty */
1243 ATEN2011_block_until_chase_response(tty, ATEN2011_port);
1246 if (break_state == -1) {
1247 data = ATEN2011_port->shadowLCR | LCR_SET_BREAK;
1249 data = ATEN2011_port->shadowLCR & ~LCR_SET_BREAK;
1252 ATEN2011_port->shadowLCR = data;
1253 DPRINTK("ATEN2011_break ATEN2011_port->shadowLCR is %x\n",
1254 ATEN2011_port->shadowLCR);
1255 set_uart_reg(port, LINE_CONTROL_REGISTER, ATEN2011_port->shadowLCR);
1260 static int ATEN2011_write_room(struct tty_struct *tty)
1262 struct usb_serial_port *port = tty->driver_data;
1265 struct ATENINTL_port *ATEN2011_port;
1267 ATEN2011_port = usb_get_serial_port_data(port);
1268 if (ATEN2011_port == NULL) {
1269 DPRINTK("%s \n", "ATEN2011_break:leaving ...........");
1273 for (i = 0; i < NUM_URBS; ++i) {
1274 if (ATEN2011_port->write_urb_pool[i]->status != -EINPROGRESS) {
1275 room += URB_TRANSFER_BUFFER_SIZE;
1279 dbg("%s - returns %d", __FUNCTION__, room);
1284 static int ATEN2011_write(struct tty_struct *tty, struct usb_serial_port *port,
1285 const unsigned char *data, int count)
1293 struct ATENINTL_port *ATEN2011_port;
1294 struct usb_serial *serial;
1295 struct ATENINTL_serial *ATEN2011_serial;
1297 const unsigned char *current_position = data;
1298 unsigned char *data1;
1299 DPRINTK("%s \n", "entering ...........");
1301 serial = port->serial;
1303 ATEN2011_port = usb_get_serial_port_data(port);
1304 if (ATEN2011_port == NULL) {
1305 DPRINTK("%s", "ATEN2011_port is NULL\n");
1309 ATEN2011_serial = usb_get_serial_data(serial);
1310 if (ATEN2011_serial == NULL) {
1311 DPRINTK("%s", "ATEN2011_serial is NULL \n");
1315 /* try to find a free urb in the list */
1318 for (i = 0; i < NUM_URBS; ++i) {
1319 if (ATEN2011_port->write_urb_pool[i]->status != -EINPROGRESS) {
1320 urb = ATEN2011_port->write_urb_pool[i];
1321 DPRINTK("\nURB:%d", i);
1327 dbg("%s - no more free urbs", __FUNCTION__);
1331 if (urb->transfer_buffer == NULL) {
1332 urb->transfer_buffer =
1333 kmalloc(URB_TRANSFER_BUFFER_SIZE, GFP_KERNEL);
1335 if (urb->transfer_buffer == NULL) {
1336 err("%s no more kernel memory...", __FUNCTION__);
1340 transfer_size = min(count, URB_TRANSFER_BUFFER_SIZE);
1342 memcpy(urb->transfer_buffer, current_position, transfer_size);
1343 /* usb_serial_debug_data (__FILE__, __FUNCTION__, transfer_size, urb->transfer_buffer); */
1345 /* fill urb with data and submit */
1346 minor = port->serial->minor;
1347 if (minor == SERIAL_TTY_NO_MINOR) ;
1349 if ((ATEN2011_serial->ATEN2011_spectrum_2or4ports == 2)
1350 && (((__u16) port->number - (__u16) (minor)) != 0)) {
1351 usb_fill_bulk_urb(urb, ATEN2011_serial->serial->dev,
1352 usb_sndbulkpipe(ATEN2011_serial->serial->dev,
1354 bulk_out_endpointAddress) +
1355 2), urb->transfer_buffer,
1357 ATEN2011_bulk_out_data_callback,
1361 usb_fill_bulk_urb(urb,
1362 ATEN2011_serial->serial->dev,
1363 usb_sndbulkpipe(ATEN2011_serial->serial->dev,
1365 bulk_out_endpointAddress),
1366 urb->transfer_buffer, transfer_size,
1367 ATEN2011_bulk_out_data_callback,
1370 data1 = urb->transfer_buffer;
1371 DPRINTK("\nbulkout endpoint is %d", port->bulk_out_endpointAddress);
1372 /* for(i=0;i < urb->actual_length;i++) */
1373 /* DPRINTK("Data is %c\n ",data1[i]); */
1375 /* send it down the pipe */
1376 status = usb_submit_urb(urb, GFP_ATOMIC);
1379 err("%s - usb_submit_urb(write bulk) failed with status = %d",
1380 __FUNCTION__, status);
1381 bytes_sent = status;
1384 bytes_sent = transfer_size;
1385 ATEN2011_port->icount.tx += transfer_size;
1386 DPRINTK("ATEN2011_port->icount.tx is %d:\n", ATEN2011_port->icount.tx);
1393 static void ATEN2011_throttle(struct tty_struct *tty)
1395 struct usb_serial_port *port = tty->driver_data;
1396 struct ATENINTL_port *ATEN2011_port;
1399 DPRINTK("- port %d\n", port->number);
1401 ATEN2011_port = usb_get_serial_port_data(port);
1403 if (ATEN2011_port == NULL)
1406 if (!ATEN2011_port->open) {
1407 DPRINTK("%s\n", "port not opened");
1411 DPRINTK("%s", "Entering .......... \n");
1414 dbg("%s - no tty available", __FUNCTION__);
1418 /* if we are implementing XON/XOFF, send the stop character */
1420 unsigned char stop_char = STOP_CHAR(tty);
1421 status = ATEN2011_write(tty, port, &stop_char, 1);
1427 /* if we are implementing RTS/CTS, toggle that line */
1428 if (tty->termios->c_cflag & CRTSCTS) {
1429 ATEN2011_port->shadowMCR &= ~MCR_RTS;
1430 status = set_uart_reg(port, MODEM_CONTROL_REGISTER,
1431 ATEN2011_port->shadowMCR);
1441 static void ATEN2011_unthrottle(struct tty_struct *tty)
1443 struct usb_serial_port *port = tty->driver_data;
1445 struct ATENINTL_port *ATEN2011_port = usb_get_serial_port_data(port);
1447 if (ATEN2011_port == NULL)
1450 if (!ATEN2011_port->open) {
1451 dbg("%s - port not opened", __FUNCTION__);
1455 DPRINTK("%s", "Entering .......... \n");
1458 dbg("%s - no tty available", __FUNCTION__);
1462 /* if we are implementing XON/XOFF, send the start character */
1464 unsigned char start_char = START_CHAR(tty);
1465 status = ATEN2011_write(tty, port, &start_char, 1);
1471 /* if we are implementing RTS/CTS, toggle that line */
1472 if (tty->termios->c_cflag & CRTSCTS) {
1473 ATEN2011_port->shadowMCR |= MCR_RTS;
1474 status = set_uart_reg(port, MODEM_CONTROL_REGISTER,
1475 ATEN2011_port->shadowMCR);
1484 static int ATEN2011_tiocmget(struct tty_struct *tty, struct file *file)
1486 struct usb_serial_port *port = tty->driver_data;
1487 struct ATENINTL_port *ATEN2011_port;
1488 unsigned int result;
1491 /* unsigned int mcr; */
1493 ATEN2011_port = usb_get_serial_port_data(port);
1495 DPRINTK("%s - port %d", __FUNCTION__, port->number);
1497 if (ATEN2011_port == NULL)
1500 status = get_uart_reg(port, MODEM_STATUS_REGISTER, &msr);
1501 status = get_uart_reg(port, MODEM_CONTROL_REGISTER, &mcr);
1502 /* mcr = ATEN2011_port->shadowMCR; */
1503 /* COMMENT2: the Fallowing three line are commented for updating only MSR values */
1504 result = ((mcr & MCR_DTR) ? TIOCM_DTR : 0)
1505 | ((mcr & MCR_RTS) ? TIOCM_RTS : 0)
1506 | ((mcr & MCR_LOOPBACK) ? TIOCM_LOOP : 0)
1507 | ((msr & ATEN2011_MSR_CTS) ? TIOCM_CTS : 0)
1508 | ((msr & ATEN2011_MSR_CD) ? TIOCM_CAR : 0)
1509 | ((msr & ATEN2011_MSR_RI) ? TIOCM_RI : 0)
1510 | ((msr & ATEN2011_MSR_DSR) ? TIOCM_DSR : 0);
1512 DPRINTK("%s - 0x%04X", __FUNCTION__, result);
1517 static int ATEN2011_tiocmset(struct tty_struct *tty, struct file *file,
1518 unsigned int set, unsigned int clear)
1520 struct usb_serial_port *port = tty->driver_data;
1521 struct ATENINTL_port *ATEN2011_port;
1523 unsigned int status;
1525 DPRINTK("%s - port %d", __FUNCTION__, port->number);
1527 ATEN2011_port = usb_get_serial_port_data(port);
1529 if (ATEN2011_port == NULL)
1532 mcr = ATEN2011_port->shadowMCR;
1533 if (clear & TIOCM_RTS)
1535 if (clear & TIOCM_DTR)
1537 if (clear & TIOCM_LOOP)
1538 mcr &= ~MCR_LOOPBACK;
1540 if (set & TIOCM_RTS)
1542 if (set & TIOCM_DTR)
1544 if (set & TIOCM_LOOP)
1545 mcr |= MCR_LOOPBACK;
1547 ATEN2011_port->shadowMCR = mcr;
1549 status = set_uart_reg(port, MODEM_CONTROL_REGISTER, mcr);
1551 DPRINTK("setting MODEM_CONTROL_REGISTER Failed\n");
1558 static void ATEN2011_set_termios(struct tty_struct *tty,
1559 struct usb_serial_port *port,
1560 struct ktermios *old_termios)
1564 struct usb_serial *serial;
1565 struct ATENINTL_port *ATEN2011_port;
1567 DPRINTK("ATEN2011_set_termios: START\n");
1569 serial = port->serial;
1571 ATEN2011_port = usb_get_serial_port_data(port);
1573 if (ATEN2011_port == NULL)
1576 if (!ATEN2011_port->open) {
1577 dbg("%s - port not opened", __FUNCTION__);
1581 DPRINTK("%s\n", "setting termios - ");
1583 cflag = tty->termios->c_cflag;
1586 DPRINTK("%s %s\n", __FUNCTION__, "cflag is NULL");
1590 /* check that they really want us to change something */
1592 if ((cflag == old_termios->c_cflag) &&
1593 (RELEVANT_IFLAG(tty->termios->c_iflag) ==
1594 RELEVANT_IFLAG(old_termios->c_iflag))) {
1595 DPRINTK("%s\n", "Nothing to change");
1600 dbg("%s - clfag %08x iflag %08x", __FUNCTION__,
1601 tty->termios->c_cflag, RELEVANT_IFLAG(tty->termios->c_iflag));
1604 dbg("%s - old clfag %08x old iflag %08x", __FUNCTION__,
1605 old_termios->c_cflag, RELEVANT_IFLAG(old_termios->c_iflag));
1608 dbg("%s - port %d", __FUNCTION__, port->number);
1610 /* change the port settings to the new ones specified */
1612 ATEN2011_change_port_settings(tty, ATEN2011_port, old_termios);
1614 if (!ATEN2011_port->read_urb) {
1615 DPRINTK("%s", "URB KILLED !!!!!\n");
1619 if (ATEN2011_port->read_urb->status != -EINPROGRESS) {
1620 ATEN2011_port->read_urb->dev = serial->dev;
1621 status = usb_submit_urb(ATEN2011_port->read_urb, GFP_ATOMIC);
1624 (" usb_submit_urb(read bulk) failed, status = %d",
1631 static int get_lsr_info(struct tty_struct *tty,
1632 struct ATENINTL_port *ATEN2011_port,
1633 unsigned int __user *value)
1636 unsigned int result = 0;
1638 count = ATEN2011_chars_in_buffer(tty);
1640 dbg("%s -- Empty", __FUNCTION__);
1641 result = TIOCSER_TEMT;
1644 if (copy_to_user(value, &result, sizeof(int)))
1649 static int get_number_bytes_avail(struct tty_struct *tty,
1650 struct ATENINTL_port *ATEN2011_port,
1651 unsigned int __user *value)
1653 unsigned int result = 0;
1656 return -ENOIOCTLCMD;
1658 result = tty->read_cnt;
1660 dbg("%s(%d) = %d", __FUNCTION__, ATEN2011_port->port->number, result);
1661 if (copy_to_user(value, &result, sizeof(int)))
1664 return -ENOIOCTLCMD;
1667 static int set_modem_info(struct ATENINTL_port *ATEN2011_port, unsigned int cmd,
1668 unsigned int __user *value)
1674 struct usb_serial_port *port;
1676 if (ATEN2011_port == NULL)
1679 port = (struct usb_serial_port *)ATEN2011_port->port;
1681 mcr = ATEN2011_port->shadowMCR;
1683 if (copy_from_user(&arg, value, sizeof(int)))
1688 if (arg & TIOCM_RTS)
1690 if (arg & TIOCM_DTR)
1692 if (arg & TIOCM_LOOP)
1693 mcr |= MCR_LOOPBACK;
1697 if (arg & TIOCM_RTS)
1699 if (arg & TIOCM_DTR)
1701 if (arg & TIOCM_LOOP)
1702 mcr &= ~MCR_LOOPBACK;
1706 /* turn off the RTS and DTR and LOOPBACK
1707 * and then only turn on what was asked to */
1708 mcr &= ~(MCR_RTS | MCR_DTR | MCR_LOOPBACK);
1709 mcr |= ((arg & TIOCM_RTS) ? MCR_RTS : 0);
1710 mcr |= ((arg & TIOCM_DTR) ? MCR_DTR : 0);
1711 mcr |= ((arg & TIOCM_LOOP) ? MCR_LOOPBACK : 0);
1715 ATEN2011_port->shadowMCR = mcr;
1717 Data = ATEN2011_port->shadowMCR;
1718 status = set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
1720 DPRINTK("setting MODEM_CONTROL_REGISTER Failed\n");
1727 static int get_modem_info(struct ATENINTL_port *ATEN2011_port,
1728 unsigned int __user *value)
1730 unsigned int result = 0;
1732 unsigned int mcr = ATEN2011_port->shadowMCR;
1735 status = get_uart_reg(ATEN2011_port->port, MODEM_STATUS_REGISTER, &msr);
1736 result = ((mcr & MCR_DTR) ? TIOCM_DTR : 0) /* 0x002 */
1737 |((mcr & MCR_RTS) ? TIOCM_RTS : 0) /* 0x004 */
1738 |((msr & ATEN2011_MSR_CTS) ? TIOCM_CTS : 0) /* 0x020 */
1739 |((msr & ATEN2011_MSR_CD) ? TIOCM_CAR : 0) /* 0x040 */
1740 |((msr & ATEN2011_MSR_RI) ? TIOCM_RI : 0) /* 0x080 */
1741 |((msr & ATEN2011_MSR_DSR) ? TIOCM_DSR : 0); /* 0x100 */
1743 dbg("%s -- %x", __FUNCTION__, result);
1745 if (copy_to_user(value, &result, sizeof(int)))
1750 static int get_serial_info(struct ATENINTL_port *ATEN2011_port,
1751 struct serial_struct __user *retinfo)
1753 struct serial_struct tmp;
1755 if (ATEN2011_port == NULL)
1761 memset(&tmp, 0, sizeof(tmp));
1763 tmp.type = PORT_16550A;
1764 tmp.line = ATEN2011_port->port->serial->minor;
1765 if (tmp.line == SERIAL_TTY_NO_MINOR)
1767 tmp.port = ATEN2011_port->port->number;
1769 tmp.flags = ASYNC_SKIP_TEST | ASYNC_AUTO_IRQ;
1770 tmp.xmit_fifo_size = NUM_URBS * URB_TRANSFER_BUFFER_SIZE;
1771 tmp.baud_base = 9600;
1772 tmp.close_delay = 5 * HZ;
1773 tmp.closing_wait = 30 * HZ;
1775 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
1780 static int ATEN2011_ioctl(struct tty_struct *tty, struct file *file,
1781 unsigned int cmd, unsigned long arg)
1783 struct usb_serial_port *port = tty->driver_data;
1784 struct ATENINTL_port *ATEN2011_port;
1785 struct async_icount cnow;
1786 struct async_icount cprev;
1787 struct serial_icounter_struct icount;
1789 unsigned int __user *user_arg = (unsigned int __user *)arg;
1791 ATEN2011_port = usb_get_serial_port_data(port);
1793 if (ATEN2011_port == NULL)
1796 dbg("%s - port %d, cmd = 0x%x", __FUNCTION__, port->number, cmd);
1799 /* return number of bytes available */
1802 dbg("%s (%d) TIOCINQ", __FUNCTION__, port->number);
1803 return get_number_bytes_avail(tty, ATEN2011_port, user_arg);
1807 dbg("%s (%d) TIOCOUTQ", __FUNCTION__, port->number);
1808 return put_user(ATEN2011_chars_in_buffer(tty), user_arg);
1812 dbg("%s (%d) TIOCSERGETLSR", __FUNCTION__, port->number);
1813 return get_lsr_info(tty, ATEN2011_port, user_arg);
1819 dbg("%s (%d) TIOCMSET/TIOCMBIC/TIOCMSET", __FUNCTION__,
1821 ATENret = set_modem_info(ATEN2011_port, cmd, user_arg);
1825 dbg("%s (%d) TIOCMGET", __FUNCTION__, port->number);
1826 return get_modem_info(ATEN2011_port, user_arg);
1829 dbg("%s (%d) TIOCGSERIAL", __FUNCTION__, port->number);
1830 return get_serial_info(ATEN2011_port,
1831 (struct serial_struct __user *)arg);
1834 dbg("%s (%d) TIOCSSERIAL", __FUNCTION__, port->number);
1838 dbg("%s (%d) TIOCMIWAIT", __FUNCTION__, port->number);
1839 cprev = ATEN2011_port->icount;
1841 /* see if a signal did it */
1842 if (signal_pending(current))
1843 return -ERESTARTSYS;
1844 cnow = ATEN2011_port->icount;
1845 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
1846 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts)
1847 return -EIO; /* no change => error */
1848 if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
1849 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
1850 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
1851 ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts))) {
1860 cnow = ATEN2011_port->icount;
1861 icount.cts = cnow.cts;
1862 icount.dsr = cnow.dsr;
1863 icount.rng = cnow.rng;
1864 icount.dcd = cnow.dcd;
1865 icount.rx = cnow.rx;
1866 icount.tx = cnow.tx;
1867 icount.frame = cnow.frame;
1868 icount.overrun = cnow.overrun;
1869 icount.parity = cnow.parity;
1870 icount.brk = cnow.brk;
1871 icount.buf_overrun = cnow.buf_overrun;
1873 dbg("%s (%d) TIOCGICOUNT RX=%d, TX=%d", __FUNCTION__,
1874 port->number, icount.rx, icount.tx);
1875 if (copy_to_user((void __user *)arg, &icount, sizeof(icount)))
1883 return -ENOIOCTLCMD;
1886 static int ATEN2011_calc_baud_rate_divisor(int baudRate, int *divisor,
1887 __u16 * clk_sel_val)
1889 dbg("%s - %d", __FUNCTION__, baudRate);
1891 if (baudRate <= 115200) {
1892 *divisor = 115200 / baudRate;
1895 if ((baudRate > 115200) && (baudRate <= 230400)) {
1896 *divisor = 230400 / baudRate;
1897 *clk_sel_val = 0x10;
1898 } else if ((baudRate > 230400) && (baudRate <= 403200)) {
1899 *divisor = 403200 / baudRate;
1900 *clk_sel_val = 0x20;
1901 } else if ((baudRate > 403200) && (baudRate <= 460800)) {
1902 *divisor = 460800 / baudRate;
1903 *clk_sel_val = 0x30;
1904 } else if ((baudRate > 460800) && (baudRate <= 806400)) {
1905 *divisor = 806400 / baudRate;
1906 *clk_sel_val = 0x40;
1907 } else if ((baudRate > 806400) && (baudRate <= 921600)) {
1908 *divisor = 921600 / baudRate;
1909 *clk_sel_val = 0x50;
1910 } else if ((baudRate > 921600) && (baudRate <= 1572864)) {
1911 *divisor = 1572864 / baudRate;
1912 *clk_sel_val = 0x60;
1913 } else if ((baudRate > 1572864) && (baudRate <= 3145728)) {
1914 *divisor = 3145728 / baudRate;
1915 *clk_sel_val = 0x70;
1920 static int ATEN2011_send_cmd_write_baud_rate(struct ATENINTL_port
1921 *ATEN2011_port, int baudRate)
1926 unsigned char number;
1928 struct usb_serial_port *port;
1931 if (ATEN2011_port == NULL)
1934 port = (struct usb_serial_port *)ATEN2011_port->port;
1936 DPRINTK("%s", "Entering .......... \n");
1938 minor = ATEN2011_port->port->serial->minor;
1939 if (minor == SERIAL_TTY_NO_MINOR)
1941 number = ATEN2011_port->port->number - minor;
1943 dbg("%s - port = %d, baud = %d", __FUNCTION__,
1944 ATEN2011_port->port->number, baudRate);
1945 /* reset clk_uart_sel in spregOffset */
1946 if (baudRate > 115200) {
1947 #ifdef HW_flow_control
1949 * NOTE: need to see the pther register to modify
1950 * setting h/w flow control bit to 1;
1952 /* Data = ATEN2011_port->shadowMCR; */
1954 ATEN2011_port->shadowMCR = Data;
1955 status = set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
1957 DPRINTK("Writing spreg failed in set_serial_baud\n");
1963 #ifdef HW_flow_control
1964 /* setting h/w flow control bit to 0; */
1965 /* Data = ATEN2011_port->shadowMCR; */
1967 ATEN2011_port->shadowMCR = Data;
1968 status = set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
1970 DPRINTK("Writing spreg failed in set_serial_baud\n");
1977 if (1) /* baudRate <= 115200) */
1982 ATEN2011_calc_baud_rate_divisor(baudRate, &divisor,
1984 status = get_reg_sync(port, ATEN2011_port->SpRegOffset, &Data);
1986 DPRINTK("reading spreg failed in set_serial_baud\n");
1989 Data = (Data & 0x8f) | clk_sel_val;
1990 status = set_reg_sync(port, ATEN2011_port->SpRegOffset, Data);
1992 DPRINTK("Writing spreg failed in set_serial_baud\n");
1995 /* Calculate the Divisor */
1998 err("%s - bad baud rate", __FUNCTION__);
1999 DPRINTK("%s\n", "bad baud rate");
2002 /* Enable access to divisor latch */
2003 Data = ATEN2011_port->shadowLCR | SERIAL_LCR_DLAB;
2004 ATEN2011_port->shadowLCR = Data;
2005 set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
2007 /* Write the divisor */
2008 Data = (unsigned char)(divisor & 0xff);
2009 DPRINTK("set_serial_baud Value to write DLL is %x\n", Data);
2010 set_uart_reg(port, DIVISOR_LATCH_LSB, Data);
2012 Data = (unsigned char)((divisor & 0xff00) >> 8);
2013 DPRINTK("set_serial_baud Value to write DLM is %x\n", Data);
2014 set_uart_reg(port, DIVISOR_LATCH_MSB, Data);
2016 /* Disable access to divisor latch */
2017 Data = ATEN2011_port->shadowLCR & ~SERIAL_LCR_DLAB;
2018 ATEN2011_port->shadowLCR = Data;
2019 set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
2026 static void ATEN2011_change_port_settings(struct tty_struct *tty,
2027 struct ATENINTL_port *ATEN2011_port,
2028 struct ktermios *old_termios)
2038 struct usb_serial_port *port;
2039 struct usb_serial *serial;
2041 if (ATEN2011_port == NULL)
2044 port = (struct usb_serial_port *)ATEN2011_port->port;
2046 serial = port->serial;
2048 dbg("%s - port %d", __FUNCTION__, ATEN2011_port->port->number);
2050 if (!ATEN2011_port->open) {
2051 dbg("%s - port not opened", __FUNCTION__);
2055 if ((!tty) || (!tty->termios)) {
2056 dbg("%s - no tty structures", __FUNCTION__);
2060 DPRINTK("%s", "Entering .......... \n");
2064 lParity = LCR_PAR_NONE;
2066 cflag = tty->termios->c_cflag;
2067 iflag = tty->termios->c_iflag;
2069 /* Change the number of bits */
2071 /* 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 */
2072 /* if(cflag & CSIZE) */
2074 switch (cflag & CSIZE) {
2092 /* Change the Parity bit */
2093 if (cflag & PARENB) {
2094 if (cflag & PARODD) {
2095 lParity = LCR_PAR_ODD;
2096 dbg("%s - parity = odd", __FUNCTION__);
2098 lParity = LCR_PAR_EVEN;
2099 dbg("%s - parity = even", __FUNCTION__);
2103 dbg("%s - parity = none", __FUNCTION__);
2106 if (cflag & CMSPAR) {
2107 lParity = lParity | 0x20;
2110 /* Change the Stop bit */
2111 if (cflag & CSTOPB) {
2113 dbg("%s - stop bits = 2", __FUNCTION__);
2116 dbg("%s - stop bits = 1", __FUNCTION__);
2119 /* Update the LCR with the correct value */
2120 ATEN2011_port->shadowLCR &=
2121 ~(LCR_BITS_MASK | LCR_STOP_MASK | LCR_PAR_MASK);
2122 ATEN2011_port->shadowLCR |= (lData | lParity | lStop);
2125 ("ATEN2011_change_port_settings ATEN2011_port->shadowLCR is %x\n",
2126 ATEN2011_port->shadowLCR);
2127 /* Disable Interrupts */
2129 set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data);
2132 set_uart_reg(port, FIFO_CONTROL_REGISTER, Data);
2135 set_uart_reg(port, FIFO_CONTROL_REGISTER, Data);
2137 /* Send the updated LCR value to the ATEN2011 */
2138 Data = ATEN2011_port->shadowLCR;
2140 set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
2143 ATEN2011_port->shadowMCR = Data;
2144 set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
2146 set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
2148 /* set up the MCR register and send it to the ATEN2011 */
2150 ATEN2011_port->shadowMCR = MCR_MASTER_IE;
2151 if (cflag & CBAUD) {
2152 ATEN2011_port->shadowMCR |= (MCR_DTR | MCR_RTS);
2155 if (cflag & CRTSCTS) {
2156 ATEN2011_port->shadowMCR |= (MCR_XON_ANY);
2159 ATEN2011_port->shadowMCR &= ~(MCR_XON_ANY);
2162 Data = ATEN2011_port->shadowMCR;
2163 set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
2165 /* Determine divisor based on baud rate */
2166 baud = tty_get_baud_rate(tty);
2169 /* pick a default, any default... */
2170 DPRINTK("%s\n", "Picked default baud...");
2174 dbg("%s - baud rate = %d", __FUNCTION__, baud);
2175 status = ATEN2011_send_cmd_write_baud_rate(ATEN2011_port, baud);
2177 /* Enable Interrupts */
2179 set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data);
2181 if (ATEN2011_port->read_urb->status != -EINPROGRESS) {
2182 ATEN2011_port->read_urb->dev = serial->dev;
2184 status = usb_submit_urb(ATEN2011_port->read_urb, GFP_ATOMIC);
2188 (" usb_submit_urb(read bulk) failed, status = %d",
2193 ("ATEN2011_change_port_settings ATEN2011_port->shadowLCR is End %x\n",
2194 ATEN2011_port->shadowLCR);
2199 static int ATEN2011_calc_num_ports(struct usb_serial *serial)
2204 int ATEN2011_2or4ports;
2205 ret = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
2206 ATEN_RDREQ, ATEN_RD_RTYPE, 0, GPIO_REGISTER,
2207 &Data, VENDOR_READ_LENGTH, ATEN_WDR_TIMEOUT);
2209 /* ghostgum: here is where the problem appears to bet */
2210 /* Which of the following are needed? */
2211 /* Greg used the serial->type->num_ports=2 */
2212 /* But the code in the ATEN2011_open relies on serial->num_ports=2 */
2213 if ((Data & 0x01) == 0) {
2214 ATEN2011_2or4ports = 2;
2215 serial->type->num_ports = 2;
2216 serial->num_ports = 2;
2218 /* else if(serial->interface->cur_altsetting->desc.bNumEndpoints == 9) */
2220 ATEN2011_2or4ports = 4;
2221 serial->type->num_ports = 4;
2222 serial->num_ports = 4;
2226 return ATEN2011_2or4ports;
2229 static int ATEN2011_startup(struct usb_serial *serial)
2231 struct ATENINTL_serial *ATEN2011_serial;
2232 struct ATENINTL_port *ATEN2011_port;
2233 struct usb_device *dev;
2238 DPRINTK("%s \n", " ATEN2011_startup :entering..........");
2241 DPRINTK("%s\n", "Invalid Handler");
2247 DPRINTK("%s\n", "Entering...");
2249 /* create our private serial structure */
2250 ATEN2011_serial = kzalloc(sizeof(struct ATENINTL_serial), GFP_KERNEL);
2251 if (ATEN2011_serial == NULL) {
2252 err("%s - Out of memory", __FUNCTION__);
2256 /* resetting the private structure field values to zero */
2257 memset(ATEN2011_serial, 0, sizeof(struct ATENINTL_serial));
2259 ATEN2011_serial->serial = serial;
2260 /* initilize status polling flag to 0 */
2261 ATEN2011_serial->status_polling_started = 0;
2263 usb_set_serial_data(serial, ATEN2011_serial);
2264 ATEN2011_serial->ATEN2011_spectrum_2or4ports =
2265 ATEN2011_calc_num_ports(serial);
2266 /* we set up the pointers to the endpoints in the ATEN2011_open *
2267 * function, as the structures aren't created yet. */
2269 /* set up port private structures */
2270 for (i = 0; i < serial->num_ports; ++i) {
2272 kmalloc(sizeof(struct ATENINTL_port), GFP_KERNEL);
2273 if (ATEN2011_port == NULL) {
2274 err("%s - Out of memory", __FUNCTION__);
2275 usb_set_serial_data(serial, NULL);
2276 kfree(ATEN2011_serial);
2279 memset(ATEN2011_port, 0, sizeof(struct ATENINTL_port));
2282 * Initialize all port interrupt end point to port 0
2283 * int endpoint. Our device has only one interrupt end point
2284 * comman to all port
2286 /* serial->port[i]->interrupt_in_endpointAddress = serial->port[0]->interrupt_in_endpointAddress; */
2288 ATEN2011_port->port = serial->port[i];
2289 usb_set_serial_port_data(serial->port[i], ATEN2011_port);
2291 minor = serial->port[i]->serial->minor;
2292 if (minor == SERIAL_TTY_NO_MINOR)
2294 ATEN2011_port->port_num =
2295 ((serial->port[i]->number - minor) + 1);
2297 if (ATEN2011_port->port_num == 1) {
2298 ATEN2011_port->SpRegOffset = 0x0;
2299 ATEN2011_port->ControlRegOffset = 0x1;
2300 ATEN2011_port->DcrRegOffset = 0x4;
2301 } else if ((ATEN2011_port->port_num == 2)
2302 && (ATEN2011_serial->ATEN2011_spectrum_2or4ports ==
2304 ATEN2011_port->SpRegOffset = 0x8;
2305 ATEN2011_port->ControlRegOffset = 0x9;
2306 ATEN2011_port->DcrRegOffset = 0x16;
2307 } else if ((ATEN2011_port->port_num == 2)
2308 && (ATEN2011_serial->ATEN2011_spectrum_2or4ports ==
2310 ATEN2011_port->SpRegOffset = 0xa;
2311 ATEN2011_port->ControlRegOffset = 0xb;
2312 ATEN2011_port->DcrRegOffset = 0x19;
2313 } else if ((ATEN2011_port->port_num == 3)
2314 && (ATEN2011_serial->ATEN2011_spectrum_2or4ports ==
2316 ATEN2011_port->SpRegOffset = 0xa;
2317 ATEN2011_port->ControlRegOffset = 0xb;
2318 ATEN2011_port->DcrRegOffset = 0x19;
2319 } else if ((ATEN2011_port->port_num == 4)
2320 && (ATEN2011_serial->ATEN2011_spectrum_2or4ports ==
2322 ATEN2011_port->SpRegOffset = 0xc;
2323 ATEN2011_port->ControlRegOffset = 0xd;
2324 ATEN2011_port->DcrRegOffset = 0x1c;
2327 usb_set_serial_port_data(serial->port[i], ATEN2011_port);
2329 /* enable rx_disable bit in control register */
2331 status = get_reg_sync(serial->port[i],
2332 ATEN2011_port->ControlRegOffset, &Data);
2334 DPRINTK("Reading ControlReg failed status-0x%x\n",
2339 ("ControlReg Reading success val is %x, status%d\n",
2341 Data |= 0x08; /* setting driver done bit */
2342 Data |= 0x04; /* sp1_bit to have cts change reflect in modem status reg */
2344 /* Data |= 0x20; */ /* rx_disable bit */
2345 status = set_reg_sync(serial->port[i],
2346 ATEN2011_port->ControlRegOffset, Data);
2349 ("Writing ControlReg failed(rx_disable) status-0x%x\n",
2354 ("ControlReg Writing success(rx_disable) status%d\n",
2358 * Write default values in DCR (i.e 0x01 in DCR0, 0x05 in DCR2
2362 status = set_reg_sync(serial->port[i],
2363 (__u16)(ATEN2011_port->DcrRegOffset + 0),
2366 DPRINTK("Writing DCR0 failed status-0x%x\n", status);
2369 DPRINTK("DCR0 Writing success status%d\n", status);
2372 status = set_reg_sync(serial->port[i],
2373 (__u16)(ATEN2011_port->DcrRegOffset + 1),
2376 DPRINTK("Writing DCR1 failed status-0x%x\n", status);
2379 DPRINTK("DCR1 Writing success status%d\n", status);
2382 status = set_reg_sync(serial->port[i],
2383 (__u16)(ATEN2011_port->DcrRegOffset + 2),
2386 DPRINTK("Writing DCR2 failed status-0x%x\n", status);
2389 DPRINTK("DCR2 Writing success status%d\n", status);
2391 /* write values in clkstart0x0 and clkmulti 0x20 */
2393 status = set_reg_sync(serial->port[i], CLK_START_VALUE_REGISTER,
2397 ("Writing CLK_START_VALUE_REGISTER failed status-0x%x\n",
2402 ("CLK_START_VALUE_REGISTER Writing success status%d\n",
2406 status = set_reg_sync(serial->port[i], CLK_MULTI_REGISTER,
2410 ("Writing CLK_MULTI_REGISTER failed status-0x%x\n",
2414 DPRINTK("CLK_MULTI_REGISTER Writing success status%d\n",
2417 /* Zero Length flag register */
2418 if ((ATEN2011_port->port_num != 1)
2419 && (ATEN2011_serial->ATEN2011_spectrum_2or4ports == 2)) {
2422 status = set_reg_sync(serial->port[i],
2423 (__u16)(ZLP_REG1 + ((__u16)ATEN2011_port->port_num)),
2425 DPRINTK("ZLIP offset%x\n",
2427 ((__u16) ATEN2011_port->port_num)));
2430 ("Writing ZLP_REG%d failed status-0x%x\n",
2434 DPRINTK("ZLP_REG%d Writing success status%d\n",
2438 status = set_reg_sync(serial->port[i],
2439 (__u16)(ZLP_REG1 + ((__u16)ATEN2011_port->port_num) - 0x1),
2441 DPRINTK("ZLIP offset%x\n",
2443 ((__u16) ATEN2011_port->port_num) -
2447 ("Writing ZLP_REG%d failed status-0x%x\n",
2451 DPRINTK("ZLP_REG%d Writing success status%d\n",
2455 ATEN2011_port->control_urb = usb_alloc_urb(0, GFP_ATOMIC);
2456 ATEN2011_port->ctrl_buf = kmalloc(16, GFP_KERNEL);
2460 /* Zero Length flag enable */
2462 status = set_reg_sync(serial->port[0], ZLP_REG5, Data);
2464 DPRINTK("Writing ZLP_REG5 failed status-0x%x\n", status);
2467 DPRINTK("ZLP_REG5 Writing success status%d\n", status);
2469 /* setting configuration feature to one */
2470 usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
2471 (__u8) 0x03, 0x00, 0x01, 0x00, NULL, 0x00, 5 * HZ);
2475 static void ATEN2011_shutdown(struct usb_serial *serial)
2478 struct ATENINTL_port *ATEN2011_port;
2479 DPRINTK("%s \n", " shutdown :entering..........");
2482 DPRINTK("%s", "Invalid Handler \n");
2486 /* check for the ports to be closed,close the ports and disconnect */
2488 /* free private structure allocated for serial port *
2489 * stop reads and writes on all ports */
2491 for (i = 0; i < serial->num_ports; ++i) {
2492 ATEN2011_port = usb_get_serial_port_data(serial->port[i]);
2493 kfree(ATEN2011_port->ctrl_buf);
2494 usb_kill_urb(ATEN2011_port->control_urb);
2495 kfree(ATEN2011_port);
2496 usb_set_serial_port_data(serial->port[i], NULL);
2499 /* free private structure allocated for serial device */
2501 kfree(usb_get_serial_data(serial));
2502 usb_set_serial_data(serial, NULL);
2504 DPRINTK("%s\n", "Thank u :: ");
2508 static struct usb_serial_driver aten_serial_driver = {
2510 .owner = THIS_MODULE,
2513 .description = DRIVER_DESC,
2514 .id_table = id_table,
2515 .open = ATEN2011_open,
2516 .close = ATEN2011_close,
2517 .write = ATEN2011_write,
2518 .write_room = ATEN2011_write_room,
2519 .chars_in_buffer = ATEN2011_chars_in_buffer,
2520 .throttle = ATEN2011_throttle,
2521 .unthrottle = ATEN2011_unthrottle,
2522 .calc_num_ports = ATEN2011_calc_num_ports,
2524 .ioctl = ATEN2011_ioctl,
2525 .set_termios = ATEN2011_set_termios,
2526 .break_ctl = ATEN2011_break,
2527 .tiocmget = ATEN2011_tiocmget,
2528 .tiocmset = ATEN2011_tiocmset,
2529 .attach = ATEN2011_startup,
2530 .shutdown = ATEN2011_shutdown,
2531 .read_bulk_callback = ATEN2011_bulk_in_callback,
2532 .read_int_callback = ATEN2011_interrupt_callback,
2535 static struct usb_driver aten_driver = {
2537 .probe = usb_serial_probe,
2538 .disconnect = usb_serial_disconnect,
2539 .id_table = id_table,
2542 static int __init aten_init(void)
2546 /* Register with the usb serial */
2547 retval = usb_serial_register(&aten_serial_driver);
2551 printk(KERN_INFO KBUILD_MODNAME ":"
2552 DRIVER_DESC " " DRIVER_VERSION "\n");
2554 /* Register with the usb */
2555 retval = usb_register(&aten_driver);
2557 usb_serial_deregister(&aten_serial_driver);
2562 static void __exit aten_exit(void)
2564 usb_deregister(&aten_driver);
2565 usb_serial_deregister(&aten_serial_driver);
2568 module_init(aten_init);
2569 module_exit(aten_exit);
2571 /* Module information */
2572 MODULE_DESCRIPTION(DRIVER_DESC);
2573 MODULE_LICENSE("GPL");
2575 MODULE_PARM_DESC(debug, "Debug enabled or not");