Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1 | /* |
Greg Kroah-Hartman | c3858cb | 2009-01-29 16:41:35 -0800 | [diff] [blame] | 2 | * Aten 2011 USB serial driver for 4 port devices |
| 3 | * |
| 4 | * Copyright (C) 2000 Inside Out Networks |
| 5 | * Copyright (C) 2001-2002, 2009 Greg Kroah-Hartman <greg@kroah.com> |
| 6 | * Copyright (C) 2009 Novell Inc. |
| 7 | * |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 13 | */ |
| 14 | |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 15 | #include <linux/kernel.h> |
| 16 | #include <linux/errno.h> |
| 17 | #include <linux/init.h> |
| 18 | #include <linux/slab.h> |
| 19 | #include <linux/tty.h> |
| 20 | #include <linux/tty_driver.h> |
| 21 | #include <linux/tty_flip.h> |
| 22 | #include <linux/module.h> |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 23 | #include <linux/serial.h> |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 24 | #include <linux/usb.h> |
Greg Kroah-Hartman | a636409 | 2009-01-29 16:57:23 -0800 | [diff] [blame^] | 25 | #include <linux/usb/serial.h> |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 26 | #include <asm/uaccess.h> |
| 27 | |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 28 | |
Greg Kroah-Hartman | a636409 | 2009-01-29 16:57:23 -0800 | [diff] [blame^] | 29 | #define ZLP_REG1 0x3A /* Zero_Flag_Reg1 58 */ |
| 30 | #define ZLP_REG2 0x3B /* Zero_Flag_Reg2 59 */ |
| 31 | #define ZLP_REG3 0x3C /* Zero_Flag_Reg3 60 */ |
| 32 | #define ZLP_REG4 0x3D /* Zero_Flag_Reg4 61 */ |
| 33 | #define ZLP_REG5 0x3E /* Zero_Flag_Reg5 62 */ |
Greg Kroah-Hartman | e5ce610 | 2009-01-29 12:57:52 -0800 | [diff] [blame] | 34 | |
Greg Kroah-Hartman | a636409 | 2009-01-29 16:57:23 -0800 | [diff] [blame^] | 35 | /* Interrupt Rotinue Defines */ |
| 36 | #define SERIAL_IIR_RLS 0x06 |
| 37 | #define SERIAL_IIR_RDA 0x04 |
| 38 | #define SERIAL_IIR_CTI 0x0c |
| 39 | #define SERIAL_IIR_THR 0x02 |
| 40 | #define SERIAL_IIR_MS 0x00 |
Greg Kroah-Hartman | e5ce610 | 2009-01-29 12:57:52 -0800 | [diff] [blame] | 41 | |
Greg Kroah-Hartman | a636409 | 2009-01-29 16:57:23 -0800 | [diff] [blame^] | 42 | /* Emulation of the bit mask on the LINE STATUS REGISTER. */ |
| 43 | #define SERIAL_LSR_DR 0x0001 |
| 44 | #define SERIAL_LSR_OE 0x0002 |
| 45 | #define SERIAL_LSR_PE 0x0004 |
| 46 | #define SERIAL_LSR_FE 0x0008 |
| 47 | #define SERIAL_LSR_BI 0x0010 |
| 48 | #define SERIAL_LSR_THRE 0x0020 |
| 49 | #define SERIAL_LSR_TEMT 0x0040 |
| 50 | #define SERIAL_LSR_FIFOERR 0x0080 |
Greg Kroah-Hartman | e5ce610 | 2009-01-29 12:57:52 -0800 | [diff] [blame] | 51 | |
Greg Kroah-Hartman | a636409 | 2009-01-29 16:57:23 -0800 | [diff] [blame^] | 52 | /* MSR bit defines(place holders) */ |
| 53 | #define ATEN_MSR_DELTA_CTS 0x10 |
| 54 | #define ATEN_MSR_DELTA_DSR 0x20 |
| 55 | #define ATEN_MSR_DELTA_RI 0x40 |
| 56 | #define ATEN_MSR_DELTA_CD 0x80 |
Greg Kroah-Hartman | e5ce610 | 2009-01-29 12:57:52 -0800 | [diff] [blame] | 57 | |
Greg Kroah-Hartman | a636409 | 2009-01-29 16:57:23 -0800 | [diff] [blame^] | 58 | /* Serial Port register Address */ |
| 59 | #define RECEIVE_BUFFER_REGISTER ((__u16)(0x00)) |
| 60 | #define TRANSMIT_HOLDING_REGISTER ((__u16)(0x00)) |
| 61 | #define INTERRUPT_ENABLE_REGISTER ((__u16)(0x01)) |
| 62 | #define INTERRUPT_IDENT_REGISTER ((__u16)(0x02)) |
| 63 | #define FIFO_CONTROL_REGISTER ((__u16)(0x02)) |
| 64 | #define LINE_CONTROL_REGISTER ((__u16)(0x03)) |
| 65 | #define MODEM_CONTROL_REGISTER ((__u16)(0x04)) |
| 66 | #define LINE_STATUS_REGISTER ((__u16)(0x05)) |
| 67 | #define MODEM_STATUS_REGISTER ((__u16)(0x06)) |
| 68 | #define SCRATCH_PAD_REGISTER ((__u16)(0x07)) |
| 69 | #define DIVISOR_LATCH_LSB ((__u16)(0x00)) |
| 70 | #define DIVISOR_LATCH_MSB ((__u16)(0x01)) |
Greg Kroah-Hartman | e5ce610 | 2009-01-29 12:57:52 -0800 | [diff] [blame] | 71 | |
Greg Kroah-Hartman | a636409 | 2009-01-29 16:57:23 -0800 | [diff] [blame^] | 72 | #define SP1_REGISTER ((__u16)(0x00)) |
| 73 | #define CONTROL1_REGISTER ((__u16)(0x01)) |
| 74 | #define CLK_MULTI_REGISTER ((__u16)(0x02)) |
| 75 | #define CLK_START_VALUE_REGISTER ((__u16)(0x03)) |
| 76 | #define DCR1_REGISTER ((__u16)(0x04)) |
| 77 | #define GPIO_REGISTER ((__u16)(0x07)) |
Greg Kroah-Hartman | e5ce610 | 2009-01-29 12:57:52 -0800 | [diff] [blame] | 78 | |
Greg Kroah-Hartman | a636409 | 2009-01-29 16:57:23 -0800 | [diff] [blame^] | 79 | #define SERIAL_LCR_DLAB ((__u16)(0x0080)) |
Greg Kroah-Hartman | e5ce610 | 2009-01-29 12:57:52 -0800 | [diff] [blame] | 80 | |
Greg Kroah-Hartman | a636409 | 2009-01-29 16:57:23 -0800 | [diff] [blame^] | 81 | /* |
| 82 | * URB POOL related defines |
| 83 | */ |
| 84 | #define NUM_URBS 16 /* URB Count */ |
| 85 | #define URB_TRANSFER_BUFFER_SIZE 32 /* URB Size */ |
Greg Kroah-Hartman | e5ce610 | 2009-01-29 12:57:52 -0800 | [diff] [blame] | 86 | |
Greg Kroah-Hartman | e5ce610 | 2009-01-29 12:57:52 -0800 | [diff] [blame] | 87 | #define USB_VENDOR_ID_ATENINTL 0x0557 |
| 88 | #define ATENINTL_DEVICE_ID_2011 0x2011 |
| 89 | #define ATENINTL_DEVICE_ID_7820 0x7820 |
| 90 | |
Greg Kroah-Hartman | a636409 | 2009-01-29 16:57:23 -0800 | [diff] [blame^] | 91 | /* different USB-serial Adapter's ID's table */ |
Greg Kroah-Hartman | e5ce610 | 2009-01-29 12:57:52 -0800 | [diff] [blame] | 92 | static struct usb_device_id ATENINTL_port_id_table [] = { |
| 93 | { USB_DEVICE(USB_VENDOR_ID_ATENINTL,ATENINTL_DEVICE_ID_2011) }, |
| 94 | { USB_DEVICE(USB_VENDOR_ID_ATENINTL,ATENINTL_DEVICE_ID_7820) }, |
| 95 | { } /* terminating entry */ |
| 96 | }; |
| 97 | |
| 98 | static __devinitdata struct usb_device_id id_table_combined [] = { |
| 99 | { USB_DEVICE(USB_VENDOR_ID_ATENINTL,ATENINTL_DEVICE_ID_2011) }, |
| 100 | { USB_DEVICE(USB_VENDOR_ID_ATENINTL,ATENINTL_DEVICE_ID_7820) }, |
| 101 | { } /* terminating entry */ |
| 102 | }; |
| 103 | |
| 104 | MODULE_DEVICE_TABLE (usb, id_table_combined); |
| 105 | |
| 106 | /* This structure holds all of the local port information */ |
| 107 | struct ATENINTL_port |
| 108 | { |
| 109 | int port_num; /*Actual port number in the device(1,2,etc)*/ |
| 110 | __u8 bulk_out_endpoint; /* the bulk out endpoint handle */ |
| 111 | unsigned char *bulk_out_buffer; /* buffer used for the bulk out endpoint */ |
| 112 | struct urb *write_urb; /* write URB for this port */ |
| 113 | __u8 bulk_in_endpoint; /* the bulk in endpoint handle */ |
| 114 | unsigned char *bulk_in_buffer; /* the buffer we use for the bulk in endpoint */ |
| 115 | struct urb *read_urb; /* read URB for this port */ |
| 116 | __s16 rxBytesAvail;/*the number of bytes that we need to read from this device */ |
| 117 | __s16 rxBytesRemaining; /* the number of port bytes left to read */ |
| 118 | char write_in_progress; /* TRUE while a write URB is outstanding */ |
| 119 | __u8 shadowLCR; /* last LCR value received */ |
| 120 | __u8 shadowMCR; /* last MCR value received */ |
| 121 | __u8 shadowMSR; /* last MSR value received */ |
| 122 | __u8 shadowLSR; /* last LSR value received */ |
| 123 | __u8 shadowXonChar; /* last value set as XON char in ATENINTL */ |
| 124 | __u8 shadowXoffChar; /* last value set as XOFF char in ATENINTL */ |
| 125 | __u8 validDataMask; |
| 126 | __u32 baudRate; |
| 127 | char open; |
| 128 | char openPending; |
| 129 | char commandPending; |
| 130 | char closePending; |
| 131 | char chaseResponsePending; |
| 132 | wait_queue_head_t wait_chase; /* for handling sleeping while waiting for chase to finish */ |
| 133 | wait_queue_head_t wait_open; /* for handling sleeping while waiting for open to finish */ |
| 134 | wait_queue_head_t wait_command; /* for handling sleeping while waiting for command to finish */ |
| 135 | wait_queue_head_t delta_msr_wait; /* for handling sleeping while waiting for msr change to happen */ |
| 136 | int delta_msr_cond; |
| 137 | struct async_icount icount; |
| 138 | struct usb_serial_port *port; /* loop back to the owner of this object */ |
| 139 | /*Offsets*/ |
| 140 | __u16 AppNum; |
| 141 | __u8 SpRegOffset; |
| 142 | __u8 ControlRegOffset; |
| 143 | __u8 DcrRegOffset; |
Greg Kroah-Hartman | e5ce610 | 2009-01-29 12:57:52 -0800 | [diff] [blame] | 144 | //for processing control URBS in interrupt context |
| 145 | struct urb *control_urb; |
| 146 | // __le16 rx_creg; |
| 147 | char *ctrl_buf; |
| 148 | int MsrLsr; |
| 149 | |
| 150 | struct urb *write_urb_pool[NUM_URBS]; |
| 151 | /* we pass a pointer to this as the arguement sent to cypress_set_termios old_termios */ |
| 152 | struct ktermios tmp_termios; /* stores the old termios settings */ |
| 153 | spinlock_t lock; /* private lock */ |
| 154 | }; |
| 155 | |
| 156 | |
| 157 | /* This structure holds all of the individual serial device information */ |
| 158 | struct ATENINTL_serial |
| 159 | { |
Greg Kroah-Hartman | e5ce610 | 2009-01-29 12:57:52 -0800 | [diff] [blame] | 160 | __u8 interrupt_in_endpoint; /* the interrupt endpoint handle */ |
| 161 | unsigned char *interrupt_in_buffer; /* the buffer we use for the interrupt endpoint */ |
| 162 | struct urb * interrupt_read_urb; /* our interrupt urb */ |
| 163 | __u8 bulk_in_endpoint; /* the bulk in endpoint handle */ |
| 164 | unsigned char *bulk_in_buffer; /* the buffer we use for the bulk in endpoint */ |
| 165 | struct urb *read_urb; /* our bulk read urb */ |
| 166 | __u8 bulk_out_endpoint; /* the bulk out endpoint handle */ |
| 167 | __s16 rxBytesAvail; /* the number of bytes that we need to read from this device */ |
| 168 | __u8 rxPort; /* the port that we are currently receiving data for */ |
| 169 | __u8 rxStatusCode; /* the receive status code */ |
| 170 | __u8 rxStatusParam; /* the receive status paramater */ |
| 171 | __s16 rxBytesRemaining; /* the number of port bytes left to read */ |
| 172 | struct usb_serial *serial; /* loop back to the owner of this object */ |
| 173 | int ATEN2011_spectrum_2or4ports; //this says the number of ports in the device |
| 174 | // Indicates about the no.of opened ports of an individual USB-serial adapater. |
| 175 | unsigned int NoOfOpenPorts; |
| 176 | // a flag for Status endpoint polling |
| 177 | unsigned char status_polling_started; |
| 178 | }; |
| 179 | |
Greg Kroah-Hartman | e5ce610 | 2009-01-29 12:57:52 -0800 | [diff] [blame] | 180 | static void ATEN2011_interrupt_callback(struct urb *urb); |
| 181 | static void ATEN2011_bulk_in_callback(struct urb *urb); |
| 182 | static void ATEN2011_bulk_out_data_callback(struct urb *urb); |
| 183 | static void ATEN2011_control_callback(struct urb *urb); |
| 184 | static int ATEN2011_get_reg(struct ATENINTL_port *ATEN,__u16 Wval, __u16 reg, __u16 * val); |
| 185 | int handle_newMsr(struct ATENINTL_port *port,__u8 newMsr); |
| 186 | int handle_newLsr(struct ATENINTL_port *port,__u8 newLsr); |
Greg Kroah-Hartman | e5ce610 | 2009-01-29 12:57:52 -0800 | [diff] [blame] | 187 | static int ATEN2011_open(struct tty_struct *tty, struct usb_serial_port *port, struct file *filp); |
| 188 | static void ATEN2011_close(struct tty_struct *tty, struct usb_serial_port *port, struct file *filp); |
| 189 | static int ATEN2011_write(struct tty_struct *tty, struct usb_serial_port *port, const unsigned char *data, int count); |
| 190 | static int ATEN2011_write_room(struct tty_struct *tty); |
| 191 | static int ATEN2011_chars_in_buffer(struct tty_struct *tty); |
| 192 | static void ATEN2011_throttle(struct tty_struct *tty); |
| 193 | static void ATEN2011_unthrottle(struct tty_struct *tty); |
| 194 | static void ATEN2011_set_termios(struct tty_struct *tty, struct usb_serial_port *port, struct ktermios *old_termios); |
| 195 | static int ATEN2011_tiocmset(struct tty_struct *tty, struct file *file, |
| 196 | unsigned int set, unsigned int clear); |
| 197 | static int ATEN2011_tiocmget(struct tty_struct *tty, struct file *file); |
| 198 | static int ATEN2011_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg); |
| 199 | static void ATEN2011_break(struct tty_struct *tty, int break_state); |
Greg Kroah-Hartman | e5ce610 | 2009-01-29 12:57:52 -0800 | [diff] [blame] | 200 | static int ATEN2011_startup(struct usb_serial *serial); |
| 201 | static void ATEN2011_shutdown(struct usb_serial *serial); |
Greg Kroah-Hartman | e5ce610 | 2009-01-29 12:57:52 -0800 | [diff] [blame] | 202 | static int ATEN2011_calc_num_ports(struct usb_serial *serial); |
| 203 | |
Greg Kroah-Hartman | e5ce610 | 2009-01-29 12:57:52 -0800 | [diff] [blame] | 204 | static int ATEN2011_calc_baud_rate_divisor(int baudRate, int *divisor,__u16 *clk_sel_val); |
| 205 | static int ATEN2011_send_cmd_write_baud_rate(struct ATENINTL_port *ATEN2011_port, int baudRate); |
Greg Kroah-Hartman | e5ce610 | 2009-01-29 12:57:52 -0800 | [diff] [blame] | 206 | static void ATEN2011_change_port_settings(struct tty_struct *tty, struct ATENINTL_port *ATEN2011_port, struct ktermios *old_termios); |
| 207 | static void ATEN2011_block_until_chase_response(struct tty_struct *tty, struct ATENINTL_port *ATEN2011_port); |
| 208 | static void ATEN2011_block_until_tx_empty(struct tty_struct *tty, struct ATENINTL_port *ATEN2011_port); |
Greg Kroah-Hartman | e5ce610 | 2009-01-29 12:57:52 -0800 | [diff] [blame] | 209 | |
| 210 | int __init ATENINTL2011_init(void); |
| 211 | void __exit ATENINTL2011_exit(void); |
| 212 | |
| 213 | |
| 214 | /************************************* |
| 215 | * Bit definitions for each register * |
| 216 | *************************************/ |
| 217 | #define LCR_BITS_5 0x00 /* 5 bits/char */ |
| 218 | #define LCR_BITS_6 0x01 /* 6 bits/char */ |
| 219 | #define LCR_BITS_7 0x02 /* 7 bits/char */ |
| 220 | #define LCR_BITS_8 0x03 /* 8 bits/char */ |
| 221 | #define LCR_BITS_MASK 0x03 /* Mask for bits/char field */ |
| 222 | |
| 223 | #define LCR_STOP_1 0x00 /* 1 stop bit */ |
| 224 | #define LCR_STOP_1_5 0x04 /* 1.5 stop bits (if 5 bits/char) */ |
| 225 | #define LCR_STOP_2 0x04 /* 2 stop bits (if 6-8 bits/char) */ |
| 226 | #define LCR_STOP_MASK 0x04 /* Mask for stop bits field */ |
| 227 | |
| 228 | #define LCR_PAR_NONE 0x00 /* No parity */ |
| 229 | #define LCR_PAR_ODD 0x08 /* Odd parity */ |
| 230 | #define LCR_PAR_EVEN 0x18 /* Even parity */ |
| 231 | #define LCR_PAR_MARK 0x28 /* Force parity bit to 1 */ |
| 232 | #define LCR_PAR_SPACE 0x38 /* Force parity bit to 0 */ |
| 233 | #define LCR_PAR_MASK 0x38 /* Mask for parity field */ |
| 234 | |
| 235 | #define LCR_SET_BREAK 0x40 /* Set Break condition */ |
| 236 | #define LCR_DL_ENABLE 0x80 /* Enable access to divisor latch */ |
| 237 | |
| 238 | #define MCR_DTR 0x01 /* Assert DTR */ |
| 239 | #define MCR_RTS 0x02 /* Assert RTS */ |
| 240 | #define MCR_OUT1 0x04 /* Loopback only: Sets state of RI */ |
| 241 | #define MCR_MASTER_IE 0x08 /* Enable interrupt outputs */ |
| 242 | #define MCR_LOOPBACK 0x10 /* Set internal (digital) loopback mode */ |
| 243 | #define MCR_XON_ANY 0x20 /* Enable any char to exit XOFF mode */ |
| 244 | |
| 245 | #define ATEN2011_MSR_CTS 0x10 /* Current state of CTS */ |
| 246 | #define ATEN2011_MSR_DSR 0x20 /* Current state of DSR */ |
| 247 | #define ATEN2011_MSR_RI 0x40 /* Current state of RI */ |
| 248 | #define ATEN2011_MSR_CD 0x80 /* Current state of CD */ |
| 249 | |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 250 | |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 251 | /* 1: Enables the debugging -- 0: Disable the debugging */ |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 252 | #define ATEN_DEBUG 0 |
| 253 | |
| 254 | #ifdef ATEN_DEBUG |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 255 | static int debug = 0; |
| 256 | #define DPRINTK(fmt, args...) printk( "%s: " fmt, __FUNCTION__ , ## args) |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 257 | |
| 258 | #else |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 259 | static int debug = 0; |
| 260 | #define DPRINTK(fmt, args...) |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 261 | |
| 262 | #endif |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 263 | |
| 264 | /* |
| 265 | * Version Information |
| 266 | */ |
Greg Kroah-Hartman | a636409 | 2009-01-29 16:57:23 -0800 | [diff] [blame^] | 267 | #define DRIVER_VERSION "2.0" |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 268 | #define DRIVER_DESC "ATENINTL 2011 USB Serial Adapter" |
| 269 | |
| 270 | /* |
| 271 | * Defines used for sending commands to port |
| 272 | */ |
| 273 | |
Greg Kroah-Hartman | a636409 | 2009-01-29 16:57:23 -0800 | [diff] [blame^] | 274 | #define ATEN_WDR_TIMEOUT (50) /* default urb timeout */ |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 275 | |
| 276 | /* Requests */ |
Greg Kroah-Hartman | a636409 | 2009-01-29 16:57:23 -0800 | [diff] [blame^] | 277 | #define ATEN_RD_RTYPE 0xC0 |
| 278 | #define ATEN_WR_RTYPE 0x40 |
| 279 | #define ATEN_RDREQ 0x0D |
| 280 | #define ATEN_WRREQ 0x0E |
| 281 | #define ATEN_CTRL_TIMEOUT 500 |
| 282 | #define VENDOR_READ_LENGTH (0x01) |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 283 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 284 | int RS485mode = 0; //set to 1 for RS485 mode and 0 for RS232 mode |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 285 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 286 | static struct usb_serial *ATEN2011_get_usb_serial(struct usb_serial_port *port, const |
| 287 | char *function); |
| 288 | static int ATEN2011_serial_paranoia_check(struct usb_serial *serial, const char |
| 289 | *function); |
| 290 | static int ATEN2011_port_paranoia_check(struct usb_serial_port *port, const char |
| 291 | *function); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 292 | |
| 293 | /* setting and get register values */ |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 294 | static int ATEN2011_set_reg_sync(struct usb_serial_port *port, __u16 reg, |
| 295 | __u16 val); |
| 296 | static int ATEN2011_get_reg_sync(struct usb_serial_port *port, __u16 reg, |
| 297 | __u16 * val); |
| 298 | static int ATEN2011_set_Uart_Reg(struct usb_serial_port *port, __u16 reg, |
| 299 | __u16 val); |
| 300 | static int ATEN2011_get_Uart_Reg(struct usb_serial_port *port, __u16 reg, |
| 301 | __u16 * val); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 302 | |
| 303 | void ATEN2011_Dump_serial_port(struct ATENINTL_port *ATEN2011_port); |
| 304 | |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 305 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 306 | static inline void ATEN2011_set_serial_private(struct usb_serial *serial, |
| 307 | struct ATENINTL_serial *data) |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 308 | { |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 309 | usb_set_serial_data(serial, (void *)data); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 310 | } |
| 311 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 312 | static inline struct ATENINTL_serial *ATEN2011_get_serial_private(struct |
| 313 | usb_serial |
| 314 | *serial) |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 315 | { |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 316 | return (struct ATENINTL_serial *)usb_get_serial_data(serial); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 317 | } |
| 318 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 319 | static inline void ATEN2011_set_port_private(struct usb_serial_port *port, |
| 320 | struct ATENINTL_port *data) |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 321 | { |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 322 | usb_set_serial_port_data(port, (void *)data); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 323 | } |
| 324 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 325 | static inline struct ATENINTL_port *ATEN2011_get_port_private(struct |
| 326 | usb_serial_port |
| 327 | *port) |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 328 | { |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 329 | return (struct ATENINTL_port *)usb_get_serial_port_data(port); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 330 | } |
| 331 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 332 | static int ATEN2011_set_reg_sync(struct usb_serial_port *port, __u16 reg, |
| 333 | __u16 val) |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 334 | { |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 335 | struct usb_device *dev = port->serial->dev; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 336 | val = val & 0x00ff; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 337 | DPRINTK("ATEN2011_set_reg_sync offset is %x, value %x\n", reg, val); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 338 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 339 | return usb_control_msg(dev, usb_sndctrlpipe(dev, 0), ATEN_WRREQ, |
| 340 | ATEN_WR_RTYPE, val, reg, NULL, 0, |
| 341 | ATEN_WDR_TIMEOUT); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 342 | } |
| 343 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 344 | static int ATEN2011_get_reg_sync(struct usb_serial_port *port, __u16 reg, |
| 345 | __u16 * val) |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 346 | { |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 347 | struct usb_device *dev = port->serial->dev; |
| 348 | int ret = 0; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 349 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 350 | ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), ATEN_RDREQ, |
| 351 | ATEN_RD_RTYPE, 0, reg, val, VENDOR_READ_LENGTH, |
| 352 | ATEN_WDR_TIMEOUT); |
| 353 | DPRINTK("ATEN2011_get_reg_sync offset is %x, return val %x\n", reg, |
| 354 | *val); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 355 | *val = (*val) & 0x00ff; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 356 | return ret; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 357 | } |
| 358 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 359 | static int ATEN2011_set_Uart_Reg(struct usb_serial_port *port, __u16 reg, |
| 360 | __u16 val) |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 361 | { |
| 362 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 363 | struct usb_device *dev = port->serial->dev; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 364 | struct ATENINTL_serial *ATEN2011_serial; |
| 365 | int minor; |
| 366 | ATEN2011_serial = ATEN2011_get_serial_private(port->serial); |
| 367 | minor = port->serial->minor; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 368 | if (minor == SERIAL_TTY_NO_MINOR) |
| 369 | minor = 0; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 370 | val = val & 0x00ff; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 371 | // For the UART control registers, the application number need to be Or'ed |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 372 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 373 | if (ATEN2011_serial->ATEN2011_spectrum_2or4ports == 4) { |
| 374 | val |= (((__u16) port->number - (__u16) (minor)) + 1) << 8; |
| 375 | DPRINTK("ATEN2011_set_Uart_Reg application number is %x\n", |
| 376 | val); |
| 377 | } else { |
| 378 | if (((__u16) port->number - (__u16) (minor)) == 0) { |
| 379 | // val= 0x100; |
| 380 | val |= |
| 381 | (((__u16) port->number - (__u16) (minor)) + 1) << 8; |
| 382 | DPRINTK |
| 383 | ("ATEN2011_set_Uart_Reg application number is %x\n", |
| 384 | val); |
| 385 | } else { |
| 386 | // val=0x300; |
| 387 | val |= |
| 388 | (((__u16) port->number - (__u16) (minor)) + 2) << 8; |
| 389 | DPRINTK |
| 390 | ("ATEN2011_set_Uart_Reg application number is %x\n", |
| 391 | val); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 392 | } |
| 393 | } |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 394 | return usb_control_msg(dev, usb_sndctrlpipe(dev, 0), ATEN_WRREQ, |
| 395 | ATEN_WR_RTYPE, val, reg, NULL, 0, |
| 396 | ATEN_WDR_TIMEOUT); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 397 | |
| 398 | } |
| 399 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 400 | static int ATEN2011_get_Uart_Reg(struct usb_serial_port *port, __u16 reg, |
| 401 | __u16 * val) |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 402 | { |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 403 | struct usb_device *dev = port->serial->dev; |
| 404 | int ret = 0; |
| 405 | __u16 Wval; |
| 406 | struct ATENINTL_serial *ATEN2011_serial; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 407 | int minor = port->serial->minor; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 408 | ATEN2011_serial = ATEN2011_get_serial_private(port->serial); |
| 409 | if (minor == SERIAL_TTY_NO_MINOR) |
| 410 | minor = 0; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 411 | |
| 412 | //DPRINTK("application number is %4x \n",(((__u16)port->number - (__u16)(minor))+1)<<8); |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 413 | /*Wval is same as application number */ |
| 414 | if (ATEN2011_serial->ATEN2011_spectrum_2or4ports == 4) { |
| 415 | Wval = (((__u16) port->number - (__u16) (minor)) + 1) << 8; |
| 416 | DPRINTK("ATEN2011_get_Uart_Reg application number is %x\n", |
| 417 | Wval); |
| 418 | } else { |
| 419 | if (((__u16) port->number - (__u16) (minor)) == 0) { |
| 420 | // Wval= 0x100; |
| 421 | Wval = |
| 422 | (((__u16) port->number - (__u16) (minor)) + 1) << 8; |
| 423 | DPRINTK |
| 424 | ("ATEN2011_get_Uart_Reg application number is %x\n", |
| 425 | Wval); |
| 426 | } else { |
| 427 | // Wval=0x300; |
| 428 | Wval = |
| 429 | (((__u16) port->number - (__u16) (minor)) + 2) << 8; |
| 430 | DPRINTK |
| 431 | ("ATEN2011_get_Uart_Reg application number is %x\n", |
| 432 | Wval); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 433 | } |
| 434 | } |
| 435 | ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), ATEN_RDREQ, |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 436 | ATEN_RD_RTYPE, Wval, reg, val, VENDOR_READ_LENGTH, |
| 437 | ATEN_WDR_TIMEOUT); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 438 | *val = (*val) & 0x00ff; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 439 | return ret; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 440 | } |
| 441 | |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 442 | void ATEN2011_Dump_serial_port(struct ATENINTL_port *ATEN2011_port) |
| 443 | { |
| 444 | |
| 445 | DPRINTK("***************************************\n"); |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 446 | DPRINTK("Application number is %4x\n", ATEN2011_port->AppNum); |
| 447 | DPRINTK("SpRegOffset is %2x\n", ATEN2011_port->SpRegOffset); |
| 448 | DPRINTK("ControlRegOffset is %2x \n", ATEN2011_port->ControlRegOffset); |
| 449 | DPRINTK("DCRRegOffset is %2x \n", ATEN2011_port->DcrRegOffset); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 450 | DPRINTK("***************************************\n"); |
| 451 | |
| 452 | } |
| 453 | |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 454 | static struct usb_serial_driver ATENINTL2011_4port_device = { |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 455 | .driver = { |
| 456 | .owner = THIS_MODULE, |
| 457 | .name = "ATEN2011", |
| 458 | }, |
| 459 | .description = DRIVER_DESC, |
| 460 | .id_table = ATENINTL_port_id_table, |
| 461 | .open = ATEN2011_open, |
| 462 | .close = ATEN2011_close, |
| 463 | .write = ATEN2011_write, |
| 464 | .write_room = ATEN2011_write_room, |
| 465 | .chars_in_buffer = ATEN2011_chars_in_buffer, |
| 466 | .throttle = ATEN2011_throttle, |
| 467 | .unthrottle = ATEN2011_unthrottle, |
| 468 | .calc_num_ports = ATEN2011_calc_num_ports, |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 469 | |
| 470 | #ifdef ATENSerialProbe |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 471 | .probe = ATEN2011_serial_probe, |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 472 | #endif |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 473 | .ioctl = ATEN2011_ioctl, |
| 474 | .set_termios = ATEN2011_set_termios, |
| 475 | .break_ctl = ATEN2011_break, |
| 476 | // .break_ctl = ATEN2011_break_ctl, |
| 477 | .tiocmget = ATEN2011_tiocmget, |
| 478 | .tiocmset = ATEN2011_tiocmset, |
| 479 | .attach = ATEN2011_startup, |
| 480 | .shutdown = ATEN2011_shutdown, |
| 481 | .read_bulk_callback = ATEN2011_bulk_in_callback, |
| 482 | .read_int_callback = ATEN2011_interrupt_callback, |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 483 | }; |
| 484 | |
| 485 | static struct usb_driver io_driver = { |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 486 | .name = "ATEN2011", |
| 487 | .probe = usb_serial_probe, |
| 488 | .disconnect = usb_serial_disconnect, |
| 489 | .id_table = id_table_combined, |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 490 | }; |
| 491 | |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 492 | //#ifdef ATEN2011 |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 493 | static void ATEN2011_interrupt_callback(struct urb *urb) |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 494 | { |
| 495 | int result; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 496 | int length; |
| 497 | struct ATENINTL_port *ATEN2011_port; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 498 | struct ATENINTL_serial *ATEN2011_serial; |
| 499 | struct usb_serial *serial; |
| 500 | __u16 Data; |
| 501 | unsigned char *data; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 502 | __u8 sp[5], st; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 503 | int i; |
| 504 | __u16 wval; |
| 505 | int minor; |
| 506 | //printk("in the function ATEN2011_interrupt_callback Length %d, Data %x \n",urb->actual_length,(unsigned int)urb->transfer_buffer); |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 507 | DPRINTK("%s", " : Entering\n"); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 508 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 509 | ATEN2011_serial = (struct ATENINTL_serial *)urb->context; |
Greg Kroah-Hartman | a636409 | 2009-01-29 16:57:23 -0800 | [diff] [blame^] | 510 | if (!urb) // || ATEN2011_serial->status_polling_started == 0 ) |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 511 | { |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 512 | DPRINTK("%s", "Invalid Pointer !!!!:\n"); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 513 | return; |
| 514 | } |
| 515 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 516 | switch (urb->status) { |
| 517 | case 0: |
| 518 | /* success */ |
| 519 | break; |
| 520 | case -ECONNRESET: |
| 521 | case -ENOENT: |
| 522 | case -ESHUTDOWN: |
| 523 | /* this urb is terminated, clean up */ |
| 524 | dbg("%s - urb shutting down with status: %d", __FUNCTION__, |
| 525 | urb->status); |
| 526 | return; |
| 527 | default: |
| 528 | dbg("%s - nonzero urb status received: %d", __FUNCTION__, |
| 529 | urb->status); |
| 530 | goto exit; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 531 | } |
| 532 | length = urb->actual_length; |
| 533 | data = urb->transfer_buffer; |
| 534 | |
| 535 | //ATEN2011_serial= (struct ATENINTL_serial *)urb->context; |
| 536 | //serial = ATEN2011_get_usb_serial(port,__FUNCTION__); |
| 537 | serial = ATEN2011_serial->serial; |
| 538 | |
| 539 | /* ATENINTL get 5 bytes |
| 540 | * Byte 1 IIR Port 1 (port.number is 0) |
| 541 | * Byte 2 IIR Port 2 (port.number is 1) |
| 542 | * Byte 3 IIR Port 3 (port.number is 2) |
| 543 | * Byte 4 IIR Port 4 (port.number is 3) |
| 544 | * Byte 5 FIFO status for both */ |
| 545 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 546 | if (length && length > 5) { |
| 547 | DPRINTK("%s \n", "Wrong data !!!"); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 548 | return; |
| 549 | } |
| 550 | |
| 551 | /* MATRIX */ |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 552 | if (ATEN2011_serial->ATEN2011_spectrum_2or4ports == 4) { |
| 553 | sp[0] = (__u8) data[0]; |
| 554 | sp[1] = (__u8) data[1]; |
| 555 | sp[2] = (__u8) data[2]; |
| 556 | sp[3] = (__u8) data[3]; |
| 557 | st = (__u8) data[4]; |
| 558 | } else { |
| 559 | sp[0] = (__u8) data[0]; |
| 560 | sp[1] = (__u8) data[2]; |
| 561 | //sp[2]=(__u8)data[2]; |
| 562 | //sp[3]=(__u8)data[3]; |
| 563 | st = (__u8) data[4]; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 564 | |
| 565 | } |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 566 | // printk("%s data is sp1:%x sp2:%x sp3:%x sp4:%x status:%x\n",__FUNCTION__,sp1,sp2,sp3,sp4,st); |
| 567 | for (i = 0; i < serial->num_ports; i++) { |
| 568 | ATEN2011_port = ATEN2011_get_port_private(serial->port[i]); |
| 569 | minor = serial->minor; |
| 570 | if (minor == SERIAL_TTY_NO_MINOR) |
| 571 | minor = 0; |
| 572 | if ((ATEN2011_serial->ATEN2011_spectrum_2or4ports == 2) |
| 573 | && (i != 0)) |
| 574 | wval = |
| 575 | (((__u16) serial->port[i]->number - |
| 576 | (__u16) (minor)) + 2) << 8; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 577 | else |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 578 | wval = |
| 579 | (((__u16) serial->port[i]->number - |
| 580 | (__u16) (minor)) + 1) << 8; |
Greg Kroah-Hartman | a636409 | 2009-01-29 16:57:23 -0800 | [diff] [blame^] | 581 | if (ATEN2011_port->open != 0) { |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 582 | //printk("%s wval is:(for 2011) %x\n",__FUNCTION__,wval); |
| 583 | |
| 584 | if (sp[i] & 0x01) { |
| 585 | DPRINTK("SP%d No Interrupt !!!\n", i); |
| 586 | } else { |
| 587 | switch (sp[i] & 0x0f) { |
| 588 | case SERIAL_IIR_RLS: |
| 589 | DPRINTK |
| 590 | ("Serial Port %d: Receiver status error or ", |
| 591 | i); |
| 592 | DPRINTK |
| 593 | ("address bit detected in 9-bit mode\n"); |
| 594 | ATEN2011_port->MsrLsr = 1; |
| 595 | ATEN2011_get_reg(ATEN2011_port, wval, |
| 596 | LINE_STATUS_REGISTER, |
| 597 | &Data); |
| 598 | break; |
| 599 | case SERIAL_IIR_MS: |
| 600 | DPRINTK |
| 601 | ("Serial Port %d: Modem status change\n", |
| 602 | i); |
| 603 | ATEN2011_port->MsrLsr = 0; |
| 604 | ATEN2011_get_reg(ATEN2011_port, wval, |
| 605 | MODEM_STATUS_REGISTER, |
| 606 | &Data); |
| 607 | break; |
| 608 | } |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 609 | } |
| 610 | } |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 611 | |
| 612 | } |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 613 | exit: |
Greg Kroah-Hartman | a636409 | 2009-01-29 16:57:23 -0800 | [diff] [blame^] | 614 | if (ATEN2011_serial->status_polling_started == 0) |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 615 | return; |
| 616 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 617 | result = usb_submit_urb(urb, GFP_ATOMIC); |
| 618 | if (result) { |
| 619 | dev_err(&urb->dev->dev, |
| 620 | "%s - Error %d submitting interrupt urb\n", |
| 621 | __FUNCTION__, result); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 622 | } |
| 623 | |
| 624 | return; |
| 625 | |
| 626 | } |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 627 | |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 628 | //#endif |
| 629 | static void ATEN2011_control_callback(struct urb *urb) |
| 630 | { |
| 631 | unsigned char *data; |
| 632 | struct ATENINTL_port *ATEN2011_port; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 633 | __u8 regval = 0x0; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 634 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 635 | if (!urb) { |
| 636 | DPRINTK("%s", "Invalid Pointer !!!!:\n"); |
| 637 | return; |
| 638 | } |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 639 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 640 | switch (urb->status) { |
| 641 | case 0: |
| 642 | /* success */ |
| 643 | break; |
| 644 | case -ECONNRESET: |
| 645 | case -ENOENT: |
| 646 | case -ESHUTDOWN: |
| 647 | /* this urb is terminated, clean up */ |
| 648 | dbg("%s - urb shutting down with status: %d", __FUNCTION__, |
| 649 | urb->status); |
| 650 | return; |
| 651 | default: |
| 652 | dbg("%s - nonzero urb status received: %d", __FUNCTION__, |
| 653 | urb->status); |
| 654 | goto exit; |
| 655 | } |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 656 | |
| 657 | ATEN2011_port = (struct ATENINTL_port *)urb->context; |
| 658 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 659 | DPRINTK("%s urb buffer size is %d\n", __FUNCTION__, urb->actual_length); |
| 660 | DPRINTK("%s ATEN2011_port->MsrLsr is %d port %d\n", __FUNCTION__, |
| 661 | ATEN2011_port->MsrLsr, ATEN2011_port->port_num); |
| 662 | data = urb->transfer_buffer; |
| 663 | regval = (__u8) data[0]; |
| 664 | DPRINTK("%s data is %x\n", __FUNCTION__, regval); |
| 665 | if (ATEN2011_port->MsrLsr == 0) |
| 666 | handle_newMsr(ATEN2011_port, regval); |
| 667 | else if (ATEN2011_port->MsrLsr == 1) |
| 668 | handle_newLsr(ATEN2011_port, regval); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 669 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 670 | exit: |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 671 | return; |
| 672 | } |
Greg Kroah-Hartman | c3858cb | 2009-01-29 16:41:35 -0800 | [diff] [blame] | 673 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 674 | int handle_newMsr(struct ATENINTL_port *port, __u8 newMsr) |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 675 | { |
| 676 | struct ATENINTL_port *ATEN2011_port; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 677 | struct async_icount *icount; |
| 678 | ATEN2011_port = port; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 679 | icount = &ATEN2011_port->icount; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 680 | if (newMsr & |
| 681 | (ATEN_MSR_DELTA_CTS | ATEN_MSR_DELTA_DSR | ATEN_MSR_DELTA_RI | |
| 682 | ATEN_MSR_DELTA_CD)) { |
| 683 | icount = &ATEN2011_port->icount; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 684 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 685 | /* update input line counters */ |
| 686 | if (newMsr & ATEN_MSR_DELTA_CTS) { |
| 687 | icount->cts++; |
| 688 | } |
| 689 | if (newMsr & ATEN_MSR_DELTA_DSR) { |
| 690 | icount->dsr++; |
| 691 | } |
| 692 | if (newMsr & ATEN_MSR_DELTA_CD) { |
| 693 | icount->dcd++; |
| 694 | } |
| 695 | if (newMsr & ATEN_MSR_DELTA_RI) { |
| 696 | icount->rng++; |
| 697 | } |
| 698 | } |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 699 | |
| 700 | return 0; |
| 701 | } |
Greg Kroah-Hartman | c3858cb | 2009-01-29 16:41:35 -0800 | [diff] [blame] | 702 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 703 | int handle_newLsr(struct ATENINTL_port *port, __u8 newLsr) |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 704 | { |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 705 | struct async_icount *icount; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 706 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 707 | dbg("%s - %02x", __FUNCTION__, newLsr); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 708 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 709 | if (newLsr & SERIAL_LSR_BI) { |
| 710 | // |
| 711 | // Parity and Framing errors only count if they |
| 712 | // occur exclusive of a break being |
| 713 | // received. |
| 714 | // |
| 715 | newLsr &= (__u8) (SERIAL_LSR_OE | SERIAL_LSR_BI); |
| 716 | } |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 717 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 718 | /* update input line counters */ |
| 719 | icount = &port->icount; |
| 720 | if (newLsr & SERIAL_LSR_BI) { |
| 721 | icount->brk++; |
| 722 | } |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 723 | if (newLsr & SERIAL_LSR_OE) { |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 724 | icount->overrun++; |
| 725 | } |
| 726 | if (newLsr & SERIAL_LSR_PE) { |
| 727 | icount->parity++; |
| 728 | } |
| 729 | if (newLsr & SERIAL_LSR_FE) { |
| 730 | icount->frame++; |
| 731 | } |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 732 | |
| 733 | return 0; |
| 734 | } |
Greg Kroah-Hartman | c3858cb | 2009-01-29 16:41:35 -0800 | [diff] [blame] | 735 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 736 | static int ATEN2011_get_reg(struct ATENINTL_port *ATEN, __u16 Wval, __u16 reg, |
| 737 | __u16 * val) |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 738 | { |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 739 | struct usb_device *dev = ATEN->port->serial->dev; |
| 740 | struct usb_ctrlrequest *dr = NULL; |
| 741 | unsigned char *buffer = NULL; |
| 742 | int ret = 0; |
| 743 | buffer = (__u8 *) ATEN->ctrl_buf; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 744 | |
| 745 | // dr=(struct usb_ctrlrequest *)(buffer); |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 746 | dr = (void *)(buffer + 2); |
| 747 | dr->bRequestType = ATEN_RD_RTYPE; |
| 748 | dr->bRequest = ATEN_RDREQ; |
| 749 | dr->wValue = cpu_to_le16(Wval); //0; |
| 750 | dr->wIndex = cpu_to_le16(reg); |
| 751 | dr->wLength = cpu_to_le16(2); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 752 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 753 | usb_fill_control_urb(ATEN->control_urb, dev, usb_rcvctrlpipe(dev, 0), |
| 754 | (unsigned char *)dr, buffer, 2, |
| 755 | ATEN2011_control_callback, ATEN); |
| 756 | ATEN->control_urb->transfer_buffer_length = 2; |
| 757 | ret = usb_submit_urb(ATEN->control_urb, GFP_ATOMIC); |
| 758 | return ret; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 759 | } |
| 760 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 761 | static void ATEN2011_bulk_in_callback(struct urb *urb) |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 762 | { |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 763 | int status; |
| 764 | unsigned char *data; |
| 765 | struct usb_serial *serial; |
| 766 | struct usb_serial_port *port; |
| 767 | struct ATENINTL_serial *ATEN2011_serial; |
| 768 | struct ATENINTL_port *ATEN2011_port; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 769 | struct tty_struct *tty; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 770 | if (!urb) { |
| 771 | DPRINTK("%s", "Invalid Pointer !!!!:\n"); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 772 | return; |
| 773 | } |
| 774 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 775 | if (urb->status) { |
| 776 | DPRINTK("nonzero read bulk status received: %d", urb->status); |
| 777 | // if(urb->status==84) |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 778 | //ThreadState=1; |
| 779 | return; |
| 780 | } |
| 781 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 782 | ATEN2011_port = (struct ATENINTL_port *)urb->context; |
| 783 | if (!ATEN2011_port) { |
| 784 | DPRINTK("%s", "NULL ATEN2011_port pointer \n"); |
| 785 | return; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 786 | } |
| 787 | |
| 788 | port = (struct usb_serial_port *)ATEN2011_port->port; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 789 | if (ATEN2011_port_paranoia_check(port, __FUNCTION__)) { |
| 790 | DPRINTK("%s", "Port Paranoia failed \n"); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 791 | return; |
| 792 | } |
| 793 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 794 | serial = ATEN2011_get_usb_serial(port, __FUNCTION__); |
| 795 | if (!serial) { |
| 796 | DPRINTK("%s\n", "Bad serial pointer "); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 797 | return; |
| 798 | } |
| 799 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 800 | DPRINTK("%s\n", "Entering... \n"); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 801 | |
| 802 | data = urb->transfer_buffer; |
| 803 | ATEN2011_serial = ATEN2011_get_serial_private(serial); |
| 804 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 805 | DPRINTK("%s", "Entering ........... \n"); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 806 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 807 | if (urb->actual_length) { |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 808 | tty = tty_port_tty_get(&ATEN2011_port->port->port); |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 809 | if (tty) { |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 810 | tty_buffer_request_room(tty, urb->actual_length); |
| 811 | tty_insert_flip_string(tty, data, urb->actual_length); |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 812 | DPRINTK(" %s \n", data); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 813 | tty_flip_buffer_push(tty); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 814 | tty_kref_put(tty); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 815 | } |
| 816 | |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 817 | ATEN2011_port->icount.rx += urb->actual_length; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 818 | DPRINTK("ATEN2011_port->icount.rx is %d:\n", |
| 819 | ATEN2011_port->icount.rx); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 820 | //MATRIX |
| 821 | } |
| 822 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 823 | if (!ATEN2011_port->read_urb) { |
| 824 | DPRINTK("%s", "URB KILLED !!!\n"); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 825 | return; |
| 826 | } |
| 827 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 828 | if (ATEN2011_port->read_urb->status != -EINPROGRESS) { |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 829 | ATEN2011_port->read_urb->dev = serial->dev; |
| 830 | |
| 831 | status = usb_submit_urb(ATEN2011_port->read_urb, GFP_ATOMIC); |
| 832 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 833 | if (status) { |
| 834 | DPRINTK |
| 835 | (" usb_submit_urb(read bulk) failed, status = %d", |
| 836 | status); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 837 | } |
| 838 | } |
| 839 | } |
| 840 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 841 | static void ATEN2011_bulk_out_data_callback(struct urb *urb) |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 842 | { |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 843 | struct ATENINTL_port *ATEN2011_port; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 844 | struct tty_struct *tty; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 845 | if (!urb) { |
| 846 | DPRINTK("%s", "Invalid Pointer !!!!:\n"); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 847 | return; |
| 848 | } |
| 849 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 850 | if (urb->status) { |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 851 | DPRINTK("nonzero write bulk status received:%d\n", urb->status); |
| 852 | return; |
| 853 | } |
| 854 | |
| 855 | ATEN2011_port = (struct ATENINTL_port *)urb->context; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 856 | if (!ATEN2011_port) { |
| 857 | DPRINTK("%s", "NULL ATEN2011_port pointer \n"); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 858 | return; |
| 859 | } |
| 860 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 861 | if (ATEN2011_port_paranoia_check(ATEN2011_port->port, __FUNCTION__)) { |
| 862 | DPRINTK("%s", "Port Paranoia failed \n"); |
| 863 | return; |
| 864 | } |
| 865 | |
| 866 | DPRINTK("%s \n", "Entering ........."); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 867 | |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 868 | tty = tty_port_tty_get(&ATEN2011_port->port->port); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 869 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 870 | if (tty && ATEN2011_port->open) { |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 871 | /* tell the tty driver that something has changed */ |
| 872 | wake_up_interruptible(&tty->write_wait); |
| 873 | } |
| 874 | |
| 875 | /* Release the Write URB */ |
Greg Kroah-Hartman | a636409 | 2009-01-29 16:57:23 -0800 | [diff] [blame^] | 876 | ATEN2011_port->write_in_progress = 0; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 877 | |
| 878 | //schedule_work(&ATEN2011_port->port->work); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 879 | tty_kref_put(tty); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 880 | |
| 881 | } |
| 882 | |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 883 | #ifdef ATENSerialProbe |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 884 | static int ATEN2011_serial_probe(struct usb_serial *serial, |
| 885 | const struct usb_device_id *id) |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 886 | { |
| 887 | |
| 888 | /*need to implement the mode_reg reading and updating\ |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 889 | structures usb_serial_ device_type\ |
| 890 | (i.e num_ports, num_bulkin,bulkout etc) */ |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 891 | /* Also we can update the changes attach */ |
| 892 | return 1; |
| 893 | } |
| 894 | #endif |
| 895 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 896 | static int ATEN2011_open(struct tty_struct *tty, struct usb_serial_port *port, |
| 897 | struct file *filp) |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 898 | { |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 899 | int response; |
| 900 | int j; |
| 901 | struct usb_serial *serial; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 902 | // struct usb_serial_port *port0; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 903 | struct urb *urb; |
| 904 | __u16 Data; |
| 905 | int status; |
| 906 | struct ATENINTL_serial *ATEN2011_serial; |
| 907 | struct ATENINTL_port *ATEN2011_port; |
| 908 | struct ktermios tmp_termios; |
| 909 | int minor; |
Greg Kroah-Hartman | 8b4efbe | 2009-01-29 13:08:23 -0800 | [diff] [blame] | 910 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 911 | if (ATEN2011_port_paranoia_check(port, __FUNCTION__)) { |
| 912 | DPRINTK("%s", "Port Paranoia failed \n"); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 913 | return -ENODEV; |
| 914 | } |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 915 | //ATEN2011_serial->NoOfOpenPorts++; |
| 916 | serial = port->serial; |
| 917 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 918 | if (ATEN2011_serial_paranoia_check(serial, __FUNCTION__)) { |
| 919 | DPRINTK("%s", "Serial Paranoia failed \n"); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 920 | return -ENODEV; |
| 921 | } |
| 922 | |
| 923 | ATEN2011_port = ATEN2011_get_port_private(port); |
| 924 | |
| 925 | if (ATEN2011_port == NULL) |
| 926 | return -ENODEV; |
| 927 | /* |
| 928 | if (ATEN2011_port->ctrl_buf==NULL) |
| 929 | { |
| 930 | ATEN2011_port->ctrl_buf = kmalloc(16,GFP_KERNEL); |
| 931 | if (ATEN2011_port->ctrl_buf == NULL) { |
| 932 | printk(", Can't allocate ctrl buff\n"); |
| 933 | return -ENOMEM; |
| 934 | } |
| 935 | |
| 936 | } |
| 937 | |
| 938 | if(!ATEN2011_port->control_urb) |
| 939 | { |
| 940 | ATEN2011_port->control_urb=kmalloc(sizeof(struct urb),GFP_KERNEL); |
| 941 | } |
| 942 | */ |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 943 | // port0 = serial->port[0]; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 944 | |
| 945 | ATEN2011_serial = ATEN2011_get_serial_private(serial); |
| 946 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 947 | if (ATEN2011_serial == NULL) //|| port0 == NULL) |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 948 | { |
| 949 | return -ENODEV; |
| 950 | } |
| 951 | // increment the number of opened ports counter here |
| 952 | ATEN2011_serial->NoOfOpenPorts++; |
| 953 | //printk("the num of ports opend is:%d\n",ATEN2011_serial->NoOfOpenPorts); |
| 954 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 955 | usb_clear_halt(serial->dev, port->write_urb->pipe); |
| 956 | usb_clear_halt(serial->dev, port->read_urb->pipe); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 957 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 958 | /* Initialising the write urb pool */ |
| 959 | for (j = 0; j < NUM_URBS; ++j) { |
| 960 | urb = usb_alloc_urb(0, GFP_ATOMIC); |
| 961 | ATEN2011_port->write_urb_pool[j] = urb; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 962 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 963 | if (urb == NULL) { |
| 964 | err("No more urbs???"); |
| 965 | continue; |
| 966 | } |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 967 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 968 | urb->transfer_buffer = NULL; |
| 969 | urb->transfer_buffer = |
| 970 | kmalloc(URB_TRANSFER_BUFFER_SIZE, GFP_KERNEL); |
| 971 | if (!urb->transfer_buffer) { |
| 972 | err("%s-out of memory for urb buffers.", __FUNCTION__); |
| 973 | continue; |
| 974 | } |
| 975 | } |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 976 | |
| 977 | /***************************************************************************** |
| 978 | * Initialize ATEN2011 -- Write Init values to corresponding Registers |
| 979 | * |
| 980 | * Register Index |
| 981 | * 1 : IER |
| 982 | * 2 : FCR |
| 983 | * 3 : LCR |
| 984 | * 4 : MCR |
| 985 | * |
| 986 | * 0x08 : SP1/2 Control Reg |
| 987 | *****************************************************************************/ |
| 988 | |
| 989 | //NEED to check the fallowing Block |
| 990 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 991 | status = 0; |
| 992 | Data = 0x0; |
| 993 | status = ATEN2011_get_reg_sync(port, ATEN2011_port->SpRegOffset, &Data); |
| 994 | if (status < 0) { |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 995 | DPRINTK("Reading Spreg failed\n"); |
| 996 | return -1; |
| 997 | } |
| 998 | Data |= 0x80; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 999 | status = ATEN2011_set_reg_sync(port, ATEN2011_port->SpRegOffset, Data); |
| 1000 | if (status < 0) { |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1001 | DPRINTK("writing Spreg failed\n"); |
| 1002 | return -1; |
| 1003 | } |
| 1004 | |
| 1005 | Data &= ~0x80; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1006 | status = ATEN2011_set_reg_sync(port, ATEN2011_port->SpRegOffset, Data); |
| 1007 | if (status < 0) { |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1008 | DPRINTK("writing Spreg failed\n"); |
| 1009 | return -1; |
| 1010 | } |
| 1011 | |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1012 | //End of block to be checked |
| 1013 | //**************************CHECK***************************// |
| 1014 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1015 | if (RS485mode == 0) |
| 1016 | Data = 0xC0; |
| 1017 | else |
| 1018 | Data = 0x00; |
| 1019 | status = 0; |
| 1020 | status = ATEN2011_set_Uart_Reg(port, SCRATCH_PAD_REGISTER, Data); |
| 1021 | if (status < 0) { |
| 1022 | DPRINTK("Writing SCRATCH_PAD_REGISTER failed status-0x%x\n", |
| 1023 | status); |
| 1024 | return -1; |
| 1025 | } else |
| 1026 | DPRINTK("SCRATCH_PAD_REGISTER Writing success status%d\n", |
| 1027 | status); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1028 | |
| 1029 | //**************************CHECK***************************// |
| 1030 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1031 | status = 0; |
| 1032 | Data = 0x0; |
| 1033 | status = |
| 1034 | ATEN2011_get_reg_sync(port, ATEN2011_port->ControlRegOffset, &Data); |
| 1035 | if (status < 0) { |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1036 | DPRINTK("Reading Controlreg failed\n"); |
| 1037 | return -1; |
| 1038 | } |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1039 | Data |= 0x08; //Driver done bit |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1040 | /* |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1041 | status = ATEN2011_set_reg_sync(port,ATEN2011_port->ControlRegOffset,Data); |
| 1042 | if(status<0){ |
| 1043 | DPRINTK("writing Controlreg failed\n"); |
| 1044 | return -1; |
| 1045 | } |
| 1046 | */ |
| 1047 | Data |= 0x20; //rx_disable |
| 1048 | status = 0; |
| 1049 | status = |
| 1050 | ATEN2011_set_reg_sync(port, ATEN2011_port->ControlRegOffset, Data); |
| 1051 | if (status < 0) { |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1052 | DPRINTK("writing Controlreg failed\n"); |
| 1053 | return -1; |
| 1054 | } |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1055 | //do register settings here |
| 1056 | // Set all regs to the device default values. |
| 1057 | //////////////////////////////////// |
| 1058 | // First Disable all interrupts. |
| 1059 | //////////////////////////////////// |
| 1060 | |
| 1061 | Data = 0x00; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1062 | status = 0; |
| 1063 | status = ATEN2011_set_Uart_Reg(port, INTERRUPT_ENABLE_REGISTER, Data); |
| 1064 | if (status < 0) { |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1065 | DPRINTK("disableing interrupts failed\n"); |
| 1066 | return -1; |
| 1067 | } |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1068 | // Set FIFO_CONTROL_REGISTER to the default value |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1069 | Data = 0x00; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1070 | status = 0; |
| 1071 | status = ATEN2011_set_Uart_Reg(port, FIFO_CONTROL_REGISTER, Data); |
| 1072 | if (status < 0) { |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1073 | DPRINTK("Writing FIFO_CONTROL_REGISTER failed\n"); |
| 1074 | return -1; |
| 1075 | } |
| 1076 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1077 | Data = 0xcf; //chk |
| 1078 | status = 0; |
| 1079 | status = ATEN2011_set_Uart_Reg(port, FIFO_CONTROL_REGISTER, Data); |
| 1080 | if (status < 0) { |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1081 | DPRINTK("Writing FIFO_CONTROL_REGISTER failed\n"); |
| 1082 | return -1; |
| 1083 | } |
| 1084 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1085 | Data = 0x03; //LCR_BITS_8 |
| 1086 | status = 0; |
| 1087 | status = ATEN2011_set_Uart_Reg(port, LINE_CONTROL_REGISTER, Data); |
| 1088 | ATEN2011_port->shadowLCR = Data; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1089 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1090 | Data = 0x0b; // MCR_DTR|MCR_RTS|MCR_MASTER_IE |
| 1091 | status = 0; |
| 1092 | status = ATEN2011_set_Uart_Reg(port, MODEM_CONTROL_REGISTER, Data); |
| 1093 | ATEN2011_port->shadowMCR = Data; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1094 | |
| 1095 | #ifdef Check |
| 1096 | Data = 0x00; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1097 | status = 0; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1098 | status = ATEN2011_get_Uart_Reg(port, LINE_CONTROL_REGISTER, &Data); |
| 1099 | ATEN2011_port->shadowLCR = Data; |
| 1100 | |
| 1101 | Data |= SERIAL_LCR_DLAB; //data latch enable in LCR 0x80 |
| 1102 | status = 0; |
| 1103 | status = ATEN2011_set_Uart_Reg(port, LINE_CONTROL_REGISTER, Data); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1104 | |
| 1105 | Data = 0x0c; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1106 | status = 0; |
| 1107 | status = ATEN2011_set_Uart_Reg(port, DIVISOR_LATCH_LSB, Data); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1108 | |
| 1109 | Data = 0x0; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1110 | status = 0; |
| 1111 | status = ATEN2011_set_Uart_Reg(port, DIVISOR_LATCH_MSB, Data); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1112 | |
| 1113 | Data = 0x00; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1114 | status = 0; |
| 1115 | status = ATEN2011_get_Uart_Reg(port, LINE_CONTROL_REGISTER, &Data); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1116 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1117 | // Data = ATEN2011_port->shadowLCR; //data latch disable |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1118 | Data = Data & ~SERIAL_LCR_DLAB; |
| 1119 | status = 0; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1120 | status = ATEN2011_set_Uart_Reg(port, LINE_CONTROL_REGISTER, Data); |
| 1121 | ATEN2011_port->shadowLCR = Data; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1122 | #endif |
| 1123 | //clearing Bulkin and Bulkout Fifo |
| 1124 | Data = 0x0; |
| 1125 | status = 0; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1126 | status = ATEN2011_get_reg_sync(port, ATEN2011_port->SpRegOffset, &Data); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1127 | |
| 1128 | Data = Data | 0x0c; |
| 1129 | status = 0; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1130 | status = ATEN2011_set_reg_sync(port, ATEN2011_port->SpRegOffset, Data); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1131 | |
| 1132 | Data = Data & ~0x0c; |
| 1133 | status = 0; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1134 | status = ATEN2011_set_reg_sync(port, ATEN2011_port->SpRegOffset, Data); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1135 | //Finally enable all interrupts |
| 1136 | Data = 0x0; |
| 1137 | Data = 0x0c; |
| 1138 | status = 0; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1139 | status = ATEN2011_set_Uart_Reg(port, INTERRUPT_ENABLE_REGISTER, Data); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1140 | |
| 1141 | //clearing rx_disable |
| 1142 | Data = 0x0; |
| 1143 | status = 0; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1144 | status = |
| 1145 | ATEN2011_get_reg_sync(port, ATEN2011_port->ControlRegOffset, &Data); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1146 | Data = Data & ~0x20; |
| 1147 | status = 0; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1148 | status = |
| 1149 | ATEN2011_set_reg_sync(port, ATEN2011_port->ControlRegOffset, Data); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1150 | |
| 1151 | // rx_negate |
| 1152 | Data = 0x0; |
| 1153 | status = 0; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1154 | status = |
| 1155 | ATEN2011_get_reg_sync(port, ATEN2011_port->ControlRegOffset, &Data); |
| 1156 | Data = Data | 0x10; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1157 | status = 0; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1158 | status = |
| 1159 | ATEN2011_set_reg_sync(port, ATEN2011_port->ControlRegOffset, Data); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1160 | |
| 1161 | /* force low_latency on so that our tty_push actually forces * |
| 1162 | * the data through,otherwise it is scheduled, and with * |
| 1163 | * high data rates (like with OHCI) data can get lost. */ |
| 1164 | |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1165 | if (tty) |
| 1166 | tty->low_latency = 1; |
| 1167 | /* |
| 1168 | printk("port number is %d \n",port->number); |
| 1169 | printk("serial number is %d \n",port->serial->minor); |
| 1170 | printk("Bulkin endpoint is %d \n",port->bulk_in_endpointAddress); |
| 1171 | printk("BulkOut endpoint is %d \n",port->bulk_out_endpointAddress); |
| 1172 | printk("Interrupt endpoint is %d \n",port->interrupt_in_endpointAddress); |
| 1173 | printk("port's number in the device is %d\n",ATEN2011_port->port_num); |
| 1174 | */ |
| 1175 | //////////////////////// |
| 1176 | //#ifdef CheckStatusPipe |
| 1177 | /* Check to see if we've set up our endpoint info yet * |
| 1178 | * (can't set it up in ATEN2011_startup as the structures * |
| 1179 | * were not set up at that time.) */ |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1180 | if (ATEN2011_serial->NoOfOpenPorts == 1) { |
| 1181 | // start the status polling here |
Greg Kroah-Hartman | a636409 | 2009-01-29 16:57:23 -0800 | [diff] [blame^] | 1182 | ATEN2011_serial->status_polling_started = 1; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1183 | //if (ATEN2011_serial->interrupt_in_buffer == NULL) |
| 1184 | // { |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1185 | /* If not yet set, Set here */ |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1186 | ATEN2011_serial->interrupt_in_buffer = |
| 1187 | serial->port[0]->interrupt_in_buffer; |
| 1188 | ATEN2011_serial->interrupt_in_endpoint = |
| 1189 | serial->port[0]->interrupt_in_endpointAddress; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1190 | //printk(" interrupt endpoint:%d \n",ATEN2011_serial->interrupt_in_endpoint); |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1191 | ATEN2011_serial->interrupt_read_urb = |
| 1192 | serial->port[0]->interrupt_in_urb; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1193 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1194 | /* set up interrupt urb */ |
| 1195 | usb_fill_int_urb(ATEN2011_serial->interrupt_read_urb, |
| 1196 | serial->dev, |
| 1197 | usb_rcvintpipe(serial->dev, |
| 1198 | ATEN2011_serial-> |
| 1199 | interrupt_in_endpoint), |
| 1200 | ATEN2011_serial->interrupt_in_buffer, |
| 1201 | ATEN2011_serial->interrupt_read_urb-> |
| 1202 | transfer_buffer_length, |
| 1203 | ATEN2011_interrupt_callback, ATEN2011_serial, |
| 1204 | ATEN2011_serial->interrupt_read_urb->interval); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1205 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1206 | /* start interrupt read for ATEN2011 * |
| 1207 | * will continue as long as ATEN2011 is connected */ |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1208 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1209 | response = |
| 1210 | usb_submit_urb(ATEN2011_serial->interrupt_read_urb, |
| 1211 | GFP_KERNEL); |
| 1212 | if (response) { |
| 1213 | DPRINTK("%s - Error %d submitting interrupt urb", |
| 1214 | __FUNCTION__, response); |
| 1215 | } |
| 1216 | // else |
| 1217 | // printk(" interrupt URB submitted\n"); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1218 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1219 | //} |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1220 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1221 | } |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1222 | //#endif |
| 1223 | |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1224 | /////////////////////// |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1225 | /* see if we've set up our endpoint info yet * |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1226 | * (can't set it up in ATEN2011_startup as the * |
| 1227 | * structures were not set up at that time.) */ |
| 1228 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1229 | DPRINTK("port number is %d \n", port->number); |
| 1230 | DPRINTK("serial number is %d \n", port->serial->minor); |
| 1231 | DPRINTK("Bulkin endpoint is %d \n", port->bulk_in_endpointAddress); |
| 1232 | DPRINTK("BulkOut endpoint is %d \n", port->bulk_out_endpointAddress); |
| 1233 | DPRINTK("Interrupt endpoint is %d \n", |
| 1234 | port->interrupt_in_endpointAddress); |
| 1235 | DPRINTK("port's number in the device is %d\n", ATEN2011_port->port_num); |
| 1236 | ATEN2011_port->bulk_in_buffer = port->bulk_in_buffer; |
| 1237 | ATEN2011_port->bulk_in_endpoint = port->bulk_in_endpointAddress; |
| 1238 | ATEN2011_port->read_urb = port->read_urb; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1239 | ATEN2011_port->bulk_out_endpoint = port->bulk_out_endpointAddress; |
| 1240 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1241 | minor = port->serial->minor; |
| 1242 | if (minor == SERIAL_TTY_NO_MINOR) |
| 1243 | minor = 0; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1244 | |
| 1245 | /* set up our bulk in urb */ |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1246 | if ((ATEN2011_serial->ATEN2011_spectrum_2or4ports == 2) |
| 1247 | && (((__u16) port->number - (__u16) (minor)) != 0)) { |
| 1248 | usb_fill_bulk_urb(ATEN2011_port->read_urb, serial->dev, |
| 1249 | usb_rcvbulkpipe(serial->dev, |
| 1250 | (port-> |
| 1251 | bulk_in_endpointAddress + |
| 1252 | 2)), port->bulk_in_buffer, |
| 1253 | ATEN2011_port->read_urb-> |
| 1254 | transfer_buffer_length, |
| 1255 | ATEN2011_bulk_in_callback, ATEN2011_port); |
| 1256 | } else |
| 1257 | usb_fill_bulk_urb(ATEN2011_port->read_urb, |
| 1258 | serial->dev, |
| 1259 | usb_rcvbulkpipe(serial->dev, |
| 1260 | port-> |
| 1261 | bulk_in_endpointAddress), |
| 1262 | port->bulk_in_buffer, |
| 1263 | ATEN2011_port->read_urb-> |
| 1264 | transfer_buffer_length, |
| 1265 | ATEN2011_bulk_in_callback, ATEN2011_port); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1266 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1267 | DPRINTK("ATEN2011_open: bulkin endpoint is %d\n", |
| 1268 | port->bulk_in_endpointAddress); |
| 1269 | response = usb_submit_urb(ATEN2011_port->read_urb, GFP_KERNEL); |
| 1270 | if (response) { |
| 1271 | err("%s - Error %d submitting control urb", __FUNCTION__, |
| 1272 | response); |
| 1273 | } |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1274 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1275 | /* initialize our wait queues */ |
| 1276 | init_waitqueue_head(&ATEN2011_port->wait_open); |
| 1277 | init_waitqueue_head(&ATEN2011_port->wait_chase); |
| 1278 | init_waitqueue_head(&ATEN2011_port->delta_msr_wait); |
| 1279 | init_waitqueue_head(&ATEN2011_port->wait_command); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1280 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1281 | /* initialize our icount structure */ |
| 1282 | memset(&(ATEN2011_port->icount), 0x00, sizeof(ATEN2011_port->icount)); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1283 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1284 | /* initialize our port settings */ |
| 1285 | ATEN2011_port->shadowMCR = MCR_MASTER_IE; /* Must set to enable ints! */ |
Greg Kroah-Hartman | a636409 | 2009-01-29 16:57:23 -0800 | [diff] [blame^] | 1286 | ATEN2011_port->chaseResponsePending = 0; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1287 | /* send a open port command */ |
Greg Kroah-Hartman | a636409 | 2009-01-29 16:57:23 -0800 | [diff] [blame^] | 1288 | ATEN2011_port->openPending = 0; |
| 1289 | ATEN2011_port->open = 1; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1290 | //ATEN2011_change_port_settings(ATEN2011_port,old_termios); |
| 1291 | /* Setup termios */ |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1292 | ATEN2011_set_termios(tty, port, &tmp_termios); |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1293 | ATEN2011_port->rxBytesAvail = 0x0; |
| 1294 | ATEN2011_port->icount.tx = 0; |
| 1295 | ATEN2011_port->icount.rx = 0; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1296 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1297 | DPRINTK |
| 1298 | ("\n\nusb_serial serial:%x ATEN2011_port:%x\nATEN2011_serial:%x usb_serial_port port:%x\n\n", |
| 1299 | (unsigned int)serial, (unsigned int)ATEN2011_port, |
| 1300 | (unsigned int)ATEN2011_serial, (unsigned int)port); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1301 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1302 | return 0; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1303 | |
| 1304 | } |
| 1305 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1306 | static void ATEN2011_close(struct tty_struct *tty, struct usb_serial_port *port, |
| 1307 | struct file *filp) |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1308 | { |
| 1309 | struct usb_serial *serial; |
| 1310 | struct ATENINTL_serial *ATEN2011_serial; |
| 1311 | struct ATENINTL_port *ATEN2011_port; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1312 | int no_urbs; |
| 1313 | __u16 Data; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1314 | //__u16 Data1= 20; |
| 1315 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1316 | DPRINTK("%s\n", "ATEN2011_close:entering..."); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1317 | /* MATRIX */ |
| 1318 | //ThreadState = 1; |
| 1319 | /* MATRIX */ |
| 1320 | //printk("Entering... :ATEN2011_close\n"); |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1321 | if (ATEN2011_port_paranoia_check(port, __FUNCTION__)) { |
| 1322 | DPRINTK("%s", "Port Paranoia failed \n"); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1323 | return; |
| 1324 | } |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1325 | serial = ATEN2011_get_usb_serial(port, __FUNCTION__); |
| 1326 | if (!serial) { |
| 1327 | DPRINTK("%s", "Serial Paranoia failed \n"); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1328 | return; |
| 1329 | } |
| 1330 | // take the Adpater and port's private data |
| 1331 | ATEN2011_serial = ATEN2011_get_serial_private(serial); |
| 1332 | ATEN2011_port = ATEN2011_get_port_private(port); |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1333 | if ((ATEN2011_serial == NULL) || (ATEN2011_port == NULL)) { |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1334 | return; |
| 1335 | } |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1336 | if (serial->dev) { |
| 1337 | /* flush and block(wait) until tx is empty */ |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1338 | ATEN2011_block_until_tx_empty(tty, ATEN2011_port); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1339 | } |
| 1340 | // kill the ports URB's |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1341 | for (no_urbs = 0; no_urbs < NUM_URBS; no_urbs++) |
| 1342 | usb_kill_urb(ATEN2011_port->write_urb_pool[no_urbs]); |
| 1343 | /* Freeing Write URBs */ |
| 1344 | for (no_urbs = 0; no_urbs < NUM_URBS; ++no_urbs) { |
| 1345 | if (ATEN2011_port->write_urb_pool[no_urbs]) { |
| 1346 | if (ATEN2011_port->write_urb_pool[no_urbs]-> |
| 1347 | transfer_buffer) |
| 1348 | kfree(ATEN2011_port->write_urb_pool[no_urbs]-> |
| 1349 | transfer_buffer); |
| 1350 | usb_free_urb(ATEN2011_port->write_urb_pool[no_urbs]); |
| 1351 | } |
| 1352 | } |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1353 | /* While closing port, shutdown all bulk read, write * |
| 1354 | * and interrupt read if they exists */ |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1355 | if (serial->dev) { |
| 1356 | if (ATEN2011_port->write_urb) { |
| 1357 | DPRINTK("%s", "Shutdown bulk write\n"); |
| 1358 | usb_kill_urb(ATEN2011_port->write_urb); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1359 | } |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1360 | if (ATEN2011_port->read_urb) { |
| 1361 | DPRINTK("%s", "Shutdown bulk read\n"); |
| 1362 | usb_kill_urb(ATEN2011_port->read_urb); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1363 | } |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1364 | if ((&ATEN2011_port->control_urb)) { |
| 1365 | DPRINTK("%s", "Shutdown control read\n"); |
| 1366 | // usb_kill_urb (ATEN2011_port->control_urb); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1367 | |
| 1368 | } |
| 1369 | } |
| 1370 | //if(ATEN2011_port->ctrl_buf != NULL) |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1371 | //kfree(ATEN2011_port->ctrl_buf); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1372 | // decrement the no.of open ports counter of an individual USB-serial adapter. |
| 1373 | ATEN2011_serial->NoOfOpenPorts--; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1374 | DPRINTK("NoOfOpenPorts in close%d:in port%d\n", |
| 1375 | ATEN2011_serial->NoOfOpenPorts, port->number); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1376 | //printk("the num of ports opend is:%d\n",ATEN2011_serial->NoOfOpenPorts); |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1377 | if (ATEN2011_serial->NoOfOpenPorts == 0) { |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1378 | //stop the stus polling here |
Greg Kroah-Hartman | a636409 | 2009-01-29 16:57:23 -0800 | [diff] [blame^] | 1379 | //printk("disabling the status polling flag to 0 :\n"); |
| 1380 | ATEN2011_serial->status_polling_started = 0; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1381 | if (ATEN2011_serial->interrupt_read_urb) { |
| 1382 | DPRINTK("%s", "Shutdown interrupt_read_urb\n"); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1383 | //ATEN2011_serial->interrupt_in_buffer=NULL; |
| 1384 | //usb_kill_urb (ATEN2011_serial->interrupt_read_urb); |
| 1385 | } |
| 1386 | } |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1387 | if (ATEN2011_port->write_urb) { |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1388 | /* if this urb had a transfer buffer already (old tx) free it */ |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1389 | if (ATEN2011_port->write_urb->transfer_buffer != NULL) { |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1390 | kfree(ATEN2011_port->write_urb->transfer_buffer); |
| 1391 | } |
| 1392 | usb_free_urb(ATEN2011_port->write_urb); |
| 1393 | } |
| 1394 | // clear the MCR & IER |
| 1395 | Data = 0x00; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1396 | ATEN2011_set_Uart_Reg(port, MODEM_CONTROL_REGISTER, Data); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1397 | Data = 0x00; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1398 | ATEN2011_set_Uart_Reg(port, INTERRUPT_ENABLE_REGISTER, Data); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1399 | |
| 1400 | //ATEN2011_get_Uart_Reg(port,MODEM_CONTROL_REGISTER,&Data1); |
| 1401 | //printk("value of MCR after closing the port is : 0x%x\n",Data1); |
| 1402 | |
Greg Kroah-Hartman | a636409 | 2009-01-29 16:57:23 -0800 | [diff] [blame^] | 1403 | ATEN2011_port->open = 0; |
| 1404 | ATEN2011_port->closePending = 0; |
| 1405 | ATEN2011_port->openPending = 0; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1406 | DPRINTK("%s \n", "Leaving ............"); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1407 | |
| 1408 | } |
| 1409 | |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1410 | static void ATEN2011_break(struct tty_struct *tty, int break_state) |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1411 | { |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1412 | struct usb_serial_port *port = tty->driver_data; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1413 | unsigned char data; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1414 | struct usb_serial *serial; |
| 1415 | struct ATENINTL_serial *ATEN2011_serial; |
| 1416 | struct ATENINTL_port *ATEN2011_port; |
| 1417 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1418 | DPRINTK("%s \n", "Entering ..........."); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1419 | DPRINTK("ATEN2011_break: Start\n"); |
| 1420 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1421 | if (ATEN2011_port_paranoia_check(port, __FUNCTION__)) { |
| 1422 | DPRINTK("%s", "Port Paranoia failed \n"); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1423 | return; |
| 1424 | } |
| 1425 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1426 | serial = ATEN2011_get_usb_serial(port, __FUNCTION__); |
| 1427 | if (!serial) { |
| 1428 | DPRINTK("%s", "Serial Paranoia failed \n"); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1429 | return; |
| 1430 | } |
| 1431 | |
| 1432 | ATEN2011_serial = ATEN2011_get_serial_private(serial); |
| 1433 | ATEN2011_port = ATEN2011_get_port_private(port); |
| 1434 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1435 | if ((ATEN2011_serial == NULL) || (ATEN2011_port == NULL)) { |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1436 | return; |
| 1437 | } |
| 1438 | |
| 1439 | /* flush and chase */ |
Greg Kroah-Hartman | a636409 | 2009-01-29 16:57:23 -0800 | [diff] [blame^] | 1440 | ATEN2011_port->chaseResponsePending = 1; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1441 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1442 | if (serial->dev) { |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1443 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1444 | /* flush and block until tx is empty */ |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1445 | ATEN2011_block_until_chase_response(tty, ATEN2011_port); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1446 | } |
| 1447 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1448 | if (break_state == -1) { |
| 1449 | data = ATEN2011_port->shadowLCR | LCR_SET_BREAK; |
| 1450 | } else { |
| 1451 | data = ATEN2011_port->shadowLCR & ~LCR_SET_BREAK; |
| 1452 | } |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1453 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1454 | ATEN2011_port->shadowLCR = data; |
| 1455 | DPRINTK("ATEN2011_break ATEN2011_port->shadowLCR is %x\n", |
| 1456 | ATEN2011_port->shadowLCR); |
| 1457 | ATEN2011_set_Uart_Reg(port, LINE_CONTROL_REGISTER, |
| 1458 | ATEN2011_port->shadowLCR); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1459 | |
| 1460 | return; |
| 1461 | } |
| 1462 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1463 | static void ATEN2011_block_until_chase_response(struct tty_struct *tty, |
| 1464 | struct ATENINTL_port |
| 1465 | *ATEN2011_port) |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1466 | { |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1467 | int timeout = 1 * HZ; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1468 | int wait = 10; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1469 | int count; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1470 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1471 | while (1) { |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1472 | count = ATEN2011_chars_in_buffer(tty); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1473 | |
| 1474 | /* Check for Buffer status */ |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1475 | if (count <= 0) { |
Greg Kroah-Hartman | a636409 | 2009-01-29 16:57:23 -0800 | [diff] [blame^] | 1476 | ATEN2011_port->chaseResponsePending = 0; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1477 | return; |
| 1478 | } |
| 1479 | |
| 1480 | /* Block the thread for a while */ |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1481 | interruptible_sleep_on_timeout(&ATEN2011_port->wait_chase, |
| 1482 | timeout); |
| 1483 | /* No activity.. count down section */ |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1484 | wait--; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1485 | if (wait == 0) { |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1486 | dbg("%s - TIMEOUT", __FUNCTION__); |
| 1487 | return; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1488 | } else { |
| 1489 | /* Reset timout value back to seconds */ |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1490 | wait = 10; |
| 1491 | } |
| 1492 | } |
| 1493 | |
| 1494 | } |
| 1495 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1496 | static void ATEN2011_block_until_tx_empty(struct tty_struct *tty, |
| 1497 | struct ATENINTL_port *ATEN2011_port) |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1498 | { |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1499 | int timeout = HZ / 10; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1500 | int wait = 30; |
| 1501 | int count; |
| 1502 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1503 | while (1) { |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1504 | |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1505 | count = ATEN2011_chars_in_buffer(tty); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1506 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1507 | /* Check for Buffer status */ |
| 1508 | if (count <= 0) { |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1509 | return; |
| 1510 | } |
| 1511 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1512 | /* Block the thread for a while */ |
| 1513 | interruptible_sleep_on_timeout(&ATEN2011_port->wait_chase, |
| 1514 | timeout); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1515 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1516 | /* No activity.. count down section */ |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1517 | wait--; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1518 | if (wait == 0) { |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1519 | dbg("%s - TIMEOUT", __FUNCTION__); |
| 1520 | return; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1521 | } else { |
| 1522 | /* Reset timout value back to seconds */ |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1523 | wait = 30; |
| 1524 | } |
| 1525 | } |
| 1526 | } |
| 1527 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1528 | static int ATEN2011_write_room(struct tty_struct *tty) |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1529 | { |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1530 | struct usb_serial_port *port = tty->driver_data; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1531 | int i; |
| 1532 | int room = 0; |
| 1533 | struct ATENINTL_port *ATEN2011_port; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1534 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1535 | // DPRINTK("%s \n"," ATEN2011_write_room:entering ..........."); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1536 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1537 | if (ATEN2011_port_paranoia_check(port, __FUNCTION__)) { |
| 1538 | DPRINTK("%s", "Invalid port \n"); |
| 1539 | DPRINTK("%s \n", " ATEN2011_write_room:leaving ..........."); |
| 1540 | return -1; |
| 1541 | } |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1542 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1543 | ATEN2011_port = ATEN2011_get_port_private(port); |
| 1544 | if (ATEN2011_port == NULL) { |
| 1545 | DPRINTK("%s \n", "ATEN2011_break:leaving ..........."); |
| 1546 | return -1; |
| 1547 | } |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1548 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1549 | for (i = 0; i < NUM_URBS; ++i) { |
| 1550 | if (ATEN2011_port->write_urb_pool[i]->status != -EINPROGRESS) { |
| 1551 | room += URB_TRANSFER_BUFFER_SIZE; |
| 1552 | } |
| 1553 | } |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1554 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1555 | dbg("%s - returns %d", __FUNCTION__, room); |
| 1556 | return (room); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1557 | |
| 1558 | } |
| 1559 | |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1560 | static int ATEN2011_chars_in_buffer(struct tty_struct *tty) |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1561 | { |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1562 | struct usb_serial_port *port = tty->driver_data; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1563 | int i; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1564 | int chars = 0; |
| 1565 | struct ATENINTL_port *ATEN2011_port; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1566 | |
| 1567 | //DPRINTK("%s \n"," ATEN2011_chars_in_buffer:entering ..........."); |
| 1568 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1569 | if (ATEN2011_port_paranoia_check(port, __FUNCTION__)) { |
| 1570 | DPRINTK("%s", "Invalid port \n"); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1571 | return -1; |
| 1572 | } |
| 1573 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1574 | ATEN2011_port = ATEN2011_get_port_private(port); |
| 1575 | if (ATEN2011_port == NULL) { |
| 1576 | DPRINTK("%s \n", "ATEN2011_break:leaving ..........."); |
| 1577 | return -1; |
| 1578 | } |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1579 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1580 | for (i = 0; i < NUM_URBS; ++i) { |
| 1581 | if (ATEN2011_port->write_urb_pool[i]->status == -EINPROGRESS) { |
| 1582 | chars += URB_TRANSFER_BUFFER_SIZE; |
| 1583 | } |
| 1584 | } |
| 1585 | dbg("%s - returns %d", __FUNCTION__, chars); |
| 1586 | return (chars); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1587 | |
| 1588 | } |
| 1589 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1590 | static int ATEN2011_write(struct tty_struct *tty, struct usb_serial_port *port, |
| 1591 | const unsigned char *data, int count) |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1592 | { |
| 1593 | int status; |
| 1594 | int i; |
| 1595 | int bytes_sent = 0; |
| 1596 | int transfer_size; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1597 | int from_user = 0; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1598 | int minor; |
| 1599 | |
| 1600 | struct ATENINTL_port *ATEN2011_port; |
| 1601 | struct usb_serial *serial; |
| 1602 | struct ATENINTL_serial *ATEN2011_serial; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1603 | struct urb *urb; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1604 | //__u16 Data; |
| 1605 | const unsigned char *current_position = data; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1606 | unsigned char *data1; |
| 1607 | DPRINTK("%s \n", "entering ..........."); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1608 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1609 | if (ATEN2011_port_paranoia_check(port, __FUNCTION__)) { |
| 1610 | DPRINTK("%s", "Port Paranoia failed \n"); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1611 | return -1; |
| 1612 | } |
| 1613 | |
| 1614 | serial = port->serial; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1615 | if (ATEN2011_serial_paranoia_check(serial, __FUNCTION__)) { |
| 1616 | DPRINTK("%s", "Serial Paranoia failed \n"); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1617 | return -1; |
| 1618 | } |
| 1619 | |
| 1620 | ATEN2011_port = ATEN2011_get_port_private(port); |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1621 | if (ATEN2011_port == NULL) { |
| 1622 | DPRINTK("%s", "ATEN2011_port is NULL\n"); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1623 | return -1; |
| 1624 | } |
| 1625 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1626 | ATEN2011_serial = ATEN2011_get_serial_private(serial); |
| 1627 | if (ATEN2011_serial == NULL) { |
| 1628 | DPRINTK("%s", "ATEN2011_serial is NULL \n"); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1629 | return -1; |
| 1630 | } |
| 1631 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1632 | /* try to find a free urb in the list */ |
| 1633 | urb = NULL; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1634 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1635 | for (i = 0; i < NUM_URBS; ++i) { |
| 1636 | if (ATEN2011_port->write_urb_pool[i]->status != -EINPROGRESS) { |
| 1637 | urb = ATEN2011_port->write_urb_pool[i]; |
| 1638 | DPRINTK("\nURB:%d", i); |
| 1639 | break; |
| 1640 | } |
| 1641 | } |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1642 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1643 | if (urb == NULL) { |
| 1644 | dbg("%s - no more free urbs", __FUNCTION__); |
| 1645 | goto exit; |
| 1646 | } |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1647 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1648 | if (urb->transfer_buffer == NULL) { |
| 1649 | urb->transfer_buffer = |
| 1650 | kmalloc(URB_TRANSFER_BUFFER_SIZE, GFP_KERNEL); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1651 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1652 | if (urb->transfer_buffer == NULL) { |
| 1653 | err("%s no more kernel memory...", __FUNCTION__); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1654 | goto exit; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1655 | } |
| 1656 | } |
| 1657 | transfer_size = min(count, URB_TRANSFER_BUFFER_SIZE); |
| 1658 | |
| 1659 | if (from_user) { |
| 1660 | if (copy_from_user |
| 1661 | (urb->transfer_buffer, current_position, transfer_size)) { |
| 1662 | bytes_sent = -EFAULT; |
| 1663 | goto exit; |
| 1664 | } |
| 1665 | } else { |
| 1666 | memcpy(urb->transfer_buffer, current_position, transfer_size); |
| 1667 | } |
| 1668 | //usb_serial_debug_data (__FILE__, __FUNCTION__, transfer_size, urb->transfer_buffer); |
| 1669 | |
| 1670 | /* fill urb with data and submit */ |
| 1671 | minor = port->serial->minor; |
| 1672 | if (minor == SERIAL_TTY_NO_MINOR) ; |
| 1673 | minor = 0; |
| 1674 | if ((ATEN2011_serial->ATEN2011_spectrum_2or4ports == 2) |
| 1675 | && (((__u16) port->number - (__u16) (minor)) != 0)) { |
| 1676 | usb_fill_bulk_urb(urb, ATEN2011_serial->serial->dev, |
| 1677 | usb_sndbulkpipe(ATEN2011_serial->serial->dev, |
| 1678 | (port-> |
| 1679 | bulk_out_endpointAddress) + |
| 1680 | 2), urb->transfer_buffer, |
| 1681 | transfer_size, |
| 1682 | ATEN2011_bulk_out_data_callback, |
| 1683 | ATEN2011_port); |
| 1684 | } else |
| 1685 | |
| 1686 | usb_fill_bulk_urb(urb, |
| 1687 | ATEN2011_serial->serial->dev, |
| 1688 | usb_sndbulkpipe(ATEN2011_serial->serial->dev, |
| 1689 | port-> |
| 1690 | bulk_out_endpointAddress), |
| 1691 | urb->transfer_buffer, transfer_size, |
| 1692 | ATEN2011_bulk_out_data_callback, |
| 1693 | ATEN2011_port); |
| 1694 | |
| 1695 | data1 = urb->transfer_buffer; |
| 1696 | DPRINTK("\nbulkout endpoint is %d", port->bulk_out_endpointAddress); |
| 1697 | //for(i=0;i < urb->actual_length;i++) |
| 1698 | // DPRINTK("Data is %c\n ",data1[i]); |
| 1699 | |
| 1700 | /* send it down the pipe */ |
| 1701 | status = usb_submit_urb(urb, GFP_ATOMIC); |
| 1702 | |
| 1703 | if (status) { |
| 1704 | err("%s - usb_submit_urb(write bulk) failed with status = %d", |
| 1705 | __FUNCTION__, status); |
| 1706 | bytes_sent = status; |
| 1707 | goto exit; |
| 1708 | } |
| 1709 | bytes_sent = transfer_size; |
| 1710 | ATEN2011_port->icount.tx += transfer_size; |
| 1711 | DPRINTK("ATEN2011_port->icount.tx is %d:\n", ATEN2011_port->icount.tx); |
| 1712 | exit: |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1713 | |
| 1714 | return bytes_sent; |
| 1715 | |
| 1716 | } |
| 1717 | |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1718 | static void ATEN2011_throttle(struct tty_struct *tty) |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1719 | { |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1720 | struct usb_serial_port *port = tty->driver_data; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1721 | struct ATENINTL_port *ATEN2011_port; |
| 1722 | int status; |
| 1723 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1724 | if (ATEN2011_port_paranoia_check(port, __FUNCTION__)) { |
| 1725 | DPRINTK("%s", "Invalid port \n"); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1726 | return; |
| 1727 | } |
| 1728 | |
| 1729 | DPRINTK("- port %d\n", port->number); |
| 1730 | |
| 1731 | ATEN2011_port = ATEN2011_get_port_private(port); |
| 1732 | |
| 1733 | if (ATEN2011_port == NULL) |
| 1734 | return; |
| 1735 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1736 | if (!ATEN2011_port->open) { |
| 1737 | DPRINTK("%s\n", "port not opened"); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1738 | return; |
| 1739 | } |
| 1740 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1741 | DPRINTK("%s", "Entering .......... \n"); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1742 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1743 | if (!tty) { |
| 1744 | dbg("%s - no tty available", __FUNCTION__); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1745 | return; |
| 1746 | } |
| 1747 | |
| 1748 | /* if we are implementing XON/XOFF, send the stop character */ |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1749 | if (I_IXOFF(tty)) { |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1750 | unsigned char stop_char = STOP_CHAR(tty); |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1751 | status = ATEN2011_write(tty, port, &stop_char, 1); //FC4 |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1752 | if (status <= 0) { |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1753 | return; |
| 1754 | } |
| 1755 | } |
| 1756 | |
| 1757 | /* if we are implementing RTS/CTS, toggle that line */ |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1758 | if (tty->termios->c_cflag & CRTSCTS) { |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1759 | ATEN2011_port->shadowMCR &= ~MCR_RTS; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1760 | status = 0; |
| 1761 | status = |
| 1762 | ATEN2011_set_Uart_Reg(port, MODEM_CONTROL_REGISTER, |
| 1763 | ATEN2011_port->shadowMCR); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1764 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1765 | if (status < 0) { |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1766 | return; |
| 1767 | } |
| 1768 | } |
| 1769 | |
| 1770 | return; |
| 1771 | } |
| 1772 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1773 | static void ATEN2011_unthrottle(struct tty_struct *tty) |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1774 | { |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1775 | struct usb_serial_port *port = tty->driver_data; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1776 | int status; |
| 1777 | struct ATENINTL_port *ATEN2011_port = ATEN2011_get_port_private(port); |
| 1778 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1779 | if (ATEN2011_port_paranoia_check(port, __FUNCTION__)) { |
| 1780 | DPRINTK("%s", "Invalid port \n"); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1781 | return; |
| 1782 | } |
| 1783 | |
| 1784 | if (ATEN2011_port == NULL) |
| 1785 | return; |
| 1786 | |
| 1787 | if (!ATEN2011_port->open) { |
| 1788 | dbg("%s - port not opened", __FUNCTION__); |
| 1789 | return; |
| 1790 | } |
| 1791 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1792 | DPRINTK("%s", "Entering .......... \n"); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1793 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1794 | if (!tty) { |
| 1795 | dbg("%s - no tty available", __FUNCTION__); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1796 | return; |
| 1797 | } |
| 1798 | |
| 1799 | /* if we are implementing XON/XOFF, send the start character */ |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1800 | if (I_IXOFF(tty)) { |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1801 | unsigned char start_char = START_CHAR(tty); |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1802 | status = ATEN2011_write(tty, port, &start_char, 1); //FC4 |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1803 | if (status <= 0) { |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1804 | return; |
| 1805 | } |
| 1806 | } |
| 1807 | |
| 1808 | /* if we are implementing RTS/CTS, toggle that line */ |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1809 | if (tty->termios->c_cflag & CRTSCTS) { |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1810 | ATEN2011_port->shadowMCR |= MCR_RTS; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1811 | status = 0; |
| 1812 | status = |
| 1813 | ATEN2011_set_Uart_Reg(port, MODEM_CONTROL_REGISTER, |
| 1814 | ATEN2011_port->shadowMCR); |
| 1815 | if (status < 0) { |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1816 | return; |
| 1817 | } |
| 1818 | } |
| 1819 | |
| 1820 | return; |
| 1821 | } |
| 1822 | |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1823 | static int ATEN2011_tiocmget(struct tty_struct *tty, struct file *file) |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1824 | { |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1825 | struct usb_serial_port *port = tty->driver_data; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1826 | //struct ti_port *tport = usb_get_serial_port_data(port); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1827 | struct ATENINTL_port *ATEN2011_port; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1828 | unsigned int result; |
| 1829 | __u16 msr; |
| 1830 | __u16 mcr; |
| 1831 | //unsigned int mcr; |
| 1832 | int status = 0; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1833 | ATEN2011_port = ATEN2011_get_port_private(port); |
| 1834 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1835 | DPRINTK("%s - port %d", __FUNCTION__, port->number); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1836 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1837 | if (ATEN2011_port == NULL) |
| 1838 | return -ENODEV; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1839 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1840 | status = ATEN2011_get_Uart_Reg(port, MODEM_STATUS_REGISTER, &msr); |
| 1841 | status = ATEN2011_get_Uart_Reg(port, MODEM_CONTROL_REGISTER, &mcr); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1842 | // mcr = ATEN2011_port->shadowMCR; |
| 1843 | // COMMENT2: the Fallowing three line are commented for updating only MSR values |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1844 | result = ((mcr & MCR_DTR) ? TIOCM_DTR : 0) |
| 1845 | | ((mcr & MCR_RTS) ? TIOCM_RTS : 0) |
| 1846 | | ((mcr & MCR_LOOPBACK) ? TIOCM_LOOP : 0) |
| 1847 | | ((msr & ATEN2011_MSR_CTS) ? TIOCM_CTS : 0) |
| 1848 | | ((msr & ATEN2011_MSR_CD) ? TIOCM_CAR : 0) |
| 1849 | | ((msr & ATEN2011_MSR_RI) ? TIOCM_RI : 0) |
| 1850 | | ((msr & ATEN2011_MSR_DSR) ? TIOCM_DSR : 0); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1851 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1852 | DPRINTK("%s - 0x%04X", __FUNCTION__, result); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1853 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1854 | return result; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1855 | } |
| 1856 | |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1857 | static int ATEN2011_tiocmset(struct tty_struct *tty, struct file *file, |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1858 | unsigned int set, unsigned int clear) |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1859 | { |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1860 | struct usb_serial_port *port = tty->driver_data; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1861 | struct ATENINTL_port *ATEN2011_port; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1862 | //struct ti_port *tport = usb_get_serial_port_data(port); |
| 1863 | unsigned int mcr; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1864 | unsigned int status; |
| 1865 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1866 | DPRINTK("%s - port %d", __FUNCTION__, port->number); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1867 | |
| 1868 | ATEN2011_port = ATEN2011_get_port_private(port); |
| 1869 | |
| 1870 | if (ATEN2011_port == NULL) |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1871 | return -ENODEV; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1872 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1873 | mcr = ATEN2011_port->shadowMCR; |
| 1874 | if (clear & TIOCM_RTS) |
| 1875 | mcr &= ~MCR_RTS; |
| 1876 | if (clear & TIOCM_DTR) |
| 1877 | mcr &= ~MCR_DTR; |
| 1878 | if (clear & TIOCM_LOOP) |
| 1879 | mcr &= ~MCR_LOOPBACK; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1880 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1881 | if (set & TIOCM_RTS) |
| 1882 | mcr |= MCR_RTS; |
| 1883 | if (set & TIOCM_DTR) |
| 1884 | mcr |= MCR_DTR; |
| 1885 | if (set & TIOCM_LOOP) |
| 1886 | mcr |= MCR_LOOPBACK; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1887 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1888 | ATEN2011_port->shadowMCR = mcr; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1889 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1890 | status = 0; |
| 1891 | status = ATEN2011_set_Uart_Reg(port, MODEM_CONTROL_REGISTER, mcr); |
| 1892 | if (status < 0) { |
| 1893 | DPRINTK("setting MODEM_CONTROL_REGISTER Failed\n"); |
| 1894 | return -1; |
| 1895 | } |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1896 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1897 | return 0; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1898 | } |
| 1899 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1900 | static void ATEN2011_set_termios(struct tty_struct *tty, |
| 1901 | struct usb_serial_port *port, |
| 1902 | struct ktermios *old_termios) |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1903 | { |
| 1904 | int status; |
| 1905 | unsigned int cflag; |
| 1906 | struct usb_serial *serial; |
| 1907 | struct ATENINTL_port *ATEN2011_port; |
Greg Kroah-Hartman | 8b4efbe | 2009-01-29 13:08:23 -0800 | [diff] [blame] | 1908 | |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1909 | DPRINTK("ATEN2011_set_termios: START\n"); |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1910 | if (ATEN2011_port_paranoia_check(port, __FUNCTION__)) { |
| 1911 | DPRINTK("%s", "Invalid port \n"); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1912 | return; |
| 1913 | } |
| 1914 | |
| 1915 | serial = port->serial; |
| 1916 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1917 | if (ATEN2011_serial_paranoia_check(serial, __FUNCTION__)) { |
| 1918 | DPRINTK("%s", "Invalid Serial \n"); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1919 | return; |
| 1920 | } |
| 1921 | |
| 1922 | ATEN2011_port = ATEN2011_get_port_private(port); |
| 1923 | |
| 1924 | if (ATEN2011_port == NULL) |
| 1925 | return; |
| 1926 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1927 | if (!ATEN2011_port->open) { |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1928 | dbg("%s - port not opened", __FUNCTION__); |
| 1929 | return; |
| 1930 | } |
| 1931 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1932 | DPRINTK("%s\n", "setting termios - "); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1933 | |
| 1934 | cflag = tty->termios->c_cflag; |
| 1935 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1936 | if (!cflag) { |
| 1937 | DPRINTK("%s %s\n", __FUNCTION__, "cflag is NULL"); |
| 1938 | return; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1939 | } |
| 1940 | |
| 1941 | /* check that they really want us to change something */ |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1942 | if (old_termios) { |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1943 | if ((cflag == old_termios->c_cflag) && |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1944 | (RELEVANT_IFLAG(tty->termios->c_iflag) == |
| 1945 | RELEVANT_IFLAG(old_termios->c_iflag))) { |
| 1946 | DPRINTK("%s\n", "Nothing to change"); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1947 | return; |
| 1948 | } |
| 1949 | } |
| 1950 | |
| 1951 | dbg("%s - clfag %08x iflag %08x", __FUNCTION__, |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1952 | tty->termios->c_cflag, RELEVANT_IFLAG(tty->termios->c_iflag)); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1953 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1954 | if (old_termios) { |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1955 | dbg("%s - old clfag %08x old iflag %08x", __FUNCTION__, |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1956 | old_termios->c_cflag, RELEVANT_IFLAG(old_termios->c_iflag)); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1957 | } |
| 1958 | |
| 1959 | dbg("%s - port %d", __FUNCTION__, port->number); |
| 1960 | |
| 1961 | /* change the port settings to the new ones specified */ |
| 1962 | |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1963 | ATEN2011_change_port_settings(tty, ATEN2011_port, old_termios); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1964 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1965 | if (!ATEN2011_port->read_urb) { |
| 1966 | DPRINTK("%s", "URB KILLED !!!!!\n"); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1967 | return; |
| 1968 | } |
| 1969 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1970 | if (ATEN2011_port->read_urb->status != -EINPROGRESS) { |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1971 | ATEN2011_port->read_urb->dev = serial->dev; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1972 | status = usb_submit_urb(ATEN2011_port->read_urb, GFP_ATOMIC); |
| 1973 | if (status) { |
| 1974 | DPRINTK |
| 1975 | (" usb_submit_urb(read bulk) failed, status = %d", |
| 1976 | status); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1977 | } |
| 1978 | } |
| 1979 | return; |
| 1980 | } |
| 1981 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1982 | static int get_lsr_info(struct tty_struct *tty, |
| 1983 | struct ATENINTL_port *ATEN2011_port, |
| 1984 | unsigned int *value) |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1985 | { |
| 1986 | int count; |
| 1987 | unsigned int result = 0; |
| 1988 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1989 | count = ATEN2011_chars_in_buffer(tty); |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 1990 | if (count == 0) { |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 1991 | dbg("%s -- Empty", __FUNCTION__); |
| 1992 | result = TIOCSER_TEMT; |
| 1993 | } |
| 1994 | |
| 1995 | if (copy_to_user(value, &result, sizeof(int))) |
| 1996 | return -EFAULT; |
| 1997 | return 0; |
| 1998 | } |
| 1999 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2000 | static int get_number_bytes_avail(struct tty_struct *tty, |
| 2001 | struct ATENINTL_port *ATEN2011_port, |
| 2002 | unsigned int *value) |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2003 | { |
| 2004 | unsigned int result = 0; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2005 | |
| 2006 | if (!tty) |
| 2007 | return -ENOIOCTLCMD; |
| 2008 | |
| 2009 | result = tty->read_cnt; |
| 2010 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2011 | dbg("%s(%d) = %d", __FUNCTION__, ATEN2011_port->port->number, result); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2012 | if (copy_to_user(value, &result, sizeof(int))) |
| 2013 | return -EFAULT; |
| 2014 | |
| 2015 | return -ENOIOCTLCMD; |
| 2016 | } |
| 2017 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2018 | static int set_modem_info(struct ATENINTL_port *ATEN2011_port, unsigned int cmd, |
| 2019 | unsigned int *value) |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2020 | { |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2021 | unsigned int mcr; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2022 | unsigned int arg; |
| 2023 | __u16 Data; |
| 2024 | int status; |
| 2025 | struct usb_serial_port *port; |
| 2026 | |
| 2027 | if (ATEN2011_port == NULL) |
| 2028 | return -1; |
| 2029 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2030 | port = (struct usb_serial_port *)ATEN2011_port->port; |
| 2031 | if (ATEN2011_port_paranoia_check(port, __FUNCTION__)) { |
| 2032 | DPRINTK("%s", "Invalid port \n"); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2033 | return -1; |
| 2034 | } |
| 2035 | |
| 2036 | mcr = ATEN2011_port->shadowMCR; |
| 2037 | |
| 2038 | if (copy_from_user(&arg, value, sizeof(int))) |
| 2039 | return -EFAULT; |
| 2040 | |
| 2041 | switch (cmd) { |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2042 | case TIOCMBIS: |
| 2043 | if (arg & TIOCM_RTS) |
| 2044 | mcr |= MCR_RTS; |
| 2045 | if (arg & TIOCM_DTR) |
| 2046 | mcr |= MCR_RTS; |
| 2047 | if (arg & TIOCM_LOOP) |
| 2048 | mcr |= MCR_LOOPBACK; |
| 2049 | break; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2050 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2051 | case TIOCMBIC: |
| 2052 | if (arg & TIOCM_RTS) |
| 2053 | mcr &= ~MCR_RTS; |
| 2054 | if (arg & TIOCM_DTR) |
| 2055 | mcr &= ~MCR_RTS; |
| 2056 | if (arg & TIOCM_LOOP) |
| 2057 | mcr &= ~MCR_LOOPBACK; |
| 2058 | break; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2059 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2060 | case TIOCMSET: |
| 2061 | /* turn off the RTS and DTR and LOOPBACK |
| 2062 | * and then only turn on what was asked to */ |
| 2063 | mcr &= ~(MCR_RTS | MCR_DTR | MCR_LOOPBACK); |
| 2064 | mcr |= ((arg & TIOCM_RTS) ? MCR_RTS : 0); |
| 2065 | mcr |= ((arg & TIOCM_DTR) ? MCR_DTR : 0); |
| 2066 | mcr |= ((arg & TIOCM_LOOP) ? MCR_LOOPBACK : 0); |
| 2067 | break; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2068 | } |
| 2069 | |
| 2070 | ATEN2011_port->shadowMCR = mcr; |
| 2071 | |
| 2072 | Data = ATEN2011_port->shadowMCR; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2073 | status = 0; |
| 2074 | status = ATEN2011_set_Uart_Reg(port, MODEM_CONTROL_REGISTER, Data); |
| 2075 | if (status < 0) { |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2076 | DPRINTK("setting MODEM_CONTROL_REGISTER Failed\n"); |
| 2077 | return -1; |
| 2078 | } |
| 2079 | |
| 2080 | return 0; |
| 2081 | } |
| 2082 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2083 | static int get_modem_info(struct ATENINTL_port *ATEN2011_port, |
| 2084 | unsigned int *value) |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2085 | { |
| 2086 | unsigned int result = 0; |
| 2087 | __u16 msr; |
| 2088 | unsigned int mcr = ATEN2011_port->shadowMCR; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2089 | int status = 0; |
| 2090 | status = |
| 2091 | ATEN2011_get_Uart_Reg(ATEN2011_port->port, MODEM_STATUS_REGISTER, |
| 2092 | &msr); |
| 2093 | result = ((mcr & MCR_DTR) ? TIOCM_DTR : 0) /* 0x002 */ |
| 2094 | |((mcr & MCR_RTS) ? TIOCM_RTS : 0) /* 0x004 */ |
| 2095 | |((msr & ATEN2011_MSR_CTS) ? TIOCM_CTS : 0) /* 0x020 */ |
| 2096 | |((msr & ATEN2011_MSR_CD) ? TIOCM_CAR : 0) /* 0x040 */ |
| 2097 | |((msr & ATEN2011_MSR_RI) ? TIOCM_RI : 0) /* 0x080 */ |
| 2098 | |((msr & ATEN2011_MSR_DSR) ? TIOCM_DSR : 0); /* 0x100 */ |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2099 | |
| 2100 | dbg("%s -- %x", __FUNCTION__, result); |
| 2101 | |
| 2102 | if (copy_to_user(value, &result, sizeof(int))) |
| 2103 | return -EFAULT; |
| 2104 | return 0; |
| 2105 | } |
| 2106 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2107 | static int get_serial_info(struct ATENINTL_port *ATEN2011_port, |
| 2108 | struct serial_struct *retinfo) |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2109 | { |
| 2110 | struct serial_struct tmp; |
| 2111 | |
| 2112 | if (ATEN2011_port == NULL) |
| 2113 | return -1; |
| 2114 | |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2115 | if (!retinfo) |
| 2116 | return -EFAULT; |
| 2117 | |
| 2118 | memset(&tmp, 0, sizeof(tmp)); |
| 2119 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2120 | tmp.type = PORT_16550A; |
| 2121 | tmp.line = ATEN2011_port->port->serial->minor; |
| 2122 | if (tmp.line == SERIAL_TTY_NO_MINOR) |
| 2123 | tmp.line = 0; |
| 2124 | tmp.port = ATEN2011_port->port->number; |
| 2125 | tmp.irq = 0; |
| 2126 | tmp.flags = ASYNC_SKIP_TEST | ASYNC_AUTO_IRQ; |
| 2127 | tmp.xmit_fifo_size = NUM_URBS * URB_TRANSFER_BUFFER_SIZE; |
| 2128 | tmp.baud_base = 9600; |
| 2129 | tmp.close_delay = 5 * HZ; |
| 2130 | tmp.closing_wait = 30 * HZ; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2131 | |
| 2132 | if (copy_to_user(retinfo, &tmp, sizeof(*retinfo))) |
| 2133 | return -EFAULT; |
| 2134 | return 0; |
| 2135 | } |
| 2136 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2137 | static int ATEN2011_ioctl(struct tty_struct *tty, struct file *file, |
| 2138 | unsigned int cmd, unsigned long arg) |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2139 | { |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2140 | struct usb_serial_port *port = tty->driver_data; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2141 | struct ATENINTL_port *ATEN2011_port; |
| 2142 | struct async_icount cnow; |
| 2143 | struct async_icount cprev; |
| 2144 | struct serial_icounter_struct icount; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2145 | int ATENret = 0; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2146 | //int retval; |
| 2147 | //struct tty_ldisc *ld; |
| 2148 | |
| 2149 | //printk("%s - port %d, cmd = 0x%x\n", __FUNCTION__, port->number, cmd); |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2150 | if (ATEN2011_port_paranoia_check(port, __FUNCTION__)) { |
| 2151 | DPRINTK("%s", "Invalid port \n"); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2152 | return -1; |
| 2153 | } |
| 2154 | |
| 2155 | ATEN2011_port = ATEN2011_get_port_private(port); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2156 | |
| 2157 | if (ATEN2011_port == NULL) |
| 2158 | return -1; |
| 2159 | |
| 2160 | dbg("%s - port %d, cmd = 0x%x", __FUNCTION__, port->number, cmd); |
| 2161 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2162 | switch (cmd) { |
| 2163 | /* return number of bytes available */ |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2164 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2165 | case TIOCINQ: |
| 2166 | dbg("%s (%d) TIOCINQ", __FUNCTION__, port->number); |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2167 | return get_number_bytes_avail(tty, ATEN2011_port, |
| 2168 | (unsigned int *)arg); |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2169 | break; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2170 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2171 | case TIOCOUTQ: |
| 2172 | dbg("%s (%d) TIOCOUTQ", __FUNCTION__, port->number); |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2173 | return put_user(ATEN2011_chars_in_buffer(tty), |
| 2174 | (int __user *)arg); |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2175 | break; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2176 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2177 | case TIOCSERGETLSR: |
| 2178 | dbg("%s (%d) TIOCSERGETLSR", __FUNCTION__, port->number); |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2179 | return get_lsr_info(tty, ATEN2011_port, (unsigned int *)arg); |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2180 | return 0; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2181 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2182 | case TIOCMBIS: |
| 2183 | case TIOCMBIC: |
| 2184 | case TIOCMSET: |
| 2185 | dbg("%s (%d) TIOCMSET/TIOCMBIC/TIOCMSET", __FUNCTION__, |
| 2186 | port->number); |
| 2187 | // printk("%s (%d) TIOCMSET/TIOCMBIC/TIOCMSET", __FUNCTION__, port->number); |
| 2188 | ATENret = |
| 2189 | set_modem_info(ATEN2011_port, cmd, (unsigned int *)arg); |
| 2190 | // printk(" %s: ret:%d\n",__FUNCTION__,ATENret); |
| 2191 | return ATENret; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2192 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2193 | case TIOCMGET: |
| 2194 | dbg("%s (%d) TIOCMGET", __FUNCTION__, port->number); |
| 2195 | return get_modem_info(ATEN2011_port, (unsigned int *)arg); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2196 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2197 | case TIOCGSERIAL: |
| 2198 | dbg("%s (%d) TIOCGSERIAL", __FUNCTION__, port->number); |
| 2199 | return get_serial_info(ATEN2011_port, |
| 2200 | (struct serial_struct *)arg); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2201 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2202 | case TIOCSSERIAL: |
| 2203 | dbg("%s (%d) TIOCSSERIAL", __FUNCTION__, port->number); |
| 2204 | break; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2205 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2206 | case TIOCMIWAIT: |
| 2207 | dbg("%s (%d) TIOCMIWAIT", __FUNCTION__, port->number); |
| 2208 | cprev = ATEN2011_port->icount; |
| 2209 | while (1) { |
| 2210 | //interruptible_sleep_on(&ATEN2011_port->delta_msr_wait); |
| 2211 | // ATEN2011_port->delta_msr_cond=0; |
| 2212 | //wait_event_interruptible(ATEN2011_port->delta_msr_wait,(ATEN2011_port->delta_msr_cond==1)); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2213 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2214 | /* see if a signal did it */ |
| 2215 | if (signal_pending(current)) |
| 2216 | return -ERESTARTSYS; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2217 | cnow = ATEN2011_port->icount; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2218 | if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr && |
| 2219 | cnow.dcd == cprev.dcd && cnow.cts == cprev.cts) |
| 2220 | return -EIO; /* no change => error */ |
| 2221 | if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) || |
| 2222 | ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) || |
| 2223 | ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) || |
| 2224 | ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts))) { |
| 2225 | return 0; |
| 2226 | } |
| 2227 | cprev = cnow; |
| 2228 | } |
| 2229 | /* NOTREACHED */ |
| 2230 | break; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2231 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2232 | case TIOCGICOUNT: |
| 2233 | cnow = ATEN2011_port->icount; |
| 2234 | icount.cts = cnow.cts; |
| 2235 | icount.dsr = cnow.dsr; |
| 2236 | icount.rng = cnow.rng; |
| 2237 | icount.dcd = cnow.dcd; |
| 2238 | icount.rx = cnow.rx; |
| 2239 | icount.tx = cnow.tx; |
| 2240 | icount.frame = cnow.frame; |
| 2241 | icount.overrun = cnow.overrun; |
| 2242 | icount.parity = cnow.parity; |
| 2243 | icount.brk = cnow.brk; |
| 2244 | icount.buf_overrun = cnow.buf_overrun; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2245 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2246 | dbg("%s (%d) TIOCGICOUNT RX=%d, TX=%d", __FUNCTION__, |
| 2247 | port->number, icount.rx, icount.tx); |
| 2248 | if (copy_to_user((void *)arg, &icount, sizeof(icount))) |
| 2249 | return -EFAULT; |
| 2250 | return 0; |
| 2251 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2252 | default: |
| 2253 | break; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2254 | } |
| 2255 | |
| 2256 | return -ENOIOCTLCMD; |
| 2257 | } |
| 2258 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2259 | static int ATEN2011_send_cmd_write_baud_rate(struct ATENINTL_port |
| 2260 | *ATEN2011_port, int baudRate) |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2261 | { |
| 2262 | int divisor = 0; |
| 2263 | int status; |
| 2264 | __u16 Data; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2265 | unsigned char number; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2266 | __u16 clk_sel_val; |
| 2267 | struct usb_serial_port *port; |
| 2268 | int minor; |
| 2269 | |
| 2270 | if (ATEN2011_port == NULL) |
| 2271 | return -1; |
| 2272 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2273 | port = (struct usb_serial_port *)ATEN2011_port->port; |
| 2274 | if (ATEN2011_port_paranoia_check(port, __FUNCTION__)) { |
| 2275 | DPRINTK("%s", "Invalid port \n"); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2276 | return -1; |
| 2277 | } |
| 2278 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2279 | if (ATEN2011_serial_paranoia_check(port->serial, __FUNCTION__)) { |
| 2280 | DPRINTK("%s", "Invalid Serial \n"); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2281 | return -1; |
| 2282 | } |
| 2283 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2284 | DPRINTK("%s", "Entering .......... \n"); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2285 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2286 | minor = ATEN2011_port->port->serial->minor; |
| 2287 | if (minor == SERIAL_TTY_NO_MINOR) |
| 2288 | minor = 0; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2289 | number = ATEN2011_port->port->number - minor; |
| 2290 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2291 | dbg("%s - port = %d, baud = %d", __FUNCTION__, |
| 2292 | ATEN2011_port->port->number, baudRate); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2293 | //reset clk_uart_sel in spregOffset |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2294 | if (baudRate > 115200) { |
| 2295 | #ifdef HW_flow_control |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2296 | //NOTE: need to see the pther register to modify |
| 2297 | //setting h/w flow control bit to 1; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2298 | status = 0; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2299 | //Data = ATEN2011_port->shadowMCR ; |
| 2300 | Data = 0x2b; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2301 | ATEN2011_port->shadowMCR = Data; |
| 2302 | status = |
| 2303 | ATEN2011_set_Uart_Reg(port, MODEM_CONTROL_REGISTER, Data); |
| 2304 | if (status < 0) { |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2305 | DPRINTK("Writing spreg failed in set_serial_baud\n"); |
| 2306 | return -1; |
| 2307 | } |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2308 | #endif |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2309 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2310 | } else { |
| 2311 | #ifdef HW_flow_control |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2312 | //setting h/w flow control bit to 0; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2313 | status = 0; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2314 | //Data = ATEN2011_port->shadowMCR ; |
| 2315 | Data = 0xb; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2316 | ATEN2011_port->shadowMCR = Data; |
| 2317 | status = |
| 2318 | ATEN2011_set_Uart_Reg(port, MODEM_CONTROL_REGISTER, Data); |
| 2319 | if (status < 0) { |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2320 | DPRINTK("Writing spreg failed in set_serial_baud\n"); |
| 2321 | return -1; |
| 2322 | } |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2323 | #endif |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2324 | |
| 2325 | } |
| 2326 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2327 | if (1) //baudRate <= 115200) |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2328 | { |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2329 | clk_sel_val = 0x0; |
| 2330 | Data = 0x0; |
| 2331 | status = 0; |
| 2332 | status = |
| 2333 | ATEN2011_calc_baud_rate_divisor(baudRate, &divisor, |
| 2334 | &clk_sel_val); |
| 2335 | status = |
| 2336 | ATEN2011_get_reg_sync(port, ATEN2011_port->SpRegOffset, |
| 2337 | &Data); |
| 2338 | if (status < 0) { |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2339 | DPRINTK("reading spreg failed in set_serial_baud\n"); |
| 2340 | return -1; |
| 2341 | } |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2342 | Data = (Data & 0x8f) | clk_sel_val; |
| 2343 | status = 0; |
| 2344 | status = |
| 2345 | ATEN2011_set_reg_sync(port, ATEN2011_port->SpRegOffset, |
| 2346 | Data); |
| 2347 | if (status < 0) { |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2348 | DPRINTK("Writing spreg failed in set_serial_baud\n"); |
| 2349 | return -1; |
| 2350 | } |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2351 | /* Calculate the Divisor */ |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2352 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2353 | if (status) { |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2354 | err("%s - bad baud rate", __FUNCTION__); |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2355 | DPRINTK("%s\n", "bad baud rate"); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2356 | return status; |
| 2357 | } |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2358 | /* Enable access to divisor latch */ |
| 2359 | Data = ATEN2011_port->shadowLCR | SERIAL_LCR_DLAB; |
| 2360 | ATEN2011_port->shadowLCR = Data; |
| 2361 | ATEN2011_set_Uart_Reg(port, LINE_CONTROL_REGISTER, Data); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2362 | |
| 2363 | /* Write the divisor */ |
Greg Kroah-Hartman | a636409 | 2009-01-29 16:57:23 -0800 | [diff] [blame^] | 2364 | Data = (unsigned char)(divisor & 0xff); |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2365 | DPRINTK("set_serial_baud Value to write DLL is %x\n", Data); |
| 2366 | ATEN2011_set_Uart_Reg(port, DIVISOR_LATCH_LSB, Data); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2367 | |
Greg Kroah-Hartman | a636409 | 2009-01-29 16:57:23 -0800 | [diff] [blame^] | 2368 | Data = (unsigned char)((divisor & 0xff00) >> 8); |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2369 | DPRINTK("set_serial_baud Value to write DLM is %x\n", Data); |
| 2370 | ATEN2011_set_Uart_Reg(port, DIVISOR_LATCH_MSB, Data); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2371 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2372 | /* Disable access to divisor latch */ |
| 2373 | Data = ATEN2011_port->shadowLCR & ~SERIAL_LCR_DLAB; |
| 2374 | ATEN2011_port->shadowLCR = Data; |
| 2375 | ATEN2011_set_Uart_Reg(port, LINE_CONTROL_REGISTER, Data); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2376 | |
| 2377 | } |
| 2378 | |
| 2379 | return status; |
| 2380 | } |
| 2381 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2382 | static int ATEN2011_calc_baud_rate_divisor(int baudRate, int *divisor, |
| 2383 | __u16 * clk_sel_val) |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2384 | { |
| 2385 | //int i; |
| 2386 | //__u16 custom,round1, round; |
| 2387 | |
| 2388 | dbg("%s - %d", __FUNCTION__, baudRate); |
| 2389 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2390 | if (baudRate <= 115200) { |
| 2391 | *divisor = 115200 / baudRate; |
| 2392 | *clk_sel_val = 0x0; |
| 2393 | } |
| 2394 | if ((baudRate > 115200) && (baudRate <= 230400)) { |
| 2395 | *divisor = 230400 / baudRate; |
| 2396 | *clk_sel_val = 0x10; |
| 2397 | } else if ((baudRate > 230400) && (baudRate <= 403200)) { |
| 2398 | *divisor = 403200 / baudRate; |
| 2399 | *clk_sel_val = 0x20; |
| 2400 | } else if ((baudRate > 403200) && (baudRate <= 460800)) { |
| 2401 | *divisor = 460800 / baudRate; |
| 2402 | *clk_sel_val = 0x30; |
| 2403 | } else if ((baudRate > 460800) && (baudRate <= 806400)) { |
| 2404 | *divisor = 806400 / baudRate; |
| 2405 | *clk_sel_val = 0x40; |
| 2406 | } else if ((baudRate > 806400) && (baudRate <= 921600)) { |
| 2407 | *divisor = 921600 / baudRate; |
| 2408 | *clk_sel_val = 0x50; |
| 2409 | } else if ((baudRate > 921600) && (baudRate <= 1572864)) { |
| 2410 | *divisor = 1572864 / baudRate; |
| 2411 | *clk_sel_val = 0x60; |
| 2412 | } else if ((baudRate > 1572864) && (baudRate <= 3145728)) { |
| 2413 | *divisor = 3145728 / baudRate; |
| 2414 | *clk_sel_val = 0x70; |
| 2415 | } |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2416 | return 0; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2417 | } |
| 2418 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2419 | static void ATEN2011_change_port_settings(struct tty_struct *tty, |
| 2420 | struct ATENINTL_port *ATEN2011_port, |
| 2421 | struct ktermios *old_termios) |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2422 | { |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2423 | int baud; |
| 2424 | unsigned cflag; |
| 2425 | unsigned iflag; |
| 2426 | __u8 mask = 0xff; |
| 2427 | __u8 lData; |
| 2428 | __u8 lParity; |
| 2429 | __u8 lStop; |
| 2430 | int status; |
| 2431 | __u16 Data; |
| 2432 | struct usb_serial_port *port; |
| 2433 | struct usb_serial *serial; |
| 2434 | |
| 2435 | if (ATEN2011_port == NULL) |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2436 | return; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2437 | |
| 2438 | port = (struct usb_serial_port *)ATEN2011_port->port; |
| 2439 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2440 | if (ATEN2011_port_paranoia_check(port, __FUNCTION__)) { |
| 2441 | DPRINTK("%s", "Invalid port \n"); |
| 2442 | return; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2443 | } |
| 2444 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2445 | if (ATEN2011_serial_paranoia_check(port->serial, __FUNCTION__)) { |
| 2446 | DPRINTK("%s", "Invalid Serial \n"); |
| 2447 | return; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2448 | } |
| 2449 | |
| 2450 | serial = port->serial; |
| 2451 | |
| 2452 | dbg("%s - port %d", __FUNCTION__, ATEN2011_port->port->number); |
| 2453 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2454 | if ((!ATEN2011_port->open) && (!ATEN2011_port->openPending)) { |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2455 | dbg("%s - port not opened", __FUNCTION__); |
| 2456 | return; |
| 2457 | } |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2458 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2459 | if ((!tty) || (!tty->termios)) { |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2460 | dbg("%s - no tty structures", __FUNCTION__); |
| 2461 | return; |
| 2462 | } |
| 2463 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2464 | DPRINTK("%s", "Entering .......... \n"); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2465 | |
| 2466 | lData = LCR_BITS_8; |
| 2467 | lStop = LCR_STOP_1; |
| 2468 | lParity = LCR_PAR_NONE; |
| 2469 | |
| 2470 | cflag = tty->termios->c_cflag; |
| 2471 | iflag = tty->termios->c_iflag; |
| 2472 | |
| 2473 | /* Change the number of bits */ |
| 2474 | |
| 2475 | //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 |
| 2476 | //if(cflag & CSIZE) |
| 2477 | { |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2478 | switch (cflag & CSIZE) { |
| 2479 | case CS5: |
| 2480 | lData = LCR_BITS_5; |
| 2481 | mask = 0x1f; |
| 2482 | break; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2483 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2484 | case CS6: |
| 2485 | lData = LCR_BITS_6; |
| 2486 | mask = 0x3f; |
| 2487 | break; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2488 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2489 | case CS7: |
| 2490 | lData = LCR_BITS_7; |
| 2491 | mask = 0x7f; |
| 2492 | break; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2493 | default: |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2494 | case CS8: |
| 2495 | lData = LCR_BITS_8; |
| 2496 | break; |
| 2497 | } |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2498 | } |
| 2499 | /* Change the Parity bit */ |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2500 | if (cflag & PARENB) { |
| 2501 | if (cflag & PARODD) { |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2502 | lParity = LCR_PAR_ODD; |
| 2503 | dbg("%s - parity = odd", __FUNCTION__); |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2504 | } else { |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2505 | lParity = LCR_PAR_EVEN; |
| 2506 | dbg("%s - parity = even", __FUNCTION__); |
| 2507 | } |
| 2508 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2509 | } else { |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2510 | dbg("%s - parity = none", __FUNCTION__); |
| 2511 | } |
| 2512 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2513 | if (cflag & CMSPAR) { |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2514 | lParity = lParity | 0x20; |
| 2515 | } |
| 2516 | |
| 2517 | /* Change the Stop bit */ |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2518 | if (cflag & CSTOPB) { |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2519 | lStop = LCR_STOP_2; |
| 2520 | dbg("%s - stop bits = 2", __FUNCTION__); |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2521 | } else { |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2522 | lStop = LCR_STOP_1; |
| 2523 | dbg("%s - stop bits = 1", __FUNCTION__); |
| 2524 | } |
| 2525 | |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2526 | /* Update the LCR with the correct value */ |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2527 | ATEN2011_port->shadowLCR &= |
| 2528 | ~(LCR_BITS_MASK | LCR_STOP_MASK | LCR_PAR_MASK); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2529 | ATEN2011_port->shadowLCR |= (lData | lParity | lStop); |
| 2530 | |
| 2531 | ATEN2011_port->validDataMask = mask; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2532 | DPRINTK |
| 2533 | ("ATEN2011_change_port_settings ATEN2011_port->shadowLCR is %x\n", |
| 2534 | ATEN2011_port->shadowLCR); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2535 | /* Disable Interrupts */ |
| 2536 | Data = 0x00; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2537 | ATEN2011_set_Uart_Reg(port, INTERRUPT_ENABLE_REGISTER, Data); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2538 | |
| 2539 | Data = 0x00; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2540 | ATEN2011_set_Uart_Reg(port, FIFO_CONTROL_REGISTER, Data); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2541 | |
| 2542 | Data = 0xcf; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2543 | ATEN2011_set_Uart_Reg(port, FIFO_CONTROL_REGISTER, Data); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2544 | |
| 2545 | /* Send the updated LCR value to the ATEN2011 */ |
| 2546 | Data = ATEN2011_port->shadowLCR; |
| 2547 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2548 | ATEN2011_set_Uart_Reg(port, LINE_CONTROL_REGISTER, Data); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2549 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2550 | Data = 0x00b; |
| 2551 | ATEN2011_port->shadowMCR = Data; |
| 2552 | ATEN2011_set_Uart_Reg(port, MODEM_CONTROL_REGISTER, Data); |
| 2553 | Data = 0x00b; |
| 2554 | ATEN2011_set_Uart_Reg(port, MODEM_CONTROL_REGISTER, Data); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2555 | |
| 2556 | /* set up the MCR register and send it to the ATEN2011 */ |
| 2557 | |
| 2558 | ATEN2011_port->shadowMCR = MCR_MASTER_IE; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2559 | if (cflag & CBAUD) { |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2560 | ATEN2011_port->shadowMCR |= (MCR_DTR | MCR_RTS); |
| 2561 | } |
| 2562 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2563 | if (cflag & CRTSCTS) { |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2564 | ATEN2011_port->shadowMCR |= (MCR_XON_ANY); |
| 2565 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2566 | } else { |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2567 | ATEN2011_port->shadowMCR &= ~(MCR_XON_ANY); |
| 2568 | } |
| 2569 | |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2570 | Data = ATEN2011_port->shadowMCR; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2571 | ATEN2011_set_Uart_Reg(port, MODEM_CONTROL_REGISTER, Data); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2572 | |
| 2573 | /* Determine divisor based on baud rate */ |
| 2574 | baud = tty_get_baud_rate(tty); |
| 2575 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2576 | if (!baud) { |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2577 | /* pick a default, any default... */ |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2578 | DPRINTK("%s\n", "Picked default baud..."); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2579 | baud = 9600; |
| 2580 | } |
| 2581 | |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2582 | dbg("%s - baud rate = %d", __FUNCTION__, baud); |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2583 | status = ATEN2011_send_cmd_write_baud_rate(ATEN2011_port, baud); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2584 | |
| 2585 | /* Enable Interrupts */ |
| 2586 | Data = 0x0c; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2587 | ATEN2011_set_Uart_Reg(port, INTERRUPT_ENABLE_REGISTER, Data); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2588 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2589 | if (ATEN2011_port->read_urb->status != -EINPROGRESS) { |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2590 | ATEN2011_port->read_urb->dev = serial->dev; |
| 2591 | |
| 2592 | status = usb_submit_urb(ATEN2011_port->read_urb, GFP_ATOMIC); |
| 2593 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2594 | if (status) { |
| 2595 | DPRINTK |
| 2596 | (" usb_submit_urb(read bulk) failed, status = %d", |
| 2597 | status); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2598 | } |
| 2599 | } |
| 2600 | //wake_up(&ATEN2011_port->delta_msr_wait); |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2601 | //ATEN2011_port->delta_msr_cond=1; |
| 2602 | DPRINTK |
| 2603 | ("ATEN2011_change_port_settings ATEN2011_port->shadowLCR is End %x\n", |
| 2604 | ATEN2011_port->shadowLCR); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2605 | |
| 2606 | return; |
| 2607 | } |
| 2608 | |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2609 | static int ATEN2011_calc_num_ports(struct usb_serial *serial) |
| 2610 | { |
| 2611 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2612 | __u16 Data = 0x00; |
| 2613 | int ret = 0; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2614 | int ATEN2011_2or4ports; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2615 | ret = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), |
| 2616 | ATEN_RDREQ, ATEN_RD_RTYPE, 0, GPIO_REGISTER, |
| 2617 | &Data, VENDOR_READ_LENGTH, ATEN_WDR_TIMEOUT); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2618 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2619 | //printk("ATEN2011_calc_num_ports GPIO is %x\n",Data); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2620 | |
| 2621 | /* ghostgum: here is where the problem appears to bet */ |
| 2622 | /* Which of the following are needed? */ |
| 2623 | /* Greg used the serial->type->num_ports=2 */ |
| 2624 | /* But the code in the ATEN2011_open relies on serial->num_ports=2 */ |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2625 | if ((Data & 0x01) == 0) { |
| 2626 | ATEN2011_2or4ports = 2; |
| 2627 | serial->type->num_ports = 2; |
| 2628 | serial->num_ports = 2; |
| 2629 | } |
| 2630 | //else if(serial->interface->cur_altsetting->desc.bNumEndpoints == 9) |
| 2631 | else { |
| 2632 | ATEN2011_2or4ports = 4; |
| 2633 | serial->type->num_ports = 4; |
| 2634 | serial->num_ports = 4; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2635 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2636 | } |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2637 | |
| 2638 | return ATEN2011_2or4ports; |
| 2639 | } |
| 2640 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2641 | static int ATEN2011_startup(struct usb_serial *serial) |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2642 | { |
| 2643 | struct ATENINTL_serial *ATEN2011_serial; |
| 2644 | struct ATENINTL_port *ATEN2011_port; |
| 2645 | struct usb_device *dev; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2646 | int i, status; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2647 | int minor; |
| 2648 | |
| 2649 | __u16 Data; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2650 | DPRINTK("%s \n", " ATEN2011_startup :entering.........."); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2651 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2652 | if (!serial) { |
| 2653 | DPRINTK("%s\n", "Invalid Handler"); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2654 | return -1; |
| 2655 | } |
| 2656 | |
| 2657 | dev = serial->dev; |
| 2658 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2659 | DPRINTK("%s\n", "Entering..."); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2660 | |
| 2661 | /* create our private serial structure */ |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2662 | ATEN2011_serial = kzalloc(sizeof(struct ATENINTL_serial), GFP_KERNEL); |
| 2663 | if (ATEN2011_serial == NULL) { |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2664 | err("%s - Out of memory", __FUNCTION__); |
| 2665 | return -ENOMEM; |
| 2666 | } |
| 2667 | |
| 2668 | /* resetting the private structure field values to zero */ |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2669 | memset(ATEN2011_serial, 0, sizeof(struct ATENINTL_serial)); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2670 | |
| 2671 | ATEN2011_serial->serial = serial; |
Greg Kroah-Hartman | a636409 | 2009-01-29 16:57:23 -0800 | [diff] [blame^] | 2672 | //initilize status polling flag to 0 |
| 2673 | ATEN2011_serial->status_polling_started = 0; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2674 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2675 | ATEN2011_set_serial_private(serial, ATEN2011_serial); |
| 2676 | ATEN2011_serial->ATEN2011_spectrum_2or4ports = |
| 2677 | ATEN2011_calc_num_ports(serial); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2678 | /* we set up the pointers to the endpoints in the ATEN2011_open * |
| 2679 | * function, as the structures aren't created yet. */ |
| 2680 | |
| 2681 | /* set up port private structures */ |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2682 | for (i = 0; i < serial->num_ports; ++i) { |
| 2683 | ATEN2011_port = |
| 2684 | kmalloc(sizeof(struct ATENINTL_port), GFP_KERNEL); |
| 2685 | if (ATEN2011_port == NULL) { |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2686 | err("%s - Out of memory", __FUNCTION__); |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2687 | ATEN2011_set_serial_private(serial, NULL); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2688 | kfree(ATEN2011_serial); |
| 2689 | return -ENOMEM; |
| 2690 | } |
| 2691 | memset(ATEN2011_port, 0, sizeof(struct ATENINTL_port)); |
| 2692 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2693 | /* Initialize all port interrupt end point to port 0 int endpoint * |
| 2694 | * Our device has only one interrupt end point comman to all port */ |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2695 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2696 | // serial->port[i]->interrupt_in_endpointAddress = serial->port[0]->interrupt_in_endpointAddress; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2697 | |
| 2698 | ATEN2011_port->port = serial->port[i]; |
| 2699 | // |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2700 | ATEN2011_set_port_private(serial->port[i], ATEN2011_port); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2701 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2702 | minor = serial->port[i]->serial->minor; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2703 | if (minor == SERIAL_TTY_NO_MINOR) |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2704 | minor = 0; |
| 2705 | ATEN2011_port->port_num = |
| 2706 | ((serial->port[i]->number - minor) + 1); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2707 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2708 | ATEN2011_port->AppNum = (((__u16) serial->port[i]->number - |
| 2709 | (__u16) (minor)) + 1) << 8; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2710 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2711 | if (ATEN2011_port->port_num == 1) { |
| 2712 | ATEN2011_port->SpRegOffset = 0x0; |
| 2713 | ATEN2011_port->ControlRegOffset = 0x1; |
| 2714 | ATEN2011_port->DcrRegOffset = 0x4; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2715 | } else if ((ATEN2011_port->port_num == 2) |
| 2716 | && (ATEN2011_serial->ATEN2011_spectrum_2or4ports == |
| 2717 | 4)) { |
| 2718 | ATEN2011_port->SpRegOffset = 0x8; |
| 2719 | ATEN2011_port->ControlRegOffset = 0x9; |
| 2720 | ATEN2011_port->DcrRegOffset = 0x16; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2721 | } else if ((ATEN2011_port->port_num == 2) |
| 2722 | && (ATEN2011_serial->ATEN2011_spectrum_2or4ports == |
| 2723 | 2)) { |
| 2724 | ATEN2011_port->SpRegOffset = 0xa; |
| 2725 | ATEN2011_port->ControlRegOffset = 0xb; |
| 2726 | ATEN2011_port->DcrRegOffset = 0x19; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2727 | } else if ((ATEN2011_port->port_num == 3) |
| 2728 | && (ATEN2011_serial->ATEN2011_spectrum_2or4ports == |
| 2729 | 4)) { |
| 2730 | ATEN2011_port->SpRegOffset = 0xa; |
| 2731 | ATEN2011_port->ControlRegOffset = 0xb; |
| 2732 | ATEN2011_port->DcrRegOffset = 0x19; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2733 | } else if ((ATEN2011_port->port_num == 4) |
| 2734 | && (ATEN2011_serial->ATEN2011_spectrum_2or4ports == |
| 2735 | 4)) { |
| 2736 | ATEN2011_port->SpRegOffset = 0xc; |
| 2737 | ATEN2011_port->ControlRegOffset = 0xd; |
| 2738 | ATEN2011_port->DcrRegOffset = 0x1c; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2739 | } |
| 2740 | ATEN2011_Dump_serial_port(ATEN2011_port); |
| 2741 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2742 | ATEN2011_set_port_private(serial->port[i], ATEN2011_port); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2743 | |
| 2744 | //enable rx_disable bit in control register |
| 2745 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2746 | status = |
| 2747 | ATEN2011_get_reg_sync(serial->port[i], |
| 2748 | ATEN2011_port->ControlRegOffset, |
| 2749 | &Data); |
| 2750 | if (status < 0) { |
| 2751 | DPRINTK("Reading ControlReg failed status-0x%x\n", |
| 2752 | status); |
| 2753 | break; |
| 2754 | } else |
| 2755 | DPRINTK |
| 2756 | ("ControlReg Reading success val is %x, status%d\n", |
| 2757 | Data, status); |
| 2758 | Data |= 0x08; //setting driver done bit |
| 2759 | Data |= 0x04; //sp1_bit to have cts change reflect in modem status reg |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2760 | |
| 2761 | //Data |= 0x20; //rx_disable bit |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2762 | status = 0; |
| 2763 | status = |
| 2764 | ATEN2011_set_reg_sync(serial->port[i], |
| 2765 | ATEN2011_port->ControlRegOffset, |
| 2766 | Data); |
| 2767 | if (status < 0) { |
| 2768 | DPRINTK |
| 2769 | ("Writing ControlReg failed(rx_disable) status-0x%x\n", |
| 2770 | status); |
| 2771 | break; |
| 2772 | } else |
| 2773 | DPRINTK |
| 2774 | ("ControlReg Writing success(rx_disable) status%d\n", |
| 2775 | status); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2776 | |
| 2777 | //Write default values in DCR (i.e 0x01 in DCR0, 0x05 in DCR2 and 0x24 in DCR3 |
| 2778 | Data = 0x01; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2779 | status = 0; |
| 2780 | status = |
| 2781 | ATEN2011_set_reg_sync(serial->port[i], |
| 2782 | (__u16) (ATEN2011_port->DcrRegOffset + |
| 2783 | 0), Data); |
| 2784 | if (status < 0) { |
| 2785 | DPRINTK("Writing DCR0 failed status-0x%x\n", status); |
| 2786 | break; |
| 2787 | } else |
| 2788 | DPRINTK("DCR0 Writing success status%d\n", status); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2789 | |
| 2790 | Data = 0x05; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2791 | status = 0; |
| 2792 | status = |
| 2793 | ATEN2011_set_reg_sync(serial->port[i], |
| 2794 | (__u16) (ATEN2011_port->DcrRegOffset + |
| 2795 | 1), Data); |
| 2796 | if (status < 0) { |
| 2797 | DPRINTK("Writing DCR1 failed status-0x%x\n", status); |
| 2798 | break; |
| 2799 | } else |
| 2800 | DPRINTK("DCR1 Writing success status%d\n", status); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2801 | |
| 2802 | Data = 0x24; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2803 | status = 0; |
| 2804 | status = |
| 2805 | ATEN2011_set_reg_sync(serial->port[i], |
| 2806 | (__u16) (ATEN2011_port->DcrRegOffset + |
| 2807 | 2), Data); |
| 2808 | if (status < 0) { |
| 2809 | DPRINTK("Writing DCR2 failed status-0x%x\n", status); |
| 2810 | break; |
| 2811 | } else |
| 2812 | DPRINTK("DCR2 Writing success status%d\n", status); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2813 | |
| 2814 | // write values in clkstart0x0 and clkmulti 0x20 |
| 2815 | Data = 0x0; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2816 | status = 0; |
| 2817 | status = |
| 2818 | ATEN2011_set_reg_sync(serial->port[i], |
| 2819 | CLK_START_VALUE_REGISTER, Data); |
| 2820 | if (status < 0) { |
| 2821 | DPRINTK |
| 2822 | ("Writing CLK_START_VALUE_REGISTER failed status-0x%x\n", |
| 2823 | status); |
| 2824 | break; |
| 2825 | } else |
| 2826 | DPRINTK |
| 2827 | ("CLK_START_VALUE_REGISTER Writing success status%d\n", |
| 2828 | status); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2829 | |
| 2830 | Data = 0x20; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2831 | status = 0; |
| 2832 | status = |
| 2833 | ATEN2011_set_reg_sync(serial->port[i], CLK_MULTI_REGISTER, |
| 2834 | Data); |
| 2835 | if (status < 0) { |
| 2836 | DPRINTK |
| 2837 | ("Writing CLK_MULTI_REGISTER failed status-0x%x\n", |
| 2838 | status); |
| 2839 | break; |
| 2840 | } else |
| 2841 | DPRINTK("CLK_MULTI_REGISTER Writing success status%d\n", |
| 2842 | status); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2843 | |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2844 | //Zero Length flag register |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2845 | if ((ATEN2011_port->port_num != 1) |
| 2846 | && (ATEN2011_serial->ATEN2011_spectrum_2or4ports == 2)) { |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2847 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2848 | Data = 0xff; |
| 2849 | status = 0; |
| 2850 | status = ATEN2011_set_reg_sync(serial->port[i], |
| 2851 | (__u16) (ZLP_REG1 + |
| 2852 | ((__u16) |
| 2853 | ATEN2011_port-> |
| 2854 | port_num)), |
| 2855 | Data); |
| 2856 | DPRINTK("ZLIP offset%x\n", |
| 2857 | (__u16) (ZLP_REG1 + |
| 2858 | ((__u16) ATEN2011_port->port_num))); |
| 2859 | if (status < 0) { |
| 2860 | DPRINTK |
| 2861 | ("Writing ZLP_REG%d failed status-0x%x\n", |
| 2862 | i + 2, status); |
| 2863 | break; |
| 2864 | } else |
| 2865 | DPRINTK("ZLP_REG%d Writing success status%d\n", |
| 2866 | i + 2, status); |
| 2867 | } else { |
| 2868 | Data = 0xff; |
| 2869 | status = 0; |
| 2870 | status = ATEN2011_set_reg_sync(serial->port[i], |
| 2871 | (__u16) (ZLP_REG1 + |
| 2872 | ((__u16) |
| 2873 | ATEN2011_port-> |
| 2874 | port_num) - |
| 2875 | 0x1), Data); |
| 2876 | DPRINTK("ZLIP offset%x\n", |
| 2877 | (__u16) (ZLP_REG1 + |
| 2878 | ((__u16) ATEN2011_port->port_num) - |
| 2879 | 0x1)); |
| 2880 | if (status < 0) { |
| 2881 | DPRINTK |
| 2882 | ("Writing ZLP_REG%d failed status-0x%x\n", |
| 2883 | i + 1, status); |
| 2884 | break; |
| 2885 | } else |
| 2886 | DPRINTK("ZLP_REG%d Writing success status%d\n", |
| 2887 | i + 1, status); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2888 | |
| 2889 | } |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2890 | ATEN2011_port->control_urb = usb_alloc_urb(0, GFP_ATOMIC); |
| 2891 | ATEN2011_port->ctrl_buf = kmalloc(16, GFP_KERNEL); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2892 | |
| 2893 | } |
| 2894 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2895 | //Zero Length flag enable |
| 2896 | Data = 0x0f; |
| 2897 | status = 0; |
| 2898 | status = ATEN2011_set_reg_sync(serial->port[0], ZLP_REG5, Data); |
| 2899 | if (status < 0) { |
| 2900 | DPRINTK("Writing ZLP_REG5 failed status-0x%x\n", status); |
| 2901 | return -1; |
| 2902 | } else |
| 2903 | DPRINTK("ZLP_REG5 Writing success status%d\n", status); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2904 | |
| 2905 | /* setting configuration feature to one */ |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2906 | usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), |
| 2907 | (__u8) 0x03, 0x00, 0x01, 0x00, 0x00, 0x00, 5 * HZ); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2908 | return 0; |
| 2909 | } |
| 2910 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2911 | static void ATEN2011_shutdown(struct usb_serial *serial) |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2912 | { |
| 2913 | int i; |
| 2914 | struct ATENINTL_port *ATEN2011_port; |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2915 | DPRINTK("%s \n", " shutdown :entering.........."); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2916 | |
| 2917 | /* MATRIX */ |
| 2918 | //ThreadState = 1; |
| 2919 | /* MATRIX */ |
| 2920 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2921 | if (!serial) { |
| 2922 | DPRINTK("%s", "Invalid Handler \n"); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2923 | return; |
| 2924 | } |
| 2925 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2926 | /* check for the ports to be closed,close the ports and disconnect */ |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2927 | |
| 2928 | /* free private structure allocated for serial port * |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2929 | * stop reads and writes on all ports */ |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2930 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2931 | for (i = 0; i < serial->num_ports; ++i) { |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2932 | ATEN2011_port = ATEN2011_get_port_private(serial->port[i]); |
| 2933 | kfree(ATEN2011_port->ctrl_buf); |
| 2934 | usb_kill_urb(ATEN2011_port->control_urb); |
| 2935 | kfree(ATEN2011_port); |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2936 | ATEN2011_set_port_private(serial->port[i], NULL); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2937 | } |
| 2938 | |
| 2939 | /* free private structure allocated for serial device */ |
| 2940 | |
| 2941 | kfree(ATEN2011_get_serial_private(serial)); |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2942 | ATEN2011_set_serial_private(serial, NULL); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2943 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2944 | DPRINTK("%s\n", "Thank u :: "); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2945 | |
| 2946 | } |
| 2947 | |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2948 | /* Inline functions to check the sanity of a pointer that is passed to us */ |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2949 | static int ATEN2011_serial_paranoia_check(struct usb_serial *serial, |
| 2950 | const char *function) |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2951 | { |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2952 | if (!serial) { |
| 2953 | dbg("%s - serial == NULL", function); |
| 2954 | return -1; |
| 2955 | } |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2956 | if (!serial->type) { |
| 2957 | dbg("%s - serial->type == NULL!", function); |
| 2958 | return -1; |
| 2959 | } |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2960 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2961 | return 0; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2962 | } |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2963 | static int ATEN2011_port_paranoia_check(struct usb_serial_port *port, |
| 2964 | const char *function) |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2965 | { |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2966 | if (!port) { |
| 2967 | dbg("%s - port == NULL", function); |
| 2968 | return -1; |
| 2969 | } |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2970 | if (!port->serial) { |
| 2971 | dbg("%s - port->serial == NULL", function); |
| 2972 | return -1; |
| 2973 | } |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2974 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2975 | return 0; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2976 | } |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2977 | static struct usb_serial *ATEN2011_get_usb_serial(struct usb_serial_port *port, |
| 2978 | const char *function) |
| 2979 | { |
| 2980 | /* if no port was specified, or it fails a paranoia check */ |
| 2981 | if (!port || |
| 2982 | ATEN2011_port_paranoia_check(port, function) || |
| 2983 | ATEN2011_serial_paranoia_check(port->serial, function)) { |
| 2984 | /* then say that we don't have a valid usb_serial thing, which will * end up genrating -ENODEV return values */ |
| 2985 | return NULL; |
| 2986 | } |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2987 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2988 | return port->serial; |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2989 | } |
| 2990 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2991 | int __init ATENINTL2011_init(void) |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2992 | { |
| 2993 | int retval; |
| 2994 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2995 | DPRINTK("%s \n", " ATEN2011_init :entering.........."); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2996 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 2997 | /* Register with the usb serial */ |
| 2998 | retval = usb_serial_register(&ATENINTL2011_4port_device); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 2999 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 3000 | if (retval) |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 3001 | goto failed_port_device_register; |
| 3002 | |
| 3003 | /* info(DRIVER_DESC " " DRIVER_VERSION); */ |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 3004 | printk(KERN_INFO KBUILD_MODNAME ":" |
| 3005 | DRIVER_DESC " " DRIVER_VERSION "\n"); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 3006 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 3007 | /* Register with the usb */ |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 3008 | retval = usb_register(&io_driver); |
| 3009 | |
| 3010 | if (retval) |
| 3011 | goto failed_usb_register; |
| 3012 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 3013 | if (retval == 0) { |
| 3014 | DPRINTK("%s\n", "Leaving..."); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 3015 | return 0; |
| 3016 | } |
| 3017 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 3018 | failed_usb_register: |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 3019 | usb_serial_deregister(&ATENINTL2011_4port_device); |
| 3020 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 3021 | failed_port_device_register: |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 3022 | |
| 3023 | return retval; |
| 3024 | } |
| 3025 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 3026 | void __exit ATENINTL2011_exit(void) |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 3027 | { |
| 3028 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 3029 | DPRINTK("%s \n", " ATEN2011_exit :entering.........."); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 3030 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 3031 | usb_deregister(&io_driver); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 3032 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 3033 | usb_serial_deregister(&ATENINTL2011_4port_device); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 3034 | |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 3035 | DPRINTK("%s\n", "End..."); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 3036 | } |
| 3037 | |
| 3038 | module_init(ATENINTL2011_init); |
| 3039 | module_exit(ATENINTL2011_exit); |
| 3040 | |
| 3041 | /* Module information */ |
Greg Kroah-Hartman | d93f87c | 2009-01-29 12:54:01 -0800 | [diff] [blame] | 3042 | MODULE_DESCRIPTION(DRIVER_DESC); |
Greg Kroah-Hartman | e6d69d9 | 2009-01-27 23:28:27 -0800 | [diff] [blame] | 3043 | MODULE_LICENSE("GPL"); |
| 3044 | |
| 3045 | MODULE_PARM_DESC(debug, "Debug enabled or not"); |