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;
126 struct urb *write_urb_pool[NUM_URBS];
127 /* we pass a pointer to this as the arguement sent to cypress_set_termios old_termios */
128 struct ktermios tmp_termios; /* stores the old termios settings */
129 spinlock_t lock; /* private lock */
133 /* This structure holds all of the individual serial device information */
134 struct ATENINTL_serial
136 __u8 interrupt_in_endpoint; /* the interrupt endpoint handle */
137 unsigned char *interrupt_in_buffer; /* the buffer we use for the interrupt endpoint */
138 struct urb * interrupt_read_urb; /* our interrupt urb */
139 __u8 bulk_in_endpoint; /* the bulk in endpoint handle */
140 unsigned char *bulk_in_buffer; /* the buffer we use for the bulk in endpoint */
141 struct urb *read_urb; /* our bulk read urb */
142 __u8 bulk_out_endpoint; /* the bulk out endpoint handle */
143 struct usb_serial *serial; /* loop back to the owner of this object */
144 int ATEN2011_spectrum_2or4ports; //this says the number of ports in the device
145 // Indicates about the no.of opened ports of an individual USB-serial adapater.
146 unsigned int NoOfOpenPorts;
147 // a flag for Status endpoint polling
148 unsigned char status_polling_started;
151 static void ATEN2011_set_termios(struct tty_struct *tty,
152 struct usb_serial_port *port,
153 struct ktermios *old_termios);
154 static void ATEN2011_change_port_settings(struct tty_struct *tty,
155 struct ATENINTL_port *ATEN2011_port,
156 struct ktermios *old_termios);
158 /*************************************
159 * Bit definitions for each register *
160 *************************************/
161 #define LCR_BITS_5 0x00 /* 5 bits/char */
162 #define LCR_BITS_6 0x01 /* 6 bits/char */
163 #define LCR_BITS_7 0x02 /* 7 bits/char */
164 #define LCR_BITS_8 0x03 /* 8 bits/char */
165 #define LCR_BITS_MASK 0x03 /* Mask for bits/char field */
167 #define LCR_STOP_1 0x00 /* 1 stop bit */
168 #define LCR_STOP_1_5 0x04 /* 1.5 stop bits (if 5 bits/char) */
169 #define LCR_STOP_2 0x04 /* 2 stop bits (if 6-8 bits/char) */
170 #define LCR_STOP_MASK 0x04 /* Mask for stop bits field */
172 #define LCR_PAR_NONE 0x00 /* No parity */
173 #define LCR_PAR_ODD 0x08 /* Odd parity */
174 #define LCR_PAR_EVEN 0x18 /* Even parity */
175 #define LCR_PAR_MARK 0x28 /* Force parity bit to 1 */
176 #define LCR_PAR_SPACE 0x38 /* Force parity bit to 0 */
177 #define LCR_PAR_MASK 0x38 /* Mask for parity field */
179 #define LCR_SET_BREAK 0x40 /* Set Break condition */
180 #define LCR_DL_ENABLE 0x80 /* Enable access to divisor latch */
182 #define MCR_DTR 0x01 /* Assert DTR */
183 #define MCR_RTS 0x02 /* Assert RTS */
184 #define MCR_OUT1 0x04 /* Loopback only: Sets state of RI */
185 #define MCR_MASTER_IE 0x08 /* Enable interrupt outputs */
186 #define MCR_LOOPBACK 0x10 /* Set internal (digital) loopback mode */
187 #define MCR_XON_ANY 0x20 /* Enable any char to exit XOFF mode */
189 #define ATEN2011_MSR_CTS 0x10 /* Current state of CTS */
190 #define ATEN2011_MSR_DSR 0x20 /* Current state of DSR */
191 #define ATEN2011_MSR_RI 0x40 /* Current state of RI */
192 #define ATEN2011_MSR_CD 0x80 /* Current state of CD */
195 /* 1: Enables the debugging -- 0: Disable the debugging */
199 static int debug = 0;
200 #define DPRINTK(fmt, args...) printk( "%s: " fmt, __FUNCTION__ , ## args)
203 static int debug = 0;
204 #define DPRINTK(fmt, args...)
209 * Version Information
211 #define DRIVER_VERSION "2.0"
212 #define DRIVER_DESC "ATENINTL 2011 USB Serial Adapter"
215 * Defines used for sending commands to port
218 #define ATEN_WDR_TIMEOUT (50) /* default urb timeout */
221 #define ATEN_RD_RTYPE 0xC0
222 #define ATEN_WR_RTYPE 0x40
223 #define ATEN_RDREQ 0x0D
224 #define ATEN_WRREQ 0x0E
225 #define ATEN_CTRL_TIMEOUT 500
226 #define VENDOR_READ_LENGTH (0x01)
228 /* set to 1 for RS485 mode and 0 for RS232 mode */
229 /* FIXME make this somehow dynamic and not build time specific */
230 static int RS485mode = 0;
232 static inline void ATEN2011_set_serial_private(struct usb_serial *serial,
233 struct ATENINTL_serial *data)
235 usb_set_serial_data(serial, (void *)data);
238 static inline struct ATENINTL_serial *ATEN2011_get_serial_private(struct
242 return (struct ATENINTL_serial *)usb_get_serial_data(serial);
245 static inline void ATEN2011_set_port_private(struct usb_serial_port *port,
246 struct ATENINTL_port *data)
248 usb_set_serial_port_data(port, (void *)data);
251 static inline struct ATENINTL_port *ATEN2011_get_port_private(struct
255 return (struct ATENINTL_port *)usb_get_serial_port_data(port);
258 static int set_reg_sync(struct usb_serial_port *port, __u16 reg, __u16 val)
260 struct usb_device *dev = port->serial->dev;
263 dbg("%s: is %x, value %x\n", __func__, reg, val);
265 return usb_control_msg(dev, usb_sndctrlpipe(dev, 0), ATEN_WRREQ,
266 ATEN_WR_RTYPE, val, reg, NULL, 0,
270 static int get_reg_sync(struct usb_serial_port *port, __u16 reg, __u16 *val)
272 struct usb_device *dev = port->serial->dev;
275 ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), ATEN_RDREQ,
276 ATEN_RD_RTYPE, 0, reg, val, VENDOR_READ_LENGTH,
278 dbg("%s: offset is %x, return val %x\n", __func__, reg, *val);
279 *val = (*val) & 0x00ff;
283 static int set_uart_reg(struct usb_serial_port *port, __u16 reg, __u16 val)
285 struct usb_device *dev = port->serial->dev;
286 struct ATENINTL_serial *a_serial;
289 a_serial = ATEN2011_get_serial_private(port->serial);
290 minor = port->serial->minor;
291 if (minor == SERIAL_TTY_NO_MINOR)
296 * For the UART control registers,
297 * the application number need to be Or'ed
299 if (a_serial->ATEN2011_spectrum_2or4ports == 4)
300 val |= (((__u16)port->number - minor) + 1) << 8;
302 if (((__u16) port->number - minor) == 0)
303 val |= (((__u16)port->number - minor) + 1) << 8;
305 val |= (((__u16)port->number - minor) + 2) << 8;
307 dbg("%s: application number is %x\n", __func__, val);
309 return usb_control_msg(dev, usb_sndctrlpipe(dev, 0), ATEN_WRREQ,
310 ATEN_WR_RTYPE, val, reg, NULL, 0,
314 static int get_uart_reg(struct usb_serial_port *port, __u16 reg, __u16 *val)
316 struct usb_device *dev = port->serial->dev;
319 struct ATENINTL_serial *a_serial;
320 __u16 minor = port->serial->minor;
322 a_serial = ATEN2011_get_serial_private(port->serial);
323 if (minor == SERIAL_TTY_NO_MINOR)
326 /* wval is same as application number */
327 if (a_serial->ATEN2011_spectrum_2or4ports == 4)
328 wval = (((__u16)port->number - minor) + 1) << 8;
330 if (((__u16) port->number - minor) == 0)
331 wval = (((__u16) port->number - minor) + 1) << 8;
333 wval = (((__u16) port->number - minor) + 2) << 8;
335 dbg("%s: application number is %x\n", __func__, wval);
336 ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), ATEN_RDREQ,
337 ATEN_RD_RTYPE, wval, reg, val, VENDOR_READ_LENGTH,
339 *val = (*val) & 0x00ff;
343 static int handle_newMsr(struct ATENINTL_port *port, __u8 newMsr)
345 struct ATENINTL_port *ATEN2011_port;
346 struct async_icount *icount;
347 ATEN2011_port = port;
348 icount = &ATEN2011_port->icount;
350 (ATEN_MSR_DELTA_CTS | ATEN_MSR_DELTA_DSR | ATEN_MSR_DELTA_RI |
351 ATEN_MSR_DELTA_CD)) {
352 icount = &ATEN2011_port->icount;
354 /* update input line counters */
355 if (newMsr & ATEN_MSR_DELTA_CTS) {
358 if (newMsr & ATEN_MSR_DELTA_DSR) {
361 if (newMsr & ATEN_MSR_DELTA_CD) {
364 if (newMsr & ATEN_MSR_DELTA_RI) {
372 static int handle_newLsr(struct ATENINTL_port *port, __u8 newLsr)
374 struct async_icount *icount;
376 dbg("%s - %02x", __FUNCTION__, newLsr);
378 if (newLsr & SERIAL_LSR_BI) {
380 // Parity and Framing errors only count if they
381 // occur exclusive of a break being
384 newLsr &= (__u8) (SERIAL_LSR_OE | SERIAL_LSR_BI);
387 /* update input line counters */
388 icount = &port->icount;
389 if (newLsr & SERIAL_LSR_BI) {
392 if (newLsr & SERIAL_LSR_OE) {
395 if (newLsr & SERIAL_LSR_PE) {
398 if (newLsr & SERIAL_LSR_FE) {
405 static void ATEN2011_control_callback(struct urb *urb)
408 struct ATENINTL_port *ATEN2011_port;
412 DPRINTK("%s", "Invalid Pointer !!!!:\n");
416 switch (urb->status) {
423 /* this urb is terminated, clean up */
424 dbg("%s - urb shutting down with status: %d", __FUNCTION__,
428 dbg("%s - nonzero urb status received: %d", __FUNCTION__,
433 ATEN2011_port = (struct ATENINTL_port *)urb->context;
435 DPRINTK("%s urb buffer size is %d\n", __FUNCTION__, urb->actual_length);
436 DPRINTK("%s ATEN2011_port->MsrLsr is %d port %d\n", __FUNCTION__,
437 ATEN2011_port->MsrLsr, ATEN2011_port->port_num);
438 data = urb->transfer_buffer;
439 regval = (__u8) data[0];
440 DPRINTK("%s data is %x\n", __FUNCTION__, regval);
441 if (ATEN2011_port->MsrLsr == 0)
442 handle_newMsr(ATEN2011_port, regval);
443 else if (ATEN2011_port->MsrLsr == 1)
444 handle_newLsr(ATEN2011_port, regval);
450 static int ATEN2011_get_reg(struct ATENINTL_port *ATEN, __u16 Wval, __u16 reg,
453 struct usb_device *dev = ATEN->port->serial->dev;
454 struct usb_ctrlrequest *dr = NULL;
455 unsigned char *buffer = NULL;
457 buffer = (__u8 *) ATEN->ctrl_buf;
459 // dr=(struct usb_ctrlrequest *)(buffer);
460 dr = (void *)(buffer + 2);
461 dr->bRequestType = ATEN_RD_RTYPE;
462 dr->bRequest = ATEN_RDREQ;
463 dr->wValue = cpu_to_le16(Wval); //0;
464 dr->wIndex = cpu_to_le16(reg);
465 dr->wLength = cpu_to_le16(2);
467 usb_fill_control_urb(ATEN->control_urb, dev, usb_rcvctrlpipe(dev, 0),
468 (unsigned char *)dr, buffer, 2,
469 ATEN2011_control_callback, ATEN);
470 ATEN->control_urb->transfer_buffer_length = 2;
471 ret = usb_submit_urb(ATEN->control_urb, GFP_ATOMIC);
475 static void ATEN2011_interrupt_callback(struct urb *urb)
479 struct ATENINTL_port *ATEN2011_port;
480 struct ATENINTL_serial *ATEN2011_serial;
481 struct usb_serial *serial;
488 //printk("in the function ATEN2011_interrupt_callback Length %d, Data %x \n",urb->actual_length,(unsigned int)urb->transfer_buffer);
489 DPRINTK("%s", " : Entering\n");
491 ATEN2011_serial = (struct ATENINTL_serial *)urb->context;
492 if (!urb) // || ATEN2011_serial->status_polling_started == 0 )
494 DPRINTK("%s", "Invalid Pointer !!!!:\n");
498 switch (urb->status) {
505 /* this urb is terminated, clean up */
506 dbg("%s - urb shutting down with status: %d", __FUNCTION__,
510 dbg("%s - nonzero urb status received: %d", __FUNCTION__,
514 length = urb->actual_length;
515 data = urb->transfer_buffer;
517 //ATEN2011_serial= (struct ATENINTL_serial *)urb->context;
518 serial = ATEN2011_serial->serial;
520 /* ATENINTL get 5 bytes
521 * Byte 1 IIR Port 1 (port.number is 0)
522 * Byte 2 IIR Port 2 (port.number is 1)
523 * Byte 3 IIR Port 3 (port.number is 2)
524 * Byte 4 IIR Port 4 (port.number is 3)
525 * Byte 5 FIFO status for both */
527 if (length && length > 5) {
528 DPRINTK("%s \n", "Wrong data !!!");
533 if (ATEN2011_serial->ATEN2011_spectrum_2or4ports == 4) {
534 sp[0] = (__u8) data[0];
535 sp[1] = (__u8) data[1];
536 sp[2] = (__u8) data[2];
537 sp[3] = (__u8) data[3];
540 sp[0] = (__u8) data[0];
541 sp[1] = (__u8) data[2];
542 //sp[2]=(__u8)data[2];
543 //sp[3]=(__u8)data[3];
547 // printk("%s data is sp1:%x sp2:%x sp3:%x sp4:%x status:%x\n",__FUNCTION__,sp1,sp2,sp3,sp4,st);
548 for (i = 0; i < serial->num_ports; i++) {
549 ATEN2011_port = ATEN2011_get_port_private(serial->port[i]);
550 minor = serial->minor;
551 if (minor == SERIAL_TTY_NO_MINOR)
553 if ((ATEN2011_serial->ATEN2011_spectrum_2or4ports == 2)
556 (((__u16) serial->port[i]->number -
557 (__u16) (minor)) + 2) << 8;
560 (((__u16) serial->port[i]->number -
561 (__u16) (minor)) + 1) << 8;
562 if (ATEN2011_port->open != 0) {
563 //printk("%s wval is:(for 2011) %x\n",__FUNCTION__,wval);
566 DPRINTK("SP%d No Interrupt !!!\n", i);
568 switch (sp[i] & 0x0f) {
571 ("Serial Port %d: Receiver status error or ",
574 ("address bit detected in 9-bit mode\n");
575 ATEN2011_port->MsrLsr = 1;
576 ATEN2011_get_reg(ATEN2011_port, wval,
577 LINE_STATUS_REGISTER,
582 ("Serial Port %d: Modem status change\n",
584 ATEN2011_port->MsrLsr = 0;
585 ATEN2011_get_reg(ATEN2011_port, wval,
586 MODEM_STATUS_REGISTER,
595 if (ATEN2011_serial->status_polling_started == 0)
598 result = usb_submit_urb(urb, GFP_ATOMIC);
600 dev_err(&urb->dev->dev,
601 "%s - Error %d submitting interrupt urb\n",
602 __FUNCTION__, result);
609 static void ATEN2011_bulk_in_callback(struct urb *urb)
613 struct usb_serial *serial;
614 struct usb_serial_port *port;
615 struct ATENINTL_serial *ATEN2011_serial;
616 struct ATENINTL_port *ATEN2011_port;
617 struct tty_struct *tty;
619 DPRINTK("%s", "Invalid Pointer !!!!:\n");
624 DPRINTK("nonzero read bulk status received: %d", urb->status);
625 // if(urb->status==84)
630 ATEN2011_port = (struct ATENINTL_port *)urb->context;
631 if (!ATEN2011_port) {
632 DPRINTK("%s", "NULL ATEN2011_port pointer \n");
636 port = (struct usb_serial_port *)ATEN2011_port->port;
637 serial = port->serial;
639 DPRINTK("%s\n", "Entering... \n");
641 data = urb->transfer_buffer;
642 ATEN2011_serial = ATEN2011_get_serial_private(serial);
644 DPRINTK("%s", "Entering ........... \n");
646 if (urb->actual_length) {
647 tty = tty_port_tty_get(&ATEN2011_port->port->port);
649 tty_buffer_request_room(tty, urb->actual_length);
650 tty_insert_flip_string(tty, data, urb->actual_length);
651 DPRINTK(" %s \n", data);
652 tty_flip_buffer_push(tty);
656 ATEN2011_port->icount.rx += urb->actual_length;
657 DPRINTK("ATEN2011_port->icount.rx is %d:\n",
658 ATEN2011_port->icount.rx);
662 if (!ATEN2011_port->read_urb) {
663 DPRINTK("%s", "URB KILLED !!!\n");
667 if (ATEN2011_port->read_urb->status != -EINPROGRESS) {
668 ATEN2011_port->read_urb->dev = serial->dev;
670 status = usb_submit_urb(ATEN2011_port->read_urb, GFP_ATOMIC);
674 (" usb_submit_urb(read bulk) failed, status = %d",
680 static void ATEN2011_bulk_out_data_callback(struct urb *urb)
682 struct ATENINTL_port *ATEN2011_port;
683 struct tty_struct *tty;
685 DPRINTK("%s", "Invalid Pointer !!!!:\n");
690 DPRINTK("nonzero write bulk status received:%d\n", urb->status);
694 ATEN2011_port = (struct ATENINTL_port *)urb->context;
695 if (!ATEN2011_port) {
696 DPRINTK("%s", "NULL ATEN2011_port pointer \n");
700 DPRINTK("%s \n", "Entering .........");
702 tty = tty_port_tty_get(&ATEN2011_port->port->port);
704 if (tty && ATEN2011_port->open) {
705 /* tell the tty driver that something has changed */
706 wake_up_interruptible(&tty->write_wait);
709 //schedule_work(&ATEN2011_port->port->work);
714 #ifdef ATENSerialProbe
715 static int ATEN2011_serial_probe(struct usb_serial *serial,
716 const struct usb_device_id *id)
719 /*need to implement the mode_reg reading and updating\
720 structures usb_serial_ device_type\
721 (i.e num_ports, num_bulkin,bulkout etc) */
722 /* Also we can update the changes attach */
727 static int ATEN2011_open(struct tty_struct *tty, struct usb_serial_port *port,
732 struct usb_serial *serial;
733 // struct usb_serial_port *port0;
737 struct ATENINTL_serial *ATEN2011_serial;
738 struct ATENINTL_port *ATEN2011_port;
739 struct ktermios tmp_termios;
742 //ATEN2011_serial->NoOfOpenPorts++;
743 serial = port->serial;
745 ATEN2011_port = ATEN2011_get_port_private(port);
747 if (ATEN2011_port == NULL)
750 if (ATEN2011_port->ctrl_buf==NULL)
752 ATEN2011_port->ctrl_buf = kmalloc(16,GFP_KERNEL);
753 if (ATEN2011_port->ctrl_buf == NULL) {
754 printk(", Can't allocate ctrl buff\n");
760 if(!ATEN2011_port->control_urb)
762 ATEN2011_port->control_urb=kmalloc(sizeof(struct urb),GFP_KERNEL);
765 // port0 = serial->port[0];
767 ATEN2011_serial = ATEN2011_get_serial_private(serial);
769 if (ATEN2011_serial == NULL) //|| port0 == NULL)
773 // increment the number of opened ports counter here
774 ATEN2011_serial->NoOfOpenPorts++;
775 //printk("the num of ports opend is:%d\n",ATEN2011_serial->NoOfOpenPorts);
777 usb_clear_halt(serial->dev, port->write_urb->pipe);
778 usb_clear_halt(serial->dev, port->read_urb->pipe);
780 /* Initialising the write urb pool */
781 for (j = 0; j < NUM_URBS; ++j) {
782 urb = usb_alloc_urb(0, GFP_ATOMIC);
783 ATEN2011_port->write_urb_pool[j] = urb;
786 err("No more urbs???");
790 urb->transfer_buffer = NULL;
791 urb->transfer_buffer =
792 kmalloc(URB_TRANSFER_BUFFER_SIZE, GFP_KERNEL);
793 if (!urb->transfer_buffer) {
794 err("%s-out of memory for urb buffers.", __FUNCTION__);
799 /*****************************************************************************
800 * Initialize ATEN2011 -- Write Init values to corresponding Registers
808 * 0x08 : SP1/2 Control Reg
809 *****************************************************************************/
811 //NEED to check the fallowing Block
814 status = get_reg_sync(port, ATEN2011_port->SpRegOffset, &Data);
816 DPRINTK("Reading Spreg failed\n");
820 status = set_reg_sync(port, ATEN2011_port->SpRegOffset, Data);
822 DPRINTK("writing Spreg failed\n");
827 status = set_reg_sync(port, ATEN2011_port->SpRegOffset, Data);
829 DPRINTK("writing Spreg failed\n");
833 //End of block to be checked
834 //**************************CHECK***************************//
840 status = set_uart_reg(port, SCRATCH_PAD_REGISTER, Data);
842 DPRINTK("Writing SCRATCH_PAD_REGISTER failed status-0x%x\n",
846 DPRINTK("SCRATCH_PAD_REGISTER Writing success status%d\n",
849 //**************************CHECK***************************//
852 status = get_reg_sync(port, ATEN2011_port->ControlRegOffset, &Data);
854 DPRINTK("Reading Controlreg failed\n");
857 Data |= 0x08; //Driver done bit
858 Data |= 0x20; //rx_disable
861 set_reg_sync(port, ATEN2011_port->ControlRegOffset, Data);
863 DPRINTK("writing Controlreg failed\n");
866 //do register settings here
867 // Set all regs to the device default values.
868 ////////////////////////////////////
869 // First Disable all interrupts.
870 ////////////////////////////////////
873 status = set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data);
875 DPRINTK("disableing interrupts failed\n");
878 // Set FIFO_CONTROL_REGISTER to the default value
880 status = set_uart_reg(port, FIFO_CONTROL_REGISTER, Data);
882 DPRINTK("Writing FIFO_CONTROL_REGISTER failed\n");
887 status = set_uart_reg(port, FIFO_CONTROL_REGISTER, Data);
889 DPRINTK("Writing FIFO_CONTROL_REGISTER failed\n");
893 Data = 0x03; //LCR_BITS_8
894 status = set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
895 ATEN2011_port->shadowLCR = Data;
897 Data = 0x0b; // MCR_DTR|MCR_RTS|MCR_MASTER_IE
898 status = set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
899 ATEN2011_port->shadowMCR = Data;
903 status = get_uart_reg(port, LINE_CONTROL_REGISTER, &Data);
904 ATEN2011_port->shadowLCR = Data;
906 Data |= SERIAL_LCR_DLAB; //data latch enable in LCR 0x80
907 status = set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
910 status = set_uart_reg(port, DIVISOR_LATCH_LSB, Data);
913 status = set_uart_reg(port, DIVISOR_LATCH_MSB, Data);
916 status = get_uart_reg(port, LINE_CONTROL_REGISTER, &Data);
918 // Data = ATEN2011_port->shadowLCR; //data latch disable
919 Data = Data & ~SERIAL_LCR_DLAB;
920 status = set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
921 ATEN2011_port->shadowLCR = Data;
923 //clearing Bulkin and Bulkout Fifo
925 status = get_reg_sync(port, ATEN2011_port->SpRegOffset, &Data);
928 status = set_reg_sync(port, ATEN2011_port->SpRegOffset, Data);
931 status = set_reg_sync(port, ATEN2011_port->SpRegOffset, Data);
932 //Finally enable all interrupts
935 status = set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data);
937 //clearing rx_disable
939 status = get_reg_sync(port, ATEN2011_port->ControlRegOffset, &Data);
941 status = set_reg_sync(port, ATEN2011_port->ControlRegOffset, Data);
945 status = get_reg_sync(port, ATEN2011_port->ControlRegOffset, &Data);
948 status = set_reg_sync(port, ATEN2011_port->ControlRegOffset, Data);
950 /* force low_latency on so that our tty_push actually forces *
951 * the data through,otherwise it is scheduled, and with *
952 * high data rates (like with OHCI) data can get lost. */
955 tty->low_latency = 1;
957 printk("port number is %d \n",port->number);
958 printk("serial number is %d \n",port->serial->minor);
959 printk("Bulkin endpoint is %d \n",port->bulk_in_endpointAddress);
960 printk("BulkOut endpoint is %d \n",port->bulk_out_endpointAddress);
961 printk("Interrupt endpoint is %d \n",port->interrupt_in_endpointAddress);
962 printk("port's number in the device is %d\n",ATEN2011_port->port_num);
964 ////////////////////////
965 //#ifdef CheckStatusPipe
966 /* Check to see if we've set up our endpoint info yet *
967 * (can't set it up in ATEN2011_startup as the structures *
968 * were not set up at that time.) */
969 if (ATEN2011_serial->NoOfOpenPorts == 1) {
970 // start the status polling here
971 ATEN2011_serial->status_polling_started = 1;
972 //if (ATEN2011_serial->interrupt_in_buffer == NULL)
974 /* If not yet set, Set here */
975 ATEN2011_serial->interrupt_in_buffer =
976 serial->port[0]->interrupt_in_buffer;
977 ATEN2011_serial->interrupt_in_endpoint =
978 serial->port[0]->interrupt_in_endpointAddress;
979 //printk(" interrupt endpoint:%d \n",ATEN2011_serial->interrupt_in_endpoint);
980 ATEN2011_serial->interrupt_read_urb =
981 serial->port[0]->interrupt_in_urb;
983 /* set up interrupt urb */
984 usb_fill_int_urb(ATEN2011_serial->interrupt_read_urb,
986 usb_rcvintpipe(serial->dev,
988 interrupt_in_endpoint),
989 ATEN2011_serial->interrupt_in_buffer,
990 ATEN2011_serial->interrupt_read_urb->
991 transfer_buffer_length,
992 ATEN2011_interrupt_callback, ATEN2011_serial,
993 ATEN2011_serial->interrupt_read_urb->interval);
995 /* start interrupt read for ATEN2011 *
996 * will continue as long as ATEN2011 is connected */
999 usb_submit_urb(ATEN2011_serial->interrupt_read_urb,
1002 DPRINTK("%s - Error %d submitting interrupt urb",
1003 __FUNCTION__, response);
1006 // printk(" interrupt URB submitted\n");
1013 ///////////////////////
1014 /* see if we've set up our endpoint info yet *
1015 * (can't set it up in ATEN2011_startup as the *
1016 * structures were not set up at that time.) */
1018 DPRINTK("port number is %d \n", port->number);
1019 DPRINTK("serial number is %d \n", port->serial->minor);
1020 DPRINTK("Bulkin endpoint is %d \n", port->bulk_in_endpointAddress);
1021 DPRINTK("BulkOut endpoint is %d \n", port->bulk_out_endpointAddress);
1022 DPRINTK("Interrupt endpoint is %d \n",
1023 port->interrupt_in_endpointAddress);
1024 DPRINTK("port's number in the device is %d\n", ATEN2011_port->port_num);
1025 ATEN2011_port->bulk_in_buffer = port->bulk_in_buffer;
1026 ATEN2011_port->bulk_in_endpoint = port->bulk_in_endpointAddress;
1027 ATEN2011_port->read_urb = port->read_urb;
1028 ATEN2011_port->bulk_out_endpoint = port->bulk_out_endpointAddress;
1030 minor = port->serial->minor;
1031 if (minor == SERIAL_TTY_NO_MINOR)
1034 /* set up our bulk in urb */
1035 if ((ATEN2011_serial->ATEN2011_spectrum_2or4ports == 2)
1036 && (((__u16) port->number - (__u16) (minor)) != 0)) {
1037 usb_fill_bulk_urb(ATEN2011_port->read_urb, serial->dev,
1038 usb_rcvbulkpipe(serial->dev,
1040 bulk_in_endpointAddress +
1041 2)), port->bulk_in_buffer,
1042 ATEN2011_port->read_urb->
1043 transfer_buffer_length,
1044 ATEN2011_bulk_in_callback, ATEN2011_port);
1046 usb_fill_bulk_urb(ATEN2011_port->read_urb,
1048 usb_rcvbulkpipe(serial->dev,
1050 bulk_in_endpointAddress),
1051 port->bulk_in_buffer,
1052 ATEN2011_port->read_urb->
1053 transfer_buffer_length,
1054 ATEN2011_bulk_in_callback, ATEN2011_port);
1056 DPRINTK("ATEN2011_open: bulkin endpoint is %d\n",
1057 port->bulk_in_endpointAddress);
1058 response = usb_submit_urb(ATEN2011_port->read_urb, GFP_KERNEL);
1060 err("%s - Error %d submitting control urb", __FUNCTION__,
1064 /* initialize our wait queues */
1065 init_waitqueue_head(&ATEN2011_port->wait_chase);
1066 init_waitqueue_head(&ATEN2011_port->wait_command);
1068 /* initialize our icount structure */
1069 memset(&(ATEN2011_port->icount), 0x00, sizeof(ATEN2011_port->icount));
1071 /* initialize our port settings */
1072 ATEN2011_port->shadowMCR = MCR_MASTER_IE; /* Must set to enable ints! */
1073 ATEN2011_port->chaseResponsePending = 0;
1074 /* send a open port command */
1075 ATEN2011_port->open = 1;
1076 //ATEN2011_change_port_settings(ATEN2011_port,old_termios);
1078 ATEN2011_set_termios(tty, port, &tmp_termios);
1079 ATEN2011_port->icount.tx = 0;
1080 ATEN2011_port->icount.rx = 0;
1083 ("\n\nusb_serial serial:%x ATEN2011_port:%x\nATEN2011_serial:%x usb_serial_port port:%x\n\n",
1084 (unsigned int)serial, (unsigned int)ATEN2011_port,
1085 (unsigned int)ATEN2011_serial, (unsigned int)port);
1091 static int ATEN2011_chars_in_buffer(struct tty_struct *tty)
1093 struct usb_serial_port *port = tty->driver_data;
1096 struct ATENINTL_port *ATEN2011_port;
1098 //DPRINTK("%s \n"," ATEN2011_chars_in_buffer:entering ...........");
1100 ATEN2011_port = ATEN2011_get_port_private(port);
1101 if (ATEN2011_port == NULL) {
1102 DPRINTK("%s \n", "ATEN2011_break:leaving ...........");
1106 for (i = 0; i < NUM_URBS; ++i) {
1107 if (ATEN2011_port->write_urb_pool[i]->status == -EINPROGRESS) {
1108 chars += URB_TRANSFER_BUFFER_SIZE;
1111 dbg("%s - returns %d", __FUNCTION__, chars);
1116 static void ATEN2011_block_until_tx_empty(struct tty_struct *tty,
1117 struct ATENINTL_port *ATEN2011_port)
1119 int timeout = HZ / 10;
1125 count = ATEN2011_chars_in_buffer(tty);
1127 /* Check for Buffer status */
1132 /* Block the thread for a while */
1133 interruptible_sleep_on_timeout(&ATEN2011_port->wait_chase,
1136 /* No activity.. count down section */
1139 dbg("%s - TIMEOUT", __FUNCTION__);
1142 /* Reset timout value back to seconds */
1148 static void ATEN2011_close(struct tty_struct *tty, struct usb_serial_port *port,
1151 struct usb_serial *serial;
1152 struct ATENINTL_serial *ATEN2011_serial;
1153 struct ATENINTL_port *ATEN2011_port;
1158 DPRINTK("%s\n", "ATEN2011_close:entering...");
1162 //printk("Entering... :ATEN2011_close\n");
1163 serial = port->serial;
1165 // take the Adpater and port's private data
1166 ATEN2011_serial = ATEN2011_get_serial_private(serial);
1167 ATEN2011_port = ATEN2011_get_port_private(port);
1168 if ((ATEN2011_serial == NULL) || (ATEN2011_port == NULL)) {
1172 /* flush and block(wait) until tx is empty */
1173 ATEN2011_block_until_tx_empty(tty, ATEN2011_port);
1175 // kill the ports URB's
1176 for (no_urbs = 0; no_urbs < NUM_URBS; no_urbs++)
1177 usb_kill_urb(ATEN2011_port->write_urb_pool[no_urbs]);
1178 /* Freeing Write URBs */
1179 for (no_urbs = 0; no_urbs < NUM_URBS; ++no_urbs) {
1180 if (ATEN2011_port->write_urb_pool[no_urbs]) {
1181 if (ATEN2011_port->write_urb_pool[no_urbs]->
1183 kfree(ATEN2011_port->write_urb_pool[no_urbs]->
1185 usb_free_urb(ATEN2011_port->write_urb_pool[no_urbs]);
1188 /* While closing port, shutdown all bulk read, write *
1189 * and interrupt read if they exists */
1191 if (ATEN2011_port->write_urb) {
1192 DPRINTK("%s", "Shutdown bulk write\n");
1193 usb_kill_urb(ATEN2011_port->write_urb);
1195 if (ATEN2011_port->read_urb) {
1196 DPRINTK("%s", "Shutdown bulk read\n");
1197 usb_kill_urb(ATEN2011_port->read_urb);
1199 if ((&ATEN2011_port->control_urb)) {
1200 DPRINTK("%s", "Shutdown control read\n");
1201 // usb_kill_urb (ATEN2011_port->control_urb);
1205 //if(ATEN2011_port->ctrl_buf != NULL)
1206 //kfree(ATEN2011_port->ctrl_buf);
1207 // decrement the no.of open ports counter of an individual USB-serial adapter.
1208 ATEN2011_serial->NoOfOpenPorts--;
1209 DPRINTK("NoOfOpenPorts in close%d:in port%d\n",
1210 ATEN2011_serial->NoOfOpenPorts, port->number);
1211 //printk("the num of ports opend is:%d\n",ATEN2011_serial->NoOfOpenPorts);
1212 if (ATEN2011_serial->NoOfOpenPorts == 0) {
1213 //stop the stus polling here
1214 //printk("disabling the status polling flag to 0 :\n");
1215 ATEN2011_serial->status_polling_started = 0;
1216 if (ATEN2011_serial->interrupt_read_urb) {
1217 DPRINTK("%s", "Shutdown interrupt_read_urb\n");
1218 //ATEN2011_serial->interrupt_in_buffer=NULL;
1219 //usb_kill_urb (ATEN2011_serial->interrupt_read_urb);
1222 if (ATEN2011_port->write_urb) {
1223 /* if this urb had a transfer buffer already (old tx) free it */
1224 if (ATEN2011_port->write_urb->transfer_buffer != NULL) {
1225 kfree(ATEN2011_port->write_urb->transfer_buffer);
1227 usb_free_urb(ATEN2011_port->write_urb);
1229 // clear the MCR & IER
1231 set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
1233 set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data);
1235 ATEN2011_port->open = 0;
1236 DPRINTK("%s \n", "Leaving ............");
1240 static void ATEN2011_block_until_chase_response(struct tty_struct *tty,
1241 struct ATENINTL_port
1244 int timeout = 1 * HZ;
1249 count = ATEN2011_chars_in_buffer(tty);
1251 /* Check for Buffer status */
1253 ATEN2011_port->chaseResponsePending = 0;
1257 /* Block the thread for a while */
1258 interruptible_sleep_on_timeout(&ATEN2011_port->wait_chase,
1260 /* No activity.. count down section */
1263 dbg("%s - TIMEOUT", __FUNCTION__);
1266 /* Reset timout value back to seconds */
1273 static void ATEN2011_break(struct tty_struct *tty, int break_state)
1275 struct usb_serial_port *port = tty->driver_data;
1277 struct usb_serial *serial;
1278 struct ATENINTL_serial *ATEN2011_serial;
1279 struct ATENINTL_port *ATEN2011_port;
1281 DPRINTK("%s \n", "Entering ...........");
1282 DPRINTK("ATEN2011_break: Start\n");
1284 serial = port->serial;
1286 ATEN2011_serial = ATEN2011_get_serial_private(serial);
1287 ATEN2011_port = ATEN2011_get_port_private(port);
1289 if ((ATEN2011_serial == NULL) || (ATEN2011_port == NULL)) {
1293 /* flush and chase */
1294 ATEN2011_port->chaseResponsePending = 1;
1298 /* flush and block until tx is empty */
1299 ATEN2011_block_until_chase_response(tty, ATEN2011_port);
1302 if (break_state == -1) {
1303 data = ATEN2011_port->shadowLCR | LCR_SET_BREAK;
1305 data = ATEN2011_port->shadowLCR & ~LCR_SET_BREAK;
1308 ATEN2011_port->shadowLCR = data;
1309 DPRINTK("ATEN2011_break ATEN2011_port->shadowLCR is %x\n",
1310 ATEN2011_port->shadowLCR);
1311 set_uart_reg(port, LINE_CONTROL_REGISTER, ATEN2011_port->shadowLCR);
1316 static int ATEN2011_write_room(struct tty_struct *tty)
1318 struct usb_serial_port *port = tty->driver_data;
1321 struct ATENINTL_port *ATEN2011_port;
1323 // DPRINTK("%s \n"," ATEN2011_write_room:entering ...........");
1325 ATEN2011_port = ATEN2011_get_port_private(port);
1326 if (ATEN2011_port == NULL) {
1327 DPRINTK("%s \n", "ATEN2011_break:leaving ...........");
1331 for (i = 0; i < NUM_URBS; ++i) {
1332 if (ATEN2011_port->write_urb_pool[i]->status != -EINPROGRESS) {
1333 room += URB_TRANSFER_BUFFER_SIZE;
1337 dbg("%s - returns %d", __FUNCTION__, room);
1342 static int ATEN2011_write(struct tty_struct *tty, struct usb_serial_port *port,
1343 const unsigned char *data, int count)
1351 struct ATENINTL_port *ATEN2011_port;
1352 struct usb_serial *serial;
1353 struct ATENINTL_serial *ATEN2011_serial;
1356 const unsigned char *current_position = data;
1357 unsigned char *data1;
1358 DPRINTK("%s \n", "entering ...........");
1360 serial = port->serial;
1362 ATEN2011_port = ATEN2011_get_port_private(port);
1363 if (ATEN2011_port == NULL) {
1364 DPRINTK("%s", "ATEN2011_port is NULL\n");
1368 ATEN2011_serial = ATEN2011_get_serial_private(serial);
1369 if (ATEN2011_serial == NULL) {
1370 DPRINTK("%s", "ATEN2011_serial is NULL \n");
1374 /* try to find a free urb in the list */
1377 for (i = 0; i < NUM_URBS; ++i) {
1378 if (ATEN2011_port->write_urb_pool[i]->status != -EINPROGRESS) {
1379 urb = ATEN2011_port->write_urb_pool[i];
1380 DPRINTK("\nURB:%d", i);
1386 dbg("%s - no more free urbs", __FUNCTION__);
1390 if (urb->transfer_buffer == NULL) {
1391 urb->transfer_buffer =
1392 kmalloc(URB_TRANSFER_BUFFER_SIZE, GFP_KERNEL);
1394 if (urb->transfer_buffer == NULL) {
1395 err("%s no more kernel memory...", __FUNCTION__);
1399 transfer_size = min(count, URB_TRANSFER_BUFFER_SIZE);
1401 memcpy(urb->transfer_buffer, current_position, transfer_size);
1402 //usb_serial_debug_data (__FILE__, __FUNCTION__, transfer_size, urb->transfer_buffer);
1404 /* fill urb with data and submit */
1405 minor = port->serial->minor;
1406 if (minor == SERIAL_TTY_NO_MINOR) ;
1408 if ((ATEN2011_serial->ATEN2011_spectrum_2or4ports == 2)
1409 && (((__u16) port->number - (__u16) (minor)) != 0)) {
1410 usb_fill_bulk_urb(urb, ATEN2011_serial->serial->dev,
1411 usb_sndbulkpipe(ATEN2011_serial->serial->dev,
1413 bulk_out_endpointAddress) +
1414 2), urb->transfer_buffer,
1416 ATEN2011_bulk_out_data_callback,
1420 usb_fill_bulk_urb(urb,
1421 ATEN2011_serial->serial->dev,
1422 usb_sndbulkpipe(ATEN2011_serial->serial->dev,
1424 bulk_out_endpointAddress),
1425 urb->transfer_buffer, transfer_size,
1426 ATEN2011_bulk_out_data_callback,
1429 data1 = urb->transfer_buffer;
1430 DPRINTK("\nbulkout endpoint is %d", port->bulk_out_endpointAddress);
1431 //for(i=0;i < urb->actual_length;i++)
1432 // DPRINTK("Data is %c\n ",data1[i]);
1434 /* send it down the pipe */
1435 status = usb_submit_urb(urb, GFP_ATOMIC);
1438 err("%s - usb_submit_urb(write bulk) failed with status = %d",
1439 __FUNCTION__, status);
1440 bytes_sent = status;
1443 bytes_sent = transfer_size;
1444 ATEN2011_port->icount.tx += transfer_size;
1445 DPRINTK("ATEN2011_port->icount.tx is %d:\n", ATEN2011_port->icount.tx);
1452 static void ATEN2011_throttle(struct tty_struct *tty)
1454 struct usb_serial_port *port = tty->driver_data;
1455 struct ATENINTL_port *ATEN2011_port;
1458 DPRINTK("- port %d\n", port->number);
1460 ATEN2011_port = ATEN2011_get_port_private(port);
1462 if (ATEN2011_port == NULL)
1465 if (!ATEN2011_port->open) {
1466 DPRINTK("%s\n", "port not opened");
1470 DPRINTK("%s", "Entering .......... \n");
1473 dbg("%s - no tty available", __FUNCTION__);
1477 /* if we are implementing XON/XOFF, send the stop character */
1479 unsigned char stop_char = STOP_CHAR(tty);
1480 status = ATEN2011_write(tty, port, &stop_char, 1); //FC4
1486 /* if we are implementing RTS/CTS, toggle that line */
1487 if (tty->termios->c_cflag & CRTSCTS) {
1488 ATEN2011_port->shadowMCR &= ~MCR_RTS;
1489 status = set_uart_reg(port, MODEM_CONTROL_REGISTER,
1490 ATEN2011_port->shadowMCR);
1500 static void ATEN2011_unthrottle(struct tty_struct *tty)
1502 struct usb_serial_port *port = tty->driver_data;
1504 struct ATENINTL_port *ATEN2011_port = ATEN2011_get_port_private(port);
1506 if (ATEN2011_port == NULL)
1509 if (!ATEN2011_port->open) {
1510 dbg("%s - port not opened", __FUNCTION__);
1514 DPRINTK("%s", "Entering .......... \n");
1517 dbg("%s - no tty available", __FUNCTION__);
1521 /* if we are implementing XON/XOFF, send the start character */
1523 unsigned char start_char = START_CHAR(tty);
1524 status = ATEN2011_write(tty, port, &start_char, 1); //FC4
1530 /* if we are implementing RTS/CTS, toggle that line */
1531 if (tty->termios->c_cflag & CRTSCTS) {
1532 ATEN2011_port->shadowMCR |= MCR_RTS;
1533 status = set_uart_reg(port, MODEM_CONTROL_REGISTER,
1534 ATEN2011_port->shadowMCR);
1543 static int ATEN2011_tiocmget(struct tty_struct *tty, struct file *file)
1545 struct usb_serial_port *port = tty->driver_data;
1546 //struct ti_port *tport = usb_get_serial_port_data(port);
1547 struct ATENINTL_port *ATEN2011_port;
1548 unsigned int result;
1553 ATEN2011_port = ATEN2011_get_port_private(port);
1555 DPRINTK("%s - port %d", __FUNCTION__, port->number);
1557 if (ATEN2011_port == NULL)
1560 status = get_uart_reg(port, MODEM_STATUS_REGISTER, &msr);
1561 status = get_uart_reg(port, MODEM_CONTROL_REGISTER, &mcr);
1562 // mcr = ATEN2011_port->shadowMCR;
1563 // COMMENT2: the Fallowing three line are commented for updating only MSR values
1564 result = ((mcr & MCR_DTR) ? TIOCM_DTR : 0)
1565 | ((mcr & MCR_RTS) ? TIOCM_RTS : 0)
1566 | ((mcr & MCR_LOOPBACK) ? TIOCM_LOOP : 0)
1567 | ((msr & ATEN2011_MSR_CTS) ? TIOCM_CTS : 0)
1568 | ((msr & ATEN2011_MSR_CD) ? TIOCM_CAR : 0)
1569 | ((msr & ATEN2011_MSR_RI) ? TIOCM_RI : 0)
1570 | ((msr & ATEN2011_MSR_DSR) ? TIOCM_DSR : 0);
1572 DPRINTK("%s - 0x%04X", __FUNCTION__, result);
1577 static int ATEN2011_tiocmset(struct tty_struct *tty, struct file *file,
1578 unsigned int set, unsigned int clear)
1580 struct usb_serial_port *port = tty->driver_data;
1581 struct ATENINTL_port *ATEN2011_port;
1582 //struct ti_port *tport = usb_get_serial_port_data(port);
1584 unsigned int status;
1586 DPRINTK("%s - port %d", __FUNCTION__, port->number);
1588 ATEN2011_port = ATEN2011_get_port_private(port);
1590 if (ATEN2011_port == NULL)
1593 mcr = ATEN2011_port->shadowMCR;
1594 if (clear & TIOCM_RTS)
1596 if (clear & TIOCM_DTR)
1598 if (clear & TIOCM_LOOP)
1599 mcr &= ~MCR_LOOPBACK;
1601 if (set & TIOCM_RTS)
1603 if (set & TIOCM_DTR)
1605 if (set & TIOCM_LOOP)
1606 mcr |= MCR_LOOPBACK;
1608 ATEN2011_port->shadowMCR = mcr;
1610 status = set_uart_reg(port, MODEM_CONTROL_REGISTER, mcr);
1612 DPRINTK("setting MODEM_CONTROL_REGISTER Failed\n");
1619 static void ATEN2011_set_termios(struct tty_struct *tty,
1620 struct usb_serial_port *port,
1621 struct ktermios *old_termios)
1625 struct usb_serial *serial;
1626 struct ATENINTL_port *ATEN2011_port;
1628 DPRINTK("ATEN2011_set_termios: START\n");
1630 serial = port->serial;
1632 ATEN2011_port = ATEN2011_get_port_private(port);
1634 if (ATEN2011_port == NULL)
1637 if (!ATEN2011_port->open) {
1638 dbg("%s - port not opened", __FUNCTION__);
1642 DPRINTK("%s\n", "setting termios - ");
1644 cflag = tty->termios->c_cflag;
1647 DPRINTK("%s %s\n", __FUNCTION__, "cflag is NULL");
1651 /* check that they really want us to change something */
1653 if ((cflag == old_termios->c_cflag) &&
1654 (RELEVANT_IFLAG(tty->termios->c_iflag) ==
1655 RELEVANT_IFLAG(old_termios->c_iflag))) {
1656 DPRINTK("%s\n", "Nothing to change");
1661 dbg("%s - clfag %08x iflag %08x", __FUNCTION__,
1662 tty->termios->c_cflag, RELEVANT_IFLAG(tty->termios->c_iflag));
1665 dbg("%s - old clfag %08x old iflag %08x", __FUNCTION__,
1666 old_termios->c_cflag, RELEVANT_IFLAG(old_termios->c_iflag));
1669 dbg("%s - port %d", __FUNCTION__, port->number);
1671 /* change the port settings to the new ones specified */
1673 ATEN2011_change_port_settings(tty, ATEN2011_port, old_termios);
1675 if (!ATEN2011_port->read_urb) {
1676 DPRINTK("%s", "URB KILLED !!!!!\n");
1680 if (ATEN2011_port->read_urb->status != -EINPROGRESS) {
1681 ATEN2011_port->read_urb->dev = serial->dev;
1682 status = usb_submit_urb(ATEN2011_port->read_urb, GFP_ATOMIC);
1685 (" usb_submit_urb(read bulk) failed, status = %d",
1692 static int get_lsr_info(struct tty_struct *tty,
1693 struct ATENINTL_port *ATEN2011_port,
1694 unsigned int __user *value)
1697 unsigned int result = 0;
1699 count = ATEN2011_chars_in_buffer(tty);
1701 dbg("%s -- Empty", __FUNCTION__);
1702 result = TIOCSER_TEMT;
1705 if (copy_to_user(value, &result, sizeof(int)))
1710 static int get_number_bytes_avail(struct tty_struct *tty,
1711 struct ATENINTL_port *ATEN2011_port,
1712 unsigned int __user *value)
1714 unsigned int result = 0;
1717 return -ENOIOCTLCMD;
1719 result = tty->read_cnt;
1721 dbg("%s(%d) = %d", __FUNCTION__, ATEN2011_port->port->number, result);
1722 if (copy_to_user(value, &result, sizeof(int)))
1725 return -ENOIOCTLCMD;
1728 static int set_modem_info(struct ATENINTL_port *ATEN2011_port, unsigned int cmd,
1729 unsigned int __user *value)
1735 struct usb_serial_port *port;
1737 if (ATEN2011_port == NULL)
1740 port = (struct usb_serial_port *)ATEN2011_port->port;
1742 mcr = ATEN2011_port->shadowMCR;
1744 if (copy_from_user(&arg, value, sizeof(int)))
1749 if (arg & TIOCM_RTS)
1751 if (arg & TIOCM_DTR)
1753 if (arg & TIOCM_LOOP)
1754 mcr |= MCR_LOOPBACK;
1758 if (arg & TIOCM_RTS)
1760 if (arg & TIOCM_DTR)
1762 if (arg & TIOCM_LOOP)
1763 mcr &= ~MCR_LOOPBACK;
1767 /* turn off the RTS and DTR and LOOPBACK
1768 * and then only turn on what was asked to */
1769 mcr &= ~(MCR_RTS | MCR_DTR | MCR_LOOPBACK);
1770 mcr |= ((arg & TIOCM_RTS) ? MCR_RTS : 0);
1771 mcr |= ((arg & TIOCM_DTR) ? MCR_DTR : 0);
1772 mcr |= ((arg & TIOCM_LOOP) ? MCR_LOOPBACK : 0);
1776 ATEN2011_port->shadowMCR = mcr;
1778 Data = ATEN2011_port->shadowMCR;
1779 status = set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
1781 DPRINTK("setting MODEM_CONTROL_REGISTER Failed\n");
1788 static int get_modem_info(struct ATENINTL_port *ATEN2011_port,
1789 unsigned int __user *value)
1791 unsigned int result = 0;
1793 unsigned int mcr = ATEN2011_port->shadowMCR;
1796 status = get_uart_reg(ATEN2011_port->port, MODEM_STATUS_REGISTER, &msr);
1797 result = ((mcr & MCR_DTR) ? TIOCM_DTR : 0) /* 0x002 */
1798 |((mcr & MCR_RTS) ? TIOCM_RTS : 0) /* 0x004 */
1799 |((msr & ATEN2011_MSR_CTS) ? TIOCM_CTS : 0) /* 0x020 */
1800 |((msr & ATEN2011_MSR_CD) ? TIOCM_CAR : 0) /* 0x040 */
1801 |((msr & ATEN2011_MSR_RI) ? TIOCM_RI : 0) /* 0x080 */
1802 |((msr & ATEN2011_MSR_DSR) ? TIOCM_DSR : 0); /* 0x100 */
1804 dbg("%s -- %x", __FUNCTION__, result);
1806 if (copy_to_user(value, &result, sizeof(int)))
1811 static int get_serial_info(struct ATENINTL_port *ATEN2011_port,
1812 struct serial_struct __user *retinfo)
1814 struct serial_struct tmp;
1816 if (ATEN2011_port == NULL)
1822 memset(&tmp, 0, sizeof(tmp));
1824 tmp.type = PORT_16550A;
1825 tmp.line = ATEN2011_port->port->serial->minor;
1826 if (tmp.line == SERIAL_TTY_NO_MINOR)
1828 tmp.port = ATEN2011_port->port->number;
1830 tmp.flags = ASYNC_SKIP_TEST | ASYNC_AUTO_IRQ;
1831 tmp.xmit_fifo_size = NUM_URBS * URB_TRANSFER_BUFFER_SIZE;
1832 tmp.baud_base = 9600;
1833 tmp.close_delay = 5 * HZ;
1834 tmp.closing_wait = 30 * HZ;
1836 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
1841 static int ATEN2011_ioctl(struct tty_struct *tty, struct file *file,
1842 unsigned int cmd, unsigned long arg)
1844 struct usb_serial_port *port = tty->driver_data;
1845 struct ATENINTL_port *ATEN2011_port;
1846 struct async_icount cnow;
1847 struct async_icount cprev;
1848 struct serial_icounter_struct icount;
1850 unsigned int __user *user_arg = (unsigned int __user *)arg;
1852 //printk("%s - port %d, cmd = 0x%x\n", __FUNCTION__, port->number, cmd);
1854 ATEN2011_port = ATEN2011_get_port_private(port);
1856 if (ATEN2011_port == NULL)
1859 dbg("%s - port %d, cmd = 0x%x", __FUNCTION__, port->number, cmd);
1862 /* return number of bytes available */
1865 dbg("%s (%d) TIOCINQ", __FUNCTION__, port->number);
1866 return get_number_bytes_avail(tty, ATEN2011_port, user_arg);
1870 dbg("%s (%d) TIOCOUTQ", __FUNCTION__, port->number);
1871 return put_user(ATEN2011_chars_in_buffer(tty), user_arg);
1875 dbg("%s (%d) TIOCSERGETLSR", __FUNCTION__, port->number);
1876 return get_lsr_info(tty, ATEN2011_port, user_arg);
1882 dbg("%s (%d) TIOCMSET/TIOCMBIC/TIOCMSET", __FUNCTION__,
1884 // printk("%s (%d) TIOCMSET/TIOCMBIC/TIOCMSET", __FUNCTION__, port->number);
1886 set_modem_info(ATEN2011_port, cmd, user_arg);
1887 // printk(" %s: ret:%d\n",__FUNCTION__,ATENret);
1891 dbg("%s (%d) TIOCMGET", __FUNCTION__, port->number);
1892 return get_modem_info(ATEN2011_port, user_arg);
1895 dbg("%s (%d) TIOCGSERIAL", __FUNCTION__, port->number);
1896 return get_serial_info(ATEN2011_port,
1897 (struct serial_struct __user *)arg);
1900 dbg("%s (%d) TIOCSSERIAL", __FUNCTION__, port->number);
1904 dbg("%s (%d) TIOCMIWAIT", __FUNCTION__, port->number);
1905 cprev = ATEN2011_port->icount;
1907 /* see if a signal did it */
1908 if (signal_pending(current))
1909 return -ERESTARTSYS;
1910 cnow = ATEN2011_port->icount;
1911 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
1912 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts)
1913 return -EIO; /* no change => error */
1914 if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
1915 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
1916 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
1917 ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts))) {
1926 cnow = ATEN2011_port->icount;
1927 icount.cts = cnow.cts;
1928 icount.dsr = cnow.dsr;
1929 icount.rng = cnow.rng;
1930 icount.dcd = cnow.dcd;
1931 icount.rx = cnow.rx;
1932 icount.tx = cnow.tx;
1933 icount.frame = cnow.frame;
1934 icount.overrun = cnow.overrun;
1935 icount.parity = cnow.parity;
1936 icount.brk = cnow.brk;
1937 icount.buf_overrun = cnow.buf_overrun;
1939 dbg("%s (%d) TIOCGICOUNT RX=%d, TX=%d", __FUNCTION__,
1940 port->number, icount.rx, icount.tx);
1941 if (copy_to_user((void __user *)arg, &icount, sizeof(icount)))
1949 return -ENOIOCTLCMD;
1952 static int ATEN2011_calc_baud_rate_divisor(int baudRate, int *divisor,
1953 __u16 * clk_sel_val)
1956 //__u16 custom,round1, round;
1958 dbg("%s - %d", __FUNCTION__, baudRate);
1960 if (baudRate <= 115200) {
1961 *divisor = 115200 / baudRate;
1964 if ((baudRate > 115200) && (baudRate <= 230400)) {
1965 *divisor = 230400 / baudRate;
1966 *clk_sel_val = 0x10;
1967 } else if ((baudRate > 230400) && (baudRate <= 403200)) {
1968 *divisor = 403200 / baudRate;
1969 *clk_sel_val = 0x20;
1970 } else if ((baudRate > 403200) && (baudRate <= 460800)) {
1971 *divisor = 460800 / baudRate;
1972 *clk_sel_val = 0x30;
1973 } else if ((baudRate > 460800) && (baudRate <= 806400)) {
1974 *divisor = 806400 / baudRate;
1975 *clk_sel_val = 0x40;
1976 } else if ((baudRate > 806400) && (baudRate <= 921600)) {
1977 *divisor = 921600 / baudRate;
1978 *clk_sel_val = 0x50;
1979 } else if ((baudRate > 921600) && (baudRate <= 1572864)) {
1980 *divisor = 1572864 / baudRate;
1981 *clk_sel_val = 0x60;
1982 } else if ((baudRate > 1572864) && (baudRate <= 3145728)) {
1983 *divisor = 3145728 / baudRate;
1984 *clk_sel_val = 0x70;
1989 static int ATEN2011_send_cmd_write_baud_rate(struct ATENINTL_port
1990 *ATEN2011_port, int baudRate)
1995 unsigned char number;
1997 struct usb_serial_port *port;
2000 if (ATEN2011_port == NULL)
2003 port = (struct usb_serial_port *)ATEN2011_port->port;
2005 DPRINTK("%s", "Entering .......... \n");
2007 minor = ATEN2011_port->port->serial->minor;
2008 if (minor == SERIAL_TTY_NO_MINOR)
2010 number = ATEN2011_port->port->number - minor;
2012 dbg("%s - port = %d, baud = %d", __FUNCTION__,
2013 ATEN2011_port->port->number, baudRate);
2014 //reset clk_uart_sel in spregOffset
2015 if (baudRate > 115200) {
2016 #ifdef HW_flow_control
2017 //NOTE: need to see the pther register to modify
2018 //setting h/w flow control bit to 1;
2019 //Data = ATEN2011_port->shadowMCR ;
2021 ATEN2011_port->shadowMCR = Data;
2022 status = set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
2024 DPRINTK("Writing spreg failed in set_serial_baud\n");
2030 #ifdef HW_flow_control
2031 //setting h/w flow control bit to 0;
2032 //Data = ATEN2011_port->shadowMCR ;
2034 ATEN2011_port->shadowMCR = Data;
2035 status = set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
2037 DPRINTK("Writing spreg failed in set_serial_baud\n");
2044 if (1) //baudRate <= 115200)
2049 ATEN2011_calc_baud_rate_divisor(baudRate, &divisor,
2051 status = get_reg_sync(port, ATEN2011_port->SpRegOffset, &Data);
2053 DPRINTK("reading spreg failed in set_serial_baud\n");
2056 Data = (Data & 0x8f) | clk_sel_val;
2057 status = set_reg_sync(port, ATEN2011_port->SpRegOffset, Data);
2059 DPRINTK("Writing spreg failed in set_serial_baud\n");
2062 /* Calculate the Divisor */
2065 err("%s - bad baud rate", __FUNCTION__);
2066 DPRINTK("%s\n", "bad baud rate");
2069 /* Enable access to divisor latch */
2070 Data = ATEN2011_port->shadowLCR | SERIAL_LCR_DLAB;
2071 ATEN2011_port->shadowLCR = Data;
2072 set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
2074 /* Write the divisor */
2075 Data = (unsigned char)(divisor & 0xff);
2076 DPRINTK("set_serial_baud Value to write DLL is %x\n", Data);
2077 set_uart_reg(port, DIVISOR_LATCH_LSB, Data);
2079 Data = (unsigned char)((divisor & 0xff00) >> 8);
2080 DPRINTK("set_serial_baud Value to write DLM is %x\n", Data);
2081 set_uart_reg(port, DIVISOR_LATCH_MSB, Data);
2083 /* Disable access to divisor latch */
2084 Data = ATEN2011_port->shadowLCR & ~SERIAL_LCR_DLAB;
2085 ATEN2011_port->shadowLCR = Data;
2086 set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
2093 static void ATEN2011_change_port_settings(struct tty_struct *tty,
2094 struct ATENINTL_port *ATEN2011_port,
2095 struct ktermios *old_termios)
2105 struct usb_serial_port *port;
2106 struct usb_serial *serial;
2108 if (ATEN2011_port == NULL)
2111 port = (struct usb_serial_port *)ATEN2011_port->port;
2113 serial = port->serial;
2115 dbg("%s - port %d", __FUNCTION__, ATEN2011_port->port->number);
2117 if (!ATEN2011_port->open) {
2118 dbg("%s - port not opened", __FUNCTION__);
2122 if ((!tty) || (!tty->termios)) {
2123 dbg("%s - no tty structures", __FUNCTION__);
2127 DPRINTK("%s", "Entering .......... \n");
2131 lParity = LCR_PAR_NONE;
2133 cflag = tty->termios->c_cflag;
2134 iflag = tty->termios->c_iflag;
2136 /* Change the number of bits */
2138 //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
2141 switch (cflag & CSIZE) {
2159 /* Change the Parity bit */
2160 if (cflag & PARENB) {
2161 if (cflag & PARODD) {
2162 lParity = LCR_PAR_ODD;
2163 dbg("%s - parity = odd", __FUNCTION__);
2165 lParity = LCR_PAR_EVEN;
2166 dbg("%s - parity = even", __FUNCTION__);
2170 dbg("%s - parity = none", __FUNCTION__);
2173 if (cflag & CMSPAR) {
2174 lParity = lParity | 0x20;
2177 /* Change the Stop bit */
2178 if (cflag & CSTOPB) {
2180 dbg("%s - stop bits = 2", __FUNCTION__);
2183 dbg("%s - stop bits = 1", __FUNCTION__);
2186 /* Update the LCR with the correct value */
2187 ATEN2011_port->shadowLCR &=
2188 ~(LCR_BITS_MASK | LCR_STOP_MASK | LCR_PAR_MASK);
2189 ATEN2011_port->shadowLCR |= (lData | lParity | lStop);
2192 ("ATEN2011_change_port_settings ATEN2011_port->shadowLCR is %x\n",
2193 ATEN2011_port->shadowLCR);
2194 /* Disable Interrupts */
2196 set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data);
2199 set_uart_reg(port, FIFO_CONTROL_REGISTER, Data);
2202 set_uart_reg(port, FIFO_CONTROL_REGISTER, Data);
2204 /* Send the updated LCR value to the ATEN2011 */
2205 Data = ATEN2011_port->shadowLCR;
2207 set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
2210 ATEN2011_port->shadowMCR = Data;
2211 set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
2213 set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
2215 /* set up the MCR register and send it to the ATEN2011 */
2217 ATEN2011_port->shadowMCR = MCR_MASTER_IE;
2218 if (cflag & CBAUD) {
2219 ATEN2011_port->shadowMCR |= (MCR_DTR | MCR_RTS);
2222 if (cflag & CRTSCTS) {
2223 ATEN2011_port->shadowMCR |= (MCR_XON_ANY);
2226 ATEN2011_port->shadowMCR &= ~(MCR_XON_ANY);
2229 Data = ATEN2011_port->shadowMCR;
2230 set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
2232 /* Determine divisor based on baud rate */
2233 baud = tty_get_baud_rate(tty);
2236 /* pick a default, any default... */
2237 DPRINTK("%s\n", "Picked default baud...");
2241 dbg("%s - baud rate = %d", __FUNCTION__, baud);
2242 status = ATEN2011_send_cmd_write_baud_rate(ATEN2011_port, baud);
2244 /* Enable Interrupts */
2246 set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data);
2248 if (ATEN2011_port->read_urb->status != -EINPROGRESS) {
2249 ATEN2011_port->read_urb->dev = serial->dev;
2251 status = usb_submit_urb(ATEN2011_port->read_urb, GFP_ATOMIC);
2255 (" usb_submit_urb(read bulk) failed, status = %d",
2260 ("ATEN2011_change_port_settings ATEN2011_port->shadowLCR is End %x\n",
2261 ATEN2011_port->shadowLCR);
2266 static int ATEN2011_calc_num_ports(struct usb_serial *serial)
2271 int ATEN2011_2or4ports;
2272 ret = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
2273 ATEN_RDREQ, ATEN_RD_RTYPE, 0, GPIO_REGISTER,
2274 &Data, VENDOR_READ_LENGTH, ATEN_WDR_TIMEOUT);
2276 //printk("ATEN2011_calc_num_ports GPIO is %x\n",Data);
2278 /* ghostgum: here is where the problem appears to bet */
2279 /* Which of the following are needed? */
2280 /* Greg used the serial->type->num_ports=2 */
2281 /* But the code in the ATEN2011_open relies on serial->num_ports=2 */
2282 if ((Data & 0x01) == 0) {
2283 ATEN2011_2or4ports = 2;
2284 serial->type->num_ports = 2;
2285 serial->num_ports = 2;
2287 //else if(serial->interface->cur_altsetting->desc.bNumEndpoints == 9)
2289 ATEN2011_2or4ports = 4;
2290 serial->type->num_ports = 4;
2291 serial->num_ports = 4;
2295 return ATEN2011_2or4ports;
2298 static int ATEN2011_startup(struct usb_serial *serial)
2300 struct ATENINTL_serial *ATEN2011_serial;
2301 struct ATENINTL_port *ATEN2011_port;
2302 struct usb_device *dev;
2307 DPRINTK("%s \n", " ATEN2011_startup :entering..........");
2310 DPRINTK("%s\n", "Invalid Handler");
2316 DPRINTK("%s\n", "Entering...");
2318 /* create our private serial structure */
2319 ATEN2011_serial = kzalloc(sizeof(struct ATENINTL_serial), GFP_KERNEL);
2320 if (ATEN2011_serial == NULL) {
2321 err("%s - Out of memory", __FUNCTION__);
2325 /* resetting the private structure field values to zero */
2326 memset(ATEN2011_serial, 0, sizeof(struct ATENINTL_serial));
2328 ATEN2011_serial->serial = serial;
2329 //initilize status polling flag to 0
2330 ATEN2011_serial->status_polling_started = 0;
2332 ATEN2011_set_serial_private(serial, ATEN2011_serial);
2333 ATEN2011_serial->ATEN2011_spectrum_2or4ports =
2334 ATEN2011_calc_num_ports(serial);
2335 /* we set up the pointers to the endpoints in the ATEN2011_open *
2336 * function, as the structures aren't created yet. */
2338 /* set up port private structures */
2339 for (i = 0; i < serial->num_ports; ++i) {
2341 kmalloc(sizeof(struct ATENINTL_port), GFP_KERNEL);
2342 if (ATEN2011_port == NULL) {
2343 err("%s - Out of memory", __FUNCTION__);
2344 ATEN2011_set_serial_private(serial, NULL);
2345 kfree(ATEN2011_serial);
2348 memset(ATEN2011_port, 0, sizeof(struct ATENINTL_port));
2350 /* Initialize all port interrupt end point to port 0 int endpoint *
2351 * Our device has only one interrupt end point comman to all port */
2353 // serial->port[i]->interrupt_in_endpointAddress = serial->port[0]->interrupt_in_endpointAddress;
2355 ATEN2011_port->port = serial->port[i];
2357 ATEN2011_set_port_private(serial->port[i], ATEN2011_port);
2359 minor = serial->port[i]->serial->minor;
2360 if (minor == SERIAL_TTY_NO_MINOR)
2362 ATEN2011_port->port_num =
2363 ((serial->port[i]->number - minor) + 1);
2365 if (ATEN2011_port->port_num == 1) {
2366 ATEN2011_port->SpRegOffset = 0x0;
2367 ATEN2011_port->ControlRegOffset = 0x1;
2368 ATEN2011_port->DcrRegOffset = 0x4;
2369 } else if ((ATEN2011_port->port_num == 2)
2370 && (ATEN2011_serial->ATEN2011_spectrum_2or4ports ==
2372 ATEN2011_port->SpRegOffset = 0x8;
2373 ATEN2011_port->ControlRegOffset = 0x9;
2374 ATEN2011_port->DcrRegOffset = 0x16;
2375 } else if ((ATEN2011_port->port_num == 2)
2376 && (ATEN2011_serial->ATEN2011_spectrum_2or4ports ==
2378 ATEN2011_port->SpRegOffset = 0xa;
2379 ATEN2011_port->ControlRegOffset = 0xb;
2380 ATEN2011_port->DcrRegOffset = 0x19;
2381 } else if ((ATEN2011_port->port_num == 3)
2382 && (ATEN2011_serial->ATEN2011_spectrum_2or4ports ==
2384 ATEN2011_port->SpRegOffset = 0xa;
2385 ATEN2011_port->ControlRegOffset = 0xb;
2386 ATEN2011_port->DcrRegOffset = 0x19;
2387 } else if ((ATEN2011_port->port_num == 4)
2388 && (ATEN2011_serial->ATEN2011_spectrum_2or4ports ==
2390 ATEN2011_port->SpRegOffset = 0xc;
2391 ATEN2011_port->ControlRegOffset = 0xd;
2392 ATEN2011_port->DcrRegOffset = 0x1c;
2395 ATEN2011_set_port_private(serial->port[i], ATEN2011_port);
2397 //enable rx_disable bit in control register
2399 status = get_reg_sync(serial->port[i],
2400 ATEN2011_port->ControlRegOffset, &Data);
2402 DPRINTK("Reading ControlReg failed status-0x%x\n",
2407 ("ControlReg Reading success val is %x, status%d\n",
2409 Data |= 0x08; //setting driver done bit
2410 Data |= 0x04; //sp1_bit to have cts change reflect in modem status reg
2412 //Data |= 0x20; //rx_disable bit
2413 status = set_reg_sync(serial->port[i],
2414 ATEN2011_port->ControlRegOffset, Data);
2417 ("Writing ControlReg failed(rx_disable) status-0x%x\n",
2422 ("ControlReg Writing success(rx_disable) status%d\n",
2425 //Write default values in DCR (i.e 0x01 in DCR0, 0x05 in DCR2 and 0x24 in DCR3
2427 status = set_reg_sync(serial->port[i],
2428 (__u16)(ATEN2011_port->DcrRegOffset + 0),
2431 DPRINTK("Writing DCR0 failed status-0x%x\n", status);
2434 DPRINTK("DCR0 Writing success status%d\n", status);
2437 status = set_reg_sync(serial->port[i],
2438 (__u16)(ATEN2011_port->DcrRegOffset + 1),
2441 DPRINTK("Writing DCR1 failed status-0x%x\n", status);
2444 DPRINTK("DCR1 Writing success status%d\n", status);
2447 status = set_reg_sync(serial->port[i],
2448 (__u16)(ATEN2011_port->DcrRegOffset + 2),
2451 DPRINTK("Writing DCR2 failed status-0x%x\n", status);
2454 DPRINTK("DCR2 Writing success status%d\n", status);
2456 // write values in clkstart0x0 and clkmulti 0x20
2458 status = set_reg_sync(serial->port[i], CLK_START_VALUE_REGISTER,
2462 ("Writing CLK_START_VALUE_REGISTER failed status-0x%x\n",
2467 ("CLK_START_VALUE_REGISTER Writing success status%d\n",
2471 status = set_reg_sync(serial->port[i], CLK_MULTI_REGISTER,
2475 ("Writing CLK_MULTI_REGISTER failed status-0x%x\n",
2479 DPRINTK("CLK_MULTI_REGISTER Writing success status%d\n",
2482 //Zero Length flag register
2483 if ((ATEN2011_port->port_num != 1)
2484 && (ATEN2011_serial->ATEN2011_spectrum_2or4ports == 2)) {
2487 status = set_reg_sync(serial->port[i],
2488 (__u16)(ZLP_REG1 + ((__u16)ATEN2011_port->port_num)),
2490 DPRINTK("ZLIP offset%x\n",
2492 ((__u16) ATEN2011_port->port_num)));
2495 ("Writing ZLP_REG%d failed status-0x%x\n",
2499 DPRINTK("ZLP_REG%d Writing success status%d\n",
2503 status = set_reg_sync(serial->port[i],
2504 (__u16)(ZLP_REG1 + ((__u16)ATEN2011_port->port_num) - 0x1),
2506 DPRINTK("ZLIP offset%x\n",
2508 ((__u16) ATEN2011_port->port_num) -
2512 ("Writing ZLP_REG%d failed status-0x%x\n",
2516 DPRINTK("ZLP_REG%d Writing success status%d\n",
2520 ATEN2011_port->control_urb = usb_alloc_urb(0, GFP_ATOMIC);
2521 ATEN2011_port->ctrl_buf = kmalloc(16, GFP_KERNEL);
2525 //Zero Length flag enable
2527 status = set_reg_sync(serial->port[0], ZLP_REG5, Data);
2529 DPRINTK("Writing ZLP_REG5 failed status-0x%x\n", status);
2532 DPRINTK("ZLP_REG5 Writing success status%d\n", status);
2534 /* setting configuration feature to one */
2535 usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
2536 (__u8) 0x03, 0x00, 0x01, 0x00, NULL, 0x00, 5 * HZ);
2540 static void ATEN2011_shutdown(struct usb_serial *serial)
2543 struct ATENINTL_port *ATEN2011_port;
2544 DPRINTK("%s \n", " shutdown :entering..........");
2551 DPRINTK("%s", "Invalid Handler \n");
2555 /* check for the ports to be closed,close the ports and disconnect */
2557 /* free private structure allocated for serial port *
2558 * stop reads and writes on all ports */
2560 for (i = 0; i < serial->num_ports; ++i) {
2561 ATEN2011_port = ATEN2011_get_port_private(serial->port[i]);
2562 kfree(ATEN2011_port->ctrl_buf);
2563 usb_kill_urb(ATEN2011_port->control_urb);
2564 kfree(ATEN2011_port);
2565 ATEN2011_set_port_private(serial->port[i], NULL);
2568 /* free private structure allocated for serial device */
2570 kfree(ATEN2011_get_serial_private(serial));
2571 ATEN2011_set_serial_private(serial, NULL);
2573 DPRINTK("%s\n", "Thank u :: ");
2577 static struct usb_serial_driver aten_serial_driver = {
2579 .owner = THIS_MODULE,
2582 .description = DRIVER_DESC,
2583 .id_table = id_table,
2584 .open = ATEN2011_open,
2585 .close = ATEN2011_close,
2586 .write = ATEN2011_write,
2587 .write_room = ATEN2011_write_room,
2588 .chars_in_buffer = ATEN2011_chars_in_buffer,
2589 .throttle = ATEN2011_throttle,
2590 .unthrottle = ATEN2011_unthrottle,
2591 .calc_num_ports = ATEN2011_calc_num_ports,
2593 .ioctl = ATEN2011_ioctl,
2594 .set_termios = ATEN2011_set_termios,
2595 .break_ctl = ATEN2011_break,
2596 .tiocmget = ATEN2011_tiocmget,
2597 .tiocmset = ATEN2011_tiocmset,
2598 .attach = ATEN2011_startup,
2599 .shutdown = ATEN2011_shutdown,
2600 .read_bulk_callback = ATEN2011_bulk_in_callback,
2601 .read_int_callback = ATEN2011_interrupt_callback,
2604 static struct usb_driver aten_driver = {
2606 .probe = usb_serial_probe,
2607 .disconnect = usb_serial_disconnect,
2608 .id_table = id_table,
2611 static int __init aten_init(void)
2615 /* Register with the usb serial */
2616 retval = usb_serial_register(&aten_serial_driver);
2620 printk(KERN_INFO KBUILD_MODNAME ":"
2621 DRIVER_DESC " " DRIVER_VERSION "\n");
2623 /* Register with the usb */
2624 retval = usb_register(&aten_driver);
2626 usb_serial_deregister(&aten_serial_driver);
2631 static void __exit aten_exit(void)
2633 usb_deregister(&aten_driver);
2634 usb_serial_deregister(&aten_serial_driver);
2637 module_init(aten_init);
2638 module_exit(aten_exit);
2640 /* Module information */
2641 MODULE_DESCRIPTION(DRIVER_DESC);
2642 MODULE_LICENSE("GPL");
2644 MODULE_PARM_DESC(debug, "Debug enabled or not");