blob: 9d264bb2d6dc2077a758d716ca28a78fc3e9ac9a [file] [log] [blame]
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001/*
Greg Kroah-Hartmanc3858cb2009-01-29 16:41:35 -08002 * 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-Hartmane6d69d92009-01-27 23:28:27 -08008 * 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-Hartmane6d69d92009-01-27 23:28:27 -080013 */
14
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -080015#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-Hartmane6d69d92009-01-27 23:28:27 -080023#include <linux/serial.h>
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -080024#include <linux/usb.h>
Greg Kroah-Hartmana6364092009-01-29 16:57:23 -080025#include <linux/usb/serial.h>
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -080026#include <asm/uaccess.h>
27
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -080028
Greg Kroah-Hartmana6364092009-01-29 16:57:23 -080029#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-Hartmane5ce6102009-01-29 12:57:52 -080034
Greg Kroah-Hartmana6364092009-01-29 16:57:23 -080035/* 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-Hartmane5ce6102009-01-29 12:57:52 -080041
Greg Kroah-Hartmana6364092009-01-29 16:57:23 -080042/* 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-Hartmane5ce6102009-01-29 12:57:52 -080051
Greg Kroah-Hartmana6364092009-01-29 16:57:23 -080052/* 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-Hartmane5ce6102009-01-29 12:57:52 -080057
Greg Kroah-Hartmana6364092009-01-29 16:57:23 -080058/* 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-Hartmane5ce6102009-01-29 12:57:52 -080071
Greg Kroah-Hartmana6364092009-01-29 16:57:23 -080072#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-Hartmane5ce6102009-01-29 12:57:52 -080078
Greg Kroah-Hartmana6364092009-01-29 16:57:23 -080079#define SERIAL_LCR_DLAB ((__u16)(0x0080))
Greg Kroah-Hartmane5ce6102009-01-29 12:57:52 -080080
Greg Kroah-Hartmana6364092009-01-29 16:57:23 -080081/*
82 * URB POOL related defines
83 */
84#define NUM_URBS 16 /* URB Count */
85#define URB_TRANSFER_BUFFER_SIZE 32 /* URB Size */
Greg Kroah-Hartmane5ce6102009-01-29 12:57:52 -080086
Greg Kroah-Hartmane5ce6102009-01-29 12:57:52 -080087#define USB_VENDOR_ID_ATENINTL 0x0557
88#define ATENINTL_DEVICE_ID_2011 0x2011
89#define ATENINTL_DEVICE_ID_7820 0x7820
90
Greg Kroah-Hartmana6364092009-01-29 16:57:23 -080091/* different USB-serial Adapter's ID's table */
Greg Kroah-Hartmane5ce6102009-01-29 12:57:52 -080092static 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
98static __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
104MODULE_DEVICE_TABLE (usb, id_table_combined);
105
106/* This structure holds all of the local port information */
107struct 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-Hartmane5ce6102009-01-29 12:57:52 -0800144 //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 */
158struct ATENINTL_serial
159{
Greg Kroah-Hartmane5ce6102009-01-29 12:57:52 -0800160 __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-Hartmane5ce6102009-01-29 12:57:52 -0800180static void ATEN2011_interrupt_callback(struct urb *urb);
181static void ATEN2011_bulk_in_callback(struct urb *urb);
182static void ATEN2011_bulk_out_data_callback(struct urb *urb);
183static void ATEN2011_control_callback(struct urb *urb);
184static int ATEN2011_get_reg(struct ATENINTL_port *ATEN,__u16 Wval, __u16 reg, __u16 * val);
185int handle_newMsr(struct ATENINTL_port *port,__u8 newMsr);
186int handle_newLsr(struct ATENINTL_port *port,__u8 newLsr);
Greg Kroah-Hartmane5ce6102009-01-29 12:57:52 -0800187static int ATEN2011_open(struct tty_struct *tty, struct usb_serial_port *port, struct file *filp);
188static void ATEN2011_close(struct tty_struct *tty, struct usb_serial_port *port, struct file *filp);
189static int ATEN2011_write(struct tty_struct *tty, struct usb_serial_port *port, const unsigned char *data, int count);
190static int ATEN2011_write_room(struct tty_struct *tty);
191static int ATEN2011_chars_in_buffer(struct tty_struct *tty);
192static void ATEN2011_throttle(struct tty_struct *tty);
193static void ATEN2011_unthrottle(struct tty_struct *tty);
194static void ATEN2011_set_termios(struct tty_struct *tty, struct usb_serial_port *port, struct ktermios *old_termios);
195static int ATEN2011_tiocmset(struct tty_struct *tty, struct file *file,
196 unsigned int set, unsigned int clear);
197static int ATEN2011_tiocmget(struct tty_struct *tty, struct file *file);
198static int ATEN2011_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg);
199static void ATEN2011_break(struct tty_struct *tty, int break_state);
Greg Kroah-Hartmane5ce6102009-01-29 12:57:52 -0800200static int ATEN2011_startup(struct usb_serial *serial);
201static void ATEN2011_shutdown(struct usb_serial *serial);
Greg Kroah-Hartmane5ce6102009-01-29 12:57:52 -0800202static int ATEN2011_calc_num_ports(struct usb_serial *serial);
203
Greg Kroah-Hartmane5ce6102009-01-29 12:57:52 -0800204static int ATEN2011_calc_baud_rate_divisor(int baudRate, int *divisor,__u16 *clk_sel_val);
205static int ATEN2011_send_cmd_write_baud_rate(struct ATENINTL_port *ATEN2011_port, int baudRate);
Greg Kroah-Hartmane5ce6102009-01-29 12:57:52 -0800206static void ATEN2011_change_port_settings(struct tty_struct *tty, struct ATENINTL_port *ATEN2011_port, struct ktermios *old_termios);
207static void ATEN2011_block_until_chase_response(struct tty_struct *tty, struct ATENINTL_port *ATEN2011_port);
208static void ATEN2011_block_until_tx_empty(struct tty_struct *tty, struct ATENINTL_port *ATEN2011_port);
Greg Kroah-Hartmane5ce6102009-01-29 12:57:52 -0800209
210int __init ATENINTL2011_init(void);
211void __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-Hartmane6d69d92009-01-27 23:28:27 -0800250
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800251/* 1: Enables the debugging -- 0: Disable the debugging */
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800252#define ATEN_DEBUG 0
253
254#ifdef ATEN_DEBUG
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800255static int debug = 0;
256#define DPRINTK(fmt, args...) printk( "%s: " fmt, __FUNCTION__ , ## args)
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800257
258#else
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800259static int debug = 0;
260#define DPRINTK(fmt, args...)
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800261
262#endif
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800263
264/*
265 * Version Information
266 */
Greg Kroah-Hartmana6364092009-01-29 16:57:23 -0800267#define DRIVER_VERSION "2.0"
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800268#define DRIVER_DESC "ATENINTL 2011 USB Serial Adapter"
269
270/*
271 * Defines used for sending commands to port
272 */
273
Greg Kroah-Hartmana6364092009-01-29 16:57:23 -0800274#define ATEN_WDR_TIMEOUT (50) /* default urb timeout */
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800275
276/* Requests */
Greg Kroah-Hartmana6364092009-01-29 16:57:23 -0800277#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-Hartmane6d69d92009-01-27 23:28:27 -0800283
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800284int RS485mode = 0; //set to 1 for RS485 mode and 0 for RS232 mode
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800285
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800286static struct usb_serial *ATEN2011_get_usb_serial(struct usb_serial_port *port, const
287 char *function);
288static int ATEN2011_serial_paranoia_check(struct usb_serial *serial, const char
289 *function);
290static int ATEN2011_port_paranoia_check(struct usb_serial_port *port, const char
291 *function);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800292
293/* setting and get register values */
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800294static int ATEN2011_set_reg_sync(struct usb_serial_port *port, __u16 reg,
295 __u16 val);
296static int ATEN2011_get_reg_sync(struct usb_serial_port *port, __u16 reg,
297 __u16 * val);
298static int ATEN2011_set_Uart_Reg(struct usb_serial_port *port, __u16 reg,
299 __u16 val);
300static int ATEN2011_get_Uart_Reg(struct usb_serial_port *port, __u16 reg,
301 __u16 * val);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800302
303void ATEN2011_Dump_serial_port(struct ATENINTL_port *ATEN2011_port);
304
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800305
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800306static inline void ATEN2011_set_serial_private(struct usb_serial *serial,
307 struct ATENINTL_serial *data)
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800308{
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800309 usb_set_serial_data(serial, (void *)data);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800310}
311
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800312static inline struct ATENINTL_serial *ATEN2011_get_serial_private(struct
313 usb_serial
314 *serial)
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800315{
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800316 return (struct ATENINTL_serial *)usb_get_serial_data(serial);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800317}
318
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800319static inline void ATEN2011_set_port_private(struct usb_serial_port *port,
320 struct ATENINTL_port *data)
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800321{
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800322 usb_set_serial_port_data(port, (void *)data);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800323}
324
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800325static inline struct ATENINTL_port *ATEN2011_get_port_private(struct
326 usb_serial_port
327 *port)
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800328{
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800329 return (struct ATENINTL_port *)usb_get_serial_port_data(port);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800330}
331
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800332static int ATEN2011_set_reg_sync(struct usb_serial_port *port, __u16 reg,
333 __u16 val)
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800334{
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800335 struct usb_device *dev = port->serial->dev;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800336 val = val & 0x00ff;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800337 DPRINTK("ATEN2011_set_reg_sync offset is %x, value %x\n", reg, val);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800338
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800339 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-Hartmane6d69d92009-01-27 23:28:27 -0800342}
343
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800344static int ATEN2011_get_reg_sync(struct usb_serial_port *port, __u16 reg,
345 __u16 * val)
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800346{
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800347 struct usb_device *dev = port->serial->dev;
348 int ret = 0;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800349
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800350 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-Hartmane6d69d92009-01-27 23:28:27 -0800355 *val = (*val) & 0x00ff;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800356 return ret;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800357}
358
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800359static int ATEN2011_set_Uart_Reg(struct usb_serial_port *port, __u16 reg,
360 __u16 val)
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800361{
362
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800363 struct usb_device *dev = port->serial->dev;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800364 struct ATENINTL_serial *ATEN2011_serial;
365 int minor;
366 ATEN2011_serial = ATEN2011_get_serial_private(port->serial);
367 minor = port->serial->minor;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800368 if (minor == SERIAL_TTY_NO_MINOR)
369 minor = 0;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800370 val = val & 0x00ff;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800371 // For the UART control registers, the application number need to be Or'ed
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800372
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800373 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-Hartmane6d69d92009-01-27 23:28:27 -0800392 }
393 }
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800394 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-Hartmane6d69d92009-01-27 23:28:27 -0800397
398}
399
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800400static int ATEN2011_get_Uart_Reg(struct usb_serial_port *port, __u16 reg,
401 __u16 * val)
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800402{
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800403 struct usb_device *dev = port->serial->dev;
404 int ret = 0;
405 __u16 Wval;
406 struct ATENINTL_serial *ATEN2011_serial;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800407 int minor = port->serial->minor;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800408 ATEN2011_serial = ATEN2011_get_serial_private(port->serial);
409 if (minor == SERIAL_TTY_NO_MINOR)
410 minor = 0;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800411
412 //DPRINTK("application number is %4x \n",(((__u16)port->number - (__u16)(minor))+1)<<8);
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800413 /*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-Hartmane6d69d92009-01-27 23:28:27 -0800433 }
434 }
435 ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), ATEN_RDREQ,
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800436 ATEN_RD_RTYPE, Wval, reg, val, VENDOR_READ_LENGTH,
437 ATEN_WDR_TIMEOUT);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800438 *val = (*val) & 0x00ff;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800439 return ret;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800440}
441
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800442void ATEN2011_Dump_serial_port(struct ATENINTL_port *ATEN2011_port)
443{
444
445 DPRINTK("***************************************\n");
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800446 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-Hartmane6d69d92009-01-27 23:28:27 -0800450 DPRINTK("***************************************\n");
451
452}
453
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800454static struct usb_serial_driver ATENINTL2011_4port_device = {
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800455 .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-Hartmane6d69d92009-01-27 23:28:27 -0800469
470#ifdef ATENSerialProbe
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800471 .probe = ATEN2011_serial_probe,
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800472#endif
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800473 .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-Hartmane6d69d92009-01-27 23:28:27 -0800483};
484
485static struct usb_driver io_driver = {
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800486 .name = "ATEN2011",
487 .probe = usb_serial_probe,
488 .disconnect = usb_serial_disconnect,
489 .id_table = id_table_combined,
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800490};
491
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800492//#ifdef ATEN2011
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800493static void ATEN2011_interrupt_callback(struct urb *urb)
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800494{
495 int result;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800496 int length;
497 struct ATENINTL_port *ATEN2011_port;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800498 struct ATENINTL_serial *ATEN2011_serial;
499 struct usb_serial *serial;
500 __u16 Data;
501 unsigned char *data;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800502 __u8 sp[5], st;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800503 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-Hartmand93f87c2009-01-29 12:54:01 -0800507 DPRINTK("%s", " : Entering\n");
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800508
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800509 ATEN2011_serial = (struct ATENINTL_serial *)urb->context;
Greg Kroah-Hartmana6364092009-01-29 16:57:23 -0800510 if (!urb) // || ATEN2011_serial->status_polling_started == 0 )
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800511 {
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800512 DPRINTK("%s", "Invalid Pointer !!!!:\n");
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800513 return;
514 }
515
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800516 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-Hartmane6d69d92009-01-27 23:28:27 -0800531 }
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-Hartmand93f87c2009-01-29 12:54:01 -0800546 if (length && length > 5) {
547 DPRINTK("%s \n", "Wrong data !!!");
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800548 return;
549 }
550
551 /* MATRIX */
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800552 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-Hartmane6d69d92009-01-27 23:28:27 -0800564
565 }
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800566 // 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-Hartmane6d69d92009-01-27 23:28:27 -0800577 else
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800578 wval =
579 (((__u16) serial->port[i]->number -
580 (__u16) (minor)) + 1) << 8;
Greg Kroah-Hartmana6364092009-01-29 16:57:23 -0800581 if (ATEN2011_port->open != 0) {
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800582 //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-Hartmane6d69d92009-01-27 23:28:27 -0800609 }
610 }
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800611
612 }
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800613 exit:
Greg Kroah-Hartmana6364092009-01-29 16:57:23 -0800614 if (ATEN2011_serial->status_polling_started == 0)
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800615 return;
616
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800617 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-Hartmane6d69d92009-01-27 23:28:27 -0800622 }
623
624 return;
625
626}
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800627
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800628//#endif
629static void ATEN2011_control_callback(struct urb *urb)
630{
631 unsigned char *data;
632 struct ATENINTL_port *ATEN2011_port;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800633 __u8 regval = 0x0;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800634
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800635 if (!urb) {
636 DPRINTK("%s", "Invalid Pointer !!!!:\n");
637 return;
638 }
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800639
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800640 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-Hartmane6d69d92009-01-27 23:28:27 -0800656
657 ATEN2011_port = (struct ATENINTL_port *)urb->context;
658
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800659 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-Hartmane6d69d92009-01-27 23:28:27 -0800669
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800670 exit:
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800671 return;
672}
Greg Kroah-Hartmanc3858cb2009-01-29 16:41:35 -0800673
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800674int handle_newMsr(struct ATENINTL_port *port, __u8 newMsr)
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800675{
676 struct ATENINTL_port *ATEN2011_port;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800677 struct async_icount *icount;
678 ATEN2011_port = port;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800679 icount = &ATEN2011_port->icount;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800680 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-Hartmane6d69d92009-01-27 23:28:27 -0800684
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800685 /* 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-Hartmane6d69d92009-01-27 23:28:27 -0800699
700 return 0;
701}
Greg Kroah-Hartmanc3858cb2009-01-29 16:41:35 -0800702
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800703int handle_newLsr(struct ATENINTL_port *port, __u8 newLsr)
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800704{
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800705 struct async_icount *icount;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800706
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800707 dbg("%s - %02x", __FUNCTION__, newLsr);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800708
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800709 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-Hartmane6d69d92009-01-27 23:28:27 -0800717
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800718 /* update input line counters */
719 icount = &port->icount;
720 if (newLsr & SERIAL_LSR_BI) {
721 icount->brk++;
722 }
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800723 if (newLsr & SERIAL_LSR_OE) {
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800724 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-Hartmane6d69d92009-01-27 23:28:27 -0800732
733 return 0;
734}
Greg Kroah-Hartmanc3858cb2009-01-29 16:41:35 -0800735
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800736static int ATEN2011_get_reg(struct ATENINTL_port *ATEN, __u16 Wval, __u16 reg,
737 __u16 * val)
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800738{
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800739 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-Hartmane6d69d92009-01-27 23:28:27 -0800744
745// dr=(struct usb_ctrlrequest *)(buffer);
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800746 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-Hartmane6d69d92009-01-27 23:28:27 -0800752
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800753 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-Hartmane6d69d92009-01-27 23:28:27 -0800759}
760
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800761static void ATEN2011_bulk_in_callback(struct urb *urb)
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800762{
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800763 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-Hartmane6d69d92009-01-27 23:28:27 -0800769 struct tty_struct *tty;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800770 if (!urb) {
771 DPRINTK("%s", "Invalid Pointer !!!!:\n");
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800772 return;
773 }
774
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800775 if (urb->status) {
776 DPRINTK("nonzero read bulk status received: %d", urb->status);
777// if(urb->status==84)
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800778 //ThreadState=1;
779 return;
780 }
781
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800782 ATEN2011_port = (struct ATENINTL_port *)urb->context;
783 if (!ATEN2011_port) {
784 DPRINTK("%s", "NULL ATEN2011_port pointer \n");
785 return;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800786 }
787
788 port = (struct usb_serial_port *)ATEN2011_port->port;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800789 if (ATEN2011_port_paranoia_check(port, __FUNCTION__)) {
790 DPRINTK("%s", "Port Paranoia failed \n");
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800791 return;
792 }
793
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800794 serial = ATEN2011_get_usb_serial(port, __FUNCTION__);
795 if (!serial) {
796 DPRINTK("%s\n", "Bad serial pointer ");
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800797 return;
798 }
799
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800800 DPRINTK("%s\n", "Entering... \n");
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800801
802 data = urb->transfer_buffer;
803 ATEN2011_serial = ATEN2011_get_serial_private(serial);
804
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800805 DPRINTK("%s", "Entering ........... \n");
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800806
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800807 if (urb->actual_length) {
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800808 tty = tty_port_tty_get(&ATEN2011_port->port->port);
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800809 if (tty) {
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800810 tty_buffer_request_room(tty, urb->actual_length);
811 tty_insert_flip_string(tty, data, urb->actual_length);
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800812 DPRINTK(" %s \n", data);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800813 tty_flip_buffer_push(tty);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800814 tty_kref_put(tty);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800815 }
816
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800817 ATEN2011_port->icount.rx += urb->actual_length;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800818 DPRINTK("ATEN2011_port->icount.rx is %d:\n",
819 ATEN2011_port->icount.rx);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800820//MATRIX
821 }
822
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800823 if (!ATEN2011_port->read_urb) {
824 DPRINTK("%s", "URB KILLED !!!\n");
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800825 return;
826 }
827
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800828 if (ATEN2011_port->read_urb->status != -EINPROGRESS) {
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800829 ATEN2011_port->read_urb->dev = serial->dev;
830
831 status = usb_submit_urb(ATEN2011_port->read_urb, GFP_ATOMIC);
832
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800833 if (status) {
834 DPRINTK
835 (" usb_submit_urb(read bulk) failed, status = %d",
836 status);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800837 }
838 }
839}
840
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800841static void ATEN2011_bulk_out_data_callback(struct urb *urb)
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800842{
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800843 struct ATENINTL_port *ATEN2011_port;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800844 struct tty_struct *tty;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800845 if (!urb) {
846 DPRINTK("%s", "Invalid Pointer !!!!:\n");
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800847 return;
848 }
849
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800850 if (urb->status) {
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800851 DPRINTK("nonzero write bulk status received:%d\n", urb->status);
852 return;
853 }
854
855 ATEN2011_port = (struct ATENINTL_port *)urb->context;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800856 if (!ATEN2011_port) {
857 DPRINTK("%s", "NULL ATEN2011_port pointer \n");
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800858 return;
859 }
860
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800861 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-Hartmane6d69d92009-01-27 23:28:27 -0800867
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800868 tty = tty_port_tty_get(&ATEN2011_port->port->port);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800869
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800870 if (tty && ATEN2011_port->open) {
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800871 /* tell the tty driver that something has changed */
872 wake_up_interruptible(&tty->write_wait);
873 }
874
875 /* Release the Write URB */
Greg Kroah-Hartmana6364092009-01-29 16:57:23 -0800876 ATEN2011_port->write_in_progress = 0;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800877
878//schedule_work(&ATEN2011_port->port->work);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800879 tty_kref_put(tty);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800880
881}
882
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800883#ifdef ATENSerialProbe
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800884static int ATEN2011_serial_probe(struct usb_serial *serial,
885 const struct usb_device_id *id)
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800886{
887
888 /*need to implement the mode_reg reading and updating\
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800889 structures usb_serial_ device_type\
890 (i.e num_ports, num_bulkin,bulkout etc) */
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800891 /* Also we can update the changes attach */
892 return 1;
893}
894#endif
895
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800896static int ATEN2011_open(struct tty_struct *tty, struct usb_serial_port *port,
897 struct file *filp)
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800898{
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800899 int response;
900 int j;
901 struct usb_serial *serial;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800902// struct usb_serial_port *port0;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800903 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-Hartman8b4efbe2009-01-29 13:08:23 -0800910
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800911 if (ATEN2011_port_paranoia_check(port, __FUNCTION__)) {
912 DPRINTK("%s", "Port Paranoia failed \n");
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800913 return -ENODEV;
914 }
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800915 //ATEN2011_serial->NoOfOpenPorts++;
916 serial = port->serial;
917
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800918 if (ATEN2011_serial_paranoia_check(serial, __FUNCTION__)) {
919 DPRINTK("%s", "Serial Paranoia failed \n");
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800920 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-Hartmand93f87c2009-01-29 12:54:01 -0800943// port0 = serial->port[0];
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800944
945 ATEN2011_serial = ATEN2011_get_serial_private(serial);
946
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800947 if (ATEN2011_serial == NULL) //|| port0 == NULL)
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800948 {
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-Hartmand93f87c2009-01-29 12:54:01 -0800955 usb_clear_halt(serial->dev, port->write_urb->pipe);
956 usb_clear_halt(serial->dev, port->read_urb->pipe);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800957
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800958 /* 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-Hartmane6d69d92009-01-27 23:28:27 -0800962
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800963 if (urb == NULL) {
964 err("No more urbs???");
965 continue;
966 }
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800967
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800968 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-Hartmane6d69d92009-01-27 23:28:27 -0800976
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-Hartmand93f87c2009-01-29 12:54:01 -0800991 status = 0;
992 Data = 0x0;
993 status = ATEN2011_get_reg_sync(port, ATEN2011_port->SpRegOffset, &Data);
994 if (status < 0) {
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -0800995 DPRINTK("Reading Spreg failed\n");
996 return -1;
997 }
998 Data |= 0x80;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -0800999 status = ATEN2011_set_reg_sync(port, ATEN2011_port->SpRegOffset, Data);
1000 if (status < 0) {
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001001 DPRINTK("writing Spreg failed\n");
1002 return -1;
1003 }
1004
1005 Data &= ~0x80;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001006 status = ATEN2011_set_reg_sync(port, ATEN2011_port->SpRegOffset, Data);
1007 if (status < 0) {
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001008 DPRINTK("writing Spreg failed\n");
1009 return -1;
1010 }
1011
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001012//End of block to be checked
1013//**************************CHECK***************************//
1014
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001015 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-Hartmane6d69d92009-01-27 23:28:27 -08001028
1029//**************************CHECK***************************//
1030
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001031 status = 0;
1032 Data = 0x0;
1033 status =
1034 ATEN2011_get_reg_sync(port, ATEN2011_port->ControlRegOffset, &Data);
1035 if (status < 0) {
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001036 DPRINTK("Reading Controlreg failed\n");
1037 return -1;
1038 }
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001039 Data |= 0x08; //Driver done bit
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001040 /*
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001041 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-Hartmane6d69d92009-01-27 23:28:27 -08001052 DPRINTK("writing Controlreg failed\n");
1053 return -1;
1054 }
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001055 //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-Hartmand93f87c2009-01-29 12:54:01 -08001062 status = 0;
1063 status = ATEN2011_set_Uart_Reg(port, INTERRUPT_ENABLE_REGISTER, Data);
1064 if (status < 0) {
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001065 DPRINTK("disableing interrupts failed\n");
1066 return -1;
1067 }
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001068 // Set FIFO_CONTROL_REGISTER to the default value
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001069 Data = 0x00;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001070 status = 0;
1071 status = ATEN2011_set_Uart_Reg(port, FIFO_CONTROL_REGISTER, Data);
1072 if (status < 0) {
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001073 DPRINTK("Writing FIFO_CONTROL_REGISTER failed\n");
1074 return -1;
1075 }
1076
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001077 Data = 0xcf; //chk
1078 status = 0;
1079 status = ATEN2011_set_Uart_Reg(port, FIFO_CONTROL_REGISTER, Data);
1080 if (status < 0) {
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001081 DPRINTK("Writing FIFO_CONTROL_REGISTER failed\n");
1082 return -1;
1083 }
1084
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001085 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-Hartmane6d69d92009-01-27 23:28:27 -08001089
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001090 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-Hartmane6d69d92009-01-27 23:28:27 -08001094
1095#ifdef Check
1096 Data = 0x00;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001097 status = 0;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001098 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-Hartmane6d69d92009-01-27 23:28:27 -08001104
1105 Data = 0x0c;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001106 status = 0;
1107 status = ATEN2011_set_Uart_Reg(port, DIVISOR_LATCH_LSB, Data);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001108
1109 Data = 0x0;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001110 status = 0;
1111 status = ATEN2011_set_Uart_Reg(port, DIVISOR_LATCH_MSB, Data);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001112
1113 Data = 0x00;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001114 status = 0;
1115 status = ATEN2011_get_Uart_Reg(port, LINE_CONTROL_REGISTER, &Data);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001116
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001117// Data = ATEN2011_port->shadowLCR; //data latch disable
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001118 Data = Data & ~SERIAL_LCR_DLAB;
1119 status = 0;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001120 status = ATEN2011_set_Uart_Reg(port, LINE_CONTROL_REGISTER, Data);
1121 ATEN2011_port->shadowLCR = Data;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001122#endif
1123 //clearing Bulkin and Bulkout Fifo
1124 Data = 0x0;
1125 status = 0;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001126 status = ATEN2011_get_reg_sync(port, ATEN2011_port->SpRegOffset, &Data);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001127
1128 Data = Data | 0x0c;
1129 status = 0;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001130 status = ATEN2011_set_reg_sync(port, ATEN2011_port->SpRegOffset, Data);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001131
1132 Data = Data & ~0x0c;
1133 status = 0;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001134 status = ATEN2011_set_reg_sync(port, ATEN2011_port->SpRegOffset, Data);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001135 //Finally enable all interrupts
1136 Data = 0x0;
1137 Data = 0x0c;
1138 status = 0;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001139 status = ATEN2011_set_Uart_Reg(port, INTERRUPT_ENABLE_REGISTER, Data);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001140
1141 //clearing rx_disable
1142 Data = 0x0;
1143 status = 0;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001144 status =
1145 ATEN2011_get_reg_sync(port, ATEN2011_port->ControlRegOffset, &Data);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001146 Data = Data & ~0x20;
1147 status = 0;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001148 status =
1149 ATEN2011_set_reg_sync(port, ATEN2011_port->ControlRegOffset, Data);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001150
1151 // rx_negate
1152 Data = 0x0;
1153 status = 0;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001154 status =
1155 ATEN2011_get_reg_sync(port, ATEN2011_port->ControlRegOffset, &Data);
1156 Data = Data | 0x10;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001157 status = 0;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001158 status =
1159 ATEN2011_set_reg_sync(port, ATEN2011_port->ControlRegOffset, Data);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001160
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-Hartmane6d69d92009-01-27 23:28:27 -08001165 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-Hartmand93f87c2009-01-29 12:54:01 -08001180 if (ATEN2011_serial->NoOfOpenPorts == 1) {
1181 // start the status polling here
Greg Kroah-Hartmana6364092009-01-29 16:57:23 -08001182 ATEN2011_serial->status_polling_started = 1;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001183 //if (ATEN2011_serial->interrupt_in_buffer == NULL)
1184 // {
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001185 /* If not yet set, Set here */
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001186 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-Hartmane6d69d92009-01-27 23:28:27 -08001190 //printk(" interrupt endpoint:%d \n",ATEN2011_serial->interrupt_in_endpoint);
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001191 ATEN2011_serial->interrupt_read_urb =
1192 serial->port[0]->interrupt_in_urb;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001193
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001194 /* 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-Hartmane6d69d92009-01-27 23:28:27 -08001205
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001206 /* start interrupt read for ATEN2011 *
1207 * will continue as long as ATEN2011 is connected */
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001208
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001209 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-Hartmane6d69d92009-01-27 23:28:27 -08001218
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001219 //}
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001220
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001221 }
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001222//#endif
1223
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001224///////////////////////
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001225 /* see if we've set up our endpoint info yet *
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001226 * (can't set it up in ATEN2011_startup as the *
1227 * structures were not set up at that time.) */
1228
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001229 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-Hartmane6d69d92009-01-27 23:28:27 -08001239 ATEN2011_port->bulk_out_endpoint = port->bulk_out_endpointAddress;
1240
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001241 minor = port->serial->minor;
1242 if (minor == SERIAL_TTY_NO_MINOR)
1243 minor = 0;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001244
1245 /* set up our bulk in urb */
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001246 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-Hartmane6d69d92009-01-27 23:28:27 -08001266
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001267 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-Hartmane6d69d92009-01-27 23:28:27 -08001274
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001275 /* 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-Hartmane6d69d92009-01-27 23:28:27 -08001280
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001281 /* initialize our icount structure */
1282 memset(&(ATEN2011_port->icount), 0x00, sizeof(ATEN2011_port->icount));
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001283
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001284 /* initialize our port settings */
1285 ATEN2011_port->shadowMCR = MCR_MASTER_IE; /* Must set to enable ints! */
Greg Kroah-Hartmana6364092009-01-29 16:57:23 -08001286 ATEN2011_port->chaseResponsePending = 0;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001287 /* send a open port command */
Greg Kroah-Hartmana6364092009-01-29 16:57:23 -08001288 ATEN2011_port->openPending = 0;
1289 ATEN2011_port->open = 1;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001290 //ATEN2011_change_port_settings(ATEN2011_port,old_termios);
1291 /* Setup termios */
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001292 ATEN2011_set_termios(tty, port, &tmp_termios);
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001293 ATEN2011_port->rxBytesAvail = 0x0;
1294 ATEN2011_port->icount.tx = 0;
1295 ATEN2011_port->icount.rx = 0;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001296
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001297 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-Hartmane6d69d92009-01-27 23:28:27 -08001301
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001302 return 0;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001303
1304}
1305
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001306static void ATEN2011_close(struct tty_struct *tty, struct usb_serial_port *port,
1307 struct file *filp)
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001308{
1309 struct usb_serial *serial;
1310 struct ATENINTL_serial *ATEN2011_serial;
1311 struct ATENINTL_port *ATEN2011_port;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001312 int no_urbs;
1313 __u16 Data;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001314 //__u16 Data1= 20;
1315
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001316 DPRINTK("%s\n", "ATEN2011_close:entering...");
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001317 /* MATRIX */
1318 //ThreadState = 1;
1319 /* MATRIX */
1320 //printk("Entering... :ATEN2011_close\n");
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001321 if (ATEN2011_port_paranoia_check(port, __FUNCTION__)) {
1322 DPRINTK("%s", "Port Paranoia failed \n");
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001323 return;
1324 }
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001325 serial = ATEN2011_get_usb_serial(port, __FUNCTION__);
1326 if (!serial) {
1327 DPRINTK("%s", "Serial Paranoia failed \n");
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001328 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-Hartmand93f87c2009-01-29 12:54:01 -08001333 if ((ATEN2011_serial == NULL) || (ATEN2011_port == NULL)) {
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001334 return;
1335 }
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001336 if (serial->dev) {
1337 /* flush and block(wait) until tx is empty */
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001338 ATEN2011_block_until_tx_empty(tty, ATEN2011_port);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001339 }
1340 // kill the ports URB's
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001341 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-Hartmane6d69d92009-01-27 23:28:27 -08001353 /* While closing port, shutdown all bulk read, write *
1354 * and interrupt read if they exists */
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001355 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-Hartmane6d69d92009-01-27 23:28:27 -08001359 }
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001360 if (ATEN2011_port->read_urb) {
1361 DPRINTK("%s", "Shutdown bulk read\n");
1362 usb_kill_urb(ATEN2011_port->read_urb);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001363 }
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001364 if ((&ATEN2011_port->control_urb)) {
1365 DPRINTK("%s", "Shutdown control read\n");
1366 // usb_kill_urb (ATEN2011_port->control_urb);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001367
1368 }
1369 }
1370 //if(ATEN2011_port->ctrl_buf != NULL)
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001371 //kfree(ATEN2011_port->ctrl_buf);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001372 // decrement the no.of open ports counter of an individual USB-serial adapter.
1373 ATEN2011_serial->NoOfOpenPorts--;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001374 DPRINTK("NoOfOpenPorts in close%d:in port%d\n",
1375 ATEN2011_serial->NoOfOpenPorts, port->number);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001376 //printk("the num of ports opend is:%d\n",ATEN2011_serial->NoOfOpenPorts);
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001377 if (ATEN2011_serial->NoOfOpenPorts == 0) {
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001378 //stop the stus polling here
Greg Kroah-Hartmana6364092009-01-29 16:57:23 -08001379 //printk("disabling the status polling flag to 0 :\n");
1380 ATEN2011_serial->status_polling_started = 0;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001381 if (ATEN2011_serial->interrupt_read_urb) {
1382 DPRINTK("%s", "Shutdown interrupt_read_urb\n");
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001383 //ATEN2011_serial->interrupt_in_buffer=NULL;
1384 //usb_kill_urb (ATEN2011_serial->interrupt_read_urb);
1385 }
1386 }
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001387 if (ATEN2011_port->write_urb) {
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001388 /* if this urb had a transfer buffer already (old tx) free it */
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001389 if (ATEN2011_port->write_urb->transfer_buffer != NULL) {
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001390 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-Hartmand93f87c2009-01-29 12:54:01 -08001396 ATEN2011_set_Uart_Reg(port, MODEM_CONTROL_REGISTER, Data);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001397 Data = 0x00;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001398 ATEN2011_set_Uart_Reg(port, INTERRUPT_ENABLE_REGISTER, Data);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001399
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-Hartmana6364092009-01-29 16:57:23 -08001403 ATEN2011_port->open = 0;
1404 ATEN2011_port->closePending = 0;
1405 ATEN2011_port->openPending = 0;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001406 DPRINTK("%s \n", "Leaving ............");
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001407
1408}
1409
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001410static void ATEN2011_break(struct tty_struct *tty, int break_state)
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001411{
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001412 struct usb_serial_port *port = tty->driver_data;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001413 unsigned char data;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001414 struct usb_serial *serial;
1415 struct ATENINTL_serial *ATEN2011_serial;
1416 struct ATENINTL_port *ATEN2011_port;
1417
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001418 DPRINTK("%s \n", "Entering ...........");
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001419 DPRINTK("ATEN2011_break: Start\n");
1420
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001421 if (ATEN2011_port_paranoia_check(port, __FUNCTION__)) {
1422 DPRINTK("%s", "Port Paranoia failed \n");
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001423 return;
1424 }
1425
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001426 serial = ATEN2011_get_usb_serial(port, __FUNCTION__);
1427 if (!serial) {
1428 DPRINTK("%s", "Serial Paranoia failed \n");
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001429 return;
1430 }
1431
1432 ATEN2011_serial = ATEN2011_get_serial_private(serial);
1433 ATEN2011_port = ATEN2011_get_port_private(port);
1434
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001435 if ((ATEN2011_serial == NULL) || (ATEN2011_port == NULL)) {
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001436 return;
1437 }
1438
1439 /* flush and chase */
Greg Kroah-Hartmana6364092009-01-29 16:57:23 -08001440 ATEN2011_port->chaseResponsePending = 1;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001441
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001442 if (serial->dev) {
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001443
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001444 /* flush and block until tx is empty */
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001445 ATEN2011_block_until_chase_response(tty, ATEN2011_port);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001446 }
1447
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001448 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-Hartmane6d69d92009-01-27 23:28:27 -08001453
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001454 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-Hartmane6d69d92009-01-27 23:28:27 -08001459
1460 return;
1461}
1462
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001463static void ATEN2011_block_until_chase_response(struct tty_struct *tty,
1464 struct ATENINTL_port
1465 *ATEN2011_port)
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001466{
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001467 int timeout = 1 * HZ;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001468 int wait = 10;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001469 int count;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001470
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001471 while (1) {
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001472 count = ATEN2011_chars_in_buffer(tty);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001473
1474 /* Check for Buffer status */
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001475 if (count <= 0) {
Greg Kroah-Hartmana6364092009-01-29 16:57:23 -08001476 ATEN2011_port->chaseResponsePending = 0;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001477 return;
1478 }
1479
1480 /* Block the thread for a while */
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001481 interruptible_sleep_on_timeout(&ATEN2011_port->wait_chase,
1482 timeout);
1483 /* No activity.. count down section */
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001484 wait--;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001485 if (wait == 0) {
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001486 dbg("%s - TIMEOUT", __FUNCTION__);
1487 return;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001488 } else {
1489 /* Reset timout value back to seconds */
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001490 wait = 10;
1491 }
1492 }
1493
1494}
1495
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001496static void ATEN2011_block_until_tx_empty(struct tty_struct *tty,
1497 struct ATENINTL_port *ATEN2011_port)
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001498{
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001499 int timeout = HZ / 10;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001500 int wait = 30;
1501 int count;
1502
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001503 while (1) {
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001504
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001505 count = ATEN2011_chars_in_buffer(tty);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001506
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001507 /* Check for Buffer status */
1508 if (count <= 0) {
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001509 return;
1510 }
1511
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001512 /* Block the thread for a while */
1513 interruptible_sleep_on_timeout(&ATEN2011_port->wait_chase,
1514 timeout);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001515
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001516 /* No activity.. count down section */
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001517 wait--;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001518 if (wait == 0) {
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001519 dbg("%s - TIMEOUT", __FUNCTION__);
1520 return;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001521 } else {
1522 /* Reset timout value back to seconds */
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001523 wait = 30;
1524 }
1525 }
1526}
1527
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001528static int ATEN2011_write_room(struct tty_struct *tty)
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001529{
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001530 struct usb_serial_port *port = tty->driver_data;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001531 int i;
1532 int room = 0;
1533 struct ATENINTL_port *ATEN2011_port;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001534
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001535// DPRINTK("%s \n"," ATEN2011_write_room:entering ...........");
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001536
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001537 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-Hartmane6d69d92009-01-27 23:28:27 -08001542
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001543 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-Hartmane6d69d92009-01-27 23:28:27 -08001548
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001549 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-Hartmane6d69d92009-01-27 23:28:27 -08001554
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001555 dbg("%s - returns %d", __FUNCTION__, room);
1556 return (room);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001557
1558}
1559
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001560static int ATEN2011_chars_in_buffer(struct tty_struct *tty)
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001561{
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001562 struct usb_serial_port *port = tty->driver_data;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001563 int i;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001564 int chars = 0;
1565 struct ATENINTL_port *ATEN2011_port;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001566
1567 //DPRINTK("%s \n"," ATEN2011_chars_in_buffer:entering ...........");
1568
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001569 if (ATEN2011_port_paranoia_check(port, __FUNCTION__)) {
1570 DPRINTK("%s", "Invalid port \n");
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001571 return -1;
1572 }
1573
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001574 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-Hartmane6d69d92009-01-27 23:28:27 -08001579
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001580 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-Hartmane6d69d92009-01-27 23:28:27 -08001587
1588}
1589
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001590static int ATEN2011_write(struct tty_struct *tty, struct usb_serial_port *port,
1591 const unsigned char *data, int count)
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001592{
1593 int status;
1594 int i;
1595 int bytes_sent = 0;
1596 int transfer_size;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001597 int from_user = 0;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001598 int minor;
1599
1600 struct ATENINTL_port *ATEN2011_port;
1601 struct usb_serial *serial;
1602 struct ATENINTL_serial *ATEN2011_serial;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001603 struct urb *urb;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001604 //__u16 Data;
1605 const unsigned char *current_position = data;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001606 unsigned char *data1;
1607 DPRINTK("%s \n", "entering ...........");
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001608
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001609 if (ATEN2011_port_paranoia_check(port, __FUNCTION__)) {
1610 DPRINTK("%s", "Port Paranoia failed \n");
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001611 return -1;
1612 }
1613
1614 serial = port->serial;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001615 if (ATEN2011_serial_paranoia_check(serial, __FUNCTION__)) {
1616 DPRINTK("%s", "Serial Paranoia failed \n");
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001617 return -1;
1618 }
1619
1620 ATEN2011_port = ATEN2011_get_port_private(port);
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001621 if (ATEN2011_port == NULL) {
1622 DPRINTK("%s", "ATEN2011_port is NULL\n");
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001623 return -1;
1624 }
1625
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001626 ATEN2011_serial = ATEN2011_get_serial_private(serial);
1627 if (ATEN2011_serial == NULL) {
1628 DPRINTK("%s", "ATEN2011_serial is NULL \n");
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001629 return -1;
1630 }
1631
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001632 /* try to find a free urb in the list */
1633 urb = NULL;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001634
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001635 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-Hartmane6d69d92009-01-27 23:28:27 -08001642
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001643 if (urb == NULL) {
1644 dbg("%s - no more free urbs", __FUNCTION__);
1645 goto exit;
1646 }
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001647
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001648 if (urb->transfer_buffer == NULL) {
1649 urb->transfer_buffer =
1650 kmalloc(URB_TRANSFER_BUFFER_SIZE, GFP_KERNEL);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001651
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001652 if (urb->transfer_buffer == NULL) {
1653 err("%s no more kernel memory...", __FUNCTION__);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001654 goto exit;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001655 }
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-Hartmane6d69d92009-01-27 23:28:27 -08001713
1714 return bytes_sent;
1715
1716}
1717
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001718static void ATEN2011_throttle(struct tty_struct *tty)
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001719{
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001720 struct usb_serial_port *port = tty->driver_data;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001721 struct ATENINTL_port *ATEN2011_port;
1722 int status;
1723
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001724 if (ATEN2011_port_paranoia_check(port, __FUNCTION__)) {
1725 DPRINTK("%s", "Invalid port \n");
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001726 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-Hartmand93f87c2009-01-29 12:54:01 -08001736 if (!ATEN2011_port->open) {
1737 DPRINTK("%s\n", "port not opened");
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001738 return;
1739 }
1740
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001741 DPRINTK("%s", "Entering .......... \n");
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001742
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001743 if (!tty) {
1744 dbg("%s - no tty available", __FUNCTION__);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001745 return;
1746 }
1747
1748 /* if we are implementing XON/XOFF, send the stop character */
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001749 if (I_IXOFF(tty)) {
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001750 unsigned char stop_char = STOP_CHAR(tty);
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001751 status = ATEN2011_write(tty, port, &stop_char, 1); //FC4
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001752 if (status <= 0) {
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001753 return;
1754 }
1755 }
1756
1757 /* if we are implementing RTS/CTS, toggle that line */
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001758 if (tty->termios->c_cflag & CRTSCTS) {
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001759 ATEN2011_port->shadowMCR &= ~MCR_RTS;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001760 status = 0;
1761 status =
1762 ATEN2011_set_Uart_Reg(port, MODEM_CONTROL_REGISTER,
1763 ATEN2011_port->shadowMCR);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001764
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001765 if (status < 0) {
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001766 return;
1767 }
1768 }
1769
1770 return;
1771}
1772
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001773static void ATEN2011_unthrottle(struct tty_struct *tty)
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001774{
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001775 struct usb_serial_port *port = tty->driver_data;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001776 int status;
1777 struct ATENINTL_port *ATEN2011_port = ATEN2011_get_port_private(port);
1778
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001779 if (ATEN2011_port_paranoia_check(port, __FUNCTION__)) {
1780 DPRINTK("%s", "Invalid port \n");
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001781 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-Hartmand93f87c2009-01-29 12:54:01 -08001792 DPRINTK("%s", "Entering .......... \n");
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001793
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001794 if (!tty) {
1795 dbg("%s - no tty available", __FUNCTION__);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001796 return;
1797 }
1798
1799 /* if we are implementing XON/XOFF, send the start character */
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001800 if (I_IXOFF(tty)) {
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001801 unsigned char start_char = START_CHAR(tty);
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001802 status = ATEN2011_write(tty, port, &start_char, 1); //FC4
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001803 if (status <= 0) {
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001804 return;
1805 }
1806 }
1807
1808 /* if we are implementing RTS/CTS, toggle that line */
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001809 if (tty->termios->c_cflag & CRTSCTS) {
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001810 ATEN2011_port->shadowMCR |= MCR_RTS;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001811 status = 0;
1812 status =
1813 ATEN2011_set_Uart_Reg(port, MODEM_CONTROL_REGISTER,
1814 ATEN2011_port->shadowMCR);
1815 if (status < 0) {
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001816 return;
1817 }
1818 }
1819
1820 return;
1821}
1822
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001823static int ATEN2011_tiocmget(struct tty_struct *tty, struct file *file)
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001824{
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001825 struct usb_serial_port *port = tty->driver_data;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001826 //struct ti_port *tport = usb_get_serial_port_data(port);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001827 struct ATENINTL_port *ATEN2011_port;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001828 unsigned int result;
1829 __u16 msr;
1830 __u16 mcr;
1831 //unsigned int mcr;
1832 int status = 0;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001833 ATEN2011_port = ATEN2011_get_port_private(port);
1834
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001835 DPRINTK("%s - port %d", __FUNCTION__, port->number);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001836
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001837 if (ATEN2011_port == NULL)
1838 return -ENODEV;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001839
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001840 status = ATEN2011_get_Uart_Reg(port, MODEM_STATUS_REGISTER, &msr);
1841 status = ATEN2011_get_Uart_Reg(port, MODEM_CONTROL_REGISTER, &mcr);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001842// mcr = ATEN2011_port->shadowMCR;
1843// COMMENT2: the Fallowing three line are commented for updating only MSR values
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001844 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-Hartmane6d69d92009-01-27 23:28:27 -08001851
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001852 DPRINTK("%s - 0x%04X", __FUNCTION__, result);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001853
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001854 return result;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001855}
1856
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001857static int ATEN2011_tiocmset(struct tty_struct *tty, struct file *file,
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001858 unsigned int set, unsigned int clear)
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001859{
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001860 struct usb_serial_port *port = tty->driver_data;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001861 struct ATENINTL_port *ATEN2011_port;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001862 //struct ti_port *tport = usb_get_serial_port_data(port);
1863 unsigned int mcr;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001864 unsigned int status;
1865
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001866 DPRINTK("%s - port %d", __FUNCTION__, port->number);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001867
1868 ATEN2011_port = ATEN2011_get_port_private(port);
1869
1870 if (ATEN2011_port == NULL)
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001871 return -ENODEV;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001872
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001873 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-Hartmane6d69d92009-01-27 23:28:27 -08001880
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001881 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-Hartmane6d69d92009-01-27 23:28:27 -08001887
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001888 ATEN2011_port->shadowMCR = mcr;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001889
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001890 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-Hartmane6d69d92009-01-27 23:28:27 -08001896
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001897 return 0;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001898}
1899
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001900static void ATEN2011_set_termios(struct tty_struct *tty,
1901 struct usb_serial_port *port,
1902 struct ktermios *old_termios)
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001903{
1904 int status;
1905 unsigned int cflag;
1906 struct usb_serial *serial;
1907 struct ATENINTL_port *ATEN2011_port;
Greg Kroah-Hartman8b4efbe2009-01-29 13:08:23 -08001908
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001909 DPRINTK("ATEN2011_set_termios: START\n");
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001910 if (ATEN2011_port_paranoia_check(port, __FUNCTION__)) {
1911 DPRINTK("%s", "Invalid port \n");
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001912 return;
1913 }
1914
1915 serial = port->serial;
1916
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001917 if (ATEN2011_serial_paranoia_check(serial, __FUNCTION__)) {
1918 DPRINTK("%s", "Invalid Serial \n");
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001919 return;
1920 }
1921
1922 ATEN2011_port = ATEN2011_get_port_private(port);
1923
1924 if (ATEN2011_port == NULL)
1925 return;
1926
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001927 if (!ATEN2011_port->open) {
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001928 dbg("%s - port not opened", __FUNCTION__);
1929 return;
1930 }
1931
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001932 DPRINTK("%s\n", "setting termios - ");
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001933
1934 cflag = tty->termios->c_cflag;
1935
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001936 if (!cflag) {
1937 DPRINTK("%s %s\n", __FUNCTION__, "cflag is NULL");
1938 return;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001939 }
1940
1941 /* check that they really want us to change something */
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001942 if (old_termios) {
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001943 if ((cflag == old_termios->c_cflag) &&
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001944 (RELEVANT_IFLAG(tty->termios->c_iflag) ==
1945 RELEVANT_IFLAG(old_termios->c_iflag))) {
1946 DPRINTK("%s\n", "Nothing to change");
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001947 return;
1948 }
1949 }
1950
1951 dbg("%s - clfag %08x iflag %08x", __FUNCTION__,
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001952 tty->termios->c_cflag, RELEVANT_IFLAG(tty->termios->c_iflag));
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001953
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001954 if (old_termios) {
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001955 dbg("%s - old clfag %08x old iflag %08x", __FUNCTION__,
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001956 old_termios->c_cflag, RELEVANT_IFLAG(old_termios->c_iflag));
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001957 }
1958
1959 dbg("%s - port %d", __FUNCTION__, port->number);
1960
1961 /* change the port settings to the new ones specified */
1962
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001963 ATEN2011_change_port_settings(tty, ATEN2011_port, old_termios);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001964
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001965 if (!ATEN2011_port->read_urb) {
1966 DPRINTK("%s", "URB KILLED !!!!!\n");
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001967 return;
1968 }
1969
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001970 if (ATEN2011_port->read_urb->status != -EINPROGRESS) {
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001971 ATEN2011_port->read_urb->dev = serial->dev;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001972 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-Hartmane6d69d92009-01-27 23:28:27 -08001977 }
1978 }
1979 return;
1980}
1981
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001982static int get_lsr_info(struct tty_struct *tty,
1983 struct ATENINTL_port *ATEN2011_port,
1984 unsigned int *value)
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001985{
1986 int count;
1987 unsigned int result = 0;
1988
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001989 count = ATEN2011_chars_in_buffer(tty);
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08001990 if (count == 0) {
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08001991 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-Hartmand93f87c2009-01-29 12:54:01 -08002000static int get_number_bytes_avail(struct tty_struct *tty,
2001 struct ATENINTL_port *ATEN2011_port,
2002 unsigned int *value)
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002003{
2004 unsigned int result = 0;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002005
2006 if (!tty)
2007 return -ENOIOCTLCMD;
2008
2009 result = tty->read_cnt;
2010
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002011 dbg("%s(%d) = %d", __FUNCTION__, ATEN2011_port->port->number, result);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002012 if (copy_to_user(value, &result, sizeof(int)))
2013 return -EFAULT;
2014
2015 return -ENOIOCTLCMD;
2016}
2017
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002018static int set_modem_info(struct ATENINTL_port *ATEN2011_port, unsigned int cmd,
2019 unsigned int *value)
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002020{
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002021 unsigned int mcr;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002022 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-Hartmand93f87c2009-01-29 12:54:01 -08002030 port = (struct usb_serial_port *)ATEN2011_port->port;
2031 if (ATEN2011_port_paranoia_check(port, __FUNCTION__)) {
2032 DPRINTK("%s", "Invalid port \n");
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002033 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-Hartmand93f87c2009-01-29 12:54:01 -08002042 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-Hartmane6d69d92009-01-27 23:28:27 -08002050
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002051 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-Hartmane6d69d92009-01-27 23:28:27 -08002059
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002060 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-Hartmane6d69d92009-01-27 23:28:27 -08002068 }
2069
2070 ATEN2011_port->shadowMCR = mcr;
2071
2072 Data = ATEN2011_port->shadowMCR;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002073 status = 0;
2074 status = ATEN2011_set_Uart_Reg(port, MODEM_CONTROL_REGISTER, Data);
2075 if (status < 0) {
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002076 DPRINTK("setting MODEM_CONTROL_REGISTER Failed\n");
2077 return -1;
2078 }
2079
2080 return 0;
2081}
2082
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002083static int get_modem_info(struct ATENINTL_port *ATEN2011_port,
2084 unsigned int *value)
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002085{
2086 unsigned int result = 0;
2087 __u16 msr;
2088 unsigned int mcr = ATEN2011_port->shadowMCR;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002089 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-Hartmane6d69d92009-01-27 23:28:27 -08002099
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-Hartmand93f87c2009-01-29 12:54:01 -08002107static int get_serial_info(struct ATENINTL_port *ATEN2011_port,
2108 struct serial_struct *retinfo)
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002109{
2110 struct serial_struct tmp;
2111
2112 if (ATEN2011_port == NULL)
2113 return -1;
2114
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002115 if (!retinfo)
2116 return -EFAULT;
2117
2118 memset(&tmp, 0, sizeof(tmp));
2119
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002120 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-Hartmane6d69d92009-01-27 23:28:27 -08002131
2132 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
2133 return -EFAULT;
2134 return 0;
2135}
2136
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002137static int ATEN2011_ioctl(struct tty_struct *tty, struct file *file,
2138 unsigned int cmd, unsigned long arg)
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002139{
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002140 struct usb_serial_port *port = tty->driver_data;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002141 struct ATENINTL_port *ATEN2011_port;
2142 struct async_icount cnow;
2143 struct async_icount cprev;
2144 struct serial_icounter_struct icount;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002145 int ATENret = 0;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002146 //int retval;
2147 //struct tty_ldisc *ld;
2148
2149 //printk("%s - port %d, cmd = 0x%x\n", __FUNCTION__, port->number, cmd);
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002150 if (ATEN2011_port_paranoia_check(port, __FUNCTION__)) {
2151 DPRINTK("%s", "Invalid port \n");
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002152 return -1;
2153 }
2154
2155 ATEN2011_port = ATEN2011_get_port_private(port);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002156
2157 if (ATEN2011_port == NULL)
2158 return -1;
2159
2160 dbg("%s - port %d, cmd = 0x%x", __FUNCTION__, port->number, cmd);
2161
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002162 switch (cmd) {
2163 /* return number of bytes available */
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002164
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002165 case TIOCINQ:
2166 dbg("%s (%d) TIOCINQ", __FUNCTION__, port->number);
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002167 return get_number_bytes_avail(tty, ATEN2011_port,
2168 (unsigned int *)arg);
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002169 break;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002170
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002171 case TIOCOUTQ:
2172 dbg("%s (%d) TIOCOUTQ", __FUNCTION__, port->number);
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002173 return put_user(ATEN2011_chars_in_buffer(tty),
2174 (int __user *)arg);
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002175 break;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002176
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002177 case TIOCSERGETLSR:
2178 dbg("%s (%d) TIOCSERGETLSR", __FUNCTION__, port->number);
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002179 return get_lsr_info(tty, ATEN2011_port, (unsigned int *)arg);
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002180 return 0;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002181
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002182 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-Hartmane6d69d92009-01-27 23:28:27 -08002192
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002193 case TIOCMGET:
2194 dbg("%s (%d) TIOCMGET", __FUNCTION__, port->number);
2195 return get_modem_info(ATEN2011_port, (unsigned int *)arg);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002196
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002197 case TIOCGSERIAL:
2198 dbg("%s (%d) TIOCGSERIAL", __FUNCTION__, port->number);
2199 return get_serial_info(ATEN2011_port,
2200 (struct serial_struct *)arg);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002201
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002202 case TIOCSSERIAL:
2203 dbg("%s (%d) TIOCSSERIAL", __FUNCTION__, port->number);
2204 break;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002205
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002206 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-Hartmane6d69d92009-01-27 23:28:27 -08002213
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002214 /* see if a signal did it */
2215 if (signal_pending(current))
2216 return -ERESTARTSYS;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002217 cnow = ATEN2011_port->icount;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002218 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-Hartmane6d69d92009-01-27 23:28:27 -08002231
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002232 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-Hartmane6d69d92009-01-27 23:28:27 -08002245
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002246 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-Hartmand93f87c2009-01-29 12:54:01 -08002252 default:
2253 break;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002254 }
2255
2256 return -ENOIOCTLCMD;
2257}
2258
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002259static int ATEN2011_send_cmd_write_baud_rate(struct ATENINTL_port
2260 *ATEN2011_port, int baudRate)
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002261{
2262 int divisor = 0;
2263 int status;
2264 __u16 Data;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002265 unsigned char number;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002266 __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-Hartmand93f87c2009-01-29 12:54:01 -08002273 port = (struct usb_serial_port *)ATEN2011_port->port;
2274 if (ATEN2011_port_paranoia_check(port, __FUNCTION__)) {
2275 DPRINTK("%s", "Invalid port \n");
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002276 return -1;
2277 }
2278
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002279 if (ATEN2011_serial_paranoia_check(port->serial, __FUNCTION__)) {
2280 DPRINTK("%s", "Invalid Serial \n");
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002281 return -1;
2282 }
2283
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002284 DPRINTK("%s", "Entering .......... \n");
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002285
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002286 minor = ATEN2011_port->port->serial->minor;
2287 if (minor == SERIAL_TTY_NO_MINOR)
2288 minor = 0;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002289 number = ATEN2011_port->port->number - minor;
2290
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002291 dbg("%s - port = %d, baud = %d", __FUNCTION__,
2292 ATEN2011_port->port->number, baudRate);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002293 //reset clk_uart_sel in spregOffset
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002294 if (baudRate > 115200) {
2295#ifdef HW_flow_control
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002296 //NOTE: need to see the pther register to modify
2297 //setting h/w flow control bit to 1;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002298 status = 0;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002299 //Data = ATEN2011_port->shadowMCR ;
2300 Data = 0x2b;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002301 ATEN2011_port->shadowMCR = Data;
2302 status =
2303 ATEN2011_set_Uart_Reg(port, MODEM_CONTROL_REGISTER, Data);
2304 if (status < 0) {
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002305 DPRINTK("Writing spreg failed in set_serial_baud\n");
2306 return -1;
2307 }
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002308#endif
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002309
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002310 } else {
2311#ifdef HW_flow_control
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002312 //setting h/w flow control bit to 0;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002313 status = 0;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002314 //Data = ATEN2011_port->shadowMCR ;
2315 Data = 0xb;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002316 ATEN2011_port->shadowMCR = Data;
2317 status =
2318 ATEN2011_set_Uart_Reg(port, MODEM_CONTROL_REGISTER, Data);
2319 if (status < 0) {
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002320 DPRINTK("Writing spreg failed in set_serial_baud\n");
2321 return -1;
2322 }
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002323#endif
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002324
2325 }
2326
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002327 if (1) //baudRate <= 115200)
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002328 {
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002329 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-Hartmane6d69d92009-01-27 23:28:27 -08002339 DPRINTK("reading spreg failed in set_serial_baud\n");
2340 return -1;
2341 }
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002342 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-Hartmane6d69d92009-01-27 23:28:27 -08002348 DPRINTK("Writing spreg failed in set_serial_baud\n");
2349 return -1;
2350 }
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002351 /* Calculate the Divisor */
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002352
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002353 if (status) {
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002354 err("%s - bad baud rate", __FUNCTION__);
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002355 DPRINTK("%s\n", "bad baud rate");
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002356 return status;
2357 }
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002358 /* 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-Hartmane6d69d92009-01-27 23:28:27 -08002362
2363 /* Write the divisor */
Greg Kroah-Hartmana6364092009-01-29 16:57:23 -08002364 Data = (unsigned char)(divisor & 0xff);
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002365 DPRINTK("set_serial_baud Value to write DLL is %x\n", Data);
2366 ATEN2011_set_Uart_Reg(port, DIVISOR_LATCH_LSB, Data);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002367
Greg Kroah-Hartmana6364092009-01-29 16:57:23 -08002368 Data = (unsigned char)((divisor & 0xff00) >> 8);
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002369 DPRINTK("set_serial_baud Value to write DLM is %x\n", Data);
2370 ATEN2011_set_Uart_Reg(port, DIVISOR_LATCH_MSB, Data);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002371
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002372 /* 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-Hartmane6d69d92009-01-27 23:28:27 -08002376
2377 }
2378
2379 return status;
2380}
2381
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002382static int ATEN2011_calc_baud_rate_divisor(int baudRate, int *divisor,
2383 __u16 * clk_sel_val)
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002384{
2385 //int i;
2386 //__u16 custom,round1, round;
2387
2388 dbg("%s - %d", __FUNCTION__, baudRate);
2389
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002390 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-Hartmane6d69d92009-01-27 23:28:27 -08002416 return 0;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002417}
2418
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002419static void ATEN2011_change_port_settings(struct tty_struct *tty,
2420 struct ATENINTL_port *ATEN2011_port,
2421 struct ktermios *old_termios)
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002422{
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002423 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-Hartmand93f87c2009-01-29 12:54:01 -08002436 return;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002437
2438 port = (struct usb_serial_port *)ATEN2011_port->port;
2439
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002440 if (ATEN2011_port_paranoia_check(port, __FUNCTION__)) {
2441 DPRINTK("%s", "Invalid port \n");
2442 return;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002443 }
2444
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002445 if (ATEN2011_serial_paranoia_check(port->serial, __FUNCTION__)) {
2446 DPRINTK("%s", "Invalid Serial \n");
2447 return;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002448 }
2449
2450 serial = port->serial;
2451
2452 dbg("%s - port %d", __FUNCTION__, ATEN2011_port->port->number);
2453
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002454 if ((!ATEN2011_port->open) && (!ATEN2011_port->openPending)) {
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002455 dbg("%s - port not opened", __FUNCTION__);
2456 return;
2457 }
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002458
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002459 if ((!tty) || (!tty->termios)) {
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002460 dbg("%s - no tty structures", __FUNCTION__);
2461 return;
2462 }
2463
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002464 DPRINTK("%s", "Entering .......... \n");
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002465
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-Hartmand93f87c2009-01-29 12:54:01 -08002478 switch (cflag & CSIZE) {
2479 case CS5:
2480 lData = LCR_BITS_5;
2481 mask = 0x1f;
2482 break;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002483
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002484 case CS6:
2485 lData = LCR_BITS_6;
2486 mask = 0x3f;
2487 break;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002488
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002489 case CS7:
2490 lData = LCR_BITS_7;
2491 mask = 0x7f;
2492 break;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002493 default:
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002494 case CS8:
2495 lData = LCR_BITS_8;
2496 break;
2497 }
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002498 }
2499 /* Change the Parity bit */
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002500 if (cflag & PARENB) {
2501 if (cflag & PARODD) {
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002502 lParity = LCR_PAR_ODD;
2503 dbg("%s - parity = odd", __FUNCTION__);
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002504 } else {
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002505 lParity = LCR_PAR_EVEN;
2506 dbg("%s - parity = even", __FUNCTION__);
2507 }
2508
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002509 } else {
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002510 dbg("%s - parity = none", __FUNCTION__);
2511 }
2512
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002513 if (cflag & CMSPAR) {
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002514 lParity = lParity | 0x20;
2515 }
2516
2517 /* Change the Stop bit */
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002518 if (cflag & CSTOPB) {
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002519 lStop = LCR_STOP_2;
2520 dbg("%s - stop bits = 2", __FUNCTION__);
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002521 } else {
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002522 lStop = LCR_STOP_1;
2523 dbg("%s - stop bits = 1", __FUNCTION__);
2524 }
2525
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002526 /* Update the LCR with the correct value */
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002527 ATEN2011_port->shadowLCR &=
2528 ~(LCR_BITS_MASK | LCR_STOP_MASK | LCR_PAR_MASK);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002529 ATEN2011_port->shadowLCR |= (lData | lParity | lStop);
2530
2531 ATEN2011_port->validDataMask = mask;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002532 DPRINTK
2533 ("ATEN2011_change_port_settings ATEN2011_port->shadowLCR is %x\n",
2534 ATEN2011_port->shadowLCR);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002535 /* Disable Interrupts */
2536 Data = 0x00;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002537 ATEN2011_set_Uart_Reg(port, INTERRUPT_ENABLE_REGISTER, Data);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002538
2539 Data = 0x00;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002540 ATEN2011_set_Uart_Reg(port, FIFO_CONTROL_REGISTER, Data);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002541
2542 Data = 0xcf;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002543 ATEN2011_set_Uart_Reg(port, FIFO_CONTROL_REGISTER, Data);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002544
2545 /* Send the updated LCR value to the ATEN2011 */
2546 Data = ATEN2011_port->shadowLCR;
2547
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002548 ATEN2011_set_Uart_Reg(port, LINE_CONTROL_REGISTER, Data);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002549
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002550 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-Hartmane6d69d92009-01-27 23:28:27 -08002555
2556 /* set up the MCR register and send it to the ATEN2011 */
2557
2558 ATEN2011_port->shadowMCR = MCR_MASTER_IE;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002559 if (cflag & CBAUD) {
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002560 ATEN2011_port->shadowMCR |= (MCR_DTR | MCR_RTS);
2561 }
2562
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002563 if (cflag & CRTSCTS) {
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002564 ATEN2011_port->shadowMCR |= (MCR_XON_ANY);
2565
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002566 } else {
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002567 ATEN2011_port->shadowMCR &= ~(MCR_XON_ANY);
2568 }
2569
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002570 Data = ATEN2011_port->shadowMCR;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002571 ATEN2011_set_Uart_Reg(port, MODEM_CONTROL_REGISTER, Data);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002572
2573 /* Determine divisor based on baud rate */
2574 baud = tty_get_baud_rate(tty);
2575
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002576 if (!baud) {
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002577 /* pick a default, any default... */
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002578 DPRINTK("%s\n", "Picked default baud...");
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002579 baud = 9600;
2580 }
2581
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002582 dbg("%s - baud rate = %d", __FUNCTION__, baud);
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002583 status = ATEN2011_send_cmd_write_baud_rate(ATEN2011_port, baud);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002584
2585 /* Enable Interrupts */
2586 Data = 0x0c;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002587 ATEN2011_set_Uart_Reg(port, INTERRUPT_ENABLE_REGISTER, Data);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002588
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002589 if (ATEN2011_port->read_urb->status != -EINPROGRESS) {
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002590 ATEN2011_port->read_urb->dev = serial->dev;
2591
2592 status = usb_submit_urb(ATEN2011_port->read_urb, GFP_ATOMIC);
2593
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002594 if (status) {
2595 DPRINTK
2596 (" usb_submit_urb(read bulk) failed, status = %d",
2597 status);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002598 }
2599 }
2600 //wake_up(&ATEN2011_port->delta_msr_wait);
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002601 //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-Hartmane6d69d92009-01-27 23:28:27 -08002605
2606 return;
2607}
2608
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002609static int ATEN2011_calc_num_ports(struct usb_serial *serial)
2610{
2611
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002612 __u16 Data = 0x00;
2613 int ret = 0;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002614 int ATEN2011_2or4ports;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002615 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-Hartmane6d69d92009-01-27 23:28:27 -08002618
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002619 //printk("ATEN2011_calc_num_ports GPIO is %x\n",Data);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002620
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-Hartmand93f87c2009-01-29 12:54:01 -08002625 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-Hartmane6d69d92009-01-27 23:28:27 -08002635
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002636 }
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002637
2638 return ATEN2011_2or4ports;
2639}
2640
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002641static int ATEN2011_startup(struct usb_serial *serial)
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002642{
2643 struct ATENINTL_serial *ATEN2011_serial;
2644 struct ATENINTL_port *ATEN2011_port;
2645 struct usb_device *dev;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002646 int i, status;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002647 int minor;
2648
2649 __u16 Data;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002650 DPRINTK("%s \n", " ATEN2011_startup :entering..........");
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002651
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002652 if (!serial) {
2653 DPRINTK("%s\n", "Invalid Handler");
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002654 return -1;
2655 }
2656
2657 dev = serial->dev;
2658
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002659 DPRINTK("%s\n", "Entering...");
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002660
2661 /* create our private serial structure */
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002662 ATEN2011_serial = kzalloc(sizeof(struct ATENINTL_serial), GFP_KERNEL);
2663 if (ATEN2011_serial == NULL) {
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002664 err("%s - Out of memory", __FUNCTION__);
2665 return -ENOMEM;
2666 }
2667
2668 /* resetting the private structure field values to zero */
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002669 memset(ATEN2011_serial, 0, sizeof(struct ATENINTL_serial));
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002670
2671 ATEN2011_serial->serial = serial;
Greg Kroah-Hartmana6364092009-01-29 16:57:23 -08002672 //initilize status polling flag to 0
2673 ATEN2011_serial->status_polling_started = 0;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002674
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002675 ATEN2011_set_serial_private(serial, ATEN2011_serial);
2676 ATEN2011_serial->ATEN2011_spectrum_2or4ports =
2677 ATEN2011_calc_num_ports(serial);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002678 /* 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-Hartmand93f87c2009-01-29 12:54:01 -08002682 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-Hartmane6d69d92009-01-27 23:28:27 -08002686 err("%s - Out of memory", __FUNCTION__);
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002687 ATEN2011_set_serial_private(serial, NULL);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002688 kfree(ATEN2011_serial);
2689 return -ENOMEM;
2690 }
2691 memset(ATEN2011_port, 0, sizeof(struct ATENINTL_port));
2692
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002693 /* 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-Hartmane6d69d92009-01-27 23:28:27 -08002695
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002696 // serial->port[i]->interrupt_in_endpointAddress = serial->port[0]->interrupt_in_endpointAddress;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002697
2698 ATEN2011_port->port = serial->port[i];
2699//
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002700 ATEN2011_set_port_private(serial->port[i], ATEN2011_port);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002701
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002702 minor = serial->port[i]->serial->minor;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002703 if (minor == SERIAL_TTY_NO_MINOR)
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002704 minor = 0;
2705 ATEN2011_port->port_num =
2706 ((serial->port[i]->number - minor) + 1);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002707
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002708 ATEN2011_port->AppNum = (((__u16) serial->port[i]->number -
2709 (__u16) (minor)) + 1) << 8;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002710
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002711 if (ATEN2011_port->port_num == 1) {
2712 ATEN2011_port->SpRegOffset = 0x0;
2713 ATEN2011_port->ControlRegOffset = 0x1;
2714 ATEN2011_port->DcrRegOffset = 0x4;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002715 } 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-Hartmand93f87c2009-01-29 12:54:01 -08002721 } 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-Hartmand93f87c2009-01-29 12:54:01 -08002727 } 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-Hartmand93f87c2009-01-29 12:54:01 -08002733 } 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-Hartmane6d69d92009-01-27 23:28:27 -08002739 }
2740 ATEN2011_Dump_serial_port(ATEN2011_port);
2741
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002742 ATEN2011_set_port_private(serial->port[i], ATEN2011_port);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002743
2744 //enable rx_disable bit in control register
2745
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002746 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-Hartmane6d69d92009-01-27 23:28:27 -08002760
2761 //Data |= 0x20; //rx_disable bit
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002762 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-Hartmane6d69d92009-01-27 23:28:27 -08002776
2777 //Write default values in DCR (i.e 0x01 in DCR0, 0x05 in DCR2 and 0x24 in DCR3
2778 Data = 0x01;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002779 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-Hartmane6d69d92009-01-27 23:28:27 -08002789
2790 Data = 0x05;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002791 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-Hartmane6d69d92009-01-27 23:28:27 -08002801
2802 Data = 0x24;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002803 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-Hartmane6d69d92009-01-27 23:28:27 -08002813
2814 // write values in clkstart0x0 and clkmulti 0x20
2815 Data = 0x0;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002816 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-Hartmane6d69d92009-01-27 23:28:27 -08002829
2830 Data = 0x20;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002831 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-Hartmane6d69d92009-01-27 23:28:27 -08002843
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002844 //Zero Length flag register
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002845 if ((ATEN2011_port->port_num != 1)
2846 && (ATEN2011_serial->ATEN2011_spectrum_2or4ports == 2)) {
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002847
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002848 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-Hartmane6d69d92009-01-27 23:28:27 -08002888
2889 }
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002890 ATEN2011_port->control_urb = usb_alloc_urb(0, GFP_ATOMIC);
2891 ATEN2011_port->ctrl_buf = kmalloc(16, GFP_KERNEL);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002892
2893 }
2894
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002895 //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-Hartmane6d69d92009-01-27 23:28:27 -08002904
2905 /* setting configuration feature to one */
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002906 usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
2907 (__u8) 0x03, 0x00, 0x01, 0x00, 0x00, 0x00, 5 * HZ);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002908 return 0;
2909}
2910
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002911static void ATEN2011_shutdown(struct usb_serial *serial)
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002912{
2913 int i;
2914 struct ATENINTL_port *ATEN2011_port;
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002915 DPRINTK("%s \n", " shutdown :entering..........");
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002916
2917/* MATRIX */
2918 //ThreadState = 1;
2919/* MATRIX */
2920
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002921 if (!serial) {
2922 DPRINTK("%s", "Invalid Handler \n");
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002923 return;
2924 }
2925
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002926 /* check for the ports to be closed,close the ports and disconnect */
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002927
2928 /* free private structure allocated for serial port *
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002929 * stop reads and writes on all ports */
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002930
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002931 for (i = 0; i < serial->num_ports; ++i) {
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002932 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-Hartmand93f87c2009-01-29 12:54:01 -08002936 ATEN2011_set_port_private(serial->port[i], NULL);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002937 }
2938
2939 /* free private structure allocated for serial device */
2940
2941 kfree(ATEN2011_get_serial_private(serial));
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002942 ATEN2011_set_serial_private(serial, NULL);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002943
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002944 DPRINTK("%s\n", "Thank u :: ");
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002945
2946}
2947
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002948/* Inline functions to check the sanity of a pointer that is passed to us */
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002949static int ATEN2011_serial_paranoia_check(struct usb_serial *serial,
2950 const char *function)
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002951{
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002952 if (!serial) {
2953 dbg("%s - serial == NULL", function);
2954 return -1;
2955 }
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002956 if (!serial->type) {
2957 dbg("%s - serial->type == NULL!", function);
2958 return -1;
2959 }
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002960
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002961 return 0;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002962}
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002963static int ATEN2011_port_paranoia_check(struct usb_serial_port *port,
2964 const char *function)
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002965{
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002966 if (!port) {
2967 dbg("%s - port == NULL", function);
2968 return -1;
2969 }
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002970 if (!port->serial) {
2971 dbg("%s - port->serial == NULL", function);
2972 return -1;
2973 }
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002974
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002975 return 0;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002976}
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002977static 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-Hartmane6d69d92009-01-27 23:28:27 -08002987
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002988 return port->serial;
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002989}
2990
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002991int __init ATENINTL2011_init(void)
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002992{
2993 int retval;
2994
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002995 DPRINTK("%s \n", " ATEN2011_init :entering..........");
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002996
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08002997 /* Register with the usb serial */
2998 retval = usb_serial_register(&ATENINTL2011_4port_device);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08002999
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08003000 if (retval)
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08003001 goto failed_port_device_register;
3002
3003/* info(DRIVER_DESC " " DRIVER_VERSION); */
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08003004 printk(KERN_INFO KBUILD_MODNAME ":"
3005 DRIVER_DESC " " DRIVER_VERSION "\n");
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08003006
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08003007 /* Register with the usb */
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08003008 retval = usb_register(&io_driver);
3009
3010 if (retval)
3011 goto failed_usb_register;
3012
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08003013 if (retval == 0) {
3014 DPRINTK("%s\n", "Leaving...");
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08003015 return 0;
3016 }
3017
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08003018 failed_usb_register:
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08003019 usb_serial_deregister(&ATENINTL2011_4port_device);
3020
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08003021 failed_port_device_register:
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08003022
3023 return retval;
3024}
3025
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08003026void __exit ATENINTL2011_exit(void)
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08003027{
3028
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08003029 DPRINTK("%s \n", " ATEN2011_exit :entering..........");
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08003030
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08003031 usb_deregister(&io_driver);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08003032
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08003033 usb_serial_deregister(&ATENINTL2011_4port_device);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08003034
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08003035 DPRINTK("%s\n", "End...");
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08003036}
3037
3038module_init(ATENINTL2011_init);
3039module_exit(ATENINTL2011_exit);
3040
3041/* Module information */
Greg Kroah-Hartmand93f87c2009-01-29 12:54:01 -08003042MODULE_DESCRIPTION(DRIVER_DESC);
Greg Kroah-Hartmane6d69d92009-01-27 23:28:27 -08003043MODULE_LICENSE("GPL");
3044
3045MODULE_PARM_DESC(debug, "Debug enabled or not");