2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 /*************************************************************************
18 *** --------------------------------------------------------------------
20 *** Project Name: ATENINTL
22 *** Module Name: ATEN2011
27 *** File Revision: 1.2
29 *** Revision Date: 2009-01-16
32 *** Purpose : It gives an interface between USB to 4 Serial
33 *** and serves as a Serial Driver for the high
34 *** level layers /applications.
37 *** Modified from ATEN revision 1.2 for Linux kernel 2.6.26 or later
42 *** DBG - Code inserted due to as part of debugging
43 *** DPRINTK - Debug Print statement
45 *************************************************************************/
47 /* all file inclusion goes here */
49 #include <linux/kernel.h>
50 #include <linux/errno.h>
51 #include <linux/init.h>
52 #include <linux/slab.h>
53 #include <linux/tty.h>
54 #include <linux/tty_driver.h>
55 #include <linux/tty_flip.h>
56 #include <linux/module.h>
57 //#include <linux/spinlock.h>
58 #include <linux/serial.h>
59 //#include <linux/ioctl.h>
60 #include <linux/usb.h>
61 #include <asm/uaccess.h>
65 #include <linux/usb/serial.h>
67 #define MAX_RS232_PORTS 2 /* Max # of RS-232 ports per device */
69 #include <linux/version.h>
72 * All typedef goes here
76 /* typedefs that the insideout headers need */
87 #define LOW8(val) ((unsigned char)(val & 0xff))
91 #define HIGH8(val) ((unsigned char)((val & 0xff00) >> 8))
95 #define NUM_ENTRIES(x) (sizeof(x)/sizeof((x)[0]))
98 #define MAX_SERIALNUMBER_LEN 12
100 /* The following table is used to map the USBx port number to
101 * the device serial number (or physical USB path), */
103 #define MAX_ATENPORTS 2
104 #define MAX_NAME_LEN 64
106 #define RAID_REG1 0x30
107 #define RAID_REG2 0x31
109 #define ZLP_REG1 0x3A //Zero_Flag_Reg1 58
110 #define ZLP_REG2 0x3B //Zero_Flag_Reg2 59
111 #define ZLP_REG3 0x3C //Zero_Flag_Reg3 60
112 #define ZLP_REG4 0x3D //Zero_Flag_Reg4 61
113 #define ZLP_REG5 0x3E //Zero_Flag_Reg5 62
115 #define THRESHOLD_VAL_SP1_1 0x3F
116 #define THRESHOLD_VAL_SP1_2 0x40
117 #define THRESHOLD_VAL_SP2_1 0x41
118 #define THRESHOLD_VAL_SP2_2 0x42
120 #define THRESHOLD_VAL_SP3_1 0x43
121 #define THRESHOLD_VAL_SP3_2 0x44
122 #define THRESHOLD_VAL_SP4_1 0x45
123 #define THRESHOLD_VAL_SP4_2 0x46
126 /* For higher baud Rates use TIOCEXBAUD */
127 #define TIOCEXBAUD 0x5462
129 #define BAUD_1152 0 /* 115200bps * 1 */
130 #define BAUD_2304 1 /* 230400bps * 2 */
131 #define BAUD_4032 2 /* 403200bps * 3.5 */
132 #define BAUD_4608 3 /* 460800bps * 4 */
133 #define BAUD_8064 4 /* 806400bps * 7 */
134 #define BAUD_9216 5 /* 921600bps * 8 */
136 #define CHASE_TIMEOUT (5*HZ) /* 5 seconds */
137 #define OPEN_TIMEOUT (5*HZ) /* 5 seconds */
138 #define COMMAND_TIMEOUT (5*HZ) /* 5 seconds */
141 #define SERIAL_MAGIC 0x6702
144 #define PORT_MAGIC 0x7301
148 /* vendor id and device id defines */
150 #define USB_VENDOR_ID_ATENINTL 0x0557
151 #define ATENINTL_DEVICE_ID_2011 0x2011
152 #define ATENINTL_DEVICE_ID_7820 0x7820
154 /* Product information read from the ATENINTL. Provided for later upgrade */
156 /* Interrupt Rotinue Defines */
158 #define SERIAL_IIR_RLS 0x06
159 #define SERIAL_IIR_RDA 0x04
160 #define SERIAL_IIR_CTI 0x0c
161 #define SERIAL_IIR_THR 0x02
162 #define SERIAL_IIR_MS 0x00
165 * Emulation of the bit mask on the LINE STATUS REGISTER.
167 #define SERIAL_LSR_DR 0x0001
168 #define SERIAL_LSR_OE 0x0002
169 #define SERIAL_LSR_PE 0x0004
170 #define SERIAL_LSR_FE 0x0008
171 #define SERIAL_LSR_BI 0x0010
172 #define SERIAL_LSR_THRE 0x0020
173 #define SERIAL_LSR_TEMT 0x0040
174 #define SERIAL_LSR_FIFOERR 0x0080
176 //MSR bit defines(place holders)
177 #define ATEN_MSR_CTS 0x01
178 #define ATEN_MSR_DSR 0x02
179 #define ATEN_MSR_RI 0x04
180 #define ATEN_MSR_CD 0x08
181 #define ATEN_MSR_DELTA_CTS 0x10
182 #define ATEN_MSR_DELTA_DSR 0x20
183 #define ATEN_MSR_DELTA_RI 0x40
184 #define ATEN_MSR_DELTA_CD 0x80
186 // Serial Port register Address
187 #define RECEIVE_BUFFER_REGISTER ((__u16)(0x00))
188 #define TRANSMIT_HOLDING_REGISTER ((__u16)(0x00))
189 #define INTERRUPT_ENABLE_REGISTER ((__u16)(0x01))
190 #define INTERRUPT_IDENT_REGISTER ((__u16)(0x02))
191 #define FIFO_CONTROL_REGISTER ((__u16)(0x02))
192 #define LINE_CONTROL_REGISTER ((__u16)(0x03))
193 #define MODEM_CONTROL_REGISTER ((__u16)(0x04))
194 #define LINE_STATUS_REGISTER ((__u16)(0x05))
195 #define MODEM_STATUS_REGISTER ((__u16)(0x06))
196 #define SCRATCH_PAD_REGISTER ((__u16)(0x07))
197 #define DIVISOR_LATCH_LSB ((__u16)(0x00))
198 #define DIVISOR_LATCH_MSB ((__u16)(0x01))
200 #define SP_REGISTER_BASE ((__u16)(0x08))
201 #define CONTROL_REGISTER_BASE ((__u16)(0x09))
202 #define DCR_REGISTER_BASE ((__u16)(0x16))
204 #define SP1_REGISTER ((__u16)(0x00))
205 #define CONTROL1_REGISTER ((__u16)(0x01))
206 #define CLK_MULTI_REGISTER ((__u16)(0x02))
207 #define CLK_START_VALUE_REGISTER ((__u16)(0x03))
208 #define DCR1_REGISTER ((__u16)(0x04))
209 #define GPIO_REGISTER ((__u16)(0x07))
211 #define CLOCK_SELECT_REG1 ((__u16)(0x13))
212 #define CLOCK_SELECT_REG2 ((__u16)(0x14))
214 #define SERIAL_LCR_DLAB ((__u16)(0x0080))
217 * URB POOL related defines
219 #define NUM_URBS 16 /* URB Count */
220 #define URB_TRANSFER_BUFFER_SIZE 32 /* URB Size */
222 struct ATENINTL_product_info
224 __u16 ProductId; /* Product Identifier */
225 __u8 NumPorts; /* Number of ports on ATENINTL */
226 __u8 ProdInfoVer; /* What version of structure is this? */
228 __u32 IsServer :1; /* Set if Server */
229 __u32 IsRS232 :1; /* Set if RS-232 ports exist */
230 __u32 IsRS422 :1; /* Set if RS-422 ports exist */
231 __u32 IsRS485 :1; /* Set if RS-485 ports exist */
232 __u32 IsReserved :28; /* Reserved for later expansion */
234 __u8 CpuRev; /* CPU revision level (chg only if s/w visible) */
235 __u8 BoardRev; /* PCB revision level (chg only if s/w visible) */
237 __u8 ManufactureDescDate[3]; /* MM/DD/YY when descriptor template was compiled */
238 __u8 Unused1[1]; /* Available */
241 // different USB-serial Adapter's ID's table
242 static struct usb_device_id ATENINTL_port_id_table [] = {
243 { USB_DEVICE(USB_VENDOR_ID_ATENINTL,ATENINTL_DEVICE_ID_2011) },
244 { USB_DEVICE(USB_VENDOR_ID_ATENINTL,ATENINTL_DEVICE_ID_7820) },
245 { } /* terminating entry */
248 static __devinitdata struct usb_device_id id_table_combined [] = {
249 { USB_DEVICE(USB_VENDOR_ID_ATENINTL,ATENINTL_DEVICE_ID_2011) },
250 { USB_DEVICE(USB_VENDOR_ID_ATENINTL,ATENINTL_DEVICE_ID_7820) },
251 { } /* terminating entry */
254 MODULE_DEVICE_TABLE (usb, id_table_combined);
256 /* This structure holds all of the local port information */
259 int port_num; /*Actual port number in the device(1,2,etc)*/
260 __u8 bulk_out_endpoint; /* the bulk out endpoint handle */
261 unsigned char *bulk_out_buffer; /* buffer used for the bulk out endpoint */
262 struct urb *write_urb; /* write URB for this port */
263 __u8 bulk_in_endpoint; /* the bulk in endpoint handle */
264 unsigned char *bulk_in_buffer; /* the buffer we use for the bulk in endpoint */
265 struct urb *read_urb; /* read URB for this port */
266 __s16 rxBytesAvail;/*the number of bytes that we need to read from this device */
267 __s16 rxBytesRemaining; /* the number of port bytes left to read */
268 char write_in_progress; /* TRUE while a write URB is outstanding */
269 __u8 shadowLCR; /* last LCR value received */
270 __u8 shadowMCR; /* last MCR value received */
271 __u8 shadowMSR; /* last MSR value received */
272 __u8 shadowLSR; /* last LSR value received */
273 __u8 shadowXonChar; /* last value set as XON char in ATENINTL */
274 __u8 shadowXoffChar; /* last value set as XOFF char in ATENINTL */
281 char chaseResponsePending;
282 wait_queue_head_t wait_chase; /* for handling sleeping while waiting for chase to finish */
283 wait_queue_head_t wait_open; /* for handling sleeping while waiting for open to finish */
284 wait_queue_head_t wait_command; /* for handling sleeping while waiting for command to finish */
285 wait_queue_head_t delta_msr_wait; /* for handling sleeping while waiting for msr change to happen */
287 struct async_icount icount;
288 struct usb_serial_port *port; /* loop back to the owner of this object */
292 __u8 ControlRegOffset;
294 __u8 ClkSelectRegOffset;
295 //for processing control URBS in interrupt context
296 struct urb *control_urb;
301 struct urb *write_urb_pool[NUM_URBS];
302 /* we pass a pointer to this as the arguement sent to cypress_set_termios old_termios */
303 struct ktermios tmp_termios; /* stores the old termios settings */
304 spinlock_t lock; /* private lock */
308 /* This structure holds all of the individual serial device information */
309 struct ATENINTL_serial
311 char name[MAX_NAME_LEN+1]; /* string name of this device */
312 struct ATENINTL_product_info product_info; /* Product Info */
313 __u8 interrupt_in_endpoint; /* the interrupt endpoint handle */
314 unsigned char *interrupt_in_buffer; /* the buffer we use for the interrupt endpoint */
315 struct urb * interrupt_read_urb; /* our interrupt urb */
316 __u8 bulk_in_endpoint; /* the bulk in endpoint handle */
317 unsigned char *bulk_in_buffer; /* the buffer we use for the bulk in endpoint */
318 struct urb *read_urb; /* our bulk read urb */
319 __u8 bulk_out_endpoint; /* the bulk out endpoint handle */
320 __s16 rxBytesAvail; /* the number of bytes that we need to read from this device */
321 __u8 rxPort; /* the port that we are currently receiving data for */
322 __u8 rxStatusCode; /* the receive status code */
323 __u8 rxStatusParam; /* the receive status paramater */
324 __s16 rxBytesRemaining; /* the number of port bytes left to read */
325 struct usb_serial *serial; /* loop back to the owner of this object */
326 int ATEN2011_spectrum_2or4ports; //this says the number of ports in the device
327 // Indicates about the no.of opened ports of an individual USB-serial adapater.
328 unsigned int NoOfOpenPorts;
329 // a flag for Status endpoint polling
330 unsigned char status_polling_started;
333 /* baud rate information */
334 struct ATEN2011_divisor_table_entry
340 /* Define table of divisors for ATENINTL 2011 hardware *
341 * These assume a 3.6864MHz crystal, the standard /16, and *
344 static struct ATEN2011_divisor_table_entry ATEN2011_divisor_table[] = {
346 { 110, 1047}, /* 2094.545455 => 230450 => .0217 % over */
347 { 134, 857}, /* 1713.011152 => 230398.5 => .00065% under */
364 /* local function prototypes */
365 /* function prototypes for all URB callbacks */
366 static void ATEN2011_interrupt_callback(struct urb *urb);
367 static void ATEN2011_bulk_in_callback(struct urb *urb);
368 static void ATEN2011_bulk_out_data_callback(struct urb *urb);
369 static void ATEN2011_control_callback(struct urb *urb);
370 static int ATEN2011_get_reg(struct ATENINTL_port *ATEN,__u16 Wval, __u16 reg, __u16 * val);
371 int handle_newMsr(struct ATENINTL_port *port,__u8 newMsr);
372 int handle_newLsr(struct ATENINTL_port *port,__u8 newLsr);
373 /* function prototypes for the usbserial callbacks */
375 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
376 static int ATEN2011_open(struct tty_struct *tty, struct usb_serial_port *port, struct file *filp);
377 static void ATEN2011_close(struct tty_struct *tty, struct usb_serial_port *port, struct file *filp);
378 static int ATEN2011_write(struct tty_struct *tty, struct usb_serial_port *port, const unsigned char *data, int count);
379 static int ATEN2011_write_room(struct tty_struct *tty);
380 static int ATEN2011_chars_in_buffer(struct tty_struct *tty);
381 static void ATEN2011_throttle(struct tty_struct *tty);
382 static void ATEN2011_unthrottle(struct tty_struct *tty);
383 static void ATEN2011_set_termios(struct tty_struct *tty, struct usb_serial_port *port, struct ktermios *old_termios);
384 static int ATEN2011_tiocmset(struct tty_struct *tty, struct file *file,
385 unsigned int set, unsigned int clear);
386 static int ATEN2011_tiocmget(struct tty_struct *tty, struct file *file);
387 static int ATEN2011_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg);
388 static void ATEN2011_break(struct tty_struct *tty, int break_state);
390 static int ATEN2011_open(struct usb_serial_port *port, struct file *filp);
391 static void ATEN2011_close(struct usb_serial_port *port, struct file *filp);
392 static int ATEN2011_write(struct usb_serial_port *port, const unsigned char *data, int count);
393 static int ATEN2011_write_room(struct usb_serial_port *port);
394 static int ATEN2011_chars_in_buffer(struct usb_serial_port *port);
395 static void ATEN2011_throttle(struct usb_serial_port *port);
396 static void ATEN2011_unthrottle(struct usb_serial_port *port);
397 static void ATEN2011_set_termios (struct usb_serial_port *port, struct ktermios *old_termios);
398 static int ATEN2011_tiocmset(struct usb_serial_port *port, struct file *file,
399 unsigned int set, unsigned int clear);
400 static int ATEN2011_tiocmget(struct usb_serial_port *port, struct file *file);
401 static int ATEN2011_ioctl(struct usb_serial_port *port, struct file *file, unsigned int cmd, unsigned long arg);
402 static void ATEN2011_break(struct usb_serial_port *port, int break_state);
405 //static void ATEN2011_break_ctl(struct usb_serial_port *port, int break_state );
407 static int ATEN2011_startup(struct usb_serial *serial);
408 static void ATEN2011_shutdown(struct usb_serial *serial);
409 //static int ATEN2011_serial_probe(struct usb_serial *serial, const struct usb_device_id *id);
410 static int ATEN2011_calc_num_ports(struct usb_serial *serial);
412 /* function prototypes for all of our local functions */
413 static int ATEN2011_calc_baud_rate_divisor(int baudRate, int *divisor,__u16 *clk_sel_val);
414 static int ATEN2011_send_cmd_write_baud_rate(struct ATENINTL_port *ATEN2011_port, int baudRate);
415 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
416 static void ATEN2011_change_port_settings(struct tty_struct *tty, struct ATENINTL_port *ATEN2011_port, struct ktermios *old_termios);
417 static void ATEN2011_block_until_chase_response(struct tty_struct *tty, struct ATENINTL_port *ATEN2011_port);
418 static void ATEN2011_block_until_tx_empty(struct tty_struct *tty, struct ATENINTL_port *ATEN2011_port);
420 static void ATEN2011_change_port_settings(struct ATENINTL_port *ATEN2011_port, struct ktermios *old_termios);
421 static void ATEN2011_block_until_chase_response(struct ATENINTL_port *ATEN2011_port);
422 static void ATEN2011_block_until_tx_empty(struct ATENINTL_port *ATEN2011_port);
425 int __init ATENINTL2011_init(void);
426 void __exit ATENINTL2011_exit(void);
429 /*************************************
430 * Bit definitions for each register *
431 *************************************/
432 #define LCR_BITS_5 0x00 /* 5 bits/char */
433 #define LCR_BITS_6 0x01 /* 6 bits/char */
434 #define LCR_BITS_7 0x02 /* 7 bits/char */
435 #define LCR_BITS_8 0x03 /* 8 bits/char */
436 #define LCR_BITS_MASK 0x03 /* Mask for bits/char field */
438 #define LCR_STOP_1 0x00 /* 1 stop bit */
439 #define LCR_STOP_1_5 0x04 /* 1.5 stop bits (if 5 bits/char) */
440 #define LCR_STOP_2 0x04 /* 2 stop bits (if 6-8 bits/char) */
441 #define LCR_STOP_MASK 0x04 /* Mask for stop bits field */
443 #define LCR_PAR_NONE 0x00 /* No parity */
444 #define LCR_PAR_ODD 0x08 /* Odd parity */
445 #define LCR_PAR_EVEN 0x18 /* Even parity */
446 #define LCR_PAR_MARK 0x28 /* Force parity bit to 1 */
447 #define LCR_PAR_SPACE 0x38 /* Force parity bit to 0 */
448 #define LCR_PAR_MASK 0x38 /* Mask for parity field */
450 #define LCR_SET_BREAK 0x40 /* Set Break condition */
451 #define LCR_DL_ENABLE 0x80 /* Enable access to divisor latch */
453 #define MCR_DTR 0x01 /* Assert DTR */
454 #define MCR_RTS 0x02 /* Assert RTS */
455 #define MCR_OUT1 0x04 /* Loopback only: Sets state of RI */
456 #define MCR_MASTER_IE 0x08 /* Enable interrupt outputs */
457 #define MCR_LOOPBACK 0x10 /* Set internal (digital) loopback mode */
458 #define MCR_XON_ANY 0x20 /* Enable any char to exit XOFF mode */
460 #define ATEN2011_MSR_CTS 0x10 /* Current state of CTS */
461 #define ATEN2011_MSR_DSR 0x20 /* Current state of DSR */
462 #define ATEN2011_MSR_RI 0x40 /* Current state of RI */
463 #define ATEN2011_MSR_CD 0x80 /* Current state of CD */
466 /* all defines goes here */
469 * Debug related defines
472 /* 1: Enables the debugging -- 0: Disable the debugging */
479 static int debug = 0;
480 #define DPRINTK(fmt, args...) printk( "%s: " fmt, __FUNCTION__ , ## args)
483 static int debug = 0;
484 #define DPRINTK(fmt, args...)
488 // #define DPRINTK(fmt, args...)
491 * Version Information
493 #define DRIVER_VERSION "1.3.1"
494 #define DRIVER_DESC "ATENINTL 2011 USB Serial Adapter"
497 * Defines used for sending commands to port
500 #define WAIT_FOR_EVER (HZ * 0 ) /* timeout urb is wait for ever */
501 #define ATEN_WDR_TIMEOUT (HZ * 5 ) /* default urb timeout */
503 #define ATEN_PORT1 0x0200
504 #define ATEN_PORT2 0x0300
505 #define ATEN_VENREG 0x0000
506 #define ATEN_MAX_PORT 0x02
507 #define ATEN_WRITE 0x0E
508 #define ATEN_READ 0x0D
511 #define ATEN_RD_RTYPE 0xC0
512 #define ATEN_WR_RTYPE 0x40
513 #define ATEN_RDREQ 0x0D
514 #define ATEN_WRREQ 0x0E
515 #define ATEN_CTRL_TIMEOUT 500
516 #define VENDOR_READ_LENGTH (0x01)
518 int ATEN2011_Thr_cnt;
519 //int ATEN2011_spectrum_2or4ports; //this says the number of ports in the device
522 int RS485mode = 0; //set to 1 for RS485 mode and 0 for RS232 mode
524 static struct usb_serial *ATEN2011_get_usb_serial(struct usb_serial_port *port, const
526 static int ATEN2011_serial_paranoia_check(struct usb_serial *serial, const char
528 static int ATEN2011_port_paranoia_check(struct usb_serial_port *port, const char
531 /* setting and get register values */
532 static int ATEN2011_set_reg_sync(struct usb_serial_port *port, __u16 reg,
534 static int ATEN2011_get_reg_sync(struct usb_serial_port *port, __u16 reg,
536 static int ATEN2011_set_Uart_Reg(struct usb_serial_port *port, __u16 reg,
538 static int ATEN2011_get_Uart_Reg(struct usb_serial_port *port, __u16 reg,
541 void ATEN2011_Dump_serial_port(struct ATENINTL_port *ATEN2011_port);
543 /************************************************************************/
544 /************************************************************************/
545 /* I N T E R F A C E F U N C T I O N S */
546 /* I N T E R F A C E F U N C T I O N S */
547 /************************************************************************/
548 /************************************************************************/
550 static inline void ATEN2011_set_serial_private(struct usb_serial *serial,
551 struct ATENINTL_serial *data)
553 usb_set_serial_data(serial, (void *)data);
556 static inline struct ATENINTL_serial *ATEN2011_get_serial_private(struct
560 return (struct ATENINTL_serial *)usb_get_serial_data(serial);
563 static inline void ATEN2011_set_port_private(struct usb_serial_port *port,
564 struct ATENINTL_port *data)
566 usb_set_serial_port_data(port, (void *)data);
569 static inline struct ATENINTL_port *ATEN2011_get_port_private(struct
573 return (struct ATENINTL_port *)usb_get_serial_port_data(port);
577 Description:- To set the Control register by calling usb_fill_control_urb function by passing usb_sndctrlpipe function as parameter.
580 usb_serial_port: Data Structure usb_serialport correponding to that seril port.
581 Reg: Register Address
582 Val: Value to set in the Register.
585 static int ATEN2011_set_reg_sync(struct usb_serial_port *port, __u16 reg,
588 struct usb_device *dev = port->serial->dev;
590 DPRINTK("ATEN2011_set_reg_sync offset is %x, value %x\n", reg, val);
592 return usb_control_msg(dev, usb_sndctrlpipe(dev, 0), ATEN_WRREQ,
593 ATEN_WR_RTYPE, val, reg, NULL, 0,
598 Description:- To set the Uart register by calling usb_fill_control_urb function by passing usb_rcvctrlpipe function as parameter.
601 usb_serial_port: Data Structure usb_serialport correponding to that seril port.
602 Reg: Register Address
603 Val: Value to receive from the Register.
606 static int ATEN2011_get_reg_sync(struct usb_serial_port *port, __u16 reg,
609 struct usb_device *dev = port->serial->dev;
612 ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), ATEN_RDREQ,
613 ATEN_RD_RTYPE, 0, reg, val, VENDOR_READ_LENGTH,
615 DPRINTK("ATEN2011_get_reg_sync offset is %x, return val %x\n", reg,
617 *val = (*val) & 0x00ff;
622 Description:- To set the Uart register by calling usb_fill_control_urb function by passing usb_sndctrlpipe function as parameter.
625 usb_serial_port: Data Structure usb_serialport correponding to that seril port.
626 Reg: Register Address
627 Val: Value to set in the Register.
630 static int ATEN2011_set_Uart_Reg(struct usb_serial_port *port, __u16 reg,
634 struct usb_device *dev = port->serial->dev;
635 struct ATENINTL_serial *ATEN2011_serial;
637 ATEN2011_serial = ATEN2011_get_serial_private(port->serial);
638 minor = port->serial->minor;
639 if (minor == SERIAL_TTY_NO_MINOR)
642 // For the UART control registers, the application number need to be Or'ed
644 if (ATEN2011_serial->ATEN2011_spectrum_2or4ports == 4) {
645 val |= (((__u16) port->number - (__u16) (minor)) + 1) << 8;
646 DPRINTK("ATEN2011_set_Uart_Reg application number is %x\n",
649 if (((__u16) port->number - (__u16) (minor)) == 0) {
652 (((__u16) port->number - (__u16) (minor)) + 1) << 8;
654 ("ATEN2011_set_Uart_Reg application number is %x\n",
659 (((__u16) port->number - (__u16) (minor)) + 2) << 8;
661 ("ATEN2011_set_Uart_Reg application number is %x\n",
665 return usb_control_msg(dev, usb_sndctrlpipe(dev, 0), ATEN_WRREQ,
666 ATEN_WR_RTYPE, val, reg, NULL, 0,
672 Description:- To set the Control register by calling usb_fill_control_urb function by passing usb_rcvctrlpipe function as parameter.
675 usb_serial_port: Data Structure usb_serialport correponding to that seril port.
676 Reg: Register Address
677 Val: Value to receive from the Register.
679 static int ATEN2011_get_Uart_Reg(struct usb_serial_port *port, __u16 reg,
682 struct usb_device *dev = port->serial->dev;
685 struct ATENINTL_serial *ATEN2011_serial;
686 int minor = port->serial->minor;
687 ATEN2011_serial = ATEN2011_get_serial_private(port->serial);
688 if (minor == SERIAL_TTY_NO_MINOR)
691 //DPRINTK("application number is %4x \n",(((__u16)port->number - (__u16)(minor))+1)<<8);
692 /*Wval is same as application number */
693 if (ATEN2011_serial->ATEN2011_spectrum_2or4ports == 4) {
694 Wval = (((__u16) port->number - (__u16) (minor)) + 1) << 8;
695 DPRINTK("ATEN2011_get_Uart_Reg application number is %x\n",
698 if (((__u16) port->number - (__u16) (minor)) == 0) {
701 (((__u16) port->number - (__u16) (minor)) + 1) << 8;
703 ("ATEN2011_get_Uart_Reg application number is %x\n",
708 (((__u16) port->number - (__u16) (minor)) + 2) << 8;
710 ("ATEN2011_get_Uart_Reg application number is %x\n",
714 ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), ATEN_RDREQ,
715 ATEN_RD_RTYPE, Wval, reg, val, VENDOR_READ_LENGTH,
717 *val = (*val) & 0x00ff;
721 void ATEN2011_Dump_serial_port(struct ATENINTL_port *ATEN2011_port)
724 DPRINTK("***************************************\n");
725 DPRINTK("Application number is %4x\n", ATEN2011_port->AppNum);
726 DPRINTK("SpRegOffset is %2x\n", ATEN2011_port->SpRegOffset);
727 DPRINTK("ControlRegOffset is %2x \n", ATEN2011_port->ControlRegOffset);
728 DPRINTK("DCRRegOffset is %2x \n", ATEN2011_port->DcrRegOffset);
729 //DPRINTK("ClkSelectRegOffset is %2x \n",ATEN2011_port->ClkSelectRegOffset);
730 DPRINTK("***************************************\n");
734 /* all structre defination goes here */
735 /****************************************************************************
736 * ATENINTL2011_4port_device
737 * Structure defining ATEN2011, usb serial device
738 ****************************************************************************/
739 static struct usb_serial_driver ATENINTL2011_4port_device = {
741 .owner = THIS_MODULE,
744 .description = DRIVER_DESC,
745 .id_table = ATENINTL_port_id_table,
746 .open = ATEN2011_open,
747 .close = ATEN2011_close,
748 .write = ATEN2011_write,
749 .write_room = ATEN2011_write_room,
750 .chars_in_buffer = ATEN2011_chars_in_buffer,
751 .throttle = ATEN2011_throttle,
752 .unthrottle = ATEN2011_unthrottle,
753 .calc_num_ports = ATEN2011_calc_num_ports,
755 #ifdef ATENSerialProbe
756 .probe = ATEN2011_serial_probe,
758 .ioctl = ATEN2011_ioctl,
759 .set_termios = ATEN2011_set_termios,
760 .break_ctl = ATEN2011_break,
761 // .break_ctl = ATEN2011_break_ctl,
762 .tiocmget = ATEN2011_tiocmget,
763 .tiocmset = ATEN2011_tiocmset,
764 .attach = ATEN2011_startup,
765 .shutdown = ATEN2011_shutdown,
766 .read_bulk_callback = ATEN2011_bulk_in_callback,
767 .read_int_callback = ATEN2011_interrupt_callback,
770 static struct usb_driver io_driver = {
772 .probe = usb_serial_probe,
773 .disconnect = usb_serial_disconnect,
774 .id_table = id_table_combined,
777 /************************************************************************/
778 /************************************************************************/
779 /* U S B C A L L B A C K F U N C T I O N S */
780 /* U S B C A L L B A C K F U N C T I O N S */
781 /************************************************************************/
782 /************************************************************************/
784 /*****************************************************************************
785 * ATEN2011_interrupt_callback
786 * this is the callback function for when we have received data on the
787 * interrupt endpoint.
789 * pointer to the URB packet,
791 *****************************************************************************/
793 static void ATEN2011_interrupt_callback(struct urb *urb)
797 struct ATENINTL_port *ATEN2011_port;
798 struct ATENINTL_serial *ATEN2011_serial;
799 struct usb_serial *serial;
806 //printk("in the function ATEN2011_interrupt_callback Length %d, Data %x \n",urb->actual_length,(unsigned int)urb->transfer_buffer);
807 DPRINTK("%s", " : Entering\n");
809 ATEN2011_serial = (struct ATENINTL_serial *)urb->context;
810 if (!urb) // || ATEN2011_serial->status_polling_started == FALSE )
812 DPRINTK("%s", "Invalid Pointer !!!!:\n");
816 switch (urb->status) {
823 /* this urb is terminated, clean up */
824 dbg("%s - urb shutting down with status: %d", __FUNCTION__,
828 dbg("%s - nonzero urb status received: %d", __FUNCTION__,
832 length = urb->actual_length;
833 data = urb->transfer_buffer;
835 //ATEN2011_serial= (struct ATENINTL_serial *)urb->context;
836 //serial = ATEN2011_get_usb_serial(port,__FUNCTION__);
837 serial = ATEN2011_serial->serial;
839 /* ATENINTL get 5 bytes
840 * Byte 1 IIR Port 1 (port.number is 0)
841 * Byte 2 IIR Port 2 (port.number is 1)
842 * Byte 3 IIR Port 3 (port.number is 2)
843 * Byte 4 IIR Port 4 (port.number is 3)
844 * Byte 5 FIFO status for both */
846 if (length && length > 5) {
847 DPRINTK("%s \n", "Wrong data !!!");
852 if (ATEN2011_serial->ATEN2011_spectrum_2or4ports == 4) {
853 sp[0] = (__u8) data[0];
854 sp[1] = (__u8) data[1];
855 sp[2] = (__u8) data[2];
856 sp[3] = (__u8) data[3];
859 sp[0] = (__u8) data[0];
860 sp[1] = (__u8) data[2];
861 //sp[2]=(__u8)data[2];
862 //sp[3]=(__u8)data[3];
866 // printk("%s data is sp1:%x sp2:%x sp3:%x sp4:%x status:%x\n",__FUNCTION__,sp1,sp2,sp3,sp4,st);
867 for (i = 0; i < serial->num_ports; i++) {
868 ATEN2011_port = ATEN2011_get_port_private(serial->port[i]);
869 minor = serial->minor;
870 if (minor == SERIAL_TTY_NO_MINOR)
872 if ((ATEN2011_serial->ATEN2011_spectrum_2or4ports == 2)
875 (((__u16) serial->port[i]->number -
876 (__u16) (minor)) + 2) << 8;
879 (((__u16) serial->port[i]->number -
880 (__u16) (minor)) + 1) << 8;
881 if (ATEN2011_port->open != FALSE) {
882 //printk("%s wval is:(for 2011) %x\n",__FUNCTION__,wval);
885 DPRINTK("SP%d No Interrupt !!!\n", i);
887 switch (sp[i] & 0x0f) {
890 ("Serial Port %d: Receiver status error or ",
893 ("address bit detected in 9-bit mode\n");
894 ATEN2011_port->MsrLsr = 1;
895 ATEN2011_get_reg(ATEN2011_port, wval,
896 LINE_STATUS_REGISTER,
901 ("Serial Port %d: Modem status change\n",
903 ATEN2011_port->MsrLsr = 0;
904 ATEN2011_get_reg(ATEN2011_port, wval,
905 MODEM_STATUS_REGISTER,
914 if (ATEN2011_serial->status_polling_started == FALSE)
917 result = usb_submit_urb(urb, GFP_ATOMIC);
919 dev_err(&urb->dev->dev,
920 "%s - Error %d submitting interrupt urb\n",
921 __FUNCTION__, result);
929 static void ATEN2011_control_callback(struct urb *urb)
932 struct ATENINTL_port *ATEN2011_port;
936 DPRINTK("%s", "Invalid Pointer !!!!:\n");
940 switch (urb->status) {
947 /* this urb is terminated, clean up */
948 dbg("%s - urb shutting down with status: %d", __FUNCTION__,
952 dbg("%s - nonzero urb status received: %d", __FUNCTION__,
957 ATEN2011_port = (struct ATENINTL_port *)urb->context;
959 DPRINTK("%s urb buffer size is %d\n", __FUNCTION__, urb->actual_length);
960 DPRINTK("%s ATEN2011_port->MsrLsr is %d port %d\n", __FUNCTION__,
961 ATEN2011_port->MsrLsr, ATEN2011_port->port_num);
962 data = urb->transfer_buffer;
963 regval = (__u8) data[0];
964 DPRINTK("%s data is %x\n", __FUNCTION__, regval);
965 if (ATEN2011_port->MsrLsr == 0)
966 handle_newMsr(ATEN2011_port, regval);
967 else if (ATEN2011_port->MsrLsr == 1)
968 handle_newLsr(ATEN2011_port, regval);
973 int handle_newMsr(struct ATENINTL_port *port, __u8 newMsr)
975 struct ATENINTL_port *ATEN2011_port;
976 struct async_icount *icount;
977 ATEN2011_port = port;
978 icount = &ATEN2011_port->icount;
980 (ATEN_MSR_DELTA_CTS | ATEN_MSR_DELTA_DSR | ATEN_MSR_DELTA_RI |
981 ATEN_MSR_DELTA_CD)) {
982 icount = &ATEN2011_port->icount;
984 /* update input line counters */
985 if (newMsr & ATEN_MSR_DELTA_CTS) {
988 if (newMsr & ATEN_MSR_DELTA_DSR) {
991 if (newMsr & ATEN_MSR_DELTA_CD) {
994 if (newMsr & ATEN_MSR_DELTA_RI) {
1001 int handle_newLsr(struct ATENINTL_port *port, __u8 newLsr)
1003 struct async_icount *icount;
1005 dbg("%s - %02x", __FUNCTION__, newLsr);
1007 if (newLsr & SERIAL_LSR_BI) {
1009 // Parity and Framing errors only count if they
1010 // occur exclusive of a break being
1013 newLsr &= (__u8) (SERIAL_LSR_OE | SERIAL_LSR_BI);
1016 /* update input line counters */
1017 icount = &port->icount;
1018 if (newLsr & SERIAL_LSR_BI) {
1021 if (newLsr & SERIAL_LSR_OE) {
1024 if (newLsr & SERIAL_LSR_PE) {
1027 if (newLsr & SERIAL_LSR_FE) {
1033 static int ATEN2011_get_reg(struct ATENINTL_port *ATEN, __u16 Wval, __u16 reg,
1036 struct usb_device *dev = ATEN->port->serial->dev;
1037 struct usb_ctrlrequest *dr = NULL;
1038 unsigned char *buffer = NULL;
1040 buffer = (__u8 *) ATEN->ctrl_buf;
1042 // dr=(struct usb_ctrlrequest *)(buffer);
1043 dr = (void *)(buffer + 2);
1044 dr->bRequestType = ATEN_RD_RTYPE;
1045 dr->bRequest = ATEN_RDREQ;
1046 dr->wValue = cpu_to_le16(Wval); //0;
1047 dr->wIndex = cpu_to_le16(reg);
1048 dr->wLength = cpu_to_le16(2);
1050 usb_fill_control_urb(ATEN->control_urb, dev, usb_rcvctrlpipe(dev, 0),
1051 (unsigned char *)dr, buffer, 2,
1052 ATEN2011_control_callback, ATEN);
1053 ATEN->control_urb->transfer_buffer_length = 2;
1054 ret = usb_submit_urb(ATEN->control_urb, GFP_ATOMIC);
1058 /*****************************************************************************
1059 * ATEN2011_bulk_in_callback
1060 * this is the callback function for when we have received data on the
1063 * pointer to the URB packet,
1065 *****************************************************************************/
1066 static void ATEN2011_bulk_in_callback(struct urb *urb)
1069 unsigned char *data;
1070 struct usb_serial *serial;
1071 struct usb_serial_port *port;
1072 struct ATENINTL_serial *ATEN2011_serial;
1073 struct ATENINTL_port *ATEN2011_port;
1074 struct tty_struct *tty;
1076 DPRINTK("%s", "Invalid Pointer !!!!:\n");
1081 DPRINTK("nonzero read bulk status received: %d", urb->status);
1082 // if(urb->status==84)
1087 ATEN2011_port = (struct ATENINTL_port *)urb->context;
1088 if (!ATEN2011_port) {
1089 DPRINTK("%s", "NULL ATEN2011_port pointer \n");
1093 port = (struct usb_serial_port *)ATEN2011_port->port;
1094 if (ATEN2011_port_paranoia_check(port, __FUNCTION__)) {
1095 DPRINTK("%s", "Port Paranoia failed \n");
1099 serial = ATEN2011_get_usb_serial(port, __FUNCTION__);
1101 DPRINTK("%s\n", "Bad serial pointer ");
1105 DPRINTK("%s\n", "Entering... \n");
1107 data = urb->transfer_buffer;
1108 ATEN2011_serial = ATEN2011_get_serial_private(serial);
1110 DPRINTK("%s", "Entering ........... \n");
1112 if (urb->actual_length) {
1114 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,28)
1115 tty = tty_port_tty_get(&ATEN2011_port->port->port);
1116 #elif LINUX_VERSION_CODE == KERNEL_VERSION(2,6,27)
1117 tty = ATEN2011_port->port->port.tty;
1119 tty = ATEN2011_port->port->tty;
1122 tty_buffer_request_room(tty, urb->actual_length);
1123 tty_insert_flip_string(tty, data, urb->actual_length);
1124 DPRINTK(" %s \n", data);
1125 tty_flip_buffer_push(tty);
1126 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,28)
1131 ATEN2011_port->icount.rx += urb->actual_length;
1132 DPRINTK("ATEN2011_port->icount.rx is %d:\n",
1133 ATEN2011_port->icount.rx);
1137 if (!ATEN2011_port->read_urb) {
1138 DPRINTK("%s", "URB KILLED !!!\n");
1142 if (ATEN2011_port->read_urb->status != -EINPROGRESS) {
1143 ATEN2011_port->read_urb->dev = serial->dev;
1145 status = usb_submit_urb(ATEN2011_port->read_urb, GFP_ATOMIC);
1149 (" usb_submit_urb(read bulk) failed, status = %d",
1155 /*****************************************************************************
1156 * ATEN2011_bulk_out_data_callback
1157 * this is the callback function for when we have finished sending serial data
1158 * on the bulk out endpoint.
1160 * pointer to the URB packet,
1162 *****************************************************************************/
1163 static void ATEN2011_bulk_out_data_callback(struct urb *urb)
1165 struct ATENINTL_port *ATEN2011_port;
1166 struct tty_struct *tty;
1168 DPRINTK("%s", "Invalid Pointer !!!!:\n");
1173 DPRINTK("nonzero write bulk status received:%d\n", urb->status);
1177 ATEN2011_port = (struct ATENINTL_port *)urb->context;
1178 if (!ATEN2011_port) {
1179 DPRINTK("%s", "NULL ATEN2011_port pointer \n");
1183 if (ATEN2011_port_paranoia_check(ATEN2011_port->port, __FUNCTION__)) {
1184 DPRINTK("%s", "Port Paranoia failed \n");
1188 DPRINTK("%s \n", "Entering .........");
1190 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,28)
1191 tty = tty_port_tty_get(&ATEN2011_port->port->port);
1192 #elif LINUX_VERSION_CODE == KERNEL_VERSION(2,6,27)
1193 tty = ATEN2011_port->port->port.tty;
1195 tty = ATEN2011_port->port->tty;
1198 if (tty && ATEN2011_port->open) {
1199 /* let the tty driver wakeup if it has a special *
1200 * write_wakeup function */
1202 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27)
1203 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP))
1204 && tty->ldisc.write_wakeup) {
1205 (tty->ldisc.write_wakeup) (tty);
1209 /* tell the tty driver that something has changed */
1210 wake_up_interruptible(&tty->write_wait);
1213 /* Release the Write URB */
1214 ATEN2011_port->write_in_progress = FALSE;
1216 //schedule_work(&ATEN2011_port->port->work);
1217 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,28)
1223 /************************************************************************/
1224 /* D R I V E R T T Y I N T E R F A C E F U N C T I O N S */
1225 /************************************************************************/
1226 #ifdef ATENSerialProbe
1227 static int ATEN2011_serial_probe(struct usb_serial *serial,
1228 const struct usb_device_id *id)
1231 /*need to implement the mode_reg reading and updating\
1232 structures usb_serial_ device_type\
1233 (i.e num_ports, num_bulkin,bulkout etc) */
1234 /* Also we can update the changes attach */
1239 /*****************************************************************************
1241 * this function is called by the tty driver when a port is opened
1242 * If successful, we return 0
1243 * Otherwise we return a negative error number.
1244 *****************************************************************************/
1246 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
1247 static int ATEN2011_open(struct tty_struct *tty, struct usb_serial_port *port,
1250 static int ATEN2011_open(struct usb_serial_port *port, struct file *filp)
1255 struct usb_serial *serial;
1256 // struct usb_serial_port *port0;
1260 struct ATENINTL_serial *ATEN2011_serial;
1261 struct ATENINTL_port *ATEN2011_port;
1262 struct ktermios tmp_termios;
1264 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27)
1265 struct tty_struct *tty = NULL;
1267 if (ATEN2011_port_paranoia_check(port, __FUNCTION__)) {
1268 DPRINTK("%s", "Port Paranoia failed \n");
1271 //ATEN2011_serial->NoOfOpenPorts++;
1272 serial = port->serial;
1274 if (ATEN2011_serial_paranoia_check(serial, __FUNCTION__)) {
1275 DPRINTK("%s", "Serial Paranoia failed \n");
1279 ATEN2011_port = ATEN2011_get_port_private(port);
1281 if (ATEN2011_port == NULL)
1284 if (ATEN2011_port->ctrl_buf==NULL)
1286 ATEN2011_port->ctrl_buf = kmalloc(16,GFP_KERNEL);
1287 if (ATEN2011_port->ctrl_buf == NULL) {
1288 printk(", Can't allocate ctrl buff\n");
1294 if(!ATEN2011_port->control_urb)
1296 ATEN2011_port->control_urb=kmalloc(sizeof(struct urb),GFP_KERNEL);
1299 // port0 = serial->port[0];
1301 ATEN2011_serial = ATEN2011_get_serial_private(serial);
1303 if (ATEN2011_serial == NULL) //|| port0 == NULL)
1307 // increment the number of opened ports counter here
1308 ATEN2011_serial->NoOfOpenPorts++;
1309 //printk("the num of ports opend is:%d\n",ATEN2011_serial->NoOfOpenPorts);
1311 usb_clear_halt(serial->dev, port->write_urb->pipe);
1312 usb_clear_halt(serial->dev, port->read_urb->pipe);
1314 /* Initialising the write urb pool */
1315 for (j = 0; j < NUM_URBS; ++j) {
1316 urb = usb_alloc_urb(0, GFP_ATOMIC);
1317 ATEN2011_port->write_urb_pool[j] = urb;
1320 err("No more urbs???");
1324 urb->transfer_buffer = NULL;
1325 urb->transfer_buffer =
1326 kmalloc(URB_TRANSFER_BUFFER_SIZE, GFP_KERNEL);
1327 if (!urb->transfer_buffer) {
1328 err("%s-out of memory for urb buffers.", __FUNCTION__);
1333 /*****************************************************************************
1334 * Initialize ATEN2011 -- Write Init values to corresponding Registers
1342 * 0x08 : SP1/2 Control Reg
1343 *****************************************************************************/
1345 //NEED to check the fallowing Block
1349 status = ATEN2011_get_reg_sync(port, ATEN2011_port->SpRegOffset, &Data);
1351 DPRINTK("Reading Spreg failed\n");
1355 status = ATEN2011_set_reg_sync(port, ATEN2011_port->SpRegOffset, Data);
1357 DPRINTK("writing Spreg failed\n");
1362 status = ATEN2011_set_reg_sync(port, ATEN2011_port->SpRegOffset, Data);
1364 DPRINTK("writing Spreg failed\n");
1368 //End of block to be checked
1369 //**************************CHECK***************************//
1376 status = ATEN2011_set_Uart_Reg(port, SCRATCH_PAD_REGISTER, Data);
1378 DPRINTK("Writing SCRATCH_PAD_REGISTER failed status-0x%x\n",
1382 DPRINTK("SCRATCH_PAD_REGISTER Writing success status%d\n",
1385 //**************************CHECK***************************//
1390 ATEN2011_get_reg_sync(port, ATEN2011_port->ControlRegOffset, &Data);
1392 DPRINTK("Reading Controlreg failed\n");
1395 Data |= 0x08; //Driver done bit
1397 status = ATEN2011_set_reg_sync(port,ATEN2011_port->ControlRegOffset,Data);
1399 DPRINTK("writing Controlreg failed\n");
1403 Data |= 0x20; //rx_disable
1406 ATEN2011_set_reg_sync(port, ATEN2011_port->ControlRegOffset, Data);
1408 DPRINTK("writing Controlreg failed\n");
1411 //do register settings here
1412 // Set all regs to the device default values.
1413 ////////////////////////////////////
1414 // First Disable all interrupts.
1415 ////////////////////////////////////
1419 status = ATEN2011_set_Uart_Reg(port, INTERRUPT_ENABLE_REGISTER, Data);
1421 DPRINTK("disableing interrupts failed\n");
1424 // Set FIFO_CONTROL_REGISTER to the default value
1427 status = ATEN2011_set_Uart_Reg(port, FIFO_CONTROL_REGISTER, Data);
1429 DPRINTK("Writing FIFO_CONTROL_REGISTER failed\n");
1435 status = ATEN2011_set_Uart_Reg(port, FIFO_CONTROL_REGISTER, Data);
1437 DPRINTK("Writing FIFO_CONTROL_REGISTER failed\n");
1441 Data = 0x03; //LCR_BITS_8
1443 status = ATEN2011_set_Uart_Reg(port, LINE_CONTROL_REGISTER, Data);
1444 ATEN2011_port->shadowLCR = Data;
1446 Data = 0x0b; // MCR_DTR|MCR_RTS|MCR_MASTER_IE
1448 status = ATEN2011_set_Uart_Reg(port, MODEM_CONTROL_REGISTER, Data);
1449 ATEN2011_port->shadowMCR = Data;
1454 status = ATEN2011_get_Uart_Reg(port, LINE_CONTROL_REGISTER, &Data);
1455 ATEN2011_port->shadowLCR = Data;
1457 Data |= SERIAL_LCR_DLAB; //data latch enable in LCR 0x80
1459 status = ATEN2011_set_Uart_Reg(port, LINE_CONTROL_REGISTER, Data);
1463 status = ATEN2011_set_Uart_Reg(port, DIVISOR_LATCH_LSB, Data);
1467 status = ATEN2011_set_Uart_Reg(port, DIVISOR_LATCH_MSB, Data);
1471 status = ATEN2011_get_Uart_Reg(port, LINE_CONTROL_REGISTER, &Data);
1473 // Data = ATEN2011_port->shadowLCR; //data latch disable
1474 Data = Data & ~SERIAL_LCR_DLAB;
1476 status = ATEN2011_set_Uart_Reg(port, LINE_CONTROL_REGISTER, Data);
1477 ATEN2011_port->shadowLCR = Data;
1479 //clearing Bulkin and Bulkout Fifo
1482 status = ATEN2011_get_reg_sync(port, ATEN2011_port->SpRegOffset, &Data);
1486 status = ATEN2011_set_reg_sync(port, ATEN2011_port->SpRegOffset, Data);
1488 Data = Data & ~0x0c;
1490 status = ATEN2011_set_reg_sync(port, ATEN2011_port->SpRegOffset, Data);
1491 //Finally enable all interrupts
1495 status = ATEN2011_set_Uart_Reg(port, INTERRUPT_ENABLE_REGISTER, Data);
1497 //clearing rx_disable
1501 ATEN2011_get_reg_sync(port, ATEN2011_port->ControlRegOffset, &Data);
1502 Data = Data & ~0x20;
1505 ATEN2011_set_reg_sync(port, ATEN2011_port->ControlRegOffset, Data);
1511 ATEN2011_get_reg_sync(port, ATEN2011_port->ControlRegOffset, &Data);
1515 ATEN2011_set_reg_sync(port, ATEN2011_port->ControlRegOffset, Data);
1517 /* force low_latency on so that our tty_push actually forces *
1518 * the data through,otherwise it is scheduled, and with *
1519 * high data rates (like with OHCI) data can get lost. */
1521 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27)
1525 tty->low_latency = 1;
1527 printk("port number is %d \n",port->number);
1528 printk("serial number is %d \n",port->serial->minor);
1529 printk("Bulkin endpoint is %d \n",port->bulk_in_endpointAddress);
1530 printk("BulkOut endpoint is %d \n",port->bulk_out_endpointAddress);
1531 printk("Interrupt endpoint is %d \n",port->interrupt_in_endpointAddress);
1532 printk("port's number in the device is %d\n",ATEN2011_port->port_num);
1534 ////////////////////////
1535 //#ifdef CheckStatusPipe
1536 /* Check to see if we've set up our endpoint info yet *
1537 * (can't set it up in ATEN2011_startup as the structures *
1538 * were not set up at that time.) */
1539 if (ATEN2011_serial->NoOfOpenPorts == 1) {
1540 // start the status polling here
1541 ATEN2011_serial->status_polling_started = TRUE;
1542 //if (ATEN2011_serial->interrupt_in_buffer == NULL)
1544 /* If not yet set, Set here */
1545 ATEN2011_serial->interrupt_in_buffer =
1546 serial->port[0]->interrupt_in_buffer;
1547 ATEN2011_serial->interrupt_in_endpoint =
1548 serial->port[0]->interrupt_in_endpointAddress;
1549 //printk(" interrupt endpoint:%d \n",ATEN2011_serial->interrupt_in_endpoint);
1550 ATEN2011_serial->interrupt_read_urb =
1551 serial->port[0]->interrupt_in_urb;
1553 /* set up interrupt urb */
1554 usb_fill_int_urb(ATEN2011_serial->interrupt_read_urb,
1556 usb_rcvintpipe(serial->dev,
1558 interrupt_in_endpoint),
1559 ATEN2011_serial->interrupt_in_buffer,
1560 ATEN2011_serial->interrupt_read_urb->
1561 transfer_buffer_length,
1562 ATEN2011_interrupt_callback, ATEN2011_serial,
1563 ATEN2011_serial->interrupt_read_urb->interval);
1565 /* start interrupt read for ATEN2011 *
1566 * will continue as long as ATEN2011 is connected */
1569 usb_submit_urb(ATEN2011_serial->interrupt_read_urb,
1572 DPRINTK("%s - Error %d submitting interrupt urb",
1573 __FUNCTION__, response);
1576 // printk(" interrupt URB submitted\n");
1583 ///////////////////////
1584 /* see if we've set up our endpoint info yet *
1585 * (can't set it up in ATEN2011_startup as the *
1586 * structures were not set up at that time.) */
1588 DPRINTK("port number is %d \n", port->number);
1589 DPRINTK("serial number is %d \n", port->serial->minor);
1590 DPRINTK("Bulkin endpoint is %d \n", port->bulk_in_endpointAddress);
1591 DPRINTK("BulkOut endpoint is %d \n", port->bulk_out_endpointAddress);
1592 DPRINTK("Interrupt endpoint is %d \n",
1593 port->interrupt_in_endpointAddress);
1594 DPRINTK("port's number in the device is %d\n", ATEN2011_port->port_num);
1595 ATEN2011_port->bulk_in_buffer = port->bulk_in_buffer;
1596 ATEN2011_port->bulk_in_endpoint = port->bulk_in_endpointAddress;
1597 ATEN2011_port->read_urb = port->read_urb;
1598 ATEN2011_port->bulk_out_endpoint = port->bulk_out_endpointAddress;
1600 minor = port->serial->minor;
1601 if (minor == SERIAL_TTY_NO_MINOR)
1604 /* set up our bulk in urb */
1605 if ((ATEN2011_serial->ATEN2011_spectrum_2or4ports == 2)
1606 && (((__u16) port->number - (__u16) (minor)) != 0)) {
1607 usb_fill_bulk_urb(ATEN2011_port->read_urb, serial->dev,
1608 usb_rcvbulkpipe(serial->dev,
1610 bulk_in_endpointAddress +
1611 2)), port->bulk_in_buffer,
1612 ATEN2011_port->read_urb->
1613 transfer_buffer_length,
1614 ATEN2011_bulk_in_callback, ATEN2011_port);
1616 usb_fill_bulk_urb(ATEN2011_port->read_urb,
1618 usb_rcvbulkpipe(serial->dev,
1620 bulk_in_endpointAddress),
1621 port->bulk_in_buffer,
1622 ATEN2011_port->read_urb->
1623 transfer_buffer_length,
1624 ATEN2011_bulk_in_callback, ATEN2011_port);
1626 DPRINTK("ATEN2011_open: bulkin endpoint is %d\n",
1627 port->bulk_in_endpointAddress);
1628 response = usb_submit_urb(ATEN2011_port->read_urb, GFP_KERNEL);
1630 err("%s - Error %d submitting control urb", __FUNCTION__,
1634 /* initialize our wait queues */
1635 init_waitqueue_head(&ATEN2011_port->wait_open);
1636 init_waitqueue_head(&ATEN2011_port->wait_chase);
1637 init_waitqueue_head(&ATEN2011_port->delta_msr_wait);
1638 init_waitqueue_head(&ATEN2011_port->wait_command);
1640 /* initialize our icount structure */
1641 memset(&(ATEN2011_port->icount), 0x00, sizeof(ATEN2011_port->icount));
1643 /* initialize our port settings */
1644 ATEN2011_port->shadowMCR = MCR_MASTER_IE; /* Must set to enable ints! */
1645 ATEN2011_port->chaseResponsePending = FALSE;
1646 /* send a open port command */
1647 ATEN2011_port->openPending = FALSE;
1648 ATEN2011_port->open = TRUE;
1649 //ATEN2011_change_port_settings(ATEN2011_port,old_termios);
1651 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
1652 ATEN2011_set_termios(tty, port, &tmp_termios);
1654 ATEN2011_set_termios(port, &tmp_termios);
1656 ATEN2011_port->rxBytesAvail = 0x0;
1657 ATEN2011_port->icount.tx = 0;
1658 ATEN2011_port->icount.rx = 0;
1661 ("\n\nusb_serial serial:%x ATEN2011_port:%x\nATEN2011_serial:%x usb_serial_port port:%x\n\n",
1662 (unsigned int)serial, (unsigned int)ATEN2011_port,
1663 (unsigned int)ATEN2011_serial, (unsigned int)port);
1669 /*****************************************************************************
1671 * this function is called by the tty driver when a port is closed
1672 *****************************************************************************/
1674 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
1675 static void ATEN2011_close(struct tty_struct *tty, struct usb_serial_port *port,
1678 static void ATEN2011_close(struct usb_serial_port *port, struct file *filp)
1681 struct usb_serial *serial;
1682 struct ATENINTL_serial *ATEN2011_serial;
1683 struct ATENINTL_port *ATEN2011_port;
1688 DPRINTK("%s\n", "ATEN2011_close:entering...");
1692 //printk("Entering... :ATEN2011_close\n");
1693 if (ATEN2011_port_paranoia_check(port, __FUNCTION__)) {
1694 DPRINTK("%s", "Port Paranoia failed \n");
1697 serial = ATEN2011_get_usb_serial(port, __FUNCTION__);
1699 DPRINTK("%s", "Serial Paranoia failed \n");
1702 // take the Adpater and port's private data
1703 ATEN2011_serial = ATEN2011_get_serial_private(serial);
1704 ATEN2011_port = ATEN2011_get_port_private(port);
1705 if ((ATEN2011_serial == NULL) || (ATEN2011_port == NULL)) {
1709 /* flush and block(wait) until tx is empty */
1710 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
1711 ATEN2011_block_until_tx_empty(tty, ATEN2011_port);
1713 ATEN2011_block_until_tx_empty(ATEN2011_port);
1716 // kill the ports URB's
1717 for (no_urbs = 0; no_urbs < NUM_URBS; no_urbs++)
1718 usb_kill_urb(ATEN2011_port->write_urb_pool[no_urbs]);
1719 /* Freeing Write URBs */
1720 for (no_urbs = 0; no_urbs < NUM_URBS; ++no_urbs) {
1721 if (ATEN2011_port->write_urb_pool[no_urbs]) {
1722 if (ATEN2011_port->write_urb_pool[no_urbs]->
1724 kfree(ATEN2011_port->write_urb_pool[no_urbs]->
1726 usb_free_urb(ATEN2011_port->write_urb_pool[no_urbs]);
1729 /* While closing port, shutdown all bulk read, write *
1730 * and interrupt read if they exists */
1732 if (ATEN2011_port->write_urb) {
1733 DPRINTK("%s", "Shutdown bulk write\n");
1734 usb_kill_urb(ATEN2011_port->write_urb);
1736 if (ATEN2011_port->read_urb) {
1737 DPRINTK("%s", "Shutdown bulk read\n");
1738 usb_kill_urb(ATEN2011_port->read_urb);
1740 if ((&ATEN2011_port->control_urb)) {
1741 DPRINTK("%s", "Shutdown control read\n");
1742 // usb_kill_urb (ATEN2011_port->control_urb);
1746 //if(ATEN2011_port->ctrl_buf != NULL)
1747 //kfree(ATEN2011_port->ctrl_buf);
1748 // decrement the no.of open ports counter of an individual USB-serial adapter.
1749 ATEN2011_serial->NoOfOpenPorts--;
1750 DPRINTK("NoOfOpenPorts in close%d:in port%d\n",
1751 ATEN2011_serial->NoOfOpenPorts, port->number);
1752 //printk("the num of ports opend is:%d\n",ATEN2011_serial->NoOfOpenPorts);
1753 if (ATEN2011_serial->NoOfOpenPorts == 0) {
1754 //stop the stus polling here
1755 //printk("disabling the status polling flag to FALSE :\n");
1756 ATEN2011_serial->status_polling_started = FALSE;
1757 if (ATEN2011_serial->interrupt_read_urb) {
1758 DPRINTK("%s", "Shutdown interrupt_read_urb\n");
1759 //ATEN2011_serial->interrupt_in_buffer=NULL;
1760 //usb_kill_urb (ATEN2011_serial->interrupt_read_urb);
1763 if (ATEN2011_port->write_urb) {
1764 /* if this urb had a transfer buffer already (old tx) free it */
1765 if (ATEN2011_port->write_urb->transfer_buffer != NULL) {
1766 kfree(ATEN2011_port->write_urb->transfer_buffer);
1768 usb_free_urb(ATEN2011_port->write_urb);
1770 // clear the MCR & IER
1772 ATEN2011_set_Uart_Reg(port, MODEM_CONTROL_REGISTER, Data);
1774 ATEN2011_set_Uart_Reg(port, INTERRUPT_ENABLE_REGISTER, Data);
1776 //ATEN2011_get_Uart_Reg(port,MODEM_CONTROL_REGISTER,&Data1);
1777 //printk("value of MCR after closing the port is : 0x%x\n",Data1);
1779 ATEN2011_port->open = FALSE;
1780 ATEN2011_port->closePending = FALSE;
1781 ATEN2011_port->openPending = FALSE;
1782 DPRINTK("%s \n", "Leaving ............");
1786 /*****************************************************************************
1788 * this function sends a break to the port
1789 *****************************************************************************/
1790 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
1791 static void ATEN2011_break(struct tty_struct *tty, int break_state)
1793 static void ATEN2011_break(struct usb_serial_port *port, int break_state)
1796 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
1797 struct usb_serial_port *port = tty->driver_data;
1800 struct usb_serial *serial;
1801 struct ATENINTL_serial *ATEN2011_serial;
1802 struct ATENINTL_port *ATEN2011_port;
1804 DPRINTK("%s \n", "Entering ...........");
1805 DPRINTK("ATEN2011_break: Start\n");
1807 if (ATEN2011_port_paranoia_check(port, __FUNCTION__)) {
1808 DPRINTK("%s", "Port Paranoia failed \n");
1812 serial = ATEN2011_get_usb_serial(port, __FUNCTION__);
1814 DPRINTK("%s", "Serial Paranoia failed \n");
1818 ATEN2011_serial = ATEN2011_get_serial_private(serial);
1819 ATEN2011_port = ATEN2011_get_port_private(port);
1821 if ((ATEN2011_serial == NULL) || (ATEN2011_port == NULL)) {
1825 /* flush and chase */
1826 ATEN2011_port->chaseResponsePending = TRUE;
1830 /* flush and block until tx is empty */
1831 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
1832 ATEN2011_block_until_chase_response(tty, ATEN2011_port);
1834 ATEN2011_block_until_chase_response(ATEN2011_port);
1838 if (break_state == -1) {
1839 data = ATEN2011_port->shadowLCR | LCR_SET_BREAK;
1841 data = ATEN2011_port->shadowLCR & ~LCR_SET_BREAK;
1844 ATEN2011_port->shadowLCR = data;
1845 DPRINTK("ATEN2011_break ATEN2011_port->shadowLCR is %x\n",
1846 ATEN2011_port->shadowLCR);
1847 ATEN2011_set_Uart_Reg(port, LINE_CONTROL_REGISTER,
1848 ATEN2011_port->shadowLCR);
1853 /************************************************************************
1855 * ATEN2011_block_until_chase_response
1857 * This function will block the close until one of the following:
1858 * 1. Response to our Chase comes from ATEN2011
1859 * 2. A timout of 10 seconds without activity has expired
1860 * (1K of ATEN2011 data @ 2400 baud ==> 4 sec to empty)
1862 ************************************************************************/
1864 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
1865 static void ATEN2011_block_until_chase_response(struct tty_struct *tty,
1866 struct ATENINTL_port
1869 static void ATEN2011_block_until_chase_response(struct ATENINTL_port
1873 int timeout = 1 * HZ;
1878 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
1879 count = ATEN2011_chars_in_buffer(tty);
1881 count = ATEN2011_chars_in_buffer(ATEN2011_port->port);
1884 /* Check for Buffer status */
1886 ATEN2011_port->chaseResponsePending = FALSE;
1890 /* Block the thread for a while */
1891 interruptible_sleep_on_timeout(&ATEN2011_port->wait_chase,
1893 /* No activity.. count down section */
1896 dbg("%s - TIMEOUT", __FUNCTION__);
1899 /* Reset timout value back to seconds */
1906 /************************************************************************
1908 * ATEN2011_block_until_tx_empty
1910 * This function will block the close until one of the following:
1912 * 2. The ATEN2011 has stopped
1913 * 3. A timout of 3 seconds without activity has expired
1915 ************************************************************************/
1916 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
1917 static void ATEN2011_block_until_tx_empty(struct tty_struct *tty,
1918 struct ATENINTL_port *ATEN2011_port)
1920 static void ATEN2011_block_until_tx_empty(struct ATENINTL_port *ATEN2011_port)
1923 int timeout = HZ / 10;
1929 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
1930 count = ATEN2011_chars_in_buffer(tty);
1932 count = ATEN2011_chars_in_buffer(ATEN2011_port->port);
1935 /* Check for Buffer status */
1940 /* Block the thread for a while */
1941 interruptible_sleep_on_timeout(&ATEN2011_port->wait_chase,
1944 /* No activity.. count down section */
1947 dbg("%s - TIMEOUT", __FUNCTION__);
1950 /* Reset timout value back to seconds */
1956 /*****************************************************************************
1957 * ATEN2011_write_room
1958 * this function is called by the tty driver when it wants to know how many
1959 * bytes of data we can accept for a specific port.
1960 * If successful, we return the amount of room that we have for this port
1961 * Otherwise we return a negative error number.
1962 *****************************************************************************/
1964 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
1965 static int ATEN2011_write_room(struct tty_struct *tty)
1967 static int ATEN2011_write_room(struct usb_serial_port *port)
1970 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
1971 struct usb_serial_port *port = tty->driver_data;
1975 struct ATENINTL_port *ATEN2011_port;
1977 // DPRINTK("%s \n"," ATEN2011_write_room:entering ...........");
1979 if (ATEN2011_port_paranoia_check(port, __FUNCTION__)) {
1980 DPRINTK("%s", "Invalid port \n");
1981 DPRINTK("%s \n", " ATEN2011_write_room:leaving ...........");
1985 ATEN2011_port = ATEN2011_get_port_private(port);
1986 if (ATEN2011_port == NULL) {
1987 DPRINTK("%s \n", "ATEN2011_break:leaving ...........");
1991 for (i = 0; i < NUM_URBS; ++i) {
1992 if (ATEN2011_port->write_urb_pool[i]->status != -EINPROGRESS) {
1993 room += URB_TRANSFER_BUFFER_SIZE;
1997 dbg("%s - returns %d", __FUNCTION__, room);
2002 /*****************************************************************************
2003 * ATEN2011_chars_in_buffer
2004 * this function is called by the tty driver when it wants to know how many
2005 * bytes of data we currently have outstanding in the port (data that has
2006 * been written, but hasn't made it out the port yet)
2007 * If successful, we return the number of bytes left to be written in the
2009 * Otherwise we return a negative error number.
2010 *****************************************************************************/
2012 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
2013 static int ATEN2011_chars_in_buffer(struct tty_struct *tty)
2015 static int ATEN2011_chars_in_buffer(struct usb_serial_port *port)
2018 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
2019 struct usb_serial_port *port = tty->driver_data;
2023 struct ATENINTL_port *ATEN2011_port;
2025 //DPRINTK("%s \n"," ATEN2011_chars_in_buffer:entering ...........");
2027 if (ATEN2011_port_paranoia_check(port, __FUNCTION__)) {
2028 DPRINTK("%s", "Invalid port \n");
2032 ATEN2011_port = ATEN2011_get_port_private(port);
2033 if (ATEN2011_port == NULL) {
2034 DPRINTK("%s \n", "ATEN2011_break:leaving ...........");
2038 for (i = 0; i < NUM_URBS; ++i) {
2039 if (ATEN2011_port->write_urb_pool[i]->status == -EINPROGRESS) {
2040 chars += URB_TRANSFER_BUFFER_SIZE;
2043 dbg("%s - returns %d", __FUNCTION__, chars);
2048 /*****************************************************************************
2050 * this function is called by the tty driver when data should be written to
2052 * If successful, we return the number of bytes written, otherwise we
2053 * return a negative error number.
2054 *****************************************************************************/
2056 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
2057 static int ATEN2011_write(struct tty_struct *tty, struct usb_serial_port *port,
2058 const unsigned char *data, int count)
2060 static int ATEN2011_write(struct usb_serial_port *port,
2061 const unsigned char *data, int count)
2071 struct ATENINTL_port *ATEN2011_port;
2072 struct usb_serial *serial;
2073 struct ATENINTL_serial *ATEN2011_serial;
2076 const unsigned char *current_position = data;
2077 unsigned char *data1;
2078 DPRINTK("%s \n", "entering ...........");
2079 //DPRINTK("ATEN2011_write: ATEN2011_port->shadowLCR is %x\n",ATEN2011_port->shadowLCR);
2084 status = ATEN2011_get_Uart_Reg(port, LINE_CONTROL_REGISTER, &Data);
2085 ATEN2011_port->shadowLCR = Data;
2086 DPRINTK("ATEN2011_write: LINE_CONTROL_REGISTER is %x\n", Data);
2087 DPRINTK("ATEN2011_write: ATEN2011_port->shadowLCR is %x\n",
2088 ATEN2011_port->shadowLCR);
2091 //status = ATEN2011_set_Uart_Reg(port,LINE_CONTROL_REGISTER,Data);
2092 //ATEN2011_port->shadowLCR=Data;//Need to add later
2094 Data |= SERIAL_LCR_DLAB; //data latch enable in LCR 0x80
2096 status = ATEN2011_set_Uart_Reg(port, LINE_CONTROL_REGISTER, Data);
2099 //status = ATEN2011_set_Uart_Reg(port,DIVISOR_LATCH_LSB,Data);
2102 status = ATEN2011_get_Uart_Reg(port, DIVISOR_LATCH_LSB, &Data);
2103 DPRINTK("ATEN2011_write:DLL value is %x\n", Data);
2107 status = ATEN2011_get_Uart_Reg(port, DIVISOR_LATCH_MSB, &Data);
2108 DPRINTK("ATEN2011_write:DLM value is %x\n", Data);
2110 Data = Data & ~SERIAL_LCR_DLAB;
2111 DPRINTK("ATEN2011_write: ATEN2011_port->shadowLCR is %x\n",
2112 ATEN2011_port->shadowLCR);
2114 status = ATEN2011_set_Uart_Reg(port, LINE_CONTROL_REGISTER, Data);
2117 if (ATEN2011_port_paranoia_check(port, __FUNCTION__)) {
2118 DPRINTK("%s", "Port Paranoia failed \n");
2122 serial = port->serial;
2123 if (ATEN2011_serial_paranoia_check(serial, __FUNCTION__)) {
2124 DPRINTK("%s", "Serial Paranoia failed \n");
2128 ATEN2011_port = ATEN2011_get_port_private(port);
2129 if (ATEN2011_port == NULL) {
2130 DPRINTK("%s", "ATEN2011_port is NULL\n");
2134 ATEN2011_serial = ATEN2011_get_serial_private(serial);
2135 if (ATEN2011_serial == NULL) {
2136 DPRINTK("%s", "ATEN2011_serial is NULL \n");
2140 /* try to find a free urb in the list */
2143 for (i = 0; i < NUM_URBS; ++i) {
2144 if (ATEN2011_port->write_urb_pool[i]->status != -EINPROGRESS) {
2145 urb = ATEN2011_port->write_urb_pool[i];
2146 DPRINTK("\nURB:%d", i);
2152 dbg("%s - no more free urbs", __FUNCTION__);
2156 if (urb->transfer_buffer == NULL) {
2157 urb->transfer_buffer =
2158 kmalloc(URB_TRANSFER_BUFFER_SIZE, GFP_KERNEL);
2160 if (urb->transfer_buffer == NULL) {
2161 err("%s no more kernel memory...", __FUNCTION__);
2165 transfer_size = min(count, URB_TRANSFER_BUFFER_SIZE);
2169 (urb->transfer_buffer, current_position, transfer_size)) {
2170 bytes_sent = -EFAULT;
2174 memcpy(urb->transfer_buffer, current_position, transfer_size);
2176 //usb_serial_debug_data (__FILE__, __FUNCTION__, transfer_size, urb->transfer_buffer);
2178 /* fill urb with data and submit */
2179 minor = port->serial->minor;
2180 if (minor == SERIAL_TTY_NO_MINOR) ;
2182 if ((ATEN2011_serial->ATEN2011_spectrum_2or4ports == 2)
2183 && (((__u16) port->number - (__u16) (minor)) != 0)) {
2184 usb_fill_bulk_urb(urb, ATEN2011_serial->serial->dev,
2185 usb_sndbulkpipe(ATEN2011_serial->serial->dev,
2187 bulk_out_endpointAddress) +
2188 2), urb->transfer_buffer,
2190 ATEN2011_bulk_out_data_callback,
2194 usb_fill_bulk_urb(urb,
2195 ATEN2011_serial->serial->dev,
2196 usb_sndbulkpipe(ATEN2011_serial->serial->dev,
2198 bulk_out_endpointAddress),
2199 urb->transfer_buffer, transfer_size,
2200 ATEN2011_bulk_out_data_callback,
2203 data1 = urb->transfer_buffer;
2204 DPRINTK("\nbulkout endpoint is %d", port->bulk_out_endpointAddress);
2205 //for(i=0;i < urb->actual_length;i++)
2206 // DPRINTK("Data is %c\n ",data1[i]);
2208 /* send it down the pipe */
2209 status = usb_submit_urb(urb, GFP_ATOMIC);
2212 err("%s - usb_submit_urb(write bulk) failed with status = %d",
2213 __FUNCTION__, status);
2214 bytes_sent = status;
2217 bytes_sent = transfer_size;
2218 ATEN2011_port->icount.tx += transfer_size;
2219 DPRINTK("ATEN2011_port->icount.tx is %d:\n", ATEN2011_port->icount.tx);
2226 /*****************************************************************************
2228 * this function is called by the tty driver when it wants to stop the data
2229 * being read from the port.
2230 *****************************************************************************/
2232 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
2233 static void ATEN2011_throttle(struct tty_struct *tty)
2235 static void ATEN2011_throttle(struct usb_serial_port *port)
2238 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
2239 struct usb_serial_port *port = tty->driver_data;
2241 struct tty_struct *tty;
2243 struct ATENINTL_port *ATEN2011_port;
2246 if (ATEN2011_port_paranoia_check(port, __FUNCTION__)) {
2247 DPRINTK("%s", "Invalid port \n");
2251 DPRINTK("- port %d\n", port->number);
2253 ATEN2011_port = ATEN2011_get_port_private(port);
2255 if (ATEN2011_port == NULL)
2258 if (!ATEN2011_port->open) {
2259 DPRINTK("%s\n", "port not opened");
2263 DPRINTK("%s", "Entering .......... \n");
2265 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27)
2269 dbg("%s - no tty available", __FUNCTION__);
2273 /* if we are implementing XON/XOFF, send the stop character */
2275 unsigned char stop_char = STOP_CHAR(tty);
2276 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
2277 status = ATEN2011_write(tty, port, &stop_char, 1); //FC4
2279 status = ATEN2011_write(port, &stop_char, 1); //FC4
2286 /* if we are implementing RTS/CTS, toggle that line */
2287 if (tty->termios->c_cflag & CRTSCTS) {
2288 ATEN2011_port->shadowMCR &= ~MCR_RTS;
2291 ATEN2011_set_Uart_Reg(port, MODEM_CONTROL_REGISTER,
2292 ATEN2011_port->shadowMCR);
2302 /*****************************************************************************
2303 * ATEN2011_unthrottle
2304 * this function is called by the tty driver when it wants to resume the data
2305 * being read from the port (called after SerialThrottle is called)
2306 *****************************************************************************/
2307 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
2308 static void ATEN2011_unthrottle(struct tty_struct *tty)
2310 static void ATEN2011_unthrottle(struct usb_serial_port *port)
2313 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
2314 struct usb_serial_port *port = tty->driver_data;
2316 struct tty_struct *tty;
2319 struct ATENINTL_port *ATEN2011_port = ATEN2011_get_port_private(port);
2321 if (ATEN2011_port_paranoia_check(port, __FUNCTION__)) {
2322 DPRINTK("%s", "Invalid port \n");
2326 if (ATEN2011_port == NULL)
2329 if (!ATEN2011_port->open) {
2330 dbg("%s - port not opened", __FUNCTION__);
2334 DPRINTK("%s", "Entering .......... \n");
2336 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27)
2340 dbg("%s - no tty available", __FUNCTION__);
2344 /* if we are implementing XON/XOFF, send the start character */
2346 unsigned char start_char = START_CHAR(tty);
2347 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
2348 status = ATEN2011_write(tty, port, &start_char, 1); //FC4
2350 status = ATEN2011_write(port, &start_char, 1); //FC4
2357 /* if we are implementing RTS/CTS, toggle that line */
2358 if (tty->termios->c_cflag & CRTSCTS) {
2359 ATEN2011_port->shadowMCR |= MCR_RTS;
2362 ATEN2011_set_Uart_Reg(port, MODEM_CONTROL_REGISTER,
2363 ATEN2011_port->shadowMCR);
2372 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
2373 static int ATEN2011_tiocmget(struct tty_struct *tty, struct file *file)
2375 static int ATEN2011_tiocmget(struct usb_serial_port *port, struct file *file)
2378 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
2379 struct usb_serial_port *port = tty->driver_data;
2381 //struct ti_port *tport = usb_get_serial_port_data(port);
2382 struct ATENINTL_port *ATEN2011_port;
2383 unsigned int result;
2388 ATEN2011_port = ATEN2011_get_port_private(port);
2390 DPRINTK("%s - port %d", __FUNCTION__, port->number);
2392 if (ATEN2011_port == NULL)
2395 status = ATEN2011_get_Uart_Reg(port, MODEM_STATUS_REGISTER, &msr);
2396 status = ATEN2011_get_Uart_Reg(port, MODEM_CONTROL_REGISTER, &mcr);
2397 // mcr = ATEN2011_port->shadowMCR;
2398 // COMMENT2: the Fallowing three line are commented for updating only MSR values
2399 result = ((mcr & MCR_DTR) ? TIOCM_DTR : 0)
2400 | ((mcr & MCR_RTS) ? TIOCM_RTS : 0)
2401 | ((mcr & MCR_LOOPBACK) ? TIOCM_LOOP : 0)
2402 | ((msr & ATEN2011_MSR_CTS) ? TIOCM_CTS : 0)
2403 | ((msr & ATEN2011_MSR_CD) ? TIOCM_CAR : 0)
2404 | ((msr & ATEN2011_MSR_RI) ? TIOCM_RI : 0)
2405 | ((msr & ATEN2011_MSR_DSR) ? TIOCM_DSR : 0);
2407 DPRINTK("%s - 0x%04X", __FUNCTION__, result);
2412 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
2413 static int ATEN2011_tiocmset(struct tty_struct *tty, struct file *file,
2414 unsigned int set, unsigned int clear)
2416 static int ATEN2011_tiocmset(struct usb_serial_port *port, struct file *file,
2417 unsigned int set, unsigned int clear)
2420 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
2421 struct usb_serial_port *port = tty->driver_data;
2423 struct ATENINTL_port *ATEN2011_port;
2424 //struct ti_port *tport = usb_get_serial_port_data(port);
2426 unsigned int status;
2428 DPRINTK("%s - port %d", __FUNCTION__, port->number);
2430 ATEN2011_port = ATEN2011_get_port_private(port);
2432 if (ATEN2011_port == NULL)
2435 mcr = ATEN2011_port->shadowMCR;
2436 if (clear & TIOCM_RTS)
2438 if (clear & TIOCM_DTR)
2440 if (clear & TIOCM_LOOP)
2441 mcr &= ~MCR_LOOPBACK;
2443 if (set & TIOCM_RTS)
2445 if (set & TIOCM_DTR)
2447 if (set & TIOCM_LOOP)
2448 mcr |= MCR_LOOPBACK;
2450 ATEN2011_port->shadowMCR = mcr;
2453 status = ATEN2011_set_Uart_Reg(port, MODEM_CONTROL_REGISTER, mcr);
2455 DPRINTK("setting MODEM_CONTROL_REGISTER Failed\n");
2462 /*****************************************************************************
2464 * this function is called by the tty driver when it wants to change the termios structure
2465 *****************************************************************************/
2467 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
2468 static void ATEN2011_set_termios(struct tty_struct *tty,
2469 struct usb_serial_port *port,
2470 struct ktermios *old_termios)
2472 static void ATEN2011_set_termios(struct usb_serial_port *port,
2473 struct ktermios *old_termios)
2478 struct usb_serial *serial;
2479 struct ATENINTL_port *ATEN2011_port;
2480 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27)
2481 struct tty_struct *tty;
2483 DPRINTK("ATEN2011_set_termios: START\n");
2484 if (ATEN2011_port_paranoia_check(port, __FUNCTION__)) {
2485 DPRINTK("%s", "Invalid port \n");
2489 serial = port->serial;
2491 if (ATEN2011_serial_paranoia_check(serial, __FUNCTION__)) {
2492 DPRINTK("%s", "Invalid Serial \n");
2496 ATEN2011_port = ATEN2011_get_port_private(port);
2498 if (ATEN2011_port == NULL)
2501 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27)
2504 if (!port->tty || !port->tty->termios) {
2505 dbg("%s - no tty or termios", __FUNCTION__);
2510 if (!ATEN2011_port->open) {
2511 dbg("%s - port not opened", __FUNCTION__);
2515 DPRINTK("%s\n", "setting termios - ");
2517 cflag = tty->termios->c_cflag;
2520 DPRINTK("%s %s\n", __FUNCTION__, "cflag is NULL");
2524 /* check that they really want us to change something */
2526 if ((cflag == old_termios->c_cflag) &&
2527 (RELEVANT_IFLAG(tty->termios->c_iflag) ==
2528 RELEVANT_IFLAG(old_termios->c_iflag))) {
2529 DPRINTK("%s\n", "Nothing to change");
2534 dbg("%s - clfag %08x iflag %08x", __FUNCTION__,
2535 tty->termios->c_cflag, RELEVANT_IFLAG(tty->termios->c_iflag));
2538 dbg("%s - old clfag %08x old iflag %08x", __FUNCTION__,
2539 old_termios->c_cflag, RELEVANT_IFLAG(old_termios->c_iflag));
2542 dbg("%s - port %d", __FUNCTION__, port->number);
2544 /* change the port settings to the new ones specified */
2546 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
2547 ATEN2011_change_port_settings(tty, ATEN2011_port, old_termios);
2549 ATEN2011_change_port_settings(ATEN2011_port, old_termios);
2552 if (!ATEN2011_port->read_urb) {
2553 DPRINTK("%s", "URB KILLED !!!!!\n");
2557 if (ATEN2011_port->read_urb->status != -EINPROGRESS) {
2558 ATEN2011_port->read_urb->dev = serial->dev;
2559 status = usb_submit_urb(ATEN2011_port->read_urb, GFP_ATOMIC);
2562 (" usb_submit_urb(read bulk) failed, status = %d",
2570 static void ATEN2011_break_ctl( struct usb_serial_port *port, int break_state )
2572 //struct usb_serial *serial = port->serial;
2574 // if (BSA_USB_CMD(BELKIN_SA_SET_BREAK_REQUEST, break_state ? 1 : 0) < 0)
2575 // err("Set break_ctl %d", break_state);
2579 /*****************************************************************************
2580 * get_lsr_info - get line status register info
2582 * Purpose: Let user call ioctl() to get info when the UART physically
2583 * is emptied. On bus types like RS485, the transmitter must
2584 * release the bus after transmitting. This must be done when
2585 * the transmit shift register is empty, not be done when the
2586 * transmit holding register is empty. This functionality
2587 * allows an RS485 driver to be written in user space.
2588 *****************************************************************************/
2590 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
2591 static int get_lsr_info(struct tty_struct *tty,
2592 struct ATENINTL_port *ATEN2011_port,
2593 unsigned int *value)
2595 static int get_lsr_info(struct ATENINTL_port *ATEN2011_port,
2596 unsigned int *value)
2600 unsigned int result = 0;
2602 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
2603 count = ATEN2011_chars_in_buffer(tty);
2605 count = ATEN2011_chars_in_buffer(ATEN2011_port->port);
2608 dbg("%s -- Empty", __FUNCTION__);
2609 result = TIOCSER_TEMT;
2612 if (copy_to_user(value, &result, sizeof(int)))
2617 /*****************************************************************************
2618 * get_number_bytes_avail - get number of bytes available
2620 * Purpose: Let user call ioctl to get the count of number of bytes available.
2621 *****************************************************************************/
2623 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
2624 static int get_number_bytes_avail(struct tty_struct *tty,
2625 struct ATENINTL_port *ATEN2011_port,
2626 unsigned int *value)
2628 static int get_number_bytes_avail(struct ATENINTL_port *ATEN2011_port,
2629 unsigned int *value)
2632 unsigned int result = 0;
2633 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27)
2634 struct tty_struct *tty = ATEN2011_port->port->tty;
2638 return -ENOIOCTLCMD;
2640 result = tty->read_cnt;
2642 dbg("%s(%d) = %d", __FUNCTION__, ATEN2011_port->port->number, result);
2643 if (copy_to_user(value, &result, sizeof(int)))
2646 return -ENOIOCTLCMD;
2649 /*****************************************************************************
2651 * function to set modem info
2652 *****************************************************************************/
2654 static int set_modem_info(struct ATENINTL_port *ATEN2011_port, unsigned int cmd,
2655 unsigned int *value)
2661 struct usb_serial_port *port;
2663 if (ATEN2011_port == NULL)
2666 port = (struct usb_serial_port *)ATEN2011_port->port;
2667 if (ATEN2011_port_paranoia_check(port, __FUNCTION__)) {
2668 DPRINTK("%s", "Invalid port \n");
2672 mcr = ATEN2011_port->shadowMCR;
2674 if (copy_from_user(&arg, value, sizeof(int)))
2679 if (arg & TIOCM_RTS)
2681 if (arg & TIOCM_DTR)
2683 if (arg & TIOCM_LOOP)
2684 mcr |= MCR_LOOPBACK;
2688 if (arg & TIOCM_RTS)
2690 if (arg & TIOCM_DTR)
2692 if (arg & TIOCM_LOOP)
2693 mcr &= ~MCR_LOOPBACK;
2697 /* turn off the RTS and DTR and LOOPBACK
2698 * and then only turn on what was asked to */
2699 mcr &= ~(MCR_RTS | MCR_DTR | MCR_LOOPBACK);
2700 mcr |= ((arg & TIOCM_RTS) ? MCR_RTS : 0);
2701 mcr |= ((arg & TIOCM_DTR) ? MCR_DTR : 0);
2702 mcr |= ((arg & TIOCM_LOOP) ? MCR_LOOPBACK : 0);
2706 ATEN2011_port->shadowMCR = mcr;
2708 Data = ATEN2011_port->shadowMCR;
2710 status = ATEN2011_set_Uart_Reg(port, MODEM_CONTROL_REGISTER, Data);
2712 DPRINTK("setting MODEM_CONTROL_REGISTER Failed\n");
2719 /*****************************************************************************
2721 * function to get modem info
2722 *****************************************************************************/
2724 static int get_modem_info(struct ATENINTL_port *ATEN2011_port,
2725 unsigned int *value)
2727 unsigned int result = 0;
2729 unsigned int mcr = ATEN2011_port->shadowMCR;
2732 ATEN2011_get_Uart_Reg(ATEN2011_port->port, MODEM_STATUS_REGISTER,
2734 result = ((mcr & MCR_DTR) ? TIOCM_DTR : 0) /* 0x002 */
2735 |((mcr & MCR_RTS) ? TIOCM_RTS : 0) /* 0x004 */
2736 |((msr & ATEN2011_MSR_CTS) ? TIOCM_CTS : 0) /* 0x020 */
2737 |((msr & ATEN2011_MSR_CD) ? TIOCM_CAR : 0) /* 0x040 */
2738 |((msr & ATEN2011_MSR_RI) ? TIOCM_RI : 0) /* 0x080 */
2739 |((msr & ATEN2011_MSR_DSR) ? TIOCM_DSR : 0); /* 0x100 */
2741 dbg("%s -- %x", __FUNCTION__, result);
2743 if (copy_to_user(value, &result, sizeof(int)))
2748 /*****************************************************************************
2750 * function to get information about serial port
2751 *****************************************************************************/
2753 static int get_serial_info(struct ATENINTL_port *ATEN2011_port,
2754 struct serial_struct *retinfo)
2756 struct serial_struct tmp;
2758 if (ATEN2011_port == NULL)
2764 memset(&tmp, 0, sizeof(tmp));
2766 tmp.type = PORT_16550A;
2767 tmp.line = ATEN2011_port->port->serial->minor;
2768 if (tmp.line == SERIAL_TTY_NO_MINOR)
2770 tmp.port = ATEN2011_port->port->number;
2772 tmp.flags = ASYNC_SKIP_TEST | ASYNC_AUTO_IRQ;
2773 tmp.xmit_fifo_size = NUM_URBS * URB_TRANSFER_BUFFER_SIZE;
2774 tmp.baud_base = 9600;
2775 tmp.close_delay = 5 * HZ;
2776 tmp.closing_wait = 30 * HZ;
2778 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
2783 /*****************************************************************************
2785 * this function handles any ioctl calls to the driver
2786 *****************************************************************************/
2788 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
2789 static int ATEN2011_ioctl(struct tty_struct *tty, struct file *file,
2790 unsigned int cmd, unsigned long arg)
2792 static int ATEN2011_ioctl(struct usb_serial_port *port, struct file *file,
2793 unsigned int cmd, unsigned long arg)
2796 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
2797 struct usb_serial_port *port = tty->driver_data;
2799 struct tty_struct *tty;
2801 struct ATENINTL_port *ATEN2011_port;
2802 struct async_icount cnow;
2803 struct async_icount cprev;
2804 struct serial_icounter_struct icount;
2807 //struct tty_ldisc *ld;
2809 //printk("%s - port %d, cmd = 0x%x\n", __FUNCTION__, port->number, cmd);
2810 if (ATEN2011_port_paranoia_check(port, __FUNCTION__)) {
2811 DPRINTK("%s", "Invalid port \n");
2815 ATEN2011_port = ATEN2011_get_port_private(port);
2816 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27)
2817 tty = ATEN2011_port->port->tty;
2820 if (ATEN2011_port == NULL)
2823 dbg("%s - port %d, cmd = 0x%x", __FUNCTION__, port->number, cmd);
2826 /* return number of bytes available */
2829 dbg("%s (%d) TIOCINQ", __FUNCTION__, port->number);
2830 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
2831 return get_number_bytes_avail(tty, ATEN2011_port,
2832 (unsigned int *)arg);
2834 return get_number_bytes_avail(ATEN2011_port,
2835 (unsigned int *)arg);
2840 dbg("%s (%d) TIOCOUTQ", __FUNCTION__, port->number);
2841 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
2842 return put_user(ATEN2011_chars_in_buffer(tty),
2845 return put_user(tty->driver->ops->chars_in_buffer ?
2846 tty->driver->ops->chars_in_buffer(tty) : 0,
2853 retval = tty_check_change(tty);
2857 ld = tty_ldisc_ref(tty);
2860 if (ld && ld->flush_buffer)
2861 ld->flush_buffer(tty);
2864 if (ld && ld->flush_buffer)
2865 ld->flush_buffer(tty);
2868 if (tty->driver->flush_buffer)
2869 tty->driver->flush_buffer(tty);
2872 tty_ldisc_deref(ld);
2875 tty_ldisc_deref(ld);
2879 dbg("%s (%d) TIOCSERGETLSR", __FUNCTION__, port->number);
2880 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
2881 return get_lsr_info(tty, ATEN2011_port, (unsigned int *)arg);
2883 return get_lsr_info(ATEN2011_port, (unsigned int *)arg);
2890 dbg("%s (%d) TIOCMSET/TIOCMBIC/TIOCMSET", __FUNCTION__,
2892 // printk("%s (%d) TIOCMSET/TIOCMBIC/TIOCMSET", __FUNCTION__, port->number);
2894 set_modem_info(ATEN2011_port, cmd, (unsigned int *)arg);
2895 // printk(" %s: ret:%d\n",__FUNCTION__,ATENret);
2899 dbg("%s (%d) TIOCMGET", __FUNCTION__, port->number);
2900 return get_modem_info(ATEN2011_port, (unsigned int *)arg);
2903 dbg("%s (%d) TIOCGSERIAL", __FUNCTION__, port->number);
2904 return get_serial_info(ATEN2011_port,
2905 (struct serial_struct *)arg);
2908 dbg("%s (%d) TIOCSSERIAL", __FUNCTION__, port->number);
2912 dbg("%s (%d) TIOCMIWAIT", __FUNCTION__, port->number);
2913 cprev = ATEN2011_port->icount;
2915 //interruptible_sleep_on(&ATEN2011_port->delta_msr_wait);
2916 // ATEN2011_port->delta_msr_cond=0;
2917 //wait_event_interruptible(ATEN2011_port->delta_msr_wait,(ATEN2011_port->delta_msr_cond==1));
2919 /* see if a signal did it */
2920 if (signal_pending(current))
2921 return -ERESTARTSYS;
2922 cnow = ATEN2011_port->icount;
2923 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
2924 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts)
2925 return -EIO; /* no change => error */
2926 if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
2927 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
2928 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
2929 ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts))) {
2938 cnow = ATEN2011_port->icount;
2939 icount.cts = cnow.cts;
2940 icount.dsr = cnow.dsr;
2941 icount.rng = cnow.rng;
2942 icount.dcd = cnow.dcd;
2943 icount.rx = cnow.rx;
2944 icount.tx = cnow.tx;
2945 icount.frame = cnow.frame;
2946 icount.overrun = cnow.overrun;
2947 icount.parity = cnow.parity;
2948 icount.brk = cnow.brk;
2949 icount.buf_overrun = cnow.buf_overrun;
2951 dbg("%s (%d) TIOCGICOUNT RX=%d, TX=%d", __FUNCTION__,
2952 port->number, icount.rx, icount.tx);
2953 if (copy_to_user((void *)arg, &icount, sizeof(icount)))
2963 return -ENOIOCTLCMD;
2966 /*****************************************************************************
2967 * ATEN2011_send_cmd_write_baud_rate
2968 * this function sends the proper command to change the baud rate of the
2970 *****************************************************************************/
2972 static int ATEN2011_send_cmd_write_baud_rate(struct ATENINTL_port
2973 *ATEN2011_port, int baudRate)
2978 unsigned char number;
2980 struct usb_serial_port *port;
2983 if (ATEN2011_port == NULL)
2986 port = (struct usb_serial_port *)ATEN2011_port->port;
2987 if (ATEN2011_port_paranoia_check(port, __FUNCTION__)) {
2988 DPRINTK("%s", "Invalid port \n");
2992 if (ATEN2011_serial_paranoia_check(port->serial, __FUNCTION__)) {
2993 DPRINTK("%s", "Invalid Serial \n");
2997 DPRINTK("%s", "Entering .......... \n");
2999 minor = ATEN2011_port->port->serial->minor;
3000 if (minor == SERIAL_TTY_NO_MINOR)
3002 number = ATEN2011_port->port->number - minor;
3004 dbg("%s - port = %d, baud = %d", __FUNCTION__,
3005 ATEN2011_port->port->number, baudRate);
3006 //reset clk_uart_sel in spregOffset
3007 if (baudRate > 115200) {
3008 #ifdef HW_flow_control
3009 //NOTE: need to see the pther register to modify
3010 //setting h/w flow control bit to 1;
3012 //Data = ATEN2011_port->shadowMCR ;
3014 ATEN2011_port->shadowMCR = Data;
3016 ATEN2011_set_Uart_Reg(port, MODEM_CONTROL_REGISTER, Data);
3018 DPRINTK("Writing spreg failed in set_serial_baud\n");
3024 #ifdef HW_flow_control
3025 //setting h/w flow control bit to 0;
3027 //Data = ATEN2011_port->shadowMCR ;
3029 ATEN2011_port->shadowMCR = Data;
3031 ATEN2011_set_Uart_Reg(port, MODEM_CONTROL_REGISTER, Data);
3033 DPRINTK("Writing spreg failed in set_serial_baud\n");
3040 if (1) //baudRate <= 115200)
3046 ATEN2011_calc_baud_rate_divisor(baudRate, &divisor,
3049 ATEN2011_get_reg_sync(port, ATEN2011_port->SpRegOffset,
3052 DPRINTK("reading spreg failed in set_serial_baud\n");
3055 Data = (Data & 0x8f) | clk_sel_val;
3058 ATEN2011_set_reg_sync(port, ATEN2011_port->SpRegOffset,
3061 DPRINTK("Writing spreg failed in set_serial_baud\n");
3064 /* Calculate the Divisor */
3067 err("%s - bad baud rate", __FUNCTION__);
3068 DPRINTK("%s\n", "bad baud rate");
3071 /* Enable access to divisor latch */
3072 Data = ATEN2011_port->shadowLCR | SERIAL_LCR_DLAB;
3073 ATEN2011_port->shadowLCR = Data;
3074 ATEN2011_set_Uart_Reg(port, LINE_CONTROL_REGISTER, Data);
3076 /* Write the divisor */
3077 Data = LOW8(divisor); //: commented to test
3078 DPRINTK("set_serial_baud Value to write DLL is %x\n", Data);
3079 ATEN2011_set_Uart_Reg(port, DIVISOR_LATCH_LSB, Data);
3081 Data = HIGH8(divisor); //: commented to test
3082 DPRINTK("set_serial_baud Value to write DLM is %x\n", Data);
3083 ATEN2011_set_Uart_Reg(port, DIVISOR_LATCH_MSB, Data);
3085 /* Disable access to divisor latch */
3086 Data = ATEN2011_port->shadowLCR & ~SERIAL_LCR_DLAB;
3087 ATEN2011_port->shadowLCR = Data;
3088 ATEN2011_set_Uart_Reg(port, LINE_CONTROL_REGISTER, Data);
3095 /*****************************************************************************
3096 * ATEN2011_calc_baud_rate_divisor
3097 * this function calculates the proper baud rate divisor for the specified
3099 *****************************************************************************/
3100 static int ATEN2011_calc_baud_rate_divisor(int baudRate, int *divisor,
3101 __u16 * clk_sel_val)
3104 //__u16 custom,round1, round;
3106 dbg("%s - %d", __FUNCTION__, baudRate);
3108 if (baudRate <= 115200) {
3109 *divisor = 115200 / baudRate;
3112 if ((baudRate > 115200) && (baudRate <= 230400)) {
3113 *divisor = 230400 / baudRate;
3114 *clk_sel_val = 0x10;
3115 } else if ((baudRate > 230400) && (baudRate <= 403200)) {
3116 *divisor = 403200 / baudRate;
3117 *clk_sel_val = 0x20;
3118 } else if ((baudRate > 403200) && (baudRate <= 460800)) {
3119 *divisor = 460800 / baudRate;
3120 *clk_sel_val = 0x30;
3121 } else if ((baudRate > 460800) && (baudRate <= 806400)) {
3122 *divisor = 806400 / baudRate;
3123 *clk_sel_val = 0x40;
3124 } else if ((baudRate > 806400) && (baudRate <= 921600)) {
3125 *divisor = 921600 / baudRate;
3126 *clk_sel_val = 0x50;
3127 } else if ((baudRate > 921600) && (baudRate <= 1572864)) {
3128 *divisor = 1572864 / baudRate;
3129 *clk_sel_val = 0x60;
3130 } else if ((baudRate > 1572864) && (baudRate <= 3145728)) {
3131 *divisor = 3145728 / baudRate;
3132 *clk_sel_val = 0x70;
3138 for (i = 0; i < NUM_ENTRIES(ATEN2011_divisor_table); i++) {
3139 if (ATEN2011_divisor_table[i].BaudRate == baudrate) {
3140 *divisor = ATEN2011_divisor_table[i].Divisor;
3145 /* After trying for all the standard baud rates *
3146 * Try calculating the divisor for this baud rate */
3148 if (baudrate > 75 && baudrate < 230400) {
3149 /* get the divisor */
3150 custom = (__u16) (230400L / baudrate);
3152 /* Check for round off */
3153 round1 = (__u16) (2304000L / baudrate);
3154 round = (__u16) (round1 - (custom * 10));
3160 DPRINTK(" Baud %d = %d\n", baudrate, custom);
3164 DPRINTK("%s\n", " Baud calculation Failed...");
3169 /*****************************************************************************
3170 * ATEN2011_change_port_settings
3171 * This routine is called to set the UART on the device to match
3172 * the specified new settings.
3173 *****************************************************************************/
3175 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
3176 static void ATEN2011_change_port_settings(struct tty_struct *tty,
3177 struct ATENINTL_port *ATEN2011_port,
3178 struct ktermios *old_termios)
3180 static void ATEN2011_change_port_settings(struct ATENINTL_port *ATEN2011_port,
3181 struct ktermios *old_termios)
3184 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27)
3185 struct tty_struct *tty;
3196 struct usb_serial_port *port;
3197 struct usb_serial *serial;
3199 if (ATEN2011_port == NULL)
3202 port = (struct usb_serial_port *)ATEN2011_port->port;
3204 if (ATEN2011_port_paranoia_check(port, __FUNCTION__)) {
3205 DPRINTK("%s", "Invalid port \n");
3209 if (ATEN2011_serial_paranoia_check(port->serial, __FUNCTION__)) {
3210 DPRINTK("%s", "Invalid Serial \n");
3214 serial = port->serial;
3216 dbg("%s - port %d", __FUNCTION__, ATEN2011_port->port->number);
3218 if ((!ATEN2011_port->open) && (!ATEN2011_port->openPending)) {
3219 dbg("%s - port not opened", __FUNCTION__);
3222 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27)
3223 tty = ATEN2011_port->port->tty;
3226 if ((!tty) || (!tty->termios)) {
3227 dbg("%s - no tty structures", __FUNCTION__);
3231 DPRINTK("%s", "Entering .......... \n");
3235 lParity = LCR_PAR_NONE;
3237 cflag = tty->termios->c_cflag;
3238 iflag = tty->termios->c_iflag;
3240 /* Change the number of bits */
3242 //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
3245 switch (cflag & CSIZE) {
3266 /* Change the Parity bit */
3267 if (cflag & PARENB) {
3268 if (cflag & PARODD) {
3269 lParity = LCR_PAR_ODD;
3270 dbg("%s - parity = odd", __FUNCTION__);
3272 lParity = LCR_PAR_EVEN;
3273 dbg("%s - parity = even", __FUNCTION__);
3277 dbg("%s - parity = none", __FUNCTION__);
3280 if (cflag & CMSPAR) {
3281 lParity = lParity | 0x20;
3284 /* Change the Stop bit */
3285 if (cflag & CSTOPB) {
3287 dbg("%s - stop bits = 2", __FUNCTION__);
3290 dbg("%s - stop bits = 1", __FUNCTION__);
3293 /* Update the LCR with the correct value */
3294 ATEN2011_port->shadowLCR &=
3295 ~(LCR_BITS_MASK | LCR_STOP_MASK | LCR_PAR_MASK);
3296 ATEN2011_port->shadowLCR |= (lData | lParity | lStop);
3298 ATEN2011_port->validDataMask = mask;
3300 ("ATEN2011_change_port_settings ATEN2011_port->shadowLCR is %x\n",
3301 ATEN2011_port->shadowLCR);
3302 /* Disable Interrupts */
3304 ATEN2011_set_Uart_Reg(port, INTERRUPT_ENABLE_REGISTER, Data);
3307 ATEN2011_set_Uart_Reg(port, FIFO_CONTROL_REGISTER, Data);
3310 ATEN2011_set_Uart_Reg(port, FIFO_CONTROL_REGISTER, Data);
3312 /* Send the updated LCR value to the ATEN2011 */
3313 Data = ATEN2011_port->shadowLCR;
3315 ATEN2011_set_Uart_Reg(port, LINE_CONTROL_REGISTER, Data);
3318 ATEN2011_port->shadowMCR = Data;
3319 ATEN2011_set_Uart_Reg(port, MODEM_CONTROL_REGISTER, Data);
3321 ATEN2011_set_Uart_Reg(port, MODEM_CONTROL_REGISTER, Data);
3323 /* set up the MCR register and send it to the ATEN2011 */
3325 ATEN2011_port->shadowMCR = MCR_MASTER_IE;
3326 if (cflag & CBAUD) {
3327 ATEN2011_port->shadowMCR |= (MCR_DTR | MCR_RTS);
3330 if (cflag & CRTSCTS) {
3331 ATEN2011_port->shadowMCR |= (MCR_XON_ANY);
3334 ATEN2011_port->shadowMCR &= ~(MCR_XON_ANY);
3337 Data = ATEN2011_port->shadowMCR;
3338 ATEN2011_set_Uart_Reg(port, MODEM_CONTROL_REGISTER, Data);
3340 /* Determine divisor based on baud rate */
3341 baud = tty_get_baud_rate(tty);
3344 /* pick a default, any default... */
3345 DPRINTK("%s\n", "Picked default baud...");
3349 dbg("%s - baud rate = %d", __FUNCTION__, baud);
3350 status = ATEN2011_send_cmd_write_baud_rate(ATEN2011_port, baud);
3352 /* Enable Interrupts */
3354 ATEN2011_set_Uart_Reg(port, INTERRUPT_ENABLE_REGISTER, Data);
3356 if (ATEN2011_port->read_urb->status != -EINPROGRESS) {
3357 ATEN2011_port->read_urb->dev = serial->dev;
3359 status = usb_submit_urb(ATEN2011_port->read_urb, GFP_ATOMIC);
3363 (" usb_submit_urb(read bulk) failed, status = %d",
3367 //wake_up(&ATEN2011_port->delta_msr_wait);
3368 //ATEN2011_port->delta_msr_cond=1;
3370 ("ATEN2011_change_port_settings ATEN2011_port->shadowLCR is End %x\n",
3371 ATEN2011_port->shadowLCR);
3376 static int ATEN2011_calc_num_ports(struct usb_serial *serial)
3381 int ATEN2011_2or4ports;
3382 ret = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
3383 ATEN_RDREQ, ATEN_RD_RTYPE, 0, GPIO_REGISTER,
3384 &Data, VENDOR_READ_LENGTH, ATEN_WDR_TIMEOUT);
3386 //printk("ATEN2011_calc_num_ports GPIO is %x\n",Data);
3388 /* ghostgum: here is where the problem appears to bet */
3389 /* Which of the following are needed? */
3390 /* Greg used the serial->type->num_ports=2 */
3391 /* But the code in the ATEN2011_open relies on serial->num_ports=2 */
3392 if ((Data & 0x01) == 0) {
3393 ATEN2011_2or4ports = 2;
3394 serial->type->num_ports = 2;
3395 serial->num_ports = 2;
3397 //else if(serial->interface->cur_altsetting->desc.bNumEndpoints == 9)
3399 ATEN2011_2or4ports = 4;
3400 serial->type->num_ports = 4;
3401 serial->num_ports = 4;
3405 return ATEN2011_2or4ports;
3408 /****************************************************************************
3410 ****************************************************************************/
3412 static int ATEN2011_startup(struct usb_serial *serial)
3414 struct ATENINTL_serial *ATEN2011_serial;
3415 struct ATENINTL_port *ATEN2011_port;
3416 struct usb_device *dev;
3421 DPRINTK("%s \n", " ATEN2011_startup :entering..........");
3424 DPRINTK("%s\n", "Invalid Handler");
3430 DPRINTK("%s\n", "Entering...");
3432 /* create our private serial structure */
3433 ATEN2011_serial = kzalloc(sizeof(struct ATENINTL_serial), GFP_KERNEL);
3434 if (ATEN2011_serial == NULL) {
3435 err("%s - Out of memory", __FUNCTION__);
3439 /* resetting the private structure field values to zero */
3440 memset(ATEN2011_serial, 0, sizeof(struct ATENINTL_serial));
3442 ATEN2011_serial->serial = serial;
3443 //initilize status polling flag to FALSE
3444 ATEN2011_serial->status_polling_started = FALSE;
3446 ATEN2011_set_serial_private(serial, ATEN2011_serial);
3447 ATEN2011_serial->ATEN2011_spectrum_2or4ports =
3448 ATEN2011_calc_num_ports(serial);
3449 /* we set up the pointers to the endpoints in the ATEN2011_open *
3450 * function, as the structures aren't created yet. */
3452 /* set up port private structures */
3453 for (i = 0; i < serial->num_ports; ++i) {
3455 kmalloc(sizeof(struct ATENINTL_port), GFP_KERNEL);
3456 if (ATEN2011_port == NULL) {
3457 err("%s - Out of memory", __FUNCTION__);
3458 ATEN2011_set_serial_private(serial, NULL);
3459 kfree(ATEN2011_serial);
3462 memset(ATEN2011_port, 0, sizeof(struct ATENINTL_port));
3464 /* Initialize all port interrupt end point to port 0 int endpoint *
3465 * Our device has only one interrupt end point comman to all port */
3467 // serial->port[i]->interrupt_in_endpointAddress = serial->port[0]->interrupt_in_endpointAddress;
3469 ATEN2011_port->port = serial->port[i];
3471 ATEN2011_set_port_private(serial->port[i], ATEN2011_port);
3473 minor = serial->port[i]->serial->minor;
3474 if (minor == SERIAL_TTY_NO_MINOR)
3476 ATEN2011_port->port_num =
3477 ((serial->port[i]->number - minor) + 1);
3479 ATEN2011_port->AppNum = (((__u16) serial->port[i]->number -
3480 (__u16) (minor)) + 1) << 8;
3482 if (ATEN2011_port->port_num == 1) {
3483 ATEN2011_port->SpRegOffset = 0x0;
3484 ATEN2011_port->ControlRegOffset = 0x1;
3485 ATEN2011_port->DcrRegOffset = 0x4;
3486 //ATEN2011_port->ClkSelectRegOffset = ;
3487 } else if ((ATEN2011_port->port_num == 2)
3488 && (ATEN2011_serial->ATEN2011_spectrum_2or4ports ==
3490 ATEN2011_port->SpRegOffset = 0x8;
3491 ATEN2011_port->ControlRegOffset = 0x9;
3492 ATEN2011_port->DcrRegOffset = 0x16;
3493 //ATEN2011_port->ClkSelectRegOffset = ;
3494 } else if ((ATEN2011_port->port_num == 2)
3495 && (ATEN2011_serial->ATEN2011_spectrum_2or4ports ==
3497 ATEN2011_port->SpRegOffset = 0xa;
3498 ATEN2011_port->ControlRegOffset = 0xb;
3499 ATEN2011_port->DcrRegOffset = 0x19;
3500 //ATEN2011_port->ClkSelectRegOffset = ;
3501 } else if ((ATEN2011_port->port_num == 3)
3502 && (ATEN2011_serial->ATEN2011_spectrum_2or4ports ==
3504 ATEN2011_port->SpRegOffset = 0xa;
3505 ATEN2011_port->ControlRegOffset = 0xb;
3506 ATEN2011_port->DcrRegOffset = 0x19;
3507 //ATEN2011_port->ClkSelectRegOffset = ;
3508 } else if ((ATEN2011_port->port_num == 4)
3509 && (ATEN2011_serial->ATEN2011_spectrum_2or4ports ==
3511 ATEN2011_port->SpRegOffset = 0xc;
3512 ATEN2011_port->ControlRegOffset = 0xd;
3513 ATEN2011_port->DcrRegOffset = 0x1c;
3514 //ATEN2011_port->ClkSelectRegOffset = ;
3516 ATEN2011_Dump_serial_port(ATEN2011_port);
3518 ATEN2011_set_port_private(serial->port[i], ATEN2011_port);
3520 //enable rx_disable bit in control register
3523 ATEN2011_get_reg_sync(serial->port[i],
3524 ATEN2011_port->ControlRegOffset,
3527 DPRINTK("Reading ControlReg failed status-0x%x\n",
3532 ("ControlReg Reading success val is %x, status%d\n",
3534 Data |= 0x08; //setting driver done bit
3535 Data |= 0x04; //sp1_bit to have cts change reflect in modem status reg
3537 //Data |= 0x20; //rx_disable bit
3540 ATEN2011_set_reg_sync(serial->port[i],
3541 ATEN2011_port->ControlRegOffset,
3545 ("Writing ControlReg failed(rx_disable) status-0x%x\n",
3550 ("ControlReg Writing success(rx_disable) status%d\n",
3553 //Write default values in DCR (i.e 0x01 in DCR0, 0x05 in DCR2 and 0x24 in DCR3
3557 ATEN2011_set_reg_sync(serial->port[i],
3558 (__u16) (ATEN2011_port->DcrRegOffset +
3561 DPRINTK("Writing DCR0 failed status-0x%x\n", status);
3564 DPRINTK("DCR0 Writing success status%d\n", status);
3569 ATEN2011_set_reg_sync(serial->port[i],
3570 (__u16) (ATEN2011_port->DcrRegOffset +
3573 DPRINTK("Writing DCR1 failed status-0x%x\n", status);
3576 DPRINTK("DCR1 Writing success status%d\n", status);
3581 ATEN2011_set_reg_sync(serial->port[i],
3582 (__u16) (ATEN2011_port->DcrRegOffset +
3585 DPRINTK("Writing DCR2 failed status-0x%x\n", status);
3588 DPRINTK("DCR2 Writing success status%d\n", status);
3590 // write values in clkstart0x0 and clkmulti 0x20
3594 ATEN2011_set_reg_sync(serial->port[i],
3595 CLK_START_VALUE_REGISTER, Data);
3598 ("Writing CLK_START_VALUE_REGISTER failed status-0x%x\n",
3603 ("CLK_START_VALUE_REGISTER Writing success status%d\n",
3609 ATEN2011_set_reg_sync(serial->port[i], CLK_MULTI_REGISTER,
3613 ("Writing CLK_MULTI_REGISTER failed status-0x%x\n",
3617 DPRINTK("CLK_MULTI_REGISTER Writing success status%d\n",
3620 //write value 0x0 to scratchpad register
3627 status=ATEN2011_set_Uart_Reg(serial->port[i],SCRATCH_PAD_REGISTER,Data);
3629 DPRINTK("Writing SCRATCH_PAD_REGISTER failed status-0x%x\n", status);
3632 else DPRINTK("SCRATCH_PAD_REGISTER Writing success status%d\n",status);
3636 //Threshold Registers
3637 if(ATEN2011_serial->ATEN2011_spectrum_2or4ports==4)
3641 status=ATEN2011_set_reg_sync(serial->port[i],\
3642 (__u16)(THRESHOLD_VAL_SP1_1+(__u16)ATEN2011_Thr_cnt),Data);
3643 DPRINTK("THRESHOLD_VAL offset is%x\n", (__u16)(THRESHOLD_VAL_SP1_1+(__u16)ATEN2011_Thr_cnt));
3645 DPRINTK("Writing THRESHOLD_VAL failed status-0x%x\n",status);
3648 else DPRINTK("THRESHOLD_VAL Writing success status%d\n",status);
3653 status=ATEN2011_set_reg_sync(serial->port[i],\
3654 (__u16)(THRESHOLD_VAL_SP1_1+(__u16)ATEN2011_Thr_cnt),Data);
3655 DPRINTK("THRESHOLD_VAL offsetis%x\n",(__u16)(THRESHOLD_VAL_SP1_1+(__u16)ATEN2011_Thr_cnt));
3657 DPRINTK("Writing THRESHOLD_VAL failed status-0x%x\n",status);
3660 else DPRINTK("THRESHOLD_VAL Writing success status%d\n",status);
3667 if(ATEN2011_port->port_num==1)
3671 status=ATEN2011_set_reg_sync(serial->port[i],\
3673 DPRINTK("THRESHOLD_VAL offset is 0x3f\n");
3675 DPRINTK("Writing THRESHOLD_VAL failed status-0x%x\n",status);
3680 status=ATEN2011_set_reg_sync(serial->port[i],\
3682 DPRINTK("THRESHOLD_VAL offset is 0x40\n");
3684 DPRINTK("Writing THRESHOLD_VAL failed status-0x%x\n",status);
3693 status=ATEN2011_set_reg_sync(serial->port[i],\
3695 DPRINTK("THRESHOLD_VAL offset is 0x43\n");
3697 DPRINTK("Writing THRESHOLD_VAL failed status-0x%x\n",status);
3702 status=ATEN2011_set_reg_sync(serial->port[i],\
3704 DPRINTK("THRESHOLD_VAL offset is 0x44\n");
3706 DPRINTK("Writing THRESHOLD_VAL failed status-0x%x\n",status);
3715 //Zero Length flag register
3716 if ((ATEN2011_port->port_num != 1)
3717 && (ATEN2011_serial->ATEN2011_spectrum_2or4ports == 2)) {
3721 status = ATEN2011_set_reg_sync(serial->port[i],
3727 DPRINTK("ZLIP offset%x\n",
3729 ((__u16) ATEN2011_port->port_num)));
3732 ("Writing ZLP_REG%d failed status-0x%x\n",
3736 DPRINTK("ZLP_REG%d Writing success status%d\n",
3741 status = ATEN2011_set_reg_sync(serial->port[i],
3747 DPRINTK("ZLIP offset%x\n",
3749 ((__u16) ATEN2011_port->port_num) -
3753 ("Writing ZLP_REG%d failed status-0x%x\n",
3757 DPRINTK("ZLP_REG%d Writing success status%d\n",
3761 ATEN2011_port->control_urb = usb_alloc_urb(0, GFP_ATOMIC);
3762 ATEN2011_port->ctrl_buf = kmalloc(16, GFP_KERNEL);
3766 ATEN2011_Thr_cnt = 0;
3767 //Zero Length flag enable
3770 status = ATEN2011_set_reg_sync(serial->port[0], ZLP_REG5, Data);
3772 DPRINTK("Writing ZLP_REG5 failed status-0x%x\n", status);
3775 DPRINTK("ZLP_REG5 Writing success status%d\n", status);
3777 /* setting configuration feature to one */
3778 usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
3779 (__u8) 0x03, 0x00, 0x01, 0x00, 0x00, 0x00, 5 * HZ);
3780 ATEN2011_Thr_cnt = 0;
3784 /****************************************************************************
3786 * This function is called whenever the device is removed from the usb bus.
3787 ****************************************************************************/
3789 static void ATEN2011_shutdown(struct usb_serial *serial)
3792 struct ATENINTL_port *ATEN2011_port;
3793 DPRINTK("%s \n", " shutdown :entering..........");
3800 DPRINTK("%s", "Invalid Handler \n");
3804 /* check for the ports to be closed,close the ports and disconnect */
3806 /* free private structure allocated for serial port *
3807 * stop reads and writes on all ports */
3809 for (i = 0; i < serial->num_ports; ++i) {
3810 ATEN2011_port = ATEN2011_get_port_private(serial->port[i]);
3811 kfree(ATEN2011_port->ctrl_buf);
3812 usb_kill_urb(ATEN2011_port->control_urb);
3813 kfree(ATEN2011_port);
3814 ATEN2011_set_port_private(serial->port[i], NULL);
3817 /* free private structure allocated for serial device */
3819 kfree(ATEN2011_get_serial_private(serial));
3820 ATEN2011_set_serial_private(serial, NULL);
3822 DPRINTK("%s\n", "Thank u :: ");
3826 /* Inline functions to check the sanity of a pointer that is passed to us */
3827 static int ATEN2011_serial_paranoia_check(struct usb_serial *serial,
3828 const char *function)
3831 dbg("%s - serial == NULL", function);
3834 // if (serial->magic != USB_SERIAL_MAGIC) {
3835 // dbg("%s - bad magic number for serial", function);
3838 if (!serial->type) {
3839 dbg("%s - serial->type == NULL!", function);
3845 static int ATEN2011_port_paranoia_check(struct usb_serial_port *port,
3846 const char *function)
3849 dbg("%s - port == NULL", function);
3852 // if (port->magic != USB_SERIAL_PORT_MAGIC) {
3853 // dbg("%s - bad magic number for port", function);
3856 if (!port->serial) {
3857 dbg("%s - port->serial == NULL", function);
3863 static struct usb_serial *ATEN2011_get_usb_serial(struct usb_serial_port *port,
3864 const char *function)
3866 /* if no port was specified, or it fails a paranoia check */
3868 ATEN2011_port_paranoia_check(port, function) ||
3869 ATEN2011_serial_paranoia_check(port->serial, function)) {
3870 /* then say that we don't have a valid usb_serial thing, which will * end up genrating -ENODEV return values */
3874 return port->serial;
3877 /****************************************************************************
3879 * This is called by the module subsystem, or on startup to initialize us
3880 ****************************************************************************/
3881 int __init ATENINTL2011_init(void)
3885 DPRINTK("%s \n", " ATEN2011_init :entering..........");
3887 /* Register with the usb serial */
3888 retval = usb_serial_register(&ATENINTL2011_4port_device);
3891 goto failed_port_device_register;
3893 /* info(DRIVER_DESC " " DRIVER_VERSION); */
3894 printk(KERN_INFO KBUILD_MODNAME ":"
3895 DRIVER_DESC " " DRIVER_VERSION "\n");
3897 /* Register with the usb */
3898 retval = usb_register(&io_driver);
3901 goto failed_usb_register;
3904 DPRINTK("%s\n", "Leaving...");
3908 failed_usb_register:
3909 usb_serial_deregister(&ATENINTL2011_4port_device);
3911 failed_port_device_register:
3916 /****************************************************************************
3918 * Called when the driver is about to be unloaded.
3919 ****************************************************************************/
3920 void __exit ATENINTL2011_exit(void)
3923 DPRINTK("%s \n", " ATEN2011_exit :entering..........");
3925 usb_deregister(&io_driver);
3927 usb_serial_deregister(&ATENINTL2011_4port_device);
3929 DPRINTK("%s\n", "End...");
3932 module_init(ATENINTL2011_init);
3933 module_exit(ATENINTL2011_exit);
3935 /* Module information */
3936 MODULE_DESCRIPTION(DRIVER_DESC);
3937 MODULE_LICENSE("GPL");
3939 MODULE_PARM_DESC(debug, "Debug enabled or not");